summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-21 17:11:58 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-21 17:11:58 +0000
commitbeecd58e21ec458d543bd5ae332d8358578d0251 (patch)
tree654a2a949dcdb3e8f42d560070b8f2035d613fd8 /clang/lib/CodeGen/CodeGenModule.cpp
parent69223bb7f5a99de5d6acdbb5e79bf9bc2ab6faca (diff)
downloadbcm5719-llvm-beecd58e21ec458d543bd5ae332d8358578d0251.tar.gz
bcm5719-llvm-beecd58e21ec458d543bd5ae332d8358578d0251.zip
Explictly track tentative definitions within Sema, then hand those
tentative definitions off to the ASTConsumer at the end of the translation unit. Eliminate CodeGen's internal tracking of tentative definitions, and instead hook into ASTConsumer::CompleteTentativeDefinition. Also, tweak the definition-deferal logic for C++, where there are no tentative definitions. Fixes <rdar://problem/6808352>, and will make it much easier for precompiled headers to cope with tentative definitions in the future. llvm-svn: 69681
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0526e7845cc..9ae93599df1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -424,13 +424,6 @@ void CodeGenModule::EmitDeferred() {
// Otherwise, emit the definition and move on to the next one.
EmitGlobalDefinition(D);
}
-
- // Emit any tentative definitions, in reverse order so the most
- // important (merged) decl will be seen and emitted first.
- for (std::vector<const VarDecl*>::reverse_iterator
- it = TentativeDefinitions.rbegin(), ie = TentativeDefinitions.rend();
- it != ie; ++it)
- EmitTentativeDefinition(*it);
}
/// EmitAnnotateAttr - Generate the llvm::ConstantStruct which contains the
@@ -502,6 +495,7 @@ bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
const VarDecl *VD = cast<VarDecl>(Global);
assert(VD->isFileVarDecl() && "Invalid decl");
+
return VD->getStorageClass() == VarDecl::Static;
}
@@ -520,16 +514,14 @@ void CodeGenModule::EmitGlobal(const ValueDecl *Global) {
const VarDecl *VD = cast<VarDecl>(Global);
assert(VD->isFileVarDecl() && "Cannot emit local var decl as global.");
- // If this isn't a definition, defer code generation.
- if (!VD->getInit()) {
- // If this is a tentative definition, remember it so that we can
- // emit the common definition if needed. It is important to
- // defer tentative definitions, since they may have incomplete
- // type.
- if (!VD->hasExternalStorage())
- TentativeDefinitions.push_back(VD);
+ // In C++, if this is marked "extern", defer code generation.
+ if (getLangOptions().CPlusPlus &&
+ VD->getStorageClass() == VarDecl::Extern && !VD->getInit())
+ return;
+
+ // In C, if this isn't a definition, defer code generation.
+ if (!getLangOptions().CPlusPlus && !VD->getInit())
return;
- }
}
// Defer code generation when possible if this is a static definition, inline
@@ -727,6 +719,9 @@ void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {
// See if we have already defined this (as a variable), if so we do
// not need to do anything.
llvm::GlobalValue *GV = GlobalDeclMap[getMangledName(D)];
+ if (!GV && MayDeferGeneration(D)) // this variable was never referenced
+ return;
+
if (llvm::GlobalVariable *Var = dyn_cast_or_null<llvm::GlobalVariable>(GV))
if (Var->hasInitializer())
return;
OpenPOWER on IntegriCloud