[PATCH] D17752: [MSVC Compat] Correctly handle finallys nested within finallys

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 29 22:54:35 PST 2016


majnemer created this revision.
majnemer added reviewers: rnk, andrew.w.kaylor.
majnemer added a subscriber: cfe-commits.

We'd lose track of the parent CodeGenFunction, leading us to get
confused with regard to which function a nested finally belonged to.

http://reviews.llvm.org/D17752

Files:
  lib/CodeGen/CGException.cpp
  test/CodeGen/exceptions-seh-finally.c

Index: test/CodeGen/exceptions-seh-finally.c
===================================================================
--- test/CodeGen/exceptions-seh-finally.c
+++ test/CodeGen/exceptions-seh-finally.c
@@ -230,3 +230,28 @@
 
 // CHECK-LABEL: define internal void @"\01?fin$1 at 0@nested___finally___finally_with_eh_edge@@"({{.*}})
 // CHECK: unreachable
+
+void finally_within_finally() {
+  __try {
+    might_crash();
+  } __finally {
+    __try {
+      might_crash();
+    } __finally {
+    }
+  }
+}
+
+// CHECK-LABEL: define void @finally_within_finally(
+// CHECK: invoke void @might_crash(
+
+// CHECK: call void @"\01?fin$0 at 0@finally_within_finally@@"(
+// CHECK: call void @"\01?fin$0 at 0@finally_within_finally@@"({{.*}}) [ "funclet"(
+
+// CHECK-LABEL: define internal void @"\01?fin$0 at 0@finally_within_finally@@"(
+// CHECK: invoke void @might_crash(
+
+// CHECK: call void @"\01?fin$1 at 0@finally_within_finally@@"(
+// CHECK: call void @"\01?fin$1 at 0@finally_within_finally@@"({{.*}}) [ "funclet"(
+
+// CHECK-LABEL: define internal void @"\01?fin$1 at 0@finally_within_finally@@"(
Index: lib/CodeGen/CGException.cpp
===================================================================
--- lib/CodeGen/CGException.cpp
+++ lib/CodeGen/CGException.cpp
@@ -1679,6 +1679,7 @@
 
   StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args,
                 OutlinedStmt->getLocStart(), OutlinedStmt->getLocStart());
+  CurCodeDecl = ParentCGF.CurCodeDecl;
 
   CGM.SetLLVMFunctionAttributes(nullptr, FnInfo, CurFn);
   EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17752.49455.patch
Type: text/x-patch
Size: 1563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160301/2a3f148a/attachment.bin>


More information about the cfe-commits mailing list