| 1 |
/* Parser for C and Objective-C. |
| 2 |
Copyright (C) 1987-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
Parser actions based on the old Bison parser; structure somewhat |
| 5 |
influenced by and fragments based on the C++ parser. |
| 6 |
|
| 7 |
This file is part of GCC. |
| 8 |
|
| 9 |
GCC is free software; you can redistribute it and/or modify it under |
| 10 |
the terms of the GNU General Public License as published by the Free |
| 11 |
Software Foundation; either version 3, or (at your option) any later |
| 12 |
version. |
| 13 |
|
| 14 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 15 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 17 |
for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with GCC; see the file COPYING3. If not see |
| 21 |
<http://www.gnu.org/licenses/>. */ |
| 22 |
|
| 23 |
/* TODO: |
| 24 |
|
| 25 |
Make sure all relevant comments, and all relevant code from all |
| 26 |
actions, brought over from old parser. Verify exact correspondence |
| 27 |
of syntax accepted. |
| 28 |
|
| 29 |
Add testcases covering every input symbol in every state in old and |
| 30 |
new parsers. |
| 31 |
|
| 32 |
Include full syntax for GNU C, including erroneous cases accepted |
| 33 |
with error messages, in syntax productions in comments. |
| 34 |
|
| 35 |
Make more diagnostics in the front end generally take an explicit |
| 36 |
location rather than implicitly using input_location. */ |
| 37 |
|
| 38 |
#include "config.h" |
| 39 |
#define INCLUDE_STRING |
| 40 |
#include "system.h" |
| 41 |
#include "coretypes.h" |
| 42 |
#include "target.h" |
| 43 |
#include "function.h" |
| 44 |
#include "c-tree.h" |
| 45 |
#include "timevar.h" |
| 46 |
#include "stringpool.h" |
| 47 |
#include "cgraph.h" |
| 48 |
#include "attribs.h" |
| 49 |
#include "stor-layout.h" |
| 50 |
#include "varasm.h" |
| 51 |
#include "trans-mem.h" |
| 52 |
#include "c-family/c-pragma.h" |
| 53 |
#include "c-lang.h" |
| 54 |
#include "c-family/c-objc.h" |
| 55 |
#include "plugin.h" |
| 56 |
#include "omp-general.h" |
| 57 |
#include "omp-offload.h" |
| 58 |
#include "builtins.h" |
| 59 |
#include "gomp-constants.h" |
| 60 |
#include "c-family/c-indentation.h" |
| 61 |
#include "gimple-expr.h" |
| 62 |
#include "context.h" |
| 63 |
#include "gcc-rich-location.h" |
| 64 |
#include "c-parser.h" |
| 65 |
#include "gimple-parser.h" |
| 66 |
#include "read-rtl-function.h" |
| 67 |
#include "run-rtl-passes.h" |
| 68 |
#include "intl.h" |
| 69 |
#include "c-family/name-hint.h" |
| 70 |
#include "tree-iterator.h" |
| 71 |
#include "tree-pretty-print.h" |
| 72 |
#include "memmodel.h" |
| 73 |
#include "c-family/known-headers.h" |
| 74 |
#include "bitmap.h" |
| 75 |
#include "analyzer/analyzer-language.h" |
| 76 |
#include "toplev.h" |
| 77 |
#include "asan.h" |
| 78 |
#include "c-family/c-ubsan.h" |
| 79 |
#include "gcc-urlifier.h" |
| 80 |
|
| 81 |
/* We need to walk over decls with incomplete struct/union/enum types |
| 82 |
after parsing the whole translation unit. |
| 83 |
In finish_decl(), if the decl is static, has incomplete |
| 84 |
struct/union/enum type, it is appended to incomplete_record_decls. |
| 85 |
In c_parser_translation_unit(), we iterate over incomplete_record_decls |
| 86 |
and report error if any of the decls are still incomplete. */ |
| 87 |
|
| 88 |
vec<tree> incomplete_record_decls; |
| 89 |
|
| 90 |
void |
| 91 |
set_c_expr_source_range (c_expr *expr, |
| 92 |
location_t start, location_t finish) |
| 93 |
{ |
| 94 |
expr->src_range.m_start = start; |
| 95 |
expr->src_range.m_finish = finish; |
| 96 |
if (expr->value) |
| 97 |
set_source_range (expr->value, start, finish); |
| 98 |
} |
| 99 |
|
| 100 |
void |
| 101 |
set_c_expr_source_range (c_expr *expr, |
| 102 |
source_range src_range) |
| 103 |
{ |
| 104 |
expr->src_range = src_range; |
| 105 |
if (expr->value) |
| 106 |
set_source_range (expr->value, src_range); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
/* Initialization routine for this file. */ |
| 111 |
|
| 112 |
void |
| 113 |
c_parse_init (void) |
| 114 |
{ |
| 115 |
/* The only initialization required is of the reserved word |
| 116 |
identifiers. */ |
| 117 |
unsigned int i; |
| 118 |
tree id; |
| 119 |
int mask = 0; |
| 120 |
|
| 121 |
/* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in |
| 122 |
the c_token structure. */ |
| 123 |
gcc_assert (RID_MAX <= 255); |
| 124 |
|
| 125 |
mask |= D_CXXONLY; |
| 126 |
if (!flag_isoc99) |
| 127 |
mask |= D_C99; |
| 128 |
if (!flag_isoc23) |
| 129 |
mask |= D_C23; |
| 130 |
if (flag_no_asm) |
| 131 |
{ |
| 132 |
mask |= D_ASM | D_EXT; |
| 133 |
if (!flag_isoc99) |
| 134 |
mask |= D_EXT89; |
| 135 |
if (!flag_isoc23) |
| 136 |
mask |= D_EXT11; |
| 137 |
} |
| 138 |
if (!c_dialect_objc ()) |
| 139 |
mask |= D_OBJC | D_CXX_OBJC; |
| 140 |
|
| 141 |
ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX); |
| 142 |
for (i = 0; i < num_c_common_reswords; i++) |
| 143 |
{ |
| 144 |
/* If a keyword is disabled, do not enter it into the table |
| 145 |
and so create a canonical spelling that isn't a keyword. */ |
| 146 |
if (c_common_reswords[i].disable & mask) |
| 147 |
{ |
| 148 |
if (warn_cxx_compat |
| 149 |
&& (c_common_reswords[i].disable & D_CXXWARN)) |
| 150 |
{ |
| 151 |
id = get_identifier (c_common_reswords[i].word); |
| 152 |
C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); |
| 153 |
C_IS_RESERVED_WORD (id) = 1; |
| 154 |
} |
| 155 |
continue; |
| 156 |
} |
| 157 |
|
| 158 |
id = get_identifier (c_common_reswords[i].word); |
| 159 |
C_SET_RID_CODE (id, c_common_reswords[i].rid); |
| 160 |
C_IS_RESERVED_WORD (id) = 1; |
| 161 |
ridpointers [(int) c_common_reswords[i].rid] = id; |
| 162 |
} |
| 163 |
|
| 164 |
for (i = 0; i < NUM_INT_N_ENTS; i++) |
| 165 |
{ |
| 166 |
/* We always create the symbols but they aren't always supported. */ |
| 167 |
char name[50]; |
| 168 |
sprintf (name, "__int%d", int_n_data[i].bitsize); |
| 169 |
id = get_identifier (name); |
| 170 |
C_SET_RID_CODE (id, RID_FIRST_INT_N + i); |
| 171 |
C_IS_RESERVED_WORD (id) = 1; |
| 172 |
|
| 173 |
sprintf (name, "__int%d__", int_n_data[i].bitsize); |
| 174 |
id = get_identifier (name); |
| 175 |
C_SET_RID_CODE (id, RID_FIRST_INT_N + i); |
| 176 |
C_IS_RESERVED_WORD (id) = 1; |
| 177 |
} |
| 178 |
|
| 179 |
if (flag_openmp) |
| 180 |
{ |
| 181 |
id = get_identifier ("omp_all_memory"); |
| 182 |
C_SET_RID_CODE (id, RID_OMP_ALL_MEMORY); |
| 183 |
C_IS_RESERVED_WORD (id) = 1; |
| 184 |
ridpointers [RID_OMP_ALL_MEMORY] = id; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/* A parser structure recording information about the state and |
| 189 |
context of parsing. Includes lexer information with up to two |
| 190 |
tokens of look-ahead; more are not needed for C. */ |
| 191 |
struct GTY(()) c_parser { |
| 192 |
/* The look-ahead tokens. */ |
| 193 |
c_token * GTY((skip)) tokens; |
| 194 |
/* Buffer for look-ahead tokens. */ |
| 195 |
c_token tokens_buf[4]; |
| 196 |
/* How many look-ahead tokens are available (0 - 4, or |
| 197 |
more if parsing from pre-lexed tokens). */ |
| 198 |
unsigned int tokens_avail; |
| 199 |
/* Raw look-ahead tokens, used only for checking in Objective-C |
| 200 |
whether '[[' starts attributes. */ |
| 201 |
vec<c_token, va_gc> *raw_tokens; |
| 202 |
/* The number of raw look-ahead tokens that have since been fully |
| 203 |
lexed. */ |
| 204 |
unsigned int raw_tokens_used; |
| 205 |
/* True if a syntax error is being recovered from; false otherwise. |
| 206 |
c_parser_error sets this flag. It should clear this flag when |
| 207 |
enough tokens have been consumed to recover from the error. */ |
| 208 |
BOOL_BITFIELD error : 1; |
| 209 |
/* True if we're processing a pragma, and shouldn't automatically |
| 210 |
consume CPP_PRAGMA_EOL. */ |
| 211 |
BOOL_BITFIELD in_pragma : 1; |
| 212 |
/* True if we're parsing the outermost block of an if statement. */ |
| 213 |
BOOL_BITFIELD in_if_block : 1; |
| 214 |
/* True if we want to lex a translated, joined string (for an |
| 215 |
initial #pragma pch_preprocess). Otherwise the parser is |
| 216 |
responsible for concatenating strings and translating to the |
| 217 |
execution character set as needed. */ |
| 218 |
BOOL_BITFIELD lex_joined_string : 1; |
| 219 |
/* True if, when the parser is concatenating string literals, it |
| 220 |
should translate them to the execution character set (false |
| 221 |
inside attributes). */ |
| 222 |
BOOL_BITFIELD translate_strings_p : 1; |
| 223 |
|
| 224 |
/* Objective-C specific parser/lexer information. */ |
| 225 |
|
| 226 |
/* True if we are in a context where the Objective-C "PQ" keywords |
| 227 |
are considered keywords. */ |
| 228 |
BOOL_BITFIELD objc_pq_context : 1; |
| 229 |
/* True if we are parsing a (potential) Objective-C foreach |
| 230 |
statement. This is set to true after we parsed 'for (' and while |
| 231 |
we wait for 'in' or ';' to decide if it's a standard C for loop or an |
| 232 |
Objective-C foreach loop. */ |
| 233 |
BOOL_BITFIELD objc_could_be_foreach_context : 1; |
| 234 |
/* The following flag is needed to contextualize Objective-C lexical |
| 235 |
analysis. In some cases (e.g., 'int NSObject;'), it is |
| 236 |
undesirable to bind an identifier to an Objective-C class, even |
| 237 |
if a class with that name exists. */ |
| 238 |
BOOL_BITFIELD objc_need_raw_identifier : 1; |
| 239 |
/* Nonzero if we're processing a __transaction statement. The value |
| 240 |
is 1 | TM_STMT_ATTR_*. */ |
| 241 |
unsigned int in_transaction : 4; |
| 242 |
/* True if we are in a context where the Objective-C "Property attribute" |
| 243 |
keywords are valid. */ |
| 244 |
BOOL_BITFIELD objc_property_attr_context : 1; |
| 245 |
|
| 246 |
/* Whether we have just seen/constructed a string-literal. Set when |
| 247 |
returning a string-literal from c_parser_string_literal. Reset |
| 248 |
in consume_token. Useful when we get a parse error and see an |
| 249 |
unknown token, which could have been a string-literal constant |
| 250 |
macro. */ |
| 251 |
BOOL_BITFIELD seen_string_literal : 1; |
| 252 |
|
| 253 |
/* TRUE if omp::directive, omp::decl or omp::sequence attributes may not |
| 254 |
appear. */ |
| 255 |
BOOL_BITFIELD omp_attrs_forbidden_p : 1; |
| 256 |
|
| 257 |
/* Location of the last consumed token. */ |
| 258 |
location_t last_token_location; |
| 259 |
|
| 260 |
/* Holds state for parsing collapsed OMP_FOR loops. Managed by |
| 261 |
c_parser_omp_for_loop. */ |
| 262 |
struct omp_for_parse_data * GTY((skip)) omp_for_parse_state; |
| 263 |
|
| 264 |
/* If we're in the context of OpenMP directives written as C23 |
| 265 |
attributes turned into pragma, the tokens field is temporarily |
| 266 |
redirected. This holds data needed to restore state afterwards. |
| 267 |
It's NULL otherwise. */ |
| 268 |
struct omp_attribute_pragma_state *in_omp_attribute_pragma; |
| 269 |
|
| 270 |
/* Set for omp::decl attribute parsing to the decl to which it |
| 271 |
appertains. */ |
| 272 |
tree in_omp_decl_attribute; |
| 273 |
|
| 274 |
/* Non-null only when parsing the body of an OpenMP metadirective. |
| 275 |
Managed by c_parser_omp_metadirective. */ |
| 276 |
struct omp_metadirective_parse_data * GTY((skip)) |
| 277 |
omp_metadirective_state; |
| 278 |
}; |
| 279 |
|
| 280 |
/* Holds data needed to restore the token stream to its previous state |
| 281 |
after parsing an OpenMP attribute-syntax pragma. */ |
| 282 |
struct GTY(()) omp_attribute_pragma_state |
| 283 |
{ |
| 284 |
vec<c_token, va_gc> *token_vec; |
| 285 |
c_token * GTY((skip)) save_tokens; |
| 286 |
unsigned int save_tokens_avail; |
| 287 |
}; |
| 288 |
|
| 289 |
/* Return a pointer to the Nth token in PARSERs tokens_buf. */ |
| 290 |
|
| 291 |
c_token * |
| 292 |
c_parser_tokens_buf (c_parser *parser, unsigned n) |
| 293 |
{ |
| 294 |
return &parser->tokens_buf[n]; |
| 295 |
} |
| 296 |
|
| 297 |
/* Return the error state of PARSER. */ |
| 298 |
|
| 299 |
bool |
| 300 |
c_parser_error (c_parser *parser) |
| 301 |
{ |
| 302 |
return parser->error; |
| 303 |
} |
| 304 |
|
| 305 |
/* Set the error state of PARSER to ERR. */ |
| 306 |
|
| 307 |
void |
| 308 |
c_parser_set_error (c_parser *parser, bool err) |
| 309 |
{ |
| 310 |
parser->error = err; |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
/* The actual parser and external interface. ??? Does this need to be |
| 315 |
garbage-collected? */ |
| 316 |
|
| 317 |
static GTY (()) c_parser *the_parser; |
| 318 |
|
| 319 |
/* Read in and lex a single token, storing it in *TOKEN. If RAW, |
| 320 |
context-sensitive postprocessing of the token is not done. */ |
| 321 |
|
| 322 |
static void |
| 323 |
c_lex_one_token (c_parser *parser, c_token *token, bool raw = false) |
| 324 |
{ |
| 325 |
timevar_push (TV_LEX); |
| 326 |
|
| 327 |
if (raw || vec_safe_length (parser->raw_tokens) == 0) |
| 328 |
{ |
| 329 |
token->type = c_lex_with_flags (&token->value, &token->location, |
| 330 |
&token->flags, |
| 331 |
(parser->lex_joined_string |
| 332 |
? 0 : C_LEX_STRING_NO_JOIN)); |
| 333 |
token->id_kind = C_ID_NONE; |
| 334 |
token->keyword = RID_MAX; |
| 335 |
token->pragma_kind = PRAGMA_NONE; |
| 336 |
} |
| 337 |
else |
| 338 |
{ |
| 339 |
/* Use a token previously lexed as a raw look-ahead token, and |
| 340 |
complete the processing on it. */ |
| 341 |
*token = (*parser->raw_tokens)[parser->raw_tokens_used]; |
| 342 |
++parser->raw_tokens_used; |
| 343 |
if (parser->raw_tokens_used == vec_safe_length (parser->raw_tokens)) |
| 344 |
{ |
| 345 |
vec_free (parser->raw_tokens); |
| 346 |
parser->raw_tokens_used = 0; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
if (raw) |
| 351 |
goto out; |
| 352 |
|
| 353 |
switch (token->type) |
| 354 |
{ |
| 355 |
case CPP_NAME: |
| 356 |
{ |
| 357 |
tree decl; |
| 358 |
|
| 359 |
bool objc_force_identifier = parser->objc_need_raw_identifier; |
| 360 |
if (c_dialect_objc ()) |
| 361 |
parser->objc_need_raw_identifier = false; |
| 362 |
|
| 363 |
if (C_IS_RESERVED_WORD (token->value)) |
| 364 |
{ |
| 365 |
enum rid rid_code = C_RID_CODE (token->value); |
| 366 |
|
| 367 |
if (rid_code == RID_CXX_COMPAT_WARN) |
| 368 |
{ |
| 369 |
warning_at (token->location, |
| 370 |
OPT_Wc___compat, |
| 371 |
"identifier %qE conflicts with C++ keyword", |
| 372 |
token->value); |
| 373 |
} |
| 374 |
else if (rid_code >= RID_FIRST_ADDR_SPACE |
| 375 |
&& rid_code <= RID_LAST_ADDR_SPACE) |
| 376 |
{ |
| 377 |
addr_space_t as; |
| 378 |
as = (addr_space_t) (rid_code - RID_FIRST_ADDR_SPACE); |
| 379 |
targetm.addr_space.diagnose_usage (as, token->location); |
| 380 |
token->id_kind = C_ID_ADDRSPACE; |
| 381 |
token->keyword = rid_code; |
| 382 |
break; |
| 383 |
} |
| 384 |
else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code)) |
| 385 |
{ |
| 386 |
/* We found an Objective-C "pq" keyword (in, out, |
| 387 |
inout, bycopy, byref, oneway). They need special |
| 388 |
care because the interpretation depends on the |
| 389 |
context. */ |
| 390 |
if (parser->objc_pq_context) |
| 391 |
{ |
| 392 |
token->type = CPP_KEYWORD; |
| 393 |
token->keyword = rid_code; |
| 394 |
break; |
| 395 |
} |
| 396 |
else if (parser->objc_could_be_foreach_context |
| 397 |
&& rid_code == RID_IN) |
| 398 |
{ |
| 399 |
/* We are in Objective-C, inside a (potential) |
| 400 |
foreach context (which means after having |
| 401 |
parsed 'for (', but before having parsed ';'), |
| 402 |
and we found 'in'. We consider it the keyword |
| 403 |
which terminates the declaration at the |
| 404 |
beginning of a foreach-statement. Note that |
| 405 |
this means you can't use 'in' for anything else |
| 406 |
in that context; in particular, in Objective-C |
| 407 |
you can't use 'in' as the name of the running |
| 408 |
variable in a C for loop. We could potentially |
| 409 |
try to add code here to disambiguate, but it |
| 410 |
seems a reasonable limitation. */ |
| 411 |
token->type = CPP_KEYWORD; |
| 412 |
token->keyword = rid_code; |
| 413 |
break; |
| 414 |
} |
| 415 |
/* Else, "pq" keywords outside of the "pq" context are |
| 416 |
not keywords, and we fall through to the code for |
| 417 |
normal tokens. */ |
| 418 |
} |
| 419 |
else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code)) |
| 420 |
{ |
| 421 |
/* We found an Objective-C "property attribute" |
| 422 |
keyword (getter, setter, readonly, etc). These are |
| 423 |
only valid in the property context. */ |
| 424 |
if (parser->objc_property_attr_context) |
| 425 |
{ |
| 426 |
token->type = CPP_KEYWORD; |
| 427 |
token->keyword = rid_code; |
| 428 |
break; |
| 429 |
} |
| 430 |
/* Else they are not special keywords. |
| 431 |
*/ |
| 432 |
} |
| 433 |
else if (c_dialect_objc () |
| 434 |
&& (OBJC_IS_AT_KEYWORD (rid_code) |
| 435 |
|| OBJC_IS_CXX_KEYWORD (rid_code))) |
| 436 |
{ |
| 437 |
/* We found one of the Objective-C "@" keywords (defs, |
| 438 |
selector, synchronized, etc) or one of the |
| 439 |
Objective-C "cxx" keywords (class, private, |
| 440 |
protected, public, try, catch, throw) without a |
| 441 |
preceding '@' sign. Do nothing and fall through to |
| 442 |
the code for normal tokens (in C++ we would still |
| 443 |
consider the CXX ones keywords, but not in C). */ |
| 444 |
; |
| 445 |
} |
| 446 |
else |
| 447 |
{ |
| 448 |
token->type = CPP_KEYWORD; |
| 449 |
token->keyword = rid_code; |
| 450 |
break; |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
decl = lookup_name (token->value); |
| 455 |
if (decl) |
| 456 |
{ |
| 457 |
if (TREE_CODE (decl) == TYPE_DECL) |
| 458 |
{ |
| 459 |
token->id_kind = C_ID_TYPENAME; |
| 460 |
break; |
| 461 |
} |
| 462 |
} |
| 463 |
else if (c_dialect_objc ()) |
| 464 |
{ |
| 465 |
tree objc_interface_decl = objc_is_class_name (token->value); |
| 466 |
/* Objective-C class names are in the same namespace as |
| 467 |
variables and typedefs, and hence are shadowed by local |
| 468 |
declarations. */ |
| 469 |
if (objc_interface_decl |
| 470 |
&& (!objc_force_identifier || global_bindings_p ())) |
| 471 |
{ |
| 472 |
token->value = objc_interface_decl; |
| 473 |
token->id_kind = C_ID_CLASSNAME; |
| 474 |
break; |
| 475 |
} |
| 476 |
} |
| 477 |
token->id_kind = C_ID_ID; |
| 478 |
} |
| 479 |
break; |
| 480 |
case CPP_AT_NAME: |
| 481 |
/* This only happens in Objective-C; it must be a keyword. */ |
| 482 |
token->type = CPP_KEYWORD; |
| 483 |
switch (C_RID_CODE (token->value)) |
| 484 |
{ |
| 485 |
/* Replace 'class' with '@class', 'private' with '@private', |
| 486 |
etc. This prevents confusion with the C++ keyword |
| 487 |
'class', and makes the tokens consistent with other |
| 488 |
Objective-C 'AT' keywords. For example '@class' is |
| 489 |
reported as RID_AT_CLASS which is consistent with |
| 490 |
'@synchronized', which is reported as |
| 491 |
RID_AT_SYNCHRONIZED. |
| 492 |
*/ |
| 493 |
case RID_CLASS: token->keyword = RID_AT_CLASS; break; |
| 494 |
case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; |
| 495 |
case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; |
| 496 |
case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; |
| 497 |
case RID_THROW: token->keyword = RID_AT_THROW; break; |
| 498 |
case RID_TRY: token->keyword = RID_AT_TRY; break; |
| 499 |
case RID_CATCH: token->keyword = RID_AT_CATCH; break; |
| 500 |
case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break; |
| 501 |
default: token->keyword = C_RID_CODE (token->value); |
| 502 |
} |
| 503 |
break; |
| 504 |
case CPP_COLON: |
| 505 |
case CPP_COMMA: |
| 506 |
case CPP_CLOSE_PAREN: |
| 507 |
case CPP_SEMICOLON: |
| 508 |
/* These tokens may affect the interpretation of any identifiers |
| 509 |
following, if doing Objective-C. */ |
| 510 |
if (c_dialect_objc ()) |
| 511 |
parser->objc_need_raw_identifier = false; |
| 512 |
break; |
| 513 |
case CPP_PRAGMA: |
| 514 |
/* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ |
| 515 |
token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); |
| 516 |
token->value = NULL; |
| 517 |
break; |
| 518 |
default: |
| 519 |
break; |
| 520 |
} |
| 521 |
out: |
| 522 |
timevar_pop (TV_LEX); |
| 523 |
} |
| 524 |
|
| 525 |
/* Return a pointer to the next token from PARSER, reading it in if |
| 526 |
necessary. */ |
| 527 |
|
| 528 |
c_token * |
| 529 |
c_parser_peek_token (c_parser *parser) |
| 530 |
{ |
| 531 |
if (parser->tokens_avail == 0) |
| 532 |
{ |
| 533 |
c_lex_one_token (parser, &parser->tokens[0]); |
| 534 |
parser->tokens_avail = 1; |
| 535 |
} |
| 536 |
return &parser->tokens[0]; |
| 537 |
} |
| 538 |
|
| 539 |
/* Return a pointer to the next-but-one token from PARSER, reading it |
| 540 |
in if necessary. The next token is already read in. */ |
| 541 |
|
| 542 |
c_token * |
| 543 |
c_parser_peek_2nd_token (c_parser *parser) |
| 544 |
{ |
| 545 |
if (parser->tokens_avail >= 2) |
| 546 |
return &parser->tokens[1]; |
| 547 |
gcc_assert (parser->tokens_avail == 1); |
| 548 |
gcc_assert (parser->tokens[0].type != CPP_EOF); |
| 549 |
gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); |
| 550 |
c_lex_one_token (parser, &parser->tokens[1]); |
| 551 |
parser->tokens_avail = 2; |
| 552 |
return &parser->tokens[1]; |
| 553 |
} |
| 554 |
|
| 555 |
/* Return a pointer to the Nth token from PARSER, reading it |
| 556 |
in if necessary. The N-1th token is already read in. */ |
| 557 |
|
| 558 |
c_token * |
| 559 |
c_parser_peek_nth_token (c_parser *parser, unsigned int n) |
| 560 |
{ |
| 561 |
/* N is 1-based, not zero-based. */ |
| 562 |
gcc_assert (n > 0); |
| 563 |
|
| 564 |
if (parser->tokens_avail >= n) |
| 565 |
return &parser->tokens[n - 1]; |
| 566 |
gcc_assert (parser->tokens_avail == n - 1); |
| 567 |
c_lex_one_token (parser, &parser->tokens[n - 1]); |
| 568 |
parser->tokens_avail = n; |
| 569 |
return &parser->tokens[n - 1]; |
| 570 |
} |
| 571 |
|
| 572 |
/* Return a pointer to the Nth token from PARSER, reading it in as a |
| 573 |
raw look-ahead token if necessary. The N-1th token is already read |
| 574 |
in. Raw look-ahead tokens remain available for when the non-raw |
| 575 |
functions above are called. */ |
| 576 |
|
| 577 |
c_token * |
| 578 |
c_parser_peek_nth_token_raw (c_parser *parser, unsigned int n) |
| 579 |
{ |
| 580 |
/* N is 1-based, not zero-based. */ |
| 581 |
gcc_assert (n > 0); |
| 582 |
|
| 583 |
if (parser->tokens_avail >= n) |
| 584 |
return &parser->tokens[n - 1]; |
| 585 |
unsigned int raw_len = vec_safe_length (parser->raw_tokens); |
| 586 |
unsigned int raw_avail |
| 587 |
= parser->tokens_avail + raw_len - parser->raw_tokens_used; |
| 588 |
gcc_assert (raw_avail >= n - 1); |
| 589 |
if (raw_avail >= n) |
| 590 |
return &(*parser->raw_tokens)[parser->raw_tokens_used |
| 591 |
+ n - 1 - parser->tokens_avail]; |
| 592 |
vec_safe_reserve (parser->raw_tokens, 1); |
| 593 |
parser->raw_tokens->quick_grow (raw_len + 1); |
| 594 |
c_lex_one_token (parser, &(*parser->raw_tokens)[raw_len], true); |
| 595 |
return &(*parser->raw_tokens)[raw_len]; |
| 596 |
} |
| 597 |
|
| 598 |
bool |
| 599 |
c_keyword_starts_typename (enum rid keyword) |
| 600 |
{ |
| 601 |
switch (keyword) |
| 602 |
{ |
| 603 |
case RID_UNSIGNED: |
| 604 |
case RID_LONG: |
| 605 |
case RID_SHORT: |
| 606 |
case RID_SIGNED: |
| 607 |
case RID_COMPLEX: |
| 608 |
case RID_INT: |
| 609 |
case RID_CHAR: |
| 610 |
case RID_FLOAT: |
| 611 |
case RID_DOUBLE: |
| 612 |
case RID_VOID: |
| 613 |
case RID_DFLOAT32: |
| 614 |
case RID_DFLOAT64: |
| 615 |
case RID_DFLOAT128: |
| 616 |
case RID_DFLOAT64X: |
| 617 |
CASE_RID_FLOATN_NX: |
| 618 |
case RID_BOOL: |
| 619 |
case RID_BITINT: |
| 620 |
case RID_ENUM: |
| 621 |
case RID_STRUCT: |
| 622 |
case RID_UNION: |
| 623 |
case RID_TYPEOF: |
| 624 |
case RID_TYPEOF_UNQUAL: |
| 625 |
case RID_CONST: |
| 626 |
case RID_ATOMIC: |
| 627 |
case RID_VOLATILE: |
| 628 |
case RID_RESTRICT: |
| 629 |
case RID_ATTRIBUTE: |
| 630 |
case RID_FRACT: |
| 631 |
case RID_ACCUM: |
| 632 |
case RID_SAT: |
| 633 |
case RID_AUTO_TYPE: |
| 634 |
case RID_ALIGNAS: |
| 635 |
return true; |
| 636 |
default: |
| 637 |
if (keyword >= RID_FIRST_INT_N |
| 638 |
&& keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS |
| 639 |
&& int_n_enabled_p[keyword - RID_FIRST_INT_N]) |
| 640 |
return true; |
| 641 |
return false; |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
/* Return true if TOKEN can start a type name, |
| 646 |
false otherwise. */ |
| 647 |
bool |
| 648 |
c_token_starts_typename (c_token *token) |
| 649 |
{ |
| 650 |
switch (token->type) |
| 651 |
{ |
| 652 |
case CPP_NAME: |
| 653 |
switch (token->id_kind) |
| 654 |
{ |
| 655 |
case C_ID_ID: |
| 656 |
return false; |
| 657 |
case C_ID_ADDRSPACE: |
| 658 |
return true; |
| 659 |
case C_ID_TYPENAME: |
| 660 |
return true; |
| 661 |
case C_ID_CLASSNAME: |
| 662 |
gcc_assert (c_dialect_objc ()); |
| 663 |
return true; |
| 664 |
default: |
| 665 |
gcc_unreachable (); |
| 666 |
} |
| 667 |
case CPP_KEYWORD: |
| 668 |
return c_keyword_starts_typename (token->keyword); |
| 669 |
case CPP_LESS: |
| 670 |
if (c_dialect_objc ()) |
| 671 |
return true; |
| 672 |
return false; |
| 673 |
default: |
| 674 |
return false; |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
/* Return true if the next token from PARSER can start a type name, |
| 679 |
false otherwise. LA specifies how to do lookahead in order to |
| 680 |
detect unknown type names. If unsure, pick CLA_PREFER_ID. */ |
| 681 |
|
| 682 |
static inline bool |
| 683 |
c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la) |
| 684 |
{ |
| 685 |
c_token *token = c_parser_peek_token (parser); |
| 686 |
if (c_token_starts_typename (token)) |
| 687 |
return true; |
| 688 |
|
| 689 |
/* Try a bit harder to detect an unknown typename. */ |
| 690 |
if (la != cla_prefer_id |
| 691 |
&& token->type == CPP_NAME |
| 692 |
&& token->id_kind == C_ID_ID |
| 693 |
|
| 694 |
/* Do not try too hard when we could have "object in array". */ |
| 695 |
&& !parser->objc_could_be_foreach_context |
| 696 |
|
| 697 |
&& (la == cla_prefer_type |
| 698 |
|| c_parser_peek_2nd_token (parser)->type == CPP_NAME |
| 699 |
|| c_parser_peek_2nd_token (parser)->type == CPP_MULT) |
| 700 |
|
| 701 |
/* Only unknown identifiers. */ |
| 702 |
&& !lookup_name (token->value)) |
| 703 |
return true; |
| 704 |
|
| 705 |
return false; |
| 706 |
} |
| 707 |
|
| 708 |
/* Return true if TOKEN, after an open parenthesis, can start a |
| 709 |
compound literal (either a storage class specifier allowed in that |
| 710 |
context, or a type name), false otherwise. */ |
| 711 |
static bool |
| 712 |
c_token_starts_compound_literal (c_token *token) |
| 713 |
{ |
| 714 |
switch (token->type) |
| 715 |
{ |
| 716 |
case CPP_KEYWORD: |
| 717 |
switch (token->keyword) |
| 718 |
{ |
| 719 |
case RID_CONSTEXPR: |
| 720 |
case RID_REGISTER: |
| 721 |
case RID_STATIC: |
| 722 |
case RID_THREAD: |
| 723 |
return true; |
| 724 |
default: |
| 725 |
break; |
| 726 |
} |
| 727 |
/* Fall through. */ |
| 728 |
default: |
| 729 |
return c_token_starts_typename (token); |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
/* Return true if TOKEN is a type qualifier, false otherwise. */ |
| 734 |
static bool |
| 735 |
c_token_is_qualifier (c_token *token) |
| 736 |
{ |
| 737 |
switch (token->type) |
| 738 |
{ |
| 739 |
case CPP_NAME: |
| 740 |
switch (token->id_kind) |
| 741 |
{ |
| 742 |
case C_ID_ADDRSPACE: |
| 743 |
return true; |
| 744 |
default: |
| 745 |
return false; |
| 746 |
} |
| 747 |
case CPP_KEYWORD: |
| 748 |
switch (token->keyword) |
| 749 |
{ |
| 750 |
case RID_CONST: |
| 751 |
case RID_VOLATILE: |
| 752 |
case RID_RESTRICT: |
| 753 |
case RID_ATTRIBUTE: |
| 754 |
case RID_ATOMIC: |
| 755 |
return true; |
| 756 |
default: |
| 757 |
return false; |
| 758 |
} |
| 759 |
case CPP_LESS: |
| 760 |
return false; |
| 761 |
default: |
| 762 |
gcc_unreachable (); |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
/* Return true if the next token from PARSER is a type qualifier, |
| 767 |
false otherwise. */ |
| 768 |
static inline bool |
| 769 |
c_parser_next_token_is_qualifier (c_parser *parser) |
| 770 |
{ |
| 771 |
c_token *token = c_parser_peek_token (parser); |
| 772 |
return c_token_is_qualifier (token); |
| 773 |
} |
| 774 |
|
| 775 |
/* Return true if TOKEN can start declaration specifiers (not |
| 776 |
including standard attributes), false otherwise. */ |
| 777 |
static bool |
| 778 |
c_token_starts_declspecs (c_token *token) |
| 779 |
{ |
| 780 |
switch (token->type) |
| 781 |
{ |
| 782 |
case CPP_NAME: |
| 783 |
switch (token->id_kind) |
| 784 |
{ |
| 785 |
case C_ID_ID: |
| 786 |
return false; |
| 787 |
case C_ID_ADDRSPACE: |
| 788 |
return true; |
| 789 |
case C_ID_TYPENAME: |
| 790 |
return true; |
| 791 |
case C_ID_CLASSNAME: |
| 792 |
gcc_assert (c_dialect_objc ()); |
| 793 |
return true; |
| 794 |
default: |
| 795 |
gcc_unreachable (); |
| 796 |
} |
| 797 |
case CPP_KEYWORD: |
| 798 |
switch (token->keyword) |
| 799 |
{ |
| 800 |
case RID_STATIC: |
| 801 |
case RID_EXTERN: |
| 802 |
case RID_REGISTER: |
| 803 |
case RID_TYPEDEF: |
| 804 |
case RID_INLINE: |
| 805 |
case RID_NORETURN: |
| 806 |
case RID_AUTO: |
| 807 |
case RID_THREAD: |
| 808 |
case RID_UNSIGNED: |
| 809 |
case RID_LONG: |
| 810 |
case RID_SHORT: |
| 811 |
case RID_SIGNED: |
| 812 |
case RID_COMPLEX: |
| 813 |
case RID_INT: |
| 814 |
case RID_CHAR: |
| 815 |
case RID_FLOAT: |
| 816 |
case RID_DOUBLE: |
| 817 |
case RID_VOID: |
| 818 |
case RID_DFLOAT32: |
| 819 |
case RID_DFLOAT64: |
| 820 |
case RID_DFLOAT128: |
| 821 |
case RID_DFLOAT64X: |
| 822 |
CASE_RID_FLOATN_NX: |
| 823 |
case RID_BOOL: |
| 824 |
case RID_BITINT: |
| 825 |
case RID_ENUM: |
| 826 |
case RID_STRUCT: |
| 827 |
case RID_UNION: |
| 828 |
case RID_TYPEOF: |
| 829 |
case RID_TYPEOF_UNQUAL: |
| 830 |
case RID_CONST: |
| 831 |
case RID_VOLATILE: |
| 832 |
case RID_RESTRICT: |
| 833 |
case RID_ATTRIBUTE: |
| 834 |
case RID_FRACT: |
| 835 |
case RID_ACCUM: |
| 836 |
case RID_SAT: |
| 837 |
case RID_ALIGNAS: |
| 838 |
case RID_ATOMIC: |
| 839 |
case RID_AUTO_TYPE: |
| 840 |
case RID_CONSTEXPR: |
| 841 |
return true; |
| 842 |
default: |
| 843 |
if (token->keyword >= RID_FIRST_INT_N |
| 844 |
&& token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS |
| 845 |
&& int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) |
| 846 |
return true; |
| 847 |
return false; |
| 848 |
} |
| 849 |
case CPP_LESS: |
| 850 |
if (c_dialect_objc ()) |
| 851 |
return true; |
| 852 |
return false; |
| 853 |
default: |
| 854 |
return false; |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
/* Return true if TOKEN can start declaration specifiers (not |
| 860 |
including standard attributes) or a static assertion, false |
| 861 |
otherwise. */ |
| 862 |
static bool |
| 863 |
c_token_starts_declaration (c_token *token) |
| 864 |
{ |
| 865 |
if (c_token_starts_declspecs (token) |
| 866 |
|| token->keyword == RID_STATIC_ASSERT) |
| 867 |
return true; |
| 868 |
else |
| 869 |
return false; |
| 870 |
} |
| 871 |
|
| 872 |
/* Return true if the next token from PARSER can start declaration |
| 873 |
specifiers (not including standard attributes), false |
| 874 |
otherwise. */ |
| 875 |
bool |
| 876 |
c_parser_next_token_starts_declspecs (c_parser *parser) |
| 877 |
{ |
| 878 |
c_token *token = c_parser_peek_token (parser); |
| 879 |
|
| 880 |
/* In Objective-C, a classname normally starts a declspecs unless it |
| 881 |
is immediately followed by a dot. In that case, it is the |
| 882 |
Objective-C 2.0 "dot-syntax" for class objects, ie, calls the |
| 883 |
setter/getter on the class. c_token_starts_declspecs() can't |
| 884 |
differentiate between the two cases because it only checks the |
| 885 |
current token, so we have a special check here. */ |
| 886 |
if (c_dialect_objc () |
| 887 |
&& token->type == CPP_NAME |
| 888 |
&& token->id_kind == C_ID_CLASSNAME |
| 889 |
&& c_parser_peek_2nd_token (parser)->type == CPP_DOT) |
| 890 |
return false; |
| 891 |
|
| 892 |
return c_token_starts_declspecs (token); |
| 893 |
} |
| 894 |
|
| 895 |
/* Return true if the next tokens from PARSER can start declaration |
| 896 |
specifiers (not including standard attributes) or a static |
| 897 |
assertion, false otherwise. */ |
| 898 |
bool |
| 899 |
c_parser_next_tokens_start_declaration (c_parser *parser) |
| 900 |
{ |
| 901 |
c_token *token = c_parser_peek_token (parser); |
| 902 |
|
| 903 |
/* Same as above. */ |
| 904 |
if (c_dialect_objc () |
| 905 |
&& token->type == CPP_NAME |
| 906 |
&& token->id_kind == C_ID_CLASSNAME |
| 907 |
&& c_parser_peek_2nd_token (parser)->type == CPP_DOT) |
| 908 |
return false; |
| 909 |
|
| 910 |
/* Labels do not start declarations. */ |
| 911 |
if (token->type == CPP_NAME |
| 912 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 913 |
return false; |
| 914 |
|
| 915 |
if (c_token_starts_declaration (token)) |
| 916 |
return true; |
| 917 |
|
| 918 |
if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl)) |
| 919 |
return true; |
| 920 |
|
| 921 |
return false; |
| 922 |
} |
| 923 |
|
| 924 |
/* Consume the next token from PARSER. */ |
| 925 |
|
| 926 |
void |
| 927 |
c_parser_consume_token (c_parser *parser) |
| 928 |
{ |
| 929 |
gcc_assert (parser->tokens_avail >= 1); |
| 930 |
gcc_assert (parser->tokens[0].type != CPP_EOF); |
| 931 |
gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); |
| 932 |
gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA); |
| 933 |
parser->last_token_location = parser->tokens[0].location; |
| 934 |
if (parser->tokens != &parser->tokens_buf[0]) |
| 935 |
parser->tokens++; |
| 936 |
else if (parser->tokens_avail >= 2) |
| 937 |
{ |
| 938 |
parser->tokens[0] = parser->tokens[1]; |
| 939 |
if (parser->tokens_avail >= 3) |
| 940 |
{ |
| 941 |
parser->tokens[1] = parser->tokens[2]; |
| 942 |
if (parser->tokens_avail >= 4) |
| 943 |
parser->tokens[2] = parser->tokens[3]; |
| 944 |
} |
| 945 |
} |
| 946 |
parser->tokens_avail--; |
| 947 |
parser->seen_string_literal = false; |
| 948 |
} |
| 949 |
|
| 950 |
/* Expect the current token to be a #pragma. Consume it and remember |
| 951 |
that we've begun parsing a pragma. */ |
| 952 |
|
| 953 |
static void |
| 954 |
c_parser_consume_pragma (c_parser *parser) |
| 955 |
{ |
| 956 |
gcc_assert (!parser->in_pragma); |
| 957 |
gcc_assert (parser->tokens_avail >= 1); |
| 958 |
gcc_assert (parser->tokens[0].type == CPP_PRAGMA); |
| 959 |
if (parser->tokens != &parser->tokens_buf[0]) |
| 960 |
parser->tokens++; |
| 961 |
else if (parser->tokens_avail >= 2) |
| 962 |
{ |
| 963 |
parser->tokens[0] = parser->tokens[1]; |
| 964 |
if (parser->tokens_avail >= 3) |
| 965 |
parser->tokens[1] = parser->tokens[2]; |
| 966 |
} |
| 967 |
parser->tokens_avail--; |
| 968 |
parser->in_pragma = true; |
| 969 |
} |
| 970 |
|
| 971 |
/* Update the global input_location from TOKEN. */ |
| 972 |
static inline void |
| 973 |
c_parser_set_source_position_from_token (c_token *token) |
| 974 |
{ |
| 975 |
if (token->type != CPP_EOF) |
| 976 |
{ |
| 977 |
input_location = token->location; |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
/* Helper function for c_parser_error. |
| 982 |
Having peeked a token of kind TOK1_KIND that might signify |
| 983 |
a conflict marker, peek successor tokens to determine |
| 984 |
if we actually do have a conflict marker. |
| 985 |
Specifically, we consider a run of 7 '<', '=' or '>' characters |
| 986 |
at the start of a line as a conflict marker. |
| 987 |
These come through the lexer as three pairs and a single, |
| 988 |
e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<'). |
| 989 |
If it returns true, *OUT_LOC is written to with the location/range |
| 990 |
of the marker. */ |
| 991 |
|
| 992 |
static bool |
| 993 |
c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind, |
| 994 |
location_t *out_loc) |
| 995 |
{ |
| 996 |
c_token *token2 = c_parser_peek_2nd_token (parser); |
| 997 |
if (token2->type != tok1_kind) |
| 998 |
return false; |
| 999 |
c_token *token3 = c_parser_peek_nth_token (parser, 3); |
| 1000 |
if (token3->type != tok1_kind) |
| 1001 |
return false; |
| 1002 |
c_token *token4 = c_parser_peek_nth_token (parser, 4); |
| 1003 |
if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind)) |
| 1004 |
return false; |
| 1005 |
|
| 1006 |
/* It must be at the start of the line. */ |
| 1007 |
location_t start_loc = c_parser_peek_token (parser)->location; |
| 1008 |
if (LOCATION_COLUMN (start_loc) != 1) |
| 1009 |
return false; |
| 1010 |
|
| 1011 |
/* We have a conflict marker. Construct a location of the form: |
| 1012 |
<<<<<<< |
| 1013 |
^~~~~~~ |
| 1014 |
with start == caret, finishing at the end of the marker. */ |
| 1015 |
location_t finish_loc = get_finish (token4->location); |
| 1016 |
*out_loc = make_location (start_loc, start_loc, finish_loc); |
| 1017 |
|
| 1018 |
return true; |
| 1019 |
} |
| 1020 |
|
| 1021 |
/* Issue a diagnostic of the form |
| 1022 |
FILE:LINE: MESSAGE before TOKEN |
| 1023 |
where TOKEN is the next token in the input stream of PARSER. |
| 1024 |
MESSAGE (specified by the caller) is usually of the form "expected |
| 1025 |
OTHER-TOKEN". |
| 1026 |
|
| 1027 |
Use RICHLOC as the location of the diagnostic. |
| 1028 |
|
| 1029 |
Do not issue a diagnostic if still recovering from an error. |
| 1030 |
|
| 1031 |
Return true iff an error was actually emitted. |
| 1032 |
|
| 1033 |
??? This is taken from the C++ parser, but building up messages in |
| 1034 |
this way is not i18n-friendly and some other approach should be |
| 1035 |
used. */ |
| 1036 |
|
| 1037 |
static bool |
| 1038 |
c_parser_error_richloc (c_parser *parser, const char *gmsgid, |
| 1039 |
rich_location *richloc) |
| 1040 |
{ |
| 1041 |
c_token *token = c_parser_peek_token (parser); |
| 1042 |
if (parser->error) |
| 1043 |
return false; |
| 1044 |
parser->error = true; |
| 1045 |
if (!gmsgid) |
| 1046 |
return false; |
| 1047 |
|
| 1048 |
/* If this is actually a conflict marker, report it as such. */ |
| 1049 |
if (token->type == CPP_LSHIFT |
| 1050 |
|| token->type == CPP_RSHIFT |
| 1051 |
|| token->type == CPP_EQ_EQ) |
| 1052 |
{ |
| 1053 |
location_t loc; |
| 1054 |
if (c_parser_peek_conflict_marker (parser, token->type, &loc)) |
| 1055 |
{ |
| 1056 |
error_at (loc, "version control conflict marker in file"); |
| 1057 |
return true; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
/* If we were parsing a string-literal and there is an unknown name |
| 1062 |
token right after, then check to see if that could also have been |
| 1063 |
a literal string by checking the name against a list of known |
| 1064 |
standard string literal constants defined in header files. If |
| 1065 |
there is one, then add that as an hint to the error message. */ |
| 1066 |
auto_diagnostic_group d; |
| 1067 |
name_hint h; |
| 1068 |
if (parser->seen_string_literal && token->type == CPP_NAME) |
| 1069 |
{ |
| 1070 |
tree name = token->value; |
| 1071 |
const char *token_name = IDENTIFIER_POINTER (name); |
| 1072 |
const char *header_hint |
| 1073 |
= get_c_stdlib_header_for_string_macro_name (token_name); |
| 1074 |
if (header_hint != NULL) |
| 1075 |
h = name_hint (NULL, new suggest_missing_header (token->location, |
| 1076 |
token_name, |
| 1077 |
header_hint)); |
| 1078 |
} |
| 1079 |
|
| 1080 |
c_parse_error (gmsgid, |
| 1081 |
/* Because c_parse_error does not understand |
| 1082 |
CPP_KEYWORD, keywords are treated like |
| 1083 |
identifiers. */ |
| 1084 |
(token->type == CPP_KEYWORD ? CPP_NAME : token->type), |
| 1085 |
/* ??? The C parser does not save the cpp flags of a |
| 1086 |
token, we need to pass 0 here and we will not get |
| 1087 |
the source spelling of some tokens but rather the |
| 1088 |
canonical spelling. */ |
| 1089 |
token->value, /*flags=*/0, richloc); |
| 1090 |
return true; |
| 1091 |
} |
| 1092 |
|
| 1093 |
/* As c_parser_error_richloc, but issue the message at the |
| 1094 |
location of PARSER's next token, or at input_location |
| 1095 |
if the next token is EOF. */ |
| 1096 |
|
| 1097 |
bool |
| 1098 |
c_parser_error (c_parser *parser, const char *gmsgid) |
| 1099 |
{ |
| 1100 |
c_token *token = c_parser_peek_token (parser); |
| 1101 |
c_parser_set_source_position_from_token (token); |
| 1102 |
rich_location richloc (line_table, input_location); |
| 1103 |
return c_parser_error_richloc (parser, gmsgid, &richloc); |
| 1104 |
} |
| 1105 |
|
| 1106 |
/* Some tokens naturally come in pairs e.g.'(' and ')'. |
| 1107 |
This class is for tracking such a matching pair of symbols. |
| 1108 |
In particular, it tracks the location of the first token, |
| 1109 |
so that if the second token is missing, we can highlight the |
| 1110 |
location of the first token when notifying the user about the |
| 1111 |
problem. */ |
| 1112 |
|
| 1113 |
template <typename traits_t> |
| 1114 |
class token_pair |
| 1115 |
{ |
| 1116 |
public: |
| 1117 |
/* token_pair's ctor. */ |
| 1118 |
token_pair () : m_open_loc (UNKNOWN_LOCATION) {} |
| 1119 |
|
| 1120 |
/* If the next token is the opening symbol for this pair, consume it and |
| 1121 |
return true. |
| 1122 |
Otherwise, issue an error and return false. |
| 1123 |
In either case, record the location of the opening token. */ |
| 1124 |
|
| 1125 |
bool require_open (c_parser *parser) |
| 1126 |
{ |
| 1127 |
c_token *token = c_parser_peek_token (parser); |
| 1128 |
if (token) |
| 1129 |
m_open_loc = token->location; |
| 1130 |
|
| 1131 |
return c_parser_require (parser, traits_t::open_token_type, |
| 1132 |
traits_t::open_gmsgid); |
| 1133 |
} |
| 1134 |
|
| 1135 |
/* Consume the next token from PARSER, recording its location as |
| 1136 |
that of the opening token within the pair. */ |
| 1137 |
|
| 1138 |
void consume_open (c_parser *parser) |
| 1139 |
{ |
| 1140 |
c_token *token = c_parser_peek_token (parser); |
| 1141 |
gcc_assert (token->type == traits_t::open_token_type); |
| 1142 |
m_open_loc = token->location; |
| 1143 |
c_parser_consume_token (parser); |
| 1144 |
} |
| 1145 |
|
| 1146 |
/* If the next token is the closing symbol for this pair, consume it |
| 1147 |
and return true. |
| 1148 |
Otherwise, issue an error, highlighting the location of the |
| 1149 |
corresponding opening token, and return false. */ |
| 1150 |
|
| 1151 |
bool require_close (c_parser *parser) const |
| 1152 |
{ |
| 1153 |
return c_parser_require (parser, traits_t::close_token_type, |
| 1154 |
traits_t::close_gmsgid, m_open_loc); |
| 1155 |
} |
| 1156 |
|
| 1157 |
/* Like token_pair::require_close, except that tokens will be skipped |
| 1158 |
until the desired token is found. An error message is still produced |
| 1159 |
if the next token is not as expected. */ |
| 1160 |
|
| 1161 |
void skip_until_found_close (c_parser *parser) const |
| 1162 |
{ |
| 1163 |
c_parser_skip_until_found (parser, traits_t::close_token_type, |
| 1164 |
traits_t::close_gmsgid, m_open_loc); |
| 1165 |
} |
| 1166 |
|
| 1167 |
private: |
| 1168 |
location_t m_open_loc; |
| 1169 |
}; |
| 1170 |
|
| 1171 |
/* Traits for token_pair<T> for tracking matching pairs of parentheses. */ |
| 1172 |
|
| 1173 |
struct matching_paren_traits |
| 1174 |
{ |
| 1175 |
static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN; |
| 1176 |
static const char * const open_gmsgid; |
| 1177 |
static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN; |
| 1178 |
static const char * const close_gmsgid; |
| 1179 |
}; |
| 1180 |
|
| 1181 |
const char * const matching_paren_traits::open_gmsgid = "expected %<(%>"; |
| 1182 |
const char * const matching_paren_traits::close_gmsgid = "expected %<)%>"; |
| 1183 |
|
| 1184 |
/* "matching_parens" is a token_pair<T> class for tracking matching |
| 1185 |
pairs of parentheses. */ |
| 1186 |
|
| 1187 |
typedef token_pair<matching_paren_traits> matching_parens; |
| 1188 |
|
| 1189 |
/* Traits for token_pair<T> for tracking matching pairs of braces. */ |
| 1190 |
|
| 1191 |
struct matching_brace_traits |
| 1192 |
{ |
| 1193 |
static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE; |
| 1194 |
static const char * const open_gmsgid; |
| 1195 |
static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE; |
| 1196 |
static const char * const close_gmsgid; |
| 1197 |
}; |
| 1198 |
|
| 1199 |
const char * const matching_brace_traits::open_gmsgid = "expected %<{%>"; |
| 1200 |
const char * const matching_brace_traits::close_gmsgid = "expected %<}%>"; |
| 1201 |
|
| 1202 |
/* "matching_braces" is a token_pair<T> class for tracking matching |
| 1203 |
pairs of braces. */ |
| 1204 |
|
| 1205 |
typedef token_pair<matching_brace_traits> matching_braces; |
| 1206 |
|
| 1207 |
/* Get a description of the matching symbol to TYPE e.g. "(" for |
| 1208 |
CPP_CLOSE_PAREN. */ |
| 1209 |
|
| 1210 |
static const char * |
| 1211 |
get_matching_symbol (enum cpp_ttype type) |
| 1212 |
{ |
| 1213 |
switch (type) |
| 1214 |
{ |
| 1215 |
default: |
| 1216 |
gcc_unreachable (); |
| 1217 |
case CPP_CLOSE_PAREN: |
| 1218 |
return "("; |
| 1219 |
case CPP_CLOSE_BRACE: |
| 1220 |
return "{"; |
| 1221 |
} |
| 1222 |
} |
| 1223 |
|
| 1224 |
/* If the next token is of the indicated TYPE, consume it. Otherwise, |
| 1225 |
issue the error MSGID. If MSGID is NULL then a message has already |
| 1226 |
been produced and no message will be produced this time. Returns |
| 1227 |
true if found, false otherwise. |
| 1228 |
|
| 1229 |
If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it |
| 1230 |
within any error as the location of an "opening" token matching |
| 1231 |
the close token TYPE (e.g. the location of the '(' when TYPE is |
| 1232 |
CPP_CLOSE_PAREN). |
| 1233 |
|
| 1234 |
If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly |
| 1235 |
one type (e.g. "expected %<)%>") and thus it may be reasonable to |
| 1236 |
attempt to generate a fix-it hint for the problem. |
| 1237 |
Otherwise msgid describes multiple token types (e.g. |
| 1238 |
"expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to |
| 1239 |
generate a fix-it hint. */ |
| 1240 |
|
| 1241 |
bool |
| 1242 |
c_parser_require (c_parser *parser, |
| 1243 |
enum cpp_ttype type, |
| 1244 |
const char *msgid, |
| 1245 |
location_t matching_location, |
| 1246 |
bool type_is_unique) |
| 1247 |
{ |
| 1248 |
if (c_parser_next_token_is (parser, type)) |
| 1249 |
{ |
| 1250 |
c_parser_consume_token (parser); |
| 1251 |
return true; |
| 1252 |
} |
| 1253 |
else |
| 1254 |
{ |
| 1255 |
location_t next_token_loc = c_parser_peek_token (parser)->location; |
| 1256 |
gcc_rich_location richloc (next_token_loc); |
| 1257 |
|
| 1258 |
/* Potentially supply a fix-it hint, suggesting to add the |
| 1259 |
missing token immediately after the *previous* token. |
| 1260 |
This may move the primary location within richloc. */ |
| 1261 |
if (!parser->error && type_is_unique) |
| 1262 |
maybe_suggest_missing_token_insertion (&richloc, type, |
| 1263 |
parser->last_token_location); |
| 1264 |
|
| 1265 |
/* If matching_location != UNKNOWN_LOCATION, highlight it. |
| 1266 |
Attempt to consolidate diagnostics by printing it as a |
| 1267 |
secondary range within the main diagnostic. */ |
| 1268 |
bool added_matching_location = false; |
| 1269 |
if (matching_location != UNKNOWN_LOCATION) |
| 1270 |
added_matching_location |
| 1271 |
= richloc.add_location_if_nearby (*global_dc, matching_location); |
| 1272 |
|
| 1273 |
if (c_parser_error_richloc (parser, msgid, &richloc)) |
| 1274 |
/* If we weren't able to consolidate matching_location, then |
| 1275 |
print it as a secondary diagnostic. */ |
| 1276 |
if (matching_location != UNKNOWN_LOCATION && !added_matching_location) |
| 1277 |
inform (matching_location, "to match this %qs", |
| 1278 |
get_matching_symbol (type)); |
| 1279 |
|
| 1280 |
return false; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
/* If the next token is the indicated keyword, consume it. Otherwise, |
| 1285 |
issue the error MSGID. Returns true if found, false otherwise. */ |
| 1286 |
|
| 1287 |
static bool |
| 1288 |
c_parser_require_keyword (c_parser *parser, |
| 1289 |
enum rid keyword, |
| 1290 |
const char *msgid) |
| 1291 |
{ |
| 1292 |
if (c_parser_next_token_is_keyword (parser, keyword)) |
| 1293 |
{ |
| 1294 |
c_parser_consume_token (parser); |
| 1295 |
return true; |
| 1296 |
} |
| 1297 |
else |
| 1298 |
{ |
| 1299 |
c_parser_error (parser, msgid); |
| 1300 |
return false; |
| 1301 |
} |
| 1302 |
} |
| 1303 |
|
| 1304 |
/* Like c_parser_require, except that tokens will be skipped until the |
| 1305 |
desired token is found. An error message is still produced if the |
| 1306 |
next token is not as expected. If MSGID is NULL then a message has |
| 1307 |
already been produced and no message will be produced this |
| 1308 |
time. |
| 1309 |
|
| 1310 |
If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it |
| 1311 |
within any error as the location of an "opening" token matching |
| 1312 |
the close token TYPE (e.g. the location of the '(' when TYPE is |
| 1313 |
CPP_CLOSE_PAREN). */ |
| 1314 |
|
| 1315 |
void |
| 1316 |
c_parser_skip_until_found (c_parser *parser, |
| 1317 |
enum cpp_ttype type, |
| 1318 |
const char *msgid, |
| 1319 |
location_t matching_location) |
| 1320 |
{ |
| 1321 |
unsigned nesting_depth = 0; |
| 1322 |
|
| 1323 |
if (c_parser_require (parser, type, msgid, matching_location)) |
| 1324 |
{ |
| 1325 |
if (UNLIKELY (type == CPP_PRAGMA_EOL) && parser->in_omp_attribute_pragma) |
| 1326 |
{ |
| 1327 |
c_token *token = c_parser_peek_token (parser); |
| 1328 |
if (token->type == CPP_EOF) |
| 1329 |
{ |
| 1330 |
parser->tokens = parser->in_omp_attribute_pragma->save_tokens; |
| 1331 |
parser->tokens_avail |
| 1332 |
= parser->in_omp_attribute_pragma->save_tokens_avail; |
| 1333 |
parser->in_omp_attribute_pragma = NULL; |
| 1334 |
} |
| 1335 |
} |
| 1336 |
return; |
| 1337 |
} |
| 1338 |
|
| 1339 |
/* Skip tokens until the desired token is found. */ |
| 1340 |
while (true) |
| 1341 |
{ |
| 1342 |
/* Peek at the next token. */ |
| 1343 |
c_token *token = c_parser_peek_token (parser); |
| 1344 |
/* If we've reached the token we want, consume it and stop. */ |
| 1345 |
if (token->type == type && !nesting_depth) |
| 1346 |
{ |
| 1347 |
c_parser_consume_token (parser); |
| 1348 |
if (UNLIKELY (type == CPP_PRAGMA_EOL) |
| 1349 |
&& parser->in_omp_attribute_pragma) |
| 1350 |
{ |
| 1351 |
c_token *token = c_parser_peek_token (parser); |
| 1352 |
if (token->type == CPP_EOF) |
| 1353 |
{ |
| 1354 |
parser->tokens = parser->in_omp_attribute_pragma->save_tokens; |
| 1355 |
parser->tokens_avail |
| 1356 |
= parser->in_omp_attribute_pragma->save_tokens_avail; |
| 1357 |
parser->in_omp_attribute_pragma = NULL; |
| 1358 |
} |
| 1359 |
} |
| 1360 |
break; |
| 1361 |
} |
| 1362 |
|
| 1363 |
/* If we've run out of tokens, stop. */ |
| 1364 |
if (token->type == CPP_EOF) |
| 1365 |
return; |
| 1366 |
if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
| 1367 |
return; |
| 1368 |
if (token->type == CPP_OPEN_BRACE |
| 1369 |
|| token->type == CPP_OPEN_PAREN |
| 1370 |
|| token->type == CPP_OPEN_SQUARE) |
| 1371 |
++nesting_depth; |
| 1372 |
else if (token->type == CPP_CLOSE_BRACE |
| 1373 |
|| token->type == CPP_CLOSE_PAREN |
| 1374 |
|| token->type == CPP_CLOSE_SQUARE) |
| 1375 |
{ |
| 1376 |
if (nesting_depth-- == 0) |
| 1377 |
break; |
| 1378 |
} |
| 1379 |
/* Consume this token. */ |
| 1380 |
c_parser_consume_token (parser); |
| 1381 |
} |
| 1382 |
parser->error = false; |
| 1383 |
} |
| 1384 |
|
| 1385 |
/* Skip tokens until the end of a parameter is found, but do not |
| 1386 |
consume the comma, semicolon or closing delimiter. */ |
| 1387 |
|
| 1388 |
static void |
| 1389 |
c_parser_skip_to_end_of_parameter (c_parser *parser) |
| 1390 |
{ |
| 1391 |
unsigned nesting_depth = 0; |
| 1392 |
|
| 1393 |
while (true) |
| 1394 |
{ |
| 1395 |
c_token *token = c_parser_peek_token (parser); |
| 1396 |
if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) |
| 1397 |
&& !nesting_depth) |
| 1398 |
break; |
| 1399 |
/* If we've run out of tokens, stop. */ |
| 1400 |
if (token->type == CPP_EOF) |
| 1401 |
return; |
| 1402 |
if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
| 1403 |
return; |
| 1404 |
if (token->type == CPP_OPEN_BRACE |
| 1405 |
|| token->type == CPP_OPEN_PAREN |
| 1406 |
|| token->type == CPP_OPEN_SQUARE) |
| 1407 |
++nesting_depth; |
| 1408 |
else if (token->type == CPP_CLOSE_BRACE |
| 1409 |
|| token->type == CPP_CLOSE_PAREN |
| 1410 |
|| token->type == CPP_CLOSE_SQUARE) |
| 1411 |
{ |
| 1412 |
if (nesting_depth-- == 0) |
| 1413 |
break; |
| 1414 |
} |
| 1415 |
/* Consume this token. */ |
| 1416 |
c_parser_consume_token (parser); |
| 1417 |
} |
| 1418 |
parser->error = false; |
| 1419 |
} |
| 1420 |
|
| 1421 |
/* Skip tokens until a non-nested closing curly brace is the next |
| 1422 |
token, or there are no more tokens. Return true in the first case, |
| 1423 |
false otherwise. */ |
| 1424 |
|
| 1425 |
static bool |
| 1426 |
c_parser_skip_to_closing_brace (c_parser *parser) |
| 1427 |
{ |
| 1428 |
unsigned nesting_depth = 0; |
| 1429 |
|
| 1430 |
while (true) |
| 1431 |
{ |
| 1432 |
c_token *token = c_parser_peek_token (parser); |
| 1433 |
|
| 1434 |
switch (token->type) |
| 1435 |
{ |
| 1436 |
case CPP_PRAGMA_EOL: |
| 1437 |
if (!parser->in_pragma) |
| 1438 |
break; |
| 1439 |
/* FALLTHRU */ |
| 1440 |
case CPP_EOF: |
| 1441 |
/* If we've run out of tokens, stop. */ |
| 1442 |
return false; |
| 1443 |
|
| 1444 |
case CPP_CLOSE_BRACE: |
| 1445 |
/* If the next token is a non-nested `}', then we have reached |
| 1446 |
the end of the current block. */ |
| 1447 |
if (nesting_depth-- == 0) |
| 1448 |
return true; |
| 1449 |
break; |
| 1450 |
|
| 1451 |
case CPP_OPEN_BRACE: |
| 1452 |
/* If it the next token is a `{', then we are entering a new |
| 1453 |
block. Consume the entire block. */ |
| 1454 |
++nesting_depth; |
| 1455 |
break; |
| 1456 |
|
| 1457 |
default: |
| 1458 |
break; |
| 1459 |
} |
| 1460 |
|
| 1461 |
/* Consume the token. */ |
| 1462 |
c_parser_consume_token (parser); |
| 1463 |
} |
| 1464 |
} |
| 1465 |
|
| 1466 |
/* Expect to be at the end of the pragma directive and consume an |
| 1467 |
end of line marker. */ |
| 1468 |
|
| 1469 |
static void |
| 1470 |
c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true) |
| 1471 |
{ |
| 1472 |
gcc_assert (parser->in_pragma); |
| 1473 |
parser->in_pragma = false; |
| 1474 |
|
| 1475 |
if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL) |
| 1476 |
c_parser_error (parser, "expected end of line"); |
| 1477 |
|
| 1478 |
cpp_ttype token_type; |
| 1479 |
do |
| 1480 |
{ |
| 1481 |
c_token *token = c_parser_peek_token (parser); |
| 1482 |
token_type = token->type; |
| 1483 |
if (token_type == CPP_EOF) |
| 1484 |
break; |
| 1485 |
c_parser_consume_token (parser); |
| 1486 |
} |
| 1487 |
while (token_type != CPP_PRAGMA_EOL); |
| 1488 |
|
| 1489 |
if (parser->in_omp_attribute_pragma) |
| 1490 |
{ |
| 1491 |
c_token *token = c_parser_peek_token (parser); |
| 1492 |
if (token->type == CPP_EOF) |
| 1493 |
{ |
| 1494 |
parser->tokens = parser->in_omp_attribute_pragma->save_tokens; |
| 1495 |
parser->tokens_avail |
| 1496 |
= parser->in_omp_attribute_pragma->save_tokens_avail; |
| 1497 |
parser->in_omp_attribute_pragma = NULL; |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
parser->error = false; |
| 1502 |
} |
| 1503 |
|
| 1504 |
/* Skip tokens until we have consumed an entire block, or until we |
| 1505 |
have consumed a non-nested ';'. */ |
| 1506 |
|
| 1507 |
static void |
| 1508 |
c_parser_skip_to_end_of_block_or_statement (c_parser *parser, |
| 1509 |
bool metadirective_p = false) |
| 1510 |
{ |
| 1511 |
unsigned nesting_depth = 0; |
| 1512 |
int bracket_depth = 0; |
| 1513 |
bool save_error = parser->error; |
| 1514 |
|
| 1515 |
while (true) |
| 1516 |
{ |
| 1517 |
c_token *token; |
| 1518 |
|
| 1519 |
/* Peek at the next token. */ |
| 1520 |
token = c_parser_peek_token (parser); |
| 1521 |
|
| 1522 |
switch (token->type) |
| 1523 |
{ |
| 1524 |
case CPP_EOF: |
| 1525 |
return; |
| 1526 |
|
| 1527 |
case CPP_PRAGMA_EOL: |
| 1528 |
if (parser->in_pragma) |
| 1529 |
return; |
| 1530 |
break; |
| 1531 |
|
| 1532 |
case CPP_SEMICOLON: |
| 1533 |
/* If the next token is a ';', we have reached the |
| 1534 |
end of the statement. */ |
| 1535 |
if (!nesting_depth && (!metadirective_p || bracket_depth <= 0)) |
| 1536 |
{ |
| 1537 |
/* Consume the ';'. */ |
| 1538 |
c_parser_consume_token (parser); |
| 1539 |
goto finished; |
| 1540 |
} |
| 1541 |
break; |
| 1542 |
|
| 1543 |
case CPP_CLOSE_BRACE: |
| 1544 |
/* If the next token is a non-nested '}', then we have |
| 1545 |
reached the end of the current block. */ |
| 1546 |
if ((nesting_depth == 0 || --nesting_depth == 0) |
| 1547 |
&& (!metadirective_p || bracket_depth <= 0)) |
| 1548 |
{ |
| 1549 |
c_parser_consume_token (parser); |
| 1550 |
goto finished; |
| 1551 |
} |
| 1552 |
break; |
| 1553 |
|
| 1554 |
case CPP_OPEN_BRACE: |
| 1555 |
/* If it the next token is a '{', then we are entering a new |
| 1556 |
block. Consume the entire block. */ |
| 1557 |
++nesting_depth; |
| 1558 |
break; |
| 1559 |
|
| 1560 |
case CPP_OPEN_PAREN: |
| 1561 |
/* Track parentheses in case the statement is a standalone 'for' |
| 1562 |
statement - we want to skip over the semicolons separating the |
| 1563 |
operands. */ |
| 1564 |
if (metadirective_p && nesting_depth == 0) |
| 1565 |
++bracket_depth; |
| 1566 |
break; |
| 1567 |
|
| 1568 |
case CPP_CLOSE_PAREN: |
| 1569 |
if (metadirective_p && nesting_depth == 0) |
| 1570 |
--bracket_depth; |
| 1571 |
break; |
| 1572 |
|
| 1573 |
case CPP_PRAGMA: |
| 1574 |
/* If we see a pragma, consume the whole thing at once. We |
| 1575 |
have some safeguards against consuming pragmas willy-nilly. |
| 1576 |
Normally, we'd expect to be here with parser->error set, |
| 1577 |
which disables these safeguards. But it's possible to get |
| 1578 |
here for secondary error recovery, after parser->error has |
| 1579 |
been cleared. */ |
| 1580 |
c_parser_consume_pragma (parser); |
| 1581 |
c_parser_skip_to_pragma_eol (parser, false); |
| 1582 |
parser->error = save_error; |
| 1583 |
continue; |
| 1584 |
|
| 1585 |
default: |
| 1586 |
break; |
| 1587 |
} |
| 1588 |
|
| 1589 |
c_parser_consume_token (parser); |
| 1590 |
} |
| 1591 |
|
| 1592 |
finished: |
| 1593 |
parser->error = false; |
| 1594 |
} |
| 1595 |
|
| 1596 |
/* CPP's options (initialized by c-opts.cc). */ |
| 1597 |
extern cpp_options *cpp_opts; |
| 1598 |
|
| 1599 |
/* Save the warning flags which are controlled by __extension__. */ |
| 1600 |
|
| 1601 |
static inline int |
| 1602 |
disable_extension_diagnostics (void) |
| 1603 |
{ |
| 1604 |
int ret = (pedantic |
| 1605 |
| (warn_pointer_arith << 1) |
| 1606 |
| (warn_traditional << 2) |
| 1607 |
| (flag_iso << 3) |
| 1608 |
| (warn_long_long << 4) |
| 1609 |
| (warn_cxx_compat << 5) |
| 1610 |
| (warn_overlength_strings << 6) |
| 1611 |
/* warn_c90_c99_compat has three states: -1/0/1, so we must |
| 1612 |
play tricks to properly restore it. */ |
| 1613 |
| ((warn_c90_c99_compat == 1) << 7) |
| 1614 |
| ((warn_c90_c99_compat == -1) << 8) |
| 1615 |
/* Similarly for warn_c99_c11_compat. */ |
| 1616 |
| ((warn_c99_c11_compat == 1) << 9) |
| 1617 |
| ((warn_c99_c11_compat == -1) << 10) |
| 1618 |
/* Similarly for warn_c11_c23_compat. */ |
| 1619 |
| ((warn_c11_c23_compat == 1) << 11) |
| 1620 |
| ((warn_c11_c23_compat == -1) << 12) |
| 1621 |
/* Similarly for warn_c23_c2y_compat. */ |
| 1622 |
| ((warn_c23_c2y_compat == 1) << 13) |
| 1623 |
| ((warn_c23_c2y_compat == -1) << 14) |
| 1624 |
); |
| 1625 |
cpp_opts->cpp_pedantic = pedantic = 0; |
| 1626 |
warn_pointer_arith = 0; |
| 1627 |
cpp_opts->cpp_warn_traditional = warn_traditional = 0; |
| 1628 |
flag_iso = 0; |
| 1629 |
cpp_opts->cpp_warn_long_long = warn_long_long = 0; |
| 1630 |
warn_cxx_compat = 0; |
| 1631 |
warn_overlength_strings = 0; |
| 1632 |
warn_c90_c99_compat = 0; |
| 1633 |
warn_c99_c11_compat = 0; |
| 1634 |
warn_c11_c23_compat = 0; |
| 1635 |
warn_c23_c2y_compat = 0; |
| 1636 |
return ret; |
| 1637 |
} |
| 1638 |
|
| 1639 |
/* Restore the warning flags which are controlled by __extension__. |
| 1640 |
FLAGS is the return value from disable_extension_diagnostics. */ |
| 1641 |
|
| 1642 |
static inline void |
| 1643 |
restore_extension_diagnostics (int flags) |
| 1644 |
{ |
| 1645 |
cpp_opts->cpp_pedantic = pedantic = flags & 1; |
| 1646 |
warn_pointer_arith = (flags >> 1) & 1; |
| 1647 |
cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1; |
| 1648 |
flag_iso = (flags >> 3) & 1; |
| 1649 |
cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1; |
| 1650 |
warn_cxx_compat = (flags >> 5) & 1; |
| 1651 |
warn_overlength_strings = (flags >> 6) & 1; |
| 1652 |
/* See above for why is this needed. */ |
| 1653 |
warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0); |
| 1654 |
warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0); |
| 1655 |
warn_c11_c23_compat = (flags >> 11) & 1 ? 1 : ((flags >> 12) & 1 ? -1 : 0); |
| 1656 |
warn_c23_c2y_compat = (flags >> 13) & 1 ? 1 : ((flags >> 14) & 1 ? -1 : 0); |
| 1657 |
} |
| 1658 |
|
| 1659 |
/* Helper data structure for parsing #pragma acc routine. */ |
| 1660 |
struct oacc_routine_data { |
| 1661 |
bool error_seen; /* Set if error has been reported. */ |
| 1662 |
bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */ |
| 1663 |
tree clauses; |
| 1664 |
location_t loc; |
| 1665 |
}; |
| 1666 |
|
| 1667 |
/* Used for parsing objc foreach statements. */ |
| 1668 |
static tree objc_foreach_break_label, objc_foreach_continue_label; |
| 1669 |
|
| 1670 |
/* Used for parsing OMP for loops. |
| 1671 |
|
| 1672 |
Some notes on flags used for context: |
| 1673 |
parser->omp_for_parse_state is non-null anywhere inside the OMP FOR |
| 1674 |
construct, except for the final-loop-body. |
| 1675 |
The want_nested_loop flag is true if inside a {} sequence where |
| 1676 |
a loop-nest (or another {} sequence containing a loop-nest) is expected, |
| 1677 |
but has not yet been seen. It's false when parsing intervening code |
| 1678 |
statements or their substatements that cannot contain a loop-nest. |
| 1679 |
The in_intervening_code flag is true when parsing any intervening code, |
| 1680 |
including substatements, and whether or not want_nested_loop is true. |
| 1681 |
|
| 1682 |
And, about error handling: |
| 1683 |
The saw_intervening_code flag is set if the loop is not perfectly |
| 1684 |
nested, even in the usual case where this is not an error. |
| 1685 |
perfect_nesting_fail is set if an error has been diagnosed because an |
| 1686 |
imperfectly-nested loop was found where a perfectly-nested one is |
| 1687 |
required (we diagnose this only once). |
| 1688 |
fail is set if any kind of structural error in the loop nest |
| 1689 |
has been found and diagnosed. |
| 1690 |
*/ |
| 1691 |
struct omp_for_parse_data { |
| 1692 |
enum tree_code code; |
| 1693 |
tree declv, condv, incrv, initv; |
| 1694 |
tree pre_body; |
| 1695 |
tree bindings; |
| 1696 |
int count; /* Expected nesting depth. */ |
| 1697 |
int depth; /* Current nesting depth. */ |
| 1698 |
location_t for_loc; |
| 1699 |
bool ordered : 1; |
| 1700 |
bool inscan : 1; |
| 1701 |
bool want_nested_loop : 1; |
| 1702 |
bool in_intervening_code : 1; |
| 1703 |
bool saw_intervening_code: 1; |
| 1704 |
bool perfect_nesting_fail : 1; |
| 1705 |
bool fail : 1; |
| 1706 |
}; |
| 1707 |
|
| 1708 |
struct attr_state |
| 1709 |
{ |
| 1710 |
/* True if we parsed a musttail attribute for return. */ |
| 1711 |
bool musttail_p; |
| 1712 |
|
| 1713 |
void reset () { musttail_p = false; } |
| 1714 |
}; |
| 1715 |
|
| 1716 |
static bool c_parser_nth_token_starts_std_attributes (c_parser *, |
| 1717 |
unsigned int); |
| 1718 |
static tree c_parser_std_attribute_specifier_sequence (c_parser *); |
| 1719 |
static void c_parser_external_declaration (c_parser *); |
| 1720 |
static void c_parser_asm_definition (c_parser *); |
| 1721 |
static tree c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, |
| 1722 |
bool, bool, bool, tree * = NULL, |
| 1723 |
vec<c_token> * = NULL, |
| 1724 |
bool have_attrs = false, |
| 1725 |
tree attrs = NULL, |
| 1726 |
struct oacc_routine_data * = NULL, |
| 1727 |
bool * = NULL); |
| 1728 |
static bool c_parser_handle_statement_omp_attributes (c_parser *, tree &, |
| 1729 |
bool *); |
| 1730 |
static void c_parser_static_assert_declaration_no_semi (c_parser *); |
| 1731 |
static void c_parser_static_assert_declaration (c_parser *); |
| 1732 |
static struct c_typespec c_parser_enum_specifier (c_parser *); |
| 1733 |
static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); |
| 1734 |
static tree c_parser_struct_declaration (c_parser *, tree *); |
| 1735 |
static struct c_typespec c_parser_typeof_specifier (c_parser *); |
| 1736 |
static tree c_parser_alignas_specifier (c_parser *); |
| 1737 |
static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, |
| 1738 |
c_dtr_syn, bool *); |
| 1739 |
static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, |
| 1740 |
bool, |
| 1741 |
struct c_declarator *); |
| 1742 |
static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree, |
| 1743 |
bool); |
| 1744 |
static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree, |
| 1745 |
tree, bool); |
| 1746 |
static struct c_parm *c_parser_parameter_declaration (c_parser *, tree, bool); |
| 1747 |
static tree c_parser_asm_string_literal (c_parser *); |
| 1748 |
static tree c_parser_simple_asm_expr (c_parser *); |
| 1749 |
static tree c_parser_gnu_attributes (c_parser *); |
| 1750 |
static struct c_expr c_parser_initializer (c_parser *, tree); |
| 1751 |
static struct c_expr c_parser_braced_init (c_parser *, tree, bool, |
| 1752 |
struct obstack *, tree); |
| 1753 |
static void c_parser_initelt (c_parser *, struct obstack *); |
| 1754 |
static void c_parser_initval (c_parser *, struct c_expr *, |
| 1755 |
struct obstack *); |
| 1756 |
static tree c_parser_compound_statement (c_parser *, location_t * = NULL); |
| 1757 |
static location_t c_parser_compound_statement_nostart (c_parser *); |
| 1758 |
static void c_parser_label (c_parser *, tree); |
| 1759 |
static void c_parser_statement (c_parser *, bool *, location_t * = NULL); |
| 1760 |
static void c_parser_statement_after_labels (c_parser *, bool *, tree, |
| 1761 |
vec<tree> * = NULL, |
| 1762 |
attr_state = {}); |
| 1763 |
static tree c_parser_c99_block_statement (c_parser *, bool *, |
| 1764 |
location_t * = NULL); |
| 1765 |
static void c_parser_if_statement (c_parser *, bool *, vec<tree> *); |
| 1766 |
static void c_parser_switch_statement (c_parser *, bool *, tree); |
| 1767 |
static void c_parser_while_statement (c_parser *, bool, unsigned short, bool, |
| 1768 |
bool *, tree); |
| 1769 |
static void c_parser_do_statement (c_parser *, bool, unsigned short, bool, |
| 1770 |
tree); |
| 1771 |
static void c_parser_for_statement (c_parser *, bool, unsigned short, bool, |
| 1772 |
bool *, tree); |
| 1773 |
static tree c_parser_asm_statement (c_parser *); |
| 1774 |
static tree c_parser_asm_operands (c_parser *); |
| 1775 |
static tree c_parser_asm_goto_operands (c_parser *); |
| 1776 |
static tree c_parser_asm_clobbers (c_parser *); |
| 1777 |
static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *, |
| 1778 |
tree = NULL_TREE); |
| 1779 |
static struct c_expr c_parser_conditional_expression (c_parser *, |
| 1780 |
struct c_expr *, tree); |
| 1781 |
static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *, |
| 1782 |
tree); |
| 1783 |
static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); |
| 1784 |
static struct c_expr c_parser_unary_expression (c_parser *); |
| 1785 |
static struct c_expr c_parser_sizeof_expression (c_parser *); |
| 1786 |
static struct c_expr c_parser_alignof_expression (c_parser *); |
| 1787 |
static struct c_expr c_parser_postfix_expression (c_parser *); |
| 1788 |
static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, |
| 1789 |
struct c_declspecs *, |
| 1790 |
struct c_type_name *, |
| 1791 |
location_t); |
| 1792 |
static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, |
| 1793 |
location_t loc, |
| 1794 |
struct c_expr); |
| 1795 |
static tree c_parser_transaction (c_parser *, enum rid); |
| 1796 |
static struct c_expr c_parser_transaction_expression (c_parser *, enum rid); |
| 1797 |
static tree c_parser_transaction_cancel (c_parser *); |
| 1798 |
static struct c_expr c_parser_expression (c_parser *); |
| 1799 |
static struct c_expr c_parser_expression_conv (c_parser *); |
| 1800 |
static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool, |
| 1801 |
vec<tree, va_gc> **, location_t *, |
| 1802 |
tree *, vec<location_t> *, |
| 1803 |
unsigned int * = NULL); |
| 1804 |
static struct c_expr c_parser_has_attribute_expression (c_parser *); |
| 1805 |
|
| 1806 |
static void c_parser_oacc_declare (c_parser *); |
| 1807 |
static void c_parser_oacc_enter_exit_data (c_parser *, bool); |
| 1808 |
static void c_parser_oacc_update (c_parser *); |
| 1809 |
static void c_parser_omp_construct (c_parser *, bool *); |
| 1810 |
static void c_parser_omp_threadprivate (c_parser *); |
| 1811 |
static void c_parser_omp_barrier (c_parser *); |
| 1812 |
static void c_parser_omp_depobj (c_parser *); |
| 1813 |
static void c_parser_omp_flush (c_parser *); |
| 1814 |
static bool c_parser_omp_next_tokens_can_be_canon_loop (c_parser *, |
| 1815 |
enum tree_code, bool); |
| 1816 |
static tree c_parser_omp_loop_nest (c_parser *, bool *); |
| 1817 |
static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code, |
| 1818 |
tree, tree *, bool *); |
| 1819 |
static void c_parser_omp_taskwait (c_parser *); |
| 1820 |
static void c_parser_omp_taskyield (c_parser *); |
| 1821 |
static void c_parser_omp_cancel (c_parser *); |
| 1822 |
static void c_parser_omp_nothing (c_parser *); |
| 1823 |
static void c_parser_omp_metadirective (c_parser *, bool *); |
| 1824 |
|
| 1825 |
enum pragma_context { pragma_external, pragma_struct, pragma_param, |
| 1826 |
pragma_stmt, pragma_compound }; |
| 1827 |
static bool c_parser_pragma (c_parser *, enum pragma_context, bool *, tree); |
| 1828 |
static bool c_parser_omp_cancellation_point (c_parser *, enum pragma_context); |
| 1829 |
static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *); |
| 1830 |
static void c_parser_omp_begin (c_parser *); |
| 1831 |
static void c_parser_omp_end (c_parser *); |
| 1832 |
static bool c_parser_omp_declare (c_parser *, enum pragma_context); |
| 1833 |
static void c_parser_omp_requires (c_parser *); |
| 1834 |
static bool c_parser_omp_error (c_parser *, enum pragma_context); |
| 1835 |
static void c_parser_omp_assumption_clauses (c_parser *, bool); |
| 1836 |
static void c_parser_omp_allocate (c_parser *); |
| 1837 |
static void c_parser_omp_assumes (c_parser *); |
| 1838 |
static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *); |
| 1839 |
static tree c_parser_omp_dispatch (location_t, c_parser *); |
| 1840 |
static void c_parser_omp_interop (c_parser *); |
| 1841 |
static void c_parser_oacc_routine (c_parser *, enum pragma_context); |
| 1842 |
|
| 1843 |
/* These Objective-C parser functions are only ever called when |
| 1844 |
compiling Objective-C. */ |
| 1845 |
static void c_parser_objc_class_definition (c_parser *, tree); |
| 1846 |
static void c_parser_objc_class_instance_variables (c_parser *); |
| 1847 |
static void c_parser_objc_class_declaration (c_parser *); |
| 1848 |
static void c_parser_objc_alias_declaration (c_parser *); |
| 1849 |
static void c_parser_objc_protocol_definition (c_parser *, tree); |
| 1850 |
static bool c_parser_objc_method_type (c_parser *); |
| 1851 |
static void c_parser_objc_method_definition (c_parser *); |
| 1852 |
static void c_parser_objc_methodprotolist (c_parser *); |
| 1853 |
static void c_parser_objc_methodproto (c_parser *); |
| 1854 |
static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *); |
| 1855 |
static tree c_parser_objc_type_name (c_parser *); |
| 1856 |
static tree c_parser_objc_protocol_refs (c_parser *); |
| 1857 |
static void c_parser_objc_try_catch_finally_statement (c_parser *); |
| 1858 |
static void c_parser_objc_synchronized_statement (c_parser *); |
| 1859 |
static tree c_parser_objc_selector (c_parser *); |
| 1860 |
static tree c_parser_objc_selector_arg (c_parser *); |
| 1861 |
static tree c_parser_objc_receiver (c_parser *); |
| 1862 |
static tree c_parser_objc_message_args (c_parser *); |
| 1863 |
static tree c_parser_objc_keywordexpr (c_parser *); |
| 1864 |
static void c_parser_objc_at_property_declaration (c_parser *); |
| 1865 |
static void c_parser_objc_at_synthesize_declaration (c_parser *); |
| 1866 |
static void c_parser_objc_at_dynamic_declaration (c_parser *); |
| 1867 |
static bool c_parser_objc_diagnose_bad_element_prefix |
| 1868 |
(c_parser *, struct c_declspecs *); |
| 1869 |
static location_t c_parser_parse_rtl_body (c_parser *, char *); |
| 1870 |
static tree c_parser_handle_musttail (c_parser *, tree, attr_state &); |
| 1871 |
|
| 1872 |
#if ENABLE_ANALYZER |
| 1873 |
|
| 1874 |
namespace ana { |
| 1875 |
|
| 1876 |
/* Concrete implementation of ana::translation_unit for the C frontend. */ |
| 1877 |
|
| 1878 |
class c_translation_unit : public translation_unit |
| 1879 |
{ |
| 1880 |
public: |
| 1881 |
/* Implementation of translation_unit::lookup_constant_by_id for use by the |
| 1882 |
analyzer to look up named constants in the user's source code. */ |
| 1883 |
tree lookup_constant_by_id (tree id) const final override |
| 1884 |
{ |
| 1885 |
/* Consider decls. */ |
| 1886 |
if (tree decl = lookup_name (id)) |
| 1887 |
if (TREE_CODE (decl) == CONST_DECL) |
| 1888 |
if (tree value = DECL_INITIAL (decl)) |
| 1889 |
if (TREE_CODE (value) == INTEGER_CST) |
| 1890 |
return value; |
| 1891 |
|
| 1892 |
/* Consider macros. */ |
| 1893 |
cpp_hashnode *hashnode = C_CPP_HASHNODE (id); |
| 1894 |
if (cpp_macro_p (hashnode)) |
| 1895 |
if (tree value = consider_macro (hashnode->value.macro)) |
| 1896 |
return value; |
| 1897 |
|
| 1898 |
return NULL_TREE; |
| 1899 |
} |
| 1900 |
|
| 1901 |
tree |
| 1902 |
lookup_type_by_id (tree id) const final override |
| 1903 |
{ |
| 1904 |
if (tree type_decl = lookup_name (id)) |
| 1905 |
if (TREE_CODE (type_decl) == TYPE_DECL) |
| 1906 |
{ |
| 1907 |
tree record_type = TREE_TYPE (type_decl); |
| 1908 |
if (TREE_CODE (record_type) == RECORD_TYPE) |
| 1909 |
return record_type; |
| 1910 |
} |
| 1911 |
|
| 1912 |
return NULL_TREE; |
| 1913 |
} |
| 1914 |
|
| 1915 |
tree |
| 1916 |
lookup_global_var_by_id (tree id) const final override |
| 1917 |
{ |
| 1918 |
if (tree var_decl = lookup_name (id)) |
| 1919 |
if (TREE_CODE (var_decl) == VAR_DECL) |
| 1920 |
return var_decl; |
| 1921 |
|
| 1922 |
return NULL_TREE; |
| 1923 |
} |
| 1924 |
|
| 1925 |
private: |
| 1926 |
/* Attempt to get an INTEGER_CST from MACRO. |
| 1927 |
Only handle the simplest cases: where MACRO's definition is a single |
| 1928 |
token containing a number, by lexing the number again. |
| 1929 |
This will handle e.g. |
| 1930 |
#define NAME 42 |
| 1931 |
and other bases but not negative numbers, parentheses or e.g. |
| 1932 |
#define NAME 1 << 7 |
| 1933 |
as doing so would require a parser. */ |
| 1934 |
tree consider_macro (cpp_macro *macro) const |
| 1935 |
{ |
| 1936 |
if (macro->paramc > 0) |
| 1937 |
return NULL_TREE; |
| 1938 |
if (macro->kind != cmk_macro) |
| 1939 |
return NULL_TREE; |
| 1940 |
if (macro->count != 1) |
| 1941 |
return NULL_TREE; |
| 1942 |
const cpp_token &tok = macro->exp.tokens[0]; |
| 1943 |
if (tok.type != CPP_NUMBER) |
| 1944 |
return NULL_TREE; |
| 1945 |
|
| 1946 |
cpp_reader *old_parse_in = parse_in; |
| 1947 |
parse_in = cpp_create_reader (CLK_GNUC89, NULL, line_table); |
| 1948 |
|
| 1949 |
pretty_printer pp; |
| 1950 |
pp_string (&pp, (const char *) tok.val.str.text); |
| 1951 |
pp_newline (&pp); |
| 1952 |
cpp_push_buffer (parse_in, |
| 1953 |
(const unsigned char *) pp_formatted_text (&pp), |
| 1954 |
strlen (pp_formatted_text (&pp)), |
| 1955 |
0); |
| 1956 |
|
| 1957 |
tree value; |
| 1958 |
location_t loc; |
| 1959 |
unsigned char cpp_flags; |
| 1960 |
c_lex_with_flags (&value, &loc, &cpp_flags, 0); |
| 1961 |
|
| 1962 |
cpp_destroy (parse_in); |
| 1963 |
parse_in = old_parse_in; |
| 1964 |
|
| 1965 |
if (value && TREE_CODE (value) == INTEGER_CST) |
| 1966 |
return value; |
| 1967 |
|
| 1968 |
return NULL_TREE; |
| 1969 |
} |
| 1970 |
}; |
| 1971 |
|
| 1972 |
} // namespace ana |
| 1973 |
|
| 1974 |
#endif /* #if ENABLE_ANALYZER */ |
| 1975 |
|
| 1976 |
/* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9). |
| 1977 |
|
| 1978 |
translation-unit: |
| 1979 |
external-declarations |
| 1980 |
|
| 1981 |
external-declarations: |
| 1982 |
external-declaration |
| 1983 |
external-declarations external-declaration |
| 1984 |
|
| 1985 |
GNU extensions: |
| 1986 |
|
| 1987 |
translation-unit: |
| 1988 |
empty |
| 1989 |
*/ |
| 1990 |
|
| 1991 |
static void |
| 1992 |
c_parser_translation_unit (c_parser *parser) |
| 1993 |
{ |
| 1994 |
if (c_parser_next_token_is (parser, CPP_EOF)) |
| 1995 |
{ |
| 1996 |
pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 1997 |
"ISO C forbids an empty translation unit"); |
| 1998 |
} |
| 1999 |
else |
| 2000 |
{ |
| 2001 |
void *obstack_position = obstack_alloc (&parser_obstack, 0); |
| 2002 |
mark_valid_location_for_stdc_pragma (false); |
| 2003 |
do |
| 2004 |
{ |
| 2005 |
ggc_collect (); |
| 2006 |
c_parser_external_declaration (parser); |
| 2007 |
obstack_free (&parser_obstack, obstack_position); |
| 2008 |
} |
| 2009 |
while (c_parser_next_token_is_not (parser, CPP_EOF)); |
| 2010 |
} |
| 2011 |
|
| 2012 |
unsigned int i; |
| 2013 |
tree decl; |
| 2014 |
FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl) |
| 2015 |
if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node) |
| 2016 |
error ("storage size of %q+D isn%'t known", decl); |
| 2017 |
|
| 2018 |
if (vec_safe_length (current_omp_declare_target_attribute)) |
| 2019 |
{ |
| 2020 |
c_omp_declare_target_attr |
| 2021 |
a = current_omp_declare_target_attribute->pop (); |
| 2022 |
if (!errorcount) |
| 2023 |
error ("%qs without corresponding %qs", |
| 2024 |
a.device_type >= 0 ? "#pragma omp begin declare target" |
| 2025 |
: "#pragma omp declare target", |
| 2026 |
"#pragma omp end declare target"); |
| 2027 |
vec_safe_truncate (current_omp_declare_target_attribute, 0); |
| 2028 |
} |
| 2029 |
if (vec_safe_length (current_omp_begin_assumes)) |
| 2030 |
{ |
| 2031 |
if (!errorcount) |
| 2032 |
error ("%qs without corresponding %qs", |
| 2033 |
"#pragma omp begin assumes", "#pragma omp end assumes"); |
| 2034 |
vec_safe_truncate (current_omp_begin_assumes, 0); |
| 2035 |
} |
| 2036 |
|
| 2037 |
#if ENABLE_ANALYZER |
| 2038 |
if (flag_analyzer) |
| 2039 |
{ |
| 2040 |
ana::c_translation_unit tu; |
| 2041 |
ana::on_finish_translation_unit (tu); |
| 2042 |
} |
| 2043 |
#endif |
| 2044 |
} |
| 2045 |
|
| 2046 |
/* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9). |
| 2047 |
|
| 2048 |
external-declaration: |
| 2049 |
function-definition |
| 2050 |
declaration |
| 2051 |
|
| 2052 |
GNU extensions: |
| 2053 |
|
| 2054 |
external-declaration: |
| 2055 |
asm-definition |
| 2056 |
; |
| 2057 |
__extension__ external-declaration |
| 2058 |
|
| 2059 |
Objective-C: |
| 2060 |
|
| 2061 |
external-declaration: |
| 2062 |
objc-class-definition |
| 2063 |
objc-class-declaration |
| 2064 |
objc-alias-declaration |
| 2065 |
objc-protocol-definition |
| 2066 |
objc-method-definition |
| 2067 |
@end |
| 2068 |
*/ |
| 2069 |
|
| 2070 |
static void |
| 2071 |
c_parser_external_declaration (c_parser *parser) |
| 2072 |
{ |
| 2073 |
int ext; |
| 2074 |
switch (c_parser_peek_token (parser)->type) |
| 2075 |
{ |
| 2076 |
case CPP_KEYWORD: |
| 2077 |
switch (c_parser_peek_token (parser)->keyword) |
| 2078 |
{ |
| 2079 |
case RID_EXTENSION: |
| 2080 |
ext = disable_extension_diagnostics (); |
| 2081 |
c_parser_consume_token (parser); |
| 2082 |
c_parser_external_declaration (parser); |
| 2083 |
restore_extension_diagnostics (ext); |
| 2084 |
break; |
| 2085 |
case RID_ASM: |
| 2086 |
c_parser_asm_definition (parser); |
| 2087 |
break; |
| 2088 |
case RID_AT_INTERFACE: |
| 2089 |
case RID_AT_IMPLEMENTATION: |
| 2090 |
gcc_assert (c_dialect_objc ()); |
| 2091 |
c_parser_objc_class_definition (parser, NULL_TREE); |
| 2092 |
break; |
| 2093 |
case RID_AT_CLASS: |
| 2094 |
gcc_assert (c_dialect_objc ()); |
| 2095 |
c_parser_objc_class_declaration (parser); |
| 2096 |
break; |
| 2097 |
case RID_AT_ALIAS: |
| 2098 |
gcc_assert (c_dialect_objc ()); |
| 2099 |
c_parser_objc_alias_declaration (parser); |
| 2100 |
break; |
| 2101 |
case RID_AT_PROTOCOL: |
| 2102 |
gcc_assert (c_dialect_objc ()); |
| 2103 |
c_parser_objc_protocol_definition (parser, NULL_TREE); |
| 2104 |
break; |
| 2105 |
case RID_AT_PROPERTY: |
| 2106 |
gcc_assert (c_dialect_objc ()); |
| 2107 |
c_parser_objc_at_property_declaration (parser); |
| 2108 |
break; |
| 2109 |
case RID_AT_SYNTHESIZE: |
| 2110 |
gcc_assert (c_dialect_objc ()); |
| 2111 |
c_parser_objc_at_synthesize_declaration (parser); |
| 2112 |
break; |
| 2113 |
case RID_AT_DYNAMIC: |
| 2114 |
gcc_assert (c_dialect_objc ()); |
| 2115 |
c_parser_objc_at_dynamic_declaration (parser); |
| 2116 |
break; |
| 2117 |
case RID_AT_END: |
| 2118 |
gcc_assert (c_dialect_objc ()); |
| 2119 |
c_parser_consume_token (parser); |
| 2120 |
objc_finish_implementation (); |
| 2121 |
break; |
| 2122 |
default: |
| 2123 |
goto decl_or_fndef; |
| 2124 |
} |
| 2125 |
break; |
| 2126 |
case CPP_SEMICOLON: |
| 2127 |
pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 2128 |
"ISO C does not allow extra %<;%> outside of a function"); |
| 2129 |
c_parser_consume_token (parser); |
| 2130 |
break; |
| 2131 |
case CPP_PRAGMA: |
| 2132 |
mark_valid_location_for_stdc_pragma (true); |
| 2133 |
c_parser_pragma (parser, pragma_external, NULL, NULL_TREE); |
| 2134 |
mark_valid_location_for_stdc_pragma (false); |
| 2135 |
break; |
| 2136 |
case CPP_PLUS: |
| 2137 |
case CPP_MINUS: |
| 2138 |
if (c_dialect_objc ()) |
| 2139 |
{ |
| 2140 |
c_parser_objc_method_definition (parser); |
| 2141 |
break; |
| 2142 |
} |
| 2143 |
/* Else fall through, and yield a syntax error trying to parse |
| 2144 |
as a declaration or function definition. */ |
| 2145 |
/* FALLTHRU */ |
| 2146 |
default: |
| 2147 |
decl_or_fndef: |
| 2148 |
/* A declaration or a function definition (or, in Objective-C, |
| 2149 |
an @interface or @protocol with prefix attributes). We can |
| 2150 |
only tell which after parsing the declaration specifiers, if |
| 2151 |
any, and the first declarator. */ |
| 2152 |
c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 2153 |
false); |
| 2154 |
break; |
| 2155 |
} |
| 2156 |
} |
| 2157 |
|
| 2158 |
static void c_parser_handle_directive_omp_attributes (tree &, vec<c_token> *&, |
| 2159 |
vec<c_token> *); |
| 2160 |
static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token> *); |
| 2161 |
static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool); |
| 2162 |
|
| 2163 |
/* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */ |
| 2164 |
|
| 2165 |
static void |
| 2166 |
add_debug_begin_stmt (location_t loc) |
| 2167 |
{ |
| 2168 |
/* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */ |
| 2169 |
if (!MAY_HAVE_DEBUG_MARKER_STMTS || !building_stmt_list_p ()) |
| 2170 |
return; |
| 2171 |
|
| 2172 |
tree stmt = build0 (DEBUG_BEGIN_STMT, void_type_node); |
| 2173 |
SET_EXPR_LOCATION (stmt, loc); |
| 2174 |
add_stmt (stmt); |
| 2175 |
} |
| 2176 |
|
| 2177 |
/* Helper function for c_parser_declaration_or_fndef and |
| 2178 |
Handle assume attribute(s). */ |
| 2179 |
|
| 2180 |
static tree |
| 2181 |
handle_assume_attribute (location_t here, tree attrs, bool nested) |
| 2182 |
{ |
| 2183 |
if (nested) |
| 2184 |
for (tree attr = lookup_attribute ("gnu", "assume", attrs); attr; |
| 2185 |
attr = lookup_attribute ("gnu", "assume", TREE_CHAIN (attr))) |
| 2186 |
{ |
| 2187 |
tree args = TREE_VALUE (attr); |
| 2188 |
int nargs = list_length (args); |
| 2189 |
if (nargs != 1) |
| 2190 |
{ |
| 2191 |
error_at (here, "wrong number of arguments specified " |
| 2192 |
"for %qE attribute", |
| 2193 |
get_attribute_name (attr)); |
| 2194 |
inform (here, "expected %i, found %i", 1, nargs); |
| 2195 |
} |
| 2196 |
else |
| 2197 |
{ |
| 2198 |
tree arg = TREE_VALUE (args); |
| 2199 |
arg = c_objc_common_truthvalue_conversion (here, arg); |
| 2200 |
arg = c_fully_fold (arg, false, NULL); |
| 2201 |
if (arg != error_mark_node) |
| 2202 |
{ |
| 2203 |
tree fn = build_call_expr_internal_loc (here, IFN_ASSUME, |
| 2204 |
void_type_node, 1, |
| 2205 |
arg); |
| 2206 |
add_stmt (fn); |
| 2207 |
} |
| 2208 |
} |
| 2209 |
} |
| 2210 |
else |
| 2211 |
pedwarn (here, OPT_Wattributes, |
| 2212 |
"%<assume%> attribute at top level"); |
| 2213 |
|
| 2214 |
return remove_attribute ("gnu", "assume", attrs); |
| 2215 |
} |
| 2216 |
|
| 2217 |
/* We might need to reclassify any previously-lexed identifier, e.g. |
| 2218 |
when we've left a for loop with an if-statement without else in the |
| 2219 |
body - we might have used a wrong scope for the token. See PR67784. */ |
| 2220 |
|
| 2221 |
static void |
| 2222 |
c_parser_maybe_reclassify_token (c_parser *parser) |
| 2223 |
{ |
| 2224 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 2225 |
{ |
| 2226 |
c_token *token = c_parser_peek_token (parser); |
| 2227 |
|
| 2228 |
if (token->id_kind != C_ID_CLASSNAME) |
| 2229 |
{ |
| 2230 |
tree decl = lookup_name (token->value); |
| 2231 |
|
| 2232 |
token->id_kind = C_ID_ID; |
| 2233 |
if (decl) |
| 2234 |
{ |
| 2235 |
if (TREE_CODE (decl) == TYPE_DECL) |
| 2236 |
token->id_kind = C_ID_TYPENAME; |
| 2237 |
} |
| 2238 |
else if (c_dialect_objc ()) |
| 2239 |
{ |
| 2240 |
tree objc_interface_decl = objc_is_class_name (token->value); |
| 2241 |
/* Objective-C class names are in the same namespace as |
| 2242 |
variables and typedefs, and hence are shadowed by local |
| 2243 |
declarations. */ |
| 2244 |
if (objc_interface_decl) |
| 2245 |
{ |
| 2246 |
token->value = objc_interface_decl; |
| 2247 |
token->id_kind = C_ID_CLASSNAME; |
| 2248 |
} |
| 2249 |
} |
| 2250 |
} |
| 2251 |
} |
| 2252 |
} |
| 2253 |
|
| 2254 |
/* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 |
| 2255 |
6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition |
| 2256 |
is accepted; otherwise (old-style parameter declarations) only other |
| 2257 |
declarations are accepted. If STATIC_ASSERT_OK is true, a static |
| 2258 |
assertion is accepted; otherwise (old-style parameter declarations) |
| 2259 |
it is not. If NESTED is true, we are inside a function or parsing |
| 2260 |
old-style parameter declarations; any functions encountered are |
| 2261 |
nested functions and declaration specifiers are required; otherwise |
| 2262 |
we are at top level and functions are normal functions and |
| 2263 |
declaration specifiers may be optional. If EMPTY_OK is true, empty |
| 2264 |
declarations are OK (subject to all other constraints); otherwise |
| 2265 |
(old-style parameter declarations) they are diagnosed. If |
| 2266 |
START_ATTR_OK is true, the declaration specifiers may start with |
| 2267 |
attributes (GNU or standard); otherwise they may not. |
| 2268 |
OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed |
| 2269 |
declaration when parsing an Objective-C foreach statement. |
| 2270 |
FALLTHRU_ATTR_P is used to signal whether this function parsed |
| 2271 |
"__attribute__((fallthrough));". ATTRS are any standard attributes |
| 2272 |
parsed in the caller (in contexts where such attributes had to be |
| 2273 |
parsed to determine whether what follows is a declaration or a |
| 2274 |
statement); HAVE_ATTRS says whether there were any such attributes |
| 2275 |
(even empty). If SIMPLE_OK, the construct can be a simple-declaration; |
| 2276 |
in that case, the ';' is not consumed (left to the caller so that it |
| 2277 |
can figure out if there was a simple-declaration or not), there must |
| 2278 |
be an initializer, and only one object may be declared. When SIMPLE_OK |
| 2279 |
is true we are called from c_parser_selection_header. |
| 2280 |
|
| 2281 |
Returns the resulting declaration, if there was any with an initializer. |
| 2282 |
|
| 2283 |
declaration: |
| 2284 |
declaration-specifiers init-declarator-list[opt] ; |
| 2285 |
static_assert-declaration |
| 2286 |
|
| 2287 |
function-definition: |
| 2288 |
declaration-specifiers[opt] declarator declaration-list[opt] |
| 2289 |
compound-statement |
| 2290 |
|
| 2291 |
declaration-list: |
| 2292 |
declaration |
| 2293 |
declaration-list declaration |
| 2294 |
|
| 2295 |
init-declarator-list: |
| 2296 |
init-declarator |
| 2297 |
init-declarator-list , init-declarator |
| 2298 |
|
| 2299 |
init-declarator: |
| 2300 |
declarator simple-asm-expr[opt] gnu-attributes[opt] |
| 2301 |
declarator simple-asm-expr[opt] gnu-attributes[opt] = initializer |
| 2302 |
|
| 2303 |
simple-declaration: |
| 2304 |
attribute-specifier-sequence[opt] declaration-specifiers declarator |
| 2305 |
= initializer |
| 2306 |
|
| 2307 |
GNU extensions: |
| 2308 |
|
| 2309 |
nested-function-definition: |
| 2310 |
declaration-specifiers declarator declaration-list[opt] |
| 2311 |
compound-statement |
| 2312 |
|
| 2313 |
attribute ; |
| 2314 |
|
| 2315 |
Objective-C: |
| 2316 |
gnu-attributes objc-class-definition |
| 2317 |
gnu-attributes objc-category-definition |
| 2318 |
gnu-attributes objc-protocol-definition |
| 2319 |
|
| 2320 |
The simple-asm-expr and gnu-attributes are GNU extensions. |
| 2321 |
|
| 2322 |
This function does not handle __extension__; that is handled in its |
| 2323 |
callers. ??? Following the old parser, __extension__ may start |
| 2324 |
external declarations, declarations in functions and declarations |
| 2325 |
at the start of "for" loops, but not old-style parameter |
| 2326 |
declarations. |
| 2327 |
|
| 2328 |
C99 requires declaration specifiers in a function definition; the |
| 2329 |
absence is diagnosed through the diagnosis of implicit int. In GNU |
| 2330 |
C we also allow but diagnose declarations without declaration |
| 2331 |
specifiers, but only at top level (elsewhere they conflict with |
| 2332 |
other syntax). |
| 2333 |
|
| 2334 |
In Objective-C, declarations of the looping variable in a foreach |
| 2335 |
statement are exceptionally terminated by 'in' (for example, 'for |
| 2336 |
(NSObject *object in array) { ... }'). |
| 2337 |
|
| 2338 |
OpenMP: |
| 2339 |
|
| 2340 |
declaration: |
| 2341 |
threadprivate-directive |
| 2342 |
|
| 2343 |
GIMPLE: |
| 2344 |
|
| 2345 |
gimple-function-definition: |
| 2346 |
declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator |
| 2347 |
declaration-list[opt] compound-statement |
| 2348 |
|
| 2349 |
rtl-function-definition: |
| 2350 |
declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator |
| 2351 |
declaration-list[opt] compound-statement */ |
| 2352 |
|
| 2353 |
static tree |
| 2354 |
c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, |
| 2355 |
bool static_assert_ok, bool empty_ok, |
| 2356 |
bool nested, bool start_attr_ok, |
| 2357 |
bool simple_ok, |
| 2358 |
tree *objc_foreach_object_declaration |
| 2359 |
/* = NULL */, |
| 2360 |
vec<c_token> *omp_declare_simd_clauses |
| 2361 |
/* = NULL */, |
| 2362 |
bool have_attrs /* = false */, |
| 2363 |
tree attrs /* = NULL_TREE */, |
| 2364 |
struct oacc_routine_data *oacc_routine_data |
| 2365 |
/* = NULL */, |
| 2366 |
bool *fallthru_attr_p /* = NULL */) |
| 2367 |
{ |
| 2368 |
struct c_declspecs *specs; |
| 2369 |
tree prefix_attrs; |
| 2370 |
tree all_prefix_attrs; |
| 2371 |
bool diagnosed_no_specs = false; |
| 2372 |
location_t here = c_parser_peek_token (parser)->location; |
| 2373 |
tree result = NULL_TREE; |
| 2374 |
|
| 2375 |
add_debug_begin_stmt (c_parser_peek_token (parser)->location); |
| 2376 |
|
| 2377 |
if (static_assert_ok |
| 2378 |
&& c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
| 2379 |
{ |
| 2380 |
c_parser_static_assert_declaration (parser); |
| 2381 |
return result; |
| 2382 |
} |
| 2383 |
specs = build_null_declspecs (); |
| 2384 |
|
| 2385 |
/* Handle any standard attributes parsed in the caller. */ |
| 2386 |
if (have_attrs) |
| 2387 |
{ |
| 2388 |
declspecs_add_attrs (here, specs, attrs); |
| 2389 |
specs->non_std_attrs_seen_p = false; |
| 2390 |
} |
| 2391 |
|
| 2392 |
/* Try to detect an unknown type name when we have "A B" or "A *B". */ |
| 2393 |
if (c_parser_peek_token (parser)->type == CPP_NAME |
| 2394 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 2395 |
&& (c_parser_peek_2nd_token (parser)->type == CPP_NAME |
| 2396 |
|| c_parser_peek_2nd_token (parser)->type == CPP_MULT) |
| 2397 |
&& (!nested || !lookup_name (c_parser_peek_token (parser)->value))) |
| 2398 |
{ |
| 2399 |
tree name = c_parser_peek_token (parser)->value; |
| 2400 |
|
| 2401 |
/* Issue a warning about NAME being an unknown type name, perhaps |
| 2402 |
with some kind of hint. |
| 2403 |
If the user forgot a "struct" etc, suggest inserting |
| 2404 |
it. Otherwise, attempt to look for misspellings. */ |
| 2405 |
gcc_rich_location richloc (here); |
| 2406 |
if (tag_exists_p (RECORD_TYPE, name)) |
| 2407 |
{ |
| 2408 |
/* This is not C++ with its implicit typedef. */ |
| 2409 |
richloc.add_fixit_insert_before ("struct "); |
| 2410 |
error_at (&richloc, |
| 2411 |
"unknown type name %qE;" |
| 2412 |
" use %<struct%> keyword to refer to the type", |
| 2413 |
name); |
| 2414 |
} |
| 2415 |
else if (tag_exists_p (UNION_TYPE, name)) |
| 2416 |
{ |
| 2417 |
richloc.add_fixit_insert_before ("union "); |
| 2418 |
error_at (&richloc, |
| 2419 |
"unknown type name %qE;" |
| 2420 |
" use %<union%> keyword to refer to the type", |
| 2421 |
name); |
| 2422 |
} |
| 2423 |
else if (tag_exists_p (ENUMERAL_TYPE, name)) |
| 2424 |
{ |
| 2425 |
richloc.add_fixit_insert_before ("enum "); |
| 2426 |
error_at (&richloc, |
| 2427 |
"unknown type name %qE;" |
| 2428 |
" use %<enum%> keyword to refer to the type", |
| 2429 |
name); |
| 2430 |
} |
| 2431 |
else |
| 2432 |
{ |
| 2433 |
auto_diagnostic_group d; |
| 2434 |
name_hint hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME, |
| 2435 |
here); |
| 2436 |
if (const char *suggestion = hint.suggestion ()) |
| 2437 |
{ |
| 2438 |
richloc.add_fixit_replace (suggestion); |
| 2439 |
error_at (&richloc, |
| 2440 |
"unknown type name %qE; did you mean %qs?", |
| 2441 |
name, suggestion); |
| 2442 |
} |
| 2443 |
else |
| 2444 |
error_at (here, "unknown type name %qE", name); |
| 2445 |
} |
| 2446 |
|
| 2447 |
/* Parse declspecs normally to get a correct pointer type, but avoid |
| 2448 |
a further "fails to be a type name" error. Refuse nested functions |
| 2449 |
since it is not how the user likely wants us to recover. */ |
| 2450 |
c_parser_peek_token (parser)->type = CPP_KEYWORD; |
| 2451 |
c_parser_peek_token (parser)->keyword = RID_VOID; |
| 2452 |
c_parser_peek_token (parser)->value = error_mark_node; |
| 2453 |
fndef_ok = !nested; |
| 2454 |
} |
| 2455 |
|
| 2456 |
/* When there are standard attributes at the start of the |
| 2457 |
declaration (to apply to the entity being declared), an |
| 2458 |
init-declarator-list or function definition must be present. */ |
| 2459 |
if (c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 2460 |
have_attrs = true; |
| 2461 |
|
| 2462 |
c_parser_declspecs (parser, specs, true, true, start_attr_ok, |
| 2463 |
true, true, start_attr_ok, true, cla_nonabstract_decl); |
| 2464 |
if (parser->error) |
| 2465 |
{ |
| 2466 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 2467 |
return result; |
| 2468 |
} |
| 2469 |
if (nested && !specs->declspecs_seen_p) |
| 2470 |
{ |
| 2471 |
c_parser_error (parser, "expected declaration specifiers"); |
| 2472 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 2473 |
return result; |
| 2474 |
} |
| 2475 |
|
| 2476 |
finish_declspecs (specs); |
| 2477 |
bool gnu_auto_type_p = specs->typespec_word == cts_auto_type; |
| 2478 |
bool std_auto_type_p = specs->c23_auto_p; |
| 2479 |
bool any_auto_type_p = gnu_auto_type_p || std_auto_type_p; |
| 2480 |
gcc_assert (!(gnu_auto_type_p && std_auto_type_p)); |
| 2481 |
const char *auto_type_keyword = gnu_auto_type_p ? "__auto_type" : "auto"; |
| 2482 |
if (specs->constexpr_p) |
| 2483 |
{ |
| 2484 |
/* An underspecified declaration may not declare tags or members |
| 2485 |
or structures or unions; it is undefined behavior to declare |
| 2486 |
the members of an enumeration. Where the structure, union or |
| 2487 |
enumeration type is declared within an initializer, this is |
| 2488 |
diagnosed elsewhere. Diagnose here the case of declaring |
| 2489 |
such a type in the type specifiers of a constexpr |
| 2490 |
declaration. */ |
| 2491 |
switch (specs->typespec_kind) |
| 2492 |
{ |
| 2493 |
case ctsk_tagfirstref: |
| 2494 |
case ctsk_tagfirstref_attrs: |
| 2495 |
error_at (here, "%qT declared in underspecified object declaration", |
| 2496 |
specs->type); |
| 2497 |
break; |
| 2498 |
|
| 2499 |
case ctsk_tagdef: |
| 2500 |
error_at (here, "%qT defined in underspecified object declaration", |
| 2501 |
specs->type); |
| 2502 |
break; |
| 2503 |
|
| 2504 |
default: |
| 2505 |
break; |
| 2506 |
} |
| 2507 |
} |
| 2508 |
|
| 2509 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 2510 |
{ |
| 2511 |
bool handled_assume = false; |
| 2512 |
if (specs->attrs |
| 2513 |
&& !nested |
| 2514 |
&& specs->typespec_kind == ctsk_none |
| 2515 |
&& c_parser_handle_statement_omp_attributes (parser, specs->attrs, |
| 2516 |
NULL)) |
| 2517 |
{ |
| 2518 |
if (specs->attrs) |
| 2519 |
c_warn_unused_attributes (specs->attrs); |
| 2520 |
while (parser->in_omp_attribute_pragma) |
| 2521 |
{ |
| 2522 |
gcc_assert (c_parser_next_token_is (parser, CPP_PRAGMA)); |
| 2523 |
c_parser_pragma (parser, pragma_external, NULL, NULL_TREE); |
| 2524 |
} |
| 2525 |
c_parser_consume_token (parser); |
| 2526 |
return result; |
| 2527 |
} |
| 2528 |
if (specs->typespec_kind == ctsk_none |
| 2529 |
&& lookup_attribute ("gnu", "assume", specs->attrs)) |
| 2530 |
{ |
| 2531 |
handled_assume = true; |
| 2532 |
specs->attrs |
| 2533 |
= handle_assume_attribute (here, specs->attrs, nested); |
| 2534 |
} |
| 2535 |
if (any_auto_type_p) |
| 2536 |
error_at (here, "%qs in empty declaration", auto_type_keyword); |
| 2537 |
else if (specs->typespec_kind == ctsk_none |
| 2538 |
&& attribute_fallthrough_p (specs->attrs)) |
| 2539 |
{ |
| 2540 |
if (fallthru_attr_p != NULL) |
| 2541 |
*fallthru_attr_p = true; |
| 2542 |
if (nested) |
| 2543 |
{ |
| 2544 |
tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH, |
| 2545 |
void_type_node, 0); |
| 2546 |
add_stmt (fn); |
| 2547 |
} |
| 2548 |
else |
| 2549 |
pedwarn (here, OPT_Wattributes, |
| 2550 |
"%<fallthrough%> attribute at top level"); |
| 2551 |
} |
| 2552 |
else if (empty_ok |
| 2553 |
&& !(have_attrs && specs->non_std_attrs_seen_p) |
| 2554 |
&& !handled_assume) |
| 2555 |
shadow_tag (specs); |
| 2556 |
else |
| 2557 |
{ |
| 2558 |
shadow_tag_warned (specs, 1); |
| 2559 |
if (!handled_assume) |
| 2560 |
pedwarn (here, 0, "empty declaration"); |
| 2561 |
} |
| 2562 |
/* We still have to evaluate size expressions. */ |
| 2563 |
if (specs->expr) |
| 2564 |
add_stmt (fold_convert (void_type_node, specs->expr)); |
| 2565 |
c_parser_consume_token (parser); |
| 2566 |
if (oacc_routine_data) |
| 2567 |
c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false); |
| 2568 |
return result; |
| 2569 |
} |
| 2570 |
else if (specs->typespec_kind == ctsk_none |
| 2571 |
&& nested |
| 2572 |
/* Only parse __attribute__((musttail)) when called from |
| 2573 |
c_parser_compound_statement_nostart. This certainly isn't |
| 2574 |
a declaration in that case, but we don't do tentative parsing |
| 2575 |
of GNU attributes right now. */ |
| 2576 |
&& fallthru_attr_p |
| 2577 |
&& c_parser_next_token_is_keyword (parser, RID_RETURN)) |
| 2578 |
{ |
| 2579 |
attr_state astate = {}; |
| 2580 |
specs->attrs = c_parser_handle_musttail (parser, specs->attrs, astate); |
| 2581 |
if (astate.musttail_p) |
| 2582 |
{ |
| 2583 |
if (specs->attrs) |
| 2584 |
{ |
| 2585 |
auto_urlify_attributes sentinel; |
| 2586 |
warning_at (c_parser_peek_token (parser)->location, |
| 2587 |
OPT_Wattributes, |
| 2588 |
"attribute %<musttail%> mixed with other attributes " |
| 2589 |
"on %<return%> statement"); |
| 2590 |
} |
| 2591 |
c_parser_statement_after_labels (parser, NULL, NULL_TREE, NULL, |
| 2592 |
astate); |
| 2593 |
return result; |
| 2594 |
} |
| 2595 |
} |
| 2596 |
|
| 2597 |
/* Provide better error recovery. Note that a type name here is usually |
| 2598 |
better diagnosed as a redeclaration. */ |
| 2599 |
if (empty_ok |
| 2600 |
&& specs->typespec_kind == ctsk_tagdef |
| 2601 |
&& c_parser_next_token_starts_declspecs (parser) |
| 2602 |
&& !c_parser_next_token_is (parser, CPP_NAME)) |
| 2603 |
{ |
| 2604 |
c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); |
| 2605 |
parser->error = false; |
| 2606 |
shadow_tag_warned (specs, 1); |
| 2607 |
return result; |
| 2608 |
} |
| 2609 |
else if (c_dialect_objc () && !any_auto_type_p) |
| 2610 |
{ |
| 2611 |
/* Prefix attributes are an error on method decls. */ |
| 2612 |
switch (c_parser_peek_token (parser)->type) |
| 2613 |
{ |
| 2614 |
case CPP_PLUS: |
| 2615 |
case CPP_MINUS: |
| 2616 |
if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 2617 |
return result; |
| 2618 |
if (specs->attrs) |
| 2619 |
{ |
| 2620 |
warning_at (c_parser_peek_token (parser)->location, |
| 2621 |
OPT_Wattributes, |
| 2622 |
"prefix attributes are ignored for methods"); |
| 2623 |
specs->attrs = NULL_TREE; |
| 2624 |
} |
| 2625 |
if (fndef_ok) |
| 2626 |
c_parser_objc_method_definition (parser); |
| 2627 |
else |
| 2628 |
c_parser_objc_methodproto (parser); |
| 2629 |
return result; |
| 2630 |
break; |
| 2631 |
default: |
| 2632 |
break; |
| 2633 |
} |
| 2634 |
/* This is where we parse 'attributes @interface ...', |
| 2635 |
'attributes @implementation ...', 'attributes @protocol ...' |
| 2636 |
(where attributes could be, for example, __attribute__ |
| 2637 |
((deprecated)). |
| 2638 |
*/ |
| 2639 |
switch (c_parser_peek_token (parser)->keyword) |
| 2640 |
{ |
| 2641 |
case RID_AT_INTERFACE: |
| 2642 |
{ |
| 2643 |
if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 2644 |
return result; |
| 2645 |
c_parser_objc_class_definition (parser, specs->attrs); |
| 2646 |
return result; |
| 2647 |
} |
| 2648 |
break; |
| 2649 |
case RID_AT_IMPLEMENTATION: |
| 2650 |
{ |
| 2651 |
if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 2652 |
return result; |
| 2653 |
if (specs->attrs) |
| 2654 |
{ |
| 2655 |
warning_at (c_parser_peek_token (parser)->location, |
| 2656 |
OPT_Wattributes, |
| 2657 |
"prefix attributes are ignored for implementations"); |
| 2658 |
specs->attrs = NULL_TREE; |
| 2659 |
} |
| 2660 |
c_parser_objc_class_definition (parser, NULL_TREE); |
| 2661 |
return result; |
| 2662 |
} |
| 2663 |
break; |
| 2664 |
case RID_AT_PROTOCOL: |
| 2665 |
{ |
| 2666 |
if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 2667 |
return result; |
| 2668 |
c_parser_objc_protocol_definition (parser, specs->attrs); |
| 2669 |
return result; |
| 2670 |
} |
| 2671 |
break; |
| 2672 |
case RID_AT_ALIAS: |
| 2673 |
case RID_AT_CLASS: |
| 2674 |
case RID_AT_END: |
| 2675 |
case RID_AT_PROPERTY: |
| 2676 |
if (specs->attrs) |
| 2677 |
{ |
| 2678 |
c_parser_error (parser, "unexpected attribute"); |
| 2679 |
specs->attrs = NULL; |
| 2680 |
} |
| 2681 |
break; |
| 2682 |
default: |
| 2683 |
break; |
| 2684 |
} |
| 2685 |
} |
| 2686 |
else if (attribute_fallthrough_p (specs->attrs)) |
| 2687 |
warning_at (here, OPT_Wattributes, |
| 2688 |
"%<fallthrough%> attribute not followed by %<;%>"); |
| 2689 |
else if (lookup_attribute ("gnu", "assume", specs->attrs)) |
| 2690 |
warning_at (here, OPT_Wattributes, |
| 2691 |
"%<assume%> attribute not followed by %<;%>"); |
| 2692 |
|
| 2693 |
auto_vec<c_token> omp_declare_simd_attr_clauses; |
| 2694 |
c_parser_handle_directive_omp_attributes (specs->attrs, |
| 2695 |
omp_declare_simd_clauses, |
| 2696 |
&omp_declare_simd_attr_clauses); |
| 2697 |
pending_xref_error (); |
| 2698 |
prefix_attrs = specs->attrs; |
| 2699 |
all_prefix_attrs = prefix_attrs; |
| 2700 |
specs->attrs = NULL_TREE; |
| 2701 |
bool more_than_one_decl = false; |
| 2702 |
while (true) |
| 2703 |
{ |
| 2704 |
struct c_declarator *declarator; |
| 2705 |
bool dummy = false; |
| 2706 |
timevar_id_t tv; |
| 2707 |
tree fnbody = NULL_TREE; |
| 2708 |
tree underspec_name = NULL_TREE; |
| 2709 |
auto_vec<c_token> omp_dsimd_idattr_clauses; |
| 2710 |
/* Declaring either one or more declarators (in which case we |
| 2711 |
should diagnose if there were no declaration specifiers) or a |
| 2712 |
function definition (in which case the diagnostic for |
| 2713 |
implicit int suffices). */ |
| 2714 |
declarator = c_parser_declarator (parser, |
| 2715 |
specs->typespec_kind != ctsk_none, |
| 2716 |
C_DTR_NORMAL, &dummy); |
| 2717 |
if (declarator == NULL) |
| 2718 |
{ |
| 2719 |
if (omp_declare_simd_clauses) |
| 2720 |
c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE, |
| 2721 |
omp_declare_simd_clauses); |
| 2722 |
if (oacc_routine_data) |
| 2723 |
c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false); |
| 2724 |
/* This check is here purely to improve the diagnostic. */ |
| 2725 |
if (!simple_ok) |
| 2726 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 2727 |
return result; |
| 2728 |
} |
| 2729 |
if (flag_openmp || flag_openmp_simd) |
| 2730 |
{ |
| 2731 |
struct c_declarator *d = declarator; |
| 2732 |
while (d->kind != cdk_id) |
| 2733 |
d = d->declarator; |
| 2734 |
vec<c_token> *dummy = NULL; |
| 2735 |
c_parser_handle_directive_omp_attributes (d->u.id.attrs, dummy, |
| 2736 |
&omp_dsimd_idattr_clauses); |
| 2737 |
} |
| 2738 |
if (gnu_auto_type_p && declarator->kind != cdk_id) |
| 2739 |
{ |
| 2740 |
error_at (here, |
| 2741 |
"%<__auto_type%> requires a plain identifier" |
| 2742 |
" as declarator"); |
| 2743 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 2744 |
return result; |
| 2745 |
} |
| 2746 |
if (std_auto_type_p) |
| 2747 |
{ |
| 2748 |
struct c_declarator *d = declarator; |
| 2749 |
while (d->kind == cdk_attrs) |
| 2750 |
d = d->declarator; |
| 2751 |
if (d->kind != cdk_id) |
| 2752 |
{ |
| 2753 |
error_at (here, |
| 2754 |
"%<auto%> requires a plain identifier, possibly with" |
| 2755 |
" attributes, as declarator"); |
| 2756 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 2757 |
return result; |
| 2758 |
} |
| 2759 |
underspec_name = d->u.id.id; |
| 2760 |
} |
| 2761 |
else if (specs->constexpr_p) |
| 2762 |
{ |
| 2763 |
struct c_declarator *d = declarator; |
| 2764 |
while (d->kind != cdk_id) |
| 2765 |
d = d->declarator; |
| 2766 |
underspec_name = d->u.id.id; |
| 2767 |
} |
| 2768 |
if (c_parser_next_token_is (parser, CPP_EQ) |
| 2769 |
|| c_parser_next_token_is (parser, CPP_COMMA) |
| 2770 |
|| c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 2771 |
|| c_parser_next_token_is_keyword (parser, RID_ASM) |
| 2772 |
|| c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) |
| 2773 |
|| c_parser_next_token_is_keyword (parser, RID_IN)) |
| 2774 |
{ |
| 2775 |
tree asm_name = NULL_TREE; |
| 2776 |
tree postfix_attrs = NULL_TREE; |
| 2777 |
if (!diagnosed_no_specs && !specs->declspecs_seen_p) |
| 2778 |
{ |
| 2779 |
diagnosed_no_specs = true; |
| 2780 |
pedwarn (here, 0, "data definition has no type or storage class"); |
| 2781 |
} |
| 2782 |
/* Having seen a data definition, there cannot now be a |
| 2783 |
function definition. */ |
| 2784 |
fndef_ok = false; |
| 2785 |
if (c_parser_next_token_is_keyword (parser, RID_ASM)) |
| 2786 |
asm_name = c_parser_simple_asm_expr (parser); |
| 2787 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 2788 |
{ |
| 2789 |
postfix_attrs = c_parser_gnu_attributes (parser); |
| 2790 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 2791 |
{ |
| 2792 |
/* This means there is an attribute specifier after |
| 2793 |
the declarator in a function definition. Provide |
| 2794 |
some more information for the user. */ |
| 2795 |
error_at (here, "attributes should be specified before the " |
| 2796 |
"declarator in a function definition"); |
| 2797 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 2798 |
return result; |
| 2799 |
} |
| 2800 |
} |
| 2801 |
if (c_parser_next_token_is (parser, CPP_EQ)) |
| 2802 |
{ |
| 2803 |
tree d; |
| 2804 |
struct c_expr init; |
| 2805 |
location_t init_loc; |
| 2806 |
c_parser_consume_token (parser); |
| 2807 |
if (any_auto_type_p) |
| 2808 |
{ |
| 2809 |
init_loc = c_parser_peek_token (parser)->location; |
| 2810 |
rich_location richloc (line_table, init_loc); |
| 2811 |
unsigned int underspec_state = 0; |
| 2812 |
if (std_auto_type_p) |
| 2813 |
underspec_state = |
| 2814 |
start_underspecified_init (init_loc, underspec_name); |
| 2815 |
start_init (NULL_TREE, asm_name, |
| 2816 |
(global_bindings_p () |
| 2817 |
|| specs->storage_class == csc_static |
| 2818 |
|| specs->constexpr_p), |
| 2819 |
specs->constexpr_p, &richloc); |
| 2820 |
/* A parameter is initialized, which is invalid. Don't |
| 2821 |
attempt to instrument the initializer. */ |
| 2822 |
int flag_sanitize_save = flag_sanitize; |
| 2823 |
if (nested && !empty_ok) |
| 2824 |
flag_sanitize = 0; |
| 2825 |
init = c_parser_expr_no_commas (parser, NULL); |
| 2826 |
if (std_auto_type_p) |
| 2827 |
finish_underspecified_init (underspec_name, |
| 2828 |
underspec_state); |
| 2829 |
flag_sanitize = flag_sanitize_save; |
| 2830 |
if (gnu_auto_type_p |
| 2831 |
&& TREE_CODE (init.value) == COMPONENT_REF |
| 2832 |
&& DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1))) |
| 2833 |
error_at (here, |
| 2834 |
"%<__auto_type%> used with a bit-field" |
| 2835 |
" initializer"); |
| 2836 |
init = convert_lvalue_to_rvalue (init_loc, init, true, true, |
| 2837 |
true); |
| 2838 |
tree init_type = TREE_TYPE (init.value); |
| 2839 |
bool vm_type = c_type_variably_modified_p (init_type); |
| 2840 |
if (vm_type) |
| 2841 |
init.value = save_expr (init.value); |
| 2842 |
finish_init (); |
| 2843 |
specs->typespec_kind = ctsk_typeof; |
| 2844 |
specs->locations[cdw_typedef] = init_loc; |
| 2845 |
specs->typedef_p = true; |
| 2846 |
specs->type = init_type; |
| 2847 |
if (specs->postfix_attrs) |
| 2848 |
{ |
| 2849 |
/* Postfix [[]] attributes are valid with C23 |
| 2850 |
auto, although not with __auto_type, and |
| 2851 |
modify the type given by the initializer. */ |
| 2852 |
specs->postfix_attrs |
| 2853 |
= c_warn_type_attributes (specs->type, |
| 2854 |
specs->postfix_attrs); |
| 2855 |
decl_attributes (&specs->type, specs->postfix_attrs, 0); |
| 2856 |
specs->postfix_attrs = NULL_TREE; |
| 2857 |
} |
| 2858 |
if (vm_type) |
| 2859 |
{ |
| 2860 |
bool maybe_const = true; |
| 2861 |
tree type_expr = c_fully_fold (init.value, false, |
| 2862 |
&maybe_const); |
| 2863 |
specs->expr_const_operands &= maybe_const; |
| 2864 |
if (specs->expr) |
| 2865 |
specs->expr = build2 (COMPOUND_EXPR, |
| 2866 |
TREE_TYPE (type_expr), |
| 2867 |
specs->expr, type_expr); |
| 2868 |
else |
| 2869 |
specs->expr = type_expr; |
| 2870 |
} |
| 2871 |
d = start_decl (declarator, specs, true, |
| 2872 |
chainon (postfix_attrs, all_prefix_attrs)); |
| 2873 |
if (!d) |
| 2874 |
d = error_mark_node; |
| 2875 |
if (omp_declare_simd_clauses) |
| 2876 |
c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 2877 |
omp_declare_simd_clauses); |
| 2878 |
if (!omp_dsimd_idattr_clauses.is_empty ()) |
| 2879 |
c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 2880 |
&omp_dsimd_idattr_clauses); |
| 2881 |
} |
| 2882 |
else |
| 2883 |
{ |
| 2884 |
/* The declaration of the variable is in effect while |
| 2885 |
its initializer is parsed, except for a constexpr |
| 2886 |
variable. */ |
| 2887 |
init_loc = c_parser_peek_token (parser)->location; |
| 2888 |
rich_location richloc (line_table, init_loc); |
| 2889 |
unsigned int underspec_state = 0; |
| 2890 |
if (specs->constexpr_p) |
| 2891 |
underspec_state = |
| 2892 |
start_underspecified_init (init_loc, underspec_name); |
| 2893 |
d = start_decl (declarator, specs, true, |
| 2894 |
chainon (postfix_attrs, |
| 2895 |
all_prefix_attrs), |
| 2896 |
!specs->constexpr_p); |
| 2897 |
if (!d) |
| 2898 |
d = error_mark_node; |
| 2899 |
if (!specs->constexpr_p && omp_declare_simd_clauses) |
| 2900 |
c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 2901 |
omp_declare_simd_clauses); |
| 2902 |
if (!specs->constexpr_p |
| 2903 |
&& !omp_dsimd_idattr_clauses.is_empty ()) |
| 2904 |
c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 2905 |
&omp_dsimd_idattr_clauses); |
| 2906 |
start_init (d, asm_name, |
| 2907 |
TREE_STATIC (d) || specs->constexpr_p, |
| 2908 |
specs->constexpr_p, &richloc); |
| 2909 |
/* A parameter is initialized, which is invalid. Don't |
| 2910 |
attempt to instrument the initializer. */ |
| 2911 |
int flag_sanitize_save = flag_sanitize; |
| 2912 |
if (TREE_CODE (d) == PARM_DECL) |
| 2913 |
flag_sanitize = 0; |
| 2914 |
init = c_parser_initializer (parser, d); |
| 2915 |
flag_sanitize = flag_sanitize_save; |
| 2916 |
if (specs->constexpr_p) |
| 2917 |
{ |
| 2918 |
finish_underspecified_init (underspec_name, |
| 2919 |
underspec_state); |
| 2920 |
d = pushdecl (d); |
| 2921 |
if (omp_declare_simd_clauses) |
| 2922 |
c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 2923 |
omp_declare_simd_clauses); |
| 2924 |
if (!specs->constexpr_p |
| 2925 |
&& !omp_dsimd_idattr_clauses.is_empty ()) |
| 2926 |
c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 2927 |
&omp_dsimd_idattr_clauses); |
| 2928 |
} |
| 2929 |
finish_init (); |
| 2930 |
} |
| 2931 |
if (oacc_routine_data) |
| 2932 |
c_finish_oacc_routine (oacc_routine_data, d, false); |
| 2933 |
if (d != error_mark_node) |
| 2934 |
{ |
| 2935 |
maybe_warn_string_init (init_loc, TREE_TYPE (d), init); |
| 2936 |
finish_decl (d, init_loc, init.value, |
| 2937 |
init.original_type, asm_name); |
| 2938 |
result = d; |
| 2939 |
} |
| 2940 |
} |
| 2941 |
else |
| 2942 |
{ |
| 2943 |
if (any_auto_type_p || specs->constexpr_p) |
| 2944 |
{ |
| 2945 |
error_at (here, |
| 2946 |
"%qs requires an initialized data declaration", |
| 2947 |
any_auto_type_p ? auto_type_keyword : "constexpr"); |
| 2948 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 2949 |
return result; |
| 2950 |
} |
| 2951 |
|
| 2952 |
location_t lastloc = UNKNOWN_LOCATION; |
| 2953 |
tree attrs = chainon (postfix_attrs, all_prefix_attrs); |
| 2954 |
tree d = start_decl (declarator, specs, false, attrs, true, |
| 2955 |
&lastloc); |
| 2956 |
if (d && TREE_CODE (d) == FUNCTION_DECL) |
| 2957 |
{ |
| 2958 |
/* Find the innermost declarator that is neither cdk_id |
| 2959 |
nor cdk_attrs. */ |
| 2960 |
const struct c_declarator *decl = declarator; |
| 2961 |
const struct c_declarator *last_non_id_attrs = NULL; |
| 2962 |
|
| 2963 |
while (decl) |
| 2964 |
switch (decl->kind) |
| 2965 |
{ |
| 2966 |
case cdk_array: |
| 2967 |
case cdk_function: |
| 2968 |
case cdk_pointer: |
| 2969 |
last_non_id_attrs = decl; |
| 2970 |
decl = decl->declarator; |
| 2971 |
break; |
| 2972 |
|
| 2973 |
case cdk_attrs: |
| 2974 |
decl = decl->declarator; |
| 2975 |
break; |
| 2976 |
|
| 2977 |
case cdk_id: |
| 2978 |
decl = 0; |
| 2979 |
break; |
| 2980 |
|
| 2981 |
default: |
| 2982 |
gcc_unreachable (); |
| 2983 |
} |
| 2984 |
|
| 2985 |
/* If it exists and is cdk_function declaration whose |
| 2986 |
arguments have not been set yet, use its arguments. */ |
| 2987 |
if (last_non_id_attrs |
| 2988 |
&& last_non_id_attrs->kind == cdk_function) |
| 2989 |
{ |
| 2990 |
tree parms = last_non_id_attrs->u.arg_info->parms; |
| 2991 |
if (DECL_ARGUMENTS (d) == NULL_TREE |
| 2992 |
&& DECL_INITIAL (d) == NULL_TREE) |
| 2993 |
DECL_ARGUMENTS (d) = parms; |
| 2994 |
|
| 2995 |
warn_parm_array_mismatch (lastloc, d, parms); |
| 2996 |
} |
| 2997 |
} |
| 2998 |
if (omp_declare_simd_clauses |
| 2999 |
|| !omp_dsimd_idattr_clauses.is_empty ()) |
| 3000 |
{ |
| 3001 |
tree parms = NULL_TREE; |
| 3002 |
if (d && TREE_CODE (d) == FUNCTION_DECL) |
| 3003 |
{ |
| 3004 |
struct c_declarator *ce = declarator; |
| 3005 |
while (ce != NULL) |
| 3006 |
if (ce->kind == cdk_function) |
| 3007 |
{ |
| 3008 |
parms = ce->u.arg_info->parms; |
| 3009 |
break; |
| 3010 |
} |
| 3011 |
else |
| 3012 |
ce = ce->declarator; |
| 3013 |
} |
| 3014 |
if (parms) |
| 3015 |
temp_store_parm_decls (d, parms); |
| 3016 |
if (omp_declare_simd_clauses) |
| 3017 |
c_finish_omp_declare_simd (parser, d, parms, |
| 3018 |
omp_declare_simd_clauses); |
| 3019 |
if (!specs->constexpr_p |
| 3020 |
&& !omp_dsimd_idattr_clauses.is_empty ()) |
| 3021 |
c_finish_omp_declare_simd (parser, d, parms, |
| 3022 |
&omp_dsimd_idattr_clauses); |
| 3023 |
if (parms) |
| 3024 |
temp_pop_parm_decls (); |
| 3025 |
} |
| 3026 |
if (oacc_routine_data) |
| 3027 |
c_finish_oacc_routine (oacc_routine_data, d, false); |
| 3028 |
if (d) |
| 3029 |
finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, |
| 3030 |
NULL_TREE, asm_name); |
| 3031 |
|
| 3032 |
if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 3033 |
{ |
| 3034 |
if (d) |
| 3035 |
*objc_foreach_object_declaration = d; |
| 3036 |
else |
| 3037 |
*objc_foreach_object_declaration = error_mark_node; |
| 3038 |
} |
| 3039 |
} |
| 3040 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 3041 |
{ |
| 3042 |
more_than_one_decl = true; |
| 3043 |
if (any_auto_type_p || specs->constexpr_p) |
| 3044 |
{ |
| 3045 |
error_at (here, |
| 3046 |
"%qs may only be used with a single declarator", |
| 3047 |
any_auto_type_p ? auto_type_keyword : "constexpr"); |
| 3048 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 3049 |
return result; |
| 3050 |
} |
| 3051 |
c_parser_consume_token (parser); |
| 3052 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 3053 |
all_prefix_attrs = chainon (c_parser_gnu_attributes (parser), |
| 3054 |
prefix_attrs); |
| 3055 |
else |
| 3056 |
all_prefix_attrs = prefix_attrs; |
| 3057 |
continue; |
| 3058 |
} |
| 3059 |
else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 3060 |
{ |
| 3061 |
if (!simple_ok) |
| 3062 |
c_parser_consume_token (parser); |
| 3063 |
return result; |
| 3064 |
} |
| 3065 |
else if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 3066 |
{ |
| 3067 |
/* This can only happen in Objective-C: we found the |
| 3068 |
'in' that terminates the declaration inside an |
| 3069 |
Objective-C foreach statement. Do not consume the |
| 3070 |
token, so that the caller can use it to determine |
| 3071 |
that this indeed is a foreach context. */ |
| 3072 |
return result; |
| 3073 |
} |
| 3074 |
else |
| 3075 |
{ |
| 3076 |
if (!simple_ok) |
| 3077 |
{ |
| 3078 |
c_parser_error (parser, "expected %<,%> or %<;%>"); |
| 3079 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 3080 |
} |
| 3081 |
/* It's not valid to use if (int i = 2, j = 3). */ |
| 3082 |
else if (more_than_one_decl) |
| 3083 |
error_at (here, "declaration in condition can only declare " |
| 3084 |
"a single object"); |
| 3085 |
return result; |
| 3086 |
} |
| 3087 |
} |
| 3088 |
else if (any_auto_type_p || specs->constexpr_p) |
| 3089 |
{ |
| 3090 |
error_at (here, |
| 3091 |
"%qs requires an initialized data declaration", |
| 3092 |
any_auto_type_p ? auto_type_keyword : "constexpr"); |
| 3093 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 3094 |
return result; |
| 3095 |
} |
| 3096 |
else if (!fndef_ok) |
| 3097 |
{ |
| 3098 |
if (simple_ok && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3099 |
/* Let c_parser_selection_header emit the error. */; |
| 3100 |
else |
| 3101 |
{ |
| 3102 |
c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " |
| 3103 |
"%<asm%> or %<__attribute__%>"); |
| 3104 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 3105 |
} |
| 3106 |
return result; |
| 3107 |
} |
| 3108 |
/* Function definition (nested or otherwise). */ |
| 3109 |
if (nested) |
| 3110 |
{ |
| 3111 |
pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions"); |
| 3112 |
c_push_function_context (); |
| 3113 |
} |
| 3114 |
if (!start_function (specs, declarator, all_prefix_attrs)) |
| 3115 |
{ |
| 3116 |
/* At this point we've consumed: |
| 3117 |
declaration-specifiers declarator |
| 3118 |
and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON, |
| 3119 |
RID_ASM, RID_ATTRIBUTE, or RID_IN, |
| 3120 |
but the |
| 3121 |
declaration-specifiers declarator |
| 3122 |
aren't grokkable as a function definition, so we have |
| 3123 |
an error. */ |
| 3124 |
gcc_assert (!c_parser_next_token_is (parser, CPP_SEMICOLON)); |
| 3125 |
if (c_parser_next_token_starts_declspecs (parser)) |
| 3126 |
{ |
| 3127 |
/* If we have |
| 3128 |
declaration-specifiers declarator decl-specs |
| 3129 |
then assume we have a missing semicolon, which would |
| 3130 |
give us: |
| 3131 |
declaration-specifiers declarator decl-specs |
| 3132 |
^ |
| 3133 |
; |
| 3134 |
<~~~~~~~~~ declaration ~~~~~~~~~~> |
| 3135 |
Use c_parser_require to get an error with a fix-it hint. */ |
| 3136 |
c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 3137 |
parser->error = false; |
| 3138 |
} |
| 3139 |
else |
| 3140 |
{ |
| 3141 |
/* This can appear in many cases looking nothing like a |
| 3142 |
function definition, so we don't give a more specific |
| 3143 |
error suggesting there was one. */ |
| 3144 |
c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " |
| 3145 |
"or %<__attribute__%>"); |
| 3146 |
} |
| 3147 |
if (nested) |
| 3148 |
c_pop_function_context (); |
| 3149 |
break; |
| 3150 |
} |
| 3151 |
|
| 3152 |
if (DECL_DECLARED_INLINE_P (current_function_decl)) |
| 3153 |
tv = TV_PARSE_INLINE; |
| 3154 |
else |
| 3155 |
tv = TV_PARSE_FUNC; |
| 3156 |
auto_timevar at (g_timer, tv); |
| 3157 |
|
| 3158 |
/* Parse old-style parameter declarations. ??? Attributes are |
| 3159 |
not allowed to start declaration specifiers here because of a |
| 3160 |
syntax conflict between a function declaration with attribute |
| 3161 |
suffix and a function definition with an attribute prefix on |
| 3162 |
first old-style parameter declaration. Following the old |
| 3163 |
parser, they are not accepted on subsequent old-style |
| 3164 |
parameter declarations either. However, there is no |
| 3165 |
ambiguity after the first declaration, nor indeed on the |
| 3166 |
first as long as we don't allow postfix attributes after a |
| 3167 |
declarator with a nonempty identifier list in a definition; |
| 3168 |
and postfix attributes have never been accepted here in |
| 3169 |
function definitions either. */ |
| 3170 |
int save_debug_nonbind_markers_p = debug_nonbind_markers_p; |
| 3171 |
debug_nonbind_markers_p = 0; |
| 3172 |
c_parser_maybe_reclassify_token (parser); |
| 3173 |
while (c_parser_next_token_is_not (parser, CPP_EOF) |
| 3174 |
&& c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) |
| 3175 |
c_parser_declaration_or_fndef (parser, false, false, false, |
| 3176 |
true, false, false); |
| 3177 |
debug_nonbind_markers_p = save_debug_nonbind_markers_p; |
| 3178 |
store_parm_decls (); |
| 3179 |
if (omp_declare_simd_clauses) |
| 3180 |
c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, |
| 3181 |
omp_declare_simd_clauses); |
| 3182 |
if (!omp_dsimd_idattr_clauses.is_empty ()) |
| 3183 |
c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, |
| 3184 |
&omp_dsimd_idattr_clauses); |
| 3185 |
if (oacc_routine_data) |
| 3186 |
c_finish_oacc_routine (oacc_routine_data, current_function_decl, true); |
| 3187 |
location_t startloc = c_parser_peek_token (parser)->location; |
| 3188 |
DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus |
| 3189 |
= startloc; |
| 3190 |
location_t endloc = startloc; |
| 3191 |
|
| 3192 |
/* If the definition was marked with __RTL, use the RTL parser now, |
| 3193 |
consuming the function body. */ |
| 3194 |
if (specs->declspec_il == cdil_rtl) |
| 3195 |
{ |
| 3196 |
endloc = c_parser_parse_rtl_body (parser, specs->gimple_or_rtl_pass); |
| 3197 |
|
| 3198 |
/* Normally, store_parm_decls sets next_is_function_body, |
| 3199 |
anticipating a function body. We need a push_scope/pop_scope |
| 3200 |
pair to flush out this state, or subsequent function parsing |
| 3201 |
will go wrong. */ |
| 3202 |
push_scope (); |
| 3203 |
pop_scope (); |
| 3204 |
|
| 3205 |
finish_function (endloc); |
| 3206 |
return result; |
| 3207 |
} |
| 3208 |
/* If the definition was marked with __GIMPLE then parse the |
| 3209 |
function body as GIMPLE. */ |
| 3210 |
else if (specs->declspec_il != cdil_none) |
| 3211 |
{ |
| 3212 |
bool saved = in_late_binary_op; |
| 3213 |
in_late_binary_op = true; |
| 3214 |
c_parser_parse_gimple_body (parser, specs->gimple_or_rtl_pass, |
| 3215 |
specs->declspec_il, |
| 3216 |
specs->entry_bb_count); |
| 3217 |
in_late_binary_op = saved; |
| 3218 |
} |
| 3219 |
else |
| 3220 |
fnbody = c_parser_compound_statement (parser, &endloc); |
| 3221 |
tree fndecl = current_function_decl; |
| 3222 |
if (nested) |
| 3223 |
{ |
| 3224 |
tree decl = current_function_decl; |
| 3225 |
/* Mark nested functions as needing static-chain initially. |
| 3226 |
lower_nested_functions will recompute it but the |
| 3227 |
DECL_STATIC_CHAIN flag is also used before that happens, |
| 3228 |
by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ |
| 3229 |
DECL_STATIC_CHAIN (decl) = 1; |
| 3230 |
add_stmt (fnbody); |
| 3231 |
finish_function (endloc); |
| 3232 |
c_pop_function_context (); |
| 3233 |
add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); |
| 3234 |
} |
| 3235 |
else |
| 3236 |
{ |
| 3237 |
if (fnbody) |
| 3238 |
add_stmt (fnbody); |
| 3239 |
finish_function (endloc); |
| 3240 |
} |
| 3241 |
/* Get rid of the empty stmt list for GIMPLE/RTL. */ |
| 3242 |
if (specs->declspec_il != cdil_none) |
| 3243 |
DECL_SAVED_TREE (fndecl) = NULL_TREE; |
| 3244 |
|
| 3245 |
break; |
| 3246 |
} |
| 3247 |
|
| 3248 |
return result; |
| 3249 |
} |
| 3250 |
|
| 3251 |
/* Parse an asm-definition (asm() outside a function body). This is a |
| 3252 |
GNU extension. |
| 3253 |
|
| 3254 |
asm-definition: |
| 3255 |
simple-asm-expr ; |
| 3256 |
asm ( toplevel-asm-argument ) ; |
| 3257 |
|
| 3258 |
toplevel-asm-argument: |
| 3259 |
asm-string-literal |
| 3260 |
asm-string-literal : asm-operands[opt] |
| 3261 |
asm-string-literal : asm-operands[opt] : asm-operands[opt] |
| 3262 |
|
| 3263 |
The :: token is considered equivalent to two consecutive : tokens. */ |
| 3264 |
|
| 3265 |
static void |
| 3266 |
c_parser_asm_definition (c_parser *parser) |
| 3267 |
{ |
| 3268 |
location_t asm_loc = c_parser_peek_token (parser)->location; |
| 3269 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
| 3270 |
c_parser_consume_token (parser); |
| 3271 |
matching_parens parens; |
| 3272 |
tree asm_str = NULL_TREE; |
| 3273 |
tree outputs = NULL_TREE, inputs = NULL_TREE; |
| 3274 |
if (!parens.require_open (parser)) |
| 3275 |
goto done; |
| 3276 |
asm_str = c_parser_asm_string_literal (parser); |
| 3277 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3278 |
{ |
| 3279 |
parens.require_close (parser); |
| 3280 |
goto done; |
| 3281 |
} |
| 3282 |
for (int section = 0; section < 2; ++section) |
| 3283 |
{ |
| 3284 |
if (c_parser_next_token_is (parser, CPP_SCOPE)) |
| 3285 |
{ |
| 3286 |
++section; |
| 3287 |
if (section == 2) |
| 3288 |
{ |
| 3289 |
c_parser_error (parser, "expected %<)%>"); |
| 3290 |
error_close_paren: |
| 3291 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 3292 |
asm_str = NULL_TREE; |
| 3293 |
goto done; |
| 3294 |
} |
| 3295 |
c_parser_consume_token (parser); |
| 3296 |
} |
| 3297 |
else if (!c_parser_require (parser, CPP_COLON, |
| 3298 |
"expected %<:%> or %<)%>", |
| 3299 |
UNKNOWN_LOCATION, false)) |
| 3300 |
goto error_close_paren; |
| 3301 |
if (!c_parser_next_token_is (parser, CPP_COLON) |
| 3302 |
&& !c_parser_next_token_is (parser, CPP_SCOPE) |
| 3303 |
&& !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3304 |
{ |
| 3305 |
if (section) |
| 3306 |
inputs = c_parser_asm_operands (parser); |
| 3307 |
else |
| 3308 |
outputs = c_parser_asm_operands (parser); |
| 3309 |
} |
| 3310 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3311 |
break; |
| 3312 |
} |
| 3313 |
|
| 3314 |
if (!parens.require_close (parser)) |
| 3315 |
{ |
| 3316 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 3317 |
asm_str = NULL_TREE; |
| 3318 |
} |
| 3319 |
|
| 3320 |
if (asm_str) |
| 3321 |
asm_str = build_asm_expr (asm_loc, asm_str, outputs, inputs, |
| 3322 |
NULL_TREE, NULL_TREE, false, false); |
| 3323 |
done: |
| 3324 |
if (asm_str) |
| 3325 |
symtab->finalize_toplevel_asm (asm_str); |
| 3326 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 3327 |
} |
| 3328 |
|
| 3329 |
/* Parse a static assertion (C11 6.7.10). |
| 3330 |
|
| 3331 |
static_assert-declaration: |
| 3332 |
static_assert-declaration-no-semi ; |
| 3333 |
*/ |
| 3334 |
|
| 3335 |
static void |
| 3336 |
c_parser_static_assert_declaration (c_parser *parser) |
| 3337 |
{ |
| 3338 |
c_parser_static_assert_declaration_no_semi (parser); |
| 3339 |
if (parser->error |
| 3340 |
|| !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 3341 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 3342 |
} |
| 3343 |
|
| 3344 |
/* Parse a static assertion (C11 6.7.10), without the trailing |
| 3345 |
semicolon. |
| 3346 |
|
| 3347 |
static_assert-declaration-no-semi: |
| 3348 |
_Static_assert ( constant-expression , string-literal ) |
| 3349 |
|
| 3350 |
C23: |
| 3351 |
static_assert-declaration-no-semi: |
| 3352 |
_Static_assert ( constant-expression ) |
| 3353 |
*/ |
| 3354 |
|
| 3355 |
static void |
| 3356 |
c_parser_static_assert_declaration_no_semi (c_parser *parser) |
| 3357 |
{ |
| 3358 |
location_t assert_loc, value_loc; |
| 3359 |
tree value; |
| 3360 |
tree string = NULL_TREE; |
| 3361 |
|
| 3362 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)); |
| 3363 |
tree spelling = c_parser_peek_token (parser)->value; |
| 3364 |
assert_loc = c_parser_peek_token (parser)->location; |
| 3365 |
if (flag_isoc99) |
| 3366 |
pedwarn_c99 (assert_loc, OPT_Wpedantic, |
| 3367 |
"ISO C99 does not support %qE", spelling); |
| 3368 |
else |
| 3369 |
pedwarn_c99 (assert_loc, OPT_Wpedantic, |
| 3370 |
"ISO C90 does not support %qE", spelling); |
| 3371 |
c_parser_consume_token (parser); |
| 3372 |
matching_parens parens; |
| 3373 |
if (!parens.require_open (parser)) |
| 3374 |
return; |
| 3375 |
location_t value_tok_loc = c_parser_peek_token (parser)->location; |
| 3376 |
value = convert_lvalue_to_rvalue (value_tok_loc, |
| 3377 |
c_parser_expr_no_commas (parser, NULL), |
| 3378 |
true, true).value; |
| 3379 |
value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc); |
| 3380 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 3381 |
{ |
| 3382 |
c_parser_consume_token (parser); |
| 3383 |
switch (c_parser_peek_token (parser)->type) |
| 3384 |
{ |
| 3385 |
case CPP_STRING: |
| 3386 |
case CPP_STRING16: |
| 3387 |
case CPP_STRING32: |
| 3388 |
case CPP_WSTRING: |
| 3389 |
case CPP_UTF8STRING: |
| 3390 |
string = c_parser_string_literal (parser, false, true).value; |
| 3391 |
break; |
| 3392 |
default: |
| 3393 |
c_parser_error (parser, "expected string literal"); |
| 3394 |
return; |
| 3395 |
} |
| 3396 |
} |
| 3397 |
else if (flag_isoc11) |
| 3398 |
/* If pedantic for pre-C11, the use of _Static_assert itself will |
| 3399 |
have been diagnosed, so do not also diagnose the use of this |
| 3400 |
new C23 feature of _Static_assert. */ |
| 3401 |
pedwarn_c11 (assert_loc, OPT_Wpedantic, |
| 3402 |
"ISO C11 does not support omitting the string in " |
| 3403 |
"%qE", spelling); |
| 3404 |
parens.require_close (parser); |
| 3405 |
|
| 3406 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) |
| 3407 |
{ |
| 3408 |
error_at (value_loc, "expression in static assertion is not an integer"); |
| 3409 |
return; |
| 3410 |
} |
| 3411 |
if (TREE_CODE (value) != INTEGER_CST) |
| 3412 |
{ |
| 3413 |
value = c_fully_fold (value, false, NULL); |
| 3414 |
/* Strip no-op conversions. */ |
| 3415 |
STRIP_TYPE_NOPS (value); |
| 3416 |
if (TREE_CODE (value) == INTEGER_CST) |
| 3417 |
pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion " |
| 3418 |
"is not an integer constant expression"); |
| 3419 |
} |
| 3420 |
if (TREE_CODE (value) != INTEGER_CST) |
| 3421 |
{ |
| 3422 |
error_at (value_loc, "expression in static assertion is not constant"); |
| 3423 |
return; |
| 3424 |
} |
| 3425 |
constant_expression_warning (value); |
| 3426 |
if (integer_zerop (value)) |
| 3427 |
{ |
| 3428 |
if (string) |
| 3429 |
error_at (assert_loc, "static assertion failed: %E", string); |
| 3430 |
else |
| 3431 |
error_at (assert_loc, "static assertion failed"); |
| 3432 |
} |
| 3433 |
} |
| 3434 |
|
| 3435 |
/* Parse some declaration specifiers (possibly none) (C90 6.5, C99 |
| 3436 |
6.7, C11 6.7), adding them to SPECS (which may already include some). |
| 3437 |
Storage class specifiers are accepted iff SCSPEC_OK; type |
| 3438 |
specifiers are accepted iff TYPESPEC_OK; alignment specifiers are |
| 3439 |
accepted iff ALIGNSPEC_OK; gnu-attributes are accepted at the start |
| 3440 |
iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK. In |
| 3441 |
addition to the syntax shown, standard attributes are accepted at |
| 3442 |
the start iff START_STD_ATTR_OK and at the end iff END_STD_ATTR_OK; |
| 3443 |
unlike gnu-attributes, they are not accepted in the middle of the |
| 3444 |
list. (This combines various different syntax productions in the C |
| 3445 |
standard, and in some cases gnu-attributes and standard attributes |
| 3446 |
at the start may already have been parsed before this function is |
| 3447 |
called.) |
| 3448 |
|
| 3449 |
declaration-specifiers: |
| 3450 |
storage-class-specifier declaration-specifiers[opt] |
| 3451 |
type-specifier declaration-specifiers[opt] |
| 3452 |
type-qualifier declaration-specifiers[opt] |
| 3453 |
function-specifier declaration-specifiers[opt] |
| 3454 |
alignment-specifier declaration-specifiers[opt] |
| 3455 |
|
| 3456 |
Function specifiers (inline) are from C99, and are currently |
| 3457 |
handled as storage class specifiers, as is __thread. Alignment |
| 3458 |
specifiers are from C11. |
| 3459 |
|
| 3460 |
C90 6.5.1, C99 6.7.1, C11 6.7.1: |
| 3461 |
storage-class-specifier: |
| 3462 |
typedef |
| 3463 |
extern |
| 3464 |
static |
| 3465 |
auto |
| 3466 |
register |
| 3467 |
_Thread_local |
| 3468 |
|
| 3469 |
(_Thread_local is new in C11.) |
| 3470 |
|
| 3471 |
C99 6.7.4, C11 6.7.4: |
| 3472 |
function-specifier: |
| 3473 |
inline |
| 3474 |
_Noreturn |
| 3475 |
|
| 3476 |
(_Noreturn is new in C11.) |
| 3477 |
|
| 3478 |
C90 6.5.2, C99 6.7.2, C11 6.7.2: |
| 3479 |
type-specifier: |
| 3480 |
void |
| 3481 |
char |
| 3482 |
short |
| 3483 |
int |
| 3484 |
long |
| 3485 |
float |
| 3486 |
double |
| 3487 |
signed |
| 3488 |
unsigned |
| 3489 |
_Bool |
| 3490 |
_Complex |
| 3491 |
[_Imaginary removed in C99 TC2] |
| 3492 |
_BitInt ( constant-expression ) |
| 3493 |
struct-or-union-specifier |
| 3494 |
enum-specifier |
| 3495 |
typedef-name |
| 3496 |
atomic-type-specifier |
| 3497 |
|
| 3498 |
(_Bool and _Complex are new in C99.) |
| 3499 |
(atomic-type-specifier is new in C11.) |
| 3500 |
(_BitInt is new in C23.) |
| 3501 |
|
| 3502 |
C90 6.5.3, C99 6.7.3, C11 6.7.3: |
| 3503 |
|
| 3504 |
type-qualifier: |
| 3505 |
const |
| 3506 |
restrict |
| 3507 |
volatile |
| 3508 |
address-space-qualifier |
| 3509 |
_Atomic |
| 3510 |
|
| 3511 |
(restrict is new in C99.) |
| 3512 |
(_Atomic is new in C11.) |
| 3513 |
|
| 3514 |
GNU extensions: |
| 3515 |
|
| 3516 |
declaration-specifiers: |
| 3517 |
gnu-attributes declaration-specifiers[opt] |
| 3518 |
|
| 3519 |
type-qualifier: |
| 3520 |
address-space |
| 3521 |
|
| 3522 |
address-space: |
| 3523 |
identifier recognized by the target |
| 3524 |
|
| 3525 |
storage-class-specifier: |
| 3526 |
__thread |
| 3527 |
|
| 3528 |
type-specifier: |
| 3529 |
typeof-specifier |
| 3530 |
__auto_type |
| 3531 |
__intN |
| 3532 |
_Decimal32 |
| 3533 |
_Decimal64 |
| 3534 |
_Decimal128 |
| 3535 |
_Fract |
| 3536 |
_Accum |
| 3537 |
_Sat |
| 3538 |
|
| 3539 |
(_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037: |
| 3540 |
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf) |
| 3541 |
|
| 3542 |
atomic-type-specifier |
| 3543 |
_Atomic ( type-name ) |
| 3544 |
|
| 3545 |
Objective-C: |
| 3546 |
|
| 3547 |
type-specifier: |
| 3548 |
class-name objc-protocol-refs[opt] |
| 3549 |
typedef-name objc-protocol-refs |
| 3550 |
objc-protocol-refs |
| 3551 |
*/ |
| 3552 |
|
| 3553 |
void |
| 3554 |
c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, |
| 3555 |
bool scspec_ok, bool typespec_ok, bool start_attr_ok, |
| 3556 |
bool alignspec_ok, bool auto_type_ok, |
| 3557 |
bool start_std_attr_ok, bool end_std_attr_ok, |
| 3558 |
enum c_lookahead_kind la) |
| 3559 |
{ |
| 3560 |
bool attrs_ok = start_attr_ok; |
| 3561 |
bool seen_type = specs->typespec_kind != ctsk_none; |
| 3562 |
|
| 3563 |
if (!typespec_ok) |
| 3564 |
gcc_assert (la == cla_prefer_id); |
| 3565 |
|
| 3566 |
if (start_std_attr_ok |
| 3567 |
&& c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 3568 |
{ |
| 3569 |
gcc_assert (!specs->non_std_attrs_seen_p); |
| 3570 |
location_t loc = c_parser_peek_token (parser)->location; |
| 3571 |
tree attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 3572 |
declspecs_add_attrs (loc, specs, attrs); |
| 3573 |
specs->non_std_attrs_seen_p = false; |
| 3574 |
} |
| 3575 |
|
| 3576 |
while (c_parser_next_token_is (parser, CPP_NAME) |
| 3577 |
|| c_parser_next_token_is (parser, CPP_KEYWORD) |
| 3578 |
|| (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) |
| 3579 |
{ |
| 3580 |
struct c_typespec t; |
| 3581 |
tree attrs; |
| 3582 |
tree align; |
| 3583 |
location_t loc = c_parser_peek_token (parser)->location; |
| 3584 |
|
| 3585 |
/* If we cannot accept a type, exit if the next token must start |
| 3586 |
one. Also, if we already have seen a tagged definition, |
| 3587 |
a typename would be an error anyway and likely the user |
| 3588 |
has simply forgotten a semicolon, so we exit. */ |
| 3589 |
if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef) |
| 3590 |
&& c_parser_next_tokens_start_typename (parser, la) |
| 3591 |
&& !c_parser_next_token_is_qualifier (parser) |
| 3592 |
&& !c_parser_next_token_is_keyword (parser, RID_ALIGNAS)) |
| 3593 |
break; |
| 3594 |
|
| 3595 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 3596 |
{ |
| 3597 |
c_token *name_token = c_parser_peek_token (parser); |
| 3598 |
tree value = name_token->value; |
| 3599 |
c_id_kind kind = name_token->id_kind; |
| 3600 |
|
| 3601 |
if (kind == C_ID_ADDRSPACE) |
| 3602 |
{ |
| 3603 |
addr_space_t as |
| 3604 |
= name_token->keyword - RID_FIRST_ADDR_SPACE; |
| 3605 |
declspecs_add_addrspace (name_token->location, specs, as); |
| 3606 |
c_parser_consume_token (parser); |
| 3607 |
attrs_ok = true; |
| 3608 |
continue; |
| 3609 |
} |
| 3610 |
|
| 3611 |
gcc_assert (!c_parser_next_token_is_qualifier (parser)); |
| 3612 |
|
| 3613 |
/* If we cannot accept a type, and the next token must start one, |
| 3614 |
exit. Do the same if we already have seen a tagged definition, |
| 3615 |
since it would be an error anyway and likely the user has simply |
| 3616 |
forgotten a semicolon. */ |
| 3617 |
if (seen_type || !c_parser_next_tokens_start_typename (parser, la)) |
| 3618 |
break; |
| 3619 |
|
| 3620 |
/* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or |
| 3621 |
a C_ID_CLASSNAME. */ |
| 3622 |
c_parser_consume_token (parser); |
| 3623 |
seen_type = true; |
| 3624 |
attrs_ok = true; |
| 3625 |
if (kind == C_ID_ID) |
| 3626 |
{ |
| 3627 |
auto_diagnostic_group d; |
| 3628 |
name_hint hint = lookup_name_fuzzy (value, FUZZY_LOOKUP_TYPENAME, |
| 3629 |
loc); |
| 3630 |
if (const char *suggestion = hint.suggestion ()) |
| 3631 |
{ |
| 3632 |
gcc_rich_location richloc (loc); |
| 3633 |
richloc.add_fixit_replace (suggestion); |
| 3634 |
error_at (&richloc, |
| 3635 |
"unknown type name %qE; did you mean %qs?", |
| 3636 |
value, suggestion); |
| 3637 |
} |
| 3638 |
else |
| 3639 |
error_at (loc, "unknown type name %qE", value); |
| 3640 |
t.kind = ctsk_typedef; |
| 3641 |
t.spec = error_mark_node; |
| 3642 |
} |
| 3643 |
else if (kind == C_ID_TYPENAME |
| 3644 |
&& (!c_dialect_objc () |
| 3645 |
|| c_parser_next_token_is_not (parser, CPP_LESS))) |
| 3646 |
{ |
| 3647 |
t.kind = ctsk_typedef; |
| 3648 |
/* For a typedef name, record the meaning, not the name. |
| 3649 |
In case of 'foo foo, bar;'. */ |
| 3650 |
t.spec = lookup_name (value); |
| 3651 |
} |
| 3652 |
else |
| 3653 |
{ |
| 3654 |
tree proto = NULL_TREE; |
| 3655 |
gcc_assert (c_dialect_objc ()); |
| 3656 |
t.kind = ctsk_objc; |
| 3657 |
if (c_parser_next_token_is (parser, CPP_LESS)) |
| 3658 |
proto = c_parser_objc_protocol_refs (parser); |
| 3659 |
t.spec = objc_get_protocol_qualified_type (value, proto); |
| 3660 |
} |
| 3661 |
t.expr = NULL_TREE; |
| 3662 |
t.expr_const_operands = true; |
| 3663 |
t.has_enum_type_specifier = false; |
| 3664 |
declspecs_add_type (name_token->location, specs, t); |
| 3665 |
continue; |
| 3666 |
} |
| 3667 |
if (c_parser_next_token_is (parser, CPP_LESS)) |
| 3668 |
{ |
| 3669 |
/* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - |
| 3670 |
[email protected]. */ |
| 3671 |
tree proto; |
| 3672 |
gcc_assert (c_dialect_objc ()); |
| 3673 |
if (!typespec_ok || seen_type) |
| 3674 |
break; |
| 3675 |
proto = c_parser_objc_protocol_refs (parser); |
| 3676 |
t.kind = ctsk_objc; |
| 3677 |
t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); |
| 3678 |
t.expr = NULL_TREE; |
| 3679 |
t.expr_const_operands = true; |
| 3680 |
t.has_enum_type_specifier = false; |
| 3681 |
declspecs_add_type (loc, specs, t); |
| 3682 |
continue; |
| 3683 |
} |
| 3684 |
gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); |
| 3685 |
switch (c_parser_peek_token (parser)->keyword) |
| 3686 |
{ |
| 3687 |
case RID_STATIC: |
| 3688 |
case RID_EXTERN: |
| 3689 |
case RID_REGISTER: |
| 3690 |
case RID_TYPEDEF: |
| 3691 |
case RID_INLINE: |
| 3692 |
case RID_NORETURN: |
| 3693 |
case RID_AUTO: |
| 3694 |
case RID_THREAD: |
| 3695 |
case RID_CONSTEXPR: |
| 3696 |
if (!scspec_ok) |
| 3697 |
goto out; |
| 3698 |
attrs_ok = true; |
| 3699 |
/* TODO: Distinguish between function specifiers (inline, noreturn) |
| 3700 |
and storage class specifiers, either here or in |
| 3701 |
declspecs_add_scspec. */ |
| 3702 |
declspecs_add_scspec (loc, specs, |
| 3703 |
c_parser_peek_token (parser)->value); |
| 3704 |
c_parser_consume_token (parser); |
| 3705 |
break; |
| 3706 |
case RID_AUTO_TYPE: |
| 3707 |
if (!auto_type_ok) |
| 3708 |
goto out; |
| 3709 |
/* Fall through. */ |
| 3710 |
case RID_UNSIGNED: |
| 3711 |
case RID_LONG: |
| 3712 |
case RID_SHORT: |
| 3713 |
case RID_SIGNED: |
| 3714 |
case RID_COMPLEX: |
| 3715 |
case RID_INT: |
| 3716 |
case RID_CHAR: |
| 3717 |
case RID_FLOAT: |
| 3718 |
case RID_DOUBLE: |
| 3719 |
case RID_VOID: |
| 3720 |
case RID_DFLOAT32: |
| 3721 |
case RID_DFLOAT64: |
| 3722 |
case RID_DFLOAT128: |
| 3723 |
case RID_DFLOAT64X: |
| 3724 |
CASE_RID_FLOATN_NX: |
| 3725 |
case RID_BOOL: |
| 3726 |
case RID_FRACT: |
| 3727 |
case RID_ACCUM: |
| 3728 |
case RID_SAT: |
| 3729 |
case RID_INT_N_0: |
| 3730 |
case RID_INT_N_1: |
| 3731 |
case RID_INT_N_2: |
| 3732 |
case RID_INT_N_3: |
| 3733 |
if (!typespec_ok) |
| 3734 |
goto out; |
| 3735 |
attrs_ok = true; |
| 3736 |
seen_type = true; |
| 3737 |
if (c_dialect_objc ()) |
| 3738 |
parser->objc_need_raw_identifier = true; |
| 3739 |
t.kind = ctsk_resword; |
| 3740 |
t.spec = c_parser_peek_token (parser)->value; |
| 3741 |
t.expr = NULL_TREE; |
| 3742 |
t.expr_const_operands = true; |
| 3743 |
t.has_enum_type_specifier = false; |
| 3744 |
declspecs_add_type (loc, specs, t); |
| 3745 |
c_parser_consume_token (parser); |
| 3746 |
break; |
| 3747 |
case RID_ENUM: |
| 3748 |
if (!typespec_ok) |
| 3749 |
goto out; |
| 3750 |
attrs_ok = true; |
| 3751 |
seen_type = true; |
| 3752 |
t = c_parser_enum_specifier (parser); |
| 3753 |
invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
| 3754 |
declspecs_add_type (loc, specs, t); |
| 3755 |
break; |
| 3756 |
case RID_STRUCT: |
| 3757 |
case RID_UNION: |
| 3758 |
if (!typespec_ok) |
| 3759 |
goto out; |
| 3760 |
attrs_ok = true; |
| 3761 |
seen_type = true; |
| 3762 |
t = c_parser_struct_or_union_specifier (parser); |
| 3763 |
invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
| 3764 |
declspecs_add_type (loc, specs, t); |
| 3765 |
break; |
| 3766 |
case RID_TYPEOF: |
| 3767 |
case RID_TYPEOF_UNQUAL: |
| 3768 |
/* ??? The old parser rejected typeof after other type |
| 3769 |
specifiers, but is a syntax error the best way of |
| 3770 |
handling this? */ |
| 3771 |
if (!typespec_ok || seen_type) |
| 3772 |
goto out; |
| 3773 |
attrs_ok = true; |
| 3774 |
seen_type = true; |
| 3775 |
t = c_parser_typeof_specifier (parser); |
| 3776 |
declspecs_add_type (loc, specs, t); |
| 3777 |
break; |
| 3778 |
case RID_BITINT: |
| 3779 |
if (!typespec_ok) |
| 3780 |
goto out; |
| 3781 |
else |
| 3782 |
{ |
| 3783 |
attrs_ok = true; |
| 3784 |
seen_type = true; |
| 3785 |
t.kind = ctsk_resword; |
| 3786 |
t.spec = c_parser_peek_token (parser)->value; |
| 3787 |
t.expr = error_mark_node; |
| 3788 |
t.expr_const_operands = true; |
| 3789 |
t.has_enum_type_specifier = false; |
| 3790 |
c_parser_consume_token (parser); |
| 3791 |
matching_parens parens; |
| 3792 |
if (parens.require_open (parser)) |
| 3793 |
{ |
| 3794 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 3795 |
t.expr = convert_lvalue_to_rvalue (loc, expr, true, |
| 3796 |
true).value; |
| 3797 |
parens.skip_until_found_close (parser); |
| 3798 |
} |
| 3799 |
declspecs_add_type (loc, specs, t); |
| 3800 |
} |
| 3801 |
break; |
| 3802 |
case RID_ATOMIC: |
| 3803 |
/* C parser handling of Objective-C constructs needs |
| 3804 |
checking for correct lvalue-to-rvalue conversions, and |
| 3805 |
the code in build_modify_expr handling various |
| 3806 |
Objective-C cases, and that in build_unary_op handling |
| 3807 |
Objective-C cases for increment / decrement, also needs |
| 3808 |
updating; uses of TYPE_MAIN_VARIANT in objc_compare_types |
| 3809 |
and objc_types_are_equivalent may also need updates. */ |
| 3810 |
if (c_dialect_objc ()) |
| 3811 |
sorry ("%<_Atomic%> in Objective-C"); |
| 3812 |
if (flag_isoc99) |
| 3813 |
pedwarn_c99 (loc, OPT_Wpedantic, |
| 3814 |
"ISO C99 does not support the %<_Atomic%> qualifier"); |
| 3815 |
else |
| 3816 |
pedwarn_c99 (loc, OPT_Wpedantic, |
| 3817 |
"ISO C90 does not support the %<_Atomic%> qualifier"); |
| 3818 |
attrs_ok = true; |
| 3819 |
tree value; |
| 3820 |
value = c_parser_peek_token (parser)->value; |
| 3821 |
c_parser_consume_token (parser); |
| 3822 |
if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 3823 |
{ |
| 3824 |
/* _Atomic ( type-name ). */ |
| 3825 |
seen_type = true; |
| 3826 |
c_parser_consume_token (parser); |
| 3827 |
struct c_type_name *type = c_parser_type_name (parser); |
| 3828 |
t.kind = ctsk_typeof; |
| 3829 |
t.spec = error_mark_node; |
| 3830 |
t.expr = NULL_TREE; |
| 3831 |
t.expr_const_operands = true; |
| 3832 |
t.has_enum_type_specifier = false; |
| 3833 |
if (type != NULL) |
| 3834 |
t.spec = groktypename (type, &t.expr, |
| 3835 |
&t.expr_const_operands); |
| 3836 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 3837 |
"expected %<)%>"); |
| 3838 |
if (t.spec != error_mark_node) |
| 3839 |
{ |
| 3840 |
if (TREE_CODE (t.spec) == ARRAY_TYPE) |
| 3841 |
error_at (loc, "%<_Atomic%>-qualified array type"); |
| 3842 |
else if (TREE_CODE (t.spec) == FUNCTION_TYPE) |
| 3843 |
error_at (loc, "%<_Atomic%>-qualified function type"); |
| 3844 |
else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED) |
| 3845 |
error_at (loc, "%<_Atomic%> applied to a qualified type"); |
| 3846 |
else |
| 3847 |
t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC); |
| 3848 |
} |
| 3849 |
declspecs_add_type (loc, specs, t); |
| 3850 |
} |
| 3851 |
else |
| 3852 |
declspecs_add_qual (loc, specs, value); |
| 3853 |
break; |
| 3854 |
case RID_CONST: |
| 3855 |
case RID_VOLATILE: |
| 3856 |
case RID_RESTRICT: |
| 3857 |
attrs_ok = true; |
| 3858 |
declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value); |
| 3859 |
c_parser_consume_token (parser); |
| 3860 |
break; |
| 3861 |
case RID_ATTRIBUTE: |
| 3862 |
if (!attrs_ok) |
| 3863 |
goto out; |
| 3864 |
attrs = c_parser_gnu_attributes (parser); |
| 3865 |
declspecs_add_attrs (loc, specs, attrs); |
| 3866 |
break; |
| 3867 |
case RID_ALIGNAS: |
| 3868 |
if (!alignspec_ok) |
| 3869 |
goto out; |
| 3870 |
align = c_parser_alignas_specifier (parser); |
| 3871 |
declspecs_add_alignas (loc, specs, align); |
| 3872 |
break; |
| 3873 |
case RID_GIMPLE: |
| 3874 |
if (! flag_gimple) |
| 3875 |
error_at (loc, "%<__GIMPLE%> only valid with %<-fgimple%>"); |
| 3876 |
c_parser_consume_token (parser); |
| 3877 |
specs->declspec_il = cdil_gimple; |
| 3878 |
specs->locations[cdw_gimple] = loc; |
| 3879 |
c_parser_gimple_or_rtl_pass_list (parser, specs); |
| 3880 |
break; |
| 3881 |
case RID_RTL: |
| 3882 |
c_parser_consume_token (parser); |
| 3883 |
specs->declspec_il = cdil_rtl; |
| 3884 |
specs->locations[cdw_rtl] = loc; |
| 3885 |
c_parser_gimple_or_rtl_pass_list (parser, specs); |
| 3886 |
break; |
| 3887 |
default: |
| 3888 |
goto out; |
| 3889 |
} |
| 3890 |
} |
| 3891 |
out: |
| 3892 |
if (end_std_attr_ok |
| 3893 |
&& c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 3894 |
specs->postfix_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 3895 |
} |
| 3896 |
|
| 3897 |
/* Complain about a non-CPP_NAME within an enumerator list. */ |
| 3898 |
|
| 3899 |
static void |
| 3900 |
report_bad_enum_name (c_parser *parser) |
| 3901 |
{ |
| 3902 |
if (!parser->error) |
| 3903 |
{ |
| 3904 |
c_token *token = c_parser_peek_token (parser); |
| 3905 |
switch (token->type) |
| 3906 |
{ |
| 3907 |
default: |
| 3908 |
break; |
| 3909 |
case CPP_CLOSE_BRACE: |
| 3910 |
/* Give a nicer error for "enum {}". */ |
| 3911 |
error_at (token->location, |
| 3912 |
"empty enum is invalid"); |
| 3913 |
parser->error = true; |
| 3914 |
return; |
| 3915 |
case CPP_KEYWORD: |
| 3916 |
/* Give a nicer error for attempts to use "true" and "false" |
| 3917 |
in enums with C23 onwards. */ |
| 3918 |
if (token->keyword == RID_FALSE |
| 3919 |
|| token->keyword == RID_TRUE) |
| 3920 |
{ |
| 3921 |
auto_diagnostic_group d; |
| 3922 |
error_at (token->location, |
| 3923 |
"cannot use keyword %qs as enumeration constant", |
| 3924 |
IDENTIFIER_POINTER (token->value)); |
| 3925 |
add_note_about_new_keyword (token->location, |
| 3926 |
token->value); |
| 3927 |
parser->error = true; |
| 3928 |
return; |
| 3929 |
} |
| 3930 |
break; |
| 3931 |
} |
| 3932 |
} |
| 3933 |
|
| 3934 |
/* Otherwise, a more generic error message. */ |
| 3935 |
c_parser_error (parser, "expected identifier"); |
| 3936 |
} |
| 3937 |
|
| 3938 |
/* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2). |
| 3939 |
|
| 3940 |
enum-specifier: |
| 3941 |
enum gnu-attributes[opt] identifier[opt] enum-type-specifier[opt] |
| 3942 |
{ enumerator-list } gnu-attributes[opt] |
| 3943 |
enum gnu-attributes[opt] identifier[opt] enum-type-specifier[opt] |
| 3944 |
{ enumerator-list , } gnu-attributes[opt] enum-type-specifier[opt] |
| 3945 |
enum gnu-attributes[opt] identifier |
| 3946 |
|
| 3947 |
The form with trailing comma is new in C99; enum-type-specifiers |
| 3948 |
are new in C23. The forms with gnu-attributes are GNU extensions. |
| 3949 |
In GNU C, we accept any expression without commas in the syntax |
| 3950 |
(assignment expressions, not just conditional expressions); |
| 3951 |
assignment expressions will be diagnosed as non-constant. |
| 3952 |
|
| 3953 |
enum-type-specifier: |
| 3954 |
: specifier-qualifier-list |
| 3955 |
|
| 3956 |
enumerator-list: |
| 3957 |
enumerator |
| 3958 |
enumerator-list , enumerator |
| 3959 |
|
| 3960 |
enumerator: |
| 3961 |
enumeration-constant attribute-specifier-sequence[opt] |
| 3962 |
enumeration-constant attribute-specifier-sequence[opt] |
| 3963 |
= constant-expression |
| 3964 |
|
| 3965 |
GNU Extensions: |
| 3966 |
|
| 3967 |
enumerator: |
| 3968 |
enumeration-constant attribute-specifier-sequence[opt] gnu-attributes[opt] |
| 3969 |
enumeration-constant attribute-specifier-sequence[opt] gnu-attributes[opt] |
| 3970 |
= constant-expression |
| 3971 |
|
| 3972 |
*/ |
| 3973 |
|
| 3974 |
static struct c_typespec |
| 3975 |
c_parser_enum_specifier (c_parser *parser) |
| 3976 |
{ |
| 3977 |
struct c_typespec ret; |
| 3978 |
bool have_std_attrs; |
| 3979 |
bool potential_nesting_p = false; |
| 3980 |
tree std_attrs = NULL_TREE; |
| 3981 |
tree attrs; |
| 3982 |
tree ident = NULL_TREE; |
| 3983 |
tree fixed_underlying_type = NULL_TREE; |
| 3984 |
location_t enum_loc; |
| 3985 |
location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 3986 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); |
| 3987 |
c_parser_consume_token (parser); |
| 3988 |
have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1); |
| 3989 |
if (have_std_attrs) |
| 3990 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 3991 |
attrs = c_parser_gnu_attributes (parser); |
| 3992 |
enum_loc = c_parser_peek_token (parser)->location; |
| 3993 |
/* Set the location in case we create a decl now. */ |
| 3994 |
c_parser_set_source_position_from_token (c_parser_peek_token (parser)); |
| 3995 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 3996 |
{ |
| 3997 |
ident = c_parser_peek_token (parser)->value; |
| 3998 |
ident_loc = c_parser_peek_token (parser)->location; |
| 3999 |
enum_loc = ident_loc; |
| 4000 |
c_parser_consume_token (parser); |
| 4001 |
} |
| 4002 |
if (c_parser_next_token_is (parser, CPP_COLON) |
| 4003 |
/* Distinguish an enum-type-specifier from a bit-field |
| 4004 |
declaration of the form "enum e : constant-expression;". */ |
| 4005 |
&& c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 4006 |
{ |
| 4007 |
pedwarn_c11 (enum_loc, OPT_Wpedantic, |
| 4008 |
"ISO C does not support specifying %<enum%> underlying " |
| 4009 |
"types before C23"); |
| 4010 |
if (ident) |
| 4011 |
{ |
| 4012 |
/* The tag is in scope during the enum-type-specifier (which |
| 4013 |
may refer to the tag inside typeof). */ |
| 4014 |
ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident, |
| 4015 |
have_std_attrs, std_attrs, true); |
| 4016 |
if (!ENUM_FIXED_UNDERLYING_TYPE_P (ret.spec)) |
| 4017 |
error_at (enum_loc, "%<enum%> declared both with and without " |
| 4018 |
"fixed underlying type"); |
| 4019 |
potential_nesting_p = NULL_TREE == TYPE_VALUES (ret.spec); |
| 4020 |
} |
| 4021 |
else |
| 4022 |
{ |
| 4023 |
/* There must be an enum definition, so this initialization |
| 4024 |
(to avoid possible warnings about uninitialized data) |
| 4025 |
will be replaced later (either with the results of that |
| 4026 |
definition, or with the results of error handling for the |
| 4027 |
case of no tag and no definition). */ |
| 4028 |
ret.spec = NULL_TREE; |
| 4029 |
ret.kind = ctsk_tagdef; |
| 4030 |
ret.expr = NULL_TREE; |
| 4031 |
ret.expr_const_operands = true; |
| 4032 |
ret.has_enum_type_specifier = true; |
| 4033 |
} |
| 4034 |
c_parser_consume_token (parser); |
| 4035 |
struct c_declspecs *specs = build_null_declspecs (); |
| 4036 |
c_parser_declspecs (parser, specs, false, true, false, false, false, |
| 4037 |
false, true, cla_prefer_id); |
| 4038 |
finish_declspecs (specs); |
| 4039 |
if (specs->default_int_p) |
| 4040 |
error_at (enum_loc, "no %<enum%> underlying type specified"); |
| 4041 |
else if (TREE_CODE (specs->type) != INTEGER_TYPE |
| 4042 |
&& TREE_CODE (specs->type) != BOOLEAN_TYPE) |
| 4043 |
{ |
| 4044 |
error_at (enum_loc, "invalid %<enum%> underlying type"); |
| 4045 |
specs->type = integer_type_node; |
| 4046 |
} |
| 4047 |
else if (specs->restrict_p) |
| 4048 |
error_at (enum_loc, "invalid use of %<restrict%>"); |
| 4049 |
fixed_underlying_type = TYPE_MAIN_VARIANT (specs->type); |
| 4050 |
if (ident) |
| 4051 |
{ |
| 4052 |
/* The type specified must be consistent with any previously |
| 4053 |
specified underlying type. If this is a newly declared |
| 4054 |
type, it is now a complete type. */ |
| 4055 |
if (ENUM_FIXED_UNDERLYING_TYPE_P (ret.spec) |
| 4056 |
&& ENUM_UNDERLYING_TYPE (ret.spec) == NULL_TREE) |
| 4057 |
{ |
| 4058 |
TYPE_MIN_VALUE (ret.spec) = |
| 4059 |
TYPE_MIN_VALUE (fixed_underlying_type); |
| 4060 |
TYPE_MAX_VALUE (ret.spec) = |
| 4061 |
TYPE_MAX_VALUE (fixed_underlying_type); |
| 4062 |
TYPE_UNSIGNED (ret.spec) = TYPE_UNSIGNED (fixed_underlying_type); |
| 4063 |
SET_TYPE_ALIGN (ret.spec, TYPE_ALIGN (fixed_underlying_type)); |
| 4064 |
TYPE_SIZE (ret.spec) = NULL_TREE; |
| 4065 |
TYPE_PRECISION (ret.spec) = |
| 4066 |
TYPE_PRECISION (fixed_underlying_type); |
| 4067 |
ENUM_UNDERLYING_TYPE (ret.spec) = fixed_underlying_type; |
| 4068 |
layout_type (ret.spec); |
| 4069 |
} |
| 4070 |
else if (ENUM_FIXED_UNDERLYING_TYPE_P (ret.spec) |
| 4071 |
&& !comptypes (fixed_underlying_type, |
| 4072 |
ENUM_UNDERLYING_TYPE (ret.spec))) |
| 4073 |
{ |
| 4074 |
error_at (enum_loc, "%<enum%> underlying type incompatible with " |
| 4075 |
"previous declaration"); |
| 4076 |
fixed_underlying_type = ENUM_UNDERLYING_TYPE (ret.spec); |
| 4077 |
} |
| 4078 |
} |
| 4079 |
} |
| 4080 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 4081 |
{ |
| 4082 |
/* Parse an enum definition. */ |
| 4083 |
struct c_enum_contents the_enum; |
| 4084 |
tree type; |
| 4085 |
tree postfix_attrs; |
| 4086 |
/* We chain the enumerators in reverse order, then put them in |
| 4087 |
forward order at the end. */ |
| 4088 |
tree values; |
| 4089 |
timevar_push (TV_PARSE_ENUM); |
| 4090 |
type = start_enum (enum_loc, &the_enum, ident, fixed_underlying_type, |
| 4091 |
potential_nesting_p); |
| 4092 |
values = NULL_TREE; |
| 4093 |
c_parser_consume_token (parser); |
| 4094 |
while (true) |
| 4095 |
{ |
| 4096 |
tree enum_id; |
| 4097 |
tree enum_value; |
| 4098 |
tree enum_decl; |
| 4099 |
bool seen_comma; |
| 4100 |
c_token *token; |
| 4101 |
location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 4102 |
location_t decl_loc, value_loc; |
| 4103 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 4104 |
{ |
| 4105 |
report_bad_enum_name (parser); |
| 4106 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 4107 |
values = error_mark_node; |
| 4108 |
break; |
| 4109 |
} |
| 4110 |
token = c_parser_peek_token (parser); |
| 4111 |
enum_id = token->value; |
| 4112 |
/* Set the location in case we create a decl now. */ |
| 4113 |
c_parser_set_source_position_from_token (token); |
| 4114 |
decl_loc = value_loc = token->location; |
| 4115 |
c_parser_consume_token (parser); |
| 4116 |
/* Parse any specified attributes. */ |
| 4117 |
tree std_attrs = NULL_TREE; |
| 4118 |
if (c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 4119 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 4120 |
tree enum_attrs = chainon (std_attrs, |
| 4121 |
c_parser_gnu_attributes (parser)); |
| 4122 |
if (c_parser_next_token_is (parser, CPP_EQ)) |
| 4123 |
{ |
| 4124 |
c_parser_consume_token (parser); |
| 4125 |
value_loc = c_parser_peek_token (parser)->location; |
| 4126 |
enum_value = convert_lvalue_to_rvalue (value_loc, |
| 4127 |
(c_parser_expr_no_commas |
| 4128 |
(parser, NULL)), |
| 4129 |
true, true).value; |
| 4130 |
} |
| 4131 |
else |
| 4132 |
enum_value = NULL_TREE; |
| 4133 |
enum_decl = build_enumerator (decl_loc, value_loc, |
| 4134 |
&the_enum, enum_id, enum_value); |
| 4135 |
if (enum_attrs) |
| 4136 |
decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0); |
| 4137 |
TREE_CHAIN (enum_decl) = values; |
| 4138 |
values = enum_decl; |
| 4139 |
seen_comma = false; |
| 4140 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 4141 |
{ |
| 4142 |
comma_loc = c_parser_peek_token (parser)->location; |
| 4143 |
seen_comma = true; |
| 4144 |
c_parser_consume_token (parser); |
| 4145 |
} |
| 4146 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4147 |
{ |
| 4148 |
if (seen_comma) |
| 4149 |
pedwarn_c90 (comma_loc, OPT_Wpedantic, |
| 4150 |
"comma at end of enumerator list"); |
| 4151 |
c_parser_consume_token (parser); |
| 4152 |
break; |
| 4153 |
} |
| 4154 |
if (!seen_comma) |
| 4155 |
{ |
| 4156 |
c_parser_error (parser, "expected %<,%> or %<}%>"); |
| 4157 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 4158 |
values = error_mark_node; |
| 4159 |
break; |
| 4160 |
} |
| 4161 |
} |
| 4162 |
postfix_attrs = c_parser_gnu_attributes (parser); |
| 4163 |
ret.spec = finish_enum (type, nreverse (values), |
| 4164 |
chainon (std_attrs, |
| 4165 |
chainon (attrs, postfix_attrs))); |
| 4166 |
ret.kind = ctsk_tagdef; |
| 4167 |
ret.expr = NULL_TREE; |
| 4168 |
ret.expr_const_operands = true; |
| 4169 |
ret.has_enum_type_specifier = fixed_underlying_type != NULL_TREE; |
| 4170 |
timevar_pop (TV_PARSE_ENUM); |
| 4171 |
return ret; |
| 4172 |
} |
| 4173 |
else if (!ident) |
| 4174 |
{ |
| 4175 |
c_parser_error (parser, "expected %<{%>"); |
| 4176 |
ret.spec = error_mark_node; |
| 4177 |
ret.kind = ctsk_tagref; |
| 4178 |
ret.expr = NULL_TREE; |
| 4179 |
ret.expr_const_operands = true; |
| 4180 |
ret.has_enum_type_specifier = false; |
| 4181 |
return ret; |
| 4182 |
} |
| 4183 |
/* Attributes may only appear when the members are defined or in |
| 4184 |
certain forward declarations (treat enum forward declarations in |
| 4185 |
GNU C analogously to struct and union forward declarations in |
| 4186 |
standard C). */ |
| 4187 |
if (have_std_attrs && c_parser_next_token_is_not (parser, CPP_SEMICOLON)) |
| 4188 |
c_parser_error (parser, "expected %<;%>"); |
| 4189 |
if (fixed_underlying_type == NULL_TREE) |
| 4190 |
{ |
| 4191 |
ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident, have_std_attrs, |
| 4192 |
std_attrs, false); |
| 4193 |
/* In ISO C, enumerated types without a fixed underlying type |
| 4194 |
can be referred to only if already defined. */ |
| 4195 |
if (pedantic && !COMPLETE_TYPE_P (ret.spec)) |
| 4196 |
{ |
| 4197 |
gcc_assert (ident); |
| 4198 |
pedwarn (enum_loc, OPT_Wpedantic, |
| 4199 |
"ISO C forbids forward references to %<enum%> types"); |
| 4200 |
} |
| 4201 |
} |
| 4202 |
return ret; |
| 4203 |
} |
| 4204 |
|
| 4205 |
/* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1). |
| 4206 |
|
| 4207 |
struct-or-union-specifier: |
| 4208 |
struct-or-union attribute-specifier-sequence[opt] gnu-attributes[opt] |
| 4209 |
identifier[opt] { struct-contents } gnu-attributes[opt] |
| 4210 |
struct-or-union attribute-specifier-sequence[opt] gnu-attributes[opt] |
| 4211 |
identifier |
| 4212 |
|
| 4213 |
struct-contents: |
| 4214 |
struct-declaration-list |
| 4215 |
|
| 4216 |
struct-declaration-list: |
| 4217 |
struct-declaration ; |
| 4218 |
struct-declaration-list struct-declaration ; |
| 4219 |
|
| 4220 |
GNU extensions: |
| 4221 |
|
| 4222 |
struct-contents: |
| 4223 |
empty |
| 4224 |
struct-declaration |
| 4225 |
struct-declaration-list struct-declaration |
| 4226 |
|
| 4227 |
struct-declaration-list: |
| 4228 |
struct-declaration-list ; |
| 4229 |
; |
| 4230 |
|
| 4231 |
(Note that in the syntax here, unlike that in ISO C, the semicolons |
| 4232 |
are included here rather than in struct-declaration, in order to |
| 4233 |
describe the syntax with extra semicolons and missing semicolon at |
| 4234 |
end.) |
| 4235 |
|
| 4236 |
Objective-C: |
| 4237 |
|
| 4238 |
struct-declaration-list: |
| 4239 |
@defs ( class-name ) |
| 4240 |
|
| 4241 |
(Note this does not include a trailing semicolon, but can be |
| 4242 |
followed by further declarations, and gets a pedwarn-if-pedantic |
| 4243 |
when followed by a semicolon.) */ |
| 4244 |
|
| 4245 |
static struct c_typespec |
| 4246 |
c_parser_struct_or_union_specifier (c_parser *parser) |
| 4247 |
{ |
| 4248 |
struct c_typespec ret; |
| 4249 |
bool have_std_attrs; |
| 4250 |
tree std_attrs = NULL_TREE; |
| 4251 |
tree attrs; |
| 4252 |
tree ident = NULL_TREE; |
| 4253 |
location_t struct_loc; |
| 4254 |
location_t ident_loc = UNKNOWN_LOCATION; |
| 4255 |
enum tree_code code; |
| 4256 |
switch (c_parser_peek_token (parser)->keyword) |
| 4257 |
{ |
| 4258 |
case RID_STRUCT: |
| 4259 |
code = RECORD_TYPE; |
| 4260 |
break; |
| 4261 |
case RID_UNION: |
| 4262 |
code = UNION_TYPE; |
| 4263 |
break; |
| 4264 |
default: |
| 4265 |
gcc_unreachable (); |
| 4266 |
} |
| 4267 |
struct_loc = c_parser_peek_token (parser)->location; |
| 4268 |
c_parser_consume_token (parser); |
| 4269 |
have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1); |
| 4270 |
if (have_std_attrs) |
| 4271 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 4272 |
attrs = c_parser_gnu_attributes (parser); |
| 4273 |
|
| 4274 |
/* Set the location in case we create a decl now. */ |
| 4275 |
c_parser_set_source_position_from_token (c_parser_peek_token (parser)); |
| 4276 |
|
| 4277 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 4278 |
{ |
| 4279 |
ident = c_parser_peek_token (parser)->value; |
| 4280 |
ident_loc = c_parser_peek_token (parser)->location; |
| 4281 |
struct_loc = ident_loc; |
| 4282 |
c_parser_consume_token (parser); |
| 4283 |
} |
| 4284 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 4285 |
{ |
| 4286 |
/* Parse a struct or union definition. Start the scope of the |
| 4287 |
tag before parsing components. */ |
| 4288 |
class c_struct_parse_info *struct_info; |
| 4289 |
tree type = start_struct (struct_loc, code, ident, &struct_info); |
| 4290 |
tree postfix_attrs; |
| 4291 |
/* We chain the components in reverse order, then put them in |
| 4292 |
forward order at the end. Each struct-declaration may |
| 4293 |
declare multiple components (comma-separated), so we must use |
| 4294 |
chainon to join them, although when parsing each |
| 4295 |
struct-declaration we can use TREE_CHAIN directly. |
| 4296 |
|
| 4297 |
The theory behind all this is that there will be more |
| 4298 |
semicolon separated fields than comma separated fields, and |
| 4299 |
so we'll be minimizing the number of node traversals required |
| 4300 |
by chainon. */ |
| 4301 |
tree contents; |
| 4302 |
tree expr = NULL; |
| 4303 |
timevar_push (TV_PARSE_STRUCT); |
| 4304 |
contents = NULL_TREE; |
| 4305 |
c_parser_consume_token (parser); |
| 4306 |
/* Handle the Objective-C @defs construct, |
| 4307 |
e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ |
| 4308 |
if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) |
| 4309 |
{ |
| 4310 |
tree name; |
| 4311 |
gcc_assert (c_dialect_objc ()); |
| 4312 |
c_parser_consume_token (parser); |
| 4313 |
matching_parens parens; |
| 4314 |
if (!parens.require_open (parser)) |
| 4315 |
goto end_at_defs; |
| 4316 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 4317 |
&& c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) |
| 4318 |
{ |
| 4319 |
name = c_parser_peek_token (parser)->value; |
| 4320 |
c_parser_consume_token (parser); |
| 4321 |
} |
| 4322 |
else |
| 4323 |
{ |
| 4324 |
c_parser_error (parser, "expected class name"); |
| 4325 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 4326 |
goto end_at_defs; |
| 4327 |
} |
| 4328 |
parens.skip_until_found_close (parser); |
| 4329 |
contents = nreverse (objc_get_class_ivars (name)); |
| 4330 |
} |
| 4331 |
end_at_defs: |
| 4332 |
/* Parse the struct-declarations and semicolons. Problems with |
| 4333 |
semicolons are diagnosed here; empty structures are diagnosed |
| 4334 |
elsewhere. */ |
| 4335 |
while (true) |
| 4336 |
{ |
| 4337 |
tree decls; |
| 4338 |
/* Parse any stray semicolon. */ |
| 4339 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 4340 |
{ |
| 4341 |
location_t semicolon_loc |
| 4342 |
= c_parser_peek_token (parser)->location; |
| 4343 |
gcc_rich_location richloc (semicolon_loc); |
| 4344 |
richloc.add_fixit_remove (); |
| 4345 |
pedwarn (&richloc, OPT_Wpedantic, |
| 4346 |
"extra semicolon in struct or union specified"); |
| 4347 |
c_parser_consume_token (parser); |
| 4348 |
continue; |
| 4349 |
} |
| 4350 |
/* Stop if at the end of the struct or union contents. */ |
| 4351 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4352 |
{ |
| 4353 |
c_parser_consume_token (parser); |
| 4354 |
break; |
| 4355 |
} |
| 4356 |
/* Accept #pragmas at struct scope. */ |
| 4357 |
if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 4358 |
{ |
| 4359 |
c_parser_pragma (parser, pragma_struct, NULL, NULL_TREE); |
| 4360 |
continue; |
| 4361 |
} |
| 4362 |
/* Parse some comma-separated declarations, but not the |
| 4363 |
trailing semicolon if any. */ |
| 4364 |
decls = c_parser_struct_declaration (parser, &expr); |
| 4365 |
contents = chainon (decls, contents); |
| 4366 |
/* If no semicolon follows, either we have a parse error or |
| 4367 |
are at the end of the struct or union and should |
| 4368 |
pedwarn. */ |
| 4369 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 4370 |
c_parser_consume_token (parser); |
| 4371 |
else |
| 4372 |
{ |
| 4373 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4374 |
pedwarn (c_parser_peek_token (parser)->location, 0, |
| 4375 |
"no semicolon at end of struct or union"); |
| 4376 |
else if (parser->error |
| 4377 |
|| !c_parser_next_token_starts_declspecs (parser)) |
| 4378 |
{ |
| 4379 |
c_parser_error (parser, "expected %<;%>"); |
| 4380 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 4381 |
break; |
| 4382 |
} |
| 4383 |
|
| 4384 |
/* If we come here, we have already emitted an error |
| 4385 |
for an expected `;', identifier or `(', and we also |
| 4386 |
recovered already. Go on with the next field. */ |
| 4387 |
} |
| 4388 |
} |
| 4389 |
postfix_attrs = c_parser_gnu_attributes (parser); |
| 4390 |
ret.spec = finish_struct (struct_loc, type, nreverse (contents), |
| 4391 |
chainon (std_attrs, |
| 4392 |
chainon (attrs, postfix_attrs)), |
| 4393 |
struct_info, &expr); |
| 4394 |
ret.kind = ctsk_tagdef; |
| 4395 |
ret.expr = expr; |
| 4396 |
ret.expr_const_operands = true; |
| 4397 |
ret.has_enum_type_specifier = false; |
| 4398 |
timevar_pop (TV_PARSE_STRUCT); |
| 4399 |
return ret; |
| 4400 |
} |
| 4401 |
else if (!ident) |
| 4402 |
{ |
| 4403 |
c_parser_error (parser, "expected %<{%>"); |
| 4404 |
ret.spec = error_mark_node; |
| 4405 |
ret.kind = ctsk_tagref; |
| 4406 |
ret.expr = NULL_TREE; |
| 4407 |
ret.expr_const_operands = true; |
| 4408 |
ret.has_enum_type_specifier = false; |
| 4409 |
return ret; |
| 4410 |
} |
| 4411 |
/* Attributes may only appear when the members are defined or in |
| 4412 |
certain forward declarations. */ |
| 4413 |
if (have_std_attrs && c_parser_next_token_is_not (parser, CPP_SEMICOLON)) |
| 4414 |
c_parser_error (parser, "expected %<;%>"); |
| 4415 |
/* ??? Existing practice is that GNU attributes are ignored after |
| 4416 |
the struct or union keyword when not defining the members. */ |
| 4417 |
ret = parser_xref_tag (ident_loc, code, ident, have_std_attrs, std_attrs, |
| 4418 |
false); |
| 4419 |
return ret; |
| 4420 |
} |
| 4421 |
|
| 4422 |
/* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1), |
| 4423 |
*without* the trailing semicolon. |
| 4424 |
|
| 4425 |
struct-declaration: |
| 4426 |
attribute-specifier-sequence[opt] specifier-qualifier-list |
| 4427 |
attribute-specifier-sequence[opt] struct-declarator-list |
| 4428 |
static_assert-declaration-no-semi |
| 4429 |
|
| 4430 |
specifier-qualifier-list: |
| 4431 |
type-specifier specifier-qualifier-list[opt] |
| 4432 |
type-qualifier specifier-qualifier-list[opt] |
| 4433 |
alignment-specifier specifier-qualifier-list[opt] |
| 4434 |
gnu-attributes specifier-qualifier-list[opt] |
| 4435 |
|
| 4436 |
struct-declarator-list: |
| 4437 |
struct-declarator |
| 4438 |
struct-declarator-list , gnu-attributes[opt] struct-declarator |
| 4439 |
|
| 4440 |
struct-declarator: |
| 4441 |
declarator gnu-attributes[opt] |
| 4442 |
declarator[opt] : constant-expression gnu-attributes[opt] |
| 4443 |
|
| 4444 |
GNU extensions: |
| 4445 |
|
| 4446 |
struct-declaration: |
| 4447 |
__extension__ struct-declaration |
| 4448 |
specifier-qualifier-list |
| 4449 |
|
| 4450 |
Unlike the ISO C syntax, semicolons are handled elsewhere. The use |
| 4451 |
of gnu-attributes where shown is a GNU extension. In GNU C, we accept |
| 4452 |
any expression without commas in the syntax (assignment |
| 4453 |
expressions, not just conditional expressions); assignment |
| 4454 |
expressions will be diagnosed as non-constant. */ |
| 4455 |
|
| 4456 |
static tree |
| 4457 |
c_parser_struct_declaration (c_parser *parser, tree *expr) |
| 4458 |
{ |
| 4459 |
struct c_declspecs *specs; |
| 4460 |
tree prefix_attrs; |
| 4461 |
tree all_prefix_attrs; |
| 4462 |
tree decls; |
| 4463 |
location_t decl_loc; |
| 4464 |
if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
| 4465 |
{ |
| 4466 |
int ext; |
| 4467 |
tree decl; |
| 4468 |
ext = disable_extension_diagnostics (); |
| 4469 |
c_parser_consume_token (parser); |
| 4470 |
decl = c_parser_struct_declaration (parser, expr); |
| 4471 |
restore_extension_diagnostics (ext); |
| 4472 |
return decl; |
| 4473 |
} |
| 4474 |
if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
| 4475 |
{ |
| 4476 |
c_parser_static_assert_declaration_no_semi (parser); |
| 4477 |
return NULL_TREE; |
| 4478 |
} |
| 4479 |
specs = build_null_declspecs (); |
| 4480 |
decl_loc = c_parser_peek_token (parser)->location; |
| 4481 |
/* Strictly by the standard, we shouldn't allow _Alignas here, |
| 4482 |
but it appears to have been intended to allow it there, so |
| 4483 |
we're keeping it as it is until WG14 reaches a conclusion |
| 4484 |
of N1731. |
| 4485 |
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */ |
| 4486 |
c_parser_declspecs (parser, specs, false, true, true, |
| 4487 |
true, false, true, true, cla_nonabstract_decl); |
| 4488 |
if (parser->error) |
| 4489 |
return NULL_TREE; |
| 4490 |
if (!specs->declspecs_seen_p) |
| 4491 |
{ |
| 4492 |
c_parser_error (parser, "expected specifier-qualifier-list"); |
| 4493 |
return NULL_TREE; |
| 4494 |
} |
| 4495 |
finish_declspecs (specs); |
| 4496 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 4497 |
|| c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4498 |
{ |
| 4499 |
tree ret; |
| 4500 |
if (specs->typespec_kind == ctsk_none) |
| 4501 |
{ |
| 4502 |
pedwarn (decl_loc, OPT_Wpedantic, |
| 4503 |
"ISO C forbids member declarations with no members"); |
| 4504 |
shadow_tag_warned (specs, pedantic); |
| 4505 |
ret = NULL_TREE; |
| 4506 |
} |
| 4507 |
else |
| 4508 |
{ |
| 4509 |
/* Support for unnamed structs or unions as members of |
| 4510 |
structs or unions (which is [a] useful and [b] supports |
| 4511 |
MS P-SDK). */ |
| 4512 |
tree attrs = NULL; |
| 4513 |
|
| 4514 |
ret = grokfield (c_parser_peek_token (parser)->location, |
| 4515 |
build_id_declarator (NULL_TREE), specs, |
| 4516 |
NULL_TREE, &attrs, expr); |
| 4517 |
if (ret) |
| 4518 |
decl_attributes (&ret, attrs, 0); |
| 4519 |
} |
| 4520 |
return ret; |
| 4521 |
} |
| 4522 |
|
| 4523 |
/* Provide better error recovery. Note that a type name here is valid, |
| 4524 |
and will be treated as a field name. */ |
| 4525 |
if (specs->typespec_kind == ctsk_tagdef |
| 4526 |
&& TREE_CODE (specs->type) != ENUMERAL_TYPE |
| 4527 |
&& c_parser_next_token_starts_declspecs (parser) |
| 4528 |
&& !c_parser_next_token_is (parser, CPP_NAME)) |
| 4529 |
{ |
| 4530 |
c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); |
| 4531 |
parser->error = false; |
| 4532 |
return NULL_TREE; |
| 4533 |
} |
| 4534 |
|
| 4535 |
pending_xref_error (); |
| 4536 |
prefix_attrs = specs->attrs; |
| 4537 |
all_prefix_attrs = prefix_attrs; |
| 4538 |
specs->attrs = NULL_TREE; |
| 4539 |
decls = NULL_TREE; |
| 4540 |
while (true) |
| 4541 |
{ |
| 4542 |
/* Declaring one or more declarators or un-named bit-fields. */ |
| 4543 |
struct c_declarator *declarator; |
| 4544 |
bool dummy = false; |
| 4545 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 4546 |
declarator = build_id_declarator (NULL_TREE); |
| 4547 |
else |
| 4548 |
declarator = c_parser_declarator (parser, |
| 4549 |
specs->typespec_kind != ctsk_none, |
| 4550 |
C_DTR_NORMAL, &dummy); |
| 4551 |
if (declarator == NULL) |
| 4552 |
{ |
| 4553 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 4554 |
break; |
| 4555 |
} |
| 4556 |
if (c_parser_next_token_is (parser, CPP_COLON) |
| 4557 |
|| c_parser_next_token_is (parser, CPP_COMMA) |
| 4558 |
|| c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 4559 |
|| c_parser_next_token_is (parser, CPP_CLOSE_BRACE) |
| 4560 |
|| c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 4561 |
{ |
| 4562 |
tree postfix_attrs = NULL_TREE; |
| 4563 |
tree width = NULL_TREE; |
| 4564 |
tree d; |
| 4565 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 4566 |
{ |
| 4567 |
c_parser_consume_token (parser); |
| 4568 |
location_t loc = c_parser_peek_token (parser)->location; |
| 4569 |
width = convert_lvalue_to_rvalue (loc, |
| 4570 |
(c_parser_expr_no_commas |
| 4571 |
(parser, NULL)), |
| 4572 |
true, true).value; |
| 4573 |
} |
| 4574 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 4575 |
postfix_attrs = c_parser_gnu_attributes (parser); |
| 4576 |
d = grokfield (c_parser_peek_token (parser)->location, |
| 4577 |
declarator, specs, width, &all_prefix_attrs, expr); |
| 4578 |
decl_attributes (&d, chainon (postfix_attrs, |
| 4579 |
all_prefix_attrs), 0); |
| 4580 |
DECL_CHAIN (d) = decls; |
| 4581 |
decls = d; |
| 4582 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 4583 |
all_prefix_attrs = chainon (c_parser_gnu_attributes (parser), |
| 4584 |
prefix_attrs); |
| 4585 |
else |
| 4586 |
all_prefix_attrs = prefix_attrs; |
| 4587 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 4588 |
c_parser_consume_token (parser); |
| 4589 |
else if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 4590 |
|| c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4591 |
{ |
| 4592 |
/* Semicolon consumed in caller. */ |
| 4593 |
break; |
| 4594 |
} |
| 4595 |
else |
| 4596 |
{ |
| 4597 |
c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); |
| 4598 |
break; |
| 4599 |
} |
| 4600 |
} |
| 4601 |
else |
| 4602 |
{ |
| 4603 |
c_parser_error (parser, |
| 4604 |
"expected %<:%>, %<,%>, %<;%>, %<}%> or " |
| 4605 |
"%<__attribute__%>"); |
| 4606 |
break; |
| 4607 |
} |
| 4608 |
} |
| 4609 |
return decls; |
| 4610 |
} |
| 4611 |
|
| 4612 |
/* Parse a typeof specifier (a GNU extension adopted in C23). |
| 4613 |
|
| 4614 |
typeof-specifier: |
| 4615 |
typeof ( expression ) |
| 4616 |
typeof ( type-name ) |
| 4617 |
typeof_unqual ( expression ) |
| 4618 |
typeof_unqual ( type-name ) |
| 4619 |
*/ |
| 4620 |
|
| 4621 |
static struct c_typespec |
| 4622 |
c_parser_typeof_specifier (c_parser *parser) |
| 4623 |
{ |
| 4624 |
bool is_unqual; |
| 4625 |
bool is_std; |
| 4626 |
struct c_typespec ret; |
| 4627 |
ret.kind = ctsk_typeof; |
| 4628 |
ret.spec = error_mark_node; |
| 4629 |
ret.expr = NULL_TREE; |
| 4630 |
ret.expr_const_operands = true; |
| 4631 |
ret.has_enum_type_specifier = false; |
| 4632 |
if (c_parser_next_token_is_keyword (parser, RID_TYPEOF)) |
| 4633 |
{ |
| 4634 |
is_unqual = false; |
| 4635 |
tree spelling = c_parser_peek_token (parser)->value; |
| 4636 |
is_std = (flag_isoc23 |
| 4637 |
&& strcmp (IDENTIFIER_POINTER (spelling), "typeof") == 0); |
| 4638 |
} |
| 4639 |
else |
| 4640 |
{ |
| 4641 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF_UNQUAL)); |
| 4642 |
is_unqual = true; |
| 4643 |
tree spelling = c_parser_peek_token (parser)->value; |
| 4644 |
is_std = strcmp (IDENTIFIER_POINTER (spelling), "typeof_unqual") == 0; |
| 4645 |
} |
| 4646 |
c_parser_consume_token (parser); |
| 4647 |
c_inhibit_evaluation_warnings++; |
| 4648 |
in_typeof++; |
| 4649 |
matching_parens parens; |
| 4650 |
if (!parens.require_open (parser)) |
| 4651 |
{ |
| 4652 |
c_inhibit_evaluation_warnings--; |
| 4653 |
in_typeof--; |
| 4654 |
return ret; |
| 4655 |
} |
| 4656 |
if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
| 4657 |
{ |
| 4658 |
struct c_type_name *type = c_parser_type_name (parser); |
| 4659 |
c_inhibit_evaluation_warnings--; |
| 4660 |
in_typeof--; |
| 4661 |
if (type != NULL) |
| 4662 |
{ |
| 4663 |
ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); |
| 4664 |
pop_maybe_used (c_type_variably_modified_p (ret.spec)); |
| 4665 |
} |
| 4666 |
} |
| 4667 |
else |
| 4668 |
{ |
| 4669 |
bool was_vm; |
| 4670 |
location_t here = c_parser_peek_token (parser)->location; |
| 4671 |
struct c_expr expr = c_parser_expression (parser); |
| 4672 |
c_inhibit_evaluation_warnings--; |
| 4673 |
in_typeof--; |
| 4674 |
if (TREE_CODE (expr.value) == COMPONENT_REF |
| 4675 |
&& DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) |
| 4676 |
error_at (here, "%<typeof%> applied to a bit-field"); |
| 4677 |
mark_exp_read (expr.value); |
| 4678 |
ret.spec = TREE_TYPE (expr.value); |
| 4679 |
was_vm = c_type_variably_modified_p (ret.spec); |
| 4680 |
/* This is returned with the type so that when the type is |
| 4681 |
evaluated, this can be evaluated. */ |
| 4682 |
if (was_vm) |
| 4683 |
ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); |
| 4684 |
pop_maybe_used (was_vm); |
| 4685 |
} |
| 4686 |
parens.skip_until_found_close (parser); |
| 4687 |
if (ret.spec != error_mark_node) |
| 4688 |
{ |
| 4689 |
if (is_unqual) |
| 4690 |
{ |
| 4691 |
bool is_array = TREE_CODE (ret.spec) == ARRAY_TYPE; |
| 4692 |
int quals = TYPE_QUALS (strip_array_types (ret.spec)); |
| 4693 |
if ((is_array ? quals & ~TYPE_QUAL_ATOMIC : quals) |
| 4694 |
!= TYPE_UNQUALIFIED) |
| 4695 |
{ |
| 4696 |
ret.spec = TYPE_MAIN_VARIANT (ret.spec); |
| 4697 |
if (quals & TYPE_QUAL_ATOMIC && is_array) |
| 4698 |
ret.spec = c_build_qualified_type (ret.spec, |
| 4699 |
TYPE_QUAL_ATOMIC); |
| 4700 |
} |
| 4701 |
} |
| 4702 |
if (is_std) |
| 4703 |
{ |
| 4704 |
/* In ISO C terms, _Noreturn is not part of the type of |
| 4705 |
expressions such as &abort, but in GCC it is represented |
| 4706 |
internally as a type qualifier. */ |
| 4707 |
if (TREE_CODE (ret.spec) == FUNCTION_TYPE |
| 4708 |
&& TYPE_QUALS (ret.spec) != TYPE_UNQUALIFIED) |
| 4709 |
ret.spec = TYPE_MAIN_VARIANT (ret.spec); |
| 4710 |
else if (FUNCTION_POINTER_TYPE_P (ret.spec) |
| 4711 |
&& TYPE_QUALS (TREE_TYPE (ret.spec)) != TYPE_UNQUALIFIED) |
| 4712 |
ret.spec |
| 4713 |
= c_build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (ret.spec))); |
| 4714 |
} |
| 4715 |
} |
| 4716 |
return ret; |
| 4717 |
} |
| 4718 |
|
| 4719 |
/* Parse an alignment-specifier. |
| 4720 |
|
| 4721 |
C11 6.7.5: |
| 4722 |
|
| 4723 |
alignment-specifier: |
| 4724 |
_Alignas ( type-name ) |
| 4725 |
_Alignas ( constant-expression ) |
| 4726 |
*/ |
| 4727 |
|
| 4728 |
static tree |
| 4729 |
c_parser_alignas_specifier (c_parser * parser) |
| 4730 |
{ |
| 4731 |
tree ret = error_mark_node; |
| 4732 |
location_t loc = c_parser_peek_token (parser)->location; |
| 4733 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS)); |
| 4734 |
tree spelling = c_parser_peek_token (parser)->value; |
| 4735 |
c_parser_consume_token (parser); |
| 4736 |
if (flag_isoc99) |
| 4737 |
pedwarn_c99 (loc, OPT_Wpedantic, |
| 4738 |
"ISO C99 does not support %qE", spelling); |
| 4739 |
else |
| 4740 |
pedwarn_c99 (loc, OPT_Wpedantic, |
| 4741 |
"ISO C90 does not support %qE", spelling); |
| 4742 |
matching_parens parens; |
| 4743 |
if (!parens.require_open (parser)) |
| 4744 |
return ret; |
| 4745 |
if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
| 4746 |
{ |
| 4747 |
struct c_type_name *type = c_parser_type_name (parser); |
| 4748 |
if (type != NULL) |
| 4749 |
ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL), |
| 4750 |
false, true, 1); |
| 4751 |
} |
| 4752 |
else |
| 4753 |
ret = convert_lvalue_to_rvalue (loc, |
| 4754 |
c_parser_expr_no_commas (parser, NULL), |
| 4755 |
true, true).value; |
| 4756 |
parens.skip_until_found_close (parser); |
| 4757 |
return ret; |
| 4758 |
} |
| 4759 |
|
| 4760 |
/* Parse a declarator, possibly an abstract declarator (C90 6.5.4, |
| 4761 |
6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then |
| 4762 |
a typedef name may be redeclared; otherwise it may not. KIND |
| 4763 |
indicates which kind of declarator is wanted. Returns a valid |
| 4764 |
declarator except in the case of a syntax error in which case NULL is |
| 4765 |
returned. *SEEN_ID is set to true if an identifier being declared is |
| 4766 |
seen; this is used to diagnose bad forms of abstract array declarators |
| 4767 |
and to determine whether an identifier list is syntactically permitted. |
| 4768 |
|
| 4769 |
declarator: |
| 4770 |
pointer[opt] direct-declarator |
| 4771 |
|
| 4772 |
direct-declarator: |
| 4773 |
identifier |
| 4774 |
( gnu-attributes[opt] declarator ) |
| 4775 |
direct-declarator array-declarator |
| 4776 |
direct-declarator ( parameter-type-list ) |
| 4777 |
direct-declarator ( identifier-list[opt] ) |
| 4778 |
|
| 4779 |
pointer: |
| 4780 |
* type-qualifier-list[opt] |
| 4781 |
* type-qualifier-list[opt] pointer |
| 4782 |
|
| 4783 |
type-qualifier-list: |
| 4784 |
type-qualifier |
| 4785 |
gnu-attributes |
| 4786 |
type-qualifier-list type-qualifier |
| 4787 |
type-qualifier-list gnu-attributes |
| 4788 |
|
| 4789 |
array-declarator: |
| 4790 |
[ type-qualifier-list[opt] assignment-expression[opt] ] |
| 4791 |
[ static type-qualifier-list[opt] assignment-expression ] |
| 4792 |
[ type-qualifier-list static assignment-expression ] |
| 4793 |
[ type-qualifier-list[opt] * ] |
| 4794 |
|
| 4795 |
parameter-type-list: |
| 4796 |
parameter-list |
| 4797 |
parameter-list , ... |
| 4798 |
|
| 4799 |
parameter-list: |
| 4800 |
parameter-declaration |
| 4801 |
parameter-list , parameter-declaration |
| 4802 |
|
| 4803 |
parameter-declaration: |
| 4804 |
declaration-specifiers declarator gnu-attributes[opt] |
| 4805 |
declaration-specifiers abstract-declarator[opt] gnu-attributes[opt] |
| 4806 |
|
| 4807 |
identifier-list: |
| 4808 |
identifier |
| 4809 |
identifier-list , identifier |
| 4810 |
|
| 4811 |
abstract-declarator: |
| 4812 |
pointer |
| 4813 |
pointer[opt] direct-abstract-declarator |
| 4814 |
|
| 4815 |
direct-abstract-declarator: |
| 4816 |
( gnu-attributes[opt] abstract-declarator ) |
| 4817 |
direct-abstract-declarator[opt] array-declarator |
| 4818 |
direct-abstract-declarator[opt] ( parameter-type-list[opt] ) |
| 4819 |
|
| 4820 |
GNU extensions: |
| 4821 |
|
| 4822 |
direct-declarator: |
| 4823 |
direct-declarator ( parameter-forward-declarations |
| 4824 |
parameter-type-list[opt] ) |
| 4825 |
|
| 4826 |
direct-abstract-declarator: |
| 4827 |
direct-abstract-declarator[opt] ( parameter-forward-declarations |
| 4828 |
parameter-type-list[opt] ) |
| 4829 |
|
| 4830 |
parameter-forward-declarations: |
| 4831 |
parameter-list ; |
| 4832 |
parameter-forward-declarations parameter-list ; |
| 4833 |
|
| 4834 |
The uses of gnu-attributes shown above are GNU extensions. |
| 4835 |
|
| 4836 |
Some forms of array declarator are not included in C99 in the |
| 4837 |
syntax for abstract declarators; these are disallowed elsewhere. |
| 4838 |
This may be a defect (DR#289). |
| 4839 |
|
| 4840 |
This function also accepts an omitted abstract declarator as being |
| 4841 |
an abstract declarator, although not part of the formal syntax. */ |
| 4842 |
|
| 4843 |
struct c_declarator * |
| 4844 |
c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, |
| 4845 |
bool *seen_id) |
| 4846 |
{ |
| 4847 |
/* Parse any initial pointer part. */ |
| 4848 |
if (c_parser_next_token_is (parser, CPP_MULT)) |
| 4849 |
{ |
| 4850 |
struct c_declspecs *quals_attrs = build_null_declspecs (); |
| 4851 |
struct c_declarator *inner; |
| 4852 |
c_parser_consume_token (parser); |
| 4853 |
c_parser_declspecs (parser, quals_attrs, false, false, true, |
| 4854 |
false, false, true, false, cla_prefer_id); |
| 4855 |
inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
| 4856 |
if (inner == NULL) |
| 4857 |
return NULL; |
| 4858 |
else |
| 4859 |
return make_pointer_declarator (quals_attrs, inner); |
| 4860 |
} |
| 4861 |
/* Now we have a direct declarator, direct abstract declarator or |
| 4862 |
nothing (which counts as a direct abstract declarator here). */ |
| 4863 |
return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); |
| 4864 |
} |
| 4865 |
|
| 4866 |
/* Parse a direct declarator or direct abstract declarator; arguments |
| 4867 |
as c_parser_declarator. */ |
| 4868 |
|
| 4869 |
static struct c_declarator * |
| 4870 |
c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, |
| 4871 |
bool *seen_id) |
| 4872 |
{ |
| 4873 |
/* The direct declarator must start with an identifier (possibly |
| 4874 |
omitted) or a parenthesized declarator (possibly abstract). In |
| 4875 |
an ordinary declarator, initial parentheses must start a |
| 4876 |
parenthesized declarator. In an abstract declarator or parameter |
| 4877 |
declarator, they could start a parenthesized declarator or a |
| 4878 |
parameter list. To tell which, the open parenthesis and any |
| 4879 |
following gnu-attributes must be read. If a declaration |
| 4880 |
specifier or standard attributes follow, then it is a parameter |
| 4881 |
list; if the specifier is a typedef name, there might be an |
| 4882 |
ambiguity about redeclaring it, which is resolved in the |
| 4883 |
direction of treating it as a typedef name. If a close |
| 4884 |
parenthesis follows, it is also an empty parameter list, as the |
| 4885 |
syntax does not permit empty abstract declarators. Otherwise, it |
| 4886 |
is a parenthesized declarator (in which case the analysis may be |
| 4887 |
repeated inside it, recursively). |
| 4888 |
|
| 4889 |
??? There is an ambiguity in a parameter declaration "int |
| 4890 |
(__attribute__((foo)) x)", where x is not a typedef name: it |
| 4891 |
could be an abstract declarator for a function, or declare x with |
| 4892 |
parentheses. The proper resolution of this ambiguity needs |
| 4893 |
documenting. At present we follow an accident of the old |
| 4894 |
parser's implementation, whereby the first parameter must have |
| 4895 |
some declaration specifiers other than just gnu-attributes. Thus as |
| 4896 |
a parameter declaration it is treated as a parenthesized |
| 4897 |
parameter named x, and as an abstract declarator it is |
| 4898 |
rejected. |
| 4899 |
|
| 4900 |
??? Also following the old parser, gnu-attributes inside an empty |
| 4901 |
parameter list are ignored, making it a list not yielding a |
| 4902 |
prototype, rather than giving an error or making it have one |
| 4903 |
parameter with implicit type int. |
| 4904 |
|
| 4905 |
??? Also following the old parser, typedef names may be |
| 4906 |
redeclared in declarators, but not Objective-C class names. */ |
| 4907 |
|
| 4908 |
if (kind != C_DTR_ABSTRACT |
| 4909 |
&& c_parser_next_token_is (parser, CPP_NAME) |
| 4910 |
&& ((type_seen_p |
| 4911 |
&& (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
| 4912 |
|| c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) |
| 4913 |
|| c_parser_peek_token (parser)->id_kind == C_ID_ID)) |
| 4914 |
{ |
| 4915 |
struct c_declarator *inner |
| 4916 |
= build_id_declarator (c_parser_peek_token (parser)->value); |
| 4917 |
*seen_id = true; |
| 4918 |
inner->id_loc = c_parser_peek_token (parser)->location; |
| 4919 |
c_parser_consume_token (parser); |
| 4920 |
if (c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 4921 |
inner->u.id.attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 4922 |
return c_parser_direct_declarator_inner (parser, *seen_id, inner); |
| 4923 |
} |
| 4924 |
|
| 4925 |
if (kind != C_DTR_NORMAL |
| 4926 |
&& c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
| 4927 |
&& !c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 4928 |
{ |
| 4929 |
struct c_declarator *inner = build_id_declarator (NULL_TREE); |
| 4930 |
inner->id_loc = c_parser_peek_token (parser)->location; |
| 4931 |
return c_parser_direct_declarator_inner (parser, *seen_id, inner); |
| 4932 |
} |
| 4933 |
|
| 4934 |
/* Either we are at the end of an abstract declarator, or we have |
| 4935 |
parentheses. */ |
| 4936 |
|
| 4937 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 4938 |
{ |
| 4939 |
tree attrs; |
| 4940 |
struct c_declarator *inner; |
| 4941 |
c_parser_consume_token (parser); |
| 4942 |
bool have_gnu_attrs = c_parser_next_token_is_keyword (parser, |
| 4943 |
RID_ATTRIBUTE); |
| 4944 |
attrs = c_parser_gnu_attributes (parser); |
| 4945 |
if (kind != C_DTR_NORMAL |
| 4946 |
&& (c_parser_next_token_starts_declspecs (parser) |
| 4947 |
|| (!have_gnu_attrs |
| 4948 |
&& (c_parser_nth_token_starts_std_attributes (parser, 1) |
| 4949 |
|| c_parser_next_token_is (parser, CPP_ELLIPSIS))) |
| 4950 |
|| c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) |
| 4951 |
{ |
| 4952 |
struct c_arg_info *args |
| 4953 |
= c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, |
| 4954 |
attrs, have_gnu_attrs); |
| 4955 |
if (args == NULL) |
| 4956 |
return NULL; |
| 4957 |
else |
| 4958 |
{ |
| 4959 |
inner = build_id_declarator (NULL_TREE); |
| 4960 |
if (!(args->types |
| 4961 |
&& args->types != error_mark_node |
| 4962 |
&& TREE_CODE (TREE_VALUE (args->types)) == IDENTIFIER_NODE) |
| 4963 |
&& c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 4964 |
{ |
| 4965 |
tree std_attrs |
| 4966 |
= c_parser_std_attribute_specifier_sequence (parser); |
| 4967 |
if (std_attrs) |
| 4968 |
inner = build_attrs_declarator (std_attrs, inner); |
| 4969 |
} |
| 4970 |
inner = build_function_declarator (args, inner); |
| 4971 |
return c_parser_direct_declarator_inner (parser, *seen_id, |
| 4972 |
inner); |
| 4973 |
} |
| 4974 |
} |
| 4975 |
/* A parenthesized declarator. */ |
| 4976 |
inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
| 4977 |
if (inner != NULL && attrs != NULL) |
| 4978 |
inner = build_attrs_declarator (attrs, inner); |
| 4979 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 4980 |
{ |
| 4981 |
c_parser_consume_token (parser); |
| 4982 |
if (inner == NULL) |
| 4983 |
return NULL; |
| 4984 |
else |
| 4985 |
return c_parser_direct_declarator_inner (parser, *seen_id, inner); |
| 4986 |
} |
| 4987 |
else |
| 4988 |
{ |
| 4989 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 4990 |
"expected %<)%>"); |
| 4991 |
return NULL; |
| 4992 |
} |
| 4993 |
} |
| 4994 |
else |
| 4995 |
{ |
| 4996 |
if (kind == C_DTR_NORMAL) |
| 4997 |
{ |
| 4998 |
c_parser_error (parser, "expected identifier or %<(%>"); |
| 4999 |
return NULL; |
| 5000 |
} |
| 5001 |
else |
| 5002 |
return build_id_declarator (NULL_TREE); |
| 5003 |
} |
| 5004 |
} |
| 5005 |
|
| 5006 |
/* Parse part of a direct declarator or direct abstract declarator, |
| 5007 |
given that some (in INNER) has already been parsed; ID_PRESENT is |
| 5008 |
true if an identifier is present, false for an abstract |
| 5009 |
declarator. */ |
| 5010 |
|
| 5011 |
static struct c_declarator * |
| 5012 |
c_parser_direct_declarator_inner (c_parser *parser, bool id_present, |
| 5013 |
struct c_declarator *inner) |
| 5014 |
{ |
| 5015 |
/* Parse a sequence of array declarators and parameter lists. */ |
| 5016 |
if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
| 5017 |
&& !c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 5018 |
{ |
| 5019 |
location_t brace_loc = c_parser_peek_token (parser)->location; |
| 5020 |
struct c_declarator *declarator; |
| 5021 |
struct c_declspecs *quals_attrs = build_null_declspecs (); |
| 5022 |
struct c_expr dimen; |
| 5023 |
dimen.value = NULL_TREE; |
| 5024 |
dimen.original_code = ERROR_MARK; |
| 5025 |
dimen.original_type = NULL_TREE; |
| 5026 |
c_parser_consume_token (parser); |
| 5027 |
c_parser_declspecs (parser, quals_attrs, false, false, true, |
| 5028 |
false, false, false, false, cla_prefer_id); |
| 5029 |
|
| 5030 |
location_t static_loc = UNKNOWN_LOCATION; |
| 5031 |
if (c_parser_next_token_is_keyword (parser, RID_STATIC)) |
| 5032 |
{ |
| 5033 |
static_loc = c_parser_peek_token (parser)->location; |
| 5034 |
c_parser_consume_token (parser); |
| 5035 |
if (!quals_attrs->declspecs_seen_p) |
| 5036 |
c_parser_declspecs (parser, quals_attrs, false, false, true, |
| 5037 |
false, false, false, false, cla_prefer_id); |
| 5038 |
} |
| 5039 |
if (!quals_attrs->declspecs_seen_p) |
| 5040 |
quals_attrs = NULL; |
| 5041 |
/* If "static" is present, there must be an array dimension. |
| 5042 |
Otherwise, there may be a dimension, "*", or no |
| 5043 |
dimension. */ |
| 5044 |
const bool static_seen = (static_loc != UNKNOWN_LOCATION); |
| 5045 |
bool star_seen = false; |
| 5046 |
if (c_parser_next_token_is (parser, CPP_MULT) |
| 5047 |
&& c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) |
| 5048 |
{ |
| 5049 |
star_seen = true; |
| 5050 |
c_parser_consume_token (parser); |
| 5051 |
} |
| 5052 |
else if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 5053 |
dimen = c_parser_expr_no_commas (parser, NULL); |
| 5054 |
|
| 5055 |
if (static_seen) |
| 5056 |
{ |
| 5057 |
if (star_seen) |
| 5058 |
{ |
| 5059 |
error_at (static_loc, |
| 5060 |
"%<static%> may not be used with an unspecified " |
| 5061 |
"variable length array size"); |
| 5062 |
/* Prevent further errors. */ |
| 5063 |
star_seen = false; |
| 5064 |
dimen.value = error_mark_node; |
| 5065 |
} |
| 5066 |
else if (!dimen.value) |
| 5067 |
error_at (static_loc, |
| 5068 |
"%<static%> may not be used without an array size"); |
| 5069 |
} |
| 5070 |
|
| 5071 |
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 5072 |
c_parser_consume_token (parser); |
| 5073 |
else |
| 5074 |
{ |
| 5075 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 5076 |
"expected %<]%>"); |
| 5077 |
return NULL; |
| 5078 |
} |
| 5079 |
if (dimen.value) |
| 5080 |
dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true); |
| 5081 |
declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs, |
| 5082 |
static_seen, star_seen); |
| 5083 |
if (declarator == NULL) |
| 5084 |
return NULL; |
| 5085 |
if (c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 5086 |
{ |
| 5087 |
tree std_attrs |
| 5088 |
= c_parser_std_attribute_specifier_sequence (parser); |
| 5089 |
if (std_attrs) |
| 5090 |
inner = build_attrs_declarator (std_attrs, inner); |
| 5091 |
} |
| 5092 |
inner = set_array_declarator_inner (declarator, inner); |
| 5093 |
return c_parser_direct_declarator_inner (parser, id_present, inner); |
| 5094 |
} |
| 5095 |
else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 5096 |
{ |
| 5097 |
tree attrs; |
| 5098 |
struct c_arg_info *args; |
| 5099 |
c_parser_consume_token (parser); |
| 5100 |
bool have_gnu_attrs = c_parser_next_token_is_keyword (parser, |
| 5101 |
RID_ATTRIBUTE); |
| 5102 |
attrs = c_parser_gnu_attributes (parser); |
| 5103 |
args = c_parser_parms_declarator (parser, id_present, attrs, |
| 5104 |
have_gnu_attrs); |
| 5105 |
if (args == NULL) |
| 5106 |
return NULL; |
| 5107 |
else |
| 5108 |
{ |
| 5109 |
if (!(args->types |
| 5110 |
&& args->types != error_mark_node |
| 5111 |
&& TREE_CODE (TREE_VALUE (args->types)) == IDENTIFIER_NODE) |
| 5112 |
&& c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 5113 |
{ |
| 5114 |
tree std_attrs |
| 5115 |
= c_parser_std_attribute_specifier_sequence (parser); |
| 5116 |
if (std_attrs) |
| 5117 |
inner = build_attrs_declarator (std_attrs, inner); |
| 5118 |
} |
| 5119 |
inner = build_function_declarator (args, inner); |
| 5120 |
return c_parser_direct_declarator_inner (parser, id_present, inner); |
| 5121 |
} |
| 5122 |
} |
| 5123 |
return inner; |
| 5124 |
} |
| 5125 |
|
| 5126 |
/* Parse a parameter list or identifier list, including the closing |
| 5127 |
parenthesis but not the opening one. ATTRS are the gnu-attributes |
| 5128 |
at the start of the list. ID_LIST_OK is true if an identifier list |
| 5129 |
is acceptable; such a list must not have attributes at the start. |
| 5130 |
HAVE_GNU_ATTRS says whether any gnu-attributes (including empty |
| 5131 |
attributes) were present (in which case standard attributes cannot |
| 5132 |
occur). */ |
| 5133 |
|
| 5134 |
static struct c_arg_info * |
| 5135 |
c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs, |
| 5136 |
bool have_gnu_attrs) |
| 5137 |
{ |
| 5138 |
push_scope (); |
| 5139 |
declare_parm_level (); |
| 5140 |
/* If the list starts with an identifier, it is an identifier list. |
| 5141 |
Otherwise, it is either a prototype list or an empty list. */ |
| 5142 |
if (id_list_ok |
| 5143 |
&& !attrs |
| 5144 |
&& c_parser_next_token_is (parser, CPP_NAME) |
| 5145 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 5146 |
|
| 5147 |
/* Look ahead to detect typos in type names. */ |
| 5148 |
&& c_parser_peek_2nd_token (parser)->type != CPP_NAME |
| 5149 |
&& c_parser_peek_2nd_token (parser)->type != CPP_MULT |
| 5150 |
&& c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN |
| 5151 |
&& c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE |
| 5152 |
&& c_parser_peek_2nd_token (parser)->type != CPP_KEYWORD) |
| 5153 |
{ |
| 5154 |
tree list = NULL_TREE, *nextp = &list; |
| 5155 |
while (c_parser_next_token_is (parser, CPP_NAME) |
| 5156 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 5157 |
{ |
| 5158 |
*nextp = build_tree_list (NULL_TREE, |
| 5159 |
c_parser_peek_token (parser)->value); |
| 5160 |
nextp = & TREE_CHAIN (*nextp); |
| 5161 |
c_parser_consume_token (parser); |
| 5162 |
if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 5163 |
break; |
| 5164 |
c_parser_consume_token (parser); |
| 5165 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5166 |
{ |
| 5167 |
c_parser_error (parser, "expected identifier"); |
| 5168 |
break; |
| 5169 |
} |
| 5170 |
} |
| 5171 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5172 |
{ |
| 5173 |
struct c_arg_info *ret = build_arg_info (); |
| 5174 |
ret->types = list; |
| 5175 |
c_parser_consume_token (parser); |
| 5176 |
pop_scope (); |
| 5177 |
return ret; |
| 5178 |
} |
| 5179 |
else |
| 5180 |
{ |
| 5181 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5182 |
"expected %<)%>"); |
| 5183 |
pop_scope (); |
| 5184 |
return NULL; |
| 5185 |
} |
| 5186 |
} |
| 5187 |
else |
| 5188 |
{ |
| 5189 |
struct c_arg_info *ret |
| 5190 |
= c_parser_parms_list_declarator (parser, attrs, NULL, have_gnu_attrs); |
| 5191 |
pop_scope (); |
| 5192 |
return ret; |
| 5193 |
} |
| 5194 |
} |
| 5195 |
|
| 5196 |
/* Parse a parameter list (possibly empty), including the closing |
| 5197 |
parenthesis but not the opening one. ATTRS are the gnu-attributes |
| 5198 |
at the start of the list; if HAVE_GNU_ATTRS, there were some such |
| 5199 |
attributes (possibly empty, in which case ATTRS is NULL_TREE), |
| 5200 |
which means standard attributes cannot start the list. EXPR is |
| 5201 |
NULL or an expression that needs to be evaluated for the side |
| 5202 |
effects of array size expressions in the parameters. */ |
| 5203 |
|
| 5204 |
static struct c_arg_info * |
| 5205 |
c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr, |
| 5206 |
bool have_gnu_attrs) |
| 5207 |
{ |
| 5208 |
bool bad_parm = false; |
| 5209 |
|
| 5210 |
/* ??? Following the old parser, forward parameter declarations may |
| 5211 |
use abstract declarators, and if no real parameter declarations |
| 5212 |
follow the forward declarations then this is not diagnosed. Also |
| 5213 |
note as above that gnu-attributes are ignored as the only contents of |
| 5214 |
the parentheses, or as the only contents after forward |
| 5215 |
declarations. */ |
| 5216 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5217 |
{ |
| 5218 |
struct c_arg_info *ret = build_arg_info (); |
| 5219 |
c_parser_consume_token (parser); |
| 5220 |
return ret; |
| 5221 |
} |
| 5222 |
if (c_parser_next_token_is (parser, CPP_ELLIPSIS) && !have_gnu_attrs) |
| 5223 |
{ |
| 5224 |
struct c_arg_info *ret = build_arg_info (); |
| 5225 |
|
| 5226 |
ret->types = NULL_TREE; |
| 5227 |
pedwarn_c11 (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 5228 |
"ISO C requires a named argument before %<...%> " |
| 5229 |
"before C23"); |
| 5230 |
c_parser_consume_token (parser); |
| 5231 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5232 |
{ |
| 5233 |
ret->no_named_args_stdarg_p = true; |
| 5234 |
c_parser_consume_token (parser); |
| 5235 |
return ret; |
| 5236 |
} |
| 5237 |
else |
| 5238 |
{ |
| 5239 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5240 |
"expected %<)%>"); |
| 5241 |
return NULL; |
| 5242 |
} |
| 5243 |
} |
| 5244 |
/* Nonempty list of parameters, either terminated with semicolon |
| 5245 |
(forward declarations; recurse) or with close parenthesis (normal |
| 5246 |
function) or with ", ... )" (variadic function). */ |
| 5247 |
while (true) |
| 5248 |
{ |
| 5249 |
/* Parse a parameter. */ |
| 5250 |
struct c_parm *parm = c_parser_parameter_declaration (parser, attrs, |
| 5251 |
have_gnu_attrs); |
| 5252 |
attrs = NULL_TREE; |
| 5253 |
have_gnu_attrs = false; |
| 5254 |
if (parm == NULL) |
| 5255 |
bad_parm = true; |
| 5256 |
else |
| 5257 |
push_parm_decl (parm, &expr); |
| 5258 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5259 |
{ |
| 5260 |
tree new_attrs; |
| 5261 |
c_parser_consume_token (parser); |
| 5262 |
mark_forward_parm_decls (); |
| 5263 |
bool new_have_gnu_attrs |
| 5264 |
= c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE); |
| 5265 |
new_attrs = c_parser_gnu_attributes (parser); |
| 5266 |
return c_parser_parms_list_declarator (parser, new_attrs, expr, |
| 5267 |
new_have_gnu_attrs); |
| 5268 |
} |
| 5269 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5270 |
{ |
| 5271 |
c_parser_consume_token (parser); |
| 5272 |
if (bad_parm) |
| 5273 |
return NULL; |
| 5274 |
else |
| 5275 |
return get_parm_info (false, expr); |
| 5276 |
} |
| 5277 |
if (!c_parser_require (parser, CPP_COMMA, |
| 5278 |
"expected %<;%>, %<,%> or %<)%>", |
| 5279 |
UNKNOWN_LOCATION, false)) |
| 5280 |
{ |
| 5281 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 5282 |
return NULL; |
| 5283 |
} |
| 5284 |
if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 5285 |
{ |
| 5286 |
c_parser_consume_token (parser); |
| 5287 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5288 |
{ |
| 5289 |
c_parser_consume_token (parser); |
| 5290 |
if (bad_parm) |
| 5291 |
return NULL; |
| 5292 |
else |
| 5293 |
return get_parm_info (true, expr); |
| 5294 |
} |
| 5295 |
else |
| 5296 |
{ |
| 5297 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5298 |
"expected %<)%>"); |
| 5299 |
return NULL; |
| 5300 |
} |
| 5301 |
} |
| 5302 |
} |
| 5303 |
} |
| 5304 |
|
| 5305 |
/* Parse a parameter declaration. ATTRS are the gnu-attributes at the |
| 5306 |
start of the declaration if it is the first parameter; |
| 5307 |
HAVE_GNU_ATTRS is true if there were any gnu-attributes there (even |
| 5308 |
empty) there. */ |
| 5309 |
|
| 5310 |
static struct c_parm * |
| 5311 |
c_parser_parameter_declaration (c_parser *parser, tree attrs, |
| 5312 |
bool have_gnu_attrs) |
| 5313 |
{ |
| 5314 |
struct c_declspecs *specs; |
| 5315 |
struct c_declarator *declarator; |
| 5316 |
tree prefix_attrs; |
| 5317 |
tree postfix_attrs = NULL_TREE; |
| 5318 |
bool dummy = false; |
| 5319 |
|
| 5320 |
/* Accept #pragmas between parameter declarations. */ |
| 5321 |
while (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 5322 |
c_parser_pragma (parser, pragma_param, NULL, NULL_TREE); |
| 5323 |
|
| 5324 |
if (!c_parser_next_token_starts_declspecs (parser) |
| 5325 |
&& !c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 5326 |
{ |
| 5327 |
c_token *token = c_parser_peek_token (parser); |
| 5328 |
if (parser->error) |
| 5329 |
return NULL; |
| 5330 |
c_parser_set_source_position_from_token (token); |
| 5331 |
if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
| 5332 |
{ |
| 5333 |
auto_diagnostic_group d; |
| 5334 |
name_hint hint = lookup_name_fuzzy (token->value, |
| 5335 |
FUZZY_LOOKUP_TYPENAME, |
| 5336 |
token->location); |
| 5337 |
if (const char *suggestion = hint.suggestion ()) |
| 5338 |
{ |
| 5339 |
gcc_rich_location richloc (token->location); |
| 5340 |
richloc.add_fixit_replace (suggestion); |
| 5341 |
error_at (&richloc, |
| 5342 |
"unknown type name %qE; did you mean %qs?", |
| 5343 |
token->value, suggestion); |
| 5344 |
} |
| 5345 |
else |
| 5346 |
error_at (token->location, "unknown type name %qE", token->value); |
| 5347 |
parser->error = true; |
| 5348 |
} |
| 5349 |
/* ??? In some Objective-C cases '...' isn't applicable so there |
| 5350 |
should be a different message. */ |
| 5351 |
else |
| 5352 |
c_parser_error (parser, |
| 5353 |
"expected declaration specifiers or %<...%>"); |
| 5354 |
c_parser_skip_to_end_of_parameter (parser); |
| 5355 |
return NULL; |
| 5356 |
} |
| 5357 |
|
| 5358 |
location_t start_loc = c_parser_peek_token (parser)->location; |
| 5359 |
|
| 5360 |
specs = build_null_declspecs (); |
| 5361 |
if (attrs) |
| 5362 |
{ |
| 5363 |
declspecs_add_attrs (input_location, specs, attrs); |
| 5364 |
attrs = NULL_TREE; |
| 5365 |
} |
| 5366 |
c_parser_declspecs (parser, specs, true, true, true, true, false, |
| 5367 |
!have_gnu_attrs, true, cla_nonabstract_decl); |
| 5368 |
finish_declspecs (specs); |
| 5369 |
pending_xref_error (); |
| 5370 |
prefix_attrs = specs->attrs; |
| 5371 |
specs->attrs = NULL_TREE; |
| 5372 |
declarator = c_parser_declarator (parser, |
| 5373 |
specs->typespec_kind != ctsk_none, |
| 5374 |
C_DTR_PARM, &dummy); |
| 5375 |
if (declarator == NULL) |
| 5376 |
{ |
| 5377 |
c_parser_skip_until_found (parser, CPP_COMMA, NULL); |
| 5378 |
return NULL; |
| 5379 |
} |
| 5380 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 5381 |
postfix_attrs = c_parser_gnu_attributes (parser); |
| 5382 |
|
| 5383 |
/* Generate a location for the parameter, ranging from the start of the |
| 5384 |
initial token to the end of the final token. |
| 5385 |
|
| 5386 |
If we have a identifier, then use it for the caret location, e.g. |
| 5387 |
|
| 5388 |
extern int callee (int one, int (*two)(int, int), float three); |
| 5389 |
~~~~~~^~~~~~~~~~~~~~ |
| 5390 |
|
| 5391 |
otherwise, reuse the start location for the caret location e.g.: |
| 5392 |
|
| 5393 |
extern int callee (int one, int (*)(int, int), float three); |
| 5394 |
^~~~~~~~~~~~~~~~~ |
| 5395 |
*/ |
| 5396 |
location_t end_loc = parser->last_token_location; |
| 5397 |
|
| 5398 |
/* Find any cdk_id declarator; determine if we have an identifier. */ |
| 5399 |
c_declarator *id_declarator = declarator; |
| 5400 |
while (id_declarator && id_declarator->kind != cdk_id) |
| 5401 |
id_declarator = id_declarator->declarator; |
| 5402 |
location_t caret_loc = (id_declarator->u.id.id |
| 5403 |
? id_declarator->id_loc |
| 5404 |
: start_loc); |
| 5405 |
location_t param_loc = make_location (caret_loc, start_loc, end_loc); |
| 5406 |
|
| 5407 |
return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), |
| 5408 |
declarator, param_loc); |
| 5409 |
} |
| 5410 |
|
| 5411 |
/* Parse a string literal in an asm expression. It should not be |
| 5412 |
translated, and wide string literals are an error although |
| 5413 |
permitted by the syntax. This is a GNU extension. |
| 5414 |
|
| 5415 |
asm-string-literal: |
| 5416 |
string-literal |
| 5417 |
*/ |
| 5418 |
|
| 5419 |
static tree |
| 5420 |
c_parser_asm_string_literal (c_parser *parser) |
| 5421 |
{ |
| 5422 |
tree str; |
| 5423 |
int save_flag = warn_overlength_strings; |
| 5424 |
warn_overlength_strings = 0; |
| 5425 |
str = c_parser_string_literal (parser, false, false).value; |
| 5426 |
warn_overlength_strings = save_flag; |
| 5427 |
return str; |
| 5428 |
} |
| 5429 |
|
| 5430 |
/* Parse a simple asm expression. This is used in restricted |
| 5431 |
contexts, where a full expression with inputs and outputs does not |
| 5432 |
make sense. This is a GNU extension. |
| 5433 |
|
| 5434 |
simple-asm-expr: |
| 5435 |
asm ( asm-string-literal ) |
| 5436 |
*/ |
| 5437 |
|
| 5438 |
static tree |
| 5439 |
c_parser_simple_asm_expr (c_parser *parser) |
| 5440 |
{ |
| 5441 |
tree str; |
| 5442 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
| 5443 |
c_parser_consume_token (parser); |
| 5444 |
matching_parens parens; |
| 5445 |
if (!parens.require_open (parser)) |
| 5446 |
return NULL_TREE; |
| 5447 |
str = c_parser_asm_string_literal (parser); |
| 5448 |
if (!parens.require_close (parser)) |
| 5449 |
{ |
| 5450 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 5451 |
return NULL_TREE; |
| 5452 |
} |
| 5453 |
return str; |
| 5454 |
} |
| 5455 |
|
| 5456 |
static tree |
| 5457 |
c_parser_gnu_attribute_any_word (c_parser *parser) |
| 5458 |
{ |
| 5459 |
tree attr_name = NULL_TREE; |
| 5460 |
|
| 5461 |
if (c_parser_next_token_is (parser, CPP_KEYWORD)) |
| 5462 |
{ |
| 5463 |
/* ??? See comment above about what keywords are accepted here. */ |
| 5464 |
bool ok; |
| 5465 |
switch (c_parser_peek_token (parser)->keyword) |
| 5466 |
{ |
| 5467 |
case RID_STATIC: |
| 5468 |
case RID_UNSIGNED: |
| 5469 |
case RID_LONG: |
| 5470 |
case RID_CONST: |
| 5471 |
case RID_EXTERN: |
| 5472 |
case RID_REGISTER: |
| 5473 |
case RID_TYPEDEF: |
| 5474 |
case RID_SHORT: |
| 5475 |
case RID_INLINE: |
| 5476 |
case RID_NORETURN: |
| 5477 |
case RID_VOLATILE: |
| 5478 |
case RID_SIGNED: |
| 5479 |
case RID_AUTO: |
| 5480 |
case RID_RESTRICT: |
| 5481 |
case RID_COMPLEX: |
| 5482 |
case RID_THREAD: |
| 5483 |
case RID_INT: |
| 5484 |
case RID_CHAR: |
| 5485 |
case RID_FLOAT: |
| 5486 |
case RID_DOUBLE: |
| 5487 |
case RID_VOID: |
| 5488 |
case RID_DFLOAT32: |
| 5489 |
case RID_DFLOAT64: |
| 5490 |
case RID_DFLOAT128: |
| 5491 |
case RID_DFLOAT64X: |
| 5492 |
CASE_RID_FLOATN_NX: |
| 5493 |
case RID_BOOL: |
| 5494 |
case RID_BITINT: |
| 5495 |
case RID_FRACT: |
| 5496 |
case RID_ACCUM: |
| 5497 |
case RID_SAT: |
| 5498 |
case RID_TRANSACTION_ATOMIC: |
| 5499 |
case RID_TRANSACTION_CANCEL: |
| 5500 |
case RID_ATOMIC: |
| 5501 |
case RID_AUTO_TYPE: |
| 5502 |
case RID_CONSTEXPR: |
| 5503 |
case RID_INT_N_0: |
| 5504 |
case RID_INT_N_1: |
| 5505 |
case RID_INT_N_2: |
| 5506 |
case RID_INT_N_3: |
| 5507 |
ok = true; |
| 5508 |
break; |
| 5509 |
default: |
| 5510 |
ok = false; |
| 5511 |
break; |
| 5512 |
} |
| 5513 |
if (!ok) |
| 5514 |
return NULL_TREE; |
| 5515 |
|
| 5516 |
/* Accept __attribute__((__const)) as __attribute__((const)) etc. */ |
| 5517 |
attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword]; |
| 5518 |
} |
| 5519 |
else if (c_parser_next_token_is (parser, CPP_NAME)) |
| 5520 |
attr_name = c_parser_peek_token (parser)->value; |
| 5521 |
|
| 5522 |
return attr_name; |
| 5523 |
} |
| 5524 |
|
| 5525 |
/* Parse attribute arguments. This is a common form of syntax |
| 5526 |
covering all currently valid GNU and standard attributes. |
| 5527 |
|
| 5528 |
gnu-attribute-arguments: |
| 5529 |
identifier |
| 5530 |
identifier , nonempty-expr-list |
| 5531 |
expr-list |
| 5532 |
|
| 5533 |
where the "identifier" must not be declared as a type. ??? Why not |
| 5534 |
allow identifiers declared as types to start the arguments? */ |
| 5535 |
|
| 5536 |
static tree |
| 5537 |
c_parser_attribute_arguments (c_parser *parser, bool takes_identifier, |
| 5538 |
bool require_string, bool assume_attr, |
| 5539 |
bool allow_empty_args) |
| 5540 |
{ |
| 5541 |
vec<tree, va_gc> *expr_list; |
| 5542 |
tree attr_args; |
| 5543 |
/* Parse the attribute contents. If they start with an |
| 5544 |
identifier which is followed by a comma or close |
| 5545 |
parenthesis, then the arguments start with that |
| 5546 |
identifier; otherwise they are an expression list. |
| 5547 |
In objective-c the identifier may be a classname. */ |
| 5548 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 5549 |
&& (c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 5550 |
|| (c_dialect_objc () |
| 5551 |
&& c_parser_peek_token (parser)->id_kind |
| 5552 |
== C_ID_CLASSNAME)) |
| 5553 |
&& ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) |
| 5554 |
|| (c_parser_peek_2nd_token (parser)->type |
| 5555 |
== CPP_CLOSE_PAREN)) |
| 5556 |
&& (takes_identifier |
| 5557 |
|| (c_dialect_objc () |
| 5558 |
&& !assume_attr |
| 5559 |
&& c_parser_peek_token (parser)->id_kind |
| 5560 |
== C_ID_CLASSNAME))) |
| 5561 |
{ |
| 5562 |
tree arg1 = c_parser_peek_token (parser)->value; |
| 5563 |
c_parser_consume_token (parser); |
| 5564 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5565 |
attr_args = build_tree_list (NULL_TREE, arg1); |
| 5566 |
else |
| 5567 |
{ |
| 5568 |
tree tree_list; |
| 5569 |
c_parser_consume_token (parser); |
| 5570 |
expr_list = c_parser_expr_list (parser, false, true, |
| 5571 |
NULL, NULL, NULL, NULL); |
| 5572 |
tree_list = build_tree_list_vec (expr_list); |
| 5573 |
attr_args = tree_cons (NULL_TREE, arg1, tree_list); |
| 5574 |
release_tree_vector (expr_list); |
| 5575 |
} |
| 5576 |
} |
| 5577 |
else |
| 5578 |
{ |
| 5579 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5580 |
{ |
| 5581 |
if (!allow_empty_args) |
| 5582 |
error_at (c_parser_peek_token (parser)->location, |
| 5583 |
"parentheses must be omitted if " |
| 5584 |
"attribute argument list is empty"); |
| 5585 |
attr_args = NULL_TREE; |
| 5586 |
} |
| 5587 |
else if (require_string) |
| 5588 |
{ |
| 5589 |
/* The only valid argument for this attribute is a string |
| 5590 |
literal. Handle this specially here to avoid accepting |
| 5591 |
string literals with excess parentheses. */ |
| 5592 |
tree string = c_parser_string_literal (parser, false, true).value; |
| 5593 |
attr_args = build_tree_list (NULL_TREE, string); |
| 5594 |
} |
| 5595 |
else if (assume_attr) |
| 5596 |
{ |
| 5597 |
tree cond |
| 5598 |
= c_parser_conditional_expression (parser, NULL, NULL_TREE).value; |
| 5599 |
if (!c_parser_next_token_is (parser, CPP_COMMA)) |
| 5600 |
attr_args = build_tree_list (NULL_TREE, cond); |
| 5601 |
else |
| 5602 |
{ |
| 5603 |
tree tree_list; |
| 5604 |
c_parser_consume_token (parser); |
| 5605 |
expr_list = c_parser_expr_list (parser, false, true, |
| 5606 |
NULL, NULL, NULL, NULL); |
| 5607 |
tree_list = build_tree_list_vec (expr_list); |
| 5608 |
attr_args = tree_cons (NULL_TREE, cond, tree_list); |
| 5609 |
release_tree_vector (expr_list); |
| 5610 |
} |
| 5611 |
} |
| 5612 |
else |
| 5613 |
{ |
| 5614 |
expr_list = c_parser_expr_list (parser, false, true, |
| 5615 |
NULL, NULL, NULL, NULL); |
| 5616 |
attr_args = build_tree_list_vec (expr_list); |
| 5617 |
release_tree_vector (expr_list); |
| 5618 |
} |
| 5619 |
} |
| 5620 |
return attr_args; |
| 5621 |
} |
| 5622 |
|
| 5623 |
/* Parse (possibly empty) gnu-attributes. This is a GNU extension. |
| 5624 |
|
| 5625 |
gnu-attributes: |
| 5626 |
empty |
| 5627 |
gnu-attributes gnu-attribute |
| 5628 |
|
| 5629 |
gnu-attribute: |
| 5630 |
__attribute__ ( ( gnu-attribute-list ) ) |
| 5631 |
|
| 5632 |
gnu-attribute-list: |
| 5633 |
gnu-attrib |
| 5634 |
gnu-attribute_list , gnu-attrib |
| 5635 |
|
| 5636 |
gnu-attrib: |
| 5637 |
empty |
| 5638 |
any-word |
| 5639 |
any-word ( gnu-attribute-arguments ) |
| 5640 |
|
| 5641 |
where "any-word" may be any identifier (including one declared as a |
| 5642 |
type), a reserved word storage class specifier, type specifier or |
| 5643 |
type qualifier. ??? This still leaves out most reserved keywords |
| 5644 |
(following the old parser), shouldn't we include them? |
| 5645 |
When EXPECT_COMMA is true, expect the attribute to be preceded |
| 5646 |
by a comma and fail if it isn't. |
| 5647 |
When EMPTY_OK is true, allow and consume any number of consecutive |
| 5648 |
commas with no attributes in between. */ |
| 5649 |
|
| 5650 |
static tree |
| 5651 |
c_parser_gnu_attribute (c_parser *parser, tree attrs, |
| 5652 |
bool expect_comma = false, bool empty_ok = true) |
| 5653 |
{ |
| 5654 |
bool comma_first = c_parser_next_token_is (parser, CPP_COMMA); |
| 5655 |
if (!comma_first |
| 5656 |
&& !c_parser_next_token_is (parser, CPP_NAME) |
| 5657 |
&& !c_parser_next_token_is (parser, CPP_KEYWORD)) |
| 5658 |
return NULL_TREE; |
| 5659 |
|
| 5660 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 5661 |
{ |
| 5662 |
c_parser_consume_token (parser); |
| 5663 |
if (!empty_ok) |
| 5664 |
return attrs; |
| 5665 |
} |
| 5666 |
|
| 5667 |
tree attr_name = c_parser_gnu_attribute_any_word (parser); |
| 5668 |
if (attr_name == NULL_TREE) |
| 5669 |
return NULL_TREE; |
| 5670 |
|
| 5671 |
attr_name = canonicalize_attr_name (attr_name); |
| 5672 |
c_parser_consume_token (parser); |
| 5673 |
|
| 5674 |
tree attr; |
| 5675 |
if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
| 5676 |
{ |
| 5677 |
if (expect_comma && !comma_first) |
| 5678 |
{ |
| 5679 |
/* A comma is missing between the last attribute on the chain |
| 5680 |
and this one. */ |
| 5681 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5682 |
"expected %<)%>"); |
| 5683 |
return error_mark_node; |
| 5684 |
} |
| 5685 |
attr = build_tree_list (attr_name, NULL_TREE); |
| 5686 |
/* Add this attribute to the list. */ |
| 5687 |
attrs = chainon (attrs, attr); |
| 5688 |
return attrs; |
| 5689 |
} |
| 5690 |
c_parser_consume_token (parser); |
| 5691 |
|
| 5692 |
tree attr_args |
| 5693 |
= c_parser_attribute_arguments (parser, |
| 5694 |
attribute_takes_identifier_p (attr_name), |
| 5695 |
false, |
| 5696 |
is_attribute_p ("assume", attr_name), |
| 5697 |
true); |
| 5698 |
|
| 5699 |
attr = build_tree_list (attr_name, attr_args); |
| 5700 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5701 |
c_parser_consume_token (parser); |
| 5702 |
else |
| 5703 |
{ |
| 5704 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5705 |
"expected %<)%>"); |
| 5706 |
return error_mark_node; |
| 5707 |
} |
| 5708 |
|
| 5709 |
if (expect_comma && !comma_first) |
| 5710 |
{ |
| 5711 |
/* A comma is missing between the last attribute on the chain |
| 5712 |
and this one. */ |
| 5713 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5714 |
"expected %<)%>"); |
| 5715 |
return error_mark_node; |
| 5716 |
} |
| 5717 |
|
| 5718 |
/* Add this attribute to the list. */ |
| 5719 |
attrs = chainon (attrs, attr); |
| 5720 |
return attrs; |
| 5721 |
} |
| 5722 |
|
| 5723 |
static tree |
| 5724 |
c_parser_gnu_attributes (c_parser *parser) |
| 5725 |
{ |
| 5726 |
tree attrs = NULL_TREE; |
| 5727 |
while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 5728 |
{ |
| 5729 |
bool save_translate_strings_p = parser->translate_strings_p; |
| 5730 |
parser->translate_strings_p = false; |
| 5731 |
/* Consume the `__attribute__' keyword. */ |
| 5732 |
c_parser_consume_token (parser); |
| 5733 |
/* Look for the two `(' tokens. */ |
| 5734 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 5735 |
{ |
| 5736 |
parser->translate_strings_p = save_translate_strings_p; |
| 5737 |
return attrs; |
| 5738 |
} |
| 5739 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 5740 |
{ |
| 5741 |
parser->translate_strings_p = save_translate_strings_p; |
| 5742 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 5743 |
return attrs; |
| 5744 |
} |
| 5745 |
/* Parse the attribute list. Require a comma between successive |
| 5746 |
(possibly empty) attributes. */ |
| 5747 |
for (bool expect_comma = false; ; expect_comma = true) |
| 5748 |
{ |
| 5749 |
/* Parse a single attribute. */ |
| 5750 |
tree attr = c_parser_gnu_attribute (parser, attrs, expect_comma); |
| 5751 |
if (attr == error_mark_node) |
| 5752 |
return attrs; |
| 5753 |
if (!attr) |
| 5754 |
break; |
| 5755 |
attrs = attr; |
| 5756 |
} |
| 5757 |
|
| 5758 |
/* Look for the two `)' tokens. */ |
| 5759 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5760 |
c_parser_consume_token (parser); |
| 5761 |
else |
| 5762 |
{ |
| 5763 |
parser->translate_strings_p = save_translate_strings_p; |
| 5764 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5765 |
"expected %<)%>"); |
| 5766 |
return attrs; |
| 5767 |
} |
| 5768 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 5769 |
c_parser_consume_token (parser); |
| 5770 |
else |
| 5771 |
{ |
| 5772 |
parser->translate_strings_p = save_translate_strings_p; |
| 5773 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 5774 |
"expected %<)%>"); |
| 5775 |
return attrs; |
| 5776 |
} |
| 5777 |
parser->translate_strings_p = save_translate_strings_p; |
| 5778 |
} |
| 5779 |
|
| 5780 |
return attrs; |
| 5781 |
} |
| 5782 |
|
| 5783 |
/* Parse an optional balanced token sequence. |
| 5784 |
|
| 5785 |
balanced-token-sequence: |
| 5786 |
balanced-token |
| 5787 |
balanced-token-sequence balanced-token |
| 5788 |
|
| 5789 |
balanced-token: |
| 5790 |
( balanced-token-sequence[opt] ) |
| 5791 |
[ balanced-token-sequence[opt] ] |
| 5792 |
{ balanced-token-sequence[opt] } |
| 5793 |
any token other than ()[]{} |
| 5794 |
*/ |
| 5795 |
|
| 5796 |
static void |
| 5797 |
c_parser_balanced_token_sequence (c_parser *parser) |
| 5798 |
{ |
| 5799 |
while (true) |
| 5800 |
{ |
| 5801 |
c_token *token = c_parser_peek_token (parser); |
| 5802 |
switch (token->type) |
| 5803 |
{ |
| 5804 |
case CPP_OPEN_BRACE: |
| 5805 |
{ |
| 5806 |
matching_braces braces; |
| 5807 |
braces.consume_open (parser); |
| 5808 |
c_parser_balanced_token_sequence (parser); |
| 5809 |
braces.require_close (parser); |
| 5810 |
break; |
| 5811 |
} |
| 5812 |
|
| 5813 |
case CPP_OPEN_PAREN: |
| 5814 |
{ |
| 5815 |
matching_parens parens; |
| 5816 |
parens.consume_open (parser); |
| 5817 |
c_parser_balanced_token_sequence (parser); |
| 5818 |
parens.require_close (parser); |
| 5819 |
break; |
| 5820 |
} |
| 5821 |
|
| 5822 |
case CPP_OPEN_SQUARE: |
| 5823 |
c_parser_consume_token (parser); |
| 5824 |
c_parser_balanced_token_sequence (parser); |
| 5825 |
c_parser_require (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); |
| 5826 |
break; |
| 5827 |
|
| 5828 |
case CPP_CLOSE_BRACE: |
| 5829 |
case CPP_CLOSE_PAREN: |
| 5830 |
case CPP_CLOSE_SQUARE: |
| 5831 |
case CPP_EOF: |
| 5832 |
return; |
| 5833 |
|
| 5834 |
case CPP_PRAGMA: |
| 5835 |
c_parser_consume_pragma (parser); |
| 5836 |
c_parser_skip_to_pragma_eol (parser, false); |
| 5837 |
break; |
| 5838 |
|
| 5839 |
default: |
| 5840 |
c_parser_consume_token (parser); |
| 5841 |
break; |
| 5842 |
} |
| 5843 |
} |
| 5844 |
} |
| 5845 |
|
| 5846 |
static bool c_parser_check_balanced_raw_token_sequence (c_parser *, |
| 5847 |
unsigned int *); |
| 5848 |
|
| 5849 |
/* Parse arguments of omp::directive or omp::decl attribute. |
| 5850 |
|
| 5851 |
directive-name ,[opt] clause-list[opt] |
| 5852 |
|
| 5853 |
For directive just remember the tokens in a vector for subsequent |
| 5854 |
parsing. */ |
| 5855 |
|
| 5856 |
static void |
| 5857 |
c_parser_omp_directive_args (c_parser *parser, tree attribute, bool decl_p) |
| 5858 |
{ |
| 5859 |
unsigned int n = 1; |
| 5860 |
c_token *first = c_parser_peek_token (parser); |
| 5861 |
if (!c_parser_check_balanced_raw_token_sequence (parser, &n) |
| 5862 |
|| (c_parser_peek_nth_token_raw (parser, n)->type |
| 5863 |
!= CPP_CLOSE_PAREN)) |
| 5864 |
{ |
| 5865 |
c_parser_balanced_token_sequence (parser); |
| 5866 |
TREE_VALUE (attribute) = NULL_TREE; |
| 5867 |
return; |
| 5868 |
} |
| 5869 |
if (n == 1) |
| 5870 |
{ |
| 5871 |
error_at (first->location, "expected OpenMP directive name"); |
| 5872 |
TREE_VALUE (attribute) = NULL_TREE; |
| 5873 |
return; |
| 5874 |
} |
| 5875 |
vec<c_token, va_gc> *v; |
| 5876 |
vec_alloc (v, n - 1); |
| 5877 |
for (--n; n; --n) |
| 5878 |
{ |
| 5879 |
c_token *tok = c_parser_peek_token (parser); |
| 5880 |
v->quick_push (*tok); |
| 5881 |
c_parser_consume_token (parser); |
| 5882 |
} |
| 5883 |
tree arg = make_node (C_TOKEN_VEC); |
| 5884 |
C_TOKEN_VEC_TOKENS (arg) = v; |
| 5885 |
if (decl_p) |
| 5886 |
TREE_PUBLIC (arg) = 1; |
| 5887 |
TREE_VALUE (attribute) = tree_cons (NULL_TREE, arg, TREE_VALUE (attribute)); |
| 5888 |
} |
| 5889 |
|
| 5890 |
/* Parse arguments of omp::sequence attribute. |
| 5891 |
|
| 5892 |
omp::[opt] directive-attr [ , omp::[opt] directive-attr ]... */ |
| 5893 |
|
| 5894 |
static void |
| 5895 |
c_parser_omp_sequence_args (c_parser *parser, tree attribute) |
| 5896 |
{ |
| 5897 |
do |
| 5898 |
{ |
| 5899 |
c_token *token = c_parser_peek_token (parser); |
| 5900 |
if (token->type == CPP_NAME |
| 5901 |
&& strcmp (IDENTIFIER_POINTER (token->value), "omp") == 0 |
| 5902 |
&& c_parser_peek_2nd_token (parser)->type == CPP_SCOPE) |
| 5903 |
{ |
| 5904 |
c_parser_consume_token (parser); |
| 5905 |
c_parser_consume_token (parser); |
| 5906 |
token = c_parser_peek_token (parser); |
| 5907 |
} |
| 5908 |
bool directive = false; |
| 5909 |
const char *p; |
| 5910 |
if (token->type != CPP_NAME) |
| 5911 |
p = ""; |
| 5912 |
else |
| 5913 |
p = IDENTIFIER_POINTER (token->value); |
| 5914 |
if (strcmp (p, "directive") == 0) |
| 5915 |
directive = true; |
| 5916 |
else if (strcmp (p, "sequence") != 0) |
| 5917 |
{ |
| 5918 |
error_at (token->location, "expected %<directive%> or %<sequence%>"); |
| 5919 |
unsigned nesting_depth = 0; |
| 5920 |
|
| 5921 |
while (true) |
| 5922 |
{ |
| 5923 |
/* Peek at the next token. */ |
| 5924 |
token = c_parser_peek_token (parser); |
| 5925 |
/* If we've reached the token we want, consume it and stop. */ |
| 5926 |
if ((token->type == CPP_CLOSE_PAREN || token->type == CPP_COMMA) |
| 5927 |
&& !nesting_depth) |
| 5928 |
break; |
| 5929 |
/* If we've run out of tokens, stop. */ |
| 5930 |
if (token->type == CPP_EOF) |
| 5931 |
break; |
| 5932 |
if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
| 5933 |
break; |
| 5934 |
if (token->type == CPP_OPEN_BRACE |
| 5935 |
|| token->type == CPP_OPEN_PAREN |
| 5936 |
|| token->type == CPP_OPEN_SQUARE) |
| 5937 |
++nesting_depth; |
| 5938 |
else if (token->type == CPP_CLOSE_BRACE |
| 5939 |
|| token->type == CPP_CLOSE_PAREN |
| 5940 |
|| token->type == CPP_CLOSE_SQUARE) |
| 5941 |
{ |
| 5942 |
if (nesting_depth-- == 0) |
| 5943 |
break; |
| 5944 |
} |
| 5945 |
/* Consume this token. */ |
| 5946 |
c_parser_consume_token (parser); |
| 5947 |
} |
| 5948 |
if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 5949 |
break; |
| 5950 |
c_parser_consume_token (parser); |
| 5951 |
continue; |
| 5952 |
} |
| 5953 |
c_parser_consume_token (parser); |
| 5954 |
matching_parens parens; |
| 5955 |
if (parens.require_open (parser)) |
| 5956 |
{ |
| 5957 |
if (directive) |
| 5958 |
c_parser_omp_directive_args (parser, attribute, false); |
| 5959 |
else |
| 5960 |
c_parser_omp_sequence_args (parser, attribute); |
| 5961 |
parens.skip_until_found_close (parser); |
| 5962 |
if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 5963 |
break; |
| 5964 |
c_parser_consume_token (parser); |
| 5965 |
} |
| 5966 |
else if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 5967 |
break; |
| 5968 |
else |
| 5969 |
c_parser_consume_token (parser); |
| 5970 |
} |
| 5971 |
while (1); |
| 5972 |
} |
| 5973 |
|
| 5974 |
/* Parse standard (C23) attributes (including GNU attributes in the |
| 5975 |
gnu:: namespace). |
| 5976 |
|
| 5977 |
attribute-specifier-sequence: |
| 5978 |
attribute-specifier-sequence[opt] attribute-specifier |
| 5979 |
|
| 5980 |
attribute-specifier: |
| 5981 |
[ [ attribute-list ] ] |
| 5982 |
|
| 5983 |
attribute-list: |
| 5984 |
attribute[opt] |
| 5985 |
attribute-list, attribute[opt] |
| 5986 |
|
| 5987 |
attribute: |
| 5988 |
attribute-token attribute-argument-clause[opt] |
| 5989 |
|
| 5990 |
attribute-token: |
| 5991 |
standard-attribute |
| 5992 |
attribute-prefixed-token |
| 5993 |
|
| 5994 |
standard-attribute: |
| 5995 |
identifier |
| 5996 |
|
| 5997 |
attribute-prefixed-token: |
| 5998 |
attribute-prefix :: identifier |
| 5999 |
|
| 6000 |
attribute-prefix: |
| 6001 |
identifier |
| 6002 |
|
| 6003 |
attribute-argument-clause: |
| 6004 |
( balanced-token-sequence[opt] ) |
| 6005 |
|
| 6006 |
Keywords are accepted as identifiers for this purpose. |
| 6007 |
|
| 6008 |
As an extension, we permit an attribute-specifier to be: |
| 6009 |
|
| 6010 |
[ [ __extension__ attribute-list ] ] |
| 6011 |
|
| 6012 |
Two colons are then accepted as a synonym for ::. No attempt is made |
| 6013 |
to check whether the colons are immediately adjacent. LOOSE_SCOPE_P |
| 6014 |
indicates whether this relaxation is in effect. */ |
| 6015 |
|
| 6016 |
static tree |
| 6017 |
c_parser_std_attribute (c_parser *parser, bool for_tm) |
| 6018 |
{ |
| 6019 |
c_token *token = c_parser_peek_token (parser); |
| 6020 |
tree ns, name, attribute; |
| 6021 |
|
| 6022 |
/* Parse the attribute-token. */ |
| 6023 |
if (token->type != CPP_NAME && token->type != CPP_KEYWORD) |
| 6024 |
{ |
| 6025 |
c_parser_error (parser, "expected identifier"); |
| 6026 |
return error_mark_node; |
| 6027 |
} |
| 6028 |
name = canonicalize_attr_name (token->value); |
| 6029 |
c_parser_consume_token (parser); |
| 6030 |
if (c_parser_next_token_is (parser, CPP_SCOPE) |
| 6031 |
|| (c_parser_next_token_is (parser, CPP_COLON) |
| 6032 |
&& (c_parser_peek_token (parser)->flags & COLON_SCOPE) != 0 |
| 6033 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
| 6034 |
{ |
| 6035 |
ns = name; |
| 6036 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 6037 |
c_parser_consume_token (parser); |
| 6038 |
c_parser_consume_token (parser); |
| 6039 |
token = c_parser_peek_token (parser); |
| 6040 |
if (token->type != CPP_NAME && token->type != CPP_KEYWORD) |
| 6041 |
{ |
| 6042 |
c_parser_error (parser, "expected identifier"); |
| 6043 |
return error_mark_node; |
| 6044 |
} |
| 6045 |
name = canonicalize_attr_name (token->value); |
| 6046 |
c_parser_consume_token (parser); |
| 6047 |
} |
| 6048 |
else |
| 6049 |
ns = NULL_TREE; |
| 6050 |
attribute = build_tree_list (build_tree_list (ns, name), NULL_TREE); |
| 6051 |
|
| 6052 |
/* Parse the arguments, if any. */ |
| 6053 |
const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (attribute)); |
| 6054 |
if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
| 6055 |
{ |
| 6056 |
if ((flag_openmp || flag_openmp_simd) |
| 6057 |
&& ns |
| 6058 |
&& is_attribute_p ("omp", ns) |
| 6059 |
&& (is_attribute_p ("directive", name) |
| 6060 |
|| is_attribute_p ("sequence", name) |
| 6061 |
|| is_attribute_p ("decl", name))) |
| 6062 |
{ |
| 6063 |
error ("%<omp::%E%> attribute requires argument", name); |
| 6064 |
return error_mark_node; |
| 6065 |
} |
| 6066 |
goto out; |
| 6067 |
} |
| 6068 |
{ |
| 6069 |
location_t open_loc = c_parser_peek_token (parser)->location; |
| 6070 |
matching_parens parens; |
| 6071 |
parens.consume_open (parser); |
| 6072 |
if ((as && as->max_length == 0) |
| 6073 |
/* Special-case the transactional-memory attribute "outer", |
| 6074 |
which is specially handled but not registered as an |
| 6075 |
attribute, to avoid allowing arbitrary balanced token |
| 6076 |
sequences as arguments. */ |
| 6077 |
|| is_attribute_p ("outer", name)) |
| 6078 |
{ |
| 6079 |
error_at (open_loc, "%qE attribute does not take any arguments", name); |
| 6080 |
parens.skip_until_found_close (parser); |
| 6081 |
return error_mark_node; |
| 6082 |
} |
| 6083 |
/* If this is a fake attribute created to handle -Wno-attributes, |
| 6084 |
we must skip parsing the arguments. */ |
| 6085 |
if (as && !attribute_ignored_p (as)) |
| 6086 |
{ |
| 6087 |
bool takes_identifier |
| 6088 |
= (ns != NULL_TREE |
| 6089 |
&& strcmp (IDENTIFIER_POINTER (ns), "gnu") == 0 |
| 6090 |
&& attribute_takes_identifier_p (name)); |
| 6091 |
bool require_string |
| 6092 |
= (ns == NULL_TREE |
| 6093 |
&& (strcmp (IDENTIFIER_POINTER (name), "deprecated") == 0 |
| 6094 |
|| strcmp (IDENTIFIER_POINTER (name), "nodiscard") == 0)); |
| 6095 |
bool assume_attr |
| 6096 |
= (ns != NULL_TREE |
| 6097 |
&& strcmp (IDENTIFIER_POINTER (ns), "gnu") == 0 |
| 6098 |
&& strcmp (IDENTIFIER_POINTER (name), "assume") == 0); |
| 6099 |
TREE_VALUE (attribute) |
| 6100 |
= c_parser_attribute_arguments (parser, takes_identifier, |
| 6101 |
require_string, assume_attr, false); |
| 6102 |
} |
| 6103 |
else |
| 6104 |
{ |
| 6105 |
if ((flag_openmp || flag_openmp_simd) |
| 6106 |
&& ns |
| 6107 |
&& is_attribute_p ("omp", ns)) |
| 6108 |
{ |
| 6109 |
if (is_attribute_p ("directive", name)) |
| 6110 |
{ |
| 6111 |
c_parser_omp_directive_args (parser, attribute, false); |
| 6112 |
parens.skip_until_found_close (parser); |
| 6113 |
return attribute; |
| 6114 |
} |
| 6115 |
else if (is_attribute_p ("decl", name)) |
| 6116 |
{ |
| 6117 |
TREE_VALUE (TREE_PURPOSE (attribute)) |
| 6118 |
= get_identifier ("directive"); |
| 6119 |
c_parser_omp_directive_args (parser, attribute, true); |
| 6120 |
parens.skip_until_found_close (parser); |
| 6121 |
return attribute; |
| 6122 |
} |
| 6123 |
else if (is_attribute_p ("sequence", name)) |
| 6124 |
{ |
| 6125 |
TREE_VALUE (TREE_PURPOSE (attribute)) |
| 6126 |
= get_identifier ("directive"); |
| 6127 |
c_parser_omp_sequence_args (parser, attribute); |
| 6128 |
parens.skip_until_found_close (parser); |
| 6129 |
TREE_VALUE (attribute) = nreverse (TREE_VALUE (attribute)); |
| 6130 |
return attribute; |
| 6131 |
} |
| 6132 |
} |
| 6133 |
c_parser_balanced_token_sequence (parser); |
| 6134 |
} |
| 6135 |
parens.require_close (parser); |
| 6136 |
} |
| 6137 |
out: |
| 6138 |
if (ns == NULL_TREE && !for_tm && !as) |
| 6139 |
{ |
| 6140 |
/* An attribute with standard syntax and no namespace specified |
| 6141 |
is a constraint violation if it is not one of the known |
| 6142 |
standard attributes. Diagnose it here with a pedwarn and |
| 6143 |
then discard it to prevent a duplicate warning later. */ |
| 6144 |
pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored", |
| 6145 |
name); |
| 6146 |
return error_mark_node; |
| 6147 |
} |
| 6148 |
return attribute; |
| 6149 |
} |
| 6150 |
|
| 6151 |
static tree |
| 6152 |
c_parser_std_attribute_list (c_parser *parser, bool for_tm) |
| 6153 |
{ |
| 6154 |
tree attributes = NULL_TREE; |
| 6155 |
while (true) |
| 6156 |
{ |
| 6157 |
c_token *token = c_parser_peek_token (parser); |
| 6158 |
if (token->type == CPP_CLOSE_SQUARE) |
| 6159 |
break; |
| 6160 |
if (token->type == CPP_COMMA) |
| 6161 |
{ |
| 6162 |
c_parser_consume_token (parser); |
| 6163 |
continue; |
| 6164 |
} |
| 6165 |
tree attribute = c_parser_std_attribute (parser, for_tm); |
| 6166 |
if (attribute != error_mark_node) |
| 6167 |
{ |
| 6168 |
TREE_CHAIN (attribute) = attributes; |
| 6169 |
attributes = attribute; |
| 6170 |
} |
| 6171 |
if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 6172 |
break; |
| 6173 |
} |
| 6174 |
return attributes; |
| 6175 |
} |
| 6176 |
|
| 6177 |
static tree |
| 6178 |
c_parser_std_attribute_specifier (c_parser *parser, bool for_tm) |
| 6179 |
{ |
| 6180 |
location_t loc = c_parser_peek_token (parser)->location; |
| 6181 |
if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>")) |
| 6182 |
return NULL_TREE; |
| 6183 |
if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>")) |
| 6184 |
{ |
| 6185 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); |
| 6186 |
return NULL_TREE; |
| 6187 |
} |
| 6188 |
tree attributes; |
| 6189 |
if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
| 6190 |
{ |
| 6191 |
auto ext = disable_extension_diagnostics (); |
| 6192 |
c_parser_consume_token (parser); |
| 6193 |
attributes = c_parser_std_attribute_list (parser, for_tm); |
| 6194 |
restore_extension_diagnostics (ext); |
| 6195 |
} |
| 6196 |
else |
| 6197 |
{ |
| 6198 |
if (!for_tm) |
| 6199 |
pedwarn_c11 (loc, OPT_Wpedantic, |
| 6200 |
"ISO C does not support %<[[]]%> attributes before C23"); |
| 6201 |
attributes = c_parser_std_attribute_list (parser, for_tm); |
| 6202 |
} |
| 6203 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); |
| 6204 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); |
| 6205 |
return nreverse (attributes); |
| 6206 |
} |
| 6207 |
|
| 6208 |
/* Look past an optional balanced token sequence of raw look-ahead |
| 6209 |
tokens starting with the *Nth token. *N is updated to point to the |
| 6210 |
following token. Return true if such a sequence was found, false |
| 6211 |
if the tokens parsed were not balanced. */ |
| 6212 |
|
| 6213 |
static bool |
| 6214 |
c_parser_check_balanced_raw_token_sequence (c_parser *parser, unsigned int *n) |
| 6215 |
{ |
| 6216 |
while (true) |
| 6217 |
{ |
| 6218 |
c_token *token = c_parser_peek_nth_token_raw (parser, *n); |
| 6219 |
switch (token->type) |
| 6220 |
{ |
| 6221 |
case CPP_OPEN_BRACE: |
| 6222 |
{ |
| 6223 |
++*n; |
| 6224 |
if (c_parser_check_balanced_raw_token_sequence (parser, n)) |
| 6225 |
{ |
| 6226 |
token = c_parser_peek_nth_token_raw (parser, *n); |
| 6227 |
if (token->type == CPP_CLOSE_BRACE) |
| 6228 |
++*n; |
| 6229 |
else |
| 6230 |
return false; |
| 6231 |
} |
| 6232 |
else |
| 6233 |
return false; |
| 6234 |
break; |
| 6235 |
} |
| 6236 |
|
| 6237 |
case CPP_OPEN_PAREN: |
| 6238 |
{ |
| 6239 |
++*n; |
| 6240 |
if (c_parser_check_balanced_raw_token_sequence (parser, n)) |
| 6241 |
{ |
| 6242 |
token = c_parser_peek_nth_token_raw (parser, *n); |
| 6243 |
if (token->type == CPP_CLOSE_PAREN) |
| 6244 |
++*n; |
| 6245 |
else |
| 6246 |
return false; |
| 6247 |
} |
| 6248 |
else |
| 6249 |
return false; |
| 6250 |
break; |
| 6251 |
} |
| 6252 |
|
| 6253 |
case CPP_OPEN_SQUARE: |
| 6254 |
{ |
| 6255 |
++*n; |
| 6256 |
if (c_parser_check_balanced_raw_token_sequence (parser, n)) |
| 6257 |
{ |
| 6258 |
token = c_parser_peek_nth_token_raw (parser, *n); |
| 6259 |
if (token->type == CPP_CLOSE_SQUARE) |
| 6260 |
++*n; |
| 6261 |
else |
| 6262 |
return false; |
| 6263 |
} |
| 6264 |
else |
| 6265 |
return false; |
| 6266 |
break; |
| 6267 |
} |
| 6268 |
|
| 6269 |
case CPP_CLOSE_BRACE: |
| 6270 |
case CPP_CLOSE_PAREN: |
| 6271 |
case CPP_CLOSE_SQUARE: |
| 6272 |
case CPP_EOF: |
| 6273 |
return true; |
| 6274 |
|
| 6275 |
default: |
| 6276 |
++*n; |
| 6277 |
break; |
| 6278 |
} |
| 6279 |
} |
| 6280 |
} |
| 6281 |
|
| 6282 |
/* Return whether standard attributes start with the Nth token. */ |
| 6283 |
|
| 6284 |
static bool |
| 6285 |
c_parser_nth_token_starts_std_attributes (c_parser *parser, unsigned int n) |
| 6286 |
{ |
| 6287 |
if (!(c_parser_peek_nth_token (parser, n)->type == CPP_OPEN_SQUARE |
| 6288 |
&& c_parser_peek_nth_token (parser, n + 1)->type == CPP_OPEN_SQUARE)) |
| 6289 |
return false; |
| 6290 |
/* In C, '[[' must start attributes. In Objective-C, we need to |
| 6291 |
check whether '[[' is matched by ']]'. */ |
| 6292 |
if (!c_dialect_objc ()) |
| 6293 |
return true; |
| 6294 |
n += 2; |
| 6295 |
if (!c_parser_check_balanced_raw_token_sequence (parser, &n)) |
| 6296 |
return false; |
| 6297 |
c_token *token = c_parser_peek_nth_token_raw (parser, n); |
| 6298 |
if (token->type != CPP_CLOSE_SQUARE) |
| 6299 |
return false; |
| 6300 |
token = c_parser_peek_nth_token_raw (parser, n + 1); |
| 6301 |
return token->type == CPP_CLOSE_SQUARE; |
| 6302 |
} |
| 6303 |
|
| 6304 |
/* Skip standard attribute tokens starting at Nth token (with 1 as the |
| 6305 |
next token), return index of the first token after the standard |
| 6306 |
attribute tokens, or N on failure. */ |
| 6307 |
|
| 6308 |
static size_t |
| 6309 |
c_parser_skip_std_attribute_spec_seq (c_parser *parser, size_t n) |
| 6310 |
{ |
| 6311 |
size_t orig_n = n; |
| 6312 |
while (true) |
| 6313 |
{ |
| 6314 |
if (c_parser_peek_nth_token_raw (parser, n)->type == CPP_OPEN_SQUARE |
| 6315 |
&& (c_parser_peek_nth_token_raw (parser, n + 1)->type |
| 6316 |
== CPP_OPEN_SQUARE)) |
| 6317 |
{ |
| 6318 |
unsigned int m = n + 2; |
| 6319 |
if (!c_parser_check_balanced_raw_token_sequence (parser, &m)) |
| 6320 |
return orig_n; |
| 6321 |
c_token *token = c_parser_peek_nth_token_raw (parser, m); |
| 6322 |
if (token->type != CPP_CLOSE_SQUARE) |
| 6323 |
return orig_n; |
| 6324 |
token = c_parser_peek_nth_token_raw (parser, m + 1); |
| 6325 |
if (token->type != CPP_CLOSE_SQUARE) |
| 6326 |
return orig_n; |
| 6327 |
n = m + 2; |
| 6328 |
} |
| 6329 |
else |
| 6330 |
break; |
| 6331 |
} |
| 6332 |
return n; |
| 6333 |
} |
| 6334 |
|
| 6335 |
static tree |
| 6336 |
c_parser_std_attribute_specifier_sequence (c_parser *parser) |
| 6337 |
{ |
| 6338 |
tree attributes = NULL_TREE; |
| 6339 |
do |
| 6340 |
{ |
| 6341 |
tree attrs = c_parser_std_attribute_specifier (parser, false); |
| 6342 |
attributes = chainon (attributes, attrs); |
| 6343 |
} |
| 6344 |
while (c_parser_nth_token_starts_std_attributes (parser, 1)); |
| 6345 |
return attributes; |
| 6346 |
} |
| 6347 |
|
| 6348 |
/* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK |
| 6349 |
says whether alignment specifiers are OK (only in cases that might |
| 6350 |
be the type name of a compound literal). |
| 6351 |
|
| 6352 |
type-name: |
| 6353 |
specifier-qualifier-list abstract-declarator[opt] |
| 6354 |
*/ |
| 6355 |
|
| 6356 |
struct c_type_name * |
| 6357 |
c_parser_type_name (c_parser *parser, bool alignas_ok) |
| 6358 |
{ |
| 6359 |
struct c_declspecs *specs = build_null_declspecs (); |
| 6360 |
struct c_declarator *declarator; |
| 6361 |
struct c_type_name *ret; |
| 6362 |
bool dummy = false; |
| 6363 |
c_parser_declspecs (parser, specs, false, true, true, alignas_ok, false, |
| 6364 |
false, true, cla_prefer_type); |
| 6365 |
if (!specs->declspecs_seen_p) |
| 6366 |
{ |
| 6367 |
c_parser_error (parser, "expected specifier-qualifier-list"); |
| 6368 |
return NULL; |
| 6369 |
} |
| 6370 |
if (specs->type != error_mark_node) |
| 6371 |
{ |
| 6372 |
pending_xref_error (); |
| 6373 |
finish_declspecs (specs); |
| 6374 |
} |
| 6375 |
declarator = c_parser_declarator (parser, |
| 6376 |
specs->typespec_kind != ctsk_none, |
| 6377 |
C_DTR_ABSTRACT, &dummy); |
| 6378 |
if (declarator == NULL) |
| 6379 |
return NULL; |
| 6380 |
ret = XOBNEW (&parser_obstack, struct c_type_name); |
| 6381 |
ret->specs = specs; |
| 6382 |
ret->declarator = declarator; |
| 6383 |
return ret; |
| 6384 |
} |
| 6385 |
|
| 6386 |
/* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9). |
| 6387 |
|
| 6388 |
initializer: |
| 6389 |
assignment-expression |
| 6390 |
{ initializer-list } |
| 6391 |
{ initializer-list , } |
| 6392 |
|
| 6393 |
initializer-list: |
| 6394 |
designation[opt] initializer |
| 6395 |
initializer-list , designation[opt] initializer |
| 6396 |
|
| 6397 |
designation: |
| 6398 |
designator-list = |
| 6399 |
|
| 6400 |
designator-list: |
| 6401 |
designator |
| 6402 |
designator-list designator |
| 6403 |
|
| 6404 |
designator: |
| 6405 |
array-designator |
| 6406 |
. identifier |
| 6407 |
|
| 6408 |
array-designator: |
| 6409 |
[ constant-expression ] |
| 6410 |
|
| 6411 |
GNU extensions: |
| 6412 |
|
| 6413 |
initializer: |
| 6414 |
{ } |
| 6415 |
|
| 6416 |
designation: |
| 6417 |
array-designator |
| 6418 |
identifier : |
| 6419 |
|
| 6420 |
array-designator: |
| 6421 |
[ constant-expression ... constant-expression ] |
| 6422 |
|
| 6423 |
Any expression without commas is accepted in the syntax for the |
| 6424 |
constant-expressions, with non-constant expressions rejected later. |
| 6425 |
|
| 6426 |
DECL is the declaration we're parsing this initializer for. |
| 6427 |
|
| 6428 |
This function is only used for top-level initializers; for nested |
| 6429 |
ones, see c_parser_initval. */ |
| 6430 |
|
| 6431 |
static struct c_expr |
| 6432 |
c_parser_initializer (c_parser *parser, tree decl) |
| 6433 |
{ |
| 6434 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 6435 |
return c_parser_braced_init (parser, NULL_TREE, false, NULL, decl); |
| 6436 |
else |
| 6437 |
{ |
| 6438 |
struct c_expr ret; |
| 6439 |
location_t loc = c_parser_peek_token (parser)->location; |
| 6440 |
ret = c_parser_expr_no_commas (parser, NULL); |
| 6441 |
if (decl != error_mark_node && C_DECL_VARIABLE_SIZE (decl)) |
| 6442 |
{ |
| 6443 |
error_at (loc, |
| 6444 |
"variable-sized object may not be initialized except " |
| 6445 |
"with an empty initializer"); |
| 6446 |
ret.set_error (); |
| 6447 |
} |
| 6448 |
/* This is handled mostly by gimplify.cc, but we have to deal with |
| 6449 |
not warning about int x = x; as it is a GCC extension to turn off |
| 6450 |
this warning but only if warn_init_self is zero. */ |
| 6451 |
if (VAR_P (decl) |
| 6452 |
&& !DECL_EXTERNAL (decl) |
| 6453 |
&& !TREE_STATIC (decl) |
| 6454 |
&& ret.value == decl |
| 6455 |
&& !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self)) |
| 6456 |
suppress_warning (decl, OPT_Winit_self); |
| 6457 |
if (TREE_CODE (ret.value) != STRING_CST |
| 6458 |
&& (TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR |
| 6459 |
|| C_DECL_DECLARED_CONSTEXPR (COMPOUND_LITERAL_EXPR_DECL |
| 6460 |
(ret.value)))) |
| 6461 |
ret = convert_lvalue_to_rvalue (loc, ret, true, true, true); |
| 6462 |
return ret; |
| 6463 |
} |
| 6464 |
} |
| 6465 |
|
| 6466 |
/* The location of the last comma within the current initializer list, |
| 6467 |
or UNKNOWN_LOCATION if not within one. */ |
| 6468 |
|
| 6469 |
location_t last_init_list_comma; |
| 6470 |
|
| 6471 |
/* Parse a braced initializer list. TYPE is the type specified for a |
| 6472 |
compound literal, and NULL_TREE for other initializers and for |
| 6473 |
nested braced lists. NESTED_P is true for nested braced lists, |
| 6474 |
false for the list of a compound literal or the list that is the |
| 6475 |
top-level initializer in a declaration. DECL is the declaration for |
| 6476 |
the top-level initializer for a declaration, otherwise NULL_TREE. */ |
| 6477 |
|
| 6478 |
static struct c_expr |
| 6479 |
c_parser_braced_init (c_parser *parser, tree type, bool nested_p, |
| 6480 |
struct obstack *outer_obstack, tree decl) |
| 6481 |
{ |
| 6482 |
struct c_expr ret; |
| 6483 |
struct obstack braced_init_obstack; |
| 6484 |
location_t brace_loc = c_parser_peek_token (parser)->location; |
| 6485 |
gcc_obstack_init (&braced_init_obstack); |
| 6486 |
gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); |
| 6487 |
bool save_c_omp_array_section_p = c_omp_array_section_p; |
| 6488 |
c_omp_array_section_p = false; |
| 6489 |
bool zero_init_padding_bits = false; |
| 6490 |
matching_braces braces; |
| 6491 |
braces.consume_open (parser); |
| 6492 |
if (nested_p) |
| 6493 |
{ |
| 6494 |
finish_implicit_inits (brace_loc, outer_obstack); |
| 6495 |
push_init_level (brace_loc, 0, &braced_init_obstack); |
| 6496 |
} |
| 6497 |
else |
| 6498 |
really_start_incremental_init (type); |
| 6499 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 6500 |
{ |
| 6501 |
pedwarn_c11 (brace_loc, OPT_Wpedantic, |
| 6502 |
"ISO C forbids empty initializer braces before C23"); |
| 6503 |
if (flag_isoc23) |
| 6504 |
zero_init_padding_bits = true; |
| 6505 |
} |
| 6506 |
else |
| 6507 |
{ |
| 6508 |
if (decl && decl != error_mark_node && C_DECL_VARIABLE_SIZE (decl)) |
| 6509 |
error_at (brace_loc, |
| 6510 |
"variable-sized object may not be initialized except " |
| 6511 |
"with an empty initializer"); |
| 6512 |
/* Parse a non-empty initializer list, possibly with a trailing |
| 6513 |
comma. */ |
| 6514 |
while (true) |
| 6515 |
{ |
| 6516 |
c_parser_initelt (parser, &braced_init_obstack); |
| 6517 |
if (parser->error) |
| 6518 |
break; |
| 6519 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 6520 |
{ |
| 6521 |
last_init_list_comma = c_parser_peek_token (parser)->location; |
| 6522 |
c_parser_consume_token (parser); |
| 6523 |
/* CPP_EMBED should be always in between two CPP_COMMA |
| 6524 |
tokens. */ |
| 6525 |
while (c_parser_next_token_is (parser, CPP_EMBED)) |
| 6526 |
{ |
| 6527 |
c_token *embed = c_parser_peek_token (parser); |
| 6528 |
c_parser_consume_token (parser); |
| 6529 |
c_expr embed_val; |
| 6530 |
embed_val.value = embed->value; |
| 6531 |
embed_val.original_code = RAW_DATA_CST; |
| 6532 |
embed_val.original_type = integer_type_node; |
| 6533 |
set_c_expr_source_range (&embed_val, embed->get_range ()); |
| 6534 |
embed_val.m_decimal = 0; |
| 6535 |
process_init_element (embed->location, embed_val, false, |
| 6536 |
&braced_init_obstack); |
| 6537 |
gcc_checking_assert (c_parser_next_token_is (parser, |
| 6538 |
CPP_COMMA)); |
| 6539 |
last_init_list_comma = c_parser_peek_token (parser)->location; |
| 6540 |
c_parser_consume_token (parser); |
| 6541 |
} |
| 6542 |
} |
| 6543 |
else |
| 6544 |
break; |
| 6545 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 6546 |
break; |
| 6547 |
} |
| 6548 |
} |
| 6549 |
c_omp_array_section_p = save_c_omp_array_section_p; |
| 6550 |
c_token *next_tok = c_parser_peek_token (parser); |
| 6551 |
if (next_tok->type != CPP_CLOSE_BRACE) |
| 6552 |
{ |
| 6553 |
ret.set_error (); |
| 6554 |
ret.original_code = ERROR_MARK; |
| 6555 |
ret.original_type = NULL; |
| 6556 |
braces.skip_until_found_close (parser); |
| 6557 |
pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma); |
| 6558 |
obstack_free (&braced_init_obstack, NULL); |
| 6559 |
return ret; |
| 6560 |
} |
| 6561 |
location_t close_loc = next_tok->location; |
| 6562 |
c_parser_consume_token (parser); |
| 6563 |
ret = pop_init_level (brace_loc, 0, &braced_init_obstack, close_loc); |
| 6564 |
if (zero_init_padding_bits |
| 6565 |
&& ret.value |
| 6566 |
&& TREE_CODE (ret.value) == CONSTRUCTOR) |
| 6567 |
CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1; |
| 6568 |
obstack_free (&braced_init_obstack, NULL); |
| 6569 |
set_c_expr_source_range (&ret, brace_loc, close_loc); |
| 6570 |
return ret; |
| 6571 |
} |
| 6572 |
|
| 6573 |
/* Parse a nested initializer, including designators. */ |
| 6574 |
|
| 6575 |
static void |
| 6576 |
c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) |
| 6577 |
{ |
| 6578 |
/* Parse any designator or designator list. A single array |
| 6579 |
designator may have the subsequent "=" omitted in GNU C, but a |
| 6580 |
longer list or a structure member designator may not. */ |
| 6581 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 6582 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 6583 |
{ |
| 6584 |
/* Old-style structure member designator. */ |
| 6585 |
set_init_label (c_parser_peek_token (parser)->location, |
| 6586 |
c_parser_peek_token (parser)->value, |
| 6587 |
c_parser_peek_token (parser)->location, |
| 6588 |
braced_init_obstack); |
| 6589 |
/* Use the colon as the error location. */ |
| 6590 |
pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic, |
| 6591 |
"obsolete use of designated initializer with %<:%>"); |
| 6592 |
c_parser_consume_token (parser); |
| 6593 |
c_parser_consume_token (parser); |
| 6594 |
} |
| 6595 |
else |
| 6596 |
{ |
| 6597 |
/* des_seen is 0 if there have been no designators, 1 if there |
| 6598 |
has been a single array designator and 2 otherwise. */ |
| 6599 |
int des_seen = 0; |
| 6600 |
/* Location of a designator. */ |
| 6601 |
location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 6602 |
while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
| 6603 |
|| c_parser_next_token_is (parser, CPP_DOT)) |
| 6604 |
{ |
| 6605 |
int des_prev = des_seen; |
| 6606 |
if (!des_seen) |
| 6607 |
des_loc = c_parser_peek_token (parser)->location; |
| 6608 |
if (des_seen < 2) |
| 6609 |
des_seen++; |
| 6610 |
if (c_parser_next_token_is (parser, CPP_DOT)) |
| 6611 |
{ |
| 6612 |
des_seen = 2; |
| 6613 |
c_parser_consume_token (parser); |
| 6614 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 6615 |
{ |
| 6616 |
set_init_label (des_loc, c_parser_peek_token (parser)->value, |
| 6617 |
c_parser_peek_token (parser)->location, |
| 6618 |
braced_init_obstack); |
| 6619 |
c_parser_consume_token (parser); |
| 6620 |
} |
| 6621 |
else |
| 6622 |
{ |
| 6623 |
struct c_expr init; |
| 6624 |
init.set_error (); |
| 6625 |
init.original_code = ERROR_MARK; |
| 6626 |
init.original_type = NULL; |
| 6627 |
c_parser_error (parser, "expected identifier"); |
| 6628 |
c_parser_skip_until_found (parser, CPP_COMMA, NULL); |
| 6629 |
process_init_element (input_location, init, false, |
| 6630 |
braced_init_obstack); |
| 6631 |
return; |
| 6632 |
} |
| 6633 |
} |
| 6634 |
else |
| 6635 |
{ |
| 6636 |
struct c_expr first_expr; |
| 6637 |
tree first, second; |
| 6638 |
location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 6639 |
location_t array_index_loc = UNKNOWN_LOCATION; |
| 6640 |
/* ??? Following the old parser, [ objc-receiver |
| 6641 |
objc-message-args ] is accepted as an initializer, |
| 6642 |
being distinguished from a designator by what follows |
| 6643 |
the first assignment expression inside the square |
| 6644 |
brackets, but after a first array designator a |
| 6645 |
subsequent square bracket is for Objective-C taken to |
| 6646 |
start an expression, using the obsolete form of |
| 6647 |
designated initializer without '=', rather than |
| 6648 |
possibly being a second level of designation: in LALR |
| 6649 |
terms, the '[' is shifted rather than reducing |
| 6650 |
designator to designator-list. */ |
| 6651 |
if (des_prev == 1 && c_dialect_objc ()) |
| 6652 |
{ |
| 6653 |
des_seen = des_prev; |
| 6654 |
break; |
| 6655 |
} |
| 6656 |
if (des_prev == 0 && c_dialect_objc ()) |
| 6657 |
{ |
| 6658 |
/* This might be an array designator or an |
| 6659 |
Objective-C message expression. If the former, |
| 6660 |
continue parsing here; if the latter, parse the |
| 6661 |
remainder of the initializer given the starting |
| 6662 |
primary-expression. ??? It might make sense to |
| 6663 |
distinguish when des_prev == 1 as well; see |
| 6664 |
previous comment. */ |
| 6665 |
tree rec, args; |
| 6666 |
struct c_expr mexpr; |
| 6667 |
c_parser_consume_token (parser); |
| 6668 |
if (c_parser_peek_token (parser)->type == CPP_NAME |
| 6669 |
&& ((c_parser_peek_token (parser)->id_kind |
| 6670 |
== C_ID_TYPENAME) |
| 6671 |
|| (c_parser_peek_token (parser)->id_kind |
| 6672 |
== C_ID_CLASSNAME))) |
| 6673 |
{ |
| 6674 |
/* Type name receiver. */ |
| 6675 |
tree id = c_parser_peek_token (parser)->value; |
| 6676 |
c_parser_consume_token (parser); |
| 6677 |
rec = objc_get_class_reference (id); |
| 6678 |
goto parse_message_args; |
| 6679 |
} |
| 6680 |
array_index_loc = c_parser_peek_token (parser)->location; |
| 6681 |
first_expr = c_parser_expr_no_commas (parser, NULL); |
| 6682 |
mark_exp_read (first_expr.value); |
| 6683 |
if (c_parser_next_token_is (parser, CPP_ELLIPSIS) |
| 6684 |
|| c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 6685 |
goto array_desig_after_first; |
| 6686 |
first = first_expr.value; |
| 6687 |
/* Expression receiver. So far only one part |
| 6688 |
without commas has been parsed; there might be |
| 6689 |
more of the expression. */ |
| 6690 |
rec = first; |
| 6691 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 6692 |
{ |
| 6693 |
struct c_expr next; |
| 6694 |
location_t comma_loc, exp_loc; |
| 6695 |
comma_loc = c_parser_peek_token (parser)->location; |
| 6696 |
c_parser_consume_token (parser); |
| 6697 |
exp_loc = c_parser_peek_token (parser)->location; |
| 6698 |
next = c_parser_expr_no_commas (parser, NULL); |
| 6699 |
next = convert_lvalue_to_rvalue (exp_loc, next, |
| 6700 |
true, true); |
| 6701 |
rec = build_compound_expr (comma_loc, rec, next.value); |
| 6702 |
} |
| 6703 |
parse_message_args: |
| 6704 |
/* Now parse the objc-message-args. */ |
| 6705 |
args = c_parser_objc_message_args (parser); |
| 6706 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 6707 |
"expected %<]%>"); |
| 6708 |
mexpr.value |
| 6709 |
= objc_build_message_expr (rec, args); |
| 6710 |
mexpr.original_code = ERROR_MARK; |
| 6711 |
mexpr.original_type = NULL; |
| 6712 |
mexpr.m_decimal = 0; |
| 6713 |
/* Now parse and process the remainder of the |
| 6714 |
initializer, starting with this message |
| 6715 |
expression as a primary-expression. */ |
| 6716 |
c_parser_initval (parser, &mexpr, braced_init_obstack); |
| 6717 |
return; |
| 6718 |
} |
| 6719 |
c_parser_consume_token (parser); |
| 6720 |
array_index_loc = c_parser_peek_token (parser)->location; |
| 6721 |
first_expr = c_parser_expr_no_commas (parser, NULL); |
| 6722 |
mark_exp_read (first_expr.value); |
| 6723 |
array_desig_after_first: |
| 6724 |
first_expr = convert_lvalue_to_rvalue (array_index_loc, |
| 6725 |
first_expr, |
| 6726 |
true, true); |
| 6727 |
first = first_expr.value; |
| 6728 |
if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 6729 |
{ |
| 6730 |
ellipsis_loc = c_parser_peek_token (parser)->location; |
| 6731 |
c_parser_consume_token (parser); |
| 6732 |
second = convert_lvalue_to_rvalue (ellipsis_loc, |
| 6733 |
(c_parser_expr_no_commas |
| 6734 |
(parser, NULL)), |
| 6735 |
true, true).value; |
| 6736 |
mark_exp_read (second); |
| 6737 |
} |
| 6738 |
else |
| 6739 |
second = NULL_TREE; |
| 6740 |
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 6741 |
{ |
| 6742 |
c_parser_consume_token (parser); |
| 6743 |
set_init_index (array_index_loc, first, second, |
| 6744 |
braced_init_obstack); |
| 6745 |
if (second) |
| 6746 |
pedwarn (ellipsis_loc, OPT_Wpedantic, |
| 6747 |
"ISO C forbids specifying range of elements to initialize"); |
| 6748 |
} |
| 6749 |
else |
| 6750 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 6751 |
"expected %<]%>"); |
| 6752 |
} |
| 6753 |
} |
| 6754 |
if (des_seen >= 1) |
| 6755 |
{ |
| 6756 |
if (c_parser_next_token_is (parser, CPP_EQ)) |
| 6757 |
{ |
| 6758 |
pedwarn_c90 (des_loc, OPT_Wpedantic, |
| 6759 |
"ISO C90 forbids specifying subobject " |
| 6760 |
"to initialize"); |
| 6761 |
c_parser_consume_token (parser); |
| 6762 |
} |
| 6763 |
else |
| 6764 |
{ |
| 6765 |
if (des_seen == 1) |
| 6766 |
pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 6767 |
"obsolete use of designated initializer without %<=%>"); |
| 6768 |
else |
| 6769 |
{ |
| 6770 |
struct c_expr init; |
| 6771 |
init.set_error (); |
| 6772 |
init.original_code = ERROR_MARK; |
| 6773 |
init.original_type = NULL; |
| 6774 |
c_parser_error (parser, "expected %<=%>"); |
| 6775 |
c_parser_skip_until_found (parser, CPP_COMMA, NULL); |
| 6776 |
process_init_element (input_location, init, false, |
| 6777 |
braced_init_obstack); |
| 6778 |
return; |
| 6779 |
} |
| 6780 |
} |
| 6781 |
} |
| 6782 |
} |
| 6783 |
c_parser_initval (parser, NULL, braced_init_obstack); |
| 6784 |
} |
| 6785 |
|
| 6786 |
/* Parse a nested initializer; as c_parser_initializer but parses |
| 6787 |
initializers within braced lists, after any designators have been |
| 6788 |
applied. If AFTER is not NULL then it is an Objective-C message |
| 6789 |
expression which is the primary-expression starting the |
| 6790 |
initializer. */ |
| 6791 |
|
| 6792 |
static void |
| 6793 |
c_parser_initval (c_parser *parser, struct c_expr *after, |
| 6794 |
struct obstack * braced_init_obstack) |
| 6795 |
{ |
| 6796 |
struct c_expr init; |
| 6797 |
gcc_assert (!after || c_dialect_objc ()); |
| 6798 |
location_t loc = c_parser_peek_token (parser)->location; |
| 6799 |
|
| 6800 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after) |
| 6801 |
init = c_parser_braced_init (parser, NULL_TREE, true, |
| 6802 |
braced_init_obstack, NULL_TREE); |
| 6803 |
else |
| 6804 |
{ |
| 6805 |
init = c_parser_expr_no_commas (parser, after); |
| 6806 |
if (init.value != NULL_TREE |
| 6807 |
&& TREE_CODE (init.value) != STRING_CST |
| 6808 |
&& (TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR |
| 6809 |
|| C_DECL_DECLARED_CONSTEXPR (COMPOUND_LITERAL_EXPR_DECL |
| 6810 |
(init.value)))) |
| 6811 |
init = convert_lvalue_to_rvalue (loc, init, true, true, true); |
| 6812 |
} |
| 6813 |
tree val = init.value; |
| 6814 |
process_init_element (loc, init, false, braced_init_obstack); |
| 6815 |
|
| 6816 |
/* Attempt to optimize large char array initializers into RAW_DATA_CST |
| 6817 |
to save compile time and memory even when not using #embed. */ |
| 6818 |
static unsigned vals_to_ignore; |
| 6819 |
if (vals_to_ignore) |
| 6820 |
/* If earlier call determined there is certain number of CPP_COMMA |
| 6821 |
CPP_NUMBER tokens with 0-255 int values, but not enough for |
| 6822 |
RAW_DATA_CST to be beneficial, don't try to check it again until |
| 6823 |
they are all parsed. */ |
| 6824 |
--vals_to_ignore; |
| 6825 |
else if (val |
| 6826 |
&& TREE_CODE (val) == INTEGER_CST |
| 6827 |
&& TREE_TYPE (val) == integer_type_node |
| 6828 |
&& c_parser_next_token_is (parser, CPP_COMMA)) |
| 6829 |
if (unsigned int len = c_maybe_optimize_large_byte_initializer ()) |
| 6830 |
{ |
| 6831 |
char buf1[64]; |
| 6832 |
unsigned int i; |
| 6833 |
gcc_checking_assert (len >= 64); |
| 6834 |
location_t last_loc = UNKNOWN_LOCATION; |
| 6835 |
for (i = 0; i < 64; ++i) |
| 6836 |
{ |
| 6837 |
c_token *tok = c_parser_peek_nth_token_raw (parser, 1 + 2 * i); |
| 6838 |
if (tok->type != CPP_COMMA) |
| 6839 |
break; |
| 6840 |
tok = c_parser_peek_nth_token_raw (parser, 2 + 2 * i); |
| 6841 |
if (tok->type != CPP_NUMBER |
| 6842 |
|| TREE_CODE (tok->value) != INTEGER_CST |
| 6843 |
|| TREE_TYPE (tok->value) != integer_type_node |
| 6844 |
|| wi::neg_p (wi::to_wide (tok->value)) |
| 6845 |
|| wi::to_widest (tok->value) > UCHAR_MAX) |
| 6846 |
break; |
| 6847 |
buf1[i] = (char) tree_to_uhwi (tok->value); |
| 6848 |
if (i == 0) |
| 6849 |
loc = tok->location; |
| 6850 |
last_loc = tok->location; |
| 6851 |
} |
| 6852 |
if (i < 64) |
| 6853 |
{ |
| 6854 |
vals_to_ignore = i; |
| 6855 |
return; |
| 6856 |
} |
| 6857 |
c_token *tok = c_parser_peek_nth_token_raw (parser, 1 + 2 * i); |
| 6858 |
/* If 64 CPP_COMMA CPP_NUMBER pairs are followed by CPP_CLOSE_BRACE, |
| 6859 |
punt if len is INT_MAX as that can mean this is a flexible array |
| 6860 |
member and in that case we need one CPP_NUMBER afterwards |
| 6861 |
(as guaranteed for CPP_EMBED). */ |
| 6862 |
if (tok->type == CPP_CLOSE_BRACE && len != INT_MAX) |
| 6863 |
len = i; |
| 6864 |
else if (tok->type != CPP_COMMA |
| 6865 |
|| (c_parser_peek_nth_token_raw (parser, 2 + 2 * i)->type |
| 6866 |
!= CPP_NUMBER)) |
| 6867 |
{ |
| 6868 |
vals_to_ignore = i; |
| 6869 |
return; |
| 6870 |
} |
| 6871 |
/* Ensure the STRING_CST fits into 128K. */ |
| 6872 |
unsigned int max_len = 131072 - offsetof (struct tree_string, str) - 1; |
| 6873 |
unsigned int orig_len = len; |
| 6874 |
unsigned int off = 0, last = 0; |
| 6875 |
if (!wi::neg_p (wi::to_wide (val)) && wi::to_widest (val) <= UCHAR_MAX) |
| 6876 |
off = 1; |
| 6877 |
len = MIN (len, max_len - off); |
| 6878 |
char *buf2 = XNEWVEC (char, len + off); |
| 6879 |
if (off) |
| 6880 |
buf2[0] = (char) tree_to_uhwi (val); |
| 6881 |
memcpy (buf2 + off, buf1, i); |
| 6882 |
for (unsigned int j = 0; j < i; ++j) |
| 6883 |
{ |
| 6884 |
c_parser_peek_token (parser); |
| 6885 |
c_parser_consume_token (parser); |
| 6886 |
c_parser_peek_token (parser); |
| 6887 |
c_parser_consume_token (parser); |
| 6888 |
} |
| 6889 |
for (; i < len; ++i) |
| 6890 |
{ |
| 6891 |
if (!c_parser_next_token_is (parser, CPP_COMMA)) |
| 6892 |
break; |
| 6893 |
tok = c_parser_peek_2nd_token (parser); |
| 6894 |
if (tok->type != CPP_NUMBER |
| 6895 |
|| TREE_CODE (tok->value) != INTEGER_CST |
| 6896 |
|| TREE_TYPE (tok->value) != integer_type_node |
| 6897 |
|| wi::neg_p (wi::to_wide (tok->value)) |
| 6898 |
|| wi::to_widest (tok->value) > UCHAR_MAX) |
| 6899 |
break; |
| 6900 |
c_token *tok2 = c_parser_peek_nth_token (parser, 3); |
| 6901 |
if (tok2->type != CPP_COMMA && tok2->type != CPP_CLOSE_BRACE) |
| 6902 |
break; |
| 6903 |
buf2[i + off] = (char) tree_to_uhwi (tok->value); |
| 6904 |
/* If orig_len is INT_MAX, this can be flexible array member and |
| 6905 |
in that case we need to ensure another element which |
| 6906 |
for CPP_EMBED is normally guaranteed after it. Include |
| 6907 |
that byte in the RAW_DATA_OWNER though, so it can be optimized |
| 6908 |
later. */ |
| 6909 |
if (orig_len == INT_MAX |
| 6910 |
&& (tok2->type == CPP_CLOSE_BRACE |
| 6911 |
|| (c_parser_peek_nth_token (parser, 4)->type |
| 6912 |
!= CPP_NUMBER))) |
| 6913 |
{ |
| 6914 |
last = 1; |
| 6915 |
break; |
| 6916 |
} |
| 6917 |
last_loc = tok->location; |
| 6918 |
c_parser_consume_token (parser); |
| 6919 |
c_parser_consume_token (parser); |
| 6920 |
} |
| 6921 |
val = make_node (RAW_DATA_CST); |
| 6922 |
TREE_TYPE (val) = integer_type_node; |
| 6923 |
RAW_DATA_LENGTH (val) = i; |
| 6924 |
tree owner = build_string (i + off + last, buf2); |
| 6925 |
XDELETEVEC (buf2); |
| 6926 |
TREE_TYPE (owner) = build_array_type_nelts (unsigned_char_type_node, |
| 6927 |
i + off + last); |
| 6928 |
RAW_DATA_OWNER (val) = owner; |
| 6929 |
RAW_DATA_POINTER (val) = TREE_STRING_POINTER (owner) + off; |
| 6930 |
init.value = val; |
| 6931 |
set_c_expr_source_range (&init, loc, last_loc); |
| 6932 |
init.original_code = RAW_DATA_CST; |
| 6933 |
init.original_type = integer_type_node; |
| 6934 |
init.m_decimal = 0; |
| 6935 |
process_init_element (loc, init, false, braced_init_obstack); |
| 6936 |
} |
| 6937 |
} |
| 6938 |
|
| 6939 |
/* Parse a compound statement (possibly a function body) (C90 6.6.2, |
| 6940 |
C99 6.8.2, C11 6.8.2, C23 6.8.2). |
| 6941 |
|
| 6942 |
compound-statement: |
| 6943 |
{ block-item-list[opt] } |
| 6944 |
{ label-declarations block-item-list } |
| 6945 |
|
| 6946 |
block-item-list: |
| 6947 |
block-item |
| 6948 |
block-item-list block-item |
| 6949 |
|
| 6950 |
block-item: |
| 6951 |
label |
| 6952 |
nested-declaration |
| 6953 |
statement |
| 6954 |
|
| 6955 |
nested-declaration: |
| 6956 |
declaration |
| 6957 |
|
| 6958 |
GNU extensions: |
| 6959 |
|
| 6960 |
compound-statement: |
| 6961 |
{ label-declarations block-item-list } |
| 6962 |
|
| 6963 |
nested-declaration: |
| 6964 |
__extension__ nested-declaration |
| 6965 |
nested-function-definition |
| 6966 |
|
| 6967 |
label-declarations: |
| 6968 |
label-declaration |
| 6969 |
label-declarations label-declaration |
| 6970 |
|
| 6971 |
label-declaration: |
| 6972 |
__label__ identifier-list ; |
| 6973 |
|
| 6974 |
Allowing the mixing of declarations and code is new in C99. The |
| 6975 |
GNU syntax also permits (not shown above) labels at the end of |
| 6976 |
compound statements, which yield an error. We don't allow labels |
| 6977 |
on declarations; this might seem like a natural extension, but |
| 6978 |
there would be a conflict between gnu-attributes on the label and |
| 6979 |
prefix gnu-attributes on the declaration. ??? The syntax follows the |
| 6980 |
old parser in requiring something after label declarations. |
| 6981 |
Although they are erroneous if the labels declared aren't defined, |
| 6982 |
is it useful for the syntax to be this way? |
| 6983 |
|
| 6984 |
OpenACC: |
| 6985 |
|
| 6986 |
block-item: |
| 6987 |
openacc-directive |
| 6988 |
|
| 6989 |
openacc-directive: |
| 6990 |
update-directive |
| 6991 |
|
| 6992 |
OpenMP: |
| 6993 |
|
| 6994 |
block-item: |
| 6995 |
openmp-directive |
| 6996 |
|
| 6997 |
openmp-directive: |
| 6998 |
barrier-directive |
| 6999 |
flush-directive |
| 7000 |
taskwait-directive |
| 7001 |
taskyield-directive |
| 7002 |
cancel-directive |
| 7003 |
cancellation-point-directive */ |
| 7004 |
|
| 7005 |
static tree |
| 7006 |
c_parser_compound_statement (c_parser *parser, location_t *endlocp) |
| 7007 |
{ |
| 7008 |
tree stmt; |
| 7009 |
location_t brace_loc; |
| 7010 |
brace_loc = c_parser_peek_token (parser)->location; |
| 7011 |
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 7012 |
{ |
| 7013 |
/* Ensure a scope is entered and left anyway to avoid confusion |
| 7014 |
if we have just prepared to enter a function body. */ |
| 7015 |
stmt = c_begin_compound_stmt (true); |
| 7016 |
c_end_compound_stmt (brace_loc, stmt, true); |
| 7017 |
return error_mark_node; |
| 7018 |
} |
| 7019 |
stmt = c_begin_compound_stmt (true); |
| 7020 |
location_t end_loc = c_parser_compound_statement_nostart (parser); |
| 7021 |
if (endlocp) |
| 7022 |
*endlocp = end_loc; |
| 7023 |
|
| 7024 |
return c_end_compound_stmt (brace_loc, stmt, true); |
| 7025 |
} |
| 7026 |
|
| 7027 |
/* Diagnose errors related to imperfectly nested loops in an OMP |
| 7028 |
loop construct. This function is called when such code is seen. |
| 7029 |
Only issue one such diagnostic no matter how much invalid |
| 7030 |
intervening code there is in the loop. |
| 7031 |
FIXME: maybe the location associated with the diagnostic should |
| 7032 |
be the current parser token instead of the location of the outer loop |
| 7033 |
nest. */ |
| 7034 |
|
| 7035 |
static void |
| 7036 |
check_omp_intervening_code (c_parser *parser) |
| 7037 |
{ |
| 7038 |
struct omp_for_parse_data *omp_for_parse_state = parser->omp_for_parse_state; |
| 7039 |
gcc_assert (omp_for_parse_state); |
| 7040 |
|
| 7041 |
if (!omp_for_parse_state->in_intervening_code) |
| 7042 |
return; |
| 7043 |
omp_for_parse_state->saw_intervening_code = true; |
| 7044 |
|
| 7045 |
/* Only diagnose errors related to perfect nesting once. */ |
| 7046 |
if (!omp_for_parse_state->perfect_nesting_fail) |
| 7047 |
{ |
| 7048 |
|
| 7049 |
/* OpenACC does not (yet) permit intervening code, in |
| 7050 |
addition to situations forbidden by the OpenMP spec. */ |
| 7051 |
if (omp_for_parse_state->code == OACC_LOOP) |
| 7052 |
{ |
| 7053 |
error_at (omp_for_parse_state->for_loc, |
| 7054 |
"inner loops must be perfectly nested in " |
| 7055 |
"%<#pragma acc loop%>"); |
| 7056 |
omp_for_parse_state->perfect_nesting_fail = true; |
| 7057 |
} |
| 7058 |
else if (omp_for_parse_state->ordered) |
| 7059 |
{ |
| 7060 |
error_at (omp_for_parse_state->for_loc, |
| 7061 |
"inner loops must be perfectly nested with " |
| 7062 |
"%<ordered%> clause"); |
| 7063 |
omp_for_parse_state->perfect_nesting_fail = true; |
| 7064 |
} |
| 7065 |
else if (omp_for_parse_state->inscan) |
| 7066 |
{ |
| 7067 |
error_at (omp_for_parse_state->for_loc, |
| 7068 |
"inner loops must be perfectly nested with " |
| 7069 |
"%<reduction%> %<inscan%> clause"); |
| 7070 |
omp_for_parse_state->perfect_nesting_fail = true; |
| 7071 |
} |
| 7072 |
else if (omp_for_parse_state->code == OMP_TILE) |
| 7073 |
{ |
| 7074 |
error_at (omp_for_parse_state->for_loc, |
| 7075 |
"inner loops must be perfectly nested in " |
| 7076 |
"%<pragma omp tile%>"); |
| 7077 |
omp_for_parse_state->perfect_nesting_fail = true; |
| 7078 |
} |
| 7079 |
if (omp_for_parse_state->perfect_nesting_fail) |
| 7080 |
omp_for_parse_state->fail = true; |
| 7081 |
} |
| 7082 |
} |
| 7083 |
|
| 7084 |
/* Helper function for below: wrap an OMP_STRUCTURED_BLOCK around SL |
| 7085 |
and add the statement to the current list. If SL is an empty statement |
| 7086 |
list, do nothing. */ |
| 7087 |
static void |
| 7088 |
add_structured_block_stmt (tree sl) |
| 7089 |
{ |
| 7090 |
if (TREE_CODE (sl) != STATEMENT_LIST |
| 7091 |
|| !tsi_end_p (tsi_start (sl))) |
| 7092 |
add_stmt (build1 (OMP_STRUCTURED_BLOCK, void_type_node, sl)); |
| 7093 |
} |
| 7094 |
|
| 7095 |
struct c_omp_attribute_data |
| 7096 |
{ |
| 7097 |
vec<c_token, va_gc> *tokens; |
| 7098 |
const c_omp_directive *dir; |
| 7099 |
c_omp_directive_kind kind; |
| 7100 |
}; |
| 7101 |
|
| 7102 |
/* Handle omp::directive and omp::sequence attributes in ATTRS |
| 7103 |
(if any) at the start of a statement or in attribute-declaration. */ |
| 7104 |
|
| 7105 |
static bool |
| 7106 |
c_parser_handle_statement_omp_attributes (c_parser *parser, tree &attrs, |
| 7107 |
bool *have_std_attrs) |
| 7108 |
{ |
| 7109 |
if (!flag_openmp && !flag_openmp_simd) |
| 7110 |
return false; |
| 7111 |
|
| 7112 |
auto_vec<c_omp_attribute_data, 16> vd; |
| 7113 |
int cnt = 0; |
| 7114 |
int tokens = 0; |
| 7115 |
bool bad = false; |
| 7116 |
for (tree *pa = &attrs; *pa; ) |
| 7117 |
if (is_attribute_namespace_p ("omp", *pa) |
| 7118 |
&& is_attribute_p ("directive", get_attribute_name (*pa))) |
| 7119 |
{ |
| 7120 |
cnt++; |
| 7121 |
for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a)) |
| 7122 |
{ |
| 7123 |
tree d = TREE_VALUE (a); |
| 7124 |
gcc_assert (TREE_CODE (d) == C_TOKEN_VEC); |
| 7125 |
vec<c_token, va_gc> *toks = C_TOKEN_VEC_TOKENS (d); |
| 7126 |
c_token *first = toks->address (); |
| 7127 |
c_token *last = first + toks->length (); |
| 7128 |
if (parser->omp_attrs_forbidden_p) |
| 7129 |
{ |
| 7130 |
error_at (first->location, |
| 7131 |
"mixing OpenMP directives with attribute and pragma " |
| 7132 |
"syntax on the same statement"); |
| 7133 |
parser->omp_attrs_forbidden_p = false; |
| 7134 |
bad = true; |
| 7135 |
} |
| 7136 |
else if (TREE_PUBLIC (d)) |
| 7137 |
{ |
| 7138 |
error_at (first->location, |
| 7139 |
"OpenMP %<omp::decl%> attribute on a statement"); |
| 7140 |
bad = true; |
| 7141 |
} |
| 7142 |
const char *directive[3] = {}; |
| 7143 |
for (int i = 0; i < 3; i++) |
| 7144 |
{ |
| 7145 |
tree id = NULL_TREE; |
| 7146 |
if (first + i == last) |
| 7147 |
break; |
| 7148 |
if (first[i].type == CPP_NAME) |
| 7149 |
id = first[i].value; |
| 7150 |
else if (first[i].type == CPP_KEYWORD) |
| 7151 |
id = ridpointers[(int) first[i].keyword]; |
| 7152 |
else |
| 7153 |
break; |
| 7154 |
directive[i] = IDENTIFIER_POINTER (id); |
| 7155 |
} |
| 7156 |
const c_omp_directive *dir = NULL; |
| 7157 |
if (directive[0]) |
| 7158 |
dir = c_omp_categorize_directive (directive[0], directive[1], |
| 7159 |
directive[2]); |
| 7160 |
if (dir == NULL) |
| 7161 |
{ |
| 7162 |
error_at (first->location, |
| 7163 |
"unknown OpenMP directive name in %qs attribute " |
| 7164 |
"argument", |
| 7165 |
TREE_PUBLIC (d) ? "omp::decl" : "omp::directive"); |
| 7166 |
continue; |
| 7167 |
} |
| 7168 |
c_omp_directive_kind kind = dir->kind; |
| 7169 |
if (dir->id == PRAGMA_OMP_ORDERED) |
| 7170 |
{ |
| 7171 |
/* ordered is C_OMP_DIR_CONSTRUCT only if it doesn't contain |
| 7172 |
depend/doacross clause. */ |
| 7173 |
if (directive[1] |
| 7174 |
&& (strcmp (directive[1], "depend") == 0 |
| 7175 |
|| strcmp (directive[1], "doacross") == 0)) |
| 7176 |
kind = C_OMP_DIR_STANDALONE; |
| 7177 |
else if (first + 2 < last |
| 7178 |
&& first[1].type == CPP_COMMA |
| 7179 |
&& first[2].type == CPP_NAME |
| 7180 |
&& (strcmp (IDENTIFIER_POINTER (first[2].value), |
| 7181 |
"depend") == 0 |
| 7182 |
|| strcmp (IDENTIFIER_POINTER (first[2].value), |
| 7183 |
"doacross") == 0)) |
| 7184 |
kind = C_OMP_DIR_STANDALONE; |
| 7185 |
} |
| 7186 |
else if (dir->id == PRAGMA_OMP_ERROR) |
| 7187 |
{ |
| 7188 |
/* error with at(execution) clause is C_OMP_DIR_STANDALONE. */ |
| 7189 |
int paren_depth = 0; |
| 7190 |
for (int i = 1; first + i < last; i++) |
| 7191 |
if (first[i].type == CPP_OPEN_PAREN) |
| 7192 |
paren_depth++; |
| 7193 |
else if (first[i].type == CPP_CLOSE_PAREN) |
| 7194 |
paren_depth--; |
| 7195 |
else if (paren_depth == 0 |
| 7196 |
&& first + i + 2 < last |
| 7197 |
&& first[i].type == CPP_NAME |
| 7198 |
&& first[i + 1].type == CPP_OPEN_PAREN |
| 7199 |
&& first[i + 2].type == CPP_NAME |
| 7200 |
&& !strcmp (IDENTIFIER_POINTER (first[i].value), |
| 7201 |
"at") |
| 7202 |
&& !strcmp (IDENTIFIER_POINTER (first[i |
| 7203 |
+ 2].value), |
| 7204 |
"execution")) |
| 7205 |
{ |
| 7206 |
kind = C_OMP_DIR_STANDALONE; |
| 7207 |
break; |
| 7208 |
} |
| 7209 |
} |
| 7210 |
c_omp_attribute_data v = { toks, dir, kind }; |
| 7211 |
vd.safe_push (v); |
| 7212 |
if (flag_openmp || dir->simd) |
| 7213 |
tokens += (last - first) + 1; |
| 7214 |
} |
| 7215 |
c_omp_attribute_data v = {}; |
| 7216 |
vd.safe_push (v); |
| 7217 |
*pa = TREE_CHAIN (*pa); |
| 7218 |
} |
| 7219 |
else |
| 7220 |
pa = &TREE_CHAIN (*pa); |
| 7221 |
|
| 7222 |
if (bad) |
| 7223 |
{ |
| 7224 |
fail: |
| 7225 |
if (have_std_attrs && attrs == NULL) |
| 7226 |
*have_std_attrs = false; |
| 7227 |
return false; |
| 7228 |
} |
| 7229 |
|
| 7230 |
unsigned int i; |
| 7231 |
c_omp_attribute_data *v; |
| 7232 |
c_omp_attribute_data *construct_seen = nullptr; |
| 7233 |
c_omp_attribute_data *standalone_seen = nullptr; |
| 7234 |
c_omp_attribute_data *prev_standalone_seen = nullptr; |
| 7235 |
FOR_EACH_VEC_ELT (vd, i, v) |
| 7236 |
if (v->tokens) |
| 7237 |
{ |
| 7238 |
if (v->kind == C_OMP_DIR_CONSTRUCT && !construct_seen) |
| 7239 |
construct_seen = v; |
| 7240 |
else if (v->kind == C_OMP_DIR_STANDALONE && !standalone_seen) |
| 7241 |
standalone_seen = v; |
| 7242 |
} |
| 7243 |
else |
| 7244 |
{ |
| 7245 |
if (standalone_seen && !prev_standalone_seen) |
| 7246 |
{ |
| 7247 |
prev_standalone_seen = standalone_seen; |
| 7248 |
standalone_seen = nullptr; |
| 7249 |
} |
| 7250 |
} |
| 7251 |
|
| 7252 |
if (cnt > 1 && construct_seen) |
| 7253 |
{ |
| 7254 |
error_at ((*construct_seen->tokens)[0].location, |
| 7255 |
"OpenMP construct among %<omp::directive%> attributes" |
| 7256 |
" requires all %<omp::directive%> attributes on the" |
| 7257 |
" same statement to be in the same %<omp::sequence%>"); |
| 7258 |
goto fail; |
| 7259 |
} |
| 7260 |
if (cnt > 1 && standalone_seen && prev_standalone_seen) |
| 7261 |
{ |
| 7262 |
error_at ((*standalone_seen->tokens)[0].location, |
| 7263 |
"multiple OpenMP standalone directives among" |
| 7264 |
" %<omp::directive%> attributes must be all within the" |
| 7265 |
" same %<omp::sequence%>"); |
| 7266 |
goto fail; |
| 7267 |
} |
| 7268 |
|
| 7269 |
if (prev_standalone_seen) |
| 7270 |
standalone_seen = prev_standalone_seen; |
| 7271 |
if (standalone_seen |
| 7272 |
&& !c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 7273 |
{ |
| 7274 |
error_at (standalone_seen->tokens->address ()->location, |
| 7275 |
"standalone OpenMP directives in %<omp::directive%> attribute" |
| 7276 |
" can only appear on an empty statement"); |
| 7277 |
goto fail; |
| 7278 |
} |
| 7279 |
if (cnt && c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 7280 |
{ |
| 7281 |
c_token *token = c_parser_peek_token (parser); |
| 7282 |
enum pragma_kind kind = token->pragma_kind; |
| 7283 |
if (kind >= PRAGMA_OMP__START_ && kind <= PRAGMA_OMP__LAST_) |
| 7284 |
{ |
| 7285 |
error_at (token->location, |
| 7286 |
"mixing OpenMP directives with attribute and pragma " |
| 7287 |
"syntax on the same statement"); |
| 7288 |
goto fail; |
| 7289 |
} |
| 7290 |
} |
| 7291 |
|
| 7292 |
if (!tokens) |
| 7293 |
return false; |
| 7294 |
|
| 7295 |
unsigned int tokens_avail = parser->tokens_avail; |
| 7296 |
|
| 7297 |
tokens++; |
| 7298 |
vec<c_token, va_gc> *toks = NULL; |
| 7299 |
vec_safe_reserve (toks, tokens, true); |
| 7300 |
FOR_EACH_VEC_ELT (vd, i, v) |
| 7301 |
{ |
| 7302 |
if (!v->tokens) |
| 7303 |
continue; |
| 7304 |
if (!flag_openmp && !v->dir->simd) |
| 7305 |
continue; |
| 7306 |
c_token *first = v->tokens->address (); |
| 7307 |
c_token *last = first + v->tokens->length (); |
| 7308 |
c_token tok = {}; |
| 7309 |
tok.type = CPP_PRAGMA; |
| 7310 |
tok.keyword = RID_MAX; |
| 7311 |
tok.pragma_kind = pragma_kind (v->dir->id); |
| 7312 |
tok.location = first->location; |
| 7313 |
toks->quick_push (tok); |
| 7314 |
while (++first < last) |
| 7315 |
toks->quick_push (*first); |
| 7316 |
tok = {}; |
| 7317 |
tok.type = CPP_PRAGMA_EOL; |
| 7318 |
tok.keyword = RID_MAX; |
| 7319 |
tok.location = last[-1].location; |
| 7320 |
toks->quick_push (tok); |
| 7321 |
} |
| 7322 |
|
| 7323 |
c_token tok = {}; |
| 7324 |
tok.type = CPP_EOF; |
| 7325 |
tok.keyword = RID_MAX; |
| 7326 |
tok.location = toks->last ().location; |
| 7327 |
toks->quick_push (tok); |
| 7328 |
|
| 7329 |
gcc_assert (!parser->in_omp_attribute_pragma); |
| 7330 |
parser->in_omp_attribute_pragma = ggc_alloc<omp_attribute_pragma_state> (); |
| 7331 |
parser->in_omp_attribute_pragma->token_vec = toks; |
| 7332 |
parser->in_omp_attribute_pragma->save_tokens = parser->tokens; |
| 7333 |
parser->in_omp_attribute_pragma->save_tokens_avail = tokens_avail; |
| 7334 |
parser->tokens = toks->address (); |
| 7335 |
parser->tokens_avail = tokens; |
| 7336 |
return true; |
| 7337 |
} |
| 7338 |
|
| 7339 |
/* Handle omp::directive and omp::sequence attributes in ATTRS |
| 7340 |
(if any) at the start or after declaration-id of a declaration. */ |
| 7341 |
|
| 7342 |
static void |
| 7343 |
c_parser_handle_directive_omp_attributes (tree &attrs, |
| 7344 |
vec<c_token> *&pragma_clauses, |
| 7345 |
vec<c_token> *attr_clauses) |
| 7346 |
{ |
| 7347 |
if (!flag_openmp && !flag_openmp_simd) |
| 7348 |
return; |
| 7349 |
|
| 7350 |
for (tree *pa = &attrs; *pa; ) |
| 7351 |
if (is_attribute_namespace_p ("omp", *pa) |
| 7352 |
&& is_attribute_p ("directive", get_attribute_name (*pa))) |
| 7353 |
{ |
| 7354 |
int cnt = 0; |
| 7355 |
for (tree *pa2 = &TREE_VALUE (*pa); *pa2; ) |
| 7356 |
{ |
| 7357 |
tree a = *pa2; |
| 7358 |
tree d = TREE_VALUE (a); |
| 7359 |
gcc_assert (TREE_CODE (d) == C_TOKEN_VEC); |
| 7360 |
vec<c_token, va_gc> *toks = C_TOKEN_VEC_TOKENS (d); |
| 7361 |
c_token *first = toks->address (); |
| 7362 |
c_token *last = first + toks->length (); |
| 7363 |
const char *directive[3] = {}; |
| 7364 |
for (int i = 0; i < 3; i++) |
| 7365 |
{ |
| 7366 |
tree id = NULL_TREE; |
| 7367 |
if (first + i == last) |
| 7368 |
break; |
| 7369 |
if (first[i].type == CPP_NAME) |
| 7370 |
id = first[i].value; |
| 7371 |
else if (first[i].type == CPP_KEYWORD) |
| 7372 |
id = ridpointers[(int) first[i].keyword]; |
| 7373 |
else |
| 7374 |
break; |
| 7375 |
directive[i] = IDENTIFIER_POINTER (id); |
| 7376 |
} |
| 7377 |
const c_omp_directive *dir = NULL; |
| 7378 |
if (directive[0]) |
| 7379 |
dir = c_omp_categorize_directive (directive[0], directive[1], |
| 7380 |
directive[2]); |
| 7381 |
if (dir == NULL) |
| 7382 |
{ |
| 7383 |
error_at (first->location, |
| 7384 |
"unknown OpenMP directive name in " |
| 7385 |
"%qs attribute argument", |
| 7386 |
TREE_PUBLIC (d) ? "omp::decl" : "omp::directive"); |
| 7387 |
*pa2 = TREE_CHAIN (a); |
| 7388 |
} |
| 7389 |
else if (dir->id == PRAGMA_OMP_DECLARE |
| 7390 |
&& (strcmp (directive[1], "simd") == 0 |
| 7391 |
|| strcmp (directive[1], "variant") == 0)) |
| 7392 |
{ |
| 7393 |
if (pragma_clauses) |
| 7394 |
{ |
| 7395 |
error_at (first->location, |
| 7396 |
"mixing OpenMP directives with attribute and " |
| 7397 |
"pragma syntax on the same declaration"); |
| 7398 |
for (pa = &attrs; *pa; ) |
| 7399 |
if (is_attribute_namespace_p ("omp", *pa) |
| 7400 |
&& is_attribute_p ("directive", |
| 7401 |
get_attribute_name (*pa))) |
| 7402 |
*pa = TREE_CHAIN (*pa); |
| 7403 |
else |
| 7404 |
pa = &TREE_CHAIN (*pa); |
| 7405 |
return; |
| 7406 |
} |
| 7407 |
++cnt; |
| 7408 |
attr_clauses->reserve (attr_clauses->length () |
| 7409 |
+ toks->length () + 2); |
| 7410 |
for (++first; first < last; ++first) |
| 7411 |
attr_clauses->quick_push (*first); |
| 7412 |
c_token tok = {}; |
| 7413 |
tok.type = CPP_PRAGMA_EOL; |
| 7414 |
tok.keyword = RID_MAX; |
| 7415 |
tok.location = last[-1].location; |
| 7416 |
attr_clauses->quick_push (tok); |
| 7417 |
*pa2 = TREE_CHAIN (a); |
| 7418 |
} |
| 7419 |
else |
| 7420 |
pa2 = &TREE_CHAIN (a); |
| 7421 |
} |
| 7422 |
if (cnt && TREE_VALUE (*pa) == NULL_TREE) |
| 7423 |
*pa = TREE_CHAIN (*pa); |
| 7424 |
else |
| 7425 |
pa = &TREE_CHAIN (*pa); |
| 7426 |
} |
| 7427 |
else |
| 7428 |
pa = &TREE_CHAIN (*pa); |
| 7429 |
if (attr_clauses->length ()) |
| 7430 |
{ |
| 7431 |
c_token tok = {}; |
| 7432 |
tok.type = CPP_EOF; |
| 7433 |
tok.keyword = RID_MAX; |
| 7434 |
tok.location = attr_clauses->last ().location; |
| 7435 |
attr_clauses->quick_push (tok); |
| 7436 |
attr_clauses->quick_push (tok); |
| 7437 |
pragma_clauses = attr_clauses; |
| 7438 |
} |
| 7439 |
} |
| 7440 |
|
| 7441 |
/* Check if STD_ATTR contains a musttail attribute and remove if it |
| 7442 |
precedes a return. PARSER is the parser and ATTR is the output |
| 7443 |
attr_state. */ |
| 7444 |
|
| 7445 |
static tree |
| 7446 |
c_parser_handle_musttail (c_parser *parser, tree std_attrs, attr_state &attr) |
| 7447 |
{ |
| 7448 |
if (c_parser_next_token_is_keyword (parser, RID_RETURN)) |
| 7449 |
{ |
| 7450 |
if (tree a = lookup_attribute ("gnu", "musttail", std_attrs)) |
| 7451 |
{ |
| 7452 |
for (; a; a = lookup_attribute ("gnu", "musttail", TREE_CHAIN (a))) |
| 7453 |
if (TREE_VALUE (a)) |
| 7454 |
error ("%qs attribute does not take any arguments", |
| 7455 |
"musttail"); |
| 7456 |
std_attrs = remove_attribute ("gnu", "musttail", std_attrs); |
| 7457 |
attr.musttail_p = true; |
| 7458 |
} |
| 7459 |
if (lookup_attribute ("clang", "musttail", std_attrs)) |
| 7460 |
{ |
| 7461 |
std_attrs = remove_attribute ("clang", "musttail", std_attrs); |
| 7462 |
attr.musttail_p = true; |
| 7463 |
} |
| 7464 |
} |
| 7465 |
return std_attrs; |
| 7466 |
} |
| 7467 |
|
| 7468 |
/* Return a statement before optional series of LABEL_EXPR/CASE_LABEL_EXPRs. |
| 7469 |
Instead of collecting vectors of labels before each stmt just in case |
| 7470 |
the statement would be iteration or switch statement for named loops, |
| 7471 |
we just remember last emitted statement and let the iteration/switch |
| 7472 |
statement search backwards in cur_stmt_list until that stmt for loop |
| 7473 |
names if any. */ |
| 7474 |
|
| 7475 |
static tree |
| 7476 |
get_before_labels () |
| 7477 |
{ |
| 7478 |
if (!building_stmt_list_p ()) |
| 7479 |
return NULL_TREE; |
| 7480 |
tree_stmt_iterator tsi = tsi_last (cur_stmt_list); |
| 7481 |
if (tsi_end_p (tsi)) |
| 7482 |
return NULL_TREE; |
| 7483 |
return tsi_stmt (tsi); |
| 7484 |
} |
| 7485 |
|
| 7486 |
/* Parse a compound statement except for the opening brace. This is |
| 7487 |
used for parsing both compound statements and statement expressions |
| 7488 |
(which follow different paths to handling the opening). */ |
| 7489 |
|
| 7490 |
static location_t |
| 7491 |
c_parser_compound_statement_nostart (c_parser *parser) |
| 7492 |
{ |
| 7493 |
bool last_stmt = false; |
| 7494 |
bool last_label = false; |
| 7495 |
bool save_valid_for_pragma = valid_location_for_stdc_pragma_p (); |
| 7496 |
location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 7497 |
struct omp_for_parse_data *omp_for_parse_state |
| 7498 |
= parser->omp_for_parse_state; |
| 7499 |
bool in_omp_loop_block |
| 7500 |
= omp_for_parse_state ? omp_for_parse_state->want_nested_loop : false; |
| 7501 |
tree sl = NULL_TREE; |
| 7502 |
attr_state astate = {}; |
| 7503 |
|
| 7504 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 7505 |
{ |
| 7506 |
location_t endloc = c_parser_peek_token (parser)->location; |
| 7507 |
add_debug_begin_stmt (endloc); |
| 7508 |
c_parser_consume_token (parser); |
| 7509 |
return endloc; |
| 7510 |
} |
| 7511 |
|
| 7512 |
/* If we're parsing a {} sequence in an OMP_FOR body, start a |
| 7513 |
statement list for intervening code. */ |
| 7514 |
if (in_omp_loop_block) |
| 7515 |
sl = push_stmt_list (); |
| 7516 |
|
| 7517 |
mark_valid_location_for_stdc_pragma (true); |
| 7518 |
if (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
| 7519 |
{ |
| 7520 |
/* Read zero or more forward-declarations for labels that nested |
| 7521 |
functions can jump to. */ |
| 7522 |
mark_valid_location_for_stdc_pragma (false); |
| 7523 |
if (in_omp_loop_block) |
| 7524 |
check_omp_intervening_code (parser); |
| 7525 |
while (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
| 7526 |
{ |
| 7527 |
label_loc = c_parser_peek_token (parser)->location; |
| 7528 |
c_parser_consume_token (parser); |
| 7529 |
/* Any identifiers, including those declared as type names, |
| 7530 |
are OK here. */ |
| 7531 |
while (true) |
| 7532 |
{ |
| 7533 |
tree label; |
| 7534 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 7535 |
{ |
| 7536 |
c_parser_error (parser, "expected identifier"); |
| 7537 |
break; |
| 7538 |
} |
| 7539 |
label |
| 7540 |
= declare_label (c_parser_peek_token (parser)->value); |
| 7541 |
C_DECLARED_LABEL_FLAG (label) = 1; |
| 7542 |
add_stmt (build_stmt (label_loc, DECL_EXPR, label)); |
| 7543 |
c_parser_consume_token (parser); |
| 7544 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 7545 |
c_parser_consume_token (parser); |
| 7546 |
else |
| 7547 |
break; |
| 7548 |
} |
| 7549 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 7550 |
} |
| 7551 |
pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations"); |
| 7552 |
} |
| 7553 |
/* We must now have at least one statement, label or declaration. */ |
| 7554 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 7555 |
{ |
| 7556 |
mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 7557 |
c_parser_error (parser, "expected declaration or statement"); |
| 7558 |
location_t endloc = c_parser_peek_token (parser)->location; |
| 7559 |
c_parser_consume_token (parser); |
| 7560 |
return endloc; |
| 7561 |
} |
| 7562 |
tree before_labels = get_before_labels (); |
| 7563 |
while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) |
| 7564 |
{ |
| 7565 |
location_t loc = c_parser_peek_token (parser)->location; |
| 7566 |
loc = expansion_point_location_if_in_system_header (loc); |
| 7567 |
|
| 7568 |
bool want_nested_loop = (omp_for_parse_state |
| 7569 |
? omp_for_parse_state->want_nested_loop |
| 7570 |
: false); |
| 7571 |
|
| 7572 |
/* First take care of special cases for OpenMP "canonical loop |
| 7573 |
nest form", that do not allow standard attributes, labels, or |
| 7574 |
__extension__ before the nested statement. */ |
| 7575 |
if (in_omp_loop_block && !last_label) |
| 7576 |
{ |
| 7577 |
tree_code code = omp_for_parse_state->code; |
| 7578 |
if (want_nested_loop |
| 7579 |
&& c_parser_omp_next_tokens_can_be_canon_loop (parser, code, |
| 7580 |
false)) |
| 7581 |
{ |
| 7582 |
/* Found the next nested loop. If there were intervening |
| 7583 |
code statements collected before now, wrap them in an |
| 7584 |
OMP_STRUCTURED_BLOCK node, and start a new structured |
| 7585 |
block to hold statements that may come after the FOR. */ |
| 7586 |
gcc_assert (sl); |
| 7587 |
add_structured_block_stmt (pop_stmt_list (sl)); |
| 7588 |
omp_for_parse_state->depth++; |
| 7589 |
add_stmt (c_parser_omp_loop_nest (parser, NULL)); |
| 7590 |
omp_for_parse_state->depth--; |
| 7591 |
sl = push_stmt_list (); |
| 7592 |
parser->error = false; |
| 7593 |
before_labels = get_before_labels (); |
| 7594 |
astate.reset (); |
| 7595 |
continue; |
| 7596 |
} |
| 7597 |
else if (want_nested_loop |
| 7598 |
&& c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 7599 |
{ |
| 7600 |
/* If this nested compound statement contains the nested loop, |
| 7601 |
we need to separate the other statements in the current |
| 7602 |
statement into separate blocks of intervening code. If |
| 7603 |
there's no nested loop, it's all part of the same |
| 7604 |
chunk of intervening code. */ |
| 7605 |
tree pre_sl = pop_stmt_list (sl); |
| 7606 |
tree nested_sl = push_stmt_list (); |
| 7607 |
mark_valid_location_for_stdc_pragma (false); |
| 7608 |
c_parser_statement_after_labels (parser, NULL, NULL_TREE); |
| 7609 |
nested_sl = pop_stmt_list (nested_sl); |
| 7610 |
if (omp_for_parse_state->want_nested_loop) |
| 7611 |
{ |
| 7612 |
/* This block didn't contain a loop-nest, so it's |
| 7613 |
all part of the same chunk of intervening code. */ |
| 7614 |
check_omp_intervening_code (parser); |
| 7615 |
sl = push_stmt_list (); |
| 7616 |
add_stmt (pre_sl); |
| 7617 |
add_stmt (nested_sl); |
| 7618 |
} |
| 7619 |
else |
| 7620 |
{ |
| 7621 |
/* It contains the nested loop. */ |
| 7622 |
add_structured_block_stmt (pre_sl); |
| 7623 |
add_stmt (nested_sl); |
| 7624 |
sl = push_stmt_list (); |
| 7625 |
} |
| 7626 |
parser->error = false; |
| 7627 |
before_labels = get_before_labels (); |
| 7628 |
astate.reset (); |
| 7629 |
continue; |
| 7630 |
} |
| 7631 |
else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 7632 |
{ |
| 7633 |
/* Prior to implementing the OpenMP 5.1 syntax for canonical |
| 7634 |
loop form, GCC used to accept an empty statements that |
| 7635 |
would now be flagged as intervening code. Continue to |
| 7636 |
do that, as an extension. */ |
| 7637 |
/* FIXME: Maybe issue a warning or something here? */ |
| 7638 |
c_parser_consume_token (parser); |
| 7639 |
before_labels = get_before_labels (); |
| 7640 |
astate.reset (); |
| 7641 |
continue; |
| 7642 |
} |
| 7643 |
} |
| 7644 |
|
| 7645 |
/* Standard attributes may start a label, statement or declaration. */ |
| 7646 |
bool have_std_attrs |
| 7647 |
= c_parser_nth_token_starts_std_attributes (parser, 1); |
| 7648 |
tree std_attrs = NULL_TREE; |
| 7649 |
if (have_std_attrs) |
| 7650 |
{ |
| 7651 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 7652 |
std_attrs = c_parser_handle_musttail (parser, std_attrs, astate); |
| 7653 |
} |
| 7654 |
if (c_parser_next_token_is_keyword (parser, RID_CASE) |
| 7655 |
|| c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
| 7656 |
|| (c_parser_next_token_is (parser, CPP_NAME) |
| 7657 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
| 7658 |
{ |
| 7659 |
if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
| 7660 |
label_loc = c_parser_peek_2nd_token (parser)->location; |
| 7661 |
else |
| 7662 |
label_loc = c_parser_peek_token (parser)->location; |
| 7663 |
last_label = true; |
| 7664 |
last_stmt = false; |
| 7665 |
mark_valid_location_for_stdc_pragma (false); |
| 7666 |
if (in_omp_loop_block) |
| 7667 |
check_omp_intervening_code (parser); |
| 7668 |
c_parser_label (parser, std_attrs); |
| 7669 |
} |
| 7670 |
else if (c_parser_next_tokens_start_declaration (parser) |
| 7671 |
|| (have_std_attrs |
| 7672 |
&& !c_parser_handle_statement_omp_attributes |
| 7673 |
(parser, std_attrs, &have_std_attrs) |
| 7674 |
&& c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 7675 |
&& (have_std_attrs = true))) |
| 7676 |
{ |
| 7677 |
if (last_label) |
| 7678 |
pedwarn_c11 (c_parser_peek_token (parser)->location, OPT_Wfree_labels, |
| 7679 |
"a label can only be part of a statement and " |
| 7680 |
"a declaration is not a statement"); |
| 7681 |
/* It's unlikely we'll see a nested loop in a declaration in |
| 7682 |
intervening code in an OMP loop, but disallow it anyway. */ |
| 7683 |
if (in_omp_loop_block) |
| 7684 |
{ |
| 7685 |
check_omp_intervening_code (parser); |
| 7686 |
omp_for_parse_state->want_nested_loop = false; |
| 7687 |
} |
| 7688 |
mark_valid_location_for_stdc_pragma (false); |
| 7689 |
bool fallthru_attr_p = false; |
| 7690 |
c_parser_declaration_or_fndef (parser, true, !have_std_attrs, |
| 7691 |
true, true, true, false, NULL, |
| 7692 |
NULL, have_std_attrs, std_attrs, |
| 7693 |
NULL, &fallthru_attr_p); |
| 7694 |
|
| 7695 |
if (in_omp_loop_block) |
| 7696 |
omp_for_parse_state->want_nested_loop = want_nested_loop; |
| 7697 |
if (last_stmt && !fallthru_attr_p) |
| 7698 |
pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
| 7699 |
"ISO C90 forbids mixed declarations and code"); |
| 7700 |
last_stmt = fallthru_attr_p; |
| 7701 |
last_label = false; |
| 7702 |
before_labels = get_before_labels (); |
| 7703 |
} |
| 7704 |
else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
| 7705 |
{ |
| 7706 |
/* __extension__ can start a declaration, but is also an |
| 7707 |
unary operator that can start an expression. Consume all |
| 7708 |
but the last of a possible series of __extension__ to |
| 7709 |
determine which. If standard attributes have already |
| 7710 |
been seen, it must start a statement, not a declaration, |
| 7711 |
but standard attributes starting a declaration may appear |
| 7712 |
after __extension__. */ |
| 7713 |
while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD |
| 7714 |
&& (c_parser_peek_2nd_token (parser)->keyword |
| 7715 |
== RID_EXTENSION)) |
| 7716 |
c_parser_consume_token (parser); |
| 7717 |
if (!have_std_attrs |
| 7718 |
&& (c_token_starts_declaration (c_parser_peek_2nd_token (parser)) |
| 7719 |
|| c_parser_nth_token_starts_std_attributes (parser, 2))) |
| 7720 |
{ |
| 7721 |
int ext; |
| 7722 |
ext = disable_extension_diagnostics (); |
| 7723 |
c_parser_consume_token (parser); |
| 7724 |
last_label = false; |
| 7725 |
/* It's unlikely we'll see a nested loop in a declaration in |
| 7726 |
intervening code in an OMP loop, but disallow it anyway. */ |
| 7727 |
if (in_omp_loop_block) |
| 7728 |
{ |
| 7729 |
check_omp_intervening_code (parser); |
| 7730 |
omp_for_parse_state->want_nested_loop = false; |
| 7731 |
} |
| 7732 |
mark_valid_location_for_stdc_pragma (false); |
| 7733 |
c_parser_declaration_or_fndef (parser, true, true, true, true, |
| 7734 |
true, false); |
| 7735 |
if (in_omp_loop_block) |
| 7736 |
omp_for_parse_state->want_nested_loop = want_nested_loop; |
| 7737 |
/* Following the old parser, __extension__ does not |
| 7738 |
disable this diagnostic. */ |
| 7739 |
restore_extension_diagnostics (ext); |
| 7740 |
if (last_stmt) |
| 7741 |
pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
| 7742 |
"ISO C90 forbids mixed declarations and code"); |
| 7743 |
last_stmt = false; |
| 7744 |
before_labels = get_before_labels (); |
| 7745 |
} |
| 7746 |
else |
| 7747 |
goto statement; |
| 7748 |
} |
| 7749 |
else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 7750 |
{ |
| 7751 |
if (have_std_attrs && !parser->in_omp_attribute_pragma) |
| 7752 |
c_parser_error (parser, "expected declaration or statement"); |
| 7753 |
else if (std_attrs) |
| 7754 |
c_warn_unused_attributes (std_attrs); |
| 7755 |
/* External pragmas, and some omp pragmas, are not associated |
| 7756 |
with regular c code, and so are not to be considered statements |
| 7757 |
syntactically. This ensures that the user doesn't put them |
| 7758 |
places that would turn into syntax errors if the directive |
| 7759 |
were ignored. */ |
| 7760 |
if (omp_for_parse_state) |
| 7761 |
omp_for_parse_state->want_nested_loop = false; |
| 7762 |
if (c_parser_pragma (parser, |
| 7763 |
last_label ? pragma_stmt : pragma_compound, |
| 7764 |
NULL, before_labels)) |
| 7765 |
{ |
| 7766 |
last_label = false; |
| 7767 |
last_stmt = true; |
| 7768 |
if (omp_for_parse_state) |
| 7769 |
check_omp_intervening_code (parser); |
| 7770 |
} |
| 7771 |
if (omp_for_parse_state) |
| 7772 |
omp_for_parse_state->want_nested_loop = want_nested_loop; |
| 7773 |
before_labels = get_before_labels (); |
| 7774 |
} |
| 7775 |
else if (c_parser_next_token_is (parser, CPP_EOF)) |
| 7776 |
{ |
| 7777 |
mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 7778 |
c_parser_error (parser, "expected declaration or statement"); |
| 7779 |
return c_parser_peek_token (parser)->location; |
| 7780 |
} |
| 7781 |
else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 7782 |
{ |
| 7783 |
if (parser->in_if_block) |
| 7784 |
{ |
| 7785 |
mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 7786 |
error_at (loc, "expected %<}%> before %<else%>"); |
| 7787 |
return c_parser_peek_token (parser)->location; |
| 7788 |
} |
| 7789 |
else |
| 7790 |
{ |
| 7791 |
error_at (loc, "%<else%> without a previous %<if%>"); |
| 7792 |
c_parser_consume_token (parser); |
| 7793 |
before_labels = get_before_labels (); |
| 7794 |
astate.reset (); |
| 7795 |
continue; |
| 7796 |
} |
| 7797 |
} |
| 7798 |
else |
| 7799 |
{ |
| 7800 |
statement: |
| 7801 |
c_warn_unused_attributes (std_attrs); |
| 7802 |
last_label = false; |
| 7803 |
last_stmt = true; |
| 7804 |
mark_valid_location_for_stdc_pragma (false); |
| 7805 |
if (!omp_for_parse_state) |
| 7806 |
c_parser_statement_after_labels (parser, NULL, before_labels, |
| 7807 |
NULL, astate); |
| 7808 |
else |
| 7809 |
{ |
| 7810 |
/* In canonical loop nest form, nested loops can only appear |
| 7811 |
directly, or in a directly nested compound statement. We |
| 7812 |
already took care of those cases above, so now we have |
| 7813 |
something else. This statement and everything inside |
| 7814 |
it must be intervening code. */ |
| 7815 |
omp_for_parse_state->want_nested_loop = false; |
| 7816 |
check_omp_intervening_code (parser); |
| 7817 |
c_parser_statement_after_labels (parser, NULL, before_labels); |
| 7818 |
omp_for_parse_state->want_nested_loop = want_nested_loop; |
| 7819 |
} |
| 7820 |
before_labels = get_before_labels (); |
| 7821 |
} |
| 7822 |
|
| 7823 |
parser->error = false; |
| 7824 |
astate.reset (); |
| 7825 |
} |
| 7826 |
if (last_label) |
| 7827 |
pedwarn_c11 (label_loc, OPT_Wfree_labels, |
| 7828 |
"label at end of compound statement"); |
| 7829 |
location_t endloc = c_parser_peek_token (parser)->location; |
| 7830 |
c_parser_consume_token (parser); |
| 7831 |
|
| 7832 |
/* Restore the value we started with. */ |
| 7833 |
mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 7834 |
|
| 7835 |
/* Package leftover intervening code, or the whole contents of the |
| 7836 |
compound statement if we were looking for a nested loop in an OMP_FOR |
| 7837 |
construct and didn't find one. */ |
| 7838 |
if (sl) |
| 7839 |
{ |
| 7840 |
sl = pop_stmt_list (sl); |
| 7841 |
if (omp_for_parse_state->want_nested_loop) |
| 7842 |
add_stmt (sl); |
| 7843 |
else |
| 7844 |
add_structured_block_stmt (sl); |
| 7845 |
} |
| 7846 |
return endloc; |
| 7847 |
} |
| 7848 |
|
| 7849 |
/* Parse all consecutive labels, possibly preceded by standard |
| 7850 |
attributes. In this context, a statement is required, not a |
| 7851 |
declaration, so attributes must be followed by a statement that is |
| 7852 |
not just a semicolon. Returns an attr_state. */ |
| 7853 |
|
| 7854 |
static attr_state |
| 7855 |
c_parser_all_labels (c_parser *parser) |
| 7856 |
{ |
| 7857 |
attr_state attr = {}; |
| 7858 |
bool have_std_attrs; |
| 7859 |
tree std_attrs = NULL; |
| 7860 |
if ((have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1))) |
| 7861 |
{ |
| 7862 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 7863 |
std_attrs = c_parser_handle_musttail (parser, std_attrs, attr); |
| 7864 |
} |
| 7865 |
|
| 7866 |
while (c_parser_next_token_is_keyword (parser, RID_CASE) |
| 7867 |
|| c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
| 7868 |
|| (c_parser_next_token_is (parser, CPP_NAME) |
| 7869 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
| 7870 |
{ |
| 7871 |
c_parser_label (parser, std_attrs); |
| 7872 |
std_attrs = NULL; |
| 7873 |
if ((have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, |
| 7874 |
1))) |
| 7875 |
{ |
| 7876 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 7877 |
std_attrs = c_parser_handle_musttail (parser, std_attrs, attr); |
| 7878 |
} |
| 7879 |
} |
| 7880 |
if (std_attrs |
| 7881 |
&& (!c_parser_handle_statement_omp_attributes (parser, std_attrs, &have_std_attrs) |
| 7882 |
|| std_attrs)) |
| 7883 |
{ |
| 7884 |
if (have_std_attrs && c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 7885 |
c_parser_error (parser, "expected statement"); |
| 7886 |
c_warn_unused_attributes (std_attrs); |
| 7887 |
} |
| 7888 |
else if (have_std_attrs && c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 7889 |
c_parser_error (parser, "expected statement"); |
| 7890 |
return attr; |
| 7891 |
} |
| 7892 |
|
| 7893 |
|
| 7894 |
/* Information used while parsing an OpenMP metadirective. */ |
| 7895 |
struct omp_metadirective_parse_data { |
| 7896 |
/* These fields are used to unique-ify labels when reparsing the |
| 7897 |
code in a metadirective alternative. */ |
| 7898 |
vec<tree> * GTY((skip)) body_labels; |
| 7899 |
unsigned int region_num; |
| 7900 |
}; |
| 7901 |
|
| 7902 |
/* Helper function for c_parser_label: mangle a metadirective region |
| 7903 |
label NAME. */ |
| 7904 |
static tree |
| 7905 |
mangle_metadirective_region_label (c_parser *parser, tree name) |
| 7906 |
{ |
| 7907 |
if (parser->omp_metadirective_state->body_labels->contains (name)) |
| 7908 |
{ |
| 7909 |
const char *old_name = IDENTIFIER_POINTER (name); |
| 7910 |
char *new_name = (char *) XALLOCAVEC (char, strlen (old_name) + 32); |
| 7911 |
sprintf (new_name, "%s_MDR%u", old_name, |
| 7912 |
parser->omp_metadirective_state->region_num); |
| 7913 |
return get_identifier (new_name); |
| 7914 |
} |
| 7915 |
return name; |
| 7916 |
} |
| 7917 |
|
| 7918 |
/* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1). |
| 7919 |
|
| 7920 |
label: |
| 7921 |
identifier : gnu-attributes[opt] |
| 7922 |
case constant-expression : |
| 7923 |
default : |
| 7924 |
|
| 7925 |
GNU extensions: |
| 7926 |
|
| 7927 |
label: |
| 7928 |
case constant-expression ... constant-expression : |
| 7929 |
|
| 7930 |
The use of gnu-attributes on labels is a GNU extension. The syntax in |
| 7931 |
GNU C accepts any expressions without commas, non-constant |
| 7932 |
expressions being rejected later. Any standard |
| 7933 |
attribute-specifier-sequence before the first label has been parsed |
| 7934 |
in the caller, to distinguish statements from declarations. Any |
| 7935 |
attribute-specifier-sequence after the label is parsed in this |
| 7936 |
function. */ |
| 7937 |
static void |
| 7938 |
c_parser_label (c_parser *parser, tree std_attrs) |
| 7939 |
{ |
| 7940 |
location_t loc1 = c_parser_peek_token (parser)->location; |
| 7941 |
tree label = NULL_TREE; |
| 7942 |
|
| 7943 |
/* Remember whether this case or a user-defined label is allowed to fall |
| 7944 |
through to. */ |
| 7945 |
bool fallthrough_p = c_parser_peek_token (parser)->flags & PREV_FALLTHROUGH; |
| 7946 |
|
| 7947 |
if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
| 7948 |
{ |
| 7949 |
tree exp1, exp2; |
| 7950 |
c_parser_consume_token (parser); |
| 7951 |
exp1 = convert_lvalue_to_rvalue (loc1, |
| 7952 |
c_parser_expr_no_commas (parser, NULL), |
| 7953 |
true, true).value; |
| 7954 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 7955 |
{ |
| 7956 |
c_parser_consume_token (parser); |
| 7957 |
label = do_case (loc1, exp1, NULL_TREE, std_attrs); |
| 7958 |
} |
| 7959 |
else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 7960 |
{ |
| 7961 |
c_parser_consume_token (parser); |
| 7962 |
exp2 = convert_lvalue_to_rvalue (loc1, |
| 7963 |
c_parser_expr_no_commas (parser, |
| 7964 |
NULL), |
| 7965 |
true, true).value; |
| 7966 |
if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 7967 |
label = do_case (loc1, exp1, exp2, std_attrs); |
| 7968 |
} |
| 7969 |
else |
| 7970 |
c_parser_error (parser, "expected %<:%> or %<...%>"); |
| 7971 |
} |
| 7972 |
else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) |
| 7973 |
{ |
| 7974 |
c_parser_consume_token (parser); |
| 7975 |
if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 7976 |
label = do_case (loc1, NULL_TREE, NULL_TREE, std_attrs); |
| 7977 |
} |
| 7978 |
else |
| 7979 |
{ |
| 7980 |
tree name = c_parser_peek_token (parser)->value; |
| 7981 |
tree tlab; |
| 7982 |
tree attrs; |
| 7983 |
location_t loc2 = c_parser_peek_token (parser)->location; |
| 7984 |
gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); |
| 7985 |
c_parser_consume_token (parser); |
| 7986 |
gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); |
| 7987 |
c_parser_consume_token (parser); |
| 7988 |
attrs = c_parser_gnu_attributes (parser); |
| 7989 |
if (parser->omp_metadirective_state) |
| 7990 |
name = mangle_metadirective_region_label (parser, name); |
| 7991 |
tlab = define_label (loc2, name); |
| 7992 |
if (tlab) |
| 7993 |
{ |
| 7994 |
decl_attributes (&tlab, attrs, 0); |
| 7995 |
decl_attributes (&tlab, std_attrs, 0); |
| 7996 |
label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); |
| 7997 |
} |
| 7998 |
if (attrs |
| 7999 |
&& c_parser_next_tokens_start_declaration (parser)) |
| 8000 |
warning_at (loc2, OPT_Wattributes, "GNU-style attribute between" |
| 8001 |
" label and declaration appertains to the label"); |
| 8002 |
} |
| 8003 |
if (label) |
| 8004 |
{ |
| 8005 |
if (TREE_CODE (label) == LABEL_EXPR) |
| 8006 |
FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label)) = fallthrough_p; |
| 8007 |
else |
| 8008 |
FALLTHROUGH_LABEL_P (CASE_LABEL (label)) = fallthrough_p; |
| 8009 |
} |
| 8010 |
} |
| 8011 |
|
| 8012 |
/* Parse a statement (C90 6.6, C99 6.8, C11 6.8). |
| 8013 |
|
| 8014 |
statement: |
| 8015 |
labeled-statement |
| 8016 |
attribute-specifier-sequence[opt] compound-statement |
| 8017 |
expression-statement |
| 8018 |
attribute-specifier-sequence[opt] selection-statement |
| 8019 |
attribute-specifier-sequence[opt] iteration-statement |
| 8020 |
attribute-specifier-sequence[opt] jump-statement |
| 8021 |
|
| 8022 |
labeled-statement: |
| 8023 |
attribute-specifier-sequence[opt] label statement |
| 8024 |
|
| 8025 |
expression-statement: |
| 8026 |
expression[opt] ; |
| 8027 |
attribute-specifier-sequence expression ; |
| 8028 |
|
| 8029 |
selection-statement: |
| 8030 |
if-statement |
| 8031 |
switch-statement |
| 8032 |
|
| 8033 |
iteration-statement: |
| 8034 |
while-statement |
| 8035 |
do-statement |
| 8036 |
for-statement |
| 8037 |
|
| 8038 |
jump-statement: |
| 8039 |
goto identifier ; |
| 8040 |
continue ; |
| 8041 |
break ; |
| 8042 |
return expression[opt] ; |
| 8043 |
|
| 8044 |
GNU extensions: |
| 8045 |
|
| 8046 |
statement: |
| 8047 |
attribute-specifier-sequence[opt] asm-statement |
| 8048 |
|
| 8049 |
jump-statement: |
| 8050 |
goto * expression ; |
| 8051 |
|
| 8052 |
expression-statement: |
| 8053 |
gnu-attributes ; |
| 8054 |
|
| 8055 |
Objective-C: |
| 8056 |
|
| 8057 |
statement: |
| 8058 |
attribute-specifier-sequence[opt] objc-throw-statement |
| 8059 |
attribute-specifier-sequence[opt] objc-try-catch-statement |
| 8060 |
attribute-specifier-sequence[opt] objc-synchronized-statement |
| 8061 |
|
| 8062 |
objc-throw-statement: |
| 8063 |
@throw expression ; |
| 8064 |
@throw ; |
| 8065 |
|
| 8066 |
OpenACC: |
| 8067 |
|
| 8068 |
statement: |
| 8069 |
attribute-specifier-sequence[opt] openacc-construct |
| 8070 |
|
| 8071 |
openacc-construct: |
| 8072 |
parallel-construct |
| 8073 |
kernels-construct |
| 8074 |
data-construct |
| 8075 |
loop-construct |
| 8076 |
|
| 8077 |
parallel-construct: |
| 8078 |
parallel-directive structured-block |
| 8079 |
|
| 8080 |
kernels-construct: |
| 8081 |
kernels-directive structured-block |
| 8082 |
|
| 8083 |
data-construct: |
| 8084 |
data-directive structured-block |
| 8085 |
|
| 8086 |
loop-construct: |
| 8087 |
loop-directive structured-block |
| 8088 |
|
| 8089 |
OpenMP: |
| 8090 |
|
| 8091 |
statement: |
| 8092 |
attribute-specifier-sequence[opt] openmp-construct |
| 8093 |
|
| 8094 |
openmp-construct: |
| 8095 |
parallel-construct |
| 8096 |
for-construct |
| 8097 |
simd-construct |
| 8098 |
for-simd-construct |
| 8099 |
sections-construct |
| 8100 |
single-construct |
| 8101 |
parallel-for-construct |
| 8102 |
parallel-for-simd-construct |
| 8103 |
parallel-sections-construct |
| 8104 |
master-construct |
| 8105 |
critical-construct |
| 8106 |
atomic-construct |
| 8107 |
ordered-construct |
| 8108 |
|
| 8109 |
parallel-construct: |
| 8110 |
parallel-directive structured-block |
| 8111 |
|
| 8112 |
for-construct: |
| 8113 |
for-directive iteration-statement |
| 8114 |
|
| 8115 |
simd-construct: |
| 8116 |
simd-directive iteration-statements |
| 8117 |
|
| 8118 |
for-simd-construct: |
| 8119 |
for-simd-directive iteration-statements |
| 8120 |
|
| 8121 |
sections-construct: |
| 8122 |
sections-directive section-scope |
| 8123 |
|
| 8124 |
single-construct: |
| 8125 |
single-directive structured-block |
| 8126 |
|
| 8127 |
parallel-for-construct: |
| 8128 |
parallel-for-directive iteration-statement |
| 8129 |
|
| 8130 |
parallel-for-simd-construct: |
| 8131 |
parallel-for-simd-directive iteration-statement |
| 8132 |
|
| 8133 |
parallel-sections-construct: |
| 8134 |
parallel-sections-directive section-scope |
| 8135 |
|
| 8136 |
master-construct: |
| 8137 |
master-directive structured-block |
| 8138 |
|
| 8139 |
critical-construct: |
| 8140 |
critical-directive structured-block |
| 8141 |
|
| 8142 |
atomic-construct: |
| 8143 |
atomic-directive expression-statement |
| 8144 |
|
| 8145 |
ordered-construct: |
| 8146 |
ordered-directive structured-block |
| 8147 |
|
| 8148 |
Transactional Memory: |
| 8149 |
|
| 8150 |
statement: |
| 8151 |
attribute-specifier-sequence[opt] transaction-statement |
| 8152 |
attribute-specifier-sequence[opt] transaction-cancel-statement |
| 8153 |
|
| 8154 |
IF_P is used to track whether there's a (possibly labeled) if statement |
| 8155 |
which is not enclosed in braces and has an else clause. This is used to |
| 8156 |
implement -Wparentheses. */ |
| 8157 |
|
| 8158 |
static void |
| 8159 |
c_parser_statement (c_parser *parser, bool *if_p, location_t *loc_after_labels) |
| 8160 |
{ |
| 8161 |
tree before_labels = get_before_labels (); |
| 8162 |
attr_state a = c_parser_all_labels (parser); |
| 8163 |
if (loc_after_labels) |
| 8164 |
*loc_after_labels = c_parser_peek_token (parser)->location; |
| 8165 |
parser->omp_attrs_forbidden_p = false; |
| 8166 |
c_parser_statement_after_labels (parser, if_p, before_labels, NULL, a); |
| 8167 |
} |
| 8168 |
|
| 8169 |
/* Parse and handle optional identifier after break or continue keywords. */ |
| 8170 |
|
| 8171 |
static tree |
| 8172 |
c_parser_bc_name (c_parser *parser, bool is_break) |
| 8173 |
{ |
| 8174 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 8175 |
return NULL_TREE; |
| 8176 |
|
| 8177 |
c_token *tok = c_parser_peek_token (parser); |
| 8178 |
tree label = c_finish_bc_name (tok->location, tok->value, is_break); |
| 8179 |
c_parser_consume_token (parser); |
| 8180 |
return label; |
| 8181 |
} |
| 8182 |
|
| 8183 |
/* Parse a statement, other than a labeled statement. CHAIN is a vector |
| 8184 |
of if-else-if conditions. All labels and standard attributes have |
| 8185 |
been parsed in the caller. |
| 8186 |
|
| 8187 |
IF_P is used to track whether there's a (possibly labeled) if statement |
| 8188 |
which is not enclosed in braces and has an else clause. This is used to |
| 8189 |
implement -Wparentheses. ASTATE is an earlier parsed attribute state. |
| 8190 |
|
| 8191 |
BEFORE_LABELS is last statement before possible labels, see |
| 8192 |
get_before_labels description for details. */ |
| 8193 |
|
| 8194 |
static void |
| 8195 |
c_parser_statement_after_labels (c_parser *parser, bool *if_p, |
| 8196 |
tree before_labels, |
| 8197 |
vec<tree> *chain, attr_state astate) |
| 8198 |
{ |
| 8199 |
location_t loc = c_parser_peek_token (parser)->location; |
| 8200 |
tree stmt = NULL_TREE; |
| 8201 |
bool in_if_block = parser->in_if_block; |
| 8202 |
parser->in_if_block = false; |
| 8203 |
if (if_p != NULL) |
| 8204 |
*if_p = false; |
| 8205 |
|
| 8206 |
if (c_parser_peek_token (parser)->type != CPP_OPEN_BRACE) |
| 8207 |
add_debug_begin_stmt (loc); |
| 8208 |
|
| 8209 |
restart: |
| 8210 |
switch (c_parser_peek_token (parser)->type) |
| 8211 |
{ |
| 8212 |
case CPP_OPEN_BRACE: |
| 8213 |
add_stmt (c_parser_compound_statement (parser)); |
| 8214 |
break; |
| 8215 |
case CPP_KEYWORD: |
| 8216 |
switch (c_parser_peek_token (parser)->keyword) |
| 8217 |
{ |
| 8218 |
case RID_IF: |
| 8219 |
c_parser_if_statement (parser, if_p, chain); |
| 8220 |
break; |
| 8221 |
case RID_SWITCH: |
| 8222 |
c_parser_switch_statement (parser, if_p, before_labels); |
| 8223 |
break; |
| 8224 |
case RID_WHILE: |
| 8225 |
c_parser_while_statement (parser, false, 0, false, if_p, before_labels); |
| 8226 |
break; |
| 8227 |
case RID_DO: |
| 8228 |
c_parser_do_statement (parser, false, 0, false, before_labels); |
| 8229 |
break; |
| 8230 |
case RID_FOR: |
| 8231 |
c_parser_for_statement (parser, false, 0, false, if_p, before_labels); |
| 8232 |
break; |
| 8233 |
case RID_GOTO: |
| 8234 |
c_parser_consume_token (parser); |
| 8235 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 8236 |
{ |
| 8237 |
tree name = c_parser_peek_token (parser)->value; |
| 8238 |
if (parser->omp_metadirective_state) |
| 8239 |
name = mangle_metadirective_region_label (parser, name); |
| 8240 |
stmt = c_finish_goto_label (loc, name); |
| 8241 |
c_parser_consume_token (parser); |
| 8242 |
} |
| 8243 |
else if (c_parser_next_token_is (parser, CPP_MULT)) |
| 8244 |
{ |
| 8245 |
struct c_expr val; |
| 8246 |
|
| 8247 |
c_parser_consume_token (parser); |
| 8248 |
val = c_parser_expression (parser); |
| 8249 |
val = convert_lvalue_to_rvalue (loc, val, false, true); |
| 8250 |
stmt = c_finish_goto_ptr (loc, val); |
| 8251 |
} |
| 8252 |
else |
| 8253 |
c_parser_error (parser, "expected identifier or %<*%>"); |
| 8254 |
goto expect_semicolon; |
| 8255 |
case RID_CONTINUE: |
| 8256 |
c_parser_consume_token (parser); |
| 8257 |
stmt = c_finish_bc_stmt (loc, objc_foreach_continue_label, false, |
| 8258 |
c_parser_bc_name (parser, false)); |
| 8259 |
goto expect_semicolon; |
| 8260 |
case RID_BREAK: |
| 8261 |
c_parser_consume_token (parser); |
| 8262 |
stmt = c_finish_bc_stmt (loc, objc_foreach_break_label, true, |
| 8263 |
c_parser_bc_name (parser, true)); |
| 8264 |
goto expect_semicolon; |
| 8265 |
case RID_RETURN: |
| 8266 |
c_parser_consume_token (parser); |
| 8267 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8268 |
{ |
| 8269 |
stmt = c_finish_return (loc, NULL_TREE, NULL_TREE, |
| 8270 |
astate.musttail_p); |
| 8271 |
c_parser_consume_token (parser); |
| 8272 |
} |
| 8273 |
else |
| 8274 |
{ |
| 8275 |
location_t xloc = c_parser_peek_token (parser)->location; |
| 8276 |
struct c_expr expr = c_parser_expression_conv (parser); |
| 8277 |
mark_exp_read (expr.value); |
| 8278 |
stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc), |
| 8279 |
expr.value, expr.original_type, |
| 8280 |
astate.musttail_p); |
| 8281 |
goto expect_semicolon; |
| 8282 |
} |
| 8283 |
break; |
| 8284 |
case RID_ASM: |
| 8285 |
stmt = c_parser_asm_statement (parser); |
| 8286 |
break; |
| 8287 |
case RID_TRANSACTION_ATOMIC: |
| 8288 |
case RID_TRANSACTION_RELAXED: |
| 8289 |
stmt = c_parser_transaction (parser, |
| 8290 |
c_parser_peek_token (parser)->keyword); |
| 8291 |
break; |
| 8292 |
case RID_TRANSACTION_CANCEL: |
| 8293 |
stmt = c_parser_transaction_cancel (parser); |
| 8294 |
goto expect_semicolon; |
| 8295 |
case RID_AT_THROW: |
| 8296 |
gcc_assert (c_dialect_objc ()); |
| 8297 |
c_parser_consume_token (parser); |
| 8298 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8299 |
{ |
| 8300 |
stmt = objc_build_throw_stmt (loc, NULL_TREE); |
| 8301 |
c_parser_consume_token (parser); |
| 8302 |
} |
| 8303 |
else |
| 8304 |
{ |
| 8305 |
struct c_expr expr = c_parser_expression (parser); |
| 8306 |
expr = convert_lvalue_to_rvalue (loc, expr, false, false); |
| 8307 |
expr.value = c_fully_fold (expr.value, false, NULL); |
| 8308 |
stmt = objc_build_throw_stmt (loc, expr.value); |
| 8309 |
goto expect_semicolon; |
| 8310 |
} |
| 8311 |
break; |
| 8312 |
case RID_AT_TRY: |
| 8313 |
gcc_assert (c_dialect_objc ()); |
| 8314 |
c_parser_objc_try_catch_finally_statement (parser); |
| 8315 |
break; |
| 8316 |
case RID_AT_SYNCHRONIZED: |
| 8317 |
gcc_assert (c_dialect_objc ()); |
| 8318 |
c_parser_objc_synchronized_statement (parser); |
| 8319 |
break; |
| 8320 |
case RID_ATTRIBUTE: |
| 8321 |
{ |
| 8322 |
/* Allow '__attribute__((fallthrough));' or |
| 8323 |
'__attribute__((assume(cond)));' or |
| 8324 |
'__attribute__((musttail))) return'. */ |
| 8325 |
tree attrs = c_parser_gnu_attributes (parser); |
| 8326 |
bool has_assume = lookup_attribute ("assume", attrs); |
| 8327 |
if (has_assume) |
| 8328 |
{ |
| 8329 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8330 |
attrs = handle_assume_attribute (loc, attrs, true); |
| 8331 |
else |
| 8332 |
{ |
| 8333 |
auto_urlify_attributes sentinel; |
| 8334 |
warning_at (loc, OPT_Wattributes, |
| 8335 |
"%<assume%> attribute not followed by %<;%>"); |
| 8336 |
has_assume = false; |
| 8337 |
} |
| 8338 |
} |
| 8339 |
gcc_assert (!astate.musttail_p); |
| 8340 |
attrs = c_parser_handle_musttail (parser, attrs, astate); |
| 8341 |
if (astate.musttail_p) |
| 8342 |
{ |
| 8343 |
if (attrs) |
| 8344 |
{ |
| 8345 |
auto_urlify_attributes sentinel; |
| 8346 |
warning_at (c_parser_peek_token (parser)->location, |
| 8347 |
OPT_Wattributes, |
| 8348 |
"attribute %<musttail%> mixed with other " |
| 8349 |
"attributes on %<return%> statement"); |
| 8350 |
} |
| 8351 |
goto restart; |
| 8352 |
} |
| 8353 |
if (attribute_fallthrough_p (attrs)) |
| 8354 |
{ |
| 8355 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8356 |
{ |
| 8357 |
tree fn = build_call_expr_internal_loc (loc, |
| 8358 |
IFN_FALLTHROUGH, |
| 8359 |
void_type_node, 0); |
| 8360 |
add_stmt (fn); |
| 8361 |
/* Eat the ';'. */ |
| 8362 |
c_parser_consume_token (parser); |
| 8363 |
} |
| 8364 |
else |
| 8365 |
{ |
| 8366 |
auto_urlify_attributes sentinel; |
| 8367 |
warning_at (loc, OPT_Wattributes, |
| 8368 |
"%<fallthrough%> attribute not followed " |
| 8369 |
"by %<;%>"); |
| 8370 |
} |
| 8371 |
} |
| 8372 |
else if (has_assume) |
| 8373 |
/* Eat the ';'. */ |
| 8374 |
c_parser_consume_token (parser); |
| 8375 |
else if (attrs != NULL_TREE) |
| 8376 |
{ |
| 8377 |
auto_urlify_attributes sentinel; |
| 8378 |
warning_at (loc, OPT_Wattributes, |
| 8379 |
"only attribute %<fallthrough%> or %<assume%> can " |
| 8380 |
"be applied to a null statement"); |
| 8381 |
} |
| 8382 |
break; |
| 8383 |
} |
| 8384 |
default: |
| 8385 |
goto expr_stmt; |
| 8386 |
} |
| 8387 |
break; |
| 8388 |
case CPP_SEMICOLON: |
| 8389 |
c_parser_consume_token (parser); |
| 8390 |
break; |
| 8391 |
case CPP_CLOSE_PAREN: |
| 8392 |
case CPP_CLOSE_SQUARE: |
| 8393 |
/* Avoid infinite loop in error recovery: |
| 8394 |
c_parser_skip_until_found stops at a closing nesting |
| 8395 |
delimiter without consuming it, but here we need to consume |
| 8396 |
it to proceed further. */ |
| 8397 |
c_parser_error (parser, "expected statement"); |
| 8398 |
c_parser_consume_token (parser); |
| 8399 |
break; |
| 8400 |
case CPP_PRAGMA: |
| 8401 |
if (!c_parser_pragma (parser, pragma_stmt, if_p, before_labels)) |
| 8402 |
goto restart; |
| 8403 |
break; |
| 8404 |
default: |
| 8405 |
expr_stmt: |
| 8406 |
stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value); |
| 8407 |
expect_semicolon: |
| 8408 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 8409 |
break; |
| 8410 |
} |
| 8411 |
/* Two cases cannot and do not have line numbers associated: If stmt |
| 8412 |
is degenerate, such as "2;", then stmt is an INTEGER_CST, which |
| 8413 |
cannot hold line numbers. But that's OK because the statement |
| 8414 |
will either be changed to a MODIFY_EXPR during gimplification of |
| 8415 |
the statement expr, or discarded. If stmt was compound, but |
| 8416 |
without new variables, we will have skipped the creation of a |
| 8417 |
BIND and will have a bare STATEMENT_LIST. But that's OK because |
| 8418 |
(recursively) all of the component statements should already have |
| 8419 |
line numbers assigned. ??? Can we discard no-op statements |
| 8420 |
earlier? */ |
| 8421 |
if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION) |
| 8422 |
protected_set_expr_location (stmt, loc); |
| 8423 |
|
| 8424 |
parser->in_if_block = in_if_block; |
| 8425 |
} |
| 8426 |
|
| 8427 |
/* Parse the condition from an if, do, while or for statements. */ |
| 8428 |
|
| 8429 |
static tree |
| 8430 |
c_parser_condition (c_parser *parser) |
| 8431 |
{ |
| 8432 |
location_t loc = c_parser_peek_token (parser)->location; |
| 8433 |
tree cond; |
| 8434 |
cond = c_parser_expression_conv (parser).value; |
| 8435 |
cond = c_objc_common_truthvalue_conversion (loc, cond); |
| 8436 |
cond = c_fully_fold (cond, false, NULL); |
| 8437 |
if (warn_sequence_point) |
| 8438 |
verify_sequence_points (cond); |
| 8439 |
return cond; |
| 8440 |
} |
| 8441 |
|
| 8442 |
/* Parse a parenthesized condition from a do or while statement. |
| 8443 |
|
| 8444 |
condition: |
| 8445 |
( expression ) |
| 8446 |
*/ |
| 8447 |
|
| 8448 |
static tree |
| 8449 |
c_parser_paren_condition (c_parser *parser) |
| 8450 |
{ |
| 8451 |
tree cond; |
| 8452 |
matching_parens parens; |
| 8453 |
if (!parens.require_open (parser)) |
| 8454 |
return error_mark_node; |
| 8455 |
cond = c_parser_condition (parser); |
| 8456 |
parens.skip_until_found_close (parser); |
| 8457 |
return cond; |
| 8458 |
} |
| 8459 |
|
| 8460 |
/* Parse a selection-header: |
| 8461 |
|
| 8462 |
selection-header: |
| 8463 |
expression |
| 8464 |
declaration expression |
| 8465 |
simple-declaration |
| 8466 |
|
| 8467 |
simple-declaration: |
| 8468 |
attribute-specifier-sequence[opt] declaration-specifiers declarator |
| 8469 |
= initializer |
| 8470 |
|
| 8471 |
SWITCH_P is true if we are called from c_parser_switch_statement; in |
| 8472 |
that case, don't perform the truthvalue conversion. */ |
| 8473 |
|
| 8474 |
static c_expr |
| 8475 |
c_parser_selection_header (c_parser *parser, bool switch_p) |
| 8476 |
{ |
| 8477 |
location_t loc = c_parser_peek_token (parser)->location; |
| 8478 |
c_expr expr; |
| 8479 |
bool parse_expr = true; |
| 8480 |
tree std_attrs; |
| 8481 |
bool have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1); |
| 8482 |
if (have_std_attrs) |
| 8483 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 8484 |
else |
| 8485 |
std_attrs = NULL_TREE; |
| 8486 |
if (c_parser_next_tokens_start_declaration (parser)) |
| 8487 |
{ |
| 8488 |
pedwarn_c23 (loc, OPT_Wpedantic, |
| 8489 |
"ISO C does not support if declarations before C2Y"); |
| 8490 |
expr.value |
| 8491 |
= c_parser_declaration_or_fndef (parser, |
| 8492 |
/*fndef_ok=*/false, |
| 8493 |
/*static_assert_ok=*/false, |
| 8494 |
/*empty_ok=*/false, |
| 8495 |
/*nested=*/true, |
| 8496 |
/*start_attr_ok=*/true, |
| 8497 |
/*simple_ok=*/true, |
| 8498 |
/*objc_foreach_object_decl=*/nullptr, |
| 8499 |
/*omp_declare_simd_clauses=*/nullptr, |
| 8500 |
have_std_attrs, |
| 8501 |
std_attrs); |
| 8502 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8503 |
c_parser_consume_token (parser); |
| 8504 |
else |
| 8505 |
{ |
| 8506 |
/* A simple-declaration is a declaration that can appear in |
| 8507 |
place of the controlling expression of a selection statement. |
| 8508 |
In that case, there shall be an initializer. */ |
| 8509 |
if (!expr.value) |
| 8510 |
{ |
| 8511 |
error_at (loc, "declaration in the controlling expression must " |
| 8512 |
"have an initializer"); |
| 8513 |
expr.original_type = error_mark_node; |
| 8514 |
expr.set_error (); |
| 8515 |
return expr; |
| 8516 |
} |
| 8517 |
parse_expr = false; |
| 8518 |
} |
| 8519 |
if (expr.value) |
| 8520 |
{ |
| 8521 |
expr.original_type = TREE_TYPE (expr.value); |
| 8522 |
expr = convert_lvalue_to_rvalue (loc, expr, /*convert_p=*/true, |
| 8523 |
/*read_p=*/true); |
| 8524 |
} |
| 8525 |
} |
| 8526 |
else if (have_std_attrs) |
| 8527 |
{ |
| 8528 |
c_parser_error (parser, "expected declaration"); |
| 8529 |
expr.original_type = error_mark_node; |
| 8530 |
expr.set_error (); |
| 8531 |
return expr; |
| 8532 |
} |
| 8533 |
|
| 8534 |
if (parse_expr) |
| 8535 |
expr = c_parser_expression_conv (parser); |
| 8536 |
if (!switch_p) |
| 8537 |
{ |
| 8538 |
expr.value = c_objc_common_truthvalue_conversion (loc, expr.value); |
| 8539 |
expr.value = c_fully_fold (expr.value, false, NULL); |
| 8540 |
if (warn_sequence_point) |
| 8541 |
verify_sequence_points (expr.value); |
| 8542 |
} |
| 8543 |
return expr; |
| 8544 |
} |
| 8545 |
|
| 8546 |
/* Parse a selection-header enclosed in parentheses: |
| 8547 |
|
| 8548 |
( selection-header ) |
| 8549 |
*/ |
| 8550 |
|
| 8551 |
static tree |
| 8552 |
c_parser_paren_selection_header (c_parser *parser) |
| 8553 |
{ |
| 8554 |
matching_parens parens; |
| 8555 |
if (!parens.require_open (parser)) |
| 8556 |
return error_mark_node; |
| 8557 |
tree cond = c_parser_selection_header (parser, /*switch_p=*/false).value; |
| 8558 |
parens.skip_until_found_close (parser); |
| 8559 |
return cond; |
| 8560 |
} |
| 8561 |
|
| 8562 |
/* Parse a statement which is a block in C99. |
| 8563 |
|
| 8564 |
IF_P is used to track whether there's a (possibly labeled) if statement |
| 8565 |
which is not enclosed in braces and has an else clause. This is used to |
| 8566 |
implement -Wparentheses. */ |
| 8567 |
|
| 8568 |
static tree |
| 8569 |
c_parser_c99_block_statement (c_parser *parser, bool *if_p, |
| 8570 |
location_t *loc_after_labels) |
| 8571 |
{ |
| 8572 |
tree block = c_begin_compound_stmt (flag_isoc99); |
| 8573 |
location_t loc = c_parser_peek_token (parser)->location; |
| 8574 |
c_parser_statement (parser, if_p, loc_after_labels); |
| 8575 |
return c_end_compound_stmt (loc, block, flag_isoc99); |
| 8576 |
} |
| 8577 |
|
| 8578 |
/* Parse the body of an if statement. This is just parsing a |
| 8579 |
statement but (a) it is a block in C99, (b) we track whether the |
| 8580 |
body is an if statement for the sake of -Wparentheses warnings, (c) |
| 8581 |
we handle an empty body specially for the sake of -Wempty-body |
| 8582 |
warnings, and (d) we call parser_compound_statement directly |
| 8583 |
because c_parser_statement_after_labels resets |
| 8584 |
parser->in_if_block. |
| 8585 |
|
| 8586 |
IF_P is used to track whether there's a (possibly labeled) if statement |
| 8587 |
which is not enclosed in braces and has an else clause. This is used to |
| 8588 |
implement -Wparentheses. */ |
| 8589 |
|
| 8590 |
static tree |
| 8591 |
c_parser_if_body (c_parser *parser, bool *if_p, |
| 8592 |
const token_indent_info &if_tinfo) |
| 8593 |
{ |
| 8594 |
tree block = c_begin_compound_stmt (flag_isoc99); |
| 8595 |
location_t body_loc = c_parser_peek_token (parser)->location; |
| 8596 |
location_t body_loc_after_labels = UNKNOWN_LOCATION; |
| 8597 |
token_indent_info body_tinfo |
| 8598 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8599 |
tree before_labels = get_before_labels (); |
| 8600 |
attr_state a = c_parser_all_labels (parser); |
| 8601 |
|
| 8602 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8603 |
{ |
| 8604 |
location_t loc = c_parser_peek_token (parser)->location; |
| 8605 |
add_stmt (build_empty_stmt (loc)); |
| 8606 |
c_parser_consume_token (parser); |
| 8607 |
if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 8608 |
warning_at (loc, OPT_Wempty_body, |
| 8609 |
"suggest braces around empty body in an %<if%> statement"); |
| 8610 |
} |
| 8611 |
else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 8612 |
add_stmt (c_parser_compound_statement (parser)); |
| 8613 |
else |
| 8614 |
{ |
| 8615 |
body_loc_after_labels = c_parser_peek_token (parser)->location; |
| 8616 |
c_parser_statement_after_labels (parser, if_p, before_labels, NULL, a); |
| 8617 |
} |
| 8618 |
|
| 8619 |
token_indent_info next_tinfo |
| 8620 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8621 |
warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo); |
| 8622 |
if (body_loc_after_labels != UNKNOWN_LOCATION |
| 8623 |
&& next_tinfo.type != CPP_SEMICOLON) |
| 8624 |
warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location, |
| 8625 |
if_tinfo.location, RID_IF); |
| 8626 |
|
| 8627 |
return c_end_compound_stmt (body_loc, block, flag_isoc99); |
| 8628 |
} |
| 8629 |
|
| 8630 |
/* Parse the else body of an if statement. This is just parsing a |
| 8631 |
statement but (a) it is a block in C99, (b) we handle an empty body |
| 8632 |
specially for the sake of -Wempty-body warnings. CHAIN is a vector |
| 8633 |
of if-else-if conditions. */ |
| 8634 |
|
| 8635 |
static tree |
| 8636 |
c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo, |
| 8637 |
vec<tree> *chain) |
| 8638 |
{ |
| 8639 |
location_t body_loc = c_parser_peek_token (parser)->location; |
| 8640 |
tree block = c_begin_compound_stmt (flag_isoc99); |
| 8641 |
token_indent_info body_tinfo |
| 8642 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8643 |
location_t body_loc_after_labels = UNKNOWN_LOCATION; |
| 8644 |
tree before_labels = get_before_labels (); |
| 8645 |
attr_state a = c_parser_all_labels (parser); |
| 8646 |
|
| 8647 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8648 |
{ |
| 8649 |
location_t loc = c_parser_peek_token (parser)->location; |
| 8650 |
warning_at (loc, |
| 8651 |
OPT_Wempty_body, |
| 8652 |
"suggest braces around empty body in an %<else%> statement"); |
| 8653 |
add_stmt (build_empty_stmt (loc)); |
| 8654 |
c_parser_consume_token (parser); |
| 8655 |
} |
| 8656 |
else |
| 8657 |
{ |
| 8658 |
if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 8659 |
body_loc_after_labels = c_parser_peek_token (parser)->location; |
| 8660 |
c_parser_statement_after_labels (parser, NULL, before_labels, chain, a); |
| 8661 |
} |
| 8662 |
|
| 8663 |
token_indent_info next_tinfo |
| 8664 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8665 |
warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo); |
| 8666 |
if (body_loc_after_labels != UNKNOWN_LOCATION |
| 8667 |
&& next_tinfo.type != CPP_SEMICOLON) |
| 8668 |
warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location, |
| 8669 |
else_tinfo.location, RID_ELSE); |
| 8670 |
|
| 8671 |
return c_end_compound_stmt (body_loc, block, flag_isoc99); |
| 8672 |
} |
| 8673 |
|
| 8674 |
/* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4). |
| 8675 |
|
| 8676 |
if-statement: |
| 8677 |
if ( selection-header ) statement |
| 8678 |
if ( selection-header ) statement else statement |
| 8679 |
|
| 8680 |
CHAIN is a vector of if-else-if conditions. |
| 8681 |
IF_P is used to track whether there's a (possibly labeled) if statement |
| 8682 |
which is not enclosed in braces and has an else clause. This is used to |
| 8683 |
implement -Wparentheses. */ |
| 8684 |
|
| 8685 |
static void |
| 8686 |
c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain) |
| 8687 |
{ |
| 8688 |
tree block; |
| 8689 |
location_t loc; |
| 8690 |
tree cond; |
| 8691 |
bool nested_if = false; |
| 8692 |
tree first_body, second_body; |
| 8693 |
bool in_if_block; |
| 8694 |
|
| 8695 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF)); |
| 8696 |
token_indent_info if_tinfo |
| 8697 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8698 |
c_parser_consume_token (parser); |
| 8699 |
block = c_begin_compound_stmt (flag_isoc99); |
| 8700 |
loc = c_parser_peek_token (parser)->location; |
| 8701 |
cond = c_parser_paren_selection_header (parser); |
| 8702 |
in_if_block = parser->in_if_block; |
| 8703 |
parser->in_if_block = true; |
| 8704 |
first_body = c_parser_if_body (parser, &nested_if, if_tinfo); |
| 8705 |
parser->in_if_block = in_if_block; |
| 8706 |
|
| 8707 |
if (warn_duplicated_cond) |
| 8708 |
warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain); |
| 8709 |
|
| 8710 |
if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 8711 |
{ |
| 8712 |
token_indent_info else_tinfo |
| 8713 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8714 |
c_parser_consume_token (parser); |
| 8715 |
if (warn_duplicated_cond) |
| 8716 |
{ |
| 8717 |
if (c_parser_next_token_is_keyword (parser, RID_IF) |
| 8718 |
&& chain == NULL) |
| 8719 |
{ |
| 8720 |
/* We've got "if (COND) else if (COND2)". Start the |
| 8721 |
condition chain and add COND as the first element. */ |
| 8722 |
chain = new vec<tree> (); |
| 8723 |
if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond)) |
| 8724 |
chain->safe_push (cond); |
| 8725 |
} |
| 8726 |
else if (!c_parser_next_token_is_keyword (parser, RID_IF)) |
| 8727 |
/* This is if-else without subsequent if. Zap the condition |
| 8728 |
chain; we would have already warned at this point. */ |
| 8729 |
vec_free (chain); |
| 8730 |
} |
| 8731 |
second_body = c_parser_else_body (parser, else_tinfo, chain); |
| 8732 |
/* Set IF_P to true to indicate that this if statement has an |
| 8733 |
else clause. This may trigger the Wparentheses warning |
| 8734 |
below when we get back up to the parent if statement. */ |
| 8735 |
if (if_p != NULL) |
| 8736 |
*if_p = true; |
| 8737 |
} |
| 8738 |
else |
| 8739 |
{ |
| 8740 |
second_body = NULL_TREE; |
| 8741 |
|
| 8742 |
/* Diagnose an ambiguous else if if-then-else is nested inside |
| 8743 |
if-then. */ |
| 8744 |
if (nested_if) |
| 8745 |
warning_at (loc, OPT_Wdangling_else, |
| 8746 |
"suggest explicit braces to avoid ambiguous %<else%>"); |
| 8747 |
|
| 8748 |
if (warn_duplicated_cond) |
| 8749 |
/* This if statement does not have an else clause. We don't |
| 8750 |
need the condition chain anymore. */ |
| 8751 |
vec_free (chain); |
| 8752 |
} |
| 8753 |
c_finish_if_stmt (loc, cond, first_body, second_body); |
| 8754 |
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
| 8755 |
|
| 8756 |
c_parser_maybe_reclassify_token (parser); |
| 8757 |
} |
| 8758 |
|
| 8759 |
/* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4). |
| 8760 |
|
| 8761 |
switch-statement: |
| 8762 |
switch (expression) statement |
| 8763 |
|
| 8764 |
BEFORE_LABELS is last statement before possible labels, see |
| 8765 |
get_before_labels description for details. */ |
| 8766 |
|
| 8767 |
static void |
| 8768 |
c_parser_switch_statement (c_parser *parser, bool *if_p, tree before_labels) |
| 8769 |
{ |
| 8770 |
struct c_expr ce; |
| 8771 |
tree block, expr, body; |
| 8772 |
unsigned char save_in_statement; |
| 8773 |
location_t switch_loc = c_parser_peek_token (parser)->location; |
| 8774 |
location_t switch_cond_loc; |
| 8775 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH)); |
| 8776 |
c_parser_consume_token (parser); |
| 8777 |
tree switch_name; |
| 8778 |
int num_names = c_get_loop_names (before_labels, true, &switch_name); |
| 8779 |
block = c_begin_compound_stmt (flag_isoc99); |
| 8780 |
bool explicit_cast_p = false; |
| 8781 |
matching_parens parens; |
| 8782 |
if (parens.require_open (parser)) |
| 8783 |
{ |
| 8784 |
switch_cond_loc = c_parser_peek_token (parser)->location; |
| 8785 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 8786 |
&& c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 8787 |
explicit_cast_p = true; |
| 8788 |
ce = c_parser_selection_header (parser, /*switch_p=*/true); |
| 8789 |
/* The call above already performed convert_lvalue_to_rvalue, but |
| 8790 |
if it parsed an expression, read_p was false. Make sure we mark |
| 8791 |
the expression as read. */ |
| 8792 |
ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, true); |
| 8793 |
expr = ce.value; |
| 8794 |
/* ??? expr has no valid location? */ |
| 8795 |
parens.skip_until_found_close (parser); |
| 8796 |
} |
| 8797 |
else |
| 8798 |
{ |
| 8799 |
switch_cond_loc = UNKNOWN_LOCATION; |
| 8800 |
expr = error_mark_node; |
| 8801 |
ce.original_type = error_mark_node; |
| 8802 |
} |
| 8803 |
tree stmt |
| 8804 |
= c_start_switch (switch_loc, switch_cond_loc, expr, explicit_cast_p, |
| 8805 |
switch_name); |
| 8806 |
save_in_statement = in_statement; |
| 8807 |
in_statement |= IN_SWITCH_STMT; |
| 8808 |
if (switch_name) |
| 8809 |
{ |
| 8810 |
C_DECL_LOOP_SWITCH_NAME_VALID (switch_name) = 1; |
| 8811 |
in_statement |= IN_NAMED_STMT; |
| 8812 |
} |
| 8813 |
else |
| 8814 |
in_statement &= ~IN_NAMED_STMT; |
| 8815 |
location_t loc_after_labels; |
| 8816 |
bool open_brace_p = c_parser_peek_token (parser)->type == CPP_OPEN_BRACE; |
| 8817 |
body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels); |
| 8818 |
location_t next_loc = c_parser_peek_token (parser)->location; |
| 8819 |
if (!open_brace_p && c_parser_peek_token (parser)->type != CPP_SEMICOLON) |
| 8820 |
warn_for_multistatement_macros (loc_after_labels, next_loc, switch_loc, |
| 8821 |
RID_SWITCH); |
| 8822 |
c_finish_switch (body, ce.original_type); |
| 8823 |
in_statement = save_in_statement; |
| 8824 |
if (num_names) |
| 8825 |
{ |
| 8826 |
if (!C_DECL_LOOP_SWITCH_NAME_USED (switch_name)) |
| 8827 |
SWITCH_STMT_NAME (stmt) = NULL_TREE; |
| 8828 |
else |
| 8829 |
SWITCH_STMT_NO_BREAK_P (stmt) = 0; |
| 8830 |
c_release_loop_names (num_names); |
| 8831 |
} |
| 8832 |
add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99)); |
| 8833 |
c_parser_maybe_reclassify_token (parser); |
| 8834 |
} |
| 8835 |
|
| 8836 |
/* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5). |
| 8837 |
|
| 8838 |
while-statement: |
| 8839 |
while (expression) statement |
| 8840 |
|
| 8841 |
IF_P is used to track whether there's a (possibly labeled) if statement |
| 8842 |
which is not enclosed in braces and has an else clause. This is used to |
| 8843 |
implement -Wparentheses. |
| 8844 |
|
| 8845 |
BEFORE_LABELS is last statement before possible labels, see |
| 8846 |
get_before_labels description for details. */ |
| 8847 |
|
| 8848 |
static void |
| 8849 |
c_parser_while_statement (c_parser *parser, bool ivdep, unsigned short unroll, |
| 8850 |
bool novector, bool *if_p, tree before_labels) |
| 8851 |
{ |
| 8852 |
tree block, cond, body; |
| 8853 |
unsigned char save_in_statement; |
| 8854 |
location_t loc; |
| 8855 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE)); |
| 8856 |
token_indent_info while_tinfo |
| 8857 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8858 |
tree loop_name; |
| 8859 |
int num_names = c_get_loop_names (before_labels, false, &loop_name); |
| 8860 |
|
| 8861 |
if (parser->omp_for_parse_state) |
| 8862 |
{ |
| 8863 |
error_at (c_parser_peek_token (parser)->location, |
| 8864 |
"loop not permitted in intervening code in OpenMP loop body"); |
| 8865 |
parser->omp_for_parse_state->fail = true; |
| 8866 |
} |
| 8867 |
|
| 8868 |
c_parser_consume_token (parser); |
| 8869 |
block = c_begin_compound_stmt (flag_isoc99); |
| 8870 |
loc = c_parser_peek_token (parser)->location; |
| 8871 |
cond = c_parser_paren_condition (parser); |
| 8872 |
if (ivdep && cond != error_mark_node) |
| 8873 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 8874 |
build_int_cst (integer_type_node, |
| 8875 |
annot_expr_ivdep_kind), |
| 8876 |
integer_zero_node); |
| 8877 |
if (unroll && cond != error_mark_node) |
| 8878 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 8879 |
build_int_cst (integer_type_node, |
| 8880 |
annot_expr_unroll_kind), |
| 8881 |
build_int_cst (integer_type_node, unroll)); |
| 8882 |
if (novector && cond != error_mark_node) |
| 8883 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 8884 |
build_int_cst (integer_type_node, |
| 8885 |
annot_expr_no_vector_kind), |
| 8886 |
integer_zero_node); |
| 8887 |
save_in_statement = in_statement; |
| 8888 |
in_statement = IN_ITERATION_STMT; |
| 8889 |
if (loop_name) |
| 8890 |
{ |
| 8891 |
C_DECL_LOOP_SWITCH_NAME_VALID (loop_name) = 1; |
| 8892 |
in_statement |= IN_NAMED_STMT; |
| 8893 |
} |
| 8894 |
|
| 8895 |
token_indent_info body_tinfo |
| 8896 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8897 |
|
| 8898 |
location_t loc_after_labels; |
| 8899 |
bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE); |
| 8900 |
body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels); |
| 8901 |
if (loop_name && !C_DECL_LOOP_SWITCH_NAME_USED (loop_name)) |
| 8902 |
loop_name = NULL_TREE; |
| 8903 |
add_stmt (build_stmt (loc, WHILE_STMT, cond, body, loop_name, NULL_TREE, |
| 8904 |
NULL_TREE)); |
| 8905 |
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
| 8906 |
c_parser_maybe_reclassify_token (parser); |
| 8907 |
if (num_names) |
| 8908 |
c_release_loop_names (num_names); |
| 8909 |
|
| 8910 |
token_indent_info next_tinfo |
| 8911 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 8912 |
warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo); |
| 8913 |
|
| 8914 |
if (next_tinfo.type != CPP_SEMICOLON && !open_brace) |
| 8915 |
warn_for_multistatement_macros (loc_after_labels, next_tinfo.location, |
| 8916 |
while_tinfo.location, RID_WHILE); |
| 8917 |
|
| 8918 |
in_statement = save_in_statement; |
| 8919 |
} |
| 8920 |
|
| 8921 |
/* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5). |
| 8922 |
|
| 8923 |
do-statement: |
| 8924 |
do statement while ( expression ) ; |
| 8925 |
|
| 8926 |
BEFORE_LABELS is last statement before possible labels, see |
| 8927 |
get_before_labels description for details. */ |
| 8928 |
|
| 8929 |
static void |
| 8930 |
c_parser_do_statement (c_parser *parser, bool ivdep, unsigned short unroll, |
| 8931 |
bool novector, tree before_labels) |
| 8932 |
{ |
| 8933 |
tree block, cond, body; |
| 8934 |
unsigned char save_in_statement; |
| 8935 |
location_t loc; |
| 8936 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); |
| 8937 |
tree loop_name; |
| 8938 |
int num_names = c_get_loop_names (before_labels, false, &loop_name); |
| 8939 |
|
| 8940 |
if (parser->omp_for_parse_state) |
| 8941 |
{ |
| 8942 |
error_at (c_parser_peek_token (parser)->location, |
| 8943 |
"loop not permitted in intervening code in OpenMP loop body"); |
| 8944 |
parser->omp_for_parse_state->fail = true; |
| 8945 |
} |
| 8946 |
|
| 8947 |
c_parser_consume_token (parser); |
| 8948 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8949 |
warning_at (c_parser_peek_token (parser)->location, |
| 8950 |
OPT_Wempty_body, |
| 8951 |
"suggest braces around empty body in %<do%> statement"); |
| 8952 |
block = c_begin_compound_stmt (flag_isoc99); |
| 8953 |
loc = c_parser_peek_token (parser)->location; |
| 8954 |
save_in_statement = in_statement; |
| 8955 |
in_statement = IN_ITERATION_STMT; |
| 8956 |
if (loop_name) |
| 8957 |
{ |
| 8958 |
C_DECL_LOOP_SWITCH_NAME_VALID (loop_name) = 1; |
| 8959 |
in_statement |= IN_NAMED_STMT; |
| 8960 |
} |
| 8961 |
body = c_parser_c99_block_statement (parser, NULL); |
| 8962 |
c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>"); |
| 8963 |
in_statement = save_in_statement; |
| 8964 |
if (num_names) |
| 8965 |
{ |
| 8966 |
if (!C_DECL_LOOP_SWITCH_NAME_USED (loop_name)) |
| 8967 |
loop_name = NULL_TREE; |
| 8968 |
c_release_loop_names (num_names); |
| 8969 |
} |
| 8970 |
cond = c_parser_paren_condition (parser); |
| 8971 |
if (ivdep && cond != error_mark_node) |
| 8972 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 8973 |
build_int_cst (integer_type_node, |
| 8974 |
annot_expr_ivdep_kind), |
| 8975 |
integer_zero_node); |
| 8976 |
if (unroll && cond != error_mark_node) |
| 8977 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 8978 |
build_int_cst (integer_type_node, |
| 8979 |
annot_expr_unroll_kind), |
| 8980 |
build_int_cst (integer_type_node, unroll)); |
| 8981 |
if (novector && cond != error_mark_node) |
| 8982 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 8983 |
build_int_cst (integer_type_node, |
| 8984 |
annot_expr_no_vector_kind), |
| 8985 |
integer_zero_node); |
| 8986 |
if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 8987 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 8988 |
|
| 8989 |
add_stmt (build_stmt (loc, DO_STMT, cond, body, loop_name)); |
| 8990 |
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
| 8991 |
} |
| 8992 |
|
| 8993 |
/* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5). |
| 8994 |
|
| 8995 |
for-statement: |
| 8996 |
for ( expression[opt] ; expression[opt] ; expression[opt] ) statement |
| 8997 |
for ( nested-declaration expression[opt] ; expression[opt] ) statement |
| 8998 |
|
| 8999 |
The form with a declaration is new in C99. |
| 9000 |
|
| 9001 |
??? In accordance with the old parser, the declaration may be a |
| 9002 |
nested function, which is then rejected in check_for_loop_decls, |
| 9003 |
but does it make any sense for this to be included in the grammar? |
| 9004 |
Note in particular that the nested function does not include a |
| 9005 |
trailing ';', whereas the "declaration" production includes one. |
| 9006 |
Also, can we reject bad declarations earlier and cheaper than |
| 9007 |
check_for_loop_decls? |
| 9008 |
|
| 9009 |
In Objective-C, there are two additional variants: |
| 9010 |
|
| 9011 |
foreach-statement: |
| 9012 |
for ( expression in expresssion ) statement |
| 9013 |
for ( declaration in expression ) statement |
| 9014 |
|
| 9015 |
This is inconsistent with C, because the second variant is allowed |
| 9016 |
even if c99 is not enabled. |
| 9017 |
|
| 9018 |
The rest of the comment documents these Objective-C foreach-statement. |
| 9019 |
|
| 9020 |
Here is the canonical example of the first variant: |
| 9021 |
for (object in array) { do something with object } |
| 9022 |
we call the first expression ("object") the "object_expression" and |
| 9023 |
the second expression ("array") the "collection_expression". |
| 9024 |
object_expression must be an lvalue of type "id" (a generic Objective-C |
| 9025 |
object) because the loop works by assigning to object_expression the |
| 9026 |
various objects from the collection_expression. collection_expression |
| 9027 |
must evaluate to something of type "id" which responds to the method |
| 9028 |
countByEnumeratingWithState:objects:count:. |
| 9029 |
|
| 9030 |
The canonical example of the second variant is: |
| 9031 |
for (id object in array) { do something with object } |
| 9032 |
which is completely equivalent to |
| 9033 |
{ |
| 9034 |
id object; |
| 9035 |
for (object in array) { do something with object } |
| 9036 |
} |
| 9037 |
Note that initizializing 'object' in some way (eg, "for ((object = |
| 9038 |
xxx) in array) { do something with object }") is possibly |
| 9039 |
technically valid, but completely pointless as 'object' will be |
| 9040 |
assigned to something else as soon as the loop starts. We should |
| 9041 |
most likely reject it (TODO). |
| 9042 |
|
| 9043 |
The beginning of the Objective-C foreach-statement looks exactly |
| 9044 |
like the beginning of the for-statement, and we can tell it is a |
| 9045 |
foreach-statement only because the initial declaration or |
| 9046 |
expression is terminated by 'in' instead of ';'. |
| 9047 |
|
| 9048 |
IF_P is used to track whether there's a (possibly labeled) if statement |
| 9049 |
which is not enclosed in braces and has an else clause. This is used to |
| 9050 |
implement -Wparentheses. |
| 9051 |
|
| 9052 |
BEFORE_LABELS is last statement before possible labels, see |
| 9053 |
get_before_labels description for details. */ |
| 9054 |
|
| 9055 |
static void |
| 9056 |
c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll, |
| 9057 |
bool novector, bool *if_p, tree before_labels) |
| 9058 |
{ |
| 9059 |
tree block, cond, incr, body; |
| 9060 |
unsigned char save_in_statement; |
| 9061 |
tree save_objc_foreach_break_label, save_objc_foreach_continue_label; |
| 9062 |
/* The following are only used when parsing an ObjC foreach statement. */ |
| 9063 |
tree object_expression; |
| 9064 |
/* Silence the bogus uninitialized warning. */ |
| 9065 |
tree collection_expression = NULL; |
| 9066 |
location_t loc = c_parser_peek_token (parser)->location; |
| 9067 |
location_t for_loc = loc; |
| 9068 |
bool is_foreach_statement = false; |
| 9069 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); |
| 9070 |
token_indent_info for_tinfo |
| 9071 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 9072 |
tree loop_name; |
| 9073 |
int num_names = c_get_loop_names (before_labels, false, &loop_name); |
| 9074 |
|
| 9075 |
if (parser->omp_for_parse_state) |
| 9076 |
{ |
| 9077 |
error_at (for_loc, |
| 9078 |
"loop not permitted in intervening code in OpenMP loop body"); |
| 9079 |
parser->omp_for_parse_state->fail = true; |
| 9080 |
} |
| 9081 |
|
| 9082 |
c_parser_consume_token (parser); |
| 9083 |
/* Open a compound statement in Objective-C as well, just in case this is |
| 9084 |
as foreach expression. */ |
| 9085 |
block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ()); |
| 9086 |
cond = error_mark_node; |
| 9087 |
incr = error_mark_node; |
| 9088 |
matching_parens parens; |
| 9089 |
if (parens.require_open (parser)) |
| 9090 |
{ |
| 9091 |
/* Parse the initialization declaration or expression. */ |
| 9092 |
object_expression = error_mark_node; |
| 9093 |
parser->objc_could_be_foreach_context = c_dialect_objc (); |
| 9094 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 9095 |
{ |
| 9096 |
parser->objc_could_be_foreach_context = false; |
| 9097 |
c_parser_consume_token (parser); |
| 9098 |
c_finish_expr_stmt (loc, NULL_TREE); |
| 9099 |
} |
| 9100 |
else if (c_parser_next_tokens_start_declaration (parser) |
| 9101 |
|| c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 9102 |
{ |
| 9103 |
c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
| 9104 |
false, &object_expression); |
| 9105 |
parser->objc_could_be_foreach_context = false; |
| 9106 |
|
| 9107 |
if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 9108 |
{ |
| 9109 |
c_parser_consume_token (parser); |
| 9110 |
is_foreach_statement = true; |
| 9111 |
if (check_for_loop_decls (for_loc, true) == NULL_TREE) |
| 9112 |
c_parser_error (parser, "multiple iterating variables in " |
| 9113 |
"fast enumeration"); |
| 9114 |
} |
| 9115 |
else |
| 9116 |
check_for_loop_decls (for_loc, flag_isoc99); |
| 9117 |
} |
| 9118 |
else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
| 9119 |
{ |
| 9120 |
/* __extension__ can start a declaration, but is also an |
| 9121 |
unary operator that can start an expression. Consume all |
| 9122 |
but the last of a possible series of __extension__ to |
| 9123 |
determine which. */ |
| 9124 |
while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD |
| 9125 |
&& (c_parser_peek_2nd_token (parser)->keyword |
| 9126 |
== RID_EXTENSION)) |
| 9127 |
c_parser_consume_token (parser); |
| 9128 |
if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)) |
| 9129 |
|| c_parser_nth_token_starts_std_attributes (parser, 2)) |
| 9130 |
{ |
| 9131 |
int ext; |
| 9132 |
ext = disable_extension_diagnostics (); |
| 9133 |
c_parser_consume_token (parser); |
| 9134 |
c_parser_declaration_or_fndef (parser, true, true, true, true, |
| 9135 |
true, false, &object_expression); |
| 9136 |
parser->objc_could_be_foreach_context = false; |
| 9137 |
|
| 9138 |
restore_extension_diagnostics (ext); |
| 9139 |
if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 9140 |
{ |
| 9141 |
c_parser_consume_token (parser); |
| 9142 |
is_foreach_statement = true; |
| 9143 |
if (check_for_loop_decls (for_loc, true) == NULL_TREE) |
| 9144 |
c_parser_error (parser, "multiple iterating variables in " |
| 9145 |
"fast enumeration"); |
| 9146 |
} |
| 9147 |
else |
| 9148 |
check_for_loop_decls (for_loc, flag_isoc99); |
| 9149 |
} |
| 9150 |
else |
| 9151 |
goto init_expr; |
| 9152 |
} |
| 9153 |
else |
| 9154 |
{ |
| 9155 |
init_expr: |
| 9156 |
{ |
| 9157 |
struct c_expr ce; |
| 9158 |
tree init_expression; |
| 9159 |
ce = c_parser_expression (parser); |
| 9160 |
init_expression = ce.value; |
| 9161 |
parser->objc_could_be_foreach_context = false; |
| 9162 |
if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 9163 |
{ |
| 9164 |
c_parser_consume_token (parser); |
| 9165 |
is_foreach_statement = true; |
| 9166 |
if (! lvalue_p (init_expression)) |
| 9167 |
c_parser_error (parser, "invalid iterating variable in " |
| 9168 |
"fast enumeration"); |
| 9169 |
object_expression |
| 9170 |
= c_fully_fold (init_expression, false, NULL); |
| 9171 |
} |
| 9172 |
else |
| 9173 |
{ |
| 9174 |
ce = convert_lvalue_to_rvalue (loc, ce, true, false); |
| 9175 |
init_expression = ce.value; |
| 9176 |
c_finish_expr_stmt (loc, init_expression); |
| 9177 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, |
| 9178 |
"expected %<;%>"); |
| 9179 |
} |
| 9180 |
} |
| 9181 |
} |
| 9182 |
/* Parse the loop condition. In the case of a foreach |
| 9183 |
statement, there is no loop condition. */ |
| 9184 |
gcc_assert (!parser->objc_could_be_foreach_context); |
| 9185 |
if (!is_foreach_statement) |
| 9186 |
{ |
| 9187 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 9188 |
{ |
| 9189 |
if (ivdep) |
| 9190 |
{ |
| 9191 |
c_parser_error (parser, "missing loop condition in loop " |
| 9192 |
"with %<GCC ivdep%> pragma"); |
| 9193 |
cond = error_mark_node; |
| 9194 |
} |
| 9195 |
else if (unroll) |
| 9196 |
{ |
| 9197 |
c_parser_error (parser, "missing loop condition in loop " |
| 9198 |
"with %<GCC unroll%> pragma"); |
| 9199 |
cond = error_mark_node; |
| 9200 |
} |
| 9201 |
else |
| 9202 |
{ |
| 9203 |
c_parser_consume_token (parser); |
| 9204 |
cond = NULL_TREE; |
| 9205 |
} |
| 9206 |
} |
| 9207 |
else |
| 9208 |
{ |
| 9209 |
cond = c_parser_condition (parser); |
| 9210 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, |
| 9211 |
"expected %<;%>"); |
| 9212 |
} |
| 9213 |
if (ivdep && cond != error_mark_node) |
| 9214 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 9215 |
build_int_cst (integer_type_node, |
| 9216 |
annot_expr_ivdep_kind), |
| 9217 |
integer_zero_node); |
| 9218 |
if (unroll && cond != error_mark_node) |
| 9219 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 9220 |
build_int_cst (integer_type_node, |
| 9221 |
annot_expr_unroll_kind), |
| 9222 |
build_int_cst (integer_type_node, unroll)); |
| 9223 |
if (novector && cond && cond != error_mark_node) |
| 9224 |
cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 9225 |
build_int_cst (integer_type_node, |
| 9226 |
annot_expr_no_vector_kind), |
| 9227 |
integer_zero_node); |
| 9228 |
} |
| 9229 |
/* Parse the increment expression (the third expression in a |
| 9230 |
for-statement). In the case of a foreach-statement, this is |
| 9231 |
the expression that follows the 'in'. */ |
| 9232 |
loc = c_parser_peek_token (parser)->location; |
| 9233 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 9234 |
{ |
| 9235 |
if (is_foreach_statement) |
| 9236 |
{ |
| 9237 |
c_parser_error (parser, |
| 9238 |
"missing collection in fast enumeration"); |
| 9239 |
collection_expression = error_mark_node; |
| 9240 |
} |
| 9241 |
else |
| 9242 |
incr = c_process_expr_stmt (loc, NULL_TREE); |
| 9243 |
} |
| 9244 |
else |
| 9245 |
{ |
| 9246 |
if (is_foreach_statement) |
| 9247 |
collection_expression |
| 9248 |
= c_fully_fold (c_parser_expression (parser).value, false, NULL); |
| 9249 |
else |
| 9250 |
{ |
| 9251 |
struct c_expr ce = c_parser_expression (parser); |
| 9252 |
ce = convert_lvalue_to_rvalue (loc, ce, true, false); |
| 9253 |
incr = c_process_expr_stmt (loc, ce.value); |
| 9254 |
} |
| 9255 |
} |
| 9256 |
parens.skip_until_found_close (parser); |
| 9257 |
} |
| 9258 |
save_in_statement = in_statement; |
| 9259 |
if (is_foreach_statement) |
| 9260 |
{ |
| 9261 |
in_statement = IN_OBJC_FOREACH; |
| 9262 |
save_objc_foreach_break_label = objc_foreach_break_label; |
| 9263 |
save_objc_foreach_continue_label = objc_foreach_continue_label; |
| 9264 |
objc_foreach_break_label = create_artificial_label (loc); |
| 9265 |
objc_foreach_continue_label = create_artificial_label (loc); |
| 9266 |
if (loop_name) |
| 9267 |
{ |
| 9268 |
gcc_checking_assert (!DECL_CHAIN (loop_name) |
| 9269 |
&& !DECL_CHAIN (objc_foreach_break_label)); |
| 9270 |
C_DECL_SWITCH_NAME (loop_name) = 1; |
| 9271 |
DECL_CHAIN (loop_name) = objc_foreach_break_label; |
| 9272 |
DECL_CHAIN (objc_foreach_break_label) = objc_foreach_continue_label; |
| 9273 |
} |
| 9274 |
} |
| 9275 |
else |
| 9276 |
in_statement = IN_ITERATION_STMT; |
| 9277 |
if (loop_name) |
| 9278 |
{ |
| 9279 |
C_DECL_LOOP_SWITCH_NAME_VALID (loop_name) = 1; |
| 9280 |
in_statement |= IN_NAMED_STMT; |
| 9281 |
} |
| 9282 |
|
| 9283 |
token_indent_info body_tinfo |
| 9284 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 9285 |
|
| 9286 |
location_t loc_after_labels; |
| 9287 |
bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE); |
| 9288 |
body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels); |
| 9289 |
|
| 9290 |
if (loop_name && is_foreach_statement) |
| 9291 |
{ |
| 9292 |
gcc_checking_assert (DECL_CHAIN (loop_name) == objc_foreach_break_label |
| 9293 |
&& (DECL_CHAIN (objc_foreach_break_label) |
| 9294 |
== objc_foreach_continue_label)); |
| 9295 |
C_DECL_SWITCH_NAME (loop_name) = 0; |
| 9296 |
DECL_CHAIN (loop_name) = NULL_TREE; |
| 9297 |
DECL_CHAIN (objc_foreach_break_label) = NULL_TREE; |
| 9298 |
} |
| 9299 |
|
| 9300 |
if (is_foreach_statement) |
| 9301 |
objc_finish_foreach_loop (for_loc, object_expression, |
| 9302 |
collection_expression, body, |
| 9303 |
objc_foreach_break_label, |
| 9304 |
objc_foreach_continue_label); |
| 9305 |
else |
| 9306 |
add_stmt (build_stmt (for_loc, FOR_STMT, NULL_TREE, cond, incr, |
| 9307 |
body, NULL_TREE, |
| 9308 |
loop_name && C_DECL_LOOP_SWITCH_NAME_USED (loop_name) |
| 9309 |
? loop_name : NULL_TREE, NULL_TREE, NULL_TREE)); |
| 9310 |
add_stmt (c_end_compound_stmt (for_loc, block, |
| 9311 |
flag_isoc99 || c_dialect_objc ())); |
| 9312 |
c_parser_maybe_reclassify_token (parser); |
| 9313 |
|
| 9314 |
token_indent_info next_tinfo |
| 9315 |
= get_token_indent_info (c_parser_peek_token (parser)); |
| 9316 |
warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo); |
| 9317 |
|
| 9318 |
if (next_tinfo.type != CPP_SEMICOLON && !open_brace) |
| 9319 |
warn_for_multistatement_macros (loc_after_labels, next_tinfo.location, |
| 9320 |
for_tinfo.location, RID_FOR); |
| 9321 |
|
| 9322 |
in_statement = save_in_statement; |
| 9323 |
if (num_names) |
| 9324 |
c_release_loop_names (num_names); |
| 9325 |
if (is_foreach_statement) |
| 9326 |
{ |
| 9327 |
objc_foreach_break_label = save_objc_foreach_break_label; |
| 9328 |
objc_foreach_continue_label = save_objc_foreach_continue_label; |
| 9329 |
} |
| 9330 |
} |
| 9331 |
|
| 9332 |
/* Parse an asm statement, a GNU extension. This is a full-blown asm |
| 9333 |
statement with inputs, outputs, clobbers, and volatile, inline, and goto |
| 9334 |
tags allowed. |
| 9335 |
|
| 9336 |
asm-qualifier: |
| 9337 |
volatile |
| 9338 |
inline |
| 9339 |
goto |
| 9340 |
|
| 9341 |
asm-qualifier-list: |
| 9342 |
asm-qualifier-list asm-qualifier |
| 9343 |
asm-qualifier |
| 9344 |
|
| 9345 |
asm-statement: |
| 9346 |
asm asm-qualifier-list[opt] ( asm-argument ) ; |
| 9347 |
|
| 9348 |
asm-argument: |
| 9349 |
asm-string-literal |
| 9350 |
asm-string-literal : asm-operands[opt] |
| 9351 |
asm-string-literal : asm-operands[opt] : asm-operands[opt] |
| 9352 |
asm-string-literal : asm-operands[opt] : asm-operands[opt] \ |
| 9353 |
: asm-clobbers[opt] |
| 9354 |
asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ |
| 9355 |
: asm-goto-operands |
| 9356 |
|
| 9357 |
The form with asm-goto-operands is valid if and only if the |
| 9358 |
asm-qualifier-list contains goto, and is the only allowed form in that case. |
| 9359 |
Duplicate asm-qualifiers are not allowed. |
| 9360 |
|
| 9361 |
The :: token is considered equivalent to two consecutive : tokens. */ |
| 9362 |
|
| 9363 |
static tree |
| 9364 |
c_parser_asm_statement (c_parser *parser) |
| 9365 |
{ |
| 9366 |
tree str, outputs, inputs, clobbers, labels, ret; |
| 9367 |
bool simple; |
| 9368 |
location_t asm_loc = c_parser_peek_token (parser)->location; |
| 9369 |
int section, nsections; |
| 9370 |
|
| 9371 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
| 9372 |
c_parser_consume_token (parser); |
| 9373 |
|
| 9374 |
/* Handle the asm-qualifier-list. */ |
| 9375 |
location_t volatile_loc = UNKNOWN_LOCATION; |
| 9376 |
location_t inline_loc = UNKNOWN_LOCATION; |
| 9377 |
location_t goto_loc = UNKNOWN_LOCATION; |
| 9378 |
for (;;) |
| 9379 |
{ |
| 9380 |
c_token *token = c_parser_peek_token (parser); |
| 9381 |
location_t loc = token->location; |
| 9382 |
switch (token->keyword) |
| 9383 |
{ |
| 9384 |
case RID_VOLATILE: |
| 9385 |
if (volatile_loc) |
| 9386 |
{ |
| 9387 |
error_at (loc, "duplicate %<asm%> qualifier %qE", token->value); |
| 9388 |
inform (volatile_loc, "first seen here"); |
| 9389 |
} |
| 9390 |
else |
| 9391 |
volatile_loc = loc; |
| 9392 |
c_parser_consume_token (parser); |
| 9393 |
continue; |
| 9394 |
|
| 9395 |
case RID_INLINE: |
| 9396 |
if (inline_loc) |
| 9397 |
{ |
| 9398 |
error_at (loc, "duplicate %<asm%> qualifier %qE", token->value); |
| 9399 |
inform (inline_loc, "first seen here"); |
| 9400 |
} |
| 9401 |
else |
| 9402 |
inline_loc = loc; |
| 9403 |
c_parser_consume_token (parser); |
| 9404 |
continue; |
| 9405 |
|
| 9406 |
case RID_GOTO: |
| 9407 |
if (goto_loc) |
| 9408 |
{ |
| 9409 |
error_at (loc, "duplicate %<asm%> qualifier %qE", token->value); |
| 9410 |
inform (goto_loc, "first seen here"); |
| 9411 |
} |
| 9412 |
else |
| 9413 |
goto_loc = loc; |
| 9414 |
c_parser_consume_token (parser); |
| 9415 |
continue; |
| 9416 |
|
| 9417 |
case RID_CONST: |
| 9418 |
case RID_RESTRICT: |
| 9419 |
error_at (loc, "%qE is not a valid %<asm%> qualifier", token->value); |
| 9420 |
c_parser_consume_token (parser); |
| 9421 |
continue; |
| 9422 |
|
| 9423 |
default: |
| 9424 |
break; |
| 9425 |
} |
| 9426 |
break; |
| 9427 |
} |
| 9428 |
|
| 9429 |
bool is_volatile = (volatile_loc != UNKNOWN_LOCATION); |
| 9430 |
bool is_inline = (inline_loc != UNKNOWN_LOCATION); |
| 9431 |
bool is_goto = (goto_loc != UNKNOWN_LOCATION); |
| 9432 |
|
| 9433 |
ret = NULL; |
| 9434 |
|
| 9435 |
matching_parens parens; |
| 9436 |
if (!parens.require_open (parser)) |
| 9437 |
goto error; |
| 9438 |
|
| 9439 |
str = c_parser_asm_string_literal (parser); |
| 9440 |
if (str == NULL_TREE) |
| 9441 |
goto error_close_paren; |
| 9442 |
|
| 9443 |
simple = true; |
| 9444 |
outputs = NULL_TREE; |
| 9445 |
inputs = NULL_TREE; |
| 9446 |
clobbers = NULL_TREE; |
| 9447 |
labels = NULL_TREE; |
| 9448 |
|
| 9449 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) |
| 9450 |
goto done_asm; |
| 9451 |
|
| 9452 |
/* Parse each colon-delimited section of operands. */ |
| 9453 |
nsections = 3 + is_goto; |
| 9454 |
for (section = 0; section < nsections; ++section) |
| 9455 |
{ |
| 9456 |
if (c_parser_next_token_is (parser, CPP_SCOPE)) |
| 9457 |
{ |
| 9458 |
++section; |
| 9459 |
if (section == nsections) |
| 9460 |
{ |
| 9461 |
c_parser_error (parser, "expected %<)%>"); |
| 9462 |
goto error_close_paren; |
| 9463 |
} |
| 9464 |
c_parser_consume_token (parser); |
| 9465 |
} |
| 9466 |
else if (!c_parser_require (parser, CPP_COLON, |
| 9467 |
is_goto |
| 9468 |
? G_("expected %<:%>") |
| 9469 |
: G_("expected %<:%> or %<)%>"), |
| 9470 |
UNKNOWN_LOCATION, is_goto)) |
| 9471 |
goto error_close_paren; |
| 9472 |
|
| 9473 |
/* Once past any colon, we're no longer a simple asm. */ |
| 9474 |
simple = false; |
| 9475 |
|
| 9476 |
if ((!c_parser_next_token_is (parser, CPP_COLON) |
| 9477 |
&& !c_parser_next_token_is (parser, CPP_SCOPE) |
| 9478 |
&& !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 9479 |
|| section == 3) |
| 9480 |
switch (section) |
| 9481 |
{ |
| 9482 |
case 0: |
| 9483 |
outputs = c_parser_asm_operands (parser); |
| 9484 |
break; |
| 9485 |
case 1: |
| 9486 |
inputs = c_parser_asm_operands (parser); |
| 9487 |
break; |
| 9488 |
case 2: |
| 9489 |
clobbers = c_parser_asm_clobbers (parser); |
| 9490 |
break; |
| 9491 |
case 3: |
| 9492 |
labels = c_parser_asm_goto_operands (parser); |
| 9493 |
break; |
| 9494 |
default: |
| 9495 |
gcc_unreachable (); |
| 9496 |
} |
| 9497 |
|
| 9498 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) |
| 9499 |
goto done_asm; |
| 9500 |
} |
| 9501 |
|
| 9502 |
done_asm: |
| 9503 |
if (!parens.require_close (parser)) |
| 9504 |
{ |
| 9505 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 9506 |
goto error; |
| 9507 |
} |
| 9508 |
|
| 9509 |
if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 9510 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 9511 |
|
| 9512 |
ret = build_asm_stmt (is_volatile, |
| 9513 |
build_asm_expr (asm_loc, str, outputs, inputs, |
| 9514 |
clobbers, labels, simple, is_inline)); |
| 9515 |
|
| 9516 |
error: |
| 9517 |
return ret; |
| 9518 |
|
| 9519 |
error_close_paren: |
| 9520 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 9521 |
goto error; |
| 9522 |
} |
| 9523 |
|
| 9524 |
/* Parse asm operands, a GNU extension. |
| 9525 |
|
| 9526 |
asm-operands: |
| 9527 |
asm-operand |
| 9528 |
asm-operands , asm-operand |
| 9529 |
|
| 9530 |
asm-operand: |
| 9531 |
asm-string-literal ( expression ) |
| 9532 |
[ identifier ] asm-string-literal ( expression ) |
| 9533 |
*/ |
| 9534 |
|
| 9535 |
static tree |
| 9536 |
c_parser_asm_operands (c_parser *parser) |
| 9537 |
{ |
| 9538 |
tree list = NULL_TREE; |
| 9539 |
while (true) |
| 9540 |
{ |
| 9541 |
tree name, str; |
| 9542 |
struct c_expr expr; |
| 9543 |
if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 9544 |
{ |
| 9545 |
c_parser_consume_token (parser); |
| 9546 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 9547 |
{ |
| 9548 |
tree id = c_parser_peek_token (parser)->value; |
| 9549 |
c_parser_consume_token (parser); |
| 9550 |
name = build_string (IDENTIFIER_LENGTH (id), |
| 9551 |
IDENTIFIER_POINTER (id)); |
| 9552 |
} |
| 9553 |
else |
| 9554 |
{ |
| 9555 |
c_parser_error (parser, "expected identifier"); |
| 9556 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 9557 |
return NULL_TREE; |
| 9558 |
} |
| 9559 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 9560 |
"expected %<]%>"); |
| 9561 |
} |
| 9562 |
else |
| 9563 |
name = NULL_TREE; |
| 9564 |
str = c_parser_asm_string_literal (parser); |
| 9565 |
if (str == NULL_TREE) |
| 9566 |
return NULL_TREE; |
| 9567 |
matching_parens parens; |
| 9568 |
if (!parens.require_open (parser)) |
| 9569 |
return NULL_TREE; |
| 9570 |
expr = c_parser_expression (parser); |
| 9571 |
mark_exp_read (expr.value); |
| 9572 |
if (!parens.require_close (parser)) |
| 9573 |
{ |
| 9574 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 9575 |
return NULL_TREE; |
| 9576 |
} |
| 9577 |
list = chainon (list, build_tree_list (build_tree_list (name, str), |
| 9578 |
expr.value)); |
| 9579 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 9580 |
c_parser_consume_token (parser); |
| 9581 |
else |
| 9582 |
break; |
| 9583 |
} |
| 9584 |
return list; |
| 9585 |
} |
| 9586 |
|
| 9587 |
/* Parse asm clobbers, a GNU extension. |
| 9588 |
|
| 9589 |
asm-clobbers: |
| 9590 |
asm-string-literal |
| 9591 |
asm-clobbers , asm-string-literal |
| 9592 |
*/ |
| 9593 |
|
| 9594 |
static tree |
| 9595 |
c_parser_asm_clobbers (c_parser *parser) |
| 9596 |
{ |
| 9597 |
tree list = NULL_TREE; |
| 9598 |
while (true) |
| 9599 |
{ |
| 9600 |
tree str = c_parser_asm_string_literal (parser); |
| 9601 |
if (str) |
| 9602 |
list = tree_cons (NULL_TREE, str, list); |
| 9603 |
else |
| 9604 |
return NULL_TREE; |
| 9605 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 9606 |
c_parser_consume_token (parser); |
| 9607 |
else |
| 9608 |
break; |
| 9609 |
} |
| 9610 |
return list; |
| 9611 |
} |
| 9612 |
|
| 9613 |
/* Parse asm goto labels, a GNU extension. |
| 9614 |
|
| 9615 |
asm-goto-operands: |
| 9616 |
identifier |
| 9617 |
asm-goto-operands , identifier |
| 9618 |
*/ |
| 9619 |
|
| 9620 |
static tree |
| 9621 |
c_parser_asm_goto_operands (c_parser *parser) |
| 9622 |
{ |
| 9623 |
tree list = NULL_TREE; |
| 9624 |
while (true) |
| 9625 |
{ |
| 9626 |
tree name, label; |
| 9627 |
|
| 9628 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 9629 |
{ |
| 9630 |
c_token *tok = c_parser_peek_token (parser); |
| 9631 |
name = tok->value; |
| 9632 |
label = lookup_label_for_goto (tok->location, name); |
| 9633 |
c_parser_consume_token (parser); |
| 9634 |
TREE_USED (label) = 1; |
| 9635 |
} |
| 9636 |
else |
| 9637 |
{ |
| 9638 |
c_parser_error (parser, "expected identifier"); |
| 9639 |
return NULL_TREE; |
| 9640 |
} |
| 9641 |
|
| 9642 |
name = build_string (IDENTIFIER_LENGTH (name), |
| 9643 |
IDENTIFIER_POINTER (name)); |
| 9644 |
list = tree_cons (name, label, list); |
| 9645 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 9646 |
c_parser_consume_token (parser); |
| 9647 |
else |
| 9648 |
return nreverse (list); |
| 9649 |
} |
| 9650 |
} |
| 9651 |
|
| 9652 |
/* Parse a possibly concatenated sequence of string literals. |
| 9653 |
TRANSLATE says whether to translate them to the execution character |
| 9654 |
set; WIDE_OK says whether any kind of prefixed string literal is |
| 9655 |
permitted in this context. This code is based on that in |
| 9656 |
lex_string. */ |
| 9657 |
|
| 9658 |
struct c_expr |
| 9659 |
c_parser_string_literal (c_parser *parser, bool translate, bool wide_ok) |
| 9660 |
{ |
| 9661 |
struct c_expr ret; |
| 9662 |
size_t count; |
| 9663 |
struct obstack str_ob; |
| 9664 |
struct obstack loc_ob; |
| 9665 |
cpp_string str, istr, *strs; |
| 9666 |
c_token *tok; |
| 9667 |
location_t loc, last_tok_loc; |
| 9668 |
enum cpp_ttype type; |
| 9669 |
tree value, string_tree; |
| 9670 |
|
| 9671 |
tok = c_parser_peek_token (parser); |
| 9672 |
loc = tok->location; |
| 9673 |
last_tok_loc = linemap_resolve_location (line_table, loc, |
| 9674 |
LRK_MACRO_DEFINITION_LOCATION, |
| 9675 |
NULL); |
| 9676 |
type = tok->type; |
| 9677 |
switch (type) |
| 9678 |
{ |
| 9679 |
case CPP_STRING: |
| 9680 |
case CPP_WSTRING: |
| 9681 |
case CPP_STRING16: |
| 9682 |
case CPP_STRING32: |
| 9683 |
case CPP_UTF8STRING: |
| 9684 |
string_tree = tok->value; |
| 9685 |
break; |
| 9686 |
|
| 9687 |
default: |
| 9688 |
c_parser_error (parser, "expected string literal"); |
| 9689 |
ret.set_error (); |
| 9690 |
ret.value = NULL_TREE; |
| 9691 |
ret.original_code = ERROR_MARK; |
| 9692 |
ret.original_type = NULL_TREE; |
| 9693 |
return ret; |
| 9694 |
} |
| 9695 |
|
| 9696 |
/* Try to avoid the overhead of creating and destroying an obstack |
| 9697 |
for the common case of just one string. */ |
| 9698 |
switch (c_parser_peek_2nd_token (parser)->type) |
| 9699 |
{ |
| 9700 |
default: |
| 9701 |
c_parser_consume_token (parser); |
| 9702 |
str.text = (const unsigned char *) TREE_STRING_POINTER (string_tree); |
| 9703 |
str.len = TREE_STRING_LENGTH (string_tree); |
| 9704 |
count = 1; |
| 9705 |
strs = &str; |
| 9706 |
break; |
| 9707 |
|
| 9708 |
case CPP_STRING: |
| 9709 |
case CPP_WSTRING: |
| 9710 |
case CPP_STRING16: |
| 9711 |
case CPP_STRING32: |
| 9712 |
case CPP_UTF8STRING: |
| 9713 |
gcc_obstack_init (&str_ob); |
| 9714 |
gcc_obstack_init (&loc_ob); |
| 9715 |
count = 0; |
| 9716 |
do |
| 9717 |
{ |
| 9718 |
c_parser_consume_token (parser); |
| 9719 |
count++; |
| 9720 |
str.text = (const unsigned char *) TREE_STRING_POINTER (string_tree); |
| 9721 |
str.len = TREE_STRING_LENGTH (string_tree); |
| 9722 |
if (type != tok->type) |
| 9723 |
{ |
| 9724 |
if (type == CPP_STRING) |
| 9725 |
type = tok->type; |
| 9726 |
else if (tok->type != CPP_STRING) |
| 9727 |
error ("unsupported non-standard concatenation " |
| 9728 |
"of string literals"); |
| 9729 |
} |
| 9730 |
obstack_grow (&str_ob, &str, sizeof (cpp_string)); |
| 9731 |
obstack_grow (&loc_ob, &last_tok_loc, sizeof (location_t)); |
| 9732 |
tok = c_parser_peek_token (parser); |
| 9733 |
string_tree = tok->value; |
| 9734 |
last_tok_loc |
| 9735 |
= linemap_resolve_location (line_table, tok->location, |
| 9736 |
LRK_MACRO_DEFINITION_LOCATION, NULL); |
| 9737 |
} |
| 9738 |
while (tok->type == CPP_STRING |
| 9739 |
|| tok->type == CPP_WSTRING |
| 9740 |
|| tok->type == CPP_STRING16 |
| 9741 |
|| tok->type == CPP_STRING32 |
| 9742 |
|| tok->type == CPP_UTF8STRING); |
| 9743 |
strs = (cpp_string *) obstack_finish (&str_ob); |
| 9744 |
} |
| 9745 |
|
| 9746 |
if (count > 1 && !in_system_header_at (input_location)) |
| 9747 |
warning (OPT_Wtraditional, |
| 9748 |
"traditional C rejects string constant concatenation"); |
| 9749 |
|
| 9750 |
if ((type == CPP_STRING || wide_ok) |
| 9751 |
&& ((translate |
| 9752 |
? cpp_interpret_string : cpp_interpret_string_notranslate) |
| 9753 |
(parse_in, strs, count, &istr, type))) |
| 9754 |
{ |
| 9755 |
value = build_string (istr.len, (const char *) istr.text); |
| 9756 |
free (CONST_CAST (unsigned char *, istr.text)); |
| 9757 |
if (count > 1) |
| 9758 |
{ |
| 9759 |
location_t *locs = (location_t *) obstack_finish (&loc_ob); |
| 9760 |
gcc_assert (g_string_concat_db); |
| 9761 |
g_string_concat_db->record_string_concatenation (count, locs); |
| 9762 |
} |
| 9763 |
} |
| 9764 |
else |
| 9765 |
{ |
| 9766 |
if (type != CPP_STRING && !wide_ok) |
| 9767 |
{ |
| 9768 |
error_at (loc, "a wide string is invalid in this context"); |
| 9769 |
type = CPP_STRING; |
| 9770 |
} |
| 9771 |
/* Callers cannot generally handle error_mark_node in this |
| 9772 |
context, so return the empty string instead. An error has |
| 9773 |
been issued, either above or from cpp_interpret_string. */ |
| 9774 |
switch (type) |
| 9775 |
{ |
| 9776 |
default: |
| 9777 |
case CPP_STRING: |
| 9778 |
case CPP_UTF8STRING: |
| 9779 |
if (type == CPP_UTF8STRING && flag_char8_t) |
| 9780 |
{ |
| 9781 |
value = build_string (TYPE_PRECISION (char8_type_node) |
| 9782 |
/ TYPE_PRECISION (char_type_node), |
| 9783 |
""); /* char8_t is 8 bits */ |
| 9784 |
} |
| 9785 |
else |
| 9786 |
value = build_string (1, ""); |
| 9787 |
break; |
| 9788 |
case CPP_STRING16: |
| 9789 |
value = build_string (TYPE_PRECISION (char16_type_node) |
| 9790 |
/ TYPE_PRECISION (char_type_node), |
| 9791 |
"\0"); /* char16_t is 16 bits */ |
| 9792 |
break; |
| 9793 |
case CPP_STRING32: |
| 9794 |
value = build_string (TYPE_PRECISION (char32_type_node) |
| 9795 |
/ TYPE_PRECISION (char_type_node), |
| 9796 |
"\0\0\0"); /* char32_t is 32 bits */ |
| 9797 |
break; |
| 9798 |
case CPP_WSTRING: |
| 9799 |
value = build_string (TYPE_PRECISION (wchar_type_node) |
| 9800 |
/ TYPE_PRECISION (char_type_node), |
| 9801 |
"\0\0\0"); /* widest supported wchar_t |
| 9802 |
is 32 bits */ |
| 9803 |
break; |
| 9804 |
} |
| 9805 |
} |
| 9806 |
|
| 9807 |
switch (type) |
| 9808 |
{ |
| 9809 |
default: |
| 9810 |
case CPP_STRING: |
| 9811 |
TREE_TYPE (value) = char_array_type_node; |
| 9812 |
break; |
| 9813 |
case CPP_UTF8STRING: |
| 9814 |
if (flag_char8_t) |
| 9815 |
TREE_TYPE (value) = char8_array_type_node; |
| 9816 |
else |
| 9817 |
TREE_TYPE (value) = char_array_type_node; |
| 9818 |
break; |
| 9819 |
case CPP_STRING16: |
| 9820 |
TREE_TYPE (value) = char16_array_type_node; |
| 9821 |
break; |
| 9822 |
case CPP_STRING32: |
| 9823 |
TREE_TYPE (value) = char32_array_type_node; |
| 9824 |
break; |
| 9825 |
case CPP_WSTRING: |
| 9826 |
TREE_TYPE (value) = wchar_array_type_node; |
| 9827 |
} |
| 9828 |
value = fix_string_type (value); |
| 9829 |
|
| 9830 |
if (count > 1) |
| 9831 |
{ |
| 9832 |
obstack_free (&str_ob, 0); |
| 9833 |
obstack_free (&loc_ob, 0); |
| 9834 |
} |
| 9835 |
|
| 9836 |
ret.value = value; |
| 9837 |
ret.original_code = STRING_CST; |
| 9838 |
ret.original_type = NULL_TREE; |
| 9839 |
set_c_expr_source_range (&ret, get_range_from_loc (line_table, loc)); |
| 9840 |
ret.m_decimal = 0; |
| 9841 |
parser->seen_string_literal = true; |
| 9842 |
return ret; |
| 9843 |
} |
| 9844 |
|
| 9845 |
/* Parse an expression other than a compound expression; that is, an |
| 9846 |
assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If |
| 9847 |
AFTER is not NULL then it is an Objective-C message expression which |
| 9848 |
is the primary-expression starting the expression as an initializer. |
| 9849 |
|
| 9850 |
assignment-expression: |
| 9851 |
conditional-expression |
| 9852 |
unary-expression assignment-operator assignment-expression |
| 9853 |
|
| 9854 |
assignment-operator: one of |
| 9855 |
= *= /= %= += -= <<= >>= &= ^= |= |
| 9856 |
|
| 9857 |
In GNU C we accept any conditional expression on the LHS and |
| 9858 |
diagnose the invalid lvalue rather than producing a syntax |
| 9859 |
error. */ |
| 9860 |
|
| 9861 |
static struct c_expr |
| 9862 |
c_parser_expr_no_commas (c_parser *parser, struct c_expr *after, |
| 9863 |
tree omp_atomic_lhs) |
| 9864 |
{ |
| 9865 |
struct c_expr lhs, rhs, ret; |
| 9866 |
enum tree_code code; |
| 9867 |
location_t op_location, exp_location; |
| 9868 |
bool save_in_omp_for = c_in_omp_for; |
| 9869 |
c_in_omp_for = false; |
| 9870 |
gcc_assert (!after || c_dialect_objc ()); |
| 9871 |
lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs); |
| 9872 |
op_location = c_parser_peek_token (parser)->location; |
| 9873 |
switch (c_parser_peek_token (parser)->type) |
| 9874 |
{ |
| 9875 |
case CPP_EQ: |
| 9876 |
code = NOP_EXPR; |
| 9877 |
break; |
| 9878 |
case CPP_MULT_EQ: |
| 9879 |
code = MULT_EXPR; |
| 9880 |
break; |
| 9881 |
case CPP_DIV_EQ: |
| 9882 |
code = TRUNC_DIV_EXPR; |
| 9883 |
break; |
| 9884 |
case CPP_MOD_EQ: |
| 9885 |
code = TRUNC_MOD_EXPR; |
| 9886 |
break; |
| 9887 |
case CPP_PLUS_EQ: |
| 9888 |
code = PLUS_EXPR; |
| 9889 |
break; |
| 9890 |
case CPP_MINUS_EQ: |
| 9891 |
code = MINUS_EXPR; |
| 9892 |
break; |
| 9893 |
case CPP_LSHIFT_EQ: |
| 9894 |
code = LSHIFT_EXPR; |
| 9895 |
break; |
| 9896 |
case CPP_RSHIFT_EQ: |
| 9897 |
code = RSHIFT_EXPR; |
| 9898 |
break; |
| 9899 |
case CPP_AND_EQ: |
| 9900 |
code = BIT_AND_EXPR; |
| 9901 |
break; |
| 9902 |
case CPP_XOR_EQ: |
| 9903 |
code = BIT_XOR_EXPR; |
| 9904 |
break; |
| 9905 |
case CPP_OR_EQ: |
| 9906 |
code = BIT_IOR_EXPR; |
| 9907 |
break; |
| 9908 |
default: |
| 9909 |
c_in_omp_for = save_in_omp_for; |
| 9910 |
return lhs; |
| 9911 |
} |
| 9912 |
c_parser_consume_token (parser); |
| 9913 |
exp_location = c_parser_peek_token (parser)->location; |
| 9914 |
rhs = c_parser_expr_no_commas (parser, NULL); |
| 9915 |
rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true); |
| 9916 |
|
| 9917 |
ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, |
| 9918 |
code, exp_location, rhs.value, |
| 9919 |
rhs.original_type); |
| 9920 |
ret.m_decimal = 0; |
| 9921 |
set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ()); |
| 9922 |
if (code == NOP_EXPR) |
| 9923 |
ret.original_code = MODIFY_EXPR; |
| 9924 |
else |
| 9925 |
{ |
| 9926 |
suppress_warning (ret.value, OPT_Wparentheses); |
| 9927 |
ret.original_code = ERROR_MARK; |
| 9928 |
} |
| 9929 |
ret.original_type = NULL; |
| 9930 |
c_in_omp_for = save_in_omp_for; |
| 9931 |
return ret; |
| 9932 |
} |
| 9933 |
|
| 9934 |
/* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If |
| 9935 |
AFTER is not NULL then it is an Objective-C message expression which is |
| 9936 |
the primary-expression starting the expression as an initializer. |
| 9937 |
|
| 9938 |
conditional-expression: |
| 9939 |
logical-OR-expression |
| 9940 |
logical-OR-expression ? expression : conditional-expression |
| 9941 |
|
| 9942 |
GNU extensions: |
| 9943 |
|
| 9944 |
conditional-expression: |
| 9945 |
logical-OR-expression ? : conditional-expression |
| 9946 |
*/ |
| 9947 |
|
| 9948 |
static struct c_expr |
| 9949 |
c_parser_conditional_expression (c_parser *parser, struct c_expr *after, |
| 9950 |
tree omp_atomic_lhs) |
| 9951 |
{ |
| 9952 |
struct c_expr cond, exp1, exp2, ret; |
| 9953 |
location_t start, cond_loc, colon_loc; |
| 9954 |
bool save_c_omp_array_section_p = c_omp_array_section_p; |
| 9955 |
|
| 9956 |
gcc_assert (!after || c_dialect_objc ()); |
| 9957 |
|
| 9958 |
cond = c_parser_binary_expression (parser, after, omp_atomic_lhs); |
| 9959 |
|
| 9960 |
if (c_parser_next_token_is_not (parser, CPP_QUERY)) |
| 9961 |
return cond; |
| 9962 |
c_omp_array_section_p = false; |
| 9963 |
if (cond.value != error_mark_node) |
| 9964 |
start = cond.get_start (); |
| 9965 |
else |
| 9966 |
start = UNKNOWN_LOCATION; |
| 9967 |
cond_loc = c_parser_peek_token (parser)->location; |
| 9968 |
cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true); |
| 9969 |
c_parser_consume_token (parser); |
| 9970 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 9971 |
{ |
| 9972 |
tree eptype = NULL_TREE; |
| 9973 |
|
| 9974 |
location_t middle_loc = c_parser_peek_token (parser)->location; |
| 9975 |
pedwarn (middle_loc, OPT_Wpedantic, |
| 9976 |
"ISO C forbids omitting the middle term of a %<?:%> expression"); |
| 9977 |
if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) |
| 9978 |
{ |
| 9979 |
eptype = TREE_TYPE (cond.value); |
| 9980 |
cond.value = TREE_OPERAND (cond.value, 0); |
| 9981 |
} |
| 9982 |
tree e = cond.value; |
| 9983 |
while (TREE_CODE (e) == COMPOUND_EXPR) |
| 9984 |
e = TREE_OPERAND (e, 1); |
| 9985 |
warn_for_omitted_condop (middle_loc, e); |
| 9986 |
/* Make sure first operand is calculated only once. */ |
| 9987 |
exp1.value = save_expr (default_conversion (cond.value)); |
| 9988 |
if (eptype) |
| 9989 |
exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); |
| 9990 |
exp1.original_type = NULL; |
| 9991 |
exp1.src_range = cond.src_range; |
| 9992 |
cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); |
| 9993 |
c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; |
| 9994 |
} |
| 9995 |
else |
| 9996 |
{ |
| 9997 |
cond.value |
| 9998 |
= c_objc_common_truthvalue_conversion |
| 9999 |
(cond_loc, default_conversion (cond.value)); |
| 10000 |
c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; |
| 10001 |
exp1 = c_parser_expression_conv (parser); |
| 10002 |
mark_exp_read (exp1.value); |
| 10003 |
c_inhibit_evaluation_warnings += |
| 10004 |
((cond.value == truthvalue_true_node) |
| 10005 |
- (cond.value == truthvalue_false_node)); |
| 10006 |
} |
| 10007 |
|
| 10008 |
colon_loc = c_parser_peek_token (parser)->location; |
| 10009 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 10010 |
{ |
| 10011 |
c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
| 10012 |
ret.set_error (); |
| 10013 |
ret.original_code = ERROR_MARK; |
| 10014 |
ret.original_type = NULL; |
| 10015 |
c_omp_array_section_p = save_c_omp_array_section_p; |
| 10016 |
return ret; |
| 10017 |
} |
| 10018 |
{ |
| 10019 |
location_t exp2_loc = c_parser_peek_token (parser)->location; |
| 10020 |
exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE); |
| 10021 |
exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true); |
| 10022 |
} |
| 10023 |
c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
| 10024 |
location_t loc1 = make_location (exp1.get_start (), exp1.src_range); |
| 10025 |
location_t loc2 = make_location (exp2.get_start (), exp2.src_range); |
| 10026 |
if (UNLIKELY (omp_atomic_lhs != NULL) |
| 10027 |
&& (TREE_CODE (cond.value) == GT_EXPR |
| 10028 |
|| TREE_CODE (cond.value) == LT_EXPR |
| 10029 |
|| TREE_CODE (cond.value) == EQ_EXPR) |
| 10030 |
&& c_tree_equal (exp2.value, omp_atomic_lhs) |
| 10031 |
&& (c_tree_equal (TREE_OPERAND (cond.value, 0), omp_atomic_lhs) |
| 10032 |
|| c_tree_equal (TREE_OPERAND (cond.value, 1), omp_atomic_lhs))) |
| 10033 |
ret.value = build3_loc (colon_loc, COND_EXPR, TREE_TYPE (omp_atomic_lhs), |
| 10034 |
cond.value, exp1.value, exp2.value); |
| 10035 |
else |
| 10036 |
ret.value |
| 10037 |
= build_conditional_expr (colon_loc, cond.value, |
| 10038 |
cond.original_code == C_MAYBE_CONST_EXPR, |
| 10039 |
exp1.value, exp1.original_type, loc1, |
| 10040 |
exp2.value, exp2.original_type, loc2); |
| 10041 |
ret.original_code = ERROR_MARK; |
| 10042 |
if (exp1.value == error_mark_node || exp2.value == error_mark_node) |
| 10043 |
ret.original_type = NULL; |
| 10044 |
else |
| 10045 |
{ |
| 10046 |
tree t1, t2; |
| 10047 |
|
| 10048 |
/* If both sides are enum type, the default conversion will have |
| 10049 |
made the type of the result be an integer type. We want to |
| 10050 |
remember the enum types we started with. */ |
| 10051 |
t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); |
| 10052 |
t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); |
| 10053 |
ret.original_type = ((t1 != error_mark_node |
| 10054 |
&& t2 != error_mark_node |
| 10055 |
&& (TYPE_MAIN_VARIANT (t1) |
| 10056 |
== TYPE_MAIN_VARIANT (t2))) |
| 10057 |
? t1 |
| 10058 |
: NULL); |
| 10059 |
} |
| 10060 |
set_c_expr_source_range (&ret, start, exp2.get_finish ()); |
| 10061 |
ret.m_decimal = 0; |
| 10062 |
c_omp_array_section_p = save_c_omp_array_section_p; |
| 10063 |
return ret; |
| 10064 |
} |
| 10065 |
|
| 10066 |
/* Parse a binary expression; that is, a logical-OR-expression (C90 |
| 10067 |
6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not |
| 10068 |
NULL then it is an Objective-C message expression which is the |
| 10069 |
primary-expression starting the expression as an initializer. |
| 10070 |
|
| 10071 |
OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic, |
| 10072 |
when it should be the unfolded lhs. In a valid OpenMP source, |
| 10073 |
one of the operands of the toplevel binary expression must be equal |
| 10074 |
to it. In that case, just return a build2 created binary operation |
| 10075 |
rather than result of parser_build_binary_op. |
| 10076 |
|
| 10077 |
multiplicative-expression: |
| 10078 |
cast-expression |
| 10079 |
multiplicative-expression * cast-expression |
| 10080 |
multiplicative-expression / cast-expression |
| 10081 |
multiplicative-expression % cast-expression |
| 10082 |
|
| 10083 |
additive-expression: |
| 10084 |
multiplicative-expression |
| 10085 |
additive-expression + multiplicative-expression |
| 10086 |
additive-expression - multiplicative-expression |
| 10087 |
|
| 10088 |
shift-expression: |
| 10089 |
additive-expression |
| 10090 |
shift-expression << additive-expression |
| 10091 |
shift-expression >> additive-expression |
| 10092 |
|
| 10093 |
relational-expression: |
| 10094 |
shift-expression |
| 10095 |
relational-expression < shift-expression |
| 10096 |
relational-expression > shift-expression |
| 10097 |
relational-expression <= shift-expression |
| 10098 |
relational-expression >= shift-expression |
| 10099 |
|
| 10100 |
equality-expression: |
| 10101 |
relational-expression |
| 10102 |
equality-expression == relational-expression |
| 10103 |
equality-expression != relational-expression |
| 10104 |
|
| 10105 |
AND-expression: |
| 10106 |
equality-expression |
| 10107 |
AND-expression & equality-expression |
| 10108 |
|
| 10109 |
exclusive-OR-expression: |
| 10110 |
AND-expression |
| 10111 |
exclusive-OR-expression ^ AND-expression |
| 10112 |
|
| 10113 |
inclusive-OR-expression: |
| 10114 |
exclusive-OR-expression |
| 10115 |
inclusive-OR-expression | exclusive-OR-expression |
| 10116 |
|
| 10117 |
logical-AND-expression: |
| 10118 |
inclusive-OR-expression |
| 10119 |
logical-AND-expression && inclusive-OR-expression |
| 10120 |
|
| 10121 |
logical-OR-expression: |
| 10122 |
logical-AND-expression |
| 10123 |
logical-OR-expression || logical-AND-expression |
| 10124 |
*/ |
| 10125 |
|
| 10126 |
static struct c_expr |
| 10127 |
c_parser_binary_expression (c_parser *parser, struct c_expr *after, |
| 10128 |
tree omp_atomic_lhs) |
| 10129 |
{ |
| 10130 |
/* A binary expression is parsed using operator-precedence parsing, |
| 10131 |
with the operands being cast expressions. All the binary |
| 10132 |
operators are left-associative. Thus a binary expression is of |
| 10133 |
form: |
| 10134 |
|
| 10135 |
E0 op1 E1 op2 E2 ... |
| 10136 |
|
| 10137 |
which we represent on a stack. On the stack, the precedence |
| 10138 |
levels are strictly increasing. When a new operator is |
| 10139 |
encountered of higher precedence than that at the top of the |
| 10140 |
stack, it is pushed; its LHS is the top expression, and its RHS |
| 10141 |
is everything parsed until it is popped. When a new operator is |
| 10142 |
encountered with precedence less than or equal to that at the top |
| 10143 |
of the stack, triples E[i-1] op[i] E[i] are popped and replaced |
| 10144 |
by the result of the operation until the operator at the top of |
| 10145 |
the stack has lower precedence than the new operator or there is |
| 10146 |
only one element on the stack; then the top expression is the LHS |
| 10147 |
of the new operator. In the case of logical AND and OR |
| 10148 |
expressions, we also need to adjust c_inhibit_evaluation_warnings |
| 10149 |
as appropriate when the operators are pushed and popped. */ |
| 10150 |
|
| 10151 |
struct { |
| 10152 |
/* The expression at this stack level. */ |
| 10153 |
struct c_expr expr; |
| 10154 |
/* The precedence of the operator on its left, PREC_NONE at the |
| 10155 |
bottom of the stack. */ |
| 10156 |
enum c_parser_prec prec; |
| 10157 |
/* The operation on its left. */ |
| 10158 |
enum tree_code op; |
| 10159 |
/* The source location of this operation. */ |
| 10160 |
location_t loc; |
| 10161 |
/* The sizeof argument if expr.original_code == {PAREN_,}SIZEOF_EXPR. */ |
| 10162 |
tree sizeof_arg; |
| 10163 |
} stack[NUM_PRECS]; |
| 10164 |
int sp; |
| 10165 |
/* Location of the binary operator. */ |
| 10166 |
location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 10167 |
#define POP \ |
| 10168 |
do { \ |
| 10169 |
switch (stack[sp].op) \ |
| 10170 |
{ \ |
| 10171 |
case TRUTH_ANDIF_EXPR: \ |
| 10172 |
c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
| 10173 |
== truthvalue_false_node); \ |
| 10174 |
break; \ |
| 10175 |
case TRUTH_ORIF_EXPR: \ |
| 10176 |
c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
| 10177 |
== truthvalue_true_node); \ |
| 10178 |
break; \ |
| 10179 |
case TRUNC_DIV_EXPR: \ |
| 10180 |
if ((stack[sp - 1].expr.original_code == SIZEOF_EXPR \ |
| 10181 |
|| stack[sp - 1].expr.original_code == PAREN_SIZEOF_EXPR) \ |
| 10182 |
&& (stack[sp].expr.original_code == SIZEOF_EXPR \ |
| 10183 |
|| stack[sp].expr.original_code == PAREN_SIZEOF_EXPR)) \ |
| 10184 |
{ \ |
| 10185 |
tree type0 = stack[sp - 1].sizeof_arg; \ |
| 10186 |
tree type1 = stack[sp].sizeof_arg; \ |
| 10187 |
tree first_arg = type0; \ |
| 10188 |
if (!TYPE_P (type0)) \ |
| 10189 |
type0 = TREE_TYPE (type0); \ |
| 10190 |
if (!TYPE_P (type1)) \ |
| 10191 |
type1 = TREE_TYPE (type1); \ |
| 10192 |
if (POINTER_TYPE_P (type0) \ |
| 10193 |
&& comptypes (TREE_TYPE (type0), type1) \ |
| 10194 |
&& !(TREE_CODE (first_arg) == PARM_DECL \ |
| 10195 |
&& C_ARRAY_PARAMETER (first_arg) \ |
| 10196 |
&& warn_sizeof_array_argument)) \ |
| 10197 |
{ \ |
| 10198 |
auto_diagnostic_group d; \ |
| 10199 |
if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \ |
| 10200 |
"division %<sizeof (%T) / sizeof (%T)%> " \ |
| 10201 |
"does not compute the number of array " \ |
| 10202 |
"elements", \ |
| 10203 |
type0, type1)) \ |
| 10204 |
if (DECL_P (first_arg)) \ |
| 10205 |
inform (DECL_SOURCE_LOCATION (first_arg), \ |
| 10206 |
"first %<sizeof%> operand was declared here"); \ |
| 10207 |
} \ |
| 10208 |
else if (TREE_CODE (type0) == ARRAY_TYPE \ |
| 10209 |
&& !char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type0))) \ |
| 10210 |
&& stack[sp].expr.original_code != PAREN_SIZEOF_EXPR) \ |
| 10211 |
maybe_warn_sizeof_array_div (stack[sp].loc, first_arg, type0, \ |
| 10212 |
stack[sp].sizeof_arg, type1); \ |
| 10213 |
} \ |
| 10214 |
break; \ |
| 10215 |
default: \ |
| 10216 |
break; \ |
| 10217 |
} \ |
| 10218 |
stack[sp - 1].expr \ |
| 10219 |
= convert_lvalue_to_rvalue (stack[sp - 1].loc, \ |
| 10220 |
stack[sp - 1].expr, true, true); \ |
| 10221 |
stack[sp].expr \ |
| 10222 |
= convert_lvalue_to_rvalue (stack[sp].loc, \ |
| 10223 |
stack[sp].expr, true, true); \ |
| 10224 |
if (UNLIKELY (omp_atomic_lhs != NULL_TREE) && sp == 1 \ |
| 10225 |
&& ((c_parser_next_token_is (parser, CPP_SEMICOLON) \ |
| 10226 |
&& ((1 << stack[sp].prec) \ |
| 10227 |
& ((1 << PREC_BITOR) | (1 << PREC_BITXOR) \ |
| 10228 |
| (1 << PREC_BITAND) | (1 << PREC_SHIFT) \ |
| 10229 |
| (1 << PREC_ADD) | (1 << PREC_MULT) \ |
| 10230 |
| (1 << PREC_EQ)))) \ |
| 10231 |
|| ((c_parser_next_token_is (parser, CPP_QUERY) \ |
| 10232 |
|| (omp_atomic_lhs == void_list_node \ |
| 10233 |
&& c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) \ |
| 10234 |
&& (stack[sp].prec == PREC_REL || stack[sp].prec == PREC_EQ)))\ |
| 10235 |
&& stack[sp].op != TRUNC_MOD_EXPR \ |
| 10236 |
&& stack[sp].op != GE_EXPR \ |
| 10237 |
&& stack[sp].op != LE_EXPR \ |
| 10238 |
&& stack[sp].op != NE_EXPR \ |
| 10239 |
&& stack[0].expr.value != error_mark_node \ |
| 10240 |
&& stack[1].expr.value != error_mark_node \ |
| 10241 |
&& (omp_atomic_lhs == void_list_node \ |
| 10242 |
|| c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \ |
| 10243 |
|| c_tree_equal (stack[1].expr.value, omp_atomic_lhs) \ |
| 10244 |
|| (stack[sp].op == EQ_EXPR \ |
| 10245 |
&& c_parser_peek_2nd_token (parser)->keyword == RID_IF))) \ |
| 10246 |
{ \ |
| 10247 |
tree t = make_node (stack[1].op); \ |
| 10248 |
TREE_TYPE (t) = TREE_TYPE (stack[0].expr.value); \ |
| 10249 |
TREE_OPERAND (t, 0) = stack[0].expr.value; \ |
| 10250 |
TREE_OPERAND (t, 1) = stack[1].expr.value; \ |
| 10251 |
stack[0].expr.value = t; \ |
| 10252 |
stack[0].expr.m_decimal = 0; \ |
| 10253 |
} \ |
| 10254 |
else \ |
| 10255 |
stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \ |
| 10256 |
stack[sp].op, \ |
| 10257 |
stack[sp - 1].expr, \ |
| 10258 |
stack[sp].expr); \ |
| 10259 |
sp--; \ |
| 10260 |
} while (0) |
| 10261 |
gcc_assert (!after || c_dialect_objc ()); |
| 10262 |
stack[0].loc = c_parser_peek_token (parser)->location; |
| 10263 |
stack[0].expr = c_parser_cast_expression (parser, after); |
| 10264 |
stack[0].prec = PREC_NONE; |
| 10265 |
stack[0].sizeof_arg = c_last_sizeof_arg; |
| 10266 |
sp = 0; |
| 10267 |
while (true) |
| 10268 |
{ |
| 10269 |
enum c_parser_prec oprec; |
| 10270 |
enum tree_code ocode; |
| 10271 |
source_range src_range; |
| 10272 |
if (parser->error) |
| 10273 |
goto out; |
| 10274 |
switch (c_parser_peek_token (parser)->type) |
| 10275 |
{ |
| 10276 |
case CPP_MULT: |
| 10277 |
oprec = PREC_MULT; |
| 10278 |
ocode = MULT_EXPR; |
| 10279 |
break; |
| 10280 |
case CPP_DIV: |
| 10281 |
oprec = PREC_MULT; |
| 10282 |
ocode = TRUNC_DIV_EXPR; |
| 10283 |
break; |
| 10284 |
case CPP_MOD: |
| 10285 |
oprec = PREC_MULT; |
| 10286 |
ocode = TRUNC_MOD_EXPR; |
| 10287 |
break; |
| 10288 |
case CPP_PLUS: |
| 10289 |
oprec = PREC_ADD; |
| 10290 |
ocode = PLUS_EXPR; |
| 10291 |
break; |
| 10292 |
case CPP_MINUS: |
| 10293 |
oprec = PREC_ADD; |
| 10294 |
ocode = MINUS_EXPR; |
| 10295 |
break; |
| 10296 |
case CPP_LSHIFT: |
| 10297 |
oprec = PREC_SHIFT; |
| 10298 |
ocode = LSHIFT_EXPR; |
| 10299 |
break; |
| 10300 |
case CPP_RSHIFT: |
| 10301 |
oprec = PREC_SHIFT; |
| 10302 |
ocode = RSHIFT_EXPR; |
| 10303 |
break; |
| 10304 |
case CPP_LESS: |
| 10305 |
oprec = PREC_REL; |
| 10306 |
ocode = LT_EXPR; |
| 10307 |
break; |
| 10308 |
case CPP_GREATER: |
| 10309 |
oprec = PREC_REL; |
| 10310 |
ocode = GT_EXPR; |
| 10311 |
break; |
| 10312 |
case CPP_LESS_EQ: |
| 10313 |
oprec = PREC_REL; |
| 10314 |
ocode = LE_EXPR; |
| 10315 |
break; |
| 10316 |
case CPP_GREATER_EQ: |
| 10317 |
oprec = PREC_REL; |
| 10318 |
ocode = GE_EXPR; |
| 10319 |
break; |
| 10320 |
case CPP_EQ_EQ: |
| 10321 |
oprec = PREC_EQ; |
| 10322 |
ocode = EQ_EXPR; |
| 10323 |
break; |
| 10324 |
case CPP_NOT_EQ: |
| 10325 |
oprec = PREC_EQ; |
| 10326 |
ocode = NE_EXPR; |
| 10327 |
break; |
| 10328 |
case CPP_AND: |
| 10329 |
oprec = PREC_BITAND; |
| 10330 |
ocode = BIT_AND_EXPR; |
| 10331 |
break; |
| 10332 |
case CPP_XOR: |
| 10333 |
oprec = PREC_BITXOR; |
| 10334 |
ocode = BIT_XOR_EXPR; |
| 10335 |
break; |
| 10336 |
case CPP_OR: |
| 10337 |
oprec = PREC_BITOR; |
| 10338 |
ocode = BIT_IOR_EXPR; |
| 10339 |
break; |
| 10340 |
case CPP_AND_AND: |
| 10341 |
oprec = PREC_LOGAND; |
| 10342 |
ocode = TRUTH_ANDIF_EXPR; |
| 10343 |
break; |
| 10344 |
case CPP_OR_OR: |
| 10345 |
oprec = PREC_LOGOR; |
| 10346 |
ocode = TRUTH_ORIF_EXPR; |
| 10347 |
break; |
| 10348 |
default: |
| 10349 |
/* Not a binary operator, so end of the binary |
| 10350 |
expression. */ |
| 10351 |
goto out; |
| 10352 |
} |
| 10353 |
binary_loc = c_parser_peek_token (parser)->location; |
| 10354 |
while (oprec <= stack[sp].prec) |
| 10355 |
POP; |
| 10356 |
c_parser_consume_token (parser); |
| 10357 |
switch (ocode) |
| 10358 |
{ |
| 10359 |
case TRUTH_ANDIF_EXPR: |
| 10360 |
src_range = stack[sp].expr.src_range; |
| 10361 |
stack[sp].expr |
| 10362 |
= convert_lvalue_to_rvalue (stack[sp].loc, |
| 10363 |
stack[sp].expr, true, true); |
| 10364 |
stack[sp].expr.value = c_objc_common_truthvalue_conversion |
| 10365 |
(stack[sp].loc, default_conversion (stack[sp].expr.value)); |
| 10366 |
c_inhibit_evaluation_warnings += (stack[sp].expr.value |
| 10367 |
== truthvalue_false_node); |
| 10368 |
set_c_expr_source_range (&stack[sp].expr, src_range); |
| 10369 |
break; |
| 10370 |
case TRUTH_ORIF_EXPR: |
| 10371 |
src_range = stack[sp].expr.src_range; |
| 10372 |
stack[sp].expr |
| 10373 |
= convert_lvalue_to_rvalue (stack[sp].loc, |
| 10374 |
stack[sp].expr, true, true); |
| 10375 |
stack[sp].expr.value = c_objc_common_truthvalue_conversion |
| 10376 |
(stack[sp].loc, default_conversion (stack[sp].expr.value)); |
| 10377 |
c_inhibit_evaluation_warnings += (stack[sp].expr.value |
| 10378 |
== truthvalue_true_node); |
| 10379 |
set_c_expr_source_range (&stack[sp].expr, src_range); |
| 10380 |
break; |
| 10381 |
default: |
| 10382 |
break; |
| 10383 |
} |
| 10384 |
sp++; |
| 10385 |
stack[sp].loc = binary_loc; |
| 10386 |
stack[sp].expr = c_parser_cast_expression (parser, NULL); |
| 10387 |
stack[sp].prec = oprec; |
| 10388 |
stack[sp].op = ocode; |
| 10389 |
stack[sp].sizeof_arg = c_last_sizeof_arg; |
| 10390 |
} |
| 10391 |
out: |
| 10392 |
while (sp > 0) |
| 10393 |
POP; |
| 10394 |
return stack[0].expr; |
| 10395 |
#undef POP |
| 10396 |
} |
| 10397 |
|
| 10398 |
/* Parse any storage class specifiers after an open parenthesis in a |
| 10399 |
context where a compound literal is permitted. */ |
| 10400 |
|
| 10401 |
static struct c_declspecs * |
| 10402 |
c_parser_compound_literal_scspecs (c_parser *parser) |
| 10403 |
{ |
| 10404 |
bool seen_scspec = false; |
| 10405 |
struct c_declspecs *specs = build_null_declspecs (); |
| 10406 |
while (c_parser_next_token_is (parser, CPP_KEYWORD)) |
| 10407 |
{ |
| 10408 |
switch (c_parser_peek_token (parser)->keyword) |
| 10409 |
{ |
| 10410 |
case RID_CONSTEXPR: |
| 10411 |
case RID_REGISTER: |
| 10412 |
case RID_STATIC: |
| 10413 |
case RID_THREAD: |
| 10414 |
seen_scspec = true; |
| 10415 |
declspecs_add_scspec (c_parser_peek_token (parser)->location, |
| 10416 |
specs, c_parser_peek_token (parser)->value); |
| 10417 |
c_parser_consume_token (parser); |
| 10418 |
break; |
| 10419 |
default: |
| 10420 |
goto out; |
| 10421 |
} |
| 10422 |
} |
| 10423 |
out: |
| 10424 |
return seen_scspec ? specs : NULL; |
| 10425 |
} |
| 10426 |
|
| 10427 |
/* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER |
| 10428 |
is not NULL then it is an Objective-C message expression which is the |
| 10429 |
primary-expression starting the expression as an initializer. |
| 10430 |
|
| 10431 |
cast-expression: |
| 10432 |
unary-expression |
| 10433 |
( type-name ) unary-expression |
| 10434 |
*/ |
| 10435 |
|
| 10436 |
static struct c_expr |
| 10437 |
c_parser_cast_expression (c_parser *parser, struct c_expr *after) |
| 10438 |
{ |
| 10439 |
location_t cast_loc = c_parser_peek_token (parser)->location; |
| 10440 |
gcc_assert (!after || c_dialect_objc ()); |
| 10441 |
if (after) |
| 10442 |
return c_parser_postfix_expression_after_primary (parser, |
| 10443 |
cast_loc, *after); |
| 10444 |
/* If the expression begins with a parenthesized type name, it may |
| 10445 |
be either a cast or a compound literal; we need to see whether |
| 10446 |
the next character is '{' to tell the difference. If not, it is |
| 10447 |
an unary expression. Full detection of unknown typenames here |
| 10448 |
would require a 3-token lookahead. */ |
| 10449 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 10450 |
&& c_token_starts_compound_literal (c_parser_peek_2nd_token (parser))) |
| 10451 |
{ |
| 10452 |
struct c_declspecs *scspecs; |
| 10453 |
struct c_type_name *type_name; |
| 10454 |
struct c_expr ret; |
| 10455 |
struct c_expr expr; |
| 10456 |
matching_parens parens; |
| 10457 |
parens.consume_open (parser); |
| 10458 |
scspecs = c_parser_compound_literal_scspecs (parser); |
| 10459 |
type_name = c_parser_type_name (parser, true); |
| 10460 |
parens.skip_until_found_close (parser); |
| 10461 |
if (type_name == NULL) |
| 10462 |
{ |
| 10463 |
ret.set_error (); |
| 10464 |
ret.original_code = ERROR_MARK; |
| 10465 |
ret.original_type = NULL; |
| 10466 |
return ret; |
| 10467 |
} |
| 10468 |
|
| 10469 |
/* Save casted types in the function's used types hash table. */ |
| 10470 |
used_types_insert (type_name->specs->type); |
| 10471 |
|
| 10472 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 10473 |
return c_parser_postfix_expression_after_paren_type (parser, scspecs, |
| 10474 |
type_name, |
| 10475 |
cast_loc); |
| 10476 |
if (scspecs) |
| 10477 |
error_at (cast_loc, "storage class specifier in cast"); |
| 10478 |
if (type_name->specs->alignas_p) |
| 10479 |
error_at (type_name->specs->locations[cdw_alignas], |
| 10480 |
"alignment specified for type name in cast"); |
| 10481 |
{ |
| 10482 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 10483 |
expr = c_parser_cast_expression (parser, NULL); |
| 10484 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true); |
| 10485 |
} |
| 10486 |
ret.value = c_cast_expr (cast_loc, type_name, expr.value); |
| 10487 |
if (ret.value && expr.value) |
| 10488 |
set_c_expr_source_range (&ret, cast_loc, expr.get_finish ()); |
| 10489 |
ret.original_code = ERROR_MARK; |
| 10490 |
ret.original_type = NULL; |
| 10491 |
ret.m_decimal = 0; |
| 10492 |
return ret; |
| 10493 |
} |
| 10494 |
else |
| 10495 |
return c_parser_unary_expression (parser); |
| 10496 |
} |
| 10497 |
|
| 10498 |
/* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3). |
| 10499 |
|
| 10500 |
unary-expression: |
| 10501 |
postfix-expression |
| 10502 |
++ unary-expression |
| 10503 |
-- unary-expression |
| 10504 |
unary-operator cast-expression |
| 10505 |
sizeof unary-expression |
| 10506 |
sizeof ( type-name ) |
| 10507 |
|
| 10508 |
unary-operator: one of |
| 10509 |
& * + - ~ ! |
| 10510 |
|
| 10511 |
GNU extensions: |
| 10512 |
|
| 10513 |
unary-expression: |
| 10514 |
__alignof__ unary-expression |
| 10515 |
__alignof__ ( type-name ) |
| 10516 |
&& identifier |
| 10517 |
|
| 10518 |
(C11 permits _Alignof with type names only.) |
| 10519 |
|
| 10520 |
unary-operator: one of |
| 10521 |
__extension__ __real__ __imag__ |
| 10522 |
|
| 10523 |
Transactional Memory: |
| 10524 |
|
| 10525 |
unary-expression: |
| 10526 |
transaction-expression |
| 10527 |
|
| 10528 |
In addition, the GNU syntax treats ++ and -- as unary operators, so |
| 10529 |
they may be applied to cast expressions with errors for non-lvalues |
| 10530 |
given later. */ |
| 10531 |
|
| 10532 |
static struct c_expr |
| 10533 |
c_parser_unary_expression (c_parser *parser) |
| 10534 |
{ |
| 10535 |
int ext; |
| 10536 |
struct c_expr ret, op; |
| 10537 |
location_t op_loc = c_parser_peek_token (parser)->location; |
| 10538 |
location_t exp_loc; |
| 10539 |
location_t finish; |
| 10540 |
ret.original_code = ERROR_MARK; |
| 10541 |
ret.original_type = NULL; |
| 10542 |
switch (c_parser_peek_token (parser)->type) |
| 10543 |
{ |
| 10544 |
case CPP_PLUS_PLUS: |
| 10545 |
c_parser_consume_token (parser); |
| 10546 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10547 |
op = c_parser_cast_expression (parser, NULL); |
| 10548 |
|
| 10549 |
op = default_function_array_read_conversion (exp_loc, op); |
| 10550 |
return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op); |
| 10551 |
case CPP_MINUS_MINUS: |
| 10552 |
c_parser_consume_token (parser); |
| 10553 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10554 |
op = c_parser_cast_expression (parser, NULL); |
| 10555 |
|
| 10556 |
op = default_function_array_read_conversion (exp_loc, op); |
| 10557 |
return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op); |
| 10558 |
case CPP_AND: |
| 10559 |
c_parser_consume_token (parser); |
| 10560 |
op = c_parser_cast_expression (parser, NULL); |
| 10561 |
mark_exp_read (op.value); |
| 10562 |
return parser_build_unary_op (op_loc, ADDR_EXPR, op); |
| 10563 |
case CPP_MULT: |
| 10564 |
{ |
| 10565 |
c_parser_consume_token (parser); |
| 10566 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10567 |
op = c_parser_cast_expression (parser, NULL); |
| 10568 |
finish = op.get_finish (); |
| 10569 |
op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 10570 |
location_t combined_loc = make_location (op_loc, op_loc, finish); |
| 10571 |
ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR); |
| 10572 |
ret.src_range.m_start = op_loc; |
| 10573 |
ret.src_range.m_finish = finish; |
| 10574 |
ret.m_decimal = 0; |
| 10575 |
return ret; |
| 10576 |
} |
| 10577 |
case CPP_PLUS: |
| 10578 |
if (!c_dialect_objc () && !in_system_header_at (input_location)) |
| 10579 |
warning_at (op_loc, |
| 10580 |
OPT_Wtraditional, |
| 10581 |
"traditional C rejects the unary plus operator"); |
| 10582 |
c_parser_consume_token (parser); |
| 10583 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10584 |
op = c_parser_cast_expression (parser, NULL); |
| 10585 |
op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 10586 |
return parser_build_unary_op (op_loc, CONVERT_EXPR, op); |
| 10587 |
case CPP_MINUS: |
| 10588 |
c_parser_consume_token (parser); |
| 10589 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10590 |
op = c_parser_cast_expression (parser, NULL); |
| 10591 |
op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 10592 |
return parser_build_unary_op (op_loc, NEGATE_EXPR, op); |
| 10593 |
case CPP_COMPL: |
| 10594 |
c_parser_consume_token (parser); |
| 10595 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10596 |
op = c_parser_cast_expression (parser, NULL); |
| 10597 |
op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 10598 |
return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); |
| 10599 |
case CPP_NOT: |
| 10600 |
c_parser_consume_token (parser); |
| 10601 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10602 |
op = c_parser_cast_expression (parser, NULL); |
| 10603 |
op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 10604 |
return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); |
| 10605 |
case CPP_AND_AND: |
| 10606 |
/* Refer to the address of a label as a pointer. */ |
| 10607 |
c_parser_consume_token (parser); |
| 10608 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 10609 |
{ |
| 10610 |
ret.value = finish_label_address_expr |
| 10611 |
(c_parser_peek_token (parser)->value, op_loc); |
| 10612 |
set_c_expr_source_range (&ret, op_loc, |
| 10613 |
c_parser_peek_token (parser)->get_finish ()); |
| 10614 |
c_parser_consume_token (parser); |
| 10615 |
} |
| 10616 |
else |
| 10617 |
{ |
| 10618 |
c_parser_error (parser, "expected identifier"); |
| 10619 |
ret.set_error (); |
| 10620 |
} |
| 10621 |
return ret; |
| 10622 |
case CPP_KEYWORD: |
| 10623 |
switch (c_parser_peek_token (parser)->keyword) |
| 10624 |
{ |
| 10625 |
case RID_SIZEOF: |
| 10626 |
return c_parser_sizeof_expression (parser); |
| 10627 |
case RID_ALIGNOF: |
| 10628 |
return c_parser_alignof_expression (parser); |
| 10629 |
case RID_BUILTIN_HAS_ATTRIBUTE: |
| 10630 |
return c_parser_has_attribute_expression (parser); |
| 10631 |
case RID_EXTENSION: |
| 10632 |
c_parser_consume_token (parser); |
| 10633 |
ext = disable_extension_diagnostics (); |
| 10634 |
ret = c_parser_cast_expression (parser, NULL); |
| 10635 |
restore_extension_diagnostics (ext); |
| 10636 |
return ret; |
| 10637 |
case RID_REALPART: |
| 10638 |
c_parser_consume_token (parser); |
| 10639 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10640 |
op = c_parser_cast_expression (parser, NULL); |
| 10641 |
op = default_function_array_conversion (exp_loc, op); |
| 10642 |
return parser_build_unary_op (op_loc, REALPART_EXPR, op); |
| 10643 |
case RID_IMAGPART: |
| 10644 |
c_parser_consume_token (parser); |
| 10645 |
exp_loc = c_parser_peek_token (parser)->location; |
| 10646 |
op = c_parser_cast_expression (parser, NULL); |
| 10647 |
op = default_function_array_conversion (exp_loc, op); |
| 10648 |
return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); |
| 10649 |
case RID_TRANSACTION_ATOMIC: |
| 10650 |
case RID_TRANSACTION_RELAXED: |
| 10651 |
return c_parser_transaction_expression (parser, |
| 10652 |
c_parser_peek_token (parser)->keyword); |
| 10653 |
default: |
| 10654 |
return c_parser_postfix_expression (parser); |
| 10655 |
} |
| 10656 |
default: |
| 10657 |
return c_parser_postfix_expression (parser); |
| 10658 |
} |
| 10659 |
} |
| 10660 |
|
| 10661 |
/* Parse a sizeof expression. */ |
| 10662 |
|
| 10663 |
static struct c_expr |
| 10664 |
c_parser_sizeof_expression (c_parser *parser) |
| 10665 |
{ |
| 10666 |
struct c_expr expr; |
| 10667 |
struct c_expr result; |
| 10668 |
location_t expr_loc; |
| 10669 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF)); |
| 10670 |
|
| 10671 |
location_t start; |
| 10672 |
location_t finish = UNKNOWN_LOCATION; |
| 10673 |
|
| 10674 |
start = c_parser_peek_token (parser)->location; |
| 10675 |
|
| 10676 |
c_parser_consume_token (parser); |
| 10677 |
c_inhibit_evaluation_warnings++; |
| 10678 |
in_sizeof++; |
| 10679 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 10680 |
&& c_token_starts_compound_literal (c_parser_peek_2nd_token (parser))) |
| 10681 |
{ |
| 10682 |
/* Either sizeof ( type-name ) or sizeof unary-expression |
| 10683 |
starting with a compound literal. */ |
| 10684 |
struct c_declspecs *scspecs; |
| 10685 |
struct c_type_name *type_name; |
| 10686 |
matching_parens parens; |
| 10687 |
parens.consume_open (parser); |
| 10688 |
expr_loc = c_parser_peek_token (parser)->location; |
| 10689 |
scspecs = c_parser_compound_literal_scspecs (parser); |
| 10690 |
type_name = c_parser_type_name (parser, true); |
| 10691 |
parens.skip_until_found_close (parser); |
| 10692 |
finish = parser->tokens_buf[0].location; |
| 10693 |
if (type_name == NULL) |
| 10694 |
{ |
| 10695 |
/* Let c_expr_sizeof_expr call pop_maybe_used and fill in c_expr |
| 10696 |
for parsing error; the parsing of the expression could have |
| 10697 |
called record_maybe_used_decl. */ |
| 10698 |
expr.set_error (); |
| 10699 |
goto sizeof_expr; |
| 10700 |
} |
| 10701 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 10702 |
{ |
| 10703 |
expr = c_parser_postfix_expression_after_paren_type (parser, scspecs, |
| 10704 |
type_name, |
| 10705 |
expr_loc); |
| 10706 |
finish = expr.get_finish (); |
| 10707 |
goto sizeof_expr; |
| 10708 |
} |
| 10709 |
/* sizeof ( type-name ). */ |
| 10710 |
if (scspecs) |
| 10711 |
error_at (expr_loc, "storage class specifier in %<sizeof%>"); |
| 10712 |
if (type_name->specs->alignas_p) |
| 10713 |
error_at (type_name->specs->locations[cdw_alignas], |
| 10714 |
"alignment specified for type name in %<sizeof%>"); |
| 10715 |
c_inhibit_evaluation_warnings--; |
| 10716 |
in_sizeof--; |
| 10717 |
result = c_expr_sizeof_type (expr_loc, type_name); |
| 10718 |
} |
| 10719 |
else |
| 10720 |
{ |
| 10721 |
expr_loc = c_parser_peek_token (parser)->location; |
| 10722 |
expr = c_parser_unary_expression (parser); |
| 10723 |
finish = expr.get_finish (); |
| 10724 |
sizeof_expr: |
| 10725 |
c_inhibit_evaluation_warnings--; |
| 10726 |
in_sizeof--; |
| 10727 |
mark_exp_read (expr.value); |
| 10728 |
if (TREE_CODE (expr.value) == COMPONENT_REF |
| 10729 |
&& DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) |
| 10730 |
error_at (expr_loc, "%<sizeof%> applied to a bit-field"); |
| 10731 |
result = c_expr_sizeof_expr (expr_loc, expr); |
| 10732 |
} |
| 10733 |
if (finish == UNKNOWN_LOCATION) |
| 10734 |
finish = start; |
| 10735 |
set_c_expr_source_range (&result, start, finish); |
| 10736 |
return result; |
| 10737 |
} |
| 10738 |
|
| 10739 |
/* Parse an alignof expression. */ |
| 10740 |
|
| 10741 |
static struct c_expr |
| 10742 |
c_parser_alignof_expression (c_parser *parser) |
| 10743 |
{ |
| 10744 |
struct c_expr expr; |
| 10745 |
location_t start_loc = c_parser_peek_token (parser)->location; |
| 10746 |
location_t end_loc; |
| 10747 |
tree alignof_spelling = c_parser_peek_token (parser)->value; |
| 10748 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); |
| 10749 |
bool is_c11_alignof = (strcmp (IDENTIFIER_POINTER (alignof_spelling), |
| 10750 |
"_Alignof") == 0 |
| 10751 |
|| strcmp (IDENTIFIER_POINTER (alignof_spelling), |
| 10752 |
"alignof") == 0); |
| 10753 |
/* A diagnostic is not required for the use of this identifier in |
| 10754 |
the implementation namespace; only diagnose it for the C11 or C23 |
| 10755 |
spelling because of existing code using the other spellings. */ |
| 10756 |
if (is_c11_alignof) |
| 10757 |
{ |
| 10758 |
if (flag_isoc99) |
| 10759 |
pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE", |
| 10760 |
alignof_spelling); |
| 10761 |
else |
| 10762 |
pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE", |
| 10763 |
alignof_spelling); |
| 10764 |
} |
| 10765 |
c_parser_consume_token (parser); |
| 10766 |
c_inhibit_evaluation_warnings++; |
| 10767 |
in_alignof++; |
| 10768 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 10769 |
&& c_token_starts_compound_literal (c_parser_peek_2nd_token (parser))) |
| 10770 |
{ |
| 10771 |
/* Either __alignof__ ( type-name ) or __alignof__ |
| 10772 |
unary-expression starting with a compound literal. */ |
| 10773 |
location_t loc; |
| 10774 |
struct c_declspecs *scspecs; |
| 10775 |
struct c_type_name *type_name; |
| 10776 |
struct c_expr ret; |
| 10777 |
matching_parens parens; |
| 10778 |
parens.consume_open (parser); |
| 10779 |
loc = c_parser_peek_token (parser)->location; |
| 10780 |
scspecs = c_parser_compound_literal_scspecs (parser); |
| 10781 |
type_name = c_parser_type_name (parser, true); |
| 10782 |
end_loc = c_parser_peek_token (parser)->location; |
| 10783 |
parens.skip_until_found_close (parser); |
| 10784 |
if (type_name == NULL) |
| 10785 |
{ |
| 10786 |
struct c_expr ret; |
| 10787 |
c_inhibit_evaluation_warnings--; |
| 10788 |
in_alignof--; |
| 10789 |
ret.set_error (); |
| 10790 |
ret.original_code = ERROR_MARK; |
| 10791 |
ret.original_type = NULL; |
| 10792 |
return ret; |
| 10793 |
} |
| 10794 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 10795 |
{ |
| 10796 |
expr = c_parser_postfix_expression_after_paren_type (parser, scspecs, |
| 10797 |
type_name, |
| 10798 |
loc); |
| 10799 |
goto alignof_expr; |
| 10800 |
} |
| 10801 |
/* alignof ( type-name ). */ |
| 10802 |
if (scspecs) |
| 10803 |
error_at (loc, "storage class specifier in %qE", alignof_spelling); |
| 10804 |
if (type_name->specs->alignas_p) |
| 10805 |
error_at (type_name->specs->locations[cdw_alignas], |
| 10806 |
"alignment specified for type name in %qE", |
| 10807 |
alignof_spelling); |
| 10808 |
c_inhibit_evaluation_warnings--; |
| 10809 |
in_alignof--; |
| 10810 |
ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name, |
| 10811 |
NULL, NULL), |
| 10812 |
false, is_c11_alignof, 1); |
| 10813 |
ret.original_code = ERROR_MARK; |
| 10814 |
ret.original_type = NULL; |
| 10815 |
set_c_expr_source_range (&ret, start_loc, end_loc); |
| 10816 |
ret.m_decimal = 0; |
| 10817 |
return ret; |
| 10818 |
} |
| 10819 |
else |
| 10820 |
{ |
| 10821 |
struct c_expr ret; |
| 10822 |
expr = c_parser_unary_expression (parser); |
| 10823 |
end_loc = expr.src_range.m_finish; |
| 10824 |
alignof_expr: |
| 10825 |
mark_exp_read (expr.value); |
| 10826 |
c_inhibit_evaluation_warnings--; |
| 10827 |
in_alignof--; |
| 10828 |
if (is_c11_alignof) |
| 10829 |
pedwarn (start_loc, |
| 10830 |
OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>", |
| 10831 |
alignof_spelling); |
| 10832 |
ret.value = c_alignof_expr (start_loc, expr.value); |
| 10833 |
ret.original_code = ERROR_MARK; |
| 10834 |
ret.original_type = NULL; |
| 10835 |
set_c_expr_source_range (&ret, start_loc, end_loc); |
| 10836 |
ret.m_decimal = 0; |
| 10837 |
return ret; |
| 10838 |
} |
| 10839 |
} |
| 10840 |
|
| 10841 |
/* Parse the __builtin_has_attribute ([expr|type], attribute-spec) |
| 10842 |
expression. */ |
| 10843 |
|
| 10844 |
static struct c_expr |
| 10845 |
c_parser_has_attribute_expression (c_parser *parser) |
| 10846 |
{ |
| 10847 |
gcc_assert (c_parser_next_token_is_keyword (parser, |
| 10848 |
RID_BUILTIN_HAS_ATTRIBUTE)); |
| 10849 |
location_t start = c_parser_peek_token (parser)->location; |
| 10850 |
c_parser_consume_token (parser); |
| 10851 |
|
| 10852 |
c_inhibit_evaluation_warnings++; |
| 10853 |
|
| 10854 |
matching_parens parens; |
| 10855 |
if (!parens.require_open (parser)) |
| 10856 |
{ |
| 10857 |
c_inhibit_evaluation_warnings--; |
| 10858 |
in_typeof--; |
| 10859 |
|
| 10860 |
struct c_expr result; |
| 10861 |
result.set_error (); |
| 10862 |
result.original_code = ERROR_MARK; |
| 10863 |
result.original_type = NULL; |
| 10864 |
return result; |
| 10865 |
} |
| 10866 |
|
| 10867 |
/* Treat the type argument the same way as in typeof for the purposes |
| 10868 |
of warnings. FIXME: Generalize this so the warning refers to |
| 10869 |
__builtin_has_attribute rather than typeof. */ |
| 10870 |
in_typeof++; |
| 10871 |
|
| 10872 |
/* The first operand: one of DECL, EXPR, or TYPE. */ |
| 10873 |
tree oper = NULL_TREE; |
| 10874 |
if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
| 10875 |
{ |
| 10876 |
struct c_type_name *tname = c_parser_type_name (parser); |
| 10877 |
in_typeof--; |
| 10878 |
if (tname) |
| 10879 |
{ |
| 10880 |
oper = groktypename (tname, NULL, NULL); |
| 10881 |
pop_maybe_used (c_type_variably_modified_p (oper)); |
| 10882 |
} |
| 10883 |
} |
| 10884 |
else |
| 10885 |
{ |
| 10886 |
struct c_expr cexpr = c_parser_expr_no_commas (parser, NULL); |
| 10887 |
c_inhibit_evaluation_warnings--; |
| 10888 |
in_typeof--; |
| 10889 |
if (cexpr.value != error_mark_node) |
| 10890 |
{ |
| 10891 |
mark_exp_read (cexpr.value); |
| 10892 |
oper = cexpr.value; |
| 10893 |
tree etype = TREE_TYPE (oper); |
| 10894 |
bool was_vm = c_type_variably_modified_p (etype); |
| 10895 |
/* This is returned with the type so that when the type is |
| 10896 |
evaluated, this can be evaluated. */ |
| 10897 |
if (was_vm) |
| 10898 |
oper = c_fully_fold (oper, false, NULL); |
| 10899 |
pop_maybe_used (was_vm); |
| 10900 |
} |
| 10901 |
} |
| 10902 |
|
| 10903 |
struct c_expr result; |
| 10904 |
result.original_code = ERROR_MARK; |
| 10905 |
result.original_type = NULL; |
| 10906 |
|
| 10907 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 10908 |
{ |
| 10909 |
/* Consume the closing parenthesis if that's the next token |
| 10910 |
in the likely case the built-in was invoked with fewer |
| 10911 |
than two arguments. */ |
| 10912 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 10913 |
c_parser_consume_token (parser); |
| 10914 |
c_inhibit_evaluation_warnings--; |
| 10915 |
result.set_error (); |
| 10916 |
return result; |
| 10917 |
} |
| 10918 |
|
| 10919 |
bool save_translate_strings_p = parser->translate_strings_p; |
| 10920 |
|
| 10921 |
location_t atloc = c_parser_peek_token (parser)->location; |
| 10922 |
/* Parse a single attribute. Require no leading comma and do not |
| 10923 |
allow empty attributes. */ |
| 10924 |
tree attr = c_parser_gnu_attribute (parser, NULL_TREE, false, false); |
| 10925 |
|
| 10926 |
parser->translate_strings_p = save_translate_strings_p; |
| 10927 |
|
| 10928 |
location_t finish = c_parser_peek_token (parser)->location; |
| 10929 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 10930 |
c_parser_consume_token (parser); |
| 10931 |
else |
| 10932 |
{ |
| 10933 |
c_parser_error (parser, "expected identifier"); |
| 10934 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 10935 |
|
| 10936 |
result.set_error (); |
| 10937 |
return result; |
| 10938 |
} |
| 10939 |
|
| 10940 |
if (!attr) |
| 10941 |
{ |
| 10942 |
error_at (atloc, "expected identifier"); |
| 10943 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 10944 |
"expected %<)%>"); |
| 10945 |
result.set_error (); |
| 10946 |
return result; |
| 10947 |
} |
| 10948 |
|
| 10949 |
result.original_code = INTEGER_CST; |
| 10950 |
result.original_type = boolean_type_node; |
| 10951 |
|
| 10952 |
if (has_attribute (atloc, oper, attr, default_conversion)) |
| 10953 |
result.value = boolean_true_node; |
| 10954 |
else |
| 10955 |
result.value = boolean_false_node; |
| 10956 |
|
| 10957 |
set_c_expr_source_range (&result, start, finish); |
| 10958 |
result.m_decimal = 0; |
| 10959 |
return result; |
| 10960 |
} |
| 10961 |
|
| 10962 |
/* Helper function to read arguments of builtins which are interfaces |
| 10963 |
for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and |
| 10964 |
others. The name of the builtin is passed using BNAME parameter. |
| 10965 |
Function returns true if there were no errors while parsing and |
| 10966 |
stores the arguments in CEXPR_LIST. If it returns true, |
| 10967 |
*OUT_CLOSE_PAREN_LOC is written to with the location of the closing |
| 10968 |
parenthesis. */ |
| 10969 |
static bool |
| 10970 |
c_parser_get_builtin_args (c_parser *parser, const char *bname, |
| 10971 |
vec<c_expr_t, va_gc> **ret_cexpr_list, |
| 10972 |
bool choose_expr_p, |
| 10973 |
location_t *out_close_paren_loc) |
| 10974 |
{ |
| 10975 |
location_t loc = c_parser_peek_token (parser)->location; |
| 10976 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 10977 |
c_expr_t expr; |
| 10978 |
bool saved_force_folding_builtin_constant_p; |
| 10979 |
|
| 10980 |
*ret_cexpr_list = NULL; |
| 10981 |
if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
| 10982 |
{ |
| 10983 |
error_at (loc, "cannot take address of %qs", bname); |
| 10984 |
return false; |
| 10985 |
} |
| 10986 |
|
| 10987 |
c_parser_consume_token (parser); |
| 10988 |
|
| 10989 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 10990 |
{ |
| 10991 |
*out_close_paren_loc = c_parser_peek_token (parser)->location; |
| 10992 |
c_parser_consume_token (parser); |
| 10993 |
return true; |
| 10994 |
} |
| 10995 |
|
| 10996 |
saved_force_folding_builtin_constant_p |
| 10997 |
= force_folding_builtin_constant_p; |
| 10998 |
force_folding_builtin_constant_p |= choose_expr_p; |
| 10999 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 11000 |
force_folding_builtin_constant_p |
| 11001 |
= saved_force_folding_builtin_constant_p; |
| 11002 |
vec_alloc (cexpr_list, 1); |
| 11003 |
vec_safe_push (cexpr_list, expr); |
| 11004 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 11005 |
{ |
| 11006 |
c_parser_consume_token (parser); |
| 11007 |
if (c_parser_next_token_is (parser, CPP_EMBED)) |
| 11008 |
{ |
| 11009 |
c_token *embed = c_parser_peek_token (parser); |
| 11010 |
tree value = embed->value; |
| 11011 |
expr.original_code = INTEGER_CST; |
| 11012 |
expr.original_type = integer_type_node; |
| 11013 |
expr.value = NULL_TREE; |
| 11014 |
set_c_expr_source_range (&expr, embed->get_range ()); |
| 11015 |
expr.m_decimal = 0; |
| 11016 |
for (unsigned int i = 0; i < (unsigned) RAW_DATA_LENGTH (value); i++) |
| 11017 |
{ |
| 11018 |
expr.value = build_int_cst (integer_type_node, |
| 11019 |
RAW_DATA_UCHAR_ELT (value, i)); |
| 11020 |
vec_safe_push (cexpr_list, expr); |
| 11021 |
} |
| 11022 |
c_parser_consume_token (parser); |
| 11023 |
continue; |
| 11024 |
} |
| 11025 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 11026 |
vec_safe_push (cexpr_list, expr); |
| 11027 |
} |
| 11028 |
|
| 11029 |
*out_close_paren_loc = c_parser_peek_token (parser)->location; |
| 11030 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 11031 |
return false; |
| 11032 |
|
| 11033 |
*ret_cexpr_list = cexpr_list; |
| 11034 |
return true; |
| 11035 |
} |
| 11036 |
|
| 11037 |
/* This represents a single generic-association. */ |
| 11038 |
|
| 11039 |
struct c_generic_association |
| 11040 |
{ |
| 11041 |
/* The location of the starting token of the type. */ |
| 11042 |
location_t type_location; |
| 11043 |
/* The association's type, or NULL_TREE for 'default'. */ |
| 11044 |
tree type; |
| 11045 |
/* The association's expression. */ |
| 11046 |
struct c_expr expression; |
| 11047 |
}; |
| 11048 |
|
| 11049 |
/* Parse a generic-selection. (C11 6.5.1.1). |
| 11050 |
|
| 11051 |
generic-selection: |
| 11052 |
_Generic ( generic-controlling-operand , generic-assoc-list ) |
| 11053 |
|
| 11054 |
generic-controlling-operand: |
| 11055 |
assignment-expression |
| 11056 |
type-name |
| 11057 |
|
| 11058 |
(The use of a type-name is new in C2Y.) |
| 11059 |
|
| 11060 |
generic-assoc-list: |
| 11061 |
generic-association |
| 11062 |
generic-assoc-list , generic-association |
| 11063 |
|
| 11064 |
generic-association: |
| 11065 |
type-name : assignment-expression |
| 11066 |
default : assignment-expression |
| 11067 |
*/ |
| 11068 |
|
| 11069 |
static struct c_expr |
| 11070 |
c_parser_generic_selection (c_parser *parser) |
| 11071 |
{ |
| 11072 |
struct c_expr selector, error_expr; |
| 11073 |
tree selector_type; |
| 11074 |
struct c_generic_association matched_assoc; |
| 11075 |
int match_found = -1; |
| 11076 |
location_t generic_loc, selector_loc; |
| 11077 |
|
| 11078 |
error_expr.original_code = ERROR_MARK; |
| 11079 |
error_expr.original_type = NULL; |
| 11080 |
error_expr.set_error (); |
| 11081 |
matched_assoc.type_location = UNKNOWN_LOCATION; |
| 11082 |
matched_assoc.type = NULL_TREE; |
| 11083 |
matched_assoc.expression = error_expr; |
| 11084 |
|
| 11085 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC)); |
| 11086 |
generic_loc = c_parser_peek_token (parser)->location; |
| 11087 |
c_parser_consume_token (parser); |
| 11088 |
if (flag_isoc99) |
| 11089 |
pedwarn_c99 (generic_loc, OPT_Wpedantic, |
| 11090 |
"ISO C99 does not support %<_Generic%>"); |
| 11091 |
else |
| 11092 |
pedwarn_c99 (generic_loc, OPT_Wpedantic, |
| 11093 |
"ISO C90 does not support %<_Generic%>"); |
| 11094 |
|
| 11095 |
matching_parens parens; |
| 11096 |
if (!parens.require_open (parser)) |
| 11097 |
return error_expr; |
| 11098 |
|
| 11099 |
selector_loc = c_parser_peek_token (parser)->location; |
| 11100 |
if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
| 11101 |
{ |
| 11102 |
c_inhibit_evaluation_warnings++; |
| 11103 |
pedwarn_c23 (selector_loc, OPT_Wpedantic, |
| 11104 |
"ISO C does not support use of type name as %<_Generic%> " |
| 11105 |
"controlling operand before C2Y"); |
| 11106 |
struct c_type_name *type = c_parser_type_name (parser); |
| 11107 |
selector_type = groktypename (type, NULL, NULL); |
| 11108 |
c_inhibit_evaluation_warnings--; |
| 11109 |
} |
| 11110 |
else |
| 11111 |
{ |
| 11112 |
c_inhibit_evaluation_warnings++; |
| 11113 |
selector = c_parser_expr_no_commas (parser, NULL); |
| 11114 |
selector = default_function_array_conversion (selector_loc, selector); |
| 11115 |
c_inhibit_evaluation_warnings--; |
| 11116 |
|
| 11117 |
if (selector.value == error_mark_node) |
| 11118 |
{ |
| 11119 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11120 |
return selector; |
| 11121 |
} |
| 11122 |
mark_exp_read (selector.value); |
| 11123 |
selector_type = TREE_TYPE (selector.value); |
| 11124 |
/* In ISO C terms, rvalues (including the controlling expression |
| 11125 |
of _Generic) do not have qualified types. */ |
| 11126 |
if (TREE_CODE (selector_type) != ARRAY_TYPE) |
| 11127 |
selector_type = TYPE_MAIN_VARIANT (selector_type); |
| 11128 |
/* In ISO C terms, _Noreturn is not part of the type of expressions |
| 11129 |
such as &abort, but in GCC it is represented internally as a type |
| 11130 |
qualifier. */ |
| 11131 |
if (FUNCTION_POINTER_TYPE_P (selector_type) |
| 11132 |
&& TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED) |
| 11133 |
selector_type |
| 11134 |
= c_build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); |
| 11135 |
} |
| 11136 |
|
| 11137 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 11138 |
{ |
| 11139 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11140 |
return error_expr; |
| 11141 |
} |
| 11142 |
|
| 11143 |
auto_vec<c_generic_association> associations; |
| 11144 |
while (1) |
| 11145 |
{ |
| 11146 |
struct c_generic_association assoc, *iter; |
| 11147 |
unsigned int ix; |
| 11148 |
c_token *token = c_parser_peek_token (parser); |
| 11149 |
|
| 11150 |
assoc.type_location = token->location; |
| 11151 |
if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT) |
| 11152 |
{ |
| 11153 |
c_parser_consume_token (parser); |
| 11154 |
assoc.type = NULL_TREE; |
| 11155 |
} |
| 11156 |
else |
| 11157 |
{ |
| 11158 |
struct c_type_name *type_name; |
| 11159 |
|
| 11160 |
type_name = c_parser_type_name (parser); |
| 11161 |
if (type_name == NULL) |
| 11162 |
{ |
| 11163 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11164 |
return error_expr; |
| 11165 |
} |
| 11166 |
assoc.type = groktypename (type_name, NULL, NULL); |
| 11167 |
if (assoc.type == error_mark_node) |
| 11168 |
{ |
| 11169 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11170 |
return error_expr; |
| 11171 |
} |
| 11172 |
|
| 11173 |
if (TREE_CODE (assoc.type) == FUNCTION_TYPE) |
| 11174 |
pedwarn_c23 (assoc.type_location, OPT_Wpedantic, |
| 11175 |
"ISO C does not support %<_Generic%> association with " |
| 11176 |
"function type before C2Y"); |
| 11177 |
else if (!COMPLETE_TYPE_P (assoc.type)) |
| 11178 |
pedwarn_c23 (assoc.type_location, OPT_Wpedantic, |
| 11179 |
"ISO C does not support %<_Generic%> association with " |
| 11180 |
"incomplete type before C2Y"); |
| 11181 |
|
| 11182 |
if (c_type_variably_modified_p (assoc.type)) |
| 11183 |
error_at (assoc.type_location, |
| 11184 |
"%<_Generic%> association has " |
| 11185 |
"variable length type"); |
| 11186 |
} |
| 11187 |
|
| 11188 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 11189 |
{ |
| 11190 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11191 |
return error_expr; |
| 11192 |
} |
| 11193 |
|
| 11194 |
bool match = assoc.type == NULL_TREE |
| 11195 |
|| comptypes (assoc.type, selector_type); |
| 11196 |
|
| 11197 |
if (!match) |
| 11198 |
c_inhibit_evaluation_warnings++; |
| 11199 |
|
| 11200 |
assoc.expression = c_parser_expr_no_commas (parser, NULL); |
| 11201 |
|
| 11202 |
if (!match) |
| 11203 |
c_inhibit_evaluation_warnings--; |
| 11204 |
|
| 11205 |
if (assoc.expression.value == error_mark_node) |
| 11206 |
{ |
| 11207 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11208 |
return error_expr; |
| 11209 |
} |
| 11210 |
|
| 11211 |
for (ix = 0; associations.iterate (ix, &iter); ++ix) |
| 11212 |
{ |
| 11213 |
if (assoc.type == NULL_TREE) |
| 11214 |
{ |
| 11215 |
if (iter->type == NULL_TREE) |
| 11216 |
{ |
| 11217 |
error_at (assoc.type_location, |
| 11218 |
"duplicate %<default%> case in %<_Generic%>"); |
| 11219 |
inform (iter->type_location, "original %<default%> is here"); |
| 11220 |
} |
| 11221 |
} |
| 11222 |
else if (iter->type != NULL_TREE) |
| 11223 |
{ |
| 11224 |
if (comptypes (assoc.type, iter->type)) |
| 11225 |
{ |
| 11226 |
error_at (assoc.type_location, |
| 11227 |
"%<_Generic%> specifies two compatible types"); |
| 11228 |
inform (iter->type_location, "compatible type is here"); |
| 11229 |
} |
| 11230 |
} |
| 11231 |
} |
| 11232 |
|
| 11233 |
if (assoc.type == NULL_TREE) |
| 11234 |
{ |
| 11235 |
if (match_found < 0) |
| 11236 |
{ |
| 11237 |
matched_assoc = assoc; |
| 11238 |
match_found = associations.length (); |
| 11239 |
} |
| 11240 |
} |
| 11241 |
else if (match) |
| 11242 |
{ |
| 11243 |
if (match_found < 0 || matched_assoc.type == NULL_TREE) |
| 11244 |
{ |
| 11245 |
matched_assoc = assoc; |
| 11246 |
match_found = associations.length (); |
| 11247 |
} |
| 11248 |
else |
| 11249 |
{ |
| 11250 |
error_at (assoc.type_location, |
| 11251 |
"%<_Generic%> selector matches multiple associations"); |
| 11252 |
inform (matched_assoc.type_location, |
| 11253 |
"other match is here"); |
| 11254 |
} |
| 11255 |
} |
| 11256 |
|
| 11257 |
associations.safe_push (assoc); |
| 11258 |
|
| 11259 |
if (c_parser_peek_token (parser)->type != CPP_COMMA) |
| 11260 |
break; |
| 11261 |
c_parser_consume_token (parser); |
| 11262 |
} |
| 11263 |
|
| 11264 |
unsigned int ix; |
| 11265 |
struct c_generic_association *iter; |
| 11266 |
FOR_EACH_VEC_ELT (associations, ix, iter) |
| 11267 |
if (ix != (unsigned) match_found) |
| 11268 |
mark_exp_read (iter->expression.value); |
| 11269 |
|
| 11270 |
if (!parens.require_close (parser)) |
| 11271 |
{ |
| 11272 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11273 |
return error_expr; |
| 11274 |
} |
| 11275 |
|
| 11276 |
if (match_found < 0) |
| 11277 |
{ |
| 11278 |
error_at (selector_loc, "%<_Generic%> selector of type %qT is not " |
| 11279 |
"compatible with any association", |
| 11280 |
selector_type); |
| 11281 |
return error_expr; |
| 11282 |
} |
| 11283 |
|
| 11284 |
return matched_assoc.expression; |
| 11285 |
} |
| 11286 |
|
| 11287 |
/* Check the validity of a function pointer argument *EXPR (argument |
| 11288 |
position POS) to __builtin_tgmath. Return the number of function |
| 11289 |
arguments if possibly valid; return 0 having reported an error if |
| 11290 |
not valid. */ |
| 11291 |
|
| 11292 |
static unsigned int |
| 11293 |
check_tgmath_function (c_expr *expr, unsigned int pos) |
| 11294 |
{ |
| 11295 |
tree type = TREE_TYPE (expr->value); |
| 11296 |
if (!FUNCTION_POINTER_TYPE_P (type)) |
| 11297 |
{ |
| 11298 |
error_at (expr->get_location (), |
| 11299 |
"argument %u of %<__builtin_tgmath%> is not a function pointer", |
| 11300 |
pos); |
| 11301 |
return 0; |
| 11302 |
} |
| 11303 |
type = TREE_TYPE (type); |
| 11304 |
if (!prototype_p (type)) |
| 11305 |
{ |
| 11306 |
error_at (expr->get_location (), |
| 11307 |
"argument %u of %<__builtin_tgmath%> is unprototyped", pos); |
| 11308 |
return 0; |
| 11309 |
} |
| 11310 |
if (stdarg_p (type)) |
| 11311 |
{ |
| 11312 |
error_at (expr->get_location (), |
| 11313 |
"argument %u of %<__builtin_tgmath%> has variable arguments", |
| 11314 |
pos); |
| 11315 |
return 0; |
| 11316 |
} |
| 11317 |
unsigned int nargs = 0; |
| 11318 |
function_args_iterator iter; |
| 11319 |
tree t; |
| 11320 |
FOREACH_FUNCTION_ARGS (type, t, iter) |
| 11321 |
{ |
| 11322 |
if (t == void_type_node) |
| 11323 |
break; |
| 11324 |
nargs++; |
| 11325 |
} |
| 11326 |
if (nargs == 0) |
| 11327 |
{ |
| 11328 |
error_at (expr->get_location (), |
| 11329 |
"argument %u of %<__builtin_tgmath%> has no arguments", pos); |
| 11330 |
return 0; |
| 11331 |
} |
| 11332 |
return nargs; |
| 11333 |
} |
| 11334 |
|
| 11335 |
/* Ways in which a parameter or return value of a type-generic macro |
| 11336 |
may vary between the different functions the macro may call. */ |
| 11337 |
enum tgmath_parm_kind |
| 11338 |
{ |
| 11339 |
tgmath_fixed, tgmath_real, tgmath_complex |
| 11340 |
}; |
| 11341 |
|
| 11342 |
/* Helper function for c_parser_postfix_expression. Parse predefined |
| 11343 |
identifiers. */ |
| 11344 |
|
| 11345 |
static struct c_expr |
| 11346 |
c_parser_predefined_identifier (c_parser *parser) |
| 11347 |
{ |
| 11348 |
location_t loc = c_parser_peek_token (parser)->location; |
| 11349 |
switch (c_parser_peek_token (parser)->keyword) |
| 11350 |
{ |
| 11351 |
case RID_FUNCTION_NAME: |
| 11352 |
pedwarn (loc, OPT_Wpedantic, "ISO C does not support %qs predefined " |
| 11353 |
"identifier", "__FUNCTION__"); |
| 11354 |
break; |
| 11355 |
case RID_PRETTY_FUNCTION_NAME: |
| 11356 |
pedwarn (loc, OPT_Wpedantic, "ISO C does not support %qs predefined " |
| 11357 |
"identifier", "__PRETTY_FUNCTION__"); |
| 11358 |
break; |
| 11359 |
case RID_C99_FUNCTION_NAME: |
| 11360 |
pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support " |
| 11361 |
"%<__func__%> predefined identifier"); |
| 11362 |
break; |
| 11363 |
default: |
| 11364 |
gcc_unreachable (); |
| 11365 |
} |
| 11366 |
|
| 11367 |
struct c_expr expr; |
| 11368 |
expr.original_code = ERROR_MARK; |
| 11369 |
expr.original_type = NULL; |
| 11370 |
expr.value = fname_decl (loc, c_parser_peek_token (parser)->keyword, |
| 11371 |
c_parser_peek_token (parser)->value); |
| 11372 |
set_c_expr_source_range (&expr, loc, loc); |
| 11373 |
expr.m_decimal = 0; |
| 11374 |
c_parser_consume_token (parser); |
| 11375 |
return expr; |
| 11376 |
} |
| 11377 |
|
| 11378 |
/* Check whether the ARRAY_REF has an counted-by object associated with it |
| 11379 |
through the "counted_by" attribute. */ |
| 11380 |
|
| 11381 |
static bool |
| 11382 |
has_counted_by_object (tree array_ref) |
| 11383 |
{ |
| 11384 |
/* Currently, only when the array_ref is an indirect_ref to a call to the |
| 11385 |
.ACCESS_WITH_SIZE, return true. |
| 11386 |
More cases can be included later when the counted_by attribute is |
| 11387 |
extended to other situations. */ |
| 11388 |
if (TREE_CODE (array_ref) == INDIRECT_REF |
| 11389 |
&& is_access_with_size_p (TREE_OPERAND (array_ref, 0))) |
| 11390 |
return true; |
| 11391 |
return false; |
| 11392 |
} |
| 11393 |
|
| 11394 |
/* Get the reference to the counted-by object associated with the ARRAY_REF. */ |
| 11395 |
|
| 11396 |
static tree |
| 11397 |
get_counted_by_ref (tree array_ref) |
| 11398 |
{ |
| 11399 |
/* Currently, only when the array_ref is an indirect_ref to a call to the |
| 11400 |
.ACCESS_WITH_SIZE, get the corresponding counted_by ref. |
| 11401 |
More cases can be included later when the counted_by attribute is |
| 11402 |
extended to other situations. */ |
| 11403 |
if (TREE_CODE (array_ref) == INDIRECT_REF |
| 11404 |
&& is_access_with_size_p (TREE_OPERAND (array_ref, 0))) |
| 11405 |
return CALL_EXPR_ARG (TREE_OPERAND (array_ref, 0), 1); |
| 11406 |
return NULL_TREE; |
| 11407 |
} |
| 11408 |
|
| 11409 |
/* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2, |
| 11410 |
C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to |
| 11411 |
call c_parser_postfix_expression_after_paren_type on encountering them. |
| 11412 |
|
| 11413 |
postfix-expression: |
| 11414 |
primary-expression |
| 11415 |
postfix-expression [ expression ] |
| 11416 |
postfix-expression ( argument-expression-list[opt] ) |
| 11417 |
postfix-expression . identifier |
| 11418 |
postfix-expression -> identifier |
| 11419 |
postfix-expression ++ |
| 11420 |
postfix-expression -- |
| 11421 |
( storage-class-specifiers[opt] type-name ) { initializer-list[opt] } |
| 11422 |
( storage-class-specifiers[opt] type-name ) { initializer-list , } |
| 11423 |
|
| 11424 |
argument-expression-list: |
| 11425 |
argument-expression |
| 11426 |
argument-expression-list , argument-expression |
| 11427 |
|
| 11428 |
primary-expression: |
| 11429 |
identifier |
| 11430 |
constant |
| 11431 |
string-literal |
| 11432 |
( expression ) |
| 11433 |
generic-selection |
| 11434 |
|
| 11435 |
GNU extensions: |
| 11436 |
|
| 11437 |
primary-expression: |
| 11438 |
__func__ |
| 11439 |
(treated as a keyword in GNU C) |
| 11440 |
__FUNCTION__ |
| 11441 |
__PRETTY_FUNCTION__ |
| 11442 |
( compound-statement ) |
| 11443 |
__builtin_va_arg ( assignment-expression , type-name ) |
| 11444 |
__builtin_offsetof ( type-name , offsetof-member-designator ) |
| 11445 |
__builtin_choose_expr ( assignment-expression , |
| 11446 |
assignment-expression , |
| 11447 |
assignment-expression ) |
| 11448 |
__builtin_types_compatible_p ( type-name , type-name ) |
| 11449 |
__builtin_tgmath ( expr-list ) |
| 11450 |
__builtin_complex ( assignment-expression , assignment-expression ) |
| 11451 |
__builtin_shuffle ( assignment-expression , assignment-expression ) |
| 11452 |
__builtin_shuffle ( assignment-expression , |
| 11453 |
assignment-expression , |
| 11454 |
assignment-expression, ) |
| 11455 |
__builtin_convertvector ( assignment-expression , type-name ) |
| 11456 |
__builtin_assoc_barrier ( assignment-expression ) |
| 11457 |
|
| 11458 |
offsetof-member-designator: |
| 11459 |
identifier |
| 11460 |
offsetof-member-designator . identifier |
| 11461 |
offsetof-member-designator [ expression ] |
| 11462 |
|
| 11463 |
Objective-C: |
| 11464 |
|
| 11465 |
primary-expression: |
| 11466 |
[ objc-receiver objc-message-args ] |
| 11467 |
@selector ( objc-selector-arg ) |
| 11468 |
@protocol ( identifier ) |
| 11469 |
@encode ( type-name ) |
| 11470 |
objc-string-literal |
| 11471 |
Classname . identifier |
| 11472 |
*/ |
| 11473 |
|
| 11474 |
static struct c_expr |
| 11475 |
c_parser_postfix_expression (c_parser *parser) |
| 11476 |
{ |
| 11477 |
struct c_expr expr, e1; |
| 11478 |
struct c_type_name *t1, *t2; |
| 11479 |
location_t loc = c_parser_peek_token (parser)->location; |
| 11480 |
source_range tok_range = c_parser_peek_token (parser)->get_range (); |
| 11481 |
expr.original_code = ERROR_MARK; |
| 11482 |
expr.original_type = NULL; |
| 11483 |
expr.m_decimal = 0; |
| 11484 |
switch (c_parser_peek_token (parser)->type) |
| 11485 |
{ |
| 11486 |
case CPP_NUMBER: |
| 11487 |
expr.value = c_parser_peek_token (parser)->value; |
| 11488 |
set_c_expr_source_range (&expr, tok_range); |
| 11489 |
loc = c_parser_peek_token (parser)->location; |
| 11490 |
expr.m_decimal = c_parser_peek_token (parser)->flags & DECIMAL_INT; |
| 11491 |
c_parser_consume_token (parser); |
| 11492 |
if (TREE_CODE (expr.value) == FIXED_CST |
| 11493 |
&& !targetm.fixed_point_supported_p ()) |
| 11494 |
{ |
| 11495 |
error_at (loc, "fixed-point types not supported for this target"); |
| 11496 |
expr.set_error (); |
| 11497 |
} |
| 11498 |
break; |
| 11499 |
case CPP_CHAR: |
| 11500 |
case CPP_CHAR16: |
| 11501 |
case CPP_CHAR32: |
| 11502 |
case CPP_UTF8CHAR: |
| 11503 |
case CPP_WCHAR: |
| 11504 |
expr.value = c_parser_peek_token (parser)->value; |
| 11505 |
/* For the purpose of warning when a pointer is compared with |
| 11506 |
a zero character constant. */ |
| 11507 |
expr.original_type = char_type_node; |
| 11508 |
set_c_expr_source_range (&expr, tok_range); |
| 11509 |
c_parser_consume_token (parser); |
| 11510 |
break; |
| 11511 |
case CPP_STRING: |
| 11512 |
case CPP_STRING16: |
| 11513 |
case CPP_STRING32: |
| 11514 |
case CPP_WSTRING: |
| 11515 |
case CPP_UTF8STRING: |
| 11516 |
expr = c_parser_string_literal (parser, parser->translate_strings_p, |
| 11517 |
true); |
| 11518 |
break; |
| 11519 |
case CPP_OBJC_STRING: |
| 11520 |
gcc_assert (c_dialect_objc ()); |
| 11521 |
expr.value |
| 11522 |
= objc_build_string_object (c_parser_peek_token (parser)->value); |
| 11523 |
set_c_expr_source_range (&expr, tok_range); |
| 11524 |
c_parser_consume_token (parser); |
| 11525 |
break; |
| 11526 |
case CPP_NAME: |
| 11527 |
switch (c_parser_peek_token (parser)->id_kind) |
| 11528 |
{ |
| 11529 |
case C_ID_ID: |
| 11530 |
{ |
| 11531 |
tree id = c_parser_peek_token (parser)->value; |
| 11532 |
c_parser_consume_token (parser); |
| 11533 |
expr.value = build_external_ref (loc, id, |
| 11534 |
(c_parser_peek_token (parser)->type |
| 11535 |
== CPP_OPEN_PAREN), |
| 11536 |
&expr.original_type); |
| 11537 |
set_c_expr_source_range (&expr, tok_range); |
| 11538 |
break; |
| 11539 |
} |
| 11540 |
case C_ID_CLASSNAME: |
| 11541 |
{ |
| 11542 |
/* Here we parse the Objective-C 2.0 Class.name dot |
| 11543 |
syntax. */ |
| 11544 |
tree class_name = c_parser_peek_token (parser)->value; |
| 11545 |
tree component; |
| 11546 |
c_parser_consume_token (parser); |
| 11547 |
gcc_assert (c_dialect_objc ()); |
| 11548 |
if (!c_parser_require (parser, CPP_DOT, "expected %<.%>")) |
| 11549 |
{ |
| 11550 |
expr.set_error (); |
| 11551 |
break; |
| 11552 |
} |
| 11553 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 11554 |
{ |
| 11555 |
c_parser_error (parser, "expected identifier"); |
| 11556 |
expr.set_error (); |
| 11557 |
break; |
| 11558 |
} |
| 11559 |
c_token *component_tok = c_parser_peek_token (parser); |
| 11560 |
component = component_tok->value; |
| 11561 |
location_t end_loc = component_tok->get_finish (); |
| 11562 |
c_parser_consume_token (parser); |
| 11563 |
expr.value = objc_build_class_component_ref (class_name, |
| 11564 |
component); |
| 11565 |
set_c_expr_source_range (&expr, loc, end_loc); |
| 11566 |
break; |
| 11567 |
} |
| 11568 |
default: |
| 11569 |
c_parser_error (parser, "expected expression"); |
| 11570 |
expr.set_error (); |
| 11571 |
break; |
| 11572 |
} |
| 11573 |
break; |
| 11574 |
case CPP_OPEN_PAREN: |
| 11575 |
/* A parenthesized expression, statement expression or compound |
| 11576 |
literal. */ |
| 11577 |
if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) |
| 11578 |
{ |
| 11579 |
/* A statement expression. */ |
| 11580 |
tree stmt; |
| 11581 |
location_t brace_loc; |
| 11582 |
bool save_c_omp_array_section_p = c_omp_array_section_p; |
| 11583 |
c_parser_consume_token (parser); |
| 11584 |
brace_loc = c_parser_peek_token (parser)->location; |
| 11585 |
c_parser_consume_token (parser); |
| 11586 |
/* If we've not yet started the current function's statement list, |
| 11587 |
or we're in the parameter scope of an old-style function |
| 11588 |
declaration, statement expressions are not allowed. */ |
| 11589 |
if (!building_stmt_list_p () || old_style_parameter_scope ()) |
| 11590 |
{ |
| 11591 |
error_at (loc, "braced-group within expression allowed " |
| 11592 |
"only inside a function"); |
| 11593 |
parser->error = true; |
| 11594 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 11595 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11596 |
expr.set_error (); |
| 11597 |
break; |
| 11598 |
} |
| 11599 |
c_omp_array_section_p = false; |
| 11600 |
stmt = c_begin_stmt_expr (); |
| 11601 |
c_parser_compound_statement_nostart (parser); |
| 11602 |
location_t close_loc = c_parser_peek_token (parser)->location; |
| 11603 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 11604 |
"expected %<)%>"); |
| 11605 |
pedwarn (loc, OPT_Wpedantic, |
| 11606 |
"ISO C forbids braced-groups within expressions"); |
| 11607 |
expr.value = c_finish_stmt_expr (brace_loc, stmt); |
| 11608 |
set_c_expr_source_range (&expr, loc, close_loc); |
| 11609 |
mark_exp_read (expr.value); |
| 11610 |
c_omp_array_section_p = save_c_omp_array_section_p; |
| 11611 |
} |
| 11612 |
else |
| 11613 |
{ |
| 11614 |
/* A parenthesized expression. */ |
| 11615 |
location_t loc_open_paren = c_parser_peek_token (parser)->location; |
| 11616 |
c_parser_consume_token (parser); |
| 11617 |
expr = c_parser_expression (parser); |
| 11618 |
if (TREE_CODE (expr.value) == MODIFY_EXPR) |
| 11619 |
suppress_warning (expr.value, OPT_Wparentheses); |
| 11620 |
if (expr.original_code != C_MAYBE_CONST_EXPR |
| 11621 |
&& expr.original_code != SIZEOF_EXPR) |
| 11622 |
expr.original_code = ERROR_MARK; |
| 11623 |
/* Remember that we saw ( ) around the sizeof. */ |
| 11624 |
if (expr.original_code == SIZEOF_EXPR) |
| 11625 |
expr.original_code = PAREN_SIZEOF_EXPR; |
| 11626 |
/* Don't change EXPR.ORIGINAL_TYPE. */ |
| 11627 |
location_t loc_close_paren = c_parser_peek_token (parser)->location; |
| 11628 |
set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren); |
| 11629 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 11630 |
"expected %<)%>", loc_open_paren); |
| 11631 |
} |
| 11632 |
break; |
| 11633 |
case CPP_KEYWORD: |
| 11634 |
switch (c_parser_peek_token (parser)->keyword) |
| 11635 |
{ |
| 11636 |
case RID_FUNCTION_NAME: |
| 11637 |
case RID_PRETTY_FUNCTION_NAME: |
| 11638 |
case RID_C99_FUNCTION_NAME: |
| 11639 |
expr = c_parser_predefined_identifier (parser); |
| 11640 |
break; |
| 11641 |
case RID_VA_ARG: |
| 11642 |
{ |
| 11643 |
location_t start_loc = loc; |
| 11644 |
c_parser_consume_token (parser); |
| 11645 |
matching_parens parens; |
| 11646 |
if (!parens.require_open (parser)) |
| 11647 |
{ |
| 11648 |
expr.set_error (); |
| 11649 |
break; |
| 11650 |
} |
| 11651 |
e1 = c_parser_expr_no_commas (parser, NULL); |
| 11652 |
mark_exp_read (e1.value); |
| 11653 |
e1.value = c_fully_fold (e1.value, false, NULL); |
| 11654 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 11655 |
{ |
| 11656 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11657 |
expr.set_error (); |
| 11658 |
break; |
| 11659 |
} |
| 11660 |
loc = c_parser_peek_token (parser)->location; |
| 11661 |
t1 = c_parser_type_name (parser); |
| 11662 |
location_t end_loc = c_parser_peek_token (parser)->get_finish (); |
| 11663 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 11664 |
"expected %<)%>"); |
| 11665 |
if (t1 == NULL) |
| 11666 |
{ |
| 11667 |
expr.set_error (); |
| 11668 |
} |
| 11669 |
else |
| 11670 |
{ |
| 11671 |
tree type_expr = NULL_TREE; |
| 11672 |
expr.value = c_build_va_arg (start_loc, e1.value, loc, |
| 11673 |
groktypename (t1, &type_expr, NULL)); |
| 11674 |
if (type_expr) |
| 11675 |
{ |
| 11676 |
expr.value = build2 (C_MAYBE_CONST_EXPR, |
| 11677 |
TREE_TYPE (expr.value), type_expr, |
| 11678 |
expr.value); |
| 11679 |
C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true; |
| 11680 |
} |
| 11681 |
set_c_expr_source_range (&expr, start_loc, end_loc); |
| 11682 |
} |
| 11683 |
} |
| 11684 |
break; |
| 11685 |
case RID_C23_VA_START: |
| 11686 |
{ |
| 11687 |
c_parser_consume_token (parser); |
| 11688 |
matching_parens parens; |
| 11689 |
if (!parens.require_open (parser)) |
| 11690 |
{ |
| 11691 |
expr.set_error (); |
| 11692 |
break; |
| 11693 |
} |
| 11694 |
e1 = c_parser_expr_no_commas (parser, NULL); |
| 11695 |
e1 = convert_lvalue_to_rvalue (e1.get_location (), e1, true, true); |
| 11696 |
if (!c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 11697 |
{ |
| 11698 |
location_t cloc = c_parser_peek_token (parser)->location; |
| 11699 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 11700 |
{ |
| 11701 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11702 |
expr.set_error (); |
| 11703 |
break; |
| 11704 |
} |
| 11705 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 11706 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 11707 |
&& (c_parser_peek_2nd_token (parser)->type |
| 11708 |
== CPP_CLOSE_PAREN)) |
| 11709 |
{ |
| 11710 |
tree name = c_parser_peek_token (parser)->value; |
| 11711 |
location_t nloc = c_parser_peek_token (parser)->location; |
| 11712 |
tree decl = lookup_name (name); |
| 11713 |
tree last_parm |
| 11714 |
= tree_last (DECL_ARGUMENTS (current_function_decl)); |
| 11715 |
if (!last_parm || decl != last_parm) |
| 11716 |
warning_at (nloc, OPT_Wvarargs, |
| 11717 |
"optional second parameter of %<va_start%> " |
| 11718 |
"not last named argument"); |
| 11719 |
else if (DECL_REGISTER (decl)) |
| 11720 |
warning_at (nloc, OPT_Wvarargs, |
| 11721 |
"undefined behavior when second parameter " |
| 11722 |
"of %<va_start%> is declared with " |
| 11723 |
"%<register%> storage"); |
| 11724 |
c_parser_consume_token (parser); |
| 11725 |
} |
| 11726 |
else |
| 11727 |
{ |
| 11728 |
unsigned nesting_depth = 0; |
| 11729 |
location_t sloc = c_parser_peek_token (parser)->location; |
| 11730 |
location_t eloc = sloc; |
| 11731 |
|
| 11732 |
/* For va_start (ap,) the ) comes from stdarg.h. |
| 11733 |
Use location of , in that case, otherwise without |
| 11734 |
-Wsystem-headers nothing is reported. After all, |
| 11735 |
the problematic token is the comma in that case. */ |
| 11736 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 11737 |
sloc = eloc = cloc; |
| 11738 |
while (true) |
| 11739 |
{ |
| 11740 |
c_token *token = c_parser_peek_token (parser); |
| 11741 |
if (token->type == CPP_CLOSE_PAREN && !nesting_depth) |
| 11742 |
break; |
| 11743 |
|
| 11744 |
if (token->type == CPP_EOF) |
| 11745 |
break; |
| 11746 |
if (token->type == CPP_OPEN_PAREN) |
| 11747 |
++nesting_depth; |
| 11748 |
else if (token->type == CPP_CLOSE_PAREN) |
| 11749 |
--nesting_depth; |
| 11750 |
eloc = token->location; |
| 11751 |
c_parser_consume_token (parser); |
| 11752 |
} |
| 11753 |
if (sloc != eloc) |
| 11754 |
sloc = make_location (sloc, sloc, eloc); |
| 11755 |
warning_at (sloc, OPT_Wvarargs, |
| 11756 |
"%<va_start%> macro used with additional " |
| 11757 |
"arguments other than identifier of the " |
| 11758 |
"last named argument"); |
| 11759 |
} |
| 11760 |
} |
| 11761 |
parens.skip_until_found_close (parser); |
| 11762 |
tree fndecl = builtin_decl_explicit (BUILT_IN_VA_START); |
| 11763 |
vec<tree, va_gc> *params; |
| 11764 |
vec_alloc (params, 2); |
| 11765 |
params->quick_push (e1.value); |
| 11766 |
params->quick_push (integer_zero_node); |
| 11767 |
auto_vec<location_t> arg_loc (2); |
| 11768 |
arg_loc.quick_push (e1.get_location ()); |
| 11769 |
arg_loc.quick_push (UNKNOWN_LOCATION); |
| 11770 |
expr.value = c_build_function_call_vec (loc, arg_loc, fndecl, |
| 11771 |
params, NULL); |
| 11772 |
set_c_expr_source_range (&expr, loc, |
| 11773 |
parser->tokens_buf[0].get_finish ()); |
| 11774 |
expr.m_decimal = 0; |
| 11775 |
expr.original_code = ERROR_MARK; |
| 11776 |
expr.original_type = NULL; |
| 11777 |
release_tree_vector (params); |
| 11778 |
break; |
| 11779 |
} |
| 11780 |
case RID_OFFSETOF: |
| 11781 |
{ |
| 11782 |
c_parser_consume_token (parser); |
| 11783 |
matching_parens parens; |
| 11784 |
if (!parens.require_open (parser)) |
| 11785 |
{ |
| 11786 |
expr.set_error (); |
| 11787 |
break; |
| 11788 |
} |
| 11789 |
t1 = c_parser_type_name (parser); |
| 11790 |
if (t1 == NULL) |
| 11791 |
parser->error = true; |
| 11792 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 11793 |
gcc_assert (parser->error); |
| 11794 |
if (parser->error) |
| 11795 |
{ |
| 11796 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11797 |
expr.set_error (); |
| 11798 |
break; |
| 11799 |
} |
| 11800 |
tree type = groktypename (t1, NULL, NULL); |
| 11801 |
tree offsetof_ref; |
| 11802 |
if (type == error_mark_node) |
| 11803 |
offsetof_ref = error_mark_node; |
| 11804 |
else |
| 11805 |
{ |
| 11806 |
offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node); |
| 11807 |
SET_EXPR_LOCATION (offsetof_ref, loc); |
| 11808 |
} |
| 11809 |
/* Parse the second argument to __builtin_offsetof. We |
| 11810 |
must have one identifier, and beyond that we want to |
| 11811 |
accept sub structure and sub array references. */ |
| 11812 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 11813 |
{ |
| 11814 |
c_token *comp_tok = c_parser_peek_token (parser); |
| 11815 |
/* Ignore the counted_by attribute for reference inside |
| 11816 |
offsetof since the information is not useful at all. */ |
| 11817 |
offsetof_ref |
| 11818 |
= build_component_ref (loc, offsetof_ref, comp_tok->value, |
| 11819 |
comp_tok->location, UNKNOWN_LOCATION, |
| 11820 |
false); |
| 11821 |
c_parser_consume_token (parser); |
| 11822 |
while (c_parser_next_token_is (parser, CPP_DOT) |
| 11823 |
|| c_parser_next_token_is (parser, |
| 11824 |
CPP_OPEN_SQUARE) |
| 11825 |
|| c_parser_next_token_is (parser, |
| 11826 |
CPP_DEREF)) |
| 11827 |
{ |
| 11828 |
if (c_parser_next_token_is (parser, CPP_DEREF)) |
| 11829 |
{ |
| 11830 |
loc = c_parser_peek_token (parser)->location; |
| 11831 |
offsetof_ref = build_array_ref (loc, |
| 11832 |
offsetof_ref, |
| 11833 |
integer_zero_node); |
| 11834 |
goto do_dot; |
| 11835 |
} |
| 11836 |
else if (c_parser_next_token_is (parser, CPP_DOT)) |
| 11837 |
{ |
| 11838 |
do_dot: |
| 11839 |
c_parser_consume_token (parser); |
| 11840 |
if (c_parser_next_token_is_not (parser, |
| 11841 |
CPP_NAME)) |
| 11842 |
{ |
| 11843 |
c_parser_error (parser, "expected identifier"); |
| 11844 |
break; |
| 11845 |
} |
| 11846 |
c_token *comp_tok = c_parser_peek_token (parser); |
| 11847 |
/* Ignore the counted_by attribute for reference inside |
| 11848 |
offsetof since the information is not useful. */ |
| 11849 |
offsetof_ref |
| 11850 |
= build_component_ref (loc, offsetof_ref, |
| 11851 |
comp_tok->value, |
| 11852 |
comp_tok->location, |
| 11853 |
UNKNOWN_LOCATION, |
| 11854 |
false); |
| 11855 |
c_parser_consume_token (parser); |
| 11856 |
} |
| 11857 |
else |
| 11858 |
{ |
| 11859 |
struct c_expr ce; |
| 11860 |
tree idx; |
| 11861 |
loc = c_parser_peek_token (parser)->location; |
| 11862 |
c_parser_consume_token (parser); |
| 11863 |
ce = c_parser_expression (parser); |
| 11864 |
ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 11865 |
idx = ce.value; |
| 11866 |
idx = c_fully_fold (idx, false, NULL); |
| 11867 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 11868 |
"expected %<]%>"); |
| 11869 |
offsetof_ref = build_array_ref (loc, offsetof_ref, idx); |
| 11870 |
} |
| 11871 |
} |
| 11872 |
} |
| 11873 |
else |
| 11874 |
c_parser_error (parser, "expected identifier"); |
| 11875 |
location_t end_loc = c_parser_peek_token (parser)->get_finish (); |
| 11876 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 11877 |
"expected %<)%>"); |
| 11878 |
expr.value = fold_offsetof (offsetof_ref); |
| 11879 |
set_c_expr_source_range (&expr, loc, end_loc); |
| 11880 |
} |
| 11881 |
break; |
| 11882 |
case RID_CHOOSE_EXPR: |
| 11883 |
{ |
| 11884 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 11885 |
c_expr_t *e1_p, *e2_p, *e3_p; |
| 11886 |
tree c; |
| 11887 |
location_t close_paren_loc; |
| 11888 |
|
| 11889 |
c_parser_consume_token (parser); |
| 11890 |
if (!c_parser_get_builtin_args (parser, |
| 11891 |
"__builtin_choose_expr", |
| 11892 |
&cexpr_list, true, |
| 11893 |
&close_paren_loc)) |
| 11894 |
{ |
| 11895 |
expr.set_error (); |
| 11896 |
break; |
| 11897 |
} |
| 11898 |
|
| 11899 |
if (vec_safe_length (cexpr_list) != 3) |
| 11900 |
{ |
| 11901 |
error_at (loc, "wrong number of arguments to " |
| 11902 |
"%<__builtin_choose_expr%>"); |
| 11903 |
expr.set_error (); |
| 11904 |
break; |
| 11905 |
} |
| 11906 |
|
| 11907 |
e1_p = &(*cexpr_list)[0]; |
| 11908 |
e2_p = &(*cexpr_list)[1]; |
| 11909 |
e3_p = &(*cexpr_list)[2]; |
| 11910 |
|
| 11911 |
c = e1_p->value; |
| 11912 |
mark_exp_read (e2_p->value); |
| 11913 |
mark_exp_read (e3_p->value); |
| 11914 |
if (TREE_CODE (c) != INTEGER_CST |
| 11915 |
|| !INTEGRAL_TYPE_P (TREE_TYPE (c))) |
| 11916 |
error_at (loc, |
| 11917 |
"first argument to %<__builtin_choose_expr%> not" |
| 11918 |
" a constant"); |
| 11919 |
constant_expression_warning (c); |
| 11920 |
expr = integer_zerop (c) ? *e3_p : *e2_p; |
| 11921 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 11922 |
break; |
| 11923 |
} |
| 11924 |
case RID_TYPES_COMPATIBLE_P: |
| 11925 |
{ |
| 11926 |
c_parser_consume_token (parser); |
| 11927 |
matching_parens parens; |
| 11928 |
if (!parens.require_open (parser)) |
| 11929 |
{ |
| 11930 |
expr.set_error (); |
| 11931 |
break; |
| 11932 |
} |
| 11933 |
t1 = c_parser_type_name (parser); |
| 11934 |
if (t1 == NULL) |
| 11935 |
{ |
| 11936 |
expr.set_error (); |
| 11937 |
break; |
| 11938 |
} |
| 11939 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 11940 |
{ |
| 11941 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 11942 |
expr.set_error (); |
| 11943 |
break; |
| 11944 |
} |
| 11945 |
t2 = c_parser_type_name (parser); |
| 11946 |
if (t2 == NULL) |
| 11947 |
{ |
| 11948 |
expr.set_error (); |
| 11949 |
break; |
| 11950 |
} |
| 11951 |
location_t close_paren_loc = c_parser_peek_token (parser)->location; |
| 11952 |
parens.skip_until_found_close (parser); |
| 11953 |
tree e1, e2; |
| 11954 |
e1 = groktypename (t1, NULL, NULL); |
| 11955 |
e2 = groktypename (t2, NULL, NULL); |
| 11956 |
if (e1 == error_mark_node || e2 == error_mark_node) |
| 11957 |
{ |
| 11958 |
expr.set_error (); |
| 11959 |
break; |
| 11960 |
} |
| 11961 |
|
| 11962 |
e1 = TYPE_MAIN_VARIANT (e1); |
| 11963 |
e2 = TYPE_MAIN_VARIANT (e2); |
| 11964 |
|
| 11965 |
expr.value |
| 11966 |
= comptypes (e1, e2) ? integer_one_node : integer_zero_node; |
| 11967 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 11968 |
} |
| 11969 |
break; |
| 11970 |
case RID_BUILTIN_TGMATH: |
| 11971 |
{ |
| 11972 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 11973 |
location_t close_paren_loc; |
| 11974 |
|
| 11975 |
c_parser_consume_token (parser); |
| 11976 |
if (!c_parser_get_builtin_args (parser, |
| 11977 |
"__builtin_tgmath", |
| 11978 |
&cexpr_list, false, |
| 11979 |
&close_paren_loc)) |
| 11980 |
{ |
| 11981 |
expr.set_error (); |
| 11982 |
break; |
| 11983 |
} |
| 11984 |
|
| 11985 |
if (vec_safe_length (cexpr_list) < 3) |
| 11986 |
{ |
| 11987 |
error_at (loc, "too few arguments to %<__builtin_tgmath%>"); |
| 11988 |
expr.set_error (); |
| 11989 |
break; |
| 11990 |
} |
| 11991 |
|
| 11992 |
unsigned int i; |
| 11993 |
c_expr_t *p; |
| 11994 |
FOR_EACH_VEC_ELT (*cexpr_list, i, p) |
| 11995 |
*p = convert_lvalue_to_rvalue (loc, *p, true, true); |
| 11996 |
unsigned int nargs = check_tgmath_function (&(*cexpr_list)[0], 1); |
| 11997 |
if (nargs == 0) |
| 11998 |
{ |
| 11999 |
expr.set_error (); |
| 12000 |
break; |
| 12001 |
} |
| 12002 |
if (vec_safe_length (cexpr_list) < nargs) |
| 12003 |
{ |
| 12004 |
error_at (loc, "too few arguments to %<__builtin_tgmath%>"); |
| 12005 |
expr.set_error (); |
| 12006 |
break; |
| 12007 |
} |
| 12008 |
unsigned int num_functions = vec_safe_length (cexpr_list) - nargs; |
| 12009 |
if (num_functions < 2) |
| 12010 |
{ |
| 12011 |
error_at (loc, "too few arguments to %<__builtin_tgmath%>"); |
| 12012 |
expr.set_error (); |
| 12013 |
break; |
| 12014 |
} |
| 12015 |
|
| 12016 |
/* The first NUM_FUNCTIONS expressions are the function |
| 12017 |
pointers. The remaining NARGS expressions are the |
| 12018 |
arguments that are to be passed to one of those |
| 12019 |
functions, chosen following <tgmath.h> rules. */ |
| 12020 |
for (unsigned int j = 1; j < num_functions; j++) |
| 12021 |
{ |
| 12022 |
unsigned int this_nargs |
| 12023 |
= check_tgmath_function (&(*cexpr_list)[j], j + 1); |
| 12024 |
if (this_nargs == 0) |
| 12025 |
{ |
| 12026 |
expr.set_error (); |
| 12027 |
goto out; |
| 12028 |
} |
| 12029 |
if (this_nargs != nargs) |
| 12030 |
{ |
| 12031 |
error_at ((*cexpr_list)[j].get_location (), |
| 12032 |
"argument %u of %<__builtin_tgmath%> has " |
| 12033 |
"wrong number of arguments", j + 1); |
| 12034 |
expr.set_error (); |
| 12035 |
goto out; |
| 12036 |
} |
| 12037 |
} |
| 12038 |
|
| 12039 |
/* The functions all have the same number of arguments. |
| 12040 |
Determine whether arguments and return types vary in |
| 12041 |
ways permitted for <tgmath.h> functions. */ |
| 12042 |
/* The first entry in each of these vectors is for the |
| 12043 |
return type, subsequent entries for parameter |
| 12044 |
types. */ |
| 12045 |
auto_vec<enum tgmath_parm_kind> parm_kind (nargs + 1); |
| 12046 |
auto_vec<tree> parm_first (nargs + 1); |
| 12047 |
auto_vec<bool> parm_complex (nargs + 1); |
| 12048 |
auto_vec<bool> parm_varies (nargs + 1); |
| 12049 |
tree first_type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[0].value)); |
| 12050 |
tree first_ret = TYPE_MAIN_VARIANT (TREE_TYPE (first_type)); |
| 12051 |
parm_first.quick_push (first_ret); |
| 12052 |
parm_complex.quick_push (TREE_CODE (first_ret) == COMPLEX_TYPE); |
| 12053 |
parm_varies.quick_push (false); |
| 12054 |
function_args_iterator iter; |
| 12055 |
tree t; |
| 12056 |
unsigned int argpos; |
| 12057 |
FOREACH_FUNCTION_ARGS (first_type, t, iter) |
| 12058 |
{ |
| 12059 |
if (t == void_type_node) |
| 12060 |
break; |
| 12061 |
parm_first.quick_push (TYPE_MAIN_VARIANT (t)); |
| 12062 |
parm_complex.quick_push (TREE_CODE (t) == COMPLEX_TYPE); |
| 12063 |
parm_varies.quick_push (false); |
| 12064 |
} |
| 12065 |
for (unsigned int j = 1; j < num_functions; j++) |
| 12066 |
{ |
| 12067 |
tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value)); |
| 12068 |
tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type)); |
| 12069 |
if (ret != parm_first[0]) |
| 12070 |
{ |
| 12071 |
parm_varies[0] = true; |
| 12072 |
if (!SCALAR_FLOAT_TYPE_P (parm_first[0]) |
| 12073 |
&& !COMPLEX_FLOAT_TYPE_P (parm_first[0])) |
| 12074 |
{ |
| 12075 |
error_at ((*cexpr_list)[0].get_location (), |
| 12076 |
"invalid type-generic return type for " |
| 12077 |
"argument %u of %<__builtin_tgmath%>", |
| 12078 |
1); |
| 12079 |
expr.set_error (); |
| 12080 |
goto out; |
| 12081 |
} |
| 12082 |
if (!SCALAR_FLOAT_TYPE_P (ret) |
| 12083 |
&& !COMPLEX_FLOAT_TYPE_P (ret)) |
| 12084 |
{ |
| 12085 |
error_at ((*cexpr_list)[j].get_location (), |
| 12086 |
"invalid type-generic return type for " |
| 12087 |
"argument %u of %<__builtin_tgmath%>", |
| 12088 |
j + 1); |
| 12089 |
expr.set_error (); |
| 12090 |
goto out; |
| 12091 |
} |
| 12092 |
} |
| 12093 |
if (TREE_CODE (ret) == COMPLEX_TYPE) |
| 12094 |
parm_complex[0] = true; |
| 12095 |
argpos = 1; |
| 12096 |
FOREACH_FUNCTION_ARGS (type, t, iter) |
| 12097 |
{ |
| 12098 |
if (t == void_type_node) |
| 12099 |
break; |
| 12100 |
t = TYPE_MAIN_VARIANT (t); |
| 12101 |
if (t != parm_first[argpos]) |
| 12102 |
{ |
| 12103 |
parm_varies[argpos] = true; |
| 12104 |
if (!SCALAR_FLOAT_TYPE_P (parm_first[argpos]) |
| 12105 |
&& !COMPLEX_FLOAT_TYPE_P (parm_first[argpos])) |
| 12106 |
{ |
| 12107 |
error_at ((*cexpr_list)[0].get_location (), |
| 12108 |
"invalid type-generic type for " |
| 12109 |
"argument %u of argument %u of " |
| 12110 |
"%<__builtin_tgmath%>", argpos, 1); |
| 12111 |
expr.set_error (); |
| 12112 |
goto out; |
| 12113 |
} |
| 12114 |
if (!SCALAR_FLOAT_TYPE_P (t) |
| 12115 |
&& !COMPLEX_FLOAT_TYPE_P (t)) |
| 12116 |
{ |
| 12117 |
error_at ((*cexpr_list)[j].get_location (), |
| 12118 |
"invalid type-generic type for " |
| 12119 |
"argument %u of argument %u of " |
| 12120 |
"%<__builtin_tgmath%>", argpos, j + 1); |
| 12121 |
expr.set_error (); |
| 12122 |
goto out; |
| 12123 |
} |
| 12124 |
} |
| 12125 |
if (TREE_CODE (t) == COMPLEX_TYPE) |
| 12126 |
parm_complex[argpos] = true; |
| 12127 |
argpos++; |
| 12128 |
} |
| 12129 |
} |
| 12130 |
enum tgmath_parm_kind max_variation = tgmath_fixed; |
| 12131 |
for (unsigned int j = 0; j <= nargs; j++) |
| 12132 |
{ |
| 12133 |
enum tgmath_parm_kind this_kind; |
| 12134 |
if (parm_varies[j]) |
| 12135 |
{ |
| 12136 |
if (parm_complex[j]) |
| 12137 |
max_variation = this_kind = tgmath_complex; |
| 12138 |
else |
| 12139 |
{ |
| 12140 |
this_kind = tgmath_real; |
| 12141 |
if (max_variation != tgmath_complex) |
| 12142 |
max_variation = tgmath_real; |
| 12143 |
} |
| 12144 |
} |
| 12145 |
else |
| 12146 |
this_kind = tgmath_fixed; |
| 12147 |
parm_kind.quick_push (this_kind); |
| 12148 |
} |
| 12149 |
if (max_variation == tgmath_fixed) |
| 12150 |
{ |
| 12151 |
error_at (loc, "function arguments of %<__builtin_tgmath%> " |
| 12152 |
"all have the same type"); |
| 12153 |
expr.set_error (); |
| 12154 |
break; |
| 12155 |
} |
| 12156 |
|
| 12157 |
/* Identify a parameter (not the return type) that varies, |
| 12158 |
including with complex types if any variation includes |
| 12159 |
complex types; there must be at least one such |
| 12160 |
parameter. */ |
| 12161 |
unsigned int tgarg = 0; |
| 12162 |
for (unsigned int j = 1; j <= nargs; j++) |
| 12163 |
if (parm_kind[j] == max_variation) |
| 12164 |
{ |
| 12165 |
tgarg = j; |
| 12166 |
break; |
| 12167 |
} |
| 12168 |
if (tgarg == 0) |
| 12169 |
{ |
| 12170 |
error_at (loc, "function arguments of %<__builtin_tgmath%> " |
| 12171 |
"lack type-generic parameter"); |
| 12172 |
expr.set_error (); |
| 12173 |
break; |
| 12174 |
} |
| 12175 |
|
| 12176 |
/* Determine the type of the relevant parameter for each |
| 12177 |
function. */ |
| 12178 |
auto_vec<tree> tg_type (num_functions); |
| 12179 |
for (unsigned int j = 0; j < num_functions; j++) |
| 12180 |
{ |
| 12181 |
tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value)); |
| 12182 |
argpos = 1; |
| 12183 |
FOREACH_FUNCTION_ARGS (type, t, iter) |
| 12184 |
{ |
| 12185 |
if (argpos == tgarg) |
| 12186 |
{ |
| 12187 |
tg_type.quick_push (TYPE_MAIN_VARIANT (t)); |
| 12188 |
break; |
| 12189 |
} |
| 12190 |
argpos++; |
| 12191 |
} |
| 12192 |
} |
| 12193 |
|
| 12194 |
/* Verify that the corresponding types are different for |
| 12195 |
all the listed functions. Also determine whether all |
| 12196 |
the types are complex, whether all the types are |
| 12197 |
standard or binary, and whether all the types are |
| 12198 |
decimal. */ |
| 12199 |
bool all_complex = true; |
| 12200 |
bool all_binary = true; |
| 12201 |
bool all_decimal = true; |
| 12202 |
hash_set<tree> tg_types; |
| 12203 |
FOR_EACH_VEC_ELT (tg_type, i, t) |
| 12204 |
{ |
| 12205 |
if (TREE_CODE (t) == COMPLEX_TYPE) |
| 12206 |
all_decimal = false; |
| 12207 |
else |
| 12208 |
{ |
| 12209 |
all_complex = false; |
| 12210 |
if (DECIMAL_FLOAT_TYPE_P (t)) |
| 12211 |
all_binary = false; |
| 12212 |
else |
| 12213 |
all_decimal = false; |
| 12214 |
} |
| 12215 |
if (tg_types.add (t)) |
| 12216 |
{ |
| 12217 |
error_at ((*cexpr_list)[i].get_location (), |
| 12218 |
"duplicate type-generic parameter type for " |
| 12219 |
"function argument %u of %<__builtin_tgmath%>", |
| 12220 |
i + 1); |
| 12221 |
expr.set_error (); |
| 12222 |
goto out; |
| 12223 |
} |
| 12224 |
} |
| 12225 |
|
| 12226 |
/* Verify that other parameters and the return type whose |
| 12227 |
types vary have their types varying in the correct |
| 12228 |
way. */ |
| 12229 |
for (unsigned int j = 0; j < num_functions; j++) |
| 12230 |
{ |
| 12231 |
tree exp_type = tg_type[j]; |
| 12232 |
tree exp_real_type = exp_type; |
| 12233 |
if (TREE_CODE (exp_type) == COMPLEX_TYPE) |
| 12234 |
exp_real_type = TREE_TYPE (exp_type); |
| 12235 |
tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value)); |
| 12236 |
tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type)); |
| 12237 |
if ((parm_kind[0] == tgmath_complex && ret != exp_type) |
| 12238 |
|| (parm_kind[0] == tgmath_real && ret != exp_real_type)) |
| 12239 |
{ |
| 12240 |
error_at ((*cexpr_list)[j].get_location (), |
| 12241 |
"bad return type for function argument %u " |
| 12242 |
"of %<__builtin_tgmath%>", j + 1); |
| 12243 |
expr.set_error (); |
| 12244 |
goto out; |
| 12245 |
} |
| 12246 |
argpos = 1; |
| 12247 |
FOREACH_FUNCTION_ARGS (type, t, iter) |
| 12248 |
{ |
| 12249 |
if (t == void_type_node) |
| 12250 |
break; |
| 12251 |
t = TYPE_MAIN_VARIANT (t); |
| 12252 |
if ((parm_kind[argpos] == tgmath_complex |
| 12253 |
&& t != exp_type) |
| 12254 |
|| (parm_kind[argpos] == tgmath_real |
| 12255 |
&& t != exp_real_type)) |
| 12256 |
{ |
| 12257 |
error_at ((*cexpr_list)[j].get_location (), |
| 12258 |
"bad type for argument %u of " |
| 12259 |
"function argument %u of " |
| 12260 |
"%<__builtin_tgmath%>", argpos, j + 1); |
| 12261 |
expr.set_error (); |
| 12262 |
goto out; |
| 12263 |
} |
| 12264 |
argpos++; |
| 12265 |
} |
| 12266 |
} |
| 12267 |
|
| 12268 |
/* The functions listed are a valid set of functions for a |
| 12269 |
<tgmath.h> macro to select between. Identify the |
| 12270 |
matching function, if any. First, the argument types |
| 12271 |
must be combined following <tgmath.h> rules. Integer |
| 12272 |
types are treated as _Decimal64 if any type-generic |
| 12273 |
argument is decimal, or if the only alternatives for |
| 12274 |
type-generic arguments are of decimal types, and are |
| 12275 |
otherwise treated as _Float32x (or _Complex _Float32x |
| 12276 |
for complex integer types) if any type-generic argument |
| 12277 |
has _FloatNx type, otherwise as double (or _Complex |
| 12278 |
double for complex integer types). After that |
| 12279 |
adjustment, types are combined following the usual |
| 12280 |
arithmetic conversions. If the function only accepts |
| 12281 |
complex arguments, a complex type is produced. */ |
| 12282 |
bool arg_complex = all_complex; |
| 12283 |
bool arg_binary = all_binary; |
| 12284 |
bool arg_int_decimal = all_decimal; |
| 12285 |
bool arg_int_floatnx = false; |
| 12286 |
bool arg_int_decimalx = false; |
| 12287 |
for (unsigned int j = 1; j <= nargs; j++) |
| 12288 |
{ |
| 12289 |
if (parm_kind[j] == tgmath_fixed) |
| 12290 |
continue; |
| 12291 |
c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1]; |
| 12292 |
tree type = TREE_TYPE (ce->value); |
| 12293 |
if (!INTEGRAL_TYPE_P (type) |
| 12294 |
&& !SCALAR_FLOAT_TYPE_P (type) |
| 12295 |
&& TREE_CODE (type) != COMPLEX_TYPE) |
| 12296 |
{ |
| 12297 |
error_at (ce->get_location (), |
| 12298 |
"invalid type of argument %u of type-generic " |
| 12299 |
"function", j); |
| 12300 |
expr.set_error (); |
| 12301 |
goto out; |
| 12302 |
} |
| 12303 |
if (DECIMAL_FLOAT_TYPE_P (type)) |
| 12304 |
{ |
| 12305 |
arg_int_decimal = true; |
| 12306 |
if (all_complex) |
| 12307 |
{ |
| 12308 |
error_at (ce->get_location (), |
| 12309 |
"decimal floating-point argument %u to " |
| 12310 |
"complex-only type-generic function", j); |
| 12311 |
expr.set_error (); |
| 12312 |
goto out; |
| 12313 |
} |
| 12314 |
else if (all_binary) |
| 12315 |
{ |
| 12316 |
error_at (ce->get_location (), |
| 12317 |
"decimal floating-point argument %u to " |
| 12318 |
"binary-only type-generic function", j); |
| 12319 |
expr.set_error (); |
| 12320 |
goto out; |
| 12321 |
} |
| 12322 |
else if (arg_complex) |
| 12323 |
{ |
| 12324 |
error_at (ce->get_location (), |
| 12325 |
"both complex and decimal floating-point " |
| 12326 |
"arguments to type-generic function"); |
| 12327 |
expr.set_error (); |
| 12328 |
goto out; |
| 12329 |
} |
| 12330 |
else if (arg_binary) |
| 12331 |
{ |
| 12332 |
error_at (ce->get_location (), |
| 12333 |
"both binary and decimal floating-point " |
| 12334 |
"arguments to type-generic function"); |
| 12335 |
expr.set_error (); |
| 12336 |
goto out; |
| 12337 |
} |
| 12338 |
} |
| 12339 |
else if (TREE_CODE (type) == COMPLEX_TYPE) |
| 12340 |
{ |
| 12341 |
arg_complex = true; |
| 12342 |
if (COMPLEX_FLOAT_TYPE_P (type)) |
| 12343 |
arg_binary = true; |
| 12344 |
if (all_decimal) |
| 12345 |
{ |
| 12346 |
error_at (ce->get_location (), |
| 12347 |
"complex argument %u to " |
| 12348 |
"decimal-only type-generic function", j); |
| 12349 |
expr.set_error (); |
| 12350 |
goto out; |
| 12351 |
} |
| 12352 |
else if (arg_int_decimal) |
| 12353 |
{ |
| 12354 |
error_at (ce->get_location (), |
| 12355 |
"both complex and decimal floating-point " |
| 12356 |
"arguments to type-generic function"); |
| 12357 |
expr.set_error (); |
| 12358 |
goto out; |
| 12359 |
} |
| 12360 |
} |
| 12361 |
else if (SCALAR_FLOAT_TYPE_P (type)) |
| 12362 |
{ |
| 12363 |
arg_binary = true; |
| 12364 |
if (all_decimal) |
| 12365 |
{ |
| 12366 |
error_at (ce->get_location (), |
| 12367 |
"binary argument %u to " |
| 12368 |
"decimal-only type-generic function", j); |
| 12369 |
expr.set_error (); |
| 12370 |
goto out; |
| 12371 |
} |
| 12372 |
else if (arg_int_decimal) |
| 12373 |
{ |
| 12374 |
error_at (ce->get_location (), |
| 12375 |
"both binary and decimal floating-point " |
| 12376 |
"arguments to type-generic function"); |
| 12377 |
expr.set_error (); |
| 12378 |
goto out; |
| 12379 |
} |
| 12380 |
} |
| 12381 |
tree rtype = TYPE_MAIN_VARIANT (type); |
| 12382 |
if (TREE_CODE (rtype) == COMPLEX_TYPE) |
| 12383 |
rtype = TREE_TYPE (rtype); |
| 12384 |
if (SCALAR_FLOAT_TYPE_P (rtype)) |
| 12385 |
for (unsigned int j = 0; j < NUM_FLOATNX_TYPES; j++) |
| 12386 |
if (rtype == FLOATNX_TYPE_NODE (j)) |
| 12387 |
{ |
| 12388 |
arg_int_floatnx = true; |
| 12389 |
break; |
| 12390 |
} |
| 12391 |
if (rtype == dfloat64x_type_node) |
| 12392 |
arg_int_decimalx = true; |
| 12393 |
} |
| 12394 |
tree arg_real = NULL_TREE; |
| 12395 |
for (unsigned int j = 1; j <= nargs; j++) |
| 12396 |
{ |
| 12397 |
if (parm_kind[j] == tgmath_fixed) |
| 12398 |
continue; |
| 12399 |
c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1]; |
| 12400 |
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (ce->value)); |
| 12401 |
if (TREE_CODE (type) == COMPLEX_TYPE) |
| 12402 |
type = TREE_TYPE (type); |
| 12403 |
if (INTEGRAL_TYPE_P (type)) |
| 12404 |
type = (arg_int_decimalx |
| 12405 |
? dfloat64x_type_node |
| 12406 |
: arg_int_floatnx |
| 12407 |
? float32x_type_node |
| 12408 |
: arg_int_decimal |
| 12409 |
? dfloat64_type_node |
| 12410 |
: double_type_node); |
| 12411 |
if (arg_real == NULL_TREE) |
| 12412 |
arg_real = type; |
| 12413 |
else |
| 12414 |
arg_real = common_type (arg_real, type); |
| 12415 |
if (arg_real == error_mark_node) |
| 12416 |
{ |
| 12417 |
expr.set_error (); |
| 12418 |
goto out; |
| 12419 |
} |
| 12420 |
} |
| 12421 |
tree arg_type = (arg_complex |
| 12422 |
? build_complex_type (arg_real) |
| 12423 |
: arg_real); |
| 12424 |
|
| 12425 |
/* Look for a function to call with type-generic parameter |
| 12426 |
type ARG_TYPE. */ |
| 12427 |
c_expr_t *fn = NULL; |
| 12428 |
for (unsigned int j = 0; j < num_functions; j++) |
| 12429 |
{ |
| 12430 |
if (tg_type[j] == arg_type) |
| 12431 |
{ |
| 12432 |
fn = &(*cexpr_list)[j]; |
| 12433 |
break; |
| 12434 |
} |
| 12435 |
} |
| 12436 |
if (fn == NULL |
| 12437 |
&& parm_kind[0] == tgmath_fixed |
| 12438 |
&& SCALAR_FLOAT_TYPE_P (parm_first[0])) |
| 12439 |
{ |
| 12440 |
/* Presume this is a macro that rounds its result to a |
| 12441 |
narrower type, and look for the first function with |
| 12442 |
at least the range and precision of the argument |
| 12443 |
type. */ |
| 12444 |
for (unsigned int j = 0; j < num_functions; j++) |
| 12445 |
{ |
| 12446 |
if (arg_complex |
| 12447 |
!= (TREE_CODE (tg_type[j]) == COMPLEX_TYPE)) |
| 12448 |
continue; |
| 12449 |
tree real_tg_type = (arg_complex |
| 12450 |
? TREE_TYPE (tg_type[j]) |
| 12451 |
: tg_type[j]); |
| 12452 |
if (DECIMAL_FLOAT_TYPE_P (arg_real) |
| 12453 |
!= DECIMAL_FLOAT_TYPE_P (real_tg_type)) |
| 12454 |
continue; |
| 12455 |
scalar_float_mode arg_mode |
| 12456 |
= SCALAR_FLOAT_TYPE_MODE (arg_real); |
| 12457 |
scalar_float_mode tg_mode |
| 12458 |
= SCALAR_FLOAT_TYPE_MODE (real_tg_type); |
| 12459 |
const real_format *arg_fmt = REAL_MODE_FORMAT (arg_mode); |
| 12460 |
const real_format *tg_fmt = REAL_MODE_FORMAT (tg_mode); |
| 12461 |
if (arg_fmt->b == tg_fmt->b |
| 12462 |
&& arg_fmt->p <= tg_fmt->p |
| 12463 |
&& arg_fmt->emax <= tg_fmt->emax |
| 12464 |
&& (arg_fmt->emin - arg_fmt->p |
| 12465 |
>= tg_fmt->emin - tg_fmt->p)) |
| 12466 |
{ |
| 12467 |
fn = &(*cexpr_list)[j]; |
| 12468 |
break; |
| 12469 |
} |
| 12470 |
} |
| 12471 |
} |
| 12472 |
if (fn == NULL) |
| 12473 |
{ |
| 12474 |
error_at (loc, "no matching function for type-generic call"); |
| 12475 |
expr.set_error (); |
| 12476 |
break; |
| 12477 |
} |
| 12478 |
|
| 12479 |
/* Construct a call to FN. */ |
| 12480 |
vec<tree, va_gc> *args; |
| 12481 |
vec_alloc (args, nargs); |
| 12482 |
vec<tree, va_gc> *origtypes; |
| 12483 |
vec_alloc (origtypes, nargs); |
| 12484 |
auto_vec<location_t> arg_loc (nargs); |
| 12485 |
for (unsigned int j = 0; j < nargs; j++) |
| 12486 |
{ |
| 12487 |
c_expr_t *ce = &(*cexpr_list)[num_functions + j]; |
| 12488 |
args->quick_push (ce->value); |
| 12489 |
arg_loc.quick_push (ce->get_location ()); |
| 12490 |
origtypes->quick_push (ce->original_type); |
| 12491 |
} |
| 12492 |
expr.value = c_build_function_call_vec (loc, arg_loc, fn->value, |
| 12493 |
args, origtypes); |
| 12494 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 12495 |
break; |
| 12496 |
} |
| 12497 |
case RID_BUILTIN_CALL_WITH_STATIC_CHAIN: |
| 12498 |
{ |
| 12499 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 12500 |
c_expr_t *e2_p; |
| 12501 |
tree chain_value; |
| 12502 |
location_t close_paren_loc; |
| 12503 |
|
| 12504 |
c_parser_consume_token (parser); |
| 12505 |
if (!c_parser_get_builtin_args (parser, |
| 12506 |
"__builtin_call_with_static_chain", |
| 12507 |
&cexpr_list, false, |
| 12508 |
&close_paren_loc)) |
| 12509 |
{ |
| 12510 |
expr.set_error (); |
| 12511 |
break; |
| 12512 |
} |
| 12513 |
if (vec_safe_length (cexpr_list) != 2) |
| 12514 |
{ |
| 12515 |
error_at (loc, "wrong number of arguments to " |
| 12516 |
"%<__builtin_call_with_static_chain%>"); |
| 12517 |
expr.set_error (); |
| 12518 |
break; |
| 12519 |
} |
| 12520 |
|
| 12521 |
expr = (*cexpr_list)[0]; |
| 12522 |
e2_p = &(*cexpr_list)[1]; |
| 12523 |
*e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); |
| 12524 |
chain_value = e2_p->value; |
| 12525 |
mark_exp_read (chain_value); |
| 12526 |
|
| 12527 |
if (TREE_CODE (expr.value) != CALL_EXPR) |
| 12528 |
error_at (loc, "first argument to " |
| 12529 |
"%<__builtin_call_with_static_chain%> " |
| 12530 |
"must be a call expression"); |
| 12531 |
else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE) |
| 12532 |
error_at (loc, "second argument to " |
| 12533 |
"%<__builtin_call_with_static_chain%> " |
| 12534 |
"must be a pointer type"); |
| 12535 |
else |
| 12536 |
CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value; |
| 12537 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 12538 |
break; |
| 12539 |
} |
| 12540 |
case RID_BUILTIN_COMPLEX: |
| 12541 |
{ |
| 12542 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 12543 |
c_expr_t *e1_p, *e2_p; |
| 12544 |
location_t close_paren_loc; |
| 12545 |
|
| 12546 |
c_parser_consume_token (parser); |
| 12547 |
if (!c_parser_get_builtin_args (parser, |
| 12548 |
"__builtin_complex", |
| 12549 |
&cexpr_list, false, |
| 12550 |
&close_paren_loc)) |
| 12551 |
{ |
| 12552 |
expr.set_error (); |
| 12553 |
break; |
| 12554 |
} |
| 12555 |
|
| 12556 |
if (vec_safe_length (cexpr_list) != 2) |
| 12557 |
{ |
| 12558 |
error_at (loc, "wrong number of arguments to " |
| 12559 |
"%<__builtin_complex%>"); |
| 12560 |
expr.set_error (); |
| 12561 |
break; |
| 12562 |
} |
| 12563 |
|
| 12564 |
e1_p = &(*cexpr_list)[0]; |
| 12565 |
e2_p = &(*cexpr_list)[1]; |
| 12566 |
|
| 12567 |
*e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true); |
| 12568 |
if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR) |
| 12569 |
e1_p->value = convert (TREE_TYPE (e1_p->value), |
| 12570 |
TREE_OPERAND (e1_p->value, 0)); |
| 12571 |
*e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); |
| 12572 |
if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR) |
| 12573 |
e2_p->value = convert (TREE_TYPE (e2_p->value), |
| 12574 |
TREE_OPERAND (e2_p->value, 0)); |
| 12575 |
if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) |
| 12576 |
|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) |
| 12577 |
|| !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)) |
| 12578 |
|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))) |
| 12579 |
{ |
| 12580 |
error_at (loc, "%<__builtin_complex%> operand " |
| 12581 |
"not of real binary floating-point type"); |
| 12582 |
expr.set_error (); |
| 12583 |
break; |
| 12584 |
} |
| 12585 |
if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value)) |
| 12586 |
!= TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value))) |
| 12587 |
{ |
| 12588 |
error_at (loc, |
| 12589 |
"%<__builtin_complex%> operands of different types"); |
| 12590 |
expr.set_error (); |
| 12591 |
break; |
| 12592 |
} |
| 12593 |
pedwarn_c90 (loc, OPT_Wpedantic, |
| 12594 |
"ISO C90 does not support complex types"); |
| 12595 |
expr.value = build2_loc (loc, COMPLEX_EXPR, |
| 12596 |
build_complex_type |
| 12597 |
(TYPE_MAIN_VARIANT |
| 12598 |
(TREE_TYPE (e1_p->value))), |
| 12599 |
e1_p->value, e2_p->value); |
| 12600 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 12601 |
break; |
| 12602 |
} |
| 12603 |
case RID_BUILTIN_COUNTED_BY_REF: |
| 12604 |
{ |
| 12605 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 12606 |
c_expr_t *e_p; |
| 12607 |
location_t close_paren_loc; |
| 12608 |
|
| 12609 |
c_parser_consume_token (parser); |
| 12610 |
if (!c_parser_get_builtin_args (parser, |
| 12611 |
"__builtin_counted_by_ref", |
| 12612 |
&cexpr_list, false, |
| 12613 |
&close_paren_loc)) |
| 12614 |
{ |
| 12615 |
expr.set_error (); |
| 12616 |
break; |
| 12617 |
} |
| 12618 |
if (vec_safe_length (cexpr_list) != 1) |
| 12619 |
{ |
| 12620 |
error_at (loc, "wrong number of arguments to " |
| 12621 |
"%<__builtin_counted_by_ref%>"); |
| 12622 |
expr.set_error (); |
| 12623 |
break; |
| 12624 |
} |
| 12625 |
|
| 12626 |
e_p = &(*cexpr_list)[0]; |
| 12627 |
tree ref = e_p->value; |
| 12628 |
|
| 12629 |
if (TREE_CODE (TREE_TYPE (ref)) != ARRAY_TYPE) |
| 12630 |
{ |
| 12631 |
error_at (loc, "the argument to %<__builtin_counted_by_ref%>" |
| 12632 |
" must be an array"); |
| 12633 |
expr.set_error (); |
| 12634 |
break; |
| 12635 |
} |
| 12636 |
|
| 12637 |
/* If the array ref is inside TYPEOF or ALIGNOF, the call to |
| 12638 |
.ACCESS_WITH_SIZE was not generated by the routine |
| 12639 |
build_component_ref by default, we should generate it here. */ |
| 12640 |
if ((in_typeof || in_alignof) && TREE_CODE (ref) == COMPONENT_REF) |
| 12641 |
ref = handle_counted_by_for_component_ref (loc, ref); |
| 12642 |
|
| 12643 |
if (has_counted_by_object (ref)) |
| 12644 |
expr.value = get_counted_by_ref (ref); |
| 12645 |
else |
| 12646 |
expr.value = null_pointer_node; |
| 12647 |
|
| 12648 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 12649 |
break; |
| 12650 |
} |
| 12651 |
case RID_BUILTIN_SHUFFLE: |
| 12652 |
{ |
| 12653 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 12654 |
unsigned int i; |
| 12655 |
c_expr_t *p; |
| 12656 |
location_t close_paren_loc; |
| 12657 |
|
| 12658 |
c_parser_consume_token (parser); |
| 12659 |
if (!c_parser_get_builtin_args (parser, |
| 12660 |
"__builtin_shuffle", |
| 12661 |
&cexpr_list, false, |
| 12662 |
&close_paren_loc)) |
| 12663 |
{ |
| 12664 |
expr.set_error (); |
| 12665 |
break; |
| 12666 |
} |
| 12667 |
|
| 12668 |
FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p) |
| 12669 |
*p = convert_lvalue_to_rvalue (loc, *p, true, true); |
| 12670 |
|
| 12671 |
if (vec_safe_length (cexpr_list) == 2) |
| 12672 |
expr.value = c_build_vec_perm_expr (loc, (*cexpr_list)[0].value, |
| 12673 |
NULL_TREE, |
| 12674 |
(*cexpr_list)[1].value); |
| 12675 |
|
| 12676 |
else if (vec_safe_length (cexpr_list) == 3) |
| 12677 |
expr.value = c_build_vec_perm_expr (loc, (*cexpr_list)[0].value, |
| 12678 |
(*cexpr_list)[1].value, |
| 12679 |
(*cexpr_list)[2].value); |
| 12680 |
else |
| 12681 |
{ |
| 12682 |
error_at (loc, "wrong number of arguments to " |
| 12683 |
"%<__builtin_shuffle%>"); |
| 12684 |
expr.set_error (); |
| 12685 |
} |
| 12686 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 12687 |
break; |
| 12688 |
} |
| 12689 |
case RID_BUILTIN_SHUFFLEVECTOR: |
| 12690 |
{ |
| 12691 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 12692 |
unsigned int i; |
| 12693 |
c_expr_t *p; |
| 12694 |
location_t close_paren_loc; |
| 12695 |
|
| 12696 |
c_parser_consume_token (parser); |
| 12697 |
if (!c_parser_get_builtin_args (parser, |
| 12698 |
"__builtin_shufflevector", |
| 12699 |
&cexpr_list, false, |
| 12700 |
&close_paren_loc)) |
| 12701 |
{ |
| 12702 |
expr.set_error (); |
| 12703 |
break; |
| 12704 |
} |
| 12705 |
|
| 12706 |
FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p) |
| 12707 |
*p = convert_lvalue_to_rvalue (loc, *p, true, true); |
| 12708 |
|
| 12709 |
if (vec_safe_length (cexpr_list) < 3) |
| 12710 |
{ |
| 12711 |
error_at (loc, "wrong number of arguments to " |
| 12712 |
"%<__builtin_shuffle%>"); |
| 12713 |
expr.set_error (); |
| 12714 |
} |
| 12715 |
else |
| 12716 |
{ |
| 12717 |
auto_vec<tree, 16> mask; |
| 12718 |
for (i = 2; i < cexpr_list->length (); ++i) |
| 12719 |
mask.safe_push ((*cexpr_list)[i].value); |
| 12720 |
expr.value = c_build_shufflevector (loc, (*cexpr_list)[0].value, |
| 12721 |
(*cexpr_list)[1].value, |
| 12722 |
mask); |
| 12723 |
} |
| 12724 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 12725 |
break; |
| 12726 |
} |
| 12727 |
case RID_BUILTIN_CONVERTVECTOR: |
| 12728 |
{ |
| 12729 |
location_t start_loc = loc; |
| 12730 |
c_parser_consume_token (parser); |
| 12731 |
matching_parens parens; |
| 12732 |
if (!parens.require_open (parser)) |
| 12733 |
{ |
| 12734 |
expr.set_error (); |
| 12735 |
break; |
| 12736 |
} |
| 12737 |
e1 = c_parser_expr_no_commas (parser, NULL); |
| 12738 |
mark_exp_read (e1.value); |
| 12739 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 12740 |
{ |
| 12741 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 12742 |
expr.set_error (); |
| 12743 |
break; |
| 12744 |
} |
| 12745 |
loc = c_parser_peek_token (parser)->location; |
| 12746 |
t1 = c_parser_type_name (parser); |
| 12747 |
location_t end_loc = c_parser_peek_token (parser)->get_finish (); |
| 12748 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 12749 |
"expected %<)%>"); |
| 12750 |
if (t1 == NULL) |
| 12751 |
expr.set_error (); |
| 12752 |
else |
| 12753 |
{ |
| 12754 |
tree type_expr = NULL_TREE; |
| 12755 |
expr.value = c_build_vec_convert (start_loc, e1.value, loc, |
| 12756 |
groktypename (t1, &type_expr, |
| 12757 |
NULL)); |
| 12758 |
set_c_expr_source_range (&expr, start_loc, end_loc); |
| 12759 |
} |
| 12760 |
} |
| 12761 |
break; |
| 12762 |
case RID_BUILTIN_ASSOC_BARRIER: |
| 12763 |
{ |
| 12764 |
location_t start_loc = loc; |
| 12765 |
c_parser_consume_token (parser); |
| 12766 |
matching_parens parens; |
| 12767 |
if (!parens.require_open (parser)) |
| 12768 |
{ |
| 12769 |
expr.set_error (); |
| 12770 |
break; |
| 12771 |
} |
| 12772 |
e1 = c_parser_expr_no_commas (parser, NULL); |
| 12773 |
mark_exp_read (e1.value); |
| 12774 |
location_t end_loc = c_parser_peek_token (parser)->get_finish (); |
| 12775 |
parens.skip_until_found_close (parser); |
| 12776 |
expr = parser_build_unary_op (loc, PAREN_EXPR, e1); |
| 12777 |
set_c_expr_source_range (&expr, start_loc, end_loc); |
| 12778 |
} |
| 12779 |
break; |
| 12780 |
case RID_BUILTIN_STDC: |
| 12781 |
{ |
| 12782 |
vec<c_expr_t, va_gc> *cexpr_list; |
| 12783 |
c_expr_t *arg_p; |
| 12784 |
location_t close_paren_loc; |
| 12785 |
enum c_builtin_stdc { |
| 12786 |
C_BUILTIN_STDC_BIT_CEIL, |
| 12787 |
C_BUILTIN_STDC_BIT_FLOOR, |
| 12788 |
C_BUILTIN_STDC_BIT_WIDTH, |
| 12789 |
C_BUILTIN_STDC_COUNT_ONES, |
| 12790 |
C_BUILTIN_STDC_COUNT_ZEROS, |
| 12791 |
C_BUILTIN_STDC_FIRST_LEADING_ONE, |
| 12792 |
C_BUILTIN_STDC_FIRST_LEADING_ZERO, |
| 12793 |
C_BUILTIN_STDC_FIRST_TRAILING_ONE, |
| 12794 |
C_BUILTIN_STDC_FIRST_TRAILING_ZERO, |
| 12795 |
C_BUILTIN_STDC_HAS_SINGLE_BIT, |
| 12796 |
C_BUILTIN_STDC_LEADING_ONES, |
| 12797 |
C_BUILTIN_STDC_LEADING_ZEROS, |
| 12798 |
C_BUILTIN_STDC_ROTATE_LEFT, |
| 12799 |
C_BUILTIN_STDC_ROTATE_RIGHT, |
| 12800 |
C_BUILTIN_STDC_TRAILING_ONES, |
| 12801 |
C_BUILTIN_STDC_TRAILING_ZEROS, |
| 12802 |
C_BUILTIN_STDC_MAX |
| 12803 |
} stdc_rid = C_BUILTIN_STDC_MAX; |
| 12804 |
const char *name |
| 12805 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 12806 |
unsigned num_args = 1; |
| 12807 |
switch (name[sizeof ("__builtin_stdc_") - 1]) |
| 12808 |
{ |
| 12809 |
case 'b': |
| 12810 |
switch (name[sizeof ("__builtin_stdc_bit_") - 1]) |
| 12811 |
{ |
| 12812 |
case 'c': |
| 12813 |
stdc_rid = C_BUILTIN_STDC_BIT_CEIL; |
| 12814 |
break; |
| 12815 |
case 'f': |
| 12816 |
stdc_rid = C_BUILTIN_STDC_BIT_FLOOR; |
| 12817 |
break; |
| 12818 |
default: |
| 12819 |
stdc_rid = C_BUILTIN_STDC_BIT_WIDTH; |
| 12820 |
break; |
| 12821 |
} |
| 12822 |
break; |
| 12823 |
case 'c': |
| 12824 |
if (name[sizeof ("__builtin_stdc_count_") - 1] == 'o') |
| 12825 |
stdc_rid = C_BUILTIN_STDC_COUNT_ONES; |
| 12826 |
else |
| 12827 |
stdc_rid = C_BUILTIN_STDC_COUNT_ZEROS; |
| 12828 |
break; |
| 12829 |
case 'f': |
| 12830 |
switch (name[sizeof ("__builtin_stdc_first_trailing_") - 1]) |
| 12831 |
{ |
| 12832 |
case 'n': |
| 12833 |
stdc_rid = C_BUILTIN_STDC_FIRST_LEADING_ONE; |
| 12834 |
break; |
| 12835 |
case 'e': |
| 12836 |
stdc_rid = C_BUILTIN_STDC_FIRST_LEADING_ZERO; |
| 12837 |
break; |
| 12838 |
case 'o': |
| 12839 |
stdc_rid = C_BUILTIN_STDC_FIRST_TRAILING_ONE; |
| 12840 |
break; |
| 12841 |
default: |
| 12842 |
stdc_rid = C_BUILTIN_STDC_FIRST_TRAILING_ZERO; |
| 12843 |
break; |
| 12844 |
} |
| 12845 |
break; |
| 12846 |
case 'h': |
| 12847 |
stdc_rid = C_BUILTIN_STDC_HAS_SINGLE_BIT; |
| 12848 |
break; |
| 12849 |
case 'l': |
| 12850 |
if (name[sizeof ("__builtin_stdc_leading_") - 1] == 'o') |
| 12851 |
stdc_rid = C_BUILTIN_STDC_LEADING_ONES; |
| 12852 |
else |
| 12853 |
stdc_rid = C_BUILTIN_STDC_LEADING_ZEROS; |
| 12854 |
break; |
| 12855 |
case 'r': |
| 12856 |
if (name[sizeof ("__builtin_stdc_rotate_") - 1] == 'l') |
| 12857 |
stdc_rid = C_BUILTIN_STDC_ROTATE_LEFT; |
| 12858 |
else |
| 12859 |
stdc_rid = C_BUILTIN_STDC_ROTATE_RIGHT; |
| 12860 |
num_args = 2; |
| 12861 |
break; |
| 12862 |
case 't': |
| 12863 |
if (name[sizeof ("__builtin_stdc_trailing_") - 1] == 'o') |
| 12864 |
stdc_rid = C_BUILTIN_STDC_TRAILING_ONES; |
| 12865 |
else |
| 12866 |
stdc_rid = C_BUILTIN_STDC_TRAILING_ZEROS; |
| 12867 |
break; |
| 12868 |
} |
| 12869 |
gcc_checking_assert (stdc_rid != C_BUILTIN_STDC_MAX); |
| 12870 |
|
| 12871 |
c_parser_consume_token (parser); |
| 12872 |
if (!c_parser_get_builtin_args (parser, name, |
| 12873 |
&cexpr_list, false, |
| 12874 |
&close_paren_loc)) |
| 12875 |
{ |
| 12876 |
expr.set_error (); |
| 12877 |
break; |
| 12878 |
} |
| 12879 |
|
| 12880 |
if (vec_safe_length (cexpr_list) != num_args) |
| 12881 |
{ |
| 12882 |
error_at (loc, "wrong number of arguments to %qs", name); |
| 12883 |
expr.set_error (); |
| 12884 |
break; |
| 12885 |
} |
| 12886 |
|
| 12887 |
arg_p = &(*cexpr_list)[0]; |
| 12888 |
*arg_p = convert_lvalue_to_rvalue (loc, *arg_p, true, true); |
| 12889 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (arg_p->value))) |
| 12890 |
{ |
| 12891 |
error_at (loc, "%qs operand not an integral type", name); |
| 12892 |
expr.set_error (); |
| 12893 |
break; |
| 12894 |
} |
| 12895 |
if (TREE_CODE (TREE_TYPE (arg_p->value)) == ENUMERAL_TYPE) |
| 12896 |
{ |
| 12897 |
error_at (loc, "argument %u in call to function " |
| 12898 |
"%qs has enumerated type", 1, name); |
| 12899 |
expr.set_error (); |
| 12900 |
break; |
| 12901 |
} |
| 12902 |
if (TREE_CODE (TREE_TYPE (arg_p->value)) == BOOLEAN_TYPE) |
| 12903 |
{ |
| 12904 |
error_at (loc, "argument %u in call to function " |
| 12905 |
"%qs has boolean type", 1, name); |
| 12906 |
expr.set_error (); |
| 12907 |
break; |
| 12908 |
} |
| 12909 |
if (!TYPE_UNSIGNED (TREE_TYPE (arg_p->value))) |
| 12910 |
{ |
| 12911 |
error_at (loc, "argument 1 in call to function " |
| 12912 |
"%qs has signed type", name); |
| 12913 |
expr.set_error (); |
| 12914 |
break; |
| 12915 |
} |
| 12916 |
if (TYPE_MAIN_VARIANT (TREE_TYPE (arg_p->value)) |
| 12917 |
== char_type_node) |
| 12918 |
{ |
| 12919 |
error_at (loc, "argument 1 in call to function " |
| 12920 |
"%qs has %<char%> type", name); |
| 12921 |
expr.set_error (); |
| 12922 |
break; |
| 12923 |
} |
| 12924 |
tree arg = arg_p->value; |
| 12925 |
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg)); |
| 12926 |
/* Expand: |
| 12927 |
__builtin_stdc_leading_zeros (arg) as |
| 12928 |
(unsigned int) __builtin_clzg (arg, prec) |
| 12929 |
__builtin_stdc_leading_ones (arg) as |
| 12930 |
(unsigned int) __builtin_clzg ((type) ~arg, prec) |
| 12931 |
__builtin_stdc_trailing_zeros (arg) as |
| 12932 |
(unsigned int) __builtin_ctzg (arg, prec) |
| 12933 |
__builtin_stdc_trailing_ones (arg) as |
| 12934 |
(unsigned int) __builtin_ctzg ((type) ~arg, prec) |
| 12935 |
__builtin_stdc_first_leading_zero (arg) as |
| 12936 |
__builtin_clzg ((type) ~arg, -1) + 1U |
| 12937 |
__builtin_stdc_first_leading_one (arg) as |
| 12938 |
__builtin_clzg (arg, -1) + 1U |
| 12939 |
__builtin_stdc_first_trailing_zero (arg) as |
| 12940 |
__builtin_ctzg ((type) ~arg, -1) + 1U |
| 12941 |
__builtin_stdc_first_trailing_one (arg) as |
| 12942 |
__builtin_ctzg (arg, -1) + 1U |
| 12943 |
__builtin_stdc_count_zeros (arg) as |
| 12944 |
(unsigned int) __builtin_popcountg ((type) ~arg) |
| 12945 |
__builtin_stdc_count_ones (arg) as |
| 12946 |
(unsigned int) __builtin_popcountg (arg) |
| 12947 |
__builtin_stdc_has_single_bit (arg) as |
| 12948 |
(_Bool) (__builtin_popcountg (arg) == 1) |
| 12949 |
__builtin_stdc_bit_width (arg) as |
| 12950 |
(unsigned int) (prec - __builtin_clzg (arg, prec)) |
| 12951 |
__builtin_stdc_bit_floor (arg) as |
| 12952 |
arg == 0 ? (type) 0 |
| 12953 |
: (type) 1 << (prec - 1 - __builtin_clzg (arg)) |
| 12954 |
__builtin_stdc_bit_ceil (arg) as |
| 12955 |
arg <= 1 ? (type) 1 |
| 12956 |
: (type) 2 << (prec - 1 - __builtin_clzg (arg - 1)) |
| 12957 |
without evaluating arg multiple times, type being |
| 12958 |
__typeof (arg) and prec __builtin_popcountg ((type) ~0)). */ |
| 12959 |
int prec = TYPE_PRECISION (type); |
| 12960 |
if (num_args == 2) |
| 12961 |
{ |
| 12962 |
/* Expand: |
| 12963 |
__builtin_stdc_rotate_left (arg1, arg2) as |
| 12964 |
arg1 r<< (arg2 % prec) |
| 12965 |
__builtin_stdc_rotate_right (arg1, arg2) as |
| 12966 |
arg1 r>> (arg2 % prec). */ |
| 12967 |
arg_p = &(*cexpr_list)[1]; |
| 12968 |
*arg_p = convert_lvalue_to_rvalue (loc, *arg_p, true, true); |
| 12969 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (arg_p->value))) |
| 12970 |
{ |
| 12971 |
error_at (loc, "%qs operand not an integral type", name); |
| 12972 |
expr.set_error (); |
| 12973 |
break; |
| 12974 |
} |
| 12975 |
if (TREE_CODE (TREE_TYPE (arg_p->value)) == ENUMERAL_TYPE) |
| 12976 |
{ |
| 12977 |
error_at (loc, "argument %u in call to function " |
| 12978 |
"%qs has enumerated type", 2, name); |
| 12979 |
expr.set_error (); |
| 12980 |
break; |
| 12981 |
} |
| 12982 |
tree arg1 = save_expr (arg); |
| 12983 |
tree arg2 = save_expr (arg_p->value); |
| 12984 |
tree_code code; |
| 12985 |
if (stdc_rid == C_BUILTIN_STDC_ROTATE_LEFT) |
| 12986 |
code = LROTATE_EXPR; |
| 12987 |
else |
| 12988 |
code = RROTATE_EXPR; |
| 12989 |
|
| 12990 |
if (TREE_CODE (arg2) == INTEGER_CST |
| 12991 |
&& tree_int_cst_sgn (arg2) < 0) |
| 12992 |
warning_at (loc, OPT_Wshift_count_negative, |
| 12993 |
"rotate count is negative"); |
| 12994 |
|
| 12995 |
tree instrument_expr = NULL_TREE; |
| 12996 |
if (sanitize_flags_p (SANITIZE_SHIFT)) |
| 12997 |
instrument_expr = ubsan_instrument_shift (loc, code, |
| 12998 |
arg1, arg2); |
| 12999 |
|
| 13000 |
/* Promote arg2 to unsigned just so that we don't |
| 13001 |
need to deal with arg2 type not being able to represent |
| 13002 |
prec. In the end gimplification uses unsigned int |
| 13003 |
for all shifts/rotates anyway. */ |
| 13004 |
if (TYPE_PRECISION (TREE_TYPE (arg2)) |
| 13005 |
< TYPE_PRECISION (integer_type_node)) |
| 13006 |
arg2 = fold_convert (unsigned_type_node, arg2); |
| 13007 |
|
| 13008 |
if (TYPE_UNSIGNED (TREE_TYPE (arg2))) |
| 13009 |
arg2 = build2_loc (loc, TRUNC_MOD_EXPR, TREE_TYPE (arg2), |
| 13010 |
arg2, build_int_cst (TREE_TYPE (arg2), |
| 13011 |
prec)); |
| 13012 |
else |
| 13013 |
{ |
| 13014 |
/* When second argument is signed, just do the modulo in |
| 13015 |
unsigned type, that results in better generated code |
| 13016 |
(for power of 2 precisions bitwise AND). */ |
| 13017 |
tree utype = c_common_unsigned_type (TREE_TYPE (arg2)); |
| 13018 |
arg2 = build2_loc (loc, TRUNC_MOD_EXPR, utype, |
| 13019 |
fold_convert (utype, arg2), |
| 13020 |
build_int_cst (utype, prec)); |
| 13021 |
} |
| 13022 |
|
| 13023 |
/* The middle-end isn't prepared to handle {L,R}ROTATE_EXPR |
| 13024 |
on types without mode precision, except for large/huge |
| 13025 |
_BitInt types. */ |
| 13026 |
if (type_has_mode_precision_p (TREE_TYPE (arg1)) |
| 13027 |
|| (TREE_CODE (TREE_TYPE (arg1)) == BITINT_TYPE |
| 13028 |
&& prec > MAX_FIXED_MODE_SIZE)) |
| 13029 |
expr.value = build2_loc (loc, code, TREE_TYPE (arg1), arg1, |
| 13030 |
arg2); |
| 13031 |
else |
| 13032 |
{ |
| 13033 |
arg2 = save_expr (arg2); |
| 13034 |
tree t1 = build2_loc (loc, (code == LROTATE_EXPR |
| 13035 |
? LSHIFT_EXPR : RSHIFT_EXPR), |
| 13036 |
TREE_TYPE (arg1), arg1, arg2); |
| 13037 |
tree t2 = build2_loc (loc, MINUS_EXPR, |
| 13038 |
TREE_TYPE (arg2), |
| 13039 |
build_int_cst (TREE_TYPE (arg2), |
| 13040 |
prec), arg2); |
| 13041 |
t2 = build2_loc (loc, (code == LROTATE_EXPR |
| 13042 |
? RSHIFT_EXPR : LSHIFT_EXPR), |
| 13043 |
TREE_TYPE (arg1), arg1, t2); |
| 13044 |
suppress_warning (t2, OPT_Wshift_count_overflow); |
| 13045 |
tree t3 = build2_loc (loc, BIT_IOR_EXPR, |
| 13046 |
TREE_TYPE (arg1), t1, t2); |
| 13047 |
tree t4 = build2_loc (loc, NE_EXPR, boolean_type_node, |
| 13048 |
arg2, |
| 13049 |
build_zero_cst (TREE_TYPE (arg2))); |
| 13050 |
t4 = build2_loc (loc, COMPOUND_EXPR, boolean_type_node, |
| 13051 |
arg1, t4); |
| 13052 |
expr.value = build3_loc (loc, COND_EXPR, |
| 13053 |
TREE_TYPE (arg1), t4, t3, arg1); |
| 13054 |
} |
| 13055 |
if (instrument_expr) |
| 13056 |
expr.value = build2_loc (loc, COMPOUND_EXPR, |
| 13057 |
TREE_TYPE (expr.value), |
| 13058 |
instrument_expr, expr.value); |
| 13059 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 13060 |
break; |
| 13061 |
} |
| 13062 |
tree barg1 = arg; |
| 13063 |
switch (stdc_rid) |
| 13064 |
{ |
| 13065 |
case C_BUILTIN_STDC_BIT_CEIL: |
| 13066 |
arg = save_expr (arg); |
| 13067 |
barg1 = build2_loc (loc, PLUS_EXPR, type, arg, |
| 13068 |
build_int_cst (type, -1)); |
| 13069 |
break; |
| 13070 |
case C_BUILTIN_STDC_BIT_FLOOR: |
| 13071 |
barg1 = arg = save_expr (arg); |
| 13072 |
break; |
| 13073 |
case C_BUILTIN_STDC_COUNT_ZEROS: |
| 13074 |
case C_BUILTIN_STDC_FIRST_LEADING_ZERO: |
| 13075 |
case C_BUILTIN_STDC_FIRST_TRAILING_ZERO: |
| 13076 |
case C_BUILTIN_STDC_LEADING_ONES: |
| 13077 |
case C_BUILTIN_STDC_TRAILING_ONES: |
| 13078 |
barg1 = build1_loc (loc, BIT_NOT_EXPR, type, arg); |
| 13079 |
break; |
| 13080 |
default: |
| 13081 |
break; |
| 13082 |
} |
| 13083 |
tree barg2 = NULL_TREE; |
| 13084 |
switch (stdc_rid) |
| 13085 |
{ |
| 13086 |
case C_BUILTIN_STDC_BIT_WIDTH: |
| 13087 |
case C_BUILTIN_STDC_LEADING_ONES: |
| 13088 |
case C_BUILTIN_STDC_LEADING_ZEROS: |
| 13089 |
case C_BUILTIN_STDC_TRAILING_ONES: |
| 13090 |
case C_BUILTIN_STDC_TRAILING_ZEROS: |
| 13091 |
barg2 = build_int_cst (integer_type_node, prec); |
| 13092 |
break; |
| 13093 |
case C_BUILTIN_STDC_FIRST_LEADING_ONE: |
| 13094 |
case C_BUILTIN_STDC_FIRST_LEADING_ZERO: |
| 13095 |
case C_BUILTIN_STDC_FIRST_TRAILING_ONE: |
| 13096 |
case C_BUILTIN_STDC_FIRST_TRAILING_ZERO: |
| 13097 |
barg2 = integer_minus_one_node; |
| 13098 |
break; |
| 13099 |
default: |
| 13100 |
break; |
| 13101 |
} |
| 13102 |
tree fndecl = NULL_TREE; |
| 13103 |
switch (stdc_rid) |
| 13104 |
{ |
| 13105 |
case C_BUILTIN_STDC_BIT_CEIL: |
| 13106 |
case C_BUILTIN_STDC_BIT_FLOOR: |
| 13107 |
case C_BUILTIN_STDC_BIT_WIDTH: |
| 13108 |
case C_BUILTIN_STDC_FIRST_LEADING_ONE: |
| 13109 |
case C_BUILTIN_STDC_FIRST_LEADING_ZERO: |
| 13110 |
case C_BUILTIN_STDC_LEADING_ONES: |
| 13111 |
case C_BUILTIN_STDC_LEADING_ZEROS: |
| 13112 |
fndecl = builtin_decl_explicit (BUILT_IN_CLZG); |
| 13113 |
break; |
| 13114 |
case C_BUILTIN_STDC_FIRST_TRAILING_ONE: |
| 13115 |
case C_BUILTIN_STDC_FIRST_TRAILING_ZERO: |
| 13116 |
case C_BUILTIN_STDC_TRAILING_ONES: |
| 13117 |
case C_BUILTIN_STDC_TRAILING_ZEROS: |
| 13118 |
fndecl = builtin_decl_explicit (BUILT_IN_CTZG); |
| 13119 |
break; |
| 13120 |
case C_BUILTIN_STDC_COUNT_ONES: |
| 13121 |
case C_BUILTIN_STDC_COUNT_ZEROS: |
| 13122 |
case C_BUILTIN_STDC_HAS_SINGLE_BIT: |
| 13123 |
fndecl = builtin_decl_explicit (BUILT_IN_POPCOUNTG); |
| 13124 |
break; |
| 13125 |
default: |
| 13126 |
gcc_unreachable (); |
| 13127 |
} |
| 13128 |
/* Construct a call to __builtin_{clz,ctz,popcount}g. */ |
| 13129 |
int nargs = barg2 != NULL_TREE ? 2 : 1; |
| 13130 |
vec<tree, va_gc> *args; |
| 13131 |
vec_alloc (args, nargs); |
| 13132 |
vec<tree, va_gc> *origtypes; |
| 13133 |
vec_alloc (origtypes, nargs); |
| 13134 |
auto_vec<location_t> arg_loc (nargs); |
| 13135 |
args->quick_push (barg1); |
| 13136 |
arg_loc.quick_push (arg_p->get_location ()); |
| 13137 |
origtypes->quick_push (arg_p->original_type); |
| 13138 |
if (nargs == 2) |
| 13139 |
{ |
| 13140 |
args->quick_push (barg2); |
| 13141 |
arg_loc.quick_push (loc); |
| 13142 |
origtypes->quick_push (integer_type_node); |
| 13143 |
} |
| 13144 |
expr.value = c_build_function_call_vec (loc, arg_loc, fndecl, |
| 13145 |
args, origtypes); |
| 13146 |
set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 13147 |
if (expr.value == error_mark_node) |
| 13148 |
break; |
| 13149 |
switch (stdc_rid) |
| 13150 |
{ |
| 13151 |
case C_BUILTIN_STDC_BIT_CEIL: |
| 13152 |
case C_BUILTIN_STDC_BIT_FLOOR: |
| 13153 |
--prec; |
| 13154 |
/* FALLTHRU */ |
| 13155 |
case C_BUILTIN_STDC_BIT_WIDTH: |
| 13156 |
expr.value = build2_loc (loc, MINUS_EXPR, integer_type_node, |
| 13157 |
build_int_cst (integer_type_node, |
| 13158 |
prec), expr.value); |
| 13159 |
break; |
| 13160 |
case C_BUILTIN_STDC_FIRST_LEADING_ONE: |
| 13161 |
case C_BUILTIN_STDC_FIRST_LEADING_ZERO: |
| 13162 |
case C_BUILTIN_STDC_FIRST_TRAILING_ONE: |
| 13163 |
case C_BUILTIN_STDC_FIRST_TRAILING_ZERO: |
| 13164 |
expr.value = build2_loc (loc, PLUS_EXPR, integer_type_node, |
| 13165 |
expr.value, integer_one_node); |
| 13166 |
break; |
| 13167 |
case C_BUILTIN_STDC_HAS_SINGLE_BIT: |
| 13168 |
expr.value = build2_loc (loc, EQ_EXPR, boolean_type_node, |
| 13169 |
expr.value, integer_one_node); |
| 13170 |
break; |
| 13171 |
default: |
| 13172 |
break; |
| 13173 |
} |
| 13174 |
|
| 13175 |
if (stdc_rid != C_BUILTIN_STDC_BIT_CEIL |
| 13176 |
&& stdc_rid != C_BUILTIN_STDC_BIT_FLOOR) |
| 13177 |
{ |
| 13178 |
if (stdc_rid != C_BUILTIN_STDC_HAS_SINGLE_BIT) |
| 13179 |
expr.value = fold_convert_loc (loc, unsigned_type_node, |
| 13180 |
expr.value); |
| 13181 |
break; |
| 13182 |
} |
| 13183 |
/* For __builtin_stdc_bit_ceil (0U) or __builtin_stdc_bit_ceil (1U) |
| 13184 |
or __builtin_stdc_bit_floor (0U) avoid bogus -Wshift-count-* |
| 13185 |
warnings. The LSHIFT_EXPR is in dead code in that case. */ |
| 13186 |
if (integer_zerop (arg) |
| 13187 |
|| (stdc_rid == C_BUILTIN_STDC_BIT_CEIL && integer_onep (arg))) |
| 13188 |
expr.value = build_int_cst (type, 0); |
| 13189 |
else |
| 13190 |
expr.value |
| 13191 |
= build2_loc (loc, LSHIFT_EXPR, type, |
| 13192 |
build_int_cst (type, |
| 13193 |
(stdc_rid |
| 13194 |
== C_BUILTIN_STDC_BIT_CEIL |
| 13195 |
? 2 : 1)), expr.value); |
| 13196 |
if (stdc_rid == C_BUILTIN_STDC_BIT_CEIL) |
| 13197 |
expr.value = build3_loc (loc, COND_EXPR, type, |
| 13198 |
build2_loc (loc, LE_EXPR, |
| 13199 |
boolean_type_node, arg, |
| 13200 |
build_int_cst (type, 1)), |
| 13201 |
build_int_cst (type, 1), |
| 13202 |
expr.value); |
| 13203 |
else |
| 13204 |
expr.value = build3_loc (loc, COND_EXPR, type, |
| 13205 |
build2_loc (loc, EQ_EXPR, |
| 13206 |
boolean_type_node, arg, |
| 13207 |
build_int_cst (type, 0)), |
| 13208 |
build_int_cst (type, 0), |
| 13209 |
expr.value); |
| 13210 |
break; |
| 13211 |
} |
| 13212 |
case RID_AT_SELECTOR: |
| 13213 |
{ |
| 13214 |
gcc_assert (c_dialect_objc ()); |
| 13215 |
c_parser_consume_token (parser); |
| 13216 |
matching_parens parens; |
| 13217 |
if (!parens.require_open (parser)) |
| 13218 |
{ |
| 13219 |
expr.set_error (); |
| 13220 |
break; |
| 13221 |
} |
| 13222 |
tree sel = c_parser_objc_selector_arg (parser); |
| 13223 |
location_t close_loc = c_parser_peek_token (parser)->location; |
| 13224 |
parens.skip_until_found_close (parser); |
| 13225 |
expr.value = objc_build_selector_expr (loc, sel); |
| 13226 |
set_c_expr_source_range (&expr, loc, close_loc); |
| 13227 |
} |
| 13228 |
break; |
| 13229 |
case RID_AT_PROTOCOL: |
| 13230 |
{ |
| 13231 |
gcc_assert (c_dialect_objc ()); |
| 13232 |
c_parser_consume_token (parser); |
| 13233 |
matching_parens parens; |
| 13234 |
if (!parens.require_open (parser)) |
| 13235 |
{ |
| 13236 |
expr.set_error (); |
| 13237 |
break; |
| 13238 |
} |
| 13239 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 13240 |
{ |
| 13241 |
c_parser_error (parser, "expected identifier"); |
| 13242 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 13243 |
expr.set_error (); |
| 13244 |
break; |
| 13245 |
} |
| 13246 |
tree id = c_parser_peek_token (parser)->value; |
| 13247 |
c_parser_consume_token (parser); |
| 13248 |
location_t close_loc = c_parser_peek_token (parser)->location; |
| 13249 |
parens.skip_until_found_close (parser); |
| 13250 |
expr.value = objc_build_protocol_expr (id); |
| 13251 |
set_c_expr_source_range (&expr, loc, close_loc); |
| 13252 |
} |
| 13253 |
break; |
| 13254 |
case RID_AT_ENCODE: |
| 13255 |
{ |
| 13256 |
/* Extension to support C-structures in the archiver. */ |
| 13257 |
gcc_assert (c_dialect_objc ()); |
| 13258 |
c_parser_consume_token (parser); |
| 13259 |
matching_parens parens; |
| 13260 |
if (!parens.require_open (parser)) |
| 13261 |
{ |
| 13262 |
expr.set_error (); |
| 13263 |
break; |
| 13264 |
} |
| 13265 |
t1 = c_parser_type_name (parser); |
| 13266 |
if (t1 == NULL) |
| 13267 |
{ |
| 13268 |
expr.set_error (); |
| 13269 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 13270 |
break; |
| 13271 |
} |
| 13272 |
location_t close_loc = c_parser_peek_token (parser)->location; |
| 13273 |
parens.skip_until_found_close (parser); |
| 13274 |
tree type = groktypename (t1, NULL, NULL); |
| 13275 |
expr.value = objc_build_encode_expr (type); |
| 13276 |
set_c_expr_source_range (&expr, loc, close_loc); |
| 13277 |
} |
| 13278 |
break; |
| 13279 |
case RID_GENERIC: |
| 13280 |
expr = c_parser_generic_selection (parser); |
| 13281 |
break; |
| 13282 |
case RID_OMP_ALL_MEMORY: |
| 13283 |
gcc_assert (flag_openmp); |
| 13284 |
c_parser_consume_token (parser); |
| 13285 |
error_at (loc, "%<omp_all_memory%> may only be used in OpenMP " |
| 13286 |
"%<depend%> clause"); |
| 13287 |
expr.set_error (); |
| 13288 |
break; |
| 13289 |
/* C23 'nullptr' literal. */ |
| 13290 |
case RID_NULLPTR: |
| 13291 |
c_parser_consume_token (parser); |
| 13292 |
expr.value = nullptr_node; |
| 13293 |
set_c_expr_source_range (&expr, tok_range); |
| 13294 |
pedwarn_c11 (loc, OPT_Wpedantic, |
| 13295 |
"ISO C does not support %qs before C23", "nullptr"); |
| 13296 |
break; |
| 13297 |
case RID_TRUE: |
| 13298 |
c_parser_consume_token (parser); |
| 13299 |
expr.value = boolean_true_node; |
| 13300 |
set_c_expr_source_range (&expr, tok_range); |
| 13301 |
break; |
| 13302 |
case RID_FALSE: |
| 13303 |
c_parser_consume_token (parser); |
| 13304 |
expr.value = boolean_false_node; |
| 13305 |
set_c_expr_source_range (&expr, tok_range); |
| 13306 |
break; |
| 13307 |
default: |
| 13308 |
c_parser_error (parser, "expected expression"); |
| 13309 |
expr.set_error (); |
| 13310 |
break; |
| 13311 |
} |
| 13312 |
break; |
| 13313 |
case CPP_OPEN_SQUARE: |
| 13314 |
if (c_dialect_objc ()) |
| 13315 |
{ |
| 13316 |
tree receiver, args; |
| 13317 |
c_parser_consume_token (parser); |
| 13318 |
receiver = c_parser_objc_receiver (parser); |
| 13319 |
args = c_parser_objc_message_args (parser); |
| 13320 |
location_t close_loc = c_parser_peek_token (parser)->location; |
| 13321 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 13322 |
"expected %<]%>"); |
| 13323 |
expr.value = objc_build_message_expr (receiver, args); |
| 13324 |
set_c_expr_source_range (&expr, loc, close_loc); |
| 13325 |
break; |
| 13326 |
} |
| 13327 |
/* Else fall through to report error. */ |
| 13328 |
/* FALLTHRU */ |
| 13329 |
default: |
| 13330 |
c_parser_error (parser, "expected expression"); |
| 13331 |
expr.set_error (); |
| 13332 |
break; |
| 13333 |
} |
| 13334 |
out: |
| 13335 |
return c_parser_postfix_expression_after_primary |
| 13336 |
(parser, EXPR_LOC_OR_LOC (expr.value, loc), expr); |
| 13337 |
} |
| 13338 |
|
| 13339 |
/* Parse a postfix expression after a parenthesized type name: the |
| 13340 |
brace-enclosed initializer of a compound literal, possibly followed |
| 13341 |
by some postfix operators. This is separate because it is not |
| 13342 |
possible to tell until after the type name whether a cast |
| 13343 |
expression has a cast or a compound literal, or whether the operand |
| 13344 |
of sizeof is a parenthesized type name or starts with a compound |
| 13345 |
literal. TYPE_LOC is the location where TYPE_NAME starts--the |
| 13346 |
location of the first token after the parentheses around the type |
| 13347 |
name. */ |
| 13348 |
|
| 13349 |
static struct c_expr |
| 13350 |
c_parser_postfix_expression_after_paren_type (c_parser *parser, |
| 13351 |
struct c_declspecs *scspecs, |
| 13352 |
struct c_type_name *type_name, |
| 13353 |
location_t type_loc) |
| 13354 |
{ |
| 13355 |
tree type; |
| 13356 |
struct c_expr init; |
| 13357 |
bool non_const; |
| 13358 |
struct c_expr expr; |
| 13359 |
location_t start_loc; |
| 13360 |
tree type_expr = NULL_TREE; |
| 13361 |
bool type_expr_const = true; |
| 13362 |
bool constexpr_p = scspecs ? scspecs->constexpr_p : false; |
| 13363 |
unsigned int underspec_state = 0; |
| 13364 |
check_compound_literal_type (type_loc, type_name); |
| 13365 |
rich_location richloc (line_table, type_loc); |
| 13366 |
start_loc = c_parser_peek_token (parser)->location; |
| 13367 |
if (constexpr_p) |
| 13368 |
{ |
| 13369 |
underspec_state = start_underspecified_init (start_loc, NULL_TREE); |
| 13370 |
/* A constexpr compound literal is subject to the constraints on |
| 13371 |
underspecified declarations, which may not declare tags or |
| 13372 |
members or structures or unions; it is undefined behavior to |
| 13373 |
declare the members of an enumeration. Where the structure, |
| 13374 |
union or enumeration type is declared within the compound |
| 13375 |
literal initializer, this is diagnosed elsewhere as a result |
| 13376 |
of the above call to start_underspecified_init. Diagnose |
| 13377 |
here the case of declaring such a type in the type specifiers |
| 13378 |
of the compound literal. */ |
| 13379 |
switch (type_name->specs->typespec_kind) |
| 13380 |
{ |
| 13381 |
case ctsk_tagfirstref: |
| 13382 |
case ctsk_tagfirstref_attrs: |
| 13383 |
error_at (type_loc, "%qT declared in %<constexpr%> compound literal", |
| 13384 |
type_name->specs->type); |
| 13385 |
break; |
| 13386 |
|
| 13387 |
case ctsk_tagdef: |
| 13388 |
error_at (type_loc, "%qT defined in %<constexpr%> compound literal", |
| 13389 |
type_name->specs->type); |
| 13390 |
break; |
| 13391 |
|
| 13392 |
default: |
| 13393 |
break; |
| 13394 |
} |
| 13395 |
} |
| 13396 |
start_init (NULL_TREE, NULL, |
| 13397 |
(global_bindings_p () |
| 13398 |
|| (scspecs && scspecs->storage_class == csc_static) |
| 13399 |
|| constexpr_p), constexpr_p, &richloc); |
| 13400 |
type = groktypename (type_name, &type_expr, &type_expr_const); |
| 13401 |
if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) |
| 13402 |
{ |
| 13403 |
error_at (type_loc, "compound literal has variable size"); |
| 13404 |
type = error_mark_node; |
| 13405 |
} |
| 13406 |
else if (TREE_CODE (type) == FUNCTION_TYPE) |
| 13407 |
{ |
| 13408 |
error_at (type_loc, "compound literal has function type"); |
| 13409 |
type = error_mark_node; |
| 13410 |
} |
| 13411 |
if (constexpr_p && type != error_mark_node) |
| 13412 |
{ |
| 13413 |
tree type_no_array = strip_array_types (type); |
| 13414 |
/* The type of a constexpr object must not be variably modified |
| 13415 |
(which applies to all compound literals), volatile, atomic or |
| 13416 |
restrict qualified or have a member with such a qualifier. |
| 13417 |
const qualification is implicitly added. */ |
| 13418 |
if (TYPE_QUALS (type_no_array) |
| 13419 |
& (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC)) |
| 13420 |
error_at (type_loc, "invalid qualifiers for %<constexpr%> object"); |
| 13421 |
else if (RECORD_OR_UNION_TYPE_P (type_no_array) |
| 13422 |
&& C_TYPE_FIELDS_NON_CONSTEXPR (type_no_array)) |
| 13423 |
error_at (type_loc, "invalid qualifiers for field of " |
| 13424 |
"%<constexpr%> object"); |
| 13425 |
type = c_build_qualified_type (type, |
| 13426 |
(TYPE_QUALS (type_no_array) |
| 13427 |
| TYPE_QUAL_CONST)); |
| 13428 |
} |
| 13429 |
init = c_parser_braced_init (parser, type, false, NULL, NULL_TREE); |
| 13430 |
if (constexpr_p) |
| 13431 |
finish_underspecified_init (NULL_TREE, underspec_state); |
| 13432 |
finish_init (); |
| 13433 |
maybe_warn_string_init (type_loc, type, init); |
| 13434 |
|
| 13435 |
if (type != error_mark_node |
| 13436 |
&& !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) |
| 13437 |
&& current_function_decl) |
| 13438 |
{ |
| 13439 |
error ("compound literal qualified by address-space qualifier"); |
| 13440 |
type = error_mark_node; |
| 13441 |
} |
| 13442 |
|
| 13443 |
if (!pedwarn_c90 (start_loc, OPT_Wpedantic, |
| 13444 |
"ISO C90 forbids compound literals") && scspecs) |
| 13445 |
pedwarn_c11 (start_loc, OPT_Wpedantic, |
| 13446 |
"ISO C forbids storage class specifiers in compound literals " |
| 13447 |
"before C23"); |
| 13448 |
non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) |
| 13449 |
? CONSTRUCTOR_NON_CONST (init.value) |
| 13450 |
: init.original_code == C_MAYBE_CONST_EXPR); |
| 13451 |
non_const |= !type_expr_const; |
| 13452 |
unsigned int alignas_align = 0; |
| 13453 |
if (type != error_mark_node |
| 13454 |
&& type_name->specs->align_log != -1) |
| 13455 |
{ |
| 13456 |
alignas_align = 1U << type_name->specs->align_log; |
| 13457 |
if (alignas_align < min_align_of_type (type)) |
| 13458 |
{ |
| 13459 |
error_at (type_name->specs->locations[cdw_alignas], |
| 13460 |
"%<_Alignas%> specifiers cannot reduce " |
| 13461 |
"alignment of compound literal"); |
| 13462 |
alignas_align = 0; |
| 13463 |
} |
| 13464 |
} |
| 13465 |
expr.value = build_compound_literal (start_loc, type, init.value, non_const, |
| 13466 |
alignas_align, scspecs); |
| 13467 |
set_c_expr_source_range (&expr, init.src_range); |
| 13468 |
expr.m_decimal = 0; |
| 13469 |
expr.original_code = ERROR_MARK; |
| 13470 |
expr.original_type = NULL; |
| 13471 |
if (type != error_mark_node |
| 13472 |
&& expr.value != error_mark_node |
| 13473 |
&& type_expr) |
| 13474 |
{ |
| 13475 |
if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) |
| 13476 |
{ |
| 13477 |
gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); |
| 13478 |
C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; |
| 13479 |
} |
| 13480 |
else |
| 13481 |
{ |
| 13482 |
gcc_assert (!non_const); |
| 13483 |
expr.value = build2 (C_MAYBE_CONST_EXPR, type, |
| 13484 |
type_expr, expr.value); |
| 13485 |
} |
| 13486 |
} |
| 13487 |
return c_parser_postfix_expression_after_primary (parser, start_loc, expr); |
| 13488 |
} |
| 13489 |
|
| 13490 |
/* Callback function for sizeof_pointer_memaccess_warning to compare |
| 13491 |
types. */ |
| 13492 |
|
| 13493 |
static bool |
| 13494 |
sizeof_ptr_memacc_comptypes (tree type1, tree type2) |
| 13495 |
{ |
| 13496 |
return comptypes (type1, type2) == 1; |
| 13497 |
} |
| 13498 |
|
| 13499 |
/* Warn for patterns where abs-like function appears to be used incorrectly, |
| 13500 |
gracefully ignore any non-abs-like function. The warning location should |
| 13501 |
be LOC. FNDECL is the declaration of called function, it must be a |
| 13502 |
BUILT_IN_NORMAL function. ARG is the first and only argument of the |
| 13503 |
call. */ |
| 13504 |
|
| 13505 |
static void |
| 13506 |
warn_for_abs (location_t loc, tree fndecl, tree arg) |
| 13507 |
{ |
| 13508 |
/* Avoid warning in unreachable subexpressions. */ |
| 13509 |
if (c_inhibit_evaluation_warnings) |
| 13510 |
return; |
| 13511 |
|
| 13512 |
tree atype = TREE_TYPE (arg); |
| 13513 |
|
| 13514 |
/* Casts from pointers (and thus arrays and fndecls) will generate |
| 13515 |
-Wint-conversion warnings. Most other wrong types hopefully lead to type |
| 13516 |
mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P |
| 13517 |
types and possibly other exotic types. */ |
| 13518 |
if (!INTEGRAL_TYPE_P (atype) |
| 13519 |
&& !SCALAR_FLOAT_TYPE_P (atype) |
| 13520 |
&& TREE_CODE (atype) != COMPLEX_TYPE) |
| 13521 |
return; |
| 13522 |
|
| 13523 |
enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl); |
| 13524 |
|
| 13525 |
switch (fcode) |
| 13526 |
{ |
| 13527 |
case BUILT_IN_ABS: |
| 13528 |
case BUILT_IN_LABS: |
| 13529 |
case BUILT_IN_LLABS: |
| 13530 |
case BUILT_IN_IMAXABS: |
| 13531 |
if (!INTEGRAL_TYPE_P (atype)) |
| 13532 |
{ |
| 13533 |
if (SCALAR_FLOAT_TYPE_P (atype)) |
| 13534 |
warning_at (loc, OPT_Wabsolute_value, |
| 13535 |
"using integer absolute value function %qD when " |
| 13536 |
"argument is of floating-point type %qT", |
| 13537 |
fndecl, atype); |
| 13538 |
else if (TREE_CODE (atype) == COMPLEX_TYPE) |
| 13539 |
warning_at (loc, OPT_Wabsolute_value, |
| 13540 |
"using integer absolute value function %qD when " |
| 13541 |
"argument is of complex type %qT", fndecl, atype); |
| 13542 |
else |
| 13543 |
gcc_unreachable (); |
| 13544 |
return; |
| 13545 |
} |
| 13546 |
if (TYPE_UNSIGNED (atype)) |
| 13547 |
warning_at (loc, OPT_Wabsolute_value, |
| 13548 |
"taking the absolute value of unsigned type %qT " |
| 13549 |
"has no effect", atype); |
| 13550 |
break; |
| 13551 |
|
| 13552 |
CASE_FLT_FN (BUILT_IN_FABS): |
| 13553 |
CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS): |
| 13554 |
if (!SCALAR_FLOAT_TYPE_P (atype) |
| 13555 |
|| DECIMAL_FLOAT_MODE_P (TYPE_MODE (atype))) |
| 13556 |
{ |
| 13557 |
if (INTEGRAL_TYPE_P (atype)) |
| 13558 |
warning_at (loc, OPT_Wabsolute_value, |
| 13559 |
"using floating-point absolute value function %qD " |
| 13560 |
"when argument is of integer type %qT", fndecl, atype); |
| 13561 |
else if (DECIMAL_FLOAT_TYPE_P (atype)) |
| 13562 |
warning_at (loc, OPT_Wabsolute_value, |
| 13563 |
"using floating-point absolute value function %qD " |
| 13564 |
"when argument is of decimal floating-point type %qT", |
| 13565 |
fndecl, atype); |
| 13566 |
else if (TREE_CODE (atype) == COMPLEX_TYPE) |
| 13567 |
warning_at (loc, OPT_Wabsolute_value, |
| 13568 |
"using floating-point absolute value function %qD when " |
| 13569 |
"argument is of complex type %qT", fndecl, atype); |
| 13570 |
else |
| 13571 |
gcc_unreachable (); |
| 13572 |
return; |
| 13573 |
} |
| 13574 |
break; |
| 13575 |
|
| 13576 |
CASE_FLT_FN (BUILT_IN_CABS): |
| 13577 |
if (TREE_CODE (atype) != COMPLEX_TYPE) |
| 13578 |
{ |
| 13579 |
if (INTEGRAL_TYPE_P (atype)) |
| 13580 |
warning_at (loc, OPT_Wabsolute_value, |
| 13581 |
"using complex absolute value function %qD when " |
| 13582 |
"argument is of integer type %qT", fndecl, atype); |
| 13583 |
else if (SCALAR_FLOAT_TYPE_P (atype)) |
| 13584 |
warning_at (loc, OPT_Wabsolute_value, |
| 13585 |
"using complex absolute value function %qD when " |
| 13586 |
"argument is of floating-point type %qT", |
| 13587 |
fndecl, atype); |
| 13588 |
else |
| 13589 |
gcc_unreachable (); |
| 13590 |
|
| 13591 |
return; |
| 13592 |
} |
| 13593 |
break; |
| 13594 |
|
| 13595 |
case BUILT_IN_FABSD32: |
| 13596 |
case BUILT_IN_FABSD64: |
| 13597 |
case BUILT_IN_FABSD128: |
| 13598 |
case BUILT_IN_FABSD64X: |
| 13599 |
if (!DECIMAL_FLOAT_TYPE_P (atype)) |
| 13600 |
{ |
| 13601 |
if (INTEGRAL_TYPE_P (atype)) |
| 13602 |
warning_at (loc, OPT_Wabsolute_value, |
| 13603 |
"using decimal floating-point absolute value " |
| 13604 |
"function %qD when argument is of integer type %qT", |
| 13605 |
fndecl, atype); |
| 13606 |
else if (SCALAR_FLOAT_TYPE_P (atype)) |
| 13607 |
warning_at (loc, OPT_Wabsolute_value, |
| 13608 |
"using decimal floating-point absolute value " |
| 13609 |
"function %qD when argument is of floating-point " |
| 13610 |
"type %qT", fndecl, atype); |
| 13611 |
else if (TREE_CODE (atype) == COMPLEX_TYPE) |
| 13612 |
warning_at (loc, OPT_Wabsolute_value, |
| 13613 |
"using decimal floating-point absolute value " |
| 13614 |
"function %qD when argument is of complex type %qT", |
| 13615 |
fndecl, atype); |
| 13616 |
else |
| 13617 |
gcc_unreachable (); |
| 13618 |
return; |
| 13619 |
} |
| 13620 |
break; |
| 13621 |
|
| 13622 |
default: |
| 13623 |
return; |
| 13624 |
} |
| 13625 |
|
| 13626 |
if (!TYPE_ARG_TYPES (TREE_TYPE (fndecl))) |
| 13627 |
return; |
| 13628 |
|
| 13629 |
tree ftype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); |
| 13630 |
if (TREE_CODE (atype) == COMPLEX_TYPE) |
| 13631 |
{ |
| 13632 |
gcc_assert (TREE_CODE (ftype) == COMPLEX_TYPE); |
| 13633 |
atype = TREE_TYPE (atype); |
| 13634 |
ftype = TREE_TYPE (ftype); |
| 13635 |
} |
| 13636 |
|
| 13637 |
if (TYPE_PRECISION (ftype) < TYPE_PRECISION (atype)) |
| 13638 |
warning_at (loc, OPT_Wabsolute_value, |
| 13639 |
"absolute value function %qD given an argument of type %qT " |
| 13640 |
"but has parameter of type %qT which may cause truncation " |
| 13641 |
"of value", fndecl, atype, ftype); |
| 13642 |
} |
| 13643 |
|
| 13644 |
|
| 13645 |
/* Parse a postfix expression after the initial primary or compound |
| 13646 |
literal; that is, parse a series of postfix operators. |
| 13647 |
|
| 13648 |
EXPR_LOC is the location of the primary expression. */ |
| 13649 |
|
| 13650 |
static struct c_expr |
| 13651 |
c_parser_postfix_expression_after_primary (c_parser *parser, |
| 13652 |
location_t expr_loc, |
| 13653 |
struct c_expr expr) |
| 13654 |
{ |
| 13655 |
struct c_expr orig_expr; |
| 13656 |
tree ident, idx, len; |
| 13657 |
location_t sizeof_arg_loc[6], comp_loc; |
| 13658 |
tree sizeof_arg[6]; |
| 13659 |
unsigned int literal_zero_mask; |
| 13660 |
unsigned int i; |
| 13661 |
vec<tree, va_gc> *exprlist; |
| 13662 |
vec<tree, va_gc> *origtypes = NULL; |
| 13663 |
vec<location_t> arg_loc = vNULL; |
| 13664 |
location_t start; |
| 13665 |
location_t finish; |
| 13666 |
|
| 13667 |
while (true) |
| 13668 |
{ |
| 13669 |
location_t op_loc = c_parser_peek_token (parser)->location; |
| 13670 |
switch (c_parser_peek_token (parser)->type) |
| 13671 |
{ |
| 13672 |
case CPP_OPEN_SQUARE: |
| 13673 |
/* Array reference. */ |
| 13674 |
c_parser_consume_token (parser); |
| 13675 |
idx = len = NULL_TREE; |
| 13676 |
if (!c_omp_array_section_p |
| 13677 |
|| c_parser_next_token_is_not (parser, CPP_COLON)) |
| 13678 |
idx = c_parser_expression (parser).value; |
| 13679 |
|
| 13680 |
if (c_omp_array_section_p |
| 13681 |
&& c_parser_next_token_is (parser, CPP_COLON)) |
| 13682 |
{ |
| 13683 |
c_parser_consume_token (parser); |
| 13684 |
if (c_parser_next_token_is_not (parser, CPP_CLOSE_SQUARE)) |
| 13685 |
len = c_parser_expression (parser).value; |
| 13686 |
|
| 13687 |
expr.value = build_omp_array_section (op_loc, expr.value, idx, |
| 13688 |
len); |
| 13689 |
} |
| 13690 |
else |
| 13691 |
expr.value = build_array_ref (op_loc, expr.value, idx); |
| 13692 |
|
| 13693 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 13694 |
"expected %<]%>"); |
| 13695 |
|
| 13696 |
start = expr.get_start (); |
| 13697 |
finish = parser->tokens_buf[0].location; |
| 13698 |
set_c_expr_source_range (&expr, start, finish); |
| 13699 |
expr.original_code = ERROR_MARK; |
| 13700 |
expr.original_type = NULL; |
| 13701 |
expr.m_decimal = 0; |
| 13702 |
break; |
| 13703 |
case CPP_OPEN_PAREN: |
| 13704 |
/* Function call. */ |
| 13705 |
{ |
| 13706 |
matching_parens parens; |
| 13707 |
parens.consume_open (parser); |
| 13708 |
for (i = 0; i < 6; i++) |
| 13709 |
{ |
| 13710 |
sizeof_arg[i] = NULL_TREE; |
| 13711 |
sizeof_arg_loc[i] = UNKNOWN_LOCATION; |
| 13712 |
} |
| 13713 |
literal_zero_mask = 0; |
| 13714 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 13715 |
exprlist = NULL; |
| 13716 |
else if (TREE_CODE (expr.value) == FUNCTION_DECL |
| 13717 |
&& fndecl_built_in_p (expr.value, BUILT_IN_CLASSIFY_TYPE) |
| 13718 |
&& c_parser_next_tokens_start_typename (parser, |
| 13719 |
cla_prefer_id)) |
| 13720 |
{ |
| 13721 |
/* __builtin_classify_type (type) */ |
| 13722 |
c_inhibit_evaluation_warnings++; |
| 13723 |
in_alignof++; |
| 13724 |
struct c_type_name *type = c_parser_type_name (parser); |
| 13725 |
c_inhibit_evaluation_warnings--; |
| 13726 |
in_alignof--; |
| 13727 |
struct c_typespec ret; |
| 13728 |
ret.expr = NULL_TREE; |
| 13729 |
ret.spec = error_mark_node; |
| 13730 |
ret.expr_const_operands = false; |
| 13731 |
if (type != NULL) |
| 13732 |
ret.spec = groktypename (type, &ret.expr, |
| 13733 |
&ret.expr_const_operands); |
| 13734 |
parens.skip_until_found_close (parser); |
| 13735 |
expr.value = build_int_cst (integer_type_node, |
| 13736 |
type_to_class (ret.spec)); |
| 13737 |
break; |
| 13738 |
} |
| 13739 |
else |
| 13740 |
exprlist = c_parser_expr_list (parser, true, false, &origtypes, |
| 13741 |
sizeof_arg_loc, sizeof_arg, |
| 13742 |
&arg_loc, &literal_zero_mask); |
| 13743 |
parens.skip_until_found_close (parser); |
| 13744 |
} |
| 13745 |
orig_expr = expr; |
| 13746 |
mark_exp_read (expr.value); |
| 13747 |
if (warn_sizeof_pointer_memaccess) |
| 13748 |
sizeof_pointer_memaccess_warning (sizeof_arg_loc, |
| 13749 |
expr.value, exprlist, |
| 13750 |
sizeof_arg, |
| 13751 |
sizeof_ptr_memacc_comptypes); |
| 13752 |
if (TREE_CODE (expr.value) == FUNCTION_DECL) |
| 13753 |
{ |
| 13754 |
if (fndecl_built_in_p (expr.value, BUILT_IN_MEMSET) |
| 13755 |
&& vec_safe_length (exprlist) == 3) |
| 13756 |
{ |
| 13757 |
tree arg0 = (*exprlist)[0]; |
| 13758 |
tree arg2 = (*exprlist)[2]; |
| 13759 |
warn_for_memset (expr_loc, arg0, arg2, literal_zero_mask); |
| 13760 |
} |
| 13761 |
if (warn_absolute_value |
| 13762 |
&& fndecl_built_in_p (expr.value, BUILT_IN_NORMAL) |
| 13763 |
&& vec_safe_length (exprlist) == 1) |
| 13764 |
warn_for_abs (expr_loc, expr.value, (*exprlist)[0]); |
| 13765 |
if (parser->omp_for_parse_state |
| 13766 |
&& parser->omp_for_parse_state->in_intervening_code |
| 13767 |
&& omp_runtime_api_call (expr.value)) |
| 13768 |
{ |
| 13769 |
error_at (expr_loc, "calls to the OpenMP runtime API are " |
| 13770 |
"not permitted in intervening code"); |
| 13771 |
parser->omp_for_parse_state->fail = true; |
| 13772 |
} |
| 13773 |
if (warn_calloc_transposed_args) |
| 13774 |
if (tree attr = lookup_attribute ("alloc_size", |
| 13775 |
TYPE_ATTRIBUTES |
| 13776 |
(TREE_TYPE (expr.value)))) |
| 13777 |
if (TREE_VALUE (attr) && TREE_CHAIN (TREE_VALUE (attr))) |
| 13778 |
warn_for_calloc (sizeof_arg_loc, expr.value, exprlist, |
| 13779 |
sizeof_arg, attr); |
| 13780 |
} |
| 13781 |
|
| 13782 |
start = expr.get_start (); |
| 13783 |
finish = parser->tokens_buf[0].get_finish (); |
| 13784 |
expr.value |
| 13785 |
= c_build_function_call_vec (expr_loc, arg_loc, expr.value, |
| 13786 |
exprlist, origtypes); |
| 13787 |
set_c_expr_source_range (&expr, start, finish); |
| 13788 |
expr.m_decimal = 0; |
| 13789 |
|
| 13790 |
expr.original_code = ERROR_MARK; |
| 13791 |
if (TREE_CODE (expr.value) == INTEGER_CST |
| 13792 |
&& TREE_CODE (orig_expr.value) == FUNCTION_DECL |
| 13793 |
&& fndecl_built_in_p (orig_expr.value, BUILT_IN_CONSTANT_P)) |
| 13794 |
expr.original_code = C_MAYBE_CONST_EXPR; |
| 13795 |
expr.original_type = NULL; |
| 13796 |
if (exprlist) |
| 13797 |
{ |
| 13798 |
release_tree_vector (exprlist); |
| 13799 |
release_tree_vector (origtypes); |
| 13800 |
} |
| 13801 |
arg_loc.release (); |
| 13802 |
break; |
| 13803 |
case CPP_DOT: |
| 13804 |
/* Structure element reference. */ |
| 13805 |
c_parser_consume_token (parser); |
| 13806 |
expr = default_function_array_conversion (expr_loc, expr); |
| 13807 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 13808 |
{ |
| 13809 |
c_token *comp_tok = c_parser_peek_token (parser); |
| 13810 |
ident = comp_tok->value; |
| 13811 |
comp_loc = comp_tok->location; |
| 13812 |
} |
| 13813 |
else |
| 13814 |
{ |
| 13815 |
c_parser_error (parser, "expected identifier"); |
| 13816 |
expr.set_error (); |
| 13817 |
expr.original_code = ERROR_MARK; |
| 13818 |
expr.original_type = NULL; |
| 13819 |
return expr; |
| 13820 |
} |
| 13821 |
start = expr.get_start (); |
| 13822 |
finish = c_parser_peek_token (parser)->get_finish (); |
| 13823 |
c_parser_consume_token (parser); |
| 13824 |
expr.value = build_component_ref (op_loc, expr.value, ident, |
| 13825 |
comp_loc, UNKNOWN_LOCATION); |
| 13826 |
set_c_expr_source_range (&expr, start, finish); |
| 13827 |
expr.original_code = ERROR_MARK; |
| 13828 |
if (TREE_CODE (expr.value) != COMPONENT_REF) |
| 13829 |
expr.original_type = NULL; |
| 13830 |
else |
| 13831 |
{ |
| 13832 |
/* Remember the original type of a bitfield. */ |
| 13833 |
tree field = TREE_OPERAND (expr.value, 1); |
| 13834 |
if (TREE_CODE (field) != FIELD_DECL) |
| 13835 |
expr.original_type = NULL; |
| 13836 |
else |
| 13837 |
expr.original_type = DECL_BIT_FIELD_TYPE (field); |
| 13838 |
} |
| 13839 |
expr.m_decimal = 0; |
| 13840 |
break; |
| 13841 |
case CPP_DEREF: |
| 13842 |
/* Structure element reference. */ |
| 13843 |
c_parser_consume_token (parser); |
| 13844 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false); |
| 13845 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 13846 |
{ |
| 13847 |
c_token *comp_tok = c_parser_peek_token (parser); |
| 13848 |
ident = comp_tok->value; |
| 13849 |
comp_loc = comp_tok->location; |
| 13850 |
} |
| 13851 |
else |
| 13852 |
{ |
| 13853 |
c_parser_error (parser, "expected identifier"); |
| 13854 |
expr.set_error (); |
| 13855 |
expr.original_code = ERROR_MARK; |
| 13856 |
expr.original_type = NULL; |
| 13857 |
return expr; |
| 13858 |
} |
| 13859 |
start = expr.get_start (); |
| 13860 |
finish = c_parser_peek_token (parser)->get_finish (); |
| 13861 |
c_parser_consume_token (parser); |
| 13862 |
expr.value = build_component_ref (op_loc, |
| 13863 |
build_indirect_ref (op_loc, |
| 13864 |
expr.value, |
| 13865 |
RO_ARROW), |
| 13866 |
ident, comp_loc, |
| 13867 |
expr.get_location ()); |
| 13868 |
set_c_expr_source_range (&expr, start, finish); |
| 13869 |
expr.original_code = ERROR_MARK; |
| 13870 |
if (TREE_CODE (expr.value) != COMPONENT_REF) |
| 13871 |
expr.original_type = NULL; |
| 13872 |
else |
| 13873 |
{ |
| 13874 |
/* Remember the original type of a bitfield. */ |
| 13875 |
tree field = TREE_OPERAND (expr.value, 1); |
| 13876 |
if (TREE_CODE (field) != FIELD_DECL) |
| 13877 |
expr.original_type = NULL; |
| 13878 |
else |
| 13879 |
expr.original_type = DECL_BIT_FIELD_TYPE (field); |
| 13880 |
} |
| 13881 |
expr.m_decimal = 0; |
| 13882 |
break; |
| 13883 |
case CPP_PLUS_PLUS: |
| 13884 |
/* Postincrement. */ |
| 13885 |
start = expr.get_start (); |
| 13886 |
finish = c_parser_peek_token (parser)->get_finish (); |
| 13887 |
c_parser_consume_token (parser); |
| 13888 |
expr = default_function_array_read_conversion (expr_loc, expr); |
| 13889 |
expr.value = build_unary_op (op_loc, POSTINCREMENT_EXPR, |
| 13890 |
expr.value, false); |
| 13891 |
set_c_expr_source_range (&expr, start, finish); |
| 13892 |
expr.original_code = ERROR_MARK; |
| 13893 |
expr.original_type = NULL; |
| 13894 |
break; |
| 13895 |
case CPP_MINUS_MINUS: |
| 13896 |
/* Postdecrement. */ |
| 13897 |
start = expr.get_start (); |
| 13898 |
finish = c_parser_peek_token (parser)->get_finish (); |
| 13899 |
c_parser_consume_token (parser); |
| 13900 |
expr = default_function_array_read_conversion (expr_loc, expr); |
| 13901 |
expr.value = build_unary_op (op_loc, POSTDECREMENT_EXPR, |
| 13902 |
expr.value, false); |
| 13903 |
set_c_expr_source_range (&expr, start, finish); |
| 13904 |
expr.original_code = ERROR_MARK; |
| 13905 |
expr.original_type = NULL; |
| 13906 |
break; |
| 13907 |
default: |
| 13908 |
return expr; |
| 13909 |
} |
| 13910 |
} |
| 13911 |
} |
| 13912 |
|
| 13913 |
/* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17). |
| 13914 |
|
| 13915 |
expression: |
| 13916 |
assignment-expression |
| 13917 |
expression , assignment-expression |
| 13918 |
*/ |
| 13919 |
|
| 13920 |
static struct c_expr |
| 13921 |
c_parser_expression (c_parser *parser) |
| 13922 |
{ |
| 13923 |
location_t tloc = c_parser_peek_token (parser)->location; |
| 13924 |
struct c_expr expr; |
| 13925 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 13926 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 13927 |
expr = convert_lvalue_to_rvalue (tloc, expr, true, false); |
| 13928 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 13929 |
{ |
| 13930 |
struct c_expr next; |
| 13931 |
tree lhsval; |
| 13932 |
location_t loc = c_parser_peek_token (parser)->location; |
| 13933 |
location_t expr_loc; |
| 13934 |
c_parser_consume_token (parser); |
| 13935 |
expr_loc = c_parser_peek_token (parser)->location; |
| 13936 |
lhsval = expr.value; |
| 13937 |
while (TREE_CODE (lhsval) == COMPOUND_EXPR |
| 13938 |
|| TREE_CODE (lhsval) == NOP_EXPR) |
| 13939 |
{ |
| 13940 |
if (TREE_CODE (lhsval) == COMPOUND_EXPR) |
| 13941 |
lhsval = TREE_OPERAND (lhsval, 1); |
| 13942 |
else |
| 13943 |
lhsval = TREE_OPERAND (lhsval, 0); |
| 13944 |
} |
| 13945 |
if (DECL_P (lhsval) || handled_component_p (lhsval)) |
| 13946 |
mark_exp_read (lhsval); |
| 13947 |
if (c_parser_next_token_is (parser, CPP_EMBED)) |
| 13948 |
{ |
| 13949 |
/* Users aren't interested in milions of -Wunused-value |
| 13950 |
warnings when using #embed inside of a comma expression, |
| 13951 |
and one CPP_NUMBER plus CPP_COMMA before it and one |
| 13952 |
CPP_COMMA plus CPP_NUMBER after it is guaranteed by |
| 13953 |
the preprocessor. Thus, parse the whole CPP_EMBED just |
| 13954 |
as a single INTEGER_CST, the last byte in it. */ |
| 13955 |
c_token *embed = c_parser_peek_token (parser); |
| 13956 |
tree val = embed->value; |
| 13957 |
unsigned last = RAW_DATA_LENGTH (val) - 1; |
| 13958 |
next.value = build_int_cst (TREE_TYPE (val), |
| 13959 |
RAW_DATA_UCHAR_ELT (val, last)); |
| 13960 |
next.original_type = integer_type_node; |
| 13961 |
c_parser_consume_token (parser); |
| 13962 |
} |
| 13963 |
else |
| 13964 |
{ |
| 13965 |
next = c_parser_expr_no_commas (parser, NULL); |
| 13966 |
next = convert_lvalue_to_rvalue (expr_loc, next, true, false); |
| 13967 |
} |
| 13968 |
expr.value = build_compound_expr (loc, expr.value, next.value); |
| 13969 |
expr.original_code = COMPOUND_EXPR; |
| 13970 |
expr.original_type = next.original_type; |
| 13971 |
expr.m_decimal = 0; |
| 13972 |
} |
| 13973 |
return expr; |
| 13974 |
} |
| 13975 |
|
| 13976 |
/* Parse an expression and convert functions or arrays to pointers and |
| 13977 |
lvalues to rvalues. */ |
| 13978 |
|
| 13979 |
static struct c_expr |
| 13980 |
c_parser_expression_conv (c_parser *parser) |
| 13981 |
{ |
| 13982 |
struct c_expr expr; |
| 13983 |
location_t loc = c_parser_peek_token (parser)->location; |
| 13984 |
expr = c_parser_expression (parser); |
| 13985 |
expr = convert_lvalue_to_rvalue (loc, expr, true, false); |
| 13986 |
return expr; |
| 13987 |
} |
| 13988 |
|
| 13989 |
/* Helper function of c_parser_expr_list. Check if IDXth (0 based) |
| 13990 |
argument is a literal zero alone and if so, set it in literal_zero_mask. */ |
| 13991 |
|
| 13992 |
static inline void |
| 13993 |
c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask, |
| 13994 |
unsigned int idx) |
| 13995 |
{ |
| 13996 |
if (idx >= HOST_BITS_PER_INT) |
| 13997 |
return; |
| 13998 |
|
| 13999 |
c_token *tok = c_parser_peek_token (parser); |
| 14000 |
switch (tok->type) |
| 14001 |
{ |
| 14002 |
case CPP_NUMBER: |
| 14003 |
case CPP_CHAR: |
| 14004 |
case CPP_WCHAR: |
| 14005 |
case CPP_CHAR16: |
| 14006 |
case CPP_CHAR32: |
| 14007 |
case CPP_UTF8CHAR: |
| 14008 |
/* If a parameter is literal zero alone, remember it |
| 14009 |
for -Wmemset-transposed-args warning. */ |
| 14010 |
if (integer_zerop (tok->value) |
| 14011 |
&& !TREE_OVERFLOW (tok->value) |
| 14012 |
&& (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 14013 |
|| c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) |
| 14014 |
*literal_zero_mask |= 1U << idx; |
| 14015 |
default: |
| 14016 |
break; |
| 14017 |
} |
| 14018 |
} |
| 14019 |
|
| 14020 |
/* Parse a non-empty list of expressions. If CONVERT_P, convert |
| 14021 |
functions and arrays to pointers and lvalues to rvalues. If |
| 14022 |
FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the |
| 14023 |
locations of function arguments into this vector. |
| 14024 |
|
| 14025 |
nonempty-expr-list: |
| 14026 |
assignment-expression |
| 14027 |
nonempty-expr-list , assignment-expression |
| 14028 |
*/ |
| 14029 |
|
| 14030 |
static vec<tree, va_gc> * |
| 14031 |
c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, |
| 14032 |
vec<tree, va_gc> **p_orig_types, |
| 14033 |
location_t *sizeof_arg_loc, tree *sizeof_arg, |
| 14034 |
vec<location_t> *locations, |
| 14035 |
unsigned int *literal_zero_mask) |
| 14036 |
{ |
| 14037 |
vec<tree, va_gc> *ret; |
| 14038 |
vec<tree, va_gc> *orig_types; |
| 14039 |
struct c_expr expr; |
| 14040 |
unsigned int idx = 0; |
| 14041 |
bool save_c_omp_array_section_p = c_omp_array_section_p; |
| 14042 |
c_omp_array_section_p = false; |
| 14043 |
|
| 14044 |
ret = make_tree_vector (); |
| 14045 |
if (p_orig_types == NULL) |
| 14046 |
orig_types = NULL; |
| 14047 |
else |
| 14048 |
orig_types = make_tree_vector (); |
| 14049 |
|
| 14050 |
if (literal_zero_mask) |
| 14051 |
c_parser_check_literal_zero (parser, literal_zero_mask, 0); |
| 14052 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 14053 |
if (convert_p) |
| 14054 |
expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true, true); |
| 14055 |
if (fold_p) |
| 14056 |
expr.value = c_fully_fold (expr.value, false, NULL); |
| 14057 |
ret->quick_push (expr.value); |
| 14058 |
if (orig_types) |
| 14059 |
orig_types->quick_push (expr.original_type); |
| 14060 |
if (locations) |
| 14061 |
locations->safe_push (expr.get_location ()); |
| 14062 |
if (sizeof_arg != NULL |
| 14063 |
&& (expr.original_code == SIZEOF_EXPR |
| 14064 |
|| expr.original_code == PAREN_SIZEOF_EXPR)) |
| 14065 |
{ |
| 14066 |
sizeof_arg[0] = c_last_sizeof_arg; |
| 14067 |
sizeof_arg_loc[0] = c_last_sizeof_loc; |
| 14068 |
} |
| 14069 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 14070 |
{ |
| 14071 |
c_parser_consume_token (parser); |
| 14072 |
if (c_parser_next_token_is (parser, CPP_EMBED)) |
| 14073 |
{ |
| 14074 |
c_token *embed = c_parser_peek_token (parser); |
| 14075 |
tree value = embed->value; |
| 14076 |
expr.original_code = INTEGER_CST; |
| 14077 |
expr.original_type = integer_type_node; |
| 14078 |
expr.value = NULL_TREE; |
| 14079 |
set_c_expr_source_range (&expr, embed->get_range ()); |
| 14080 |
expr.m_decimal = 0; |
| 14081 |
for (unsigned int i = 0; i < (unsigned) RAW_DATA_LENGTH (value); i++) |
| 14082 |
{ |
| 14083 |
if (literal_zero_mask |
| 14084 |
&& idx + 1 < HOST_BITS_PER_INT |
| 14085 |
&& RAW_DATA_POINTER (value)[i] == 0) |
| 14086 |
*literal_zero_mask |= 1U << (idx + 1); |
| 14087 |
expr.value = build_int_cst (integer_type_node, |
| 14088 |
RAW_DATA_UCHAR_ELT (value, i)); |
| 14089 |
vec_safe_push (ret, expr.value); |
| 14090 |
if (orig_types) |
| 14091 |
vec_safe_push (orig_types, expr.original_type); |
| 14092 |
if (locations) |
| 14093 |
locations->safe_push (expr.get_location ()); |
| 14094 |
++idx; |
| 14095 |
} |
| 14096 |
c_parser_consume_token (parser); |
| 14097 |
continue; |
| 14098 |
} |
| 14099 |
if (literal_zero_mask) |
| 14100 |
c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1); |
| 14101 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 14102 |
if (convert_p) |
| 14103 |
expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true, |
| 14104 |
true); |
| 14105 |
if (fold_p) |
| 14106 |
expr.value = c_fully_fold (expr.value, false, NULL); |
| 14107 |
vec_safe_push (ret, expr.value); |
| 14108 |
if (orig_types) |
| 14109 |
vec_safe_push (orig_types, expr.original_type); |
| 14110 |
if (locations) |
| 14111 |
locations->safe_push (expr.get_location ()); |
| 14112 |
if (++idx < 6 |
| 14113 |
&& sizeof_arg != NULL |
| 14114 |
&& (expr.original_code == SIZEOF_EXPR |
| 14115 |
|| expr.original_code == PAREN_SIZEOF_EXPR)) |
| 14116 |
{ |
| 14117 |
sizeof_arg[idx] = c_last_sizeof_arg; |
| 14118 |
sizeof_arg_loc[idx] = c_last_sizeof_loc; |
| 14119 |
} |
| 14120 |
} |
| 14121 |
if (orig_types) |
| 14122 |
*p_orig_types = orig_types; |
| 14123 |
c_omp_array_section_p = save_c_omp_array_section_p; |
| 14124 |
return ret; |
| 14125 |
} |
| 14126 |
|
| 14127 |
/* Parse Objective-C-specific constructs. */ |
| 14128 |
|
| 14129 |
/* Parse an objc-class-definition. |
| 14130 |
|
| 14131 |
objc-class-definition: |
| 14132 |
@interface identifier objc-superclass[opt] objc-protocol-refs[opt] |
| 14133 |
objc-class-instance-variables[opt] objc-methodprotolist @end |
| 14134 |
@implementation identifier objc-superclass[opt] |
| 14135 |
objc-class-instance-variables[opt] |
| 14136 |
@interface identifier ( identifier ) objc-protocol-refs[opt] |
| 14137 |
objc-methodprotolist @end |
| 14138 |
@interface identifier ( ) objc-protocol-refs[opt] |
| 14139 |
objc-methodprotolist @end |
| 14140 |
@implementation identifier ( identifier ) |
| 14141 |
|
| 14142 |
objc-superclass: |
| 14143 |
: identifier |
| 14144 |
|
| 14145 |
"@interface identifier (" must start "@interface identifier ( |
| 14146 |
identifier ) ...": objc-methodprotolist in the first production may |
| 14147 |
not start with a parenthesized identifier as a declarator of a data |
| 14148 |
definition with no declaration specifiers if the objc-superclass, |
| 14149 |
objc-protocol-refs and objc-class-instance-variables are omitted. */ |
| 14150 |
|
| 14151 |
static void |
| 14152 |
c_parser_objc_class_definition (c_parser *parser, tree attributes) |
| 14153 |
{ |
| 14154 |
bool iface_p; |
| 14155 |
tree id1; |
| 14156 |
tree superclass; |
| 14157 |
if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) |
| 14158 |
iface_p = true; |
| 14159 |
else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) |
| 14160 |
iface_p = false; |
| 14161 |
else |
| 14162 |
gcc_unreachable (); |
| 14163 |
|
| 14164 |
c_parser_consume_token (parser); |
| 14165 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14166 |
{ |
| 14167 |
c_parser_error (parser, "expected identifier"); |
| 14168 |
return; |
| 14169 |
} |
| 14170 |
id1 = c_parser_peek_token (parser)->value; |
| 14171 |
location_t loc1 = c_parser_peek_token (parser)->location; |
| 14172 |
c_parser_consume_token (parser); |
| 14173 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 14174 |
{ |
| 14175 |
/* We have a category or class extension. */ |
| 14176 |
tree id2; |
| 14177 |
tree proto = NULL_TREE; |
| 14178 |
matching_parens parens; |
| 14179 |
parens.consume_open (parser); |
| 14180 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14181 |
{ |
| 14182 |
if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 14183 |
{ |
| 14184 |
/* We have a class extension. */ |
| 14185 |
id2 = NULL_TREE; |
| 14186 |
} |
| 14187 |
else |
| 14188 |
{ |
| 14189 |
c_parser_error (parser, "expected identifier or %<)%>"); |
| 14190 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 14191 |
return; |
| 14192 |
} |
| 14193 |
} |
| 14194 |
else |
| 14195 |
{ |
| 14196 |
id2 = c_parser_peek_token (parser)->value; |
| 14197 |
c_parser_consume_token (parser); |
| 14198 |
} |
| 14199 |
parens.skip_until_found_close (parser); |
| 14200 |
if (!iface_p) |
| 14201 |
{ |
| 14202 |
objc_start_category_implementation (id1, id2); |
| 14203 |
return; |
| 14204 |
} |
| 14205 |
if (c_parser_next_token_is (parser, CPP_LESS)) |
| 14206 |
proto = c_parser_objc_protocol_refs (parser); |
| 14207 |
objc_start_category_interface (id1, id2, proto, attributes); |
| 14208 |
c_parser_objc_methodprotolist (parser); |
| 14209 |
c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); |
| 14210 |
objc_finish_interface (); |
| 14211 |
return; |
| 14212 |
} |
| 14213 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 14214 |
{ |
| 14215 |
c_parser_consume_token (parser); |
| 14216 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14217 |
{ |
| 14218 |
c_parser_error (parser, "expected identifier"); |
| 14219 |
return; |
| 14220 |
} |
| 14221 |
superclass = c_parser_peek_token (parser)->value; |
| 14222 |
c_parser_consume_token (parser); |
| 14223 |
} |
| 14224 |
else |
| 14225 |
superclass = NULL_TREE; |
| 14226 |
if (iface_p) |
| 14227 |
{ |
| 14228 |
tree proto = NULL_TREE; |
| 14229 |
if (c_parser_next_token_is (parser, CPP_LESS)) |
| 14230 |
proto = c_parser_objc_protocol_refs (parser); |
| 14231 |
objc_start_class_interface (id1, loc1, superclass, proto, attributes); |
| 14232 |
} |
| 14233 |
else |
| 14234 |
objc_start_class_implementation (id1, superclass); |
| 14235 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 14236 |
c_parser_objc_class_instance_variables (parser); |
| 14237 |
if (iface_p) |
| 14238 |
{ |
| 14239 |
objc_continue_interface (); |
| 14240 |
c_parser_objc_methodprotolist (parser); |
| 14241 |
c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); |
| 14242 |
objc_finish_interface (); |
| 14243 |
} |
| 14244 |
else |
| 14245 |
{ |
| 14246 |
objc_continue_implementation (); |
| 14247 |
return; |
| 14248 |
} |
| 14249 |
} |
| 14250 |
|
| 14251 |
/* Parse objc-class-instance-variables. |
| 14252 |
|
| 14253 |
objc-class-instance-variables: |
| 14254 |
{ objc-instance-variable-decl-list[opt] } |
| 14255 |
|
| 14256 |
objc-instance-variable-decl-list: |
| 14257 |
objc-visibility-spec |
| 14258 |
objc-instance-variable-decl ; |
| 14259 |
; |
| 14260 |
objc-instance-variable-decl-list objc-visibility-spec |
| 14261 |
objc-instance-variable-decl-list objc-instance-variable-decl ; |
| 14262 |
objc-instance-variable-decl-list ; |
| 14263 |
|
| 14264 |
objc-visibility-spec: |
| 14265 |
@private |
| 14266 |
@protected |
| 14267 |
@public |
| 14268 |
|
| 14269 |
objc-instance-variable-decl: |
| 14270 |
struct-declaration |
| 14271 |
*/ |
| 14272 |
|
| 14273 |
static void |
| 14274 |
c_parser_objc_class_instance_variables (c_parser *parser) |
| 14275 |
{ |
| 14276 |
gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); |
| 14277 |
c_parser_consume_token (parser); |
| 14278 |
while (c_parser_next_token_is_not (parser, CPP_EOF)) |
| 14279 |
{ |
| 14280 |
tree decls; |
| 14281 |
/* Parse any stray semicolon. */ |
| 14282 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 14283 |
{ |
| 14284 |
pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 14285 |
"extra semicolon"); |
| 14286 |
c_parser_consume_token (parser); |
| 14287 |
continue; |
| 14288 |
} |
| 14289 |
/* Stop if at the end of the instance variables. */ |
| 14290 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 14291 |
{ |
| 14292 |
c_parser_consume_token (parser); |
| 14293 |
break; |
| 14294 |
} |
| 14295 |
/* Parse any objc-visibility-spec. */ |
| 14296 |
if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) |
| 14297 |
{ |
| 14298 |
c_parser_consume_token (parser); |
| 14299 |
objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); |
| 14300 |
continue; |
| 14301 |
} |
| 14302 |
else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED)) |
| 14303 |
{ |
| 14304 |
c_parser_consume_token (parser); |
| 14305 |
objc_set_visibility (OBJC_IVAR_VIS_PROTECTED); |
| 14306 |
continue; |
| 14307 |
} |
| 14308 |
else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC)) |
| 14309 |
{ |
| 14310 |
c_parser_consume_token (parser); |
| 14311 |
objc_set_visibility (OBJC_IVAR_VIS_PUBLIC); |
| 14312 |
continue; |
| 14313 |
} |
| 14314 |
else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE)) |
| 14315 |
{ |
| 14316 |
c_parser_consume_token (parser); |
| 14317 |
objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); |
| 14318 |
continue; |
| 14319 |
} |
| 14320 |
else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 14321 |
{ |
| 14322 |
c_parser_pragma (parser, pragma_external, NULL, NULL_TREE); |
| 14323 |
continue; |
| 14324 |
} |
| 14325 |
|
| 14326 |
/* Parse some comma-separated declarations. */ |
| 14327 |
decls = c_parser_struct_declaration (parser, NULL); |
| 14328 |
if (decls == NULL) |
| 14329 |
{ |
| 14330 |
/* There is a syntax error. We want to skip the offending |
| 14331 |
tokens up to the next ';' (included) or '}' |
| 14332 |
(excluded). */ |
| 14333 |
|
| 14334 |
/* First, skip manually a ')' or ']'. This is because they |
| 14335 |
reduce the nesting level, so c_parser_skip_until_found() |
| 14336 |
wouldn't be able to skip past them. */ |
| 14337 |
c_token *token = c_parser_peek_token (parser); |
| 14338 |
if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) |
| 14339 |
c_parser_consume_token (parser); |
| 14340 |
|
| 14341 |
/* Then, do the standard skipping. */ |
| 14342 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 14343 |
|
| 14344 |
/* We hopefully recovered. Start normal parsing again. */ |
| 14345 |
parser->error = false; |
| 14346 |
continue; |
| 14347 |
} |
| 14348 |
else |
| 14349 |
{ |
| 14350 |
/* Comma-separated instance variables are chained together |
| 14351 |
in reverse order; add them one by one. */ |
| 14352 |
tree ivar = nreverse (decls); |
| 14353 |
for (; ivar; ivar = DECL_CHAIN (ivar)) |
| 14354 |
objc_add_instance_variable (copy_node (ivar)); |
| 14355 |
} |
| 14356 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 14357 |
} |
| 14358 |
} |
| 14359 |
|
| 14360 |
/* Parse an objc-class-declaration. |
| 14361 |
|
| 14362 |
objc-class-declaration: |
| 14363 |
@class identifier-list ; |
| 14364 |
*/ |
| 14365 |
|
| 14366 |
static void |
| 14367 |
c_parser_objc_class_declaration (c_parser *parser) |
| 14368 |
{ |
| 14369 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS)); |
| 14370 |
c_parser_consume_token (parser); |
| 14371 |
/* Any identifiers, including those declared as type names, are OK |
| 14372 |
here. */ |
| 14373 |
while (true) |
| 14374 |
{ |
| 14375 |
tree id; |
| 14376 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14377 |
{ |
| 14378 |
c_parser_error (parser, "expected identifier"); |
| 14379 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 14380 |
parser->error = false; |
| 14381 |
return; |
| 14382 |
} |
| 14383 |
id = c_parser_peek_token (parser)->value; |
| 14384 |
objc_declare_class (id); |
| 14385 |
c_parser_consume_token (parser); |
| 14386 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 14387 |
c_parser_consume_token (parser); |
| 14388 |
else |
| 14389 |
break; |
| 14390 |
} |
| 14391 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 14392 |
} |
| 14393 |
|
| 14394 |
/* Parse an objc-alias-declaration. |
| 14395 |
|
| 14396 |
objc-alias-declaration: |
| 14397 |
@compatibility_alias identifier identifier ; |
| 14398 |
*/ |
| 14399 |
|
| 14400 |
static void |
| 14401 |
c_parser_objc_alias_declaration (c_parser *parser) |
| 14402 |
{ |
| 14403 |
tree id1, id2; |
| 14404 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS)); |
| 14405 |
c_parser_consume_token (parser); |
| 14406 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14407 |
{ |
| 14408 |
c_parser_error (parser, "expected identifier"); |
| 14409 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 14410 |
return; |
| 14411 |
} |
| 14412 |
id1 = c_parser_peek_token (parser)->value; |
| 14413 |
c_parser_consume_token (parser); |
| 14414 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14415 |
{ |
| 14416 |
c_parser_error (parser, "expected identifier"); |
| 14417 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 14418 |
return; |
| 14419 |
} |
| 14420 |
id2 = c_parser_peek_token (parser)->value; |
| 14421 |
c_parser_consume_token (parser); |
| 14422 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 14423 |
objc_declare_alias (id1, id2); |
| 14424 |
} |
| 14425 |
|
| 14426 |
/* Parse an objc-protocol-definition. |
| 14427 |
|
| 14428 |
objc-protocol-definition: |
| 14429 |
@protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end |
| 14430 |
@protocol identifier-list ; |
| 14431 |
|
| 14432 |
"@protocol identifier ;" should be resolved as "@protocol |
| 14433 |
identifier-list ;": objc-methodprotolist may not start with a |
| 14434 |
semicolon in the first alternative if objc-protocol-refs are |
| 14435 |
omitted. */ |
| 14436 |
|
| 14437 |
static void |
| 14438 |
c_parser_objc_protocol_definition (c_parser *parser, tree attributes) |
| 14439 |
{ |
| 14440 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); |
| 14441 |
|
| 14442 |
c_parser_consume_token (parser); |
| 14443 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14444 |
{ |
| 14445 |
c_parser_error (parser, "expected identifier"); |
| 14446 |
return; |
| 14447 |
} |
| 14448 |
if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 14449 |
|| c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) |
| 14450 |
{ |
| 14451 |
/* Any identifiers, including those declared as type names, are |
| 14452 |
OK here. */ |
| 14453 |
while (true) |
| 14454 |
{ |
| 14455 |
tree id; |
| 14456 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14457 |
{ |
| 14458 |
c_parser_error (parser, "expected identifier"); |
| 14459 |
break; |
| 14460 |
} |
| 14461 |
id = c_parser_peek_token (parser)->value; |
| 14462 |
objc_declare_protocol (id, attributes); |
| 14463 |
c_parser_consume_token (parser); |
| 14464 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 14465 |
c_parser_consume_token (parser); |
| 14466 |
else |
| 14467 |
break; |
| 14468 |
} |
| 14469 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 14470 |
} |
| 14471 |
else |
| 14472 |
{ |
| 14473 |
tree id = c_parser_peek_token (parser)->value; |
| 14474 |
tree proto = NULL_TREE; |
| 14475 |
c_parser_consume_token (parser); |
| 14476 |
if (c_parser_next_token_is (parser, CPP_LESS)) |
| 14477 |
proto = c_parser_objc_protocol_refs (parser); |
| 14478 |
parser->objc_pq_context = true; |
| 14479 |
objc_start_protocol (id, proto, attributes); |
| 14480 |
c_parser_objc_methodprotolist (parser); |
| 14481 |
c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); |
| 14482 |
parser->objc_pq_context = false; |
| 14483 |
objc_finish_interface (); |
| 14484 |
} |
| 14485 |
} |
| 14486 |
|
| 14487 |
/* Parse an objc-method-type. |
| 14488 |
|
| 14489 |
objc-method-type: |
| 14490 |
+ |
| 14491 |
- |
| 14492 |
|
| 14493 |
Return true if it is a class method (+) and false if it is |
| 14494 |
an instance method (-). |
| 14495 |
*/ |
| 14496 |
static inline bool |
| 14497 |
c_parser_objc_method_type (c_parser *parser) |
| 14498 |
{ |
| 14499 |
switch (c_parser_peek_token (parser)->type) |
| 14500 |
{ |
| 14501 |
case CPP_PLUS: |
| 14502 |
c_parser_consume_token (parser); |
| 14503 |
return true; |
| 14504 |
case CPP_MINUS: |
| 14505 |
c_parser_consume_token (parser); |
| 14506 |
return false; |
| 14507 |
default: |
| 14508 |
gcc_unreachable (); |
| 14509 |
} |
| 14510 |
} |
| 14511 |
|
| 14512 |
/* Parse an objc-method-definition. |
| 14513 |
|
| 14514 |
objc-method-definition: |
| 14515 |
objc-method-type objc-method-decl ;[opt] compound-statement |
| 14516 |
*/ |
| 14517 |
|
| 14518 |
static void |
| 14519 |
c_parser_objc_method_definition (c_parser *parser) |
| 14520 |
{ |
| 14521 |
bool is_class_method = c_parser_objc_method_type (parser); |
| 14522 |
tree decl, attributes = NULL_TREE, expr = NULL_TREE; |
| 14523 |
parser->objc_pq_context = true; |
| 14524 |
decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
| 14525 |
&expr); |
| 14526 |
if (decl == error_mark_node) |
| 14527 |
return; /* Bail here. */ |
| 14528 |
|
| 14529 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 14530 |
{ |
| 14531 |
c_parser_consume_token (parser); |
| 14532 |
pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 14533 |
"extra semicolon in method definition specified"); |
| 14534 |
} |
| 14535 |
|
| 14536 |
if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 14537 |
{ |
| 14538 |
c_parser_error (parser, "expected %<{%>"); |
| 14539 |
return; |
| 14540 |
} |
| 14541 |
|
| 14542 |
parser->objc_pq_context = false; |
| 14543 |
if (objc_start_method_definition (is_class_method, decl, attributes, expr)) |
| 14544 |
{ |
| 14545 |
add_stmt (c_parser_compound_statement (parser)); |
| 14546 |
objc_finish_method_definition (current_function_decl); |
| 14547 |
} |
| 14548 |
else |
| 14549 |
{ |
| 14550 |
/* This code is executed when we find a method definition |
| 14551 |
outside of an @implementation context (or invalid for other |
| 14552 |
reasons). Parse the method (to keep going) but do not emit |
| 14553 |
any code. |
| 14554 |
*/ |
| 14555 |
c_parser_compound_statement (parser); |
| 14556 |
} |
| 14557 |
} |
| 14558 |
|
| 14559 |
/* Parse an objc-methodprotolist. |
| 14560 |
|
| 14561 |
objc-methodprotolist: |
| 14562 |
empty |
| 14563 |
objc-methodprotolist objc-methodproto |
| 14564 |
objc-methodprotolist declaration |
| 14565 |
objc-methodprotolist ; |
| 14566 |
@optional |
| 14567 |
@required |
| 14568 |
|
| 14569 |
The declaration is a data definition, which may be missing |
| 14570 |
declaration specifiers under the same rules and diagnostics as |
| 14571 |
other data definitions outside functions, and the stray semicolon |
| 14572 |
is diagnosed the same way as a stray semicolon outside a |
| 14573 |
function. */ |
| 14574 |
|
| 14575 |
static void |
| 14576 |
c_parser_objc_methodprotolist (c_parser *parser) |
| 14577 |
{ |
| 14578 |
while (true) |
| 14579 |
{ |
| 14580 |
/* The list is terminated by @end. */ |
| 14581 |
switch (c_parser_peek_token (parser)->type) |
| 14582 |
{ |
| 14583 |
case CPP_SEMICOLON: |
| 14584 |
pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 14585 |
"ISO C does not allow extra %<;%> outside of a function"); |
| 14586 |
c_parser_consume_token (parser); |
| 14587 |
break; |
| 14588 |
case CPP_PLUS: |
| 14589 |
case CPP_MINUS: |
| 14590 |
c_parser_objc_methodproto (parser); |
| 14591 |
break; |
| 14592 |
case CPP_PRAGMA: |
| 14593 |
c_parser_pragma (parser, pragma_external, NULL, NULL_TREE); |
| 14594 |
break; |
| 14595 |
case CPP_EOF: |
| 14596 |
return; |
| 14597 |
default: |
| 14598 |
if (c_parser_next_token_is_keyword (parser, RID_AT_END)) |
| 14599 |
return; |
| 14600 |
else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)) |
| 14601 |
c_parser_objc_at_property_declaration (parser); |
| 14602 |
else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL)) |
| 14603 |
{ |
| 14604 |
objc_set_method_opt (true); |
| 14605 |
c_parser_consume_token (parser); |
| 14606 |
} |
| 14607 |
else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED)) |
| 14608 |
{ |
| 14609 |
objc_set_method_opt (false); |
| 14610 |
c_parser_consume_token (parser); |
| 14611 |
} |
| 14612 |
else |
| 14613 |
c_parser_declaration_or_fndef (parser, false, false, true, |
| 14614 |
false, true, false); |
| 14615 |
break; |
| 14616 |
} |
| 14617 |
} |
| 14618 |
} |
| 14619 |
|
| 14620 |
/* Parse an objc-methodproto. |
| 14621 |
|
| 14622 |
objc-methodproto: |
| 14623 |
objc-method-type objc-method-decl ; |
| 14624 |
*/ |
| 14625 |
|
| 14626 |
static void |
| 14627 |
c_parser_objc_methodproto (c_parser *parser) |
| 14628 |
{ |
| 14629 |
bool is_class_method = c_parser_objc_method_type (parser); |
| 14630 |
tree decl, attributes = NULL_TREE; |
| 14631 |
|
| 14632 |
/* Remember protocol qualifiers in prototypes. */ |
| 14633 |
parser->objc_pq_context = true; |
| 14634 |
decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
| 14635 |
NULL); |
| 14636 |
/* Forget protocol qualifiers now. */ |
| 14637 |
parser->objc_pq_context = false; |
| 14638 |
|
| 14639 |
/* Do not allow the presence of attributes to hide an erroneous |
| 14640 |
method implementation in the interface section. */ |
| 14641 |
if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 14642 |
{ |
| 14643 |
c_parser_error (parser, "expected %<;%>"); |
| 14644 |
return; |
| 14645 |
} |
| 14646 |
|
| 14647 |
if (decl != error_mark_node) |
| 14648 |
objc_add_method_declaration (is_class_method, decl, attributes); |
| 14649 |
|
| 14650 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 14651 |
} |
| 14652 |
|
| 14653 |
/* If we are at a position that method attributes may be present, check that |
| 14654 |
there are not any parsed already (a syntax error) and then collect any |
| 14655 |
specified at the current location. Finally, if new attributes were present, |
| 14656 |
check that the next token is legal ( ';' for decls and '{' for defs). */ |
| 14657 |
|
| 14658 |
static bool |
| 14659 |
c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes) |
| 14660 |
{ |
| 14661 |
bool bad = false; |
| 14662 |
if (*attributes) |
| 14663 |
{ |
| 14664 |
c_parser_error (parser, |
| 14665 |
"method attributes must be specified at the end only"); |
| 14666 |
*attributes = NULL_TREE; |
| 14667 |
bad = true; |
| 14668 |
} |
| 14669 |
|
| 14670 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 14671 |
*attributes = c_parser_gnu_attributes (parser); |
| 14672 |
|
| 14673 |
/* If there were no attributes here, just report any earlier error. */ |
| 14674 |
if (*attributes == NULL_TREE || bad) |
| 14675 |
return bad; |
| 14676 |
|
| 14677 |
/* If the attributes are followed by a ; or {, then just report any earlier |
| 14678 |
error. */ |
| 14679 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 14680 |
|| c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 14681 |
return bad; |
| 14682 |
|
| 14683 |
/* We've got attributes, but not at the end. */ |
| 14684 |
c_parser_error (parser, |
| 14685 |
"expected %<;%> or %<{%> after method attribute definition"); |
| 14686 |
return true; |
| 14687 |
} |
| 14688 |
|
| 14689 |
/* Parse an objc-method-decl. |
| 14690 |
|
| 14691 |
objc-method-decl: |
| 14692 |
( objc-type-name ) objc-selector |
| 14693 |
objc-selector |
| 14694 |
( objc-type-name ) objc-keyword-selector objc-optparmlist |
| 14695 |
objc-keyword-selector objc-optparmlist |
| 14696 |
gnu-attributes |
| 14697 |
|
| 14698 |
objc-keyword-selector: |
| 14699 |
objc-keyword-decl |
| 14700 |
objc-keyword-selector objc-keyword-decl |
| 14701 |
|
| 14702 |
objc-keyword-decl: |
| 14703 |
objc-selector : ( objc-type-name ) identifier |
| 14704 |
objc-selector : identifier |
| 14705 |
: ( objc-type-name ) identifier |
| 14706 |
: identifier |
| 14707 |
|
| 14708 |
objc-optparmlist: |
| 14709 |
objc-optparms objc-optellipsis |
| 14710 |
|
| 14711 |
objc-optparms: |
| 14712 |
empty |
| 14713 |
objc-opt-parms , parameter-declaration |
| 14714 |
|
| 14715 |
objc-optellipsis: |
| 14716 |
empty |
| 14717 |
, ... |
| 14718 |
*/ |
| 14719 |
|
| 14720 |
static tree |
| 14721 |
c_parser_objc_method_decl (c_parser *parser, bool is_class_method, |
| 14722 |
tree *attributes, tree *expr) |
| 14723 |
{ |
| 14724 |
tree type = NULL_TREE; |
| 14725 |
tree sel; |
| 14726 |
tree parms = NULL_TREE; |
| 14727 |
bool ellipsis = false; |
| 14728 |
bool attr_err = false; |
| 14729 |
|
| 14730 |
*attributes = NULL_TREE; |
| 14731 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 14732 |
{ |
| 14733 |
matching_parens parens; |
| 14734 |
parens.consume_open (parser); |
| 14735 |
type = c_parser_objc_type_name (parser); |
| 14736 |
parens.skip_until_found_close (parser); |
| 14737 |
} |
| 14738 |
sel = c_parser_objc_selector (parser); |
| 14739 |
/* If there is no selector, or a colon follows, we have an |
| 14740 |
objc-keyword-selector. If there is a selector, and a colon does |
| 14741 |
not follow, that selector ends the objc-method-decl. */ |
| 14742 |
if (!sel || c_parser_next_token_is (parser, CPP_COLON)) |
| 14743 |
{ |
| 14744 |
tree tsel = sel; |
| 14745 |
tree list = NULL_TREE; |
| 14746 |
while (true) |
| 14747 |
{ |
| 14748 |
tree atype = NULL_TREE, id, keyworddecl; |
| 14749 |
tree param_attr = NULL_TREE; |
| 14750 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 14751 |
break; |
| 14752 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 14753 |
{ |
| 14754 |
c_parser_consume_token (parser); |
| 14755 |
atype = c_parser_objc_type_name (parser); |
| 14756 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 14757 |
"expected %<)%>"); |
| 14758 |
} |
| 14759 |
/* New ObjC allows attributes on method parameters. */ |
| 14760 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 14761 |
param_attr = c_parser_gnu_attributes (parser); |
| 14762 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14763 |
{ |
| 14764 |
c_parser_error (parser, "expected identifier"); |
| 14765 |
return error_mark_node; |
| 14766 |
} |
| 14767 |
id = c_parser_peek_token (parser)->value; |
| 14768 |
c_parser_consume_token (parser); |
| 14769 |
keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr); |
| 14770 |
list = chainon (list, keyworddecl); |
| 14771 |
tsel = c_parser_objc_selector (parser); |
| 14772 |
if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 14773 |
break; |
| 14774 |
} |
| 14775 |
|
| 14776 |
attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; |
| 14777 |
|
| 14778 |
/* Parse the optional parameter list. Optional Objective-C |
| 14779 |
method parameters follow the C syntax, and may include '...' |
| 14780 |
to denote a variable number of arguments. */ |
| 14781 |
parms = make_node (TREE_LIST); |
| 14782 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 14783 |
{ |
| 14784 |
struct c_parm *parm; |
| 14785 |
c_parser_consume_token (parser); |
| 14786 |
if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 14787 |
{ |
| 14788 |
ellipsis = true; |
| 14789 |
c_parser_consume_token (parser); |
| 14790 |
attr_err |= c_parser_objc_maybe_method_attributes |
| 14791 |
(parser, attributes) ; |
| 14792 |
break; |
| 14793 |
} |
| 14794 |
parm = c_parser_parameter_declaration (parser, NULL_TREE, false); |
| 14795 |
if (parm == NULL) |
| 14796 |
break; |
| 14797 |
parms = chainon (parms, |
| 14798 |
build_tree_list (NULL_TREE, grokparm (parm, expr))); |
| 14799 |
} |
| 14800 |
sel = list; |
| 14801 |
} |
| 14802 |
else |
| 14803 |
attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; |
| 14804 |
|
| 14805 |
if (sel == NULL) |
| 14806 |
{ |
| 14807 |
c_parser_error (parser, "objective-c method declaration is expected"); |
| 14808 |
return error_mark_node; |
| 14809 |
} |
| 14810 |
|
| 14811 |
if (attr_err) |
| 14812 |
return error_mark_node; |
| 14813 |
|
| 14814 |
return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis); |
| 14815 |
} |
| 14816 |
|
| 14817 |
/* Parse an objc-type-name. |
| 14818 |
|
| 14819 |
objc-type-name: |
| 14820 |
objc-type-qualifiers[opt] type-name |
| 14821 |
objc-type-qualifiers[opt] |
| 14822 |
|
| 14823 |
objc-type-qualifiers: |
| 14824 |
objc-type-qualifier |
| 14825 |
objc-type-qualifiers objc-type-qualifier |
| 14826 |
|
| 14827 |
objc-type-qualifier: one of |
| 14828 |
in out inout bycopy byref oneway |
| 14829 |
*/ |
| 14830 |
|
| 14831 |
static tree |
| 14832 |
c_parser_objc_type_name (c_parser *parser) |
| 14833 |
{ |
| 14834 |
tree quals = NULL_TREE; |
| 14835 |
struct c_type_name *type_name = NULL; |
| 14836 |
tree type = NULL_TREE; |
| 14837 |
while (true) |
| 14838 |
{ |
| 14839 |
c_token *token = c_parser_peek_token (parser); |
| 14840 |
if (token->type == CPP_KEYWORD |
| 14841 |
&& (token->keyword == RID_IN |
| 14842 |
|| token->keyword == RID_OUT |
| 14843 |
|| token->keyword == RID_INOUT |
| 14844 |
|| token->keyword == RID_BYCOPY |
| 14845 |
|| token->keyword == RID_BYREF |
| 14846 |
|| token->keyword == RID_ONEWAY)) |
| 14847 |
{ |
| 14848 |
quals = chainon (build_tree_list (NULL_TREE, token->value), quals); |
| 14849 |
c_parser_consume_token (parser); |
| 14850 |
} |
| 14851 |
else |
| 14852 |
break; |
| 14853 |
} |
| 14854 |
if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
| 14855 |
type_name = c_parser_type_name (parser); |
| 14856 |
if (type_name) |
| 14857 |
type = groktypename (type_name, NULL, NULL); |
| 14858 |
|
| 14859 |
/* If the type is unknown, and error has already been produced and |
| 14860 |
we need to recover from the error. In that case, use NULL_TREE |
| 14861 |
for the type, as if no type had been specified; this will use the |
| 14862 |
default type ('id') which is good for error recovery. */ |
| 14863 |
if (type == error_mark_node) |
| 14864 |
type = NULL_TREE; |
| 14865 |
|
| 14866 |
return build_tree_list (quals, type); |
| 14867 |
} |
| 14868 |
|
| 14869 |
/* Parse objc-protocol-refs. |
| 14870 |
|
| 14871 |
objc-protocol-refs: |
| 14872 |
< identifier-list > |
| 14873 |
*/ |
| 14874 |
|
| 14875 |
static tree |
| 14876 |
c_parser_objc_protocol_refs (c_parser *parser) |
| 14877 |
{ |
| 14878 |
tree list = NULL_TREE; |
| 14879 |
gcc_assert (c_parser_next_token_is (parser, CPP_LESS)); |
| 14880 |
c_parser_consume_token (parser); |
| 14881 |
/* Any identifiers, including those declared as type names, are OK |
| 14882 |
here. */ |
| 14883 |
while (true) |
| 14884 |
{ |
| 14885 |
tree id; |
| 14886 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 14887 |
{ |
| 14888 |
c_parser_error (parser, "expected identifier"); |
| 14889 |
break; |
| 14890 |
} |
| 14891 |
id = c_parser_peek_token (parser)->value; |
| 14892 |
list = chainon (list, build_tree_list (NULL_TREE, id)); |
| 14893 |
c_parser_consume_token (parser); |
| 14894 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 14895 |
c_parser_consume_token (parser); |
| 14896 |
else |
| 14897 |
break; |
| 14898 |
} |
| 14899 |
c_parser_require (parser, CPP_GREATER, "expected %<>%>"); |
| 14900 |
return list; |
| 14901 |
} |
| 14902 |
|
| 14903 |
/* Parse an objc-try-catch-finally-statement. |
| 14904 |
|
| 14905 |
objc-try-catch-finally-statement: |
| 14906 |
@try compound-statement objc-catch-list[opt] |
| 14907 |
@try compound-statement objc-catch-list[opt] @finally compound-statement |
| 14908 |
|
| 14909 |
objc-catch-list: |
| 14910 |
@catch ( objc-catch-parameter-declaration ) compound-statement |
| 14911 |
objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement |
| 14912 |
|
| 14913 |
objc-catch-parameter-declaration: |
| 14914 |
parameter-declaration |
| 14915 |
'...' |
| 14916 |
|
| 14917 |
where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS. |
| 14918 |
|
| 14919 |
PS: This function is identical to cp_parser_objc_try_catch_finally_statement |
| 14920 |
for C++. Keep them in sync. */ |
| 14921 |
|
| 14922 |
static void |
| 14923 |
c_parser_objc_try_catch_finally_statement (c_parser *parser) |
| 14924 |
{ |
| 14925 |
location_t location; |
| 14926 |
tree stmt; |
| 14927 |
|
| 14928 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY)); |
| 14929 |
c_parser_consume_token (parser); |
| 14930 |
location = c_parser_peek_token (parser)->location; |
| 14931 |
objc_maybe_warn_exceptions (location); |
| 14932 |
stmt = c_parser_compound_statement (parser); |
| 14933 |
objc_begin_try_stmt (location, stmt); |
| 14934 |
|
| 14935 |
while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH)) |
| 14936 |
{ |
| 14937 |
struct c_parm *parm; |
| 14938 |
tree parameter_declaration = error_mark_node; |
| 14939 |
bool seen_open_paren = false; |
| 14940 |
|
| 14941 |
c_parser_consume_token (parser); |
| 14942 |
matching_parens parens; |
| 14943 |
if (!parens.require_open (parser)) |
| 14944 |
seen_open_paren = true; |
| 14945 |
if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 14946 |
{ |
| 14947 |
/* We have "@catch (...)" (where the '...' are literally |
| 14948 |
what is in the code). Skip the '...'. |
| 14949 |
parameter_declaration is set to NULL_TREE, and |
| 14950 |
objc_being_catch_clauses() knows that that means |
| 14951 |
'...'. */ |
| 14952 |
c_parser_consume_token (parser); |
| 14953 |
parameter_declaration = NULL_TREE; |
| 14954 |
} |
| 14955 |
else |
| 14956 |
{ |
| 14957 |
/* We have "@catch (NSException *exception)" or something |
| 14958 |
like that. Parse the parameter declaration. */ |
| 14959 |
parm = c_parser_parameter_declaration (parser, NULL_TREE, false); |
| 14960 |
if (parm == NULL) |
| 14961 |
parameter_declaration = error_mark_node; |
| 14962 |
else |
| 14963 |
parameter_declaration = grokparm (parm, NULL); |
| 14964 |
} |
| 14965 |
if (seen_open_paren) |
| 14966 |
parens.require_close (parser); |
| 14967 |
else |
| 14968 |
{ |
| 14969 |
/* If there was no open parenthesis, we are recovering from |
| 14970 |
an error, and we are trying to figure out what mistake |
| 14971 |
the user has made. */ |
| 14972 |
|
| 14973 |
/* If there is an immediate closing parenthesis, the user |
| 14974 |
probably forgot the opening one (ie, they typed "@catch |
| 14975 |
NSException *e)". Parse the closing parenthesis and keep |
| 14976 |
going. */ |
| 14977 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 14978 |
c_parser_consume_token (parser); |
| 14979 |
|
| 14980 |
/* If these is no immediate closing parenthesis, the user |
| 14981 |
probably doesn't know that parenthesis are required at |
| 14982 |
all (ie, they typed "@catch NSException *e"). So, just |
| 14983 |
forget about the closing parenthesis and keep going. */ |
| 14984 |
} |
| 14985 |
objc_begin_catch_clause (parameter_declaration); |
| 14986 |
if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 14987 |
c_parser_compound_statement_nostart (parser); |
| 14988 |
objc_finish_catch_clause (); |
| 14989 |
} |
| 14990 |
if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) |
| 14991 |
{ |
| 14992 |
c_parser_consume_token (parser); |
| 14993 |
location = c_parser_peek_token (parser)->location; |
| 14994 |
stmt = c_parser_compound_statement (parser); |
| 14995 |
objc_build_finally_clause (location, stmt); |
| 14996 |
} |
| 14997 |
objc_finish_try_stmt (); |
| 14998 |
} |
| 14999 |
|
| 15000 |
/* Parse an objc-synchronized-statement. |
| 15001 |
|
| 15002 |
objc-synchronized-statement: |
| 15003 |
@synchronized ( expression ) compound-statement |
| 15004 |
*/ |
| 15005 |
|
| 15006 |
static void |
| 15007 |
c_parser_objc_synchronized_statement (c_parser *parser) |
| 15008 |
{ |
| 15009 |
location_t loc; |
| 15010 |
tree expr, stmt; |
| 15011 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); |
| 15012 |
c_parser_consume_token (parser); |
| 15013 |
loc = c_parser_peek_token (parser)->location; |
| 15014 |
objc_maybe_warn_exceptions (loc); |
| 15015 |
matching_parens parens; |
| 15016 |
if (parens.require_open (parser)) |
| 15017 |
{ |
| 15018 |
struct c_expr ce = c_parser_expression (parser); |
| 15019 |
ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 15020 |
expr = ce.value; |
| 15021 |
expr = c_fully_fold (expr, false, NULL); |
| 15022 |
parens.skip_until_found_close (parser); |
| 15023 |
} |
| 15024 |
else |
| 15025 |
expr = error_mark_node; |
| 15026 |
stmt = c_parser_compound_statement (parser); |
| 15027 |
objc_build_synchronized (loc, expr, stmt); |
| 15028 |
} |
| 15029 |
|
| 15030 |
/* Parse an objc-selector; return NULL_TREE without an error if the |
| 15031 |
next token is not an objc-selector. |
| 15032 |
|
| 15033 |
objc-selector: |
| 15034 |
identifier |
| 15035 |
one of |
| 15036 |
enum struct union if else while do for switch case default |
| 15037 |
break continue return goto asm sizeof typeof typeof_unqual __alignof |
| 15038 |
unsigned long const short volatile signed restrict _Complex |
| 15039 |
in out inout bycopy byref oneway int char float double void _Bool |
| 15040 |
_Atomic |
| 15041 |
|
| 15042 |
??? Why this selection of keywords but not, for example, storage |
| 15043 |
class specifiers? */ |
| 15044 |
|
| 15045 |
static tree |
| 15046 |
c_parser_objc_selector (c_parser *parser) |
| 15047 |
{ |
| 15048 |
c_token *token = c_parser_peek_token (parser); |
| 15049 |
tree value = token->value; |
| 15050 |
if (token->type == CPP_NAME) |
| 15051 |
{ |
| 15052 |
c_parser_consume_token (parser); |
| 15053 |
return value; |
| 15054 |
} |
| 15055 |
if (token->type != CPP_KEYWORD) |
| 15056 |
return NULL_TREE; |
| 15057 |
switch (token->keyword) |
| 15058 |
{ |
| 15059 |
case RID_ENUM: |
| 15060 |
case RID_STRUCT: |
| 15061 |
case RID_UNION: |
| 15062 |
case RID_IF: |
| 15063 |
case RID_ELSE: |
| 15064 |
case RID_WHILE: |
| 15065 |
case RID_DO: |
| 15066 |
case RID_FOR: |
| 15067 |
case RID_SWITCH: |
| 15068 |
case RID_CASE: |
| 15069 |
case RID_DEFAULT: |
| 15070 |
case RID_BREAK: |
| 15071 |
case RID_CONTINUE: |
| 15072 |
case RID_RETURN: |
| 15073 |
case RID_GOTO: |
| 15074 |
case RID_ASM: |
| 15075 |
case RID_SIZEOF: |
| 15076 |
case RID_TYPEOF: |
| 15077 |
case RID_TYPEOF_UNQUAL: |
| 15078 |
case RID_ALIGNOF: |
| 15079 |
case RID_UNSIGNED: |
| 15080 |
case RID_LONG: |
| 15081 |
case RID_CONST: |
| 15082 |
case RID_SHORT: |
| 15083 |
case RID_VOLATILE: |
| 15084 |
case RID_SIGNED: |
| 15085 |
case RID_RESTRICT: |
| 15086 |
case RID_COMPLEX: |
| 15087 |
case RID_IN: |
| 15088 |
case RID_OUT: |
| 15089 |
case RID_INOUT: |
| 15090 |
case RID_BYCOPY: |
| 15091 |
case RID_BYREF: |
| 15092 |
case RID_ONEWAY: |
| 15093 |
case RID_INT: |
| 15094 |
case RID_CHAR: |
| 15095 |
case RID_FLOAT: |
| 15096 |
case RID_DOUBLE: |
| 15097 |
CASE_RID_FLOATN_NX: |
| 15098 |
case RID_VOID: |
| 15099 |
case RID_BOOL: |
| 15100 |
case RID_ATOMIC: |
| 15101 |
case RID_AUTO_TYPE: |
| 15102 |
case RID_INT_N_0: |
| 15103 |
case RID_INT_N_1: |
| 15104 |
case RID_INT_N_2: |
| 15105 |
case RID_INT_N_3: |
| 15106 |
c_parser_consume_token (parser); |
| 15107 |
return value; |
| 15108 |
default: |
| 15109 |
return NULL_TREE; |
| 15110 |
} |
| 15111 |
} |
| 15112 |
|
| 15113 |
/* Parse an objc-selector-arg. |
| 15114 |
|
| 15115 |
objc-selector-arg: |
| 15116 |
objc-selector |
| 15117 |
objc-keywordname-list |
| 15118 |
|
| 15119 |
objc-keywordname-list: |
| 15120 |
objc-keywordname |
| 15121 |
objc-keywordname-list objc-keywordname |
| 15122 |
|
| 15123 |
objc-keywordname: |
| 15124 |
objc-selector : |
| 15125 |
: |
| 15126 |
*/ |
| 15127 |
|
| 15128 |
static tree |
| 15129 |
c_parser_objc_selector_arg (c_parser *parser) |
| 15130 |
{ |
| 15131 |
tree sel = c_parser_objc_selector (parser); |
| 15132 |
tree list = NULL_TREE; |
| 15133 |
if (sel |
| 15134 |
&& c_parser_next_token_is_not (parser, CPP_COLON) |
| 15135 |
&& c_parser_next_token_is_not (parser, CPP_SCOPE)) |
| 15136 |
return sel; |
| 15137 |
while (true) |
| 15138 |
{ |
| 15139 |
if (c_parser_next_token_is (parser, CPP_SCOPE)) |
| 15140 |
{ |
| 15141 |
c_parser_consume_token (parser); |
| 15142 |
list = chainon (list, build_tree_list (sel, NULL_TREE)); |
| 15143 |
list = chainon (list, build_tree_list (NULL_TREE, NULL_TREE)); |
| 15144 |
} |
| 15145 |
else |
| 15146 |
{ |
| 15147 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 15148 |
return list; |
| 15149 |
list = chainon (list, build_tree_list (sel, NULL_TREE)); |
| 15150 |
} |
| 15151 |
sel = c_parser_objc_selector (parser); |
| 15152 |
if (!sel |
| 15153 |
&& c_parser_next_token_is_not (parser, CPP_COLON) |
| 15154 |
&& c_parser_next_token_is_not (parser, CPP_SCOPE)) |
| 15155 |
break; |
| 15156 |
} |
| 15157 |
return list; |
| 15158 |
} |
| 15159 |
|
| 15160 |
/* Parse an objc-receiver. |
| 15161 |
|
| 15162 |
objc-receiver: |
| 15163 |
expression |
| 15164 |
class-name |
| 15165 |
type-name |
| 15166 |
*/ |
| 15167 |
|
| 15168 |
static tree |
| 15169 |
c_parser_objc_receiver (c_parser *parser) |
| 15170 |
{ |
| 15171 |
location_t loc = c_parser_peek_token (parser)->location; |
| 15172 |
|
| 15173 |
if (c_parser_peek_token (parser)->type == CPP_NAME |
| 15174 |
&& (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
| 15175 |
|| c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) |
| 15176 |
{ |
| 15177 |
tree id = c_parser_peek_token (parser)->value; |
| 15178 |
c_parser_consume_token (parser); |
| 15179 |
return objc_get_class_reference (id); |
| 15180 |
} |
| 15181 |
struct c_expr ce = c_parser_expression (parser); |
| 15182 |
ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 15183 |
return c_fully_fold (ce.value, false, NULL); |
| 15184 |
} |
| 15185 |
|
| 15186 |
/* Parse objc-message-args. |
| 15187 |
|
| 15188 |
objc-message-args: |
| 15189 |
objc-selector |
| 15190 |
objc-keywordarg-list |
| 15191 |
|
| 15192 |
objc-keywordarg-list: |
| 15193 |
objc-keywordarg |
| 15194 |
objc-keywordarg-list objc-keywordarg |
| 15195 |
|
| 15196 |
objc-keywordarg: |
| 15197 |
objc-selector : objc-keywordexpr |
| 15198 |
: objc-keywordexpr |
| 15199 |
*/ |
| 15200 |
|
| 15201 |
static tree |
| 15202 |
c_parser_objc_message_args (c_parser *parser) |
| 15203 |
{ |
| 15204 |
tree sel = c_parser_objc_selector (parser); |
| 15205 |
tree list = NULL_TREE; |
| 15206 |
if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 15207 |
return sel; |
| 15208 |
while (true) |
| 15209 |
{ |
| 15210 |
tree keywordexpr; |
| 15211 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 15212 |
return error_mark_node; |
| 15213 |
keywordexpr = c_parser_objc_keywordexpr (parser); |
| 15214 |
list = chainon (list, build_tree_list (sel, keywordexpr)); |
| 15215 |
sel = c_parser_objc_selector (parser); |
| 15216 |
if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 15217 |
break; |
| 15218 |
} |
| 15219 |
return list; |
| 15220 |
} |
| 15221 |
|
| 15222 |
/* Parse an objc-keywordexpr. |
| 15223 |
|
| 15224 |
objc-keywordexpr: |
| 15225 |
nonempty-expr-list |
| 15226 |
*/ |
| 15227 |
|
| 15228 |
static tree |
| 15229 |
c_parser_objc_keywordexpr (c_parser *parser) |
| 15230 |
{ |
| 15231 |
tree ret; |
| 15232 |
vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true, |
| 15233 |
NULL, NULL, NULL, NULL); |
| 15234 |
if (vec_safe_length (expr_list) == 1) |
| 15235 |
{ |
| 15236 |
/* Just return the expression, remove a level of |
| 15237 |
indirection. */ |
| 15238 |
ret = (*expr_list)[0]; |
| 15239 |
} |
| 15240 |
else |
| 15241 |
{ |
| 15242 |
/* We have a comma expression, we will collapse later. */ |
| 15243 |
ret = build_tree_list_vec (expr_list); |
| 15244 |
} |
| 15245 |
release_tree_vector (expr_list); |
| 15246 |
return ret; |
| 15247 |
} |
| 15248 |
|
| 15249 |
/* A check, needed in several places, that ObjC interface, implementation or |
| 15250 |
method definitions are not prefixed by incorrect items. */ |
| 15251 |
static bool |
| 15252 |
c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, |
| 15253 |
struct c_declspecs *specs) |
| 15254 |
{ |
| 15255 |
if (!specs->declspecs_seen_p || specs->non_sc_seen_p |
| 15256 |
|| specs->typespec_kind != ctsk_none) |
| 15257 |
{ |
| 15258 |
c_parser_error (parser, |
| 15259 |
"no type or storage class may be specified here,"); |
| 15260 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 15261 |
return true; |
| 15262 |
} |
| 15263 |
return false; |
| 15264 |
} |
| 15265 |
|
| 15266 |
/* Parse an Objective-C @property declaration. The syntax is: |
| 15267 |
|
| 15268 |
objc-property-declaration: |
| 15269 |
'@property' objc-property-attributes[opt] struct-declaration ; |
| 15270 |
|
| 15271 |
objc-property-attributes: |
| 15272 |
'(' objc-property-attribute-list ')' |
| 15273 |
|
| 15274 |
objc-property-attribute-list: |
| 15275 |
objc-property-attribute |
| 15276 |
objc-property-attribute-list, objc-property-attribute |
| 15277 |
|
| 15278 |
objc-property-attribute |
| 15279 |
'getter' = identifier |
| 15280 |
'setter' = identifier |
| 15281 |
'readonly' |
| 15282 |
'readwrite' |
| 15283 |
'assign' |
| 15284 |
'retain' |
| 15285 |
'copy' |
| 15286 |
'nonatomic' |
| 15287 |
|
| 15288 |
For example: |
| 15289 |
@property NSString *name; |
| 15290 |
@property (readonly) id object; |
| 15291 |
@property (retain, nonatomic, getter=getTheName) id name; |
| 15292 |
@property int a, b, c; |
| 15293 |
|
| 15294 |
PS: This function is identical to cp_parser_objc_at_propery_declaration |
| 15295 |
for C++. Keep them in sync. */ |
| 15296 |
static void |
| 15297 |
c_parser_objc_at_property_declaration (c_parser *parser) |
| 15298 |
{ |
| 15299 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)); |
| 15300 |
location_t loc = c_parser_peek_token (parser)->location; |
| 15301 |
c_parser_consume_token (parser); /* Eat '@property'. */ |
| 15302 |
|
| 15303 |
/* Parse the optional attribute list. |
| 15304 |
|
| 15305 |
A list of parsed, but not verified, attributes. */ |
| 15306 |
vec<property_attribute_info *> prop_attr_list = vNULL; |
| 15307 |
|
| 15308 |
bool syntax_error = false; |
| 15309 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 15310 |
{ |
| 15311 |
matching_parens parens; |
| 15312 |
|
| 15313 |
location_t attr_start = c_parser_peek_token (parser)->location; |
| 15314 |
/* Eat the '(' */ |
| 15315 |
parens.consume_open (parser); |
| 15316 |
|
| 15317 |
/* Property attribute keywords are valid now. */ |
| 15318 |
parser->objc_property_attr_context = true; |
| 15319 |
|
| 15320 |
/* Allow @property (), with a warning. */ |
| 15321 |
location_t attr_end = c_parser_peek_token (parser)->location; |
| 15322 |
|
| 15323 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 15324 |
{ |
| 15325 |
location_t attr_comb = make_location (attr_end, attr_start, attr_end); |
| 15326 |
warning_at (attr_comb, OPT_Wattributes, |
| 15327 |
"empty property attribute list"); |
| 15328 |
} |
| 15329 |
else |
| 15330 |
while (true) |
| 15331 |
{ |
| 15332 |
c_token *token = c_parser_peek_token (parser); |
| 15333 |
attr_start = token->location; |
| 15334 |
attr_end = get_finish (token->location); |
| 15335 |
location_t attr_comb = make_location (attr_start, attr_start, |
| 15336 |
attr_end); |
| 15337 |
|
| 15338 |
if (token->type == CPP_CLOSE_PAREN || token->type == CPP_COMMA) |
| 15339 |
{ |
| 15340 |
warning_at (attr_comb, OPT_Wattributes, |
| 15341 |
"missing property attribute"); |
| 15342 |
if (token->type == CPP_CLOSE_PAREN) |
| 15343 |
break; |
| 15344 |
c_parser_consume_token (parser); |
| 15345 |
continue; |
| 15346 |
} |
| 15347 |
|
| 15348 |
tree attr_name = NULL_TREE; |
| 15349 |
enum rid keyword = RID_MAX; /* Not a valid property attribute. */ |
| 15350 |
bool add_at = false; |
| 15351 |
if (token->type == CPP_KEYWORD) |
| 15352 |
{ |
| 15353 |
keyword = token->keyword; |
| 15354 |
if (OBJC_IS_AT_KEYWORD (keyword)) |
| 15355 |
{ |
| 15356 |
/* For '@' keywords the token value has the keyword, |
| 15357 |
prepend the '@' for diagnostics. */ |
| 15358 |
attr_name = token->value; |
| 15359 |
add_at = true; |
| 15360 |
} |
| 15361 |
else |
| 15362 |
attr_name = ridpointers[(int)keyword]; |
| 15363 |
} |
| 15364 |
else if (token->type == CPP_NAME) |
| 15365 |
attr_name = token->value; |
| 15366 |
c_parser_consume_token (parser); |
| 15367 |
|
| 15368 |
enum objc_property_attribute_kind prop_kind |
| 15369 |
= objc_prop_attr_kind_for_rid (keyword); |
| 15370 |
property_attribute_info *prop |
| 15371 |
= new property_attribute_info (attr_name, attr_comb, prop_kind); |
| 15372 |
prop_attr_list.safe_push (prop); |
| 15373 |
|
| 15374 |
tree meth_name; |
| 15375 |
switch (prop->prop_kind) |
| 15376 |
{ |
| 15377 |
default: break; |
| 15378 |
case OBJC_PROPERTY_ATTR_UNKNOWN: |
| 15379 |
if (attr_name) |
| 15380 |
error_at (attr_comb, "unknown property attribute %<%s%s%>", |
| 15381 |
add_at ? "@" : "", IDENTIFIER_POINTER (attr_name)); |
| 15382 |
else |
| 15383 |
error_at (attr_comb, "unknown property attribute"); |
| 15384 |
prop->parse_error = syntax_error = true; |
| 15385 |
break; |
| 15386 |
|
| 15387 |
case OBJC_PROPERTY_ATTR_GETTER: |
| 15388 |
case OBJC_PROPERTY_ATTR_SETTER: |
| 15389 |
if (c_parser_next_token_is_not (parser, CPP_EQ)) |
| 15390 |
{ |
| 15391 |
attr_comb = make_location (attr_end, attr_start, attr_end); |
| 15392 |
error_at (attr_comb, "expected %<=%> after Objective-C %qE", |
| 15393 |
attr_name); |
| 15394 |
prop->parse_error = syntax_error = true; |
| 15395 |
break; |
| 15396 |
} |
| 15397 |
token = c_parser_peek_token (parser); |
| 15398 |
attr_end = token->location; |
| 15399 |
c_parser_consume_token (parser); /* eat the = */ |
| 15400 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 15401 |
{ |
| 15402 |
attr_comb = make_location (attr_end, attr_start, attr_end); |
| 15403 |
error_at (attr_comb, "expected %qE selector name", |
| 15404 |
attr_name); |
| 15405 |
prop->parse_error = syntax_error = true; |
| 15406 |
break; |
| 15407 |
} |
| 15408 |
/* Get the end of the method name, and consume the name. */ |
| 15409 |
token = c_parser_peek_token (parser); |
| 15410 |
attr_end = get_finish (token->location); |
| 15411 |
meth_name = token->value; |
| 15412 |
c_parser_consume_token (parser); |
| 15413 |
if (prop->prop_kind == OBJC_PROPERTY_ATTR_SETTER) |
| 15414 |
{ |
| 15415 |
if (c_parser_next_token_is_not (parser, CPP_COLON)) |
| 15416 |
{ |
| 15417 |
attr_comb = make_location (attr_end, attr_start, |
| 15418 |
attr_end); |
| 15419 |
error_at (attr_comb, "setter method names must" |
| 15420 |
" terminate with %<:%>"); |
| 15421 |
prop->parse_error = syntax_error = true; |
| 15422 |
} |
| 15423 |
else |
| 15424 |
{ |
| 15425 |
attr_end = get_finish (c_parser_peek_token |
| 15426 |
(parser)->location); |
| 15427 |
c_parser_consume_token (parser); |
| 15428 |
} |
| 15429 |
attr_comb = make_location (attr_start, attr_start, |
| 15430 |
attr_end); |
| 15431 |
} |
| 15432 |
else |
| 15433 |
attr_comb = make_location (attr_start, attr_start, |
| 15434 |
attr_end); |
| 15435 |
prop->ident = meth_name; |
| 15436 |
/* Updated location including all that was successfully |
| 15437 |
parsed. */ |
| 15438 |
prop->prop_loc = attr_comb; |
| 15439 |
break; |
| 15440 |
} |
| 15441 |
|
| 15442 |
/* If we see a comma here, then keep going - even if we already |
| 15443 |
saw a syntax error. For simple mistakes e.g. (asign, getter=x) |
| 15444 |
this makes a more useful output and avoid spurious warnings about |
| 15445 |
missing attributes that are, in fact, specified after the one with |
| 15446 |
the syntax error. */ |
| 15447 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 15448 |
c_parser_consume_token (parser); |
| 15449 |
else |
| 15450 |
break; |
| 15451 |
} |
| 15452 |
parser->objc_property_attr_context = false; |
| 15453 |
|
| 15454 |
if (syntax_error && c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) |
| 15455 |
/* We don't really want to chew the whole of the file looking for a |
| 15456 |
matching closing parenthesis, so we will try to read the decl and |
| 15457 |
let the error handling for that close out the statement. */ |
| 15458 |
; |
| 15459 |
else |
| 15460 |
syntax_error = false, parens.skip_until_found_close (parser); |
| 15461 |
} |
| 15462 |
|
| 15463 |
/* 'properties' is the list of properties that we read. Usually a |
| 15464 |
single one, but maybe more (eg, in "@property int a, b, c;" there |
| 15465 |
are three). */ |
| 15466 |
tree properties = c_parser_struct_declaration (parser, NULL); |
| 15467 |
|
| 15468 |
if (properties == error_mark_node) |
| 15469 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 15470 |
else |
| 15471 |
{ |
| 15472 |
if (properties == NULL_TREE) |
| 15473 |
c_parser_error (parser, "expected identifier"); |
| 15474 |
else |
| 15475 |
{ |
| 15476 |
/* Comma-separated properties are chained together in reverse order; |
| 15477 |
add them one by one. */ |
| 15478 |
properties = nreverse (properties); |
| 15479 |
for (; properties; properties = TREE_CHAIN (properties)) |
| 15480 |
objc_add_property_declaration (loc, copy_node (properties), |
| 15481 |
prop_attr_list); |
| 15482 |
} |
| 15483 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 15484 |
} |
| 15485 |
|
| 15486 |
while (!prop_attr_list.is_empty()) |
| 15487 |
delete prop_attr_list.pop (); |
| 15488 |
prop_attr_list.release (); |
| 15489 |
parser->error = false; |
| 15490 |
} |
| 15491 |
|
| 15492 |
/* Parse an Objective-C @synthesize declaration. The syntax is: |
| 15493 |
|
| 15494 |
objc-synthesize-declaration: |
| 15495 |
@synthesize objc-synthesize-identifier-list ; |
| 15496 |
|
| 15497 |
objc-synthesize-identifier-list: |
| 15498 |
objc-synthesize-identifier |
| 15499 |
objc-synthesize-identifier-list, objc-synthesize-identifier |
| 15500 |
|
| 15501 |
objc-synthesize-identifier |
| 15502 |
identifier |
| 15503 |
identifier = identifier |
| 15504 |
|
| 15505 |
For example: |
| 15506 |
@synthesize MyProperty; |
| 15507 |
@synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty; |
| 15508 |
|
| 15509 |
PS: This function is identical to cp_parser_objc_at_synthesize_declaration |
| 15510 |
for C++. Keep them in sync. |
| 15511 |
*/ |
| 15512 |
static void |
| 15513 |
c_parser_objc_at_synthesize_declaration (c_parser *parser) |
| 15514 |
{ |
| 15515 |
tree list = NULL_TREE; |
| 15516 |
location_t loc; |
| 15517 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE)); |
| 15518 |
loc = c_parser_peek_token (parser)->location; |
| 15519 |
|
| 15520 |
c_parser_consume_token (parser); |
| 15521 |
while (true) |
| 15522 |
{ |
| 15523 |
tree property, ivar; |
| 15524 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 15525 |
{ |
| 15526 |
c_parser_error (parser, "expected identifier"); |
| 15527 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 15528 |
/* Once we find the semicolon, we can resume normal parsing. |
| 15529 |
We have to reset parser->error manually because |
| 15530 |
c_parser_skip_until_found() won't reset it for us if the |
| 15531 |
next token is precisely a semicolon. */ |
| 15532 |
parser->error = false; |
| 15533 |
return; |
| 15534 |
} |
| 15535 |
property = c_parser_peek_token (parser)->value; |
| 15536 |
c_parser_consume_token (parser); |
| 15537 |
if (c_parser_next_token_is (parser, CPP_EQ)) |
| 15538 |
{ |
| 15539 |
c_parser_consume_token (parser); |
| 15540 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 15541 |
{ |
| 15542 |
c_parser_error (parser, "expected identifier"); |
| 15543 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 15544 |
parser->error = false; |
| 15545 |
return; |
| 15546 |
} |
| 15547 |
ivar = c_parser_peek_token (parser)->value; |
| 15548 |
c_parser_consume_token (parser); |
| 15549 |
} |
| 15550 |
else |
| 15551 |
ivar = NULL_TREE; |
| 15552 |
list = chainon (list, build_tree_list (ivar, property)); |
| 15553 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 15554 |
c_parser_consume_token (parser); |
| 15555 |
else |
| 15556 |
break; |
| 15557 |
} |
| 15558 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 15559 |
objc_add_synthesize_declaration (loc, list); |
| 15560 |
} |
| 15561 |
|
| 15562 |
/* Parse an Objective-C @dynamic declaration. The syntax is: |
| 15563 |
|
| 15564 |
objc-dynamic-declaration: |
| 15565 |
@dynamic identifier-list ; |
| 15566 |
|
| 15567 |
For example: |
| 15568 |
@dynamic MyProperty; |
| 15569 |
@dynamic MyProperty, AnotherProperty; |
| 15570 |
|
| 15571 |
PS: This function is identical to cp_parser_objc_at_dynamic_declaration |
| 15572 |
for C++. Keep them in sync. |
| 15573 |
*/ |
| 15574 |
static void |
| 15575 |
c_parser_objc_at_dynamic_declaration (c_parser *parser) |
| 15576 |
{ |
| 15577 |
tree list = NULL_TREE; |
| 15578 |
location_t loc; |
| 15579 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC)); |
| 15580 |
loc = c_parser_peek_token (parser)->location; |
| 15581 |
|
| 15582 |
c_parser_consume_token (parser); |
| 15583 |
while (true) |
| 15584 |
{ |
| 15585 |
tree property; |
| 15586 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 15587 |
{ |
| 15588 |
c_parser_error (parser, "expected identifier"); |
| 15589 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 15590 |
parser->error = false; |
| 15591 |
return; |
| 15592 |
} |
| 15593 |
property = c_parser_peek_token (parser)->value; |
| 15594 |
list = chainon (list, build_tree_list (NULL_TREE, property)); |
| 15595 |
c_parser_consume_token (parser); |
| 15596 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 15597 |
c_parser_consume_token (parser); |
| 15598 |
else |
| 15599 |
break; |
| 15600 |
} |
| 15601 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 15602 |
objc_add_dynamic_declaration (loc, list); |
| 15603 |
} |
| 15604 |
|
| 15605 |
|
| 15606 |
/* Parse a pragma GCC ivdep. */ |
| 15607 |
|
| 15608 |
static bool |
| 15609 |
c_parse_pragma_ivdep (c_parser *parser) |
| 15610 |
{ |
| 15611 |
c_parser_consume_pragma (parser); |
| 15612 |
c_parser_skip_to_pragma_eol (parser); |
| 15613 |
return true; |
| 15614 |
} |
| 15615 |
|
| 15616 |
/* Parse a pragma GCC novector. */ |
| 15617 |
|
| 15618 |
static bool |
| 15619 |
c_parse_pragma_novector (c_parser *parser) |
| 15620 |
{ |
| 15621 |
c_parser_consume_pragma (parser); |
| 15622 |
c_parser_skip_to_pragma_eol (parser); |
| 15623 |
return true; |
| 15624 |
} |
| 15625 |
|
| 15626 |
/* Parse a pragma GCC unroll. */ |
| 15627 |
|
| 15628 |
static unsigned short |
| 15629 |
c_parser_pragma_unroll (c_parser *parser) |
| 15630 |
{ |
| 15631 |
unsigned short unroll; |
| 15632 |
c_parser_consume_pragma (parser); |
| 15633 |
location_t location = c_parser_peek_token (parser)->location; |
| 15634 |
tree expr = c_parser_expr_no_commas (parser, NULL).value; |
| 15635 |
mark_exp_read (expr); |
| 15636 |
expr = c_fully_fold (expr, false, NULL); |
| 15637 |
HOST_WIDE_INT lunroll = 0; |
| 15638 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)) |
| 15639 |
|| TREE_CODE (expr) != INTEGER_CST |
| 15640 |
|| (lunroll = tree_to_shwi (expr)) < 0 |
| 15641 |
|| lunroll >= USHRT_MAX) |
| 15642 |
{ |
| 15643 |
error_at (location, "%<#pragma GCC unroll%> requires an" |
| 15644 |
" assignment-expression that evaluates to a non-negative" |
| 15645 |
" integral constant less than %u", USHRT_MAX); |
| 15646 |
unroll = 0; |
| 15647 |
} |
| 15648 |
else |
| 15649 |
{ |
| 15650 |
unroll = (unsigned short)lunroll; |
| 15651 |
if (unroll == 0) |
| 15652 |
unroll = 1; |
| 15653 |
} |
| 15654 |
|
| 15655 |
c_parser_skip_to_pragma_eol (parser); |
| 15656 |
return unroll; |
| 15657 |
} |
| 15658 |
|
| 15659 |
/* Handle pragmas. Some OpenMP pragmas are associated with, and therefore |
| 15660 |
should be considered, statements. ALLOW_STMT is true if we're within |
| 15661 |
the context of a function and such pragmas are to be allowed. Returns |
| 15662 |
true if we actually parsed such a pragma. BEFORE_LABELS is last statement |
| 15663 |
before possible labels, see get_before_labels description for details. */ |
| 15664 |
|
| 15665 |
static bool |
| 15666 |
c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p, |
| 15667 |
tree before_labels) |
| 15668 |
{ |
| 15669 |
unsigned int id; |
| 15670 |
const char *construct = NULL; |
| 15671 |
|
| 15672 |
input_location = c_parser_peek_token (parser)->location; |
| 15673 |
id = c_parser_peek_token (parser)->pragma_kind; |
| 15674 |
gcc_assert (id != PRAGMA_NONE); |
| 15675 |
if (parser->omp_for_parse_state |
| 15676 |
&& parser->omp_for_parse_state->in_intervening_code |
| 15677 |
&& id >= PRAGMA_OMP__START_ |
| 15678 |
&& id <= PRAGMA_OMP__LAST_) |
| 15679 |
{ |
| 15680 |
error_at (input_location, |
| 15681 |
"intervening code must not contain OpenMP directives"); |
| 15682 |
parser->omp_for_parse_state->fail = true; |
| 15683 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15684 |
return false; |
| 15685 |
} |
| 15686 |
|
| 15687 |
switch (id) |
| 15688 |
{ |
| 15689 |
case PRAGMA_OACC_DECLARE: |
| 15690 |
c_parser_oacc_declare (parser); |
| 15691 |
return false; |
| 15692 |
|
| 15693 |
case PRAGMA_OACC_ENTER_DATA: |
| 15694 |
if (context != pragma_compound) |
| 15695 |
{ |
| 15696 |
construct = "acc enter data"; |
| 15697 |
in_compound: |
| 15698 |
if (context == pragma_stmt) |
| 15699 |
{ |
| 15700 |
error_at (c_parser_peek_token (parser)->location, |
| 15701 |
"%<#pragma %s%> may only be used in compound " |
| 15702 |
"statements", construct); |
| 15703 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15704 |
return true; |
| 15705 |
} |
| 15706 |
goto bad_stmt; |
| 15707 |
} |
| 15708 |
c_parser_oacc_enter_exit_data (parser, true); |
| 15709 |
return false; |
| 15710 |
|
| 15711 |
case PRAGMA_OACC_EXIT_DATA: |
| 15712 |
if (context != pragma_compound) |
| 15713 |
{ |
| 15714 |
construct = "acc exit data"; |
| 15715 |
goto in_compound; |
| 15716 |
} |
| 15717 |
c_parser_oacc_enter_exit_data (parser, false); |
| 15718 |
return false; |
| 15719 |
|
| 15720 |
case PRAGMA_OACC_ROUTINE: |
| 15721 |
if (context != pragma_external) |
| 15722 |
{ |
| 15723 |
error_at (c_parser_peek_token (parser)->location, |
| 15724 |
"%<#pragma acc routine%> must be at file scope"); |
| 15725 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15726 |
return false; |
| 15727 |
} |
| 15728 |
c_parser_oacc_routine (parser, context); |
| 15729 |
return false; |
| 15730 |
|
| 15731 |
case PRAGMA_OACC_UPDATE: |
| 15732 |
if (context != pragma_compound) |
| 15733 |
{ |
| 15734 |
construct = "acc update"; |
| 15735 |
goto in_compound; |
| 15736 |
} |
| 15737 |
c_parser_oacc_update (parser); |
| 15738 |
return false; |
| 15739 |
|
| 15740 |
case PRAGMA_OMP_BARRIER: |
| 15741 |
if (context != pragma_compound) |
| 15742 |
{ |
| 15743 |
construct = "omp barrier"; |
| 15744 |
goto in_compound; |
| 15745 |
} |
| 15746 |
c_parser_omp_barrier (parser); |
| 15747 |
return false; |
| 15748 |
|
| 15749 |
case PRAGMA_OMP_DEPOBJ: |
| 15750 |
if (context != pragma_compound) |
| 15751 |
{ |
| 15752 |
construct = "omp depobj"; |
| 15753 |
goto in_compound; |
| 15754 |
} |
| 15755 |
c_parser_omp_depobj (parser); |
| 15756 |
return false; |
| 15757 |
|
| 15758 |
case PRAGMA_OMP_FLUSH: |
| 15759 |
if (context != pragma_compound) |
| 15760 |
{ |
| 15761 |
construct = "omp flush"; |
| 15762 |
goto in_compound; |
| 15763 |
} |
| 15764 |
c_parser_omp_flush (parser); |
| 15765 |
return false; |
| 15766 |
|
| 15767 |
case PRAGMA_OMP_INTEROP: |
| 15768 |
if (context != pragma_compound) |
| 15769 |
{ |
| 15770 |
construct = "omp interop"; |
| 15771 |
goto in_compound; |
| 15772 |
} |
| 15773 |
c_parser_omp_interop (parser); |
| 15774 |
return false; |
| 15775 |
|
| 15776 |
case PRAGMA_OMP_TASKWAIT: |
| 15777 |
if (context != pragma_compound) |
| 15778 |
{ |
| 15779 |
construct = "omp taskwait"; |
| 15780 |
goto in_compound; |
| 15781 |
} |
| 15782 |
c_parser_omp_taskwait (parser); |
| 15783 |
return false; |
| 15784 |
|
| 15785 |
case PRAGMA_OMP_TASKYIELD: |
| 15786 |
if (context != pragma_compound) |
| 15787 |
{ |
| 15788 |
construct = "omp taskyield"; |
| 15789 |
goto in_compound; |
| 15790 |
} |
| 15791 |
c_parser_omp_taskyield (parser); |
| 15792 |
return false; |
| 15793 |
|
| 15794 |
case PRAGMA_OMP_CANCEL: |
| 15795 |
if (context != pragma_compound) |
| 15796 |
{ |
| 15797 |
construct = "omp cancel"; |
| 15798 |
goto in_compound; |
| 15799 |
} |
| 15800 |
c_parser_omp_cancel (parser); |
| 15801 |
return false; |
| 15802 |
|
| 15803 |
case PRAGMA_OMP_CANCELLATION_POINT: |
| 15804 |
return c_parser_omp_cancellation_point (parser, context); |
| 15805 |
|
| 15806 |
case PRAGMA_OMP_THREADPRIVATE: |
| 15807 |
c_parser_omp_threadprivate (parser); |
| 15808 |
return false; |
| 15809 |
|
| 15810 |
case PRAGMA_OMP_TARGET: |
| 15811 |
return c_parser_omp_target (parser, context, if_p); |
| 15812 |
|
| 15813 |
case PRAGMA_OMP_BEGIN: |
| 15814 |
c_parser_omp_begin (parser); |
| 15815 |
return false; |
| 15816 |
|
| 15817 |
case PRAGMA_OMP_END: |
| 15818 |
c_parser_omp_end (parser); |
| 15819 |
return false; |
| 15820 |
|
| 15821 |
case PRAGMA_OMP_SCAN: |
| 15822 |
error_at (c_parser_peek_token (parser)->location, |
| 15823 |
"%<#pragma omp scan%> may only be used in " |
| 15824 |
"a loop construct with %<inscan%> %<reduction%> clause"); |
| 15825 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15826 |
return false; |
| 15827 |
|
| 15828 |
case PRAGMA_OMP_SECTION: |
| 15829 |
error_at (c_parser_peek_token (parser)->location, |
| 15830 |
"%<#pragma omp section%> may only be used in " |
| 15831 |
"%<#pragma omp sections%> construct"); |
| 15832 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15833 |
return false; |
| 15834 |
|
| 15835 |
case PRAGMA_OMP_DECLARE: |
| 15836 |
return c_parser_omp_declare (parser, context); |
| 15837 |
|
| 15838 |
case PRAGMA_OMP_REQUIRES: |
| 15839 |
if (context != pragma_external) |
| 15840 |
{ |
| 15841 |
error_at (c_parser_peek_token (parser)->location, |
| 15842 |
"%<#pragma %s%> may only be used at file scope", |
| 15843 |
"omp requires"); |
| 15844 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15845 |
return false; |
| 15846 |
} |
| 15847 |
c_parser_omp_requires (parser); |
| 15848 |
return false; |
| 15849 |
|
| 15850 |
case PRAGMA_OMP_ALLOCATE: |
| 15851 |
c_parser_omp_allocate (parser); |
| 15852 |
return false; |
| 15853 |
|
| 15854 |
case PRAGMA_OMP_ASSUMES: |
| 15855 |
if (context != pragma_external) |
| 15856 |
{ |
| 15857 |
error_at (c_parser_peek_token (parser)->location, |
| 15858 |
"%<#pragma %s%> may only be used at file scope", |
| 15859 |
"omp assumes"); |
| 15860 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15861 |
return false; |
| 15862 |
} |
| 15863 |
c_parser_omp_assumes (parser); |
| 15864 |
return false; |
| 15865 |
|
| 15866 |
case PRAGMA_OMP_NOTHING: |
| 15867 |
c_parser_omp_nothing (parser); |
| 15868 |
return false; |
| 15869 |
|
| 15870 |
case PRAGMA_OMP_METADIRECTIVE: |
| 15871 |
c_parser_omp_metadirective (parser, if_p); |
| 15872 |
return true; |
| 15873 |
|
| 15874 |
case PRAGMA_OMP_ERROR: |
| 15875 |
return c_parser_omp_error (parser, context); |
| 15876 |
|
| 15877 |
case PRAGMA_OMP_ORDERED: |
| 15878 |
return c_parser_omp_ordered (parser, context, if_p); |
| 15879 |
|
| 15880 |
case PRAGMA_NOVECTOR: |
| 15881 |
case PRAGMA_UNROLL: |
| 15882 |
case PRAGMA_IVDEP: |
| 15883 |
{ |
| 15884 |
bool novector = false; |
| 15885 |
unsigned short unroll = 0; |
| 15886 |
bool ivdep = false; |
| 15887 |
|
| 15888 |
switch (id) |
| 15889 |
{ |
| 15890 |
case PRAGMA_NOVECTOR: |
| 15891 |
novector = c_parse_pragma_novector (parser); |
| 15892 |
break; |
| 15893 |
case PRAGMA_UNROLL: |
| 15894 |
unroll = c_parser_pragma_unroll (parser); |
| 15895 |
break; |
| 15896 |
case PRAGMA_IVDEP: |
| 15897 |
ivdep = c_parse_pragma_ivdep (parser); |
| 15898 |
break; |
| 15899 |
default: |
| 15900 |
gcc_unreachable (); |
| 15901 |
} |
| 15902 |
|
| 15903 |
c_token *tok = c_parser_peek_token (parser); |
| 15904 |
bool has_more = tok->type == CPP_PRAGMA; |
| 15905 |
while (has_more) |
| 15906 |
{ |
| 15907 |
switch (tok->pragma_kind) |
| 15908 |
{ |
| 15909 |
case PRAGMA_IVDEP: |
| 15910 |
ivdep = c_parse_pragma_ivdep (parser); |
| 15911 |
break; |
| 15912 |
case PRAGMA_UNROLL: |
| 15913 |
unroll = c_parser_pragma_unroll (parser); |
| 15914 |
break; |
| 15915 |
case PRAGMA_NOVECTOR: |
| 15916 |
novector = c_parse_pragma_novector (parser); |
| 15917 |
break; |
| 15918 |
default: |
| 15919 |
has_more = false; |
| 15920 |
break; |
| 15921 |
} |
| 15922 |
tok = c_parser_peek_token (parser); |
| 15923 |
has_more = has_more && tok->type == CPP_PRAGMA; |
| 15924 |
} |
| 15925 |
if (!c_parser_next_token_is_keyword (parser, RID_FOR) |
| 15926 |
&& !c_parser_next_token_is_keyword (parser, RID_WHILE) |
| 15927 |
&& !c_parser_next_token_is_keyword (parser, RID_DO)) |
| 15928 |
{ |
| 15929 |
c_parser_error (parser, "for, while or do statement expected"); |
| 15930 |
return false; |
| 15931 |
} |
| 15932 |
if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 15933 |
c_parser_for_statement (parser, ivdep, unroll, novector, if_p, |
| 15934 |
before_labels); |
| 15935 |
else if (c_parser_next_token_is_keyword (parser, RID_WHILE)) |
| 15936 |
c_parser_while_statement (parser, ivdep, unroll, novector, if_p, |
| 15937 |
before_labels); |
| 15938 |
else |
| 15939 |
c_parser_do_statement (parser, ivdep, unroll, novector, |
| 15940 |
before_labels); |
| 15941 |
} |
| 15942 |
return true; |
| 15943 |
|
| 15944 |
case PRAGMA_GCC_PCH_PREPROCESS: |
| 15945 |
c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); |
| 15946 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15947 |
return false; |
| 15948 |
|
| 15949 |
case PRAGMA_OACC_WAIT: |
| 15950 |
if (context != pragma_compound) |
| 15951 |
{ |
| 15952 |
construct = "acc wait"; |
| 15953 |
goto in_compound; |
| 15954 |
} |
| 15955 |
/* FALL THROUGH. */ |
| 15956 |
|
| 15957 |
default: |
| 15958 |
if (id < PRAGMA_FIRST_EXTERNAL) |
| 15959 |
{ |
| 15960 |
if (context != pragma_stmt && context != pragma_compound) |
| 15961 |
{ |
| 15962 |
bad_stmt: |
| 15963 |
c_parser_error (parser, "expected declaration specifiers"); |
| 15964 |
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 15965 |
return false; |
| 15966 |
} |
| 15967 |
c_parser_omp_construct (parser, if_p); |
| 15968 |
return true; |
| 15969 |
} |
| 15970 |
break; |
| 15971 |
} |
| 15972 |
|
| 15973 |
c_parser_consume_pragma (parser); |
| 15974 |
c_invoke_pragma_handler (id); |
| 15975 |
|
| 15976 |
/* Skip to EOL, but suppress any error message. Those will have been |
| 15977 |
generated by the handler routine through calling error, as opposed |
| 15978 |
to calling c_parser_error. */ |
| 15979 |
parser->error = true; |
| 15980 |
c_parser_skip_to_pragma_eol (parser); |
| 15981 |
|
| 15982 |
return false; |
| 15983 |
} |
| 15984 |
|
| 15985 |
/* The interface the pragma parsers have to the lexer. */ |
| 15986 |
|
| 15987 |
enum cpp_ttype |
| 15988 |
pragma_lex (tree *value, location_t *loc) |
| 15989 |
{ |
| 15990 |
c_token *tok = c_parser_peek_token (the_parser); |
| 15991 |
enum cpp_ttype ret = tok->type; |
| 15992 |
|
| 15993 |
*value = tok->value; |
| 15994 |
if (loc) |
| 15995 |
*loc = tok->location; |
| 15996 |
|
| 15997 |
if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) |
| 15998 |
ret = CPP_EOF; |
| 15999 |
else if (ret == CPP_STRING) |
| 16000 |
*value = c_parser_string_literal (the_parser, false, false).value; |
| 16001 |
else |
| 16002 |
{ |
| 16003 |
if (ret == CPP_KEYWORD) |
| 16004 |
ret = CPP_NAME; |
| 16005 |
c_parser_consume_token (the_parser); |
| 16006 |
} |
| 16007 |
|
| 16008 |
return ret; |
| 16009 |
} |
| 16010 |
|
| 16011 |
void |
| 16012 |
pragma_lex_discard_to_eol () |
| 16013 |
{ |
| 16014 |
cpp_ttype type; |
| 16015 |
do |
| 16016 |
{ |
| 16017 |
type = c_parser_peek_token (the_parser)->type; |
| 16018 |
gcc_assert (type != CPP_EOF); |
| 16019 |
c_parser_consume_token (the_parser); |
| 16020 |
} while (type != CPP_PRAGMA_EOL); |
| 16021 |
} |
| 16022 |
|
| 16023 |
static void |
| 16024 |
c_parser_pragma_pch_preprocess (c_parser *parser) |
| 16025 |
{ |
| 16026 |
tree name = NULL; |
| 16027 |
|
| 16028 |
parser->lex_joined_string = true; |
| 16029 |
c_parser_consume_pragma (parser); |
| 16030 |
if (c_parser_next_token_is (parser, CPP_STRING)) |
| 16031 |
{ |
| 16032 |
name = c_parser_peek_token (parser)->value; |
| 16033 |
c_parser_consume_token (parser); |
| 16034 |
} |
| 16035 |
else |
| 16036 |
c_parser_error (parser, "expected string literal"); |
| 16037 |
c_parser_skip_to_pragma_eol (parser); |
| 16038 |
parser->lex_joined_string = false; |
| 16039 |
|
| 16040 |
if (name) |
| 16041 |
c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name)); |
| 16042 |
} |
| 16043 |
|
| 16044 |
/* OpenACC and OpenMP parsing routines. */ |
| 16045 |
|
| 16046 |
/* Returns name of the next clause. |
| 16047 |
If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and |
| 16048 |
the token is not consumed. Otherwise appropriate pragma_omp_clause is |
| 16049 |
returned and the token is consumed. */ |
| 16050 |
|
| 16051 |
static pragma_omp_clause |
| 16052 |
c_parser_omp_clause_name (c_parser *parser) |
| 16053 |
{ |
| 16054 |
pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE; |
| 16055 |
|
| 16056 |
if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
| 16057 |
result = PRAGMA_OACC_CLAUSE_AUTO; |
| 16058 |
else if (c_parser_next_token_is_keyword (parser, RID_IF)) |
| 16059 |
result = PRAGMA_OMP_CLAUSE_IF; |
| 16060 |
else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) |
| 16061 |
result = PRAGMA_OMP_CLAUSE_DEFAULT; |
| 16062 |
else if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 16063 |
result = PRAGMA_OMP_CLAUSE_FOR; |
| 16064 |
else if (c_parser_next_token_is (parser, CPP_NAME)) |
| 16065 |
{ |
| 16066 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 16067 |
|
| 16068 |
switch (p[0]) |
| 16069 |
{ |
| 16070 |
case 'a': |
| 16071 |
if (!strcmp ("affinity", p)) |
| 16072 |
result = PRAGMA_OMP_CLAUSE_AFFINITY; |
| 16073 |
else if (!strcmp ("aligned", p)) |
| 16074 |
result = PRAGMA_OMP_CLAUSE_ALIGNED; |
| 16075 |
else if (!strcmp ("allocate", p)) |
| 16076 |
result = PRAGMA_OMP_CLAUSE_ALLOCATE; |
| 16077 |
else if (!strcmp ("async", p)) |
| 16078 |
result = PRAGMA_OACC_CLAUSE_ASYNC; |
| 16079 |
else if (!strcmp ("attach", p)) |
| 16080 |
result = PRAGMA_OACC_CLAUSE_ATTACH; |
| 16081 |
break; |
| 16082 |
case 'b': |
| 16083 |
if (!strcmp ("bind", p)) |
| 16084 |
result = PRAGMA_OMP_CLAUSE_BIND; |
| 16085 |
break; |
| 16086 |
case 'c': |
| 16087 |
if (!strcmp ("collapse", p)) |
| 16088 |
result = PRAGMA_OMP_CLAUSE_COLLAPSE; |
| 16089 |
else if (!strcmp ("copy", p)) |
| 16090 |
result = PRAGMA_OACC_CLAUSE_COPY; |
| 16091 |
else if (!strcmp ("copyin", p)) |
| 16092 |
result = PRAGMA_OMP_CLAUSE_COPYIN; |
| 16093 |
else if (!strcmp ("copyout", p)) |
| 16094 |
result = PRAGMA_OACC_CLAUSE_COPYOUT; |
| 16095 |
else if (!strcmp ("copyprivate", p)) |
| 16096 |
result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; |
| 16097 |
else if (!strcmp ("create", p)) |
| 16098 |
result = PRAGMA_OACC_CLAUSE_CREATE; |
| 16099 |
break; |
| 16100 |
case 'd': |
| 16101 |
if (!strcmp ("defaultmap", p)) |
| 16102 |
result = PRAGMA_OMP_CLAUSE_DEFAULTMAP; |
| 16103 |
else if (!strcmp ("delete", p)) |
| 16104 |
result = PRAGMA_OACC_CLAUSE_DELETE; |
| 16105 |
else if (!strcmp ("depend", p)) |
| 16106 |
result = PRAGMA_OMP_CLAUSE_DEPEND; |
| 16107 |
else if (!strcmp ("destroy", p)) |
| 16108 |
result = PRAGMA_OMP_CLAUSE_DESTROY; |
| 16109 |
else if (!strcmp ("detach", p)) |
| 16110 |
result = PRAGMA_OACC_CLAUSE_DETACH; |
| 16111 |
else if (!strcmp ("device", p)) |
| 16112 |
result = PRAGMA_OMP_CLAUSE_DEVICE; |
| 16113 |
else if (!strcmp ("deviceptr", p)) |
| 16114 |
result = PRAGMA_OACC_CLAUSE_DEVICEPTR; |
| 16115 |
else if (!strcmp ("device_resident", p)) |
| 16116 |
result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT; |
| 16117 |
else if (!strcmp ("device_type", p)) |
| 16118 |
result = PRAGMA_OMP_CLAUSE_DEVICE_TYPE; |
| 16119 |
else if (!strcmp ("dist_schedule", p)) |
| 16120 |
result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE; |
| 16121 |
else if (!strcmp ("doacross", p)) |
| 16122 |
result = PRAGMA_OMP_CLAUSE_DOACROSS; |
| 16123 |
break; |
| 16124 |
case 'e': |
| 16125 |
if (!strcmp ("enter", p)) |
| 16126 |
result = PRAGMA_OMP_CLAUSE_ENTER; |
| 16127 |
break; |
| 16128 |
case 'f': |
| 16129 |
if (!strcmp ("filter", p)) |
| 16130 |
result = PRAGMA_OMP_CLAUSE_FILTER; |
| 16131 |
else if (!strcmp ("final", p)) |
| 16132 |
result = PRAGMA_OMP_CLAUSE_FINAL; |
| 16133 |
else if (!strcmp ("finalize", p)) |
| 16134 |
result = PRAGMA_OACC_CLAUSE_FINALIZE; |
| 16135 |
else if (!strcmp ("firstprivate", p)) |
| 16136 |
result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; |
| 16137 |
else if (!strcmp ("from", p)) |
| 16138 |
result = PRAGMA_OMP_CLAUSE_FROM; |
| 16139 |
else if (!strcmp ("full", p)) |
| 16140 |
result = PRAGMA_OMP_CLAUSE_FULL; |
| 16141 |
break; |
| 16142 |
case 'g': |
| 16143 |
if (!strcmp ("gang", p)) |
| 16144 |
result = PRAGMA_OACC_CLAUSE_GANG; |
| 16145 |
else if (!strcmp ("grainsize", p)) |
| 16146 |
result = PRAGMA_OMP_CLAUSE_GRAINSIZE; |
| 16147 |
break; |
| 16148 |
case 'h': |
| 16149 |
if (!strcmp ("has_device_addr", p)) |
| 16150 |
result = PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR; |
| 16151 |
else if (!strcmp ("hint", p)) |
| 16152 |
result = PRAGMA_OMP_CLAUSE_HINT; |
| 16153 |
else if (!strcmp ("host", p)) |
| 16154 |
result = PRAGMA_OACC_CLAUSE_HOST; |
| 16155 |
break; |
| 16156 |
case 'i': |
| 16157 |
if (!strcmp ("if_present", p)) |
| 16158 |
result = PRAGMA_OACC_CLAUSE_IF_PRESENT; |
| 16159 |
else if (!strcmp ("in_reduction", p)) |
| 16160 |
result = PRAGMA_OMP_CLAUSE_IN_REDUCTION; |
| 16161 |
else if (!strcmp ("inbranch", p)) |
| 16162 |
result = PRAGMA_OMP_CLAUSE_INBRANCH; |
| 16163 |
else if (!strcmp ("independent", p)) |
| 16164 |
result = PRAGMA_OACC_CLAUSE_INDEPENDENT; |
| 16165 |
else if (!strcmp ("indirect", p)) |
| 16166 |
result = PRAGMA_OMP_CLAUSE_INDIRECT; |
| 16167 |
else if (!strcmp ("init", p)) |
| 16168 |
result = PRAGMA_OMP_CLAUSE_INIT; |
| 16169 |
else if (!strcmp ("is_device_ptr", p)) |
| 16170 |
result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR; |
| 16171 |
else if (!strcmp ("interop", p)) |
| 16172 |
result = PRAGMA_OMP_CLAUSE_INTEROP; |
| 16173 |
break; |
| 16174 |
case 'l': |
| 16175 |
if (!strcmp ("lastprivate", p)) |
| 16176 |
result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; |
| 16177 |
else if (!strcmp ("linear", p)) |
| 16178 |
result = PRAGMA_OMP_CLAUSE_LINEAR; |
| 16179 |
else if (!strcmp ("link", p)) |
| 16180 |
result = PRAGMA_OMP_CLAUSE_LINK; |
| 16181 |
break; |
| 16182 |
case 'm': |
| 16183 |
if (!strcmp ("map", p)) |
| 16184 |
result = PRAGMA_OMP_CLAUSE_MAP; |
| 16185 |
else if (!strcmp ("mergeable", p)) |
| 16186 |
result = PRAGMA_OMP_CLAUSE_MERGEABLE; |
| 16187 |
break; |
| 16188 |
case 'n': |
| 16189 |
if (!strcmp ("no_create", p)) |
| 16190 |
result = PRAGMA_OACC_CLAUSE_NO_CREATE; |
| 16191 |
else if (!strcmp ("nocontext", p)) |
| 16192 |
result = PRAGMA_OMP_CLAUSE_NOCONTEXT; |
| 16193 |
else if (!strcmp ("nogroup", p)) |
| 16194 |
result = PRAGMA_OMP_CLAUSE_NOGROUP; |
| 16195 |
else if (!strcmp ("nohost", p)) |
| 16196 |
result = PRAGMA_OACC_CLAUSE_NOHOST; |
| 16197 |
else if (!strcmp ("nontemporal", p)) |
| 16198 |
result = PRAGMA_OMP_CLAUSE_NONTEMPORAL; |
| 16199 |
else if (!strcmp ("notinbranch", p)) |
| 16200 |
result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; |
| 16201 |
else if (!strcmp ("novariants", p)) |
| 16202 |
result = PRAGMA_OMP_CLAUSE_NOVARIANTS; |
| 16203 |
else if (!strcmp ("nowait", p)) |
| 16204 |
result = PRAGMA_OMP_CLAUSE_NOWAIT; |
| 16205 |
else if (!strcmp ("num_gangs", p)) |
| 16206 |
result = PRAGMA_OACC_CLAUSE_NUM_GANGS; |
| 16207 |
else if (!strcmp ("num_tasks", p)) |
| 16208 |
result = PRAGMA_OMP_CLAUSE_NUM_TASKS; |
| 16209 |
else if (!strcmp ("num_teams", p)) |
| 16210 |
result = PRAGMA_OMP_CLAUSE_NUM_TEAMS; |
| 16211 |
else if (!strcmp ("num_threads", p)) |
| 16212 |
result = PRAGMA_OMP_CLAUSE_NUM_THREADS; |
| 16213 |
else if (!strcmp ("num_workers", p)) |
| 16214 |
result = PRAGMA_OACC_CLAUSE_NUM_WORKERS; |
| 16215 |
break; |
| 16216 |
case 'o': |
| 16217 |
if (!strcmp ("ordered", p)) |
| 16218 |
result = PRAGMA_OMP_CLAUSE_ORDERED; |
| 16219 |
else if (!strcmp ("order", p)) |
| 16220 |
result = PRAGMA_OMP_CLAUSE_ORDER; |
| 16221 |
break; |
| 16222 |
case 'p': |
| 16223 |
if (!strcmp ("parallel", p)) |
| 16224 |
result = PRAGMA_OMP_CLAUSE_PARALLEL; |
| 16225 |
else if (!strcmp ("partial", p)) |
| 16226 |
result = PRAGMA_OMP_CLAUSE_PARTIAL; |
| 16227 |
else if (!strcmp ("present", p)) |
| 16228 |
result = PRAGMA_OACC_CLAUSE_PRESENT; |
| 16229 |
/* As of OpenACC 2.5, these are now aliases of the non-present_or |
| 16230 |
clauses. */ |
| 16231 |
else if (!strcmp ("present_or_copy", p) |
| 16232 |
|| !strcmp ("pcopy", p)) |
| 16233 |
result = PRAGMA_OACC_CLAUSE_COPY; |
| 16234 |
else if (!strcmp ("present_or_copyin", p) |
| 16235 |
|| !strcmp ("pcopyin", p)) |
| 16236 |
result = PRAGMA_OACC_CLAUSE_COPYIN; |
| 16237 |
else if (!strcmp ("present_or_copyout", p) |
| 16238 |
|| !strcmp ("pcopyout", p)) |
| 16239 |
result = PRAGMA_OACC_CLAUSE_COPYOUT; |
| 16240 |
else if (!strcmp ("present_or_create", p) |
| 16241 |
|| !strcmp ("pcreate", p)) |
| 16242 |
result = PRAGMA_OACC_CLAUSE_CREATE; |
| 16243 |
else if (!strcmp ("priority", p)) |
| 16244 |
result = PRAGMA_OMP_CLAUSE_PRIORITY; |
| 16245 |
else if (!strcmp ("private", p)) |
| 16246 |
result = PRAGMA_OMP_CLAUSE_PRIVATE; |
| 16247 |
else if (!strcmp ("proc_bind", p)) |
| 16248 |
result = PRAGMA_OMP_CLAUSE_PROC_BIND; |
| 16249 |
break; |
| 16250 |
case 'r': |
| 16251 |
if (!strcmp ("reduction", p)) |
| 16252 |
result = PRAGMA_OMP_CLAUSE_REDUCTION; |
| 16253 |
break; |
| 16254 |
case 's': |
| 16255 |
if (!strcmp ("safelen", p)) |
| 16256 |
result = PRAGMA_OMP_CLAUSE_SAFELEN; |
| 16257 |
else if (!strcmp ("schedule", p)) |
| 16258 |
result = PRAGMA_OMP_CLAUSE_SCHEDULE; |
| 16259 |
else if (!strcmp ("sections", p)) |
| 16260 |
result = PRAGMA_OMP_CLAUSE_SECTIONS; |
| 16261 |
else if (!strcmp ("self", p)) |
| 16262 |
result = PRAGMA_OACC_CLAUSE_SELF; |
| 16263 |
else if (!strcmp ("seq", p)) |
| 16264 |
result = PRAGMA_OACC_CLAUSE_SEQ; |
| 16265 |
else if (!strcmp ("shared", p)) |
| 16266 |
result = PRAGMA_OMP_CLAUSE_SHARED; |
| 16267 |
else if (!strcmp ("simd", p)) |
| 16268 |
result = PRAGMA_OMP_CLAUSE_SIMD; |
| 16269 |
else if (!strcmp ("simdlen", p)) |
| 16270 |
result = PRAGMA_OMP_CLAUSE_SIMDLEN; |
| 16271 |
break; |
| 16272 |
case 't': |
| 16273 |
if (!strcmp ("task_reduction", p)) |
| 16274 |
result = PRAGMA_OMP_CLAUSE_TASK_REDUCTION; |
| 16275 |
else if (!strcmp ("taskgroup", p)) |
| 16276 |
result = PRAGMA_OMP_CLAUSE_TASKGROUP; |
| 16277 |
else if (!strcmp ("thread_limit", p)) |
| 16278 |
result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; |
| 16279 |
else if (!strcmp ("threads", p)) |
| 16280 |
result = PRAGMA_OMP_CLAUSE_THREADS; |
| 16281 |
else if (!strcmp ("tile", p)) |
| 16282 |
result = PRAGMA_OACC_CLAUSE_TILE; |
| 16283 |
else if (!strcmp ("to", p)) |
| 16284 |
result = PRAGMA_OMP_CLAUSE_TO; |
| 16285 |
break; |
| 16286 |
case 'u': |
| 16287 |
if (!strcmp ("uniform", p)) |
| 16288 |
result = PRAGMA_OMP_CLAUSE_UNIFORM; |
| 16289 |
else if (!strcmp ("untied", p)) |
| 16290 |
result = PRAGMA_OMP_CLAUSE_UNTIED; |
| 16291 |
else if (!strcmp ("use", p)) |
| 16292 |
result = PRAGMA_OMP_CLAUSE_USE; |
| 16293 |
else if (!strcmp ("use_device", p)) |
| 16294 |
result = PRAGMA_OACC_CLAUSE_USE_DEVICE; |
| 16295 |
else if (!strcmp ("use_device_addr", p)) |
| 16296 |
result = PRAGMA_OMP_CLAUSE_USE_DEVICE_ADDR; |
| 16297 |
else if (!strcmp ("use_device_ptr", p)) |
| 16298 |
result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR; |
| 16299 |
break; |
| 16300 |
case 'v': |
| 16301 |
if (!strcmp ("vector", p)) |
| 16302 |
result = PRAGMA_OACC_CLAUSE_VECTOR; |
| 16303 |
else if (!strcmp ("vector_length", p)) |
| 16304 |
result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH; |
| 16305 |
break; |
| 16306 |
case 'w': |
| 16307 |
if (!strcmp ("wait", p)) |
| 16308 |
result = PRAGMA_OACC_CLAUSE_WAIT; |
| 16309 |
else if (!strcmp ("worker", p)) |
| 16310 |
result = PRAGMA_OACC_CLAUSE_WORKER; |
| 16311 |
break; |
| 16312 |
} |
| 16313 |
} |
| 16314 |
|
| 16315 |
if (result != PRAGMA_OMP_CLAUSE_NONE) |
| 16316 |
c_parser_consume_token (parser); |
| 16317 |
|
| 16318 |
return result; |
| 16319 |
} |
| 16320 |
|
| 16321 |
/* Validate that a clause of the given type does not already exist. */ |
| 16322 |
|
| 16323 |
static void |
| 16324 |
check_no_duplicate_clause (tree clauses, enum omp_clause_code code, |
| 16325 |
const char *name) |
| 16326 |
{ |
| 16327 |
if (tree c = omp_find_clause (clauses, code)) |
| 16328 |
error_at (OMP_CLAUSE_LOCATION (c), "too many %qs clauses", name); |
| 16329 |
} |
| 16330 |
|
| 16331 |
/* OpenACC 2.0 |
| 16332 |
Parse wait clause or wait directive parameters. */ |
| 16333 |
|
| 16334 |
static tree |
| 16335 |
c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list) |
| 16336 |
{ |
| 16337 |
vec<tree, va_gc> *args; |
| 16338 |
tree t, args_tree; |
| 16339 |
|
| 16340 |
matching_parens parens; |
| 16341 |
if (!parens.require_open (parser)) |
| 16342 |
return list; |
| 16343 |
|
| 16344 |
args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL); |
| 16345 |
args_tree = build_tree_list_vec (args); |
| 16346 |
|
| 16347 |
for (t = args_tree; t; t = TREE_CHAIN (t)) |
| 16348 |
{ |
| 16349 |
tree targ = TREE_VALUE (t); |
| 16350 |
|
| 16351 |
if (targ != error_mark_node) |
| 16352 |
{ |
| 16353 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (targ))) |
| 16354 |
{ |
| 16355 |
c_parser_error (parser, "expression must be integral"); |
| 16356 |
targ = error_mark_node; |
| 16357 |
} |
| 16358 |
else |
| 16359 |
{ |
| 16360 |
tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT); |
| 16361 |
|
| 16362 |
OMP_CLAUSE_DECL (c) = targ; |
| 16363 |
OMP_CLAUSE_CHAIN (c) = list; |
| 16364 |
list = c; |
| 16365 |
} |
| 16366 |
} |
| 16367 |
} |
| 16368 |
|
| 16369 |
release_tree_vector (args); |
| 16370 |
parens.require_close (parser); |
| 16371 |
return list; |
| 16372 |
} |
| 16373 |
|
| 16374 |
/* OpenACC 2.0, OpenMP 2.5: |
| 16375 |
variable-list: |
| 16376 |
identifier |
| 16377 |
variable-list , identifier |
| 16378 |
|
| 16379 |
If KIND is nonzero, create the appropriate node and install the |
| 16380 |
decl in OMP_CLAUSE_DECL and add the node to the head of the list. |
| 16381 |
If KIND is nonzero, CLAUSE_LOC is the location of the clause. |
| 16382 |
|
| 16383 |
If KIND is zero (= OMP_CLAUSE_ERROR), create a TREE_LIST with the decl |
| 16384 |
in TREE_PURPOSE and the location in TREE_VALUE (accessible using |
| 16385 |
EXPR_LOCATION); return the list created. |
| 16386 |
|
| 16387 |
The optional ALLOW_DEREF argument is true if list items can use the deref |
| 16388 |
(->) operator. */ |
| 16389 |
|
| 16390 |
struct omp_dim |
| 16391 |
{ |
| 16392 |
tree low_bound, length; |
| 16393 |
location_t loc; |
| 16394 |
bool no_colon; |
| 16395 |
omp_dim (tree lb, tree len, location_t lo, bool nc) |
| 16396 |
: low_bound (lb), length (len), loc (lo), no_colon (nc) {} |
| 16397 |
}; |
| 16398 |
|
| 16399 |
static tree |
| 16400 |
c_parser_omp_variable_list (c_parser *parser, |
| 16401 |
location_t clause_loc, |
| 16402 |
enum omp_clause_code kind, tree list, |
| 16403 |
bool map_lvalue = false) |
| 16404 |
{ |
| 16405 |
auto_vec<omp_dim> dims; |
| 16406 |
bool array_section_p; |
| 16407 |
auto_vec<c_token> tokens; |
| 16408 |
unsigned int tokens_avail = 0; |
| 16409 |
c_token *saved_tokens = NULL; |
| 16410 |
|
| 16411 |
while (1) |
| 16412 |
{ |
| 16413 |
tree t = NULL_TREE; |
| 16414 |
location_t tloc = c_parser_peek_token (parser)->location; |
| 16415 |
|
| 16416 |
if (kind == OMP_CLAUSE_DEPEND || kind == OMP_CLAUSE_AFFINITY) |
| 16417 |
{ |
| 16418 |
if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 16419 |
|| c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 16420 |
{ |
| 16421 |
struct c_expr expr; |
| 16422 |
if (kind == OMP_CLAUSE_DEPEND |
| 16423 |
&& c_parser_next_token_is_keyword (parser, |
| 16424 |
RID_OMP_ALL_MEMORY) |
| 16425 |
&& (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 16426 |
|| (c_parser_peek_2nd_token (parser)->type |
| 16427 |
== CPP_CLOSE_PAREN))) |
| 16428 |
{ |
| 16429 |
expr.value = ridpointers[RID_OMP_ALL_MEMORY]; |
| 16430 |
c_parser_consume_token (parser); |
| 16431 |
} |
| 16432 |
else |
| 16433 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 16434 |
if (expr.value != error_mark_node) |
| 16435 |
{ |
| 16436 |
tree u = build_omp_clause (clause_loc, kind); |
| 16437 |
OMP_CLAUSE_DECL (u) = expr.value; |
| 16438 |
OMP_CLAUSE_CHAIN (u) = list; |
| 16439 |
list = u; |
| 16440 |
} |
| 16441 |
|
| 16442 |
if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 16443 |
break; |
| 16444 |
|
| 16445 |
c_parser_consume_token (parser); |
| 16446 |
continue; |
| 16447 |
} |
| 16448 |
|
| 16449 |
tokens.truncate (0); |
| 16450 |
unsigned int nesting_depth = 0; |
| 16451 |
while (1) |
| 16452 |
{ |
| 16453 |
c_token *token = c_parser_peek_token (parser); |
| 16454 |
switch (token->type) |
| 16455 |
{ |
| 16456 |
case CPP_EOF: |
| 16457 |
case CPP_PRAGMA_EOL: |
| 16458 |
break; |
| 16459 |
case CPP_OPEN_BRACE: |
| 16460 |
case CPP_OPEN_PAREN: |
| 16461 |
case CPP_OPEN_SQUARE: |
| 16462 |
++nesting_depth; |
| 16463 |
goto add; |
| 16464 |
case CPP_CLOSE_BRACE: |
| 16465 |
case CPP_CLOSE_PAREN: |
| 16466 |
case CPP_CLOSE_SQUARE: |
| 16467 |
if (nesting_depth-- == 0) |
| 16468 |
break; |
| 16469 |
goto add; |
| 16470 |
case CPP_COMMA: |
| 16471 |
if (nesting_depth == 0) |
| 16472 |
break; |
| 16473 |
goto add; |
| 16474 |
default: |
| 16475 |
add: |
| 16476 |
tokens.safe_push (*token); |
| 16477 |
c_parser_consume_token (parser); |
| 16478 |
continue; |
| 16479 |
} |
| 16480 |
break; |
| 16481 |
} |
| 16482 |
|
| 16483 |
/* Make sure nothing tries to read past the end of the tokens. */ |
| 16484 |
c_token eof_token; |
| 16485 |
memset (&eof_token, 0, sizeof (eof_token)); |
| 16486 |
eof_token.type = CPP_EOF; |
| 16487 |
tokens.safe_push (eof_token); |
| 16488 |
tokens.safe_push (eof_token); |
| 16489 |
|
| 16490 |
saved_tokens = parser->tokens; |
| 16491 |
tokens_avail = parser->tokens_avail; |
| 16492 |
parser->tokens = tokens.address (); |
| 16493 |
parser->tokens_avail = tokens.length (); |
| 16494 |
} |
| 16495 |
else if (map_lvalue |
| 16496 |
&& (kind == OMP_CLAUSE_MAP |
| 16497 |
|| kind == OMP_CLAUSE_TO |
| 16498 |
|| kind == OMP_CLAUSE_FROM)) |
| 16499 |
{ |
| 16500 |
location_t loc = c_parser_peek_token (parser)->location; |
| 16501 |
bool save_c_omp_array_section_p = c_omp_array_section_p; |
| 16502 |
c_omp_array_section_p = true; |
| 16503 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 16504 |
if (expr.value != error_mark_node) |
| 16505 |
mark_exp_read (expr.value); |
| 16506 |
c_omp_array_section_p = save_c_omp_array_section_p; |
| 16507 |
tree decl = expr.value; |
| 16508 |
|
| 16509 |
/* This code rewrites a parsed expression containing various tree |
| 16510 |
codes used to represent array accesses into a more uniform nest of |
| 16511 |
OMP_ARRAY_SECTION nodes before it is processed by |
| 16512 |
c-typeck.cc:handle_omp_array_sections_1. It might be more |
| 16513 |
efficient to move this logic to that function instead, analysing |
| 16514 |
the parsed expression directly rather than this preprocessed |
| 16515 |
form. (See also equivalent code in cp/parser.cc, |
| 16516 |
cp/semantics.cc). */ |
| 16517 |
dims.truncate (0); |
| 16518 |
if (TREE_CODE (decl) == OMP_ARRAY_SECTION) |
| 16519 |
{ |
| 16520 |
while (TREE_CODE (decl) == OMP_ARRAY_SECTION) |
| 16521 |
{ |
| 16522 |
tree low_bound = TREE_OPERAND (decl, 1); |
| 16523 |
tree length = TREE_OPERAND (decl, 2); |
| 16524 |
dims.safe_push (omp_dim (low_bound, length, loc, false)); |
| 16525 |
decl = TREE_OPERAND (decl, 0); |
| 16526 |
} |
| 16527 |
|
| 16528 |
while (TREE_CODE (decl) == ARRAY_REF |
| 16529 |
|| TREE_CODE (decl) == INDIRECT_REF |
| 16530 |
|| TREE_CODE (decl) == COMPOUND_EXPR) |
| 16531 |
{ |
| 16532 |
if (TREE_CODE (decl) == COMPOUND_EXPR) |
| 16533 |
{ |
| 16534 |
decl = TREE_OPERAND (decl, 1); |
| 16535 |
STRIP_NOPS (decl); |
| 16536 |
} |
| 16537 |
else if (TREE_CODE (decl) == INDIRECT_REF) |
| 16538 |
{ |
| 16539 |
dims.safe_push (omp_dim (integer_zero_node, |
| 16540 |
integer_one_node, loc, true)); |
| 16541 |
decl = TREE_OPERAND (decl, 0); |
| 16542 |
} |
| 16543 |
else /* ARRAY_REF. */ |
| 16544 |
{ |
| 16545 |
tree index = TREE_OPERAND (decl, 1); |
| 16546 |
dims.safe_push (omp_dim (index, integer_one_node, loc, |
| 16547 |
true)); |
| 16548 |
decl = TREE_OPERAND (decl, 0); |
| 16549 |
} |
| 16550 |
} |
| 16551 |
|
| 16552 |
for (int i = dims.length () - 1; i >= 0; i--) |
| 16553 |
decl = build_omp_array_section (loc, decl, dims[i].low_bound, |
| 16554 |
dims[i].length); |
| 16555 |
} |
| 16556 |
else if (TREE_CODE (decl) == INDIRECT_REF) |
| 16557 |
{ |
| 16558 |
/* Turn indirection of a pointer "*foo" into "foo[0:1]". */ |
| 16559 |
decl = TREE_OPERAND (decl, 0); |
| 16560 |
STRIP_NOPS (decl); |
| 16561 |
|
| 16562 |
decl = build_omp_array_section (loc, decl, integer_zero_node, |
| 16563 |
integer_one_node); |
| 16564 |
} |
| 16565 |
else if (TREE_CODE (decl) == ARRAY_REF) |
| 16566 |
{ |
| 16567 |
tree idx = TREE_OPERAND (decl, 1); |
| 16568 |
|
| 16569 |
decl = TREE_OPERAND (decl, 0); |
| 16570 |
STRIP_NOPS (decl); |
| 16571 |
|
| 16572 |
decl = build_omp_array_section (loc, decl, idx, integer_one_node); |
| 16573 |
} |
| 16574 |
else if (TREE_CODE (decl) == NON_LVALUE_EXPR |
| 16575 |
|| CONVERT_EXPR_P (decl)) |
| 16576 |
decl = TREE_OPERAND (decl, 0); |
| 16577 |
|
| 16578 |
tree u = build_omp_clause (clause_loc, kind); |
| 16579 |
OMP_CLAUSE_DECL (u) = decl; |
| 16580 |
OMP_CLAUSE_CHAIN (u) = list; |
| 16581 |
list = u; |
| 16582 |
|
| 16583 |
goto next_item; |
| 16584 |
} |
| 16585 |
|
| 16586 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 16587 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 16588 |
{ |
| 16589 |
t = lookup_name (c_parser_peek_token (parser)->value); |
| 16590 |
|
| 16591 |
if (t == NULL_TREE) |
| 16592 |
{ |
| 16593 |
undeclared_variable (c_parser_peek_token (parser)->location, |
| 16594 |
c_parser_peek_token (parser)->value); |
| 16595 |
t = error_mark_node; |
| 16596 |
} |
| 16597 |
|
| 16598 |
c_parser_consume_token (parser); |
| 16599 |
} |
| 16600 |
else if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 16601 |
&& (c_parser_peek_token (parser)->keyword == RID_FUNCTION_NAME |
| 16602 |
|| (c_parser_peek_token (parser)->keyword |
| 16603 |
== RID_PRETTY_FUNCTION_NAME) |
| 16604 |
|| (c_parser_peek_token (parser)->keyword |
| 16605 |
== RID_C99_FUNCTION_NAME))) |
| 16606 |
t = c_parser_predefined_identifier (parser).value; |
| 16607 |
else |
| 16608 |
{ |
| 16609 |
c_parser_error (parser, "expected identifier"); |
| 16610 |
break; |
| 16611 |
} |
| 16612 |
|
| 16613 |
if (t == error_mark_node) |
| 16614 |
; |
| 16615 |
else if (kind != 0) /* kind != OMP_CLAUSE_ERROR */ |
| 16616 |
{ |
| 16617 |
switch (kind) |
| 16618 |
{ |
| 16619 |
case OMP_CLAUSE__CACHE_: |
| 16620 |
/* The OpenACC cache directive explicitly only allows "array |
| 16621 |
elements or subarrays". */ |
| 16622 |
if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE) |
| 16623 |
{ |
| 16624 |
c_parser_error (parser, "expected %<[%>"); |
| 16625 |
t = error_mark_node; |
| 16626 |
break; |
| 16627 |
} |
| 16628 |
/* FALLTHROUGH */ |
| 16629 |
case OMP_CLAUSE_MAP: |
| 16630 |
case OMP_CLAUSE_FROM: |
| 16631 |
case OMP_CLAUSE_TO: |
| 16632 |
start_component_ref: |
| 16633 |
while (c_parser_next_token_is (parser, CPP_DOT) |
| 16634 |
|| c_parser_next_token_is (parser, CPP_DEREF)) |
| 16635 |
{ |
| 16636 |
location_t op_loc = c_parser_peek_token (parser)->location; |
| 16637 |
location_t arrow_loc = UNKNOWN_LOCATION; |
| 16638 |
if (c_parser_next_token_is (parser, CPP_DEREF)) |
| 16639 |
{ |
| 16640 |
c_expr t_expr; |
| 16641 |
t_expr.value = t; |
| 16642 |
t_expr.original_code = ERROR_MARK; |
| 16643 |
t_expr.original_type = NULL; |
| 16644 |
set_c_expr_source_range (&t_expr, op_loc, op_loc); |
| 16645 |
t_expr.m_decimal = 0; |
| 16646 |
t_expr = convert_lvalue_to_rvalue (op_loc, t_expr, |
| 16647 |
true, false); |
| 16648 |
t = build_indirect_ref (op_loc, t_expr.value, RO_ARROW); |
| 16649 |
arrow_loc = t_expr.get_location (); |
| 16650 |
} |
| 16651 |
c_parser_consume_token (parser); |
| 16652 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 16653 |
{ |
| 16654 |
c_parser_error (parser, "expected identifier"); |
| 16655 |
t = error_mark_node; |
| 16656 |
break; |
| 16657 |
} |
| 16658 |
|
| 16659 |
c_token *comp_tok = c_parser_peek_token (parser); |
| 16660 |
tree ident = comp_tok->value; |
| 16661 |
location_t comp_loc = comp_tok->location; |
| 16662 |
c_parser_consume_token (parser); |
| 16663 |
t = build_component_ref (op_loc, t, ident, comp_loc, |
| 16664 |
arrow_loc); |
| 16665 |
} |
| 16666 |
/* FALLTHROUGH */ |
| 16667 |
case OMP_CLAUSE_AFFINITY: |
| 16668 |
case OMP_CLAUSE_DEPEND: |
| 16669 |
case OMP_CLAUSE_REDUCTION: |
| 16670 |
case OMP_CLAUSE_IN_REDUCTION: |
| 16671 |
case OMP_CLAUSE_TASK_REDUCTION: |
| 16672 |
case OMP_CLAUSE_HAS_DEVICE_ADDR: |
| 16673 |
array_section_p = false; |
| 16674 |
dims.truncate (0); |
| 16675 |
while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 16676 |
{ |
| 16677 |
location_t loc = UNKNOWN_LOCATION; |
| 16678 |
tree low_bound = NULL_TREE, length = NULL_TREE; |
| 16679 |
bool no_colon = false; |
| 16680 |
|
| 16681 |
c_parser_consume_token (parser); |
| 16682 |
if (!c_parser_next_token_is (parser, CPP_COLON)) |
| 16683 |
{ |
| 16684 |
location_t expr_loc |
| 16685 |
= c_parser_peek_token (parser)->location; |
| 16686 |
c_expr expr = c_parser_expression (parser); |
| 16687 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, |
| 16688 |
false, true); |
| 16689 |
low_bound = expr.value; |
| 16690 |
loc = expr_loc; |
| 16691 |
} |
| 16692 |
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 16693 |
{ |
| 16694 |
length = integer_one_node; |
| 16695 |
no_colon = true; |
| 16696 |
} |
| 16697 |
else |
| 16698 |
{ |
| 16699 |
/* Look for `:'. */ |
| 16700 |
if (!c_parser_require (parser, CPP_COLON, |
| 16701 |
"expected %<:%>")) |
| 16702 |
{ |
| 16703 |
t = error_mark_node; |
| 16704 |
break; |
| 16705 |
} |
| 16706 |
array_section_p = true; |
| 16707 |
if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 16708 |
{ |
| 16709 |
location_t expr_loc |
| 16710 |
= c_parser_peek_token (parser)->location; |
| 16711 |
c_expr expr = c_parser_expression (parser); |
| 16712 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, |
| 16713 |
false, true); |
| 16714 |
length = expr.value; |
| 16715 |
} |
| 16716 |
} |
| 16717 |
/* Look for the closing `]'. */ |
| 16718 |
if (!c_parser_require (parser, CPP_CLOSE_SQUARE, |
| 16719 |
"expected %<]%>")) |
| 16720 |
{ |
| 16721 |
t = error_mark_node; |
| 16722 |
break; |
| 16723 |
} |
| 16724 |
|
| 16725 |
dims.safe_push (omp_dim (low_bound, length, loc, no_colon)); |
| 16726 |
} |
| 16727 |
|
| 16728 |
if (t != error_mark_node) |
| 16729 |
{ |
| 16730 |
if ((kind == OMP_CLAUSE_MAP |
| 16731 |
|| kind == OMP_CLAUSE_FROM |
| 16732 |
|| kind == OMP_CLAUSE_TO) |
| 16733 |
&& !array_section_p |
| 16734 |
&& (c_parser_next_token_is (parser, CPP_DOT) |
| 16735 |
|| c_parser_next_token_is (parser, CPP_DEREF))) |
| 16736 |
{ |
| 16737 |
for (unsigned i = 0; i < dims.length (); i++) |
| 16738 |
{ |
| 16739 |
gcc_assert (dims[i].length == integer_one_node); |
| 16740 |
t = build_array_ref (dims[i].loc, |
| 16741 |
t, dims[i].low_bound); |
| 16742 |
} |
| 16743 |
goto start_component_ref; |
| 16744 |
} |
| 16745 |
else |
| 16746 |
for (unsigned i = 0; i < dims.length (); i++) |
| 16747 |
t = build_omp_array_section (clause_loc, t, |
| 16748 |
dims[i].low_bound, |
| 16749 |
dims[i].length); |
| 16750 |
} |
| 16751 |
|
| 16752 |
if ((kind == OMP_CLAUSE_DEPEND || kind == OMP_CLAUSE_AFFINITY) |
| 16753 |
&& t != error_mark_node |
| 16754 |
&& parser->tokens_avail != 2) |
| 16755 |
{ |
| 16756 |
if (array_section_p) |
| 16757 |
{ |
| 16758 |
error_at (c_parser_peek_token (parser)->location, |
| 16759 |
"expected %<)%> or %<,%>"); |
| 16760 |
t = error_mark_node; |
| 16761 |
} |
| 16762 |
else |
| 16763 |
{ |
| 16764 |
parser->tokens = tokens.address (); |
| 16765 |
parser->tokens_avail = tokens.length (); |
| 16766 |
|
| 16767 |
t = c_parser_expr_no_commas (parser, NULL).value; |
| 16768 |
if (t != error_mark_node && parser->tokens_avail != 2) |
| 16769 |
{ |
| 16770 |
error_at (c_parser_peek_token (parser)->location, |
| 16771 |
"expected %<)%> or %<,%>"); |
| 16772 |
t = error_mark_node; |
| 16773 |
} |
| 16774 |
} |
| 16775 |
} |
| 16776 |
break; |
| 16777 |
default: |
| 16778 |
break; |
| 16779 |
} |
| 16780 |
|
| 16781 |
if (t != error_mark_node) |
| 16782 |
{ |
| 16783 |
tree u = build_omp_clause (clause_loc, kind); |
| 16784 |
OMP_CLAUSE_DECL (u) = t; |
| 16785 |
OMP_CLAUSE_CHAIN (u) = list; |
| 16786 |
list = u; |
| 16787 |
} |
| 16788 |
} |
| 16789 |
else /* kind == OMP_CLAUSE_ERROR */ |
| 16790 |
list = tree_cons (t, build_empty_stmt (tloc), list); |
| 16791 |
|
| 16792 |
if (kind == OMP_CLAUSE_DEPEND || kind == OMP_CLAUSE_AFFINITY) |
| 16793 |
{ |
| 16794 |
parser->tokens = saved_tokens; |
| 16795 |
parser->tokens_avail = tokens_avail; |
| 16796 |
} |
| 16797 |
|
| 16798 |
next_item: |
| 16799 |
if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 16800 |
break; |
| 16801 |
|
| 16802 |
c_parser_consume_token (parser); |
| 16803 |
} |
| 16804 |
|
| 16805 |
return list; |
| 16806 |
} |
| 16807 |
|
| 16808 |
/* Similarly, but expect leading and trailing parenthesis. This is a very |
| 16809 |
common case for OpenACC and OpenMP clauses. The optional ALLOW_DEREF |
| 16810 |
argument is true if list items can use the deref (->) operator. */ |
| 16811 |
|
| 16812 |
static tree |
| 16813 |
c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, |
| 16814 |
tree list, bool map_lvalue = false) |
| 16815 |
{ |
| 16816 |
/* The clauses location. */ |
| 16817 |
location_t loc = c_parser_peek_token (parser)->location; |
| 16818 |
|
| 16819 |
if (parser->in_omp_decl_attribute) |
| 16820 |
{ |
| 16821 |
if (kind) |
| 16822 |
{ |
| 16823 |
tree u = build_omp_clause (loc, kind); |
| 16824 |
OMP_CLAUSE_DECL (u) = parser->in_omp_decl_attribute; |
| 16825 |
OMP_CLAUSE_CHAIN (u) = list; |
| 16826 |
return u; |
| 16827 |
} |
| 16828 |
else |
| 16829 |
return tree_cons (parser->in_omp_decl_attribute, NULL_TREE, list); |
| 16830 |
} |
| 16831 |
|
| 16832 |
matching_parens parens; |
| 16833 |
if (parens.require_open (parser)) |
| 16834 |
{ |
| 16835 |
list = c_parser_omp_variable_list (parser, loc, kind, list, map_lvalue); |
| 16836 |
parens.skip_until_found_close (parser); |
| 16837 |
} |
| 16838 |
return list; |
| 16839 |
} |
| 16840 |
|
| 16841 |
/* OpenACC 2.0: |
| 16842 |
copy ( variable-list ) |
| 16843 |
copyin ( variable-list ) |
| 16844 |
copyout ( variable-list ) |
| 16845 |
create ( variable-list ) |
| 16846 |
delete ( variable-list ) |
| 16847 |
present ( variable-list ) |
| 16848 |
|
| 16849 |
OpenACC 2.6: |
| 16850 |
no_create ( variable-list ) |
| 16851 |
attach ( variable-list ) |
| 16852 |
detach ( variable-list ) |
| 16853 |
|
| 16854 |
OpenACC 2.7: |
| 16855 |
copyin (readonly : variable-list ) |
| 16856 |
*/ |
| 16857 |
|
| 16858 |
static tree |
| 16859 |
c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind, |
| 16860 |
tree list) |
| 16861 |
{ |
| 16862 |
enum gomp_map_kind kind; |
| 16863 |
switch (c_kind) |
| 16864 |
{ |
| 16865 |
case PRAGMA_OACC_CLAUSE_ATTACH: |
| 16866 |
kind = GOMP_MAP_ATTACH; |
| 16867 |
break; |
| 16868 |
case PRAGMA_OACC_CLAUSE_COPY: |
| 16869 |
kind = GOMP_MAP_TOFROM; |
| 16870 |
break; |
| 16871 |
case PRAGMA_OACC_CLAUSE_COPYIN: |
| 16872 |
kind = GOMP_MAP_TO; |
| 16873 |
break; |
| 16874 |
case PRAGMA_OACC_CLAUSE_COPYOUT: |
| 16875 |
kind = GOMP_MAP_FROM; |
| 16876 |
break; |
| 16877 |
case PRAGMA_OACC_CLAUSE_CREATE: |
| 16878 |
kind = GOMP_MAP_ALLOC; |
| 16879 |
break; |
| 16880 |
case PRAGMA_OACC_CLAUSE_DELETE: |
| 16881 |
kind = GOMP_MAP_RELEASE; |
| 16882 |
break; |
| 16883 |
case PRAGMA_OACC_CLAUSE_DETACH: |
| 16884 |
kind = GOMP_MAP_DETACH; |
| 16885 |
break; |
| 16886 |
case PRAGMA_OACC_CLAUSE_DEVICE: |
| 16887 |
kind = GOMP_MAP_FORCE_TO; |
| 16888 |
break; |
| 16889 |
case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT: |
| 16890 |
kind = GOMP_MAP_DEVICE_RESIDENT; |
| 16891 |
break; |
| 16892 |
case PRAGMA_OACC_CLAUSE_LINK: |
| 16893 |
kind = GOMP_MAP_LINK; |
| 16894 |
break; |
| 16895 |
case PRAGMA_OACC_CLAUSE_NO_CREATE: |
| 16896 |
kind = GOMP_MAP_IF_PRESENT; |
| 16897 |
break; |
| 16898 |
case PRAGMA_OACC_CLAUSE_PRESENT: |
| 16899 |
kind = GOMP_MAP_FORCE_PRESENT; |
| 16900 |
break; |
| 16901 |
case PRAGMA_OACC_CLAUSE_SELF: |
| 16902 |
/* "The 'host' clause is a synonym for the 'self' clause." */ |
| 16903 |
case PRAGMA_OACC_CLAUSE_HOST: |
| 16904 |
kind = GOMP_MAP_FORCE_FROM; |
| 16905 |
break; |
| 16906 |
default: |
| 16907 |
gcc_unreachable (); |
| 16908 |
} |
| 16909 |
|
| 16910 |
tree nl = list; |
| 16911 |
bool readonly = false; |
| 16912 |
location_t open_loc = c_parser_peek_token (parser)->location; |
| 16913 |
matching_parens parens; |
| 16914 |
if (parens.require_open (parser)) |
| 16915 |
{ |
| 16916 |
/* Turn on readonly modifier parsing for copyin clause. */ |
| 16917 |
if (c_kind == PRAGMA_OACC_CLAUSE_COPYIN) |
| 16918 |
{ |
| 16919 |
c_token *token = c_parser_peek_token (parser); |
| 16920 |
if (token->type == CPP_NAME |
| 16921 |
&& !strcmp (IDENTIFIER_POINTER (token->value), "readonly") |
| 16922 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 16923 |
{ |
| 16924 |
c_parser_consume_token (parser); |
| 16925 |
c_parser_consume_token (parser); |
| 16926 |
readonly = true; |
| 16927 |
} |
| 16928 |
} |
| 16929 |
nl = c_parser_omp_variable_list (parser, open_loc, OMP_CLAUSE_MAP, list, |
| 16930 |
false); |
| 16931 |
parens.skip_until_found_close (parser); |
| 16932 |
} |
| 16933 |
|
| 16934 |
for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 16935 |
{ |
| 16936 |
OMP_CLAUSE_SET_MAP_KIND (c, kind); |
| 16937 |
if (readonly) |
| 16938 |
OMP_CLAUSE_MAP_READONLY (c) = 1; |
| 16939 |
} |
| 16940 |
|
| 16941 |
return nl; |
| 16942 |
} |
| 16943 |
|
| 16944 |
/* OpenACC 2.0: |
| 16945 |
deviceptr ( variable-list ) */ |
| 16946 |
|
| 16947 |
static tree |
| 16948 |
c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list) |
| 16949 |
{ |
| 16950 |
tree vars, t; |
| 16951 |
|
| 16952 |
/* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic |
| 16953 |
c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR, |
| 16954 |
variable-list must only allow for pointer variables. */ |
| 16955 |
vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
| 16956 |
for (t = vars; t && t; t = TREE_CHAIN (t)) |
| 16957 |
{ |
| 16958 |
tree v = TREE_PURPOSE (t); |
| 16959 |
location_t loc = EXPR_LOCATION (TREE_VALUE (t)); |
| 16960 |
|
| 16961 |
if (!VAR_P (v) && TREE_CODE (v) != PARM_DECL) |
| 16962 |
error_at (loc, "%qD is not a variable", v); |
| 16963 |
else if (TREE_TYPE (v) == error_mark_node) |
| 16964 |
; |
| 16965 |
else if (!POINTER_TYPE_P (TREE_TYPE (v))) |
| 16966 |
error_at (loc, "%qD is not a pointer variable", v); |
| 16967 |
|
| 16968 |
tree u = build_omp_clause (loc, OMP_CLAUSE_MAP); |
| 16969 |
OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR); |
| 16970 |
OMP_CLAUSE_DECL (u) = v; |
| 16971 |
OMP_CLAUSE_CHAIN (u) = list; |
| 16972 |
list = u; |
| 16973 |
} |
| 16974 |
|
| 16975 |
return list; |
| 16976 |
} |
| 16977 |
|
| 16978 |
/* OpenACC 2.0, OpenMP 3.0: |
| 16979 |
collapse ( constant-expression ) */ |
| 16980 |
|
| 16981 |
static tree |
| 16982 |
c_parser_omp_clause_collapse (c_parser *parser, tree list) |
| 16983 |
{ |
| 16984 |
tree c, num = error_mark_node; |
| 16985 |
HOST_WIDE_INT n; |
| 16986 |
location_t loc; |
| 16987 |
|
| 16988 |
check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse"); |
| 16989 |
check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile"); |
| 16990 |
|
| 16991 |
loc = c_parser_peek_token (parser)->location; |
| 16992 |
matching_parens parens; |
| 16993 |
if (parens.require_open (parser)) |
| 16994 |
{ |
| 16995 |
num = c_parser_expr_no_commas (parser, NULL).value; |
| 16996 |
parens.skip_until_found_close (parser); |
| 16997 |
} |
| 16998 |
if (num == error_mark_node) |
| 16999 |
return list; |
| 17000 |
mark_exp_read (num); |
| 17001 |
num = c_fully_fold (num, false, NULL); |
| 17002 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
| 17003 |
|| !tree_fits_shwi_p (num) |
| 17004 |
|| (n = tree_to_shwi (num)) <= 0 |
| 17005 |
|| (int) n != n) |
| 17006 |
{ |
| 17007 |
error_at (loc, |
| 17008 |
"collapse argument needs positive constant integer expression"); |
| 17009 |
return list; |
| 17010 |
} |
| 17011 |
c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); |
| 17012 |
OMP_CLAUSE_COLLAPSE_EXPR (c) = num; |
| 17013 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17014 |
return c; |
| 17015 |
} |
| 17016 |
|
| 17017 |
/* OpenMP 2.5: |
| 17018 |
copyin ( variable-list ) */ |
| 17019 |
|
| 17020 |
static tree |
| 17021 |
c_parser_omp_clause_copyin (c_parser *parser, tree list) |
| 17022 |
{ |
| 17023 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list); |
| 17024 |
} |
| 17025 |
|
| 17026 |
/* OpenMP 2.5: |
| 17027 |
copyprivate ( variable-list ) */ |
| 17028 |
|
| 17029 |
static tree |
| 17030 |
c_parser_omp_clause_copyprivate (c_parser *parser, tree list) |
| 17031 |
{ |
| 17032 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list); |
| 17033 |
} |
| 17034 |
|
| 17035 |
/* OpenMP 2.5: |
| 17036 |
default ( none | shared ) |
| 17037 |
|
| 17038 |
OpenMP 5.1: |
| 17039 |
default ( private | firstprivate ) |
| 17040 |
|
| 17041 |
OpenACC: |
| 17042 |
default ( none | present ) */ |
| 17043 |
|
| 17044 |
static tree |
| 17045 |
c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc) |
| 17046 |
{ |
| 17047 |
enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; |
| 17048 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17049 |
tree c; |
| 17050 |
|
| 17051 |
matching_parens parens; |
| 17052 |
if (!parens.require_open (parser)) |
| 17053 |
return list; |
| 17054 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 17055 |
{ |
| 17056 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 17057 |
|
| 17058 |
switch (p[0]) |
| 17059 |
{ |
| 17060 |
case 'n': |
| 17061 |
if (strcmp ("none", p) != 0) |
| 17062 |
goto invalid_kind; |
| 17063 |
kind = OMP_CLAUSE_DEFAULT_NONE; |
| 17064 |
break; |
| 17065 |
|
| 17066 |
case 'p': |
| 17067 |
if (is_oacc) |
| 17068 |
{ |
| 17069 |
if (strcmp ("present", p) != 0) |
| 17070 |
goto invalid_kind; |
| 17071 |
kind = OMP_CLAUSE_DEFAULT_PRESENT; |
| 17072 |
} |
| 17073 |
else |
| 17074 |
{ |
| 17075 |
if (strcmp ("private", p) != 0) |
| 17076 |
goto invalid_kind; |
| 17077 |
kind = OMP_CLAUSE_DEFAULT_PRIVATE; |
| 17078 |
} |
| 17079 |
break; |
| 17080 |
|
| 17081 |
case 'f': |
| 17082 |
if (strcmp ("firstprivate", p) != 0 || is_oacc) |
| 17083 |
goto invalid_kind; |
| 17084 |
kind = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE; |
| 17085 |
break; |
| 17086 |
|
| 17087 |
case 's': |
| 17088 |
if (strcmp ("shared", p) != 0 || is_oacc) |
| 17089 |
goto invalid_kind; |
| 17090 |
kind = OMP_CLAUSE_DEFAULT_SHARED; |
| 17091 |
break; |
| 17092 |
|
| 17093 |
default: |
| 17094 |
goto invalid_kind; |
| 17095 |
} |
| 17096 |
|
| 17097 |
c_parser_consume_token (parser); |
| 17098 |
} |
| 17099 |
else |
| 17100 |
{ |
| 17101 |
invalid_kind: |
| 17102 |
if (is_oacc) |
| 17103 |
c_parser_error (parser, "expected %<none%> or %<present%>"); |
| 17104 |
else |
| 17105 |
c_parser_error (parser, "expected %<none%>, %<shared%>, " |
| 17106 |
"%<private%> or %<firstprivate%>"); |
| 17107 |
} |
| 17108 |
parens.skip_until_found_close (parser); |
| 17109 |
|
| 17110 |
if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED) |
| 17111 |
return list; |
| 17112 |
|
| 17113 |
check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default"); |
| 17114 |
c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT); |
| 17115 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17116 |
OMP_CLAUSE_DEFAULT_KIND (c) = kind; |
| 17117 |
|
| 17118 |
return c; |
| 17119 |
} |
| 17120 |
|
| 17121 |
/* OpenMP 2.5: |
| 17122 |
firstprivate ( variable-list ) */ |
| 17123 |
|
| 17124 |
static tree |
| 17125 |
c_parser_omp_clause_firstprivate (c_parser *parser, tree list) |
| 17126 |
{ |
| 17127 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list); |
| 17128 |
} |
| 17129 |
|
| 17130 |
/* OpenMP 3.1: |
| 17131 |
final ( expression ) */ |
| 17132 |
|
| 17133 |
static tree |
| 17134 |
c_parser_omp_clause_final (c_parser *parser, tree list) |
| 17135 |
{ |
| 17136 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17137 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 17138 |
{ |
| 17139 |
matching_parens parens; |
| 17140 |
tree t, c; |
| 17141 |
if (!parens.require_open (parser)) |
| 17142 |
t = error_mark_node; |
| 17143 |
else |
| 17144 |
{ |
| 17145 |
location_t eloc = c_parser_peek_token (parser)->location; |
| 17146 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17147 |
t = convert_lvalue_to_rvalue (eloc, expr, true, true).value; |
| 17148 |
t = c_objc_common_truthvalue_conversion (eloc, t); |
| 17149 |
t = c_fully_fold (t, false, NULL); |
| 17150 |
parens.skip_until_found_close (parser); |
| 17151 |
} |
| 17152 |
|
| 17153 |
check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final"); |
| 17154 |
|
| 17155 |
c = build_omp_clause (loc, OMP_CLAUSE_FINAL); |
| 17156 |
OMP_CLAUSE_FINAL_EXPR (c) = t; |
| 17157 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17158 |
list = c; |
| 17159 |
} |
| 17160 |
else |
| 17161 |
c_parser_error (parser, "expected %<(%>"); |
| 17162 |
|
| 17163 |
return list; |
| 17164 |
} |
| 17165 |
|
| 17166 |
/* OpenMP 5.1: |
| 17167 |
indirect [( expression )] |
| 17168 |
*/ |
| 17169 |
|
| 17170 |
static tree |
| 17171 |
c_parser_omp_clause_indirect (c_parser *parser, tree list) |
| 17172 |
{ |
| 17173 |
location_t location = c_parser_peek_token (parser)->location; |
| 17174 |
tree t; |
| 17175 |
|
| 17176 |
if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 17177 |
{ |
| 17178 |
matching_parens parens; |
| 17179 |
if (!parens.require_open (parser)) |
| 17180 |
return list; |
| 17181 |
|
| 17182 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17183 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17184 |
expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
| 17185 |
t = c_objc_common_truthvalue_conversion (loc, expr.value); |
| 17186 |
t = c_fully_fold (t, false, NULL); |
| 17187 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) |
| 17188 |
|| TREE_CODE (t) != INTEGER_CST) |
| 17189 |
{ |
| 17190 |
c_parser_error (parser, "expected constant logical expression"); |
| 17191 |
return list; |
| 17192 |
} |
| 17193 |
parens.skip_until_found_close (parser); |
| 17194 |
} |
| 17195 |
else |
| 17196 |
t = integer_one_node; |
| 17197 |
|
| 17198 |
check_no_duplicate_clause (list, OMP_CLAUSE_INDIRECT, "indirect"); |
| 17199 |
|
| 17200 |
tree c = build_omp_clause (location, OMP_CLAUSE_INDIRECT); |
| 17201 |
OMP_CLAUSE_INDIRECT_EXPR (c) = t; |
| 17202 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17203 |
|
| 17204 |
return c; |
| 17205 |
} |
| 17206 |
|
| 17207 |
/* OpenACC, OpenMP 2.5: |
| 17208 |
if ( expression ) |
| 17209 |
|
| 17210 |
OpenMP 4.5: |
| 17211 |
if ( directive-name-modifier : expression ) |
| 17212 |
|
| 17213 |
directive-name-modifier: |
| 17214 |
parallel | task | taskloop | target data | target | target update |
| 17215 |
| target enter data | target exit data |
| 17216 |
|
| 17217 |
OpenMP 5.0: |
| 17218 |
directive-name-modifier: |
| 17219 |
... | simd | cancel */ |
| 17220 |
|
| 17221 |
static tree |
| 17222 |
c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) |
| 17223 |
{ |
| 17224 |
location_t location = c_parser_peek_token (parser)->location; |
| 17225 |
enum tree_code if_modifier = ERROR_MARK; |
| 17226 |
|
| 17227 |
matching_parens parens; |
| 17228 |
if (!parens.require_open (parser)) |
| 17229 |
return list; |
| 17230 |
|
| 17231 |
if (is_omp && c_parser_next_token_is (parser, CPP_NAME)) |
| 17232 |
{ |
| 17233 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 17234 |
int n = 2; |
| 17235 |
if (strcmp (p, "cancel") == 0) |
| 17236 |
if_modifier = VOID_CST; |
| 17237 |
else if (strcmp (p, "parallel") == 0) |
| 17238 |
if_modifier = OMP_PARALLEL; |
| 17239 |
else if (strcmp (p, "simd") == 0) |
| 17240 |
if_modifier = OMP_SIMD; |
| 17241 |
else if (strcmp (p, "task") == 0) |
| 17242 |
if_modifier = OMP_TASK; |
| 17243 |
else if (strcmp (p, "taskloop") == 0) |
| 17244 |
if_modifier = OMP_TASKLOOP; |
| 17245 |
else if (strcmp (p, "target") == 0) |
| 17246 |
{ |
| 17247 |
if_modifier = OMP_TARGET; |
| 17248 |
if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 17249 |
{ |
| 17250 |
p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value); |
| 17251 |
if (strcmp ("data", p) == 0) |
| 17252 |
if_modifier = OMP_TARGET_DATA; |
| 17253 |
else if (strcmp ("update", p) == 0) |
| 17254 |
if_modifier = OMP_TARGET_UPDATE; |
| 17255 |
else if (strcmp ("enter", p) == 0) |
| 17256 |
if_modifier = OMP_TARGET_ENTER_DATA; |
| 17257 |
else if (strcmp ("exit", p) == 0) |
| 17258 |
if_modifier = OMP_TARGET_EXIT_DATA; |
| 17259 |
if (if_modifier != OMP_TARGET) |
| 17260 |
{ |
| 17261 |
n = 3; |
| 17262 |
c_parser_consume_token (parser); |
| 17263 |
} |
| 17264 |
else |
| 17265 |
{ |
| 17266 |
location_t loc = c_parser_peek_2nd_token (parser)->location; |
| 17267 |
error_at (loc, "expected %<data%>, %<update%>, %<enter%> " |
| 17268 |
"or %<exit%>"); |
| 17269 |
if_modifier = ERROR_MARK; |
| 17270 |
} |
| 17271 |
if (if_modifier == OMP_TARGET_ENTER_DATA |
| 17272 |
|| if_modifier == OMP_TARGET_EXIT_DATA) |
| 17273 |
{ |
| 17274 |
if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 17275 |
{ |
| 17276 |
p = IDENTIFIER_POINTER |
| 17277 |
(c_parser_peek_2nd_token (parser)->value); |
| 17278 |
if (strcmp ("data", p) == 0) |
| 17279 |
n = 4; |
| 17280 |
} |
| 17281 |
if (n == 4) |
| 17282 |
c_parser_consume_token (parser); |
| 17283 |
else |
| 17284 |
{ |
| 17285 |
location_t loc |
| 17286 |
= c_parser_peek_2nd_token (parser)->location; |
| 17287 |
error_at (loc, "expected %<data%>"); |
| 17288 |
if_modifier = ERROR_MARK; |
| 17289 |
} |
| 17290 |
} |
| 17291 |
} |
| 17292 |
} |
| 17293 |
if (if_modifier != ERROR_MARK) |
| 17294 |
{ |
| 17295 |
if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 17296 |
{ |
| 17297 |
c_parser_consume_token (parser); |
| 17298 |
c_parser_consume_token (parser); |
| 17299 |
} |
| 17300 |
else |
| 17301 |
{ |
| 17302 |
if (n > 2) |
| 17303 |
{ |
| 17304 |
location_t loc = c_parser_peek_2nd_token (parser)->location; |
| 17305 |
error_at (loc, "expected %<:%>"); |
| 17306 |
} |
| 17307 |
if_modifier = ERROR_MARK; |
| 17308 |
} |
| 17309 |
} |
| 17310 |
} |
| 17311 |
|
| 17312 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17313 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17314 |
expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
| 17315 |
tree t = c_objc_common_truthvalue_conversion (loc, expr.value), c; |
| 17316 |
t = c_fully_fold (t, false, NULL); |
| 17317 |
parens.skip_until_found_close (parser); |
| 17318 |
|
| 17319 |
for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) |
| 17320 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF) |
| 17321 |
{ |
| 17322 |
if (if_modifier != ERROR_MARK |
| 17323 |
&& OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) |
| 17324 |
{ |
| 17325 |
const char *p = NULL; |
| 17326 |
switch (if_modifier) |
| 17327 |
{ |
| 17328 |
case VOID_CST: p = "cancel"; break; |
| 17329 |
case OMP_PARALLEL: p = "parallel"; break; |
| 17330 |
case OMP_SIMD: p = "simd"; break; |
| 17331 |
case OMP_TASK: p = "task"; break; |
| 17332 |
case OMP_TASKLOOP: p = "taskloop"; break; |
| 17333 |
case OMP_TARGET_DATA: p = "target data"; break; |
| 17334 |
case OMP_TARGET: p = "target"; break; |
| 17335 |
case OMP_TARGET_UPDATE: p = "target update"; break; |
| 17336 |
case OMP_TARGET_ENTER_DATA: p = "target enter data"; break; |
| 17337 |
case OMP_TARGET_EXIT_DATA: p = "target exit data"; break; |
| 17338 |
default: gcc_unreachable (); |
| 17339 |
} |
| 17340 |
error_at (location, "too many %<if%> clauses with %qs modifier", |
| 17341 |
p); |
| 17342 |
return list; |
| 17343 |
} |
| 17344 |
else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) |
| 17345 |
{ |
| 17346 |
if (!is_omp) |
| 17347 |
error_at (location, "too many %<if%> clauses"); |
| 17348 |
else |
| 17349 |
error_at (location, "too many %<if%> clauses without modifier"); |
| 17350 |
return list; |
| 17351 |
} |
| 17352 |
else if (if_modifier == ERROR_MARK |
| 17353 |
|| OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK) |
| 17354 |
{ |
| 17355 |
error_at (location, "if any %<if%> clause has modifier, then all " |
| 17356 |
"%<if%> clauses have to use modifier"); |
| 17357 |
return list; |
| 17358 |
} |
| 17359 |
} |
| 17360 |
|
| 17361 |
c = build_omp_clause (location, OMP_CLAUSE_IF); |
| 17362 |
OMP_CLAUSE_IF_MODIFIER (c) = if_modifier; |
| 17363 |
OMP_CLAUSE_IF_EXPR (c) = t; |
| 17364 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17365 |
return c; |
| 17366 |
} |
| 17367 |
|
| 17368 |
/* OpenMP 2.5: |
| 17369 |
lastprivate ( variable-list ) |
| 17370 |
|
| 17371 |
OpenMP 5.0: |
| 17372 |
lastprivate ( [ lastprivate-modifier : ] variable-list ) */ |
| 17373 |
|
| 17374 |
static tree |
| 17375 |
c_parser_omp_clause_lastprivate (c_parser *parser, tree list) |
| 17376 |
{ |
| 17377 |
/* The clauses location. */ |
| 17378 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17379 |
|
| 17380 |
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 17381 |
{ |
| 17382 |
bool conditional = false; |
| 17383 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 17384 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 17385 |
{ |
| 17386 |
const char *p |
| 17387 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 17388 |
if (strcmp (p, "conditional") == 0) |
| 17389 |
{ |
| 17390 |
conditional = true; |
| 17391 |
c_parser_consume_token (parser); |
| 17392 |
c_parser_consume_token (parser); |
| 17393 |
} |
| 17394 |
} |
| 17395 |
tree nlist = c_parser_omp_variable_list (parser, loc, |
| 17396 |
OMP_CLAUSE_LASTPRIVATE, list); |
| 17397 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
| 17398 |
if (conditional) |
| 17399 |
for (tree c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 17400 |
OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 1; |
| 17401 |
return nlist; |
| 17402 |
} |
| 17403 |
return list; |
| 17404 |
} |
| 17405 |
|
| 17406 |
/* OpenMP 3.1: |
| 17407 |
mergeable */ |
| 17408 |
|
| 17409 |
static tree |
| 17410 |
c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 17411 |
{ |
| 17412 |
tree c; |
| 17413 |
|
| 17414 |
/* FIXME: Should we allow duplicates? */ |
| 17415 |
check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable"); |
| 17416 |
|
| 17417 |
c = build_omp_clause (c_parser_peek_token (parser)->location, |
| 17418 |
OMP_CLAUSE_MERGEABLE); |
| 17419 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17420 |
|
| 17421 |
return c; |
| 17422 |
} |
| 17423 |
|
| 17424 |
/* OpenMP 2.5: |
| 17425 |
nowait */ |
| 17426 |
|
| 17427 |
static tree |
| 17428 |
c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 17429 |
{ |
| 17430 |
tree c; |
| 17431 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17432 |
|
| 17433 |
check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait"); |
| 17434 |
|
| 17435 |
c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); |
| 17436 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17437 |
return c; |
| 17438 |
} |
| 17439 |
|
| 17440 |
/* OpenMP 2.5: |
| 17441 |
num_threads ( expression ) */ |
| 17442 |
|
| 17443 |
static tree |
| 17444 |
c_parser_omp_clause_num_threads (c_parser *parser, tree list) |
| 17445 |
{ |
| 17446 |
location_t num_threads_loc = c_parser_peek_token (parser)->location; |
| 17447 |
matching_parens parens; |
| 17448 |
if (parens.require_open (parser)) |
| 17449 |
{ |
| 17450 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 17451 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17452 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 17453 |
tree c, t = expr.value; |
| 17454 |
t = c_fully_fold (t, false, NULL); |
| 17455 |
|
| 17456 |
parens.skip_until_found_close (parser); |
| 17457 |
|
| 17458 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 17459 |
{ |
| 17460 |
c_parser_error (parser, "expected integer expression"); |
| 17461 |
return list; |
| 17462 |
} |
| 17463 |
|
| 17464 |
/* Attempt to statically determine when the number isn't positive. */ |
| 17465 |
c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 17466 |
build_int_cst (TREE_TYPE (t), 0)); |
| 17467 |
protected_set_expr_location (c, expr_loc); |
| 17468 |
if (c == boolean_true_node) |
| 17469 |
{ |
| 17470 |
warning_at (expr_loc, OPT_Wopenmp, |
| 17471 |
"%<num_threads%> value must be positive"); |
| 17472 |
t = integer_one_node; |
| 17473 |
} |
| 17474 |
|
| 17475 |
check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); |
| 17476 |
|
| 17477 |
c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); |
| 17478 |
OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; |
| 17479 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17480 |
list = c; |
| 17481 |
} |
| 17482 |
|
| 17483 |
return list; |
| 17484 |
} |
| 17485 |
|
| 17486 |
/* OpenMP 4.5: |
| 17487 |
num_tasks ( expression ) |
| 17488 |
|
| 17489 |
OpenMP 5.1: |
| 17490 |
num_tasks ( strict : expression ) */ |
| 17491 |
|
| 17492 |
static tree |
| 17493 |
c_parser_omp_clause_num_tasks (c_parser *parser, tree list) |
| 17494 |
{ |
| 17495 |
location_t num_tasks_loc = c_parser_peek_token (parser)->location; |
| 17496 |
matching_parens parens; |
| 17497 |
if (parens.require_open (parser)) |
| 17498 |
{ |
| 17499 |
bool strict = false; |
| 17500 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 17501 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON |
| 17502 |
&& strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 17503 |
"strict") == 0) |
| 17504 |
{ |
| 17505 |
strict = true; |
| 17506 |
c_parser_consume_token (parser); |
| 17507 |
c_parser_consume_token (parser); |
| 17508 |
} |
| 17509 |
|
| 17510 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 17511 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17512 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 17513 |
tree c, t = expr.value; |
| 17514 |
t = c_fully_fold (t, false, NULL); |
| 17515 |
|
| 17516 |
parens.skip_until_found_close (parser); |
| 17517 |
|
| 17518 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 17519 |
{ |
| 17520 |
c_parser_error (parser, "expected integer expression"); |
| 17521 |
return list; |
| 17522 |
} |
| 17523 |
|
| 17524 |
/* Attempt to statically determine when the number isn't positive. */ |
| 17525 |
c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 17526 |
build_int_cst (TREE_TYPE (t), 0)); |
| 17527 |
if (CAN_HAVE_LOCATION_P (c)) |
| 17528 |
SET_EXPR_LOCATION (c, expr_loc); |
| 17529 |
if (c == boolean_true_node) |
| 17530 |
{ |
| 17531 |
warning_at (expr_loc, OPT_Wopenmp, |
| 17532 |
"%<num_tasks%> value must be positive"); |
| 17533 |
t = integer_one_node; |
| 17534 |
} |
| 17535 |
|
| 17536 |
check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks"); |
| 17537 |
|
| 17538 |
c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS); |
| 17539 |
OMP_CLAUSE_NUM_TASKS_EXPR (c) = t; |
| 17540 |
OMP_CLAUSE_NUM_TASKS_STRICT (c) = strict; |
| 17541 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17542 |
list = c; |
| 17543 |
} |
| 17544 |
|
| 17545 |
return list; |
| 17546 |
} |
| 17547 |
|
| 17548 |
/* OpenMP 4.5: |
| 17549 |
grainsize ( expression ) |
| 17550 |
|
| 17551 |
OpenMP 5.1: |
| 17552 |
grainsize ( strict : expression ) */ |
| 17553 |
|
| 17554 |
static tree |
| 17555 |
c_parser_omp_clause_grainsize (c_parser *parser, tree list) |
| 17556 |
{ |
| 17557 |
location_t grainsize_loc = c_parser_peek_token (parser)->location; |
| 17558 |
matching_parens parens; |
| 17559 |
if (parens.require_open (parser)) |
| 17560 |
{ |
| 17561 |
bool strict = false; |
| 17562 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 17563 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON |
| 17564 |
&& strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 17565 |
"strict") == 0) |
| 17566 |
{ |
| 17567 |
strict = true; |
| 17568 |
c_parser_consume_token (parser); |
| 17569 |
c_parser_consume_token (parser); |
| 17570 |
} |
| 17571 |
|
| 17572 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 17573 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17574 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 17575 |
tree c, t = expr.value; |
| 17576 |
t = c_fully_fold (t, false, NULL); |
| 17577 |
|
| 17578 |
parens.skip_until_found_close (parser); |
| 17579 |
|
| 17580 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 17581 |
{ |
| 17582 |
c_parser_error (parser, "expected integer expression"); |
| 17583 |
return list; |
| 17584 |
} |
| 17585 |
|
| 17586 |
/* Attempt to statically determine when the number isn't positive. */ |
| 17587 |
c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 17588 |
build_int_cst (TREE_TYPE (t), 0)); |
| 17589 |
if (CAN_HAVE_LOCATION_P (c)) |
| 17590 |
SET_EXPR_LOCATION (c, expr_loc); |
| 17591 |
if (c == boolean_true_node) |
| 17592 |
{ |
| 17593 |
warning_at (expr_loc, OPT_Wopenmp, |
| 17594 |
"%<grainsize%> value must be positive"); |
| 17595 |
t = integer_one_node; |
| 17596 |
} |
| 17597 |
|
| 17598 |
check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize"); |
| 17599 |
|
| 17600 |
c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE); |
| 17601 |
OMP_CLAUSE_GRAINSIZE_EXPR (c) = t; |
| 17602 |
OMP_CLAUSE_GRAINSIZE_STRICT (c) = strict; |
| 17603 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17604 |
list = c; |
| 17605 |
} |
| 17606 |
|
| 17607 |
return list; |
| 17608 |
} |
| 17609 |
|
| 17610 |
/* OpenMP 4.5: |
| 17611 |
priority ( expression ) */ |
| 17612 |
|
| 17613 |
static tree |
| 17614 |
c_parser_omp_clause_priority (c_parser *parser, tree list) |
| 17615 |
{ |
| 17616 |
location_t priority_loc = c_parser_peek_token (parser)->location; |
| 17617 |
matching_parens parens; |
| 17618 |
if (parens.require_open (parser)) |
| 17619 |
{ |
| 17620 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 17621 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17622 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 17623 |
tree c, t = expr.value; |
| 17624 |
t = c_fully_fold (t, false, NULL); |
| 17625 |
|
| 17626 |
parens.skip_until_found_close (parser); |
| 17627 |
|
| 17628 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 17629 |
{ |
| 17630 |
c_parser_error (parser, "expected integer expression"); |
| 17631 |
return list; |
| 17632 |
} |
| 17633 |
|
| 17634 |
/* Attempt to statically determine when the number isn't |
| 17635 |
non-negative. */ |
| 17636 |
c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t, |
| 17637 |
build_int_cst (TREE_TYPE (t), 0)); |
| 17638 |
if (CAN_HAVE_LOCATION_P (c)) |
| 17639 |
SET_EXPR_LOCATION (c, expr_loc); |
| 17640 |
if (c == boolean_true_node) |
| 17641 |
{ |
| 17642 |
warning_at (expr_loc, OPT_Wopenmp, |
| 17643 |
"%<priority%> value must be non-negative"); |
| 17644 |
t = integer_one_node; |
| 17645 |
} |
| 17646 |
|
| 17647 |
check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority"); |
| 17648 |
|
| 17649 |
c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY); |
| 17650 |
OMP_CLAUSE_PRIORITY_EXPR (c) = t; |
| 17651 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17652 |
list = c; |
| 17653 |
} |
| 17654 |
|
| 17655 |
return list; |
| 17656 |
} |
| 17657 |
|
| 17658 |
/* OpenMP 4.5: |
| 17659 |
hint ( expression ) */ |
| 17660 |
|
| 17661 |
static tree |
| 17662 |
c_parser_omp_clause_hint (c_parser *parser, tree list) |
| 17663 |
{ |
| 17664 |
location_t hint_loc = c_parser_peek_token (parser)->location; |
| 17665 |
matching_parens parens; |
| 17666 |
if (parens.require_open (parser)) |
| 17667 |
{ |
| 17668 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 17669 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17670 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 17671 |
tree c, t = expr.value; |
| 17672 |
t = c_fully_fold (t, false, NULL); |
| 17673 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) |
| 17674 |
|| TREE_CODE (t) != INTEGER_CST |
| 17675 |
|| tree_int_cst_sgn (t) == -1) |
| 17676 |
{ |
| 17677 |
c_parser_error (parser, "expected constant integer expression " |
| 17678 |
"with valid sync-hint value"); |
| 17679 |
return list; |
| 17680 |
} |
| 17681 |
parens.skip_until_found_close (parser); |
| 17682 |
check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint"); |
| 17683 |
|
| 17684 |
c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT); |
| 17685 |
OMP_CLAUSE_HINT_EXPR (c) = t; |
| 17686 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17687 |
list = c; |
| 17688 |
} |
| 17689 |
|
| 17690 |
return list; |
| 17691 |
} |
| 17692 |
|
| 17693 |
/* OpenMP 5.1: |
| 17694 |
filter ( integer-expression ) */ |
| 17695 |
|
| 17696 |
static tree |
| 17697 |
c_parser_omp_clause_filter (c_parser *parser, tree list) |
| 17698 |
{ |
| 17699 |
location_t hint_loc = c_parser_peek_token (parser)->location; |
| 17700 |
matching_parens parens; |
| 17701 |
if (parens.require_open (parser)) |
| 17702 |
{ |
| 17703 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 17704 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 17705 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 17706 |
tree c, t = expr.value; |
| 17707 |
t = c_fully_fold (t, false, NULL); |
| 17708 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 17709 |
{ |
| 17710 |
c_parser_error (parser, "expected integer expression"); |
| 17711 |
return list; |
| 17712 |
} |
| 17713 |
parens.skip_until_found_close (parser); |
| 17714 |
check_no_duplicate_clause (list, OMP_CLAUSE_FILTER, "filter"); |
| 17715 |
|
| 17716 |
c = build_omp_clause (hint_loc, OMP_CLAUSE_FILTER); |
| 17717 |
OMP_CLAUSE_FILTER_EXPR (c) = t; |
| 17718 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17719 |
list = c; |
| 17720 |
} |
| 17721 |
|
| 17722 |
return list; |
| 17723 |
} |
| 17724 |
|
| 17725 |
/* OpenMP 4.5: |
| 17726 |
defaultmap ( tofrom : scalar ) |
| 17727 |
|
| 17728 |
OpenMP 5.0: |
| 17729 |
defaultmap ( implicit-behavior [ : variable-category ] ) */ |
| 17730 |
|
| 17731 |
static tree |
| 17732 |
c_parser_omp_clause_defaultmap (c_parser *parser, tree list) |
| 17733 |
{ |
| 17734 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17735 |
tree c; |
| 17736 |
const char *p; |
| 17737 |
enum omp_clause_defaultmap_kind behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT; |
| 17738 |
enum omp_clause_defaultmap_kind category |
| 17739 |
= OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED; |
| 17740 |
|
| 17741 |
matching_parens parens; |
| 17742 |
if (!parens.require_open (parser)) |
| 17743 |
return list; |
| 17744 |
if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) |
| 17745 |
p = "default"; |
| 17746 |
else if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 17747 |
{ |
| 17748 |
invalid_behavior: |
| 17749 |
c_parser_error (parser, "expected %<alloc%>, %<to%>, %<from%>, " |
| 17750 |
"%<tofrom%>, %<firstprivate%>, %<none%> " |
| 17751 |
"or %<default%>"); |
| 17752 |
goto out_err; |
| 17753 |
} |
| 17754 |
else |
| 17755 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 17756 |
|
| 17757 |
switch (p[0]) |
| 17758 |
{ |
| 17759 |
case 'a': |
| 17760 |
if (strcmp ("alloc", p) == 0) |
| 17761 |
behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC; |
| 17762 |
else |
| 17763 |
goto invalid_behavior; |
| 17764 |
break; |
| 17765 |
|
| 17766 |
case 'd': |
| 17767 |
if (strcmp ("default", p) == 0) |
| 17768 |
behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT; |
| 17769 |
else |
| 17770 |
goto invalid_behavior; |
| 17771 |
break; |
| 17772 |
|
| 17773 |
case 'f': |
| 17774 |
if (strcmp ("firstprivate", p) == 0) |
| 17775 |
behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE; |
| 17776 |
else if (strcmp ("from", p) == 0) |
| 17777 |
behavior = OMP_CLAUSE_DEFAULTMAP_FROM; |
| 17778 |
else |
| 17779 |
goto invalid_behavior; |
| 17780 |
break; |
| 17781 |
|
| 17782 |
case 'n': |
| 17783 |
if (strcmp ("none", p) == 0) |
| 17784 |
behavior = OMP_CLAUSE_DEFAULTMAP_NONE; |
| 17785 |
else |
| 17786 |
goto invalid_behavior; |
| 17787 |
break; |
| 17788 |
|
| 17789 |
case 'p': |
| 17790 |
if (strcmp ("present", p) == 0) |
| 17791 |
behavior = OMP_CLAUSE_DEFAULTMAP_PRESENT; |
| 17792 |
else |
| 17793 |
goto invalid_behavior; |
| 17794 |
break; |
| 17795 |
|
| 17796 |
case 't': |
| 17797 |
if (strcmp ("tofrom", p) == 0) |
| 17798 |
behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM; |
| 17799 |
else if (strcmp ("to", p) == 0) |
| 17800 |
behavior = OMP_CLAUSE_DEFAULTMAP_TO; |
| 17801 |
else |
| 17802 |
goto invalid_behavior; |
| 17803 |
break; |
| 17804 |
|
| 17805 |
default: |
| 17806 |
goto invalid_behavior; |
| 17807 |
} |
| 17808 |
c_parser_consume_token (parser); |
| 17809 |
|
| 17810 |
if (!c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 17811 |
{ |
| 17812 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 17813 |
goto out_err; |
| 17814 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 17815 |
{ |
| 17816 |
invalid_category: |
| 17817 |
c_parser_error (parser, "expected %<scalar%>, %<aggregate%>, " |
| 17818 |
"%<pointer%> or %<all%>"); |
| 17819 |
goto out_err; |
| 17820 |
} |
| 17821 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 17822 |
switch (p[0]) |
| 17823 |
{ |
| 17824 |
case 'a': |
| 17825 |
if (strcmp ("aggregate", p) == 0) |
| 17826 |
category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE; |
| 17827 |
else if (strcmp ("all", p) == 0) |
| 17828 |
category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL; |
| 17829 |
else |
| 17830 |
goto invalid_category; |
| 17831 |
break; |
| 17832 |
|
| 17833 |
case 'p': |
| 17834 |
if (strcmp ("pointer", p) == 0) |
| 17835 |
category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER; |
| 17836 |
else |
| 17837 |
goto invalid_category; |
| 17838 |
break; |
| 17839 |
|
| 17840 |
case 's': |
| 17841 |
if (strcmp ("scalar", p) == 0) |
| 17842 |
category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR; |
| 17843 |
else |
| 17844 |
goto invalid_category; |
| 17845 |
break; |
| 17846 |
|
| 17847 |
default: |
| 17848 |
goto invalid_category; |
| 17849 |
} |
| 17850 |
|
| 17851 |
c_parser_consume_token (parser); |
| 17852 |
} |
| 17853 |
parens.skip_until_found_close (parser); |
| 17854 |
|
| 17855 |
for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) |
| 17856 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEFAULTMAP |
| 17857 |
&& (category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED |
| 17858 |
|| category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL |
| 17859 |
|| OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) == category |
| 17860 |
|| (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) |
| 17861 |
== OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED) |
| 17862 |
|| (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) |
| 17863 |
== OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL))) |
| 17864 |
{ |
| 17865 |
enum omp_clause_defaultmap_kind cat = category; |
| 17866 |
location_t loc = OMP_CLAUSE_LOCATION (c); |
| 17867 |
if (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED |
| 17868 |
|| (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL |
| 17869 |
&& (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) |
| 17870 |
!= OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED))) |
| 17871 |
cat = OMP_CLAUSE_DEFAULTMAP_CATEGORY (c); |
| 17872 |
p = NULL; |
| 17873 |
switch (cat) |
| 17874 |
{ |
| 17875 |
case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED: |
| 17876 |
p = NULL; |
| 17877 |
break; |
| 17878 |
case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL: |
| 17879 |
p = "all"; |
| 17880 |
break; |
| 17881 |
case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE: |
| 17882 |
p = "aggregate"; |
| 17883 |
break; |
| 17884 |
case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER: |
| 17885 |
p = "pointer"; |
| 17886 |
break; |
| 17887 |
case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR: |
| 17888 |
p = "scalar"; |
| 17889 |
break; |
| 17890 |
default: |
| 17891 |
gcc_unreachable (); |
| 17892 |
} |
| 17893 |
if (p) |
| 17894 |
error_at (loc, "too many %<defaultmap%> clauses with %qs category", |
| 17895 |
p); |
| 17896 |
else |
| 17897 |
error_at (loc, "too many %<defaultmap%> clauses with unspecified " |
| 17898 |
"category"); |
| 17899 |
break; |
| 17900 |
} |
| 17901 |
|
| 17902 |
c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP); |
| 17903 |
OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category); |
| 17904 |
OMP_CLAUSE_CHAIN (c) = list; |
| 17905 |
return c; |
| 17906 |
|
| 17907 |
out_err: |
| 17908 |
parens.skip_until_found_close (parser); |
| 17909 |
return list; |
| 17910 |
} |
| 17911 |
|
| 17912 |
/* OpenACC 2.0: |
| 17913 |
use_device ( variable-list ) |
| 17914 |
|
| 17915 |
OpenMP 4.5: |
| 17916 |
use_device_ptr ( variable-list ) */ |
| 17917 |
|
| 17918 |
static tree |
| 17919 |
c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list) |
| 17920 |
{ |
| 17921 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR, |
| 17922 |
list); |
| 17923 |
} |
| 17924 |
|
| 17925 |
/* OpenMP 5.0: |
| 17926 |
use_device_addr ( variable-list ) */ |
| 17927 |
|
| 17928 |
static tree |
| 17929 |
c_parser_omp_clause_use_device_addr (c_parser *parser, tree list) |
| 17930 |
{ |
| 17931 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_ADDR, |
| 17932 |
list); |
| 17933 |
} |
| 17934 |
|
| 17935 |
/* OpenMP 5.1: |
| 17936 |
has_device_addr ( variable-list ) */ |
| 17937 |
|
| 17938 |
static tree |
| 17939 |
c_parser_omp_clause_has_device_addr (c_parser *parser, tree list) |
| 17940 |
{ |
| 17941 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_HAS_DEVICE_ADDR, |
| 17942 |
list); |
| 17943 |
} |
| 17944 |
|
| 17945 |
/* OpenMP 4.5: |
| 17946 |
is_device_ptr ( variable-list ) */ |
| 17947 |
|
| 17948 |
static tree |
| 17949 |
c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list) |
| 17950 |
{ |
| 17951 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list); |
| 17952 |
} |
| 17953 |
|
| 17954 |
/* OpenACC: |
| 17955 |
num_gangs ( expression ) |
| 17956 |
num_workers ( expression ) |
| 17957 |
vector_length ( expression ) */ |
| 17958 |
|
| 17959 |
static tree |
| 17960 |
c_parser_oacc_single_int_clause (c_parser *parser, omp_clause_code code, |
| 17961 |
tree list) |
| 17962 |
{ |
| 17963 |
location_t loc = c_parser_peek_token (parser)->location; |
| 17964 |
|
| 17965 |
matching_parens parens; |
| 17966 |
if (!parens.require_open (parser)) |
| 17967 |
return list; |
| 17968 |
|
| 17969 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 17970 |
c_expr expr = c_parser_expression (parser); |
| 17971 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 17972 |
tree c, t = expr.value; |
| 17973 |
t = c_fully_fold (t, false, NULL); |
| 17974 |
|
| 17975 |
parens.skip_until_found_close (parser); |
| 17976 |
|
| 17977 |
if (t == error_mark_node) |
| 17978 |
return list; |
| 17979 |
else if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 17980 |
{ |
| 17981 |
error_at (expr_loc, "%qs expression must be integral", |
| 17982 |
omp_clause_code_name[code]); |
| 17983 |
return list; |
| 17984 |
} |
| 17985 |
|
| 17986 |
/* Attempt to statically determine when the number isn't positive. */ |
| 17987 |
c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 17988 |
build_int_cst (TREE_TYPE (t), 0)); |
| 17989 |
protected_set_expr_location (c, expr_loc); |
| 17990 |
if (c == boolean_true_node) |
| 17991 |
{ |
| 17992 |
warning_at (expr_loc, 0, |
| 17993 |
"%qs value must be positive", |
| 17994 |
omp_clause_code_name[code]); |
| 17995 |
t = integer_one_node; |
| 17996 |
} |
| 17997 |
|
| 17998 |
check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
| 17999 |
|
| 18000 |
c = build_omp_clause (loc, code); |
| 18001 |
OMP_CLAUSE_OPERAND (c, 0) = t; |
| 18002 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18003 |
return c; |
| 18004 |
} |
| 18005 |
|
| 18006 |
/* OpenACC: |
| 18007 |
|
| 18008 |
gang [( gang-arg-list )] |
| 18009 |
worker [( [num:] int-expr )] |
| 18010 |
vector [( [length:] int-expr )] |
| 18011 |
|
| 18012 |
where gang-arg is one of: |
| 18013 |
|
| 18014 |
[num:] int-expr |
| 18015 |
static: size-expr |
| 18016 |
|
| 18017 |
and size-expr may be: |
| 18018 |
|
| 18019 |
* |
| 18020 |
int-expr |
| 18021 |
*/ |
| 18022 |
|
| 18023 |
static tree |
| 18024 |
c_parser_oacc_shape_clause (c_parser *parser, location_t loc, |
| 18025 |
omp_clause_code kind, |
| 18026 |
const char *str, tree list) |
| 18027 |
{ |
| 18028 |
const char *id = "num"; |
| 18029 |
tree ops[2] = { NULL_TREE, NULL_TREE }, c; |
| 18030 |
|
| 18031 |
if (kind == OMP_CLAUSE_VECTOR) |
| 18032 |
id = "length"; |
| 18033 |
|
| 18034 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 18035 |
{ |
| 18036 |
c_parser_consume_token (parser); |
| 18037 |
|
| 18038 |
do |
| 18039 |
{ |
| 18040 |
c_token *next = c_parser_peek_token (parser); |
| 18041 |
int idx = 0; |
| 18042 |
|
| 18043 |
/* Gang static argument. */ |
| 18044 |
if (kind == OMP_CLAUSE_GANG |
| 18045 |
&& c_parser_next_token_is_keyword (parser, RID_STATIC)) |
| 18046 |
{ |
| 18047 |
c_parser_consume_token (parser); |
| 18048 |
|
| 18049 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 18050 |
goto cleanup_error; |
| 18051 |
|
| 18052 |
idx = 1; |
| 18053 |
if (ops[idx] != NULL_TREE) |
| 18054 |
{ |
| 18055 |
c_parser_error (parser, "too many %<static%> arguments"); |
| 18056 |
goto cleanup_error; |
| 18057 |
} |
| 18058 |
|
| 18059 |
/* Check for the '*' argument. */ |
| 18060 |
if (c_parser_next_token_is (parser, CPP_MULT) |
| 18061 |
&& (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 18062 |
|| c_parser_peek_2nd_token (parser)->type |
| 18063 |
== CPP_CLOSE_PAREN)) |
| 18064 |
{ |
| 18065 |
c_parser_consume_token (parser); |
| 18066 |
ops[idx] = integer_minus_one_node; |
| 18067 |
|
| 18068 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 18069 |
{ |
| 18070 |
c_parser_consume_token (parser); |
| 18071 |
continue; |
| 18072 |
} |
| 18073 |
else |
| 18074 |
break; |
| 18075 |
} |
| 18076 |
} |
| 18077 |
/* Worker num: argument and vector length: arguments. */ |
| 18078 |
else if (c_parser_next_token_is (parser, CPP_NAME) |
| 18079 |
&& strcmp (id, IDENTIFIER_POINTER (next->value)) == 0 |
| 18080 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 18081 |
{ |
| 18082 |
c_parser_consume_token (parser); /* id */ |
| 18083 |
c_parser_consume_token (parser); /* ':' */ |
| 18084 |
} |
| 18085 |
|
| 18086 |
/* Now collect the actual argument. */ |
| 18087 |
if (ops[idx] != NULL_TREE) |
| 18088 |
{ |
| 18089 |
c_parser_error (parser, "unexpected argument"); |
| 18090 |
goto cleanup_error; |
| 18091 |
} |
| 18092 |
|
| 18093 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 18094 |
c_expr cexpr = c_parser_expr_no_commas (parser, NULL); |
| 18095 |
cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true); |
| 18096 |
tree expr = cexpr.value; |
| 18097 |
if (expr == error_mark_node) |
| 18098 |
goto cleanup_error; |
| 18099 |
|
| 18100 |
expr = c_fully_fold (expr, false, NULL); |
| 18101 |
|
| 18102 |
/* Attempt to statically determine when the number isn't a |
| 18103 |
positive integer. */ |
| 18104 |
|
| 18105 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))) |
| 18106 |
{ |
| 18107 |
c_parser_error (parser, "expected integer expression"); |
| 18108 |
return list; |
| 18109 |
} |
| 18110 |
|
| 18111 |
tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr, |
| 18112 |
build_int_cst (TREE_TYPE (expr), 0)); |
| 18113 |
if (c == boolean_true_node) |
| 18114 |
{ |
| 18115 |
warning_at (loc, 0, |
| 18116 |
"%qs value must be positive", str); |
| 18117 |
expr = integer_one_node; |
| 18118 |
} |
| 18119 |
|
| 18120 |
ops[idx] = expr; |
| 18121 |
|
| 18122 |
if (kind == OMP_CLAUSE_GANG |
| 18123 |
&& c_parser_next_token_is (parser, CPP_COMMA)) |
| 18124 |
{ |
| 18125 |
c_parser_consume_token (parser); |
| 18126 |
continue; |
| 18127 |
} |
| 18128 |
break; |
| 18129 |
} |
| 18130 |
while (1); |
| 18131 |
|
| 18132 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 18133 |
goto cleanup_error; |
| 18134 |
} |
| 18135 |
|
| 18136 |
check_no_duplicate_clause (list, kind, str); |
| 18137 |
|
| 18138 |
c = build_omp_clause (loc, kind); |
| 18139 |
|
| 18140 |
if (ops[1]) |
| 18141 |
OMP_CLAUSE_OPERAND (c, 1) = ops[1]; |
| 18142 |
|
| 18143 |
OMP_CLAUSE_OPERAND (c, 0) = ops[0]; |
| 18144 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18145 |
|
| 18146 |
return c; |
| 18147 |
|
| 18148 |
cleanup_error: |
| 18149 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
| 18150 |
return list; |
| 18151 |
} |
| 18152 |
|
| 18153 |
/* OpenACC 2.5: |
| 18154 |
auto |
| 18155 |
finalize |
| 18156 |
independent |
| 18157 |
nohost |
| 18158 |
seq */ |
| 18159 |
|
| 18160 |
static tree |
| 18161 |
c_parser_oacc_simple_clause (location_t loc, enum omp_clause_code code, |
| 18162 |
tree list) |
| 18163 |
{ |
| 18164 |
check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
| 18165 |
|
| 18166 |
tree c = build_omp_clause (loc, code); |
| 18167 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18168 |
|
| 18169 |
return c; |
| 18170 |
} |
| 18171 |
|
| 18172 |
/* OpenACC: |
| 18173 |
async [( int-expr )] */ |
| 18174 |
|
| 18175 |
static tree |
| 18176 |
c_parser_oacc_clause_async (c_parser *parser, tree list) |
| 18177 |
{ |
| 18178 |
tree c, t; |
| 18179 |
location_t loc = c_parser_peek_token (parser)->location; |
| 18180 |
|
| 18181 |
t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); |
| 18182 |
|
| 18183 |
if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 18184 |
{ |
| 18185 |
c_parser_consume_token (parser); |
| 18186 |
|
| 18187 |
t = c_parser_expr_no_commas (parser, NULL).value; |
| 18188 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 18189 |
c_parser_error (parser, "expected integer expression"); |
| 18190 |
else if (t == error_mark_node |
| 18191 |
|| !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 18192 |
return list; |
| 18193 |
} |
| 18194 |
else |
| 18195 |
t = c_fully_fold (t, false, NULL); |
| 18196 |
|
| 18197 |
check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async"); |
| 18198 |
|
| 18199 |
c = build_omp_clause (loc, OMP_CLAUSE_ASYNC); |
| 18200 |
OMP_CLAUSE_ASYNC_EXPR (c) = t; |
| 18201 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18202 |
list = c; |
| 18203 |
|
| 18204 |
return list; |
| 18205 |
} |
| 18206 |
|
| 18207 |
/* OpenACC 2.0: |
| 18208 |
tile ( size-expr-list ) */ |
| 18209 |
|
| 18210 |
static tree |
| 18211 |
c_parser_oacc_clause_tile (c_parser *parser, tree list) |
| 18212 |
{ |
| 18213 |
tree c, expr = error_mark_node; |
| 18214 |
location_t loc; |
| 18215 |
tree tile = NULL_TREE; |
| 18216 |
|
| 18217 |
check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile"); |
| 18218 |
check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse"); |
| 18219 |
|
| 18220 |
loc = c_parser_peek_token (parser)->location; |
| 18221 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 18222 |
return list; |
| 18223 |
|
| 18224 |
do |
| 18225 |
{ |
| 18226 |
if (tile && !c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 18227 |
return list; |
| 18228 |
|
| 18229 |
if (c_parser_next_token_is (parser, CPP_MULT) |
| 18230 |
&& (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 18231 |
|| c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) |
| 18232 |
{ |
| 18233 |
c_parser_consume_token (parser); |
| 18234 |
expr = integer_zero_node; |
| 18235 |
} |
| 18236 |
else |
| 18237 |
{ |
| 18238 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 18239 |
c_expr cexpr = c_parser_expr_no_commas (parser, NULL); |
| 18240 |
cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true); |
| 18241 |
expr = cexpr.value; |
| 18242 |
|
| 18243 |
if (expr == error_mark_node) |
| 18244 |
{ |
| 18245 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 18246 |
"expected %<)%>"); |
| 18247 |
return list; |
| 18248 |
} |
| 18249 |
|
| 18250 |
expr = c_fully_fold (expr, false, NULL); |
| 18251 |
|
| 18252 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)) |
| 18253 |
|| !tree_fits_shwi_p (expr) |
| 18254 |
|| tree_to_shwi (expr) <= 0) |
| 18255 |
{ |
| 18256 |
error_at (expr_loc, "%<tile%> argument needs positive" |
| 18257 |
" integral constant"); |
| 18258 |
expr = integer_zero_node; |
| 18259 |
} |
| 18260 |
} |
| 18261 |
|
| 18262 |
tile = tree_cons (NULL_TREE, expr, tile); |
| 18263 |
} |
| 18264 |
while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)); |
| 18265 |
|
| 18266 |
/* Consume the trailing ')'. */ |
| 18267 |
c_parser_consume_token (parser); |
| 18268 |
|
| 18269 |
c = build_omp_clause (loc, OMP_CLAUSE_TILE); |
| 18270 |
tile = nreverse (tile); |
| 18271 |
OMP_CLAUSE_TILE_LIST (c) = tile; |
| 18272 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18273 |
return c; |
| 18274 |
} |
| 18275 |
|
| 18276 |
/* OpenACC: |
| 18277 |
wait [( int-expr-list )] */ |
| 18278 |
|
| 18279 |
static tree |
| 18280 |
c_parser_oacc_clause_wait (c_parser *parser, tree list) |
| 18281 |
{ |
| 18282 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 18283 |
|
| 18284 |
if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 18285 |
list = c_parser_oacc_wait_list (parser, clause_loc, list); |
| 18286 |
else |
| 18287 |
{ |
| 18288 |
tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT); |
| 18289 |
|
| 18290 |
OMP_CLAUSE_DECL (c) = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); |
| 18291 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18292 |
list = c; |
| 18293 |
} |
| 18294 |
|
| 18295 |
return list; |
| 18296 |
} |
| 18297 |
|
| 18298 |
/* OpenACC 2.7: |
| 18299 |
self [( expression )] */ |
| 18300 |
|
| 18301 |
static tree |
| 18302 |
c_parser_oacc_compute_clause_self (c_parser *parser, tree list) |
| 18303 |
{ |
| 18304 |
tree t; |
| 18305 |
location_t location = c_parser_peek_token (parser)->location; |
| 18306 |
if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 18307 |
{ |
| 18308 |
matching_parens parens; |
| 18309 |
parens.consume_open (parser); |
| 18310 |
|
| 18311 |
location_t loc = c_parser_peek_token (parser)->location; |
| 18312 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 18313 |
expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
| 18314 |
t = c_objc_common_truthvalue_conversion (loc, expr.value); |
| 18315 |
t = c_fully_fold (t, false, NULL); |
| 18316 |
parens.skip_until_found_close (parser); |
| 18317 |
} |
| 18318 |
else |
| 18319 |
t = truthvalue_true_node; |
| 18320 |
|
| 18321 |
for (tree c = list; c; c = OMP_CLAUSE_CHAIN (c)) |
| 18322 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SELF) |
| 18323 |
{ |
| 18324 |
error_at (location, "too many %<self%> clauses"); |
| 18325 |
return list; |
| 18326 |
} |
| 18327 |
|
| 18328 |
tree c = build_omp_clause (location, OMP_CLAUSE_SELF); |
| 18329 |
OMP_CLAUSE_SELF_EXPR (c) = t; |
| 18330 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18331 |
return c; |
| 18332 |
} |
| 18333 |
|
| 18334 |
/* OpenMP 5.0: |
| 18335 |
order ( concurrent ) |
| 18336 |
|
| 18337 |
OpenMP 5.1: |
| 18338 |
order ( order-modifier : concurrent ) |
| 18339 |
|
| 18340 |
order-modifier: |
| 18341 |
reproducible |
| 18342 |
unconstrained */ |
| 18343 |
|
| 18344 |
static tree |
| 18345 |
c_parser_omp_clause_order (c_parser *parser, tree list) |
| 18346 |
{ |
| 18347 |
location_t loc = c_parser_peek_token (parser)->location; |
| 18348 |
tree c; |
| 18349 |
const char *p; |
| 18350 |
bool unconstrained = false; |
| 18351 |
bool reproducible = false; |
| 18352 |
|
| 18353 |
matching_parens parens; |
| 18354 |
if (!parens.require_open (parser)) |
| 18355 |
return list; |
| 18356 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 18357 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 18358 |
{ |
| 18359 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 18360 |
if (strcmp (p, "unconstrained") == 0) |
| 18361 |
unconstrained = true; |
| 18362 |
else if (strcmp (p, "reproducible") == 0) |
| 18363 |
reproducible = true; |
| 18364 |
else |
| 18365 |
{ |
| 18366 |
c_parser_error (parser, "expected %<reproducible%> or " |
| 18367 |
"%<unconstrained%>"); |
| 18368 |
goto out_err; |
| 18369 |
} |
| 18370 |
c_parser_consume_token (parser); |
| 18371 |
c_parser_consume_token (parser); |
| 18372 |
} |
| 18373 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 18374 |
{ |
| 18375 |
c_parser_error (parser, "expected %<concurrent%>"); |
| 18376 |
goto out_err; |
| 18377 |
} |
| 18378 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 18379 |
if (strcmp (p, "concurrent") != 0) |
| 18380 |
{ |
| 18381 |
c_parser_error (parser, "expected %<concurrent%>"); |
| 18382 |
goto out_err; |
| 18383 |
} |
| 18384 |
c_parser_consume_token (parser); |
| 18385 |
parens.skip_until_found_close (parser); |
| 18386 |
check_no_duplicate_clause (list, OMP_CLAUSE_ORDER, "order"); |
| 18387 |
c = build_omp_clause (loc, OMP_CLAUSE_ORDER); |
| 18388 |
OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = unconstrained; |
| 18389 |
OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = reproducible; |
| 18390 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18391 |
return c; |
| 18392 |
|
| 18393 |
out_err: |
| 18394 |
parens.skip_until_found_close (parser); |
| 18395 |
return list; |
| 18396 |
} |
| 18397 |
|
| 18398 |
|
| 18399 |
/* OpenMP 5.0: |
| 18400 |
bind ( teams | parallel | thread ) */ |
| 18401 |
|
| 18402 |
static tree |
| 18403 |
c_parser_omp_clause_bind (c_parser *parser, tree list) |
| 18404 |
{ |
| 18405 |
location_t loc = c_parser_peek_token (parser)->location; |
| 18406 |
tree c; |
| 18407 |
const char *p; |
| 18408 |
enum omp_clause_bind_kind kind = OMP_CLAUSE_BIND_THREAD; |
| 18409 |
|
| 18410 |
matching_parens parens; |
| 18411 |
if (!parens.require_open (parser)) |
| 18412 |
return list; |
| 18413 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 18414 |
{ |
| 18415 |
invalid: |
| 18416 |
c_parser_error (parser, |
| 18417 |
"expected %<teams%>, %<parallel%> or %<thread%>"); |
| 18418 |
parens.skip_until_found_close (parser); |
| 18419 |
return list; |
| 18420 |
} |
| 18421 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 18422 |
if (strcmp (p, "teams") == 0) |
| 18423 |
kind = OMP_CLAUSE_BIND_TEAMS; |
| 18424 |
else if (strcmp (p, "parallel") == 0) |
| 18425 |
kind = OMP_CLAUSE_BIND_PARALLEL; |
| 18426 |
else if (strcmp (p, "thread") != 0) |
| 18427 |
goto invalid; |
| 18428 |
c_parser_consume_token (parser); |
| 18429 |
parens.skip_until_found_close (parser); |
| 18430 |
/* check_no_duplicate_clause (list, OMP_CLAUSE_BIND, "bind"); */ |
| 18431 |
c = build_omp_clause (loc, OMP_CLAUSE_BIND); |
| 18432 |
OMP_CLAUSE_BIND_KIND (c) = kind; |
| 18433 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18434 |
return c; |
| 18435 |
} |
| 18436 |
|
| 18437 |
|
| 18438 |
/* OpenMP 2.5: |
| 18439 |
ordered |
| 18440 |
|
| 18441 |
OpenMP 4.5: |
| 18442 |
ordered ( constant-expression ) */ |
| 18443 |
|
| 18444 |
static tree |
| 18445 |
c_parser_omp_clause_ordered (c_parser *parser, tree list) |
| 18446 |
{ |
| 18447 |
check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); |
| 18448 |
|
| 18449 |
tree c, num = NULL_TREE; |
| 18450 |
HOST_WIDE_INT n; |
| 18451 |
location_t loc = c_parser_peek_token (parser)->location; |
| 18452 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 18453 |
{ |
| 18454 |
matching_parens parens; |
| 18455 |
parens.consume_open (parser); |
| 18456 |
num = c_parser_expr_no_commas (parser, NULL).value; |
| 18457 |
parens.skip_until_found_close (parser); |
| 18458 |
} |
| 18459 |
if (num == error_mark_node) |
| 18460 |
return list; |
| 18461 |
if (num) |
| 18462 |
{ |
| 18463 |
mark_exp_read (num); |
| 18464 |
num = c_fully_fold (num, false, NULL); |
| 18465 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
| 18466 |
|| !tree_fits_shwi_p (num) |
| 18467 |
|| (n = tree_to_shwi (num)) <= 0 |
| 18468 |
|| (int) n != n) |
| 18469 |
{ |
| 18470 |
error_at (loc, "ordered argument needs positive " |
| 18471 |
"constant integer expression"); |
| 18472 |
return list; |
| 18473 |
} |
| 18474 |
} |
| 18475 |
c = build_omp_clause (loc, OMP_CLAUSE_ORDERED); |
| 18476 |
OMP_CLAUSE_ORDERED_EXPR (c) = num; |
| 18477 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18478 |
return c; |
| 18479 |
} |
| 18480 |
|
| 18481 |
/* OpenMP 2.5: |
| 18482 |
private ( variable-list ) */ |
| 18483 |
|
| 18484 |
static tree |
| 18485 |
c_parser_omp_clause_private (c_parser *parser, tree list) |
| 18486 |
{ |
| 18487 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list); |
| 18488 |
} |
| 18489 |
|
| 18490 |
/* OpenMP 2.5: |
| 18491 |
reduction ( reduction-operator : variable-list ) |
| 18492 |
|
| 18493 |
reduction-operator: |
| 18494 |
One of: + * - & ^ | && || |
| 18495 |
|
| 18496 |
OpenMP 3.1: |
| 18497 |
|
| 18498 |
reduction-operator: |
| 18499 |
One of: + * - & ^ | && || max min |
| 18500 |
|
| 18501 |
OpenMP 4.0: |
| 18502 |
|
| 18503 |
reduction-operator: |
| 18504 |
One of: + * - & ^ | && || |
| 18505 |
identifier |
| 18506 |
|
| 18507 |
OpenMP 5.0: |
| 18508 |
reduction ( reduction-modifier, reduction-operator : variable-list ) |
| 18509 |
in_reduction ( reduction-operator : variable-list ) |
| 18510 |
task_reduction ( reduction-operator : variable-list ) */ |
| 18511 |
|
| 18512 |
static tree |
| 18513 |
c_parser_omp_clause_reduction (c_parser *parser, enum omp_clause_code kind, |
| 18514 |
bool is_omp, tree list) |
| 18515 |
{ |
| 18516 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 18517 |
matching_parens parens; |
| 18518 |
if (parens.require_open (parser)) |
| 18519 |
{ |
| 18520 |
bool task = false; |
| 18521 |
bool inscan = false; |
| 18522 |
enum tree_code code = ERROR_MARK; |
| 18523 |
tree reduc_id = NULL_TREE; |
| 18524 |
|
| 18525 |
if (kind == OMP_CLAUSE_REDUCTION && is_omp) |
| 18526 |
{ |
| 18527 |
if (c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
| 18528 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COMMA) |
| 18529 |
{ |
| 18530 |
c_parser_consume_token (parser); |
| 18531 |
c_parser_consume_token (parser); |
| 18532 |
} |
| 18533 |
else if (c_parser_next_token_is (parser, CPP_NAME) |
| 18534 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COMMA) |
| 18535 |
{ |
| 18536 |
const char *p |
| 18537 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 18538 |
if (strcmp (p, "task") == 0) |
| 18539 |
task = true; |
| 18540 |
else if (strcmp (p, "inscan") == 0) |
| 18541 |
inscan = true; |
| 18542 |
if (task || inscan) |
| 18543 |
{ |
| 18544 |
c_parser_consume_token (parser); |
| 18545 |
c_parser_consume_token (parser); |
| 18546 |
} |
| 18547 |
} |
| 18548 |
} |
| 18549 |
|
| 18550 |
switch (c_parser_peek_token (parser)->type) |
| 18551 |
{ |
| 18552 |
case CPP_PLUS: |
| 18553 |
code = PLUS_EXPR; |
| 18554 |
break; |
| 18555 |
case CPP_MULT: |
| 18556 |
code = MULT_EXPR; |
| 18557 |
break; |
| 18558 |
case CPP_MINUS: |
| 18559 |
code = MINUS_EXPR; |
| 18560 |
break; |
| 18561 |
case CPP_AND: |
| 18562 |
code = BIT_AND_EXPR; |
| 18563 |
break; |
| 18564 |
case CPP_XOR: |
| 18565 |
code = BIT_XOR_EXPR; |
| 18566 |
break; |
| 18567 |
case CPP_OR: |
| 18568 |
code = BIT_IOR_EXPR; |
| 18569 |
break; |
| 18570 |
case CPP_AND_AND: |
| 18571 |
code = TRUTH_ANDIF_EXPR; |
| 18572 |
break; |
| 18573 |
case CPP_OR_OR: |
| 18574 |
code = TRUTH_ORIF_EXPR; |
| 18575 |
break; |
| 18576 |
case CPP_NAME: |
| 18577 |
{ |
| 18578 |
const char *p |
| 18579 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 18580 |
if (strcmp (p, "min") == 0) |
| 18581 |
{ |
| 18582 |
code = MIN_EXPR; |
| 18583 |
break; |
| 18584 |
} |
| 18585 |
if (strcmp (p, "max") == 0) |
| 18586 |
{ |
| 18587 |
code = MAX_EXPR; |
| 18588 |
break; |
| 18589 |
} |
| 18590 |
reduc_id = c_parser_peek_token (parser)->value; |
| 18591 |
break; |
| 18592 |
} |
| 18593 |
default: |
| 18594 |
c_parser_error (parser, |
| 18595 |
"expected %<+%>, %<*%>, %<-%>, %<&%>, " |
| 18596 |
"%<^%>, %<|%>, %<&&%>, %<||%> or identifier"); |
| 18597 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
| 18598 |
return list; |
| 18599 |
} |
| 18600 |
c_parser_consume_token (parser); |
| 18601 |
reduc_id = c_omp_reduction_id (code, reduc_id); |
| 18602 |
if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 18603 |
{ |
| 18604 |
tree nl, c; |
| 18605 |
|
| 18606 |
nl = c_parser_omp_variable_list (parser, clause_loc, kind, list); |
| 18607 |
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 18608 |
{ |
| 18609 |
tree d = OMP_CLAUSE_DECL (c), type; |
| 18610 |
if (TREE_CODE (d) != OMP_ARRAY_SECTION) |
| 18611 |
type = TREE_TYPE (d); |
| 18612 |
else |
| 18613 |
{ |
| 18614 |
int cnt = 0; |
| 18615 |
tree t; |
| 18616 |
for (t = d; |
| 18617 |
TREE_CODE (t) == OMP_ARRAY_SECTION; |
| 18618 |
t = TREE_OPERAND (t, 0)) |
| 18619 |
cnt++; |
| 18620 |
type = TREE_TYPE (t); |
| 18621 |
while (cnt > 0) |
| 18622 |
{ |
| 18623 |
if (TREE_CODE (type) != POINTER_TYPE |
| 18624 |
&& TREE_CODE (type) != ARRAY_TYPE) |
| 18625 |
break; |
| 18626 |
type = TREE_TYPE (type); |
| 18627 |
cnt--; |
| 18628 |
} |
| 18629 |
} |
| 18630 |
while (TREE_CODE (type) == ARRAY_TYPE) |
| 18631 |
type = TREE_TYPE (type); |
| 18632 |
OMP_CLAUSE_REDUCTION_CODE (c) = code; |
| 18633 |
if (task) |
| 18634 |
OMP_CLAUSE_REDUCTION_TASK (c) = 1; |
| 18635 |
else if (inscan) |
| 18636 |
OMP_CLAUSE_REDUCTION_INSCAN (c) = 1; |
| 18637 |
if (code == ERROR_MARK |
| 18638 |
|| !(INTEGRAL_TYPE_P (type) |
| 18639 |
|| SCALAR_FLOAT_TYPE_P (type) |
| 18640 |
|| TREE_CODE (type) == COMPLEX_TYPE)) |
| 18641 |
OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) |
| 18642 |
= c_omp_reduction_lookup (reduc_id, |
| 18643 |
TYPE_MAIN_VARIANT (type)); |
| 18644 |
} |
| 18645 |
|
| 18646 |
list = nl; |
| 18647 |
} |
| 18648 |
parens.skip_until_found_close (parser); |
| 18649 |
} |
| 18650 |
return list; |
| 18651 |
} |
| 18652 |
|
| 18653 |
/* OpenMP 2.5: |
| 18654 |
schedule ( schedule-kind ) |
| 18655 |
schedule ( schedule-kind , expression ) |
| 18656 |
|
| 18657 |
schedule-kind: |
| 18658 |
static | dynamic | guided | runtime | auto |
| 18659 |
|
| 18660 |
OpenMP 4.5: |
| 18661 |
schedule ( schedule-modifier : schedule-kind ) |
| 18662 |
schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression ) |
| 18663 |
|
| 18664 |
schedule-modifier: |
| 18665 |
simd |
| 18666 |
monotonic |
| 18667 |
nonmonotonic */ |
| 18668 |
|
| 18669 |
static tree |
| 18670 |
c_parser_omp_clause_schedule (c_parser *parser, tree list) |
| 18671 |
{ |
| 18672 |
tree c, t; |
| 18673 |
location_t loc = c_parser_peek_token (parser)->location; |
| 18674 |
int modifiers = 0, nmodifiers = 0; |
| 18675 |
|
| 18676 |
matching_parens parens; |
| 18677 |
if (!parens.require_open (parser)) |
| 18678 |
return list; |
| 18679 |
|
| 18680 |
c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); |
| 18681 |
|
| 18682 |
location_t comma = UNKNOWN_LOCATION; |
| 18683 |
while (c_parser_next_token_is (parser, CPP_NAME)) |
| 18684 |
{ |
| 18685 |
tree kind = c_parser_peek_token (parser)->value; |
| 18686 |
const char *p = IDENTIFIER_POINTER (kind); |
| 18687 |
if (strcmp ("simd", p) == 0) |
| 18688 |
OMP_CLAUSE_SCHEDULE_SIMD (c) = 1; |
| 18689 |
else if (strcmp ("monotonic", p) == 0) |
| 18690 |
modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC; |
| 18691 |
else if (strcmp ("nonmonotonic", p) == 0) |
| 18692 |
modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC; |
| 18693 |
else |
| 18694 |
break; |
| 18695 |
comma = UNKNOWN_LOCATION; |
| 18696 |
c_parser_consume_token (parser); |
| 18697 |
if (nmodifiers++ == 0 |
| 18698 |
&& c_parser_next_token_is (parser, CPP_COMMA)) |
| 18699 |
{ |
| 18700 |
comma = c_parser_peek_token (parser)->location; |
| 18701 |
c_parser_consume_token (parser); |
| 18702 |
} |
| 18703 |
else |
| 18704 |
{ |
| 18705 |
c_parser_require (parser, CPP_COLON, "expected %<:%>"); |
| 18706 |
break; |
| 18707 |
} |
| 18708 |
} |
| 18709 |
if (comma != UNKNOWN_LOCATION) |
| 18710 |
error_at (comma, "expected %<:%>"); |
| 18711 |
|
| 18712 |
if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC |
| 18713 |
| OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) |
| 18714 |
== (OMP_CLAUSE_SCHEDULE_MONOTONIC |
| 18715 |
| OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) |
| 18716 |
{ |
| 18717 |
error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers " |
| 18718 |
"specified"); |
| 18719 |
modifiers = 0; |
| 18720 |
} |
| 18721 |
|
| 18722 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 18723 |
{ |
| 18724 |
tree kind = c_parser_peek_token (parser)->value; |
| 18725 |
const char *p = IDENTIFIER_POINTER (kind); |
| 18726 |
|
| 18727 |
switch (p[0]) |
| 18728 |
{ |
| 18729 |
case 'd': |
| 18730 |
if (strcmp ("dynamic", p) != 0) |
| 18731 |
goto invalid_kind; |
| 18732 |
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; |
| 18733 |
break; |
| 18734 |
|
| 18735 |
case 'g': |
| 18736 |
if (strcmp ("guided", p) != 0) |
| 18737 |
goto invalid_kind; |
| 18738 |
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; |
| 18739 |
break; |
| 18740 |
|
| 18741 |
case 'r': |
| 18742 |
if (strcmp ("runtime", p) != 0) |
| 18743 |
goto invalid_kind; |
| 18744 |
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; |
| 18745 |
break; |
| 18746 |
|
| 18747 |
default: |
| 18748 |
goto invalid_kind; |
| 18749 |
} |
| 18750 |
} |
| 18751 |
else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) |
| 18752 |
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; |
| 18753 |
else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
| 18754 |
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; |
| 18755 |
else |
| 18756 |
goto invalid_kind; |
| 18757 |
|
| 18758 |
c_parser_consume_token (parser); |
| 18759 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 18760 |
{ |
| 18761 |
location_t here; |
| 18762 |
c_parser_consume_token (parser); |
| 18763 |
|
| 18764 |
here = c_parser_peek_token (parser)->location; |
| 18765 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 18766 |
expr = convert_lvalue_to_rvalue (here, expr, false, true); |
| 18767 |
t = expr.value; |
| 18768 |
t = c_fully_fold (t, false, NULL); |
| 18769 |
|
| 18770 |
if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) |
| 18771 |
error_at (here, "schedule %<runtime%> does not take " |
| 18772 |
"a %<chunk_size%> parameter"); |
| 18773 |
else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) |
| 18774 |
error_at (here, |
| 18775 |
"schedule %<auto%> does not take " |
| 18776 |
"a %<chunk_size%> parameter"); |
| 18777 |
else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE |
| 18778 |
|| TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE) |
| 18779 |
{ |
| 18780 |
/* Attempt to statically determine when the number isn't |
| 18781 |
positive. */ |
| 18782 |
tree s = fold_build2_loc (loc, LE_EXPR, boolean_type_node, t, |
| 18783 |
build_int_cst (TREE_TYPE (t), 0)); |
| 18784 |
protected_set_expr_location (s, loc); |
| 18785 |
if (s == boolean_true_node) |
| 18786 |
{ |
| 18787 |
warning_at (loc, OPT_Wopenmp, |
| 18788 |
"chunk size value must be positive"); |
| 18789 |
t = integer_one_node; |
| 18790 |
} |
| 18791 |
OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; |
| 18792 |
} |
| 18793 |
else |
| 18794 |
c_parser_error (parser, "expected integer expression"); |
| 18795 |
|
| 18796 |
parens.skip_until_found_close (parser); |
| 18797 |
} |
| 18798 |
else |
| 18799 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 18800 |
"expected %<,%> or %<)%>"); |
| 18801 |
|
| 18802 |
OMP_CLAUSE_SCHEDULE_KIND (c) |
| 18803 |
= (enum omp_clause_schedule_kind) |
| 18804 |
(OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers); |
| 18805 |
|
| 18806 |
check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); |
| 18807 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18808 |
return c; |
| 18809 |
|
| 18810 |
invalid_kind: |
| 18811 |
c_parser_error (parser, "invalid schedule kind"); |
| 18812 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
| 18813 |
return list; |
| 18814 |
} |
| 18815 |
|
| 18816 |
/* OpenMP 2.5: |
| 18817 |
shared ( variable-list ) */ |
| 18818 |
|
| 18819 |
static tree |
| 18820 |
c_parser_omp_clause_shared (c_parser *parser, tree list) |
| 18821 |
{ |
| 18822 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list); |
| 18823 |
} |
| 18824 |
|
| 18825 |
/* OpenMP 3.0: |
| 18826 |
untied */ |
| 18827 |
|
| 18828 |
static tree |
| 18829 |
c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 18830 |
{ |
| 18831 |
tree c; |
| 18832 |
|
| 18833 |
/* FIXME: Should we allow duplicates? */ |
| 18834 |
check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); |
| 18835 |
|
| 18836 |
c = build_omp_clause (c_parser_peek_token (parser)->location, |
| 18837 |
OMP_CLAUSE_UNTIED); |
| 18838 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18839 |
|
| 18840 |
return c; |
| 18841 |
} |
| 18842 |
|
| 18843 |
/* OpenMP 4.0: |
| 18844 |
inbranch |
| 18845 |
notinbranch */ |
| 18846 |
|
| 18847 |
static tree |
| 18848 |
c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED, |
| 18849 |
enum omp_clause_code code, tree list) |
| 18850 |
{ |
| 18851 |
check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
| 18852 |
|
| 18853 |
tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
| 18854 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18855 |
|
| 18856 |
return c; |
| 18857 |
} |
| 18858 |
|
| 18859 |
/* OpenMP 4.0: |
| 18860 |
parallel |
| 18861 |
for |
| 18862 |
sections |
| 18863 |
taskgroup */ |
| 18864 |
|
| 18865 |
static tree |
| 18866 |
c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED, |
| 18867 |
enum omp_clause_code code, tree list) |
| 18868 |
{ |
| 18869 |
tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
| 18870 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18871 |
|
| 18872 |
return c; |
| 18873 |
} |
| 18874 |
|
| 18875 |
/* OpenMP 4.5: |
| 18876 |
nogroup */ |
| 18877 |
|
| 18878 |
static tree |
| 18879 |
c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 18880 |
{ |
| 18881 |
check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup"); |
| 18882 |
tree c = build_omp_clause (c_parser_peek_token (parser)->location, |
| 18883 |
OMP_CLAUSE_NOGROUP); |
| 18884 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18885 |
return c; |
| 18886 |
} |
| 18887 |
|
| 18888 |
/* OpenMP 4.5: |
| 18889 |
simd |
| 18890 |
threads */ |
| 18891 |
|
| 18892 |
static tree |
| 18893 |
c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED, |
| 18894 |
enum omp_clause_code code, tree list) |
| 18895 |
{ |
| 18896 |
check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
| 18897 |
tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
| 18898 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18899 |
return c; |
| 18900 |
} |
| 18901 |
|
| 18902 |
/* OpenMP 4.0: |
| 18903 |
num_teams ( expression ) |
| 18904 |
|
| 18905 |
OpenMP 5.1: |
| 18906 |
num_teams ( expression : expression ) */ |
| 18907 |
|
| 18908 |
static tree |
| 18909 |
c_parser_omp_clause_num_teams (c_parser *parser, tree list) |
| 18910 |
{ |
| 18911 |
location_t num_teams_loc = c_parser_peek_token (parser)->location; |
| 18912 |
matching_parens parens; |
| 18913 |
if (parens.require_open (parser)) |
| 18914 |
{ |
| 18915 |
location_t upper_loc = c_parser_peek_token (parser)->location; |
| 18916 |
location_t lower_loc = UNKNOWN_LOCATION; |
| 18917 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 18918 |
expr = convert_lvalue_to_rvalue (upper_loc, expr, false, true); |
| 18919 |
tree c, upper = expr.value, lower = NULL_TREE; |
| 18920 |
upper = c_fully_fold (upper, false, NULL); |
| 18921 |
|
| 18922 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 18923 |
{ |
| 18924 |
c_parser_consume_token (parser); |
| 18925 |
lower_loc = upper_loc; |
| 18926 |
lower = upper; |
| 18927 |
upper_loc = c_parser_peek_token (parser)->location; |
| 18928 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 18929 |
expr = convert_lvalue_to_rvalue (upper_loc, expr, false, true); |
| 18930 |
upper = expr.value; |
| 18931 |
upper = c_fully_fold (upper, false, NULL); |
| 18932 |
} |
| 18933 |
|
| 18934 |
parens.skip_until_found_close (parser); |
| 18935 |
|
| 18936 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (upper)) |
| 18937 |
|| (lower && !INTEGRAL_TYPE_P (TREE_TYPE (lower)))) |
| 18938 |
{ |
| 18939 |
c_parser_error (parser, "expected integer expression"); |
| 18940 |
return list; |
| 18941 |
} |
| 18942 |
|
| 18943 |
/* Attempt to statically determine when the number isn't positive. */ |
| 18944 |
c = fold_build2_loc (upper_loc, LE_EXPR, boolean_type_node, upper, |
| 18945 |
build_int_cst (TREE_TYPE (upper), 0)); |
| 18946 |
protected_set_expr_location (c, upper_loc); |
| 18947 |
if (c == boolean_true_node) |
| 18948 |
{ |
| 18949 |
warning_at (upper_loc, OPT_Wopenmp, |
| 18950 |
"%<num_teams%> value must be positive"); |
| 18951 |
upper = integer_one_node; |
| 18952 |
} |
| 18953 |
if (lower) |
| 18954 |
{ |
| 18955 |
c = fold_build2_loc (lower_loc, LE_EXPR, boolean_type_node, lower, |
| 18956 |
build_int_cst (TREE_TYPE (lower), 0)); |
| 18957 |
protected_set_expr_location (c, lower_loc); |
| 18958 |
if (c == boolean_true_node) |
| 18959 |
{ |
| 18960 |
warning_at (lower_loc, OPT_Wopenmp, |
| 18961 |
"%<num_teams%> value must be positive"); |
| 18962 |
lower = NULL_TREE; |
| 18963 |
} |
| 18964 |
else if (TREE_CODE (lower) == INTEGER_CST |
| 18965 |
&& TREE_CODE (upper) == INTEGER_CST |
| 18966 |
&& tree_int_cst_lt (upper, lower)) |
| 18967 |
{ |
| 18968 |
warning_at (lower_loc, OPT_Wopenmp, |
| 18969 |
"%<num_teams%> lower bound %qE bigger than upper " |
| 18970 |
"bound %qE", lower, upper); |
| 18971 |
lower = NULL_TREE; |
| 18972 |
} |
| 18973 |
} |
| 18974 |
|
| 18975 |
check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams"); |
| 18976 |
|
| 18977 |
c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS); |
| 18978 |
OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c) = upper; |
| 18979 |
OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = lower; |
| 18980 |
OMP_CLAUSE_CHAIN (c) = list; |
| 18981 |
list = c; |
| 18982 |
} |
| 18983 |
|
| 18984 |
return list; |
| 18985 |
} |
| 18986 |
|
| 18987 |
/* OpenMP 4.0: |
| 18988 |
thread_limit ( expression ) */ |
| 18989 |
|
| 18990 |
static tree |
| 18991 |
c_parser_omp_clause_thread_limit (c_parser *parser, tree list) |
| 18992 |
{ |
| 18993 |
location_t num_thread_limit_loc = c_parser_peek_token (parser)->location; |
| 18994 |
matching_parens parens; |
| 18995 |
if (parens.require_open (parser)) |
| 18996 |
{ |
| 18997 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 18998 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 18999 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 19000 |
tree c, t = expr.value; |
| 19001 |
t = c_fully_fold (t, false, NULL); |
| 19002 |
|
| 19003 |
parens.skip_until_found_close (parser); |
| 19004 |
|
| 19005 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 19006 |
{ |
| 19007 |
c_parser_error (parser, "expected integer expression"); |
| 19008 |
return list; |
| 19009 |
} |
| 19010 |
|
| 19011 |
/* Attempt to statically determine when the number isn't positive. */ |
| 19012 |
c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 19013 |
build_int_cst (TREE_TYPE (t), 0)); |
| 19014 |
protected_set_expr_location (c, expr_loc); |
| 19015 |
if (c == boolean_true_node) |
| 19016 |
{ |
| 19017 |
warning_at (expr_loc, OPT_Wopenmp, |
| 19018 |
"%<thread_limit%> value must be positive"); |
| 19019 |
t = integer_one_node; |
| 19020 |
} |
| 19021 |
|
| 19022 |
check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT, |
| 19023 |
"thread_limit"); |
| 19024 |
|
| 19025 |
c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT); |
| 19026 |
OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; |
| 19027 |
OMP_CLAUSE_CHAIN (c) = list; |
| 19028 |
list = c; |
| 19029 |
} |
| 19030 |
|
| 19031 |
return list; |
| 19032 |
} |
| 19033 |
|
| 19034 |
/* OpenMP 4.0: |
| 19035 |
aligned ( variable-list ) |
| 19036 |
aligned ( variable-list : constant-expression ) */ |
| 19037 |
|
| 19038 |
static tree |
| 19039 |
c_parser_omp_clause_aligned (c_parser *parser, tree list) |
| 19040 |
{ |
| 19041 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19042 |
tree nl, c; |
| 19043 |
|
| 19044 |
matching_parens parens; |
| 19045 |
if (!parens.require_open (parser)) |
| 19046 |
return list; |
| 19047 |
|
| 19048 |
nl = c_parser_omp_variable_list (parser, clause_loc, |
| 19049 |
OMP_CLAUSE_ALIGNED, list); |
| 19050 |
|
| 19051 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 19052 |
{ |
| 19053 |
c_parser_consume_token (parser); |
| 19054 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 19055 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19056 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 19057 |
tree alignment = expr.value; |
| 19058 |
alignment = c_fully_fold (alignment, false, NULL); |
| 19059 |
if (TREE_CODE (alignment) != INTEGER_CST |
| 19060 |
|| !INTEGRAL_TYPE_P (TREE_TYPE (alignment)) |
| 19061 |
|| tree_int_cst_sgn (alignment) != 1) |
| 19062 |
{ |
| 19063 |
error_at (clause_loc, "%<aligned%> clause alignment expression must " |
| 19064 |
"be positive constant integer expression"); |
| 19065 |
alignment = NULL_TREE; |
| 19066 |
} |
| 19067 |
|
| 19068 |
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 19069 |
OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment; |
| 19070 |
} |
| 19071 |
|
| 19072 |
parens.skip_until_found_close (parser); |
| 19073 |
return nl; |
| 19074 |
} |
| 19075 |
|
| 19076 |
/* OpenMP 5.0: |
| 19077 |
allocate ( variable-list ) |
| 19078 |
allocate ( expression : variable-list ) |
| 19079 |
|
| 19080 |
OpenMP 5.1: |
| 19081 |
allocate ( allocator-modifier : variable-list ) |
| 19082 |
allocate ( allocator-modifier , allocator-modifier : variable-list ) |
| 19083 |
|
| 19084 |
allocator-modifier: |
| 19085 |
allocator ( expression ) |
| 19086 |
align ( expression ) */ |
| 19087 |
|
| 19088 |
static tree |
| 19089 |
c_parser_omp_clause_allocate (c_parser *parser, tree list) |
| 19090 |
{ |
| 19091 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19092 |
tree nl, c; |
| 19093 |
tree allocator = NULL_TREE; |
| 19094 |
tree align = NULL_TREE; |
| 19095 |
|
| 19096 |
matching_parens parens; |
| 19097 |
if (!parens.require_open (parser)) |
| 19098 |
return list; |
| 19099 |
|
| 19100 |
if ((c_parser_next_token_is_not (parser, CPP_NAME) |
| 19101 |
&& c_parser_next_token_is_not (parser, CPP_KEYWORD)) |
| 19102 |
|| (c_parser_peek_2nd_token (parser)->type != CPP_COMMA |
| 19103 |
&& c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)) |
| 19104 |
{ |
| 19105 |
bool has_modifiers = false; |
| 19106 |
tree orig_type = NULL_TREE; |
| 19107 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 19108 |
&& c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN) |
| 19109 |
{ |
| 19110 |
unsigned int n = 3; |
| 19111 |
const char *p |
| 19112 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 19113 |
if ((strcmp (p, "allocator") == 0 || strcmp (p, "align") == 0) |
| 19114 |
&& c_parser_check_balanced_raw_token_sequence (parser, &n) |
| 19115 |
&& (c_parser_peek_nth_token_raw (parser, n)->type |
| 19116 |
== CPP_CLOSE_PAREN)) |
| 19117 |
{ |
| 19118 |
if (c_parser_peek_nth_token_raw (parser, n + 1)->type |
| 19119 |
== CPP_COLON) |
| 19120 |
has_modifiers = true; |
| 19121 |
else if (c_parser_peek_nth_token_raw (parser, n + 1)->type |
| 19122 |
== CPP_COMMA |
| 19123 |
&& (c_parser_peek_nth_token_raw (parser, n + 2)->type |
| 19124 |
== CPP_NAME) |
| 19125 |
&& (c_parser_peek_nth_token_raw (parser, n + 3)->type |
| 19126 |
== CPP_OPEN_PAREN)) |
| 19127 |
{ |
| 19128 |
c_token *tok = c_parser_peek_nth_token_raw (parser, n + 2); |
| 19129 |
const char *q = IDENTIFIER_POINTER (tok->value); |
| 19130 |
n += 4; |
| 19131 |
if ((strcmp (q, "allocator") == 0 |
| 19132 |
|| strcmp (q, "align") == 0) |
| 19133 |
&& c_parser_check_balanced_raw_token_sequence (parser, |
| 19134 |
&n) |
| 19135 |
&& (c_parser_peek_nth_token_raw (parser, n)->type |
| 19136 |
== CPP_CLOSE_PAREN) |
| 19137 |
&& (c_parser_peek_nth_token_raw (parser, n + 1)->type |
| 19138 |
== CPP_COLON)) |
| 19139 |
has_modifiers = true; |
| 19140 |
} |
| 19141 |
} |
| 19142 |
if (has_modifiers) |
| 19143 |
{ |
| 19144 |
c_parser_consume_token (parser); |
| 19145 |
matching_parens parens2; |
| 19146 |
parens2.require_open (parser); |
| 19147 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 19148 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19149 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 19150 |
if (expr.value == error_mark_node) |
| 19151 |
; |
| 19152 |
else if (strcmp (p, "allocator") == 0) |
| 19153 |
{ |
| 19154 |
allocator = expr.value; |
| 19155 |
allocator = c_fully_fold (allocator, false, NULL); |
| 19156 |
orig_type = expr.original_type |
| 19157 |
? expr.original_type : TREE_TYPE (allocator); |
| 19158 |
orig_type = TYPE_MAIN_VARIANT (orig_type); |
| 19159 |
} |
| 19160 |
else |
| 19161 |
{ |
| 19162 |
align = expr.value; |
| 19163 |
align = c_fully_fold (align, false, NULL); |
| 19164 |
} |
| 19165 |
parens2.skip_until_found_close (parser); |
| 19166 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 19167 |
{ |
| 19168 |
c_parser_consume_token (parser); |
| 19169 |
c_token *tok = c_parser_peek_token (parser); |
| 19170 |
const char *q = ""; |
| 19171 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 19172 |
q = IDENTIFIER_POINTER (tok->value); |
| 19173 |
if (strcmp (q, "allocator") != 0 && strcmp (q, "align") != 0) |
| 19174 |
{ |
| 19175 |
c_parser_error (parser, "expected %<allocator%> or " |
| 19176 |
"%<align%>"); |
| 19177 |
parens.skip_until_found_close (parser); |
| 19178 |
return list; |
| 19179 |
} |
| 19180 |
else if (strcmp (p, q) == 0) |
| 19181 |
{ |
| 19182 |
error_at (tok->location, "duplicate %qs modifier", p); |
| 19183 |
parens.skip_until_found_close (parser); |
| 19184 |
return list; |
| 19185 |
} |
| 19186 |
c_parser_consume_token (parser); |
| 19187 |
if (!parens2.require_open (parser)) |
| 19188 |
{ |
| 19189 |
parens.skip_until_found_close (parser); |
| 19190 |
return list; |
| 19191 |
} |
| 19192 |
expr_loc = c_parser_peek_token (parser)->location; |
| 19193 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 19194 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, |
| 19195 |
true); |
| 19196 |
if (strcmp (q, "allocator") == 0) |
| 19197 |
{ |
| 19198 |
allocator = expr.value; |
| 19199 |
allocator = c_fully_fold (allocator, false, NULL); |
| 19200 |
orig_type = expr.original_type |
| 19201 |
? expr.original_type : TREE_TYPE (allocator); |
| 19202 |
orig_type = TYPE_MAIN_VARIANT (orig_type); |
| 19203 |
} |
| 19204 |
else |
| 19205 |
{ |
| 19206 |
align = expr.value; |
| 19207 |
align = c_fully_fold (align, false, NULL); |
| 19208 |
} |
| 19209 |
parens2.skip_until_found_close (parser); |
| 19210 |
} |
| 19211 |
} |
| 19212 |
} |
| 19213 |
if (!has_modifiers) |
| 19214 |
{ |
| 19215 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 19216 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19217 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 19218 |
allocator = expr.value; |
| 19219 |
allocator = c_fully_fold (allocator, false, NULL); |
| 19220 |
orig_type = expr.original_type |
| 19221 |
? expr.original_type : TREE_TYPE (allocator); |
| 19222 |
orig_type = TYPE_MAIN_VARIANT (orig_type); |
| 19223 |
} |
| 19224 |
if (allocator |
| 19225 |
&& (!INTEGRAL_TYPE_P (TREE_TYPE (allocator)) |
| 19226 |
|| TREE_CODE (orig_type) != ENUMERAL_TYPE |
| 19227 |
|| (TYPE_NAME (orig_type) |
| 19228 |
!= get_identifier ("omp_allocator_handle_t")))) |
| 19229 |
{ |
| 19230 |
error_at (clause_loc, "%<allocate%> clause allocator expression " |
| 19231 |
"has type %qT rather than " |
| 19232 |
"%<omp_allocator_handle_t%>", |
| 19233 |
TREE_TYPE (allocator)); |
| 19234 |
allocator = NULL_TREE; |
| 19235 |
} |
| 19236 |
if (align |
| 19237 |
&& (!INTEGRAL_TYPE_P (TREE_TYPE (align)) |
| 19238 |
|| !tree_fits_uhwi_p (align) |
| 19239 |
|| !integer_pow2p (align))) |
| 19240 |
{ |
| 19241 |
error_at (clause_loc, "%<allocate%> clause %<align%> modifier " |
| 19242 |
"argument needs to be positive constant " |
| 19243 |
"power of two integer expression"); |
| 19244 |
align = NULL_TREE; |
| 19245 |
} |
| 19246 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 19247 |
{ |
| 19248 |
parens.skip_until_found_close (parser); |
| 19249 |
return list; |
| 19250 |
} |
| 19251 |
} |
| 19252 |
|
| 19253 |
nl = c_parser_omp_variable_list (parser, clause_loc, |
| 19254 |
OMP_CLAUSE_ALLOCATE, list); |
| 19255 |
|
| 19256 |
if (allocator || align) |
| 19257 |
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 19258 |
{ |
| 19259 |
OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator; |
| 19260 |
OMP_CLAUSE_ALLOCATE_ALIGN (c) = align; |
| 19261 |
} |
| 19262 |
|
| 19263 |
parens.skip_until_found_close (parser); |
| 19264 |
return nl; |
| 19265 |
} |
| 19266 |
|
| 19267 |
/* OpenMP 4.0: |
| 19268 |
linear ( variable-list ) |
| 19269 |
linear ( variable-list : expression ) |
| 19270 |
|
| 19271 |
OpenMP 4.5: |
| 19272 |
linear ( modifier ( variable-list ) ) |
| 19273 |
linear ( modifier ( variable-list ) : expression ) |
| 19274 |
|
| 19275 |
modifier: |
| 19276 |
val |
| 19277 |
|
| 19278 |
OpenMP 5.2: |
| 19279 |
linear ( variable-list : modifiers-list ) |
| 19280 |
|
| 19281 |
modifiers: |
| 19282 |
val |
| 19283 |
step ( expression ) */ |
| 19284 |
|
| 19285 |
static tree |
| 19286 |
c_parser_omp_clause_linear (c_parser *parser, tree list) |
| 19287 |
{ |
| 19288 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19289 |
tree nl, c, step; |
| 19290 |
enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT; |
| 19291 |
bool old_linear_modifier = false; |
| 19292 |
|
| 19293 |
matching_parens parens; |
| 19294 |
if (!parens.require_open (parser)) |
| 19295 |
return list; |
| 19296 |
|
| 19297 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 19298 |
{ |
| 19299 |
c_token *tok = c_parser_peek_token (parser); |
| 19300 |
const char *p = IDENTIFIER_POINTER (tok->value); |
| 19301 |
if (strcmp ("val", p) == 0) |
| 19302 |
kind = OMP_CLAUSE_LINEAR_VAL; |
| 19303 |
if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN) |
| 19304 |
kind = OMP_CLAUSE_LINEAR_DEFAULT; |
| 19305 |
if (kind != OMP_CLAUSE_LINEAR_DEFAULT) |
| 19306 |
{ |
| 19307 |
old_linear_modifier = true; |
| 19308 |
c_parser_consume_token (parser); |
| 19309 |
c_parser_consume_token (parser); |
| 19310 |
} |
| 19311 |
} |
| 19312 |
|
| 19313 |
nl = c_parser_omp_variable_list (parser, clause_loc, |
| 19314 |
OMP_CLAUSE_LINEAR, list); |
| 19315 |
|
| 19316 |
if (kind != OMP_CLAUSE_LINEAR_DEFAULT) |
| 19317 |
parens.skip_until_found_close (parser); |
| 19318 |
|
| 19319 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 19320 |
{ |
| 19321 |
c_parser_consume_token (parser); |
| 19322 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 19323 |
bool has_modifiers = false; |
| 19324 |
if (kind == OMP_CLAUSE_LINEAR_DEFAULT |
| 19325 |
&& c_parser_next_token_is (parser, CPP_NAME)) |
| 19326 |
{ |
| 19327 |
c_token *tok = c_parser_peek_token (parser); |
| 19328 |
const char *p = IDENTIFIER_POINTER (tok->value); |
| 19329 |
unsigned int pos = 0; |
| 19330 |
if (strcmp ("val", p) == 0) |
| 19331 |
pos = 2; |
| 19332 |
else if (strcmp ("step", p) == 0 |
| 19333 |
&& c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN) |
| 19334 |
{ |
| 19335 |
pos = 3; |
| 19336 |
if (c_parser_check_balanced_raw_token_sequence (parser, &pos) |
| 19337 |
&& (c_parser_peek_nth_token_raw (parser, pos)->type |
| 19338 |
== CPP_CLOSE_PAREN)) |
| 19339 |
++pos; |
| 19340 |
else |
| 19341 |
pos = 0; |
| 19342 |
} |
| 19343 |
if (pos) |
| 19344 |
{ |
| 19345 |
tok = c_parser_peek_nth_token_raw (parser, pos); |
| 19346 |
if (tok->type == CPP_COMMA || tok->type == CPP_CLOSE_PAREN) |
| 19347 |
has_modifiers = true; |
| 19348 |
} |
| 19349 |
} |
| 19350 |
if (has_modifiers) |
| 19351 |
{ |
| 19352 |
step = NULL_TREE; |
| 19353 |
while (c_parser_next_token_is (parser, CPP_NAME)) |
| 19354 |
{ |
| 19355 |
c_token *tok = c_parser_peek_token (parser); |
| 19356 |
const char *p = IDENTIFIER_POINTER (tok->value); |
| 19357 |
if (strcmp ("val", p) == 0) |
| 19358 |
{ |
| 19359 |
if (kind != OMP_CLAUSE_LINEAR_DEFAULT) |
| 19360 |
error_at (tok->location, "multiple linear modifiers"); |
| 19361 |
kind = OMP_CLAUSE_LINEAR_DEFAULT; |
| 19362 |
c_parser_consume_token (parser); |
| 19363 |
} |
| 19364 |
else if (strcmp ("step", p) == 0) |
| 19365 |
{ |
| 19366 |
c_parser_consume_token (parser); |
| 19367 |
matching_parens parens2; |
| 19368 |
if (parens2.require_open (parser)) |
| 19369 |
{ |
| 19370 |
if (step) |
| 19371 |
error_at (tok->location, |
| 19372 |
"multiple %<step%> modifiers"); |
| 19373 |
expr_loc = c_parser_peek_token (parser)->location; |
| 19374 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19375 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, |
| 19376 |
true); |
| 19377 |
step = c_fully_fold (expr.value, false, NULL); |
| 19378 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) |
| 19379 |
{ |
| 19380 |
error_at (clause_loc, "%<linear%> clause step " |
| 19381 |
"expression must be integral"); |
| 19382 |
step = integer_one_node; |
| 19383 |
} |
| 19384 |
parens2.skip_until_found_close (parser); |
| 19385 |
} |
| 19386 |
else |
| 19387 |
break; |
| 19388 |
} |
| 19389 |
else |
| 19390 |
break; |
| 19391 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 19392 |
{ |
| 19393 |
c_parser_consume_token (parser); |
| 19394 |
continue; |
| 19395 |
} |
| 19396 |
break; |
| 19397 |
} |
| 19398 |
if (!step) |
| 19399 |
step = integer_one_node; |
| 19400 |
} |
| 19401 |
else |
| 19402 |
{ |
| 19403 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19404 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 19405 |
step = c_fully_fold (expr.value, false, NULL); |
| 19406 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) |
| 19407 |
{ |
| 19408 |
error_at (clause_loc, "%<linear%> clause step expression must " |
| 19409 |
"be integral"); |
| 19410 |
step = integer_one_node; |
| 19411 |
} |
| 19412 |
} |
| 19413 |
|
| 19414 |
} |
| 19415 |
else |
| 19416 |
step = integer_one_node; |
| 19417 |
|
| 19418 |
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 19419 |
{ |
| 19420 |
OMP_CLAUSE_LINEAR_STEP (c) = step; |
| 19421 |
OMP_CLAUSE_LINEAR_KIND (c) = kind; |
| 19422 |
OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c) = old_linear_modifier; |
| 19423 |
} |
| 19424 |
|
| 19425 |
parens.skip_until_found_close (parser); |
| 19426 |
return nl; |
| 19427 |
} |
| 19428 |
|
| 19429 |
/* OpenMP 5.0: |
| 19430 |
nontemporal ( variable-list ) */ |
| 19431 |
|
| 19432 |
static tree |
| 19433 |
c_parser_omp_clause_nontemporal (c_parser *parser, tree list) |
| 19434 |
{ |
| 19435 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_NONTEMPORAL, list); |
| 19436 |
} |
| 19437 |
|
| 19438 |
/* OpenMP 4.0: |
| 19439 |
safelen ( constant-expression ) */ |
| 19440 |
|
| 19441 |
static tree |
| 19442 |
c_parser_omp_clause_safelen (c_parser *parser, tree list) |
| 19443 |
{ |
| 19444 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19445 |
tree c, t; |
| 19446 |
|
| 19447 |
matching_parens parens; |
| 19448 |
if (!parens.require_open (parser)) |
| 19449 |
return list; |
| 19450 |
|
| 19451 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 19452 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19453 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 19454 |
t = expr.value; |
| 19455 |
t = c_fully_fold (t, false, NULL); |
| 19456 |
if (TREE_CODE (t) != INTEGER_CST |
| 19457 |
|| !INTEGRAL_TYPE_P (TREE_TYPE (t)) |
| 19458 |
|| tree_int_cst_sgn (t) != 1) |
| 19459 |
{ |
| 19460 |
error_at (clause_loc, "%<safelen%> clause expression must " |
| 19461 |
"be positive constant integer expression"); |
| 19462 |
t = NULL_TREE; |
| 19463 |
} |
| 19464 |
|
| 19465 |
parens.skip_until_found_close (parser); |
| 19466 |
if (t == NULL_TREE || t == error_mark_node) |
| 19467 |
return list; |
| 19468 |
|
| 19469 |
check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen"); |
| 19470 |
|
| 19471 |
c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN); |
| 19472 |
OMP_CLAUSE_SAFELEN_EXPR (c) = t; |
| 19473 |
OMP_CLAUSE_CHAIN (c) = list; |
| 19474 |
return c; |
| 19475 |
} |
| 19476 |
|
| 19477 |
/* OpenMP 4.0: |
| 19478 |
simdlen ( constant-expression ) */ |
| 19479 |
|
| 19480 |
static tree |
| 19481 |
c_parser_omp_clause_simdlen (c_parser *parser, tree list) |
| 19482 |
{ |
| 19483 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19484 |
tree c, t; |
| 19485 |
|
| 19486 |
matching_parens parens; |
| 19487 |
if (!parens.require_open (parser)) |
| 19488 |
return list; |
| 19489 |
|
| 19490 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 19491 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19492 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 19493 |
t = expr.value; |
| 19494 |
t = c_fully_fold (t, false, NULL); |
| 19495 |
if (TREE_CODE (t) != INTEGER_CST |
| 19496 |
|| !INTEGRAL_TYPE_P (TREE_TYPE (t)) |
| 19497 |
|| tree_int_cst_sgn (t) != 1) |
| 19498 |
{ |
| 19499 |
error_at (clause_loc, "%<simdlen%> clause expression must " |
| 19500 |
"be positive constant integer expression"); |
| 19501 |
t = NULL_TREE; |
| 19502 |
} |
| 19503 |
|
| 19504 |
parens.skip_until_found_close (parser); |
| 19505 |
if (t == NULL_TREE || t == error_mark_node) |
| 19506 |
return list; |
| 19507 |
|
| 19508 |
check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen"); |
| 19509 |
|
| 19510 |
c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN); |
| 19511 |
OMP_CLAUSE_SIMDLEN_EXPR (c) = t; |
| 19512 |
OMP_CLAUSE_CHAIN (c) = list; |
| 19513 |
return c; |
| 19514 |
} |
| 19515 |
|
| 19516 |
/* OpenMP 4.5: |
| 19517 |
vec: |
| 19518 |
identifier [+/- integer] |
| 19519 |
vec , identifier [+/- integer] |
| 19520 |
*/ |
| 19521 |
|
| 19522 |
static tree |
| 19523 |
c_parser_omp_clause_doacross_sink (c_parser *parser, location_t clause_loc, |
| 19524 |
tree list, bool depend_p) |
| 19525 |
{ |
| 19526 |
tree vec = NULL; |
| 19527 |
if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 19528 |
|| c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 19529 |
{ |
| 19530 |
c_parser_error (parser, "expected identifier"); |
| 19531 |
return list; |
| 19532 |
} |
| 19533 |
|
| 19534 |
if (!depend_p) |
| 19535 |
{ |
| 19536 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 19537 |
if (strcmp (p, "omp_cur_iteration") == 0 |
| 19538 |
&& c_parser_peek_2nd_token (parser)->type == CPP_MINUS |
| 19539 |
&& c_parser_peek_nth_token (parser, 3)->type == CPP_NUMBER |
| 19540 |
&& c_parser_peek_nth_token (parser, 4)->type == CPP_CLOSE_PAREN) |
| 19541 |
{ |
| 19542 |
tree val = c_parser_peek_nth_token (parser, 3)->value; |
| 19543 |
if (integer_onep (val)) |
| 19544 |
{ |
| 19545 |
c_parser_consume_token (parser); |
| 19546 |
c_parser_consume_token (parser); |
| 19547 |
c_parser_consume_token (parser); |
| 19548 |
tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS); |
| 19549 |
OMP_CLAUSE_DOACROSS_KIND (u) = OMP_CLAUSE_DOACROSS_SINK; |
| 19550 |
OMP_CLAUSE_CHAIN (u) = list; |
| 19551 |
return u; |
| 19552 |
} |
| 19553 |
} |
| 19554 |
} |
| 19555 |
|
| 19556 |
|
| 19557 |
|
| 19558 |
while (c_parser_next_token_is (parser, CPP_NAME) |
| 19559 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 19560 |
{ |
| 19561 |
tree t = lookup_name (c_parser_peek_token (parser)->value); |
| 19562 |
tree addend = NULL; |
| 19563 |
|
| 19564 |
if (t == NULL_TREE) |
| 19565 |
{ |
| 19566 |
undeclared_variable (c_parser_peek_token (parser)->location, |
| 19567 |
c_parser_peek_token (parser)->value); |
| 19568 |
t = error_mark_node; |
| 19569 |
} |
| 19570 |
|
| 19571 |
c_parser_consume_token (parser); |
| 19572 |
|
| 19573 |
bool neg = false; |
| 19574 |
if (c_parser_next_token_is (parser, CPP_MINUS)) |
| 19575 |
neg = true; |
| 19576 |
else if (!c_parser_next_token_is (parser, CPP_PLUS)) |
| 19577 |
{ |
| 19578 |
addend = integer_zero_node; |
| 19579 |
neg = false; |
| 19580 |
goto add_to_vector; |
| 19581 |
} |
| 19582 |
c_parser_consume_token (parser); |
| 19583 |
|
| 19584 |
if (c_parser_next_token_is_not (parser, CPP_NUMBER)) |
| 19585 |
{ |
| 19586 |
c_parser_error (parser, "expected integer"); |
| 19587 |
return list; |
| 19588 |
} |
| 19589 |
|
| 19590 |
addend = c_parser_peek_token (parser)->value; |
| 19591 |
if (TREE_CODE (addend) != INTEGER_CST) |
| 19592 |
{ |
| 19593 |
c_parser_error (parser, "expected integer"); |
| 19594 |
return list; |
| 19595 |
} |
| 19596 |
c_parser_consume_token (parser); |
| 19597 |
|
| 19598 |
add_to_vector: |
| 19599 |
if (t != error_mark_node) |
| 19600 |
{ |
| 19601 |
vec = tree_cons (addend, t, vec); |
| 19602 |
if (neg) |
| 19603 |
OMP_CLAUSE_DOACROSS_SINK_NEGATIVE (vec) = 1; |
| 19604 |
} |
| 19605 |
|
| 19606 |
if (c_parser_next_token_is_not (parser, CPP_COMMA) |
| 19607 |
|| c_parser_peek_2nd_token (parser)->type != CPP_NAME |
| 19608 |
|| c_parser_peek_2nd_token (parser)->id_kind != C_ID_ID) |
| 19609 |
break; |
| 19610 |
|
| 19611 |
c_parser_consume_token (parser); |
| 19612 |
} |
| 19613 |
|
| 19614 |
if (vec == NULL_TREE) |
| 19615 |
return list; |
| 19616 |
|
| 19617 |
tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS); |
| 19618 |
OMP_CLAUSE_DOACROSS_KIND (u) = OMP_CLAUSE_DOACROSS_SINK; |
| 19619 |
OMP_CLAUSE_DOACROSS_DEPEND (u) = depend_p; |
| 19620 |
OMP_CLAUSE_DECL (u) = nreverse (vec); |
| 19621 |
OMP_CLAUSE_CHAIN (u) = list; |
| 19622 |
return u; |
| 19623 |
} |
| 19624 |
|
| 19625 |
/* OpenMP 5.0: |
| 19626 |
iterators ( iterators-definition ) |
| 19627 |
|
| 19628 |
iterators-definition: |
| 19629 |
iterator-specifier |
| 19630 |
iterator-specifier , iterators-definition |
| 19631 |
|
| 19632 |
iterator-specifier: |
| 19633 |
identifier = range-specification |
| 19634 |
iterator-type identifier = range-specification |
| 19635 |
|
| 19636 |
range-specification: |
| 19637 |
begin : end |
| 19638 |
begin : end : step */ |
| 19639 |
|
| 19640 |
static tree |
| 19641 |
c_parser_omp_iterators (c_parser *parser) |
| 19642 |
{ |
| 19643 |
tree ret = NULL_TREE, *last = &ret; |
| 19644 |
c_parser_consume_token (parser); |
| 19645 |
|
| 19646 |
push_scope (); |
| 19647 |
|
| 19648 |
matching_parens parens; |
| 19649 |
if (!parens.require_open (parser)) |
| 19650 |
return error_mark_node; |
| 19651 |
|
| 19652 |
do |
| 19653 |
{ |
| 19654 |
tree iter_type = NULL_TREE, type_expr = NULL_TREE; |
| 19655 |
if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
| 19656 |
{ |
| 19657 |
struct c_type_name *type = c_parser_type_name (parser); |
| 19658 |
if (type != NULL) |
| 19659 |
iter_type = groktypename (type, &type_expr, NULL); |
| 19660 |
} |
| 19661 |
if (iter_type == NULL_TREE) |
| 19662 |
iter_type = integer_type_node; |
| 19663 |
|
| 19664 |
location_t loc = c_parser_peek_token (parser)->location; |
| 19665 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 19666 |
{ |
| 19667 |
c_parser_error (parser, "expected identifier"); |
| 19668 |
break; |
| 19669 |
} |
| 19670 |
|
| 19671 |
tree id = c_parser_peek_token (parser)->value; |
| 19672 |
c_parser_consume_token (parser); |
| 19673 |
|
| 19674 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 19675 |
break; |
| 19676 |
|
| 19677 |
location_t eloc = c_parser_peek_token (parser)->location; |
| 19678 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 19679 |
expr = convert_lvalue_to_rvalue (eloc, expr, true, false); |
| 19680 |
tree begin = expr.value; |
| 19681 |
|
| 19682 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 19683 |
break; |
| 19684 |
|
| 19685 |
eloc = c_parser_peek_token (parser)->location; |
| 19686 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 19687 |
expr = convert_lvalue_to_rvalue (eloc, expr, true, false); |
| 19688 |
tree end = expr.value; |
| 19689 |
|
| 19690 |
tree step = integer_one_node; |
| 19691 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 19692 |
{ |
| 19693 |
c_parser_consume_token (parser); |
| 19694 |
eloc = c_parser_peek_token (parser)->location; |
| 19695 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 19696 |
expr = convert_lvalue_to_rvalue (eloc, expr, true, false); |
| 19697 |
step = expr.value; |
| 19698 |
} |
| 19699 |
|
| 19700 |
tree iter_var = build_decl (loc, VAR_DECL, id, iter_type); |
| 19701 |
DECL_ARTIFICIAL (iter_var) = 1; |
| 19702 |
DECL_CONTEXT (iter_var) = current_function_decl; |
| 19703 |
pushdecl (iter_var); |
| 19704 |
|
| 19705 |
*last = make_tree_vec (6); |
| 19706 |
TREE_VEC_ELT (*last, 0) = iter_var; |
| 19707 |
TREE_VEC_ELT (*last, 1) = begin; |
| 19708 |
TREE_VEC_ELT (*last, 2) = end; |
| 19709 |
TREE_VEC_ELT (*last, 3) = step; |
| 19710 |
last = &TREE_CHAIN (*last); |
| 19711 |
|
| 19712 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 19713 |
{ |
| 19714 |
c_parser_consume_token (parser); |
| 19715 |
continue; |
| 19716 |
} |
| 19717 |
break; |
| 19718 |
} |
| 19719 |
while (1); |
| 19720 |
|
| 19721 |
parens.skip_until_found_close (parser); |
| 19722 |
return ret ? ret : error_mark_node; |
| 19723 |
} |
| 19724 |
|
| 19725 |
/* OpenMP 5.0: |
| 19726 |
affinity ( [aff-modifier :] variable-list ) |
| 19727 |
aff-modifier: |
| 19728 |
iterator ( iterators-definition ) */ |
| 19729 |
|
| 19730 |
static tree |
| 19731 |
c_parser_omp_clause_affinity (c_parser *parser, tree list) |
| 19732 |
{ |
| 19733 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19734 |
tree nl, iterators = NULL_TREE; |
| 19735 |
|
| 19736 |
matching_parens parens; |
| 19737 |
if (!parens.require_open (parser)) |
| 19738 |
return list; |
| 19739 |
|
| 19740 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 19741 |
{ |
| 19742 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 19743 |
bool parse_iter = ((strcmp ("iterator", p) == 0) |
| 19744 |
&& (c_parser_peek_2nd_token (parser)->type |
| 19745 |
== CPP_OPEN_PAREN)); |
| 19746 |
if (parse_iter) |
| 19747 |
{ |
| 19748 |
unsigned n = 3; |
| 19749 |
parse_iter = (c_parser_check_balanced_raw_token_sequence (parser, &n) |
| 19750 |
&& (c_parser_peek_nth_token_raw (parser, n)->type |
| 19751 |
== CPP_CLOSE_PAREN) |
| 19752 |
&& (c_parser_peek_nth_token_raw (parser, n + 1)->type |
| 19753 |
== CPP_COLON)); |
| 19754 |
} |
| 19755 |
if (parse_iter) |
| 19756 |
{ |
| 19757 |
iterators = c_parser_omp_iterators (parser); |
| 19758 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 19759 |
{ |
| 19760 |
if (iterators) |
| 19761 |
pop_scope (); |
| 19762 |
parens.skip_until_found_close (parser); |
| 19763 |
return list; |
| 19764 |
} |
| 19765 |
} |
| 19766 |
} |
| 19767 |
nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_AFFINITY, |
| 19768 |
list); |
| 19769 |
if (iterators) |
| 19770 |
{ |
| 19771 |
tree block = pop_scope (); |
| 19772 |
if (iterators != error_mark_node) |
| 19773 |
{ |
| 19774 |
TREE_VEC_ELT (iterators, 5) = block; |
| 19775 |
for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 19776 |
OMP_CLAUSE_DECL (c) = build_tree_list (iterators, |
| 19777 |
OMP_CLAUSE_DECL (c)); |
| 19778 |
} |
| 19779 |
} |
| 19780 |
|
| 19781 |
parens.skip_until_found_close (parser); |
| 19782 |
return nl; |
| 19783 |
} |
| 19784 |
|
| 19785 |
|
| 19786 |
/* OpenMP 4.0: |
| 19787 |
depend ( depend-kind: variable-list ) |
| 19788 |
|
| 19789 |
depend-kind: |
| 19790 |
in | out | inout |
| 19791 |
|
| 19792 |
OpenMP 4.5: |
| 19793 |
depend ( source ) |
| 19794 |
|
| 19795 |
depend ( sink : vec ) |
| 19796 |
|
| 19797 |
OpenMP 5.0: |
| 19798 |
depend ( depend-modifier , depend-kind: variable-list ) |
| 19799 |
|
| 19800 |
depend-kind: |
| 19801 |
in | out | inout | mutexinoutset | depobj | inoutset |
| 19802 |
|
| 19803 |
depend-modifier: |
| 19804 |
iterator ( iterators-definition ) */ |
| 19805 |
|
| 19806 |
static tree |
| 19807 |
c_parser_omp_clause_depend (c_parser *parser, tree list) |
| 19808 |
{ |
| 19809 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19810 |
enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_LAST; |
| 19811 |
enum omp_clause_doacross_kind dkind = OMP_CLAUSE_DOACROSS_LAST; |
| 19812 |
tree nl, c, iterators = NULL_TREE; |
| 19813 |
|
| 19814 |
matching_parens parens; |
| 19815 |
if (!parens.require_open (parser)) |
| 19816 |
return list; |
| 19817 |
|
| 19818 |
do |
| 19819 |
{ |
| 19820 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 19821 |
goto invalid_kind; |
| 19822 |
|
| 19823 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 19824 |
if (strcmp ("iterator", p) == 0 && iterators == NULL_TREE) |
| 19825 |
{ |
| 19826 |
iterators = c_parser_omp_iterators (parser); |
| 19827 |
c_parser_require (parser, CPP_COMMA, "expected %<,%>"); |
| 19828 |
continue; |
| 19829 |
} |
| 19830 |
if (strcmp ("in", p) == 0) |
| 19831 |
kind = OMP_CLAUSE_DEPEND_IN; |
| 19832 |
else if (strcmp ("inout", p) == 0) |
| 19833 |
kind = OMP_CLAUSE_DEPEND_INOUT; |
| 19834 |
else if (strcmp ("inoutset", p) == 0) |
| 19835 |
kind = OMP_CLAUSE_DEPEND_INOUTSET; |
| 19836 |
else if (strcmp ("mutexinoutset", p) == 0) |
| 19837 |
kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET; |
| 19838 |
else if (strcmp ("out", p) == 0) |
| 19839 |
kind = OMP_CLAUSE_DEPEND_OUT; |
| 19840 |
else if (strcmp ("depobj", p) == 0) |
| 19841 |
kind = OMP_CLAUSE_DEPEND_DEPOBJ; |
| 19842 |
else if (strcmp ("sink", p) == 0) |
| 19843 |
dkind = OMP_CLAUSE_DOACROSS_SINK; |
| 19844 |
else if (strcmp ("source", p) == 0) |
| 19845 |
dkind = OMP_CLAUSE_DOACROSS_SOURCE; |
| 19846 |
else |
| 19847 |
goto invalid_kind; |
| 19848 |
break; |
| 19849 |
} |
| 19850 |
while (1); |
| 19851 |
|
| 19852 |
c_parser_consume_token (parser); |
| 19853 |
|
| 19854 |
if (iterators |
| 19855 |
&& (dkind == OMP_CLAUSE_DOACROSS_SOURCE |
| 19856 |
|| dkind == OMP_CLAUSE_DOACROSS_SINK)) |
| 19857 |
{ |
| 19858 |
pop_scope (); |
| 19859 |
error_at (clause_loc, "%<iterator%> modifier incompatible with %qs", |
| 19860 |
dkind == OMP_CLAUSE_DOACROSS_SOURCE ? "source" : "sink"); |
| 19861 |
iterators = NULL_TREE; |
| 19862 |
} |
| 19863 |
|
| 19864 |
if (dkind == OMP_CLAUSE_DOACROSS_SOURCE) |
| 19865 |
{ |
| 19866 |
c = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS); |
| 19867 |
OMP_CLAUSE_DOACROSS_KIND (c) = dkind; |
| 19868 |
OMP_CLAUSE_DOACROSS_DEPEND (c) = 1; |
| 19869 |
OMP_CLAUSE_DECL (c) = NULL_TREE; |
| 19870 |
OMP_CLAUSE_CHAIN (c) = list; |
| 19871 |
parens.skip_until_found_close (parser); |
| 19872 |
return c; |
| 19873 |
} |
| 19874 |
|
| 19875 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 19876 |
goto resync_fail; |
| 19877 |
|
| 19878 |
if (dkind == OMP_CLAUSE_DOACROSS_SINK) |
| 19879 |
nl = c_parser_omp_clause_doacross_sink (parser, clause_loc, list, true); |
| 19880 |
else |
| 19881 |
{ |
| 19882 |
nl = c_parser_omp_variable_list (parser, clause_loc, |
| 19883 |
OMP_CLAUSE_DEPEND, list); |
| 19884 |
|
| 19885 |
if (iterators) |
| 19886 |
{ |
| 19887 |
tree block = pop_scope (); |
| 19888 |
if (iterators == error_mark_node) |
| 19889 |
iterators = NULL_TREE; |
| 19890 |
else |
| 19891 |
TREE_VEC_ELT (iterators, 5) = block; |
| 19892 |
} |
| 19893 |
|
| 19894 |
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 19895 |
{ |
| 19896 |
OMP_CLAUSE_DEPEND_KIND (c) = kind; |
| 19897 |
if (iterators) |
| 19898 |
OMP_CLAUSE_DECL (c) |
| 19899 |
= build_tree_list (iterators, OMP_CLAUSE_DECL (c)); |
| 19900 |
} |
| 19901 |
} |
| 19902 |
|
| 19903 |
parens.skip_until_found_close (parser); |
| 19904 |
return nl; |
| 19905 |
|
| 19906 |
invalid_kind: |
| 19907 |
c_parser_error (parser, "invalid depend kind"); |
| 19908 |
resync_fail: |
| 19909 |
parens.skip_until_found_close (parser); |
| 19910 |
if (iterators) |
| 19911 |
pop_scope (); |
| 19912 |
return list; |
| 19913 |
} |
| 19914 |
|
| 19915 |
/* OpenMP 5.2: |
| 19916 |
doacross ( source : ) |
| 19917 |
doacross ( source : omp_cur_iteration ) |
| 19918 |
|
| 19919 |
doacross ( sink : vec ) |
| 19920 |
doacross ( sink : omp_cur_iteration - logical_iteration ) */ |
| 19921 |
|
| 19922 |
static tree |
| 19923 |
c_parser_omp_clause_doacross (c_parser *parser, tree list) |
| 19924 |
{ |
| 19925 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19926 |
enum omp_clause_doacross_kind kind = OMP_CLAUSE_DOACROSS_LAST; |
| 19927 |
tree nl; |
| 19928 |
const char *p; |
| 19929 |
|
| 19930 |
matching_parens parens; |
| 19931 |
if (!parens.require_open (parser)) |
| 19932 |
return list; |
| 19933 |
|
| 19934 |
if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 19935 |
goto invalid_kind; |
| 19936 |
|
| 19937 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 19938 |
if (strcmp ("sink", p) == 0) |
| 19939 |
kind = OMP_CLAUSE_DOACROSS_SINK; |
| 19940 |
else if (strcmp ("source", p) == 0) |
| 19941 |
kind = OMP_CLAUSE_DOACROSS_SOURCE; |
| 19942 |
else |
| 19943 |
goto invalid_kind; |
| 19944 |
|
| 19945 |
c_parser_consume_token (parser); |
| 19946 |
|
| 19947 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 19948 |
goto resync_fail; |
| 19949 |
|
| 19950 |
if (kind == OMP_CLAUSE_DOACROSS_SOURCE) |
| 19951 |
{ |
| 19952 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 19953 |
&& strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 19954 |
"omp_cur_iteration") == 0) |
| 19955 |
c_parser_consume_token (parser); |
| 19956 |
nl = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS); |
| 19957 |
OMP_CLAUSE_DOACROSS_KIND (nl) = OMP_CLAUSE_DOACROSS_SOURCE; |
| 19958 |
OMP_CLAUSE_DECL (nl) = NULL_TREE; |
| 19959 |
OMP_CLAUSE_CHAIN (nl) = list; |
| 19960 |
} |
| 19961 |
else |
| 19962 |
nl = c_parser_omp_clause_doacross_sink (parser, clause_loc, list, false); |
| 19963 |
|
| 19964 |
parens.skip_until_found_close (parser); |
| 19965 |
return nl; |
| 19966 |
|
| 19967 |
invalid_kind: |
| 19968 |
c_parser_error (parser, "invalid doacross kind"); |
| 19969 |
resync_fail: |
| 19970 |
parens.skip_until_found_close (parser); |
| 19971 |
return list; |
| 19972 |
} |
| 19973 |
|
| 19974 |
/* OpenMP 4.0: |
| 19975 |
map ( map-kind: variable-list ) |
| 19976 |
map ( variable-list ) |
| 19977 |
|
| 19978 |
map-kind: |
| 19979 |
alloc | to | from | tofrom |
| 19980 |
|
| 19981 |
OpenMP 4.5: |
| 19982 |
map-kind: |
| 19983 |
alloc | to | from | tofrom | release | delete |
| 19984 |
|
| 19985 |
map ( always [,] map-kind: variable-list ) |
| 19986 |
|
| 19987 |
OpenMP 5.0: |
| 19988 |
map ( [map-type-modifier[,] ...] map-kind: variable-list ) |
| 19989 |
|
| 19990 |
map-type-modifier: |
| 19991 |
always | close */ |
| 19992 |
|
| 19993 |
static tree |
| 19994 |
c_parser_omp_clause_map (c_parser *parser, tree list) |
| 19995 |
{ |
| 19996 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 19997 |
enum gomp_map_kind kind = GOMP_MAP_TOFROM; |
| 19998 |
tree nl, c; |
| 19999 |
|
| 20000 |
matching_parens parens; |
| 20001 |
if (!parens.require_open (parser)) |
| 20002 |
return list; |
| 20003 |
|
| 20004 |
int pos = 1; |
| 20005 |
int map_kind_pos = 0; |
| 20006 |
while (c_parser_peek_nth_token_raw (parser, pos)->type == CPP_NAME) |
| 20007 |
{ |
| 20008 |
if (c_parser_peek_nth_token_raw (parser, pos + 1)->type == CPP_COLON) |
| 20009 |
{ |
| 20010 |
map_kind_pos = pos; |
| 20011 |
break; |
| 20012 |
} |
| 20013 |
|
| 20014 |
if (c_parser_peek_nth_token_raw (parser, pos + 1)->type == CPP_COMMA) |
| 20015 |
pos++; |
| 20016 |
pos++; |
| 20017 |
} |
| 20018 |
|
| 20019 |
int always_modifier = 0; |
| 20020 |
int close_modifier = 0; |
| 20021 |
int present_modifier = 0; |
| 20022 |
for (int pos = 1; pos < map_kind_pos; ++pos) |
| 20023 |
{ |
| 20024 |
c_token *tok = c_parser_peek_token (parser); |
| 20025 |
|
| 20026 |
if (tok->type == CPP_COMMA) |
| 20027 |
{ |
| 20028 |
c_parser_consume_token (parser); |
| 20029 |
continue; |
| 20030 |
} |
| 20031 |
|
| 20032 |
const char *p = IDENTIFIER_POINTER (tok->value); |
| 20033 |
if (strcmp ("always", p) == 0) |
| 20034 |
{ |
| 20035 |
if (always_modifier) |
| 20036 |
{ |
| 20037 |
c_parser_error (parser, "too many %<always%> modifiers"); |
| 20038 |
parens.skip_until_found_close (parser); |
| 20039 |
return list; |
| 20040 |
} |
| 20041 |
always_modifier++; |
| 20042 |
} |
| 20043 |
else if (strcmp ("close", p) == 0) |
| 20044 |
{ |
| 20045 |
if (close_modifier) |
| 20046 |
{ |
| 20047 |
c_parser_error (parser, "too many %<close%> modifiers"); |
| 20048 |
parens.skip_until_found_close (parser); |
| 20049 |
return list; |
| 20050 |
} |
| 20051 |
close_modifier++; |
| 20052 |
} |
| 20053 |
else if (strcmp ("present", p) == 0) |
| 20054 |
{ |
| 20055 |
if (present_modifier) |
| 20056 |
{ |
| 20057 |
c_parser_error (parser, "too many %<present%> modifiers"); |
| 20058 |
parens.skip_until_found_close (parser); |
| 20059 |
return list; |
| 20060 |
} |
| 20061 |
present_modifier++; |
| 20062 |
} |
| 20063 |
else |
| 20064 |
{ |
| 20065 |
c_parser_error (parser, "%<map%> clause with map-type modifier other " |
| 20066 |
"than %<always%>, %<close%> or %<present%>"); |
| 20067 |
parens.skip_until_found_close (parser); |
| 20068 |
return list; |
| 20069 |
} |
| 20070 |
|
| 20071 |
c_parser_consume_token (parser); |
| 20072 |
} |
| 20073 |
|
| 20074 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 20075 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 20076 |
{ |
| 20077 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 20078 |
int always_present_modifier = always_modifier && present_modifier; |
| 20079 |
|
| 20080 |
if (strcmp ("alloc", p) == 0) |
| 20081 |
kind = present_modifier ? GOMP_MAP_PRESENT_ALLOC : GOMP_MAP_ALLOC; |
| 20082 |
else if (strcmp ("to", p) == 0) |
| 20083 |
kind = (always_present_modifier ? GOMP_MAP_ALWAYS_PRESENT_TO |
| 20084 |
: present_modifier ? GOMP_MAP_PRESENT_TO |
| 20085 |
: always_modifier ? GOMP_MAP_ALWAYS_TO |
| 20086 |
: GOMP_MAP_TO); |
| 20087 |
else if (strcmp ("from", p) == 0) |
| 20088 |
kind = (always_present_modifier ? GOMP_MAP_ALWAYS_PRESENT_FROM |
| 20089 |
: present_modifier ? GOMP_MAP_PRESENT_FROM |
| 20090 |
: always_modifier ? GOMP_MAP_ALWAYS_FROM |
| 20091 |
: GOMP_MAP_FROM); |
| 20092 |
else if (strcmp ("tofrom", p) == 0) |
| 20093 |
kind = (always_present_modifier ? GOMP_MAP_ALWAYS_PRESENT_TOFROM |
| 20094 |
: present_modifier ? GOMP_MAP_PRESENT_TOFROM |
| 20095 |
: always_modifier ? GOMP_MAP_ALWAYS_TOFROM |
| 20096 |
: GOMP_MAP_TOFROM); |
| 20097 |
else if (strcmp ("release", p) == 0) |
| 20098 |
kind = GOMP_MAP_RELEASE; |
| 20099 |
else if (strcmp ("delete", p) == 0) |
| 20100 |
kind = GOMP_MAP_DELETE; |
| 20101 |
else |
| 20102 |
{ |
| 20103 |
c_parser_error (parser, "invalid map kind"); |
| 20104 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 20105 |
"expected %<)%>"); |
| 20106 |
return list; |
| 20107 |
} |
| 20108 |
c_parser_consume_token (parser); |
| 20109 |
c_parser_consume_token (parser); |
| 20110 |
} |
| 20111 |
|
| 20112 |
nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list, |
| 20113 |
true); |
| 20114 |
|
| 20115 |
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 20116 |
OMP_CLAUSE_SET_MAP_KIND (c, kind); |
| 20117 |
|
| 20118 |
parens.skip_until_found_close (parser); |
| 20119 |
return nl; |
| 20120 |
} |
| 20121 |
|
| 20122 |
/* OpenMP 4.0: |
| 20123 |
device ( expression ) |
| 20124 |
|
| 20125 |
OpenMP 5.0: |
| 20126 |
device ( [device-modifier :] integer-expression ) |
| 20127 |
|
| 20128 |
device-modifier: |
| 20129 |
ancestor | device_num */ |
| 20130 |
|
| 20131 |
static tree |
| 20132 |
c_parser_omp_clause_device (c_parser *parser, tree list) |
| 20133 |
{ |
| 20134 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 20135 |
location_t expr_loc; |
| 20136 |
c_expr expr; |
| 20137 |
tree c, t; |
| 20138 |
bool ancestor = false; |
| 20139 |
|
| 20140 |
matching_parens parens; |
| 20141 |
if (!parens.require_open (parser)) |
| 20142 |
return list; |
| 20143 |
|
| 20144 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 20145 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 20146 |
{ |
| 20147 |
c_token *tok = c_parser_peek_token (parser); |
| 20148 |
const char *p = IDENTIFIER_POINTER (tok->value); |
| 20149 |
if (strcmp ("ancestor", p) == 0) |
| 20150 |
{ |
| 20151 |
/* A requires directive with the reverse_offload clause must be |
| 20152 |
specified. */ |
| 20153 |
if ((omp_requires_mask & OMP_REQUIRES_REVERSE_OFFLOAD) == 0) |
| 20154 |
{ |
| 20155 |
error_at (tok->location, "%<ancestor%> device modifier not " |
| 20156 |
"preceded by %<requires%> directive " |
| 20157 |
"with %<reverse_offload%> clause"); |
| 20158 |
parens.skip_until_found_close (parser); |
| 20159 |
return list; |
| 20160 |
} |
| 20161 |
ancestor = true; |
| 20162 |
} |
| 20163 |
else if (strcmp ("device_num", p) == 0) |
| 20164 |
; |
| 20165 |
else |
| 20166 |
{ |
| 20167 |
error_at (tok->location, "expected %<ancestor%> or %<device_num%>"); |
| 20168 |
parens.skip_until_found_close (parser); |
| 20169 |
return list; |
| 20170 |
} |
| 20171 |
c_parser_consume_token (parser); |
| 20172 |
c_parser_consume_token (parser); |
| 20173 |
} |
| 20174 |
|
| 20175 |
expr_loc = c_parser_peek_token (parser)->location; |
| 20176 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 20177 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 20178 |
t = expr.value; |
| 20179 |
t = c_fully_fold (t, false, NULL); |
| 20180 |
|
| 20181 |
parens.skip_until_found_close (parser); |
| 20182 |
|
| 20183 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 20184 |
{ |
| 20185 |
c_parser_error (parser, "expected integer expression"); |
| 20186 |
return list; |
| 20187 |
} |
| 20188 |
if (ancestor && TREE_CODE (t) == INTEGER_CST && !integer_onep (t)) |
| 20189 |
{ |
| 20190 |
error_at (expr_loc, "the %<device%> clause expression must evaluate to " |
| 20191 |
"%<1%>"); |
| 20192 |
return list; |
| 20193 |
} |
| 20194 |
|
| 20195 |
check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device"); |
| 20196 |
|
| 20197 |
c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE); |
| 20198 |
|
| 20199 |
OMP_CLAUSE_DEVICE_ID (c) = t; |
| 20200 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20201 |
OMP_CLAUSE_DEVICE_ANCESTOR (c) = ancestor; |
| 20202 |
|
| 20203 |
list = c; |
| 20204 |
return list; |
| 20205 |
} |
| 20206 |
|
| 20207 |
/* OpenMP 4.0: |
| 20208 |
dist_schedule ( static ) |
| 20209 |
dist_schedule ( static , expression ) */ |
| 20210 |
|
| 20211 |
static tree |
| 20212 |
c_parser_omp_clause_dist_schedule (c_parser *parser, tree list) |
| 20213 |
{ |
| 20214 |
tree c, t = NULL_TREE; |
| 20215 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20216 |
|
| 20217 |
matching_parens parens; |
| 20218 |
if (!parens.require_open (parser)) |
| 20219 |
return list; |
| 20220 |
|
| 20221 |
if (!c_parser_next_token_is_keyword (parser, RID_STATIC)) |
| 20222 |
{ |
| 20223 |
c_parser_error (parser, "invalid dist_schedule kind"); |
| 20224 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 20225 |
"expected %<)%>"); |
| 20226 |
return list; |
| 20227 |
} |
| 20228 |
|
| 20229 |
c_parser_consume_token (parser); |
| 20230 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 20231 |
{ |
| 20232 |
c_parser_consume_token (parser); |
| 20233 |
|
| 20234 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 20235 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 20236 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 20237 |
t = expr.value; |
| 20238 |
t = c_fully_fold (t, false, NULL); |
| 20239 |
parens.skip_until_found_close (parser); |
| 20240 |
} |
| 20241 |
else |
| 20242 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 20243 |
"expected %<,%> or %<)%>"); |
| 20244 |
|
| 20245 |
/* check_no_duplicate_clause (list, OMP_CLAUSE_DIST_SCHEDULE, |
| 20246 |
"dist_schedule"); */ |
| 20247 |
if (omp_find_clause (list, OMP_CLAUSE_DIST_SCHEDULE)) |
| 20248 |
warning_at (loc, OPT_Wopenmp, "too many %qs clauses", "dist_schedule"); |
| 20249 |
if (t == error_mark_node) |
| 20250 |
return list; |
| 20251 |
|
| 20252 |
c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE); |
| 20253 |
OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; |
| 20254 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20255 |
return c; |
| 20256 |
} |
| 20257 |
|
| 20258 |
/* OpenMP 4.0: |
| 20259 |
proc_bind ( proc-bind-kind ) |
| 20260 |
|
| 20261 |
proc-bind-kind: |
| 20262 |
primary | master | close | spread |
| 20263 |
where OpenMP 5.1 added 'primary' and deprecated the alias 'master'. */ |
| 20264 |
|
| 20265 |
static tree |
| 20266 |
c_parser_omp_clause_proc_bind (c_parser *parser, tree list) |
| 20267 |
{ |
| 20268 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 20269 |
enum omp_clause_proc_bind_kind kind; |
| 20270 |
tree c; |
| 20271 |
|
| 20272 |
matching_parens parens; |
| 20273 |
if (!parens.require_open (parser)) |
| 20274 |
return list; |
| 20275 |
|
| 20276 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 20277 |
{ |
| 20278 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 20279 |
if (strcmp ("primary", p) == 0) |
| 20280 |
kind = OMP_CLAUSE_PROC_BIND_PRIMARY; |
| 20281 |
else if (strcmp ("master", p) == 0) |
| 20282 |
kind = OMP_CLAUSE_PROC_BIND_MASTER; |
| 20283 |
else if (strcmp ("close", p) == 0) |
| 20284 |
kind = OMP_CLAUSE_PROC_BIND_CLOSE; |
| 20285 |
else if (strcmp ("spread", p) == 0) |
| 20286 |
kind = OMP_CLAUSE_PROC_BIND_SPREAD; |
| 20287 |
else |
| 20288 |
goto invalid_kind; |
| 20289 |
} |
| 20290 |
else |
| 20291 |
goto invalid_kind; |
| 20292 |
|
| 20293 |
check_no_duplicate_clause (list, OMP_CLAUSE_PROC_BIND, "proc_bind"); |
| 20294 |
c_parser_consume_token (parser); |
| 20295 |
parens.skip_until_found_close (parser); |
| 20296 |
c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND); |
| 20297 |
OMP_CLAUSE_PROC_BIND_KIND (c) = kind; |
| 20298 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20299 |
return c; |
| 20300 |
|
| 20301 |
invalid_kind: |
| 20302 |
c_parser_error (parser, "invalid proc_bind kind"); |
| 20303 |
parens.skip_until_found_close (parser); |
| 20304 |
return list; |
| 20305 |
} |
| 20306 |
|
| 20307 |
/* OpenMP 5.0: |
| 20308 |
device_type ( host | nohost | any ) */ |
| 20309 |
|
| 20310 |
static tree |
| 20311 |
c_parser_omp_clause_device_type (c_parser *parser, tree list) |
| 20312 |
{ |
| 20313 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 20314 |
enum omp_clause_device_type_kind kind; |
| 20315 |
tree c; |
| 20316 |
|
| 20317 |
matching_parens parens; |
| 20318 |
if (!parens.require_open (parser)) |
| 20319 |
return list; |
| 20320 |
|
| 20321 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 20322 |
{ |
| 20323 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 20324 |
if (strcmp ("host", p) == 0) |
| 20325 |
kind = OMP_CLAUSE_DEVICE_TYPE_HOST; |
| 20326 |
else if (strcmp ("nohost", p) == 0) |
| 20327 |
kind = OMP_CLAUSE_DEVICE_TYPE_NOHOST; |
| 20328 |
else if (strcmp ("any", p) == 0) |
| 20329 |
kind = OMP_CLAUSE_DEVICE_TYPE_ANY; |
| 20330 |
else |
| 20331 |
goto invalid_kind; |
| 20332 |
} |
| 20333 |
else |
| 20334 |
goto invalid_kind; |
| 20335 |
|
| 20336 |
check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE_TYPE, |
| 20337 |
"device_type"); |
| 20338 |
c_parser_consume_token (parser); |
| 20339 |
parens.skip_until_found_close (parser); |
| 20340 |
c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE_TYPE); |
| 20341 |
OMP_CLAUSE_DEVICE_TYPE_KIND (c) = kind; |
| 20342 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20343 |
return c; |
| 20344 |
|
| 20345 |
invalid_kind: |
| 20346 |
c_parser_error (parser, "expected %<host%>, %<nohost%> or %<any%>"); |
| 20347 |
parens.skip_until_found_close (parser); |
| 20348 |
return list; |
| 20349 |
} |
| 20350 |
|
| 20351 |
/* OpenMP 4.0: |
| 20352 |
from ( variable-list ) |
| 20353 |
to ( variable-list ) |
| 20354 |
|
| 20355 |
OpenMP 5.1: |
| 20356 |
from ( [present :] variable-list ) |
| 20357 |
to ( [present :] variable-list ) */ |
| 20358 |
|
| 20359 |
static tree |
| 20360 |
c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind, |
| 20361 |
tree list) |
| 20362 |
{ |
| 20363 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20364 |
matching_parens parens; |
| 20365 |
if (!parens.require_open (parser)) |
| 20366 |
return list; |
| 20367 |
|
| 20368 |
bool present = false; |
| 20369 |
c_token *token = c_parser_peek_token (parser); |
| 20370 |
|
| 20371 |
if (token->type == CPP_NAME |
| 20372 |
&& strcmp (IDENTIFIER_POINTER (token->value), "present") == 0 |
| 20373 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 20374 |
{ |
| 20375 |
present = true; |
| 20376 |
c_parser_consume_token (parser); |
| 20377 |
c_parser_consume_token (parser); |
| 20378 |
} |
| 20379 |
|
| 20380 |
tree nl = c_parser_omp_variable_list (parser, loc, kind, list); |
| 20381 |
parens.skip_until_found_close (parser); |
| 20382 |
|
| 20383 |
if (present) |
| 20384 |
for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 20385 |
OMP_CLAUSE_MOTION_PRESENT (c) = 1; |
| 20386 |
|
| 20387 |
return nl; |
| 20388 |
} |
| 20389 |
|
| 20390 |
/* OpenMP 4.0: |
| 20391 |
uniform ( variable-list ) */ |
| 20392 |
|
| 20393 |
static tree |
| 20394 |
c_parser_omp_clause_uniform (c_parser *parser, tree list) |
| 20395 |
{ |
| 20396 |
/* The clauses location. */ |
| 20397 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20398 |
|
| 20399 |
matching_parens parens; |
| 20400 |
if (parens.require_open (parser)) |
| 20401 |
{ |
| 20402 |
list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM, |
| 20403 |
list); |
| 20404 |
parens.skip_until_found_close (parser); |
| 20405 |
} |
| 20406 |
return list; |
| 20407 |
} |
| 20408 |
|
| 20409 |
/* OpenMP 5.1 |
| 20410 |
full */ |
| 20411 |
|
| 20412 |
static tree |
| 20413 |
c_parser_omp_clause_full (c_parser *parser, tree list) |
| 20414 |
{ |
| 20415 |
check_no_duplicate_clause (list, OMP_CLAUSE_FULL, "full"); |
| 20416 |
|
| 20417 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20418 |
tree c = build_omp_clause (loc, OMP_CLAUSE_FULL); |
| 20419 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20420 |
return c; |
| 20421 |
} |
| 20422 |
|
| 20423 |
/* OpenMP 5.1 |
| 20424 |
partial ( constant-expression ) */ |
| 20425 |
|
| 20426 |
static tree |
| 20427 |
c_parser_omp_clause_partial (c_parser *parser, tree list) |
| 20428 |
{ |
| 20429 |
tree num = NULL_TREE; |
| 20430 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20431 |
|
| 20432 |
check_no_duplicate_clause (list, OMP_CLAUSE_PARTIAL, "partial"); |
| 20433 |
|
| 20434 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 20435 |
{ |
| 20436 |
matching_parens parens; |
| 20437 |
parens.consume_open (parser); |
| 20438 |
num = c_parser_expr_no_commas (parser, NULL).value; |
| 20439 |
parens.skip_until_found_close (parser); |
| 20440 |
|
| 20441 |
if (num == error_mark_node) |
| 20442 |
return list; |
| 20443 |
|
| 20444 |
mark_exp_read (num); |
| 20445 |
num = c_fully_fold (num, false, NULL); |
| 20446 |
HOST_WIDE_INT n; |
| 20447 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
| 20448 |
|| !tree_fits_shwi_p (num) |
| 20449 |
|| (n = tree_to_shwi (num)) <= 0 |
| 20450 |
|| (int) n != n) |
| 20451 |
{ |
| 20452 |
error_at (loc, "%<partial%> argument needs positive constant " |
| 20453 |
"integer expression"); |
| 20454 |
return list; |
| 20455 |
} |
| 20456 |
} |
| 20457 |
|
| 20458 |
tree c = build_omp_clause (loc, OMP_CLAUSE_PARTIAL); |
| 20459 |
OMP_CLAUSE_PARTIAL_EXPR (c) = num; |
| 20460 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20461 |
return c; |
| 20462 |
} |
| 20463 |
|
| 20464 |
/* OpenMP 5.1 |
| 20465 |
novariants ( scalar-expression ) */ |
| 20466 |
|
| 20467 |
static tree |
| 20468 |
c_parser_omp_clause_novariants (c_parser *parser, tree list) |
| 20469 |
{ |
| 20470 |
matching_parens parens; |
| 20471 |
if (!parens.require_open (parser)) |
| 20472 |
return list; |
| 20473 |
|
| 20474 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20475 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 20476 |
tree t = convert_lvalue_to_rvalue (loc, expr, true, true).value; |
| 20477 |
t = c_objc_common_truthvalue_conversion (loc, t); |
| 20478 |
t = c_fully_fold (t, false, NULL); |
| 20479 |
parens.skip_until_found_close (parser); |
| 20480 |
|
| 20481 |
check_no_duplicate_clause (list, OMP_CLAUSE_NOVARIANTS, "novariants"); |
| 20482 |
|
| 20483 |
tree c = build_omp_clause (loc, OMP_CLAUSE_NOVARIANTS); |
| 20484 |
OMP_CLAUSE_NOVARIANTS_EXPR (c) = t; |
| 20485 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20486 |
list = c; |
| 20487 |
|
| 20488 |
return list; |
| 20489 |
} |
| 20490 |
|
| 20491 |
/* OpenMP 5.1 |
| 20492 |
nocontext ( scalar-expression ) */ |
| 20493 |
|
| 20494 |
static tree |
| 20495 |
c_parser_omp_clause_nocontext (c_parser *parser, tree list) |
| 20496 |
{ |
| 20497 |
matching_parens parens; |
| 20498 |
if (!parens.require_open (parser)) |
| 20499 |
return list; |
| 20500 |
|
| 20501 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20502 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 20503 |
tree t = convert_lvalue_to_rvalue (loc, expr, true, true).value; |
| 20504 |
t = c_objc_common_truthvalue_conversion (loc, t); |
| 20505 |
t = c_fully_fold (t, false, NULL); |
| 20506 |
parens.skip_until_found_close (parser); |
| 20507 |
|
| 20508 |
check_no_duplicate_clause (list, OMP_CLAUSE_NOCONTEXT, "nocontext"); |
| 20509 |
|
| 20510 |
tree c = build_omp_clause (loc, OMP_CLAUSE_NOCONTEXT); |
| 20511 |
OMP_CLAUSE_NOCONTEXT_EXPR (c) = t; |
| 20512 |
OMP_CLAUSE_CHAIN (c) = list; |
| 20513 |
list = c; |
| 20514 |
|
| 20515 |
return list; |
| 20516 |
} |
| 20517 |
|
| 20518 |
/* OpenMP 5.0: |
| 20519 |
detach ( event-handle ) */ |
| 20520 |
|
| 20521 |
static tree |
| 20522 |
c_parser_omp_clause_detach (c_parser *parser, tree list) |
| 20523 |
{ |
| 20524 |
matching_parens parens; |
| 20525 |
location_t clause_loc = c_parser_peek_token (parser)->location; |
| 20526 |
|
| 20527 |
if (!parens.require_open (parser)) |
| 20528 |
return list; |
| 20529 |
|
| 20530 |
if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 20531 |
|| c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 20532 |
{ |
| 20533 |
c_parser_error (parser, "expected identifier"); |
| 20534 |
parens.skip_until_found_close (parser); |
| 20535 |
return list; |
| 20536 |
} |
| 20537 |
|
| 20538 |
tree t = lookup_name (c_parser_peek_token (parser)->value); |
| 20539 |
if (t == NULL_TREE) |
| 20540 |
{ |
| 20541 |
undeclared_variable (c_parser_peek_token (parser)->location, |
| 20542 |
c_parser_peek_token (parser)->value); |
| 20543 |
parens.skip_until_found_close (parser); |
| 20544 |
return list; |
| 20545 |
} |
| 20546 |
c_parser_consume_token (parser); |
| 20547 |
|
| 20548 |
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t)); |
| 20549 |
if (!INTEGRAL_TYPE_P (type) |
| 20550 |
|| TREE_CODE (type) != ENUMERAL_TYPE |
| 20551 |
|| TYPE_NAME (type) != get_identifier ("omp_event_handle_t")) |
| 20552 |
{ |
| 20553 |
error_at (clause_loc, "%<detach%> clause event handle " |
| 20554 |
"has type %qT rather than " |
| 20555 |
"%<omp_event_handle_t%>", |
| 20556 |
type); |
| 20557 |
parens.skip_until_found_close (parser); |
| 20558 |
return list; |
| 20559 |
} |
| 20560 |
|
| 20561 |
tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DETACH); |
| 20562 |
OMP_CLAUSE_DECL (u) = t; |
| 20563 |
OMP_CLAUSE_CHAIN (u) = list; |
| 20564 |
parens.skip_until_found_close (parser); |
| 20565 |
return u; |
| 20566 |
} |
| 20567 |
|
| 20568 |
/* OpenMP 5.0: |
| 20569 |
destroy ( variable-list ) */ |
| 20570 |
|
| 20571 |
static tree |
| 20572 |
c_parser_omp_clause_destroy (c_parser *parser, tree list) |
| 20573 |
{ |
| 20574 |
tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_DESTROY, list); |
| 20575 |
for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 20576 |
TREE_ADDRESSABLE (OMP_CLAUSE_DECL (c)) = 1; |
| 20577 |
return nl; |
| 20578 |
} |
| 20579 |
|
| 20580 |
/* OpenMP 5.1: |
| 20581 |
prefer_type ( const-int-expr-or-string-literal-list ) |
| 20582 |
|
| 20583 |
OpenMP 6.0: |
| 20584 |
prefer_type ( { preference-selector-list }, { ... } ) |
| 20585 |
|
| 20586 |
with preference-selector being: |
| 20587 |
fr ( identifier-or-string-literal-list ) |
| 20588 |
attr ( string-list ) |
| 20589 |
|
| 20590 |
Data format: |
| 20591 |
For the foreign runtime identifiers, string values are converted to |
| 20592 |
their integer value; unknown string or integer values are set to |
| 20593 |
GOMP_INTEROP_IFR_KNOWN. |
| 20594 |
|
| 20595 |
Each item (a) GOMP_INTEROP_IFR_SEPARATOR |
| 20596 |
(b) for any 'fr', its integer value. |
| 20597 |
Note: Spec only permits 1 'fr' entry (6.0; changed after TR13) |
| 20598 |
(c) GOMP_INTEROP_IFR_SEPARATOR |
| 20599 |
(d) list of \0-terminated non-empty strings for 'attr' |
| 20600 |
(e) '\0' |
| 20601 |
Tailing '\0'. */ |
| 20602 |
|
| 20603 |
static tree |
| 20604 |
c_parser_omp_modifier_prefer_type (c_parser *parser) |
| 20605 |
{ |
| 20606 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 20607 |
return error_mark_node; |
| 20608 |
|
| 20609 |
std::string str; |
| 20610 |
|
| 20611 |
/* Old Format: const-int-expr-or-string-literal-list */ |
| 20612 |
if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 20613 |
while (true) |
| 20614 |
{ |
| 20615 |
str += (char) GOMP_INTEROP_IFR_SEPARATOR; |
| 20616 |
if (c_parser_next_token_is (parser, CPP_STRING)) |
| 20617 |
{ |
| 20618 |
c_expr cval = c_parser_string_literal (parser, false, false); |
| 20619 |
if (cval.value == error_mark_node) |
| 20620 |
return error_mark_node; |
| 20621 |
if ((size_t) TREE_STRING_LENGTH (cval.value) |
| 20622 |
!= strlen (TREE_STRING_POINTER (cval.value)) + 1) |
| 20623 |
{ |
| 20624 |
error_at (cval.get_location (), "string literal must " |
| 20625 |
"not contain %<\\0%>"); |
| 20626 |
parser->error = true; |
| 20627 |
return error_mark_node; |
| 20628 |
} |
| 20629 |
|
| 20630 |
char c = omp_get_fr_id_from_name (TREE_STRING_POINTER (cval.value)); |
| 20631 |
if (c == GOMP_INTEROP_IFR_UNKNOWN) |
| 20632 |
warning_at (cval.get_location (), OPT_Wopenmp, |
| 20633 |
"unknown foreign runtime identifier %qs", |
| 20634 |
TREE_STRING_POINTER (cval.value)); |
| 20635 |
str += c; |
| 20636 |
} |
| 20637 |
else |
| 20638 |
{ |
| 20639 |
c_expr cval = c_parser_expr_no_commas (parser, NULL); |
| 20640 |
tree value = c_fully_fold (cval.value, false, NULL); |
| 20641 |
if (INTEGRAL_TYPE_P (TREE_TYPE (value)) |
| 20642 |
&& TREE_CODE (value) != INTEGER_CST) |
| 20643 |
value = convert_lvalue_to_rvalue (cval.get_start (), cval, |
| 20644 |
false, true).value; |
| 20645 |
if (TREE_CODE (value) != INTEGER_CST |
| 20646 |
|| !tree_fits_shwi_p (value)) |
| 20647 |
{ |
| 20648 |
c_parser_error (parser, "expected string literal or constant " |
| 20649 |
"integer expression"); |
| 20650 |
return error_mark_node; |
| 20651 |
} |
| 20652 |
HOST_WIDE_INT n = tree_to_shwi (value); |
| 20653 |
if (n < 1 || n > GOMP_INTEROP_IFR_LAST) |
| 20654 |
{ |
| 20655 |
warning_at (cval.get_location (), OPT_Wopenmp, |
| 20656 |
"unknown foreign runtime identifier %qwd", n); |
| 20657 |
n = GOMP_INTEROP_IFR_UNKNOWN; |
| 20658 |
} |
| 20659 |
str += (char) n; |
| 20660 |
} |
| 20661 |
str += (char) GOMP_INTEROP_IFR_SEPARATOR; |
| 20662 |
str += '\0'; |
| 20663 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 20664 |
{ |
| 20665 |
c_parser_consume_token (parser); |
| 20666 |
continue; |
| 20667 |
} |
| 20668 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, |
| 20669 |
"expected %<,%> or %<)%>")) |
| 20670 |
return error_mark_node; |
| 20671 |
str += '\0'; |
| 20672 |
tree res = build_string (str.length (), str.data ()); |
| 20673 |
TREE_TYPE (res) = build_array_type_nelts (unsigned_char_type_node, |
| 20674 |
str.length ()); |
| 20675 |
return res; |
| 20676 |
} |
| 20677 |
|
| 20678 |
/* New format. */ |
| 20679 |
std::string str2; |
| 20680 |
while (true) |
| 20681 |
{ |
| 20682 |
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 20683 |
return error_mark_node; |
| 20684 |
str += (char) GOMP_INTEROP_IFR_SEPARATOR; |
| 20685 |
str2.clear (); |
| 20686 |
bool has_fr = false; |
| 20687 |
while (true) |
| 20688 |
{ |
| 20689 |
c_token *tok = c_parser_peek_token (parser); |
| 20690 |
if (tok->type != CPP_NAME |
| 20691 |
|| (strcmp("fr", IDENTIFIER_POINTER (tok->value)) != 0 |
| 20692 |
&& strcmp("attr", IDENTIFIER_POINTER (tok->value)) != 0)) |
| 20693 |
{ |
| 20694 |
c_parser_error (parser, "expected %<fr%> or %<attr%> preference " |
| 20695 |
"selector"); |
| 20696 |
return error_mark_node; |
| 20697 |
} |
| 20698 |
c_parser_consume_token (parser); |
| 20699 |
bool is_fr = IDENTIFIER_POINTER (tok->value)[0] == 'f'; |
| 20700 |
if (is_fr && has_fr) |
| 20701 |
{ |
| 20702 |
c_parser_error (parser, "duplicated %<fr%> preference selector"); |
| 20703 |
return error_mark_node; |
| 20704 |
} |
| 20705 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 20706 |
return error_mark_node; |
| 20707 |
while (true) |
| 20708 |
{ |
| 20709 |
if (c_parser_next_token_is (parser, CPP_STRING)) |
| 20710 |
{ |
| 20711 |
c_expr cval = c_parser_string_literal (parser, false, false); |
| 20712 |
tree value = cval.value; |
| 20713 |
if (value == error_mark_node) |
| 20714 |
return error_mark_node; |
| 20715 |
if ((size_t) TREE_STRING_LENGTH (value) |
| 20716 |
!= strlen (TREE_STRING_POINTER (value)) + 1) |
| 20717 |
{ |
| 20718 |
error_at (cval.get_location (), "string literal must " |
| 20719 |
"not contain %<\\0%>"); |
| 20720 |
parser->error = true; |
| 20721 |
return error_mark_node; |
| 20722 |
} |
| 20723 |
if (!is_fr) |
| 20724 |
{ |
| 20725 |
if (!startswith (TREE_STRING_POINTER (value), "ompx_")) |
| 20726 |
{ |
| 20727 |
error_at (cval.get_location (), |
| 20728 |
"%<attr%> string literal must start with " |
| 20729 |
"%<ompx_%>"); |
| 20730 |
parser->error = true; |
| 20731 |
return error_mark_node; |
| 20732 |
} |
| 20733 |
if (strchr (TREE_STRING_POINTER (value), ',')) |
| 20734 |
{ |
| 20735 |
error_at (cval.get_location (), |
| 20736 |
"%<attr%> string literal must not contain " |
| 20737 |
"a comma"); |
| 20738 |
parser->error = true; |
| 20739 |
return error_mark_node; |
| 20740 |
} |
| 20741 |
str2 += TREE_STRING_POINTER (value); |
| 20742 |
str2 += '\0'; |
| 20743 |
} |
| 20744 |
else |
| 20745 |
{ |
| 20746 |
if (*TREE_STRING_POINTER (value) == '\0') |
| 20747 |
{ |
| 20748 |
c_parser_error (parser, "non-empty string literal expected"); |
| 20749 |
return error_mark_node; |
| 20750 |
} |
| 20751 |
char c = omp_get_fr_id_from_name (TREE_STRING_POINTER (value)); |
| 20752 |
if (c == GOMP_INTEROP_IFR_UNKNOWN) |
| 20753 |
warning_at (cval.get_location (), OPT_Wopenmp, |
| 20754 |
"unknown foreign runtime identifier %qs", |
| 20755 |
TREE_STRING_POINTER (value)); |
| 20756 |
str += c; |
| 20757 |
has_fr = true; |
| 20758 |
} |
| 20759 |
} |
| 20760 |
else if (!is_fr) |
| 20761 |
{ |
| 20762 |
c_parser_error (parser, "expected string literal"); |
| 20763 |
return error_mark_node; |
| 20764 |
} |
| 20765 |
else |
| 20766 |
{ |
| 20767 |
c_expr cval = c_parser_expr_no_commas (parser, NULL); |
| 20768 |
tree value = c_fully_fold (cval.value, false, NULL); |
| 20769 |
if (INTEGRAL_TYPE_P (TREE_TYPE (value)) |
| 20770 |
&& TREE_CODE (value) != INTEGER_CST) |
| 20771 |
value = convert_lvalue_to_rvalue (cval.get_start (), cval, |
| 20772 |
false, true).value; |
| 20773 |
|
| 20774 |
if (TREE_CODE (value) != INTEGER_CST |
| 20775 |
|| !tree_fits_shwi_p (value)) |
| 20776 |
{ |
| 20777 |
c_parser_error (parser, "expected string literal or " |
| 20778 |
"constant integer expression"); |
| 20779 |
return error_mark_node; |
| 20780 |
} |
| 20781 |
HOST_WIDE_INT n = tree_to_shwi (value); |
| 20782 |
if (n < 1 || n > GOMP_INTEROP_IFR_LAST) |
| 20783 |
{ |
| 20784 |
warning_at (cval.get_location (), OPT_Wopenmp, |
| 20785 |
"unknown foreign runtime identifier %qwd", n); |
| 20786 |
n = GOMP_INTEROP_IFR_UNKNOWN; |
| 20787 |
} |
| 20788 |
str += (char) n; |
| 20789 |
has_fr = true; |
| 20790 |
} |
| 20791 |
if (!is_fr |
| 20792 |
&& c_parser_next_token_is (parser, CPP_COMMA)) |
| 20793 |
{ |
| 20794 |
c_parser_consume_token (parser); |
| 20795 |
continue; |
| 20796 |
} |
| 20797 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, |
| 20798 |
is_fr ? G_("expected %<)%>") |
| 20799 |
: G_("expected %<)%> or %<,%>"))) |
| 20800 |
return error_mark_node; |
| 20801 |
break; |
| 20802 |
} |
| 20803 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 20804 |
{ |
| 20805 |
c_parser_consume_token (parser); |
| 20806 |
continue; |
| 20807 |
} |
| 20808 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 20809 |
break; |
| 20810 |
c_parser_error (parser, "expected %<,%> or %<}%>"); |
| 20811 |
return error_mark_node; |
| 20812 |
} |
| 20813 |
str += (char) GOMP_INTEROP_IFR_SEPARATOR; |
| 20814 |
str += str2; |
| 20815 |
str += '\0'; |
| 20816 |
c_parser_consume_token (parser); |
| 20817 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 20818 |
break; |
| 20819 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<)%> or %<,%>")) |
| 20820 |
return error_mark_node; |
| 20821 |
} |
| 20822 |
c_parser_consume_token (parser); |
| 20823 |
str += '\0'; |
| 20824 |
tree res = build_string (str.length (), str.data ()); |
| 20825 |
TREE_TYPE (res) = build_array_type_nelts (unsigned_char_type_node, |
| 20826 |
str.length ()); |
| 20827 |
return res; |
| 20828 |
} |
| 20829 |
|
| 20830 |
/* OpenMP 5.1 |
| 20831 |
modifiers of the 'init' clause, used by the 'init' and the |
| 20832 |
'append_args' clauses. |
| 20833 |
|
| 20834 |
Modifiers: |
| 20835 |
target |
| 20836 |
targetsync |
| 20837 |
prefer_type (preference-specification) |
| 20838 |
|
| 20839 |
Returns 'false' if an error has been issued. */ |
| 20840 |
|
| 20841 |
static bool |
| 20842 |
c_parser_omp_clause_init_modifiers (c_parser *parser, bool *target, |
| 20843 |
bool *targetsync, tree *prefer_type_tree) |
| 20844 |
{ |
| 20845 |
*target = false; |
| 20846 |
*targetsync = false; |
| 20847 |
*prefer_type_tree = NULL_TREE; |
| 20848 |
|
| 20849 |
do |
| 20850 |
{ |
| 20851 |
c_token *tok = c_parser_peek_token (parser); |
| 20852 |
if (tok->type != CPP_NAME) |
| 20853 |
goto fail; |
| 20854 |
const char *p = IDENTIFIER_POINTER (tok->value); |
| 20855 |
if (strcmp ("targetsync", p) == 0) |
| 20856 |
{ |
| 20857 |
if (*targetsync) |
| 20858 |
error_at (tok->location, "duplicate %<targetsync%> modifier"); |
| 20859 |
*targetsync = true; |
| 20860 |
c_parser_consume_token (parser); |
| 20861 |
} |
| 20862 |
else if (strcmp ("target", p) == 0) |
| 20863 |
{ |
| 20864 |
if (*target) |
| 20865 |
error_at (tok->location, "duplicate %<target%> modifier"); |
| 20866 |
*target = true; |
| 20867 |
c_parser_consume_token (parser); |
| 20868 |
} |
| 20869 |
else if (strcmp ("prefer_type", p) == 0) |
| 20870 |
{ |
| 20871 |
if (*prefer_type_tree != NULL_TREE) |
| 20872 |
error_at (tok->location, "duplicate %<prefer_type%> modifier"); |
| 20873 |
c_parser_consume_token (parser); |
| 20874 |
*prefer_type_tree = c_parser_omp_modifier_prefer_type (parser); |
| 20875 |
if (*prefer_type_tree == error_mark_node) |
| 20876 |
return false; |
| 20877 |
} |
| 20878 |
else |
| 20879 |
goto fail; |
| 20880 |
tok = c_parser_peek_token (parser); |
| 20881 |
if (tok->type == CPP_COMMA) |
| 20882 |
{ |
| 20883 |
c_parser_consume_token (parser); |
| 20884 |
continue; |
| 20885 |
} |
| 20886 |
/* Unknown token - either done or an error; handle it in the caller. */ |
| 20887 |
return true; |
| 20888 |
} |
| 20889 |
while (true); |
| 20890 |
|
| 20891 |
fail: |
| 20892 |
c_parser_error (parser, |
| 20893 |
"expected %<prefer_type%>, %<target%>, or %<targetsync%>"); |
| 20894 |
return false; |
| 20895 |
} |
| 20896 |
|
| 20897 |
/* OpenMP 5.1: |
| 20898 |
init ( [init-modifier-list : ] variable-list ) |
| 20899 |
|
| 20900 |
Modifiers: |
| 20901 |
target |
| 20902 |
targetsync |
| 20903 |
prefer_type (preference-specification) */ |
| 20904 |
|
| 20905 |
static tree |
| 20906 |
c_parser_omp_clause_init (c_parser *parser, tree list) |
| 20907 |
{ |
| 20908 |
location_t loc = c_parser_peek_token (parser)->location; |
| 20909 |
|
| 20910 |
matching_parens parens; |
| 20911 |
if (!parens.require_open (parser)) |
| 20912 |
return list; |
| 20913 |
|
| 20914 |
bool target = false; |
| 20915 |
bool targetsync = false; |
| 20916 |
tree prefer_type_tree = NULL_TREE; |
| 20917 |
|
| 20918 |
if (!c_parser_omp_clause_init_modifiers (parser, &target, &targetsync, |
| 20919 |
&prefer_type_tree) |
| 20920 |
|| !c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 20921 |
{ |
| 20922 |
if (prefer_type_tree != error_mark_node) |
| 20923 |
parens.skip_until_found_close (parser); |
| 20924 |
return list; |
| 20925 |
} |
| 20926 |
|
| 20927 |
if (!target && !targetsync) |
| 20928 |
error_at (loc, |
| 20929 |
"missing required %<target%> and/or %<targetsync%> modifier"); |
| 20930 |
|
| 20931 |
tree nl = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_INIT, list, |
| 20932 |
false); |
| 20933 |
parens.skip_until_found_close (parser); |
| 20934 |
|
| 20935 |
for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 20936 |
{ |
| 20937 |
TREE_ADDRESSABLE (OMP_CLAUSE_DECL (c)) = 1; |
| 20938 |
if (target) |
| 20939 |
OMP_CLAUSE_INIT_TARGET (c) = 1; |
| 20940 |
if (targetsync) |
| 20941 |
OMP_CLAUSE_INIT_TARGETSYNC (c) = 1; |
| 20942 |
if (prefer_type_tree) |
| 20943 |
OMP_CLAUSE_INIT_PREFER_TYPE (c) = prefer_type_tree; |
| 20944 |
} |
| 20945 |
return nl; |
| 20946 |
} |
| 20947 |
|
| 20948 |
/* OpenMP 5.0: |
| 20949 |
use ( variable-list ) */ |
| 20950 |
|
| 20951 |
static tree |
| 20952 |
c_parser_omp_clause_use (c_parser *parser, tree list) |
| 20953 |
{ |
| 20954 |
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE, list); |
| 20955 |
} |
| 20956 |
|
| 20957 |
/* OpenMP 6.0: |
| 20958 |
interop ( variable-list ) */ |
| 20959 |
|
| 20960 |
static tree |
| 20961 |
c_parser_omp_clause_interop (c_parser *parser, tree list) |
| 20962 |
{ |
| 20963 |
check_no_duplicate_clause (list, OMP_CLAUSE_INTEROP, "interop"); |
| 20964 |
tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_INTEROP, list); |
| 20965 |
for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 20966 |
{ |
| 20967 |
TREE_USED (OMP_CLAUSE_DECL (c)) = 1; |
| 20968 |
DECL_READ_P (OMP_CLAUSE_DECL (c)) = 1; |
| 20969 |
} |
| 20970 |
return nl; |
| 20971 |
} |
| 20972 |
|
| 20973 |
/* Parse all OpenACC clauses. The set clauses allowed by the directive |
| 20974 |
is a bitmask in MASK. Return the list of clauses found. */ |
| 20975 |
|
| 20976 |
static tree |
| 20977 |
c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, |
| 20978 |
const char *where, bool finish_p = true, |
| 20979 |
bool target_p = false) |
| 20980 |
{ |
| 20981 |
tree clauses = NULL; |
| 20982 |
bool first = true; |
| 20983 |
|
| 20984 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 20985 |
{ |
| 20986 |
location_t here; |
| 20987 |
pragma_omp_clause c_kind; |
| 20988 |
const char *c_name; |
| 20989 |
tree prev = clauses; |
| 20990 |
|
| 20991 |
if (!first && c_parser_next_token_is (parser, CPP_COMMA)) |
| 20992 |
c_parser_consume_token (parser); |
| 20993 |
|
| 20994 |
here = c_parser_peek_token (parser)->location; |
| 20995 |
c_kind = c_parser_omp_clause_name (parser); |
| 20996 |
|
| 20997 |
switch (c_kind) |
| 20998 |
{ |
| 20999 |
case PRAGMA_OACC_CLAUSE_ASYNC: |
| 21000 |
clauses = c_parser_oacc_clause_async (parser, clauses); |
| 21001 |
c_name = "async"; |
| 21002 |
break; |
| 21003 |
case PRAGMA_OACC_CLAUSE_AUTO: |
| 21004 |
clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_AUTO, |
| 21005 |
clauses); |
| 21006 |
c_name = "auto"; |
| 21007 |
break; |
| 21008 |
case PRAGMA_OACC_CLAUSE_ATTACH: |
| 21009 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21010 |
c_name = "attach"; |
| 21011 |
break; |
| 21012 |
case PRAGMA_OACC_CLAUSE_COLLAPSE: |
| 21013 |
clauses = c_parser_omp_clause_collapse (parser, clauses); |
| 21014 |
c_name = "collapse"; |
| 21015 |
break; |
| 21016 |
case PRAGMA_OACC_CLAUSE_COPY: |
| 21017 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21018 |
c_name = "copy"; |
| 21019 |
break; |
| 21020 |
case PRAGMA_OACC_CLAUSE_COPYIN: |
| 21021 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21022 |
c_name = "copyin"; |
| 21023 |
break; |
| 21024 |
case PRAGMA_OACC_CLAUSE_COPYOUT: |
| 21025 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21026 |
c_name = "copyout"; |
| 21027 |
break; |
| 21028 |
case PRAGMA_OACC_CLAUSE_CREATE: |
| 21029 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21030 |
c_name = "create"; |
| 21031 |
break; |
| 21032 |
case PRAGMA_OACC_CLAUSE_DELETE: |
| 21033 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21034 |
c_name = "delete"; |
| 21035 |
break; |
| 21036 |
case PRAGMA_OMP_CLAUSE_DEFAULT: |
| 21037 |
clauses = c_parser_omp_clause_default (parser, clauses, true); |
| 21038 |
c_name = "default"; |
| 21039 |
break; |
| 21040 |
case PRAGMA_OACC_CLAUSE_DETACH: |
| 21041 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21042 |
c_name = "detach"; |
| 21043 |
break; |
| 21044 |
case PRAGMA_OACC_CLAUSE_DEVICE: |
| 21045 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21046 |
c_name = "device"; |
| 21047 |
break; |
| 21048 |
case PRAGMA_OACC_CLAUSE_DEVICEPTR: |
| 21049 |
clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses); |
| 21050 |
c_name = "deviceptr"; |
| 21051 |
break; |
| 21052 |
case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT: |
| 21053 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21054 |
c_name = "device_resident"; |
| 21055 |
break; |
| 21056 |
case PRAGMA_OACC_CLAUSE_FINALIZE: |
| 21057 |
clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_FINALIZE, |
| 21058 |
clauses); |
| 21059 |
c_name = "finalize"; |
| 21060 |
break; |
| 21061 |
case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE: |
| 21062 |
clauses = c_parser_omp_clause_firstprivate (parser, clauses); |
| 21063 |
c_name = "firstprivate"; |
| 21064 |
break; |
| 21065 |
case PRAGMA_OACC_CLAUSE_GANG: |
| 21066 |
c_name = "gang"; |
| 21067 |
clauses = c_parser_oacc_shape_clause (parser, here, OMP_CLAUSE_GANG, |
| 21068 |
c_name, clauses); |
| 21069 |
break; |
| 21070 |
case PRAGMA_OACC_CLAUSE_HOST: |
| 21071 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21072 |
c_name = "host"; |
| 21073 |
break; |
| 21074 |
case PRAGMA_OACC_CLAUSE_IF: |
| 21075 |
clauses = c_parser_omp_clause_if (parser, clauses, false); |
| 21076 |
c_name = "if"; |
| 21077 |
break; |
| 21078 |
case PRAGMA_OACC_CLAUSE_IF_PRESENT: |
| 21079 |
clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_IF_PRESENT, |
| 21080 |
clauses); |
| 21081 |
c_name = "if_present"; |
| 21082 |
break; |
| 21083 |
case PRAGMA_OACC_CLAUSE_INDEPENDENT: |
| 21084 |
clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_INDEPENDENT, |
| 21085 |
clauses); |
| 21086 |
c_name = "independent"; |
| 21087 |
break; |
| 21088 |
case PRAGMA_OACC_CLAUSE_LINK: |
| 21089 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21090 |
c_name = "link"; |
| 21091 |
break; |
| 21092 |
case PRAGMA_OACC_CLAUSE_NO_CREATE: |
| 21093 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21094 |
c_name = "no_create"; |
| 21095 |
break; |
| 21096 |
case PRAGMA_OACC_CLAUSE_NOHOST: |
| 21097 |
clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_NOHOST, |
| 21098 |
clauses); |
| 21099 |
c_name = "nohost"; |
| 21100 |
break; |
| 21101 |
case PRAGMA_OACC_CLAUSE_NUM_GANGS: |
| 21102 |
clauses = c_parser_oacc_single_int_clause (parser, |
| 21103 |
OMP_CLAUSE_NUM_GANGS, |
| 21104 |
clauses); |
| 21105 |
c_name = "num_gangs"; |
| 21106 |
break; |
| 21107 |
case PRAGMA_OACC_CLAUSE_NUM_WORKERS: |
| 21108 |
clauses = c_parser_oacc_single_int_clause (parser, |
| 21109 |
OMP_CLAUSE_NUM_WORKERS, |
| 21110 |
clauses); |
| 21111 |
c_name = "num_workers"; |
| 21112 |
break; |
| 21113 |
case PRAGMA_OACC_CLAUSE_PRESENT: |
| 21114 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21115 |
c_name = "present"; |
| 21116 |
break; |
| 21117 |
case PRAGMA_OACC_CLAUSE_PRIVATE: |
| 21118 |
clauses = c_parser_omp_clause_private (parser, clauses); |
| 21119 |
c_name = "private"; |
| 21120 |
break; |
| 21121 |
case PRAGMA_OACC_CLAUSE_REDUCTION: |
| 21122 |
clauses |
| 21123 |
= c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION, |
| 21124 |
false, clauses); |
| 21125 |
c_name = "reduction"; |
| 21126 |
break; |
| 21127 |
case PRAGMA_OACC_CLAUSE_SELF: |
| 21128 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)) == 0) |
| 21129 |
/* OpenACC compute construct */ |
| 21130 |
clauses = c_parser_oacc_compute_clause_self (parser, clauses); |
| 21131 |
else |
| 21132 |
/* OpenACC 'update' directive */ |
| 21133 |
clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 21134 |
c_name = "self"; |
| 21135 |
break; |
| 21136 |
case PRAGMA_OACC_CLAUSE_SEQ: |
| 21137 |
clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_SEQ, |
| 21138 |
clauses); |
| 21139 |
c_name = "seq"; |
| 21140 |
break; |
| 21141 |
case PRAGMA_OACC_CLAUSE_TILE: |
| 21142 |
clauses = c_parser_oacc_clause_tile (parser, clauses); |
| 21143 |
c_name = "tile"; |
| 21144 |
break; |
| 21145 |
case PRAGMA_OACC_CLAUSE_USE_DEVICE: |
| 21146 |
clauses = c_parser_omp_clause_use_device_ptr (parser, clauses); |
| 21147 |
c_name = "use_device"; |
| 21148 |
break; |
| 21149 |
case PRAGMA_OACC_CLAUSE_VECTOR: |
| 21150 |
c_name = "vector"; |
| 21151 |
clauses = c_parser_oacc_shape_clause (parser, here, OMP_CLAUSE_VECTOR, |
| 21152 |
c_name, clauses); |
| 21153 |
break; |
| 21154 |
case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH: |
| 21155 |
clauses = c_parser_oacc_single_int_clause (parser, |
| 21156 |
OMP_CLAUSE_VECTOR_LENGTH, |
| 21157 |
clauses); |
| 21158 |
c_name = "vector_length"; |
| 21159 |
break; |
| 21160 |
case PRAGMA_OACC_CLAUSE_WAIT: |
| 21161 |
clauses = c_parser_oacc_clause_wait (parser, clauses); |
| 21162 |
c_name = "wait"; |
| 21163 |
break; |
| 21164 |
case PRAGMA_OACC_CLAUSE_WORKER: |
| 21165 |
c_name = "worker"; |
| 21166 |
clauses = c_parser_oacc_shape_clause (parser, here, OMP_CLAUSE_WORKER, |
| 21167 |
c_name, clauses); |
| 21168 |
break; |
| 21169 |
default: |
| 21170 |
c_parser_error (parser, "expected an OpenACC clause"); |
| 21171 |
goto saw_error; |
| 21172 |
} |
| 21173 |
|
| 21174 |
first = false; |
| 21175 |
|
| 21176 |
if (((mask >> c_kind) & 1) == 0) |
| 21177 |
{ |
| 21178 |
/* Remove the invalid clause(s) from the list to avoid |
| 21179 |
confusing the rest of the compiler. */ |
| 21180 |
clauses = prev; |
| 21181 |
error_at (here, "%qs is not valid for %qs", c_name, where); |
| 21182 |
} |
| 21183 |
} |
| 21184 |
|
| 21185 |
saw_error: |
| 21186 |
c_parser_skip_to_pragma_eol (parser); |
| 21187 |
|
| 21188 |
if (finish_p) |
| 21189 |
return c_finish_omp_clauses (clauses, target_p ? C_ORT_ACC_TARGET |
| 21190 |
: C_ORT_ACC); |
| 21191 |
|
| 21192 |
return clauses; |
| 21193 |
} |
| 21194 |
|
| 21195 |
/* Parse all OpenMP clauses. The set clauses allowed by the directive |
| 21196 |
is a bitmask in MASK. Return the list of clauses found. |
| 21197 |
FINISH_P set if c_finish_omp_clauses should be called. |
| 21198 |
NESTED non-zero if clauses should be terminated by closing paren instead |
| 21199 |
of end of pragma. If it is 2, additionally commas are required in between |
| 21200 |
the clauses. */ |
| 21201 |
|
| 21202 |
static tree |
| 21203 |
c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, |
| 21204 |
const char *where, bool finish_p = true, |
| 21205 |
int nested = 0) |
| 21206 |
{ |
| 21207 |
tree clauses = NULL; |
| 21208 |
bool first = true; |
| 21209 |
|
| 21210 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 21211 |
{ |
| 21212 |
location_t here; |
| 21213 |
pragma_omp_clause c_kind; |
| 21214 |
const char *c_name; |
| 21215 |
tree prev = clauses; |
| 21216 |
|
| 21217 |
if (nested && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 21218 |
break; |
| 21219 |
|
| 21220 |
if (!first || nested != 2) |
| 21221 |
{ |
| 21222 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 21223 |
c_parser_consume_token (parser); |
| 21224 |
else if (nested == 2) |
| 21225 |
error_at (c_parser_peek_token (parser)->location, |
| 21226 |
"clauses in %<simd%> trait should be separated " |
| 21227 |
"by %<,%>"); |
| 21228 |
} |
| 21229 |
|
| 21230 |
here = c_parser_peek_token (parser)->location; |
| 21231 |
c_kind = c_parser_omp_clause_name (parser); |
| 21232 |
|
| 21233 |
switch (c_kind) |
| 21234 |
{ |
| 21235 |
case PRAGMA_OMP_CLAUSE_BIND: |
| 21236 |
clauses = c_parser_omp_clause_bind (parser, clauses); |
| 21237 |
c_name = "bind"; |
| 21238 |
break; |
| 21239 |
case PRAGMA_OMP_CLAUSE_COLLAPSE: |
| 21240 |
clauses = c_parser_omp_clause_collapse (parser, clauses); |
| 21241 |
c_name = "collapse"; |
| 21242 |
break; |
| 21243 |
case PRAGMA_OMP_CLAUSE_COPYIN: |
| 21244 |
clauses = c_parser_omp_clause_copyin (parser, clauses); |
| 21245 |
c_name = "copyin"; |
| 21246 |
break; |
| 21247 |
case PRAGMA_OMP_CLAUSE_COPYPRIVATE: |
| 21248 |
clauses = c_parser_omp_clause_copyprivate (parser, clauses); |
| 21249 |
c_name = "copyprivate"; |
| 21250 |
break; |
| 21251 |
case PRAGMA_OMP_CLAUSE_DEFAULT: |
| 21252 |
clauses = c_parser_omp_clause_default (parser, clauses, false); |
| 21253 |
c_name = "default"; |
| 21254 |
break; |
| 21255 |
case PRAGMA_OMP_CLAUSE_DETACH: |
| 21256 |
clauses = c_parser_omp_clause_detach (parser, clauses); |
| 21257 |
c_name = "detach"; |
| 21258 |
break; |
| 21259 |
case PRAGMA_OMP_CLAUSE_FILTER: |
| 21260 |
clauses = c_parser_omp_clause_filter (parser, clauses); |
| 21261 |
c_name = "filter"; |
| 21262 |
break; |
| 21263 |
case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: |
| 21264 |
clauses = c_parser_omp_clause_firstprivate (parser, clauses); |
| 21265 |
c_name = "firstprivate"; |
| 21266 |
break; |
| 21267 |
case PRAGMA_OMP_CLAUSE_FINAL: |
| 21268 |
clauses = c_parser_omp_clause_final (parser, clauses); |
| 21269 |
c_name = "final"; |
| 21270 |
break; |
| 21271 |
case PRAGMA_OMP_CLAUSE_GRAINSIZE: |
| 21272 |
clauses = c_parser_omp_clause_grainsize (parser, clauses); |
| 21273 |
c_name = "grainsize"; |
| 21274 |
break; |
| 21275 |
case PRAGMA_OMP_CLAUSE_HINT: |
| 21276 |
clauses = c_parser_omp_clause_hint (parser, clauses); |
| 21277 |
c_name = "hint"; |
| 21278 |
break; |
| 21279 |
case PRAGMA_OMP_CLAUSE_DEFAULTMAP: |
| 21280 |
clauses = c_parser_omp_clause_defaultmap (parser, clauses); |
| 21281 |
c_name = "defaultmap"; |
| 21282 |
break; |
| 21283 |
case PRAGMA_OMP_CLAUSE_IF: |
| 21284 |
clauses = c_parser_omp_clause_if (parser, clauses, true); |
| 21285 |
c_name = "if"; |
| 21286 |
break; |
| 21287 |
case PRAGMA_OMP_CLAUSE_IN_REDUCTION: |
| 21288 |
clauses |
| 21289 |
= c_parser_omp_clause_reduction (parser, OMP_CLAUSE_IN_REDUCTION, |
| 21290 |
true, clauses); |
| 21291 |
c_name = "in_reduction"; |
| 21292 |
break; |
| 21293 |
case PRAGMA_OMP_CLAUSE_INDIRECT: |
| 21294 |
clauses = c_parser_omp_clause_indirect (parser, clauses); |
| 21295 |
c_name = "indirect"; |
| 21296 |
break; |
| 21297 |
case PRAGMA_OMP_CLAUSE_LASTPRIVATE: |
| 21298 |
clauses = c_parser_omp_clause_lastprivate (parser, clauses); |
| 21299 |
c_name = "lastprivate"; |
| 21300 |
break; |
| 21301 |
case PRAGMA_OMP_CLAUSE_MERGEABLE: |
| 21302 |
clauses = c_parser_omp_clause_mergeable (parser, clauses); |
| 21303 |
c_name = "mergeable"; |
| 21304 |
break; |
| 21305 |
case PRAGMA_OMP_CLAUSE_NOWAIT: |
| 21306 |
clauses = c_parser_omp_clause_nowait (parser, clauses); |
| 21307 |
c_name = "nowait"; |
| 21308 |
break; |
| 21309 |
case PRAGMA_OMP_CLAUSE_NUM_TASKS: |
| 21310 |
clauses = c_parser_omp_clause_num_tasks (parser, clauses); |
| 21311 |
c_name = "num_tasks"; |
| 21312 |
break; |
| 21313 |
case PRAGMA_OMP_CLAUSE_NUM_THREADS: |
| 21314 |
clauses = c_parser_omp_clause_num_threads (parser, clauses); |
| 21315 |
c_name = "num_threads"; |
| 21316 |
break; |
| 21317 |
case PRAGMA_OMP_CLAUSE_ORDER: |
| 21318 |
clauses = c_parser_omp_clause_order (parser, clauses); |
| 21319 |
c_name = "order"; |
| 21320 |
break; |
| 21321 |
case PRAGMA_OMP_CLAUSE_ORDERED: |
| 21322 |
clauses = c_parser_omp_clause_ordered (parser, clauses); |
| 21323 |
c_name = "ordered"; |
| 21324 |
break; |
| 21325 |
case PRAGMA_OMP_CLAUSE_PRIORITY: |
| 21326 |
clauses = c_parser_omp_clause_priority (parser, clauses); |
| 21327 |
c_name = "priority"; |
| 21328 |
break; |
| 21329 |
case PRAGMA_OMP_CLAUSE_PRIVATE: |
| 21330 |
clauses = c_parser_omp_clause_private (parser, clauses); |
| 21331 |
c_name = "private"; |
| 21332 |
break; |
| 21333 |
case PRAGMA_OMP_CLAUSE_REDUCTION: |
| 21334 |
clauses |
| 21335 |
= c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION, |
| 21336 |
true, clauses); |
| 21337 |
c_name = "reduction"; |
| 21338 |
break; |
| 21339 |
case PRAGMA_OMP_CLAUSE_SCHEDULE: |
| 21340 |
clauses = c_parser_omp_clause_schedule (parser, clauses); |
| 21341 |
c_name = "schedule"; |
| 21342 |
break; |
| 21343 |
case PRAGMA_OMP_CLAUSE_SHARED: |
| 21344 |
clauses = c_parser_omp_clause_shared (parser, clauses); |
| 21345 |
c_name = "shared"; |
| 21346 |
break; |
| 21347 |
case PRAGMA_OMP_CLAUSE_TASK_REDUCTION: |
| 21348 |
clauses |
| 21349 |
= c_parser_omp_clause_reduction (parser, OMP_CLAUSE_TASK_REDUCTION, |
| 21350 |
true, clauses); |
| 21351 |
c_name = "task_reduction"; |
| 21352 |
break; |
| 21353 |
case PRAGMA_OMP_CLAUSE_UNTIED: |
| 21354 |
clauses = c_parser_omp_clause_untied (parser, clauses); |
| 21355 |
c_name = "untied"; |
| 21356 |
break; |
| 21357 |
case PRAGMA_OMP_CLAUSE_INBRANCH: |
| 21358 |
clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH, |
| 21359 |
clauses); |
| 21360 |
c_name = "inbranch"; |
| 21361 |
break; |
| 21362 |
case PRAGMA_OMP_CLAUSE_NONTEMPORAL: |
| 21363 |
clauses = c_parser_omp_clause_nontemporal (parser, clauses); |
| 21364 |
c_name = "nontemporal"; |
| 21365 |
break; |
| 21366 |
case PRAGMA_OMP_CLAUSE_NOTINBRANCH: |
| 21367 |
clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, |
| 21368 |
clauses); |
| 21369 |
c_name = "notinbranch"; |
| 21370 |
break; |
| 21371 |
case PRAGMA_OMP_CLAUSE_PARALLEL: |
| 21372 |
clauses |
| 21373 |
= c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL, |
| 21374 |
clauses); |
| 21375 |
c_name = "parallel"; |
| 21376 |
if (!first) |
| 21377 |
{ |
| 21378 |
clause_not_first: |
| 21379 |
error_at (here, "%qs must be the first clause of %qs", |
| 21380 |
c_name, where); |
| 21381 |
clauses = prev; |
| 21382 |
} |
| 21383 |
break; |
| 21384 |
case PRAGMA_OMP_CLAUSE_FOR: |
| 21385 |
clauses |
| 21386 |
= c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR, |
| 21387 |
clauses); |
| 21388 |
c_name = "for"; |
| 21389 |
if (!first) |
| 21390 |
goto clause_not_first; |
| 21391 |
break; |
| 21392 |
case PRAGMA_OMP_CLAUSE_SECTIONS: |
| 21393 |
clauses |
| 21394 |
= c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS, |
| 21395 |
clauses); |
| 21396 |
c_name = "sections"; |
| 21397 |
if (!first) |
| 21398 |
goto clause_not_first; |
| 21399 |
break; |
| 21400 |
case PRAGMA_OMP_CLAUSE_TASKGROUP: |
| 21401 |
clauses |
| 21402 |
= c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP, |
| 21403 |
clauses); |
| 21404 |
c_name = "taskgroup"; |
| 21405 |
if (!first) |
| 21406 |
goto clause_not_first; |
| 21407 |
break; |
| 21408 |
case PRAGMA_OMP_CLAUSE_LINK: |
| 21409 |
clauses |
| 21410 |
= c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses); |
| 21411 |
c_name = "link"; |
| 21412 |
break; |
| 21413 |
case PRAGMA_OMP_CLAUSE_TO: |
| 21414 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0) |
| 21415 |
{ |
| 21416 |
tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER, |
| 21417 |
clauses); |
| 21418 |
for (tree c = nl; c != clauses; c = OMP_CLAUSE_CHAIN (c)) |
| 21419 |
OMP_CLAUSE_ENTER_TO (c) = 1; |
| 21420 |
clauses = nl; |
| 21421 |
} |
| 21422 |
else |
| 21423 |
clauses = c_parser_omp_clause_from_to (parser, OMP_CLAUSE_TO, |
| 21424 |
clauses); |
| 21425 |
c_name = "to"; |
| 21426 |
break; |
| 21427 |
case PRAGMA_OMP_CLAUSE_FROM: |
| 21428 |
clauses = c_parser_omp_clause_from_to (parser, OMP_CLAUSE_FROM, |
| 21429 |
clauses); |
| 21430 |
c_name = "from"; |
| 21431 |
break; |
| 21432 |
case PRAGMA_OMP_CLAUSE_UNIFORM: |
| 21433 |
clauses = c_parser_omp_clause_uniform (parser, clauses); |
| 21434 |
c_name = "uniform"; |
| 21435 |
break; |
| 21436 |
case PRAGMA_OMP_CLAUSE_NUM_TEAMS: |
| 21437 |
clauses = c_parser_omp_clause_num_teams (parser, clauses); |
| 21438 |
c_name = "num_teams"; |
| 21439 |
break; |
| 21440 |
case PRAGMA_OMP_CLAUSE_THREAD_LIMIT: |
| 21441 |
clauses = c_parser_omp_clause_thread_limit (parser, clauses); |
| 21442 |
c_name = "thread_limit"; |
| 21443 |
break; |
| 21444 |
case PRAGMA_OMP_CLAUSE_ALIGNED: |
| 21445 |
clauses = c_parser_omp_clause_aligned (parser, clauses); |
| 21446 |
c_name = "aligned"; |
| 21447 |
break; |
| 21448 |
case PRAGMA_OMP_CLAUSE_ALLOCATE: |
| 21449 |
clauses = c_parser_omp_clause_allocate (parser, clauses); |
| 21450 |
c_name = "allocate"; |
| 21451 |
break; |
| 21452 |
case PRAGMA_OMP_CLAUSE_LINEAR: |
| 21453 |
clauses = c_parser_omp_clause_linear (parser, clauses); |
| 21454 |
c_name = "linear"; |
| 21455 |
break; |
| 21456 |
case PRAGMA_OMP_CLAUSE_AFFINITY: |
| 21457 |
clauses = c_parser_omp_clause_affinity (parser, clauses); |
| 21458 |
c_name = "affinity"; |
| 21459 |
break; |
| 21460 |
case PRAGMA_OMP_CLAUSE_DEPEND: |
| 21461 |
clauses = c_parser_omp_clause_depend (parser, clauses); |
| 21462 |
c_name = "depend"; |
| 21463 |
break; |
| 21464 |
case PRAGMA_OMP_CLAUSE_DOACROSS: |
| 21465 |
clauses = c_parser_omp_clause_doacross (parser, clauses); |
| 21466 |
c_name = "doacross"; |
| 21467 |
break; |
| 21468 |
case PRAGMA_OMP_CLAUSE_DESTROY: |
| 21469 |
clauses = c_parser_omp_clause_destroy (parser, clauses); |
| 21470 |
c_name = "destroy"; |
| 21471 |
break; |
| 21472 |
case PRAGMA_OMP_CLAUSE_INIT: |
| 21473 |
clauses = c_parser_omp_clause_init (parser, clauses); |
| 21474 |
c_name = "init"; |
| 21475 |
break; |
| 21476 |
case PRAGMA_OMP_CLAUSE_USE: |
| 21477 |
clauses = c_parser_omp_clause_use (parser, clauses); |
| 21478 |
c_name = "use"; |
| 21479 |
break; |
| 21480 |
case PRAGMA_OMP_CLAUSE_INTEROP: |
| 21481 |
clauses = c_parser_omp_clause_interop (parser, clauses); |
| 21482 |
c_name = "interop"; |
| 21483 |
break; |
| 21484 |
case PRAGMA_OMP_CLAUSE_MAP: |
| 21485 |
clauses = c_parser_omp_clause_map (parser, clauses); |
| 21486 |
c_name = "map"; |
| 21487 |
break; |
| 21488 |
case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR: |
| 21489 |
clauses = c_parser_omp_clause_use_device_ptr (parser, clauses); |
| 21490 |
c_name = "use_device_ptr"; |
| 21491 |
break; |
| 21492 |
case PRAGMA_OMP_CLAUSE_USE_DEVICE_ADDR: |
| 21493 |
clauses = c_parser_omp_clause_use_device_addr (parser, clauses); |
| 21494 |
c_name = "use_device_addr"; |
| 21495 |
break; |
| 21496 |
case PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR: |
| 21497 |
clauses = c_parser_omp_clause_has_device_addr (parser, clauses); |
| 21498 |
c_name = "has_device_addr"; |
| 21499 |
break; |
| 21500 |
case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR: |
| 21501 |
clauses = c_parser_omp_clause_is_device_ptr (parser, clauses); |
| 21502 |
c_name = "is_device_ptr"; |
| 21503 |
break; |
| 21504 |
case PRAGMA_OMP_CLAUSE_DEVICE: |
| 21505 |
clauses = c_parser_omp_clause_device (parser, clauses); |
| 21506 |
c_name = "device"; |
| 21507 |
break; |
| 21508 |
case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE: |
| 21509 |
clauses = c_parser_omp_clause_dist_schedule (parser, clauses); |
| 21510 |
c_name = "dist_schedule"; |
| 21511 |
break; |
| 21512 |
case PRAGMA_OMP_CLAUSE_PROC_BIND: |
| 21513 |
clauses = c_parser_omp_clause_proc_bind (parser, clauses); |
| 21514 |
c_name = "proc_bind"; |
| 21515 |
break; |
| 21516 |
case PRAGMA_OMP_CLAUSE_DEVICE_TYPE: |
| 21517 |
clauses = c_parser_omp_clause_device_type (parser, clauses); |
| 21518 |
c_name = "device_type"; |
| 21519 |
break; |
| 21520 |
case PRAGMA_OMP_CLAUSE_SAFELEN: |
| 21521 |
clauses = c_parser_omp_clause_safelen (parser, clauses); |
| 21522 |
c_name = "safelen"; |
| 21523 |
break; |
| 21524 |
case PRAGMA_OMP_CLAUSE_SIMDLEN: |
| 21525 |
clauses = c_parser_omp_clause_simdlen (parser, clauses); |
| 21526 |
c_name = "simdlen"; |
| 21527 |
break; |
| 21528 |
case PRAGMA_OMP_CLAUSE_NOGROUP: |
| 21529 |
clauses = c_parser_omp_clause_nogroup (parser, clauses); |
| 21530 |
c_name = "nogroup"; |
| 21531 |
break; |
| 21532 |
case PRAGMA_OMP_CLAUSE_THREADS: |
| 21533 |
clauses |
| 21534 |
= c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS, |
| 21535 |
clauses); |
| 21536 |
c_name = "threads"; |
| 21537 |
break; |
| 21538 |
case PRAGMA_OMP_CLAUSE_SIMD: |
| 21539 |
clauses |
| 21540 |
= c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD, |
| 21541 |
clauses); |
| 21542 |
c_name = "simd"; |
| 21543 |
break; |
| 21544 |
case PRAGMA_OMP_CLAUSE_ENTER: |
| 21545 |
clauses |
| 21546 |
= c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER, |
| 21547 |
clauses); |
| 21548 |
c_name = "enter"; |
| 21549 |
break; |
| 21550 |
case PRAGMA_OMP_CLAUSE_FULL: |
| 21551 |
c_name = "full"; |
| 21552 |
clauses = c_parser_omp_clause_full (parser, clauses); |
| 21553 |
break; |
| 21554 |
case PRAGMA_OMP_CLAUSE_PARTIAL: |
| 21555 |
c_name = "partial"; |
| 21556 |
clauses = c_parser_omp_clause_partial (parser, clauses); |
| 21557 |
break; |
| 21558 |
case PRAGMA_OMP_CLAUSE_NOVARIANTS: |
| 21559 |
c_name = "novariants"; |
| 21560 |
clauses = c_parser_omp_clause_novariants (parser, clauses); |
| 21561 |
break; |
| 21562 |
case PRAGMA_OMP_CLAUSE_NOCONTEXT: |
| 21563 |
c_name = "nocontext"; |
| 21564 |
clauses = c_parser_omp_clause_nocontext (parser, clauses); |
| 21565 |
break; |
| 21566 |
default: |
| 21567 |
c_parser_error (parser, "expected an OpenMP clause"); |
| 21568 |
goto saw_error; |
| 21569 |
} |
| 21570 |
|
| 21571 |
first = false; |
| 21572 |
|
| 21573 |
if (((mask >> c_kind) & 1) == 0) |
| 21574 |
{ |
| 21575 |
/* Remove the invalid clause(s) from the list to avoid |
| 21576 |
confusing the rest of the compiler. */ |
| 21577 |
clauses = prev; |
| 21578 |
error_at (here, "%qs is not valid for %qs", c_name, where); |
| 21579 |
} |
| 21580 |
} |
| 21581 |
|
| 21582 |
saw_error: |
| 21583 |
if (!nested) |
| 21584 |
c_parser_skip_to_pragma_eol (parser); |
| 21585 |
|
| 21586 |
if (finish_p) |
| 21587 |
{ |
| 21588 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0) |
| 21589 |
return c_finish_omp_clauses (clauses, C_ORT_OMP_DECLARE_SIMD); |
| 21590 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE)) != 0) |
| 21591 |
return c_finish_omp_clauses (clauses, C_ORT_OMP_INTEROP); |
| 21592 |
return c_finish_omp_clauses (clauses, C_ORT_OMP); |
| 21593 |
} |
| 21594 |
|
| 21595 |
return clauses; |
| 21596 |
} |
| 21597 |
|
| 21598 |
/* OpenACC 2.0, OpenMP 2.5: |
| 21599 |
structured-block: |
| 21600 |
statement |
| 21601 |
|
| 21602 |
In practice, we're also interested in adding the statement to an |
| 21603 |
outer node. So it is convenient if we work around the fact that |
| 21604 |
c_parser_statement calls add_stmt. */ |
| 21605 |
|
| 21606 |
static tree |
| 21607 |
c_parser_omp_structured_block (c_parser *parser, bool *if_p) |
| 21608 |
{ |
| 21609 |
tree stmt = push_stmt_list (); |
| 21610 |
parser->omp_attrs_forbidden_p = true; |
| 21611 |
c_parser_statement (parser, if_p); |
| 21612 |
return pop_stmt_list (stmt); |
| 21613 |
} |
| 21614 |
|
| 21615 |
/* OpenACC 2.0: |
| 21616 |
# pragma acc cache (variable-list) new-line |
| 21617 |
|
| 21618 |
OpenACC 2.7: |
| 21619 |
# pragma acc cache (readonly: variable-list) new-line |
| 21620 |
|
| 21621 |
LOC is the location of the #pragma token. |
| 21622 |
*/ |
| 21623 |
|
| 21624 |
static tree |
| 21625 |
c_parser_oacc_cache (location_t loc, c_parser *parser) |
| 21626 |
{ |
| 21627 |
tree stmt, clauses = NULL_TREE; |
| 21628 |
bool readonly = false; |
| 21629 |
location_t open_loc = c_parser_peek_token (parser)->location; |
| 21630 |
matching_parens parens; |
| 21631 |
if (parens.require_open (parser)) |
| 21632 |
{ |
| 21633 |
c_token *token = c_parser_peek_token (parser); |
| 21634 |
if (token->type == CPP_NAME |
| 21635 |
&& !strcmp (IDENTIFIER_POINTER (token->value), "readonly") |
| 21636 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 21637 |
{ |
| 21638 |
c_parser_consume_token (parser); |
| 21639 |
c_parser_consume_token (parser); |
| 21640 |
readonly = true; |
| 21641 |
} |
| 21642 |
clauses = c_parser_omp_variable_list (parser, open_loc, |
| 21643 |
OMP_CLAUSE__CACHE_, NULL_TREE); |
| 21644 |
parens.skip_until_found_close (parser); |
| 21645 |
} |
| 21646 |
|
| 21647 |
if (readonly) |
| 21648 |
for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) |
| 21649 |
OMP_CLAUSE__CACHE__READONLY (c) = 1; |
| 21650 |
|
| 21651 |
clauses = c_finish_omp_clauses (clauses, C_ORT_ACC); |
| 21652 |
|
| 21653 |
c_parser_skip_to_pragma_eol (parser); |
| 21654 |
|
| 21655 |
stmt = make_node (OACC_CACHE); |
| 21656 |
TREE_TYPE (stmt) = void_type_node; |
| 21657 |
OACC_CACHE_CLAUSES (stmt) = clauses; |
| 21658 |
SET_EXPR_LOCATION (stmt, loc); |
| 21659 |
add_stmt (stmt); |
| 21660 |
|
| 21661 |
return stmt; |
| 21662 |
} |
| 21663 |
|
| 21664 |
/* OpenACC 2.0: |
| 21665 |
# pragma acc data oacc-data-clause[optseq] new-line |
| 21666 |
structured-block |
| 21667 |
|
| 21668 |
LOC is the location of the #pragma token. |
| 21669 |
*/ |
| 21670 |
|
| 21671 |
#define OACC_DATA_CLAUSE_MASK \ |
| 21672 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \ |
| 21673 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 21674 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 21675 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 21676 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 21677 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ |
| 21678 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 21679 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 21680 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \ |
| 21681 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)) |
| 21682 |
|
| 21683 |
static tree |
| 21684 |
c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p) |
| 21685 |
{ |
| 21686 |
tree stmt, clauses, block; |
| 21687 |
|
| 21688 |
clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK, |
| 21689 |
"#pragma acc data"); |
| 21690 |
|
| 21691 |
block = c_begin_omp_parallel (); |
| 21692 |
add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 21693 |
|
| 21694 |
stmt = c_finish_oacc_data (loc, clauses, block); |
| 21695 |
|
| 21696 |
return stmt; |
| 21697 |
} |
| 21698 |
|
| 21699 |
/* OpenACC 2.0: |
| 21700 |
# pragma acc declare oacc-data-clause[optseq] new-line |
| 21701 |
*/ |
| 21702 |
|
| 21703 |
#define OACC_DECLARE_CLAUSE_MASK \ |
| 21704 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 21705 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 21706 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 21707 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 21708 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 21709 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \ |
| 21710 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \ |
| 21711 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)) |
| 21712 |
|
| 21713 |
static void |
| 21714 |
c_parser_oacc_declare (c_parser *parser) |
| 21715 |
{ |
| 21716 |
location_t pragma_loc = c_parser_peek_token (parser)->location; |
| 21717 |
tree clauses, stmt, t, decl; |
| 21718 |
|
| 21719 |
bool error = false; |
| 21720 |
|
| 21721 |
c_parser_consume_pragma (parser); |
| 21722 |
|
| 21723 |
clauses = c_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK, |
| 21724 |
"#pragma acc declare"); |
| 21725 |
if (!clauses) |
| 21726 |
{ |
| 21727 |
error_at (pragma_loc, |
| 21728 |
"no valid clauses specified in %<#pragma acc declare%>"); |
| 21729 |
return; |
| 21730 |
} |
| 21731 |
|
| 21732 |
for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t)) |
| 21733 |
{ |
| 21734 |
location_t loc = OMP_CLAUSE_LOCATION (t); |
| 21735 |
decl = OMP_CLAUSE_DECL (t); |
| 21736 |
if (!DECL_P (decl)) |
| 21737 |
{ |
| 21738 |
error_at (loc, "array section in %<#pragma acc declare%>"); |
| 21739 |
error = true; |
| 21740 |
continue; |
| 21741 |
} |
| 21742 |
|
| 21743 |
switch (OMP_CLAUSE_MAP_KIND (t)) |
| 21744 |
{ |
| 21745 |
case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 21746 |
case GOMP_MAP_ALLOC: |
| 21747 |
case GOMP_MAP_TO: |
| 21748 |
case GOMP_MAP_FORCE_DEVICEPTR: |
| 21749 |
case GOMP_MAP_DEVICE_RESIDENT: |
| 21750 |
break; |
| 21751 |
|
| 21752 |
case GOMP_MAP_LINK: |
| 21753 |
if (!global_bindings_p () |
| 21754 |
&& (TREE_STATIC (decl) |
| 21755 |
|| !DECL_EXTERNAL (decl))) |
| 21756 |
{ |
| 21757 |
error_at (loc, |
| 21758 |
"%qD must be a global variable in " |
| 21759 |
"%<#pragma acc declare link%>", |
| 21760 |
decl); |
| 21761 |
error = true; |
| 21762 |
continue; |
| 21763 |
} |
| 21764 |
break; |
| 21765 |
|
| 21766 |
default: |
| 21767 |
if (global_bindings_p ()) |
| 21768 |
{ |
| 21769 |
error_at (loc, "invalid OpenACC clause at file scope"); |
| 21770 |
error = true; |
| 21771 |
continue; |
| 21772 |
} |
| 21773 |
if (DECL_EXTERNAL (decl)) |
| 21774 |
{ |
| 21775 |
error_at (loc, |
| 21776 |
"invalid use of %<extern%> variable %qD " |
| 21777 |
"in %<#pragma acc declare%>", decl); |
| 21778 |
error = true; |
| 21779 |
continue; |
| 21780 |
} |
| 21781 |
else if (TREE_PUBLIC (decl)) |
| 21782 |
{ |
| 21783 |
error_at (loc, |
| 21784 |
"invalid use of %<global%> variable %qD " |
| 21785 |
"in %<#pragma acc declare%>", decl); |
| 21786 |
error = true; |
| 21787 |
continue; |
| 21788 |
} |
| 21789 |
break; |
| 21790 |
} |
| 21791 |
|
| 21792 |
if (!c_check_in_current_scope (decl)) |
| 21793 |
{ |
| 21794 |
error_at (loc, |
| 21795 |
"%qD must be a variable declared in the same scope as " |
| 21796 |
"%<#pragma acc declare%>", decl); |
| 21797 |
error = true; |
| 21798 |
continue; |
| 21799 |
} |
| 21800 |
|
| 21801 |
if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)) |
| 21802 |
|| lookup_attribute ("omp declare target link", |
| 21803 |
DECL_ATTRIBUTES (decl))) |
| 21804 |
{ |
| 21805 |
error_at (loc, "variable %qD used more than once with " |
| 21806 |
"%<#pragma acc declare%>", decl); |
| 21807 |
error = true; |
| 21808 |
continue; |
| 21809 |
} |
| 21810 |
|
| 21811 |
if (!error) |
| 21812 |
{ |
| 21813 |
tree id; |
| 21814 |
|
| 21815 |
if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK) |
| 21816 |
id = get_identifier ("omp declare target link"); |
| 21817 |
else |
| 21818 |
id = get_identifier ("omp declare target"); |
| 21819 |
|
| 21820 |
DECL_ATTRIBUTES (decl) |
| 21821 |
= tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl)); |
| 21822 |
|
| 21823 |
if (global_bindings_p ()) |
| 21824 |
{ |
| 21825 |
symtab_node *node = symtab_node::get (decl); |
| 21826 |
if (node != NULL) |
| 21827 |
{ |
| 21828 |
node->offloadable = 1; |
| 21829 |
if (ENABLE_OFFLOADING) |
| 21830 |
{ |
| 21831 |
g->have_offload = true; |
| 21832 |
if (is_a <varpool_node *> (node)) |
| 21833 |
vec_safe_push (offload_vars, decl); |
| 21834 |
} |
| 21835 |
} |
| 21836 |
} |
| 21837 |
} |
| 21838 |
} |
| 21839 |
|
| 21840 |
if (error || global_bindings_p ()) |
| 21841 |
return; |
| 21842 |
|
| 21843 |
stmt = make_node (OACC_DECLARE); |
| 21844 |
TREE_TYPE (stmt) = void_type_node; |
| 21845 |
OACC_DECLARE_CLAUSES (stmt) = clauses; |
| 21846 |
SET_EXPR_LOCATION (stmt, pragma_loc); |
| 21847 |
|
| 21848 |
add_stmt (stmt); |
| 21849 |
|
| 21850 |
return; |
| 21851 |
} |
| 21852 |
|
| 21853 |
/* OpenACC 2.0: |
| 21854 |
# pragma acc enter data oacc-enter-data-clause[optseq] new-line |
| 21855 |
|
| 21856 |
or |
| 21857 |
|
| 21858 |
# pragma acc exit data oacc-exit-data-clause[optseq] new-line |
| 21859 |
|
| 21860 |
|
| 21861 |
LOC is the location of the #pragma token. |
| 21862 |
*/ |
| 21863 |
|
| 21864 |
#define OACC_ENTER_DATA_CLAUSE_MASK \ |
| 21865 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 21866 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 21867 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \ |
| 21868 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 21869 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 21870 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 21871 |
|
| 21872 |
#define OACC_EXIT_DATA_CLAUSE_MASK \ |
| 21873 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 21874 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 21875 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 21876 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \ |
| 21877 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DETACH) \ |
| 21878 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FINALIZE) \ |
| 21879 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 21880 |
|
| 21881 |
static void |
| 21882 |
c_parser_oacc_enter_exit_data (c_parser *parser, bool enter) |
| 21883 |
{ |
| 21884 |
location_t loc = c_parser_peek_token (parser)->location; |
| 21885 |
tree clauses, stmt; |
| 21886 |
const char *p = ""; |
| 21887 |
|
| 21888 |
c_parser_consume_pragma (parser); |
| 21889 |
|
| 21890 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 21891 |
{ |
| 21892 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 21893 |
c_parser_consume_token (parser); |
| 21894 |
} |
| 21895 |
|
| 21896 |
if (strcmp (p, "data") != 0) |
| 21897 |
{ |
| 21898 |
error_at (loc, "expected %<data%> after %<#pragma acc %s%>", |
| 21899 |
enter ? "enter" : "exit"); |
| 21900 |
parser->error = true; |
| 21901 |
c_parser_skip_to_pragma_eol (parser); |
| 21902 |
return; |
| 21903 |
} |
| 21904 |
|
| 21905 |
if (enter) |
| 21906 |
clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK, |
| 21907 |
"#pragma acc enter data"); |
| 21908 |
else |
| 21909 |
clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK, |
| 21910 |
"#pragma acc exit data"); |
| 21911 |
|
| 21912 |
if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) |
| 21913 |
{ |
| 21914 |
error_at (loc, "%<#pragma acc %s data%> has no data movement clause", |
| 21915 |
enter ? "enter" : "exit"); |
| 21916 |
return; |
| 21917 |
} |
| 21918 |
|
| 21919 |
stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA); |
| 21920 |
TREE_TYPE (stmt) = void_type_node; |
| 21921 |
OMP_STANDALONE_CLAUSES (stmt) = clauses; |
| 21922 |
SET_EXPR_LOCATION (stmt, loc); |
| 21923 |
add_stmt (stmt); |
| 21924 |
} |
| 21925 |
|
| 21926 |
|
| 21927 |
/* OpenACC 2.0: |
| 21928 |
# pragma acc host_data oacc-data-clause[optseq] new-line |
| 21929 |
structured-block |
| 21930 |
*/ |
| 21931 |
|
| 21932 |
#define OACC_HOST_DATA_CLAUSE_MASK \ |
| 21933 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) \ |
| 21934 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 21935 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) ) |
| 21936 |
|
| 21937 |
static tree |
| 21938 |
c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p) |
| 21939 |
{ |
| 21940 |
tree stmt, clauses, block; |
| 21941 |
|
| 21942 |
clauses = c_parser_oacc_all_clauses (parser, OACC_HOST_DATA_CLAUSE_MASK, |
| 21943 |
"#pragma acc host_data", false); |
| 21944 |
if (!omp_find_clause (clauses, OMP_CLAUSE_USE_DEVICE_PTR)) |
| 21945 |
{ |
| 21946 |
error_at (loc, "%<host_data%> construct requires %<use_device%> clause"); |
| 21947 |
return error_mark_node; |
| 21948 |
} |
| 21949 |
clauses = c_finish_omp_clauses (clauses, C_ORT_ACC); |
| 21950 |
block = c_begin_omp_parallel (); |
| 21951 |
add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 21952 |
stmt = c_finish_oacc_host_data (loc, clauses, block); |
| 21953 |
return stmt; |
| 21954 |
} |
| 21955 |
|
| 21956 |
|
| 21957 |
/* OpenACC 2.0: |
| 21958 |
|
| 21959 |
# pragma acc loop oacc-loop-clause[optseq] new-line |
| 21960 |
structured-block |
| 21961 |
|
| 21962 |
LOC is the location of the #pragma token. |
| 21963 |
*/ |
| 21964 |
|
| 21965 |
#define OACC_LOOP_CLAUSE_MASK \ |
| 21966 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \ |
| 21967 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ |
| 21968 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ |
| 21969 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \ |
| 21970 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \ |
| 21971 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \ |
| 21972 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \ |
| 21973 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \ |
| 21974 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \ |
| 21975 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) ) |
| 21976 |
static tree |
| 21977 |
c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, |
| 21978 |
omp_clause_mask mask, tree *cclauses, bool *if_p) |
| 21979 |
{ |
| 21980 |
bool is_parallel = ((mask >> PRAGMA_OACC_CLAUSE_REDUCTION) & 1) == 1; |
| 21981 |
|
| 21982 |
strcat (p_name, " loop"); |
| 21983 |
mask |= OACC_LOOP_CLAUSE_MASK; |
| 21984 |
|
| 21985 |
tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name, |
| 21986 |
/*finish_p=*/cclauses == NULL, |
| 21987 |
/*target=*/is_parallel); |
| 21988 |
if (cclauses) |
| 21989 |
{ |
| 21990 |
clauses = c_oacc_split_loop_clauses (clauses, cclauses, is_parallel); |
| 21991 |
if (*cclauses) |
| 21992 |
*cclauses = c_finish_omp_clauses (*cclauses, C_ORT_ACC_TARGET); |
| 21993 |
if (clauses) |
| 21994 |
clauses = c_finish_omp_clauses (clauses, C_ORT_ACC); |
| 21995 |
} |
| 21996 |
|
| 21997 |
tree block = c_begin_compound_stmt (true); |
| 21998 |
tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL, |
| 21999 |
if_p); |
| 22000 |
block = c_end_compound_stmt (loc, block, true); |
| 22001 |
add_stmt (block); |
| 22002 |
|
| 22003 |
return stmt; |
| 22004 |
} |
| 22005 |
|
| 22006 |
/* OpenACC 2.0: |
| 22007 |
# pragma acc kernels oacc-kernels-clause[optseq] new-line |
| 22008 |
structured-block |
| 22009 |
|
| 22010 |
or |
| 22011 |
|
| 22012 |
# pragma acc parallel oacc-parallel-clause[optseq] new-line |
| 22013 |
structured-block |
| 22014 |
|
| 22015 |
OpenACC 2.6: |
| 22016 |
|
| 22017 |
# pragma acc serial oacc-serial-clause[optseq] new-line |
| 22018 |
structured-block |
| 22019 |
|
| 22020 |
LOC is the location of the #pragma token. |
| 22021 |
*/ |
| 22022 |
|
| 22023 |
#define OACC_KERNELS_CLAUSE_MASK \ |
| 22024 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 22025 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \ |
| 22026 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 22027 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 22028 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 22029 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 22030 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ |
| 22031 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 22032 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 22033 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \ |
| 22034 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ |
| 22035 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ |
| 22036 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ |
| 22037 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ |
| 22038 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ |
| 22039 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 22040 |
|
| 22041 |
#define OACC_PARALLEL_CLAUSE_MASK \ |
| 22042 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 22043 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \ |
| 22044 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 22045 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 22046 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 22047 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 22048 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ |
| 22049 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 22050 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 22051 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \ |
| 22052 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ |
| 22053 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \ |
| 22054 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ |
| 22055 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ |
| 22056 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ |
| 22057 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ |
| 22058 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ |
| 22059 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ |
| 22060 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 22061 |
|
| 22062 |
#define OACC_SERIAL_CLAUSE_MASK \ |
| 22063 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 22064 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \ |
| 22065 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 22066 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 22067 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 22068 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 22069 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ |
| 22070 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 22071 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 22072 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \ |
| 22073 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ |
| 22074 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \ |
| 22075 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ |
| 22076 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ |
| 22077 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ |
| 22078 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 22079 |
|
| 22080 |
static tree |
| 22081 |
c_parser_oacc_compute (location_t loc, c_parser *parser, |
| 22082 |
enum pragma_kind p_kind, char *p_name, bool *if_p) |
| 22083 |
{ |
| 22084 |
omp_clause_mask mask; |
| 22085 |
enum tree_code code; |
| 22086 |
switch (p_kind) |
| 22087 |
{ |
| 22088 |
case PRAGMA_OACC_KERNELS: |
| 22089 |
strcat (p_name, " kernels"); |
| 22090 |
mask = OACC_KERNELS_CLAUSE_MASK; |
| 22091 |
code = OACC_KERNELS; |
| 22092 |
break; |
| 22093 |
case PRAGMA_OACC_PARALLEL: |
| 22094 |
strcat (p_name, " parallel"); |
| 22095 |
mask = OACC_PARALLEL_CLAUSE_MASK; |
| 22096 |
code = OACC_PARALLEL; |
| 22097 |
break; |
| 22098 |
case PRAGMA_OACC_SERIAL: |
| 22099 |
strcat (p_name, " serial"); |
| 22100 |
mask = OACC_SERIAL_CLAUSE_MASK; |
| 22101 |
code = OACC_SERIAL; |
| 22102 |
break; |
| 22103 |
default: |
| 22104 |
gcc_unreachable (); |
| 22105 |
} |
| 22106 |
|
| 22107 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 22108 |
{ |
| 22109 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 22110 |
if (strcmp (p, "loop") == 0) |
| 22111 |
{ |
| 22112 |
c_parser_consume_token (parser); |
| 22113 |
tree block = c_begin_omp_parallel (); |
| 22114 |
tree clauses; |
| 22115 |
c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p); |
| 22116 |
return c_finish_omp_construct (loc, code, block, clauses); |
| 22117 |
} |
| 22118 |
} |
| 22119 |
|
| 22120 |
tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name, |
| 22121 |
/*finish_p=*/true, |
| 22122 |
/*target=*/true); |
| 22123 |
|
| 22124 |
tree block = c_begin_omp_parallel (); |
| 22125 |
add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 22126 |
|
| 22127 |
return c_finish_omp_construct (loc, code, block, clauses); |
| 22128 |
} |
| 22129 |
|
| 22130 |
/* OpenACC 2.0: |
| 22131 |
# pragma acc routine oacc-routine-clause[optseq] new-line |
| 22132 |
function-definition |
| 22133 |
|
| 22134 |
# pragma acc routine ( name ) oacc-routine-clause[optseq] new-line |
| 22135 |
*/ |
| 22136 |
|
| 22137 |
#define OACC_ROUTINE_CLAUSE_MASK \ |
| 22138 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \ |
| 22139 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \ |
| 22140 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \ |
| 22141 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \ |
| 22142 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NOHOST) ) |
| 22143 |
|
| 22144 |
/* Parse an OpenACC routine directive. For named directives, we apply |
| 22145 |
immediately to the named function. For unnamed ones we then parse |
| 22146 |
a declaration or definition, which must be for a function. */ |
| 22147 |
|
| 22148 |
static void |
| 22149 |
c_parser_oacc_routine (c_parser *parser, enum pragma_context context) |
| 22150 |
{ |
| 22151 |
gcc_checking_assert (context == pragma_external); |
| 22152 |
|
| 22153 |
oacc_routine_data data; |
| 22154 |
data.error_seen = false; |
| 22155 |
data.fndecl_seen = false; |
| 22156 |
data.loc = c_parser_peek_token (parser)->location; |
| 22157 |
|
| 22158 |
c_parser_consume_pragma (parser); |
| 22159 |
|
| 22160 |
/* Look for optional '( name )'. */ |
| 22161 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 22162 |
{ |
| 22163 |
c_parser_consume_token (parser); /* '(' */ |
| 22164 |
|
| 22165 |
tree decl = NULL_TREE; |
| 22166 |
c_token *name_token = c_parser_peek_token (parser); |
| 22167 |
location_t name_loc = name_token->location; |
| 22168 |
if (name_token->type == CPP_NAME |
| 22169 |
&& (name_token->id_kind == C_ID_ID |
| 22170 |
|| name_token->id_kind == C_ID_TYPENAME)) |
| 22171 |
{ |
| 22172 |
decl = lookup_name (name_token->value); |
| 22173 |
if (!decl) |
| 22174 |
error_at (name_loc, |
| 22175 |
"%qE has not been declared", name_token->value); |
| 22176 |
c_parser_consume_token (parser); |
| 22177 |
} |
| 22178 |
else |
| 22179 |
c_parser_error (parser, "expected function name"); |
| 22180 |
|
| 22181 |
if (!decl |
| 22182 |
|| !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 22183 |
{ |
| 22184 |
c_parser_skip_to_pragma_eol (parser, false); |
| 22185 |
return; |
| 22186 |
} |
| 22187 |
|
| 22188 |
data.clauses |
| 22189 |
= c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK, |
| 22190 |
"#pragma acc routine"); |
| 22191 |
/* The clauses are in reverse order; fix that to make later diagnostic |
| 22192 |
emission easier. */ |
| 22193 |
data.clauses = nreverse (data.clauses); |
| 22194 |
|
| 22195 |
if (TREE_CODE (decl) != FUNCTION_DECL) |
| 22196 |
{ |
| 22197 |
error_at (name_loc, "%qD does not refer to a function", decl); |
| 22198 |
return; |
| 22199 |
} |
| 22200 |
|
| 22201 |
c_finish_oacc_routine (&data, decl, false); |
| 22202 |
} |
| 22203 |
else /* No optional '( name )'. */ |
| 22204 |
{ |
| 22205 |
data.clauses |
| 22206 |
= c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK, |
| 22207 |
"#pragma acc routine"); |
| 22208 |
/* The clauses are in reverse order; fix that to make later diagnostic |
| 22209 |
emission easier. */ |
| 22210 |
data.clauses = nreverse (data.clauses); |
| 22211 |
|
| 22212 |
/* Emit a helpful diagnostic if there's another pragma following this |
| 22213 |
one. Also don't allow a static assertion declaration, as in the |
| 22214 |
following we'll just parse a *single* "declaration or function |
| 22215 |
definition", and the static assertion counts an one. */ |
| 22216 |
if (c_parser_next_token_is (parser, CPP_PRAGMA) |
| 22217 |
|| c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
| 22218 |
{ |
| 22219 |
error_at (data.loc, |
| 22220 |
"%<#pragma acc routine%> not immediately followed by" |
| 22221 |
" function declaration or definition"); |
| 22222 |
/* ..., and then just keep going. */ |
| 22223 |
return; |
| 22224 |
} |
| 22225 |
|
| 22226 |
/* We only have to consider the pragma_external case here. */ |
| 22227 |
if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 22228 |
&& c_parser_peek_token (parser)->keyword == RID_EXTENSION) |
| 22229 |
{ |
| 22230 |
int ext = disable_extension_diagnostics (); |
| 22231 |
do |
| 22232 |
c_parser_consume_token (parser); |
| 22233 |
while (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 22234 |
&& c_parser_peek_token (parser)->keyword == RID_EXTENSION); |
| 22235 |
c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 22236 |
false, NULL, NULL, false, NULL, &data); |
| 22237 |
restore_extension_diagnostics (ext); |
| 22238 |
} |
| 22239 |
else |
| 22240 |
c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 22241 |
false, NULL, NULL, false, NULL, &data); |
| 22242 |
} |
| 22243 |
} |
| 22244 |
|
| 22245 |
/* Finalize an OpenACC routine pragma, applying it to FNDECL. |
| 22246 |
IS_DEFN is true if we're applying it to the definition. */ |
| 22247 |
|
| 22248 |
static void |
| 22249 |
c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl, |
| 22250 |
bool is_defn) |
| 22251 |
{ |
| 22252 |
/* Keep going if we're in error reporting mode. */ |
| 22253 |
if (data->error_seen |
| 22254 |
|| fndecl == error_mark_node) |
| 22255 |
return; |
| 22256 |
|
| 22257 |
if (data->fndecl_seen) |
| 22258 |
{ |
| 22259 |
error_at (data->loc, |
| 22260 |
"%<#pragma acc routine%> not immediately followed by" |
| 22261 |
" a single function declaration or definition"); |
| 22262 |
data->error_seen = true; |
| 22263 |
return; |
| 22264 |
} |
| 22265 |
if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) |
| 22266 |
{ |
| 22267 |
error_at (data->loc, |
| 22268 |
"%<#pragma acc routine%> not immediately followed by" |
| 22269 |
" function declaration or definition"); |
| 22270 |
data->error_seen = true; |
| 22271 |
return; |
| 22272 |
} |
| 22273 |
|
| 22274 |
int compatible |
| 22275 |
= oacc_verify_routine_clauses (fndecl, &data->clauses, data->loc, |
| 22276 |
"#pragma acc routine"); |
| 22277 |
if (compatible < 0) |
| 22278 |
{ |
| 22279 |
data->error_seen = true; |
| 22280 |
return; |
| 22281 |
} |
| 22282 |
if (compatible > 0) |
| 22283 |
{ |
| 22284 |
} |
| 22285 |
else |
| 22286 |
{ |
| 22287 |
if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl))) |
| 22288 |
{ |
| 22289 |
error_at (data->loc, |
| 22290 |
TREE_USED (fndecl) |
| 22291 |
? G_("%<#pragma acc routine%> must be applied before use") |
| 22292 |
: G_("%<#pragma acc routine%> must be applied before" |
| 22293 |
" definition")); |
| 22294 |
data->error_seen = true; |
| 22295 |
return; |
| 22296 |
} |
| 22297 |
|
| 22298 |
/* Set the routine's level of parallelism. */ |
| 22299 |
tree dims = oacc_build_routine_dims (data->clauses); |
| 22300 |
oacc_replace_fn_attrib (fndecl, dims); |
| 22301 |
|
| 22302 |
/* Add an "omp declare target" attribute. */ |
| 22303 |
DECL_ATTRIBUTES (fndecl) |
| 22304 |
= tree_cons (get_identifier ("omp declare target"), |
| 22305 |
data->clauses, DECL_ATTRIBUTES (fndecl)); |
| 22306 |
} |
| 22307 |
|
| 22308 |
/* Remember that we've used this "#pragma acc routine". */ |
| 22309 |
data->fndecl_seen = true; |
| 22310 |
} |
| 22311 |
|
| 22312 |
/* OpenACC 2.0: |
| 22313 |
# pragma acc update oacc-update-clause[optseq] new-line |
| 22314 |
*/ |
| 22315 |
|
| 22316 |
#define OACC_UPDATE_CLAUSE_MASK \ |
| 22317 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 22318 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \ |
| 22319 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \ |
| 22320 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 22321 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) \ |
| 22322 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ |
| 22323 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 22324 |
|
| 22325 |
static void |
| 22326 |
c_parser_oacc_update (c_parser *parser) |
| 22327 |
{ |
| 22328 |
location_t loc = c_parser_peek_token (parser)->location; |
| 22329 |
|
| 22330 |
c_parser_consume_pragma (parser); |
| 22331 |
|
| 22332 |
tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK, |
| 22333 |
"#pragma acc update"); |
| 22334 |
if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) |
| 22335 |
{ |
| 22336 |
error_at (loc, |
| 22337 |
"%<#pragma acc update%> must contain at least one " |
| 22338 |
"%<device%> or %<host%> or %<self%> clause"); |
| 22339 |
return; |
| 22340 |
} |
| 22341 |
|
| 22342 |
if (parser->error) |
| 22343 |
return; |
| 22344 |
|
| 22345 |
tree stmt = make_node (OACC_UPDATE); |
| 22346 |
TREE_TYPE (stmt) = void_type_node; |
| 22347 |
OACC_UPDATE_CLAUSES (stmt) = clauses; |
| 22348 |
SET_EXPR_LOCATION (stmt, loc); |
| 22349 |
add_stmt (stmt); |
| 22350 |
} |
| 22351 |
|
| 22352 |
/* OpenACC 2.0: |
| 22353 |
# pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line |
| 22354 |
|
| 22355 |
LOC is the location of the #pragma token. |
| 22356 |
*/ |
| 22357 |
|
| 22358 |
#define OACC_WAIT_CLAUSE_MASK \ |
| 22359 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) ) |
| 22360 |
|
| 22361 |
static tree |
| 22362 |
c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name) |
| 22363 |
{ |
| 22364 |
tree clauses, list = NULL_TREE, stmt = NULL_TREE; |
| 22365 |
|
| 22366 |
if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 22367 |
list = c_parser_oacc_wait_list (parser, loc, list); |
| 22368 |
|
| 22369 |
strcpy (p_name, " wait"); |
| 22370 |
clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name); |
| 22371 |
stmt = c_finish_oacc_wait (loc, list, clauses); |
| 22372 |
add_stmt (stmt); |
| 22373 |
|
| 22374 |
return stmt; |
| 22375 |
} |
| 22376 |
|
| 22377 |
struct c_omp_loc_tree |
| 22378 |
{ |
| 22379 |
location_t loc; |
| 22380 |
tree var; |
| 22381 |
}; |
| 22382 |
|
| 22383 |
/* Check whether the expression used in the allocator clause is declared or |
| 22384 |
modified between the variable declaration and its allocate directive. */ |
| 22385 |
static tree |
| 22386 |
c_check_omp_allocate_allocator_r (tree *tp, int *, void *data) |
| 22387 |
{ |
| 22388 |
tree var = ((struct c_omp_loc_tree *) data)->var; |
| 22389 |
location_t loc = ((struct c_omp_loc_tree *) data)->loc; |
| 22390 |
if (TREE_CODE (*tp) == VAR_DECL && c_check_in_current_scope (*tp)) |
| 22391 |
{ |
| 22392 |
if (linemap_location_before_p (line_table, DECL_SOURCE_LOCATION (var), |
| 22393 |
DECL_SOURCE_LOCATION (*tp))) |
| 22394 |
{ |
| 22395 |
error_at (loc, "variable %qD used in the %<allocator%> clause must " |
| 22396 |
"be declared before %qD", *tp, var); |
| 22397 |
inform (DECL_SOURCE_LOCATION (*tp), "declared here"); |
| 22398 |
inform (DECL_SOURCE_LOCATION (var), |
| 22399 |
"to be allocated variable declared here"); |
| 22400 |
return *tp; |
| 22401 |
} |
| 22402 |
else |
| 22403 |
{ |
| 22404 |
gcc_assert (cur_stmt_list |
| 22405 |
&& TREE_CODE (cur_stmt_list) == STATEMENT_LIST); |
| 22406 |
|
| 22407 |
tree_stmt_iterator l = tsi_last (cur_stmt_list); |
| 22408 |
while (!tsi_end_p (l)) |
| 22409 |
{ |
| 22410 |
if (linemap_location_before_p (line_table, EXPR_LOCATION (*l), |
| 22411 |
DECL_SOURCE_LOCATION (var))) |
| 22412 |
break; |
| 22413 |
if (TREE_CODE (*l) == MODIFY_EXPR |
| 22414 |
&& TREE_OPERAND (*l, 0) == *tp) |
| 22415 |
{ |
| 22416 |
error_at (loc, |
| 22417 |
"variable %qD used in the %<allocator%> clause " |
| 22418 |
"must not be modified between declaration of %qD " |
| 22419 |
"and its %<allocate%> directive", *tp, var); |
| 22420 |
inform (EXPR_LOCATION (*l), "modified here"); |
| 22421 |
inform (DECL_SOURCE_LOCATION (var), |
| 22422 |
"to be allocated variable declared here"); |
| 22423 |
return *tp; |
| 22424 |
} |
| 22425 |
--l; |
| 22426 |
} |
| 22427 |
} |
| 22428 |
} |
| 22429 |
return NULL_TREE; |
| 22430 |
} |
| 22431 |
|
| 22432 |
/* OpenMP 5.x: |
| 22433 |
# pragma omp allocate (list) clauses |
| 22434 |
|
| 22435 |
OpenMP 5.0 clause: |
| 22436 |
allocator (omp_allocator_handle_t expression) |
| 22437 |
|
| 22438 |
OpenMP 5.1 additional clause: |
| 22439 |
align (constant-expression)] */ |
| 22440 |
|
| 22441 |
static void |
| 22442 |
c_parser_omp_allocate (c_parser *parser) |
| 22443 |
{ |
| 22444 |
tree alignment = NULL_TREE; |
| 22445 |
tree allocator = NULL_TREE; |
| 22446 |
c_parser_consume_pragma (parser); |
| 22447 |
location_t loc = c_parser_peek_token (parser)->location; |
| 22448 |
location_t allocator_loc = UNKNOWN_LOCATION; |
| 22449 |
tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ALLOCATE, NULL_TREE); |
| 22450 |
do |
| 22451 |
{ |
| 22452 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 22453 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 22454 |
c_parser_consume_token (parser); |
| 22455 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 22456 |
break; |
| 22457 |
matching_parens parens; |
| 22458 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 22459 |
c_parser_consume_token (parser); |
| 22460 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 22461 |
if (strcmp ("align", p) != 0 && strcmp ("allocator", p) != 0) |
| 22462 |
{ |
| 22463 |
error_at (c_parser_peek_token (parser)->location, |
| 22464 |
"expected %<allocator%> or %<align%>"); |
| 22465 |
break; |
| 22466 |
} |
| 22467 |
if (!parens.require_open (parser)) |
| 22468 |
break; |
| 22469 |
|
| 22470 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 22471 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 22472 |
expr_loc = c_parser_peek_token (parser)->location; |
| 22473 |
if (expr.value == error_mark_node) |
| 22474 |
; |
| 22475 |
else if (p[2] == 'i' && alignment) |
| 22476 |
{ |
| 22477 |
error_at (expr_loc, "too many %qs clauses", "align"); |
| 22478 |
break; |
| 22479 |
} |
| 22480 |
else if (p[2] == 'i') |
| 22481 |
{ |
| 22482 |
alignment = c_fully_fold (expr.value, false, NULL); |
| 22483 |
if (TREE_CODE (alignment) != INTEGER_CST |
| 22484 |
|| !INTEGRAL_TYPE_P (TREE_TYPE (alignment)) |
| 22485 |
|| tree_int_cst_sgn (alignment) != 1 |
| 22486 |
|| !integer_pow2p (alignment)) |
| 22487 |
{ |
| 22488 |
error_at (expr_loc, "%<align%> clause argument needs to be " |
| 22489 |
"positive constant power of two integer " |
| 22490 |
"expression"); |
| 22491 |
alignment = NULL_TREE; |
| 22492 |
} |
| 22493 |
} |
| 22494 |
else if (allocator) |
| 22495 |
{ |
| 22496 |
error_at (expr_loc, "too many %qs clauses", "allocator"); |
| 22497 |
break; |
| 22498 |
} |
| 22499 |
else |
| 22500 |
{ |
| 22501 |
allocator = c_fully_fold (expr.value, false, NULL); |
| 22502 |
allocator_loc = expr_loc; |
| 22503 |
tree orig_type |
| 22504 |
= expr.original_type ? expr.original_type : TREE_TYPE (allocator); |
| 22505 |
orig_type = TYPE_MAIN_VARIANT (orig_type); |
| 22506 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (allocator)) |
| 22507 |
|| TREE_CODE (orig_type) != ENUMERAL_TYPE |
| 22508 |
|| TYPE_NAME (orig_type) |
| 22509 |
!= get_identifier ("omp_allocator_handle_t")) |
| 22510 |
{ |
| 22511 |
error_at (expr_loc, |
| 22512 |
"%<allocator%> clause allocator expression has type " |
| 22513 |
"%qT rather than %<omp_allocator_handle_t%>", |
| 22514 |
TREE_TYPE (allocator)); |
| 22515 |
allocator = NULL_TREE; |
| 22516 |
} |
| 22517 |
} |
| 22518 |
parens.skip_until_found_close (parser); |
| 22519 |
} while (true); |
| 22520 |
c_parser_skip_to_pragma_eol (parser); |
| 22521 |
|
| 22522 |
c_mark_decl_jump_unsafe_in_current_scope (); |
| 22523 |
for (tree c = nl; c != NULL_TREE; c = OMP_CLAUSE_CHAIN (c)) |
| 22524 |
{ |
| 22525 |
tree var = OMP_CLAUSE_DECL (c); |
| 22526 |
if (TREE_CODE (var) == PARM_DECL) |
| 22527 |
{ |
| 22528 |
error_at (OMP_CLAUSE_LOCATION (nl), |
| 22529 |
"function parameter %qD may not appear as list item in an " |
| 22530 |
"%<allocate%> directive", var); |
| 22531 |
continue; |
| 22532 |
} |
| 22533 |
if (!parser->in_omp_decl_attribute && !c_check_in_current_scope (var)) |
| 22534 |
{ |
| 22535 |
error_at (OMP_CLAUSE_LOCATION (nl), |
| 22536 |
"%<allocate%> directive must be in the same scope as %qD", |
| 22537 |
var); |
| 22538 |
inform (DECL_SOURCE_LOCATION (var), "declared here"); |
| 22539 |
continue; |
| 22540 |
} |
| 22541 |
if (lookup_attribute ("omp allocate", DECL_ATTRIBUTES (var))) |
| 22542 |
{ |
| 22543 |
error_at (OMP_CLAUSE_LOCATION (nl), |
| 22544 |
"%qD already appeared as list item in an " |
| 22545 |
"%<allocate%> directive", var); |
| 22546 |
continue; |
| 22547 |
} |
| 22548 |
if (TREE_STATIC (var)) |
| 22549 |
{ |
| 22550 |
if (allocator == NULL_TREE && allocator_loc == UNKNOWN_LOCATION) |
| 22551 |
{ |
| 22552 |
error_at (loc, |
| 22553 |
"%<allocator%> clause required for " |
| 22554 |
"static variable %qD", var); |
| 22555 |
continue; |
| 22556 |
} |
| 22557 |
else if (allocator |
| 22558 |
&& (wi::to_widest (allocator) < 1 |
| 22559 |
|| wi::to_widest (allocator) > GOMP_OMP_PREDEF_ALLOC_MAX) |
| 22560 |
&& (wi::to_widest (allocator) < GOMP_OMPX_PREDEF_ALLOC_MIN |
| 22561 |
|| wi::to_widest (allocator) > GOMP_OMPX_PREDEF_ALLOC_MAX)) |
| 22562 |
{ |
| 22563 |
error_at (allocator_loc, |
| 22564 |
"%<allocator%> clause requires a predefined allocator as " |
| 22565 |
"%qD is static", var); |
| 22566 |
} |
| 22567 |
} |
| 22568 |
if (allocator) |
| 22569 |
{ |
| 22570 |
struct c_omp_loc_tree data |
| 22571 |
= {EXPR_LOC_OR_LOC (allocator, OMP_CLAUSE_LOCATION (nl)), var}; |
| 22572 |
walk_tree (&allocator, c_check_omp_allocate_allocator_r, &data, NULL); |
| 22573 |
} |
| 22574 |
DECL_ATTRIBUTES (var) = tree_cons (get_identifier ("omp allocate"), |
| 22575 |
build_tree_list (allocator, alignment), |
| 22576 |
DECL_ATTRIBUTES (var)); |
| 22577 |
} |
| 22578 |
} |
| 22579 |
|
| 22580 |
/* OpenMP 2.5: |
| 22581 |
# pragma omp atomic new-line |
| 22582 |
expression-stmt |
| 22583 |
|
| 22584 |
expression-stmt: |
| 22585 |
x binop= expr | x++ | ++x | x-- | --x |
| 22586 |
binop: |
| 22587 |
+, *, -, /, &, ^, |, <<, >> |
| 22588 |
|
| 22589 |
where x is an lvalue expression with scalar type. |
| 22590 |
|
| 22591 |
OpenMP 3.1: |
| 22592 |
# pragma omp atomic new-line |
| 22593 |
update-stmt |
| 22594 |
|
| 22595 |
# pragma omp atomic read new-line |
| 22596 |
read-stmt |
| 22597 |
|
| 22598 |
# pragma omp atomic write new-line |
| 22599 |
write-stmt |
| 22600 |
|
| 22601 |
# pragma omp atomic update new-line |
| 22602 |
update-stmt |
| 22603 |
|
| 22604 |
# pragma omp atomic capture new-line |
| 22605 |
capture-stmt |
| 22606 |
|
| 22607 |
# pragma omp atomic capture new-line |
| 22608 |
capture-block |
| 22609 |
|
| 22610 |
read-stmt: |
| 22611 |
v = x |
| 22612 |
write-stmt: |
| 22613 |
x = expr |
| 22614 |
update-stmt: |
| 22615 |
expression-stmt | x = x binop expr |
| 22616 |
capture-stmt: |
| 22617 |
v = expression-stmt |
| 22618 |
capture-block: |
| 22619 |
{ v = x; update-stmt; } | { update-stmt; v = x; } |
| 22620 |
|
| 22621 |
OpenMP 4.0: |
| 22622 |
update-stmt: |
| 22623 |
expression-stmt | x = x binop expr | x = expr binop x |
| 22624 |
capture-stmt: |
| 22625 |
v = update-stmt |
| 22626 |
capture-block: |
| 22627 |
{ v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; } |
| 22628 |
|
| 22629 |
OpenMP 5.1: |
| 22630 |
# pragma omp atomic compare new-line |
| 22631 |
conditional-update-atomic |
| 22632 |
|
| 22633 |
# pragma omp atomic compare capture new-line |
| 22634 |
conditional-update-capture-atomic |
| 22635 |
|
| 22636 |
conditional-update-atomic: |
| 22637 |
cond-expr-stmt | cond-update-stmt |
| 22638 |
cond-expr-stmt: |
| 22639 |
x = expr ordop x ? expr : x; |
| 22640 |
x = x ordop expr ? expr : x; |
| 22641 |
x = x == e ? d : x; |
| 22642 |
cond-update-stmt: |
| 22643 |
if (expr ordop x) { x = expr; } |
| 22644 |
if (x ordop expr) { x = expr; } |
| 22645 |
if (x == e) { x = d; } |
| 22646 |
ordop: |
| 22647 |
<, > |
| 22648 |
conditional-update-capture-atomic: |
| 22649 |
v = cond-expr-stmt |
| 22650 |
{ v = x; cond-expr-stmt } |
| 22651 |
{ cond-expr-stmt v = x; } |
| 22652 |
{ v = x; cond-update-stmt } |
| 22653 |
{ cond-update-stmt v = x; } |
| 22654 |
if (x == e) { x = d; } else { v = x; } |
| 22655 |
{ r = x == e; if (r) { x = d; } } |
| 22656 |
{ r = x == e; if (r) { x = d; } else { v = x; } } |
| 22657 |
|
| 22658 |
where x, r and v are lvalue expressions with scalar type, |
| 22659 |
expr, e and d are expressions with scalar type and e might be |
| 22660 |
the same as v. |
| 22661 |
|
| 22662 |
LOC is the location of the #pragma token. */ |
| 22663 |
|
| 22664 |
static void |
| 22665 |
c_parser_omp_atomic (location_t loc, c_parser *parser, bool openacc) |
| 22666 |
{ |
| 22667 |
tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE, r = NULL_TREE; |
| 22668 |
tree lhs1 = NULL_TREE, rhs1 = NULL_TREE; |
| 22669 |
tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE; |
| 22670 |
enum tree_code code = ERROR_MARK, opcode = NOP_EXPR; |
| 22671 |
enum omp_memory_order memory_order = OMP_MEMORY_ORDER_UNSPECIFIED; |
| 22672 |
struct c_expr expr; |
| 22673 |
location_t eloc; |
| 22674 |
bool structured_block = false; |
| 22675 |
bool swapped = false; |
| 22676 |
bool non_lvalue_p; |
| 22677 |
tree clauses = NULL_TREE; |
| 22678 |
bool capture = false; |
| 22679 |
bool compare = false; |
| 22680 |
bool weak = false; |
| 22681 |
enum omp_memory_order fail = OMP_MEMORY_ORDER_UNSPECIFIED; |
| 22682 |
bool no_semicolon = false; |
| 22683 |
bool extra_scope = false; |
| 22684 |
|
| 22685 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 22686 |
{ |
| 22687 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 22688 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 22689 |
c_parser_consume_token (parser); |
| 22690 |
|
| 22691 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 22692 |
{ |
| 22693 |
const char *p |
| 22694 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 22695 |
location_t cloc = c_parser_peek_token (parser)->location; |
| 22696 |
enum tree_code new_code = ERROR_MARK; |
| 22697 |
enum omp_memory_order new_memory_order |
| 22698 |
= OMP_MEMORY_ORDER_UNSPECIFIED; |
| 22699 |
bool new_capture = false; |
| 22700 |
bool new_compare = false; |
| 22701 |
bool new_weak = false; |
| 22702 |
enum omp_memory_order new_fail = OMP_MEMORY_ORDER_UNSPECIFIED; |
| 22703 |
|
| 22704 |
if (!strcmp (p, "read")) |
| 22705 |
new_code = OMP_ATOMIC_READ; |
| 22706 |
else if (!strcmp (p, "write")) |
| 22707 |
new_code = NOP_EXPR; |
| 22708 |
else if (!strcmp (p, "update")) |
| 22709 |
new_code = OMP_ATOMIC; |
| 22710 |
else if (openacc && !strcmp (p, "capture")) |
| 22711 |
new_code = OMP_ATOMIC_CAPTURE_NEW; |
| 22712 |
else if (openacc) |
| 22713 |
{ |
| 22714 |
p = NULL; |
| 22715 |
error_at (cloc, "expected %<read%>, %<write%>, %<update%>, " |
| 22716 |
"or %<capture%> clause"); |
| 22717 |
} |
| 22718 |
else if (!strcmp (p, "capture")) |
| 22719 |
new_capture = true; |
| 22720 |
else if (!strcmp (p, "compare")) |
| 22721 |
new_compare = true; |
| 22722 |
else if (!strcmp (p, "weak")) |
| 22723 |
new_weak = true; |
| 22724 |
else if (!strcmp (p, "fail")) |
| 22725 |
{ |
| 22726 |
matching_parens parens; |
| 22727 |
|
| 22728 |
c_parser_consume_token (parser); |
| 22729 |
if (!parens.require_open (parser)) |
| 22730 |
continue; |
| 22731 |
|
| 22732 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 22733 |
{ |
| 22734 |
const char *q |
| 22735 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 22736 |
|
| 22737 |
if (!strcmp (q, "seq_cst")) |
| 22738 |
new_fail = OMP_MEMORY_ORDER_SEQ_CST; |
| 22739 |
else if (!strcmp (q, "acquire")) |
| 22740 |
new_fail = OMP_MEMORY_ORDER_ACQUIRE; |
| 22741 |
else if (!strcmp (q, "relaxed")) |
| 22742 |
new_fail = OMP_MEMORY_ORDER_RELAXED; |
| 22743 |
} |
| 22744 |
|
| 22745 |
if (new_fail != OMP_MEMORY_ORDER_UNSPECIFIED) |
| 22746 |
{ |
| 22747 |
c_parser_consume_token (parser); |
| 22748 |
if (fail != OMP_MEMORY_ORDER_UNSPECIFIED) |
| 22749 |
error_at (cloc, "too many %qs clauses", "fail"); |
| 22750 |
else |
| 22751 |
fail = new_fail; |
| 22752 |
} |
| 22753 |
else |
| 22754 |
c_parser_error (parser, "expected %<seq_cst%>, %<acquire%> " |
| 22755 |
"or %<relaxed%>"); |
| 22756 |
parens.skip_until_found_close (parser); |
| 22757 |
continue; |
| 22758 |
} |
| 22759 |
else if (!strcmp (p, "seq_cst")) |
| 22760 |
new_memory_order = OMP_MEMORY_ORDER_SEQ_CST; |
| 22761 |
else if (!strcmp (p, "acq_rel")) |
| 22762 |
new_memory_order = OMP_MEMORY_ORDER_ACQ_REL; |
| 22763 |
else if (!strcmp (p, "release")) |
| 22764 |
new_memory_order = OMP_MEMORY_ORDER_RELEASE; |
| 22765 |
else if (!strcmp (p, "acquire")) |
| 22766 |
new_memory_order = OMP_MEMORY_ORDER_ACQUIRE; |
| 22767 |
else if (!strcmp (p, "relaxed")) |
| 22768 |
new_memory_order = OMP_MEMORY_ORDER_RELAXED; |
| 22769 |
else if (!strcmp (p, "hint")) |
| 22770 |
{ |
| 22771 |
c_parser_consume_token (parser); |
| 22772 |
clauses = c_parser_omp_clause_hint (parser, clauses); |
| 22773 |
continue; |
| 22774 |
} |
| 22775 |
else |
| 22776 |
{ |
| 22777 |
p = NULL; |
| 22778 |
error_at (cloc, "expected %<read%>, %<write%>, %<update%>, " |
| 22779 |
"%<capture%>, %<compare%>, %<weak%>, %<fail%>, " |
| 22780 |
"%<seq_cst%>, %<acq_rel%>, %<release%>, " |
| 22781 |
"%<relaxed%> or %<hint%> clause"); |
| 22782 |
} |
| 22783 |
if (p) |
| 22784 |
{ |
| 22785 |
if (new_code != ERROR_MARK) |
| 22786 |
{ |
| 22787 |
/* OpenACC permits 'update capture'. */ |
| 22788 |
if (openacc |
| 22789 |
&& code == OMP_ATOMIC |
| 22790 |
&& new_code == OMP_ATOMIC_CAPTURE_NEW) |
| 22791 |
code = new_code; |
| 22792 |
else if (code != ERROR_MARK) |
| 22793 |
error_at (cloc, "too many atomic clauses"); |
| 22794 |
else |
| 22795 |
code = new_code; |
| 22796 |
} |
| 22797 |
else if (new_memory_order != OMP_MEMORY_ORDER_UNSPECIFIED) |
| 22798 |
{ |
| 22799 |
if (memory_order != OMP_MEMORY_ORDER_UNSPECIFIED) |
| 22800 |
error_at (cloc, "too many memory order clauses"); |
| 22801 |
else |
| 22802 |
memory_order = new_memory_order; |
| 22803 |
} |
| 22804 |
else if (new_capture) |
| 22805 |
{ |
| 22806 |
if (capture) |
| 22807 |
error_at (cloc, "too many %qs clauses", "capture"); |
| 22808 |
else |
| 22809 |
capture = true; |
| 22810 |
} |
| 22811 |
else if (new_compare) |
| 22812 |
{ |
| 22813 |
if (compare) |
| 22814 |
error_at (cloc, "too many %qs clauses", "compare"); |
| 22815 |
else |
| 22816 |
compare = true; |
| 22817 |
} |
| 22818 |
else if (new_weak) |
| 22819 |
{ |
| 22820 |
if (weak) |
| 22821 |
error_at (cloc, "too many %qs clauses", "weak"); |
| 22822 |
else |
| 22823 |
weak = true; |
| 22824 |
} |
| 22825 |
c_parser_consume_token (parser); |
| 22826 |
continue; |
| 22827 |
} |
| 22828 |
} |
| 22829 |
break; |
| 22830 |
} |
| 22831 |
c_parser_skip_to_pragma_eol (parser); |
| 22832 |
|
| 22833 |
if (code == ERROR_MARK) |
| 22834 |
code = OMP_ATOMIC; |
| 22835 |
if (capture) |
| 22836 |
{ |
| 22837 |
if (code != OMP_ATOMIC) |
| 22838 |
error_at (loc, "%qs clause is incompatible with %<read%> or %<write%> " |
| 22839 |
"clauses", "capture"); |
| 22840 |
else |
| 22841 |
code = OMP_ATOMIC_CAPTURE_NEW; |
| 22842 |
} |
| 22843 |
if (compare && code != OMP_ATOMIC && code != OMP_ATOMIC_CAPTURE_NEW) |
| 22844 |
{ |
| 22845 |
error_at (loc, "%qs clause is incompatible with %<read%> or %<write%> " |
| 22846 |
"clauses", "compare"); |
| 22847 |
compare = false; |
| 22848 |
} |
| 22849 |
if (fail != OMP_MEMORY_ORDER_UNSPECIFIED && !compare) |
| 22850 |
{ |
| 22851 |
error_at (loc, "%qs clause requires %qs clause", "fail", "compare"); |
| 22852 |
fail = OMP_MEMORY_ORDER_UNSPECIFIED; |
| 22853 |
} |
| 22854 |
if (weak && !compare) |
| 22855 |
{ |
| 22856 |
error_at (loc, "%qs clause requires %qs clause", "weak", "compare"); |
| 22857 |
weak = false; |
| 22858 |
} |
| 22859 |
if (openacc) |
| 22860 |
memory_order = OMP_MEMORY_ORDER_RELAXED; |
| 22861 |
else if (memory_order == OMP_MEMORY_ORDER_UNSPECIFIED) |
| 22862 |
{ |
| 22863 |
omp_requires_mask |
| 22864 |
= (enum omp_requires) (omp_requires_mask |
| 22865 |
| OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED); |
| 22866 |
switch ((enum omp_memory_order) |
| 22867 |
(omp_requires_mask & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER)) |
| 22868 |
{ |
| 22869 |
case OMP_MEMORY_ORDER_UNSPECIFIED: |
| 22870 |
case OMP_MEMORY_ORDER_RELAXED: |
| 22871 |
memory_order = OMP_MEMORY_ORDER_RELAXED; |
| 22872 |
break; |
| 22873 |
case OMP_MEMORY_ORDER_SEQ_CST: |
| 22874 |
memory_order = OMP_MEMORY_ORDER_SEQ_CST; |
| 22875 |
break; |
| 22876 |
case OMP_MEMORY_ORDER_ACQUIRE: |
| 22877 |
if (code == NOP_EXPR) /* atomic write */ |
| 22878 |
{ |
| 22879 |
error_at (loc, "%<#pragma omp atomic write%> incompatible with " |
| 22880 |
"%<acquire%> clause implicitly provided by a " |
| 22881 |
"%<requires%> directive"); |
| 22882 |
memory_order = OMP_MEMORY_ORDER_SEQ_CST; |
| 22883 |
} |
| 22884 |
else |
| 22885 |
memory_order = OMP_MEMORY_ORDER_ACQUIRE; |
| 22886 |
break; |
| 22887 |
case OMP_MEMORY_ORDER_RELEASE: |
| 22888 |
if (code == OMP_ATOMIC_READ) |
| 22889 |
{ |
| 22890 |
error_at (loc, "%<#pragma omp atomic read%> incompatible with " |
| 22891 |
"%<release%> clause implicitly provided by a " |
| 22892 |
"%<requires%> directive"); |
| 22893 |
memory_order = OMP_MEMORY_ORDER_SEQ_CST; |
| 22894 |
} |
| 22895 |
else |
| 22896 |
memory_order = OMP_MEMORY_ORDER_RELEASE; |
| 22897 |
break; |
| 22898 |
case OMP_MEMORY_ORDER_ACQ_REL: |
| 22899 |
switch (code) |
| 22900 |
{ |
| 22901 |
case OMP_ATOMIC_READ: |
| 22902 |
memory_order = OMP_MEMORY_ORDER_ACQUIRE; |
| 22903 |
break; |
| 22904 |
case NOP_EXPR: /* atomic write */ |
| 22905 |
memory_order = OMP_MEMORY_ORDER_RELEASE; |
| 22906 |
break; |
| 22907 |
default: |
| 22908 |
memory_order = OMP_MEMORY_ORDER_ACQ_REL; |
| 22909 |
break; |
| 22910 |
} |
| 22911 |
break; |
| 22912 |
default: |
| 22913 |
gcc_unreachable (); |
| 22914 |
} |
| 22915 |
} |
| 22916 |
else |
| 22917 |
switch (code) |
| 22918 |
{ |
| 22919 |
case OMP_ATOMIC_READ: |
| 22920 |
if (memory_order == OMP_MEMORY_ORDER_RELEASE) |
| 22921 |
{ |
| 22922 |
error_at (loc, "%<#pragma omp atomic read%> incompatible with " |
| 22923 |
"%<release%> clause"); |
| 22924 |
memory_order = OMP_MEMORY_ORDER_SEQ_CST; |
| 22925 |
} |
| 22926 |
else if (memory_order == OMP_MEMORY_ORDER_ACQ_REL) |
| 22927 |
memory_order = OMP_MEMORY_ORDER_ACQUIRE; |
| 22928 |
break; |
| 22929 |
case NOP_EXPR: /* atomic write */ |
| 22930 |
if (memory_order == OMP_MEMORY_ORDER_ACQUIRE) |
| 22931 |
{ |
| 22932 |
error_at (loc, "%<#pragma omp atomic write%> incompatible with " |
| 22933 |
"%<acquire%> clause"); |
| 22934 |
memory_order = OMP_MEMORY_ORDER_SEQ_CST; |
| 22935 |
} |
| 22936 |
else if (memory_order == OMP_MEMORY_ORDER_ACQ_REL) |
| 22937 |
memory_order = OMP_MEMORY_ORDER_RELEASE; |
| 22938 |
break; |
| 22939 |
default: |
| 22940 |
break; |
| 22941 |
} |
| 22942 |
if (fail != OMP_MEMORY_ORDER_UNSPECIFIED) |
| 22943 |
memory_order |
| 22944 |
= (enum omp_memory_order) (memory_order |
| 22945 |
| (fail << OMP_FAIL_MEMORY_ORDER_SHIFT)); |
| 22946 |
|
| 22947 |
switch (code) |
| 22948 |
{ |
| 22949 |
case OMP_ATOMIC_READ: |
| 22950 |
case NOP_EXPR: /* atomic write */ |
| 22951 |
v = c_parser_cast_expression (parser, NULL).value; |
| 22952 |
non_lvalue_p = !lvalue_p (v); |
| 22953 |
v = c_fully_fold (v, false, NULL, true); |
| 22954 |
if (v == error_mark_node) |
| 22955 |
goto saw_error; |
| 22956 |
if (non_lvalue_p) |
| 22957 |
v = non_lvalue (v); |
| 22958 |
loc = c_parser_peek_token (parser)->location; |
| 22959 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 22960 |
goto saw_error; |
| 22961 |
if (code == NOP_EXPR) |
| 22962 |
{ |
| 22963 |
eloc = c_parser_peek_token (parser)->location; |
| 22964 |
expr = c_parser_expression (parser); |
| 22965 |
expr = default_function_array_read_conversion (eloc, expr); |
| 22966 |
/* atomic write is represented by OMP_ATOMIC with NOP_EXPR |
| 22967 |
opcode. */ |
| 22968 |
code = OMP_ATOMIC; |
| 22969 |
lhs = v; |
| 22970 |
v = NULL_TREE; |
| 22971 |
rhs = c_fully_fold (expr.value, false, NULL); |
| 22972 |
if (rhs == error_mark_node) |
| 22973 |
goto saw_error; |
| 22974 |
} |
| 22975 |
else |
| 22976 |
{ |
| 22977 |
lhs = c_parser_cast_expression (parser, NULL).value; |
| 22978 |
non_lvalue_p = !lvalue_p (lhs); |
| 22979 |
lhs = c_fully_fold (lhs, false, NULL, true); |
| 22980 |
if (lhs == error_mark_node) |
| 22981 |
goto saw_error; |
| 22982 |
if (non_lvalue_p) |
| 22983 |
lhs = non_lvalue (lhs); |
| 22984 |
} |
| 22985 |
goto done; |
| 22986 |
case OMP_ATOMIC_CAPTURE_NEW: |
| 22987 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 22988 |
{ |
| 22989 |
c_parser_consume_token (parser); |
| 22990 |
structured_block = true; |
| 22991 |
} |
| 22992 |
else if (compare |
| 22993 |
&& c_parser_next_token_is_keyword (parser, RID_IF)) |
| 22994 |
break; |
| 22995 |
else |
| 22996 |
{ |
| 22997 |
v = c_parser_cast_expression (parser, NULL).value; |
| 22998 |
non_lvalue_p = !lvalue_p (v); |
| 22999 |
v = c_fully_fold (v, false, NULL, true); |
| 23000 |
if (v == error_mark_node) |
| 23001 |
goto saw_error; |
| 23002 |
if (non_lvalue_p) |
| 23003 |
v = non_lvalue (v); |
| 23004 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 23005 |
goto saw_error; |
| 23006 |
if (compare && c_parser_next_token_is_keyword (parser, RID_IF)) |
| 23007 |
{ |
| 23008 |
eloc = c_parser_peek_token (parser)->location; |
| 23009 |
error_at (eloc, "expected expression"); |
| 23010 |
goto saw_error; |
| 23011 |
} |
| 23012 |
} |
| 23013 |
break; |
| 23014 |
default: |
| 23015 |
break; |
| 23016 |
} |
| 23017 |
|
| 23018 |
/* For structured_block case we don't know yet whether |
| 23019 |
old or new x should be captured. */ |
| 23020 |
restart: |
| 23021 |
if (compare && c_parser_next_token_is_keyword (parser, RID_IF)) |
| 23022 |
{ |
| 23023 |
c_parser_consume_token (parser); |
| 23024 |
|
| 23025 |
matching_parens parens; |
| 23026 |
if (!parens.require_open (parser)) |
| 23027 |
goto saw_error; |
| 23028 |
eloc = c_parser_peek_token (parser)->location; |
| 23029 |
c_expr cmp_expr; |
| 23030 |
if (r) |
| 23031 |
{ |
| 23032 |
cmp_expr = c_parser_cast_expression (parser, NULL); |
| 23033 |
cmp_expr = default_function_array_conversion (eloc, cmp_expr); |
| 23034 |
} |
| 23035 |
else |
| 23036 |
cmp_expr = c_parser_binary_expression (parser, NULL, void_list_node); |
| 23037 |
parens.skip_until_found_close (parser); |
| 23038 |
if (cmp_expr.value == error_mark_node) |
| 23039 |
goto saw_error; |
| 23040 |
if (r) |
| 23041 |
{ |
| 23042 |
if (!c_tree_equal (cmp_expr.value, unfolded_lhs)) |
| 23043 |
goto bad_if; |
| 23044 |
cmp_expr.value = rhs1; |
| 23045 |
rhs1 = NULL_TREE; |
| 23046 |
gcc_assert (TREE_CODE (cmp_expr.value) == EQ_EXPR); |
| 23047 |
} |
| 23048 |
if (TREE_CODE (cmp_expr.value) == EQ_EXPR) |
| 23049 |
; |
| 23050 |
else if (!structured_block && code == OMP_ATOMIC_CAPTURE_NEW) |
| 23051 |
{ |
| 23052 |
error_at (EXPR_LOC_OR_LOC (cmp_expr.value, eloc), |
| 23053 |
"expected %<==%> comparison in %<if%> condition"); |
| 23054 |
goto saw_error; |
| 23055 |
} |
| 23056 |
else if (TREE_CODE (cmp_expr.value) != GT_EXPR |
| 23057 |
&& TREE_CODE (cmp_expr.value) != LT_EXPR) |
| 23058 |
{ |
| 23059 |
error_at (EXPR_LOC_OR_LOC (cmp_expr.value, eloc), |
| 23060 |
"expected %<==%>, %<<%> or %<>%> comparison in %<if%> " |
| 23061 |
"condition"); |
| 23062 |
goto saw_error; |
| 23063 |
} |
| 23064 |
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 23065 |
goto saw_error; |
| 23066 |
|
| 23067 |
extra_scope = true; |
| 23068 |
eloc = c_parser_peek_token (parser)->location; |
| 23069 |
expr = c_parser_cast_expression (parser, NULL); |
| 23070 |
lhs = expr.value; |
| 23071 |
expr = default_function_array_conversion (eloc, expr); |
| 23072 |
unfolded_lhs = expr.value; |
| 23073 |
lhs = c_fully_fold (lhs, false, NULL, true); |
| 23074 |
orig_lhs = lhs; |
| 23075 |
if (lhs == error_mark_node) |
| 23076 |
goto saw_error; |
| 23077 |
if (!lvalue_p (unfolded_lhs)) |
| 23078 |
lhs = non_lvalue (lhs); |
| 23079 |
if (!c_parser_next_token_is (parser, CPP_EQ)) |
| 23080 |
{ |
| 23081 |
c_parser_error (parser, "expected %<=%>"); |
| 23082 |
goto saw_error; |
| 23083 |
} |
| 23084 |
c_parser_consume_token (parser); |
| 23085 |
eloc = c_parser_peek_token (parser)->location; |
| 23086 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 23087 |
rhs1 = expr.value; |
| 23088 |
|
| 23089 |
if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 23090 |
goto saw_error; |
| 23091 |
|
| 23092 |
if (!c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>")) |
| 23093 |
goto saw_error; |
| 23094 |
|
| 23095 |
extra_scope = false; |
| 23096 |
no_semicolon = true; |
| 23097 |
|
| 23098 |
if (c_tree_equal (TREE_OPERAND (cmp_expr.value, 0), unfolded_lhs)) |
| 23099 |
{ |
| 23100 |
if (TREE_CODE (cmp_expr.value) == EQ_EXPR) |
| 23101 |
{ |
| 23102 |
opcode = COND_EXPR; |
| 23103 |
rhs = c_fully_fold (TREE_OPERAND (cmp_expr.value, 1), |
| 23104 |
false, NULL, true); |
| 23105 |
rhs1 = c_fully_fold (rhs1, false, NULL, true); |
| 23106 |
} |
| 23107 |
else if (c_tree_equal (TREE_OPERAND (cmp_expr.value, 1), rhs1)) |
| 23108 |
{ |
| 23109 |
opcode = (TREE_CODE (cmp_expr.value) == GT_EXPR |
| 23110 |
? MIN_EXPR : MAX_EXPR); |
| 23111 |
rhs = c_fully_fold (rhs1, false, NULL, true); |
| 23112 |
rhs1 = c_fully_fold (TREE_OPERAND (cmp_expr.value, 0), |
| 23113 |
false, NULL, true); |
| 23114 |
} |
| 23115 |
else |
| 23116 |
goto bad_if; |
| 23117 |
} |
| 23118 |
else if (TREE_CODE (cmp_expr.value) == EQ_EXPR) |
| 23119 |
goto bad_if; |
| 23120 |
else if (c_tree_equal (TREE_OPERAND (cmp_expr.value, 1), unfolded_lhs) |
| 23121 |
&& c_tree_equal (TREE_OPERAND (cmp_expr.value, 0), rhs1)) |
| 23122 |
{ |
| 23123 |
opcode = (TREE_CODE (cmp_expr.value) == GT_EXPR |
| 23124 |
? MAX_EXPR : MIN_EXPR); |
| 23125 |
rhs = c_fully_fold (rhs1, false, NULL, true); |
| 23126 |
rhs1 = c_fully_fold (TREE_OPERAND (cmp_expr.value, 1), |
| 23127 |
false, NULL, true); |
| 23128 |
} |
| 23129 |
else |
| 23130 |
{ |
| 23131 |
bad_if: |
| 23132 |
c_parser_error (parser, |
| 23133 |
"invalid form of %<#pragma omp atomic compare%>"); |
| 23134 |
goto saw_error; |
| 23135 |
} |
| 23136 |
|
| 23137 |
if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 23138 |
{ |
| 23139 |
if (code != OMP_ATOMIC_CAPTURE_NEW |
| 23140 |
|| (structured_block && r == NULL_TREE) |
| 23141 |
|| TREE_CODE (cmp_expr.value) != EQ_EXPR) |
| 23142 |
{ |
| 23143 |
eloc = c_parser_peek_token (parser)->location; |
| 23144 |
error_at (eloc, "unexpected %<else%>"); |
| 23145 |
goto saw_error; |
| 23146 |
} |
| 23147 |
|
| 23148 |
c_parser_consume_token (parser); |
| 23149 |
|
| 23150 |
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 23151 |
goto saw_error; |
| 23152 |
|
| 23153 |
extra_scope = true; |
| 23154 |
v = c_parser_cast_expression (parser, NULL).value; |
| 23155 |
non_lvalue_p = !lvalue_p (v); |
| 23156 |
v = c_fully_fold (v, false, NULL, true); |
| 23157 |
if (v == error_mark_node) |
| 23158 |
goto saw_error; |
| 23159 |
if (non_lvalue_p) |
| 23160 |
v = non_lvalue (v); |
| 23161 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 23162 |
goto saw_error; |
| 23163 |
|
| 23164 |
expr = c_parser_expr_no_commas (parser, NULL); |
| 23165 |
|
| 23166 |
if (!c_tree_equal (expr.value, unfolded_lhs)) |
| 23167 |
goto bad_if; |
| 23168 |
|
| 23169 |
if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 23170 |
goto saw_error; |
| 23171 |
|
| 23172 |
if (!c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>")) |
| 23173 |
goto saw_error; |
| 23174 |
|
| 23175 |
extra_scope = false; |
| 23176 |
code = OMP_ATOMIC_CAPTURE_OLD; |
| 23177 |
if (r == NULL_TREE) |
| 23178 |
/* Signal to c_finish_omp_atomic that in |
| 23179 |
if (x == e) { x = d; } else { v = x; } |
| 23180 |
case the store to v should be conditional. */ |
| 23181 |
r = void_list_node; |
| 23182 |
} |
| 23183 |
else if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) |
| 23184 |
{ |
| 23185 |
c_parser_require_keyword (parser, RID_ELSE, "expected %<else%>"); |
| 23186 |
goto saw_error; |
| 23187 |
} |
| 23188 |
else if (code == OMP_ATOMIC_CAPTURE_NEW |
| 23189 |
&& r != NULL_TREE |
| 23190 |
&& v == NULL_TREE) |
| 23191 |
code = OMP_ATOMIC; |
| 23192 |
goto stmt_done; |
| 23193 |
} |
| 23194 |
eloc = c_parser_peek_token (parser)->location; |
| 23195 |
expr = c_parser_cast_expression (parser, NULL); |
| 23196 |
lhs = expr.value; |
| 23197 |
expr = default_function_array_conversion (eloc, expr); |
| 23198 |
unfolded_lhs = expr.value; |
| 23199 |
lhs = c_fully_fold (lhs, false, NULL, true); |
| 23200 |
orig_lhs = lhs; |
| 23201 |
switch (TREE_CODE (lhs)) |
| 23202 |
{ |
| 23203 |
invalid_compare: |
| 23204 |
error_at (eloc, "invalid form of %<pragma omp atomic compare%>"); |
| 23205 |
/* FALLTHRU */ |
| 23206 |
case ERROR_MARK: |
| 23207 |
saw_error: |
| 23208 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 23209 |
if (extra_scope && c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 23210 |
c_parser_consume_token (parser); |
| 23211 |
if (structured_block) |
| 23212 |
{ |
| 23213 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 23214 |
c_parser_consume_token (parser); |
| 23215 |
else if (code == OMP_ATOMIC_CAPTURE_NEW) |
| 23216 |
{ |
| 23217 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 23218 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 23219 |
c_parser_consume_token (parser); |
| 23220 |
} |
| 23221 |
} |
| 23222 |
return; |
| 23223 |
|
| 23224 |
case POSTINCREMENT_EXPR: |
| 23225 |
if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) |
| 23226 |
code = OMP_ATOMIC_CAPTURE_OLD; |
| 23227 |
/* FALLTHROUGH */ |
| 23228 |
case PREINCREMENT_EXPR: |
| 23229 |
lhs = TREE_OPERAND (lhs, 0); |
| 23230 |
unfolded_lhs = NULL_TREE; |
| 23231 |
opcode = PLUS_EXPR; |
| 23232 |
rhs = integer_one_node; |
| 23233 |
if (compare) |
| 23234 |
goto invalid_compare; |
| 23235 |
break; |
| 23236 |
|
| 23237 |
case POSTDECREMENT_EXPR: |
| 23238 |
if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) |
| 23239 |
code = OMP_ATOMIC_CAPTURE_OLD; |
| 23240 |
/* FALLTHROUGH */ |
| 23241 |
case PREDECREMENT_EXPR: |
| 23242 |
lhs = TREE_OPERAND (lhs, 0); |
| 23243 |
unfolded_lhs = NULL_TREE; |
| 23244 |
opcode = MINUS_EXPR; |
| 23245 |
rhs = integer_one_node; |
| 23246 |
if (compare) |
| 23247 |
goto invalid_compare; |
| 23248 |
break; |
| 23249 |
|
| 23250 |
case COMPOUND_EXPR: |
| 23251 |
if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR |
| 23252 |
&& TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR |
| 23253 |
&& TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR |
| 23254 |
&& TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0) |
| 23255 |
&& C_BOOLEAN_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND |
| 23256 |
(TREE_OPERAND (lhs, 1), 0), 0)))) |
| 23257 |
/* Undo effects of boolean_increment for post {in,de}crement. */ |
| 23258 |
lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0); |
| 23259 |
/* FALLTHRU */ |
| 23260 |
case MODIFY_EXPR: |
| 23261 |
if (TREE_CODE (lhs) == MODIFY_EXPR |
| 23262 |
&& C_BOOLEAN_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))) |
| 23263 |
{ |
| 23264 |
/* Undo effects of boolean_increment. */ |
| 23265 |
if (integer_onep (TREE_OPERAND (lhs, 1))) |
| 23266 |
{ |
| 23267 |
/* This is pre or post increment. */ |
| 23268 |
rhs = TREE_OPERAND (lhs, 1); |
| 23269 |
lhs = TREE_OPERAND (lhs, 0); |
| 23270 |
unfolded_lhs = NULL_TREE; |
| 23271 |
opcode = NOP_EXPR; |
| 23272 |
if (code == OMP_ATOMIC_CAPTURE_NEW |
| 23273 |
&& !structured_block |
| 23274 |
&& TREE_CODE (orig_lhs) == COMPOUND_EXPR) |
| 23275 |
code = OMP_ATOMIC_CAPTURE_OLD; |
| 23276 |
if (compare) |
| 23277 |
goto invalid_compare; |
| 23278 |
break; |
| 23279 |
} |
| 23280 |
if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR |
| 23281 |
&& TREE_OPERAND (lhs, 0) |
| 23282 |
== TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) |
| 23283 |
{ |
| 23284 |
/* This is pre or post decrement. */ |
| 23285 |
rhs = TREE_OPERAND (lhs, 1); |
| 23286 |
lhs = TREE_OPERAND (lhs, 0); |
| 23287 |
unfolded_lhs = NULL_TREE; |
| 23288 |
opcode = NOP_EXPR; |
| 23289 |
if (code == OMP_ATOMIC_CAPTURE_NEW |
| 23290 |
&& !structured_block |
| 23291 |
&& TREE_CODE (orig_lhs) == COMPOUND_EXPR) |
| 23292 |
code = OMP_ATOMIC_CAPTURE_OLD; |
| 23293 |
if (compare) |
| 23294 |
goto invalid_compare; |
| 23295 |
break; |
| 23296 |
} |
| 23297 |
} |
| 23298 |
/* FALLTHRU */ |
| 23299 |
default: |
| 23300 |
if (!lvalue_p (unfolded_lhs)) |
| 23301 |
lhs = non_lvalue (lhs); |
| 23302 |
if (compare && !c_parser_next_token_is (parser, CPP_EQ)) |
| 23303 |
{ |
| 23304 |
c_parser_error (parser, "expected %<=%>"); |
| 23305 |
goto saw_error; |
| 23306 |
} |
| 23307 |
switch (c_parser_peek_token (parser)->type) |
| 23308 |
{ |
| 23309 |
case CPP_MULT_EQ: |
| 23310 |
opcode = MULT_EXPR; |
| 23311 |
break; |
| 23312 |
case CPP_DIV_EQ: |
| 23313 |
opcode = TRUNC_DIV_EXPR; |
| 23314 |
break; |
| 23315 |
case CPP_PLUS_EQ: |
| 23316 |
opcode = PLUS_EXPR; |
| 23317 |
break; |
| 23318 |
case CPP_MINUS_EQ: |
| 23319 |
opcode = MINUS_EXPR; |
| 23320 |
break; |
| 23321 |
case CPP_LSHIFT_EQ: |
| 23322 |
opcode = LSHIFT_EXPR; |
| 23323 |
break; |
| 23324 |
case CPP_RSHIFT_EQ: |
| 23325 |
opcode = RSHIFT_EXPR; |
| 23326 |
break; |
| 23327 |
case CPP_AND_EQ: |
| 23328 |
opcode = BIT_AND_EXPR; |
| 23329 |
break; |
| 23330 |
case CPP_OR_EQ: |
| 23331 |
opcode = BIT_IOR_EXPR; |
| 23332 |
break; |
| 23333 |
case CPP_XOR_EQ: |
| 23334 |
opcode = BIT_XOR_EXPR; |
| 23335 |
break; |
| 23336 |
case CPP_EQ: |
| 23337 |
c_parser_consume_token (parser); |
| 23338 |
eloc = c_parser_peek_token (parser)->location; |
| 23339 |
expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs); |
| 23340 |
rhs1 = expr.value; |
| 23341 |
switch (TREE_CODE (rhs1)) |
| 23342 |
{ |
| 23343 |
case MULT_EXPR: |
| 23344 |
case TRUNC_DIV_EXPR: |
| 23345 |
case RDIV_EXPR: |
| 23346 |
case PLUS_EXPR: |
| 23347 |
case MINUS_EXPR: |
| 23348 |
case LSHIFT_EXPR: |
| 23349 |
case RSHIFT_EXPR: |
| 23350 |
case BIT_AND_EXPR: |
| 23351 |
case BIT_IOR_EXPR: |
| 23352 |
case BIT_XOR_EXPR: |
| 23353 |
if (compare) |
| 23354 |
break; |
| 23355 |
if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs)) |
| 23356 |
{ |
| 23357 |
opcode = TREE_CODE (rhs1); |
| 23358 |
rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL, |
| 23359 |
true); |
| 23360 |
rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL, |
| 23361 |
true); |
| 23362 |
goto stmt_done; |
| 23363 |
} |
| 23364 |
if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs)) |
| 23365 |
{ |
| 23366 |
opcode = TREE_CODE (rhs1); |
| 23367 |
rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL, |
| 23368 |
true); |
| 23369 |
rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL, |
| 23370 |
true); |
| 23371 |
swapped = !commutative_tree_code (opcode); |
| 23372 |
goto stmt_done; |
| 23373 |
} |
| 23374 |
break; |
| 23375 |
case COND_EXPR: |
| 23376 |
if (!compare) |
| 23377 |
break; |
| 23378 |
if (TREE_CODE (TREE_OPERAND (rhs1, 0)) != GT_EXPR |
| 23379 |
&& TREE_CODE (TREE_OPERAND (rhs1, 0)) != LT_EXPR |
| 23380 |
&& TREE_CODE (TREE_OPERAND (rhs1, 0)) != EQ_EXPR) |
| 23381 |
break; |
| 23382 |
if (!TREE_OPERAND (rhs1, 1)) |
| 23383 |
break; |
| 23384 |
if (!c_tree_equal (TREE_OPERAND (rhs1, 2), unfolded_lhs)) |
| 23385 |
break; |
| 23386 |
if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0), |
| 23387 |
unfolded_lhs)) |
| 23388 |
{ |
| 23389 |
if (TREE_CODE (TREE_OPERAND (rhs1, 0)) == EQ_EXPR) |
| 23390 |
{ |
| 23391 |
opcode = COND_EXPR; |
| 23392 |
rhs = c_fully_fold (TREE_OPERAND (TREE_OPERAND (rhs1, |
| 23393 |
0), 1), |
| 23394 |
false, NULL, true); |
| 23395 |
rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, |
| 23396 |
NULL, true); |
| 23397 |
goto stmt_done; |
| 23398 |
} |
| 23399 |
if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1), |
| 23400 |
TREE_OPERAND (rhs1, 1))) |
| 23401 |
{ |
| 23402 |
opcode = (TREE_CODE (TREE_OPERAND (rhs1, 0)) == GT_EXPR |
| 23403 |
? MIN_EXPR : MAX_EXPR); |
| 23404 |
rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL, |
| 23405 |
true); |
| 23406 |
rhs1 = c_fully_fold (TREE_OPERAND (TREE_OPERAND (rhs1, |
| 23407 |
0), 0), |
| 23408 |
false, NULL, true); |
| 23409 |
goto stmt_done; |
| 23410 |
} |
| 23411 |
} |
| 23412 |
else if (TREE_CODE (TREE_OPERAND (rhs1, 0)) == EQ_EXPR) |
| 23413 |
break; |
| 23414 |
else if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1), |
| 23415 |
unfolded_lhs)) |
| 23416 |
{ |
| 23417 |
if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0), |
| 23418 |
TREE_OPERAND (rhs1, 1))) |
| 23419 |
{ |
| 23420 |
opcode = (TREE_CODE (TREE_OPERAND (rhs1, 0)) == GT_EXPR |
| 23421 |
? MAX_EXPR : MIN_EXPR); |
| 23422 |
rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL, |
| 23423 |
true); |
| 23424 |
rhs1 = c_fully_fold (TREE_OPERAND (TREE_OPERAND (rhs1, |
| 23425 |
0), 1), |
| 23426 |
false, NULL, true); |
| 23427 |
goto stmt_done; |
| 23428 |
} |
| 23429 |
} |
| 23430 |
break; |
| 23431 |
case EQ_EXPR: |
| 23432 |
if (!compare |
| 23433 |
|| code != OMP_ATOMIC_CAPTURE_NEW |
| 23434 |
|| !structured_block |
| 23435 |
|| v |
| 23436 |
|| r) |
| 23437 |
break; |
| 23438 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 23439 |
&& c_parser_peek_2nd_token (parser)->keyword == RID_IF) |
| 23440 |
{ |
| 23441 |
r = lhs; |
| 23442 |
lhs = NULL_TREE; |
| 23443 |
c_parser_consume_token (parser); |
| 23444 |
goto restart; |
| 23445 |
} |
| 23446 |
break; |
| 23447 |
case ERROR_MARK: |
| 23448 |
goto saw_error; |
| 23449 |
default: |
| 23450 |
break; |
| 23451 |
} |
| 23452 |
if (c_parser_peek_token (parser)->type == CPP_SEMICOLON) |
| 23453 |
{ |
| 23454 |
if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) |
| 23455 |
{ |
| 23456 |
code = OMP_ATOMIC_CAPTURE_OLD; |
| 23457 |
v = lhs; |
| 23458 |
lhs = NULL_TREE; |
| 23459 |
expr = default_function_array_read_conversion (eloc, expr); |
| 23460 |
unfolded_lhs1 = expr.value; |
| 23461 |
lhs1 = c_fully_fold (unfolded_lhs1, false, NULL, true); |
| 23462 |
rhs1 = NULL_TREE; |
| 23463 |
c_parser_consume_token (parser); |
| 23464 |
goto restart; |
| 23465 |
} |
| 23466 |
if (structured_block && !compare) |
| 23467 |
{ |
| 23468 |
opcode = NOP_EXPR; |
| 23469 |
expr = default_function_array_read_conversion (eloc, expr); |
| 23470 |
rhs = c_fully_fold (expr.value, false, NULL, true); |
| 23471 |
rhs1 = NULL_TREE; |
| 23472 |
goto stmt_done; |
| 23473 |
} |
| 23474 |
} |
| 23475 |
c_parser_error (parser, "invalid form of %<#pragma omp atomic%>"); |
| 23476 |
goto saw_error; |
| 23477 |
default: |
| 23478 |
c_parser_error (parser, |
| 23479 |
"invalid operator for %<#pragma omp atomic%>"); |
| 23480 |
goto saw_error; |
| 23481 |
} |
| 23482 |
|
| 23483 |
/* Arrange to pass the location of the assignment operator to |
| 23484 |
c_finish_omp_atomic. */ |
| 23485 |
loc = c_parser_peek_token (parser)->location; |
| 23486 |
c_parser_consume_token (parser); |
| 23487 |
eloc = c_parser_peek_token (parser)->location; |
| 23488 |
expr = c_parser_expression (parser); |
| 23489 |
expr = default_function_array_read_conversion (eloc, expr); |
| 23490 |
rhs = expr.value; |
| 23491 |
rhs = c_fully_fold (rhs, false, NULL, true); |
| 23492 |
break; |
| 23493 |
} |
| 23494 |
stmt_done: |
| 23495 |
if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW && r == NULL_TREE) |
| 23496 |
{ |
| 23497 |
if (!no_semicolon |
| 23498 |
&& !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 23499 |
goto saw_error; |
| 23500 |
no_semicolon = false; |
| 23501 |
v = c_parser_cast_expression (parser, NULL).value; |
| 23502 |
non_lvalue_p = !lvalue_p (v); |
| 23503 |
v = c_fully_fold (v, false, NULL, true); |
| 23504 |
if (v == error_mark_node) |
| 23505 |
goto saw_error; |
| 23506 |
if (non_lvalue_p) |
| 23507 |
v = non_lvalue (v); |
| 23508 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 23509 |
goto saw_error; |
| 23510 |
eloc = c_parser_peek_token (parser)->location; |
| 23511 |
expr = c_parser_cast_expression (parser, NULL); |
| 23512 |
lhs1 = expr.value; |
| 23513 |
expr = default_function_array_read_conversion (eloc, expr); |
| 23514 |
unfolded_lhs1 = expr.value; |
| 23515 |
lhs1 = c_fully_fold (lhs1, false, NULL, true); |
| 23516 |
if (lhs1 == error_mark_node) |
| 23517 |
goto saw_error; |
| 23518 |
if (!lvalue_p (unfolded_lhs1)) |
| 23519 |
lhs1 = non_lvalue (lhs1); |
| 23520 |
} |
| 23521 |
if (structured_block) |
| 23522 |
{ |
| 23523 |
if (!no_semicolon) |
| 23524 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 23525 |
c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"); |
| 23526 |
} |
| 23527 |
done: |
| 23528 |
if (weak && opcode != COND_EXPR) |
| 23529 |
{ |
| 23530 |
error_at (loc, "%<weak%> clause requires atomic equality comparison"); |
| 23531 |
weak = false; |
| 23532 |
} |
| 23533 |
if (unfolded_lhs && unfolded_lhs1 |
| 23534 |
&& !c_tree_equal (unfolded_lhs, unfolded_lhs1)) |
| 23535 |
{ |
| 23536 |
error ("%<#pragma omp atomic capture%> uses two different " |
| 23537 |
"expressions for memory"); |
| 23538 |
stmt = error_mark_node; |
| 23539 |
} |
| 23540 |
else |
| 23541 |
stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, r, |
| 23542 |
swapped, memory_order, weak); |
| 23543 |
if (stmt != error_mark_node) |
| 23544 |
add_stmt (stmt); |
| 23545 |
|
| 23546 |
if (!structured_block && !no_semicolon) |
| 23547 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 23548 |
} |
| 23549 |
|
| 23550 |
|
| 23551 |
/* OpenMP 2.5: |
| 23552 |
# pragma omp barrier new-line |
| 23553 |
*/ |
| 23554 |
|
| 23555 |
static void |
| 23556 |
c_parser_omp_barrier (c_parser *parser) |
| 23557 |
{ |
| 23558 |
location_t loc = c_parser_peek_token (parser)->location; |
| 23559 |
c_parser_consume_pragma (parser); |
| 23560 |
c_parser_skip_to_pragma_eol (parser); |
| 23561 |
|
| 23562 |
c_finish_omp_barrier (loc); |
| 23563 |
} |
| 23564 |
|
| 23565 |
/* OpenMP 2.5: |
| 23566 |
# pragma omp critical [(name)] new-line |
| 23567 |
structured-block |
| 23568 |
|
| 23569 |
OpenMP 4.5: |
| 23570 |
# pragma omp critical [(name) [hint(expression)]] new-line |
| 23571 |
|
| 23572 |
LOC is the location of the #pragma itself. */ |
| 23573 |
|
| 23574 |
#define OMP_CRITICAL_CLAUSE_MASK \ |
| 23575 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) ) |
| 23576 |
|
| 23577 |
static tree |
| 23578 |
c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p) |
| 23579 |
{ |
| 23580 |
tree stmt, name = NULL_TREE, clauses = NULL_TREE; |
| 23581 |
|
| 23582 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 23583 |
{ |
| 23584 |
c_parser_consume_token (parser); |
| 23585 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 23586 |
{ |
| 23587 |
name = c_parser_peek_token (parser)->value; |
| 23588 |
c_parser_consume_token (parser); |
| 23589 |
c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
| 23590 |
} |
| 23591 |
else |
| 23592 |
c_parser_error (parser, "expected identifier"); |
| 23593 |
|
| 23594 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 23595 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 23596 |
c_parser_consume_token (parser); |
| 23597 |
} |
| 23598 |
clauses = c_parser_omp_all_clauses (parser, OMP_CRITICAL_CLAUSE_MASK, |
| 23599 |
"#pragma omp critical"); |
| 23600 |
stmt = c_parser_omp_structured_block (parser, if_p); |
| 23601 |
return c_finish_omp_critical (loc, stmt, name, clauses); |
| 23602 |
} |
| 23603 |
|
| 23604 |
/* OpenMP 5.0: |
| 23605 |
# pragma omp depobj ( depobj ) depobj-clause new-line |
| 23606 |
|
| 23607 |
depobj-clause: |
| 23608 |
depend (dependence-type : locator) |
| 23609 |
destroy |
| 23610 |
update (dependence-type) |
| 23611 |
|
| 23612 |
OpenMP 5.2 additionally: |
| 23613 |
destroy ( depobj ) |
| 23614 |
|
| 23615 |
dependence-type: |
| 23616 |
in |
| 23617 |
out |
| 23618 |
inout |
| 23619 |
mutexinout */ |
| 23620 |
|
| 23621 |
static void |
| 23622 |
c_parser_omp_depobj (c_parser *parser) |
| 23623 |
{ |
| 23624 |
location_t loc = c_parser_peek_token (parser)->location; |
| 23625 |
c_parser_consume_pragma (parser); |
| 23626 |
matching_parens parens; |
| 23627 |
if (!parens.require_open (parser)) |
| 23628 |
{ |
| 23629 |
c_parser_skip_to_pragma_eol (parser); |
| 23630 |
return; |
| 23631 |
} |
| 23632 |
|
| 23633 |
tree depobj = c_parser_expr_no_commas (parser, NULL).value; |
| 23634 |
if (depobj != error_mark_node) |
| 23635 |
{ |
| 23636 |
if (!lvalue_p (depobj)) |
| 23637 |
{ |
| 23638 |
error_at (EXPR_LOC_OR_LOC (depobj, loc), |
| 23639 |
"%<depobj%> expression is not lvalue expression"); |
| 23640 |
depobj = error_mark_node; |
| 23641 |
} |
| 23642 |
else |
| 23643 |
{ |
| 23644 |
tree addr = build_unary_op (EXPR_LOC_OR_LOC (depobj, loc), ADDR_EXPR, |
| 23645 |
depobj, false); |
| 23646 |
if (addr == error_mark_node) |
| 23647 |
depobj = error_mark_node; |
| 23648 |
else |
| 23649 |
depobj = build_indirect_ref (EXPR_LOC_OR_LOC (depobj, loc), |
| 23650 |
addr, RO_UNARY_STAR); |
| 23651 |
} |
| 23652 |
} |
| 23653 |
|
| 23654 |
parens.skip_until_found_close (parser); |
| 23655 |
tree clause = NULL_TREE; |
| 23656 |
enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INVALID; |
| 23657 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 23658 |
c_parser_consume_token (parser); |
| 23659 |
location_t c_loc = c_parser_peek_token (parser)->location; |
| 23660 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 23661 |
{ |
| 23662 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 23663 |
|
| 23664 |
c_parser_consume_token (parser); |
| 23665 |
if (!strcmp ("depend", p)) |
| 23666 |
{ |
| 23667 |
clause = c_parser_omp_clause_depend (parser, NULL_TREE); |
| 23668 |
clause = c_finish_omp_clauses (clause, C_ORT_OMP); |
| 23669 |
if (!clause) |
| 23670 |
clause = error_mark_node; |
| 23671 |
} |
| 23672 |
else if (!strcmp ("destroy", p)) |
| 23673 |
{ |
| 23674 |
matching_parens c_parens; |
| 23675 |
kind = OMP_CLAUSE_DEPEND_LAST; |
| 23676 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 23677 |
&& c_parens.require_open (parser)) |
| 23678 |
{ |
| 23679 |
tree destobj = c_parser_expr_no_commas (parser, NULL).value; |
| 23680 |
if (!lvalue_p (destobj)) |
| 23681 |
error_at (EXPR_LOC_OR_LOC (destobj, c_loc), |
| 23682 |
"%<destroy%> expression is not lvalue expression"); |
| 23683 |
else if (depobj != error_mark_node |
| 23684 |
&& !operand_equal_p (destobj, depobj, |
| 23685 |
OEP_MATCH_SIDE_EFFECTS |
| 23686 |
| OEP_LEXICOGRAPHIC)) |
| 23687 |
warning_at (EXPR_LOC_OR_LOC (destobj, c_loc), OPT_Wopenmp, |
| 23688 |
"the %<destroy%> expression %qE should be the same " |
| 23689 |
"as the %<depobj%> argument %qE", destobj, depobj); |
| 23690 |
c_parens.skip_until_found_close (parser); |
| 23691 |
} |
| 23692 |
} |
| 23693 |
else if (!strcmp ("update", p)) |
| 23694 |
{ |
| 23695 |
matching_parens c_parens; |
| 23696 |
if (c_parens.require_open (parser)) |
| 23697 |
{ |
| 23698 |
location_t c2_loc = c_parser_peek_token (parser)->location; |
| 23699 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 23700 |
{ |
| 23701 |
const char *p2 |
| 23702 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 23703 |
|
| 23704 |
c_parser_consume_token (parser); |
| 23705 |
if (!strcmp ("in", p2)) |
| 23706 |
kind = OMP_CLAUSE_DEPEND_IN; |
| 23707 |
else if (!strcmp ("out", p2)) |
| 23708 |
kind = OMP_CLAUSE_DEPEND_OUT; |
| 23709 |
else if (!strcmp ("inout", p2)) |
| 23710 |
kind = OMP_CLAUSE_DEPEND_INOUT; |
| 23711 |
else if (!strcmp ("mutexinoutset", p2)) |
| 23712 |
kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET; |
| 23713 |
else if (!strcmp ("inoutset", p2)) |
| 23714 |
kind = OMP_CLAUSE_DEPEND_INOUTSET; |
| 23715 |
} |
| 23716 |
if (kind == OMP_CLAUSE_DEPEND_INVALID) |
| 23717 |
{ |
| 23718 |
clause = error_mark_node; |
| 23719 |
error_at (c2_loc, "expected %<in%>, %<out%>, %<inout%>, " |
| 23720 |
"%<mutexinoutset%> or %<inoutset%>"); |
| 23721 |
} |
| 23722 |
c_parens.skip_until_found_close (parser); |
| 23723 |
} |
| 23724 |
else |
| 23725 |
clause = error_mark_node; |
| 23726 |
} |
| 23727 |
} |
| 23728 |
if (!clause && kind == OMP_CLAUSE_DEPEND_INVALID) |
| 23729 |
{ |
| 23730 |
clause = error_mark_node; |
| 23731 |
error_at (c_loc, "expected %<depend%>, %<destroy%> or %<update%> clause"); |
| 23732 |
} |
| 23733 |
c_parser_skip_to_pragma_eol (parser); |
| 23734 |
|
| 23735 |
c_finish_omp_depobj (loc, depobj, kind, clause); |
| 23736 |
} |
| 23737 |
|
| 23738 |
|
| 23739 |
/* OpenMP 2.5: |
| 23740 |
# pragma omp flush flush-vars[opt] new-line |
| 23741 |
|
| 23742 |
flush-vars: |
| 23743 |
( variable-list ) |
| 23744 |
|
| 23745 |
OpenMP 5.0: |
| 23746 |
# pragma omp flush memory-order-clause new-line */ |
| 23747 |
|
| 23748 |
static void |
| 23749 |
c_parser_omp_flush (c_parser *parser) |
| 23750 |
{ |
| 23751 |
location_t loc = c_parser_peek_token (parser)->location; |
| 23752 |
c_parser_consume_pragma (parser); |
| 23753 |
enum memmodel mo = MEMMODEL_LAST; |
| 23754 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 23755 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 23756 |
c_parser_consume_token (parser); |
| 23757 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 23758 |
{ |
| 23759 |
const char *p |
| 23760 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 23761 |
|
| 23762 |
if (!strcmp (p, "seq_cst")) |
| 23763 |
mo = MEMMODEL_SEQ_CST; |
| 23764 |
else if (!strcmp (p, "acq_rel")) |
| 23765 |
mo = MEMMODEL_ACQ_REL; |
| 23766 |
else if (!strcmp (p, "release")) |
| 23767 |
mo = MEMMODEL_RELEASE; |
| 23768 |
else if (!strcmp (p, "acquire")) |
| 23769 |
mo = MEMMODEL_ACQUIRE; |
| 23770 |
else |
| 23771 |
error_at (c_parser_peek_token (parser)->location, |
| 23772 |
"expected %<seq_cst%>, %<acq_rel%>, %<release%> or " |
| 23773 |
"%<acquire%>"); |
| 23774 |
c_parser_consume_token (parser); |
| 23775 |
} |
| 23776 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 23777 |
{ |
| 23778 |
if (mo != MEMMODEL_LAST) |
| 23779 |
error_at (c_parser_peek_token (parser)->location, |
| 23780 |
"%<flush%> list specified together with memory order " |
| 23781 |
"clause"); |
| 23782 |
c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
| 23783 |
} |
| 23784 |
else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 23785 |
c_parser_error (parser, "expected %<(%> or end of line"); |
| 23786 |
c_parser_skip_to_pragma_eol (parser); |
| 23787 |
|
| 23788 |
c_finish_omp_flush (loc, mo); |
| 23789 |
} |
| 23790 |
|
| 23791 |
/* Return true if next tokens contain a standard attribute that contains |
| 23792 |
omp::directive (DIRECTIVE). */ |
| 23793 |
|
| 23794 |
static bool |
| 23795 |
c_parser_omp_section_scan (c_parser *parser, const char *directive, |
| 23796 |
bool tentative) |
| 23797 |
{ |
| 23798 |
if (!c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 23799 |
return false; |
| 23800 |
unsigned int n = 3; |
| 23801 |
if (!c_parser_check_balanced_raw_token_sequence (parser, &n)) |
| 23802 |
return false; |
| 23803 |
c_token *token = c_parser_peek_nth_token_raw (parser, n); |
| 23804 |
if (token->type != CPP_CLOSE_SQUARE) |
| 23805 |
return false; |
| 23806 |
token = c_parser_peek_nth_token_raw (parser, n + 1); |
| 23807 |
if (token->type != CPP_CLOSE_SQUARE) |
| 23808 |
return false; |
| 23809 |
if (n < 9) |
| 23810 |
return false; |
| 23811 |
if (c_parser_peek_nth_token_raw (parser, 3)->type == CPP_NAME |
| 23812 |
&& c_parser_peek_nth_token_raw (parser, 4)->type == CPP_OPEN_PAREN |
| 23813 |
&& c_parser_peek_nth_token_raw (parser, 5)->type == CPP_NAME) |
| 23814 |
{ |
| 23815 |
tree first = c_parser_peek_nth_token_raw (parser, 3)->value; |
| 23816 |
tree second = c_parser_peek_nth_token_raw (parser, 5)->value; |
| 23817 |
if (strcmp (IDENTIFIER_POINTER (first), "directive") |
| 23818 |
&& strcmp (IDENTIFIER_POINTER (first), "__directive__")) |
| 23819 |
return false; |
| 23820 |
if (strcmp (IDENTIFIER_POINTER (second), directive)) |
| 23821 |
return false; |
| 23822 |
} |
| 23823 |
if (tentative) |
| 23824 |
return true; |
| 23825 |
location_t first_loc = c_parser_peek_token (parser)->location; |
| 23826 |
location_t last_loc = c_parser_peek_nth_token_raw (parser, n + 1)->location; |
| 23827 |
location_t middle_loc = UNKNOWN_LOCATION; |
| 23828 |
tree std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 23829 |
bool seen = false; |
| 23830 |
int cnt = 0; |
| 23831 |
for (tree attr = std_attrs; attr; attr = TREE_CHAIN (attr)) |
| 23832 |
if (is_attribute_namespace_p ("omp", attr) |
| 23833 |
&& is_attribute_p ("directive", get_attribute_name (attr))) |
| 23834 |
{ |
| 23835 |
for (tree a = TREE_VALUE (attr); a; a = TREE_CHAIN (a)) |
| 23836 |
{ |
| 23837 |
tree d = TREE_VALUE (a); |
| 23838 |
gcc_assert (TREE_CODE (d) == C_TOKEN_VEC); |
| 23839 |
c_token *first = C_TOKEN_VEC_TOKENS (d)->address (); |
| 23840 |
cnt++; |
| 23841 |
if (first->type == CPP_NAME |
| 23842 |
&& strcmp (IDENTIFIER_POINTER (first->value), |
| 23843 |
directive) == 0) |
| 23844 |
{ |
| 23845 |
seen = true; |
| 23846 |
if (middle_loc == UNKNOWN_LOCATION) |
| 23847 |
middle_loc = first->location; |
| 23848 |
} |
| 23849 |
} |
| 23850 |
} |
| 23851 |
if (!seen) |
| 23852 |
return false; |
| 23853 |
if (cnt != 1 || TREE_CHAIN (std_attrs)) |
| 23854 |
{ |
| 23855 |
error_at (make_location (first_loc, last_loc, middle_loc), |
| 23856 |
"%<[[omp::directive(%s)]]%> must be the only specified " |
| 23857 |
"attribute on a statement", directive); |
| 23858 |
return false; |
| 23859 |
} |
| 23860 |
c_parser_handle_statement_omp_attributes (parser, std_attrs, NULL); |
| 23861 |
return true; |
| 23862 |
} |
| 23863 |
|
| 23864 |
/* Parse an OpenMP structured block sequence. KIND is the corresponding |
| 23865 |
separating directive. */ |
| 23866 |
|
| 23867 |
static tree |
| 23868 |
c_parser_omp_structured_block_sequence (c_parser *parser, |
| 23869 |
enum pragma_kind kind) |
| 23870 |
{ |
| 23871 |
tree stmt = push_stmt_list (); |
| 23872 |
c_parser_statement (parser, NULL); |
| 23873 |
do |
| 23874 |
{ |
| 23875 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 23876 |
break; |
| 23877 |
if (c_parser_next_token_is (parser, CPP_EOF)) |
| 23878 |
break; |
| 23879 |
|
| 23880 |
if (kind != PRAGMA_NONE |
| 23881 |
&& c_parser_peek_token (parser)->pragma_kind == kind) |
| 23882 |
break; |
| 23883 |
|
| 23884 |
if (kind != PRAGMA_NONE |
| 23885 |
&& c_parser_omp_section_scan (parser, |
| 23886 |
kind == PRAGMA_OMP_SCAN |
| 23887 |
? "scan" : "section", false)) |
| 23888 |
break; |
| 23889 |
|
| 23890 |
c_parser_statement (parser, NULL); |
| 23891 |
} |
| 23892 |
while (1); |
| 23893 |
return pop_stmt_list (stmt); |
| 23894 |
} |
| 23895 |
|
| 23896 |
/* OpenMP 5.0: |
| 23897 |
|
| 23898 |
scan-loop-body: |
| 23899 |
{ structured-block scan-directive structured-block } */ |
| 23900 |
|
| 23901 |
static void |
| 23902 |
c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed) |
| 23903 |
{ |
| 23904 |
tree substmt; |
| 23905 |
location_t loc; |
| 23906 |
tree clauses = NULL_TREE; |
| 23907 |
bool found_scan = false; |
| 23908 |
|
| 23909 |
loc = c_parser_peek_token (parser)->location; |
| 23910 |
if (!open_brace_parsed |
| 23911 |
&& !c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 23912 |
{ |
| 23913 |
/* Avoid skipping until the end of the block. */ |
| 23914 |
parser->error = false; |
| 23915 |
return; |
| 23916 |
} |
| 23917 |
|
| 23918 |
if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SCAN) |
| 23919 |
substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_OMP_SCAN); |
| 23920 |
else |
| 23921 |
{ |
| 23922 |
warning_at (c_parser_peek_token (parser)->location, OPT_Wopenmp, |
| 23923 |
"%<#pragma omp scan%> with zero preceding executable " |
| 23924 |
"statements"); |
| 23925 |
substmt = build_empty_stmt (loc); |
| 23926 |
} |
| 23927 |
substmt = build2 (OMP_SCAN, void_type_node, substmt, NULL_TREE); |
| 23928 |
SET_EXPR_LOCATION (substmt, loc); |
| 23929 |
add_stmt (substmt); |
| 23930 |
|
| 23931 |
loc = c_parser_peek_token (parser)->location; |
| 23932 |
if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SCAN) |
| 23933 |
{ |
| 23934 |
enum omp_clause_code clause = OMP_CLAUSE_ERROR; |
| 23935 |
found_scan = true; |
| 23936 |
|
| 23937 |
c_parser_consume_pragma (parser); |
| 23938 |
|
| 23939 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 23940 |
c_parser_consume_token (parser); |
| 23941 |
|
| 23942 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 23943 |
{ |
| 23944 |
const char *p |
| 23945 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 23946 |
if (strcmp (p, "inclusive") == 0) |
| 23947 |
clause = OMP_CLAUSE_INCLUSIVE; |
| 23948 |
else if (strcmp (p, "exclusive") == 0) |
| 23949 |
clause = OMP_CLAUSE_EXCLUSIVE; |
| 23950 |
} |
| 23951 |
if (clause != OMP_CLAUSE_ERROR) |
| 23952 |
{ |
| 23953 |
c_parser_consume_token (parser); |
| 23954 |
clauses = c_parser_omp_var_list_parens (parser, clause, NULL_TREE); |
| 23955 |
} |
| 23956 |
else |
| 23957 |
c_parser_error (parser, "expected %<inclusive%> or " |
| 23958 |
"%<exclusive%> clause"); |
| 23959 |
c_parser_skip_to_pragma_eol (parser); |
| 23960 |
} |
| 23961 |
else |
| 23962 |
error ("expected %<#pragma omp scan%>"); |
| 23963 |
|
| 23964 |
clauses = c_finish_omp_clauses (clauses, C_ORT_OMP); |
| 23965 |
if (!c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 23966 |
substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_NONE); |
| 23967 |
else |
| 23968 |
{ |
| 23969 |
if (found_scan) |
| 23970 |
warning_at (loc, OPT_Wopenmp, |
| 23971 |
"%<#pragma omp scan%> with zero succeeding executable " |
| 23972 |
"statements"); |
| 23973 |
substmt = build_empty_stmt (loc); |
| 23974 |
} |
| 23975 |
substmt = build2 (OMP_SCAN, void_type_node, substmt, clauses); |
| 23976 |
SET_EXPR_LOCATION (substmt, loc); |
| 23977 |
add_stmt (substmt); |
| 23978 |
|
| 23979 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, |
| 23980 |
"expected %<}%>"); |
| 23981 |
} |
| 23982 |
|
| 23983 |
|
| 23984 |
/* Check if the next tokens can start a canonical loop. Return true if yes, |
| 23985 |
otherwise diagnose an error if ERROR_P is true, and return false. */ |
| 23986 |
static bool |
| 23987 |
c_parser_omp_next_tokens_can_be_canon_loop (c_parser *parser, |
| 23988 |
enum tree_code code, |
| 23989 |
bool error_p) |
| 23990 |
{ |
| 23991 |
if (code == OACC_LOOP) |
| 23992 |
{ |
| 23993 |
if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 23994 |
return true; |
| 23995 |
if (error_p) |
| 23996 |
c_parser_error (parser, "for statement expected"); |
| 23997 |
} |
| 23998 |
else |
| 23999 |
{ |
| 24000 |
if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 24001 |
return true; |
| 24002 |
|
| 24003 |
if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 24004 |
switch (c_parser_peek_token (parser)->pragma_kind) |
| 24005 |
{ |
| 24006 |
case PRAGMA_OMP_UNROLL: |
| 24007 |
case PRAGMA_OMP_TILE: |
| 24008 |
return true; |
| 24009 |
default: |
| 24010 |
break; |
| 24011 |
} |
| 24012 |
|
| 24013 |
/* Skip standard attributes on next for in case they are |
| 24014 |
[[omp::directive (unroll partial (4))]] or |
| 24015 |
[[omp::directive (tile sizes (1, 2, 3))]] etc. */ |
| 24016 |
size_t n = c_parser_skip_std_attribute_spec_seq (parser, 1); |
| 24017 |
c_token *token = c_parser_peek_nth_token_raw (parser, n); |
| 24018 |
/* TOKEN is a raw token that hasn't been converted to a keyword yet, |
| 24019 |
we have to do the lookup explicitly. */ |
| 24020 |
if (token->type == CPP_NAME |
| 24021 |
&& C_IS_RESERVED_WORD (token->value) |
| 24022 |
&& C_RID_CODE (token->value) == RID_FOR) |
| 24023 |
return true; |
| 24024 |
if (error_p) |
| 24025 |
c_parser_error (parser, "loop nest expected"); |
| 24026 |
} |
| 24027 |
|
| 24028 |
return false; |
| 24029 |
} |
| 24030 |
|
| 24031 |
static tree c_parser_omp_tile (location_t, c_parser *, bool *); |
| 24032 |
static tree c_parser_omp_unroll (location_t, c_parser *, bool *); |
| 24033 |
|
| 24034 |
/* This function parses a single level of a loop nest, invoking itself |
| 24035 |
recursively if necessary. |
| 24036 |
|
| 24037 |
loop-nest :: for (...) loop-body |
| 24038 |
loop-body :: loop-nest |
| 24039 |
| { [intervening-code] loop-body [intervening-code] } |
| 24040 |
| final-loop-body |
| 24041 |
intervening-code :: structured-block-sequence |
| 24042 |
final-loop-body :: structured-block |
| 24043 |
|
| 24044 |
For a collapsed loop nest, only a single OMP_FOR is built, pulling out |
| 24045 |
all the iterator information from the inner loops into the |
| 24046 |
parser->omp_for_parse_state structure. |
| 24047 |
|
| 24048 |
The iterator decl, init, cond, and incr are stored in vectors. |
| 24049 |
|
| 24050 |
Initialization code for iterator variables is collected into |
| 24051 |
parser->omp_for_parse_state->pre_body and ends up inserted directly |
| 24052 |
into the OMP_FOR structure. */ |
| 24053 |
|
| 24054 |
static tree |
| 24055 |
c_parser_omp_loop_nest (c_parser *parser, bool *if_p) |
| 24056 |
{ |
| 24057 |
tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE; |
| 24058 |
tree body = NULL_TREE; |
| 24059 |
matching_parens parens; |
| 24060 |
bool moreloops; |
| 24061 |
unsigned char save_in_statement; |
| 24062 |
tree loop_scope; |
| 24063 |
location_t loc; |
| 24064 |
struct omp_for_parse_data *omp_for_parse_state |
| 24065 |
= parser->omp_for_parse_state; |
| 24066 |
gcc_assert (omp_for_parse_state); |
| 24067 |
int depth = omp_for_parse_state->depth; |
| 24068 |
|
| 24069 |
/* Arrange for C23 standard attribute syntax to be parsed as regular |
| 24070 |
pragmas. */ |
| 24071 |
if (c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 24072 |
{ |
| 24073 |
tree std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 24074 |
c_parser_handle_statement_omp_attributes (parser, std_attrs, NULL); |
| 24075 |
if (std_attrs) |
| 24076 |
error_at (c_parser_peek_token (parser)->location, |
| 24077 |
"attributes other than OpenMP directives " |
| 24078 |
"are not allowed on %<for%> in loop nest"); |
| 24079 |
} |
| 24080 |
|
| 24081 |
loc = c_parser_peek_token (parser)->location; |
| 24082 |
|
| 24083 |
/* Handle loop transformations first. */ |
| 24084 |
if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 24085 |
{ |
| 24086 |
tree transform = NULL_TREE, sizes, body = NULL_TREE; |
| 24087 |
int count = 0; |
| 24088 |
switch (c_parser_peek_token (parser)->pragma_kind) |
| 24089 |
{ |
| 24090 |
case PRAGMA_OMP_UNROLL: |
| 24091 |
c_parser_consume_pragma (parser); |
| 24092 |
body = push_stmt_list (); |
| 24093 |
transform = c_parser_omp_unroll (loc, parser, if_p); |
| 24094 |
body = pop_stmt_list (body); |
| 24095 |
if (transform == NULL_TREE || transform == error_mark_node) |
| 24096 |
{ |
| 24097 |
transform = error_mark_node; |
| 24098 |
break; |
| 24099 |
} |
| 24100 |
gcc_assert (TREE_CODE (transform) == OMP_UNROLL); |
| 24101 |
if (omp_find_clause (OMP_FOR_CLAUSES (transform), |
| 24102 |
OMP_CLAUSE_PARTIAL)) |
| 24103 |
{ |
| 24104 |
if (omp_for_parse_state->count - depth > 1) |
| 24105 |
{ |
| 24106 |
error_at (loc, "%<unroll%> construct with %<partial%> " |
| 24107 |
"clause generates just one loop with " |
| 24108 |
"canonical form but %d loops are needed", |
| 24109 |
omp_for_parse_state->count - depth); |
| 24110 |
transform = error_mark_node; |
| 24111 |
} |
| 24112 |
else |
| 24113 |
count = 1; |
| 24114 |
} |
| 24115 |
else |
| 24116 |
{ |
| 24117 |
error_at (loc, "generated loop of %<unroll%> construct " |
| 24118 |
"without %<partial%> clause does not have " |
| 24119 |
"canonical form"); |
| 24120 |
transform = error_mark_node; |
| 24121 |
} |
| 24122 |
break; |
| 24123 |
case PRAGMA_OMP_TILE: |
| 24124 |
c_parser_consume_pragma (parser); |
| 24125 |
body = push_stmt_list (); |
| 24126 |
transform = c_parser_omp_tile (loc, parser, if_p); |
| 24127 |
body = pop_stmt_list (body); |
| 24128 |
if (transform == NULL_TREE || transform == error_mark_node) |
| 24129 |
{ |
| 24130 |
transform = error_mark_node; |
| 24131 |
break; |
| 24132 |
} |
| 24133 |
gcc_assert (TREE_CODE (transform) == OMP_TILE); |
| 24134 |
sizes = omp_find_clause (OMP_FOR_CLAUSES (transform), |
| 24135 |
OMP_CLAUSE_SIZES); |
| 24136 |
gcc_assert (sizes); |
| 24137 |
count = list_length (OMP_CLAUSE_SIZES_LIST (sizes)); |
| 24138 |
if (depth + count < omp_for_parse_state->count) |
| 24139 |
{ |
| 24140 |
error_at (loc, "%<tile%> construct generates %d loops " |
| 24141 |
"with canonical form but %d loops are needed", |
| 24142 |
count, omp_for_parse_state->count - depth); |
| 24143 |
transform = error_mark_node; |
| 24144 |
} |
| 24145 |
break; |
| 24146 |
default: |
| 24147 |
c_parser_pragma (parser, pragma_stmt, NULL, void_list_node); |
| 24148 |
break; |
| 24149 |
} |
| 24150 |
if (transform == NULL_TREE) |
| 24151 |
error_at (loc, "expected %<for%> loop or OpenMP loop " |
| 24152 |
"transformation construct"); |
| 24153 |
if (transform == NULL_TREE || transform == error_mark_node) |
| 24154 |
{ |
| 24155 |
omp_for_parse_state->fail = true; |
| 24156 |
return NULL_TREE; |
| 24157 |
} |
| 24158 |
for (count = omp_for_parse_state->count; depth < count; ++depth) |
| 24159 |
{ |
| 24160 |
TREE_VEC_ELT (omp_for_parse_state->declv, depth) = NULL_TREE; |
| 24161 |
TREE_VEC_ELT (omp_for_parse_state->initv, depth) = NULL_TREE; |
| 24162 |
TREE_VEC_ELT (omp_for_parse_state->condv, depth) = NULL_TREE; |
| 24163 |
TREE_VEC_ELT (omp_for_parse_state->incrv, depth) = NULL_TREE; |
| 24164 |
} |
| 24165 |
omp_for_parse_state->want_nested_loop = false; |
| 24166 |
return body; |
| 24167 |
} |
| 24168 |
|
| 24169 |
/* We have already matched the FOR token but not consumed it yet. */ |
| 24170 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); |
| 24171 |
c_parser_consume_token (parser); |
| 24172 |
|
| 24173 |
/* Forbid break/continue in the loop initializer, condition, and |
| 24174 |
increment expressions. */ |
| 24175 |
save_in_statement = in_statement; |
| 24176 |
in_statement = IN_OMP_BLOCK; |
| 24177 |
|
| 24178 |
/* We are not in intervening code now. */ |
| 24179 |
omp_for_parse_state->in_intervening_code = false; |
| 24180 |
|
| 24181 |
if (!parens.require_open (parser)) |
| 24182 |
{ |
| 24183 |
omp_for_parse_state->fail = true; |
| 24184 |
return NULL_TREE; |
| 24185 |
} |
| 24186 |
|
| 24187 |
/* An implicit scope block surrounds each level of FOR loop, for |
| 24188 |
declarations of iteration variables at this loop depth. */ |
| 24189 |
loop_scope = c_begin_compound_stmt (true); |
| 24190 |
|
| 24191 |
/* Parse the initialization declaration or expression. */ |
| 24192 |
if (c_parser_next_tokens_start_declaration (parser)) |
| 24193 |
{ |
| 24194 |
/* This is a declaration, which must be added to the pre_body code. */ |
| 24195 |
tree this_pre_body = push_stmt_list (); |
| 24196 |
c_in_omp_for = true; |
| 24197 |
c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
| 24198 |
false); |
| 24199 |
c_in_omp_for = false; |
| 24200 |
this_pre_body = pop_stmt_list (this_pre_body); |
| 24201 |
append_to_statement_list_force (this_pre_body, |
| 24202 |
&(omp_for_parse_state->pre_body)); |
| 24203 |
decl = check_for_loop_decls (omp_for_parse_state->for_loc, flag_isoc99); |
| 24204 |
if (decl == NULL) |
| 24205 |
goto error_init; |
| 24206 |
if (DECL_INITIAL (decl) == error_mark_node) |
| 24207 |
decl = error_mark_node; |
| 24208 |
init = decl; |
| 24209 |
} |
| 24210 |
else if (c_parser_next_token_is (parser, CPP_NAME) |
| 24211 |
&& c_parser_peek_2nd_token (parser)->type == CPP_EQ) |
| 24212 |
{ |
| 24213 |
struct c_expr decl_exp; |
| 24214 |
struct c_expr init_exp; |
| 24215 |
location_t init_loc; |
| 24216 |
|
| 24217 |
decl_exp = c_parser_postfix_expression (parser); |
| 24218 |
decl = decl_exp.value; |
| 24219 |
|
| 24220 |
c_parser_require (parser, CPP_EQ, "expected %<=%>"); |
| 24221 |
|
| 24222 |
init_loc = c_parser_peek_token (parser)->location; |
| 24223 |
init_exp = c_parser_expr_no_commas (parser, NULL); |
| 24224 |
init_exp = default_function_array_read_conversion (init_loc, |
| 24225 |
init_exp); |
| 24226 |
c_in_omp_for = true; |
| 24227 |
init = build_modify_expr (init_loc, decl, decl_exp.original_type, |
| 24228 |
NOP_EXPR, init_loc, init_exp.value, |
| 24229 |
init_exp.original_type); |
| 24230 |
c_in_omp_for = false; |
| 24231 |
init = c_process_expr_stmt (init_loc, init); |
| 24232 |
|
| 24233 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 24234 |
} |
| 24235 |
else |
| 24236 |
{ |
| 24237 |
error_init: |
| 24238 |
c_parser_error (parser, |
| 24239 |
"expected iteration declaration or initialization"); |
| 24240 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 24241 |
"expected %<)%>"); |
| 24242 |
omp_for_parse_state->fail = true; |
| 24243 |
goto parse_next; |
| 24244 |
} |
| 24245 |
|
| 24246 |
/* Parse the loop condition. */ |
| 24247 |
if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) |
| 24248 |
{ |
| 24249 |
location_t cond_loc = c_parser_peek_token (parser)->location; |
| 24250 |
c_in_omp_for = true; |
| 24251 |
struct c_expr cond_expr |
| 24252 |
= c_parser_binary_expression (parser, NULL, NULL_TREE); |
| 24253 |
c_in_omp_for = false; |
| 24254 |
|
| 24255 |
cond = cond_expr.value; |
| 24256 |
cond = c_objc_common_truthvalue_conversion (cond_loc, cond); |
| 24257 |
switch (cond_expr.original_code) |
| 24258 |
{ |
| 24259 |
case GT_EXPR: |
| 24260 |
case GE_EXPR: |
| 24261 |
case LT_EXPR: |
| 24262 |
case LE_EXPR: |
| 24263 |
break; |
| 24264 |
case NE_EXPR: |
| 24265 |
if (omp_for_parse_state->code != OACC_LOOP) |
| 24266 |
break; |
| 24267 |
/* FALLTHRU. */ |
| 24268 |
default: |
| 24269 |
/* Can't be cond = error_mark_node, because we want to preserve |
| 24270 |
the location until c_finish_omp_for. */ |
| 24271 |
cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); |
| 24272 |
break; |
| 24273 |
} |
| 24274 |
protected_set_expr_location (cond, cond_loc); |
| 24275 |
} |
| 24276 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 24277 |
|
| 24278 |
/* Parse the increment expression. */ |
| 24279 |
if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) |
| 24280 |
{ |
| 24281 |
location_t incr_loc = c_parser_peek_token (parser)->location; |
| 24282 |
|
| 24283 |
incr = c_process_expr_stmt (incr_loc, |
| 24284 |
c_parser_expression (parser).value); |
| 24285 |
} |
| 24286 |
parens.skip_until_found_close (parser); |
| 24287 |
|
| 24288 |
if (decl == NULL || decl == error_mark_node || init == error_mark_node) |
| 24289 |
omp_for_parse_state->fail = true; |
| 24290 |
else |
| 24291 |
{ |
| 24292 |
TREE_VEC_ELT (omp_for_parse_state->declv, depth) = decl; |
| 24293 |
TREE_VEC_ELT (omp_for_parse_state->initv, depth) = init; |
| 24294 |
TREE_VEC_ELT (omp_for_parse_state->condv, depth) = cond; |
| 24295 |
TREE_VEC_ELT (omp_for_parse_state->incrv, depth) = incr; |
| 24296 |
} |
| 24297 |
|
| 24298 |
parse_next: |
| 24299 |
moreloops = depth < omp_for_parse_state->count - 1; |
| 24300 |
omp_for_parse_state->want_nested_loop = moreloops; |
| 24301 |
if (moreloops |
| 24302 |
&& c_parser_omp_next_tokens_can_be_canon_loop (parser, |
| 24303 |
omp_for_parse_state->code, |
| 24304 |
false)) |
| 24305 |
{ |
| 24306 |
omp_for_parse_state->depth++; |
| 24307 |
body = c_parser_omp_loop_nest (parser, if_p); |
| 24308 |
omp_for_parse_state->depth--; |
| 24309 |
} |
| 24310 |
else if (moreloops && c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 24311 |
{ |
| 24312 |
/* This is the open brace in the loop-body grammar production. Rather |
| 24313 |
than trying to special-case braces, just parse it as a compound |
| 24314 |
statement and handle the nested loop-body case there. Note that |
| 24315 |
when we see a further open brace inside the compound statement |
| 24316 |
loop-body, we don't know whether it is the start of intervening |
| 24317 |
code that is a compound statement, or a level of braces |
| 24318 |
surrounding a nested loop-body. Use the WANT_NESTED_LOOP state |
| 24319 |
bit to ensure we have only one nested loop at each level. */ |
| 24320 |
omp_for_parse_state->in_intervening_code = true; |
| 24321 |
body = c_parser_compound_statement (parser, NULL); |
| 24322 |
omp_for_parse_state->in_intervening_code = false; |
| 24323 |
if (omp_for_parse_state->want_nested_loop) |
| 24324 |
{ |
| 24325 |
/* We have already parsed the whole loop body and not found a |
| 24326 |
nested loop. */ |
| 24327 |
error_at (omp_for_parse_state->for_loc, |
| 24328 |
"not enough nested loops"); |
| 24329 |
omp_for_parse_state->fail = true; |
| 24330 |
} |
| 24331 |
if_p = NULL; |
| 24332 |
} |
| 24333 |
else |
| 24334 |
{ |
| 24335 |
/* This is the final-loop-body case in the grammar: we have |
| 24336 |
something that is not a FOR and not an open brace. */ |
| 24337 |
if (moreloops) |
| 24338 |
{ |
| 24339 |
/* If we were expecting a nested loop, give an error and mark |
| 24340 |
that parsing has failed, and try to recover by parsing the |
| 24341 |
body as regular code without further collapsing. */ |
| 24342 |
error_at (omp_for_parse_state->for_loc, |
| 24343 |
"not enough nested loops"); |
| 24344 |
omp_for_parse_state->fail = true; |
| 24345 |
} |
| 24346 |
in_statement = IN_OMP_FOR; |
| 24347 |
parser->omp_for_parse_state = NULL; |
| 24348 |
body = push_stmt_list (); |
| 24349 |
if (omp_for_parse_state->inscan) |
| 24350 |
c_parser_omp_scan_loop_body (parser, false); |
| 24351 |
else |
| 24352 |
add_stmt (c_parser_c99_block_statement (parser, if_p)); |
| 24353 |
body = pop_stmt_list (body); |
| 24354 |
parser->omp_for_parse_state = omp_for_parse_state; |
| 24355 |
} |
| 24356 |
in_statement = save_in_statement; |
| 24357 |
omp_for_parse_state->want_nested_loop = false; |
| 24358 |
omp_for_parse_state->in_intervening_code = true; |
| 24359 |
|
| 24360 |
/* Pop and return the implicit scope surrounding this level of loop. |
| 24361 |
If the iteration variable at this depth was bound in the for loop, |
| 24362 |
pull out and save the binding. Later in c_parser_omp_for_loop, |
| 24363 |
these bindings will be moved to the scope surrounding the entire |
| 24364 |
OMP_FOR. That keeps the gimplifier happy later on, and meanwhile |
| 24365 |
we have already resolved all references to the iteration variable |
| 24366 |
in its true scope. */ |
| 24367 |
if (body) |
| 24368 |
add_stmt (body); |
| 24369 |
body = c_end_compound_stmt (loc, loop_scope, true); |
| 24370 |
if (decl && TREE_CODE (body) == BIND_EXPR) |
| 24371 |
{ |
| 24372 |
tree t = BIND_EXPR_VARS (body); |
| 24373 |
tree prev = NULL_TREE, next = NULL_TREE; |
| 24374 |
while (t) |
| 24375 |
{ |
| 24376 |
next = DECL_CHAIN (t); |
| 24377 |
if (t == decl) |
| 24378 |
{ |
| 24379 |
if (prev) |
| 24380 |
DECL_CHAIN (prev) = next; |
| 24381 |
else |
| 24382 |
{ |
| 24383 |
BIND_EXPR_VARS (body) = next; |
| 24384 |
BLOCK_VARS (BIND_EXPR_BLOCK (body)) = next; |
| 24385 |
} |
| 24386 |
DECL_CHAIN (t) = omp_for_parse_state->bindings; |
| 24387 |
omp_for_parse_state->bindings = t; |
| 24388 |
break; |
| 24389 |
} |
| 24390 |
else |
| 24391 |
{ |
| 24392 |
prev = t; |
| 24393 |
t = next; |
| 24394 |
} |
| 24395 |
} |
| 24396 |
if (BIND_EXPR_VARS (body) == NULL_TREE) |
| 24397 |
body = BIND_EXPR_BODY (body); |
| 24398 |
} |
| 24399 |
|
| 24400 |
return body; |
| 24401 |
} |
| 24402 |
|
| 24403 |
/* Parse the restricted form of loop statements allowed by OpenACC and OpenMP. |
| 24404 |
The real trick here is to determine the loop control variable early |
| 24405 |
so that we can push a new decl if necessary to make it private. |
| 24406 |
LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp", |
| 24407 |
respectively. */ |
| 24408 |
|
| 24409 |
static tree |
| 24410 |
c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, |
| 24411 |
tree clauses, tree *cclauses, bool *if_p) |
| 24412 |
{ |
| 24413 |
tree body, stmt, cl; |
| 24414 |
tree ret = NULL_TREE; |
| 24415 |
tree ordered_cl = NULL_TREE; |
| 24416 |
int i, collapse = 1, ordered = 0, count; |
| 24417 |
bool oacc_tiling = false; |
| 24418 |
bool inscan = false; |
| 24419 |
struct omp_for_parse_data data; |
| 24420 |
struct omp_for_parse_data *save_data = parser->omp_for_parse_state; |
| 24421 |
|
| 24422 |
for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) |
| 24423 |
if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) |
| 24424 |
collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl)); |
| 24425 |
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE) |
| 24426 |
{ |
| 24427 |
oacc_tiling = true; |
| 24428 |
collapse = list_length (OMP_CLAUSE_TILE_LIST (cl)); |
| 24429 |
} |
| 24430 |
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_SIZES) |
| 24431 |
collapse = list_length (OMP_CLAUSE_SIZES_LIST (cl)); |
| 24432 |
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED |
| 24433 |
&& OMP_CLAUSE_ORDERED_EXPR (cl)) |
| 24434 |
{ |
| 24435 |
ordered_cl = cl; |
| 24436 |
ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl)); |
| 24437 |
} |
| 24438 |
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_REDUCTION |
| 24439 |
&& OMP_CLAUSE_REDUCTION_INSCAN (cl) |
| 24440 |
&& (code == OMP_SIMD || code == OMP_FOR)) |
| 24441 |
inscan = true; |
| 24442 |
|
| 24443 |
if (ordered && ordered < collapse) |
| 24444 |
{ |
| 24445 |
error_at (OMP_CLAUSE_LOCATION (ordered_cl), |
| 24446 |
"%<ordered%> clause parameter is less than %<collapse%>"); |
| 24447 |
OMP_CLAUSE_ORDERED_EXPR (ordered_cl) |
| 24448 |
= build_int_cst (NULL_TREE, collapse); |
| 24449 |
ordered = collapse; |
| 24450 |
} |
| 24451 |
|
| 24452 |
gcc_assert (oacc_tiling || (collapse >= 1 && ordered >= 0)); |
| 24453 |
count = ordered ? ordered : collapse; |
| 24454 |
|
| 24455 |
if (!c_parser_omp_next_tokens_can_be_canon_loop (parser, code, true)) |
| 24456 |
return NULL; |
| 24457 |
|
| 24458 |
/* Initialize parse state for recursive descent. */ |
| 24459 |
data.declv = make_tree_vec (count); |
| 24460 |
data.initv = make_tree_vec (count); |
| 24461 |
data.condv = make_tree_vec (count); |
| 24462 |
data.incrv = make_tree_vec (count); |
| 24463 |
data.pre_body = NULL_TREE; |
| 24464 |
data.bindings = NULL_TREE; |
| 24465 |
data.for_loc = c_parser_peek_token (parser)->location; |
| 24466 |
data.count = count; |
| 24467 |
data.depth = 0; |
| 24468 |
data.want_nested_loop = true; |
| 24469 |
data.ordered = ordered > 0; |
| 24470 |
data.in_intervening_code = false; |
| 24471 |
data.perfect_nesting_fail = false; |
| 24472 |
data.fail = false; |
| 24473 |
data.inscan = inscan; |
| 24474 |
data.saw_intervening_code = false; |
| 24475 |
data.code = code; |
| 24476 |
parser->omp_for_parse_state = &data; |
| 24477 |
|
| 24478 |
body = c_parser_omp_loop_nest (parser, if_p); |
| 24479 |
|
| 24480 |
/* Add saved bindings for iteration variables that were declared in |
| 24481 |
the nested for loop to the scope surrounding the entire loop. */ |
| 24482 |
for (tree t = data.bindings; t; ) |
| 24483 |
{ |
| 24484 |
tree n = TREE_CHAIN (t); |
| 24485 |
TREE_CHAIN (t) = NULL_TREE; |
| 24486 |
pushdecl (t); |
| 24487 |
t = n; |
| 24488 |
} |
| 24489 |
|
| 24490 |
/* Only bother calling c_finish_omp_for if we haven't already generated |
| 24491 |
an error from the initialization parsing. */ |
| 24492 |
if (!data.fail) |
| 24493 |
{ |
| 24494 |
c_in_omp_for = true; |
| 24495 |
stmt = c_finish_omp_for (loc, code, data.declv, NULL, data.initv, |
| 24496 |
data.condv, data.incrv, |
| 24497 |
body, data.pre_body, true); |
| 24498 |
c_in_omp_for = false; |
| 24499 |
|
| 24500 |
/* Check for iterators appearing in lb, b or incr expressions. */ |
| 24501 |
if (stmt && !c_omp_check_loop_iv (stmt, data.declv, NULL)) |
| 24502 |
stmt = NULL_TREE; |
| 24503 |
|
| 24504 |
/* Check for errors involving lb/ub/incr expressions referencing |
| 24505 |
variables declared in intervening code. */ |
| 24506 |
if (data.saw_intervening_code |
| 24507 |
&& stmt |
| 24508 |
&& !c_omp_check_loop_binding_exprs (stmt, NULL)) |
| 24509 |
stmt = NULL_TREE; |
| 24510 |
|
| 24511 |
if (stmt) |
| 24512 |
{ |
| 24513 |
add_stmt (stmt); |
| 24514 |
|
| 24515 |
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (stmt)); i++) |
| 24516 |
{ |
| 24517 |
tree init = TREE_VEC_ELT (OMP_FOR_INIT (stmt), i); |
| 24518 |
if (init == NULL_TREE) |
| 24519 |
break; |
| 24520 |
gcc_assert (TREE_CODE (init) == MODIFY_EXPR); |
| 24521 |
tree decl = TREE_OPERAND (init, 0); |
| 24522 |
tree cond = TREE_VEC_ELT (OMP_FOR_COND (stmt), i); |
| 24523 |
gcc_assert (COMPARISON_CLASS_P (cond)); |
| 24524 |
gcc_assert (TREE_OPERAND (cond, 0) == decl); |
| 24525 |
|
| 24526 |
tree op0 = TREE_OPERAND (init, 1); |
| 24527 |
if (!OMP_FOR_NON_RECTANGULAR (stmt) |
| 24528 |
|| TREE_CODE (op0) != TREE_VEC) |
| 24529 |
TREE_OPERAND (init, 1) = c_fully_fold (op0, false, NULL); |
| 24530 |
else |
| 24531 |
{ |
| 24532 |
TREE_VEC_ELT (op0, 1) |
| 24533 |
= c_fully_fold (TREE_VEC_ELT (op0, 1), false, NULL); |
| 24534 |
TREE_VEC_ELT (op0, 2) |
| 24535 |
= c_fully_fold (TREE_VEC_ELT (op0, 2), false, NULL); |
| 24536 |
} |
| 24537 |
|
| 24538 |
tree op1 = TREE_OPERAND (cond, 1); |
| 24539 |
if (!OMP_FOR_NON_RECTANGULAR (stmt) |
| 24540 |
|| TREE_CODE (op1) != TREE_VEC) |
| 24541 |
TREE_OPERAND (cond, 1) = c_fully_fold (op1, false, NULL); |
| 24542 |
else |
| 24543 |
{ |
| 24544 |
TREE_VEC_ELT (op1, 1) |
| 24545 |
= c_fully_fold (TREE_VEC_ELT (op1, 1), false, NULL); |
| 24546 |
TREE_VEC_ELT (op1, 2) |
| 24547 |
= c_fully_fold (TREE_VEC_ELT (op1, 2), false, NULL); |
| 24548 |
} |
| 24549 |
} |
| 24550 |
|
| 24551 |
if (cclauses != NULL |
| 24552 |
&& cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL) |
| 24553 |
{ |
| 24554 |
tree *c; |
| 24555 |
for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; ) |
| 24556 |
if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE |
| 24557 |
&& OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) |
| 24558 |
c = &OMP_CLAUSE_CHAIN (*c); |
| 24559 |
else |
| 24560 |
{ |
| 24561 |
for (i = 0; i < count; i++) |
| 24562 |
if (TREE_VEC_ELT (data.declv, i) == OMP_CLAUSE_DECL (*c)) |
| 24563 |
break; |
| 24564 |
if (i == count) |
| 24565 |
c = &OMP_CLAUSE_CHAIN (*c); |
| 24566 |
else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) |
| 24567 |
{ |
| 24568 |
error_at (loc, |
| 24569 |
"iteration variable %qD should not be firstprivate", |
| 24570 |
OMP_CLAUSE_DECL (*c)); |
| 24571 |
*c = OMP_CLAUSE_CHAIN (*c); |
| 24572 |
} |
| 24573 |
else |
| 24574 |
{ |
| 24575 |
/* Move lastprivate (decl) clause to |
| 24576 |
OMP_FOR_CLAUSES. */ |
| 24577 |
tree l = *c; |
| 24578 |
*c = OMP_CLAUSE_CHAIN (*c); |
| 24579 |
if (code == OMP_SIMD) |
| 24580 |
{ |
| 24581 |
OMP_CLAUSE_CHAIN (l) |
| 24582 |
= cclauses[C_OMP_CLAUSE_SPLIT_FOR]; |
| 24583 |
cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l; |
| 24584 |
} |
| 24585 |
else |
| 24586 |
{ |
| 24587 |
OMP_CLAUSE_CHAIN (l) = clauses; |
| 24588 |
clauses = l; |
| 24589 |
} |
| 24590 |
} |
| 24591 |
} |
| 24592 |
} |
| 24593 |
OMP_FOR_CLAUSES (stmt) = clauses; |
| 24594 |
} |
| 24595 |
ret = stmt; |
| 24596 |
} |
| 24597 |
|
| 24598 |
parser->omp_for_parse_state = save_data; |
| 24599 |
return ret; |
| 24600 |
} |
| 24601 |
|
| 24602 |
/* Helper function for OpenMP parsing, split clauses and call |
| 24603 |
finish_omp_clauses on each of the set of clauses afterwards. */ |
| 24604 |
|
| 24605 |
static void |
| 24606 |
omp_split_clauses (location_t loc, enum tree_code code, |
| 24607 |
omp_clause_mask mask, tree clauses, tree *cclauses) |
| 24608 |
{ |
| 24609 |
int i; |
| 24610 |
c_omp_split_clauses (loc, code, mask, clauses, cclauses); |
| 24611 |
for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) |
| 24612 |
if (cclauses[i]) |
| 24613 |
cclauses[i] = c_finish_omp_clauses (cclauses[i], |
| 24614 |
i == C_OMP_CLAUSE_SPLIT_TARGET |
| 24615 |
? C_ORT_OMP_TARGET : C_ORT_OMP); |
| 24616 |
} |
| 24617 |
|
| 24618 |
/* OpenMP 5.0: |
| 24619 |
#pragma omp loop loop-clause[optseq] new-line |
| 24620 |
for-loop |
| 24621 |
|
| 24622 |
LOC is the location of the #pragma token. |
| 24623 |
*/ |
| 24624 |
|
| 24625 |
#define OMP_LOOP_CLAUSE_MASK \ |
| 24626 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 24627 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 24628 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 24629 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
| 24630 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_BIND) \ |
| 24631 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER)) |
| 24632 |
|
| 24633 |
static tree |
| 24634 |
c_parser_omp_loop (location_t loc, c_parser *parser, |
| 24635 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 24636 |
bool *if_p) |
| 24637 |
{ |
| 24638 |
tree block, clauses, ret; |
| 24639 |
|
| 24640 |
strcat (p_name, " loop"); |
| 24641 |
mask |= OMP_LOOP_CLAUSE_MASK; |
| 24642 |
|
| 24643 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 24644 |
if (cclauses) |
| 24645 |
{ |
| 24646 |
omp_split_clauses (loc, OMP_LOOP, mask, clauses, cclauses); |
| 24647 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_LOOP]; |
| 24648 |
} |
| 24649 |
|
| 24650 |
block = c_begin_compound_stmt (true); |
| 24651 |
ret = c_parser_omp_for_loop (loc, parser, OMP_LOOP, clauses, cclauses, if_p); |
| 24652 |
block = c_end_compound_stmt (loc, block, true); |
| 24653 |
add_stmt (block); |
| 24654 |
|
| 24655 |
return ret; |
| 24656 |
} |
| 24657 |
|
| 24658 |
/* OpenMP 4.0: |
| 24659 |
#pragma omp simd simd-clause[optseq] new-line |
| 24660 |
for-loop |
| 24661 |
|
| 24662 |
LOC is the location of the #pragma token. |
| 24663 |
*/ |
| 24664 |
|
| 24665 |
#define OMP_SIMD_CLAUSE_MASK \ |
| 24666 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \ |
| 24667 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ |
| 24668 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
| 24669 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ |
| 24670 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 24671 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 24672 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 24673 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
| 24674 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 24675 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL) \ |
| 24676 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER)) |
| 24677 |
|
| 24678 |
static tree |
| 24679 |
c_parser_omp_simd (location_t loc, c_parser *parser, |
| 24680 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 24681 |
bool *if_p) |
| 24682 |
{ |
| 24683 |
tree block, clauses, ret; |
| 24684 |
|
| 24685 |
strcat (p_name, " simd"); |
| 24686 |
mask |= OMP_SIMD_CLAUSE_MASK; |
| 24687 |
|
| 24688 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 24689 |
if (cclauses) |
| 24690 |
{ |
| 24691 |
omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses); |
| 24692 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; |
| 24693 |
} |
| 24694 |
|
| 24695 |
block = c_begin_compound_stmt (true); |
| 24696 |
ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p); |
| 24697 |
block = c_end_compound_stmt (loc, block, true); |
| 24698 |
add_stmt (block); |
| 24699 |
|
| 24700 |
return ret; |
| 24701 |
} |
| 24702 |
|
| 24703 |
/* OpenMP 2.5: |
| 24704 |
#pragma omp for for-clause[optseq] new-line |
| 24705 |
for-loop |
| 24706 |
|
| 24707 |
OpenMP 4.0: |
| 24708 |
#pragma omp for simd for-simd-clause[optseq] new-line |
| 24709 |
for-loop |
| 24710 |
|
| 24711 |
LOC is the location of the #pragma token. |
| 24712 |
*/ |
| 24713 |
|
| 24714 |
#define OMP_FOR_CLAUSE_MASK \ |
| 24715 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 24716 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 24717 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 24718 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
| 24719 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 24720 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \ |
| 24721 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \ |
| 24722 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
| 24723 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \ |
| 24724 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 24725 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER)) |
| 24726 |
|
| 24727 |
static tree |
| 24728 |
c_parser_omp_for (location_t loc, c_parser *parser, |
| 24729 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 24730 |
bool *if_p) |
| 24731 |
{ |
| 24732 |
tree block, clauses, ret; |
| 24733 |
|
| 24734 |
strcat (p_name, " for"); |
| 24735 |
mask |= OMP_FOR_CLAUSE_MASK; |
| 24736 |
/* parallel for{, simd} disallows nowait clause, but for |
| 24737 |
target {teams distribute ,}parallel for{, simd} it should be accepted. */ |
| 24738 |
if (cclauses && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0) |
| 24739 |
mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); |
| 24740 |
/* Composite distribute parallel for{, simd} disallows ordered clause. */ |
| 24741 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) |
| 24742 |
mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED); |
| 24743 |
|
| 24744 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 24745 |
{ |
| 24746 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 24747 |
|
| 24748 |
if (strcmp (p, "simd") == 0) |
| 24749 |
{ |
| 24750 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 24751 |
if (cclauses == NULL) |
| 24752 |
cclauses = cclauses_buf; |
| 24753 |
|
| 24754 |
c_parser_consume_token (parser); |
| 24755 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 24756 |
return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 24757 |
if_p); |
| 24758 |
block = c_begin_compound_stmt (true); |
| 24759 |
ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p); |
| 24760 |
block = c_end_compound_stmt (loc, block, true); |
| 24761 |
if (ret == NULL_TREE) |
| 24762 |
return ret; |
| 24763 |
ret = make_node (OMP_FOR); |
| 24764 |
TREE_TYPE (ret) = void_type_node; |
| 24765 |
OMP_FOR_BODY (ret) = block; |
| 24766 |
OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; |
| 24767 |
SET_EXPR_LOCATION (ret, loc); |
| 24768 |
add_stmt (ret); |
| 24769 |
return ret; |
| 24770 |
} |
| 24771 |
} |
| 24772 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 24773 |
{ |
| 24774 |
c_parser_skip_to_pragma_eol (parser, false); |
| 24775 |
return NULL_TREE; |
| 24776 |
} |
| 24777 |
|
| 24778 |
/* Composite distribute parallel for disallows linear clause. */ |
| 24779 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) |
| 24780 |
mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR); |
| 24781 |
|
| 24782 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 24783 |
if (cclauses) |
| 24784 |
{ |
| 24785 |
omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses); |
| 24786 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; |
| 24787 |
} |
| 24788 |
|
| 24789 |
block = c_begin_compound_stmt (true); |
| 24790 |
ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p); |
| 24791 |
block = c_end_compound_stmt (loc, block, true); |
| 24792 |
add_stmt (block); |
| 24793 |
|
| 24794 |
return ret; |
| 24795 |
} |
| 24796 |
|
| 24797 |
static tree c_parser_omp_taskloop (location_t, c_parser *, char *, |
| 24798 |
omp_clause_mask, tree *, bool *); |
| 24799 |
|
| 24800 |
/* OpenMP 2.5: |
| 24801 |
# pragma omp master new-line |
| 24802 |
structured-block |
| 24803 |
|
| 24804 |
LOC is the location of the #pragma token. |
| 24805 |
*/ |
| 24806 |
|
| 24807 |
static tree |
| 24808 |
c_parser_omp_master (location_t loc, c_parser *parser, |
| 24809 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 24810 |
bool *if_p) |
| 24811 |
{ |
| 24812 |
tree block, clauses, ret; |
| 24813 |
|
| 24814 |
strcat (p_name, " master"); |
| 24815 |
|
| 24816 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 24817 |
{ |
| 24818 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 24819 |
|
| 24820 |
if (strcmp (p, "taskloop") == 0) |
| 24821 |
{ |
| 24822 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 24823 |
if (cclauses == NULL) |
| 24824 |
cclauses = cclauses_buf; |
| 24825 |
|
| 24826 |
c_parser_consume_token (parser); |
| 24827 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 24828 |
return c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses, |
| 24829 |
if_p); |
| 24830 |
block = c_begin_compound_stmt (true); |
| 24831 |
ret = c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses, |
| 24832 |
if_p); |
| 24833 |
block = c_end_compound_stmt (loc, block, true); |
| 24834 |
if (ret == NULL_TREE) |
| 24835 |
return ret; |
| 24836 |
ret = c_finish_omp_master (loc, block); |
| 24837 |
OMP_MASTER_COMBINED (ret) = 1; |
| 24838 |
return ret; |
| 24839 |
} |
| 24840 |
} |
| 24841 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 24842 |
{ |
| 24843 |
c_parser_skip_to_pragma_eol (parser, false); |
| 24844 |
return NULL_TREE; |
| 24845 |
} |
| 24846 |
|
| 24847 |
if (cclauses) |
| 24848 |
{ |
| 24849 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, false); |
| 24850 |
omp_split_clauses (loc, OMP_MASTER, mask, clauses, cclauses); |
| 24851 |
} |
| 24852 |
else |
| 24853 |
c_parser_skip_to_pragma_eol (parser); |
| 24854 |
|
| 24855 |
return c_finish_omp_master (loc, c_parser_omp_structured_block (parser, |
| 24856 |
if_p)); |
| 24857 |
} |
| 24858 |
|
| 24859 |
/* OpenMP 5.1: |
| 24860 |
# pragma omp masked masked-clauses new-line |
| 24861 |
structured-block |
| 24862 |
|
| 24863 |
LOC is the location of the #pragma token. |
| 24864 |
*/ |
| 24865 |
|
| 24866 |
#define OMP_MASKED_CLAUSE_MASK \ |
| 24867 |
(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FILTER) |
| 24868 |
|
| 24869 |
static tree |
| 24870 |
c_parser_omp_masked (location_t loc, c_parser *parser, |
| 24871 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 24872 |
bool *if_p) |
| 24873 |
{ |
| 24874 |
tree block, clauses, ret; |
| 24875 |
|
| 24876 |
strcat (p_name, " masked"); |
| 24877 |
mask |= OMP_MASKED_CLAUSE_MASK; |
| 24878 |
|
| 24879 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 24880 |
{ |
| 24881 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 24882 |
|
| 24883 |
if (strcmp (p, "taskloop") == 0) |
| 24884 |
{ |
| 24885 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 24886 |
if (cclauses == NULL) |
| 24887 |
cclauses = cclauses_buf; |
| 24888 |
|
| 24889 |
c_parser_consume_token (parser); |
| 24890 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 24891 |
return c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses, |
| 24892 |
if_p); |
| 24893 |
block = c_begin_compound_stmt (true); |
| 24894 |
ret = c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses, |
| 24895 |
if_p); |
| 24896 |
block = c_end_compound_stmt (loc, block, true); |
| 24897 |
if (ret == NULL_TREE) |
| 24898 |
return ret; |
| 24899 |
ret = c_finish_omp_masked (loc, block, |
| 24900 |
cclauses[C_OMP_CLAUSE_SPLIT_MASKED]); |
| 24901 |
OMP_MASKED_COMBINED (ret) = 1; |
| 24902 |
return ret; |
| 24903 |
} |
| 24904 |
} |
| 24905 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 24906 |
{ |
| 24907 |
c_parser_skip_to_pragma_eol (parser, false); |
| 24908 |
return NULL_TREE; |
| 24909 |
} |
| 24910 |
|
| 24911 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 24912 |
if (cclauses) |
| 24913 |
{ |
| 24914 |
omp_split_clauses (loc, OMP_MASKED, mask, clauses, cclauses); |
| 24915 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_MASKED]; |
| 24916 |
} |
| 24917 |
|
| 24918 |
return c_finish_omp_masked (loc, c_parser_omp_structured_block (parser, |
| 24919 |
if_p), |
| 24920 |
clauses); |
| 24921 |
} |
| 24922 |
|
| 24923 |
/* OpenMP 5.1: |
| 24924 |
# pragma omp interop clauses[opt] new-line */ |
| 24925 |
|
| 24926 |
#define OMP_INTEROP_CLAUSE_MASK \ |
| 24927 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 24928 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DESTROY) \ |
| 24929 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 24930 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INIT) \ |
| 24931 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \ |
| 24932 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE)) |
| 24933 |
|
| 24934 |
static void |
| 24935 |
c_parser_omp_interop (c_parser *parser) |
| 24936 |
{ |
| 24937 |
location_t loc = c_parser_peek_token (parser)->location; |
| 24938 |
c_parser_consume_pragma (parser); |
| 24939 |
tree clauses = c_parser_omp_all_clauses (parser, |
| 24940 |
OMP_INTEROP_CLAUSE_MASK, |
| 24941 |
"#pragma omp interop"); |
| 24942 |
tree stmt = make_node (OMP_INTEROP); |
| 24943 |
TREE_TYPE (stmt) = void_type_node; |
| 24944 |
OMP_INTEROP_CLAUSES (stmt) = clauses; |
| 24945 |
SET_EXPR_LOCATION (stmt, loc); |
| 24946 |
add_stmt (stmt); |
| 24947 |
} |
| 24948 |
|
| 24949 |
/* OpenMP 2.5: |
| 24950 |
# pragma omp ordered new-line |
| 24951 |
structured-block |
| 24952 |
|
| 24953 |
OpenMP 4.5: |
| 24954 |
# pragma omp ordered ordered-clauses new-line |
| 24955 |
structured-block |
| 24956 |
|
| 24957 |
# pragma omp ordered depend-clauses new-line |
| 24958 |
|
| 24959 |
OpenMP 5.2 |
| 24960 |
# pragma omp ordered doacross-clauses new-line */ |
| 24961 |
|
| 24962 |
#define OMP_ORDERED_CLAUSE_MASK \ |
| 24963 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \ |
| 24964 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD)) |
| 24965 |
|
| 24966 |
#define OMP_ORDERED_DEPEND_CLAUSE_MASK \ |
| 24967 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 24968 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DOACROSS)) |
| 24969 |
|
| 24970 |
static bool |
| 24971 |
c_parser_omp_ordered (c_parser *parser, enum pragma_context context, |
| 24972 |
bool *if_p) |
| 24973 |
{ |
| 24974 |
location_t loc = c_parser_peek_token (parser)->location; |
| 24975 |
c_parser_consume_pragma (parser); |
| 24976 |
|
| 24977 |
if (context != pragma_stmt && context != pragma_compound) |
| 24978 |
{ |
| 24979 |
c_parser_error (parser, "expected declaration specifiers"); |
| 24980 |
c_parser_skip_to_pragma_eol (parser, false); |
| 24981 |
return false; |
| 24982 |
} |
| 24983 |
|
| 24984 |
int n = 1; |
| 24985 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 24986 |
n = 2; |
| 24987 |
|
| 24988 |
if (c_parser_peek_nth_token (parser, n)->type == CPP_NAME) |
| 24989 |
{ |
| 24990 |
const char *p |
| 24991 |
= IDENTIFIER_POINTER (c_parser_peek_nth_token (parser, n)->value); |
| 24992 |
|
| 24993 |
if (!strcmp ("depend", p) || !strcmp ("doacross", p)) |
| 24994 |
{ |
| 24995 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 24996 |
{ |
| 24997 |
c_parser_skip_to_pragma_eol (parser, false); |
| 24998 |
return false; |
| 24999 |
} |
| 25000 |
if (context == pragma_stmt) |
| 25001 |
{ |
| 25002 |
error_at (loc, |
| 25003 |
"%<#pragma omp ordered%> with %qs clause may " |
| 25004 |
"only be used in compound statements", p); |
| 25005 |
c_parser_skip_to_pragma_eol (parser, false); |
| 25006 |
return true; |
| 25007 |
} |
| 25008 |
|
| 25009 |
tree clauses |
| 25010 |
= c_parser_omp_all_clauses (parser, |
| 25011 |
OMP_ORDERED_DEPEND_CLAUSE_MASK, |
| 25012 |
"#pragma omp ordered"); |
| 25013 |
c_finish_omp_ordered (loc, clauses, NULL_TREE); |
| 25014 |
return false; |
| 25015 |
} |
| 25016 |
} |
| 25017 |
|
| 25018 |
tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK, |
| 25019 |
"#pragma omp ordered"); |
| 25020 |
|
| 25021 |
if (!flag_openmp /* flag_openmp_simd */ |
| 25022 |
&& omp_find_clause (clauses, OMP_CLAUSE_SIMD) == NULL_TREE) |
| 25023 |
return false; |
| 25024 |
|
| 25025 |
c_finish_omp_ordered (loc, clauses, |
| 25026 |
c_parser_omp_structured_block (parser, if_p)); |
| 25027 |
return true; |
| 25028 |
} |
| 25029 |
|
| 25030 |
/* OpenMP 2.5: |
| 25031 |
|
| 25032 |
section-scope: |
| 25033 |
{ section-sequence } |
| 25034 |
|
| 25035 |
section-sequence: |
| 25036 |
section-directive[opt] structured-block |
| 25037 |
section-sequence section-directive structured-block |
| 25038 |
|
| 25039 |
OpenMP 5.1 allows structured-block-sequence instead of structured-block. |
| 25040 |
|
| 25041 |
SECTIONS_LOC is the location of the #pragma omp sections. */ |
| 25042 |
|
| 25043 |
static tree |
| 25044 |
c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser) |
| 25045 |
{ |
| 25046 |
tree stmt, substmt; |
| 25047 |
bool error_suppress = false; |
| 25048 |
location_t loc; |
| 25049 |
|
| 25050 |
loc = c_parser_peek_token (parser)->location; |
| 25051 |
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 25052 |
{ |
| 25053 |
/* Avoid skipping until the end of the block. */ |
| 25054 |
parser->error = false; |
| 25055 |
return NULL_TREE; |
| 25056 |
} |
| 25057 |
|
| 25058 |
stmt = push_stmt_list (); |
| 25059 |
|
| 25060 |
if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION |
| 25061 |
&& !c_parser_omp_section_scan (parser, "section", true)) |
| 25062 |
{ |
| 25063 |
substmt = c_parser_omp_structured_block_sequence (parser, |
| 25064 |
PRAGMA_OMP_SECTION); |
| 25065 |
substmt = build1 (OMP_SECTION, void_type_node, substmt); |
| 25066 |
SET_EXPR_LOCATION (substmt, loc); |
| 25067 |
add_stmt (substmt); |
| 25068 |
} |
| 25069 |
|
| 25070 |
while (1) |
| 25071 |
{ |
| 25072 |
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 25073 |
break; |
| 25074 |
if (c_parser_next_token_is (parser, CPP_EOF)) |
| 25075 |
break; |
| 25076 |
|
| 25077 |
loc = c_parser_peek_token (parser)->location; |
| 25078 |
c_parser_omp_section_scan (parser, "section", false); |
| 25079 |
if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) |
| 25080 |
{ |
| 25081 |
c_parser_consume_pragma (parser); |
| 25082 |
c_parser_skip_to_pragma_eol (parser); |
| 25083 |
error_suppress = false; |
| 25084 |
} |
| 25085 |
else if (!error_suppress) |
| 25086 |
{ |
| 25087 |
error_at (loc, "expected %<#pragma omp section%> or %<}%>"); |
| 25088 |
error_suppress = true; |
| 25089 |
} |
| 25090 |
|
| 25091 |
substmt = c_parser_omp_structured_block_sequence (parser, |
| 25092 |
PRAGMA_OMP_SECTION); |
| 25093 |
substmt = build1 (OMP_SECTION, void_type_node, substmt); |
| 25094 |
SET_EXPR_LOCATION (substmt, loc); |
| 25095 |
add_stmt (substmt); |
| 25096 |
} |
| 25097 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, |
| 25098 |
"expected %<#pragma omp section%> or %<}%>"); |
| 25099 |
|
| 25100 |
substmt = pop_stmt_list (stmt); |
| 25101 |
|
| 25102 |
stmt = make_node (OMP_SECTIONS); |
| 25103 |
SET_EXPR_LOCATION (stmt, sections_loc); |
| 25104 |
TREE_TYPE (stmt) = void_type_node; |
| 25105 |
OMP_SECTIONS_BODY (stmt) = substmt; |
| 25106 |
|
| 25107 |
return add_stmt (stmt); |
| 25108 |
} |
| 25109 |
|
| 25110 |
/* OpenMP 2.5: |
| 25111 |
# pragma omp sections sections-clause[optseq] newline |
| 25112 |
sections-scope |
| 25113 |
|
| 25114 |
LOC is the location of the #pragma token. |
| 25115 |
*/ |
| 25116 |
|
| 25117 |
#define OMP_SECTIONS_CLAUSE_MASK \ |
| 25118 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 25119 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 25120 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 25121 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 25122 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25123 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 25124 |
|
| 25125 |
static tree |
| 25126 |
c_parser_omp_sections (location_t loc, c_parser *parser, |
| 25127 |
char *p_name, omp_clause_mask mask, tree *cclauses) |
| 25128 |
{ |
| 25129 |
tree block, clauses, ret; |
| 25130 |
|
| 25131 |
strcat (p_name, " sections"); |
| 25132 |
mask |= OMP_SECTIONS_CLAUSE_MASK; |
| 25133 |
if (cclauses) |
| 25134 |
mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); |
| 25135 |
|
| 25136 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 25137 |
if (cclauses) |
| 25138 |
{ |
| 25139 |
omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses); |
| 25140 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]; |
| 25141 |
} |
| 25142 |
|
| 25143 |
block = c_begin_compound_stmt (true); |
| 25144 |
ret = c_parser_omp_sections_scope (loc, parser); |
| 25145 |
if (ret) |
| 25146 |
OMP_SECTIONS_CLAUSES (ret) = clauses; |
| 25147 |
block = c_end_compound_stmt (loc, block, true); |
| 25148 |
add_stmt (block); |
| 25149 |
|
| 25150 |
return ret; |
| 25151 |
} |
| 25152 |
|
| 25153 |
/* OpenMP 2.5: |
| 25154 |
# pragma omp parallel parallel-clause[optseq] new-line |
| 25155 |
structured-block |
| 25156 |
# pragma omp parallel for parallel-for-clause[optseq] new-line |
| 25157 |
structured-block |
| 25158 |
# pragma omp parallel sections parallel-sections-clause[optseq] new-line |
| 25159 |
structured-block |
| 25160 |
|
| 25161 |
OpenMP 4.0: |
| 25162 |
# pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line |
| 25163 |
structured-block |
| 25164 |
|
| 25165 |
LOC is the location of the #pragma token. |
| 25166 |
*/ |
| 25167 |
|
| 25168 |
#define OMP_PARALLEL_CLAUSE_MASK \ |
| 25169 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 25170 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 25171 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 25172 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
| 25173 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 25174 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \ |
| 25175 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 25176 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \ |
| 25177 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25178 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND)) |
| 25179 |
|
| 25180 |
static tree |
| 25181 |
c_parser_omp_parallel (location_t loc, c_parser *parser, |
| 25182 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 25183 |
bool *if_p) |
| 25184 |
{ |
| 25185 |
tree stmt, clauses, block; |
| 25186 |
|
| 25187 |
strcat (p_name, " parallel"); |
| 25188 |
mask |= OMP_PARALLEL_CLAUSE_MASK; |
| 25189 |
/* #pragma omp target parallel{, for, for simd} disallow copyin clause. */ |
| 25190 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0 |
| 25191 |
&& (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0) |
| 25192 |
mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN); |
| 25193 |
|
| 25194 |
if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 25195 |
{ |
| 25196 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25197 |
if (cclauses == NULL) |
| 25198 |
cclauses = cclauses_buf; |
| 25199 |
|
| 25200 |
c_parser_consume_token (parser); |
| 25201 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25202 |
return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p); |
| 25203 |
block = c_begin_omp_parallel (); |
| 25204 |
tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p); |
| 25205 |
stmt |
| 25206 |
= c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], |
| 25207 |
block); |
| 25208 |
if (ret == NULL_TREE) |
| 25209 |
return ret; |
| 25210 |
OMP_PARALLEL_COMBINED (stmt) = 1; |
| 25211 |
return stmt; |
| 25212 |
} |
| 25213 |
/* When combined with distribute, parallel has to be followed by for. |
| 25214 |
#pragma omp target parallel is allowed though. */ |
| 25215 |
else if (cclauses |
| 25216 |
&& (mask & (OMP_CLAUSE_MASK_1 |
| 25217 |
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) |
| 25218 |
{ |
| 25219 |
error_at (loc, "expected %<for%> after %qs", p_name); |
| 25220 |
c_parser_skip_to_pragma_eol (parser); |
| 25221 |
return NULL_TREE; |
| 25222 |
} |
| 25223 |
else if (c_parser_next_token_is (parser, CPP_NAME)) |
| 25224 |
{ |
| 25225 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 25226 |
if (cclauses == NULL && strcmp (p, "masked") == 0) |
| 25227 |
{ |
| 25228 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25229 |
cclauses = cclauses_buf; |
| 25230 |
|
| 25231 |
c_parser_consume_token (parser); |
| 25232 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25233 |
return c_parser_omp_masked (loc, parser, p_name, mask, cclauses, |
| 25234 |
if_p); |
| 25235 |
block = c_begin_omp_parallel (); |
| 25236 |
tree ret = c_parser_omp_masked (loc, parser, p_name, mask, cclauses, |
| 25237 |
if_p); |
| 25238 |
stmt = c_finish_omp_parallel (loc, |
| 25239 |
cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], |
| 25240 |
block); |
| 25241 |
if (ret == NULL) |
| 25242 |
return ret; |
| 25243 |
/* masked does have just filter clause, but during gimplification |
| 25244 |
isn't represented by a gimplification omp context, so for |
| 25245 |
#pragma omp parallel masked don't set OMP_PARALLEL_COMBINED, |
| 25246 |
so that |
| 25247 |
#pragma omp parallel masked |
| 25248 |
#pragma omp taskloop simd lastprivate (x) |
| 25249 |
isn't confused with |
| 25250 |
#pragma omp parallel masked taskloop simd lastprivate (x) */ |
| 25251 |
if (OMP_MASKED_COMBINED (ret)) |
| 25252 |
OMP_PARALLEL_COMBINED (stmt) = 1; |
| 25253 |
return stmt; |
| 25254 |
} |
| 25255 |
else if (cclauses == NULL && strcmp (p, "master") == 0) |
| 25256 |
{ |
| 25257 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25258 |
cclauses = cclauses_buf; |
| 25259 |
|
| 25260 |
c_parser_consume_token (parser); |
| 25261 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25262 |
return c_parser_omp_master (loc, parser, p_name, mask, cclauses, |
| 25263 |
if_p); |
| 25264 |
block = c_begin_omp_parallel (); |
| 25265 |
tree ret = c_parser_omp_master (loc, parser, p_name, mask, cclauses, |
| 25266 |
if_p); |
| 25267 |
stmt = c_finish_omp_parallel (loc, |
| 25268 |
cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], |
| 25269 |
block); |
| 25270 |
if (ret == NULL) |
| 25271 |
return ret; |
| 25272 |
/* master doesn't have any clauses and during gimplification |
| 25273 |
isn't represented by a gimplification omp context, so for |
| 25274 |
#pragma omp parallel master don't set OMP_PARALLEL_COMBINED, |
| 25275 |
so that |
| 25276 |
#pragma omp parallel master |
| 25277 |
#pragma omp taskloop simd lastprivate (x) |
| 25278 |
isn't confused with |
| 25279 |
#pragma omp parallel master taskloop simd lastprivate (x) */ |
| 25280 |
if (OMP_MASTER_COMBINED (ret)) |
| 25281 |
OMP_PARALLEL_COMBINED (stmt) = 1; |
| 25282 |
return stmt; |
| 25283 |
} |
| 25284 |
else if (strcmp (p, "loop") == 0) |
| 25285 |
{ |
| 25286 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25287 |
if (cclauses == NULL) |
| 25288 |
cclauses = cclauses_buf; |
| 25289 |
|
| 25290 |
c_parser_consume_token (parser); |
| 25291 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25292 |
return c_parser_omp_loop (loc, parser, p_name, mask, cclauses, |
| 25293 |
if_p); |
| 25294 |
block = c_begin_omp_parallel (); |
| 25295 |
tree ret = c_parser_omp_loop (loc, parser, p_name, mask, cclauses, |
| 25296 |
if_p); |
| 25297 |
stmt |
| 25298 |
= c_finish_omp_parallel (loc, |
| 25299 |
cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], |
| 25300 |
block); |
| 25301 |
if (ret == NULL_TREE) |
| 25302 |
return ret; |
| 25303 |
OMP_PARALLEL_COMBINED (stmt) = 1; |
| 25304 |
return stmt; |
| 25305 |
} |
| 25306 |
else if (!flag_openmp) /* flag_openmp_simd */ |
| 25307 |
{ |
| 25308 |
c_parser_skip_to_pragma_eol (parser, false); |
| 25309 |
return NULL_TREE; |
| 25310 |
} |
| 25311 |
else if (cclauses == NULL && strcmp (p, "sections") == 0) |
| 25312 |
{ |
| 25313 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25314 |
cclauses = cclauses_buf; |
| 25315 |
|
| 25316 |
c_parser_consume_token (parser); |
| 25317 |
block = c_begin_omp_parallel (); |
| 25318 |
c_parser_omp_sections (loc, parser, p_name, mask, cclauses); |
| 25319 |
stmt = c_finish_omp_parallel (loc, |
| 25320 |
cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], |
| 25321 |
block); |
| 25322 |
OMP_PARALLEL_COMBINED (stmt) = 1; |
| 25323 |
return stmt; |
| 25324 |
} |
| 25325 |
} |
| 25326 |
else if (!flag_openmp) /* flag_openmp_simd */ |
| 25327 |
{ |
| 25328 |
c_parser_skip_to_pragma_eol (parser, false); |
| 25329 |
return NULL_TREE; |
| 25330 |
} |
| 25331 |
|
| 25332 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 25333 |
if (cclauses) |
| 25334 |
{ |
| 25335 |
omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses); |
| 25336 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; |
| 25337 |
} |
| 25338 |
|
| 25339 |
block = c_begin_omp_parallel (); |
| 25340 |
parser->omp_attrs_forbidden_p = true; |
| 25341 |
c_parser_statement (parser, if_p); |
| 25342 |
stmt = c_finish_omp_parallel (loc, clauses, block); |
| 25343 |
|
| 25344 |
return stmt; |
| 25345 |
} |
| 25346 |
|
| 25347 |
/* OpenMP 2.5: |
| 25348 |
# pragma omp single single-clause[optseq] new-line |
| 25349 |
structured-block |
| 25350 |
|
| 25351 |
LOC is the location of the #pragma. |
| 25352 |
*/ |
| 25353 |
|
| 25354 |
#define OMP_SINGLE_CLAUSE_MASK \ |
| 25355 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 25356 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 25357 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ |
| 25358 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25359 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 25360 |
|
| 25361 |
static tree |
| 25362 |
c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p) |
| 25363 |
{ |
| 25364 |
tree stmt = make_node (OMP_SINGLE); |
| 25365 |
SET_EXPR_LOCATION (stmt, loc); |
| 25366 |
TREE_TYPE (stmt) = void_type_node; |
| 25367 |
|
| 25368 |
OMP_SINGLE_CLAUSES (stmt) |
| 25369 |
= c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, |
| 25370 |
"#pragma omp single"); |
| 25371 |
OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p); |
| 25372 |
|
| 25373 |
return add_stmt (stmt); |
| 25374 |
} |
| 25375 |
|
| 25376 |
/* OpenMP 5.1: |
| 25377 |
# pragma omp scope scope-clause[optseq] new-line |
| 25378 |
structured-block |
| 25379 |
|
| 25380 |
LOC is the location of the #pragma. |
| 25381 |
*/ |
| 25382 |
|
| 25383 |
#define OMP_SCOPE_CLAUSE_MASK \ |
| 25384 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 25385 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 25386 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 25387 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25388 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 25389 |
|
| 25390 |
static tree |
| 25391 |
c_parser_omp_scope (location_t loc, c_parser *parser, bool *if_p) |
| 25392 |
{ |
| 25393 |
tree stmt = make_node (OMP_SCOPE); |
| 25394 |
SET_EXPR_LOCATION (stmt, loc); |
| 25395 |
TREE_TYPE (stmt) = void_type_node; |
| 25396 |
|
| 25397 |
OMP_SCOPE_CLAUSES (stmt) |
| 25398 |
= c_parser_omp_all_clauses (parser, OMP_SCOPE_CLAUSE_MASK, |
| 25399 |
"#pragma omp scope"); |
| 25400 |
OMP_SCOPE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p); |
| 25401 |
|
| 25402 |
return add_stmt (stmt); |
| 25403 |
} |
| 25404 |
|
| 25405 |
/* Parse a function dispatch structured block: |
| 25406 |
|
| 25407 |
lvalue-expression = target-call ( [expression-list] ); |
| 25408 |
or |
| 25409 |
target-call ( [expression-list] ); |
| 25410 |
|
| 25411 |
Adapted from c_parser_expr_no_commas and c_parser_postfix_expression |
| 25412 |
(CPP_NAME/C_ID_ID) for the function name. |
| 25413 |
*/ |
| 25414 |
static tree |
| 25415 |
c_parser_omp_dispatch_body (c_parser *parser) |
| 25416 |
{ |
| 25417 |
struct c_expr lhs, rhs, ret; |
| 25418 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 25419 |
source_range tok_range = c_parser_peek_token (parser)->get_range (); |
| 25420 |
|
| 25421 |
lhs = c_parser_conditional_expression (parser, NULL, NULL); |
| 25422 |
if (TREE_CODE (lhs.value) == CALL_EXPR) |
| 25423 |
return lhs.value; |
| 25424 |
|
| 25425 |
location_t op_location = c_parser_peek_token (parser)->location; |
| 25426 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 25427 |
return error_mark_node; |
| 25428 |
|
| 25429 |
/* Parse function name. */ |
| 25430 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 25431 |
{ |
| 25432 |
c_parser_error (parser, "expected a function name"); |
| 25433 |
return error_mark_node; |
| 25434 |
} |
| 25435 |
expr_loc = c_parser_peek_token (parser)->location; |
| 25436 |
tree id = c_parser_peek_token (parser)->value; |
| 25437 |
c_parser_consume_token (parser); |
| 25438 |
if (!c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 25439 |
{ |
| 25440 |
c_parser_error (parser, "expected a function name"); |
| 25441 |
return error_mark_node; |
| 25442 |
} |
| 25443 |
|
| 25444 |
rhs.value = build_external_ref (expr_loc, id, true, &rhs.original_type); |
| 25445 |
set_c_expr_source_range (&rhs, tok_range); |
| 25446 |
|
| 25447 |
/* Parse argument list. */ |
| 25448 |
rhs = c_parser_postfix_expression_after_primary ( |
| 25449 |
parser, EXPR_LOC_OR_LOC (rhs.value, expr_loc), rhs); |
| 25450 |
if (TREE_CODE (rhs.value) != CALL_EXPR) |
| 25451 |
{ |
| 25452 |
error_at (EXPR_LOC_OR_LOC (rhs.value, expr_loc), |
| 25453 |
"expected target-function call"); |
| 25454 |
return error_mark_node; |
| 25455 |
} |
| 25456 |
|
| 25457 |
/* Build assignment. */ |
| 25458 |
rhs = convert_lvalue_to_rvalue (expr_loc, rhs, true, true); |
| 25459 |
ret.value |
| 25460 |
= build_modify_expr (op_location, lhs.value, lhs.original_type, NOP_EXPR, |
| 25461 |
expr_loc, rhs.value, rhs.original_type); |
| 25462 |
ret.m_decimal = 0; |
| 25463 |
set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ()); |
| 25464 |
ret.original_code = MODIFY_EXPR; |
| 25465 |
ret.original_type = NULL; |
| 25466 |
return ret.value; |
| 25467 |
} |
| 25468 |
|
| 25469 |
/* OpenMP 5.1: |
| 25470 |
# pragma omp dispatch dispatch-clause[optseq] new-line |
| 25471 |
expression-stmt |
| 25472 |
|
| 25473 |
LOC is the location of the #pragma. |
| 25474 |
*/ |
| 25475 |
|
| 25476 |
#define OMP_DISPATCH_CLAUSE_MASK \ |
| 25477 |
((OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 25478 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 25479 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOVARIANTS) \ |
| 25480 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOCONTEXT) \ |
| 25481 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR) \ |
| 25482 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INTEROP) \ |
| 25483 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR) \ |
| 25484 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 25485 |
|
| 25486 |
static tree |
| 25487 |
c_parser_omp_dispatch (location_t loc, c_parser *parser) |
| 25488 |
{ |
| 25489 |
tree stmt = make_node (OMP_DISPATCH); |
| 25490 |
SET_EXPR_LOCATION (stmt, loc); |
| 25491 |
TREE_TYPE (stmt) = void_type_node; |
| 25492 |
|
| 25493 |
OMP_DISPATCH_CLAUSES (stmt) |
| 25494 |
= c_parser_omp_all_clauses (parser, OMP_DISPATCH_CLAUSE_MASK, |
| 25495 |
"#pragma omp dispatch"); |
| 25496 |
|
| 25497 |
// Extract depend clauses and create taskwait |
| 25498 |
tree depend_clauses = NULL_TREE; |
| 25499 |
tree *depend_clauses_ptr = &depend_clauses; |
| 25500 |
for (tree c = OMP_DISPATCH_CLAUSES (stmt); c; c = OMP_CLAUSE_CHAIN (c)) |
| 25501 |
{ |
| 25502 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) |
| 25503 |
{ |
| 25504 |
*depend_clauses_ptr = c; |
| 25505 |
depend_clauses_ptr = &OMP_CLAUSE_CHAIN (c); |
| 25506 |
} |
| 25507 |
} |
| 25508 |
if (depend_clauses != NULL_TREE) |
| 25509 |
{ |
| 25510 |
tree stmt = make_node (OMP_TASK); |
| 25511 |
TREE_TYPE (stmt) = void_node; |
| 25512 |
OMP_TASK_CLAUSES (stmt) = depend_clauses; |
| 25513 |
OMP_TASK_BODY (stmt) = NULL_TREE; |
| 25514 |
SET_EXPR_LOCATION (stmt, loc); |
| 25515 |
add_stmt (stmt); |
| 25516 |
} |
| 25517 |
|
| 25518 |
// Parse body as expression statement |
| 25519 |
loc = c_parser_peek_token (parser)->location; |
| 25520 |
tree dispatch_body = c_parser_omp_dispatch_body (parser); |
| 25521 |
if (dispatch_body == error_mark_node) |
| 25522 |
{ |
| 25523 |
inform (loc, "%<#pragma omp dispatch%> must be followed by a function " |
| 25524 |
"call with optional assignment"); |
| 25525 |
c_parser_skip_to_end_of_block_or_statement (parser); |
| 25526 |
return NULL_TREE; |
| 25527 |
} |
| 25528 |
|
| 25529 |
// Walk the tree to find the dispatch function call and wrap it into an IFN |
| 25530 |
gcc_assert (TREE_CODE (dispatch_body) == CALL_EXPR |
| 25531 |
|| TREE_CODE (dispatch_body) == MODIFY_EXPR); |
| 25532 |
tree *dispatch_call = TREE_CODE (dispatch_body) == MODIFY_EXPR |
| 25533 |
? &TREE_OPERAND (dispatch_body, 1) |
| 25534 |
: &dispatch_body; |
| 25535 |
while (TREE_CODE (*dispatch_call) == FLOAT_EXPR |
| 25536 |
|| TREE_CODE (*dispatch_call) == CONVERT_EXPR |
| 25537 |
|| TREE_CODE (*dispatch_call) == NOP_EXPR) |
| 25538 |
dispatch_call = &TREE_OPERAND (*dispatch_call, 0); |
| 25539 |
*dispatch_call = build_call_expr_internal_loc ( |
| 25540 |
loc, IFN_GOMP_DISPATCH, |
| 25541 |
TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (*dispatch_call))), 1, *dispatch_call); |
| 25542 |
|
| 25543 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
| 25544 |
OMP_DISPATCH_BODY (stmt) = dispatch_body; |
| 25545 |
|
| 25546 |
return add_stmt (stmt); |
| 25547 |
} |
| 25548 |
|
| 25549 |
/* OpenMP 3.0: |
| 25550 |
# pragma omp task task-clause[optseq] new-line |
| 25551 |
|
| 25552 |
LOC is the location of the #pragma. |
| 25553 |
*/ |
| 25554 |
|
| 25555 |
#define OMP_TASK_CLAUSE_MASK \ |
| 25556 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 25557 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ |
| 25558 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
| 25559 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 25560 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 25561 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 25562 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ |
| 25563 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ |
| 25564 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 25565 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \ |
| 25566 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25567 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION) \ |
| 25568 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DETACH) \ |
| 25569 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_AFFINITY)) |
| 25570 |
|
| 25571 |
static tree |
| 25572 |
c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p) |
| 25573 |
{ |
| 25574 |
tree clauses, block; |
| 25575 |
|
| 25576 |
clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, |
| 25577 |
"#pragma omp task"); |
| 25578 |
|
| 25579 |
block = c_begin_omp_task (); |
| 25580 |
parser->omp_attrs_forbidden_p = true; |
| 25581 |
c_parser_statement (parser, if_p); |
| 25582 |
return c_finish_omp_task (loc, clauses, block); |
| 25583 |
} |
| 25584 |
|
| 25585 |
/* OpenMP 3.0: |
| 25586 |
# pragma omp taskwait new-line |
| 25587 |
|
| 25588 |
OpenMP 5.0: |
| 25589 |
# pragma omp taskwait taskwait-clause[optseq] new-line |
| 25590 |
*/ |
| 25591 |
|
| 25592 |
#define OMP_TASKWAIT_CLAUSE_MASK \ |
| 25593 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 25594 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 25595 |
|
| 25596 |
static void |
| 25597 |
c_parser_omp_taskwait (c_parser *parser) |
| 25598 |
{ |
| 25599 |
location_t loc = c_parser_peek_token (parser)->location; |
| 25600 |
c_parser_consume_pragma (parser); |
| 25601 |
|
| 25602 |
tree clauses |
| 25603 |
= c_parser_omp_all_clauses (parser, OMP_TASKWAIT_CLAUSE_MASK, |
| 25604 |
"#pragma omp taskwait"); |
| 25605 |
|
| 25606 |
if (clauses) |
| 25607 |
{ |
| 25608 |
tree stmt = make_node (OMP_TASK); |
| 25609 |
TREE_TYPE (stmt) = void_node; |
| 25610 |
OMP_TASK_CLAUSES (stmt) = clauses; |
| 25611 |
OMP_TASK_BODY (stmt) = NULL_TREE; |
| 25612 |
SET_EXPR_LOCATION (stmt, loc); |
| 25613 |
add_stmt (stmt); |
| 25614 |
} |
| 25615 |
else |
| 25616 |
c_finish_omp_taskwait (loc); |
| 25617 |
} |
| 25618 |
|
| 25619 |
/* OpenMP 3.1: |
| 25620 |
# pragma omp taskyield new-line |
| 25621 |
*/ |
| 25622 |
|
| 25623 |
static void |
| 25624 |
c_parser_omp_taskyield (c_parser *parser) |
| 25625 |
{ |
| 25626 |
location_t loc = c_parser_peek_token (parser)->location; |
| 25627 |
c_parser_consume_pragma (parser); |
| 25628 |
c_parser_skip_to_pragma_eol (parser); |
| 25629 |
|
| 25630 |
c_finish_omp_taskyield (loc); |
| 25631 |
} |
| 25632 |
|
| 25633 |
/* OpenMP 4.0: |
| 25634 |
# pragma omp taskgroup new-line |
| 25635 |
|
| 25636 |
OpenMP 5.0: |
| 25637 |
# pragma omp taskgroup taskgroup-clause[optseq] new-line |
| 25638 |
*/ |
| 25639 |
|
| 25640 |
#define OMP_TASKGROUP_CLAUSE_MASK \ |
| 25641 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25642 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION)) |
| 25643 |
|
| 25644 |
static tree |
| 25645 |
c_parser_omp_taskgroup (location_t loc, c_parser *parser, bool *if_p) |
| 25646 |
{ |
| 25647 |
tree clauses = c_parser_omp_all_clauses (parser, OMP_TASKGROUP_CLAUSE_MASK, |
| 25648 |
"#pragma omp taskgroup"); |
| 25649 |
|
| 25650 |
tree body = c_parser_omp_structured_block (parser, if_p); |
| 25651 |
return c_finish_omp_taskgroup (loc, body, clauses); |
| 25652 |
} |
| 25653 |
|
| 25654 |
/* OpenMP 4.0: |
| 25655 |
# pragma omp cancel cancel-clause[optseq] new-line |
| 25656 |
|
| 25657 |
LOC is the location of the #pragma. |
| 25658 |
*/ |
| 25659 |
|
| 25660 |
#define OMP_CANCEL_CLAUSE_MASK \ |
| 25661 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ |
| 25662 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ |
| 25663 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ |
| 25664 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \ |
| 25665 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) |
| 25666 |
|
| 25667 |
static void |
| 25668 |
c_parser_omp_cancel (c_parser *parser) |
| 25669 |
{ |
| 25670 |
location_t loc = c_parser_peek_token (parser)->location; |
| 25671 |
|
| 25672 |
c_parser_consume_pragma (parser); |
| 25673 |
tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK, |
| 25674 |
"#pragma omp cancel"); |
| 25675 |
|
| 25676 |
c_finish_omp_cancel (loc, clauses); |
| 25677 |
} |
| 25678 |
|
| 25679 |
/* OpenMP 4.0: |
| 25680 |
# pragma omp cancellation point cancelpt-clause[optseq] new-line |
| 25681 |
|
| 25682 |
LOC is the location of the #pragma. |
| 25683 |
*/ |
| 25684 |
|
| 25685 |
#define OMP_CANCELLATION_POINT_CLAUSE_MASK \ |
| 25686 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ |
| 25687 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ |
| 25688 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ |
| 25689 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)) |
| 25690 |
|
| 25691 |
static bool |
| 25692 |
c_parser_omp_cancellation_point (c_parser *parser, enum pragma_context context) |
| 25693 |
{ |
| 25694 |
location_t loc = c_parser_peek_token (parser)->location; |
| 25695 |
tree clauses; |
| 25696 |
bool point_seen = false; |
| 25697 |
|
| 25698 |
c_parser_consume_pragma (parser); |
| 25699 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 25700 |
{ |
| 25701 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 25702 |
if (strcmp (p, "point") == 0) |
| 25703 |
{ |
| 25704 |
c_parser_consume_token (parser); |
| 25705 |
point_seen = true; |
| 25706 |
} |
| 25707 |
} |
| 25708 |
if (!point_seen) |
| 25709 |
{ |
| 25710 |
c_parser_error (parser, "expected %<point%>"); |
| 25711 |
c_parser_skip_to_pragma_eol (parser); |
| 25712 |
return false; |
| 25713 |
} |
| 25714 |
|
| 25715 |
if (context != pragma_compound) |
| 25716 |
{ |
| 25717 |
if (context == pragma_stmt) |
| 25718 |
error_at (loc, |
| 25719 |
"%<#pragma %s%> may only be used in compound statements", |
| 25720 |
"omp cancellation point"); |
| 25721 |
else |
| 25722 |
c_parser_error (parser, "expected declaration specifiers"); |
| 25723 |
c_parser_skip_to_pragma_eol (parser, false); |
| 25724 |
return true; |
| 25725 |
} |
| 25726 |
|
| 25727 |
clauses |
| 25728 |
= c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK, |
| 25729 |
"#pragma omp cancellation point"); |
| 25730 |
|
| 25731 |
c_finish_omp_cancellation_point (loc, clauses); |
| 25732 |
return true; |
| 25733 |
} |
| 25734 |
|
| 25735 |
/* OpenMP 4.0: |
| 25736 |
#pragma omp distribute distribute-clause[optseq] new-line |
| 25737 |
for-loop */ |
| 25738 |
|
| 25739 |
#define OMP_DISTRIBUTE_CLAUSE_MASK \ |
| 25740 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 25741 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 25742 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 25743 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\ |
| 25744 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25745 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
| 25746 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER)) |
| 25747 |
|
| 25748 |
static tree |
| 25749 |
c_parser_omp_distribute (location_t loc, c_parser *parser, |
| 25750 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 25751 |
bool *if_p) |
| 25752 |
{ |
| 25753 |
tree clauses, block, ret; |
| 25754 |
|
| 25755 |
strcat (p_name, " distribute"); |
| 25756 |
mask |= OMP_DISTRIBUTE_CLAUSE_MASK; |
| 25757 |
|
| 25758 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 25759 |
{ |
| 25760 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 25761 |
bool simd = false; |
| 25762 |
bool parallel = false; |
| 25763 |
|
| 25764 |
if (strcmp (p, "simd") == 0) |
| 25765 |
simd = true; |
| 25766 |
else |
| 25767 |
parallel = strcmp (p, "parallel") == 0; |
| 25768 |
if (parallel || simd) |
| 25769 |
{ |
| 25770 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25771 |
if (cclauses == NULL) |
| 25772 |
cclauses = cclauses_buf; |
| 25773 |
c_parser_consume_token (parser); |
| 25774 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25775 |
{ |
| 25776 |
if (simd) |
| 25777 |
return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 25778 |
if_p); |
| 25779 |
else |
| 25780 |
return c_parser_omp_parallel (loc, parser, p_name, mask, |
| 25781 |
cclauses, if_p); |
| 25782 |
} |
| 25783 |
block = c_begin_compound_stmt (true); |
| 25784 |
if (simd) |
| 25785 |
ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 25786 |
if_p); |
| 25787 |
else |
| 25788 |
ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses, |
| 25789 |
if_p); |
| 25790 |
block = c_end_compound_stmt (loc, block, true); |
| 25791 |
if (ret == NULL) |
| 25792 |
return ret; |
| 25793 |
ret = make_node (OMP_DISTRIBUTE); |
| 25794 |
TREE_TYPE (ret) = void_type_node; |
| 25795 |
OMP_FOR_BODY (ret) = block; |
| 25796 |
OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; |
| 25797 |
SET_EXPR_LOCATION (ret, loc); |
| 25798 |
add_stmt (ret); |
| 25799 |
return ret; |
| 25800 |
} |
| 25801 |
} |
| 25802 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25803 |
{ |
| 25804 |
c_parser_skip_to_pragma_eol (parser, false); |
| 25805 |
return NULL_TREE; |
| 25806 |
} |
| 25807 |
|
| 25808 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 25809 |
if (cclauses) |
| 25810 |
{ |
| 25811 |
omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses); |
| 25812 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; |
| 25813 |
} |
| 25814 |
|
| 25815 |
block = c_begin_compound_stmt (true); |
| 25816 |
ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL, |
| 25817 |
if_p); |
| 25818 |
block = c_end_compound_stmt (loc, block, true); |
| 25819 |
add_stmt (block); |
| 25820 |
|
| 25821 |
return ret; |
| 25822 |
} |
| 25823 |
|
| 25824 |
/* OpenMP 4.0: |
| 25825 |
# pragma omp teams teams-clause[optseq] new-line |
| 25826 |
structured-block */ |
| 25827 |
|
| 25828 |
#define OMP_TEAMS_CLAUSE_MASK \ |
| 25829 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 25830 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 25831 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 25832 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 25833 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \ |
| 25834 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \ |
| 25835 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 25836 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)) |
| 25837 |
|
| 25838 |
static tree |
| 25839 |
c_parser_omp_teams (location_t loc, c_parser *parser, |
| 25840 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 25841 |
bool *if_p) |
| 25842 |
{ |
| 25843 |
tree clauses, block, ret; |
| 25844 |
|
| 25845 |
strcat (p_name, " teams"); |
| 25846 |
mask |= OMP_TEAMS_CLAUSE_MASK; |
| 25847 |
|
| 25848 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 25849 |
{ |
| 25850 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 25851 |
if (strcmp (p, "distribute") == 0) |
| 25852 |
{ |
| 25853 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25854 |
if (cclauses == NULL) |
| 25855 |
cclauses = cclauses_buf; |
| 25856 |
|
| 25857 |
c_parser_consume_token (parser); |
| 25858 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25859 |
return c_parser_omp_distribute (loc, parser, p_name, mask, |
| 25860 |
cclauses, if_p); |
| 25861 |
block = c_begin_omp_parallel (); |
| 25862 |
ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses, |
| 25863 |
if_p); |
| 25864 |
block = c_end_compound_stmt (loc, block, true); |
| 25865 |
if (ret == NULL) |
| 25866 |
return ret; |
| 25867 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; |
| 25868 |
ret = make_node (OMP_TEAMS); |
| 25869 |
TREE_TYPE (ret) = void_type_node; |
| 25870 |
OMP_TEAMS_CLAUSES (ret) = clauses; |
| 25871 |
OMP_TEAMS_BODY (ret) = block; |
| 25872 |
OMP_TEAMS_COMBINED (ret) = 1; |
| 25873 |
SET_EXPR_LOCATION (ret, loc); |
| 25874 |
return add_stmt (ret); |
| 25875 |
} |
| 25876 |
else if (strcmp (p, "loop") == 0) |
| 25877 |
{ |
| 25878 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 25879 |
if (cclauses == NULL) |
| 25880 |
cclauses = cclauses_buf; |
| 25881 |
|
| 25882 |
c_parser_consume_token (parser); |
| 25883 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25884 |
return c_parser_omp_loop (loc, parser, p_name, mask, cclauses, |
| 25885 |
if_p); |
| 25886 |
block = c_begin_omp_parallel (); |
| 25887 |
ret = c_parser_omp_loop (loc, parser, p_name, mask, cclauses, if_p); |
| 25888 |
block = c_end_compound_stmt (loc, block, true); |
| 25889 |
if (ret == NULL) |
| 25890 |
return ret; |
| 25891 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; |
| 25892 |
ret = make_node (OMP_TEAMS); |
| 25893 |
TREE_TYPE (ret) = void_type_node; |
| 25894 |
OMP_TEAMS_CLAUSES (ret) = clauses; |
| 25895 |
OMP_TEAMS_BODY (ret) = block; |
| 25896 |
OMP_TEAMS_COMBINED (ret) = 1; |
| 25897 |
SET_EXPR_LOCATION (ret, loc); |
| 25898 |
return add_stmt (ret); |
| 25899 |
} |
| 25900 |
} |
| 25901 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 25902 |
{ |
| 25903 |
c_parser_skip_to_pragma_eol (parser, false); |
| 25904 |
return NULL_TREE; |
| 25905 |
} |
| 25906 |
|
| 25907 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 25908 |
if (cclauses) |
| 25909 |
{ |
| 25910 |
omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses); |
| 25911 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; |
| 25912 |
} |
| 25913 |
|
| 25914 |
tree stmt = make_node (OMP_TEAMS); |
| 25915 |
TREE_TYPE (stmt) = void_type_node; |
| 25916 |
OMP_TEAMS_CLAUSES (stmt) = clauses; |
| 25917 |
block = c_begin_omp_parallel (); |
| 25918 |
add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 25919 |
OMP_TEAMS_BODY (stmt) = c_end_compound_stmt (loc, block, true); |
| 25920 |
SET_EXPR_LOCATION (stmt, loc); |
| 25921 |
|
| 25922 |
return add_stmt (stmt); |
| 25923 |
} |
| 25924 |
|
| 25925 |
/* OpenMP 4.0: |
| 25926 |
# pragma omp target data target-data-clause[optseq] new-line |
| 25927 |
structured-block */ |
| 25928 |
|
| 25929 |
#define OMP_TARGET_DATA_CLAUSE_MASK \ |
| 25930 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 25931 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 25932 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 25933 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR) \ |
| 25934 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_ADDR)) |
| 25935 |
|
| 25936 |
static tree |
| 25937 |
c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p) |
| 25938 |
{ |
| 25939 |
if (flag_openmp) |
| 25940 |
omp_requires_mask |
| 25941 |
= (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); |
| 25942 |
|
| 25943 |
tree clauses |
| 25944 |
= c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK, |
| 25945 |
"#pragma omp target data"); |
| 25946 |
c_omp_adjust_map_clauses (clauses, false); |
| 25947 |
int map_seen = 0; |
| 25948 |
for (tree *pc = &clauses; *pc;) |
| 25949 |
{ |
| 25950 |
if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 25951 |
switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 25952 |
{ |
| 25953 |
case GOMP_MAP_TO: |
| 25954 |
case GOMP_MAP_ALWAYS_TO: |
| 25955 |
case GOMP_MAP_PRESENT_TO: |
| 25956 |
case GOMP_MAP_ALWAYS_PRESENT_TO: |
| 25957 |
case GOMP_MAP_FROM: |
| 25958 |
case GOMP_MAP_ALWAYS_FROM: |
| 25959 |
case GOMP_MAP_PRESENT_FROM: |
| 25960 |
case GOMP_MAP_ALWAYS_PRESENT_FROM: |
| 25961 |
case GOMP_MAP_TOFROM: |
| 25962 |
case GOMP_MAP_ALWAYS_TOFROM: |
| 25963 |
case GOMP_MAP_PRESENT_TOFROM: |
| 25964 |
case GOMP_MAP_ALWAYS_PRESENT_TOFROM: |
| 25965 |
case GOMP_MAP_ALLOC: |
| 25966 |
case GOMP_MAP_PRESENT_ALLOC: |
| 25967 |
map_seen = 3; |
| 25968 |
break; |
| 25969 |
case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 25970 |
case GOMP_MAP_ALWAYS_POINTER: |
| 25971 |
case GOMP_MAP_ATTACH_DETACH: |
| 25972 |
case GOMP_MAP_ATTACH: |
| 25973 |
break; |
| 25974 |
default: |
| 25975 |
map_seen |= 1; |
| 25976 |
error_at (OMP_CLAUSE_LOCATION (*pc), |
| 25977 |
"%<#pragma omp target data%> with map-type other " |
| 25978 |
"than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " |
| 25979 |
"on %<map%> clause"); |
| 25980 |
*pc = OMP_CLAUSE_CHAIN (*pc); |
| 25981 |
continue; |
| 25982 |
} |
| 25983 |
else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_PTR |
| 25984 |
|| OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_ADDR) |
| 25985 |
map_seen = 3; |
| 25986 |
pc = &OMP_CLAUSE_CHAIN (*pc); |
| 25987 |
} |
| 25988 |
|
| 25989 |
if (map_seen != 3) |
| 25990 |
{ |
| 25991 |
if (map_seen == 0) |
| 25992 |
error_at (loc, |
| 25993 |
"%<#pragma omp target data%> must contain at least " |
| 25994 |
"one %<map%>, %<use_device_ptr%> or %<use_device_addr%> " |
| 25995 |
"clause"); |
| 25996 |
return NULL_TREE; |
| 25997 |
} |
| 25998 |
|
| 25999 |
tree stmt = make_node (OMP_TARGET_DATA); |
| 26000 |
TREE_TYPE (stmt) = void_type_node; |
| 26001 |
OMP_TARGET_DATA_CLAUSES (stmt) = clauses; |
| 26002 |
keep_next_level (); |
| 26003 |
tree block = c_begin_compound_stmt (true); |
| 26004 |
add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 26005 |
OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true); |
| 26006 |
|
| 26007 |
SET_EXPR_LOCATION (stmt, loc); |
| 26008 |
return add_stmt (stmt); |
| 26009 |
} |
| 26010 |
|
| 26011 |
/* OpenMP 4.0: |
| 26012 |
# pragma omp target update target-update-clause[optseq] new-line */ |
| 26013 |
|
| 26014 |
#define OMP_TARGET_UPDATE_CLAUSE_MASK \ |
| 26015 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \ |
| 26016 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ |
| 26017 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 26018 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 26019 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 26020 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 26021 |
|
| 26022 |
static bool |
| 26023 |
c_parser_omp_target_update (location_t loc, c_parser *parser, |
| 26024 |
enum pragma_context context) |
| 26025 |
{ |
| 26026 |
if (context == pragma_stmt) |
| 26027 |
{ |
| 26028 |
error_at (loc, "%<#pragma %s%> may only be used in compound statements", |
| 26029 |
"omp target update"); |
| 26030 |
c_parser_skip_to_pragma_eol (parser, false); |
| 26031 |
return true; |
| 26032 |
} |
| 26033 |
|
| 26034 |
tree clauses |
| 26035 |
= c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK, |
| 26036 |
"#pragma omp target update"); |
| 26037 |
if (omp_find_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE |
| 26038 |
&& omp_find_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE) |
| 26039 |
{ |
| 26040 |
error_at (loc, |
| 26041 |
"%<#pragma omp target update%> must contain at least one " |
| 26042 |
"%<from%> or %<to%> clauses"); |
| 26043 |
return false; |
| 26044 |
} |
| 26045 |
|
| 26046 |
if (flag_openmp) |
| 26047 |
omp_requires_mask |
| 26048 |
= (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); |
| 26049 |
|
| 26050 |
tree stmt = make_node (OMP_TARGET_UPDATE); |
| 26051 |
TREE_TYPE (stmt) = void_type_node; |
| 26052 |
OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses; |
| 26053 |
SET_EXPR_LOCATION (stmt, loc); |
| 26054 |
add_stmt (stmt); |
| 26055 |
return false; |
| 26056 |
} |
| 26057 |
|
| 26058 |
/* OpenMP 4.5: |
| 26059 |
# pragma omp target enter data target-data-clause[optseq] new-line */ |
| 26060 |
|
| 26061 |
#define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \ |
| 26062 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 26063 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 26064 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 26065 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 26066 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 26067 |
|
| 26068 |
static bool |
| 26069 |
c_parser_omp_target_enter_data (location_t loc, c_parser *parser, |
| 26070 |
enum pragma_context context) |
| 26071 |
{ |
| 26072 |
bool data_seen = false; |
| 26073 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 26074 |
{ |
| 26075 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 26076 |
if (strcmp (p, "data") == 0) |
| 26077 |
{ |
| 26078 |
c_parser_consume_token (parser); |
| 26079 |
data_seen = true; |
| 26080 |
} |
| 26081 |
} |
| 26082 |
if (!data_seen) |
| 26083 |
{ |
| 26084 |
c_parser_error (parser, "expected %<data%>"); |
| 26085 |
c_parser_skip_to_pragma_eol (parser); |
| 26086 |
return false; |
| 26087 |
} |
| 26088 |
|
| 26089 |
if (context == pragma_stmt) |
| 26090 |
{ |
| 26091 |
error_at (loc, "%<#pragma %s%> may only be used in compound statements", |
| 26092 |
"omp target enter data"); |
| 26093 |
c_parser_skip_to_pragma_eol (parser, false); |
| 26094 |
return true; |
| 26095 |
} |
| 26096 |
|
| 26097 |
if (flag_openmp) |
| 26098 |
omp_requires_mask |
| 26099 |
= (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); |
| 26100 |
|
| 26101 |
tree clauses |
| 26102 |
= c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK, |
| 26103 |
"#pragma omp target enter data"); |
| 26104 |
c_omp_adjust_map_clauses (clauses, false); |
| 26105 |
int map_seen = 0; |
| 26106 |
for (tree *pc = &clauses; *pc;) |
| 26107 |
{ |
| 26108 |
if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 26109 |
switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 26110 |
{ |
| 26111 |
case GOMP_MAP_TO: |
| 26112 |
case GOMP_MAP_ALWAYS_TO: |
| 26113 |
case GOMP_MAP_PRESENT_TO: |
| 26114 |
case GOMP_MAP_ALWAYS_PRESENT_TO: |
| 26115 |
case GOMP_MAP_ALLOC: |
| 26116 |
case GOMP_MAP_PRESENT_ALLOC: |
| 26117 |
map_seen = 3; |
| 26118 |
break; |
| 26119 |
case GOMP_MAP_TOFROM: |
| 26120 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_TO); |
| 26121 |
map_seen = 3; |
| 26122 |
break; |
| 26123 |
case GOMP_MAP_ALWAYS_TOFROM: |
| 26124 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_TO); |
| 26125 |
map_seen = 3; |
| 26126 |
break; |
| 26127 |
case GOMP_MAP_PRESENT_TOFROM: |
| 26128 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_PRESENT_TO); |
| 26129 |
map_seen = 3; |
| 26130 |
break; |
| 26131 |
case GOMP_MAP_ALWAYS_PRESENT_TOFROM: |
| 26132 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_PRESENT_TO); |
| 26133 |
map_seen = 3; |
| 26134 |
break; |
| 26135 |
case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 26136 |
case GOMP_MAP_ALWAYS_POINTER: |
| 26137 |
case GOMP_MAP_ATTACH_DETACH: |
| 26138 |
case GOMP_MAP_ATTACH: |
| 26139 |
break; |
| 26140 |
default: |
| 26141 |
map_seen |= 1; |
| 26142 |
error_at (OMP_CLAUSE_LOCATION (*pc), |
| 26143 |
"%<#pragma omp target enter data%> with map-type other " |
| 26144 |
"than %<to%>, %<tofrom%> or %<alloc%> on %<map%> clause"); |
| 26145 |
*pc = OMP_CLAUSE_CHAIN (*pc); |
| 26146 |
continue; |
| 26147 |
} |
| 26148 |
pc = &OMP_CLAUSE_CHAIN (*pc); |
| 26149 |
} |
| 26150 |
|
| 26151 |
if (map_seen != 3) |
| 26152 |
{ |
| 26153 |
if (map_seen == 0) |
| 26154 |
error_at (loc, |
| 26155 |
"%<#pragma omp target enter data%> must contain at least " |
| 26156 |
"one %<map%> clause"); |
| 26157 |
return true; |
| 26158 |
} |
| 26159 |
|
| 26160 |
tree stmt = make_node (OMP_TARGET_ENTER_DATA); |
| 26161 |
TREE_TYPE (stmt) = void_type_node; |
| 26162 |
OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses; |
| 26163 |
SET_EXPR_LOCATION (stmt, loc); |
| 26164 |
add_stmt (stmt); |
| 26165 |
return true; |
| 26166 |
} |
| 26167 |
|
| 26168 |
/* OpenMP 4.5: |
| 26169 |
# pragma omp target exit data target-data-clause[optseq] new-line */ |
| 26170 |
|
| 26171 |
#define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \ |
| 26172 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 26173 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 26174 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 26175 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 26176 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 26177 |
|
| 26178 |
static bool |
| 26179 |
c_parser_omp_target_exit_data (location_t loc, c_parser *parser, |
| 26180 |
enum pragma_context context) |
| 26181 |
{ |
| 26182 |
bool data_seen = false; |
| 26183 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 26184 |
{ |
| 26185 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 26186 |
if (strcmp (p, "data") == 0) |
| 26187 |
{ |
| 26188 |
c_parser_consume_token (parser); |
| 26189 |
data_seen = true; |
| 26190 |
} |
| 26191 |
} |
| 26192 |
if (!data_seen) |
| 26193 |
{ |
| 26194 |
c_parser_error (parser, "expected %<data%>"); |
| 26195 |
c_parser_skip_to_pragma_eol (parser); |
| 26196 |
return false; |
| 26197 |
} |
| 26198 |
|
| 26199 |
if (context == pragma_stmt) |
| 26200 |
{ |
| 26201 |
error_at (loc, "%<#pragma %s%> may only be used in compound statements", |
| 26202 |
"omp target exit data"); |
| 26203 |
c_parser_skip_to_pragma_eol (parser, false); |
| 26204 |
return true; |
| 26205 |
} |
| 26206 |
|
| 26207 |
if (flag_openmp) |
| 26208 |
omp_requires_mask |
| 26209 |
= (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); |
| 26210 |
|
| 26211 |
tree clauses |
| 26212 |
= c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK, |
| 26213 |
"#pragma omp target exit data", false); |
| 26214 |
clauses = c_finish_omp_clauses (clauses, C_ORT_OMP_EXIT_DATA); |
| 26215 |
c_omp_adjust_map_clauses (clauses, false); |
| 26216 |
int map_seen = 0; |
| 26217 |
for (tree *pc = &clauses; *pc;) |
| 26218 |
{ |
| 26219 |
if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 26220 |
switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 26221 |
{ |
| 26222 |
case GOMP_MAP_FROM: |
| 26223 |
case GOMP_MAP_ALWAYS_FROM: |
| 26224 |
case GOMP_MAP_PRESENT_FROM: |
| 26225 |
case GOMP_MAP_ALWAYS_PRESENT_FROM: |
| 26226 |
case GOMP_MAP_RELEASE: |
| 26227 |
case GOMP_MAP_DELETE: |
| 26228 |
map_seen = 3; |
| 26229 |
break; |
| 26230 |
case GOMP_MAP_TOFROM: |
| 26231 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_FROM); |
| 26232 |
map_seen = 3; |
| 26233 |
break; |
| 26234 |
case GOMP_MAP_ALWAYS_TOFROM: |
| 26235 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_FROM); |
| 26236 |
map_seen = 3; |
| 26237 |
break; |
| 26238 |
case GOMP_MAP_PRESENT_TOFROM: |
| 26239 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_PRESENT_FROM); |
| 26240 |
map_seen = 3; |
| 26241 |
break; |
| 26242 |
case GOMP_MAP_ALWAYS_PRESENT_TOFROM: |
| 26243 |
OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_PRESENT_FROM); |
| 26244 |
map_seen = 3; |
| 26245 |
break; |
| 26246 |
case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 26247 |
case GOMP_MAP_ALWAYS_POINTER: |
| 26248 |
case GOMP_MAP_ATTACH_DETACH: |
| 26249 |
case GOMP_MAP_DETACH: |
| 26250 |
break; |
| 26251 |
default: |
| 26252 |
map_seen |= 1; |
| 26253 |
error_at (OMP_CLAUSE_LOCATION (*pc), |
| 26254 |
"%<#pragma omp target exit data%> with map-type other " |
| 26255 |
"than %<from%>, %<tofrom%>, %<release%> or %<delete%> " |
| 26256 |
"on %<map%> clause"); |
| 26257 |
*pc = OMP_CLAUSE_CHAIN (*pc); |
| 26258 |
continue; |
| 26259 |
} |
| 26260 |
pc = &OMP_CLAUSE_CHAIN (*pc); |
| 26261 |
} |
| 26262 |
|
| 26263 |
if (map_seen != 3) |
| 26264 |
{ |
| 26265 |
if (map_seen == 0) |
| 26266 |
error_at (loc, |
| 26267 |
"%<#pragma omp target exit data%> must contain at least one " |
| 26268 |
"%<map%> clause"); |
| 26269 |
return true; |
| 26270 |
} |
| 26271 |
|
| 26272 |
tree stmt = make_node (OMP_TARGET_EXIT_DATA); |
| 26273 |
TREE_TYPE (stmt) = void_type_node; |
| 26274 |
OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses; |
| 26275 |
SET_EXPR_LOCATION (stmt, loc); |
| 26276 |
add_stmt (stmt); |
| 26277 |
return true; |
| 26278 |
} |
| 26279 |
|
| 26280 |
/* OpenMP 4.0: |
| 26281 |
# pragma omp target target-clause[optseq] new-line |
| 26282 |
structured-block */ |
| 26283 |
|
| 26284 |
#define OMP_TARGET_CLAUSE_MASK \ |
| 26285 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 26286 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 26287 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 26288 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 26289 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \ |
| 26290 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 26291 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 26292 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 26293 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \ |
| 26294 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION) \ |
| 26295 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \ |
| 26296 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR)\ |
| 26297 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR)) |
| 26298 |
|
| 26299 |
static bool |
| 26300 |
c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p) |
| 26301 |
{ |
| 26302 |
location_t loc = c_parser_peek_token (parser)->location; |
| 26303 |
c_parser_consume_pragma (parser); |
| 26304 |
tree *pc = NULL, stmt, block; |
| 26305 |
|
| 26306 |
if (context != pragma_stmt && context != pragma_compound) |
| 26307 |
{ |
| 26308 |
c_parser_error (parser, "expected declaration specifiers"); |
| 26309 |
c_parser_skip_to_pragma_eol (parser); |
| 26310 |
return false; |
| 26311 |
} |
| 26312 |
|
| 26313 |
if (flag_openmp) |
| 26314 |
omp_requires_mask |
| 26315 |
= (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); |
| 26316 |
|
| 26317 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 26318 |
{ |
| 26319 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 26320 |
enum tree_code ccode = ERROR_MARK; |
| 26321 |
|
| 26322 |
if (strcmp (p, "teams") == 0) |
| 26323 |
ccode = OMP_TEAMS; |
| 26324 |
else if (strcmp (p, "parallel") == 0) |
| 26325 |
ccode = OMP_PARALLEL; |
| 26326 |
else if (strcmp (p, "simd") == 0) |
| 26327 |
ccode = OMP_SIMD; |
| 26328 |
if (ccode != ERROR_MARK) |
| 26329 |
{ |
| 26330 |
tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 26331 |
char p_name[sizeof ("#pragma omp target teams distribute " |
| 26332 |
"parallel for simd")]; |
| 26333 |
|
| 26334 |
c_parser_consume_token (parser); |
| 26335 |
strcpy (p_name, "#pragma omp target"); |
| 26336 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 26337 |
{ |
| 26338 |
tree stmt; |
| 26339 |
switch (ccode) |
| 26340 |
{ |
| 26341 |
case OMP_TEAMS: |
| 26342 |
stmt = c_parser_omp_teams (loc, parser, p_name, |
| 26343 |
OMP_TARGET_CLAUSE_MASK, |
| 26344 |
cclauses, if_p); |
| 26345 |
break; |
| 26346 |
case OMP_PARALLEL: |
| 26347 |
stmt = c_parser_omp_parallel (loc, parser, p_name, |
| 26348 |
OMP_TARGET_CLAUSE_MASK, |
| 26349 |
cclauses, if_p); |
| 26350 |
break; |
| 26351 |
case OMP_SIMD: |
| 26352 |
stmt = c_parser_omp_simd (loc, parser, p_name, |
| 26353 |
OMP_TARGET_CLAUSE_MASK, |
| 26354 |
cclauses, if_p); |
| 26355 |
break; |
| 26356 |
default: |
| 26357 |
gcc_unreachable (); |
| 26358 |
} |
| 26359 |
return stmt != NULL_TREE; |
| 26360 |
} |
| 26361 |
keep_next_level (); |
| 26362 |
tree block = c_begin_compound_stmt (true), ret; |
| 26363 |
switch (ccode) |
| 26364 |
{ |
| 26365 |
case OMP_TEAMS: |
| 26366 |
ret = c_parser_omp_teams (loc, parser, p_name, |
| 26367 |
OMP_TARGET_CLAUSE_MASK, cclauses, |
| 26368 |
if_p); |
| 26369 |
break; |
| 26370 |
case OMP_PARALLEL: |
| 26371 |
ret = c_parser_omp_parallel (loc, parser, p_name, |
| 26372 |
OMP_TARGET_CLAUSE_MASK, cclauses, |
| 26373 |
if_p); |
| 26374 |
break; |
| 26375 |
case OMP_SIMD: |
| 26376 |
ret = c_parser_omp_simd (loc, parser, p_name, |
| 26377 |
OMP_TARGET_CLAUSE_MASK, cclauses, |
| 26378 |
if_p); |
| 26379 |
break; |
| 26380 |
default: |
| 26381 |
gcc_unreachable (); |
| 26382 |
} |
| 26383 |
block = c_end_compound_stmt (loc, block, true); |
| 26384 |
if (ret == NULL_TREE) |
| 26385 |
return false; |
| 26386 |
if (ccode == OMP_TEAMS) |
| 26387 |
/* For combined target teams, ensure the num_teams and |
| 26388 |
thread_limit clause expressions are evaluated on the host, |
| 26389 |
before entering the target construct. */ |
| 26390 |
for (tree c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; |
| 26391 |
c; c = OMP_CLAUSE_CHAIN (c)) |
| 26392 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS |
| 26393 |
|| OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT) |
| 26394 |
for (int i = 0; |
| 26395 |
i <= (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS); ++i) |
| 26396 |
if (OMP_CLAUSE_OPERAND (c, i) |
| 26397 |
&& TREE_CODE (OMP_CLAUSE_OPERAND (c, i)) != INTEGER_CST) |
| 26398 |
{ |
| 26399 |
tree expr = OMP_CLAUSE_OPERAND (c, i); |
| 26400 |
tree tmp = create_tmp_var_raw (TREE_TYPE (expr)); |
| 26401 |
expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp, |
| 26402 |
expr, NULL_TREE, NULL_TREE); |
| 26403 |
add_stmt (expr); |
| 26404 |
OMP_CLAUSE_OPERAND (c, i) = expr; |
| 26405 |
tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c), |
| 26406 |
OMP_CLAUSE_FIRSTPRIVATE); |
| 26407 |
OMP_CLAUSE_DECL (tc) = tmp; |
| 26408 |
OMP_CLAUSE_CHAIN (tc) |
| 26409 |
= cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; |
| 26410 |
cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc; |
| 26411 |
} |
| 26412 |
tree stmt = make_node (OMP_TARGET); |
| 26413 |
TREE_TYPE (stmt) = void_type_node; |
| 26414 |
OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; |
| 26415 |
c_omp_adjust_map_clauses (OMP_TARGET_CLAUSES (stmt), true); |
| 26416 |
OMP_TARGET_BODY (stmt) = block; |
| 26417 |
OMP_TARGET_COMBINED (stmt) = 1; |
| 26418 |
SET_EXPR_LOCATION (stmt, loc); |
| 26419 |
add_stmt (stmt); |
| 26420 |
pc = &OMP_TARGET_CLAUSES (stmt); |
| 26421 |
goto check_clauses; |
| 26422 |
} |
| 26423 |
else if (!flag_openmp) /* flag_openmp_simd */ |
| 26424 |
{ |
| 26425 |
c_parser_skip_to_pragma_eol (parser, false); |
| 26426 |
return false; |
| 26427 |
} |
| 26428 |
else if (strcmp (p, "data") == 0) |
| 26429 |
{ |
| 26430 |
c_parser_consume_token (parser); |
| 26431 |
c_parser_omp_target_data (loc, parser, if_p); |
| 26432 |
return true; |
| 26433 |
} |
| 26434 |
else if (strcmp (p, "enter") == 0) |
| 26435 |
{ |
| 26436 |
c_parser_consume_token (parser); |
| 26437 |
return c_parser_omp_target_enter_data (loc, parser, context); |
| 26438 |
} |
| 26439 |
else if (strcmp (p, "exit") == 0) |
| 26440 |
{ |
| 26441 |
c_parser_consume_token (parser); |
| 26442 |
return c_parser_omp_target_exit_data (loc, parser, context); |
| 26443 |
} |
| 26444 |
else if (strcmp (p, "update") == 0) |
| 26445 |
{ |
| 26446 |
c_parser_consume_token (parser); |
| 26447 |
return c_parser_omp_target_update (loc, parser, context); |
| 26448 |
} |
| 26449 |
} |
| 26450 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 26451 |
{ |
| 26452 |
c_parser_skip_to_pragma_eol (parser, false); |
| 26453 |
return false; |
| 26454 |
} |
| 26455 |
|
| 26456 |
stmt = make_node (OMP_TARGET); |
| 26457 |
TREE_TYPE (stmt) = void_type_node; |
| 26458 |
|
| 26459 |
OMP_TARGET_CLAUSES (stmt) |
| 26460 |
= c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK, |
| 26461 |
"#pragma omp target", false); |
| 26462 |
for (tree c = OMP_TARGET_CLAUSES (stmt); c; c = OMP_CLAUSE_CHAIN (c)) |
| 26463 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION) |
| 26464 |
{ |
| 26465 |
tree nc = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP); |
| 26466 |
OMP_CLAUSE_DECL (nc) = OMP_CLAUSE_DECL (c); |
| 26467 |
OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_ALWAYS_TOFROM); |
| 26468 |
OMP_CLAUSE_CHAIN (nc) = OMP_CLAUSE_CHAIN (c); |
| 26469 |
OMP_CLAUSE_CHAIN (c) = nc; |
| 26470 |
} |
| 26471 |
OMP_TARGET_CLAUSES (stmt) |
| 26472 |
= c_finish_omp_clauses (OMP_TARGET_CLAUSES (stmt), C_ORT_OMP_TARGET); |
| 26473 |
c_omp_adjust_map_clauses (OMP_TARGET_CLAUSES (stmt), true); |
| 26474 |
|
| 26475 |
pc = &OMP_TARGET_CLAUSES (stmt); |
| 26476 |
keep_next_level (); |
| 26477 |
block = c_begin_compound_stmt (true); |
| 26478 |
add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 26479 |
OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true); |
| 26480 |
|
| 26481 |
SET_EXPR_LOCATION (stmt, loc); |
| 26482 |
add_stmt (stmt); |
| 26483 |
|
| 26484 |
check_clauses: |
| 26485 |
while (*pc) |
| 26486 |
{ |
| 26487 |
if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 26488 |
switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 26489 |
{ |
| 26490 |
case GOMP_MAP_TO: |
| 26491 |
case GOMP_MAP_ALWAYS_TO: |
| 26492 |
case GOMP_MAP_PRESENT_TO: |
| 26493 |
case GOMP_MAP_ALWAYS_PRESENT_TO: |
| 26494 |
case GOMP_MAP_FROM: |
| 26495 |
case GOMP_MAP_ALWAYS_FROM: |
| 26496 |
case GOMP_MAP_PRESENT_FROM: |
| 26497 |
case GOMP_MAP_ALWAYS_PRESENT_FROM: |
| 26498 |
case GOMP_MAP_TOFROM: |
| 26499 |
case GOMP_MAP_ALWAYS_TOFROM: |
| 26500 |
case GOMP_MAP_PRESENT_TOFROM: |
| 26501 |
case GOMP_MAP_ALWAYS_PRESENT_TOFROM: |
| 26502 |
case GOMP_MAP_ALLOC: |
| 26503 |
case GOMP_MAP_PRESENT_ALLOC: |
| 26504 |
case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 26505 |
case GOMP_MAP_ALWAYS_POINTER: |
| 26506 |
case GOMP_MAP_POINTER: |
| 26507 |
case GOMP_MAP_ATTACH_DETACH: |
| 26508 |
case GOMP_MAP_ATTACH: |
| 26509 |
break; |
| 26510 |
default: |
| 26511 |
error_at (OMP_CLAUSE_LOCATION (*pc), |
| 26512 |
"%<#pragma omp target%> with map-type other " |
| 26513 |
"than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " |
| 26514 |
"on %<map%> clause"); |
| 26515 |
*pc = OMP_CLAUSE_CHAIN (*pc); |
| 26516 |
continue; |
| 26517 |
} |
| 26518 |
pc = &OMP_CLAUSE_CHAIN (*pc); |
| 26519 |
} |
| 26520 |
cfun->has_omp_target = true; |
| 26521 |
return true; |
| 26522 |
} |
| 26523 |
|
| 26524 |
/* OpenMP 4.0: |
| 26525 |
# pragma omp declare simd declare-simd-clauses[optseq] new-line |
| 26526 |
|
| 26527 |
OpenMP 5.0: |
| 26528 |
# pragma omp declare variant (identifier) match(context-selector) new-line |
| 26529 |
|
| 26530 |
OpenMP 5.1 |
| 26531 |
# pragma omp declare variant (identifier) match(context-selector) \ |
| 26532 |
adjust_args(adjust-op:argument-list) append_args(interop-list) new-line |
| 26533 |
*/ |
| 26534 |
|
| 26535 |
#define OMP_DECLARE_SIMD_CLAUSE_MASK \ |
| 26536 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ |
| 26537 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
| 26538 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ |
| 26539 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \ |
| 26540 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \ |
| 26541 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH)) |
| 26542 |
|
| 26543 |
static void |
| 26544 |
c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context) |
| 26545 |
{ |
| 26546 |
c_token *token = c_parser_peek_token (parser); |
| 26547 |
gcc_assert (token->type == CPP_NAME); |
| 26548 |
tree kind = token->value; |
| 26549 |
gcc_assert (strcmp (IDENTIFIER_POINTER (kind), "simd") == 0 |
| 26550 |
|| strcmp (IDENTIFIER_POINTER (kind), "variant") == 0); |
| 26551 |
|
| 26552 |
auto_vec<c_token> clauses; |
| 26553 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 26554 |
{ |
| 26555 |
c_token *token = c_parser_peek_token (parser); |
| 26556 |
if (token->type == CPP_EOF) |
| 26557 |
{ |
| 26558 |
c_parser_skip_to_pragma_eol (parser); |
| 26559 |
return; |
| 26560 |
} |
| 26561 |
clauses.safe_push (*token); |
| 26562 |
c_parser_consume_token (parser); |
| 26563 |
} |
| 26564 |
clauses.safe_push (*c_parser_peek_token (parser)); |
| 26565 |
c_parser_skip_to_pragma_eol (parser); |
| 26566 |
|
| 26567 |
while (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 26568 |
{ |
| 26569 |
if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_DECLARE |
| 26570 |
|| c_parser_peek_2nd_token (parser)->type != CPP_NAME |
| 26571 |
|| c_parser_peek_2nd_token (parser)->value != kind) |
| 26572 |
{ |
| 26573 |
error ("%<#pragma omp declare %s%> must be followed by " |
| 26574 |
"function declaration or definition or another " |
| 26575 |
"%<#pragma omp declare %s%>", |
| 26576 |
IDENTIFIER_POINTER (kind), IDENTIFIER_POINTER (kind)); |
| 26577 |
return; |
| 26578 |
} |
| 26579 |
c_parser_consume_pragma (parser); |
| 26580 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 26581 |
{ |
| 26582 |
c_token *token = c_parser_peek_token (parser); |
| 26583 |
if (token->type == CPP_EOF) |
| 26584 |
{ |
| 26585 |
c_parser_skip_to_pragma_eol (parser); |
| 26586 |
return; |
| 26587 |
} |
| 26588 |
clauses.safe_push (*token); |
| 26589 |
c_parser_consume_token (parser); |
| 26590 |
} |
| 26591 |
clauses.safe_push (*c_parser_peek_token (parser)); |
| 26592 |
c_parser_skip_to_pragma_eol (parser); |
| 26593 |
} |
| 26594 |
|
| 26595 |
/* Make sure nothing tries to read past the end of the tokens. */ |
| 26596 |
c_token eof_token; |
| 26597 |
memset (&eof_token, 0, sizeof (eof_token)); |
| 26598 |
eof_token.type = CPP_EOF; |
| 26599 |
clauses.safe_push (eof_token); |
| 26600 |
clauses.safe_push (eof_token); |
| 26601 |
|
| 26602 |
switch (context) |
| 26603 |
{ |
| 26604 |
case pragma_external: |
| 26605 |
if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 26606 |
&& c_parser_peek_token (parser)->keyword == RID_EXTENSION) |
| 26607 |
{ |
| 26608 |
int ext = disable_extension_diagnostics (); |
| 26609 |
do |
| 26610 |
c_parser_consume_token (parser); |
| 26611 |
while (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 26612 |
&& c_parser_peek_token (parser)->keyword == RID_EXTENSION); |
| 26613 |
c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 26614 |
false, NULL, &clauses); |
| 26615 |
restore_extension_diagnostics (ext); |
| 26616 |
} |
| 26617 |
else |
| 26618 |
c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 26619 |
false, NULL, &clauses); |
| 26620 |
break; |
| 26621 |
case pragma_struct: |
| 26622 |
case pragma_param: |
| 26623 |
case pragma_stmt: |
| 26624 |
error ("%<#pragma omp declare %s%> must be followed by " |
| 26625 |
"function declaration or definition", |
| 26626 |
IDENTIFIER_POINTER (kind)); |
| 26627 |
break; |
| 26628 |
case pragma_compound: |
| 26629 |
bool have_std_attrs; |
| 26630 |
tree std_attrs; |
| 26631 |
have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1); |
| 26632 |
if (have_std_attrs) |
| 26633 |
std_attrs = c_parser_std_attribute_specifier_sequence (parser); |
| 26634 |
else |
| 26635 |
std_attrs = NULL_TREE; |
| 26636 |
if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 26637 |
&& c_parser_peek_token (parser)->keyword == RID_EXTENSION) |
| 26638 |
{ |
| 26639 |
int ext = disable_extension_diagnostics (); |
| 26640 |
do |
| 26641 |
c_parser_consume_token (parser); |
| 26642 |
while (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 26643 |
&& c_parser_peek_token (parser)->keyword == RID_EXTENSION); |
| 26644 |
if (c_parser_next_tokens_start_declaration (parser) |
| 26645 |
|| c_parser_nth_token_starts_std_attributes (parser, 1)) |
| 26646 |
{ |
| 26647 |
c_parser_declaration_or_fndef (parser, true, true, true, true, |
| 26648 |
true, false, NULL, &clauses, |
| 26649 |
have_std_attrs, std_attrs); |
| 26650 |
restore_extension_diagnostics (ext); |
| 26651 |
break; |
| 26652 |
} |
| 26653 |
restore_extension_diagnostics (ext); |
| 26654 |
} |
| 26655 |
else if (c_parser_next_tokens_start_declaration (parser)) |
| 26656 |
{ |
| 26657 |
c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
| 26658 |
false, NULL, &clauses, have_std_attrs, |
| 26659 |
std_attrs); |
| 26660 |
break; |
| 26661 |
} |
| 26662 |
error ("%<#pragma omp declare %s%> must be followed by " |
| 26663 |
"function declaration or definition", |
| 26664 |
IDENTIFIER_POINTER (kind)); |
| 26665 |
break; |
| 26666 |
default: |
| 26667 |
gcc_unreachable (); |
| 26668 |
} |
| 26669 |
} |
| 26670 |
|
| 26671 |
/* OpenMP 5.0: |
| 26672 |
|
| 26673 |
trait-selector: |
| 26674 |
trait-selector-name[([trait-score:]trait-property[,trait-property[,...]])] |
| 26675 |
|
| 26676 |
trait-score: |
| 26677 |
score(score-expression) |
| 26678 |
|
| 26679 |
Note that this function returns a list of trait selectors for the |
| 26680 |
trait-selector-set SET. */ |
| 26681 |
|
| 26682 |
static tree |
| 26683 |
c_parser_omp_context_selector (c_parser *parser, enum omp_tss_code set, |
| 26684 |
tree parms) |
| 26685 |
{ |
| 26686 |
tree ret = NULL_TREE; |
| 26687 |
do |
| 26688 |
{ |
| 26689 |
tree selector; |
| 26690 |
if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 26691 |
|| c_parser_next_token_is (parser, CPP_NAME)) |
| 26692 |
selector = c_parser_peek_token (parser)->value; |
| 26693 |
else |
| 26694 |
{ |
| 26695 |
c_parser_error (parser, "expected trait selector name"); |
| 26696 |
return error_mark_node; |
| 26697 |
} |
| 26698 |
enum omp_ts_code sel |
| 26699 |
= omp_lookup_ts_code (set, IDENTIFIER_POINTER (selector)); |
| 26700 |
|
| 26701 |
if (sel == OMP_TRAIT_INVALID) |
| 26702 |
{ |
| 26703 |
/* Per the spec, "Implementations can ignore specified selectors |
| 26704 |
that are not those described in this section"; however, we |
| 26705 |
must record such selectors because they cause match failures. */ |
| 26706 |
warning_at (c_parser_peek_token (parser)->location, OPT_Wopenmp, |
| 26707 |
"unknown selector %qs for context selector set %qs", |
| 26708 |
IDENTIFIER_POINTER (selector), omp_tss_map[set]); |
| 26709 |
c_parser_consume_token (parser); |
| 26710 |
ret = make_trait_selector (sel, NULL_TREE, NULL_TREE, ret); |
| 26711 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 26712 |
c_parser_balanced_token_sequence (parser); |
| 26713 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 26714 |
{ |
| 26715 |
c_parser_consume_token (parser); |
| 26716 |
continue; |
| 26717 |
} |
| 26718 |
else |
| 26719 |
break; |
| 26720 |
} |
| 26721 |
|
| 26722 |
c_parser_consume_token (parser); |
| 26723 |
|
| 26724 |
tree properties = NULL_TREE; |
| 26725 |
tree scoreval = NULL_TREE; |
| 26726 |
enum omp_tp_type property_kind = omp_ts_map[sel].tp_type; |
| 26727 |
bool allow_score = omp_ts_map[sel].allow_score; |
| 26728 |
tree t; |
| 26729 |
|
| 26730 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 26731 |
{ |
| 26732 |
if (property_kind == OMP_TRAIT_PROPERTY_NONE) |
| 26733 |
{ |
| 26734 |
error_at (c_parser_peek_token (parser)->location, |
| 26735 |
"selector %qs does not accept any properties", |
| 26736 |
IDENTIFIER_POINTER (selector)); |
| 26737 |
return error_mark_node; |
| 26738 |
} |
| 26739 |
|
| 26740 |
matching_parens parens; |
| 26741 |
parens.require_open (parser); |
| 26742 |
|
| 26743 |
c_token *token = c_parser_peek_token (parser); |
| 26744 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 26745 |
&& strcmp (IDENTIFIER_POINTER (token->value), "score") == 0 |
| 26746 |
&& c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN) |
| 26747 |
{ |
| 26748 |
c_parser_consume_token (parser); |
| 26749 |
|
| 26750 |
matching_parens parens2; |
| 26751 |
parens2.require_open (parser); |
| 26752 |
tree score = c_parser_expr_no_commas (parser, NULL).value; |
| 26753 |
parens2.skip_until_found_close (parser); |
| 26754 |
c_parser_require (parser, CPP_COLON, "expected %<:%>"); |
| 26755 |
if (!allow_score) |
| 26756 |
error_at (token->location, |
| 26757 |
"%<score%> cannot be specified in traits " |
| 26758 |
"in the %qs trait-selector-set", |
| 26759 |
omp_tss_map[set]); |
| 26760 |
else if (score != error_mark_node) |
| 26761 |
{ |
| 26762 |
mark_exp_read (score); |
| 26763 |
score = c_fully_fold (score, false, NULL); |
| 26764 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (score)) |
| 26765 |
|| TREE_CODE (score) != INTEGER_CST) |
| 26766 |
error_at (token->location, "%<score%> argument must " |
| 26767 |
"be constant integer expression"); |
| 26768 |
else if (tree_int_cst_sgn (score) < 0) |
| 26769 |
error_at (token->location, "%<score%> argument must " |
| 26770 |
"be non-negative"); |
| 26771 |
else |
| 26772 |
scoreval = score; |
| 26773 |
} |
| 26774 |
token = c_parser_peek_token (parser); |
| 26775 |
} |
| 26776 |
|
| 26777 |
switch (property_kind) |
| 26778 |
{ |
| 26779 |
case OMP_TRAIT_PROPERTY_ID: |
| 26780 |
if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 26781 |
|| c_parser_next_token_is (parser, CPP_NAME)) |
| 26782 |
{ |
| 26783 |
tree prop = c_parser_peek_token (parser)->value; |
| 26784 |
c_parser_consume_token (parser); |
| 26785 |
properties = make_trait_property (prop, NULL_TREE, |
| 26786 |
properties); |
| 26787 |
} |
| 26788 |
else |
| 26789 |
{ |
| 26790 |
c_parser_error (parser, "expected identifier"); |
| 26791 |
return error_mark_node; |
| 26792 |
} |
| 26793 |
break; |
| 26794 |
case OMP_TRAIT_PROPERTY_NAME_LIST: |
| 26795 |
do |
| 26796 |
{ |
| 26797 |
tree prop = OMP_TP_NAMELIST_NODE; |
| 26798 |
tree value = NULL_TREE; |
| 26799 |
if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 26800 |
|| c_parser_next_token_is (parser, CPP_NAME)) |
| 26801 |
{ |
| 26802 |
value = c_parser_peek_token (parser)->value; |
| 26803 |
c_parser_consume_token (parser); |
| 26804 |
} |
| 26805 |
else if (c_parser_next_token_is (parser, CPP_STRING)) |
| 26806 |
value = c_parser_string_literal (parser, false, |
| 26807 |
false).value; |
| 26808 |
else |
| 26809 |
{ |
| 26810 |
c_parser_error (parser, "expected identifier or " |
| 26811 |
"string literal"); |
| 26812 |
return error_mark_node; |
| 26813 |
} |
| 26814 |
|
| 26815 |
properties = make_trait_property (prop, value, properties); |
| 26816 |
|
| 26817 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 26818 |
c_parser_consume_token (parser); |
| 26819 |
else |
| 26820 |
break; |
| 26821 |
} |
| 26822 |
while (1); |
| 26823 |
break; |
| 26824 |
case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR: |
| 26825 |
case OMP_TRAIT_PROPERTY_BOOL_EXPR: |
| 26826 |
t = c_parser_expr_no_commas (parser, NULL).value; |
| 26827 |
if (t == error_mark_node) |
| 26828 |
return error_mark_node; |
| 26829 |
mark_exp_read (t); |
| 26830 |
t = c_fully_fold (t, false, NULL); |
| 26831 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 26832 |
{ |
| 26833 |
error_at (token->location, |
| 26834 |
"property must be integer expression"); |
| 26835 |
return error_mark_node; |
| 26836 |
} |
| 26837 |
properties = make_trait_property (NULL_TREE, t, properties); |
| 26838 |
break; |
| 26839 |
case OMP_TRAIT_PROPERTY_CLAUSE_LIST: |
| 26840 |
if (sel == OMP_TRAIT_CONSTRUCT_SIMD) |
| 26841 |
{ |
| 26842 |
if (parms == NULL_TREE) |
| 26843 |
{ |
| 26844 |
error_at (token->location, "properties for %<simd%> " |
| 26845 |
"selector may not be specified in " |
| 26846 |
"%<metadirective%>"); |
| 26847 |
return error_mark_node; |
| 26848 |
} |
| 26849 |
tree c; |
| 26850 |
c = c_parser_omp_all_clauses (parser, |
| 26851 |
OMP_DECLARE_SIMD_CLAUSE_MASK, |
| 26852 |
"simd", true, 2); |
| 26853 |
c = c_omp_declare_simd_clauses_to_numbers (parms |
| 26854 |
== error_mark_node |
| 26855 |
? NULL_TREE : parms, |
| 26856 |
c); |
| 26857 |
properties = c; |
| 26858 |
} |
| 26859 |
else if (sel == OMP_TRAIT_IMPLEMENTATION_REQUIRES) |
| 26860 |
{ |
| 26861 |
/* FIXME: The "requires" selector was added in OpenMP 5.1. |
| 26862 |
Currently only the now-deprecated syntax |
| 26863 |
from OpenMP 5.0 is supported. */ |
| 26864 |
sorry_at (token->location, |
| 26865 |
"%<requires%> selector is not supported yet"); |
| 26866 |
return error_mark_node; |
| 26867 |
} |
| 26868 |
else |
| 26869 |
gcc_unreachable (); |
| 26870 |
break; |
| 26871 |
default: |
| 26872 |
gcc_unreachable (); |
| 26873 |
} |
| 26874 |
|
| 26875 |
parens.skip_until_found_close (parser); |
| 26876 |
properties = nreverse (properties); |
| 26877 |
} |
| 26878 |
else if (property_kind != OMP_TRAIT_PROPERTY_NONE |
| 26879 |
&& property_kind != OMP_TRAIT_PROPERTY_CLAUSE_LIST |
| 26880 |
&& property_kind != OMP_TRAIT_PROPERTY_EXTENSION) |
| 26881 |
{ |
| 26882 |
c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"); |
| 26883 |
return error_mark_node; |
| 26884 |
} |
| 26885 |
|
| 26886 |
ret = make_trait_selector (sel, scoreval, properties, ret); |
| 26887 |
|
| 26888 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 26889 |
c_parser_consume_token (parser); |
| 26890 |
else |
| 26891 |
break; |
| 26892 |
} |
| 26893 |
while (1); |
| 26894 |
|
| 26895 |
return nreverse (ret); |
| 26896 |
} |
| 26897 |
|
| 26898 |
/* OpenMP 5.0: |
| 26899 |
|
| 26900 |
trait-set-selector[,trait-set-selector[,...]] |
| 26901 |
|
| 26902 |
trait-set-selector: |
| 26903 |
trait-set-selector-name = { trait-selector[, trait-selector[, ...]] } |
| 26904 |
|
| 26905 |
trait-set-selector-name: |
| 26906 |
constructor |
| 26907 |
device |
| 26908 |
implementation |
| 26909 |
user */ |
| 26910 |
|
| 26911 |
static tree |
| 26912 |
c_parser_omp_context_selector_specification (c_parser *parser, tree parms) |
| 26913 |
{ |
| 26914 |
tree ret = NULL_TREE; |
| 26915 |
do |
| 26916 |
{ |
| 26917 |
const char *setp = ""; |
| 26918 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 26919 |
setp = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 26920 |
enum omp_tss_code set = omp_lookup_tss_code (setp); |
| 26921 |
|
| 26922 |
if (set == OMP_TRAIT_SET_INVALID) |
| 26923 |
{ |
| 26924 |
c_parser_error (parser, "expected context selector set name"); |
| 26925 |
return error_mark_node; |
| 26926 |
} |
| 26927 |
|
| 26928 |
c_parser_consume_token (parser); |
| 26929 |
|
| 26930 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 26931 |
return error_mark_node; |
| 26932 |
|
| 26933 |
matching_braces braces; |
| 26934 |
if (!braces.require_open (parser)) |
| 26935 |
return error_mark_node; |
| 26936 |
|
| 26937 |
tree selectors = c_parser_omp_context_selector (parser, set, parms); |
| 26938 |
if (selectors == error_mark_node) |
| 26939 |
{ |
| 26940 |
c_parser_skip_to_closing_brace (parser); |
| 26941 |
ret = error_mark_node; |
| 26942 |
} |
| 26943 |
else if (ret != error_mark_node) |
| 26944 |
ret = make_trait_set_selector (set, selectors, ret); |
| 26945 |
|
| 26946 |
braces.require_close (parser); |
| 26947 |
|
| 26948 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 26949 |
c_parser_consume_token (parser); |
| 26950 |
else |
| 26951 |
break; |
| 26952 |
} |
| 26953 |
while (1); |
| 26954 |
|
| 26955 |
if (ret == error_mark_node) |
| 26956 |
return ret; |
| 26957 |
return nreverse (ret); |
| 26958 |
} |
| 26959 |
|
| 26960 |
/* Finalize #pragma omp declare variant after FNDECL has been parsed, and put |
| 26961 |
that into "omp declare variant base" attribute. */ |
| 26962 |
|
| 26963 |
static void |
| 26964 |
c_finish_omp_declare_variant (c_parser *parser, tree fndecl, tree parms) |
| 26965 |
{ |
| 26966 |
matching_parens parens; |
| 26967 |
if (!parens.require_open (parser)) |
| 26968 |
{ |
| 26969 |
fail: |
| 26970 |
c_parser_skip_to_pragma_eol (parser, false); |
| 26971 |
return; |
| 26972 |
} |
| 26973 |
|
| 26974 |
if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 26975 |
|| c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 26976 |
{ |
| 26977 |
c_parser_error (parser, "expected identifier"); |
| 26978 |
goto fail; |
| 26979 |
} |
| 26980 |
|
| 26981 |
c_token *token = c_parser_peek_token (parser); |
| 26982 |
tree variant = lookup_name (token->value); |
| 26983 |
|
| 26984 |
if (variant == NULL_TREE) |
| 26985 |
{ |
| 26986 |
undeclared_variable (token->location, token->value); |
| 26987 |
variant = error_mark_node; |
| 26988 |
} |
| 26989 |
|
| 26990 |
c_parser_consume_token (parser); |
| 26991 |
|
| 26992 |
parens.require_close (parser); |
| 26993 |
|
| 26994 |
tree append_args_tree = NULL_TREE; |
| 26995 |
tree append_args_last; |
| 26996 |
vec<tree> adjust_args_list = vNULL; |
| 26997 |
bool has_match = false, has_adjust_args = false; |
| 26998 |
location_t adjust_args_loc = UNKNOWN_LOCATION; |
| 26999 |
location_t append_args_loc = UNKNOWN_LOCATION; |
| 27000 |
location_t match_loc = UNKNOWN_LOCATION; |
| 27001 |
tree need_device_ptr_list = NULL_TREE; |
| 27002 |
tree ctx = error_mark_node; |
| 27003 |
|
| 27004 |
do |
| 27005 |
{ |
| 27006 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 27007 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 27008 |
c_parser_consume_token (parser); |
| 27009 |
|
| 27010 |
const char *clause = ""; |
| 27011 |
location_t loc = c_parser_peek_token (parser)->location; |
| 27012 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 27013 |
clause = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 27014 |
|
| 27015 |
enum clause |
| 27016 |
{ |
| 27017 |
match, |
| 27018 |
adjust_args, |
| 27019 |
append_args |
| 27020 |
} ccode; |
| 27021 |
|
| 27022 |
if (strcmp (clause, "match") == 0) |
| 27023 |
{ |
| 27024 |
ccode = match; |
| 27025 |
match_loc = loc; |
| 27026 |
} |
| 27027 |
else if (strcmp (clause, "adjust_args") == 0) |
| 27028 |
{ |
| 27029 |
ccode = adjust_args; |
| 27030 |
adjust_args_loc = loc; |
| 27031 |
} |
| 27032 |
else if (strcmp (clause, "append_args") == 0) |
| 27033 |
{ |
| 27034 |
ccode = append_args; |
| 27035 |
append_args_loc = loc; |
| 27036 |
} |
| 27037 |
else |
| 27038 |
{ |
| 27039 |
c_parser_error (parser, "expected %<match%>, %<adjust_args%> or " |
| 27040 |
"%<append_args%> clause"); |
| 27041 |
goto fail; |
| 27042 |
} |
| 27043 |
|
| 27044 |
c_parser_consume_token (parser); |
| 27045 |
|
| 27046 |
if (!parens.require_open (parser)) |
| 27047 |
goto fail; |
| 27048 |
|
| 27049 |
if (parms == NULL_TREE) |
| 27050 |
parms = error_mark_node; |
| 27051 |
|
| 27052 |
if (ccode == match) |
| 27053 |
{ |
| 27054 |
if (has_match) |
| 27055 |
error_at (match_loc, "too many %<match%> clauses"); |
| 27056 |
has_match = true; |
| 27057 |
ctx = c_parser_omp_context_selector_specification (parser, parms); |
| 27058 |
if (ctx == error_mark_node) |
| 27059 |
goto fail; |
| 27060 |
ctx = omp_check_context_selector (match_loc, ctx, |
| 27061 |
OMP_CTX_DECLARE_VARIANT); |
| 27062 |
if (ctx != error_mark_node && variant != error_mark_node) |
| 27063 |
{ |
| 27064 |
if (TREE_CODE (variant) != FUNCTION_DECL) |
| 27065 |
{ |
| 27066 |
error_at (token->location, "variant %qD is not a function", |
| 27067 |
variant); |
| 27068 |
variant = error_mark_node; |
| 27069 |
} |
| 27070 |
else if (fndecl_built_in_p (variant) |
| 27071 |
&& (strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)), |
| 27072 |
"__builtin_", strlen ("__builtin_")) |
| 27073 |
== 0 |
| 27074 |
|| strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)), |
| 27075 |
"__sync_", strlen ("__sync_")) |
| 27076 |
== 0 |
| 27077 |
|| strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)), |
| 27078 |
"__atomic_", strlen ("__atomic_")) |
| 27079 |
== 0)) |
| 27080 |
{ |
| 27081 |
error_at (token->location, "variant %qD is a built-in", |
| 27082 |
variant); |
| 27083 |
variant = error_mark_node; |
| 27084 |
} |
| 27085 |
} |
| 27086 |
} |
| 27087 |
else if (ccode == adjust_args) |
| 27088 |
{ |
| 27089 |
has_adjust_args = true; |
| 27090 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 27091 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 27092 |
{ |
| 27093 |
const char *p |
| 27094 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 27095 |
if (strcmp (p, "need_device_ptr") == 0 |
| 27096 |
|| strcmp (p, "nothing") == 0) |
| 27097 |
{ |
| 27098 |
c_parser_consume_token (parser); // need_device_ptr |
| 27099 |
c_parser_consume_token (parser); // : |
| 27100 |
|
| 27101 |
loc = c_parser_peek_token (parser)->location; |
| 27102 |
tree list |
| 27103 |
= c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_ERROR, |
| 27104 |
NULL_TREE); |
| 27105 |
|
| 27106 |
tree arg; |
| 27107 |
if (variant != error_mark_node) |
| 27108 |
for (tree c = list; c != NULL_TREE; c = TREE_CHAIN (c)) |
| 27109 |
{ |
| 27110 |
tree decl = TREE_PURPOSE (c); |
| 27111 |
location_t arg_loc = EXPR_LOCATION (TREE_VALUE (c)); |
| 27112 |
int idx; |
| 27113 |
for (arg = parms, idx = 0; arg != NULL; |
| 27114 |
arg = TREE_CHAIN (arg), idx++) |
| 27115 |
if (arg == decl) |
| 27116 |
break; |
| 27117 |
if (arg == NULL_TREE) |
| 27118 |
{ |
| 27119 |
error_at (arg_loc, |
| 27120 |
"%qD is not a function argument", |
| 27121 |
decl); |
| 27122 |
goto fail; |
| 27123 |
} |
| 27124 |
if (adjust_args_list.contains (arg)) |
| 27125 |
{ |
| 27126 |
error_at (arg_loc, |
| 27127 |
"%qD is specified more than once", |
| 27128 |
decl); |
| 27129 |
goto fail; |
| 27130 |
} |
| 27131 |
if (strcmp (p, "need_device_ptr") == 0 |
| 27132 |
&& TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE) |
| 27133 |
{ |
| 27134 |
error_at (loc, "%qD is not of pointer type", decl); |
| 27135 |
goto fail; |
| 27136 |
} |
| 27137 |
adjust_args_list.safe_push (arg); |
| 27138 |
if (strcmp (p, "need_device_ptr") == 0) |
| 27139 |
{ |
| 27140 |
need_device_ptr_list = chainon ( |
| 27141 |
need_device_ptr_list, |
| 27142 |
build_tree_list ( |
| 27143 |
NULL_TREE, |
| 27144 |
build_int_cst ( |
| 27145 |
integer_type_node, |
| 27146 |
idx))); // Store 0-based argument index, |
| 27147 |
// as in gimplify_call_expr |
| 27148 |
} |
| 27149 |
} |
| 27150 |
} |
| 27151 |
else |
| 27152 |
{ |
| 27153 |
error_at (c_parser_peek_token (parser)->location, |
| 27154 |
"expected %<nothing%> or %<need_device_ptr%>"); |
| 27155 |
if (strcmp (p, "need_device_addr") == 0) |
| 27156 |
inform (c_parser_peek_token (parser)->location, |
| 27157 |
"%<need_device_addr%> is not valid for C"); |
| 27158 |
goto fail; |
| 27159 |
} |
| 27160 |
} |
| 27161 |
else |
| 27162 |
{ |
| 27163 |
error_at (c_parser_peek_token (parser)->location, |
| 27164 |
"expected %<nothing%> or %<need_device_ptr%> " |
| 27165 |
"followed by %<:%>"); |
| 27166 |
goto fail; |
| 27167 |
} |
| 27168 |
} |
| 27169 |
else if (ccode == append_args) |
| 27170 |
{ |
| 27171 |
if (append_args_tree) |
| 27172 |
{ |
| 27173 |
error_at (append_args_loc, "too many %qs clauses", "append_args"); |
| 27174 |
append_args_tree = NULL_TREE; |
| 27175 |
} |
| 27176 |
do |
| 27177 |
{ |
| 27178 |
location_t loc = c_parser_peek_token (parser)->location; |
| 27179 |
if (!c_parser_next_token_is (parser, CPP_NAME) |
| 27180 |
|| strcmp ("interop", |
| 27181 |
IDENTIFIER_POINTER ( |
| 27182 |
c_parser_peek_token (parser)->value))) |
| 27183 |
{ |
| 27184 |
error_at (loc, "expected %<interop%>"); |
| 27185 |
goto fail; |
| 27186 |
} |
| 27187 |
c_parser_consume_token (parser); |
| 27188 |
|
| 27189 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 27190 |
goto fail; |
| 27191 |
bool target = false; |
| 27192 |
bool targetsync = false; |
| 27193 |
tree prefer_type_tree = NULL_TREE; |
| 27194 |
if (!c_parser_omp_clause_init_modifiers (parser, &target, |
| 27195 |
&targetsync, |
| 27196 |
&prefer_type_tree) |
| 27197 |
|| !c_parser_require (parser, CPP_CLOSE_PAREN, |
| 27198 |
"expected %<)%> or %<,%>")) |
| 27199 |
goto fail; |
| 27200 |
if (!target && !targetsync) |
| 27201 |
error_at (loc, |
| 27202 |
"missing required %<target%> and/or " |
| 27203 |
"%<targetsync%> modifier"); |
| 27204 |
tree t = build_tree_list (target ? boolean_true_node |
| 27205 |
: boolean_false_node, |
| 27206 |
targetsync ? boolean_true_node |
| 27207 |
: boolean_false_node); |
| 27208 |
t = build1_loc (loc, NOP_EXPR, void_type_node, t); |
| 27209 |
t = build_tree_list (t, prefer_type_tree); |
| 27210 |
if (append_args_tree) |
| 27211 |
{ |
| 27212 |
TREE_CHAIN (append_args_last) = t; |
| 27213 |
append_args_last = t; |
| 27214 |
} |
| 27215 |
else |
| 27216 |
append_args_tree = append_args_last = t; |
| 27217 |
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 27218 |
break; |
| 27219 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<)%> or %<,%>")) |
| 27220 |
goto fail; |
| 27221 |
} |
| 27222 |
while (true); |
| 27223 |
} |
| 27224 |
|
| 27225 |
parens.require_close (parser); |
| 27226 |
} while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)); |
| 27227 |
c_parser_skip_to_pragma_eol (parser); |
| 27228 |
|
| 27229 |
if ((ctx != error_mark_node && variant != error_mark_node) |
| 27230 |
&& !omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT, |
| 27231 |
OMP_TRAIT_CONSTRUCT_SIMD)) |
| 27232 |
{ |
| 27233 |
bool fail = false; |
| 27234 |
if (append_args_tree) |
| 27235 |
{ |
| 27236 |
int nappend_args = 0; |
| 27237 |
int nbase_args = 0; |
| 27238 |
for (tree t = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); |
| 27239 |
t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t)) |
| 27240 |
nbase_args++; |
| 27241 |
for (tree t = append_args_tree; t; t = TREE_CHAIN (t)) |
| 27242 |
nappend_args++; |
| 27243 |
|
| 27244 |
/* Store as purpose = arg number after which to append |
| 27245 |
and value = list of interop items. */ |
| 27246 |
append_args_tree = build_tree_list (build_int_cst (integer_type_node, |
| 27247 |
nbase_args), |
| 27248 |
append_args_tree); |
| 27249 |
tree args, arg; |
| 27250 |
args = arg = TYPE_ARG_TYPES (TREE_TYPE (variant)); |
| 27251 |
for (int j = 0; j < nbase_args && arg; j++, arg = TREE_CHAIN (arg)) |
| 27252 |
args = arg; |
| 27253 |
for (int i = 0; i < nappend_args && arg; i++) |
| 27254 |
arg = TREE_CHAIN (arg); |
| 27255 |
tree saved_args; |
| 27256 |
if (nbase_args && args) |
| 27257 |
{ |
| 27258 |
saved_args = TREE_CHAIN (args); |
| 27259 |
TREE_CHAIN (args) = arg; |
| 27260 |
} |
| 27261 |
else |
| 27262 |
{ |
| 27263 |
saved_args = args; |
| 27264 |
TYPE_ARG_TYPES (TREE_TYPE (variant)) = arg; |
| 27265 |
TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1; |
| 27266 |
} |
| 27267 |
if (!comptypes (TREE_TYPE (fndecl), TREE_TYPE (variant))) |
| 27268 |
fail = true; |
| 27269 |
if (nbase_args && args) |
| 27270 |
TREE_CHAIN (args) = saved_args; |
| 27271 |
else |
| 27272 |
{ |
| 27273 |
TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_args; |
| 27274 |
TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 0; |
| 27275 |
} |
| 27276 |
arg = saved_args; |
| 27277 |
if (!fail) |
| 27278 |
for (int i = 0; i < nappend_args; i++, arg = TREE_CHAIN (arg)) |
| 27279 |
if (!arg || !c_omp_interop_t_p (TREE_VALUE (arg))) |
| 27280 |
{ |
| 27281 |
error_at (DECL_SOURCE_LOCATION (variant), |
| 27282 |
"argument %d of %qD must be of %<omp_interop_t%>", |
| 27283 |
nbase_args + i + 1, variant); |
| 27284 |
inform (append_args_loc, "%<append_args%> specified here"); |
| 27285 |
break; |
| 27286 |
} |
| 27287 |
} |
| 27288 |
else |
| 27289 |
{ |
| 27290 |
if (comptypes (TREE_TYPE (fndecl), TREE_TYPE (variant))) |
| 27291 |
{ |
| 27292 |
if (TYPE_ARG_TYPES (TREE_TYPE (variant)) == NULL_TREE |
| 27293 |
&& TYPE_ARG_TYPES (TREE_TYPE (fndecl)) != NULL_TREE) |
| 27294 |
{ |
| 27295 |
if (!append_args_tree) |
| 27296 |
TYPE_ARG_TYPES (TREE_TYPE (variant)) |
| 27297 |
= TYPE_ARG_TYPES (TREE_TYPE (fndecl)); |
| 27298 |
else |
| 27299 |
{ |
| 27300 |
tree new_args = NULL_TREE; |
| 27301 |
tree arg, last_arg = NULL_TREE; |
| 27302 |
for (arg = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); |
| 27303 |
arg && arg != void_type_node; arg = TREE_CHAIN (arg)) |
| 27304 |
{ |
| 27305 |
if (new_args == NULL_TREE) |
| 27306 |
new_args = last_arg = copy_node (arg); |
| 27307 |
else |
| 27308 |
{ |
| 27309 |
TREE_CHAIN (last_arg) = copy_node (arg); |
| 27310 |
last_arg = TREE_CHAIN (last_arg); |
| 27311 |
} |
| 27312 |
} |
| 27313 |
for (tree t3 = append_args_tree; t3; t3 = TREE_CHAIN (t3)) |
| 27314 |
{ |
| 27315 |
tree type = lookup_name (get_identifier ("omp_interop_t")); |
| 27316 |
type = type ? TREE_TYPE (type) : ptr_type_node; |
| 27317 |
last_arg = tree_cons (NULL_TREE, type, last_arg); |
| 27318 |
} |
| 27319 |
TREE_CHAIN (last_arg) = arg; |
| 27320 |
TYPE_ARG_TYPES (TREE_TYPE (variant)) = new_args; |
| 27321 |
} |
| 27322 |
} |
| 27323 |
} |
| 27324 |
else |
| 27325 |
fail = true; |
| 27326 |
} |
| 27327 |
if (fail) |
| 27328 |
{ |
| 27329 |
error_at (token->location, |
| 27330 |
"variant %qD and base %qD have incompatible types", |
| 27331 |
variant, fndecl); |
| 27332 |
variant = error_mark_node; |
| 27333 |
} |
| 27334 |
} |
| 27335 |
if (ctx != error_mark_node && variant != error_mark_node) |
| 27336 |
{ |
| 27337 |
C_DECL_USED (variant) = 1; |
| 27338 |
tree construct = omp_get_context_selector_list (ctx, |
| 27339 |
OMP_TRAIT_SET_CONSTRUCT); |
| 27340 |
omp_mark_declare_variant (match_loc, variant, construct); |
| 27341 |
if (omp_context_selector_matches (ctx, NULL_TREE, false)) |
| 27342 |
{ |
| 27343 |
tree attr = tree_cons (get_identifier ("omp declare variant base"), |
| 27344 |
build_tree_list (variant, ctx), |
| 27345 |
DECL_ATTRIBUTES (fndecl)); |
| 27346 |
DECL_ATTRIBUTES (fndecl) = attr; |
| 27347 |
} |
| 27348 |
} |
| 27349 |
|
| 27350 |
if (has_adjust_args || append_args_tree) |
| 27351 |
{ |
| 27352 |
if (!has_match) |
| 27353 |
{ |
| 27354 |
error_at (has_adjust_args ? adjust_args_loc : append_args_loc, |
| 27355 |
"an %qs clause requires a %<match%> clause", |
| 27356 |
has_adjust_args ? "adjust_args" : "append_args"); |
| 27357 |
} |
| 27358 |
else if (ctx != error_mark_node && variant != error_mark_node) |
| 27359 |
{ |
| 27360 |
tree attr = lookup_attribute ("omp declare variant base", |
| 27361 |
DECL_ATTRIBUTES (fndecl)); |
| 27362 |
if (attr != NULL_TREE) |
| 27363 |
{ |
| 27364 |
tree ctx = TREE_VALUE (TREE_VALUE (attr)); |
| 27365 |
if (!omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT, |
| 27366 |
OMP_TRAIT_CONSTRUCT_DISPATCH)) |
| 27367 |
error_at (has_adjust_args ? adjust_args_loc : append_args_loc, |
| 27368 |
"an %qs clause can only be specified if the " |
| 27369 |
"%<dispatch%> selector of the %<construct%> selector " |
| 27370 |
"set appears in the %<match%> clause", |
| 27371 |
has_adjust_args ? "adjust_args" : "append_args"); |
| 27372 |
} |
| 27373 |
} |
| 27374 |
} |
| 27375 |
|
| 27376 |
if ((ctx != error_mark_node && variant != error_mark_node) |
| 27377 |
&& (need_device_ptr_list || append_args_tree)) |
| 27378 |
{ |
| 27379 |
tree variant_decl = tree_strip_nop_conversions (variant); |
| 27380 |
tree t = build_tree_list (need_device_ptr_list, |
| 27381 |
NULL_TREE /* need_device_addr */); |
| 27382 |
TREE_CHAIN (t) = append_args_tree; |
| 27383 |
DECL_ATTRIBUTES (variant_decl) |
| 27384 |
= tree_cons (get_identifier ("omp declare variant variant args"), t, |
| 27385 |
DECL_ATTRIBUTES (variant_decl)); |
| 27386 |
} |
| 27387 |
} |
| 27388 |
|
| 27389 |
/* Finalize #pragma omp declare simd or #pragma omp declare variant |
| 27390 |
clauses after FNDECL has been parsed, and put that into "omp declare simd" |
| 27391 |
or "omp declare variant base" attribute. */ |
| 27392 |
|
| 27393 |
static void |
| 27394 |
c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, |
| 27395 |
vec<c_token> *pclauses) |
| 27396 |
{ |
| 27397 |
vec<c_token> &clauses = *pclauses; |
| 27398 |
|
| 27399 |
/* Normally first token is CPP_NAME "simd" or "variant". CPP_EOF there |
| 27400 |
indicates error has been reported and CPP_PRAGMA that |
| 27401 |
c_finish_omp_declare_simd has already processed the tokens. */ |
| 27402 |
if (clauses.exists () && clauses[0].type == CPP_EOF) |
| 27403 |
return; |
| 27404 |
const char *kind = "simd"; |
| 27405 |
if (clauses.exists () |
| 27406 |
&& (clauses[0].type == CPP_NAME || clauses[0].type == CPP_PRAGMA)) |
| 27407 |
kind = IDENTIFIER_POINTER (clauses[0].value); |
| 27408 |
gcc_assert (strcmp (kind, "simd") == 0 || strcmp (kind, "variant") == 0); |
| 27409 |
if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) |
| 27410 |
{ |
| 27411 |
error ("%<#pragma omp declare %s%> not immediately followed by " |
| 27412 |
"a function declaration or definition", kind); |
| 27413 |
clauses[0].type = CPP_EOF; |
| 27414 |
return; |
| 27415 |
} |
| 27416 |
if (clauses.exists () && clauses[0].type != CPP_NAME) |
| 27417 |
{ |
| 27418 |
error_at (DECL_SOURCE_LOCATION (fndecl), |
| 27419 |
"%<#pragma omp declare %s%> not immediately followed by " |
| 27420 |
"a single function declaration or definition", kind); |
| 27421 |
clauses[0].type = CPP_EOF; |
| 27422 |
return; |
| 27423 |
} |
| 27424 |
|
| 27425 |
if (parms == NULL_TREE) |
| 27426 |
parms = DECL_ARGUMENTS (fndecl); |
| 27427 |
|
| 27428 |
unsigned int tokens_avail = parser->tokens_avail; |
| 27429 |
gcc_assert (parser->tokens == &parser->tokens_buf[0]); |
| 27430 |
|
| 27431 |
parser->tokens = clauses.address (); |
| 27432 |
parser->tokens_avail = clauses.length (); |
| 27433 |
|
| 27434 |
/* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */ |
| 27435 |
while (parser->tokens_avail > 3) |
| 27436 |
{ |
| 27437 |
c_token *token = c_parser_peek_token (parser); |
| 27438 |
gcc_assert (token->type == CPP_NAME); |
| 27439 |
kind = IDENTIFIER_POINTER (token->value); |
| 27440 |
c_parser_consume_token (parser); |
| 27441 |
parser->in_pragma = true; |
| 27442 |
|
| 27443 |
if (strcmp (kind, "simd") == 0) |
| 27444 |
{ |
| 27445 |
tree c; |
| 27446 |
c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, |
| 27447 |
"#pragma omp declare simd"); |
| 27448 |
c = c_omp_declare_simd_clauses_to_numbers (parms, c); |
| 27449 |
if (c != NULL_TREE) |
| 27450 |
c = tree_cons (NULL_TREE, c, NULL_TREE); |
| 27451 |
c = build_tree_list (get_identifier ("omp declare simd"), c); |
| 27452 |
TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl); |
| 27453 |
DECL_ATTRIBUTES (fndecl) = c; |
| 27454 |
} |
| 27455 |
else |
| 27456 |
{ |
| 27457 |
gcc_assert (strcmp (kind, "variant") == 0); |
| 27458 |
c_finish_omp_declare_variant (parser, fndecl, parms); |
| 27459 |
} |
| 27460 |
} |
| 27461 |
|
| 27462 |
parser->tokens = &parser->tokens_buf[0]; |
| 27463 |
parser->tokens_avail = tokens_avail; |
| 27464 |
if (clauses.exists ()) |
| 27465 |
clauses[0].type = CPP_PRAGMA; |
| 27466 |
} |
| 27467 |
|
| 27468 |
/* D should be C_TOKEN_VEC from omp::decl attribute. If it contains |
| 27469 |
a threadprivate, groupprivate, allocate or declare target directive, |
| 27470 |
return true and parse it for DECL. */ |
| 27471 |
|
| 27472 |
bool |
| 27473 |
c_maybe_parse_omp_decl (tree decl, tree d) |
| 27474 |
{ |
| 27475 |
gcc_assert (TREE_CODE (d) == C_TOKEN_VEC); |
| 27476 |
vec<c_token, va_gc> *toks = C_TOKEN_VEC_TOKENS (d); |
| 27477 |
c_token *first = toks->address (); |
| 27478 |
c_token *last = first + toks->length (); |
| 27479 |
const char *directive[3] = {}; |
| 27480 |
for (int j = 0; j < 3; j++) |
| 27481 |
{ |
| 27482 |
tree id = NULL_TREE; |
| 27483 |
if (first + j == last) |
| 27484 |
break; |
| 27485 |
if (first[j].type == CPP_NAME) |
| 27486 |
id = first[j].value; |
| 27487 |
else if (first[j].type == CPP_KEYWORD) |
| 27488 |
id = ridpointers[(int) first[j].keyword]; |
| 27489 |
else |
| 27490 |
break; |
| 27491 |
directive[j] = IDENTIFIER_POINTER (id); |
| 27492 |
} |
| 27493 |
const c_omp_directive *dir = NULL; |
| 27494 |
if (directive[0]) |
| 27495 |
dir = c_omp_categorize_directive (directive[0], directive[1], |
| 27496 |
directive[2]); |
| 27497 |
if (dir == NULL) |
| 27498 |
{ |
| 27499 |
error_at (first->location, |
| 27500 |
"unknown OpenMP directive name in " |
| 27501 |
"%qs attribute argument", "omp::decl"); |
| 27502 |
return false; |
| 27503 |
} |
| 27504 |
if (dir->id != PRAGMA_OMP_THREADPRIVATE |
| 27505 |
/* && dir->id != PRAGMA_OMP_GROUPPRIVATE */ |
| 27506 |
&& dir->id != PRAGMA_OMP_ALLOCATE |
| 27507 |
&& (dir->id != PRAGMA_OMP_DECLARE |
| 27508 |
|| strcmp (directive[1], "target") != 0)) |
| 27509 |
return false; |
| 27510 |
|
| 27511 |
if (!flag_openmp && !dir->simd) |
| 27512 |
return true; |
| 27513 |
|
| 27514 |
c_parser *parser = the_parser; |
| 27515 |
unsigned int tokens_avail = parser->tokens_avail; |
| 27516 |
gcc_assert (parser->tokens == &parser->tokens_buf[0]); |
| 27517 |
toks = NULL; |
| 27518 |
vec_safe_reserve (toks, last - first + 2, true); |
| 27519 |
c_token tok = {}; |
| 27520 |
tok.type = CPP_PRAGMA; |
| 27521 |
tok.keyword = RID_MAX; |
| 27522 |
tok.pragma_kind = pragma_kind (dir->id); |
| 27523 |
tok.location = first->location; |
| 27524 |
toks->quick_push (tok); |
| 27525 |
while (++first < last) |
| 27526 |
toks->quick_push (*first); |
| 27527 |
tok = {}; |
| 27528 |
tok.type = CPP_PRAGMA_EOL; |
| 27529 |
tok.keyword = RID_MAX; |
| 27530 |
tok.location = last[-1].location; |
| 27531 |
toks->quick_push (tok); |
| 27532 |
tok = {}; |
| 27533 |
tok.type = CPP_EOF; |
| 27534 |
tok.keyword = RID_MAX; |
| 27535 |
tok.location = last[-1].location; |
| 27536 |
toks->quick_push (tok); |
| 27537 |
parser->in_omp_decl_attribute = decl; |
| 27538 |
gcc_assert (!parser->in_omp_attribute_pragma); |
| 27539 |
parser->in_omp_attribute_pragma = ggc_alloc<omp_attribute_pragma_state> (); |
| 27540 |
parser->in_omp_attribute_pragma->token_vec = toks; |
| 27541 |
parser->in_omp_attribute_pragma->save_tokens = parser->tokens; |
| 27542 |
parser->in_omp_attribute_pragma->save_tokens_avail = tokens_avail; |
| 27543 |
parser->tokens = toks->address (); |
| 27544 |
parser->tokens_avail = toks->length (); |
| 27545 |
c_parser_pragma (parser, pragma_external, NULL, NULL_TREE); |
| 27546 |
parser->in_omp_decl_attribute = NULL_TREE; |
| 27547 |
return true; |
| 27548 |
} |
| 27549 |
|
| 27550 |
/* OpenMP 4.0: |
| 27551 |
# pragma omp declare target new-line |
| 27552 |
declarations and definitions |
| 27553 |
# pragma omp end declare target new-line |
| 27554 |
|
| 27555 |
OpenMP 4.5: |
| 27556 |
# pragma omp declare target ( extended-list ) new-line |
| 27557 |
|
| 27558 |
# pragma omp declare target declare-target-clauses[seq] new-line */ |
| 27559 |
|
| 27560 |
#define OMP_DECLARE_TARGET_CLAUSE_MASK \ |
| 27561 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ |
| 27562 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ENTER) \ |
| 27563 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK) \ |
| 27564 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE) \ |
| 27565 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INDIRECT)) |
| 27566 |
|
| 27567 |
static void |
| 27568 |
c_parser_omp_declare_target (c_parser *parser) |
| 27569 |
{ |
| 27570 |
tree clauses = NULL_TREE; |
| 27571 |
int device_type = 0; |
| 27572 |
bool indirect = false; |
| 27573 |
bool only_device_type_or_indirect = true; |
| 27574 |
if (flag_openmp) |
| 27575 |
omp_requires_mask |
| 27576 |
= (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); |
| 27577 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 27578 |
|| (c_parser_next_token_is (parser, CPP_COMMA) |
| 27579 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME)) |
| 27580 |
clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK, |
| 27581 |
"#pragma omp declare target"); |
| 27582 |
else if (parser->in_omp_decl_attribute |
| 27583 |
|| c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 27584 |
{ |
| 27585 |
clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER, |
| 27586 |
clauses); |
| 27587 |
clauses = c_finish_omp_clauses (clauses, C_ORT_OMP); |
| 27588 |
c_parser_skip_to_pragma_eol (parser); |
| 27589 |
} |
| 27590 |
else |
| 27591 |
{ |
| 27592 |
bool attr_syntax = parser->in_omp_attribute_pragma != NULL; |
| 27593 |
c_parser_skip_to_pragma_eol (parser); |
| 27594 |
c_omp_declare_target_attr attr = { attr_syntax, -1, 0 }; |
| 27595 |
vec_safe_push (current_omp_declare_target_attribute, attr); |
| 27596 |
return; |
| 27597 |
} |
| 27598 |
for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) |
| 27599 |
{ |
| 27600 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE) |
| 27601 |
device_type |= OMP_CLAUSE_DEVICE_TYPE_KIND (c); |
| 27602 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INDIRECT) |
| 27603 |
indirect |= !integer_zerop (OMP_CLAUSE_INDIRECT_EXPR (c)); |
| 27604 |
} |
| 27605 |
for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) |
| 27606 |
{ |
| 27607 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE |
| 27608 |
|| OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INDIRECT) |
| 27609 |
continue; |
| 27610 |
tree t = OMP_CLAUSE_DECL (c), id; |
| 27611 |
tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t)); |
| 27612 |
tree at2 = lookup_attribute ("omp declare target link", |
| 27613 |
DECL_ATTRIBUTES (t)); |
| 27614 |
only_device_type_or_indirect = false; |
| 27615 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK) |
| 27616 |
{ |
| 27617 |
id = get_identifier ("omp declare target link"); |
| 27618 |
std::swap (at1, at2); |
| 27619 |
} |
| 27620 |
else |
| 27621 |
id = get_identifier ("omp declare target"); |
| 27622 |
if (at2) |
| 27623 |
{ |
| 27624 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER) |
| 27625 |
error_at (OMP_CLAUSE_LOCATION (c), |
| 27626 |
"%qD specified both in declare target %<link%> and %qs" |
| 27627 |
" clauses", t, OMP_CLAUSE_ENTER_TO (c) ? "to" : "enter"); |
| 27628 |
else |
| 27629 |
error_at (OMP_CLAUSE_LOCATION (c), |
| 27630 |
"%qD specified both in declare target %<link%> and " |
| 27631 |
"%<to%> or %<enter%> clauses", t); |
| 27632 |
continue; |
| 27633 |
} |
| 27634 |
if (!at1) |
| 27635 |
{ |
| 27636 |
DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); |
| 27637 |
if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t)) |
| 27638 |
continue; |
| 27639 |
|
| 27640 |
symtab_node *node = symtab_node::get (t); |
| 27641 |
if (node != NULL) |
| 27642 |
{ |
| 27643 |
node->offloadable = 1; |
| 27644 |
if (ENABLE_OFFLOADING) |
| 27645 |
{ |
| 27646 |
g->have_offload = true; |
| 27647 |
if (is_a <varpool_node *> (node)) |
| 27648 |
vec_safe_push (offload_vars, t); |
| 27649 |
} |
| 27650 |
} |
| 27651 |
} |
| 27652 |
if (TREE_CODE (t) != FUNCTION_DECL) |
| 27653 |
continue; |
| 27654 |
if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0) |
| 27655 |
{ |
| 27656 |
tree at3 = lookup_attribute ("omp declare target host", |
| 27657 |
DECL_ATTRIBUTES (t)); |
| 27658 |
if (at3 == NULL_TREE) |
| 27659 |
{ |
| 27660 |
id = get_identifier ("omp declare target host"); |
| 27661 |
DECL_ATTRIBUTES (t) |
| 27662 |
= tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); |
| 27663 |
} |
| 27664 |
} |
| 27665 |
if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0) |
| 27666 |
{ |
| 27667 |
tree at3 = lookup_attribute ("omp declare target nohost", |
| 27668 |
DECL_ATTRIBUTES (t)); |
| 27669 |
if (at3 == NULL_TREE) |
| 27670 |
{ |
| 27671 |
id = get_identifier ("omp declare target nohost"); |
| 27672 |
DECL_ATTRIBUTES (t) |
| 27673 |
= tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); |
| 27674 |
} |
| 27675 |
} |
| 27676 |
if (indirect) |
| 27677 |
{ |
| 27678 |
tree at4 = lookup_attribute ("omp declare target indirect", |
| 27679 |
DECL_ATTRIBUTES (t)); |
| 27680 |
if (at4 == NULL_TREE) |
| 27681 |
{ |
| 27682 |
id = get_identifier ("omp declare target indirect"); |
| 27683 |
DECL_ATTRIBUTES (t) |
| 27684 |
= tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); |
| 27685 |
} |
| 27686 |
} |
| 27687 |
} |
| 27688 |
if ((device_type || indirect) && only_device_type_or_indirect) |
| 27689 |
error_at (OMP_CLAUSE_LOCATION (clauses), |
| 27690 |
"directive with only %<device_type%> or %<indirect%> clauses"); |
| 27691 |
if (indirect && device_type && device_type != OMP_CLAUSE_DEVICE_TYPE_ANY) |
| 27692 |
error_at (OMP_CLAUSE_LOCATION (clauses), |
| 27693 |
"%<device_type%> clause must specify 'any' when used with " |
| 27694 |
"an %<indirect%> clause"); |
| 27695 |
} |
| 27696 |
|
| 27697 |
/* OpenMP 5.1 |
| 27698 |
#pragma omp begin assumes clauses[optseq] new-line |
| 27699 |
|
| 27700 |
#pragma omp begin declare target clauses[optseq] new-line */ |
| 27701 |
|
| 27702 |
#define OMP_BEGIN_DECLARE_TARGET_CLAUSE_MASK \ |
| 27703 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE) \ |
| 27704 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INDIRECT)) |
| 27705 |
|
| 27706 |
static void |
| 27707 |
c_parser_omp_begin (c_parser *parser) |
| 27708 |
{ |
| 27709 |
const char *p = ""; |
| 27710 |
c_parser_consume_pragma (parser); |
| 27711 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 27712 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 27713 |
if (strcmp (p, "declare") == 0) |
| 27714 |
{ |
| 27715 |
c_parser_consume_token (parser); |
| 27716 |
p = ""; |
| 27717 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 27718 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 27719 |
if (strcmp (p, "target") == 0) |
| 27720 |
{ |
| 27721 |
c_parser_consume_token (parser); |
| 27722 |
bool attr_syntax = parser->in_omp_attribute_pragma != NULL; |
| 27723 |
tree clauses |
| 27724 |
= c_parser_omp_all_clauses (parser, |
| 27725 |
OMP_BEGIN_DECLARE_TARGET_CLAUSE_MASK, |
| 27726 |
"#pragma omp begin declare target"); |
| 27727 |
int device_type = 0; |
| 27728 |
int indirect = 0; |
| 27729 |
for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) |
| 27730 |
{ |
| 27731 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE) |
| 27732 |
device_type |= OMP_CLAUSE_DEVICE_TYPE_KIND (c); |
| 27733 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INDIRECT) |
| 27734 |
indirect |= !integer_zerop (OMP_CLAUSE_INDIRECT_EXPR (c)); |
| 27735 |
} |
| 27736 |
c_omp_declare_target_attr attr = { attr_syntax, device_type, |
| 27737 |
indirect }; |
| 27738 |
vec_safe_push (current_omp_declare_target_attribute, attr); |
| 27739 |
} |
| 27740 |
else |
| 27741 |
{ |
| 27742 |
c_parser_error (parser, "expected %<target%>"); |
| 27743 |
c_parser_skip_to_pragma_eol (parser); |
| 27744 |
} |
| 27745 |
} |
| 27746 |
else if (strcmp (p, "assumes") == 0) |
| 27747 |
{ |
| 27748 |
c_parser_consume_token (parser); |
| 27749 |
bool attr_syntax = parser->in_omp_attribute_pragma != NULL; |
| 27750 |
c_parser_omp_assumption_clauses (parser, false); |
| 27751 |
struct c_omp_begin_assumes_data a = { attr_syntax }; |
| 27752 |
vec_safe_push (current_omp_begin_assumes, a); |
| 27753 |
} |
| 27754 |
else |
| 27755 |
{ |
| 27756 |
c_parser_error (parser, "expected %<declare target%> or %<assumes%>"); |
| 27757 |
c_parser_skip_to_pragma_eol (parser); |
| 27758 |
} |
| 27759 |
} |
| 27760 |
|
| 27761 |
/* OpenMP 4.0 |
| 27762 |
#pragma omp end declare target |
| 27763 |
|
| 27764 |
OpenMP 5.1 |
| 27765 |
#pragma omp end assumes */ |
| 27766 |
|
| 27767 |
static void |
| 27768 |
c_parser_omp_end (c_parser *parser) |
| 27769 |
{ |
| 27770 |
location_t loc = c_parser_peek_token (parser)->location; |
| 27771 |
const char *p = ""; |
| 27772 |
c_parser_consume_pragma (parser); |
| 27773 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 27774 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 27775 |
if (strcmp (p, "declare") == 0) |
| 27776 |
{ |
| 27777 |
c_parser_consume_token (parser); |
| 27778 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 27779 |
&& strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 27780 |
"target") == 0) |
| 27781 |
c_parser_consume_token (parser); |
| 27782 |
else |
| 27783 |
{ |
| 27784 |
c_parser_error (parser, "expected %<target%>"); |
| 27785 |
c_parser_skip_to_pragma_eol (parser); |
| 27786 |
return; |
| 27787 |
} |
| 27788 |
bool attr_syntax = parser->in_omp_attribute_pragma != NULL; |
| 27789 |
c_parser_skip_to_pragma_eol (parser); |
| 27790 |
if (!vec_safe_length (current_omp_declare_target_attribute)) |
| 27791 |
error_at (loc, "%<#pragma omp end declare target%> without " |
| 27792 |
"corresponding %<#pragma omp declare target%> or " |
| 27793 |
"%<#pragma omp begin declare target%>"); |
| 27794 |
else |
| 27795 |
{ |
| 27796 |
c_omp_declare_target_attr |
| 27797 |
a = current_omp_declare_target_attribute->pop (); |
| 27798 |
if (a.attr_syntax != attr_syntax) |
| 27799 |
{ |
| 27800 |
if (a.attr_syntax) |
| 27801 |
error_at (loc, |
| 27802 |
"%qs in attribute syntax terminated " |
| 27803 |
"with %qs in pragma syntax", |
| 27804 |
a.device_type >= 0 ? "begin declare target" |
| 27805 |
: "declare target", |
| 27806 |
"end declare target"); |
| 27807 |
else |
| 27808 |
error_at (loc, |
| 27809 |
"%qs in pragma syntax terminated " |
| 27810 |
"with %qs in attribute syntax", |
| 27811 |
a.device_type >= 0 ? "begin declare target" |
| 27812 |
: "declare target", |
| 27813 |
"end declare target"); |
| 27814 |
} |
| 27815 |
} |
| 27816 |
} |
| 27817 |
else if (strcmp (p, "assumes") == 0) |
| 27818 |
{ |
| 27819 |
c_parser_consume_token (parser); |
| 27820 |
bool attr_syntax = parser->in_omp_attribute_pragma != NULL; |
| 27821 |
c_parser_skip_to_pragma_eol (parser); |
| 27822 |
if (!vec_safe_length (current_omp_begin_assumes)) |
| 27823 |
error_at (loc, "%qs without corresponding %qs", |
| 27824 |
"#pragma omp end assumes", "#pragma omp begin assumes"); |
| 27825 |
else |
| 27826 |
{ |
| 27827 |
c_omp_begin_assumes_data |
| 27828 |
a = current_omp_begin_assumes->pop (); |
| 27829 |
if (a.attr_syntax != attr_syntax) |
| 27830 |
{ |
| 27831 |
if (a.attr_syntax) |
| 27832 |
error_at (loc, |
| 27833 |
"%qs in attribute syntax terminated " |
| 27834 |
"with %qs in pragma syntax", |
| 27835 |
"begin assumes", "end assumes"); |
| 27836 |
else |
| 27837 |
error_at (loc, |
| 27838 |
"%qs in pragma syntax terminated " |
| 27839 |
"with %qs in attribute syntax", |
| 27840 |
"begin assumes", "end assumes"); |
| 27841 |
} |
| 27842 |
} |
| 27843 |
} |
| 27844 |
else |
| 27845 |
{ |
| 27846 |
c_parser_error (parser, "expected %<declare%> or %<assumes%>"); |
| 27847 |
c_parser_skip_to_pragma_eol (parser); |
| 27848 |
} |
| 27849 |
} |
| 27850 |
|
| 27851 |
/* OpenMP 4.0 |
| 27852 |
#pragma omp declare reduction (reduction-id : typename-list : expression) \ |
| 27853 |
initializer-clause[opt] new-line |
| 27854 |
|
| 27855 |
initializer-clause: |
| 27856 |
initializer (omp_priv = initializer) |
| 27857 |
initializer (function-name (argument-list)) */ |
| 27858 |
|
| 27859 |
static void |
| 27860 |
c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context) |
| 27861 |
{ |
| 27862 |
unsigned int tokens_avail = 0, i; |
| 27863 |
c_token *saved_tokens = NULL; |
| 27864 |
vec<tree> types = vNULL; |
| 27865 |
vec<c_token> clauses = vNULL; |
| 27866 |
enum tree_code reduc_code = ERROR_MARK; |
| 27867 |
tree reduc_id = NULL_TREE; |
| 27868 |
tree type; |
| 27869 |
location_t rloc = c_parser_peek_token (parser)->location; |
| 27870 |
|
| 27871 |
if (context == pragma_struct || context == pragma_param) |
| 27872 |
{ |
| 27873 |
error ("%<#pragma omp declare reduction%> not at file or block scope"); |
| 27874 |
goto fail; |
| 27875 |
} |
| 27876 |
|
| 27877 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 27878 |
goto fail; |
| 27879 |
|
| 27880 |
switch (c_parser_peek_token (parser)->type) |
| 27881 |
{ |
| 27882 |
case CPP_PLUS: |
| 27883 |
reduc_code = PLUS_EXPR; |
| 27884 |
break; |
| 27885 |
case CPP_MULT: |
| 27886 |
reduc_code = MULT_EXPR; |
| 27887 |
break; |
| 27888 |
case CPP_MINUS: |
| 27889 |
reduc_code = MINUS_EXPR; |
| 27890 |
break; |
| 27891 |
case CPP_AND: |
| 27892 |
reduc_code = BIT_AND_EXPR; |
| 27893 |
break; |
| 27894 |
case CPP_XOR: |
| 27895 |
reduc_code = BIT_XOR_EXPR; |
| 27896 |
break; |
| 27897 |
case CPP_OR: |
| 27898 |
reduc_code = BIT_IOR_EXPR; |
| 27899 |
break; |
| 27900 |
case CPP_AND_AND: |
| 27901 |
reduc_code = TRUTH_ANDIF_EXPR; |
| 27902 |
break; |
| 27903 |
case CPP_OR_OR: |
| 27904 |
reduc_code = TRUTH_ORIF_EXPR; |
| 27905 |
break; |
| 27906 |
case CPP_NAME: |
| 27907 |
const char *p; |
| 27908 |
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 27909 |
if (strcmp (p, "min") == 0) |
| 27910 |
{ |
| 27911 |
reduc_code = MIN_EXPR; |
| 27912 |
break; |
| 27913 |
} |
| 27914 |
if (strcmp (p, "max") == 0) |
| 27915 |
{ |
| 27916 |
reduc_code = MAX_EXPR; |
| 27917 |
break; |
| 27918 |
} |
| 27919 |
reduc_id = c_parser_peek_token (parser)->value; |
| 27920 |
break; |
| 27921 |
default: |
| 27922 |
c_parser_error (parser, |
| 27923 |
"expected %<+%>, %<*%>, %<-%>, %<&%>, " |
| 27924 |
"%<^%>, %<|%>, %<&&%>, %<||%> or identifier"); |
| 27925 |
goto fail; |
| 27926 |
} |
| 27927 |
|
| 27928 |
tree orig_reduc_id, reduc_decl; |
| 27929 |
orig_reduc_id = reduc_id; |
| 27930 |
reduc_id = c_omp_reduction_id (reduc_code, reduc_id); |
| 27931 |
reduc_decl = c_omp_reduction_decl (reduc_id); |
| 27932 |
c_parser_consume_token (parser); |
| 27933 |
|
| 27934 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 27935 |
goto fail; |
| 27936 |
|
| 27937 |
while (true) |
| 27938 |
{ |
| 27939 |
location_t loc = c_parser_peek_token (parser)->location; |
| 27940 |
struct c_type_name *ctype = c_parser_type_name (parser); |
| 27941 |
if (ctype != NULL) |
| 27942 |
{ |
| 27943 |
type = groktypename (ctype, NULL, NULL); |
| 27944 |
if (type == error_mark_node) |
| 27945 |
; |
| 27946 |
else if ((INTEGRAL_TYPE_P (type) |
| 27947 |
|| SCALAR_FLOAT_TYPE_P (type) |
| 27948 |
|| TREE_CODE (type) == COMPLEX_TYPE) |
| 27949 |
&& orig_reduc_id == NULL_TREE) |
| 27950 |
error_at (loc, "predeclared arithmetic type in " |
| 27951 |
"%<#pragma omp declare reduction%>"); |
| 27952 |
else if (TREE_CODE (type) == FUNCTION_TYPE |
| 27953 |
|| TREE_CODE (type) == ARRAY_TYPE) |
| 27954 |
error_at (loc, "function or array type in " |
| 27955 |
"%<#pragma omp declare reduction%>"); |
| 27956 |
else if (TYPE_ATOMIC (type)) |
| 27957 |
error_at (loc, "%<_Atomic%> qualified type in " |
| 27958 |
"%<#pragma omp declare reduction%>"); |
| 27959 |
else if (TYPE_QUALS_NO_ADDR_SPACE (type)) |
| 27960 |
error_at (loc, "const, volatile or restrict qualified type in " |
| 27961 |
"%<#pragma omp declare reduction%>"); |
| 27962 |
else |
| 27963 |
{ |
| 27964 |
tree t; |
| 27965 |
for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t)) |
| 27966 |
if (comptypes (TREE_PURPOSE (t), type)) |
| 27967 |
{ |
| 27968 |
error_at (loc, "redeclaration of %qs " |
| 27969 |
"%<#pragma omp declare reduction%> for " |
| 27970 |
"type %qT", |
| 27971 |
IDENTIFIER_POINTER (reduc_id) |
| 27972 |
+ sizeof ("omp declare reduction ") - 1, |
| 27973 |
type); |
| 27974 |
location_t ploc |
| 27975 |
= DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t), |
| 27976 |
0)); |
| 27977 |
error_at (ploc, "previous %<#pragma omp declare " |
| 27978 |
"reduction%>"); |
| 27979 |
break; |
| 27980 |
} |
| 27981 |
if (t == NULL_TREE) |
| 27982 |
types.safe_push (type); |
| 27983 |
} |
| 27984 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 27985 |
c_parser_consume_token (parser); |
| 27986 |
else |
| 27987 |
break; |
| 27988 |
} |
| 27989 |
else |
| 27990 |
break; |
| 27991 |
} |
| 27992 |
|
| 27993 |
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>") |
| 27994 |
|| types.is_empty ()) |
| 27995 |
{ |
| 27996 |
fail: |
| 27997 |
clauses.release (); |
| 27998 |
types.release (); |
| 27999 |
while (true) |
| 28000 |
{ |
| 28001 |
c_token *token = c_parser_peek_token (parser); |
| 28002 |
if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL) |
| 28003 |
break; |
| 28004 |
c_parser_consume_token (parser); |
| 28005 |
} |
| 28006 |
c_parser_skip_to_pragma_eol (parser); |
| 28007 |
return; |
| 28008 |
} |
| 28009 |
|
| 28010 |
if (types.length () > 1) |
| 28011 |
{ |
| 28012 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 28013 |
{ |
| 28014 |
c_token *token = c_parser_peek_token (parser); |
| 28015 |
if (token->type == CPP_EOF) |
| 28016 |
goto fail; |
| 28017 |
clauses.safe_push (*token); |
| 28018 |
c_parser_consume_token (parser); |
| 28019 |
} |
| 28020 |
clauses.safe_push (*c_parser_peek_token (parser)); |
| 28021 |
c_parser_skip_to_pragma_eol (parser); |
| 28022 |
|
| 28023 |
/* Make sure nothing tries to read past the end of the tokens. */ |
| 28024 |
c_token eof_token; |
| 28025 |
memset (&eof_token, 0, sizeof (eof_token)); |
| 28026 |
eof_token.type = CPP_EOF; |
| 28027 |
clauses.safe_push (eof_token); |
| 28028 |
clauses.safe_push (eof_token); |
| 28029 |
} |
| 28030 |
|
| 28031 |
int errs = errorcount; |
| 28032 |
FOR_EACH_VEC_ELT (types, i, type) |
| 28033 |
{ |
| 28034 |
saved_tokens = parser->tokens; |
| 28035 |
tokens_avail = parser->tokens_avail; |
| 28036 |
if (!clauses.is_empty ()) |
| 28037 |
{ |
| 28038 |
parser->tokens = clauses.address (); |
| 28039 |
parser->tokens_avail = clauses.length (); |
| 28040 |
parser->in_pragma = true; |
| 28041 |
} |
| 28042 |
|
| 28043 |
bool nested = current_function_decl != NULL_TREE; |
| 28044 |
if (nested) |
| 28045 |
c_push_function_context (); |
| 28046 |
tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, |
| 28047 |
reduc_id, default_function_type); |
| 28048 |
current_function_decl = fndecl; |
| 28049 |
allocate_struct_function (fndecl, true); |
| 28050 |
push_scope (); |
| 28051 |
tree stmt = push_stmt_list (); |
| 28052 |
/* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't |
| 28053 |
warn about these. */ |
| 28054 |
tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 28055 |
get_identifier ("omp_out"), type); |
| 28056 |
DECL_ARTIFICIAL (omp_out) = 1; |
| 28057 |
DECL_CONTEXT (omp_out) = fndecl; |
| 28058 |
pushdecl (omp_out); |
| 28059 |
tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 28060 |
get_identifier ("omp_in"), type); |
| 28061 |
DECL_ARTIFICIAL (omp_in) = 1; |
| 28062 |
DECL_CONTEXT (omp_in) = fndecl; |
| 28063 |
pushdecl (omp_in); |
| 28064 |
struct c_expr combiner = c_parser_expression (parser); |
| 28065 |
struct c_expr initializer; |
| 28066 |
tree omp_priv = NULL_TREE, omp_orig = NULL_TREE; |
| 28067 |
bool bad = false; |
| 28068 |
initializer.set_error (); |
| 28069 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 28070 |
bad = true; |
| 28071 |
else if (c_parser_next_token_is (parser, CPP_COMMA) |
| 28072 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 28073 |
c_parser_consume_token (parser); |
| 28074 |
if (!bad |
| 28075 |
&& (c_parser_next_token_is (parser, CPP_NAME) |
| 28076 |
&& strcmp (IDENTIFIER_POINTER |
| 28077 |
(c_parser_peek_token (parser)->value), |
| 28078 |
"initializer") == 0)) |
| 28079 |
{ |
| 28080 |
c_parser_consume_token (parser); |
| 28081 |
pop_scope (); |
| 28082 |
push_scope (); |
| 28083 |
omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 28084 |
get_identifier ("omp_priv"), type); |
| 28085 |
DECL_ARTIFICIAL (omp_priv) = 1; |
| 28086 |
DECL_INITIAL (omp_priv) = error_mark_node; |
| 28087 |
DECL_CONTEXT (omp_priv) = fndecl; |
| 28088 |
pushdecl (omp_priv); |
| 28089 |
omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 28090 |
get_identifier ("omp_orig"), type); |
| 28091 |
DECL_ARTIFICIAL (omp_orig) = 1; |
| 28092 |
DECL_CONTEXT (omp_orig) = fndecl; |
| 28093 |
pushdecl (omp_orig); |
| 28094 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 28095 |
bad = true; |
| 28096 |
else if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 28097 |
{ |
| 28098 |
c_parser_error (parser, "expected %<omp_priv%> or " |
| 28099 |
"function-name"); |
| 28100 |
bad = true; |
| 28101 |
} |
| 28102 |
else if (strcmp (IDENTIFIER_POINTER |
| 28103 |
(c_parser_peek_token (parser)->value), |
| 28104 |
"omp_priv") != 0) |
| 28105 |
{ |
| 28106 |
if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN |
| 28107 |
|| c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 28108 |
{ |
| 28109 |
c_parser_error (parser, "expected function-name %<(%>"); |
| 28110 |
bad = true; |
| 28111 |
} |
| 28112 |
else |
| 28113 |
initializer = c_parser_postfix_expression (parser); |
| 28114 |
if (initializer.value |
| 28115 |
&& TREE_CODE (initializer.value) == CALL_EXPR) |
| 28116 |
{ |
| 28117 |
int j; |
| 28118 |
tree c = initializer.value; |
| 28119 |
for (j = 0; j < call_expr_nargs (c); j++) |
| 28120 |
{ |
| 28121 |
tree a = CALL_EXPR_ARG (c, j); |
| 28122 |
STRIP_NOPS (a); |
| 28123 |
if (TREE_CODE (a) == ADDR_EXPR |
| 28124 |
&& TREE_OPERAND (a, 0) == omp_priv) |
| 28125 |
break; |
| 28126 |
} |
| 28127 |
if (j == call_expr_nargs (c)) |
| 28128 |
error ("one of the initializer call arguments should be " |
| 28129 |
"%<&omp_priv%>"); |
| 28130 |
} |
| 28131 |
} |
| 28132 |
else |
| 28133 |
{ |
| 28134 |
c_parser_consume_token (parser); |
| 28135 |
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 28136 |
bad = true; |
| 28137 |
else |
| 28138 |
{ |
| 28139 |
tree st = push_stmt_list (); |
| 28140 |
location_t loc = c_parser_peek_token (parser)->location; |
| 28141 |
rich_location richloc (line_table, loc); |
| 28142 |
start_init (omp_priv, NULL_TREE, false, false, &richloc); |
| 28143 |
struct c_expr init = c_parser_initializer (parser, omp_priv); |
| 28144 |
finish_init (); |
| 28145 |
finish_decl (omp_priv, loc, init.value, |
| 28146 |
init.original_type, NULL_TREE); |
| 28147 |
pop_stmt_list (st); |
| 28148 |
} |
| 28149 |
} |
| 28150 |
if (!bad |
| 28151 |
&& !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 28152 |
bad = true; |
| 28153 |
} |
| 28154 |
|
| 28155 |
if (!bad) |
| 28156 |
{ |
| 28157 |
c_parser_skip_to_pragma_eol (parser); |
| 28158 |
|
| 28159 |
tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3), |
| 28160 |
DECL_INITIAL (reduc_decl)); |
| 28161 |
DECL_INITIAL (reduc_decl) = t; |
| 28162 |
DECL_SOURCE_LOCATION (omp_out) = rloc; |
| 28163 |
TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out; |
| 28164 |
TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in; |
| 28165 |
TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value; |
| 28166 |
walk_tree (&combiner.value, c_check_omp_declare_reduction_r, |
| 28167 |
&TREE_VEC_ELT (TREE_VALUE (t), 0), NULL); |
| 28168 |
if (omp_priv) |
| 28169 |
{ |
| 28170 |
DECL_SOURCE_LOCATION (omp_priv) = rloc; |
| 28171 |
TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv; |
| 28172 |
TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig; |
| 28173 |
TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value; |
| 28174 |
walk_tree (&initializer.value, c_check_omp_declare_reduction_r, |
| 28175 |
&TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); |
| 28176 |
walk_tree (&DECL_INITIAL (omp_priv), |
| 28177 |
c_check_omp_declare_reduction_r, |
| 28178 |
&TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); |
| 28179 |
} |
| 28180 |
} |
| 28181 |
|
| 28182 |
pop_stmt_list (stmt); |
| 28183 |
pop_scope (); |
| 28184 |
if (cfun->language != NULL) |
| 28185 |
{ |
| 28186 |
ggc_free (cfun->language); |
| 28187 |
cfun->language = NULL; |
| 28188 |
} |
| 28189 |
set_cfun (NULL); |
| 28190 |
current_function_decl = NULL_TREE; |
| 28191 |
if (nested) |
| 28192 |
c_pop_function_context (); |
| 28193 |
|
| 28194 |
if (!clauses.is_empty ()) |
| 28195 |
{ |
| 28196 |
parser->tokens = saved_tokens; |
| 28197 |
parser->tokens_avail = tokens_avail; |
| 28198 |
} |
| 28199 |
if (bad) |
| 28200 |
goto fail; |
| 28201 |
if (errs != errorcount) |
| 28202 |
break; |
| 28203 |
} |
| 28204 |
|
| 28205 |
clauses.release (); |
| 28206 |
types.release (); |
| 28207 |
} |
| 28208 |
|
| 28209 |
/* OpenMP 4.0 |
| 28210 |
#pragma omp declare simd declare-simd-clauses[optseq] new-line |
| 28211 |
#pragma omp declare reduction (reduction-id : typename-list : expression) \ |
| 28212 |
initializer-clause[opt] new-line |
| 28213 |
#pragma omp declare target new-line |
| 28214 |
|
| 28215 |
OpenMP 5.0 |
| 28216 |
#pragma omp declare variant (identifier) match (context-selector) |
| 28217 |
|
| 28218 |
OpenMP 5.1 |
| 28219 |
#pragma omp declare variant (identifier) match (context-selector) \ |
| 28220 |
adjust_args(adjust-op:argument-list) */ |
| 28221 |
|
| 28222 |
static bool |
| 28223 |
c_parser_omp_declare (c_parser *parser, enum pragma_context context) |
| 28224 |
{ |
| 28225 |
c_parser_consume_pragma (parser); |
| 28226 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 28227 |
{ |
| 28228 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 28229 |
if (strcmp (p, "simd") == 0) |
| 28230 |
{ |
| 28231 |
/* c_parser_consume_token (parser); done in |
| 28232 |
c_parser_omp_declare_simd. */ |
| 28233 |
c_parser_omp_declare_simd (parser, context); |
| 28234 |
return true; |
| 28235 |
} |
| 28236 |
if (strcmp (p, "reduction") == 0) |
| 28237 |
{ |
| 28238 |
c_parser_consume_token (parser); |
| 28239 |
c_parser_omp_declare_reduction (parser, context); |
| 28240 |
return false; |
| 28241 |
} |
| 28242 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 28243 |
{ |
| 28244 |
c_parser_skip_to_pragma_eol (parser, false); |
| 28245 |
return false; |
| 28246 |
} |
| 28247 |
if (strcmp (p, "target") == 0) |
| 28248 |
{ |
| 28249 |
c_parser_consume_token (parser); |
| 28250 |
c_parser_omp_declare_target (parser); |
| 28251 |
return false; |
| 28252 |
} |
| 28253 |
if (strcmp (p, "variant") == 0) |
| 28254 |
{ |
| 28255 |
/* c_parser_consume_token (parser); done in |
| 28256 |
c_parser_omp_declare_simd. */ |
| 28257 |
c_parser_omp_declare_simd (parser, context); |
| 28258 |
return true; |
| 28259 |
} |
| 28260 |
} |
| 28261 |
|
| 28262 |
c_parser_error (parser, "expected %<simd%>, %<reduction%>, " |
| 28263 |
"%<target%> or %<variant%>"); |
| 28264 |
c_parser_skip_to_pragma_eol (parser); |
| 28265 |
return false; |
| 28266 |
} |
| 28267 |
|
| 28268 |
/* OpenMP 5.0 |
| 28269 |
#pragma omp requires clauses[optseq] new-line */ |
| 28270 |
|
| 28271 |
static void |
| 28272 |
c_parser_omp_requires (c_parser *parser) |
| 28273 |
{ |
| 28274 |
enum omp_requires new_req = (enum omp_requires) 0; |
| 28275 |
|
| 28276 |
c_parser_consume_pragma (parser); |
| 28277 |
|
| 28278 |
location_t loc = c_parser_peek_token (parser)->location; |
| 28279 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 28280 |
{ |
| 28281 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 28282 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 28283 |
c_parser_consume_token (parser); |
| 28284 |
|
| 28285 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 28286 |
{ |
| 28287 |
const char *p |
| 28288 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 28289 |
location_t cloc = c_parser_peek_token (parser)->location; |
| 28290 |
enum omp_requires this_req = (enum omp_requires) 0; |
| 28291 |
|
| 28292 |
if (!strcmp (p, "unified_address")) |
| 28293 |
this_req = OMP_REQUIRES_UNIFIED_ADDRESS; |
| 28294 |
else if (!strcmp (p, "unified_shared_memory")) |
| 28295 |
this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY; |
| 28296 |
else if (!strcmp (p, "self_maps")) |
| 28297 |
this_req = OMP_REQUIRES_SELF_MAPS; |
| 28298 |
else if (!strcmp (p, "dynamic_allocators")) |
| 28299 |
this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS; |
| 28300 |
else if (!strcmp (p, "reverse_offload")) |
| 28301 |
this_req = OMP_REQUIRES_REVERSE_OFFLOAD; |
| 28302 |
else if (!strcmp (p, "atomic_default_mem_order")) |
| 28303 |
{ |
| 28304 |
c_parser_consume_token (parser); |
| 28305 |
|
| 28306 |
matching_parens parens; |
| 28307 |
if (parens.require_open (parser)) |
| 28308 |
{ |
| 28309 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 28310 |
{ |
| 28311 |
tree v = c_parser_peek_token (parser)->value; |
| 28312 |
p = IDENTIFIER_POINTER (v); |
| 28313 |
|
| 28314 |
if (!strcmp (p, "seq_cst")) |
| 28315 |
this_req |
| 28316 |
= (enum omp_requires) OMP_MEMORY_ORDER_SEQ_CST; |
| 28317 |
else if (!strcmp (p, "relaxed")) |
| 28318 |
this_req |
| 28319 |
= (enum omp_requires) OMP_MEMORY_ORDER_RELAXED; |
| 28320 |
else if (!strcmp (p, "release")) |
| 28321 |
this_req |
| 28322 |
= (enum omp_requires) OMP_MEMORY_ORDER_RELEASE; |
| 28323 |
else if (!strcmp (p, "acq_rel")) |
| 28324 |
this_req |
| 28325 |
= (enum omp_requires) OMP_MEMORY_ORDER_ACQ_REL; |
| 28326 |
else if (!strcmp (p, "acquire")) |
| 28327 |
this_req |
| 28328 |
= (enum omp_requires) OMP_MEMORY_ORDER_ACQUIRE; |
| 28329 |
} |
| 28330 |
if (this_req == 0) |
| 28331 |
{ |
| 28332 |
error_at (c_parser_peek_token (parser)->location, |
| 28333 |
"expected %<acq_rel%>, %<acquire%>, " |
| 28334 |
"%<relaxed%>, %<release%> or %<seq_cst%>"); |
| 28335 |
switch (c_parser_peek_token (parser)->type) |
| 28336 |
{ |
| 28337 |
case CPP_EOF: |
| 28338 |
case CPP_PRAGMA_EOL: |
| 28339 |
case CPP_CLOSE_PAREN: |
| 28340 |
break; |
| 28341 |
default: |
| 28342 |
if (c_parser_peek_2nd_token (parser)->type |
| 28343 |
== CPP_CLOSE_PAREN) |
| 28344 |
c_parser_consume_token (parser); |
| 28345 |
break; |
| 28346 |
} |
| 28347 |
} |
| 28348 |
else |
| 28349 |
c_parser_consume_token (parser); |
| 28350 |
|
| 28351 |
parens.skip_until_found_close (parser); |
| 28352 |
if (this_req == 0) |
| 28353 |
{ |
| 28354 |
c_parser_skip_to_pragma_eol (parser, false); |
| 28355 |
return; |
| 28356 |
} |
| 28357 |
} |
| 28358 |
p = NULL; |
| 28359 |
} |
| 28360 |
else |
| 28361 |
{ |
| 28362 |
error_at (cloc, "expected %<unified_address%>, " |
| 28363 |
"%<unified_shared_memory%>, " |
| 28364 |
"%<self_maps%>, " |
| 28365 |
"%<dynamic_allocators%>, " |
| 28366 |
"%<reverse_offload%> " |
| 28367 |
"or %<atomic_default_mem_order%> clause"); |
| 28368 |
c_parser_skip_to_pragma_eol (parser, false); |
| 28369 |
return; |
| 28370 |
} |
| 28371 |
if (p) |
| 28372 |
c_parser_consume_token (parser); |
| 28373 |
if (this_req) |
| 28374 |
{ |
| 28375 |
if ((this_req & ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) |
| 28376 |
{ |
| 28377 |
if ((this_req & new_req) != 0) |
| 28378 |
error_at (cloc, "too many %qs clauses", p); |
| 28379 |
if (this_req != OMP_REQUIRES_DYNAMIC_ALLOCATORS |
| 28380 |
&& (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0) |
| 28381 |
error_at (cloc, "%qs clause used lexically after first " |
| 28382 |
"target construct or offloading API", p); |
| 28383 |
} |
| 28384 |
else if ((new_req & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) |
| 28385 |
{ |
| 28386 |
error_at (cloc, "too many %qs clauses", |
| 28387 |
"atomic_default_mem_order"); |
| 28388 |
this_req = (enum omp_requires) 0; |
| 28389 |
} |
| 28390 |
else if ((omp_requires_mask |
| 28391 |
& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) |
| 28392 |
{ |
| 28393 |
error_at (cloc, "more than one %<atomic_default_mem_order%>" |
| 28394 |
" clause in a single compilation unit"); |
| 28395 |
this_req |
| 28396 |
= (enum omp_requires) |
| 28397 |
(omp_requires_mask |
| 28398 |
& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER); |
| 28399 |
} |
| 28400 |
else if ((omp_requires_mask |
| 28401 |
& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED) != 0) |
| 28402 |
error_at (cloc, "%<atomic_default_mem_order%> clause used " |
| 28403 |
"lexically after first %<atomic%> construct " |
| 28404 |
"without memory order clause"); |
| 28405 |
new_req = (enum omp_requires) (new_req | this_req); |
| 28406 |
omp_requires_mask |
| 28407 |
= (enum omp_requires) (omp_requires_mask | this_req); |
| 28408 |
continue; |
| 28409 |
} |
| 28410 |
} |
| 28411 |
break; |
| 28412 |
} |
| 28413 |
c_parser_skip_to_pragma_eol (parser); |
| 28414 |
|
| 28415 |
if (new_req == 0) |
| 28416 |
error_at (loc, "%<pragma omp requires%> requires at least one clause"); |
| 28417 |
} |
| 28418 |
|
| 28419 |
/* Helper function for c_parser_omp_taskloop. |
| 28420 |
Disallow zero sized or potentially zero sized task reductions. */ |
| 28421 |
|
| 28422 |
static tree |
| 28423 |
c_finish_taskloop_clauses (tree clauses) |
| 28424 |
{ |
| 28425 |
tree *pc = &clauses; |
| 28426 |
for (tree c = clauses; c; c = *pc) |
| 28427 |
{ |
| 28428 |
bool remove = false; |
| 28429 |
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) |
| 28430 |
{ |
| 28431 |
tree type = strip_array_types (TREE_TYPE (OMP_CLAUSE_DECL (c))); |
| 28432 |
if (integer_zerop (TYPE_SIZE_UNIT (type))) |
| 28433 |
{ |
| 28434 |
error_at (OMP_CLAUSE_LOCATION (c), |
| 28435 |
"zero sized type %qT in %<reduction%> clause", type); |
| 28436 |
remove = true; |
| 28437 |
} |
| 28438 |
else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST) |
| 28439 |
{ |
| 28440 |
error_at (OMP_CLAUSE_LOCATION (c), |
| 28441 |
"variable sized type %qT in %<reduction%> clause", |
| 28442 |
type); |
| 28443 |
remove = true; |
| 28444 |
} |
| 28445 |
} |
| 28446 |
if (remove) |
| 28447 |
*pc = OMP_CLAUSE_CHAIN (c); |
| 28448 |
else |
| 28449 |
pc = &OMP_CLAUSE_CHAIN (c); |
| 28450 |
} |
| 28451 |
return clauses; |
| 28452 |
} |
| 28453 |
|
| 28454 |
/* OpenMP 4.5: |
| 28455 |
#pragma omp taskloop taskloop-clause[optseq] new-line |
| 28456 |
for-loop |
| 28457 |
|
| 28458 |
#pragma omp taskloop simd taskloop-simd-clause[optseq] new-line |
| 28459 |
for-loop */ |
| 28460 |
|
| 28461 |
#define OMP_TASKLOOP_CLAUSE_MASK \ |
| 28462 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 28463 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 28464 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 28465 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 28466 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
| 28467 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \ |
| 28468 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \ |
| 28469 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
| 28470 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ |
| 28471 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 28472 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ |
| 28473 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ |
| 28474 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \ |
| 28475 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \ |
| 28476 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \ |
| 28477 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 28478 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION)) |
| 28479 |
|
| 28480 |
static tree |
| 28481 |
c_parser_omp_taskloop (location_t loc, c_parser *parser, |
| 28482 |
char *p_name, omp_clause_mask mask, tree *cclauses, |
| 28483 |
bool *if_p) |
| 28484 |
{ |
| 28485 |
tree clauses, block, ret; |
| 28486 |
|
| 28487 |
strcat (p_name, " taskloop"); |
| 28488 |
mask |= OMP_TASKLOOP_CLAUSE_MASK; |
| 28489 |
/* #pragma omp parallel master taskloop{, simd} disallow in_reduction |
| 28490 |
clause. */ |
| 28491 |
if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) |
| 28492 |
mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION); |
| 28493 |
|
| 28494 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 28495 |
{ |
| 28496 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 28497 |
|
| 28498 |
if (strcmp (p, "simd") == 0) |
| 28499 |
{ |
| 28500 |
tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 28501 |
if (cclauses == NULL) |
| 28502 |
cclauses = cclauses_buf; |
| 28503 |
c_parser_consume_token (parser); |
| 28504 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 28505 |
return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 28506 |
if_p); |
| 28507 |
block = c_begin_compound_stmt (true); |
| 28508 |
ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p); |
| 28509 |
block = c_end_compound_stmt (loc, block, true); |
| 28510 |
if (ret == NULL) |
| 28511 |
return ret; |
| 28512 |
ret = make_node (OMP_TASKLOOP); |
| 28513 |
TREE_TYPE (ret) = void_type_node; |
| 28514 |
OMP_FOR_BODY (ret) = block; |
| 28515 |
OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; |
| 28516 |
OMP_FOR_CLAUSES (ret) |
| 28517 |
= c_finish_taskloop_clauses (OMP_FOR_CLAUSES (ret)); |
| 28518 |
SET_EXPR_LOCATION (ret, loc); |
| 28519 |
add_stmt (ret); |
| 28520 |
return ret; |
| 28521 |
} |
| 28522 |
} |
| 28523 |
if (!flag_openmp) /* flag_openmp_simd */ |
| 28524 |
{ |
| 28525 |
c_parser_skip_to_pragma_eol (parser, false); |
| 28526 |
return NULL_TREE; |
| 28527 |
} |
| 28528 |
|
| 28529 |
clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 28530 |
if (cclauses) |
| 28531 |
{ |
| 28532 |
omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses); |
| 28533 |
clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; |
| 28534 |
} |
| 28535 |
|
| 28536 |
clauses = c_finish_taskloop_clauses (clauses); |
| 28537 |
block = c_begin_compound_stmt (true); |
| 28538 |
ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p); |
| 28539 |
block = c_end_compound_stmt (loc, block, true); |
| 28540 |
add_stmt (block); |
| 28541 |
|
| 28542 |
return ret; |
| 28543 |
} |
| 28544 |
|
| 28545 |
/* OpenMP 5.1: Parse sizes list for "omp tile sizes" |
| 28546 |
sizes ( size-expr-list ) */ |
| 28547 |
static tree |
| 28548 |
c_parser_omp_tile_sizes (c_parser *parser, location_t loc) |
| 28549 |
{ |
| 28550 |
tree sizes = NULL_TREE; |
| 28551 |
|
| 28552 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 28553 |
c_parser_consume_token (parser); |
| 28554 |
|
| 28555 |
c_token *tok = c_parser_peek_token (parser); |
| 28556 |
if (tok->type != CPP_NAME |
| 28557 |
|| strcmp ("sizes", IDENTIFIER_POINTER (tok->value))) |
| 28558 |
{ |
| 28559 |
c_parser_error (parser, "expected %<sizes%>"); |
| 28560 |
return error_mark_node; |
| 28561 |
} |
| 28562 |
c_parser_consume_token (parser); |
| 28563 |
|
| 28564 |
matching_parens parens; |
| 28565 |
if (!parens.require_open (parser)) |
| 28566 |
return error_mark_node; |
| 28567 |
|
| 28568 |
vec<tree, va_gc> *sizes_vec |
| 28569 |
= c_parser_expr_list (parser, true, true, NULL, NULL, NULL, NULL); |
| 28570 |
sizes = build_tree_list_vec (sizes_vec); |
| 28571 |
release_tree_vector (sizes_vec); |
| 28572 |
|
| 28573 |
for (tree s = sizes; s; s = TREE_CHAIN (s)) |
| 28574 |
{ |
| 28575 |
tree expr = TREE_VALUE (s); |
| 28576 |
if (expr == error_mark_node) |
| 28577 |
{ |
| 28578 |
parens.skip_until_found_close (parser); |
| 28579 |
return error_mark_node; |
| 28580 |
} |
| 28581 |
|
| 28582 |
HOST_WIDE_INT n; |
| 28583 |
if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)) |
| 28584 |
|| !tree_fits_shwi_p (expr) |
| 28585 |
|| (n = tree_to_shwi (expr)) <= 0 |
| 28586 |
|| (int) n != n) |
| 28587 |
{ |
| 28588 |
c_parser_error (parser, "%<sizes%> argument needs positive" |
| 28589 |
" integral constant"); |
| 28590 |
TREE_VALUE (s) = integer_one_node; |
| 28591 |
} |
| 28592 |
} |
| 28593 |
parens.require_close (parser); |
| 28594 |
|
| 28595 |
gcc_assert (sizes); |
| 28596 |
tree c = build_omp_clause (loc, OMP_CLAUSE_SIZES); |
| 28597 |
OMP_CLAUSE_SIZES_LIST (c) = sizes; |
| 28598 |
|
| 28599 |
return c; |
| 28600 |
} |
| 28601 |
|
| 28602 |
/* OpenMP 5.1: |
| 28603 |
#pragma omp tile sizes ( size-expr-list ) new-line |
| 28604 |
for-loop |
| 28605 |
|
| 28606 |
LOC is the location of the #pragma token. */ |
| 28607 |
|
| 28608 |
static tree |
| 28609 |
c_parser_omp_tile (location_t loc, c_parser *parser, bool *if_p) |
| 28610 |
{ |
| 28611 |
tree clauses = c_parser_omp_tile_sizes (parser, loc); |
| 28612 |
c_parser_skip_to_pragma_eol (parser); |
| 28613 |
|
| 28614 |
if (!clauses || clauses == error_mark_node) |
| 28615 |
return error_mark_node; |
| 28616 |
|
| 28617 |
tree block = c_begin_compound_stmt (true); |
| 28618 |
tree ret = c_parser_omp_for_loop (loc, parser, OMP_TILE, clauses, |
| 28619 |
NULL, if_p); |
| 28620 |
block = c_end_compound_stmt (loc, block, true); |
| 28621 |
add_stmt (block); |
| 28622 |
|
| 28623 |
return ret; |
| 28624 |
} |
| 28625 |
|
| 28626 |
#define OMP_UNROLL_CLAUSE_MASK \ |
| 28627 |
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARTIAL) \ |
| 28628 |
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FULL)) |
| 28629 |
|
| 28630 |
/* OpenMP 5.1 |
| 28631 |
#pragma omp unroll unroll-clause[optseq] new-line |
| 28632 |
for-loop |
| 28633 |
|
| 28634 |
LOC is the location of the #pragma token. */ |
| 28635 |
|
| 28636 |
static tree |
| 28637 |
c_parser_omp_unroll (location_t loc, c_parser *parser, bool *if_p) |
| 28638 |
{ |
| 28639 |
tree clauses = c_parser_omp_all_clauses (parser, OMP_UNROLL_CLAUSE_MASK, |
| 28640 |
"#pragma omp unroll", true); |
| 28641 |
|
| 28642 |
tree block = c_begin_compound_stmt (true); |
| 28643 |
tree ret = c_parser_omp_for_loop (loc, parser, OMP_UNROLL, clauses, |
| 28644 |
NULL, if_p); |
| 28645 |
block = c_end_compound_stmt (loc, block, true); |
| 28646 |
add_stmt (block); |
| 28647 |
|
| 28648 |
return ret; |
| 28649 |
} |
| 28650 |
|
| 28651 |
/* OpenMP 5.1 |
| 28652 |
#pragma omp nothing new-line */ |
| 28653 |
|
| 28654 |
static void |
| 28655 |
c_parser_omp_nothing (c_parser *parser) |
| 28656 |
{ |
| 28657 |
c_parser_consume_pragma (parser); |
| 28658 |
c_parser_skip_to_pragma_eol (parser); |
| 28659 |
} |
| 28660 |
|
| 28661 |
/* OpenMP 5.1 |
| 28662 |
#pragma omp error clauses[optseq] new-line */ |
| 28663 |
|
| 28664 |
static bool |
| 28665 |
c_parser_omp_error (c_parser *parser, enum pragma_context context) |
| 28666 |
{ |
| 28667 |
int at_compilation = -1; |
| 28668 |
int severity_fatal = -1; |
| 28669 |
tree message = NULL_TREE; |
| 28670 |
bool bad = false; |
| 28671 |
location_t loc = c_parser_peek_token (parser)->location; |
| 28672 |
|
| 28673 |
c_parser_consume_pragma (parser); |
| 28674 |
|
| 28675 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 28676 |
{ |
| 28677 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 28678 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 28679 |
c_parser_consume_token (parser); |
| 28680 |
|
| 28681 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 28682 |
break; |
| 28683 |
|
| 28684 |
const char *p |
| 28685 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 28686 |
location_t cloc = c_parser_peek_token (parser)->location; |
| 28687 |
static const char *args[] = { |
| 28688 |
"execution", "compilation", "warning", "fatal" |
| 28689 |
}; |
| 28690 |
int *v = NULL; |
| 28691 |
int idx = 0, n = -1; |
| 28692 |
tree m = NULL_TREE; |
| 28693 |
|
| 28694 |
if (!strcmp (p, "at")) |
| 28695 |
v = &at_compilation; |
| 28696 |
else if (!strcmp (p, "severity")) |
| 28697 |
{ |
| 28698 |
v = &severity_fatal; |
| 28699 |
idx += 2; |
| 28700 |
} |
| 28701 |
else if (strcmp (p, "message")) |
| 28702 |
{ |
| 28703 |
error_at (cloc, |
| 28704 |
"expected %<at%>, %<severity%> or %<message%> clause"); |
| 28705 |
c_parser_skip_to_pragma_eol (parser, false); |
| 28706 |
return false; |
| 28707 |
} |
| 28708 |
|
| 28709 |
c_parser_consume_token (parser); |
| 28710 |
|
| 28711 |
matching_parens parens; |
| 28712 |
if (parens.require_open (parser)) |
| 28713 |
{ |
| 28714 |
if (v == NULL) |
| 28715 |
{ |
| 28716 |
location_t expr_loc = c_parser_peek_token (parser)->location; |
| 28717 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 28718 |
expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true); |
| 28719 |
m = convert (const_string_type_node, expr.value); |
| 28720 |
m = c_fully_fold (m, false, NULL); |
| 28721 |
} |
| 28722 |
else |
| 28723 |
{ |
| 28724 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 28725 |
{ |
| 28726 |
tree val = c_parser_peek_token (parser)->value; |
| 28727 |
const char *q = IDENTIFIER_POINTER (val); |
| 28728 |
|
| 28729 |
if (!strcmp (q, args[idx])) |
| 28730 |
n = 0; |
| 28731 |
else if (!strcmp (q, args[idx + 1])) |
| 28732 |
n = 1; |
| 28733 |
} |
| 28734 |
if (n == -1) |
| 28735 |
{ |
| 28736 |
error_at (c_parser_peek_token (parser)->location, |
| 28737 |
"expected %qs or %qs", args[idx], args[idx + 1]); |
| 28738 |
bad = true; |
| 28739 |
switch (c_parser_peek_token (parser)->type) |
| 28740 |
{ |
| 28741 |
case CPP_EOF: |
| 28742 |
case CPP_PRAGMA_EOL: |
| 28743 |
case CPP_CLOSE_PAREN: |
| 28744 |
break; |
| 28745 |
default: |
| 28746 |
if (c_parser_peek_2nd_token (parser)->type |
| 28747 |
== CPP_CLOSE_PAREN) |
| 28748 |
c_parser_consume_token (parser); |
| 28749 |
break; |
| 28750 |
} |
| 28751 |
} |
| 28752 |
else |
| 28753 |
c_parser_consume_token (parser); |
| 28754 |
} |
| 28755 |
|
| 28756 |
parens.skip_until_found_close (parser); |
| 28757 |
|
| 28758 |
if (v == NULL) |
| 28759 |
{ |
| 28760 |
if (message) |
| 28761 |
{ |
| 28762 |
error_at (cloc, "too many %qs clauses", p); |
| 28763 |
bad = true; |
| 28764 |
} |
| 28765 |
else |
| 28766 |
message = m; |
| 28767 |
} |
| 28768 |
else if (n != -1) |
| 28769 |
{ |
| 28770 |
if (*v != -1) |
| 28771 |
{ |
| 28772 |
error_at (cloc, "too many %qs clauses", p); |
| 28773 |
bad = true; |
| 28774 |
} |
| 28775 |
else |
| 28776 |
*v = n; |
| 28777 |
} |
| 28778 |
} |
| 28779 |
else |
| 28780 |
bad = true; |
| 28781 |
} |
| 28782 |
c_parser_skip_to_pragma_eol (parser); |
| 28783 |
if (bad) |
| 28784 |
return true; |
| 28785 |
|
| 28786 |
if (at_compilation == -1) |
| 28787 |
at_compilation = 1; |
| 28788 |
if (severity_fatal == -1) |
| 28789 |
severity_fatal = 1; |
| 28790 |
if (!at_compilation) |
| 28791 |
{ |
| 28792 |
if (context != pragma_compound) |
| 28793 |
{ |
| 28794 |
error_at (loc, "%<#pragma omp error%> with %<at(execution)%> clause " |
| 28795 |
"may only be used in compound statements"); |
| 28796 |
return true; |
| 28797 |
} |
| 28798 |
tree fndecl |
| 28799 |
= builtin_decl_explicit (severity_fatal ? BUILT_IN_GOMP_ERROR |
| 28800 |
: BUILT_IN_GOMP_WARNING); |
| 28801 |
if (!message) |
| 28802 |
message = build_zero_cst (const_string_type_node); |
| 28803 |
tree stmt = build_call_expr_loc (loc, fndecl, 2, message, |
| 28804 |
build_all_ones_cst (size_type_node)); |
| 28805 |
add_stmt (stmt); |
| 28806 |
return true; |
| 28807 |
} |
| 28808 |
const char *msg = NULL; |
| 28809 |
if (message) |
| 28810 |
{ |
| 28811 |
msg = c_getstr (message); |
| 28812 |
if (msg == NULL) |
| 28813 |
msg = _("<message unknown at compile time>"); |
| 28814 |
} |
| 28815 |
if (msg) |
| 28816 |
emit_diagnostic (severity_fatal ? DK_ERROR : DK_WARNING, loc, 0, |
| 28817 |
"%<pragma omp error%> encountered: %s", msg); |
| 28818 |
else |
| 28819 |
emit_diagnostic (severity_fatal ? DK_ERROR : DK_WARNING, loc, 0, |
| 28820 |
"%<pragma omp error%> encountered"); |
| 28821 |
return false; |
| 28822 |
} |
| 28823 |
|
| 28824 |
/* Assumption clauses: |
| 28825 |
OpenMP 5.1 |
| 28826 |
absent (directive-name-list) |
| 28827 |
contains (directive-name-list) |
| 28828 |
holds (expression) |
| 28829 |
no_openmp |
| 28830 |
no_openmp_routines |
| 28831 |
no_parallelism */ |
| 28832 |
|
| 28833 |
static void |
| 28834 |
c_parser_omp_assumption_clauses (c_parser *parser, bool is_assume) |
| 28835 |
{ |
| 28836 |
bool no_openmp = false; |
| 28837 |
bool no_openmp_routines = false; |
| 28838 |
bool no_parallelism = false; |
| 28839 |
bitmap_head absent_head, contains_head; |
| 28840 |
|
| 28841 |
bitmap_obstack_initialize (NULL); |
| 28842 |
bitmap_initialize (&absent_head, &bitmap_default_obstack); |
| 28843 |
bitmap_initialize (&contains_head, &bitmap_default_obstack); |
| 28844 |
|
| 28845 |
if (c_parser_next_token_is (parser, CPP_PRAGMA_EOL)) |
| 28846 |
error_at (c_parser_peek_token (parser)->location, |
| 28847 |
"expected at least one assumption clause"); |
| 28848 |
|
| 28849 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 28850 |
{ |
| 28851 |
if (c_parser_next_token_is (parser, CPP_COMMA) |
| 28852 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 28853 |
c_parser_consume_token (parser); |
| 28854 |
|
| 28855 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 28856 |
break; |
| 28857 |
|
| 28858 |
const char *p |
| 28859 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 28860 |
location_t cloc = c_parser_peek_token (parser)->location; |
| 28861 |
|
| 28862 |
if (!strcmp (p, "no_openmp")) |
| 28863 |
{ |
| 28864 |
c_parser_consume_token (parser); |
| 28865 |
if (no_openmp) |
| 28866 |
error_at (cloc, "too many %qs clauses", "no_openmp"); |
| 28867 |
no_openmp = true; |
| 28868 |
} |
| 28869 |
else if (!strcmp (p, "no_openmp_routines")) |
| 28870 |
{ |
| 28871 |
c_parser_consume_token (parser); |
| 28872 |
if (no_openmp_routines) |
| 28873 |
error_at (cloc, "too many %qs clauses", "no_openmp_routines"); |
| 28874 |
no_openmp_routines = true; |
| 28875 |
} |
| 28876 |
else if (!strcmp (p, "no_parallelism")) |
| 28877 |
{ |
| 28878 |
c_parser_consume_token (parser); |
| 28879 |
if (no_parallelism) |
| 28880 |
error_at (cloc, "too many %qs clauses", "no_parallelism"); |
| 28881 |
no_parallelism = true; |
| 28882 |
} |
| 28883 |
else if (!strcmp (p, "holds")) |
| 28884 |
{ |
| 28885 |
c_parser_consume_token (parser); |
| 28886 |
matching_parens parens; |
| 28887 |
if (parens.require_open (parser)) |
| 28888 |
{ |
| 28889 |
location_t eloc = c_parser_peek_token (parser)->location; |
| 28890 |
c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 28891 |
tree t = convert_lvalue_to_rvalue (eloc, expr, true, true).value; |
| 28892 |
t = c_objc_common_truthvalue_conversion (eloc, t); |
| 28893 |
t = c_fully_fold (t, false, NULL); |
| 28894 |
if (is_assume && t != error_mark_node) |
| 28895 |
{ |
| 28896 |
tree fn = build_call_expr_internal_loc (eloc, IFN_ASSUME, |
| 28897 |
void_type_node, 1, |
| 28898 |
t); |
| 28899 |
add_stmt (fn); |
| 28900 |
} |
| 28901 |
parens.skip_until_found_close (parser); |
| 28902 |
} |
| 28903 |
} |
| 28904 |
else if (!strcmp (p, "absent") || !strcmp (p, "contains")) |
| 28905 |
{ |
| 28906 |
c_parser_consume_token (parser); |
| 28907 |
matching_parens parens; |
| 28908 |
if (parens.require_open (parser)) |
| 28909 |
{ |
| 28910 |
do |
| 28911 |
{ |
| 28912 |
const char *directive[3] = {}; |
| 28913 |
int i; |
| 28914 |
location_t dloc = c_parser_peek_token (parser)->location; |
| 28915 |
for (i = 0; i < 3; i++) |
| 28916 |
{ |
| 28917 |
tree id; |
| 28918 |
if (c_parser_peek_nth_token (parser, i + 1)->type |
| 28919 |
== CPP_NAME) |
| 28920 |
id = c_parser_peek_nth_token (parser, i + 1)->value; |
| 28921 |
else if (c_parser_peek_nth_token (parser, i + 1)->keyword |
| 28922 |
!= RID_MAX) |
| 28923 |
{ |
| 28924 |
enum rid rid |
| 28925 |
= c_parser_peek_nth_token (parser, i + 1)->keyword; |
| 28926 |
id = ridpointers[rid]; |
| 28927 |
} |
| 28928 |
else |
| 28929 |
break; |
| 28930 |
directive[i] = IDENTIFIER_POINTER (id); |
| 28931 |
} |
| 28932 |
if (i == 0) |
| 28933 |
error_at (dloc, "expected directive name"); |
| 28934 |
else |
| 28935 |
{ |
| 28936 |
const struct c_omp_directive *dir |
| 28937 |
= c_omp_categorize_directive (directive[0], |
| 28938 |
directive[1], |
| 28939 |
directive[2]); |
| 28940 |
if (dir |
| 28941 |
&& (dir->kind == C_OMP_DIR_DECLARATIVE |
| 28942 |
|| dir->kind == C_OMP_DIR_INFORMATIONAL |
| 28943 |
|| dir->kind == C_OMP_DIR_META)) |
| 28944 |
error_at (dloc, "invalid OpenMP directive name in " |
| 28945 |
"%qs clause argument: declarative, " |
| 28946 |
"informational, and meta directives " |
| 28947 |
"not permitted", p); |
| 28948 |
else if (dir == NULL |
| 28949 |
|| dir->id == PRAGMA_OMP_END |
| 28950 |
|| (!dir->second && directive[1]) |
| 28951 |
|| (!dir->third && directive[2])) |
| 28952 |
error_at (dloc, "unknown OpenMP directive name in " |
| 28953 |
"%qs clause argument", p); |
| 28954 |
else |
| 28955 |
{ |
| 28956 |
int id = dir - c_omp_directives; |
| 28957 |
if (bitmap_bit_p (p[0] == 'a' ? &contains_head |
| 28958 |
: &absent_head, id)) |
| 28959 |
error_at (dloc, "%<%s%s%s%s%s%> directive " |
| 28960 |
"mentioned in both %<absent%> and " |
| 28961 |
"%<contains%> clauses", |
| 28962 |
directive[0], |
| 28963 |
directive[1] ? " " : "", |
| 28964 |
directive[1] ? directive[1] : "", |
| 28965 |
directive[2] ? " " : "", |
| 28966 |
directive[2] ? directive[2] : ""); |
| 28967 |
else if (!bitmap_set_bit (p[0] == 'a' |
| 28968 |
? &absent_head |
| 28969 |
: &contains_head, id)) |
| 28970 |
error_at (dloc, "%<%s%s%s%s%s%> directive " |
| 28971 |
"mentioned multiple times in %qs " |
| 28972 |
"clauses", |
| 28973 |
directive[0], |
| 28974 |
directive[1] ? " " : "", |
| 28975 |
directive[1] ? directive[1] : "", |
| 28976 |
directive[2] ? " " : "", |
| 28977 |
directive[2] ? directive[2] : "", p); |
| 28978 |
} |
| 28979 |
for (; i; --i) |
| 28980 |
c_parser_consume_token (parser); |
| 28981 |
} |
| 28982 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 28983 |
c_parser_consume_token (parser); |
| 28984 |
else |
| 28985 |
break; |
| 28986 |
} |
| 28987 |
while (1); |
| 28988 |
parens.skip_until_found_close (parser); |
| 28989 |
} |
| 28990 |
} |
| 28991 |
else if (startswith (p, "ext_")) |
| 28992 |
{ |
| 28993 |
warning_at (cloc, OPT_Wopenmp, "unknown assumption clause %qs", p); |
| 28994 |
c_parser_consume_token (parser); |
| 28995 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 28996 |
{ |
| 28997 |
matching_parens parens; |
| 28998 |
parens.consume_open (parser); |
| 28999 |
c_parser_balanced_token_sequence (parser); |
| 29000 |
parens.require_close (parser); |
| 29001 |
} |
| 29002 |
} |
| 29003 |
else |
| 29004 |
{ |
| 29005 |
c_parser_consume_token (parser); |
| 29006 |
error_at (cloc, "expected assumption clause"); |
| 29007 |
break; |
| 29008 |
} |
| 29009 |
} |
| 29010 |
c_parser_skip_to_pragma_eol (parser); |
| 29011 |
} |
| 29012 |
|
| 29013 |
/* OpenMP 5.1 |
| 29014 |
#pragma omp assume clauses[optseq] new-line */ |
| 29015 |
|
| 29016 |
static void |
| 29017 |
c_parser_omp_assume (c_parser *parser, bool *if_p) |
| 29018 |
{ |
| 29019 |
c_parser_omp_assumption_clauses (parser, true); |
| 29020 |
add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 29021 |
} |
| 29022 |
|
| 29023 |
/* OpenMP 5.1 |
| 29024 |
#pragma omp assumes clauses[optseq] new-line */ |
| 29025 |
|
| 29026 |
static void |
| 29027 |
c_parser_omp_assumes (c_parser *parser) |
| 29028 |
{ |
| 29029 |
c_parser_consume_pragma (parser); |
| 29030 |
c_parser_omp_assumption_clauses (parser, false); |
| 29031 |
} |
| 29032 |
|
| 29033 |
/* Helper function for c_parser_omp_metadirective. */ |
| 29034 |
|
| 29035 |
static void |
| 29036 |
analyze_metadirective_body (c_parser *parser, |
| 29037 |
vec<c_token> &tokens, |
| 29038 |
vec<tree> &labels) |
| 29039 |
{ |
| 29040 |
int nesting_depth = 0; |
| 29041 |
int bracket_depth = 0; |
| 29042 |
bool ignore_label = false; |
| 29043 |
|
| 29044 |
/* Read in the body tokens to the tokens for each candidate directive. */ |
| 29045 |
while (1) |
| 29046 |
{ |
| 29047 |
c_token *token = c_parser_peek_token (parser); |
| 29048 |
bool stop = false; |
| 29049 |
|
| 29050 |
if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
| 29051 |
ignore_label = true; |
| 29052 |
|
| 29053 |
switch (token->type) |
| 29054 |
{ |
| 29055 |
case CPP_EOF: |
| 29056 |
break; |
| 29057 |
case CPP_NAME: |
| 29058 |
if (!ignore_label |
| 29059 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 29060 |
labels.safe_push (token->value); |
| 29061 |
goto add; |
| 29062 |
case CPP_OPEN_BRACE: |
| 29063 |
++nesting_depth; |
| 29064 |
goto add; |
| 29065 |
case CPP_CLOSE_BRACE: |
| 29066 |
if (--nesting_depth == 0 && bracket_depth == 0) |
| 29067 |
stop = true; |
| 29068 |
goto add; |
| 29069 |
case CPP_OPEN_PAREN: |
| 29070 |
++bracket_depth; |
| 29071 |
goto add; |
| 29072 |
case CPP_CLOSE_PAREN: |
| 29073 |
--bracket_depth; |
| 29074 |
goto add; |
| 29075 |
case CPP_COLON: |
| 29076 |
ignore_label = false; |
| 29077 |
goto add; |
| 29078 |
case CPP_SEMICOLON: |
| 29079 |
if (nesting_depth == 0 && bracket_depth == 0) |
| 29080 |
stop = true; |
| 29081 |
goto add; |
| 29082 |
default: |
| 29083 |
add: |
| 29084 |
tokens.safe_push (*token); |
| 29085 |
if (token->type == CPP_PRAGMA) |
| 29086 |
c_parser_consume_pragma (parser); |
| 29087 |
else if (token->type == CPP_PRAGMA_EOL) |
| 29088 |
c_parser_skip_to_pragma_eol (parser); |
| 29089 |
else |
| 29090 |
c_parser_consume_token (parser); |
| 29091 |
if (stop) |
| 29092 |
break; |
| 29093 |
continue; |
| 29094 |
} |
| 29095 |
break; |
| 29096 |
} |
| 29097 |
} |
| 29098 |
|
| 29099 |
/* OpenMP 5.0: |
| 29100 |
|
| 29101 |
# pragma omp metadirective [clause[, clause]] |
| 29102 |
*/ |
| 29103 |
|
| 29104 |
static void |
| 29105 |
c_parser_omp_metadirective (c_parser *parser, bool *if_p) |
| 29106 |
{ |
| 29107 |
static unsigned int metadirective_region_count = 0; |
| 29108 |
|
| 29109 |
tree ret; |
| 29110 |
auto_vec<c_token> directive_tokens; |
| 29111 |
auto_vec<c_token> body_tokens; |
| 29112 |
auto_vec<tree> body_labels; |
| 29113 |
auto_vec<const struct c_omp_directive *> directives; |
| 29114 |
auto_vec<tree> ctxs; |
| 29115 |
vec<struct omp_variant> candidates; |
| 29116 |
bool default_seen = false; |
| 29117 |
int directive_token_idx = 0; |
| 29118 |
tree standalone_body = NULL_TREE; |
| 29119 |
location_t pragma_loc = c_parser_peek_token (parser)->location; |
| 29120 |
bool requires_body = false; |
| 29121 |
|
| 29122 |
ret = make_node (OMP_METADIRECTIVE); |
| 29123 |
SET_EXPR_LOCATION (ret, pragma_loc); |
| 29124 |
TREE_TYPE (ret) = void_type_node; |
| 29125 |
OMP_METADIRECTIVE_VARIANTS (ret) = NULL_TREE; |
| 29126 |
|
| 29127 |
c_parser_consume_pragma (parser); |
| 29128 |
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 29129 |
{ |
| 29130 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 29131 |
c_parser_consume_token (parser); |
| 29132 |
if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 29133 |
&& c_parser_next_token_is_not (parser, CPP_KEYWORD)) |
| 29134 |
{ |
| 29135 |
c_parser_error (parser, "expected %<when%>, " |
| 29136 |
"%<otherwise%>, or %<default%> clause"); |
| 29137 |
goto error; |
| 29138 |
} |
| 29139 |
|
| 29140 |
location_t match_loc = c_parser_peek_token (parser)->location; |
| 29141 |
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 29142 |
c_parser_consume_token (parser); |
| 29143 |
bool default_p |
| 29144 |
= strcmp (p, "default") == 0 || strcmp (p, "otherwise") == 0; |
| 29145 |
if (default_p) |
| 29146 |
{ |
| 29147 |
if (default_seen) |
| 29148 |
{ |
| 29149 |
error_at (match_loc, "too many %<otherwise%> or %<default%> " |
| 29150 |
"clauses in %<metadirective%>"); |
| 29151 |
goto error; |
| 29152 |
} |
| 29153 |
default_seen = true; |
| 29154 |
} |
| 29155 |
else if (default_seen) |
| 29156 |
{ |
| 29157 |
error_at (match_loc, "%<otherwise%> or %<default%> clause " |
| 29158 |
"must appear last in %<metadirective%>"); |
| 29159 |
goto error; |
| 29160 |
} |
| 29161 |
if (!default_p && strcmp (p, "when") != 0) |
| 29162 |
{ |
| 29163 |
error_at (match_loc, "%qs is not valid for %qs", |
| 29164 |
p, "metadirective"); |
| 29165 |
goto error; |
| 29166 |
} |
| 29167 |
|
| 29168 |
matching_parens parens; |
| 29169 |
tree ctx = NULL_TREE; |
| 29170 |
bool skip = false; |
| 29171 |
|
| 29172 |
if (!parens.require_open (parser)) |
| 29173 |
goto error; |
| 29174 |
|
| 29175 |
if (!default_p) |
| 29176 |
{ |
| 29177 |
ctx = c_parser_omp_context_selector_specification (parser, |
| 29178 |
NULL_TREE); |
| 29179 |
if (ctx == error_mark_node) |
| 29180 |
goto error; |
| 29181 |
ctx = omp_check_context_selector (match_loc, ctx, |
| 29182 |
OMP_CTX_METADIRECTIVE); |
| 29183 |
if (ctx == error_mark_node) |
| 29184 |
goto error; |
| 29185 |
|
| 29186 |
/* Remove the selector from further consideration if it can be |
| 29187 |
evaluated as a non-match at this point. */ |
| 29188 |
skip = (omp_context_selector_matches (ctx, NULL_TREE, false) == 0); |
| 29189 |
|
| 29190 |
if (c_parser_next_token_is_not (parser, CPP_COLON)) |
| 29191 |
{ |
| 29192 |
c_parser_require (parser, CPP_COLON, "expected %<:%>"); |
| 29193 |
goto error; |
| 29194 |
} |
| 29195 |
c_parser_consume_token (parser); |
| 29196 |
} |
| 29197 |
|
| 29198 |
/* Read in the directive type and create a dummy pragma token for |
| 29199 |
it. */ |
| 29200 |
location_t loc = c_parser_peek_token (parser)->location; |
| 29201 |
|
| 29202 |
const char *directive[3] = {}; |
| 29203 |
int i; |
| 29204 |
for (i = 0; i < 3; i++) |
| 29205 |
{ |
| 29206 |
tree id; |
| 29207 |
if (c_parser_peek_nth_token (parser, i + 1)->type |
| 29208 |
== CPP_CLOSE_PAREN) |
| 29209 |
{ |
| 29210 |
if (i == 0) |
| 29211 |
directive[i++] = "nothing"; |
| 29212 |
break; |
| 29213 |
} |
| 29214 |
else if (c_parser_peek_nth_token (parser, i + 1)->type |
| 29215 |
== CPP_NAME) |
| 29216 |
id = c_parser_peek_nth_token (parser, i + 1)->value; |
| 29217 |
else if (c_parser_peek_nth_token (parser, i + 1)->keyword |
| 29218 |
!= RID_MAX) |
| 29219 |
{ |
| 29220 |
enum rid rid |
| 29221 |
= c_parser_peek_nth_token (parser, i + 1)->keyword; |
| 29222 |
id = ridpointers[rid]; |
| 29223 |
} |
| 29224 |
else |
| 29225 |
break; |
| 29226 |
|
| 29227 |
directive[i] = IDENTIFIER_POINTER (id); |
| 29228 |
} |
| 29229 |
if (i == 0) |
| 29230 |
{ |
| 29231 |
error_at (loc, "expected directive name"); |
| 29232 |
goto error; |
| 29233 |
} |
| 29234 |
|
| 29235 |
const struct c_omp_directive *omp_directive |
| 29236 |
= c_omp_categorize_directive (directive[0], |
| 29237 |
directive[1], |
| 29238 |
directive[2]); |
| 29239 |
|
| 29240 |
if (omp_directive == NULL) |
| 29241 |
{ |
| 29242 |
for (int j = 0; j < i; j++) |
| 29243 |
c_parser_consume_token (parser); |
| 29244 |
c_parser_error (parser, "unknown directive name"); |
| 29245 |
goto error; |
| 29246 |
} |
| 29247 |
else |
| 29248 |
{ |
| 29249 |
int token_count = 0; |
| 29250 |
if (omp_directive->first) token_count++; |
| 29251 |
if (omp_directive->second) token_count++; |
| 29252 |
if (omp_directive->third) token_count++; |
| 29253 |
for (int j = 0; j < token_count; j++) |
| 29254 |
c_parser_consume_token (parser); |
| 29255 |
} |
| 29256 |
if (omp_directive->id == PRAGMA_OMP_METADIRECTIVE) |
| 29257 |
{ |
| 29258 |
c_parser_error (parser, |
| 29259 |
"metadirectives cannot be used as variants of a " |
| 29260 |
"%<metadirective%>"); |
| 29261 |
goto error; |
| 29262 |
} |
| 29263 |
if (omp_directive->kind == C_OMP_DIR_DECLARATIVE) |
| 29264 |
{ |
| 29265 |
sorry_at (loc, "declarative directive variants of a " |
| 29266 |
"%<metadirective%> are not supported"); |
| 29267 |
goto error; |
| 29268 |
} |
| 29269 |
if (omp_directive->kind == C_OMP_DIR_CONSTRUCT) |
| 29270 |
requires_body = true; |
| 29271 |
|
| 29272 |
if (!skip) |
| 29273 |
{ |
| 29274 |
c_token pragma_token; |
| 29275 |
pragma_token.type = CPP_PRAGMA; |
| 29276 |
pragma_token.location = loc; |
| 29277 |
pragma_token.pragma_kind = (enum pragma_kind) omp_directive->id; |
| 29278 |
|
| 29279 |
directives.safe_push (omp_directive); |
| 29280 |
directive_tokens.safe_push (pragma_token); |
| 29281 |
ctxs.safe_push (ctx); |
| 29282 |
} |
| 29283 |
|
| 29284 |
/* Read in tokens for the directive clauses. */ |
| 29285 |
int nesting_depth = 0; |
| 29286 |
while (1) |
| 29287 |
{ |
| 29288 |
c_token *token = c_parser_peek_token (parser); |
| 29289 |
switch (token->type) |
| 29290 |
{ |
| 29291 |
case CPP_EOF: |
| 29292 |
case CPP_PRAGMA_EOL: |
| 29293 |
break; |
| 29294 |
case CPP_OPEN_PAREN: |
| 29295 |
++nesting_depth; |
| 29296 |
goto add; |
| 29297 |
case CPP_CLOSE_PAREN: |
| 29298 |
if (nesting_depth-- == 0) |
| 29299 |
{ |
| 29300 |
c_parser_consume_token (parser); |
| 29301 |
break; |
| 29302 |
} |
| 29303 |
goto add; |
| 29304 |
default: |
| 29305 |
add: |
| 29306 |
if (!skip) |
| 29307 |
directive_tokens.safe_push (*token); |
| 29308 |
c_parser_consume_token (parser); |
| 29309 |
continue; |
| 29310 |
} |
| 29311 |
break; |
| 29312 |
} |
| 29313 |
|
| 29314 |
if (!skip) |
| 29315 |
{ |
| 29316 |
c_token eol_token; |
| 29317 |
memset (&eol_token, 0, sizeof (eol_token)); |
| 29318 |
eol_token.type = CPP_PRAGMA_EOL; |
| 29319 |
directive_tokens.safe_push (eol_token); |
| 29320 |
} |
| 29321 |
} |
| 29322 |
c_parser_skip_to_pragma_eol (parser); |
| 29323 |
|
| 29324 |
if (!default_seen) |
| 29325 |
{ |
| 29326 |
/* Add a default clause that evaluates to 'omp nothing'. */ |
| 29327 |
const struct c_omp_directive *omp_directive |
| 29328 |
= c_omp_categorize_directive ("nothing", NULL, NULL); |
| 29329 |
|
| 29330 |
c_token pragma_token; |
| 29331 |
pragma_token.type = CPP_PRAGMA; |
| 29332 |
pragma_token.location = UNKNOWN_LOCATION; |
| 29333 |
pragma_token.pragma_kind = PRAGMA_OMP_NOTHING; |
| 29334 |
|
| 29335 |
directives.safe_push (omp_directive); |
| 29336 |
directive_tokens.safe_push (pragma_token); |
| 29337 |
ctxs.safe_push (NULL_TREE); |
| 29338 |
|
| 29339 |
c_token eol_token; |
| 29340 |
memset (&eol_token, 0, sizeof (eol_token)); |
| 29341 |
eol_token.type = CPP_PRAGMA_EOL; |
| 29342 |
directive_tokens.safe_push (eol_token); |
| 29343 |
} |
| 29344 |
|
| 29345 |
if (requires_body) |
| 29346 |
analyze_metadirective_body (parser, body_tokens, body_labels); |
| 29347 |
|
| 29348 |
/* Process each candidate directive. */ |
| 29349 |
unsigned i; |
| 29350 |
tree ctx; |
| 29351 |
|
| 29352 |
FOR_EACH_VEC_ELT (ctxs, i, ctx) |
| 29353 |
{ |
| 29354 |
auto_vec<c_token> tokens; |
| 29355 |
|
| 29356 |
/* Add the directive tokens. */ |
| 29357 |
do |
| 29358 |
tokens.safe_push (directive_tokens [directive_token_idx++]); |
| 29359 |
while (tokens.last ().type != CPP_PRAGMA_EOL); |
| 29360 |
|
| 29361 |
/* Add the body tokens. */ |
| 29362 |
gcc_assert (requires_body || body_tokens.is_empty ()); |
| 29363 |
for (unsigned j = 0; j < body_tokens.length (); j++) |
| 29364 |
tokens.safe_push (body_tokens[j]); |
| 29365 |
|
| 29366 |
/* Make sure nothing tries to read past the end of the tokens. */ |
| 29367 |
c_token eof_token; |
| 29368 |
memset (&eof_token, 0, sizeof (eof_token)); |
| 29369 |
eof_token.type = CPP_EOF; |
| 29370 |
tokens.safe_push (eof_token); |
| 29371 |
tokens.safe_push (eof_token); |
| 29372 |
|
| 29373 |
unsigned int old_tokens_avail = parser->tokens_avail; |
| 29374 |
c_token *old_tokens = parser->tokens; |
| 29375 |
struct omp_attribute_pragma_state *old_in_omp_attribute_pragma |
| 29376 |
= parser->in_omp_attribute_pragma; |
| 29377 |
struct omp_metadirective_parse_data *old_state |
| 29378 |
= parser->omp_metadirective_state; |
| 29379 |
|
| 29380 |
struct omp_metadirective_parse_data new_state; |
| 29381 |
new_state.body_labels = &body_labels; |
| 29382 |
new_state.region_num = ++metadirective_region_count; |
| 29383 |
|
| 29384 |
parser->tokens = tokens.address (); |
| 29385 |
parser->tokens_avail = tokens.length (); |
| 29386 |
parser->in_omp_attribute_pragma = NULL; |
| 29387 |
parser->omp_metadirective_state = &new_state; |
| 29388 |
|
| 29389 |
int prev_errorcount = errorcount; |
| 29390 |
tree directive = c_begin_compound_stmt (true); |
| 29391 |
|
| 29392 |
c_parser_pragma (parser, pragma_compound, if_p, NULL_TREE); |
| 29393 |
directive = c_end_compound_stmt (pragma_loc, directive, true); |
| 29394 |
bool standalone_p |
| 29395 |
= directives[i]->kind == C_OMP_DIR_STANDALONE |
| 29396 |
|| directives[i]->kind == C_OMP_DIR_UTILITY; |
| 29397 |
if (standalone_p && requires_body) |
| 29398 |
{ |
| 29399 |
/* Parsing standalone directives will not consume the body |
| 29400 |
tokens, so do that here. */ |
| 29401 |
if (standalone_body == NULL_TREE) |
| 29402 |
{ |
| 29403 |
standalone_body = push_stmt_list (); |
| 29404 |
c_parser_statement (parser, if_p); |
| 29405 |
standalone_body = pop_stmt_list (standalone_body); |
| 29406 |
} |
| 29407 |
else |
| 29408 |
c_parser_skip_to_end_of_block_or_statement (parser, true); |
| 29409 |
} |
| 29410 |
|
| 29411 |
tree body = standalone_p ? standalone_body : NULL_TREE; |
| 29412 |
tree variant = make_omp_metadirective_variant (ctx, directive, body); |
| 29413 |
OMP_METADIRECTIVE_VARIANTS (ret) |
| 29414 |
= chainon (OMP_METADIRECTIVE_VARIANTS (ret), variant); |
| 29415 |
|
| 29416 |
/* Check that all valid tokens have been consumed if no parse errors |
| 29417 |
encountered. */ |
| 29418 |
if (errorcount == prev_errorcount) |
| 29419 |
{ |
| 29420 |
gcc_assert (parser->tokens_avail == 2); |
| 29421 |
gcc_assert (c_parser_next_token_is (parser, CPP_EOF)); |
| 29422 |
gcc_assert (c_parser_peek_2nd_token (parser)->type == CPP_EOF); |
| 29423 |
} |
| 29424 |
|
| 29425 |
parser->tokens = old_tokens; |
| 29426 |
parser->tokens_avail = old_tokens_avail; |
| 29427 |
parser->in_omp_attribute_pragma = old_in_omp_attribute_pragma; |
| 29428 |
parser->omp_metadirective_state = old_state; |
| 29429 |
} |
| 29430 |
|
| 29431 |
/* Try to resolve the metadirective early. */ |
| 29432 |
candidates = omp_early_resolve_metadirective (ret); |
| 29433 |
if (!candidates.is_empty ()) |
| 29434 |
ret = c_omp_expand_variant_construct (candidates); |
| 29435 |
|
| 29436 |
add_stmt (ret); |
| 29437 |
return; |
| 29438 |
|
| 29439 |
error: |
| 29440 |
/* Skip the metadirective pragma. Do not skip the metadirective body. */ |
| 29441 |
if (parser->in_pragma) |
| 29442 |
c_parser_skip_to_pragma_eol (parser, false); |
| 29443 |
} |
| 29444 |
|
| 29445 |
/* Main entry point to parsing most OpenMP pragmas. */ |
| 29446 |
|
| 29447 |
static void |
| 29448 |
c_parser_omp_construct (c_parser *parser, bool *if_p) |
| 29449 |
{ |
| 29450 |
enum pragma_kind p_kind; |
| 29451 |
location_t loc; |
| 29452 |
tree stmt; |
| 29453 |
char p_name[sizeof "#pragma omp teams distribute parallel for simd"]; |
| 29454 |
omp_clause_mask mask (0); |
| 29455 |
|
| 29456 |
loc = c_parser_peek_token (parser)->location; |
| 29457 |
p_kind = c_parser_peek_token (parser)->pragma_kind; |
| 29458 |
c_parser_consume_pragma (parser); |
| 29459 |
|
| 29460 |
switch (p_kind) |
| 29461 |
{ |
| 29462 |
case PRAGMA_OACC_ATOMIC: |
| 29463 |
c_parser_omp_atomic (loc, parser, true); |
| 29464 |
return; |
| 29465 |
case PRAGMA_OACC_CACHE: |
| 29466 |
strcpy (p_name, "#pragma acc"); |
| 29467 |
stmt = c_parser_oacc_cache (loc, parser); |
| 29468 |
break; |
| 29469 |
case PRAGMA_OACC_DATA: |
| 29470 |
stmt = c_parser_oacc_data (loc, parser, if_p); |
| 29471 |
break; |
| 29472 |
case PRAGMA_OACC_HOST_DATA: |
| 29473 |
stmt = c_parser_oacc_host_data (loc, parser, if_p); |
| 29474 |
break; |
| 29475 |
case PRAGMA_OACC_KERNELS: |
| 29476 |
case PRAGMA_OACC_PARALLEL: |
| 29477 |
case PRAGMA_OACC_SERIAL: |
| 29478 |
strcpy (p_name, "#pragma acc"); |
| 29479 |
stmt = c_parser_oacc_compute (loc, parser, p_kind, p_name, if_p); |
| 29480 |
break; |
| 29481 |
case PRAGMA_OACC_LOOP: |
| 29482 |
strcpy (p_name, "#pragma acc"); |
| 29483 |
stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p); |
| 29484 |
break; |
| 29485 |
case PRAGMA_OACC_WAIT: |
| 29486 |
strcpy (p_name, "#pragma wait"); |
| 29487 |
stmt = c_parser_oacc_wait (loc, parser, p_name); |
| 29488 |
break; |
| 29489 |
case PRAGMA_OMP_ATOMIC: |
| 29490 |
c_parser_omp_atomic (loc, parser, false); |
| 29491 |
return; |
| 29492 |
case PRAGMA_OMP_CRITICAL: |
| 29493 |
stmt = c_parser_omp_critical (loc, parser, if_p); |
| 29494 |
break; |
| 29495 |
case PRAGMA_OMP_DISTRIBUTE: |
| 29496 |
strcpy (p_name, "#pragma omp"); |
| 29497 |
stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p); |
| 29498 |
break; |
| 29499 |
case PRAGMA_OMP_FOR: |
| 29500 |
strcpy (p_name, "#pragma omp"); |
| 29501 |
stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p); |
| 29502 |
break; |
| 29503 |
case PRAGMA_OMP_LOOP: |
| 29504 |
strcpy (p_name, "#pragma omp"); |
| 29505 |
stmt = c_parser_omp_loop (loc, parser, p_name, mask, NULL, if_p); |
| 29506 |
break; |
| 29507 |
case PRAGMA_OMP_MASKED: |
| 29508 |
strcpy (p_name, "#pragma omp"); |
| 29509 |
stmt = c_parser_omp_masked (loc, parser, p_name, mask, NULL, if_p); |
| 29510 |
break; |
| 29511 |
case PRAGMA_OMP_MASTER: |
| 29512 |
strcpy (p_name, "#pragma omp"); |
| 29513 |
stmt = c_parser_omp_master (loc, parser, p_name, mask, NULL, if_p); |
| 29514 |
break; |
| 29515 |
case PRAGMA_OMP_PARALLEL: |
| 29516 |
strcpy (p_name, "#pragma omp"); |
| 29517 |
stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p); |
| 29518 |
break; |
| 29519 |
case PRAGMA_OMP_SCOPE: |
| 29520 |
stmt = c_parser_omp_scope (loc, parser, if_p); |
| 29521 |
break; |
| 29522 |
case PRAGMA_OMP_SECTIONS: |
| 29523 |
strcpy (p_name, "#pragma omp"); |
| 29524 |
stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL); |
| 29525 |
break; |
| 29526 |
case PRAGMA_OMP_SIMD: |
| 29527 |
strcpy (p_name, "#pragma omp"); |
| 29528 |
stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p); |
| 29529 |
break; |
| 29530 |
case PRAGMA_OMP_SINGLE: |
| 29531 |
stmt = c_parser_omp_single (loc, parser, if_p); |
| 29532 |
break; |
| 29533 |
case PRAGMA_OMP_TASK: |
| 29534 |
stmt = c_parser_omp_task (loc, parser, if_p); |
| 29535 |
break; |
| 29536 |
case PRAGMA_OMP_TASKGROUP: |
| 29537 |
stmt = c_parser_omp_taskgroup (loc, parser, if_p); |
| 29538 |
break; |
| 29539 |
case PRAGMA_OMP_TASKLOOP: |
| 29540 |
strcpy (p_name, "#pragma omp"); |
| 29541 |
stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p); |
| 29542 |
break; |
| 29543 |
case PRAGMA_OMP_TEAMS: |
| 29544 |
strcpy (p_name, "#pragma omp"); |
| 29545 |
stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p); |
| 29546 |
break; |
| 29547 |
case PRAGMA_OMP_ASSUME: |
| 29548 |
c_parser_omp_assume (parser, if_p); |
| 29549 |
return; |
| 29550 |
case PRAGMA_OMP_TILE: |
| 29551 |
stmt = c_parser_omp_tile (loc, parser, if_p); |
| 29552 |
break; |
| 29553 |
case PRAGMA_OMP_UNROLL: |
| 29554 |
stmt = c_parser_omp_unroll (loc, parser, if_p); |
| 29555 |
break; |
| 29556 |
case PRAGMA_OMP_DISPATCH: |
| 29557 |
stmt = c_parser_omp_dispatch (loc, parser); |
| 29558 |
break; |
| 29559 |
default: |
| 29560 |
gcc_unreachable (); |
| 29561 |
} |
| 29562 |
|
| 29563 |
if (stmt && stmt != error_mark_node) |
| 29564 |
gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION); |
| 29565 |
} |
| 29566 |
|
| 29567 |
|
| 29568 |
/* OpenMP 2.5: |
| 29569 |
# pragma omp threadprivate (variable-list) */ |
| 29570 |
|
| 29571 |
static void |
| 29572 |
c_parser_omp_threadprivate (c_parser *parser) |
| 29573 |
{ |
| 29574 |
tree vars, t; |
| 29575 |
location_t loc; |
| 29576 |
|
| 29577 |
c_parser_consume_pragma (parser); |
| 29578 |
vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
| 29579 |
|
| 29580 |
/* Mark every variable in VARS to be assigned thread local storage. */ |
| 29581 |
for (t = vars; t; t = TREE_CHAIN (t)) |
| 29582 |
{ |
| 29583 |
tree v = TREE_PURPOSE (t); |
| 29584 |
loc = EXPR_LOCATION (TREE_VALUE (t)); |
| 29585 |
|
| 29586 |
/* If V had already been marked threadprivate, it doesn't matter |
| 29587 |
whether it had been used prior to this point. */ |
| 29588 |
if (!VAR_P (v)) |
| 29589 |
error_at (loc, "%qD is not a variable", v); |
| 29590 |
else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) |
| 29591 |
error_at (loc, "%qE declared %<threadprivate%> after first use", v); |
| 29592 |
else if (! is_global_var (v)) |
| 29593 |
error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); |
| 29594 |
else if (TREE_TYPE (v) == error_mark_node) |
| 29595 |
; |
| 29596 |
else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) |
| 29597 |
error_at (loc, "%<threadprivate%> %qE has incomplete type", v); |
| 29598 |
else |
| 29599 |
{ |
| 29600 |
if (! DECL_THREAD_LOCAL_P (v)) |
| 29601 |
{ |
| 29602 |
set_decl_tls_model (v, decl_default_tls_model (v)); |
| 29603 |
/* If rtl has been already set for this var, call |
| 29604 |
make_decl_rtl once again, so that encode_section_info |
| 29605 |
has a chance to look at the new decl flags. */ |
| 29606 |
if (DECL_RTL_SET_P (v)) |
| 29607 |
make_decl_rtl (v); |
| 29608 |
} |
| 29609 |
C_DECL_THREADPRIVATE_P (v) = 1; |
| 29610 |
} |
| 29611 |
} |
| 29612 |
|
| 29613 |
c_parser_skip_to_pragma_eol (parser); |
| 29614 |
} |
| 29615 |
|
| 29616 |
/* Parse a transaction attribute (GCC Extension). |
| 29617 |
|
| 29618 |
transaction-attribute: |
| 29619 |
gnu-attributes |
| 29620 |
attribute-specifier |
| 29621 |
*/ |
| 29622 |
|
| 29623 |
static tree |
| 29624 |
c_parser_transaction_attributes (c_parser *parser) |
| 29625 |
{ |
| 29626 |
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 29627 |
return c_parser_gnu_attributes (parser); |
| 29628 |
|
| 29629 |
if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 29630 |
return NULL_TREE; |
| 29631 |
return c_parser_std_attribute_specifier (parser, true); |
| 29632 |
} |
| 29633 |
|
| 29634 |
/* Parse a __transaction_atomic or __transaction_relaxed statement |
| 29635 |
(GCC Extension). |
| 29636 |
|
| 29637 |
transaction-statement: |
| 29638 |
__transaction_atomic transaction-attribute[opt] compound-statement |
| 29639 |
__transaction_relaxed compound-statement |
| 29640 |
|
| 29641 |
Note that the only valid attribute is: "outer". |
| 29642 |
*/ |
| 29643 |
|
| 29644 |
static tree |
| 29645 |
c_parser_transaction (c_parser *parser, enum rid keyword) |
| 29646 |
{ |
| 29647 |
unsigned int old_in = parser->in_transaction; |
| 29648 |
unsigned int this_in = 1, new_in; |
| 29649 |
location_t loc = c_parser_peek_token (parser)->location; |
| 29650 |
tree stmt, attrs; |
| 29651 |
|
| 29652 |
gcc_assert ((keyword == RID_TRANSACTION_ATOMIC |
| 29653 |
|| keyword == RID_TRANSACTION_RELAXED) |
| 29654 |
&& c_parser_next_token_is_keyword (parser, keyword)); |
| 29655 |
c_parser_consume_token (parser); |
| 29656 |
|
| 29657 |
if (keyword == RID_TRANSACTION_RELAXED) |
| 29658 |
this_in |= TM_STMT_ATTR_RELAXED; |
| 29659 |
else |
| 29660 |
{ |
| 29661 |
attrs = c_parser_transaction_attributes (parser); |
| 29662 |
if (attrs) |
| 29663 |
this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER); |
| 29664 |
} |
| 29665 |
|
| 29666 |
/* Keep track if we're in the lexical scope of an outer transaction. */ |
| 29667 |
new_in = this_in | (old_in & TM_STMT_ATTR_OUTER); |
| 29668 |
|
| 29669 |
parser->in_transaction = new_in; |
| 29670 |
stmt = c_parser_compound_statement (parser); |
| 29671 |
parser->in_transaction = old_in; |
| 29672 |
|
| 29673 |
if (flag_tm) |
| 29674 |
stmt = c_finish_transaction (loc, stmt, this_in); |
| 29675 |
else |
| 29676 |
error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? |
| 29677 |
"%<__transaction_atomic%> without transactional memory support enabled" |
| 29678 |
: "%<__transaction_relaxed %> " |
| 29679 |
"without transactional memory support enabled")); |
| 29680 |
|
| 29681 |
return stmt; |
| 29682 |
} |
| 29683 |
|
| 29684 |
/* Parse a __transaction_atomic or __transaction_relaxed expression |
| 29685 |
(GCC Extension). |
| 29686 |
|
| 29687 |
transaction-expression: |
| 29688 |
__transaction_atomic ( expression ) |
| 29689 |
__transaction_relaxed ( expression ) |
| 29690 |
*/ |
| 29691 |
|
| 29692 |
static struct c_expr |
| 29693 |
c_parser_transaction_expression (c_parser *parser, enum rid keyword) |
| 29694 |
{ |
| 29695 |
struct c_expr ret; |
| 29696 |
unsigned int old_in = parser->in_transaction; |
| 29697 |
unsigned int this_in = 1; |
| 29698 |
location_t loc = c_parser_peek_token (parser)->location; |
| 29699 |
tree attrs; |
| 29700 |
|
| 29701 |
gcc_assert ((keyword == RID_TRANSACTION_ATOMIC |
| 29702 |
|| keyword == RID_TRANSACTION_RELAXED) |
| 29703 |
&& c_parser_next_token_is_keyword (parser, keyword)); |
| 29704 |
c_parser_consume_token (parser); |
| 29705 |
|
| 29706 |
if (keyword == RID_TRANSACTION_RELAXED) |
| 29707 |
this_in |= TM_STMT_ATTR_RELAXED; |
| 29708 |
else |
| 29709 |
{ |
| 29710 |
attrs = c_parser_transaction_attributes (parser); |
| 29711 |
if (attrs) |
| 29712 |
this_in |= parse_tm_stmt_attr (attrs, 0); |
| 29713 |
} |
| 29714 |
|
| 29715 |
parser->in_transaction = this_in; |
| 29716 |
matching_parens parens; |
| 29717 |
if (parens.require_open (parser)) |
| 29718 |
{ |
| 29719 |
tree expr = c_parser_expression (parser).value; |
| 29720 |
ret.original_type = TREE_TYPE (expr); |
| 29721 |
ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr); |
| 29722 |
if (this_in & TM_STMT_ATTR_RELAXED) |
| 29723 |
TRANSACTION_EXPR_RELAXED (ret.value) = 1; |
| 29724 |
SET_EXPR_LOCATION (ret.value, loc); |
| 29725 |
ret.original_code = TRANSACTION_EXPR; |
| 29726 |
ret.m_decimal = 0; |
| 29727 |
if (!parens.require_close (parser)) |
| 29728 |
{ |
| 29729 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 29730 |
goto error; |
| 29731 |
} |
| 29732 |
} |
| 29733 |
else |
| 29734 |
{ |
| 29735 |
error: |
| 29736 |
ret.set_error (); |
| 29737 |
ret.original_code = ERROR_MARK; |
| 29738 |
ret.original_type = NULL; |
| 29739 |
} |
| 29740 |
parser->in_transaction = old_in; |
| 29741 |
|
| 29742 |
if (!flag_tm) |
| 29743 |
error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? |
| 29744 |
"%<__transaction_atomic%> without transactional memory support enabled" |
| 29745 |
: "%<__transaction_relaxed %> " |
| 29746 |
"without transactional memory support enabled")); |
| 29747 |
|
| 29748 |
set_c_expr_source_range (&ret, loc, loc); |
| 29749 |
|
| 29750 |
return ret; |
| 29751 |
} |
| 29752 |
|
| 29753 |
/* Parse a __transaction_cancel statement (GCC Extension). |
| 29754 |
|
| 29755 |
transaction-cancel-statement: |
| 29756 |
__transaction_cancel transaction-attribute[opt] ; |
| 29757 |
|
| 29758 |
Note that the only valid attribute is "outer". |
| 29759 |
*/ |
| 29760 |
|
| 29761 |
static tree |
| 29762 |
c_parser_transaction_cancel (c_parser *parser) |
| 29763 |
{ |
| 29764 |
location_t loc = c_parser_peek_token (parser)->location; |
| 29765 |
tree attrs; |
| 29766 |
bool is_outer = false; |
| 29767 |
|
| 29768 |
gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL)); |
| 29769 |
c_parser_consume_token (parser); |
| 29770 |
|
| 29771 |
attrs = c_parser_transaction_attributes (parser); |
| 29772 |
if (attrs) |
| 29773 |
is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0); |
| 29774 |
|
| 29775 |
if (!flag_tm) |
| 29776 |
{ |
| 29777 |
error_at (loc, "%<__transaction_cancel%> without " |
| 29778 |
"transactional memory support enabled"); |
| 29779 |
goto ret_error; |
| 29780 |
} |
| 29781 |
else if (parser->in_transaction & TM_STMT_ATTR_RELAXED) |
| 29782 |
{ |
| 29783 |
error_at (loc, "%<__transaction_cancel%> within a " |
| 29784 |
"%<__transaction_relaxed%>"); |
| 29785 |
goto ret_error; |
| 29786 |
} |
| 29787 |
else if (is_outer) |
| 29788 |
{ |
| 29789 |
if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0 |
| 29790 |
&& !is_tm_may_cancel_outer (current_function_decl)) |
| 29791 |
{ |
| 29792 |
error_at (loc, "outer %<__transaction_cancel%> not " |
| 29793 |
"within outer %<__transaction_atomic%> or " |
| 29794 |
"a %<transaction_may_cancel_outer%> function"); |
| 29795 |
goto ret_error; |
| 29796 |
} |
| 29797 |
} |
| 29798 |
else if (parser->in_transaction == 0) |
| 29799 |
{ |
| 29800 |
error_at (loc, "%<__transaction_cancel%> not within " |
| 29801 |
"%<__transaction_atomic%>"); |
| 29802 |
goto ret_error; |
| 29803 |
} |
| 29804 |
|
| 29805 |
return add_stmt (build_tm_abort_call (loc, is_outer)); |
| 29806 |
|
| 29807 |
ret_error: |
| 29808 |
return build1 (NOP_EXPR, void_type_node, error_mark_node); |
| 29809 |
} |
| 29810 |
|
| 29811 |
/* Parse a single source file. */ |
| 29812 |
|
| 29813 |
void |
| 29814 |
c_parse_file (void) |
| 29815 |
{ |
| 29816 |
/* Use local storage to begin. If the first token is a pragma, parse it. |
| 29817 |
If it is #pragma GCC pch_preprocess, then this will load a PCH file |
| 29818 |
which will cause garbage collection. */ |
| 29819 |
c_parser tparser; |
| 29820 |
|
| 29821 |
memset (&tparser, 0, sizeof tparser); |
| 29822 |
tparser.translate_strings_p = true; |
| 29823 |
tparser.tokens = &tparser.tokens_buf[0]; |
| 29824 |
the_parser = &tparser; |
| 29825 |
|
| 29826 |
if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) |
| 29827 |
c_parser_pragma_pch_preprocess (&tparser); |
| 29828 |
else |
| 29829 |
c_common_no_more_pch (); |
| 29830 |
|
| 29831 |
the_parser = ggc_alloc<c_parser> (); |
| 29832 |
*the_parser = tparser; |
| 29833 |
if (tparser.tokens == &tparser.tokens_buf[0]) |
| 29834 |
the_parser->tokens = &the_parser->tokens_buf[0]; |
| 29835 |
|
| 29836 |
/* Initialize EH, if we've been told to do so. */ |
| 29837 |
if (flag_exceptions) |
| 29838 |
using_eh_for_cleanups (); |
| 29839 |
|
| 29840 |
c_parser_translation_unit (the_parser); |
| 29841 |
the_parser = NULL; |
| 29842 |
} |
| 29843 |
|
| 29844 |
void |
| 29845 |
c_init_preprocess (void) |
| 29846 |
{ |
| 29847 |
/* Create a parser for use by pragma_lex during preprocessing. */ |
| 29848 |
the_parser = ggc_alloc<c_parser> (); |
| 29849 |
memset (the_parser, 0, sizeof (c_parser)); |
| 29850 |
the_parser->tokens = &the_parser->tokens_buf[0]; |
| 29851 |
} |
| 29852 |
|
| 29853 |
/* Parse the body of a function declaration marked with "__RTL". |
| 29854 |
|
| 29855 |
The RTL parser works on the level of characters read from a |
| 29856 |
FILE *, whereas c_parser works at the level of tokens. |
| 29857 |
Square this circle by consuming all of the tokens up to and |
| 29858 |
including the closing brace, recording the start/end of the RTL |
| 29859 |
fragment, and reopening the file and re-reading the relevant |
| 29860 |
lines within the RTL parser. |
| 29861 |
|
| 29862 |
This requires the opening and closing braces of the C function |
| 29863 |
to be on separate lines from the RTL they wrap. |
| 29864 |
|
| 29865 |
Take ownership of START_WITH_PASS, if non-NULL. */ |
| 29866 |
|
| 29867 |
location_t |
| 29868 |
c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass) |
| 29869 |
{ |
| 29870 |
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 29871 |
{ |
| 29872 |
free (start_with_pass); |
| 29873 |
return c_parser_peek_token (parser)->location; |
| 29874 |
} |
| 29875 |
|
| 29876 |
location_t start_loc = c_parser_peek_token (parser)->location; |
| 29877 |
|
| 29878 |
/* Consume all tokens, up to the closing brace, handling |
| 29879 |
matching pairs of braces in the rtl dump. */ |
| 29880 |
int num_open_braces = 1; |
| 29881 |
while (1) |
| 29882 |
{ |
| 29883 |
switch (c_parser_peek_token (parser)->type) |
| 29884 |
{ |
| 29885 |
case CPP_OPEN_BRACE: |
| 29886 |
num_open_braces++; |
| 29887 |
break; |
| 29888 |
case CPP_CLOSE_BRACE: |
| 29889 |
if (--num_open_braces == 0) |
| 29890 |
goto found_closing_brace; |
| 29891 |
break; |
| 29892 |
case CPP_EOF: |
| 29893 |
error_at (start_loc, "no closing brace"); |
| 29894 |
free (start_with_pass); |
| 29895 |
return c_parser_peek_token (parser)->location; |
| 29896 |
default: |
| 29897 |
break; |
| 29898 |
} |
| 29899 |
c_parser_consume_token (parser); |
| 29900 |
} |
| 29901 |
|
| 29902 |
found_closing_brace: |
| 29903 |
/* At the closing brace; record its location. */ |
| 29904 |
location_t end_loc = c_parser_peek_token (parser)->location; |
| 29905 |
|
| 29906 |
/* Consume the closing brace. */ |
| 29907 |
c_parser_consume_token (parser); |
| 29908 |
|
| 29909 |
/* Invoke the RTL parser. */ |
| 29910 |
if (!read_rtl_function_body_from_file_range (start_loc, end_loc)) |
| 29911 |
{ |
| 29912 |
free (start_with_pass); |
| 29913 |
return end_loc; |
| 29914 |
} |
| 29915 |
|
| 29916 |
/* Run the backend on the cfun created above, transferring ownership of |
| 29917 |
START_WITH_PASS. */ |
| 29918 |
run_rtl_passes (start_with_pass); |
| 29919 |
return end_loc; |
| 29920 |
} |
| 29921 |
|
| 29922 |
#include "gt-c-c-parser.h" |