]> granicus.if.org Git - clang/commitdiff
Fix emission of static tentative definitions referenced from other static functions
authorDouglas Gregor <dgregor@apple.com>
Tue, 21 Apr 2009 19:28:58 +0000 (19:28 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 21 Apr 2009 19:28:58 +0000 (19:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69699 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp

index 9ae93599df1691e867b6efcbec2697727ca96dcd..80e4bd9f9bbecad9d9c60c15c3c28f01c7fba6d9 100644 (file)
@@ -716,16 +716,18 @@ CodeGenModule::CreateRuntimeVariable(const llvm::Type *Ty,
 void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {
   assert(!D->getInit() && "Cannot emit definite definitions here!");
 
-  // 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())
+  if (MayDeferGeneration(D)) {
+    // If we have not seen a reference to this variable yet, place it
+    // into the deferred declarations table to be emitted if needed
+    // later.
+    const char *MangledName = getMangledName(D);
+    if (GlobalDeclMap.count(MangledName) == 0) {
+      DeferredDecls[MangledName] = D;
       return;
-  
+    }
+  }
+
+  // The tentative definition is the only definition.
   EmitGlobalVarDefinition(D);
 }