Author: asb Date: Sat Feb 3 03:56:11 2018 New Revision: 324170 URL: http://llvm.org/viewvc/llvm-project?rev=324170&view=rev Log: [RISCV] Create a LinuxTargetInfo when targeting Linux
Previously, RISCV32TargetInfo or RISCV64TargetInfo were created unconditionally. Use LinuxTargetInfo<RISCV??TargetInfo> to ensure that the proper OS-specific defines are present. This patch only adds logic to instantiate LinuxTargetInfo and leaves a TODO, as I'm reluctant to add logic for other targets (e.g. FreeBSD, RTEMS) until I've produced and tested at least one binary for that OS+target combo. Thanks to @mgrang to reporting the issue. Modified: cfe/trunk/lib/Basic/Targets.cpp cfe/trunk/test/Preprocessor/init.c Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=324170&r1=324169&r2=324170&view=diff ============================================================================== --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Sat Feb 3 03:56:11 2018 @@ -372,8 +372,14 @@ TargetInfo *AllocateTarget(const llvm::T return new AMDGPUTargetInfo(Triple, Opts); case llvm::Triple::riscv32: + // TODO: add cases for FreeBSD, NetBSD, RTEMS once tested. + if (os == llvm::Triple::Linux) + return new LinuxTargetInfo<RISCV32TargetInfo>(Triple, Opts); return new RISCV32TargetInfo(Triple, Opts); case llvm::Triple::riscv64: + // TODO: add cases for FreeBSD, NetBSD, RTEMS once tested. + if (os == llvm::Triple::Linux) + return new LinuxTargetInfo<RISCV64TargetInfo>(Triple, Opts); return new RISCV64TargetInfo(Triple, Opts); case llvm::Triple::sparc: Modified: cfe/trunk/test/Preprocessor/init.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=324170&r1=324169&r2=324170&view=diff ============================================================================== --- cfe/trunk/test/Preprocessor/init.c (original) +++ cfe/trunk/test/Preprocessor/init.c Sat Feb 3 03:56:11 2018 @@ -10005,6 +10005,8 @@ // RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32 < /dev/null \ // RUN: | FileCheck -match-full-lines -check-prefix=RISCV32 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32-unknown-linux < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefixes=RISCV32,RISCV32-LINUX %s // RISCV32: #define _ILP32 1 // RISCV32: #define __ATOMIC_ACQUIRE 2 // RISCV32: #define __ATOMIC_ACQ_REL 4 @@ -10196,13 +10198,22 @@ // RISCV32: #define __WINT_TYPE__ unsigned int // RISCV32: #define __WINT_UNSIGNED__ 1 // RISCV32: #define __WINT_WIDTH__ 32 +// RISCV32-LINUX: #define __gnu_linux__ 1 +// RISCV32-LINUX: #define __linux 1 +// RISCV32-LINUX: #define __linux__ 1 // RISCV32: #define __riscv 1 // RISCV32: #define __riscv_cmodel_medlow 1 // RISCV32: #define __riscv_float_abi_soft 1 // RISCV32: #define __riscv_xlen 32 +// RISCV32-LINUX: #define __unix 1 +// RISCV32-LINUX: #define __unix__ 1 +// RISCV32-LINUX: #define linux 1 +// RISCV32-LINUX: #define unix 1 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv64 < /dev/null \ // RUN: | FileCheck -match-full-lines -check-prefix=RISCV64 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv64-unknown-linux < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefixes=RISCV64,RISCV64-LINUX %s // RISCV64: #define _LP64 1 // RISCV64: #define __ATOMIC_ACQUIRE 2 // RISCV64: #define __ATOMIC_ACQ_REL 4 @@ -10394,7 +10405,14 @@ // RISCV64: #define __WINT_TYPE__ unsigned int // RISCV64: #define __WINT_UNSIGNED__ 1 // RISCV64: #define __WINT_WIDTH__ 32 +// RISCV64-LINUX: #define __gnu_linux__ 1 +// RISCV64-LINUX: #define __linux 1 +// RISCV64-LINUX: #define __linux__ 1 // RISCV64: #define __riscv 1 // RISCV64: #define __riscv_cmodel_medlow 1 // RISCV64: #define __riscv_float_abi_soft 1 // RISCV64: #define __riscv_xlen 64 +// RISCV64-LINUX: #define __unix 1 +// RISCV64-LINUX: #define __unix__ 1 +// RISCV64-LINUX: #define linux 1 +// RISCV64-LINUX: #define unix 1 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits