r234264 - [WinEH] Don't create an alloca for unnamed catch parameters

Reid Kleckner reid at kleckner.net
Mon Apr 6 17:10:00 PDT 2015


Author: rnk
Date: Mon Apr  6 19:09:59 2015
New Revision: 234264

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

Modified:
    cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-catch.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=234264&r1=234263&r2=234264&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Mon Apr  6 19:09:59 2015
@@ -809,7 +809,9 @@ void MicrosoftCXXABI::emitBeginCatch(Cod
   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<CallEndCatchMSVC>(NormalAndEHCleanup);

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-catch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-catch.cpp?rev=234264&r1=234263&r2=234264&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-catch.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-catch.cpp Mon Apr  6 19:09:59 2015
@@ -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);

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp?rev=234264&r1=234263&r2=234264&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp Mon Apr  6 19:09:59 2015
@@ -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





More information about the cfe-commits mailing list