1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 // Check that it's OK for kernels to call HD functions that call device-only
6 #include "Inputs/cuda.h"
8 __device__ void device_fn(int) {}
9 // expected-note@-1 2 {{declared here}}
11 inline __host__ __device__ int hd1() {
12 device_fn(0); // expected-error {{reference to __device__ function}}
16 inline __host__ __device__ int hd2() {
17 // No error here because hd2 is only referenced from a kernel.
22 inline __host__ __device__ void hd3(int) {
23 device_fn(0); // expected-error {{reference to __device__ function 'device_fn'}}
25 inline __host__ __device__ void hd3(double) {}
27 inline __host__ __device__ void hd4(int) {}
28 inline __host__ __device__ void hd4(double) {
29 device_fn(0); // No error; this function is never called.
32 __global__ void kernel(int) { hd2(); }
35 void launch_kernel() {
36 kernel<<<0, 0>>>(T());
38 // Notice that these two diagnostics are different: Because the call to hd1
39 // is not dependent on T, the call to hd1 comes from 'launch_kernel', while
40 // the call to hd3, being dependent, comes from 'launch_kernel<int>'.
41 hd1(); // expected-note {{called by 'launch_kernel<int>'}}
42 hd3(T()); // expected-note {{called by 'launch_kernel<int>'}}
47 // expected-note@-1 2 {{called by 'host_fn'}}