From 4d633793e81a53fe6c373fb1af93e3c36cbc1ec8 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Wed, 28 Jan 2026 00:58:50 +0000 Subject: [PATCH] Don't change WASM_EXCEPTIONS mode when setting -fno-exceptions We have 3 main user-facing EH flags, `-fwasm-exceptions`, `-fexceptions`, and `-fno-exceptions`. IIRC they aren't supposed to be mutually exclusive, -fwasm-exceptions` composes with the other 2, setting the mode of codegen, where the other 2 set whether exceptions compile. If you do `em++ -fno-exceptions -fwasm-exceptions` on a file that has try/catch, you get the expected compile-time error. However if you do `em++ -fwasm-exceptions -fno-exceptions` you should get the same error, but instead you get `clang++: error: invalid argument '-fwasm-exceptions' not allowed with '-enable-emscripten-sjlj'`. This is because the underlying clang is indeed getting passed the `-mllvm -enable-emscripten-sjlj` flag in the latter case but not the former case. --- test/test_core.py | 6 ++++++ tools/cmdline.py | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test_core.py b/test/test_core.py index a0ca156aca1f2..a2faff75a0c4d 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -1720,6 +1720,12 @@ def clear_all_relevant_settings(self): self.assert_fail([EMCC, test_file('hello_world.cpp')] + self.get_cflags(), expected) clear_all_relevant_settings(self) + expected = "error: cannot use 'throw' with exceptions disabled" + self.assert_fail([EMCC, test_file('core/test_exceptions.cpp'), '-fwasm-exceptions', '-fno-exceptions'] + self.get_cflags(), expected) + clear_all_relevant_settings(self) + self.assert_fail([EMCC, test_file('core/test_exceptions.cpp'), '-fno-exceptions', '-fwasm-exceptions'] + self.get_cflags(), expected) + clear_all_relevant_settings(self) + # Marked as impure since the WASI reactor modules (modules without main) # are not yet supported by the wasm engines we test against. @also_with_standalone_wasm(impure=True) diff --git a/tools/cmdline.py b/tools/cmdline.py index 8ce4faf2a7a12..030ba2b418ff0 100644 --- a/tools/cmdline.py +++ b/tools/cmdline.py @@ -508,7 +508,6 @@ def consume_arg_file(): elif arg == '-fno-exceptions': settings.DISABLE_EXCEPTION_CATCHING = 1 settings.DISABLE_EXCEPTION_THROWING = 1 - settings.WASM_EXCEPTIONS = 0 elif arg == '-mbulk-memory': feature_matrix.enable_feature(feature_matrix.Feature.BULK_MEMORY, '-mbulk-memory',