From 46d6052cd771f3bd99d3e5a8d259114f1cc5f929 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 13 Oct 2017 16:55:14 +0000 Subject: [PATCH] [SEH] Use the SEH personality on frontend-outlined funclets This allows __try inside __finally to work. Fixes PR34939 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315707 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGException.cpp | 7 ++++++- test/CodeGenCXX/exceptions-seh.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index 709ed00264..1bff6490b8 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -225,7 +225,12 @@ const EHPersonality &EHPersonality::get(CodeGenModule &CGM, } const EHPersonality &EHPersonality::get(CodeGenFunction &CGF) { - return get(CGF.CGM, dyn_cast_or_null(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(FD)); } static llvm::Constant *getPersonalityFn(CodeGenModule &CGM, diff --git a/test/CodeGenCXX/exceptions-seh.cpp b/test/CodeGenCXX/exceptions-seh.cpp index 4f7eacd667..fa2d834c1e 100644 --- a/test/CodeGenCXX/exceptions-seh.cpp +++ b/test/CodeGenCXX/exceptions-seh.cpp @@ -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@0@nested_finally@@"(i8 1, i8* {{.*}}) + +// CHECK-LABEL: define internal void @"\01?fin$0@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@0@nested_finally@@"(i8 1, i8* {{.*}}) + void use_seh_in_lambda() { ([]() { __try { -- 2.49.0