]> granicus.if.org Git - clang/commitdiff
CodeGen: Don't crash when replacing functions
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 29 Mar 2014 14:19:55 +0000 (14:19 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 29 Mar 2014 14:19:55 +0000 (14:19 +0000)
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.

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

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/inline2.c

index addf8d09e41d43aa09ef4b49f0adf66ee58c9139..92f49379f1b895acd3a1db065f0d6bf3d5f16cfd 100644 (file)
@@ -1177,12 +1177,14 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
       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 {
index 670ae201f9bae76d2d579c53fa55c486125c94af..84cd4db027749ec5edaace9610e619d5de54a4dd 100644 (file)
@@ -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);