Skip to content

WIP: do not promote rustc_args_required_const #80759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions compiler/rustc_mir/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,14 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
self.super_terminator(terminator, location);

match terminator.kind {
TerminatorKind::Call { ref func, .. } => {
TerminatorKind::Call { ref func, ref args, .. } => {
if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
let fn_sig = self.ccx.tcx.fn_sig(def_id);
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
let name = self.ccx.tcx.item_name(def_id);
// FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
// FIXME: Find some way to do this without general
// promotion (hard-code array literals, or compile to
// `inline const`).
if name.as_str().starts_with("simd_shuffle") {
self.candidates
.push(Candidate::Argument { bb: location.block, index: 2 });
Expand All @@ -242,7 +244,12 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {

if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) {
for index in constant_args {
self.candidates.push(Candidate::Argument { bb: location.block, index });
// FIXME perform this check in some more sensible place
if !matches!(args[index], Operand::Constant(_)) {
let span = terminator.source_info.span;
let msg = format!("argument {} is required to be a constant", index + 1);
self.ccx.tcx.sess.span_err(span, &msg);
}
}
}
}
Expand Down