@@ -5,6 +5,7 @@ use rustc_middle::mir::*;
55use rustc_middle:: ty:: subst:: SubstsRef ;
66use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
77use rustc_span:: symbol:: { sym, Symbol } ;
8+ use rustc_span:: Span ;
89use rustc_target:: spec:: abi:: Abi ;
910
1011pub struct LowerIntrinsics ;
@@ -119,6 +120,9 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
119120 terminator. kind = TerminatorKind :: Goto { target } ;
120121 }
121122 }
123+ _ if intrinsic_name. as_str ( ) . starts_with ( "simd_shuffle" ) => {
124+ validate_simd_shuffle ( tcx, args, terminator. source_info . span ) ;
125+ }
122126 _ => { }
123127 }
124128 }
@@ -132,9 +136,19 @@ fn resolve_rust_intrinsic(
132136) -> Option < ( Symbol , SubstsRef < ' tcx > ) > {
133137 if let ty:: FnDef ( def_id, substs) = * func_ty. kind ( ) {
134138 let fn_sig = func_ty. fn_sig ( tcx) ;
135- if fn_sig . abi ( ) == Abi :: RustIntrinsic {
139+ if let Abi :: RustIntrinsic | Abi :: PlatformIntrinsic = fn_sig . abi ( ) {
136140 return Some ( ( tcx. item_name ( def_id) , substs) ) ;
137141 }
138142 }
139143 None
140144}
145+
146+ fn validate_simd_shuffle ( tcx : TyCtxt < ' tcx > , args : & [ Operand < ' tcx > ] , span : Span ) {
147+ match & args[ 2 ] {
148+ Operand :: Constant ( _) => { } // all good
149+ _ => {
150+ let msg = format ! ( "last argument of `simd_shuffle` is required to be a `const` item" ) ;
151+ tcx. sess . span_err ( span, & msg) ;
152+ }
153+ }
154+ }
0 commit comments