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

2016-03-01 Thread David Majnemer via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL262379: [MSVC Compat] Correctly handle finallys nested 
within finallys (authored by majnemer).

Changed prior to commit:
  http://reviews.llvm.org/D17752?vs=49522=49525#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17752

Files:
  cfe/trunk/lib/CodeGen/CGException.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGen/exceptions-seh-finally.c

Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
@@ -669,6 +669,9 @@
 
   DidCallStackSave = false;
   CurCodeDecl = D;
+  if (const auto *FD = dyn_cast_or_null(D))
+if (FD->usesSEHTry())
+  CurSEHParent = FD;
   CurFuncDecl = (D ? D->getNonClosureContext() : nullptr);
   FnRetTy = RetTy;
   CurFn = Fn;
Index: cfe/trunk/lib/CodeGen/CGException.cpp
===
--- cfe/trunk/lib/CodeGen/CGException.cpp
+++ cfe/trunk/lib/CodeGen/CGException.cpp
@@ -1625,14 +1625,13 @@
   SmallString<128> Name;
   {
 llvm::raw_svector_ostream OS(Name);
-const Decl *ParentCodeDecl = ParentCGF.CurCodeDecl;
-const NamedDecl *Parent = dyn_cast_or_null(ParentCodeDecl);
-assert(Parent && "FIXME: handle unnamed decls (lambdas, blocks) with SEH");
+const FunctionDecl *ParentSEHFn = ParentCGF.CurSEHParent;
+assert(ParentSEHFn && "No CurSEHParent!");
 MangleContext  = CGM.getCXXABI().getMangleContext();
 if (IsFilter)
-  Mangler.mangleSEHFilterExpression(Parent, OS);
+  Mangler.mangleSEHFilterExpression(ParentSEHFn, OS);
 else
-  Mangler.mangleSEHFinallyBlock(Parent, OS);
+  Mangler.mangleSEHFinallyBlock(ParentSEHFn, OS);
   }
 
   FunctionArgList Args;
@@ -1679,6 +1678,7 @@
 
   StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args,
 OutlinedStmt->getLocStart(), OutlinedStmt->getLocStart());
+  CurSEHParent = ParentCGF.CurSEHParent;
 
   CGM.SetLLVMFunctionAttributes(nullptr, FnInfo, CurFn);
   EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter);
Index: cfe/trunk/lib/CodeGen/CodeGenFunction.h
===
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h
@@ -276,6 +276,8 @@
   /// potentially set the return value.
   bool SawAsmBlock;
 
+  const FunctionDecl *CurSEHParent = nullptr;
+
   /// True if the current function is an outlined SEH helper. This can be a
   /// finally block or filter expression.
   bool IsOutlinedSEHHelper;
@@ -1150,10 +1152,7 @@
 return getInvokeDestImpl();
   }
 
-  bool currentFunctionUsesSEHTry() const {
-const auto *FD = dyn_cast_or_null(CurCodeDecl);
-return FD && FD->usesSEHTry();
-  }
+  bool currentFunctionUsesSEHTry() const { return CurSEHParent != nullptr; }
 
   const TargetInfo () const { return Target; }
   llvm::LLVMContext () { return CGM.getLLVMContext(); }
Index: cfe/trunk/test/CodeGen/exceptions-seh-finally.c
===
--- cfe/trunk/test/CodeGen/exceptions-seh-finally.c
+++ cfe/trunk/test/CodeGen/exceptions-seh-finally.c
@@ -230,3 +230,28 @@
 
 // CHECK-LABEL: define internal void @"\01?fin$1@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@0@finally_within_finally@@"(
+// CHECK: call void @"\01?fin$0@0@finally_within_finally@@"({{.*}}) [ "funclet"(
+
+// CHECK-LABEL: define internal void @"\01?fin$0@0@finally_within_finally@@"(
+// CHECK: invoke void @might_crash(
+
+// CHECK: call void @"\01?fin$1@0@finally_within_finally@@"(
+// CHECK: call void @"\01?fin$1@0@finally_within_finally@@"({{.*}}) [ "funclet"(
+
+// CHECK-LABEL: define internal void @"\01?fin$1@0@finally_within_finally@@"(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-03-01 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


