Skip to content

Commit

Permalink
Rollup merge of rust-lang#66534 - immunant:multiple_global_decls, r=e…
Browse files Browse the repository at this point in the history
…ddyb

Allow global references via ForeignItem and Item for the same symbol name during LLVM codegen

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 rust-lang#66464
  • Loading branch information
tmandry authored Nov 27, 2019
2 parents 5139b53 + 32168a3 commit 8a7a9f2
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 8a7a9f2

Please sign in to comment.