summaryrefslogtreecommitdiffstats
path: root/clang/test/Preprocessor
diff options
context:
space:
mode:
authorJonas Hahnfeld <hahnjo@hahnjo.de>2018-08-25 13:42:40 +0000
committerJonas Hahnfeld <hahnjo@hahnjo.de>2018-08-25 13:42:40 +0000
commit931939bf922b45ad8c00e6a0b36d927e42b51661 (patch)
tree9ea1b929d159061137d3e1bfe44a479f117b90b4 /clang/test/Preprocessor
parent7ded6a909bb8baddeee706f5591ecec601270758 (diff)
downloadbcm5719-llvm-931939bf922b45ad8c00e6a0b36d927e42b51661.tar.gz
bcm5719-llvm-931939bf922b45ad8c00e6a0b36d927e42b51661.zip
[CUDA/OpenMP] Define only some host macros during device compilation
When compiling CUDA or OpenMP device code Clang parses header files that expect certain predefined macros from the host architecture. To make this work the compiler passes the host triple via the -aux-triple argument and (until now) pulls in all macros for that "auxiliary triple" unconditionally. However this results in defines like __SSE_MATH__ that will trigger inline assembly making use of the "advertised" target features. See the discussion of D47849 and PR38464 for a detailed explanation of the encountered problems. Instead of blacklisting "known bad" examples this patch starts adding defines that are needed for certain headers like bits/wordsize.h and bits/mathinline.h. The disadvantage of this approach is that it decouples the definitions from their target toolchain. However in my opinion it's more important to keep definitions for one header close together. For one this will include a clear documentation why these particular defines are needed. Furthermore it simplifies maintenance because adding defines for a new header or support for a new aux-triple only needs to touch one piece of code. Differential Revision: https://reviews.llvm.org/D50845 llvm-svn: 340681
Diffstat (limited to 'clang/test/Preprocessor')
-rw-r--r--clang/test/Preprocessor/aux-triple.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/clang/test/Preprocessor/aux-triple.c b/clang/test/Preprocessor/aux-triple.c
new file mode 100644
index 00000000000..0211a156731
--- /dev/null
+++ b/clang/test/Preprocessor/aux-triple.c
@@ -0,0 +1,62 @@
+// Ensure that Clang sets some very basic target defines based on -aux-triple.
+
+// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \
+// RUN: -triple nvptx64-none-none \
+// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding < /dev/null \
+// RUN: -triple nvptx64-none-none \
+// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s
+// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \
+// RUN: -triple nvptx64-none-none \
+// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s
+
+// CUDA:
+// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \
+// RUN: -triple nvptx64-none-none -aux-triple powerpc64le-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines %s \
+// RUN: -check-prefixes NVPTX64,PPC64,LINUX,LINUX-CPP
+// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \
+// RUN: -triple nvptx64-none-none -aux-triple x86_64-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines %s \
+// RUN: -check-prefixes NVPTX64,X86_64,LINUX,LINUX-CPP
+
+// OpenMP:
+// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \
+// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \
+// RUN: -aux-triple powerpc64le-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,PPC64,LINUX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \
+// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \
+// RUN: -aux-triple x86_64-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,X86_64,LINUX %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding < /dev/null \
+// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \
+// RUN: -aux-triple powerpc64le-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines %s \
+// RUN: -check-prefixes NVPTX64,PPC64,LINUX,LINUX-CPP
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding < /dev/null \
+// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \
+// RUN: -aux-triple x86_64-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines %s \
+// RUN: -check-prefixes NVPTX64,X86_64,LINUX,LINUX-CPP
+
+// NONE-NOT:#define _GNU_SOURCE
+// LINUX-CPP:#define _GNU_SOURCE 1
+
+// NVPTX64:#define _LP64 1
+
+// NONE-NOT:#define __ELF__
+// LINUX:#define __ELF__ 1
+
+// NVPTX64:#define __LP64__ 1
+// NVPTX64:#define __NVPTX__ 1
+// NVPTX64:#define __PTX__ 1
+
+// NONE-NOT:#define __linux__
+// LINUX:#define __linux__ 1
+
+// NONE-NOT:#define __powerpc64__
+// PPC64:#define __powerpc64__ 1
+
+// NONE-NOT:#define __x86_64__
+// X86_64:#define __x86_64__ 1
OpenPOWER on IntegriCloud