Skip to content

Commit 987298c

Browse files
committed
Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin
Replace Rvalue::NullaryOp by a variant in mir::Operand. Based on rust-lang/rust#148151 This PR fully removes the MIR `Rvalue::NullaryOp`. After rust-lang/rust#148151, it was only useful for runtime checks like `ub_checks`, `contract_checks` and `overflow_checks`. These are "runtime" checks, boolean constants that may only be `true` in codegen. It depends on a rustc flag passed to codegen, so we need to represent those flags cross-crate. This PR replaces those runtime checks by special variants in MIR `ConstValue`. This allows code that expects constants to manipulate those as such, even if we may not always be able to evaluate them to actual scalars.
2 parents 005046d + 8592162 commit 987298c

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

src/base.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
1010
use rustc_index::IndexVec;
1111
use rustc_middle::ty::TypeVisitableExt;
1212
use rustc_middle::ty::adjustment::PointerCoercion;
13-
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
13+
use rustc_middle::ty::layout::FnAbiOf;
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
1515
use rustc_session::config::OutputFilenames;
1616
use rustc_span::Symbol;
@@ -853,17 +853,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
853853
fx.bcx.ins().nop();
854854
}
855855
}
856-
Rvalue::NullaryOp(ref null_op) => {
857-
assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env()));
858-
let val = match null_op {
859-
NullOp::RuntimeChecks(kind) => kind.value(fx.tcx.sess),
860-
};
861-
let val = CValue::by_val(
862-
fx.bcx.ins().iconst(types::I8, i64::from(val)),
863-
fx.layout_of(fx.tcx.types.bool),
864-
);
865-
lval.write_cvalue(fx, val);
866-
}
867856
Rvalue::Aggregate(ref kind, ref operands)
868857
if matches!(**kind, AggregateKind::RawPtr(..)) =>
869858
{
@@ -1050,6 +1039,11 @@ pub(crate) fn codegen_operand<'tcx>(
10501039
cplace.to_cvalue(fx)
10511040
}
10521041
Operand::Constant(const_) => crate::constant::codegen_constant_operand(fx, const_),
1042+
Operand::RuntimeChecks(checks) => {
1043+
let val = checks.value(fx.tcx.sess);
1044+
let layout = fx.layout_of(fx.tcx.types.bool);
1045+
return CValue::const_val(fx, layout, val.into());
1046+
}
10531047
}
10541048
}
10551049

src/constant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
540540
operand: &Operand<'tcx>,
541541
) -> Option<ScalarInt> {
542542
match operand {
543+
Operand::RuntimeChecks(checks) => Some(checks.value(fx.tcx.sess).into()),
543544
Operand::Constant(const_) => eval_mir_constant(fx, const_).0.try_to_scalar_int(),
544545
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
545546
// inside a temporary before being passed to the intrinsic requiring the const argument.

0 commit comments

Comments
 (0)