[PATCH] D96171: [clang][emscripten] Add builtin define for __EMSCRIPTEN_PTHREADS__

Sam Clegg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 5 12:50:01 PST 2021


sbc100 created this revision.
Herald added subscribers: wingo, jfb, dschuff.
sbc100 requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

Currently the emscripten frontend driver injects this when building
with thread support.  Moving this into the clang driver itself makes
the emscripten python driver less magical.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96171

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===================================================================
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1473,6 +1473,15 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm64-unknown-unknown \
 // RUN:   < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY,WEBASSEMBLY64 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm32-emscripten \
+// RUN:   < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY,WEBASSEMBLY32,EMSCRIPTEN %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm32-emscripten -pthread -target-feature +atomics \
+// RUN:   < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY,WEBASSEMBLY32,EMSCRIPTEN,EMSCRIPTEN-THREADS %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm64-emscripten \
+// RUN:   < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY,WEBASSEMBLY64,EMSCRIPTEN %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=wasm32-wasi \
 // RUN:   < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefixes=WEBASSEMBLY,WEBASSEMBLY32,WEBASSEMBLY-WASI %s
@@ -1490,6 +1499,7 @@
 // WEBASSEMBLY32-NOT:#define _LP64
 // WEBASSEMBLY64-NOT:#define _ILP32
 // WEBASSEMBLY64:#define _LP64 1
+// EMSCRIPTEN-THREADS:#define _REENTRANT 1
 // WEBASSEMBLY-NEXT:#define __ATOMIC_ACQUIRE 2
 // WEBASSEMBLY-NEXT:#define __ATOMIC_ACQ_REL 4
 // WEBASSEMBLY-NEXT:#define __ATOMIC_CONSUME 1
@@ -1529,6 +1539,8 @@
 // WEBASSEMBLY-NEXT:#define __DBL_MIN__ 2.2250738585072014e-308
 // WEBASSEMBLY-NEXT:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
 // WEBASSEMBLY-NOT:#define __ELF__
+// EMSCRIPTEN-THREADS-NEXT:#define __EMSCRIPTEN_PTHREADS__ 1
+// EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
 // WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
 // WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
 // WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
Index: clang/lib/Basic/Targets/OSTargets.h
===================================================================
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -940,6 +940,8 @@
                     MacroBuilder &Builder) const final {
     WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
     Builder.defineMacro("__EMSCRIPTEN__");
+    if (Opts.POSIXThreads)
+      Builder.defineMacro("__EMSCRIPTEN_PTHREADS__");
   }
 
 public:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96171.321854.patch
Type: text/x-patch
Size: 2557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210205/619fae3c/attachment.bin>


More information about the cfe-commits mailing list