From fa9ab53d95e56b60ad44d279c558aa1e902a6d77 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 21 Apr 2009 19:28:58 +0000 Subject: Fix emission of static tentative definitions referenced from other static functions llvm-svn: 69699 --- clang/lib/CodeGen/CodeGenModule.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 9ae93599df1..80e4bd9f9bb 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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); } -- cgit v1.2.3