| 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 |
|
| 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 |
|
| 18 |
void PC2() |
| 19 |
{ |
| 20 |
if (0) |
| 21 |
#pragma acc routine /* { dg-error ".#pragma acc routine. must be at file scope" } */ |
| 22 |
; |
| 23 |
} |
| 24 |
|
| 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 |
/* PR c++/101731 */ |
| 98 |
/* Regarding the current C/C++ difference, see |
| 99 |
<http://mid.mail-archive.com/20211122150231.GP2646553@tucnak>. */ |
| 100 |
#pragma acc routine /* { dg-error "not immediately followed by a single function declaration or definition" "" { target c++ } } */ |
| 101 |
int pr101731_foo (int pr101731_bar ()); |
| 102 |
#pragma acc routine (pr101731_foo) vector /* { dg-error "has already been marked with an OpenACC 'routine' directive" "" { target c } } */ |
| 103 |
#pragma acc routine (pr101731_bar) vector /* { dg-error "'pr101731_bar' has not been declared" } */ |
| 104 |
|
| 105 |
#pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */ |
| 106 |
#pragma acc routine |
| 107 |
int fn4 (void); |
| 108 |
|
| 109 |
int fn5a (void); |
| 110 |
int fn5b (void); |
| 111 |
#pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */ |
| 112 |
#pragma acc routine (fn5a) |
| 113 |
#pragma acc routine (fn5b) |
| 114 |
int fn5 (void); |
| 115 |
|
| 116 |
#pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */ |
| 117 |
#pragma acc routine (fn6a) /* { dg-error ".fn6a. has not been declared" } */ |
| 118 |
#pragma acc routine (fn6b) /* { dg-error ".fn6b. has not been declared" } */ |
| 119 |
int fn6 (void); |
| 120 |
|
| 121 |
#ifdef __cplusplus |
| 122 |
|
| 123 |
#pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" "" { target c++ } } */ |
| 124 |
namespace f {} |
| 125 |
|
| 126 |
namespace g {} |
| 127 |
|
| 128 |
#pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" "" { target c++ } } */ |
| 129 |
using namespace g; |
| 130 |
|
| 131 |
#pragma acc routine (g) /* { dg-error ".g. does not refer to a function" "" { target c++ } } */ |
| 132 |
|
| 133 |
#endif /* __cplusplus */ |
| 134 |
|
| 135 |
#pragma acc routine (a) /* { dg-error ".a. does not refer to a function" } */ |
| 136 |
|
| 137 |
#pragma acc routine (c) /* { dg-error ".c. does not refer to a function" } */ |
| 138 |
|
| 139 |
|
| 140 |
/* Static assert. */ |
| 141 |
|
| 142 |
#pragma acc routine /* { dg-bogus ".#pragma acc routine. not immediately followed by function declaration or definition" "TODO" { xfail *-*-* } } */ |
| 143 |
#ifndef __cplusplus /* C */ |
| 144 |
_Static_assert(0, ""); /* { dg-error "static assertion failed" "" { target c } } */ |
| 145 |
#elif __cplusplus < 201103L /* C++98 */ |
| 146 |
/* C++98 doesn't support static_assert, so fake an error in combination, and as |
| 147 |
expected with the "#pragma acc routine" above. */ |
| 148 |
int dummy_instead_of_static_assert; |
| 149 |
#else /* C++ */ |
| 150 |
static_assert(0, ""); /* { dg-error "static assertion failed" "" { target c++11 } } */ |
| 151 |
#endif |
| 152 |
void f_static_assert(); |
| 153 |
/* Check that we already recognized "f_static_assert" as an OpenACC routine. */ |
| 154 |
#pragma acc routine (f_static_assert) /* { dg-error ".#pragma acc routine. already applied to .\[void \]*f_static_assert" "TODO" { xfail *-*-* } } */ |
| 155 |
|
| 156 |
|
| 157 |
/* __extension__ usage. */ |
| 158 |
|
| 159 |
#pragma acc routine |
| 160 |
__extension__ extern void ex1(); |
| 161 |
#pragma acc routine (ex1) worker /* { dg-error "has already been marked with an OpenACC 'routine' directive" } */ |
| 162 |
|
| 163 |
#pragma acc routine |
| 164 |
__extension__ __extension__ __extension__ __extension__ __extension__ void ex2() |
| 165 |
{ |
| 166 |
} |
| 167 |
#pragma acc routine (ex2) worker /* { dg-error "has already been marked with an OpenACC 'routine' directive" } */ |
| 168 |
|
| 169 |
#pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */ |
| 170 |
__extension__ int ex3; |
| 171 |
#pragma acc routine (ex3) /* { dg-error ".ex3. does not refer to a function" } */ |
| 172 |
|
| 173 |
|
| 174 |
/* "#pragma acc routine" must be applied before. */ |
| 175 |
|
| 176 |
void Bar (); |
| 177 |
|
| 178 |
void Foo () |
| 179 |
{ |
| 180 |
Bar (); |
| 181 |
} |
| 182 |
|
| 183 |
#pragma acc routine (Bar) // { dg-error ".#pragma acc routine. must be applied before use" } |
| 184 |
|
| 185 |
#pragma acc routine (Foo) gang // { dg-error ".#pragma acc routine. must be applied before definition" } |
| 186 |
|
| 187 |
#pragma acc routine (Baz) // { dg-error "not been declared" } |
| 188 |
|
| 189 |
|
| 190 |
/* OpenACC declare. */ |
| 191 |
|
| 192 |
int vb1; /* { dg-error "directive for use" } */ |
| 193 |
extern int vb2; /* { dg-error "directive for use" } */ |
| 194 |
static int vb3; /* { dg-error "directive for use" } */ |
| 195 |
|
| 196 |
#pragma acc routine |
| 197 |
int |
| 198 |
func1 (int a) |
| 199 |
{ |
| 200 |
vb1 = a + 1; |
| 201 |
vb2 = vb1 + 1; |
| 202 |
vb3 = vb2 + 1; |
| 203 |
|
| 204 |
return vb3; |
| 205 |
} |
| 206 |
|
| 207 |
#pragma acc routine |
| 208 |
int |
| 209 |
func2 (int a) |
| 210 |
{ |
| 211 |
extern int vb4; /* { dg-error "directive for use" } */ |
| 212 |
static int vb5; |
| 213 |
|
| 214 |
vb4 = a + 1; |
| 215 |
vb5 = vb4 + 1; |
| 216 |
|
| 217 |
return vb5; |
| 218 |
} |
| 219 |
|
| 220 |
extern int vb6; /* { dg-error "clause used in" } */ |
| 221 |
#pragma acc declare link (vb6) |
| 222 |
static int vb7; /* { dg-error "clause used in" } */ |
| 223 |
#pragma acc declare link (vb7) |
| 224 |
|
| 225 |
#pragma acc routine |
| 226 |
int |
| 227 |
func3 (int a) |
| 228 |
{ |
| 229 |
vb6 = a + 1; |
| 230 |
vb7 = vb6 + 1; |
| 231 |
|
| 232 |
return vb7; |
| 233 |
} |
| 234 |
|
| 235 |
int vb8; |
| 236 |
#pragma acc declare create (vb8) |
| 237 |
extern int vb9; |
| 238 |
#pragma acc declare create (vb9) |
| 239 |
static int vb10; |
| 240 |
#pragma acc declare create (vb10) |
| 241 |
|
| 242 |
#pragma acc routine |
| 243 |
int |
| 244 |
func4 (int a) |
| 245 |
{ |
| 246 |
vb8 = a + 1; |
| 247 |
vb9 = vb8 + 1; |
| 248 |
vb10 = vb9 + 1; |
| 249 |
|
| 250 |
return vb10; |
| 251 |
} |
| 252 |
|
| 253 |
int vb11; |
| 254 |
#pragma acc declare device_resident (vb11) |
| 255 |
extern int vb12; |
| 256 |
#pragma acc declare device_resident (vb12) |
| 257 |
extern int vb13; |
| 258 |
#pragma acc declare device_resident (vb13) |
| 259 |
|
| 260 |
#pragma acc routine |
| 261 |
int |
| 262 |
func5 (int a) |
| 263 |
{ |
| 264 |
vb11 = a + 1; |
| 265 |
vb12 = vb11 + 1; |
| 266 |
vb13 = vb12 + 1; |
| 267 |
|
| 268 |
return vb13; |
| 269 |
} |
| 270 |
|
| 271 |
#pragma acc routine |
| 272 |
int |
| 273 |
func6 (int a) |
| 274 |
{ |
| 275 |
extern int vb14; |
| 276 |
#pragma acc declare create (vb14) |
| 277 |
static int vb15; |
| 278 |
#pragma acc declare create (vb15) |
| 279 |
|
| 280 |
vb14 = a + 1; |
| 281 |
vb15 = vb14 + 1; |
| 282 |
|
| 283 |
return vb15; |
| 284 |
} |