Skip to content

Commit 27a6798

Browse files
committed
Check whether a static is mutable instead of passing it down
1 parent c381148 commit 27a6798

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

compiler/rustc_codegen_gcc/src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
5555
global_value
5656
}
5757

58-
fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
58+
fn codegen_static(&self, def_id: DefId) {
5959
let attrs = self.tcx.codegen_fn_attrs(def_id);
6060

6161
let value =
@@ -89,7 +89,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
8989

9090
// As an optimization, all shared statics which do not have interior
9191
// mutability are placed into read-only memory.
92-
if !is_mutable {
92+
if !self.tcx.static_mutability(def_id).unwrap().is_mut() {
9393
if self.type_is_freeze(ty) {
9494
#[cfg(feature = "master")]
9595
global.global_set_readonly();

compiler/rustc_codegen_llvm/src/consts.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'ll> CodegenCx<'ll, '_> {
344344
g
345345
}
346346

347-
fn codegen_static_item(&self, def_id: DefId, is_mutable: bool) {
347+
fn codegen_static_item(&self, def_id: DefId) {
348348
unsafe {
349349
let attrs = self.tcx.codegen_fn_attrs(def_id);
350350

@@ -356,7 +356,7 @@ impl<'ll> CodegenCx<'ll, '_> {
356356

357357
let instance = Instance::mono(self.tcx, def_id);
358358
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
359-
if !is_mutable {
359+
if !self.tcx.is_mutable_static(def_id) {
360360
debug_assert_eq!(alloc.mutability.is_not(), self.type_is_freeze(ty));
361361
}
362362
debug_assert_eq!(alloc.align, self.align_of(ty));
@@ -409,7 +409,7 @@ impl<'ll> CodegenCx<'ll, '_> {
409409

410410
// As an optimization, all shared statics which do not have interior
411411
// mutability are placed into read-only memory.
412-
if !is_mutable && alloc.mutability.is_not() {
412+
if !self.tcx.is_mutable_static(def_id) && alloc.mutability.is_not() {
413413
llvm::LLVMSetGlobalConstant(g, llvm::True);
414414
}
415415

@@ -555,8 +555,8 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
555555
gv
556556
}
557557

558-
fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
559-
self.codegen_static_item(def_id, is_mutable)
558+
fn codegen_static(&self, def_id: DefId) {
559+
self.codegen_static_item(def_id)
560560
}
561561

562562
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of ptr.

compiler/rustc_codegen_ssa/src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
3030

3131
match *self {
3232
MonoItem::Static(def_id) => {
33-
cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id));
33+
cx.codegen_static(def_id);
3434
}
3535
MonoItem::GlobalAsm(item_id) => {
3636
let item = cx.tcx().hir().item(item_id);

compiler/rustc_codegen_ssa/src/traits/statics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_target::abi::Align;
44

55
pub trait StaticMethods: BackendTypes {
66
fn static_addr_of(&self, cv: Self::Value, align: Align, kind: Option<&str>) -> Self::Value;
7-
fn codegen_static(&self, def_id: DefId, is_mutable: bool);
7+
fn codegen_static(&self, def_id: DefId);
88

99
/// Mark the given global value as "used", to prevent the compiler and linker from potentially
1010
/// removing a static variable that may otherwise appear unused.

0 commit comments

Comments
 (0)