Avoid crashing when failing to emit a thunk
If we crash, we raise a crash handler dialog, and that's really
annoying. Even though we can't emit correct IR until we have musttail,
don't crash.
llvm-svn: 205948
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index e26d6b2d..ca8b99a 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2546,8 +2546,14 @@
// FIXME: Do this earlier rather than hacking it in here!
llvm::Value *ArgMemory = 0;
if (llvm::StructType *ArgStruct = CallInfo.getArgStruct()) {
- llvm::AllocaInst *AI = new llvm::AllocaInst(
- ArgStruct, "argmem", CallArgs.getStackBase()->getNextNode());
+ llvm::Instruction *IP = CallArgs.getStackBase();
+ llvm::AllocaInst *AI;
+ if (IP) {
+ IP = IP->getNextNode();
+ AI = new llvm::AllocaInst(ArgStruct, "argmem", IP);
+ } else {
+ AI = Builder.CreateAlloca(ArgStruct, nullptr, "argmem");
+ }
AI->setUsedWithInAlloca(true);
assert(AI->isUsedWithInAlloca() && !AI->isStaticAlloca());
ArgMemory = AI;