r205948 - Avoid crashing when failing to emit a thunk

Reid Kleckner reid at kleckner.net
Wed Apr 9 18:40:15 PDT 2014


Author: rnk
Date: Wed Apr  9 20:40:15 2014
New Revision: 205948

URL: http://llvm.org/viewvc/llvm-project?rev=205948&view=rev
Log:
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.

Added:
    cfe/trunk/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=205948&r1=205947&r2=205948&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Apr  9 20:40:15 2014
@@ -2546,8 +2546,14 @@ RValue CodeGenFunction::EmitCall(const C
   // 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;

Added: cfe/trunk/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp?rev=205948&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp Wed Apr  9 20:40:15 2014
@@ -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;





More information about the cfe-commits mailing list