]> granicus.if.org Git - clang/commitdiff
Always check that the definition of a function has the correct type.
authorEli Friedman <eli.friedman@gmail.com>
Fri, 30 May 2008 11:13:18 +0000 (11:13 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 30 May 2008 11:13:18 +0000 (11:13 +0000)
This fixes a crash on the included testcase (found in NetHack).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51767 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/static-forward-decl-fun.c [new file with mode: 0644]

index e5bd15e8566ded5e026cefcabb30f823d9a7daf8..43c7129010b28516f5f8f4ecce039052a356801a 100644 (file)
@@ -187,7 +187,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunctionDecl(const FunctionDecl *D,
                                                      bool isDefinition) {
   // See if it is already in the map.  If so, just return it.
   llvm::Constant *&Entry = GlobalDeclMap[D];
-  if (Entry) return Entry;
+  if (!isDefinition && Entry) return Entry;
 
   const llvm::Type *Ty = getTypes().ConvertType(D->getType());
   
diff --git a/test/CodeGen/static-forward-decl-fun.c b/test/CodeGen/static-forward-decl-fun.c
new file mode 100644 (file)
index 0000000..636c8fb
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang %s -emit-llvm
+
+static int staticfun(void);
+int (*staticuse1)(void) = staticfun;
+static int staticfun() {return 1;}
+int (*staticuse2)(void) = staticfun;