Skip to content

Commit bb03730

Browse files
committed
Use information from allocation instead of from the static's type
1 parent 6177a6d commit bb03730

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ impl<'ll> CodegenCx<'ll, '_> {
358358

359359
let instance = Instance::mono(self.tcx, def_id);
360360
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
361+
if !is_mutable {
362+
debug_assert_eq!(alloc.mutability.is_not(), self.type_is_freeze(ty));
363+
}
364+
debug_assert_eq!(alloc.align, self.align_of(ty));
361365
let llty = self.layout_of(ty).llvm_type(self);
362366

363367
let g = self.get_static_inner(def_id, llty);
@@ -396,7 +400,7 @@ impl<'ll> CodegenCx<'ll, '_> {
396400
self.statics_to_rauw.borrow_mut().push((g, new_g));
397401
new_g
398402
};
399-
set_global_alignment(self, g, self.align_of(ty));
403+
set_global_alignment(self, g, alloc.align);
400404
llvm::LLVMSetInitializer(g, v);
401405

402406
if self.should_assume_dso_local(g, true) {
@@ -405,7 +409,7 @@ impl<'ll> CodegenCx<'ll, '_> {
405409

406410
// As an optimization, all shared statics which do not have interior
407411
// mutability are placed into read-only memory.
408-
if !is_mutable && self.type_is_freeze(ty) {
412+
if !is_mutable && alloc.mutability.is_not() {
409413
llvm::LLVMSetGlobalConstant(g, llvm::True);
410414
}
411415

0 commit comments

Comments
 (0)