Skip to content

Commit dca3a6e

Browse files
authored
[WebAssembly] Make EH depend on multivalue and reference-types (llvm#91299)
This PR turns on multivalue and reference-types features when exception-handling feature is turned on, and errors out when disabling of those dependent features is explicitly requested. I think doing this would be safe anyway regardless of whether or when we end up turning on reference-types by default. We currently don't yet have a experimental flag for the Clang and LLVM for the new experimental EH yet. But I think it should be fine to turn those features on even if the LLVM does not yet generate the new EH instructions, for the same reason we tried to turn them on by default and the browsers that support EH also support multivalue and reference-types anyway.
1 parent 117bda5 commit dca3a6e

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

clang/lib/Driver/ToolChains/WebAssembly.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,23 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
347347
// Backend needs -wasm-enable-eh to enable Wasm EH
348348
CC1Args.push_back("-mllvm");
349349
CC1Args.push_back("-wasm-enable-eh");
350+
351+
// New Wasm EH spec (adopted in Oct 2023) requires multivalue and
352+
// reference-types.
353+
if (DriverArgs.hasFlag(options::OPT_mno_multivalue,
354+
options::OPT_mmultivalue, false)) {
355+
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
356+
<< "-fwasm-exceptions" << "-mno-multivalue";
357+
}
358+
if (DriverArgs.hasFlag(options::OPT_mno_reference_types,
359+
options::OPT_mreference_types, false)) {
360+
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
361+
<< "-fwasm-exceptions" << "-mno-reference-types";
362+
}
363+
CC1Args.push_back("-target-feature");
364+
CC1Args.push_back("+multivalue");
365+
CC1Args.push_back("-target-feature");
366+
CC1Args.push_back("+reference-types");
350367
}
351368

352369
for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
@@ -408,6 +425,23 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
408425
CC1Args.push_back("+exception-handling");
409426
// Backend needs '-exception-model=wasm' to use Wasm EH instructions
410427
CC1Args.push_back("-exception-model=wasm");
428+
429+
// New Wasm EH spec (adopted in Oct 2023) requires multivalue and
430+
// reference-types.
431+
if (DriverArgs.hasFlag(options::OPT_mno_multivalue,
432+
options::OPT_mmultivalue, false)) {
433+
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
434+
<< "-mllvm -wasm-enable-sjlj" << "-mno-multivalue";
435+
}
436+
if (DriverArgs.hasFlag(options::OPT_mno_reference_types,
437+
options::OPT_mreference_types, false)) {
438+
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
439+
<< "-mllvm -wasm-enable-sjlj" << "-mno-reference-types";
440+
}
441+
CC1Args.push_back("-target-feature");
442+
CC1Args.push_back("+multivalue");
443+
CC1Args.push_back("-target-feature");
444+
CC1Args.push_back("+reference-types");
411445
}
412446
}
413447
}

clang/test/Driver/wasm-toolchain.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,45 @@
120120
// RUN: | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_WO_ENABLE %s
121121
// EMSCRIPTEN_EH_ALLOWED_WO_ENABLE: invalid argument '-mllvm -emscripten-cxx-exceptions-allowed' only allowed with '-mllvm -enable-emscripten-cxx-exceptions'
122122

123-
// '-fwasm-exceptions' sets +exception-handling and '-mllvm -wasm-enable-eh'
123+
// '-fwasm-exceptions' sets +exception-handling, -multivalue, -reference-types
124+
// and '-mllvm -wasm-enable-eh'
124125
// RUN: %clang -### --target=wasm32-unknown-unknown \
125126
// RUN: --sysroot=/foo %s -fwasm-exceptions 2>&1 \
126127
// RUN: | FileCheck -check-prefix=WASM_EXCEPTIONS %s
127-
// WASM_EXCEPTIONS: "-cc1" {{.*}} "-target-feature" "+exception-handling" "-mllvm" "-wasm-enable-eh"
128+
// WASM_EXCEPTIONS: "-cc1" {{.*}} "-target-feature" "+exception-handling" "-mllvm" "-wasm-enable-eh" "-target-feature" "+multivalue" "-target-feature" "+reference-types"
128129

129130
// '-fwasm-exceptions' not allowed with '-mno-exception-handling'
130131
// RUN: not %clang -### --target=wasm32-unknown-unknown \
131132
// RUN: --sysroot=/foo %s -fwasm-exceptions -mno-exception-handling 2>&1 \
132133
// RUN: | FileCheck -check-prefix=WASM_EXCEPTIONS_NO_EH %s
133134
// WASM_EXCEPTIONS_NO_EH: invalid argument '-fwasm-exceptions' not allowed with '-mno-exception-handling'
134135

