1 /* Miscellaneous OpenACC routine front end checking.  */
2 
3 /* Pragma context.  */
4 
5 struct PC
6 {
7 #pragma acc routine /* { dg-error ".#pragma acc routine. must be at file scope" } */
8 };
9 
PC1()10 void PC1( /* { dg-bogus "variable or field .PC1. declared void" "TODO" { xfail c++ } } */
11 #pragma acc routine
12 	 /* { dg-error ".#pragma acc routine. must be at file scope" "" { target c } .-1 }
13 	    { dg-error ".#pragma. is not allowed here" "" { target c++ } .-2 } */
14 ) /* { dg-bogus "expected declaration specifiers or .\\.\\.\\.. before .\\). token" "TODO" { xfail c } } */
15 {
16 }
17 
PC2()18 void PC2()
19 {
20   if (0)
21 #pragma acc routine /* { dg-error ".#pragma acc routine. must be at file scope" } */
22     ;
23 }
24 
PC3()25 void PC3()
26 {
27 #pragma acc routine /* { dg-error ".#pragma acc routine. must be at file scope" } */
28 }
29 
30 
31 /* "( name )" syntax.  */
32 
33 #pragma acc routine ( /* { dg-error "expected (function name|unqualified-id) before end of line" } */
34 #pragma acc routine () /* { dg-error "expected (function name|unqualified-id) before .\\). token" } */
35 #pragma acc routine (+) /* { dg-error "expected (function name|unqualified-id) before .\\+. token" } */
36 #pragma acc routine (?) /* { dg-error "expected (function name|unqualified-id) before .\\?. token" } */
37 #pragma acc routine (:) /* { dg-error "expected (function name|unqualified-id) before .:. token" } */
38 #pragma acc routine (4) /* { dg-error "expected (function name|unqualified-id) before numeric constant" } */
39 #pragma acc routine ('4') /* { dg-error "expected (function name|unqualified-id) before .4." } */
40 #pragma acc routine ("4") /* { dg-error "expected (function name|unqualified-id) before string constant" } */
41 extern void R1(void);
42 extern void R2(void);
43 #pragma acc routine (R1, R2, R3) worker /* { dg-error "expected .\\). before .,. token" } */
44 #pragma acc routine (R1 R2 R3) worker /* { dg-error "expected .\\). before .R2." } */
45 #pragma acc routine (R1) worker
46 #pragma acc routine (R2) worker
47 
48 
49 /* "#pragma acc routine" not immediately followed by (a single) function
50    declaration or definition.  */
51 
52 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
53 int a;
54 
55 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by a single function declaration or definition" } */
56 void fn1 (void), fn1b (void);
57 
58 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
59 int b, fn2 (void);
60 
61 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
62 int b_, fn2_ (void), B_;
63 
64 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by a single function declaration or definition" } */
65 int fn3 (void), b2;
66 
67 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
68 typedef struct c c;
69 
70 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
71 struct d {} d;
72 
73 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
74 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by a single function declaration or definition" } */
75 void fn1_2 (void), fn1b_2 (void);
76 
77 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
78 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
79 int b_2, fn2_2 (void);
80 
81 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
82 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
83 int b_2_, fn2_2_ (void), B_2_;
84 
85 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
86 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by a single function declaration or definition" } */
87 int fn3_2 (void), b2_2;
88 
89 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
90 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
91 typedef struct c_2 c_2;
92 
93 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
94 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
95 struct d_2 {} d_2;
96 
97 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
98 #pragma acc routine
99 int fn4 (void);
100 
101 int fn5a (void);
102 int fn5b (void);
103 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
104 #pragma acc routine (fn5a)
105 #pragma acc routine (fn5b)
106 int fn5 (void);
107 
108 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
109 #pragma acc routine (fn6a) /* { dg-error ".fn6a. has not been declared" } */
110 #pragma acc routine (fn6b) /* { dg-error ".fn6b. has not been declared" } */
111 int fn6 (void);
112 
113 #ifdef __cplusplus
114 
115 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" "" { target c++ } } */
116 namespace f {}
117 
118 namespace g {}
119 
120 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" "" { target c++ } } */
121 using namespace g;
122 
123 #pragma acc routine (g) /* { dg-error ".g. does not refer to a function" "" { target c++ } } */
124 
125 #endif /* __cplusplus */
126 
127 #pragma acc routine (a) /* { dg-error ".a. does not refer to a function" } */
128 
129 #pragma acc routine (c) /* { dg-error ".c. does not refer to a function" } */
130 
131 
132 /* Static assert.  */
133 
134 #pragma acc routine /* { dg-bogus ".#pragma acc routine. not immediately followed by function declaration or definition" "TODO" { xfail *-*-* } } */
135 #ifndef __cplusplus /* C */
136 _Static_assert(0, ""); /* { dg-error "static assertion failed" "" { target c } } */
137 #elif __cplusplus < 201103L /* C++98 */
138 /* C++98 doesn't support static_assert, so fake an error in combination, and as
139    expected with the "#pragma acc routine" above.  */
140 int dummy_instead_of_static_assert;
141 #else /* C++ */
142 static_assert(0, ""); /* { dg-error "static assertion failed" "" { target c++11 } } */
143 #endif
144 void f_static_assert();
145 /* Check that we already recognized "f_static_assert" as an OpenACC routine.  */
146 #pragma acc routine (f_static_assert) /* { dg-error ".#pragma acc routine. already applied to .\[void \]*f_static_assert" "TODO" { xfail *-*-* } } */
147 
148 
149 /* __extension__ usage.  */
150 
151 #pragma acc routine
152 __extension__ extern void ex1();
153 #pragma acc routine (ex1) worker /* { dg-error "has already been marked with an OpenACC 'routine' directive" } */
154 
155 #pragma acc routine
ex2()156 __extension__ __extension__ __extension__ __extension__ __extension__ void ex2()
157 {
158 }
159 #pragma acc routine (ex2) worker /* { dg-error "has already been marked with an OpenACC 'routine' directive" } */
160 
161 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
162 __extension__ int ex3;
163 #pragma acc routine (ex3) /* { dg-error ".ex3. does not refer to a function" } */
164 
165 
166 /* "#pragma acc routine" must be applied before.  */
167 
168 void Bar ();
169 
Foo()170 void Foo ()
171 {
172   Bar ();
173 }
174 
175 #pragma acc routine (Bar) // { dg-error ".#pragma acc routine. must be applied before use" }
176 
177 #pragma acc routine (Foo) gang // { dg-error ".#pragma acc routine. must be applied before definition" }
178 
179 #pragma acc routine (Baz) // { dg-error "not been declared" }
180 
181 
182 /* OpenACC declare.  */
183 
184 int vb1;		/* { dg-error "directive for use" } */
185 extern int vb2;		/* { dg-error "directive for use" } */
186 static int vb3;		/* { dg-error "directive for use" } */
187 
188 #pragma acc routine
189 int
func1(int a)190 func1 (int a)
191 {
192   vb1 = a + 1;
193   vb2 = vb1 + 1;
194   vb3 = vb2 + 1;
195 
196   return vb3;
197 }
198 
199 #pragma acc routine
200 int
func2(int a)201 func2 (int a)
202 {
203   extern int vb4;	/* { dg-error "directive for use" } */
204   static int vb5;
205 
206   vb4 = a + 1;
207   vb5 = vb4 + 1;
208 
209   return vb5;
210 }
211 
212 extern int vb6;			/* { dg-error "clause used in" } */
213 #pragma acc declare link (vb6)
214 static int vb7;			/* { dg-error "clause used in" } */
215 #pragma acc declare link (vb7)
216 
217 #pragma acc routine
218 int
func3(int a)219 func3 (int a)
220 {
221   vb6 = a + 1;
222   vb7 = vb6 + 1;
223 
224   return vb7;
225 }
226 
227 int vb8;
228 #pragma acc declare create (vb8)
229 extern int vb9;
230 #pragma acc declare create (vb9)
231 static int vb10;
232 #pragma acc declare create (vb10)
233 
234 #pragma acc routine
235 int
func4(int a)236 func4 (int a)
237 {
238   vb8 = a + 1;
239   vb9 = vb8 + 1;
240   vb10 = vb9 + 1;
241 
242   return vb10;
243 }
244 
245 int vb11;
246 #pragma acc declare device_resident (vb11)
247 extern int vb12;
248 #pragma acc declare device_resident (vb12)
249 extern int vb13;
250 #pragma acc declare device_resident (vb13)
251 
252 #pragma acc routine
253 int
func5(int a)254 func5 (int a)
255 {
256   vb11 = a + 1;
257   vb12 = vb11 + 1;
258   vb13 = vb12 + 1;
259 
260   return vb13;
261 }
262 
263 #pragma acc routine
264 int
func6(int a)265 func6 (int a)
266 {
267   extern int vb14;
268 #pragma acc declare create (vb14)
269   static int vb15;
270 #pragma acc declare create (vb15)
271 
272   vb14 = a + 1;
273   vb15 = vb14 + 1;
274 
275   return vb15;
276 }
277