Line data Source code
1 : /* Parser for C and Objective-C.
2 :
3 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
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 217303018 : set_c_expr_source_range (c_expr *expr,
92 : location_t start, location_t finish)
93 : {
94 217303018 : expr->src_range.m_start = start;
95 217303018 : expr->src_range.m_finish = finish;
96 217303018 : if (expr->value)
97 217302922 : set_source_range (expr->value, start, finish);
98 217303018 : }
99 :
100 : void
101 238693050 : set_c_expr_source_range (c_expr *expr,
102 : source_range src_range)
103 : {
104 238693050 : expr->src_range = src_range;
105 238693050 : if (expr->value)
106 238693045 : set_source_range (expr->value, src_range);
107 238693050 : }
108 :
109 :
110 : /* Initialization routine for this file. */
111 :
112 : void
113 114432 : c_parse_init (void)
114 : {
115 : /* The only initialization required is of the reserved word
116 : identifiers. */
117 114432 : unsigned int i;
118 114432 : tree id;
119 114432 : 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 114432 : gcc_assert (RID_MAX <= 255);
124 :
125 114432 : mask |= D_CXXONLY;
126 114432 : if (!flag_isoc99)
127 6972 : mask |= D_C99;
128 114432 : if (!flag_isoc23)
129 13260 : mask |= D_C23;
130 114432 : if (flag_no_asm)
131 : {
132 6355 : mask |= D_ASM | D_EXT;
133 6355 : if (!flag_isoc99)
134 4021 : mask |= D_EXT89;
135 6355 : if (!flag_isoc23)
136 5168 : mask |= D_EXT11;
137 : }
138 114432 : if (!c_dialect_objc ())
139 114432 : mask |= D_OBJC | D_CXX_OBJC;
140 :
141 114432 : ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
142 27005952 : 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 26891520 : if (c_common_reswords[i].disable & mask)
147 : {
148 10257457 : if (warn_cxx_compat
149 116469 : && (c_common_reswords[i].disable & D_CXXWARN))
150 : {
151 55815 : id = get_identifier (c_common_reswords[i].word);
152 55815 : C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
153 55815 : C_IS_RESERVED_WORD (id) = 1;
154 : }
155 10257457 : continue;
156 : }
157 :
158 16634063 : id = get_identifier (c_common_reswords[i].word);
159 16634063 : C_SET_RID_CODE (id, c_common_reswords[i].rid);
160 16634063 : C_IS_RESERVED_WORD (id) = 1;
161 16634063 : ridpointers [(int) c_common_reswords[i].rid] = id;
162 : }
163 :
164 228864 : for (i = 0; i < NUM_INT_N_ENTS; i++)
165 : {
166 : /* We always create the symbols but they aren't always supported. */
167 114432 : char name[50];
168 114432 : sprintf (name, "__int%d", int_n_data[i].bitsize);
169 114432 : id = get_identifier (name);
170 114432 : C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
171 114432 : C_IS_RESERVED_WORD (id) = 1;
172 :
173 114432 : sprintf (name, "__int%d__", int_n_data[i].bitsize);
174 114432 : id = get_identifier (name);
175 114432 : C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
176 114432 : C_IS_RESERVED_WORD (id) = 1;
177 : }
178 :
179 114432 : if (flag_openmp)
180 : {
181 2424 : id = get_identifier ("omp_all_memory");
182 2424 : C_SET_RID_CODE (id, RID_OMP_ALL_MEMORY);
183 2424 : C_IS_RESERVED_WORD (id) = 1;
184 2424 : ridpointers [RID_OMP_ALL_MEMORY] = id;
185 : }
186 114432 : }
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 error : 1;
209 : /* True if we're processing a pragma, and shouldn't automatically
210 : consume CPP_PRAGMA_EOL. */
211 : bool in_pragma : 1;
212 : /* True if we're parsing the outermost block of an if statement. */
213 : bool 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 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 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 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 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 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 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 seen_string_literal : 1;
252 :
253 : /* TRUE if omp::directive, omp::decl or omp::sequence attributes may not
254 : appear. */
255 : bool 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 : /* Holds data for deferred lookup of base functions for OpenMP
290 : "begin declare variant", which are permitted to be declared after
291 : the variant. */
292 : struct GTY(()) omp_begin_declare_variant_map_entry {
293 : tree variant; /* The variant decl. */
294 : tree id; /* Name of base function. */
295 : tree ctx; /* The context selector associated with the variant. */
296 : };
297 : vec<omp_begin_declare_variant_map_entry, va_gc> *omp_begin_declare_variant_map;
298 :
299 : static tree omp_start_variant_function (c_declarator *, tree);
300 : static void omp_finish_variant_function (tree, tree, tree);
301 :
302 : /* Return a pointer to the Nth token in PARSERs tokens_buf. */
303 :
304 : c_token *
305 338 : c_parser_tokens_buf (c_parser *parser, unsigned n)
306 : {
307 338 : return &parser->tokens_buf[n];
308 : }
309 :
310 : /* Return the error state of PARSER. */
311 :
312 : bool
313 13579 : c_parser_error (c_parser *parser)
314 : {
315 13579 : return parser->error;
316 : }
317 :
318 : /* Set the error state of PARSER to ERR. */
319 :
320 : void
321 0 : c_parser_set_error (c_parser *parser, bool err)
322 : {
323 0 : parser->error = err;
324 0 : }
325 :
326 :
327 : /* The actual parser and external interface. ??? Does this need to be
328 : garbage-collected? */
329 :
330 : static GTY (()) c_parser *the_parser;
331 :
332 : /* Read in and lex a single token, storing it in *TOKEN. If RAW,
333 : context-sensitive postprocessing of the token is not done. */
334 :
335 : static void
336 2402633843 : c_lex_one_token (c_parser *parser, c_token *token, bool raw = false)
337 : {
338 2402633843 : timevar_push (TV_LEX);
339 :
340 2402633843 : if (raw || vec_safe_length (parser->raw_tokens) == 0)
341 : {
342 2402527622 : token->type = c_lex_with_flags (&token->value, &token->location,
343 : &token->flags,
344 2402527622 : (parser->lex_joined_string
345 : ? 0 : C_LEX_STRING_NO_JOIN));
346 2402527472 : token->id_kind = C_ID_NONE;
347 2402527472 : token->keyword = RID_MAX;
348 2402527472 : token->pragma_kind = PRAGMA_NONE;
349 : }
350 : else
351 : {
352 : /* Use a token previously lexed as a raw look-ahead token, and
353 : complete the processing on it. */
354 106221 : *token = (*parser->raw_tokens)[parser->raw_tokens_used];
355 106221 : ++parser->raw_tokens_used;
356 106221 : if (parser->raw_tokens_used == vec_safe_length (parser->raw_tokens))
357 : {
358 16154 : vec_free (parser->raw_tokens);
359 16154 : parser->raw_tokens_used = 0;
360 : }
361 : }
362 :
363 2402633693 : if (raw)
364 106221 : goto out;
365 :
366 2402527472 : switch (token->type)
367 : {
368 1080911201 : case CPP_NAME:
369 1080911201 : {
370 1080911201 : tree decl;
371 :
372 1080911201 : bool objc_force_identifier = parser->objc_need_raw_identifier;
373 1080911201 : if (c_dialect_objc ())
374 0 : parser->objc_need_raw_identifier = false;
375 :
376 1080911201 : if (C_IS_RESERVED_WORD (token->value))
377 : {
378 300488068 : enum rid rid_code = C_RID_CODE (token->value);
379 :
380 300488068 : if (rid_code == RID_CXX_COMPAT_WARN)
381 : {
382 35 : warning_at (token->location,
383 35 : OPT_Wc___compat,
384 : "identifier %qE conflicts with C++ keyword",
385 : token->value);
386 : }
387 300488033 : else if (rid_code >= RID_FIRST_ADDR_SPACE
388 300488033 : && rid_code <= RID_LAST_ADDR_SPACE)
389 : {
390 178 : addr_space_t as;
391 178 : as = (addr_space_t) (rid_code - RID_FIRST_ADDR_SPACE);
392 178 : targetm.addr_space.diagnose_usage (as, token->location);
393 178 : token->id_kind = C_ID_ADDRSPACE;
394 178 : token->keyword = rid_code;
395 178 : break;
396 : }
397 300487855 : else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
398 : {
399 : /* We found an Objective-C "pq" keyword (in, out,
400 : inout, bycopy, byref, oneway). They need special
401 : care because the interpretation depends on the
402 : context. */
403 0 : if (parser->objc_pq_context)
404 : {
405 0 : token->type = CPP_KEYWORD;
406 0 : token->keyword = rid_code;
407 0 : break;
408 : }
409 0 : else if (parser->objc_could_be_foreach_context
410 0 : && rid_code == RID_IN)
411 : {
412 : /* We are in Objective-C, inside a (potential)
413 : foreach context (which means after having
414 : parsed 'for (', but before having parsed ';'),
415 : and we found 'in'. We consider it the keyword
416 : which terminates the declaration at the
417 : beginning of a foreach-statement. Note that
418 : this means you can't use 'in' for anything else
419 : in that context; in particular, in Objective-C
420 : you can't use 'in' as the name of the running
421 : variable in a C for loop. We could potentially
422 : try to add code here to disambiguate, but it
423 : seems a reasonable limitation. */
424 0 : token->type = CPP_KEYWORD;
425 0 : token->keyword = rid_code;
426 0 : break;
427 : }
428 : /* Else, "pq" keywords outside of the "pq" context are
429 : not keywords, and we fall through to the code for
430 : normal tokens. */
431 : }
432 300487855 : else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
433 : {
434 : /* We found an Objective-C "property attribute"
435 : keyword (getter, setter, readonly, etc). These are
436 : only valid in the property context. */
437 0 : if (parser->objc_property_attr_context)
438 : {
439 0 : token->type = CPP_KEYWORD;
440 0 : token->keyword = rid_code;
441 0 : break;
442 : }
443 : /* Else they are not special keywords.
444 : */
445 : }
446 300487855 : else if (c_dialect_objc ()
447 0 : && (OBJC_IS_AT_KEYWORD (rid_code)
448 : || OBJC_IS_CXX_KEYWORD (rid_code)))
449 : {
450 : /* We found one of the Objective-C "@" keywords (defs,
451 : selector, synchronized, etc) or one of the
452 : Objective-C "cxx" keywords (class, private,
453 : protected, public, try, catch, throw) without a
454 : preceding '@' sign. Do nothing and fall through to
455 : the code for normal tokens (in C++ we would still
456 : consider the CXX ones keywords, but not in C). */
457 : ;
458 : }
459 : else
460 : {
461 300487855 : token->type = CPP_KEYWORD;
462 300487855 : token->keyword = rid_code;
463 300487855 : break;
464 : }
465 : }
466 :
467 780423168 : decl = lookup_name (token->value);
468 780423168 : if (decl)
469 : {
470 436737179 : if (TREE_CODE (decl) == TYPE_DECL)
471 : {
472 254673720 : token->id_kind = C_ID_TYPENAME;
473 254673720 : break;
474 : }
475 : }
476 343685989 : else if (c_dialect_objc ())
477 : {
478 0 : tree objc_interface_decl = objc_is_class_name (token->value);
479 : /* Objective-C class names are in the same namespace as
480 : variables and typedefs, and hence are shadowed by local
481 : declarations. */
482 0 : if (objc_interface_decl
483 0 : && (!objc_force_identifier || global_bindings_p ()))
484 : {
485 0 : token->value = objc_interface_decl;
486 0 : token->id_kind = C_ID_CLASSNAME;
487 0 : break;
488 : }
489 : }
490 525749448 : token->id_kind = C_ID_ID;
491 : }
492 525749448 : break;
493 0 : case CPP_AT_NAME:
494 : /* This only happens in Objective-C; it must be a keyword. */
495 0 : token->type = CPP_KEYWORD;
496 0 : switch (C_RID_CODE (token->value))
497 : {
498 : /* Replace 'class' with '@class', 'private' with '@private',
499 : etc. This prevents confusion with the C++ keyword
500 : 'class', and makes the tokens consistent with other
501 : Objective-C 'AT' keywords. For example '@class' is
502 : reported as RID_AT_CLASS which is consistent with
503 : '@synchronized', which is reported as
504 : RID_AT_SYNCHRONIZED.
505 : */
506 0 : case RID_CLASS: token->keyword = RID_AT_CLASS; break;
507 0 : case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
508 0 : case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
509 0 : case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
510 0 : case RID_THROW: token->keyword = RID_AT_THROW; break;
511 0 : case RID_TRY: token->keyword = RID_AT_TRY; break;
512 0 : case RID_CATCH: token->keyword = RID_AT_CATCH; break;
513 0 : case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break;
514 0 : default: token->keyword = C_RID_CODE (token->value);
515 : }
516 : break;
517 724896384 : case CPP_COLON:
518 724896384 : case CPP_COMMA:
519 724896384 : case CPP_CLOSE_PAREN:
520 724896384 : case CPP_SEMICOLON:
521 : /* These tokens may affect the interpretation of any identifiers
522 : following, if doing Objective-C. */
523 724896384 : if (c_dialect_objc ())
524 0 : parser->objc_need_raw_identifier = false;
525 : break;
526 1979091 : case CPP_PRAGMA:
527 : /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
528 1979091 : token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
529 1979091 : token->value = NULL;
530 1979091 : break;
531 : default:
532 : break;
533 : }
534 2402633693 : out:
535 2402633693 : timevar_pop (TV_LEX);
536 2402633693 : }
537 :
538 : /* Return a pointer to the next token from PARSER, reading it in if
539 : necessary. */
540 :
541 : c_token *
542 17909451268 : c_parser_peek_token (c_parser *parser)
543 : {
544 17909451268 : if (parser->tokens_avail == 0)
545 : {
546 1968567458 : c_lex_one_token (parser, &parser->tokens[0]);
547 1968567308 : parser->tokens_avail = 1;
548 : }
549 17909451118 : return &parser->tokens[0];
550 : }
551 :
552 : /* Return a pointer to the next-but-one token from PARSER, reading it
553 : in if necessary. The next token is already read in. */
554 :
555 : c_token *
556 164678558 : c_parser_peek_2nd_token (c_parser *parser)
557 : {
558 164678558 : if (parser->tokens_avail >= 2)
559 9212237 : return &parser->tokens[1];
560 155466321 : gcc_assert (parser->tokens_avail == 1);
561 155466321 : gcc_assert (parser->tokens[0].type != CPP_EOF);
562 155466321 : gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
563 155466321 : c_lex_one_token (parser, &parser->tokens[1]);
564 155466321 : parser->tokens_avail = 2;
565 155466321 : return &parser->tokens[1];
566 : }
567 :
568 : /* Return a pointer to the Nth token from PARSER, reading it
569 : in if necessary. The N-1th token is already read in. */
570 :
571 : c_token *
572 1334644938 : c_parser_peek_nth_token (c_parser *parser, unsigned int n)
573 : {
574 : /* N is 1-based, not zero-based. */
575 1334644938 : gcc_assert (n > 0);
576 :
577 1334644938 : if (parser->tokens_avail >= n)
578 1056151095 : return &parser->tokens[n - 1];
579 278493843 : gcc_assert (parser->tokens_avail == n - 1);
580 278493843 : c_lex_one_token (parser, &parser->tokens[n - 1]);
581 278493843 : parser->tokens_avail = n;
582 278493843 : return &parser->tokens[n - 1];
583 : }
584 :
585 : /* Return a pointer to the Nth token from PARSER, reading it in as a
586 : raw look-ahead token if necessary. The N-1th token is already read
587 : in. Raw look-ahead tokens remain available for when the non-raw
588 : functions above are called. */
589 :
590 : c_token *
591 143108 : c_parser_peek_nth_token_raw (c_parser *parser, unsigned int n)
592 : {
593 : /* N is 1-based, not zero-based. */
594 143108 : gcc_assert (n > 0);
595 :
596 143108 : if (parser->tokens_avail >= n)
597 10590 : return &parser->tokens[n - 1];
598 132518 : unsigned int raw_len = vec_safe_length (parser->raw_tokens);
599 132518 : unsigned int raw_avail
600 132518 : = parser->tokens_avail + raw_len - parser->raw_tokens_used;
601 132518 : gcc_assert (raw_avail >= n - 1);
602 132518 : if (raw_avail >= n)
603 26297 : return &(*parser->raw_tokens)[parser->raw_tokens_used
604 26297 : + n - 1 - parser->tokens_avail];
605 106221 : vec_safe_reserve (parser->raw_tokens, 1);
606 106221 : parser->raw_tokens->quick_grow (raw_len + 1);
607 106221 : c_lex_one_token (parser, &(*parser->raw_tokens)[raw_len], true);
608 106221 : return &(*parser->raw_tokens)[raw_len];
609 : }
610 :
611 : bool
612 46299220 : c_keyword_starts_typename (enum rid keyword)
613 : {
614 46299220 : switch (keyword)
615 : {
616 : case RID_UNSIGNED:
617 : case RID_LONG:
618 : case RID_SHORT:
619 : case RID_SIGNED:
620 : case RID_COMPLEX:
621 : case RID_INT:
622 : case RID_CHAR:
623 : case RID_FLOAT:
624 : case RID_DOUBLE:
625 : case RID_VOID:
626 : case RID_DFLOAT32:
627 : case RID_DFLOAT64:
628 : case RID_DFLOAT128:
629 : case RID_DFLOAT64X:
630 : CASE_RID_FLOATN_NX:
631 : case RID_BOOL:
632 : case RID_BITINT:
633 : case RID_ENUM:
634 : case RID_STRUCT:
635 : case RID_UNION:
636 : case RID_TYPEOF:
637 : case RID_TYPEOF_UNQUAL:
638 : case RID_CONST:
639 : case RID_ATOMIC:
640 : case RID_VOLATILE:
641 : case RID_RESTRICT:
642 : case RID_ATTRIBUTE:
643 : case RID_FRACT:
644 : case RID_ACCUM:
645 : case RID_SAT:
646 : case RID_AUTO_TYPE:
647 : case RID_ALIGNAS:
648 : return true;
649 37963769 : default:
650 37963769 : if (keyword >= RID_FIRST_INT_N
651 : && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
652 585 : && int_n_enabled_p[keyword - RID_FIRST_INT_N])
653 : return true;
654 : return false;
655 : }
656 : }
657 :
658 : /* Return true if TOKEN can start a type name,
659 : false otherwise. */
660 : bool
661 465443787 : c_token_starts_typename (c_token *token)
662 : {
663 465443787 : switch (token->type)
664 : {
665 411928062 : case CPP_NAME:
666 411928062 : switch (token->id_kind)
667 : {
668 : case C_ID_ID:
669 : return false;
670 : case C_ID_ADDRSPACE:
671 : return true;
672 : case C_ID_TYPENAME:
673 : return true;
674 0 : case C_ID_CLASSNAME:
675 0 : gcc_assert (c_dialect_objc ());
676 : return true;
677 0 : default:
678 0 : gcc_unreachable ();
679 : }
680 46244465 : case CPP_KEYWORD:
681 46244465 : return c_keyword_starts_typename (token->keyword);
682 0 : case CPP_LESS:
683 0 : if (c_dialect_objc ())
684 : return true;
685 : return false;
686 : default:
687 : return false;
688 : }
689 : }
690 :
691 : /* Return true if the next token from PARSER, starting from token N, can start
692 : a type name, false otherwise. LA specifies how to do lookahead in order to
693 : detect unknown type names. If unsure, pick CLA_PREFER_ID. */
694 :
695 : static inline bool
696 330846550 : c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la,
697 : unsigned int n = 1)
698 : {
699 330846550 : c_token *token = c_parser_peek_nth_token (parser, n);
700 330846550 : if (c_token_starts_typename (token))
701 : return true;
702 :
703 : /* Try a bit harder to detect an unknown typename. */
704 72288097 : if (la != cla_prefer_id
705 45961087 : && token->type == CPP_NAME
706 6725915 : && token->id_kind == C_ID_ID
707 :
708 : /* Do not try too hard when we could have "object in array". */
709 6725915 : && !parser->objc_could_be_foreach_context
710 :
711 6725915 : && (la == cla_prefer_type
712 6725822 : || c_parser_peek_nth_token (parser, n + 1)->type == CPP_NAME
713 6725740 : || c_parser_peek_nth_token (parser, n + 1)->type == CPP_MULT)
714 :
715 : /* Only unknown identifiers. */
716 72289538 : && !lookup_name (token->value))
717 193 : return true;
718 :
719 : return false;
720 : }
721 :
722 : /* Return true if TOKEN, after an open parenthesis, can start a
723 : compound literal (either a storage class specifier allowed in that
724 : context, or a type name), false otherwise. */
725 : static bool
726 134593109 : c_token_starts_compound_literal (c_token *token)
727 : {
728 134593109 : switch (token->type)
729 : {
730 4678853 : case CPP_KEYWORD:
731 4678853 : switch (token->keyword)
732 : {
733 : case RID_CONSTEXPR:
734 : case RID_REGISTER:
735 : case RID_STATIC:
736 : case RID_THREAD:
737 : return true;
738 : default:
739 : break;
740 : }
741 : /* Fall through. */
742 134592799 : default:
743 134592799 : return c_token_starts_typename (token);
744 : }
745 : }
746 :
747 : /* Return true if TOKEN is a type qualifier, false otherwise. */
748 : static bool
749 452550441 : c_token_is_qualifier (c_token *token)
750 : {
751 452550441 : switch (token->type)
752 : {
753 448612337 : case CPP_NAME:
754 448612337 : switch (token->id_kind)
755 : {
756 : case C_ID_ADDRSPACE:
757 : return true;
758 : default:
759 : return false;
760 : }
761 3938104 : case CPP_KEYWORD:
762 3938104 : switch (token->keyword)
763 : {
764 : case RID_CONST:
765 : case RID_VOLATILE:
766 : case RID_RESTRICT:
767 : case RID_ATTRIBUTE:
768 : case RID_ATOMIC:
769 : return true;
770 : default:
771 : return false;
772 : }
773 : case CPP_LESS:
774 : return false;
775 0 : default:
776 0 : gcc_unreachable ();
777 : }
778 : }
779 :
780 : /* Return true if the next token from PARSER is a type qualifier,
781 : false otherwise. */
782 : static inline bool
783 452550441 : c_parser_next_token_is_qualifier (c_parser *parser)
784 : {
785 452550441 : c_token *token = c_parser_peek_token (parser);
786 452550441 : return c_token_is_qualifier (token);
787 : }
788 :
789 : /* Return true if TOKEN can start declaration specifiers (not
790 : including standard attributes), false otherwise. */
791 : static bool
792 182185118 : c_token_starts_declspecs (c_token *token)
793 : {
794 182185118 : switch (token->type)
795 : {
796 101529498 : case CPP_NAME:
797 101529498 : switch (token->id_kind)
798 : {
799 : case C_ID_ID:
800 : return false;
801 : case C_ID_ADDRSPACE:
802 : return true;
803 : case C_ID_TYPENAME:
804 : return true;
805 0 : case C_ID_CLASSNAME:
806 0 : gcc_assert (c_dialect_objc ());
807 : return true;
808 0 : default:
809 0 : gcc_unreachable ();
810 : }
811 78932695 : case CPP_KEYWORD:
812 78932695 : switch (token->keyword)
813 : {
814 : case RID_STATIC:
815 : case RID_EXTERN:
816 : case RID_REGISTER:
817 : case RID_TYPEDEF:
818 : case RID_INLINE:
819 : case RID_NORETURN:
820 : case RID_AUTO:
821 : case RID_THREAD:
822 : case RID_UNSIGNED:
823 : case RID_LONG:
824 : case RID_SHORT:
825 : case RID_SIGNED:
826 : case RID_COMPLEX:
827 : case RID_INT:
828 : case RID_CHAR:
829 : case RID_FLOAT:
830 : case RID_DOUBLE:
831 : case RID_VOID:
832 : case RID_DFLOAT32:
833 : case RID_DFLOAT64:
834 : case RID_DFLOAT128:
835 : case RID_DFLOAT64X:
836 : CASE_RID_FLOATN_NX:
837 : case RID_BOOL:
838 : case RID_BITINT:
839 : case RID_ENUM:
840 : case RID_STRUCT:
841 : case RID_UNION:
842 : case RID_TYPEOF:
843 : case RID_TYPEOF_UNQUAL:
844 : case RID_CONST:
845 : case RID_VOLATILE:
846 : case RID_RESTRICT:
847 : case RID_ATTRIBUTE:
848 : case RID_FRACT:
849 : case RID_ACCUM:
850 : case RID_SAT:
851 : case RID_ALIGNAS:
852 : case RID_ATOMIC:
853 : case RID_AUTO_TYPE:
854 : case RID_CONSTEXPR:
855 : return true;
856 37613726 : default:
857 37613726 : if (token->keyword >= RID_FIRST_INT_N
858 : && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
859 539 : && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
860 : return true;
861 : return false;
862 : }
863 2 : case CPP_LESS:
864 2 : if (c_dialect_objc ())
865 : return true;
866 : return false;
867 : default:
868 : return false;
869 : }
870 : }
871 :
872 :
873 : /* Return true if TOKEN can start declaration specifiers (not
874 : including standard attributes) or a static assertion, false
875 : otherwise. */
876 : static bool
877 52752146 : c_token_starts_declaration (c_token *token)
878 : {
879 52752146 : if (c_token_starts_declspecs (token)
880 52752146 : || token->keyword == RID_STATIC_ASSERT)
881 7743423 : return true;
882 : else
883 : return false;
884 : }
885 :
886 : /* Return true if the next token from PARSER can start declaration
887 : specifiers (not including standard attributes), false
888 : otherwise. */
889 : bool
890 129432972 : c_parser_next_token_starts_declspecs (c_parser *parser)
891 : {
892 129432972 : c_token *token = c_parser_peek_token (parser);
893 :
894 : /* In Objective-C, a classname normally starts a declspecs unless it
895 : is immediately followed by a dot. In that case, it is the
896 : Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
897 : setter/getter on the class. c_token_starts_declspecs() can't
898 : differentiate between the two cases because it only checks the
899 : current token, so we have a special check here. */
900 129432972 : if (c_dialect_objc ()
901 0 : && token->type == CPP_NAME
902 0 : && token->id_kind == C_ID_CLASSNAME
903 129432972 : && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
904 : return false;
905 :
906 129432972 : return c_token_starts_declspecs (token);
907 : }
908 :
909 : static bool c_parser_check_balanced_raw_token_sequence (c_parser *,
910 : unsigned int *);
911 :
912 : /* Return true if the next tokens from PARSER (starting with token N, 1-based)
913 : can start declaration specifiers (not including standard attributes) or a
914 : static assertion, false otherwise. */
915 : bool
916 52753599 : c_parser_next_tokens_start_declaration (c_parser *parser, unsigned int n)
917 : {
918 52753599 : c_token *token = c_parser_peek_nth_token (parser, n);
919 :
920 : /* Same as above. */
921 52753599 : if (c_dialect_objc ()
922 0 : && token->type == CPP_NAME
923 0 : && token->id_kind == C_ID_CLASSNAME
924 52753599 : && c_parser_peek_nth_token (parser, n + 1)->type == CPP_DOT)
925 : return false;
926 :
927 : /* Labels do not start declarations. */
928 52753599 : if (token->type == CPP_NAME
929 52753599 : && c_parser_peek_nth_token (parser, n + 1)->type == CPP_COLON)
930 : return false;
931 :
932 : /* A static assertion is only a declaration if followed by a semicolon;
933 : otherwise, it may be an expression in C2Y. */
934 52753581 : if (token->keyword == RID_STATIC_ASSERT
935 52753581 : && c_parser_peek_nth_token (parser, n + 1)->type == CPP_OPEN_PAREN)
936 : {
937 1435 : n += 2;
938 1435 : if (!c_parser_check_balanced_raw_token_sequence (parser, &n)
939 1435 : || c_parser_peek_nth_token_raw (parser, n)->type != CPP_CLOSE_PAREN)
940 : /* Invalid static assertion syntax; treat as a declaration and report a
941 : syntax error there. */
942 : return true;
943 1430 : return c_parser_peek_nth_token_raw (parser, n + 1)->type == CPP_SEMICOLON;
944 : }
945 :
946 52752146 : if (c_token_starts_declaration (token))
947 : return true;
948 :
949 45008723 : if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl, n))
950 : return true;
951 :
952 : return false;
953 : }
954 :
955 : /* Consume the next token from PARSER. */
956 :
957 : void
958 2400486105 : c_parser_consume_token (c_parser *parser)
959 : {
960 2400486105 : gcc_assert (parser->tokens_avail >= 1);
961 2400486105 : gcc_assert (parser->tokens[0].type != CPP_EOF);
962 2400486105 : gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
963 : /* CPP_PRAGMA should not show up here except if there was an error or inside
964 : another pragma. */
965 2400486105 : gcc_assert (parser->in_pragma
966 : || parser->error
967 : || parser->tokens[0].type != CPP_PRAGMA);
968 2400486105 : parser->last_token_location = parser->tokens[0].location;
969 2400486105 : if (parser->tokens != &parser->tokens_buf[0])
970 46083 : parser->tokens++;
971 2400440022 : else if (parser->tokens_avail >= 2)
972 : {
973 158784100 : parser->tokens[0] = parser->tokens[1];
974 158784100 : if (parser->tokens_avail >= 3)
975 : {
976 33601 : parser->tokens[1] = parser->tokens[2];
977 33601 : if (parser->tokens_avail >= 4)
978 12914 : parser->tokens[2] = parser->tokens[3];
979 : }
980 : }
981 2400486105 : parser->tokens_avail--;
982 2400486105 : parser->seen_string_literal = false;
983 2400486105 : }
984 :
985 : /* Expect the current token to be a #pragma. Consume it and remember
986 : that we've begun parsing a pragma. */
987 :
988 : static void
989 1979904 : c_parser_consume_pragma (c_parser *parser)
990 : {
991 1979904 : gcc_assert (!parser->in_pragma);
992 1979904 : gcc_assert (parser->tokens_avail >= 1);
993 1979904 : gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
994 1979904 : if (parser->tokens != &parser->tokens_buf[0])
995 924 : parser->tokens++;
996 1978980 : else if (parser->tokens_avail >= 2)
997 : {
998 307 : parser->tokens[0] = parser->tokens[1];
999 307 : if (parser->tokens_avail >= 3)
1000 10 : parser->tokens[1] = parser->tokens[2];
1001 : }
1002 1979904 : parser->tokens_avail--;
1003 1979904 : parser->in_pragma = true;
1004 1979904 : }
1005 :
1006 : /* Update the global input_location from TOKEN. */
1007 : static inline void
1008 8306014 : c_parser_set_source_position_from_token (c_token *token)
1009 : {
1010 8306014 : if (token->type != CPP_EOF)
1011 : {
1012 8305933 : input_location = token->location;
1013 : }
1014 : }
1015 :
1016 : /* Helper function for c_parser_error.
1017 : Having peeked a token of kind TOK1_KIND that might signify
1018 : a conflict marker, peek successor tokens to determine
1019 : if we actually do have a conflict marker.
1020 : Specifically, we consider a run of 7 '<', '=' or '>' characters
1021 : at the start of a line as a conflict marker.
1022 : These come through the lexer as three pairs and a single,
1023 : e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
1024 : If it returns true, *OUT_LOC is written to with the location/range
1025 : of the marker. */
1026 :
1027 : static bool
1028 30 : c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind,
1029 : location_t *out_loc)
1030 : {
1031 30 : c_token *token2 = c_parser_peek_2nd_token (parser);
1032 30 : if (token2->type != tok1_kind)
1033 : return false;
1034 25 : c_token *token3 = c_parser_peek_nth_token (parser, 3);
1035 25 : if (token3->type != tok1_kind)
1036 : return false;
1037 22 : c_token *token4 = c_parser_peek_nth_token (parser, 4);
1038 22 : if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind))
1039 : return false;
1040 :
1041 : /* It must be at the start of the line. */
1042 15 : location_t start_loc = c_parser_peek_token (parser)->location;
1043 15 : if (LOCATION_COLUMN (start_loc) != 1)
1044 : return false;
1045 :
1046 : /* We have a conflict marker. Construct a location of the form:
1047 : <<<<<<<
1048 : ^~~~~~~
1049 : with start == caret, finishing at the end of the marker. */
1050 12 : location_t finish_loc = get_finish (token4->location);
1051 12 : *out_loc = make_location (start_loc, start_loc, finish_loc);
1052 :
1053 12 : return true;
1054 : }
1055 :
1056 : /* Issue a diagnostic of the form
1057 : FILE:LINE: MESSAGE before TOKEN
1058 : where TOKEN is the next token in the input stream of PARSER.
1059 : MESSAGE (specified by the caller) is usually of the form "expected
1060 : OTHER-TOKEN".
1061 :
1062 : Use RICHLOC as the location of the diagnostic.
1063 :
1064 : Do not issue a diagnostic if still recovering from an error.
1065 :
1066 : Return true iff an error was actually emitted.
1067 :
1068 : ??? This is taken from the C++ parser, but building up messages in
1069 : this way is not i18n-friendly and some other approach should be
1070 : used. */
1071 :
1072 : static bool
1073 3158 : c_parser_error_richloc (c_parser *parser, const char *gmsgid,
1074 : rich_location *richloc)
1075 : {
1076 3158 : c_token *token = c_parser_peek_token (parser);
1077 3158 : if (parser->error)
1078 : return false;
1079 2403 : parser->error = true;
1080 2403 : if (!gmsgid)
1081 : return false;
1082 :
1083 : /* If this is actually a conflict marker, report it as such. */
1084 2288 : if (token->type == CPP_LSHIFT
1085 2288 : || token->type == CPP_RSHIFT
1086 2269 : || token->type == CPP_EQ_EQ)
1087 : {
1088 30 : location_t loc;
1089 30 : if (c_parser_peek_conflict_marker (parser, token->type, &loc))
1090 : {
1091 12 : error_at (loc, "version control conflict marker in file");
1092 12 : return true;
1093 : }
1094 : }
1095 :
1096 : /* If we were parsing a string-literal and there is an unknown name
1097 : token right after, then check to see if that could also have been
1098 : a literal string by checking the name against a list of known
1099 : standard string literal constants defined in header files. If
1100 : there is one, then add that as an hint to the error message. */
1101 2276 : auto_diagnostic_group d;
1102 2276 : name_hint h;
1103 2276 : if (parser->seen_string_literal && token->type == CPP_NAME)
1104 : {
1105 16 : tree name = token->value;
1106 16 : const char *token_name = IDENTIFIER_POINTER (name);
1107 16 : const char *header_hint
1108 16 : = get_c_stdlib_header_for_string_macro_name (token_name);
1109 16 : if (header_hint != NULL)
1110 48 : h = name_hint (nullptr,
1111 : std::make_unique<suggest_missing_header>
1112 32 : (token->location,
1113 : token_name,
1114 16 : header_hint));
1115 : }
1116 :
1117 2276 : c_parse_error (gmsgid,
1118 : /* Because c_parse_error does not understand
1119 : CPP_KEYWORD, keywords are treated like
1120 : identifiers. */
1121 2276 : (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
1122 : /* ??? The C parser does not save the cpp flags of a
1123 : token, we need to pass 0 here and we will not get
1124 : the source spelling of some tokens but rather the
1125 : canonical spelling. */
1126 : token->value, /*flags=*/0, richloc);
1127 2276 : return true;
1128 2276 : }
1129 :
1130 : /* As c_parser_error_richloc, but issue the message at the
1131 : location of PARSER's next token, or at input_location
1132 : if the next token is EOF. */
1133 :
1134 : bool
1135 2015 : c_parser_error (c_parser *parser, const char *gmsgid)
1136 : {
1137 2015 : c_token *token = c_parser_peek_token (parser);
1138 2015 : c_parser_set_source_position_from_token (token);
1139 2015 : rich_location richloc (line_table, input_location);
1140 2015 : return c_parser_error_richloc (parser, gmsgid, &richloc);
1141 2015 : }
1142 :
1143 : /* Some tokens naturally come in pairs e.g.'(' and ')'.
1144 : This class is for tracking such a matching pair of symbols.
1145 : In particular, it tracks the location of the first token,
1146 : so that if the second token is missing, we can highlight the
1147 : location of the first token when notifying the user about the
1148 : problem. */
1149 :
1150 : template <typename traits_t>
1151 : class token_pair
1152 : {
1153 : public:
1154 : /* token_pair's ctor. */
1155 184143157 : token_pair () : m_open_loc (UNKNOWN_LOCATION) {}
1156 :
1157 : /* If the next token is the opening symbol for this pair, consume it and
1158 : return true.
1159 : Otherwise, issue an error and return false.
1160 : In either case, record the location of the opening token. */
1161 :
1162 4585796 : bool require_open (c_parser *parser)
1163 : {
1164 4585796 : c_token *token = c_parser_peek_token (parser);
1165 4585796 : if (token)
1166 4585796 : m_open_loc = token->location;
1167 :
1168 4585796 : return c_parser_require (parser, traits_t::open_token_type,
1169 4585796 : traits_t::open_gmsgid);
1170 : }
1171 :
1172 : /* Consume the next token from PARSER, recording its location as
1173 : that of the opening token within the pair. */
1174 :
1175 179557678 : void consume_open (c_parser *parser)
1176 : {
1177 179557678 : c_token *token = c_parser_peek_token (parser);
1178 179557678 : gcc_assert (token->type == traits_t::open_token_type);
1179 179557678 : m_open_loc = token->location;
1180 179557678 : c_parser_consume_token (parser);
1181 179557678 : }
1182 :
1183 : /* If the next token is the closing symbol for this pair, consume it
1184 : and return true.
1185 : Otherwise, issue an error, highlighting the location of the
1186 : corresponding opening token, and return false. */
1187 :
1188 1806630 : bool require_close (c_parser *parser) const
1189 : {
1190 1806630 : return c_parser_require (parser, traits_t::close_token_type,
1191 1806630 : traits_t::close_gmsgid, m_open_loc);
1192 : }
1193 :
1194 : /* Like token_pair::require_close, except that tokens will be skipped
1195 : until the desired token is found. An error message is still produced
1196 : if the next token is not as expected. */
1197 :
1198 180932448 : void skip_until_found_close (c_parser *parser) const
1199 : {
1200 180932448 : c_parser_skip_until_found (parser, traits_t::close_token_type,
1201 180932448 : traits_t::close_gmsgid, m_open_loc);
1202 : }
1203 :
1204 : private:
1205 : location_t m_open_loc;
1206 : };
1207 :
1208 : /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
1209 :
1210 : struct matching_paren_traits
1211 : {
1212 : static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN;
1213 : static const char * const open_gmsgid;
1214 : static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN;
1215 : static const char * const close_gmsgid;
1216 : };
1217 :
1218 : const char * const matching_paren_traits::open_gmsgid = "expected %<(%>";
1219 : const char * const matching_paren_traits::close_gmsgid = "expected %<)%>";
1220 :
1221 : /* "matching_parens" is a token_pair<T> class for tracking matching
1222 : pairs of parentheses. */
1223 :
1224 : typedef token_pair<matching_paren_traits> matching_parens;
1225 :
1226 : /* Traits for token_pair<T> for tracking matching pairs of braces. */
1227 :
1228 : struct matching_brace_traits
1229 : {
1230 : static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE;
1231 : static const char * const open_gmsgid;
1232 : static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE;
1233 : static const char * const close_gmsgid;
1234 : };
1235 :
1236 : const char * const matching_brace_traits::open_gmsgid = "expected %<{%>";
1237 : const char * const matching_brace_traits::close_gmsgid = "expected %<}%>";
1238 :
1239 : /* "matching_braces" is a token_pair<T> class for tracking matching
1240 : pairs of braces. */
1241 :
1242 : typedef token_pair<matching_brace_traits> matching_braces;
1243 :
1244 : /* Get a description of the matching symbol to TYPE e.g. "(" for
1245 : CPP_CLOSE_PAREN. */
1246 :
1247 : static const char *
1248 4 : get_matching_symbol (enum cpp_ttype type)
1249 : {
1250 4 : switch (type)
1251 : {
1252 0 : default:
1253 0 : gcc_unreachable ();
1254 : case CPP_CLOSE_PAREN:
1255 : return "(";
1256 1 : case CPP_CLOSE_BRACE:
1257 1 : return "{";
1258 : }
1259 : }
1260 :
1261 : /* If the next token is of the indicated TYPE, consume it. Otherwise,
1262 : issue the error MSGID. If MSGID is NULL then a message has already
1263 : been produced and no message will be produced this time. Returns
1264 : true if found, false otherwise.
1265 :
1266 : If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1267 : within any error as the location of an "opening" token matching
1268 : the close token TYPE (e.g. the location of the '(' when TYPE is
1269 : CPP_CLOSE_PAREN).
1270 :
1271 : If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1272 : one type (e.g. "expected %<)%>") and thus it may be reasonable to
1273 : attempt to generate a fix-it hint for the problem.
1274 : Otherwise msgid describes multiple token types (e.g.
1275 : "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1276 : generate a fix-it hint. */
1277 :
1278 : bool
1279 470736659 : c_parser_require (c_parser *parser,
1280 : enum cpp_ttype type,
1281 : const char *msgid,
1282 : location_t matching_location,
1283 : bool type_is_unique)
1284 : {
1285 470736659 : if (c_parser_next_token_is (parser, type))
1286 : {
1287 470735516 : c_parser_consume_token (parser);
1288 470735516 : return true;
1289 : }
1290 : else
1291 : {
1292 1143 : location_t next_token_loc = c_parser_peek_token (parser)->location;
1293 1143 : gcc_rich_location richloc (next_token_loc);
1294 :
1295 : /* Potentially supply a fix-it hint, suggesting to add the
1296 : missing token immediately after the *previous* token.
1297 : This may move the primary location within richloc. */
1298 1143 : if (!parser->error && type_is_unique)
1299 674 : maybe_suggest_missing_token_insertion (&richloc, type,
1300 : parser->last_token_location);
1301 :
1302 : /* If matching_location != UNKNOWN_LOCATION, highlight it.
1303 : Attempt to consolidate diagnostics by printing it as a
1304 : secondary range within the main diagnostic. */
1305 1143 : bool added_matching_location = false;
1306 1143 : if (matching_location != UNKNOWN_LOCATION)
1307 422 : added_matching_location
1308 422 : = richloc.add_location_if_nearby (*global_dc, matching_location);
1309 :
1310 1143 : if (c_parser_error_richloc (parser, msgid, &richloc))
1311 : /* If we weren't able to consolidate matching_location, then
1312 : print it as a secondary diagnostic. */
1313 567 : if (matching_location != UNKNOWN_LOCATION && !added_matching_location)
1314 4 : inform (matching_location, "to match this %qs",
1315 : get_matching_symbol (type));
1316 :
1317 1143 : return false;
1318 1143 : }
1319 : }
1320 :
1321 : /* If the next token is the indicated keyword, consume it. Otherwise,
1322 : issue the error MSGID. Returns true if found, false otherwise. */
1323 :
1324 : static bool
1325 149464 : c_parser_require_keyword (c_parser *parser,
1326 : enum rid keyword,
1327 : const char *msgid)
1328 : {
1329 149464 : if (c_parser_next_token_is_keyword (parser, keyword))
1330 : {
1331 149463 : c_parser_consume_token (parser);
1332 149463 : return true;
1333 : }
1334 : else
1335 : {
1336 1 : c_parser_error (parser, msgid);
1337 1 : return false;
1338 : }
1339 : }
1340 :
1341 : /* Like c_parser_require, except that tokens will be skipped until the
1342 : desired token is found. An error message is still produced if the
1343 : next token is not as expected. If MSGID is NULL then a message has
1344 : already been produced and no message will be produced this
1345 : time.
1346 :
1347 : If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1348 : within any error as the location of an "opening" token matching
1349 : the close token TYPE (e.g. the location of the '(' when TYPE is
1350 : CPP_CLOSE_PAREN). */
1351 :
1352 : void
1353 235328066 : c_parser_skip_until_found (c_parser *parser,
1354 : enum cpp_ttype type,
1355 : const char *msgid,
1356 : location_t matching_location)
1357 : {
1358 235328066 : unsigned nesting_depth = 0;
1359 :
1360 235328066 : if (c_parser_require (parser, type, msgid, matching_location))
1361 : {
1362 235327153 : if (UNLIKELY (type == CPP_PRAGMA_EOL) && parser->in_omp_attribute_pragma)
1363 : {
1364 0 : c_token *token = c_parser_peek_token (parser);
1365 0 : if (token->type == CPP_EOF)
1366 : {
1367 0 : parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
1368 0 : parser->tokens_avail
1369 0 : = parser->in_omp_attribute_pragma->save_tokens_avail;
1370 0 : parser->in_omp_attribute_pragma = NULL;
1371 : }
1372 : }
1373 : return;
1374 : }
1375 :
1376 : /* Skip tokens until the desired token is found. */
1377 6073 : while (true)
1378 : {
1379 : /* Peek at the next token. */
1380 3493 : c_token *token = c_parser_peek_token (parser);
1381 : /* If we've reached the token we want, consume it and stop. */
1382 3493 : if (token->type == type && !nesting_depth)
1383 : {
1384 710 : c_parser_consume_token (parser);
1385 710 : if (UNLIKELY (type == CPP_PRAGMA_EOL)
1386 108 : && parser->in_omp_attribute_pragma)
1387 : {
1388 1 : c_token *token = c_parser_peek_token (parser);
1389 1 : if (token->type == CPP_EOF)
1390 : {
1391 1 : parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
1392 1 : parser->tokens_avail
1393 1 : = parser->in_omp_attribute_pragma->save_tokens_avail;
1394 1 : parser->in_omp_attribute_pragma = NULL;
1395 : }
1396 : }
1397 : break;
1398 : }
1399 :
1400 : /* If we've run out of tokens, stop. */
1401 2783 : if (token->type == CPP_EOF)
1402 : return;
1403 2764 : if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1404 : return;
1405 2698 : if (token->type == CPP_OPEN_BRACE
1406 : || token->type == CPP_OPEN_PAREN
1407 : || token->type == CPP_OPEN_SQUARE)
1408 296 : ++nesting_depth;
1409 : else if (token->type == CPP_CLOSE_BRACE
1410 : || token->type == CPP_CLOSE_PAREN
1411 : || token->type == CPP_CLOSE_SQUARE)
1412 : {
1413 414 : if (nesting_depth-- == 0)
1414 : break;
1415 : }
1416 : /* Consume this token. */
1417 2580 : c_parser_consume_token (parser);
1418 2580 : }
1419 828 : parser->error = false;
1420 : }
1421 :
1422 : /* Skip tokens until the end of a parameter is found, but do not
1423 : consume the comma, semicolon or closing delimiter. */
1424 :
1425 : static void
1426 97 : c_parser_skip_to_end_of_parameter (c_parser *parser)
1427 : {
1428 97 : unsigned nesting_depth = 0;
1429 :
1430 501 : while (true)
1431 : {
1432 299 : c_token *token = c_parser_peek_token (parser);
1433 299 : if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
1434 25 : && !nesting_depth)
1435 : break;
1436 : /* If we've run out of tokens, stop. */
1437 274 : if (token->type == CPP_EOF)
1438 : return;
1439 274 : if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1440 : return;
1441 274 : if (token->type == CPP_OPEN_BRACE
1442 : || token->type == CPP_OPEN_PAREN
1443 : || token->type == CPP_OPEN_SQUARE)
1444 3 : ++nesting_depth;
1445 : else if (token->type == CPP_CLOSE_BRACE
1446 : || token->type == CPP_CLOSE_PAREN
1447 : || token->type == CPP_CLOSE_SQUARE)
1448 : {
1449 75 : if (nesting_depth-- == 0)
1450 : break;
1451 : }
1452 : /* Consume this token. */
1453 202 : c_parser_consume_token (parser);
1454 202 : }
1455 97 : parser->error = false;
1456 : }
1457 :
1458 : /* Skip tokens until a non-nested closing curly brace is the next
1459 : token, or there are no more tokens. Return true in the first case,
1460 : false otherwise. */
1461 :
1462 : static bool
1463 26 : c_parser_skip_to_closing_brace (c_parser *parser)
1464 : {
1465 26 : unsigned nesting_depth = 0;
1466 :
1467 96 : while (true)
1468 : {
1469 61 : c_token *token = c_parser_peek_token (parser);
1470 :
1471 61 : switch (token->type)
1472 : {
1473 2 : case CPP_PRAGMA_EOL:
1474 2 : if (!parser->in_pragma)
1475 : break;
1476 : /* FALLTHRU */
1477 : case CPP_EOF:
1478 : /* If we've run out of tokens, stop. */
1479 : return false;
1480 :
1481 24 : case CPP_CLOSE_BRACE:
1482 : /* If the next token is a non-nested `}', then we have reached
1483 : the end of the current block. */
1484 24 : if (nesting_depth-- == 0)
1485 : return true;
1486 : break;
1487 :
1488 0 : case CPP_OPEN_BRACE:
1489 : /* If it the next token is a `{', then we are entering a new
1490 : block. Consume the entire block. */
1491 0 : ++nesting_depth;
1492 0 : break;
1493 :
1494 : default:
1495 : break;
1496 : }
1497 :
1498 : /* Consume the token. */
1499 35 : c_parser_consume_token (parser);
1500 35 : }
1501 : }
1502 :
1503 : /* Expect to be at the end of the pragma directive and consume an
1504 : end of line marker. */
1505 :
1506 : static void
1507 1981085 : c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
1508 : {
1509 1981085 : gcc_assert (parser->in_pragma);
1510 1981085 : parser->in_pragma = false;
1511 :
1512 1981085 : if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
1513 217 : c_parser_error (parser, "expected end of line");
1514 :
1515 1982516 : cpp_ttype token_type;
1516 1982516 : do
1517 : {
1518 1982516 : c_token *token = c_parser_peek_token (parser);
1519 1982516 : token_type = token->type;
1520 1982516 : if (token_type == CPP_EOF)
1521 : break;
1522 1982516 : c_parser_consume_token (parser);
1523 : }
1524 1982516 : while (token_type != CPP_PRAGMA_EOL);
1525 :
1526 1981085 : if (parser->in_omp_attribute_pragma)
1527 : {
1528 754 : c_token *token = c_parser_peek_token (parser);
1529 754 : if (token->type == CPP_EOF)
1530 : {
1531 607 : parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
1532 607 : parser->tokens_avail
1533 607 : = parser->in_omp_attribute_pragma->save_tokens_avail;
1534 607 : parser->in_omp_attribute_pragma = NULL;
1535 : }
1536 : }
1537 :
1538 1981085 : parser->error = false;
1539 1981085 : }
1540 :
1541 : /* Skip tokens up to and including "#pragma omp end declare variant".
1542 : Properly handle nested "#pragma omp begin declare variant" pragmas. */
1543 : static void
1544 6 : c_parser_skip_to_pragma_omp_end_declare_variant (c_parser *parser)
1545 : {
1546 166 : for (int depth = 0; depth >= 0; )
1547 : {
1548 160 : c_token *token = c_parser_peek_token (parser);
1549 :
1550 160 : switch (token->type)
1551 : {
1552 0 : case CPP_PRAGMA_EOL:
1553 0 : if (!parser->in_pragma)
1554 : break;
1555 : /* FALLTHRU */
1556 : case CPP_EOF:
1557 : /* If we've run out of tokens, stop. */
1558 : return;
1559 :
1560 10 : case CPP_PRAGMA:
1561 10 : if ((token->pragma_kind == PRAGMA_OMP_BEGIN
1562 8 : || token->pragma_kind == PRAGMA_OMP_END)
1563 10 : && c_parser_peek_nth_token (parser, 2)->type == CPP_NAME
1564 20 : && c_parser_peek_nth_token (parser, 3)->type == CPP_NAME)
1565 : {
1566 10 : tree id1 = c_parser_peek_nth_token (parser, 2)->value;
1567 10 : tree id2 = c_parser_peek_nth_token (parser, 3)->value;
1568 10 : if (strcmp (IDENTIFIER_POINTER (id1), "declare") == 0
1569 20 : && strcmp (IDENTIFIER_POINTER (id2), "variant") == 0)
1570 : {
1571 10 : if (token->pragma_kind == PRAGMA_OMP_BEGIN)
1572 2 : depth++;
1573 : else
1574 8 : depth--;
1575 : }
1576 : }
1577 10 : c_parser_consume_pragma (parser);
1578 10 : c_parser_skip_to_pragma_eol (parser, false);
1579 10 : continue;
1580 :
1581 : default:
1582 : break;
1583 10 : }
1584 :
1585 : /* Consume the token. */
1586 150 : c_parser_consume_token (parser);
1587 : }
1588 : }
1589 :
1590 : /* Skip tokens until we have consumed an entire block, or until we
1591 : have consumed a non-nested ';'. */
1592 :
1593 : static void
1594 533 : c_parser_skip_to_end_of_block_or_statement (c_parser *parser,
1595 : bool metadirective_p = false)
1596 : {
1597 533 : unsigned nesting_depth = 0;
1598 533 : int bracket_depth = 0;
1599 533 : bool save_error = parser->error;
1600 :
1601 1911 : while (true)
1602 : {
1603 1911 : c_token *token;
1604 :
1605 : /* Peek at the next token. */
1606 1911 : token = c_parser_peek_token (parser);
1607 :
1608 1911 : switch (token->type)
1609 : {
1610 : case CPP_EOF:
1611 : return;
1612 :
1613 0 : case CPP_PRAGMA_EOL:
1614 0 : if (parser->in_pragma)
1615 : return;
1616 : break;
1617 :
1618 464 : case CPP_SEMICOLON:
1619 : /* If the next token is a ';', we have reached the
1620 : end of the statement. */
1621 464 : if (!nesting_depth && (!metadirective_p || bracket_depth <= 0))
1622 : {
1623 : /* Consume the ';'. */
1624 399 : c_parser_consume_token (parser);
1625 399 : goto finished;
1626 : }
1627 : break;
1628 :
1629 110 : case CPP_CLOSE_BRACE:
1630 : /* If the next token is a non-nested '}', then we have
1631 : reached the end of the current block. */
1632 61 : if ((nesting_depth == 0 || --nesting_depth == 0)
1633 171 : && (!metadirective_p || bracket_depth <= 0))
1634 : {
1635 110 : c_parser_consume_token (parser);
1636 110 : goto finished;
1637 : }
1638 : break;
1639 :
1640 61 : case CPP_OPEN_BRACE:
1641 : /* If it the next token is a '{', then we are entering a new
1642 : block. Consume the entire block. */
1643 61 : ++nesting_depth;
1644 61 : break;
1645 :
1646 64 : case CPP_OPEN_PAREN:
1647 : /* Track parentheses in case the statement is a standalone 'for'
1648 : statement - we want to skip over the semicolons separating the
1649 : operands. */
1650 64 : if (metadirective_p && nesting_depth == 0)
1651 2 : ++bracket_depth;
1652 : break;
1653 :
1654 90 : case CPP_CLOSE_PAREN:
1655 90 : if (metadirective_p && nesting_depth == 0)
1656 2 : --bracket_depth;
1657 : break;
1658 :
1659 7 : case CPP_PRAGMA:
1660 : /* If we see a pragma, consume the whole thing at once. We
1661 : have some safeguards against consuming pragmas willy-nilly.
1662 : Normally, we'd expect to be here with parser->error set,
1663 : which disables these safeguards. But it's possible to get
1664 : here for secondary error recovery, after parser->error has
1665 : been cleared. */
1666 7 : c_parser_consume_pragma (parser);
1667 7 : c_parser_skip_to_pragma_eol (parser, false);
1668 7 : parser->error = save_error;
1669 7 : continue;
1670 :
1671 : default:
1672 : break;
1673 : }
1674 :
1675 1371 : c_parser_consume_token (parser);
1676 : }
1677 :
1678 509 : finished:
1679 509 : parser->error = false;
1680 : }
1681 :
1682 : /* CPP's options (initialized by c-opts.cc). */
1683 : extern cpp_options *cpp_opts;
1684 :
1685 : /* Save the warning flags which are controlled by __extension__. */
1686 :
1687 : static inline int
1688 980547 : disable_extension_diagnostics (void)
1689 : {
1690 1961094 : int ret = (pedantic
1691 980547 : | (warn_pointer_arith << 1)
1692 980547 : | (warn_traditional << 2)
1693 980547 : | (flag_iso << 3)
1694 980547 : | (warn_long_long << 4)
1695 980547 : | (warn_cxx_compat << 5)
1696 980547 : | (warn_overlength_strings << 6)
1697 : /* warn_c90_c99_compat has three states: -1/0/1, so we must
1698 : play tricks to properly restore it. */
1699 980547 : | ((warn_c90_c99_compat == 1) << 7)
1700 980547 : | ((warn_c90_c99_compat == -1) << 8)
1701 : /* Similarly for warn_c99_c11_compat. */
1702 980547 : | ((warn_c99_c11_compat == 1) << 9)
1703 980547 : | ((warn_c99_c11_compat == -1) << 10)
1704 : /* Similarly for warn_c11_c23_compat. */
1705 980547 : | ((warn_c11_c23_compat == 1) << 11)
1706 980547 : | ((warn_c11_c23_compat == -1) << 12)
1707 : /* Similarly for warn_c23_c2y_compat. */
1708 980547 : | ((warn_c23_c2y_compat == 1) << 13)
1709 980547 : | ((warn_c23_c2y_compat == -1) << 14)
1710 : );
1711 980547 : cpp_opts->cpp_pedantic = pedantic = 0;
1712 980547 : warn_pointer_arith = 0;
1713 980547 : cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1714 980547 : flag_iso = 0;
1715 980547 : cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1716 980547 : warn_cxx_compat = 0;
1717 980547 : warn_overlength_strings = 0;
1718 980547 : warn_c90_c99_compat = 0;
1719 980547 : warn_c99_c11_compat = 0;
1720 980547 : warn_c11_c23_compat = 0;
1721 980547 : warn_c23_c2y_compat = 0;
1722 980547 : return ret;
1723 : }
1724 :
1725 : /* Restore the warning flags which are controlled by __extension__.
1726 : FLAGS is the return value from disable_extension_diagnostics. */
1727 :
1728 : static inline void
1729 980547 : restore_extension_diagnostics (int flags)
1730 : {
1731 980547 : cpp_opts->cpp_pedantic = pedantic = flags & 1;
1732 980547 : warn_pointer_arith = (flags >> 1) & 1;
1733 980547 : cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1734 980547 : flag_iso = (flags >> 3) & 1;
1735 980547 : cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1736 980547 : warn_cxx_compat = (flags >> 5) & 1;
1737 980547 : warn_overlength_strings = (flags >> 6) & 1;
1738 : /* See above for why is this needed. */
1739 980547 : warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1740 980547 : warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1741 980547 : warn_c11_c23_compat = (flags >> 11) & 1 ? 1 : ((flags >> 12) & 1 ? -1 : 0);
1742 980547 : warn_c23_c2y_compat = (flags >> 13) & 1 ? 1 : ((flags >> 14) & 1 ? -1 : 0);
1743 980547 : }
1744 :
1745 : /* Helper data structure for parsing #pragma acc routine. */
1746 : struct oacc_routine_data {
1747 : bool error_seen; /* Set if error has been reported. */
1748 : bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */
1749 : tree clauses;
1750 : location_t loc;
1751 : };
1752 :
1753 : /* Used for parsing objc foreach statements. */
1754 : static tree objc_foreach_break_label, objc_foreach_continue_label;
1755 :
1756 : /* Used for parsing OMP for loops.
1757 :
1758 : Some notes on flags used for context:
1759 : parser->omp_for_parse_state is non-null anywhere inside the OMP FOR
1760 : construct, except for the final-loop-body.
1761 : The want_nested_loop flag is true if inside a {} sequence where
1762 : a loop-nest (or another {} sequence containing a loop-nest) is expected,
1763 : but has not yet been seen. It's false when parsing intervening code
1764 : statements or their substatements that cannot contain a loop-nest.
1765 : The in_intervening_code flag is true when parsing any intervening code,
1766 : including substatements, and whether or not want_nested_loop is true.
1767 :
1768 : And, about error handling:
1769 : The saw_intervening_code flag is set if the loop is not perfectly
1770 : nested, even in the usual case where this is not an error.
1771 : perfect_nesting_fail is set if an error has been diagnosed because an
1772 : imperfectly-nested loop was found where a perfectly-nested one is
1773 : required (we diagnose this only once).
1774 : fail is set if any kind of structural error in the loop nest
1775 : has been found and diagnosed.
1776 : */
1777 : struct omp_for_parse_data {
1778 : enum tree_code code;
1779 : tree declv, condv, incrv, initv;
1780 : tree pre_body;
1781 : tree bindings;
1782 : int count; /* Expected nesting depth. */
1783 : int depth; /* Current nesting depth. */
1784 : location_t for_loc;
1785 : bool ordered : 1;
1786 : bool inscan : 1;
1787 : bool want_nested_loop : 1;
1788 : bool in_intervening_code : 1;
1789 : bool saw_intervening_code: 1;
1790 : bool perfect_nesting_fail : 1;
1791 : bool fail : 1;
1792 : };
1793 :
1794 : struct attr_state
1795 : {
1796 : /* True if we parsed a musttail attribute for return. */
1797 : bool musttail_p;
1798 :
1799 52182587 : void reset () { musttail_p = false; }
1800 : };
1801 :
1802 : static bool c_parser_nth_token_starts_std_attributes (c_parser *,
1803 : unsigned int);
1804 : static tree c_parser_std_attribute_specifier_sequence (c_parser *);
1805 : static void c_parser_external_declaration (c_parser *);
1806 : static void c_parser_asm_definition (c_parser *);
1807 : static tree c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1808 : bool, bool, bool, tree * = NULL,
1809 : vec<c_token> * = NULL,
1810 : bool have_attrs = false,
1811 : tree attrs = NULL,
1812 : struct oacc_routine_data * = NULL,
1813 : bool * = NULL);
1814 : static bool c_parser_handle_statement_omp_attributes (c_parser *, tree &,
1815 : bool *);
1816 : static void c_parser_static_assert_declaration_no_semi (c_parser *);
1817 : static void c_parser_static_assert_declaration (c_parser *);
1818 : static struct c_typespec c_parser_enum_specifier (c_parser *);
1819 : static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1820 : static tree c_parser_struct_declaration (c_parser *, tree *);
1821 : static struct c_typespec c_parser_typeof_specifier (c_parser *);
1822 : static tree c_parser_alignas_specifier (c_parser *);
1823 : static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1824 : c_dtr_syn, bool *);
1825 : static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1826 : bool,
1827 : struct c_declarator *);
1828 : static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree,
1829 : bool);
1830 : static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1831 : tree, bool);
1832 : static struct c_parm *c_parser_parameter_declaration (c_parser *, tree, bool);
1833 : static tree c_parser_asm_string_literal (c_parser *);
1834 : static tree c_parser_simple_asm_expr (c_parser *);
1835 : static tree c_parser_gnu_attributes (c_parser *);
1836 : static struct c_expr c_parser_initializer (c_parser *, tree);
1837 : static struct c_expr c_parser_braced_init (c_parser *, tree, bool,
1838 : struct obstack *, bool);
1839 : static void c_parser_initelt (c_parser *, struct obstack *);
1840 : static void c_parser_initval (c_parser *, struct c_expr *,
1841 : struct obstack *);
1842 : static tree c_parser_compound_statement (c_parser *, location_t * = NULL);
1843 : static location_t c_parser_compound_statement_nostart (c_parser *);
1844 : static void c_parser_label (c_parser *, tree);
1845 : static void c_parser_statement (c_parser *, bool *, location_t * = NULL);
1846 : static void c_parser_statement_after_labels (c_parser *, bool *, tree,
1847 : vec<tree> * = NULL,
1848 : attr_state = {});
1849 : static tree c_parser_c99_block_statement (c_parser *, bool *,
1850 : location_t * = NULL);
1851 : static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
1852 : static void c_parser_switch_statement (c_parser *, bool *, tree);
1853 : static void c_parser_while_statement (c_parser *, bool, unsigned short, bool,
1854 : bool *, tree);
1855 : static void c_parser_do_statement (c_parser *, bool, unsigned short, bool,
1856 : tree);
1857 : static void c_parser_for_statement (c_parser *, bool, unsigned short, bool,
1858 : bool *, tree);
1859 : static tree c_parser_asm_statement (c_parser *);
1860 : static tree c_parser_asm_operands (c_parser *);
1861 : static tree c_parser_asm_goto_operands (c_parser *);
1862 : static tree c_parser_asm_clobbers (c_parser *);
1863 : static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1864 : tree = NULL_TREE);
1865 : static struct c_expr c_parser_conditional_expression (c_parser *,
1866 : struct c_expr *, tree);
1867 : static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1868 : tree);
1869 : static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1870 : static struct c_expr c_parser_unary_expression (c_parser *);
1871 : static struct c_expr c_parser_sizeof_or_countof_expression (c_parser *,
1872 : enum rid);
1873 : static struct c_expr c_parser_alignof_expression (c_parser *);
1874 : static struct c_expr c_parser_maxof_or_minof_expression (c_parser *, enum rid);
1875 : static struct c_expr c_parser_postfix_expression (c_parser *);
1876 : static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1877 : struct c_declspecs *,
1878 : struct c_type_name *,
1879 : location_t);
1880 : static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1881 : location_t loc,
1882 : struct c_expr);
1883 : static tree c_parser_transaction (c_parser *, enum rid);
1884 : static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1885 : static tree c_parser_transaction_cancel (c_parser *);
1886 : static struct c_expr c_parser_expression (c_parser *);
1887 : static struct c_expr c_parser_expression_conv (c_parser *);
1888 : static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1889 : vec<tree, va_gc> **, location_t *,
1890 : tree *, vec<location_t> *,
1891 : unsigned int * = NULL);
1892 : static struct c_expr c_parser_has_attribute_expression (c_parser *);
1893 :
1894 : static void c_parser_oacc_declare (c_parser *);
1895 : static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1896 : static void c_parser_oacc_update (c_parser *);
1897 : static void c_parser_omp_construct (c_parser *, bool *);
1898 : static void c_parser_omp_groupprivate (c_parser *);
1899 : static void c_parser_omp_threadprivate (c_parser *);
1900 : static void c_parser_omp_barrier (c_parser *);
1901 : static void c_parser_omp_depobj (c_parser *);
1902 : static void c_parser_omp_flush (c_parser *);
1903 : static bool c_parser_omp_next_tokens_can_be_canon_loop (c_parser *,
1904 : enum tree_code, bool);
1905 : static tree c_parser_omp_loop_nest (c_parser *, bool *);
1906 : static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1907 : tree, tree *, bool *);
1908 : static void c_parser_omp_taskwait (c_parser *);
1909 : static void c_parser_omp_taskyield (c_parser *);
1910 : static void c_parser_omp_cancel (c_parser *);
1911 : static void c_parser_omp_nothing (c_parser *);
1912 : static void c_parser_omp_metadirective (c_parser *, bool *);
1913 :
1914 : enum pragma_context { pragma_external, pragma_struct, pragma_param,
1915 : pragma_stmt, pragma_compound };
1916 : static bool c_parser_pragma (c_parser *, enum pragma_context, bool *, tree);
1917 : static bool c_parser_omp_cancellation_point (c_parser *, enum pragma_context);
1918 : static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
1919 : static void c_parser_omp_begin (c_parser *);
1920 : static void c_parser_omp_end (c_parser *);
1921 : static bool c_parser_omp_declare (c_parser *, enum pragma_context);
1922 : static void c_parser_omp_requires (c_parser *);
1923 : static bool c_parser_omp_error (c_parser *, enum pragma_context);
1924 : static void c_parser_omp_assumption_clauses (c_parser *, bool);
1925 : static void c_parser_omp_allocate (c_parser *);
1926 : static void c_parser_omp_assumes (c_parser *);
1927 : static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
1928 : static tree c_parser_omp_dispatch (location_t, c_parser *);
1929 : static void c_parser_omp_interop (c_parser *);
1930 : static void c_parser_oacc_routine (c_parser *, enum pragma_context);
1931 :
1932 : /* These Objective-C parser functions are only ever called when
1933 : compiling Objective-C. */
1934 : static void c_parser_objc_class_definition (c_parser *, tree);
1935 : static void c_parser_objc_class_instance_variables (c_parser *);
1936 : static void c_parser_objc_class_declaration (c_parser *);
1937 : static void c_parser_objc_alias_declaration (c_parser *);
1938 : static void c_parser_objc_protocol_definition (c_parser *, tree);
1939 : static bool c_parser_objc_method_type (c_parser *);
1940 : static void c_parser_objc_method_definition (c_parser *);
1941 : static void c_parser_objc_methodprotolist (c_parser *);
1942 : static void c_parser_objc_methodproto (c_parser *);
1943 : static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1944 : static tree c_parser_objc_type_name (c_parser *);
1945 : static tree c_parser_objc_protocol_refs (c_parser *);
1946 : static void c_parser_objc_try_catch_finally_statement (c_parser *);
1947 : static void c_parser_objc_synchronized_statement (c_parser *);
1948 : static tree c_parser_objc_selector (c_parser *);
1949 : static tree c_parser_objc_selector_arg (c_parser *);
1950 : static tree c_parser_objc_receiver (c_parser *);
1951 : static tree c_parser_objc_message_args (c_parser *);
1952 : static tree c_parser_objc_keywordexpr (c_parser *);
1953 : static void c_parser_objc_at_property_declaration (c_parser *);
1954 : static void c_parser_objc_at_synthesize_declaration (c_parser *);
1955 : static void c_parser_objc_at_dynamic_declaration (c_parser *);
1956 : static bool c_parser_objc_diagnose_bad_element_prefix
1957 : (c_parser *, struct c_declspecs *);
1958 : static location_t c_parser_parse_rtl_body (c_parser *, char *);
1959 : static tree c_parser_handle_musttail (c_parser *, tree, attr_state &);
1960 :
1961 : #if ENABLE_ANALYZER
1962 :
1963 : namespace ana {
1964 :
1965 : /* Concrete implementation of ana::translation_unit for the C frontend. */
1966 :
1967 : class c_translation_unit : public translation_unit
1968 : {
1969 : public:
1970 : /* Implementation of translation_unit::lookup_constant_by_id for use by the
1971 : analyzer to look up named constants in the user's source code. */
1972 11832 : tree lookup_constant_by_id (tree id) const final override
1973 : {
1974 : /* Consider decls. */
1975 11832 : if (tree decl = lookup_name (id))
1976 43 : if (TREE_CODE (decl) == CONST_DECL)
1977 43 : if (tree value = DECL_INITIAL (decl))
1978 43 : if (TREE_CODE (value) == INTEGER_CST)
1979 : return value;
1980 :
1981 : /* Consider macros. */
1982 11789 : cpp_hashnode *hashnode = C_CPP_HASHNODE (id);
1983 11789 : if (cpp_macro_p (hashnode))
1984 82 : if (tree value = consider_macro (hashnode->value.macro))
1985 : return value;
1986 :
1987 : return NULL_TREE;
1988 : }
1989 :
1990 : tree
1991 0 : lookup_type_by_id (tree id) const final override
1992 : {
1993 0 : if (tree type_decl = lookup_name (id))
1994 0 : if (TREE_CODE (type_decl) == TYPE_DECL)
1995 : {
1996 0 : tree record_type = TREE_TYPE (type_decl);
1997 0 : if (TREE_CODE (record_type) == RECORD_TYPE)
1998 0 : return record_type;
1999 : }
2000 :
2001 : return NULL_TREE;
2002 : }
2003 :
2004 : tree
2005 0 : lookup_global_var_by_id (tree id) const final override
2006 : {
2007 0 : if (tree var_decl = lookup_name (id))
2008 0 : if (TREE_CODE (var_decl) == VAR_DECL)
2009 0 : return var_decl;
2010 :
2011 : return NULL_TREE;
2012 : }
2013 :
2014 : private:
2015 : /* Attempt to get an INTEGER_CST from MACRO.
2016 : Only handle the simplest cases: where MACRO's definition is a single
2017 : token containing a number, by lexing the number again.
2018 : This will handle e.g.
2019 : #define NAME 42
2020 : and other bases but not negative numbers, parentheses or e.g.
2021 : #define NAME 1 << 7
2022 : as doing so would require a parser.
2023 : Also handle the case where MACRO's definition is a single identifier
2024 : that is itself a macro name (e.g. "#define O_CREAT _FCREAT"), by
2025 : following the chain of aliases. */
2026 82 : tree consider_macro (cpp_macro *macro, int depth = 0) const
2027 : {
2028 : /* UInteger option variables are stored as int, so "depth" must be signed
2029 : to avoid a signed/unsigned comparison here. */
2030 84 : gcc_assert (depth >= 0);
2031 :
2032 84 : if (macro->paramc > 0)
2033 : return NULL_TREE;
2034 81 : if (macro->kind != cmk_macro)
2035 : return NULL_TREE;
2036 81 : if (macro->count != 1)
2037 : return NULL_TREE;
2038 75 : const cpp_token &tok = macro->exp.tokens[0];
2039 75 : if (tok.type == CPP_NAME)
2040 : {
2041 : /* Limit recursion. */
2042 4 : if (depth >= param_analyzer_max_macro_alias_depth)
2043 : return NULL_TREE;
2044 :
2045 3 : cpp_hashnode *alias = tok.val.node.node;
2046 3 : if (cpp_macro_p (alias))
2047 2 : return consider_macro (alias->value.macro, depth + 1);
2048 :
2049 : /* Not a simple alias. */
2050 : return NULL_TREE;
2051 : }
2052 71 : else if (tok.type != CPP_NUMBER)
2053 : return NULL_TREE;
2054 :
2055 69 : cpp_reader *old_parse_in = parse_in;
2056 69 : parse_in = cpp_create_reader (CLK_GNUC89, NULL, line_table);
2057 :
2058 69 : pretty_printer pp;
2059 69 : pp_string (&pp, (const char *) tok.val.str.text);
2060 69 : pp_newline (&pp);
2061 138 : cpp_push_buffer (parse_in,
2062 69 : (const unsigned char *) pp_formatted_text (&pp),
2063 : strlen (pp_formatted_text (&pp)),
2064 : 0);
2065 :
2066 69 : tree value;
2067 69 : location_t loc;
2068 69 : unsigned char cpp_flags;
2069 69 : c_lex_with_flags (&value, &loc, &cpp_flags, 0);
2070 :
2071 69 : cpp_destroy (parse_in);
2072 69 : parse_in = old_parse_in;
2073 :
2074 69 : if (value && TREE_CODE (value) == INTEGER_CST)
2075 69 : return value;
2076 :
2077 : return NULL_TREE;
2078 69 : }
2079 : };
2080 :
2081 : } // namespace ana
2082 :
2083 : #endif /* #if ENABLE_ANALYZER */
2084 :
2085 : /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
2086 :
2087 : translation-unit:
2088 : external-declarations
2089 :
2090 : external-declarations:
2091 : external-declaration
2092 : external-declarations external-declaration
2093 :
2094 : GNU extensions:
2095 :
2096 : translation-unit:
2097 : empty
2098 : */
2099 :
2100 : static void
2101 108556 : c_parser_translation_unit (c_parser *parser)
2102 : {
2103 108556 : if (c_parser_next_token_is (parser, CPP_EOF))
2104 : {
2105 1162 : pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2106 : "ISO C forbids an empty translation unit");
2107 : }
2108 : else
2109 : {
2110 107394 : void *obstack_position = obstack_alloc (&parser_obstack, 0);
2111 107394 : mark_valid_location_for_stdc_pragma (false);
2112 60374925 : do
2113 : {
2114 60374925 : ggc_collect ();
2115 60374925 : c_parser_external_declaration (parser);
2116 60374920 : obstack_free (&parser_obstack, obstack_position);
2117 : }
2118 60374920 : while (c_parser_next_token_is_not (parser, CPP_EOF));
2119 : }
2120 :
2121 108466 : unsigned int i;
2122 108466 : tree decl;
2123 108601 : FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl)
2124 135 : if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node)
2125 37 : error ("storage size of %q+D isn%'t known", decl);
2126 :
2127 108466 : if (vec_safe_length (current_omp_declare_target_attribute))
2128 : {
2129 4 : c_omp_declare_target_attr
2130 4 : a = current_omp_declare_target_attribute->pop ();
2131 4 : if (!errorcount)
2132 3 : error ("%qs without corresponding %qs",
2133 : a.device_type >= 0 ? "#pragma omp begin declare target"
2134 : : "#pragma omp declare target",
2135 : "#pragma omp end declare target");
2136 4 : vec_safe_truncate (current_omp_declare_target_attribute, 0);
2137 : }
2138 108466 : if (vec_safe_length (current_omp_begin_assumes))
2139 : {
2140 1 : if (!errorcount)
2141 1 : error ("%qs without corresponding %qs",
2142 : "#pragma omp begin assumes", "#pragma omp end assumes");
2143 1 : vec_safe_truncate (current_omp_begin_assumes, 0);
2144 : }
2145 108466 : if (vec_safe_length (current_omp_declare_variant_attribute))
2146 : {
2147 0 : if (!errorcount)
2148 0 : error ("%<omp begin declare variant%> without corresponding "
2149 : "%<omp end declare variant%>");
2150 0 : vec_safe_truncate (current_omp_declare_variant_attribute, 0);
2151 : }
2152 108466 : if (vec_safe_length (omp_begin_declare_variant_map))
2153 : {
2154 : unsigned int i;
2155 : omp_begin_declare_variant_map_entry *e;
2156 35 : FOR_EACH_VEC_ELT (*omp_begin_declare_variant_map, i, e)
2157 26 : omp_finish_variant_function (e->variant, e->id, e->ctx);
2158 9 : vec_safe_truncate (omp_begin_declare_variant_map, 0);
2159 : }
2160 :
2161 : #if ENABLE_ANALYZER
2162 108466 : if (flag_analyzer)
2163 : {
2164 1479 : ana::c_translation_unit tu;
2165 1479 : ana::on_finish_translation_unit (tu);
2166 : }
2167 : #endif
2168 108466 : }
2169 :
2170 : /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
2171 :
2172 : external-declaration:
2173 : function-definition
2174 : declaration
2175 :
2176 : GNU extensions:
2177 :
2178 : external-declaration:
2179 : asm-definition
2180 : ;
2181 : __extension__ external-declaration
2182 :
2183 : Objective-C:
2184 :
2185 : external-declaration:
2186 : objc-class-definition
2187 : objc-class-declaration
2188 : objc-alias-declaration
2189 : objc-protocol-definition
2190 : objc-method-definition
2191 : @end
2192 : */
2193 :
2194 : static void
2195 60822306 : c_parser_external_declaration (c_parser *parser)
2196 : {
2197 60822306 : int ext;
2198 60822306 : switch (c_parser_peek_token (parser)->type)
2199 : {
2200 58960137 : case CPP_KEYWORD:
2201 58960137 : switch (c_parser_peek_token (parser)->keyword)
2202 : {
2203 447381 : case RID_EXTENSION:
2204 447381 : ext = disable_extension_diagnostics ();
2205 447381 : c_parser_consume_token (parser);
2206 447381 : c_parser_external_declaration (parser);
2207 447381 : restore_extension_diagnostics (ext);
2208 447381 : break;
2209 214 : case RID_ASM:
2210 214 : c_parser_asm_definition (parser);
2211 214 : break;
2212 0 : case RID_AT_INTERFACE:
2213 0 : case RID_AT_IMPLEMENTATION:
2214 0 : gcc_assert (c_dialect_objc ());
2215 0 : c_parser_objc_class_definition (parser, NULL_TREE);
2216 0 : break;
2217 0 : case RID_AT_CLASS:
2218 0 : gcc_assert (c_dialect_objc ());
2219 0 : c_parser_objc_class_declaration (parser);
2220 0 : break;
2221 0 : case RID_AT_ALIAS:
2222 0 : gcc_assert (c_dialect_objc ());
2223 0 : c_parser_objc_alias_declaration (parser);
2224 0 : break;
2225 0 : case RID_AT_PROTOCOL:
2226 0 : gcc_assert (c_dialect_objc ());
2227 0 : c_parser_objc_protocol_definition (parser, NULL_TREE);
2228 0 : break;
2229 0 : case RID_AT_PROPERTY:
2230 0 : gcc_assert (c_dialect_objc ());
2231 0 : c_parser_objc_at_property_declaration (parser);
2232 0 : break;
2233 0 : case RID_AT_SYNTHESIZE:
2234 0 : gcc_assert (c_dialect_objc ());
2235 0 : c_parser_objc_at_synthesize_declaration (parser);
2236 0 : break;
2237 0 : case RID_AT_DYNAMIC:
2238 0 : gcc_assert (c_dialect_objc ());
2239 0 : c_parser_objc_at_dynamic_declaration (parser);
2240 0 : break;
2241 0 : case RID_AT_END:
2242 0 : gcc_assert (c_dialect_objc ());
2243 0 : c_parser_consume_token (parser);
2244 0 : objc_finish_implementation ();
2245 0 : break;
2246 58512542 : default:
2247 58512542 : goto decl_or_fndef;
2248 : }
2249 : break;
2250 2296 : case CPP_SEMICOLON:
2251 2296 : pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2252 : "ISO C does not allow extra %<;%> outside of a function");
2253 2296 : c_parser_consume_token (parser);
2254 2296 : break;
2255 1635572 : case CPP_PRAGMA:
2256 1635572 : mark_valid_location_for_stdc_pragma (true);
2257 1635572 : c_parser_pragma (parser, pragma_external, NULL, NULL_TREE);
2258 1635572 : mark_valid_location_for_stdc_pragma (false);
2259 1635572 : break;
2260 1 : case CPP_PLUS:
2261 1 : case CPP_MINUS:
2262 1 : if (c_dialect_objc ())
2263 : {
2264 0 : c_parser_objc_method_definition (parser);
2265 0 : break;
2266 : }
2267 : /* Else fall through, and yield a syntax error trying to parse
2268 : as a declaration or function definition. */
2269 : /* FALLTHRU */
2270 58736843 : default:
2271 1 : decl_or_fndef:
2272 : /* A declaration or a function definition (or, in Objective-C,
2273 : an @interface or @protocol with prefix attributes). We can
2274 : only tell which after parsing the declaration specifiers, if
2275 : any, and the first declarator. */
2276 58736843 : c_parser_declaration_or_fndef (parser, true, true, true, false, true,
2277 : false);
2278 58736843 : break;
2279 : }
2280 60822301 : }
2281 :
2282 : static void c_parser_handle_directive_omp_attributes (tree &, vec<c_token> *&,
2283 : vec<c_token> *);
2284 : static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token> *);
2285 : static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool);
2286 :
2287 : /* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */
2288 :
2289 : static void
2290 110754831 : add_debug_begin_stmt (location_t loc)
2291 : {
2292 : /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */
2293 110754831 : if (!MAY_HAVE_DEBUG_MARKER_STMTS || !building_stmt_list_p ())
2294 : return;
2295 :
2296 2812343 : tree stmt = build0 (DEBUG_BEGIN_STMT, void_type_node);
2297 2812343 : SET_EXPR_LOCATION (stmt, loc);
2298 2812343 : add_stmt (stmt);
2299 : }
2300 :
2301 : /* Helper function for c_parser_declaration_or_fndef and
2302 : Handle assume attribute(s). */
2303 :
2304 : static tree
2305 38 : handle_assume_attribute (location_t here, tree attrs, bool nested)
2306 : {
2307 38 : if (nested)
2308 78 : for (tree attr = lookup_attribute ("gnu", "assume", attrs); attr;
2309 41 : attr = lookup_attribute ("gnu", "assume", TREE_CHAIN (attr)))
2310 : {
2311 41 : tree args = TREE_VALUE (attr);
2312 41 : int nargs = list_length (args);
2313 41 : if (nargs != 1)
2314 : {
2315 6 : error_at (here, "wrong number of arguments specified "
2316 : "for %qE attribute",
2317 : get_attribute_name (attr));
2318 6 : inform (here, "expected %i, found %i", 1, nargs);
2319 : }
2320 : else
2321 : {
2322 35 : tree arg = TREE_VALUE (args);
2323 35 : arg = c_objc_common_truthvalue_conversion (here, arg);
2324 35 : arg = c_fully_fold (arg, false, NULL);
2325 35 : if (arg != error_mark_node)
2326 : {
2327 33 : tree fn = build_call_expr_internal_loc (here, IFN_ASSUME,
2328 : void_type_node, 1,
2329 : arg);
2330 33 : add_stmt (fn);
2331 : }
2332 : }
2333 : }
2334 : else
2335 1 : pedwarn (here, OPT_Wattributes,
2336 : "%<assume%> attribute at top level");
2337 :
2338 38 : return remove_attribute ("gnu", "assume", attrs);
2339 : }
2340 :
2341 : /* We might need to reclassify any previously-lexed identifier, e.g.
2342 : when we've left a for loop with an if-statement without else in the
2343 : body - we might have used a wrong scope for the token. See PR67784. */
2344 :
2345 : static void
2346 39340163 : c_parser_maybe_reclassify_token (c_parser *parser)
2347 : {
2348 39340163 : if (c_parser_next_token_is (parser, CPP_NAME))
2349 : {
2350 210528 : c_token *token = c_parser_peek_token (parser);
2351 :
2352 210528 : if (token->id_kind == C_ID_ID || token->id_kind == C_ID_TYPENAME)
2353 : {
2354 210527 : tree decl = lookup_name (token->value);
2355 :
2356 210527 : token->id_kind = C_ID_ID;
2357 210527 : if (decl)
2358 : {
2359 207255 : if (TREE_CODE (decl) == TYPE_DECL)
2360 2342 : token->id_kind = C_ID_TYPENAME;
2361 : }
2362 3272 : else if (c_dialect_objc ())
2363 : {
2364 0 : tree objc_interface_decl = objc_is_class_name (token->value);
2365 : /* Objective-C class names are in the same namespace as
2366 : variables and typedefs, and hence are shadowed by local
2367 : declarations. */
2368 0 : if (objc_interface_decl)
2369 : {
2370 0 : token->value = objc_interface_decl;
2371 0 : token->id_kind = C_ID_CLASSNAME;
2372 : }
2373 : }
2374 : }
2375 : }
2376 39340163 : }
2377 :
2378 : /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
2379 : 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
2380 : is accepted; otherwise (old-style parameter declarations) only other
2381 : declarations are accepted. If STATIC_ASSERT_OK is true, a static
2382 : assertion is accepted; otherwise (old-style parameter declarations)
2383 : it is not. If NESTED is true, we are inside a function or parsing
2384 : old-style parameter declarations; any functions encountered are
2385 : nested functions and declaration specifiers are required; otherwise
2386 : we are at top level and functions are normal functions and
2387 : declaration specifiers may be optional. If EMPTY_OK is true, empty
2388 : declarations are OK (subject to all other constraints); otherwise
2389 : (old-style parameter declarations) they are diagnosed. If
2390 : START_ATTR_OK is true, the declaration specifiers may start with
2391 : attributes (GNU or standard); otherwise they may not.
2392 : OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
2393 : declaration when parsing an Objective-C foreach statement.
2394 : FALLTHRU_ATTR_P is used to signal whether this function parsed
2395 : "__attribute__((fallthrough));". ATTRS are any standard attributes
2396 : parsed in the caller (in contexts where such attributes had to be
2397 : parsed to determine whether what follows is a declaration or a
2398 : statement); HAVE_ATTRS says whether there were any such attributes
2399 : (even empty). If SIMPLE_OK, the construct can be a simple-declaration;
2400 : in that case, the ';' is not consumed (left to the caller so that it
2401 : can figure out if there was a simple-declaration or not), there must
2402 : be an initializer, and only one object may be declared. When SIMPLE_OK
2403 : is true we are called from c_parser_selection_header.
2404 :
2405 : Returns the resulting declaration, if there was any with an initializer.
2406 :
2407 : declaration:
2408 : declaration-specifiers init-declarator-list[opt] ;
2409 : static_assert-declaration
2410 :
2411 : function-definition:
2412 : declaration-specifiers[opt] declarator declaration-list[opt]
2413 : compound-statement
2414 :
2415 : declaration-list:
2416 : declaration
2417 : declaration-list declaration
2418 :
2419 : init-declarator-list:
2420 : init-declarator
2421 : init-declarator-list , init-declarator
2422 :
2423 : init-declarator:
2424 : declarator simple-asm-expr[opt] gnu-attributes[opt]
2425 : declarator simple-asm-expr[opt] gnu-attributes[opt] = initializer
2426 :
2427 : simple-declaration:
2428 : attribute-specifier-sequence[opt] declaration-specifiers declarator
2429 : = initializer
2430 :
2431 : GNU extensions:
2432 :
2433 : nested-function-definition:
2434 : declaration-specifiers declarator declaration-list[opt]
2435 : compound-statement
2436 :
2437 : attribute ;
2438 :
2439 : Objective-C:
2440 : gnu-attributes objc-class-definition
2441 : gnu-attributes objc-category-definition
2442 : gnu-attributes objc-protocol-definition
2443 :
2444 : The simple-asm-expr and gnu-attributes are GNU extensions.
2445 :
2446 : This function does not handle __extension__; that is handled in its
2447 : callers. ??? Following the old parser, __extension__ may start
2448 : external declarations, declarations in functions and declarations
2449 : at the start of "for" loops, but not old-style parameter
2450 : declarations.
2451 :
2452 : C99 requires declaration specifiers in a function definition; the
2453 : absence is diagnosed through the diagnosis of implicit int. In GNU
2454 : C we also allow but diagnose declarations without declaration
2455 : specifiers, but only at top level (elsewhere they conflict with
2456 : other syntax).
2457 :
2458 : In Objective-C, declarations of the looping variable in a foreach
2459 : statement are exceptionally terminated by 'in' (for example, 'for
2460 : (NSObject *object in array) { ... }').
2461 :
2462 : OpenMP:
2463 :
2464 : declaration:
2465 : threadprivate-directive
2466 :
2467 : GIMPLE:
2468 :
2469 : gimple-function-definition:
2470 : declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
2471 : declaration-list[opt] compound-statement
2472 :
2473 : rtl-function-definition:
2474 : declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
2475 : declaration-list[opt] compound-statement */
2476 :
2477 : static tree
2478 66491385 : c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
2479 : bool static_assert_ok, bool empty_ok,
2480 : bool nested, bool start_attr_ok,
2481 : bool simple_ok,
2482 : tree *objc_foreach_object_declaration
2483 : /* = NULL */,
2484 : vec<c_token> *omp_declare_simd_clauses
2485 : /* = NULL */,
2486 : bool have_attrs /* = false */,
2487 : tree attrs /* = NULL_TREE */,
2488 : struct oacc_routine_data *oacc_routine_data
2489 : /* = NULL */,
2490 : bool *fallthru_attr_p /* = NULL */)
2491 : {
2492 66491385 : struct c_declspecs *specs;
2493 66491385 : tree prefix_attrs;
2494 66491385 : tree all_prefix_attrs;
2495 66491385 : bool diagnosed_no_specs = false;
2496 66491385 : location_t here = c_parser_peek_token (parser)->location;
2497 66491385 : tree result = NULL_TREE;
2498 :
2499 66491385 : add_debug_begin_stmt (c_parser_peek_token (parser)->location);
2500 :
2501 66491385 : if (static_assert_ok
2502 132969423 : && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2503 : {
2504 2265 : c_parser_static_assert_declaration (parser);
2505 2265 : return result;
2506 : }
2507 66489120 : specs = build_null_declspecs ();
2508 :
2509 : /* Handle any standard attributes parsed in the caller. */
2510 66489120 : if (have_attrs)
2511 : {
2512 143 : declspecs_add_attrs (here, specs, attrs);
2513 143 : specs->non_std_attrs_seen_p = false;
2514 : }
2515 :
2516 : /* Try to detect an unknown type name when we have "A B" or "A *B". */
2517 66489120 : if (c_parser_peek_token (parser)->type == CPP_NAME
2518 5967219 : && c_parser_peek_token (parser)->id_kind == C_ID_ID
2519 9289 : && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
2520 9186 : || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
2521 66489247 : && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
2522 : {
2523 125 : tree name = c_parser_peek_token (parser)->value;
2524 :
2525 : /* Issue a warning about NAME being an unknown type name, perhaps
2526 : with some kind of hint.
2527 : If the user forgot a "struct" etc, suggest inserting
2528 : it. Otherwise, attempt to look for misspellings. */
2529 125 : gcc_rich_location richloc (here);
2530 125 : if (tag_exists_p (RECORD_TYPE, name))
2531 : {
2532 : /* This is not C++ with its implicit typedef. */
2533 3 : richloc.add_fixit_insert_before ("struct ");
2534 3 : error_at (&richloc,
2535 : "unknown type name %qE;"
2536 : " use %<struct%> keyword to refer to the type",
2537 : name);
2538 : }
2539 122 : else if (tag_exists_p (UNION_TYPE, name))
2540 : {
2541 3 : richloc.add_fixit_insert_before ("union ");
2542 3 : error_at (&richloc,
2543 : "unknown type name %qE;"
2544 : " use %<union%> keyword to refer to the type",
2545 : name);
2546 : }
2547 119 : else if (tag_exists_p (ENUMERAL_TYPE, name))
2548 : {
2549 3 : richloc.add_fixit_insert_before ("enum ");
2550 3 : error_at (&richloc,
2551 : "unknown type name %qE;"
2552 : " use %<enum%> keyword to refer to the type",
2553 : name);
2554 : }
2555 : else
2556 : {
2557 116 : auto_diagnostic_group d;
2558 116 : name_hint hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME,
2559 116 : here);
2560 116 : if (const char *suggestion = hint.suggestion ())
2561 : {
2562 10 : richloc.add_fixit_replace (suggestion);
2563 10 : error_at (&richloc,
2564 : "unknown type name %qE; did you mean %qs?",
2565 : name, suggestion);
2566 : }
2567 : else
2568 106 : error_at (here, "unknown type name %qE", name);
2569 116 : }
2570 :
2571 : /* Parse declspecs normally to get a correct pointer type, but avoid
2572 : a further "fails to be a type name" error. Refuse nested functions
2573 : since it is not how the user likely wants us to recover. */
2574 125 : c_parser_peek_token (parser)->type = CPP_KEYWORD;
2575 125 : c_parser_peek_token (parser)->keyword = RID_VOID;
2576 125 : c_parser_peek_token (parser)->value = error_mark_node;
2577 125 : fndef_ok = !nested;
2578 125 : }
2579 :
2580 : /* When there are standard attributes at the start of the
2581 : declaration (to apply to the entity being declared), an
2582 : init-declarator-list or function definition must be present. */
2583 66489120 : if (c_parser_nth_token_starts_std_attributes (parser, 1))
2584 1444 : have_attrs = true;
2585 :
2586 66489120 : c_parser_declspecs (parser, specs, true, true, start_attr_ok,
2587 : true, true, start_attr_ok, true, cla_nonabstract_decl);
2588 66489120 : if (parser->error)
2589 : {
2590 31 : c_parser_skip_to_end_of_block_or_statement (parser);
2591 31 : return result;
2592 : }
2593 66489089 : if (nested && !specs->declspecs_seen_p)
2594 : {
2595 63 : c_parser_error (parser, "expected declaration specifiers");
2596 63 : c_parser_skip_to_end_of_block_or_statement (parser);
2597 63 : return result;
2598 : }
2599 :
2600 66489026 : finish_declspecs (specs);
2601 : /* When the decl is declared, its type is a top level type, we should
2602 : call verify_counted_by_for_top_anonymous_type. */
2603 66489026 : if (specs->typespec_kind == ctsk_tagdef)
2604 1211882 : verify_counted_by_for_top_anonymous_type (specs->type);
2605 :
2606 66489026 : bool gnu_auto_type_p = specs->typespec_word == cts_auto_type;
2607 66489026 : bool std_auto_type_p = specs->c23_auto_p;
2608 66489026 : bool any_auto_type_p = gnu_auto_type_p || std_auto_type_p;
2609 66489026 : gcc_assert (!(gnu_auto_type_p && std_auto_type_p));
2610 66489026 : const char *auto_type_keyword = gnu_auto_type_p ? "__auto_type" : "auto";
2611 66489026 : if (specs->constexpr_p)
2612 : {
2613 : /* An underspecified declaration may not declare tags or members
2614 : or structures or unions; it is undefined behavior to declare
2615 : the members of an enumeration. Where the structure, union or
2616 : enumeration type is declared within an initializer, this is
2617 : diagnosed elsewhere. Diagnose here the case of declaring
2618 : such a type in the type specifiers of a constexpr
2619 : declaration. */
2620 398 : switch (specs->typespec_kind)
2621 : {
2622 6 : case ctsk_tagfirstref:
2623 6 : case ctsk_tagfirstref_attrs:
2624 6 : error_at (here, "%qT declared in underspecified object declaration",
2625 : specs->type);
2626 6 : break;
2627 :
2628 10 : case ctsk_tagdef:
2629 10 : error_at (here, "%qT defined in underspecified object declaration",
2630 : specs->type);
2631 10 : break;
2632 :
2633 : default:
2634 : break;
2635 : }
2636 : }
2637 :
2638 66489026 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2639 : {
2640 513291 : bool handled_assume = false;
2641 513291 : if (specs->attrs
2642 504 : && !nested
2643 127 : && specs->typespec_kind == ctsk_none
2644 513400 : && c_parser_handle_statement_omp_attributes (parser, specs->attrs,
2645 : NULL))
2646 : {
2647 88 : if (specs->attrs)
2648 0 : c_warn_unused_attributes (specs->attrs);
2649 177 : while (parser->in_omp_attribute_pragma)
2650 : {
2651 89 : gcc_assert (c_parser_next_token_is (parser, CPP_PRAGMA));
2652 89 : c_parser_pragma (parser, pragma_external, NULL, NULL_TREE);
2653 : }
2654 88 : c_parser_consume_token (parser);
2655 88 : return result;
2656 : }
2657 513203 : if (specs->typespec_kind == ctsk_none
2658 513203 : && lookup_attribute ("gnu", "assume", specs->attrs))
2659 : {
2660 38 : handled_assume = true;
2661 38 : specs->attrs
2662 38 : = handle_assume_attribute (here, specs->attrs, nested);
2663 : }
2664 513203 : if (any_auto_type_p)
2665 6 : error_at (here, "%qs in empty declaration", auto_type_keyword);
2666 513197 : else if (specs->typespec_kind == ctsk_none
2667 513197 : && attribute_fallthrough_p (specs->attrs))
2668 : {
2669 328 : if (fallthru_attr_p != NULL)
2670 327 : *fallthru_attr_p = true;
2671 328 : if (nested)
2672 : {
2673 327 : tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH,
2674 : void_type_node, 0);
2675 327 : add_stmt (fn);
2676 : }
2677 : else
2678 1 : pedwarn (here, OPT_Wattributes,
2679 : "%<fallthrough%> attribute at top level");
2680 : }
2681 512869 : else if (empty_ok
2682 512852 : && !(have_attrs && specs->non_std_attrs_seen_p)
2683 512849 : && !handled_assume)
2684 512811 : shadow_tag (specs);
2685 : else
2686 : {
2687 58 : shadow_tag_warned (specs, 1);
2688 58 : if (!handled_assume)
2689 20 : pedwarn (here, 0, "empty declaration");
2690 : }
2691 : /* We still have to evaluate size expressions. */
2692 513203 : if (specs->expr)
2693 117 : add_stmt (fold_convert (void_type_node, specs->expr));
2694 513203 : c_parser_consume_token (parser);
2695 513203 : if (oacc_routine_data)
2696 0 : c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
2697 : return result;
2698 : }
2699 65975735 : else if (specs->typespec_kind == ctsk_none
2700 : && nested
2701 : /* Only parse __attribute__((musttail)) when called from
2702 : c_parser_compound_statement_nostart. This certainly isn't
2703 : a declaration in that case, but we don't do tentative parsing
2704 : of GNU attributes right now. */
2705 9777 : && fallthru_attr_p
2706 65975820 : && c_parser_next_token_is_keyword (parser, RID_RETURN))
2707 : {
2708 14 : attr_state astate = {};
2709 14 : specs->attrs = c_parser_handle_musttail (parser, specs->attrs, astate);
2710 14 : if (astate.musttail_p)
2711 : {
2712 14 : if (specs->attrs)
2713 : {
2714 0 : auto_urlify_attributes sentinel;
2715 0 : warning_at (c_parser_peek_token (parser)->location,
2716 0 : OPT_Wattributes,
2717 : "attribute %<musttail%> mixed with other attributes "
2718 : "on %<return%> statement");
2719 0 : }
2720 14 : c_parser_statement_after_labels (parser, NULL, NULL_TREE, NULL,
2721 : astate);
2722 14 : return result;
2723 : }
2724 : }
2725 :
2726 : /* Provide better error recovery. Note that a type name here is usually
2727 : better diagnosed as a redeclaration. */
2728 65975721 : if (empty_ok
2729 65962588 : && specs->typespec_kind == ctsk_tagdef
2730 788215 : && c_parser_next_token_starts_declspecs (parser)
2731 65975751 : && !c_parser_next_token_is (parser, CPP_NAME))
2732 : {
2733 9 : c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2734 9 : parser->error = false;
2735 9 : shadow_tag_warned (specs, 1);
2736 9 : return result;
2737 : }
2738 65975712 : else if (c_dialect_objc () && !any_auto_type_p)
2739 : {
2740 : /* Prefix attributes are an error on method decls. */
2741 0 : switch (c_parser_peek_token (parser)->type)
2742 : {
2743 0 : case CPP_PLUS:
2744 0 : case CPP_MINUS:
2745 0 : if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
2746 : return result;
2747 0 : if (specs->attrs)
2748 : {
2749 0 : warning_at (c_parser_peek_token (parser)->location,
2750 0 : OPT_Wattributes,
2751 : "prefix attributes are ignored for methods");
2752 0 : specs->attrs = NULL_TREE;
2753 : }
2754 0 : if (fndef_ok)
2755 0 : c_parser_objc_method_definition (parser);
2756 : else
2757 0 : c_parser_objc_methodproto (parser);
2758 : return result;
2759 0 : break;
2760 0 : default:
2761 0 : break;
2762 : }
2763 : /* This is where we parse 'attributes @interface ...',
2764 : 'attributes @implementation ...', 'attributes @protocol ...'
2765 : (where attributes could be, for example, __attribute__
2766 : ((deprecated)).
2767 : */
2768 0 : switch (c_parser_peek_token (parser)->keyword)
2769 : {
2770 0 : case RID_AT_INTERFACE:
2771 0 : {
2772 0 : if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
2773 : return result;
2774 0 : c_parser_objc_class_definition (parser, specs->attrs);
2775 0 : return result;
2776 : }
2777 0 : break;
2778 0 : case RID_AT_IMPLEMENTATION:
2779 0 : {
2780 0 : if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
2781 : return result;
2782 0 : if (specs->attrs)
2783 : {
2784 0 : warning_at (c_parser_peek_token (parser)->location,
2785 0 : OPT_Wattributes,
2786 : "prefix attributes are ignored for implementations");
2787 0 : specs->attrs = NULL_TREE;
2788 : }
2789 0 : c_parser_objc_class_definition (parser, NULL_TREE);
2790 0 : return result;
2791 : }
2792 0 : break;
2793 0 : case RID_AT_PROTOCOL:
2794 0 : {
2795 0 : if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
2796 : return result;
2797 0 : c_parser_objc_protocol_definition (parser, specs->attrs);
2798 0 : return result;
2799 : }
2800 0 : break;
2801 0 : case RID_AT_ALIAS:
2802 0 : case RID_AT_CLASS:
2803 0 : case RID_AT_END:
2804 0 : case RID_AT_PROPERTY:
2805 0 : if (specs->attrs)
2806 : {
2807 0 : c_parser_error (parser, "unexpected attribute");
2808 0 : specs->attrs = NULL;
2809 : }
2810 : break;
2811 : default:
2812 : break;
2813 : }
2814 : }
2815 65975712 : else if (attribute_fallthrough_p (specs->attrs))
2816 5 : warning_at (here, OPT_Wattributes,
2817 : "%<fallthrough%> attribute not followed by %<;%>");
2818 65975707 : else if (lookup_attribute ("gnu", "assume", specs->attrs))
2819 2 : warning_at (here, OPT_Wattributes,
2820 : "%<assume%> attribute not followed by %<;%>");
2821 :
2822 131951419 : auto_vec<c_token> omp_declare_simd_attr_clauses;
2823 65975712 : c_parser_handle_directive_omp_attributes (specs->attrs,
2824 : omp_declare_simd_clauses,
2825 : &omp_declare_simd_attr_clauses);
2826 65975712 : pending_xref_error ();
2827 65975712 : prefix_attrs = specs->attrs;
2828 65975712 : all_prefix_attrs = prefix_attrs;
2829 65975712 : specs->attrs = NULL_TREE;
2830 65975712 : bool more_than_one_decl = false;
2831 66837650 : while (true)
2832 : {
2833 66406681 : struct c_declarator *declarator;
2834 66406681 : bool dummy = false;
2835 66406681 : timevar_id_t tv;
2836 66406681 : tree fnbody = NULL_TREE;
2837 66406681 : tree underspec_name = NULL_TREE;
2838 66406681 : auto_vec<c_token> omp_dsimd_idattr_clauses;
2839 : /* Declaring either one or more declarators (in which case we
2840 : should diagnose if there were no declaration specifiers) or a
2841 : function definition (in which case the diagnostic for
2842 : implicit int suffices). */
2843 132813362 : declarator = c_parser_declarator (parser,
2844 66406681 : specs->typespec_kind != ctsk_none,
2845 : C_DTR_NORMAL, &dummy);
2846 66406681 : if (declarator == NULL)
2847 : {
2848 255 : if (omp_declare_simd_clauses)
2849 1 : c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
2850 : omp_declare_simd_clauses);
2851 255 : if (oacc_routine_data)
2852 0 : c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
2853 : /* This check is here purely to improve the diagnostic. */
2854 255 : if (!simple_ok)
2855 235 : c_parser_skip_to_end_of_block_or_statement (parser);
2856 : return result;
2857 : }
2858 66406426 : if (flag_openmp || flag_openmp_simd)
2859 : {
2860 : struct c_declarator *d = declarator;
2861 936924 : while (d->kind != cdk_id)
2862 409062 : d = d->declarator;
2863 527862 : vec<c_token> *dummy = NULL;
2864 527862 : c_parser_handle_directive_omp_attributes (d->u.id.attrs, dummy,
2865 : &omp_dsimd_idattr_clauses);
2866 : }
2867 66406426 : if (gnu_auto_type_p && declarator->kind != cdk_id)
2868 : {
2869 1 : error_at (here,
2870 : "%<__auto_type%> requires a plain identifier"
2871 : " as declarator");
2872 1 : c_parser_skip_to_end_of_block_or_statement (parser);
2873 1 : return result;
2874 : }
2875 66406425 : if (std_auto_type_p)
2876 : {
2877 : struct c_declarator *d = declarator;
2878 84 : while (d->kind == cdk_attrs)
2879 0 : d = d->declarator;
2880 84 : if (d->kind != cdk_id)
2881 : {
2882 1 : error_at (here,
2883 : "%<auto%> requires a plain identifier, possibly with"
2884 : " attributes, as declarator");
2885 1 : c_parser_skip_to_end_of_block_or_statement (parser);
2886 1 : return result;
2887 : }
2888 83 : underspec_name = d->u.id.id;
2889 : }
2890 66406341 : else if (specs->constexpr_p)
2891 : {
2892 : struct c_declarator *d = declarator;
2893 462 : while (d->kind != cdk_id)
2894 79 : d = d->declarator;
2895 383 : underspec_name = d->u.id.id;
2896 : }
2897 66406424 : if (c_parser_next_token_is (parser, CPP_EQ)
2898 59987486 : || c_parser_next_token_is (parser, CPP_COMMA)
2899 59674291 : || c_parser_next_token_is (parser, CPP_SEMICOLON)
2900 51525880 : || c_parser_next_token_is_keyword (parser, RID_ASM)
2901 50645415 : || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
2902 104075793 : || c_parser_next_token_is_keyword (parser, RID_IN))
2903 : {
2904 28737055 : tree asm_name = NULL_TREE;
2905 28737055 : tree postfix_attrs = NULL_TREE;
2906 28737055 : if (!diagnosed_no_specs && !specs->declspecs_seen_p)
2907 : {
2908 79 : diagnosed_no_specs = true;
2909 79 : pedwarn (here, 0, "data definition has no type or storage class");
2910 : }
2911 : /* Having seen a data definition, there cannot now be a
2912 : function definition. */
2913 28737055 : fndef_ok = false;
2914 28737055 : if (c_parser_next_token_is_keyword (parser, RID_ASM))
2915 880465 : asm_name = c_parser_simple_asm_expr (parser);
2916 28737055 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2917 : {
2918 13803808 : postfix_attrs = c_parser_gnu_attributes (parser);
2919 13803808 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2920 : {
2921 : /* This means there is an attribute specifier after
2922 : the declarator in a function definition. Provide
2923 : some more information for the user. */
2924 1 : error_at (here, "attributes should be specified before the "
2925 : "declarator in a function definition");
2926 1 : c_parser_skip_to_end_of_block_or_statement (parser);
2927 1 : return result;
2928 : }
2929 : }
2930 28737054 : if (c_parser_next_token_is (parser, CPP_EQ))
2931 : {
2932 6420418 : tree d;
2933 6420418 : struct c_expr init;
2934 6420418 : location_t init_loc;
2935 6420418 : c_parser_consume_token (parser);
2936 6420418 : if (any_auto_type_p)
2937 : {
2938 1969 : init_loc = c_parser_peek_token (parser)->location;
2939 1969 : rich_location richloc (line_table, init_loc);
2940 1969 : unsigned int underspec_state = 0;
2941 1969 : if (std_auto_type_p)
2942 81 : underspec_state =
2943 81 : start_underspecified_init (init_loc, underspec_name);
2944 3874 : start_init (NULL_TREE, asm_name,
2945 1969 : (global_bindings_p ()
2946 1905 : || specs->storage_class == csc_static
2947 1903 : || specs->constexpr_p),
2948 : specs->constexpr_p, &richloc);
2949 : /* A parameter is initialized, which is invalid. Don't
2950 : attempt to instrument the initializer. */
2951 1969 : sanitize_code_type flag_sanitize_save = flag_sanitize;
2952 1969 : if (nested && !empty_ok)
2953 30 : flag_sanitize = 0;
2954 1969 : init = c_parser_expr_no_commas (parser, NULL);
2955 1969 : if (std_auto_type_p)
2956 81 : finish_underspecified_init (underspec_name,
2957 : underspec_state);
2958 1969 : flag_sanitize = flag_sanitize_save;
2959 1969 : if (gnu_auto_type_p
2960 1888 : && TREE_CODE (init.value) == COMPONENT_REF
2961 1970 : && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
2962 1 : error_at (here,
2963 : "%<__auto_type%> used with a bit-field"
2964 : " initializer");
2965 1969 : init = convert_lvalue_to_rvalue (init_loc, init, true, true,
2966 : true);
2967 1969 : tree init_type = TREE_TYPE (init.value);
2968 1969 : bool vm_type = c_type_variably_modified_p (init_type);
2969 1969 : if (vm_type)
2970 95 : init.value = save_expr (init.value);
2971 1969 : finish_init ();
2972 1969 : specs->typespec_kind = ctsk_typeof;
2973 1969 : specs->locations[cdw_typedef] = init_loc;
2974 1969 : specs->typedef_p = true;
2975 1969 : specs->type = init_type;
2976 1969 : if (specs->postfix_attrs)
2977 : {
2978 : /* Postfix [[]] attributes are valid with C23
2979 : auto, although not with __auto_type, and
2980 : modify the type given by the initializer. */
2981 2 : specs->postfix_attrs
2982 2 : = c_warn_type_attributes (specs->type,
2983 : specs->postfix_attrs);
2984 2 : decl_attributes (&specs->type, specs->postfix_attrs, 0);
2985 2 : specs->postfix_attrs = NULL_TREE;
2986 : }
2987 1969 : if (vm_type)
2988 : {
2989 95 : bool maybe_const = true;
2990 95 : tree type_expr = c_fully_fold (init.value, false,
2991 : &maybe_const);
2992 95 : specs->expr_const_operands &= maybe_const;
2993 95 : if (specs->expr)
2994 0 : specs->expr = build2 (COMPOUND_EXPR,
2995 0 : TREE_TYPE (type_expr),
2996 : specs->expr, type_expr);
2997 : else
2998 : specs->expr = type_expr;
2999 : }
3000 1969 : d = start_decl (declarator, specs, true,
3001 : chainon (postfix_attrs, all_prefix_attrs));
3002 1969 : if (!d)
3003 12 : d = error_mark_node;
3004 1969 : if (omp_declare_simd_clauses)
3005 0 : c_finish_omp_declare_simd (parser, d, NULL_TREE,
3006 : omp_declare_simd_clauses);
3007 1969 : if (!omp_dsimd_idattr_clauses.is_empty ())
3008 0 : c_finish_omp_declare_simd (parser, d, NULL_TREE,
3009 : &omp_dsimd_idattr_clauses);
3010 1969 : }
3011 : else
3012 : {
3013 : /* The declaration of the variable is in effect while
3014 : its initializer is parsed, except for a constexpr
3015 : variable. */
3016 6418449 : init_loc = c_parser_peek_token (parser)->location;
3017 6418449 : rich_location richloc (line_table, init_loc);
3018 6418449 : unsigned int underspec_state = 0;
3019 6418449 : if (specs->constexpr_p)
3020 378 : underspec_state =
3021 378 : start_underspecified_init (init_loc, underspec_name);
3022 6418449 : d = start_decl (declarator, specs, true,
3023 : chainon (postfix_attrs,
3024 : all_prefix_attrs),
3025 6418449 : !specs->constexpr_p);
3026 6418449 : if (!d)
3027 4 : d = error_mark_node;
3028 6418449 : if (!specs->constexpr_p && omp_declare_simd_clauses)
3029 0 : c_finish_omp_declare_simd (parser, d, NULL_TREE,
3030 : omp_declare_simd_clauses);
3031 6418449 : if (!specs->constexpr_p
3032 6418449 : && !omp_dsimd_idattr_clauses.is_empty ())
3033 0 : c_finish_omp_declare_simd (parser, d, NULL_TREE,
3034 : &omp_dsimd_idattr_clauses);
3035 6418449 : start_init (d, asm_name,
3036 6418449 : TREE_STATIC (d) || specs->constexpr_p,
3037 : specs->constexpr_p, &richloc);
3038 : /* A parameter is initialized, which is invalid. Don't
3039 : attempt to instrument the initializer. */
3040 6418449 : sanitize_code_type flag_sanitize_save = flag_sanitize;
3041 6418449 : if (TREE_CODE (d) == PARM_DECL)
3042 35 : flag_sanitize = 0;
3043 6418449 : init = c_parser_initializer (parser, d);
3044 6418447 : flag_sanitize = flag_sanitize_save;
3045 6418447 : if (specs->constexpr_p)
3046 : {
3047 378 : finish_underspecified_init (underspec_name,
3048 : underspec_state);
3049 378 : d = pushdecl (d);
3050 378 : if (omp_declare_simd_clauses)
3051 0 : c_finish_omp_declare_simd (parser, d, NULL_TREE,
3052 : omp_declare_simd_clauses);
3053 378 : if (!specs->constexpr_p
3054 378 : && !omp_dsimd_idattr_clauses.is_empty ())
3055 0 : c_finish_omp_declare_simd (parser, d, NULL_TREE,
3056 : &omp_dsimd_idattr_clauses);
3057 : }
3058 6418447 : finish_init ();
3059 6418447 : }
3060 6420416 : if (oacc_routine_data)
3061 0 : c_finish_oacc_routine (oacc_routine_data, d, false);
3062 6420416 : if (d != error_mark_node)
3063 : {
3064 6420400 : maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
3065 6420400 : finish_decl (d, init_loc, init.value,
3066 : init.original_type, asm_name);
3067 6420400 : result = d;
3068 : }
3069 : }
3070 : else
3071 : {
3072 22316636 : if (any_auto_type_p || specs->constexpr_p)
3073 : {
3074 8 : error_at (here,
3075 : "%qs requires an initialized data declaration",
3076 : any_auto_type_p ? auto_type_keyword : "constexpr");
3077 5 : c_parser_skip_to_end_of_block_or_statement (parser);
3078 5 : return result;
3079 : }
3080 :
3081 22316631 : location_t lastloc = UNKNOWN_LOCATION;
3082 22316631 : tree attrs = chainon (postfix_attrs, all_prefix_attrs);
3083 22316631 : tree d = start_decl (declarator, specs, false, attrs, true,
3084 : &lastloc);
3085 22316630 : if (d && TREE_CODE (d) == FUNCTION_DECL)
3086 : {
3087 : /* Find the innermost declarator that is neither cdk_id
3088 : nor cdk_attrs. */
3089 : const struct c_declarator *decl = declarator;
3090 : const struct c_declarator *last_non_id_attrs = NULL;
3091 :
3092 31125268 : while (decl)
3093 31125268 : switch (decl->kind)
3094 : {
3095 15789148 : case cdk_array:
3096 15789148 : case cdk_function:
3097 15789148 : case cdk_pointer:
3098 15789148 : last_non_id_attrs = decl;
3099 15789148 : decl = decl->declarator;
3100 15789148 : break;
3101 :
3102 119 : case cdk_attrs:
3103 119 : decl = decl->declarator;
3104 119 : break;
3105 :
3106 : case cdk_id:
3107 : decl = 0;
3108 : break;
3109 :
3110 0 : default:
3111 0 : gcc_unreachable ();
3112 : }
3113 :
3114 : /* If it exists and is cdk_function declaration whose
3115 : arguments have not been set yet, use its arguments. */
3116 15336001 : if (last_non_id_attrs
3117 14715017 : && last_non_id_attrs->kind == cdk_function)
3118 : {
3119 14715017 : tree parms = last_non_id_attrs->u.arg_info->parms;
3120 14715017 : if (DECL_ARGUMENTS (d) == NULL_TREE
3121 14715017 : && DECL_INITIAL (d) == NULL_TREE)
3122 14182742 : DECL_ARGUMENTS (d) = parms;
3123 :
3124 14715017 : warn_parms_array_mismatch (lastloc, d, parms);
3125 : }
3126 : }
3127 22316630 : if (omp_declare_simd_clauses
3128 22316630 : || !omp_dsimd_idattr_clauses.is_empty ())
3129 : {
3130 507 : tree parms = NULL_TREE;
3131 507 : if (d && TREE_CODE (d) == FUNCTION_DECL)
3132 : {
3133 : struct c_declarator *ce = declarator;
3134 496 : while (ce != NULL)
3135 496 : if (ce->kind == cdk_function)
3136 : {
3137 493 : parms = ce->u.arg_info->parms;
3138 493 : break;
3139 : }
3140 : else
3141 3 : ce = ce->declarator;
3142 : }
3143 493 : if (parms)
3144 267 : temp_store_parm_decls (d, parms);
3145 507 : if (omp_declare_simd_clauses)
3146 487 : c_finish_omp_declare_simd (parser, d, parms,
3147 : omp_declare_simd_clauses);
3148 507 : if (!specs->constexpr_p
3149 507 : && !omp_dsimd_idattr_clauses.is_empty ())
3150 22 : c_finish_omp_declare_simd (parser, d, parms,
3151 : &omp_dsimd_idattr_clauses);
3152 507 : if (parms)
3153 267 : temp_pop_parm_decls ();
3154 : }
3155 22316630 : if (oacc_routine_data)
3156 72 : c_finish_oacc_routine (oacc_routine_data, d, false);
3157 22316630 : if (d)
3158 22316622 : finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
3159 : NULL_TREE, asm_name);
3160 :
3161 22316630 : if (c_parser_next_token_is_keyword (parser, RID_IN))
3162 : {
3163 0 : if (d)
3164 0 : *objc_foreach_object_declaration = d;
3165 : else
3166 0 : *objc_foreach_object_declaration = error_mark_node;
3167 : }
3168 : }
3169 28737046 : if (c_parser_next_token_is (parser, CPP_COMMA))
3170 : {
3171 430972 : more_than_one_decl = true;
3172 430972 : if (any_auto_type_p || specs->constexpr_p)
3173 : {
3174 4 : error_at (here,
3175 : "%qs may only be used with a single declarator",
3176 : any_auto_type_p ? auto_type_keyword : "constexpr");
3177 3 : c_parser_skip_to_end_of_block_or_statement (parser);
3178 3 : return result;
3179 : }
3180 430969 : c_parser_consume_token (parser);
3181 430969 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3182 19 : all_prefix_attrs = chainon (c_parser_gnu_attributes (parser),
3183 : prefix_attrs);
3184 : else
3185 : all_prefix_attrs = prefix_attrs;
3186 430969 : continue;
3187 : }
3188 28306074 : else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3189 : {
3190 28305929 : if (!simple_ok)
3191 28305830 : c_parser_consume_token (parser);
3192 : return result;
3193 : }
3194 145 : else if (c_parser_next_token_is_keyword (parser, RID_IN))
3195 : {
3196 : /* This can only happen in Objective-C: we found the
3197 : 'in' that terminates the declaration inside an
3198 : Objective-C foreach statement. Do not consume the
3199 : token, so that the caller can use it to determine
3200 : that this indeed is a foreach context. */
3201 : return result;
3202 : }
3203 : else
3204 : {
3205 145 : if (!simple_ok)
3206 : {
3207 53 : c_parser_error (parser, "expected %<,%> or %<;%>");
3208 53 : c_parser_skip_to_end_of_block_or_statement (parser);
3209 : }
3210 : /* It's not valid to use if (int i = 2, j = 3). */
3211 92 : else if (more_than_one_decl)
3212 4 : error_at (here, "declaration in condition can only declare "
3213 : "a single object");
3214 : return result;
3215 : }
3216 : }
3217 37669369 : else if (any_auto_type_p || specs->constexpr_p)
3218 : {
3219 4 : error_at (here,
3220 : "%qs requires an initialized data declaration",
3221 : any_auto_type_p ? auto_type_keyword : "constexpr");
3222 4 : c_parser_skip_to_end_of_block_or_statement (parser);
3223 4 : return result;
3224 : }
3225 37669365 : else if (!fndef_ok)
3226 : {
3227 74 : if (simple_ok && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3228 : /* Let c_parser_selection_header emit the error. */;
3229 : else
3230 : {
3231 34 : c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
3232 : "%<asm%> or %<__attribute__%>");
3233 34 : c_parser_skip_to_end_of_block_or_statement (parser);
3234 : }
3235 : return result;
3236 : }
3237 : /* Function definition (nested or otherwise). */
3238 37669311 : if (nested)
3239 : {
3240 1619 : pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
3241 1619 : c_push_function_context ();
3242 : }
3243 :
3244 : /* If we're in an OpenMP "begin declare variant" block, the
3245 : name in the declarator refers to the base function. We need
3246 : to save that and modify the declarator to have the mangled
3247 : name for the variant function instead. */
3248 37669311 : tree dv_base = NULL_TREE;
3249 37669311 : tree dv_ctx = NULL_TREE;
3250 37669311 : if (!vec_safe_is_empty (current_omp_declare_variant_attribute))
3251 : {
3252 26 : c_omp_declare_variant_attr a
3253 26 : = current_omp_declare_variant_attribute->last ();
3254 26 : dv_ctx = copy_list (a.selector);
3255 26 : dv_base = omp_start_variant_function (declarator, dv_ctx);
3256 : }
3257 :
3258 37669311 : if (!start_function (specs, declarator, all_prefix_attrs))
3259 : {
3260 : /* At this point we've consumed:
3261 : declaration-specifiers declarator
3262 : and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
3263 : RID_ASM, RID_ATTRIBUTE, or RID_IN,
3264 : but the
3265 : declaration-specifiers declarator
3266 : aren't grokkable as a function definition, so we have
3267 : an error. */
3268 36 : gcc_assert (!c_parser_next_token_is (parser, CPP_SEMICOLON));
3269 36 : if (c_parser_next_token_starts_declspecs (parser))
3270 : {
3271 : /* If we have
3272 : declaration-specifiers declarator decl-specs
3273 : then assume we have a missing semicolon, which would
3274 : give us:
3275 : declaration-specifiers declarator decl-specs
3276 : ^
3277 : ;
3278 : <~~~~~~~~~ declaration ~~~~~~~~~~>
3279 : Use c_parser_require to get an error with a fix-it hint. */
3280 13 : c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>");
3281 13 : parser->error = false;
3282 : }
3283 : else
3284 : {
3285 : /* This can appear in many cases looking nothing like a
3286 : function definition, so we don't give a more specific
3287 : error suggesting there was one. */
3288 23 : c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
3289 : "or %<__attribute__%>");
3290 : }
3291 36 : if (nested)
3292 1 : c_pop_function_context ();
3293 : break;
3294 : }
3295 :
3296 37669275 : if (DECL_DECLARED_INLINE_P (current_function_decl))
3297 : tv = TV_PARSE_INLINE;
3298 : else
3299 704890 : tv = TV_PARSE_FUNC;
3300 37669275 : auto_timevar at (g_timer, tv);
3301 :
3302 : /* Parse old-style parameter declarations. ??? Attributes are
3303 : not allowed to start declaration specifiers here because of a
3304 : syntax conflict between a function declaration with attribute
3305 : suffix and a function definition with an attribute prefix on
3306 : first old-style parameter declaration. Following the old
3307 : parser, they are not accepted on subsequent old-style
3308 : parameter declarations either. However, there is no
3309 : ambiguity after the first declaration, nor indeed on the
3310 : first as long as we don't allow postfix attributes after a
3311 : declarator with a nonempty identifier list in a definition;
3312 : and postfix attributes have never been accepted here in
3313 : function definitions either. */
3314 37669275 : int save_debug_nonbind_markers_p = debug_nonbind_markers_p;
3315 37669275 : debug_nonbind_markers_p = 0;
3316 37669275 : c_parser_maybe_reclassify_token (parser);
3317 37669275 : while (c_parser_next_token_is_not (parser, CPP_EOF)
3318 75364490 : && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
3319 12978 : c_parser_declaration_or_fndef (parser, false, false, false,
3320 : true, false, false);
3321 37669275 : debug_nonbind_markers_p = save_debug_nonbind_markers_p;
3322 37669275 : store_parm_decls ();
3323 37669275 : if (omp_declare_simd_clauses)
3324 370 : c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
3325 : omp_declare_simd_clauses);
3326 37669275 : if (!omp_dsimd_idattr_clauses.is_empty ())
3327 4 : c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
3328 : &omp_dsimd_idattr_clauses);
3329 37669275 : if (oacc_routine_data)
3330 130 : c_finish_oacc_routine (oacc_routine_data, current_function_decl, true);
3331 37669275 : location_t startloc = c_parser_peek_token (parser)->location;
3332 37669275 : DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
3333 37669275 : = startloc;
3334 37669275 : location_t endloc = startloc;
3335 : /* If this function was in a "begin declare variant" block,
3336 : remember it. We will associate it with the base function at
3337 : the end of processing the translation unit, since it is permitted
3338 : for the variant definition to appear before the base declaration. */
3339 37669275 : if (dv_base && current_function_decl != error_mark_node)
3340 : {
3341 26 : omp_begin_declare_variant_map_entry e
3342 26 : = { current_function_decl, dv_base, dv_ctx };
3343 26 : vec_safe_push (omp_begin_declare_variant_map, e);
3344 : }
3345 :
3346 : /* If the definition was marked with __RTL, use the RTL parser now,
3347 : consuming the function body. */
3348 37669275 : if (specs->declspec_il == cdil_rtl)
3349 : {
3350 25 : endloc = c_parser_parse_rtl_body (parser, specs->gimple_or_rtl_pass);
3351 :
3352 : /* Normally, store_parm_decls sets next_is_function_body,
3353 : anticipating a function body. We need a push_scope/pop_scope
3354 : pair to flush out this state, or subsequent function parsing
3355 : will go wrong. */
3356 24 : push_scope ();
3357 24 : pop_scope ();
3358 :
3359 24 : finish_function (endloc);
3360 24 : return result;
3361 : }
3362 : /* If the definition was marked with __GIMPLE then parse the
3363 : function body as GIMPLE. */
3364 37669250 : else if (specs->declspec_il != cdil_none)
3365 : {
3366 1074 : bool saved = in_late_binary_op;
3367 1074 : in_late_binary_op = true;
3368 1074 : c_parser_parse_gimple_body (parser, specs->gimple_or_rtl_pass,
3369 1074 : specs->declspec_il,
3370 : specs->entry_bb_count);
3371 1074 : in_late_binary_op = saved;
3372 : }
3373 : else
3374 37668176 : fnbody = c_parser_compound_statement (parser, &endloc);
3375 37669249 : tree fndecl = current_function_decl;
3376 37669249 : if (nested && specs->declspec_il == cdil_none)
3377 : {
3378 1617 : tree decl = current_function_decl;
3379 : /* Mark nested functions as needing static-chain initially.
3380 : lower_nested_functions will recompute it but the
3381 : DECL_STATIC_CHAIN flag is also used before that happens,
3382 : by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
3383 1617 : DECL_STATIC_CHAIN (decl) = 1;
3384 1617 : add_stmt (fnbody);
3385 1617 : finish_function (endloc);
3386 1617 : c_pop_function_context ();
3387 1617 : add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
3388 1617 : }
3389 1 : else if (nested)
3390 : {
3391 1 : if (specs->declspec_il == cdil_rtl)
3392 0 : error ("%<__RTL%> function cannot be a nested function");
3393 : else
3394 1 : error ("%<__GIMPLE%> function cannot be a nested function");
3395 1 : finish_function (endloc);
3396 1 : c_pop_function_context ();
3397 : }
3398 : else
3399 : {
3400 37667631 : if (fnbody)
3401 37666558 : add_stmt (fnbody);
3402 37667631 : finish_function (endloc);
3403 : }
3404 : /* Get rid of the empty stmt list for GIMPLE/RTL. */
3405 37669249 : if (specs->declspec_il != cdil_none)
3406 1074 : DECL_SAVED_TREE (fndecl) = NULL_TREE;
3407 :
3408 37669249 : break;
3409 28737391 : }
3410 :
3411 37669285 : return result;
3412 : }
3413 :
3414 : /* Parse an asm-definition (asm() outside a function body). This is a
3415 : GNU extension.
3416 :
3417 : asm-definition:
3418 : simple-asm-expr ;
3419 : asm ( toplevel-asm-argument ) ;
3420 :
3421 : toplevel-asm-argument:
3422 : asm-string-literal
3423 : asm-string-literal : asm-operands[opt]
3424 : asm-string-literal : asm-operands[opt] : asm-operands[opt]
3425 :
3426 : The :: token is considered equivalent to two consecutive : tokens. */
3427 :
3428 : static void
3429 214 : c_parser_asm_definition (c_parser *parser)
3430 : {
3431 214 : location_t asm_loc = c_parser_peek_token (parser)->location;
3432 214 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3433 214 : c_parser_consume_token (parser);
3434 214 : matching_parens parens;
3435 214 : tree asm_str = NULL_TREE;
3436 214 : tree outputs = NULL_TREE, inputs = NULL_TREE;
3437 214 : if (!parens.require_open (parser))
3438 5 : goto done;
3439 209 : asm_str = c_parser_asm_string_literal (parser);
3440 209 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3441 : {
3442 154 : parens.require_close (parser);
3443 154 : goto done;
3444 : }
3445 73 : for (int section = 0; section < 2; ++section)
3446 : {
3447 71 : if (c_parser_next_token_is (parser, CPP_SCOPE))
3448 : {
3449 29 : ++section;
3450 29 : if (section == 2)
3451 : {
3452 0 : c_parser_error (parser, "expected %<)%>");
3453 1 : error_close_paren:
3454 1 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3455 1 : asm_str = NULL_TREE;
3456 1 : goto done;
3457 : }
3458 29 : c_parser_consume_token (parser);
3459 : }
3460 42 : else if (!c_parser_require (parser, CPP_COLON,
3461 : "expected %<:%> or %<)%>",
3462 : UNKNOWN_LOCATION, false))
3463 1 : goto error_close_paren;
3464 70 : if (!c_parser_next_token_is (parser, CPP_COLON)
3465 56 : && !c_parser_next_token_is (parser, CPP_SCOPE)
3466 126 : && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3467 : {
3468 56 : if (section)
3469 45 : inputs = c_parser_asm_operands (parser);
3470 : else
3471 11 : outputs = c_parser_asm_operands (parser);
3472 : }
3473 70 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3474 : break;
3475 : }
3476 :
3477 54 : if (!parens.require_close (parser))
3478 : {
3479 2 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3480 2 : asm_str = NULL_TREE;
3481 : }
3482 :
3483 54 : if (asm_str)
3484 52 : asm_str = build_asm_expr (asm_loc, asm_str, outputs, inputs,
3485 : NULL_TREE, NULL_TREE, false, false);
3486 212 : done:
3487 212 : if (asm_str)
3488 206 : symtab->finalize_toplevel_asm (asm_str);
3489 214 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3490 214 : }
3491 :
3492 : /* Parse a static assertion (C11 6.7.10).
3493 :
3494 : static_assert-declaration:
3495 : static_assert-declaration-no-semi ;
3496 : */
3497 :
3498 : static void
3499 2265 : c_parser_static_assert_declaration (c_parser *parser)
3500 : {
3501 2265 : c_parser_static_assert_declaration_no_semi (parser);
3502 2265 : if (parser->error
3503 2265 : || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
3504 8 : c_parser_skip_to_end_of_block_or_statement (parser);
3505 2265 : }
3506 :
3507 : /* Parse a static assertion (C11 6.7.10), without the trailing
3508 : semicolon.
3509 :
3510 : static_assert-declaration-no-semi:
3511 : _Static_assert ( constant-expression , string-literal )
3512 :
3513 : C23:
3514 : static_assert-declaration-no-semi:
3515 : _Static_assert ( constant-expression )
3516 : */
3517 :
3518 : static void
3519 2450 : c_parser_static_assert_declaration_no_semi (c_parser *parser)
3520 : {
3521 2450 : location_t assert_loc, value_loc;
3522 2450 : tree value;
3523 2450 : tree string = NULL_TREE;
3524 :
3525 2450 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
3526 2450 : tree spelling = c_parser_peek_token (parser)->value;
3527 2450 : assert_loc = c_parser_peek_token (parser)->location;
3528 2450 : if (flag_isoc99)
3529 2446 : pedwarn_c99 (assert_loc, OPT_Wpedantic,
3530 : "ISO C99 does not support %qE", spelling);
3531 : else
3532 4 : pedwarn_c99 (assert_loc, OPT_Wpedantic,
3533 : "ISO C90 does not support %qE", spelling);
3534 2450 : c_parser_consume_token (parser);
3535 2450 : matching_parens parens;
3536 2450 : if (!parens.require_open (parser))
3537 15 : return;
3538 2449 : location_t value_tok_loc = c_parser_peek_token (parser)->location;
3539 2449 : value = convert_lvalue_to_rvalue (value_tok_loc,
3540 : c_parser_expr_no_commas (parser, NULL),
3541 : true, true).value;
3542 2449 : value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc);
3543 2449 : if (c_parser_next_token_is (parser, CPP_COMMA))
3544 : {
3545 1785 : c_parser_consume_token (parser);
3546 1785 : switch (c_parser_peek_token (parser)->type)
3547 : {
3548 1782 : case CPP_STRING:
3549 1782 : case CPP_STRING16:
3550 1782 : case CPP_STRING32:
3551 1782 : case CPP_WSTRING:
3552 1782 : case CPP_UTF8STRING:
3553 1782 : string = c_parser_string_literal (parser, false, true).value;
3554 1782 : break;
3555 3 : default:
3556 3 : c_parser_error (parser, "expected string literal");
3557 3 : return;
3558 : }
3559 : }
3560 664 : else if (flag_isoc11)
3561 : /* If pedantic for pre-C11, the use of _Static_assert itself will
3562 : have been diagnosed, so do not also diagnose the use of this
3563 : new C23 feature of _Static_assert. */
3564 662 : pedwarn_c11 (assert_loc, OPT_Wpedantic,
3565 : "ISO C11 does not support omitting the string in "
3566 : "%qE", spelling);
3567 2446 : parens.require_close (parser);
3568 :
3569 2446 : if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
3570 : {
3571 5 : error_at (value_loc, "expression in static assertion is not an integer");
3572 5 : return;
3573 : }
3574 2441 : if (TREE_CODE (value) != INTEGER_CST)
3575 : {
3576 12 : value = c_fully_fold (value, false, NULL);
3577 : /* Strip no-op conversions. */
3578 24 : STRIP_TYPE_NOPS (value);
3579 12 : if (TREE_CODE (value) == INTEGER_CST)
3580 6 : pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
3581 : "is not an integer constant expression");
3582 : }
3583 2441 : if (TREE_CODE (value) != INTEGER_CST)
3584 : {
3585 6 : error_at (value_loc, "expression in static assertion is not constant");
3586 6 : return;
3587 : }
3588 2435 : constant_expression_warning (value);
3589 2435 : if (integer_zerop (value))
3590 : {
3591 41 : if (string)
3592 22 : error_at (assert_loc, "static assertion failed: %E", string);
3593 : else
3594 19 : error_at (assert_loc, "static assertion failed");
3595 : }
3596 : }
3597 :
3598 : /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
3599 : 6.7, C11 6.7), adding them to SPECS (which may already include some).
3600 : Storage class specifiers are accepted iff SCSPEC_OK; type
3601 : specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
3602 : accepted iff ALIGNSPEC_OK; gnu-attributes are accepted at the start
3603 : iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK. In
3604 : addition to the syntax shown, standard attributes are accepted at
3605 : the start iff START_STD_ATTR_OK and at the end iff END_STD_ATTR_OK;
3606 : unlike gnu-attributes, they are not accepted in the middle of the
3607 : list. (This combines various different syntax productions in the C
3608 : standard, and in some cases gnu-attributes and standard attributes
3609 : at the start may already have been parsed before this function is
3610 : called.)
3611 :
3612 : declaration-specifiers:
3613 : storage-class-specifier declaration-specifiers[opt]
3614 : type-specifier declaration-specifiers[opt]
3615 : type-qualifier declaration-specifiers[opt]
3616 : function-specifier declaration-specifiers[opt]
3617 : alignment-specifier declaration-specifiers[opt]
3618 :
3619 : Function specifiers (inline) are from C99, and are currently
3620 : handled as storage class specifiers, as is __thread. Alignment
3621 : specifiers are from C11.
3622 :
3623 : C90 6.5.1, C99 6.7.1, C11 6.7.1:
3624 : storage-class-specifier:
3625 : typedef
3626 : extern
3627 : static
3628 : auto
3629 : register
3630 : _Thread_local
3631 :
3632 : (_Thread_local is new in C11.)
3633 :
3634 : C99 6.7.4, C11 6.7.4:
3635 : function-specifier:
3636 : inline
3637 : _Noreturn
3638 :
3639 : (_Noreturn is new in C11.)
3640 :
3641 : C90 6.5.2, C99 6.7.2, C11 6.7.2:
3642 : type-specifier:
3643 : void
3644 : char
3645 : short
3646 : int
3647 : long
3648 : float
3649 : double
3650 : signed
3651 : unsigned
3652 : _Bool
3653 : _Complex
3654 : [_Imaginary removed in C99 TC2]
3655 : _BitInt ( constant-expression )
3656 : struct-or-union-specifier
3657 : enum-specifier
3658 : typedef-name
3659 : atomic-type-specifier
3660 :
3661 : (_Bool and _Complex are new in C99.)
3662 : (atomic-type-specifier is new in C11.)
3663 : (_BitInt is new in C23.)
3664 :
3665 : C90 6.5.3, C99 6.7.3, C11 6.7.3:
3666 :
3667 : type-qualifier:
3668 : const
3669 : restrict
3670 : volatile
3671 : address-space-qualifier
3672 : _Atomic
3673 :
3674 : (restrict is new in C99.)
3675 : (_Atomic is new in C11.)
3676 :
3677 : GNU extensions:
3678 :
3679 : declaration-specifiers:
3680 : gnu-attributes declaration-specifiers[opt]
3681 :
3682 : type-qualifier:
3683 : address-space
3684 :
3685 : address-space:
3686 : identifier recognized by the target
3687 :
3688 : storage-class-specifier:
3689 : __thread
3690 :
3691 : type-specifier:
3692 : typeof-specifier
3693 : __auto_type
3694 : __intN
3695 : _Decimal32
3696 : _Decimal64
3697 : _Decimal128
3698 : _Fract
3699 : _Accum
3700 : _Sat
3701 :
3702 : (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
3703 : http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
3704 :
3705 : atomic-type-specifier
3706 : _Atomic ( type-name )
3707 :
3708 : Objective-C:
3709 :
3710 : type-specifier:
3711 : class-name objc-protocol-refs[opt]
3712 : typedef-name objc-protocol-refs
3713 : objc-protocol-refs
3714 : */
3715 :
3716 : void
3717 345554547 : c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
3718 : bool scspec_ok, bool typespec_ok, bool start_attr_ok,
3719 : bool alignspec_ok, bool auto_type_ok,
3720 : bool start_std_attr_ok, bool end_std_attr_ok,
3721 : enum c_lookahead_kind la)
3722 : {
3723 345554547 : bool attrs_ok = start_attr_ok;
3724 345554547 : bool seen_type = specs->typespec_kind != ctsk_none;
3725 :
3726 345554547 : if (!typespec_ok)
3727 19943404 : gcc_assert (la == cla_prefer_id);
3728 :
3729 345554547 : if (start_std_attr_ok
3730 345554547 : && c_parser_nth_token_starts_std_attributes (parser, 1))
3731 : {
3732 1482 : gcc_assert (!specs->non_std_attrs_seen_p);
3733 1482 : location_t loc = c_parser_peek_token (parser)->location;
3734 1482 : tree attrs = c_parser_std_attribute_specifier_sequence (parser);
3735 1482 : declspecs_add_attrs (loc, specs, attrs);
3736 1482 : specs->non_std_attrs_seen_p = false;
3737 : }
3738 :
3739 837612380 : while (c_parser_next_token_is (parser, CPP_NAME)
3740 388999866 : || c_parser_next_token_is (parser, CPP_KEYWORD)
3741 989171141 : || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
3742 : {
3743 686053619 : struct c_typespec t;
3744 686053619 : tree attrs;
3745 686053619 : tree align;
3746 686053619 : location_t loc = c_parser_peek_token (parser)->location;
3747 :
3748 : /* If we cannot accept a type, exit if the next token must start
3749 : one. Also, if we already have seen a tagged definition,
3750 : a typename would be an error anyway and likely the user
3751 : has simply forgotten a semicolon, so we exit. */
3752 669363383 : if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
3753 17632792 : && c_parser_next_tokens_start_typename (parser, la)
3754 3938211 : && !c_parser_next_token_is_qualifier (parser)
3755 686053746 : && !c_parser_next_token_is_keyword (parser, RID_ALIGNAS))
3756 : break;
3757 :
3758 686053501 : if (c_parser_next_token_is (parser, CPP_NAME))
3759 : {
3760 448612408 : c_token *name_token = c_parser_peek_token (parser);
3761 448612408 : tree value = name_token->value;
3762 448612408 : c_id_kind kind = name_token->id_kind;
3763 :
3764 448612408 : if (kind == C_ID_ADDRSPACE)
3765 : {
3766 178 : addr_space_t as
3767 178 : = name_token->keyword - RID_FIRST_ADDR_SPACE;
3768 178 : declspecs_add_addrspace (name_token->location, specs, as);
3769 178 : c_parser_consume_token (parser);
3770 178 : attrs_ok = true;
3771 254619383 : continue;
3772 178 : }
3773 :
3774 448612230 : gcc_assert (!c_parser_next_token_is_qualifier (parser));
3775 :
3776 : /* If we cannot accept a type, and the next token must start one,
3777 : exit. Do the same if we already have seen a tagged definition,
3778 : since it would be an error anyway and likely the user has simply
3779 : forgotten a semicolon. */
3780 448612230 : if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
3781 : break;
3782 :
3783 : /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
3784 : a C_ID_CLASSNAME. */
3785 254619205 : c_parser_consume_token (parser);
3786 254619205 : seen_type = true;
3787 254619205 : attrs_ok = true;
3788 254619205 : if (kind == C_ID_ID)
3789 : {
3790 51 : auto_diagnostic_group d;
3791 51 : name_hint hint = lookup_name_fuzzy (value, FUZZY_LOOKUP_TYPENAME,
3792 51 : loc);
3793 51 : if (const char *suggestion = hint.suggestion ())
3794 : {
3795 2 : gcc_rich_location richloc (loc);
3796 2 : richloc.add_fixit_replace (suggestion);
3797 2 : error_at (&richloc,
3798 : "unknown type name %qE; did you mean %qs?",
3799 : value, suggestion);
3800 2 : }
3801 : else
3802 49 : error_at (loc, "unknown type name %qE", value);
3803 51 : t.kind = ctsk_typedef;
3804 51 : t.spec = error_mark_node;
3805 51 : }
3806 254619154 : else if (kind == C_ID_TYPENAME
3807 254619154 : && (!c_dialect_objc ()
3808 0 : || c_parser_next_token_is_not (parser, CPP_LESS)))
3809 : {
3810 254619154 : t.kind = ctsk_typedef;
3811 : /* For a typedef name, record the meaning, not the name.
3812 : In case of 'foo foo, bar;'. */
3813 254619154 : t.spec = lookup_name (value);
3814 : }
3815 : else
3816 : {
3817 0 : tree proto = NULL_TREE;
3818 0 : gcc_assert (c_dialect_objc ());
3819 0 : t.kind = ctsk_objc;
3820 0 : if (c_parser_next_token_is (parser, CPP_LESS))
3821 0 : proto = c_parser_objc_protocol_refs (parser);
3822 0 : t.spec = objc_get_protocol_qualified_type (value, proto);
3823 : }
3824 254619205 : t.expr = NULL_TREE;
3825 254619205 : t.expr_const_operands = true;
3826 254619205 : t.has_enum_type_specifier = false;
3827 254619205 : declspecs_add_type (name_token->location, specs, t);
3828 254619205 : continue;
3829 254619205 : }
3830 237441093 : if (c_parser_next_token_is (parser, CPP_LESS))
3831 : {
3832 : /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
3833 : nisse@lysator.liu.se. */
3834 0 : tree proto;
3835 0 : gcc_assert (c_dialect_objc ());
3836 0 : if (!typespec_ok || seen_type)
3837 : break;
3838 0 : proto = c_parser_objc_protocol_refs (parser);
3839 0 : t.kind = ctsk_objc;
3840 0 : t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
3841 0 : t.expr = NULL_TREE;
3842 0 : t.expr_const_operands = true;
3843 0 : t.has_enum_type_specifier = false;
3844 0 : declspecs_add_type (loc, specs, t);
3845 0 : continue;
3846 0 : }
3847 237441093 : gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
3848 237441093 : switch (c_parser_peek_token (parser)->keyword)
3849 : {
3850 93778018 : case RID_STATIC:
3851 93778018 : case RID_EXTERN:
3852 93778018 : case RID_REGISTER:
3853 93778018 : case RID_TYPEDEF:
3854 93778018 : case RID_INLINE:
3855 93778018 : case RID_NORETURN:
3856 93778018 : case RID_AUTO:
3857 93778018 : case RID_THREAD:
3858 93778018 : case RID_CONSTEXPR:
3859 93778018 : if (!scspec_ok)
3860 2643 : goto out;
3861 93777885 : attrs_ok = true;
3862 : /* TODO: Distinguish between function specifiers (inline, noreturn)
3863 : and storage class specifiers, either here or in
3864 : declspecs_add_scspec. */
3865 93777885 : declspecs_add_scspec (loc, specs,
3866 93777885 : c_parser_peek_token (parser)->value);
3867 93777885 : c_parser_consume_token (parser);
3868 93777885 : break;
3869 1898 : case RID_AUTO_TYPE:
3870 1898 : if (!auto_type_ok)
3871 0 : goto out;
3872 : /* Fall through. */
3873 85794426 : case RID_UNSIGNED:
3874 85794426 : case RID_LONG:
3875 85794426 : case RID_SHORT:
3876 85794426 : case RID_SIGNED:
3877 85794426 : case RID_COMPLEX:
3878 85794426 : case RID_INT:
3879 85794426 : case RID_CHAR:
3880 85794426 : case RID_FLOAT:
3881 85794426 : case RID_DOUBLE:
3882 85794426 : case RID_VOID:
3883 85794426 : case RID_DFLOAT32:
3884 85794426 : case RID_DFLOAT64:
3885 85794426 : case RID_DFLOAT128:
3886 85794426 : case RID_DFLOAT64X:
3887 85794426 : CASE_RID_FLOATN_NX:
3888 85794426 : case RID_BOOL:
3889 85794426 : case RID_FRACT:
3890 85794426 : case RID_ACCUM:
3891 85794426 : case RID_SAT:
3892 85794426 : case RID_INT_N_0:
3893 85794426 : case RID_INT_N_1:
3894 85794426 : case RID_INT_N_2:
3895 85794426 : case RID_INT_N_3:
3896 85794426 : if (!typespec_ok)
3897 0 : goto out;
3898 85794426 : attrs_ok = true;
3899 85794426 : seen_type = true;
3900 85794426 : if (c_dialect_objc ())
3901 0 : parser->objc_need_raw_identifier = true;
3902 85794426 : t.kind = ctsk_resword;
3903 85794426 : t.spec = c_parser_peek_token (parser)->value;
3904 85794426 : t.expr = NULL_TREE;
3905 85794426 : t.expr_const_operands = true;
3906 85794426 : t.has_enum_type_specifier = false;
3907 85794426 : declspecs_add_type (loc, specs, t);
3908 85794426 : c_parser_consume_token (parser);
3909 85794426 : break;
3910 246436 : case RID_ENUM:
3911 246436 : if (!typespec_ok)
3912 0 : goto out;
3913 246436 : attrs_ok = true;
3914 246436 : seen_type = true;
3915 246436 : t = c_parser_enum_specifier (parser);
3916 246436 : invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
3917 246436 : declspecs_add_type (loc, specs, t);
3918 246436 : break;
3919 2239083 : case RID_STRUCT:
3920 2239083 : case RID_UNION:
3921 2239083 : if (!typespec_ok)
3922 0 : goto out;
3923 2239083 : attrs_ok = true;
3924 2239083 : seen_type = true;
3925 2239083 : t = c_parser_struct_or_union_specifier (parser);
3926 2239083 : invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
3927 2239083 : declspecs_add_type (loc, specs, t);
3928 2239083 : break;
3929 822190 : case RID_TYPEOF:
3930 822190 : case RID_TYPEOF_UNQUAL:
3931 : /* ??? The old parser rejected typeof after other type
3932 : specifiers, but is a syntax error the best way of
3933 : handling this? */
3934 822190 : if (!typespec_ok || seen_type)
3935 2 : goto out;
3936 822188 : attrs_ok = true;
3937 822188 : seen_type = true;
3938 822188 : t = c_parser_typeof_specifier (parser);
3939 822188 : declspecs_add_type (loc, specs, t);
3940 822188 : break;
3941 48165 : case RID_BITINT:
3942 48165 : if (!typespec_ok)
3943 0 : goto out;
3944 : else
3945 : {
3946 48165 : attrs_ok = true;
3947 48165 : seen_type = true;
3948 48165 : t.kind = ctsk_resword;
3949 48165 : t.spec = c_parser_peek_token (parser)->value;
3950 48165 : t.expr = error_mark_node;
3951 48165 : t.expr_const_operands = true;
3952 48165 : t.has_enum_type_specifier = false;
3953 48165 : c_parser_consume_token (parser);
3954 48165 : matching_parens parens;
3955 48165 : if (parens.require_open (parser))
3956 : {
3957 48165 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
3958 48165 : t.expr = convert_lvalue_to_rvalue (loc, expr, true,
3959 48165 : true).value;
3960 48165 : parens.skip_until_found_close (parser);
3961 : }
3962 48165 : declspecs_add_type (loc, specs, t);
3963 : }
3964 48165 : break;
3965 33945 : case RID_ATOMIC:
3966 : /* C parser handling of Objective-C constructs needs
3967 : checking for correct lvalue-to-rvalue conversions, and
3968 : the code in build_modify_expr handling various
3969 : Objective-C cases, and that in build_unary_op handling
3970 : Objective-C cases for increment / decrement, also needs
3971 : updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
3972 : and objc_types_are_equivalent may also need updates. */
3973 33945 : if (c_dialect_objc ())
3974 0 : sorry ("%<_Atomic%> in Objective-C");
3975 33945 : if (flag_isoc99)
3976 33894 : pedwarn_c99 (loc, OPT_Wpedantic,
3977 : "ISO C99 does not support the %<_Atomic%> qualifier");
3978 : else
3979 51 : pedwarn_c99 (loc, OPT_Wpedantic,
3980 : "ISO C90 does not support the %<_Atomic%> qualifier");
3981 33945 : attrs_ok = true;
3982 33945 : tree value;
3983 33945 : value = c_parser_peek_token (parser)->value;
3984 33945 : c_parser_consume_token (parser);
3985 67680 : if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3986 : {
3987 : /* _Atomic ( type-name ). */
3988 13431 : seen_type = true;
3989 13431 : c_parser_consume_token (parser);
3990 13431 : struct c_type_name *type = c_parser_type_name (parser);
3991 13431 : t.kind = ctsk_typeof;
3992 13431 : t.spec = error_mark_node;
3993 13431 : t.expr = NULL_TREE;
3994 13431 : t.expr_const_operands = true;
3995 13431 : t.has_enum_type_specifier = false;
3996 13431 : if (type != NULL)
3997 13430 : t.spec = groktypename (type, &t.expr,
3998 : &t.expr_const_operands);
3999 13431 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4000 : "expected %<)%>");
4001 13431 : if (t.spec != error_mark_node)
4002 : {
4003 13430 : if (TREE_CODE (t.spec) == ARRAY_TYPE)
4004 1 : error_at (loc, "%<_Atomic%>-qualified array type");
4005 13429 : else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
4006 1 : error_at (loc, "%<_Atomic%>-qualified function type");
4007 13428 : else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
4008 4 : error_at (loc, "%<_Atomic%> applied to a qualified type");
4009 : else
4010 13424 : t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
4011 : }
4012 13431 : declspecs_add_type (loc, specs, t);
4013 : }
4014 : else
4015 20514 : declspecs_add_qual (loc, specs, value);
4016 : break;
4017 17196503 : case RID_CONST:
4018 17196503 : case RID_VOLATILE:
4019 17196503 : case RID_RESTRICT:
4020 17196503 : attrs_ok = true;
4021 17196503 : declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
4022 17196503 : c_parser_consume_token (parser);
4023 17196503 : break;
4024 37278517 : case RID_ATTRIBUTE:
4025 37278517 : if (!attrs_ok)
4026 0 : goto out;
4027 37278517 : attrs = c_parser_gnu_attributes (parser);
4028 37278517 : declspecs_add_attrs (loc, specs, attrs);
4029 37278517 : break;
4030 218 : case RID_ALIGNAS:
4031 218 : if (!alignspec_ok)
4032 16 : goto out;
4033 202 : align = c_parser_alignas_specifier (parser);
4034 202 : declspecs_add_alignas (loc, specs, align);
4035 202 : break;
4036 1075 : case RID_GIMPLE:
4037 1075 : if (! flag_gimple)
4038 0 : error_at (loc, "%<__GIMPLE%> only valid with %<-fgimple%>");
4039 1075 : c_parser_consume_token (parser);
4040 1075 : specs->declspec_il = cdil_gimple;
4041 1075 : specs->locations[cdw_gimple] = loc;
4042 1075 : c_parser_gimple_or_rtl_pass_list (parser, specs);
4043 1075 : break;
4044 25 : case RID_RTL:
4045 25 : c_parser_consume_token (parser);
4046 25 : specs->declspec_il = cdil_rtl;
4047 25 : specs->locations[cdw_rtl] = loc;
4048 25 : c_parser_gimple_or_rtl_pass_list (parser, specs);
4049 25 : break;
4050 2492 : default:
4051 2492 : goto out;
4052 : }
4053 : }
4054 345554547 : out:
4055 345554547 : if (end_std_attr_ok
4056 345554547 : && c_parser_nth_token_starts_std_attributes (parser, 1))
4057 119 : specs->postfix_attrs = c_parser_std_attribute_specifier_sequence (parser);
4058 345554547 : }
4059 :
4060 : /* Complain about a non-CPP_NAME within an enumerator list. */
4061 :
4062 : static void
4063 11 : report_bad_enum_name (c_parser *parser)
4064 : {
4065 11 : if (!parser->error)
4066 : {
4067 11 : c_token *token = c_parser_peek_token (parser);
4068 11 : switch (token->type)
4069 : {
4070 : default:
4071 : break;
4072 6 : case CPP_CLOSE_BRACE:
4073 : /* Give a nicer error for "enum {}". */
4074 6 : error_at (token->location,
4075 : "empty enum is invalid");
4076 6 : parser->error = true;
4077 6 : return;
4078 3 : case CPP_KEYWORD:
4079 : /* Give a nicer error for attempts to use "true" and "false"
4080 : in enums with C23 onwards. */
4081 3 : if (token->keyword == RID_FALSE
4082 2 : || token->keyword == RID_TRUE)
4083 : {
4084 2 : auto_diagnostic_group d;
4085 4 : error_at (token->location,
4086 : "cannot use keyword %qs as enumeration constant",
4087 2 : IDENTIFIER_POINTER (token->value));
4088 2 : add_note_about_new_keyword (token->location,
4089 : token->value);
4090 2 : parser->error = true;
4091 2 : return;
4092 2 : }
4093 : break;
4094 : }
4095 : }
4096 :
4097 : /* Otherwise, a more generic error message. */
4098 3 : c_parser_error (parser, "expected identifier");
4099 : }
4100 :
4101 : /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
4102 :
4103 : enum-specifier:
4104 : enum gnu-attributes[opt] identifier[opt] enum-type-specifier[opt]
4105 : { enumerator-list } gnu-attributes[opt]
4106 : enum gnu-attributes[opt] identifier[opt] enum-type-specifier[opt]
4107 : { enumerator-list , } gnu-attributes[opt] enum-type-specifier[opt]
4108 : enum gnu-attributes[opt] identifier
4109 :
4110 : The form with trailing comma is new in C99; enum-type-specifiers
4111 : are new in C23. The forms with gnu-attributes are GNU extensions.
4112 : In GNU C, we accept any expression without commas in the syntax
4113 : (assignment expressions, not just conditional expressions);
4114 : assignment expressions will be diagnosed as non-constant.
4115 :
4116 : enum-type-specifier:
4117 : : specifier-qualifier-list
4118 :
4119 : enumerator-list:
4120 : enumerator
4121 : enumerator-list , enumerator
4122 :
4123 : enumerator:
4124 : enumeration-constant attribute-specifier-sequence[opt]
4125 : enumeration-constant attribute-specifier-sequence[opt]
4126 : = constant-expression
4127 :
4128 : GNU Extensions:
4129 :
4130 : enumerator:
4131 : enumeration-constant attribute-specifier-sequence[opt] gnu-attributes[opt]
4132 : enumeration-constant attribute-specifier-sequence[opt] gnu-attributes[opt]
4133 : = constant-expression
4134 :
4135 : */
4136 :
4137 : static struct c_typespec
4138 246436 : c_parser_enum_specifier (c_parser *parser)
4139 : {
4140 246436 : struct c_typespec ret;
4141 246436 : bool have_std_attrs;
4142 246436 : bool potential_nesting_p = false;
4143 246436 : tree std_attrs = NULL_TREE;
4144 246436 : tree attrs;
4145 246436 : tree ident = NULL_TREE;
4146 246436 : tree fixed_underlying_type = NULL_TREE;
4147 246436 : location_t enum_loc;
4148 246436 : location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4149 246436 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
4150 246436 : c_parser_consume_token (parser);
4151 246436 : have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1);
4152 246436 : if (have_std_attrs)
4153 14 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
4154 246436 : attrs = c_parser_gnu_attributes (parser);
4155 246436 : enum_loc = c_parser_peek_token (parser)->location;
4156 : /* Set the location in case we create a decl now. */
4157 246436 : c_parser_set_source_position_from_token (c_parser_peek_token (parser));
4158 246436 : if (c_parser_next_token_is (parser, CPP_NAME))
4159 : {
4160 135211 : ident = c_parser_peek_token (parser)->value;
4161 135211 : ident_loc = c_parser_peek_token (parser)->location;
4162 135211 : enum_loc = ident_loc;
4163 135211 : c_parser_consume_token (parser);
4164 : }
4165 246436 : if (c_parser_next_token_is (parser, CPP_COLON)
4166 : /* Distinguish an enum-type-specifier from a bit-field
4167 : declaration of the form "enum e : constant-expression;". */
4168 246436 : && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4169 : {
4170 194 : pedwarn_c11 (enum_loc, OPT_Wpedantic,
4171 : "ISO C does not support specifying %<enum%> underlying "
4172 : "types before C23");
4173 194 : if (ident)
4174 : {
4175 : /* The tag is in scope during the enum-type-specifier (which
4176 : may refer to the tag inside typeof). */
4177 190 : ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident,
4178 : have_std_attrs, std_attrs, true);
4179 190 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (ret.spec))
4180 3 : error_at (enum_loc, "%<enum%> declared both with and without "
4181 : "fixed underlying type");
4182 190 : potential_nesting_p = NULL_TREE == TYPE_VALUES (ret.spec);
4183 : }
4184 : else
4185 : {
4186 : /* There must be an enum definition, so this initialization
4187 : (to avoid possible warnings about uninitialized data)
4188 : will be replaced later (either with the results of that
4189 : definition, or with the results of error handling for the
4190 : case of no tag and no definition). */
4191 4 : ret.spec = NULL_TREE;
4192 4 : ret.kind = ctsk_tagdef;
4193 4 : ret.expr = NULL_TREE;
4194 4 : ret.expr_const_operands = true;
4195 4 : ret.has_enum_type_specifier = true;
4196 : }
4197 194 : c_parser_consume_token (parser);
4198 194 : struct c_declspecs *specs = build_null_declspecs ();
4199 194 : c_parser_declspecs (parser, specs, false, true, false, false, false,
4200 : false, true, cla_prefer_id);
4201 194 : finish_declspecs (specs);
4202 194 : if (specs->default_int_p)
4203 1 : error_at (enum_loc, "no %<enum%> underlying type specified");
4204 193 : else if (TREE_CODE (specs->type) != INTEGER_TYPE
4205 193 : && TREE_CODE (specs->type) != BOOLEAN_TYPE
4206 29 : && (!flag_isoc2y || TREE_CODE (specs->type) != BITINT_TYPE))
4207 : {
4208 9 : error_at (enum_loc, "invalid %<enum%> underlying type");
4209 9 : specs->type = integer_type_node;
4210 : }
4211 184 : else if (specs->restrict_p)
4212 1 : error_at (enum_loc, "invalid use of %<restrict%>");
4213 194 : fixed_underlying_type = TYPE_MAIN_VARIANT (specs->type);
4214 194 : if (ident)
4215 : {
4216 : /* The type specified must be consistent with any previously
4217 : specified underlying type. If this is a newly declared
4218 : type, it is now a complete type. */
4219 190 : if (ENUM_FIXED_UNDERLYING_TYPE_P (ret.spec)
4220 190 : && ENUM_UNDERLYING_TYPE (ret.spec) == NULL_TREE)
4221 : {
4222 507 : TYPE_MIN_VALUE (ret.spec) =
4223 169 : TYPE_MIN_VALUE (fixed_underlying_type);
4224 507 : TYPE_MAX_VALUE (ret.spec) =
4225 169 : TYPE_MAX_VALUE (fixed_underlying_type);
4226 169 : TYPE_UNSIGNED (ret.spec) = TYPE_UNSIGNED (fixed_underlying_type);
4227 169 : SET_TYPE_ALIGN (ret.spec, TYPE_ALIGN (fixed_underlying_type));
4228 169 : TYPE_SIZE (ret.spec) = NULL_TREE;
4229 169 : TYPE_PRECISION (ret.spec) =
4230 169 : TYPE_PRECISION (fixed_underlying_type);
4231 169 : ENUM_UNDERLYING_TYPE (ret.spec) = fixed_underlying_type;
4232 169 : layout_type (ret.spec);
4233 : }
4234 21 : else if (ENUM_FIXED_UNDERLYING_TYPE_P (ret.spec)
4235 37 : && !comptypes (fixed_underlying_type,
4236 16 : ENUM_UNDERLYING_TYPE (ret.spec)))
4237 : {
4238 3 : error_at (enum_loc, "%<enum%> underlying type incompatible with "
4239 : "previous declaration");
4240 3 : fixed_underlying_type = ENUM_UNDERLYING_TYPE (ret.spec);
4241 : }
4242 : }
4243 : }
4244 246436 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4245 : {
4246 : /* Parse an enum definition. */
4247 186491 : struct c_enum_contents the_enum;
4248 186491 : tree type;
4249 186491 : tree postfix_attrs;
4250 : /* We chain the enumerators in reverse order, then put them in
4251 : forward order at the end. */
4252 186491 : tree values;
4253 186491 : timevar_push (TV_PARSE_ENUM);
4254 186491 : type = start_enum (enum_loc, &the_enum, ident, fixed_underlying_type,
4255 : potential_nesting_p);
4256 186491 : values = NULL_TREE;
4257 186491 : c_parser_consume_token (parser);
4258 5818394 : while (true)
4259 : {
4260 5818394 : tree enum_id;
4261 5818394 : tree enum_value;
4262 5818394 : tree enum_decl;
4263 5818394 : bool seen_comma;
4264 5818394 : c_token *token;
4265 5818394 : location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4266 5818394 : location_t decl_loc, value_loc;
4267 5818394 : if (c_parser_next_token_is_not (parser, CPP_NAME))
4268 : {
4269 11 : report_bad_enum_name (parser);
4270 11 : c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
4271 11 : values = error_mark_node;
4272 11 : break;
4273 : }
4274 5818383 : token = c_parser_peek_token (parser);
4275 5818383 : enum_id = token->value;
4276 : /* Set the location in case we create a decl now. */
4277 5818383 : c_parser_set_source_position_from_token (token);
4278 5818383 : decl_loc = value_loc = token->location;
4279 5818383 : c_parser_consume_token (parser);
4280 : /* Parse any specified attributes. */
4281 5818383 : tree std_attrs = NULL_TREE;
4282 5818383 : if (c_parser_nth_token_starts_std_attributes (parser, 1))
4283 12 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
4284 5818383 : tree enum_attrs = chainon (std_attrs,
4285 : c_parser_gnu_attributes (parser));
4286 5818383 : if (c_parser_next_token_is (parser, CPP_EQ))
4287 : {
4288 3640112 : c_parser_consume_token (parser);
4289 3640112 : value_loc = c_parser_peek_token (parser)->location;
4290 3640112 : enum_value = convert_lvalue_to_rvalue (value_loc,
4291 : (c_parser_expr_no_commas
4292 : (parser, NULL)),
4293 : true, true).value;
4294 : }
4295 : else
4296 : enum_value = NULL_TREE;
4297 5818383 : enum_decl = build_enumerator (decl_loc, value_loc,
4298 : &the_enum, enum_id, enum_value);
4299 5818383 : if (enum_attrs)
4300 3737 : decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0);
4301 5818383 : TREE_CHAIN (enum_decl) = values;
4302 5818383 : values = enum_decl;
4303 5818383 : seen_comma = false;
4304 5818383 : if (c_parser_next_token_is (parser, CPP_COMMA))
4305 : {
4306 5653140 : comma_loc = c_parser_peek_token (parser)->location;
4307 5653140 : seen_comma = true;
4308 5653140 : c_parser_consume_token (parser);
4309 : }
4310 5818383 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4311 : {
4312 186465 : if (seen_comma)
4313 21237 : pedwarn_c90 (comma_loc, OPT_Wpedantic,
4314 : "comma at end of enumerator list");
4315 186465 : c_parser_consume_token (parser);
4316 186465 : break;
4317 : }
4318 5631918 : if (!seen_comma)
4319 : {
4320 15 : c_parser_error (parser, "expected %<,%> or %<}%>");
4321 15 : c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
4322 15 : values = error_mark_node;
4323 15 : break;
4324 : }
4325 : }
4326 186491 : postfix_attrs = c_parser_gnu_attributes (parser);
4327 186491 : ret.spec = finish_enum (type, nreverse (values),
4328 : chainon (std_attrs,
4329 : chainon (attrs, postfix_attrs)));
4330 186491 : ret.kind = ctsk_tagdef;
4331 186491 : ret.expr = NULL_TREE;
4332 186491 : ret.expr_const_operands = true;
4333 186491 : ret.has_enum_type_specifier = fixed_underlying_type != NULL_TREE;
4334 186491 : timevar_pop (TV_PARSE_ENUM);
4335 186491 : return ret;
4336 : }
4337 59945 : else if (!ident)
4338 : {
4339 1 : c_parser_error (parser, "expected %<{%>");
4340 1 : ret.spec = error_mark_node;
4341 1 : ret.kind = ctsk_tagref;
4342 1 : ret.expr = NULL_TREE;
4343 1 : ret.expr_const_operands = true;
4344 1 : ret.has_enum_type_specifier = false;
4345 1 : return ret;
4346 : }
4347 : /* Attributes may only appear when the members are defined or in
4348 : certain forward declarations (treat enum forward declarations in
4349 : GNU C analogously to struct and union forward declarations in
4350 : standard C). */
4351 59945 : if (have_std_attrs && c_parser_next_token_is_not (parser, CPP_SEMICOLON))
4352 1 : c_parser_error (parser, "expected %<;%>");
4353 59944 : if (fixed_underlying_type == NULL_TREE)
4354 : {
4355 59895 : ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident, have_std_attrs,
4356 : std_attrs, false);
4357 : /* In ISO C, enumerated types without a fixed underlying type
4358 : can be referred to only if already defined. */
4359 59895 : if (pedantic && !COMPLETE_TYPE_P (ret.spec))
4360 : {
4361 11 : gcc_assert (ident);
4362 11 : pedwarn (enum_loc, OPT_Wpedantic,
4363 : "ISO C forbids forward references to %<enum%> types");
4364 : }
4365 : }
4366 : return ret;
4367 : }
4368 :
4369 : /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
4370 :
4371 : struct-or-union-specifier:
4372 : struct-or-union attribute-specifier-sequence[opt] gnu-attributes[opt]
4373 : identifier[opt] { struct-contents } gnu-attributes[opt]
4374 : struct-or-union attribute-specifier-sequence[opt] gnu-attributes[opt]
4375 : identifier
4376 :
4377 : struct-contents:
4378 : struct-declaration-list
4379 :
4380 : struct-declaration-list:
4381 : struct-declaration ;
4382 : struct-declaration-list struct-declaration ;
4383 :
4384 : GNU extensions:
4385 :
4386 : struct-contents:
4387 : empty
4388 : struct-declaration
4389 : struct-declaration-list struct-declaration
4390 :
4391 : struct-declaration-list:
4392 : struct-declaration-list ;
4393 : ;
4394 :
4395 : (Note that in the syntax here, unlike that in ISO C, the semicolons
4396 : are included here rather than in struct-declaration, in order to
4397 : describe the syntax with extra semicolons and missing semicolon at
4398 : end.)
4399 :
4400 : Objective-C:
4401 :
4402 : struct-declaration-list:
4403 : @defs ( class-name )
4404 :
4405 : (Note this does not include a trailing semicolon, but can be
4406 : followed by further declarations, and gets a pedwarn-if-pedantic
4407 : when followed by a semicolon.) */
4408 :
4409 : static struct c_typespec
4410 2239083 : c_parser_struct_or_union_specifier (c_parser *parser)
4411 : {
4412 2239083 : struct c_typespec ret;
4413 2239083 : bool have_std_attrs;
4414 2239083 : tree std_attrs = NULL_TREE;
4415 2239083 : tree attrs;
4416 2239083 : tree ident = NULL_TREE;
4417 2239083 : location_t struct_loc;
4418 2239083 : location_t ident_loc = UNKNOWN_LOCATION;
4419 2239083 : enum tree_code code;
4420 2239083 : switch (c_parser_peek_token (parser)->keyword)
4421 : {
4422 : case RID_STRUCT:
4423 : code = RECORD_TYPE;
4424 : break;
4425 423932 : case RID_UNION:
4426 423932 : code = UNION_TYPE;
4427 423932 : break;
4428 0 : default:
4429 0 : gcc_unreachable ();
4430 : }
4431 2239083 : struct_loc = c_parser_peek_token (parser)->location;
4432 2239083 : c_parser_consume_token (parser);
4433 2239083 : have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1);
4434 2239083 : if (have_std_attrs)
4435 34 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
4436 2239083 : attrs = c_parser_gnu_attributes (parser);
4437 :
4438 : /* Set the location in case we create a decl now. */
4439 2239083 : c_parser_set_source_position_from_token (c_parser_peek_token (parser));
4440 :
4441 2239083 : if (c_parser_next_token_is (parser, CPP_NAME))
4442 : {
4443 1538605 : ident = c_parser_peek_token (parser)->value;
4444 1538605 : ident_loc = c_parser_peek_token (parser)->location;
4445 1538605 : struct_loc = ident_loc;
4446 1538605 : c_parser_consume_token (parser);
4447 : }
4448 2239083 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4449 : {
4450 : /* Parse a struct or union definition. Start the scope of the
4451 : tag before parsing components. */
4452 1193399 : class c_struct_parse_info *struct_info;
4453 1193399 : tree type = start_struct (struct_loc, code, ident, &struct_info);
4454 1193399 : tree postfix_attrs;
4455 : /* We chain the components in reverse order, then put them in
4456 : forward order at the end. Each struct-declaration may
4457 : declare multiple components (comma-separated), so we must use
4458 : chainon to join them, although when parsing each
4459 : struct-declaration we can use TREE_CHAIN directly.
4460 :
4461 : The theory behind all this is that there will be more
4462 : semicolon separated fields than comma separated fields, and
4463 : so we'll be minimizing the number of node traversals required
4464 : by chainon. */
4465 1193399 : tree contents;
4466 1193399 : tree expr = NULL;
4467 1193399 : timevar_push (TV_PARSE_STRUCT);
4468 1193399 : contents = NULL_TREE;
4469 1193399 : c_parser_consume_token (parser);
4470 : /* Handle the Objective-C @defs construct,
4471 : e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
4472 1193399 : if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
4473 : {
4474 0 : tree name;
4475 0 : gcc_assert (c_dialect_objc ());
4476 0 : c_parser_consume_token (parser);
4477 0 : matching_parens parens;
4478 0 : if (!parens.require_open (parser))
4479 0 : goto end_at_defs;
4480 0 : if (c_parser_next_token_is (parser, CPP_NAME)
4481 0 : && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
4482 : {
4483 0 : name = c_parser_peek_token (parser)->value;
4484 0 : c_parser_consume_token (parser);
4485 : }
4486 : else
4487 : {
4488 0 : c_parser_error (parser, "expected class name");
4489 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4490 0 : goto end_at_defs;
4491 : }
4492 0 : parens.skip_until_found_close (parser);
4493 0 : contents = nreverse (objc_get_class_ivars (name));
4494 : }
4495 1193399 : end_at_defs:
4496 : /* Parse the struct-declarations and semicolons. Problems with
4497 : semicolons are diagnosed here; empty structures are diagnosed
4498 : elsewhere. */
4499 5496977 : while (true)
4500 : {
4501 5496977 : tree decls;
4502 : /* Parse any stray semicolon. */
4503 5496977 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4504 : {
4505 14 : location_t semicolon_loc
4506 14 : = c_parser_peek_token (parser)->location;
4507 14 : gcc_rich_location richloc (semicolon_loc);
4508 14 : richloc.add_fixit_remove ();
4509 14 : pedwarn (&richloc, OPT_Wpedantic,
4510 : "extra semicolon in struct or union specified");
4511 14 : c_parser_consume_token (parser);
4512 14 : continue;
4513 14 : }
4514 : /* Stop if at the end of the struct or union contents. */
4515 5496963 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4516 : {
4517 1193390 : c_parser_consume_token (parser);
4518 1193390 : break;
4519 : }
4520 : /* Accept #pragmas at struct scope. */
4521 4303573 : if (c_parser_next_token_is (parser, CPP_PRAGMA))
4522 : {
4523 20 : c_parser_pragma (parser, pragma_struct, NULL, NULL_TREE);
4524 20 : continue;
4525 : }
4526 : /* Parse some comma-separated declarations, but not the
4527 : trailing semicolon if any. */
4528 4303553 : decls = c_parser_struct_declaration (parser, &expr);
4529 4303553 : contents = chainon (decls, contents);
4530 : /* If no semicolon follows, either we have a parse error or
4531 : are at the end of the struct or union and should
4532 : pedwarn. */
4533 4303553 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4534 4303514 : c_parser_consume_token (parser);
4535 : else
4536 : {
4537 39 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4538 28 : pedwarn (c_parser_peek_token (parser)->location, 0,
4539 : "no semicolon at end of struct or union");
4540 11 : else if (parser->error
4541 11 : || !c_parser_next_token_starts_declspecs (parser))
4542 : {
4543 9 : c_parser_error (parser, "expected %<;%>");
4544 9 : c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
4545 9 : break;
4546 : }
4547 :
4548 : /* If we come here, we have already emitted an error
4549 : for an expected `;', identifier or `(', and we also
4550 : recovered already. Go on with the next field. */
4551 : }
4552 : }
4553 1193399 : postfix_attrs = c_parser_gnu_attributes (parser);
4554 1193399 : ret.spec = finish_struct (struct_loc, type, nreverse (contents),
4555 : chainon (std_attrs,
4556 : chainon (attrs, postfix_attrs)),
4557 : struct_info, &expr);
4558 1193399 : ret.kind = ctsk_tagdef;
4559 1193399 : ret.expr = expr;
4560 1193399 : ret.expr_const_operands = true;
4561 1193399 : ret.has_enum_type_specifier = false;
4562 1193399 : timevar_pop (TV_PARSE_STRUCT);
4563 1193399 : return ret;
4564 : }
4565 1045684 : else if (!ident)
4566 : {
4567 10 : c_parser_error (parser, "expected %<{%>");
4568 10 : ret.spec = error_mark_node;
4569 10 : ret.kind = ctsk_tagref;
4570 10 : ret.expr = NULL_TREE;
4571 10 : ret.expr_const_operands = true;
4572 10 : ret.has_enum_type_specifier = false;
4573 10 : return ret;
4574 : }
4575 : /* Attributes may only appear when the members are defined or in
4576 : certain forward declarations. */
4577 1045684 : if (have_std_attrs && c_parser_next_token_is_not (parser, CPP_SEMICOLON))
4578 2 : c_parser_error (parser, "expected %<;%>");
4579 : /* ??? Existing practice is that GNU attributes are ignored after
4580 : the struct or union keyword when not defining the members. */
4581 1045674 : ret = parser_xref_tag (ident_loc, code, ident, have_std_attrs, std_attrs,
4582 : false);
4583 1045674 : return ret;
4584 : }
4585 :
4586 : /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
4587 : *without* the trailing semicolon.
4588 :
4589 : struct-declaration:
4590 : attribute-specifier-sequence[opt] specifier-qualifier-list
4591 : attribute-specifier-sequence[opt] struct-declarator-list
4592 : static_assert-declaration-no-semi
4593 :
4594 : specifier-qualifier-list:
4595 : type-specifier specifier-qualifier-list[opt]
4596 : type-qualifier specifier-qualifier-list[opt]
4597 : alignment-specifier specifier-qualifier-list[opt]
4598 : gnu-attributes specifier-qualifier-list[opt]
4599 :
4600 : struct-declarator-list:
4601 : struct-declarator
4602 : struct-declarator-list , gnu-attributes[opt] struct-declarator
4603 :
4604 : struct-declarator:
4605 : declarator gnu-attributes[opt]
4606 : declarator[opt] : constant-expression gnu-attributes[opt]
4607 :
4608 : GNU extensions:
4609 :
4610 : struct-declaration:
4611 : __extension__ struct-declaration
4612 : specifier-qualifier-list
4613 :
4614 : Unlike the ISO C syntax, semicolons are handled elsewhere. The use
4615 : of gnu-attributes where shown is a GNU extension. In GNU C, we accept
4616 : any expression without commas in the syntax (assignment
4617 : expressions, not just conditional expressions); assignment
4618 : expressions will be diagnosed as non-constant. */
4619 :
4620 : static tree
4621 4370178 : c_parser_struct_declaration (c_parser *parser, tree *expr)
4622 : {
4623 4370178 : struct c_declspecs *specs;
4624 4370178 : tree prefix_attrs;
4625 4370178 : tree all_prefix_attrs;
4626 4370178 : tree decls;
4627 4370178 : location_t decl_loc;
4628 4370178 : if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4629 : {
4630 66625 : int ext;
4631 66625 : tree decl;
4632 66625 : ext = disable_extension_diagnostics ();
4633 66625 : c_parser_consume_token (parser);
4634 66625 : decl = c_parser_struct_declaration (parser, expr);
4635 66625 : restore_extension_diagnostics (ext);
4636 66625 : return decl;
4637 : }
4638 4303553 : if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
4639 : {
4640 17 : c_parser_static_assert_declaration_no_semi (parser);
4641 17 : return NULL_TREE;
4642 : }
4643 4303536 : specs = build_null_declspecs ();
4644 4303536 : decl_loc = c_parser_peek_token (parser)->location;
4645 : /* Strictly by the standard, we shouldn't allow _Alignas here,
4646 : but it appears to have been intended to allow it there, so
4647 : we're keeping it as it is until WG14 reaches a conclusion
4648 : of N1731.
4649 : <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
4650 4303536 : c_parser_declspecs (parser, specs, false, true, true,
4651 : true, false, true, true, cla_nonabstract_decl);
4652 4303536 : if (parser->error)
4653 : return NULL_TREE;
4654 4303528 : if (!specs->declspecs_seen_p)
4655 : {
4656 1 : c_parser_error (parser, "expected specifier-qualifier-list");
4657 1 : return NULL_TREE;
4658 : }
4659 4303527 : finish_declspecs (specs);
4660 4303527 : if (c_parser_next_token_is (parser, CPP_SEMICOLON)
4661 8596198 : || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4662 : {
4663 10860 : tree ret;
4664 10860 : if (specs->typespec_kind == ctsk_none)
4665 : {
4666 3 : pedwarn (decl_loc, OPT_Wpedantic,
4667 : "ISO C forbids member declarations with no members");
4668 3 : shadow_tag_warned (specs, pedantic);
4669 3 : ret = NULL_TREE;
4670 : }
4671 : else
4672 : {
4673 : /* Support for unnamed structs or unions as members of
4674 : structs or unions (which is [a] useful and [b] supports
4675 : MS P-SDK). */
4676 10857 : tree attrs = NULL;
4677 :
4678 10857 : ret = grokfield (c_parser_peek_token (parser)->location,
4679 : build_id_declarator (NULL_TREE), specs,
4680 : NULL_TREE, &attrs, expr);
4681 10857 : if (ret)
4682 10828 : decl_attributes (&ret, attrs, 0);
4683 : }
4684 10860 : return ret;
4685 : }
4686 :
4687 : /* Provide better error recovery. Note that a type name here is valid,
4688 : and will be treated as a field name. */
4689 4292667 : if (specs->typespec_kind == ctsk_tagdef
4690 155480 : && TREE_CODE (specs->type) != ENUMERAL_TYPE
4691 155327 : && c_parser_next_token_starts_declspecs (parser)
4692 4292670 : && !c_parser_next_token_is (parser, CPP_NAME))
4693 : {
4694 2 : c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
4695 2 : parser->error = false;
4696 2 : return NULL_TREE;
4697 : }
4698 :
4699 4292665 : pending_xref_error ();
4700 4292665 : prefix_attrs = specs->attrs;
4701 4292665 : all_prefix_attrs = prefix_attrs;
4702 4292665 : specs->attrs = NULL_TREE;
4703 4292665 : decls = NULL_TREE;
4704 4408935 : while (true)
4705 : {
4706 : /* Declaring one or more declarators or un-named bit-fields. */
4707 4350800 : struct c_declarator *declarator;
4708 4350800 : bool dummy = false;
4709 4350800 : if (c_parser_next_token_is (parser, CPP_COLON))
4710 11621 : declarator = build_id_declarator (NULL_TREE);
4711 : else
4712 4339179 : declarator = c_parser_declarator (parser,
4713 4339179 : specs->typespec_kind != ctsk_none,
4714 : C_DTR_NORMAL, &dummy);
4715 4350800 : if (declarator == NULL)
4716 : {
4717 1 : c_parser_skip_to_end_of_block_or_statement (parser);
4718 1 : break;
4719 : }
4720 4350799 : if (c_parser_next_token_is (parser, CPP_COLON)
4721 4295675 : || c_parser_next_token_is (parser, CPP_COMMA)
4722 4239868 : || c_parser_next_token_is (parser, CPP_SEMICOLON)
4723 33177 : || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
4724 4383953 : || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4725 : {
4726 4350799 : tree postfix_attrs = NULL_TREE;
4727 4350799 : tree width = NULL_TREE;
4728 4350799 : tree d;
4729 4350799 : if (c_parser_next_token_is (parser, CPP_COLON))
4730 : {
4731 55124 : c_parser_consume_token (parser);
4732 55124 : location_t loc = c_parser_peek_token (parser)->location;
4733 55124 : width = convert_lvalue_to_rvalue (loc,
4734 : (c_parser_expr_no_commas
4735 : (parser, NULL)),
4736 : true, true).value;
4737 : }
4738 4350799 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4739 33337 : postfix_attrs = c_parser_gnu_attributes (parser);
4740 4350799 : d = grokfield (c_parser_peek_token (parser)->location,
4741 : declarator, specs, width, &all_prefix_attrs, expr);
4742 4350799 : decl_attributes (&d, chainon (postfix_attrs,
4743 : all_prefix_attrs), 0);
4744 4350799 : DECL_CHAIN (d) = decls;
4745 4350799 : decls = d;
4746 4350799 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4747 0 : all_prefix_attrs = chainon (c_parser_gnu_attributes (parser),
4748 : prefix_attrs);
4749 : else
4750 : all_prefix_attrs = prefix_attrs;
4751 4350799 : if (c_parser_next_token_is (parser, CPP_COMMA))
4752 58135 : c_parser_consume_token (parser);
4753 4292664 : else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
4754 4292687 : || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4755 : {
4756 : /* Semicolon consumed in caller. */
4757 : break;
4758 : }
4759 : else
4760 : {
4761 0 : c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
4762 0 : break;
4763 : }
4764 : }
4765 : else
4766 : {
4767 0 : c_parser_error (parser,
4768 : "expected %<:%>, %<,%>, %<;%>, %<}%> or "
4769 : "%<__attribute__%>");
4770 0 : break;
4771 : }
4772 58135 : }
4773 4292665 : return decls;
4774 : }
4775 :
4776 : /* Parse a typeof specifier (a GNU extension adopted in C23).
4777 :
4778 : typeof-specifier:
4779 : typeof ( expression )
4780 : typeof ( type-name )
4781 : typeof_unqual ( expression )
4782 : typeof_unqual ( type-name )
4783 : */
4784 :
4785 : static struct c_typespec
4786 822188 : c_parser_typeof_specifier (c_parser *parser)
4787 : {
4788 822188 : bool is_unqual;
4789 822188 : bool is_std;
4790 822188 : struct c_typespec ret;
4791 822188 : ret.kind = ctsk_typeof;
4792 822188 : ret.spec = error_mark_node;
4793 822188 : ret.expr = NULL_TREE;
4794 822188 : ret.expr_const_operands = true;
4795 822188 : ret.has_enum_type_specifier = false;
4796 822188 : if (c_parser_next_token_is_keyword (parser, RID_TYPEOF))
4797 : {
4798 822096 : is_unqual = false;
4799 822096 : tree spelling = c_parser_peek_token (parser)->value;
4800 822096 : is_std = (flag_isoc23
4801 925082 : && strcmp (IDENTIFIER_POINTER (spelling), "typeof") == 0);
4802 : }
4803 : else
4804 : {
4805 92 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF_UNQUAL));
4806 92 : is_unqual = true;
4807 92 : tree spelling = c_parser_peek_token (parser)->value;
4808 92 : is_std = strcmp (IDENTIFIER_POINTER (spelling), "typeof_unqual") == 0;
4809 : }
4810 822188 : c_parser_consume_token (parser);
4811 822188 : c_inhibit_evaluation_warnings++;
4812 822188 : in_typeof++;
4813 822188 : matching_parens parens;
4814 822188 : if (!parens.require_open (parser))
4815 : {
4816 0 : c_inhibit_evaluation_warnings--;
4817 0 : in_typeof--;
4818 0 : return ret;
4819 : }
4820 822188 : if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
4821 : {
4822 691 : struct c_type_name *type = c_parser_type_name (parser);
4823 691 : c_inhibit_evaluation_warnings--;
4824 691 : in_typeof--;
4825 691 : if (type != NULL)
4826 : {
4827 691 : ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
4828 691 : pop_maybe_used (c_type_variably_modified_p (ret.spec));
4829 : }
4830 : }
4831 : else
4832 : {
4833 821497 : bool was_vm;
4834 821497 : location_t here = c_parser_peek_token (parser)->location;
4835 821497 : struct c_expr expr = c_parser_expression (parser);
4836 821497 : c_inhibit_evaluation_warnings--;
4837 821497 : in_typeof--;
4838 821497 : if (TREE_CODE (expr.value) == COMPONENT_REF
4839 821497 : && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4840 13 : error_at (here, "%<typeof%> applied to a bit-field");
4841 821497 : mark_exp_read (expr.value);
4842 821497 : ret.spec = TREE_TYPE (expr.value);
4843 821497 : was_vm = c_type_variably_modified_p (ret.spec);
4844 : /* This is returned with the type so that when the type is
4845 : evaluated, this can be evaluated. */
4846 821497 : if (was_vm)
4847 238 : ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
4848 821497 : pop_maybe_used (was_vm);
4849 : }
4850 822188 : parens.skip_until_found_close (parser);
4851 822188 : if (ret.spec != error_mark_node)
4852 : {
4853 822177 : if (is_unqual)
4854 : {
4855 92 : bool is_array = TREE_CODE (ret.spec) == ARRAY_TYPE;
4856 92 : auto quals = TYPE_QUALS (strip_array_types (ret.spec));
4857 92 : if ((is_array ? quals.without (TYPE_QUAL_ATOMIC) : quals)
4858 822228 : != TYPE_UNQUALIFIED)
4859 : {
4860 51 : ret.spec = TYPE_MAIN_VARIANT (ret.spec);
4861 51 : if (quals.has (TYPE_QUAL_ATOMIC) && is_array)
4862 4 : ret.spec = c_build_qualified_type (ret.spec,
4863 : TYPE_QUAL_ATOMIC);
4864 : }
4865 : }
4866 822177 : if (is_std)
4867 : {
4868 : /* In ISO C terms, _Noreturn is not part of the type of
4869 : expressions such as &abort, but in GCC it is represented
4870 : internally as a type qualifier. */
4871 4317 : if (TREE_CODE (ret.spec) == FUNCTION_TYPE
4872 4317 : && TYPE_QUALS (ret.spec) != TYPE_UNQUALIFIED)
4873 2 : ret.spec = TYPE_MAIN_VARIANT (ret.spec);
4874 2929 : else if (FUNCTION_POINTER_TYPE_P (ret.spec)
4875 7143 : && TYPE_QUALS (TREE_TYPE (ret.spec)) != TYPE_UNQUALIFIED)
4876 2 : ret.spec
4877 2 : = c_build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (ret.spec)));
4878 : }
4879 : }
4880 : return ret;
4881 : }
4882 :
4883 : /* Parse an alignment-specifier.
4884 :
4885 : C11 6.7.5:
4886 :
4887 : alignment-specifier:
4888 : _Alignas ( type-name )
4889 : _Alignas ( constant-expression )
4890 : */
4891 :
4892 : static tree
4893 202 : c_parser_alignas_specifier (c_parser * parser)
4894 : {
4895 202 : tree ret = error_mark_node;
4896 202 : location_t loc = c_parser_peek_token (parser)->location;
4897 202 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
4898 202 : tree spelling = c_parser_peek_token (parser)->value;
4899 202 : c_parser_consume_token (parser);
4900 202 : if (flag_isoc99)
4901 199 : pedwarn_c99 (loc, OPT_Wpedantic,
4902 : "ISO C99 does not support %qE", spelling);
4903 : else
4904 3 : pedwarn_c99 (loc, OPT_Wpedantic,
4905 : "ISO C90 does not support %qE", spelling);
4906 202 : matching_parens parens;
4907 202 : if (!parens.require_open (parser))
4908 : return ret;
4909 202 : if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
4910 : {
4911 132 : struct c_type_name *type = c_parser_type_name (parser);
4912 132 : if (type != NULL)
4913 131 : ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
4914 : false, true, 1);
4915 : }
4916 : else
4917 70 : ret = convert_lvalue_to_rvalue (loc,
4918 : c_parser_expr_no_commas (parser, NULL),
4919 : true, true).value;
4920 202 : parens.skip_until_found_close (parser);
4921 202 : return ret;
4922 : }
4923 :
4924 : /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
4925 : 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
4926 : a typedef name may be redeclared; otherwise it may not. KIND
4927 : indicates which kind of declarator is wanted. Returns a valid
4928 : declarator except in the case of a syntax error in which case NULL is
4929 : returned. *SEEN_ID is set to true if an identifier being declared is
4930 : seen; this is used to diagnose bad forms of abstract array declarators
4931 : and to determine whether an identifier list is syntactically permitted.
4932 :
4933 : declarator:
4934 : pointer[opt] direct-declarator
4935 :
4936 : direct-declarator:
4937 : identifier
4938 : ( gnu-attributes[opt] declarator )
4939 : direct-declarator array-declarator
4940 : direct-declarator ( parameter-type-list )
4941 : direct-declarator ( identifier-list[opt] )
4942 :
4943 : pointer:
4944 : * type-qualifier-list[opt]
4945 : * type-qualifier-list[opt] pointer
4946 :
4947 : type-qualifier-list:
4948 : type-qualifier
4949 : gnu-attributes
4950 : type-qualifier-list type-qualifier
4951 : type-qualifier-list gnu-attributes
4952 :
4953 : array-declarator:
4954 : [ type-qualifier-list[opt] assignment-expression[opt] ]
4955 : [ static type-qualifier-list[opt] assignment-expression ]
4956 : [ type-qualifier-list static assignment-expression ]
4957 : [ type-qualifier-list[opt] * ]
4958 :
4959 : parameter-type-list:
4960 : parameter-list
4961 : parameter-list , ...
4962 :
4963 : parameter-list:
4964 : parameter-declaration
4965 : parameter-list , parameter-declaration
4966 :
4967 : parameter-declaration:
4968 : declaration-specifiers declarator gnu-attributes[opt]
4969 : declaration-specifiers abstract-declarator[opt] gnu-attributes[opt]
4970 :
4971 : identifier-list:
4972 : identifier
4973 : identifier-list , identifier
4974 :
4975 : abstract-declarator:
4976 : pointer
4977 : pointer[opt] direct-abstract-declarator
4978 :
4979 : direct-abstract-declarator:
4980 : ( gnu-attributes[opt] abstract-declarator )
4981 : direct-abstract-declarator[opt] array-declarator
4982 : direct-abstract-declarator[opt] ( parameter-type-list[opt] )
4983 :
4984 : GNU extensions:
4985 :
4986 : direct-declarator:
4987 : direct-declarator ( parameter-forward-declarations
4988 : parameter-type-list[opt] )
4989 :
4990 : direct-abstract-declarator:
4991 : direct-abstract-declarator[opt] ( parameter-forward-declarations
4992 : parameter-type-list[opt] )
4993 :
4994 : parameter-forward-declarations:
4995 : parameter-list ;
4996 : parameter-forward-declarations parameter-list ;
4997 :
4998 : The uses of gnu-attributes shown above are GNU extensions.
4999 :
5000 : Some forms of array declarator are not included in C99 in the
5001 : syntax for abstract declarators; these are disallowed elsewhere.
5002 : This may be a defect (DR#289).
5003 :
5004 : This function also accepts an omitted abstract declarator as being
5005 : an abstract declarator, although not part of the formal syntax. */
5006 :
5007 : struct c_declarator *
5008 344594331 : c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
5009 : bool *seen_id)
5010 : {
5011 : /* Parse any initial pointer part. */
5012 344594331 : if (c_parser_next_token_is (parser, CPP_MULT))
5013 : {
5014 18790601 : struct c_declspecs *quals_attrs = build_null_declspecs ();
5015 18790601 : struct c_declarator *inner;
5016 18790601 : c_parser_consume_token (parser);
5017 18790601 : c_parser_declspecs (parser, quals_attrs, false, false, true,
5018 : false, false, true, false, cla_prefer_id);
5019 18790601 : inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
5020 18790601 : if (inner == NULL)
5021 : return NULL;
5022 : else
5023 18790592 : return make_pointer_declarator (quals_attrs, inner);
5024 : }
5025 : /* Now we have a direct declarator, direct abstract declarator or
5026 : nothing (which counts as a direct abstract declarator here). */
5027 325803730 : return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
5028 : }
5029 :
5030 : /* Parse a direct declarator or direct abstract declarator; arguments
5031 : as c_parser_declarator. */
5032 :
5033 : static struct c_declarator *
5034 325803730 : c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
5035 : bool *seen_id)
5036 : {
5037 : /* The direct declarator must start with an identifier (possibly
5038 : omitted) or a parenthesized declarator (possibly abstract). In
5039 : an ordinary declarator, initial parentheses must start a
5040 : parenthesized declarator. In an abstract declarator or parameter
5041 : declarator, they could start a parenthesized declarator or a
5042 : parameter list. To tell which, the open parenthesis and any
5043 : following gnu-attributes must be read. If a declaration
5044 : specifier or standard attributes follow, then it is a parameter
5045 : list; if the specifier is a typedef name, there might be an
5046 : ambiguity about redeclaring it, which is resolved in the
5047 : direction of treating it as a typedef name. If a close
5048 : parenthesis follows, it is also an empty parameter list, as the
5049 : syntax does not permit empty abstract declarators. Otherwise, it
5050 : is a parenthesized declarator (in which case the analysis may be
5051 : repeated inside it, recursively).
5052 :
5053 : ??? There is an ambiguity in a parameter declaration "int
5054 : (__attribute__((foo)) x)", where x is not a typedef name: it
5055 : could be an abstract declarator for a function, or declare x with
5056 : parentheses. The proper resolution of this ambiguity needs
5057 : documenting. At present we follow an accident of the old
5058 : parser's implementation, whereby the first parameter must have
5059 : some declaration specifiers other than just gnu-attributes. Thus as
5060 : a parameter declaration it is treated as a parenthesized
5061 : parameter named x, and as an abstract declarator it is
5062 : rejected.
5063 :
5064 : ??? Also following the old parser, gnu-attributes inside an empty
5065 : parameter list are ignored, making it a list not yielding a
5066 : prototype, rather than giving an error or making it have one
5067 : parameter with implicit type int.
5068 :
5069 : ??? Also following the old parser, typedef names may be
5070 : redeclared in declarators, but not Objective-C class names. */
5071 :
5072 325803730 : if (kind != C_DTR_ABSTRACT
5073 199369377 : && c_parser_next_token_is (parser, CPP_NAME)
5074 520243031 : && ((type_seen_p
5075 194429439 : && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
5076 194381552 : || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
5077 194391414 : || c_parser_peek_token (parser)->id_kind == C_ID_ID))
5078 : {
5079 194439301 : struct c_declarator *inner
5080 194439301 : = build_id_declarator (c_parser_peek_token (parser)->value);
5081 194439301 : *seen_id = true;
5082 194439301 : inner->id_loc = c_parser_peek_token (parser)->location;
5083 194439301 : c_parser_consume_token (parser);
5084 194439301 : if (c_parser_nth_token_starts_std_attributes (parser, 1))
5085 93 : inner->u.id.attrs = c_parser_std_attribute_specifier_sequence (parser);
5086 194439301 : return c_parser_direct_declarator_inner (parser, *seen_id, inner);
5087 : }
5088 :
5089 131364429 : if (kind != C_DTR_NORMAL
5090 131224257 : && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
5091 131388796 : && !c_parser_nth_token_starts_std_attributes (parser, 1))
5092 : {
5093 24367 : struct c_declarator *inner = build_id_declarator (NULL_TREE);
5094 24367 : inner->id_loc = c_parser_peek_token (parser)->location;
5095 24367 : return c_parser_direct_declarator_inner (parser, *seen_id, inner);
5096 : }
5097 :
5098 : /* Either we are at the end of an abstract declarator, or we have
5099 : parentheses. */
5100 :
5101 131340062 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5102 : {
5103 239646 : tree attrs;
5104 239646 : struct c_declarator *inner;
5105 239646 : c_parser_consume_token (parser);
5106 239646 : bool have_gnu_attrs = c_parser_next_token_is_keyword (parser,
5107 : RID_ATTRIBUTE);
5108 239646 : attrs = c_parser_gnu_attributes (parser);
5109 239646 : if (kind != C_DTR_NORMAL
5110 239646 : && (c_parser_next_token_starts_declspecs (parser)
5111 99586 : || (!have_gnu_attrs
5112 99428 : && (c_parser_nth_token_starts_std_attributes (parser, 1)
5113 99428 : || c_parser_next_token_is (parser, CPP_ELLIPSIS)))
5114 99581 : || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
5115 : {
5116 64 : struct c_arg_info *args
5117 64 : = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
5118 : attrs, have_gnu_attrs);
5119 64 : if (args == NULL)
5120 : return NULL;
5121 : else
5122 : {
5123 64 : inner = build_id_declarator (NULL_TREE);
5124 89 : if (!(args->types
5125 25 : && args->types != error_mark_node
5126 25 : && TREE_CODE (TREE_VALUE (args->types)) == IDENTIFIER_NODE)
5127 89 : && c_parser_nth_token_starts_std_attributes (parser, 1))
5128 : {
5129 4 : tree std_attrs
5130 4 : = c_parser_std_attribute_specifier_sequence (parser);
5131 4 : if (std_attrs)
5132 2 : inner = build_attrs_declarator (std_attrs, inner);
5133 : }
5134 64 : inner = build_function_declarator (args, inner);
5135 64 : return c_parser_direct_declarator_inner (parser, *seen_id,
5136 64 : inner);
5137 : }
5138 : }
5139 : /* A parenthesized declarator. */
5140 239582 : inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
5141 239582 : if (inner != NULL && attrs != NULL)
5142 179 : inner = build_attrs_declarator (attrs, inner);
5143 239582 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5144 : {
5145 239566 : c_parser_consume_token (parser);
5146 239566 : if (inner == NULL)
5147 : return NULL;
5148 : else
5149 239566 : return c_parser_direct_declarator_inner (parser, *seen_id, inner);
5150 : }
5151 : else
5152 : {
5153 16 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5154 : "expected %<)%>");
5155 16 : return NULL;
5156 : }
5157 : }
5158 : else
5159 : {
5160 131100416 : if (kind == C_DTR_NORMAL)
5161 : {
5162 137 : c_parser_error (parser, "expected identifier or %<(%>");
5163 137 : return NULL;
5164 : }
5165 : else
5166 131100279 : return build_id_declarator (NULL_TREE);
5167 : }
5168 : }
5169 :
5170 : /* Parse part of a direct declarator or direct abstract declarator,
5171 : given that some (in INNER) has already been parsed; ID_PRESENT is
5172 : true if an identifier is present, false for an abstract
5173 : declarator. */
5174 :
5175 : static struct c_declarator *
5176 194703298 : c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
5177 : struct c_declarator *inner)
5178 : {
5179 : /* Parse a sequence of array declarators and parameter lists. */
5180 248448461 : if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
5181 248448461 : && !c_parser_nth_token_starts_std_attributes (parser, 1))
5182 : {
5183 1152692 : location_t brace_loc = c_parser_peek_token (parser)->location;
5184 1152692 : struct c_declarator *declarator;
5185 1152692 : struct c_declspecs *quals_attrs = build_null_declspecs ();
5186 1152692 : struct c_expr dimen;
5187 1152692 : dimen.value = NULL_TREE;
5188 1152692 : dimen.original_code = ERROR_MARK;
5189 1152692 : dimen.original_type = NULL_TREE;
5190 1152692 : c_parser_consume_token (parser);
5191 1152692 : c_parser_declspecs (parser, quals_attrs, false, false, true,
5192 : false, false, false, false, cla_prefer_id);
5193 :
5194 1152692 : location_t static_loc = UNKNOWN_LOCATION;
5195 1152692 : if (c_parser_next_token_is_keyword (parser, RID_STATIC))
5196 : {
5197 131 : static_loc = c_parser_peek_token (parser)->location;
5198 131 : c_parser_consume_token (parser);
5199 131 : if (!quals_attrs->declspecs_seen_p)
5200 111 : c_parser_declspecs (parser, quals_attrs, false, false, true,
5201 : false, false, false, false, cla_prefer_id);
5202 : }
5203 1152692 : if (!quals_attrs->declspecs_seen_p)
5204 1151721 : quals_attrs = NULL;
5205 : /* If "static" is present, there must be an array dimension.
5206 : Otherwise, there may be a dimension, "*", or no
5207 : dimension. */
5208 1152692 : const bool static_seen = (static_loc != UNKNOWN_LOCATION);
5209 1152692 : bool star_seen = false;
5210 1152692 : if (c_parser_next_token_is (parser, CPP_MULT)
5211 1152692 : && c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
5212 : {
5213 155 : star_seen = true;
5214 155 : c_parser_consume_token (parser);
5215 : }
5216 1152537 : else if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
5217 980050 : dimen = c_parser_expr_no_commas (parser, NULL);
5218 :
5219 1152692 : if (static_seen)
5220 : {
5221 131 : if (star_seen)
5222 : {
5223 3 : error_at (static_loc,
5224 : "%<static%> may not be used with an unspecified "
5225 : "variable length array size");
5226 : /* Prevent further errors. */
5227 3 : star_seen = false;
5228 3 : dimen.value = error_mark_node;
5229 : }
5230 128 : else if (!dimen.value)
5231 2 : error_at (static_loc,
5232 : "%<static%> may not be used without an array size");
5233 : }
5234 :
5235 1152692 : if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
5236 1152677 : c_parser_consume_token (parser);
5237 : else
5238 : {
5239 15 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5240 : "expected %<]%>");
5241 15 : return NULL;
5242 : }
5243 1152677 : if (dimen.value)
5244 980038 : dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
5245 1152677 : declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
5246 : static_seen, star_seen);
5247 1152677 : if (declarator == NULL)
5248 : return NULL;
5249 1152677 : if (c_parser_nth_token_starts_std_attributes (parser, 1))
5250 : {
5251 16 : tree std_attrs
5252 16 : = c_parser_std_attribute_specifier_sequence (parser);
5253 16 : if (std_attrs)
5254 10 : inner = build_attrs_declarator (std_attrs, inner);
5255 : }
5256 1152677 : inner = set_array_declarator_inner (declarator, inner);
5257 1152677 : return c_parser_direct_declarator_inner (parser, id_present, inner);
5258 : }
5259 247295769 : else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5260 : {
5261 52592594 : tree attrs;
5262 52592594 : struct c_arg_info *args;
5263 52592594 : c_parser_consume_token (parser);
5264 52592594 : bool have_gnu_attrs = c_parser_next_token_is_keyword (parser,
5265 : RID_ATTRIBUTE);
5266 52592594 : attrs = c_parser_gnu_attributes (parser);
5267 52592594 : args = c_parser_parms_declarator (parser, id_present, attrs,
5268 : have_gnu_attrs);
5269 52592594 : if (args == NULL)
5270 : return NULL;
5271 : else
5272 : {
5273 104395360 : if (!(args->types
5274 51802874 : && args->types != error_mark_node
5275 51802874 : && TREE_CODE (TREE_VALUE (args->types)) == IDENTIFIER_NODE)
5276 104386674 : && c_parser_nth_token_starts_std_attributes (parser, 1))
5277 : {
5278 138 : tree std_attrs
5279 138 : = c_parser_std_attribute_specifier_sequence (parser);
5280 138 : if (std_attrs)
5281 121 : inner = build_attrs_declarator (std_attrs, inner);
5282 : }
5283 52592486 : inner = build_function_declarator (args, inner);
5284 52592486 : return c_parser_direct_declarator_inner (parser, id_present, inner);
5285 : }
5286 : }
5287 : return inner;
5288 : }
5289 :
5290 : /* Parse a parameter list or identifier list, including the closing
5291 : parenthesis but not the opening one. ATTRS are the gnu-attributes
5292 : at the start of the list. ID_LIST_OK is true if an identifier list
5293 : is acceptable; such a list must not have attributes at the start.
5294 : HAVE_GNU_ATTRS says whether any gnu-attributes (including empty
5295 : attributes) were present (in which case standard attributes cannot
5296 : occur). */
5297 :
5298 : static struct c_arg_info *
5299 52592658 : c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs,
5300 : bool have_gnu_attrs)
5301 : {
5302 52592658 : push_scope ();
5303 52592658 : declare_parm_level ();
5304 : /* If the list starts with an identifier, it is an identifier list.
5305 : Otherwise, it is either a prototype list or an empty list. */
5306 52592658 : if (id_list_ok
5307 52592658 : && !attrs
5308 52580487 : && c_parser_next_token_is (parser, CPP_NAME)
5309 35027211 : && c_parser_peek_token (parser)->id_kind == C_ID_ID
5310 :
5311 : /* Look ahead to detect typos in type names. */
5312 8697 : && c_parser_peek_2nd_token (parser)->type != CPP_NAME
5313 8690 : && c_parser_peek_2nd_token (parser)->type != CPP_MULT
5314 8689 : && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
5315 8688 : && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE
5316 52601345 : && c_parser_peek_2nd_token (parser)->type != CPP_KEYWORD)
5317 : {
5318 8686 : tree list = NULL_TREE, *nextp = &list;
5319 8686 : while (c_parser_next_token_is (parser, CPP_NAME)
5320 34291 : && c_parser_peek_token (parser)->id_kind == C_ID_ID)
5321 : {
5322 34291 : *nextp = build_tree_list (NULL_TREE,
5323 34291 : c_parser_peek_token (parser)->value);
5324 34291 : nextp = & TREE_CHAIN (*nextp);
5325 34291 : c_parser_consume_token (parser);
5326 34291 : if (c_parser_next_token_is_not (parser, CPP_COMMA))
5327 : break;
5328 25605 : c_parser_consume_token (parser);
5329 25605 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5330 : {
5331 0 : c_parser_error (parser, "expected identifier");
5332 0 : break;
5333 : }
5334 : }
5335 8686 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5336 : {
5337 8686 : struct c_arg_info *ret = build_arg_info ();
5338 8686 : ret->types = list;
5339 8686 : c_parser_consume_token (parser);
5340 8686 : pop_scope ();
5341 8686 : return ret;
5342 : }
5343 : else
5344 : {
5345 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5346 : "expected %<)%>");
5347 0 : pop_scope ();
5348 0 : return NULL;
5349 : }
5350 : }
5351 : else
5352 : {
5353 52583972 : struct c_arg_info *ret
5354 52583972 : = c_parser_parms_list_declarator (parser, attrs, NULL, have_gnu_attrs);
5355 52583972 : pop_scope ();
5356 52583972 : return ret;
5357 : }
5358 : }
5359 :
5360 : /* Parse a parameter list (possibly empty), including the closing
5361 : parenthesis but not the opening one. ATTRS are the gnu-attributes
5362 : at the start of the list; if HAVE_GNU_ATTRS, there were some such
5363 : attributes (possibly empty, in which case ATTRS is NULL_TREE),
5364 : which means standard attributes cannot start the list. EXPR is
5365 : NULL or an expression that needs to be evaluated for the side
5366 : effects of array size expressions in the parameters. */
5367 :
5368 : static struct c_arg_info *
5369 52584014 : c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr,
5370 : bool have_gnu_attrs)
5371 : {
5372 52584014 : bool bad_parm = false;
5373 :
5374 : /* ??? Following the old parser, forward parameter declarations may
5375 : use abstract declarators, and if no real parameter declarations
5376 : follow the forward declarations then this is not diagnosed. Also
5377 : note as above that gnu-attributes are ignored as the only contents of
5378 : the parentheses, or as the only contents after forward
5379 : declarations. */
5380 52584014 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5381 : {
5382 789491 : struct c_arg_info *ret = build_arg_info ();
5383 789491 : c_parser_consume_token (parser);
5384 789491 : return ret;
5385 : }
5386 51794523 : if (c_parser_next_token_is (parser, CPP_ELLIPSIS) && !have_gnu_attrs)
5387 : {
5388 137 : struct c_arg_info *ret = build_arg_info ();
5389 :
5390 137 : ret->types = NULL_TREE;
5391 137 : pedwarn_c11 (c_parser_peek_token (parser)->location, OPT_Wpedantic,
5392 : "ISO C requires a named argument before %<...%> "
5393 : "before C23");
5394 137 : c_parser_consume_token (parser);
5395 137 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5396 : {
5397 137 : ret->no_named_args_stdarg_p = true;
5398 137 : c_parser_consume_token (parser);
5399 137 : return ret;
5400 : }
5401 : else
5402 : {
5403 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5404 : "expected %<)%>");
5405 0 : return NULL;
5406 : }
5407 : }
5408 : /* Nonempty list of parameters, either terminated with semicolon
5409 : (forward declarations; recurse) or with close parenthesis (normal
5410 : function) or with ", ... )" (variadic function). */
5411 128385357 : while (true)
5412 : {
5413 : /* Parse a parameter. */
5414 128385357 : struct c_parm *parm = c_parser_parameter_declaration (parser, attrs,
5415 : have_gnu_attrs);
5416 128385357 : attrs = NULL_TREE;
5417 128385357 : have_gnu_attrs = false;
5418 128385357 : if (parm == NULL)
5419 : bad_parm = true;
5420 : else
5421 128385248 : push_parm_decl (parm, &expr);
5422 128385357 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5423 : {
5424 42 : tree new_attrs;
5425 42 : c_parser_consume_token (parser);
5426 42 : mark_forward_parm_decls ();
5427 42 : bool new_have_gnu_attrs
5428 42 : = c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE);
5429 42 : new_attrs = c_parser_gnu_attributes (parser);
5430 42 : return c_parser_parms_list_declarator (parser, new_attrs, expr,
5431 42 : new_have_gnu_attrs);
5432 : }
5433 128385315 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5434 : {
5435 51579540 : c_parser_consume_token (parser);
5436 51579540 : if (bad_parm)
5437 : return NULL;
5438 : else
5439 51579455 : return get_parm_info (false, expr);
5440 : }
5441 76805775 : if (!c_parser_require (parser, CPP_COMMA,
5442 : "expected %<;%>, %<,%> or %<)%>",
5443 : UNKNOWN_LOCATION, false))
5444 : {
5445 8 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5446 8 : return NULL;
5447 : }
5448 76805767 : if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
5449 : {
5450 214796 : c_parser_consume_token (parser);
5451 214796 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5452 : {
5453 214789 : c_parser_consume_token (parser);
5454 214789 : if (bad_parm)
5455 : return NULL;
5456 : else
5457 214781 : return get_parm_info (true, expr);
5458 : }
5459 : else
5460 : {
5461 7 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5462 : "expected %<)%>");
5463 7 : return NULL;
5464 : }
5465 : }
5466 : }
5467 : }
5468 :
5469 : /* Parse a parameter declaration. ATTRS are the gnu-attributes at the
5470 : start of the declaration if it is the first parameter;
5471 : HAVE_GNU_ATTRS is true if there were any gnu-attributes there (even
5472 : empty) there. */
5473 :
5474 : static struct c_parm *
5475 128385357 : c_parser_parameter_declaration (c_parser *parser, tree attrs,
5476 : bool have_gnu_attrs)
5477 : {
5478 128385357 : struct c_declspecs *specs;
5479 128385357 : struct c_declarator *declarator;
5480 128385357 : tree prefix_attrs;
5481 128385357 : tree postfix_attrs = NULL_TREE;
5482 128385357 : bool dummy = false;
5483 :
5484 : /* Accept #pragmas between parameter declarations. */
5485 128385359 : while (c_parser_next_token_is (parser, CPP_PRAGMA))
5486 2 : c_parser_pragma (parser, pragma_param, NULL, NULL_TREE);
5487 :
5488 128385357 : if (!c_parser_next_token_starts_declspecs (parser)
5489 128385357 : && !c_parser_nth_token_starts_std_attributes (parser, 1))
5490 : {
5491 97 : c_token *token = c_parser_peek_token (parser);
5492 97 : if (parser->error)
5493 : return NULL;
5494 97 : c_parser_set_source_position_from_token (token);
5495 97 : if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
5496 : {
5497 79 : auto_diagnostic_group d;
5498 79 : name_hint hint = lookup_name_fuzzy (token->value,
5499 : FUZZY_LOOKUP_TYPENAME,
5500 79 : token->location);
5501 79 : if (const char *suggestion = hint.suggestion ())
5502 : {
5503 30 : gcc_rich_location richloc (token->location);
5504 30 : richloc.add_fixit_replace (suggestion);
5505 30 : error_at (&richloc,
5506 : "unknown type name %qE; did you mean %qs?",
5507 : token->value, suggestion);
5508 30 : }
5509 : else
5510 49 : error_at (token->location, "unknown type name %qE", token->value);
5511 79 : parser->error = true;
5512 79 : }
5513 : /* ??? In some Objective-C cases '...' isn't applicable so there
5514 : should be a different message. */
5515 : else
5516 18 : c_parser_error (parser,
5517 : "expected declaration specifiers or %<...%>");
5518 97 : c_parser_skip_to_end_of_parameter (parser);
5519 97 : return NULL;
5520 : }
5521 :
5522 128385260 : location_t start_loc = c_parser_peek_token (parser)->location;
5523 :
5524 128385260 : specs = build_null_declspecs ();
5525 128385260 : if (attrs)
5526 : {
5527 341 : declspecs_add_attrs (input_location, specs, attrs);
5528 341 : attrs = NULL_TREE;
5529 : }
5530 128385260 : c_parser_declspecs (parser, specs, true, true, true, true, false,
5531 : !have_gnu_attrs, true, cla_nonabstract_decl);
5532 128385260 : finish_declspecs (specs);
5533 : /* When the param is declared, its type is a top level type, we should
5534 : call verify_counted_by_for_top_anonymous_type. */
5535 128385260 : if (specs->typespec_kind == ctsk_tagdef)
5536 67 : verify_counted_by_for_top_anonymous_type (specs->type);
5537 :
5538 128385260 : pending_xref_error ();
5539 128385260 : prefix_attrs = specs->attrs;
5540 128385260 : specs->attrs = NULL_TREE;
5541 256770520 : declarator = c_parser_declarator (parser,
5542 128385260 : specs->typespec_kind != ctsk_none,
5543 : C_DTR_PARM, &dummy);
5544 128385260 : if (declarator == NULL)
5545 : {
5546 12 : c_parser_skip_until_found (parser, CPP_COMMA, NULL);
5547 12 : return NULL;
5548 : }
5549 128385248 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
5550 17370 : postfix_attrs = c_parser_gnu_attributes (parser);
5551 :
5552 : /* Generate a location for the parameter, ranging from the start of the
5553 : initial token to the end of the final token.
5554 :
5555 : If we have a identifier, then use it for the caret location, e.g.
5556 :
5557 : extern int callee (int one, int (*two)(int, int), float three);
5558 : ~~~~~~^~~~~~~~~~~~~~
5559 :
5560 : otherwise, reuse the start location for the caret location e.g.:
5561 :
5562 : extern int callee (int one, int (*)(int, int), float three);
5563 : ^~~~~~~~~~~~~~~~~
5564 : */
5565 128385248 : location_t end_loc = parser->last_token_location;
5566 :
5567 : /* Find any cdk_id declarator; determine if we have an identifier. */
5568 128385248 : c_declarator *id_declarator = declarator;
5569 141708028 : while (id_declarator && id_declarator->kind != cdk_id)
5570 13322780 : id_declarator = id_declarator->declarator;
5571 123689149 : location_t caret_loc = (id_declarator->u.id.id
5572 128385248 : ? id_declarator->id_loc
5573 : : start_loc);
5574 128385248 : location_t param_loc = make_location (caret_loc, start_loc, end_loc);
5575 :
5576 128385248 : return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
5577 128385248 : declarator, param_loc);
5578 : }
5579 :
5580 : /* Parse a string literal in an asm expression. It should not be
5581 : translated, and wide string literals are an error although
5582 : permitted by the syntax. This is a GNU extension.
5583 :
5584 : asm-string-literal:
5585 : string-literal
5586 : */
5587 :
5588 : static tree
5589 2061960 : c_parser_asm_string_literal (c_parser *parser)
5590 : {
5591 2061960 : tree str;
5592 2061960 : int save_flag = warn_overlength_strings;
5593 2061960 : warn_overlength_strings = 0;
5594 2061960 : str = c_parser_string_literal (parser, false, false).value;
5595 2061960 : warn_overlength_strings = save_flag;
5596 2061960 : return str;
5597 : }
5598 :
5599 : /* Parse a simple asm expression. This is used in restricted
5600 : contexts, where a full expression with inputs and outputs does not
5601 : make sense. This is a GNU extension.
5602 :
5603 : simple-asm-expr:
5604 : asm ( asm-string-literal )
5605 : */
5606 :
5607 : static tree
5608 880465 : c_parser_simple_asm_expr (c_parser *parser)
5609 : {
5610 880465 : tree str;
5611 880465 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5612 880465 : c_parser_consume_token (parser);
5613 880465 : matching_parens parens;
5614 880465 : if (!parens.require_open (parser))
5615 : return NULL_TREE;
5616 880465 : str = c_parser_asm_string_literal (parser);
5617 880465 : if (!parens.require_close (parser))
5618 : {
5619 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5620 0 : return NULL_TREE;
5621 : }
5622 : return str;
5623 : }
5624 :
5625 : static tree
5626 140949672 : c_parser_gnu_attribute_any_word (c_parser *parser)
5627 : {
5628 140949672 : tree attr_name = NULL_TREE;
5629 :
5630 140949672 : if (c_parser_next_token_is (parser, CPP_KEYWORD))
5631 : {
5632 : /* ??? See comment above about what keywords are accepted here. */
5633 913127 : bool ok;
5634 913127 : switch (c_parser_peek_token (parser)->keyword)
5635 : {
5636 : case RID_STATIC:
5637 : case RID_UNSIGNED:
5638 : case RID_LONG:
5639 : case RID_CONST:
5640 : case RID_EXTERN:
5641 : case RID_REGISTER:
5642 : case RID_TYPEDEF:
5643 : case RID_SHORT:
5644 : case RID_INLINE:
5645 : case RID_NORETURN:
5646 : case RID_VOLATILE:
5647 : case RID_SIGNED:
5648 : case RID_AUTO:
5649 : case RID_RESTRICT:
5650 : case RID_COMPLEX:
5651 : case RID_THREAD:
5652 : case RID_INT:
5653 : case RID_CHAR:
5654 : case RID_FLOAT:
5655 : case RID_DOUBLE:
5656 : case RID_VOID:
5657 : case RID_DFLOAT32:
5658 : case RID_DFLOAT64:
5659 : case RID_DFLOAT128:
5660 : case RID_DFLOAT64X:
5661 : CASE_RID_FLOATN_NX:
5662 : case RID_BOOL:
5663 : case RID_BITINT:
5664 : case RID_FRACT:
5665 : case RID_ACCUM:
5666 : case RID_SAT:
5667 : case RID_TRANSACTION_ATOMIC:
5668 : case RID_TRANSACTION_CANCEL:
5669 : case RID_ATOMIC:
5670 : case RID_AUTO_TYPE:
5671 : case RID_CONSTEXPR:
5672 : case RID_INT_N_0:
5673 : case RID_INT_N_1:
5674 : case RID_INT_N_2:
5675 : case RID_INT_N_3:
5676 : ok = true;
5677 : break;
5678 : default:
5679 : ok = false;
5680 : break;
5681 : }
5682 913127 : if (!ok)
5683 : return NULL_TREE;
5684 :
5685 : /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
5686 913127 : attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
5687 : }
5688 140036545 : else if (c_parser_next_token_is (parser, CPP_NAME))
5689 140036542 : attr_name = c_parser_peek_token (parser)->value;
5690 :
5691 : return attr_name;
5692 : }
5693 :
5694 : /* Parse attribute arguments. This is a common form of syntax
5695 : covering all currently valid GNU and standard attributes.
5696 :
5697 : gnu-attribute-arguments:
5698 : identifier
5699 : identifier , nonempty-expr-list
5700 : expr-list
5701 :
5702 : where the "identifier" must not be declared as a type. ??? Why not
5703 : allow identifiers declared as types to start the arguments? */
5704 :
5705 : static tree
5706 4723181 : c_parser_attribute_arguments (c_parser *parser, bool takes_identifier,
5707 : bool require_string, bool assume_attr,
5708 : bool allow_empty_args)
5709 : {
5710 4723181 : vec<tree, va_gc> *expr_list;
5711 4723181 : tree attr_args;
5712 : /* Parse the attribute contents. If they start with an
5713 : identifier which is followed by a comma or close
5714 : parenthesis, then the arguments start with that
5715 : identifier; otherwise they are an expression list.
5716 : In objective-c the identifier may be a classname. */
5717 4723181 : if (c_parser_next_token_is (parser, CPP_NAME)
5718 604632 : && (c_parser_peek_token (parser)->id_kind == C_ID_ID
5719 1 : || (c_dialect_objc ()
5720 0 : && c_parser_peek_token (parser)->id_kind
5721 : == C_ID_CLASSNAME))
5722 604631 : && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
5723 40829 : || (c_parser_peek_2nd_token (parser)->type
5724 : == CPP_CLOSE_PAREN))
5725 5327773 : && (takes_identifier
5726 145815 : || (c_dialect_objc ()
5727 0 : && !assume_attr
5728 0 : && c_parser_peek_token (parser)->id_kind
5729 : == C_ID_CLASSNAME)))
5730 : {
5731 458777 : tree arg1 = c_parser_peek_token (parser)->value;
5732 458777 : c_parser_consume_token (parser);
5733 458777 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5734 36323 : attr_args = build_tree_list (NULL_TREE, arg1);
5735 : else
5736 : {
5737 422454 : tree tree_list;
5738 422454 : c_parser_consume_token (parser);
5739 422454 : expr_list = c_parser_expr_list (parser, false, true,
5740 : NULL, NULL, NULL, NULL);
5741 422454 : tree_list = build_tree_list_vec (expr_list);
5742 422454 : attr_args = tree_cons (NULL_TREE, arg1, tree_list);
5743 422454 : release_tree_vector (expr_list);
5744 : }
5745 : }
5746 : else
5747 : {
5748 4264404 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5749 : {
5750 16 : if (!allow_empty_args)
5751 3 : error_at (c_parser_peek_token (parser)->location,
5752 : "parentheses must be omitted if "
5753 : "attribute argument list is empty");
5754 : attr_args = NULL_TREE;
5755 : }
5756 4264388 : else if (require_string)
5757 : {
5758 : /* The only valid argument for this attribute is a string
5759 : literal. Handle this specially here to avoid accepting
5760 : string literals with excess parentheses. */
5761 19 : tree string = c_parser_string_literal (parser, false, true).value;
5762 19 : attr_args = build_tree_list (NULL_TREE, string);
5763 : }
5764 4264369 : else if (assume_attr)
5765 : {
5766 45 : tree cond
5767 45 : = c_parser_conditional_expression (parser, NULL, NULL_TREE).value;
5768 45 : if (!c_parser_next_token_is (parser, CPP_COMMA))
5769 43 : attr_args = build_tree_list (NULL_TREE, cond);
5770 : else
5771 : {
5772 2 : tree tree_list;
5773 2 : c_parser_consume_token (parser);
5774 2 : expr_list = c_parser_expr_list (parser, false, true,
5775 : NULL, NULL, NULL, NULL);
5776 2 : tree_list = build_tree_list_vec (expr_list);
5777 2 : attr_args = tree_cons (NULL_TREE, cond, tree_list);
5778 2 : release_tree_vector (expr_list);
5779 : }
5780 : }
5781 : else
5782 : {
5783 4264324 : expr_list = c_parser_expr_list (parser, false, true,
5784 : NULL, NULL, NULL, NULL);
5785 4264324 : attr_args = build_tree_list_vec (expr_list);
5786 4264324 : release_tree_vector (expr_list);
5787 : }
5788 : }
5789 4723181 : return attr_args;
5790 : }
5791 :
5792 : /* Parse (possibly empty) gnu-attributes. This is a GNU extension.
5793 :
5794 : gnu-attributes:
5795 : empty
5796 : gnu-attributes gnu-attribute
5797 :
5798 : gnu-attribute:
5799 : __attribute__ ( ( gnu-attribute-list ) )
5800 :
5801 : gnu-attribute-list:
5802 : gnu-attrib
5803 : gnu-attribute_list , gnu-attrib
5804 :
5805 : gnu-attrib:
5806 : empty
5807 : any-word
5808 : any-word ( gnu-attribute-arguments )
5809 :
5810 : where "any-word" may be any identifier (including one declared as a
5811 : type), a reserved word storage class specifier, type specifier or
5812 : type qualifier. ??? This still leaves out most reserved keywords
5813 : (following the old parser), shouldn't we include them?
5814 : When EXPECT_COMMA is true, expect the attribute to be preceded
5815 : by a comma and fail if it isn't.
5816 : When EMPTY_OK is true, allow and consume any number of consecutive
5817 : commas with no attributes in between. */
5818 :
5819 : static tree
5820 196278563 : c_parser_gnu_attribute (c_parser *parser, tree attrs,
5821 : bool expect_comma = false, bool empty_ok = true)
5822 : {
5823 196278563 : bool comma_first = c_parser_next_token_is (parser, CPP_COMMA);
5824 196278563 : if (!comma_first
5825 110658542 : && !c_parser_next_token_is (parser, CPP_NAME)
5826 252520474 : && !c_parser_next_token_is (parser, CPP_KEYWORD))
5827 : return NULL_TREE;
5828 :
5829 226569700 : while (c_parser_next_token_is (parser, CPP_COMMA))
5830 : {
5831 85620028 : c_parser_consume_token (parser);
5832 85620028 : if (!empty_ok)
5833 : return attrs;
5834 : }
5835 :
5836 140949672 : tree attr_name = c_parser_gnu_attribute_any_word (parser);
5837 140949672 : if (attr_name == NULL_TREE)
5838 : return NULL_TREE;
5839 :
5840 140949669 : attr_name = canonicalize_attr_name (attr_name);
5841 140949669 : c_parser_consume_token (parser);
5842 :
5843 140949669 : tree attr;
5844 140949669 : if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
5845 : {
5846 136226635 : if (expect_comma && !comma_first)
5847 : {
5848 : /* A comma is missing between the last attribute on the chain
5849 : and this one. */
5850 7 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5851 : "expected %<)%>");
5852 7 : return error_mark_node;
5853 : }
5854 136226628 : attr = build_tree_list (attr_name, NULL_TREE);
5855 : /* Add this attribute to the list. */
5856 136226628 : attrs = chainon (attrs, attr);
5857 136226628 : return attrs;
5858 : }
5859 4723034 : c_parser_consume_token (parser);
5860 :
5861 4723034 : tree attr_args
5862 4723034 : = c_parser_attribute_arguments (parser,
5863 : attribute_takes_identifier_p (attr_name),
5864 : false,
5865 : is_attribute_p ("assume", attr_name),
5866 : true);
5867 :
5868 4723034 : attr = build_tree_list (attr_name, attr_args);
5869 4723034 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5870 4723032 : c_parser_consume_token (parser);
5871 : else
5872 : {
5873 2 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5874 : "expected %<)%>");
5875 2 : return error_mark_node;
5876 : }
5877 :
5878 4723032 : if (expect_comma && !comma_first)
5879 : {
5880 : /* A comma is missing between the last attribute on the chain
5881 : and this one. */
5882 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5883 : "expected %<)%>");
5884 0 : return error_mark_node;
5885 : }
5886 :
5887 : /* Add this attribute to the list. */
5888 4723032 : attrs = chainon (attrs, attr);
5889 4723032 : return attrs;
5890 : }
5891 :
5892 : static tree
5893 113673824 : c_parser_gnu_attributes (c_parser *parser)
5894 : {
5895 113673824 : tree attrs = NULL_TREE;
5896 169002714 : while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
5897 : {
5898 55328900 : bool save_translate_strings_p = parser->translate_strings_p;
5899 55328900 : parser->translate_strings_p = false;
5900 : /* Consume the `__attribute__' keyword. */
5901 55328900 : c_parser_consume_token (parser);
5902 : /* Look for the two `(' tokens. */
5903 55328900 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5904 : {
5905 0 : parser->translate_strings_p = save_translate_strings_p;
5906 0 : return attrs;
5907 : }
5908 55328900 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5909 : {
5910 0 : parser->translate_strings_p = save_translate_strings_p;
5911 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5912 0 : return attrs;
5913 : }
5914 : /* Parse the attribute list. Require a comma between successive
5915 : (possibly empty) attributes. */
5916 : for (bool expect_comma = false; ; expect_comma = true)
5917 : {
5918 : /* Parse a single attribute. */
5919 196277802 : tree attr = c_parser_gnu_attribute (parser, attrs, expect_comma);
5920 196277802 : if (attr == error_mark_node)
5921 : return attrs;
5922 196277793 : if (!attr)
5923 : break;
5924 : attrs = attr;
5925 : }
5926 :
5927 : /* Look for the two `)' tokens. */
5928 55328891 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5929 55328891 : c_parser_consume_token (parser);
5930 : else
5931 : {
5932 0 : parser->translate_strings_p = save_translate_strings_p;
5933 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5934 : "expected %<)%>");
5935 0 : return attrs;
5936 : }
5937 55328891 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5938 55328890 : c_parser_consume_token (parser);
5939 : else
5940 : {
5941 1 : parser->translate_strings_p = save_translate_strings_p;
5942 1 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5943 : "expected %<)%>");
5944 1 : return attrs;
5945 : }
5946 55328890 : parser->translate_strings_p = save_translate_strings_p;
5947 : }
5948 :
5949 : return attrs;
5950 : }
5951 :
5952 : /* Parse an optional balanced token sequence.
5953 :
5954 : balanced-token-sequence:
5955 : balanced-token
5956 : balanced-token-sequence balanced-token
5957 :
5958 : balanced-token:
5959 : ( balanced-token-sequence[opt] )
5960 : [ balanced-token-sequence[opt] ]
5961 : { balanced-token-sequence[opt] }
5962 : any token other than ()[]{}
5963 : */
5964 :
5965 : static void
5966 145 : c_parser_balanced_token_sequence (c_parser *parser)
5967 : {
5968 563 : while (true)
5969 : {
5970 563 : c_token *token = c_parser_peek_token (parser);
5971 563 : switch (token->type)
5972 : {
5973 4 : case CPP_OPEN_BRACE:
5974 4 : {
5975 4 : matching_braces braces;
5976 4 : braces.consume_open (parser);
5977 4 : c_parser_balanced_token_sequence (parser);
5978 4 : braces.require_close (parser);
5979 4 : break;
5980 : }
5981 :
5982 42 : case CPP_OPEN_PAREN:
5983 42 : {
5984 42 : matching_parens parens;
5985 42 : parens.consume_open (parser);
5986 42 : c_parser_balanced_token_sequence (parser);
5987 42 : parens.require_close (parser);
5988 42 : break;
5989 : }
5990 :
5991 33 : case CPP_OPEN_SQUARE:
5992 33 : c_parser_consume_token (parser);
5993 33 : c_parser_balanced_token_sequence (parser);
5994 33 : c_parser_require (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
5995 33 : break;
5996 :
5997 145 : case CPP_CLOSE_BRACE:
5998 145 : case CPP_CLOSE_PAREN:
5999 145 : case CPP_CLOSE_SQUARE:
6000 145 : case CPP_EOF:
6001 145 : return;
6002 :
6003 1 : case CPP_PRAGMA:
6004 1 : c_parser_consume_pragma (parser);
6005 1 : c_parser_skip_to_pragma_eol (parser, false);
6006 1 : break;
6007 :
6008 338 : default:
6009 338 : c_parser_consume_token (parser);
6010 338 : break;
6011 : }
6012 : }
6013 : }
6014 :
6015 : /* Parse arguments of omp::directive or omp::decl attribute.
6016 :
6017 : directive-name ,[opt] clause-list[opt]
6018 :
6019 : For directive just remember the tokens in a vector for subsequent
6020 : parsing. */
6021 :
6022 : static void
6023 914 : c_parser_omp_directive_args (c_parser *parser, tree attribute, bool decl_p)
6024 : {
6025 914 : unsigned int n = 1;
6026 914 : c_token *first = c_parser_peek_token (parser);
6027 914 : if (!c_parser_check_balanced_raw_token_sequence (parser, &n)
6028 914 : || (c_parser_peek_nth_token_raw (parser, n)->type
6029 : != CPP_CLOSE_PAREN))
6030 : {
6031 1 : c_parser_balanced_token_sequence (parser);
6032 1 : TREE_VALUE (attribute) = NULL_TREE;
6033 3 : return;
6034 : }
6035 913 : if (n == 1)
6036 : {
6037 2 : error_at (first->location, "expected OpenMP directive name");
6038 2 : TREE_VALUE (attribute) = NULL_TREE;
6039 2 : return;
6040 : }
6041 911 : vec<c_token, va_gc> *v;
6042 911 : vec_alloc (v, n - 1);
6043 18777 : for (--n; n; --n)
6044 : {
6045 17866 : c_token *tok = c_parser_peek_token (parser);
6046 17866 : v->quick_push (*tok);
6047 17866 : c_parser_consume_token (parser);
6048 : }
6049 911 : tree arg = make_node (C_TOKEN_VEC);
6050 911 : C_TOKEN_VEC_TOKENS (arg) = v;
6051 911 : if (decl_p)
6052 58 : TREE_PUBLIC (arg) = 1;
6053 911 : TREE_VALUE (attribute) = tree_cons (NULL_TREE, arg, TREE_VALUE (attribute));
6054 : }
6055 :
6056 : /* Parse arguments of omp::sequence attribute.
6057 :
6058 : omp::[opt] directive-attr [ , omp::[opt] directive-attr ]... */
6059 :
6060 : static void
6061 157 : c_parser_omp_sequence_args (c_parser *parser, tree attribute)
6062 : {
6063 314 : do
6064 : {
6065 314 : c_token *token = c_parser_peek_token (parser);
6066 314 : if (token->type == CPP_NAME
6067 313 : && strcmp (IDENTIFIER_POINTER (token->value), "omp") == 0
6068 378 : && c_parser_peek_2nd_token (parser)->type == CPP_SCOPE)
6069 : {
6070 64 : c_parser_consume_token (parser);
6071 64 : c_parser_consume_token (parser);
6072 64 : token = c_parser_peek_token (parser);
6073 : }
6074 314 : bool directive = false;
6075 314 : const char *p;
6076 314 : if (token->type != CPP_NAME)
6077 : p = "";
6078 : else
6079 313 : p = IDENTIFIER_POINTER (token->value);
6080 314 : if (strcmp (p, "directive") == 0)
6081 : directive = true;
6082 12 : else if (strcmp (p, "sequence") != 0)
6083 : {
6084 7 : error_at (token->location, "expected %<directive%> or %<sequence%>");
6085 7 : unsigned nesting_depth = 0;
6086 :
6087 47 : while (true)
6088 : {
6089 : /* Peek at the next token. */
6090 27 : token = c_parser_peek_token (parser);
6091 : /* If we've reached the token we want, consume it and stop. */
6092 27 : if ((token->type == CPP_CLOSE_PAREN || token->type == CPP_COMMA)
6093 13 : && !nesting_depth)
6094 : break;
6095 : /* If we've run out of tokens, stop. */
6096 20 : if (token->type == CPP_EOF)
6097 : break;
6098 20 : if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
6099 : break;
6100 20 : if (token->type == CPP_OPEN_BRACE
6101 : || token->type == CPP_OPEN_PAREN
6102 : || token->type == CPP_OPEN_SQUARE)
6103 6 : ++nesting_depth;
6104 : else if (token->type == CPP_CLOSE_BRACE
6105 : || token->type == CPP_CLOSE_PAREN
6106 : || token->type == CPP_CLOSE_SQUARE)
6107 : {
6108 6 : if (nesting_depth-- == 0)
6109 : break;
6110 : }
6111 : /* Consume this token. */
6112 20 : c_parser_consume_token (parser);
6113 : }
6114 7 : if (c_parser_next_token_is_not (parser, CPP_COMMA))
6115 : break;
6116 0 : c_parser_consume_token (parser);
6117 0 : continue;
6118 0 : }
6119 307 : c_parser_consume_token (parser);
6120 307 : matching_parens parens;
6121 307 : if (parens.require_open (parser))
6122 : {
6123 305 : if (directive)
6124 301 : c_parser_omp_directive_args (parser, attribute, false);
6125 : else
6126 4 : c_parser_omp_sequence_args (parser, attribute);
6127 305 : parens.skip_until_found_close (parser);
6128 305 : if (c_parser_next_token_is_not (parser, CPP_COMMA))
6129 : break;
6130 157 : c_parser_consume_token (parser);
6131 : }
6132 2 : else if (c_parser_next_token_is_not (parser, CPP_COMMA))
6133 : break;
6134 : else
6135 0 : c_parser_consume_token (parser);
6136 : }
6137 : while (1);
6138 157 : }
6139 :
6140 : /* Parse standard (C23) attributes (including GNU attributes in the
6141 : gnu:: namespace).
6142 :
6143 : attribute-specifier-sequence:
6144 : attribute-specifier-sequence[opt] attribute-specifier
6145 :
6146 : attribute-specifier:
6147 : [ [ attribute-list ] ]
6148 :
6149 : attribute-list:
6150 : attribute[opt]
6151 : attribute-list, attribute[opt]
6152 :
6153 : attribute:
6154 : attribute-token attribute-argument-clause[opt]
6155 :
6156 : attribute-token:
6157 : standard-attribute
6158 : attribute-prefixed-token
6159 :
6160 : standard-attribute:
6161 : identifier
6162 :
6163 : attribute-prefixed-token:
6164 : attribute-prefix :: identifier
6165 :
6166 : attribute-prefix:
6167 : identifier
6168 :
6169 : attribute-argument-clause:
6170 : ( balanced-token-sequence[opt] )
6171 :
6172 : Keywords are accepted as identifiers for this purpose.
6173 :
6174 : As an extension, we permit an attribute-specifier to be:
6175 :
6176 : [ [ __extension__ attribute-list ] ]
6177 :
6178 : Two colons are then accepted as a synonym for ::. No attempt is made
6179 : to check whether the colons are immediately adjacent. LOOSE_SCOPE_P
6180 : indicates whether this relaxation is in effect. */
6181 :
6182 : static tree
6183 2908 : c_parser_std_attribute (c_parser *parser, bool for_tm)
6184 : {
6185 2908 : c_token *token = c_parser_peek_token (parser);
6186 2908 : tree ns, name, attribute;
6187 :
6188 : /* Parse the attribute-token. */
6189 2908 : if (token->type != CPP_NAME && token->type != CPP_KEYWORD)
6190 : {
6191 2 : c_parser_error (parser, "expected identifier");
6192 2 : return error_mark_node;
6193 : }
6194 2906 : name = canonicalize_attr_name (token->value);
6195 2906 : c_parser_consume_token (parser);
6196 2906 : if (c_parser_next_token_is (parser, CPP_SCOPE)
6197 3372 : || (c_parser_next_token_is (parser, CPP_COLON)
6198 39 : && (c_parser_peek_token (parser)->flags & COLON_SCOPE) != 0
6199 13 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
6200 : {
6201 2453 : ns = name;
6202 2453 : if (c_parser_next_token_is (parser, CPP_COLON))
6203 13 : c_parser_consume_token (parser);
6204 2453 : c_parser_consume_token (parser);
6205 2453 : token = c_parser_peek_token (parser);
6206 2453 : if (token->type != CPP_NAME && token->type != CPP_KEYWORD)
6207 : {
6208 0 : c_parser_error (parser, "expected identifier");
6209 0 : return error_mark_node;
6210 : }
6211 2453 : name = canonicalize_attr_name (token->value);
6212 2453 : c_parser_consume_token (parser);
6213 : }
6214 : else
6215 : ns = NULL_TREE;
6216 2906 : attribute = build_tree_list (build_tree_list (ns, name), NULL_TREE);
6217 :
6218 : /* Parse the arguments, if any. */
6219 2906 : const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (attribute));
6220 2906 : if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6221 : {
6222 1903 : if ((flag_openmp || flag_openmp_simd)
6223 9 : && ns
6224 7 : && is_attribute_p ("omp", ns)
6225 1915 : && (is_attribute_p ("directive", name)
6226 2 : || is_attribute_p ("sequence", name)
6227 1 : || is_attribute_p ("decl", name)))
6228 : {
6229 3 : error ("%<omp::%E%> attribute requires argument", name);
6230 3 : return error_mark_node;
6231 : }
6232 1909 : goto out;
6233 : }
6234 994 : {
6235 994 : location_t open_loc = c_parser_peek_token (parser)->location;
6236 994 : matching_parens parens;
6237 994 : parens.consume_open (parser);
6238 183 : if ((as && as->max_length == 0)
6239 : /* Special-case the transactional-memory attribute "outer",
6240 : which is specially handled but not registered as an
6241 : attribute, to avoid allowing arbitrary balanced token
6242 : sequences as arguments. */
6243 1154 : || is_attribute_p ("outer", name))
6244 : {
6245 24 : error_at (open_loc, "%qE attribute does not take any arguments", name);
6246 24 : parens.skip_until_found_close (parser);
6247 790 : return error_mark_node;
6248 : }
6249 : /* If this is a fake attribute created to handle -Wno-attributes,
6250 : we must skip parsing the arguments. */
6251 970 : if (as && !attribute_ignored_p (as))
6252 : {
6253 147 : bool takes_identifier
6254 : = (ns != NULL_TREE
6255 126 : && strcmp (IDENTIFIER_POINTER (ns), "gnu") == 0
6256 273 : && attribute_takes_identifier_p (name));
6257 : bool require_string
6258 : = (ns == NULL_TREE
6259 21 : && (strcmp (IDENTIFIER_POINTER (name), "deprecated") == 0
6260 11 : || strcmp (IDENTIFIER_POINTER (name), "nodiscard") == 0));
6261 : bool assume_attr
6262 : = (ns != NULL_TREE
6263 126 : && strcmp (IDENTIFIER_POINTER (ns), "gnu") == 0
6264 126 : && strcmp (IDENTIFIER_POINTER (name), "assume") == 0);
6265 294 : TREE_VALUE (attribute)
6266 147 : = c_parser_attribute_arguments (parser, takes_identifier,
6267 : require_string, assume_attr, false);
6268 : }
6269 : else
6270 : {
6271 57 : if ((flag_openmp || flag_openmp_simd)
6272 766 : && ns
6273 1589 : && is_attribute_p ("omp", ns))
6274 : {
6275 766 : if (is_attribute_p ("directive", name))
6276 : {
6277 554 : c_parser_omp_directive_args (parser, attribute, false);
6278 554 : parens.skip_until_found_close (parser);
6279 554 : return attribute;
6280 : }
6281 212 : else if (is_attribute_p ("decl", name))
6282 : {
6283 59 : TREE_VALUE (TREE_PURPOSE (attribute))
6284 59 : = get_identifier ("directive");
6285 59 : c_parser_omp_directive_args (parser, attribute, true);
6286 59 : parens.skip_until_found_close (parser);
6287 59 : return attribute;
6288 : }
6289 153 : else if (is_attribute_p ("sequence", name))
6290 : {
6291 153 : TREE_VALUE (TREE_PURPOSE (attribute))
6292 153 : = get_identifier ("directive");
6293 153 : c_parser_omp_sequence_args (parser, attribute);
6294 153 : parens.skip_until_found_close (parser);
6295 153 : TREE_VALUE (attribute) = nreverse (TREE_VALUE (attribute));
6296 153 : return attribute;
6297 : }
6298 : }
6299 57 : c_parser_balanced_token_sequence (parser);
6300 : }
6301 204 : parens.require_close (parser);
6302 : }
6303 2113 : out:
6304 2113 : if (ns == NULL_TREE && !for_tm && !as)
6305 : {
6306 : /* An attribute with standard syntax and no namespace specified
6307 : is a constraint violation if it is not one of the known
6308 : standard attributes. Diagnose it here with a pedwarn and
6309 : then discard it to prevent a duplicate warning later. */
6310 73 : pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
6311 : name);
6312 73 : return error_mark_node;
6313 : }
6314 : return attribute;
6315 : }
6316 :
6317 : static tree
6318 3010 : c_parser_std_attribute_list (c_parser *parser, bool for_tm)
6319 : {
6320 3010 : tree attributes = NULL_TREE;
6321 3260 : while (true)
6322 : {
6323 3260 : c_token *token = c_parser_peek_token (parser);
6324 3260 : if (token->type == CPP_CLOSE_SQUARE)
6325 : break;
6326 3044 : if (token->type == CPP_COMMA)
6327 : {
6328 136 : c_parser_consume_token (parser);
6329 136 : continue;
6330 : }
6331 2908 : tree attribute = c_parser_std_attribute (parser, for_tm);
6332 2908 : if (attribute != error_mark_node)
6333 : {
6334 2806 : TREE_CHAIN (attribute) = attributes;
6335 2806 : attributes = attribute;
6336 : }
6337 2908 : if (c_parser_next_token_is_not (parser, CPP_COMMA))
6338 : break;
6339 : }
6340 3010 : return attributes;
6341 : }
6342 :
6343 : static tree
6344 3010 : c_parser_std_attribute_specifier (c_parser *parser, bool for_tm)
6345 : {
6346 3010 : location_t loc = c_parser_peek_token (parser)->location;
6347 3010 : if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
6348 : return NULL_TREE;
6349 3010 : if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
6350 : {
6351 0 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
6352 0 : return NULL_TREE;
6353 : }
6354 3010 : tree attributes;
6355 3010 : if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
6356 : {
6357 42 : auto ext = disable_extension_diagnostics ();
6358 42 : c_parser_consume_token (parser);
6359 42 : attributes = c_parser_std_attribute_list (parser, for_tm);
6360 42 : restore_extension_diagnostics (ext);
6361 : }
6362 : else
6363 : {
6364 2968 : if (!for_tm)
6365 2948 : pedwarn_c11 (loc, OPT_Wpedantic,
6366 : "ISO C does not support %<[[]]%> attributes before C23");
6367 2968 : attributes = c_parser_std_attribute_list (parser, for_tm);
6368 : }
6369 3010 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
6370 3010 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
6371 3010 : return nreverse (attributes);
6372 : }
6373 :
6374 : /* Look past an optional balanced token sequence of raw look-ahead
6375 : tokens starting with the *Nth token. *N is updated to point to the
6376 : following token. Return true if such a sequence was found, false
6377 : if the tokens parsed were not balanced. */
6378 :
6379 : static bool
6380 13766 : c_parser_check_balanced_raw_token_sequence (c_parser *parser, unsigned int *n)
6381 : {
6382 61787 : while (true)
6383 : {
6384 61787 : c_token *token = c_parser_peek_nth_token_raw (parser, *n);
6385 61787 : switch (token->type)
6386 : {
6387 66 : case CPP_OPEN_BRACE:
6388 66 : {
6389 66 : ++*n;
6390 66 : if (c_parser_check_balanced_raw_token_sequence (parser, n))
6391 : {
6392 66 : token = c_parser_peek_nth_token_raw (parser, *n);
6393 66 : if (token->type == CPP_CLOSE_BRACE)
6394 66 : ++*n;
6395 : else
6396 : return false;
6397 : }
6398 : else
6399 : return false;
6400 66 : break;
6401 : }
6402 :
6403 10934 : case CPP_OPEN_PAREN:
6404 10934 : {
6405 10934 : ++*n;
6406 10934 : if (c_parser_check_balanced_raw_token_sequence (parser, n))
6407 : {
6408 10934 : token = c_parser_peek_nth_token_raw (parser, *n);
6409 10934 : if (token->type == CPP_CLOSE_PAREN)
6410 10934 : ++*n;
6411 : else
6412 : return false;
6413 : }
6414 : else
6415 : return false;
6416 10934 : break;
6417 : }
6418 :
6419 79 : case CPP_OPEN_SQUARE:
6420 79 : {
6421 79 : ++*n;
6422 79 : if (c_parser_check_balanced_raw_token_sequence (parser, n))
6423 : {
6424 79 : token = c_parser_peek_nth_token_raw (parser, *n);
6425 79 : if (token->type == CPP_CLOSE_SQUARE)
6426 79 : ++*n;
6427 : else
6428 : return false;
6429 : }
6430 : else
6431 : return false;
6432 79 : break;
6433 : }
6434 :
6435 : case CPP_CLOSE_BRACE:
6436 : case CPP_CLOSE_PAREN:
6437 : case CPP_CLOSE_SQUARE:
6438 : case CPP_EOF:
6439 : return true;
6440 :
6441 36942 : default:
6442 36942 : ++*n;
6443 36942 : break;
6444 : }
6445 : }
6446 : }
6447 :
6448 : /* Return whether standard attributes start with the Nth token. */
6449 :
6450 : static bool
6451 923707983 : c_parser_nth_token_starts_std_attributes (c_parser *parser, unsigned int n)
6452 : {
6453 923707983 : if (!(c_parser_peek_nth_token (parser, n)->type == CPP_OPEN_SQUARE
6454 2327048 : && c_parser_peek_nth_token (parser, n + 1)->type == CPP_OPEN_SQUARE))
6455 : return false;
6456 : /* In C, '[[' must start attributes. In Objective-C, we need to
6457 : check whether '[[' is matched by ']]'. */
6458 4458 : if (!c_dialect_objc ())
6459 : return true;
6460 0 : n += 2;
6461 0 : if (!c_parser_check_balanced_raw_token_sequence (parser, &n))
6462 : return false;
6463 0 : c_token *token = c_parser_peek_nth_token_raw (parser, n);
6464 0 : if (token->type != CPP_CLOSE_SQUARE)
6465 : return false;
6466 0 : token = c_parser_peek_nth_token_raw (parser, n + 1);
6467 0 : return token->type == CPP_CLOSE_SQUARE;
6468 : }
6469 :
6470 : /* Skip standard attribute tokens starting at Nth token (with 1 as the
6471 : next token), return index of the first token after the standard
6472 : attribute tokens, or N on failure. */
6473 :
6474 : static size_t
6475 329 : c_parser_skip_std_attribute_spec_seq (c_parser *parser, size_t n)
6476 : {
6477 329 : size_t orig_n = n;
6478 361 : while (true)
6479 : {
6480 345 : if (c_parser_peek_nth_token_raw (parser, n)->type == CPP_OPEN_SQUARE
6481 345 : && (c_parser_peek_nth_token_raw (parser, n + 1)->type
6482 : == CPP_OPEN_SQUARE))
6483 : {
6484 16 : unsigned int m = n + 2;
6485 16 : if (!c_parser_check_balanced_raw_token_sequence (parser, &m))
6486 0 : return orig_n;
6487 16 : c_token *token = c_parser_peek_nth_token_raw (parser, m);
6488 16 : if (token->type != CPP_CLOSE_SQUARE)
6489 : return orig_n;
6490 16 : token = c_parser_peek_nth_token_raw (parser, m + 1);
6491 16 : if (token->type != CPP_CLOSE_SQUARE)
6492 : return orig_n;
6493 16 : n = m + 2;
6494 : }
6495 : else
6496 : break;
6497 16 : }
6498 : return n;
6499 : }
6500 :
6501 : static tree
6502 2929 : c_parser_std_attribute_specifier_sequence (c_parser *parser)
6503 : {
6504 2929 : tree attributes = NULL_TREE;
6505 2990 : do
6506 : {
6507 2990 : tree attrs = c_parser_std_attribute_specifier (parser, false);
6508 2990 : attributes = chainon (attributes, attrs);
6509 : }
6510 2990 : while (c_parser_nth_token_starts_std_attributes (parser, 1));
6511 2929 : return attributes;
6512 : }
6513 :
6514 : /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
6515 : says whether alignment specifiers are OK (only in cases that might
6516 : be the type name of a compound literal).
6517 :
6518 : type-name:
6519 : specifier-qualifier-list abstract-declarator[opt]
6520 : */
6521 :
6522 : struct c_type_name *
6523 126428609 : c_parser_type_name (c_parser *parser, bool alignas_ok)
6524 : {
6525 126428609 : struct c_declspecs *specs = build_null_declspecs ();
6526 126428609 : struct c_declarator *declarator;
6527 126428609 : struct c_type_name *ret;
6528 126428609 : bool dummy = false;
6529 126428609 : c_parser_declspecs (parser, specs, false, true, true, alignas_ok, false,
6530 : false, true, cla_prefer_type);
6531 126428609 : if (!specs->declspecs_seen_p)
6532 : {
6533 5 : c_parser_error (parser, "expected specifier-qualifier-list");
6534 5 : return NULL;
6535 : }
6536 126428604 : if (specs->type != error_mark_node)
6537 : {
6538 126428587 : pending_xref_error ();
6539 126428587 : finish_declspecs (specs);
6540 : /* When the typename is declared, its type is a top level type, we should
6541 : call verify_counted_by_for_top_anonymous_type. */
6542 126428587 : if (specs->typespec_kind == ctsk_tagdef)
6543 1669 : verify_counted_by_for_top_anonymous_type (specs->type);
6544 : }
6545 252857208 : declarator = c_parser_declarator (parser,
6546 126428604 : specs->typespec_kind != ctsk_none,
6547 : C_DTR_ABSTRACT, &dummy);
6548 126428604 : if (declarator == NULL)
6549 : return NULL;
6550 126428599 : ret = XOBNEW (&parser_obstack, struct c_type_name);
6551 126428599 : ret->specs = specs;
6552 126428599 : ret->declarator = declarator;
6553 126428599 : return ret;
6554 : }
6555 :
6556 : /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
6557 :
6558 : initializer:
6559 : assignment-expression
6560 : { initializer-list }
6561 : { initializer-list , }
6562 :
6563 : initializer-list:
6564 : designation[opt] initializer
6565 : initializer-list , designation[opt] initializer
6566 :
6567 : designation:
6568 : designator-list =
6569 :
6570 : designator-list:
6571 : designator
6572 : designator-list designator
6573 :
6574 : designator:
6575 : array-designator
6576 : . identifier
6577 :
6578 : array-designator:
6579 : [ constant-expression ]
6580 :
6581 : GNU extensions:
6582 :
6583 : initializer:
6584 : { }
6585 :
6586 : designation:
6587 : array-designator
6588 : identifier :
6589 :
6590 : array-designator:
6591 : [ constant-expression ... constant-expression ]
6592 :
6593 : Any expression without commas is accepted in the syntax for the
6594 : constant-expressions, with non-constant expressions rejected later.
6595 :
6596 : DECL is the declaration we're parsing this initializer for.
6597 :
6598 : This function is only used for top-level initializers; for nested
6599 : ones, see c_parser_initval. */
6600 :
6601 : static struct c_expr
6602 6418505 : c_parser_initializer (c_parser *parser, tree decl)
6603 : {
6604 6418505 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6605 107998 : return c_parser_braced_init (parser, NULL_TREE, false, NULL,
6606 107998 : decl != error_mark_node
6607 215994 : && C_DECL_VARIABLE_SIZE (decl));
6608 : else
6609 : {
6610 6310507 : struct c_expr ret;
6611 6310507 : location_t loc = c_parser_peek_token (parser)->location;
6612 6310507 : ret = c_parser_expr_no_commas (parser, NULL);
6613 6310505 : if (decl != error_mark_node && C_DECL_VARIABLE_SIZE (decl))
6614 : {
6615 2 : error_at (loc,
6616 : "variable-sized object may not be initialized except "
6617 : "with an empty initializer");
6618 2 : ret.set_error ();
6619 : }
6620 : /* This is handled mostly by gimplify.cc, but we have to deal with
6621 : not warning about int x = x; as it is a GCC extension to turn off
6622 : this warning but only if warn_init_self is zero. */
6623 6310505 : if (VAR_P (decl)
6624 6310457 : && !DECL_EXTERNAL (decl)
6625 6310457 : && !TREE_STATIC (decl)
6626 6189850 : && ret.value == decl
6627 12620962 : && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
6628 90239 : suppress_warning (decl, OPT_Winit_self);
6629 6310505 : if (TREE_CODE (ret.value) != STRING_CST
6630 6310505 : && (TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR
6631 96523 : || C_DECL_DECLARED_CONSTEXPR (COMPOUND_LITERAL_EXPR_DECL
6632 : (ret.value))))
6633 6199914 : ret = convert_lvalue_to_rvalue (loc, ret, true, true, true);
6634 6310505 : return ret;
6635 : }
6636 : }
6637 :
6638 : /* The location of the last comma within the current initializer list,
6639 : or UNKNOWN_LOCATION if not within one. */
6640 :
6641 : location_t last_init_list_comma;
6642 :
6643 : /* Parse a braced initializer list. TYPE is the type specified for a
6644 : compound literal, and NULL_TREE for other initializers and for
6645 : nested braced lists. NESTED_P is true for nested braced lists,
6646 : false for the list of a compound literal or the list that is the
6647 : top-level initializer in a declaration. VARSIZE_P indicates
6648 : whether the object to be initialized has a variable size. */
6649 :
6650 : static struct c_expr
6651 1377451 : c_parser_braced_init (c_parser *parser, tree type, bool nested_p,
6652 : struct obstack *outer_obstack, bool varsize_p)
6653 : {
6654 1377451 : struct c_expr ret;
6655 1377451 : struct obstack braced_init_obstack;
6656 1377451 : location_t brace_loc = c_parser_peek_token (parser)->location;
6657 1377451 : gcc_obstack_init (&braced_init_obstack);
6658 1377451 : gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6659 1377451 : bool save_c_omp_array_section_p = c_omp_array_section_p;
6660 1377451 : c_omp_array_section_p = false;
6661 1377451 : bool zero_init_padding_bits = false;
6662 1377451 : matching_braces braces;
6663 1377451 : braces.consume_open (parser);
6664 1377451 : if (nested_p)
6665 : {
6666 340140 : finish_implicit_inits (brace_loc, outer_obstack);
6667 340140 : push_init_level (brace_loc, 0, &braced_init_obstack);
6668 : }
6669 : else
6670 1037311 : really_start_incremental_init (type);
6671 1377451 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6672 : {
6673 3142 : pedwarn_c11 (brace_loc, OPT_Wpedantic,
6674 : "ISO C forbids empty initializer braces before C23");
6675 3142 : if (flag_isoc23)
6676 1377451 : zero_init_padding_bits = true;
6677 : }
6678 : else
6679 : {
6680 1374309 : if (varsize_p)
6681 61 : error_at (brace_loc,
6682 : "variable-sized object may not be initialized except "
6683 : "with an empty initializer");
6684 : /* Parse a non-empty initializer list, possibly with a trailing
6685 : comma. */
6686 8992756 : while (true)
6687 : {
6688 8992756 : c_parser_initelt (parser, &braced_init_obstack);
6689 8992756 : if (parser->error)
6690 : break;
6691 8992726 : if (c_parser_next_token_is (parser, CPP_COMMA))
6692 : {
6693 7621226 : last_init_list_comma = c_parser_peek_token (parser)->location;
6694 7621226 : c_parser_consume_token (parser);
6695 : /* CPP_EMBED should be always in between two CPP_COMMA
6696 : tokens. */
6697 15242555 : while (c_parser_next_token_is (parser, CPP_EMBED))
6698 : {
6699 103 : c_token *embed = c_parser_peek_token (parser);
6700 103 : c_parser_consume_token (parser);
6701 103 : c_expr embed_val;
6702 103 : embed_val.value = embed->value;
6703 103 : embed_val.original_code = RAW_DATA_CST;
6704 103 : embed_val.original_type = integer_type_node;
6705 103 : set_c_expr_source_range (&embed_val, embed->get_range ());
6706 103 : embed_val.m_decimal = 0;
6707 103 : process_init_element (embed->location, embed_val, false,
6708 : &braced_init_obstack);
6709 103 : gcc_checking_assert (c_parser_next_token_is (parser,
6710 : CPP_COMMA));
6711 103 : last_init_list_comma = c_parser_peek_token (parser)->location;
6712 103 : c_parser_consume_token (parser);
6713 : }
6714 : }
6715 : else
6716 : break;
6717 7621226 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6718 : break;
6719 : }
6720 : }
6721 1377451 : c_omp_array_section_p = save_c_omp_array_section_p;
6722 1377451 : c_token *next_tok = c_parser_peek_token (parser);
6723 1377451 : if (next_tok->type != CPP_CLOSE_BRACE)
6724 : {
6725 31 : ret.set_error ();
6726 31 : ret.original_code = ERROR_MARK;
6727 31 : ret.original_type = NULL;
6728 31 : braces.skip_until_found_close (parser);
6729 31 : pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma);
6730 31 : obstack_free (&braced_init_obstack, NULL);
6731 : return ret;
6732 : }
6733 1377420 : location_t close_loc = next_tok->location;
6734 1377420 : c_parser_consume_token (parser);
6735 1377420 : ret = pop_init_level (brace_loc, 0, &braced_init_obstack, close_loc);
6736 1377420 : if (zero_init_padding_bits
6737 2825 : && ret.value
6738 2783 : && TREE_CODE (ret.value) == CONSTRUCTOR)
6739 2688 : CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
6740 1377420 : obstack_free (&braced_init_obstack, NULL);
6741 1377420 : set_c_expr_source_range (&ret, brace_loc, close_loc);
6742 1377420 : return ret;
6743 : }
6744 :
6745 : /* Parse a nested initializer, including designators. */
6746 :
6747 : static void
6748 8992756 : c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
6749 : {
6750 : /* Parse any designator or designator list. A single array
6751 : designator may have the subsequent "=" omitted in GNU C, but a
6752 : longer list or a structure member designator may not. */
6753 8992756 : if (c_parser_next_token_is (parser, CPP_NAME)
6754 8992756 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
6755 : {
6756 : /* Old-style structure member designator. */
6757 156 : set_init_label (c_parser_peek_token (parser)->location,
6758 156 : c_parser_peek_token (parser)->value,
6759 156 : c_parser_peek_token (parser)->location,
6760 : braced_init_obstack);
6761 : /* Use the colon as the error location. */
6762 156 : pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
6763 : "obsolete use of designated initializer with %<:%>");
6764 156 : c_parser_consume_token (parser);
6765 156 : c_parser_consume_token (parser);
6766 : }
6767 : else
6768 : {
6769 : /* des_seen is 0 if there have been no designators, 1 if there
6770 : has been a single array designator and 2 otherwise. */
6771 : int des_seen = 0;
6772 : /* Location of a designator. */
6773 : location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
6774 9029718 : while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
6775 18057500 : || c_parser_next_token_is (parser, CPP_DOT))
6776 : {
6777 37118 : int des_prev = des_seen;
6778 37118 : if (!des_seen)
6779 34840 : des_loc = c_parser_peek_token (parser)->location;
6780 37118 : if (des_seen < 2)
6781 34918 : des_seen++;
6782 37118 : if (c_parser_next_token_is (parser, CPP_DOT))
6783 : {
6784 35182 : des_seen = 2;
6785 35182 : c_parser_consume_token (parser);
6786 35182 : if (c_parser_next_token_is (parser, CPP_NAME))
6787 : {
6788 35182 : set_init_label (des_loc, c_parser_peek_token (parser)->value,
6789 35182 : c_parser_peek_token (parser)->location,
6790 : braced_init_obstack);
6791 35182 : c_parser_consume_token (parser);
6792 : }
6793 : else
6794 : {
6795 0 : struct c_expr init;
6796 0 : init.set_error ();
6797 0 : init.original_code = ERROR_MARK;
6798 0 : init.original_type = NULL;
6799 0 : c_parser_error (parser, "expected identifier");
6800 0 : c_parser_skip_until_found (parser, CPP_COMMA, NULL);
6801 0 : process_init_element (input_location, init, false,
6802 : braced_init_obstack);
6803 0 : return;
6804 : }
6805 : }
6806 : else
6807 : {
6808 1936 : struct c_expr first_expr;
6809 1936 : tree first, second;
6810 1936 : location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
6811 1936 : location_t array_index_loc = UNKNOWN_LOCATION;
6812 : /* ??? Following the old parser, [ objc-receiver
6813 : objc-message-args ] is accepted as an initializer,
6814 : being distinguished from a designator by what follows
6815 : the first assignment expression inside the square
6816 : brackets, but after a first array designator a
6817 : subsequent square bracket is for Objective-C taken to
6818 : start an expression, using the obsolete form of
6819 : designated initializer without '=', rather than
6820 : possibly being a second level of designation: in LALR
6821 : terms, the '[' is shifted rather than reducing
6822 : designator to designator-list. */
6823 1936 : if (des_prev == 1 && c_dialect_objc ())
6824 : {
6825 0 : des_seen = des_prev;
6826 0 : break;
6827 : }
6828 1936 : if (des_prev == 0 && c_dialect_objc ())
6829 : {
6830 : /* This might be an array designator or an
6831 : Objective-C message expression. If the former,
6832 : continue parsing here; if the latter, parse the
6833 : remainder of the initializer given the starting
6834 : primary-expression. ??? It might make sense to
6835 : distinguish when des_prev == 1 as well; see
6836 : previous comment. */
6837 0 : tree rec, args;
6838 0 : struct c_expr mexpr;
6839 0 : c_parser_consume_token (parser);
6840 0 : if (c_parser_peek_token (parser)->type == CPP_NAME
6841 0 : && ((c_parser_peek_token (parser)->id_kind
6842 : == C_ID_TYPENAME)
6843 0 : || (c_parser_peek_token (parser)->id_kind
6844 : == C_ID_CLASSNAME)))
6845 : {
6846 : /* Type name receiver. */
6847 0 : tree id = c_parser_peek_token (parser)->value;
6848 0 : c_parser_consume_token (parser);
6849 0 : rec = objc_get_class_reference (id);
6850 0 : goto parse_message_args;
6851 : }
6852 0 : array_index_loc = c_parser_peek_token (parser)->location;
6853 0 : first_expr = c_parser_expr_no_commas (parser, NULL);
6854 0 : mark_exp_read (first_expr.value);
6855 0 : if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
6856 0 : || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
6857 0 : goto array_desig_after_first;
6858 0 : first = first_expr.value;
6859 : /* Expression receiver. So far only one part
6860 : without commas has been parsed; there might be
6861 : more of the expression. */
6862 0 : rec = first;
6863 0 : while (c_parser_next_token_is (parser, CPP_COMMA))
6864 : {
6865 0 : struct c_expr next;
6866 0 : location_t comma_loc, exp_loc;
6867 0 : comma_loc = c_parser_peek_token (parser)->location;
6868 0 : c_parser_consume_token (parser);
6869 0 : exp_loc = c_parser_peek_token (parser)->location;
6870 0 : next = c_parser_expr_no_commas (parser, NULL);
6871 0 : next = convert_lvalue_to_rvalue (exp_loc, next,
6872 : true, true);
6873 0 : rec = build_compound_expr (comma_loc, rec, next.value);
6874 : }
6875 0 : parse_message_args:
6876 : /* Now parse the objc-message-args. */
6877 0 : args = c_parser_objc_message_args (parser);
6878 0 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6879 : "expected %<]%>");
6880 0 : mexpr.value
6881 0 : = objc_build_message_expr (rec, args);
6882 0 : mexpr.original_code = ERROR_MARK;
6883 0 : mexpr.original_type = NULL;
6884 0 : mexpr.m_decimal = 0;
6885 : /* Now parse and process the remainder of the
6886 : initializer, starting with this message
6887 : expression as a primary-expression. */
6888 0 : c_parser_initval (parser, &mexpr, braced_init_obstack);
6889 0 : return;
6890 : }
6891 1936 : c_parser_consume_token (parser);
6892 1936 : array_index_loc = c_parser_peek_token (parser)->location;
6893 1936 : first_expr = c_parser_expr_no_commas (parser, NULL);
6894 1936 : mark_exp_read (first_expr.value);
6895 1936 : array_desig_after_first:
6896 1936 : first_expr = convert_lvalue_to_rvalue (array_index_loc,
6897 : first_expr,
6898 : true, true);
6899 1936 : first = first_expr.value;
6900 1936 : if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6901 : {
6902 397 : ellipsis_loc = c_parser_peek_token (parser)->location;
6903 397 : c_parser_consume_token (parser);
6904 397 : second = convert_lvalue_to_rvalue (ellipsis_loc,
6905 : (c_parser_expr_no_commas
6906 : (parser, NULL)),
6907 : true, true).value;
6908 397 : mark_exp_read (second);
6909 : }
6910 : else
6911 : second = NULL_TREE;
6912 1936 : if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
6913 : {
6914 1936 : c_parser_consume_token (parser);
6915 1936 : set_init_index (array_index_loc, first, second,
6916 : braced_init_obstack);
6917 1936 : if (second)
6918 397 : pedwarn (ellipsis_loc, OPT_Wpedantic,
6919 : "ISO C forbids specifying range of elements to initialize");
6920 : }
6921 : else
6922 0 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6923 : "expected %<]%>");
6924 : }
6925 : }
6926 8992600 : if (des_seen >= 1)
6927 : {
6928 34840 : if (c_parser_next_token_is (parser, CPP_EQ))
6929 : {
6930 34819 : pedwarn_c90 (des_loc, OPT_Wpedantic,
6931 : "ISO C90 forbids specifying subobject "
6932 : "to initialize");
6933 34819 : c_parser_consume_token (parser);
6934 : }
6935 : else
6936 : {
6937 21 : if (des_seen == 1)
6938 19 : pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
6939 : "obsolete use of designated initializer without %<=%>");
6940 : else
6941 : {
6942 2 : struct c_expr init;
6943 2 : init.set_error ();
6944 2 : init.original_code = ERROR_MARK;
6945 2 : init.original_type = NULL;
6946 2 : c_parser_error (parser, "expected %<=%>");
6947 2 : c_parser_skip_until_found (parser, CPP_COMMA, NULL);
6948 2 : process_init_element (input_location, init, false,
6949 : braced_init_obstack);
6950 2 : return;
6951 : }
6952 : }
6953 : }
6954 : }
6955 8992754 : c_parser_initval (parser, NULL, braced_init_obstack);
6956 : }
6957 :
6958 : /* Parse a nested initializer; as c_parser_initializer but parses
6959 : initializers within braced lists, after any designators have been
6960 : applied. If AFTER is not NULL then it is an Objective-C message
6961 : expression which is the primary-expression starting the
6962 : initializer. */
6963 :
6964 : static void
6965 8992754 : c_parser_initval (c_parser *parser, struct c_expr *after,
6966 : struct obstack * braced_init_obstack)
6967 : {
6968 8992754 : struct c_expr init;
6969 8992754 : gcc_assert (!after || c_dialect_objc ());
6970 8992754 : location_t loc = c_parser_peek_token (parser)->location;
6971 :
6972 8992754 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
6973 340140 : init = c_parser_braced_init (parser, NULL_TREE, true,
6974 : braced_init_obstack, false);
6975 : else
6976 : {
6977 8652614 : init = c_parser_expr_no_commas (parser, after);
6978 8652614 : if (init.value != NULL_TREE
6979 8652614 : && TREE_CODE (init.value) != STRING_CST
6980 17263684 : && (TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR
6981 177 : || C_DECL_DECLARED_CONSTEXPR (COMPOUND_LITERAL_EXPR_DECL
6982 : (init.value))))
6983 8610898 : init = convert_lvalue_to_rvalue (loc, init, true, true, true);
6984 : }
6985 8992754 : tree val = init.value;
6986 8992754 : process_init_element (loc, init, false, braced_init_obstack);
6987 :
6988 : /* Attempt to optimize large char array initializers into RAW_DATA_CST
6989 : to save compile time and memory even when not using #embed. */
6990 8992754 : static unsigned vals_to_ignore;
6991 8992754 : if (vals_to_ignore)
6992 : /* If earlier call determined there is certain number of CPP_COMMA
6993 : CPP_NUMBER tokens with 0-255 int values, but not enough for
6994 : RAW_DATA_CST to be beneficial, don't try to check it again until
6995 : they are all parsed. */
6996 6875 : --vals_to_ignore;
6997 8985879 : else if (val
6998 8985783 : && TREE_CODE (val) == INTEGER_CST
6999 4246819 : && TREE_TYPE (val) == integer_type_node
7000 12683432 : && c_parser_next_token_is (parser, CPP_COMMA))
7001 3029407 : if (unsigned int len = c_maybe_optimize_large_byte_initializer ())
7002 : {
7003 8766 : char buf1[64];
7004 8766 : unsigned int i;
7005 8766 : gcc_checking_assert (len >= 64);
7006 : location_t last_loc = UNKNOWN_LOCATION;
7007 21529 : for (i = 0; i < 64; ++i)
7008 : {
7009 21431 : c_token *tok = c_parser_peek_nth_token_raw (parser, 1 + 2 * i);
7010 21431 : if (tok->type != CPP_COMMA)
7011 : break;
7012 20552 : tok = c_parser_peek_nth_token_raw (parser, 2 + 2 * i);
7013 20552 : if (tok->type != CPP_NUMBER
7014 12763 : || TREE_CODE (tok->value) != INTEGER_CST
7015 12763 : || TREE_TYPE (tok->value) != integer_type_node
7016 12763 : || wi::neg_p (wi::to_wide (tok->value))
7017 33315 : || wi::to_widest (tok->value) > UCHAR_MAX)
7018 : break;
7019 12763 : buf1[i] = (char) tree_to_uhwi (tok->value);
7020 12763 : if (i == 0)
7021 1211 : loc = tok->location;
7022 12763 : last_loc = tok->location;
7023 : }
7024 8766 : if (i < 64)
7025 : {
7026 8668 : vals_to_ignore = i;
7027 8674 : return;
7028 : }
7029 98 : c_token *tok = c_parser_peek_nth_token_raw (parser, 1 + 2 * i);
7030 : /* If 64 CPP_COMMA CPP_NUMBER pairs are followed by CPP_CLOSE_BRACE,
7031 : punt if len is INT_MAX as that can mean this is a flexible array
7032 : member and in that case we need one CPP_NUMBER afterwards
7033 : (as guaranteed for CPP_EMBED). */
7034 98 : if (tok->type == CPP_CLOSE_BRACE && len != INT_MAX)
7035 : len = i;
7036 96 : else if (tok->type != CPP_COMMA
7037 96 : || (c_parser_peek_nth_token_raw (parser, 2 + 2 * i)->type
7038 : != CPP_NUMBER))
7039 : {
7040 6 : vals_to_ignore = i;
7041 6 : return;
7042 : }
7043 : /* Ensure the STRING_CST fits into 128K. */
7044 92 : unsigned int max_len = 131072 - offsetof (struct tree_string, str) - 1;
7045 92 : unsigned int orig_len = len;
7046 92 : unsigned int off = 0, last = 0;
7047 92 : if (!wi::neg_p (wi::to_wide (val)) && wi::to_widest (val) <= UCHAR_MAX)
7048 84 : off = 1;
7049 92 : len = MIN (len, max_len - off);
7050 92 : char *buf2 = XNEWVEC (char, len + off);
7051 92 : if (off)
7052 84 : buf2[0] = (char) tree_to_uhwi (val);
7053 92 : memcpy (buf2 + off, buf1, i);
7054 5980 : for (unsigned int j = 0; j < i; ++j)
7055 : {
7056 5888 : c_parser_peek_token (parser);
7057 5888 : c_parser_consume_token (parser);
7058 5888 : c_parser_peek_token (parser);
7059 5888 : c_parser_consume_token (parser);
7060 : }
7061 19700 : for (; i < len; ++i)
7062 : {
7063 19660 : if (!c_parser_next_token_is (parser, CPP_COMMA))
7064 : break;
7065 19658 : tok = c_parser_peek_2nd_token (parser);
7066 19658 : if (tok->type != CPP_NUMBER
7067 19650 : || TREE_CODE (tok->value) != INTEGER_CST
7068 19650 : || TREE_TYPE (tok->value) != integer_type_node
7069 19650 : || wi::neg_p (wi::to_wide (tok->value))
7070 39308 : || wi::to_widest (tok->value) > UCHAR_MAX)
7071 : break;
7072 19650 : c_token *tok2 = c_parser_peek_nth_token (parser, 3);
7073 19650 : if (tok2->type != CPP_COMMA && tok2->type != CPP_CLOSE_BRACE)
7074 : break;
7075 19647 : buf2[i + off] = (char) tree_to_uhwi (tok->value);
7076 : /* If orig_len is INT_MAX, this can be flexible array member and
7077 : in that case we need to ensure another element which
7078 : for CPP_EMBED is normally guaranteed after it. Include
7079 : that byte in the RAW_DATA_OWNER though, so it can be optimized
7080 : later. */
7081 19647 : if (orig_len == INT_MAX
7082 19647 : && (tok2->type == CPP_CLOSE_BRACE
7083 12859 : || (c_parser_peek_nth_token (parser, 4)->type
7084 : != CPP_NUMBER)))
7085 : {
7086 : last = 1;
7087 : break;
7088 : }
7089 19608 : last_loc = tok->location;
7090 19608 : c_parser_consume_token (parser);
7091 19608 : c_parser_consume_token (parser);
7092 : }
7093 92 : val = make_node (RAW_DATA_CST);
7094 92 : TREE_TYPE (val) = integer_type_node;
7095 92 : RAW_DATA_LENGTH (val) = i;
7096 92 : tree owner = build_string (i + off + last, buf2);
7097 92 : XDELETEVEC (buf2);
7098 92 : TREE_TYPE (owner) = build_array_type_nelts (unsigned_char_type_node,
7099 92 : i + off + last);
7100 92 : RAW_DATA_OWNER (val) = owner;
7101 92 : RAW_DATA_POINTER (val) = TREE_STRING_POINTER (owner) + off;
7102 92 : init.value = val;
7103 92 : set_c_expr_source_range (&init, loc, last_loc);
7104 92 : init.original_code = RAW_DATA_CST;
7105 92 : init.original_type = integer_type_node;
7106 92 : init.m_decimal = 0;
7107 92 : process_init_element (loc, init, false, braced_init_obstack);
7108 : }
7109 : }
7110 :
7111 : /* Parse a compound statement (possibly a function body) (C90 6.6.2,
7112 : C99 6.8.2, C11 6.8.2, C23 6.8.2).
7113 :
7114 : compound-statement:
7115 : { block-item-list[opt] }
7116 : { label-declarations block-item-list }
7117 :
7118 : block-item-list:
7119 : block-item
7120 : block-item-list block-item
7121 :
7122 : block-item:
7123 : label
7124 : nested-declaration
7125 : statement
7126 :
7127 : nested-declaration:
7128 : declaration
7129 :
7130 : GNU extensions:
7131 :
7132 : compound-statement:
7133 : { label-declarations block-item-list }
7134 :
7135 : nested-declaration:
7136 : __extension__ nested-declaration
7137 : nested-function-definition
7138 :
7139 : label-declarations:
7140 : label-declaration
7141 : label-declarations label-declaration
7142 :
7143 : label-declaration:
7144 : __label__ identifier-list ;
7145 :
7146 : Allowing the mixing of declarations and code is new in C99. The
7147 : GNU syntax also permits (not shown above) labels at the end of
7148 : compound statements, which yield an error. We don't allow labels
7149 : on declarations; this might seem like a natural extension, but
7150 : there would be a conflict between gnu-attributes on the label and
7151 : prefix gnu-attributes on the declaration. ??? The syntax follows the
7152 : old parser in requiring something after label declarations.
7153 : Although they are erroneous if the labels declared aren't defined,
7154 : is it useful for the syntax to be this way?
7155 :
7156 : OpenACC:
7157 :
7158 : block-item:
7159 : openacc-directive
7160 :
7161 : openacc-directive:
7162 : update-directive
7163 :
7164 : OpenMP:
7165 :
7166 : block-item:
7167 : openmp-directive
7168 :
7169 : openmp-directive:
7170 : barrier-directive
7171 : flush-directive
7172 : taskwait-directive
7173 : taskyield-directive
7174 : cancel-directive
7175 : cancellation-point-directive */
7176 :
7177 : static tree
7178 38591035 : c_parser_compound_statement (c_parser *parser, location_t *endlocp)
7179 : {
7180 38591035 : tree stmt;
7181 38591035 : location_t brace_loc;
7182 38591035 : brace_loc = c_parser_peek_token (parser)->location;
7183 38591035 : if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7184 : {
7185 : /* Ensure a scope is entered and left anyway to avoid confusion
7186 : if we have just prepared to enter a function body. */
7187 16 : stmt = c_begin_compound_stmt (true);
7188 16 : c_end_compound_stmt (brace_loc, stmt, true);
7189 16 : return error_mark_node;
7190 : }
7191 38591019 : stmt = c_begin_compound_stmt (true);
7192 38591019 : location_t end_loc = c_parser_compound_statement_nostart (parser);
7193 38591018 : if (endlocp)
7194 37668159 : *endlocp = end_loc;
7195 :
7196 38591018 : return c_end_compound_stmt (brace_loc, stmt, true);
7197 : }
7198 :
7199 : /* Diagnose errors related to imperfectly nested loops in an OMP
7200 : loop construct. This function is called when such code is seen.
7201 : Only issue one such diagnostic no matter how much invalid
7202 : intervening code there is in the loop.
7203 : FIXME: maybe the location associated with the diagnostic should
7204 : be the current parser token instead of the location of the outer loop
7205 : nest. */
7206 :
7207 : static void
7208 299 : check_omp_intervening_code (c_parser *parser)
7209 : {
7210 299 : struct omp_for_parse_data *omp_for_parse_state = parser->omp_for_parse_state;
7211 299 : gcc_assert (omp_for_parse_state);
7212 :
7213 299 : if (!omp_for_parse_state->in_intervening_code)
7214 : return;
7215 278 : omp_for_parse_state->saw_intervening_code = true;
7216 :
7217 : /* Only diagnose errors related to perfect nesting once. */
7218 278 : if (!omp_for_parse_state->perfect_nesting_fail)
7219 : {
7220 :
7221 : /* OpenACC does not (yet) permit intervening code, in
7222 : addition to situations forbidden by the OpenMP spec. */
7223 256 : if (omp_for_parse_state->code == OACC_LOOP)
7224 : {
7225 3 : error_at (omp_for_parse_state->for_loc,
7226 : "inner loops must be perfectly nested in "
7227 : "%<#pragma acc loop%>");
7228 3 : omp_for_parse_state->perfect_nesting_fail = true;
7229 : }
7230 253 : else if (omp_for_parse_state->ordered)
7231 : {
7232 11 : error_at (omp_for_parse_state->for_loc,
7233 : "inner loops must be perfectly nested with "
7234 : "%<ordered%> clause");
7235 11 : omp_for_parse_state->perfect_nesting_fail = true;
7236 : }
7237 242 : else if (omp_for_parse_state->inscan)
7238 : {
7239 2 : error_at (omp_for_parse_state->for_loc,
7240 : "inner loops must be perfectly nested with "
7241 : "%<reduction%> %<inscan%> clause");
7242 2 : omp_for_parse_state->perfect_nesting_fail = true;
7243 : }
7244 240 : else if (omp_for_parse_state->code == OMP_TILE)
7245 : {
7246 9 : error_at (omp_for_parse_state->for_loc,
7247 : "inner loops must be perfectly nested in "
7248 : "%<pragma omp tile%>");
7249 9 : omp_for_parse_state->perfect_nesting_fail = true;
7250 : }
7251 256 : if (omp_for_parse_state->perfect_nesting_fail)
7252 25 : omp_for_parse_state->fail = true;
7253 : }
7254 : }
7255 :
7256 : /* Helper function for below: wrap an OMP_STRUCTURED_BLOCK around SL
7257 : and add the statement to the current list. If SL is an empty statement
7258 : list, do nothing. */
7259 : static void
7260 294 : add_structured_block_stmt (tree sl)
7261 : {
7262 294 : if (TREE_CODE (sl) != STATEMENT_LIST
7263 294 : || !tsi_end_p (tsi_start (sl)))
7264 152 : add_stmt (build1 (OMP_STRUCTURED_BLOCK, void_type_node, sl));
7265 294 : }
7266 :
7267 : struct c_omp_attribute_data
7268 : {
7269 : vec<c_token, va_gc> *tokens;
7270 : const c_omp_directive *dir;
7271 : c_omp_directive_kind kind;
7272 : };
7273 :
7274 : /* Handle omp::directive and omp::sequence attributes in ATTRS
7275 : (if any) at the start of a statement or in attribute-declaration. */
7276 :
7277 : static bool
7278 875 : c_parser_handle_statement_omp_attributes (c_parser *parser, tree &attrs,
7279 : bool *have_std_attrs)
7280 : {
7281 875 : if (!flag_openmp && !flag_openmp_simd)
7282 : return false;
7283 :
7284 610 : auto_vec<c_omp_attribute_data, 16> vd;
7285 610 : int cnt = 0;
7286 610 : int tokens = 0;
7287 610 : bool bad = false;
7288 1220 : for (tree *pa = &attrs; *pa; )
7289 610 : if (is_attribute_namespace_p ("omp", *pa)
7290 610 : && is_attribute_p ("directive", get_attribute_name (*pa)))
7291 : {
7292 609 : cnt++;
7293 1358 : for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a))
7294 : {
7295 749 : tree d = TREE_VALUE (a);
7296 749 : gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
7297 749 : vec<c_token, va_gc> *toks = C_TOKEN_VEC_TOKENS (d);
7298 749 : c_token *first = toks->address ();
7299 749 : c_token *last = first + toks->length ();
7300 749 : if (parser->omp_attrs_forbidden_p)
7301 : {
7302 14 : error_at (first->location,
7303 : "mixing OpenMP directives with attribute and pragma "
7304 : "syntax on the same statement");
7305 14 : parser->omp_attrs_forbidden_p = false;
7306 14 : bad = true;
7307 : }
7308 735 : else if (TREE_PUBLIC (d))
7309 : {
7310 3 : error_at (first->location,
7311 : "OpenMP %<omp::decl%> attribute on a statement");
7312 3 : bad = true;
7313 : }
7314 749 : const char *directive[3] = {};
7315 2208 : for (int i = 0; i < 3; i++)
7316 : {
7317 2026 : tree id = NULL_TREE;
7318 2026 : if (first + i == last)
7319 : break;
7320 1781 : if (first[i].type == CPP_NAME)
7321 1341 : id = first[i].value;
7322 440 : else if (first[i].type == CPP_KEYWORD)
7323 118 : id = ridpointers[(int) first[i].keyword];
7324 : else
7325 : break;
7326 1459 : directive[i] = IDENTIFIER_POINTER (id);
7327 : }
7328 749 : const c_omp_directive *dir = NULL;
7329 749 : if (directive[0])
7330 749 : dir = c_omp_categorize_directive (directive[0], directive[1],
7331 : directive[2]);
7332 749 : if (dir == NULL)
7333 : {
7334 1 : error_at (first->location,
7335 : "unknown OpenMP directive name in %qs attribute "
7336 : "argument",
7337 1 : TREE_PUBLIC (d) ? "omp::decl" : "omp::directive");
7338 1 : continue;
7339 : }
7340 748 : c_omp_directive_kind kind = dir->kind;
7341 748 : if (dir->id == PRAGMA_OMP_ORDERED)
7342 : {
7343 : /* ordered is C_OMP_DIR_CONSTRUCT only if it doesn't contain
7344 : depend/doacross clause. */
7345 8 : if (directive[1]
7346 4 : && (strcmp (directive[1], "depend") == 0
7347 2 : || strcmp (directive[1], "doacross") == 0))
7348 : kind = C_OMP_DIR_STANDALONE;
7349 6 : else if (first + 2 < last
7350 4 : && first[1].type == CPP_COMMA
7351 4 : && first[2].type == CPP_NAME
7352 10 : && (strcmp (IDENTIFIER_POINTER (first[2].value),
7353 : "depend") == 0
7354 2 : || strcmp (IDENTIFIER_POINTER (first[2].value),
7355 : "doacross") == 0))
7356 : kind = C_OMP_DIR_STANDALONE;
7357 : }
7358 740 : else if (dir->id == PRAGMA_OMP_ERROR)
7359 : {
7360 : /* error with at(execution) clause is C_OMP_DIR_STANDALONE. */
7361 : int paren_depth = 0;
7362 99 : for (int i = 1; first + i < last; i++)
7363 84 : if (first[i].type == CPP_OPEN_PAREN)
7364 18 : paren_depth++;
7365 66 : else if (first[i].type == CPP_CLOSE_PAREN)
7366 18 : paren_depth--;
7367 48 : else if (paren_depth == 0
7368 30 : && first + i + 2 < last
7369 30 : && first[i].type == CPP_NAME
7370 21 : && first[i + 1].type == CPP_OPEN_PAREN
7371 21 : && first[i + 2].type == CPP_NAME
7372 15 : && !strcmp (IDENTIFIER_POINTER (first[i].value),
7373 : "at")
7374 57 : && !strcmp (IDENTIFIER_POINTER (first[i
7375 : + 2].value),
7376 : "execution"))
7377 : {
7378 : kind = C_OMP_DIR_STANDALONE;
7379 : break;
7380 : }
7381 : }
7382 748 : c_omp_attribute_data v = { toks, dir, kind };
7383 748 : vd.safe_push (v);
7384 748 : if (flag_openmp || dir->simd)
7385 748 : tokens += (last - first) + 1;
7386 : }
7387 609 : c_omp_attribute_data v = {};
7388 609 : vd.safe_push (v);
7389 609 : *pa = TREE_CHAIN (*pa);
7390 : }
7391 : else
7392 1 : pa = &TREE_CHAIN (*pa);
7393 :
7394 610 : if (bad)
7395 : {
7396 17 : fail:
7397 29 : if (have_std_attrs && attrs == NULL)
7398 26 : *have_std_attrs = false;
7399 : return false;
7400 : }
7401 :
7402 : unsigned int i;
7403 : c_omp_attribute_data *v;
7404 : c_omp_attribute_data *construct_seen = nullptr;
7405 : c_omp_attribute_data *standalone_seen = nullptr;
7406 : c_omp_attribute_data *prev_standalone_seen = nullptr;
7407 1915 : FOR_EACH_VEC_ELT (vd, i, v)
7408 1322 : if (v->tokens)
7409 : {
7410 730 : if (v->kind == C_OMP_DIR_CONSTRUCT && !construct_seen)
7411 : construct_seen = v;
7412 359 : else if (v->kind == C_OMP_DIR_STANDALONE && !standalone_seen)
7413 71 : standalone_seen = v;
7414 : }
7415 : else
7416 : {
7417 592 : if (standalone_seen && !prev_standalone_seen)
7418 : {
7419 1322 : prev_standalone_seen = standalone_seen;
7420 1322 : standalone_seen = nullptr;
7421 : }
7422 : }
7423 :
7424 593 : if (cnt > 1 && construct_seen)
7425 : {
7426 4 : error_at ((*construct_seen->tokens)[0].location,
7427 : "OpenMP construct among %<omp::directive%> attributes"
7428 : " requires all %<omp::directive%> attributes on the"
7429 : " same statement to be in the same %<omp::sequence%>");
7430 4 : goto fail;
7431 : }
7432 589 : if (cnt > 1 && standalone_seen && prev_standalone_seen)
7433 : {
7434 2 : error_at ((*standalone_seen->tokens)[0].location,
7435 : "multiple OpenMP standalone directives among"
7436 : " %<omp::directive%> attributes must be all within the"
7437 : " same %<omp::sequence%>");
7438 2 : goto fail;
7439 : }
7440 :
7441 587 : if (prev_standalone_seen)
7442 : standalone_seen = prev_standalone_seen;
7443 520 : if (standalone_seen
7444 587 : && !c_parser_next_token_is (parser, CPP_SEMICOLON))
7445 : {
7446 2 : error_at (standalone_seen->tokens->address ()->location,
7447 : "standalone OpenMP directives in %<omp::directive%> attribute"
7448 : " can only appear on an empty statement");
7449 2 : goto fail;
7450 : }
7451 1162 : if (cnt && c_parser_next_token_is (parser, CPP_PRAGMA))
7452 : {
7453 4 : c_token *token = c_parser_peek_token (parser);
7454 4 : enum pragma_kind kind = token->pragma_kind;
7455 4 : if (kind >= PRAGMA_OMP__START_ && kind <= PRAGMA_OMP__LAST_)
7456 : {
7457 4 : error_at (token->location,
7458 : "mixing OpenMP directives with attribute and pragma "
7459 : "syntax on the same statement");
7460 4 : goto fail;
7461 : }
7462 : }
7463 :
7464 581 : if (!tokens)
7465 : return false;
7466 :
7467 565 : unsigned int tokens_avail = parser->tokens_avail;
7468 :
7469 565 : tokens++;
7470 565 : vec<c_token, va_gc> *toks = NULL;
7471 565 : vec_safe_reserve (toks, tokens, true);
7472 2408 : FOR_EACH_VEC_ELT (vd, i, v)
7473 : {
7474 1278 : if (!v->tokens)
7475 566 : continue;
7476 712 : if (!flag_openmp && !v->dir->simd)
7477 0 : continue;
7478 712 : c_token *first = v->tokens->address ();
7479 712 : c_token *last = first + v->tokens->length ();
7480 712 : c_token tok = {};
7481 712 : tok.type = CPP_PRAGMA;
7482 712 : tok.keyword = RID_MAX;
7483 712 : tok.pragma_kind = pragma_kind (v->dir->id);
7484 712 : tok.location = first->location;
7485 712 : toks->quick_push (tok);
7486 17475 : while (++first < last)
7487 16051 : toks->quick_push (*first);
7488 712 : tok = {};
7489 712 : tok.type = CPP_PRAGMA_EOL;
7490 712 : tok.keyword = RID_MAX;
7491 712 : tok.location = last[-1].location;
7492 712 : toks->quick_push (tok);
7493 : }
7494 :
7495 565 : c_token tok = {};
7496 565 : tok.type = CPP_EOF;
7497 565 : tok.keyword = RID_MAX;
7498 565 : tok.location = toks->last ().location;
7499 565 : toks->quick_push (tok);
7500 :
7501 565 : gcc_assert (!parser->in_omp_attribute_pragma);
7502 565 : parser->in_omp_attribute_pragma = ggc_alloc<omp_attribute_pragma_state> ();
7503 565 : parser->in_omp_attribute_pragma->token_vec = toks;
7504 565 : parser->in_omp_attribute_pragma->save_tokens = parser->tokens;
7505 565 : parser->in_omp_attribute_pragma->save_tokens_avail = tokens_avail;
7506 565 : parser->tokens = toks->address ();
7507 565 : parser->tokens_avail = tokens;
7508 565 : return true;
7509 610 : }
7510 :
7511 : /* Handle omp::directive and omp::sequence attributes in ATTRS
7512 : (if any) at the start or after declaration-id of a declaration. */
7513 :
7514 : static void
7515 66503574 : c_parser_handle_directive_omp_attributes (tree &attrs,
7516 : vec<c_token> *&pragma_clauses,
7517 : vec<c_token> *attr_clauses)
7518 : {
7519 66503574 : if (!flag_openmp && !flag_openmp_simd)
7520 : return;
7521 :
7522 1732792 : for (tree *pa = &attrs; *pa; )
7523 683909 : if (is_attribute_namespace_p ("omp", *pa)
7524 683909 : && is_attribute_p ("directive", get_attribute_name (*pa)))
7525 : {
7526 141 : int cnt = 0;
7527 281 : for (tree *pa2 = &TREE_VALUE (*pa); *pa2; )
7528 : {
7529 142 : tree a = *pa2;
7530 142 : tree d = TREE_VALUE (a);
7531 142 : gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
7532 142 : vec<c_token, va_gc> *toks = C_TOKEN_VEC_TOKENS (d);
7533 142 : c_token *first = toks->address ();
7534 142 : c_token *last = first + toks->length ();
7535 142 : const char *directive[3] = {};
7536 424 : for (int i = 0; i < 3; i++)
7537 : {
7538 390 : tree id = NULL_TREE;
7539 390 : if (first + i == last)
7540 : break;
7541 335 : if (first[i].type == CPP_NAME)
7542 282 : id = first[i].value;
7543 53 : else if (first[i].type == CPP_KEYWORD)
7544 0 : id = ridpointers[(int) first[i].keyword];
7545 : else
7546 : break;
7547 282 : directive[i] = IDENTIFIER_POINTER (id);
7548 : }
7549 142 : const c_omp_directive *dir = NULL;
7550 142 : if (directive[0])
7551 142 : dir = c_omp_categorize_directive (directive[0], directive[1],
7552 : directive[2]);
7553 142 : if (dir == NULL)
7554 : {
7555 9 : error_at (first->location,
7556 : "unknown OpenMP directive name in "
7557 : "%qs attribute argument",
7558 9 : TREE_PUBLIC (d) ? "omp::decl" : "omp::directive");
7559 9 : *pa2 = TREE_CHAIN (a);
7560 : }
7561 133 : else if (dir->id == PRAGMA_OMP_DECLARE
7562 105 : && (strcmp (directive[1], "simd") == 0
7563 22 : || strcmp (directive[1], "variant") == 0))
7564 : {
7565 92 : if (pragma_clauses)
7566 : {
7567 2 : error_at (first->location,
7568 : "mixing OpenMP directives with attribute and "
7569 : "pragma syntax on the same declaration");
7570 6 : for (pa = &attrs; *pa; )
7571 2 : if (is_attribute_namespace_p ("omp", *pa)
7572 4 : && is_attribute_p ("directive",
7573 2 : get_attribute_name (*pa)))
7574 2 : *pa = TREE_CHAIN (*pa);
7575 : else
7576 0 : pa = &TREE_CHAIN (*pa);
7577 2 : return;
7578 : }
7579 90 : ++cnt;
7580 110 : attr_clauses->reserve (attr_clauses->length ()
7581 90 : + toks->length () + 2);
7582 834 : for (++first; first < last; ++first)
7583 744 : attr_clauses->quick_push (*first);
7584 90 : c_token tok = {};
7585 90 : tok.type = CPP_PRAGMA_EOL;
7586 90 : tok.keyword = RID_MAX;
7587 90 : tok.location = last[-1].location;
7588 90 : attr_clauses->quick_push (tok);
7589 90 : *pa2 = TREE_CHAIN (a);
7590 90 : }
7591 : else
7592 41 : pa2 = &TREE_CHAIN (a);
7593 : }
7594 139 : if (cnt && TREE_VALUE (*pa) == NULL_TREE)
7595 86 : *pa = TREE_CHAIN (*pa);
7596 : else
7597 53 : pa = &TREE_CHAIN (*pa);
7598 : }
7599 : else
7600 683768 : pa = &TREE_CHAIN (*pa);
7601 1048883 : if (attr_clauses->length ())
7602 : {
7603 70 : c_token tok = {};
7604 70 : tok.type = CPP_EOF;
7605 70 : tok.keyword = RID_MAX;
7606 70 : tok.location = attr_clauses->last ().location;
7607 70 : attr_clauses->quick_push (tok);
7608 70 : attr_clauses->quick_push (tok);
7609 70 : pragma_clauses = attr_clauses;
7610 : }
7611 : }
7612 :
7613 : /* Check if STD_ATTR contains a musttail attribute and remove if it
7614 : precedes a return. PARSER is the parser and ATTR is the output
7615 : attr_state. */
7616 :
7617 : static tree
7618 975 : c_parser_handle_musttail (c_parser *parser, tree std_attrs, attr_state &attr)
7619 : {
7620 975 : if (c_parser_next_token_is_keyword (parser, RID_RETURN))
7621 : {
7622 226 : if (tree a = lookup_attribute ("gnu", "musttail", std_attrs))
7623 : {
7624 420 : for (; a; a = lookup_attribute ("gnu", "musttail", TREE_CHAIN (a)))
7625 211 : if (TREE_VALUE (a))
7626 2 : error ("%qs attribute does not take any arguments",
7627 : "musttail");
7628 209 : std_attrs = remove_attribute ("gnu", "musttail", std_attrs);
7629 209 : attr.musttail_p = true;
7630 : }
7631 226 : if (lookup_attribute ("clang", "musttail", std_attrs))
7632 : {
7633 10 : std_attrs = remove_attribute ("clang", "musttail", std_attrs);
7634 10 : attr.musttail_p = true;
7635 : }
7636 : }
7637 975 : return std_attrs;
7638 : }
7639 :
7640 : /* Return a statement before optional series of LABEL_EXPR/CASE_LABEL_EXPRs.
7641 : Instead of collecting vectors of labels before each stmt just in case
7642 : the statement would be iteration or switch statement for named loops,
7643 : we just remember last emitted statement and let the iteration/switch
7644 : statement search backwards in cur_stmt_list until that stmt for loop
7645 : names if any. */
7646 :
7647 : static tree
7648 91822274 : get_before_labels ()
7649 : {
7650 91822274 : if (!building_stmt_list_p ())
7651 : return NULL_TREE;
7652 91822274 : tree_stmt_iterator tsi = tsi_last (cur_stmt_list);
7653 91822274 : if (tsi_end_p (tsi))
7654 : return NULL_TREE;
7655 50762703 : return tsi_stmt (tsi);
7656 : }
7657 :
7658 : /* Parse a compound statement except for the opening brace. This is
7659 : used for parsing both compound statements and statement expressions
7660 : (which follow different paths to handling the opening). */
7661 :
7662 : static location_t
7663 38626459 : c_parser_compound_statement_nostart (c_parser *parser)
7664 : {
7665 38626459 : bool last_stmt = false;
7666 38626459 : bool last_label = false;
7667 38626459 : bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
7668 38626459 : location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
7669 38626459 : struct omp_for_parse_data *omp_for_parse_state
7670 : = parser->omp_for_parse_state;
7671 77252918 : bool in_omp_loop_block
7672 38626459 : = omp_for_parse_state ? omp_for_parse_state->want_nested_loop : false;
7673 38626459 : tree sl = NULL_TREE;
7674 38626459 : attr_state astate = {};
7675 :
7676 38626459 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7677 : {
7678 24104 : location_t endloc = c_parser_peek_token (parser)->location;
7679 24104 : add_debug_begin_stmt (endloc);
7680 24104 : c_parser_consume_token (parser);
7681 24104 : return endloc;
7682 : }
7683 :
7684 : /* If we're parsing a {} sequence in an OMP_FOR body, start a
7685 : statement list for intervening code. */
7686 38602355 : if (in_omp_loop_block)
7687 178 : sl = push_stmt_list ();
7688 :
7689 38602355 : mark_valid_location_for_stdc_pragma (true);
7690 38602355 : if (c_parser_next_token_is_keyword (parser, RID_LABEL))
7691 : {
7692 : /* Read zero or more forward-declarations for labels that nested
7693 : functions can jump to. */
7694 753 : mark_valid_location_for_stdc_pragma (false);
7695 753 : if (in_omp_loop_block)
7696 5 : check_omp_intervening_code (parser);
7697 1628 : while (c_parser_next_token_is_keyword (parser, RID_LABEL))
7698 : {
7699 875 : label_loc = c_parser_peek_token (parser)->location;
7700 875 : c_parser_consume_token (parser);
7701 : /* Any identifiers, including those declared as type names,
7702 : are OK here. */
7703 1587 : while (true)
7704 : {
7705 1231 : tree label;
7706 1231 : if (c_parser_next_token_is_not (parser, CPP_NAME))
7707 : {
7708 0 : c_parser_error (parser, "expected identifier");
7709 0 : break;
7710 : }
7711 1231 : label
7712 1231 : = declare_label (c_parser_peek_token (parser)->value);
7713 1231 : C_DECLARED_LABEL_FLAG (label) = 1;
7714 1231 : add_stmt (build_stmt (label_loc, DECL_EXPR, label));
7715 1231 : c_parser_consume_token (parser);
7716 1231 : if (c_parser_next_token_is (parser, CPP_COMMA))
7717 356 : c_parser_consume_token (parser);
7718 : else
7719 : break;
7720 356 : }
7721 875 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7722 : }
7723 753 : pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
7724 : }
7725 : /* We must now have at least one statement, label or declaration. */
7726 38602355 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7727 : {
7728 0 : mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
7729 0 : c_parser_error (parser, "expected declaration or statement");
7730 0 : location_t endloc = c_parser_peek_token (parser)->location;
7731 0 : c_parser_consume_token (parser);
7732 0 : return endloc;
7733 : }
7734 38602355 : tree before_labels = get_before_labels ();
7735 129387297 : while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
7736 : {
7737 52182646 : location_t loc = c_parser_peek_token (parser)->location;
7738 52182646 : loc = expansion_point_location_if_in_system_header (loc);
7739 :
7740 104365292 : bool want_nested_loop = (omp_for_parse_state
7741 52182646 : ? omp_for_parse_state->want_nested_loop
7742 : : false);
7743 :
7744 : /* First take care of special cases for OpenMP "canonical loop
7745 : nest form", that do not allow standard attributes, labels, or
7746 : __extension__ before the nested statement. */
7747 52182646 : if (in_omp_loop_block && !last_label)
7748 : {
7749 397 : tree_code code = omp_for_parse_state->code;
7750 513 : if (want_nested_loop
7751 397 : && c_parser_omp_next_tokens_can_be_canon_loop (parser, code,
7752 : false))
7753 : {
7754 : /* Found the next nested loop. If there were intervening
7755 : code statements collected before now, wrap them in an
7756 : OMP_STRUCTURED_BLOCK node, and start a new structured
7757 : block to hold statements that may come after the FOR. */
7758 116 : gcc_assert (sl);
7759 116 : add_structured_block_stmt (pop_stmt_list (sl));
7760 116 : omp_for_parse_state->depth++;
7761 116 : add_stmt (c_parser_omp_loop_nest (parser, NULL));
7762 116 : omp_for_parse_state->depth--;
7763 116 : sl = push_stmt_list ();
7764 116 : parser->error = false;
7765 116 : before_labels = get_before_labels ();
7766 116 : astate.reset ();
7767 167 : continue;
7768 : }
7769 281 : else if (want_nested_loop
7770 468 : && c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7771 : {
7772 : /* If this nested compound statement contains the nested loop,
7773 : we need to separate the other statements in the current
7774 : statement into separate blocks of intervening code. If
7775 : there's no nested loop, it's all part of the same
7776 : chunk of intervening code. */
7777 44 : tree pre_sl = pop_stmt_list (sl);
7778 44 : tree nested_sl = push_stmt_list ();
7779 44 : mark_valid_location_for_stdc_pragma (false);
7780 44 : c_parser_statement_after_labels (parser, NULL, NULL_TREE);
7781 44 : nested_sl = pop_stmt_list (nested_sl);
7782 44 : if (omp_for_parse_state->want_nested_loop)
7783 : {
7784 : /* This block didn't contain a loop-nest, so it's
7785 : all part of the same chunk of intervening code. */
7786 13 : check_omp_intervening_code (parser);
7787 13 : sl = push_stmt_list ();
7788 13 : add_stmt (pre_sl);
7789 13 : add_stmt (nested_sl);
7790 : }
7791 : else
7792 : {
7793 : /* It contains the nested loop. */
7794 31 : add_structured_block_stmt (pre_sl);
7795 31 : add_stmt (nested_sl);
7796 31 : sl = push_stmt_list ();
7797 : }
7798 44 : parser->error = false;
7799 44 : before_labels = get_before_labels ();
7800 44 : astate.reset ();
7801 44 : continue;
7802 44 : }
7803 237 : else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7804 : {
7805 : /* Prior to implementing the OpenMP 5.1 syntax for canonical
7806 : loop form, GCC used to accept an empty statements that
7807 : would now be flagged as intervening code. Continue to
7808 : do that, as an extension. */
7809 : /* FIXME: Maybe issue a warning or something here? */
7810 4 : c_parser_consume_token (parser);
7811 4 : before_labels = get_before_labels ();
7812 4 : astate.reset ();
7813 4 : continue;
7814 : }
7815 : }
7816 :
7817 : /* Standard attributes may start a label, statement or declaration. */
7818 52182482 : bool have_std_attrs
7819 52182482 : = c_parser_nth_token_starts_std_attributes (parser, 1);
7820 52182482 : tree std_attrs = NULL_TREE;
7821 52182482 : if (have_std_attrs)
7822 : {
7823 839 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
7824 839 : std_attrs = c_parser_handle_musttail (parser, std_attrs, astate);
7825 : }
7826 52182482 : if (c_parser_next_token_is_keyword (parser, RID_CASE)
7827 51178539 : || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
7828 103326223 : || (c_parser_next_token_is (parser, CPP_NAME)
7829 10359333 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
7830 : {
7831 1062941 : if (c_parser_next_token_is_keyword (parser, RID_CASE))
7832 1003943 : label_loc = c_parser_peek_2nd_token (parser)->location;
7833 : else
7834 58998 : label_loc = c_parser_peek_token (parser)->location;
7835 1062941 : last_label = true;
7836 1062941 : last_stmt = false;
7837 1062941 : mark_valid_location_for_stdc_pragma (false);
7838 1062941 : if (in_omp_loop_block)
7839 26 : check_omp_intervening_code (parser);
7840 1062941 : c_parser_label (parser, std_attrs);
7841 : }
7842 51119541 : else if (c_parser_next_tokens_start_declaration (parser)
7843 51119541 : || (have_std_attrs
7844 702 : && !c_parser_handle_statement_omp_attributes
7845 702 : (parser, std_attrs, &have_std_attrs)
7846 268 : && c_parser_next_token_is (parser, CPP_SEMICOLON)
7847 77 : && (have_std_attrs = true)))
7848 : {
7849 7710993 : if (last_label)
7850 97 : pedwarn_c11 (c_parser_peek_token (parser)->location, OPT_Wfree_labels,
7851 : "a label can only be part of a statement and "
7852 : "a declaration is not a statement");
7853 : /* It's unlikely we'll see a nested loop in a declaration in
7854 : intervening code in an OMP loop, but disallow it anyway. */
7855 7710993 : if (in_omp_loop_block)
7856 : {
7857 19 : check_omp_intervening_code (parser);
7858 19 : omp_for_parse_state->want_nested_loop = false;
7859 : }
7860 7710993 : mark_valid_location_for_stdc_pragma (false);
7861 7710993 : bool fallthru_attr_p = false;
7862 7710993 : c_parser_declaration_or_fndef (parser, true, !have_std_attrs,
7863 : true, true, true, false, NULL,
7864 : NULL, have_std_attrs, std_attrs,
7865 : NULL, &fallthru_attr_p);
7866 :
7867 7710993 : if (in_omp_loop_block)
7868 19 : omp_for_parse_state->want_nested_loop = want_nested_loop;
7869 7710993 : if (last_stmt && !fallthru_attr_p)
7870 313797 : pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
7871 : "ISO C90 forbids mixed declarations and code");
7872 7710993 : last_stmt = fallthru_attr_p;
7873 7710993 : last_label = false;
7874 7710993 : before_labels = get_before_labels ();
7875 : }
7876 43408548 : else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
7877 : {
7878 : /* __extension__ can start a declaration, but is also an
7879 : unary operator that can start an expression. Consume all
7880 : but the last of a possible series of __extension__ to
7881 : determine which. If standard attributes have already
7882 : been seen, it must start a statement, not a declaration,
7883 : but standard attributes starting a declaration may appear
7884 : after __extension__. */
7885 1568 : while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
7886 784 : && (c_parser_peek_2nd_token (parser)->keyword
7887 : == RID_EXTENSION))
7888 0 : c_parser_consume_token (parser);
7889 784 : if (!have_std_attrs
7890 784 : && (c_parser_next_tokens_start_declaration (parser, 2)
7891 713 : || c_parser_nth_token_starts_std_attributes (parser, 2)))
7892 : {
7893 74 : int ext;
7894 74 : ext = disable_extension_diagnostics ();
7895 74 : c_parser_consume_token (parser);
7896 74 : last_label = false;
7897 : /* It's unlikely we'll see a nested loop in a declaration in
7898 : intervening code in an OMP loop, but disallow it anyway. */
7899 74 : if (in_omp_loop_block)
7900 : {
7901 0 : check_omp_intervening_code (parser);
7902 0 : omp_for_parse_state->want_nested_loop = false;
7903 : }
7904 74 : mark_valid_location_for_stdc_pragma (false);
7905 74 : c_parser_declaration_or_fndef (parser, true, true, true, true,
7906 : true, false);
7907 74 : if (in_omp_loop_block)
7908 0 : omp_for_parse_state->want_nested_loop = want_nested_loop;
7909 : /* Following the old parser, __extension__ does not
7910 : disable this diagnostic. */
7911 74 : restore_extension_diagnostics (ext);
7912 74 : if (last_stmt)
7913 7 : pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
7914 : "ISO C90 forbids mixed declarations and code");
7915 74 : last_stmt = false;
7916 74 : before_labels = get_before_labels ();
7917 : }
7918 : else
7919 710 : goto statement;
7920 : }
7921 43407764 : else if (c_parser_next_token_is (parser, CPP_PRAGMA))
7922 : {
7923 339973 : if (have_std_attrs && !parser->in_omp_attribute_pragma)
7924 0 : c_parser_error (parser, "expected declaration or statement");
7925 339973 : else if (std_attrs)
7926 0 : c_warn_unused_attributes (std_attrs);
7927 : /* External pragmas, and some omp pragmas, are not associated
7928 : with regular c code, and so are not to be considered statements
7929 : syntactically. This ensures that the user doesn't put them
7930 : places that would turn into syntax errors if the directive
7931 : were ignored. */
7932 339973 : if (omp_for_parse_state)
7933 13 : omp_for_parse_state->want_nested_loop = false;
7934 679863 : if (c_parser_pragma (parser,
7935 : last_label ? pragma_stmt : pragma_compound,
7936 : NULL, before_labels))
7937 : {
7938 23627 : last_label = false;
7939 23627 : last_stmt = true;
7940 23627 : if (omp_for_parse_state)
7941 5 : check_omp_intervening_code (parser);
7942 : }
7943 316351 : if (omp_for_parse_state)
7944 13 : omp_for_parse_state->want_nested_loop = want_nested_loop;
7945 339973 : before_labels = get_before_labels ();
7946 : }
7947 43067791 : else if (c_parser_next_token_is (parser, CPP_EOF))
7948 : {
7949 56 : mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
7950 56 : c_parser_error (parser, "expected declaration or statement");
7951 58 : return c_parser_peek_token (parser)->location;
7952 : }
7953 43067735 : else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
7954 : {
7955 5 : if (parser->in_if_block)
7956 : {
7957 2 : mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
7958 2 : error_at (loc, "expected %<}%> before %<else%>");
7959 2 : return c_parser_peek_token (parser)->location;
7960 : }
7961 : else
7962 : {
7963 3 : error_at (loc, "%<else%> without a previous %<if%>");
7964 3 : c_parser_consume_token (parser);
7965 3 : before_labels = get_before_labels ();
7966 3 : astate.reset ();
7967 3 : continue;
7968 : }
7969 : }
7970 : else
7971 : {
7972 43067730 : statement:
7973 43068440 : c_warn_unused_attributes (std_attrs);
7974 43068440 : last_label = false;
7975 43068440 : last_stmt = true;
7976 43068440 : mark_valid_location_for_stdc_pragma (false);
7977 43068440 : if (!omp_for_parse_state)
7978 43068209 : c_parser_statement_after_labels (parser, NULL, before_labels,
7979 : NULL, astate);
7980 : else
7981 : {
7982 : /* In canonical loop nest form, nested loops can only appear
7983 : directly, or in a directly nested compound statement. We
7984 : already took care of those cases above, so now we have
7985 : something else. This statement and everything inside
7986 : it must be intervening code. */
7987 231 : omp_for_parse_state->want_nested_loop = false;
7988 231 : check_omp_intervening_code (parser);
7989 231 : c_parser_statement_after_labels (parser, NULL, before_labels);
7990 231 : omp_for_parse_state->want_nested_loop = want_nested_loop;
7991 : }
7992 43068439 : before_labels = get_before_labels ();
7993 : }
7994 :
7995 52182420 : parser->error = false;
7996 52182420 : astate.reset ();
7997 : }
7998 38602296 : if (last_label)
7999 51 : pedwarn_c11 (label_loc, OPT_Wfree_labels,
8000 : "label at end of compound statement");
8001 38602296 : location_t endloc = c_parser_peek_token (parser)->location;
8002 38602296 : c_parser_consume_token (parser);
8003 :
8004 : /* Restore the value we started with. */
8005 38602296 : mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
8006 :
8007 : /* Package leftover intervening code, or the whole contents of the
8008 : compound statement if we were looking for a nested loop in an OMP_FOR
8009 : construct and didn't find one. */
8010 38602296 : if (sl)
8011 : {
8012 178 : sl = pop_stmt_list (sl);
8013 178 : if (omp_for_parse_state->want_nested_loop)
8014 31 : add_stmt (sl);
8015 : else
8016 147 : add_structured_block_stmt (sl);
8017 : }
8018 : return endloc;
8019 : }
8020 :
8021 : /* Parse all consecutive labels, possibly preceded by standard
8022 : attributes. In this context, a statement is required, not a
8023 : declaration, so attributes must be followed by a statement that is
8024 : not just a semicolon. Returns an attr_state. */
8025 :
8026 : static attr_state
8027 2100273 : c_parser_all_labels (c_parser *parser)
8028 : {
8029 2100273 : attr_state attr = {};
8030 2100273 : bool have_std_attrs;
8031 2100273 : tree std_attrs = NULL;
8032 2100273 : if ((have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1)))
8033 : {
8034 110 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
8035 110 : std_attrs = c_parser_handle_musttail (parser, std_attrs, attr);
8036 : }
8037 :
8038 2101348 : while (c_parser_next_token_is_keyword (parser, RID_CASE)
8039 2100774 : || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
8040 4202111 : || (c_parser_next_token_is (parser, CPP_NAME)
8041 519149 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
8042 : {
8043 1075 : c_parser_label (parser, std_attrs);
8044 1075 : std_attrs = NULL;
8045 1075 : if ((have_std_attrs = c_parser_nth_token_starts_std_attributes (parser,
8046 : 1)))
8047 : {
8048 3 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
8049 3 : std_attrs = c_parser_handle_musttail (parser, std_attrs, attr);
8050 : }
8051 : }
8052 2100273 : if (std_attrs
8053 2100273 : && (!c_parser_handle_statement_omp_attributes (parser, std_attrs, &have_std_attrs)
8054 11 : || std_attrs))
8055 : {
8056 22 : if (have_std_attrs && c_parser_next_token_is (parser, CPP_SEMICOLON))
8057 0 : c_parser_error (parser, "expected statement");
8058 18 : c_warn_unused_attributes (std_attrs);
8059 : }
8060 2100348 : else if (have_std_attrs && c_parser_next_token_is (parser, CPP_SEMICOLON))
8061 1 : c_parser_error (parser, "expected statement");
8062 2100273 : return attr;
8063 : }
8064 :
8065 :
8066 : /* Information used while parsing an OpenMP metadirective. */
8067 : struct omp_metadirective_parse_data {
8068 : /* These fields are used to unique-ify labels when reparsing the
8069 : code in a metadirective alternative. */
8070 : vec<tree> * GTY((skip)) body_labels;
8071 : unsigned int region_num;
8072 : };
8073 :
8074 : /* Helper function for c_parser_label: mangle a metadirective region
8075 : label NAME. */
8076 : static tree
8077 0 : mangle_metadirective_region_label (c_parser *parser, tree name)
8078 : {
8079 0 : if (parser->omp_metadirective_state->body_labels->contains (name))
8080 : {
8081 0 : const char *old_name = IDENTIFIER_POINTER (name);
8082 0 : char *new_name = (char *) XALLOCAVEC (char, strlen (old_name) + 32);
8083 0 : sprintf (new_name, "%s_MDR%u", old_name,
8084 : parser->omp_metadirective_state->region_num);
8085 0 : return get_identifier (new_name);
8086 : }
8087 0 : return name;
8088 : }
8089 :
8090 : /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
8091 :
8092 : label:
8093 : identifier : gnu-attributes[opt]
8094 : case constant-expression :
8095 : default :
8096 :
8097 : GNU extensions:
8098 :
8099 : label:
8100 : case constant-expression ... constant-expression :
8101 :
8102 : The use of gnu-attributes on labels is a GNU extension. The syntax in
8103 : GNU C accepts any expressions without commas, non-constant
8104 : expressions being rejected later. Any standard
8105 : attribute-specifier-sequence before the first label has been parsed
8106 : in the caller, to distinguish statements from declarations. Any
8107 : attribute-specifier-sequence after the label is parsed in this
8108 : function. */
8109 : static void
8110 1064016 : c_parser_label (c_parser *parser, tree std_attrs)
8111 : {
8112 1064016 : location_t loc1 = c_parser_peek_token (parser)->location;
8113 1064016 : tree label = NULL_TREE;
8114 :
8115 : /* Remember whether this case or a user-defined label is allowed to fall
8116 : through to. */
8117 1064016 : bool fallthrough_p = c_parser_peek_token (parser)->flags & PREV_FALLTHROUGH;
8118 :
8119 1064016 : if (c_parser_next_token_is_keyword (parser, RID_CASE))
8120 : {
8121 1004517 : tree exp1, exp2;
8122 1004517 : c_parser_consume_token (parser);
8123 1004517 : exp1 = convert_lvalue_to_rvalue (loc1,
8124 : c_parser_expr_no_commas (parser, NULL),
8125 : true, true).value;
8126 1004517 : if (c_parser_next_token_is (parser, CPP_COLON))
8127 : {
8128 1004194 : c_parser_consume_token (parser);
8129 1004194 : label = do_case (loc1, exp1, NULL_TREE, std_attrs);
8130 : }
8131 323 : else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8132 : {
8133 315 : c_parser_consume_token (parser);
8134 315 : exp2 = convert_lvalue_to_rvalue (loc1,
8135 : c_parser_expr_no_commas (parser,
8136 : NULL),
8137 : true, true).value;
8138 315 : if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8139 315 : label = do_case (loc1, exp1, exp2, std_attrs);
8140 : }
8141 : else
8142 8 : c_parser_error (parser, "expected %<:%> or %<...%>");
8143 : }
8144 59499 : else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8145 : {
8146 34809 : c_parser_consume_token (parser);
8147 34809 : if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8148 34809 : label = do_case (loc1, NULL_TREE, NULL_TREE, std_attrs);
8149 : }
8150 : else
8151 : {
8152 24690 : tree name = c_parser_peek_token (parser)->value;
8153 24690 : tree tlab;
8154 24690 : tree attrs;
8155 24690 : location_t loc2 = c_parser_peek_token (parser)->location;
8156 24690 : gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
8157 24690 : c_parser_consume_token (parser);
8158 24690 : gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
8159 24690 : c_parser_consume_token (parser);
8160 24690 : attrs = c_parser_gnu_attributes (parser);
8161 24690 : if (parser->omp_metadirective_state)
8162 0 : name = mangle_metadirective_region_label (parser, name);
8163 24690 : tlab = define_label (loc2, name);
8164 24690 : if (tlab)
8165 : {
8166 24662 : decl_attributes (&tlab, attrs, 0);
8167 24662 : decl_attributes (&tlab, std_attrs, 0);
8168 24662 : label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
8169 : }
8170 24690 : if (attrs
8171 24690 : && c_parser_next_tokens_start_declaration (parser))
8172 1 : warning_at (loc2, OPT_Wattributes, "GNU-style attribute between"
8173 : " label and declaration appertains to the label");
8174 : }
8175 1064016 : if (label)
8176 : {
8177 1063836 : if (TREE_CODE (label) == LABEL_EXPR)
8178 24662 : FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label)) = fallthrough_p;
8179 : else
8180 1039174 : FALLTHROUGH_LABEL_P (CASE_LABEL (label)) = fallthrough_p;
8181 : }
8182 1064016 : }
8183 :
8184 : /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
8185 :
8186 : statement:
8187 : labeled-statement
8188 : attribute-specifier-sequence[opt] compound-statement
8189 : expression-statement
8190 : attribute-specifier-sequence[opt] selection-statement
8191 : attribute-specifier-sequence[opt] iteration-statement
8192 : attribute-specifier-sequence[opt] jump-statement
8193 :
8194 : labeled-statement:
8195 : attribute-specifier-sequence[opt] label statement
8196 :
8197 : expression-statement:
8198 : expression[opt] ;
8199 : attribute-specifier-sequence expression ;
8200 :
8201 : selection-statement:
8202 : if-statement
8203 : switch-statement
8204 :
8205 : iteration-statement:
8206 : while-statement
8207 : do-statement
8208 : for-statement
8209 :
8210 : jump-statement:
8211 : goto identifier ;
8212 : continue ;
8213 : break ;
8214 : return expression[opt] ;
8215 :
8216 : GNU extensions:
8217 :
8218 : statement:
8219 : attribute-specifier-sequence[opt] asm-statement
8220 :
8221 : jump-statement:
8222 : goto * expression ;
8223 :
8224 : expression-statement:
8225 : gnu-attributes ;
8226 :
8227 : Objective-C:
8228 :
8229 : statement:
8230 : attribute-specifier-sequence[opt] objc-throw-statement
8231 : attribute-specifier-sequence[opt] objc-try-catch-statement
8232 : attribute-specifier-sequence[opt] objc-synchronized-statement
8233 :
8234 : objc-throw-statement:
8235 : @throw expression ;
8236 : @throw ;
8237 :
8238 : OpenACC:
8239 :
8240 : statement:
8241 : attribute-specifier-sequence[opt] openacc-construct
8242 :
8243 : openacc-construct:
8244 : parallel-construct
8245 : kernels-construct
8246 : data-construct
8247 : loop-construct
8248 :
8249 : parallel-construct:
8250 : parallel-directive structured-block
8251 :
8252 : kernels-construct:
8253 : kernels-directive structured-block
8254 :
8255 : data-construct:
8256 : data-directive structured-block
8257 :
8258 : loop-construct:
8259 : loop-directive structured-block
8260 :
8261 : OpenMP:
8262 :
8263 : statement:
8264 : attribute-specifier-sequence[opt] openmp-construct
8265 :
8266 : openmp-construct:
8267 : parallel-construct
8268 : for-construct
8269 : simd-construct
8270 : for-simd-construct
8271 : sections-construct
8272 : single-construct
8273 : parallel-for-construct
8274 : parallel-for-simd-construct
8275 : parallel-sections-construct
8276 : master-construct
8277 : critical-construct
8278 : atomic-construct
8279 : ordered-construct
8280 :
8281 : parallel-construct:
8282 : parallel-directive structured-block
8283 :
8284 : for-construct:
8285 : for-directive iteration-statement
8286 :
8287 : simd-construct:
8288 : simd-directive iteration-statements
8289 :
8290 : for-simd-construct:
8291 : for-simd-directive iteration-statements
8292 :
8293 : sections-construct:
8294 : sections-directive section-scope
8295 :
8296 : single-construct:
8297 : single-directive structured-block
8298 :
8299 : parallel-for-construct:
8300 : parallel-for-directive iteration-statement
8301 :
8302 : parallel-for-simd-construct:
8303 : parallel-for-simd-directive iteration-statement
8304 :
8305 : parallel-sections-construct:
8306 : parallel-sections-directive section-scope
8307 :
8308 : master-construct:
8309 : master-directive structured-block
8310 :
8311 : critical-construct:
8312 : critical-directive structured-block
8313 :
8314 : atomic-construct:
8315 : atomic-directive expression-statement
8316 :
8317 : ordered-construct:
8318 : ordered-directive structured-block
8319 :
8320 : Transactional Memory:
8321 :
8322 : statement:
8323 : attribute-specifier-sequence[opt] transaction-statement
8324 : attribute-specifier-sequence[opt] transaction-cancel-statement
8325 :
8326 : IF_P is used to track whether there's a (possibly labeled) if statement
8327 : which is not enclosed in braces and has an else clause. This is used to
8328 : implement -Wparentheses. */
8329 :
8330 : static void
8331 549799 : c_parser_statement (c_parser *parser, bool *if_p, location_t *loc_after_labels)
8332 : {
8333 549799 : tree before_labels = get_before_labels ();
8334 549799 : attr_state a = c_parser_all_labels (parser);
8335 549799 : if (loc_after_labels)
8336 379747 : *loc_after_labels = c_parser_peek_token (parser)->location;
8337 549799 : parser->omp_attrs_forbidden_p = false;
8338 549799 : c_parser_statement_after_labels (parser, if_p, before_labels, NULL, a);
8339 549799 : }
8340 :
8341 : /* Parse and handle optional identifier after break or continue keywords. */
8342 :
8343 : static tree
8344 191621 : c_parser_bc_name (c_parser *parser, bool is_break)
8345 : {
8346 191621 : if (!c_parser_next_token_is (parser, CPP_NAME))
8347 : return NULL_TREE;
8348 :
8349 316 : c_token *tok = c_parser_peek_token (parser);
8350 316 : tree label = c_finish_bc_name (tok->location, tok->value, is_break);
8351 316 : c_parser_consume_token (parser);
8352 316 : return label;
8353 : }
8354 :
8355 : /* Parse a statement, other than a labeled statement. CHAIN is a vector
8356 : of if-else-if conditions. All labels and standard attributes have
8357 : been parsed in the caller.
8358 :
8359 : IF_P is used to track whether there's a (possibly labeled) if statement
8360 : which is not enclosed in braces and has an else clause. This is used to
8361 : implement -Wparentheses. ASTATE is an earlier parsed attribute state.
8362 :
8363 : BEFORE_LABELS is last statement before possible labels, see
8364 : get_before_labels description for details. */
8365 :
8366 : static void
8367 44701544 : c_parser_statement_after_labels (c_parser *parser, bool *if_p,
8368 : tree before_labels,
8369 : vec<tree> *chain, attr_state astate)
8370 : {
8371 44701544 : location_t loc = c_parser_peek_token (parser)->location;
8372 44701544 : tree stmt = NULL_TREE;
8373 44701544 : bool in_if_block = parser->in_if_block;
8374 44701544 : parser->in_if_block = false;
8375 44701544 : if (if_p != NULL)
8376 827058 : *if_p = false;
8377 :
8378 44701544 : if (c_parser_peek_token (parser)->type != CPP_OPEN_BRACE)
8379 44239342 : add_debug_begin_stmt (loc);
8380 :
8381 44701544 : restart:
8382 44701601 : switch (c_parser_peek_token (parser)->type)
8383 : {
8384 462210 : case CPP_OPEN_BRACE:
8385 462210 : add_stmt (c_parser_compound_statement (parser));
8386 462210 : break;
8387 38140439 : case CPP_KEYWORD:
8388 38140439 : switch (c_parser_peek_token (parser)->keyword)
8389 : {
8390 1291141 : case RID_IF:
8391 1291141 : c_parser_if_statement (parser, if_p, chain);
8392 1291141 : break;
8393 38806 : case RID_SWITCH:
8394 38806 : c_parser_switch_statement (parser, if_p, before_labels);
8395 38806 : break;
8396 45174 : case RID_WHILE:
8397 45174 : c_parser_while_statement (parser, false, 0, false, if_p, before_labels);
8398 45174 : break;
8399 149404 : case RID_DO:
8400 149404 : c_parser_do_statement (parser, false, 0, false, before_labels);
8401 149404 : break;
8402 292398 : case RID_FOR:
8403 292398 : c_parser_for_statement (parser, false, 0, false, if_p, before_labels);
8404 292398 : break;
8405 84709 : case RID_GOTO:
8406 84709 : c_parser_consume_token (parser);
8407 84709 : if (c_parser_next_token_is (parser, CPP_NAME))
8408 : {
8409 83636 : tree name = c_parser_peek_token (parser)->value;
8410 83636 : if (parser->omp_metadirective_state)
8411 0 : name = mangle_metadirective_region_label (parser, name);
8412 83636 : stmt = c_finish_goto_label (loc, name);
8413 83636 : c_parser_consume_token (parser);
8414 : }
8415 1073 : else if (c_parser_next_token_is (parser, CPP_MULT))
8416 : {
8417 1073 : struct c_expr val;
8418 :
8419 1073 : c_parser_consume_token (parser);
8420 1073 : val = c_parser_expression (parser);
8421 1073 : val = convert_lvalue_to_rvalue (loc, val, false, true);
8422 1073 : stmt = c_finish_goto_ptr (loc, val);
8423 : }
8424 : else
8425 0 : c_parser_error (parser, "expected identifier or %<*%>");
8426 84709 : goto expect_semicolon;
8427 13365 : case RID_CONTINUE:
8428 13365 : c_parser_consume_token (parser);
8429 13365 : stmt = c_finish_bc_stmt (loc, objc_foreach_continue_label, false,
8430 : c_parser_bc_name (parser, false));
8431 13365 : goto expect_semicolon;
8432 178256 : case RID_BREAK:
8433 178256 : c_parser_consume_token (parser);
8434 178256 : stmt = c_finish_bc_stmt (loc, objc_foreach_break_label, true,
8435 : c_parser_bc_name (parser, true));
8436 178256 : goto expect_semicolon;
8437 35832247 : case RID_RETURN:
8438 35832247 : c_parser_consume_token (parser);
8439 35832247 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8440 : {
8441 21650 : stmt = c_finish_return (loc, NULL_TREE, NULL_TREE,
8442 : astate.musttail_p);
8443 21650 : c_parser_consume_token (parser);
8444 : }
8445 : else
8446 : {
8447 35810597 : location_t xloc = c_parser_peek_token (parser)->location;
8448 35810597 : struct c_expr expr = c_parser_expression_conv (parser);
8449 35810597 : mark_exp_read (expr.value);
8450 35810597 : stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc),
8451 : expr.value, expr.original_type,
8452 : astate.musttail_p);
8453 35810597 : goto expect_semicolon;
8454 : }
8455 21650 : break;
8456 196191 : case RID_ASM:
8457 196191 : stmt = c_parser_asm_statement (parser);
8458 196191 : break;
8459 137 : case RID_TRANSACTION_ATOMIC:
8460 137 : case RID_TRANSACTION_RELAXED:
8461 274 : stmt = c_parser_transaction (parser,
8462 137 : c_parser_peek_token (parser)->keyword);
8463 137 : break;
8464 28 : case RID_TRANSACTION_CANCEL:
8465 28 : stmt = c_parser_transaction_cancel (parser);
8466 28 : goto expect_semicolon;
8467 0 : case RID_AT_THROW:
8468 0 : gcc_assert (c_dialect_objc ());
8469 0 : c_parser_consume_token (parser);
8470 0 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8471 : {
8472 0 : stmt = objc_build_throw_stmt (loc, NULL_TREE);
8473 0 : c_parser_consume_token (parser);
8474 : }
8475 : else
8476 : {
8477 0 : struct c_expr expr = c_parser_expression (parser);
8478 0 : expr = convert_lvalue_to_rvalue (loc, expr, false, false);
8479 0 : expr.value = c_fully_fold (expr.value, false, NULL);
8480 0 : stmt = objc_build_throw_stmt (loc, expr.value);
8481 0 : goto expect_semicolon;
8482 : }
8483 0 : break;
8484 0 : case RID_AT_TRY:
8485 0 : gcc_assert (c_dialect_objc ());
8486 0 : c_parser_objc_try_catch_finally_statement (parser);
8487 0 : break;
8488 0 : case RID_AT_SYNCHRONIZED:
8489 0 : gcc_assert (c_dialect_objc ());
8490 0 : c_parser_objc_synchronized_statement (parser);
8491 0 : break;
8492 9 : case RID_ATTRIBUTE:
8493 9 : {
8494 : /* Allow '__attribute__((fallthrough));' or
8495 : '__attribute__((assume(cond)));' or
8496 : '__attribute__((musttail))) return'. */
8497 9 : tree attrs = c_parser_gnu_attributes (parser);
8498 9 : bool has_assume = lookup_attribute ("assume", attrs);
8499 9 : if (has_assume)
8500 : {
8501 0 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8502 0 : attrs = handle_assume_attribute (loc, attrs, true);
8503 : else
8504 : {
8505 0 : auto_urlify_attributes sentinel;
8506 0 : warning_at (loc, OPT_Wattributes,
8507 : "%<assume%> attribute not followed by %<;%>");
8508 0 : has_assume = false;
8509 0 : }
8510 : }
8511 9 : gcc_assert (!astate.musttail_p);
8512 9 : attrs = c_parser_handle_musttail (parser, attrs, astate);
8513 9 : if (astate.musttail_p)
8514 : {
8515 4 : if (attrs)
8516 : {
8517 1 : auto_urlify_attributes sentinel;
8518 1 : warning_at (c_parser_peek_token (parser)->location,
8519 1 : OPT_Wattributes,
8520 : "attribute %<musttail%> mixed with other "
8521 : "attributes on %<return%> statement");
8522 1 : }
8523 4 : goto restart;
8524 : }
8525 5 : if (attribute_fallthrough_p (attrs))
8526 : {
8527 5 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8528 : {
8529 5 : tree fn = build_call_expr_internal_loc (loc,
8530 : IFN_FALLTHROUGH,
8531 : void_type_node, 0);
8532 5 : add_stmt (fn);
8533 : /* Eat the ';'. */
8534 5 : c_parser_consume_token (parser);
8535 : }
8536 : else
8537 : {
8538 0 : auto_urlify_attributes sentinel;
8539 0 : warning_at (loc, OPT_Wattributes,
8540 : "%<fallthrough%> attribute not followed "
8541 : "by %<;%>");
8542 0 : }
8543 : }
8544 0 : else if (has_assume)
8545 : /* Eat the ';'. */
8546 0 : c_parser_consume_token (parser);
8547 0 : else if (attrs != NULL_TREE)
8548 : {
8549 0 : auto_urlify_attributes sentinel;
8550 0 : warning_at (loc, OPT_Wattributes,
8551 : "only attribute %<fallthrough%> or %<assume%> can "
8552 : "be applied to a null statement");
8553 0 : }
8554 : break;
8555 : }
8556 18574 : default:
8557 18574 : goto expr_stmt;
8558 : }
8559 : break;
8560 208470 : case CPP_SEMICOLON:
8561 208470 : c_parser_consume_token (parser);
8562 208470 : break;
8563 5 : case CPP_CLOSE_PAREN:
8564 5 : case CPP_CLOSE_SQUARE:
8565 : /* Avoid infinite loop in error recovery:
8566 : c_parser_skip_until_found stops at a closing nesting
8567 : delimiter without consuming it, but here we need to consume
8568 : it to proceed further. */
8569 5 : c_parser_error (parser, "expected statement");
8570 5 : c_parser_consume_token (parser);
8571 5 : break;
8572 2749 : case CPP_PRAGMA:
8573 2749 : if (!c_parser_pragma (parser, pragma_stmt, if_p, before_labels))
8574 53 : goto restart;
8575 : break;
8576 5906302 : default:
8577 5906302 : expr_stmt:
8578 5906302 : stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
8579 41993256 : expect_semicolon:
8580 41993256 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8581 41993256 : break;
8582 : }
8583 : /* Two cases cannot and do not have line numbers associated: If stmt
8584 : is degenerate, such as "2;", then stmt is an INTEGER_CST, which
8585 : cannot hold line numbers. But that's OK because the statement
8586 : will either be changed to a MODIFY_EXPR during gimplification of
8587 : the statement expr, or discarded. If stmt was compound, but
8588 : without new variables, we will have skipped the creation of a
8589 : BIND and will have a bare STATEMENT_LIST. But that's OK because
8590 : (recursively) all of the component statements should already have
8591 : line numbers assigned. ??? Can we discard no-op statements
8592 : earlier? */
8593 44701543 : if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
8594 2493806 : protected_set_expr_location (stmt, loc);
8595 :
8596 44701543 : parser->in_if_block = in_if_block;
8597 44701543 : }
8598 :
8599 : /* Parse the condition from an if, do, while or for statements. */
8600 :
8601 : static tree
8602 487020 : c_parser_condition (c_parser *parser)
8603 : {
8604 487020 : location_t loc = c_parser_peek_token (parser)->location;
8605 487020 : tree cond;
8606 487020 : cond = c_parser_expression_conv (parser).value;
8607 487020 : cond = c_objc_common_truthvalue_conversion (loc, cond);
8608 487020 : cond = c_fully_fold (cond, false, NULL);
8609 487020 : if (warn_sequence_point)
8610 85780 : verify_sequence_points (cond);
8611 487020 : return cond;
8612 : }
8613 :
8614 : /* Parse a parenthesized condition from a do or while statement.
8615 :
8616 : condition:
8617 : ( expression )
8618 : */
8619 :
8620 : static tree
8621 194652 : c_parser_paren_condition (c_parser *parser)
8622 : {
8623 194652 : tree cond;
8624 194652 : matching_parens parens;
8625 194652 : if (!parens.require_open (parser))
8626 0 : return error_mark_node;
8627 194652 : cond = c_parser_condition (parser);
8628 194652 : parens.skip_until_found_close (parser);
8629 194652 : return cond;
8630 : }
8631 :
8632 : /* Parse a selection-header:
8633 :
8634 : selection-header:
8635 : expression
8636 : declaration expression
8637 : simple-declaration
8638 :
8639 : simple-declaration:
8640 : attribute-specifier-sequence[opt] declaration-specifiers declarator
8641 : = initializer
8642 :
8643 : SWITCH_P is true if we are called from c_parser_switch_statement; in
8644 : that case, don't perform the truthvalue conversion. */
8645 :
8646 : static c_expr
8647 1329939 : c_parser_selection_header (c_parser *parser, bool switch_p)
8648 : {
8649 1329939 : location_t loc = c_parser_peek_token (parser)->location;
8650 1329939 : c_expr expr;
8651 1329939 : bool parse_expr = true;
8652 1329939 : tree std_attrs;
8653 1329939 : bool have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1);
8654 1329939 : if (have_std_attrs)
8655 20 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
8656 : else
8657 : std_attrs = NULL_TREE;
8658 1329939 : if (c_parser_next_tokens_start_declaration (parser))
8659 : {
8660 239 : pedwarn_c23 (loc, OPT_Wpedantic,
8661 : "ISO C does not support if declarations before C2Y");
8662 239 : expr.value
8663 239 : = c_parser_declaration_or_fndef (parser,
8664 : /*fndef_ok=*/false,
8665 : /*static_assert_ok=*/false,
8666 : /*empty_ok=*/false,
8667 : /*nested=*/true,
8668 : /*start_attr_ok=*/true,
8669 : /*simple_ok=*/true,
8670 : /*objc_foreach_object_decl=*/nullptr,
8671 : /*omp_declare_simd_clauses=*/nullptr,
8672 : have_std_attrs,
8673 : std_attrs);
8674 239 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8675 99 : c_parser_consume_token (parser);
8676 : else
8677 : {
8678 : /* A simple-declaration is a declaration that can appear in
8679 : place of the controlling expression of a selection statement.
8680 : In that case, there shall be an initializer. */
8681 140 : if (!expr.value)
8682 : {
8683 48 : error_at (loc, "declaration in the controlling expression must "
8684 : "have an initializer");
8685 48 : expr.original_type = error_mark_node;
8686 48 : expr.set_error ();
8687 48 : return expr;
8688 : }
8689 : parse_expr = false;
8690 : }
8691 191 : if (expr.value)
8692 : {
8693 175 : expr.original_type = TREE_TYPE (expr.value);
8694 175 : expr = convert_lvalue_to_rvalue (loc, expr, /*convert_p=*/true,
8695 : /*read_p=*/true);
8696 : }
8697 : }
8698 1329700 : else if (have_std_attrs)
8699 : {
8700 8 : c_parser_error (parser, "expected declaration");
8701 8 : expr.original_type = error_mark_node;
8702 8 : expr.set_error ();
8703 8 : return expr;
8704 : }
8705 :
8706 191 : if (parse_expr)
8707 1329791 : expr = c_parser_expression_conv (parser);
8708 1329883 : if (!switch_p)
8709 : {
8710 1291112 : expr.value = c_objc_common_truthvalue_conversion (loc, expr.value);
8711 1291112 : expr.value = c_fully_fold (expr.value, false, NULL);
8712 1291112 : if (warn_sequence_point)
8713 251641 : verify_sequence_points (expr.value);
8714 : }
8715 : return expr;
8716 : }
8717 :
8718 : /* Parse a selection-header enclosed in parentheses:
8719 :
8720 : ( selection-header )
8721 : */
8722 :
8723 : static tree
8724 1291141 : c_parser_paren_selection_header (c_parser *parser)
8725 : {
8726 1291141 : matching_parens parens;
8727 1291141 : if (!parens.require_open (parser))
8728 1 : return error_mark_node;
8729 1291140 : tree cond = c_parser_selection_header (parser, /*switch_p=*/false).value;
8730 1291140 : parens.skip_until_found_close (parser);
8731 1291140 : return cond;
8732 : }
8733 :
8734 : /* Parse a statement which is a block in C99.
8735 :
8736 : IF_P is used to track whether there's a (possibly labeled) if statement
8737 : which is not enclosed in braces and has an else clause. This is used to
8738 : implement -Wparentheses. */
8739 :
8740 : static tree
8741 539952 : c_parser_c99_block_statement (c_parser *parser, bool *if_p,
8742 : location_t *loc_after_labels)
8743 : {
8744 539952 : tree block = c_begin_compound_stmt (flag_isoc99);
8745 539952 : location_t loc = c_parser_peek_token (parser)->location;
8746 539952 : c_parser_statement (parser, if_p, loc_after_labels);
8747 539952 : return c_end_compound_stmt (loc, block, flag_isoc99);
8748 : }
8749 :
8750 : /* Parse the body of an if statement. This is just parsing a
8751 : statement but (a) it is a block in C99, (b) we track whether the
8752 : body is an if statement for the sake of -Wparentheses warnings, (c)
8753 : we handle an empty body specially for the sake of -Wempty-body
8754 : warnings, and (d) we call parser_compound_statement directly
8755 : because c_parser_statement_after_labels resets
8756 : parser->in_if_block.
8757 :
8758 : IF_P is used to track whether there's a (possibly labeled) if statement
8759 : which is not enclosed in braces and has an else clause. This is used to
8760 : implement -Wparentheses. */
8761 :
8762 : static tree
8763 1291141 : c_parser_if_body (c_parser *parser, bool *if_p,
8764 : const token_indent_info &if_tinfo)
8765 : {
8766 1291141 : tree block = c_begin_compound_stmt (flag_isoc99);
8767 1291141 : location_t body_loc = c_parser_peek_token (parser)->location;
8768 1291141 : location_t body_loc_after_labels = UNKNOWN_LOCATION;
8769 1291141 : token_indent_info body_tinfo
8770 1291141 : = get_token_indent_info (c_parser_peek_token (parser));
8771 1291141 : tree before_labels = get_before_labels ();
8772 1291141 : attr_state a = c_parser_all_labels (parser);
8773 :
8774 1291141 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8775 : {
8776 6813 : location_t loc = c_parser_peek_token (parser)->location;
8777 6813 : add_stmt (build_empty_stmt (loc));
8778 6813 : c_parser_consume_token (parser);
8779 6813 : if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
8780 466 : warning_at (loc, OPT_Wempty_body,
8781 : "suggest braces around empty body in an %<if%> statement");
8782 : }
8783 1284328 : else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8784 460385 : add_stmt (c_parser_compound_statement (parser));
8785 : else
8786 : {
8787 823943 : body_loc_after_labels = c_parser_peek_token (parser)->location;
8788 823943 : c_parser_statement_after_labels (parser, if_p, before_labels, NULL, a);
8789 : }
8790 :
8791 1291141 : token_indent_info next_tinfo
8792 1291141 : = get_token_indent_info (c_parser_peek_token (parser));
8793 1291141 : warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo);
8794 1291141 : if (body_loc_after_labels != UNKNOWN_LOCATION
8795 823943 : && next_tinfo.type != CPP_SEMICOLON)
8796 819139 : warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location,
8797 819139 : if_tinfo.location, RID_IF);
8798 :
8799 1291141 : return c_end_compound_stmt (body_loc, block, flag_isoc99);
8800 : }
8801 :
8802 : /* Parse the else body of an if statement. This is just parsing a
8803 : statement but (a) it is a block in C99, (b) we handle an empty body
8804 : specially for the sake of -Wempty-body warnings. CHAIN is a vector
8805 : of if-else-if conditions. */
8806 :
8807 : static tree
8808 259333 : c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
8809 : vec<tree> *chain)
8810 : {
8811 259333 : location_t body_loc = c_parser_peek_token (parser)->location;
8812 259333 : tree block = c_begin_compound_stmt (flag_isoc99);
8813 259333 : token_indent_info body_tinfo
8814 259333 : = get_token_indent_info (c_parser_peek_token (parser));
8815 259333 : location_t body_loc_after_labels = UNKNOWN_LOCATION;
8816 259333 : tree before_labels = get_before_labels ();
8817 259333 : attr_state a = c_parser_all_labels (parser);
8818 :
8819 259333 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8820 : {
8821 29 : location_t loc = c_parser_peek_token (parser)->location;
8822 29 : warning_at (loc,
8823 29 : OPT_Wempty_body,
8824 : "suggest braces around empty body in an %<else%> statement");
8825 29 : add_stmt (build_empty_stmt (loc));
8826 29 : c_parser_consume_token (parser);
8827 : }
8828 : else
8829 : {
8830 259304 : if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8831 222015 : body_loc_after_labels = c_parser_peek_token (parser)->location;
8832 259304 : c_parser_statement_after_labels (parser, NULL, before_labels, chain, a);
8833 : }
8834 :
8835 259333 : token_indent_info next_tinfo
8836 259333 : = get_token_indent_info (c_parser_peek_token (parser));
8837 259333 : warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo);
8838 259333 : if (body_loc_after_labels != UNKNOWN_LOCATION
8839 222015 : && next_tinfo.type != CPP_SEMICOLON)
8840 222001 : warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location,
8841 222001 : else_tinfo.location, RID_ELSE);
8842 :
8843 259333 : return c_end_compound_stmt (body_loc, block, flag_isoc99);
8844 : }
8845 :
8846 : /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
8847 :
8848 : if-statement:
8849 : if ( selection-header ) statement
8850 : if ( selection-header ) statement else statement
8851 :
8852 : CHAIN is a vector of if-else-if conditions.
8853 : IF_P is used to track whether there's a (possibly labeled) if statement
8854 : which is not enclosed in braces and has an else clause. This is used to
8855 : implement -Wparentheses. */
8856 :
8857 : static void
8858 1291141 : c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
8859 : {
8860 1291141 : tree block;
8861 1291141 : location_t loc;
8862 1291141 : tree cond;
8863 1291141 : bool nested_if = false;
8864 1291141 : tree first_body, second_body;
8865 1291141 : bool in_if_block;
8866 :
8867 1291141 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
8868 1291141 : token_indent_info if_tinfo
8869 1291141 : = get_token_indent_info (c_parser_peek_token (parser));
8870 1291141 : c_parser_consume_token (parser);
8871 1291141 : block = c_begin_compound_stmt (flag_isoc99);
8872 1291141 : loc = c_parser_peek_token (parser)->location;
8873 1291141 : cond = c_parser_paren_selection_header (parser);
8874 1291141 : in_if_block = parser->in_if_block;
8875 1291141 : parser->in_if_block = true;
8876 1291141 : first_body = c_parser_if_body (parser, &nested_if, if_tinfo);
8877 1291141 : parser->in_if_block = in_if_block;
8878 :
8879 1291141 : if (warn_duplicated_cond)
8880 62 : warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain);
8881 :
8882 1291141 : if (c_parser_next_token_is_keyword (parser, RID_ELSE))
8883 : {
8884 259333 : token_indent_info else_tinfo
8885 259333 : = get_token_indent_info (c_parser_peek_token (parser));
8886 259333 : c_parser_consume_token (parser);
8887 259333 : if (warn_duplicated_cond)
8888 : {
8889 43 : if (c_parser_next_token_is_keyword (parser, RID_IF)
8890 43 : && chain == NULL)
8891 : {
8892 : /* We've got "if (COND) else if (COND2)". Start the
8893 : condition chain and add COND as the first element. */
8894 18 : chain = new vec<tree> ();
8895 18 : if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond))
8896 12 : chain->safe_push (cond);
8897 : }
8898 25 : else if (!c_parser_next_token_is_keyword (parser, RID_IF))
8899 : /* This is if-else without subsequent if. Zap the condition
8900 : chain; we would have already warned at this point. */
8901 4 : vec_free (chain);
8902 : }
8903 259333 : second_body = c_parser_else_body (parser, else_tinfo, chain);
8904 : /* Set IF_P to true to indicate that this if statement has an
8905 : else clause. This may trigger the Wparentheses warning
8906 : below when we get back up to the parent if statement. */
8907 259333 : if (if_p != NULL)
8908 276 : *if_p = true;
8909 : }
8910 : else
8911 : {
8912 1031808 : second_body = NULL_TREE;
8913 :
8914 : /* Diagnose an ambiguous else if if-then-else is nested inside
8915 : if-then. */
8916 1031808 : if (nested_if)
8917 201 : warning_at (loc, OPT_Wdangling_else,
8918 : "suggest explicit braces to avoid ambiguous %<else%>");
8919 :
8920 1031808 : if (warn_duplicated_cond)
8921 : /* This if statement does not have an else clause. We don't
8922 : need the condition chain anymore. */
8923 19 : vec_free (chain);
8924 : }
8925 1291141 : c_finish_if_stmt (loc, cond, first_body, second_body);
8926 1291141 : add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
8927 :
8928 1291141 : c_parser_maybe_reclassify_token (parser);
8929 1291141 : }
8930 :
8931 : /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
8932 :
8933 : switch-statement:
8934 : switch (expression) statement
8935 :
8936 : BEFORE_LABELS is last statement before possible labels, see
8937 : get_before_labels description for details. */
8938 :
8939 : static void
8940 38806 : c_parser_switch_statement (c_parser *parser, bool *if_p, tree before_labels)
8941 : {
8942 38806 : struct c_expr ce;
8943 38806 : tree block, expr, body;
8944 38806 : unsigned char save_in_statement;
8945 38806 : location_t switch_loc = c_parser_peek_token (parser)->location;
8946 38806 : location_t switch_cond_loc;
8947 38806 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
8948 38806 : c_parser_consume_token (parser);
8949 38806 : tree switch_name;
8950 38806 : int num_names = c_get_loop_names (before_labels, true, &switch_name);
8951 38806 : block = c_begin_compound_stmt (flag_isoc99);
8952 38806 : bool explicit_cast_p = false;
8953 38806 : matching_parens parens;
8954 38806 : if (parens.require_open (parser))
8955 : {
8956 38799 : switch_cond_loc = c_parser_peek_token (parser)->location;
8957 38799 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
8958 38799 : && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
8959 : explicit_cast_p = true;
8960 38799 : ce = c_parser_selection_header (parser, /*switch_p=*/true);
8961 : /* The call above already performed convert_lvalue_to_rvalue, but
8962 : if it parsed an expression, read_p was false. Make sure we mark
8963 : the expression as read. */
8964 38799 : ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, true);
8965 38799 : expr = ce.value;
8966 : /* ??? expr has no valid location? */
8967 38799 : parens.skip_until_found_close (parser);
8968 : }
8969 : else
8970 : {
8971 7 : switch_cond_loc = UNKNOWN_LOCATION;
8972 7 : expr = error_mark_node;
8973 7 : ce.original_type = error_mark_node;
8974 : }
8975 38806 : tree stmt
8976 38806 : = c_start_switch (switch_loc, switch_cond_loc, expr, explicit_cast_p,
8977 : switch_name);
8978 38806 : save_in_statement = in_statement;
8979 38806 : in_statement |= IN_SWITCH_STMT;
8980 38806 : if (switch_name)
8981 : {
8982 160 : C_DECL_LOOP_SWITCH_NAME_VALID (switch_name) = 1;
8983 160 : in_statement |= IN_NAMED_STMT;
8984 : }
8985 : else
8986 38646 : in_statement &= ~IN_NAMED_STMT;
8987 38806 : location_t loc_after_labels;
8988 38806 : bool open_brace_p = c_parser_peek_token (parser)->type == CPP_OPEN_BRACE;
8989 38806 : body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
8990 38806 : location_t next_loc = c_parser_peek_token (parser)->location;
8991 38806 : if (!open_brace_p && c_parser_peek_token (parser)->type != CPP_SEMICOLON)
8992 429 : warn_for_multistatement_macros (loc_after_labels, next_loc, switch_loc,
8993 : RID_SWITCH);
8994 38806 : c_finish_switch (body, ce.original_type);
8995 38806 : in_statement = save_in_statement;
8996 38806 : if (num_names)
8997 : {
8998 160 : if (!C_DECL_LOOP_SWITCH_NAME_USED (switch_name))
8999 148 : SWITCH_STMT_NAME (stmt) = NULL_TREE;
9000 : else
9001 12 : SWITCH_STMT_NO_BREAK_P (stmt) = 0;
9002 160 : c_release_loop_names (num_names);
9003 : }
9004 38806 : add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
9005 38806 : c_parser_maybe_reclassify_token (parser);
9006 38806 : }
9007 :
9008 : /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
9009 :
9010 : while-statement:
9011 : while (expression) statement
9012 :
9013 : IF_P is used to track whether there's a (possibly labeled) if statement
9014 : which is not enclosed in braces and has an else clause. This is used to
9015 : implement -Wparentheses.
9016 :
9017 : BEFORE_LABELS is last statement before possible labels, see
9018 : get_before_labels description for details. */
9019 :
9020 : static void
9021 45189 : c_parser_while_statement (c_parser *parser, bool ivdep, unsigned short unroll,
9022 : bool novector, bool *if_p, tree before_labels)
9023 : {
9024 45189 : tree block, cond, body;
9025 45189 : unsigned char save_in_statement;
9026 45189 : location_t loc;
9027 45189 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
9028 45189 : token_indent_info while_tinfo
9029 45189 : = get_token_indent_info (c_parser_peek_token (parser));
9030 45189 : tree loop_name;
9031 45189 : int num_names = c_get_loop_names (before_labels, false, &loop_name);
9032 :
9033 45189 : if (parser->omp_for_parse_state)
9034 : {
9035 1 : error_at (c_parser_peek_token (parser)->location,
9036 : "loop not permitted in intervening code in OpenMP loop body");
9037 1 : parser->omp_for_parse_state->fail = true;
9038 : }
9039 :
9040 45189 : c_parser_consume_token (parser);
9041 45189 : block = c_begin_compound_stmt (flag_isoc99);
9042 45189 : loc = c_parser_peek_token (parser)->location;
9043 45189 : cond = c_parser_paren_condition (parser);
9044 45189 : if (ivdep && cond != error_mark_node)
9045 3 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9046 : build_int_cst (integer_type_node,
9047 : annot_expr_ivdep_kind),
9048 : integer_zero_node);
9049 45189 : if (unroll && cond != error_mark_node)
9050 6 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9051 : build_int_cst (integer_type_node,
9052 : annot_expr_unroll_kind),
9053 6 : build_int_cst (integer_type_node, unroll));
9054 45189 : if (novector && cond != error_mark_node)
9055 6 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9056 : build_int_cst (integer_type_node,
9057 : annot_expr_no_vector_kind),
9058 : integer_zero_node);
9059 45189 : save_in_statement = in_statement;
9060 45189 : in_statement = IN_ITERATION_STMT;
9061 45189 : if (loop_name)
9062 : {
9063 135 : C_DECL_LOOP_SWITCH_NAME_VALID (loop_name) = 1;
9064 135 : in_statement |= IN_NAMED_STMT;
9065 : }
9066 :
9067 45189 : token_indent_info body_tinfo
9068 45189 : = get_token_indent_info (c_parser_peek_token (parser));
9069 :
9070 45189 : location_t loc_after_labels;
9071 45189 : bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE);
9072 45189 : body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
9073 45189 : if (loop_name && !C_DECL_LOOP_SWITCH_NAME_USED (loop_name))
9074 133 : loop_name = NULL_TREE;
9075 45189 : add_stmt (build_stmt (loc, WHILE_STMT, cond, body, loop_name, NULL_TREE,
9076 : NULL_TREE));
9077 45189 : add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
9078 45189 : c_parser_maybe_reclassify_token (parser);
9079 45189 : if (num_names)
9080 135 : c_release_loop_names (num_names);
9081 :
9082 45189 : token_indent_info next_tinfo
9083 45189 : = get_token_indent_info (c_parser_peek_token (parser));
9084 45189 : warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo);
9085 :
9086 45189 : if (next_tinfo.type != CPP_SEMICOLON && !open_brace)
9087 10806 : warn_for_multistatement_macros (loc_after_labels, next_tinfo.location,
9088 : while_tinfo.location, RID_WHILE);
9089 :
9090 45189 : in_statement = save_in_statement;
9091 45189 : }
9092 :
9093 : /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
9094 :
9095 : do-statement:
9096 : do statement while ( expression ) ;
9097 :
9098 : BEFORE_LABELS is last statement before possible labels, see
9099 : get_before_labels description for details. */
9100 :
9101 : static void
9102 149463 : c_parser_do_statement (c_parser *parser, bool ivdep, unsigned short unroll,
9103 : bool novector, tree before_labels)
9104 : {
9105 149463 : tree block, cond, body;
9106 149463 : unsigned char save_in_statement;
9107 149463 : location_t loc;
9108 149463 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
9109 149463 : tree loop_name;
9110 149463 : int num_names = c_get_loop_names (before_labels, false, &loop_name);
9111 :
9112 149463 : if (parser->omp_for_parse_state)
9113 : {
9114 1 : error_at (c_parser_peek_token (parser)->location,
9115 : "loop not permitted in intervening code in OpenMP loop body");
9116 1 : parser->omp_for_parse_state->fail = true;
9117 : }
9118 :
9119 149463 : c_parser_consume_token (parser);
9120 149463 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9121 50 : warning_at (c_parser_peek_token (parser)->location,
9122 50 : OPT_Wempty_body,
9123 : "suggest braces around empty body in %<do%> statement");
9124 149463 : block = c_begin_compound_stmt (flag_isoc99);
9125 149463 : loc = c_parser_peek_token (parser)->location;
9126 149463 : save_in_statement = in_statement;
9127 149463 : in_statement = IN_ITERATION_STMT;
9128 149463 : if (loop_name)
9129 : {
9130 181 : C_DECL_LOOP_SWITCH_NAME_VALID (loop_name) = 1;
9131 181 : in_statement |= IN_NAMED_STMT;
9132 : }
9133 149463 : body = c_parser_c99_block_statement (parser, NULL);
9134 149463 : c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
9135 149463 : in_statement = save_in_statement;
9136 149463 : if (num_names)
9137 : {
9138 181 : if (!C_DECL_LOOP_SWITCH_NAME_USED (loop_name))
9139 179 : loop_name = NULL_TREE;
9140 181 : c_release_loop_names (num_names);
9141 : }
9142 149463 : cond = c_parser_paren_condition (parser);
9143 149463 : if (ivdep && cond != error_mark_node)
9144 2 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9145 : build_int_cst (integer_type_node,
9146 : annot_expr_ivdep_kind),
9147 : integer_zero_node);
9148 149463 : if (unroll && cond != error_mark_node)
9149 3 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9150 : build_int_cst (integer_type_node,
9151 : annot_expr_unroll_kind),
9152 3 : build_int_cst (integer_type_node, unroll));
9153 149463 : if (novector && cond != error_mark_node)
9154 54 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9155 : build_int_cst (integer_type_node,
9156 : annot_expr_no_vector_kind),
9157 : integer_zero_node);
9158 149463 : if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
9159 0 : c_parser_skip_to_end_of_block_or_statement (parser);
9160 :
9161 149463 : add_stmt (build_stmt (loc, DO_STMT, cond, body, loop_name));
9162 149463 : add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
9163 149463 : }
9164 :
9165 : /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
9166 :
9167 : for-statement:
9168 : for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
9169 : for ( nested-declaration expression[opt] ; expression[opt] ) statement
9170 :
9171 : The form with a declaration is new in C99.
9172 :
9173 : ??? In accordance with the old parser, the declaration may be a
9174 : nested function, which is then rejected in check_for_loop_decls,
9175 : but does it make any sense for this to be included in the grammar?
9176 : Note in particular that the nested function does not include a
9177 : trailing ';', whereas the "declaration" production includes one.
9178 : Also, can we reject bad declarations earlier and cheaper than
9179 : check_for_loop_decls?
9180 :
9181 : In Objective-C, there are two additional variants:
9182 :
9183 : foreach-statement:
9184 : for ( expression in expression ) statement
9185 : for ( declaration in expression ) statement
9186 :
9187 : This is inconsistent with C, because the second variant is allowed
9188 : even if c99 is not enabled.
9189 :
9190 : The rest of the comment documents these Objective-C foreach-statement.
9191 :
9192 : Here is the canonical example of the first variant:
9193 : for (object in array) { do something with object }
9194 : we call the first expression ("object") the "object_expression" and
9195 : the second expression ("array") the "collection_expression".
9196 : object_expression must be an lvalue of type "id" (a generic Objective-C
9197 : object) because the loop works by assigning to object_expression the
9198 : various objects from the collection_expression. collection_expression
9199 : must evaluate to something of type "id" which responds to the method
9200 : countByEnumeratingWithState:objects:count:.
9201 :
9202 : The canonical example of the second variant is:
9203 : for (id object in array) { do something with object }
9204 : which is completely equivalent to
9205 : {
9206 : id object;
9207 : for (object in array) { do something with object }
9208 : }
9209 : Note that initizializing 'object' in some way (eg, "for ((object =
9210 : xxx) in array) { do something with object }") is possibly
9211 : technically valid, but completely pointless as 'object' will be
9212 : assigned to something else as soon as the loop starts. We should
9213 : most likely reject it (TODO).
9214 :
9215 : The beginning of the Objective-C foreach-statement looks exactly
9216 : like the beginning of the for-statement, and we can tell it is a
9217 : foreach-statement only because the initial declaration or
9218 : expression is terminated by 'in' instead of ';'.
9219 :
9220 : IF_P is used to track whether there's a (possibly labeled) if statement
9221 : which is not enclosed in braces and has an else clause. This is used to
9222 : implement -Wparentheses.
9223 :
9224 : BEFORE_LABELS is last statement before possible labels, see
9225 : get_before_labels description for details. */
9226 :
9227 : static void
9228 295752 : c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll,
9229 : bool novector, bool *if_p, tree before_labels)
9230 : {
9231 295752 : tree block, cond, incr, body;
9232 295752 : unsigned char save_in_statement;
9233 295752 : tree save_objc_foreach_break_label, save_objc_foreach_continue_label;
9234 : /* The following are only used when parsing an ObjC foreach statement. */
9235 295752 : tree object_expression;
9236 : /* Silence the bogus uninitialized warning. */
9237 295752 : tree collection_expression = NULL;
9238 295752 : location_t loc = c_parser_peek_token (parser)->location;
9239 295752 : location_t for_loc = loc;
9240 295752 : bool is_foreach_statement = false;
9241 295752 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
9242 295752 : token_indent_info for_tinfo
9243 295752 : = get_token_indent_info (c_parser_peek_token (parser));
9244 295752 : tree loop_name;
9245 295752 : int num_names = c_get_loop_names (before_labels, false, &loop_name);
9246 :
9247 295752 : if (parser->omp_for_parse_state)
9248 : {
9249 13 : error_at (for_loc,
9250 : "loop not permitted in intervening code in OpenMP loop body");
9251 13 : parser->omp_for_parse_state->fail = true;
9252 : }
9253 :
9254 295752 : c_parser_consume_token (parser);
9255 : /* Open a compound statement in Objective-C as well, just in case this is
9256 : as foreach expression. */
9257 590613 : block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
9258 295752 : cond = error_mark_node;
9259 295752 : incr = error_mark_node;
9260 295752 : matching_parens parens;
9261 295752 : if (parens.require_open (parser))
9262 : {
9263 : /* Parse the initialization declaration or expression. */
9264 295751 : object_expression = error_mark_node;
9265 295751 : parser->objc_could_be_foreach_context = c_dialect_objc ();
9266 295751 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9267 : {
9268 14417 : parser->objc_could_be_foreach_context = false;
9269 14417 : c_parser_consume_token (parser);
9270 14417 : c_finish_expr_stmt (loc, NULL_TREE);
9271 : }
9272 281334 : else if (c_parser_next_tokens_start_declaration (parser)
9273 281334 : || c_parser_nth_token_starts_std_attributes (parser, 1))
9274 : {
9275 24468 : c_parser_declaration_or_fndef (parser, true, true, true, true, true,
9276 : false, &object_expression);
9277 24468 : parser->objc_could_be_foreach_context = false;
9278 :
9279 24468 : if (c_parser_next_token_is_keyword (parser, RID_IN))
9280 : {
9281 0 : c_parser_consume_token (parser);
9282 0 : is_foreach_statement = true;
9283 0 : if (check_for_loop_decls (for_loc, true) == NULL_TREE)
9284 0 : c_parser_error (parser, "multiple iterating variables in "
9285 : "fast enumeration");
9286 : }
9287 : else
9288 24468 : check_for_loop_decls (for_loc, flag_isoc99);
9289 : }
9290 256866 : else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
9291 : {
9292 : /* __extension__ can start a declaration, but is also an
9293 : unary operator that can start an expression. Consume all
9294 : but the last of a possible series of __extension__ to
9295 : determine which. */
9296 0 : while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
9297 0 : && (c_parser_peek_2nd_token (parser)->keyword
9298 : == RID_EXTENSION))
9299 0 : c_parser_consume_token (parser);
9300 0 : if (c_parser_next_tokens_start_declaration (parser, 2)
9301 0 : || c_parser_nth_token_starts_std_attributes (parser, 2))
9302 : {
9303 0 : int ext;
9304 0 : ext = disable_extension_diagnostics ();
9305 0 : c_parser_consume_token (parser);
9306 0 : c_parser_declaration_or_fndef (parser, true, true, true, true,
9307 : true, false, &object_expression);
9308 0 : parser->objc_could_be_foreach_context = false;
9309 :
9310 0 : restore_extension_diagnostics (ext);
9311 0 : if (c_parser_next_token_is_keyword (parser, RID_IN))
9312 : {
9313 0 : c_parser_consume_token (parser);
9314 0 : is_foreach_statement = true;
9315 0 : if (check_for_loop_decls (for_loc, true) == NULL_TREE)
9316 0 : c_parser_error (parser, "multiple iterating variables in "
9317 : "fast enumeration");
9318 : }
9319 : else
9320 0 : check_for_loop_decls (for_loc, flag_isoc99);
9321 : }
9322 : else
9323 0 : goto init_expr;
9324 : }
9325 : else
9326 : {
9327 256866 : init_expr:
9328 256866 : {
9329 256866 : struct c_expr ce;
9330 256866 : tree init_expression;
9331 256866 : ce = c_parser_expression (parser);
9332 256866 : init_expression = ce.value;
9333 256866 : parser->objc_could_be_foreach_context = false;
9334 256866 : if (c_parser_next_token_is_keyword (parser, RID_IN))
9335 : {
9336 0 : c_parser_consume_token (parser);
9337 0 : is_foreach_statement = true;
9338 0 : if (! lvalue_p (init_expression))
9339 0 : c_parser_error (parser, "invalid iterating variable in "
9340 : "fast enumeration");
9341 0 : object_expression
9342 0 : = c_fully_fold (init_expression, false, NULL);
9343 : }
9344 : else
9345 : {
9346 256866 : ce = convert_lvalue_to_rvalue (loc, ce, true, false);
9347 256866 : init_expression = ce.value;
9348 256866 : c_finish_expr_stmt (loc, init_expression);
9349 256866 : c_parser_skip_until_found (parser, CPP_SEMICOLON,
9350 : "expected %<;%>");
9351 : }
9352 : }
9353 : }
9354 : /* Parse the loop condition. In the case of a foreach
9355 : statement, there is no loop condition. */
9356 295751 : gcc_assert (!parser->objc_could_be_foreach_context);
9357 295751 : if (!is_foreach_statement)
9358 : {
9359 295751 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9360 : {
9361 3383 : if (ivdep)
9362 : {
9363 1 : c_parser_error (parser, "missing loop condition in loop "
9364 : "with %<GCC ivdep%> pragma");
9365 1 : cond = error_mark_node;
9366 : }
9367 3382 : else if (unroll)
9368 : {
9369 0 : c_parser_error (parser, "missing loop condition in loop "
9370 : "with %<GCC unroll%> pragma");
9371 0 : cond = error_mark_node;
9372 : }
9373 : else
9374 : {
9375 3382 : c_parser_consume_token (parser);
9376 3382 : cond = NULL_TREE;
9377 : }
9378 : }
9379 : else
9380 : {
9381 292368 : cond = c_parser_condition (parser);
9382 292368 : c_parser_skip_until_found (parser, CPP_SEMICOLON,
9383 : "expected %<;%>");
9384 : }
9385 295751 : if (ivdep && cond != error_mark_node)
9386 122 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9387 : build_int_cst (integer_type_node,
9388 : annot_expr_ivdep_kind),
9389 : integer_zero_node);
9390 295751 : if (unroll && cond != error_mark_node)
9391 284 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9392 : build_int_cst (integer_type_node,
9393 : annot_expr_unroll_kind),
9394 284 : build_int_cst (integer_type_node, unroll));
9395 295751 : if (novector && cond && cond != error_mark_node)
9396 2959 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
9397 : build_int_cst (integer_type_node,
9398 : annot_expr_no_vector_kind),
9399 : integer_zero_node);
9400 : }
9401 : /* Parse the increment expression (the third expression in a
9402 : for-statement). In the case of a foreach-statement, this is
9403 : the expression that follows the 'in'. */
9404 295751 : loc = c_parser_peek_token (parser)->location;
9405 295751 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9406 : {
9407 4568 : if (is_foreach_statement)
9408 : {
9409 0 : c_parser_error (parser,
9410 : "missing collection in fast enumeration");
9411 0 : collection_expression = error_mark_node;
9412 : }
9413 : else
9414 4568 : incr = c_process_expr_stmt (loc, NULL_TREE);
9415 : }
9416 : else
9417 : {
9418 291183 : if (is_foreach_statement)
9419 0 : collection_expression
9420 0 : = c_fully_fold (c_parser_expression (parser).value, false, NULL);
9421 : else
9422 : {
9423 291183 : struct c_expr ce = c_parser_expression (parser);
9424 291183 : ce = convert_lvalue_to_rvalue (loc, ce, true, false);
9425 291183 : incr = c_process_expr_stmt (loc, ce.value);
9426 : }
9427 : }
9428 295751 : parens.skip_until_found_close (parser);
9429 : }
9430 295752 : save_in_statement = in_statement;
9431 295752 : if (is_foreach_statement)
9432 : {
9433 0 : in_statement = IN_OBJC_FOREACH;
9434 0 : save_objc_foreach_break_label = objc_foreach_break_label;
9435 0 : save_objc_foreach_continue_label = objc_foreach_continue_label;
9436 0 : objc_foreach_break_label = create_artificial_label (loc);
9437 0 : objc_foreach_continue_label = create_artificial_label (loc);
9438 0 : if (loop_name)
9439 : {
9440 0 : gcc_checking_assert (!DECL_CHAIN (loop_name)
9441 : && !DECL_CHAIN (objc_foreach_break_label));
9442 0 : C_DECL_SWITCH_NAME (loop_name) = 1;
9443 0 : DECL_CHAIN (loop_name) = objc_foreach_break_label;
9444 0 : DECL_CHAIN (objc_foreach_break_label) = objc_foreach_continue_label;
9445 : }
9446 : }
9447 : else
9448 295752 : in_statement = IN_ITERATION_STMT;
9449 295752 : if (loop_name)
9450 : {
9451 505 : C_DECL_LOOP_SWITCH_NAME_VALID (loop_name) = 1;
9452 505 : in_statement |= IN_NAMED_STMT;
9453 : }
9454 :
9455 295752 : token_indent_info body_tinfo
9456 295752 : = get_token_indent_info (c_parser_peek_token (parser));
9457 :
9458 295752 : location_t loc_after_labels;
9459 295752 : bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE);
9460 295752 : body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
9461 :
9462 295752 : if (loop_name && is_foreach_statement)
9463 : {
9464 0 : gcc_checking_assert (DECL_CHAIN (loop_name) == objc_foreach_break_label
9465 : && (DECL_CHAIN (objc_foreach_break_label)
9466 : == objc_foreach_continue_label));
9467 0 : C_DECL_SWITCH_NAME (loop_name) = 0;
9468 0 : DECL_CHAIN (loop_name) = NULL_TREE;
9469 0 : DECL_CHAIN (objc_foreach_break_label) = NULL_TREE;
9470 : }
9471 :
9472 295247 : if (is_foreach_statement)
9473 0 : objc_finish_foreach_loop (for_loc, object_expression,
9474 : collection_expression, body,
9475 : objc_foreach_break_label,
9476 : objc_foreach_continue_label);
9477 : else
9478 591504 : add_stmt (build_stmt (for_loc, FOR_STMT, NULL_TREE, cond, incr,
9479 : body, NULL_TREE,
9480 505 : loop_name && C_DECL_LOOP_SWITCH_NAME_USED (loop_name)
9481 : ? loop_name : NULL_TREE, NULL_TREE, NULL_TREE));
9482 295752 : add_stmt (c_end_compound_stmt (for_loc, block,
9483 295752 : flag_isoc99 || c_dialect_objc ()));
9484 295752 : c_parser_maybe_reclassify_token (parser);
9485 :
9486 295752 : token_indent_info next_tinfo
9487 295752 : = get_token_indent_info (c_parser_peek_token (parser));
9488 295752 : warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo);
9489 :
9490 295752 : if (next_tinfo.type != CPP_SEMICOLON && !open_brace)
9491 176492 : warn_for_multistatement_macros (loc_after_labels, next_tinfo.location,
9492 : for_tinfo.location, RID_FOR);
9493 :
9494 295752 : in_statement = save_in_statement;
9495 295752 : if (num_names)
9496 505 : c_release_loop_names (num_names);
9497 295752 : if (is_foreach_statement)
9498 : {
9499 0 : objc_foreach_break_label = save_objc_foreach_break_label;
9500 0 : objc_foreach_continue_label = save_objc_foreach_continue_label;
9501 : }
9502 295752 : }
9503 :
9504 : /* Parse an asm statement, a GNU extension. This is a full-blown asm
9505 : statement with inputs, outputs, clobbers, and volatile, inline, and goto
9506 : tags allowed.
9507 :
9508 : asm-qualifier:
9509 : volatile
9510 : inline
9511 : goto
9512 :
9513 : asm-qualifier-list:
9514 : asm-qualifier-list asm-qualifier
9515 : asm-qualifier
9516 :
9517 : asm-statement:
9518 : asm asm-qualifier-list[opt] ( asm-argument ) ;
9519 :
9520 : asm-argument:
9521 : asm-string-literal
9522 : asm-string-literal : asm-operands[opt]
9523 : asm-string-literal : asm-operands[opt] : asm-operands[opt]
9524 : asm-string-literal : asm-operands[opt] : asm-operands[opt] \
9525 : : asm-clobbers[opt]
9526 : asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
9527 : : asm-goto-operands
9528 :
9529 : The form with asm-goto-operands is valid if and only if the
9530 : asm-qualifier-list contains goto, and is the only allowed form in that case.
9531 : Duplicate asm-qualifiers are not allowed.
9532 :
9533 : The :: token is considered equivalent to two consecutive : tokens. */
9534 :
9535 : static tree
9536 196191 : c_parser_asm_statement (c_parser *parser)
9537 : {
9538 196191 : tree str, outputs, inputs, clobbers, labels, ret;
9539 196191 : bool simple;
9540 196191 : location_t asm_loc = c_parser_peek_token (parser)->location;
9541 196191 : int section, nsections;
9542 :
9543 196191 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
9544 196191 : c_parser_consume_token (parser);
9545 :
9546 : /* Handle the asm-qualifier-list. */
9547 196191 : location_t volatile_loc = UNKNOWN_LOCATION;
9548 196191 : location_t inline_loc = UNKNOWN_LOCATION;
9549 196191 : location_t goto_loc = UNKNOWN_LOCATION;
9550 353086 : for (;;)
9551 : {
9552 353086 : c_token *token = c_parser_peek_token (parser);
9553 353086 : location_t loc = token->location;
9554 353086 : switch (token->keyword)
9555 : {
9556 156296 : case RID_VOLATILE:
9557 156296 : if (volatile_loc)
9558 : {
9559 6 : error_at (loc, "duplicate %<asm%> qualifier %qE", token->value);
9560 6 : inform (volatile_loc, "first seen here");
9561 : }
9562 : else
9563 : volatile_loc = loc;
9564 156296 : c_parser_consume_token (parser);
9565 156296 : continue;
9566 :
9567 38 : case RID_INLINE:
9568 38 : if (inline_loc)
9569 : {
9570 6 : error_at (loc, "duplicate %<asm%> qualifier %qE", token->value);
9571 6 : inform (inline_loc, "first seen here");
9572 : }
9573 : else
9574 : inline_loc = loc;
9575 38 : c_parser_consume_token (parser);
9576 38 : continue;
9577 :
9578 559 : case RID_GOTO:
9579 559 : if (goto_loc)
9580 : {
9581 6 : error_at (loc, "duplicate %<asm%> qualifier %qE", token->value);
9582 6 : inform (goto_loc, "first seen here");
9583 : }
9584 : else
9585 : goto_loc = loc;
9586 559 : c_parser_consume_token (parser);
9587 559 : continue;
9588 :
9589 2 : case RID_CONST:
9590 2 : case RID_RESTRICT:
9591 2 : error_at (loc, "%qE is not a valid %<asm%> qualifier", token->value);
9592 2 : c_parser_consume_token (parser);
9593 2 : continue;
9594 :
9595 196191 : default:
9596 196191 : break;
9597 : }
9598 196191 : break;
9599 : }
9600 :
9601 196191 : bool is_volatile = (volatile_loc != UNKNOWN_LOCATION);
9602 196191 : bool is_inline = (inline_loc != UNKNOWN_LOCATION);
9603 196191 : bool is_goto = (goto_loc != UNKNOWN_LOCATION);
9604 :
9605 196191 : ret = NULL;
9606 :
9607 196191 : matching_parens parens;
9608 196191 : if (!parens.require_open (parser))
9609 0 : goto error;
9610 :
9611 196191 : str = c_parser_asm_string_literal (parser);
9612 196191 : if (str == NULL_TREE)
9613 12 : goto error_close_paren;
9614 :
9615 196179 : simple = true;
9616 196179 : outputs = NULL_TREE;
9617 196179 : inputs = NULL_TREE;
9618 196179 : clobbers = NULL_TREE;
9619 196179 : labels = NULL_TREE;
9620 :
9621 196179 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
9622 1884 : goto done_asm;
9623 :
9624 : /* Parse each colon-delimited section of operands. */
9625 194295 : nsections = 3 + is_goto;
9626 502143 : for (section = 0; section < nsections; ++section)
9627 : {
9628 501600 : if (c_parser_next_token_is (parser, CPP_SCOPE))
9629 : {
9630 25185 : ++section;
9631 25185 : if (section == nsections)
9632 : {
9633 5 : c_parser_error (parser, "expected %<)%>");
9634 5 : goto error_close_paren;
9635 : }
9636 25180 : c_parser_consume_token (parser);
9637 : }
9638 950958 : else if (!c_parser_require (parser, CPP_COLON,
9639 : is_goto
9640 : ? G_("expected %<:%>")
9641 : : G_("expected %<:%> or %<)%>"),
9642 : UNKNOWN_LOCATION, is_goto))
9643 7 : goto error_close_paren;
9644 :
9645 : /* Once past any colon, we're no longer a simple asm. */
9646 501588 : simple = false;
9647 :
9648 501588 : if ((!c_parser_next_token_is (parser, CPP_COLON)
9649 420236 : && !c_parser_next_token_is (parser, CPP_SCOPE)
9650 420158 : && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9651 511454 : || section == 3)
9652 410371 : switch (section)
9653 : {
9654 134063 : case 0:
9655 134063 : outputs = c_parser_asm_operands (parser);
9656 134063 : break;
9657 133446 : case 1:
9658 133446 : inputs = c_parser_asm_operands (parser);
9659 133446 : break;
9660 142319 : case 2:
9661 142319 : clobbers = c_parser_asm_clobbers (parser);
9662 142319 : break;
9663 543 : case 3:
9664 543 : labels = c_parser_asm_goto_operands (parser);
9665 543 : break;
9666 0 : default:
9667 0 : gcc_unreachable ();
9668 : }
9669 :
9670 501588 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
9671 193740 : goto done_asm;
9672 : }
9673 :
9674 543 : done_asm:
9675 196167 : if (!parens.require_close (parser))
9676 : {
9677 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
9678 0 : goto error;
9679 : }
9680 :
9681 196167 : if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
9682 0 : c_parser_skip_to_end_of_block_or_statement (parser);
9683 :
9684 196167 : ret = build_asm_stmt (is_volatile,
9685 : build_asm_expr (asm_loc, str, outputs, inputs,
9686 : clobbers, labels, simple, is_inline));
9687 :
9688 196191 : error:
9689 196191 : return ret;
9690 :
9691 24 : error_close_paren:
9692 24 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
9693 24 : goto error;
9694 : }
9695 :
9696 : /* Parse asm operands, a GNU extension.
9697 :
9698 : asm-operands:
9699 : asm-operand
9700 : asm-operands , asm-operand
9701 :
9702 : asm-operand:
9703 : asm-string-literal ( expression )
9704 : [ identifier ] asm-string-literal ( expression )
9705 : */
9706 :
9707 : static tree
9708 267565 : c_parser_asm_operands (c_parser *parser)
9709 : {
9710 267565 : tree list = NULL_TREE;
9711 1176731 : while (true)
9712 : {
9713 722148 : tree name, str;
9714 722148 : struct c_expr expr;
9715 722148 : if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
9716 : {
9717 717 : c_parser_consume_token (parser);
9718 717 : if (c_parser_next_token_is (parser, CPP_NAME))
9719 : {
9720 717 : tree id = c_parser_peek_token (parser)->value;
9721 717 : c_parser_consume_token (parser);
9722 717 : name = build_string (IDENTIFIER_LENGTH (id),
9723 717 : IDENTIFIER_POINTER (id));
9724 : }
9725 : else
9726 : {
9727 0 : c_parser_error (parser, "expected identifier");
9728 0 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
9729 0 : return NULL_TREE;
9730 : }
9731 717 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
9732 : "expected %<]%>");
9733 : }
9734 : else
9735 : name = NULL_TREE;
9736 722148 : str = c_parser_asm_string_literal (parser);
9737 722148 : if (str == NULL_TREE)
9738 : return NULL_TREE;
9739 722148 : matching_parens parens;
9740 722148 : if (!parens.require_open (parser))
9741 : return NULL_TREE;
9742 722148 : expr = c_parser_expression (parser);
9743 722148 : mark_exp_read (expr.value);
9744 722148 : if (!parens.require_close (parser))
9745 : {
9746 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
9747 0 : return NULL_TREE;
9748 : }
9749 722148 : list = chainon (list, build_tree_list (build_tree_list (name, str),
9750 : expr.value));
9751 722148 : if (c_parser_next_token_is (parser, CPP_COMMA))
9752 454583 : c_parser_consume_token (parser);
9753 : else
9754 : break;
9755 454583 : }
9756 267565 : return list;
9757 : }
9758 :
9759 : /* Parse asm clobbers, a GNU extension.
9760 :
9761 : asm-clobbers:
9762 : asm-string-literal
9763 : asm-clobbers , asm-string-literal
9764 : */
9765 :
9766 : static tree
9767 142319 : c_parser_asm_clobbers (c_parser *parser)
9768 : {
9769 142319 : tree list = NULL_TREE;
9770 383575 : while (true)
9771 : {
9772 262947 : tree str = c_parser_asm_string_literal (parser);
9773 262947 : if (str)
9774 262947 : list = tree_cons (NULL_TREE, str, list);
9775 : else
9776 : return NULL_TREE;
9777 262947 : if (c_parser_next_token_is (parser, CPP_COMMA))
9778 120628 : c_parser_consume_token (parser);
9779 : else
9780 : break;
9781 120628 : }
9782 : return list;
9783 : }
9784 :
9785 : /* Parse asm goto labels, a GNU extension.
9786 :
9787 : asm-goto-operands:
9788 : identifier
9789 : asm-goto-operands , identifier
9790 : */
9791 :
9792 : static tree
9793 543 : c_parser_asm_goto_operands (c_parser *parser)
9794 : {
9795 543 : tree list = NULL_TREE;
9796 1179 : while (true)
9797 : {
9798 861 : tree name, label;
9799 :
9800 861 : if (c_parser_next_token_is (parser, CPP_NAME))
9801 : {
9802 860 : c_token *tok = c_parser_peek_token (parser);
9803 860 : name = tok->value;
9804 860 : label = lookup_label_for_goto (tok->location, name);
9805 860 : c_parser_consume_token (parser);
9806 860 : TREE_USED (label) = 1;
9807 : }
9808 : else
9809 : {
9810 1 : c_parser_error (parser, "expected identifier");
9811 1 : return NULL_TREE;
9812 : }
9813 :
9814 860 : name = build_string (IDENTIFIER_LENGTH (name),
9815 860 : IDENTIFIER_POINTER (name));
9816 860 : list = tree_cons (name, label, list);
9817 860 : if (c_parser_next_token_is (parser, CPP_COMMA))
9818 318 : c_parser_consume_token (parser);
9819 : else
9820 542 : return nreverse (list);
9821 318 : }
9822 : }
9823 :
9824 : /* Parse a possibly concatenated sequence of string literals.
9825 : TRANSLATE says whether to translate them to the execution character
9826 : set; WIDE_OK says whether any kind of prefixed string literal is
9827 : permitted in this context. This code is based on that in
9828 : lex_string. */
9829 :
9830 : struct c_expr
9831 3888359 : c_parser_string_literal (c_parser *parser, bool translate, bool wide_ok)
9832 : {
9833 3888359 : struct c_expr ret;
9834 3888359 : size_t count;
9835 3888359 : struct obstack str_ob;
9836 3888359 : struct obstack loc_ob;
9837 3888359 : cpp_string str, istr, *strs;
9838 3888359 : c_token *tok;
9839 3888359 : location_t loc, last_tok_loc;
9840 3888359 : enum cpp_ttype type;
9841 3888359 : tree value, string_tree;
9842 :
9843 3888359 : tok = c_parser_peek_token (parser);
9844 3888359 : loc = tok->location;
9845 3888359 : last_tok_loc = linemap_resolve_location (line_table, loc,
9846 : LRK_MACRO_DEFINITION_LOCATION,
9847 : NULL);
9848 3888359 : type = tok->type;
9849 3888359 : switch (type)
9850 : {
9851 3888342 : case CPP_STRING:
9852 3888342 : case CPP_WSTRING:
9853 3888342 : case CPP_STRING16:
9854 3888342 : case CPP_STRING32:
9855 3888342 : case CPP_UTF8STRING:
9856 3888342 : string_tree = tok->value;
9857 3888342 : break;
9858 :
9859 17 : default:
9860 17 : c_parser_error (parser, "expected string literal");
9861 17 : ret.set_error ();
9862 17 : ret.value = NULL_TREE;
9863 17 : ret.original_code = ERROR_MARK;
9864 17 : ret.original_type = NULL_TREE;
9865 17 : return ret;
9866 : }
9867 :
9868 : /* Try to avoid the overhead of creating and destroying an obstack
9869 : for the common case of just one string. */
9870 3888342 : switch (c_parser_peek_2nd_token (parser)->type)
9871 : {
9872 2998315 : default:
9873 2998315 : c_parser_consume_token (parser);
9874 2998315 : str.text = (const unsigned char *) TREE_STRING_POINTER (string_tree);
9875 2998315 : str.len = TREE_STRING_LENGTH (string_tree);
9876 2998315 : count = 1;
9877 2998315 : strs = &str;
9878 2998315 : break;
9879 :
9880 890027 : case CPP_STRING:
9881 890027 : case CPP_WSTRING:
9882 890027 : case CPP_STRING16:
9883 890027 : case CPP_STRING32:
9884 890027 : case CPP_UTF8STRING:
9885 890027 : gcc_obstack_init (&str_ob);
9886 890027 : gcc_obstack_init (&loc_ob);
9887 890027 : count = 0;
9888 27890124 : do
9889 : {
9890 27890124 : c_parser_consume_token (parser);
9891 27890124 : count++;
9892 27890124 : str.text = (const unsigned char *) TREE_STRING_POINTER (string_tree);
9893 27890124 : str.len = TREE_STRING_LENGTH (string_tree);
9894 27890124 : if (type != tok->type)
9895 : {
9896 669 : if (type == CPP_STRING)
9897 29 : type = tok->type;
9898 640 : else if (tok->type != CPP_STRING)
9899 66 : error ("unsupported non-standard concatenation "
9900 : "of string literals");
9901 : }
9902 27890124 : obstack_grow (&str_ob, &str, sizeof (cpp_string));
9903 27890124 : obstack_grow (&loc_ob, &last_tok_loc, sizeof (location_t));
9904 27890124 : tok = c_parser_peek_token (parser);
9905 27890124 : string_tree = tok->value;
9906 27890124 : last_tok_loc
9907 27890124 : = linemap_resolve_location (line_table, tok->location,
9908 : LRK_MACRO_DEFINITION_LOCATION, NULL);
9909 : }
9910 27890124 : while (tok->type == CPP_STRING
9911 : || tok->type == CPP_WSTRING
9912 : || tok->type == CPP_STRING16
9913 : || tok->type == CPP_STRING32
9914 27890124 : || tok->type == CPP_UTF8STRING);
9915 890027 : strs = (cpp_string *) obstack_finish (&str_ob);
9916 : }
9917 :
9918 3888342 : if (count > 1 && !in_system_header_at (input_location))
9919 659110 : warning (OPT_Wtraditional,
9920 : "traditional C rejects string constant concatenation");
9921 :
9922 3888342 : if ((type == CPP_STRING || wide_ok)
9923 7776674 : && ((translate
9924 3888332 : ? cpp_interpret_string : cpp_interpret_string_notranslate)
9925 3888332 : (parse_in, strs, count, &istr, type)))
9926 : {
9927 3888332 : value = build_string (istr.len, (const char *) istr.text);
9928 3888332 : free (const_cast<unsigned char *> (istr.text));
9929 3888332 : if (count > 1)
9930 : {
9931 890027 : location_t *locs = (location_t *) obstack_finish (&loc_ob);
9932 890027 : gcc_assert (g_string_concat_db);
9933 890027 : g_string_concat_db->record_string_concatenation (count, locs);
9934 : }
9935 : }
9936 : else
9937 : {
9938 10 : if (type != CPP_STRING && !wide_ok)
9939 : {
9940 10 : error_at (loc, "a wide string is invalid in this context");
9941 10 : type = CPP_STRING;
9942 : }
9943 : /* Callers cannot generally handle error_mark_node in this
9944 : context, so return the empty string instead. An error has
9945 : been issued, either above or from cpp_interpret_string. */
9946 10 : switch (type)
9947 : {
9948 10 : default:
9949 10 : case CPP_STRING:
9950 10 : case CPP_UTF8STRING:
9951 10 : if (type == CPP_UTF8STRING && flag_char8_t)
9952 : {
9953 0 : value = build_string (TYPE_PRECISION (char8_type_node)
9954 0 : / TYPE_PRECISION (char_type_node),
9955 : ""); /* char8_t is 8 bits */
9956 : }
9957 : else
9958 10 : value = build_string (1, "");
9959 : break;
9960 0 : case CPP_STRING16:
9961 0 : value = build_string (TYPE_PRECISION (char16_type_node)
9962 0 : / TYPE_PRECISION (char_type_node),
9963 : "\0"); /* char16_t is 16 bits */
9964 0 : break;
9965 0 : case CPP_STRING32:
9966 0 : value = build_string (TYPE_PRECISION (char32_type_node)
9967 0 : / TYPE_PRECISION (char_type_node),
9968 : "\0\0\0"); /* char32_t is 32 bits */
9969 0 : break;
9970 0 : case CPP_WSTRING:
9971 0 : value = build_string (TYPE_PRECISION (wchar_type_node)
9972 0 : / TYPE_PRECISION (char_type_node),
9973 : "\0\0\0"); /* widest supported wchar_t
9974 : is 32 bits */
9975 0 : break;
9976 : }
9977 : }
9978 :
9979 3888342 : switch (type)
9980 : {
9981 3885030 : default:
9982 3885030 : case CPP_STRING:
9983 3885030 : TREE_TYPE (value) = char_array_type_node;
9984 3885030 : break;
9985 264 : case CPP_UTF8STRING:
9986 264 : if (flag_char8_t)
9987 82 : TREE_TYPE (value) = char8_array_type_node;
9988 : else
9989 182 : TREE_TYPE (value) = char_array_type_node;
9990 : break;
9991 229 : case CPP_STRING16:
9992 229 : TREE_TYPE (value) = char16_array_type_node;
9993 229 : break;
9994 2294 : case CPP_STRING32:
9995 2294 : TREE_TYPE (value) = char32_array_type_node;
9996 2294 : break;
9997 525 : case CPP_WSTRING:
9998 525 : TREE_TYPE (value) = wchar_array_type_node;
9999 : }
10000 3888342 : value = fix_string_type (value);
10001 :
10002 3888342 : if (count > 1)
10003 : {
10004 890027 : obstack_free (&str_ob, 0);
10005 890027 : obstack_free (&loc_ob, 0);
10006 : }
10007 :
10008 3888342 : ret.value = value;
10009 3888342 : ret.original_code = STRING_CST;
10010 3888342 : ret.original_type = NULL_TREE;
10011 3888342 : set_c_expr_source_range (&ret, get_range_from_loc (line_table, loc));
10012 3888342 : ret.m_decimal = 0;
10013 3888342 : parser->seen_string_literal = true;
10014 3888342 : return ret;
10015 : }
10016 :
10017 : /* Parse an expression other than a compound expression; that is, an
10018 : assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
10019 : AFTER is not NULL then it is an Objective-C message expression which
10020 : is the primary-expression starting the expression as an initializer.
10021 :
10022 : assignment-expression:
10023 : conditional-expression
10024 : unary-expression assignment-operator assignment-expression
10025 :
10026 : assignment-operator: one of
10027 : = *= /= %= += -= <<= >>= &= ^= |=
10028 :
10029 : In GNU C we accept any conditional expression on the LHS and
10030 : diagnose the invalid lvalue rather than producing a syntax
10031 : error. */
10032 :
10033 : static struct c_expr
10034 235183803 : c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
10035 : tree omp_atomic_lhs)
10036 : {
10037 235183803 : struct c_expr lhs, rhs, ret;
10038 235183803 : enum tree_code code;
10039 235183803 : location_t op_location, exp_location;
10040 235183803 : bool save_in_omp_for = c_in_omp_for;
10041 235183803 : c_in_omp_for = false;
10042 235183803 : gcc_assert (!after || c_dialect_objc ());
10043 235183803 : lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
10044 235183801 : op_location = c_parser_peek_token (parser)->location;
10045 235183801 : switch (c_parser_peek_token (parser)->type)
10046 : {
10047 : case CPP_EQ:
10048 : code = NOP_EXPR;
10049 : break;
10050 12624 : case CPP_MULT_EQ:
10051 12624 : code = MULT_EXPR;
10052 12624 : break;
10053 8842 : case CPP_DIV_EQ:
10054 8842 : code = TRUNC_DIV_EXPR;
10055 8842 : break;
10056 2247 : case CPP_MOD_EQ:
10057 2247 : code = TRUNC_MOD_EXPR;
10058 2247 : break;
10059 92589 : case CPP_PLUS_EQ:
10060 92589 : code = PLUS_EXPR;
10061 92589 : break;
10062 29759 : case CPP_MINUS_EQ:
10063 29759 : code = MINUS_EXPR;
10064 29759 : break;
10065 4209 : case CPP_LSHIFT_EQ:
10066 4209 : code = LSHIFT_EXPR;
10067 4209 : break;
10068 17227 : case CPP_RSHIFT_EQ:
10069 17227 : code = RSHIFT_EXPR;
10070 17227 : break;
10071 25620 : case CPP_AND_EQ:
10072 25620 : code = BIT_AND_EXPR;
10073 25620 : break;
10074 3510 : case CPP_XOR_EQ:
10075 3510 : code = BIT_XOR_EXPR;
10076 3510 : break;
10077 21152 : case CPP_OR_EQ:
10078 21152 : code = BIT_IOR_EXPR;
10079 21152 : break;
10080 232197719 : default:
10081 232197719 : c_in_omp_for = save_in_omp_for;
10082 232197719 : return lhs;
10083 : }
10084 2986082 : c_parser_consume_token (parser);
10085 2986082 : exp_location = c_parser_peek_token (parser)->location;
10086 2986082 : rhs = c_parser_expr_no_commas (parser, NULL);
10087 2986082 : rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
10088 :
10089 2986082 : ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
10090 : code, exp_location, rhs.value,
10091 : rhs.original_type);
10092 2986082 : ret.m_decimal = 0;
10093 2986082 : set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ());
10094 2986082 : if (code == NOP_EXPR)
10095 2768303 : ret.original_code = MODIFY_EXPR;
10096 : else
10097 : {
10098 217779 : suppress_warning (ret.value, OPT_Wparentheses);
10099 217779 : ret.original_code = ERROR_MARK;
10100 : }
10101 2986082 : ret.original_type = NULL;
10102 2986082 : c_in_omp_for = save_in_omp_for;
10103 2986082 : return ret;
10104 : }
10105 :
10106 : /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
10107 : AFTER is not NULL then it is an Objective-C message expression which is
10108 : the primary-expression starting the expression as an initializer.
10109 :
10110 : conditional-expression:
10111 : logical-OR-expression
10112 : logical-OR-expression ? expression : conditional-expression
10113 :
10114 : GNU extensions:
10115 :
10116 : conditional-expression:
10117 : logical-OR-expression ? : conditional-expression
10118 : */
10119 :
10120 : static struct c_expr
10121 235592985 : c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
10122 : tree omp_atomic_lhs)
10123 : {
10124 235592985 : struct c_expr cond, exp1, exp2, ret;
10125 235592985 : location_t start, cond_loc, colon_loc;
10126 235592985 : bool save_c_omp_array_section_p = c_omp_array_section_p;
10127 :
10128 235592985 : gcc_assert (!after || c_dialect_objc ());
10129 :
10130 235592985 : cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
10131 :
10132 235592983 : if (c_parser_next_token_is_not (parser, CPP_QUERY))
10133 235183992 : return cond;
10134 408991 : c_omp_array_section_p = false;
10135 408991 : if (cond.value != error_mark_node)
10136 408980 : start = cond.get_start ();
10137 : else
10138 : start = UNKNOWN_LOCATION;
10139 408991 : cond_loc = c_parser_peek_token (parser)->location;
10140 408991 : cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
10141 408991 : c_parser_consume_token (parser);
10142 408991 : if (c_parser_next_token_is (parser, CPP_COLON))
10143 : {
10144 781 : tree eptype = NULL_TREE;
10145 :
10146 781 : location_t middle_loc = c_parser_peek_token (parser)->location;
10147 781 : pedwarn (middle_loc, OPT_Wpedantic,
10148 : "ISO C forbids omitting the middle term of a %<?:%> expression");
10149 781 : if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
10150 : {
10151 1 : eptype = TREE_TYPE (cond.value);
10152 1 : cond.value = TREE_OPERAND (cond.value, 0);
10153 : }
10154 781 : tree e = cond.value;
10155 784 : while (TREE_CODE (e) == COMPOUND_EXPR)
10156 3 : e = TREE_OPERAND (e, 1);
10157 781 : warn_for_omitted_condop (middle_loc, e);
10158 : /* Make sure first operand is calculated only once. */
10159 781 : exp1.value = save_expr (default_conversion (cond.value));
10160 781 : if (eptype)
10161 1 : exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
10162 781 : exp1.original_type = NULL;
10163 781 : exp1.src_range = cond.src_range;
10164 781 : cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
10165 781 : c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
10166 : }
10167 : else
10168 : {
10169 408210 : cond.value
10170 408210 : = c_objc_common_truthvalue_conversion
10171 408210 : (cond_loc, default_conversion (cond.value));
10172 408210 : c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
10173 408210 : exp1 = c_parser_expression_conv (parser);
10174 408210 : mark_exp_read (exp1.value);
10175 408210 : c_inhibit_evaluation_warnings +=
10176 408210 : ((cond.value == truthvalue_true_node)
10177 408210 : - (cond.value == truthvalue_false_node));
10178 : }
10179 :
10180 408991 : colon_loc = c_parser_peek_token (parser)->location;
10181 408991 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10182 : {
10183 9 : c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
10184 9 : ret.set_error ();
10185 9 : ret.original_code = ERROR_MARK;
10186 9 : ret.original_type = NULL;
10187 9 : c_omp_array_section_p = save_c_omp_array_section_p;
10188 9 : return ret;
10189 : }
10190 408982 : {
10191 408982 : location_t exp2_loc = c_parser_peek_token (parser)->location;
10192 408982 : exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
10193 408982 : exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
10194 : }
10195 408982 : c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
10196 408982 : location_t loc1 = make_location (exp1.get_start (), exp1.src_range);
10197 408982 : location_t loc2 = make_location (exp2.get_start (), exp2.src_range);
10198 408982 : if (UNLIKELY (omp_atomic_lhs != NULL)
10199 69 : && (TREE_CODE (cond.value) == GT_EXPR
10200 : || TREE_CODE (cond.value) == LT_EXPR
10201 : || TREE_CODE (cond.value) == EQ_EXPR)
10202 63 : && c_tree_equal (exp2.value, omp_atomic_lhs)
10203 409040 : && (c_tree_equal (TREE_OPERAND (cond.value, 0), omp_atomic_lhs)
10204 19 : || c_tree_equal (TREE_OPERAND (cond.value, 1), omp_atomic_lhs)))
10205 55 : ret.value = build3_loc (colon_loc, COND_EXPR, TREE_TYPE (omp_atomic_lhs),
10206 : cond.value, exp1.value, exp2.value);
10207 : else
10208 408927 : ret.value
10209 408927 : = build_conditional_expr (colon_loc, cond.value,
10210 408927 : cond.original_code == C_MAYBE_CONST_EXPR,
10211 : exp1.value, exp1.original_type, loc1,
10212 : exp2.value, exp2.original_type, loc2);
10213 408982 : ret.original_code = ERROR_MARK;
10214 408982 : if (exp1.value == error_mark_node || exp2.value == error_mark_node)
10215 15 : ret.original_type = NULL;
10216 : else
10217 : {
10218 408967 : tree t1, t2;
10219 :
10220 : /* If both sides are enum type, the default conversion will have
10221 : made the type of the result be an integer type. We want to
10222 : remember the enum types we started with. */
10223 408967 : t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
10224 408967 : t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
10225 408967 : ret.original_type = ((t1 != error_mark_node
10226 408967 : && t2 != error_mark_node
10227 408967 : && (TYPE_MAIN_VARIANT (t1)
10228 408967 : == TYPE_MAIN_VARIANT (t2)))
10229 408967 : ? t1
10230 : : NULL);
10231 : }
10232 408982 : set_c_expr_source_range (&ret, start, exp2.get_finish ());
10233 408982 : ret.m_decimal = 0;
10234 408982 : c_omp_array_section_p = save_c_omp_array_section_p;
10235 408982 : return ret;
10236 : }
10237 :
10238 : /* Parse a binary expression; that is, a logical-OR-expression (C90
10239 : 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
10240 : NULL then it is an Objective-C message expression which is the
10241 : primary-expression starting the expression as an initializer.
10242 :
10243 : OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
10244 : when it should be the unfolded lhs. In a valid OpenMP source,
10245 : one of the operands of the toplevel binary expression must be equal
10246 : to it. In that case, just return a build2 created binary operation
10247 : rather than result of parser_build_binary_op.
10248 :
10249 : multiplicative-expression:
10250 : cast-expression
10251 : multiplicative-expression * cast-expression
10252 : multiplicative-expression / cast-expression
10253 : multiplicative-expression % cast-expression
10254 :
10255 : additive-expression:
10256 : multiplicative-expression
10257 : additive-expression + multiplicative-expression
10258 : additive-expression - multiplicative-expression
10259 :
10260 : shift-expression:
10261 : additive-expression
10262 : shift-expression << additive-expression
10263 : shift-expression >> additive-expression
10264 :
10265 : relational-expression:
10266 : shift-expression
10267 : relational-expression < shift-expression
10268 : relational-expression > shift-expression
10269 : relational-expression <= shift-expression
10270 : relational-expression >= shift-expression
10271 :
10272 : equality-expression:
10273 : relational-expression
10274 : equality-expression == relational-expression
10275 : equality-expression != relational-expression
10276 :
10277 : AND-expression:
10278 : equality-expression
10279 : AND-expression & equality-expression
10280 :
10281 : exclusive-OR-expression:
10282 : AND-expression
10283 : exclusive-OR-expression ^ AND-expression
10284 :
10285 : inclusive-OR-expression:
10286 : exclusive-OR-expression
10287 : inclusive-OR-expression | exclusive-OR-expression
10288 :
10289 : logical-AND-expression:
10290 : inclusive-OR-expression
10291 : logical-AND-expression && inclusive-OR-expression
10292 :
10293 : logical-OR-expression:
10294 : logical-AND-expression
10295 : logical-OR-expression || logical-AND-expression
10296 : */
10297 :
10298 : static struct c_expr
10299 235609511 : c_parser_binary_expression (c_parser *parser, struct c_expr *after,
10300 : tree omp_atomic_lhs)
10301 : {
10302 : /* A binary expression is parsed using operator-precedence parsing,
10303 : with the operands being cast expressions. All the binary
10304 : operators are left-associative. Thus a binary expression is of
10305 : form:
10306 :
10307 : E0 op1 E1 op2 E2 ...
10308 :
10309 : which we represent on a stack. On the stack, the precedence
10310 : levels are strictly increasing. When a new operator is
10311 : encountered of higher precedence than that at the top of the
10312 : stack, it is pushed; its LHS is the top expression, and its RHS
10313 : is everything parsed until it is popped. When a new operator is
10314 : encountered with precedence less than or equal to that at the top
10315 : of the stack, triples E[i-1] op[i] E[i] are popped and replaced
10316 : by the result of the operation until the operator at the top of
10317 : the stack has lower precedence than the new operator or there is
10318 : only one element on the stack; then the top expression is the LHS
10319 : of the new operator. In the case of logical AND and OR
10320 : expressions, we also need to adjust c_inhibit_evaluation_warnings
10321 : as appropriate when the operators are pushed and popped. */
10322 :
10323 235609511 : struct {
10324 : /* The expression at this stack level. */
10325 : struct c_expr expr;
10326 : /* The precedence of the operator on its left, PREC_NONE at the
10327 : bottom of the stack. */
10328 : enum c_parser_prec prec;
10329 : /* The operation on its left. */
10330 : enum tree_code op;
10331 : /* The source location of this operation. */
10332 : location_t loc;
10333 : /* The sizeof argument if expr.original_code == {PAREN_,}SIZEOF_EXPR. */
10334 : tree sizeof_arg;
10335 : /* The original expr.value before c_objc_common_truthvalue_conversion
10336 : for TRUTH_{AND,OR}*_EXPR lhs operands. */
10337 : tree orig_expr;
10338 : } stack[NUM_PRECS];
10339 235609511 : int sp;
10340 : /* Location of the binary operator. */
10341 235609511 : location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
10342 : #define POP \
10343 : do { \
10344 : switch (stack[sp].op) \
10345 : { \
10346 : case TRUTH_ANDIF_EXPR: \
10347 : c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
10348 : == truthvalue_false_node); \
10349 : break; \
10350 : case TRUTH_ORIF_EXPR: \
10351 : c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
10352 : == truthvalue_true_node); \
10353 : break; \
10354 : case TRUNC_DIV_EXPR: \
10355 : if ((stack[sp - 1].expr.original_code == SIZEOF_EXPR \
10356 : || stack[sp - 1].expr.original_code == PAREN_SIZEOF_EXPR) \
10357 : && (stack[sp].expr.original_code == SIZEOF_EXPR \
10358 : || stack[sp].expr.original_code == PAREN_SIZEOF_EXPR)) \
10359 : { \
10360 : tree type0 = stack[sp - 1].sizeof_arg; \
10361 : tree type1 = stack[sp].sizeof_arg; \
10362 : tree first_arg = type0; \
10363 : if (!TYPE_P (type0)) \
10364 : type0 = TREE_TYPE (type0); \
10365 : if (!TYPE_P (type1)) \
10366 : type1 = TREE_TYPE (type1); \
10367 : if (POINTER_TYPE_P (type0) \
10368 : && comptypes (TREE_TYPE (type0), type1) \
10369 : && !(TREE_CODE (first_arg) == PARM_DECL \
10370 : && C_ARRAY_PARAMETER (first_arg) \
10371 : && warn_sizeof_array_argument)) \
10372 : { \
10373 : auto_diagnostic_group d; \
10374 : if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
10375 : "division %<sizeof (%T) / sizeof (%T)%> " \
10376 : "does not compute the number of array " \
10377 : "elements", \
10378 : type0, type1)) \
10379 : if (DECL_P (first_arg)) \
10380 : inform (DECL_SOURCE_LOCATION (first_arg), \
10381 : "first %<sizeof%> operand was declared here"); \
10382 : } \
10383 : else if (TREE_CODE (type0) == ARRAY_TYPE \
10384 : && !char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type0))) \
10385 : && stack[sp].expr.original_code != PAREN_SIZEOF_EXPR) \
10386 : maybe_warn_sizeof_array_div (stack[sp].loc, first_arg, type0, \
10387 : stack[sp].sizeof_arg, type1); \
10388 : } \
10389 : break; \
10390 : default: \
10391 : break; \
10392 : } \
10393 : stack[sp - 1].expr \
10394 : = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
10395 : stack[sp - 1].expr, true, true); \
10396 : stack[sp].expr \
10397 : = convert_lvalue_to_rvalue (stack[sp].loc, \
10398 : stack[sp].expr, true, true); \
10399 : if (UNLIKELY (omp_atomic_lhs != NULL_TREE) && sp == 1 \
10400 : && ((c_parser_next_token_is (parser, CPP_SEMICOLON) \
10401 : && ((1 << stack[sp].prec) \
10402 : & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) \
10403 : | (1 << PREC_BITAND) | (1 << PREC_SHIFT) \
10404 : | (1 << PREC_ADD) | (1 << PREC_MULT) \
10405 : | (1 << PREC_EQ)))) \
10406 : || ((c_parser_next_token_is (parser, CPP_QUERY) \
10407 : || (omp_atomic_lhs == void_list_node \
10408 : && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) \
10409 : && (stack[sp].prec == PREC_REL || stack[sp].prec == PREC_EQ)))\
10410 : && stack[sp].op != TRUNC_MOD_EXPR \
10411 : && stack[sp].op != GE_EXPR \
10412 : && stack[sp].op != LE_EXPR \
10413 : && stack[sp].op != NE_EXPR \
10414 : && stack[0].expr.value != error_mark_node \
10415 : && stack[1].expr.value != error_mark_node \
10416 : && (omp_atomic_lhs == void_list_node \
10417 : || c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
10418 : || c_tree_equal (stack[1].expr.value, omp_atomic_lhs) \
10419 : || (stack[sp].op == EQ_EXPR \
10420 : && c_parser_peek_2nd_token (parser)->keyword == RID_IF))) \
10421 : { \
10422 : tree t = make_node (stack[1].op); \
10423 : TREE_TYPE (t) = TREE_TYPE (stack[0].expr.value); \
10424 : TREE_OPERAND (t, 0) = stack[0].expr.value; \
10425 : TREE_OPERAND (t, 1) = stack[1].expr.value; \
10426 : stack[0].expr.value = t; \
10427 : stack[0].expr.m_decimal = 0; \
10428 : } \
10429 : else \
10430 : stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
10431 : stack[sp].op, \
10432 : stack[sp - 1].expr, \
10433 : stack[sp].expr, \
10434 : stack[sp - 1].orig_expr); \
10435 : stack[sp - 1].orig_expr = NULL_TREE; \
10436 : sp--; \
10437 : } while (0)
10438 235609511 : gcc_assert (!after || c_dialect_objc ());
10439 235609511 : stack[0].loc = c_parser_peek_token (parser)->location;
10440 235609511 : stack[0].expr = c_parser_cast_expression (parser, after);
10441 235609511 : stack[0].prec = PREC_NONE;
10442 235609511 : stack[0].sizeof_arg = c_last_sizeof_arg;
10443 235609511 : stack[0].orig_expr = NULL_TREE;
10444 235609511 : sp = 0;
10445 255665013 : while (true)
10446 : {
10447 245637262 : enum c_parser_prec oprec;
10448 245637262 : enum tree_code ocode;
10449 245637262 : source_range src_range;
10450 245637262 : if (parser->error)
10451 1072 : goto out;
10452 245636190 : switch (c_parser_peek_token (parser)->type)
10453 : {
10454 : case CPP_MULT:
10455 : oprec = PREC_MULT;
10456 : ocode = MULT_EXPR;
10457 : break;
10458 268777 : case CPP_DIV:
10459 268777 : oprec = PREC_MULT;
10460 268777 : ocode = TRUNC_DIV_EXPR;
10461 268777 : break;
10462 57167 : case CPP_MOD:
10463 57167 : oprec = PREC_MULT;
10464 57167 : ocode = TRUNC_MOD_EXPR;
10465 57167 : break;
10466 2305164 : case CPP_PLUS:
10467 2305164 : oprec = PREC_ADD;
10468 2305164 : ocode = PLUS_EXPR;
10469 2305164 : break;
10470 763561 : case CPP_MINUS:
10471 763561 : oprec = PREC_ADD;
10472 763561 : ocode = MINUS_EXPR;
10473 763561 : break;
10474 806520 : case CPP_LSHIFT:
10475 806520 : oprec = PREC_SHIFT;
10476 806520 : ocode = LSHIFT_EXPR;
10477 806520 : break;
10478 217752 : case CPP_RSHIFT:
10479 217752 : oprec = PREC_SHIFT;
10480 217752 : ocode = RSHIFT_EXPR;
10481 217752 : break;
10482 483806 : case CPP_LESS:
10483 483806 : oprec = PREC_REL;
10484 483806 : ocode = LT_EXPR;
10485 483806 : break;
10486 199479 : case CPP_GREATER:
10487 199479 : oprec = PREC_REL;
10488 199479 : ocode = GT_EXPR;
10489 199479 : break;
10490 164107 : case CPP_LESS_EQ:
10491 164107 : oprec = PREC_REL;
10492 164107 : ocode = LE_EXPR;
10493 164107 : break;
10494 168734 : case CPP_GREATER_EQ:
10495 168734 : oprec = PREC_REL;
10496 168734 : ocode = GE_EXPR;
10497 168734 : break;
10498 404616 : case CPP_EQ_EQ:
10499 404616 : oprec = PREC_EQ;
10500 404616 : ocode = EQ_EXPR;
10501 404616 : break;
10502 785020 : case CPP_NOT_EQ:
10503 785020 : oprec = PREC_EQ;
10504 785020 : ocode = NE_EXPR;
10505 785020 : break;
10506 655816 : case CPP_AND:
10507 655816 : oprec = PREC_BITAND;
10508 655816 : ocode = BIT_AND_EXPR;
10509 655816 : break;
10510 84837 : case CPP_XOR:
10511 84837 : oprec = PREC_BITXOR;
10512 84837 : ocode = BIT_XOR_EXPR;
10513 84837 : break;
10514 876726 : case CPP_OR:
10515 876726 : oprec = PREC_BITOR;
10516 876726 : ocode = BIT_IOR_EXPR;
10517 876726 : break;
10518 187951 : case CPP_AND_AND:
10519 187951 : oprec = PREC_LOGAND;
10520 187951 : ocode = TRUTH_ANDIF_EXPR;
10521 187951 : break;
10522 326758 : case CPP_OR_OR:
10523 326758 : oprec = PREC_LOGOR;
10524 326758 : ocode = TRUTH_ORIF_EXPR;
10525 326758 : break;
10526 235608439 : default:
10527 : /* Not a binary operator, so end of the binary
10528 : expression. */
10529 235608439 : goto out;
10530 : }
10531 10027751 : binary_loc = c_parser_peek_token (parser)->location;
10532 10027751 : while (oprec <= stack[sp].prec)
10533 11497307 : POP;
10534 10027751 : c_parser_consume_token (parser);
10535 10027751 : switch (ocode)
10536 : {
10537 187951 : case TRUTH_ANDIF_EXPR:
10538 187951 : src_range = stack[sp].expr.src_range;
10539 187951 : stack[sp].expr
10540 187951 : = convert_lvalue_to_rvalue (stack[sp].loc,
10541 : stack[sp].expr, true, true);
10542 187951 : stack[sp].orig_expr = stack[sp].expr.value;
10543 375902 : stack[sp].expr.value = c_objc_common_truthvalue_conversion
10544 187951 : (stack[sp].loc, default_conversion (stack[sp].expr.value));
10545 187951 : c_inhibit_evaluation_warnings += (stack[sp].expr.value
10546 187951 : == truthvalue_false_node);
10547 187951 : set_c_expr_source_range (&stack[sp].expr, src_range);
10548 187951 : break;
10549 326758 : case TRUTH_ORIF_EXPR:
10550 326758 : src_range = stack[sp].expr.src_range;
10551 326758 : stack[sp].expr
10552 326758 : = convert_lvalue_to_rvalue (stack[sp].loc,
10553 : stack[sp].expr, true, true);
10554 326758 : stack[sp].orig_expr = stack[sp].expr.value;
10555 653516 : stack[sp].expr.value = c_objc_common_truthvalue_conversion
10556 326758 : (stack[sp].loc, default_conversion (stack[sp].expr.value));
10557 326758 : c_inhibit_evaluation_warnings += (stack[sp].expr.value
10558 326758 : == truthvalue_true_node);
10559 326758 : set_c_expr_source_range (&stack[sp].expr, src_range);
10560 326758 : break;
10561 : default:
10562 : break;
10563 : }
10564 10027751 : sp++;
10565 10027751 : stack[sp].loc = binary_loc;
10566 10027751 : stack[sp].expr = c_parser_cast_expression (parser, NULL);
10567 10027751 : stack[sp].prec = oprec;
10568 10027751 : stack[sp].op = ocode;
10569 10027751 : stack[sp].sizeof_arg = c_last_sizeof_arg;
10570 10027751 : stack[sp].orig_expr = NULL_TREE;
10571 10027751 : }
10572 235609511 : out:
10573 235609511 : while (sp > 0)
10574 244167945 : POP;
10575 235609509 : return stack[0].expr;
10576 : #undef POP
10577 : }
10578 :
10579 : /* Parse any storage class specifiers after an open parenthesis in a
10580 : context where a compound literal is permitted. */
10581 :
10582 : static struct c_declspecs *
10583 126384647 : c_parser_compound_literal_scspecs (c_parser *parser)
10584 : {
10585 126384647 : bool seen_scspec = false;
10586 126384647 : struct c_declspecs *specs = build_null_declspecs ();
10587 252769637 : while (c_parser_next_token_is (parser, CPP_KEYWORD))
10588 : {
10589 4384596 : switch (c_parser_peek_token (parser)->keyword)
10590 : {
10591 343 : case RID_CONSTEXPR:
10592 343 : case RID_REGISTER:
10593 343 : case RID_STATIC:
10594 343 : case RID_THREAD:
10595 343 : seen_scspec = true;
10596 343 : declspecs_add_scspec (c_parser_peek_token (parser)->location,
10597 343 : specs, c_parser_peek_token (parser)->value);
10598 343 : c_parser_consume_token (parser);
10599 343 : break;
10600 4384253 : default:
10601 4384253 : goto out;
10602 : }
10603 : }
10604 122000394 : out:
10605 126384647 : return seen_scspec ? specs : NULL;
10606 : }
10607 :
10608 : /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
10609 : is not NULL then it is an Objective-C message expression which is the
10610 : primary-expression starting the expression as an initializer.
10611 :
10612 : cast-expression:
10613 : unary-expression
10614 : ( type-name ) unary-expression
10615 : */
10616 :
10617 : static struct c_expr
10618 380918955 : c_parser_cast_expression (c_parser *parser, struct c_expr *after)
10619 : {
10620 380918955 : location_t cast_loc = c_parser_peek_token (parser)->location;
10621 380918955 : gcc_assert (!after || c_dialect_objc ());
10622 0 : if (after)
10623 0 : return c_parser_postfix_expression_after_primary (parser,
10624 0 : cast_loc, *after);
10625 : /* If the expression begins with a parenthesized type name, it may
10626 : be either a cast or a compound literal; we need to see whether
10627 : the next character is '{' to tell the difference. If not, it is
10628 : an unary expression. Full detection of unknown typenames here
10629 : would require a 3-token lookahead. */
10630 380918955 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
10631 380918955 : && c_token_starts_compound_literal (c_parser_peek_2nd_token (parser)))
10632 : {
10633 126019463 : struct c_declspecs *scspecs;
10634 126019463 : struct c_type_name *type_name;
10635 126019463 : struct c_expr ret;
10636 126019463 : struct c_expr expr;
10637 126019463 : matching_parens parens;
10638 126019463 : parens.consume_open (parser);
10639 126019463 : scspecs = c_parser_compound_literal_scspecs (parser);
10640 126019463 : type_name = c_parser_type_name (parser, true);
10641 126019463 : parens.skip_until_found_close (parser);
10642 126019463 : if (type_name == NULL)
10643 : {
10644 1 : ret.set_error ();
10645 1 : ret.original_code = ERROR_MARK;
10646 1 : ret.original_type = NULL;
10647 1 : return ret;
10648 : }
10649 :
10650 : /* Save casted types in the function's used types hash table. */
10651 126019462 : used_types_insert (type_name->specs->type);
10652 :
10653 126019462 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
10654 929285 : return c_parser_postfix_expression_after_paren_type (parser, scspecs,
10655 : type_name,
10656 929285 : cast_loc);
10657 125090177 : if (scspecs)
10658 1 : error_at (cast_loc, "storage class specifier in cast");
10659 125090177 : if (type_name->specs->alignas_p)
10660 1 : error_at (type_name->specs->locations[cdw_alignas],
10661 : "alignment specified for type name in cast");
10662 125090177 : {
10663 125090177 : location_t expr_loc = c_parser_peek_token (parser)->location;
10664 125090177 : expr = c_parser_cast_expression (parser, NULL);
10665 125090177 : expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
10666 : }
10667 125090177 : ret.value = c_cast_expr (cast_loc, type_name, expr.value);
10668 125090177 : if (ret.value && expr.value)
10669 125090177 : set_c_expr_source_range (&ret, cast_loc, expr.get_finish ());
10670 125090177 : ret.original_code = ERROR_MARK;
10671 125090177 : ret.original_type = NULL;
10672 125090177 : ret.m_decimal = 0;
10673 125090177 : return ret;
10674 : }
10675 : else
10676 254899492 : return c_parser_unary_expression (parser);
10677 : }
10678 :
10679 :
10680 : /* Like mark_exp_read but skip marking VAR_DECLs and PARM_DECLs
10681 : depending on the warning mode. This helper function is
10682 : used in c_parser_unary_expression and
10683 : and c_parser_postfix_expression_after_primary for
10684 : pre/post-increment/decrement operations.
10685 : */
10686 :
10687 : static void
10688 951459 : mark_exp_read_cond (tree exp)
10689 : {
10690 951459 : if ((VAR_P (exp) || TREE_CODE (exp) == PARM_DECL)
10691 872063 : && (VAR_P (exp) ? warn_unused_but_set_variable
10692 : : warn_unused_but_set_parameter) > 1)
10693 : return;
10694 :
10695 753333 : mark_exp_read (exp);
10696 : }
10697 :
10698 :
10699 : /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
10700 :
10701 : unary-expression:
10702 : postfix-expression
10703 : ++ unary-expression
10704 : -- unary-expression
10705 : unary-operator cast-expression
10706 : _Countof unary-expression
10707 : _Countof ( type-name )
10708 : sizeof unary-expression
10709 : sizeof ( type-name )
10710 : static-assert-declaration-no-semi
10711 :
10712 : (_Countof and the use of static assertions in expressions are new in C2y.)
10713 :
10714 : unary-operator: one of
10715 : & * + - ~ !
10716 :
10717 : GNU extensions:
10718 :
10719 : unary-expression:
10720 : __alignof__ unary-expression
10721 : __alignof__ ( type-name )
10722 : _Maxof ( type-name )
10723 : _Minof ( type-name )
10724 : && identifier
10725 :
10726 : (C11 permits _Alignof with type names only.)
10727 :
10728 : unary-operator: one of
10729 : __extension__ __real__ __imag__
10730 :
10731 : Transactional Memory:
10732 :
10733 : unary-expression:
10734 : transaction-expression
10735 :
10736 : In addition, the GNU syntax treats ++ and -- as unary operators, so
10737 : they may be applied to cast expressions with errors for non-lvalues
10738 : given later. */
10739 :
10740 : static struct c_expr
10741 255255589 : c_parser_unary_expression (c_parser *parser)
10742 : {
10743 255255589 : int ext;
10744 255255589 : struct c_expr ret, op;
10745 255255589 : location_t op_loc = c_parser_peek_token (parser)->location;
10746 255255589 : location_t exp_loc;
10747 255255589 : location_t finish;
10748 255255589 : ret.original_code = ERROR_MARK;
10749 255255589 : ret.original_type = NULL;
10750 255255589 : switch (c_parser_peek_token (parser)->type)
10751 : {
10752 221463 : case CPP_PLUS_PLUS:
10753 221463 : c_parser_consume_token (parser);
10754 221463 : exp_loc = c_parser_peek_token (parser)->location;
10755 221463 : op = c_parser_cast_expression (parser, NULL);
10756 221463 : mark_exp_read_cond (op.value);
10757 221463 : op = default_function_array_conversion (exp_loc, op);
10758 221463 : return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
10759 20404 : case CPP_MINUS_MINUS:
10760 20404 : c_parser_consume_token (parser);
10761 20404 : exp_loc = c_parser_peek_token (parser)->location;
10762 20404 : op = c_parser_cast_expression (parser, NULL);
10763 20404 : mark_exp_read_cond (op.value);
10764 20404 : op = default_function_array_conversion (exp_loc, op);
10765 20404 : return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
10766 453117 : case CPP_AND:
10767 453117 : c_parser_consume_token (parser);
10768 453117 : op = c_parser_cast_expression (parser, NULL);
10769 453117 : mark_exp_read (op.value);
10770 453117 : return parser_build_unary_op (op_loc, ADDR_EXPR, op);
10771 1224038 : case CPP_MULT:
10772 1224038 : {
10773 1224038 : c_parser_consume_token (parser);
10774 1224038 : exp_loc = c_parser_peek_token (parser)->location;
10775 1224038 : op = c_parser_cast_expression (parser, NULL);
10776 1224038 : finish = op.get_finish ();
10777 1224038 : op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
10778 1224038 : location_t combined_loc = make_location (op_loc, op_loc, finish);
10779 1224038 : ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR);
10780 1224038 : ret.src_range.m_start = op_loc;
10781 1224038 : ret.src_range.m_finish = finish;
10782 1224038 : ret.m_decimal = 0;
10783 1224038 : return ret;
10784 : }
10785 28812 : case CPP_PLUS:
10786 28812 : if (!c_dialect_objc () && !in_system_header_at (input_location))
10787 28810 : warning_at (op_loc,
10788 28810 : OPT_Wtraditional,
10789 : "traditional C rejects the unary plus operator");
10790 28812 : c_parser_consume_token (parser);
10791 28812 : exp_loc = c_parser_peek_token (parser)->location;
10792 28812 : op = c_parser_cast_expression (parser, NULL);
10793 28812 : op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
10794 28812 : return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
10795 7017504 : case CPP_MINUS:
10796 7017504 : c_parser_consume_token (parser);
10797 7017504 : exp_loc = c_parser_peek_token (parser)->location;
10798 7017504 : op = c_parser_cast_expression (parser, NULL);
10799 7017504 : op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
10800 7017504 : return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
10801 299054 : case CPP_COMPL:
10802 299054 : c_parser_consume_token (parser);
10803 299054 : exp_loc = c_parser_peek_token (parser)->location;
10804 299054 : op = c_parser_cast_expression (parser, NULL);
10805 299054 : op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
10806 299054 : return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
10807 379378 : case CPP_NOT:
10808 379378 : c_parser_consume_token (parser);
10809 379378 : exp_loc = c_parser_peek_token (parser)->location;
10810 379378 : op = c_parser_cast_expression (parser, NULL);
10811 379378 : op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
10812 379378 : return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
10813 2019 : case CPP_AND_AND:
10814 : /* Refer to the address of a label as a pointer. */
10815 2019 : c_parser_consume_token (parser);
10816 2019 : if (c_parser_next_token_is (parser, CPP_NAME))
10817 : {
10818 4024 : ret.value = finish_label_address_expr
10819 2012 : (c_parser_peek_token (parser)->value, op_loc);
10820 2012 : set_c_expr_source_range (&ret, op_loc,
10821 : c_parser_peek_token (parser)->get_finish ());
10822 2012 : c_parser_consume_token (parser);
10823 : }
10824 : else
10825 : {
10826 7 : c_parser_error (parser, "expected identifier");
10827 7 : ret.set_error ();
10828 : }
10829 2019 : return ret;
10830 2925567 : case CPP_KEYWORD:
10831 2925567 : {
10832 2925567 : enum rid rid = c_parser_peek_token (parser)->keyword;
10833 2925567 : switch (rid)
10834 : {
10835 648985 : case RID_COUNTOF:
10836 648985 : case RID_SIZEOF:
10837 648985 : return c_parser_sizeof_or_countof_expression (parser, rid);
10838 72296 : case RID_ALIGNOF:
10839 72296 : return c_parser_alignof_expression (parser);
10840 102 : case RID_MAXOF:
10841 102 : case RID_MINOF:
10842 102 : return c_parser_maxof_or_minof_expression (parser, rid);
10843 765 : case RID_BUILTIN_HAS_ATTRIBUTE:
10844 765 : return c_parser_has_attribute_expression (parser);
10845 466420 : case RID_EXTENSION:
10846 466420 : c_parser_consume_token (parser);
10847 466420 : ext = disable_extension_diagnostics ();
10848 466420 : ret = c_parser_cast_expression (parser, NULL);
10849 466420 : restore_extension_diagnostics (ext);
10850 466420 : return ret;
10851 38406 : case RID_REALPART:
10852 38406 : c_parser_consume_token (parser);
10853 38406 : exp_loc = c_parser_peek_token (parser)->location;
10854 38406 : op = c_parser_cast_expression (parser, NULL);
10855 38406 : op = default_function_array_conversion (exp_loc, op);
10856 38406 : return parser_build_unary_op (op_loc, REALPART_EXPR, op);
10857 40268 : case RID_IMAGPART:
10858 40268 : c_parser_consume_token (parser);
10859 40268 : exp_loc = c_parser_peek_token (parser)->location;
10860 40268 : op = c_parser_cast_expression (parser, NULL);
10861 40268 : op = default_function_array_conversion (exp_loc, op);
10862 40268 : return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
10863 7 : case RID_TRANSACTION_ATOMIC:
10864 7 : case RID_TRANSACTION_RELAXED:
10865 7 : return c_parser_transaction_expression (parser, rid);
10866 168 : case RID_STATIC_ASSERT:
10867 168 : c_parser_static_assert_declaration_no_semi (parser);
10868 168 : pedwarn_c23 (op_loc, OPT_Wpedantic,
10869 : "ISO C does not support static assertions in "
10870 : "expressions before C2Y");
10871 168 : ret.value = void_node;
10872 168 : set_c_expr_source_range (&ret, op_loc, op_loc);
10873 168 : ret.m_decimal = 0;
10874 168 : return ret;
10875 1658150 : default:
10876 1658150 : return c_parser_postfix_expression (parser);
10877 : }
10878 : }
10879 242684233 : default:
10880 242684233 : return c_parser_postfix_expression (parser);
10881 : }
10882 : }
10883 :
10884 : /* Parse a sizeof or _Countof expression. */
10885 :
10886 : static struct c_expr
10887 648985 : c_parser_sizeof_or_countof_expression (c_parser *parser, enum rid rid)
10888 : {
10889 648985 : const char *op_name = (rid == RID_COUNTOF) ? "_Countof" : "sizeof";
10890 648985 : struct c_expr expr;
10891 648985 : struct c_expr result;
10892 648985 : location_t expr_loc;
10893 648985 : gcc_assert (c_parser_next_token_is_keyword (parser, rid));
10894 :
10895 648985 : location_t start;
10896 648985 : location_t finish = UNKNOWN_LOCATION;
10897 :
10898 648985 : start = c_parser_peek_token (parser)->location;
10899 :
10900 648985 : if (rid == RID_COUNTOF)
10901 72 : pedwarn_c23 (start, OPT_Wpedantic,
10902 : "ISO C does not support %qs before C2Y", op_name);
10903 :
10904 648985 : c_parser_consume_token (parser);
10905 648985 : c_inhibit_evaluation_warnings++;
10906 648985 : if (rid == RID_COUNTOF)
10907 72 : in_countof++;
10908 : else
10909 648913 : in_sizeof++;
10910 648985 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
10911 648985 : && c_token_starts_compound_literal (c_parser_peek_2nd_token (parser)))
10912 : {
10913 : /* Either sizeof ( type-name ) or sizeof unary-expression
10914 : starting with a compound literal. */
10915 333687 : struct c_declspecs *scspecs;
10916 333687 : struct c_type_name *type_name;
10917 333687 : matching_parens parens;
10918 333687 : parens.consume_open (parser);
10919 333687 : expr_loc = c_parser_peek_token (parser)->location;
10920 333687 : scspecs = c_parser_compound_literal_scspecs (parser);
10921 333687 : type_name = c_parser_type_name (parser, true);
10922 333687 : parens.skip_until_found_close (parser);
10923 333687 : finish = parser->tokens_buf[0].location;
10924 333687 : if (type_name == NULL)
10925 : {
10926 : /* Let c_expr_sizeof_expr call pop_maybe_used and fill in c_expr
10927 : for parsing error; the parsing of the expression could have
10928 : called record_maybe_used_decl. */
10929 1 : expr.set_error ();
10930 27 : goto Xof_expr;
10931 : }
10932 333686 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
10933 : {
10934 26 : expr = c_parser_postfix_expression_after_paren_type (parser, scspecs,
10935 : type_name,
10936 : expr_loc);
10937 26 : finish = expr.get_finish ();
10938 26 : goto Xof_expr;
10939 : }
10940 : /* sizeof ( type-name ). */
10941 333660 : if (scspecs)
10942 1 : error_at (expr_loc, "storage class specifier in %qs", op_name);
10943 333660 : if (type_name->specs->alignas_p)
10944 2 : error_at (type_name->specs->locations[cdw_alignas],
10945 : "alignment specified for type name in %qs", op_name);
10946 333660 : c_inhibit_evaluation_warnings--;
10947 333660 : if (rid == RID_COUNTOF)
10948 : {
10949 18 : in_countof--;
10950 18 : result = c_expr_countof_type (expr_loc, type_name);
10951 : }
10952 : else
10953 : {
10954 333642 : in_sizeof--;
10955 333642 : result = c_expr_sizeof_type (expr_loc, type_name);
10956 : }
10957 : }
10958 : else
10959 : {
10960 315298 : expr_loc = c_parser_peek_token (parser)->location;
10961 315298 : expr = c_parser_unary_expression (parser);
10962 315298 : finish = expr.get_finish ();
10963 315325 : Xof_expr:
10964 315325 : c_inhibit_evaluation_warnings--;
10965 315325 : if (rid == RID_COUNTOF)
10966 54 : in_countof--;
10967 : else
10968 315271 : in_sizeof--;
10969 315325 : mark_exp_read (expr.value);
10970 315325 : if (TREE_CODE (expr.value) == COMPONENT_REF
10971 315325 : && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
10972 1 : error_at (expr_loc, "%qs applied to a bit-field", op_name);
10973 315325 : if (rid == RID_COUNTOF)
10974 54 : result = c_expr_countof_expr (expr_loc, expr);
10975 : else
10976 315271 : result = c_expr_sizeof_expr (expr_loc, expr);
10977 : }
10978 648985 : if (finish == UNKNOWN_LOCATION)
10979 1 : finish = start;
10980 648985 : set_c_expr_source_range (&result, start, finish);
10981 648985 : return result;
10982 : }
10983 :
10984 : /* Parse an alignof expression. */
10985 :
10986 : static struct c_expr
10987 72296 : c_parser_alignof_expression (c_parser *parser)
10988 : {
10989 72296 : struct c_expr expr;
10990 72296 : location_t start_loc = c_parser_peek_token (parser)->location;
10991 72296 : location_t end_loc;
10992 72296 : tree alignof_spelling = c_parser_peek_token (parser)->value;
10993 72296 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
10994 72296 : bool is_c11_alignof = (strcmp (IDENTIFIER_POINTER (alignof_spelling),
10995 : "_Alignof") == 0
10996 72296 : || strcmp (IDENTIFIER_POINTER (alignof_spelling),
10997 : "alignof") == 0);
10998 : /* A diagnostic is not required for the use of this identifier in
10999 : the implementation namespace; only diagnose it for the C11 or C23
11000 : spelling because of existing code using the other spellings. */
11001 : if (is_c11_alignof)
11002 : {
11003 234 : if (flag_isoc99)
11004 230 : pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE",
11005 : alignof_spelling);
11006 : else
11007 4 : pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE",
11008 : alignof_spelling);
11009 : }
11010 72296 : c_parser_consume_token (parser);
11011 72296 : c_inhibit_evaluation_warnings++;
11012 72296 : in_alignof++;
11013 72296 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
11014 72296 : && c_token_starts_compound_literal (c_parser_peek_2nd_token (parser)))
11015 : {
11016 : /* Either __alignof__ ( type-name ) or __alignof__
11017 : unary-expression starting with a compound literal. */
11018 31497 : location_t loc;
11019 31497 : struct c_declspecs *scspecs;
11020 31497 : struct c_type_name *type_name;
11021 31497 : struct c_expr ret;
11022 31497 : matching_parens parens;
11023 31497 : parens.consume_open (parser);
11024 31497 : loc = c_parser_peek_token (parser)->location;
11025 31497 : scspecs = c_parser_compound_literal_scspecs (parser);
11026 31497 : type_name = c_parser_type_name (parser, true);
11027 31497 : end_loc = c_parser_peek_token (parser)->location;
11028 31497 : parens.skip_until_found_close (parser);
11029 31497 : if (type_name == NULL)
11030 : {
11031 0 : struct c_expr ret;
11032 0 : c_inhibit_evaluation_warnings--;
11033 0 : in_alignof--;
11034 0 : ret.set_error ();
11035 0 : ret.original_code = ERROR_MARK;
11036 0 : ret.original_type = NULL;
11037 31495 : return ret;
11038 : }
11039 31497 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
11040 : {
11041 2 : expr = c_parser_postfix_expression_after_paren_type (parser, scspecs,
11042 : type_name,
11043 : loc);
11044 2 : goto alignof_expr;
11045 : }
11046 : /* alignof ( type-name ). */
11047 31495 : if (scspecs)
11048 1 : error_at (loc, "storage class specifier in %qE", alignof_spelling);
11049 31495 : if (type_name->specs->alignas_p)
11050 1 : error_at (type_name->specs->locations[cdw_alignas],
11051 : "alignment specified for type name in %qE",
11052 : alignof_spelling);
11053 31495 : c_inhibit_evaluation_warnings--;
11054 31495 : in_alignof--;
11055 31495 : ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
11056 : NULL, NULL),
11057 : false, is_c11_alignof, 1);
11058 31495 : ret.original_code = ERROR_MARK;
11059 31495 : ret.original_type = NULL;
11060 31495 : set_c_expr_source_range (&ret, start_loc, end_loc);
11061 31495 : ret.m_decimal = 0;
11062 31495 : return ret;
11063 : }
11064 : else
11065 : {
11066 40799 : struct c_expr ret;
11067 40799 : expr = c_parser_unary_expression (parser);
11068 40799 : end_loc = expr.src_range.m_finish;
11069 40801 : alignof_expr:
11070 40801 : mark_exp_read (expr.value);
11071 40801 : c_inhibit_evaluation_warnings--;
11072 40801 : in_alignof--;
11073 40801 : if (is_c11_alignof)
11074 36 : pedwarn (start_loc,
11075 36 : OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
11076 : alignof_spelling);
11077 40801 : ret.value = c_alignof_expr (start_loc, expr.value);
11078 40801 : ret.original_code = ERROR_MARK;
11079 40801 : ret.original_type = NULL;
11080 40801 : set_c_expr_source_range (&ret, start_loc, end_loc);
11081 40801 : ret.m_decimal = 0;
11082 40801 : return ret;
11083 : }
11084 : }
11085 :
11086 : /* Parse a _Maxof or _Minof expression. */
11087 :
11088 : static struct c_expr
11089 102 : c_parser_maxof_or_minof_expression (c_parser *parser, enum rid rid)
11090 : {
11091 102 : const char *op_name = (rid == RID_MAXOF) ? "_Maxof" : "_Minof";
11092 102 : struct c_expr result;
11093 102 : location_t expr_loc;
11094 102 : struct c_type_name *type_name;
11095 102 : matching_parens parens;
11096 102 : gcc_assert (c_parser_next_token_is_keyword (parser, rid));
11097 :
11098 102 : location_t start;
11099 102 : location_t finish = UNKNOWN_LOCATION;
11100 :
11101 102 : start = c_parser_peek_token (parser)->location;
11102 :
11103 102 : pedwarn (start, OPT_Wpedantic, "ISO C does not support %qs", op_name);
11104 :
11105 102 : c_parser_consume_token (parser);
11106 102 : c_inhibit_evaluation_warnings++;
11107 102 : if (!c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11108 : {
11109 2 : c_parser_error (parser, "expected %<(%>");
11110 2 : goto fail;
11111 : }
11112 100 : parens.consume_open (parser);
11113 100 : expr_loc = c_parser_peek_token (parser)->location;
11114 100 : if (!c_token_starts_typename (c_parser_peek_token (parser)))
11115 : {
11116 6 : error_at (expr_loc, "invalid application of %qs to something not a type", op_name);
11117 6 : parens.skip_until_found_close (parser);
11118 6 : goto fail;
11119 : }
11120 94 : type_name = c_parser_type_name (parser, true);
11121 94 : if (type_name == NULL)
11122 : {
11123 : // c_parser_type_name() has already diagnosed the error.
11124 2 : parens.skip_until_found_close (parser);
11125 2 : goto fail;
11126 : }
11127 92 : parens.skip_until_found_close (parser);
11128 92 : finish = parser->tokens_buf[0].location;
11129 92 : if (type_name->specs->alignas_p)
11130 2 : error_at (type_name->specs->locations[cdw_alignas],
11131 : "alignment specified for type name in %qs", op_name);
11132 92 : c_inhibit_evaluation_warnings--;
11133 92 : if (rid == RID_MAXOF)
11134 46 : result = c_expr_maxof_type (expr_loc, type_name);
11135 : else
11136 46 : result = c_expr_minof_type (expr_loc, type_name);
11137 92 : set_c_expr_source_range (&result, start, finish);
11138 92 : return result;
11139 10 : fail:
11140 10 : c_inhibit_evaluation_warnings--;
11141 10 : result.set_error ();
11142 10 : result.original_code = ERROR_MARK;
11143 10 : result.original_type = NULL;
11144 10 : return result;
11145 : }
11146 :
11147 : /* Parse the __builtin_has_attribute ([expr|type], attribute-spec)
11148 : expression. */
11149 :
11150 : static struct c_expr
11151 765 : c_parser_has_attribute_expression (c_parser *parser)
11152 : {
11153 765 : gcc_assert (c_parser_next_token_is_keyword (parser,
11154 : RID_BUILTIN_HAS_ATTRIBUTE));
11155 765 : location_t start = c_parser_peek_token (parser)->location;
11156 765 : c_parser_consume_token (parser);
11157 :
11158 765 : c_inhibit_evaluation_warnings++;
11159 :
11160 765 : matching_parens parens;
11161 765 : if (!parens.require_open (parser))
11162 : {
11163 0 : c_inhibit_evaluation_warnings--;
11164 0 : in_typeof--;
11165 :
11166 0 : struct c_expr result;
11167 0 : result.set_error ();
11168 0 : result.original_code = ERROR_MARK;
11169 0 : result.original_type = NULL;
11170 0 : return result;
11171 : }
11172 :
11173 : /* Treat the type argument the same way as in typeof for the purposes
11174 : of warnings. FIXME: Generalize this so the warning refers to
11175 : __builtin_has_attribute rather than typeof. */
11176 765 : in_typeof++;
11177 :
11178 : /* The first operand: one of DECL, EXPR, or TYPE. */
11179 765 : tree oper = NULL_TREE;
11180 765 : if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
11181 : {
11182 148 : struct c_type_name *tname = c_parser_type_name (parser);
11183 148 : in_typeof--;
11184 148 : if (tname)
11185 : {
11186 148 : oper = groktypename (tname, NULL, NULL);
11187 148 : pop_maybe_used (c_type_variably_modified_p (oper));
11188 : }
11189 : }
11190 : else
11191 : {
11192 617 : struct c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
11193 617 : c_inhibit_evaluation_warnings--;
11194 617 : in_typeof--;
11195 617 : if (cexpr.value != error_mark_node)
11196 : {
11197 614 : mark_exp_read (cexpr.value);
11198 614 : oper = cexpr.value;
11199 614 : tree etype = TREE_TYPE (oper);
11200 614 : bool was_vm = c_type_variably_modified_p (etype);
11201 : /* This is returned with the type so that when the type is
11202 : evaluated, this can be evaluated. */
11203 614 : if (was_vm)
11204 0 : oper = c_fully_fold (oper, false, NULL);
11205 614 : pop_maybe_used (was_vm);
11206 : }
11207 : }
11208 :
11209 765 : struct c_expr result;
11210 765 : result.original_code = ERROR_MARK;
11211 765 : result.original_type = NULL;
11212 :
11213 765 : if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
11214 : {
11215 : /* Consume the closing parenthesis if that's the next token
11216 : in the likely case the built-in was invoked with fewer
11217 : than two arguments. */
11218 4 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
11219 4 : c_parser_consume_token (parser);
11220 4 : c_inhibit_evaluation_warnings--;
11221 4 : result.set_error ();
11222 4 : return result;
11223 : }
11224 :
11225 761 : bool save_translate_strings_p = parser->translate_strings_p;
11226 :
11227 761 : location_t atloc = c_parser_peek_token (parser)->location;
11228 : /* Parse a single attribute. Require no leading comma and do not
11229 : allow empty attributes. */
11230 761 : tree attr = c_parser_gnu_attribute (parser, NULL_TREE, false, false);
11231 :
11232 761 : parser->translate_strings_p = save_translate_strings_p;
11233 :
11234 761 : location_t finish = c_parser_peek_token (parser)->location;
11235 761 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
11236 758 : c_parser_consume_token (parser);
11237 : else
11238 : {
11239 3 : c_parser_error (parser, "expected identifier");
11240 3 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11241 :
11242 3 : result.set_error ();
11243 3 : return result;
11244 : }
11245 :
11246 758 : if (!attr)
11247 : {
11248 0 : error_at (atloc, "expected identifier");
11249 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11250 : "expected %<)%>");
11251 0 : result.set_error ();
11252 0 : return result;
11253 : }
11254 :
11255 758 : result.original_code = INTEGER_CST;
11256 758 : result.original_type = boolean_type_node;
11257 :
11258 758 : if (has_attribute (atloc, oper, attr, default_conversion))
11259 296 : result.value = boolean_true_node;
11260 : else
11261 462 : result.value = boolean_false_node;
11262 :
11263 758 : set_c_expr_source_range (&result, start, finish);
11264 758 : result.m_decimal = 0;
11265 758 : return result;
11266 : }
11267 :
11268 : /* Helper function to read arguments of builtins which are interfaces
11269 : for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
11270 : others. The name of the builtin is passed using BNAME parameter.
11271 : Function returns true if there were no errors while parsing and
11272 : stores the arguments in CEXPR_LIST. If it returns true,
11273 : *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
11274 : parenthesis. */
11275 : static bool
11276 1580501 : c_parser_get_builtin_args (c_parser *parser, const char *bname,
11277 : vec<c_expr_t, va_gc> **ret_cexpr_list,
11278 : bool choose_expr_p,
11279 : location_t *out_close_paren_loc)
11280 : {
11281 1580501 : location_t loc = c_parser_peek_token (parser)->location;
11282 1580501 : vec<c_expr_t, va_gc> *cexpr_list;
11283 1580501 : c_expr_t expr;
11284 1580501 : bool saved_force_folding_builtin_constant_p;
11285 :
11286 1580501 : *ret_cexpr_list = NULL;
11287 1580501 : if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
11288 : {
11289 1 : error_at (loc, "cannot take address of %qs", bname);
11290 1 : return false;
11291 : }
11292 :
11293 1580500 : c_parser_consume_token (parser);
11294 :
11295 1580500 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
11296 : {
11297 24 : *out_close_paren_loc = c_parser_peek_token (parser)->location;
11298 24 : c_parser_consume_token (parser);
11299 24 : return true;
11300 : }
11301 :
11302 1580476 : saved_force_folding_builtin_constant_p
11303 1580476 : = force_folding_builtin_constant_p;
11304 1580476 : force_folding_builtin_constant_p |= choose_expr_p;
11305 1580476 : expr = c_parser_expr_no_commas (parser, NULL);
11306 1580476 : force_folding_builtin_constant_p
11307 1580476 : = saved_force_folding_builtin_constant_p;
11308 1580476 : vec_alloc (cexpr_list, 1);
11309 1580476 : vec_safe_push (cexpr_list, expr);
11310 18496567 : while (c_parser_next_token_is (parser, CPP_COMMA))
11311 : {
11312 15335615 : c_parser_consume_token (parser);
11313 15335615 : if (c_parser_next_token_is (parser, CPP_EMBED))
11314 : {
11315 2 : c_token *embed = c_parser_peek_token (parser);
11316 2 : tree value = embed->value;
11317 2 : expr.original_code = INTEGER_CST;
11318 2 : expr.original_type = integer_type_node;
11319 2 : expr.value = NULL_TREE;
11320 2 : set_c_expr_source_range (&expr, embed->get_range ());
11321 2 : expr.m_decimal = 0;
11322 510 : for (unsigned int i = 0; i < (unsigned) RAW_DATA_LENGTH (value); i++)
11323 : {
11324 1016 : expr.value = build_int_cst (integer_type_node,
11325 508 : RAW_DATA_UCHAR_ELT (value, i));
11326 508 : vec_safe_push (cexpr_list, expr);
11327 : }
11328 2 : c_parser_consume_token (parser);
11329 2 : continue;
11330 2 : }
11331 15335613 : expr = c_parser_expr_no_commas (parser, NULL);
11332 15335613 : vec_safe_push (cexpr_list, expr);
11333 : }
11334 :
11335 1580476 : *out_close_paren_loc = c_parser_peek_token (parser)->location;
11336 1580476 : if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
11337 : return false;
11338 :
11339 1580476 : *ret_cexpr_list = cexpr_list;
11340 1580476 : return true;
11341 : }
11342 :
11343 : /* This represents a single generic-association. */
11344 :
11345 : struct c_generic_association
11346 : {
11347 : /* The location of the starting token of the type. */
11348 : location_t type_location;
11349 : /* The association's type, or NULL_TREE for 'default'. */
11350 : tree type;
11351 : /* The association's expression. */
11352 : struct c_expr expression;
11353 : };
11354 :
11355 : /* Parse a generic-selection. (C11 6.5.1.1).
11356 :
11357 : generic-selection:
11358 : _Generic ( generic-controlling-operand , generic-assoc-list )
11359 :
11360 : generic-controlling-operand:
11361 : assignment-expression
11362 : type-name
11363 :
11364 : (The use of a type-name is new in C2Y.)
11365 :
11366 : generic-assoc-list:
11367 : generic-association
11368 : generic-assoc-list , generic-association
11369 :
11370 : generic-association:
11371 : type-name : assignment-expression
11372 : default : assignment-expression
11373 : */
11374 :
11375 : static struct c_expr
11376 1420 : c_parser_generic_selection (c_parser *parser)
11377 : {
11378 1420 : struct c_expr selector, error_expr;
11379 1420 : tree selector_type;
11380 1420 : struct c_generic_association matched_assoc;
11381 1420 : int match_found = -1;
11382 1420 : location_t generic_loc, selector_loc;
11383 :
11384 1420 : error_expr.original_code = ERROR_MARK;
11385 1420 : error_expr.original_type = NULL;
11386 1420 : error_expr.set_error ();
11387 1420 : matched_assoc.type_location = UNKNOWN_LOCATION;
11388 1420 : matched_assoc.type = NULL_TREE;
11389 1420 : matched_assoc.expression = error_expr;
11390 :
11391 1420 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
11392 1420 : generic_loc = c_parser_peek_token (parser)->location;
11393 1420 : c_parser_consume_token (parser);
11394 1420 : if (flag_isoc99)
11395 1418 : pedwarn_c99 (generic_loc, OPT_Wpedantic,
11396 : "ISO C99 does not support %<_Generic%>");
11397 : else
11398 2 : pedwarn_c99 (generic_loc, OPT_Wpedantic,
11399 : "ISO C90 does not support %<_Generic%>");
11400 :
11401 1420 : matching_parens parens;
11402 1420 : if (!parens.require_open (parser))
11403 0 : return error_expr;
11404 :
11405 1420 : selector_loc = c_parser_peek_token (parser)->location;
11406 1420 : if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
11407 : {
11408 38 : c_inhibit_evaluation_warnings++;
11409 38 : pedwarn_c23 (selector_loc, OPT_Wpedantic,
11410 : "ISO C does not support use of type name as %<_Generic%> "
11411 : "controlling operand before C2Y");
11412 38 : struct c_type_name *type = c_parser_type_name (parser);
11413 38 : if (type)
11414 37 : selector_type = groktypename (type, NULL, NULL);
11415 38 : c_inhibit_evaluation_warnings--;
11416 38 : if (!type)
11417 : {
11418 1 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11419 1 : return error_expr;
11420 : }
11421 : }
11422 : else
11423 : {
11424 1382 : c_inhibit_evaluation_warnings++;
11425 1382 : in_generic++;
11426 1382 : selector = c_parser_expr_no_commas (parser, NULL);
11427 1382 : selector = default_function_array_conversion (selector_loc, selector);
11428 1382 : c_inhibit_evaluation_warnings--;
11429 1382 : in_generic--;
11430 1382 : pop_maybe_used (!flag_isoc23);
11431 :
11432 1382 : if (selector.value == error_mark_node)
11433 : {
11434 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11435 0 : return selector;
11436 : }
11437 1382 : mark_exp_read (selector.value);
11438 1382 : selector_type = TREE_TYPE (selector.value);
11439 : /* In ISO C terms, rvalues (including the controlling expression
11440 : of _Generic) do not have qualified types. */
11441 1382 : if (TREE_CODE (selector_type) != ARRAY_TYPE)
11442 1382 : selector_type = TYPE_MAIN_VARIANT (selector_type);
11443 : /* In ISO C terms, _Noreturn is not part of the type of expressions
11444 : such as &abort, but in GCC it is represented internally as a type
11445 : qualifier. */
11446 571 : if (FUNCTION_POINTER_TYPE_P (selector_type)
11447 1386 : && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
11448 1 : selector_type
11449 1 : = c_build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
11450 : }
11451 :
11452 1419 : if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
11453 : {
11454 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11455 0 : return error_expr;
11456 : }
11457 :
11458 1419 : auto_vec<c_generic_association> associations;
11459 1419 : struct maybe_used_decl *maybe_used_default = NULL;
11460 4073 : while (1)
11461 : {
11462 2746 : struct c_generic_association assoc, *iter;
11463 2746 : unsigned int ix;
11464 2746 : c_token *token = c_parser_peek_token (parser);
11465 :
11466 2746 : assoc.type_location = token->location;
11467 2746 : if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
11468 : {
11469 1210 : c_parser_consume_token (parser);
11470 1210 : assoc.type = NULL_TREE;
11471 : }
11472 : else
11473 : {
11474 1536 : struct c_type_name *type_name;
11475 :
11476 1536 : type_name = c_parser_type_name (parser);
11477 1536 : if (type_name == NULL)
11478 : {
11479 1 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11480 1 : return error_expr;
11481 : }
11482 1535 : assoc.type = grokgenassoc (type_name);
11483 1535 : if (assoc.type == error_mark_node)
11484 : {
11485 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11486 0 : return error_expr;
11487 : }
11488 :
11489 1535 : if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
11490 9 : pedwarn_c23 (assoc.type_location, OPT_Wpedantic,
11491 : "ISO C does not support %<_Generic%> association with "
11492 : "function type before C2Y");
11493 1526 : else if (!COMPLETE_TYPE_P (assoc.type))
11494 13 : pedwarn_c23 (assoc.type_location, OPT_Wpedantic,
11495 : "ISO C does not support %<_Generic%> association with "
11496 : "incomplete type before C2Y");
11497 :
11498 1535 : if (c_type_variably_modified_p (assoc.type))
11499 9 : pedwarn_c23 (assoc.type_location, OPT_Wpedantic,
11500 : "ISO C does not support %<_Generic%> association with "
11501 : "variably-modified type before C2Y");
11502 : }
11503 :
11504 2745 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11505 : {
11506 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11507 0 : return error_expr;
11508 : }
11509 :
11510 2745 : bool match = assoc.type == NULL_TREE
11511 2745 : || comptypes (assoc.type, selector_type);
11512 :
11513 2354 : if (!match || matched_assoc.type != NULL_TREE)
11514 837 : c_inhibit_evaluation_warnings++;
11515 2745 : in_generic++;
11516 :
11517 2745 : assoc.expression = c_parser_expr_no_commas (parser, NULL);
11518 :
11519 2745 : if (!match || matched_assoc.type != NULL_TREE)
11520 837 : c_inhibit_evaluation_warnings--;
11521 2745 : in_generic--;
11522 2745 : if (!match)
11523 391 : pop_maybe_used (!flag_isoc23);
11524 2354 : else if (assoc.type == NULL_TREE)
11525 1210 : maybe_used_default = save_maybe_used ();
11526 : else
11527 1144 : pop_maybe_used (true);
11528 :
11529 2745 : if (assoc.expression.value == error_mark_node)
11530 : {
11531 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11532 0 : return error_expr;
11533 : }
11534 :
11535 4187 : for (ix = 0; associations.iterate (ix, &iter); ++ix)
11536 : {
11537 1442 : if (assoc.type == NULL_TREE)
11538 : {
11539 719 : if (iter->type == NULL_TREE)
11540 : {
11541 1 : error_at (assoc.type_location,
11542 : "duplicate %<default%> case in %<_Generic%>");
11543 1 : inform (iter->type_location, "original %<default%> is here");
11544 : }
11545 : }
11546 723 : else if (iter->type != NULL_TREE)
11547 : {
11548 184 : if (comptypes (assoc.type, iter->type))
11549 : {
11550 1 : error_at (assoc.type_location,
11551 : "%<_Generic%> specifies two compatible types");
11552 1 : inform (iter->type_location, "compatible type is here");
11553 : }
11554 : }
11555 : }
11556 :
11557 2745 : if (assoc.type == NULL_TREE)
11558 : {
11559 1210 : if (match_found < 0)
11560 : {
11561 763 : matched_assoc = assoc;
11562 1019 : match_found = associations.length ();
11563 : }
11564 : }
11565 1535 : else if (match)
11566 : {
11567 1144 : if (match_found < 0 || matched_assoc.type == NULL_TREE)
11568 : {
11569 1144 : matched_assoc = assoc;
11570 1678 : match_found = associations.length ();
11571 : }
11572 : else
11573 : {
11574 0 : error_at (assoc.type_location,
11575 : "%<_Generic%> selector matches multiple associations");
11576 0 : inform (matched_assoc.type_location,
11577 : "other match is here");
11578 : }
11579 : }
11580 :
11581 2745 : associations.safe_push (assoc);
11582 :
11583 2745 : if (c_parser_peek_token (parser)->type != CPP_COMMA)
11584 : break;
11585 1327 : c_parser_consume_token (parser);
11586 1327 : }
11587 :
11588 1418 : if (match_found >= 0 && matched_assoc.type == NULL_TREE)
11589 : {
11590 : /* Declarations referenced in the default association are used. */
11591 271 : restore_maybe_used (maybe_used_default);
11592 271 : pop_maybe_used (true);
11593 : }
11594 1147 : else if (maybe_used_default)
11595 : {
11596 : /* Declarations referenced in the default association are not used, but
11597 : are treated as used before C23. */
11598 8 : restore_maybe_used (maybe_used_default);
11599 8 : pop_maybe_used (!flag_isoc23);
11600 : }
11601 :
11602 1418 : unsigned int ix;
11603 1418 : struct c_generic_association *iter;
11604 4162 : FOR_EACH_VEC_ELT (associations, ix, iter)
11605 2744 : if (ix != (unsigned) match_found)
11606 1330 : mark_exp_read (iter->expression.value);
11607 :
11608 1418 : if (!parens.require_close (parser))
11609 : {
11610 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11611 0 : return error_expr;
11612 : }
11613 :
11614 1418 : if (match_found < 0)
11615 : {
11616 4 : error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
11617 : "compatible with any association",
11618 : selector_type);
11619 4 : return error_expr;
11620 : }
11621 :
11622 1414 : return matched_assoc.expression;
11623 1419 : }
11624 :
11625 : /* Check the validity of a function pointer argument *EXPR (argument
11626 : position POS) to __builtin_tgmath. Return the number of function
11627 : arguments if possibly valid; return 0 having reported an error if
11628 : not valid. */
11629 :
11630 : static unsigned int
11631 1755 : check_tgmath_function (c_expr *expr, unsigned int pos)
11632 : {
11633 1755 : tree type = TREE_TYPE (expr->value);
11634 1755 : if (!FUNCTION_POINTER_TYPE_P (type))
11635 : {
11636 2 : error_at (expr->get_location (),
11637 : "argument %u of %<__builtin_tgmath%> is not a function pointer",
11638 : pos);
11639 2 : return 0;
11640 : }
11641 1753 : type = TREE_TYPE (type);
11642 1753 : if (!prototype_p (type))
11643 : {
11644 2 : error_at (expr->get_location (),
11645 : "argument %u of %<__builtin_tgmath%> is unprototyped", pos);
11646 2 : return 0;
11647 : }
11648 1751 : if (stdarg_p (type))
11649 : {
11650 2 : error_at (expr->get_location (),
11651 : "argument %u of %<__builtin_tgmath%> has variable arguments",
11652 : pos);
11653 2 : return 0;
11654 : }
11655 1749 : unsigned int nargs = 0;
11656 1749 : function_args_iterator iter;
11657 1749 : tree t;
11658 4176 : FOREACH_FUNCTION_ARGS (type, t, iter)
11659 : {
11660 4176 : if (t == void_type_node)
11661 : break;
11662 2427 : nargs++;
11663 : }
11664 1749 : if (nargs == 0)
11665 : {
11666 2 : error_at (expr->get_location (),
11667 : "argument %u of %<__builtin_tgmath%> has no arguments", pos);
11668 2 : return 0;
11669 : }
11670 : return nargs;
11671 : }
11672 :
11673 : /* Ways in which a parameter or return value of a type-generic macro
11674 : may vary between the different functions the macro may call. */
11675 : enum tgmath_parm_kind
11676 : {
11677 : tgmath_fixed, tgmath_real, tgmath_complex
11678 : };
11679 :
11680 : /* Helper function for c_parser_postfix_expression. Parse predefined
11681 : identifiers. */
11682 :
11683 : static struct c_expr
11684 13507 : c_parser_predefined_identifier (c_parser *parser)
11685 : {
11686 13507 : location_t loc = c_parser_peek_token (parser)->location;
11687 13507 : switch (c_parser_peek_token (parser)->keyword)
11688 : {
11689 717 : case RID_FUNCTION_NAME:
11690 717 : pedwarn (loc, OPT_Wpedantic, "ISO C does not support %qs predefined "
11691 : "identifier", "__FUNCTION__");
11692 717 : break;
11693 6254 : case RID_PRETTY_FUNCTION_NAME:
11694 6254 : pedwarn (loc, OPT_Wpedantic, "ISO C does not support %qs predefined "
11695 : "identifier", "__PRETTY_FUNCTION__");
11696 6254 : break;
11697 6536 : case RID_C99_FUNCTION_NAME:
11698 6536 : pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support "
11699 : "%<__func__%> predefined identifier");
11700 6536 : break;
11701 0 : default:
11702 0 : gcc_unreachable ();
11703 : }
11704 :
11705 13507 : struct c_expr expr;
11706 13507 : expr.original_code = ERROR_MARK;
11707 13507 : expr.original_type = NULL;
11708 13507 : expr.value = fname_decl (loc, c_parser_peek_token (parser)->keyword,
11709 13507 : c_parser_peek_token (parser)->value);
11710 13507 : set_c_expr_source_range (&expr, loc, loc);
11711 13507 : expr.m_decimal = 0;
11712 13507 : c_parser_consume_token (parser);
11713 13507 : return expr;
11714 : }
11715 :
11716 : /* Check whether the REF has an counted-by object associated with it
11717 : through the "counted_by" attribute. */
11718 :
11719 : static bool
11720 80 : has_counted_by_object (tree ref)
11721 : {
11722 : /* Currently, there are two cases are valid:
11723 : A. when the ref is an indirect_ref to a call to the
11724 : .ACCESS_WITH_SIZE, return true. (this is for FAM)
11725 : B. when the ref is a call to .ACCESS_WITH_SIZE, return true.
11726 : (this is for pointer field inside a structure)
11727 : More cases can be included later when the counted_by attribute is
11728 : extended to other situations. */
11729 80 : if ((TREE_CODE (ref) == INDIRECT_REF
11730 25 : && is_access_with_size_p (TREE_OPERAND (ref, 0)))
11731 80 : || is_access_with_size_p (ref))
11732 50 : return true;
11733 : return false;
11734 : }
11735 :
11736 : /* Get the reference to the counted-by object associated with the REF. */
11737 :
11738 : static tree
11739 50 : get_counted_by_ref (tree ref)
11740 : {
11741 : /* Currently, there are two cases are valid:
11742 : A. when the ref is an indirect_ref to a call to the
11743 : .ACCESS_WITH_SIZE, return true. (this is for FAM)
11744 : B. when the ref is a call to .ACCESS_WITH_SIZE, return true.
11745 : (this is for pointer field inside a structure)
11746 : More cases can be included later when the counted_by attribute is
11747 : extended to other situations. */
11748 50 : if (TREE_CODE (ref) == INDIRECT_REF
11749 50 : && is_access_with_size_p (TREE_OPERAND (ref, 0)))
11750 25 : return CALL_EXPR_ARG (TREE_OPERAND (ref, 0), 1);
11751 25 : else if (is_access_with_size_p (ref))
11752 25 : return CALL_EXPR_ARG (ref, 1);
11753 :
11754 : return NULL_TREE;
11755 : }
11756 :
11757 : /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
11758 : C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
11759 : call c_parser_postfix_expression_after_paren_type on encountering them.
11760 :
11761 : postfix-expression:
11762 : primary-expression
11763 : postfix-expression [ expression ]
11764 : postfix-expression ( argument-expression-list[opt] )
11765 : postfix-expression . identifier
11766 : postfix-expression -> identifier
11767 : postfix-expression ++
11768 : postfix-expression --
11769 : ( storage-class-specifiers[opt] type-name ) { initializer-list[opt] }
11770 : ( storage-class-specifiers[opt] type-name ) { initializer-list , }
11771 :
11772 : argument-expression-list:
11773 : argument-expression
11774 : argument-expression-list , argument-expression
11775 :
11776 : primary-expression:
11777 : identifier
11778 : constant
11779 : string-literal
11780 : ( expression )
11781 : generic-selection
11782 :
11783 : GNU extensions:
11784 :
11785 : primary-expression:
11786 : __func__
11787 : (treated as a keyword in GNU C)
11788 : __FUNCTION__
11789 : __PRETTY_FUNCTION__
11790 : ( compound-statement )
11791 : __builtin_va_arg ( assignment-expression , type-name )
11792 : __builtin_offsetof ( type-name , offsetof-member-designator )
11793 : __builtin_choose_expr ( assignment-expression ,
11794 : assignment-expression ,
11795 : assignment-expression )
11796 : __builtin_types_compatible_p ( type-name , type-name )
11797 : __builtin_tgmath ( expr-list )
11798 : __builtin_complex ( assignment-expression , assignment-expression )
11799 : __builtin_shuffle ( assignment-expression , assignment-expression )
11800 : __builtin_shuffle ( assignment-expression ,
11801 : assignment-expression ,
11802 : assignment-expression, )
11803 : __builtin_convertvector ( assignment-expression , type-name )
11804 : __builtin_assoc_barrier ( assignment-expression )
11805 :
11806 : offsetof-member-designator:
11807 : identifier
11808 : offsetof-member-designator . identifier
11809 : offsetof-member-designator [ expression ]
11810 :
11811 : Objective-C:
11812 :
11813 : primary-expression:
11814 : [ objc-receiver objc-message-args ]
11815 : @selector ( objc-selector-arg )
11816 : @protocol ( identifier )
11817 : @encode ( type-name )
11818 : objc-string-literal
11819 : Classname . identifier
11820 : */
11821 :
11822 : static struct c_expr
11823 244354070 : c_parser_postfix_expression (c_parser *parser)
11824 : {
11825 244354070 : struct c_expr expr, e1;
11826 244354070 : struct c_type_name *t1, *t2;
11827 244354070 : location_t loc = c_parser_peek_token (parser)->location;
11828 244354070 : source_range tok_range = c_parser_peek_token (parser)->get_range ();
11829 244354070 : expr.original_code = ERROR_MARK;
11830 244354070 : expr.original_type = NULL;
11831 244354070 : expr.m_decimal = 0;
11832 244354070 : switch (c_parser_peek_token (parser)->type)
11833 : {
11834 52779712 : case CPP_NUMBER:
11835 52779712 : expr.value = c_parser_peek_token (parser)->value;
11836 52779712 : set_c_expr_source_range (&expr, tok_range);
11837 52779712 : loc = c_parser_peek_token (parser)->location;
11838 52779712 : expr.m_decimal = c_parser_peek_token (parser)->flags & DECIMAL_INT;
11839 52779712 : c_parser_consume_token (parser);
11840 52779712 : if (TREE_CODE (expr.value) == FIXED_CST
11841 52779712 : && !targetm.fixed_point_supported_p ())
11842 : {
11843 6 : error_at (loc, "fixed-point types not supported for this target");
11844 6 : expr.set_error ();
11845 : }
11846 : break;
11847 118915 : case CPP_CHAR:
11848 118915 : case CPP_CHAR16:
11849 118915 : case CPP_CHAR32:
11850 118915 : case CPP_UTF8CHAR:
11851 118915 : case CPP_WCHAR:
11852 118915 : expr.value = c_parser_peek_token (parser)->value;
11853 : /* For the purpose of warning when a pointer is compared with
11854 : a zero character constant. */
11855 118915 : expr.original_type = char_type_node;
11856 118915 : set_c_expr_source_range (&expr, tok_range);
11857 118915 : c_parser_consume_token (parser);
11858 118915 : break;
11859 1172331 : case CPP_STRING:
11860 1172331 : case CPP_STRING16:
11861 1172331 : case CPP_STRING32:
11862 1172331 : case CPP_WSTRING:
11863 1172331 : case CPP_UTF8STRING:
11864 1172331 : expr = c_parser_string_literal (parser, parser->translate_strings_p,
11865 : true);
11866 1172331 : break;
11867 0 : case CPP_OBJC_STRING:
11868 0 : gcc_assert (c_dialect_objc ());
11869 0 : expr.value
11870 0 : = objc_build_string_object (c_parser_peek_token (parser)->value);
11871 0 : set_c_expr_source_range (&expr, tok_range);
11872 0 : c_parser_consume_token (parser);
11873 0 : break;
11874 180415707 : case CPP_NAME:
11875 180415707 : switch (c_parser_peek_token (parser)->id_kind)
11876 : {
11877 180415705 : case C_ID_ID:
11878 180415705 : {
11879 180415705 : tree id = c_parser_peek_token (parser)->value;
11880 180415705 : c_parser_consume_token (parser);
11881 541247115 : expr.value = build_external_ref (loc, id,
11882 180415705 : (c_parser_peek_token (parser)->type
11883 : == CPP_OPEN_PAREN),
11884 : &expr.original_type);
11885 180415705 : set_c_expr_source_range (&expr, tok_range);
11886 180415705 : break;
11887 : }
11888 0 : case C_ID_CLASSNAME:
11889 0 : {
11890 : /* Here we parse the Objective-C 2.0 Class.name dot
11891 : syntax. */
11892 0 : tree class_name = c_parser_peek_token (parser)->value;
11893 0 : tree component;
11894 0 : c_parser_consume_token (parser);
11895 0 : gcc_assert (c_dialect_objc ());
11896 0 : if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
11897 : {
11898 0 : expr.set_error ();
11899 0 : break;
11900 : }
11901 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
11902 : {
11903 0 : c_parser_error (parser, "expected identifier");
11904 0 : expr.set_error ();
11905 0 : break;
11906 : }
11907 0 : c_token *component_tok = c_parser_peek_token (parser);
11908 0 : component = component_tok->value;
11909 0 : location_t end_loc = component_tok->get_finish ();
11910 0 : c_parser_consume_token (parser);
11911 0 : expr.value = objc_build_class_component_ref (class_name,
11912 : component);
11913 0 : set_c_expr_source_range (&expr, loc, end_loc);
11914 0 : break;
11915 : }
11916 2 : default:
11917 2 : c_parser_error (parser, "expected expression");
11918 2 : expr.set_error ();
11919 2 : break;
11920 : }
11921 : break;
11922 8208462 : case CPP_OPEN_PAREN:
11923 : /* A parenthesized expression, statement expression or compound
11924 : literal. */
11925 8208462 : if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
11926 : {
11927 : /* A statement expression. */
11928 35464 : tree stmt;
11929 35464 : location_t brace_loc;
11930 35464 : bool save_c_omp_array_section_p = c_omp_array_section_p;
11931 35464 : c_parser_consume_token (parser);
11932 35464 : brace_loc = c_parser_peek_token (parser)->location;
11933 35464 : c_parser_consume_token (parser);
11934 : /* If we've not yet started the current function's statement list,
11935 : or we're in the parameter scope of an old-style function
11936 : declaration, statement expressions are not allowed. */
11937 35464 : if (!building_stmt_list_p () || old_style_parameter_scope ())
11938 : {
11939 24 : error_at (loc, "braced-group within expression allowed "
11940 : "only inside a function");
11941 24 : parser->error = true;
11942 24 : c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
11943 24 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
11944 24 : expr.set_error ();
11945 24 : break;
11946 : }
11947 35440 : c_omp_array_section_p = false;
11948 35440 : stmt = c_begin_stmt_expr ();
11949 35440 : c_parser_compound_statement_nostart (parser);
11950 35440 : location_t close_loc = c_parser_peek_token (parser)->location;
11951 35440 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11952 : "expected %<)%>");
11953 35440 : pedwarn (loc, OPT_Wpedantic,
11954 : "ISO C forbids braced-groups within expressions");
11955 35440 : expr.value = c_finish_stmt_expr (brace_loc, stmt);
11956 35440 : set_c_expr_source_range (&expr, loc, close_loc);
11957 35440 : mark_exp_read (expr.value);
11958 35440 : c_omp_array_section_p = save_c_omp_array_section_p;
11959 : }
11960 : else
11961 : {
11962 : /* A parenthesized expression. */
11963 8172998 : location_t loc_open_paren = c_parser_peek_token (parser)->location;
11964 8172998 : c_parser_consume_token (parser);
11965 8172998 : expr = c_parser_expression (parser);
11966 8172998 : if (TREE_CODE (expr.value) == MODIFY_EXPR)
11967 38229 : suppress_warning (expr.value, OPT_Wparentheses);
11968 8172998 : if (expr.original_code != C_MAYBE_CONST_EXPR
11969 8172986 : && expr.original_code != SIZEOF_EXPR)
11970 8168072 : expr.original_code = ERROR_MARK;
11971 : /* Remember that we saw ( ) around the sizeof. */
11972 8172998 : if (expr.original_code == SIZEOF_EXPR)
11973 4914 : expr.original_code = PAREN_SIZEOF_EXPR;
11974 : /* Don't change EXPR.ORIGINAL_TYPE. */
11975 8172998 : location_t loc_close_paren = c_parser_peek_token (parser)->location;
11976 8172998 : set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren);
11977 8172998 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11978 : "expected %<)%>", loc_open_paren);
11979 : }
11980 : break;
11981 1658150 : case CPP_KEYWORD:
11982 1658150 : switch (c_parser_peek_token (parser)->keyword)
11983 : {
11984 13487 : case RID_FUNCTION_NAME:
11985 13487 : case RID_PRETTY_FUNCTION_NAME:
11986 13487 : case RID_C99_FUNCTION_NAME:
11987 13487 : expr = c_parser_predefined_identifier (parser);
11988 13487 : break;
11989 20008 : case RID_VA_ARG:
11990 20008 : {
11991 20008 : location_t start_loc = loc;
11992 20008 : c_parser_consume_token (parser);
11993 20008 : matching_parens parens;
11994 20008 : if (!parens.require_open (parser))
11995 : {
11996 0 : expr.set_error ();
11997 0 : break;
11998 : }
11999 20008 : e1 = c_parser_expr_no_commas (parser, NULL);
12000 20008 : mark_exp_read (e1.value);
12001 20008 : e1.value = c_fully_fold (e1.value, false, NULL);
12002 20008 : if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
12003 : {
12004 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
12005 0 : expr.set_error ();
12006 0 : break;
12007 : }
12008 20008 : loc = c_parser_peek_token (parser)->location;
12009 20008 : t1 = c_parser_type_name (parser);
12010 20008 : location_t end_loc = c_parser_peek_token (parser)->get_finish ();
12011 20008 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12012 : "expected %<)%>");
12013 20008 : if (t1 == NULL)
12014 : {
12015 0 : expr.set_error ();
12016 : }
12017 : else
12018 : {
12019 20008 : tree type_expr = NULL_TREE;
12020 20008 : tree type = groktypename (t1, &type_expr, NULL);
12021 20008 : expr.value = c_build_va_arg (start_loc, e1.value, loc,
12022 : type, type_expr);
12023 20008 : set_c_expr_source_range (&expr, start_loc, end_loc);
12024 : }
12025 : }
12026 20008 : break;
12027 13657 : case RID_C23_VA_START:
12028 13657 : {
12029 13657 : c_parser_consume_token (parser);
12030 13657 : matching_parens parens;
12031 13657 : if (!parens.require_open (parser))
12032 : {
12033 0 : expr.set_error ();
12034 0 : break;
12035 : }
12036 13657 : e1 = c_parser_expr_no_commas (parser, NULL);
12037 13657 : e1 = convert_lvalue_to_rvalue (e1.get_location (), e1, true, true);
12038 13657 : if (!c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
12039 : {
12040 13479 : location_t cloc = c_parser_peek_token (parser)->location;
12041 13479 : if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
12042 : {
12043 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
12044 0 : expr.set_error ();
12045 0 : break;
12046 : }
12047 13479 : if (c_parser_next_token_is (parser, CPP_NAME)
12048 13474 : && c_parser_peek_token (parser)->id_kind == C_ID_ID
12049 26953 : && (c_parser_peek_2nd_token (parser)->type
12050 : == CPP_CLOSE_PAREN))
12051 : {
12052 13453 : tree name = c_parser_peek_token (parser)->value;
12053 13453 : location_t nloc = c_parser_peek_token (parser)->location;
12054 13453 : tree decl = lookup_name (name);
12055 13453 : tree last_parm
12056 13453 : = tree_last (DECL_ARGUMENTS (current_function_decl));
12057 13453 : if (!last_parm || decl != last_parm)
12058 4 : warning_at (nloc, OPT_Wvarargs,
12059 : "optional second parameter of %<va_start%> "
12060 : "not last named argument");
12061 13449 : else if (DECL_REGISTER (decl))
12062 2 : warning_at (nloc, OPT_Wvarargs,
12063 : "undefined behavior when second parameter "
12064 : "of %<va_start%> is declared with "
12065 : "%<register%> storage");
12066 13453 : c_parser_consume_token (parser);
12067 : }
12068 : else
12069 : {
12070 26 : unsigned nesting_depth = 0;
12071 26 : location_t sloc = c_parser_peek_token (parser)->location;
12072 26 : location_t eloc = sloc;
12073 :
12074 : /* For va_start (ap,) the ) comes from stdarg.h.
12075 : Use location of , in that case, otherwise without
12076 : -Wsystem-headers nothing is reported. After all,
12077 : the problematic token is the comma in that case. */
12078 26 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
12079 1 : sloc = eloc = cloc;
12080 492 : while (true)
12081 : {
12082 259 : c_token *token = c_parser_peek_token (parser);
12083 259 : if (token->type == CPP_CLOSE_PAREN && !nesting_depth)
12084 : break;
12085 :
12086 233 : if (token->type == CPP_EOF)
12087 : break;
12088 233 : if (token->type == CPP_OPEN_PAREN)
12089 8 : ++nesting_depth;
12090 225 : else if (token->type == CPP_CLOSE_PAREN)
12091 8 : --nesting_depth;
12092 233 : eloc = token->location;
12093 233 : c_parser_consume_token (parser);
12094 233 : }
12095 26 : if (sloc != eloc)
12096 25 : sloc = make_location (sloc, sloc, eloc);
12097 26 : warning_at (sloc, OPT_Wvarargs,
12098 : "%<va_start%> macro used with additional "
12099 : "arguments other than identifier of the "
12100 : "last named argument");
12101 : }
12102 : }
12103 13657 : parens.skip_until_found_close (parser);
12104 13657 : tree fndecl = builtin_decl_explicit (BUILT_IN_VA_START);
12105 13657 : vec<tree, va_gc> *params;
12106 13657 : vec_alloc (params, 2);
12107 13657 : params->quick_push (e1.value);
12108 13657 : params->quick_push (integer_zero_node);
12109 13657 : auto_vec<location_t> arg_loc (2);
12110 13657 : arg_loc.quick_push (e1.get_location ());
12111 13657 : arg_loc.quick_push (UNKNOWN_LOCATION);
12112 13657 : expr.value = c_build_function_call_vec (loc, arg_loc, fndecl,
12113 : params, NULL);
12114 13657 : set_c_expr_source_range (&expr, loc,
12115 : parser->tokens_buf[0].get_finish ());
12116 13657 : expr.m_decimal = 0;
12117 13657 : expr.original_code = ERROR_MARK;
12118 13657 : expr.original_type = NULL;
12119 13657 : release_tree_vector (params);
12120 13657 : break;
12121 13657 : }
12122 3686 : case RID_OFFSETOF:
12123 3686 : {
12124 3686 : c_parser_consume_token (parser);
12125 3686 : matching_parens parens;
12126 3686 : if (!parens.require_open (parser))
12127 : {
12128 0 : expr.set_error ();
12129 1 : break;
12130 : }
12131 3686 : t1 = c_parser_type_name (parser);
12132 3686 : if (t1 == NULL)
12133 0 : parser->error = true;
12134 3686 : if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
12135 1 : gcc_assert (parser->error);
12136 3686 : if (parser->error)
12137 : {
12138 1 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
12139 1 : expr.set_error ();
12140 1 : break;
12141 : }
12142 3685 : tree type = groktypename (t1, NULL, NULL);
12143 3685 : tree offsetof_ref;
12144 3685 : if (type == error_mark_node)
12145 : offsetof_ref = error_mark_node;
12146 : else
12147 : {
12148 3684 : offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
12149 3684 : SET_EXPR_LOCATION (offsetof_ref, loc);
12150 : }
12151 : /* Parse the second argument to __builtin_offsetof. We
12152 : must have one identifier, and beyond that we want to
12153 : accept sub structure and sub array references. */
12154 3685 : if (c_parser_next_token_is (parser, CPP_NAME))
12155 : {
12156 3685 : c_token *comp_tok = c_parser_peek_token (parser);
12157 3685 : offsetof_ref
12158 3685 : = build_component_ref (loc, offsetof_ref, comp_tok->value,
12159 : comp_tok->location, UNKNOWN_LOCATION);
12160 3685 : c_parser_consume_token (parser);
12161 3685 : while (c_parser_next_token_is (parser, CPP_DOT)
12162 4155 : || c_parser_next_token_is (parser,
12163 : CPP_OPEN_SQUARE)
12164 8086 : || c_parser_next_token_is (parser,
12165 : CPP_DEREF))
12166 : {
12167 715 : if (c_parser_next_token_is (parser, CPP_DEREF))
12168 : {
12169 1 : loc = c_parser_peek_token (parser)->location;
12170 1 : offsetof_ref = build_array_ref (loc,
12171 : offsetof_ref,
12172 : integer_zero_node);
12173 1 : goto do_dot;
12174 : }
12175 714 : else if (c_parser_next_token_is (parser, CPP_DOT))
12176 : {
12177 245 : do_dot:
12178 246 : c_parser_consume_token (parser);
12179 246 : if (c_parser_next_token_is_not (parser,
12180 : CPP_NAME))
12181 : {
12182 0 : c_parser_error (parser, "expected identifier");
12183 0 : break;
12184 : }
12185 246 : c_token *comp_tok = c_parser_peek_token (parser);
12186 246 : offsetof_ref
12187 246 : = build_component_ref (loc, offsetof_ref,
12188 : comp_tok->value,
12189 : comp_tok->location,
12190 : UNKNOWN_LOCATION);
12191 246 : c_parser_consume_token (parser);
12192 : }
12193 : else
12194 : {
12195 469 : struct c_expr ce;
12196 469 : tree idx;
12197 469 : loc = c_parser_peek_token (parser)->location;
12198 469 : c_parser_consume_token (parser);
12199 469 : ce = c_parser_expression (parser);
12200 469 : ce = convert_lvalue_to_rvalue (loc, ce, false, false);
12201 469 : idx = ce.value;
12202 469 : idx = c_fully_fold (idx, false, NULL);
12203 469 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
12204 : "expected %<]%>");
12205 469 : offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
12206 : }
12207 : }
12208 : }
12209 : else
12210 0 : c_parser_error (parser, "expected identifier");
12211 3685 : location_t end_loc = c_parser_peek_token (parser)->get_finish ();
12212 3685 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12213 : "expected %<)%>");
12214 3685 : expr.value = fold_offsetof (offsetof_ref);
12215 3685 : set_c_expr_source_range (&expr, loc, end_loc);
12216 : }
12217 3685 : break;
12218 1171 : case RID_CHOOSE_EXPR:
12219 1171 : {
12220 1171 : vec<c_expr_t, va_gc> *cexpr_list;
12221 1171 : c_expr_t *e1_p, *e2_p, *e3_p;
12222 1171 : tree c;
12223 1171 : location_t close_paren_loc;
12224 :
12225 1171 : c_parser_consume_token (parser);
12226 1171 : if (!c_parser_get_builtin_args (parser,
12227 : "__builtin_choose_expr",
12228 : &cexpr_list, true,
12229 : &close_paren_loc))
12230 : {
12231 0 : expr.set_error ();
12232 0 : break;
12233 : }
12234 :
12235 1171 : if (vec_safe_length (cexpr_list) != 3)
12236 : {
12237 0 : error_at (loc, "wrong number of arguments to "
12238 : "%<__builtin_choose_expr%>");
12239 0 : expr.set_error ();
12240 0 : break;
12241 : }
12242 :
12243 1171 : e1_p = &(*cexpr_list)[0];
12244 1171 : e2_p = &(*cexpr_list)[1];
12245 1171 : e3_p = &(*cexpr_list)[2];
12246 :
12247 1171 : c = e1_p->value;
12248 1171 : mark_exp_read (e2_p->value);
12249 1171 : mark_exp_read (e3_p->value);
12250 1171 : if (TREE_CODE (c) != INTEGER_CST
12251 1171 : || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
12252 7 : error_at (loc,
12253 : "first argument to %<__builtin_choose_expr%> not"
12254 : " a constant");
12255 1171 : constant_expression_warning (c);
12256 1171 : expr = integer_zerop (c) ? *e3_p : *e2_p;
12257 1171 : set_c_expr_source_range (&expr, loc, close_paren_loc);
12258 1171 : break;
12259 : }
12260 675 : case RID_TYPES_COMPATIBLE_P:
12261 675 : {
12262 675 : c_parser_consume_token (parser);
12263 675 : matching_parens parens;
12264 675 : if (!parens.require_open (parser))
12265 : {
12266 0 : expr.set_error ();
12267 2 : break;
12268 : }
12269 675 : t1 = c_parser_type_name (parser);
12270 675 : if (t1 == NULL)
12271 : {
12272 0 : expr.set_error ();
12273 0 : break;
12274 : }
12275 675 : if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
12276 : {
12277 1 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
12278 1 : expr.set_error ();
12279 1 : break;
12280 : }
12281 674 : t2 = c_parser_type_name (parser);
12282 674 : if (t2 == NULL)
12283 : {
12284 0 : expr.set_error ();
12285 0 : break;
12286 : }
12287 674 : location_t close_paren_loc = c_parser_peek_token (parser)->location;
12288 674 : parens.skip_until_found_close (parser);
12289 674 : tree e1, e2;
12290 674 : e1 = groktypename (t1, NULL, NULL);
12291 674 : e2 = groktypename (t2, NULL, NULL);
12292 674 : if (e1 == error_mark_node || e2 == error_mark_node)
12293 : {
12294 1 : expr.set_error ();
12295 1 : break;
12296 : }
12297 :
12298 673 : e1 = TYPE_MAIN_VARIANT (e1);
12299 673 : e2 = TYPE_MAIN_VARIANT (e2);
12300 :
12301 673 : expr.value
12302 673 : = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
12303 673 : set_c_expr_source_range (&expr, loc, close_paren_loc);
12304 : }
12305 673 : break;
12306 356 : case RID_BUILTIN_TGMATH:
12307 356 : {
12308 356 : vec<c_expr_t, va_gc> *cexpr_list;
12309 356 : location_t close_paren_loc;
12310 :
12311 356 : c_parser_consume_token (parser);
12312 356 : if (!c_parser_get_builtin_args (parser,
12313 : "__builtin_tgmath",
12314 : &cexpr_list, false,
12315 : &close_paren_loc))
12316 : {
12317 0 : expr.set_error ();
12318 327 : break;
12319 : }
12320 :
12321 356 : if (vec_safe_length (cexpr_list) < 3)
12322 : {
12323 3 : error_at (loc, "too few arguments to %<__builtin_tgmath%>");
12324 3 : expr.set_error ();
12325 3 : break;
12326 : }
12327 :
12328 : unsigned int i;
12329 : c_expr_t *p;
12330 2587 : FOR_EACH_VEC_ELT (*cexpr_list, i, p)
12331 2234 : *p = convert_lvalue_to_rvalue (loc, *p, true, true);
12332 353 : unsigned int nargs = check_tgmath_function (&(*cexpr_list)[0], 1);
12333 353 : if (nargs == 0)
12334 : {
12335 4 : expr.set_error ();
12336 4 : break;
12337 : }
12338 698 : if (vec_safe_length (cexpr_list) < nargs)
12339 : {
12340 1 : error_at (loc, "too few arguments to %<__builtin_tgmath%>");
12341 1 : expr.set_error ();
12342 1 : break;
12343 : }
12344 348 : unsigned int num_functions = vec_safe_length (cexpr_list) - nargs;
12345 348 : if (num_functions < 2)
12346 : {
12347 1 : error_at (loc, "too few arguments to %<__builtin_tgmath%>");
12348 1 : expr.set_error ();
12349 1 : break;
12350 : }
12351 :
12352 : /* The first NUM_FUNCTIONS expressions are the function
12353 : pointers. The remaining NARGS expressions are the
12354 : arguments that are to be passed to one of those
12355 : functions, chosen following <tgmath.h> rules. */
12356 1744 : for (unsigned int j = 1; j < num_functions; j++)
12357 : {
12358 1402 : unsigned int this_nargs
12359 1402 : = check_tgmath_function (&(*cexpr_list)[j], j + 1);
12360 1402 : if (this_nargs == 0)
12361 : {
12362 4 : expr.set_error ();
12363 29 : goto out;
12364 : }
12365 1398 : if (this_nargs != nargs)
12366 : {
12367 1 : error_at ((*cexpr_list)[j].get_location (),
12368 : "argument %u of %<__builtin_tgmath%> has "
12369 : "wrong number of arguments", j + 1);
12370 1 : expr.set_error ();
12371 1 : goto out;
12372 : }
12373 : }
12374 :
12375 : /* The functions all have the same number of arguments.
12376 : Determine whether arguments and return types vary in
12377 : ways permitted for <tgmath.h> functions. */
12378 : /* The first entry in each of these vectors is for the
12379 : return type, subsequent entries for parameter
12380 : types. */
12381 342 : auto_vec<enum tgmath_parm_kind> parm_kind (nargs + 1);
12382 342 : auto_vec<tree> parm_first (nargs + 1);
12383 342 : auto_vec<bool> parm_complex (nargs + 1);
12384 342 : auto_vec<bool> parm_varies (nargs + 1);
12385 342 : tree first_type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[0].value));
12386 342 : tree first_ret = TYPE_MAIN_VARIANT (TREE_TYPE (first_type));
12387 342 : parm_first.quick_push (first_ret);
12388 342 : parm_complex.quick_push (TREE_CODE (first_ret) == COMPLEX_TYPE);
12389 342 : parm_varies.quick_push (false);
12390 342 : function_args_iterator iter;
12391 342 : tree t;
12392 342 : unsigned int argpos;
12393 802 : FOREACH_FUNCTION_ARGS (first_type, t, iter)
12394 : {
12395 802 : if (t == void_type_node)
12396 : break;
12397 460 : parm_first.quick_push (TYPE_MAIN_VARIANT (t));
12398 460 : parm_complex.quick_push (TREE_CODE (t) == COMPLEX_TYPE);
12399 460 : parm_varies.quick_push (false);
12400 : }
12401 1727 : for (unsigned int j = 1; j < num_functions; j++)
12402 : {
12403 1397 : tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
12404 1397 : tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type));
12405 1397 : if (ret != parm_first[0])
12406 : {
12407 1294 : parm_varies[0] = true;
12408 1294 : if (!SCALAR_FLOAT_TYPE_P (parm_first[0])
12409 1294 : && !COMPLEX_FLOAT_TYPE_P (parm_first[0]))
12410 : {
12411 3 : error_at ((*cexpr_list)[0].get_location (),
12412 : "invalid type-generic return type for "
12413 : "argument %u of %<__builtin_tgmath%>",
12414 : 1);
12415 3 : expr.set_error ();
12416 3 : goto out;
12417 : }
12418 1291 : if (!SCALAR_FLOAT_TYPE_P (ret)
12419 1291 : && !COMPLEX_FLOAT_TYPE_P (ret))
12420 : {
12421 3 : error_at ((*cexpr_list)[j].get_location (),
12422 : "invalid type-generic return type for "
12423 : "argument %u of %<__builtin_tgmath%>",
12424 : j + 1);
12425 3 : expr.set_error ();
12426 3 : goto out;
12427 : }
12428 : }
12429 1391 : if (TREE_CODE (ret) == COMPLEX_TYPE)
12430 342 : parm_complex[0] = true;
12431 1391 : argpos = 1;
12432 3329 : FOREACH_FUNCTION_ARGS (type, t, iter)
12433 : {
12434 3329 : if (t == void_type_node)
12435 : break;
12436 1944 : t = TYPE_MAIN_VARIANT (t);
12437 1944 : if (t != parm_first[argpos])
12438 : {
12439 1919 : parm_varies[argpos] = true;
12440 1919 : if (!SCALAR_FLOAT_TYPE_P (parm_first[argpos])
12441 1919 : && !COMPLEX_FLOAT_TYPE_P (parm_first[argpos]))
12442 : {
12443 3 : error_at ((*cexpr_list)[0].get_location (),
12444 : "invalid type-generic type for "
12445 : "argument %u of argument %u of "
12446 : "%<__builtin_tgmath%>", argpos, 1);
12447 3 : expr.set_error ();
12448 3 : goto out;
12449 : }
12450 1916 : if (!SCALAR_FLOAT_TYPE_P (t)
12451 1916 : && !COMPLEX_FLOAT_TYPE_P (t))
12452 : {
12453 3 : error_at ((*cexpr_list)[j].get_location (),
12454 : "invalid type-generic type for "
12455 : "argument %u of argument %u of "
12456 : "%<__builtin_tgmath%>", argpos, j + 1);
12457 3 : expr.set_error ();
12458 3 : goto out;
12459 : }
12460 : }
12461 1938 : if (TREE_CODE (t) == COMPLEX_TYPE)
12462 674 : parm_complex[argpos] = true;
12463 1938 : argpos++;
12464 : }
12465 : }
12466 : enum tgmath_parm_kind max_variation = tgmath_fixed;
12467 1108 : for (unsigned int j = 0; j <= nargs; j++)
12468 : {
12469 778 : enum tgmath_parm_kind this_kind;
12470 778 : if (parm_varies[j])
12471 : {
12472 731 : if (parm_complex[j])
12473 394 : max_variation = this_kind = tgmath_complex;
12474 : else
12475 : {
12476 337 : this_kind = tgmath_real;
12477 337 : if (max_variation != tgmath_complex)
12478 778 : max_variation = tgmath_real;
12479 : }
12480 : }
12481 : else
12482 47 : this_kind = tgmath_fixed;
12483 778 : parm_kind.quick_push (this_kind);
12484 : }
12485 330 : if (max_variation == tgmath_fixed)
12486 : {
12487 1 : error_at (loc, "function arguments of %<__builtin_tgmath%> "
12488 : "all have the same type");
12489 1 : expr.set_error ();
12490 1 : break;
12491 : }
12492 :
12493 : /* Identify a parameter (not the return type) that varies,
12494 : including with complex types if any variation includes
12495 : complex types; there must be at least one such
12496 : parameter. */
12497 341 : unsigned int tgarg = 0;
12498 341 : for (unsigned int j = 1; j <= nargs; j++)
12499 339 : if (parm_kind[j] == max_variation)
12500 : {
12501 : tgarg = j;
12502 : break;
12503 : }
12504 329 : if (tgarg == 0)
12505 : {
12506 2 : error_at (loc, "function arguments of %<__builtin_tgmath%> "
12507 : "lack type-generic parameter");
12508 2 : expr.set_error ();
12509 2 : break;
12510 : }
12511 :
12512 : /* Determine the type of the relevant parameter for each
12513 : function. */
12514 327 : auto_vec<tree> tg_type (num_functions);
12515 2362 : for (unsigned int j = 0; j < num_functions; j++)
12516 : {
12517 1708 : tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
12518 1708 : argpos = 1;
12519 1738 : FOREACH_FUNCTION_ARGS (type, t, iter)
12520 : {
12521 1738 : if (argpos == tgarg)
12522 : {
12523 1708 : tg_type.quick_push (TYPE_MAIN_VARIANT (t));
12524 1708 : break;
12525 : }
12526 30 : argpos++;
12527 : }
12528 : }
12529 :
12530 : /* Verify that the corresponding types are different for
12531 : all the listed functions. Also determine whether all
12532 : the types are complex, whether all the types are
12533 : standard or binary, and whether all the types are
12534 : decimal. */
12535 327 : bool all_complex = true;
12536 327 : bool all_binary = true;
12537 327 : bool all_decimal = true;
12538 327 : hash_set<tree> tg_types;
12539 2687 : FOR_EACH_VEC_ELT (tg_type, i, t)
12540 : {
12541 1708 : if (TREE_CODE (t) == COMPLEX_TYPE)
12542 : all_decimal = false;
12543 : else
12544 : {
12545 1186 : all_complex = false;
12546 1186 : if (DECIMAL_FLOAT_TYPE_P (t))
12547 : all_binary = false;
12548 : else
12549 : all_decimal = false;
12550 : }
12551 1708 : if (tg_types.add (t))
12552 : {
12553 1 : error_at ((*cexpr_list)[i].get_location (),
12554 : "duplicate type-generic parameter type for "
12555 : "function argument %u of %<__builtin_tgmath%>",
12556 : i + 1);
12557 1 : expr.set_error ();
12558 1 : goto out;
12559 : }
12560 : }
12561 :
12562 : /* Verify that other parameters and the return type whose
12563 : types vary have their types varying in the correct
12564 : way. */
12565 2029 : for (unsigned int j = 0; j < num_functions; j++)
12566 : {
12567 1705 : tree exp_type = tg_type[j];
12568 1705 : tree exp_real_type = exp_type;
12569 1705 : if (TREE_CODE (exp_type) == COMPLEX_TYPE)
12570 522 : exp_real_type = TREE_TYPE (exp_type);
12571 1705 : tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
12572 1705 : tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type));
12573 2606 : if ((parm_kind[0] == tgmath_complex && ret != exp_type)
12574 2606 : || (parm_kind[0] == tgmath_real && ret != exp_real_type))
12575 : {
12576 1 : error_at ((*cexpr_list)[j].get_location (),
12577 : "bad return type for function argument %u "
12578 : "of %<__builtin_tgmath%>", j + 1);
12579 1 : expr.set_error ();
12580 1 : goto out;
12581 : }
12582 1704 : argpos = 1;
12583 4078 : FOREACH_FUNCTION_ARGS (type, t, iter)
12584 : {
12585 4078 : if (t == void_type_node)
12586 : break;
12587 2375 : t = TYPE_MAIN_VARIANT (t);
12588 2375 : if ((parm_kind[argpos] == tgmath_complex
12589 1787 : && t != exp_type)
12590 4162 : || (parm_kind[argpos] == tgmath_real
12591 558 : && t != exp_real_type))
12592 : {
12593 1 : error_at ((*cexpr_list)[j].get_location (),
12594 : "bad type for argument %u of "
12595 : "function argument %u of "
12596 : "%<__builtin_tgmath%>", argpos, j + 1);
12597 1 : expr.set_error ();
12598 1 : goto out;
12599 : }
12600 2374 : argpos++;
12601 : }
12602 : }
12603 :
12604 : /* The functions listed are a valid set of functions for a
12605 : <tgmath.h> macro to select between. Identify the
12606 : matching function, if any. First, the argument types
12607 : must be combined following <tgmath.h> rules. Integer
12608 : types are treated as _Decimal64 if any type-generic
12609 : argument is decimal, or if the only alternatives for
12610 : type-generic arguments are of decimal types, and are
12611 : otherwise treated as _Float32x (or _Complex _Float32x
12612 : for complex integer types) if any type-generic argument
12613 : has _FloatNx type, otherwise as double (or _Complex
12614 : double for complex integer types). After that
12615 : adjustment, types are combined following the usual
12616 : arithmetic conversions. If the function only accepts
12617 : complex arguments, a complex type is produced. */
12618 : bool arg_complex = all_complex;
12619 : bool arg_binary = all_binary;
12620 : bool arg_int_decimal = all_decimal;
12621 : bool arg_int_floatnx = false;
12622 : bool arg_int_decimalx = false;
12623 756 : for (unsigned int j = 1; j <= nargs; j++)
12624 : {
12625 441 : if (parm_kind[j] == tgmath_fixed)
12626 10 : continue;
12627 431 : c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1];
12628 431 : tree type = TREE_TYPE (ce->value);
12629 431 : if (!INTEGRAL_TYPE_P (type)
12630 431 : && !SCALAR_FLOAT_TYPE_P (type)
12631 89 : && TREE_CODE (type) != COMPLEX_TYPE)
12632 : {
12633 1 : error_at (ce->get_location (),
12634 : "invalid type of argument %u of type-generic "
12635 : "function", j);
12636 1 : expr.set_error ();
12637 1 : goto out;
12638 : }
12639 430 : if (DECIMAL_FLOAT_TYPE_P (type))
12640 : {
12641 68 : arg_int_decimal = true;
12642 68 : if (all_complex)
12643 : {
12644 1 : error_at (ce->get_location (),
12645 : "decimal floating-point argument %u to "
12646 : "complex-only type-generic function", j);
12647 1 : expr.set_error ();
12648 1 : goto out;
12649 : }
12650 67 : else if (all_binary)
12651 : {
12652 1 : error_at (ce->get_location (),
12653 : "decimal floating-point argument %u to "
12654 : "binary-only type-generic function", j);
12655 1 : expr.set_error ();
12656 1 : goto out;
12657 : }
12658 66 : else if (arg_complex)
12659 : {
12660 1 : error_at (ce->get_location (),
12661 : "both complex and decimal floating-point "
12662 : "arguments to type-generic function");
12663 1 : expr.set_error ();
12664 1 : goto out;
12665 : }
12666 65 : else if (arg_binary)
12667 : {
12668 1 : error_at (ce->get_location (),
12669 : "both binary and decimal floating-point "
12670 : "arguments to type-generic function");
12671 1 : expr.set_error ();
12672 1 : goto out;
12673 : }
12674 : }
12675 362 : else if (TREE_CODE (type) == COMPLEX_TYPE)
12676 : {
12677 88 : arg_complex = true;
12678 88 : if (COMPLEX_FLOAT_TYPE_P (type))
12679 : arg_binary = true;
12680 88 : if (all_decimal)
12681 : {
12682 1 : error_at (ce->get_location (),
12683 : "complex argument %u to "
12684 : "decimal-only type-generic function", j);
12685 1 : expr.set_error ();
12686 1 : goto out;
12687 : }
12688 87 : else if (arg_int_decimal)
12689 : {
12690 1 : error_at (ce->get_location (),
12691 : "both complex and decimal floating-point "
12692 : "arguments to type-generic function");
12693 1 : expr.set_error ();
12694 1 : goto out;
12695 : }
12696 : }
12697 274 : else if (SCALAR_FLOAT_TYPE_P (type))
12698 : {
12699 180 : arg_binary = true;
12700 180 : if (all_decimal)
12701 : {
12702 1 : error_at (ce->get_location (),
12703 : "binary argument %u to "
12704 : "decimal-only type-generic function", j);
12705 1 : expr.set_error ();
12706 1 : goto out;
12707 : }
12708 179 : else if (arg_int_decimal)
12709 : {
12710 1 : error_at (ce->get_location (),
12711 : "both binary and decimal floating-point "
12712 : "arguments to type-generic function");
12713 1 : expr.set_error ();
12714 1 : goto out;
12715 : }
12716 : }
12717 422 : tree rtype = TYPE_MAIN_VARIANT (type);
12718 422 : if (TREE_CODE (rtype) == COMPLEX_TYPE)
12719 86 : rtype = TREE_TYPE (rtype);
12720 422 : if (SCALAR_FLOAT_TYPE_P (rtype))
12721 1208 : for (unsigned int j = 0; j < NUM_FLOATNX_TYPES; j++)
12722 908 : if (rtype == FLOATNX_TYPE_NODE (j))
12723 : {
12724 : arg_int_floatnx = true;
12725 : break;
12726 : }
12727 422 : if (rtype == dfloat64x_type_node)
12728 0 : arg_int_decimalx = true;
12729 : }
12730 : tree arg_real = NULL_TREE;
12731 743 : for (unsigned int j = 1; j <= nargs; j++)
12732 : {
12733 428 : if (parm_kind[j] == tgmath_fixed)
12734 10 : continue;
12735 418 : c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1];
12736 418 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (ce->value));
12737 418 : if (TREE_CODE (type) == COMPLEX_TYPE)
12738 85 : type = TREE_TYPE (type);
12739 418 : if (INTEGRAL_TYPE_P (type))
12740 114 : type = (arg_int_decimalx
12741 114 : ? dfloat64x_type_node
12742 : : arg_int_floatnx
12743 114 : ? float32x_type_node
12744 : : arg_int_decimal
12745 106 : ? dfloat64_type_node
12746 : : double_type_node);
12747 418 : if (arg_real == NULL_TREE)
12748 : arg_real = type;
12749 : else
12750 103 : arg_real = common_type (arg_real, type);
12751 418 : if (arg_real == error_mark_node)
12752 : {
12753 0 : expr.set_error ();
12754 0 : goto out;
12755 : }
12756 : }
12757 315 : tree arg_type = (arg_complex
12758 315 : ? build_complex_type (arg_real)
12759 : : arg_real);
12760 :
12761 : /* Look for a function to call with type-generic parameter
12762 : type ARG_TYPE. */
12763 315 : c_expr_t *fn = NULL;
12764 976 : for (unsigned int j = 0; j < num_functions; j++)
12765 : {
12766 970 : if (tg_type[j] == arg_type)
12767 : {
12768 309 : fn = &(*cexpr_list)[j];
12769 309 : break;
12770 : }
12771 : }
12772 315 : if (fn == NULL
12773 6 : && parm_kind[0] == tgmath_fixed
12774 4 : && SCALAR_FLOAT_TYPE_P (parm_first[0]))
12775 : {
12776 : /* Presume this is a macro that rounds its result to a
12777 : narrower type, and look for the first function with
12778 : at least the range and precision of the argument
12779 : type. */
12780 4 : for (unsigned int j = 0; j < num_functions; j++)
12781 : {
12782 8 : if (arg_complex
12783 4 : != (TREE_CODE (tg_type[j]) == COMPLEX_TYPE))
12784 0 : continue;
12785 4 : tree real_tg_type = (arg_complex
12786 4 : ? TREE_TYPE (tg_type[j])
12787 0 : : tg_type[j]);
12788 8 : if (DECIMAL_FLOAT_TYPE_P (arg_real)
12789 4 : != DECIMAL_FLOAT_TYPE_P (real_tg_type))
12790 0 : continue;
12791 4 : scalar_float_mode arg_mode
12792 4 : = SCALAR_FLOAT_TYPE_MODE (arg_real);
12793 4 : scalar_float_mode tg_mode
12794 4 : = SCALAR_FLOAT_TYPE_MODE (real_tg_type);
12795 4 : const real_format *arg_fmt = REAL_MODE_FORMAT (arg_mode);
12796 4 : const real_format *tg_fmt = REAL_MODE_FORMAT (tg_mode);
12797 4 : if (arg_fmt->b == tg_fmt->b
12798 4 : && arg_fmt->p <= tg_fmt->p
12799 4 : && arg_fmt->emax <= tg_fmt->emax
12800 4 : && (arg_fmt->emin - arg_fmt->p
12801 4 : >= tg_fmt->emin - tg_fmt->p))
12802 : {
12803 4 : fn = &(*cexpr_list)[j];
12804 4 : break;
12805 : }
12806 : }
12807 : }
12808 315 : if (fn == NULL)
12809 : {
12810 2 : error_at (loc, "no matching function for type-generic call");
12811 2 : expr.set_error ();
12812 2 : break;
12813 : }
12814 :
12815 : /* Construct a call to FN. */
12816 313 : vec<tree, va_gc> *args;
12817 313 : vec_alloc (args, nargs);
12818 313 : vec<tree, va_gc> *origtypes;
12819 313 : vec_alloc (origtypes, nargs);
12820 313 : auto_vec<location_t> arg_loc (nargs);
12821 1052 : for (unsigned int j = 0; j < nargs; j++)
12822 : {
12823 426 : c_expr_t *ce = &(*cexpr_list)[num_functions + j];
12824 426 : args->quick_push (ce->value);
12825 426 : arg_loc.quick_push (ce->get_location ());
12826 426 : origtypes->quick_push (ce->original_type);
12827 : }
12828 313 : expr.value = c_build_function_call_vec (loc, arg_loc, fn->value,
12829 : args, origtypes);
12830 313 : set_c_expr_source_range (&expr, loc, close_paren_loc);
12831 313 : break;
12832 982 : }
12833 23 : case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
12834 23 : {
12835 23 : vec<c_expr_t, va_gc> *cexpr_list;
12836 23 : c_expr_t *e2_p;
12837 23 : tree chain_value;
12838 23 : location_t close_paren_loc;
12839 :
12840 23 : c_parser_consume_token (parser);
12841 23 : if (!c_parser_get_builtin_args (parser,
12842 : "__builtin_call_with_static_chain",
12843 : &cexpr_list, false,
12844 : &close_paren_loc))
12845 : {
12846 0 : expr.set_error ();
12847 0 : break;
12848 : }
12849 23 : if (vec_safe_length (cexpr_list) != 2)
12850 : {
12851 0 : error_at (loc, "wrong number of arguments to "
12852 : "%<__builtin_call_with_static_chain%>");
12853 0 : expr.set_error ();
12854 0 : break;
12855 : }
12856 :
12857 23 : expr = (*cexpr_list)[0];
12858 23 : e2_p = &(*cexpr_list)[1];
12859 23 : *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
12860 23 : chain_value = e2_p->value;
12861 23 : mark_exp_read (chain_value);
12862 :
12863 23 : if (TREE_CODE (expr.value) != CALL_EXPR)
12864 3 : error_at (loc, "first argument to "
12865 : "%<__builtin_call_with_static_chain%> "
12866 : "must be a call expression");
12867 20 : else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
12868 1 : error_at (loc, "second argument to "
12869 : "%<__builtin_call_with_static_chain%> "
12870 : "must be a pointer type");
12871 : else
12872 19 : CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
12873 23 : set_c_expr_source_range (&expr, loc, close_paren_loc);
12874 23 : break;
12875 : }
12876 12078 : case RID_BUILTIN_COMPLEX:
12877 12078 : {
12878 12078 : vec<c_expr_t, va_gc> *cexpr_list;
12879 12078 : c_expr_t *e1_p, *e2_p;
12880 12078 : location_t close_paren_loc;
12881 :
12882 12078 : c_parser_consume_token (parser);
12883 12078 : if (!c_parser_get_builtin_args (parser,
12884 : "__builtin_complex",
12885 : &cexpr_list, false,
12886 : &close_paren_loc))
12887 : {
12888 1 : expr.set_error ();
12889 1 : break;
12890 : }
12891 :
12892 12077 : if (vec_safe_length (cexpr_list) != 2)
12893 : {
12894 2 : error_at (loc, "wrong number of arguments to "
12895 : "%<__builtin_complex%>");
12896 2 : expr.set_error ();
12897 2 : break;
12898 : }
12899 :
12900 12075 : e1_p = &(*cexpr_list)[0];
12901 12075 : e2_p = &(*cexpr_list)[1];
12902 :
12903 12075 : *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
12904 12075 : if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
12905 56 : e1_p->value = convert (TREE_TYPE (e1_p->value),
12906 56 : TREE_OPERAND (e1_p->value, 0));
12907 12075 : *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
12908 12075 : if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
12909 56 : e2_p->value = convert (TREE_TYPE (e2_p->value),
12910 56 : TREE_OPERAND (e2_p->value, 0));
12911 12075 : if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
12912 12074 : || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
12913 12073 : || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
12914 24147 : || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
12915 : {
12916 3 : error_at (loc, "%<__builtin_complex%> operand "
12917 : "not of real binary floating-point type");
12918 3 : expr.set_error ();
12919 3 : break;
12920 : }
12921 12072 : if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
12922 12072 : != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
12923 : {
12924 1 : error_at (loc,
12925 : "%<__builtin_complex%> operands of different types");
12926 1 : expr.set_error ();
12927 1 : break;
12928 : }
12929 12071 : pedwarn_c90 (loc, OPT_Wpedantic,
12930 : "ISO C90 does not support complex types");
12931 12071 : expr.value = build2_loc (loc, COMPLEX_EXPR,
12932 : build_complex_type
12933 12071 : (TYPE_MAIN_VARIANT
12934 : (TREE_TYPE (e1_p->value))),
12935 : e1_p->value, e2_p->value);
12936 12071 : set_c_expr_source_range (&expr, loc, close_paren_loc);
12937 12071 : break;
12938 : }
12939 88 : case RID_BUILTIN_COUNTED_BY_REF:
12940 88 : {
12941 88 : vec<c_expr_t, va_gc> *cexpr_list;
12942 88 : c_expr_t *e_p;
12943 88 : location_t close_paren_loc;
12944 :
12945 88 : c_parser_consume_token (parser);
12946 88 : if (!c_parser_get_builtin_args (parser,
12947 : "__builtin_counted_by_ref",
12948 : &cexpr_list, false,
12949 : &close_paren_loc))
12950 : {
12951 0 : expr.set_error ();
12952 0 : break;
12953 : }
12954 88 : if (vec_safe_length (cexpr_list) != 1)
12955 : {
12956 4 : error_at (loc, "wrong number of arguments to "
12957 : "%<__builtin_counted_by_ref%>");
12958 4 : expr.set_error ();
12959 4 : break;
12960 : }
12961 :
12962 84 : e_p = &(*cexpr_list)[0];
12963 84 : tree ref = e_p->value;
12964 :
12965 84 : if (TREE_CODE (TREE_TYPE (ref)) != ARRAY_TYPE
12966 84 : && TREE_CODE (TREE_TYPE (ref)) != POINTER_TYPE)
12967 : {
12968 2 : error_at (loc, "the argument to %<__builtin_counted_by_ref%>"
12969 : " must be an array or pointer");
12970 2 : expr.set_error ();
12971 2 : break;
12972 : }
12973 :
12974 82 : if (TREE_CODE (ref) != COMPONENT_REF)
12975 : {
12976 2 : error_at (loc, "the argument to %<__builtin_counted_by_ref%>"
12977 : " must be a field of a structure");
12978 2 : expr.set_error ();
12979 2 : break;
12980 : }
12981 :
12982 : /* If the ref is inside TYPEOF or ALIGNOF, the call to
12983 : .ACCESS_WITH_SIZE was not generated by the routine
12984 : build_component_ref by default, we should generate it here. */
12985 80 : if (TREE_CODE (ref) == COMPONENT_REF)
12986 80 : ref = handle_counted_by_for_component_ref (loc, ref);
12987 :
12988 80 : if (has_counted_by_object (ref))
12989 50 : expr.value = get_counted_by_ref (ref);
12990 : else
12991 30 : expr.value = null_pointer_node;
12992 :
12993 80 : set_c_expr_source_range (&expr, loc, close_paren_loc);
12994 80 : break;
12995 : }
12996 474941 : case RID_BUILTIN_SHUFFLE:
12997 474941 : {
12998 474941 : vec<c_expr_t, va_gc> *cexpr_list;
12999 474941 : unsigned int i;
13000 474941 : c_expr_t *p;
13001 474941 : location_t close_paren_loc;
13002 :
13003 474941 : c_parser_consume_token (parser);
13004 474941 : if (!c_parser_get_builtin_args (parser,
13005 : "__builtin_shuffle",
13006 : &cexpr_list, false,
13007 : &close_paren_loc))
13008 : {
13009 0 : expr.set_error ();
13010 0 : break;
13011 : }
13012 :
13013 1466451 : FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
13014 991510 : *p = convert_lvalue_to_rvalue (loc, *p, true, true);
13015 :
13016 474941 : if (vec_safe_length (cexpr_list) == 2)
13017 433313 : expr.value = c_build_vec_perm_expr (loc, (*cexpr_list)[0].value,
13018 : NULL_TREE,
13019 433313 : (*cexpr_list)[1].value);
13020 :
13021 41628 : else if (vec_safe_length (cexpr_list) == 3)
13022 41628 : expr.value = c_build_vec_perm_expr (loc, (*cexpr_list)[0].value,
13023 41628 : (*cexpr_list)[1].value,
13024 41628 : (*cexpr_list)[2].value);
13025 : else
13026 : {
13027 0 : error_at (loc, "wrong number of arguments to "
13028 : "%<__builtin_shuffle%>");
13029 0 : expr.set_error ();
13030 : }
13031 474941 : set_c_expr_source_range (&expr, loc, close_paren_loc);
13032 474941 : break;
13033 : }
13034 1090435 : case RID_BUILTIN_SHUFFLEVECTOR:
13035 1090435 : {
13036 1090435 : vec<c_expr_t, va_gc> *cexpr_list;
13037 1090435 : unsigned int i;
13038 1090435 : c_expr_t *p;
13039 1090435 : location_t close_paren_loc;
13040 :
13041 1090435 : c_parser_consume_token (parser);
13042 1090435 : if (!c_parser_get_builtin_args (parser,
13043 : "__builtin_shufflevector",
13044 : &cexpr_list, false,
13045 : &close_paren_loc))
13046 : {
13047 0 : expr.set_error ();
13048 0 : break;
13049 : }
13050 :
13051 16983509 : FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
13052 15893074 : *p = convert_lvalue_to_rvalue (loc, *p, true, true);
13053 :
13054 1090435 : if (vec_safe_length (cexpr_list) < 3)
13055 : {
13056 0 : error_at (loc, "wrong number of arguments to "
13057 : "%<__builtin_shuffle%>");
13058 0 : expr.set_error ();
13059 : }
13060 : else
13061 : {
13062 1090435 : auto_vec<tree, 16> mask;
13063 14802639 : for (i = 2; i < cexpr_list->length (); ++i)
13064 13712204 : mask.safe_push ((*cexpr_list)[i].value);
13065 1090435 : expr.value = c_build_shufflevector (loc, (*cexpr_list)[0].value,
13066 1090435 : (*cexpr_list)[1].value,
13067 : mask);
13068 1090435 : }
13069 1090435 : set_c_expr_source_range (&expr, loc, close_paren_loc);
13070 1090435 : break;
13071 : }
13072 444 : case RID_BUILTIN_CONVERTVECTOR:
13073 444 : {
13074 444 : location_t start_loc = loc;
13075 444 : c_parser_consume_token (parser);
13076 444 : matching_parens parens;
13077 444 : if (!parens.require_open (parser))
13078 : {
13079 0 : expr.set_error ();
13080 2 : break;
13081 : }
13082 444 : e1 = c_parser_expr_no_commas (parser, NULL);
13083 444 : mark_exp_read (e1.value);
13084 444 : if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
13085 : {
13086 2 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
13087 2 : expr.set_error ();
13088 2 : break;
13089 : }
13090 442 : loc = c_parser_peek_token (parser)->location;
13091 442 : t1 = c_parser_type_name (parser);
13092 442 : location_t end_loc = c_parser_peek_token (parser)->get_finish ();
13093 442 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13094 : "expected %<)%>");
13095 442 : if (t1 == NULL)
13096 1 : expr.set_error ();
13097 : else
13098 : {
13099 441 : tree type_expr = NULL_TREE;
13100 441 : expr.value = c_build_vec_convert (start_loc, e1.value, loc,
13101 : groktypename (t1, &type_expr,
13102 : NULL));
13103 441 : set_c_expr_source_range (&expr, start_loc, end_loc);
13104 : }
13105 : }
13106 442 : break;
13107 12 : case RID_BUILTIN_ASSOC_BARRIER:
13108 12 : {
13109 12 : location_t start_loc = loc;
13110 12 : c_parser_consume_token (parser);
13111 12 : matching_parens parens;
13112 12 : if (!parens.require_open (parser))
13113 : {
13114 0 : expr.set_error ();
13115 0 : break;
13116 : }
13117 12 : e1 = c_parser_expr_no_commas (parser, NULL);
13118 12 : mark_exp_read (e1.value);
13119 12 : location_t end_loc = c_parser_peek_token (parser)->get_finish ();
13120 12 : parens.skip_until_found_close (parser);
13121 12 : expr = parser_build_unary_op (loc, PAREN_EXPR, e1);
13122 12 : set_c_expr_source_range (&expr, start_loc, end_loc);
13123 : }
13124 12 : break;
13125 1077 : case RID_BUILTIN_STDC:
13126 1077 : {
13127 1077 : vec<c_expr_t, va_gc> *cexpr_list;
13128 1077 : c_expr_t *arg_p;
13129 1077 : location_t close_paren_loc;
13130 1077 : enum c_builtin_stdc {
13131 : C_BUILTIN_STDC_BIT_CEIL,
13132 : C_BUILTIN_STDC_BIT_FLOOR,
13133 : C_BUILTIN_STDC_BIT_WIDTH,
13134 : C_BUILTIN_STDC_COUNT_ONES,
13135 : C_BUILTIN_STDC_COUNT_ZEROS,
13136 : C_BUILTIN_STDC_FIRST_LEADING_ONE,
13137 : C_BUILTIN_STDC_FIRST_LEADING_ZERO,
13138 : C_BUILTIN_STDC_FIRST_TRAILING_ONE,
13139 : C_BUILTIN_STDC_FIRST_TRAILING_ZERO,
13140 : C_BUILTIN_STDC_HAS_SINGLE_BIT,
13141 : C_BUILTIN_STDC_LEADING_ONES,
13142 : C_BUILTIN_STDC_LEADING_ZEROS,
13143 : C_BUILTIN_STDC_ROTATE_LEFT,
13144 : C_BUILTIN_STDC_ROTATE_RIGHT,
13145 : C_BUILTIN_STDC_TRAILING_ONES,
13146 : C_BUILTIN_STDC_TRAILING_ZEROS,
13147 : C_BUILTIN_STDC_MAX
13148 1077 : } stdc_rid = C_BUILTIN_STDC_MAX;
13149 1077 : const char *name
13150 1077 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13151 1077 : unsigned num_args = 1;
13152 1077 : switch (name[sizeof ("__builtin_stdc_") - 1])
13153 : {
13154 203 : case 'b':
13155 203 : switch (name[sizeof ("__builtin_stdc_bit_") - 1])
13156 : {
13157 : case 'c':
13158 : stdc_rid = C_BUILTIN_STDC_BIT_CEIL;
13159 : break;
13160 64 : case 'f':
13161 64 : stdc_rid = C_BUILTIN_STDC_BIT_FLOOR;
13162 64 : break;
13163 : default:
13164 : stdc_rid = C_BUILTIN_STDC_BIT_WIDTH;
13165 : break;
13166 : }
13167 : break;
13168 106 : case 'c':
13169 106 : if (name[sizeof ("__builtin_stdc_count_") - 1] == 'o')
13170 : stdc_rid = C_BUILTIN_STDC_COUNT_ONES;
13171 : else
13172 53 : stdc_rid = C_BUILTIN_STDC_COUNT_ZEROS;
13173 : break;
13174 215 : case 'f':
13175 215 : switch (name[sizeof ("__builtin_stdc_first_trailing_") - 1])
13176 : {
13177 : case 'n':
13178 : stdc_rid = C_BUILTIN_STDC_FIRST_LEADING_ONE;
13179 : break;
13180 : case 'e':
13181 : stdc_rid = C_BUILTIN_STDC_FIRST_LEADING_ZERO;
13182 : break;
13183 : case 'o':
13184 : stdc_rid = C_BUILTIN_STDC_FIRST_TRAILING_ONE;
13185 : break;
13186 : default:
13187 : stdc_rid = C_BUILTIN_STDC_FIRST_TRAILING_ZERO;
13188 : break;
13189 : }
13190 : break;
13191 : case 'h':
13192 : stdc_rid = C_BUILTIN_STDC_HAS_SINGLE_BIT;
13193 : break;
13194 106 : case 'l':
13195 106 : if (name[sizeof ("__builtin_stdc_leading_") - 1] == 'o')
13196 : stdc_rid = C_BUILTIN_STDC_LEADING_ONES;
13197 : else
13198 53 : stdc_rid = C_BUILTIN_STDC_LEADING_ZEROS;
13199 : break;
13200 288 : case 'r':
13201 288 : if (name[sizeof ("__builtin_stdc_rotate_") - 1] == 'l')
13202 : stdc_rid = C_BUILTIN_STDC_ROTATE_LEFT;
13203 : else
13204 138 : stdc_rid = C_BUILTIN_STDC_ROTATE_RIGHT;
13205 : num_args = 2;
13206 : break;
13207 106 : case 't':
13208 106 : if (name[sizeof ("__builtin_stdc_trailing_") - 1] == 'o')
13209 : stdc_rid = C_BUILTIN_STDC_TRAILING_ONES;
13210 : else
13211 53 : stdc_rid = C_BUILTIN_STDC_TRAILING_ZEROS;
13212 : break;
13213 : }
13214 442 : gcc_checking_assert (stdc_rid != C_BUILTIN_STDC_MAX);
13215 :
13216 1077 : c_parser_consume_token (parser);
13217 1077 : if (!c_parser_get_builtin_args (parser, name,
13218 : &cexpr_list, false,
13219 : &close_paren_loc))
13220 : {
13221 0 : expr.set_error ();
13222 0 : break;
13223 : }
13224 :
13225 2138 : if (vec_safe_length (cexpr_list) != num_args)
13226 : {
13227 34 : error_at (loc, "wrong number of arguments to %qs", name);
13228 34 : expr.set_error ();
13229 34 : break;
13230 : }
13231 :
13232 1043 : arg_p = &(*cexpr_list)[0];
13233 1043 : *arg_p = convert_lvalue_to_rvalue (loc, *arg_p, true, true);
13234 1043 : if (!INTEGRAL_TYPE_P (TREE_TYPE (arg_p->value)))
13235 : {
13236 80 : error_at (loc, "%qs operand not an integral type", name);
13237 80 : expr.set_error ();
13238 80 : break;
13239 : }
13240 963 : if (TREE_CODE (TREE_TYPE (arg_p->value)) == ENUMERAL_TYPE)
13241 : {
13242 16 : error_at (loc, "argument %u in call to function "
13243 : "%qs has enumerated type", 1, name);
13244 16 : expr.set_error ();
13245 16 : break;
13246 : }
13247 947 : if (TREE_CODE (TREE_TYPE (arg_p->value)) == BOOLEAN_TYPE)
13248 : {
13249 16 : error_at (loc, "argument %u in call to function "
13250 : "%qs has boolean type", 1, name);
13251 16 : expr.set_error ();
13252 16 : break;
13253 : }
13254 931 : if (!TYPE_UNSIGNED (TREE_TYPE (arg_p->value)))
13255 : {
13256 16 : error_at (loc, "argument 1 in call to function "
13257 : "%qs has signed type", name);
13258 16 : expr.set_error ();
13259 16 : break;
13260 : }
13261 915 : if (TYPE_MAIN_VARIANT (TREE_TYPE (arg_p->value))
13262 915 : == char_type_node)
13263 : {
13264 16 : error_at (loc, "argument 1 in call to function "
13265 : "%qs has %<char%> type", name);
13266 16 : expr.set_error ();
13267 16 : break;
13268 : }
13269 899 : tree arg = arg_p->value;
13270 899 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg));
13271 : /* Expand:
13272 : __builtin_stdc_leading_zeros (arg) as
13273 : (unsigned int) __builtin_clzg (arg, prec)
13274 : __builtin_stdc_leading_ones (arg) as
13275 : (unsigned int) __builtin_clzg ((type) ~arg, prec)
13276 : __builtin_stdc_trailing_zeros (arg) as
13277 : (unsigned int) __builtin_ctzg (arg, prec)
13278 : __builtin_stdc_trailing_ones (arg) as
13279 : (unsigned int) __builtin_ctzg ((type) ~arg, prec)
13280 : __builtin_stdc_first_leading_zero (arg) as
13281 : __builtin_clzg ((type) ~arg, -1) + 1U
13282 : __builtin_stdc_first_leading_one (arg) as
13283 : __builtin_clzg (arg, -1) + 1U
13284 : __builtin_stdc_first_trailing_zero (arg) as
13285 : __builtin_ctzg ((type) ~arg, -1) + 1U
13286 : __builtin_stdc_first_trailing_one (arg) as
13287 : __builtin_ctzg (arg, -1) + 1U
13288 : __builtin_stdc_count_zeros (arg) as
13289 : (unsigned int) __builtin_popcountg ((type) ~arg)
13290 : __builtin_stdc_count_ones (arg) as
13291 : (unsigned int) __builtin_popcountg (arg)
13292 : __builtin_stdc_has_single_bit (arg) as
13293 : (_Bool) (__builtin_popcountg (arg) == 1)
13294 : __builtin_stdc_bit_width (arg) as
13295 : (unsigned int) (prec - __builtin_clzg (arg, prec))
13296 : __builtin_stdc_bit_floor (arg) as
13297 : arg == 0 ? (type) 0
13298 : : (type) 1 << (prec - 1 - __builtin_clzg (arg))
13299 : __builtin_stdc_bit_ceil (arg) as
13300 : arg <= 1 ? (type) 1
13301 : : (type) 2 << (prec - 1 - __builtin_clzg (arg - 1))
13302 : without evaluating arg multiple times, type being
13303 : __typeof (arg) and prec __builtin_popcountg ((type) ~0)). */
13304 899 : int prec = TYPE_PRECISION (type);
13305 899 : if (num_args == 2)
13306 : {
13307 : /* Expand:
13308 : __builtin_stdc_rotate_left (arg1, arg2) as
13309 : arg1 r<< (arg2 % prec)
13310 : __builtin_stdc_rotate_right (arg1, arg2) as
13311 : arg1 r>> (arg2 % prec). */
13312 264 : arg_p = &(*cexpr_list)[1];
13313 264 : *arg_p = convert_lvalue_to_rvalue (loc, *arg_p, true, true);
13314 264 : if (!INTEGRAL_TYPE_P (TREE_TYPE (arg_p->value)))
13315 : {
13316 10 : error_at (loc, "%qs operand not an integral type", name);
13317 10 : expr.set_error ();
13318 10 : break;
13319 : }
13320 254 : if (TREE_CODE (TREE_TYPE (arg_p->value)) == ENUMERAL_TYPE)
13321 : {
13322 2 : error_at (loc, "argument %u in call to function "
13323 : "%qs has enumerated type", 2, name);
13324 2 : expr.set_error ();
13325 2 : break;
13326 : }
13327 252 : tree arg1 = save_expr (arg);
13328 252 : tree arg2 = save_expr (arg_p->value);
13329 252 : tree_code code;
13330 252 : if (stdc_rid == C_BUILTIN_STDC_ROTATE_LEFT)
13331 : code = LROTATE_EXPR;
13332 : else
13333 120 : code = RROTATE_EXPR;
13334 :
13335 252 : if (TREE_CODE (arg2) == INTEGER_CST
13336 252 : && tree_int_cst_sgn (arg2) < 0)
13337 20 : warning_at (loc, OPT_Wshift_count_negative,
13338 : "rotate count is negative");
13339 :
13340 252 : tree instrument_expr = NULL_TREE;
13341 252 : if (sanitize_flags_p (SANITIZE_SHIFT))
13342 28 : instrument_expr = ubsan_instrument_shift (loc, code,
13343 : arg1, arg2);
13344 :
13345 : /* Promote arg2 to unsigned just so that we don't
13346 : need to deal with arg2 type not being able to represent
13347 : prec. In the end gimplification uses unsigned int
13348 : for all shifts/rotates anyway. */
13349 252 : if (TYPE_PRECISION (TREE_TYPE (arg2))
13350 252 : < TYPE_PRECISION (integer_type_node))
13351 13 : arg2 = fold_convert (unsigned_type_node, arg2);
13352 :
13353 252 : if (TYPE_UNSIGNED (TREE_TYPE (arg2)))
13354 26 : arg2 = build2_loc (loc, TRUNC_MOD_EXPR, TREE_TYPE (arg2),
13355 26 : arg2, build_int_cst (TREE_TYPE (arg2),
13356 26 : prec));
13357 : else
13358 : {
13359 : /* When second argument is signed, just do the modulo in
13360 : unsigned type, that results in better generated code
13361 : (for power of 2 precisions bitwise AND). */
13362 226 : tree utype = c_common_unsigned_type (TREE_TYPE (arg2));
13363 226 : arg2 = build2_loc (loc, TRUNC_MOD_EXPR, utype,
13364 : fold_convert (utype, arg2),
13365 226 : build_int_cst (utype, prec));
13366 : }
13367 :
13368 : /* The middle-end isn't prepared to handle {L,R}ROTATE_EXPR
13369 : on types without mode precision, except for large/huge
13370 : _BitInt types. */
13371 252 : if (type_has_mode_precision_p (TREE_TYPE (arg1))
13372 252 : || (TREE_CODE (TREE_TYPE (arg1)) == BITINT_TYPE
13373 154 : && prec > MAX_FIXED_MODE_SIZE))
13374 193 : expr.value = build2_loc (loc, code, TREE_TYPE (arg1), arg1,
13375 : arg2);
13376 : else
13377 : {
13378 59 : arg2 = save_expr (arg2);
13379 84 : tree t1 = build2_loc (loc, (code == LROTATE_EXPR
13380 : ? LSHIFT_EXPR : RSHIFT_EXPR),
13381 59 : TREE_TYPE (arg1), arg1, arg2);
13382 118 : tree t2 = build2_loc (loc, MINUS_EXPR,
13383 59 : TREE_TYPE (arg2),
13384 59 : build_int_cst (TREE_TYPE (arg2),
13385 59 : prec), arg2);
13386 84 : t2 = build2_loc (loc, (code == LROTATE_EXPR
13387 : ? RSHIFT_EXPR : LSHIFT_EXPR),
13388 59 : TREE_TYPE (arg1), arg1, t2);
13389 59 : suppress_warning (t2, OPT_Wshift_count_overflow);
13390 59 : tree t3 = build2_loc (loc, BIT_IOR_EXPR,
13391 59 : TREE_TYPE (arg1), t1, t2);
13392 59 : tree t4 = build2_loc (loc, NE_EXPR, boolean_type_node,
13393 : arg2,
13394 59 : build_zero_cst (TREE_TYPE (arg2)));
13395 59 : t4 = build2_loc (loc, COMPOUND_EXPR, boolean_type_node,
13396 : arg1, t4);
13397 59 : expr.value = build3_loc (loc, COND_EXPR,
13398 59 : TREE_TYPE (arg1), t4, t3, arg1);
13399 : }
13400 252 : if (instrument_expr)
13401 28 : expr.value = build2_loc (loc, COMPOUND_EXPR,
13402 28 : TREE_TYPE (expr.value),
13403 : instrument_expr, expr.value);
13404 252 : set_c_expr_source_range (&expr, loc, close_paren_loc);
13405 252 : break;
13406 : }
13407 635 : tree barg1 = arg;
13408 635 : switch (stdc_rid)
13409 : {
13410 70 : case C_BUILTIN_STDC_BIT_CEIL:
13411 70 : arg = save_expr (arg);
13412 70 : barg1 = build2_loc (loc, PLUS_EXPR, type, arg,
13413 : build_int_cst (type, -1));
13414 70 : break;
13415 53 : case C_BUILTIN_STDC_BIT_FLOOR:
13416 53 : barg1 = arg = save_expr (arg);
13417 53 : break;
13418 211 : case C_BUILTIN_STDC_COUNT_ZEROS:
13419 211 : case C_BUILTIN_STDC_FIRST_LEADING_ZERO:
13420 211 : case C_BUILTIN_STDC_FIRST_TRAILING_ZERO:
13421 211 : case C_BUILTIN_STDC_LEADING_ONES:
13422 211 : case C_BUILTIN_STDC_TRAILING_ONES:
13423 211 : barg1 = build1_loc (loc, BIT_NOT_EXPR, type, arg);
13424 211 : break;
13425 : default:
13426 : break;
13427 : }
13428 635 : tree barg2 = NULL_TREE;
13429 635 : switch (stdc_rid)
13430 : {
13431 215 : case C_BUILTIN_STDC_BIT_WIDTH:
13432 215 : case C_BUILTIN_STDC_LEADING_ONES:
13433 215 : case C_BUILTIN_STDC_LEADING_ZEROS:
13434 215 : case C_BUILTIN_STDC_TRAILING_ONES:
13435 215 : case C_BUILTIN_STDC_TRAILING_ZEROS:
13436 215 : barg2 = build_int_cst (integer_type_node, prec);
13437 215 : break;
13438 171 : case C_BUILTIN_STDC_FIRST_LEADING_ONE:
13439 171 : case C_BUILTIN_STDC_FIRST_LEADING_ZERO:
13440 171 : case C_BUILTIN_STDC_FIRST_TRAILING_ONE:
13441 171 : case C_BUILTIN_STDC_FIRST_TRAILING_ZERO:
13442 171 : barg2 = integer_minus_one_node;
13443 171 : break;
13444 : default:
13445 : break;
13446 : }
13447 635 : tree fndecl = NULL_TREE;
13448 635 : switch (stdc_rid)
13449 : {
13450 341 : case C_BUILTIN_STDC_BIT_CEIL:
13451 341 : case C_BUILTIN_STDC_BIT_FLOOR:
13452 341 : case C_BUILTIN_STDC_BIT_WIDTH:
13453 341 : case C_BUILTIN_STDC_FIRST_LEADING_ONE:
13454 341 : case C_BUILTIN_STDC_FIRST_LEADING_ZERO:
13455 341 : case C_BUILTIN_STDC_LEADING_ONES:
13456 341 : case C_BUILTIN_STDC_LEADING_ZEROS:
13457 341 : fndecl = builtin_decl_explicit (BUILT_IN_CLZG);
13458 341 : break;
13459 168 : case C_BUILTIN_STDC_FIRST_TRAILING_ONE:
13460 168 : case C_BUILTIN_STDC_FIRST_TRAILING_ZERO:
13461 168 : case C_BUILTIN_STDC_TRAILING_ONES:
13462 168 : case C_BUILTIN_STDC_TRAILING_ZEROS:
13463 168 : fndecl = builtin_decl_explicit (BUILT_IN_CTZG);
13464 168 : break;
13465 126 : case C_BUILTIN_STDC_COUNT_ONES:
13466 126 : case C_BUILTIN_STDC_COUNT_ZEROS:
13467 126 : case C_BUILTIN_STDC_HAS_SINGLE_BIT:
13468 126 : fndecl = builtin_decl_explicit (BUILT_IN_POPCOUNTG);
13469 126 : break;
13470 0 : default:
13471 0 : gcc_unreachable ();
13472 : }
13473 : /* Construct a call to __builtin_{clz,ctz,popcount}g. */
13474 635 : int nargs = barg2 != NULL_TREE ? 2 : 1;
13475 635 : vec<tree, va_gc> *args;
13476 635 : vec_alloc (args, nargs);
13477 635 : vec<tree, va_gc> *origtypes;
13478 635 : vec_alloc (origtypes, nargs);
13479 1270 : auto_vec<location_t> arg_loc (nargs);
13480 635 : args->quick_push (barg1);
13481 635 : arg_loc.quick_push (arg_p->get_location ());
13482 635 : origtypes->quick_push (arg_p->original_type);
13483 635 : if (nargs == 2)
13484 : {
13485 386 : args->quick_push (barg2);
13486 386 : arg_loc.quick_push (loc);
13487 386 : origtypes->quick_push (integer_type_node);
13488 : }
13489 635 : expr.value = c_build_function_call_vec (loc, arg_loc, fndecl,
13490 : args, origtypes);
13491 635 : set_c_expr_source_range (&expr, loc, close_paren_loc);
13492 635 : if (expr.value == error_mark_node)
13493 : break;
13494 635 : switch (stdc_rid)
13495 : {
13496 123 : case C_BUILTIN_STDC_BIT_CEIL:
13497 123 : case C_BUILTIN_STDC_BIT_FLOOR:
13498 123 : --prec;
13499 : /* FALLTHRU */
13500 170 : case C_BUILTIN_STDC_BIT_WIDTH:
13501 170 : expr.value = build2_loc (loc, MINUS_EXPR, integer_type_node,
13502 : build_int_cst (integer_type_node,
13503 170 : prec), expr.value);
13504 170 : break;
13505 171 : case C_BUILTIN_STDC_FIRST_LEADING_ONE:
13506 171 : case C_BUILTIN_STDC_FIRST_LEADING_ZERO:
13507 171 : case C_BUILTIN_STDC_FIRST_TRAILING_ONE:
13508 171 : case C_BUILTIN_STDC_FIRST_TRAILING_ZERO:
13509 171 : expr.value = build2_loc (loc, PLUS_EXPR, integer_type_node,
13510 : expr.value, integer_one_node);
13511 171 : break;
13512 42 : case C_BUILTIN_STDC_HAS_SINGLE_BIT:
13513 42 : expr.value = build2_loc (loc, EQ_EXPR, boolean_type_node,
13514 : expr.value, integer_one_node);
13515 42 : break;
13516 : default:
13517 : break;
13518 : }
13519 :
13520 383 : if (stdc_rid != C_BUILTIN_STDC_BIT_CEIL
13521 : && stdc_rid != C_BUILTIN_STDC_BIT_FLOOR)
13522 : {
13523 512 : if (stdc_rid != C_BUILTIN_STDC_HAS_SINGLE_BIT)
13524 470 : expr.value = fold_convert_loc (loc, unsigned_type_node,
13525 : expr.value);
13526 : break;
13527 : }
13528 : /* For __builtin_stdc_bit_ceil (0U) or __builtin_stdc_bit_ceil (1U)
13529 : or __builtin_stdc_bit_floor (0U) avoid bogus -Wshift-count-*
13530 : warnings. The LSHIFT_EXPR is in dead code in that case. */
13531 123 : if (integer_zerop (arg)
13532 123 : || (stdc_rid == C_BUILTIN_STDC_BIT_CEIL && integer_onep (arg)))
13533 42 : expr.value = build_int_cst (type, 0);
13534 : else
13535 81 : expr.value
13536 81 : = build2_loc (loc, LSHIFT_EXPR, type,
13537 : build_int_cst (type,
13538 : (stdc_rid
13539 : == C_BUILTIN_STDC_BIT_CEIL
13540 115 : ? 2 : 1)), expr.value);
13541 123 : if (stdc_rid == C_BUILTIN_STDC_BIT_CEIL)
13542 70 : expr.value = build3_loc (loc, COND_EXPR, type,
13543 : build2_loc (loc, LE_EXPR,
13544 : boolean_type_node, arg,
13545 : build_int_cst (type, 1)),
13546 : build_int_cst (type, 1),
13547 : expr.value);
13548 : else
13549 53 : expr.value = build3_loc (loc, COND_EXPR, type,
13550 : build2_loc (loc, EQ_EXPR,
13551 : boolean_type_node, arg,
13552 : build_int_cst (type, 0)),
13553 : build_int_cst (type, 0),
13554 : expr.value);
13555 : break;
13556 : }
13557 332 : case RID_BUILTIN_BSWAPG:
13558 332 : case RID_BUILTIN_BITREVERSEG:
13559 332 : case RID_BUILTIN_CLMULG:
13560 332 : {
13561 332 : vec<c_expr_t, va_gc> *cexpr_list;
13562 332 : location_t close_paren_loc;
13563 332 : internal_fn ifn;
13564 332 : const char *name;
13565 332 : switch (c_parser_peek_token (parser)->keyword)
13566 : {
13567 : case RID_BUILTIN_BSWAPG:
13568 : ifn = IFN_BSWAP;
13569 : name = "__builtin_bswapg";
13570 : break;
13571 68 : case RID_BUILTIN_BITREVERSEG:
13572 68 : ifn = IFN_BITREVERSE;
13573 68 : name = "__builtin_bitreverseg";
13574 68 : break;
13575 215 : case RID_BUILTIN_CLMULG:
13576 215 : ifn = IFN_CLMUL;
13577 215 : name = "__builtin_clmulg";
13578 215 : break;
13579 0 : default:
13580 0 : gcc_unreachable ();
13581 : }
13582 :
13583 332 : c_parser_consume_token (parser);
13584 332 : if (!c_parser_get_builtin_args (parser, name, &cexpr_list, false,
13585 : &close_paren_loc))
13586 : {
13587 0 : expr.set_error ();
13588 0 : break;
13589 : }
13590 :
13591 332 : const unsigned nargs = vec_safe_length (cexpr_list);
13592 449 : if (nargs < (ifn == IFN_CLMUL ? 2 : 1)
13593 439 : || nargs > (ifn == IFN_CLMUL ? 3 : 1))
13594 : {
13595 9 : error_at (loc, "wrong number of arguments to %qs", name);
13596 9 : expr.set_error ();
13597 9 : break;
13598 : }
13599 :
13600 323 : c_expr_t *arg_p = &(*cexpr_list)[0];
13601 323 : *arg_p = convert_lvalue_to_rvalue (loc, *arg_p, true, true);
13602 323 : tree arg = arg_p->value;
13603 323 : if (error_operand_p (arg))
13604 : {
13605 2 : expr.set_error ();
13606 2 : break;
13607 : }
13608 321 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg));
13609 321 : if (!INTEGRAL_TYPE_P (type))
13610 : {
13611 12 : error_at (arg_p->get_location (),
13612 : "%qs operand not an integral type", name);
13613 12 : expr.set_error ();
13614 12 : break;
13615 : }
13616 309 : if (TREE_CODE (type) == ENUMERAL_TYPE)
13617 : {
13618 15 : error_at (arg_p->get_location (),
13619 : "argument %u in call to function "
13620 : "%qs has enumerated type", 1, name);
13621 15 : expr.set_error ();
13622 15 : break;
13623 : }
13624 294 : if (TREE_CODE (type) == BOOLEAN_TYPE)
13625 : {
13626 4 : error_at (arg_p->get_location (),
13627 : "argument %u in call to function "
13628 : "%qs has boolean type", 1, name);
13629 4 : expr.set_error ();
13630 4 : break;
13631 : }
13632 290 : if (!TYPE_UNSIGNED (type))
13633 : {
13634 11 : error_at (arg_p->get_location (),
13635 : "argument 1 in call to function "
13636 : "%qs has signed type", name);
13637 11 : expr.set_error ();
13638 11 : break;
13639 : }
13640 279 : if (ifn == IFN_BSWAP && (TYPE_PRECISION (type) % 8) != 0)
13641 : {
13642 5 : error_at (arg_p->get_location (),
13643 : "precision %d of argument 1 to function "
13644 : "%qs is not a multiple of 8",
13645 5 : TYPE_PRECISION (type), name);
13646 5 : expr.set_error ();
13647 5 : break;
13648 : }
13649 274 : arg = c_fully_fold (arg, false, NULL);
13650 274 : if (ifn == IFN_CLMUL)
13651 : {
13652 196 : arg_p = &(*cexpr_list)[1];
13653 196 : *arg_p = convert_lvalue_to_rvalue (loc, *arg_p, true, true);
13654 196 : tree arg2 = arg_p->value;
13655 196 : if (error_operand_p (arg2))
13656 : {
13657 0 : expr.set_error ();
13658 0 : break;
13659 : }
13660 196 : if (!comptypes_same_p (type,
13661 196 : TYPE_MAIN_VARIANT (TREE_TYPE (arg2))))
13662 : {
13663 8 : error_at (loc, "arguments 1 and 2 to function %qs "
13664 : "have different types %qT and %qT",
13665 : name, type,
13666 8 : TYPE_MAIN_VARIANT (TREE_TYPE (arg2)));
13667 8 : expr.set_error ();
13668 8 : break;
13669 : }
13670 188 : arg2 = c_fully_fold (arg2, false, NULL);
13671 188 : tree arg3 = NULL_TREE;
13672 188 : if (nargs == 3)
13673 : {
13674 63 : arg_p = &(*cexpr_list)[2];
13675 63 : *arg_p = convert_lvalue_to_rvalue (loc, *arg_p,
13676 : true, true);
13677 63 : arg3 = arg_p->value;
13678 63 : if (error_operand_p (arg3))
13679 : {
13680 0 : expr.set_error ();
13681 0 : break;
13682 : }
13683 63 : if (!POINTER_TYPE_P (TREE_TYPE (arg3)))
13684 : {
13685 1 : error_at (arg_p->get_location (),
13686 : "argument 3 to function %qs does not have "
13687 : "pointer type", name);
13688 1 : expr.set_error ();
13689 1 : break;
13690 : }
13691 62 : tree htype = TREE_TYPE (TREE_TYPE (arg3));
13692 62 : if (!comptypes_same_p (type, TYPE_MAIN_VARIANT (htype)))
13693 : {
13694 1 : error_at (loc, "arguments 1 and 3 to function %qs "
13695 : "have incompatible types %qT and %qT",
13696 1 : name, type, TREE_TYPE (arg3));
13697 1 : expr.set_error ();
13698 1 : break;
13699 : }
13700 61 : if (TYPE_READONLY (htype))
13701 : {
13702 1 : error_at (arg_p->get_location (),
13703 : "argument 3 to function %qs has pointer to "
13704 : "%qs type %qT",
13705 1 : name, "const", TREE_TYPE (arg3));
13706 1 : expr.set_error ();
13707 1 : break;
13708 : }
13709 60 : if (TYPE_ATOMIC (htype))
13710 : {
13711 1 : error_at (arg_p->get_location (),
13712 : "argument 3 to function %qs "
13713 : "has pointer to %qs type %qT",
13714 1 : name, "_Atomic", TREE_TYPE (arg3));
13715 1 : expr.set_error ();
13716 1 : break;
13717 : }
13718 : }
13719 184 : expr.value = fold_build_builtin_clmulg (loc, arg, arg2, arg3);
13720 : }
13721 : else
13722 78 : expr.value = fold_build_builtin_bswapg_bitreverseg (loc, ifn,
13723 : arg);
13724 262 : set_c_expr_source_range (&expr, loc, close_paren_loc);
13725 262 : break;
13726 : }
13727 0 : case RID_AT_SELECTOR:
13728 0 : {
13729 0 : gcc_assert (c_dialect_objc ());
13730 0 : c_parser_consume_token (parser);
13731 0 : matching_parens parens;
13732 0 : if (!parens.require_open (parser))
13733 : {
13734 0 : expr.set_error ();
13735 0 : break;
13736 : }
13737 0 : tree sel = c_parser_objc_selector_arg (parser);
13738 0 : location_t close_loc = c_parser_peek_token (parser)->location;
13739 0 : parens.skip_until_found_close (parser);
13740 0 : expr.value = objc_build_selector_expr (loc, sel);
13741 0 : set_c_expr_source_range (&expr, loc, close_loc);
13742 : }
13743 0 : break;
13744 0 : case RID_AT_PROTOCOL:
13745 0 : {
13746 0 : gcc_assert (c_dialect_objc ());
13747 0 : c_parser_consume_token (parser);
13748 0 : matching_parens parens;
13749 0 : if (!parens.require_open (parser))
13750 : {
13751 0 : expr.set_error ();
13752 0 : break;
13753 : }
13754 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
13755 : {
13756 0 : c_parser_error (parser, "expected identifier");
13757 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
13758 0 : expr.set_error ();
13759 0 : break;
13760 : }
13761 0 : tree id = c_parser_peek_token (parser)->value;
13762 0 : c_parser_consume_token (parser);
13763 0 : location_t close_loc = c_parser_peek_token (parser)->location;
13764 0 : parens.skip_until_found_close (parser);
13765 0 : expr.value = objc_build_protocol_expr (id);
13766 0 : set_c_expr_source_range (&expr, loc, close_loc);
13767 : }
13768 0 : break;
13769 0 : case RID_AT_ENCODE:
13770 0 : {
13771 : /* Extension to support C-structures in the archiver. */
13772 0 : gcc_assert (c_dialect_objc ());
13773 0 : c_parser_consume_token (parser);
13774 0 : matching_parens parens;
13775 0 : if (!parens.require_open (parser))
13776 : {
13777 0 : expr.set_error ();
13778 0 : break;
13779 : }
13780 0 : t1 = c_parser_type_name (parser);
13781 0 : if (t1 == NULL)
13782 : {
13783 0 : expr.set_error ();
13784 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
13785 0 : break;
13786 : }
13787 0 : location_t close_loc = c_parser_peek_token (parser)->location;
13788 0 : parens.skip_until_found_close (parser);
13789 0 : tree type = groktypename (t1, NULL, NULL);
13790 0 : expr.value = objc_build_encode_expr (type);
13791 0 : set_c_expr_source_range (&expr, loc, close_loc);
13792 : }
13793 0 : break;
13794 1420 : case RID_GENERIC:
13795 1420 : expr = c_parser_generic_selection (parser);
13796 1420 : break;
13797 3 : case RID_OMP_ALL_MEMORY:
13798 3 : gcc_assert (flag_openmp);
13799 3 : c_parser_consume_token (parser);
13800 3 : error_at (loc, "%<omp_all_memory%> may only be used in OpenMP "
13801 : "%<depend%> clause");
13802 3 : expr.set_error ();
13803 3 : break;
13804 : /* C23 'nullptr' literal. */
13805 11157 : case RID_NULLPTR:
13806 11157 : c_parser_consume_token (parser);
13807 11157 : expr.value = nullptr_node;
13808 11157 : set_c_expr_source_range (&expr, tok_range);
13809 11157 : pedwarn_c11 (loc, OPT_Wpedantic,
13810 : "ISO C does not support %qs before C23", "nullptr");
13811 11157 : break;
13812 6801 : case RID_TRUE:
13813 6801 : c_parser_consume_token (parser);
13814 6801 : expr.value = boolean_true_node;
13815 6801 : set_c_expr_source_range (&expr, tok_range);
13816 6801 : break;
13817 6261 : case RID_FALSE:
13818 6261 : c_parser_consume_token (parser);
13819 6261 : expr.value = boolean_false_node;
13820 6261 : set_c_expr_source_range (&expr, tok_range);
13821 6261 : break;
13822 38 : default:
13823 38 : c_parser_error (parser, "expected expression");
13824 38 : expr.set_error ();
13825 38 : break;
13826 : }
13827 : break;
13828 2 : case CPP_OPEN_SQUARE:
13829 2 : if (c_dialect_objc ())
13830 : {
13831 0 : tree receiver, args;
13832 0 : c_parser_consume_token (parser);
13833 0 : receiver = c_parser_objc_receiver (parser);
13834 0 : args = c_parser_objc_message_args (parser);
13835 0 : location_t close_loc = c_parser_peek_token (parser)->location;
13836 0 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
13837 : "expected %<]%>");
13838 0 : expr.value = objc_build_message_expr (receiver, args);
13839 0 : set_c_expr_source_range (&expr, loc, close_loc);
13840 0 : break;
13841 : }
13842 : /* Else fall through to report error. */
13843 : /* FALLTHRU */
13844 793 : default:
13845 793 : c_parser_error (parser, "expected expression");
13846 793 : expr.set_error ();
13847 793 : break;
13848 : }
13849 244354070 : out:
13850 244354070 : return c_parser_postfix_expression_after_primary
13851 244354070 : (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr);
13852 : }
13853 :
13854 : /* Parse a postfix expression after a parenthesized type name: the
13855 : brace-enclosed initializer of a compound literal, possibly followed
13856 : by some postfix operators. This is separate because it is not
13857 : possible to tell until after the type name whether a cast
13858 : expression has a cast or a compound literal, or whether the operand
13859 : of sizeof is a parenthesized type name or starts with a compound
13860 : literal. TYPE_LOC is the location where TYPE_NAME starts--the
13861 : location of the first token after the parentheses around the type
13862 : name. */
13863 :
13864 : static struct c_expr
13865 929313 : c_parser_postfix_expression_after_paren_type (c_parser *parser,
13866 : struct c_declspecs *scspecs,
13867 : struct c_type_name *type_name,
13868 : location_t type_loc)
13869 : {
13870 929313 : tree type;
13871 929313 : struct c_expr init;
13872 929313 : bool non_const;
13873 929313 : struct c_expr expr;
13874 929313 : location_t start_loc;
13875 929313 : tree type_expr = NULL_TREE;
13876 929313 : bool type_expr_const = true;
13877 929313 : bool constexpr_p = scspecs ? scspecs->constexpr_p : false;
13878 929313 : unsigned int underspec_state = 0;
13879 929313 : check_compound_literal_type (type_loc, type_name);
13880 929313 : rich_location richloc (line_table, type_loc);
13881 929313 : start_loc = c_parser_peek_token (parser)->location;
13882 929313 : if (constexpr_p)
13883 : {
13884 234 : underspec_state = start_underspecified_init (start_loc, NULL_TREE);
13885 : /* A constexpr compound literal is subject to the constraints on
13886 : underspecified declarations, which may not declare tags or
13887 : members or structures or unions; it is undefined behavior to
13888 : declare the members of an enumeration. Where the structure,
13889 : union or enumeration type is declared within the compound
13890 : literal initializer, this is diagnosed elsewhere as a result
13891 : of the above call to start_underspecified_init. Diagnose
13892 : here the case of declaring such a type in the type specifiers
13893 : of the compound literal. */
13894 234 : switch (type_name->specs->typespec_kind)
13895 : {
13896 2 : case ctsk_tagfirstref:
13897 2 : case ctsk_tagfirstref_attrs:
13898 2 : error_at (type_loc, "%qT declared in %<constexpr%> compound literal",
13899 : type_name->specs->type);
13900 2 : break;
13901 :
13902 4 : case ctsk_tagdef:
13903 4 : error_at (type_loc, "%qT defined in %<constexpr%> compound literal",
13904 : type_name->specs->type);
13905 4 : break;
13906 :
13907 : default:
13908 : break;
13909 : }
13910 : }
13911 1858372 : start_init (NULL_TREE, NULL,
13912 929313 : (global_bindings_p ()
13913 929059 : || (scspecs && scspecs->storage_class == csc_static)
13914 : || constexpr_p), constexpr_p, &richloc);
13915 929313 : type = groktypename (type_name, &type_expr, &type_expr_const);
13916 929313 : bool varsize_p = false;
13917 929313 : if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
13918 : {
13919 16 : pedwarn (type_loc, OPT_Wpedantic, "compound literal has variable size");
13920 16 : varsize_p = true;
13921 : }
13922 929297 : else if (TREE_CODE (type) == FUNCTION_TYPE)
13923 : {
13924 3 : error_at (type_loc, "compound literal has function type");
13925 3 : type = error_mark_node;
13926 : }
13927 929313 : if (constexpr_p && type != error_mark_node)
13928 : {
13929 234 : tree type_no_array = strip_array_types (type);
13930 : /* The type of a constexpr object must not be variably modified
13931 : (which applies to all compound literals), volatile, atomic or
13932 : restrict qualified or have a member with such a qualifier.
13933 : const qualification is implicitly added. */
13934 234 : if (TYPE_QUALS (type_no_array)
13935 234 : .has (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
13936 9 : error_at (type_loc, "invalid qualifiers for %<constexpr%> object");
13937 225 : else if (RECORD_OR_UNION_TYPE_P (type_no_array)
13938 225 : && C_TYPE_FIELDS_NON_CONSTEXPR (type_no_array))
13939 8 : error_at (type_loc, "invalid qualifiers for field of "
13940 : "%<constexpr%> object");
13941 234 : type = c_build_qualified_type (type,
13942 234 : (TYPE_QUALS (type_no_array)
13943 : | TYPE_QUAL_CONST));
13944 : }
13945 929313 : init = c_parser_braced_init (parser, type, false, NULL, varsize_p);
13946 929313 : if (constexpr_p)
13947 234 : finish_underspecified_init (NULL_TREE, underspec_state);
13948 929313 : finish_init ();
13949 929313 : maybe_warn_string_init (type_loc, type, init);
13950 :
13951 929313 : if (type != error_mark_node
13952 929306 : && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
13953 929313 : && current_function_decl)
13954 : {
13955 0 : error ("compound literal qualified by address-space qualifier");
13956 0 : type = error_mark_node;
13957 : }
13958 :
13959 1858321 : if (!pedwarn_c90 (start_loc, OPT_Wpedantic,
13960 929313 : "ISO C90 forbids compound literals") && scspecs)
13961 305 : pedwarn_c11 (start_loc, OPT_Wpedantic,
13962 : "ISO C forbids storage class specifiers in compound literals "
13963 : "before C23");
13964 929313 : non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
13965 1858163 : ? CONSTRUCTOR_NON_CONST (init.value)
13966 463 : : init.original_code == C_MAYBE_CONST_EXPR);
13967 929313 : non_const |= !type_expr_const;
13968 929313 : unsigned int alignas_align = 0;
13969 929313 : if (type != error_mark_node
13970 929306 : && type_name->specs->align_log != -1)
13971 : {
13972 4 : alignas_align = 1U << type_name->specs->align_log;
13973 4 : if (alignas_align < min_align_of_type (type))
13974 : {
13975 1 : error_at (type_name->specs->locations[cdw_alignas],
13976 : "%<_Alignas%> specifiers cannot reduce "
13977 : "alignment of compound literal");
13978 1 : alignas_align = 0;
13979 : }
13980 : }
13981 929313 : expr.value = build_compound_literal (start_loc, type, init.value, non_const,
13982 : alignas_align, scspecs);
13983 929313 : set_c_expr_source_range (&expr, init.src_range);
13984 929313 : expr.m_decimal = 0;
13985 929313 : expr.original_code = ERROR_MARK;
13986 929313 : expr.original_type = NULL;
13987 929313 : if (type != error_mark_node
13988 929306 : && expr.value != error_mark_node
13989 929234 : && type_expr)
13990 : {
13991 41 : if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
13992 : {
13993 19 : gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
13994 19 : C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
13995 : }
13996 : else
13997 : {
13998 22 : gcc_assert (!non_const);
13999 22 : expr.value = build2 (C_MAYBE_CONST_EXPR, type,
14000 : type_expr, expr.value);
14001 : }
14002 : }
14003 929313 : return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
14004 929313 : }
14005 :
14006 : /* Callback function for sizeof_pointer_memaccess_warning to compare
14007 : types. */
14008 :
14009 : static bool
14010 3472 : sizeof_ptr_memacc_comptypes (tree type1, tree type2)
14011 : {
14012 3472 : return comptypes (type1, type2) == 1;
14013 : }
14014 :
14015 : /* Warn for patterns where abs-like function appears to be used incorrectly,
14016 : gracefully ignore any non-abs-like function. The warning location should
14017 : be LOC. FNDECL is the declaration of called function, it must be a
14018 : BUILT_IN_NORMAL function. ARG is the first and only argument of the
14019 : call. */
14020 :
14021 : static void
14022 58224 : warn_for_abs (location_t loc, tree fndecl, tree arg)
14023 : {
14024 : /* Avoid warning in unreachable subexpressions. */
14025 58224 : if (c_inhibit_evaluation_warnings)
14026 : return;
14027 :
14028 31886 : tree atype = TREE_TYPE (arg);
14029 :
14030 : /* Casts from pointers (and thus arrays and fndecls) will generate
14031 : -Wint-conversion warnings. Most other wrong types hopefully lead to type
14032 : mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P
14033 : types and possibly other exotic types. */
14034 31886 : if (!INTEGRAL_TYPE_P (atype)
14035 31886 : && !SCALAR_FLOAT_TYPE_P (atype)
14036 5256 : && TREE_CODE (atype) != COMPLEX_TYPE)
14037 : return;
14038 :
14039 27108 : enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
14040 :
14041 27108 : switch (fcode)
14042 : {
14043 39 : case BUILT_IN_ABS:
14044 39 : case BUILT_IN_LABS:
14045 39 : case BUILT_IN_LLABS:
14046 39 : case BUILT_IN_IMAXABS:
14047 39 : if (!INTEGRAL_TYPE_P (atype))
14048 : {
14049 4 : if (SCALAR_FLOAT_TYPE_P (atype))
14050 3 : warning_at (loc, OPT_Wabsolute_value,
14051 : "using integer absolute value function %qD when "
14052 : "argument is of floating-point type %qT",
14053 : fndecl, atype);
14054 1 : else if (TREE_CODE (atype) == COMPLEX_TYPE)
14055 1 : warning_at (loc, OPT_Wabsolute_value,
14056 : "using integer absolute value function %qD when "
14057 : "argument is of complex type %qT", fndecl, atype);
14058 : else
14059 : gcc_unreachable ();
14060 : return;
14061 : }
14062 35 : if (TYPE_UNSIGNED (atype))
14063 9 : warning_at (loc, OPT_Wabsolute_value,
14064 : "taking the absolute value of unsigned type %qT "
14065 : "has no effect", atype);
14066 : break;
14067 :
14068 572 : CASE_FLT_FN (BUILT_IN_FABS):
14069 572 : CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
14070 572 : if (!SCALAR_FLOAT_TYPE_P (atype)
14071 572 : || DECIMAL_FLOAT_MODE_P (TYPE_MODE (atype)))
14072 : {
14073 4 : if (INTEGRAL_TYPE_P (atype))
14074 2 : warning_at (loc, OPT_Wabsolute_value,
14075 : "using floating-point absolute value function %qD "
14076 : "when argument is of integer type %qT", fndecl, atype);
14077 2 : else if (DECIMAL_FLOAT_TYPE_P (atype))
14078 1 : warning_at (loc, OPT_Wabsolute_value,
14079 : "using floating-point absolute value function %qD "
14080 : "when argument is of decimal floating-point type %qT",
14081 : fndecl, atype);
14082 1 : else if (TREE_CODE (atype) == COMPLEX_TYPE)
14083 1 : warning_at (loc, OPT_Wabsolute_value,
14084 : "using floating-point absolute value function %qD when "
14085 : "argument is of complex type %qT", fndecl, atype);
14086 : else
14087 0 : gcc_unreachable ();
14088 : return;
14089 : }
14090 : break;
14091 :
14092 7 : CASE_FLT_FN (BUILT_IN_CABS):
14093 7 : if (TREE_CODE (atype) != COMPLEX_TYPE)
14094 : {
14095 4 : if (INTEGRAL_TYPE_P (atype))
14096 2 : warning_at (loc, OPT_Wabsolute_value,
14097 : "using complex absolute value function %qD when "
14098 : "argument is of integer type %qT", fndecl, atype);
14099 2 : else if (SCALAR_FLOAT_TYPE_P (atype))
14100 2 : warning_at (loc, OPT_Wabsolute_value,
14101 : "using complex absolute value function %qD when "
14102 : "argument is of floating-point type %qT",
14103 : fndecl, atype);
14104 : else
14105 : gcc_unreachable ();
14106 :
14107 : return;
14108 : }
14109 : break;
14110 :
14111 6 : case BUILT_IN_FABSD32:
14112 6 : case BUILT_IN_FABSD64:
14113 6 : case BUILT_IN_FABSD128:
14114 6 : case BUILT_IN_FABSD64X:
14115 6 : if (!DECIMAL_FLOAT_TYPE_P (atype))
14116 : {
14117 4 : if (INTEGRAL_TYPE_P (atype))
14118 1 : warning_at (loc, OPT_Wabsolute_value,
14119 : "using decimal floating-point absolute value "
14120 : "function %qD when argument is of integer type %qT",
14121 : fndecl, atype);
14122 3 : else if (SCALAR_FLOAT_TYPE_P (atype))
14123 2 : warning_at (loc, OPT_Wabsolute_value,
14124 : "using decimal floating-point absolute value "
14125 : "function %qD when argument is of floating-point "
14126 : "type %qT", fndecl, atype);
14127 1 : else if (TREE_CODE (atype) == COMPLEX_TYPE)
14128 1 : warning_at (loc, OPT_Wabsolute_value,
14129 : "using decimal floating-point absolute value "
14130 : "function %qD when argument is of complex type %qT",
14131 : fndecl, atype);
14132 : else
14133 0 : gcc_unreachable ();
14134 : return;
14135 : }
14136 : break;
14137 :
14138 : default:
14139 : return;
14140 : }
14141 :
14142 608 : if (!TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
14143 : return;
14144 :
14145 607 : tree ftype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
14146 607 : if (TREE_CODE (atype) == COMPLEX_TYPE)
14147 : {
14148 3 : gcc_assert (TREE_CODE (ftype) == COMPLEX_TYPE);
14149 3 : atype = TREE_TYPE (atype);
14150 3 : ftype = TREE_TYPE (ftype);
14151 : }
14152 :
14153 607 : if (TYPE_PRECISION (ftype) < TYPE_PRECISION (atype))
14154 9 : warning_at (loc, OPT_Wabsolute_value,
14155 : "absolute value function %qD given an argument of type %qT "
14156 : "but has parameter of type %qT which may cause truncation "
14157 : "of value", fndecl, atype, ftype);
14158 : }
14159 :
14160 :
14161 : /* Parse a postfix expression after the initial primary or compound
14162 : literal; that is, parse a series of postfix operators.
14163 :
14164 : EXPR_LOC is the location of the primary expression. */
14165 :
14166 : static struct c_expr
14167 245283433 : c_parser_postfix_expression_after_primary (c_parser *parser,
14168 : location_t expr_loc,
14169 : struct c_expr expr)
14170 : {
14171 245283433 : struct c_expr orig_expr;
14172 245283433 : tree ident, idx, len;
14173 245283433 : location_t sizeof_arg_loc[6], comp_loc;
14174 245283433 : tree sizeof_arg[6];
14175 245283433 : unsigned int literal_zero_mask;
14176 245283433 : unsigned int i;
14177 245283433 : vec<tree, va_gc> *exprlist;
14178 245283433 : vec<tree, va_gc> *origtypes = NULL;
14179 245283433 : vec<location_t> arg_loc = vNULL;
14180 303632358 : location_t start;
14181 303632358 : location_t finish;
14182 :
14183 303632358 : while (true)
14184 : {
14185 303632358 : location_t op_loc = c_parser_peek_token (parser)->location;
14186 303632358 : switch (c_parser_peek_token (parser)->type)
14187 : {
14188 3562353 : case CPP_OPEN_SQUARE:
14189 : /* Array reference. */
14190 3562353 : c_parser_consume_token (parser);
14191 3562353 : idx = len = NULL_TREE;
14192 3562353 : if (!c_omp_array_section_p
14193 3563093 : || c_parser_next_token_is_not (parser, CPP_COLON))
14194 3562156 : idx = c_parser_expression (parser).value;
14195 :
14196 3562353 : if (c_omp_array_section_p
14197 3563093 : && c_parser_next_token_is (parser, CPP_COLON))
14198 : {
14199 585 : c_parser_consume_token (parser);
14200 585 : if (c_parser_next_token_is_not (parser, CPP_CLOSE_SQUARE))
14201 550 : len = c_parser_expression (parser).value;
14202 :
14203 585 : expr.value = build_omp_array_section (op_loc, expr.value, idx,
14204 : len);
14205 : }
14206 : else
14207 3561768 : expr.value = build_array_ref (op_loc, expr.value, idx);
14208 :
14209 3562353 : c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
14210 : "expected %<]%>");
14211 :
14212 3562353 : start = expr.get_start ();
14213 3562353 : finish = parser->tokens_buf[0].location;
14214 3562353 : set_c_expr_source_range (&expr, start, finish);
14215 3562353 : expr.original_code = ERROR_MARK;
14216 3562353 : expr.original_type = NULL;
14217 3562353 : expr.m_decimal = 0;
14218 3562353 : break;
14219 51794053 : case CPP_OPEN_PAREN:
14220 : /* Function call. */
14221 51794053 : {
14222 51794053 : matching_parens parens;
14223 51794053 : parens.consume_open (parser);
14224 414352424 : for (i = 0; i < 6; i++)
14225 : {
14226 310764318 : sizeof_arg[i] = NULL_TREE;
14227 310764318 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
14228 : }
14229 51794053 : literal_zero_mask = 0;
14230 51794053 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
14231 : exprlist = NULL;
14232 39444521 : else if (TREE_CODE (expr.value) == FUNCTION_DECL
14233 39376858 : && fndecl_built_in_p (expr.value, BUILT_IN_CLASSIFY_TYPE)
14234 39446305 : && c_parser_next_tokens_start_typename (parser,
14235 : cla_prefer_id))
14236 : {
14237 : /* __builtin_classify_type (type) */
14238 29 : c_inhibit_evaluation_warnings++;
14239 29 : in_alignof++;
14240 29 : struct c_type_name *type = c_parser_type_name (parser);
14241 29 : c_inhibit_evaluation_warnings--;
14242 29 : in_alignof--;
14243 29 : struct c_typespec ret;
14244 29 : ret.expr = NULL_TREE;
14245 29 : ret.spec = error_mark_node;
14246 29 : ret.expr_const_operands = false;
14247 29 : if (type != NULL)
14248 29 : ret.spec = groktypename (type, &ret.expr,
14249 : &ret.expr_const_operands);
14250 29 : parens.skip_until_found_close (parser);
14251 29 : expr.value = build_int_cst (integer_type_node,
14252 29 : type_to_class (ret.spec));
14253 29 : break;
14254 : }
14255 : else
14256 39444492 : exprlist = c_parser_expr_list (parser, true, false, &origtypes,
14257 : sizeof_arg_loc, sizeof_arg,
14258 : &arg_loc, &literal_zero_mask);
14259 51794024 : parens.skip_until_found_close (parser);
14260 : }
14261 51794024 : orig_expr = expr;
14262 51794024 : mark_exp_read (expr.value);
14263 51794024 : if (warn_sizeof_pointer_memaccess)
14264 4684749 : sizeof_pointer_memaccess_warning (sizeof_arg_loc,
14265 : expr.value, exprlist,
14266 : sizeof_arg,
14267 : sizeof_ptr_memacc_comptypes);
14268 51794024 : if (TREE_CODE (expr.value) == FUNCTION_DECL)
14269 : {
14270 51716546 : if (fndecl_built_in_p (expr.value, BUILT_IN_MEMSET)
14271 51748463 : && vec_safe_length (exprlist) == 3)
14272 : {
14273 31917 : tree arg0 = (*exprlist)[0];
14274 31917 : tree arg2 = (*exprlist)[2];
14275 31917 : warn_for_memset (expr_loc, arg0, arg2, literal_zero_mask);
14276 : }
14277 51716546 : if (warn_absolute_value
14278 4399016 : && fndecl_built_in_p (expr.value, BUILT_IN_NORMAL)
14279 51860359 : && vec_safe_length (exprlist) == 1)
14280 58224 : warn_for_abs (expr_loc, expr.value, (*exprlist)[0]);
14281 51716546 : if (parser->omp_for_parse_state
14282 178 : && parser->omp_for_parse_state->in_intervening_code
14283 51716685 : && omp_runtime_api_call (expr.value))
14284 : {
14285 2 : error_at (expr_loc, "calls to the OpenMP runtime API are "
14286 : "not permitted in intervening code");
14287 2 : parser->omp_for_parse_state->fail = true;
14288 : }
14289 51716546 : if (warn_calloc_transposed_args)
14290 4398991 : if (tree attr = lookup_attribute ("alloc_size",
14291 4398991 : TYPE_ATTRIBUTES
14292 : (TREE_TYPE (expr.value))))
14293 1321 : if (TREE_VALUE (attr) && TREE_CHAIN (TREE_VALUE (attr)))
14294 146 : warn_for_calloc (sizeof_arg_loc, expr.value, exprlist,
14295 : sizeof_arg, attr);
14296 : }
14297 :
14298 51794024 : start = expr.get_start ();
14299 51794024 : finish = parser->tokens_buf[0].get_finish ();
14300 51794024 : expr.value
14301 51794024 : = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
14302 : exprlist, origtypes);
14303 51794024 : set_c_expr_source_range (&expr, start, finish);
14304 51794024 : expr.m_decimal = 0;
14305 :
14306 51794024 : expr.original_code = ERROR_MARK;
14307 51794024 : if (TREE_CODE (expr.value) == INTEGER_CST
14308 12792 : && TREE_CODE (orig_expr.value) == FUNCTION_DECL
14309 51806816 : && fndecl_built_in_p (orig_expr.value, BUILT_IN_CONSTANT_P))
14310 1563 : expr.original_code = C_MAYBE_CONST_EXPR;
14311 51794024 : expr.original_type = NULL;
14312 51794024 : if (exprlist)
14313 : {
14314 39444492 : release_tree_vector (exprlist);
14315 39444492 : release_tree_vector (origtypes);
14316 : }
14317 51794024 : arg_loc.release ();
14318 51794024 : break;
14319 1772915 : case CPP_DOT:
14320 : /* Structure element reference. */
14321 1772915 : c_parser_consume_token (parser);
14322 1772915 : expr = default_function_array_conversion (expr_loc, expr);
14323 1772915 : if (c_parser_next_token_is (parser, CPP_NAME))
14324 : {
14325 1772915 : c_token *comp_tok = c_parser_peek_token (parser);
14326 1772915 : ident = comp_tok->value;
14327 1772915 : comp_loc = comp_tok->location;
14328 : }
14329 : else
14330 : {
14331 0 : c_parser_error (parser, "expected identifier");
14332 0 : expr.set_error ();
14333 0 : expr.original_code = ERROR_MARK;
14334 0 : expr.original_type = NULL;
14335 0 : return expr;
14336 : }
14337 1772915 : start = expr.get_start ();
14338 1772915 : finish = c_parser_peek_token (parser)->get_finish ();
14339 1772915 : c_parser_consume_token (parser);
14340 1772915 : expr.value = build_component_ref (op_loc, expr.value, ident,
14341 : comp_loc, UNKNOWN_LOCATION);
14342 1772915 : set_c_expr_source_range (&expr, start, finish);
14343 1772915 : expr.original_code = ERROR_MARK;
14344 1772915 : if (TREE_CODE (expr.value) != COMPONENT_REF)
14345 32 : expr.original_type = NULL;
14346 : else
14347 : {
14348 : /* Remember the original type of a bitfield. */
14349 1772883 : tree field = TREE_OPERAND (expr.value, 1);
14350 1772883 : if (TREE_CODE (field) != FIELD_DECL)
14351 0 : expr.original_type = NULL;
14352 : else
14353 1772883 : expr.original_type = DECL_BIT_FIELD_TYPE (field);
14354 : }
14355 1772915 : expr.m_decimal = 0;
14356 1772915 : break;
14357 510044 : case CPP_DEREF:
14358 : /* Structure element reference. */
14359 510044 : c_parser_consume_token (parser);
14360 510044 : expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
14361 510044 : if (c_parser_next_token_is (parser, CPP_NAME))
14362 : {
14363 510012 : c_token *comp_tok = c_parser_peek_token (parser);
14364 510012 : ident = comp_tok->value;
14365 510012 : comp_loc = comp_tok->location;
14366 : }
14367 : else
14368 : {
14369 32 : c_parser_error (parser, "expected identifier");
14370 32 : expr.set_error ();
14371 32 : expr.original_code = ERROR_MARK;
14372 32 : expr.original_type = NULL;
14373 32 : return expr;
14374 : }
14375 510012 : start = expr.get_start ();
14376 510012 : finish = c_parser_peek_token (parser)->get_finish ();
14377 510012 : c_parser_consume_token (parser);
14378 510012 : expr.value = build_component_ref (op_loc,
14379 : build_indirect_ref (op_loc,
14380 : expr.value,
14381 : RO_ARROW),
14382 : ident, comp_loc,
14383 : expr.get_location ());
14384 510012 : set_c_expr_source_range (&expr, start, finish);
14385 510012 : expr.original_code = ERROR_MARK;
14386 510012 : if (TREE_CODE (expr.value) != COMPONENT_REF)
14387 121 : expr.original_type = NULL;
14388 : else
14389 : {
14390 : /* Remember the original type of a bitfield. */
14391 509891 : tree field = TREE_OPERAND (expr.value, 1);
14392 509891 : if (TREE_CODE (field) != FIELD_DECL)
14393 0 : expr.original_type = NULL;
14394 : else
14395 509891 : expr.original_type = DECL_BIT_FIELD_TYPE (field);
14396 : }
14397 510012 : expr.m_decimal = 0;
14398 510012 : break;
14399 691378 : case CPP_PLUS_PLUS:
14400 : /* Postincrement. */
14401 691378 : start = expr.get_start ();
14402 691378 : finish = c_parser_peek_token (parser)->get_finish ();
14403 691378 : c_parser_consume_token (parser);
14404 691378 : mark_exp_read_cond (expr.value);
14405 691378 : expr = default_function_array_conversion (expr_loc, expr);
14406 691378 : expr.value = build_unary_op (op_loc, POSTINCREMENT_EXPR,
14407 : expr.value, false);
14408 691378 : set_c_expr_source_range (&expr, start, finish);
14409 691378 : expr.original_code = ERROR_MARK;
14410 691378 : expr.original_type = NULL;
14411 691378 : break;
14412 18214 : case CPP_MINUS_MINUS:
14413 : /* Postdecrement. */
14414 18214 : start = expr.get_start ();
14415 18214 : finish = c_parser_peek_token (parser)->get_finish ();
14416 18214 : c_parser_consume_token (parser);
14417 18214 : mark_exp_read_cond (expr.value);
14418 18214 : expr = default_function_array_conversion (expr_loc, expr);
14419 18214 : expr.value = build_unary_op (op_loc, POSTDECREMENT_EXPR,
14420 : expr.value, false);
14421 18214 : set_c_expr_source_range (&expr, start, finish);
14422 18214 : expr.original_code = ERROR_MARK;
14423 18214 : expr.original_type = NULL;
14424 18214 : break;
14425 245283401 : default:
14426 245283401 : return expr;
14427 : }
14428 : }
14429 : }
14430 :
14431 : /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
14432 :
14433 : expression:
14434 : assignment-expression
14435 : expression , assignment-expression
14436 : */
14437 :
14438 : static struct c_expr
14439 57793320 : c_parser_expression (c_parser *parser)
14440 : {
14441 57793320 : location_t tloc = c_parser_peek_token (parser)->location;
14442 57793320 : struct c_expr expr;
14443 57793320 : expr = c_parser_expr_no_commas (parser, NULL);
14444 57793320 : if (c_parser_next_token_is (parser, CPP_COMMA))
14445 91557 : expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
14446 57898059 : while (c_parser_next_token_is (parser, CPP_COMMA))
14447 : {
14448 104739 : struct c_expr next;
14449 104739 : tree lhsval;
14450 104739 : location_t loc = c_parser_peek_token (parser)->location;
14451 104739 : location_t expr_loc;
14452 104739 : c_parser_consume_token (parser);
14453 104739 : expr_loc = c_parser_peek_token (parser)->location;
14454 104739 : lhsval = expr.value;
14455 104739 : while (TREE_CODE (lhsval) == COMPOUND_EXPR
14456 118777 : || TREE_CODE (lhsval) == NOP_EXPR)
14457 : {
14458 14038 : if (TREE_CODE (lhsval) == COMPOUND_EXPR)
14459 13940 : lhsval = TREE_OPERAND (lhsval, 1);
14460 : else
14461 98 : lhsval = TREE_OPERAND (lhsval, 0);
14462 : }
14463 104739 : if (DECL_P (lhsval) || handled_component_p (lhsval))
14464 89 : mark_exp_read (lhsval);
14465 104739 : if (c_parser_next_token_is (parser, CPP_EMBED))
14466 : {
14467 : /* Users aren't interested in millions of -Wunused-value
14468 : warnings when using #embed inside of a comma expression,
14469 : and one CPP_NUMBER plus CPP_COMMA before it and one
14470 : CPP_COMMA plus CPP_NUMBER after it is guaranteed by
14471 : the preprocessor. Thus, parse the whole CPP_EMBED just
14472 : as a single INTEGER_CST, the last byte in it. */
14473 1 : c_token *embed = c_parser_peek_token (parser);
14474 1 : tree val = embed->value;
14475 1 : unsigned last = RAW_DATA_LENGTH (val) - 1;
14476 1 : next.value = build_int_cst (TREE_TYPE (val),
14477 1 : RAW_DATA_UCHAR_ELT (val, last));
14478 1 : next.original_type = integer_type_node;
14479 1 : c_parser_consume_token (parser);
14480 : }
14481 : else
14482 : {
14483 104738 : next = c_parser_expr_no_commas (parser, NULL);
14484 104738 : next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
14485 : }
14486 104739 : expr.value = build_compound_expr (loc, expr.value, next.value);
14487 104739 : expr.original_code = COMPOUND_EXPR;
14488 104739 : expr.original_type = next.original_type;
14489 104739 : expr.m_decimal = 0;
14490 : }
14491 57793320 : return expr;
14492 : }
14493 :
14494 : /* Parse an expression and convert functions or arrays to pointers and
14495 : lvalues to rvalues. */
14496 :
14497 : static struct c_expr
14498 43941920 : c_parser_expression_conv (c_parser *parser)
14499 : {
14500 43941920 : struct c_expr expr;
14501 43941920 : location_t loc = c_parser_peek_token (parser)->location;
14502 43941920 : expr = c_parser_expression (parser);
14503 43941920 : expr = convert_lvalue_to_rvalue (loc, expr, true, false);
14504 43941920 : return expr;
14505 : }
14506 :
14507 : /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
14508 : argument is a literal zero alone and if so, set it in literal_zero_mask. */
14509 :
14510 : static inline void
14511 130468819 : c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
14512 : unsigned int idx)
14513 : {
14514 130468819 : if (idx >= HOST_BITS_PER_INT)
14515 : return;
14516 :
14517 130446136 : c_token *tok = c_parser_peek_token (parser);
14518 130446136 : switch (tok->type)
14519 : {
14520 6992718 : case CPP_NUMBER:
14521 6992718 : case CPP_CHAR:
14522 6992718 : case CPP_WCHAR:
14523 6992718 : case CPP_CHAR16:
14524 6992718 : case CPP_CHAR32:
14525 6992718 : case CPP_UTF8CHAR:
14526 : /* If a parameter is literal zero alone, remember it
14527 : for -Wmemset-transposed-args warning. */
14528 6992718 : if (integer_zerop (tok->value)
14529 1276108 : && !TREE_OVERFLOW (tok->value)
14530 8268826 : && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
14531 884420 : || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
14532 1275197 : *literal_zero_mask |= 1U << idx;
14533 : default:
14534 : break;
14535 : }
14536 : }
14537 :
14538 : /* Parse a non-empty list of expressions. If CONVERT_P, convert
14539 : functions and arrays to pointers and lvalues to rvalues. If
14540 : FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
14541 : locations of function arguments into this vector.
14542 :
14543 : nonempty-expr-list:
14544 : assignment-expression
14545 : nonempty-expr-list , assignment-expression
14546 : */
14547 :
14548 : static vec<tree, va_gc> *
14549 44131874 : c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
14550 : vec<tree, va_gc> **p_orig_types,
14551 : location_t *sizeof_arg_loc, tree *sizeof_arg,
14552 : vec<location_t> *locations,
14553 : unsigned int *literal_zero_mask)
14554 : {
14555 44131874 : vec<tree, va_gc> *ret;
14556 44131874 : vec<tree, va_gc> *orig_types;
14557 44131874 : struct c_expr expr;
14558 44131874 : unsigned int idx = 0;
14559 44131874 : bool save_c_omp_array_section_p = c_omp_array_section_p;
14560 44131874 : c_omp_array_section_p = false;
14561 :
14562 44131874 : ret = make_tree_vector ();
14563 44131874 : if (p_orig_types == NULL)
14564 : orig_types = NULL;
14565 : else
14566 39444492 : orig_types = make_tree_vector ();
14567 :
14568 44131874 : if (literal_zero_mask)
14569 39444492 : c_parser_check_literal_zero (parser, literal_zero_mask, 0);
14570 44131874 : expr = c_parser_expr_no_commas (parser, NULL);
14571 44131874 : if (convert_p)
14572 39444963 : expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true, true);
14573 44131874 : if (fold_p)
14574 4687382 : expr.value = c_fully_fold (expr.value, false, NULL);
14575 44131874 : ret->quick_push (expr.value);
14576 44131874 : if (orig_types)
14577 39444492 : orig_types->quick_push (expr.original_type);
14578 44131874 : if (locations)
14579 39444492 : locations->safe_push (expr.get_location ());
14580 44131874 : if (sizeof_arg != NULL
14581 39444492 : && (expr.original_code == SIZEOF_EXPR
14582 39444492 : || expr.original_code == PAREN_SIZEOF_EXPR))
14583 : {
14584 2344 : sizeof_arg[0] = c_last_sizeof_arg;
14585 2344 : sizeof_arg_loc[0] = c_last_sizeof_loc;
14586 : }
14587 136619051 : while (c_parser_next_token_is (parser, CPP_COMMA))
14588 : {
14589 92487177 : c_parser_consume_token (parser);
14590 92487177 : if (c_parser_next_token_is (parser, CPP_EMBED))
14591 : {
14592 3 : c_token *embed = c_parser_peek_token (parser);
14593 3 : tree value = embed->value;
14594 3 : expr.original_code = INTEGER_CST;
14595 3 : expr.original_type = integer_type_node;
14596 3 : expr.value = NULL_TREE;
14597 3 : set_c_expr_source_range (&expr, embed->get_range ());
14598 3 : expr.m_decimal = 0;
14599 381 : for (unsigned int i = 0; i < (unsigned) RAW_DATA_LENGTH (value); i++)
14600 : {
14601 378 : if (literal_zero_mask
14602 126 : && idx + 1 < HOST_BITS_PER_INT
14603 409 : && RAW_DATA_POINTER (value)[i] == 0)
14604 0 : *literal_zero_mask |= 1U << (idx + 1);
14605 378 : expr.value = build_int_cst (integer_type_node,
14606 378 : RAW_DATA_UCHAR_ELT (value, i));
14607 378 : vec_safe_push (ret, expr.value);
14608 378 : if (orig_types)
14609 126 : vec_safe_push (orig_types, expr.original_type);
14610 378 : if (locations)
14611 126 : locations->safe_push (expr.get_location ());
14612 378 : ++idx;
14613 : }
14614 3 : c_parser_consume_token (parser);
14615 3 : continue;
14616 3 : }
14617 92487174 : if (literal_zero_mask)
14618 91024327 : c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
14619 92487174 : expr = c_parser_expr_no_commas (parser, NULL);
14620 92487174 : if (convert_p)
14621 91024593 : expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true,
14622 : true);
14623 92487174 : if (fold_p)
14624 1462847 : expr.value = c_fully_fold (expr.value, false, NULL);
14625 92487174 : vec_safe_push (ret, expr.value);
14626 92487174 : if (orig_types)
14627 91024327 : vec_safe_push (orig_types, expr.original_type);
14628 92487174 : if (locations)
14629 91024327 : locations->safe_push (expr.get_location ());
14630 92487174 : if (++idx < 6
14631 90922847 : && sizeof_arg != NULL
14632 92487174 : && (expr.original_code == SIZEOF_EXPR
14633 89460014 : || expr.original_code == PAREN_SIZEOF_EXPR))
14634 : {
14635 79779 : sizeof_arg[idx] = c_last_sizeof_arg;
14636 79779 : sizeof_arg_loc[idx] = c_last_sizeof_loc;
14637 : }
14638 : }
14639 44131874 : if (orig_types)
14640 39444492 : *p_orig_types = orig_types;
14641 44131874 : c_omp_array_section_p = save_c_omp_array_section_p;
14642 44131874 : return ret;
14643 : }
14644 :
14645 : /* Parse Objective-C-specific constructs. */
14646 :
14647 : /* Parse an objc-class-definition.
14648 :
14649 : objc-class-definition:
14650 : @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
14651 : objc-class-instance-variables[opt] objc-methodprotolist @end
14652 : @implementation identifier objc-superclass[opt]
14653 : objc-class-instance-variables[opt]
14654 : @interface identifier ( identifier ) objc-protocol-refs[opt]
14655 : objc-methodprotolist @end
14656 : @interface identifier ( ) objc-protocol-refs[opt]
14657 : objc-methodprotolist @end
14658 : @implementation identifier ( identifier )
14659 :
14660 : objc-superclass:
14661 : : identifier
14662 :
14663 : "@interface identifier (" must start "@interface identifier (
14664 : identifier ) ...": objc-methodprotolist in the first production may
14665 : not start with a parenthesized identifier as a declarator of a data
14666 : definition with no declaration specifiers if the objc-superclass,
14667 : objc-protocol-refs and objc-class-instance-variables are omitted. */
14668 :
14669 : static void
14670 0 : c_parser_objc_class_definition (c_parser *parser, tree attributes)
14671 : {
14672 0 : bool iface_p;
14673 0 : tree id1;
14674 0 : tree superclass;
14675 0 : if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
14676 : iface_p = true;
14677 0 : else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
14678 : iface_p = false;
14679 : else
14680 0 : gcc_unreachable ();
14681 :
14682 0 : c_parser_consume_token (parser);
14683 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14684 : {
14685 0 : c_parser_error (parser, "expected identifier");
14686 0 : return;
14687 : }
14688 0 : id1 = c_parser_peek_token (parser)->value;
14689 0 : location_t loc1 = c_parser_peek_token (parser)->location;
14690 0 : c_parser_consume_token (parser);
14691 0 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14692 : {
14693 : /* We have a category or class extension. */
14694 0 : tree id2;
14695 0 : tree proto = NULL_TREE;
14696 0 : matching_parens parens;
14697 0 : parens.consume_open (parser);
14698 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14699 : {
14700 0 : if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
14701 : {
14702 : /* We have a class extension. */
14703 : id2 = NULL_TREE;
14704 : }
14705 : else
14706 : {
14707 0 : c_parser_error (parser, "expected identifier or %<)%>");
14708 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
14709 0 : return;
14710 : }
14711 : }
14712 : else
14713 : {
14714 0 : id2 = c_parser_peek_token (parser)->value;
14715 0 : c_parser_consume_token (parser);
14716 : }
14717 0 : parens.skip_until_found_close (parser);
14718 0 : if (!iface_p)
14719 : {
14720 0 : objc_start_category_implementation (id1, id2);
14721 0 : return;
14722 : }
14723 0 : if (c_parser_next_token_is (parser, CPP_LESS))
14724 0 : proto = c_parser_objc_protocol_refs (parser);
14725 0 : objc_start_category_interface (id1, id2, proto, attributes);
14726 0 : c_parser_objc_methodprotolist (parser);
14727 0 : c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
14728 0 : objc_finish_interface ();
14729 0 : return;
14730 : }
14731 0 : if (c_parser_next_token_is (parser, CPP_COLON))
14732 : {
14733 0 : c_parser_consume_token (parser);
14734 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14735 : {
14736 0 : c_parser_error (parser, "expected identifier");
14737 0 : return;
14738 : }
14739 0 : superclass = c_parser_peek_token (parser)->value;
14740 0 : c_parser_consume_token (parser);
14741 : }
14742 : else
14743 : superclass = NULL_TREE;
14744 0 : if (iface_p)
14745 : {
14746 0 : tree proto = NULL_TREE;
14747 0 : if (c_parser_next_token_is (parser, CPP_LESS))
14748 0 : proto = c_parser_objc_protocol_refs (parser);
14749 0 : objc_start_class_interface (id1, loc1, superclass, proto, attributes);
14750 : }
14751 : else
14752 0 : objc_start_class_implementation (id1, superclass);
14753 0 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
14754 0 : c_parser_objc_class_instance_variables (parser);
14755 0 : if (iface_p)
14756 : {
14757 0 : objc_continue_interface ();
14758 0 : c_parser_objc_methodprotolist (parser);
14759 0 : c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
14760 0 : objc_finish_interface ();
14761 : }
14762 : else
14763 : {
14764 0 : objc_continue_implementation ();
14765 0 : return;
14766 : }
14767 : }
14768 :
14769 : /* Parse objc-class-instance-variables.
14770 :
14771 : objc-class-instance-variables:
14772 : { objc-instance-variable-decl-list[opt] }
14773 :
14774 : objc-instance-variable-decl-list:
14775 : objc-visibility-spec
14776 : objc-instance-variable-decl ;
14777 : ;
14778 : objc-instance-variable-decl-list objc-visibility-spec
14779 : objc-instance-variable-decl-list objc-instance-variable-decl ;
14780 : objc-instance-variable-decl-list ;
14781 :
14782 : objc-visibility-spec:
14783 : @private
14784 : @protected
14785 : @public
14786 :
14787 : objc-instance-variable-decl:
14788 : struct-declaration
14789 : */
14790 :
14791 : static void
14792 0 : c_parser_objc_class_instance_variables (c_parser *parser)
14793 : {
14794 0 : gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
14795 0 : c_parser_consume_token (parser);
14796 0 : while (c_parser_next_token_is_not (parser, CPP_EOF))
14797 : {
14798 0 : tree decls;
14799 : /* Parse any stray semicolon. */
14800 0 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
14801 : {
14802 0 : pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
14803 : "extra semicolon");
14804 0 : c_parser_consume_token (parser);
14805 0 : continue;
14806 : }
14807 : /* Stop if at the end of the instance variables. */
14808 0 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
14809 : {
14810 0 : c_parser_consume_token (parser);
14811 0 : break;
14812 : }
14813 : /* Parse any objc-visibility-spec. */
14814 0 : if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
14815 : {
14816 0 : c_parser_consume_token (parser);
14817 0 : objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
14818 0 : continue;
14819 : }
14820 0 : else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
14821 : {
14822 0 : c_parser_consume_token (parser);
14823 0 : objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
14824 0 : continue;
14825 : }
14826 0 : else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
14827 : {
14828 0 : c_parser_consume_token (parser);
14829 0 : objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
14830 0 : continue;
14831 : }
14832 0 : else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
14833 : {
14834 0 : c_parser_consume_token (parser);
14835 0 : objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
14836 0 : continue;
14837 : }
14838 0 : else if (c_parser_next_token_is (parser, CPP_PRAGMA))
14839 : {
14840 0 : c_parser_pragma (parser, pragma_external, NULL, NULL_TREE);
14841 0 : continue;
14842 : }
14843 :
14844 : /* Parse some comma-separated declarations. */
14845 0 : decls = c_parser_struct_declaration (parser, NULL);
14846 0 : if (decls == NULL)
14847 : {
14848 : /* There is a syntax error. We want to skip the offending
14849 : tokens up to the next ';' (included) or '}'
14850 : (excluded). */
14851 :
14852 : /* First, skip manually a ')' or ']'. This is because they
14853 : reduce the nesting level, so c_parser_skip_until_found()
14854 : wouldn't be able to skip past them. */
14855 0 : c_token *token = c_parser_peek_token (parser);
14856 0 : if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
14857 0 : c_parser_consume_token (parser);
14858 :
14859 : /* Then, do the standard skipping. */
14860 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
14861 :
14862 : /* We hopefully recovered. Start normal parsing again. */
14863 0 : parser->error = false;
14864 0 : continue;
14865 0 : }
14866 : else
14867 : {
14868 : /* Comma-separated instance variables are chained together
14869 : in reverse order; add them one by one. */
14870 0 : tree ivar = nreverse (decls);
14871 0 : for (; ivar; ivar = DECL_CHAIN (ivar))
14872 0 : objc_add_instance_variable (copy_node (ivar));
14873 : }
14874 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14875 : }
14876 0 : }
14877 :
14878 : /* Parse an objc-class-declaration.
14879 :
14880 : objc-class-declaration:
14881 : @class identifier-list ;
14882 : */
14883 :
14884 : static void
14885 0 : c_parser_objc_class_declaration (c_parser *parser)
14886 : {
14887 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
14888 0 : c_parser_consume_token (parser);
14889 : /* Any identifiers, including those declared as type names, are OK
14890 : here. */
14891 0 : while (true)
14892 : {
14893 0 : tree id;
14894 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14895 : {
14896 0 : c_parser_error (parser, "expected identifier");
14897 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
14898 0 : parser->error = false;
14899 0 : return;
14900 : }
14901 0 : id = c_parser_peek_token (parser)->value;
14902 0 : objc_declare_class (id);
14903 0 : c_parser_consume_token (parser);
14904 0 : if (c_parser_next_token_is (parser, CPP_COMMA))
14905 0 : c_parser_consume_token (parser);
14906 : else
14907 : break;
14908 0 : }
14909 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14910 : }
14911 :
14912 : /* Parse an objc-alias-declaration.
14913 :
14914 : objc-alias-declaration:
14915 : @compatibility_alias identifier identifier ;
14916 : */
14917 :
14918 : static void
14919 0 : c_parser_objc_alias_declaration (c_parser *parser)
14920 : {
14921 0 : tree id1, id2;
14922 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
14923 0 : c_parser_consume_token (parser);
14924 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14925 : {
14926 0 : c_parser_error (parser, "expected identifier");
14927 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
14928 0 : return;
14929 : }
14930 0 : id1 = c_parser_peek_token (parser)->value;
14931 0 : c_parser_consume_token (parser);
14932 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14933 : {
14934 0 : c_parser_error (parser, "expected identifier");
14935 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
14936 0 : return;
14937 : }
14938 0 : id2 = c_parser_peek_token (parser)->value;
14939 0 : c_parser_consume_token (parser);
14940 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14941 0 : objc_declare_alias (id1, id2);
14942 : }
14943 :
14944 : /* Parse an objc-protocol-definition.
14945 :
14946 : objc-protocol-definition:
14947 : @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
14948 : @protocol identifier-list ;
14949 :
14950 : "@protocol identifier ;" should be resolved as "@protocol
14951 : identifier-list ;": objc-methodprotolist may not start with a
14952 : semicolon in the first alternative if objc-protocol-refs are
14953 : omitted. */
14954 :
14955 : static void
14956 0 : c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
14957 : {
14958 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
14959 :
14960 0 : c_parser_consume_token (parser);
14961 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14962 : {
14963 0 : c_parser_error (parser, "expected identifier");
14964 0 : return;
14965 : }
14966 0 : if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
14967 0 : || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
14968 : {
14969 : /* Any identifiers, including those declared as type names, are
14970 : OK here. */
14971 0 : while (true)
14972 : {
14973 0 : tree id;
14974 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
14975 : {
14976 0 : c_parser_error (parser, "expected identifier");
14977 0 : break;
14978 : }
14979 0 : id = c_parser_peek_token (parser)->value;
14980 0 : objc_declare_protocol (id, attributes);
14981 0 : c_parser_consume_token (parser);
14982 0 : if (c_parser_next_token_is (parser, CPP_COMMA))
14983 0 : c_parser_consume_token (parser);
14984 : else
14985 : break;
14986 0 : }
14987 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14988 : }
14989 : else
14990 : {
14991 0 : tree id = c_parser_peek_token (parser)->value;
14992 0 : tree proto = NULL_TREE;
14993 0 : c_parser_consume_token (parser);
14994 0 : if (c_parser_next_token_is (parser, CPP_LESS))
14995 0 : proto = c_parser_objc_protocol_refs (parser);
14996 0 : parser->objc_pq_context = true;
14997 0 : objc_start_protocol (id, proto, attributes);
14998 0 : c_parser_objc_methodprotolist (parser);
14999 0 : c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
15000 0 : parser->objc_pq_context = false;
15001 0 : objc_finish_interface ();
15002 : }
15003 : }
15004 :
15005 : /* Parse an objc-method-type.
15006 :
15007 : objc-method-type:
15008 : +
15009 : -
15010 :
15011 : Return true if it is a class method (+) and false if it is
15012 : an instance method (-).
15013 : */
15014 : static inline bool
15015 0 : c_parser_objc_method_type (c_parser *parser)
15016 : {
15017 0 : switch (c_parser_peek_token (parser)->type)
15018 : {
15019 0 : case CPP_PLUS:
15020 0 : c_parser_consume_token (parser);
15021 0 : return true;
15022 0 : case CPP_MINUS:
15023 0 : c_parser_consume_token (parser);
15024 0 : return false;
15025 0 : default:
15026 0 : gcc_unreachable ();
15027 : }
15028 : }
15029 :
15030 : /* Parse an objc-method-definition.
15031 :
15032 : objc-method-definition:
15033 : objc-method-type objc-method-decl ;[opt] compound-statement
15034 : */
15035 :
15036 : static void
15037 0 : c_parser_objc_method_definition (c_parser *parser)
15038 : {
15039 0 : bool is_class_method = c_parser_objc_method_type (parser);
15040 0 : tree decl, attributes = NULL_TREE, expr = NULL_TREE;
15041 0 : parser->objc_pq_context = true;
15042 0 : decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
15043 : &expr);
15044 0 : if (decl == error_mark_node)
15045 0 : return; /* Bail here. */
15046 :
15047 0 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
15048 : {
15049 0 : c_parser_consume_token (parser);
15050 0 : pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
15051 : "extra semicolon in method definition specified");
15052 : }
15053 :
15054 0 : if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
15055 : {
15056 0 : c_parser_error (parser, "expected %<{%>");
15057 0 : return;
15058 : }
15059 :
15060 0 : parser->objc_pq_context = false;
15061 0 : if (objc_start_method_definition (is_class_method, decl, attributes, expr))
15062 : {
15063 0 : add_stmt (c_parser_compound_statement (parser));
15064 0 : objc_finish_method_definition (current_function_decl);
15065 : }
15066 : else
15067 : {
15068 : /* This code is executed when we find a method definition
15069 : outside of an @implementation context (or invalid for other
15070 : reasons). Parse the method (to keep going) but do not emit
15071 : any code.
15072 : */
15073 0 : c_parser_compound_statement (parser);
15074 : }
15075 : }
15076 :
15077 : /* Parse an objc-methodprotolist.
15078 :
15079 : objc-methodprotolist:
15080 : empty
15081 : objc-methodprotolist objc-methodproto
15082 : objc-methodprotolist declaration
15083 : objc-methodprotolist ;
15084 : @optional
15085 : @required
15086 :
15087 : The declaration is a data definition, which may be missing
15088 : declaration specifiers under the same rules and diagnostics as
15089 : other data definitions outside functions, and the stray semicolon
15090 : is diagnosed the same way as a stray semicolon outside a
15091 : function. */
15092 :
15093 : static void
15094 0 : c_parser_objc_methodprotolist (c_parser *parser)
15095 : {
15096 0 : while (true)
15097 : {
15098 : /* The list is terminated by @end. */
15099 0 : switch (c_parser_peek_token (parser)->type)
15100 : {
15101 0 : case CPP_SEMICOLON:
15102 0 : pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
15103 : "ISO C does not allow extra %<;%> outside of a function");
15104 0 : c_parser_consume_token (parser);
15105 0 : break;
15106 0 : case CPP_PLUS:
15107 0 : case CPP_MINUS:
15108 0 : c_parser_objc_methodproto (parser);
15109 0 : break;
15110 0 : case CPP_PRAGMA:
15111 0 : c_parser_pragma (parser, pragma_external, NULL, NULL_TREE);
15112 0 : break;
15113 : case CPP_EOF:
15114 : return;
15115 0 : default:
15116 0 : if (c_parser_next_token_is_keyword (parser, RID_AT_END))
15117 : return;
15118 0 : else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
15119 0 : c_parser_objc_at_property_declaration (parser);
15120 0 : else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
15121 : {
15122 0 : objc_set_method_opt (true);
15123 0 : c_parser_consume_token (parser);
15124 : }
15125 0 : else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
15126 : {
15127 0 : objc_set_method_opt (false);
15128 0 : c_parser_consume_token (parser);
15129 : }
15130 : else
15131 0 : c_parser_declaration_or_fndef (parser, false, false, true,
15132 : false, true, false);
15133 : break;
15134 : }
15135 : }
15136 : }
15137 :
15138 : /* Parse an objc-methodproto.
15139 :
15140 : objc-methodproto:
15141 : objc-method-type objc-method-decl ;
15142 : */
15143 :
15144 : static void
15145 0 : c_parser_objc_methodproto (c_parser *parser)
15146 : {
15147 0 : bool is_class_method = c_parser_objc_method_type (parser);
15148 0 : tree decl, attributes = NULL_TREE;
15149 :
15150 : /* Remember protocol qualifiers in prototypes. */
15151 0 : parser->objc_pq_context = true;
15152 0 : decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
15153 : NULL);
15154 : /* Forget protocol qualifiers now. */
15155 0 : parser->objc_pq_context = false;
15156 :
15157 : /* Do not allow the presence of attributes to hide an erroneous
15158 : method implementation in the interface section. */
15159 0 : if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
15160 : {
15161 0 : c_parser_error (parser, "expected %<;%>");
15162 0 : return;
15163 : }
15164 :
15165 0 : if (decl != error_mark_node)
15166 0 : objc_add_method_declaration (is_class_method, decl, attributes);
15167 :
15168 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15169 : }
15170 :
15171 : /* If we are at a position that method attributes may be present, check that
15172 : there are not any parsed already (a syntax error) and then collect any
15173 : specified at the current location. Finally, if new attributes were present,
15174 : check that the next token is legal ( ';' for decls and '{' for defs). */
15175 :
15176 : static bool
15177 0 : c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
15178 : {
15179 0 : bool bad = false;
15180 0 : if (*attributes)
15181 : {
15182 0 : c_parser_error (parser,
15183 : "method attributes must be specified at the end only");
15184 0 : *attributes = NULL_TREE;
15185 0 : bad = true;
15186 : }
15187 :
15188 0 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
15189 0 : *attributes = c_parser_gnu_attributes (parser);
15190 :
15191 : /* If there were no attributes here, just report any earlier error. */
15192 0 : if (*attributes == NULL_TREE || bad)
15193 : return bad;
15194 :
15195 : /* If the attributes are followed by a ; or {, then just report any earlier
15196 : error. */
15197 0 : if (c_parser_next_token_is (parser, CPP_SEMICOLON)
15198 0 : || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
15199 : return bad;
15200 :
15201 : /* We've got attributes, but not at the end. */
15202 0 : c_parser_error (parser,
15203 : "expected %<;%> or %<{%> after method attribute definition");
15204 0 : return true;
15205 : }
15206 :
15207 : /* Parse an objc-method-decl.
15208 :
15209 : objc-method-decl:
15210 : ( objc-type-name ) objc-selector
15211 : objc-selector
15212 : ( objc-type-name ) objc-keyword-selector objc-optparmlist
15213 : objc-keyword-selector objc-optparmlist
15214 : gnu-attributes
15215 :
15216 : objc-keyword-selector:
15217 : objc-keyword-decl
15218 : objc-keyword-selector objc-keyword-decl
15219 :
15220 : objc-keyword-decl:
15221 : objc-selector : ( objc-type-name ) identifier
15222 : objc-selector : identifier
15223 : : ( objc-type-name ) identifier
15224 : : identifier
15225 :
15226 : objc-optparmlist:
15227 : objc-optparms objc-optellipsis
15228 :
15229 : objc-optparms:
15230 : empty
15231 : objc-opt-parms , parameter-declaration
15232 :
15233 : objc-optellipsis:
15234 : empty
15235 : , ...
15236 : */
15237 :
15238 : static tree
15239 0 : c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
15240 : tree *attributes, tree *expr)
15241 : {
15242 0 : tree type = NULL_TREE;
15243 0 : tree sel;
15244 0 : tree parms = NULL_TREE;
15245 0 : bool ellipsis = false;
15246 0 : bool attr_err = false;
15247 :
15248 0 : *attributes = NULL_TREE;
15249 0 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15250 : {
15251 0 : matching_parens parens;
15252 0 : parens.consume_open (parser);
15253 0 : type = c_parser_objc_type_name (parser);
15254 0 : parens.skip_until_found_close (parser);
15255 : }
15256 0 : sel = c_parser_objc_selector (parser);
15257 : /* If there is no selector, or a colon follows, we have an
15258 : objc-keyword-selector. If there is a selector, and a colon does
15259 : not follow, that selector ends the objc-method-decl. */
15260 0 : if (!sel || c_parser_next_token_is (parser, CPP_COLON))
15261 : {
15262 : tree tsel = sel;
15263 : tree list = NULL_TREE;
15264 0 : while (true)
15265 : {
15266 0 : tree atype = NULL_TREE, id, keyworddecl;
15267 0 : tree param_attr = NULL_TREE;
15268 0 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
15269 : break;
15270 0 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15271 : {
15272 0 : c_parser_consume_token (parser);
15273 0 : atype = c_parser_objc_type_name (parser);
15274 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
15275 : "expected %<)%>");
15276 : }
15277 : /* New ObjC allows attributes on method parameters. */
15278 0 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
15279 0 : param_attr = c_parser_gnu_attributes (parser);
15280 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
15281 : {
15282 0 : c_parser_error (parser, "expected identifier");
15283 0 : return error_mark_node;
15284 : }
15285 0 : id = c_parser_peek_token (parser)->value;
15286 0 : c_parser_consume_token (parser);
15287 0 : keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
15288 0 : list = chainon (list, keyworddecl);
15289 0 : tsel = c_parser_objc_selector (parser);
15290 0 : if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
15291 : break;
15292 : }
15293 :
15294 0 : attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
15295 :
15296 : /* Parse the optional parameter list. Optional Objective-C
15297 : method parameters follow the C syntax, and may include '...'
15298 : to denote a variable number of arguments. */
15299 0 : parms = make_node (TREE_LIST);
15300 0 : while (c_parser_next_token_is (parser, CPP_COMMA))
15301 : {
15302 0 : struct c_parm *parm;
15303 0 : c_parser_consume_token (parser);
15304 0 : if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
15305 : {
15306 0 : ellipsis = true;
15307 0 : c_parser_consume_token (parser);
15308 0 : attr_err |= c_parser_objc_maybe_method_attributes
15309 0 : (parser, attributes) ;
15310 0 : break;
15311 : }
15312 0 : parm = c_parser_parameter_declaration (parser, NULL_TREE, false);
15313 0 : if (parm == NULL)
15314 : break;
15315 0 : parms = chainon (parms,
15316 : build_tree_list (NULL_TREE, grokparm (parm, expr)));
15317 : }
15318 : sel = list;
15319 : }
15320 : else
15321 0 : attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
15322 :
15323 0 : if (sel == NULL)
15324 : {
15325 0 : c_parser_error (parser, "objective-c method declaration is expected");
15326 0 : return error_mark_node;
15327 : }
15328 :
15329 0 : if (attr_err)
15330 0 : return error_mark_node;
15331 :
15332 0 : return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
15333 : }
15334 :
15335 : /* Parse an objc-type-name.
15336 :
15337 : objc-type-name:
15338 : objc-type-qualifiers[opt] type-name
15339 : objc-type-qualifiers[opt]
15340 :
15341 : objc-type-qualifiers:
15342 : objc-type-qualifier
15343 : objc-type-qualifiers objc-type-qualifier
15344 :
15345 : objc-type-qualifier: one of
15346 : in out inout bycopy byref oneway
15347 : */
15348 :
15349 : static tree
15350 0 : c_parser_objc_type_name (c_parser *parser)
15351 : {
15352 0 : tree quals = NULL_TREE;
15353 0 : struct c_type_name *type_name = NULL;
15354 0 : tree type = NULL_TREE;
15355 0 : while (true)
15356 : {
15357 0 : c_token *token = c_parser_peek_token (parser);
15358 0 : if (token->type == CPP_KEYWORD
15359 0 : && (token->keyword == RID_IN
15360 : || token->keyword == RID_OUT
15361 : || token->keyword == RID_INOUT
15362 : || token->keyword == RID_BYCOPY
15363 : || token->keyword == RID_BYREF
15364 0 : || token->keyword == RID_ONEWAY))
15365 : {
15366 0 : quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
15367 0 : c_parser_consume_token (parser);
15368 : }
15369 : else
15370 : break;
15371 0 : }
15372 0 : if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
15373 0 : type_name = c_parser_type_name (parser);
15374 0 : if (type_name)
15375 0 : type = groktypename (type_name, NULL, NULL);
15376 :
15377 : /* If the type is unknown, and error has already been produced and
15378 : we need to recover from the error. In that case, use NULL_TREE
15379 : for the type, as if no type had been specified; this will use the
15380 : default type ('id') which is good for error recovery. */
15381 0 : if (type == error_mark_node)
15382 0 : type = NULL_TREE;
15383 :
15384 0 : return build_tree_list (quals, type);
15385 : }
15386 :
15387 : /* Parse objc-protocol-refs.
15388 :
15389 : objc-protocol-refs:
15390 : < identifier-list >
15391 : */
15392 :
15393 : static tree
15394 0 : c_parser_objc_protocol_refs (c_parser *parser)
15395 : {
15396 0 : tree list = NULL_TREE;
15397 0 : gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
15398 0 : c_parser_consume_token (parser);
15399 : /* Any identifiers, including those declared as type names, are OK
15400 : here. */
15401 0 : while (true)
15402 : {
15403 0 : tree id;
15404 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
15405 : {
15406 0 : c_parser_error (parser, "expected identifier");
15407 0 : break;
15408 : }
15409 0 : id = c_parser_peek_token (parser)->value;
15410 0 : list = chainon (list, build_tree_list (NULL_TREE, id));
15411 0 : c_parser_consume_token (parser);
15412 0 : if (c_parser_next_token_is (parser, CPP_COMMA))
15413 0 : c_parser_consume_token (parser);
15414 : else
15415 : break;
15416 0 : }
15417 0 : c_parser_require (parser, CPP_GREATER, "expected %<>%>");
15418 0 : return list;
15419 : }
15420 :
15421 : /* Parse an objc-try-catch-finally-statement.
15422 :
15423 : objc-try-catch-finally-statement:
15424 : @try compound-statement objc-catch-list[opt]
15425 : @try compound-statement objc-catch-list[opt] @finally compound-statement
15426 :
15427 : objc-catch-list:
15428 : @catch ( objc-catch-parameter-declaration ) compound-statement
15429 : objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
15430 :
15431 : objc-catch-parameter-declaration:
15432 : parameter-declaration
15433 : '...'
15434 :
15435 : where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
15436 :
15437 : PS: This function is identical to cp_parser_objc_try_catch_finally_statement
15438 : for C++. Keep them in sync. */
15439 :
15440 : static void
15441 0 : c_parser_objc_try_catch_finally_statement (c_parser *parser)
15442 : {
15443 0 : location_t location;
15444 0 : tree stmt;
15445 :
15446 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
15447 0 : c_parser_consume_token (parser);
15448 0 : location = c_parser_peek_token (parser)->location;
15449 0 : objc_maybe_warn_exceptions (location);
15450 0 : stmt = c_parser_compound_statement (parser);
15451 0 : objc_begin_try_stmt (location, stmt);
15452 :
15453 0 : while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
15454 : {
15455 0 : struct c_parm *parm;
15456 0 : tree parameter_declaration = error_mark_node;
15457 0 : bool seen_open_paren = false;
15458 :
15459 0 : c_parser_consume_token (parser);
15460 0 : matching_parens parens;
15461 0 : if (!parens.require_open (parser))
15462 0 : seen_open_paren = true;
15463 0 : if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
15464 : {
15465 : /* We have "@catch (...)" (where the '...' are literally
15466 : what is in the code). Skip the '...'.
15467 : parameter_declaration is set to NULL_TREE, and
15468 : objc_being_catch_clauses() knows that that means
15469 : '...'. */
15470 0 : c_parser_consume_token (parser);
15471 0 : parameter_declaration = NULL_TREE;
15472 : }
15473 : else
15474 : {
15475 : /* We have "@catch (NSException *exception)" or something
15476 : like that. Parse the parameter declaration. */
15477 0 : parm = c_parser_parameter_declaration (parser, NULL_TREE, false);
15478 0 : if (parm == NULL)
15479 0 : parameter_declaration = error_mark_node;
15480 : else
15481 0 : parameter_declaration = grokparm (parm, NULL);
15482 : }
15483 0 : if (seen_open_paren)
15484 0 : parens.require_close (parser);
15485 : else
15486 : {
15487 : /* If there was no open parenthesis, we are recovering from
15488 : an error, and we are trying to figure out what mistake
15489 : the user has made. */
15490 :
15491 : /* If there is an immediate closing parenthesis, the user
15492 : probably forgot the opening one (ie, they typed "@catch
15493 : NSException *e)". Parse the closing parenthesis and keep
15494 : going. */
15495 0 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
15496 0 : c_parser_consume_token (parser);
15497 :
15498 : /* If these is no immediate closing parenthesis, the user
15499 : probably doesn't know that parenthesis are required at
15500 : all (ie, they typed "@catch NSException *e"). So, just
15501 : forget about the closing parenthesis and keep going. */
15502 : }
15503 0 : objc_begin_catch_clause (parameter_declaration);
15504 0 : if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
15505 0 : c_parser_compound_statement_nostart (parser);
15506 0 : objc_finish_catch_clause ();
15507 : }
15508 0 : if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
15509 : {
15510 0 : c_parser_consume_token (parser);
15511 0 : location = c_parser_peek_token (parser)->location;
15512 0 : stmt = c_parser_compound_statement (parser);
15513 0 : objc_build_finally_clause (location, stmt);
15514 : }
15515 0 : objc_finish_try_stmt ();
15516 0 : }
15517 :
15518 : /* Parse an objc-synchronized-statement.
15519 :
15520 : objc-synchronized-statement:
15521 : @synchronized ( expression ) compound-statement
15522 : */
15523 :
15524 : static void
15525 0 : c_parser_objc_synchronized_statement (c_parser *parser)
15526 : {
15527 0 : location_t loc;
15528 0 : tree expr, stmt;
15529 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
15530 0 : c_parser_consume_token (parser);
15531 0 : loc = c_parser_peek_token (parser)->location;
15532 0 : objc_maybe_warn_exceptions (loc);
15533 0 : matching_parens parens;
15534 0 : if (parens.require_open (parser))
15535 : {
15536 0 : struct c_expr ce = c_parser_expression (parser);
15537 0 : ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15538 0 : expr = ce.value;
15539 0 : expr = c_fully_fold (expr, false, NULL);
15540 0 : parens.skip_until_found_close (parser);
15541 : }
15542 : else
15543 0 : expr = error_mark_node;
15544 0 : stmt = c_parser_compound_statement (parser);
15545 0 : objc_build_synchronized (loc, expr, stmt);
15546 0 : }
15547 :
15548 : /* Parse an objc-selector; return NULL_TREE without an error if the
15549 : next token is not an objc-selector.
15550 :
15551 : objc-selector:
15552 : identifier
15553 : one of
15554 : enum struct union if else while do for switch case default
15555 : break continue return goto asm sizeof typeof typeof_unqual __alignof
15556 : unsigned long const short volatile signed restrict _Complex
15557 : in out inout bycopy byref oneway int char float double void _Bool
15558 : _Atomic
15559 :
15560 : ??? Why this selection of keywords but not, for example, storage
15561 : class specifiers? */
15562 :
15563 : static tree
15564 0 : c_parser_objc_selector (c_parser *parser)
15565 : {
15566 0 : c_token *token = c_parser_peek_token (parser);
15567 0 : tree value = token->value;
15568 0 : if (token->type == CPP_NAME)
15569 : {
15570 0 : c_parser_consume_token (parser);
15571 0 : return value;
15572 : }
15573 0 : if (token->type != CPP_KEYWORD)
15574 : return NULL_TREE;
15575 0 : switch (token->keyword)
15576 : {
15577 0 : case RID_ENUM:
15578 0 : case RID_STRUCT:
15579 0 : case RID_UNION:
15580 0 : case RID_IF:
15581 0 : case RID_ELSE:
15582 0 : case RID_WHILE:
15583 0 : case RID_DO:
15584 0 : case RID_FOR:
15585 0 : case RID_SWITCH:
15586 0 : case RID_CASE:
15587 0 : case RID_DEFAULT:
15588 0 : case RID_BREAK:
15589 0 : case RID_CONTINUE:
15590 0 : case RID_RETURN:
15591 0 : case RID_GOTO:
15592 0 : case RID_ASM:
15593 0 : case RID_SIZEOF:
15594 0 : case RID_TYPEOF:
15595 0 : case RID_TYPEOF_UNQUAL:
15596 0 : case RID_ALIGNOF:
15597 0 : case RID_UNSIGNED:
15598 0 : case RID_LONG:
15599 0 : case RID_CONST:
15600 0 : case RID_SHORT:
15601 0 : case RID_VOLATILE:
15602 0 : case RID_SIGNED:
15603 0 : case RID_RESTRICT:
15604 0 : case RID_COMPLEX:
15605 0 : case RID_IN:
15606 0 : case RID_OUT:
15607 0 : case RID_INOUT:
15608 0 : case RID_BYCOPY:
15609 0 : case RID_BYREF:
15610 0 : case RID_ONEWAY:
15611 0 : case RID_INT:
15612 0 : case RID_CHAR:
15613 0 : case RID_FLOAT:
15614 0 : case RID_DOUBLE:
15615 0 : CASE_RID_FLOATN_NX:
15616 0 : case RID_VOID:
15617 0 : case RID_BOOL:
15618 0 : case RID_ATOMIC:
15619 0 : case RID_AUTO_TYPE:
15620 0 : case RID_INT_N_0:
15621 0 : case RID_INT_N_1:
15622 0 : case RID_INT_N_2:
15623 0 : case RID_INT_N_3:
15624 0 : c_parser_consume_token (parser);
15625 0 : return value;
15626 : default:
15627 : return NULL_TREE;
15628 : }
15629 : }
15630 :
15631 : /* Parse an objc-selector-arg.
15632 :
15633 : objc-selector-arg:
15634 : objc-selector
15635 : objc-keywordname-list
15636 :
15637 : objc-keywordname-list:
15638 : objc-keywordname
15639 : objc-keywordname-list objc-keywordname
15640 :
15641 : objc-keywordname:
15642 : objc-selector :
15643 : :
15644 : */
15645 :
15646 : static tree
15647 0 : c_parser_objc_selector_arg (c_parser *parser)
15648 : {
15649 0 : tree sel = c_parser_objc_selector (parser);
15650 0 : tree list = NULL_TREE;
15651 0 : if (sel
15652 0 : && c_parser_next_token_is_not (parser, CPP_COLON)
15653 0 : && c_parser_next_token_is_not (parser, CPP_SCOPE))
15654 : return sel;
15655 0 : while (true)
15656 : {
15657 0 : if (c_parser_next_token_is (parser, CPP_SCOPE))
15658 : {
15659 0 : c_parser_consume_token (parser);
15660 0 : list = chainon (list, build_tree_list (sel, NULL_TREE));
15661 0 : list = chainon (list, build_tree_list (NULL_TREE, NULL_TREE));
15662 : }
15663 : else
15664 : {
15665 0 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
15666 : return list;
15667 0 : list = chainon (list, build_tree_list (sel, NULL_TREE));
15668 : }
15669 0 : sel = c_parser_objc_selector (parser);
15670 0 : if (!sel
15671 0 : && c_parser_next_token_is_not (parser, CPP_COLON)
15672 0 : && c_parser_next_token_is_not (parser, CPP_SCOPE))
15673 : break;
15674 : }
15675 : return list;
15676 : }
15677 :
15678 : /* Parse an objc-receiver.
15679 :
15680 : objc-receiver:
15681 : expression
15682 : class-name
15683 : type-name
15684 : */
15685 :
15686 : static tree
15687 0 : c_parser_objc_receiver (c_parser *parser)
15688 : {
15689 0 : location_t loc = c_parser_peek_token (parser)->location;
15690 :
15691 0 : if (c_parser_peek_token (parser)->type == CPP_NAME
15692 0 : && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
15693 0 : || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
15694 : {
15695 0 : tree id = c_parser_peek_token (parser)->value;
15696 0 : c_parser_consume_token (parser);
15697 0 : return objc_get_class_reference (id);
15698 : }
15699 0 : struct c_expr ce = c_parser_expression (parser);
15700 0 : ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15701 0 : return c_fully_fold (ce.value, false, NULL);
15702 : }
15703 :
15704 : /* Parse objc-message-args.
15705 :
15706 : objc-message-args:
15707 : objc-selector
15708 : objc-keywordarg-list
15709 :
15710 : objc-keywordarg-list:
15711 : objc-keywordarg
15712 : objc-keywordarg-list objc-keywordarg
15713 :
15714 : objc-keywordarg:
15715 : objc-selector : objc-keywordexpr
15716 : : objc-keywordexpr
15717 : */
15718 :
15719 : static tree
15720 0 : c_parser_objc_message_args (c_parser *parser)
15721 : {
15722 0 : tree sel = c_parser_objc_selector (parser);
15723 0 : tree list = NULL_TREE;
15724 0 : if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
15725 : return sel;
15726 0 : while (true)
15727 : {
15728 0 : tree keywordexpr;
15729 0 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
15730 0 : return error_mark_node;
15731 0 : keywordexpr = c_parser_objc_keywordexpr (parser);
15732 0 : list = chainon (list, build_tree_list (sel, keywordexpr));
15733 0 : sel = c_parser_objc_selector (parser);
15734 0 : if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
15735 : break;
15736 : }
15737 : return list;
15738 : }
15739 :
15740 : /* Parse an objc-keywordexpr.
15741 :
15742 : objc-keywordexpr:
15743 : nonempty-expr-list
15744 : */
15745 :
15746 : static tree
15747 0 : c_parser_objc_keywordexpr (c_parser *parser)
15748 : {
15749 0 : tree ret;
15750 0 : vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
15751 : NULL, NULL, NULL, NULL);
15752 0 : if (vec_safe_length (expr_list) == 1)
15753 : {
15754 : /* Just return the expression, remove a level of
15755 : indirection. */
15756 0 : ret = (*expr_list)[0];
15757 : }
15758 : else
15759 : {
15760 : /* We have a comma expression, we will collapse later. */
15761 0 : ret = build_tree_list_vec (expr_list);
15762 : }
15763 0 : release_tree_vector (expr_list);
15764 0 : return ret;
15765 : }
15766 :
15767 : /* A check, needed in several places, that ObjC interface, implementation or
15768 : method definitions are not prefixed by incorrect items. */
15769 : static bool
15770 0 : c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
15771 : struct c_declspecs *specs)
15772 : {
15773 0 : if (!specs->declspecs_seen_p || specs->non_sc_seen_p
15774 0 : || specs->typespec_kind != ctsk_none)
15775 : {
15776 0 : c_parser_error (parser,
15777 : "no type or storage class may be specified here,");
15778 0 : c_parser_skip_to_end_of_block_or_statement (parser);
15779 0 : return true;
15780 : }
15781 : return false;
15782 : }
15783 :
15784 : /* Parse an Objective-C @property declaration. The syntax is:
15785 :
15786 : objc-property-declaration:
15787 : '@property' objc-property-attributes[opt] struct-declaration ;
15788 :
15789 : objc-property-attributes:
15790 : '(' objc-property-attribute-list ')'
15791 :
15792 : objc-property-attribute-list:
15793 : objc-property-attribute
15794 : objc-property-attribute-list, objc-property-attribute
15795 :
15796 : objc-property-attribute
15797 : 'getter' = identifier
15798 : 'setter' = identifier
15799 : 'readonly'
15800 : 'readwrite'
15801 : 'assign'
15802 : 'retain'
15803 : 'copy'
15804 : 'nonatomic'
15805 :
15806 : For example:
15807 : @property NSString *name;
15808 : @property (readonly) id object;
15809 : @property (retain, nonatomic, getter=getTheName) id name;
15810 : @property int a, b, c;
15811 :
15812 : PS: This function is identical to cp_parser_objc_at_propery_declaration
15813 : for C++. Keep them in sync. */
15814 : static void
15815 0 : c_parser_objc_at_property_declaration (c_parser *parser)
15816 : {
15817 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
15818 0 : location_t loc = c_parser_peek_token (parser)->location;
15819 0 : c_parser_consume_token (parser); /* Eat '@property'. */
15820 :
15821 : /* Parse the optional attribute list.
15822 :
15823 : A list of parsed, but not verified, attributes. */
15824 0 : vec<property_attribute_info *> prop_attr_list = vNULL;
15825 :
15826 0 : bool syntax_error = false;
15827 0 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15828 : {
15829 0 : matching_parens parens;
15830 :
15831 0 : location_t attr_start = c_parser_peek_token (parser)->location;
15832 : /* Eat the '(' */
15833 0 : parens.consume_open (parser);
15834 :
15835 : /* Property attribute keywords are valid now. */
15836 0 : parser->objc_property_attr_context = true;
15837 :
15838 : /* Allow @property (), with a warning. */
15839 0 : location_t attr_end = c_parser_peek_token (parser)->location;
15840 :
15841 0 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
15842 : {
15843 0 : location_t attr_comb = make_location (attr_end, attr_start, attr_end);
15844 0 : warning_at (attr_comb, OPT_Wattributes,
15845 : "empty property attribute list");
15846 : }
15847 : else
15848 0 : while (true)
15849 : {
15850 0 : c_token *token = c_parser_peek_token (parser);
15851 0 : attr_start = token->location;
15852 0 : attr_end = get_finish (token->location);
15853 0 : location_t attr_comb = make_location (attr_start, attr_start,
15854 : attr_end);
15855 :
15856 0 : if (token->type == CPP_CLOSE_PAREN || token->type == CPP_COMMA)
15857 : {
15858 0 : warning_at (attr_comb, OPT_Wattributes,
15859 : "missing property attribute");
15860 0 : if (token->type == CPP_CLOSE_PAREN)
15861 : break;
15862 0 : c_parser_consume_token (parser);
15863 0 : continue;
15864 : }
15865 :
15866 0 : tree attr_name = NULL_TREE;
15867 0 : enum rid keyword = RID_MAX; /* Not a valid property attribute. */
15868 0 : bool add_at = false;
15869 0 : if (token->type == CPP_KEYWORD)
15870 : {
15871 0 : keyword = token->keyword;
15872 0 : if (OBJC_IS_AT_KEYWORD (keyword))
15873 : {
15874 : /* For '@' keywords the token value has the keyword,
15875 : prepend the '@' for diagnostics. */
15876 0 : attr_name = token->value;
15877 0 : add_at = true;
15878 : }
15879 : else
15880 0 : attr_name = ridpointers[(int)keyword];
15881 : }
15882 0 : else if (token->type == CPP_NAME)
15883 0 : attr_name = token->value;
15884 0 : c_parser_consume_token (parser);
15885 :
15886 0 : enum objc_property_attribute_kind prop_kind
15887 0 : = objc_prop_attr_kind_for_rid (keyword);
15888 0 : property_attribute_info *prop
15889 0 : = new property_attribute_info (attr_name, attr_comb, prop_kind);
15890 0 : prop_attr_list.safe_push (prop);
15891 :
15892 0 : tree meth_name;
15893 0 : switch (prop->prop_kind)
15894 : {
15895 : default: break;
15896 0 : case OBJC_PROPERTY_ATTR_UNKNOWN:
15897 0 : if (attr_name)
15898 0 : error_at (attr_comb, "unknown property attribute %<%s%s%>",
15899 0 : add_at ? "@" : "", IDENTIFIER_POINTER (attr_name));
15900 : else
15901 0 : error_at (attr_comb, "unknown property attribute");
15902 0 : prop->parse_error = syntax_error = true;
15903 0 : break;
15904 :
15905 0 : case OBJC_PROPERTY_ATTR_GETTER:
15906 0 : case OBJC_PROPERTY_ATTR_SETTER:
15907 0 : if (c_parser_next_token_is_not (parser, CPP_EQ))
15908 : {
15909 0 : attr_comb = make_location (attr_end, attr_start, attr_end);
15910 0 : error_at (attr_comb, "expected %<=%> after Objective-C %qE",
15911 : attr_name);
15912 0 : prop->parse_error = syntax_error = true;
15913 0 : break;
15914 : }
15915 0 : token = c_parser_peek_token (parser);
15916 0 : attr_end = token->location;
15917 0 : c_parser_consume_token (parser); /* eat the = */
15918 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
15919 : {
15920 0 : attr_comb = make_location (attr_end, attr_start, attr_end);
15921 0 : error_at (attr_comb, "expected %qE selector name",
15922 : attr_name);
15923 0 : prop->parse_error = syntax_error = true;
15924 0 : break;
15925 : }
15926 : /* Get the end of the method name, and consume the name. */
15927 0 : token = c_parser_peek_token (parser);
15928 0 : attr_end = get_finish (token->location);
15929 0 : meth_name = token->value;
15930 0 : c_parser_consume_token (parser);
15931 0 : if (prop->prop_kind == OBJC_PROPERTY_ATTR_SETTER)
15932 : {
15933 0 : if (c_parser_next_token_is_not (parser, CPP_COLON))
15934 : {
15935 0 : attr_comb = make_location (attr_end, attr_start,
15936 : attr_end);
15937 0 : error_at (attr_comb, "setter method names must"
15938 : " terminate with %<:%>");
15939 0 : prop->parse_error = syntax_error = true;
15940 : }
15941 : else
15942 : {
15943 0 : attr_end = get_finish (c_parser_peek_token
15944 0 : (parser)->location);
15945 0 : c_parser_consume_token (parser);
15946 : }
15947 0 : attr_comb = make_location (attr_start, attr_start,
15948 : attr_end);
15949 : }
15950 : else
15951 0 : attr_comb = make_location (attr_start, attr_start,
15952 : attr_end);
15953 0 : prop->ident = meth_name;
15954 : /* Updated location including all that was successfully
15955 : parsed. */
15956 0 : prop->prop_loc = attr_comb;
15957 0 : break;
15958 : }
15959 :
15960 : /* If we see a comma here, then keep going - even if we already
15961 : saw a syntax error. For simple mistakes e.g. (assign, getter=x)
15962 : this makes a more useful output and avoid spurious warnings about
15963 : missing attributes that are, in fact, specified after the one with
15964 : the syntax error. */
15965 0 : if (c_parser_next_token_is (parser, CPP_COMMA))
15966 0 : c_parser_consume_token (parser);
15967 : else
15968 : break;
15969 : }
15970 0 : parser->objc_property_attr_context = false;
15971 :
15972 0 : if (syntax_error && c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
15973 : /* We don't really want to chew the whole of the file looking for a
15974 : matching closing parenthesis, so we will try to read the decl and
15975 : let the error handling for that close out the statement. */
15976 : ;
15977 : else
15978 0 : syntax_error = false, parens.skip_until_found_close (parser);
15979 : }
15980 :
15981 : /* 'properties' is the list of properties that we read. Usually a
15982 : single one, but maybe more (eg, in "@property int a, b, c;" there
15983 : are three). */
15984 0 : tree properties = c_parser_struct_declaration (parser, NULL);
15985 :
15986 0 : if (properties == error_mark_node)
15987 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
15988 : else
15989 : {
15990 0 : if (properties == NULL_TREE)
15991 0 : c_parser_error (parser, "expected identifier");
15992 : else
15993 : {
15994 : /* Comma-separated properties are chained together in reverse order;
15995 : add them one by one. */
15996 0 : properties = nreverse (properties);
15997 0 : for (; properties; properties = TREE_CHAIN (properties))
15998 0 : objc_add_property_declaration (loc, copy_node (properties),
15999 : prop_attr_list);
16000 : }
16001 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
16002 : }
16003 :
16004 0 : while (!prop_attr_list.is_empty())
16005 0 : delete prop_attr_list.pop ();
16006 0 : prop_attr_list.release ();
16007 0 : parser->error = false;
16008 0 : }
16009 :
16010 : /* Parse an Objective-C @synthesize declaration. The syntax is:
16011 :
16012 : objc-synthesize-declaration:
16013 : @synthesize objc-synthesize-identifier-list ;
16014 :
16015 : objc-synthesize-identifier-list:
16016 : objc-synthesize-identifier
16017 : objc-synthesize-identifier-list, objc-synthesize-identifier
16018 :
16019 : objc-synthesize-identifier
16020 : identifier
16021 : identifier = identifier
16022 :
16023 : For example:
16024 : @synthesize MyProperty;
16025 : @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
16026 :
16027 : PS: This function is identical to cp_parser_objc_at_synthesize_declaration
16028 : for C++. Keep them in sync.
16029 : */
16030 : static void
16031 0 : c_parser_objc_at_synthesize_declaration (c_parser *parser)
16032 : {
16033 0 : tree list = NULL_TREE;
16034 0 : location_t loc;
16035 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
16036 0 : loc = c_parser_peek_token (parser)->location;
16037 :
16038 0 : c_parser_consume_token (parser);
16039 0 : while (true)
16040 : {
16041 0 : tree property, ivar;
16042 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
16043 : {
16044 0 : c_parser_error (parser, "expected identifier");
16045 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
16046 : /* Once we find the semicolon, we can resume normal parsing.
16047 : We have to reset parser->error manually because
16048 : c_parser_skip_until_found() won't reset it for us if the
16049 : next token is precisely a semicolon. */
16050 0 : parser->error = false;
16051 0 : return;
16052 : }
16053 0 : property = c_parser_peek_token (parser)->value;
16054 0 : c_parser_consume_token (parser);
16055 0 : if (c_parser_next_token_is (parser, CPP_EQ))
16056 : {
16057 0 : c_parser_consume_token (parser);
16058 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
16059 : {
16060 0 : c_parser_error (parser, "expected identifier");
16061 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
16062 0 : parser->error = false;
16063 0 : return;
16064 : }
16065 0 : ivar = c_parser_peek_token (parser)->value;
16066 0 : c_parser_consume_token (parser);
16067 : }
16068 : else
16069 : ivar = NULL_TREE;
16070 0 : list = chainon (list, build_tree_list (ivar, property));
16071 0 : if (c_parser_next_token_is (parser, CPP_COMMA))
16072 0 : c_parser_consume_token (parser);
16073 : else
16074 : break;
16075 0 : }
16076 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
16077 0 : objc_add_synthesize_declaration (loc, list);
16078 : }
16079 :
16080 : /* Parse an Objective-C @dynamic declaration. The syntax is:
16081 :
16082 : objc-dynamic-declaration:
16083 : @dynamic identifier-list ;
16084 :
16085 : For example:
16086 : @dynamic MyProperty;
16087 : @dynamic MyProperty, AnotherProperty;
16088 :
16089 : PS: This function is identical to cp_parser_objc_at_dynamic_declaration
16090 : for C++. Keep them in sync.
16091 : */
16092 : static void
16093 0 : c_parser_objc_at_dynamic_declaration (c_parser *parser)
16094 : {
16095 0 : tree list = NULL_TREE;
16096 0 : location_t loc;
16097 0 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
16098 0 : loc = c_parser_peek_token (parser)->location;
16099 :
16100 0 : c_parser_consume_token (parser);
16101 0 : while (true)
16102 : {
16103 0 : tree property;
16104 0 : if (c_parser_next_token_is_not (parser, CPP_NAME))
16105 : {
16106 0 : c_parser_error (parser, "expected identifier");
16107 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
16108 0 : parser->error = false;
16109 0 : return;
16110 : }
16111 0 : property = c_parser_peek_token (parser)->value;
16112 0 : list = chainon (list, build_tree_list (NULL_TREE, property));
16113 0 : c_parser_consume_token (parser);
16114 0 : if (c_parser_next_token_is (parser, CPP_COMMA))
16115 0 : c_parser_consume_token (parser);
16116 : else
16117 : break;
16118 0 : }
16119 0 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
16120 0 : objc_add_dynamic_declaration (loc, list);
16121 : }
16122 :
16123 :
16124 : /* Parse a pragma GCC ivdep. */
16125 :
16126 : static bool
16127 128 : c_parse_pragma_ivdep (c_parser *parser)
16128 : {
16129 0 : c_parser_consume_pragma (parser);
16130 0 : c_parser_skip_to_pragma_eol (parser);
16131 128 : return true;
16132 : }
16133 :
16134 : /* Parse a pragma GCC novector. */
16135 :
16136 : static bool
16137 3020 : c_parse_pragma_novector (c_parser *parser)
16138 : {
16139 0 : c_parser_consume_pragma (parser);
16140 0 : c_parser_skip_to_pragma_eol (parser);
16141 3020 : return true;
16142 : }
16143 :
16144 : /* Parse a pragma GCC unroll. */
16145 :
16146 : static unsigned short
16147 297 : c_parser_pragma_unroll (c_parser *parser)
16148 : {
16149 297 : unsigned short unroll;
16150 297 : c_parser_consume_pragma (parser);
16151 297 : location_t location = c_parser_peek_token (parser)->location;
16152 297 : tree expr = c_parser_expr_no_commas (parser, NULL).value;
16153 297 : mark_exp_read (expr);
16154 297 : expr = c_fully_fold (expr, false, NULL);
16155 297 : HOST_WIDE_INT lunroll = 0;
16156 594 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
16157 296 : || TREE_CODE (expr) != INTEGER_CST
16158 295 : || (lunroll = tree_to_shwi (expr)) < 0
16159 591 : || lunroll >= USHRT_MAX)
16160 : {
16161 4 : error_at (location, "%<#pragma GCC unroll%> requires an"
16162 : " assignment-expression that evaluates to a non-negative"
16163 : " integral constant less than %u", USHRT_MAX);
16164 4 : unroll = 0;
16165 : }
16166 : else
16167 : {
16168 293 : unroll = (unsigned short)lunroll;
16169 293 : if (unroll == 0)
16170 : unroll = 1;
16171 : }
16172 :
16173 297 : c_parser_skip_to_pragma_eol (parser);
16174 297 : return unroll;
16175 : }
16176 :
16177 : /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
16178 : should be considered, statements. ALLOW_STMT is true if we're within
16179 : the context of a function and such pragmas are to be allowed. Returns
16180 : true if we actually parsed such a pragma. BEFORE_LABELS is last statement
16181 : before possible labels, see get_before_labels description for details. */
16182 :
16183 : static bool
16184 1978612 : c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p,
16185 : tree before_labels)
16186 : {
16187 1978612 : unsigned int id;
16188 1978612 : const char *construct = NULL;
16189 :
16190 1978612 : input_location = c_parser_peek_token (parser)->location;
16191 1978612 : id = c_parser_peek_token (parser)->pragma_kind;
16192 1978612 : gcc_assert (id != PRAGMA_NONE);
16193 1978612 : if (parser->omp_for_parse_state
16194 16 : && parser->omp_for_parse_state->in_intervening_code
16195 13 : && id >= PRAGMA_OMP__START_ && id <= PRAGMA_OMP__LAST_
16196 : /* Allow a safe subset of non-executable directives. See classification in
16197 : array c_omp_directives. */
16198 7 : && id != PRAGMA_OMP_METADIRECTIVE && id != PRAGMA_OMP_NOTHING
16199 5 : && id != PRAGMA_OMP_ASSUME && id != PRAGMA_OMP_ERROR)
16200 : {
16201 2 : error_at (
16202 : input_location,
16203 : "intervening code must not contain executable OpenMP directives");
16204 2 : parser->omp_for_parse_state->fail = true;
16205 2 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16206 2 : return false;
16207 : }
16208 :
16209 1978610 : switch (id)
16210 : {
16211 144 : case PRAGMA_OACC_DECLARE:
16212 144 : c_parser_oacc_declare (parser);
16213 144 : return false;
16214 :
16215 136 : case PRAGMA_OACC_ENTER_DATA:
16216 136 : if (context != pragma_compound)
16217 : {
16218 : construct = "acc enter data";
16219 62 : in_compound:
16220 62 : if (context == pragma_stmt)
16221 : {
16222 59 : error_at (c_parser_peek_token (parser)->location,
16223 : "%<#pragma %s%> may only be used in compound "
16224 : "statements", construct);
16225 59 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16226 59 : return true;
16227 : }
16228 3 : goto bad_stmt;
16229 : }
16230 133 : c_parser_oacc_enter_exit_data (parser, true);
16231 133 : return false;
16232 :
16233 131 : case PRAGMA_OACC_EXIT_DATA:
16234 131 : if (context != pragma_compound)
16235 : {
16236 3 : construct = "acc exit data";
16237 3 : goto in_compound;
16238 : }
16239 128 : c_parser_oacc_enter_exit_data (parser, false);
16240 128 : return false;
16241 :
16242 350 : case PRAGMA_OACC_ROUTINE:
16243 350 : if (context != pragma_external)
16244 : {
16245 5 : error_at (c_parser_peek_token (parser)->location,
16246 : "%<#pragma acc routine%> must be at file scope");
16247 5 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16248 5 : return false;
16249 : }
16250 345 : c_parser_oacc_routine (parser, context);
16251 345 : return false;
16252 :
16253 100 : case PRAGMA_OACC_UPDATE:
16254 100 : if (context != pragma_compound)
16255 : {
16256 8 : construct = "acc update";
16257 8 : goto in_compound;
16258 : }
16259 92 : c_parser_oacc_update (parser);
16260 92 : return false;
16261 :
16262 373 : case PRAGMA_OMP_BARRIER:
16263 373 : if (context != pragma_compound)
16264 : {
16265 11 : construct = "omp barrier";
16266 11 : goto in_compound;
16267 : }
16268 362 : c_parser_omp_barrier (parser);
16269 362 : return false;
16270 :
16271 76 : case PRAGMA_OMP_DEPOBJ:
16272 76 : if (context != pragma_compound)
16273 : {
16274 1 : construct = "omp depobj";
16275 1 : goto in_compound;
16276 : }
16277 75 : c_parser_omp_depobj (parser);
16278 75 : return false;
16279 :
16280 68 : case PRAGMA_OMP_FLUSH:
16281 68 : if (context != pragma_compound)
16282 : {
16283 9 : construct = "omp flush";
16284 9 : goto in_compound;
16285 : }
16286 59 : c_parser_omp_flush (parser);
16287 59 : return false;
16288 :
16289 183 : case PRAGMA_OMP_INTEROP:
16290 183 : if (context != pragma_compound)
16291 : {
16292 0 : construct = "omp interop";
16293 0 : goto in_compound;
16294 : }
16295 183 : c_parser_omp_interop (parser);
16296 183 : return false;
16297 :
16298 102 : case PRAGMA_OMP_TASKWAIT:
16299 102 : if (context != pragma_compound)
16300 : {
16301 8 : construct = "omp taskwait";
16302 8 : goto in_compound;
16303 : }
16304 94 : c_parser_omp_taskwait (parser);
16305 94 : return false;
16306 :
16307 14 : case PRAGMA_OMP_TASKYIELD:
16308 14 : if (context != pragma_compound)
16309 : {
16310 8 : construct = "omp taskyield";
16311 8 : goto in_compound;
16312 : }
16313 6 : c_parser_omp_taskyield (parser);
16314 6 : return false;
16315 :
16316 229 : case PRAGMA_OMP_CANCEL:
16317 229 : if (context != pragma_compound)
16318 : {
16319 8 : construct = "omp cancel";
16320 8 : goto in_compound;
16321 : }
16322 221 : c_parser_omp_cancel (parser);
16323 221 : return false;
16324 :
16325 179 : case PRAGMA_OMP_CANCELLATION_POINT:
16326 179 : return c_parser_omp_cancellation_point (parser, context);
16327 :
16328 9 : case PRAGMA_OMP_GROUPPRIVATE:
16329 9 : c_parser_omp_groupprivate (parser);
16330 9 : return false;
16331 :
16332 79 : case PRAGMA_OMP_THREADPRIVATE:
16333 79 : c_parser_omp_threadprivate (parser);
16334 79 : return false;
16335 :
16336 7763 : case PRAGMA_OMP_TARGET:
16337 7763 : return c_parser_omp_target (parser, context, if_p);
16338 :
16339 132 : case PRAGMA_OMP_BEGIN:
16340 132 : c_parser_omp_begin (parser);
16341 132 : return false;
16342 :
16343 226 : case PRAGMA_OMP_END:
16344 226 : c_parser_omp_end (parser);
16345 226 : return false;
16346 :
16347 22 : case PRAGMA_OMP_SCAN:
16348 22 : error_at (c_parser_peek_token (parser)->location,
16349 : "%<#pragma omp scan%> may only be used in "
16350 : "a loop construct with %<inscan%> %<reduction%> clause");
16351 22 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16352 22 : return false;
16353 :
16354 5 : case PRAGMA_OMP_SECTION:
16355 5 : error_at (c_parser_peek_token (parser)->location,
16356 : "%<#pragma omp section%> may only be used in "
16357 : "%<#pragma omp sections%> construct");
16358 5 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16359 5 : return false;
16360 :
16361 1352 : case PRAGMA_OMP_DECLARE:
16362 1352 : return c_parser_omp_declare (parser, context);
16363 :
16364 72 : case PRAGMA_OMP_REQUIRES:
16365 72 : if (context != pragma_external)
16366 : {
16367 8 : error_at (c_parser_peek_token (parser)->location,
16368 : "%<#pragma %s%> may only be used at file scope",
16369 : "omp requires");
16370 8 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16371 8 : return false;
16372 : }
16373 64 : c_parser_omp_requires (parser);
16374 64 : return false;
16375 :
16376 118 : case PRAGMA_OMP_ALLOCATE:
16377 118 : c_parser_omp_allocate (parser);
16378 118 : return false;
16379 :
16380 39 : case PRAGMA_OMP_ASSUMES:
16381 39 : if (context != pragma_external)
16382 : {
16383 1 : error_at (c_parser_peek_token (parser)->location,
16384 : "%<#pragma %s%> may only be used at file scope",
16385 : "omp assumes");
16386 1 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16387 1 : return false;
16388 : }
16389 38 : c_parser_omp_assumes (parser);
16390 38 : return false;
16391 :
16392 79 : case PRAGMA_OMP_NOTHING:
16393 79 : c_parser_omp_nothing (parser);
16394 79 : return false;
16395 :
16396 110 : case PRAGMA_OMP_METADIRECTIVE:
16397 110 : c_parser_omp_metadirective (parser, if_p);
16398 110 : return true;
16399 :
16400 126 : case PRAGMA_OMP_ERROR:
16401 126 : return c_parser_omp_error (parser, context);
16402 :
16403 545 : case PRAGMA_OMP_ORDERED:
16404 545 : return c_parser_omp_ordered (parser, context, if_p);
16405 :
16406 3428 : case PRAGMA_NOVECTOR:
16407 3428 : case PRAGMA_UNROLL:
16408 3428 : case PRAGMA_IVDEP:
16409 3428 : {
16410 3428 : bool novector = false;
16411 3428 : unsigned short unroll = 0;
16412 3428 : bool ivdep = false;
16413 :
16414 3428 : switch (id)
16415 : {
16416 3016 : case PRAGMA_NOVECTOR:
16417 3016 : novector = c_parse_pragma_novector (parser);
16418 3016 : break;
16419 287 : case PRAGMA_UNROLL:
16420 287 : unroll = c_parser_pragma_unroll (parser);
16421 287 : break;
16422 125 : case PRAGMA_IVDEP:
16423 125 : ivdep = c_parse_pragma_ivdep (parser);
16424 125 : break;
16425 : default:
16426 : gcc_unreachable ();
16427 : }
16428 :
16429 3428 : c_token *tok = c_parser_peek_token (parser);
16430 3428 : bool has_more = tok->type == CPP_PRAGMA;
16431 3445 : while (has_more)
16432 : {
16433 17 : switch (tok->pragma_kind)
16434 : {
16435 3 : case PRAGMA_IVDEP:
16436 3 : ivdep = c_parse_pragma_ivdep (parser);
16437 3 : break;
16438 10 : case PRAGMA_UNROLL:
16439 10 : unroll = c_parser_pragma_unroll (parser);
16440 10 : break;
16441 4 : case PRAGMA_NOVECTOR:
16442 4 : novector = c_parse_pragma_novector (parser);
16443 4 : break;
16444 : default:
16445 : has_more = false;
16446 : break;
16447 : }
16448 17 : tok = c_parser_peek_token (parser);
16449 28 : has_more = has_more && tok->type == CPP_PRAGMA;
16450 : }
16451 3428 : if (!c_parser_next_token_is_keyword (parser, RID_FOR)
16452 74 : && !c_parser_next_token_is_keyword (parser, RID_WHILE)
16453 3487 : && !c_parser_next_token_is_keyword (parser, RID_DO))
16454 : {
16455 0 : c_parser_error (parser, "for, while or do statement expected");
16456 0 : return false;
16457 : }
16458 3428 : if (c_parser_next_token_is_keyword (parser, RID_FOR))
16459 3354 : c_parser_for_statement (parser, ivdep, unroll, novector, if_p,
16460 : before_labels);
16461 74 : else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
16462 15 : c_parser_while_statement (parser, ivdep, unroll, novector, if_p,
16463 : before_labels);
16464 : else
16465 59 : c_parser_do_statement (parser, ivdep, unroll, novector,
16466 : before_labels);
16467 : }
16468 : return true;
16469 :
16470 1 : case PRAGMA_GCC_PCH_PREPROCESS:
16471 1 : c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
16472 1 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16473 1 : return false;
16474 :
16475 89 : case PRAGMA_OACC_WAIT:
16476 89 : if (context != pragma_compound)
16477 : {
16478 3 : construct = "acc wait";
16479 3 : goto in_compound;
16480 : }
16481 : /* FALL THROUGH. */
16482 :
16483 1962416 : default:
16484 1962416 : if (id < PRAGMA_FIRST_EXTERNAL)
16485 : {
16486 17483 : if (context != pragma_stmt && context != pragma_compound)
16487 : {
16488 2 : bad_stmt:
16489 5 : c_parser_error (parser, "expected declaration specifiers");
16490 5 : c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16491 5 : return false;
16492 : }
16493 17481 : c_parser_omp_construct (parser, if_p);
16494 17481 : return true;
16495 : }
16496 1944933 : break;
16497 : }
16498 :
16499 1944933 : c_parser_consume_pragma (parser);
16500 1944933 : c_invoke_pragma_handler (id);
16501 :
16502 : /* Skip to EOL, but suppress any error message. Those will have been
16503 : generated by the handler routine through calling error, as opposed
16504 : to calling c_parser_error. */
16505 1944933 : parser->error = true;
16506 1944933 : c_parser_skip_to_pragma_eol (parser);
16507 :
16508 1944933 : return false;
16509 : }
16510 :
16511 : /* The interface the pragma parsers have to the lexer. */
16512 :
16513 : enum cpp_ttype
16514 3680256 : pragma_lex (tree *value, location_t *loc)
16515 : {
16516 3680256 : c_token *tok = c_parser_peek_token (the_parser);
16517 3680256 : enum cpp_ttype ret = tok->type;
16518 :
16519 3680256 : *value = tok->value;
16520 3680256 : if (loc)
16521 1537155 : *loc = tok->location;
16522 :
16523 3680256 : if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
16524 : ret = CPP_EOF;
16525 2076206 : else if (ret == CPP_STRING)
16526 651611 : *value = c_parser_string_literal (the_parser, false, false).value;
16527 : else
16528 : {
16529 1424595 : if (ret == CPP_KEYWORD)
16530 366 : ret = CPP_NAME;
16531 1424595 : c_parser_consume_token (the_parser);
16532 : }
16533 :
16534 3680256 : return ret;
16535 : }
16536 :
16537 : void
16538 11056 : pragma_lex_discard_to_eol ()
16539 : {
16540 11056 : cpp_ttype type;
16541 11056 : do
16542 : {
16543 11056 : type = c_parser_peek_token (the_parser)->type;
16544 11056 : gcc_assert (type != CPP_EOF);
16545 11056 : c_parser_consume_token (the_parser);
16546 11056 : } while (type != CPP_PRAGMA_EOL);
16547 11056 : }
16548 :
16549 : static void
16550 12 : c_parser_pragma_pch_preprocess (c_parser *parser)
16551 : {
16552 12 : tree name = NULL;
16553 :
16554 12 : parser->lex_joined_string = true;
16555 12 : c_parser_consume_pragma (parser);
16556 12 : if (c_parser_next_token_is (parser, CPP_STRING))
16557 : {
16558 12 : name = c_parser_peek_token (parser)->value;
16559 12 : c_parser_consume_token (parser);
16560 : }
16561 : else
16562 0 : c_parser_error (parser, "expected string literal");
16563 12 : c_parser_skip_to_pragma_eol (parser);
16564 12 : parser->lex_joined_string = false;
16565 :
16566 12 : if (name)
16567 12 : c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
16568 12 : }
16569 :
16570 : /* OpenACC and OpenMP parsing routines. */
16571 :
16572 : /* Returns name of the next clause.
16573 : If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
16574 : the token is not consumed. Otherwise appropriate pragma_omp_clause is
16575 : returned and the token is consumed. */
16576 :
16577 : static pragma_omp_clause
16578 34866 : c_parser_omp_clause_name (c_parser *parser)
16579 : {
16580 34866 : pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
16581 :
16582 34866 : if (c_parser_next_token_is_keyword (parser, RID_AUTO))
16583 : result = PRAGMA_OACC_CLAUSE_AUTO;
16584 34741 : else if (c_parser_next_token_is_keyword (parser, RID_IF))
16585 : result = PRAGMA_OMP_CLAUSE_IF;
16586 33848 : else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
16587 : result = PRAGMA_OMP_CLAUSE_DEFAULT;
16588 33119 : else if (c_parser_next_token_is_keyword (parser, RID_FOR))
16589 : result = PRAGMA_OMP_CLAUSE_FOR;
16590 33035 : else if (c_parser_next_token_is (parser, CPP_NAME))
16591 : {
16592 32949 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16593 :
16594 32949 : switch (p[0])
16595 : {
16596 1134 : case 'a':
16597 1134 : if (!strcmp ("affinity", p))
16598 : result = PRAGMA_OMP_CLAUSE_AFFINITY;
16599 983 : else if (!strcmp ("aligned", p))
16600 : result = PRAGMA_OMP_CLAUSE_ALIGNED;
16601 755 : else if (!strcmp ("allocate", p))
16602 : result = PRAGMA_OMP_CLAUSE_ALLOCATE;
16603 270 : else if (!strcmp ("async", p))
16604 : result = PRAGMA_OACC_CLAUSE_ASYNC;
16605 30 : else if (!strcmp ("attach", p))
16606 34866 : result = PRAGMA_OACC_CLAUSE_ATTACH;
16607 : break;
16608 118 : case 'b':
16609 118 : if (!strcmp ("bind", p))
16610 34866 : result = PRAGMA_OMP_CLAUSE_BIND;
16611 : break;
16612 4596 : case 'c':
16613 4596 : if (!strcmp ("collapse", p))
16614 : result = PRAGMA_OMP_CLAUSE_COLLAPSE;
16615 1642 : else if (!strcmp ("copy", p))
16616 : result = PRAGMA_OACC_CLAUSE_COPY;
16617 858 : else if (!strcmp ("copyin", p))
16618 : result = PRAGMA_OMP_CLAUSE_COPYIN;
16619 422 : else if (!strcmp ("copyout", p))
16620 : result = PRAGMA_OACC_CLAUSE_COPYOUT;
16621 99 : else if (!strcmp ("copyprivate", p))
16622 : result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
16623 75 : else if (!strcmp ("create", p))
16624 34866 : result = PRAGMA_OACC_CLAUSE_CREATE;
16625 : break;
16626 3564 : case 'd':
16627 3564 : if (!strcmp ("defaultmap", p))
16628 : result = PRAGMA_OMP_CLAUSE_DEFAULTMAP;
16629 3323 : else if (!strcmp ("delete", p))
16630 : result = PRAGMA_OACC_CLAUSE_DELETE;
16631 3255 : else if (!strcmp ("depend", p))
16632 : result = PRAGMA_OMP_CLAUSE_DEPEND;
16633 2398 : else if (!strcmp ("destroy", p))
16634 : result = PRAGMA_OMP_CLAUSE_DESTROY;
16635 2357 : else if (!strcmp ("detach", p))
16636 : result = PRAGMA_OACC_CLAUSE_DETACH;
16637 2303 : else if (!strcmp ("device", p))
16638 : result = PRAGMA_OMP_CLAUSE_DEVICE;
16639 1879 : else if (!strcmp ("deviceptr", p))
16640 : result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
16641 1822 : else if (!strcmp ("device_resident", p))
16642 : result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT;
16643 1806 : else if (!strcmp ("device_type", p))
16644 : result = PRAGMA_OMP_CLAUSE_DEVICE_TYPE;
16645 1753 : else if (!strcmp ("dist_schedule", p))
16646 : result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
16647 167 : else if (!strcmp ("doacross", p))
16648 : result = PRAGMA_OMP_CLAUSE_DOACROSS;
16649 22 : else if (!strcmp ("dyn_groupprivate", p))
16650 34866 : result = PRAGMA_OMP_CLAUSE_DYN_GROUPPRIVATE;
16651 : break;
16652 63 : case 'e':
16653 63 : if (!strcmp ("enter", p))
16654 34866 : result = PRAGMA_OMP_CLAUSE_ENTER;
16655 : break;
16656 3511 : case 'f':
16657 3511 : if (!strcmp ("filter", p))
16658 : result = PRAGMA_OMP_CLAUSE_FILTER;
16659 3448 : else if (!strcmp ("final", p))
16660 : result = PRAGMA_OMP_CLAUSE_FINAL;
16661 3349 : else if (!strcmp ("finalize", p))
16662 : result = PRAGMA_OACC_CLAUSE_FINALIZE;
16663 3337 : else if (!strcmp ("firstprivate", p))
16664 : result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
16665 2532 : else if (!strcmp ("from", p))
16666 : result = PRAGMA_OMP_CLAUSE_FROM;
16667 73 : else if (!strcmp ("full", p))
16668 34866 : result = PRAGMA_OMP_CLAUSE_FULL;
16669 : break;
16670 651 : case 'g':
16671 651 : if (!strcmp ("gang", p))
16672 : result = PRAGMA_OACC_CLAUSE_GANG;
16673 62 : else if (!strcmp ("grainsize", p))
16674 34866 : result = PRAGMA_OMP_CLAUSE_GRAINSIZE;
16675 : break;
16676 158 : case 'h':
16677 158 : if (!strcmp ("has_device_addr", p))
16678 : result = PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR;
16679 70 : else if (!strcmp ("hint", p))
16680 : result = PRAGMA_OMP_CLAUSE_HINT;
16681 41 : else if (!strcmp ("host", p))
16682 34866 : result = PRAGMA_OACC_CLAUSE_HOST;
16683 : break;
16684 819 : case 'i':
16685 819 : if (!strcmp ("if_present", p))
16686 : result = PRAGMA_OACC_CLAUSE_IF_PRESENT;
16687 800 : else if (!strcmp ("in_reduction", p))
16688 : result = PRAGMA_OMP_CLAUSE_IN_REDUCTION;
16689 478 : else if (!strcmp ("inbranch", p))
16690 : result = PRAGMA_OMP_CLAUSE_INBRANCH;
16691 396 : else if (!strcmp ("independent", p))
16692 : result = PRAGMA_OACC_CLAUSE_INDEPENDENT;
16693 351 : else if (!strcmp ("indirect", p))
16694 : result = PRAGMA_OMP_CLAUSE_INDIRECT;
16695 325 : else if (!strcmp ("init", p))
16696 : result = PRAGMA_OMP_CLAUSE_INIT;
16697 158 : else if (!strcmp ("is_device_ptr", p))
16698 : result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR;
16699 43 : else if (!strcmp ("interop", p))
16700 34866 : result = PRAGMA_OMP_CLAUSE_INTEROP;
16701 : break;
16702 1270 : case 'l':
16703 1270 : if (!strcmp ("lastprivate", p))
16704 : result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
16705 537 : else if (!strcmp ("linear", p))
16706 : result = PRAGMA_OMP_CLAUSE_LINEAR;
16707 59 : else if (!strcmp ("link", p))
16708 : result = PRAGMA_OMP_CLAUSE_LINK;
16709 12 : else if (!strcmp ("local", p))
16710 34866 : result = PRAGMA_OMP_CLAUSE_LOCAL;
16711 : break;
16712 2123 : case 'm':
16713 2123 : if (!strcmp ("map", p))
16714 : result = PRAGMA_OMP_CLAUSE_MAP;
16715 79 : else if (!strcmp ("mergeable", p))
16716 34866 : result = PRAGMA_OMP_CLAUSE_MERGEABLE;
16717 : break;
16718 1961 : case 'n':
16719 1961 : if (!strcmp ("no_create", p))
16720 : result = PRAGMA_OACC_CLAUSE_NO_CREATE;
16721 1951 : else if (!strcmp ("nocontext", p))
16722 : result = PRAGMA_OMP_CLAUSE_NOCONTEXT;
16723 1928 : else if (!strcmp ("nogroup", p))
16724 : result = PRAGMA_OMP_CLAUSE_NOGROUP;
16725 1910 : else if (!strcmp ("nohost", p))
16726 : result = PRAGMA_OACC_CLAUSE_NOHOST;
16727 1885 : else if (!strcmp ("nontemporal", p))
16728 : result = PRAGMA_OMP_CLAUSE_NONTEMPORAL;
16729 1764 : else if (!strcmp ("notinbranch", p))
16730 : result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
16731 1623 : else if (!strcmp ("novariants", p))
16732 : result = PRAGMA_OMP_CLAUSE_NOVARIANTS;
16733 1599 : else if (!strcmp ("nowait", p))
16734 : result = PRAGMA_OMP_CLAUSE_NOWAIT;
16735 1204 : else if (!strcmp ("num_gangs", p))
16736 : result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
16737 902 : else if (!strcmp ("num_tasks", p))
16738 : result = PRAGMA_OMP_CLAUSE_NUM_TASKS;
16739 852 : else if (!strcmp ("num_teams", p))
16740 : result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
16741 660 : else if (!strcmp ("num_threads", p))
16742 : result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
16743 207 : else if (!strcmp ("num_workers", p))
16744 34866 : result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
16745 : break;
16746 692 : case 'o':
16747 692 : if (!strcmp ("ordered", p))
16748 : result = PRAGMA_OMP_CLAUSE_ORDERED;
16749 382 : else if (!strcmp ("order", p))
16750 34866 : result = PRAGMA_OMP_CLAUSE_ORDER;
16751 : break;
16752 1658 : case 'p':
16753 1658 : if (!strcmp ("parallel", p))
16754 : result = PRAGMA_OMP_CLAUSE_PARALLEL;
16755 1543 : else if (!strcmp ("partial", p))
16756 : result = PRAGMA_OMP_CLAUSE_PARTIAL;
16757 1313 : else if (!strcmp ("present", p))
16758 : result = PRAGMA_OACC_CLAUSE_PRESENT;
16759 : /* As of OpenACC 2.5, these are now aliases of the non-present_or
16760 : clauses. */
16761 1185 : else if (!strcmp ("present_or_copy", p)
16762 1172 : || !strcmp ("pcopy", p))
16763 : result = PRAGMA_OACC_CLAUSE_COPY;
16764 1163 : else if (!strcmp ("present_or_copyin", p)
16765 1147 : || !strcmp ("pcopyin", p))
16766 : result = PRAGMA_OACC_CLAUSE_COPYIN;
16767 1138 : else if (!strcmp ("present_or_copyout", p)
16768 1085 : || !strcmp ("pcopyout", p))
16769 : result = PRAGMA_OACC_CLAUSE_COPYOUT;
16770 1071 : else if (!strcmp ("present_or_create", p)
16771 1057 : || !strcmp ("pcreate", p))
16772 : result = PRAGMA_OACC_CLAUSE_CREATE;
16773 1052 : else if (!strcmp ("priority", p))
16774 : result = PRAGMA_OMP_CLAUSE_PRIORITY;
16775 954 : else if (!strcmp ("private", p))
16776 : result = PRAGMA_OMP_CLAUSE_PRIVATE;
16777 205 : else if (!strcmp ("proc_bind", p))
16778 34866 : result = PRAGMA_OMP_CLAUSE_PROC_BIND;
16779 : break;
16780 2702 : case 'r':
16781 2702 : if (!strcmp ("reduction", p))
16782 34866 : result = PRAGMA_OMP_CLAUSE_REDUCTION;
16783 : break;
16784 5245 : case 's':
16785 5245 : if (!strcmp ("safelen", p))
16786 : result = PRAGMA_OMP_CLAUSE_SAFELEN;
16787 5018 : else if (!strcmp ("schedule", p))
16788 : result = PRAGMA_OMP_CLAUSE_SCHEDULE;
16789 1535 : else if (!strcmp ("sections", p))
16790 : result = PRAGMA_OMP_CLAUSE_SECTIONS;
16791 1457 : else if (!strcmp ("self", p))
16792 : result = PRAGMA_OACC_CLAUSE_SELF;
16793 1391 : else if (!strcmp ("seq", p))
16794 : result = PRAGMA_OACC_CLAUSE_SEQ;
16795 1130 : else if (!strcmp ("shared", p))
16796 : result = PRAGMA_OMP_CLAUSE_SHARED;
16797 419 : else if (!strcmp ("simd", p))
16798 : result = PRAGMA_OMP_CLAUSE_SIMD;
16799 362 : else if (!strcmp ("simdlen", p))
16800 34866 : result = PRAGMA_OMP_CLAUSE_SIMDLEN;
16801 : break;
16802 1014 : case 't':
16803 1014 : if (!strcmp ("task_reduction", p))
16804 : result = PRAGMA_OMP_CLAUSE_TASK_REDUCTION;
16805 928 : else if (!strcmp ("taskgroup", p))
16806 : result = PRAGMA_OMP_CLAUSE_TASKGROUP;
16807 818 : else if (!strcmp ("thread_limit", p))
16808 : result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
16809 663 : else if (!strcmp ("threads", p))
16810 : result = PRAGMA_OMP_CLAUSE_THREADS;
16811 617 : else if (!strcmp ("tile", p))
16812 : result = PRAGMA_OACC_CLAUSE_TILE;
16813 494 : else if (!strcmp ("to", p))
16814 34866 : result = PRAGMA_OMP_CLAUSE_TO;
16815 : break;
16816 378 : case 'u':
16817 378 : if (!strcmp ("uniform", p))
16818 : result = PRAGMA_OMP_CLAUSE_UNIFORM;
16819 261 : else if (!strcmp ("untied", p))
16820 : result = PRAGMA_OMP_CLAUSE_UNTIED;
16821 164 : else if (!strcmp ("use", p))
16822 : result = PRAGMA_OMP_CLAUSE_USE;
16823 121 : else if (!strcmp ("use_device", p))
16824 : result = PRAGMA_OACC_CLAUSE_USE_DEVICE;
16825 100 : else if (!strcmp ("use_device_addr", p))
16826 : result = PRAGMA_OMP_CLAUSE_USE_DEVICE_ADDR;
16827 65 : else if (!strcmp ("use_device_ptr", p))
16828 : result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR;
16829 55 : else if (!strcmp ("uses_allocators", p))
16830 34866 : result = PRAGMA_OMP_CLAUSE_USES_ALLOCATORS;
16831 : break;
16832 741 : case 'v':
16833 741 : if (!strcmp ("vector", p))
16834 : result = PRAGMA_OACC_CLAUSE_VECTOR;
16835 223 : else if (!strcmp ("vector_length", p))
16836 34866 : result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
16837 : break;
16838 550 : case 'w':
16839 550 : if (!strcmp ("wait", p))
16840 : result = PRAGMA_OACC_CLAUSE_WAIT;
16841 453 : else if (!strcmp ("worker", p))
16842 34866 : result = PRAGMA_OACC_CLAUSE_WORKER;
16843 : break;
16844 : }
16845 : }
16846 :
16847 34866 : if (result != PRAGMA_OMP_CLAUSE_NONE)
16848 34750 : c_parser_consume_token (parser);
16849 :
16850 34866 : return result;
16851 : }
16852 :
16853 : /* Validate that a clause of the given type does not already exist. */
16854 :
16855 : static void
16856 17711 : check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
16857 : const char *name)
16858 : {
16859 17711 : if (tree c = omp_find_clause (clauses, code))
16860 348 : error_at (OMP_CLAUSE_LOCATION (c), "too many %qs clauses", name);
16861 17711 : }
16862 :
16863 : /* OpenACC 2.0
16864 : Parse wait clause or wait directive parameters. */
16865 :
16866 : static tree
16867 131 : c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
16868 : {
16869 131 : vec<tree, va_gc> *args;
16870 131 : tree t, args_tree;
16871 :
16872 131 : matching_parens parens;
16873 131 : if (!parens.require_open (parser))
16874 : return list;
16875 :
16876 131 : args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
16877 131 : args_tree = build_tree_list_vec (args);
16878 :
16879 436 : for (t = args_tree; t; t = TREE_CHAIN (t))
16880 : {
16881 174 : tree targ = TREE_VALUE (t);
16882 :
16883 174 : if (targ != error_mark_node)
16884 : {
16885 160 : if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
16886 : {
16887 6 : c_parser_error (parser, "expression must be integral");
16888 6 : targ = error_mark_node;
16889 : }
16890 : else
16891 : {
16892 154 : tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
16893 :
16894 154 : OMP_CLAUSE_DECL (c) = targ;
16895 154 : OMP_CLAUSE_CHAIN (c) = list;
16896 154 : list = c;
16897 : }
16898 : }
16899 : }
16900 :
16901 131 : release_tree_vector (args);
16902 131 : parens.require_close (parser);
16903 131 : return list;
16904 : }
16905 :
16906 : /* OpenACC 2.0, OpenMP 2.5:
16907 : variable-list:
16908 : identifier
16909 : variable-list , identifier
16910 :
16911 : If KIND is nonzero, create the appropriate node and install the
16912 : decl in OMP_CLAUSE_DECL and add the node to the head of the list.
16913 : If KIND is nonzero, CLAUSE_LOC is the location of the clause.
16914 :
16915 : If KIND is zero (= OMP_CLAUSE_ERROR), create a TREE_LIST with the decl
16916 : in TREE_PURPOSE and the location in TREE_VALUE (accessible using
16917 : EXPR_LOCATION); return the list created.
16918 :
16919 : The optional ALLOW_DEREF argument is true if list items can use the deref
16920 : (->) operator. */
16921 :
16922 : struct omp_dim
16923 : {
16924 : tree low_bound, length;
16925 : location_t loc;
16926 : bool no_colon;
16927 3335 : omp_dim (tree lb, tree len, location_t lo, bool nc)
16928 3335 : : low_bound (lb), length (len), loc (lo), no_colon (nc) {}
16929 : };
16930 :
16931 : static tree
16932 16813 : c_parser_omp_variable_list (c_parser *parser,
16933 : location_t clause_loc,
16934 : enum omp_clause_code kind, tree list,
16935 : bool map_lvalue = false)
16936 : {
16937 16813 : auto_vec<omp_dim> dims;
16938 16813 : bool array_section_p;
16939 16813 : auto_vec<c_token> tokens;
16940 16813 : unsigned int tokens_avail = 0;
16941 16813 : c_token *saved_tokens = NULL;
16942 :
16943 20172 : while (1)
16944 : {
16945 20172 : tree t = NULL_TREE;
16946 20172 : location_t tloc = c_parser_peek_token (parser)->location;
16947 :
16948 20172 : if (kind == OMP_CLAUSE_DEPEND || kind == OMP_CLAUSE_AFFINITY)
16949 : {
16950 893 : if (c_parser_next_token_is_not (parser, CPP_NAME)
16951 893 : || c_parser_peek_token (parser)->id_kind != C_ID_ID)
16952 : {
16953 29 : struct c_expr expr;
16954 29 : if (kind == OMP_CLAUSE_DEPEND
16955 27 : && c_parser_next_token_is_keyword (parser,
16956 : RID_OMP_ALL_MEMORY)
16957 45 : && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
16958 13 : || (c_parser_peek_2nd_token (parser)->type
16959 : == CPP_CLOSE_PAREN)))
16960 : {
16961 15 : expr.value = ridpointers[RID_OMP_ALL_MEMORY];
16962 15 : c_parser_consume_token (parser);
16963 : }
16964 : else
16965 14 : expr = c_parser_expr_no_commas (parser, NULL);
16966 29 : if (expr.value != error_mark_node)
16967 : {
16968 27 : tree u = build_omp_clause (clause_loc, kind);
16969 27 : OMP_CLAUSE_DECL (u) = expr.value;
16970 27 : OMP_CLAUSE_CHAIN (u) = list;
16971 27 : list = u;
16972 : }
16973 :
16974 29 : if (c_parser_next_token_is_not (parser, CPP_COMMA))
16975 : break;
16976 :
16977 4 : c_parser_consume_token (parser);
16978 4 : continue;
16979 4 : }
16980 :
16981 864 : tokens.truncate (0);
16982 864 : unsigned int nesting_depth = 0;
16983 11312 : while (1)
16984 : {
16985 6088 : c_token *token = c_parser_peek_token (parser);
16986 6088 : switch (token->type)
16987 : {
16988 : case CPP_EOF:
16989 : case CPP_PRAGMA_EOL:
16990 : break;
16991 938 : case CPP_OPEN_BRACE:
16992 938 : case CPP_OPEN_PAREN:
16993 938 : case CPP_OPEN_SQUARE:
16994 938 : ++nesting_depth;
16995 938 : goto add;
16996 1736 : case CPP_CLOSE_BRACE:
16997 1736 : case CPP_CLOSE_PAREN:
16998 1736 : case CPP_CLOSE_SQUARE:
16999 1736 : if (nesting_depth-- == 0)
17000 : break;
17001 938 : goto add;
17002 138 : case CPP_COMMA:
17003 138 : if (nesting_depth == 0)
17004 : break;
17005 72 : goto add;
17006 5224 : default:
17007 5224 : add:
17008 5224 : tokens.safe_push (*token);
17009 5224 : c_parser_consume_token (parser);
17010 5224 : continue;
17011 : }
17012 864 : break;
17013 5224 : }
17014 :
17015 : /* Make sure nothing tries to read past the end of the tokens. */
17016 864 : c_token eof_token;
17017 864 : memset (&eof_token, 0, sizeof (eof_token));
17018 864 : eof_token.type = CPP_EOF;
17019 864 : tokens.safe_push (eof_token);
17020 864 : tokens.safe_push (eof_token);
17021 :
17022 864 : saved_tokens = parser->tokens;
17023 864 : tokens_avail = parser->tokens_avail;
17024 864 : parser->tokens = tokens.address ();
17025 1728 : parser->tokens_avail = tokens.length ();
17026 : }
17027 19279 : else if (map_lvalue
17028 2456 : && (kind == OMP_CLAUSE_MAP
17029 : || kind == OMP_CLAUSE_TO
17030 2456 : || kind == OMP_CLAUSE_FROM))
17031 : {
17032 2456 : location_t loc = c_parser_peek_token (parser)->location;
17033 2456 : bool save_c_omp_array_section_p = c_omp_array_section_p;
17034 2456 : c_omp_array_section_p = true;
17035 2456 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
17036 2456 : if (expr.value != error_mark_node)
17037 2442 : mark_exp_read (expr.value);
17038 2456 : c_omp_array_section_p = save_c_omp_array_section_p;
17039 2456 : tree decl = expr.value;
17040 :
17041 : /* This code rewrites a parsed expression containing various tree
17042 : codes used to represent array accesses into a more uniform nest of
17043 : OMP_ARRAY_SECTION nodes before it is processed by
17044 : c-typeck.cc:handle_omp_array_sections_1. It might be more
17045 : efficient to move this logic to that function instead, analysing
17046 : the parsed expression directly rather than this preprocessed
17047 : form. (See also equivalent code in cp/parser.cc,
17048 : cp/semantics.cc). */
17049 2456 : dims.truncate (0);
17050 2456 : if (TREE_CODE (decl) == OMP_ARRAY_SECTION)
17051 : {
17052 1082 : while (TREE_CODE (decl) == OMP_ARRAY_SECTION)
17053 : {
17054 571 : tree low_bound = TREE_OPERAND (decl, 1);
17055 571 : tree length = TREE_OPERAND (decl, 2);
17056 571 : dims.safe_push (omp_dim (low_bound, length, loc, false));
17057 571 : decl = TREE_OPERAND (decl, 0);
17058 : }
17059 :
17060 544 : while (TREE_CODE (decl) == ARRAY_REF
17061 : || TREE_CODE (decl) == INDIRECT_REF
17062 544 : || TREE_CODE (decl) == COMPOUND_EXPR)
17063 : {
17064 33 : if (TREE_CODE (decl) == COMPOUND_EXPR)
17065 : {
17066 2 : decl = TREE_OPERAND (decl, 1);
17067 2 : STRIP_NOPS (decl);
17068 : }
17069 31 : else if (TREE_CODE (decl) == INDIRECT_REF)
17070 : {
17071 46 : dims.safe_push (omp_dim (integer_zero_node,
17072 23 : integer_one_node, loc, true));
17073 23 : decl = TREE_OPERAND (decl, 0);
17074 : }
17075 : else /* ARRAY_REF. */
17076 : {
17077 8 : tree index = TREE_OPERAND (decl, 1);
17078 16 : dims.safe_push (omp_dim (index, integer_one_node, loc,
17079 8 : true));
17080 8 : decl = TREE_OPERAND (decl, 0);
17081 : }
17082 : }
17083 :
17084 1624 : for (int i = dims.length () - 1; i >= 0; i--)
17085 602 : decl = build_omp_array_section (loc, decl, dims[i].low_bound,
17086 602 : dims[i].length);
17087 : }
17088 1945 : else if (TREE_CODE (decl) == INDIRECT_REF)
17089 : {
17090 : /* Turn indirection of a pointer "*foo" into "foo[0:1]". */
17091 55 : decl = TREE_OPERAND (decl, 0);
17092 55 : STRIP_NOPS (decl);
17093 :
17094 55 : decl = build_omp_array_section (loc, decl, integer_zero_node,
17095 : integer_one_node);
17096 : }
17097 1890 : else if (TREE_CODE (decl) == ARRAY_REF)
17098 : {
17099 13 : tree idx = TREE_OPERAND (decl, 1);
17100 :
17101 13 : decl = TREE_OPERAND (decl, 0);
17102 13 : STRIP_NOPS (decl);
17103 :
17104 13 : decl = build_omp_array_section (loc, decl, idx, integer_one_node);
17105 : }
17106 1877 : else if (TREE_CODE (decl) == NON_LVALUE_EXPR
17107 1877 : || CONVERT_EXPR_P (decl))
17108 0 : decl = TREE_OPERAND (decl, 0);
17109 :
17110 2456 : tree u = build_omp_clause (loc, kind);
17111 2456 : OMP_CLAUSE_DECL (u) = decl;
17112 2456 : OMP_CLAUSE_CHAIN (u) = list;
17113 2456 : list = u;
17114 :
17115 2456 : goto next_item;
17116 : }
17117 :
17118 17687 : if (c_parser_next_token_is (parser, CPP_NAME)
17119 17687 : && c_parser_peek_token (parser)->id_kind == C_ID_ID)
17120 : {
17121 17649 : t = lookup_name (c_parser_peek_token (parser)->value);
17122 :
17123 17649 : if (t == NULL_TREE)
17124 : {
17125 14 : undeclared_variable (c_parser_peek_token (parser)->location,
17126 14 : c_parser_peek_token (parser)->value);
17127 14 : t = error_mark_node;
17128 : }
17129 :
17130 17649 : c_parser_consume_token (parser);
17131 : }
17132 38 : else if (c_parser_next_token_is (parser, CPP_KEYWORD)
17133 38 : && (c_parser_peek_token (parser)->keyword == RID_FUNCTION_NAME
17134 15 : || (c_parser_peek_token (parser)->keyword
17135 : == RID_PRETTY_FUNCTION_NAME)
17136 9 : || (c_parser_peek_token (parser)->keyword
17137 : == RID_C99_FUNCTION_NAME)))
17138 20 : t = c_parser_predefined_identifier (parser).value;
17139 : else
17140 : {
17141 18 : c_parser_error (parser, "expected identifier");
17142 18 : break;
17143 : }
17144 :
17145 17669 : if (t == error_mark_node)
17146 : ;
17147 17651 : else if (kind != 0) /* kind != OMP_CLAUSE_ERROR */
17148 : {
17149 17418 : switch (kind)
17150 : {
17151 139 : case OMP_CLAUSE__CACHE_:
17152 : /* The OpenACC cache directive explicitly only allows "array
17153 : elements or subarrays". */
17154 139 : if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
17155 : {
17156 3 : c_parser_error (parser, "expected %<[%>");
17157 3 : t = error_mark_node;
17158 3 : break;
17159 : }
17160 : /* FALLTHROUGH */
17161 : case OMP_CLAUSE_MAP:
17162 : case OMP_CLAUSE_FROM:
17163 : case OMP_CLAUSE_TO:
17164 5683 : start_component_ref:
17165 6011 : while (c_parser_next_token_is (parser, CPP_DOT)
17166 11803 : || c_parser_next_token_is (parser, CPP_DEREF))
17167 : {
17168 328 : location_t op_loc = c_parser_peek_token (parser)->location;
17169 328 : location_t arrow_loc = UNKNOWN_LOCATION;
17170 328 : if (c_parser_next_token_is (parser, CPP_DEREF))
17171 : {
17172 109 : c_expr t_expr;
17173 109 : t_expr.value = t;
17174 109 : t_expr.original_code = ERROR_MARK;
17175 109 : t_expr.original_type = NULL;
17176 109 : set_c_expr_source_range (&t_expr, op_loc, op_loc);
17177 109 : t_expr.m_decimal = 0;
17178 109 : t_expr = convert_lvalue_to_rvalue (op_loc, t_expr,
17179 : true, false);
17180 109 : t = build_indirect_ref (op_loc, t_expr.value, RO_ARROW);
17181 109 : arrow_loc = t_expr.get_location ();
17182 : }
17183 328 : c_parser_consume_token (parser);
17184 328 : if (!c_parser_next_token_is (parser, CPP_NAME))
17185 : {
17186 0 : c_parser_error (parser, "expected identifier");
17187 0 : t = error_mark_node;
17188 0 : break;
17189 : }
17190 :
17191 328 : c_token *comp_tok = c_parser_peek_token (parser);
17192 328 : tree ident = comp_tok->value;
17193 328 : location_t comp_loc = comp_tok->location;
17194 328 : c_parser_consume_token (parser);
17195 328 : t = build_component_ref (op_loc, t, ident, comp_loc,
17196 : arrow_loc);
17197 : }
17198 : /* FALLTHROUGH */
17199 10360 : case OMP_CLAUSE_AFFINITY:
17200 10360 : case OMP_CLAUSE_DEPEND:
17201 10360 : case OMP_CLAUSE_REDUCTION:
17202 10360 : case OMP_CLAUSE_IN_REDUCTION:
17203 10360 : case OMP_CLAUSE_TASK_REDUCTION:
17204 10360 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
17205 10360 : array_section_p = false;
17206 10360 : dims.truncate (0);
17207 23453 : while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
17208 : {
17209 2733 : location_t loc = UNKNOWN_LOCATION;
17210 2733 : tree low_bound = NULL_TREE, length = NULL_TREE;
17211 2733 : bool no_colon = false;
17212 :
17213 2733 : c_parser_consume_token (parser);
17214 2733 : if (!c_parser_next_token_is (parser, CPP_COLON))
17215 : {
17216 2310 : location_t expr_loc
17217 2310 : = c_parser_peek_token (parser)->location;
17218 2310 : c_expr expr = c_parser_expression (parser);
17219 2310 : expr = convert_lvalue_to_rvalue (expr_loc, expr,
17220 : false, true);
17221 2310 : low_bound = expr.value;
17222 2310 : loc = expr_loc;
17223 : }
17224 2733 : if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
17225 : {
17226 435 : length = integer_one_node;
17227 435 : no_colon = true;
17228 : }
17229 : else
17230 : {
17231 : /* Look for `:'. */
17232 2298 : if (!c_parser_require (parser, CPP_COLON,
17233 : "expected %<:%>"))
17234 : {
17235 0 : t = error_mark_node;
17236 0 : break;
17237 : }
17238 2298 : array_section_p = true;
17239 2298 : if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
17240 : {
17241 2109 : location_t expr_loc
17242 2109 : = c_parser_peek_token (parser)->location;
17243 2109 : c_expr expr = c_parser_expression (parser);
17244 2109 : expr = convert_lvalue_to_rvalue (expr_loc, expr,
17245 : false, true);
17246 2109 : length = expr.value;
17247 : }
17248 : }
17249 : /* Look for the closing `]'. */
17250 2733 : if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
17251 : "expected %<]%>"))
17252 : {
17253 0 : t = error_mark_node;
17254 0 : break;
17255 : }
17256 :
17257 2733 : dims.safe_push (omp_dim (low_bound, length, loc, no_colon));
17258 : }
17259 :
17260 10360 : if (t != error_mark_node)
17261 : {
17262 10360 : if ((kind == OMP_CLAUSE_MAP
17263 10360 : || kind == OMP_CLAUSE_FROM
17264 5238 : || kind == OMP_CLAUSE_TO)
17265 5547 : && !array_section_p
17266 14650 : && (c_parser_next_token_is (parser, CPP_DOT)
17267 4286 : || c_parser_next_token_is (parser, CPP_DEREF)))
17268 : {
17269 8 : for (unsigned i = 0; i < dims.length (); i++)
17270 : {
17271 4 : gcc_assert (dims[i].length == integer_one_node);
17272 4 : t = build_array_ref (dims[i].loc,
17273 4 : t, dims[i].low_bound);
17274 : }
17275 4 : goto start_component_ref;
17276 : }
17277 : else
17278 13085 : for (unsigned i = 0; i < dims.length (); i++)
17279 5458 : t = build_omp_array_section (clause_loc, t,
17280 2729 : dims[i].low_bound,
17281 2729 : dims[i].length);
17282 : }
17283 :
17284 10356 : if ((kind == OMP_CLAUSE_DEPEND || kind == OMP_CLAUSE_AFFINITY)
17285 860 : && t != error_mark_node
17286 860 : && parser->tokens_avail != 2)
17287 : {
17288 44 : if (array_section_p)
17289 : {
17290 12 : error_at (c_parser_peek_token (parser)->location,
17291 : "expected %<)%> or %<,%>");
17292 12 : t = error_mark_node;
17293 : }
17294 : else
17295 : {
17296 32 : parser->tokens = tokens.address ();
17297 32 : parser->tokens_avail = tokens.length ();
17298 :
17299 32 : t = c_parser_expr_no_commas (parser, NULL).value;
17300 32 : if (t != error_mark_node && parser->tokens_avail != 2)
17301 : {
17302 0 : error_at (c_parser_peek_token (parser)->location,
17303 : "expected %<)%> or %<,%>");
17304 0 : t = error_mark_node;
17305 : }
17306 : }
17307 : }
17308 : break;
17309 : default:
17310 : break;
17311 : }
17312 :
17313 17418 : if (t != error_mark_node)
17314 : {
17315 17403 : tree u = build_omp_clause (clause_loc, kind);
17316 17403 : OMP_CLAUSE_DECL (u) = t;
17317 17403 : OMP_CLAUSE_CHAIN (u) = list;
17318 17403 : list = u;
17319 : }
17320 : }
17321 : else /* kind == OMP_CLAUSE_ERROR */
17322 233 : list = tree_cons (t, build_empty_stmt (tloc), list);
17323 :
17324 17669 : if (kind == OMP_CLAUSE_DEPEND || kind == OMP_CLAUSE_AFFINITY)
17325 : {
17326 864 : parser->tokens = saved_tokens;
17327 864 : parser->tokens_avail = tokens_avail;
17328 : }
17329 :
17330 16805 : next_item:
17331 20125 : if (c_parser_next_token_is_not (parser, CPP_COMMA))
17332 : break;
17333 :
17334 3355 : c_parser_consume_token (parser);
17335 : }
17336 :
17337 16813 : return list;
17338 16813 : }
17339 :
17340 : /* Similarly, but expect leading and trailing parenthesis. This is a very
17341 : common case for OpenACC and OpenMP clauses. The optional ALLOW_DEREF
17342 : argument is true if list items can use the deref (->) operator. */
17343 :
17344 : static tree
17345 3662 : c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
17346 : tree list, bool map_lvalue = false)
17347 : {
17348 : /* The clauses location. */
17349 3662 : location_t loc = c_parser_peek_token (parser)->location;
17350 :
17351 3662 : if (parser->in_omp_decl_attribute)
17352 : {
17353 42 : if (kind)
17354 : {
17355 22 : tree u = build_omp_clause (loc, kind);
17356 22 : OMP_CLAUSE_DECL (u) = parser->in_omp_decl_attribute;
17357 22 : OMP_CLAUSE_CHAIN (u) = list;
17358 22 : return u;
17359 : }
17360 : else
17361 20 : return tree_cons (parser->in_omp_decl_attribute, NULL_TREE, list);
17362 : }
17363 :
17364 3620 : matching_parens parens;
17365 3620 : if (parens.require_open (parser))
17366 : {
17367 3616 : list = c_parser_omp_variable_list (parser, loc, kind, list, map_lvalue);
17368 3616 : parens.skip_until_found_close (parser);
17369 : }
17370 : return list;
17371 : }
17372 :
17373 : /* OpenACC 2.0:
17374 : copy ( variable-list )
17375 : copyin ( variable-list )
17376 : copyout ( variable-list )
17377 : create ( variable-list )
17378 : delete ( variable-list )
17379 : present ( variable-list )
17380 :
17381 : OpenACC 2.6:
17382 : no_create ( variable-list )
17383 : attach ( variable-list )
17384 : detach ( variable-list )
17385 :
17386 : OpenACC 2.7:
17387 : copyin (readonly : variable-list )
17388 : */
17389 :
17390 : static tree
17391 2026 : c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
17392 : tree list)
17393 : {
17394 2026 : enum gomp_map_kind kind;
17395 2026 : switch (c_kind)
17396 : {
17397 : case PRAGMA_OACC_CLAUSE_ATTACH:
17398 : kind = GOMP_MAP_ATTACH;
17399 : break;
17400 806 : case PRAGMA_OACC_CLAUSE_COPY:
17401 806 : kind = GOMP_MAP_TOFROM;
17402 806 : break;
17403 359 : case PRAGMA_OACC_CLAUSE_COPYIN:
17404 359 : kind = GOMP_MAP_TO;
17405 359 : break;
17406 390 : case PRAGMA_OACC_CLAUSE_COPYOUT:
17407 390 : kind = GOMP_MAP_FROM;
17408 390 : break;
17409 94 : case PRAGMA_OACC_CLAUSE_CREATE:
17410 94 : kind = GOMP_MAP_ALLOC;
17411 94 : break;
17412 68 : case PRAGMA_OACC_CLAUSE_DELETE:
17413 68 : kind = GOMP_MAP_RELEASE;
17414 68 : break;
17415 20 : case PRAGMA_OACC_CLAUSE_DETACH:
17416 20 : kind = GOMP_MAP_DETACH;
17417 20 : break;
17418 36 : case PRAGMA_OACC_CLAUSE_DEVICE:
17419 36 : kind = GOMP_MAP_FORCE_TO;
17420 36 : break;
17421 16 : case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
17422 16 : kind = GOMP_MAP_DEVICE_RESIDENT;
17423 16 : break;
17424 13 : case PRAGMA_OACC_CLAUSE_LINK:
17425 13 : kind = GOMP_MAP_LINK;
17426 13 : break;
17427 10 : case PRAGMA_OACC_CLAUSE_NO_CREATE:
17428 10 : kind = GOMP_MAP_IF_PRESENT;
17429 10 : break;
17430 128 : case PRAGMA_OACC_CLAUSE_PRESENT:
17431 128 : kind = GOMP_MAP_FORCE_PRESENT;
17432 128 : break;
17433 59 : case PRAGMA_OACC_CLAUSE_SELF:
17434 : /* "The 'host' clause is a synonym for the 'self' clause." */
17435 59 : case PRAGMA_OACC_CLAUSE_HOST:
17436 59 : kind = GOMP_MAP_FORCE_FROM;
17437 59 : break;
17438 0 : default:
17439 0 : gcc_unreachable ();
17440 : }
17441 :
17442 2026 : tree nl = list;
17443 2026 : bool readonly = false;
17444 2026 : location_t open_loc = c_parser_peek_token (parser)->location;
17445 2026 : matching_parens parens;
17446 2026 : if (parens.require_open (parser))
17447 : {
17448 : /* Turn on readonly modifier parsing for copyin clause. */
17449 2026 : if (c_kind == PRAGMA_OACC_CLAUSE_COPYIN)
17450 : {
17451 359 : c_token *token = c_parser_peek_token (parser);
17452 359 : if (token->type == CPP_NAME
17453 359 : && !strcmp (IDENTIFIER_POINTER (token->value), "readonly")
17454 366 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
17455 : {
17456 7 : c_parser_consume_token (parser);
17457 7 : c_parser_consume_token (parser);
17458 7 : readonly = true;
17459 : }
17460 : }
17461 2026 : nl = c_parser_omp_variable_list (parser, open_loc, OMP_CLAUSE_MAP, list,
17462 : false);
17463 2026 : parens.skip_until_found_close (parser);
17464 : }
17465 :
17466 4671 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
17467 : {
17468 2645 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
17469 2645 : if (readonly)
17470 13 : OMP_CLAUSE_MAP_READONLY (c) = 1;
17471 : }
17472 :
17473 2026 : return nl;
17474 : }
17475 :
17476 : /* OpenACC 2.0:
17477 : deviceptr ( variable-list ) */
17478 :
17479 : static tree
17480 57 : c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
17481 : {
17482 57 : tree vars, t;
17483 :
17484 : /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
17485 : c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
17486 : variable-list must only allow for pointer variables. */
17487 57 : vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
17488 175 : for (t = vars; t && t; t = TREE_CHAIN (t))
17489 : {
17490 61 : tree v = TREE_PURPOSE (t);
17491 61 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
17492 :
17493 61 : if (!VAR_P (v) && TREE_CODE (v) != PARM_DECL)
17494 3 : error_at (loc, "%qD is not a variable", v);
17495 58 : else if (TREE_TYPE (v) == error_mark_node)
17496 : ;
17497 57 : else if (!POINTER_TYPE_P (TREE_TYPE (v)))
17498 7 : error_at (loc, "%qD is not a pointer variable", v);
17499 :
17500 61 : tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
17501 61 : OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
17502 61 : OMP_CLAUSE_DECL (u) = v;
17503 61 : OMP_CLAUSE_CHAIN (u) = list;
17504 61 : list = u;
17505 : }
17506 :
17507 57 : return list;
17508 : }
17509 :
17510 : /* OpenACC 2.0, OpenMP 3.0:
17511 : collapse ( constant-expression ) */
17512 :
17513 : static tree
17514 2954 : c_parser_omp_clause_collapse (c_parser *parser, tree list)
17515 : {
17516 2954 : tree c, num = error_mark_node;
17517 2954 : HOST_WIDE_INT n;
17518 2954 : location_t loc;
17519 :
17520 2954 : check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
17521 2954 : check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
17522 :
17523 2954 : loc = c_parser_peek_token (parser)->location;
17524 2954 : matching_parens parens;
17525 2954 : if (parens.require_open (parser))
17526 : {
17527 2954 : num = c_parser_expr_no_commas (parser, NULL).value;
17528 2954 : parens.skip_until_found_close (parser);
17529 : }
17530 2954 : if (num == error_mark_node)
17531 : return list;
17532 2954 : mark_exp_read (num);
17533 2954 : num = c_fully_fold (num, false, NULL);
17534 5908 : if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
17535 2954 : || !tree_fits_shwi_p (num)
17536 2954 : || (n = tree_to_shwi (num)) <= 0
17537 5908 : || (int) n != n)
17538 : {
17539 0 : error_at (loc,
17540 : "collapse argument needs positive constant integer expression");
17541 0 : return list;
17542 : }
17543 2954 : c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
17544 2954 : OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
17545 2954 : OMP_CLAUSE_CHAIN (c) = list;
17546 2954 : return c;
17547 : }
17548 :
17549 : /* OpenMP 2.5:
17550 : copyin ( variable-list ) */
17551 :
17552 : static tree
17553 102 : c_parser_omp_clause_copyin (c_parser *parser, tree list)
17554 : {
17555 102 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
17556 : }
17557 :
17558 : /* OpenMP 2.5:
17559 : copyprivate ( variable-list ) */
17560 :
17561 : static tree
17562 24 : c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
17563 : {
17564 24 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
17565 : }
17566 :
17567 : /* OpenMP 2.5:
17568 : default ( none | shared )
17569 :
17570 : OpenMP 5.1:
17571 : default ( private | firstprivate )
17572 :
17573 : OpenACC:
17574 : default ( none | present ) */
17575 :
17576 : static tree
17577 729 : c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc)
17578 : {
17579 729 : enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
17580 729 : location_t loc = c_parser_peek_token (parser)->location;
17581 729 : tree c;
17582 :
17583 729 : matching_parens parens;
17584 729 : if (!parens.require_open (parser))
17585 : return list;
17586 726 : if (c_parser_next_token_is (parser, CPP_NAME))
17587 : {
17588 714 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17589 :
17590 714 : switch (p[0])
17591 : {
17592 391 : case 'n':
17593 391 : if (strcmp ("none", p) != 0)
17594 0 : goto invalid_kind;
17595 : kind = OMP_CLAUSE_DEFAULT_NONE;
17596 : break;
17597 :
17598 23 : case 'p':
17599 23 : if (is_oacc)
17600 : {
17601 18 : if (strcmp ("present", p) != 0)
17602 3 : goto invalid_kind;
17603 : kind = OMP_CLAUSE_DEFAULT_PRESENT;
17604 : }
17605 : else
17606 : {
17607 5 : if (strcmp ("private", p) != 0)
17608 0 : goto invalid_kind;
17609 : kind = OMP_CLAUSE_DEFAULT_PRIVATE;
17610 : }
17611 : break;
17612 :
17613 9 : case 'f':
17614 9 : if (strcmp ("firstprivate", p) != 0 || is_oacc)
17615 0 : goto invalid_kind;
17616 : kind = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
17617 : break;
17618 :
17619 287 : case 's':
17620 287 : if (strcmp ("shared", p) != 0 || is_oacc)
17621 0 : goto invalid_kind;
17622 : kind = OMP_CLAUSE_DEFAULT_SHARED;
17623 : break;
17624 :
17625 4 : default:
17626 4 : goto invalid_kind;
17627 : }
17628 :
17629 701 : c_parser_consume_token (parser);
17630 : }
17631 : else
17632 : {
17633 25 : invalid_kind:
17634 25 : if (is_oacc)
17635 21 : c_parser_error (parser, "expected %<none%> or %<present%>");
17636 : else
17637 4 : c_parser_error (parser, "expected %<none%>, %<shared%>, "
17638 : "%<private%> or %<firstprivate%>");
17639 : }
17640 726 : parens.skip_until_found_close (parser);
17641 :
17642 726 : if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
17643 : return list;
17644 :
17645 701 : check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
17646 701 : c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
17647 701 : OMP_CLAUSE_CHAIN (c) = list;
17648 701 : OMP_CLAUSE_DEFAULT_KIND (c) = kind;
17649 :
17650 701 : return c;
17651 : }
17652 :
17653 : /* OpenMP 2.5:
17654 : firstprivate ( variable-list ) */
17655 :
17656 : static tree
17657 804 : c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
17658 : {
17659 691 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
17660 : }
17661 :
17662 : /* OpenMP 3.1:
17663 : final ( expression ) */
17664 :
17665 : static tree
17666 99 : c_parser_omp_clause_final (c_parser *parser, tree list)
17667 : {
17668 99 : location_t loc = c_parser_peek_token (parser)->location;
17669 99 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
17670 : {
17671 99 : matching_parens parens;
17672 99 : tree t, c;
17673 99 : if (!parens.require_open (parser))
17674 0 : t = error_mark_node;
17675 : else
17676 : {
17677 99 : location_t eloc = c_parser_peek_token (parser)->location;
17678 99 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
17679 99 : t = convert_lvalue_to_rvalue (eloc, expr, true, true).value;
17680 99 : t = c_objc_common_truthvalue_conversion (eloc, t);
17681 99 : t = c_fully_fold (t, false, NULL);
17682 99 : parens.skip_until_found_close (parser);
17683 : }
17684 :
17685 99 : check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
17686 :
17687 99 : c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
17688 99 : OMP_CLAUSE_FINAL_EXPR (c) = t;
17689 99 : OMP_CLAUSE_CHAIN (c) = list;
17690 99 : list = c;
17691 : }
17692 : else
17693 0 : c_parser_error (parser, "expected %<(%>");
17694 :
17695 99 : return list;
17696 : }
17697 :
17698 : /* OpenMP 5.1:
17699 : indirect [( expression )]
17700 : */
17701 :
17702 : static tree
17703 26 : c_parser_omp_clause_indirect (c_parser *parser, tree list)
17704 : {
17705 26 : location_t location = c_parser_peek_token (parser)->location;
17706 26 : tree t;
17707 :
17708 26 : if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
17709 : {
17710 17 : matching_parens parens;
17711 17 : if (!parens.require_open (parser))
17712 1 : return list;
17713 :
17714 17 : location_t loc = c_parser_peek_token (parser)->location;
17715 17 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
17716 17 : expr = convert_lvalue_to_rvalue (loc, expr, true, true);
17717 17 : t = c_objc_common_truthvalue_conversion (loc, expr.value);
17718 17 : t = c_fully_fold (t, false, NULL);
17719 34 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
17720 34 : || TREE_CODE (t) != INTEGER_CST)
17721 : {
17722 1 : c_parser_error (parser, "expected constant logical expression");
17723 1 : return list;
17724 : }
17725 16 : parens.skip_until_found_close (parser);
17726 : }
17727 : else
17728 9 : t = integer_one_node;
17729 :
17730 25 : check_no_duplicate_clause (list, OMP_CLAUSE_INDIRECT, "indirect");
17731 :
17732 25 : tree c = build_omp_clause (location, OMP_CLAUSE_INDIRECT);
17733 25 : OMP_CLAUSE_INDIRECT_EXPR (c) = t;
17734 25 : OMP_CLAUSE_CHAIN (c) = list;
17735 :
17736 25 : return c;
17737 : }
17738 :
17739 : /* OpenACC, OpenMP 2.5:
17740 : if ( expression )
17741 :
17742 : OpenMP 4.5:
17743 : if ( directive-name-modifier : expression )
17744 :
17745 : directive-name-modifier:
17746 : parallel | task | taskloop | target data | target | target update
17747 : | target enter data | target exit data
17748 :
17749 : OpenMP 5.0:
17750 : directive-name-modifier:
17751 : ... | simd | cancel */
17752 :
17753 : static tree
17754 893 : c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp)
17755 : {
17756 893 : location_t location = c_parser_peek_token (parser)->location;
17757 893 : enum tree_code if_modifier = ERROR_MARK;
17758 :
17759 893 : matching_parens parens;
17760 893 : if (!parens.require_open (parser))
17761 : return list;
17762 :
17763 1681 : if (is_omp && c_parser_next_token_is (parser, CPP_NAME))
17764 : {
17765 641 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17766 641 : int n = 2;
17767 641 : if (strcmp (p, "cancel") == 0)
17768 : if_modifier = VOID_CST;
17769 626 : else if (strcmp (p, "parallel") == 0)
17770 : if_modifier = OMP_PARALLEL;
17771 487 : else if (strcmp (p, "simd") == 0)
17772 : if_modifier = OMP_SIMD;
17773 381 : else if (strcmp (p, "task") == 0)
17774 : if_modifier = OMP_TASK;
17775 370 : else if (strcmp (p, "taskloop") == 0)
17776 : if_modifier = OMP_TASKLOOP;
17777 319 : else if (strcmp (p, "target") == 0)
17778 : {
17779 102 : if_modifier = OMP_TARGET;
17780 102 : if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
17781 : {
17782 37 : p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value);
17783 37 : if (strcmp ("data", p) == 0)
17784 : if_modifier = OMP_TARGET_DATA;
17785 29 : else if (strcmp ("update", p) == 0)
17786 : if_modifier = OMP_TARGET_UPDATE;
17787 18 : else if (strcmp ("enter", p) == 0)
17788 : if_modifier = OMP_TARGET_ENTER_DATA;
17789 10 : else if (strcmp ("exit", p) == 0)
17790 : if_modifier = OMP_TARGET_EXIT_DATA;
17791 0 : if (if_modifier != OMP_TARGET)
17792 : {
17793 37 : n = 3;
17794 37 : c_parser_consume_token (parser);
17795 : }
17796 : else
17797 : {
17798 0 : location_t loc = c_parser_peek_2nd_token (parser)->location;
17799 0 : error_at (loc, "expected %<data%>, %<update%>, %<enter%> "
17800 : "or %<exit%>");
17801 0 : if_modifier = ERROR_MARK;
17802 : }
17803 0 : if (if_modifier == OMP_TARGET_ENTER_DATA
17804 37 : || if_modifier == OMP_TARGET_EXIT_DATA)
17805 : {
17806 18 : if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
17807 : {
17808 18 : p = IDENTIFIER_POINTER
17809 : (c_parser_peek_2nd_token (parser)->value);
17810 18 : if (strcmp ("data", p) == 0)
17811 : n = 4;
17812 : }
17813 0 : if (n == 4)
17814 18 : c_parser_consume_token (parser);
17815 : else
17816 : {
17817 0 : location_t loc
17818 0 : = c_parser_peek_2nd_token (parser)->location;
17819 0 : error_at (loc, "expected %<data%>");
17820 0 : if_modifier = ERROR_MARK;
17821 : }
17822 : }
17823 : }
17824 : }
17825 37 : if (if_modifier != ERROR_MARK)
17826 : {
17827 424 : if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
17828 : {
17829 423 : c_parser_consume_token (parser);
17830 423 : c_parser_consume_token (parser);
17831 : }
17832 : else
17833 : {
17834 1 : if (n > 2)
17835 : {
17836 0 : location_t loc = c_parser_peek_2nd_token (parser)->location;
17837 0 : error_at (loc, "expected %<:%>");
17838 : }
17839 : if_modifier = ERROR_MARK;
17840 : }
17841 : }
17842 : }
17843 :
17844 893 : location_t loc = c_parser_peek_token (parser)->location;
17845 893 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
17846 893 : expr = convert_lvalue_to_rvalue (loc, expr, true, true);
17847 893 : tree t = c_objc_common_truthvalue_conversion (loc, expr.value), c;
17848 893 : t = c_fully_fold (t, false, NULL);
17849 893 : parens.skip_until_found_close (parser);
17850 :
17851 4900 : for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
17852 3154 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF)
17853 : {
17854 174 : if (if_modifier != ERROR_MARK
17855 174 : && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
17856 : {
17857 9 : const char *p = NULL;
17858 9 : switch (if_modifier)
17859 : {
17860 : case VOID_CST: p = "cancel"; break;
17861 1 : case OMP_PARALLEL: p = "parallel"; break;
17862 0 : case OMP_SIMD: p = "simd"; break;
17863 1 : case OMP_TASK: p = "task"; break;
17864 1 : case OMP_TASKLOOP: p = "taskloop"; break;
17865 1 : case OMP_TARGET_DATA: p = "target data"; break;
17866 1 : case OMP_TARGET: p = "target"; break;
17867 1 : case OMP_TARGET_UPDATE: p = "target update"; break;
17868 1 : case OMP_TARGET_ENTER_DATA: p = "target enter data"; break;
17869 1 : case OMP_TARGET_EXIT_DATA: p = "target exit data"; break;
17870 : default: gcc_unreachable ();
17871 : }
17872 9 : error_at (location, "too many %<if%> clauses with %qs modifier",
17873 : p);
17874 9 : return list;
17875 : }
17876 165 : else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
17877 : {
17878 13 : if (!is_omp)
17879 1 : error_at (location, "too many %<if%> clauses");
17880 : else
17881 12 : error_at (location, "too many %<if%> clauses without modifier");
17882 : return list;
17883 : }
17884 152 : else if (if_modifier == ERROR_MARK
17885 152 : || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK)
17886 : {
17887 18 : error_at (location, "if any %<if%> clause has modifier, then all "
17888 : "%<if%> clauses have to use modifier");
17889 18 : return list;
17890 : }
17891 : }
17892 :
17893 853 : c = build_omp_clause (location, OMP_CLAUSE_IF);
17894 853 : OMP_CLAUSE_IF_MODIFIER (c) = if_modifier;
17895 853 : OMP_CLAUSE_IF_EXPR (c) = t;
17896 853 : OMP_CLAUSE_CHAIN (c) = list;
17897 853 : return c;
17898 : }
17899 :
17900 : /* OpenMP 2.5:
17901 : lastprivate ( variable-list )
17902 :
17903 : OpenMP 5.0:
17904 : lastprivate ( [ lastprivate-modifier : ] variable-list ) */
17905 :
17906 : static tree
17907 733 : c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
17908 : {
17909 : /* The clauses location. */
17910 733 : location_t loc = c_parser_peek_token (parser)->location;
17911 :
17912 733 : if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17913 : {
17914 733 : bool conditional = false;
17915 733 : if (c_parser_next_token_is (parser, CPP_NAME)
17916 733 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
17917 : {
17918 107 : const char *p
17919 107 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17920 107 : if (strcmp (p, "conditional") == 0)
17921 : {
17922 107 : conditional = true;
17923 107 : c_parser_consume_token (parser);
17924 107 : c_parser_consume_token (parser);
17925 : }
17926 : }
17927 733 : tree nlist = c_parser_omp_variable_list (parser, loc,
17928 : OMP_CLAUSE_LASTPRIVATE, list);
17929 733 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
17930 733 : if (conditional)
17931 246 : for (tree c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
17932 139 : OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 1;
17933 : return nlist;
17934 : }
17935 : return list;
17936 : }
17937 :
17938 : /* OpenMP 3.1:
17939 : mergeable */
17940 :
17941 : static tree
17942 79 : c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
17943 : {
17944 79 : tree c;
17945 :
17946 : /* FIXME: Should we allow duplicates? */
17947 79 : check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
17948 :
17949 79 : c = build_omp_clause (c_parser_peek_token (parser)->location,
17950 : OMP_CLAUSE_MERGEABLE);
17951 79 : OMP_CLAUSE_CHAIN (c) = list;
17952 :
17953 79 : return c;
17954 : }
17955 :
17956 : /* OpenMP 2.5:
17957 : nowait */
17958 :
17959 : static tree
17960 395 : c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
17961 : {
17962 395 : tree c;
17963 395 : location_t loc = c_parser_peek_token (parser)->location;
17964 :
17965 395 : check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
17966 :
17967 395 : c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
17968 395 : OMP_CLAUSE_CHAIN (c) = list;
17969 395 : return c;
17970 : }
17971 :
17972 : /* OpenMP 2.5:
17973 : num_threads ( expression ) */
17974 :
17975 : static tree
17976 453 : c_parser_omp_clause_num_threads (c_parser *parser, tree list)
17977 : {
17978 453 : location_t num_threads_loc = c_parser_peek_token (parser)->location;
17979 453 : matching_parens parens;
17980 453 : if (parens.require_open (parser))
17981 : {
17982 453 : location_t expr_loc = c_parser_peek_token (parser)->location;
17983 453 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
17984 453 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
17985 453 : tree c, t = expr.value;
17986 453 : t = c_fully_fold (t, false, NULL);
17987 :
17988 453 : parens.skip_until_found_close (parser);
17989 :
17990 453 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
17991 : {
17992 0 : c_parser_error (parser, "expected integer expression");
17993 0 : return list;
17994 : }
17995 :
17996 : /* Attempt to statically determine when the number isn't positive. */
17997 453 : c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
17998 453 : build_int_cst (TREE_TYPE (t), 0));
17999 453 : protected_set_expr_location (c, expr_loc);
18000 453 : if (c == boolean_true_node)
18001 : {
18002 1 : warning_at (expr_loc, OPT_Wopenmp,
18003 : "%<num_threads%> value must be positive");
18004 1 : t = integer_one_node;
18005 : }
18006 :
18007 453 : check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
18008 :
18009 453 : c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
18010 453 : OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
18011 453 : OMP_CLAUSE_CHAIN (c) = list;
18012 453 : list = c;
18013 : }
18014 :
18015 : return list;
18016 : }
18017 :
18018 : /* OpenMP 4.5:
18019 : num_tasks ( expression )
18020 :
18021 : OpenMP 5.1:
18022 : num_tasks ( strict : expression ) */
18023 :
18024 : static tree
18025 50 : c_parser_omp_clause_num_tasks (c_parser *parser, tree list)
18026 : {
18027 50 : location_t num_tasks_loc = c_parser_peek_token (parser)->location;
18028 50 : matching_parens parens;
18029 50 : if (parens.require_open (parser))
18030 : {
18031 50 : bool strict = false;
18032 50 : if (c_parser_next_token_is (parser, CPP_NAME)
18033 40 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON
18034 51 : && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
18035 : "strict") == 0)
18036 : {
18037 1 : strict = true;
18038 1 : c_parser_consume_token (parser);
18039 1 : c_parser_consume_token (parser);
18040 : }
18041 :
18042 50 : location_t expr_loc = c_parser_peek_token (parser)->location;
18043 50 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
18044 50 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
18045 50 : tree c, t = expr.value;
18046 50 : t = c_fully_fold (t, false, NULL);
18047 :
18048 50 : parens.skip_until_found_close (parser);
18049 :
18050 50 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
18051 : {
18052 0 : c_parser_error (parser, "expected integer expression");
18053 0 : return list;
18054 : }
18055 :
18056 : /* Attempt to statically determine when the number isn't positive. */
18057 50 : c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
18058 50 : build_int_cst (TREE_TYPE (t), 0));
18059 50 : if (CAN_HAVE_LOCATION_P (c))
18060 40 : SET_EXPR_LOCATION (c, expr_loc);
18061 50 : if (c == boolean_true_node)
18062 : {
18063 0 : warning_at (expr_loc, OPT_Wopenmp,
18064 : "%<num_tasks%> value must be positive");
18065 0 : t = integer_one_node;
18066 : }
18067 :
18068 50 : check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks");
18069 :
18070 50 : c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS);
18071 50 : OMP_CLAUSE_NUM_TASKS_EXPR (c) = t;
18072 50 : OMP_CLAUSE_NUM_TASKS_STRICT (c) = strict;
18073 50 : OMP_CLAUSE_CHAIN (c) = list;
18074 50 : list = c;
18075 : }
18076 :
18077 : return list;
18078 : }
18079 :
18080 : /* OpenMP 4.5:
18081 : grainsize ( expression )
18082 :
18083 : OpenMP 5.1:
18084 : grainsize ( strict : expression ) */
18085 :
18086 : static tree
18087 62 : c_parser_omp_clause_grainsize (c_parser *parser, tree list)
18088 : {
18089 62 : location_t grainsize_loc = c_parser_peek_token (parser)->location;
18090 62 : matching_parens parens;
18091 62 : if (parens.require_open (parser))
18092 : {
18093 62 : bool strict = false;
18094 62 : if (c_parser_next_token_is (parser, CPP_NAME)
18095 47 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON
18096 63 : && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
18097 : "strict") == 0)
18098 : {
18099 1 : strict = true;
18100 1 : c_parser_consume_token (parser);
18101 1 : c_parser_consume_token (parser);
18102 : }
18103 :
18104 62 : location_t expr_loc = c_parser_peek_token (parser)->location;
18105 62 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
18106 62 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
18107 62 : tree c, t = expr.value;
18108 62 : t = c_fully_fold (t, false, NULL);
18109 :
18110 62 : parens.skip_until_found_close (parser);
18111 :
18112 62 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
18113 : {
18114 0 : c_parser_error (parser, "expected integer expression");
18115 0 : return list;
18116 : }
18117 :
18118 : /* Attempt to statically determine when the number isn't positive. */
18119 62 : c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
18120 62 : build_int_cst (TREE_TYPE (t), 0));
18121 62 : if (CAN_HAVE_LOCATION_P (c))
18122 47 : SET_EXPR_LOCATION (c, expr_loc);
18123 62 : if (c == boolean_true_node)
18124 : {
18125 0 : warning_at (expr_loc, OPT_Wopenmp,
18126 : "%<grainsize%> value must be positive");
18127 0 : t = integer_one_node;
18128 : }
18129 :
18130 62 : check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize");
18131 :
18132 62 : c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE);
18133 62 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
18134 62 : OMP_CLAUSE_GRAINSIZE_STRICT (c) = strict;
18135 62 : OMP_CLAUSE_CHAIN (c) = list;
18136 62 : list = c;
18137 : }
18138 :
18139 : return list;
18140 : }
18141 :
18142 : /* OpenMP 4.5:
18143 : priority ( expression ) */
18144 :
18145 : static tree
18146 98 : c_parser_omp_clause_priority (c_parser *parser, tree list)
18147 : {
18148 98 : location_t priority_loc = c_parser_peek_token (parser)->location;
18149 98 : matching_parens parens;
18150 98 : if (parens.require_open (parser))
18151 : {
18152 98 : location_t expr_loc = c_parser_peek_token (parser)->location;
18153 98 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
18154 98 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
18155 98 : tree c, t = expr.value;
18156 98 : t = c_fully_fold (t, false, NULL);
18157 :
18158 98 : parens.skip_until_found_close (parser);
18159 :
18160 98 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
18161 : {
18162 0 : c_parser_error (parser, "expected integer expression");
18163 0 : return list;
18164 : }
18165 :
18166 : /* Attempt to statically determine when the number isn't
18167 : non-negative. */
18168 98 : c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t,
18169 98 : build_int_cst (TREE_TYPE (t), 0));
18170 98 : if (CAN_HAVE_LOCATION_P (c))
18171 87 : SET_EXPR_LOCATION (c, expr_loc);
18172 98 : if (c == boolean_true_node)
18173 : {
18174 0 : warning_at (expr_loc, OPT_Wopenmp,
18175 : "%<priority%> value must be non-negative");
18176 0 : t = integer_one_node;
18177 : }
18178 :
18179 98 : check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority");
18180 :
18181 98 : c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY);
18182 98 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
18183 98 : OMP_CLAUSE_CHAIN (c) = list;
18184 98 : list = c;
18185 : }
18186 :
18187 : return list;
18188 : }
18189 :
18190 : /* OpenMP 4.5:
18191 : hint ( expression ) */
18192 :
18193 : static tree
18194 58 : c_parser_omp_clause_hint (c_parser *parser, tree list)
18195 : {
18196 58 : location_t hint_loc = c_parser_peek_token (parser)->location;
18197 58 : matching_parens parens;
18198 58 : if (parens.require_open (parser))
18199 : {
18200 58 : location_t expr_loc = c_parser_peek_token (parser)->location;
18201 58 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
18202 58 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
18203 58 : tree c, t = expr.value;
18204 58 : t = c_fully_fold (t, false, NULL);
18205 116 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
18206 57 : || TREE_CODE (t) != INTEGER_CST
18207 111 : || tree_int_cst_sgn (t) == -1)
18208 : {
18209 6 : c_parser_error (parser, "expected constant integer expression "
18210 : "with valid sync-hint value");
18211 6 : return list;
18212 : }
18213 52 : parens.skip_until_found_close (parser);
18214 52 : check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint");
18215 :
18216 52 : c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT);
18217 52 : OMP_CLAUSE_HINT_EXPR (c) = t;
18218 52 : OMP_CLAUSE_CHAIN (c) = list;
18219 52 : list = c;
18220 : }
18221 :
18222 : return list;
18223 : }
18224 :
18225 : /* OpenMP 5.1:
18226 : filter ( integer-expression ) */
18227 :
18228 : static tree
18229 63 : c_parser_omp_clause_filter (c_parser *parser, tree list)
18230 : {
18231 63 : location_t hint_loc = c_parser_peek_token (parser)->location;
18232 63 : matching_parens parens;
18233 63 : if (parens.require_open (parser))
18234 : {
18235 63 : location_t expr_loc = c_parser_peek_token (parser)->location;
18236 63 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
18237 63 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
18238 63 : tree c, t = expr.value;
18239 63 : t = c_fully_fold (t, false, NULL);
18240 63 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
18241 : {
18242 2 : c_parser_error (parser, "expected integer expression");
18243 2 : return list;
18244 : }
18245 61 : parens.skip_until_found_close (parser);
18246 61 : check_no_duplicate_clause (list, OMP_CLAUSE_FILTER, "filter");
18247 :
18248 61 : c = build_omp_clause (hint_loc, OMP_CLAUSE_FILTER);
18249 61 : OMP_CLAUSE_FILTER_EXPR (c) = t;
18250 61 : OMP_CLAUSE_CHAIN (c) = list;
18251 61 : list = c;
18252 : }
18253 :
18254 : return list;
18255 : }
18256 :
18257 : /* OpenMP 4.5:
18258 : defaultmap ( tofrom : scalar )
18259 :
18260 : OpenMP 5.0:
18261 : defaultmap ( implicit-behavior [ : variable-category ] ) */
18262 :
18263 : static tree
18264 241 : c_parser_omp_clause_defaultmap (c_parser *parser, tree list)
18265 : {
18266 241 : location_t loc = c_parser_peek_token (parser)->location;
18267 241 : tree c;
18268 241 : const char *p;
18269 241 : enum omp_clause_defaultmap_kind behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
18270 241 : enum omp_clause_defaultmap_kind category
18271 : = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
18272 :
18273 241 : matching_parens parens;
18274 241 : if (!parens.require_open (parser))
18275 : return list;
18276 241 : if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
18277 : p = "default";
18278 234 : else if (!c_parser_next_token_is (parser, CPP_NAME))
18279 : {
18280 2 : invalid_behavior:
18281 3 : c_parser_error (parser, "expected %<alloc%>, %<to%>, %<from%>, "
18282 : "%<tofrom%>, %<firstprivate%>, %<none%> "
18283 : "or %<default%>");
18284 3 : goto out_err;
18285 : }
18286 : else
18287 232 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
18288 :
18289 239 : switch (p[0])
18290 : {
18291 7 : case 'a':
18292 7 : if (strcmp ("alloc", p) == 0)
18293 : behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC;
18294 : else
18295 0 : goto invalid_behavior;
18296 : break;
18297 :
18298 7 : case 'd':
18299 7 : if (strcmp ("default", p) == 0)
18300 : behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
18301 : else
18302 0 : goto invalid_behavior;
18303 : break;
18304 :
18305 27 : case 'f':
18306 27 : if (strcmp ("firstprivate", p) == 0)
18307 : behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
18308 3 : else if (strcmp ("from", p) == 0)
18309 : behavior = OMP_CLAUSE_DEFAULTMAP_FROM;
18310 : else
18311 0 : goto invalid_behavior;
18312 : break;
18313 :
18314 104 : case 'n':
18315 104 : if (strcmp ("none", p) == 0)
18316 : behavior = OMP_CLAUSE_DEFAULTMAP_NONE;
18317 : else
18318 0 : goto invalid_behavior;
18319 : break;
18320 :
18321 4 : case 'p':
18322 4 : if (strcmp ("present", p) == 0)
18323 : behavior = OMP_CLAUSE_DEFAULTMAP_PRESENT;
18324 : else
18325 0 : goto invalid_behavior;
18326 : break;
18327 :
18328 89 : case 't':
18329 89 : if (strcmp ("tofrom", p) == 0)
18330 : behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM;
18331 4 : else if (strcmp ("to", p) == 0)
18332 : behavior = OMP_CLAUSE_DEFAULTMAP_TO;
18333 : else
18334 0 : goto invalid_behavior;
18335 : break;
18336 :
18337 1 : default:
18338 1 : goto invalid_behavior;
18339 : }
18340 238 : c_parser_consume_token (parser);
18341 :
18342 238 : if (!c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
18343 : {
18344 131 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
18345 3 : goto out_err;
18346 128 : if (!c_parser_next_token_is (parser, CPP_NAME))
18347 : {
18348 1 : invalid_category:
18349 2 : c_parser_error (parser, "expected %<scalar%>, %<aggregate%>, "
18350 : "%<pointer%> or %<all%>");
18351 2 : goto out_err;
18352 : }
18353 127 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
18354 127 : switch (p[0])
18355 : {
18356 22 : case 'a':
18357 22 : if (strcmp ("aggregate", p) == 0)
18358 : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE;
18359 8 : else if (strcmp ("all", p) == 0)
18360 : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL;
18361 : else
18362 0 : goto invalid_category;
18363 : break;
18364 :
18365 14 : case 'p':
18366 14 : if (strcmp ("pointer", p) == 0)
18367 : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER;
18368 : else
18369 0 : goto invalid_category;
18370 : break;
18371 :
18372 90 : case 's':
18373 90 : if (strcmp ("scalar", p) == 0)
18374 : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR;
18375 : else
18376 0 : goto invalid_category;
18377 : break;
18378 :
18379 1 : default:
18380 1 : goto invalid_category;
18381 : }
18382 :
18383 126 : c_parser_consume_token (parser);
18384 : }
18385 233 : parens.skip_until_found_close (parser);
18386 :
18387 971 : for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
18388 518 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEFAULTMAP
18389 518 : && (category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
18390 : || category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL
18391 32 : || OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) == category
18392 31 : || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c)
18393 : == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED)
18394 29 : || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c)
18395 : == OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL)))
18396 : {
18397 13 : enum omp_clause_defaultmap_kind cat = category;
18398 13 : location_t loc = OMP_CLAUSE_LOCATION (c);
18399 13 : if (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
18400 13 : || (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL
18401 3 : && (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c)
18402 : != OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED)))
18403 8 : cat = OMP_CLAUSE_DEFAULTMAP_CATEGORY (c);
18404 13 : p = NULL;
18405 13 : switch (cat)
18406 : {
18407 : case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED:
18408 : p = NULL;
18409 : break;
18410 3 : case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL:
18411 3 : p = "all";
18412 3 : break;
18413 2 : case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE:
18414 2 : p = "aggregate";
18415 2 : break;
18416 3 : case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER:
18417 3 : p = "pointer";
18418 3 : break;
18419 : case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR:
18420 : p = "scalar";
18421 : break;
18422 0 : default:
18423 0 : gcc_unreachable ();
18424 : }
18425 8 : if (p)
18426 10 : error_at (loc, "too many %<defaultmap%> clauses with %qs category",
18427 : p);
18428 : else
18429 3 : error_at (loc, "too many %<defaultmap%> clauses with unspecified "
18430 : "category");
18431 : break;
18432 : }
18433 :
18434 233 : c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP);
18435 233 : OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category);
18436 233 : OMP_CLAUSE_CHAIN (c) = list;
18437 233 : return c;
18438 :
18439 8 : out_err:
18440 8 : parens.skip_until_found_close (parser);
18441 8 : return list;
18442 : }
18443 :
18444 : /* OpenACC 2.0:
18445 : use_device ( variable-list )
18446 :
18447 : OpenMP 4.5:
18448 : use_device_ptr ( variable-list ) */
18449 :
18450 : static tree
18451 31 : c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list)
18452 : {
18453 10 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR,
18454 10 : list);
18455 : }
18456 :
18457 : /* OpenMP 5.0:
18458 : use_device_addr ( variable-list ) */
18459 :
18460 : static tree
18461 35 : c_parser_omp_clause_use_device_addr (c_parser *parser, tree list)
18462 : {
18463 35 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_ADDR,
18464 35 : list);
18465 : }
18466 :
18467 : /* OpenMP 5.1:
18468 : has_device_addr ( variable-list ) */
18469 :
18470 : static tree
18471 88 : c_parser_omp_clause_has_device_addr (c_parser *parser, tree list)
18472 : {
18473 88 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_HAS_DEVICE_ADDR,
18474 88 : list);
18475 : }
18476 :
18477 : /* OpenMP 4.5:
18478 : is_device_ptr ( variable-list ) */
18479 :
18480 : static tree
18481 115 : c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list)
18482 : {
18483 115 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list);
18484 : }
18485 :
18486 : /* OpenACC:
18487 : num_gangs ( expression )
18488 : num_workers ( expression )
18489 : vector_length ( expression ) */
18490 :
18491 : static tree
18492 732 : c_parser_oacc_single_int_clause (c_parser *parser, omp_clause_code code,
18493 : tree list)
18494 : {
18495 732 : location_t loc = c_parser_peek_token (parser)->location;
18496 :
18497 732 : matching_parens parens;
18498 732 : if (!parens.require_open (parser))
18499 : return list;
18500 :
18501 726 : location_t expr_loc = c_parser_peek_token (parser)->location;
18502 726 : c_expr expr = c_parser_expression (parser);
18503 726 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
18504 726 : tree c, t = expr.value;
18505 726 : t = c_fully_fold (t, false, NULL);
18506 :
18507 726 : parens.skip_until_found_close (parser);
18508 :
18509 726 : if (t == error_mark_node)
18510 : return list;
18511 702 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
18512 : {
18513 16 : error_at (expr_loc, "%qs expression must be integral",
18514 16 : omp_clause_code_name[code]);
18515 16 : return list;
18516 : }
18517 :
18518 : /* Attempt to statically determine when the number isn't positive. */
18519 686 : c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
18520 686 : build_int_cst (TREE_TYPE (t), 0));
18521 686 : protected_set_expr_location (c, expr_loc);
18522 686 : if (c == boolean_true_node)
18523 : {
18524 36 : warning_at (expr_loc, 0,
18525 : "%qs value must be positive",
18526 18 : omp_clause_code_name[code]);
18527 18 : t = integer_one_node;
18528 : }
18529 :
18530 686 : check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
18531 :
18532 686 : c = build_omp_clause (loc, code);
18533 686 : OMP_CLAUSE_OPERAND (c, 0) = t;
18534 686 : OMP_CLAUSE_CHAIN (c) = list;
18535 686 : return c;
18536 : }
18537 :
18538 : /* OpenACC:
18539 :
18540 : gang [( gang-arg-list )]
18541 : worker [( [num:] int-expr )]
18542 : vector [( [length:] int-expr )]
18543 :
18544 : where gang-arg is one of:
18545 :
18546 : [num:] int-expr
18547 : static: size-expr
18548 :
18549 : and size-expr may be:
18550 :
18551 : *
18552 : int-expr
18553 : */
18554 :
18555 : static tree
18556 1560 : c_parser_oacc_shape_clause (c_parser *parser, location_t loc,
18557 : omp_clause_code kind,
18558 : const char *str, tree list)
18559 : {
18560 1560 : const char *id = "num";
18561 1560 : tree ops[2] = { NULL_TREE, NULL_TREE }, c;
18562 :
18563 1560 : if (kind == OMP_CLAUSE_VECTOR)
18564 518 : id = "length";
18565 :
18566 1560 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
18567 : {
18568 246 : c_parser_consume_token (parser);
18569 :
18570 276 : do
18571 : {
18572 261 : c_token *next = c_parser_peek_token (parser);
18573 261 : int idx = 0;
18574 :
18575 : /* Gang static argument. */
18576 261 : if (kind == OMP_CLAUSE_GANG
18577 403 : && c_parser_next_token_is_keyword (parser, RID_STATIC))
18578 : {
18579 70 : c_parser_consume_token (parser);
18580 :
18581 70 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
18582 12 : goto cleanup_error;
18583 :
18584 70 : idx = 1;
18585 70 : if (ops[idx] != NULL_TREE)
18586 : {
18587 0 : c_parser_error (parser, "too many %<static%> arguments");
18588 0 : goto cleanup_error;
18589 : }
18590 :
18591 : /* Check for the '*' argument. */
18592 70 : if (c_parser_next_token_is (parser, CPP_MULT)
18593 70 : && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
18594 30 : || c_parser_peek_2nd_token (parser)->type
18595 : == CPP_CLOSE_PAREN))
18596 : {
18597 29 : c_parser_consume_token (parser);
18598 29 : ops[idx] = integer_minus_one_node;
18599 :
18600 29 : if (c_parser_next_token_is (parser, CPP_COMMA))
18601 : {
18602 1 : c_parser_consume_token (parser);
18603 1 : continue;
18604 : }
18605 : else
18606 : break;
18607 : }
18608 : }
18609 : /* Worker num: argument and vector length: arguments. */
18610 191 : else if (c_parser_next_token_is (parser, CPP_NAME)
18611 149 : && strcmp (id, IDENTIFIER_POINTER (next->value)) == 0
18612 324 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
18613 : {
18614 127 : c_parser_consume_token (parser); /* id */
18615 127 : c_parser_consume_token (parser); /* ':' */
18616 : }
18617 :
18618 : /* Now collect the actual argument. */
18619 232 : if (ops[idx] != NULL_TREE)
18620 : {
18621 5 : c_parser_error (parser, "unexpected argument");
18622 5 : goto cleanup_error;
18623 : }
18624 :
18625 227 : location_t expr_loc = c_parser_peek_token (parser)->location;
18626 227 : c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
18627 227 : cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
18628 227 : tree expr = cexpr.value;
18629 227 : if (expr == error_mark_node)
18630 7 : goto cleanup_error;
18631 :
18632 220 : expr = c_fully_fold (expr, false, NULL);
18633 :
18634 : /* Attempt to statically determine when the number isn't a
18635 : positive integer. */
18636 :
18637 220 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)))
18638 : {
18639 14 : c_parser_error (parser, "expected integer expression");
18640 14 : return list;
18641 : }
18642 :
18643 206 : tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr,
18644 206 : build_int_cst (TREE_TYPE (expr), 0));
18645 206 : if (c == boolean_true_node)
18646 : {
18647 1 : warning_at (loc, 0,
18648 : "%qs value must be positive", str);
18649 1 : expr = integer_one_node;
18650 : }
18651 :
18652 206 : ops[idx] = expr;
18653 :
18654 220 : if (kind == OMP_CLAUSE_GANG
18655 305 : && c_parser_next_token_is (parser, CPP_COMMA))
18656 : {
18657 14 : c_parser_consume_token (parser);
18658 14 : continue;
18659 : }
18660 : break;
18661 15 : }
18662 : while (1);
18663 :
18664 220 : if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
18665 7 : goto cleanup_error;
18666 : }
18667 :
18668 1527 : check_no_duplicate_clause (list, kind, str);
18669 :
18670 1527 : c = build_omp_clause (loc, kind);
18671 :
18672 1527 : if (ops[1])
18673 67 : OMP_CLAUSE_OPERAND (c, 1) = ops[1];
18674 :
18675 1527 : OMP_CLAUSE_OPERAND (c, 0) = ops[0];
18676 1527 : OMP_CLAUSE_CHAIN (c) = list;
18677 :
18678 1527 : return c;
18679 :
18680 19 : cleanup_error:
18681 19 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
18682 19 : return list;
18683 : }
18684 :
18685 : /* OpenACC 2.5:
18686 : auto
18687 : finalize
18688 : independent
18689 : nohost
18690 : seq */
18691 :
18692 : static tree
18693 487 : c_parser_oacc_simple_clause (location_t loc, enum omp_clause_code code,
18694 : tree list)
18695 : {
18696 487 : check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
18697 :
18698 487 : tree c = build_omp_clause (loc, code);
18699 487 : OMP_CLAUSE_CHAIN (c) = list;
18700 :
18701 487 : return c;
18702 : }
18703 :
18704 : /* OpenACC:
18705 : async [( int-expr )] */
18706 :
18707 : static tree
18708 240 : c_parser_oacc_clause_async (c_parser *parser, tree list)
18709 : {
18710 240 : tree c, t;
18711 240 : location_t loc = c_parser_peek_token (parser)->location;
18712 :
18713 240 : t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
18714 :
18715 240 : if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
18716 : {
18717 187 : c_parser_consume_token (parser);
18718 :
18719 187 : t = c_parser_expr_no_commas (parser, NULL).value;
18720 187 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
18721 9 : c_parser_error (parser, "expected integer expression");
18722 178 : else if (t == error_mark_node
18723 178 : || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
18724 : return list;
18725 : }
18726 : else
18727 53 : t = c_fully_fold (t, false, NULL);
18728 :
18729 226 : check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
18730 :
18731 226 : c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
18732 226 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
18733 226 : OMP_CLAUSE_CHAIN (c) = list;
18734 226 : list = c;
18735 :
18736 226 : return list;
18737 : }
18738 :
18739 : /* OpenACC 2.0:
18740 : tile ( size-expr-list ) */
18741 :
18742 : static tree
18743 123 : c_parser_oacc_clause_tile (c_parser *parser, tree list)
18744 : {
18745 123 : tree c, expr = error_mark_node;
18746 123 : location_t loc;
18747 123 : tree tile = NULL_TREE;
18748 :
18749 123 : check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
18750 123 : check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
18751 :
18752 123 : loc = c_parser_peek_token (parser)->location;
18753 123 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
18754 : return list;
18755 :
18756 163 : do
18757 : {
18758 163 : if (tile && !c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
18759 : return list;
18760 :
18761 163 : if (c_parser_next_token_is (parser, CPP_MULT)
18762 163 : && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
18763 53 : || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
18764 : {
18765 60 : c_parser_consume_token (parser);
18766 60 : expr = integer_zero_node;
18767 : }
18768 : else
18769 : {
18770 103 : location_t expr_loc = c_parser_peek_token (parser)->location;
18771 103 : c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
18772 103 : cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
18773 103 : expr = cexpr.value;
18774 :
18775 103 : if (expr == error_mark_node)
18776 : {
18777 7 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
18778 : "expected %<)%>");
18779 7 : return list;
18780 : }
18781 :
18782 96 : expr = c_fully_fold (expr, false, NULL);
18783 :
18784 192 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
18785 95 : || !tree_fits_shwi_p (expr)
18786 183 : || tree_to_shwi (expr) <= 0)
18787 : {
18788 16 : error_at (expr_loc, "%<tile%> argument needs positive"
18789 : " integral constant");
18790 16 : expr = integer_zero_node;
18791 : }
18792 : }
18793 :
18794 156 : tile = tree_cons (NULL_TREE, expr, tile);
18795 : }
18796 156 : while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN));
18797 :
18798 : /* Consume the trailing ')'. */
18799 111 : c_parser_consume_token (parser);
18800 :
18801 111 : c = build_omp_clause (loc, OMP_CLAUSE_TILE);
18802 111 : tile = nreverse (tile);
18803 111 : OMP_CLAUSE_TILE_LIST (c) = tile;
18804 111 : OMP_CLAUSE_CHAIN (c) = list;
18805 111 : return c;
18806 : }
18807 :
18808 : /* OpenACC:
18809 : wait [( int-expr-list )] */
18810 :
18811 : static tree
18812 97 : c_parser_oacc_clause_wait (c_parser *parser, tree list)
18813 : {
18814 97 : location_t clause_loc = c_parser_peek_token (parser)->location;
18815 :
18816 97 : if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
18817 82 : list = c_parser_oacc_wait_list (parser, clause_loc, list);
18818 : else
18819 : {
18820 15 : tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
18821 :
18822 15 : OMP_CLAUSE_DECL (c) = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
18823 15 : OMP_CLAUSE_CHAIN (c) = list;
18824 15 : list = c;
18825 : }
18826 :
18827 97 : return list;
18828 : }
18829 :
18830 : /* OpenACC 2.7:
18831 : self [( expression )] */
18832 :
18833 : static tree
18834 48 : c_parser_oacc_compute_clause_self (c_parser *parser, tree list)
18835 : {
18836 48 : tree t;
18837 48 : location_t location = c_parser_peek_token (parser)->location;
18838 48 : if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
18839 : {
18840 42 : matching_parens parens;
18841 42 : parens.consume_open (parser);
18842 :
18843 42 : location_t loc = c_parser_peek_token (parser)->location;
18844 42 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
18845 42 : expr = convert_lvalue_to_rvalue (loc, expr, true, true);
18846 42 : t = c_objc_common_truthvalue_conversion (loc, expr.value);
18847 42 : t = c_fully_fold (t, false, NULL);
18848 42 : parens.skip_until_found_close (parser);
18849 : }
18850 : else
18851 6 : t = truthvalue_true_node;
18852 :
18853 78 : for (tree c = list; c; c = OMP_CLAUSE_CHAIN (c))
18854 36 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SELF)
18855 : {
18856 6 : error_at (location, "too many %<self%> clauses");
18857 6 : return list;
18858 : }
18859 :
18860 42 : tree c = build_omp_clause (location, OMP_CLAUSE_SELF);
18861 42 : OMP_CLAUSE_SELF_EXPR (c) = t;
18862 42 : OMP_CLAUSE_CHAIN (c) = list;
18863 42 : return c;
18864 : }
18865 :
18866 : /* OpenMP 5.0:
18867 : order ( concurrent )
18868 :
18869 : OpenMP 5.1:
18870 : order ( order-modifier : concurrent )
18871 :
18872 : order-modifier:
18873 : reproducible
18874 : unconstrained */
18875 :
18876 : static tree
18877 376 : c_parser_omp_clause_order (c_parser *parser, tree list)
18878 : {
18879 376 : location_t loc = c_parser_peek_token (parser)->location;
18880 376 : tree c;
18881 376 : const char *p;
18882 376 : bool unconstrained = false;
18883 376 : bool reproducible = false;
18884 :
18885 376 : matching_parens parens;
18886 376 : if (!parens.require_open (parser))
18887 : return list;
18888 374 : if (c_parser_next_token_is (parser, CPP_NAME)
18889 374 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
18890 : {
18891 107 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
18892 107 : if (strcmp (p, "unconstrained") == 0)
18893 : unconstrained = true;
18894 56 : else if (strcmp (p, "reproducible") == 0)
18895 : reproducible = true;
18896 : else
18897 : {
18898 1 : c_parser_error (parser, "expected %<reproducible%> or "
18899 : "%<unconstrained%>");
18900 1 : goto out_err;
18901 : }
18902 106 : c_parser_consume_token (parser);
18903 106 : c_parser_consume_token (parser);
18904 : }
18905 373 : if (!c_parser_next_token_is (parser, CPP_NAME))
18906 : {
18907 0 : c_parser_error (parser, "expected %<concurrent%>");
18908 0 : goto out_err;
18909 : }
18910 373 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
18911 373 : if (strcmp (p, "concurrent") != 0)
18912 : {
18913 1 : c_parser_error (parser, "expected %<concurrent%>");
18914 1 : goto out_err;
18915 : }
18916 372 : c_parser_consume_token (parser);
18917 372 : parens.skip_until_found_close (parser);
18918 372 : check_no_duplicate_clause (list, OMP_CLAUSE_ORDER, "order");
18919 372 : c = build_omp_clause (loc, OMP_CLAUSE_ORDER);
18920 372 : OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = unconstrained;
18921 372 : OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = reproducible;
18922 372 : OMP_CLAUSE_CHAIN (c) = list;
18923 372 : return c;
18924 :
18925 2 : out_err:
18926 2 : parens.skip_until_found_close (parser);
18927 2 : return list;
18928 : }
18929 :
18930 :
18931 : /* OpenMP 5.0:
18932 : bind ( teams | parallel | thread ) */
18933 :
18934 : static tree
18935 116 : c_parser_omp_clause_bind (c_parser *parser, tree list)
18936 : {
18937 116 : location_t loc = c_parser_peek_token (parser)->location;
18938 116 : tree c;
18939 116 : const char *p;
18940 116 : enum omp_clause_bind_kind kind = OMP_CLAUSE_BIND_THREAD;
18941 :
18942 116 : matching_parens parens;
18943 116 : if (!parens.require_open (parser))
18944 : return list;
18945 114 : if (!c_parser_next_token_is (parser, CPP_NAME))
18946 : {
18947 3 : invalid:
18948 4 : c_parser_error (parser,
18949 : "expected %<teams%>, %<parallel%> or %<thread%>");
18950 4 : parens.skip_until_found_close (parser);
18951 4 : return list;
18952 : }
18953 111 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
18954 111 : if (strcmp (p, "teams") == 0)
18955 : kind = OMP_CLAUSE_BIND_TEAMS;
18956 72 : else if (strcmp (p, "parallel") == 0)
18957 : kind = OMP_CLAUSE_BIND_PARALLEL;
18958 35 : else if (strcmp (p, "thread") != 0)
18959 1 : goto invalid;
18960 110 : c_parser_consume_token (parser);
18961 110 : parens.skip_until_found_close (parser);
18962 : /* check_no_duplicate_clause (list, OMP_CLAUSE_BIND, "bind"); */
18963 110 : c = build_omp_clause (loc, OMP_CLAUSE_BIND);
18964 110 : OMP_CLAUSE_BIND_KIND (c) = kind;
18965 110 : OMP_CLAUSE_CHAIN (c) = list;
18966 110 : return c;
18967 : }
18968 :
18969 :
18970 : /* OpenMP 2.5:
18971 : ordered
18972 :
18973 : OpenMP 4.5:
18974 : ordered ( constant-expression ) */
18975 :
18976 : static tree
18977 310 : c_parser_omp_clause_ordered (c_parser *parser, tree list)
18978 : {
18979 310 : check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
18980 :
18981 310 : tree c, num = NULL_TREE;
18982 310 : HOST_WIDE_INT n;
18983 310 : location_t loc = c_parser_peek_token (parser)->location;
18984 310 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
18985 : {
18986 169 : matching_parens parens;
18987 169 : parens.consume_open (parser);
18988 169 : num = c_parser_expr_no_commas (parser, NULL).value;
18989 169 : parens.skip_until_found_close (parser);
18990 : }
18991 310 : if (num == error_mark_node)
18992 : return list;
18993 310 : if (num)
18994 : {
18995 169 : mark_exp_read (num);
18996 169 : num = c_fully_fold (num, false, NULL);
18997 338 : if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
18998 169 : || !tree_fits_shwi_p (num)
18999 169 : || (n = tree_to_shwi (num)) <= 0
19000 338 : || (int) n != n)
19001 : {
19002 0 : error_at (loc, "ordered argument needs positive "
19003 : "constant integer expression");
19004 0 : return list;
19005 : }
19006 : }
19007 310 : c = build_omp_clause (loc, OMP_CLAUSE_ORDERED);
19008 310 : OMP_CLAUSE_ORDERED_EXPR (c) = num;
19009 310 : OMP_CLAUSE_CHAIN (c) = list;
19010 310 : return c;
19011 : }
19012 :
19013 : /* OpenMP 2.5:
19014 : private ( variable-list ) */
19015 :
19016 : static tree
19017 749 : c_parser_omp_clause_private (c_parser *parser, tree list)
19018 : {
19019 683 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
19020 : }
19021 :
19022 : /* OpenMP 2.5:
19023 : reduction ( reduction-operator : variable-list )
19024 :
19025 : reduction-operator:
19026 : One of: + * - & ^ | && ||
19027 :
19028 : OpenMP 3.1:
19029 :
19030 : reduction-operator:
19031 : One of: + * - & ^ | && || max min
19032 :
19033 : OpenMP 4.0:
19034 :
19035 : reduction-operator:
19036 : One of: + * - & ^ | && ||
19037 : identifier
19038 :
19039 : OpenMP 5.0:
19040 : reduction ( reduction-modifier, reduction-operator : variable-list )
19041 : in_reduction ( reduction-operator : variable-list )
19042 : task_reduction ( reduction-operator : variable-list ) */
19043 :
19044 : static tree
19045 3110 : c_parser_omp_clause_reduction (c_parser *parser, enum omp_clause_code kind,
19046 : bool is_omp, tree list)
19047 : {
19048 3110 : location_t clause_loc = c_parser_peek_token (parser)->location;
19049 3110 : matching_parens parens;
19050 3110 : if (parens.require_open (parser))
19051 : {
19052 3110 : bool task = false;
19053 3110 : bool inscan = false;
19054 3110 : enum tree_code code = ERROR_MARK;
19055 3110 : tree reduc_id = NULL_TREE;
19056 :
19057 3110 : if (kind == OMP_CLAUSE_REDUCTION && is_omp)
19058 : {
19059 1797 : if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)
19060 1797 : && c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
19061 : {
19062 87 : c_parser_consume_token (parser);
19063 87 : c_parser_consume_token (parser);
19064 : }
19065 1710 : else if (c_parser_next_token_is (parser, CPP_NAME)
19066 1710 : && c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
19067 : {
19068 471 : const char *p
19069 471 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
19070 471 : if (strcmp (p, "task") == 0)
19071 : task = true;
19072 288 : else if (strcmp (p, "inscan") == 0)
19073 : inscan = true;
19074 : if (task || inscan)
19075 : {
19076 471 : c_parser_consume_token (parser);
19077 471 : c_parser_consume_token (parser);
19078 : }
19079 : }
19080 : }
19081 :
19082 3110 : switch (c_parser_peek_token (parser)->type)
19083 : {
19084 : case CPP_PLUS:
19085 : code = PLUS_EXPR;
19086 : break;
19087 253 : case CPP_MULT:
19088 253 : code = MULT_EXPR;
19089 253 : break;
19090 157 : case CPP_MINUS:
19091 157 : if (is_omp)
19092 : {
19093 4 : location_t loc = c_parser_peek_token (parser)->location;
19094 4 : gcc_rich_location richloc (loc);
19095 4 : richloc.add_fixit_replace ("+");
19096 4 : warning_at (&richloc, OPT_Wdeprecated_openmp,
19097 : "%<-%> operator for reductions deprecated in "
19098 : "OpenMP 5.2");
19099 4 : }
19100 : code = MINUS_EXPR;
19101 : break;
19102 27 : case CPP_AND:
19103 27 : code = BIT_AND_EXPR;
19104 27 : break;
19105 14 : case CPP_XOR:
19106 14 : code = BIT_XOR_EXPR;
19107 14 : break;
19108 82 : case CPP_OR:
19109 82 : code = BIT_IOR_EXPR;
19110 82 : break;
19111 67 : case CPP_AND_AND:
19112 67 : code = TRUTH_ANDIF_EXPR;
19113 67 : break;
19114 78 : case CPP_OR_OR:
19115 78 : code = TRUTH_ORIF_EXPR;
19116 78 : break;
19117 253 : case CPP_NAME:
19118 253 : {
19119 253 : const char *p
19120 253 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
19121 253 : if (strcmp (p, "min") == 0)
19122 : {
19123 : code = MIN_EXPR;
19124 : break;
19125 : }
19126 213 : if (strcmp (p, "max") == 0)
19127 : {
19128 : code = MAX_EXPR;
19129 : break;
19130 : }
19131 130 : reduc_id = c_parser_peek_token (parser)->value;
19132 130 : break;
19133 : }
19134 0 : default:
19135 0 : c_parser_error (parser,
19136 : "expected %<+%>, %<*%>, %<-%>, %<&%>, "
19137 : "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
19138 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
19139 0 : return list;
19140 : }
19141 3110 : c_parser_consume_token (parser);
19142 3110 : reduc_id = c_omp_reduction_id (code, reduc_id);
19143 3110 : if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
19144 : {
19145 3110 : tree nl, c;
19146 :
19147 3110 : nl = c_parser_omp_variable_list (parser, clause_loc, kind, list);
19148 9948 : for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
19149 : {
19150 3728 : tree d = OMP_CLAUSE_DECL (c), type;
19151 3728 : if (TREE_CODE (d) != OMP_ARRAY_SECTION)
19152 3209 : type = TREE_TYPE (d);
19153 : else
19154 : {
19155 : int cnt = 0;
19156 : tree t;
19157 636 : for (t = d;
19158 1155 : TREE_CODE (t) == OMP_ARRAY_SECTION;
19159 636 : t = TREE_OPERAND (t, 0))
19160 636 : cnt++;
19161 519 : type = TREE_TYPE (t);
19162 1153 : while (cnt > 0)
19163 : {
19164 636 : if (TREE_CODE (type) != POINTER_TYPE
19165 399 : && TREE_CODE (type) != ARRAY_TYPE)
19166 : break;
19167 634 : type = TREE_TYPE (type);
19168 634 : cnt--;
19169 : }
19170 : }
19171 3821 : while (TREE_CODE (type) == ARRAY_TYPE)
19172 93 : type = TREE_TYPE (type);
19173 3728 : OMP_CLAUSE_REDUCTION_CODE (c) = code;
19174 3728 : if (task)
19175 215 : OMP_CLAUSE_REDUCTION_TASK (c) = 1;
19176 3513 : else if (inscan)
19177 403 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 1;
19178 3728 : if (code == ERROR_MARK
19179 222 : || !(INTEGRAL_TYPE_P (type)
19180 3588 : || SCALAR_FLOAT_TYPE_P (type)
19181 : || TREE_CODE (type) == COMPLEX_TYPE))
19182 276 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
19183 552 : = c_omp_reduction_lookup (reduc_id,
19184 276 : TYPE_MAIN_VARIANT (type));
19185 : }
19186 :
19187 : list = nl;
19188 : }
19189 3110 : parens.skip_until_found_close (parser);
19190 : }
19191 : return list;
19192 : }
19193 :
19194 : /* OpenMP 2.5:
19195 : schedule ( schedule-kind )
19196 : schedule ( schedule-kind , expression )
19197 :
19198 : schedule-kind:
19199 : static | dynamic | guided | runtime | auto
19200 :
19201 : OpenMP 4.5:
19202 : schedule ( schedule-modifier : schedule-kind )
19203 : schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
19204 :
19205 : schedule-modifier:
19206 : simd
19207 : monotonic
19208 : nonmonotonic */
19209 :
19210 : static tree
19211 3483 : c_parser_omp_clause_schedule (c_parser *parser, tree list)
19212 : {
19213 3483 : tree c, t;
19214 3483 : location_t loc = c_parser_peek_token (parser)->location;
19215 3483 : int modifiers = 0, nmodifiers = 0;
19216 :
19217 3483 : matching_parens parens;
19218 3483 : if (!parens.require_open (parser))
19219 : return list;
19220 :
19221 3481 : c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
19222 :
19223 3481 : location_t comma = UNKNOWN_LOCATION;
19224 6976 : while (c_parser_next_token_is (parser, CPP_NAME))
19225 : {
19226 1782 : tree kind = c_parser_peek_token (parser)->value;
19227 1782 : const char *p = IDENTIFIER_POINTER (kind);
19228 1782 : if (strcmp ("simd", p) == 0)
19229 31 : OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
19230 1751 : else if (strcmp ("monotonic", p) == 0)
19231 74 : modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC;
19232 1677 : else if (strcmp ("nonmonotonic", p) == 0)
19233 84 : modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC;
19234 : else
19235 : break;
19236 189 : comma = UNKNOWN_LOCATION;
19237 189 : c_parser_consume_token (parser);
19238 189 : if (nmodifiers++ == 0
19239 367 : && c_parser_next_token_is (parser, CPP_COMMA))
19240 : {
19241 14 : comma = c_parser_peek_token (parser)->location;
19242 14 : c_parser_consume_token (parser);
19243 : }
19244 : else
19245 : {
19246 175 : c_parser_require (parser, CPP_COLON, "expected %<:%>");
19247 175 : break;
19248 : }
19249 : }
19250 3481 : if (comma != UNKNOWN_LOCATION)
19251 3 : error_at (comma, "expected %<:%>");
19252 :
19253 3481 : if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC
19254 : | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
19255 : == (OMP_CLAUSE_SCHEDULE_MONOTONIC
19256 : | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
19257 : {
19258 2 : error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers "
19259 : "specified");
19260 2 : modifiers = 0;
19261 : }
19262 :
19263 3481 : if (c_parser_next_token_is (parser, CPP_NAME))
19264 : {
19265 1710 : tree kind = c_parser_peek_token (parser)->value;
19266 1710 : const char *p = IDENTIFIER_POINTER (kind);
19267 :
19268 1710 : switch (p[0])
19269 : {
19270 170 : case 'd':
19271 170 : if (strcmp ("dynamic", p) != 0)
19272 0 : goto invalid_kind;
19273 170 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
19274 170 : break;
19275 :
19276 762 : case 'g':
19277 762 : if (strcmp ("guided", p) != 0)
19278 0 : goto invalid_kind;
19279 762 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
19280 762 : break;
19281 :
19282 777 : case 'r':
19283 777 : if (strcmp ("runtime", p) != 0)
19284 0 : goto invalid_kind;
19285 777 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
19286 777 : break;
19287 :
19288 1 : default:
19289 1 : goto invalid_kind;
19290 : }
19291 : }
19292 1771 : else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
19293 1090 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
19294 681 : else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
19295 680 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
19296 : else
19297 1 : goto invalid_kind;
19298 :
19299 3479 : c_parser_consume_token (parser);
19300 3479 : if (c_parser_next_token_is (parser, CPP_COMMA))
19301 : {
19302 1806 : location_t here;
19303 1806 : c_parser_consume_token (parser);
19304 :
19305 1806 : here = c_parser_peek_token (parser)->location;
19306 1806 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19307 1806 : expr = convert_lvalue_to_rvalue (here, expr, false, true);
19308 1806 : t = expr.value;
19309 1806 : t = c_fully_fold (t, false, NULL);
19310 :
19311 1806 : if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
19312 1 : error_at (here, "schedule %<runtime%> does not take "
19313 : "a %<chunk_size%> parameter");
19314 1805 : else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
19315 0 : error_at (here,
19316 : "schedule %<auto%> does not take "
19317 : "a %<chunk_size%> parameter");
19318 1805 : else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
19319 1805 : || TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE)
19320 : {
19321 : /* Attempt to statically determine when the number isn't
19322 : positive. */
19323 1804 : tree s = fold_build2_loc (loc, LE_EXPR, boolean_type_node, t,
19324 1804 : build_int_cst (TREE_TYPE (t), 0));
19325 1804 : protected_set_expr_location (s, loc);
19326 1804 : if (s == boolean_true_node)
19327 : {
19328 2 : warning_at (loc, OPT_Wopenmp,
19329 : "chunk size value must be positive");
19330 2 : t = integer_one_node;
19331 : }
19332 1804 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
19333 : }
19334 : else
19335 1 : c_parser_error (parser, "expected integer expression");
19336 :
19337 1806 : parens.skip_until_found_close (parser);
19338 : }
19339 : else
19340 1673 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
19341 : "expected %<,%> or %<)%>");
19342 :
19343 6958 : OMP_CLAUSE_SCHEDULE_KIND (c)
19344 6958 : = (enum omp_clause_schedule_kind)
19345 3479 : (OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers);
19346 :
19347 3479 : check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
19348 3479 : OMP_CLAUSE_CHAIN (c) = list;
19349 3479 : return c;
19350 :
19351 2 : invalid_kind:
19352 2 : c_parser_error (parser, "invalid schedule kind");
19353 2 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
19354 2 : return list;
19355 : }
19356 :
19357 : /* OpenMP 2.5:
19358 : shared ( variable-list ) */
19359 :
19360 : static tree
19361 711 : c_parser_omp_clause_shared (c_parser *parser, tree list)
19362 : {
19363 711 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
19364 : }
19365 :
19366 : /* OpenMP 3.0:
19367 : untied */
19368 :
19369 : static tree
19370 97 : c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
19371 : {
19372 97 : tree c;
19373 :
19374 : /* FIXME: Should we allow duplicates? */
19375 97 : check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
19376 :
19377 97 : c = build_omp_clause (c_parser_peek_token (parser)->location,
19378 : OMP_CLAUSE_UNTIED);
19379 97 : OMP_CLAUSE_CHAIN (c) = list;
19380 :
19381 97 : return c;
19382 : }
19383 :
19384 : /* OpenMP 4.0:
19385 : inbranch
19386 : notinbranch */
19387 :
19388 : static tree
19389 223 : c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
19390 : enum omp_clause_code code, tree list)
19391 : {
19392 223 : check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
19393 :
19394 223 : tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
19395 223 : OMP_CLAUSE_CHAIN (c) = list;
19396 :
19397 223 : return c;
19398 : }
19399 :
19400 : /* OpenMP 4.0:
19401 : parallel
19402 : for
19403 : sections
19404 : taskgroup */
19405 :
19406 : static tree
19407 387 : c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
19408 : enum omp_clause_code code, tree list)
19409 : {
19410 387 : tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
19411 387 : OMP_CLAUSE_CHAIN (c) = list;
19412 :
19413 387 : return c;
19414 : }
19415 :
19416 : /* OpenMP 4.5:
19417 : nogroup */
19418 :
19419 : static tree
19420 18 : c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list)
19421 : {
19422 18 : check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup");
19423 18 : tree c = build_omp_clause (c_parser_peek_token (parser)->location,
19424 : OMP_CLAUSE_NOGROUP);
19425 18 : OMP_CLAUSE_CHAIN (c) = list;
19426 18 : return c;
19427 : }
19428 :
19429 : /* OpenMP 4.5:
19430 : simd
19431 : threads */
19432 :
19433 : static tree
19434 103 : c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED,
19435 : enum omp_clause_code code, tree list)
19436 : {
19437 103 : check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
19438 103 : tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
19439 103 : OMP_CLAUSE_CHAIN (c) = list;
19440 103 : return c;
19441 : }
19442 :
19443 : /* OpenMP 4.0:
19444 : num_teams ( expression )
19445 :
19446 : OpenMP 5.1:
19447 : num_teams ( expression : expression ) */
19448 :
19449 : static tree
19450 192 : c_parser_omp_clause_num_teams (c_parser *parser, tree list)
19451 : {
19452 192 : location_t num_teams_loc = c_parser_peek_token (parser)->location;
19453 192 : matching_parens parens;
19454 192 : if (parens.require_open (parser))
19455 : {
19456 192 : location_t upper_loc = c_parser_peek_token (parser)->location;
19457 192 : location_t lower_loc = UNKNOWN_LOCATION;
19458 192 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19459 192 : expr = convert_lvalue_to_rvalue (upper_loc, expr, false, true);
19460 192 : tree c, upper = expr.value, lower = NULL_TREE;
19461 192 : upper = c_fully_fold (upper, false, NULL);
19462 :
19463 192 : if (c_parser_next_token_is (parser, CPP_COLON))
19464 : {
19465 51 : c_parser_consume_token (parser);
19466 51 : lower_loc = upper_loc;
19467 51 : lower = upper;
19468 51 : upper_loc = c_parser_peek_token (parser)->location;
19469 51 : expr = c_parser_expr_no_commas (parser, NULL);
19470 51 : expr = convert_lvalue_to_rvalue (upper_loc, expr, false, true);
19471 51 : upper = expr.value;
19472 51 : upper = c_fully_fold (upper, false, NULL);
19473 : }
19474 :
19475 192 : parens.skip_until_found_close (parser);
19476 :
19477 384 : if (!INTEGRAL_TYPE_P (TREE_TYPE (upper))
19478 384 : || (lower && !INTEGRAL_TYPE_P (TREE_TYPE (lower))))
19479 : {
19480 0 : c_parser_error (parser, "expected integer expression");
19481 0 : return list;
19482 : }
19483 :
19484 : /* Attempt to statically determine when the number isn't positive. */
19485 192 : c = fold_build2_loc (upper_loc, LE_EXPR, boolean_type_node, upper,
19486 192 : build_int_cst (TREE_TYPE (upper), 0));
19487 192 : protected_set_expr_location (c, upper_loc);
19488 192 : if (c == boolean_true_node)
19489 : {
19490 4 : warning_at (upper_loc, OPT_Wopenmp,
19491 : "%<num_teams%> value must be positive");
19492 4 : upper = integer_one_node;
19493 : }
19494 192 : if (lower)
19495 : {
19496 51 : c = fold_build2_loc (lower_loc, LE_EXPR, boolean_type_node, lower,
19497 51 : build_int_cst (TREE_TYPE (lower), 0));
19498 51 : protected_set_expr_location (c, lower_loc);
19499 51 : if (c == boolean_true_node)
19500 : {
19501 2 : warning_at (lower_loc, OPT_Wopenmp,
19502 : "%<num_teams%> value must be positive");
19503 2 : lower = NULL_TREE;
19504 : }
19505 49 : else if (TREE_CODE (lower) == INTEGER_CST
19506 7 : && TREE_CODE (upper) == INTEGER_CST
19507 54 : && tree_int_cst_lt (upper, lower))
19508 : {
19509 2 : warning_at (lower_loc, OPT_Wopenmp,
19510 : "%<num_teams%> lower bound %qE bigger than upper "
19511 : "bound %qE", lower, upper);
19512 2 : lower = NULL_TREE;
19513 : }
19514 : }
19515 :
19516 192 : check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
19517 :
19518 192 : c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
19519 192 : OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c) = upper;
19520 192 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = lower;
19521 192 : OMP_CLAUSE_CHAIN (c) = list;
19522 192 : list = c;
19523 : }
19524 :
19525 : return list;
19526 : }
19527 :
19528 : /* OpenMP 4.0:
19529 : thread_limit ( expression ) */
19530 :
19531 : static tree
19532 155 : c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
19533 : {
19534 155 : location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
19535 155 : matching_parens parens;
19536 155 : if (parens.require_open (parser))
19537 : {
19538 155 : location_t expr_loc = c_parser_peek_token (parser)->location;
19539 155 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19540 155 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
19541 155 : tree c, t = expr.value;
19542 155 : t = c_fully_fold (t, false, NULL);
19543 :
19544 155 : parens.skip_until_found_close (parser);
19545 :
19546 155 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
19547 : {
19548 0 : c_parser_error (parser, "expected integer expression");
19549 0 : return list;
19550 : }
19551 :
19552 : /* Attempt to statically determine when the number isn't positive. */
19553 155 : c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
19554 155 : build_int_cst (TREE_TYPE (t), 0));
19555 155 : protected_set_expr_location (c, expr_loc);
19556 155 : if (c == boolean_true_node)
19557 : {
19558 0 : warning_at (expr_loc, OPT_Wopenmp,
19559 : "%<thread_limit%> value must be positive");
19560 0 : t = integer_one_node;
19561 : }
19562 :
19563 155 : check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
19564 : "thread_limit");
19565 :
19566 155 : c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
19567 155 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
19568 155 : OMP_CLAUSE_CHAIN (c) = list;
19569 155 : list = c;
19570 : }
19571 :
19572 : return list;
19573 : }
19574 :
19575 : /* OpenMP 4.0:
19576 : aligned ( variable-list )
19577 : aligned ( variable-list : constant-expression ) */
19578 :
19579 : static tree
19580 228 : c_parser_omp_clause_aligned (c_parser *parser, tree list)
19581 : {
19582 228 : location_t clause_loc = c_parser_peek_token (parser)->location;
19583 228 : tree nl, c;
19584 :
19585 228 : matching_parens parens;
19586 228 : if (!parens.require_open (parser))
19587 : return list;
19588 :
19589 228 : nl = c_parser_omp_variable_list (parser, clause_loc,
19590 : OMP_CLAUSE_ALIGNED, list);
19591 :
19592 228 : if (c_parser_next_token_is (parser, CPP_COLON))
19593 : {
19594 212 : c_parser_consume_token (parser);
19595 212 : location_t expr_loc = c_parser_peek_token (parser)->location;
19596 212 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19597 212 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
19598 212 : tree alignment = expr.value;
19599 212 : alignment = c_fully_fold (alignment, false, NULL);
19600 212 : if (TREE_CODE (alignment) != INTEGER_CST
19601 210 : || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
19602 422 : || tree_int_cst_sgn (alignment) != 1)
19603 : {
19604 4 : error_at (clause_loc, "%<aligned%> clause alignment expression must "
19605 : "be positive constant integer expression");
19606 4 : alignment = NULL_TREE;
19607 : }
19608 :
19609 444 : for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
19610 232 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
19611 : }
19612 :
19613 228 : parens.skip_until_found_close (parser);
19614 228 : return nl;
19615 : }
19616 :
19617 : /* OpenMP 5.0:
19618 : allocate ( variable-list )
19619 : allocate ( expression : variable-list )
19620 :
19621 : OpenMP 5.1:
19622 : allocate ( allocator-modifier : variable-list )
19623 : allocate ( allocator-modifier , allocator-modifier : variable-list )
19624 :
19625 : allocator-modifier:
19626 : allocator ( expression )
19627 : align ( expression ) */
19628 :
19629 : static tree
19630 485 : c_parser_omp_clause_allocate (c_parser *parser, tree list)
19631 : {
19632 485 : location_t clause_loc = c_parser_peek_token (parser)->location;
19633 485 : tree nl, c;
19634 485 : tree allocator = NULL_TREE;
19635 485 : tree align = NULL_TREE;
19636 :
19637 485 : matching_parens parens;
19638 485 : if (!parens.require_open (parser))
19639 : return list;
19640 :
19641 485 : if ((c_parser_next_token_is_not (parser, CPP_NAME)
19642 5 : && c_parser_next_token_is_not (parser, CPP_KEYWORD))
19643 485 : || (c_parser_peek_2nd_token (parser)->type != CPP_COMMA
19644 466 : && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN))
19645 : {
19646 220 : bool has_modifiers = false;
19647 220 : tree orig_type = NULL_TREE;
19648 220 : if (c_parser_next_token_is (parser, CPP_NAME)
19649 220 : && c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN)
19650 : {
19651 76 : unsigned int n = 3;
19652 76 : const char *p
19653 76 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
19654 29 : if ((strcmp (p, "allocator") == 0 || strcmp (p, "align") == 0)
19655 74 : && c_parser_check_balanced_raw_token_sequence (parser, &n)
19656 150 : && (c_parser_peek_nth_token_raw (parser, n)->type
19657 : == CPP_CLOSE_PAREN))
19658 : {
19659 74 : if (c_parser_peek_nth_token_raw (parser, n + 1)->type
19660 : == CPP_COLON)
19661 : has_modifiers = true;
19662 39 : else if (c_parser_peek_nth_token_raw (parser, n + 1)->type
19663 : == CPP_COMMA
19664 39 : && (c_parser_peek_nth_token_raw (parser, n + 2)->type
19665 : == CPP_NAME)
19666 78 : && (c_parser_peek_nth_token_raw (parser, n + 3)->type
19667 : == CPP_OPEN_PAREN))
19668 : {
19669 39 : c_token *tok = c_parser_peek_nth_token_raw (parser, n + 2);
19670 39 : const char *q = IDENTIFIER_POINTER (tok->value);
19671 39 : n += 4;
19672 39 : if ((strcmp (q, "allocator") == 0
19673 26 : || strcmp (q, "align") == 0)
19674 39 : && c_parser_check_balanced_raw_token_sequence (parser,
19675 : &n)
19676 39 : && (c_parser_peek_nth_token_raw (parser, n)->type
19677 : == CPP_CLOSE_PAREN)
19678 78 : && (c_parser_peek_nth_token_raw (parser, n + 1)->type
19679 : == CPP_COLON))
19680 : has_modifiers = true;
19681 : }
19682 : }
19683 : if (has_modifiers)
19684 : {
19685 74 : c_parser_consume_token (parser);
19686 74 : matching_parens parens2;
19687 74 : parens2.require_open (parser);
19688 74 : location_t expr_loc = c_parser_peek_token (parser)->location;
19689 74 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19690 74 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
19691 74 : if (expr.value == error_mark_node)
19692 : ;
19693 73 : else if (strcmp (p, "allocator") == 0)
19694 : {
19695 46 : allocator = expr.value;
19696 46 : allocator = c_fully_fold (allocator, false, NULL);
19697 3 : orig_type = expr.original_type
19698 46 : ? expr.original_type : TREE_TYPE (allocator);
19699 46 : orig_type = TYPE_MAIN_VARIANT (orig_type);
19700 : }
19701 : else
19702 : {
19703 27 : align = expr.value;
19704 27 : align = c_fully_fold (align, false, NULL);
19705 : }
19706 74 : parens2.skip_until_found_close (parser);
19707 74 : if (c_parser_next_token_is (parser, CPP_COMMA))
19708 : {
19709 39 : c_parser_consume_token (parser);
19710 39 : c_token *tok = c_parser_peek_token (parser);
19711 39 : const char *q = "";
19712 39 : if (c_parser_next_token_is (parser, CPP_NAME))
19713 39 : q = IDENTIFIER_POINTER (tok->value);
19714 39 : if (strcmp (q, "allocator") != 0 && strcmp (q, "align") != 0)
19715 : {
19716 0 : c_parser_error (parser, "expected %<allocator%> or "
19717 : "%<align%>");
19718 0 : parens.skip_until_found_close (parser);
19719 2 : return list;
19720 : }
19721 39 : else if (strcmp (p, q) == 0)
19722 : {
19723 2 : error_at (tok->location, "duplicate %qs modifier", p);
19724 2 : parens.skip_until_found_close (parser);
19725 2 : return list;
19726 : }
19727 37 : c_parser_consume_token (parser);
19728 37 : if (!parens2.require_open (parser))
19729 : {
19730 0 : parens.skip_until_found_close (parser);
19731 0 : return list;
19732 : }
19733 37 : expr_loc = c_parser_peek_token (parser)->location;
19734 37 : expr = c_parser_expr_no_commas (parser, NULL);
19735 37 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false,
19736 : true);
19737 37 : if (strcmp (q, "allocator") == 0)
19738 : {
19739 12 : allocator = expr.value;
19740 12 : allocator = c_fully_fold (allocator, false, NULL);
19741 2 : orig_type = expr.original_type
19742 12 : ? expr.original_type : TREE_TYPE (allocator);
19743 12 : orig_type = TYPE_MAIN_VARIANT (orig_type);
19744 : }
19745 : else
19746 : {
19747 25 : align = expr.value;
19748 25 : align = c_fully_fold (align, false, NULL);
19749 : }
19750 37 : parens2.skip_until_found_close (parser);
19751 : }
19752 : }
19753 : }
19754 74 : if (!has_modifiers)
19755 : {
19756 146 : location_t expr_loc = c_parser_peek_token (parser)->location;
19757 146 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19758 146 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
19759 146 : if (expr.value != error_mark_node)
19760 : {
19761 145 : allocator = expr.value;
19762 145 : allocator = c_fully_fold (allocator, false, NULL);
19763 7 : orig_type = expr.original_type
19764 145 : ? expr.original_type : TREE_TYPE (allocator);
19765 145 : orig_type = TYPE_MAIN_VARIANT (orig_type);
19766 : }
19767 : }
19768 218 : if (allocator
19769 218 : && (!INTEGRAL_TYPE_P (TREE_TYPE (allocator))
19770 200 : || TREE_CODE (orig_type) != ENUMERAL_TYPE
19771 396 : || (TYPE_NAME (orig_type)
19772 198 : != get_identifier ("omp_allocator_handle_t"))))
19773 : {
19774 8 : error_at (clause_loc, "%<allocate%> clause allocator expression "
19775 : "has type %qT rather than "
19776 : "%<omp_allocator_handle_t%>",
19777 4 : TREE_TYPE (allocator));
19778 4 : allocator = NULL_TREE;
19779 : }
19780 218 : if (align
19781 218 : && (!INTEGRAL_TYPE_P (TREE_TYPE (align))
19782 50 : || !tree_fits_uhwi_p (align)
19783 49 : || !integer_pow2p (align)))
19784 : {
19785 4 : error_at (clause_loc, "%<allocate%> clause %<align%> modifier "
19786 : "argument needs to be positive constant "
19787 : "power of two integer expression");
19788 4 : align = NULL_TREE;
19789 : }
19790 218 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
19791 : {
19792 0 : parens.skip_until_found_close (parser);
19793 0 : return list;
19794 : }
19795 : }
19796 :
19797 483 : nl = c_parser_omp_variable_list (parser, clause_loc,
19798 : OMP_CLAUSE_ALLOCATE, list);
19799 :
19800 483 : if (allocator || align)
19801 508 : for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
19802 : {
19803 300 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
19804 300 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
19805 : }
19806 :
19807 483 : parens.skip_until_found_close (parser);
19808 483 : return nl;
19809 : }
19810 :
19811 : /* OpenMP 5.0:
19812 : uses_allocators ( allocator-list )
19813 :
19814 : allocator-list:
19815 : allocator
19816 : allocator , allocator-list
19817 : allocator ( traits-array )
19818 : allocator ( traits-array ) , allocator-list
19819 :
19820 : Deprecated in 5.2, removed in 6.0: 'allocator(trait-array)' syntax.
19821 :
19822 : OpenMP 5.2:
19823 :
19824 : uses_allocators ( modifier : allocator-list )
19825 : uses_allocators ( modifier , modifier : allocator-list )
19826 :
19827 : OpenMP 6.0:
19828 : uses_allocators ( [modifier-list :] allocator-list [; ...] )
19829 :
19830 : modifier:
19831 : traits ( traits-array )
19832 : memspace ( mem-space-handle ) */
19833 :
19834 : static tree
19835 55 : c_parser_omp_clause_uses_allocators (c_parser *parser, tree list)
19836 : {
19837 55 : location_t clause_loc = c_parser_peek_token (parser)->location;
19838 55 : tree nl = list;
19839 55 : matching_parens parens;
19840 55 : if (!parens.require_open (parser))
19841 : return list;
19842 :
19843 55 : parse_next:
19844 :
19845 59 : bool has_modifiers = false;
19846 59 : bool seen_allocators = false;
19847 59 : tree memspace_expr = NULL_TREE;
19848 59 : tree traits_var = NULL_TREE;
19849 :
19850 59 : if (c_parser_next_token_is (parser, CPP_NAME)
19851 59 : && c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN)
19852 : {
19853 38 : unsigned int n = 3;
19854 38 : const char *p
19855 38 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
19856 25 : if ((strcmp (p, "traits") == 0 || strcmp (p, "memspace") == 0)
19857 26 : && c_parser_check_balanced_raw_token_sequence (parser, &n)
19858 64 : && (c_parser_peek_nth_token_raw (parser, n)->type
19859 : == CPP_CLOSE_PAREN))
19860 : {
19861 26 : if (c_parser_peek_nth_token_raw (parser, n + 1)->type
19862 : == CPP_COLON)
19863 : has_modifiers = true;
19864 9 : else if (c_parser_peek_nth_token_raw (parser, n + 1)->type
19865 : == CPP_COMMA
19866 8 : && (c_parser_peek_nth_token_raw (parser, n + 2)->type
19867 : == CPP_NAME)
19868 17 : && (c_parser_peek_nth_token_raw (parser, n + 3)->type
19869 : == CPP_OPEN_PAREN))
19870 : {
19871 7 : c_token *tok = c_parser_peek_nth_token_raw (parser, n + 2);
19872 7 : const char *q = IDENTIFIER_POINTER (tok->value);
19873 7 : n += 4;
19874 7 : if ((strcmp (q, "traits") == 0
19875 3 : || strcmp (q, "memspace") == 0)
19876 7 : && c_parser_check_balanced_raw_token_sequence (parser, &n)
19877 14 : && (c_parser_peek_nth_token_raw (parser, n)->type
19878 : == CPP_CLOSE_PAREN))
19879 : {
19880 7 : if (c_parser_peek_nth_token_raw (parser, n + 1)->type
19881 : == CPP_COLON)
19882 6 : has_modifiers = true;
19883 7 : if ((c_parser_peek_nth_token_raw (parser, n + 1)->type
19884 : == CPP_COMMA)
19885 7 : && (c_parser_peek_nth_token_raw (parser, n + 2)->type
19886 : == CPP_NAME))
19887 : {
19888 1 : c_token *tok
19889 1 : = c_parser_peek_nth_token_raw (parser, n + 2);
19890 1 : const char *m = IDENTIFIER_POINTER (tok->value);
19891 1 : if (strcmp (p, m) == 0 || strcmp (q, m) == 0)
19892 : {
19893 1 : error_at (tok->location, "duplicate %qs modifier", m);
19894 1 : goto end;
19895 : }
19896 : }
19897 : }
19898 : }
19899 : }
19900 6 : if (has_modifiers)
19901 : {
19902 23 : c_parser_consume_token (parser);
19903 23 : matching_parens parens2;
19904 23 : parens2.require_open (parser);
19905 23 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19906 23 : if (expr.value == error_mark_node)
19907 : ;
19908 20 : else if (strcmp (p, "traits") == 0)
19909 : {
19910 11 : traits_var = expr.value;
19911 11 : traits_var = c_fully_fold (traits_var, false, NULL);
19912 11 : mark_exp_read (traits_var);
19913 : }
19914 : else
19915 : {
19916 9 : memspace_expr = expr.value;
19917 9 : memspace_expr = c_fully_fold (memspace_expr, false, NULL);
19918 : }
19919 23 : parens2.skip_until_found_close (parser);
19920 23 : if (c_parser_next_token_is (parser, CPP_COMMA))
19921 : {
19922 6 : c_parser_consume_token (parser);
19923 6 : c_token *tok = c_parser_peek_token (parser);
19924 6 : const char *q = "";
19925 6 : if (c_parser_next_token_is (parser, CPP_NAME))
19926 6 : q = IDENTIFIER_POINTER (tok->value);
19927 6 : if (strcmp (q, "traits") != 0 && strcmp (q, "memspace") != 0)
19928 : {
19929 0 : c_parser_error (parser, "expected %<traits%> or "
19930 : "%<memspace%>");
19931 0 : parens.skip_until_found_close (parser);
19932 0 : return list;
19933 : }
19934 6 : else if (strcmp (p, q) == 0)
19935 : {
19936 0 : error_at (tok->location, "duplicate %qs modifier", p);
19937 0 : parens.skip_until_found_close (parser);
19938 0 : return list;
19939 : }
19940 6 : c_parser_consume_token (parser);
19941 6 : if (!parens2.require_open (parser))
19942 : {
19943 0 : parens.skip_until_found_close (parser);
19944 0 : return list;
19945 : }
19946 6 : expr = c_parser_expr_no_commas (parser, NULL);
19947 6 : if (strcmp (q, "traits") == 0)
19948 : {
19949 3 : traits_var = expr.value;
19950 3 : traits_var = c_fully_fold (traits_var, false, NULL);
19951 3 : mark_exp_read (traits_var);
19952 : }
19953 : else
19954 : {
19955 3 : memspace_expr = expr.value;
19956 3 : memspace_expr = c_fully_fold (memspace_expr, false, NULL);
19957 : }
19958 6 : parens2.skip_until_found_close (parser);
19959 : }
19960 23 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
19961 0 : goto end;
19962 : }
19963 : }
19964 :
19965 69 : while (c_parser_next_token_is (parser, CPP_NAME))
19966 : {
19967 69 : location_t alloc_loc = c_parser_peek_token (parser)->location;
19968 69 : c_token *tok = c_parser_peek_token (parser);
19969 69 : const char *tok_s = IDENTIFIER_POINTER (tok->value);
19970 69 : tree t = lookup_name (tok->value);
19971 69 : if (t == NULL_TREE)
19972 : {
19973 4 : undeclared_variable (tok->location, tok->value);
19974 4 : t = error_mark_node;
19975 : }
19976 69 : c_parser_consume_token (parser);
19977 :
19978 : /* Legacy traits syntax. */
19979 69 : tree legacy_traits = NULL_TREE;
19980 69 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
19981 19 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME
19982 88 : && c_parser_peek_nth_token_raw (parser, 3)->type == CPP_CLOSE_PAREN)
19983 : {
19984 19 : matching_parens parens2;
19985 19 : parens2.require_open (parser);
19986 19 : const char *tok_a
19987 19 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
19988 19 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
19989 19 : location_t close_loc = c_parser_peek_token (parser)->location;
19990 19 : parens2.skip_until_found_close (parser);
19991 :
19992 19 : if (has_modifiers)
19993 : {
19994 2 : error_at (make_location (alloc_loc, alloc_loc, close_loc),
19995 : "legacy %<%s(%s)%> traits syntax not allowed in "
19996 : "%<uses_allocators%> clause when using modifiers",
19997 : tok_s, tok_a);
19998 3 : goto end;
19999 : }
20000 17 : legacy_traits = c_fully_fold (expr.value, false, NULL);
20001 17 : if (legacy_traits == error_mark_node)
20002 1 : goto end;
20003 16 : mark_exp_read (legacy_traits);
20004 :
20005 16 : gcc_rich_location richloc (make_location (alloc_loc, alloc_loc, close_loc));
20006 16 : if (nl == list)
20007 : {
20008 : /* Fixit only works well if it is the only first item. */
20009 13 : richloc.add_fixit_replace (alloc_loc, "traits");
20010 13 : richloc.add_fixit_insert_after (close_loc, ": ");
20011 13 : richloc.add_fixit_insert_after (close_loc, tok_s);
20012 : }
20013 16 : warning_at (&richloc, OPT_Wdeprecated_openmp,
20014 : "the specification of arguments to %<uses_allocators%> "
20015 : "where each item is of the form %<allocator(traits)%> is "
20016 : "deprecated since OpenMP 5.2");
20017 16 : }
20018 :
20019 66 : if (seen_allocators && has_modifiers)
20020 : {
20021 2 : error_at (c_parser_peek_token (parser)->location,
20022 : "%<uses_allocators%> clause only accepts a single "
20023 : "allocator when using modifiers");
20024 2 : goto end;
20025 : }
20026 64 : seen_allocators = true;
20027 :
20028 64 : tree c = build_omp_clause (clause_loc,
20029 : OMP_CLAUSE_USES_ALLOCATORS);
20030 64 : OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c) = t;
20031 64 : OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c) = memspace_expr;
20032 64 : OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c) = (legacy_traits
20033 64 : ? legacy_traits : traits_var);
20034 64 : OMP_CLAUSE_CHAIN (c) = nl;
20035 64 : nl = c;
20036 :
20037 64 : if (c_parser_next_token_is (parser, CPP_COMMA))
20038 11 : c_parser_consume_token (parser);
20039 : else
20040 : break;
20041 : }
20042 :
20043 53 : if (c_parser_next_token_is (parser, CPP_SEMICOLON))
20044 : {
20045 4 : c_parser_consume_token (parser);
20046 4 : goto parse_next;
20047 : }
20048 :
20049 49 : end:
20050 55 : parens.skip_until_found_close (parser);
20051 55 : return nl;
20052 : }
20053 :
20054 : /* OpenMP 4.0:
20055 : linear ( variable-list )
20056 : linear ( variable-list : expression )
20057 :
20058 : OpenMP 4.5:
20059 : linear ( modifier ( variable-list ) )
20060 : linear ( modifier ( variable-list ) : expression )
20061 :
20062 : modifier:
20063 : val
20064 :
20065 : OpenMP 5.2:
20066 : linear ( variable-list : modifiers-list )
20067 :
20068 : modifiers:
20069 : val
20070 : step ( expression ) */
20071 :
20072 : static tree
20073 478 : c_parser_omp_clause_linear (c_parser *parser, tree list)
20074 : {
20075 478 : location_t clause_loc = c_parser_peek_token (parser)->location;
20076 478 : location_t rm1_loc = UNKNOWN_LOCATION, rm2_loc = UNKNOWN_LOCATION;
20077 478 : location_t after_colon_loc = UNKNOWN_LOCATION;
20078 478 : tree nl, c, step;
20079 478 : enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT;
20080 478 : bool old_linear_modifier = false;
20081 :
20082 478 : matching_parens parens;
20083 478 : if (!parens.require_open (parser))
20084 : return list;
20085 :
20086 478 : if (c_parser_next_token_is (parser, CPP_NAME))
20087 : {
20088 478 : c_token *tok = c_parser_peek_token (parser);
20089 478 : const char *p = IDENTIFIER_POINTER (tok->value);
20090 478 : if (strcmp ("val", p) == 0)
20091 12 : kind = OMP_CLAUSE_LINEAR_VAL;
20092 478 : if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN)
20093 : kind = OMP_CLAUSE_LINEAR_DEFAULT;
20094 12 : if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
20095 : {
20096 12 : old_linear_modifier = true;
20097 12 : rm1_loc = make_location (tok->location, tok->location,
20098 12 : c_parser_peek_2nd_token (parser)->location);
20099 12 : c_parser_consume_token (parser);
20100 12 : c_parser_consume_token (parser);
20101 : }
20102 : }
20103 :
20104 478 : nl = c_parser_omp_variable_list (parser, clause_loc,
20105 : OMP_CLAUSE_LINEAR, list);
20106 :
20107 478 : if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
20108 : {
20109 12 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
20110 12 : rm2_loc = c_parser_peek_token (parser)->location;
20111 12 : parens.skip_until_found_close (parser);
20112 : }
20113 :
20114 478 : if (c_parser_next_token_is (parser, CPP_COLON))
20115 : {
20116 351 : c_parser_consume_token (parser);
20117 351 : location_t expr_loc = c_parser_peek_token (parser)->location;
20118 351 : after_colon_loc = expr_loc;
20119 351 : bool has_modifiers = false;
20120 351 : if (kind == OMP_CLAUSE_LINEAR_DEFAULT
20121 691 : && c_parser_next_token_is (parser, CPP_NAME))
20122 : {
20123 74 : c_token *tok = c_parser_peek_token (parser);
20124 74 : const char *p = IDENTIFIER_POINTER (tok->value);
20125 74 : unsigned int pos = 0;
20126 74 : if (strcmp ("val", p) == 0)
20127 9 : pos = 2;
20128 65 : else if (strcmp ("step", p) == 0
20129 65 : && c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN)
20130 : {
20131 13 : pos = 3;
20132 13 : if (c_parser_check_balanced_raw_token_sequence (parser, &pos)
20133 13 : && (c_parser_peek_nth_token_raw (parser, pos)->type
20134 : == CPP_CLOSE_PAREN))
20135 13 : ++pos;
20136 : else
20137 0 : pos = 0;
20138 : }
20139 74 : if (pos)
20140 : {
20141 22 : tok = c_parser_peek_nth_token_raw (parser, pos);
20142 22 : if (tok->type == CPP_COMMA || tok->type == CPP_CLOSE_PAREN)
20143 19 : has_modifiers = true;
20144 : }
20145 : }
20146 74 : if (has_modifiers)
20147 : {
20148 : step = NULL_TREE;
20149 29 : while (c_parser_next_token_is (parser, CPP_NAME))
20150 : {
20151 29 : c_token *tok = c_parser_peek_token (parser);
20152 29 : const char *p = IDENTIFIER_POINTER (tok->value);
20153 29 : if (strcmp ("val", p) == 0)
20154 : {
20155 11 : if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
20156 : error_at (tok->location, "multiple linear modifiers");
20157 11 : kind = OMP_CLAUSE_LINEAR_DEFAULT;
20158 11 : c_parser_consume_token (parser);
20159 : }
20160 18 : else if (strcmp ("step", p) == 0)
20161 : {
20162 18 : c_parser_consume_token (parser);
20163 18 : matching_parens parens2;
20164 18 : if (parens2.require_open (parser))
20165 : {
20166 18 : if (step)
20167 0 : error_at (tok->location,
20168 : "multiple %<step%> modifiers");
20169 18 : expr_loc = c_parser_peek_token (parser)->location;
20170 18 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
20171 18 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false,
20172 : true);
20173 18 : step = c_fully_fold (expr.value, false, NULL);
20174 18 : if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
20175 : {
20176 0 : error_at (clause_loc, "%<linear%> clause step "
20177 : "expression must be integral");
20178 0 : step = integer_one_node;
20179 : }
20180 18 : parens2.skip_until_found_close (parser);
20181 : }
20182 : else
20183 : break;
20184 : }
20185 : else
20186 : break;
20187 29 : if (c_parser_next_token_is (parser, CPP_COMMA))
20188 : {
20189 10 : c_parser_consume_token (parser);
20190 10 : continue;
20191 : }
20192 : break;
20193 : }
20194 19 : if (!step)
20195 1 : step = integer_one_node;
20196 : }
20197 : else
20198 : {
20199 332 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
20200 332 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
20201 332 : step = c_fully_fold (expr.value, false, NULL);
20202 332 : if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
20203 : {
20204 2 : error_at (clause_loc, "%<linear%> clause step expression must "
20205 : "be integral");
20206 2 : step = integer_one_node;
20207 : }
20208 : }
20209 :
20210 : }
20211 : else
20212 127 : step = integer_one_node;
20213 :
20214 965 : for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
20215 : {
20216 487 : OMP_CLAUSE_LINEAR_STEP (c) = step;
20217 487 : OMP_CLAUSE_LINEAR_KIND (c) = kind;
20218 487 : OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c) = old_linear_modifier;
20219 : }
20220 :
20221 478 : if (old_linear_modifier)
20222 : {
20223 12 : gcc_rich_location richloc (clause_loc);
20224 12 : if (rm2_loc != UNKNOWN_LOCATION)
20225 : {
20226 12 : richloc.add_fixit_remove (rm1_loc);
20227 12 : if (after_colon_loc != UNKNOWN_LOCATION)
20228 : {
20229 11 : richloc.add_fixit_remove (rm2_loc);
20230 11 : richloc.add_fixit_insert_before (after_colon_loc, "val, step (");
20231 11 : location_t close_loc = c_parser_peek_token (parser)->location;
20232 11 : richloc.add_fixit_insert_before (close_loc, ")");
20233 : }
20234 : else
20235 1 : richloc.add_fixit_replace (rm2_loc, " : val");
20236 : }
20237 12 : warning_at (&richloc, OPT_Wdeprecated_openmp,
20238 : "specifying the list items as arguments to the "
20239 : "modifiers is deprecated since OpenMP 5.2");
20240 12 : }
20241 :
20242 478 : parens.skip_until_found_close (parser);
20243 478 : return nl;
20244 : }
20245 :
20246 : /* OpenMP 5.0:
20247 : nontemporal ( variable-list ) */
20248 :
20249 : static tree
20250 121 : c_parser_omp_clause_nontemporal (c_parser *parser, tree list)
20251 : {
20252 121 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_NONTEMPORAL, list);
20253 : }
20254 :
20255 : /* OpenMP 4.0:
20256 : safelen ( constant-expression ) */
20257 :
20258 : static tree
20259 227 : c_parser_omp_clause_safelen (c_parser *parser, tree list)
20260 : {
20261 227 : location_t clause_loc = c_parser_peek_token (parser)->location;
20262 227 : tree c, t;
20263 :
20264 227 : matching_parens parens;
20265 227 : if (!parens.require_open (parser))
20266 : return list;
20267 :
20268 227 : location_t expr_loc = c_parser_peek_token (parser)->location;
20269 227 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
20270 227 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
20271 227 : t = expr.value;
20272 227 : t = c_fully_fold (t, false, NULL);
20273 227 : if (TREE_CODE (t) != INTEGER_CST
20274 225 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
20275 452 : || tree_int_cst_sgn (t) != 1)
20276 : {
20277 4 : error_at (clause_loc, "%<safelen%> clause expression must "
20278 : "be positive constant integer expression");
20279 4 : t = NULL_TREE;
20280 : }
20281 :
20282 227 : parens.skip_until_found_close (parser);
20283 227 : if (t == NULL_TREE || t == error_mark_node)
20284 : return list;
20285 :
20286 223 : check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
20287 :
20288 223 : c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
20289 223 : OMP_CLAUSE_SAFELEN_EXPR (c) = t;
20290 223 : OMP_CLAUSE_CHAIN (c) = list;
20291 223 : return c;
20292 : }
20293 :
20294 : /* OpenMP 4.0:
20295 : simdlen ( constant-expression )
20296 :
20297 : OpenMP 6.1:
20298 : simdlen ([scaled(type[, constant-expression]):] constant-expression ) */
20299 :
20300 : static tree
20301 362 : c_parser_omp_clause_simdlen (c_parser *parser, tree list)
20302 : {
20303 362 : location_t clause_loc = c_parser_peek_token (parser)->location;
20304 362 : tree c, t = NULL_TREE, type = NULL_TREE, divisor = NULL_TREE;
20305 :
20306 362 : matching_parens parens;
20307 362 : if (!parens.require_open (parser))
20308 : return list;
20309 :
20310 362 : unsigned pos = 3;
20311 362 : if (c_parser_next_token_is (parser, CPP_NAME)
20312 18 : && c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN
20313 17 : && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
20314 : "scaled") == 0
20315 17 : && c_parser_check_balanced_raw_token_sequence (parser, &pos)
20316 379 : && c_parser_peek_nth_token_raw (parser, ++pos)->type == CPP_COLON)
20317 : {
20318 16 : c_parser_consume_token (parser);
20319 16 : matching_parens parens2;
20320 16 : parens2.require_open (parser);
20321 :
20322 16 : location_t loc = c_parser_peek_token (parser)->location;
20323 16 : struct c_type_name *ctype = c_parser_type_name (parser);
20324 16 : if (ctype == NULL
20325 15 : || (type = groktypename (ctype, NULL, NULL)) == NULL
20326 16 : || (!INTEGRAL_TYPE_P (type)
20327 15 : && !SCALAR_FLOAT_TYPE_P (type)
20328 2 : && TREE_CODE (type) != COMPLEX_TYPE))
20329 : {
20330 2 : error_at (loc, "expected arithmetic type name as argument to the "
20331 : "%<scaled%> modifier");
20332 2 : type = error_mark_node;
20333 : }
20334 14 : else if (c_parser_next_token_is (parser, CPP_COMMA))
20335 : {
20336 9 : c_parser_consume_token (parser);
20337 9 : loc = c_parser_peek_token (parser)->location;
20338 9 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
20339 9 : expr = convert_lvalue_to_rvalue (loc, expr, false, true);
20340 9 : divisor = expr.value;
20341 9 : divisor = c_fully_fold (divisor, false, NULL);
20342 9 : if (TREE_CODE (divisor) != INTEGER_CST
20343 8 : || !INTEGRAL_TYPE_P (TREE_TYPE (divisor))
20344 17 : || tree_int_cst_sgn (divisor) != 1)
20345 : {
20346 3 : error_at (loc, "divisor expression of the %<scaled%> modifier "
20347 : "must a be positive constant integer expression");
20348 3 : type = error_mark_node;
20349 : }
20350 : }
20351 16 : parens2.skip_until_found_close (parser);
20352 16 : c_parser_require (parser, CPP_COLON, "expected %<:%>");
20353 : }
20354 :
20355 362 : if (type != error_mark_node)
20356 : {
20357 357 : location_t expr_loc = c_parser_peek_token (parser)->location;
20358 357 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
20359 357 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
20360 357 : t = expr.value;
20361 357 : t = c_fully_fold (t, false, NULL);
20362 357 : if (TREE_CODE (t) != INTEGER_CST
20363 354 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
20364 711 : || tree_int_cst_sgn (t) != 1)
20365 : {
20366 5 : error_at (clause_loc, "%<simdlen%> clause expression must "
20367 : "be positive constant integer expression");
20368 5 : t = NULL_TREE;
20369 : }
20370 : }
20371 :
20372 362 : parens.skip_until_found_close (parser);
20373 362 : if (type == error_mark_node || t == NULL_TREE || t == error_mark_node)
20374 : return list;
20375 :
20376 352 : check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
20377 :
20378 352 : c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
20379 352 : OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
20380 352 : OMP_CLAUSE_SIMDLEN_TYPE (c) = type;
20381 352 : OMP_CLAUSE_SIMDLEN_DIVISOR (c) = divisor;
20382 352 : OMP_CLAUSE_CHAIN (c) = list;
20383 352 : return c;
20384 : }
20385 :
20386 : /* OpenMP 4.5:
20387 : vec:
20388 : identifier [+/- integer]
20389 : vec , identifier [+/- integer]
20390 : */
20391 :
20392 : static tree
20393 207 : c_parser_omp_clause_doacross_sink (c_parser *parser, location_t clause_loc,
20394 : tree list, bool depend_p)
20395 : {
20396 207 : tree vec = NULL;
20397 207 : if (c_parser_next_token_is_not (parser, CPP_NAME)
20398 207 : || c_parser_peek_token (parser)->id_kind != C_ID_ID)
20399 : {
20400 0 : c_parser_error (parser, "expected identifier");
20401 0 : return list;
20402 : }
20403 :
20404 207 : if (!depend_p)
20405 : {
20406 83 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
20407 83 : if (strcmp (p, "omp_cur_iteration") == 0
20408 36 : && c_parser_peek_2nd_token (parser)->type == CPP_MINUS
20409 34 : && c_parser_peek_nth_token (parser, 3)->type == CPP_NUMBER
20410 116 : && c_parser_peek_nth_token (parser, 4)->type == CPP_CLOSE_PAREN)
20411 : {
20412 33 : tree val = c_parser_peek_nth_token (parser, 3)->value;
20413 33 : if (integer_onep (val))
20414 : {
20415 33 : c_parser_consume_token (parser);
20416 33 : c_parser_consume_token (parser);
20417 33 : c_parser_consume_token (parser);
20418 33 : tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS);
20419 33 : OMP_CLAUSE_DOACROSS_KIND (u) = OMP_CLAUSE_DOACROSS_SINK;
20420 33 : OMP_CLAUSE_CHAIN (u) = list;
20421 33 : return u;
20422 : }
20423 : }
20424 : }
20425 :
20426 :
20427 :
20428 1152 : while (c_parser_next_token_is (parser, CPP_NAME)
20429 1152 : && c_parser_peek_token (parser)->id_kind == C_ID_ID)
20430 : {
20431 1152 : tree t = lookup_name (c_parser_peek_token (parser)->value);
20432 1152 : tree addend = NULL;
20433 :
20434 1152 : if (t == NULL_TREE)
20435 : {
20436 6 : undeclared_variable (c_parser_peek_token (parser)->location,
20437 6 : c_parser_peek_token (parser)->value);
20438 6 : t = error_mark_node;
20439 : }
20440 :
20441 1152 : c_parser_consume_token (parser);
20442 :
20443 1152 : bool neg = false;
20444 1152 : if (c_parser_next_token_is (parser, CPP_MINUS))
20445 : neg = true;
20446 920 : else if (!c_parser_next_token_is (parser, CPP_PLUS))
20447 : {
20448 857 : addend = integer_zero_node;
20449 857 : neg = false;
20450 857 : goto add_to_vector;
20451 : }
20452 295 : c_parser_consume_token (parser);
20453 :
20454 295 : if (c_parser_next_token_is_not (parser, CPP_NUMBER))
20455 : {
20456 1 : c_parser_error (parser, "expected integer");
20457 1 : return list;
20458 : }
20459 :
20460 294 : addend = c_parser_peek_token (parser)->value;
20461 294 : if (TREE_CODE (addend) != INTEGER_CST)
20462 : {
20463 0 : c_parser_error (parser, "expected integer");
20464 0 : return list;
20465 : }
20466 294 : c_parser_consume_token (parser);
20467 :
20468 1151 : add_to_vector:
20469 1151 : if (t != error_mark_node)
20470 : {
20471 1146 : vec = tree_cons (addend, t, vec);
20472 1146 : if (neg)
20473 229 : OMP_CLAUSE_DOACROSS_SINK_NEGATIVE (vec) = 1;
20474 : }
20475 :
20476 1151 : if (c_parser_next_token_is_not (parser, CPP_COMMA)
20477 979 : || c_parser_peek_2nd_token (parser)->type != CPP_NAME
20478 2129 : || c_parser_peek_2nd_token (parser)->id_kind != C_ID_ID)
20479 : break;
20480 :
20481 978 : c_parser_consume_token (parser);
20482 : }
20483 :
20484 173 : if (vec == NULL_TREE)
20485 : return list;
20486 :
20487 169 : tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS);
20488 169 : OMP_CLAUSE_DOACROSS_KIND (u) = OMP_CLAUSE_DOACROSS_SINK;
20489 169 : OMP_CLAUSE_DOACROSS_DEPEND (u) = depend_p;
20490 169 : OMP_CLAUSE_DECL (u) = nreverse (vec);
20491 169 : OMP_CLAUSE_CHAIN (u) = list;
20492 169 : return u;
20493 : }
20494 :
20495 : /* OpenMP 5.0:
20496 : iterators ( iterators-definition )
20497 :
20498 : iterators-definition:
20499 : iterator-specifier
20500 : iterator-specifier , iterators-definition
20501 :
20502 : iterator-specifier:
20503 : identifier = range-specification
20504 : iterator-type identifier = range-specification
20505 :
20506 : range-specification:
20507 : begin : end
20508 : begin : end : step */
20509 :
20510 : static tree
20511 155 : c_parser_omp_iterators (c_parser *parser)
20512 : {
20513 155 : tree ret = NULL_TREE, *last = &ret;
20514 155 : c_parser_consume_token (parser);
20515 :
20516 155 : push_scope ();
20517 :
20518 155 : matching_parens parens;
20519 155 : if (!parens.require_open (parser))
20520 1 : return error_mark_node;
20521 :
20522 220 : do
20523 : {
20524 187 : tree iter_type = NULL_TREE, type_expr = NULL_TREE;
20525 187 : if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
20526 : {
20527 50 : struct c_type_name *type = c_parser_type_name (parser);
20528 50 : if (type != NULL)
20529 50 : iter_type = groktypename (type, &type_expr, NULL);
20530 : }
20531 50 : if (iter_type == NULL_TREE)
20532 137 : iter_type = integer_type_node;
20533 :
20534 187 : location_t loc = c_parser_peek_token (parser)->location;
20535 187 : if (!c_parser_next_token_is (parser, CPP_NAME))
20536 : {
20537 8 : c_parser_error (parser, "expected identifier");
20538 8 : break;
20539 : }
20540 :
20541 179 : tree id = c_parser_peek_token (parser)->value;
20542 179 : c_parser_consume_token (parser);
20543 :
20544 179 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
20545 : break;
20546 :
20547 177 : location_t eloc = c_parser_peek_token (parser)->location;
20548 177 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
20549 177 : expr = convert_lvalue_to_rvalue (eloc, expr, true, false);
20550 177 : tree begin = expr.value;
20551 :
20552 177 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
20553 : break;
20554 :
20555 175 : eloc = c_parser_peek_token (parser)->location;
20556 175 : expr = c_parser_expr_no_commas (parser, NULL);
20557 175 : expr = convert_lvalue_to_rvalue (eloc, expr, true, false);
20558 175 : tree end = expr.value;
20559 :
20560 175 : tree step = integer_one_node;
20561 175 : if (c_parser_next_token_is (parser, CPP_COLON))
20562 : {
20563 59 : c_parser_consume_token (parser);
20564 59 : eloc = c_parser_peek_token (parser)->location;
20565 59 : expr = c_parser_expr_no_commas (parser, NULL);
20566 59 : expr = convert_lvalue_to_rvalue (eloc, expr, true, false);
20567 59 : step = expr.value;
20568 : }
20569 :
20570 175 : tree iter_var = build_decl (loc, VAR_DECL, id, iter_type);
20571 175 : DECL_ARTIFICIAL (iter_var) = 1;
20572 175 : DECL_CONTEXT (iter_var) = current_function_decl;
20573 175 : pushdecl (iter_var);
20574 :
20575 175 : *last = make_omp_iterator ();
20576 175 : OMP_ITERATOR_VAR (*last) = iter_var;
20577 175 : OMP_ITERATOR_BEGIN (*last) = begin;
20578 175 : OMP_ITERATOR_END (*last) = end;
20579 175 : OMP_ITERATOR_STEP (*last) = step;
20580 175 : last = &TREE_CHAIN (*last);
20581 :
20582 175 : if (c_parser_next_token_is (parser, CPP_COMMA))
20583 : {
20584 33 : c_parser_consume_token (parser);
20585 33 : continue;
20586 : }
20587 : break;
20588 33 : }
20589 : while (1);
20590 :
20591 154 : parens.skip_until_found_close (parser);
20592 154 : return ret ? ret : error_mark_node;
20593 : }
20594 :
20595 : /* OpenMP 5.0:
20596 : affinity ( [aff-modifier :] variable-list )
20597 : aff-modifier:
20598 : iterator ( iterators-definition ) */
20599 :
20600 : static tree
20601 151 : c_parser_omp_clause_affinity (c_parser *parser, tree list)
20602 : {
20603 151 : location_t clause_loc = c_parser_peek_token (parser)->location;
20604 151 : tree nl, iterators = NULL_TREE;
20605 :
20606 151 : matching_parens parens;
20607 151 : if (!parens.require_open (parser))
20608 : return list;
20609 :
20610 151 : if (c_parser_next_token_is (parser, CPP_NAME))
20611 : {
20612 149 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
20613 149 : bool parse_iter = ((strcmp ("iterator", p) == 0)
20614 149 : && (c_parser_peek_2nd_token (parser)->type
20615 50 : == CPP_OPEN_PAREN));
20616 50 : if (parse_iter)
20617 : {
20618 50 : unsigned n = 3;
20619 50 : parse_iter = (c_parser_check_balanced_raw_token_sequence (parser, &n)
20620 50 : && (c_parser_peek_nth_token_raw (parser, n)->type
20621 : == CPP_CLOSE_PAREN)
20622 100 : && (c_parser_peek_nth_token_raw (parser, n + 1)->type
20623 : == CPP_COLON));
20624 : }
20625 3 : if (parse_iter)
20626 : {
20627 47 : iterators = c_parser_omp_iterators (parser);
20628 47 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
20629 : {
20630 0 : if (iterators)
20631 0 : pop_scope ();
20632 0 : parens.skip_until_found_close (parser);
20633 0 : return list;
20634 : }
20635 : }
20636 : }
20637 151 : nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_AFFINITY,
20638 : list);
20639 151 : if (iterators)
20640 : {
20641 47 : tree block = pop_scope ();
20642 47 : if (iterators != error_mark_node)
20643 : {
20644 43 : OMP_ITERATOR_BLOCK (iterators) = block;
20645 99 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
20646 112 : OMP_CLAUSE_DECL (c) = build_tree_list (iterators,
20647 56 : OMP_CLAUSE_DECL (c));
20648 : }
20649 : }
20650 :
20651 151 : parens.skip_until_found_close (parser);
20652 151 : return nl;
20653 : }
20654 :
20655 :
20656 : /* OpenMP 4.0:
20657 : depend ( depend-kind: variable-list )
20658 :
20659 : depend-kind:
20660 : in | out | inout
20661 :
20662 : OpenMP 4.5:
20663 : depend ( source )
20664 :
20665 : depend ( sink : vec )
20666 :
20667 : OpenMP 5.0:
20668 : depend ( depend-modifier , depend-kind: variable-list )
20669 :
20670 : depend-kind:
20671 : in | out | inout | mutexinoutset | depobj | inoutset
20672 :
20673 : depend-modifier:
20674 : iterator ( iterators-definition ) */
20675 :
20676 : static tree
20677 895 : c_parser_omp_clause_depend (c_parser *parser, tree list, location_t here)
20678 : {
20679 895 : location_t clause_loc = c_parser_peek_token (parser)->location;
20680 895 : enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_LAST;
20681 895 : enum omp_clause_doacross_kind dkind = OMP_CLAUSE_DOACROSS_LAST;
20682 895 : tree nl, c, iterators = NULL_TREE;
20683 :
20684 895 : matching_parens parens;
20685 895 : if (!parens.require_open (parser))
20686 : return list;
20687 :
20688 1049 : do
20689 : {
20690 972 : if (c_parser_next_token_is_not (parser, CPP_NAME))
20691 0 : goto invalid_kind;
20692 :
20693 972 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
20694 972 : if (strcmp ("iterator", p) == 0 && iterators == NULL_TREE)
20695 : {
20696 77 : iterators = c_parser_omp_iterators (parser);
20697 77 : c_parser_require (parser, CPP_COMMA, "expected %<,%>");
20698 77 : continue;
20699 : }
20700 895 : if (strcmp ("in", p) == 0)
20701 : kind = OMP_CLAUSE_DEPEND_IN;
20702 644 : else if (strcmp ("inout", p) == 0)
20703 : kind = OMP_CLAUSE_DEPEND_INOUT;
20704 425 : else if (strcmp ("inoutset", p) == 0)
20705 : kind = OMP_CLAUSE_DEPEND_INOUTSET;
20706 410 : else if (strcmp ("mutexinoutset", p) == 0)
20707 : kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
20708 389 : else if (strcmp ("out", p) == 0)
20709 : kind = OMP_CLAUSE_DEPEND_OUT;
20710 244 : else if (strcmp ("depobj", p) == 0)
20711 : kind = OMP_CLAUSE_DEPEND_DEPOBJ;
20712 223 : else if (strcmp ("sink", p) == 0)
20713 : {
20714 124 : gcc_rich_location richloc (clause_loc);
20715 124 : richloc.add_fixit_replace (here, "doacross");
20716 124 : warning_at (&richloc, OPT_Wdeprecated_openmp,
20717 : "%<sink%> modifier with %<depend%> clause deprecated "
20718 : "since OpenMP 5.2, use with %<doacross%>");
20719 124 : dkind = OMP_CLAUSE_DOACROSS_SINK;
20720 124 : }
20721 99 : else if (strcmp ("source", p) == 0)
20722 : {
20723 97 : gcc_rich_location richloc (clause_loc);
20724 97 : richloc.add_fixit_replace (here, "doacross");
20725 97 : warning_at (&richloc, OPT_Wdeprecated_openmp,
20726 : "%<source%> modifier with %<depend%> clause deprecated "
20727 : "since OpenMP 5.2, use with %<doacross%>");
20728 97 : dkind = OMP_CLAUSE_DOACROSS_SOURCE;
20729 97 : }
20730 : else
20731 2 : goto invalid_kind;
20732 893 : break;
20733 77 : }
20734 : while (1);
20735 :
20736 893 : c_parser_consume_token (parser);
20737 :
20738 893 : if (iterators
20739 893 : && (dkind == OMP_CLAUSE_DOACROSS_SOURCE
20740 893 : || dkind == OMP_CLAUSE_DOACROSS_SINK))
20741 : {
20742 2 : pop_scope ();
20743 2 : error_at (clause_loc, "%<iterator%> modifier incompatible with %qs",
20744 : dkind == OMP_CLAUSE_DOACROSS_SOURCE ? "source" : "sink");
20745 2 : iterators = NULL_TREE;
20746 : }
20747 :
20748 893 : if (dkind == OMP_CLAUSE_DOACROSS_SOURCE)
20749 : {
20750 97 : c = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS);
20751 97 : OMP_CLAUSE_DOACROSS_KIND (c) = dkind;
20752 97 : OMP_CLAUSE_DOACROSS_DEPEND (c) = 1;
20753 97 : OMP_CLAUSE_DECL (c) = NULL_TREE;
20754 97 : OMP_CLAUSE_CHAIN (c) = list;
20755 97 : parens.skip_until_found_close (parser);
20756 97 : return c;
20757 : }
20758 :
20759 796 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
20760 0 : goto resync_fail;
20761 :
20762 796 : if (dkind == OMP_CLAUSE_DOACROSS_SINK)
20763 124 : nl = c_parser_omp_clause_doacross_sink (parser, clause_loc, list, true);
20764 : else
20765 : {
20766 672 : nl = c_parser_omp_variable_list (parser, clause_loc,
20767 : OMP_CLAUSE_DEPEND, list);
20768 :
20769 672 : if (iterators)
20770 : {
20771 73 : tree block = pop_scope ();
20772 73 : if (iterators == error_mark_node)
20773 : iterators = NULL_TREE;
20774 : else
20775 68 : OMP_ITERATOR_BLOCK (iterators) = block;
20776 : }
20777 :
20778 1385 : for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
20779 : {
20780 713 : OMP_CLAUSE_DEPEND_KIND (c) = kind;
20781 713 : if (iterators)
20782 150 : OMP_CLAUSE_DECL (c)
20783 150 : = build_tree_list (iterators, OMP_CLAUSE_DECL (c));
20784 : }
20785 : }
20786 :
20787 796 : parens.skip_until_found_close (parser);
20788 796 : return nl;
20789 :
20790 2 : invalid_kind:
20791 2 : c_parser_error (parser, "invalid depend kind");
20792 2 : resync_fail:
20793 2 : parens.skip_until_found_close (parser);
20794 2 : if (iterators)
20795 2 : pop_scope ();
20796 : return list;
20797 : }
20798 :
20799 : /* OpenMP 5.2:
20800 : doacross ( source : )
20801 : doacross ( source : omp_cur_iteration )
20802 :
20803 : doacross ( sink : vec )
20804 : doacross ( sink : omp_cur_iteration - logical_iteration ) */
20805 :
20806 : static tree
20807 145 : c_parser_omp_clause_doacross (c_parser *parser, tree list)
20808 : {
20809 145 : location_t clause_loc = c_parser_peek_token (parser)->location;
20810 145 : enum omp_clause_doacross_kind kind = OMP_CLAUSE_DOACROSS_LAST;
20811 145 : tree nl;
20812 145 : const char *p;
20813 :
20814 145 : matching_parens parens;
20815 145 : if (!parens.require_open (parser))
20816 : return list;
20817 :
20818 145 : if (c_parser_next_token_is_not (parser, CPP_NAME))
20819 0 : goto invalid_kind;
20820 :
20821 145 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
20822 145 : if (strcmp ("sink", p) == 0)
20823 : kind = OMP_CLAUSE_DOACROSS_SINK;
20824 60 : else if (strcmp ("source", p) == 0)
20825 : kind = OMP_CLAUSE_DOACROSS_SOURCE;
20826 : else
20827 0 : goto invalid_kind;
20828 :
20829 145 : c_parser_consume_token (parser);
20830 :
20831 145 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
20832 4 : goto resync_fail;
20833 :
20834 141 : if (kind == OMP_CLAUSE_DOACROSS_SOURCE)
20835 : {
20836 58 : if (c_parser_next_token_is (parser, CPP_NAME)
20837 58 : && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
20838 : "omp_cur_iteration") == 0)
20839 28 : c_parser_consume_token (parser);
20840 58 : nl = build_omp_clause (clause_loc, OMP_CLAUSE_DOACROSS);
20841 58 : OMP_CLAUSE_DOACROSS_KIND (nl) = OMP_CLAUSE_DOACROSS_SOURCE;
20842 58 : OMP_CLAUSE_DECL (nl) = NULL_TREE;
20843 58 : OMP_CLAUSE_CHAIN (nl) = list;
20844 : }
20845 : else
20846 83 : nl = c_parser_omp_clause_doacross_sink (parser, clause_loc, list, false);
20847 :
20848 141 : parens.skip_until_found_close (parser);
20849 141 : return nl;
20850 :
20851 0 : invalid_kind:
20852 0 : c_parser_error (parser, "invalid doacross kind");
20853 4 : resync_fail:
20854 4 : parens.skip_until_found_close (parser);
20855 4 : return list;
20856 : }
20857 :
20858 : /* OpenMP 6.1:
20859 : dyn_groupprivate ( [fallback-modifier : ] integer-expression )
20860 :
20861 : fallback-modifier
20862 : fallback( abort | default_mem | null ) */
20863 :
20864 : static tree
20865 21 : c_parser_omp_clause_dyn_groupprivate (c_parser *parser, tree list)
20866 : {
20867 21 : location_t clause_loc = c_parser_peek_token (parser)->location;
20868 21 : matching_parens parens;
20869 21 : if (!parens.require_open (parser))
20870 : return list;
20871 :
20872 21 : enum omp_clause_fallback_kind kind = OMP_CLAUSE_FALLBACK_UNSPECIFIED;
20873 :
20874 21 : unsigned n = 3;
20875 21 : if (c_parser_next_token_is (parser, CPP_NAME)
20876 21 : && (c_parser_peek_2nd_token (parser)->type == CPP_COLON
20877 9 : || (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN
20878 8 : && c_parser_check_balanced_raw_token_sequence (parser, &n)
20879 8 : && (c_parser_peek_nth_token_raw (parser, n)->type
20880 : == CPP_CLOSE_PAREN)
20881 8 : && (c_parser_peek_nth_token_raw (parser, n + 1)->type
20882 : == CPP_COLON))))
20883 : {
20884 10 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
20885 10 : if (strcmp (p, "fallback") != 0)
20886 : {
20887 3 : c_parser_error (parser, "expected %<fallback%> modifier");
20888 3 : return list;
20889 : }
20890 7 : c_parser_consume_token (parser);
20891 7 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
20892 : return list;
20893 6 : p = "";
20894 6 : if (c_parser_next_token_is (parser, CPP_NAME))
20895 5 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
20896 6 : if (strcmp (p, "abort") == 0)
20897 : kind = OMP_CLAUSE_FALLBACK_ABORT;
20898 5 : else if (strcmp (p, "default_mem") == 0)
20899 : kind = OMP_CLAUSE_FALLBACK_DEFAULT_MEM;
20900 4 : else if (strcmp (p, "null") == 0)
20901 : kind = OMP_CLAUSE_FALLBACK_NULL;
20902 : else
20903 : {
20904 2 : c_parser_error (parser, "expected %<abort%>, %<default_mem%>, or "
20905 : "%<null%> as fallback mode");
20906 2 : return list;
20907 : }
20908 4 : c_parser_consume_token (parser);
20909 4 : if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
20910 : return list;
20911 3 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
20912 : return list;
20913 : }
20914 14 : location_t expr_loc = c_parser_peek_token (parser)->location;
20915 14 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
20916 14 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
20917 14 : tree size = c_fully_fold (expr.value, false, NULL);
20918 14 : parens.skip_until_found_close (parser);
20919 :
20920 14 : if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
20921 : {
20922 2 : error_at (expr_loc, "expected integer expression");
20923 2 : return list;
20924 : }
20925 :
20926 : /* Attempt to statically determine when the number is negative. */
20927 12 : tree c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, size,
20928 12 : build_int_cst (TREE_TYPE (size), 0));
20929 12 : protected_set_expr_location (c, expr_loc);
20930 12 : if (c == boolean_true_node)
20931 : {
20932 3 : warning_at (expr_loc, OPT_Wopenmp,
20933 : "%<dyn_groupprivate%> value must be non-negative");
20934 3 : size = integer_zero_node;
20935 : }
20936 12 : check_no_duplicate_clause (list, OMP_CLAUSE_DYN_GROUPPRIVATE,
20937 : "dyn_groupprivate");
20938 :
20939 12 : c = build_omp_clause (clause_loc, OMP_CLAUSE_DYN_GROUPPRIVATE);
20940 12 : OMP_CLAUSE_DYN_GROUPPRIVATE_KIND (c) = kind;
20941 12 : OMP_CLAUSE_DYN_GROUPPRIVATE_EXPR (c) = size;
20942 12 : OMP_CLAUSE_CHAIN (c) = list;
20943 12 : list = c;
20944 :
20945 12 : return list;
20946 : }
20947 :
20948 : /* OpenMP 4.0:
20949 : map ( map-kind: variable-list )
20950 : map ( variable-list )
20951 :
20952 : map-kind:
20953 : alloc | to | from | tofrom
20954 :
20955 : OpenMP 4.5:
20956 : map-kind:
20957 : alloc | to | from | tofrom | release | delete
20958 :
20959 : map ( always [,] map-kind: variable-list )
20960 :
20961 : OpenMP 5.0:
20962 : map ( [map-type-modifier[,] ...] map-kind: variable-list )
20963 :
20964 : map-type-modifier:
20965 : always | close | present | iterator (iterators-definition) */
20966 :
20967 : static tree
20968 2044 : c_parser_omp_clause_map (c_parser *parser, tree list, bool declare_mapper_p)
20969 : {
20970 2044 : location_t clause_loc = c_parser_peek_token (parser)->location;
20971 2044 : tree nl, c;
20972 2044 : enum gomp_map_kind kind = declare_mapper_p ? GOMP_MAP_UNSET : GOMP_MAP_TOFROM;
20973 :
20974 2044 : matching_parens parens;
20975 2044 : if (!parens.require_open (parser))
20976 : return list;
20977 :
20978 : int pos = 1;
20979 2670 : int map_kind_pos = 0;
20980 : int iterator_length = 0;
20981 3296 : for (;;)
20982 : {
20983 2670 : c_token *tok = c_parser_peek_nth_token_raw (parser, pos);
20984 2670 : if (tok->type != CPP_NAME)
20985 : break;
20986 :
20987 2345 : const char *p = IDENTIFIER_POINTER (tok->value);
20988 2345 : c_token *next_tok = c_parser_peek_nth_token_raw (parser, pos + 1);
20989 2345 : if (strcmp (p, "iterator") == 0 && next_tok->type == CPP_OPEN_PAREN)
20990 : {
20991 18 : unsigned n = pos + 2;
20992 18 : if (c_parser_check_balanced_raw_token_sequence (parser, &n)
20993 18 : && c_parser_peek_nth_token_raw (parser, n)->type
20994 : == CPP_CLOSE_PAREN)
20995 : {
20996 18 : iterator_length = n - pos + 1;
20997 18 : pos = n;
20998 18 : next_tok = c_parser_peek_nth_token_raw (parser, pos + 1);
20999 : }
21000 : }
21001 :
21002 2345 : if (next_tok->type == CPP_COLON)
21003 : {
21004 : map_kind_pos = pos;
21005 : break;
21006 : }
21007 :
21008 626 : if (next_tok->type == CPP_COMMA)
21009 235 : pos++;
21010 391 : else if (c_parser_peek_nth_token_raw (parser, pos + 1)->type
21011 : == CPP_OPEN_PAREN)
21012 : {
21013 14 : unsigned int npos = pos + 2;
21014 14 : if (c_parser_check_balanced_raw_token_sequence (parser, &npos)
21015 14 : && (c_parser_peek_nth_token_raw (parser, npos)->type
21016 : == CPP_CLOSE_PAREN)
21017 28 : && (c_parser_peek_nth_token_raw (parser, npos + 1)->type
21018 : == CPP_COMMA))
21019 13 : pos = npos + 1;
21020 : }
21021 :
21022 626 : pos++;
21023 626 : }
21024 :
21025 2044 : int always_modifier = 0;
21026 2044 : int close_modifier = 0;
21027 2044 : int present_modifier = 0;
21028 2044 : int mapper_modifier = 0;
21029 2044 : int num_commas = 0;
21030 2044 : int num_identifiers = 0;
21031 2044 : tree mapper_name = NULL_TREE;
21032 2044 : tree iterators = NULL_TREE;
21033 2505 : for (int pos = 1; pos < map_kind_pos; ++pos)
21034 : {
21035 479 : c_token *tok = c_parser_peek_token (parser);
21036 :
21037 479 : if (tok->type == CPP_COMMA)
21038 : {
21039 207 : ++num_commas;
21040 207 : if (num_commas > num_identifiers)
21041 0 : c_parser_error (parser, "illegal comma");
21042 207 : c_parser_consume_token (parser);
21043 207 : continue;
21044 : }
21045 :
21046 272 : const char *p = IDENTIFIER_POINTER (tok->value);
21047 272 : if (strcmp ("always", p) == 0)
21048 : {
21049 101 : if (always_modifier)
21050 : {
21051 4 : c_parser_error (parser, "too many %<always%> modifiers");
21052 4 : parens.skip_until_found_close (parser);
21053 4 : return list;
21054 : }
21055 97 : always_modifier++;
21056 97 : c_parser_consume_token (parser);
21057 : }
21058 171 : else if (strcmp ("close", p) == 0)
21059 : {
21060 67 : if (close_modifier)
21061 : {
21062 4 : c_parser_error (parser, "too many %<close%> modifiers");
21063 4 : parens.skip_until_found_close (parser);
21064 4 : return list;
21065 : }
21066 63 : close_modifier++;
21067 63 : c_parser_consume_token (parser);
21068 : }
21069 104 : else if (strcmp ("iterator", p) == 0)
21070 : {
21071 18 : if (iterators)
21072 : {
21073 1 : c_parser_error (parser, "too many %<iterator%> modifiers");
21074 1 : parens.skip_until_found_close (parser);
21075 1 : return list;
21076 : }
21077 17 : iterators = c_parser_omp_iterators (parser);
21078 17 : pos += iterator_length - 1;
21079 : }
21080 86 : else if (strcmp ("mapper", p) == 0)
21081 : {
21082 13 : c_parser_consume_token (parser);
21083 :
21084 13 : matching_parens mparens;
21085 13 : if (mparens.require_open (parser))
21086 : {
21087 13 : if (mapper_modifier)
21088 : {
21089 0 : c_parser_error (parser, "too many %<mapper%> modifiers");
21090 : /* Assume it's a well-formed mapper modifier, even if it
21091 : seems to be in the wrong place. */
21092 0 : c_parser_consume_token (parser);
21093 0 : mparens.require_close (parser);
21094 0 : parens.skip_until_found_close (parser);
21095 0 : return list;
21096 : }
21097 :
21098 13 : tok = c_parser_peek_token (parser);
21099 :
21100 13 : switch (tok->type)
21101 : {
21102 6 : case CPP_NAME:
21103 6 : {
21104 6 : mapper_name = tok->value;
21105 6 : c_parser_consume_token (parser);
21106 6 : if (declare_mapper_p)
21107 : {
21108 1 : error_at (tok->location,
21109 : "in %<declare mapper%> directives, parameter "
21110 : "to %<mapper%> modifier must be %<default%>");
21111 : }
21112 : }
21113 : break;
21114 :
21115 7 : case CPP_KEYWORD:
21116 7 : if (tok->keyword == RID_DEFAULT)
21117 : {
21118 7 : c_parser_consume_token (parser);
21119 7 : break;
21120 : }
21121 : /* Fallthrough. */
21122 :
21123 0 : default:
21124 0 : error_at (tok->location,
21125 : "expected identifier or %<default%>");
21126 0 : return list;
21127 : }
21128 :
21129 13 : if (!mparens.require_close (parser))
21130 : {
21131 0 : parens.skip_until_found_close (parser);
21132 0 : return list;
21133 : }
21134 :
21135 13 : mapper_modifier++;
21136 13 : pos += 3;
21137 : }
21138 : }
21139 73 : else if (strcmp ("present", p) == 0)
21140 : {
21141 68 : if (present_modifier)
21142 : {
21143 4 : c_parser_error (parser, "too many %<present%> modifiers");
21144 4 : parens.skip_until_found_close (parser);
21145 4 : return list;
21146 : }
21147 64 : present_modifier++;
21148 64 : c_parser_consume_token (parser);
21149 : }
21150 : else
21151 : {
21152 5 : c_parser_error (parser, "%<map%> clause with map-type modifier other "
21153 : "than %<always%>, %<close%>, %<iterator%>, "
21154 : "%<mapper%> or %<present%>");
21155 5 : parens.skip_until_found_close (parser);
21156 5 : return list;
21157 : }
21158 254 : ++num_identifiers;
21159 254 : if (num_identifiers - 1 > num_commas)
21160 : {
21161 30 : gcc_rich_location richloc (clause_loc);
21162 30 : richloc.add_fixit_insert_before (tok->location, ",");
21163 30 : warning_at (&richloc, OPT_Wdeprecated_openmp,
21164 : "%<map%> clause modifiers without comma separation is "
21165 : "deprecated since OpenMP 5.2");
21166 30 : }
21167 : num_commas = num_identifiers - 1;
21168 : }
21169 :
21170 2026 : if (c_parser_next_token_is (parser, CPP_NAME)
21171 2026 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
21172 : {
21173 1701 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
21174 1701 : int always_present_modifier = always_modifier && present_modifier;
21175 :
21176 1701 : if (strcmp ("alloc", p) == 0)
21177 161 : kind = present_modifier ? GOMP_MAP_PRESENT_ALLOC : GOMP_MAP_ALLOC;
21178 1540 : else if (strcmp ("to", p) == 0)
21179 1056 : kind = (always_present_modifier ? GOMP_MAP_ALWAYS_PRESENT_TO
21180 544 : : present_modifier ? GOMP_MAP_PRESENT_TO
21181 533 : : always_modifier ? GOMP_MAP_ALWAYS_TO
21182 : : GOMP_MAP_TO);
21183 990 : else if (strcmp ("from", p) == 0)
21184 1201 : kind = (always_present_modifier ? GOMP_MAP_ALWAYS_PRESENT_FROM
21185 607 : : present_modifier ? GOMP_MAP_PRESENT_FROM
21186 602 : : always_modifier ? GOMP_MAP_ALWAYS_FROM
21187 : : GOMP_MAP_FROM);
21188 377 : else if (strcmp ("tofrom", p) == 0)
21189 588 : kind = (always_present_modifier ? GOMP_MAP_ALWAYS_PRESENT_TOFROM
21190 304 : : present_modifier ? GOMP_MAP_PRESENT_TOFROM
21191 298 : : always_modifier ? GOMP_MAP_ALWAYS_TOFROM
21192 : : GOMP_MAP_TOFROM);
21193 67 : else if (strcmp ("release", p) == 0)
21194 : kind = GOMP_MAP_RELEASE;
21195 19 : else if (strcmp ("delete", p) == 0)
21196 : kind = GOMP_MAP_DELETE;
21197 : else
21198 : {
21199 0 : c_parser_error (parser, "invalid map kind");
21200 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
21201 : "expected %<)%>");
21202 0 : return list;
21203 : }
21204 1701 : c_parser_consume_token (parser);
21205 1701 : c_parser_consume_token (parser);
21206 : }
21207 :
21208 2026 : nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list,
21209 : true);
21210 :
21211 2026 : tree last_new = NULL_TREE;
21212 :
21213 2026 : if (iterators)
21214 : {
21215 16 : tree block = pop_scope ();
21216 16 : if (iterators == error_mark_node)
21217 : iterators = NULL_TREE;
21218 : else
21219 16 : OMP_ITERATOR_BLOCK (iterators) = block;
21220 : }
21221 :
21222 4482 : for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
21223 : {
21224 2456 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
21225 2456 : OMP_CLAUSE_ITERATORS (c) = iterators;
21226 2456 : last_new = c;
21227 : }
21228 :
21229 2026 : if (mapper_name)
21230 : {
21231 6 : tree name = build_omp_clause (input_location, OMP_CLAUSE_MAP);
21232 6 : OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_PUSH_MAPPER_NAME);
21233 6 : OMP_CLAUSE_DECL (name) = mapper_name;
21234 6 : OMP_CLAUSE_CHAIN (name) = nl;
21235 6 : nl = name;
21236 :
21237 6 : gcc_assert (last_new);
21238 :
21239 6 : name = build_omp_clause (input_location, OMP_CLAUSE_MAP);
21240 6 : OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_POP_MAPPER_NAME);
21241 6 : OMP_CLAUSE_DECL (name) = null_pointer_node;
21242 6 : OMP_CLAUSE_CHAIN (name) = OMP_CLAUSE_CHAIN (last_new);
21243 6 : OMP_CLAUSE_CHAIN (last_new) = name;
21244 : }
21245 :
21246 2026 : parens.skip_until_found_close (parser);
21247 2026 : return nl;
21248 : }
21249 :
21250 : /* OpenMP 4.0:
21251 : device ( expression )
21252 :
21253 : OpenMP 5.0:
21254 : device ( [device-modifier :] integer-expression )
21255 :
21256 : device-modifier:
21257 : ancestor | device_num */
21258 :
21259 : static tree
21260 388 : c_parser_omp_clause_device (c_parser *parser, tree list)
21261 : {
21262 388 : location_t clause_loc = c_parser_peek_token (parser)->location;
21263 388 : location_t expr_loc;
21264 388 : c_expr expr;
21265 388 : tree c, t;
21266 388 : bool ancestor = false;
21267 :
21268 388 : matching_parens parens;
21269 388 : if (!parens.require_open (parser))
21270 : return list;
21271 :
21272 388 : if (c_parser_next_token_is (parser, CPP_NAME)
21273 388 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
21274 : {
21275 48 : c_token *tok = c_parser_peek_token (parser);
21276 48 : const char *p = IDENTIFIER_POINTER (tok->value);
21277 48 : if (strcmp ("ancestor", p) == 0)
21278 : {
21279 : /* A requires directive with the reverse_offload clause must be
21280 : specified. */
21281 25 : if ((omp_requires_mask & OMP_REQUIRES_REVERSE_OFFLOAD) == 0)
21282 : {
21283 1 : error_at (tok->location, "%<ancestor%> device modifier not "
21284 : "preceded by %<requires%> directive "
21285 : "with %<reverse_offload%> clause");
21286 1 : parens.skip_until_found_close (parser);
21287 1 : return list;
21288 : }
21289 : ancestor = true;
21290 : }
21291 23 : else if (strcmp ("device_num", p) == 0)
21292 : ;
21293 : else
21294 : {
21295 1 : error_at (tok->location, "expected %<ancestor%> or %<device_num%>");
21296 1 : parens.skip_until_found_close (parser);
21297 1 : return list;
21298 : }
21299 46 : c_parser_consume_token (parser);
21300 46 : c_parser_consume_token (parser);
21301 : }
21302 :
21303 386 : expr_loc = c_parser_peek_token (parser)->location;
21304 386 : expr = c_parser_expr_no_commas (parser, NULL);
21305 386 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
21306 386 : t = expr.value;
21307 386 : t = c_fully_fold (t, false, NULL);
21308 :
21309 386 : parens.skip_until_found_close (parser);
21310 :
21311 386 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
21312 : {
21313 2 : c_parser_error (parser, "expected integer expression");
21314 2 : return list;
21315 : }
21316 384 : if (ancestor && TREE_CODE (t) == INTEGER_CST && !integer_onep (t))
21317 : {
21318 1 : error_at (expr_loc, "the %<device%> clause expression must evaluate to "
21319 : "%<1%>");
21320 1 : return list;
21321 : }
21322 :
21323 383 : check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
21324 :
21325 383 : c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
21326 :
21327 383 : OMP_CLAUSE_DEVICE_ID (c) = t;
21328 383 : OMP_CLAUSE_CHAIN (c) = list;
21329 383 : OMP_CLAUSE_DEVICE_ANCESTOR (c) = ancestor;
21330 :
21331 383 : list = c;
21332 383 : return list;
21333 : }
21334 :
21335 : /* OpenMP 4.0:
21336 : dist_schedule ( static )
21337 : dist_schedule ( static , expression ) */
21338 :
21339 : static tree
21340 1586 : c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
21341 : {
21342 1586 : tree c, t = NULL_TREE;
21343 1586 : location_t loc = c_parser_peek_token (parser)->location;
21344 :
21345 1586 : matching_parens parens;
21346 1586 : if (!parens.require_open (parser))
21347 : return list;
21348 :
21349 1586 : if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
21350 : {
21351 0 : c_parser_error (parser, "invalid dist_schedule kind");
21352 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
21353 : "expected %<)%>");
21354 0 : return list;
21355 : }
21356 :
21357 1586 : c_parser_consume_token (parser);
21358 1586 : if (c_parser_next_token_is (parser, CPP_COMMA))
21359 : {
21360 1579 : c_parser_consume_token (parser);
21361 :
21362 1579 : location_t expr_loc = c_parser_peek_token (parser)->location;
21363 1579 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
21364 1579 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
21365 1579 : t = expr.value;
21366 1579 : t = c_fully_fold (t, false, NULL);
21367 1579 : parens.skip_until_found_close (parser);
21368 : }
21369 : else
21370 7 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
21371 : "expected %<,%> or %<)%>");
21372 :
21373 : /* check_no_duplicate_clause (list, OMP_CLAUSE_DIST_SCHEDULE,
21374 : "dist_schedule"); */
21375 1586 : if (omp_find_clause (list, OMP_CLAUSE_DIST_SCHEDULE))
21376 2 : warning_at (loc, OPT_Wopenmp, "too many %qs clauses", "dist_schedule");
21377 1586 : if (t == error_mark_node)
21378 : return list;
21379 :
21380 1586 : c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
21381 1586 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
21382 1586 : OMP_CLAUSE_CHAIN (c) = list;
21383 1586 : return c;
21384 : }
21385 :
21386 : /* OpenMP 4.0:
21387 : proc_bind ( proc-bind-kind )
21388 :
21389 : proc-bind-kind:
21390 : primary | master | close | spread
21391 : where OpenMP 5.1 added 'primary' and deprecated the alias 'master'. */
21392 :
21393 : static tree
21394 195 : c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
21395 : {
21396 195 : location_t clause_loc = c_parser_peek_token (parser)->location;
21397 195 : enum omp_clause_proc_bind_kind kind;
21398 195 : tree c;
21399 :
21400 195 : matching_parens parens;
21401 195 : if (!parens.require_open (parser))
21402 : return list;
21403 :
21404 195 : if (c_parser_next_token_is (parser, CPP_NAME))
21405 : {
21406 195 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
21407 195 : if (strcmp ("primary", p) == 0)
21408 : kind = OMP_CLAUSE_PROC_BIND_PRIMARY;
21409 194 : else if (strcmp ("master", p) == 0)
21410 : {
21411 17 : gcc_rich_location richloc (clause_loc);
21412 17 : richloc.add_fixit_replace (c_parser_peek_token (parser)->location,
21413 : "primary");
21414 17 : warning_at (&richloc, OPT_Wdeprecated_openmp,
21415 : "%<master%> affinity deprecated since OpenMP 5.1, "
21416 : "use %<primary%>");
21417 17 : kind = OMP_CLAUSE_PROC_BIND_MASTER;
21418 17 : }
21419 177 : else if (strcmp ("close", p) == 0)
21420 : kind = OMP_CLAUSE_PROC_BIND_CLOSE;
21421 165 : else if (strcmp ("spread", p) == 0)
21422 : kind = OMP_CLAUSE_PROC_BIND_SPREAD;
21423 : else
21424 0 : goto invalid_kind;
21425 : }
21426 : else
21427 0 : goto invalid_kind;
21428 :
21429 195 : check_no_duplicate_clause (list, OMP_CLAUSE_PROC_BIND, "proc_bind");
21430 195 : c_parser_consume_token (parser);
21431 195 : parens.skip_until_found_close (parser);
21432 195 : c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
21433 195 : OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
21434 195 : OMP_CLAUSE_CHAIN (c) = list;
21435 195 : return c;
21436 :
21437 0 : invalid_kind:
21438 0 : c_parser_error (parser, "invalid proc_bind kind");
21439 0 : parens.skip_until_found_close (parser);
21440 0 : return list;
21441 : }
21442 :
21443 : /* OpenMP 5.0:
21444 : device_type ( host | nohost | any ) */
21445 :
21446 : static tree
21447 53 : c_parser_omp_clause_device_type (c_parser *parser, tree list)
21448 : {
21449 53 : location_t clause_loc = c_parser_peek_token (parser)->location;
21450 53 : enum omp_clause_device_type_kind kind;
21451 53 : tree c;
21452 :
21453 53 : matching_parens parens;
21454 53 : if (!parens.require_open (parser))
21455 : return list;
21456 :
21457 53 : if (c_parser_next_token_is (parser, CPP_NAME))
21458 : {
21459 53 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
21460 53 : if (strcmp ("host", p) == 0)
21461 : kind = OMP_CLAUSE_DEVICE_TYPE_HOST;
21462 33 : else if (strcmp ("nohost", p) == 0)
21463 : kind = OMP_CLAUSE_DEVICE_TYPE_NOHOST;
21464 20 : else if (strcmp ("any", p) == 0)
21465 : kind = OMP_CLAUSE_DEVICE_TYPE_ANY;
21466 : else
21467 0 : goto invalid_kind;
21468 : }
21469 : else
21470 0 : goto invalid_kind;
21471 :
21472 53 : check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE_TYPE,
21473 : "device_type");
21474 53 : c_parser_consume_token (parser);
21475 53 : parens.skip_until_found_close (parser);
21476 53 : c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE_TYPE);
21477 53 : OMP_CLAUSE_DEVICE_TYPE_KIND (c) = kind;
21478 53 : OMP_CLAUSE_CHAIN (c) = list;
21479 53 : return c;
21480 :
21481 0 : invalid_kind:
21482 0 : c_parser_error (parser, "expected %<host%>, %<nohost%> or %<any%>");
21483 0 : parens.skip_until_found_close (parser);
21484 0 : return list;
21485 : }
21486 :
21487 : /* OpenMP 4.0:
21488 : from ( variable-list )
21489 : to ( variable-list )
21490 :
21491 : OpenMP 5.1:
21492 : from ( [motion-modifier[,] [motion-modifier[,]...]:] variable-list )
21493 : to ( [motion-modifier[,] [motion-modifier[,]...]:] variable-list )
21494 :
21495 : motion-modifier:
21496 : present | iterator (iterators-definition) | mapper (id) */
21497 :
21498 : static tree
21499 2864 : c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
21500 : tree list)
21501 : {
21502 2864 : location_t loc = c_parser_peek_token (parser)->location;
21503 2864 : matching_parens parens;
21504 2864 : if (!parens.require_open (parser))
21505 : return list;
21506 :
21507 5716 : int pos = 1, colon_pos = 0;
21508 : int iterator_length = 0;
21509 :
21510 5716 : while (c_parser_peek_nth_token_raw (parser, pos)->type == CPP_NAME)
21511 : {
21512 2878 : const char *identifier =
21513 2878 : IDENTIFIER_POINTER (c_parser_peek_nth_token_raw (parser, pos)->value);
21514 2878 : if (c_parser_peek_nth_token_raw (parser, pos + 1)->type
21515 : == CPP_OPEN_PAREN)
21516 : {
21517 20 : unsigned int npos = pos + 2;
21518 20 : if (c_parser_check_balanced_raw_token_sequence (parser, &npos)
21519 20 : && (c_parser_peek_nth_token_raw (parser, npos)->type
21520 : == CPP_CLOSE_PAREN))
21521 : {
21522 20 : if (strcmp (identifier, "iterator") == 0)
21523 15 : iterator_length = npos - pos + 1;
21524 20 : pos = npos;
21525 : }
21526 : }
21527 2878 : if (c_parser_peek_nth_token_raw (parser, pos + 1)->type == CPP_COMMA)
21528 14 : pos += 2;
21529 : else
21530 : pos++;
21531 2878 : if (c_parser_peek_nth_token_raw (parser, pos)->type == CPP_COLON)
21532 : {
21533 : colon_pos = pos;
21534 : break;
21535 : }
21536 : }
21537 :
21538 2864 : bool present = false, mapper_modifier = false;
21539 2864 : tree iterators = NULL_TREE;
21540 2864 : tree mapper_name = NULL_TREE;
21541 :
21542 2898 : for (int pos = 1; pos < colon_pos; ++pos)
21543 : {
21544 36 : c_token *token = c_parser_peek_token (parser);
21545 36 : if (token->type == CPP_COMMA)
21546 : {
21547 5 : c_parser_consume_token (parser);
21548 5 : continue;
21549 : }
21550 31 : const char *p = IDENTIFIER_POINTER (token->value);
21551 31 : if (strcmp ("present", p) == 0)
21552 : {
21553 10 : if (present)
21554 : {
21555 0 : c_parser_error (parser, "too many %<present%> modifiers");
21556 0 : parens.skip_until_found_close (parser);
21557 0 : return list;
21558 : }
21559 10 : present = true;
21560 10 : c_parser_consume_token (parser);
21561 : }
21562 21 : else if (strcmp ("iterator", p) == 0)
21563 : {
21564 15 : if (iterators)
21565 : {
21566 1 : c_parser_error (parser, "too many %<iterator%> modifiers");
21567 1 : parens.skip_until_found_close (parser);
21568 1 : return list;
21569 : }
21570 14 : iterators = c_parser_omp_iterators (parser);
21571 14 : pos += iterator_length - 1;
21572 : }
21573 6 : else if (strcmp ("mapper", p) == 0)
21574 : {
21575 5 : c_parser_consume_token (parser);
21576 :
21577 5 : matching_parens mparens;
21578 5 : if (mparens.require_open (parser))
21579 : {
21580 5 : if (mapper_modifier)
21581 : {
21582 0 : c_parser_error (parser, "too many %<mapper%> modifiers");
21583 : /* Assume it's a well-formed mapper modifier, even if it
21584 : seems to be in the wrong place. */
21585 0 : c_parser_consume_token (parser);
21586 0 : mparens.require_close (parser);
21587 0 : parens.skip_until_found_close (parser);
21588 0 : return list;
21589 : }
21590 :
21591 5 : token = c_parser_peek_token (parser);
21592 5 : switch (token->type)
21593 : {
21594 5 : case CPP_NAME:
21595 5 : {
21596 5 : mapper_name = token->value;
21597 5 : c_parser_consume_token (parser);
21598 : }
21599 5 : break;
21600 0 : case CPP_KEYWORD:
21601 0 : if (token->keyword == RID_DEFAULT)
21602 : {
21603 0 : c_parser_consume_token (parser);
21604 0 : break;
21605 : }
21606 : /* FALLTHROUGH */
21607 0 : default:
21608 0 : error_at (token->location,
21609 : "expected identifier or %<default%>");
21610 0 : return list;
21611 : }
21612 5 : if (!mparens.require_close (parser))
21613 : {
21614 0 : parens.skip_until_found_close (parser);
21615 0 : return list;
21616 : }
21617 5 : mapper_modifier = true;
21618 5 : pos += 3;
21619 : }
21620 : }
21621 : else
21622 : {
21623 2 : error_at (token->location,
21624 : "%qs clause with modifier other than %<iterator%>, "
21625 : "%<mapper%>, or %<present%>",
21626 : kind == OMP_CLAUSE_TO ? "to" : "from");
21627 1 : parens.skip_until_found_close (parser);
21628 1 : return list;
21629 : }
21630 : }
21631 :
21632 2862 : if (colon_pos)
21633 24 : c_parser_require (parser, CPP_COLON, "expected %<:%>");
21634 :
21635 2862 : tree nl = c_parser_omp_variable_list (parser, loc, kind, list);
21636 2862 : parens.skip_until_found_close (parser);
21637 :
21638 2862 : if (present)
21639 26 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
21640 16 : OMP_CLAUSE_MOTION_PRESENT (c) = 1;
21641 :
21642 2862 : if (iterators)
21643 : {
21644 12 : tree block = pop_scope ();
21645 12 : if (iterators == error_mark_node)
21646 : iterators = NULL_TREE;
21647 : else
21648 12 : OMP_ITERATOR_BLOCK (iterators) = block;
21649 : }
21650 :
21651 12 : if (iterators)
21652 28 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
21653 16 : OMP_CLAUSE_ITERATORS (c) = iterators;
21654 :
21655 2862 : if (mapper_name)
21656 : {
21657 : tree last_new = NULL_TREE;
21658 10 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
21659 5 : last_new = c;
21660 :
21661 5 : tree name = build_omp_clause (input_location, OMP_CLAUSE_MAP);
21662 5 : OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_PUSH_MAPPER_NAME);
21663 5 : OMP_CLAUSE_DECL (name) = mapper_name;
21664 5 : OMP_CLAUSE_CHAIN (name) = nl;
21665 5 : nl = name;
21666 :
21667 5 : gcc_assert (last_new);
21668 :
21669 5 : name = build_omp_clause (input_location, OMP_CLAUSE_MAP);
21670 5 : OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_POP_MAPPER_NAME);
21671 5 : OMP_CLAUSE_DECL (name) = null_pointer_node;
21672 5 : OMP_CLAUSE_CHAIN (name) = OMP_CLAUSE_CHAIN (last_new);
21673 5 : OMP_CLAUSE_CHAIN (last_new) = name;
21674 : }
21675 :
21676 : return nl;
21677 : }
21678 :
21679 : /* OpenMP 4.0:
21680 : uniform ( variable-list ) */
21681 :
21682 : static tree
21683 117 : c_parser_omp_clause_uniform (c_parser *parser, tree list)
21684 : {
21685 : /* The clauses location. */
21686 117 : location_t loc = c_parser_peek_token (parser)->location;
21687 :
21688 117 : matching_parens parens;
21689 117 : if (parens.require_open (parser))
21690 : {
21691 117 : list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
21692 : list);
21693 117 : parens.skip_until_found_close (parser);
21694 : }
21695 117 : return list;
21696 : }
21697 :
21698 : /* OpenMP 5.1
21699 : full */
21700 :
21701 : static tree
21702 69 : c_parser_omp_clause_full (c_parser *parser, tree list)
21703 : {
21704 69 : check_no_duplicate_clause (list, OMP_CLAUSE_FULL, "full");
21705 :
21706 69 : location_t loc = c_parser_peek_token (parser)->location;
21707 69 : tree c = build_omp_clause (loc, OMP_CLAUSE_FULL);
21708 69 : OMP_CLAUSE_CHAIN (c) = list;
21709 69 : return c;
21710 : }
21711 :
21712 : /* OpenMP 5.1
21713 : partial ( constant-expression ) */
21714 :
21715 : static tree
21716 230 : c_parser_omp_clause_partial (c_parser *parser, tree list)
21717 : {
21718 230 : tree num = NULL_TREE;
21719 230 : location_t loc = c_parser_peek_token (parser)->location;
21720 :
21721 230 : check_no_duplicate_clause (list, OMP_CLAUSE_PARTIAL, "partial");
21722 :
21723 230 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
21724 : {
21725 173 : matching_parens parens;
21726 173 : parens.consume_open (parser);
21727 173 : num = c_parser_expr_no_commas (parser, NULL).value;
21728 173 : parens.skip_until_found_close (parser);
21729 :
21730 173 : if (num == error_mark_node)
21731 7 : return list;
21732 :
21733 171 : mark_exp_read (num);
21734 171 : num = c_fully_fold (num, false, NULL);
21735 171 : HOST_WIDE_INT n;
21736 342 : if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
21737 170 : || !tree_fits_shwi_p (num)
21738 168 : || (n = tree_to_shwi (num)) <= 0
21739 337 : || (int) n != n)
21740 : {
21741 5 : error_at (loc, "%<partial%> argument needs positive constant "
21742 : "integer expression");
21743 5 : return list;
21744 : }
21745 : }
21746 :
21747 223 : tree c = build_omp_clause (loc, OMP_CLAUSE_PARTIAL);
21748 223 : OMP_CLAUSE_PARTIAL_EXPR (c) = num;
21749 223 : OMP_CLAUSE_CHAIN (c) = list;
21750 223 : return c;
21751 : }
21752 :
21753 : /* OpenMP 5.1
21754 : novariants ( scalar-expression ) */
21755 :
21756 : static tree
21757 24 : c_parser_omp_clause_novariants (c_parser *parser, tree list)
21758 : {
21759 24 : matching_parens parens;
21760 24 : if (!parens.require_open (parser))
21761 : return list;
21762 :
21763 24 : location_t loc = c_parser_peek_token (parser)->location;
21764 24 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
21765 24 : tree t = convert_lvalue_to_rvalue (loc, expr, true, true).value;
21766 24 : t = c_objc_common_truthvalue_conversion (loc, t);
21767 24 : t = c_fully_fold (t, false, NULL);
21768 24 : parens.skip_until_found_close (parser);
21769 :
21770 24 : check_no_duplicate_clause (list, OMP_CLAUSE_NOVARIANTS, "novariants");
21771 :
21772 24 : tree c = build_omp_clause (loc, OMP_CLAUSE_NOVARIANTS);
21773 24 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
21774 24 : OMP_CLAUSE_CHAIN (c) = list;
21775 24 : list = c;
21776 :
21777 24 : return list;
21778 : }
21779 :
21780 : /* OpenMP 5.1
21781 : nocontext ( scalar-expression ) */
21782 :
21783 : static tree
21784 23 : c_parser_omp_clause_nocontext (c_parser *parser, tree list)
21785 : {
21786 23 : matching_parens parens;
21787 23 : if (!parens.require_open (parser))
21788 : return list;
21789 :
21790 23 : location_t loc = c_parser_peek_token (parser)->location;
21791 23 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
21792 23 : tree t = convert_lvalue_to_rvalue (loc, expr, true, true).value;
21793 23 : t = c_objc_common_truthvalue_conversion (loc, t);
21794 23 : t = c_fully_fold (t, false, NULL);
21795 23 : parens.skip_until_found_close (parser);
21796 :
21797 23 : check_no_duplicate_clause (list, OMP_CLAUSE_NOCONTEXT, "nocontext");
21798 :
21799 23 : tree c = build_omp_clause (loc, OMP_CLAUSE_NOCONTEXT);
21800 23 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
21801 23 : OMP_CLAUSE_CHAIN (c) = list;
21802 23 : list = c;
21803 :
21804 23 : return list;
21805 : }
21806 :
21807 : /* OpenMP 5.0:
21808 : detach ( event-handle ) */
21809 :
21810 : static tree
21811 34 : c_parser_omp_clause_detach (c_parser *parser, tree list)
21812 : {
21813 34 : matching_parens parens;
21814 34 : location_t clause_loc = c_parser_peek_token (parser)->location;
21815 :
21816 34 : if (!parens.require_open (parser))
21817 : return list;
21818 :
21819 34 : if (c_parser_next_token_is_not (parser, CPP_NAME)
21820 34 : || c_parser_peek_token (parser)->id_kind != C_ID_ID)
21821 : {
21822 1 : c_parser_error (parser, "expected identifier");
21823 1 : parens.skip_until_found_close (parser);
21824 1 : return list;
21825 : }
21826 :
21827 33 : tree t = lookup_name (c_parser_peek_token (parser)->value);
21828 33 : if (t == NULL_TREE)
21829 : {
21830 0 : undeclared_variable (c_parser_peek_token (parser)->location,
21831 0 : c_parser_peek_token (parser)->value);
21832 0 : parens.skip_until_found_close (parser);
21833 0 : return list;
21834 : }
21835 33 : c_parser_consume_token (parser);
21836 :
21837 33 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
21838 33 : if (!INTEGRAL_TYPE_P (type)
21839 : || TREE_CODE (type) != ENUMERAL_TYPE
21840 33 : || TYPE_NAME (type) != get_identifier ("omp_event_handle_t"))
21841 : {
21842 1 : error_at (clause_loc, "%<detach%> clause event handle "
21843 : "has type %qT rather than "
21844 : "%<omp_event_handle_t%>",
21845 : type);
21846 1 : parens.skip_until_found_close (parser);
21847 1 : return list;
21848 : }
21849 :
21850 32 : tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DETACH);
21851 32 : OMP_CLAUSE_DECL (u) = t;
21852 32 : OMP_CLAUSE_CHAIN (u) = list;
21853 32 : parens.skip_until_found_close (parser);
21854 32 : return u;
21855 : }
21856 :
21857 : /* OpenMP 5.0:
21858 : destroy ( variable-list ) */
21859 :
21860 : static tree
21861 41 : c_parser_omp_clause_destroy (c_parser *parser, tree list)
21862 : {
21863 41 : tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_DESTROY, list);
21864 127 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
21865 45 : TREE_ADDRESSABLE (OMP_CLAUSE_DECL (c)) = 1;
21866 41 : return nl;
21867 : }
21868 :
21869 : /* OpenMP 5.1:
21870 : prefer_type ( const-int-expr-or-string-literal-list )
21871 :
21872 : OpenMP 6.0:
21873 : prefer_type ( { preference-selector-list }, { ... } )
21874 :
21875 : with preference-selector being:
21876 : fr ( identifier-or-string-literal-list )
21877 : attr ( string-list )
21878 :
21879 : Data format:
21880 : For the foreign runtime identifiers, string values are converted to
21881 : their integer value; unknown string or integer values are set to
21882 : GOMP_INTEROP_IFR_KNOWN.
21883 :
21884 : Each item (a) GOMP_INTEROP_IFR_SEPARATOR
21885 : (b) for any 'fr', its integer value.
21886 : Note: Spec only permits 1 'fr' entry (6.0; changed after TR13)
21887 : (c) GOMP_INTEROP_IFR_SEPARATOR
21888 : (d) list of \0-terminated non-empty strings for 'attr'
21889 : (e) '\0'
21890 : Tailing '\0'. */
21891 :
21892 : static tree
21893 125 : c_parser_omp_modifier_prefer_type (c_parser *parser)
21894 : {
21895 125 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
21896 2 : return error_mark_node;
21897 :
21898 123 : std::string str;
21899 :
21900 : /* Old Format: const-int-expr-or-string-literal-list */
21901 123 : if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
21902 240 : while (true)
21903 : {
21904 150 : str += (char) GOMP_INTEROP_IFR_SEPARATOR;
21905 150 : if (c_parser_next_token_is (parser, CPP_STRING))
21906 : {
21907 117 : c_expr cval = c_parser_string_literal (parser, false, false);
21908 117 : if (cval.value == error_mark_node)
21909 1 : return error_mark_node;
21910 117 : if ((size_t) TREE_STRING_LENGTH (cval.value)
21911 117 : != strlen (TREE_STRING_POINTER (cval.value)) + 1)
21912 : {
21913 1 : error_at (cval.get_location (), "string literal must "
21914 : "not contain %<\\0%>");
21915 1 : parser->error = true;
21916 1 : return error_mark_node;
21917 : }
21918 :
21919 116 : char c = omp_get_fr_id_from_name (TREE_STRING_POINTER (cval.value));
21920 116 : if (c == GOMP_INTEROP_IFR_UNKNOWN)
21921 3 : warning_at (cval.get_location (), OPT_Wopenmp,
21922 : "unknown foreign runtime identifier %qs",
21923 3 : TREE_STRING_POINTER (cval.value));
21924 116 : str += c;
21925 : }
21926 : else
21927 : {
21928 33 : c_expr cval = c_parser_expr_no_commas (parser, NULL);
21929 33 : tree value = c_fully_fold (cval.value, false, NULL);
21930 64 : if (INTEGRAL_TYPE_P (TREE_TYPE (value))
21931 61 : && TREE_CODE (value) != INTEGER_CST)
21932 3 : value = convert_lvalue_to_rvalue (cval.get_start (), cval,
21933 : false, true).value;
21934 33 : if (TREE_CODE (value) != INTEGER_CST
21935 28 : || !tree_fits_shwi_p (value))
21936 : {
21937 5 : c_parser_error (parser, "expected string literal or constant "
21938 : "integer expression");
21939 5 : return error_mark_node;
21940 : }
21941 28 : HOST_WIDE_INT n = tree_to_shwi (value);
21942 28 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
21943 : {
21944 3 : warning_at (cval.get_location (), OPT_Wopenmp,
21945 : "unknown foreign runtime identifier %qwd", n);
21946 3 : n = GOMP_INTEROP_IFR_UNKNOWN;
21947 : }
21948 28 : str += (char) n;
21949 : }
21950 144 : str += (char) GOMP_INTEROP_IFR_SEPARATOR;
21951 144 : str += '\0';
21952 144 : if (c_parser_next_token_is (parser, CPP_COMMA))
21953 : {
21954 90 : c_parser_consume_token (parser);
21955 90 : continue;
21956 : }
21957 54 : if (!c_parser_require (parser, CPP_CLOSE_PAREN,
21958 : "expected %<,%> or %<)%>"))
21959 0 : return error_mark_node;
21960 54 : str += '\0';
21961 54 : tree res = build_string (str.length (), str.data ());
21962 54 : TREE_TYPE (res) = build_array_type_nelts (unsigned_char_type_node,
21963 54 : str.length ());
21964 54 : return res;
21965 90 : }
21966 :
21967 : /* New format. */
21968 63 : std::string str2;
21969 128 : while (true)
21970 : {
21971 128 : if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
21972 1 : return error_mark_node;
21973 127 : str += (char) GOMP_INTEROP_IFR_SEPARATOR;
21974 127 : str2.clear ();
21975 127 : bool has_fr = false;
21976 205 : while (true)
21977 : {
21978 166 : c_token *tok = c_parser_peek_token (parser);
21979 166 : if (tok->type != CPP_NAME
21980 166 : || (strcmp("fr", IDENTIFIER_POINTER (tok->value)) != 0
21981 63 : && strcmp("attr", IDENTIFIER_POINTER (tok->value)) != 0))
21982 : {
21983 0 : c_parser_error (parser, "expected %<fr%> or %<attr%> preference "
21984 : "selector");
21985 0 : return error_mark_node;
21986 : }
21987 166 : c_parser_consume_token (parser);
21988 166 : bool is_fr = IDENTIFIER_POINTER (tok->value)[0] == 'f';
21989 166 : if (is_fr && has_fr)
21990 : {
21991 1 : c_parser_error (parser, "duplicated %<fr%> preference selector");
21992 1 : return error_mark_node;
21993 : }
21994 165 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
21995 0 : return error_mark_node;
21996 175 : while (true)
21997 : {
21998 170 : if (c_parser_next_token_is (parser, CPP_STRING))
21999 : {
22000 133 : c_expr cval = c_parser_string_literal (parser, false, false);
22001 133 : tree value = cval.value;
22002 133 : if (value == error_mark_node)
22003 6 : return error_mark_node;
22004 133 : if ((size_t) TREE_STRING_LENGTH (value)
22005 133 : != strlen (TREE_STRING_POINTER (value)) + 1)
22006 : {
22007 2 : error_at (cval.get_location (), "string literal must "
22008 : "not contain %<\\0%>");
22009 2 : parser->error = true;
22010 2 : return error_mark_node;
22011 : }
22012 131 : if (!is_fr)
22013 : {
22014 67 : if (!startswith (TREE_STRING_POINTER (value), "ompx_"))
22015 : {
22016 1 : error_at (cval.get_location (),
22017 : "%<attr%> string literal must start with "
22018 : "%<ompx_%>");
22019 1 : parser->error = true;
22020 1 : return error_mark_node;
22021 : }
22022 66 : if (strchr (TREE_STRING_POINTER (value), ','))
22023 : {
22024 2 : error_at (cval.get_location (),
22025 : "%<attr%> string literal must not contain "
22026 : "a comma");
22027 2 : parser->error = true;
22028 2 : return error_mark_node;
22029 : }
22030 64 : str2 += TREE_STRING_POINTER (value);
22031 64 : str2 += '\0';
22032 : }
22033 : else
22034 : {
22035 64 : if (*TREE_STRING_POINTER (value) == '\0')
22036 : {
22037 1 : c_parser_error (parser, "non-empty string literal expected");
22038 1 : return error_mark_node;
22039 : }
22040 63 : char c = omp_get_fr_id_from_name (TREE_STRING_POINTER (value));
22041 63 : if (c == GOMP_INTEROP_IFR_UNKNOWN)
22042 3 : warning_at (cval.get_location (), OPT_Wopenmp,
22043 : "unknown foreign runtime identifier %qs",
22044 3 : TREE_STRING_POINTER (value));
22045 63 : str += c;
22046 63 : has_fr = true;
22047 : }
22048 : }
22049 37 : else if (!is_fr)
22050 : {
22051 1 : c_parser_error (parser, "expected string literal");
22052 1 : return error_mark_node;
22053 : }
22054 : else
22055 : {
22056 36 : c_expr cval = c_parser_expr_no_commas (parser, NULL);
22057 36 : tree value = c_fully_fold (cval.value, false, NULL);
22058 70 : if (INTEGRAL_TYPE_P (TREE_TYPE (value))
22059 68 : && TREE_CODE (value) != INTEGER_CST)
22060 3 : value = convert_lvalue_to_rvalue (cval.get_start (), cval,
22061 : false, true).value;
22062 :
22063 36 : if (TREE_CODE (value) != INTEGER_CST
22064 32 : || !tree_fits_shwi_p (value))
22065 : {
22066 4 : c_parser_error (parser, "expected string literal or "
22067 : "constant integer expression");
22068 4 : return error_mark_node;
22069 : }
22070 32 : HOST_WIDE_INT n = tree_to_shwi (value);
22071 32 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
22072 : {
22073 0 : warning_at (cval.get_location (), OPT_Wopenmp,
22074 : "unknown foreign runtime identifier %qwd", n);
22075 0 : n = GOMP_INTEROP_IFR_UNKNOWN;
22076 : }
22077 32 : str += (char) n;
22078 32 : has_fr = true;
22079 : }
22080 164 : if (!is_fr
22081 223 : && c_parser_next_token_is (parser, CPP_COMMA))
22082 : {
22083 5 : c_parser_consume_token (parser);
22084 5 : continue;
22085 : }
22086 213 : if (!c_parser_require (parser, CPP_CLOSE_PAREN,
22087 : is_fr ? G_("expected %<)%>")
22088 : : G_("expected %<)%> or %<,%>")))
22089 4 : return error_mark_node;
22090 150 : break;
22091 5 : }
22092 150 : if (c_parser_next_token_is (parser, CPP_COMMA))
22093 : {
22094 39 : c_parser_consume_token (parser);
22095 39 : continue;
22096 : }
22097 111 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
22098 : break;
22099 2 : c_parser_error (parser, "expected %<,%> or %<}%>");
22100 2 : return error_mark_node;
22101 39 : }
22102 109 : str += (char) GOMP_INTEROP_IFR_SEPARATOR;
22103 109 : str += str2;
22104 109 : str += '\0';
22105 109 : c_parser_consume_token (parser);
22106 109 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
22107 : break;
22108 66 : if (!c_parser_require (parser, CPP_COMMA, "expected %<)%> or %<,%>"))
22109 1 : return error_mark_node;
22110 : }
22111 43 : c_parser_consume_token (parser);
22112 43 : str += '\0';
22113 43 : tree res = build_string (str.length (), str.data ());
22114 43 : TREE_TYPE (res) = build_array_type_nelts (unsigned_char_type_node,
22115 43 : str.length ());
22116 43 : return res;
22117 186 : }
22118 :
22119 : /* OpenMP 5.1
22120 : modifiers of the 'init' clause, used by the 'init' and the
22121 : 'append_args' clauses.
22122 :
22123 : Modifiers:
22124 : target
22125 : targetsync
22126 : prefer_type (preference-specification)
22127 :
22128 : Returns 'false' if an error has been issued. */
22129 :
22130 : static bool
22131 234 : c_parser_omp_clause_init_modifiers (c_parser *parser, bool *target,
22132 : bool *targetsync, tree *prefer_type_tree)
22133 : {
22134 234 : *target = false;
22135 234 : *targetsync = false;
22136 234 : *prefer_type_tree = NULL_TREE;
22137 :
22138 540 : do
22139 : {
22140 387 : c_token *tok = c_parser_peek_token (parser);
22141 387 : if (tok->type != CPP_NAME)
22142 1 : goto fail;
22143 386 : const char *p = IDENTIFIER_POINTER (tok->value);
22144 386 : if (strcmp ("targetsync", p) == 0)
22145 : {
22146 105 : if (*targetsync)
22147 1 : error_at (tok->location, "duplicate %<targetsync%> modifier");
22148 105 : *targetsync = true;
22149 105 : c_parser_consume_token (parser);
22150 : }
22151 281 : else if (strcmp ("target", p) == 0)
22152 : {
22153 148 : if (*target)
22154 3 : error_at (tok->location, "duplicate %<target%> modifier");
22155 148 : *target = true;
22156 148 : c_parser_consume_token (parser);
22157 : }
22158 133 : else if (strcmp ("prefer_type", p) == 0)
22159 : {
22160 125 : if (*prefer_type_tree != NULL_TREE)
22161 1 : error_at (tok->location, "duplicate %<prefer_type%> modifier");
22162 125 : c_parser_consume_token (parser);
22163 125 : *prefer_type_tree = c_parser_omp_modifier_prefer_type (parser);
22164 125 : if (*prefer_type_tree == error_mark_node)
22165 : return false;
22166 : }
22167 : else
22168 8 : goto fail;
22169 350 : tok = c_parser_peek_token (parser);
22170 350 : if (tok->type == CPP_COMMA)
22171 : {
22172 153 : c_parser_consume_token (parser);
22173 153 : continue;
22174 : }
22175 : /* Unknown token - either done or an error; handle it in the caller. */
22176 : return true;
22177 153 : }
22178 : while (true);
22179 :
22180 9 : fail:
22181 9 : c_parser_error (parser,
22182 : "expected %<prefer_type%>, %<target%>, or %<targetsync%>");
22183 9 : return false;
22184 : }
22185 :
22186 : /* OpenMP 5.1:
22187 : init ( [init-modifier-list : ] variable-list )
22188 :
22189 : Modifiers:
22190 : target
22191 : targetsync
22192 : prefer_type (preference-specification) */
22193 :
22194 : static tree
22195 167 : c_parser_omp_clause_init (c_parser *parser, tree list)
22196 : {
22197 167 : location_t loc = c_parser_peek_token (parser)->location;
22198 :
22199 167 : matching_parens parens;
22200 167 : if (!parens.require_open (parser))
22201 : return list;
22202 :
22203 167 : bool target = false;
22204 167 : bool targetsync = false;
22205 167 : tree prefer_type_tree = NULL_TREE;
22206 :
22207 167 : if (!c_parser_omp_clause_init_modifiers (parser, &target, &targetsync,
22208 : &prefer_type_tree)
22209 167 : || !c_parser_require (parser, CPP_COLON, "expected %<:%>"))
22210 : {
22211 39 : if (prefer_type_tree != error_mark_node)
22212 11 : parens.skip_until_found_close (parser);
22213 : return list;
22214 : }
22215 :
22216 128 : if (!target && !targetsync)
22217 2 : error_at (loc,
22218 : "missing required %<target%> and/or %<targetsync%> modifier");
22219 :
22220 128 : tree nl = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_INIT, list,
22221 : false);
22222 128 : parens.skip_until_found_close (parser);
22223 :
22224 408 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
22225 : {
22226 152 : TREE_ADDRESSABLE (OMP_CLAUSE_DECL (c)) = 1;
22227 152 : if (target)
22228 90 : OMP_CLAUSE_INIT_TARGET (c) = 1;
22229 152 : if (targetsync)
22230 81 : OMP_CLAUSE_INIT_TARGETSYNC (c) = 1;
22231 152 : if (prefer_type_tree)
22232 73 : OMP_CLAUSE_INIT_PREFER_TYPE (c) = prefer_type_tree;
22233 : }
22234 : return nl;
22235 : }
22236 :
22237 : /* OpenMP 5.0:
22238 : use ( variable-list ) */
22239 :
22240 : static tree
22241 43 : c_parser_omp_clause_use (c_parser *parser, tree list)
22242 : {
22243 43 : return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE, list);
22244 : }
22245 :
22246 : /* OpenMP 6.0:
22247 : interop ( variable-list ) */
22248 :
22249 : static tree
22250 43 : c_parser_omp_clause_interop (c_parser *parser, tree list)
22251 : {
22252 43 : check_no_duplicate_clause (list, OMP_CLAUSE_INTEROP, "interop");
22253 43 : tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_INTEROP, list);
22254 145 : for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
22255 : {
22256 59 : TREE_USED (OMP_CLAUSE_DECL (c)) = 1;
22257 59 : DECL_READ_P (OMP_CLAUSE_DECL (c)) = 1;
22258 : }
22259 43 : return nl;
22260 : }
22261 :
22262 : /* Parse all OpenACC clauses. The set clauses allowed by the directive
22263 : is a bitmask in MASK. Return the list of clauses found. */
22264 :
22265 : static tree
22266 5352 : c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
22267 : const char *where, bool finish_p = true,
22268 : bool target_p = false)
22269 : {
22270 5352 : tree clauses = NULL;
22271 5352 : bool first = true;
22272 :
22273 12079 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
22274 : {
22275 6773 : location_t here;
22276 6773 : pragma_omp_clause c_kind;
22277 6773 : const char *c_name;
22278 6773 : tree prev = clauses;
22279 :
22280 9391 : if (!first && c_parser_next_token_is (parser, CPP_COMMA))
22281 11 : c_parser_consume_token (parser);
22282 :
22283 6773 : here = c_parser_peek_token (parser)->location;
22284 6773 : c_kind = c_parser_omp_clause_name (parser);
22285 :
22286 6773 : switch (c_kind)
22287 : {
22288 240 : case PRAGMA_OACC_CLAUSE_ASYNC:
22289 240 : clauses = c_parser_oacc_clause_async (parser, clauses);
22290 240 : c_name = "async";
22291 240 : break;
22292 125 : case PRAGMA_OACC_CLAUSE_AUTO:
22293 125 : clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_AUTO,
22294 : clauses);
22295 125 : c_name = "auto";
22296 125 : break;
22297 27 : case PRAGMA_OACC_CLAUSE_ATTACH:
22298 27 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22299 27 : c_name = "attach";
22300 27 : break;
22301 59 : case PRAGMA_OACC_CLAUSE_COLLAPSE:
22302 59 : clauses = c_parser_omp_clause_collapse (parser, clauses);
22303 59 : c_name = "collapse";
22304 59 : break;
22305 806 : case PRAGMA_OACC_CLAUSE_COPY:
22306 806 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22307 806 : c_name = "copy";
22308 806 : break;
22309 359 : case PRAGMA_OACC_CLAUSE_COPYIN:
22310 359 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22311 359 : c_name = "copyin";
22312 359 : break;
22313 390 : case PRAGMA_OACC_CLAUSE_COPYOUT:
22314 390 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22315 390 : c_name = "copyout";
22316 390 : break;
22317 94 : case PRAGMA_OACC_CLAUSE_CREATE:
22318 94 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22319 94 : c_name = "create";
22320 94 : break;
22321 68 : case PRAGMA_OACC_CLAUSE_DELETE:
22322 68 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22323 68 : c_name = "delete";
22324 68 : break;
22325 88 : case PRAGMA_OMP_CLAUSE_DEFAULT:
22326 88 : clauses = c_parser_omp_clause_default (parser, clauses, true);
22327 88 : c_name = "default";
22328 88 : break;
22329 20 : case PRAGMA_OACC_CLAUSE_DETACH:
22330 20 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22331 20 : c_name = "detach";
22332 20 : break;
22333 36 : case PRAGMA_OACC_CLAUSE_DEVICE:
22334 36 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22335 36 : c_name = "device";
22336 36 : break;
22337 57 : case PRAGMA_OACC_CLAUSE_DEVICEPTR:
22338 57 : clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
22339 57 : c_name = "deviceptr";
22340 57 : break;
22341 16 : case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
22342 16 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22343 16 : c_name = "device_resident";
22344 16 : break;
22345 12 : case PRAGMA_OACC_CLAUSE_FINALIZE:
22346 12 : clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_FINALIZE,
22347 : clauses);
22348 12 : c_name = "finalize";
22349 12 : break;
22350 113 : case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
22351 113 : clauses = c_parser_omp_clause_firstprivate (parser, clauses);
22352 113 : c_name = "firstprivate";
22353 113 : break;
22354 589 : case PRAGMA_OACC_CLAUSE_GANG:
22355 589 : c_name = "gang";
22356 589 : clauses = c_parser_oacc_shape_clause (parser, here, OMP_CLAUSE_GANG,
22357 : c_name, clauses);
22358 589 : break;
22359 41 : case PRAGMA_OACC_CLAUSE_HOST:
22360 41 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22361 41 : c_name = "host";
22362 41 : break;
22363 105 : case PRAGMA_OACC_CLAUSE_IF:
22364 105 : clauses = c_parser_omp_clause_if (parser, clauses, false);
22365 105 : c_name = "if";
22366 105 : break;
22367 19 : case PRAGMA_OACC_CLAUSE_IF_PRESENT:
22368 19 : clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_IF_PRESENT,
22369 : clauses);
22370 19 : c_name = "if_present";
22371 19 : break;
22372 45 : case PRAGMA_OACC_CLAUSE_INDEPENDENT:
22373 45 : clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_INDEPENDENT,
22374 : clauses);
22375 45 : c_name = "independent";
22376 45 : break;
22377 13 : case PRAGMA_OACC_CLAUSE_LINK:
22378 13 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22379 13 : c_name = "link";
22380 13 : break;
22381 10 : case PRAGMA_OACC_CLAUSE_NO_CREATE:
22382 10 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22383 10 : c_name = "no_create";
22384 10 : break;
22385 25 : case PRAGMA_OACC_CLAUSE_NOHOST:
22386 25 : clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_NOHOST,
22387 : clauses);
22388 25 : c_name = "nohost";
22389 25 : break;
22390 302 : case PRAGMA_OACC_CLAUSE_NUM_GANGS:
22391 302 : clauses = c_parser_oacc_single_int_clause (parser,
22392 : OMP_CLAUSE_NUM_GANGS,
22393 : clauses);
22394 302 : c_name = "num_gangs";
22395 302 : break;
22396 207 : case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
22397 207 : clauses = c_parser_oacc_single_int_clause (parser,
22398 : OMP_CLAUSE_NUM_WORKERS,
22399 : clauses);
22400 207 : c_name = "num_workers";
22401 207 : break;
22402 128 : case PRAGMA_OACC_CLAUSE_PRESENT:
22403 128 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22404 128 : c_name = "present";
22405 128 : break;
22406 66 : case PRAGMA_OACC_CLAUSE_PRIVATE:
22407 66 : clauses = c_parser_omp_clause_private (parser, clauses);
22408 66 : c_name = "private";
22409 66 : break;
22410 905 : case PRAGMA_OACC_CLAUSE_REDUCTION:
22411 905 : clauses
22412 905 : = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION,
22413 : false, clauses);
22414 905 : c_name = "reduction";
22415 905 : break;
22416 66 : case PRAGMA_OACC_CLAUSE_SELF:
22417 66 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)) == 0)
22418 : /* OpenACC compute construct */
22419 48 : clauses = c_parser_oacc_compute_clause_self (parser, clauses);
22420 : else
22421 : /* OpenACC 'update' directive */
22422 18 : clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
22423 : c_name = "self";
22424 : break;
22425 261 : case PRAGMA_OACC_CLAUSE_SEQ:
22426 261 : clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_SEQ,
22427 : clauses);
22428 261 : c_name = "seq";
22429 261 : break;
22430 123 : case PRAGMA_OACC_CLAUSE_TILE:
22431 123 : clauses = c_parser_oacc_clause_tile (parser, clauses);
22432 123 : c_name = "tile";
22433 123 : break;
22434 21 : case PRAGMA_OACC_CLAUSE_USE_DEVICE:
22435 21 : clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
22436 21 : c_name = "use_device";
22437 21 : break;
22438 518 : case PRAGMA_OACC_CLAUSE_VECTOR:
22439 518 : c_name = "vector";
22440 518 : clauses = c_parser_oacc_shape_clause (parser, here, OMP_CLAUSE_VECTOR,
22441 : c_name, clauses);
22442 518 : break;
22443 223 : case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
22444 223 : clauses = c_parser_oacc_single_int_clause (parser,
22445 : OMP_CLAUSE_VECTOR_LENGTH,
22446 : clauses);
22447 223 : c_name = "vector_length";
22448 223 : break;
22449 97 : case PRAGMA_OACC_CLAUSE_WAIT:
22450 97 : clauses = c_parser_oacc_clause_wait (parser, clauses);
22451 97 : c_name = "wait";
22452 97 : break;
22453 453 : case PRAGMA_OACC_CLAUSE_WORKER:
22454 453 : c_name = "worker";
22455 453 : clauses = c_parser_oacc_shape_clause (parser, here, OMP_CLAUSE_WORKER,
22456 : c_name, clauses);
22457 453 : break;
22458 46 : default:
22459 46 : c_parser_error (parser, "expected an OpenACC clause");
22460 46 : goto saw_error;
22461 : }
22462 :
22463 6727 : first = false;
22464 :
22465 6727 : if (((mask >> c_kind) & 1) == 0)
22466 : {
22467 : /* Remove the invalid clause(s) from the list to avoid
22468 : confusing the rest of the compiler. */
22469 18 : clauses = prev;
22470 18 : error_at (here, "%qs is not valid for %qs", c_name, where);
22471 : }
22472 : }
22473 :
22474 5306 : saw_error:
22475 5352 : c_parser_skip_to_pragma_eol (parser);
22476 :
22477 5352 : if (finish_p)
22478 7831 : return c_finish_omp_clauses (clauses, target_p ? C_ORT_ACC_TARGET
22479 4656 : : C_ORT_ACC);
22480 :
22481 : return clauses;
22482 : }
22483 :
22484 : /* Parse all OpenMP clauses. The set clauses allowed by the directive
22485 : is a bitmask in MASK. Return the list of clauses found.
22486 : FINISH_P set if c_finish_omp_clauses should be called.
22487 : NESTED non-zero if clauses should be terminated by closing paren instead
22488 : of end of pragma. If it is 2, additionally commas are required in between
22489 : the clauses. */
22490 :
22491 : static tree
22492 20574 : c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
22493 : const char *where, bool finish_p = true,
22494 : int nested = 0)
22495 : {
22496 20574 : tree clauses = NULL;
22497 20574 : bool first = true;
22498 :
22499 48507 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
22500 : {
22501 28028 : location_t here;
22502 28028 : pragma_omp_clause c_kind;
22503 28028 : const char *c_name;
22504 28028 : tree prev = clauses;
22505 :
22506 28131 : if (nested && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
22507 : break;
22508 :
22509 28003 : if (!first || nested != 2)
22510 : {
22511 27977 : if (c_parser_next_token_is (parser, CPP_COMMA))
22512 2702 : c_parser_consume_token (parser);
22513 25275 : else if (nested == 2)
22514 3 : error_at (c_parser_peek_token (parser)->location,
22515 : "clauses in %<simd%> trait should be separated "
22516 : "by %<,%>");
22517 : }
22518 :
22519 28003 : here = c_parser_peek_token (parser)->location;
22520 28003 : c_kind = c_parser_omp_clause_name (parser);
22521 :
22522 28003 : switch (c_kind)
22523 : {
22524 116 : case PRAGMA_OMP_CLAUSE_BIND:
22525 116 : clauses = c_parser_omp_clause_bind (parser, clauses);
22526 116 : c_name = "bind";
22527 116 : break;
22528 2895 : case PRAGMA_OMP_CLAUSE_COLLAPSE:
22529 2895 : clauses = c_parser_omp_clause_collapse (parser, clauses);
22530 2895 : c_name = "collapse";
22531 2895 : break;
22532 102 : case PRAGMA_OMP_CLAUSE_COPYIN:
22533 102 : clauses = c_parser_omp_clause_copyin (parser, clauses);
22534 102 : c_name = "copyin";
22535 102 : break;
22536 24 : case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
22537 24 : clauses = c_parser_omp_clause_copyprivate (parser, clauses);
22538 24 : c_name = "copyprivate";
22539 24 : break;
22540 641 : case PRAGMA_OMP_CLAUSE_DEFAULT:
22541 641 : clauses = c_parser_omp_clause_default (parser, clauses, false);
22542 641 : c_name = "default";
22543 641 : break;
22544 34 : case PRAGMA_OMP_CLAUSE_DETACH:
22545 34 : clauses = c_parser_omp_clause_detach (parser, clauses);
22546 34 : c_name = "detach";
22547 34 : break;
22548 63 : case PRAGMA_OMP_CLAUSE_FILTER:
22549 63 : clauses = c_parser_omp_clause_filter (parser, clauses);
22550 63 : c_name = "filter";
22551 63 : break;
22552 691 : case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
22553 691 : clauses = c_parser_omp_clause_firstprivate (parser, clauses);
22554 691 : c_name = "firstprivate";
22555 691 : break;
22556 99 : case PRAGMA_OMP_CLAUSE_FINAL:
22557 99 : clauses = c_parser_omp_clause_final (parser, clauses);
22558 99 : c_name = "final";
22559 99 : break;
22560 62 : case PRAGMA_OMP_CLAUSE_GRAINSIZE:
22561 62 : clauses = c_parser_omp_clause_grainsize (parser, clauses);
22562 62 : c_name = "grainsize";
22563 62 : break;
22564 29 : case PRAGMA_OMP_CLAUSE_HINT:
22565 29 : clauses = c_parser_omp_clause_hint (parser, clauses);
22566 29 : c_name = "hint";
22567 29 : break;
22568 241 : case PRAGMA_OMP_CLAUSE_DEFAULTMAP:
22569 241 : clauses = c_parser_omp_clause_defaultmap (parser, clauses);
22570 241 : c_name = "defaultmap";
22571 241 : break;
22572 788 : case PRAGMA_OMP_CLAUSE_IF:
22573 788 : clauses = c_parser_omp_clause_if (parser, clauses, true);
22574 788 : c_name = "if";
22575 788 : break;
22576 322 : case PRAGMA_OMP_CLAUSE_IN_REDUCTION:
22577 322 : clauses
22578 322 : = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_IN_REDUCTION,
22579 : true, clauses);
22580 322 : c_name = "in_reduction";
22581 322 : break;
22582 26 : case PRAGMA_OMP_CLAUSE_INDIRECT:
22583 26 : clauses = c_parser_omp_clause_indirect (parser, clauses);
22584 26 : c_name = "indirect";
22585 26 : break;
22586 733 : case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
22587 733 : clauses = c_parser_omp_clause_lastprivate (parser, clauses);
22588 733 : c_name = "lastprivate";
22589 733 : break;
22590 79 : case PRAGMA_OMP_CLAUSE_MERGEABLE:
22591 79 : clauses = c_parser_omp_clause_mergeable (parser, clauses);
22592 79 : c_name = "mergeable";
22593 79 : break;
22594 395 : case PRAGMA_OMP_CLAUSE_NOWAIT:
22595 395 : clauses = c_parser_omp_clause_nowait (parser, clauses);
22596 395 : c_name = "nowait";
22597 395 : break;
22598 50 : case PRAGMA_OMP_CLAUSE_NUM_TASKS:
22599 50 : clauses = c_parser_omp_clause_num_tasks (parser, clauses);
22600 50 : c_name = "num_tasks";
22601 50 : break;
22602 453 : case PRAGMA_OMP_CLAUSE_NUM_THREADS:
22603 453 : clauses = c_parser_omp_clause_num_threads (parser, clauses);
22604 453 : c_name = "num_threads";
22605 453 : break;
22606 376 : case PRAGMA_OMP_CLAUSE_ORDER:
22607 376 : clauses = c_parser_omp_clause_order (parser, clauses);
22608 376 : c_name = "order";
22609 376 : break;
22610 310 : case PRAGMA_OMP_CLAUSE_ORDERED:
22611 310 : clauses = c_parser_omp_clause_ordered (parser, clauses);
22612 310 : c_name = "ordered";
22613 310 : break;
22614 98 : case PRAGMA_OMP_CLAUSE_PRIORITY:
22615 98 : clauses = c_parser_omp_clause_priority (parser, clauses);
22616 98 : c_name = "priority";
22617 98 : break;
22618 683 : case PRAGMA_OMP_CLAUSE_PRIVATE:
22619 683 : clauses = c_parser_omp_clause_private (parser, clauses);
22620 683 : c_name = "private";
22621 683 : break;
22622 1797 : case PRAGMA_OMP_CLAUSE_REDUCTION:
22623 1797 : clauses
22624 1797 : = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION,
22625 : true, clauses);
22626 1797 : c_name = "reduction";
22627 1797 : break;
22628 3483 : case PRAGMA_OMP_CLAUSE_SCHEDULE:
22629 3483 : clauses = c_parser_omp_clause_schedule (parser, clauses);
22630 3483 : c_name = "schedule";
22631 3483 : break;
22632 711 : case PRAGMA_OMP_CLAUSE_SHARED:
22633 711 : clauses = c_parser_omp_clause_shared (parser, clauses);
22634 711 : c_name = "shared";
22635 711 : break;
22636 86 : case PRAGMA_OMP_CLAUSE_TASK_REDUCTION:
22637 86 : clauses
22638 86 : = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_TASK_REDUCTION,
22639 : true, clauses);
22640 86 : c_name = "task_reduction";
22641 86 : break;
22642 97 : case PRAGMA_OMP_CLAUSE_UNTIED:
22643 97 : clauses = c_parser_omp_clause_untied (parser, clauses);
22644 97 : c_name = "untied";
22645 97 : break;
22646 82 : case PRAGMA_OMP_CLAUSE_INBRANCH:
22647 82 : clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
22648 : clauses);
22649 82 : c_name = "inbranch";
22650 82 : break;
22651 121 : case PRAGMA_OMP_CLAUSE_NONTEMPORAL:
22652 121 : clauses = c_parser_omp_clause_nontemporal (parser, clauses);
22653 121 : c_name = "nontemporal";
22654 121 : break;
22655 141 : case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
22656 141 : clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
22657 : clauses);
22658 141 : c_name = "notinbranch";
22659 141 : break;
22660 115 : case PRAGMA_OMP_CLAUSE_PARALLEL:
22661 115 : clauses
22662 115 : = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
22663 : clauses);
22664 115 : c_name = "parallel";
22665 115 : if (!first)
22666 : {
22667 0 : clause_not_first:
22668 0 : error_at (here, "%qs must be the first clause of %qs",
22669 : c_name, where);
22670 0 : clauses = prev;
22671 : }
22672 : break;
22673 84 : case PRAGMA_OMP_CLAUSE_FOR:
22674 84 : clauses
22675 84 : = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
22676 : clauses);
22677 84 : c_name = "for";
22678 84 : if (!first)
22679 0 : goto clause_not_first;
22680 : break;
22681 78 : case PRAGMA_OMP_CLAUSE_SECTIONS:
22682 78 : clauses
22683 78 : = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
22684 : clauses);
22685 78 : c_name = "sections";
22686 78 : if (!first)
22687 0 : goto clause_not_first;
22688 : break;
22689 110 : case PRAGMA_OMP_CLAUSE_TASKGROUP:
22690 110 : clauses
22691 110 : = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
22692 : clauses);
22693 110 : c_name = "taskgroup";
22694 110 : if (!first)
22695 0 : goto clause_not_first;
22696 : break;
22697 34 : case PRAGMA_OMP_CLAUSE_LINK:
22698 34 : clauses
22699 34 : = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses);
22700 34 : c_name = "link";
22701 34 : break;
22702 12 : case PRAGMA_OMP_CLAUSE_LOCAL:
22703 12 : clauses
22704 12 : = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LOCAL, clauses);
22705 12 : c_name = "local";
22706 12 : break;
22707 492 : case PRAGMA_OMP_CLAUSE_TO:
22708 492 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0)
22709 : {
22710 87 : gcc_rich_location richloc (here);
22711 87 : richloc.add_fixit_replace ("enter");
22712 87 : warning_at (&richloc, OPT_Wdeprecated_openmp,
22713 : "%<to%> clause with %<declare target%> deprecated "
22714 : "since OpenMP 5.2, use %<enter%>");
22715 87 : tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER,
22716 : clauses);
22717 280 : for (tree c = nl; c != clauses; c = OMP_CLAUSE_CHAIN (c))
22718 106 : OMP_CLAUSE_ENTER_TO (c) = 1;
22719 87 : clauses = nl;
22720 87 : }
22721 : else
22722 405 : clauses = c_parser_omp_clause_from_to (parser, OMP_CLAUSE_TO,
22723 : clauses);
22724 : c_name = "to";
22725 : break;
22726 2459 : case PRAGMA_OMP_CLAUSE_FROM:
22727 2459 : clauses = c_parser_omp_clause_from_to (parser, OMP_CLAUSE_FROM,
22728 : clauses);
22729 2459 : c_name = "from";
22730 2459 : break;
22731 117 : case PRAGMA_OMP_CLAUSE_UNIFORM:
22732 117 : clauses = c_parser_omp_clause_uniform (parser, clauses);
22733 117 : c_name = "uniform";
22734 117 : break;
22735 192 : case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
22736 192 : clauses = c_parser_omp_clause_num_teams (parser, clauses);
22737 192 : c_name = "num_teams";
22738 192 : break;
22739 155 : case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
22740 155 : clauses = c_parser_omp_clause_thread_limit (parser, clauses);
22741 155 : c_name = "thread_limit";
22742 155 : break;
22743 228 : case PRAGMA_OMP_CLAUSE_ALIGNED:
22744 228 : clauses = c_parser_omp_clause_aligned (parser, clauses);
22745 228 : c_name = "aligned";
22746 228 : break;
22747 485 : case PRAGMA_OMP_CLAUSE_ALLOCATE:
22748 485 : clauses = c_parser_omp_clause_allocate (parser, clauses);
22749 485 : c_name = "allocate";
22750 485 : break;
22751 478 : case PRAGMA_OMP_CLAUSE_LINEAR:
22752 478 : clauses = c_parser_omp_clause_linear (parser, clauses);
22753 478 : c_name = "linear";
22754 478 : break;
22755 55 : case PRAGMA_OMP_CLAUSE_USES_ALLOCATORS:
22756 55 : clauses = c_parser_omp_clause_uses_allocators (parser, clauses);
22757 55 : c_name = "uses_allocators";
22758 55 : break;
22759 151 : case PRAGMA_OMP_CLAUSE_AFFINITY:
22760 151 : clauses = c_parser_omp_clause_affinity (parser, clauses);
22761 151 : c_name = "affinity";
22762 151 : break;
22763 857 : case PRAGMA_OMP_CLAUSE_DEPEND:
22764 857 : clauses = c_parser_omp_clause_depend (parser, clauses, here);
22765 857 : c_name = "depend";
22766 857 : break;
22767 145 : case PRAGMA_OMP_CLAUSE_DOACROSS:
22768 145 : clauses = c_parser_omp_clause_doacross (parser, clauses);
22769 145 : c_name = "doacross";
22770 145 : break;
22771 41 : case PRAGMA_OMP_CLAUSE_DESTROY:
22772 41 : clauses = c_parser_omp_clause_destroy (parser, clauses);
22773 41 : c_name = "destroy";
22774 41 : break;
22775 21 : case PRAGMA_OMP_CLAUSE_DYN_GROUPPRIVATE:
22776 21 : clauses = c_parser_omp_clause_dyn_groupprivate (parser, clauses);
22777 21 : c_name = "dyn_groupprivate";
22778 21 : break;
22779 167 : case PRAGMA_OMP_CLAUSE_INIT:
22780 167 : clauses = c_parser_omp_clause_init (parser, clauses);
22781 167 : c_name = "init";
22782 167 : break;
22783 43 : case PRAGMA_OMP_CLAUSE_USE:
22784 43 : clauses = c_parser_omp_clause_use (parser, clauses);
22785 43 : c_name = "use";
22786 43 : break;
22787 43 : case PRAGMA_OMP_CLAUSE_INTEROP:
22788 43 : clauses = c_parser_omp_clause_interop (parser, clauses);
22789 43 : c_name = "interop";
22790 43 : break;
22791 1955 : case PRAGMA_OMP_CLAUSE_MAP:
22792 1955 : clauses = c_parser_omp_clause_map (parser, clauses, false);
22793 1955 : c_name = "map";
22794 1955 : break;
22795 10 : case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR:
22796 10 : clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
22797 10 : c_name = "use_device_ptr";
22798 10 : break;
22799 35 : case PRAGMA_OMP_CLAUSE_USE_DEVICE_ADDR:
22800 35 : clauses = c_parser_omp_clause_use_device_addr (parser, clauses);
22801 35 : c_name = "use_device_addr";
22802 35 : break;
22803 88 : case PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR:
22804 88 : clauses = c_parser_omp_clause_has_device_addr (parser, clauses);
22805 88 : c_name = "has_device_addr";
22806 88 : break;
22807 115 : case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR:
22808 115 : clauses = c_parser_omp_clause_is_device_ptr (parser, clauses);
22809 115 : c_name = "is_device_ptr";
22810 115 : break;
22811 388 : case PRAGMA_OMP_CLAUSE_DEVICE:
22812 388 : clauses = c_parser_omp_clause_device (parser, clauses);
22813 388 : c_name = "device";
22814 388 : break;
22815 1586 : case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
22816 1586 : clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
22817 1586 : c_name = "dist_schedule";
22818 1586 : break;
22819 195 : case PRAGMA_OMP_CLAUSE_PROC_BIND:
22820 195 : clauses = c_parser_omp_clause_proc_bind (parser, clauses);
22821 195 : c_name = "proc_bind";
22822 195 : break;
22823 53 : case PRAGMA_OMP_CLAUSE_DEVICE_TYPE:
22824 53 : clauses = c_parser_omp_clause_device_type (parser, clauses);
22825 53 : c_name = "device_type";
22826 53 : break;
22827 227 : case PRAGMA_OMP_CLAUSE_SAFELEN:
22828 227 : clauses = c_parser_omp_clause_safelen (parser, clauses);
22829 227 : c_name = "safelen";
22830 227 : break;
22831 362 : case PRAGMA_OMP_CLAUSE_SIMDLEN:
22832 362 : clauses = c_parser_omp_clause_simdlen (parser, clauses);
22833 362 : c_name = "simdlen";
22834 362 : break;
22835 18 : case PRAGMA_OMP_CLAUSE_NOGROUP:
22836 18 : clauses = c_parser_omp_clause_nogroup (parser, clauses);
22837 18 : c_name = "nogroup";
22838 18 : break;
22839 46 : case PRAGMA_OMP_CLAUSE_THREADS:
22840 46 : clauses
22841 46 : = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS,
22842 : clauses);
22843 46 : c_name = "threads";
22844 46 : break;
22845 57 : case PRAGMA_OMP_CLAUSE_SIMD:
22846 57 : clauses
22847 57 : = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD,
22848 : clauses);
22849 57 : c_name = "simd";
22850 57 : break;
22851 62 : case PRAGMA_OMP_CLAUSE_ENTER:
22852 62 : clauses
22853 62 : = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER,
22854 : clauses);
22855 62 : c_name = "enter";
22856 62 : break;
22857 69 : case PRAGMA_OMP_CLAUSE_FULL:
22858 69 : c_name = "full";
22859 69 : clauses = c_parser_omp_clause_full (parser, clauses);
22860 69 : break;
22861 230 : case PRAGMA_OMP_CLAUSE_PARTIAL:
22862 230 : c_name = "partial";
22863 230 : clauses = c_parser_omp_clause_partial (parser, clauses);
22864 230 : break;
22865 24 : case PRAGMA_OMP_CLAUSE_NOVARIANTS:
22866 24 : c_name = "novariants";
22867 24 : clauses = c_parser_omp_clause_novariants (parser, clauses);
22868 24 : break;
22869 23 : case PRAGMA_OMP_CLAUSE_NOCONTEXT:
22870 23 : c_name = "nocontext";
22871 23 : clauses = c_parser_omp_clause_nocontext (parser, clauses);
22872 23 : break;
22873 70 : default:
22874 70 : c_parser_error (parser, "expected an OpenMP clause");
22875 70 : goto saw_error;
22876 : }
22877 :
22878 27933 : first = false;
22879 :
22880 27933 : if (((mask >> c_kind) & 1) == 0)
22881 : {
22882 : /* Remove the invalid clause(s) from the list to avoid
22883 : confusing the rest of the compiler. */
22884 24 : clauses = prev;
22885 24 : error_at (here, "%qs is not valid for %qs", c_name, where);
22886 : }
22887 : }
22888 :
22889 20479 : saw_error:
22890 20574 : if (!nested)
22891 20548 : c_parser_skip_to_pragma_eol (parser);
22892 :
22893 20574 : if (finish_p)
22894 : {
22895 8557 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0)
22896 427 : return c_finish_omp_clauses (clauses, C_ORT_OMP_DECLARE_SIMD);
22897 8130 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE)) != 0)
22898 183 : return c_finish_omp_clauses (clauses, C_ORT_OMP_INTEROP);
22899 7947 : return c_finish_omp_clauses (clauses, C_ORT_OMP);
22900 : }
22901 :
22902 : return clauses;
22903 : }
22904 :
22905 : /* OpenACC 2.0, OpenMP 2.5:
22906 : structured-block:
22907 : statement
22908 :
22909 : In practice, we're also interested in adding the statement to an
22910 : outer node. So it is convenient if we work around the fact that
22911 : c_parser_statement calls add_stmt. */
22912 :
22913 : static tree
22914 6863 : c_parser_omp_structured_block (c_parser *parser, bool *if_p)
22915 : {
22916 6863 : tree stmt = push_stmt_list ();
22917 6863 : parser->omp_attrs_forbidden_p = true;
22918 6863 : c_parser_statement (parser, if_p);
22919 6863 : return pop_stmt_list (stmt);
22920 : }
22921 :
22922 : /* OpenACC 2.0:
22923 : # pragma acc cache (variable-list) new-line
22924 :
22925 : OpenACC 2.7:
22926 : # pragma acc cache (readonly: variable-list) new-line
22927 :
22928 : LOC is the location of the #pragma token.
22929 : */
22930 :
22931 : static tree
22932 137 : c_parser_oacc_cache (location_t loc, c_parser *parser)
22933 : {
22934 137 : tree stmt, clauses = NULL_TREE;
22935 137 : bool readonly = false;
22936 137 : location_t open_loc = c_parser_peek_token (parser)->location;
22937 137 : matching_parens parens;
22938 137 : if (parens.require_open (parser))
22939 : {
22940 135 : c_token *token = c_parser_peek_token (parser);
22941 135 : if (token->type == CPP_NAME
22942 131 : && !strcmp (IDENTIFIER_POINTER (token->value), "readonly")
22943 139 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
22944 : {
22945 4 : c_parser_consume_token (parser);
22946 4 : c_parser_consume_token (parser);
22947 4 : readonly = true;
22948 : }
22949 135 : clauses = c_parser_omp_variable_list (parser, open_loc,
22950 : OMP_CLAUSE__CACHE_, NULL_TREE);
22951 135 : parens.skip_until_found_close (parser);
22952 : }
22953 :
22954 135 : if (readonly)
22955 8 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
22956 4 : OMP_CLAUSE__CACHE__READONLY (c) = 1;
22957 :
22958 137 : clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
22959 :
22960 137 : c_parser_skip_to_pragma_eol (parser);
22961 :
22962 137 : stmt = make_node (OACC_CACHE);
22963 137 : TREE_TYPE (stmt) = void_type_node;
22964 137 : OACC_CACHE_CLAUSES (stmt) = clauses;
22965 137 : SET_EXPR_LOCATION (stmt, loc);
22966 137 : add_stmt (stmt);
22967 :
22968 137 : return stmt;
22969 : }
22970 :
22971 : /* OpenACC 2.0:
22972 : # pragma acc data oacc-data-clause[optseq] new-line
22973 : structured-block
22974 :
22975 : LOC is the location of the #pragma token.
22976 : */
22977 :
22978 : #define OACC_DATA_CLAUSE_MASK \
22979 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \
22980 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
22981 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
22982 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
22983 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
22984 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
22985 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
22986 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
22987 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \
22988 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
22989 :
22990 : static tree
22991 497 : c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p)
22992 : {
22993 497 : tree stmt, clauses, block;
22994 :
22995 497 : clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
22996 : "#pragma acc data");
22997 :
22998 497 : block = c_begin_omp_parallel ();
22999 497 : add_stmt (c_parser_omp_structured_block (parser, if_p));
23000 :
23001 497 : stmt = c_finish_oacc_data (loc, clauses, block);
23002 :
23003 497 : return stmt;
23004 : }
23005 :
23006 : /* OpenACC 2.0:
23007 : # pragma acc declare oacc-data-clause[optseq] new-line
23008 : */
23009 :
23010 : #define OACC_DECLARE_CLAUSE_MASK \
23011 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
23012 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
23013 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
23014 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
23015 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
23016 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
23017 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
23018 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
23019 :
23020 : static void
23021 144 : c_parser_oacc_declare (c_parser *parser)
23022 : {
23023 144 : location_t pragma_loc = c_parser_peek_token (parser)->location;
23024 144 : tree clauses, stmt, t, decl;
23025 :
23026 144 : bool error = false;
23027 :
23028 144 : c_parser_consume_pragma (parser);
23029 :
23030 144 : clauses = c_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK,
23031 : "#pragma acc declare");
23032 144 : if (!clauses)
23033 : {
23034 2 : error_at (pragma_loc,
23035 : "no valid clauses specified in %<#pragma acc declare%>");
23036 2 : return;
23037 : }
23038 :
23039 296 : for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t))
23040 : {
23041 154 : location_t loc = OMP_CLAUSE_LOCATION (t);
23042 154 : decl = OMP_CLAUSE_DECL (t);
23043 154 : if (!DECL_P (decl))
23044 : {
23045 1 : error_at (loc, "array section in %<#pragma acc declare%>");
23046 1 : error = true;
23047 1 : continue;
23048 : }
23049 :
23050 153 : switch (OMP_CLAUSE_MAP_KIND (t))
23051 : {
23052 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
23053 : case GOMP_MAP_ALLOC:
23054 : case GOMP_MAP_TO:
23055 : case GOMP_MAP_FORCE_DEVICEPTR:
23056 : case GOMP_MAP_DEVICE_RESIDENT:
23057 : break;
23058 :
23059 13 : case GOMP_MAP_LINK:
23060 13 : if (!global_bindings_p ()
23061 13 : && (TREE_STATIC (decl)
23062 6 : || !DECL_EXTERNAL (decl)))
23063 : {
23064 2 : error_at (loc,
23065 : "%qD must be a global variable in "
23066 : "%<#pragma acc declare link%>",
23067 : decl);
23068 2 : error = true;
23069 2 : continue;
23070 : }
23071 : break;
23072 :
23073 42 : default:
23074 42 : if (global_bindings_p ())
23075 : {
23076 5 : error_at (loc, "invalid OpenACC clause at file scope");
23077 5 : error = true;
23078 5 : continue;
23079 : }
23080 37 : if (DECL_EXTERNAL (decl))
23081 : {
23082 10 : error_at (loc,
23083 : "invalid use of %<extern%> variable %qD "
23084 : "in %<#pragma acc declare%>", decl);
23085 10 : error = true;
23086 10 : continue;
23087 : }
23088 27 : else if (TREE_PUBLIC (decl))
23089 : {
23090 2 : error_at (loc,
23091 : "invalid use of %<global%> variable %qD "
23092 : "in %<#pragma acc declare%>", decl);
23093 2 : error = true;
23094 2 : continue;
23095 : }
23096 : break;
23097 : }
23098 :
23099 134 : if (!c_check_in_current_scope (decl))
23100 : {
23101 2 : error_at (loc,
23102 : "%qD must be a variable declared in the same scope as "
23103 : "%<#pragma acc declare%>", decl);
23104 2 : error = true;
23105 2 : continue;
23106 : }
23107 :
23108 132 : if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))
23109 250 : || lookup_attribute ("omp declare target link",
23110 118 : DECL_ATTRIBUTES (decl)))
23111 : {
23112 17 : error_at (loc, "variable %qD used more than once with "
23113 : "%<#pragma acc declare%>", decl);
23114 17 : error = true;
23115 17 : continue;
23116 : }
23117 :
23118 115 : if (!error)
23119 : {
23120 115 : tree id;
23121 :
23122 115 : if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK)
23123 7 : id = get_identifier ("omp declare target link");
23124 : else
23125 108 : id = get_identifier ("omp declare target");
23126 :
23127 115 : DECL_ATTRIBUTES (decl)
23128 115 : = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
23129 :
23130 115 : if (global_bindings_p ())
23131 : {
23132 45 : symtab_node *node = symtab_node::get (decl);
23133 45 : if (node != NULL)
23134 : {
23135 33 : node->offloadable = 1;
23136 33 : if (ENABLE_OFFLOADING)
23137 : {
23138 : g->have_offload = true;
23139 : if (is_a <varpool_node *> (node))
23140 : vec_safe_push (offload_vars, decl);
23141 : }
23142 : }
23143 : }
23144 : }
23145 : }
23146 :
23147 142 : if (error || global_bindings_p ())
23148 : return;
23149 :
23150 68 : stmt = make_node (OACC_DECLARE);
23151 68 : TREE_TYPE (stmt) = void_type_node;
23152 68 : OACC_DECLARE_CLAUSES (stmt) = clauses;
23153 68 : SET_EXPR_LOCATION (stmt, pragma_loc);
23154 :
23155 68 : add_stmt (stmt);
23156 :
23157 68 : return;
23158 : }
23159 :
23160 : /* OpenACC 2.0:
23161 : # pragma acc enter data oacc-enter-data-clause[optseq] new-line
23162 :
23163 : or
23164 :
23165 : # pragma acc exit data oacc-exit-data-clause[optseq] new-line
23166 :
23167 :
23168 : LOC is the location of the #pragma token.
23169 : */
23170 :
23171 : #define OACC_ENTER_DATA_CLAUSE_MASK \
23172 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
23173 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
23174 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \
23175 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
23176 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
23177 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
23178 :
23179 : #define OACC_EXIT_DATA_CLAUSE_MASK \
23180 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
23181 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
23182 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
23183 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
23184 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DETACH) \
23185 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FINALIZE) \
23186 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
23187 :
23188 : static void
23189 261 : c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
23190 : {
23191 261 : location_t loc = c_parser_peek_token (parser)->location;
23192 261 : tree clauses, stmt;
23193 261 : const char *p = "";
23194 :
23195 261 : c_parser_consume_pragma (parser);
23196 :
23197 261 : if (c_parser_next_token_is (parser, CPP_NAME))
23198 : {
23199 258 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
23200 258 : c_parser_consume_token (parser);
23201 : }
23202 :
23203 261 : if (strcmp (p, "data") != 0)
23204 : {
23205 8 : error_at (loc, "expected %<data%> after %<#pragma acc %s%>",
23206 : enter ? "enter" : "exit");
23207 6 : parser->error = true;
23208 6 : c_parser_skip_to_pragma_eol (parser);
23209 6 : return;
23210 : }
23211 :
23212 255 : if (enter)
23213 129 : clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
23214 : "#pragma acc enter data");
23215 : else
23216 126 : clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
23217 : "#pragma acc exit data");
23218 :
23219 255 : if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
23220 : {
23221 15 : error_at (loc, "%<#pragma acc %s data%> has no data movement clause",
23222 : enter ? "enter" : "exit");
23223 15 : return;
23224 : }
23225 :
23226 240 : stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);
23227 240 : TREE_TYPE (stmt) = void_type_node;
23228 240 : OMP_STANDALONE_CLAUSES (stmt) = clauses;
23229 240 : SET_EXPR_LOCATION (stmt, loc);
23230 240 : add_stmt (stmt);
23231 : }
23232 :
23233 :
23234 : /* OpenACC 2.0:
23235 : # pragma acc host_data oacc-data-clause[optseq] new-line
23236 : structured-block
23237 : */
23238 :
23239 : #define OACC_HOST_DATA_CLAUSE_MASK \
23240 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) \
23241 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
23242 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) )
23243 :
23244 : static tree
23245 23 : c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p)
23246 : {
23247 23 : tree stmt, clauses, block;
23248 :
23249 23 : clauses = c_parser_oacc_all_clauses (parser, OACC_HOST_DATA_CLAUSE_MASK,
23250 : "#pragma acc host_data", false);
23251 23 : if (!omp_find_clause (clauses, OMP_CLAUSE_USE_DEVICE_PTR))
23252 : {
23253 2 : error_at (loc, "%<host_data%> construct requires %<use_device%> clause");
23254 2 : return error_mark_node;
23255 : }
23256 21 : clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
23257 21 : block = c_begin_omp_parallel ();
23258 21 : add_stmt (c_parser_omp_structured_block (parser, if_p));
23259 21 : stmt = c_finish_oacc_host_data (loc, clauses, block);
23260 21 : return stmt;
23261 : }
23262 :
23263 :
23264 : /* OpenACC 2.0:
23265 :
23266 : # pragma acc loop oacc-loop-clause[optseq] new-line
23267 : structured-block
23268 :
23269 : LOC is the location of the #pragma token.
23270 : */
23271 :
23272 : #define OACC_LOOP_CLAUSE_MASK \
23273 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
23274 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
23275 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
23276 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
23277 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
23278 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
23279 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
23280 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
23281 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
23282 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
23283 : static tree
23284 2444 : c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name,
23285 : omp_clause_mask mask, tree *cclauses, bool *if_p)
23286 : {
23287 2444 : bool is_parallel = ((mask >> PRAGMA_OACC_CLAUSE_REDUCTION) & 1) == 1;
23288 :
23289 2444 : strcat (p_name, " loop");
23290 2444 : mask |= OACC_LOOP_CLAUSE_MASK;
23291 :
23292 2444 : tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name,
23293 : /*finish_p=*/cclauses == NULL,
23294 : /*target=*/is_parallel);
23295 2444 : if (cclauses)
23296 : {
23297 673 : clauses = c_oacc_split_loop_clauses (clauses, cclauses, is_parallel);
23298 673 : if (*cclauses)
23299 152 : *cclauses = c_finish_omp_clauses (*cclauses, C_ORT_ACC_TARGET);
23300 673 : if (clauses)
23301 271 : clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
23302 : }
23303 :
23304 2444 : tree block = c_begin_compound_stmt (true);
23305 2444 : tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL,
23306 : if_p);
23307 2444 : block = c_end_compound_stmt (loc, block, true);
23308 2444 : add_stmt (block);
23309 :
23310 2444 : return stmt;
23311 : }
23312 :
23313 : /* OpenACC 2.0:
23314 : # pragma acc kernels oacc-kernels-clause[optseq] new-line
23315 : structured-block
23316 :
23317 : or
23318 :
23319 : # pragma acc parallel oacc-parallel-clause[optseq] new-line
23320 : structured-block
23321 :
23322 : OpenACC 2.6:
23323 :
23324 : # pragma acc serial oacc-serial-clause[optseq] new-line
23325 : structured-block
23326 :
23327 : LOC is the location of the #pragma token.
23328 : */
23329 :
23330 : #define OACC_KERNELS_CLAUSE_MASK \
23331 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
23332 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \
23333 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
23334 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
23335 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
23336 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
23337 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
23338 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
23339 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
23340 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \
23341 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
23342 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
23343 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
23344 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
23345 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
23346 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
23347 :
23348 : #define OACC_PARALLEL_CLAUSE_MASK \
23349 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
23350 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \
23351 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
23352 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
23353 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
23354 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
23355 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
23356 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
23357 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
23358 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \
23359 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
23360 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
23361 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
23362 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
23363 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
23364 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
23365 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
23366 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
23367 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
23368 :
23369 : #define OACC_SERIAL_CLAUSE_MASK \
23370 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
23371 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ATTACH) \
23372 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
23373 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
23374 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
23375 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
23376 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
23377 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
23378 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
23379 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NO_CREATE) \
23380 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
23381 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
23382 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
23383 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
23384 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
23385 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
23386 :
23387 : static tree
23388 2154 : c_parser_oacc_compute (location_t loc, c_parser *parser,
23389 : enum pragma_kind p_kind, char *p_name, bool *if_p)
23390 : {
23391 2154 : omp_clause_mask mask;
23392 2154 : enum tree_code code;
23393 2154 : switch (p_kind)
23394 : {
23395 522 : case PRAGMA_OACC_KERNELS:
23396 522 : strcat (p_name, " kernels");
23397 522 : mask = OACC_KERNELS_CLAUSE_MASK;
23398 522 : code = OACC_KERNELS;
23399 522 : break;
23400 1457 : case PRAGMA_OACC_PARALLEL:
23401 1457 : strcat (p_name, " parallel");
23402 1457 : mask = OACC_PARALLEL_CLAUSE_MASK;
23403 1457 : code = OACC_PARALLEL;
23404 1457 : break;
23405 175 : case PRAGMA_OACC_SERIAL:
23406 175 : strcat (p_name, " serial");
23407 175 : mask = OACC_SERIAL_CLAUSE_MASK;
23408 175 : code = OACC_SERIAL;
23409 175 : break;
23410 0 : default:
23411 0 : gcc_unreachable ();
23412 : }
23413 :
23414 2154 : if (c_parser_next_token_is (parser, CPP_NAME))
23415 : {
23416 1710 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
23417 1710 : if (strcmp (p, "loop") == 0)
23418 : {
23419 673 : c_parser_consume_token (parser);
23420 673 : tree block = c_begin_omp_parallel ();
23421 673 : tree clauses;
23422 673 : c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p);
23423 673 : return c_finish_omp_construct (loc, code, block, clauses);
23424 : }
23425 : }
23426 :
23427 1481 : tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name,
23428 : /*finish_p=*/true,
23429 : /*target=*/true);
23430 :
23431 1481 : tree block = c_begin_omp_parallel ();
23432 1481 : add_stmt (c_parser_omp_structured_block (parser, if_p));
23433 :
23434 1481 : return c_finish_omp_construct (loc, code, block, clauses);
23435 : }
23436 :
23437 : /* OpenACC 2.0:
23438 : # pragma acc routine oacc-routine-clause[optseq] new-line
23439 : function-definition
23440 :
23441 : # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
23442 : */
23443 :
23444 : #define OACC_ROUTINE_CLAUSE_MASK \
23445 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
23446 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
23447 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
23448 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
23449 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NOHOST) )
23450 :
23451 : /* Parse an OpenACC routine directive. For named directives, we apply
23452 : immediately to the named function. For unnamed ones we then parse
23453 : a declaration or definition, which must be for a function. */
23454 :
23455 : static void
23456 345 : c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
23457 : {
23458 345 : gcc_checking_assert (context == pragma_external);
23459 :
23460 345 : oacc_routine_data data;
23461 345 : data.error_seen = false;
23462 345 : data.fndecl_seen = false;
23463 345 : data.loc = c_parser_peek_token (parser)->location;
23464 :
23465 345 : c_parser_consume_pragma (parser);
23466 :
23467 : /* Look for optional '( name )'. */
23468 345 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
23469 : {
23470 143 : c_parser_consume_token (parser); /* '(' */
23471 :
23472 143 : tree decl = NULL_TREE;
23473 143 : c_token *name_token = c_parser_peek_token (parser);
23474 143 : location_t name_loc = name_token->location;
23475 143 : if (name_token->type == CPP_NAME
23476 135 : && (name_token->id_kind == C_ID_ID
23477 : || name_token->id_kind == C_ID_TYPENAME))
23478 : {
23479 135 : decl = lookup_name (name_token->value);
23480 135 : if (!decl)
23481 5 : error_at (name_loc,
23482 : "%qE has not been declared", name_token->value);
23483 135 : c_parser_consume_token (parser);
23484 : }
23485 : else
23486 8 : c_parser_error (parser, "expected function name");
23487 :
23488 8 : if (!decl
23489 135 : || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
23490 : {
23491 15 : c_parser_skip_to_pragma_eol (parser, false);
23492 43 : return;
23493 : }
23494 :
23495 128 : data.clauses
23496 128 : = c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
23497 : "#pragma acc routine");
23498 : /* The clauses are in reverse order; fix that to make later diagnostic
23499 : emission easier. */
23500 128 : data.clauses = nreverse (data.clauses);
23501 :
23502 128 : if (TREE_CODE (decl) != FUNCTION_DECL)
23503 : {
23504 3 : error_at (name_loc, "%qD does not refer to a function", decl);
23505 3 : return;
23506 : }
23507 :
23508 125 : c_finish_oacc_routine (&data, decl, false);
23509 : }
23510 : else /* No optional '( name )'. */
23511 : {
23512 202 : data.clauses
23513 202 : = c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
23514 : "#pragma acc routine");
23515 : /* The clauses are in reverse order; fix that to make later diagnostic
23516 : emission easier. */
23517 202 : data.clauses = nreverse (data.clauses);
23518 :
23519 : /* Emit a helpful diagnostic if there's another pragma following this
23520 : one. Also don't allow a static assertion declaration, as in the
23521 : following we'll just parse a *single* "declaration or function
23522 : definition", and the static assertion counts an one. */
23523 202 : if (c_parser_next_token_is (parser, CPP_PRAGMA)
23524 395 : || c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
23525 : {
23526 10 : error_at (data.loc,
23527 : "%<#pragma acc routine%> not immediately followed by"
23528 : " function declaration or definition");
23529 : /* ..., and then just keep going. */
23530 10 : return;
23531 : }
23532 :
23533 : /* We only have to consider the pragma_external case here. */
23534 192 : if (c_parser_next_token_is (parser, CPP_KEYWORD)
23535 192 : && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
23536 : {
23537 3 : int ext = disable_extension_diagnostics ();
23538 7 : do
23539 7 : c_parser_consume_token (parser);
23540 7 : while (c_parser_next_token_is (parser, CPP_KEYWORD)
23541 10 : && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
23542 3 : c_parser_declaration_or_fndef (parser, true, true, true, false, true,
23543 : false, NULL, NULL, false, NULL, &data);
23544 3 : restore_extension_diagnostics (ext);
23545 : }
23546 : else
23547 189 : c_parser_declaration_or_fndef (parser, true, true, true, false, true,
23548 : false, NULL, NULL, false, NULL, &data);
23549 : }
23550 : }
23551 :
23552 : /* Finalize an OpenACC routine pragma, applying it to FNDECL.
23553 : IS_DEFN is true if we're applying it to the definition. */
23554 :
23555 : static void
23556 327 : c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl,
23557 : bool is_defn)
23558 : {
23559 : /* Keep going if we're in error reporting mode. */
23560 327 : if (data->error_seen
23561 321 : || fndecl == error_mark_node)
23562 : return;
23563 :
23564 321 : if (data->fndecl_seen)
23565 : {
23566 4 : error_at (data->loc,
23567 : "%<#pragma acc routine%> not immediately followed by"
23568 : " a single function declaration or definition");
23569 4 : data->error_seen = true;
23570 4 : return;
23571 : }
23572 317 : if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
23573 : {
23574 10 : error_at (data->loc,
23575 : "%<#pragma acc routine%> not immediately followed by"
23576 : " function declaration or definition");
23577 10 : data->error_seen = true;
23578 10 : return;
23579 : }
23580 :
23581 307 : int compatible
23582 307 : = oacc_verify_routine_clauses (fndecl, &data->clauses, data->loc,
23583 : "#pragma acc routine");
23584 307 : if (compatible < 0)
23585 : {
23586 47 : data->error_seen = true;
23587 47 : return;
23588 : }
23589 260 : if (compatible > 0)
23590 : {
23591 : }
23592 : else
23593 : {
23594 269 : if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
23595 : {
23596 3 : error_at (data->loc,
23597 : TREE_USED (fndecl)
23598 : ? G_("%<#pragma acc routine%> must be applied before use")
23599 : : G_("%<#pragma acc routine%> must be applied before"
23600 : " definition"));
23601 2 : data->error_seen = true;
23602 2 : return;
23603 : }
23604 :
23605 : /* Set the routine's level of parallelism. */
23606 197 : tree dims = oacc_build_routine_dims (data->clauses);
23607 197 : oacc_replace_fn_attrib (fndecl, dims);
23608 :
23609 : /* Add an "omp declare target" attribute. */
23610 197 : DECL_ATTRIBUTES (fndecl)
23611 394 : = tree_cons (get_identifier ("omp declare target"),
23612 197 : data->clauses, DECL_ATTRIBUTES (fndecl));
23613 : }
23614 :
23615 : /* Remember that we've used this "#pragma acc routine". */
23616 258 : data->fndecl_seen = true;
23617 : }
23618 :
23619 : /* OpenACC 2.0:
23620 : # pragma acc update oacc-update-clause[optseq] new-line
23621 : */
23622 :
23623 : #define OACC_UPDATE_CLAUSE_MASK \
23624 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
23625 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
23626 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
23627 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
23628 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) \
23629 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
23630 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
23631 :
23632 : static void
23633 92 : c_parser_oacc_update (c_parser *parser)
23634 : {
23635 92 : location_t loc = c_parser_peek_token (parser)->location;
23636 :
23637 92 : c_parser_consume_pragma (parser);
23638 :
23639 92 : tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
23640 : "#pragma acc update");
23641 92 : if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
23642 : {
23643 1 : error_at (loc,
23644 : "%<#pragma acc update%> must contain at least one "
23645 : "%<device%> or %<host%> or %<self%> clause");
23646 1 : return;
23647 : }
23648 :
23649 91 : if (parser->error)
23650 : return;
23651 :
23652 91 : tree stmt = make_node (OACC_UPDATE);
23653 91 : TREE_TYPE (stmt) = void_type_node;
23654 91 : OACC_UPDATE_CLAUSES (stmt) = clauses;
23655 91 : SET_EXPR_LOCATION (stmt, loc);
23656 91 : add_stmt (stmt);
23657 : }
23658 :
23659 : /* OpenACC 2.0:
23660 : # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
23661 :
23662 : LOC is the location of the #pragma token.
23663 : */
23664 :
23665 : #define OACC_WAIT_CLAUSE_MASK \
23666 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
23667 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) )
23668 :
23669 : static tree
23670 86 : c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
23671 : {
23672 86 : tree clauses, list = NULL_TREE, stmt = NULL_TREE;
23673 :
23674 86 : if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
23675 49 : list = c_parser_oacc_wait_list (parser, loc, list);
23676 :
23677 86 : strcpy (p_name, " wait");
23678 86 : clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
23679 86 : stmt = c_finish_oacc_wait (loc, list, clauses);
23680 86 : add_stmt (stmt);
23681 :
23682 86 : return stmt;
23683 : }
23684 :
23685 : struct c_omp_loc_tree
23686 : {
23687 : location_t loc;
23688 : tree var;
23689 : };
23690 :
23691 : /* Check whether the expression used in the allocator clause is declared or
23692 : modified between the variable declaration and its allocate directive. */
23693 : static tree
23694 87 : c_check_omp_allocate_allocator_r (tree *tp, int *, void *data)
23695 : {
23696 87 : tree var = ((struct c_omp_loc_tree *) data)->var;
23697 87 : location_t loc = ((struct c_omp_loc_tree *) data)->loc;
23698 87 : if (TREE_CODE (*tp) == VAR_DECL && c_check_in_current_scope (*tp))
23699 : {
23700 19 : if (linemap_location_before_p (line_table, DECL_SOURCE_LOCATION (var),
23701 19 : DECL_SOURCE_LOCATION (*tp)))
23702 : {
23703 4 : error_at (loc, "variable %qD used in the %<allocator%> clause must "
23704 : "be declared before %qD", *tp, var);
23705 4 : inform (DECL_SOURCE_LOCATION (*tp), "declared here");
23706 4 : inform (DECL_SOURCE_LOCATION (var),
23707 : "to be allocated variable declared here");
23708 4 : return *tp;
23709 : }
23710 : else
23711 : {
23712 15 : gcc_assert (cur_stmt_list
23713 : && TREE_CODE (cur_stmt_list) == STATEMENT_LIST);
23714 :
23715 15 : tree_stmt_iterator l = tsi_last (cur_stmt_list);
23716 19 : while (!tsi_end_p (l))
23717 : {
23718 19 : if (linemap_location_before_p (line_table, EXPR_LOCATION (*l),
23719 19 : DECL_SOURCE_LOCATION (var)))
23720 : break;
23721 6 : if (TREE_CODE (*l) == MODIFY_EXPR
23722 6 : && TREE_OPERAND (*l, 0) == *tp)
23723 : {
23724 2 : error_at (loc,
23725 : "variable %qD used in the %<allocator%> clause "
23726 : "must not be modified between declaration of %qD "
23727 : "and its %<allocate%> directive", *tp, var);
23728 2 : inform (EXPR_LOCATION (*l), "modified here");
23729 2 : inform (DECL_SOURCE_LOCATION (var),
23730 : "to be allocated variable declared here");
23731 2 : return *tp;
23732 : }
23733 4 : --l;
23734 : }
23735 : }
23736 : }
23737 : return NULL_TREE;
23738 : }
23739 :
23740 : /* OpenMP 5.x:
23741 : # pragma omp allocate (list) clauses
23742 :
23743 : OpenMP 5.0 clause:
23744 : allocator (omp_allocator_handle_t expression)
23745 :
23746 : OpenMP 5.1 additional clause:
23747 : align (constant-expression)] */
23748 :
23749 : static void
23750 118 : c_parser_omp_allocate (c_parser *parser)
23751 : {
23752 118 : tree alignment = NULL_TREE;
23753 118 : tree allocator = NULL_TREE;
23754 118 : c_parser_consume_pragma (parser);
23755 118 : location_t loc = c_parser_peek_token (parser)->location;
23756 118 : location_t allocator_loc = UNKNOWN_LOCATION;
23757 118 : tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ALLOCATE, NULL_TREE);
23758 340 : do
23759 : {
23760 229 : if (c_parser_next_token_is (parser, CPP_COMMA)
23761 229 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
23762 9 : c_parser_consume_token (parser);
23763 229 : if (!c_parser_next_token_is (parser, CPP_NAME))
23764 : break;
23765 114 : matching_parens parens;
23766 114 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
23767 114 : c_parser_consume_token (parser);
23768 114 : location_t expr_loc = c_parser_peek_token (parser)->location;
23769 114 : if (strcmp ("align", p) != 0 && strcmp ("allocator", p) != 0)
23770 : {
23771 1 : error_at (c_parser_peek_token (parser)->location,
23772 : "expected %<allocator%> or %<align%>");
23773 1 : break;
23774 : }
23775 113 : if (!parens.require_open (parser))
23776 : break;
23777 :
23778 113 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
23779 113 : expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
23780 113 : expr_loc = c_parser_peek_token (parser)->location;
23781 113 : if (expr.value == error_mark_node)
23782 : ;
23783 112 : else if (p[2] == 'i' && alignment)
23784 : {
23785 1 : error_at (expr_loc, "too many %qs clauses", "align");
23786 1 : break;
23787 : }
23788 111 : else if (p[2] == 'i')
23789 : {
23790 32 : alignment = c_fully_fold (expr.value, false, NULL);
23791 32 : if (TREE_CODE (alignment) != INTEGER_CST
23792 31 : || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
23793 31 : || tree_int_cst_sgn (alignment) != 1
23794 62 : || !integer_pow2p (alignment))
23795 : {
23796 4 : error_at (expr_loc, "%<align%> clause argument needs to be "
23797 : "positive constant power of two integer "
23798 : "expression");
23799 4 : alignment = NULL_TREE;
23800 : }
23801 : }
23802 79 : else if (allocator)
23803 : {
23804 1 : error_at (expr_loc, "too many %qs clauses", "allocator");
23805 1 : break;
23806 : }
23807 : else
23808 : {
23809 78 : allocator = c_fully_fold (expr.value, false, NULL);
23810 78 : allocator_loc = expr_loc;
23811 78 : tree orig_type
23812 78 : = expr.original_type ? expr.original_type : TREE_TYPE (allocator);
23813 78 : orig_type = TYPE_MAIN_VARIANT (orig_type);
23814 79 : if (!INTEGRAL_TYPE_P (TREE_TYPE (allocator))
23815 78 : || TREE_CODE (orig_type) != ENUMERAL_TYPE
23816 232 : || TYPE_NAME (orig_type)
23817 77 : != get_identifier ("omp_allocator_handle_t"))
23818 : {
23819 1 : error_at (expr_loc,
23820 : "%<allocator%> clause expression has type "
23821 : "%qT rather than %<omp_allocator_handle_t%>",
23822 1 : TREE_TYPE (allocator));
23823 1 : allocator = NULL_TREE;
23824 : }
23825 : }
23826 111 : parens.skip_until_found_close (parser);
23827 111 : } while (true);
23828 118 : c_parser_skip_to_pragma_eol (parser);
23829 :
23830 118 : c_mark_decl_jump_unsafe_in_current_scope ();
23831 435 : for (tree c = nl; c != NULL_TREE; c = OMP_CLAUSE_CHAIN (c))
23832 : {
23833 199 : tree var = OMP_CLAUSE_DECL (c);
23834 199 : if (TREE_CODE (var) == PARM_DECL)
23835 : {
23836 24 : error_at (OMP_CLAUSE_LOCATION (nl),
23837 : "function parameter %qD may not appear as list item in an "
23838 : "%<allocate%> directive", var);
23839 24 : continue;
23840 : }
23841 175 : if (!parser->in_omp_decl_attribute && !c_check_in_current_scope (var))
23842 : {
23843 6 : error_at (OMP_CLAUSE_LOCATION (nl),
23844 : "%<allocate%> directive must be in the same scope as %qD",
23845 : var);
23846 6 : inform (DECL_SOURCE_LOCATION (var), "declared here");
23847 6 : continue;
23848 : }
23849 169 : if (lookup_attribute ("omp allocate", DECL_ATTRIBUTES (var)))
23850 : {
23851 41 : error_at (OMP_CLAUSE_LOCATION (nl),
23852 : "%qD already appeared as list item in an "
23853 : "%<allocate%> directive", var);
23854 41 : continue;
23855 : }
23856 128 : if (TREE_STATIC (var))
23857 : {
23858 46 : if (allocator == NULL_TREE && allocator_loc == UNKNOWN_LOCATION)
23859 : {
23860 3 : error_at (loc,
23861 : "%<allocator%> clause required for "
23862 : "static variable %qD", var);
23863 3 : continue;
23864 : }
23865 43 : else if (allocator
23866 43 : && (wi::to_widest (allocator) < 1
23867 40 : || wi::to_widest (allocator) > GOMP_OMP_PREDEF_ALLOC_MAX)
23868 56 : && (wi::to_widest (allocator) < GOMP_OMPX_PREDEF_ALLOC_MIN
23869 13 : || wi::to_widest (allocator) > GOMP_OMPX_PREDEF_ALLOC_MAX))
23870 : {
23871 8 : error_at (allocator_loc,
23872 : "%<allocator%> clause requires a predefined allocator as "
23873 : "%qD is static", var);
23874 : }
23875 35 : else if (allocator
23876 70 : && (wi::eq_p (wi::to_widest (allocator),
23877 35 : GOMP_OMP_PREDEF_ALLOC_CGROUP)
23878 33 : || wi::eq_p (wi::to_widest (allocator),
23879 33 : GOMP_OMP_PREDEF_ALLOC_PTEAM)
23880 31 : || wi::eq_p (wi::to_widest (allocator),
23881 66 : GOMP_OMP_PREDEF_ALLOC_THREAD)))
23882 : {
23883 6 : error_at (allocator_loc,
23884 : "%<allocator%> clause for static variable %qD must not "
23885 : "be %<omp_cgroup_mem_alloc%>, %<omp_pteam_mem_alloc%>, "
23886 : "or %<omp_thread_mem_alloc%>", var);
23887 : }
23888 : }
23889 125 : if (allocator)
23890 : {
23891 79 : struct c_omp_loc_tree data
23892 156 : = {EXPR_LOC_OR_LOC (allocator, OMP_CLAUSE_LOCATION (nl)), var};
23893 79 : walk_tree (&allocator, c_check_omp_allocate_allocator_r, &data, NULL);
23894 : }
23895 125 : DECL_ATTRIBUTES (var) = tree_cons (get_identifier ("omp allocate"),
23896 : build_tree_list (allocator, alignment),
23897 125 : DECL_ATTRIBUTES (var));
23898 : }
23899 118 : }
23900 :
23901 : /* OpenMP 2.5:
23902 : # pragma omp atomic new-line
23903 : expression-stmt
23904 :
23905 : expression-stmt:
23906 : x binop= expr | x++ | ++x | x-- | --x
23907 : binop:
23908 : +, *, -, /, &, ^, |, <<, >>
23909 :
23910 : where x is an lvalue expression with scalar type.
23911 :
23912 : OpenMP 3.1:
23913 : # pragma omp atomic new-line
23914 : update-stmt
23915 :
23916 : # pragma omp atomic read new-line
23917 : read-stmt
23918 :
23919 : # pragma omp atomic write new-line
23920 : write-stmt
23921 :
23922 : # pragma omp atomic update new-line
23923 : update-stmt
23924 :
23925 : # pragma omp atomic capture new-line
23926 : capture-stmt
23927 :
23928 : # pragma omp atomic capture new-line
23929 : capture-block
23930 :
23931 : read-stmt:
23932 : v = x
23933 : write-stmt:
23934 : x = expr
23935 : update-stmt:
23936 : expression-stmt | x = x binop expr
23937 : capture-stmt:
23938 : v = expression-stmt
23939 : capture-block:
23940 : { v = x; update-stmt; } | { update-stmt; v = x; }
23941 :
23942 : OpenMP 4.0:
23943 : update-stmt:
23944 : expression-stmt | x = x binop expr | x = expr binop x
23945 : capture-stmt:
23946 : v = update-stmt
23947 : capture-block:
23948 : { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
23949 :
23950 : OpenMP 5.1:
23951 : # pragma omp atomic compare new-line
23952 : conditional-update-atomic
23953 :
23954 : # pragma omp atomic compare capture new-line
23955 : conditional-update-capture-atomic
23956 :
23957 : conditional-update-atomic:
23958 : cond-expr-stmt | cond-update-stmt
23959 : cond-expr-stmt:
23960 : x = expr ordop x ? expr : x;
23961 : x = x ordop expr ? expr : x;
23962 : x = x == e ? d : x;
23963 : cond-update-stmt:
23964 : if (expr ordop x) { x = expr; }
23965 : if (x ordop expr) { x = expr; }
23966 : if (x == e) { x = d; }
23967 : ordop:
23968 : <, >
23969 : conditional-update-capture-atomic:
23970 : v = cond-expr-stmt
23971 : { v = x; cond-expr-stmt }
23972 : { cond-expr-stmt v = x; }
23973 : { v = x; cond-update-stmt }
23974 : { cond-update-stmt v = x; }
23975 : if (x == e) { x = d; } else { v = x; }
23976 : { r = x == e; if (r) { x = d; } }
23977 : { r = x == e; if (r) { x = d; } else { v = x; } }
23978 :
23979 : where x, r and v are lvalue expressions with scalar type,
23980 : expr, e and d are expressions with scalar type and e might be
23981 : the same as v.
23982 :
23983 : LOC is the location of the #pragma token. */
23984 :
23985 : static void
23986 1776 : c_parser_omp_atomic (location_t loc, c_parser *parser, bool openacc)
23987 : {
23988 1776 : tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE, r = NULL_TREE;
23989 1776 : tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
23990 1776 : tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
23991 1776 : enum tree_code code = ERROR_MARK, opcode = NOP_EXPR;
23992 1776 : enum omp_memory_order memory_order = OMP_MEMORY_ORDER_UNSPECIFIED;
23993 1776 : struct c_expr expr;
23994 1776 : location_t eloc;
23995 1776 : bool structured_block = false;
23996 1776 : bool swapped = false;
23997 1776 : bool non_lvalue_p;
23998 1776 : tree clauses = NULL_TREE;
23999 1776 : bool capture = false;
24000 1776 : bool compare = false;
24001 1776 : bool weak = false;
24002 1776 : enum omp_memory_order fail = OMP_MEMORY_ORDER_UNSPECIFIED;
24003 1776 : bool no_semicolon = false;
24004 1776 : bool extra_scope = false;
24005 :
24006 3312 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
24007 : {
24008 1546 : if (c_parser_next_token_is (parser, CPP_COMMA)
24009 1546 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
24010 82 : c_parser_consume_token (parser);
24011 :
24012 1546 : if (c_parser_next_token_is (parser, CPP_NAME))
24013 : {
24014 1542 : const char *p
24015 1542 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
24016 1542 : location_t cloc = c_parser_peek_token (parser)->location;
24017 1542 : enum tree_code new_code = ERROR_MARK;
24018 1542 : enum omp_memory_order new_memory_order
24019 : = OMP_MEMORY_ORDER_UNSPECIFIED;
24020 1542 : bool new_capture = false;
24021 1542 : bool new_compare = false;
24022 1542 : bool new_weak = false;
24023 1542 : enum omp_memory_order new_fail = OMP_MEMORY_ORDER_UNSPECIFIED;
24024 :
24025 1542 : if (!strcmp (p, "read"))
24026 : new_code = OMP_ATOMIC_READ;
24027 1271 : else if (!strcmp (p, "write"))
24028 : new_code = NOP_EXPR;
24029 1073 : else if (!strcmp (p, "update"))
24030 : new_code = OMP_ATOMIC;
24031 891 : else if (openacc && !strcmp (p, "capture"))
24032 : new_code = OMP_ATOMIC_CAPTURE_NEW;
24033 4 : else if (openacc)
24034 : {
24035 4 : p = NULL;
24036 4 : error_at (cloc, "expected %<read%>, %<write%>, %<update%>, "
24037 : "or %<capture%> clause");
24038 : }
24039 653 : else if (!strcmp (p, "capture"))
24040 : new_capture = true;
24041 408 : else if (!strcmp (p, "compare"))
24042 : new_compare = true;
24043 235 : else if (!strcmp (p, "weak"))
24044 : new_weak = true;
24045 222 : else if (!strcmp (p, "fail"))
24046 : {
24047 33 : matching_parens parens;
24048 :
24049 33 : c_parser_consume_token (parser);
24050 33 : if (!parens.require_open (parser))
24051 1 : continue;
24052 :
24053 32 : if (c_parser_next_token_is (parser, CPP_NAME))
24054 : {
24055 30 : const char *q
24056 30 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
24057 :
24058 30 : if (!strcmp (q, "seq_cst"))
24059 : new_fail = OMP_MEMORY_ORDER_SEQ_CST;
24060 24 : else if (!strcmp (q, "acquire"))
24061 : new_fail = OMP_MEMORY_ORDER_ACQUIRE;
24062 17 : else if (!strcmp (q, "relaxed"))
24063 : new_fail = OMP_MEMORY_ORDER_RELAXED;
24064 : }
24065 :
24066 : if (new_fail != OMP_MEMORY_ORDER_UNSPECIFIED)
24067 : {
24068 27 : c_parser_consume_token (parser);
24069 27 : if (fail != OMP_MEMORY_ORDER_UNSPECIFIED)
24070 2 : error_at (cloc, "too many %qs clauses", "fail");
24071 : else
24072 : fail = new_fail;
24073 : }
24074 : else
24075 5 : c_parser_error (parser, "expected %<seq_cst%>, %<acquire%> "
24076 : "or %<relaxed%>");
24077 32 : parens.skip_until_found_close (parser);
24078 32 : continue;
24079 32 : }
24080 189 : else if (!strcmp (p, "seq_cst"))
24081 : new_memory_order = OMP_MEMORY_ORDER_SEQ_CST;
24082 112 : else if (!strcmp (p, "acq_rel"))
24083 : new_memory_order = OMP_MEMORY_ORDER_ACQ_REL;
24084 100 : else if (!strcmp (p, "release"))
24085 : new_memory_order = OMP_MEMORY_ORDER_RELEASE;
24086 70 : else if (!strcmp (p, "acquire"))
24087 : new_memory_order = OMP_MEMORY_ORDER_ACQUIRE;
24088 57 : else if (!strcmp (p, "relaxed"))
24089 : new_memory_order = OMP_MEMORY_ORDER_RELAXED;
24090 31 : else if (!strcmp (p, "hint"))
24091 : {
24092 29 : c_parser_consume_token (parser);
24093 29 : clauses = c_parser_omp_clause_hint (parser, clauses);
24094 29 : continue;
24095 : }
24096 : else
24097 : {
24098 2 : p = NULL;
24099 2 : error_at (cloc, "expected %<read%>, %<write%>, %<update%>, "
24100 : "%<capture%>, %<compare%>, %<weak%>, %<fail%>, "
24101 : "%<seq_cst%>, %<acq_rel%>, %<release%>, "
24102 : "%<relaxed%> or %<hint%> clause");
24103 : }
24104 6 : if (p)
24105 : {
24106 1474 : if (new_code != ERROR_MARK)
24107 : {
24108 : /* OpenACC permits 'update capture'. */
24109 885 : if (openacc
24110 885 : && code == OMP_ATOMIC
24111 4 : && new_code == OMP_ATOMIC_CAPTURE_NEW)
24112 : code = new_code;
24113 882 : else if (code != ERROR_MARK)
24114 5 : error_at (cloc, "too many atomic clauses");
24115 : else
24116 : code = new_code;
24117 : }
24118 589 : else if (new_memory_order != OMP_MEMORY_ORDER_UNSPECIFIED)
24119 : {
24120 158 : if (memory_order != OMP_MEMORY_ORDER_UNSPECIFIED)
24121 35 : error_at (cloc, "too many memory order clauses");
24122 : else
24123 : memory_order = new_memory_order;
24124 : }
24125 431 : else if (new_capture)
24126 : {
24127 245 : if (capture)
24128 1 : error_at (cloc, "too many %qs clauses", "capture");
24129 : else
24130 : capture = true;
24131 : }
24132 186 : else if (new_compare)
24133 : {
24134 173 : if (compare)
24135 1 : error_at (cloc, "too many %qs clauses", "compare");
24136 : else
24137 : compare = true;
24138 : }
24139 13 : else if (new_weak)
24140 : {
24141 13 : if (weak)
24142 1 : error_at (cloc, "too many %qs clauses", "weak");
24143 : else
24144 : weak = true;
24145 : }
24146 1474 : c_parser_consume_token (parser);
24147 1474 : continue;
24148 : }
24149 : }
24150 : break;
24151 : }
24152 1776 : c_parser_skip_to_pragma_eol (parser);
24153 :
24154 1776 : if (code == ERROR_MARK)
24155 899 : code = OMP_ATOMIC;
24156 1776 : if (capture)
24157 : {
24158 244 : if (code != OMP_ATOMIC)
24159 2 : error_at (loc, "%qs clause is incompatible with %<read%> or %<write%> "
24160 : "clauses", "capture");
24161 : else
24162 : code = OMP_ATOMIC_CAPTURE_NEW;
24163 : }
24164 1776 : if (compare && code != OMP_ATOMIC && code != OMP_ATOMIC_CAPTURE_NEW)
24165 : {
24166 2 : error_at (loc, "%qs clause is incompatible with %<read%> or %<write%> "
24167 : "clauses", "compare");
24168 2 : compare = false;
24169 : }
24170 1776 : if (fail != OMP_MEMORY_ORDER_UNSPECIFIED && !compare)
24171 : {
24172 5 : error_at (loc, "%qs clause requires %qs clause", "fail", "compare");
24173 5 : fail = OMP_MEMORY_ORDER_UNSPECIFIED;
24174 : }
24175 1776 : if (weak && !compare)
24176 : {
24177 5 : error_at (loc, "%qs clause requires %qs clause", "weak", "compare");
24178 5 : weak = false;
24179 : }
24180 1776 : if (openacc)
24181 : memory_order = OMP_MEMORY_ORDER_RELAXED;
24182 1467 : else if (memory_order == OMP_MEMORY_ORDER_UNSPECIFIED)
24183 : {
24184 1344 : omp_requires_mask
24185 1344 : = (enum omp_requires) (omp_requires_mask
24186 : | OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED);
24187 1344 : switch ((enum omp_memory_order)
24188 : (omp_requires_mask & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER))
24189 : {
24190 : case OMP_MEMORY_ORDER_UNSPECIFIED:
24191 : case OMP_MEMORY_ORDER_RELAXED:
24192 : memory_order = OMP_MEMORY_ORDER_RELAXED;
24193 : break;
24194 : case OMP_MEMORY_ORDER_SEQ_CST:
24195 1776 : memory_order = OMP_MEMORY_ORDER_SEQ_CST;
24196 : break;
24197 4 : case OMP_MEMORY_ORDER_ACQUIRE:
24198 4 : if (code == NOP_EXPR) /* atomic write */
24199 : {
24200 1 : error_at (loc, "%<#pragma omp atomic write%> incompatible with "
24201 : "%<acquire%> clause implicitly provided by a "
24202 : "%<requires%> directive");
24203 1 : memory_order = OMP_MEMORY_ORDER_SEQ_CST;
24204 : }
24205 : else
24206 : memory_order = OMP_MEMORY_ORDER_ACQUIRE;
24207 : break;
24208 3 : case OMP_MEMORY_ORDER_RELEASE:
24209 3 : if (code == OMP_ATOMIC_READ)
24210 : {
24211 1 : error_at (loc, "%<#pragma omp atomic read%> incompatible with "
24212 : "%<release%> clause implicitly provided by a "
24213 : "%<requires%> directive");
24214 1 : memory_order = OMP_MEMORY_ORDER_SEQ_CST;
24215 : }
24216 : else
24217 : memory_order = OMP_MEMORY_ORDER_RELEASE;
24218 : break;
24219 9 : case OMP_MEMORY_ORDER_ACQ_REL:
24220 9 : switch (code)
24221 : {
24222 : case OMP_ATOMIC_READ:
24223 : memory_order = OMP_MEMORY_ORDER_ACQUIRE;
24224 : break;
24225 : case NOP_EXPR: /* atomic write */
24226 5 : memory_order = OMP_MEMORY_ORDER_RELEASE;
24227 : break;
24228 : default:
24229 1776 : memory_order = OMP_MEMORY_ORDER_ACQ_REL;
24230 : break;
24231 : }
24232 : break;
24233 0 : default:
24234 0 : gcc_unreachable ();
24235 : }
24236 : }
24237 : else
24238 123 : switch (code)
24239 : {
24240 25 : case OMP_ATOMIC_READ:
24241 25 : if (memory_order == OMP_MEMORY_ORDER_RELEASE)
24242 : {
24243 1 : error_at (loc, "%<#pragma omp atomic read%> incompatible with "
24244 : "%<release%> clause");
24245 1 : memory_order = OMP_MEMORY_ORDER_SEQ_CST;
24246 : }
24247 24 : else if (memory_order == OMP_MEMORY_ORDER_ACQ_REL)
24248 6 : memory_order = OMP_MEMORY_ORDER_ACQUIRE;
24249 : break;
24250 16 : case NOP_EXPR: /* atomic write */
24251 16 : if (memory_order == OMP_MEMORY_ORDER_ACQUIRE)
24252 : {
24253 1 : error_at (loc, "%<#pragma omp atomic write%> incompatible with "
24254 : "%<acquire%> clause");
24255 1 : memory_order = OMP_MEMORY_ORDER_SEQ_CST;
24256 : }
24257 15 : else if (memory_order == OMP_MEMORY_ORDER_ACQ_REL)
24258 5 : memory_order = OMP_MEMORY_ORDER_RELEASE;
24259 : break;
24260 : default:
24261 : break;
24262 : }
24263 1776 : if (fail != OMP_MEMORY_ORDER_UNSPECIFIED)
24264 20 : memory_order
24265 20 : = (enum omp_memory_order) (memory_order
24266 : | (fail << OMP_FAIL_MEMORY_ORDER_SHIFT));
24267 :
24268 1776 : switch (code)
24269 : {
24270 468 : case OMP_ATOMIC_READ:
24271 468 : case NOP_EXPR: /* atomic write */
24272 468 : v = c_parser_cast_expression (parser, NULL).value;
24273 468 : non_lvalue_p = !lvalue_p (v);
24274 468 : v = c_fully_fold (v, false, NULL, true);
24275 468 : if (v == error_mark_node)
24276 0 : goto saw_error;
24277 468 : if (non_lvalue_p)
24278 4 : v = non_lvalue (v);
24279 468 : loc = c_parser_peek_token (parser)->location;
24280 468 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
24281 0 : goto saw_error;
24282 468 : if (code == NOP_EXPR)
24283 : {
24284 197 : eloc = c_parser_peek_token (parser)->location;
24285 197 : expr = c_parser_expression (parser);
24286 197 : expr = default_function_array_read_conversion (eloc, expr);
24287 : /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
24288 : opcode. */
24289 197 : code = OMP_ATOMIC;
24290 197 : lhs = v;
24291 197 : v = NULL_TREE;
24292 197 : rhs = c_fully_fold (expr.value, false, NULL);
24293 197 : if (rhs == error_mark_node)
24294 0 : goto saw_error;
24295 : }
24296 : else
24297 : {
24298 271 : lhs = c_parser_cast_expression (parser, NULL).value;
24299 271 : non_lvalue_p = !lvalue_p (lhs);
24300 271 : lhs = c_fully_fold (lhs, false, NULL, true);
24301 271 : if (lhs == error_mark_node)
24302 0 : goto saw_error;
24303 271 : if (non_lvalue_p)
24304 2 : lhs = non_lvalue (lhs);
24305 : }
24306 468 : goto done;
24307 474 : case OMP_ATOMIC_CAPTURE_NEW:
24308 474 : if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
24309 : {
24310 314 : c_parser_consume_token (parser);
24311 314 : structured_block = true;
24312 : }
24313 160 : else if (compare
24314 189 : && c_parser_next_token_is_keyword (parser, RID_IF))
24315 : break;
24316 : else
24317 : {
24318 143 : v = c_parser_cast_expression (parser, NULL).value;
24319 143 : non_lvalue_p = !lvalue_p (v);
24320 143 : v = c_fully_fold (v, false, NULL, true);
24321 143 : if (v == error_mark_node)
24322 0 : goto saw_error;
24323 143 : if (non_lvalue_p)
24324 2 : v = non_lvalue (v);
24325 143 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
24326 0 : goto saw_error;
24327 155 : if (compare && c_parser_next_token_is_keyword (parser, RID_IF))
24328 : {
24329 1 : eloc = c_parser_peek_token (parser)->location;
24330 1 : error_at (eloc, "expected expression");
24331 1 : goto saw_error;
24332 : }
24333 : }
24334 : break;
24335 : default:
24336 : break;
24337 : }
24338 :
24339 : /* For structured_block case we don't know yet whether
24340 : old or new x should be captured. */
24341 1307 : restart:
24342 1699 : if (compare && c_parser_next_token_is_keyword (parser, RID_IF))
24343 : {
24344 85 : c_parser_consume_token (parser);
24345 :
24346 85 : matching_parens parens;
24347 85 : if (!parens.require_open (parser))
24348 33 : goto saw_error;
24349 84 : eloc = c_parser_peek_token (parser)->location;
24350 84 : c_expr cmp_expr;
24351 84 : if (r)
24352 : {
24353 17 : cmp_expr = c_parser_cast_expression (parser, NULL);
24354 17 : cmp_expr = default_function_array_conversion (eloc, cmp_expr);
24355 : }
24356 : else
24357 67 : cmp_expr = c_parser_binary_expression (parser, NULL, void_list_node);
24358 84 : parens.skip_until_found_close (parser);
24359 84 : if (cmp_expr.value == error_mark_node)
24360 0 : goto saw_error;
24361 84 : if (r)
24362 : {
24363 17 : if (!c_tree_equal (cmp_expr.value, unfolded_lhs))
24364 1 : goto bad_if;
24365 16 : cmp_expr.value = rhs1;
24366 16 : rhs1 = NULL_TREE;
24367 16 : gcc_assert (TREE_CODE (cmp_expr.value) == EQ_EXPR);
24368 : }
24369 83 : if (TREE_CODE (cmp_expr.value) == EQ_EXPR)
24370 : ;
24371 36 : else if (!structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
24372 : {
24373 2 : error_at (EXPR_LOC_OR_LOC (cmp_expr.value, eloc),
24374 : "expected %<==%> comparison in %<if%> condition");
24375 2 : goto saw_error;
24376 : }
24377 34 : else if (TREE_CODE (cmp_expr.value) != GT_EXPR
24378 25 : && TREE_CODE (cmp_expr.value) != LT_EXPR)
24379 : {
24380 10 : error_at (EXPR_LOC_OR_LOC (cmp_expr.value, eloc),
24381 : "expected %<==%>, %<<%> or %<>%> comparison in %<if%> "
24382 : "condition");
24383 10 : goto saw_error;
24384 : }
24385 71 : if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
24386 2 : goto saw_error;
24387 :
24388 69 : extra_scope = true;
24389 69 : eloc = c_parser_peek_token (parser)->location;
24390 69 : expr = c_parser_cast_expression (parser, NULL);
24391 69 : lhs = expr.value;
24392 69 : expr = default_function_array_conversion (eloc, expr);
24393 69 : unfolded_lhs = expr.value;
24394 69 : lhs = c_fully_fold (lhs, false, NULL, true);
24395 69 : orig_lhs = lhs;
24396 69 : if (lhs == error_mark_node)
24397 0 : goto saw_error;
24398 69 : if (!lvalue_p (unfolded_lhs))
24399 0 : lhs = non_lvalue (lhs);
24400 69 : if (!c_parser_next_token_is (parser, CPP_EQ))
24401 : {
24402 1 : c_parser_error (parser, "expected %<=%>");
24403 1 : goto saw_error;
24404 : }
24405 68 : c_parser_consume_token (parser);
24406 68 : eloc = c_parser_peek_token (parser)->location;
24407 68 : expr = c_parser_expr_no_commas (parser, NULL);
24408 68 : rhs1 = expr.value;
24409 :
24410 68 : if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
24411 1 : goto saw_error;
24412 :
24413 67 : if (!c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"))
24414 1 : goto saw_error;
24415 :
24416 66 : extra_scope = false;
24417 66 : no_semicolon = true;
24418 :
24419 66 : if (c_tree_equal (TREE_OPERAND (cmp_expr.value, 0), unfolded_lhs))
24420 : {
24421 59 : if (TREE_CODE (cmp_expr.value) == EQ_EXPR)
24422 : {
24423 44 : opcode = COND_EXPR;
24424 44 : rhs = c_fully_fold (TREE_OPERAND (cmp_expr.value, 1),
24425 : false, NULL, true);
24426 44 : rhs1 = c_fully_fold (rhs1, false, NULL, true);
24427 : }
24428 15 : else if (c_tree_equal (TREE_OPERAND (cmp_expr.value, 1), rhs1))
24429 : {
24430 7 : opcode = (TREE_CODE (cmp_expr.value) == GT_EXPR
24431 13 : ? MIN_EXPR : MAX_EXPR);
24432 13 : rhs = c_fully_fold (rhs1, false, NULL, true);
24433 13 : rhs1 = c_fully_fold (TREE_OPERAND (cmp_expr.value, 0),
24434 : false, NULL, true);
24435 : }
24436 : else
24437 2 : goto bad_if;
24438 : }
24439 7 : else if (TREE_CODE (cmp_expr.value) == EQ_EXPR)
24440 2 : goto bad_if;
24441 5 : else if (c_tree_equal (TREE_OPERAND (cmp_expr.value, 1), unfolded_lhs)
24442 5 : && c_tree_equal (TREE_OPERAND (cmp_expr.value, 0), rhs1))
24443 : {
24444 2 : opcode = (TREE_CODE (cmp_expr.value) == GT_EXPR
24445 3 : ? MAX_EXPR : MIN_EXPR);
24446 3 : rhs = c_fully_fold (rhs1, false, NULL, true);
24447 3 : rhs1 = c_fully_fold (TREE_OPERAND (cmp_expr.value, 1),
24448 : false, NULL, true);
24449 : }
24450 : else
24451 : {
24452 8 : bad_if:
24453 8 : c_parser_error (parser,
24454 : "invalid form of %<#pragma omp atomic compare%>");
24455 8 : goto saw_error;
24456 : }
24457 :
24458 60 : if (c_parser_next_token_is_keyword (parser, RID_ELSE))
24459 : {
24460 24 : if (code != OMP_ATOMIC_CAPTURE_NEW
24461 22 : || (structured_block && r == NULL_TREE)
24462 21 : || TREE_CODE (cmp_expr.value) != EQ_EXPR)
24463 : {
24464 3 : eloc = c_parser_peek_token (parser)->location;
24465 3 : error_at (eloc, "unexpected %<else%>");
24466 3 : goto saw_error;
24467 : }
24468 :
24469 21 : c_parser_consume_token (parser);
24470 :
24471 21 : if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
24472 1 : goto saw_error;
24473 :
24474 20 : extra_scope = true;
24475 20 : v = c_parser_cast_expression (parser, NULL).value;
24476 20 : non_lvalue_p = !lvalue_p (v);
24477 20 : v = c_fully_fold (v, false, NULL, true);
24478 20 : if (v == error_mark_node)
24479 0 : goto saw_error;
24480 20 : if (non_lvalue_p)
24481 0 : v = non_lvalue (v);
24482 20 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
24483 1 : goto saw_error;
24484 :
24485 19 : expr = c_parser_expr_no_commas (parser, NULL);
24486 :
24487 19 : if (!c_tree_equal (expr.value, unfolded_lhs))
24488 1 : goto bad_if;
24489 :
24490 18 : if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
24491 1 : goto saw_error;
24492 :
24493 17 : if (!c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"))
24494 0 : goto saw_error;
24495 :
24496 17 : extra_scope = false;
24497 17 : code = OMP_ATOMIC_CAPTURE_OLD;
24498 17 : if (r == NULL_TREE)
24499 : /* Signal to c_finish_omp_atomic that in
24500 : if (x == e) { x = d; } else { v = x; }
24501 : case the store to v should be conditional. */
24502 10 : r = void_list_node;
24503 : }
24504 36 : else if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
24505 : {
24506 1 : c_parser_require_keyword (parser, RID_ELSE, "expected %<else%>");
24507 1 : goto saw_error;
24508 : }
24509 35 : else if (code == OMP_ATOMIC_CAPTURE_NEW
24510 35 : && r != NULL_TREE
24511 9 : && v == NULL_TREE)
24512 52 : code = OMP_ATOMIC;
24513 52 : goto stmt_done;
24514 : }
24515 1406 : eloc = c_parser_peek_token (parser)->location;
24516 1406 : expr = c_parser_cast_expression (parser, NULL);
24517 1406 : lhs = expr.value;
24518 1406 : expr = default_function_array_conversion (eloc, expr);
24519 1406 : unfolded_lhs = expr.value;
24520 1406 : lhs = c_fully_fold (lhs, false, NULL, true);
24521 1406 : orig_lhs = lhs;
24522 1406 : switch (TREE_CODE (lhs))
24523 : {
24524 4 : invalid_compare:
24525 4 : error_at (eloc, "invalid form of %<pragma omp atomic compare%>");
24526 : /* FALLTHRU */
24527 84 : case ERROR_MARK:
24528 84 : saw_error:
24529 84 : c_parser_skip_to_end_of_block_or_statement (parser);
24530 90 : if (extra_scope && c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
24531 4 : c_parser_consume_token (parser);
24532 84 : if (structured_block)
24533 : {
24534 10 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
24535 9 : c_parser_consume_token (parser);
24536 1 : else if (code == OMP_ATOMIC_CAPTURE_NEW)
24537 : {
24538 1 : c_parser_skip_to_end_of_block_or_statement (parser);
24539 1 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
24540 1 : c_parser_consume_token (parser);
24541 : }
24542 : }
24543 84 : return;
24544 :
24545 181 : case POSTINCREMENT_EXPR:
24546 181 : if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
24547 21 : code = OMP_ATOMIC_CAPTURE_OLD;
24548 : /* FALLTHROUGH */
24549 243 : case PREINCREMENT_EXPR:
24550 243 : lhs = TREE_OPERAND (lhs, 0);
24551 243 : unfolded_lhs = NULL_TREE;
24552 243 : opcode = PLUS_EXPR;
24553 243 : rhs = integer_one_node;
24554 243 : if (compare)
24555 2 : goto invalid_compare;
24556 : break;
24557 :
24558 24 : case POSTDECREMENT_EXPR:
24559 24 : if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
24560 2 : code = OMP_ATOMIC_CAPTURE_OLD;
24561 : /* FALLTHROUGH */
24562 52 : case PREDECREMENT_EXPR:
24563 52 : lhs = TREE_OPERAND (lhs, 0);
24564 52 : unfolded_lhs = NULL_TREE;
24565 52 : opcode = MINUS_EXPR;
24566 52 : rhs = integer_one_node;
24567 52 : if (compare)
24568 2 : goto invalid_compare;
24569 : break;
24570 :
24571 12 : case COMPOUND_EXPR:
24572 12 : if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
24573 12 : && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
24574 12 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
24575 12 : && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
24576 24 : && C_BOOLEAN_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
24577 : (TREE_OPERAND (lhs, 1), 0), 0))))
24578 : /* Undo effects of boolean_increment for post {in,de}crement. */
24579 12 : lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
24580 : /* FALLTHRU */
24581 24 : case MODIFY_EXPR:
24582 24 : if (TREE_CODE (lhs) == MODIFY_EXPR
24583 24 : && C_BOOLEAN_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0))))
24584 : {
24585 : /* Undo effects of boolean_increment. */
24586 24 : if (integer_onep (TREE_OPERAND (lhs, 1)))
24587 : {
24588 : /* This is pre or post increment. */
24589 12 : rhs = TREE_OPERAND (lhs, 1);
24590 12 : lhs = TREE_OPERAND (lhs, 0);
24591 12 : unfolded_lhs = NULL_TREE;
24592 12 : opcode = NOP_EXPR;
24593 12 : if (code == OMP_ATOMIC_CAPTURE_NEW
24594 12 : && !structured_block
24595 2 : && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
24596 1 : code = OMP_ATOMIC_CAPTURE_OLD;
24597 12 : if (compare)
24598 0 : goto invalid_compare;
24599 : break;
24600 : }
24601 12 : if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
24602 12 : && TREE_OPERAND (lhs, 0)
24603 12 : == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
24604 : {
24605 : /* This is pre or post decrement. */
24606 12 : rhs = TREE_OPERAND (lhs, 1);
24607 12 : lhs = TREE_OPERAND (lhs, 0);
24608 12 : unfolded_lhs = NULL_TREE;
24609 12 : opcode = NOP_EXPR;
24610 12 : if (code == OMP_ATOMIC_CAPTURE_NEW
24611 12 : && !structured_block
24612 2 : && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
24613 1 : code = OMP_ATOMIC_CAPTURE_OLD;
24614 12 : if (compare)
24615 0 : goto invalid_compare;
24616 : break;
24617 : }
24618 : }
24619 : /* FALLTHRU */
24620 1083 : default:
24621 1083 : if (!lvalue_p (unfolded_lhs))
24622 5 : lhs = non_lvalue (lhs);
24623 1202 : if (compare && !c_parser_next_token_is (parser, CPP_EQ))
24624 : {
24625 7 : c_parser_error (parser, "expected %<=%>");
24626 7 : goto saw_error;
24627 : }
24628 1076 : switch (c_parser_peek_token (parser)->type)
24629 : {
24630 : case CPP_MULT_EQ:
24631 : opcode = MULT_EXPR;
24632 : break;
24633 : case CPP_DIV_EQ:
24634 : opcode = TRUNC_DIV_EXPR;
24635 : break;
24636 : case CPP_PLUS_EQ:
24637 : opcode = PLUS_EXPR;
24638 : break;
24639 : case CPP_MINUS_EQ:
24640 : opcode = MINUS_EXPR;
24641 : break;
24642 : case CPP_LSHIFT_EQ:
24643 : opcode = LSHIFT_EXPR;
24644 : break;
24645 : case CPP_RSHIFT_EQ:
24646 : opcode = RSHIFT_EXPR;
24647 : break;
24648 : case CPP_AND_EQ:
24649 : opcode = BIT_AND_EXPR;
24650 : break;
24651 : case CPP_OR_EQ:
24652 : opcode = BIT_IOR_EXPR;
24653 : break;
24654 : case CPP_XOR_EQ:
24655 : opcode = BIT_XOR_EXPR;
24656 : break;
24657 556 : case CPP_EQ:
24658 556 : c_parser_consume_token (parser);
24659 556 : eloc = c_parser_peek_token (parser)->location;
24660 556 : expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
24661 556 : rhs1 = expr.value;
24662 556 : switch (TREE_CODE (rhs1))
24663 : {
24664 289 : case MULT_EXPR:
24665 289 : case TRUNC_DIV_EXPR:
24666 289 : case RDIV_EXPR:
24667 289 : case PLUS_EXPR:
24668 289 : case MINUS_EXPR:
24669 289 : case LSHIFT_EXPR:
24670 289 : case RSHIFT_EXPR:
24671 289 : case BIT_AND_EXPR:
24672 289 : case BIT_IOR_EXPR:
24673 289 : case BIT_XOR_EXPR:
24674 289 : if (compare)
24675 : break;
24676 282 : if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
24677 : {
24678 147 : opcode = TREE_CODE (rhs1);
24679 147 : rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
24680 : true);
24681 147 : rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
24682 : true);
24683 147 : goto stmt_done;
24684 : }
24685 135 : if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
24686 : {
24687 117 : opcode = TREE_CODE (rhs1);
24688 117 : rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
24689 : true);
24690 117 : rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
24691 : true);
24692 117 : swapped = !commutative_tree_code (opcode);
24693 117 : goto stmt_done;
24694 : }
24695 : break;
24696 69 : case COND_EXPR:
24697 69 : if (!compare)
24698 : break;
24699 66 : if (TREE_CODE (TREE_OPERAND (rhs1, 0)) != GT_EXPR
24700 44 : && TREE_CODE (TREE_OPERAND (rhs1, 0)) != LT_EXPR
24701 97 : && TREE_CODE (TREE_OPERAND (rhs1, 0)) != EQ_EXPR)
24702 : break;
24703 63 : if (!TREE_OPERAND (rhs1, 1))
24704 : break;
24705 63 : if (!c_tree_equal (TREE_OPERAND (rhs1, 2), unfolded_lhs))
24706 : break;
24707 58 : if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0),
24708 : unfolded_lhs))
24709 : {
24710 39 : if (TREE_CODE (TREE_OPERAND (rhs1, 0)) == EQ_EXPR)
24711 : {
24712 23 : opcode = COND_EXPR;
24713 23 : rhs = c_fully_fold (TREE_OPERAND (TREE_OPERAND (rhs1,
24714 : 0), 1),
24715 : false, NULL, true);
24716 23 : rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false,
24717 : NULL, true);
24718 23 : goto stmt_done;
24719 : }
24720 16 : if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1),
24721 16 : TREE_OPERAND (rhs1, 1)))
24722 : {
24723 21 : opcode = (TREE_CODE (TREE_OPERAND (rhs1, 0)) == GT_EXPR
24724 14 : ? MIN_EXPR : MAX_EXPR);
24725 14 : rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
24726 : true);
24727 14 : rhs1 = c_fully_fold (TREE_OPERAND (TREE_OPERAND (rhs1,
24728 : 0), 0),
24729 : false, NULL, true);
24730 14 : goto stmt_done;
24731 : }
24732 : }
24733 19 : else if (TREE_CODE (TREE_OPERAND (rhs1, 0)) == EQ_EXPR)
24734 : break;
24735 17 : else if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1),
24736 : unfolded_lhs))
24737 : {
24738 15 : if (c_tree_equal (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0),
24739 15 : TREE_OPERAND (rhs1, 1)))
24740 : {
24741 18 : opcode = (TREE_CODE (TREE_OPERAND (rhs1, 0)) == GT_EXPR
24742 15 : ? MAX_EXPR : MIN_EXPR);
24743 15 : rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
24744 : true);
24745 15 : rhs1 = c_fully_fold (TREE_OPERAND (TREE_OPERAND (rhs1,
24746 : 0), 1),
24747 : false, NULL, true);
24748 15 : goto stmt_done;
24749 : }
24750 : }
24751 : break;
24752 17 : case EQ_EXPR:
24753 17 : if (!compare
24754 17 : || code != OMP_ATOMIC_CAPTURE_NEW
24755 17 : || !structured_block
24756 17 : || v
24757 17 : || r)
24758 : break;
24759 17 : if (c_parser_next_token_is (parser, CPP_SEMICOLON)
24760 17 : && c_parser_peek_2nd_token (parser)->keyword == RID_IF)
24761 : {
24762 17 : r = lhs;
24763 17 : lhs = NULL_TREE;
24764 17 : c_parser_consume_token (parser);
24765 17 : goto restart;
24766 : }
24767 : break;
24768 0 : case ERROR_MARK:
24769 0 : goto saw_error;
24770 : default:
24771 : break;
24772 : }
24773 223 : if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
24774 : {
24775 223 : if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
24776 : {
24777 167 : code = OMP_ATOMIC_CAPTURE_OLD;
24778 167 : v = lhs;
24779 167 : lhs = NULL_TREE;
24780 167 : expr = default_function_array_read_conversion (eloc, expr);
24781 167 : unfolded_lhs1 = expr.value;
24782 167 : lhs1 = c_fully_fold (unfolded_lhs1, false, NULL, true);
24783 167 : rhs1 = NULL_TREE;
24784 167 : c_parser_consume_token (parser);
24785 167 : goto restart;
24786 : }
24787 56 : if (structured_block && !compare)
24788 : {
24789 26 : opcode = NOP_EXPR;
24790 26 : expr = default_function_array_read_conversion (eloc, expr);
24791 26 : rhs = c_fully_fold (expr.value, false, NULL, true);
24792 26 : rhs1 = NULL_TREE;
24793 26 : goto stmt_done;
24794 : }
24795 : }
24796 30 : c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
24797 30 : goto saw_error;
24798 5 : default:
24799 5 : c_parser_error (parser,
24800 : "invalid operator for %<#pragma omp atomic%>");
24801 5 : goto saw_error;
24802 : }
24803 :
24804 : /* Arrange to pass the location of the assignment operator to
24805 : c_finish_omp_atomic. */
24806 515 : loc = c_parser_peek_token (parser)->location;
24807 515 : c_parser_consume_token (parser);
24808 515 : eloc = c_parser_peek_token (parser)->location;
24809 515 : expr = c_parser_expression (parser);
24810 515 : expr = default_function_array_read_conversion (eloc, expr);
24811 515 : rhs = expr.value;
24812 515 : rhs = c_fully_fold (rhs, false, NULL, true);
24813 515 : break;
24814 : }
24815 1224 : stmt_done:
24816 1224 : if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW && r == NULL_TREE)
24817 : {
24818 129 : if (!no_semicolon
24819 129 : && !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
24820 0 : goto saw_error;
24821 129 : no_semicolon = false;
24822 129 : v = c_parser_cast_expression (parser, NULL).value;
24823 129 : non_lvalue_p = !lvalue_p (v);
24824 129 : v = c_fully_fold (v, false, NULL, true);
24825 129 : if (v == error_mark_node)
24826 0 : goto saw_error;
24827 129 : if (non_lvalue_p)
24828 2 : v = non_lvalue (v);
24829 129 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
24830 0 : goto saw_error;
24831 129 : eloc = c_parser_peek_token (parser)->location;
24832 129 : expr = c_parser_cast_expression (parser, NULL);
24833 129 : lhs1 = expr.value;
24834 129 : expr = default_function_array_read_conversion (eloc, expr);
24835 129 : unfolded_lhs1 = expr.value;
24836 129 : lhs1 = c_fully_fold (lhs1, false, NULL, true);
24837 129 : if (lhs1 == error_mark_node)
24838 0 : goto saw_error;
24839 129 : if (!lvalue_p (unfolded_lhs1))
24840 2 : lhs1 = non_lvalue (lhs1);
24841 : }
24842 1224 : if (structured_block)
24843 : {
24844 304 : if (!no_semicolon)
24845 280 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
24846 304 : c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
24847 : }
24848 920 : done:
24849 1692 : if (weak && opcode != COND_EXPR)
24850 : {
24851 1 : error_at (loc, "%<weak%> clause requires atomic equality comparison");
24852 1 : weak = false;
24853 : }
24854 1692 : if (unfolded_lhs && unfolded_lhs1
24855 1692 : && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
24856 : {
24857 5 : error ("%<#pragma omp atomic capture%> uses two different "
24858 : "expressions for memory");
24859 5 : stmt = error_mark_node;
24860 : }
24861 : else
24862 1687 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, r,
24863 : swapped, memory_order, weak);
24864 1692 : if (stmt != error_mark_node)
24865 1662 : add_stmt (stmt);
24866 :
24867 1692 : if (!structured_block && !no_semicolon)
24868 1369 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
24869 : }
24870 :
24871 :
24872 : /* OpenMP 2.5:
24873 : # pragma omp barrier new-line
24874 : */
24875 :
24876 : static void
24877 362 : c_parser_omp_barrier (c_parser *parser)
24878 : {
24879 362 : location_t loc = c_parser_peek_token (parser)->location;
24880 362 : c_parser_consume_pragma (parser);
24881 362 : c_parser_skip_to_pragma_eol (parser);
24882 :
24883 362 : c_finish_omp_barrier (loc);
24884 362 : }
24885 :
24886 : /* OpenMP 2.5:
24887 : # pragma omp critical [(name)] new-line
24888 : structured-block
24889 :
24890 : OpenMP 4.5:
24891 : # pragma omp critical [(name) [hint(expression)]] new-line
24892 :
24893 : LOC is the location of the #pragma itself. */
24894 :
24895 : #define OMP_CRITICAL_CLAUSE_MASK \
24896 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
24897 :
24898 : static tree
24899 144 : c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p)
24900 : {
24901 144 : tree stmt, name = NULL_TREE, clauses = NULL_TREE;
24902 :
24903 144 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
24904 : {
24905 49 : c_parser_consume_token (parser);
24906 49 : if (c_parser_next_token_is (parser, CPP_NAME))
24907 : {
24908 48 : name = c_parser_peek_token (parser)->value;
24909 48 : c_parser_consume_token (parser);
24910 48 : c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
24911 : }
24912 : else
24913 1 : c_parser_error (parser, "expected identifier");
24914 :
24915 49 : if (c_parser_next_token_is (parser, CPP_COMMA)
24916 49 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
24917 4 : c_parser_consume_token (parser);
24918 : }
24919 144 : clauses = c_parser_omp_all_clauses (parser, OMP_CRITICAL_CLAUSE_MASK,
24920 : "#pragma omp critical");
24921 144 : stmt = c_parser_omp_structured_block (parser, if_p);
24922 144 : return c_finish_omp_critical (loc, stmt, name, clauses);
24923 : }
24924 :
24925 : /* OpenMP 5.0:
24926 : # pragma omp depobj ( depobj ) depobj-clause new-line
24927 :
24928 : depobj-clause:
24929 : depend (dependence-type : locator)
24930 : destroy
24931 : update (dependence-type)
24932 :
24933 : OpenMP 5.2 additionally:
24934 : destroy ( depobj )
24935 :
24936 : dependence-type:
24937 : in
24938 : out
24939 : inout
24940 : mutexinout */
24941 :
24942 : static void
24943 75 : c_parser_omp_depobj (c_parser *parser)
24944 : {
24945 75 : location_t loc = c_parser_peek_token (parser)->location;
24946 75 : c_parser_consume_pragma (parser);
24947 75 : matching_parens parens;
24948 75 : if (!parens.require_open (parser))
24949 : {
24950 3 : c_parser_skip_to_pragma_eol (parser);
24951 3 : return;
24952 : }
24953 :
24954 72 : tree depobj = c_parser_expr_no_commas (parser, NULL).value;
24955 72 : if (depobj != error_mark_node)
24956 : {
24957 71 : if (!lvalue_p (depobj))
24958 : {
24959 1 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
24960 : "%<depobj%> expression is not lvalue expression");
24961 1 : depobj = error_mark_node;
24962 : }
24963 : else
24964 : {
24965 70 : tree addr = build_unary_op (EXPR_LOC_OR_LOC (depobj, loc), ADDR_EXPR,
24966 : depobj, false);
24967 70 : if (addr == error_mark_node)
24968 : depobj = error_mark_node;
24969 : else
24970 70 : depobj = build_indirect_ref (EXPR_LOC_OR_LOC (depobj, loc),
24971 : addr, RO_UNARY_STAR);
24972 : }
24973 : }
24974 :
24975 72 : parens.skip_until_found_close (parser);
24976 72 : tree clause = NULL_TREE;
24977 72 : enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INVALID;
24978 72 : if (c_parser_next_token_is (parser, CPP_COMMA))
24979 3 : c_parser_consume_token (parser);
24980 72 : location_t c_loc = c_parser_peek_token (parser)->location;
24981 72 : if (c_parser_next_token_is (parser, CPP_NAME))
24982 : {
24983 71 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
24984 :
24985 71 : c_parser_consume_token (parser);
24986 71 : if (!strcmp ("depend", p))
24987 : {
24988 38 : clause = c_parser_omp_clause_depend (parser, NULL_TREE, c_loc);
24989 38 : clause = c_finish_omp_clauses (clause, C_ORT_OMP);
24990 38 : if (!clause)
24991 2 : clause = error_mark_node;
24992 : }
24993 33 : else if (!strcmp ("destroy", p))
24994 : {
24995 22 : matching_parens c_parens;
24996 22 : kind = OMP_CLAUSE_DEPEND_LAST;
24997 22 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
24998 22 : && c_parens.require_open (parser))
24999 : {
25000 7 : tree destobj = c_parser_expr_no_commas (parser, NULL).value;
25001 7 : if (!lvalue_p (destobj))
25002 1 : error_at (EXPR_LOC_OR_LOC (destobj, c_loc),
25003 : "%<destroy%> expression is not lvalue expression");
25004 6 : else if (depobj != error_mark_node
25005 6 : && !operand_equal_p (destobj, depobj,
25006 : OEP_MATCH_SIDE_EFFECTS
25007 : | OEP_LEXICOGRAPHIC))
25008 2 : warning_at (EXPR_LOC_OR_LOC (destobj, c_loc), OPT_Wopenmp,
25009 : "the %<destroy%> expression %qE should be the same "
25010 : "as the %<depobj%> argument %qE", destobj, depobj);
25011 7 : c_parens.skip_until_found_close (parser);
25012 : }
25013 : }
25014 11 : else if (!strcmp ("update", p))
25015 : {
25016 10 : matching_parens c_parens;
25017 10 : if (c_parens.require_open (parser))
25018 : {
25019 10 : location_t c2_loc = c_parser_peek_token (parser)->location;
25020 10 : if (c_parser_next_token_is (parser, CPP_NAME))
25021 : {
25022 10 : const char *p2
25023 10 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
25024 :
25025 10 : c_parser_consume_token (parser);
25026 10 : if (!strcmp ("in", p2))
25027 : kind = OMP_CLAUSE_DEPEND_IN;
25028 8 : else if (!strcmp ("out", p2))
25029 : kind = OMP_CLAUSE_DEPEND_OUT;
25030 7 : else if (!strcmp ("inout", p2))
25031 : kind = OMP_CLAUSE_DEPEND_INOUT;
25032 4 : else if (!strcmp ("mutexinoutset", p2))
25033 : kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
25034 3 : else if (!strcmp ("inoutset", p2))
25035 : kind = OMP_CLAUSE_DEPEND_INOUTSET;
25036 : }
25037 : if (kind == OMP_CLAUSE_DEPEND_INVALID)
25038 : {
25039 1 : clause = error_mark_node;
25040 1 : error_at (c2_loc, "expected %<in%>, %<out%>, %<inout%>, "
25041 : "%<mutexinoutset%> or %<inoutset%>");
25042 : }
25043 10 : c_parens.skip_until_found_close (parser);
25044 : }
25045 : else
25046 0 : clause = error_mark_node;
25047 : }
25048 : }
25049 72 : if (!clause && kind == OMP_CLAUSE_DEPEND_INVALID)
25050 : {
25051 2 : clause = error_mark_node;
25052 2 : error_at (c_loc, "expected %<depend%>, %<destroy%> or %<update%> clause");
25053 : }
25054 72 : c_parser_skip_to_pragma_eol (parser);
25055 :
25056 72 : c_finish_omp_depobj (loc, depobj, kind, clause);
25057 : }
25058 :
25059 :
25060 : /* OpenMP 2.5:
25061 : # pragma omp flush flush-vars[opt] new-line
25062 :
25063 : flush-vars:
25064 : ( variable-list )
25065 :
25066 : OpenMP 5.0:
25067 : # pragma omp flush memory-order-clause new-line */
25068 :
25069 : static void
25070 59 : c_parser_omp_flush (c_parser *parser)
25071 : {
25072 59 : location_t loc = c_parser_peek_token (parser)->location;
25073 59 : c_parser_consume_pragma (parser);
25074 59 : enum memmodel mo = MEMMODEL_LAST;
25075 59 : if (c_parser_next_token_is (parser, CPP_COMMA)
25076 59 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
25077 8 : c_parser_consume_token (parser);
25078 59 : if (c_parser_next_token_is (parser, CPP_NAME))
25079 : {
25080 27 : const char *p
25081 27 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
25082 :
25083 27 : if (!strcmp (p, "seq_cst"))
25084 : mo = MEMMODEL_SEQ_CST;
25085 21 : else if (!strcmp (p, "acq_rel"))
25086 : mo = MEMMODEL_ACQ_REL;
25087 15 : else if (!strcmp (p, "release"))
25088 : mo = MEMMODEL_RELEASE;
25089 9 : else if (!strcmp (p, "acquire"))
25090 : mo = MEMMODEL_ACQUIRE;
25091 : else
25092 3 : error_at (c_parser_peek_token (parser)->location,
25093 : "expected %<seq_cst%>, %<acq_rel%>, %<release%> or "
25094 : "%<acquire%>");
25095 27 : c_parser_consume_token (parser);
25096 : }
25097 59 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
25098 : {
25099 20 : if (mo != MEMMODEL_LAST)
25100 4 : error_at (c_parser_peek_token (parser)->location,
25101 : "%<flush%> list specified together with memory order "
25102 : "clause");
25103 20 : c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
25104 : }
25105 39 : else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
25106 1 : c_parser_error (parser, "expected %<(%> or end of line");
25107 59 : c_parser_skip_to_pragma_eol (parser);
25108 :
25109 59 : c_finish_omp_flush (loc, mo);
25110 59 : }
25111 :
25112 : /* Return true if next tokens contain a standard attribute that contains
25113 : omp::directive (DIRECTIVE). */
25114 :
25115 : static bool
25116 365 : c_parser_omp_section_scan (c_parser *parser, const char *directive,
25117 : bool tentative)
25118 : {
25119 365 : if (!c_parser_nth_token_starts_std_attributes (parser, 1))
25120 : return false;
25121 36 : unsigned int n = 3;
25122 36 : if (!c_parser_check_balanced_raw_token_sequence (parser, &n))
25123 : return false;
25124 36 : c_token *token = c_parser_peek_nth_token_raw (parser, n);
25125 36 : if (token->type != CPP_CLOSE_SQUARE)
25126 : return false;
25127 36 : token = c_parser_peek_nth_token_raw (parser, n + 1);
25128 36 : if (token->type != CPP_CLOSE_SQUARE)
25129 : return false;
25130 36 : if (n < 9)
25131 : return false;
25132 35 : if (c_parser_peek_nth_token_raw (parser, 3)->type == CPP_NAME
25133 35 : && c_parser_peek_nth_token_raw (parser, 4)->type == CPP_OPEN_PAREN
25134 35 : && c_parser_peek_nth_token_raw (parser, 5)->type == CPP_NAME)
25135 : {
25136 0 : tree first = c_parser_peek_nth_token_raw (parser, 3)->value;
25137 0 : tree second = c_parser_peek_nth_token_raw (parser, 5)->value;
25138 0 : if (strcmp (IDENTIFIER_POINTER (first), "directive")
25139 0 : && strcmp (IDENTIFIER_POINTER (first), "__directive__"))
25140 : return false;
25141 0 : if (strcmp (IDENTIFIER_POINTER (second), directive))
25142 : return false;
25143 : }
25144 35 : if (tentative)
25145 : return true;
25146 32 : location_t first_loc = c_parser_peek_token (parser)->location;
25147 32 : location_t last_loc = c_parser_peek_nth_token_raw (parser, n + 1)->location;
25148 32 : location_t middle_loc = UNKNOWN_LOCATION;
25149 32 : tree std_attrs = c_parser_std_attribute_specifier_sequence (parser);
25150 32 : bool seen = false;
25151 32 : int cnt = 0;
25152 67 : for (tree attr = std_attrs; attr; attr = TREE_CHAIN (attr))
25153 35 : if (is_attribute_namespace_p ("omp", attr)
25154 35 : && is_attribute_p ("directive", get_attribute_name (attr)))
25155 : {
25156 68 : for (tree a = TREE_VALUE (attr); a; a = TREE_CHAIN (a))
25157 : {
25158 36 : tree d = TREE_VALUE (a);
25159 36 : gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
25160 36 : c_token *first = C_TOKEN_VEC_TOKENS (d)->address ();
25161 36 : cnt++;
25162 36 : if (first->type == CPP_NAME
25163 36 : && strcmp (IDENTIFIER_POINTER (first->value),
25164 : directive) == 0)
25165 : {
25166 31 : seen = true;
25167 31 : if (middle_loc == UNKNOWN_LOCATION)
25168 31 : middle_loc = first->location;
25169 : }
25170 : }
25171 : }
25172 32 : if (!seen)
25173 : return false;
25174 31 : if (cnt != 1 || TREE_CHAIN (std_attrs))
25175 : {
25176 7 : error_at (make_location (first_loc, last_loc, middle_loc),
25177 : "%<[[omp::directive(%s)]]%> must be the only specified "
25178 : "attribute on a statement", directive);
25179 7 : return false;
25180 : }
25181 24 : c_parser_handle_statement_omp_attributes (parser, std_attrs, NULL);
25182 24 : return true;
25183 : }
25184 :
25185 : /* Parse an OpenMP structured block sequence. KIND is the corresponding
25186 : separating directive. */
25187 :
25188 : static tree
25189 823 : c_parser_omp_structured_block_sequence (c_parser *parser,
25190 : enum pragma_kind kind)
25191 : {
25192 823 : tree stmt = push_stmt_list ();
25193 823 : c_parser_statement (parser, NULL);
25194 917 : do
25195 : {
25196 870 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
25197 : break;
25198 464 : if (c_parser_next_token_is (parser, CPP_EOF))
25199 : break;
25200 :
25201 464 : if (kind != PRAGMA_NONE
25202 464 : && c_parser_peek_token (parser)->pragma_kind == kind)
25203 : break;
25204 :
25205 69 : if (kind != PRAGMA_NONE
25206 104 : && c_parser_omp_section_scan (parser,
25207 : kind == PRAGMA_OMP_SCAN
25208 : ? "scan" : "section", false))
25209 : break;
25210 :
25211 47 : c_parser_statement (parser, NULL);
25212 : }
25213 : while (1);
25214 823 : return pop_stmt_list (stmt);
25215 : }
25216 :
25217 : /* OpenMP 5.0:
25218 :
25219 : scan-loop-body:
25220 : { structured-block scan-directive structured-block } */
25221 :
25222 : static void
25223 267 : c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
25224 : {
25225 267 : tree substmt;
25226 267 : location_t loc;
25227 267 : tree clauses = NULL_TREE;
25228 267 : bool found_scan = false;
25229 :
25230 267 : loc = c_parser_peek_token (parser)->location;
25231 267 : if (!open_brace_parsed
25232 267 : && !c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
25233 : {
25234 : /* Avoid skipping until the end of the block. */
25235 1 : parser->error = false;
25236 1 : return;
25237 : }
25238 :
25239 266 : if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SCAN)
25240 264 : substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_OMP_SCAN);
25241 : else
25242 : {
25243 2 : warning_at (c_parser_peek_token (parser)->location, OPT_Wopenmp,
25244 : "%<#pragma omp scan%> with zero preceding executable "
25245 : "statements");
25246 2 : substmt = build_empty_stmt (loc);
25247 : }
25248 266 : substmt = build2 (OMP_SCAN, void_type_node, substmt, NULL_TREE);
25249 266 : SET_EXPR_LOCATION (substmt, loc);
25250 266 : add_stmt (substmt);
25251 :
25252 266 : loc = c_parser_peek_token (parser)->location;
25253 266 : if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SCAN)
25254 : {
25255 259 : enum omp_clause_code clause = OMP_CLAUSE_ERROR;
25256 259 : found_scan = true;
25257 :
25258 259 : c_parser_consume_pragma (parser);
25259 :
25260 259 : if (c_parser_next_token_is (parser, CPP_COMMA))
25261 4 : c_parser_consume_token (parser);
25262 :
25263 259 : if (c_parser_next_token_is (parser, CPP_NAME))
25264 : {
25265 257 : const char *p
25266 257 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
25267 257 : if (strcmp (p, "inclusive") == 0)
25268 : clause = OMP_CLAUSE_INCLUSIVE;
25269 126 : else if (strcmp (p, "exclusive") == 0)
25270 : clause = OMP_CLAUSE_EXCLUSIVE;
25271 : }
25272 : if (clause != OMP_CLAUSE_ERROR)
25273 : {
25274 257 : c_parser_consume_token (parser);
25275 257 : clauses = c_parser_omp_var_list_parens (parser, clause, NULL_TREE);
25276 : }
25277 : else
25278 2 : c_parser_error (parser, "expected %<inclusive%> or "
25279 : "%<exclusive%> clause");
25280 259 : c_parser_skip_to_pragma_eol (parser);
25281 : }
25282 : else
25283 7 : error ("expected %<#pragma omp scan%>");
25284 :
25285 266 : clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
25286 266 : if (!c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
25287 257 : substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_NONE);
25288 : else
25289 : {
25290 9 : if (found_scan)
25291 2 : warning_at (loc, OPT_Wopenmp,
25292 : "%<#pragma omp scan%> with zero succeeding executable "
25293 : "statements");
25294 9 : substmt = build_empty_stmt (loc);
25295 : }
25296 266 : substmt = build2 (OMP_SCAN, void_type_node, substmt, clauses);
25297 266 : SET_EXPR_LOCATION (substmt, loc);
25298 266 : add_stmt (substmt);
25299 :
25300 266 : c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
25301 : "expected %<}%>");
25302 : }
25303 :
25304 :
25305 : /* Check if the next tokens can start a canonical loop. Return true if yes,
25306 : otherwise diagnose an error if ERROR_P is true, and return false. */
25307 : static bool
25308 17383 : c_parser_omp_next_tokens_can_be_canon_loop (c_parser *parser,
25309 : enum tree_code code,
25310 : bool error_p)
25311 : {
25312 17383 : if (code == OACC_LOOP)
25313 : {
25314 2581 : if (c_parser_next_token_is_keyword (parser, RID_FOR))
25315 : return true;
25316 27 : if (error_p)
25317 4 : c_parser_error (parser, "for statement expected");
25318 : }
25319 : else
25320 : {
25321 14802 : if (c_parser_next_token_is_keyword (parser, RID_FOR))
25322 : return true;
25323 :
25324 897 : if (c_parser_next_token_is (parser, CPP_PRAGMA))
25325 582 : switch (c_parser_peek_token (parser)->pragma_kind)
25326 : {
25327 : case PRAGMA_OMP_UNROLL:
25328 : case PRAGMA_OMP_TILE:
25329 : return true;
25330 : default:
25331 : break;
25332 : }
25333 :
25334 : /* Skip standard attributes on next for in case they are
25335 : [[omp::directive (unroll partial (4))]] or
25336 : [[omp::directive (tile sizes (1, 2, 3))]] etc. */
25337 329 : size_t n = c_parser_skip_std_attribute_spec_seq (parser, 1);
25338 329 : c_token *token = c_parser_peek_nth_token_raw (parser, n);
25339 : /* TOKEN is a raw token that hasn't been converted to a keyword yet,
25340 : we have to do the lookup explicitly. */
25341 329 : if (token->type == CPP_NAME
25342 108 : && C_IS_RESERVED_WORD (token->value)
25343 341 : && C_RID_CODE (token->value) == RID_FOR)
25344 : return true;
25345 317 : if (error_p)
25346 7 : c_parser_error (parser, "loop nest expected");
25347 : }
25348 :
25349 : return false;
25350 : }
25351 :
25352 : static tree c_parser_omp_tile (location_t, c_parser *, bool *);
25353 : static tree c_parser_omp_unroll (location_t, c_parser *, bool *);
25354 :
25355 : /* This function parses a single level of a loop nest, invoking itself
25356 : recursively if necessary.
25357 :
25358 : loop-nest :: for (...) loop-body
25359 : loop-body :: loop-nest
25360 : | { [intervening-code] loop-body [intervening-code] }
25361 : | final-loop-body
25362 : intervening-code :: structured-block-sequence
25363 : final-loop-body :: structured-block
25364 :
25365 : For a collapsed loop nest, only a single OMP_FOR is built, pulling out
25366 : all the iterator information from the inner loops into the
25367 : parser->omp_for_parse_state structure.
25368 :
25369 : The iterator decl, init, cond, and incr are stored in vectors.
25370 :
25371 : Initialization code for iterator variables is collected into
25372 : parser->omp_for_parse_state->pre_body and ends up inserted directly
25373 : into the OMP_FOR structure. */
25374 :
25375 : static tree
25376 17039 : c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
25377 : {
25378 17039 : tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE;
25379 17039 : tree body = NULL_TREE;
25380 17039 : matching_parens parens;
25381 17039 : bool moreloops;
25382 17039 : unsigned char save_in_statement;
25383 17039 : tree loop_scope;
25384 17039 : location_t loc;
25385 17039 : struct omp_for_parse_data *omp_for_parse_state
25386 : = parser->omp_for_parse_state;
25387 17039 : gcc_assert (omp_for_parse_state);
25388 17039 : int depth = omp_for_parse_state->depth;
25389 :
25390 : /* Arrange for C23 standard attribute syntax to be parsed as regular
25391 : pragmas. */
25392 17039 : if (c_parser_nth_token_starts_std_attributes (parser, 1))
25393 : {
25394 12 : tree std_attrs = c_parser_std_attribute_specifier_sequence (parser);
25395 12 : c_parser_handle_statement_omp_attributes (parser, std_attrs, NULL);
25396 12 : if (std_attrs)
25397 0 : error_at (c_parser_peek_token (parser)->location,
25398 : "attributes other than OpenMP directives "
25399 : "are not allowed on %<for%> in loop nest");
25400 : }
25401 :
25402 17039 : loc = c_parser_peek_token (parser)->location;
25403 :
25404 : /* Handle loop transformations first. */
25405 17039 : if (c_parser_next_token_is (parser, CPP_PRAGMA))
25406 : {
25407 576 : tree transform = NULL_TREE, sizes, body = NULL_TREE;
25408 576 : int count = 0;
25409 576 : switch (c_parser_peek_token (parser)->pragma_kind)
25410 : {
25411 208 : case PRAGMA_OMP_UNROLL:
25412 208 : c_parser_consume_pragma (parser);
25413 208 : body = push_stmt_list ();
25414 208 : transform = c_parser_omp_unroll (loc, parser, if_p);
25415 208 : body = pop_stmt_list (body);
25416 208 : if (transform == NULL_TREE || transform == error_mark_node)
25417 : {
25418 7 : transform = error_mark_node;
25419 7 : break;
25420 : }
25421 201 : gcc_assert (TREE_CODE (transform) == OMP_UNROLL);
25422 201 : if (omp_find_clause (OMP_FOR_CLAUSES (transform),
25423 : OMP_CLAUSE_PARTIAL))
25424 : {
25425 172 : if (omp_for_parse_state->count - depth > 1)
25426 : {
25427 10 : error_at (loc, "%<unroll%> construct with %<partial%> "
25428 : "clause generates just one loop with "
25429 : "canonical form but %d loops are needed",
25430 : omp_for_parse_state->count - depth);
25431 10 : transform = error_mark_node;
25432 : }
25433 : else
25434 576 : count = 1;
25435 : }
25436 : else
25437 : {
25438 29 : error_at (loc, "generated loop of %<unroll%> construct "
25439 : "without %<partial%> clause does not have "
25440 : "canonical form");
25441 29 : transform = error_mark_node;
25442 : }
25443 : break;
25444 366 : case PRAGMA_OMP_TILE:
25445 366 : c_parser_consume_pragma (parser);
25446 366 : body = push_stmt_list ();
25447 366 : transform = c_parser_omp_tile (loc, parser, if_p);
25448 366 : body = pop_stmt_list (body);
25449 366 : if (transform == NULL_TREE || transform == error_mark_node)
25450 : {
25451 40 : transform = error_mark_node;
25452 40 : break;
25453 : }
25454 326 : gcc_assert (TREE_CODE (transform) == OMP_TILE);
25455 326 : sizes = omp_find_clause (OMP_FOR_CLAUSES (transform),
25456 : OMP_CLAUSE_SIZES);
25457 326 : gcc_assert (sizes);
25458 326 : count = list_length (OMP_CLAUSE_SIZES_LIST (sizes));
25459 326 : if (depth + count < omp_for_parse_state->count)
25460 : {
25461 16 : error_at (loc, "%<tile%> construct generates %d loops "
25462 : "with canonical form but %d loops are needed",
25463 : count, omp_for_parse_state->count - depth);
25464 16 : transform = error_mark_node;
25465 : }
25466 : break;
25467 2 : default:
25468 2 : c_parser_pragma (parser, pragma_stmt, NULL, void_list_node);
25469 2 : break;
25470 : }
25471 576 : if (transform == NULL_TREE)
25472 2 : error_at (loc, "expected %<for%> loop or OpenMP loop "
25473 : "transformation construct");
25474 576 : if (transform == NULL_TREE || transform == error_mark_node)
25475 : {
25476 104 : omp_for_parse_state->fail = true;
25477 104 : return NULL_TREE;
25478 : }
25479 1030 : for (count = omp_for_parse_state->count; depth < count; ++depth)
25480 : {
25481 558 : TREE_VEC_ELT (omp_for_parse_state->declv, depth) = NULL_TREE;
25482 558 : TREE_VEC_ELT (omp_for_parse_state->initv, depth) = NULL_TREE;
25483 558 : TREE_VEC_ELT (omp_for_parse_state->condv, depth) = NULL_TREE;
25484 558 : TREE_VEC_ELT (omp_for_parse_state->incrv, depth) = NULL_TREE;
25485 : }
25486 472 : omp_for_parse_state->want_nested_loop = false;
25487 472 : return body;
25488 : }
25489 :
25490 : /* We have already matched the FOR token but not consumed it yet. */
25491 16463 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
25492 16463 : c_parser_consume_token (parser);
25493 :
25494 : /* Forbid break/continue in the loop initializer, condition, and
25495 : increment expressions. */
25496 16463 : save_in_statement = in_statement;
25497 16463 : in_statement = IN_OMP_BLOCK;
25498 :
25499 : /* We are not in intervening code now. */
25500 16463 : omp_for_parse_state->in_intervening_code = false;
25501 :
25502 16463 : if (!parens.require_open (parser))
25503 : {
25504 0 : omp_for_parse_state->fail = true;
25505 0 : return NULL_TREE;
25506 : }
25507 :
25508 : /* An implicit scope block surrounds each level of FOR loop, for
25509 : declarations of iteration variables at this loop depth. */
25510 16463 : loop_scope = c_begin_compound_stmt (true);
25511 :
25512 : /* Parse the initialization declaration or expression. */
25513 16463 : if (c_parser_next_tokens_start_declaration (parser))
25514 : {
25515 : /* This is a declaration, which must be added to the pre_body code. */
25516 4794 : tree this_pre_body = push_stmt_list ();
25517 4794 : c_in_omp_for = true;
25518 4794 : c_parser_declaration_or_fndef (parser, true, true, true, true, true,
25519 : false);
25520 4794 : c_in_omp_for = false;
25521 4794 : this_pre_body = pop_stmt_list (this_pre_body);
25522 4794 : append_to_statement_list_force (this_pre_body,
25523 : &(omp_for_parse_state->pre_body));
25524 4794 : decl = check_for_loop_decls (omp_for_parse_state->for_loc, flag_isoc99);
25525 4794 : if (decl == NULL)
25526 0 : goto error_init;
25527 4794 : if (DECL_INITIAL (decl) == error_mark_node)
25528 1 : decl = error_mark_node;
25529 : init = decl;
25530 : }
25531 11669 : else if (c_parser_next_token_is (parser, CPP_NAME)
25532 11669 : && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
25533 : {
25534 11667 : struct c_expr decl_exp;
25535 11667 : struct c_expr init_exp;
25536 11667 : location_t init_loc;
25537 :
25538 11667 : decl_exp = c_parser_postfix_expression (parser);
25539 11667 : decl = decl_exp.value;
25540 :
25541 11667 : c_parser_require (parser, CPP_EQ, "expected %<=%>");
25542 :
25543 11667 : init_loc = c_parser_peek_token (parser)->location;
25544 11667 : init_exp = c_parser_expr_no_commas (parser, NULL);
25545 11667 : init_exp = default_function_array_read_conversion (init_loc,
25546 : init_exp);
25547 11667 : c_in_omp_for = true;
25548 11667 : init = build_modify_expr (init_loc, decl, decl_exp.original_type,
25549 : NOP_EXPR, init_loc, init_exp.value,
25550 : init_exp.original_type);
25551 11667 : c_in_omp_for = false;
25552 11667 : init = c_process_expr_stmt (init_loc, init);
25553 :
25554 11667 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
25555 : }
25556 : else
25557 : {
25558 2 : error_init:
25559 2 : c_parser_error (parser,
25560 : "expected iteration declaration or initialization");
25561 2 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
25562 : "expected %<)%>");
25563 2 : omp_for_parse_state->fail = true;
25564 2 : goto parse_next;
25565 : }
25566 :
25567 : /* Parse the loop condition. */
25568 16461 : if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
25569 : {
25570 16459 : location_t cond_loc = c_parser_peek_token (parser)->location;
25571 16459 : c_in_omp_for = true;
25572 16459 : struct c_expr cond_expr
25573 16459 : = c_parser_binary_expression (parser, NULL, NULL_TREE);
25574 16459 : c_in_omp_for = false;
25575 :
25576 16459 : cond = cond_expr.value;
25577 16459 : cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
25578 16459 : switch (cond_expr.original_code)
25579 : {
25580 : case GT_EXPR:
25581 : case GE_EXPR:
25582 : case LT_EXPR:
25583 : case LE_EXPR:
25584 : break;
25585 2425 : case NE_EXPR:
25586 2425 : if (omp_for_parse_state->code != OACC_LOOP)
25587 : break;
25588 : /* FALLTHRU. */
25589 7 : default:
25590 : /* Can't be cond = error_mark_node, because we want to preserve
25591 : the location until c_finish_omp_for. */
25592 7 : cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
25593 7 : break;
25594 : }
25595 16459 : protected_set_expr_location (cond, cond_loc);
25596 : }
25597 16461 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
25598 :
25599 : /* Parse the increment expression. */
25600 16461 : if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
25601 : {
25602 16461 : location_t incr_loc = c_parser_peek_token (parser)->location;
25603 :
25604 16461 : incr = c_process_expr_stmt (incr_loc,
25605 32922 : c_parser_expression (parser).value);
25606 : }
25607 16461 : parens.skip_until_found_close (parser);
25608 :
25609 16461 : if (decl == NULL || decl == error_mark_node || init == error_mark_node)
25610 3 : omp_for_parse_state->fail = true;
25611 : else
25612 : {
25613 16458 : TREE_VEC_ELT (omp_for_parse_state->declv, depth) = decl;
25614 16458 : TREE_VEC_ELT (omp_for_parse_state->initv, depth) = init;
25615 16458 : TREE_VEC_ELT (omp_for_parse_state->condv, depth) = cond;
25616 16458 : TREE_VEC_ELT (omp_for_parse_state->incrv, depth) = incr;
25617 : }
25618 :
25619 16463 : parse_next:
25620 16463 : moreloops = depth < omp_for_parse_state->count - 1;
25621 16463 : omp_for_parse_state->want_nested_loop = moreloops;
25622 16463 : if (moreloops
25623 16463 : && c_parser_omp_next_tokens_can_be_canon_loop (parser,
25624 : omp_for_parse_state->code,
25625 : false))
25626 : {
25627 5327 : omp_for_parse_state->depth++;
25628 5327 : body = c_parser_omp_loop_nest (parser, if_p);
25629 5327 : omp_for_parse_state->depth--;
25630 : }
25631 11282 : else if (moreloops && c_parser_next_token_is (parser, CPP_OPEN_BRACE))
25632 : {
25633 : /* This is the open brace in the loop-body grammar production. Rather
25634 : than trying to special-case braces, just parse it as a compound
25635 : statement and handle the nested loop-body case there. Note that
25636 : when we see a further open brace inside the compound statement
25637 : loop-body, we don't know whether it is the start of intervening
25638 : code that is a compound statement, or a level of braces
25639 : surrounding a nested loop-body. Use the WANT_NESTED_LOOP state
25640 : bit to ensure we have only one nested loop at each level. */
25641 127 : omp_for_parse_state->in_intervening_code = true;
25642 127 : body = c_parser_compound_statement (parser, NULL);
25643 127 : omp_for_parse_state->in_intervening_code = false;
25644 127 : if (omp_for_parse_state->want_nested_loop)
25645 : {
25646 : /* We have already parsed the whole loop body and not found a
25647 : nested loop. */
25648 11 : error_at (omp_for_parse_state->for_loc,
25649 : "not enough nested loops");
25650 11 : omp_for_parse_state->fail = true;
25651 : }
25652 16463 : if_p = NULL;
25653 : }
25654 : else
25655 : {
25656 : /* This is the final-loop-body case in the grammar: we have
25657 : something that is not a FOR and not an open brace. */
25658 11009 : if (moreloops)
25659 : {
25660 : /* If we were expecting a nested loop, give an error and mark
25661 : that parsing has failed, and try to recover by parsing the
25662 : body as regular code without further collapsing. */
25663 19 : error_at (omp_for_parse_state->for_loc,
25664 : "not enough nested loops");
25665 19 : omp_for_parse_state->fail = true;
25666 : }
25667 11009 : in_statement = IN_OMP_FOR;
25668 11009 : parser->omp_for_parse_state = NULL;
25669 11009 : body = push_stmt_list ();
25670 11009 : if (omp_for_parse_state->inscan)
25671 267 : c_parser_omp_scan_loop_body (parser, false);
25672 : else
25673 10742 : add_stmt (c_parser_c99_block_statement (parser, if_p));
25674 11009 : body = pop_stmt_list (body);
25675 11009 : parser->omp_for_parse_state = omp_for_parse_state;
25676 : }
25677 16463 : in_statement = save_in_statement;
25678 16463 : omp_for_parse_state->want_nested_loop = false;
25679 16463 : omp_for_parse_state->in_intervening_code = true;
25680 :
25681 : /* Pop and return the implicit scope surrounding this level of loop.
25682 : If the iteration variable at this depth was bound in the for loop,
25683 : pull out and save the binding. Later in c_parser_omp_for_loop,
25684 : these bindings will be moved to the scope surrounding the entire
25685 : OMP_FOR. That keeps the gimplifier happy later on, and meanwhile
25686 : we have already resolved all references to the iteration variable
25687 : in its true scope. */
25688 16463 : if (body)
25689 16457 : add_stmt (body);
25690 16463 : body = c_end_compound_stmt (loc, loop_scope, true);
25691 16463 : if (decl && TREE_CODE (body) == BIND_EXPR)
25692 : {
25693 5180 : tree t = BIND_EXPR_VARS (body);
25694 5180 : tree prev = NULL_TREE, next = NULL_TREE;
25695 5616 : while (t)
25696 : {
25697 5229 : next = DECL_CHAIN (t);
25698 5229 : if (t == decl)
25699 : {
25700 4793 : if (prev)
25701 0 : DECL_CHAIN (prev) = next;
25702 : else
25703 : {
25704 4793 : BIND_EXPR_VARS (body) = next;
25705 4793 : BLOCK_VARS (BIND_EXPR_BLOCK (body)) = next;
25706 : }
25707 4793 : DECL_CHAIN (t) = omp_for_parse_state->bindings;
25708 4793 : omp_for_parse_state->bindings = t;
25709 4793 : break;
25710 : }
25711 : else
25712 : {
25713 : prev = t;
25714 : t = next;
25715 : }
25716 : }
25717 5180 : if (BIND_EXPR_VARS (body) == NULL_TREE)
25718 4793 : body = BIND_EXPR_BODY (body);
25719 : }
25720 :
25721 : return body;
25722 : }
25723 :
25724 : /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
25725 : The real trick here is to determine the loop control variable early
25726 : so that we can push a new decl if necessary to make it private.
25727 : LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
25728 : respectively. */
25729 :
25730 : static tree
25731 11607 : c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
25732 : tree clauses, tree *cclauses, bool *if_p)
25733 : {
25734 11607 : tree body, stmt, cl;
25735 11607 : tree ret = NULL_TREE;
25736 11607 : tree ordered_cl = NULL_TREE;
25737 11607 : int i, collapse = 1, ordered = 0, count;
25738 11607 : bool oacc_tiling = false;
25739 11607 : bool inscan = false;
25740 11607 : struct omp_for_parse_data data;
25741 11607 : struct omp_for_parse_data *save_data = parser->omp_for_parse_state;
25742 :
25743 27583 : for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
25744 15976 : if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
25745 2954 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
25746 13022 : else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
25747 : {
25748 111 : oacc_tiling = true;
25749 111 : collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
25750 : }
25751 12911 : else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_SIZES)
25752 464 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (cl));
25753 12447 : else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
25754 12447 : && OMP_CLAUSE_ORDERED_EXPR (cl))
25755 : {
25756 161 : ordered_cl = cl;
25757 161 : ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl));
25758 : }
25759 12286 : else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_REDUCTION
25760 2114 : && OMP_CLAUSE_REDUCTION_INSCAN (cl)
25761 12674 : && (code == OMP_SIMD || code == OMP_FOR))
25762 : inscan = true;
25763 :
25764 11607 : if (ordered && ordered < collapse)
25765 : {
25766 2 : error_at (OMP_CLAUSE_LOCATION (ordered_cl),
25767 : "%<ordered%> clause parameter is less than %<collapse%>");
25768 2 : OMP_CLAUSE_ORDERED_EXPR (ordered_cl)
25769 2 : = build_int_cst (integer_type_node, collapse);
25770 2 : ordered = collapse;
25771 : }
25772 :
25773 11607 : gcc_assert (oacc_tiling || (collapse >= 1 && ordered >= 0));
25774 11607 : count = ordered ? ordered : collapse;
25775 :
25776 11607 : if (!c_parser_omp_next_tokens_can_be_canon_loop (parser, code, true))
25777 : return NULL;
25778 :
25779 : /* Initialize parse state for recursive descent. */
25780 11596 : data.declv = make_tree_vec (count);
25781 11596 : data.initv = make_tree_vec (count);
25782 11596 : data.condv = make_tree_vec (count);
25783 11596 : data.incrv = make_tree_vec (count);
25784 11596 : data.pre_body = NULL_TREE;
25785 11596 : data.bindings = NULL_TREE;
25786 11596 : data.for_loc = c_parser_peek_token (parser)->location;
25787 11596 : data.count = count;
25788 11596 : data.depth = 0;
25789 11596 : data.want_nested_loop = true;
25790 11596 : data.ordered = ordered > 0;
25791 11596 : data.in_intervening_code = false;
25792 11596 : data.perfect_nesting_fail = false;
25793 11596 : data.fail = false;
25794 11596 : data.inscan = inscan;
25795 11596 : data.saw_intervening_code = false;
25796 11596 : data.code = code;
25797 11596 : parser->omp_for_parse_state = &data;
25798 :
25799 11596 : body = c_parser_omp_loop_nest (parser, if_p);
25800 :
25801 : /* Add saved bindings for iteration variables that were declared in
25802 : the nested for loop to the scope surrounding the entire loop. */
25803 16389 : for (tree t = data.bindings; t; )
25804 : {
25805 4793 : tree n = TREE_CHAIN (t);
25806 4793 : TREE_CHAIN (t) = NULL_TREE;
25807 4793 : pushdecl (t);
25808 4793 : t = n;
25809 : }
25810 :
25811 : /* Only bother calling c_finish_omp_for if we haven't already generated
25812 : an error from the initialization parsing. */
25813 11596 : if (!data.fail)
25814 : {
25815 11433 : c_in_omp_for = true;
25816 11433 : stmt = c_finish_omp_for (loc, code, data.declv, NULL, data.initv,
25817 : data.condv, data.incrv,
25818 : body, data.pre_body, true);
25819 11433 : c_in_omp_for = false;
25820 :
25821 : /* Check for iterators appearing in lb, b or incr expressions. */
25822 11433 : if (stmt && !c_omp_check_loop_iv (stmt, data.declv, NULL))
25823 : stmt = NULL_TREE;
25824 :
25825 : /* Check for errors involving lb/ub/incr expressions referencing
25826 : variables declared in intervening code. */
25827 11433 : if (data.saw_intervening_code
25828 42 : && stmt
25829 11475 : && !c_omp_check_loop_binding_exprs (stmt, NULL))
25830 : stmt = NULL_TREE;
25831 :
25832 11423 : if (stmt)
25833 : {
25834 11278 : add_stmt (stmt);
25835 :
25836 38717 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (stmt)); i++)
25837 : {
25838 16619 : tree init = TREE_VEC_ELT (OMP_FOR_INIT (stmt), i);
25839 16619 : if (init == NULL_TREE)
25840 : break;
25841 16161 : gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
25842 16161 : tree decl = TREE_OPERAND (init, 0);
25843 16161 : tree cond = TREE_VEC_ELT (OMP_FOR_COND (stmt), i);
25844 16161 : gcc_assert (COMPARISON_CLASS_P (cond));
25845 16161 : gcc_assert (TREE_OPERAND (cond, 0) == decl);
25846 :
25847 16161 : tree op0 = TREE_OPERAND (init, 1);
25848 16161 : if (!OMP_FOR_NON_RECTANGULAR (stmt)
25849 16161 : || TREE_CODE (op0) != TREE_VEC)
25850 15974 : TREE_OPERAND (init, 1) = c_fully_fold (op0, false, NULL);
25851 : else
25852 : {
25853 187 : TREE_VEC_ELT (op0, 1)
25854 187 : = c_fully_fold (TREE_VEC_ELT (op0, 1), false, NULL);
25855 187 : TREE_VEC_ELT (op0, 2)
25856 374 : = c_fully_fold (TREE_VEC_ELT (op0, 2), false, NULL);
25857 : }
25858 :
25859 16161 : tree op1 = TREE_OPERAND (cond, 1);
25860 16161 : if (!OMP_FOR_NON_RECTANGULAR (stmt)
25861 16161 : || TREE_CODE (op1) != TREE_VEC)
25862 15955 : TREE_OPERAND (cond, 1) = c_fully_fold (op1, false, NULL);
25863 : else
25864 : {
25865 206 : TREE_VEC_ELT (op1, 1)
25866 206 : = c_fully_fold (TREE_VEC_ELT (op1, 1), false, NULL);
25867 206 : TREE_VEC_ELT (op1, 2)
25868 412 : = c_fully_fold (TREE_VEC_ELT (op1, 2), false, NULL);
25869 : }
25870 : }
25871 :
25872 11278 : if (cclauses != NULL
25873 5261 : && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
25874 : {
25875 757 : tree *c;
25876 3317 : for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
25877 2560 : if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
25878 2560 : && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
25879 1860 : c = &OMP_CLAUSE_CHAIN (*c);
25880 : else
25881 : {
25882 1441 : for (i = 0; i < count; i++)
25883 923 : if (TREE_VEC_ELT (data.declv, i) == OMP_CLAUSE_DECL (*c))
25884 : break;
25885 700 : if (i == count)
25886 518 : c = &OMP_CLAUSE_CHAIN (*c);
25887 182 : else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
25888 : {
25889 1 : error_at (loc,
25890 : "iteration variable %qD should not be firstprivate",
25891 1 : OMP_CLAUSE_DECL (*c));
25892 1 : *c = OMP_CLAUSE_CHAIN (*c);
25893 : }
25894 : else
25895 : {
25896 : /* Move lastprivate (decl) clause to
25897 : OMP_FOR_CLAUSES. */
25898 181 : tree l = *c;
25899 181 : *c = OMP_CLAUSE_CHAIN (*c);
25900 181 : if (code == OMP_SIMD)
25901 : {
25902 46 : OMP_CLAUSE_CHAIN (l)
25903 46 : = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
25904 46 : cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
25905 : }
25906 : else
25907 : {
25908 135 : OMP_CLAUSE_CHAIN (l) = clauses;
25909 135 : clauses = l;
25910 : }
25911 : }
25912 : }
25913 : }
25914 11278 : OMP_FOR_CLAUSES (stmt) = clauses;
25915 : }
25916 : ret = stmt;
25917 : }
25918 :
25919 11596 : parser->omp_for_parse_state = save_data;
25920 11596 : return ret;
25921 : }
25922 :
25923 : /* Helper function for OpenMP parsing, split clauses and call
25924 : finish_omp_clauses on each of the set of clauses afterwards. */
25925 :
25926 : static void
25927 6581 : omp_split_clauses (location_t loc, enum tree_code code,
25928 : omp_clause_mask mask, tree clauses, tree *cclauses)
25929 : {
25930 6581 : int i;
25931 6581 : c_omp_split_clauses (loc, code, mask, clauses, cclauses);
25932 52648 : for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
25933 39486 : if (cclauses[i])
25934 20273 : cclauses[i] = c_finish_omp_clauses (cclauses[i],
25935 : i == C_OMP_CLAUSE_SPLIT_TARGET
25936 : ? C_ORT_OMP_TARGET : C_ORT_OMP);
25937 6581 : }
25938 :
25939 : /* OpenMP 5.0:
25940 : #pragma omp loop loop-clause[optseq] new-line
25941 : for-loop
25942 :
25943 : LOC is the location of the #pragma token.
25944 : */
25945 :
25946 : #define OMP_LOOP_CLAUSE_MASK \
25947 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
25948 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
25949 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
25950 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
25951 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_BIND) \
25952 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER))
25953 :
25954 : static tree
25955 235 : c_parser_omp_loop (location_t loc, c_parser *parser,
25956 : char *p_name, omp_clause_mask mask, tree *cclauses,
25957 : bool *if_p)
25958 : {
25959 235 : tree block, clauses, ret;
25960 :
25961 235 : strcat (p_name, " loop");
25962 235 : mask |= OMP_LOOP_CLAUSE_MASK;
25963 :
25964 235 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
25965 235 : if (cclauses)
25966 : {
25967 77 : omp_split_clauses (loc, OMP_LOOP, mask, clauses, cclauses);
25968 77 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_LOOP];
25969 : }
25970 :
25971 235 : block = c_begin_compound_stmt (true);
25972 235 : ret = c_parser_omp_for_loop (loc, parser, OMP_LOOP, clauses, cclauses, if_p);
25973 235 : block = c_end_compound_stmt (loc, block, true);
25974 235 : add_stmt (block);
25975 :
25976 235 : return ret;
25977 : }
25978 :
25979 : /* OpenMP 4.0:
25980 : #pragma omp simd simd-clause[optseq] new-line
25981 : for-loop
25982 :
25983 : LOC is the location of the #pragma token.
25984 : */
25985 :
25986 : #define OMP_SIMD_CLAUSE_MASK \
25987 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
25988 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
25989 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
25990 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
25991 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
25992 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
25993 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
25994 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
25995 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
25996 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL) \
25997 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER))
25998 :
25999 : static tree
26000 3550 : c_parser_omp_simd (location_t loc, c_parser *parser,
26001 : char *p_name, omp_clause_mask mask, tree *cclauses,
26002 : bool *if_p)
26003 : {
26004 3550 : tree block, clauses, ret;
26005 :
26006 3550 : strcat (p_name, " simd");
26007 3550 : mask |= OMP_SIMD_CLAUSE_MASK;
26008 :
26009 3550 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
26010 3550 : if (cclauses)
26011 : {
26012 2785 : omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
26013 2785 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
26014 : }
26015 :
26016 3550 : block = c_begin_compound_stmt (true);
26017 3550 : ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p);
26018 3550 : block = c_end_compound_stmt (loc, block, true);
26019 3550 : add_stmt (block);
26020 :
26021 3550 : return ret;
26022 : }
26023 :
26024 : /* OpenMP 2.5:
26025 : #pragma omp for for-clause[optseq] new-line
26026 : for-loop
26027 :
26028 : OpenMP 4.0:
26029 : #pragma omp for simd for-simd-clause[optseq] new-line
26030 : for-loop
26031 :
26032 : LOC is the location of the #pragma token.
26033 : */
26034 :
26035 : #define OMP_FOR_CLAUSE_MASK \
26036 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
26037 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
26038 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
26039 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
26040 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
26041 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
26042 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
26043 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
26044 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
26045 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
26046 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER))
26047 :
26048 : static tree
26049 6210 : c_parser_omp_for (location_t loc, c_parser *parser,
26050 : char *p_name, omp_clause_mask mask, tree *cclauses,
26051 : bool *if_p)
26052 : {
26053 6210 : tree block, clauses, ret;
26054 :
26055 6210 : strcat (p_name, " for");
26056 6210 : mask |= OMP_FOR_CLAUSE_MASK;
26057 : /* parallel for{, simd} disallows nowait clause, but for
26058 : target {teams distribute ,}parallel for{, simd} it should be accepted. */
26059 6210 : if (cclauses && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0)
26060 3250 : mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
26061 : /* Composite distribute parallel for{, simd} disallows ordered clause. */
26062 6210 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
26063 2724 : mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
26064 :
26065 6210 : if (c_parser_next_token_is (parser, CPP_NAME))
26066 : {
26067 5459 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
26068 :
26069 5459 : if (strcmp (p, "simd") == 0)
26070 : {
26071 2207 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26072 2207 : if (cclauses == NULL)
26073 301 : cclauses = cclauses_buf;
26074 :
26075 2207 : c_parser_consume_token (parser);
26076 2207 : if (!flag_openmp) /* flag_openmp_simd */
26077 14 : return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
26078 14 : if_p);
26079 2193 : block = c_begin_compound_stmt (true);
26080 2193 : ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
26081 2193 : block = c_end_compound_stmt (loc, block, true);
26082 2193 : if (ret == NULL_TREE)
26083 : return ret;
26084 2182 : ret = make_node (OMP_FOR);
26085 2182 : TREE_TYPE (ret) = void_type_node;
26086 2182 : OMP_FOR_BODY (ret) = block;
26087 2182 : OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
26088 2182 : SET_EXPR_LOCATION (ret, loc);
26089 2182 : add_stmt (ret);
26090 2182 : return ret;
26091 : }
26092 : }
26093 4003 : if (!flag_openmp) /* flag_openmp_simd */
26094 : {
26095 9 : c_parser_skip_to_pragma_eol (parser, false);
26096 9 : return NULL_TREE;
26097 : }
26098 :
26099 : /* Composite distribute parallel for disallows linear clause. */
26100 3994 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
26101 1371 : mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR);
26102 :
26103 3994 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
26104 3994 : if (cclauses)
26105 : {
26106 2462 : omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
26107 2462 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
26108 : }
26109 :
26110 3994 : block = c_begin_compound_stmt (true);
26111 3994 : ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p);
26112 3994 : block = c_end_compound_stmt (loc, block, true);
26113 3994 : add_stmt (block);
26114 :
26115 3994 : return ret;
26116 : }
26117 :
26118 : static tree c_parser_omp_taskloop (location_t, c_parser *, char *,
26119 : omp_clause_mask, tree *, bool *);
26120 :
26121 : /* OpenMP 2.5:
26122 : # pragma omp master new-line
26123 : structured-block
26124 :
26125 : LOC is the location of the #pragma token.
26126 : */
26127 :
26128 : static tree
26129 228 : c_parser_omp_master (location_t loc, c_parser *parser,
26130 : char *p_name, omp_clause_mask mask, tree *cclauses,
26131 : bool *if_p, location_t master_loc)
26132 : {
26133 228 : tree block, clauses, ret;
26134 228 : gcc_rich_location richloc (loc);
26135 228 : if (master_loc != UNKNOWN_LOCATION)
26136 91 : richloc.add_fixit_replace (master_loc, "masked");
26137 228 : warning_at (&richloc, OPT_Wdeprecated_openmp,
26138 : "%<master%> construct deprecated since OpenMP 5.1, use "
26139 : "%<masked%>");
26140 :
26141 228 : strcat (p_name, " master");
26142 :
26143 228 : if (c_parser_next_token_is (parser, CPP_NAME))
26144 : {
26145 123 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
26146 :
26147 123 : if (strcmp (p, "taskloop") == 0)
26148 : {
26149 94 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26150 94 : if (cclauses == NULL)
26151 47 : cclauses = cclauses_buf;
26152 :
26153 94 : c_parser_consume_token (parser);
26154 94 : if (!flag_openmp) /* flag_openmp_simd */
26155 4 : return c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses,
26156 4 : if_p);
26157 90 : block = c_begin_compound_stmt (true);
26158 90 : ret = c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses,
26159 : if_p);
26160 90 : block = c_end_compound_stmt (loc, block, true);
26161 90 : if (ret == NULL_TREE)
26162 : return ret;
26163 90 : ret = c_finish_omp_master (loc, block);
26164 90 : OMP_MASTER_COMBINED (ret) = 1;
26165 90 : return ret;
26166 : }
26167 : }
26168 134 : if (!flag_openmp) /* flag_openmp_simd */
26169 : {
26170 2 : c_parser_skip_to_pragma_eol (parser, false);
26171 2 : return NULL_TREE;
26172 : }
26173 :
26174 132 : if (cclauses)
26175 : {
26176 43 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, false);
26177 43 : omp_split_clauses (loc, OMP_MASTER, mask, clauses, cclauses);
26178 : }
26179 : else
26180 89 : c_parser_skip_to_pragma_eol (parser);
26181 :
26182 132 : return c_finish_omp_master (loc, c_parser_omp_structured_block (parser,
26183 132 : if_p));
26184 228 : }
26185 :
26186 : /* OpenMP 5.1:
26187 : # pragma omp masked masked-clauses new-line
26188 : structured-block
26189 :
26190 : LOC is the location of the #pragma token.
26191 : */
26192 :
26193 : #define OMP_MASKED_CLAUSE_MASK \
26194 : (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FILTER)
26195 :
26196 : static tree
26197 130 : c_parser_omp_masked (location_t loc, c_parser *parser,
26198 : char *p_name, omp_clause_mask mask, tree *cclauses,
26199 : bool *if_p)
26200 : {
26201 130 : tree block, clauses, ret;
26202 :
26203 130 : strcat (p_name, " masked");
26204 130 : mask |= OMP_MASKED_CLAUSE_MASK;
26205 :
26206 130 : if (c_parser_next_token_is (parser, CPP_NAME))
26207 : {
26208 87 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
26209 :
26210 87 : if (strcmp (p, "taskloop") == 0)
26211 : {
26212 68 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26213 68 : if (cclauses == NULL)
26214 21 : cclauses = cclauses_buf;
26215 :
26216 68 : c_parser_consume_token (parser);
26217 68 : if (!flag_openmp) /* flag_openmp_simd */
26218 0 : return c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses,
26219 0 : if_p);
26220 68 : block = c_begin_compound_stmt (true);
26221 68 : ret = c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses,
26222 : if_p);
26223 68 : block = c_end_compound_stmt (loc, block, true);
26224 68 : if (ret == NULL_TREE)
26225 : return ret;
26226 68 : ret = c_finish_omp_masked (loc, block,
26227 : cclauses[C_OMP_CLAUSE_SPLIT_MASKED]);
26228 68 : OMP_MASKED_COMBINED (ret) = 1;
26229 68 : return ret;
26230 : }
26231 : }
26232 62 : if (!flag_openmp) /* flag_openmp_simd */
26233 : {
26234 0 : c_parser_skip_to_pragma_eol (parser, false);
26235 0 : return NULL_TREE;
26236 : }
26237 :
26238 62 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
26239 62 : if (cclauses)
26240 : {
26241 9 : omp_split_clauses (loc, OMP_MASKED, mask, clauses, cclauses);
26242 9 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_MASKED];
26243 : }
26244 :
26245 62 : return c_finish_omp_masked (loc, c_parser_omp_structured_block (parser,
26246 : if_p),
26247 62 : clauses);
26248 : }
26249 :
26250 : /* OpenMP 5.1:
26251 : # pragma omp interop clauses[opt] new-line */
26252 :
26253 : #define OMP_INTEROP_CLAUSE_MASK \
26254 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
26255 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DESTROY) \
26256 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
26257 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INIT) \
26258 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
26259 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE))
26260 :
26261 : static void
26262 183 : c_parser_omp_interop (c_parser *parser)
26263 : {
26264 183 : location_t loc = c_parser_peek_token (parser)->location;
26265 183 : c_parser_consume_pragma (parser);
26266 366 : tree clauses = c_parser_omp_all_clauses (parser,
26267 183 : OMP_INTEROP_CLAUSE_MASK,
26268 : "#pragma omp interop");
26269 183 : tree stmt = make_node (OMP_INTEROP);
26270 183 : TREE_TYPE (stmt) = void_type_node;
26271 183 : OMP_INTEROP_CLAUSES (stmt) = clauses;
26272 183 : SET_EXPR_LOCATION (stmt, loc);
26273 183 : add_stmt (stmt);
26274 183 : }
26275 :
26276 : /* OpenMP 2.5:
26277 : # pragma omp ordered new-line
26278 : structured-block
26279 :
26280 : OpenMP 4.5:
26281 : # pragma omp ordered ordered-clauses new-line
26282 : structured-block
26283 :
26284 : # pragma omp ordered depend-clauses new-line
26285 :
26286 : OpenMP 5.2
26287 : # pragma omp ordered doacross-clauses new-line */
26288 :
26289 : #define OMP_ORDERED_CLAUSE_MASK \
26290 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
26291 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
26292 :
26293 : #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
26294 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
26295 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DOACROSS))
26296 :
26297 : static bool
26298 545 : c_parser_omp_ordered (c_parser *parser, enum pragma_context context,
26299 : bool *if_p)
26300 : {
26301 545 : location_t loc = c_parser_peek_token (parser)->location;
26302 545 : c_parser_consume_pragma (parser);
26303 :
26304 545 : if (context != pragma_stmt && context != pragma_compound)
26305 : {
26306 1 : c_parser_error (parser, "expected declaration specifiers");
26307 1 : c_parser_skip_to_pragma_eol (parser, false);
26308 1 : return false;
26309 : }
26310 :
26311 544 : int n = 1;
26312 544 : if (c_parser_next_token_is (parser, CPP_COMMA))
26313 8 : n = 2;
26314 :
26315 544 : if (c_parser_peek_nth_token (parser, n)->type == CPP_NAME)
26316 : {
26317 433 : const char *p
26318 433 : = IDENTIFIER_POINTER (c_parser_peek_nth_token (parser, n)->value);
26319 :
26320 433 : if (!strcmp ("depend", p) || !strcmp ("doacross", p))
26321 : {
26322 349 : if (!flag_openmp) /* flag_openmp_simd */
26323 : {
26324 2 : c_parser_skip_to_pragma_eol (parser, false);
26325 2 : return false;
26326 : }
26327 347 : if (context == pragma_stmt)
26328 : {
26329 16 : error_at (loc,
26330 : "%<#pragma omp ordered%> with %qs clause may "
26331 : "only be used in compound statements", p);
26332 16 : c_parser_skip_to_pragma_eol (parser, false);
26333 16 : return true;
26334 : }
26335 :
26336 331 : tree clauses
26337 662 : = c_parser_omp_all_clauses (parser,
26338 331 : OMP_ORDERED_DEPEND_CLAUSE_MASK,
26339 : "#pragma omp ordered");
26340 331 : c_finish_omp_ordered (loc, clauses, NULL_TREE);
26341 331 : return false;
26342 : }
26343 : }
26344 :
26345 195 : tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK,
26346 : "#pragma omp ordered");
26347 :
26348 195 : if (!flag_openmp /* flag_openmp_simd */
26349 195 : && omp_find_clause (clauses, OMP_CLAUSE_SIMD) == NULL_TREE)
26350 : return false;
26351 :
26352 193 : c_finish_omp_ordered (loc, clauses,
26353 : c_parser_omp_structured_block (parser, if_p));
26354 193 : return true;
26355 : }
26356 :
26357 : /* OpenMP 2.5:
26358 :
26359 : section-scope:
26360 : { section-sequence }
26361 :
26362 : section-sequence:
26363 : section-directive[opt] structured-block
26364 : section-sequence section-directive structured-block
26365 :
26366 : OpenMP 5.1 allows structured-block-sequence instead of structured-block.
26367 :
26368 : SECTIONS_LOC is the location of the #pragma omp sections. */
26369 :
26370 : static tree
26371 144 : c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
26372 : {
26373 144 : tree stmt, substmt;
26374 144 : bool error_suppress = false;
26375 144 : location_t loc;
26376 :
26377 144 : loc = c_parser_peek_token (parser)->location;
26378 144 : if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
26379 : {
26380 : /* Avoid skipping until the end of the block. */
26381 2 : parser->error = false;
26382 2 : return NULL_TREE;
26383 : }
26384 :
26385 142 : stmt = push_stmt_list ();
26386 :
26387 142 : if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION
26388 142 : && !c_parser_omp_section_scan (parser, "section", true))
26389 : {
26390 83 : substmt = c_parser_omp_structured_block_sequence (parser,
26391 : PRAGMA_OMP_SECTION);
26392 83 : substmt = build1 (OMP_SECTION, void_type_node, substmt);
26393 83 : SET_EXPR_LOCATION (substmt, loc);
26394 83 : add_stmt (substmt);
26395 : }
26396 :
26397 580 : while (1)
26398 : {
26399 361 : if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
26400 : break;
26401 219 : if (c_parser_next_token_is (parser, CPP_EOF))
26402 : break;
26403 :
26404 219 : loc = c_parser_peek_token (parser)->location;
26405 219 : c_parser_omp_section_scan (parser, "section", false);
26406 219 : if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
26407 : {
26408 218 : c_parser_consume_pragma (parser);
26409 218 : c_parser_skip_to_pragma_eol (parser);
26410 218 : error_suppress = false;
26411 : }
26412 1 : else if (!error_suppress)
26413 : {
26414 1 : error_at (loc, "expected %<#pragma omp section%> or %<}%>");
26415 1 : error_suppress = true;
26416 : }
26417 :
26418 219 : substmt = c_parser_omp_structured_block_sequence (parser,
26419 : PRAGMA_OMP_SECTION);
26420 219 : substmt = build1 (OMP_SECTION, void_type_node, substmt);
26421 219 : SET_EXPR_LOCATION (substmt, loc);
26422 219 : add_stmt (substmt);
26423 : }
26424 142 : c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
26425 : "expected %<#pragma omp section%> or %<}%>");
26426 :
26427 142 : substmt = pop_stmt_list (stmt);
26428 :
26429 142 : stmt = make_node (OMP_SECTIONS);
26430 142 : SET_EXPR_LOCATION (stmt, sections_loc);
26431 142 : TREE_TYPE (stmt) = void_type_node;
26432 142 : OMP_SECTIONS_BODY (stmt) = substmt;
26433 :
26434 142 : return add_stmt (stmt);
26435 : }
26436 :
26437 : /* OpenMP 2.5:
26438 : # pragma omp sections sections-clause[optseq] newline
26439 : sections-scope
26440 :
26441 : LOC is the location of the #pragma token.
26442 : */
26443 :
26444 : #define OMP_SECTIONS_CLAUSE_MASK \
26445 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
26446 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
26447 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
26448 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
26449 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
26450 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
26451 :
26452 : static tree
26453 144 : c_parser_omp_sections (location_t loc, c_parser *parser,
26454 : char *p_name, omp_clause_mask mask, tree *cclauses)
26455 : {
26456 144 : tree block, clauses, ret;
26457 :
26458 144 : strcat (p_name, " sections");
26459 144 : mask |= OMP_SECTIONS_CLAUSE_MASK;
26460 144 : if (cclauses)
26461 36 : mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
26462 :
26463 144 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
26464 144 : if (cclauses)
26465 : {
26466 36 : omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
26467 36 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
26468 : }
26469 :
26470 144 : block = c_begin_compound_stmt (true);
26471 144 : ret = c_parser_omp_sections_scope (loc, parser);
26472 144 : if (ret)
26473 142 : OMP_SECTIONS_CLAUSES (ret) = clauses;
26474 144 : block = c_end_compound_stmt (loc, block, true);
26475 144 : add_stmt (block);
26476 :
26477 144 : return ret;
26478 : }
26479 :
26480 : /* OpenMP 2.5:
26481 : # pragma omp parallel parallel-clause[optseq] new-line
26482 : structured-block
26483 : # pragma omp parallel for parallel-for-clause[optseq] new-line
26484 : structured-block
26485 : # pragma omp parallel sections parallel-sections-clause[optseq] new-line
26486 : structured-block
26487 :
26488 : OpenMP 4.0:
26489 : # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
26490 : structured-block
26491 :
26492 : LOC is the location of the #pragma token.
26493 : */
26494 :
26495 : #define OMP_PARALLEL_CLAUSE_MASK \
26496 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
26497 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
26498 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
26499 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
26500 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
26501 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
26502 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
26503 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
26504 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
26505 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
26506 :
26507 : static tree
26508 5750 : c_parser_omp_parallel (location_t loc, c_parser *parser,
26509 : char *p_name, omp_clause_mask mask, tree *cclauses,
26510 : bool *if_p)
26511 : {
26512 5750 : tree stmt, clauses, block;
26513 :
26514 5750 : strcat (p_name, " parallel");
26515 5750 : mask |= OMP_PARALLEL_CLAUSE_MASK;
26516 : /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
26517 5750 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0
26518 1169 : && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0)
26519 493 : mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN);
26520 :
26521 5750 : if (c_parser_next_token_is_keyword (parser, RID_FOR))
26522 : {
26523 4376 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26524 4376 : if (cclauses == NULL)
26525 1202 : cclauses = cclauses_buf;
26526 :
26527 4376 : c_parser_consume_token (parser);
26528 4376 : if (!flag_openmp) /* flag_openmp_simd */
26529 20 : return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
26530 4356 : block = c_begin_omp_parallel ();
26531 4356 : tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
26532 4356 : stmt
26533 4356 : = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
26534 : block);
26535 4356 : if (ret == NULL_TREE)
26536 : return ret;
26537 4295 : OMP_PARALLEL_COMBINED (stmt) = 1;
26538 4295 : return stmt;
26539 : }
26540 : /* When combined with distribute, parallel has to be followed by for.
26541 : #pragma omp target parallel is allowed though. */
26542 1374 : else if (cclauses
26543 1374 : && (mask & (OMP_CLAUSE_MASK_1
26544 43 : << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
26545 : {
26546 0 : error_at (loc, "expected %<for%> after %qs", p_name);
26547 0 : c_parser_skip_to_pragma_eol (parser);
26548 0 : return NULL_TREE;
26549 : }
26550 1374 : else if (c_parser_next_token_is (parser, CPP_NAME))
26551 : {
26552 756 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
26553 756 : location_t ploc = c_parser_peek_token (parser)->location;
26554 756 : if (cclauses == NULL && strcmp (p, "masked") == 0)
26555 : {
26556 56 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26557 56 : cclauses = cclauses_buf;
26558 :
26559 56 : c_parser_consume_token (parser);
26560 56 : if (!flag_openmp) /* flag_openmp_simd */
26561 0 : return c_parser_omp_masked (loc, parser, p_name, mask, cclauses,
26562 0 : if_p);
26563 56 : block = c_begin_omp_parallel ();
26564 56 : tree ret = c_parser_omp_masked (loc, parser, p_name, mask, cclauses,
26565 : if_p);
26566 56 : stmt = c_finish_omp_parallel (loc,
26567 : cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
26568 : block);
26569 56 : if (ret == NULL)
26570 : return ret;
26571 : /* masked does have just filter clause, but during gimplification
26572 : isn't represented by a gimplification omp context, so for
26573 : #pragma omp parallel masked don't set OMP_PARALLEL_COMBINED,
26574 : so that
26575 : #pragma omp parallel masked
26576 : #pragma omp taskloop simd lastprivate (x)
26577 : isn't confused with
26578 : #pragma omp parallel masked taskloop simd lastprivate (x) */
26579 56 : if (OMP_MASKED_COMBINED (ret))
26580 47 : OMP_PARALLEL_COMBINED (stmt) = 1;
26581 : return stmt;
26582 : }
26583 662 : else if (cclauses == NULL && strcmp (p, "master") == 0)
26584 : {
26585 91 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26586 91 : cclauses = cclauses_buf;
26587 :
26588 91 : c_parser_consume_token (parser);
26589 91 : if (!flag_openmp) /* flag_openmp_simd */
26590 3 : return c_parser_omp_master (loc, parser, p_name, mask, cclauses,
26591 3 : if_p, ploc);
26592 88 : block = c_begin_omp_parallel ();
26593 88 : tree ret = c_parser_omp_master (loc, parser, p_name, mask, cclauses,
26594 : if_p, ploc);
26595 88 : stmt = c_finish_omp_parallel (loc,
26596 : cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
26597 : block);
26598 88 : if (ret == NULL)
26599 : return ret;
26600 : /* master doesn't have any clauses and during gimplification
26601 : isn't represented by a gimplification omp context, so for
26602 : #pragma omp parallel master don't set OMP_PARALLEL_COMBINED,
26603 : so that
26604 : #pragma omp parallel master
26605 : #pragma omp taskloop simd lastprivate (x)
26606 : isn't confused with
26607 : #pragma omp parallel master taskloop simd lastprivate (x) */
26608 88 : if (OMP_MASTER_COMBINED (ret))
26609 45 : OMP_PARALLEL_COMBINED (stmt) = 1;
26610 : return stmt;
26611 : }
26612 609 : else if (strcmp (p, "loop") == 0)
26613 : {
26614 43 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26615 43 : if (cclauses == NULL)
26616 24 : cclauses = cclauses_buf;
26617 :
26618 43 : c_parser_consume_token (parser);
26619 43 : if (!flag_openmp) /* flag_openmp_simd */
26620 2 : return c_parser_omp_loop (loc, parser, p_name, mask, cclauses,
26621 2 : if_p);
26622 41 : block = c_begin_omp_parallel ();
26623 41 : tree ret = c_parser_omp_loop (loc, parser, p_name, mask, cclauses,
26624 : if_p);
26625 41 : stmt
26626 41 : = c_finish_omp_parallel (loc,
26627 : cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
26628 : block);
26629 41 : if (ret == NULL_TREE)
26630 : return ret;
26631 41 : OMP_PARALLEL_COMBINED (stmt) = 1;
26632 41 : return stmt;
26633 : }
26634 566 : else if (!flag_openmp) /* flag_openmp_simd */
26635 : {
26636 1 : c_parser_skip_to_pragma_eol (parser, false);
26637 1 : return NULL_TREE;
26638 : }
26639 565 : else if (cclauses == NULL && strcmp (p, "sections") == 0)
26640 : {
26641 36 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
26642 36 : cclauses = cclauses_buf;
26643 :
26644 36 : c_parser_consume_token (parser);
26645 36 : block = c_begin_omp_parallel ();
26646 36 : c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
26647 36 : stmt = c_finish_omp_parallel (loc,
26648 : cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
26649 : block);
26650 36 : OMP_PARALLEL_COMBINED (stmt) = 1;
26651 36 : return stmt;
26652 : }
26653 : }
26654 618 : else if (!flag_openmp) /* flag_openmp_simd */
26655 : {
26656 1 : c_parser_skip_to_pragma_eol (parser, false);
26657 1 : return NULL_TREE;
26658 : }
26659 :
26660 1146 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
26661 1146 : if (cclauses)
26662 : {
26663 23 : omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses);
26664 23 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
26665 : }
26666 :
26667 1146 : block = c_begin_omp_parallel ();
26668 1146 : parser->omp_attrs_forbidden_p = true;
26669 1146 : c_parser_statement (parser, if_p);
26670 1146 : stmt = c_finish_omp_parallel (loc, clauses, block);
26671 :
26672 1146 : return stmt;
26673 : }
26674 :
26675 : /* OpenMP 2.5:
26676 : # pragma omp single single-clause[optseq] new-line
26677 : structured-block
26678 :
26679 : LOC is the location of the #pragma.
26680 : */
26681 :
26682 : #define OMP_SINGLE_CLAUSE_MASK \
26683 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
26684 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
26685 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
26686 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
26687 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
26688 :
26689 : static tree
26690 230 : c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p)
26691 : {
26692 230 : tree stmt = make_node (OMP_SINGLE);
26693 230 : SET_EXPR_LOCATION (stmt, loc);
26694 230 : TREE_TYPE (stmt) = void_type_node;
26695 :
26696 230 : OMP_SINGLE_CLAUSES (stmt)
26697 230 : = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
26698 : "#pragma omp single");
26699 230 : OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
26700 :
26701 230 : return add_stmt (stmt);
26702 : }
26703 :
26704 : /* OpenMP 5.1:
26705 : # pragma omp scope scope-clause[optseq] new-line
26706 : structured-block
26707 :
26708 : LOC is the location of the #pragma.
26709 : */
26710 :
26711 : #define OMP_SCOPE_CLAUSE_MASK \
26712 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
26713 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
26714 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
26715 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
26716 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
26717 :
26718 : static tree
26719 68 : c_parser_omp_scope (location_t loc, c_parser *parser, bool *if_p)
26720 : {
26721 68 : tree stmt = make_node (OMP_SCOPE);
26722 68 : SET_EXPR_LOCATION (stmt, loc);
26723 68 : TREE_TYPE (stmt) = void_type_node;
26724 :
26725 68 : OMP_SCOPE_CLAUSES (stmt)
26726 68 : = c_parser_omp_all_clauses (parser, OMP_SCOPE_CLAUSE_MASK,
26727 : "#pragma omp scope");
26728 68 : OMP_SCOPE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
26729 :
26730 68 : return add_stmt (stmt);
26731 : }
26732 :
26733 : /* Parse a function dispatch structured block:
26734 :
26735 : lvalue-expression = target-call ( [expression-list] );
26736 : or
26737 : target-call ( [expression-list] );
26738 :
26739 : Adapted from c_parser_expr_no_commas and c_parser_postfix_expression
26740 : (CPP_NAME/C_ID_ID) for the function name.
26741 : */
26742 : static tree
26743 155 : c_parser_omp_dispatch_body (c_parser *parser)
26744 : {
26745 155 : struct c_expr lhs, rhs, ret;
26746 155 : location_t expr_loc = c_parser_peek_token (parser)->location;
26747 155 : source_range tok_range = c_parser_peek_token (parser)->get_range ();
26748 :
26749 155 : lhs = c_parser_conditional_expression (parser, NULL, NULL);
26750 155 : if (TREE_CODE (lhs.value) == CALL_EXPR)
26751 : return lhs.value;
26752 :
26753 56 : location_t op_location = c_parser_peek_token (parser)->location;
26754 56 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
26755 4 : return error_mark_node;
26756 :
26757 : /* Parse function name. */
26758 52 : if (!c_parser_next_token_is (parser, CPP_NAME))
26759 : {
26760 1 : c_parser_error (parser, "expected a function name");
26761 1 : return error_mark_node;
26762 : }
26763 51 : expr_loc = c_parser_peek_token (parser)->location;
26764 51 : tree id = c_parser_peek_token (parser)->value;
26765 51 : c_parser_consume_token (parser);
26766 51 : if (!c_parser_next_token_is (parser, CPP_OPEN_PAREN))
26767 : {
26768 1 : c_parser_error (parser, "expected a function name");
26769 1 : return error_mark_node;
26770 : }
26771 :
26772 50 : rhs.value = build_external_ref (expr_loc, id, true, &rhs.original_type);
26773 50 : set_c_expr_source_range (&rhs, tok_range);
26774 :
26775 : /* Parse argument list. */
26776 50 : rhs = c_parser_postfix_expression_after_primary (
26777 50 : parser, EXPR_LOC_OR_LOC (rhs.value, expr_loc), rhs);
26778 50 : if (TREE_CODE (rhs.value) != CALL_EXPR)
26779 : {
26780 0 : error_at (EXPR_LOC_OR_LOC (rhs.value, expr_loc),
26781 : "expected target-function call");
26782 0 : return error_mark_node;
26783 : }
26784 :
26785 : /* Build assignment. */
26786 50 : rhs = convert_lvalue_to_rvalue (expr_loc, rhs, true, true);
26787 50 : ret.value
26788 50 : = build_modify_expr (op_location, lhs.value, lhs.original_type, NOP_EXPR,
26789 : expr_loc, rhs.value, rhs.original_type);
26790 50 : ret.m_decimal = 0;
26791 50 : set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ());
26792 50 : ret.original_code = MODIFY_EXPR;
26793 50 : ret.original_type = NULL;
26794 50 : return ret.value;
26795 : }
26796 :
26797 : /* OpenMP 5.1:
26798 : # pragma omp dispatch dispatch-clause[optseq] new-line
26799 : expression-stmt
26800 :
26801 : LOC is the location of the #pragma.
26802 : */
26803 :
26804 : #define OMP_DISPATCH_CLAUSE_MASK \
26805 : ((OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
26806 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
26807 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOVARIANTS) \
26808 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOCONTEXT) \
26809 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR) \
26810 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INTEROP) \
26811 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR) \
26812 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
26813 :
26814 : static tree
26815 155 : c_parser_omp_dispatch (location_t loc, c_parser *parser)
26816 : {
26817 155 : tree stmt = make_node (OMP_DISPATCH);
26818 155 : SET_EXPR_LOCATION (stmt, loc);
26819 155 : TREE_TYPE (stmt) = void_type_node;
26820 :
26821 155 : OMP_DISPATCH_CLAUSES (stmt)
26822 155 : = c_parser_omp_all_clauses (parser, OMP_DISPATCH_CLAUSE_MASK,
26823 : "#pragma omp dispatch");
26824 :
26825 : // Extract depend clauses and create taskwait
26826 155 : tree depend_clauses = NULL_TREE;
26827 155 : tree *depend_clauses_ptr = &depend_clauses;
26828 342 : for (tree c = OMP_DISPATCH_CLAUSES (stmt); c; c = OMP_CLAUSE_CHAIN (c))
26829 : {
26830 187 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
26831 : {
26832 5 : *depend_clauses_ptr = c;
26833 5 : depend_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
26834 : }
26835 : }
26836 155 : if (depend_clauses != NULL_TREE)
26837 : {
26838 5 : tree stmt = make_node (OMP_TASK);
26839 5 : TREE_TYPE (stmt) = void_node;
26840 5 : OMP_TASK_CLAUSES (stmt) = depend_clauses;
26841 5 : OMP_TASK_BODY (stmt) = NULL_TREE;
26842 5 : SET_EXPR_LOCATION (stmt, loc);
26843 5 : add_stmt (stmt);
26844 : }
26845 :
26846 : // Parse body as expression statement
26847 155 : loc = c_parser_peek_token (parser)->location;
26848 155 : tree dispatch_body = c_parser_omp_dispatch_body (parser);
26849 155 : if (dispatch_body == error_mark_node)
26850 : {
26851 6 : inform (loc, "%<#pragma omp dispatch%> must be followed by a function "
26852 : "call with optional assignment");
26853 6 : c_parser_skip_to_end_of_block_or_statement (parser);
26854 6 : return NULL_TREE;
26855 : }
26856 :
26857 : // Walk the tree to find the dispatch function call and wrap it into an IFN
26858 149 : gcc_assert (TREE_CODE (dispatch_body) == CALL_EXPR
26859 : || TREE_CODE (dispatch_body) == MODIFY_EXPR);
26860 149 : tree *dispatch_call = TREE_CODE (dispatch_body) == MODIFY_EXPR
26861 149 : ? &TREE_OPERAND (dispatch_body, 1)
26862 149 : : &dispatch_body;
26863 154 : while (TREE_CODE (*dispatch_call) == FLOAT_EXPR
26864 : || TREE_CODE (*dispatch_call) == CONVERT_EXPR
26865 154 : || TREE_CODE (*dispatch_call) == NOP_EXPR)
26866 5 : dispatch_call = &TREE_OPERAND (*dispatch_call, 0);
26867 149 : *dispatch_call = build_call_expr_internal_loc (
26868 : loc, IFN_GOMP_DISPATCH,
26869 149 : TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (*dispatch_call))), 1, *dispatch_call);
26870 :
26871 149 : c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
26872 149 : OMP_DISPATCH_BODY (stmt) = dispatch_body;
26873 :
26874 149 : return add_stmt (stmt);
26875 : }
26876 :
26877 : /* OpenMP 3.0:
26878 : # pragma omp task task-clause[optseq] new-line
26879 :
26880 : LOC is the location of the #pragma.
26881 : */
26882 :
26883 : #define OMP_TASK_CLAUSE_MASK \
26884 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
26885 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
26886 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
26887 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
26888 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
26889 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
26890 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
26891 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
26892 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
26893 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \
26894 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
26895 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION) \
26896 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DETACH) \
26897 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_AFFINITY))
26898 :
26899 : static tree
26900 917 : c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p)
26901 : {
26902 917 : tree clauses, block;
26903 :
26904 917 : clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
26905 : "#pragma omp task");
26906 :
26907 917 : block = c_begin_omp_task ();
26908 917 : parser->omp_attrs_forbidden_p = true;
26909 917 : c_parser_statement (parser, if_p);
26910 917 : return c_finish_omp_task (loc, clauses, block);
26911 : }
26912 :
26913 : /* OpenMP 3.0:
26914 : # pragma omp taskwait new-line
26915 :
26916 : OpenMP 5.0:
26917 : # pragma omp taskwait taskwait-clause[optseq] new-line
26918 : */
26919 :
26920 : #define OMP_TASKWAIT_CLAUSE_MASK \
26921 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
26922 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
26923 :
26924 : static void
26925 94 : c_parser_omp_taskwait (c_parser *parser)
26926 : {
26927 94 : location_t loc = c_parser_peek_token (parser)->location;
26928 94 : c_parser_consume_pragma (parser);
26929 :
26930 94 : tree clauses
26931 94 : = c_parser_omp_all_clauses (parser, OMP_TASKWAIT_CLAUSE_MASK,
26932 : "#pragma omp taskwait");
26933 :
26934 94 : if (clauses)
26935 : {
26936 21 : tree stmt = make_node (OMP_TASK);
26937 21 : TREE_TYPE (stmt) = void_node;
26938 21 : OMP_TASK_CLAUSES (stmt) = clauses;
26939 21 : OMP_TASK_BODY (stmt) = NULL_TREE;
26940 21 : SET_EXPR_LOCATION (stmt, loc);
26941 21 : add_stmt (stmt);
26942 : }
26943 : else
26944 73 : c_finish_omp_taskwait (loc);
26945 94 : }
26946 :
26947 : /* OpenMP 3.1:
26948 : # pragma omp taskyield new-line
26949 : */
26950 :
26951 : static void
26952 6 : c_parser_omp_taskyield (c_parser *parser)
26953 : {
26954 6 : location_t loc = c_parser_peek_token (parser)->location;
26955 6 : c_parser_consume_pragma (parser);
26956 6 : c_parser_skip_to_pragma_eol (parser);
26957 :
26958 6 : c_finish_omp_taskyield (loc);
26959 6 : }
26960 :
26961 : /* OpenMP 4.0:
26962 : # pragma omp taskgroup new-line
26963 :
26964 : OpenMP 5.0:
26965 : # pragma omp taskgroup taskgroup-clause[optseq] new-line
26966 : */
26967 :
26968 : #define OMP_TASKGROUP_CLAUSE_MASK \
26969 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
26970 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION))
26971 :
26972 : static tree
26973 138 : c_parser_omp_taskgroup (location_t loc, c_parser *parser, bool *if_p)
26974 : {
26975 138 : tree clauses = c_parser_omp_all_clauses (parser, OMP_TASKGROUP_CLAUSE_MASK,
26976 : "#pragma omp taskgroup");
26977 :
26978 138 : tree body = c_parser_omp_structured_block (parser, if_p);
26979 138 : return c_finish_omp_taskgroup (loc, body, clauses);
26980 : }
26981 :
26982 : /* OpenMP 4.0:
26983 : # pragma omp cancel cancel-clause[optseq] new-line
26984 :
26985 : LOC is the location of the #pragma.
26986 : */
26987 :
26988 : #define OMP_CANCEL_CLAUSE_MASK \
26989 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
26990 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
26991 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
26992 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
26993 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
26994 :
26995 : static void
26996 221 : c_parser_omp_cancel (c_parser *parser)
26997 : {
26998 221 : location_t loc = c_parser_peek_token (parser)->location;
26999 :
27000 221 : c_parser_consume_pragma (parser);
27001 221 : tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
27002 : "#pragma omp cancel");
27003 :
27004 221 : c_finish_omp_cancel (loc, clauses);
27005 221 : }
27006 :
27007 : /* OpenMP 4.0:
27008 : # pragma omp cancellation point cancelpt-clause[optseq] new-line
27009 :
27010 : LOC is the location of the #pragma.
27011 : */
27012 :
27013 : #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
27014 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
27015 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
27016 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
27017 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
27018 :
27019 : static bool
27020 179 : c_parser_omp_cancellation_point (c_parser *parser, enum pragma_context context)
27021 : {
27022 179 : location_t loc = c_parser_peek_token (parser)->location;
27023 179 : tree clauses;
27024 179 : bool point_seen = false;
27025 :
27026 179 : c_parser_consume_pragma (parser);
27027 179 : if (c_parser_next_token_is (parser, CPP_NAME))
27028 : {
27029 179 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
27030 179 : if (strcmp (p, "point") == 0)
27031 : {
27032 177 : c_parser_consume_token (parser);
27033 177 : point_seen = true;
27034 : }
27035 : }
27036 177 : if (!point_seen)
27037 : {
27038 2 : c_parser_error (parser, "expected %<point%>");
27039 2 : c_parser_skip_to_pragma_eol (parser);
27040 2 : return false;
27041 : }
27042 :
27043 177 : if (context != pragma_compound)
27044 : {
27045 10 : if (context == pragma_stmt)
27046 9 : error_at (loc,
27047 : "%<#pragma %s%> may only be used in compound statements",
27048 : "omp cancellation point");
27049 : else
27050 1 : c_parser_error (parser, "expected declaration specifiers");
27051 10 : c_parser_skip_to_pragma_eol (parser, false);
27052 10 : return true;
27053 : }
27054 :
27055 167 : clauses
27056 167 : = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
27057 : "#pragma omp cancellation point");
27058 :
27059 167 : c_finish_omp_cancellation_point (loc, clauses);
27060 167 : return true;
27061 : }
27062 :
27063 : /* OpenMP 4.0:
27064 : #pragma omp distribute distribute-clause[optseq] new-line
27065 : for-loop */
27066 :
27067 : #define OMP_DISTRIBUTE_CLAUSE_MASK \
27068 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
27069 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
27070 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
27071 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
27072 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
27073 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
27074 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDER))
27075 :
27076 : static tree
27077 3435 : c_parser_omp_distribute (location_t loc, c_parser *parser,
27078 : char *p_name, omp_clause_mask mask, tree *cclauses,
27079 : bool *if_p)
27080 : {
27081 3435 : tree clauses, block, ret;
27082 :
27083 3435 : strcat (p_name, " distribute");
27084 3435 : mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
27085 :
27086 3435 : if (c_parser_next_token_is (parser, CPP_NAME))
27087 : {
27088 3335 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
27089 3335 : bool simd = false;
27090 3335 : bool parallel = false;
27091 :
27092 3335 : if (strcmp (p, "simd") == 0)
27093 : simd = true;
27094 : else
27095 2995 : parallel = strcmp (p, "parallel") == 0;
27096 2995 : if (parallel || simd)
27097 : {
27098 3064 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
27099 3064 : if (cclauses == NULL)
27100 1147 : cclauses = cclauses_buf;
27101 3064 : c_parser_consume_token (parser);
27102 3064 : if (!flag_openmp) /* flag_openmp_simd */
27103 : {
27104 15 : if (simd)
27105 6 : return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
27106 6 : if_p);
27107 : else
27108 9 : return c_parser_omp_parallel (loc, parser, p_name, mask,
27109 9 : cclauses, if_p);
27110 : }
27111 3049 : block = c_begin_compound_stmt (true);
27112 3049 : if (simd)
27113 334 : ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
27114 : if_p);
27115 : else
27116 2715 : ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses,
27117 : if_p);
27118 3049 : block = c_end_compound_stmt (loc, block, true);
27119 3049 : if (ret == NULL)
27120 : return ret;
27121 3044 : ret = make_node (OMP_DISTRIBUTE);
27122 3044 : TREE_TYPE (ret) = void_type_node;
27123 3044 : OMP_FOR_BODY (ret) = block;
27124 3044 : OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
27125 3044 : SET_EXPR_LOCATION (ret, loc);
27126 3044 : add_stmt (ret);
27127 3044 : return ret;
27128 : }
27129 : }
27130 371 : if (!flag_openmp) /* flag_openmp_simd */
27131 : {
27132 2 : c_parser_skip_to_pragma_eol (parser, false);
27133 2 : return NULL_TREE;
27134 : }
27135 :
27136 369 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
27137 369 : if (cclauses)
27138 : {
27139 194 : omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
27140 194 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
27141 : }
27142 :
27143 369 : block = c_begin_compound_stmt (true);
27144 369 : ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL,
27145 : if_p);
27146 369 : block = c_end_compound_stmt (loc, block, true);
27147 369 : add_stmt (block);
27148 :
27149 369 : return ret;
27150 : }
27151 :
27152 : /* OpenMP 4.0:
27153 : # pragma omp teams teams-clause[optseq] new-line
27154 : structured-block */
27155 :
27156 : #define OMP_TEAMS_CLAUSE_MASK \
27157 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
27158 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
27159 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
27160 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
27161 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
27162 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
27163 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
27164 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
27165 :
27166 : static tree
27167 3684 : c_parser_omp_teams (location_t loc, c_parser *parser,
27168 : char *p_name, omp_clause_mask mask, tree *cclauses,
27169 : bool *if_p)
27170 : {
27171 3684 : tree clauses, block, ret;
27172 :
27173 3684 : strcat (p_name, " teams");
27174 3684 : mask |= OMP_TEAMS_CLAUSE_MASK;
27175 :
27176 3684 : if (c_parser_next_token_is (parser, CPP_NAME))
27177 : {
27178 2346 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
27179 2346 : if (strcmp (p, "distribute") == 0)
27180 : {
27181 2113 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
27182 2113 : if (cclauses == NULL)
27183 1271 : cclauses = cclauses_buf;
27184 :
27185 2113 : c_parser_consume_token (parser);
27186 2113 : if (!flag_openmp) /* flag_openmp_simd */
27187 12 : return c_parser_omp_distribute (loc, parser, p_name, mask,
27188 12 : cclauses, if_p);
27189 2101 : block = c_begin_omp_parallel ();
27190 2101 : ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses,
27191 : if_p);
27192 2101 : block = c_end_compound_stmt (loc, block, true);
27193 2101 : if (ret == NULL)
27194 : return ret;
27195 2101 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
27196 2101 : ret = make_node (OMP_TEAMS);
27197 2101 : TREE_TYPE (ret) = void_type_node;
27198 2101 : OMP_TEAMS_CLAUSES (ret) = clauses;
27199 2101 : OMP_TEAMS_BODY (ret) = block;
27200 2101 : OMP_TEAMS_COMBINED (ret) = 1;
27201 2101 : SET_EXPR_LOCATION (ret, loc);
27202 2101 : return add_stmt (ret);
27203 : }
27204 233 : else if (strcmp (p, "loop") == 0)
27205 : {
27206 34 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
27207 34 : if (cclauses == NULL)
27208 16 : cclauses = cclauses_buf;
27209 :
27210 34 : c_parser_consume_token (parser);
27211 34 : if (!flag_openmp) /* flag_openmp_simd */
27212 2 : return c_parser_omp_loop (loc, parser, p_name, mask, cclauses,
27213 2 : if_p);
27214 32 : block = c_begin_omp_parallel ();
27215 32 : ret = c_parser_omp_loop (loc, parser, p_name, mask, cclauses, if_p);
27216 32 : block = c_end_compound_stmt (loc, block, true);
27217 32 : if (ret == NULL)
27218 : return ret;
27219 32 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
27220 32 : ret = make_node (OMP_TEAMS);
27221 32 : TREE_TYPE (ret) = void_type_node;
27222 32 : OMP_TEAMS_CLAUSES (ret) = clauses;
27223 32 : OMP_TEAMS_BODY (ret) = block;
27224 32 : OMP_TEAMS_COMBINED (ret) = 1;
27225 32 : SET_EXPR_LOCATION (ret, loc);
27226 32 : return add_stmt (ret);
27227 : }
27228 : }
27229 1537 : if (!flag_openmp) /* flag_openmp_simd */
27230 : {
27231 2 : c_parser_skip_to_pragma_eol (parser, false);
27232 2 : return NULL_TREE;
27233 : }
27234 :
27235 1535 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
27236 1535 : if (cclauses)
27237 : {
27238 886 : omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
27239 886 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
27240 : }
27241 :
27242 1535 : tree stmt = make_node (OMP_TEAMS);
27243 1535 : TREE_TYPE (stmt) = void_type_node;
27244 1535 : OMP_TEAMS_CLAUSES (stmt) = clauses;
27245 1535 : block = c_begin_omp_parallel ();
27246 1535 : add_stmt (c_parser_omp_structured_block (parser, if_p));
27247 1535 : OMP_TEAMS_BODY (stmt) = c_end_compound_stmt (loc, block, true);
27248 1535 : SET_EXPR_LOCATION (stmt, loc);
27249 :
27250 1535 : return add_stmt (stmt);
27251 : }
27252 :
27253 : /* OpenMP 4.0:
27254 : # pragma omp target data target-data-clause[optseq] new-line
27255 : structured-block */
27256 :
27257 : #define OMP_TARGET_DATA_CLAUSE_MASK \
27258 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
27259 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
27260 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
27261 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR) \
27262 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_ADDR))
27263 :
27264 : static tree
27265 160 : c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p)
27266 : {
27267 160 : if (flag_openmp)
27268 160 : omp_requires_mask
27269 160 : = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
27270 :
27271 160 : tree clauses
27272 160 : = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
27273 : "#pragma omp target data", false);
27274 160 : clauses = c_omp_instantiate_mappers (clauses, C_ORT_OMP);
27275 160 : clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
27276 160 : c_omp_adjust_map_clauses (clauses, false);
27277 160 : int map_seen = 0;
27278 632 : for (tree *pc = &clauses; *pc;)
27279 : {
27280 312 : if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
27281 230 : switch (OMP_CLAUSE_MAP_KIND (*pc))
27282 : {
27283 : case GOMP_MAP_TO:
27284 : case GOMP_MAP_ALWAYS_TO:
27285 : case GOMP_MAP_PRESENT_TO:
27286 : case GOMP_MAP_ALWAYS_PRESENT_TO:
27287 : case GOMP_MAP_FROM:
27288 : case GOMP_MAP_ALWAYS_FROM:
27289 : case GOMP_MAP_PRESENT_FROM:
27290 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
27291 : case GOMP_MAP_TOFROM:
27292 : case GOMP_MAP_ALWAYS_TOFROM:
27293 : case GOMP_MAP_PRESENT_TOFROM:
27294 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
27295 : case GOMP_MAP_ALLOC:
27296 : case GOMP_MAP_PRESENT_ALLOC:
27297 312 : map_seen = 3;
27298 : break;
27299 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
27300 : case GOMP_MAP_ALWAYS_POINTER:
27301 : case GOMP_MAP_ATTACH_DETACH:
27302 : case GOMP_MAP_ATTACH:
27303 : break;
27304 0 : default:
27305 0 : map_seen |= 1;
27306 0 : error_at (OMP_CLAUSE_LOCATION (*pc),
27307 : "%<#pragma omp target data%> with map-type other "
27308 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
27309 : "on %<map%> clause");
27310 0 : *pc = OMP_CLAUSE_CHAIN (*pc);
27311 0 : continue;
27312 : }
27313 82 : else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_PTR
27314 82 : || OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_ADDR)
27315 : map_seen = 3;
27316 312 : pc = &OMP_CLAUSE_CHAIN (*pc);
27317 : }
27318 :
27319 160 : if (map_seen != 3)
27320 : {
27321 3 : if (map_seen == 0)
27322 3 : error_at (loc,
27323 : "%<#pragma omp target data%> must contain at least "
27324 : "one %<map%>, %<use_device_ptr%> or %<use_device_addr%> "
27325 : "clause");
27326 : return NULL_TREE;
27327 : }
27328 :
27329 157 : tree stmt = make_node (OMP_TARGET_DATA);
27330 157 : TREE_TYPE (stmt) = void_type_node;
27331 157 : OMP_TARGET_DATA_CLAUSES (stmt) = clauses;
27332 157 : keep_next_level ();
27333 157 : tree block = c_begin_compound_stmt (true);
27334 157 : add_stmt (c_parser_omp_structured_block (parser, if_p));
27335 157 : OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
27336 :
27337 157 : SET_EXPR_LOCATION (stmt, loc);
27338 157 : return add_stmt (stmt);
27339 : }
27340 :
27341 : /* OpenMP 4.0:
27342 : # pragma omp target update target-update-clause[optseq] new-line */
27343 :
27344 : #define OMP_TARGET_UPDATE_CLAUSE_MASK \
27345 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
27346 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
27347 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
27348 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
27349 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
27350 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
27351 :
27352 : static bool
27353 2859 : c_parser_omp_target_update (location_t loc, c_parser *parser,
27354 : enum pragma_context context)
27355 : {
27356 2859 : if (context == pragma_stmt)
27357 : {
27358 8 : error_at (loc, "%<#pragma %s%> may only be used in compound statements",
27359 : "omp target update");
27360 8 : c_parser_skip_to_pragma_eol (parser, false);
27361 8 : return true;
27362 : }
27363 :
27364 2851 : tree clauses
27365 2851 : = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
27366 : "#pragma omp target update",
27367 : /* finish_p = */ false);
27368 2851 : clauses = c_omp_instantiate_mappers (clauses, C_ORT_OMP_UPDATE);
27369 2851 : clauses = c_finish_omp_clauses (clauses, C_ORT_OMP_UPDATE);
27370 :
27371 2851 : if (omp_find_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
27372 2851 : && omp_find_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
27373 : {
27374 5 : error_at (loc,
27375 : "%<#pragma omp target update%> must contain at least one "
27376 : "%<from%> or %<to%> clauses");
27377 5 : return false;
27378 : }
27379 :
27380 2846 : if (flag_openmp)
27381 2846 : omp_requires_mask
27382 2846 : = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
27383 :
27384 2846 : tree stmt = make_node (OMP_TARGET_UPDATE);
27385 2846 : TREE_TYPE (stmt) = void_type_node;
27386 2846 : OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
27387 2846 : SET_EXPR_LOCATION (stmt, loc);
27388 2846 : add_stmt (stmt);
27389 2846 : return false;
27390 : }
27391 :
27392 : /* OpenMP 4.5:
27393 : # pragma omp target enter data target-data-clause[optseq] new-line */
27394 :
27395 : #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
27396 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
27397 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
27398 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
27399 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
27400 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
27401 :
27402 : static bool
27403 152 : c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
27404 : enum pragma_context context)
27405 : {
27406 152 : bool data_seen = false;
27407 152 : if (c_parser_next_token_is (parser, CPP_NAME))
27408 : {
27409 152 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
27410 152 : if (strcmp (p, "data") == 0)
27411 : {
27412 152 : c_parser_consume_token (parser);
27413 152 : data_seen = true;
27414 : }
27415 : }
27416 152 : if (!data_seen)
27417 : {
27418 0 : c_parser_error (parser, "expected %<data%>");
27419 0 : c_parser_skip_to_pragma_eol (parser);
27420 0 : return false;
27421 : }
27422 :
27423 152 : if (context == pragma_stmt)
27424 : {
27425 8 : error_at (loc, "%<#pragma %s%> may only be used in compound statements",
27426 : "omp target enter data");
27427 8 : c_parser_skip_to_pragma_eol (parser, false);
27428 8 : return true;
27429 : }
27430 :
27431 144 : if (flag_openmp)
27432 144 : omp_requires_mask
27433 144 : = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
27434 :
27435 144 : tree clauses
27436 144 : = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK,
27437 : "#pragma omp target enter data", false);
27438 144 : clauses = c_omp_instantiate_mappers (clauses, C_ORT_OMP);
27439 144 : clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
27440 144 : c_omp_adjust_map_clauses (clauses, false);
27441 144 : int map_seen = 0;
27442 640 : for (tree *pc = &clauses; *pc;)
27443 : {
27444 352 : if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
27445 301 : switch (OMP_CLAUSE_MAP_KIND (*pc))
27446 : {
27447 : case GOMP_MAP_TO:
27448 : case GOMP_MAP_ALWAYS_TO:
27449 : case GOMP_MAP_PRESENT_TO:
27450 : case GOMP_MAP_ALWAYS_PRESENT_TO:
27451 : case GOMP_MAP_ALLOC:
27452 : case GOMP_MAP_PRESENT_ALLOC:
27453 350 : map_seen = 3;
27454 : break;
27455 36 : case GOMP_MAP_TOFROM:
27456 36 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_TO);
27457 36 : map_seen = 3;
27458 36 : break;
27459 3 : case GOMP_MAP_ALWAYS_TOFROM:
27460 3 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_TO);
27461 3 : map_seen = 3;
27462 3 : break;
27463 2 : case GOMP_MAP_PRESENT_TOFROM:
27464 2 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_PRESENT_TO);
27465 2 : map_seen = 3;
27466 2 : break;
27467 2 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
27468 2 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_PRESENT_TO);
27469 2 : map_seen = 3;
27470 2 : break;
27471 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
27472 : case GOMP_MAP_ALWAYS_POINTER:
27473 : case GOMP_MAP_ATTACH_DETACH:
27474 : case GOMP_MAP_ATTACH:
27475 : break;
27476 2 : default:
27477 2 : map_seen |= 1;
27478 2 : error_at (OMP_CLAUSE_LOCATION (*pc),
27479 : "%<#pragma omp target enter data%> with map-type other "
27480 : "than %<to%>, %<tofrom%> or %<alloc%> on %<map%> clause");
27481 2 : *pc = OMP_CLAUSE_CHAIN (*pc);
27482 2 : continue;
27483 : }
27484 350 : pc = &OMP_CLAUSE_CHAIN (*pc);
27485 : }
27486 :
27487 144 : if (map_seen != 3)
27488 : {
27489 4 : if (map_seen == 0)
27490 2 : error_at (loc,
27491 : "%<#pragma omp target enter data%> must contain at least "
27492 : "one %<map%> clause");
27493 : return true;
27494 : }
27495 :
27496 140 : tree stmt = make_node (OMP_TARGET_ENTER_DATA);
27497 140 : TREE_TYPE (stmt) = void_type_node;
27498 140 : OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses;
27499 140 : SET_EXPR_LOCATION (stmt, loc);
27500 140 : add_stmt (stmt);
27501 140 : return true;
27502 : }
27503 :
27504 : /* OpenMP 4.5:
27505 : # pragma omp target exit data target-data-clause[optseq] new-line */
27506 :
27507 : #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
27508 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
27509 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
27510 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
27511 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
27512 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
27513 :
27514 : static bool
27515 130 : c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
27516 : enum pragma_context context)
27517 : {
27518 130 : bool data_seen = false;
27519 130 : if (c_parser_next_token_is (parser, CPP_NAME))
27520 : {
27521 130 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
27522 130 : if (strcmp (p, "data") == 0)
27523 : {
27524 130 : c_parser_consume_token (parser);
27525 130 : data_seen = true;
27526 : }
27527 : }
27528 130 : if (!data_seen)
27529 : {
27530 0 : c_parser_error (parser, "expected %<data%>");
27531 0 : c_parser_skip_to_pragma_eol (parser);
27532 0 : return false;
27533 : }
27534 :
27535 130 : if (context == pragma_stmt)
27536 : {
27537 8 : error_at (loc, "%<#pragma %s%> may only be used in compound statements",
27538 : "omp target exit data");
27539 8 : c_parser_skip_to_pragma_eol (parser, false);
27540 8 : return true;
27541 : }
27542 :
27543 122 : if (flag_openmp)
27544 122 : omp_requires_mask
27545 122 : = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
27546 :
27547 122 : tree clauses
27548 122 : = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK,
27549 : "#pragma omp target exit data", false);
27550 122 : clauses = c_omp_instantiate_mappers (clauses, C_ORT_OMP_EXIT_DATA);
27551 122 : clauses = c_finish_omp_clauses (clauses, C_ORT_OMP_EXIT_DATA);
27552 122 : c_omp_adjust_map_clauses (clauses, false);
27553 122 : int map_seen = 0;
27554 546 : for (tree *pc = &clauses; *pc;)
27555 : {
27556 302 : if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
27557 251 : switch (OMP_CLAUSE_MAP_KIND (*pc))
27558 : {
27559 : case GOMP_MAP_FROM:
27560 : case GOMP_MAP_ALWAYS_FROM:
27561 : case GOMP_MAP_PRESENT_FROM:
27562 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
27563 : case GOMP_MAP_RELEASE:
27564 : case GOMP_MAP_DELETE:
27565 300 : map_seen = 3;
27566 : break;
27567 30 : case GOMP_MAP_TOFROM:
27568 30 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_FROM);
27569 30 : map_seen = 3;
27570 30 : break;
27571 1 : case GOMP_MAP_ALWAYS_TOFROM:
27572 1 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_FROM);
27573 1 : map_seen = 3;
27574 1 : break;
27575 0 : case GOMP_MAP_PRESENT_TOFROM:
27576 0 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_PRESENT_FROM);
27577 0 : map_seen = 3;
27578 0 : break;
27579 0 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
27580 0 : OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_PRESENT_FROM);
27581 0 : map_seen = 3;
27582 0 : break;
27583 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
27584 : case GOMP_MAP_ALWAYS_POINTER:
27585 : case GOMP_MAP_ATTACH_DETACH:
27586 : case GOMP_MAP_DETACH:
27587 : break;
27588 2 : default:
27589 2 : map_seen |= 1;
27590 2 : error_at (OMP_CLAUSE_LOCATION (*pc),
27591 : "%<#pragma omp target exit data%> with map-type other "
27592 : "than %<from%>, %<tofrom%>, %<release%> or %<delete%> "
27593 : "on %<map%> clause");
27594 2 : *pc = OMP_CLAUSE_CHAIN (*pc);
27595 2 : continue;
27596 : }
27597 300 : pc = &OMP_CLAUSE_CHAIN (*pc);
27598 : }
27599 :
27600 122 : if (map_seen != 3)
27601 : {
27602 2 : if (map_seen == 0)
27603 0 : error_at (loc,
27604 : "%<#pragma omp target exit data%> must contain at least one "
27605 : "%<map%> clause");
27606 : return true;
27607 : }
27608 :
27609 120 : tree stmt = make_node (OMP_TARGET_EXIT_DATA);
27610 120 : TREE_TYPE (stmt) = void_type_node;
27611 120 : OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses;
27612 120 : SET_EXPR_LOCATION (stmt, loc);
27613 120 : add_stmt (stmt);
27614 120 : return true;
27615 : }
27616 :
27617 : /* OpenMP 4.0:
27618 : # pragma omp target target-clause[optseq] new-line
27619 : structured-block */
27620 :
27621 : #define OMP_TARGET_CLAUSE_MASK \
27622 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
27623 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
27624 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
27625 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
27626 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE) \
27627 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DYN_GROUPPRIVATE) \
27628 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
27629 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR) \
27630 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
27631 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION) \
27632 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR)\
27633 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
27634 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
27635 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
27636 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
27637 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USES_ALLOCATORS))
27638 :
27639 : static bool
27640 7763 : c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p)
27641 : {
27642 7763 : location_t loc = c_parser_peek_token (parser)->location;
27643 7763 : c_parser_consume_pragma (parser);
27644 7763 : tree *pc = NULL, stmt, block, body, clauses;
27645 :
27646 7763 : if (context != pragma_stmt && context != pragma_compound)
27647 : {
27648 2 : c_parser_error (parser, "expected declaration specifiers");
27649 2 : c_parser_skip_to_pragma_eol (parser);
27650 2 : return false;
27651 : }
27652 :
27653 7761 : if (flag_openmp)
27654 7747 : omp_requires_mask
27655 7747 : = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
27656 :
27657 7761 : if (c_parser_next_token_is (parser, CPP_NAME))
27658 : {
27659 6815 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
27660 6815 : enum tree_code ccode = ERROR_MARK;
27661 :
27662 6815 : if (strcmp (p, "teams") == 0)
27663 : ccode = OMP_TEAMS;
27664 5068 : else if (strcmp (p, "parallel") == 0)
27665 : ccode = OMP_PARALLEL;
27666 4575 : else if (strcmp (p, "simd") == 0)
27667 : ccode = OMP_SIMD;
27668 4515 : if (ccode != ERROR_MARK)
27669 : {
27670 2300 : tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
27671 2300 : char p_name[sizeof ("#pragma omp target teams distribute "
27672 : "parallel for simd")];
27673 :
27674 2300 : c_parser_consume_token (parser);
27675 2300 : strcpy (p_name, "#pragma omp target");
27676 2300 : if (!flag_openmp) /* flag_openmp_simd */
27677 : {
27678 13 : tree stmt;
27679 13 : switch (ccode)
27680 : {
27681 8 : case OMP_TEAMS:
27682 8 : stmt = c_parser_omp_teams (loc, parser, p_name,
27683 8 : OMP_TARGET_CLAUSE_MASK,
27684 : cclauses, if_p);
27685 8 : break;
27686 4 : case OMP_PARALLEL:
27687 4 : stmt = c_parser_omp_parallel (loc, parser, p_name,
27688 4 : OMP_TARGET_CLAUSE_MASK,
27689 : cclauses, if_p);
27690 4 : break;
27691 1 : case OMP_SIMD:
27692 1 : stmt = c_parser_omp_simd (loc, parser, p_name,
27693 1 : OMP_TARGET_CLAUSE_MASK,
27694 : cclauses, if_p);
27695 1 : break;
27696 : default:
27697 : gcc_unreachable ();
27698 : }
27699 21 : return stmt != NULL_TREE;
27700 : }
27701 2287 : keep_next_level ();
27702 2287 : tree block = c_begin_compound_stmt (true), ret;
27703 2287 : switch (ccode)
27704 : {
27705 1739 : case OMP_TEAMS:
27706 1739 : ret = c_parser_omp_teams (loc, parser, p_name,
27707 1739 : OMP_TARGET_CLAUSE_MASK, cclauses,
27708 : if_p);
27709 1739 : break;
27710 489 : case OMP_PARALLEL:
27711 489 : ret = c_parser_omp_parallel (loc, parser, p_name,
27712 489 : OMP_TARGET_CLAUSE_MASK, cclauses,
27713 : if_p);
27714 489 : break;
27715 59 : case OMP_SIMD:
27716 59 : ret = c_parser_omp_simd (loc, parser, p_name,
27717 59 : OMP_TARGET_CLAUSE_MASK, cclauses,
27718 : if_p);
27719 59 : break;
27720 : default:
27721 : gcc_unreachable ();
27722 : }
27723 2287 : block = c_end_compound_stmt (loc, block, true);
27724 2287 : if (ret == NULL_TREE)
27725 : return false;
27726 2279 : if (ccode == OMP_TEAMS)
27727 : /* For combined target teams, ensure the num_teams and
27728 : thread_limit clause expressions are evaluated on the host,
27729 : before entering the target construct. */
27730 2223 : for (tree c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
27731 2223 : c; c = OMP_CLAUSE_CHAIN (c))
27732 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
27733 484 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT)
27734 207 : for (int i = 0;
27735 340 : i <= (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS); ++i)
27736 207 : if (OMP_CLAUSE_OPERAND (c, i)
27737 207 : && TREE_CODE (OMP_CLAUSE_OPERAND (c, i)) != INTEGER_CST)
27738 : {
27739 129 : tree expr = OMP_CLAUSE_OPERAND (c, i);
27740 129 : tree tmp = create_tmp_var_raw (TREE_TYPE (expr));
27741 129 : expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp,
27742 : expr, NULL_TREE, NULL_TREE);
27743 129 : add_stmt (expr);
27744 129 : OMP_CLAUSE_OPERAND (c, i) = expr;
27745 129 : tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c),
27746 : OMP_CLAUSE_FIRSTPRIVATE);
27747 129 : OMP_CLAUSE_DECL (tc) = tmp;
27748 129 : OMP_CLAUSE_CHAIN (tc)
27749 129 : = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
27750 129 : cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc;
27751 : }
27752 2279 : tree stmt = make_node (OMP_TARGET);
27753 2279 : TREE_TYPE (stmt) = void_type_node;
27754 2279 : OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
27755 2279 : c_omp_adjust_map_clauses (OMP_TARGET_CLAUSES (stmt), true);
27756 2279 : OMP_TARGET_BODY (stmt) = block;
27757 2279 : OMP_TARGET_COMBINED (stmt) = 1;
27758 2279 : SET_EXPR_LOCATION (stmt, loc);
27759 2279 : add_stmt (stmt);
27760 2279 : pc = &OMP_TARGET_CLAUSES (stmt);
27761 2279 : goto check_clauses;
27762 : }
27763 4515 : else if (!flag_openmp) /* flag_openmp_simd */
27764 : {
27765 0 : c_parser_skip_to_pragma_eol (parser, false);
27766 0 : return false;
27767 : }
27768 4515 : else if (strcmp (p, "data") == 0)
27769 : {
27770 160 : c_parser_consume_token (parser);
27771 160 : c_parser_omp_target_data (loc, parser, if_p);
27772 160 : return true;
27773 : }
27774 4355 : else if (strcmp (p, "enter") == 0)
27775 : {
27776 152 : c_parser_consume_token (parser);
27777 152 : return c_parser_omp_target_enter_data (loc, parser, context);
27778 : }
27779 4203 : else if (strcmp (p, "exit") == 0)
27780 : {
27781 130 : c_parser_consume_token (parser);
27782 130 : return c_parser_omp_target_exit_data (loc, parser, context);
27783 : }
27784 4073 : else if (strcmp (p, "update") == 0)
27785 : {
27786 2859 : c_parser_consume_token (parser);
27787 2859 : return c_parser_omp_target_update (loc, parser, context);
27788 : }
27789 : }
27790 2160 : if (!flag_openmp) /* flag_openmp_simd */
27791 : {
27792 1 : c_parser_skip_to_pragma_eol (parser, false);
27793 1 : return false;
27794 : }
27795 :
27796 2159 : stmt = make_node (OMP_TARGET);
27797 2159 : TREE_TYPE (stmt) = void_type_node;
27798 :
27799 2159 : clauses = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
27800 : "#pragma omp target", false);
27801 4323 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
27802 2164 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
27803 : {
27804 50 : tree nc = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
27805 50 : OMP_CLAUSE_DECL (nc) = OMP_CLAUSE_DECL (c);
27806 50 : OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_ALWAYS_TOFROM);
27807 50 : OMP_CLAUSE_CHAIN (nc) = OMP_CLAUSE_CHAIN (c);
27808 50 : OMP_CLAUSE_CHAIN (c) = nc;
27809 : }
27810 2159 : clauses = c_omp_instantiate_mappers (clauses, C_ORT_OMP_TARGET);
27811 2159 : clauses = c_finish_omp_clauses (clauses, C_ORT_OMP_TARGET);
27812 2159 : c_omp_adjust_map_clauses (clauses, true);
27813 :
27814 2159 : keep_next_level ();
27815 2159 : block = c_begin_compound_stmt (true);
27816 2159 : body = c_parser_omp_structured_block (parser, if_p);
27817 :
27818 2159 : c_omp_scan_mapper_bindings (loc, &clauses, body);
27819 :
27820 2159 : add_stmt (body);
27821 2159 : OMP_TARGET_CLAUSES (stmt) = clauses;
27822 2159 : pc = &OMP_TARGET_CLAUSES (stmt);
27823 2159 : OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
27824 :
27825 2159 : SET_EXPR_LOCATION (stmt, loc);
27826 2159 : add_stmt (stmt);
27827 :
27828 4438 : check_clauses:
27829 8359 : while (*pc)
27830 : {
27831 3921 : if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
27832 2202 : switch (OMP_CLAUSE_MAP_KIND (*pc))
27833 : {
27834 : case GOMP_MAP_TO:
27835 : case GOMP_MAP_ALWAYS_TO:
27836 : case GOMP_MAP_PRESENT_TO:
27837 : case GOMP_MAP_ALWAYS_PRESENT_TO:
27838 : case GOMP_MAP_FROM:
27839 : case GOMP_MAP_ALWAYS_FROM:
27840 : case GOMP_MAP_PRESENT_FROM:
27841 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
27842 : case GOMP_MAP_TOFROM:
27843 : case GOMP_MAP_ALWAYS_TOFROM:
27844 : case GOMP_MAP_PRESENT_TOFROM:
27845 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
27846 : case GOMP_MAP_ALLOC:
27847 : case GOMP_MAP_PRESENT_ALLOC:
27848 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
27849 : case GOMP_MAP_ALWAYS_POINTER:
27850 : case GOMP_MAP_POINTER:
27851 : case GOMP_MAP_ATTACH_DETACH:
27852 : case GOMP_MAP_ATTACH:
27853 : break;
27854 1 : default:
27855 1 : error_at (OMP_CLAUSE_LOCATION (*pc),
27856 : "%<#pragma omp target%> with map-type other "
27857 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
27858 : "on %<map%> clause");
27859 1 : *pc = OMP_CLAUSE_CHAIN (*pc);
27860 1 : continue;
27861 : }
27862 3920 : pc = &OMP_CLAUSE_CHAIN (*pc);
27863 : }
27864 4438 : cfun->has_omp_target = true;
27865 4438 : return true;
27866 : }
27867 :
27868 : /* OpenMP 4.0:
27869 : # pragma omp declare simd declare-simd-clauses[optseq] new-line
27870 :
27871 : OpenMP 5.0:
27872 : # pragma omp declare variant (identifier) match(context-selector) new-line
27873 :
27874 : OpenMP 5.1
27875 : # pragma omp declare variant (identifier) match(context-selector) \
27876 : adjust_args(adjust-op:argument-list) append_args(interop-list) new-line
27877 : */
27878 :
27879 : #define OMP_DECLARE_SIMD_CLAUSE_MASK \
27880 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
27881 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
27882 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
27883 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
27884 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
27885 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
27886 :
27887 : static void
27888 812 : c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
27889 : {
27890 812 : c_token *token = c_parser_peek_token (parser);
27891 812 : gcc_assert (token->type == CPP_NAME);
27892 812 : tree kind = token->value;
27893 812 : gcc_assert (strcmp (IDENTIFIER_POINTER (kind), "simd") == 0
27894 : || strcmp (IDENTIFIER_POINTER (kind), "variant") == 0);
27895 :
27896 812 : auto_vec<c_token> clauses;
27897 12998 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
27898 : {
27899 12186 : c_token *token = c_parser_peek_token (parser);
27900 12186 : if (token->type == CPP_EOF)
27901 : {
27902 0 : c_parser_skip_to_pragma_eol (parser);
27903 0 : return;
27904 : }
27905 12186 : clauses.safe_push (*token);
27906 12186 : c_parser_consume_token (parser);
27907 : }
27908 812 : clauses.safe_push (*c_parser_peek_token (parser));
27909 812 : c_parser_skip_to_pragma_eol (parser);
27910 :
27911 1921 : while (c_parser_next_token_is (parser, CPP_PRAGMA))
27912 : {
27913 299 : if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_DECLARE
27914 297 : || c_parser_peek_2nd_token (parser)->type != CPP_NAME
27915 596 : || c_parser_peek_2nd_token (parser)->value != kind)
27916 : {
27917 2 : error ("%<#pragma omp declare %s%> must be followed by "
27918 : "function declaration or definition or another "
27919 : "%<#pragma omp declare %s%>",
27920 2 : IDENTIFIER_POINTER (kind), IDENTIFIER_POINTER (kind));
27921 2 : return;
27922 : }
27923 297 : c_parser_consume_pragma (parser);
27924 6459 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
27925 : {
27926 5865 : c_token *token = c_parser_peek_token (parser);
27927 5865 : if (token->type == CPP_EOF)
27928 : {
27929 0 : c_parser_skip_to_pragma_eol (parser);
27930 0 : return;
27931 : }
27932 5865 : clauses.safe_push (*token);
27933 5865 : c_parser_consume_token (parser);
27934 : }
27935 297 : clauses.safe_push (*c_parser_peek_token (parser));
27936 297 : c_parser_skip_to_pragma_eol (parser);
27937 : }
27938 :
27939 : /* Make sure nothing tries to read past the end of the tokens. */
27940 810 : c_token eof_token;
27941 810 : memset (&eof_token, 0, sizeof (eof_token));
27942 810 : eof_token.type = CPP_EOF;
27943 810 : clauses.safe_push (eof_token);
27944 810 : clauses.safe_push (eof_token);
27945 :
27946 810 : switch (context)
27947 : {
27948 793 : case pragma_external:
27949 793 : if (c_parser_next_token_is (parser, CPP_KEYWORD)
27950 793 : && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
27951 : {
27952 1 : int ext = disable_extension_diagnostics ();
27953 1 : do
27954 1 : c_parser_consume_token (parser);
27955 1 : while (c_parser_next_token_is (parser, CPP_KEYWORD)
27956 2 : && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
27957 1 : c_parser_declaration_or_fndef (parser, true, true, true, false, true,
27958 : false, NULL, &clauses);
27959 1 : restore_extension_diagnostics (ext);
27960 : }
27961 : else
27962 792 : c_parser_declaration_or_fndef (parser, true, true, true, false, true,
27963 : false, NULL, &clauses);
27964 : break;
27965 6 : case pragma_struct:
27966 6 : case pragma_param:
27967 6 : case pragma_stmt:
27968 6 : error ("%<#pragma omp declare %s%> must be followed by "
27969 : "function declaration or definition",
27970 6 : IDENTIFIER_POINTER (kind));
27971 6 : break;
27972 11 : case pragma_compound:
27973 11 : bool have_std_attrs;
27974 11 : tree std_attrs;
27975 11 : have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1);
27976 11 : if (have_std_attrs)
27977 1 : std_attrs = c_parser_std_attribute_specifier_sequence (parser);
27978 : else
27979 : std_attrs = NULL_TREE;
27980 11 : if (c_parser_next_token_is (parser, CPP_KEYWORD)
27981 11 : && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
27982 : {
27983 1 : int ext = disable_extension_diagnostics ();
27984 3 : do
27985 3 : c_parser_consume_token (parser);
27986 3 : while (c_parser_next_token_is (parser, CPP_KEYWORD)
27987 4 : && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
27988 1 : if (c_parser_next_tokens_start_declaration (parser)
27989 1 : || c_parser_nth_token_starts_std_attributes (parser, 1))
27990 : {
27991 1 : c_parser_declaration_or_fndef (parser, true, true, true, true,
27992 : true, false, NULL, &clauses,
27993 : have_std_attrs, std_attrs);
27994 1 : restore_extension_diagnostics (ext);
27995 1 : break;
27996 : }
27997 0 : restore_extension_diagnostics (ext);
27998 : }
27999 10 : else if (c_parser_next_tokens_start_declaration (parser))
28000 : {
28001 10 : c_parser_declaration_or_fndef (parser, true, true, true, true, true,
28002 : false, NULL, &clauses, have_std_attrs,
28003 : std_attrs);
28004 10 : break;
28005 : }
28006 0 : error ("%<#pragma omp declare %s%> must be followed by "
28007 : "function declaration or definition",
28008 0 : IDENTIFIER_POINTER (kind));
28009 0 : break;
28010 0 : default:
28011 0 : gcc_unreachable ();
28012 : }
28013 812 : }
28014 :
28015 : /* OpenMP 5.0:
28016 :
28017 : trait-selector:
28018 : trait-selector-name[([trait-score:]trait-property[,trait-property[,...]])]
28019 :
28020 : trait-score:
28021 : score(score-expression)
28022 :
28023 : Note that this function returns a list of trait selectors for the
28024 : trait-selector-set SET. */
28025 :
28026 : static tree
28027 1282 : c_parser_omp_context_selector (c_parser *parser, enum omp_tss_code set,
28028 : tree parms)
28029 : {
28030 1282 : tree ret = NULL_TREE;
28031 1464 : do
28032 : {
28033 1464 : tree selector;
28034 1464 : if (c_parser_next_token_is (parser, CPP_KEYWORD)
28035 2867 : || c_parser_next_token_is (parser, CPP_NAME))
28036 1462 : selector = c_parser_peek_token (parser)->value;
28037 : else
28038 : {
28039 2 : c_parser_error (parser, "expected trait selector name");
28040 2 : return error_mark_node;
28041 : }
28042 1462 : enum omp_ts_code sel
28043 1462 : = omp_lookup_ts_code (set, IDENTIFIER_POINTER (selector));
28044 :
28045 1462 : if (sel == OMP_TRAIT_INVALID)
28046 : {
28047 : /* Per the spec, "Implementations can ignore specified selectors
28048 : that are not those described in this section"; however, we
28049 : must record such selectors because they cause match failures. */
28050 18 : warning_at (c_parser_peek_token (parser)->location, OPT_Wopenmp,
28051 : "unknown selector %qs for context selector set %qs",
28052 18 : IDENTIFIER_POINTER (selector), omp_tss_map[set]);
28053 18 : c_parser_consume_token (parser);
28054 18 : ret = make_trait_selector (sel, NULL_TREE, NULL_TREE, ret);
28055 18 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
28056 5 : c_parser_balanced_token_sequence (parser);
28057 18 : if (c_parser_next_token_is (parser, CPP_COMMA))
28058 : {
28059 1 : c_parser_consume_token (parser);
28060 1 : continue;
28061 : }
28062 : else
28063 : break;
28064 : }
28065 :
28066 1444 : c_parser_consume_token (parser);
28067 :
28068 1444 : tree properties = NULL_TREE;
28069 1444 : tree scoreval = NULL_TREE;
28070 1444 : enum omp_tp_type property_kind = omp_ts_map[sel].tp_type;
28071 1444 : bool allow_score = omp_ts_map[sel].allow_score;
28072 1444 : tree t;
28073 :
28074 1444 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
28075 : {
28076 826 : if (property_kind == OMP_TRAIT_PROPERTY_NONE)
28077 : {
28078 12 : error_at (c_parser_peek_token (parser)->location,
28079 : "selector %qs does not accept any properties",
28080 6 : IDENTIFIER_POINTER (selector));
28081 16 : return error_mark_node;
28082 : }
28083 :
28084 820 : matching_parens parens;
28085 820 : parens.require_open (parser);
28086 :
28087 820 : c_token *token = c_parser_peek_token (parser);
28088 820 : if (c_parser_next_token_is (parser, CPP_NAME)
28089 627 : && strcmp (IDENTIFIER_POINTER (token->value), "score") == 0
28090 913 : && c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN)
28091 : {
28092 93 : c_parser_consume_token (parser);
28093 :
28094 93 : matching_parens parens2;
28095 93 : parens2.require_open (parser);
28096 93 : tree score = c_parser_expr_no_commas (parser, NULL).value;
28097 93 : parens2.skip_until_found_close (parser);
28098 93 : c_parser_require (parser, CPP_COLON, "expected %<:%>");
28099 93 : if (!allow_score)
28100 13 : error_at (token->location,
28101 : "%<score%> cannot be specified in traits "
28102 : "in the %qs trait-selector-set",
28103 : omp_tss_map[set]);
28104 80 : else if (score != error_mark_node)
28105 : {
28106 80 : mark_exp_read (score);
28107 80 : score = c_fully_fold (score, false, NULL);
28108 160 : if (!INTEGRAL_TYPE_P (TREE_TYPE (score))
28109 159 : || TREE_CODE (score) != INTEGER_CST)
28110 1 : error_at (token->location, "%<score%> argument must "
28111 : "be constant integer expression");
28112 79 : else if (tree_int_cst_sgn (score) < 0)
28113 1 : error_at (token->location, "%<score%> argument must "
28114 : "be non-negative");
28115 : else
28116 : scoreval = score;
28117 : }
28118 93 : token = c_parser_peek_token (parser);
28119 : }
28120 :
28121 820 : switch (property_kind)
28122 : {
28123 25 : case OMP_TRAIT_PROPERTY_ID:
28124 25 : if (c_parser_next_token_is (parser, CPP_KEYWORD)
28125 50 : || c_parser_next_token_is (parser, CPP_NAME))
28126 : {
28127 24 : tree prop = c_parser_peek_token (parser)->value;
28128 24 : c_parser_consume_token (parser);
28129 24 : properties = make_trait_property (prop, NULL_TREE,
28130 : properties);
28131 : }
28132 : else
28133 : {
28134 1 : c_parser_error (parser, "expected identifier");
28135 1 : return error_mark_node;
28136 : }
28137 24 : break;
28138 701 : case OMP_TRAIT_PROPERTY_NAME_LIST:
28139 759 : do
28140 : {
28141 701 : tree prop = OMP_TP_NAMELIST_NODE;
28142 701 : tree value = NULL_TREE;
28143 701 : if (c_parser_next_token_is (parser, CPP_KEYWORD)
28144 1402 : || c_parser_next_token_is (parser, CPP_NAME))
28145 : {
28146 536 : value = c_parser_peek_token (parser)->value;
28147 536 : c_parser_consume_token (parser);
28148 : }
28149 165 : else if (c_parser_next_token_is (parser, CPP_STRING))
28150 160 : value = c_parser_string_literal (parser, false,
28151 : false).value;
28152 : else
28153 : {
28154 5 : c_parser_error (parser, "expected identifier or "
28155 : "string literal");
28156 5 : return error_mark_node;
28157 : }
28158 :
28159 696 : properties = make_trait_property (prop, value, properties);
28160 :
28161 696 : if (c_parser_next_token_is (parser, CPP_COMMA))
28162 58 : c_parser_consume_token (parser);
28163 : else
28164 : break;
28165 58 : }
28166 : while (1);
28167 : break;
28168 126 : case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
28169 126 : case OMP_TRAIT_PROPERTY_BOOL_EXPR:
28170 126 : {
28171 126 : c_expr texpr = c_parser_expr_no_commas (parser, NULL);
28172 126 : texpr = convert_lvalue_to_rvalue (token->location, texpr,
28173 : true, true);
28174 126 : t = texpr.value;
28175 : }
28176 126 : if (t == error_mark_node)
28177 : return error_mark_node;
28178 124 : mark_exp_read (t);
28179 124 : if (property_kind == OMP_TRAIT_PROPERTY_BOOL_EXPR)
28180 : {
28181 101 : t = c_objc_common_truthvalue_conversion (token->location,
28182 : t,
28183 : boolean_type_node);
28184 101 : if (t == error_mark_node)
28185 : return error_mark_node;
28186 : }
28187 23 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
28188 : {
28189 0 : error_at (token->location,
28190 : "property must be integer expression");
28191 0 : return error_mark_node;
28192 : }
28193 122 : t = c_fully_fold (t, false, NULL);
28194 122 : properties = make_trait_property (NULL_TREE, t, properties);
28195 122 : break;
28196 26 : case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
28197 26 : if (sel == OMP_TRAIT_CONSTRUCT_SIMD)
28198 : {
28199 26 : if (parms == NULL_TREE)
28200 : {
28201 0 : error_at (token->location, "properties for %<simd%> "
28202 : "selector may not be specified in "
28203 : "%<metadirective%>");
28204 0 : return error_mark_node;
28205 : }
28206 26 : tree c;
28207 52 : c = c_parser_omp_all_clauses (parser,
28208 26 : OMP_DECLARE_SIMD_CLAUSE_MASK,
28209 : "simd", true, 2);
28210 52 : c = c_omp_declare_simd_clauses_to_numbers (parms
28211 26 : == error_mark_node
28212 : ? NULL_TREE : parms,
28213 : c);
28214 26 : properties = c;
28215 : }
28216 0 : else if (sel == OMP_TRAIT_IMPLEMENTATION_REQUIRES)
28217 : {
28218 : /* FIXME: The "requires" selector was added in OpenMP 5.1.
28219 : Currently only the now-deprecated syntax
28220 : from OpenMP 5.0 is supported. */
28221 0 : sorry_at (token->location,
28222 : "%<requires%> selector is not supported yet");
28223 0 : return error_mark_node;
28224 : }
28225 : else
28226 0 : gcc_unreachable ();
28227 26 : break;
28228 0 : default:
28229 0 : gcc_unreachable ();
28230 : }
28231 :
28232 810 : parens.skip_until_found_close (parser);
28233 810 : properties = nreverse (properties);
28234 : }
28235 618 : else if (property_kind != OMP_TRAIT_PROPERTY_NONE
28236 618 : && property_kind != OMP_TRAIT_PROPERTY_CLAUSE_LIST
28237 8 : && property_kind != OMP_TRAIT_PROPERTY_EXTENSION)
28238 : {
28239 8 : c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>");
28240 8 : return error_mark_node;
28241 : }
28242 :
28243 1420 : ret = make_trait_selector (sel, scoreval, properties, ret);
28244 :
28245 1420 : if (c_parser_next_token_is (parser, CPP_COMMA))
28246 181 : c_parser_consume_token (parser);
28247 : else
28248 : break;
28249 : }
28250 : while (1);
28251 :
28252 1256 : return nreverse (ret);
28253 : }
28254 :
28255 : /* OpenMP 5.0:
28256 :
28257 : trait-set-selector[,trait-set-selector[,...]]
28258 :
28259 : trait-set-selector:
28260 : trait-set-selector-name = { trait-selector[, trait-selector[, ...]] }
28261 :
28262 : trait-set-selector-name:
28263 : constructor
28264 : device
28265 : implementation
28266 : user */
28267 :
28268 : static tree
28269 928 : c_parser_omp_context_selector_specification (c_parser *parser, tree parms)
28270 : {
28271 928 : tree ret = NULL_TREE;
28272 1656 : do
28273 : {
28274 1292 : const char *setp = "";
28275 1292 : if (c_parser_next_token_is (parser, CPP_NAME))
28276 1290 : setp = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
28277 1292 : enum omp_tss_code set = omp_lookup_tss_code (setp);
28278 :
28279 1292 : if (set == OMP_TRAIT_SET_INVALID)
28280 : {
28281 6 : c_parser_error (parser, "expected context selector set name");
28282 10 : return error_mark_node;
28283 : }
28284 :
28285 1286 : c_parser_consume_token (parser);
28286 :
28287 1286 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
28288 1 : return error_mark_node;
28289 :
28290 1285 : matching_braces braces;
28291 1285 : if (!braces.require_open (parser))
28292 3 : return error_mark_node;
28293 :
28294 1282 : tree selectors = c_parser_omp_context_selector (parser, set, parms);
28295 1282 : if (selectors == error_mark_node)
28296 : {
28297 26 : c_parser_skip_to_closing_brace (parser);
28298 26 : ret = error_mark_node;
28299 : }
28300 1256 : else if (ret != error_mark_node)
28301 1256 : ret = make_trait_set_selector (set, selectors, ret);
28302 :
28303 1282 : braces.require_close (parser);
28304 :
28305 1282 : if (c_parser_next_token_is (parser, CPP_COMMA))
28306 364 : c_parser_consume_token (parser);
28307 : else
28308 : break;
28309 364 : }
28310 : while (1);
28311 :
28312 918 : if (ret == error_mark_node)
28313 : return ret;
28314 892 : return nreverse (ret);
28315 : }
28316 :
28317 : /* Finalize #pragma omp declare variant after FNDECL has been parsed, and put
28318 : that into "omp declare variant base" attribute. */
28319 :
28320 : static void
28321 777 : c_finish_omp_declare_variant (c_parser *parser, tree fndecl, tree parms)
28322 : {
28323 777 : matching_parens parens;
28324 777 : if (!parens.require_open (parser))
28325 : {
28326 3 : fail:
28327 50 : c_parser_skip_to_pragma_eol (parser, false);
28328 50 : return;
28329 : }
28330 :
28331 774 : if (c_parser_next_token_is_not (parser, CPP_NAME)
28332 774 : || c_parser_peek_token (parser)->id_kind != C_ID_ID)
28333 : {
28334 3 : c_parser_error (parser, "expected identifier");
28335 3 : goto fail;
28336 : }
28337 :
28338 771 : c_token *token = c_parser_peek_token (parser);
28339 771 : tree variant = lookup_name (token->value);
28340 :
28341 771 : if (variant == NULL_TREE)
28342 : {
28343 3 : undeclared_variable (token->location, token->value);
28344 3 : variant = error_mark_node;
28345 : }
28346 768 : else if (TREE_CODE (variant) != FUNCTION_DECL)
28347 : {
28348 1 : error_at (token->location, "variant %qD is not a function",
28349 : variant);
28350 1 : variant = error_mark_node;
28351 : }
28352 767 : else if (fndecl_built_in_p (variant)
28353 767 : && (strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)),
28354 : "__builtin_", strlen ("__builtin_")) == 0
28355 0 : || strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)),
28356 : "__sync_", strlen ("__sync_")) == 0
28357 0 : || strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)),
28358 : "__atomic_", strlen ("__atomic_")) == 0))
28359 : {
28360 1 : error_at (token->location, "variant %qD is a built-in",
28361 : variant);
28362 1 : variant = error_mark_node;
28363 : }
28364 766 : else if (variant == fndecl)
28365 : {
28366 2 : error_at (token->location, "variant %qD is the same as base function",
28367 : variant);
28368 2 : variant = error_mark_node;
28369 : }
28370 :
28371 771 : c_parser_consume_token (parser);
28372 :
28373 771 : parens.require_close (parser);
28374 :
28375 771 : tree append_args_tree = NULL_TREE;
28376 771 : tree append_args_last;
28377 771 : vec<tree> adjust_args_list = vNULL;
28378 771 : bool has_match = false, has_adjust_args = false;
28379 771 : location_t adjust_args_loc = UNKNOWN_LOCATION;
28380 771 : location_t append_args_loc = UNKNOWN_LOCATION;
28381 771 : location_t match_loc = UNKNOWN_LOCATION;
28382 771 : tree need_device_ptr_list = NULL_TREE;
28383 771 : tree ctx = error_mark_node;
28384 :
28385 870 : do
28386 : {
28387 870 : if (c_parser_next_token_is (parser, CPP_COMMA)
28388 870 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
28389 9 : c_parser_consume_token (parser);
28390 :
28391 870 : const char *clause = "";
28392 870 : location_t loc = c_parser_peek_token (parser)->location;
28393 870 : if (c_parser_next_token_is (parser, CPP_NAME))
28394 869 : clause = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
28395 :
28396 870 : enum clause
28397 : {
28398 : match,
28399 : adjust_args,
28400 : append_args
28401 : } ccode;
28402 :
28403 870 : if (strcmp (clause, "match") == 0)
28404 : {
28405 : ccode = match;
28406 : match_loc = loc;
28407 : }
28408 102 : else if (strcmp (clause, "adjust_args") == 0)
28409 : {
28410 : ccode = adjust_args;
28411 : adjust_args_loc = loc;
28412 : }
28413 50 : else if (strcmp (clause, "append_args") == 0)
28414 : {
28415 : ccode = append_args;
28416 : append_args_loc = loc;
28417 : }
28418 : else
28419 : {
28420 2 : c_parser_error (parser, "expected %<match%>, %<adjust_args%> or "
28421 : "%<append_args%> clause");
28422 2 : goto fail;
28423 : }
28424 :
28425 868 : c_parser_consume_token (parser);
28426 :
28427 868 : if (!parens.require_open (parser))
28428 1 : goto fail;
28429 :
28430 867 : if (parms == NULL_TREE)
28431 605 : parms = error_mark_node;
28432 :
28433 867 : if (ccode == match)
28434 : {
28435 767 : if (has_match)
28436 1 : error_at (match_loc, "too many %<match%> clauses");
28437 767 : has_match = true;
28438 767 : ctx = c_parser_omp_context_selector_specification (parser, parms);
28439 767 : if (ctx == error_mark_node)
28440 32 : goto fail;
28441 735 : ctx = omp_check_context_selector (match_loc, ctx,
28442 : OMP_CTX_DECLARE_VARIANT);
28443 :
28444 : /* The OpenMP spec says the merging rules for enclosing
28445 : "begin declare variant" contexts apply to "declare variant
28446 : directives" -- the term it uses to refer to both directive
28447 : forms. */
28448 735 : if (ctx != error_mark_node
28449 735 : && !vec_safe_is_empty (current_omp_declare_variant_attribute))
28450 : {
28451 2 : c_omp_declare_variant_attr a
28452 2 : = current_omp_declare_variant_attribute->last ();
28453 2 : tree outer_ctx = a.selector;
28454 2 : ctx = omp_merge_context_selectors (match_loc, outer_ctx, ctx,
28455 : OMP_CTX_DECLARE_VARIANT);
28456 : }
28457 : }
28458 100 : else if (ccode == adjust_args)
28459 : {
28460 52 : has_adjust_args = true;
28461 52 : if (c_parser_next_token_is (parser, CPP_NAME)
28462 52 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
28463 : {
28464 50 : const char *p
28465 50 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
28466 50 : if (strcmp (p, "need_device_ptr") == 0
28467 15 : || strcmp (p, "nothing") == 0)
28468 : {
28469 48 : c_parser_consume_token (parser); // need_device_ptr
28470 48 : c_parser_consume_token (parser); // :
28471 :
28472 48 : loc = c_parser_peek_token (parser)->location;
28473 48 : tree list
28474 48 : = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_ERROR,
28475 : NULL_TREE);
28476 :
28477 48 : tree arg;
28478 48 : if (variant != error_mark_node)
28479 103 : for (tree c = list; c != NULL_TREE; c = TREE_CHAIN (c))
28480 : {
28481 61 : tree decl = TREE_PURPOSE (c);
28482 61 : location_t arg_loc = EXPR_LOCATION (TREE_VALUE (c));
28483 61 : int idx;
28484 111 : for (arg = parms, idx = 0; arg != NULL;
28485 50 : arg = TREE_CHAIN (arg), idx++)
28486 110 : if (arg == decl)
28487 : break;
28488 61 : if (arg == NULL_TREE)
28489 : {
28490 1 : error_at (arg_loc,
28491 : "%qD is not a function argument",
28492 : decl);
28493 5 : goto fail;
28494 : }
28495 60 : if (adjust_args_list.contains (arg))
28496 : {
28497 3 : error_at (arg_loc,
28498 : "%qD is specified more than once",
28499 : decl);
28500 3 : goto fail;
28501 : }
28502 57 : if (strcmp (p, "need_device_ptr") == 0
28503 57 : && TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE)
28504 : {
28505 1 : error_at (loc, "%qD is not of pointer type", decl);
28506 1 : goto fail;
28507 : }
28508 56 : adjust_args_list.safe_push (arg);
28509 56 : if (strcmp (p, "need_device_ptr") == 0)
28510 : {
28511 46 : need_device_ptr_list = chainon (
28512 : need_device_ptr_list,
28513 : build_tree_list (
28514 : NULL_TREE,
28515 : build_int_cst (
28516 : integer_type_node,
28517 46 : idx))); // Store 0-based argument index,
28518 : // as in gimplify_call_expr
28519 : }
28520 : }
28521 : }
28522 : else
28523 : {
28524 2 : error_at (c_parser_peek_token (parser)->location,
28525 : "expected %<nothing%> or %<need_device_ptr%>");
28526 2 : if (strcmp (p, "need_device_addr") == 0)
28527 1 : inform (c_parser_peek_token (parser)->location,
28528 : "%<need_device_addr%> is not valid for C");
28529 2 : goto fail;
28530 : }
28531 : }
28532 : else
28533 : {
28534 2 : error_at (c_parser_peek_token (parser)->location,
28535 : "expected %<nothing%> or %<need_device_ptr%> "
28536 : "followed by %<:%>");
28537 2 : goto fail;
28538 : }
28539 : }
28540 48 : else if (ccode == append_args)
28541 : {
28542 48 : if (append_args_tree)
28543 : {
28544 1 : error_at (append_args_loc, "too many %qs clauses", "append_args");
28545 1 : append_args_tree = NULL_TREE;
28546 : }
28547 86 : do
28548 : {
28549 67 : location_t loc = c_parser_peek_token (parser)->location;
28550 67 : if (!c_parser_next_token_is (parser, CPP_NAME)
28551 67 : || strcmp ("interop",
28552 67 : IDENTIFIER_POINTER (
28553 : c_parser_peek_token (parser)->value)))
28554 : {
28555 0 : error_at (loc, "expected %<interop%>");
28556 0 : goto fail;
28557 : }
28558 67 : c_parser_consume_token (parser);
28559 :
28560 67 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
28561 0 : goto fail;
28562 67 : bool target = false;
28563 67 : bool targetsync = false;
28564 67 : tree prefer_type_tree = NULL_TREE;
28565 67 : if (!c_parser_omp_clause_init_modifiers (parser, &target,
28566 : &targetsync,
28567 : &prefer_type_tree)
28568 67 : || !c_parser_require (parser, CPP_CLOSE_PAREN,
28569 : "expected %<)%> or %<,%>"))
28570 0 : goto fail;
28571 67 : if (!target && !targetsync)
28572 3 : error_at (loc,
28573 : "missing required %<target%> and/or "
28574 : "%<targetsync%> modifier");
28575 67 : tree t = build_tree_list (target ? boolean_true_node
28576 : : boolean_false_node,
28577 : targetsync ? boolean_true_node
28578 : : boolean_false_node);
28579 67 : t = build1_loc (loc, NOP_EXPR, void_type_node, t);
28580 67 : t = build_tree_list (t, prefer_type_tree);
28581 67 : if (append_args_tree)
28582 : {
28583 19 : TREE_CHAIN (append_args_last) = t;
28584 19 : append_args_last = t;
28585 : }
28586 : else
28587 : append_args_tree = append_args_last = t;
28588 67 : if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
28589 : break;
28590 19 : if (!c_parser_require (parser, CPP_COMMA, "expected %<)%> or %<,%>"))
28591 0 : goto fail;
28592 19 : }
28593 : while (true);
28594 : }
28595 :
28596 826 : parens.require_close (parser);
28597 826 : } while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL));
28598 727 : if (variant != error_mark_node && !has_match)
28599 : {
28600 1 : c_parser_error (parser, "expected %<match%> clause");
28601 1 : variant = error_mark_node;
28602 : }
28603 727 : c_parser_skip_to_pragma_eol (parser);
28604 :
28605 : /* At this point, we have completed parsing of the pragma, now it's
28606 : on to error checking. */
28607 727 : if (variant == error_mark_node || ctx == error_mark_node)
28608 : /* Previously diagnosed error. */
28609 : return;
28610 :
28611 697 : if ((has_adjust_args || append_args_tree)
28612 697 : && !omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
28613 : OMP_TRAIT_CONSTRUCT_DISPATCH))
28614 : {
28615 1 : error_at (has_adjust_args ? adjust_args_loc : append_args_loc,
28616 : "an %qs clause can only be specified if the "
28617 : "%<dispatch%> selector of the %<construct%> selector "
28618 : "set appears in the %<match%> clause",
28619 : has_adjust_args ? "adjust_args" : "append_args");
28620 1 : return;
28621 : }
28622 :
28623 696 : if (!omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
28624 : OMP_TRAIT_CONSTRUCT_SIMD))
28625 : /* Check that the base and variant have compatible types. */
28626 : {
28627 670 : tree base_type = TREE_TYPE (fndecl);
28628 670 : tree variant_type = TREE_TYPE (variant);
28629 670 : bool unprototyped_variant
28630 670 : = (TYPE_ARG_TYPES (variant_type) == NULL_TREE
28631 670 : && !TYPE_NO_NAMED_ARGS_STDARG_P (variant_type));
28632 :
28633 670 : if (append_args_tree
28634 47 : && TYPE_ARG_TYPES (base_type) == NULL_TREE
28635 678 : && !TYPE_NO_NAMED_ARGS_STDARG_P (base_type))
28636 : {
28637 : /* The base function is a pre-C23 unprototyped function. Without
28638 : a prototype, we don't know the offset where the append_args go.
28639 : That offset needs to be stored with the append_args in the
28640 : variant function attributes, so we cannot presently handle
28641 : this case. */
28642 6 : sorry_at (append_args_loc,
28643 : "%<append_args%> with unprototyped base function "
28644 : "is not supported yet");
28645 6 : inform (DECL_SOURCE_LOCATION (fndecl),
28646 : "base function %qD declared here", fndecl);
28647 6 : return;
28648 : }
28649 664 : else if (append_args_tree)
28650 : {
28651 : /* Find nbase_args, the number of fixed arguments in the base
28652 : function. */
28653 41 : int nappend_args = 0;
28654 41 : int nbase_args = 0;
28655 41 : for (tree t = TYPE_ARG_TYPES (base_type);
28656 183 : t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
28657 55 : nbase_args++;
28658 101 : for (tree t = append_args_tree; t; t = TREE_CHAIN (t))
28659 60 : nappend_args++;
28660 :
28661 : /* Store as purpose = arg number after which to append
28662 : and value = list of interop items. */
28663 41 : append_args_tree = build_tree_list (build_int_cst (integer_type_node,
28664 41 : nbase_args),
28665 : append_args_tree);
28666 :
28667 : /* Give a specific diagnostic if the append_args parameters
28668 : of the variant are of the wrong type, or missing. The
28669 : compatible types test below could fail to detect this if
28670 : the variant is a varargs function. */
28671 41 : if (!unprototyped_variant)
28672 : {
28673 39 : tree args = TYPE_ARG_TYPES (variant_type);
28674 90 : for (int i = 0; args && i < nbase_args;
28675 51 : i++, args = TREE_CHAIN (args))
28676 : ;
28677 89 : for (int i = 0; i < nappend_args; i++, args = TREE_CHAIN (args))
28678 109 : if (!args || !c_omp_interop_t_p (TREE_VALUE (args)))
28679 : {
28680 5 : error_at (DECL_SOURCE_LOCATION (variant),
28681 : "argument %d of %qD must be of "
28682 : "%<omp_interop_t%>",
28683 5 : nbase_args + i + 1, variant);
28684 5 : inform (append_args_loc,
28685 : "%<append_args%> specified here");
28686 100 : return;
28687 : }
28688 : }
28689 :
28690 : /* Perform the "implementation defined transformation" on the type
28691 : of the base function to add the append_args before checking it
28692 : for compatibility with the function variant's type. */
28693 36 : tree args = TYPE_ARG_TYPES (base_type);
28694 36 : tree newargs = NULL_TREE;
28695 36 : tree lastarg = NULL_TREE;
28696 89 : for (int j = 0; j < nbase_args; j++, args = TREE_CHAIN (args))
28697 : {
28698 53 : tree t = tree_cons (TREE_PURPOSE (args),
28699 53 : TREE_VALUE (args), NULL_TREE);
28700 53 : if (lastarg)
28701 31 : TREE_CHAIN (lastarg) = t;
28702 : else
28703 : newargs = t;
28704 53 : lastarg = t;
28705 : }
28706 36 : tree type = lookup_name (get_identifier ("omp_interop_t"));
28707 36 : type = type ? TREE_TYPE (type) : pointer_sized_int_node;
28708 87 : for (int j = 0; j < nappend_args; j++)
28709 : {
28710 51 : tree t = tree_cons (NULL_TREE, type, NULL_TREE);
28711 51 : if (lastarg)
28712 37 : TREE_CHAIN (lastarg) = t;
28713 : else
28714 : newargs = t;
28715 51 : lastarg = t;
28716 : }
28717 36 : TREE_CHAIN (lastarg) = args;
28718 :
28719 : /* Temporarily stuff newargs into the original base_type. */
28720 36 : tree saveargs = TYPE_ARG_TYPES (base_type);
28721 36 : TYPE_ARG_TYPES (base_type) = newargs;
28722 36 : bool fail = !comptypes (base_type, variant_type);
28723 36 : TYPE_ARG_TYPES (base_type) = saveargs;
28724 :
28725 36 : if (fail)
28726 : {
28727 2 : error_at (token->location,
28728 : "variant %qD and base %qD have incompatible types "
28729 : "after %<append_args%> adjustment",
28730 : variant, fndecl);
28731 2 : inform (DECL_SOURCE_LOCATION (variant),
28732 : "%<declare variant%> candidate %qD declared here",
28733 : variant);
28734 2 : return;
28735 : }
28736 34 : else if (unprototyped_variant)
28737 : /* If we've got an unprototyped variant, copy the transformed
28738 : base arg types to the variant. This is needed later by
28739 : modify_call_for_omp_dispatch. */
28740 2 : TYPE_ARG_TYPES (variant_type) = newargs;
28741 : }
28742 : else /* No append_args present. */
28743 : {
28744 623 : if (!comptypes (base_type, variant_type))
28745 : {
28746 1 : error_at (token->location,
28747 : "variant %qD and base %qD have incompatible types",
28748 : variant, fndecl);
28749 1 : inform (DECL_SOURCE_LOCATION (variant),
28750 : "%<declare variant%> candidate %qD declared here",
28751 : variant);
28752 1 : return;
28753 : }
28754 622 : else if (TYPE_ARG_TYPES (variant_type) == NULL_TREE
28755 3 : && !TYPE_NO_NAMED_ARGS_STDARG_P (variant_type)
28756 624 : && TYPE_ARG_TYPES (base_type) != NULL_TREE)
28757 : /* If we've got an unprototyped variant but the base has
28758 : a prototype, copy the base arg types to the variant. */
28759 1 : TYPE_ARG_TYPES (variant_type) = TYPE_ARG_TYPES (base_type);
28760 : }
28761 : }
28762 :
28763 : /* If we made it here, store the parsed information. */
28764 682 : C_DECL_USED (variant) = 1;
28765 682 : tree construct = omp_get_context_selector_list (ctx,
28766 : OMP_TRAIT_SET_CONSTRUCT);
28767 682 : omp_mark_declare_variant (match_loc, variant, construct);
28768 682 : if (omp_context_selector_matches (ctx, NULL_TREE, false))
28769 : {
28770 248 : tree attr = tree_cons (get_identifier ("omp declare variant base"),
28771 : build_tree_list (variant, ctx),
28772 248 : DECL_ATTRIBUTES (fndecl));
28773 248 : DECL_ATTRIBUTES (fndecl) = attr;
28774 : }
28775 :
28776 682 : if (need_device_ptr_list || append_args_tree)
28777 : {
28778 49 : tree variant_decl = tree_strip_nop_conversions (variant);
28779 49 : tree t = build_tree_list (need_device_ptr_list,
28780 : NULL_TREE /* need_device_addr */);
28781 49 : TREE_CHAIN (t) = append_args_tree;
28782 49 : DECL_ATTRIBUTES (variant_decl)
28783 98 : = tree_cons (get_identifier ("omp declare variant variant args"), t,
28784 49 : DECL_ATTRIBUTES (variant_decl));
28785 : }
28786 : }
28787 :
28788 : /* Finalize #pragma omp declare simd or #pragma omp declare variant
28789 : clauses after FNDECL has been parsed, and put that into "omp declare simd"
28790 : or "omp declare variant base" attribute. */
28791 :
28792 : static void
28793 884 : c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
28794 : vec<c_token> *pclauses)
28795 : {
28796 884 : vec<c_token> &clauses = *pclauses;
28797 :
28798 : /* Normally first token is CPP_NAME "simd" or "variant". CPP_EOF there
28799 : indicates error has been reported and CPP_PRAGMA that
28800 : c_finish_omp_declare_simd has already processed the tokens. */
28801 1768 : if (clauses.exists () && clauses[0].type == CPP_EOF)
28802 : return;
28803 880 : const char *kind = "simd";
28804 880 : if (clauses.exists ()
28805 1760 : && (clauses[0].type == CPP_NAME || clauses[0].type == CPP_PRAGMA))
28806 880 : kind = IDENTIFIER_POINTER (clauses[0].value);
28807 880 : gcc_assert (strcmp (kind, "simd") == 0 || strcmp (kind, "variant") == 0);
28808 880 : if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
28809 : {
28810 15 : error ("%<#pragma omp declare %s%> not immediately followed by "
28811 : "a function declaration or definition", kind);
28812 15 : clauses[0].type = CPP_EOF;
28813 15 : return;
28814 : }
28815 1730 : if (clauses.exists () && clauses[0].type != CPP_NAME)
28816 : {
28817 2 : error_at (DECL_SOURCE_LOCATION (fndecl),
28818 : "%<#pragma omp declare %s%> not immediately followed by "
28819 : "a single function declaration or definition", kind);
28820 2 : clauses[0].type = CPP_EOF;
28821 2 : return;
28822 : }
28823 863 : if (DECL_FUNCTION_VERSIONED (fndecl))
28824 : {
28825 0 : error_at (DECL_SOURCE_LOCATION (fndecl),
28826 : "%<#pragma omp declare %s%> cannot be used with function "
28827 : "multi-versioning", kind);
28828 0 : return;
28829 : }
28830 :
28831 863 : if (parms == NULL_TREE)
28832 600 : parms = DECL_ARGUMENTS (fndecl);
28833 :
28834 863 : unsigned int tokens_avail = parser->tokens_avail;
28835 863 : gcc_assert (parser->tokens == &parser->tokens_buf[0]);
28836 :
28837 863 : parser->tokens = clauses.address ();
28838 863 : parser->tokens_avail = clauses.length ();
28839 :
28840 : /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
28841 2041 : while (parser->tokens_avail > 3)
28842 : {
28843 1178 : c_token *token = c_parser_peek_token (parser);
28844 1178 : gcc_assert (token->type == CPP_NAME);
28845 1178 : kind = IDENTIFIER_POINTER (token->value);
28846 1178 : c_parser_consume_token (parser);
28847 1178 : parser->in_pragma = true;
28848 :
28849 1178 : if (strcmp (kind, "simd") == 0)
28850 : {
28851 401 : tree c;
28852 401 : c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
28853 : "#pragma omp declare simd");
28854 401 : c = c_omp_declare_simd_clauses_to_numbers (parms, c);
28855 401 : if (c != NULL_TREE)
28856 292 : c = tree_cons (NULL_TREE, c, NULL_TREE);
28857 401 : c = build_tree_list (get_identifier ("omp declare simd"), c);
28858 401 : TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
28859 401 : DECL_ATTRIBUTES (fndecl) = c;
28860 : }
28861 : else
28862 : {
28863 777 : gcc_assert (strcmp (kind, "variant") == 0);
28864 777 : c_finish_omp_declare_variant (parser, fndecl, parms);
28865 : }
28866 : }
28867 :
28868 863 : parser->tokens = &parser->tokens_buf[0];
28869 863 : parser->tokens_avail = tokens_avail;
28870 863 : if (clauses.exists ())
28871 863 : clauses[0].type = CPP_PRAGMA;
28872 : }
28873 :
28874 : /* This is consistent with the C++ front end. */
28875 :
28876 : #if !defined (NO_DOT_IN_LABEL)
28877 : #define JOIN_STR "."
28878 : #elif !defined (NO_DOLLAR_IN_LABEL)
28879 : #define JOIN_STR "$"
28880 : #else
28881 : #define JOIN_STR "_"
28882 : #endif
28883 :
28884 : /* Helper function for OpenMP "begin declare variant" directives.
28885 : Function definitions inside the construct need to have their names
28886 : mangled according to the context selector CTX. The DECLARATOR is
28887 : modified in place to point to a new identifier; the original name of
28888 : the function is returned. */
28889 : static tree
28890 26 : omp_start_variant_function (c_declarator *declarator, tree ctx)
28891 : {
28892 26 : c_declarator *id = declarator;
28893 52 : while (id->kind != cdk_id)
28894 : {
28895 26 : id = id->declarator;
28896 26 : gcc_assert (id);
28897 : }
28898 26 : tree name = id->u.id.id;
28899 26 : id->u.id.id = omp_mangle_variant_name (name, ctx, JOIN_STR);
28900 26 : return name;
28901 : }
28902 :
28903 : /* Helper function for OpenMP "begin declare variant" directives. Now
28904 : that we have a DECL for the variant function, and BASE_NAME for the
28905 : base function, add an "omp declare variant base" attribute pointing
28906 : at CTX to the base decl, and an "omp declare variant variant"
28907 : attribute to the variant DECL. */
28908 : static void
28909 26 : omp_finish_variant_function (tree decl, tree base_name, tree ctx)
28910 : {
28911 : /* First look up BASE_NAME and ensure it matches DECL. */
28912 26 : tree base_decl = lookup_name (base_name);
28913 26 : if (base_decl == error_mark_node)
28914 : base_decl = NULL_TREE;
28915 26 : if (!base_decl)
28916 : {
28917 1 : error_at (DECL_SOURCE_LOCATION (decl),
28918 : "no declaration of base function %qs",
28919 1 : IDENTIFIER_POINTER (base_name));
28920 1 : return;
28921 : }
28922 :
28923 25 : if (!comptypes (TREE_TYPE (decl), TREE_TYPE (base_decl)))
28924 : {
28925 2 : error_at (DECL_SOURCE_LOCATION (decl),
28926 : "variant function definition does not match "
28927 : "declaration of %qE", base_decl);
28928 2 : inform (DECL_SOURCE_LOCATION (base_decl),
28929 : "%qE declared here", base_decl);
28930 2 : return;
28931 : }
28932 :
28933 : /* Now set the attributes on the base and variant decls for the middle
28934 : end. */
28935 23 : omp_check_for_duplicate_variant (DECL_SOURCE_LOCATION (decl),
28936 : base_decl, ctx);
28937 23 : tree construct
28938 23 : = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
28939 23 : omp_mark_declare_variant (DECL_SOURCE_LOCATION (decl), decl, construct);
28940 23 : tree attrs = DECL_ATTRIBUTES (base_decl);
28941 23 : tree match_loc_node
28942 23 : = maybe_wrap_with_location (integer_zero_node,
28943 23 : DECL_SOURCE_LOCATION (base_decl));
28944 23 : tree loc_node = tree_cons (match_loc_node, integer_zero_node,
28945 : build_tree_list (match_loc_node,
28946 : integer_zero_node));
28947 23 : attrs = tree_cons (get_identifier ("omp declare variant base"),
28948 : tree_cons (decl, ctx, loc_node), attrs);
28949 23 : DECL_ATTRIBUTES (base_decl) = attrs;
28950 :
28951 : /* Variant functions are essentially anonymous and cannot be referenced
28952 : outside the compilation unit. */
28953 23 : TREE_PUBLIC (decl) = 0;
28954 23 : DECL_COMDAT (decl) = 0;
28955 : }
28956 :
28957 :
28958 : /* D should be C_TOKEN_VEC from omp::decl attribute. If it contains
28959 : a threadprivate, groupprivate, allocate or declare target directive,
28960 : return true and parse it for DECL. */
28961 :
28962 : bool
28963 43 : c_maybe_parse_omp_decl (tree decl, tree d)
28964 : {
28965 43 : gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
28966 43 : vec<c_token, va_gc> *toks = C_TOKEN_VEC_TOKENS (d);
28967 43 : c_token *first = toks->address ();
28968 43 : c_token *last = first + toks->length ();
28969 43 : const char *directive[3] = {};
28970 119 : for (int j = 0; j < 3; j++)
28971 : {
28972 107 : tree id = NULL_TREE;
28973 107 : if (first + j == last)
28974 : break;
28975 86 : if (first[j].type == CPP_NAME)
28976 76 : id = first[j].value;
28977 10 : else if (first[j].type == CPP_KEYWORD)
28978 0 : id = ridpointers[(int) first[j].keyword];
28979 : else
28980 : break;
28981 76 : directive[j] = IDENTIFIER_POINTER (id);
28982 : }
28983 43 : const c_omp_directive *dir = NULL;
28984 43 : if (directive[0])
28985 43 : dir = c_omp_categorize_directive (directive[0], directive[1],
28986 : directive[2]);
28987 43 : if (dir == NULL)
28988 : {
28989 0 : error_at (first->location,
28990 : "unknown OpenMP directive name in "
28991 : "%qs attribute argument", "omp::decl");
28992 0 : return false;
28993 : }
28994 43 : if (dir->id != PRAGMA_OMP_THREADPRIVATE
28995 28 : && dir->id != PRAGMA_OMP_GROUPPRIVATE
28996 23 : && dir->id != PRAGMA_OMP_ALLOCATE
28997 21 : && (dir->id != PRAGMA_OMP_DECLARE
28998 21 : || strcmp (directive[1], "target") != 0))
28999 : return false;
29000 :
29001 43 : if (!flag_openmp && !dir->simd)
29002 : return true;
29003 :
29004 43 : c_parser *parser = the_parser;
29005 43 : unsigned int tokens_avail = parser->tokens_avail;
29006 43 : gcc_assert (parser->tokens == &parser->tokens_buf[0]);
29007 43 : toks = NULL;
29008 43 : vec_safe_reserve (toks, last - first + 2, true);
29009 43 : c_token tok = {};
29010 43 : tok.type = CPP_PRAGMA;
29011 43 : tok.keyword = RID_MAX;
29012 43 : tok.pragma_kind = pragma_kind (dir->id);
29013 43 : tok.location = first->location;
29014 43 : toks->quick_push (tok);
29015 201 : while (++first < last)
29016 115 : toks->quick_push (*first);
29017 43 : tok = {};
29018 43 : tok.type = CPP_PRAGMA_EOL;
29019 43 : tok.keyword = RID_MAX;
29020 43 : tok.location = last[-1].location;
29021 43 : toks->quick_push (tok);
29022 43 : tok = {};
29023 43 : tok.type = CPP_EOF;
29024 43 : tok.keyword = RID_MAX;
29025 43 : tok.location = last[-1].location;
29026 43 : toks->quick_push (tok);
29027 43 : parser->in_omp_decl_attribute = decl;
29028 43 : gcc_assert (!parser->in_omp_attribute_pragma);
29029 43 : parser->in_omp_attribute_pragma = ggc_alloc<omp_attribute_pragma_state> ();
29030 43 : parser->in_omp_attribute_pragma->token_vec = toks;
29031 43 : parser->in_omp_attribute_pragma->save_tokens = parser->tokens;
29032 43 : parser->in_omp_attribute_pragma->save_tokens_avail = tokens_avail;
29033 43 : parser->tokens = toks->address ();
29034 43 : parser->tokens_avail = toks->length ();
29035 43 : c_parser_pragma (parser, pragma_external, NULL, NULL_TREE);
29036 43 : parser->in_omp_decl_attribute = NULL_TREE;
29037 43 : return true;
29038 : }
29039 :
29040 : /* OpenMP 4.0:
29041 : # pragma omp declare target new-line
29042 : declarations and definitions
29043 : # pragma omp end declare target new-line
29044 :
29045 : OpenMP 4.5:
29046 : # pragma omp declare target ( extended-list ) new-line
29047 :
29048 : # pragma omp declare target declare-target-clauses[seq] new-line */
29049 :
29050 : #define OMP_DECLARE_TARGET_CLAUSE_MASK \
29051 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
29052 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ENTER) \
29053 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK) \
29054 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LOCAL) \
29055 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE) \
29056 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INDIRECT))
29057 :
29058 : static void
29059 298 : c_parser_omp_declare_target (c_parser *parser)
29060 : {
29061 298 : tree clauses = NULL_TREE;
29062 298 : int device_type = 0;
29063 298 : bool indirect = false;
29064 298 : bool only_device_type_or_indirect = true;
29065 298 : if (flag_openmp)
29066 298 : omp_requires_mask
29067 298 : = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
29068 298 : if (c_parser_next_token_is (parser, CPP_NAME)
29069 424 : || (c_parser_next_token_is (parser, CPP_COMMA)
29070 5 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME))
29071 176 : clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK,
29072 : "#pragma omp declare target");
29073 122 : else if (parser->in_omp_decl_attribute
29074 238 : || c_parser_next_token_is (parser, CPP_OPEN_PAREN))
29075 : {
29076 20 : clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER,
29077 : clauses);
29078 20 : clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
29079 20 : c_parser_skip_to_pragma_eol (parser);
29080 : }
29081 : else
29082 : {
29083 102 : warning_at (c_parser_peek_token (parser)->location,
29084 102 : OPT_Wdeprecated_openmp,
29085 : "use of %<omp declare target%> as a synonym for "
29086 : "%<omp begin declare target%> has been deprecated since "
29087 : "OpenMP 5.2");
29088 102 : bool attr_syntax = parser->in_omp_attribute_pragma != NULL;
29089 102 : c_parser_skip_to_pragma_eol (parser);
29090 102 : c_omp_declare_target_attr attr = { attr_syntax, -1, 0 };
29091 102 : vec_safe_push (current_omp_declare_target_attribute, attr);
29092 102 : return;
29093 : }
29094 496 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
29095 : {
29096 300 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE)
29097 27 : device_type |= OMP_CLAUSE_DEVICE_TYPE_KIND (c);
29098 300 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INDIRECT)
29099 16 : indirect |= !integer_zerop (OMP_CLAUSE_INDIRECT_EXPR (c));
29100 : }
29101 496 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
29102 : {
29103 300 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE
29104 300 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INDIRECT)
29105 43 : continue;
29106 257 : tree t = OMP_CLAUSE_DECL (c), id;
29107 257 : tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
29108 257 : tree at2 = lookup_attribute ("omp declare target link",
29109 257 : DECL_ATTRIBUTES (t));
29110 257 : only_device_type_or_indirect = false;
29111 257 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
29112 : {
29113 34 : id = get_identifier ("omp declare target link");
29114 34 : std::swap (at1, at2);
29115 : }
29116 : else
29117 223 : id = get_identifier ("omp declare target");
29118 257 : if (at2)
29119 : {
29120 8 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
29121 3 : error_at (OMP_CLAUSE_LOCATION (c),
29122 : "%qD specified both in declare target %<link%> and %qs"
29123 3 : " clauses", t, OMP_CLAUSE_ENTER_TO (c) ? "to" : "enter");
29124 5 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LOCAL
29125 5 : || value_member (get_identifier ("local"), TREE_VALUE (at2)))
29126 2 : error_at (OMP_CLAUSE_LOCATION (c),
29127 : "%qD specified both in declare target %<link%> and "
29128 : "%<local%> clauses", t);
29129 : else
29130 3 : error_at (OMP_CLAUSE_LOCATION (c),
29131 : "%qD specified both in declare target %<link%> and "
29132 : "%<to%> or %<enter%> clauses", t);
29133 8 : continue;
29134 : }
29135 249 : if (!at1)
29136 : {
29137 216 : DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
29138 216 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LOCAL)
29139 7 : TREE_VALUE (DECL_ATTRIBUTES (t))
29140 14 : = tree_cons (NULL_TREE, get_identifier ("local"),
29141 7 : TREE_VALUE (DECL_ATTRIBUTES (t)));
29142 :
29143 216 : if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
29144 1 : continue;
29145 :
29146 215 : symtab_node *node = symtab_node::get (t);
29147 215 : if (node != NULL)
29148 : {
29149 167 : node->offloadable = 1;
29150 167 : if (ENABLE_OFFLOADING)
29151 : {
29152 : g->have_offload = true;
29153 : if (is_a <varpool_node *> (node)
29154 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LOCAL)
29155 : vec_safe_push (offload_vars, t);
29156 : }
29157 : }
29158 : }
29159 : else
29160 : {
29161 33 : bool saw_local = value_member (get_identifier ("local"),
29162 33 : TREE_VALUE (at1));
29163 35 : if (saw_local && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
29164 : {
29165 2 : error_at (OMP_CLAUSE_LOCATION (c),
29166 : "%qD specified both in declare target %<local%> and "
29167 : "%qs clauses", t,
29168 2 : OMP_CLAUSE_ENTER_TO (c) ? "to" : "enter");
29169 2 : continue;
29170 : }
29171 62 : else if (!saw_local && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LOCAL)
29172 : {
29173 2 : error_at (OMP_CLAUSE_LOCATION (c),
29174 : "%qD specified both in declare target %<local%> and "
29175 : "%<to%> or %<enter%> clauses", t);
29176 2 : continue;
29177 : }
29178 : }
29179 244 : if (TREE_CODE (t) != FUNCTION_DECL)
29180 162 : continue;
29181 82 : if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0)
29182 : {
29183 13 : tree at3 = lookup_attribute ("omp declare target host",
29184 13 : DECL_ATTRIBUTES (t));
29185 13 : if (at3 == NULL_TREE)
29186 : {
29187 11 : id = get_identifier ("omp declare target host");
29188 11 : DECL_ATTRIBUTES (t)
29189 22 : = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
29190 : }
29191 : }
29192 82 : if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0)
29193 : {
29194 13 : tree at3 = lookup_attribute ("omp declare target nohost",
29195 13 : DECL_ATTRIBUTES (t));
29196 13 : if (at3 == NULL_TREE)
29197 : {
29198 11 : id = get_identifier ("omp declare target nohost");
29199 11 : DECL_ATTRIBUTES (t)
29200 22 : = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
29201 : }
29202 : }
29203 82 : if (indirect)
29204 : {
29205 9 : tree at4 = lookup_attribute ("omp declare target indirect",
29206 9 : DECL_ATTRIBUTES (t));
29207 9 : if (at4 == NULL_TREE)
29208 : {
29209 9 : id = get_identifier ("omp declare target indirect");
29210 9 : DECL_ATTRIBUTES (t)
29211 18 : = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
29212 : }
29213 : }
29214 : }
29215 196 : if ((device_type || indirect) && only_device_type_or_indirect)
29216 3 : error_at (OMP_CLAUSE_LOCATION (clauses),
29217 : "directive with only %<device_type%> or %<indirect%> clauses");
29218 196 : if (indirect && device_type && device_type != OMP_CLAUSE_DEVICE_TYPE_ANY)
29219 1 : error_at (OMP_CLAUSE_LOCATION (clauses),
29220 : "%<device_type%> clause must specify 'any' when used with "
29221 : "an %<indirect%> clause");
29222 : }
29223 :
29224 : /* OpenMP 5.1
29225 : #pragma omp begin assumes clauses[optseq] new-line
29226 :
29227 : #pragma omp begin declare target clauses[optseq] new-line
29228 :
29229 : #pragma omp begin declare variant match (context-selector) new-line */
29230 :
29231 : #define OMP_BEGIN_DECLARE_TARGET_CLAUSE_MASK \
29232 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE) \
29233 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INDIRECT))
29234 :
29235 : static void
29236 132 : c_parser_omp_begin (c_parser *parser)
29237 : {
29238 132 : const char *p = "";
29239 132 : c_parser_consume_pragma (parser);
29240 132 : if (c_parser_next_token_is (parser, CPP_NAME))
29241 132 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
29242 132 : if (strcmp (p, "declare") == 0)
29243 : {
29244 86 : c_parser_consume_token (parser);
29245 86 : p = "";
29246 86 : if (c_parser_next_token_is (parser, CPP_NAME))
29247 86 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
29248 86 : if (strcmp (p, "target") == 0)
29249 : {
29250 54 : c_parser_consume_token (parser);
29251 54 : bool attr_syntax = parser->in_omp_attribute_pragma != NULL;
29252 54 : tree clauses
29253 54 : = c_parser_omp_all_clauses (parser,
29254 54 : OMP_BEGIN_DECLARE_TARGET_CLAUSE_MASK,
29255 : "#pragma omp begin declare target");
29256 54 : int device_type = 0;
29257 54 : int indirect = 0;
29258 132 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
29259 : {
29260 24 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE)
29261 15 : device_type |= OMP_CLAUSE_DEVICE_TYPE_KIND (c);
29262 24 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INDIRECT)
29263 9 : indirect |= !integer_zerop (OMP_CLAUSE_INDIRECT_EXPR (c));
29264 : }
29265 54 : c_omp_declare_target_attr attr = { attr_syntax, device_type,
29266 54 : indirect };
29267 54 : vec_safe_push (current_omp_declare_target_attribute, attr);
29268 : }
29269 32 : else if (strcmp (p, "variant") == 0)
29270 : {
29271 32 : c_parser_consume_token (parser);
29272 32 : const char *clause = "";
29273 32 : matching_parens parens;
29274 32 : location_t match_loc = c_parser_peek_token (parser)->location;
29275 32 : if (c_parser_next_token_is (parser, CPP_COMMA))
29276 1 : c_parser_consume_token (parser);
29277 32 : if (c_parser_next_token_is (parser, CPP_NAME))
29278 : {
29279 32 : tree id = c_parser_peek_token (parser)->value;
29280 32 : clause = IDENTIFIER_POINTER (id);
29281 : }
29282 32 : if (strcmp (clause, "match") != 0)
29283 : {
29284 0 : c_parser_error (parser, "expected %<match%>");
29285 0 : c_parser_skip_to_pragma_eol (parser);
29286 6 : return;
29287 : }
29288 :
29289 32 : c_parser_consume_token (parser);
29290 :
29291 32 : if (!parens.require_open (parser))
29292 : {
29293 0 : c_parser_skip_to_pragma_eol (parser, false);
29294 0 : return;
29295 : }
29296 :
29297 32 : tree ctx =
29298 32 : c_parser_omp_context_selector_specification (parser, NULL_TREE);
29299 32 : if (ctx != error_mark_node)
29300 30 : ctx = omp_check_context_selector (match_loc, ctx,
29301 : OMP_CTX_BEGIN_DECLARE_VARIANT);
29302 :
29303 32 : if (ctx != error_mark_node
29304 32 : && !vec_safe_is_empty (current_omp_declare_variant_attribute))
29305 : {
29306 7 : c_omp_declare_variant_attr a
29307 7 : = current_omp_declare_variant_attribute->last ();
29308 7 : tree outer_ctx = a.selector;
29309 7 : ctx = omp_merge_context_selectors (match_loc, outer_ctx, ctx,
29310 : OMP_CTX_BEGIN_DECLARE_VARIANT);
29311 : }
29312 :
29313 32 : if (ctx == error_mark_node
29314 32 : || !omp_context_selector_matches (ctx, NULL_TREE, false, true))
29315 : {
29316 : /* The context is either invalid or cannot possibly match.
29317 : In the latter case the spec says all code in the begin/end
29318 : sequence will be elided. In the former case we'll get bogus
29319 : errors from trying to parse it without a valid context to
29320 : use for name-mangling, so elide that too. */
29321 6 : c_parser_skip_to_pragma_eol (parser, false);
29322 6 : c_parser_skip_to_pragma_omp_end_declare_variant (parser);
29323 6 : return;
29324 : }
29325 : else
29326 : {
29327 26 : bool attr_syntax = parser->in_omp_attribute_pragma != NULL;
29328 26 : c_omp_declare_variant_attr a = { attr_syntax, ctx };
29329 26 : vec_safe_push (current_omp_declare_variant_attribute, a);
29330 : }
29331 :
29332 26 : parens.require_close (parser);
29333 26 : c_parser_skip_to_pragma_eol (parser);
29334 : }
29335 : else
29336 : {
29337 0 : c_parser_error (parser, "expected %<target%> or %<variant%>");
29338 0 : c_parser_skip_to_pragma_eol (parser, false);
29339 : }
29340 : }
29341 46 : else if (strcmp (p, "assumes") == 0)
29342 : {
29343 46 : c_parser_consume_token (parser);
29344 46 : bool attr_syntax = parser->in_omp_attribute_pragma != NULL;
29345 46 : c_parser_omp_assumption_clauses (parser, false);
29346 46 : struct c_omp_begin_assumes_data a = { attr_syntax };
29347 46 : vec_safe_push (current_omp_begin_assumes, a);
29348 : }
29349 : else
29350 : {
29351 0 : c_parser_error (parser, "expected %<declare target%>, "
29352 : "%<declare variant%>, or %<assumes%>");
29353 0 : c_parser_skip_to_pragma_eol (parser);
29354 : }
29355 : }
29356 :
29357 : /* OpenMP 4.0
29358 : #pragma omp end declare target
29359 :
29360 : OpenMP 5.1
29361 : #pragma omp end assumes
29362 : #pragma omp end declare variant */
29363 :
29364 : static void
29365 226 : c_parser_omp_end (c_parser *parser)
29366 : {
29367 226 : location_t loc = c_parser_peek_token (parser)->location;
29368 226 : const char *p = "";
29369 226 : c_parser_consume_pragma (parser);
29370 226 : if (c_parser_next_token_is (parser, CPP_NAME))
29371 226 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
29372 226 : if (strcmp (p, "declare") == 0)
29373 : {
29374 180 : c_parser_consume_token (parser);
29375 180 : p = "";
29376 180 : if (c_parser_next_token_is (parser, CPP_NAME))
29377 180 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
29378 180 : if (strcmp (p, "target") == 0)
29379 : {
29380 154 : c_parser_consume_token (parser);
29381 154 : bool attr_syntax = parser->in_omp_attribute_pragma != NULL;
29382 154 : c_parser_skip_to_pragma_eol (parser);
29383 154 : if (!vec_safe_length (current_omp_declare_target_attribute))
29384 2 : error_at (loc, "%<#pragma omp end declare target%> without "
29385 : "corresponding %<#pragma omp declare target%> or "
29386 : "%<#pragma omp begin declare target%>");
29387 : else
29388 : {
29389 152 : c_omp_declare_target_attr
29390 152 : a = current_omp_declare_target_attribute->pop ();
29391 152 : if (a.attr_syntax != attr_syntax)
29392 : {
29393 16 : if (a.attr_syntax)
29394 12 : error_at (loc,
29395 : "%qs in attribute syntax terminated "
29396 : "with %qs in pragma syntax",
29397 : a.device_type >= 0 ? "begin declare target"
29398 : : "declare target",
29399 : "end declare target");
29400 : else
29401 12 : error_at (loc,
29402 : "%qs in pragma syntax terminated "
29403 : "with %qs in attribute syntax",
29404 : a.device_type >= 0 ? "begin declare target"
29405 : : "declare target",
29406 : "end declare target");
29407 : }
29408 : }
29409 : }
29410 26 : else if (strcmp (p, "variant") == 0)
29411 : {
29412 26 : c_parser_consume_token (parser);
29413 26 : bool attr_syntax = parser->in_omp_attribute_pragma != NULL;
29414 26 : c_parser_skip_to_pragma_eol (parser);
29415 26 : if (!vec_safe_length (current_omp_declare_variant_attribute))
29416 0 : error_at (loc, "%<#pragma omp end declare variant%> without "
29417 : "corresponding %<#pragma omp begin declare variant%>");
29418 : else
29419 : {
29420 26 : c_omp_declare_variant_attr
29421 26 : a = current_omp_declare_variant_attribute->pop ();
29422 26 : if (a.attr_syntax != attr_syntax)
29423 : {
29424 2 : if (a.attr_syntax)
29425 1 : error_at (loc,
29426 : "%<begin declare variant%> in attribute syntax "
29427 : "terminated with "
29428 : "%<end declare variant%> in pragma syntax");
29429 : else
29430 1 : error_at (loc,
29431 : "%<begin declare variant%> in pragma syntax "
29432 : "terminated with "
29433 : "%<end declare variant%> in attribute syntax");
29434 : }
29435 : }
29436 : }
29437 : else
29438 : {
29439 0 : c_parser_error (parser, "expected %<target%> or %<variant%>");
29440 0 : c_parser_skip_to_pragma_eol (parser);
29441 0 : return;
29442 : }
29443 : }
29444 46 : else if (strcmp (p, "assumes") == 0)
29445 : {
29446 46 : c_parser_consume_token (parser);
29447 46 : bool attr_syntax = parser->in_omp_attribute_pragma != NULL;
29448 46 : c_parser_skip_to_pragma_eol (parser);
29449 46 : if (!vec_safe_length (current_omp_begin_assumes))
29450 1 : error_at (loc, "%qs without corresponding %qs",
29451 : "#pragma omp end assumes", "#pragma omp begin assumes");
29452 : else
29453 : {
29454 45 : c_omp_begin_assumes_data
29455 45 : a = current_omp_begin_assumes->pop ();
29456 45 : if (a.attr_syntax != attr_syntax)
29457 : {
29458 8 : if (a.attr_syntax)
29459 4 : error_at (loc,
29460 : "%qs in attribute syntax terminated "
29461 : "with %qs in pragma syntax",
29462 : "begin assumes", "end assumes");
29463 : else
29464 4 : error_at (loc,
29465 : "%qs in pragma syntax terminated "
29466 : "with %qs in attribute syntax",
29467 : "begin assumes", "end assumes");
29468 : }
29469 : }
29470 : }
29471 : else
29472 : {
29473 0 : c_parser_error (parser, "expected %<declare%> or %<assumes%>");
29474 0 : c_parser_skip_to_pragma_eol (parser);
29475 : }
29476 : }
29477 :
29478 : /* OpenMP 5.0
29479 : #pragma omp declare mapper ([mapper-identifier :] type var) \
29480 : [clause [ [,] clause ] ... ] new-line */
29481 :
29482 : static void
29483 77 : c_parser_omp_declare_mapper (c_parser *parser, enum pragma_context context)
29484 : {
29485 77 : tree type, mapper_name = NULL_TREE, var = NULL_TREE, stmt, stmtlist;
29486 77 : tree maplist = NULL_TREE, mapper_id, mapper_decl, t;
29487 77 : c_token *token;
29488 :
29489 77 : if (context == pragma_struct || context == pragma_param)
29490 : {
29491 2 : error ("%<#pragma omp declare mapper%> not at file or block scope");
29492 2 : goto fail;
29493 : }
29494 :
29495 75 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
29496 0 : goto fail;
29497 :
29498 75 : token = c_parser_peek_token (parser);
29499 :
29500 75 : if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
29501 : {
29502 24 : switch (token->type)
29503 : {
29504 17 : case CPP_NAME:
29505 17 : mapper_name = token->value;
29506 17 : c_parser_consume_token (parser);
29507 17 : break;
29508 7 : case CPP_KEYWORD:
29509 7 : if (token->keyword == RID_DEFAULT)
29510 : {
29511 6 : mapper_name = NULL_TREE;
29512 6 : c_parser_consume_token (parser);
29513 6 : break;
29514 : }
29515 : /* Fallthrough. */
29516 1 : default:
29517 1 : error_at (token->location, "expected identifier or %<default%>");
29518 1 : c_parser_skip_to_pragma_eol (parser, false);
29519 1 : return;
29520 : }
29521 :
29522 23 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
29523 0 : goto fail;
29524 : }
29525 :
29526 74 : mapper_id = c_omp_mapper_id (mapper_name);
29527 74 : mapper_decl = c_omp_mapper_decl (mapper_id);
29528 :
29529 74 : {
29530 74 : location_t loc = c_parser_peek_token (parser)->location;
29531 74 : struct c_type_name *ctype = c_parser_type_name (parser);
29532 74 : type = groktypename (ctype, NULL, NULL);
29533 74 : if (type == error_mark_node)
29534 3 : goto fail;
29535 71 : if (!RECORD_OR_UNION_TYPE_P (type))
29536 : {
29537 5 : error_at (loc, "%qT is not a struct or union type in "
29538 : "%<#pragma omp declare mapper%>", type);
29539 5 : c_parser_skip_to_pragma_eol (parser, false);
29540 5 : return;
29541 : }
29542 76 : for (tree t = DECL_INITIAL (mapper_decl); t; t = TREE_CHAIN (t))
29543 17 : if (comptypes (TREE_PURPOSE (t), type))
29544 : {
29545 7 : error_at (loc, "redeclaration of %qs %<#pragma omp declare "
29546 7 : "mapper%> for type %qT", IDENTIFIER_POINTER (mapper_id)
29547 : + sizeof ("omp declare mapper ") - 1,
29548 : type);
29549 7 : tree prevmapper = TREE_VALUE (t);
29550 : /* Hmm, this location might not be very accurate. */
29551 7 : location_t ploc
29552 7 : = DECL_SOURCE_LOCATION (OMP_DECLARE_MAPPER_DECL (prevmapper));
29553 7 : inform (ploc, "%<#pragma omp declare mapper%> "
29554 : "previously declared here");
29555 7 : c_parser_skip_to_pragma_eol (parser, false);
29556 7 : return;
29557 : }
29558 : }
29559 :
29560 59 : token = c_parser_peek_token (parser);
29561 59 : if (token->type == CPP_NAME)
29562 : {
29563 57 : var = build_decl (token->location, VAR_DECL, token->value, type);
29564 57 : c_parser_consume_token (parser);
29565 57 : DECL_ARTIFICIAL (var) = 1;
29566 : }
29567 : else
29568 : {
29569 2 : error_at (token->location, "expected identifier");
29570 2 : goto fail;
29571 : }
29572 :
29573 57 : if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
29574 0 : goto fail;
29575 :
29576 57 : push_scope ();
29577 57 : stmtlist = push_stmt_list ();
29578 57 : pushdecl (var);
29579 57 : DECL_CONTEXT (var) = current_function_decl;
29580 :
29581 146 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
29582 : {
29583 90 : location_t here;
29584 90 : pragma_omp_clause c_kind;
29585 90 : here = c_parser_peek_token (parser)->location;
29586 90 : c_kind = c_parser_omp_clause_name (parser);
29587 90 : if (c_kind != PRAGMA_OMP_CLAUSE_MAP)
29588 : {
29589 1 : error_at (here, "unexpected clause");
29590 1 : goto fail;
29591 : }
29592 89 : maplist = c_parser_omp_clause_map (parser, maplist, true);
29593 : }
29594 :
29595 56 : if (maplist == NULL_TREE)
29596 : {
29597 1 : error_at (input_location, "missing %<map%> clause");
29598 1 : goto fail;
29599 : }
29600 : tree list;
29601 61 : for (list = maplist; list; list = OMP_CLAUSE_CHAIN (list))
29602 : {
29603 57 : tree dvar = OMP_CLAUSE_DECL (list);
29604 133 : while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
29605 76 : dvar = TREE_OPERAND (dvar, 0);
29606 57 : if (dvar == var)
29607 : break;
29608 : }
29609 55 : if (!list)
29610 4 : error_at (input_location, "at least one %<map%> clause must map %qD or an "
29611 : "element of it", var);
29612 :
29613 55 : stmt = make_node (OMP_DECLARE_MAPPER);
29614 55 : TREE_TYPE (stmt) = type;
29615 55 : OMP_DECLARE_MAPPER_ID (stmt) = mapper_name;
29616 55 : OMP_DECLARE_MAPPER_DECL (stmt) = var;
29617 55 : OMP_DECLARE_MAPPER_CLAUSES (stmt) = maplist;
29618 :
29619 55 : add_stmt (stmt);
29620 :
29621 55 : pop_stmt_list (stmtlist);
29622 55 : pop_scope ();
29623 :
29624 55 : c_parser_skip_to_pragma_eol (parser);
29625 :
29626 55 : t = tree_cons (type, stmt, DECL_INITIAL (mapper_decl));
29627 55 : DECL_INITIAL (mapper_decl) = t;
29628 :
29629 55 : return;
29630 :
29631 9 : fail:
29632 9 : c_parser_skip_to_pragma_eol (parser);
29633 : }
29634 :
29635 : /* OpenMP 4.0
29636 : #pragma omp declare reduction (reduction-id : typename-list : expression) \
29637 : initializer-clause[opt] new-line
29638 :
29639 : initializer-clause:
29640 : initializer (omp_priv = initializer)
29641 : initializer (function-name (argument-list)) */
29642 :
29643 : static void
29644 165 : c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
29645 : {
29646 165 : unsigned int tokens_avail = 0, i;
29647 165 : c_token *saved_tokens = NULL;
29648 165 : vec<tree> types = vNULL;
29649 165 : vec<c_token> clauses = vNULL;
29650 165 : enum tree_code reduc_code = ERROR_MARK;
29651 165 : tree reduc_id = NULL_TREE;
29652 165 : tree type;
29653 165 : location_t rloc = c_parser_peek_token (parser)->location;
29654 :
29655 165 : if (context == pragma_struct || context == pragma_param)
29656 : {
29657 2 : error ("%<#pragma omp declare reduction%> not at file or block scope");
29658 2 : goto fail;
29659 : }
29660 :
29661 163 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
29662 1 : goto fail;
29663 :
29664 162 : switch (c_parser_peek_token (parser)->type)
29665 : {
29666 : case CPP_PLUS:
29667 : reduc_code = PLUS_EXPR;
29668 : break;
29669 14 : case CPP_MULT:
29670 14 : reduc_code = MULT_EXPR;
29671 14 : break;
29672 0 : case CPP_MINUS:
29673 0 : reduc_code = MINUS_EXPR;
29674 0 : break;
29675 4 : case CPP_AND:
29676 4 : reduc_code = BIT_AND_EXPR;
29677 4 : break;
29678 0 : case CPP_XOR:
29679 0 : reduc_code = BIT_XOR_EXPR;
29680 0 : break;
29681 10 : case CPP_OR:
29682 10 : reduc_code = BIT_IOR_EXPR;
29683 10 : break;
29684 0 : case CPP_AND_AND:
29685 0 : reduc_code = TRUTH_ANDIF_EXPR;
29686 0 : break;
29687 0 : case CPP_OR_OR:
29688 0 : reduc_code = TRUTH_ORIF_EXPR;
29689 0 : break;
29690 89 : case CPP_NAME:
29691 89 : const char *p;
29692 89 : p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
29693 89 : if (strcmp (p, "min") == 0)
29694 : {
29695 : reduc_code = MIN_EXPR;
29696 : break;
29697 : }
29698 83 : if (strcmp (p, "max") == 0)
29699 : {
29700 : reduc_code = MAX_EXPR;
29701 : break;
29702 : }
29703 83 : reduc_id = c_parser_peek_token (parser)->value;
29704 83 : break;
29705 0 : default:
29706 0 : c_parser_error (parser,
29707 : "expected %<+%>, %<*%>, %<-%>, %<&%>, "
29708 : "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
29709 0 : goto fail;
29710 : }
29711 :
29712 162 : tree orig_reduc_id, reduc_decl;
29713 162 : orig_reduc_id = reduc_id;
29714 162 : reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
29715 162 : reduc_decl = c_omp_reduction_decl (reduc_id);
29716 162 : c_parser_consume_token (parser);
29717 :
29718 162 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
29719 0 : goto fail;
29720 :
29721 166 : while (true)
29722 : {
29723 164 : location_t loc = c_parser_peek_token (parser)->location;
29724 164 : struct c_type_name *ctype = c_parser_type_name (parser);
29725 164 : if (ctype != NULL)
29726 : {
29727 164 : type = groktypename (ctype, NULL, NULL);
29728 164 : if (type == error_mark_node)
29729 : ;
29730 164 : else if ((INTEGRAL_TYPE_P (type)
29731 164 : || SCALAR_FLOAT_TYPE_P (type)
29732 99 : || TREE_CODE (type) == COMPLEX_TYPE)
29733 69 : && orig_reduc_id == NULL_TREE)
29734 8 : error_at (loc, "predeclared arithmetic type in "
29735 : "%<#pragma omp declare reduction%>");
29736 156 : else if (TREE_CODE (type) == FUNCTION_TYPE
29737 151 : || TREE_CODE (type) == ARRAY_TYPE)
29738 8 : error_at (loc, "function or array type in "
29739 : "%<#pragma omp declare reduction%>");
29740 148 : else if (TYPE_ATOMIC (type))
29741 1 : error_at (loc, "%<_Atomic%> qualified type in "
29742 : "%<#pragma omp declare reduction%>");
29743 147 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
29744 8 : error_at (loc, "const, volatile or restrict qualified type in "
29745 : "%<#pragma omp declare reduction%>");
29746 : else
29747 : {
29748 139 : tree t;
29749 201 : for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
29750 66 : if (comptypes (TREE_PURPOSE (t), type))
29751 : {
29752 4 : error_at (loc, "redeclaration of %qs "
29753 : "%<#pragma omp declare reduction%> for "
29754 : "type %qT",
29755 4 : IDENTIFIER_POINTER (reduc_id)
29756 : + sizeof ("omp declare reduction ") - 1,
29757 : type);
29758 4 : location_t ploc
29759 4 : = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
29760 : 0));
29761 4 : inform (ploc, "%<#pragma omp declare reduction%> "
29762 : "previously declared here");
29763 4 : break;
29764 : }
29765 4 : if (t == NULL_TREE)
29766 135 : types.safe_push (type);
29767 : }
29768 164 : if (c_parser_next_token_is (parser, CPP_COMMA))
29769 2 : c_parser_consume_token (parser);
29770 : else
29771 : break;
29772 : }
29773 : else
29774 : break;
29775 2 : }
29776 :
29777 162 : if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
29778 162 : || types.is_empty ())
29779 : {
29780 34 : fail:
29781 34 : clauses.release ();
29782 34 : types.release ();
29783 460 : while (true)
29784 : {
29785 247 : c_token *token = c_parser_peek_token (parser);
29786 247 : if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
29787 : break;
29788 213 : c_parser_consume_token (parser);
29789 213 : }
29790 34 : c_parser_skip_to_pragma_eol (parser);
29791 34 : return;
29792 : }
29793 :
29794 133 : if (types.length () > 1)
29795 : {
29796 13 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
29797 : {
29798 12 : c_token *token = c_parser_peek_token (parser);
29799 12 : if (token->type == CPP_EOF)
29800 0 : goto fail;
29801 12 : clauses.safe_push (*token);
29802 12 : c_parser_consume_token (parser);
29803 : }
29804 1 : clauses.safe_push (*c_parser_peek_token (parser));
29805 1 : c_parser_skip_to_pragma_eol (parser);
29806 :
29807 : /* Make sure nothing tries to read past the end of the tokens. */
29808 1 : c_token eof_token;
29809 1 : memset (&eof_token, 0, sizeof (eof_token));
29810 1 : eof_token.type = CPP_EOF;
29811 1 : clauses.safe_push (eof_token);
29812 1 : clauses.safe_push (eof_token);
29813 : }
29814 :
29815 133 : int errs = errorcount;
29816 240 : FOR_EACH_VEC_ELT (types, i, type)
29817 : {
29818 135 : saved_tokens = parser->tokens;
29819 135 : tokens_avail = parser->tokens_avail;
29820 135 : if (!clauses.is_empty ())
29821 : {
29822 3 : parser->tokens = clauses.address ();
29823 3 : parser->tokens_avail = clauses.length ();
29824 3 : parser->in_pragma = true;
29825 : }
29826 :
29827 135 : bool nested = current_function_decl != NULL_TREE;
29828 135 : if (nested)
29829 27 : c_push_function_context ();
29830 135 : tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
29831 : reduc_id, default_function_type);
29832 135 : current_function_decl = fndecl;
29833 135 : allocate_struct_function (fndecl, true);
29834 135 : push_scope ();
29835 135 : tree stmt = push_stmt_list ();
29836 : /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
29837 : warn about these. */
29838 135 : tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
29839 : get_identifier ("omp_out"), type);
29840 135 : DECL_ARTIFICIAL (omp_out) = 1;
29841 135 : DECL_CONTEXT (omp_out) = fndecl;
29842 135 : pushdecl (omp_out);
29843 135 : tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
29844 : get_identifier ("omp_in"), type);
29845 135 : DECL_ARTIFICIAL (omp_in) = 1;
29846 135 : DECL_CONTEXT (omp_in) = fndecl;
29847 135 : pushdecl (omp_in);
29848 135 : struct c_expr combiner = c_parser_expression (parser);
29849 135 : struct c_expr initializer;
29850 135 : tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
29851 135 : bool bad = false;
29852 135 : initializer.set_error ();
29853 135 : if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
29854 : bad = true;
29855 135 : else if (c_parser_next_token_is (parser, CPP_COMMA)
29856 135 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
29857 2 : c_parser_consume_token (parser);
29858 2 : if (!bad
29859 135 : && (c_parser_next_token_is (parser, CPP_NAME)
29860 78 : && strcmp (IDENTIFIER_POINTER
29861 : (c_parser_peek_token (parser)->value),
29862 : "initializer") == 0))
29863 : {
29864 78 : c_parser_consume_token (parser);
29865 78 : pop_scope ();
29866 78 : push_scope ();
29867 78 : omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
29868 : get_identifier ("omp_priv"), type);
29869 78 : DECL_ARTIFICIAL (omp_priv) = 1;
29870 78 : DECL_INITIAL (omp_priv) = error_mark_node;
29871 78 : DECL_CONTEXT (omp_priv) = fndecl;
29872 78 : pushdecl (omp_priv);
29873 78 : omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
29874 : get_identifier ("omp_orig"), type);
29875 78 : DECL_ARTIFICIAL (omp_orig) = 1;
29876 78 : DECL_CONTEXT (omp_orig) = fndecl;
29877 78 : pushdecl (omp_orig);
29878 78 : if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
29879 : bad = true;
29880 78 : else if (!c_parser_next_token_is (parser, CPP_NAME))
29881 : {
29882 0 : c_parser_error (parser, "expected %<omp_priv%> or "
29883 : "function-name");
29884 0 : bad = true;
29885 : }
29886 78 : else if (strcmp (IDENTIFIER_POINTER
29887 : (c_parser_peek_token (parser)->value),
29888 : "omp_priv") != 0)
29889 : {
29890 20 : if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
29891 20 : || c_parser_peek_token (parser)->id_kind != C_ID_ID)
29892 : {
29893 0 : c_parser_error (parser, "expected function-name %<(%>");
29894 0 : bad = true;
29895 : }
29896 : else
29897 20 : initializer = c_parser_postfix_expression (parser);
29898 20 : if (initializer.value
29899 20 : && TREE_CODE (initializer.value) == CALL_EXPR)
29900 : {
29901 : int j;
29902 : tree c = initializer.value;
29903 21 : for (j = 0; j < call_expr_nargs (c); j++)
29904 : {
29905 20 : tree a = CALL_EXPR_ARG (c, j);
29906 20 : STRIP_NOPS (a);
29907 20 : if (TREE_CODE (a) == ADDR_EXPR
29908 20 : && TREE_OPERAND (a, 0) == omp_priv)
29909 : break;
29910 : }
29911 20 : if (j == call_expr_nargs (c))
29912 1 : error ("one of the initializer call arguments should be "
29913 : "%<&omp_priv%>");
29914 : }
29915 : }
29916 : else
29917 : {
29918 58 : c_parser_consume_token (parser);
29919 58 : if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
29920 : bad = true;
29921 : else
29922 : {
29923 56 : tree st = push_stmt_list ();
29924 56 : location_t loc = c_parser_peek_token (parser)->location;
29925 56 : rich_location richloc (line_table, loc);
29926 56 : start_init (omp_priv, NULL_TREE, false, false, &richloc);
29927 56 : struct c_expr init = c_parser_initializer (parser, omp_priv);
29928 56 : finish_init ();
29929 56 : finish_decl (omp_priv, loc, init.value,
29930 : init.original_type, NULL_TREE);
29931 56 : pop_stmt_list (st);
29932 56 : }
29933 : }
29934 0 : if (!bad
29935 76 : && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
29936 : bad = true;
29937 : }
29938 :
29939 135 : if (!bad)
29940 : {
29941 133 : c_parser_skip_to_pragma_eol (parser);
29942 :
29943 190 : tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
29944 133 : DECL_INITIAL (reduc_decl));
29945 133 : DECL_INITIAL (reduc_decl) = t;
29946 133 : DECL_SOURCE_LOCATION (omp_out) = rloc;
29947 133 : TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
29948 133 : TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
29949 133 : TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
29950 133 : walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
29951 : &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
29952 133 : if (omp_priv)
29953 : {
29954 76 : DECL_SOURCE_LOCATION (omp_priv) = rloc;
29955 76 : TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
29956 76 : TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
29957 76 : TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
29958 76 : walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
29959 : &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
29960 76 : walk_tree (&DECL_INITIAL (omp_priv),
29961 : c_check_omp_declare_reduction_r,
29962 : &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
29963 : }
29964 : }
29965 :
29966 135 : pop_stmt_list (stmt);
29967 135 : pop_scope ();
29968 135 : if (cfun->language != NULL)
29969 : {
29970 0 : ggc_free (cfun->language);
29971 0 : cfun->language = NULL;
29972 : }
29973 135 : set_cfun (NULL);
29974 135 : current_function_decl = NULL_TREE;
29975 135 : if (nested)
29976 27 : c_pop_function_context ();
29977 :
29978 135 : if (!clauses.is_empty ())
29979 : {
29980 3 : parser->tokens = saved_tokens;
29981 3 : parser->tokens_avail = tokens_avail;
29982 : }
29983 135 : if (bad)
29984 2 : goto fail;
29985 133 : if (errs != errorcount)
29986 : break;
29987 : }
29988 :
29989 131 : clauses.release ();
29990 131 : types.release ();
29991 : }
29992 :
29993 : /* OpenMP 4.0
29994 : #pragma omp declare simd declare-simd-clauses[optseq] new-line
29995 : #pragma omp declare reduction (reduction-id : typename-list : expression) \
29996 : initializer-clause[opt] new-line
29997 : #pragma omp declare target new-line
29998 :
29999 : OpenMP 5.0
30000 : #pragma omp declare variant (identifier) match (context-selector)
30001 :
30002 : OpenMP 5.1
30003 : #pragma omp declare variant (identifier) match (context-selector) \
30004 : adjust_args(adjust-op:argument-list) */
30005 :
30006 : static bool
30007 1352 : c_parser_omp_declare (c_parser *parser, enum pragma_context context)
30008 : {
30009 1352 : c_parser_consume_pragma (parser);
30010 1352 : if (c_parser_next_token_is (parser, CPP_NAME))
30011 : {
30012 1352 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
30013 1352 : if (strcmp (p, "simd") == 0)
30014 : {
30015 : /* c_parser_consume_token (parser); done in
30016 : c_parser_omp_declare_simd. */
30017 305 : c_parser_omp_declare_simd (parser, context);
30018 305 : return true;
30019 : }
30020 1047 : if (strcmp (p, "reduction") == 0)
30021 : {
30022 165 : c_parser_consume_token (parser);
30023 165 : c_parser_omp_declare_reduction (parser, context);
30024 165 : return false;
30025 : }
30026 882 : if (strcmp (p, "mapper") == 0)
30027 : {
30028 77 : c_parser_consume_token (parser);
30029 77 : c_parser_omp_declare_mapper (parser, context);
30030 77 : return false;
30031 : }
30032 805 : if (!flag_openmp) /* flag_openmp_simd */
30033 : {
30034 0 : c_parser_skip_to_pragma_eol (parser, false);
30035 0 : return false;
30036 : }
30037 805 : if (strcmp (p, "target") == 0)
30038 : {
30039 298 : c_parser_consume_token (parser);
30040 298 : c_parser_omp_declare_target (parser);
30041 298 : return false;
30042 : }
30043 507 : if (strcmp (p, "variant") == 0)
30044 : {
30045 : /* c_parser_consume_token (parser); done in
30046 : c_parser_omp_declare_simd. */
30047 507 : c_parser_omp_declare_simd (parser, context);
30048 507 : return true;
30049 : }
30050 : }
30051 :
30052 0 : c_parser_error (parser, "expected %<simd%>, %<reduction%>, "
30053 : "%<target%> or %<variant%>");
30054 0 : c_parser_skip_to_pragma_eol (parser);
30055 0 : return false;
30056 : }
30057 :
30058 : /* OpenMP 5.0
30059 : #pragma omp requires clauses[optseq] new-line */
30060 :
30061 : static void
30062 64 : c_parser_omp_requires (c_parser *parser)
30063 : {
30064 64 : enum omp_requires new_req = (enum omp_requires) 0;
30065 :
30066 64 : c_parser_consume_pragma (parser);
30067 :
30068 64 : location_t loc = c_parser_peek_token (parser)->location;
30069 142 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
30070 : {
30071 82 : if (c_parser_next_token_is (parser, CPP_COMMA)
30072 82 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
30073 14 : c_parser_consume_token (parser);
30074 :
30075 82 : if (c_parser_next_token_is (parser, CPP_NAME))
30076 : {
30077 81 : const char *p
30078 81 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
30079 81 : location_t cloc = c_parser_peek_token (parser)->location;
30080 81 : enum omp_requires this_req = (enum omp_requires) 0;
30081 :
30082 81 : if (!strcmp (p, "unified_address"))
30083 : this_req = OMP_REQUIRES_UNIFIED_ADDRESS;
30084 67 : else if (!strcmp (p, "unified_shared_memory"))
30085 : this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY;
30086 55 : else if (!strcmp (p, "self_maps"))
30087 : this_req = OMP_REQUIRES_SELF_MAPS;
30088 49 : else if (!strcmp (p, "dynamic_allocators"))
30089 : this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS;
30090 38 : else if (!strcmp (p, "reverse_offload"))
30091 : this_req = OMP_REQUIRES_REVERSE_OFFLOAD;
30092 21 : else if (!strcmp (p, "atomic_default_mem_order"))
30093 : {
30094 20 : c_parser_consume_token (parser);
30095 :
30096 20 : matching_parens parens;
30097 20 : if (parens.require_open (parser))
30098 : {
30099 20 : if (c_parser_next_token_is (parser, CPP_NAME))
30100 : {
30101 19 : tree v = c_parser_peek_token (parser)->value;
30102 19 : p = IDENTIFIER_POINTER (v);
30103 :
30104 19 : if (!strcmp (p, "seq_cst"))
30105 : this_req
30106 : = (enum omp_requires) OMP_MEMORY_ORDER_SEQ_CST;
30107 10 : else if (!strcmp (p, "relaxed"))
30108 : this_req
30109 : = (enum omp_requires) OMP_MEMORY_ORDER_RELAXED;
30110 9 : else if (!strcmp (p, "release"))
30111 : this_req
30112 : = (enum omp_requires) OMP_MEMORY_ORDER_RELEASE;
30113 7 : else if (!strcmp (p, "acq_rel"))
30114 : this_req
30115 : = (enum omp_requires) OMP_MEMORY_ORDER_ACQ_REL;
30116 4 : else if (!strcmp (p, "acquire"))
30117 : this_req
30118 : = (enum omp_requires) OMP_MEMORY_ORDER_ACQUIRE;
30119 : }
30120 : if (this_req == 0)
30121 : {
30122 2 : error_at (c_parser_peek_token (parser)->location,
30123 : "expected %<acq_rel%>, %<acquire%>, "
30124 : "%<relaxed%>, %<release%> or %<seq_cst%>");
30125 2 : switch (c_parser_peek_token (parser)->type)
30126 : {
30127 : case CPP_EOF:
30128 : case CPP_PRAGMA_EOL:
30129 : case CPP_CLOSE_PAREN:
30130 : break;
30131 1 : default:
30132 1 : if (c_parser_peek_2nd_token (parser)->type
30133 : == CPP_CLOSE_PAREN)
30134 1 : c_parser_consume_token (parser);
30135 : break;
30136 : }
30137 : }
30138 : else
30139 18 : c_parser_consume_token (parser);
30140 :
30141 20 : parens.skip_until_found_close (parser);
30142 20 : if (this_req == 0)
30143 : {
30144 2 : c_parser_skip_to_pragma_eol (parser, false);
30145 2 : return;
30146 : }
30147 : }
30148 18 : p = NULL;
30149 : }
30150 : else
30151 : {
30152 1 : error_at (cloc, "expected %<unified_address%>, "
30153 : "%<unified_shared_memory%>, "
30154 : "%<self_maps%>, "
30155 : "%<dynamic_allocators%>, "
30156 : "%<reverse_offload%> "
30157 : "or %<atomic_default_mem_order%> clause");
30158 1 : c_parser_skip_to_pragma_eol (parser, false);
30159 1 : return;
30160 : }
30161 18 : if (p)
30162 60 : c_parser_consume_token (parser);
30163 78 : if (this_req)
30164 : {
30165 78 : if ((this_req & ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
30166 : {
30167 60 : if ((this_req & new_req) != 0)
30168 4 : error_at (cloc, "too many %qs clauses", p);
30169 60 : if (this_req != OMP_REQUIRES_DYNAMIC_ALLOCATORS
30170 49 : && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0)
30171 4 : error_at (cloc, "%qs clause used lexically after first "
30172 : "target construct or offloading API", p);
30173 : }
30174 18 : else if ((new_req & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
30175 : {
30176 1 : error_at (cloc, "too many %qs clauses",
30177 : "atomic_default_mem_order");
30178 1 : this_req = (enum omp_requires) 0;
30179 : }
30180 17 : else if ((omp_requires_mask
30181 : & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
30182 : {
30183 2 : error_at (cloc, "more than one %<atomic_default_mem_order%>"
30184 : " clause in a single compilation unit");
30185 2 : this_req
30186 2 : = (enum omp_requires)
30187 2 : (omp_requires_mask
30188 : & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER);
30189 : }
30190 15 : else if ((omp_requires_mask
30191 : & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED) != 0)
30192 1 : error_at (cloc, "%<atomic_default_mem_order%> clause used "
30193 : "lexically after first %<atomic%> construct "
30194 : "without memory order clause");
30195 78 : new_req = (enum omp_requires) (new_req | this_req);
30196 78 : omp_requires_mask
30197 78 : = (enum omp_requires) (omp_requires_mask | this_req);
30198 78 : continue;
30199 : }
30200 : }
30201 : break;
30202 : }
30203 61 : c_parser_skip_to_pragma_eol (parser);
30204 :
30205 61 : if (new_req == 0)
30206 1 : error_at (loc, "%<pragma omp requires%> requires at least one clause");
30207 : }
30208 :
30209 : /* Helper function for c_parser_omp_taskloop.
30210 : Disallow zero sized or potentially zero sized task reductions. */
30211 :
30212 : static tree
30213 413 : c_finish_taskloop_clauses (tree clauses)
30214 : {
30215 413 : tree *pc = &clauses;
30216 2064 : for (tree c = clauses; c; c = *pc)
30217 : {
30218 1651 : bool remove = false;
30219 1651 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
30220 : {
30221 143 : tree type = strip_array_types (TREE_TYPE (OMP_CLAUSE_DECL (c)));
30222 143 : if (integer_zerop (TYPE_SIZE_UNIT (type)))
30223 : {
30224 2 : error_at (OMP_CLAUSE_LOCATION (c),
30225 : "zero sized type %qT in %<reduction%> clause", type);
30226 2 : remove = true;
30227 : }
30228 141 : else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
30229 : {
30230 0 : error_at (OMP_CLAUSE_LOCATION (c),
30231 : "variable sized type %qT in %<reduction%> clause",
30232 : type);
30233 0 : remove = true;
30234 : }
30235 : }
30236 2 : if (remove)
30237 2 : *pc = OMP_CLAUSE_CHAIN (c);
30238 : else
30239 1649 : pc = &OMP_CLAUSE_CHAIN (c);
30240 : }
30241 413 : return clauses;
30242 : }
30243 :
30244 : /* OpenMP 4.5:
30245 : #pragma omp taskloop taskloop-clause[optseq] new-line
30246 : for-loop
30247 :
30248 : #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
30249 : for-loop */
30250 :
30251 : #define OMP_TASKLOOP_CLAUSE_MASK \
30252 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
30253 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
30254 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
30255 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
30256 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
30257 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
30258 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
30259 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
30260 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
30261 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
30262 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
30263 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
30264 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
30265 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \
30266 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALLOCATE) \
30267 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
30268 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
30269 :
30270 : static tree
30271 418 : c_parser_omp_taskloop (location_t loc, c_parser *parser,
30272 : char *p_name, omp_clause_mask mask, tree *cclauses,
30273 : bool *if_p)
30274 : {
30275 418 : tree clauses, block, ret;
30276 :
30277 418 : strcat (p_name, " taskloop");
30278 418 : mask |= OMP_TASKLOOP_CLAUSE_MASK;
30279 : /* #pragma omp parallel master taskloop{, simd} disallow in_reduction
30280 : clause. */
30281 418 : if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
30282 94 : mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION);
30283 :
30284 418 : if (c_parser_next_token_is (parser, CPP_NAME))
30285 : {
30286 342 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
30287 :
30288 342 : if (strcmp (p, "simd") == 0)
30289 : {
30290 178 : tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
30291 178 : if (cclauses == NULL)
30292 84 : cclauses = cclauses_buf;
30293 178 : c_parser_consume_token (parser);
30294 178 : if (!flag_openmp) /* flag_openmp_simd */
30295 3 : return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
30296 3 : if_p);
30297 175 : block = c_begin_compound_stmt (true);
30298 175 : ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
30299 175 : block = c_end_compound_stmt (loc, block, true);
30300 175 : if (ret == NULL)
30301 : return ret;
30302 175 : ret = make_node (OMP_TASKLOOP);
30303 175 : TREE_TYPE (ret) = void_type_node;
30304 175 : OMP_FOR_BODY (ret) = block;
30305 175 : OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
30306 175 : OMP_FOR_CLAUSES (ret)
30307 175 : = c_finish_taskloop_clauses (OMP_FOR_CLAUSES (ret));
30308 175 : SET_EXPR_LOCATION (ret, loc);
30309 175 : add_stmt (ret);
30310 175 : return ret;
30311 : }
30312 : }
30313 240 : if (!flag_openmp) /* flag_openmp_simd */
30314 : {
30315 2 : c_parser_skip_to_pragma_eol (parser, false);
30316 2 : return NULL_TREE;
30317 : }
30318 :
30319 238 : clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
30320 238 : if (cclauses)
30321 : {
30322 66 : omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses);
30323 66 : clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
30324 : }
30325 :
30326 238 : clauses = c_finish_taskloop_clauses (clauses);
30327 238 : block = c_begin_compound_stmt (true);
30328 238 : ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p);
30329 238 : block = c_end_compound_stmt (loc, block, true);
30330 238 : add_stmt (block);
30331 :
30332 238 : return ret;
30333 : }
30334 :
30335 : /* OpenMP 5.1: Parse sizes list for "omp tile sizes"
30336 : sizes ( size-expr-list ) */
30337 : static tree
30338 476 : c_parser_omp_tile_sizes (c_parser *parser, location_t loc)
30339 : {
30340 476 : tree sizes = NULL_TREE;
30341 :
30342 476 : if (c_parser_next_token_is (parser, CPP_COMMA))
30343 2 : c_parser_consume_token (parser);
30344 :
30345 476 : c_token *tok = c_parser_peek_token (parser);
30346 476 : if (tok->type != CPP_NAME
30347 476 : || strcmp ("sizes", IDENTIFIER_POINTER (tok->value)))
30348 : {
30349 1 : c_parser_error (parser, "expected %<sizes%>");
30350 1 : return error_mark_node;
30351 : }
30352 475 : c_parser_consume_token (parser);
30353 :
30354 475 : matching_parens parens;
30355 475 : if (!parens.require_open (parser))
30356 4 : return error_mark_node;
30357 :
30358 471 : vec<tree, va_gc> *sizes_vec
30359 471 : = c_parser_expr_list (parser, true, true, NULL, NULL, NULL, NULL);
30360 471 : sizes = build_tree_list_vec (sizes_vec);
30361 471 : release_tree_vector (sizes_vec);
30362 :
30363 1669 : for (tree s = sizes; s; s = TREE_CHAIN (s))
30364 : {
30365 734 : tree expr = TREE_VALUE (s);
30366 734 : if (expr == error_mark_node)
30367 : {
30368 7 : parens.skip_until_found_close (parser);
30369 7 : return error_mark_node;
30370 : }
30371 :
30372 727 : HOST_WIDE_INT n;
30373 1454 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
30374 724 : || !tree_fits_shwi_p (expr)
30375 722 : || (n = tree_to_shwi (expr)) <= 0
30376 1440 : || (int) n != n)
30377 : {
30378 14 : c_parser_error (parser, "%<sizes%> argument needs positive"
30379 : " integral constant");
30380 14 : TREE_VALUE (s) = integer_one_node;
30381 : }
30382 : }
30383 464 : parens.require_close (parser);
30384 :
30385 464 : gcc_assert (sizes);
30386 464 : tree c = build_omp_clause (loc, OMP_CLAUSE_SIZES);
30387 464 : OMP_CLAUSE_SIZES_LIST (c) = sizes;
30388 :
30389 464 : return c;
30390 : }
30391 :
30392 : /* OpenMP 5.1:
30393 : #pragma omp tile sizes ( size-expr-list ) new-line
30394 : for-loop
30395 :
30396 : LOC is the location of the #pragma token. */
30397 :
30398 : static tree
30399 476 : c_parser_omp_tile (location_t loc, c_parser *parser, bool *if_p)
30400 : {
30401 476 : tree clauses = c_parser_omp_tile_sizes (parser, loc);
30402 476 : c_parser_skip_to_pragma_eol (parser);
30403 :
30404 476 : if (!clauses || clauses == error_mark_node)
30405 12 : return error_mark_node;
30406 :
30407 464 : tree block = c_begin_compound_stmt (true);
30408 464 : tree ret = c_parser_omp_for_loop (loc, parser, OMP_TILE, clauses,
30409 : NULL, if_p);
30410 464 : block = c_end_compound_stmt (loc, block, true);
30411 464 : add_stmt (block);
30412 :
30413 464 : return ret;
30414 : }
30415 :
30416 : #define OMP_UNROLL_CLAUSE_MASK \
30417 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARTIAL) \
30418 : | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FULL))
30419 :
30420 : /* OpenMP 5.1
30421 : #pragma omp unroll unroll-clause[optseq] new-line
30422 : for-loop
30423 :
30424 : LOC is the location of the #pragma token. */
30425 :
30426 : static tree
30427 313 : c_parser_omp_unroll (location_t loc, c_parser *parser, bool *if_p)
30428 : {
30429 313 : tree clauses = c_parser_omp_all_clauses (parser, OMP_UNROLL_CLAUSE_MASK,
30430 : "#pragma omp unroll", true);
30431 :
30432 313 : tree block = c_begin_compound_stmt (true);
30433 313 : tree ret = c_parser_omp_for_loop (loc, parser, OMP_UNROLL, clauses,
30434 : NULL, if_p);
30435 313 : block = c_end_compound_stmt (loc, block, true);
30436 313 : add_stmt (block);
30437 :
30438 313 : return ret;
30439 : }
30440 :
30441 : /* OpenMP 5.1
30442 : #pragma omp nothing new-line */
30443 :
30444 : static void
30445 79 : c_parser_omp_nothing (c_parser *parser)
30446 : {
30447 79 : c_parser_consume_pragma (parser);
30448 79 : c_parser_skip_to_pragma_eol (parser);
30449 79 : }
30450 :
30451 : /* OpenMP 5.1
30452 : #pragma omp error clauses[optseq] new-line */
30453 :
30454 : static bool
30455 126 : c_parser_omp_error (c_parser *parser, enum pragma_context context)
30456 : {
30457 126 : int at_compilation = -1;
30458 126 : int severity_fatal = -1;
30459 126 : tree message = NULL_TREE;
30460 126 : bool bad = false;
30461 126 : location_t loc = c_parser_peek_token (parser)->location;
30462 :
30463 126 : c_parser_consume_pragma (parser);
30464 :
30465 463 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
30466 : {
30467 214 : if (c_parser_next_token_is (parser, CPP_COMMA)
30468 214 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
30469 21 : c_parser_consume_token (parser);
30470 :
30471 214 : if (!c_parser_next_token_is (parser, CPP_NAME))
30472 : break;
30473 :
30474 213 : const char *p
30475 213 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
30476 213 : location_t cloc = c_parser_peek_token (parser)->location;
30477 213 : static const char *args[] = {
30478 : "execution", "compilation", "warning", "fatal"
30479 : };
30480 213 : int *v = NULL;
30481 213 : int idx = 0, n = -1;
30482 213 : tree m = NULL_TREE;
30483 :
30484 213 : if (!strcmp (p, "at"))
30485 : v = &at_compilation;
30486 127 : else if (!strcmp (p, "severity"))
30487 : {
30488 : v = &severity_fatal;
30489 : idx += 2;
30490 : }
30491 82 : else if (strcmp (p, "message"))
30492 : {
30493 2 : error_at (cloc,
30494 : "expected %<at%>, %<severity%> or %<message%> clause");
30495 2 : c_parser_skip_to_pragma_eol (parser, false);
30496 2 : return false;
30497 : }
30498 :
30499 211 : c_parser_consume_token (parser);
30500 :
30501 211 : matching_parens parens;
30502 211 : if (parens.require_open (parser))
30503 : {
30504 208 : if (v == NULL)
30505 : {
30506 79 : location_t expr_loc = c_parser_peek_token (parser)->location;
30507 79 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
30508 79 : expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
30509 79 : m = convert (const_string_type_node, expr.value);
30510 79 : m = c_fully_fold (m, false, NULL);
30511 : }
30512 : else
30513 : {
30514 129 : if (c_parser_next_token_is (parser, CPP_NAME))
30515 : {
30516 125 : tree val = c_parser_peek_token (parser)->value;
30517 125 : const char *q = IDENTIFIER_POINTER (val);
30518 :
30519 125 : if (!strcmp (q, args[idx]))
30520 : n = 0;
30521 41 : else if (!strcmp (q, args[idx + 1]))
30522 : n = 1;
30523 : }
30524 : if (n == -1)
30525 : {
30526 6 : error_at (c_parser_peek_token (parser)->location,
30527 6 : "expected %qs or %qs", args[idx], args[idx + 1]);
30528 6 : bad = true;
30529 6 : switch (c_parser_peek_token (parser)->type)
30530 : {
30531 : case CPP_EOF:
30532 : case CPP_PRAGMA_EOL:
30533 : case CPP_CLOSE_PAREN:
30534 : break;
30535 4 : default:
30536 4 : if (c_parser_peek_2nd_token (parser)->type
30537 : == CPP_CLOSE_PAREN)
30538 2 : c_parser_consume_token (parser);
30539 : break;
30540 : }
30541 : }
30542 : else
30543 123 : c_parser_consume_token (parser);
30544 : }
30545 :
30546 208 : parens.skip_until_found_close (parser);
30547 :
30548 208 : if (v == NULL)
30549 : {
30550 79 : if (message)
30551 : {
30552 1 : error_at (cloc, "too many %qs clauses", p);
30553 1 : bad = true;
30554 : }
30555 : else
30556 : message = m;
30557 : }
30558 129 : else if (n != -1)
30559 : {
30560 123 : if (*v != -1)
30561 : {
30562 2 : error_at (cloc, "too many %qs clauses", p);
30563 2 : bad = true;
30564 : }
30565 : else
30566 121 : *v = n;
30567 : }
30568 : }
30569 : else
30570 : bad = true;
30571 : }
30572 124 : c_parser_skip_to_pragma_eol (parser);
30573 124 : if (bad)
30574 : return true;
30575 :
30576 112 : if (at_compilation == -1)
30577 33 : at_compilation = 1;
30578 112 : if (severity_fatal == -1)
30579 74 : severity_fatal = 1;
30580 112 : if (!at_compilation)
30581 : {
30582 58 : if (context != pragma_compound)
30583 : {
30584 7 : error_at (loc, "%<#pragma omp error%> with %<at(execution)%> clause "
30585 : "may only be used in compound statements");
30586 7 : return true;
30587 : }
30588 51 : if (parser->omp_for_parse_state
30589 1 : && parser->omp_for_parse_state->in_intervening_code)
30590 : {
30591 1 : error_at (loc, "%<#pragma omp error%> with %<at(execution)%> clause "
30592 : "may not be used in intervening code");
30593 1 : parser->omp_for_parse_state->fail = true;
30594 1 : return true;
30595 : }
30596 50 : tree fndecl
30597 58 : = builtin_decl_explicit (severity_fatal ? BUILT_IN_GOMP_ERROR
30598 : : BUILT_IN_GOMP_WARNING);
30599 50 : if (!message)
30600 4 : message = build_zero_cst (const_string_type_node);
30601 50 : tree stmt = build_call_expr_loc (loc, fndecl, 2, message,
30602 : build_all_ones_cst (size_type_node));
30603 50 : add_stmt (stmt);
30604 50 : return true;
30605 : }
30606 54 : const char *msg = NULL;
30607 54 : if (message)
30608 : {
30609 27 : msg = c_getstr (message);
30610 27 : if (msg == NULL)
30611 6 : msg = _("<message unknown at compile time>");
30612 : }
30613 15 : const enum diagnostics::kind diag_kind = (severity_fatal
30614 54 : ? diagnostics::kind::error
30615 : : diagnostics::kind::warning);
30616 54 : if (msg)
30617 27 : emit_diagnostic (diag_kind, loc, 0,
30618 : "%<pragma omp error%> encountered: %s", msg);
30619 : else
30620 27 : emit_diagnostic (diag_kind, loc, 0,
30621 : "%<pragma omp error%> encountered");
30622 : return false;
30623 : }
30624 :
30625 : /* Assumption clauses
30626 : OpenMP 5.1:
30627 : absent (directive-name-list)
30628 : contains (directive-name-list)
30629 : holds (expression)
30630 : no_openmp
30631 : no_openmp_routines
30632 : no_parallelism
30633 :
30634 : OpenMP 6.0:
30635 : no_openmp_constructs */
30636 :
30637 : static void
30638 130 : c_parser_omp_assumption_clauses (c_parser *parser, bool is_assume)
30639 : {
30640 130 : bool no_openmp = false;
30641 130 : bool no_openmp_constructs = false;
30642 130 : bool no_openmp_routines = false;
30643 130 : bool no_parallelism = false;
30644 130 : bitmap_head absent_head, contains_head;
30645 :
30646 130 : bitmap_obstack_initialize (NULL);
30647 130 : bitmap_initialize (&absent_head, &bitmap_default_obstack);
30648 130 : bitmap_initialize (&contains_head, &bitmap_default_obstack);
30649 :
30650 130 : if (c_parser_next_token_is (parser, CPP_PRAGMA_EOL))
30651 3 : error_at (c_parser_peek_token (parser)->location,
30652 : "expected at least one assumption clause");
30653 :
30654 359 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
30655 : {
30656 233 : if (c_parser_next_token_is (parser, CPP_COMMA)
30657 233 : && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
30658 53 : c_parser_consume_token (parser);
30659 :
30660 233 : if (!c_parser_next_token_is (parser, CPP_NAME))
30661 : break;
30662 :
30663 233 : const char *p
30664 233 : = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
30665 233 : location_t cloc = c_parser_peek_token (parser)->location;
30666 :
30667 233 : if (!strcmp (p, "no_openmp"))
30668 : {
30669 18 : c_parser_consume_token (parser);
30670 18 : if (no_openmp)
30671 3 : error_at (cloc, "too many %qs clauses", "no_openmp");
30672 229 : no_openmp = true;
30673 : }
30674 215 : else if (!strcmp (p, "no_openmp_constructs"))
30675 : {
30676 4 : c_parser_consume_token (parser);
30677 4 : if (no_openmp_constructs)
30678 1 : error_at (cloc, "too many %qs clauses", "no_openmp_constructs");
30679 229 : no_openmp_constructs = true;
30680 : }
30681 211 : else if (!strcmp (p, "no_openmp_routines"))
30682 : {
30683 17 : c_parser_consume_token (parser);
30684 17 : if (no_openmp_routines)
30685 3 : error_at (cloc, "too many %qs clauses", "no_openmp_routines");
30686 229 : no_openmp_routines = true;
30687 : }
30688 194 : else if (!strcmp (p, "no_parallelism"))
30689 : {
30690 19 : c_parser_consume_token (parser);
30691 19 : if (no_parallelism)
30692 3 : error_at (cloc, "too many %qs clauses", "no_parallelism");
30693 229 : no_parallelism = true;
30694 : }
30695 175 : else if (!strcmp (p, "holds"))
30696 : {
30697 19 : c_parser_consume_token (parser);
30698 19 : matching_parens parens;
30699 19 : if (parens.require_open (parser))
30700 : {
30701 19 : location_t eloc = c_parser_peek_token (parser)->location;
30702 19 : c_expr expr = c_parser_expr_no_commas (parser, NULL);
30703 19 : tree t = convert_lvalue_to_rvalue (eloc, expr, true, true).value;
30704 19 : t = c_objc_common_truthvalue_conversion (eloc, t);
30705 19 : t = c_fully_fold (t, false, NULL);
30706 19 : if (is_assume && t != error_mark_node)
30707 : {
30708 11 : tree fn = build_call_expr_internal_loc (eloc, IFN_ASSUME,
30709 : void_type_node, 1,
30710 : t);
30711 11 : add_stmt (fn);
30712 : }
30713 19 : parens.skip_until_found_close (parser);
30714 : }
30715 : }
30716 156 : else if (!strcmp (p, "absent") || !strcmp (p, "contains"))
30717 : {
30718 146 : c_parser_consume_token (parser);
30719 146 : matching_parens parens;
30720 146 : if (parens.require_open (parser))
30721 : {
30722 604 : do
30723 : {
30724 375 : const char *directive[3] = {};
30725 375 : int i;
30726 375 : location_t dloc = c_parser_peek_token (parser)->location;
30727 844 : for (i = 0; i < 3; i++)
30728 : {
30729 811 : tree id;
30730 811 : if (c_parser_peek_nth_token (parser, i + 1)->type
30731 : == CPP_NAME)
30732 457 : id = c_parser_peek_nth_token (parser, i + 1)->value;
30733 354 : else if (c_parser_peek_nth_token (parser, i + 1)->keyword
30734 : != RID_MAX)
30735 : {
30736 12 : enum rid rid
30737 12 : = c_parser_peek_nth_token (parser, i + 1)->keyword;
30738 12 : id = ridpointers[rid];
30739 : }
30740 : else
30741 : break;
30742 469 : directive[i] = IDENTIFIER_POINTER (id);
30743 : }
30744 375 : if (i == 0)
30745 0 : error_at (dloc, "expected directive name");
30746 : else
30747 : {
30748 375 : const struct c_omp_directive *dir
30749 375 : = c_omp_categorize_directive (directive[0],
30750 : directive[1],
30751 : directive[2]);
30752 375 : if (dir
30753 372 : && dir->id != PRAGMA_OMP_END
30754 369 : && (dir->kind == C_OMP_DIR_DECLARATIVE
30755 365 : || dir->kind == C_OMP_DIR_INFORMATIONAL
30756 356 : || dir->kind == C_OMP_DIR_META))
30757 13 : error_at (dloc, "invalid OpenMP directive name in "
30758 : "%qs clause argument: declarative, "
30759 : "informational, and meta directives "
30760 : "not permitted", p);
30761 : else if (dir == NULL
30762 359 : || dir->id == PRAGMA_OMP_END
30763 356 : || (!dir->second && directive[1])
30764 347 : || (!dir->third && directive[2]))
30765 15 : error_at (dloc, "unknown OpenMP directive name in "
30766 : "%qs clause argument", p);
30767 : else
30768 : {
30769 347 : int id = dir - c_omp_directives;
30770 392 : if (bitmap_bit_p (p[0] == 'a' ? &contains_head
30771 : : &absent_head, id))
30772 18 : error_at (dloc, "%<%s%s%s%s%s%> directive "
30773 : "mentioned in both %<absent%> and "
30774 : "%<contains%> clauses",
30775 : directive[0],
30776 : directive[1] ? " " : "",
30777 : directive[1] ? directive[1] : "",
30778 : directive[2] ? " " : "",
30779 : directive[2] ? directive[2] : "");
30780 383 : else if (!bitmap_set_bit (p[0] == 'a'
30781 : ? &absent_head
30782 : : &contains_head, id))
30783 36 : error_at (dloc, "%<%s%s%s%s%s%> directive "
30784 : "mentioned multiple times in %qs "
30785 : "clauses",
30786 : directive[0],
30787 : directive[1] ? " " : "",
30788 : directive[1] ? directive[1] : "",
30789 : directive[2] ? " " : "",
30790 : directive[2] ? directive[2] : "", p);
30791 : }
30792 844 : for (; i; --i)
30793 469 : c_parser_consume_token (parser);
30794 : }
30795 375 : if (c_parser_next_token_is (parser, CPP_COMMA))
30796 229 : c_parser_consume_token (parser);
30797 : else
30798 : break;
30799 229 : }
30800 : while (1);
30801 146 : parens.skip_until_found_close (parser);
30802 : }
30803 146 : }
30804 10 : else if (startswith (p, "ext_"))
30805 : {
30806 6 : warning_at (cloc, OPT_Wopenmp, "unknown assumption clause %qs", p);
30807 6 : c_parser_consume_token (parser);
30808 6 : if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
30809 : {
30810 3 : matching_parens parens;
30811 3 : parens.consume_open (parser);
30812 3 : c_parser_balanced_token_sequence (parser);
30813 3 : parens.require_close (parser);
30814 : }
30815 : }
30816 : else
30817 : {
30818 4 : c_parser_consume_token (parser);
30819 4 : error_at (cloc, "expected assumption clause");
30820 4 : break;
30821 : }
30822 : }
30823 130 : c_parser_skip_to_pragma_eol (parser);
30824 130 : }
30825 :
30826 : /* OpenMP 5.1
30827 : #pragma omp assume clauses[optseq] new-line */
30828 :
30829 : static void
30830 46 : c_parser_omp_assume (c_parser *parser, bool *if_p)
30831 : {
30832 46 : c_parser_omp_assumption_clauses (parser, true);
30833 46 : add_stmt (c_parser_omp_structured_block (parser, if_p));
30834 46 : }
30835 :
30836 : /* OpenMP 5.1
30837 : #pragma omp assumes clauses[optseq] new-line */
30838 :
30839 : static void
30840 38 : c_parser_omp_assumes (c_parser *parser)
30841 : {
30842 38 : c_parser_consume_pragma (parser);
30843 38 : c_parser_omp_assumption_clauses (parser, false);
30844 38 : }
30845 :
30846 : /* Helper function for c_parser_omp_metadirective. */
30847 :
30848 : static void
30849 58 : analyze_metadirective_body (c_parser *parser,
30850 : vec<c_token> &tokens,
30851 : vec<tree> &labels)
30852 : {
30853 58 : int nesting_depth = 0;
30854 58 : int bracket_depth = 0;
30855 58 : bool ignore_label = false;
30856 :
30857 : /* Read in the body tokens to the tokens for each candidate directive. */
30858 3242 : while (1)
30859 : {
30860 1650 : c_token *token = c_parser_peek_token (parser);
30861 1650 : bool stop = false;
30862 :
30863 1650 : if (c_parser_next_token_is_keyword (parser, RID_CASE))
30864 0 : ignore_label = true;
30865 :
30866 1650 : switch (token->type)
30867 : {
30868 : case CPP_EOF:
30869 : break;
30870 531 : case CPP_NAME:
30871 531 : if (!ignore_label
30872 531 : && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
30873 0 : labels.safe_push (token->value);
30874 531 : goto add;
30875 21 : case CPP_OPEN_BRACE:
30876 21 : ++nesting_depth;
30877 21 : goto add;
30878 21 : case CPP_CLOSE_BRACE:
30879 21 : if (--nesting_depth == 0 && bracket_depth == 0)
30880 21 : stop = true;
30881 21 : goto add;
30882 85 : case CPP_OPEN_PAREN:
30883 85 : ++bracket_depth;
30884 85 : goto add;
30885 85 : case CPP_CLOSE_PAREN:
30886 85 : --bracket_depth;
30887 85 : goto add;
30888 9 : case CPP_COLON:
30889 9 : ignore_label = false;
30890 9 : goto add;
30891 185 : case CPP_SEMICOLON:
30892 185 : if (nesting_depth == 0 && bracket_depth == 0)
30893 50 : stop = true;
30894 185 : goto add;
30895 1650 : default:
30896 1650 : add:
30897 1650 : tokens.safe_push (*token);
30898 1650 : if (token->type == CPP_PRAGMA)
30899 5 : c_parser_consume_pragma (parser);
30900 1645 : else if (token->type == CPP_PRAGMA_EOL)
30901 5 : c_parser_skip_to_pragma_eol (parser);
30902 : else
30903 1640 : c_parser_consume_token (parser);
30904 1650 : if (stop)
30905 : break;
30906 1592 : continue;
30907 : }
30908 58 : break;
30909 1592 : }
30910 58 : }
30911 :
30912 : /* OpenMP 5.0:
30913 :
30914 : # pragma omp metadirective [clause[, clause]]
30915 : */
30916 :
30917 : static void
30918 110 : c_parser_omp_metadirective (c_parser *parser, bool *if_p)
30919 : {
30920 110 : static unsigned int metadirective_region_count = 0;
30921 :
30922 110 : tree ret;
30923 110 : auto_vec<c_token> directive_tokens;
30924 110 : auto_vec<c_token> body_tokens;
30925 110 : auto_vec<tree> body_labels;
30926 110 : auto_vec<const struct c_omp_directive *> directives;
30927 110 : auto_vec<tree> ctxs;
30928 110 : vec<struct omp_variant> candidates;
30929 110 : bool default_seen = false;
30930 110 : int directive_token_idx = 0;
30931 110 : tree standalone_body = NULL_TREE;
30932 110 : location_t pragma_loc = c_parser_peek_token (parser)->location;
30933 110 : bool requires_body = false;
30934 :
30935 110 : ret = make_node (OMP_METADIRECTIVE);
30936 110 : SET_EXPR_LOCATION (ret, pragma_loc);
30937 110 : TREE_TYPE (ret) = void_type_node;
30938 110 : OMP_METADIRECTIVE_VARIANTS (ret) = NULL_TREE;
30939 :
30940 110 : c_parser_consume_pragma (parser);
30941 418 : while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
30942 : {
30943 214 : if (c_parser_next_token_is (parser, CPP_COMMA))
30944 15 : c_parser_consume_token (parser);
30945 214 : if (c_parser_next_token_is_not (parser, CPP_NAME)
30946 278 : && c_parser_next_token_is_not (parser, CPP_KEYWORD))
30947 : {
30948 0 : c_parser_error (parser, "expected %<when%>, "
30949 : "%<otherwise%>, or %<default%> clause");
30950 0 : goto error;
30951 : }
30952 :
30953 214 : location_t match_loc = c_parser_peek_token (parser)->location;
30954 214 : const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
30955 214 : if (strcmp (p, "default") == 0)
30956 : {
30957 64 : gcc_rich_location richloc (pragma_loc);
30958 64 : richloc.add_fixit_replace (match_loc, "otherwise");
30959 64 : warning_at (&richloc, OPT_Wdeprecated_openmp,
30960 : "%<default%> clause on metadirectives deprecated since "
30961 : "OpenMP 5.2, use %<otherwise%>");
30962 64 : }
30963 214 : c_parser_consume_token (parser);
30964 428 : bool default_p
30965 214 : = strcmp (p, "default") == 0 || strcmp (p, "otherwise") == 0;
30966 133 : if (default_p)
30967 : {
30968 81 : if (default_seen)
30969 : {
30970 4 : error_at (match_loc, "too many %<otherwise%> or %<default%> "
30971 : "clauses in %<metadirective%>");
30972 4 : goto error;
30973 : }
30974 : default_seen = true;
30975 : }
30976 133 : else if (default_seen)
30977 : {
30978 2 : error_at (match_loc, "%<otherwise%> or %<default%> clause "
30979 : "must appear last in %<metadirective%>");
30980 2 : goto error;
30981 : }
30982 208 : if (!default_p && strcmp (p, "when") != 0)
30983 : {
30984 2 : error_at (match_loc, "%qs is not valid for %qs",
30985 : p, "metadirective");
30986 2 : goto error;
30987 : }
30988 :
30989 206 : matching_parens parens;
30990 206 : tree ctx = NULL_TREE;
30991 206 : bool skip = false;
30992 :
30993 206 : if (!parens.require_open (parser))
30994 0 : goto error;
30995 :
30996 206 : if (!default_p)
30997 : {
30998 129 : ctx = c_parser_omp_context_selector_specification (parser,
30999 : NULL_TREE);
31000 129 : if (ctx == error_mark_node)
31001 2 : goto error;
31002 127 : ctx = omp_check_context_selector (match_loc, ctx,
31003 : OMP_CTX_METADIRECTIVE);
31004 127 : if (ctx == error_mark_node)
31005 0 : goto error;
31006 :
31007 : /* Remove the selector from further consideration if it can be
31008 : evaluated as a non-match at this point. */
31009 127 : skip = (omp_context_selector_matches (ctx, NULL_TREE, false) == 0);
31010 :
31011 127 : if (c_parser_next_token_is_not (parser, CPP_COLON))
31012 : {
31013 2 : c_parser_require (parser, CPP_COLON, "expected %<:%>");
31014 2 : goto error;
31015 : }
31016 125 : c_parser_consume_token (parser);
31017 : }
31018 :
31019 : /* Read in the directive type and create a dummy pragma token for
31020 : it. */
31021 202 : location_t loc = c_parser_peek_token (parser)->location;
31022 :
31023 202 : const char *directive[3] = {};
31024 202 : int i;
31025 561 : for (i = 0; i < 3; i++)
31026 : {
31027 541 : tree id;
31028 541 : if (c_parser_peek_nth_token (parser, i + 1)->type
31029 : == CPP_CLOSE_PAREN)
31030 : {
31031 118 : if (i == 0)
31032 2 : directive[i++] = "nothing";
31033 : break;
31034 : }
31035 423 : else if (c_parser_peek_nth_token (parser, i + 1)->type
31036 : == CPP_NAME)
31037 282 : id = c_parser_peek_nth_token (parser, i + 1)->value;
31038 141 : else if (c_parser_peek_nth_token (parser, i + 1)->keyword
31039 : != RID_MAX)
31040 : {
31041 77 : enum rid rid
31042 77 : = c_parser_peek_nth_token (parser, i + 1)->keyword;
31043 77 : id = ridpointers[rid];
31044 : }
31045 : else
31046 : break;
31047 :
31048 359 : directive[i] = IDENTIFIER_POINTER (id);
31049 : }
31050 86 : if (i == 0)
31051 : {
31052 0 : error_at (loc, "expected directive name");
31053 0 : goto error;
31054 : }
31055 :
31056 202 : const struct c_omp_directive *omp_directive
31057 202 : = c_omp_categorize_directive (directive[0],
31058 : directive[1],
31059 202 : directive[2]);
31060 :
31061 202 : if (omp_directive == NULL)
31062 : {
31063 4 : for (int j = 0; j < i; j++)
31064 2 : c_parser_consume_token (parser);
31065 2 : c_parser_error (parser, "unknown directive name");
31066 2 : goto error;
31067 : }
31068 : else
31069 : {
31070 200 : int token_count = 0;
31071 200 : if (omp_directive->first) token_count++;
31072 200 : if (omp_directive->second) token_count++;
31073 200 : if (omp_directive->third) token_count++;
31074 400 : for (int j = 0; j < token_count; j++)
31075 200 : c_parser_consume_token (parser);
31076 : }
31077 200 : if (omp_directive->id == PRAGMA_OMP_METADIRECTIVE)
31078 : {
31079 2 : c_parser_error (parser,
31080 : "metadirectives cannot be used as variants of a "
31081 : "%<metadirective%>");
31082 2 : goto error;
31083 : }
31084 198 : if (omp_directive->kind == C_OMP_DIR_DECLARATIVE)
31085 : {
31086 0 : sorry_at (loc, "declarative directive variants of a "
31087 : "%<metadirective%> are not supported");
31088 0 : goto error;
31089 : }
31090 198 : if (omp_directive->kind == C_OMP_DIR_CONSTRUCT)
31091 117 : requires_body = true;
31092 :
31093 198 : if (!skip)
31094 : {
31095 163 : c_token pragma_token;
31096 163 : pragma_token.type = CPP_PRAGMA;
31097 163 : pragma_token.location = loc;
31098 163 : pragma_token.pragma_kind = (enum pragma_kind) omp_directive->id;
31099 :
31100 163 : directives.safe_push (omp_directive);
31101 163 : directive_tokens.safe_push (pragma_token);
31102 163 : ctxs.safe_push (ctx);
31103 : }
31104 :
31105 : /* Read in tokens for the directive clauses. */
31106 198 : int nesting_depth = 0;
31107 1484 : while (1)
31108 : {
31109 841 : c_token *token = c_parser_peek_token (parser);
31110 841 : switch (token->type)
31111 : {
31112 : case CPP_EOF:
31113 : case CPP_PRAGMA_EOL:
31114 : break;
31115 117 : case CPP_OPEN_PAREN:
31116 117 : ++nesting_depth;
31117 117 : goto add;
31118 313 : case CPP_CLOSE_PAREN:
31119 313 : if (nesting_depth-- == 0)
31120 : {
31121 196 : c_parser_consume_token (parser);
31122 196 : break;
31123 : }
31124 117 : goto add;
31125 643 : default:
31126 643 : add:
31127 643 : if (!skip)
31128 550 : directive_tokens.safe_push (*token);
31129 643 : c_parser_consume_token (parser);
31130 643 : continue;
31131 : }
31132 198 : break;
31133 643 : }
31134 :
31135 198 : if (!skip)
31136 : {
31137 163 : c_token eol_token;
31138 163 : memset (&eol_token, 0, sizeof (eol_token));
31139 163 : eol_token.type = CPP_PRAGMA_EOL;
31140 163 : directive_tokens.safe_push (eol_token);
31141 : }
31142 : }
31143 94 : c_parser_skip_to_pragma_eol (parser);
31144 :
31145 : /* If only one selector matches and it evaluates to 'omp nothing', no need to
31146 : proceed. */
31147 94 : if (ctxs.length () == 1)
31148 : {
31149 37 : tree ctx = ctxs[0];
31150 37 : if (ctx == NULL_TREE
31151 37 : || (omp_context_selector_matches (ctx, NULL_TREE, false) == 1
31152 13 : && directive_tokens[0].pragma_kind == PRAGMA_OMP_NOTHING))
31153 : return;
31154 : }
31155 :
31156 72 : if (!default_seen)
31157 : {
31158 : /* Add a default clause that evaluates to 'omp nothing'. */
31159 27 : const struct c_omp_directive *omp_directive
31160 27 : = c_omp_categorize_directive ("nothing", NULL, NULL);
31161 :
31162 27 : c_token pragma_token;
31163 27 : pragma_token.type = CPP_PRAGMA;
31164 27 : pragma_token.location = UNKNOWN_LOCATION;
31165 27 : pragma_token.pragma_kind = PRAGMA_OMP_NOTHING;
31166 :
31167 27 : directives.safe_push (omp_directive);
31168 27 : directive_tokens.safe_push (pragma_token);
31169 27 : ctxs.safe_push (NULL_TREE);
31170 :
31171 27 : c_token eol_token;
31172 27 : memset (&eol_token, 0, sizeof (eol_token));
31173 27 : eol_token.type = CPP_PRAGMA_EOL;
31174 27 : directive_tokens.safe_push (eol_token);
31175 : }
31176 :
31177 72 : if (requires_body)
31178 58 : analyze_metadirective_body (parser, body_tokens, body_labels);
31179 :
31180 : /* Process each candidate directive. */
31181 72 : unsigned i;
31182 72 : tree ctx;
31183 :
31184 234 : FOR_EACH_VEC_ELT (ctxs, i, ctx)
31185 : {
31186 162 : auto_vec<c_token> tokens;
31187 :
31188 : /* Add the directive tokens. */
31189 842 : do
31190 842 : tokens.safe_push (directive_tokens [directive_token_idx++]);
31191 842 : while (tokens.last ().type != CPP_PRAGMA_EOL);
31192 :
31193 : /* Add the body tokens. */
31194 162 : gcc_assert (requires_body || body_tokens.is_empty ());
31195 3670 : for (unsigned j = 0; j < body_tokens.length (); j++)
31196 3508 : tokens.safe_push (body_tokens[j]);
31197 :
31198 : /* Make sure nothing tries to read past the end of the tokens. */
31199 162 : c_token eof_token;
31200 162 : memset (&eof_token, 0, sizeof (eof_token));
31201 162 : eof_token.type = CPP_EOF;
31202 162 : tokens.safe_push (eof_token);
31203 162 : tokens.safe_push (eof_token);
31204 :
31205 162 : unsigned int old_tokens_avail = parser->tokens_avail;
31206 162 : c_token *old_tokens = parser->tokens;
31207 162 : struct omp_attribute_pragma_state *old_in_omp_attribute_pragma
31208 : = parser->in_omp_attribute_pragma;
31209 162 : struct omp_metadirective_parse_data *old_state
31210 : = parser->omp_metadirective_state;
31211 :
31212 162 : struct omp_metadirective_parse_data new_state;
31213 162 : new_state.body_labels = &body_labels;
31214 162 : new_state.region_num = ++metadirective_region_count;
31215 :
31216 162 : parser->tokens = tokens.address ();
31217 162 : parser->tokens_avail = tokens.length ();
31218 162 : parser->in_omp_attribute_pragma = NULL;
31219 162 : parser->omp_metadirective_state = &new_state;
31220 :
31221 162 : int prev_errorcount = errorcount;
31222 162 : tree directive = c_begin_compound_stmt (true);
31223 :
31224 162 : c_parser_pragma (parser, pragma_compound, if_p, NULL_TREE);
31225 162 : directive = c_end_compound_stmt (pragma_loc, directive, true);
31226 162 : bool standalone_p
31227 162 : = directives[i]->kind == C_OMP_DIR_STANDALONE
31228 162 : || directives[i]->kind == C_OMP_DIR_UTILITY;
31229 89 : if (standalone_p && requires_body)
31230 : {
31231 : /* Parsing standalone directives will not consume the body
31232 : tokens, so do that here. */
31233 53 : if (standalone_body == NULL_TREE)
31234 : {
31235 51 : standalone_body = push_stmt_list ();
31236 51 : c_parser_statement (parser, if_p); // TODO skip this
31237 51 : standalone_body = pop_stmt_list (standalone_body);
31238 : }
31239 : else
31240 2 : c_parser_skip_to_end_of_block_or_statement (parser, true);
31241 : }
31242 :
31243 162 : tree body = standalone_p ? standalone_body : NULL_TREE;
31244 162 : tree variant = make_omp_metadirective_variant (ctx, directive, body);
31245 324 : OMP_METADIRECTIVE_VARIANTS (ret)
31246 162 : = chainon (OMP_METADIRECTIVE_VARIANTS (ret), variant);
31247 :
31248 : /* Check that all valid tokens have been consumed if no parse errors
31249 : encountered. */
31250 162 : if (errorcount == prev_errorcount)
31251 : {
31252 160 : gcc_assert (parser->tokens_avail == 2);
31253 160 : gcc_assert (c_parser_next_token_is (parser, CPP_EOF));
31254 160 : gcc_assert (c_parser_peek_2nd_token (parser)->type == CPP_EOF);
31255 : }
31256 :
31257 162 : parser->tokens = old_tokens;
31258 162 : parser->tokens_avail = old_tokens_avail;
31259 162 : parser->in_omp_attribute_pragma = old_in_omp_attribute_pragma;
31260 162 : parser->omp_metadirective_state = old_state;
31261 162 : }
31262 :
31263 : /* Try to resolve the metadirective early. */
31264 72 : candidates = omp_early_resolve_metadirective (ret);
31265 72 : if (!candidates.is_empty ())
31266 48 : ret = c_omp_expand_variant_construct (candidates);
31267 :
31268 72 : add_stmt (ret);
31269 72 : return;
31270 :
31271 16 : error:
31272 : /* Skip the metadirective pragma. Do not skip the metadirective body. */
31273 16 : if (parser->in_pragma)
31274 16 : c_parser_skip_to_pragma_eol (parser, false);
31275 110 : }
31276 :
31277 : /* Main entry point to parsing most OpenMP pragmas. */
31278 :
31279 : static void
31280 17481 : c_parser_omp_construct (c_parser *parser, bool *if_p)
31281 : {
31282 17481 : enum pragma_kind p_kind;
31283 17481 : location_t loc;
31284 17481 : tree stmt;
31285 17481 : char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
31286 17481 : omp_clause_mask mask (0);
31287 :
31288 17481 : loc = c_parser_peek_token (parser)->location;
31289 17481 : p_kind = c_parser_peek_token (parser)->pragma_kind;
31290 17481 : c_parser_consume_pragma (parser);
31291 :
31292 17481 : switch (p_kind)
31293 : {
31294 309 : case PRAGMA_OACC_ATOMIC:
31295 309 : c_parser_omp_atomic (loc, parser, true);
31296 2131 : return;
31297 137 : case PRAGMA_OACC_CACHE:
31298 137 : strcpy (p_name, "#pragma acc");
31299 137 : stmt = c_parser_oacc_cache (loc, parser);
31300 137 : break;
31301 497 : case PRAGMA_OACC_DATA:
31302 497 : stmt = c_parser_oacc_data (loc, parser, if_p);
31303 497 : break;
31304 23 : case PRAGMA_OACC_HOST_DATA:
31305 23 : stmt = c_parser_oacc_host_data (loc, parser, if_p);
31306 23 : break;
31307 2154 : case PRAGMA_OACC_KERNELS:
31308 2154 : case PRAGMA_OACC_PARALLEL:
31309 2154 : case PRAGMA_OACC_SERIAL:
31310 2154 : strcpy (p_name, "#pragma acc");
31311 2154 : stmt = c_parser_oacc_compute (loc, parser, p_kind, p_name, if_p);
31312 2154 : break;
31313 1771 : case PRAGMA_OACC_LOOP:
31314 1771 : strcpy (p_name, "#pragma acc");
31315 1771 : stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p);
31316 1771 : break;
31317 86 : case PRAGMA_OACC_WAIT:
31318 86 : strcpy (p_name, "#pragma wait");
31319 86 : stmt = c_parser_oacc_wait (loc, parser, p_name);
31320 86 : break;
31321 1467 : case PRAGMA_OMP_ATOMIC:
31322 1467 : c_parser_omp_atomic (loc, parser, false);
31323 1467 : return;
31324 144 : case PRAGMA_OMP_CRITICAL:
31325 144 : stmt = c_parser_omp_critical (loc, parser, if_p);
31326 144 : break;
31327 1322 : case PRAGMA_OMP_DISTRIBUTE:
31328 1322 : strcpy (p_name, "#pragma omp");
31329 1322 : stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p);
31330 1322 : break;
31331 1834 : case PRAGMA_OMP_FOR:
31332 1834 : strcpy (p_name, "#pragma omp");
31333 1834 : stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p);
31334 1834 : break;
31335 158 : case PRAGMA_OMP_LOOP:
31336 158 : strcpy (p_name, "#pragma omp");
31337 158 : stmt = c_parser_omp_loop (loc, parser, p_name, mask, NULL, if_p);
31338 158 : break;
31339 74 : case PRAGMA_OMP_MASKED:
31340 74 : strcpy (p_name, "#pragma omp");
31341 74 : stmt = c_parser_omp_masked (loc, parser, p_name, mask, NULL, if_p);
31342 74 : break;
31343 137 : case PRAGMA_OMP_MASTER:
31344 137 : strcpy (p_name, "#pragma omp");
31345 137 : stmt = c_parser_omp_master (loc, parser, p_name, mask, NULL, if_p,
31346 : UNKNOWN_LOCATION);
31347 137 : break;
31348 2533 : case PRAGMA_OMP_PARALLEL:
31349 2533 : strcpy (p_name, "#pragma omp");
31350 2533 : stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p);
31351 2533 : break;
31352 68 : case PRAGMA_OMP_SCOPE:
31353 68 : stmt = c_parser_omp_scope (loc, parser, if_p);
31354 68 : break;
31355 108 : case PRAGMA_OMP_SECTIONS:
31356 108 : strcpy (p_name, "#pragma omp");
31357 108 : stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
31358 108 : break;
31359 765 : case PRAGMA_OMP_SIMD:
31360 765 : strcpy (p_name, "#pragma omp");
31361 765 : stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p);
31362 765 : break;
31363 230 : case PRAGMA_OMP_SINGLE:
31364 230 : stmt = c_parser_omp_single (loc, parser, if_p);
31365 230 : break;
31366 917 : case PRAGMA_OMP_TASK:
31367 917 : stmt = c_parser_omp_task (loc, parser, if_p);
31368 917 : break;
31369 138 : case PRAGMA_OMP_TASKGROUP:
31370 138 : stmt = c_parser_omp_taskgroup (loc, parser, if_p);
31371 138 : break;
31372 256 : case PRAGMA_OMP_TASKLOOP:
31373 256 : strcpy (p_name, "#pragma omp");
31374 256 : stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p);
31375 256 : break;
31376 1937 : case PRAGMA_OMP_TEAMS:
31377 1937 : strcpy (p_name, "#pragma omp");
31378 1937 : stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p);
31379 1937 : break;
31380 46 : case PRAGMA_OMP_ASSUME:
31381 46 : c_parser_omp_assume (parser, if_p);
31382 46 : return;
31383 110 : case PRAGMA_OMP_TILE:
31384 110 : stmt = c_parser_omp_tile (loc, parser, if_p);
31385 110 : break;
31386 105 : case PRAGMA_OMP_UNROLL:
31387 105 : stmt = c_parser_omp_unroll (loc, parser, if_p);
31388 105 : break;
31389 155 : case PRAGMA_OMP_DISPATCH:
31390 155 : stmt = c_parser_omp_dispatch (loc, parser);
31391 155 : break;
31392 0 : default:
31393 0 : gcc_unreachable ();
31394 : }
31395 :
31396 15659 : if (stmt && stmt != error_mark_node)
31397 15350 : gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
31398 : }
31399 :
31400 : /* OpenMP 6.0:
31401 : # pragma omp groupprivate (variable-list) [device_type(...)] */
31402 :
31403 : #define OMP_GROUPPRIVATE_CLAUSE_MASK \
31404 : ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE) )
31405 :
31406 : static void
31407 9 : c_parser_omp_groupprivate (c_parser *parser)
31408 : {
31409 9 : location_t loc = c_parser_peek_token (parser)->location;
31410 9 : c_parser_consume_pragma (parser);
31411 9 : tree vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
31412 9 : tree clauses = c_parser_omp_all_clauses (parser, OMP_GROUPPRIVATE_CLAUSE_MASK,
31413 : "#pragma omp groupprivate");
31414 : /* TODO: Implies 'declare target local' with specified device_type, check for
31415 : conflicts. Check for other restrictions. */
31416 9 : (void) vars;
31417 9 : (void) clauses;
31418 9 : sorry_at (loc, "%<omp groupprivate%>");
31419 9 : }
31420 :
31421 : /* OpenMP 2.5:
31422 : # pragma omp threadprivate (variable-list) */
31423 :
31424 : static void
31425 79 : c_parser_omp_threadprivate (c_parser *parser)
31426 : {
31427 79 : tree vars, t;
31428 79 : location_t loc;
31429 :
31430 79 : c_parser_consume_pragma (parser);
31431 79 : vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
31432 :
31433 : /* Mark every variable in VARS to be assigned thread local storage. */
31434 248 : for (t = vars; t; t = TREE_CHAIN (t))
31435 : {
31436 90 : tree v = TREE_PURPOSE (t);
31437 90 : loc = EXPR_LOCATION (TREE_VALUE (t));
31438 :
31439 : /* If V had already been marked threadprivate, it doesn't matter
31440 : whether it had been used prior to this point. */
31441 90 : if (!VAR_P (v))
31442 1 : error_at (loc, "%qD is not a variable", v);
31443 89 : else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
31444 2 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
31445 87 : else if (! is_global_var (v))
31446 2 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
31447 85 : else if (TREE_TYPE (v) == error_mark_node)
31448 : ;
31449 84 : else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
31450 1 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
31451 : else
31452 : {
31453 83 : if (! DECL_THREAD_LOCAL_P (v))
31454 : {
31455 83 : set_decl_tls_model (v, decl_default_tls_model (v));
31456 : /* If rtl has been already set for this var, call
31457 : make_decl_rtl once again, so that encode_section_info
31458 : has a chance to look at the new decl flags. */
31459 83 : if (DECL_RTL_SET_P (v))
31460 0 : make_decl_rtl (v);
31461 : }
31462 83 : C_DECL_THREADPRIVATE_P (v) = 1;
31463 : }
31464 : }
31465 :
31466 79 : c_parser_skip_to_pragma_eol (parser);
31467 79 : }
31468 :
31469 : /* Parse a transaction attribute (GCC Extension).
31470 :
31471 : transaction-attribute:
31472 : gnu-attributes
31473 : attribute-specifier
31474 : */
31475 :
31476 : static tree
31477 139 : c_parser_transaction_attributes (c_parser *parser)
31478 : {
31479 139 : if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
31480 0 : return c_parser_gnu_attributes (parser);
31481 :
31482 139 : if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
31483 : return NULL_TREE;
31484 20 : return c_parser_std_attribute_specifier (parser, true);
31485 : }
31486 :
31487 : /* Parse a __transaction_atomic or __transaction_relaxed statement
31488 : (GCC Extension).
31489 :
31490 : transaction-statement:
31491 : __transaction_atomic transaction-attribute[opt] compound-statement
31492 : __transaction_relaxed compound-statement
31493 :
31494 : Note that the only valid attribute is: "outer".
31495 : */
31496 :
31497 : static tree
31498 137 : c_parser_transaction (c_parser *parser, enum rid keyword)
31499 : {
31500 137 : unsigned int old_in = parser->in_transaction;
31501 137 : unsigned int this_in = 1, new_in;
31502 137 : location_t loc = c_parser_peek_token (parser)->location;
31503 137 : tree stmt, attrs;
31504 :
31505 274 : gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
31506 : || keyword == RID_TRANSACTION_RELAXED)
31507 : && c_parser_next_token_is_keyword (parser, keyword));
31508 137 : c_parser_consume_token (parser);
31509 :
31510 137 : if (keyword == RID_TRANSACTION_RELAXED)
31511 : this_in |= TM_STMT_ATTR_RELAXED;
31512 : else
31513 : {
31514 106 : attrs = c_parser_transaction_attributes (parser);
31515 106 : if (attrs)
31516 14 : this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
31517 : }
31518 :
31519 : /* Keep track if we're in the lexical scope of an outer transaction. */
31520 137 : new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
31521 :
31522 137 : parser->in_transaction = new_in;
31523 137 : stmt = c_parser_compound_statement (parser);
31524 137 : parser->in_transaction = old_in;
31525 :
31526 137 : if (flag_tm)
31527 135 : stmt = c_finish_transaction (loc, stmt, this_in);
31528 : else
31529 2 : error_at (loc,
31530 : keyword == RID_TRANSACTION_ATOMIC
31531 : ? G_("%<__transaction_atomic%> without transactional memory "
31532 : "support enabled")
31533 : : G_("%<__transaction_relaxed%> without transactional memory "
31534 : "support enabled"));
31535 :
31536 137 : return stmt;
31537 : }
31538 :
31539 : /* Parse a __transaction_atomic or __transaction_relaxed expression
31540 : (GCC Extension).
31541 :
31542 : transaction-expression:
31543 : __transaction_atomic ( expression )
31544 : __transaction_relaxed ( expression )
31545 : */
31546 :
31547 : static struct c_expr
31548 7 : c_parser_transaction_expression (c_parser *parser, enum rid keyword)
31549 : {
31550 7 : struct c_expr ret;
31551 7 : unsigned int old_in = parser->in_transaction;
31552 7 : unsigned int this_in = 1;
31553 7 : location_t loc = c_parser_peek_token (parser)->location;
31554 7 : tree attrs;
31555 :
31556 14 : gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
31557 : || keyword == RID_TRANSACTION_RELAXED)
31558 : && c_parser_next_token_is_keyword (parser, keyword));
31559 7 : c_parser_consume_token (parser);
31560 :
31561 7 : if (keyword == RID_TRANSACTION_RELAXED)
31562 : this_in |= TM_STMT_ATTR_RELAXED;
31563 : else
31564 : {
31565 5 : attrs = c_parser_transaction_attributes (parser);
31566 5 : if (attrs)
31567 0 : this_in |= parse_tm_stmt_attr (attrs, 0);
31568 : }
31569 :
31570 7 : parser->in_transaction = this_in;
31571 7 : matching_parens parens;
31572 7 : if (parens.require_open (parser))
31573 : {
31574 7 : tree expr = c_parser_expression (parser).value;
31575 7 : ret.original_type = TREE_TYPE (expr);
31576 7 : ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
31577 7 : if (this_in & TM_STMT_ATTR_RELAXED)
31578 2 : TRANSACTION_EXPR_RELAXED (ret.value) = 1;
31579 7 : SET_EXPR_LOCATION (ret.value, loc);
31580 7 : ret.original_code = TRANSACTION_EXPR;
31581 7 : ret.m_decimal = 0;
31582 7 : if (!parens.require_close (parser))
31583 : {
31584 0 : c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
31585 0 : goto error;
31586 : }
31587 : }
31588 : else
31589 : {
31590 0 : error:
31591 0 : ret.set_error ();
31592 0 : ret.original_code = ERROR_MARK;
31593 0 : ret.original_type = NULL;
31594 : }
31595 7 : parser->in_transaction = old_in;
31596 :
31597 7 : if (!flag_tm)
31598 6 : error_at (loc,
31599 : keyword == RID_TRANSACTION_ATOMIC
31600 : ? G_("%<__transaction_atomic%> without transactional memory "
31601 : "support enabled")
31602 : : G_("%<__transaction_relaxed%> without transactional memory "
31603 : "support enabled"));
31604 :
31605 7 : set_c_expr_source_range (&ret, loc, loc);
31606 :
31607 7 : return ret;
31608 : }
31609 :
31610 : /* Parse a __transaction_cancel statement (GCC Extension).
31611 :
31612 : transaction-cancel-statement:
31613 : __transaction_cancel transaction-attribute[opt] ;
31614 :
31615 : Note that the only valid attribute is "outer".
31616 : */
31617 :
31618 : static tree
31619 28 : c_parser_transaction_cancel (c_parser *parser)
31620 : {
31621 28 : location_t loc = c_parser_peek_token (parser)->location;
31622 28 : tree attrs;
31623 28 : bool is_outer = false;
31624 :
31625 28 : gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
31626 28 : c_parser_consume_token (parser);
31627 :
31628 28 : attrs = c_parser_transaction_attributes (parser);
31629 28 : if (attrs)
31630 5 : is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
31631 :
31632 28 : if (!flag_tm)
31633 : {
31634 2 : error_at (loc, "%<__transaction_cancel%> without "
31635 : "transactional memory support enabled");
31636 2 : goto ret_error;
31637 : }
31638 26 : else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
31639 : {
31640 0 : error_at (loc, "%<__transaction_cancel%> within a "
31641 : "%<__transaction_relaxed%>");
31642 0 : goto ret_error;
31643 : }
31644 26 : else if (is_outer)
31645 : {
31646 5 : if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
31647 5 : && !is_tm_may_cancel_outer (current_function_decl))
31648 : {
31649 0 : error_at (loc, "outer %<__transaction_cancel%> not "
31650 : "within outer %<__transaction_atomic%> or "
31651 : "a %<transaction_may_cancel_outer%> function");
31652 0 : goto ret_error;
31653 : }
31654 : }
31655 21 : else if (parser->in_transaction == 0)
31656 : {
31657 0 : error_at (loc, "%<__transaction_cancel%> not within "
31658 : "%<__transaction_atomic%>");
31659 0 : goto ret_error;
31660 : }
31661 :
31662 26 : return add_stmt (build_tm_abort_call (loc, is_outer));
31663 :
31664 2 : ret_error:
31665 2 : return build1 (NOP_EXPR, void_type_node, error_mark_node);
31666 : }
31667 :
31668 : /* Parse a single source file. */
31669 :
31670 : void
31671 108621 : c_parse_file (void)
31672 : {
31673 : /* Use local storage to begin. If the first token is a pragma, parse it.
31674 : If it is #pragma GCC pch_preprocess, then this will load a PCH file
31675 : which will cause garbage collection. */
31676 108621 : c_parser tparser;
31677 :
31678 108621 : memset (&tparser, 0, sizeof tparser);
31679 108621 : tparser.translate_strings_p = true;
31680 108621 : tparser.tokens = &tparser.tokens_buf[0];
31681 108621 : the_parser = &tparser;
31682 :
31683 108621 : if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
31684 12 : c_parser_pragma_pch_preprocess (&tparser);
31685 : else
31686 108544 : c_common_no_more_pch ();
31687 :
31688 108556 : the_parser = ggc_alloc<c_parser> ();
31689 108556 : *the_parser = tparser;
31690 108556 : if (tparser.tokens == &tparser.tokens_buf[0])
31691 108556 : the_parser->tokens = &the_parser->tokens_buf[0];
31692 :
31693 : /* Initialize EH, if we've been told to do so. */
31694 108556 : if (flag_exceptions)
31695 525 : using_eh_for_cleanups ();
31696 :
31697 108556 : c_parser_translation_unit (the_parser);
31698 108466 : the_parser = NULL;
31699 108466 : }
31700 :
31701 : void
31702 5823 : c_init_preprocess (void)
31703 : {
31704 : /* Create a parser for use by pragma_lex during preprocessing. */
31705 5823 : the_parser = ggc_alloc<c_parser> ();
31706 5823 : memset (the_parser, 0, sizeof (c_parser));
31707 5823 : the_parser->tokens = &the_parser->tokens_buf[0];
31708 5823 : }
31709 :
31710 : /* Parse the body of a function declaration marked with "__RTL".
31711 :
31712 : The RTL parser works on the level of characters read from a
31713 : FILE *, whereas c_parser works at the level of tokens.
31714 : Square this circle by consuming all of the tokens up to and
31715 : including the closing brace, recording the start/end of the RTL
31716 : fragment, and reopening the file and re-reading the relevant
31717 : lines within the RTL parser.
31718 :
31719 : This requires the opening and closing braces of the C function
31720 : to be on separate lines from the RTL they wrap.
31721 :
31722 : Take ownership of START_WITH_PASS, if non-NULL. */
31723 :
31724 : location_t
31725 25 : c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass)
31726 : {
31727 25 : if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
31728 : {
31729 0 : free (start_with_pass);
31730 0 : return c_parser_peek_token (parser)->location;
31731 : }
31732 :
31733 25 : location_t start_loc = c_parser_peek_token (parser)->location;
31734 :
31735 : /* Consume all tokens, up to the closing brace, handling
31736 : matching pairs of braces in the rtl dump. */
31737 25 : int num_open_braces = 1;
31738 25241 : while (1)
31739 : {
31740 12633 : switch (c_parser_peek_token (parser)->type)
31741 : {
31742 1 : case CPP_OPEN_BRACE:
31743 1 : num_open_braces++;
31744 1 : break;
31745 25 : case CPP_CLOSE_BRACE:
31746 25 : if (--num_open_braces == 0)
31747 24 : goto found_closing_brace;
31748 : break;
31749 1 : case CPP_EOF:
31750 1 : error_at (start_loc, "no closing brace");
31751 1 : free (start_with_pass);
31752 1 : return c_parser_peek_token (parser)->location;
31753 : default:
31754 : break;
31755 : }
31756 12608 : c_parser_consume_token (parser);
31757 : }
31758 :
31759 24 : found_closing_brace:
31760 : /* At the closing brace; record its location. */
31761 24 : location_t end_loc = c_parser_peek_token (parser)->location;
31762 :
31763 : /* Consume the closing brace. */
31764 24 : c_parser_consume_token (parser);
31765 :
31766 : /* Invoke the RTL parser. */
31767 24 : if (!read_rtl_function_body_from_file_range (start_loc, end_loc))
31768 : {
31769 0 : free (start_with_pass);
31770 0 : return end_loc;
31771 : }
31772 :
31773 : /* Run the backend on the cfun created above, transferring ownership of
31774 : START_WITH_PASS. */
31775 23 : run_rtl_passes (start_with_pass);
31776 23 : return end_loc;
31777 : }
31778 :
31779 : #include "gt-c-c-parser.h"
|