From a3676bd0facf44a576af975ee7529abd61122d55 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 16 Nov 2025 19:21:17 +0000 Subject: [PATCH] Introduce Operand::RuntimeChecks. --- src/base.rs | 8 +++++++- src/constant.rs | 9 ++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/base.rs b/src/base.rs index 4dbee7665eb8..79f65141e66f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -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); + } } } diff --git a/src/constant.rs b/src/constant.rs index 29c8e8ab1e52..c25034d4be22 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -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 { 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.