From: Chris Lattner Date: Sun, 2 Dec 2007 06:30:46 +0000 (+0000) Subject: merge the llvm global variable when there are multiple C decls. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fafad83da6eff6bf090f6eb2dc1019ace7473f38;p=clang merge the llvm global variable when there are multiple C decls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44507 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp index 51f758c542..7ef4fe19de 100644 --- a/CodeGen/CodeGenModule.cpp +++ b/CodeGen/CodeGenModule.cpp @@ -51,21 +51,28 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) { QualType ASTTy = cast(D)->getType(); const llvm::Type *Ty = getTypes().ConvertType(ASTTy); if (isa(D)) { - const llvm::FunctionType *FTy = cast(Ty); - // Check to see if the function already exists. if (llvm::Function *F = getModule().getFunction(D->getName())) { // If so, make sure it is the correct type. - return llvm::ConstantExpr::getBitCast(F, llvm::PointerType::get(FTy)); + return Entry = llvm::ConstantExpr::getBitCast(F, + llvm::PointerType::get(Ty)); } // FIXME: param attributes for sext/zext etc. + const llvm::FunctionType *FTy = cast(Ty); return Entry = new llvm::Function(FTy, llvm::Function::ExternalLinkage, D->getName(), &getModule()); } assert(isa(D) && "Unknown global decl!"); + if (llvm::GlobalVariable *GV = getModule().getGlobalVariable(D->getName())) { + // If so, make sure it is the correct type. + return Entry = llvm::ConstantExpr::getBitCast(GV, + llvm::PointerType::get(Ty)); + + } + return Entry = new llvm::GlobalVariable(Ty, false, llvm::GlobalValue::ExternalLinkage, 0, D->getName(), &getModule());