From e96d56ddc61d7cf1e67da2c17017156cc81a0c31 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 7 Apr 2015 00:09:59 +0000 Subject: [PATCH] [WinEH] Don't create an alloca for unnamed catch parameters The catch object parameter to llvm.eh.begincatch is optional, and can be null. We can save some ourselves the stack space, copy ctor, and dtor calls if we pass null. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234264 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MicrosoftCXXABI.cpp | 4 +++- test/CodeGenCXX/microsoft-abi-eh-catch.cpp | 12 ++++++++++++ test/CodeGenCXX/microsoft-abi-try-throw.cpp | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp index 2a76203e71..f00cd9c81d 100644 --- a/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -809,7 +809,9 @@ void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF, llvm::Function *BeginCatch = CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_begincatch); - if (!CatchParam) { + // If this is a catch-all or the catch parameter is unnamed, we don't need to + // emit an alloca to the object. + if (!CatchParam || !CatchParam->getDeclName()) { llvm::Value *Args[2] = {Exn, llvm::Constant::getNullValue(CGF.Int8PtrTy)}; CGF.EmitNounwindRuntimeCall(BeginCatch, Args); CGF.EHStack.pushCleanup(NormalAndEHCleanup); diff --git a/test/CodeGenCXX/microsoft-abi-eh-catch.cpp b/test/CodeGenCXX/microsoft-abi-eh-catch.cpp index 15edef3d13..292fad2e4d 100644 --- a/test/CodeGenCXX/microsoft-abi-eh-catch.cpp +++ b/test/CodeGenCXX/microsoft-abi-eh-catch.cpp @@ -48,6 +48,18 @@ extern "C" void catch_int() { // WIN64: call void @handle_exception(i8* %[[e_i8]]) // WIN64: call void @llvm.eh.endcatch() +extern "C" void catch_int_unnamed() { + try { + might_throw(); + } catch (int) { + } +} + +// WIN64-LABEL: define void @catch_int_unnamed() +// WIN64: landingpad { i8*, i32 } +// WIN64: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* null) +// WIN64: call void @llvm.eh.endcatch() + struct A { A(); A(const A &o); diff --git a/test/CodeGenCXX/microsoft-abi-try-throw.cpp b/test/CodeGenCXX/microsoft-abi-try-throw.cpp index a3a45a5468..fed3976171 100644 --- a/test/CodeGenCXX/microsoft-abi-try-throw.cpp +++ b/test/CodeGenCXX/microsoft-abi-try-throw.cpp @@ -21,7 +21,7 @@ int main() { external(); // TRY: invoke void @"\01?external@@YAXXZ" } catch (int) { rv = 1; - // TRY: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* %{{.*}}) + // TRY: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* null) // TRY: call void @llvm.eh.endcatch() } #endif -- 2.40.0