[llvm] [WebAssembly] Add tests for EH/SjLj option errors (PR #93583)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 10:28:50 PDT 2024
https://github.com/aheejin created https://github.com/llvm/llvm-project/pull/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)
>From 7e91a90023a90634959961bb035e15f2a57038e8 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Mon, 27 May 2024 21:59:40 +0000
Subject: [PATCH] [WebAssembly] Add tests for EH/SjLj option errors
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)
---
.../WebAssembly/WebAssemblyTargetMachine.cpp | 34 ++++++++++---------
.../CodeGen/WebAssembly/eh-option-errors.ll | 19 +++++++++++
.../WebAssembly/lower-em-ehsjlj-options.ll | 3 --
3 files changed, 37 insertions(+), 19 deletions(-)
create mode 100644 llvm/test/CodeGen/WebAssembly/eh-option-errors.ll
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index de342e8965736..68126992ddcd7 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -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
@@ -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.
diff --git a/llvm/test/CodeGen/WebAssembly/eh-option-errors.ll b/llvm/test/CodeGen/WebAssembly/eh-option-errors.ll
new file mode 100644
index 0000000000000..74d02ddc405d3
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/eh-option-errors.ll
@@ -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
diff --git a/llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll b/llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll
index 4a63c812d6ae9..66872a5422986 100644
--- a/llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll
+++ b/llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll
@@ -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"
@@ -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
More information about the llvm-commits
mailing list