From: Abhina Sreeskantharajan Date: Tue, 25 Aug 2020 17:50:17 +0000 (-0400) Subject: [SystemZ][z/OS] Add z/OS Target and define macros X-Git-Tag: llvmorg-13-init~13774 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97ccf93b3615ff4c0d5fe116e6a7c7b616d8ec0c;p=platform%2Fupstream%2Fllvm.git [SystemZ][z/OS] Add z/OS Target and define macros This patch adds the z/OS target and defines macros as a stepping stone towards enabling a native build on z/OS. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D85324 --- diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 38a388a..933b7b3 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -452,6 +452,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple, switch (os) { case llvm::Triple::Linux: return new LinuxTargetInfo(Triple, Opts); + case llvm::Triple::ZOS: + return new ZOSTargetInfo(Triple, Opts); default: return new SystemZTargetInfo(Triple, Opts); } diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a2c0fd4..9c206fc 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -728,6 +728,55 @@ public: bool defaultsToAIXPowerAlignment() const override { return true; } }; +// z/OS target +template +class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { +protected: + void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, + MacroBuilder &Builder) const override { + // FIXME: _LONG_LONG should not be defined under -std=c89. + Builder.defineMacro("_LONG_LONG"); + Builder.defineMacro("_OPEN_DEFAULT"); + // _UNIX03_WITHDRAWN is required to build libcxx. + Builder.defineMacro("_UNIX03_WITHDRAWN"); + Builder.defineMacro("__370__"); + Builder.defineMacro("__BFP__"); + // FIXME: __BOOL__ should not be defined under -std=c89. + Builder.defineMacro("__BOOL__"); + Builder.defineMacro("__LONGNAME__"); + Builder.defineMacro("__MVS__"); + Builder.defineMacro("__THW_370__"); + Builder.defineMacro("__THW_BIG_ENDIAN__"); + Builder.defineMacro("__TOS_390__"); + Builder.defineMacro("__TOS_MVS__"); + Builder.defineMacro("__XPLINK__"); + + if (this->PointerWidth == 64) + Builder.defineMacro("__64BIT__"); + + if (Opts.CPlusPlus) { + Builder.defineMacro("__DLL__"); + // _XOPEN_SOURCE=600 is required to build libcxx. + Builder.defineMacro("_XOPEN_SOURCE", "600"); + } + + if (Opts.GNUMode) { + Builder.defineMacro("_MI_BUILTIN"); + Builder.defineMacro("_EXT"); + } + + if (Opts.CPlusPlus && Opts.WChar) { + // Macro __wchar_t is defined so that the wchar_t data + // type is not declared as a typedef in system headers. + Builder.defineMacro("__wchar_t"); + } + } + +public: + ZOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) + : OSTargetInfo(Triple, Opts) {} +}; + void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder); diff --git a/clang/test/Preprocessor/init-zos.c b/clang/test/Preprocessor/init-zos.c new file mode 100644 index 0000000..50c4ed9 --- /dev/null +++ b/clang/test/Preprocessor/init-zos.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s +// RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-GNUXX %s + +// S390X-ZOS-GNUXX:#define _EXT 1 +// S390X-ZOS:#define _LONG_LONG 1 +// S390X-ZOS-GNUXX:#define _MI_BUILTIN 1 +// S390X-ZOS:#define _OPEN_DEFAULT 1 +// S390X-ZOS:#define _UNIX03_WITHDRAWN 1 +// S390X-ZOS-GNUXX:#define _XOPEN_SOURCE 600 +// S390X-ZOS:#define __370__ 1 +// S390X-ZOS:#define __64BIT__ 1 +// S390X-ZOS:#define __BFP__ 1 +// S390X-ZOS:#define __BOOL__ 1 +// S390X-ZOS-GNUXX:#define __DLL__ 1 +// S390X-ZOS:#define __LONGNAME__ 1 +// S390X-ZOS:#define __MVS__ 1 +// S390X-ZOS:#define __THW_370__ 1 +// S390X-ZOS:#define __THW_BIG_ENDIAN__ 1 +// S390X-ZOS:#define __TOS_390__ 1 +// S390X-ZOS:#define __TOS_MVS__ 1 +// S390X-ZOS:#define __XPLINK__ 1 +// S390X-ZOS-GNUXX:#define __wchar_t 1