Skip to content

Commit 8f28249

Browse files
committed
[WebAssembly] Enable Wasm EH features only once
llvm#122466 had an unexpected side effect that, `EnableFeaturesForWasmEHSjLj` and `BanIncompatibleOptionsForWasmEHSjLj` can be called multiple times now, every time a Wasm EH flag (`-fwasm-exceptions, `-wasm-enable-eh`, `-wasm-enable-sjlj`, ..) was checked and handled. This resulted in unnecessarily adding the same feature-enabling arguments multiple times to the command line, for example, `-target-feature +exception-handling` could be added as many as three times, which didn't cause any errors but unnecessary. Also we ran `BanIncompatibleOptionsForWasmEHSjLj` more than once, which was harmless but unnecessary. This guards these functions with a static variable so that we only run them once. This does not add any new tests because honestly I don't see any value of having a test that checks `-target-feature +exception-handling` is only added once...
1 parent 697c188 commit 8f28249

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

clang/lib/Driver/ToolChains/WebAssembly.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
347347
// Bans incompatible options for Wasm EH / SjLj. We don't allow using
348348
// different modes for EH and SjLj.
349349
auto BanIncompatibleOptionsForWasmEHSjLj = [&](StringRef CurOption) {
350+
static bool HasRun = false;
351+
if (HasRun)
352+
return;
350353
if (DriverArgs.hasFlag(options::OPT_mno_exception_handing,
351354
options::OPT_mexception_handing, false))
352355
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
@@ -370,10 +373,14 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
370373
<< CurOption << Option;
371374
}
372375
}
376+
HasRun = true;
373377
};
374378

375379
// Enable necessary features for Wasm EH / SjLj in the backend.
376380
auto EnableFeaturesForWasmEHSjLj = [&]() {
381+
static bool HasRun = false;
382+
if (HasRun)
383+
return;
377384
CC1Args.push_back("-target-feature");
378385
CC1Args.push_back("+exception-handling");
379386
// The standardized Wasm EH spec requires multivalue and reference-types.
@@ -383,6 +390,7 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
383390
CC1Args.push_back("+reference-types");
384391
// Backend needs '-exception-model=wasm' to use Wasm EH instructions
385392
CC1Args.push_back("-exception-model=wasm");
393+
HasRun = true;
386394
};
387395

388396
if (DriverArgs.getLastArg(options::OPT_fwasm_exceptions)) {

0 commit comments

Comments
 (0)