From: Douglas Gregor Date: Tue, 21 Apr 2009 19:28:58 +0000 (+0000) Subject: Fix emission of static tentative definitions referenced from other static functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7520bd1de12af10ea08c662440565adbdf589317;p=clang Fix emission of static tentative definitions referenced from other static functions git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69699 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 9ae93599df..80e4bd9f9b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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(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); }