]> granicus.if.org Git - clang/commitdiff
Avoid crashing when failing to emit a thunk
authorReid Kleckner <reid@kleckner.net>
Thu, 10 Apr 2014 01:40:15 +0000 (01:40 +0000)
committerReid Kleckner <reid@kleckner.net>
Thu, 10 Apr 2014 01:40:15 +0000 (01:40 +0000)
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.

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

lib/CodeGen/CGCall.cpp
test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp [new file with mode: 0644]

index e26d6b2d0efb34a1608952713946a96cec3ce004..ca8b99a3cbdf3eeb45deb573b91f92d756405ef0 100644 (file)
@@ -2546,8 +2546,14 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // 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;
diff --git a/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp b/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp
new file mode 100644 (file)
index 0000000..becec2d
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple=i386-pc-win32 %s -verify
+
+struct A {
+  A();
+  ~A();
+  int a;
+};
+struct B {
+  virtual void f(A); // expected-error {{cannot compile this non-trivial argument copy for thunk yet}}
+};
+void (B::*mp)(A) = &B::f;