From fcb890ea0c2d47d2fe6ea45fbb41fd3cb78645c8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 6 Oct 2023 14:39:23 +0000 Subject: [PATCH] Use information from allocation instead of from the static's type --- compiler/rustc_codegen_llvm/src/consts.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 9c1b64fdb00..fbbc1ecbbca 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -358,6 +358,10 @@ impl<'ll> CodegenCx<'ll, '_> { let instance = Instance::mono(self.tcx, def_id); let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all()); + if !is_mutable { + debug_assert_eq!(alloc.mutability.is_not(), self.type_is_freeze(ty)); + } + debug_assert_eq!(alloc.align, self.align_of(ty)); let llty = self.layout_of(ty).llvm_type(self); let g = self.get_static_inner(def_id, llty); @@ -396,7 +400,7 @@ impl<'ll> CodegenCx<'ll, '_> { self.statics_to_rauw.borrow_mut().push((g, new_g)); new_g }; - set_global_alignment(self, g, self.align_of(ty)); + set_global_alignment(self, g, alloc.align); llvm::LLVMSetInitializer(g, v); if self.should_assume_dso_local(g, true) { @@ -405,7 +409,7 @@ impl<'ll> CodegenCx<'ll, '_> { // As an optimization, all shared statics which do not have interior // mutability are placed into read-only memory. - if !is_mutable && self.type_is_freeze(ty) { + if !is_mutable && alloc.mutability.is_not() { llvm::LLVMSetGlobalConstant(g, llvm::True); }