Skip to content

Commit e82caa3

Browse files
author
Justin Lebar
committedMar 23, 2016
[CUDA] Simplify SemaCUDA/function-overload.cu test.
Summary: Principally, don't hardcode the line numbers of various notes. This lets us make changes to the test without recomputing linenos everywhere. Instead, just tell -verify that we may get 0 or more notes pointing to the relevant function definitions. Checking that we get exactly the right note isn't so important (and anyway is checked elsewhere). Reviewers: tra Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18385 llvm-svn: 264206
1 parent 3345351 commit e82caa3

File tree

1 file changed

+77
-84
lines changed

1 file changed

+77
-84
lines changed
 

‎clang/test/SemaCUDA/function-overload.cu

+77-84
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,85 @@
1616

1717
#include "Inputs/cuda.h"
1818

19-
typedef int (*fp_t)(void);
20-
typedef void (*gp_t)(void);
19+
typedef int (*fp_t)();
20+
typedef void (*gp_t)();
2121

22-
// Host and unattributed functions can't be overloaded
23-
__host__ int hh(void) { return 1; } // expected-note {{previous definition is here}}
24-
int hh(void) { return 1; } // expected-error {{redefinition of 'hh'}}
22+
// Host and unattributed functions can't be overloaded.
23+
__host__ void hh() {} // expected-note {{previous definition is here}}
24+
void hh() {} // expected-error {{redefinition of 'hh'}}
2525

26-
// H/D overloading is OK
27-
__host__ int dh(void) { return 2; }
28-
__device__ int dh(void) { return 2; }
26+
// H/D overloading is OK.
27+
__host__ int dh() { return 2; }
28+
__device__ int dh() { return 2; }
2929

30-
// H/HD and D/HD are not allowed
31-
__host__ __device__ int hdh(void) { return 5; } // expected-note {{previous definition is here}}
32-
__host__ int hdh(void) { return 4; } // expected-error {{redefinition of 'hdh'}}
30+
// H/HD and D/HD are not allowed.
31+
__host__ __device__ int hdh() { return 5; } // expected-note {{previous definition is here}}
32+
__host__ int hdh() { return 4; } // expected-error {{redefinition of 'hdh'}}
3333

34-
__host__ int hhd(void) { return 4; } // expected-note {{previous definition is here}}
35-
__host__ __device__ int hhd(void) { return 5; } // expected-error {{redefinition of 'hhd'}}
34+
__host__ int hhd() { return 4; } // expected-note {{previous definition is here}}
35+
__host__ __device__ int hhd() { return 5; } // expected-error {{redefinition of 'hhd'}}
3636
// expected-warning@-1 {{attribute declaration must precede definition}}
3737
// expected-note@-3 {{previous definition is here}}
3838

39-
__host__ __device__ int hdd(void) { return 7; } // expected-note {{previous definition is here}}
40-
__device__ int hdd(void) { return 6; } // expected-error {{redefinition of 'hdd'}}
39+
__host__ __device__ int hdd() { return 7; } // expected-note {{previous definition is here}}
40+
__device__ int hdd() { return 6; } // expected-error {{redefinition of 'hdd'}}
4141

42-
__device__ int dhd(void) { return 6; } // expected-note {{previous definition is here}}
43-
__host__ __device__ int dhd(void) { return 7; } // expected-error {{redefinition of 'dhd'}}
42+
__device__ int dhd() { return 6; } // expected-note {{previous definition is here}}
43+
__host__ __device__ int dhd() { return 7; } // expected-error {{redefinition of 'dhd'}}
4444
// expected-warning@-1 {{attribute declaration must precede definition}}
4545
// expected-note@-3 {{previous definition is here}}
4646

47-
// Same tests for extern "C" functions
48-
extern "C" __host__ int chh(void) {return 11;} // expected-note {{previous definition is here}}
49-
extern "C" int chh(void) {return 11;} // expected-error {{redefinition of 'chh'}}
47+
// Same tests for extern "C" functions.
48+
extern "C" __host__ int chh() {return 11;} // expected-note {{previous definition is here}}
49+
extern "C" int chh() {return 11;} // expected-error {{redefinition of 'chh'}}
5050