http://reviews.llvm.org/D17752



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-03-01 Thread David Majnemer via cfe-commits
majnemer updated this revision to Diff 49522.
majnemer added a comment.

- Address Reid's review comments


http://reviews.llvm.org/D17752

Files:
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  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@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@0@finally_within_finally@@"(
+// CHECK: call void @"\01?fin$0@0@finally_within_finally@@"({{.*}}) [ "funclet"(
+
+// CHECK-LABEL: define internal void @"\01?fin$0@0@finally_within_finally@@"(
+// CHECK: invoke void @might_crash(
+
+// CHECK: call void @"\01?fin$1@0@finally_within_finally@@"(
+// CHECK: call void @"\01?fin$1@0@finally_within_finally@@"({{.*}}) [ "funclet"(
+
+// CHECK-LABEL: define internal void @"\01?fin$1@0@finally_within_finally@@"(
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -276,6 +276,8 @@
   /// potentially set the return value.
   bool SawAsmBlock;
 
+  const FunctionDecl *CurSEHParent = nullptr;
+
   /// True if the current function is an outlined SEH helper. This can be a
   /// finally block or filter expression.
   bool IsOutlinedSEHHelper;
@@ -1150,10 +1152,7 @@
 return getInvokeDestImpl();
   }
 
-  bool currentFunctionUsesSEHTry() const {
-const auto *FD = dyn_cast_or_null(CurCodeDecl);
-return FD && FD->usesSEHTry();
-  }
+  bool currentFunctionUsesSEHTry() const { return CurSEHParent != nullptr; }
 
   const TargetInfo () const { return Target; }
   llvm::LLVMContext () { return CGM.getLLVMContext(); }
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -669,6 +669,9 @@
 
   DidCallStackSave = false;
   CurCodeDecl = D;
+  if (const auto *FD = dyn_cast_or_null(D))
+if (FD->usesSEHTry())
+  CurSEHParent = FD;
   CurFuncDecl = (D ? D->getNonClosureContext() : nullptr);
   FnRetTy = RetTy;
   CurFn = Fn;
Index: lib/CodeGen/CGException.cpp
===
--- lib/CodeGen/CGException.cpp
+++ lib/CodeGen/CGException.cpp
@@ -1625,14 +1625,13 @@
   SmallString<128> Name;
   {
 llvm::raw_svector_ostream OS(Name);
-const Decl *ParentCodeDecl = ParentCGF.CurCodeDecl;
-const NamedDecl *Parent = dyn_cast_or_null(ParentCodeDecl);
-assert(Parent && "FIXME: handle unnamed decls (lambdas, blocks) with SEH");
+const FunctionDecl *ParentSEHFn = ParentCGF.CurSEHParent;
+assert(ParentSEHFn && "No CurSEHParent!");
 MangleContext  = CGM.getCXXABI().getMangleContext();
 if (IsFilter)
-  Mangler.mangleSEHFilterExpression(Parent, OS);
+  Mangler.mangleSEHFilterExpression(ParentSEHFn, OS);
 else
-  Mangler.mangleSEHFinallyBlock(Parent, OS);
+  Mangler.mangleSEHFinallyBlock(ParentSEHFn, OS);
   }
 
   FunctionArgList Args;
@@ -1679,6 +1678,7 @@
 
   StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args,
 OutlinedStmt->getLocStart(), OutlinedStmt->getLocStart());
+  CurSEHParent = ParentCGF.CurSEHParent;
 
   CGM.SetLLVMFunctionAttributes(nullptr, FnInfo, CurFn);
   EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-03-01 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


Comment at: lib/CodeGen/CGException.cpp:1680-1682
@@ -1679,4 +1679,5 @@
 
   StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args,
 OutlinedStmt->getLocStart(), OutlinedStmt->getLocStart());
+  CurCodeDecl = ParentCGF.CurCodeDecl;
 

Let's have a new field for this. We don't want most of the behavior controlled 
by CurCodeDecl in the rest of CodeGen.


http://reviews.llvm.org/D17752



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits