[clang] a3f6884 - [Windows SEH] Fix ehcleanup crash for Windows -EHa
Phoebe Wang via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 11 23:44:21 PDT 2023
Author: Phoebe Wang
Date: 2023-04-12T14:44:11+08:00
New Revision: a3f688422c44519b578f9ae728b955aabe6b494e
URL: https://github.com/llvm/llvm-project/commit/a3f688422c44519b578f9ae728b955aabe6b494e
DIFF: https://github.com/llvm/llvm-project/commit/a3f688422c44519b578f9ae728b955aabe6b494e.diff
LOG: [Windows SEH] Fix ehcleanup crash for Windows -EHa
`Builder.GetInsertBlock()` may return null sometimes. https://godbolt.org/z/n1Ph47jP1
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D147867
Added:
Modified:
clang/lib/CodeGen/CGCleanup.cpp
clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 175d91488efd0..0bbab283603d9 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -782,7 +782,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
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 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
if (!Personality.isMSVCPersonality()) {
EHStack.pushTerminate();
PushedTerminate = true;
+ } else if (IsEHa && getInvokeDest()) {
+ EmitSehCppScopeEnd();
}
// We only actually emit the cleanup code if the cleanup is either
diff --git a/clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp b/clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
index a65ab39bea3e4..822c629bc207f 100644
--- a/clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
+++ b/clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
@@ -12,3 +12,20 @@ void foo() {
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();
+}
More information about the cfe-commits
mailing list