Skip to content

Commit

Permalink
[WebAssembly] Add tests for EH/SjLj option errors (llvm#93583)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
aheejin committed May 28, 2024
1 parent 196a080 commit 08de0b3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
34 changes: 18 additions & 16 deletions llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,29 @@ using WebAssembly::WasmEnableEmSjLj;
using WebAssembly::WasmEnableSjLj;

static void basicCheckForEHAndSjLj(TargetMachine *TM) {
// Before checking, we make sure TargetOptions.ExceptionModel is the same as

// You can't enable two modes of EH at the same time
if (WasmEnableEmEH && WasmEnableEH)
report_fatal_error(
"-enable-emscripten-cxx-exceptions 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-enable-sjlj");
// You can't mix Emscripten EH with Wasm SjLj.
if (WasmEnableEmEH && WasmEnableSjLj)
report_fatal_error(
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");

// Here we make sure TargetOptions.ExceptionModel is the same as
// MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang
// stores the exception model info in LangOptions, which is later transferred
// to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly,
// clang's LangOptions is not used and thus the exception model info is not
// correctly transferred to TargetOptions and MCAsmInfo, so we make sure we
// have the correct exception model in WebAssemblyMCAsmInfo constructor.
// But in this case TargetOptions is still not updated, so we make sure they
// are the same.
// have the correct exception model in WebAssemblyMCAsmInfo constructor. But
// in this case TargetOptions is still not updated, so we make sure they are
// the same.
TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();

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

// You can't enable two modes of EH at the same time
if (WasmEnableEmEH && WasmEnableEH)
report_fatal_error(
"-enable-emscripten-cxx-exceptions 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-enable-sjlj");
// You can't mix Emscripten EH with Wasm SjLj.
if (WasmEnableEmEH && WasmEnableSjLj)
report_fatal_error(
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
// Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
// measure, but some code will error out at compile time in this combination.
// See WebAssemblyLowerEmscriptenEHSjLj pass for details.
Expand Down
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/WebAssembly/eh-option-errors.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
target triple = "wasm32-unknown-unknown"

; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -wasm-enable-eh 2>&1 | FileCheck %s --check-prefix=EM_EH_W_WASM_EH
; EM_EH_W_WASM_EH: LLVM ERROR: -enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh

; RUN: not --crash llc < %s -enable-emscripten-sjlj -wasm-enable-sjlj 2>&1 | FileCheck %s --check-prefix=EM_SJLJ_W_WASM_SJLJ
; EM_SJLJ_W_WASM_SJLJ: LLVM ERROR: -enable-emscripten-sjlj not allowed with -wasm-enable-sjlj

; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -wasm-enable-sjlj 2>&1 | FileCheck %s --check-prefix=EM_EH_W_WASM_SJLJ
; EM_EH_W_WASM_SJLJ: LLVM ERROR: -enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj

; RUN: not --crash llc < %s -wasm-enable-eh -exception-model=dwarf 2>&1 | FileCheck %s --check-prefix=EH_MODEL_DWARF
; EH_MODEL_DWARF: LLVM ERROR: -exception-model should be either 'none' or 'wasm'

; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -exception-model=wasm 2>&1 | FileCheck %s --check-prefix=EM_EH_W_MODEL_WASM
; EM_EH_W_MODEL_WASM: LLVM ERROR: -exception-model=wasm not allowed with -enable-emscripten-cxx-exceptions

; RUN: not --crash llc < %s -exception-model=wasm 2>&1 | FileCheck %s --check-prefix=MODEL_WASM_WO_WASM_EH_SJLJ
; 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
3 changes: 0 additions & 3 deletions llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
; RUN: llc < %s -enable-emscripten-cxx-exceptions | FileCheck %s --check-prefix=EH
; RUN: llc < %s -enable-emscripten-sjlj | FileCheck %s --check-prefix=SJLJ
; RUN: llc < %s | FileCheck %s --check-prefix=NONE
; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -exception-model=wasm 2>&1 | FileCheck %s --check-prefix=WASM-EH-EM-EH

target triple = "wasm32-unknown-unknown"

Expand Down Expand Up @@ -97,5 +96,3 @@ declare void @free(ptr)
attributes #0 = { returns_twice }
attributes #1 = { noreturn }
attributes #2 = { nounwind }

; WASM-EH-EM-EH: LLVM ERROR: -exception-model=wasm not allowed with -enable-emscripten-cxx-exceptions

0 comments on commit 08de0b3

Please sign in to comment.