diff options
author | Artem Belevich <tra@google.com> | 2015-09-22 17:23:05 +0000 |
---|---|---|
committer | Artem Belevich <tra@google.com> | 2015-09-22 17:23:05 +0000 |
commit | 9674a64cd9f83b6ad7b8b4d1dab82966ad7e050b (patch) | |
tree | 6568637bd1f2779df4b61d5a3c6fdc8cdd2022aa /clang/test/SemaCUDA/builtins.cu | |
parent | 94a55e8169a1e82a2cf954e0495a899cfddee1ac (diff) | |
download | bcm5719-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.cu | 36 |
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 |