Skip to content

Commit b0194d2

Browse files
authored
[SEH] Ignore async exception flag when the environment is not MSVC (#88101)
Fixes #62449
1 parent a831c54 commit b0194d2

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,14 @@ static bool addExceptionArgs(const ArgList &Args, types::ID InputType,
346346
bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
347347
false);
348348

349-
bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
350-
options::OPT_fno_async_exceptions, false);
351-
if (EHa) {
352-
CmdArgs.push_back("-fasync-exceptions");
353-
EH = true;
349+
// Async exceptions are Windows MSVC only.
350+
if (Triple.isWindowsMSVCEnvironment()) {
351+
bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
352+
options::OPT_fno_async_exceptions, false);
353+
if (EHa) {
354+
CmdArgs.push_back("-fasync-exceptions");
355+
EH = true;
356+
}
354357
}
355358

356359
// Obj-C exceptions are enabled by default, regardless of -fexceptions. This
@@ -8102,7 +8105,8 @@ struct EHFlags {
81028105
/// The 'a' modifier is unimplemented and fundamentally hard in LLVM IR.
81038106
/// - c: Assume that extern "C" functions are implicitly nounwind.
81048107
/// The default is /EHs-c-, meaning cleanups are disabled.
8105-
static EHFlags parseClangCLEHFlags(const Driver &D, const ArgList &Args) {
8108+
static EHFlags parseClangCLEHFlags(const Driver &D, const ArgList &Args,
8109+
bool isWindowsMSVC) {
81068110
EHFlags EH;
81078111

81088112
std::vector<std::string> EHArgs =
@@ -8112,8 +8116,15 @@ static EHFlags parseClangCLEHFlags(const Driver &D, const ArgList &Args) {
81128116
switch (EHVal[I]) {
81138117
case 'a':
81148118
EH.Asynch = maybeConsumeDash(EHVal, I);
8115-
if (EH.Asynch)
8119+
if (EH.Asynch) {
8120+
// Async exceptions are Windows MSVC only.
8121+
if (!isWindowsMSVC) {
8122+
EH.Asynch = false;
8123+
D.Diag(clang::diag::warn_drv_unused_argument) << "/EHa" << EHVal;
8124+
continue;
8125+
}
81168126
EH.Synch = false;
8127+
}
81178128
continue;
81188129
case 'c':
81198130
EH.NoUnwindC = maybeConsumeDash(EHVal, I);
@@ -8177,7 +8188,8 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
81778188

81788189
const Driver &D = getToolChain().getDriver();
81798190

8180-
EHFlags EH = parseClangCLEHFlags(D, Args);
8191+
bool IsWindowsMSVC = getToolChain().getTriple().isWindowsMSVCEnvironment();
8192+
EHFlags EH = parseClangCLEHFlags(D, Args, IsWindowsMSVC);
81818193
if (!isNVPTX && (EH.Synch || EH.Asynch)) {
81828194
if (types::isCXX(InputType))
81838195
CmdArgs.push_back("-fcxx-exceptions");
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang --target=x86_64-pc-windows -fasync-exceptions -fsyntax-only %s -### 2>&1 | FileCheck %s
2+
// RUN: %clang_cl --target=x86_64-pc-windows /EHa -fsyntax-only %s -### 2>&1 | FileCheck %s
3+
// RUN: %clang --target=x86_64-pc-windows-gnu -fasync-exceptions -fsyntax-only %s -### 2>&1 | FileCheck %s --check-prefixes=GNU-ALL,GNU
4+
// RUN: %clang_cl --target=x86_64-pc-windows-gnu /EHa -fsyntax-only %s -### 2>&1 | FileCheck %s --check-prefixes=GNU-ALL,CL-GNU
5+
6+
// CHECK-NOT: warning
7+
// GNU: warning: argument unused during compilation: '-fasync-exceptions' [-Wunused-command-line-argument]
8+
// CL-GNU: warning: argument unused during compilation: '/EHa' [-Wunused-command-line-argument]
9+
10+
// CHECK: -fasync-exceptions
11+
// GNU-ALL-NOT: -fasync-exceptions
12+
struct S {
13+
union _Un {
14+
~_Un() {}
15+
char _Buf[12];
16+
};
17+
_Un _un;
18+
};
19+
20+
struct Embed {
21+
S v2;
22+
};
23+
24+
void PR62449() { Embed v{}; }

0 commit comments

Comments
 (0)