summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCUDA/builtins.cu
diff options
context:
space:
mode:
authorArtem Belevich <tra@google.com>2015-09-22 17:23:05 +0000
committerArtem Belevich <tra@google.com>2015-09-22 17:23:05 +0000
commit9674a64cd9f83b6ad7b8b4d1dab82966ad7e050b (patch)
tree6568637bd1f2779df4b61d5a3c6fdc8cdd2022aa /clang/test/SemaCUDA/builtins.cu
parent94a55e8169a1e82a2cf954e0495a899cfddee1ac (diff)
downloadbcm5719-llvm-9674a64cd9f83b6ad7b8b4d1dab82966ad7e050b.tar.gz
bcm5719-llvm-9674a64cd9f83b6ad7b8b4d1dab82966ad7e050b.zip
[CUDA] Add appropriate host/device attribute to builtins.
The changes are part of attribute-based CUDA function overloading (D12453) and as such are only enabled when it's in effect (-fcuda-target-overloads). Differential Revision: http://reviews.llvm.org/D12122 llvm-svn: 248296
Diffstat (limited to 'clang/test/SemaCUDA/builtins.cu')
-rw-r--r--clang/test/SemaCUDA/builtins.cu36
1 files changed, 36 insertions, 0 deletions
diff --git a/clang/test/SemaCUDA/builtins.cu b/clang/test/SemaCUDA/builtins.cu
new file mode 100644
index 00000000000..2c619b56339
--- /dev/null
+++ b/clang/test/SemaCUDA/builtins.cu
@@ -0,0 +1,36 @@
+// Tests that target-specific builtins have appropriate host/device
+// attributes and that CUDA call restrictions are enforced. Also
+// verify that non-target builtins can be used from both host and
+// device functions.
+//
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -fcuda-target-overloads -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device \
+// RUN: -fcuda-target-overloads -fsyntax-only -verify %s
+
+
+#ifdef __CUDA_ARCH__
+// Device-side builtins are not allowed to be called from host functions.
+void hf() {
+ int x = __builtin_ptx_read_tid_x(); // expected-note {{'__builtin_ptx_read_tid_x' declared here}}
+ // expected-error@-1 {{reference to __device__ function '__builtin_ptx_read_tid_x' in __host__ function}}
+ x = __builtin_abs(1);
+}
+__attribute__((device)) void df() {
+ int x = __builtin_ptx_read_tid_x();
+ x = __builtin_abs(1);
+}
+#else
+// Host-side builtins are not allowed to be called from device functions.
+__attribute__((device)) void df() {
+ int x = __builtin_ia32_rdtsc(); // expected-note {{'__builtin_ia32_rdtsc' declared here}}
+ // expected-error@-1 {{reference to __host__ function '__builtin_ia32_rdtsc' in __device__ function}}
+ x = __builtin_abs(1);
+}
+void hf() {
+ int x = __builtin_ia32_rdtsc();
+ x = __builtin_abs(1);
+}
+#endif
OpenPOWER on IntegriCloud