Skip to content

Commit 08de0b3

Browse files
authored
[WebAssembly] Add tests for EH/SjLj option errors (llvm#93583)
This adds tests for EH/SjLj option errors and swaps the error checking order for unimportant cosmetic reasons (I think checking EH/SjLj conflicts is more important than the model checking)
1 parent 196a080 commit 08de0b3

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,29 @@ using WebAssembly::WasmEnableEmSjLj;
388388
using WebAssembly::WasmEnableSjLj;
389389

390390
static void basicCheckForEHAndSjLj(TargetMachine *TM) {
391-
// Before checking, we make sure TargetOptions.ExceptionModel is the same as
391+
392+
// You can't enable two modes of EH at the same time
393+
if (WasmEnableEmEH && WasmEnableEH)
394+
report_fatal_error(
395+
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
396+
// You can't enable two modes of SjLj at the same time
397+
if (WasmEnableEmSjLj && WasmEnableSjLj)
398+
report_fatal_error(
399+
"-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj");
400+
// You can't mix Emscripten EH with Wasm SjLj.
401+
if (WasmEnableEmEH && WasmEnableSjLj)
402+
report_fatal_error(
403+
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
404+
405+
// Here we make sure TargetOptions.ExceptionModel is the same as
392406
// MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang
393407
// stores the exception model info in LangOptions, which is later transferred
394408
// to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly,
395409
// clang's LangOptions is not used and thus the exception model info is not
396410
// correctly transferred to TargetOptions and MCAsmInfo, so we make sure we
397-
// have the correct exception model in WebAssemblyMCAsmInfo constructor.
398-
// But in this case TargetOptions is still not updated, so we make sure they
399-
// are the same.
411+
// have the correct exception model in WebAssemblyMCAsmInfo constructor. But
412+
// in this case TargetOptions is still not updated, so we make sure they are
413+
// the same.
400414
TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();
401415

402416
// Basic Correctness checking related to -exception-model
@@ -418,18 +432,6 @@ static void basicCheckForEHAndSjLj(TargetMachine *TM) {
418432
"-exception-model=wasm only allowed with at least one of "
419433
"-wasm-enable-eh or -wasm-enable-sjlj");
420434

421-
// You can't enable two modes of EH at the same time
422-
if (WasmEnableEmEH && WasmEnableEH)
423-
report_fatal_error(
424-
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
425-
// You can't enable two modes of SjLj at the same time
426-
if (WasmEnableEmSjLj && WasmEnableSjLj)
427-
report_fatal_error(
428-
"-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj");
429-
// You can't mix Emscripten EH with Wasm SjLj.
430-
if (WasmEnableEmEH && WasmEnableSjLj)
431-
report_fatal_error(
432-
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
433435
// Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
434436
// measure, but some code will error out at compile time in this combination.
435437
// See WebAssemblyLowerEmscriptenEHSjLj pass for details.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
target triple = "wasm32-unknown-unknown"
2+
3+
; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -wasm-enable-eh 2>&1 | FileCheck %s --check-prefix=EM_EH_W_WASM_EH
4+
; EM_EH_W_WASM_EH: LLVM ERROR: -enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh
5+
6+
; RUN: not --crash llc < %s -enable-emscripten-sjlj -wasm-enable-sjlj 2>&1 | FileCheck %s --check-prefix=EM_SJLJ_W_WASM_SJLJ
7+
; EM_SJLJ_W_WASM_SJLJ: LLVM ERROR: -enable-emscripten-sjlj not allowed with -wasm-enable-sjlj
8+
9+
; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -wasm-enable-sjlj 2>&1 | FileCheck %s --check-prefix=EM_EH_W_WASM_SJLJ
10+
; EM_EH_W_WASM_SJLJ: LLVM ERROR: -enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj
11+
12+
; RUN: not --crash llc < %s -wasm-enable-eh -exception-model=dwarf 2>&1 | FileCheck %s --check-prefix=EH_MODEL_DWARF
13+
; EH_MODEL_DWARF: LLVM ERROR: -exception-model should be either 'none' or 'wasm'
14+
15+
; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -exception-model=wasm 2>&1 | FileCheck %s --check-prefix=EM_EH_W_MODEL_WASM
16+
; EM_EH_W_MODEL_WASM: LLVM ERROR: -exception-model=wasm not allowed with -enable-emscripten-cxx-exceptions
17+
18+
; RUN: not --crash llc < %s -exception-model=wasm 2>&1 | FileCheck %s --check-prefix=MODEL_WASM_WO_WASM_EH_SJLJ
19+
; MODEL_WASM_WO_WASM_EH_SJLJ: LLVM ERROR: -exception-model=wasm only allowed with at least one of -wasm-enable-eh or -wasm-enable-sjlj

llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
; RUN: llc < %s -enable-emscripten-cxx-exceptions | FileCheck %s --check-prefix=EH
22
; RUN: llc < %s -enable-emscripten-sjlj | FileCheck %s --check-prefix=SJLJ
33
; RUN: llc < %s | FileCheck %s --check-prefix=NONE
4-
; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -exception-model=wasm 2>&1 | FileCheck %s --check-prefix=WASM-EH-EM-EH
54

65
target triple = "wasm32-unknown-unknown"
76

@@ -97,5 +96,3 @@ declare void @free(ptr)
9796
attributes #0 = { returns_twice }
9897
attributes #1 = { noreturn }
9998
attributes #2 = { nounwind }
100-
101-
; WASM-EH-EM-EH: LLVM ERROR: -exception-model=wasm not allowed with -enable-emscripten-cxx-exceptions

0 commit comments

Comments
 (0)