blob: 814fda2ac7d34e2cdc85b4cba4400ffb4ac29443 [file] [log] [blame]
Artem Belevichb5bc9232015-09-22 17:23:22 +00001// Tests that host and target builtins can be used in the same TU,
2// have appropriate host/device attributes and that CUDA call
3// restrictions are enforced. Also verify that non-target builtins can
4// be used from both host and device functions.
Artem Belevich9674a642015-09-22 17:23:05 +00005//
6// REQUIRES: x86-registered-target
7// REQUIRES: nvptx-registered-target
8// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
Artem Belevichb5bc9232015-09-22 17:23:22 +00009// RUN: -aux-triple nvptx64-unknown-cuda \
Justin Lebar25c4a812016-03-29 16:24:16 +000010// RUN: -fsyntax-only -verify %s
Artem Belevich9674a642015-09-22 17:23:05 +000011// RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device \
Artem Belevichb5bc9232015-09-22 17:23:22 +000012// RUN: -aux-triple x86_64-unknown-unknown \
Justin Lebar25c4a812016-03-29 16:24:16 +000013// RUN: -fsyntax-only -verify %s
Artem Belevich9674a642015-09-22 17:23:05 +000014
Artem Belevichfe5b1ac2018-08-30 20:53:15 +000015#if !(defined(__amd64__) && defined(__PTX__))
16#error "Expected to see preprocessor macros from both sides of compilation."
Artem Belevichb5bc9232015-09-22 17:23:22 +000017#endif
Artem Belevich9674a642015-09-22 17:23:05 +000018
Artem Belevich9674a642015-09-22 17:23:05 +000019void hf() {
Artem Belevichb5bc9232015-09-22 17:23:22 +000020 int x = __builtin_ia32_rdtsc();
Justin Bogner2d5de7e2016-07-07 16:41:08 +000021 int y = __nvvm_read_ptx_sreg_tid_x(); // expected-note {{'__nvvm_read_ptx_sreg_tid_x' declared here}}
22 // expected-error@-1 {{reference to __device__ function '__nvvm_read_ptx_sreg_tid_x' in __host__ function}}
Artem Belevich9674a642015-09-22 17:23:05 +000023 x = __builtin_abs(1);
24}
Artem Belevichb5bc9232015-09-22 17:23:22 +000025
Artem Belevich9674a642015-09-22 17:23:05 +000026__attribute__((device)) void df() {
Justin Bogner2d5de7e2016-07-07 16:41:08 +000027 int x = __nvvm_read_ptx_sreg_tid_x();
Artem Belevichb5bc9232015-09-22 17:23:22 +000028 int y = __builtin_ia32_rdtsc(); // expected-error {{reference to __host__ function '__builtin_ia32_rdtsc' in __device__ function}}
29 // expected-note@20 {{'__builtin_ia32_rdtsc' declared here}}
Artem Belevich9674a642015-09-22 17:23:05 +000030 x = __builtin_abs(1);
31}