]> granicus.if.org Git - clang/commitdiff
merge functions with multiple function decls if they have the same name.
authorChris Lattner <sabre@nondot.org>
Sun, 2 Dec 2007 05:56:05 +0000 (05:56 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 2 Dec 2007 05:56:05 +0000 (05:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44505 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CodeGenModule.cpp

index 54009b0e4235b60263f07f80473fe0ef698d023d..b76d5e35eefc92e64a9993c2e5a716d7f5a3f7a7 100644 (file)
@@ -40,6 +40,13 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) {
   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));
+    }
+    
     // FIXME: param attributes for sext/zext etc.
     return Entry = new llvm::Function(FTy, llvm::Function::ExternalLinkage,
                                       D->getName(), &getModule());