[llvm-branch-commits] [clang] [llvm] WebAssembly: Introduce ExceptionHandling::EmscriptenEH model (PR #221443)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Sep 5 06:33:50 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-webassembly
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Add a dedicated EmscriptenEH exception model so the control uses
the standard exception model control, instead of relying on a backend
specific cl::opt. This will later migrate to a module flag and
remove -enable-emscripten-cxx-exceptions
Co-authored-by: Claude (Claude-Opus-4.8) <noreply@<!-- -->anthropic.com>
---
Patch is 24.82 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/221443.diff
20 Files Affected:
- (modified) clang/include/clang/Basic/CodeGenOptions.h (+12-1)
- (modified) clang/include/clang/Basic/DiagnosticFrontendKinds.td (+1-1)
- (modified) clang/include/clang/Options/Options.td (+2-2)
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+2)
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+4-1)
- (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (-6)
- (modified) clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll (+1-1)
- (modified) clang/test/Driver/ir-exception-model.c (+2)
- (modified) clang/test/Driver/wasm-toolchain.c (+3-3)
- (modified) llvm/include/llvm/Support/CodeGen.h (+8-7)
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+2)
- (modified) llvm/lib/CodeGen/CommandFlags.cpp (+3-1)
- (modified) llvm/lib/CodeGen/TargetPassConfig.cpp (+3)
- (modified) llvm/lib/Passes/CodeGenPassBuilder.cpp (+3)
- (modified) llvm/lib/Target/WebAssembly/WebAssembly.h (+5-1)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (+1)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp (+6-3)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp (+11-6)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp (+20-12)
- (modified) llvm/test/CodeGen/WebAssembly/eh-option-errors.ll (+5-8)
``````````diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 17f367bc02607..8b65a5bc920a5 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -199,7 +199,14 @@ class CodeGenOptions : public CodeGenOptionsBase {
}
/// Possible exception handling behavior.
- enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
+ enum class ExceptionHandlingKind {
+ None,
+ SjLj,
+ WinEH,
+ DwarfCFI,
+ Wasm,
+ EmscriptenEH
+ };
enum class SwiftAsyncFramePointerKind {
Auto, // Choose Swift async extended frame info based on deployment target.
@@ -634,6 +641,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
return getExceptionHandling() == ExceptionHandlingKind::Wasm;
}
+ bool hasEmscriptenExceptions() const {
+ return getExceptionHandling() == ExceptionHandlingKind::EmscriptenEH;
+ }
+
/// Check if Clang profile instrumenation is on.
bool hasProfileClangInstr() const {
return getProfileInstr() ==
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index a10f10502a702..de38915bd8985 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -151,7 +151,7 @@ def err_fe_invalid_multiple_actions : Error<
def err_fe_invalid_alignment : Error<
"invalid value '%1' in '%0'; alignment must be a power of 2">;
def err_fe_invalid_exception_model
- : Error<"invalid exception model '%select{none|sjlj|seh|dwarf|wasm}0' for target '%1'">;
+ : Error<"invalid exception model '%select{none|sjlj|seh|dwarf|wasm|emscripten}0' for target '%1'">;
def err_fe_invalid_source_date_epoch : Error<
"environment variable 'SOURCE_DATE_EPOCH' ('%0') must be a non-negative decimal integer <= %1">;
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 2f2ab2f2ba6d8..60d511c5a71e5 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2459,9 +2459,9 @@ def femscripten_exceptions : Flag<["-"], "femscripten-exceptions">,
HelpText<"Use Emscripten JavaScript-based C++ exceptions">;
def exception_model : Separate<["-"], "exception-model">,
Visibility<[CC1Option]>, HelpText<"The exception model">,
- Values<"dwarf,sjlj,seh,wasm,none">,
+ Values<"dwarf,sjlj,seh,wasm,emscripten,none">,
NormalizedValuesScope<"CodeGenOptions::ExceptionHandlingKind">,
- NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm", "None"]>,
+ NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm", "EmscriptenEH", "None"]>,
MarshallingInfoEnum<CodeGenOpts<"ExceptionHandling">, "None">;
def exception_model_EQ : Joined<["-"], "exception-model=">,
Visibility<[CC1Option]>, Alias<exception_model>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index ed369d360c48b..d73d1fb497d07 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -419,6 +419,8 @@ static bool initTargetOptions(const CompilerInstance &CI,
Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
if (CodeGenOpts.hasWasmExceptions())
Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
+ if (CodeGenOpts.hasEmscriptenExceptions())
+ Options.ExceptionModel = llvm::ExceptionHandling::EmscriptenEH;
Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index ab852bf0e0043..9f426a0f17fcc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7891,7 +7891,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Handle exception personalities
Arg *A = Args.getLastArg(
options::OPT_fsjlj_exceptions, options::OPT_fseh_exceptions,
- options::OPT_fdwarf_exceptions, options::OPT_fwasm_exceptions);
+ options::OPT_fdwarf_exceptions, options::OPT_fwasm_exceptions,
+ options::OPT_femscripten_exceptions);
if (A) {
const Option &Opt = A->getOption();
if (Opt.matches(options::OPT_fsjlj_exceptions))
@@ -7902,6 +7903,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-exception-model=dwarf");
if (Opt.matches(options::OPT_fwasm_exceptions))
CmdArgs.push_back("-exception-model=wasm");
+ if (Opt.matches(options::OPT_femscripten_exceptions))
+ CmdArgs.push_back("-exception-model=emscripten");
} else {
switch (TC.GetExceptionModel(Args)) {
default:
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 0d3271d31a0b7..2880f03057ba6 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -462,12 +462,6 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
CC1Args.push_back("-wasm-enable-eh");
}
- if (DriverArgs.getLastArg(options::OPT_femscripten_exceptions)) {
- // Backend needs -enable-emscripten-cxx-exceptions to enable Emscripten EH
- CC1Args.push_back("-mllvm");
- CC1Args.push_back("-enable-emscripten-cxx-exceptions");
- }
-
for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
StringRef Opt = A->getValue(0);
if (Opt.starts_with("-emscripten-cxx-exceptions-allowed")) {
diff --git a/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll b/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
index 85bfc7f74daed..8263c98670aab 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
+++ b/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
@@ -11,7 +11,7 @@
; CHECK-LABEL: define void @test(
; ERR: error: invalid value 'invalid' in '-exception-model=invalid'
-; ERR-BE: fatal error: error in backend: -exception-model should be either 'none' or 'wasm'
+; ERR-BE: fatal error: error in backend: -exception-model should be either 'none', 'wasm', or 'emscripten'
define void @test() {
ret void
}
diff --git a/clang/test/Driver/ir-exception-model.c b/clang/test/Driver/ir-exception-model.c
index 9e8f998de0d6b..b5d68c644e1b7 100644
--- a/clang/test/Driver/ir-exception-model.c
+++ b/clang/test/Driver/ir-exception-model.c
@@ -1,5 +1,6 @@
// RUN: %clang -### -target wasm32-unknown-unknown -fwasm-exceptions -c -S -o - %S/Inputs/file.ll 2>&1 | FileCheck %s
// RUN: %clang -### -target wasm32-unknown-unknown -Xclang -exception-model=wasm -c -S -o - %S/Inputs/file.ll 2>&1 | FileCheck %s
+// RUN: %clang -### -target wasm32-unknown-emscripten -femscripten-exceptions -c -S -o - %S/Inputs/file.ll 2>&1 | FileCheck -check-prefix=EMSCRIPTEN %s
// RUN: %clang -### -target wasm32-unknown-unknown -Xclang -exception-model=dwarf -c -S -o - %S/Inputs/file.ll 2>&1 | FileCheck -check-prefix=DWARF %s
// RUN: %clang -### -target wasm32-unknown-unknown -Xclang -exception-model=sjlj -c -S -o - %S/Inputs/file.ll 2>&1 | FileCheck -check-prefix=SJLJ %s
// RUN: %clang -### -target wasm32-unknown-unknown -Xclang -exception-model=wineh -c -S -o - %S/Inputs/file.ll 2>&1 | FileCheck -check-prefix=WINEH %s
@@ -8,6 +9,7 @@
// Check that -fwasm-exceptions propagates -exception-model to cc1
// CHECK: "-exception-model=wasm"
+// EMSCRIPTEN: "-exception-model=emscripten"
// DWARF: "-exception-model=dwarf"
// SJLJ: "-exception-model=sjlj"
// WINEH: "-exception-model=wineh"
diff --git a/clang/test/Driver/wasm-toolchain.c b/clang/test/Driver/wasm-toolchain.c
index 083773e8e8197..665cf4d1a667b 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -123,7 +123,7 @@
// '-mllvm -emscripten-cxx-exceptions-allowed=foo,bar' sets
// '-mllvm --force-attribute=foo:noinline -mllvm --force-attribute=bar:noinline'
// RUN: %clang -### --target=wasm32-unknown-unknown \
-// RUN: --sysroot=/foo %s -mllvm -enable-emscripten-cxx-exceptions \
+// RUN: --sysroot=/foo %s -femscripten-exceptions \
// RUN: -mllvm -emscripten-cxx-exceptions-allowed=foo,bar 2>&1 \
// RUN: | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_NOINLINE %s
// EMSCRIPTEN_EH_ALLOWED_NOINLINE: "-cc1" {{.*}} "-mllvm" "--force-attribute=foo:noinline" "-mllvm" "--force-attribute=bar:noinline"
@@ -135,11 +135,11 @@
// RUN: | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_WO_ENABLE %s
// EMSCRIPTEN_EH_ALLOWED_WO_ENABLE: invalid argument '-mllvm -emscripten-cxx-exceptions-allowed' only allowed with '-femscripten-exceptions'
-// '-femscripten-exceptions' sets '-mllvm -enable-emscripten-cxx-exceptions'
+// '-femscripten-exceptions' sets '-exception-model=emscripten'
// RUN: %clang -### --target=wasm32-unknown-unknown \
// RUN: --sysroot=/foo %s -femscripten-exceptions 2>&1 \
// RUN: | FileCheck -check-prefix=EMSCRIPTEN_EXCEPTIONS %s
-// EMSCRIPTEN_EXCEPTIONS: "-cc1" {{.*}} "-mllvm" "-enable-emscripten-cxx-exceptions"
+// EMSCRIPTEN_EXCEPTIONS: "-cc1" {{.*}} "-exception-model=emscripten"
// '-femscripten-exceptions' satisfies the '-emscripten-cxx-exceptions-allowed'
// companion requirement.
diff --git a/llvm/include/llvm/Support/CodeGen.h b/llvm/include/llvm/Support/CodeGen.h
index e61a36ed42d96..6b1929ebb5c71 100644
--- a/llvm/include/llvm/Support/CodeGen.h
+++ b/llvm/include/llvm/Support/CodeGen.h
@@ -52,13 +52,14 @@ namespace llvm {
}
enum class ExceptionHandling : int {
- None, ///< No exception support
- DwarfCFI, ///< DWARF-like instruction based exceptions
- SjLj, ///< setjmp/longjmp based exceptions
- ARM, ///< ARM EHABI
- WinEH, ///< Windows Exception Handling
- Wasm, ///< WebAssembly Exception Handling
- AIX, ///< AIX Exception Handling
+ None, ///< No exception support
+ DwarfCFI, ///< DWARF-like instruction based exceptions
+ SjLj, ///< setjmp/longjmp based exceptions
+ ARM, ///< ARM EHABI
+ WinEH, ///< Windows Exception Handling
+ Wasm, ///< WebAssembly Exception Handling
+ EmscriptenEH, ///< Emscripten JavaScript-based C++ exception handling
+ AIX, ///< AIX Exception Handling
ZOS, ///< z/OS MVS Exception Handling. Very similar to DwarfCFI, but the
///< PPA1 is used instead of an .eh_frame section.
};
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3d06677d1706b..a535d4bb473cc 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -669,6 +669,8 @@ bool AsmPrinter::doInitialization(Module &M) {
EHStreamer *ES = nullptr;
switch (MAI.getExceptionHandlingType()) {
case ExceptionHandling::None:
+ case ExceptionHandling::EmscriptenEH:
+ // Emscripten EH is handled in JS glue code and emits no EH tables here.
if (!usesCFIWithoutEH())
break;
[[fallthrough]];
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index db149dd938203..6de05e3469cca 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -198,7 +198,9 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
clEnumValN(ExceptionHandling::WinEH, "wineh",
"Windows exception model"),
clEnumValN(ExceptionHandling::Wasm, "wasm",
- "WebAssembly exception handling")));
+ "WebAssembly exception handling"),
+ clEnumValN(ExceptionHandling::EmscriptenEH, "emscripten",
+ "Emscripten JavaScript-based C++ exception handling")));
CGBINDOPT(ExceptionModel);
static cl::opt<CodeGenFileType> FileType(
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index e390db16aa63d..3d8883a8a2049 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -961,6 +961,9 @@ void TargetPassConfig::addPassesToHandleExceptions() {
addPass(createWasmEHPass());
break;
case ExceptionHandling::None:
+ case ExceptionHandling::EmscriptenEH:
+ // Emscripten EH is lowered earlier by WebAssemblyLowerEmscriptenEHSjLj, so
+ // by this point it needs no generic EH preparation, like the None case.
addPass(createLowerInvokePass());
// The lower invoke pass may create unreachable code. Remove it.
diff --git a/llvm/lib/Passes/CodeGenPassBuilder.cpp b/llvm/lib/Passes/CodeGenPassBuilder.cpp
index 63e161965820e..57d4b74c4e24c 100644
--- a/llvm/lib/Passes/CodeGenPassBuilder.cpp
+++ b/llvm/lib/Passes/CodeGenPassBuilder.cpp
@@ -473,6 +473,9 @@ void CodeGenPassBuilder::addPassesToHandleExceptions(PassManagerWrapper &PMW) {
addFunctionPass(WasmEHPreparePass(), PMW);
break;
case ExceptionHandling::None:
+ case ExceptionHandling::EmscriptenEH:
+ // Emscripten EH is lowered earlier by WebAssemblyLowerEmscriptenEHSjLj, so
+ // by this point it needs no generic EH preparation, like the None case.
addFunctionPass(LowerInvokePass(), PMW);
// The lower invoke pass may create unreachable code. Remove it.
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.h b/llvm/lib/Target/WebAssembly/WebAssembly.h
index 94628d0944f8d..e6aefc2ba43e9 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.h
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.h
@@ -35,11 +35,15 @@ class FunctionPass;
// LLVM IR passes.
class WebAssemblyLowerEmscriptenEHSjLjPass
: public RequiredPassInfoMixin<WebAssemblyLowerEmscriptenEHSjLjPass> {
+ bool EnableEmEH;
+
public:
+ WebAssemblyLowerEmscriptenEHSjLjPass(bool EnableEmEH = false)
+ : EnableEmEH(EnableEmEH) {}
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
};
-ModulePass *createWebAssemblyLowerEmscriptenEHSjLjLegacyPass();
+ModulePass *createWebAssemblyLowerEmscriptenEHSjLjLegacyPass(bool EnableEmEH);
class WebAssemblyAddMissingPrototypesPass
: public RequiredPassInfoMixin<WebAssemblyAddMissingPrototypesPass> {
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 69a0f97253f3e..d64f03c24b11c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -166,6 +166,7 @@ MCSymbolWasm *WebAssemblyAsmPrinter::getMCSymbolForFunction(
MCSymbolWasm *WasmSym = nullptr;
const bool EnableEmEH =
+ TM.Options.ExceptionModel == ExceptionHandling::EmscriptenEH ||
WebAssembly::WasmEnableEmEH || WebAssembly::WasmEnableEmSjLj;
if (EnableEmEH && isEmscriptenInvokeName(F->getName())) {
assert(Sig);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
index 7fecb163625cf..653080fd81582 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
@@ -127,7 +127,10 @@ void WebAssemblyCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
// TargetPassConfig::addPassesToHandleExceptions, but that runs after these IR
// passes and Emscripten SjLj handling expects all invokes to be lowered
// before.
- if (!WasmEnableEmEH && !WasmEnableEH) {
+ bool EnableEmEH =
+ TM.Options.ExceptionModel == ExceptionHandling::EmscriptenEH ||
+ WasmEnableEmEH;
+ if (!EnableEmEH && !WasmEnableEH) {
addFunctionPass(LowerInvokePass(), PMW);
// The lower invoke pass may create unreachable code. Remove it in order not
// to process dead blocks in setjmp/longjmp handling.
@@ -138,9 +141,9 @@ void WebAssemblyCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
// done in WasmEHPrepare pass, Wasm SjLj preparation shares libraries and
// transformation algorithms with Emscripten SjLj, so we run
// LowerEmscriptenEHSjLj pass also when Wasm SjLj is enabled.
- if (WasmEnableEmEH || WasmEnableEmSjLj || WasmEnableSjLj) {
+ if (EnableEmEH || WasmEnableEmSjLj || WasmEnableSjLj) {
flushFPMsToMPM(PMW);
- addModulePass(WebAssemblyLowerEmscriptenEHSjLjPass(), PMW);
+ addModulePass(WebAssemblyLowerEmscriptenEHSjLjPass(EnableEmEH), PMW);
}
// Expand indirectbr instructions to switches.
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index cd1ce993a16ed..5894e9b09ffdc 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -359,8 +359,9 @@ class WebAssemblyLowerEmscriptenEHSjLjImpl {
public:
WebAssemblyLowerEmscriptenEHSjLjImpl(
+ bool EnableEmEH,
std::function<DominatorTree &(Function &F)> GetDominatorTree)
- : EnableEmEH(WebAssembly::WasmEnableEmEH),
+ : EnableEmEH(EnableEmEH || WebAssembly::WasmEnableEmEH),
EnableEmSjLj(WebAssembly::WasmEnableEmSjLj),
EnableWasmSjLj(WebAssembly::WasmEnableSjLj),
GetDominatorTree(GetDominatorTree) {
@@ -375,6 +376,8 @@ class WebAssemblyLowerEmscriptenEHSjLjImpl {
};
class WebAssemblyLowerEmscriptenEHSjLjLegacy final : public ModulePass {
+ bool EnableEmEH;
+
StringRef getPassName() const override {
return "WebAssembly Lower Emscripten Exceptions";
}
@@ -382,7 +385,8 @@ class WebAssemblyLowerEmscriptenEHSjLjLegacy final : public ModulePass {
public:
static char ID;
- WebAssemblyLowerEmscriptenEHSjLjLegacy() : ModulePass(ID) {}
+ WebAssemblyLowerEmscriptenEHSjLjLegacy(bool EnableEmEH = false)
+ : ModulePass(ID), EnableEmEH(EnableEmEH) {}
bool runOnModule(Module &M) override;
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -396,8 +400,9 @@ INITIALIZE_PASS(WebAssemblyLowerEmscriptenEHSjLjLegacy, DEBUG_TYPE,
"WebAssembly Lower Emscripten Exceptions / Setjmp / Longjmp",
false, false)
-ModulePass *llvm::createWebAssemblyLowerEmscriptenEHSjLjLegacyPass() {
- return new WebAssemblyLowerEmscriptenEHSjLjLegacy();
+ModulePass *
+llvm::createWebAssemblyLowerEmscriptenEHSjLjLegacyPass(bool EnableEmEH) {
+ return new WebAssemblyLowerEmscriptenEHSjLjLegacy(EnableEmEH);
}
static bool canThrow(const Value *V) {
@@ -1871,7 +1876,7 @@ void WebAssemblyLowerEmscriptenEHSjLjImpl::handleLongjmpableCallsForWasmSjLj(
bool WebAssemblyLowerEmscriptenEHSjLjLegacy::runOnModule(Module &M) {
WebAssemblyLowerEmscriptenEHSjLjImpl Impl(
- [&](Function &F) -> DominatorTree & {
+ EnableEmEH, [&](Function &F) -> DominatorTree & {
return getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
});
return Impl.runOnModule(M);
@@ -1881,7 +1886,7 @@ PreservedAnalyses
WebAssemblyLowerEmscriptenEHSjLjPass::run(Module &M,
ModuleAnalysisManager &MAM) {
WebAssemblyLowerEmscriptenEHSjLjImpl Impl(
- [&](Function &F) -> DominatorTree & {
+ EnableEmEH, [&](Function &F) -> DominatorTree & {
return MAM.getResult<FunctionAnalysisManagerModuleProxy>(M)
.getManager()
.getResult<DominatorTreeAnalysis>(F);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 964b67edde3e0..a9a905b6698c0 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -141,18 +141,24 @@ using WebAssembly::WasmEnableSjLj;
static void basicCheckForEHAndSjLj(TargetMachine *TM) {
+ // Emscripten EH is selected by the exception model. WasmEnableEmEH is a
+ // deprecated cl::opt alias, OR-ed in here until it is removed.
+ bool EnableEmEH =
+ TM->Options.ExceptionModel == ExceptionHandling::EmscriptenEH ||
+ WasmEnableEmEH;
+
// You can't enable two modes of EH at the same time
- if (WasmEnableEmEH && WasmEnableEH)
+ if (EnableEmEH && WasmEnableEH)
report_fatal_error(
- "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
+ "-exception-model=emscripten not allowed with -wasm-enable-eh");
// You can't enable two modes of SjLj at the same time
if (WasmEnableEmSjLj && WasmEnableSjLj)
report_fatal_error(
"-enable-emscripten-sjlj not allowed with -wasm-ena...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/221443
More information about the llvm-branch-commits
mailing list