[clang] 3be9e0b - [WebAssembly] Check bulk-memory when adjusting lang opts
Thomas Lively via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 4 16:07:23 PST 2022
Author: Thomas Lively
Date: 2022-03-04T16:07:16-08:00
New Revision: 3be9e0ba972cc3486971f745a606e2c44472b655
URL: https://github.com/llvm/llvm-project/commit/3be9e0ba972cc3486971f745a606e2c44472b655
DIFF: https://github.com/llvm/llvm-project/commit/3be9e0ba972cc3486971f745a606e2c44472b655.diff
LOG: [WebAssembly] Check bulk-memory when adjusting lang opts
We previously had logic to disable pthreads, set the ThreadModel to Single, and
disable thread-safe statics when the atomics target features is disabled, since
that means that the resulting program will not be used in a threaded context.
Similarly check for the presence of the bulk-memory feature, since that is also
necessary to produce multithreaded programs.
Differential Revision: https://reviews.llvm.org/D121014
Added:
Modified:
clang/lib/Basic/Targets/WebAssembly.cpp
clang/test/CodeGenCXX/static-init-wasm.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index 023c03c7cf5c0..18ff109bf2d39 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -256,9 +256,10 @@ ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags,
LangOptions &Opts) {
TargetInfo::adjust(Diags, Opts);
- // If the Atomics feature isn't available, turn off POSIXThreads and
- // ThreadModel, so that we don't predefine _REENTRANT or __STDCPP_THREADS__.
- if (!HasAtomics) {
+ // Turn off POSIXThreads and ThreadModel so that we don't predefine _REENTRANT
+ // or __STDCPP_THREADS__ if we will eventually end up stripping atomics
+ // because they are unsupported.
+ if (!HasAtomics || !HasBulkMemory) {
Opts.POSIXThreads = false;
Opts.setThreadModel(LangOptions::ThreadModelKind::Single);
Opts.ThreadsafeStatics = false;
diff --git a/clang/test/CodeGenCXX/static-init-wasm.cpp b/clang/test/CodeGenCXX/static-init-wasm.cpp
index 0a066de616fa9..3742976ca4947 100644
--- a/clang/test/CodeGenCXX/static-init-wasm.cpp
+++ b/clang/test/CodeGenCXX/static-init-wasm.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -target-feature +atomics -o - %s \
+// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -target-feature +atomics -target-feature +bulk-memory -o - %s \
// RUN: | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -target-feature +atomics -o - %s \
+// RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -target-feature +atomics -target-feature +bulk-memory -o - %s \
// RUN: | FileCheck %s -check-prefix=WEBASSEMBLY64
// Test that we don't create common blocks.
@@ -53,9 +53,9 @@ A theA;
// WEBASSEMBLY64: define internal void @_GLOBAL__sub_I_static_init_wasm.cpp() #3 {
// WEBASSEMBLY64: call void @__cxx_global_var_init()
-// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -o - %s \
+// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -target-feature +bulk-memory -o - %s \
// RUN: | FileCheck %s -check-prefix=NOATOMICS
-// RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -o - %s \
+// RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -target-feature +bulk-memory -o - %s \
// RUN: | FileCheck %s -check-prefix=NOATOMICS
// NOATOMICS-LABEL: @_Z1gv()
@@ -66,3 +66,17 @@ A theA;
// NOATOMICS-NOT: __cxa_guard_acquire
// NOATOMICS: [[END]]:
// NOATOMICS-NEXT: ret void
+
+// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -target-feature +atomics -o - %s \
+// RUN: | FileCheck %s -check-prefix=NOBULKMEM
+// RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -target-feature +atomics -o - %s \
+// RUN: | FileCheck %s -check-prefix=NOBULKMEM
+
+// NOBULKMEM-LABEL: @_Z1gv()
+// NOBULKMEM: %[[R0:.+]] = load i8, i8* @_ZGVZ1gvE1a, align 1
+// NOBULKMEM-NEXT: %guard.uninitialized = icmp eq i8 %[[R0]], 0
+// NOBULKMEM-NEXT: br i1 %guard.uninitialized, label %[[CHECK:.+]], label %[[END:.+]],
+// NOBULKMEM: [[CHECK]]:
+// NOBULKMEM-NOT: __cxa_guard_acquire
+// NOBULKMEM: [[END]]:
+// NOBULKMEM-NEXT: ret void
More information about the cfe-commits
mailing list