From a0de5ae5a1933acfc0a161d945b1ce1d05c7e82e Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 9 Nov 2025 02:57:31 +0000 Subject: [PATCH 1/3] Replace Rvalue::NullaryOp by a variant in mir::ConstValue. --- src/base.rs | 13 +------------ src/constant.rs | 5 +++++ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/base.rs b/src/base.rs index ac5b3c240785..4dbee7665eb8 100644 --- a/src/base.rs +++ b/src/base.rs @@ -10,7 +10,7 @@ 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, HasTypingEnv}; +use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::config::OutputFilenames; use rustc_span::Symbol; @@ -853,17 +853,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: fx.bcx.ins().nop(); } } - Rvalue::NullaryOp(ref null_op) => { - assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env())); - let val = match null_op { - NullOp::RuntimeChecks(kind) => kind.value(fx.tcx.sess), - }; - let val = CValue::by_val( - fx.bcx.ins().iconst(types::I8, i64::from(val)), - fx.layout_of(fx.tcx.types.bool), - ); - lval.write_cvalue(fx, val); - } Rvalue::Aggregate(ref kind, ref operands) if matches!(**kind, AggregateKind::RawPtr(..)) => { diff --git a/src/constant.rs b/src/constant.rs index 2b65b8290681..29c8e8ab1e52 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -215,6 +215,11 @@ 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()), From a3676bd0facf44a576af975ee7529abd61122d55 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 16 Nov 2025 19:21:17 +0000 Subject: [PATCH 2/3] 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. From 85921620d1ea3f7f725b6942b386ed1aa8c3d18f Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 14 Dec 2025 17:29:59 +0000 Subject: [PATCH 3/3] Use ScalarInt from bool. --- src/base.rs | 7 +++---- src/constant.rs | 5 +---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/base.rs b/src/base.rs index 79f65141e66f..1a916c876824 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; @@ -1040,10 +1040,9 @@ pub(crate) fn codegen_operand<'tcx>( } 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 val = checks.value(fx.tcx.sess); let layout = fx.layout_of(fx.tcx.types.bool); - return CValue::const_val(fx, layout, int); + return CValue::const_val(fx, layout, val.into()); } } } diff --git a/src/constant.rs b/src/constant.rs index c25034d4be22..ff8e6744bd32 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -540,10 +540,7 @@ 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::RuntimeChecks(checks) => Some(checks.value(fx.tcx.sess).into()), 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.