[PATCH] D147867: [Windows SEH] Fix ehcleanup crash for Windows -EHa

Phoebe Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 11 23:44:29 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGa3f688422c44: [Windows SEH] Fix ehcleanup crash for Windows -EHa (authored by pengfei).

Changed prior to commit:
  https://reviews.llvm.org/D147867?vs=511935&id=512662#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147867/new/

https://reviews.llvm.org/D147867

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
===================================================================
--- clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
@@ -12,3 +12,20 @@
   return;
   }
 }
+
+__declspec(noreturn) void bar();
+class baz {
+public:
+  ~baz();
+};
+
+// CHECK: define dso_local void @"?qux@@YAXXZ
+// CHECK: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: llvm.seh.try
+// CHECK-NOT: llvm.seh.scope.end
+
+// We don't need to generate llvm.seh.scope.end for unreachable.
+void qux() {
+  baz a;
+  bar();
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===================================================================
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -782,7 +782,7 @@
   if (!RequiresNormalCleanup) {
     // Mark CPP scope end for passed-by-value Arg temp
     //   per Windows ABI which is "normally" Cleanup in callee
-    if (IsEHa && getInvokeDest()) {
+    if (IsEHa && getInvokeDest() && Builder.GetInsertBlock()) {
       if (Personality.isMSVCXXPersonality())
         EmitSehCppScopeEnd();
     }
@@ -1031,6 +1031,8 @@
     if (!Personality.isMSVCPersonality()) {
       EHStack.pushTerminate();
       PushedTerminate = true;
+    } else if (IsEHa && getInvokeDest()) {
+      EmitSehCppScopeEnd();
     }
 
     // We only actually emit the cleanup code if the cleanup is either


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147867.512662.patch
Type: text/x-patch
Size: 1441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230412/f982cd30/attachment.bin>


More information about the cfe-commits mailing list