From c5b3aab66bc3a08acc4c00aeeebc5799ad9e8e4f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 2 Dec 2007 05:56:05 +0000 Subject: [PATCH] merge functions with multiple function decls if they have the same name. llvm-svn: 44505 --- clang/CodeGen/CodeGenModule.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp index 54009b0e4235..b76d5e35eefc 100644 --- a/clang/CodeGen/CodeGenModule.cpp +++ b/clang/CodeGen/CodeGenModule.cpp @@ -40,6 +40,13 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) { 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)); + } + // FIXME: param attributes for sext/zext etc. return Entry = new llvm::Function(FTy, llvm::Function::ExternalLinkage, D->getName(), &getModule());