[cfe-commits] r51767 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/static-forward-decl-fun.c

Eli Friedman eli.friedman at gmail.com
Fri May 30 04:13:19 PDT 2008


Author: efriedma
Date: Fri May 30 06:13:18 2008
New Revision: 51767

URL: http://llvm.org/viewvc/llvm-project?rev=51767&view=rev
Log:
Always check that the definition of a function has the correct type.  
This fixes a crash on the included testcase (found in NetHack).


Added:
    cfe/trunk/test/CodeGen/static-forward-decl-fun.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=51767&r1=51766&r2=51767&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri May 30 06:13:18 2008
@@ -187,7 +187,7 @@
                                                      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());
   

Added: cfe/trunk/test/CodeGen/static-forward-decl-fun.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/static-forward-decl-fun.c?rev=51767&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/static-forward-decl-fun.c (added)
+++ cfe/trunk/test/CodeGen/static-forward-decl-fun.c Fri May 30 06:13:18 2008
@@ -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;





More information about the cfe-commits mailing list