From c38f186f229b37875b73ecd4c1d44d62c38bc354 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 10 Apr 2014 01:40:15 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205948 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 10 ++++++++-- .../microsoft-abi-nontrivial-memptr-thunks.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index e26d6b2d0e..ca8b99a3cb 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -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 index 0000000000..becec2d86f --- /dev/null +++ b/test/CodeGenCXX/microsoft-abi-nontrivial-memptr-thunks.cpp @@ -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; -- 2.40.0