blob: ea7a4cce8d2b6e5ab9642daa9369fbf95730f582 [file] [log] [blame]
Justin Lebar18e2d822016-08-15 23:00:49 +00001// RUN: %clang_cc1 %s --std=c++11 -triple nvptx-unknown-unknown -fcuda-is-device -emit-llvm -o - -verify
2
3// Note: This test won't work with -fsyntax-only, because some of these errors
4// are emitted during codegen.
5
6#include "Inputs/cuda.h"
7
8extern "C" void host_fn() {}
9
10struct S {
11 S() {}
12 ~S() { host_fn(); }
13 int x;
14};
15
16struct T {
17 __host__ __device__ void hd() { host_fn(); }
18 // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
19
20 // No error; this is (implicitly) inline and is never called, so isn't
21 // codegen'ed.
22 __host__ __device__ void hd2() { host_fn(); }
23
24 __host__ __device__ void hd3();
25
26 void h() {}
27};
28
29__host__ __device__ void T::hd3() {
30 host_fn();
31 // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
32}
33
34template <typename T> __host__ __device__ void hd2() { host_fn(); }
35// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
36__global__ void kernel() { hd2<int>(); }
37
38__host__ __device__ void hd() { host_fn(); }
39// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
40
41template <typename T> __host__ __device__ void hd3() { host_fn(); }
42// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
43__device__ void device_fn() { hd3<int>(); }
44
45// No error because this is never instantiated.
46template <typename T> __host__ __device__ void hd4() { host_fn(); }
47
48__host__ __device__ void local_var() {
49 S s;
50 // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}}
51}
52
53__host__ __device__ void placement_new(char *ptr) {
54 ::new(ptr) S();
55 // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}}
56}
57
58__host__ __device__ void explicit_destructor(S *s) {
59 s->~S();
60 // expected-error@-1 {{reference to __host__ function '~S' in __host__ __device__ function}}
61}
62
63__host__ __device__ void hd_member_fn() {
64 T t;
65 // Necessary to trigger an error on T::hd. It's (implicitly) inline, so
66 // isn't codegen'ed until we call it.
67 t.hd();
68}
69
70__host__ __device__ void h_member_fn() {
71 T t;
72 t.h();
73 // expected-error@-1 {{reference to __host__ function 'h' in __host__ __device__ function}}
74}
75
76__host__ __device__ void fn_ptr() {
77 auto* ptr = &host_fn;
78 // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
79}
80
81template <typename T>
82__host__ __device__ void fn_ptr_template() {
83 auto* ptr = &host_fn; // Not an error because the template isn't instantiated.
84}