Introduce Operand::RuntimeChecks.

This commit is contained in:
Camille Gillot 2025-11-16 19:21:17 +00:00
parent a0de5ae5a1
commit a3676bd0fa
2 changed files with 11 additions and 6 deletions

View file

@ -8,10 +8,10 @@ use rustc_ast::InlineAsmOptions;
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_index::IndexVec;
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{ScalarInt, TypeVisitableExt};
use rustc_session::config::OutputFilenames;
use rustc_span::Symbol;
@ -1039,6 +1039,12 @@ pub(crate) fn codegen_operand<'tcx>(
cplace.to_cvalue(fx)
}
Operand::Constant(const_) => crate::constant::codegen_constant_operand(fx, const_),
Operand::RuntimeChecks(checks) => {
let int = checks.value(fx.tcx.sess);
let int = ScalarInt::try_from_uint(int, Size::from_bits(1)).unwrap();
let layout = fx.layout_of(fx.tcx.types.bool);
return CValue::const_val(fx, layout, int);
}
}
}

View file

@ -215,11 +215,6 @@ pub(crate) fn codegen_const_value<'tcx>(
CValue::by_val(val, layout)
}
},
ConstValue::RuntimeChecks(checks) => {
let int = checks.value(fx.tcx.sess);
let int = ScalarInt::try_from_uint(int, Size::from_bits(1)).unwrap();
return CValue::const_val(fx, layout, int);
}
ConstValue::Indirect { alloc_id, offset } => CValue::by_ref(
Pointer::new(pointer_for_allocation(fx, alloc_id))
.offset_i64(fx, i64::try_from(offset.bytes()).unwrap()),
@ -545,6 +540,10 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
operand: &Operand<'tcx>,
) -> Option<ScalarInt> {
match operand {
Operand::RuntimeChecks(checks) => {
let int = checks.value(fx.tcx.sess);
ScalarInt::try_from_uint(int, Size::from_bits(1))
}
Operand::Constant(const_) => eval_mir_constant(fx, const_).0.try_to_scalar_int(),
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
// inside a temporary before being passed to the intrinsic requiring the const argument.