diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -361,10 +361,15 @@ llvm::DenseMap EmittedDeferredDecls; void addEmittedDeferredDecl(GlobalDecl GD) { - if (!llvm::isa(GD.getDecl())) - return; - llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD); - if (llvm::GlobalValue::isLinkOnceLinkage(L) || + // Assume a linkage by default that does not need reemission. + auto L = llvm::GlobalValue::ExternalLinkage; + if (llvm::isa(GD.getDecl())) + L = getFunctionLinkage(GD); + else if (auto *VD = llvm::dyn_cast(GD.getDecl())) + L = getLLVMLinkageVarDefinition(VD); + + if (llvm::GlobalValue::isInternalLinkage(L) || + llvm::GlobalValue::isLinkOnceLinkage(L) || llvm::GlobalValue::isWeakLinkage(L)) { EmittedDeferredDecls[getMangledName(GD)] = GD; } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3677,7 +3677,6 @@ // The value must be emitted, but cannot be emitted eagerly. assert(!MayBeEmittedEagerly(Global)); addDeferredDeclToEmit(GD); - EmittedDeferredDecls[MangledName] = GD; } else { // Otherwise, remember that we saw a deferred decl with this name. The // first use of the mangled name will cause it to move into @@ -4417,7 +4416,6 @@ // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we // don't need it anymore). addDeferredDeclToEmit(DDI->second); - EmittedDeferredDecls[DDI->first] = DDI->second; DeferredDecls.erase(DDI); // Otherwise, there are cases we have to worry about where we're @@ -4677,7 +4675,6 @@ // Move the potentially referenced deferred decl to the DeferredDeclsToEmit // list, and remove it from DeferredDecls (since we don't need it anymore). addDeferredDeclToEmit(DDI->second); - EmittedDeferredDecls[DDI->first] = DDI->second; DeferredDecls.erase(DDI); }