51-
// H/D overloading is OK
52-
extern "C" __device__ int cdh(void) {return 10;}
53-
extern "C" __host__ int cdh(void) {return 11;}
51+
// H/D overloading is OK.
52+
extern "C" __device__ int cdh() {return 10;}
53+
extern "C" __host__ int cdh() {return 11;}
5454

5555
// H/HD and D/HD overloading is not allowed.
56-
extern "C" __host__ __device__ int chhd1(void) {return 12;} // expected-note {{previous definition is here}}
57-
extern "C" __host__ int chhd1(void) {return 13;} // expected-error {{redefinition of 'chhd1'}}
56+
extern "C" __host__ __device__ int chhd1() {return 12;} // expected-note {{previous definition is here}}
57+
extern "C" __host__ int chhd1() {return 13;} // expected-error {{redefinition of 'chhd1'}}
5858

59-
extern "C" __host__ int chhd2(void) {return 13;} // expected-note {{previous definition is here}}
60-
extern "C" __host__ __device__ int chhd2(void) {return 12;} // expected-error {{redefinition of 'chhd2'}}
59+
extern "C" __host__ int chhd2() {return 13;} // expected-note {{previous definition is here}}
60+
extern "C" __host__ __device__ int chhd2() {return 12;} // expected-error {{redefinition of 'chhd2'}}
6161
// expected-warning@-1 {{attribute declaration must precede definition}}
6262
// expected-note@-3 {{previous definition is here}}
6363

