Skip to content

Commit

Permalink
[Windows SEH] Fix catch+return crash for Windows -EHa
Browse files Browse the repository at this point in the history
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
  • Loading branch information
phoebewang committed Apr 1, 2023
1 parent 52dd9de commit 0cc66f3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 14 additions & 0 deletions clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 0cc66f3

Please sign in to comment.