Skip to content

Commit

Permalink
Allow different global references to the same name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rinon committed Nov 19, 2019
1 parent a0d40f8 commit 32168a3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@ impl CodegenCx<'ll, 'tcx> {
ref attrs, span, kind: hir::ItemKind::Static(..), ..
}) => {
let sym_str = sym.as_str();
if self.get_declared_value(&sym_str).is_some() {
span_bug!(span, "Conflicting symbol names for static?");
if let Some(g) = self.get_declared_value(&sym_str) {
if self.val_ty(g) != self.type_ptr_to(llty) {
span_bug!(span, "Conflicting types for static");
}
}

let g = self.define_global(&sym_str, llty).unwrap();
let g = self.declare_global(&sym_str, llty);

if !self.tcx.is_reachable_non_generic(def_id) {
unsafe {
Expand Down

0 comments on commit 32168a3

Please sign in to comment.