Author: Matt Arsenault Date: 2026-09-13T09:19:16+02:00 New Revision: 8ea78db3c1bf6522ccaf6d75e73a03d80f08a00b
URL: https://github.com/llvm/llvm-project/commit/8ea78db3c1bf6522ccaf6d75e73a03d80f08a00b DIFF: https://github.com/llvm/llvm-project/commit/8ea78db3c1bf6522ccaf6d75e73a03d80f08a00b.diff LOG: clang/WebAssembly: Add -femscripten-exceptions driver flag (#221431) Added: Modified: clang/include/clang/Options/Options.td clang/lib/Driver/ToolChains/WebAssembly.cpp clang/test/Driver/wasm-toolchain.c Removed: ################################################################################ diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 56194af32f68f..32b12beba880b 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -2455,6 +2455,9 @@ def fseh_exceptions : Flag<["-"], "fseh-exceptions">, Group<f_Group>, HelpText<"Use SEH style exceptions">; def fwasm_exceptions : Flag<["-"], "fwasm-exceptions">, Group<f_Group>, HelpText<"Use WebAssembly style exceptions">; +def femscripten_exceptions : Flag<["-"], "femscripten-exceptions">, + Group<f_Group>, + 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">, diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp index fee1f47f073ea..23ae184105f8d 100644 --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -423,6 +423,10 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, getDriver().Diag(diag::err_drv_argument_not_allowed_with) << CurOption << "-mno-reference-types"; + if (DriverArgs.hasArg(options::OPT_femscripten_exceptions)) + getDriver().Diag(diag::err_drv_argument_not_allowed_with) + << CurOption << "-femscripten-exceptions"; + for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) { for (const auto *Option : {"-enable-emscripten-cxx-exceptions", "-enable-emscripten-sjlj", @@ -458,12 +462,20 @@ 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")) { // '-mllvm -emscripten-cxx-exceptions-allowed' should be used with - // '-mllvm -enable-emscripten-cxx-exceptions' - bool EmEHArgExists = false; + // '-femscripten-exceptions' (or the underlying + // '-mllvm -enable-emscripten-cxx-exceptions'). + bool EmEHArgExists = + DriverArgs.hasArg(options::OPT_femscripten_exceptions); for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) { if (StringRef(A->getValue(0)) == "-enable-emscripten-cxx-exceptions") { EmEHArgExists = true; @@ -473,7 +485,7 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, if (!EmEHArgExists) getDriver().Diag(diag::err_drv_argument_only_allowed_with) << "-mllvm -emscripten-cxx-exceptions-allowed" - << "-mllvm -enable-emscripten-cxx-exceptions"; + << "-femscripten-exceptions"; // Prevent functions specified in -emscripten-cxx-exceptions-allowed list // from being inlined before reaching the wasm backend. diff --git a/clang/test/Driver/wasm-toolchain.c b/clang/test/Driver/wasm-toolchain.c index 467d79e57aff1..083773e8e8197 100644 --- a/clang/test/Driver/wasm-toolchain.c +++ b/clang/test/Driver/wasm-toolchain.c @@ -133,7 +133,26 @@ // RUN: not %clang -### --target=wasm32-unknown-unknown \ // RUN: --sysroot=/foo %s -mllvm -emscripten-cxx-exceptions-allowed 2>&1 \ // 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 '-mllvm -enable-emscripten-cxx-exceptions' +// 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' +// 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" + +// '-femscripten-exceptions' satisfies the '-emscripten-cxx-exceptions-allowed' +// companion requirement. +// RUN: %clang -### --target=wasm32-unknown-unknown \ +// 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 + +// '-fwasm-exceptions' not allowed with '-femscripten-exceptions' +// RUN: not %clang -### --target=wasm32-unknown-unknown \ +// RUN: --sysroot=/foo %s -fwasm-exceptions -femscripten-exceptions 2>&1 \ +// RUN: | FileCheck -check-prefix=WASM_EXCEPTIONS_FEMSCRIPTEN_EH %s +// WASM_EXCEPTIONS_FEMSCRIPTEN_EH: invalid argument '-fwasm-exceptions' not allowed with '-femscripten-exceptions' // '-fwasm-exceptions' sets +exception-handling, -multivalue, -reference-types, // "-exception-model=wasm", and '-mllvm -wasm-enable-eh' _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
