Skip to content

Commit 2e8e91c

Browse files
committed
add check that simd_shuffle arguments are constants
1 parent 44a8e8d commit 2e8e91c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

compiler/rustc_mir/src/transform/lower_intrinsics.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_middle::mir::*;
55
use rustc_middle::ty::subst::SubstsRef;
66
use rustc_middle::ty::{self, Ty, TyCtxt};
77
use rustc_span::symbol::{sym, Symbol};
8+
use rustc_span::Span;
89
use rustc_target::spec::abi::Abi;
910

1011
pub 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

Comments
 (0)