From b0a580112b53f3b64abf2d67b6776141d0fa7c44 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 9 Dec 2023 15:53:41 -0500 Subject: [PATCH] Use immediate_backend_type when reading from a const alloc --- compiler/rustc_codegen_ssa/src/mir/operand.rs | 2 +- tests/ui/codegen/const-bool-bitcast.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/ui/codegen/const-bool-bitcast.rs diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index d724f9503bb6c..feee3ac03d0a7 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -155,7 +155,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { Abi::Scalar(s @ abi::Scalar::Initialized { .. }) => { let size = s.size(bx); assert_eq!(size, layout.size, "abi::Scalar size does not match layout size"); - let val = read_scalar(offset, size, s, bx.backend_type(layout)); + let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout)); OperandRef { val: OperandValue::Immediate(val), layout } } Abi::ScalarPair( diff --git a/tests/ui/codegen/const-bool-bitcast.rs b/tests/ui/codegen/const-bool-bitcast.rs new file mode 100644 index 0000000000000..24ae76b902991 --- /dev/null +++ b/tests/ui/codegen/const-bool-bitcast.rs @@ -0,0 +1,15 @@ +// This is a regression test for https://github.com/rust-lang/rust/issues/118047 +// build-pass +// compile-flags: -Zmir-opt-level=0 -Zmir-enable-passes=+DataflowConstProp + +#![crate_type = "lib"] + +pub struct State { + inner: bool +} + +pub fn make() -> State { + State { + inner: true + } +}