pengfei created this revision.
pengfei added reviewers: tentzen, efriedma, LuoYuanke, jyu2.
Herald added subscribers: kbarton, nemanjai.
Herald added a project: All.
pengfei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`Builder.GetInsertBlock()` may return null sometimes. 
https://godbolt.org/z/n1Ph47jP1


Repository:
  rG LLVM Github Monorepo

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
+
+// FIXME: We may need to generate llvm.seh.scope.end or remove 
llvm.seh.scope.begin.
+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


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
+
+// FIXME: We may need to generate llvm.seh.scope.end or remove llvm.seh.scope.begin.
+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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to