https://github.com/aheejin updated https://github.com/llvm/llvm-project/pull/92604
>From bedab4dc6edc3fd44d79c42d4fd62dc1a6937fb0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn <ahee...@gmail.com> Date: Fri, 17 May 2024 20:41:21 +0000 Subject: [PATCH 1/3] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions When using other specific exception options in Clang, such as `-fseh-exceptions` or `-fsjlj-exceptions`, Clang defines a corresponding preprocessor such as `-D__USING_SJLJ_EXCEPTIONS__`. Emscripten does that in our own build system: https://github.com/emscripten-core/emscripten/blob/7dcd7f40749918e141dc33397d2f4311dd80637a/tools/system_libs.py#L1577-L1578 But to make Wasm EH usable in non-Emscripten toolchain, this has to be defined somewhere else. This PR makes Wasm EH consistent with other exception scheme by letting it defined by Clang depending on the exception option. --- clang/lib/Frontend/InitPreprocessor.cpp | 2 ++ clang/test/CodeGenCXX/wasm-eh.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index c1d209466ffe5..3cc85ff502776 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI, else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions()) + Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp b/clang/test/CodeGenCXX/wasm-eh.cpp index af023f52191b9..09588985d4e74 100644 --- a/clang/test/CodeGenCXX/wasm-eh.cpp +++ b/clang/test/CodeGenCXX/wasm-eh.cpp @@ -1,4 +1,8 @@ // REQUIRES: webassembly-registered-target + +// RUN: %clang -E -dM %s -target wasm32-unknown-unknown -fwasm-exceptions | FileCheck %s -check-prefix PREPROCESSOR +// PREPROCESSOR: #define __USING_WASM_EXCEPTIONS__ 1 + // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s >From 38b517419cb60e9fb88828847fd8d57542e9a651 Mon Sep 17 00:00:00 2001 From: Heejin Ahn <ahee...@gmail.com> Date: Fri, 17 May 2024 21:25:07 +0000 Subject: [PATCH 2/3] Add Wasm condition --- clang/lib/Frontend/InitPreprocessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 3cc85ff502776..f76f16e2228e7 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,7 +1006,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); - else if (LangOpts.hasWasmExceptions()) + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) >From 8d57019721697c1367e5aca99e032e7c094aedb2 Mon Sep 17 00:00:00 2001 From: Heejin Ahn <ahee...@gmail.com> Date: Fri, 17 May 2024 23:07:19 +0000 Subject: [PATCH 3/3] __USING_WASM_EXCEPTIONS__ -> __WASM_EXCEPTIONS__ --- clang/lib/Frontend/InitPreprocessor.cpp | 2 +- clang/test/CodeGenCXX/wasm-eh.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index f76f16e2228e7..68760e00003e0 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1007,7 +1007,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) - Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); + Builder.defineMacro("__WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp b/clang/test/CodeGenCXX/wasm-eh.cpp index 09588985d4e74..b70c07386fd14 100644 --- a/clang/test/CodeGenCXX/wasm-eh.cpp +++ b/clang/test/CodeGenCXX/wasm-eh.cpp @@ -1,7 +1,7 @@ // REQUIRES: webassembly-registered-target // RUN: %clang -E -dM %s -target wasm32-unknown-unknown -fwasm-exceptions | FileCheck %s -check-prefix PREPROCESSOR -// PREPROCESSOR: #define __USING_WASM_EXCEPTIONS__ 1 +// PREPROCESSOR: #define __WASM_EXCEPTIONS__ 1 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits