blob: d484af141726898eca15327be459934650149c4a [file] [log] [blame]
Justin Lebar23d95422016-10-13 20:52:12 +00001// RUN: %clang_cc1 %s --std=c++11 -triple nvptx-unknown-unknown -fcuda-is-device \
Justin Lebar6c86e912016-10-19 21:15:01 +00002// RUN: -emit-llvm -o /dev/null -verify -verify-ignore-unexpected=note
Justin Lebar18e2d822016-08-15 23:00:49 +00003
4// Note: This test won't work with -fsyntax-only, because some of these errors
5// are emitted during codegen.
6
7#include "Inputs/cuda.h"
8
9extern "C" void host_fn() {}
Justin Lebar26bb3112016-08-16 00:48:21 +000010// expected-note@-1 {{'host_fn' declared here}}
11// expected-note@-2 {{'host_fn' declared here}}
12// expected-note@-3 {{'host_fn' declared here}}
13// expected-note@-4 {{'host_fn' declared here}}
14// expected-note@-5 {{'host_fn' declared here}}
15// expected-note@-6 {{'host_fn' declared here}}
Justin Lebar9fdb46e2016-10-08 01:07:11 +000016// expected-note@-7 {{'host_fn' declared here}}
17
18struct Dummy {};
Justin Lebar18e2d822016-08-15 23:00:49 +000019
20struct S {
21 S() {}
Justin Lebar26bb3112016-08-16 00:48:21 +000022 // expected-note@-1 {{'S' declared here}}
23 // expected-note@-2 {{'S' declared here}}
Justin Lebar18e2d822016-08-15 23:00:49 +000024 ~S() { host_fn(); }
Justin Lebar26bb3112016-08-16 00:48:21 +000025 // expected-note@-1 {{'~S' declared here}}
Justin Lebar18e2d822016-08-15 23:00:49 +000026 int x;
27};
28
29struct T {
30 __host__ __device__ void hd() { host_fn(); }
31 // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
32
33 // No error; this is (implicitly) inline and is never called, so isn't
34 // codegen'ed.
35 __host__ __device__ void hd2() { host_fn(); }
36
37 __host__ __device__ void hd3();
38
39 void h() {}
Justin Lebar26bb3112016-08-16 00:48:21 +000040 // expected-note@-1 {{'h' declared here}}
Justin Lebar9fdb46e2016-10-08 01:07:11 +000041
42 void operator+();
43 // expected-note@-1 {{'operator+' declared here}}
44
45 void operator-(const T&) {}
46 // expected-note@-1 {{'operator-' declared here}}
47
48 operator Dummy() { return Dummy(); }
49 // expected-note@-1 {{'operator Dummy' declared here}}
Richard Smithf75dcbe2016-10-11 00:21:10 +000050
51 __host__ void operator delete(void*);
52 __device__ void operator delete(void*, size_t);
53};
54
55struct U {
56 __device__ void operator delete(void*, size_t) = delete;
57 __host__ __device__ void operator delete(void*);
Justin Lebar18e2d822016-08-15 23:00:49 +000058};
59
60__host__ __device__ void T::hd3() {
61 host_fn();
62 // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
63}
64
65template <typename T> __host__ __device__ void hd2() { host_fn(); }
66// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
67__global__ void kernel() { hd2<int>(); }
68
69__host__ __device__ void hd() { host_fn(); }
70// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
71
72template <typename T> __host__ __device__ void hd3() { host_fn(); }
73// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
74__device__ void device_fn() { hd3<int>(); }
75
76// No error because this is never instantiated.
77template <typename T> __host__ __device__ void hd4() { host_fn(); }
78
79__host__ __device__ void local_var() {
80 S s;
81 // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}}
82}
83
84__host__ __device__ void placement_new(char *ptr) {
85 ::new(ptr) S();
86 // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}}
87}
88
89__host__ __device__ void explicit_destructor(S *s) {
90 s->~S();
91 // expected-error@-1 {{reference to __host__ function '~S' in __host__ __device__ function}}
92}
93
Richard Smithf75dcbe2016-10-11 00:21:10 +000094__host__ __device__ void class_specific_delete(T *t, U *u) {
95 delete t; // ok, call sized device delete even though host has preferable non-sized version
96 delete u; // ok, call non-sized HD delete rather than sized D delete
97}
98
Justin Lebar18e2d822016-08-15 23:00:49 +000099__host__ __device__ void hd_member_fn() {
100 T t;
101 // Necessary to trigger an error on T::hd. It's (implicitly) inline, so
102 // isn't codegen'ed until we call it.
103 t.hd();
104}
105
106__host__ __device__ void h_member_fn() {
107 T t;
108 t.h();
109 // expected-error@-1 {{reference to __host__ function 'h' in __host__ __device__ function}}
110}
111
112__host__ __device__ void fn_ptr() {
113 auto* ptr = &host_fn;
114 // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
115}
116
117template <typename T>
118__host__ __device__ void fn_ptr_template() {
119 auto* ptr = &host_fn; // Not an error because the template isn't instantiated.
120}
Justin Lebar9fdb46e2016-10-08 01:07:11 +0000121
122__host__ __device__ void unaryOp() {
123 T t;
124 (void) +t; // expected-error {{reference to __host__ function 'operator+' in __host__ __device__ function}}
125}
126
127__host__ __device__ void binaryOp() {
128 T t;
129 (void) (t - t); // expected-error {{reference to __host__ function 'operator-' in __host__ __device__ function}}
130}
131
132__host__ __device__ void implicitConversion() {
133 T t;
134 Dummy d = t; // expected-error {{reference to __host__ function 'operator Dummy' in __host__ __device__ function}}
135}
136
137template <typename T>
138struct TmplStruct {
139 template <typename U> __host__ __device__ void fn() {}
140};
141
142template <>
143template <>
144__host__ __device__ void TmplStruct<int>::fn<int>() { host_fn(); }
145// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
146
147__device__ void double_specialization() { TmplStruct<int>().fn<int>(); }