Justin Lebar | 9730ae9 | 2016-10-19 21:03:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
| 3 | // The hd function template is instantiated three times. |
| 4 | // |
| 5 | // Two of those instantiations call a device function, which is an error when |
| 6 | // compiling for host. Clang should report both errors. |
| 7 | |
| 8 | #include "Inputs/cuda.h" |
| 9 | |
| 10 | template <typename T> |
| 11 | struct Selector {}; |
| 12 | |
| 13 | template <> |
| 14 | struct Selector<int> { |
| 15 | __host__ void f() {} |
| 16 | }; |
| 17 | |
| 18 | template <> |
| 19 | struct Selector<float> { |
| 20 | __device__ void f() {} // expected-note {{declared here}} |
| 21 | }; |
| 22 | |
| 23 | template <> |
| 24 | struct Selector<double> { |
| 25 | __device__ void f() {} // expected-note {{declared here}} |
| 26 | }; |
| 27 | |
| 28 | template <typename T> |
| 29 | inline __host__ __device__ void hd() { |
| 30 | Selector<T>().f(); |
Justin Lebar | 4d38a5c | 2016-10-21 20:50:47 +0000 | [diff] [blame] | 31 | // expected-error@-1 2 {{reference to __device__ function}} |
Justin Lebar | 9730ae9 | 2016-10-19 21:03:38 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void host_fn() { |
| 35 | hd<int>(); |
| 36 | hd<double>(); // expected-note {{function template specialization 'hd<double>'}} |
Justin Lebar | 6c86e91 | 2016-10-19 21:15:01 +0000 | [diff] [blame] | 37 | // expected-note@-1 {{called by 'host_fn'}} |
Justin Lebar | 9730ae9 | 2016-10-19 21:03:38 +0000 | [diff] [blame] | 38 | hd<float>(); // expected-note {{function template specialization 'hd<float>'}} |
Justin Lebar | 6c86e91 | 2016-10-19 21:15:01 +0000 | [diff] [blame] | 39 | // expected-note@-1 {{called by 'host_fn'}} |
Justin Lebar | 9730ae9 | 2016-10-19 21:03:38 +0000 | [diff] [blame] | 40 | } |