r315707 - [SEH] Use the SEH personality on frontend-outlined funclets

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 13 09:55:14 PDT 2017


Author: rnk
Date: Fri Oct 13 09:55:14 2017
New Revision: 315707

URL: http://llvm.org/viewvc/llvm-project?rev=315707&view=rev
Log:
[SEH] Use the SEH personality on frontend-outlined funclets

This allows __try inside __finally to work.

Fixes PR34939

Modified:
    cfe/trunk/lib/CodeGen/CGException.cpp
    cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=315707&r1=315706&r2=315707&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Fri Oct 13 09:55:14 2017
@@ -225,7 +225,12 @@ const EHPersonality &EHPersonality::get(
 }
 
 const EHPersonality &EHPersonality::get(CodeGenFunction &CGF) {
-  return get(CGF.CGM, dyn_cast_or_null<FunctionDecl>(CGF.CurCodeDecl));
+  const auto *FD = CGF.CurCodeDecl;
+  // For outlined finallys and filters, use the SEH personality in case they
+  // contain more SEH. This mostly only affects finallys. Filters could
+  // hypothetically use gnu statement expressions to sneak in nested SEH.
+  FD = FD ? FD : CGF.CurSEHParent;
+  return get(CGF.CGM, dyn_cast_or_null<FunctionDecl>(FD));
 }
 
 static llvm::Constant *getPersonalityFn(CodeGenModule &CGM,

Modified: cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp?rev=315707&r1=315706&r2=315707&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp Fri Oct 13 09:55:14 2017
@@ -76,6 +76,27 @@ extern "C" void use_seh() {
 // CHECK: [[cont]]
 // CHECK: br label %[[ret]]
 
+extern "C" void nested_finally() {
+  __try {
+    might_throw();
+  } __finally {
+    __try {
+      might_throw();
+    } __finally {
+    }
+  }
+}
+
+// CHECK-LABEL: define void @nested_finally() #{{[0-9]+}}
+// CHECK-SAME:  personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
+// CHECK: invoke void @might_throw()
+// CHECK: call void @"\01?fin$0 at 0@nested_finally@@"(i8 1, i8* {{.*}})
+
+// CHECK-LABEL: define internal void @"\01?fin$0 at 0@nested_finally@@"
+// CHECK-SAME:  personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
+// CHECK: invoke void @might_throw()
+// CHECK: call void @"\01?fin$1 at 0@nested_finally@@"(i8 1, i8* {{.*}})
+
 void use_seh_in_lambda() {
   ([]() {
     __try {




More information about the cfe-commits mailing list