Skip to content

Commit 3a38e93

Browse files
hahnjotru
authored andcommitted
[CodeGen] Clean up access to EmittedDeferredDecls, NFCI.
GlobalDecls should only be added to EmittedDeferredDecls if they need reemission. This is checked in addEmittedDeferredDecl, which is called via addDeferredDeclToEmit. Extend these checks to also handle VarDecls (for lambdas, as tested in Interpreter/lambda.cpp) and remove the direct access of EmittedDeferredDecls in EmitGlobal that may actually end up duplicating FunctionDecls. Differential Revision: https://reviews.llvm.org/D156897 (cherry picked from commit b719e41)
1 parent c202e5c commit 3a38e93

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,7 +3664,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
36643664
// The value must be emitted, but cannot be emitted eagerly.
36653665
assert(!MayBeEmittedEagerly(Global));
36663666
addDeferredDeclToEmit(GD);
3667-
EmittedDeferredDecls[MangledName] = GD;
36683667
} else {
36693668
// Otherwise, remember that we saw a deferred decl with this name. The
36703669
// first use of the mangled name will cause it to move into
@@ -4404,7 +4403,6 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
44044403
// DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
44054404
// don't need it anymore).
44064405
addDeferredDeclToEmit(DDI->second);
4407-
EmittedDeferredDecls[DDI->first] = DDI->second;
44084406
DeferredDecls.erase(DDI);
44094407

44104408
// Otherwise, there are cases we have to worry about where we're
@@ -4685,7 +4683,6 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
46854683
// Move the potentially referenced deferred decl to the DeferredDeclsToEmit
46864684
// list, and remove it from DeferredDecls (since we don't need it anymore).
46874685
addDeferredDeclToEmit(DDI->second);
4688-
EmittedDeferredDecls[DDI->first] = DDI->second;
46894686
DeferredDecls.erase(DDI);
46904687
}
46914688

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,15 @@ class CodeGenModule : public CodeGenTypeCache {
361361
llvm::DenseMap<llvm::StringRef, GlobalDecl> EmittedDeferredDecls;
362362

363363
void addEmittedDeferredDecl(GlobalDecl GD) {
364-
if (!llvm::isa<FunctionDecl>(GD.getDecl()))
365-
return;
366-
llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
367-
if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
364+
// Assume a linkage by default that does not need reemission.
365+
auto L = llvm::GlobalValue::ExternalLinkage;
366+
if (llvm::isa<FunctionDecl>(GD.getDecl()))
367+
L = getFunctionLinkage(GD);
368+
else if (auto *VD = llvm::dyn_cast<VarDecl>(GD.getDecl()))
369+
L = getLLVMLinkageVarDefinition(VD);
370+
371+
if (llvm::GlobalValue::isInternalLinkage(L) ||
372+
llvm::GlobalValue::isLinkOnceLinkage(L) ||
368373
llvm::GlobalValue::isWeakLinkage(L)) {
369374
EmittedDeferredDecls[getMangledName(GD)] = GD;
370375
}

0 commit comments

Comments
 (0)