135-
// '-fwasm-exceptions' not allowed with '-mllvm -enable-emscripten-cxx-exceptions'
136+
// '-fwasm-exceptions' not allowed with
137+
// '-mllvm -enable-emscripten-cxx-exceptions'
136138
// RUN: not %clang -### --target=wasm32-unknown-unknown \
137139
// RUN: --sysroot=/foo %s -fwasm-exceptions \
138140
// RUN: -mllvm -enable-emscripten-cxx-exceptions 2>&1 \
139141
// RUN: | FileCheck -check-prefix=WASM_EXCEPTIONS_EMSCRIPTEN_EH %s
140142
// WASM_EXCEPTIONS_EMSCRIPTEN_EH: invalid argument '-fwasm-exceptions' not allowed with '-mllvm -enable-emscripten-cxx-exceptions'
141143

142-
// '-mllvm -wasm-enable-sjlj' sets +exception-handling and
143-
// '-exception-model=wasm'
144+
// '-fwasm-exceptions' not allowed with '-mno-multivalue'
145+
// RUN: not %clang -### --target=wasm32-unknown-unknown \
146+
// RUN: --sysroot=/foo %s -fwasm-exceptions -mno-multivalue 2>&1 \
147+
// RUN: | FileCheck -check-prefix=WASM_EXCEPTIONS_NO_MULTIVALUE %s
148+
// WASM_EXCEPTIONS_NO_MULTIVALUE: invalid argument '-fwasm-exceptions' not allowed with '-mno-multivalue'
149+
150+
// '-fwasm-exceptions' not allowed with '-mno-reference-types'
151+
// RUN: not %clang -### --target=wasm32-unknown-unknown \
152+
// RUN: --sysroot=/foo %s -fwasm-exceptions -mno-reference-types 2>&1 \
153+
// RUN: | FileCheck -check-prefix=WASM_EXCEPTIONS_NO_REFERENCE_TYPES %s
154+
// WASM_EXCEPTIONS_NO_REFERENCE_TYPES: invalid argument '-fwasm-exceptions' not allowed with '-mno-reference-types'
155+
156+
// '-mllvm -wasm-enable-sjlj' sets +exception-handling, +multivalue,
157+
// +reference-types and '-exception-model=wasm'
144158
// RUN: %clang -### --target=wasm32-unknown-unknown \
145159
// RUN: --sysroot=/foo %s -mllvm -wasm-enable-sjlj 2>&1 \
146160
// RUN: | FileCheck -check-prefix=WASM_SJLJ %s
147-
// WASM_SJLJ: "-cc1" {{.*}} "-target-feature" "+exception-handling" "-exception-model=wasm"
161+
// WASM_SJLJ: "-cc1" {{.*}} "-target-feature" "+exception-handling" "-exception-model=wasm" "-target-feature" "+multivalue" "-target-feature" "+reference-types"
148162

149163
// '-mllvm -wasm-enable-sjlj' not allowed with '-mno-exception-handling'
150164
// RUN: not %clang -### --target=wasm32-unknown-unknown \
@@ -168,6 +182,19 @@
168182
// RUN: | FileCheck -check-prefix=WASM_SJLJ_EMSCRIPTEN_SJLJ %s
169183
// WASM_SJLJ_EMSCRIPTEN_SJLJ: invalid argument '-mllvm -wasm-enable-sjlj' not allowed with '-mllvm -enable-emscripten-sjlj'
170184

185+
// '-mllvm -wasm-enable-sjlj' not allowed with '-mno-multivalue'
186+
// RUN: not %clang -### --target=wasm32-unknown-unknown \
187+
// RUN: --sysroot=/foo %s -mllvm -wasm-enable-sjlj -mno-multivalue 2>&1 \
188+
// RUN: | FileCheck -check-prefix=WASM_SJLJ_NO_MULTIVALUE %s
189+
// WASM_SJLJ_NO_MULTIVALUE: invalid argument '-mllvm -wasm-enable-sjlj' not allowed with '-mno-multivalue'
190+
191+
// '-mllvm -wasm-enable-sjlj' not allowed with '-mno-reference-types'
192+
// RUN: not %clang -### --target=wasm32-unknown-unknown \
193+
// RUN: --sysroot=/foo %s -mllvm -wasm-enable-sjlj \
194+
// RUN: -mno-reference-types 2>&1 \
195+
// RUN: | FileCheck -check-prefix=WASM_SJLJ_NO_REFERENCE_TYPES %s
196+
// WASM_SJLJ_NO_REFERENCE_TYPES: invalid argument '-mllvm -wasm-enable-sjlj' not allowed with '-mno-reference-types'
197+
171198
// RUN: %clang -### %s -fsanitize=address --target=wasm32-unknown-emscripten 2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
172199
// CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
173200
// CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"

0 commit comments

Comments
 (0)