diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index e26d6b2d0efb34a1608952713946a96cec3ce004..ca8b99a3cbdf3eeb45deb573b91f92d756405ef0 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 0000000000000000000000000000000000000000..becec2d86f994935292e35b25678f721ae13982e --- /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;