From c05d30e444a1208a8a872002d1146b5cf55e370a Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 25 Aug 2021 18:13:46 -0400 Subject: [PATCH] [clang][Emscripten] Define __unix family of macros This will allow us to remove these from the downstream driver: https://github.com/emscripten-core/emscripten/blob/57270ce8150a5107e591b4e9ec7cbeff0ba7c905/emcc.py#L860-L863 Differential Revision: https://reviews.llvm.org/D108735 --- clang/lib/Basic/Targets/OSTargets.h | 1 + clang/test/Preprocessor/init.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 440ec63f9cef..e9dcc9e84dd7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -944,6 +944,7 @@ class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const final { WebAssemblyOSTargetInfo::getOSDefines(Opts, Triple, Builder); + DefineStd(Builder, "unix", Opts); Builder.defineMacro("__EMSCRIPTEN__"); if (Opts.POSIXThreads) Builder.defineMacro("__EMSCRIPTEN_PTHREADS__"); diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 65d737352cad..c14ef173390a 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -1847,8 +1847,10 @@ // WEBASSEMBLY-NEXT:#define __clang_version__ "{{.*}}" // WEBASSEMBLY-NEXT:#define __clang_wide_literal_encoding__ {{.*}} // WEBASSEMBLY-NEXT:#define __llvm__ 1 -// WEBASSEMBLY-NOT:#define __unix -// WEBASSEMBLY-NOT:#define __unix__ +// WEBASSEMBLY-WASI-NOT:#define __unix +// WEBASSEMBLY-WASI-NOT:#define __unix__ +// EMSCRIPTEN-NEXT:#define __unix 1 +// EMSCRIPTEN-NEXT:#define __unix__ 1 // WEBASSEMBLY-WASI-NEXT:#define __wasi__ 1 // WEBASSEMBLY-NOT:#define __wasm_simd128__ // WEBASSEMBLY-NOT:#define __wasm_simd256__ @@ -1863,6 +1865,8 @@ // WEBASSEMBLY64-NEXT:#define __wasm64 1 // WEBASSEMBLY64-NEXT:#define __wasm64__ 1 // WEBASSEMBLY-NEXT:#define __wasm__ 1 +// EMSCRIPTEN:#define unix 1 +// WEBASSEMBLY-WASI-NOT:#define unix 1 // WEBASSEMBLY-CXX-NOT:_REENTRANT // WEBASSEMBLY-CXX-NOT:__STDCPP_THREADS__ // WEBASSEMBLY-CXX-ATOMICS:#define _REENTRANT 1