Skip to content

Commit 32168a3

Browse files
committed
Allow different global references to the same name
Combining CGUs can result in code that references a static variable through both an Item and a ForeignItem with the same name. We don't care that the global was already created by a ForeignItem reference when we see the Item reference, as long as the LLVM types of the ForeignItem and Item match. Fixes #66464
1 parent a0d40f8 commit 32168a3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/librustc_codegen_llvm/consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,13 @@ impl CodegenCx<'ll, 'tcx> {
233233
ref attrs, span, kind: hir::ItemKind::Static(..), ..
234234
}) => {
235235
let sym_str = sym.as_str();
236-
if self.get_declared_value(&sym_str).is_some() {
237-
span_bug!(span, "Conflicting symbol names for static?");
236+
if let Some(g) = self.get_declared_value(&sym_str) {
237+
if self.val_ty(g) != self.type_ptr_to(llty) {
238+
span_bug!(span, "Conflicting types for static");
239+
}
238240
}
239241

240-
let g = self.define_global(&sym_str, llty).unwrap();
242+
let g = self.declare_global(&sym_str, llty);
241243

242244
if !self.tcx.is_reachable_non_generic(def_id) {
243245
unsafe {

0 commit comments

Comments
 (0)