[clang] 0cc66f3 - [Windows SEH] Fix catch+return crash for Windows -EHa

Phoebe Wang via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 31 23:53:42 PDT 2023


Author: Phoebe Wang
Date: 2023-04-01T14:53:33+08:00
New Revision: 0cc66f3c779b80a199d692fa84f7ed8d29373d1c

URL: https://github.com/llvm/llvm-project/commit/0cc66f3c779b80a199d692fa84f7ed8d29373d1c
DIFF: https://github.com/llvm/llvm-project/commit/0cc66f3c779b80a199d692fa84f7ed8d29373d1c.diff

LOG: [Windows SEH] Fix catch+return crash for Windows -EHa

This change also turns on -fasync-exceptions by default under -EHa
option due to the backend patch merged.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D147165

Added: 
    clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp

Modified: 
    clang/lib/CodeGen/CGCleanup.cpp
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 43758ac27e439..175d91488efd0 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -836,7 +836,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
       EmitBlock(NormalEntry);
 
       // intercept normal cleanup to mark SEH scope end
-      if (IsEHa) {
+      if (IsEHa && getInvokeDest()) {
         if (Personality.isMSVCXXPersonality())
           EmitSehCppScopeEnd();
         else

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index f5efcebb3bbd9..1984e1393a15c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7666,6 +7666,8 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
     if (types::isCXX(InputType))
       CmdArgs.push_back("-fcxx-exceptions");
     CmdArgs.push_back("-fexceptions");
+    if (EH.Asynch)
+      CmdArgs.push_back("-fasync-exceptions");
   }
   if (types::isCXX(InputType) && EH.Synch && EH.NoUnwindC)
     CmdArgs.push_back("-fexternc-nounwind");

diff  --git a/clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp b/clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
new file mode 100644
index 0000000000000..a65ab39bea3e4
--- /dev/null
+++ b/clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: define dso_local void @"?foo@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK-NOT: llvm.seh.scope.begin
+// CHECK-NOT: llvm.seh.scope.end
+
+// FIXME: Do we actually need llvm.seh.scope*?
+void foo() {
+  try {}
+  catch (...) {
+  return;
+  }
+}


        


More information about the cfe-commits mailing list