summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorArtem Belevich <tra@google.com>2015-08-19 20:48:20 +0000
committerArtem Belevich <tra@google.com>2015-08-19 20:48:20 +0000
commit39259ffc65556b2e848ff691f6611f896c0ed6aa (patch)
tree2d1499fac723f833c6a5af56ee1d0a1be90e750d /clang/test
parent61ede1519cdfb3d390bb268dc0e9ce8dcb277c30 (diff)
downloadbcm5719-llvm-39259ffc65556b2e848ff691f6611f896c0ed6aa.tar.gz
bcm5719-llvm-39259ffc65556b2e848ff691f6611f896c0ed6aa.zip
[CUDA] Add appropriate host/device attribute to builtins.
Differential Revision: http://reviews.llvm.org/D12122 llvm-svn: 245496
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCUDA/builtins.cu35
-rw-r--r--clang/test/SemaCUDA/implicit-intrinsic.cu6
2 files changed, 38 insertions, 3 deletions
diff --git a/clang/test/SemaCUDA/builtins.cu b/clang/test/SemaCUDA/builtins.cu
new file mode 100644
index 00000000000..80b9d69980b
--- /dev/null
+++ b/clang/test/SemaCUDA/builtins.cu
@@ -0,0 +1,35 @@
+// 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 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device \
+// RUN: -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
diff --git a/clang/test/SemaCUDA/implicit-intrinsic.cu b/clang/test/SemaCUDA/implicit-intrinsic.cu
index 3d24aa719e5..7414a66b03c 100644
--- a/clang/test/SemaCUDA/implicit-intrinsic.cu
+++ b/clang/test/SemaCUDA/implicit-intrinsic.cu
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=gnu++11 -triple nvptx64-unknown-unknown -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-unknown-unknown -fcuda-is-device -fsyntax-only -verify %s
#include "Inputs/cuda.h"
// expected-no-diagnostics
__device__ void __threadfence_system() {
- // This shouldn't produce an error, since __nvvm_membar_sys is inferred to
- // be __host__ __device__ and thus callable from device code.
+ // This shouldn't produce an error, since __nvvm_membar_sys should be
+ // __device__ and thus callable from device code.
__nvvm_membar_sys();
}
OpenPOWER on IntegriCloud