[clang] 95da64d - [WebAssembly] Use single-threaded mode when -matomics isn't enabled.
Dan Gohman via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 4 18:17:15 PST 2021
Author: Dan Gohman
Date: 2021-02-04T18:16:48-08:00
New Revision: 95da64da23ac3a5855a8934a738b0fa10aa1323c
URL: https://github.com/llvm/llvm-project/commit/95da64da23ac3a5855a8934a738b0fa10aa1323c
DIFF: https://github.com/llvm/llvm-project/commit/95da64da23ac3a5855a8934a738b0fa10aa1323c.diff
LOG: [WebAssembly] Use single-threaded mode when -matomics isn't enabled.
When the -matomics feature is not enabled, disable POSIXThreads
mode and set the thread model to Single, so that we don't predefine
macros like `__STDCPP_THREADS__`.
Differential Revision: https://reviews.llvm.org/D96091
Added:
Modified:
clang/lib/Basic/Targets/WebAssembly.cpp
clang/lib/Basic/Targets/WebAssembly.h
clang/test/Preprocessor/init.c
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index dcb3d8fd7790..89babe85794d 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -253,6 +253,15 @@ ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
Builtin::FirstTSBuiltin);
}
+void WebAssemblyTargetInfo::adjust(LangOptions &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) {
+ Opts.POSIXThreads = false;
+ Opts.setThreadModel(LangOptions::ThreadModelKind::Single);
+ }
+}
+
void WebAssembly32TargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
WebAssemblyTargetInfo::getTargetDefines(Opts, Builder);
diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h
index 0068ccb5d71f..9150d849f601 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -138,6 +138,8 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
bool hasExtIntType() const override { return true; }
bool hasProtectedVisibility() const override { return false; }
+
+ void adjust(LangOptions &Opts) override;
};
class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 23c4989c5152..e29b6d3972f8 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1479,6 +1479,12 @@
// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm64-wasi \
// RUN: < /dev/null \
// RUN: | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY,WEBASSEMBLY64,WEBASSEMBLY-WASI %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm32-unknown-unknown -x c++ \
+// RUN: < /dev/null \
+// RUN: | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY-CXX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm32-unknown-unknown -x c++ -pthread -target-feature +atomics \
+// RUN: < /dev/null \
+// RUN: | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY-CXX-ATOMICS %s
//
// WEBASSEMBLY32:#define _ILP32 1
// WEBASSEMBLY32-NOT:#define _LP64
@@ -1847,6 +1853,10 @@
// WEBASSEMBLY64-NEXT:#define __wasm64 1
// WEBASSEMBLY64-NEXT:#define __wasm64__ 1
// WEBASSEMBLY-NEXT:#define __wasm__ 1
+// WEBASSEMBLY-CXX-NOT:_REENTRANT
+// WEBASSEMBLY-CXX-NOT:__STDCPP_THREADS__
+// WEBASSEMBLY-CXX-ATOMICS:#define _REENTRANT 1
+// WEBASSEMBLY-CXX-ATOMICS:#define __STDCPP_THREADS__ 1
// RUN: %clang_cc1 -E -dM -ffreestanding -triple i686-windows-cygnus < /dev/null | FileCheck -match-full-lines -check-prefix CYGWIN-X32 %s
// CYGWIN-X32: #define __USER_LABEL_PREFIX__ _
More information about the cfe-commits
mailing list