Skip to content

Commit 4ff8a9b

Browse files
Don't inherit codegen attrs from parent static
1 parent 66de611 commit 4ff8a9b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

compiler/rustc_const_eval/src/interpret/intern.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_ast::Mutability;
1818
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1919
use rustc_errors::ErrorGuaranteed;
2020
use rustc_hir as hir;
21+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2122
use rustc_middle::mir::interpret::{ConstAllocation, CtfeProvenance, InterpResult};
2223
use rustc_middle::query::TyCtxtAt;
2324
use rustc_middle::ty::layout::TyAndLayout;
@@ -106,13 +107,17 @@ fn intern_as_new_static<'tcx>(
106107
DefKind::Static { mutability: alloc.0.mutability, nested: true },
107108
);
108109
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
109-
feed.codegen_fn_attrs(tcx.codegen_fn_attrs(static_id).clone());
110+
111+
// These do not inherit the codegen attrs of the parent static allocation, since
112+
// it doesn't make sense for them to inherit their `#[no_mangle]` and `#[link_name = ..]`
113+
// and the like.
114+
feed.codegen_fn_attrs(CodegenFnAttrs::new());
115+
110116
feed.eval_static_initializer(Ok(alloc));
111117
feed.generics_of(tcx.generics_of(static_id).clone());
112118
feed.def_ident_span(tcx.def_ident_span(static_id));
113119
feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id));
114-
115-
feed.feed_hir()
120+
feed.feed_hir();
116121
}
117122

118123
/// How a constant value should be interned.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ build-pass
2+
3+
// Make sure that the nested static allocation for `FOO` doesn't inherit `no_mangle`.
4+
#[no_mangle]
5+
pub static mut FOO: &mut [i32] = &mut [42];
6+
7+
// Make sure that the nested static allocation for `BAR` doesn't inherit `export_name`.
8+
#[export_name = "BAR_"]
9+
pub static mut BAR: &mut [i32] = &mut [42];
10+
11+
fn main() {}

0 commit comments

Comments
 (0)