summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-03-29 14:19:55 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-03-29 14:19:55 +0000
commitaf3698066a1ea2e5ab4cc08ae9a59620cf18adb7 (patch)
tree6611f457cde58103bfc8f8c9005b7437ca7a2c0b
parent238b508aafd6199a98c09e5a600452e3496f03c3 (diff)
downloadbcm5719-llvm-af3698066a1ea2e5ab4cc08ae9a59620cf18adb7.tar.gz
bcm5719-llvm-af3698066a1ea2e5ab4cc08ae9a59620cf18adb7.zip
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. llvm-svn: 205099
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp12
-rw-r--r--clang/test/CodeGen/inline2.c9
2 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index addf8d09e41..92f49379f1b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -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 {
diff --git a/clang/test/CodeGen/inline2.c b/clang/test/CodeGen/inline2.c
index 670ae201f9b..84cd4db0277 100644
--- a/clang/test/CodeGen/inline2.c
+++ b/clang/test/CodeGen/inline2.c
@@ -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);
OpenPOWER on IntegriCloud