r205099 - CodeGen: Don't crash when replacing functions

David Majnemer david.majnemer at gmail.com
Sat Mar 29 07:19:55 PDT 2014


Author: majnemer
Date: Sat Mar 29 09:19:55 2014
New Revision: 205099

URL: http://llvm.org/viewvc/llvm-project?rev=205099&view=rev
Log:
CodeGen: Don't crash when replacing functions

The peculiarities of C99 create scenario where an LLVM IR function
declaration may need to be replaced with a definition baring a different
type because the prototype and definition are not required to agree.

However, we were not properly deferring this when it occurred.

This fixes PR19280.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/inline2.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=205099&r1=205098&r2=205099&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat Mar 29 09:19:55 2014
@@ -1177,12 +1177,14 @@ void CodeGenModule::EmitGlobal(GlobalDec
       if (!FD->doesDeclarationForceExternallyVisibleDefinition())
         return;
 
-      const FunctionDecl *InlineDefinition = 0;
-      FD->getBody(InlineDefinition);
-
       StringRef MangledName = getMangledName(GD);
-      DeferredDecls.erase(MangledName);
-      EmitGlobalDefinition(InlineDefinition);
+
+      // Compute the function info and LLVM type.
+      const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+      llvm::Type *Ty = getTypes().GetFunctionType(FI);
+
+      GetOrCreateLLVMFunction(MangledName, Ty, GD, /*ForVTable=*/false,
+                              /*DontDefer=*/false);
       return;
     }
   } else {

Modified: cfe/trunk/test/CodeGen/inline2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/inline2.c?rev=205099&r1=205098&r2=205099&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/inline2.c (original)
+++ cfe/trunk/test/CodeGen/inline2.c Sat Mar 29 09:19:55 2014
@@ -39,6 +39,9 @@ extern int f7(void) { return 0; }
 // CHECK-GNU89-LABEL: define i32 @fA()
 inline int fA(void) { return 0; }
 
+// CHECK-GNU89-LABEL: define i32 @fB()
+inline int fB() { return 0; }
+
 // CHECK-GNU89-LABEL: define available_externally i32 @f4()
 // CHECK-C99-LABEL: define i32 @f4()
 int f4(void);
@@ -56,7 +59,11 @@ extern inline int f9(void) { return 0; }
 
 // CHECK-C99-LABEL: define available_externally i32 @fA()
 
+// CHECK-C99-LABEL: define i32 @fB()
+
 int test_all() { 
   return f0() + f1() + f2() + f3() + f4() + f5() + f6() + f7() + f8() + f9() 
-    + fA();
+    + fA() + fB();
 }
+
+int fB(void);





More information about the cfe-commits mailing list