Skip to content

[WebAssembly] Enable Wasm EH features only once #124042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
// Bans incompatible options for Wasm EH / SjLj. We don't allow using
// different modes for EH and SjLj.
auto BanIncompatibleOptionsForWasmEHSjLj = [&](StringRef CurOption) {
static bool HasRun = false;
if (HasRun)
return;
if (DriverArgs.hasFlag(options::OPT_mno_exception_handing,
options::OPT_mexception_handing, false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
Expand All @@ -370,10 +373,14 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
<< CurOption << Option;
}
}
HasRun = true;
};

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

if (DriverArgs.getLastArg(options::OPT_fwasm_exceptions)) {
Expand Down
Loading