6464
// Helper functions to verify calling restrictions.
65-
__device__ int d(void) { return 8; }
66-
__host__ int h(void) { return 9; }
67-
__global__ void g(void) {}
68-
extern "C" __device__ int cd(void) {return 10;}
69-
extern "C" __host__ int ch(void) {return 11;}
70-
71-
__host__ void hostf(void) {
65+
__device__ int d() { return 8; }
66+
// expected-note@-1 1+ {{'d' declared here}}
67+
// expected-note@-2 1+ {{candidate function not viable: call to __device__ function from __host__ function}}
68+
// expected-note@-3 0+ {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
69+
70+
__host__ int h() { return 9; }
71+
// expected-note@-1 1+ {{'h' declared here}}
72+
// expected-note@-2 1+ {{candidate function not viable: call to __host__ function from __device__ function}}
73+
// expected-note@-3 0+ {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
74+
// expected-note@-4 1+ {{candidate function not viable: call to __host__ function from __global__ function}}
75+
76+
__global__ void g() {}
77+
// expected-note@-1 1+ {{'g' declared here}}
78+
// expected-note@-2 1+ {{candidate function not viable: call to __global__ function from __device__ function}}
79+
// expected-note@-3 0+ {{candidate function not viable: call to __global__ function from __host__ __device__ function}}
80+
// expected-note@-4 1+ {{candidate function not viable: call to __global__ function from __global__ function}}
81+
82+
extern "C" __device__ int cd() {return 10;}
83+
// expected-note@-1 1+ {{'cd' declared here}}
84+
// expected-note@-2 1+ {{candidate function not viable: call to __device__ function from __host__ function}}
85+
// expected-note@-3 0+ {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
86+
87+
extern "C" __host__ int ch() {return 11;}
88+
// expected-note@-1 1+ {{'ch' declared here}}
89+
// expected-note@-2 1+ {{candidate function not viable: call to __host__ function from __device__ function}}
90+
// expected-note@-3 0+ {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
91+
// expected-note@-4 1+ {{candidate function not viable: call to __host__ function from __global__ function}}
92+
93+
__host__ void hostf() {
7294
fp_t dp = d;
7395
// expected-error@-1 {{reference to __device__ function 'd' in __host__ function}}
74-
// expected-note@65 {{'d' declared here}}
7596
fp_t cdp = cd;
7697
// expected-error@-1 {{reference to __device__ function 'cd' in __host__ function}}
77-
// expected-note@68 {{'cd' declared here}}
7898
fp_t hp = h;
7999
fp_t chp = ch;
80100
fp_t dhp = dh;
@@ -83,10 +103,8 @@ __host__ void hostf(void) {
83103

84104
d();
85105
// expected-error@-1 {{no matching function for call to 'd'}}
86-
// expected-note@65 {{candidate function not viable: call to __device__ function from __host__ function}}
87106
cd();
88107
// expected-error@-1 {{no matching function for call to 'cd'}}
89-
// expected-note@68 {{candidate function not viable: call to __device__ function from __host__ function}}
90108
h();
91109
ch();
92110
dh();
@@ -95,108 +113,85 @@ __host__ void hostf(void) {
95113
g<<<0,0>>>();
96114
}
97115

98-
99-
__device__ void devicef(void) {
116+
__device__ void devicef() {
100117
fp_t dp = d;
101118
fp_t cdp = cd;
102119
fp_t hp = h;
103120
// expected-error@-1 {{reference to __host__ function 'h' in __device__ function}}
104-
// expected-note@66 {{'h' declared here}}
105121
fp_t chp = ch;
106122
// expected-error@-1 {{reference to __host__ function 'ch' in __device__ function}}
107-
// expected-note@69 {{'ch' declared here}}
108123
fp_t dhp = dh;
109124
fp_t cdhp = cdh;
110125
gp_t gp = g; // expected-error {{reference to __global__ function 'g' in __device__ function}}
111-
// expected-note@67 {{'g' declared here}}
112126

113127
d();
114128
cd();
115129
h(); // expected-error {{no matching function for call to 'h'}}
116-
// expected-note@66 {{candidate function not viable: call to __host__ function from __device__ function}}
117130
ch(); // expected-error {{no matching function for call to 'ch'}}
118-
// expected-note@69 {{candidate function not viable: call to __host__ function from __device__ function}}
119131
dh();
120132
cdh();
121133
g(); // expected-error {{no matching function for call to 'g'}}
122-
// expected-note@67 {{candidate function not viable: call to __global__ function from __device__ function}}
123134
g<<<0,0>>>(); // expected-error {{reference to __global__ function 'g' in __device__ function}}
124-
// expected-note@67 {{'g' declared here}}
125135
}
126136

127-
__global__ void globalf(void) {
137+
__global__ void globalf() {
128138
fp_t dp = d;
129139
fp_t cdp = cd;
130140
fp_t hp = h;
131141
// expected-error@-1 {{reference to __host__ function 'h' in __global__ function}}
132-
// expected-note@66 {{'h' declared here}}
133142
fp_t chp = ch;
134143
// expected-error@-1 {{reference to __host__ function 'ch' in __global__ function}}
135-
// expected-note@69 {{'ch' declared here}}
136144
fp_t dhp = dh;
137145
fp_t cdhp = cdh;
138146
gp_t gp = g;
139147
// expected-error@-1 {{reference to __global__ function 'g' in __global__ function}}
140-
// expected-note@67 {{'g' declared here}}
141148

142149
d();
143150
cd();
144151
h();
145152
// expected-error@-1 {{no matching function for call to 'h'}}
146-
// expected-note@66 {{candidate function not viable: call to __host__ function from __global__ function}}
147153
ch();
148154
// expected-error@-1 {{no matching function for call to 'ch'}}
149-
// expected-note@69 {{candidate function not viable: call to __host__ function from __global__ function}}
150155
dh();
151156
cdh();
152157
g(); // expected-error {{no matching function for call to 'g'}}
153-
// expected-note@67 {{candidate function not viable: call to __global__ function from __global__ function}}
154158
g<<<0,0>>>(); // expected-error {{reference to __global__ function 'g' in __global__ function}}
155-
// expected-note@67 {{'g' declared here}}
156159
}
157160

158-
__host__ __device__ void hostdevicef(void) {
161+
__host__ __device__ void hostdevicef() {
159162
fp_t dp = d;
160163
fp_t cdp = cd;
164+
#if !defined(NOCHECKS) && !defined(__CUDA_ARCH__)
165+
// expected-error@-3 {{reference to __device__ function 'd' in __host__ __device__ function}}
166+
// expected-error@-3 {{reference to __device__ function 'cd' in __host__ __device__ function}}
167+
#endif
168+
161169
fp_t hp = h;
162170
fp_t chp = ch;
163-
#if !defined(NOCHECKS)
164-
#if !defined(__CUDA_ARCH__)
165-
// expected-error@-6 {{reference to __device__ function 'd' in __host__ __device__ function}}
166-
// expected-note@65 {{'d' declared here}}
167-
// expected-error@-7 {{reference to __device__ function 'cd' in __host__ __device__ function}}
168-
// expected-note@68 {{'cd' declared here}}
169-
#else
170-
// expected-error@-9 {{reference to __host__ function 'h' in __host__ __device__ function}}
171-
// expected-note@66 {{'h' declared here}}
172-
// expected-error@-10 {{reference to __host__ function 'ch' in __host__ __device__ function}}
173-
// expected-note@69 {{'ch' declared here}}
174-
#endif
171+
#if !defined(NOCHECKS) && defined(__CUDA_ARCH__)
172+
// expected-error@-3 {{reference to __host__ function 'h' in __host__ __device__ function}}
173+
// expected-error@-3 {{reference to __host__ function 'ch' in __host__ __device__ function}}
175174
#endif
175+
176176
fp_t dhp = dh;
177177
fp_t cdhp = cdh;
178178
gp_t gp = g;
179179
#if defined(__CUDA_ARCH__)
180180
// expected-error@-2 {{reference to __global__ function 'g' in __host__ __device__ function}}
181-
// expected-note@67 {{'g' declared here}}
182181
#endif
183182

184183
d();
185184
cd();
185+
#if !defined(NOCHECKS) && !defined(__CUDA_ARCH__)
186+
// expected-error@-3 {{no matching function for call to 'd'}}
187+
// expected-error@-3 {{no matching function for call to 'cd'}}
188+
#endif
189+
186190
h();
187191
ch();
188-
#if !defined(NOCHECKS)
189-
#if !defined(__CUDA_ARCH__)
190-
// expected-error@-6 {{no matching function for call to 'd'}}
191-
// expected-note@65 {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
192-
// expected-error@-7 {{no matching function for call to 'cd'}}
193-
// expected-note@68 {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
194-
#else
195-
// expected-error@-9 {{no matching function for call to 'h'}}
196-
// expected-note@66 {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
197-
// expected-error@-10 {{no matching function for call to 'ch'}}
198-
// expected-note@69 {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
199-
#endif
192+
#if !defined(NOCHECKS) && defined(__CUDA_ARCH__)
193+
// expected-error@-3 {{no matching function for call to 'h'}}
194+
// expected-error@-3 {{no matching function for call to 'ch'}}
200195
#endif
201196

202197
dh();
@@ -207,9 +202,7 @@ __host__ __device__ void hostdevicef(void) {
207202
// expected-error@-3 {{call to global function g not configured}}
208203
#else
209204
// expected-error@-5 {{no matching function for call to 'g'}}
210-
// expected-note@67 {{candidate function not viable: call to __global__ function from __host__ __device__ function}}
211-
// expected-error@-6 {{reference to __global__ function 'g' in __host__ __device__ function}}
212-
// expected-note@67 {{'g' declared here}}
205+
// expected-error@-5 {{reference to __global__ function 'g' in __host__ __device__ function}}
213206
#endif // __CUDA_ARCH__
214207
}
215208

0 commit comments

Comments
 (0)
Please sign in to comment.