[WinEH] Don't create an alloca for unnamed catch parameters
authorReid Kleckner <reid@kleckner.net>
Tue, 7 Apr 2015 00:09:59 +0000 (00:09 +0000)
committerReid Kleckner <reid@kleckner.net>
Tue, 7 Apr 2015 00:09:59 +0000 (00:09 +0000)
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.

llvm-svn: 234264

clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/microsoft-abi-eh-catch.cpp
clang/test/CodeGenCXX/microsoft-abi-try-throw.cpp

index 2a76203e71c4225cbe5587d72cd127a151935a1f..f00cd9c81dff0700fe3fc6d4cf3bda8637b405a8 100644 (file)
@@ -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<CallEndCatchMSVC>(NormalAndEHCleanup);
index 15edef3d1319f2239dbe4ff20909aeabc9f87bf9..292fad2e4d6fee1ad882a3e8c32f90b6596ccccd 100644 (file)
@@ -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);
index a3a45a5468594fa8c2a010a519895649bd13d503..fed39761714ef18a2c25b1a1e2622346bc6cf87b 100644 (file)
@@ -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