Author: majnemer Date: Wed Feb 24 11:02:45 2016 New Revision: 261751 URL: http://llvm.org/viewvc/llvm-project?rev=261751&view=rev Log: [WinEH] Make sure terminate handlers have funclet operands
Calls to the terminate handler must be annotated within the exception region they are within. Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/lib/CodeGen/CGException.cpp cfe/trunk/test/CodeGenCXX/exceptions-cxx-new.cpp cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-terminate.cpp Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=261751&r1=261750&r2=261751&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Feb 24 11:02:45 2016 @@ -3064,16 +3064,6 @@ CodeGenFunction::EmitRuntimeCall(llvm::V return EmitRuntimeCall(callee, None, name); } -/// Emits a simple call (never an invoke) to the given runtime function. -llvm::CallInst * -CodeGenFunction::EmitRuntimeCall(llvm::Value *callee, - ArrayRef<llvm::Value*> args, - const llvm::Twine &name) { - llvm::CallInst *call = Builder.CreateCall(callee, args, name); - call->setCallingConv(getRuntimeCC()); - return call; -} - // Calls which may throw must have operand bundles indicating which funclet // they are nested within. static void @@ -3092,6 +3082,19 @@ getBundlesForFunclet(llvm::Value *Callee BundleList.emplace_back("funclet", CurrentFuncletPad); } +/// Emits a simple call (never an invoke) to the given runtime function. +llvm::CallInst * +CodeGenFunction::EmitRuntimeCall(llvm::Value *callee, + ArrayRef<llvm::Value*> args, + const llvm::Twine &name) { + SmallVector<llvm::OperandBundleDef, 1> BundleList; + getBundlesForFunclet(callee, CurrentFuncletPad, BundleList); + + llvm::CallInst *call = Builder.CreateCall(callee, args, BundleList, name); + call->setCallingConv(getRuntimeCC()); + return call; +} + /// Emits a call or invoke to the given noreturn runtime function. void CodeGenFunction::EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee, ArrayRef<llvm::Value*> args) { Modified: cfe/trunk/lib/CodeGen/CGException.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=261751&r1=261750&r2=261751&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGException.cpp (original) +++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Feb 24 11:02:45 2016 @@ -1326,11 +1326,13 @@ llvm::BasicBlock *CodeGenFunction::getTe TerminateHandler = createBasicBlock("terminate.handler"); Builder.SetInsertPoint(TerminateHandler); llvm::Value *Exn = nullptr; + SaveAndRestore<llvm::Instruction *> RestoreCurrentFuncletPad( + CurrentFuncletPad); if (EHPersonality::get(*this).usesFuncletPads()) { llvm::Value *ParentPad = CurrentFuncletPad; if (!ParentPad) ParentPad = llvm::ConstantTokenNone::get(CGM.getLLVMContext()); - Builder.CreateCleanupPad(ParentPad); + CurrentFuncletPad = Builder.CreateCleanupPad(ParentPad); } else { if (getLangOpts().CPlusPlus) Exn = getExceptionFromSlot(); Modified: cfe/trunk/test/CodeGenCXX/exceptions-cxx-new.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/exceptions-cxx-new.cpp?rev=261751&r1=261750&r2=261751&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/exceptions-cxx-new.cpp (original) +++ cfe/trunk/test/CodeGenCXX/exceptions-cxx-new.cpp Wed Feb 24 11:02:45 2016 @@ -72,6 +72,6 @@ void test_cleanup() { // CHECK: ret void // CHECK: [[TERMINATE]] -// CHECK: cleanuppad within none [] -// CHECK-NEXT: call void @"\01?terminate@@YAXXZ"() +// CHECK: %[[CLEANUPPAD:.*]] = cleanuppad within none [] +// CHECK-NEXT: call void @"\01?terminate@@YAXXZ"() {{.*}} [ "funclet"(token %[[CLEANUPPAD]]) ] Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-terminate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-terminate.cpp?rev=261751&r1=261750&r2=261751&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-terminate.cpp (original) +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-terminate.cpp Wed Feb 24 11:02:45 2016 @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc -mconstructor-aliases -fexceptions -fcxx-exceptions -fms-compatibility-version=18.00 | FileCheck -check-prefix=MSVC2013 %s -// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc -mconstructor-aliases -fexceptions -fcxx-exceptions -fms-compatibility-version=19.00 | FileCheck -check-prefix=MSVC2015 %s +// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc -mconstructor-aliases -fexceptions -fcxx-exceptions -fms-compatibility-version=18.00 | FileCheck -check-prefix=MSVC2013 -check-prefix=CHECK %s +// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc -mconstructor-aliases -fexceptions -fcxx-exceptions -fms-compatibility-version=19.00 | FileCheck -check-prefix=MSVC2015 -check-prefix=CHECK %s void may_throw(); void never_throws() noexcept(true) { @@ -9,7 +9,8 @@ void never_throws() noexcept(true) { // CHECK-LABEL: define void @"\01?never_throws@@YAXXZ"() // CHECK-SAME: personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) // CHECK: invoke void @"\01?may_throw@@YAXXZ"() -// CHECK: cleanuppad within none [] +// CHECK: %[[cp:.*]] = cleanuppad within none [] // MSVC2013: call void @"\01?terminate@@YAXXZ"() // MSVC2015: call void @__std_terminate() +// CHECK-SAME: [ "funclet"(token %[[cp]]) ] // CHECK-NEXT: unreachable _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits