xref: /llvm-project/clang/test/SemaCUDA/bad-calls-on-same-line.cu (revision b670ab7b6b3d2f26179213be1da1d4ba376f50a3)
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> {
fSelector15   __host__ void f() {}
16 };
17 
18 template <>
19 struct Selector<float> {
fSelector20   __device__ void f() {} // expected-note {{declared here}}
21 };
22 
23 template <>
24 struct Selector<double> {
fSelector25   __device__ void f() {} // expected-note {{declared here}}
26 };
27 
28 template <typename T>
hd()29 inline __host__ __device__ void hd() {
30   Selector<T>().f();
31   // expected-error@-1 2 {{reference to __device__ function}}
32 }
33 
host_fn()34 void host_fn() {
35   hd<int>();
36   hd<double>();
37   // expected-note@-1 {{called by 'host_fn'}}
38   hd<float>();
39   // expected-note@-1 {{called by 'host_fn'}}
40 }
41