[PATCH] D103664: [Windows SEH]: Fix -O2 crash for Windows -EHa
Ten Tzen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 3 19:43:12 PDT 2021
tentzen created this revision.
tentzen added reviewers: asmith, aganea, zahiraam.
tentzen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch fixes a Windows -EHa crash induced by previous commit 797ad701522988e212495285dade8efac41a24d4 <https://reviews.llvm.org/rG797ad701522988e212495285dade8efac41a24d4>.
The crush was caused "LifetimeMarker" scope (with option -O2) that should not be considered as SEH Scope.
This change also turns off -fasync-exceptions by default under -EHa option for now.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103664
Files:
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/windows-seh-EHa-CppDtors01.cpp
Index: clang/test/CodeGen/windows-seh-EHa-CppDtors01.cpp
===================================================================
--- clang/test/CodeGen/windows-seh-EHa-CppDtors01.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppDtors01.cpp
@@ -1,4 +1,5 @@
// 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
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -O2 -S -emit-llvm %s -o - | FileCheck %s
// CHECK: invoke void @llvm.seh.scope.begin()
// CHECK: invoke void @llvm.seh.scope.begin()
@@ -8,8 +9,8 @@
// CHECK: invoke void @llvm.seh.scope.end()
// CHECK: invoke void @llvm.seh.try.begin()
-// CHECK: %[[src:[0-9-]+]] = load volatile i32, i32* %i
-// CHECK-NEXT: invoke void @"?crash@@YAXH at Z"(i32 %[[src]])
+// CHECK: = load volatile i32, i32* %i
+// CHECK-NEXT: invoke void @"?crash@@YAXH at Z"(i32
// CHECK: invoke void @llvm.seh.try.end()
// ****************************************************************************
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7151,8 +7151,6 @@
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");
Index: clang/lib/CodeGen/CGCleanup.cpp
===================================================================
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -195,7 +195,7 @@
Scope->setLifetimeMarker();
// With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
- if (CGF->getLangOpts().EHAsynch && IsEHCleanup &&
+ if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
CGF->getTarget().getCXXABI().isMicrosoft())
CGF->EmitSehCppScopeBegin();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103664.349748.patch
Type: text/x-patch
Size: 2199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210604/c9033b8d/attachment-0001.bin>
More information about the cfe-commits
mailing list