diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-12-02 06:30:46 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-12-02 06:30:46 +0000 |
| commit | 6d27513f6ef02868752373db749b5d631ab0c2b1 (patch) | |
| tree | d6e2473c2a2b425587cf10ac0b50bd000db34c8f /clang/CodeGen/CodeGenModule.cpp | |
| parent | 41af8182d80e26c5c1f302b89c8de0007ea7df1d (diff) | |
| download | bcm5719-llvm-6d27513f6ef02868752373db749b5d631ab0c2b1.tar.gz bcm5719-llvm-6d27513f6ef02868752373db749b5d631ab0c2b1.zip | |
merge the llvm global variable when there are multiple C decls.
llvm-svn: 44507
Diffstat (limited to 'clang/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/CodeGen/CodeGenModule.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp index 51f758c5422..7ef4fe19deb 100644 --- a/clang/CodeGen/CodeGenModule.cpp +++ b/clang/CodeGen/CodeGenModule.cpp @@ -51,21 +51,28 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) { QualType ASTTy = cast<ValueDecl>(D)->getType(); const llvm::Type *Ty = getTypes().ConvertType(ASTTy); if (isa<FunctionDecl>(D)) { - const llvm::FunctionType *FTy = cast<llvm::FunctionType>(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<llvm::FunctionType>(Ty); return Entry = new llvm::Function(FTy, llvm::Function::ExternalLinkage, D->getName(), &getModule()); } assert(isa<FileVarDecl>(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()); |

