]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/c/c-parser.c
89498254b7858725c001137aa7c25dd38a62499c
[thirdparty/gcc.git] / gcc / c / c-parser.c
1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
3
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 /* TODO:
24
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
27 of syntax accepted.
28
29 Add testcases covering every input symbol in every state in old and
30 new parsers.
31
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
34
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
37
38 #include "config.h"
39 #include "system.h"
40 #include "coretypes.h"
41 #include "target.h"
42 #include "function.h"
43 #include "c-tree.h"
44 #include "timevar.h"
45 #include "stringpool.h"
46 #include "cgraph.h"
47 #include "attribs.h"
48 #include "stor-layout.h"
49 #include "varasm.h"
50 #include "trans-mem.h"
51 #include "c-family/c-pragma.h"
52 #include "c-lang.h"
53 #include "c-family/c-objc.h"
54 #include "plugin.h"
55 #include "omp-low.h"
56 #include "builtins.h"
57 #include "gomp-constants.h"
58 #include "c-family/c-indentation.h"
59 #include "gimple-expr.h"
60 #include "context.h"
61
62 \f
63 /* Initialization routine for this file. */
64
65 void
66 c_parse_init (void)
67 {
68 /* The only initialization required is of the reserved word
69 identifiers. */
70 unsigned int i;
71 tree id;
72 int mask = 0;
73
74 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
75 the c_token structure. */
76 gcc_assert (RID_MAX <= 255);
77
78 mask |= D_CXXONLY;
79 if (!flag_isoc99)
80 mask |= D_C99;
81 if (flag_no_asm)
82 {
83 mask |= D_ASM | D_EXT;
84 if (!flag_isoc99)
85 mask |= D_EXT89;
86 }
87 if (!c_dialect_objc ())
88 mask |= D_OBJC | D_CXX_OBJC;
89
90 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
91 for (i = 0; i < num_c_common_reswords; i++)
92 {
93 /* If a keyword is disabled, do not enter it into the table
94 and so create a canonical spelling that isn't a keyword. */
95 if (c_common_reswords[i].disable & mask)
96 {
97 if (warn_cxx_compat
98 && (c_common_reswords[i].disable & D_CXXWARN))
99 {
100 id = get_identifier (c_common_reswords[i].word);
101 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
102 C_IS_RESERVED_WORD (id) = 1;
103 }
104 continue;
105 }
106
107 id = get_identifier (c_common_reswords[i].word);
108 C_SET_RID_CODE (id, c_common_reswords[i].rid);
109 C_IS_RESERVED_WORD (id) = 1;
110 ridpointers [(int) c_common_reswords[i].rid] = id;
111 }
112
113 for (i = 0; i < NUM_INT_N_ENTS; i++)
114 {
115 /* We always create the symbols but they aren't always supported. */
116 char name[50];
117 sprintf (name, "__int%d", int_n_data[i].bitsize);
118 id = get_identifier (name);
119 C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
120 C_IS_RESERVED_WORD (id) = 1;
121 }
122 }
123 \f
124 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
125 and the C parser. Unlike the C++ lexer, the parser structure
126 stores the lexer information instead of using a separate structure.
127 Identifiers are separated into ordinary identifiers, type names,
128 keywords and some other Objective-C types of identifiers, and some
129 look-ahead is maintained.
130
131 ??? It might be a good idea to lex the whole file up front (as for
132 C++). It would then be possible to share more of the C and C++
133 lexer code, if desired. */
134
135 /* More information about the type of a CPP_NAME token. */
136 enum c_id_kind {
137 /* An ordinary identifier. */
138 C_ID_ID,
139 /* An identifier declared as a typedef name. */
140 C_ID_TYPENAME,
141 /* An identifier declared as an Objective-C class name. */
142 C_ID_CLASSNAME,
143 /* An address space identifier. */
144 C_ID_ADDRSPACE,
145 /* Not an identifier. */
146 C_ID_NONE
147 };
148
149 /* A single C token after string literal concatenation and conversion
150 of preprocessing tokens to tokens. */
151 struct GTY (()) c_token {
152 /* The kind of token. */
153 ENUM_BITFIELD (cpp_ttype) type : 8;
154 /* If this token is a CPP_NAME, this value indicates whether also
155 declared as some kind of type. Otherwise, it is C_ID_NONE. */
156 ENUM_BITFIELD (c_id_kind) id_kind : 8;
157 /* If this token is a keyword, this value indicates which keyword.
158 Otherwise, this value is RID_MAX. */
159 ENUM_BITFIELD (rid) keyword : 8;
160 /* If this token is a CPP_PRAGMA, this indicates the pragma that
161 was seen. Otherwise it is PRAGMA_NONE. */
162 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
163 /* The location at which this token was found. */
164 location_t location;
165 /* The value associated with this token, if any. */
166 tree value;
167 };
168
169 /* A parser structure recording information about the state and
170 context of parsing. Includes lexer information with up to two
171 tokens of look-ahead; more are not needed for C. */
172 struct GTY(()) c_parser {
173 /* The look-ahead tokens. */
174 c_token * GTY((skip)) tokens;
175 /* Buffer for look-ahead tokens. */
176 c_token tokens_buf[2];
177 /* How many look-ahead tokens are available (0, 1 or 2, or
178 more if parsing from pre-lexed tokens). */
179 unsigned int tokens_avail;
180 /* True if a syntax error is being recovered from; false otherwise.
181 c_parser_error sets this flag. It should clear this flag when
182 enough tokens have been consumed to recover from the error. */
183 BOOL_BITFIELD error : 1;
184 /* True if we're processing a pragma, and shouldn't automatically
185 consume CPP_PRAGMA_EOL. */
186 BOOL_BITFIELD in_pragma : 1;
187 /* True if we're parsing the outermost block of an if statement. */
188 BOOL_BITFIELD in_if_block : 1;
189 /* True if we want to lex an untranslated string. */
190 BOOL_BITFIELD lex_untranslated_string : 1;
191
192 /* Objective-C specific parser/lexer information. */
193
194 /* True if we are in a context where the Objective-C "PQ" keywords
195 are considered keywords. */
196 BOOL_BITFIELD objc_pq_context : 1;
197 /* True if we are parsing a (potential) Objective-C foreach
198 statement. This is set to true after we parsed 'for (' and while
199 we wait for 'in' or ';' to decide if it's a standard C for loop or an
200 Objective-C foreach loop. */
201 BOOL_BITFIELD objc_could_be_foreach_context : 1;
202 /* The following flag is needed to contextualize Objective-C lexical
203 analysis. In some cases (e.g., 'int NSObject;'), it is
204 undesirable to bind an identifier to an Objective-C class, even
205 if a class with that name exists. */
206 BOOL_BITFIELD objc_need_raw_identifier : 1;
207 /* Nonzero if we're processing a __transaction statement. The value
208 is 1 | TM_STMT_ATTR_*. */
209 unsigned int in_transaction : 4;
210 /* True if we are in a context where the Objective-C "Property attribute"
211 keywords are valid. */
212 BOOL_BITFIELD objc_property_attr_context : 1;
213
214 /* Cilk Plus specific parser/lexer information. */
215
216 /* Buffer to hold all the tokens from parsing the vector attribute for the
217 SIMD-enabled functions (formerly known as elemental functions). */
218 vec <c_token, va_gc> *cilk_simd_fn_tokens;
219 };
220
221
222 /* The actual parser and external interface. ??? Does this need to be
223 garbage-collected? */
224
225 static GTY (()) c_parser *the_parser;
226
227 /* Read in and lex a single token, storing it in *TOKEN. */
228
229 static void
230 c_lex_one_token (c_parser *parser, c_token *token)
231 {
232 timevar_push (TV_LEX);
233
234 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
235 (parser->lex_untranslated_string
236 ? C_LEX_STRING_NO_TRANSLATE : 0));
237 token->id_kind = C_ID_NONE;
238 token->keyword = RID_MAX;
239 token->pragma_kind = PRAGMA_NONE;
240
241 switch (token->type)
242 {
243 case CPP_NAME:
244 {
245 tree decl;
246
247 bool objc_force_identifier = parser->objc_need_raw_identifier;
248 if (c_dialect_objc ())
249 parser->objc_need_raw_identifier = false;
250
251 if (C_IS_RESERVED_WORD (token->value))
252 {
253 enum rid rid_code = C_RID_CODE (token->value);
254
255 if (rid_code == RID_CXX_COMPAT_WARN)
256 {
257 warning_at (token->location,
258 OPT_Wc___compat,
259 "identifier %qE conflicts with C++ keyword",
260 token->value);
261 }
262 else if (rid_code >= RID_FIRST_ADDR_SPACE
263 && rid_code <= RID_LAST_ADDR_SPACE)
264 {
265 token->id_kind = C_ID_ADDRSPACE;
266 token->keyword = rid_code;
267 break;
268 }
269 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
270 {
271 /* We found an Objective-C "pq" keyword (in, out,
272 inout, bycopy, byref, oneway). They need special
273 care because the interpretation depends on the
274 context. */
275 if (parser->objc_pq_context)
276 {
277 token->type = CPP_KEYWORD;
278 token->keyword = rid_code;
279 break;
280 }
281 else if (parser->objc_could_be_foreach_context
282 && rid_code == RID_IN)
283 {
284 /* We are in Objective-C, inside a (potential)
285 foreach context (which means after having
286 parsed 'for (', but before having parsed ';'),
287 and we found 'in'. We consider it the keyword
288 which terminates the declaration at the
289 beginning of a foreach-statement. Note that
290 this means you can't use 'in' for anything else
291 in that context; in particular, in Objective-C
292 you can't use 'in' as the name of the running
293 variable in a C for loop. We could potentially
294 try to add code here to disambiguate, but it
295 seems a reasonable limitation. */
296 token->type = CPP_KEYWORD;
297 token->keyword = rid_code;
298 break;
299 }
300 /* Else, "pq" keywords outside of the "pq" context are
301 not keywords, and we fall through to the code for
302 normal tokens. */
303 }
304 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
305 {
306 /* We found an Objective-C "property attribute"
307 keyword (getter, setter, readonly, etc). These are
308 only valid in the property context. */
309 if (parser->objc_property_attr_context)
310 {
311 token->type = CPP_KEYWORD;
312 token->keyword = rid_code;
313 break;
314 }
315 /* Else they are not special keywords.
316 */
317 }
318 else if (c_dialect_objc ()
319 && (OBJC_IS_AT_KEYWORD (rid_code)
320 || OBJC_IS_CXX_KEYWORD (rid_code)))
321 {
322 /* We found one of the Objective-C "@" keywords (defs,
323 selector, synchronized, etc) or one of the
324 Objective-C "cxx" keywords (class, private,
325 protected, public, try, catch, throw) without a
326 preceding '@' sign. Do nothing and fall through to
327 the code for normal tokens (in C++ we would still
328 consider the CXX ones keywords, but not in C). */
329 ;
330 }
331 else
332 {
333 token->type = CPP_KEYWORD;
334 token->keyword = rid_code;
335 break;
336 }
337 }
338
339 decl = lookup_name (token->value);
340 if (decl)
341 {
342 if (TREE_CODE (decl) == TYPE_DECL)
343 {
344 token->id_kind = C_ID_TYPENAME;
345 break;
346 }
347 }
348 else if (c_dialect_objc ())
349 {
350 tree objc_interface_decl = objc_is_class_name (token->value);
351 /* Objective-C class names are in the same namespace as
352 variables and typedefs, and hence are shadowed by local
353 declarations. */
354 if (objc_interface_decl
355 && (!objc_force_identifier || global_bindings_p ()))
356 {
357 token->value = objc_interface_decl;
358 token->id_kind = C_ID_CLASSNAME;
359 break;
360 }
361 }
362 token->id_kind = C_ID_ID;
363 }
364 break;
365 case CPP_AT_NAME:
366 /* This only happens in Objective-C; it must be a keyword. */
367 token->type = CPP_KEYWORD;
368 switch (C_RID_CODE (token->value))
369 {
370 /* Replace 'class' with '@class', 'private' with '@private',
371 etc. This prevents confusion with the C++ keyword
372 'class', and makes the tokens consistent with other
373 Objective-C 'AT' keywords. For example '@class' is
374 reported as RID_AT_CLASS which is consistent with
375 '@synchronized', which is reported as
376 RID_AT_SYNCHRONIZED.
377 */
378 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
379 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
380 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
381 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
382 case RID_THROW: token->keyword = RID_AT_THROW; break;
383 case RID_TRY: token->keyword = RID_AT_TRY; break;
384 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
385 case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break;
386 default: token->keyword = C_RID_CODE (token->value);
387 }
388 break;
389 case CPP_COLON:
390 case CPP_COMMA:
391 case CPP_CLOSE_PAREN:
392 case CPP_SEMICOLON:
393 /* These tokens may affect the interpretation of any identifiers
394 following, if doing Objective-C. */
395 if (c_dialect_objc ())
396 parser->objc_need_raw_identifier = false;
397 break;
398 case CPP_PRAGMA:
399 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
400 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
401 token->value = NULL;
402 break;
403 default:
404 break;
405 }
406 timevar_pop (TV_LEX);
407 }
408
409 /* Return a pointer to the next token from PARSER, reading it in if
410 necessary. */
411
412 static inline c_token *
413 c_parser_peek_token (c_parser *parser)
414 {
415 if (parser->tokens_avail == 0)
416 {
417 c_lex_one_token (parser, &parser->tokens[0]);
418 parser->tokens_avail = 1;
419 }
420 return &parser->tokens[0];
421 }
422
423 /* Return true if the next token from PARSER has the indicated
424 TYPE. */
425
426 static inline bool
427 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
428 {
429 return c_parser_peek_token (parser)->type == type;
430 }
431
432 /* Return true if the next token from PARSER does not have the
433 indicated TYPE. */
434
435 static inline bool
436 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
437 {
438 return !c_parser_next_token_is (parser, type);
439 }
440
441 /* Return true if the next token from PARSER is the indicated
442 KEYWORD. */
443
444 static inline bool
445 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
446 {
447 return c_parser_peek_token (parser)->keyword == keyword;
448 }
449
450 /* Return a pointer to the next-but-one token from PARSER, reading it
451 in if necessary. The next token is already read in. */
452
453 static c_token *
454 c_parser_peek_2nd_token (c_parser *parser)
455 {
456 if (parser->tokens_avail >= 2)
457 return &parser->tokens[1];
458 gcc_assert (parser->tokens_avail == 1);
459 gcc_assert (parser->tokens[0].type != CPP_EOF);
460 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
461 c_lex_one_token (parser, &parser->tokens[1]);
462 parser->tokens_avail = 2;
463 return &parser->tokens[1];
464 }
465
466 /* Return true if TOKEN can start a type name,
467 false otherwise. */
468 static bool
469 c_token_starts_typename (c_token *token)
470 {
471 switch (token->type)
472 {
473 case CPP_NAME:
474 switch (token->id_kind)
475 {
476 case C_ID_ID:
477 return false;
478 case C_ID_ADDRSPACE:
479 return true;
480 case C_ID_TYPENAME:
481 return true;
482 case C_ID_CLASSNAME:
483 gcc_assert (c_dialect_objc ());
484 return true;
485 default:
486 gcc_unreachable ();
487 }
488 case CPP_KEYWORD:
489 switch (token->keyword)
490 {
491 case RID_UNSIGNED:
492 case RID_LONG:
493 case RID_SHORT:
494 case RID_SIGNED:
495 case RID_COMPLEX:
496 case RID_INT:
497 case RID_CHAR:
498 case RID_FLOAT:
499 case RID_DOUBLE:
500 case RID_VOID:
501 case RID_DFLOAT32:
502 case RID_DFLOAT64:
503 case RID_DFLOAT128:
504 case RID_BOOL:
505 case RID_ENUM:
506 case RID_STRUCT:
507 case RID_UNION:
508 case RID_TYPEOF:
509 case RID_CONST:
510 case RID_ATOMIC:
511 case RID_VOLATILE:
512 case RID_RESTRICT:
513 case RID_ATTRIBUTE:
514 case RID_FRACT:
515 case RID_ACCUM:
516 case RID_SAT:
517 case RID_AUTO_TYPE:
518 return true;
519 default:
520 if (token->keyword >= RID_FIRST_INT_N
521 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
522 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
523 return true;
524 return false;
525 }
526 case CPP_LESS:
527 if (c_dialect_objc ())
528 return true;
529 return false;
530 default:
531 return false;
532 }
533 }
534
535 enum c_lookahead_kind {
536 /* Always treat unknown identifiers as typenames. */
537 cla_prefer_type,
538
539 /* Could be parsing a nonabstract declarator. Only treat an identifier
540 as a typename if followed by another identifier or a star. */
541 cla_nonabstract_decl,
542
543 /* Never treat identifiers as typenames. */
544 cla_prefer_id
545 };
546
547 /* Return true if the next token from PARSER can start a type name,
548 false otherwise. LA specifies how to do lookahead in order to
549 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
550
551 static inline bool
552 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
553 {
554 c_token *token = c_parser_peek_token (parser);
555 if (c_token_starts_typename (token))
556 return true;
557
558 /* Try a bit harder to detect an unknown typename. */
559 if (la != cla_prefer_id
560 && token->type == CPP_NAME
561 && token->id_kind == C_ID_ID
562
563 /* Do not try too hard when we could have "object in array". */
564 && !parser->objc_could_be_foreach_context
565
566 && (la == cla_prefer_type
567 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
568 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
569
570 /* Only unknown identifiers. */
571 && !lookup_name (token->value))
572 return true;
573
574 return false;
575 }
576
577 /* Return true if TOKEN is a type qualifier, false otherwise. */
578 static bool
579 c_token_is_qualifier (c_token *token)
580 {
581 switch (token->type)
582 {
583 case CPP_NAME:
584 switch (token->id_kind)
585 {
586 case C_ID_ADDRSPACE:
587 return true;
588 default:
589 return false;
590 }
591 case CPP_KEYWORD:
592 switch (token->keyword)
593 {
594 case RID_CONST:
595 case RID_VOLATILE:
596 case RID_RESTRICT:
597 case RID_ATTRIBUTE:
598 case RID_ATOMIC:
599 return true;
600 default:
601 return false;
602 }
603 case CPP_LESS:
604 return false;
605 default:
606 gcc_unreachable ();
607 }
608 }
609
610 /* Return true if the next token from PARSER is a type qualifier,
611 false otherwise. */
612 static inline bool
613 c_parser_next_token_is_qualifier (c_parser *parser)
614 {
615 c_token *token = c_parser_peek_token (parser);
616 return c_token_is_qualifier (token);
617 }
618
619 /* Return true if TOKEN can start declaration specifiers, false
620 otherwise. */
621 static bool
622 c_token_starts_declspecs (c_token *token)
623 {
624 switch (token->type)
625 {
626 case CPP_NAME:
627 switch (token->id_kind)
628 {
629 case C_ID_ID:
630 return false;
631 case C_ID_ADDRSPACE:
632 return true;
633 case C_ID_TYPENAME:
634 return true;
635 case C_ID_CLASSNAME:
636 gcc_assert (c_dialect_objc ());
637 return true;
638 default:
639 gcc_unreachable ();
640 }
641 case CPP_KEYWORD:
642 switch (token->keyword)
643 {
644 case RID_STATIC:
645 case RID_EXTERN:
646 case RID_REGISTER:
647 case RID_TYPEDEF:
648 case RID_INLINE:
649 case RID_NORETURN:
650 case RID_AUTO:
651 case RID_THREAD:
652 case RID_UNSIGNED:
653 case RID_LONG:
654 case RID_SHORT:
655 case RID_SIGNED:
656 case RID_COMPLEX:
657 case RID_INT:
658 case RID_CHAR:
659 case RID_FLOAT:
660 case RID_DOUBLE:
661 case RID_VOID:
662 case RID_DFLOAT32:
663 case RID_DFLOAT64:
664 case RID_DFLOAT128:
665 case RID_BOOL:
666 case RID_ENUM:
667 case RID_STRUCT:
668 case RID_UNION:
669 case RID_TYPEOF:
670 case RID_CONST:
671 case RID_VOLATILE:
672 case RID_RESTRICT:
673 case RID_ATTRIBUTE:
674 case RID_FRACT:
675 case RID_ACCUM:
676 case RID_SAT:
677 case RID_ALIGNAS:
678 case RID_ATOMIC:
679 case RID_AUTO_TYPE:
680 return true;
681 default:
682 if (token->keyword >= RID_FIRST_INT_N
683 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
684 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
685 return true;
686 return false;
687 }
688 case CPP_LESS:
689 if (c_dialect_objc ())
690 return true;
691 return false;
692 default:
693 return false;
694 }
695 }
696
697
698 /* Return true if TOKEN can start declaration specifiers or a static
699 assertion, false otherwise. */
700 static bool
701 c_token_starts_declaration (c_token *token)
702 {
703 if (c_token_starts_declspecs (token)
704 || token->keyword == RID_STATIC_ASSERT)
705 return true;
706 else
707 return false;
708 }
709
710 /* Return true if the next token from PARSER can start declaration
711 specifiers, false otherwise. */
712 static inline bool
713 c_parser_next_token_starts_declspecs (c_parser *parser)
714 {
715 c_token *token = c_parser_peek_token (parser);
716
717 /* In Objective-C, a classname normally starts a declspecs unless it
718 is immediately followed by a dot. In that case, it is the
719 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
720 setter/getter on the class. c_token_starts_declspecs() can't
721 differentiate between the two cases because it only checks the
722 current token, so we have a special check here. */
723 if (c_dialect_objc ()
724 && token->type == CPP_NAME
725 && token->id_kind == C_ID_CLASSNAME
726 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
727 return false;
728
729 return c_token_starts_declspecs (token);
730 }
731
732 /* Return true if the next tokens from PARSER can start declaration
733 specifiers or a static assertion, false otherwise. */
734 static inline bool
735 c_parser_next_tokens_start_declaration (c_parser *parser)
736 {
737 c_token *token = c_parser_peek_token (parser);
738
739 /* Same as above. */
740 if (c_dialect_objc ()
741 && token->type == CPP_NAME
742 && token->id_kind == C_ID_CLASSNAME
743 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
744 return false;
745
746 /* Labels do not start declarations. */
747 if (token->type == CPP_NAME
748 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
749 return false;
750
751 if (c_token_starts_declaration (token))
752 return true;
753
754 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
755 return true;
756
757 return false;
758 }
759
760 /* Consume the next token from PARSER. */
761
762 static void
763 c_parser_consume_token (c_parser *parser)
764 {
765 gcc_assert (parser->tokens_avail >= 1);
766 gcc_assert (parser->tokens[0].type != CPP_EOF);
767 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
768 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
769 if (parser->tokens != &parser->tokens_buf[0])
770 parser->tokens++;
771 else if (parser->tokens_avail == 2)
772 parser->tokens[0] = parser->tokens[1];
773 parser->tokens_avail--;
774 }
775
776 /* Expect the current token to be a #pragma. Consume it and remember
777 that we've begun parsing a pragma. */
778
779 static void
780 c_parser_consume_pragma (c_parser *parser)
781 {
782 gcc_assert (!parser->in_pragma);
783 gcc_assert (parser->tokens_avail >= 1);
784 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
785 if (parser->tokens != &parser->tokens_buf[0])
786 parser->tokens++;
787 else if (parser->tokens_avail == 2)
788 parser->tokens[0] = parser->tokens[1];
789 parser->tokens_avail--;
790 parser->in_pragma = true;
791 }
792
793 /* Update the global input_location from TOKEN. */
794 static inline void
795 c_parser_set_source_position_from_token (c_token *token)
796 {
797 if (token->type != CPP_EOF)
798 {
799 input_location = token->location;
800 }
801 }
802
803 /* Issue a diagnostic of the form
804 FILE:LINE: MESSAGE before TOKEN
805 where TOKEN is the next token in the input stream of PARSER.
806 MESSAGE (specified by the caller) is usually of the form "expected
807 OTHER-TOKEN".
808
809 Do not issue a diagnostic if still recovering from an error.
810
811 ??? This is taken from the C++ parser, but building up messages in
812 this way is not i18n-friendly and some other approach should be
813 used. */
814
815 static void
816 c_parser_error (c_parser *parser, const char *gmsgid)
817 {
818 c_token *token = c_parser_peek_token (parser);
819 if (parser->error)
820 return;
821 parser->error = true;
822 if (!gmsgid)
823 return;
824 /* This diagnostic makes more sense if it is tagged to the line of
825 the token we just peeked at. */
826 c_parser_set_source_position_from_token (token);
827 c_parse_error (gmsgid,
828 /* Because c_parse_error does not understand
829 CPP_KEYWORD, keywords are treated like
830 identifiers. */
831 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
832 /* ??? The C parser does not save the cpp flags of a
833 token, we need to pass 0 here and we will not get
834 the source spelling of some tokens but rather the
835 canonical spelling. */
836 token->value, /*flags=*/0);
837 }
838
839 /* If the next token is of the indicated TYPE, consume it. Otherwise,
840 issue the error MSGID. If MSGID is NULL then a message has already
841 been produced and no message will be produced this time. Returns
842 true if found, false otherwise. */
843
844 static bool
845 c_parser_require (c_parser *parser,
846 enum cpp_ttype type,
847 const char *msgid)
848 {
849 if (c_parser_next_token_is (parser, type))
850 {
851 c_parser_consume_token (parser);
852 return true;
853 }
854 else
855 {
856 c_parser_error (parser, msgid);
857 return false;
858 }
859 }
860
861 /* If the next token is the indicated keyword, consume it. Otherwise,
862 issue the error MSGID. Returns true if found, false otherwise. */
863
864 static bool
865 c_parser_require_keyword (c_parser *parser,
866 enum rid keyword,
867 const char *msgid)
868 {
869 if (c_parser_next_token_is_keyword (parser, keyword))
870 {
871 c_parser_consume_token (parser);
872 return true;
873 }
874 else
875 {
876 c_parser_error (parser, msgid);
877 return false;
878 }
879 }
880
881 /* Like c_parser_require, except that tokens will be skipped until the
882 desired token is found. An error message is still produced if the
883 next token is not as expected. If MSGID is NULL then a message has
884 already been produced and no message will be produced this
885 time. */
886
887 static void
888 c_parser_skip_until_found (c_parser *parser,
889 enum cpp_ttype type,
890 const char *msgid)
891 {
892 unsigned nesting_depth = 0;
893
894 if (c_parser_require (parser, type, msgid))
895 return;
896
897 /* Skip tokens until the desired token is found. */
898 while (true)
899 {
900 /* Peek at the next token. */
901 c_token *token = c_parser_peek_token (parser);
902 /* If we've reached the token we want, consume it and stop. */
903 if (token->type == type && !nesting_depth)
904 {
905 c_parser_consume_token (parser);
906 break;
907 }
908
909 /* If we've run out of tokens, stop. */
910 if (token->type == CPP_EOF)
911 return;
912 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
913 return;
914 if (token->type == CPP_OPEN_BRACE
915 || token->type == CPP_OPEN_PAREN
916 || token->type == CPP_OPEN_SQUARE)
917 ++nesting_depth;
918 else if (token->type == CPP_CLOSE_BRACE
919 || token->type == CPP_CLOSE_PAREN
920 || token->type == CPP_CLOSE_SQUARE)
921 {
922 if (nesting_depth-- == 0)
923 break;
924 }
925 /* Consume this token. */
926 c_parser_consume_token (parser);
927 }
928 parser->error = false;
929 }
930
931 /* Skip tokens until the end of a parameter is found, but do not
932 consume the comma, semicolon or closing delimiter. */
933
934 static void
935 c_parser_skip_to_end_of_parameter (c_parser *parser)
936 {
937 unsigned nesting_depth = 0;
938
939 while (true)
940 {
941 c_token *token = c_parser_peek_token (parser);
942 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
943 && !nesting_depth)
944 break;
945 /* If we've run out of tokens, stop. */
946 if (token->type == CPP_EOF)
947 return;
948 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
949 return;
950 if (token->type == CPP_OPEN_BRACE
951 || token->type == CPP_OPEN_PAREN
952 || token->type == CPP_OPEN_SQUARE)
953 ++nesting_depth;
954 else if (token->type == CPP_CLOSE_BRACE
955 || token->type == CPP_CLOSE_PAREN
956 || token->type == CPP_CLOSE_SQUARE)
957 {
958 if (nesting_depth-- == 0)
959 break;
960 }
961 /* Consume this token. */
962 c_parser_consume_token (parser);
963 }
964 parser->error = false;
965 }
966
967 /* Expect to be at the end of the pragma directive and consume an
968 end of line marker. */
969
970 static void
971 c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
972 {
973 gcc_assert (parser->in_pragma);
974 parser->in_pragma = false;
975
976 if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
977 c_parser_error (parser, "expected end of line");
978
979 cpp_ttype token_type;
980 do
981 {
982 c_token *token = c_parser_peek_token (parser);
983 token_type = token->type;
984 if (token_type == CPP_EOF)
985 break;
986 c_parser_consume_token (parser);
987 }
988 while (token_type != CPP_PRAGMA_EOL);
989
990 parser->error = false;
991 }
992
993 /* Skip tokens until we have consumed an entire block, or until we
994 have consumed a non-nested ';'. */
995
996 static void
997 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
998 {
999 unsigned nesting_depth = 0;
1000 bool save_error = parser->error;
1001
1002 while (true)
1003 {
1004 c_token *token;
1005
1006 /* Peek at the next token. */
1007 token = c_parser_peek_token (parser);
1008
1009 switch (token->type)
1010 {
1011 case CPP_EOF:
1012 return;
1013
1014 case CPP_PRAGMA_EOL:
1015 if (parser->in_pragma)
1016 return;
1017 break;
1018
1019 case CPP_SEMICOLON:
1020 /* If the next token is a ';', we have reached the
1021 end of the statement. */
1022 if (!nesting_depth)
1023 {
1024 /* Consume the ';'. */
1025 c_parser_consume_token (parser);
1026 goto finished;
1027 }
1028 break;
1029
1030 case CPP_CLOSE_BRACE:
1031 /* If the next token is a non-nested '}', then we have
1032 reached the end of the current block. */
1033 if (nesting_depth == 0 || --nesting_depth == 0)
1034 {
1035 c_parser_consume_token (parser);
1036 goto finished;
1037 }
1038 break;
1039
1040 case CPP_OPEN_BRACE:
1041 /* If it the next token is a '{', then we are entering a new
1042 block. Consume the entire block. */
1043 ++nesting_depth;
1044 break;
1045
1046 case CPP_PRAGMA:
1047 /* If we see a pragma, consume the whole thing at once. We
1048 have some safeguards against consuming pragmas willy-nilly.
1049 Normally, we'd expect to be here with parser->error set,
1050 which disables these safeguards. But it's possible to get
1051 here for secondary error recovery, after parser->error has
1052 been cleared. */
1053 c_parser_consume_pragma (parser);
1054 c_parser_skip_to_pragma_eol (parser);
1055 parser->error = save_error;
1056 continue;
1057
1058 default:
1059 break;
1060 }
1061
1062 c_parser_consume_token (parser);
1063 }
1064
1065 finished:
1066 parser->error = false;
1067 }
1068
1069 /* CPP's options (initialized by c-opts.c). */
1070 extern cpp_options *cpp_opts;
1071
1072 /* Save the warning flags which are controlled by __extension__. */
1073
1074 static inline int
1075 disable_extension_diagnostics (void)
1076 {
1077 int ret = (pedantic
1078 | (warn_pointer_arith << 1)
1079 | (warn_traditional << 2)
1080 | (flag_iso << 3)
1081 | (warn_long_long << 4)
1082 | (warn_cxx_compat << 5)
1083 | (warn_overlength_strings << 6)
1084 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1085 play tricks to properly restore it. */
1086 | ((warn_c90_c99_compat == 1) << 7)
1087 | ((warn_c90_c99_compat == -1) << 8)
1088 /* Similarly for warn_c99_c11_compat. */
1089 | ((warn_c99_c11_compat == 1) << 9)
1090 | ((warn_c99_c11_compat == -1) << 10)
1091 );
1092 cpp_opts->cpp_pedantic = pedantic = 0;
1093 warn_pointer_arith = 0;
1094 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1095 flag_iso = 0;
1096 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1097 warn_cxx_compat = 0;
1098 warn_overlength_strings = 0;
1099 warn_c90_c99_compat = 0;
1100 warn_c99_c11_compat = 0;
1101 return ret;
1102 }
1103
1104 /* Restore the warning flags which are controlled by __extension__.
1105 FLAGS is the return value from disable_extension_diagnostics. */
1106
1107 static inline void
1108 restore_extension_diagnostics (int flags)
1109 {
1110 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1111 warn_pointer_arith = (flags >> 1) & 1;
1112 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1113 flag_iso = (flags >> 3) & 1;
1114 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1115 warn_cxx_compat = (flags >> 5) & 1;
1116 warn_overlength_strings = (flags >> 6) & 1;
1117 /* See above for why is this needed. */
1118 warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1119 warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1120 }
1121
1122 /* Possibly kinds of declarator to parse. */
1123 enum c_dtr_syn {
1124 /* A normal declarator with an identifier. */
1125 C_DTR_NORMAL,
1126 /* An abstract declarator (maybe empty). */
1127 C_DTR_ABSTRACT,
1128 /* A parameter declarator: may be either, but after a type name does
1129 not redeclare a typedef name as an identifier if it can
1130 alternatively be interpreted as a typedef name; see DR#009,
1131 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1132 following DR#249. For example, given a typedef T, "int T" and
1133 "int *T" are valid parameter declarations redeclaring T, while
1134 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1135 abstract declarators rather than involving redundant parentheses;
1136 the same applies with attributes inside the parentheses before
1137 "T". */
1138 C_DTR_PARM
1139 };
1140
1141 /* The binary operation precedence levels, where 0 is a dummy lowest level
1142 used for the bottom of the stack. */
1143 enum c_parser_prec {
1144 PREC_NONE,
1145 PREC_LOGOR,
1146 PREC_LOGAND,
1147 PREC_BITOR,
1148 PREC_BITXOR,
1149 PREC_BITAND,
1150 PREC_EQ,
1151 PREC_REL,
1152 PREC_SHIFT,
1153 PREC_ADD,
1154 PREC_MULT,
1155 NUM_PRECS
1156 };
1157
1158 static void c_parser_external_declaration (c_parser *);
1159 static void c_parser_asm_definition (c_parser *);
1160 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1161 bool, bool, tree *, vec<c_token>,
1162 tree = NULL_TREE);
1163 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1164 static void c_parser_static_assert_declaration (c_parser *);
1165 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1166 bool, bool, bool, enum c_lookahead_kind);
1167 static struct c_typespec c_parser_enum_specifier (c_parser *);
1168 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1169 static tree c_parser_struct_declaration (c_parser *);
1170 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1171 static tree c_parser_alignas_specifier (c_parser *);
1172 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1173 bool *);
1174 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1175 c_dtr_syn, bool *);
1176 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1177 bool,
1178 struct c_declarator *);
1179 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1180 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1181 tree);
1182 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1183 static tree c_parser_simple_asm_expr (c_parser *);
1184 static tree c_parser_attributes (c_parser *);
1185 static struct c_type_name *c_parser_type_name (c_parser *);
1186 static struct c_expr c_parser_initializer (c_parser *);
1187 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1188 static void c_parser_initelt (c_parser *, struct obstack *);
1189 static void c_parser_initval (c_parser *, struct c_expr *,
1190 struct obstack *);
1191 static tree c_parser_compound_statement (c_parser *);
1192 static void c_parser_compound_statement_nostart (c_parser *);
1193 static void c_parser_label (c_parser *);
1194 static void c_parser_statement (c_parser *);
1195 static void c_parser_statement_after_labels (c_parser *, vec<tree> * = NULL);
1196 static void c_parser_if_statement (c_parser *, vec<tree> *);
1197 static void c_parser_switch_statement (c_parser *);
1198 static void c_parser_while_statement (c_parser *, bool);
1199 static void c_parser_do_statement (c_parser *, bool);
1200 static void c_parser_for_statement (c_parser *, bool);
1201 static tree c_parser_asm_statement (c_parser *);
1202 static tree c_parser_asm_operands (c_parser *);
1203 static tree c_parser_asm_goto_operands (c_parser *);
1204 static tree c_parser_asm_clobbers (c_parser *);
1205 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1206 tree = NULL_TREE);
1207 static struct c_expr c_parser_conditional_expression (c_parser *,
1208 struct c_expr *, tree);
1209 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1210 tree);
1211 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1212 static struct c_expr c_parser_unary_expression (c_parser *);
1213 static struct c_expr c_parser_sizeof_expression (c_parser *);
1214 static struct c_expr c_parser_alignof_expression (c_parser *);
1215 static struct c_expr c_parser_postfix_expression (c_parser *);
1216 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1217 struct c_type_name *,
1218 location_t);
1219 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1220 location_t loc,
1221 struct c_expr);
1222 static tree c_parser_transaction (c_parser *, enum rid);
1223 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1224 static tree c_parser_transaction_cancel (c_parser *);
1225 static struct c_expr c_parser_expression (c_parser *);
1226 static struct c_expr c_parser_expression_conv (c_parser *);
1227 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1228 vec<tree, va_gc> **, location_t *,
1229 tree *, vec<location_t> *,
1230 unsigned int * = NULL);
1231 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1232 static void c_parser_oacc_update (c_parser *);
1233 static void c_parser_omp_construct (c_parser *);
1234 static void c_parser_omp_threadprivate (c_parser *);
1235 static void c_parser_omp_barrier (c_parser *);
1236 static void c_parser_omp_flush (c_parser *);
1237 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1238 tree, tree *);
1239 static void c_parser_omp_taskwait (c_parser *);
1240 static void c_parser_omp_taskyield (c_parser *);
1241 static void c_parser_omp_cancel (c_parser *);
1242 static void c_parser_omp_cancellation_point (c_parser *);
1243
1244 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1245 pragma_stmt, pragma_compound };
1246 static bool c_parser_pragma (c_parser *, enum pragma_context);
1247 static bool c_parser_omp_target (c_parser *, enum pragma_context);
1248 static void c_parser_omp_end_declare_target (c_parser *);
1249 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1250 static bool c_parser_omp_ordered (c_parser *, enum pragma_context);
1251 static void c_parser_oacc_routine (c_parser *parser, enum pragma_context);
1252
1253 /* These Objective-C parser functions are only ever called when
1254 compiling Objective-C. */
1255 static void c_parser_objc_class_definition (c_parser *, tree);
1256 static void c_parser_objc_class_instance_variables (c_parser *);
1257 static void c_parser_objc_class_declaration (c_parser *);
1258 static void c_parser_objc_alias_declaration (c_parser *);
1259 static void c_parser_objc_protocol_definition (c_parser *, tree);
1260 static bool c_parser_objc_method_type (c_parser *);
1261 static void c_parser_objc_method_definition (c_parser *);
1262 static void c_parser_objc_methodprotolist (c_parser *);
1263 static void c_parser_objc_methodproto (c_parser *);
1264 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1265 static tree c_parser_objc_type_name (c_parser *);
1266 static tree c_parser_objc_protocol_refs (c_parser *);
1267 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1268 static void c_parser_objc_synchronized_statement (c_parser *);
1269 static tree c_parser_objc_selector (c_parser *);
1270 static tree c_parser_objc_selector_arg (c_parser *);
1271 static tree c_parser_objc_receiver (c_parser *);
1272 static tree c_parser_objc_message_args (c_parser *);
1273 static tree c_parser_objc_keywordexpr (c_parser *);
1274 static void c_parser_objc_at_property_declaration (c_parser *);
1275 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1276 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1277 static bool c_parser_objc_diagnose_bad_element_prefix
1278 (c_parser *, struct c_declspecs *);
1279
1280 /* Cilk Plus supporting routines. */
1281 static void c_parser_cilk_simd (c_parser *);
1282 static void c_parser_cilk_for (c_parser *, tree);
1283 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
1284 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
1285 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
1286 static void c_parser_cilk_grainsize (c_parser *);
1287
1288 /* Parse a translation unit (C90 6.7, C99 6.9).
1289
1290 translation-unit:
1291 external-declarations
1292
1293 external-declarations:
1294 external-declaration
1295 external-declarations external-declaration
1296
1297 GNU extensions:
1298
1299 translation-unit:
1300 empty
1301 */
1302
1303 static void
1304 c_parser_translation_unit (c_parser *parser)
1305 {
1306 if (c_parser_next_token_is (parser, CPP_EOF))
1307 {
1308 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1309 "ISO C forbids an empty translation unit");
1310 }
1311 else
1312 {
1313 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1314 mark_valid_location_for_stdc_pragma (false);
1315 do
1316 {
1317 ggc_collect ();
1318 c_parser_external_declaration (parser);
1319 obstack_free (&parser_obstack, obstack_position);
1320 }
1321 while (c_parser_next_token_is_not (parser, CPP_EOF));
1322 }
1323 }
1324
1325 /* Parse an external declaration (C90 6.7, C99 6.9).
1326
1327 external-declaration:
1328 function-definition
1329 declaration
1330
1331 GNU extensions:
1332
1333 external-declaration:
1334 asm-definition
1335 ;
1336 __extension__ external-declaration
1337
1338 Objective-C:
1339
1340 external-declaration:
1341 objc-class-definition
1342 objc-class-declaration
1343 objc-alias-declaration
1344 objc-protocol-definition
1345 objc-method-definition
1346 @end
1347 */
1348
1349 static void
1350 c_parser_external_declaration (c_parser *parser)
1351 {
1352 int ext;
1353 switch (c_parser_peek_token (parser)->type)
1354 {
1355 case CPP_KEYWORD:
1356 switch (c_parser_peek_token (parser)->keyword)
1357 {
1358 case RID_EXTENSION:
1359 ext = disable_extension_diagnostics ();
1360 c_parser_consume_token (parser);
1361 c_parser_external_declaration (parser);
1362 restore_extension_diagnostics (ext);
1363 break;
1364 case RID_ASM:
1365 c_parser_asm_definition (parser);
1366 break;
1367 case RID_AT_INTERFACE:
1368 case RID_AT_IMPLEMENTATION:
1369 gcc_assert (c_dialect_objc ());
1370 c_parser_objc_class_definition (parser, NULL_TREE);
1371 break;
1372 case RID_AT_CLASS:
1373 gcc_assert (c_dialect_objc ());
1374 c_parser_objc_class_declaration (parser);
1375 break;
1376 case RID_AT_ALIAS:
1377 gcc_assert (c_dialect_objc ());
1378 c_parser_objc_alias_declaration (parser);
1379 break;
1380 case RID_AT_PROTOCOL:
1381 gcc_assert (c_dialect_objc ());
1382 c_parser_objc_protocol_definition (parser, NULL_TREE);
1383 break;
1384 case RID_AT_PROPERTY:
1385 gcc_assert (c_dialect_objc ());
1386 c_parser_objc_at_property_declaration (parser);
1387 break;
1388 case RID_AT_SYNTHESIZE:
1389 gcc_assert (c_dialect_objc ());
1390 c_parser_objc_at_synthesize_declaration (parser);
1391 break;
1392 case RID_AT_DYNAMIC:
1393 gcc_assert (c_dialect_objc ());
1394 c_parser_objc_at_dynamic_declaration (parser);
1395 break;
1396 case RID_AT_END:
1397 gcc_assert (c_dialect_objc ());
1398 c_parser_consume_token (parser);
1399 objc_finish_implementation ();
1400 break;
1401 default:
1402 goto decl_or_fndef;
1403 }
1404 break;
1405 case CPP_SEMICOLON:
1406 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1407 "ISO C does not allow extra %<;%> outside of a function");
1408 c_parser_consume_token (parser);
1409 break;
1410 case CPP_PRAGMA:
1411 mark_valid_location_for_stdc_pragma (true);
1412 c_parser_pragma (parser, pragma_external);
1413 mark_valid_location_for_stdc_pragma (false);
1414 break;
1415 case CPP_PLUS:
1416 case CPP_MINUS:
1417 if (c_dialect_objc ())
1418 {
1419 c_parser_objc_method_definition (parser);
1420 break;
1421 }
1422 /* Else fall through, and yield a syntax error trying to parse
1423 as a declaration or function definition. */
1424 default:
1425 decl_or_fndef:
1426 /* A declaration or a function definition (or, in Objective-C,
1427 an @interface or @protocol with prefix attributes). We can
1428 only tell which after parsing the declaration specifiers, if
1429 any, and the first declarator. */
1430 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1431 NULL, vNULL);
1432 break;
1433 }
1434 }
1435
1436 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1437 static void c_finish_oacc_routine (c_parser *, tree, tree, bool, bool, bool);
1438
1439 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1440 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1441 accepted; otherwise (old-style parameter declarations) only other
1442 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1443 assertion is accepted; otherwise (old-style parameter declarations)
1444 it is not. If NESTED is true, we are inside a function or parsing
1445 old-style parameter declarations; any functions encountered are
1446 nested functions and declaration specifiers are required; otherwise
1447 we are at top level and functions are normal functions and
1448 declaration specifiers may be optional. If EMPTY_OK is true, empty
1449 declarations are OK (subject to all other constraints); otherwise
1450 (old-style parameter declarations) they are diagnosed. If
1451 START_ATTR_OK is true, the declaration specifiers may start with
1452 attributes; otherwise they may not.
1453 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1454 declaration when parsing an Objective-C foreach statement.
1455
1456 declaration:
1457 declaration-specifiers init-declarator-list[opt] ;
1458 static_assert-declaration
1459
1460 function-definition:
1461 declaration-specifiers[opt] declarator declaration-list[opt]
1462 compound-statement
1463
1464 declaration-list:
1465 declaration
1466 declaration-list declaration
1467
1468 init-declarator-list:
1469 init-declarator
1470 init-declarator-list , init-declarator
1471
1472 init-declarator:
1473 declarator simple-asm-expr[opt] attributes[opt]
1474 declarator simple-asm-expr[opt] attributes[opt] = initializer
1475
1476 GNU extensions:
1477
1478 nested-function-definition:
1479 declaration-specifiers declarator declaration-list[opt]
1480 compound-statement
1481
1482 Objective-C:
1483 attributes objc-class-definition
1484 attributes objc-category-definition
1485 attributes objc-protocol-definition
1486
1487 The simple-asm-expr and attributes are GNU extensions.
1488
1489 This function does not handle __extension__; that is handled in its
1490 callers. ??? Following the old parser, __extension__ may start
1491 external declarations, declarations in functions and declarations
1492 at the start of "for" loops, but not old-style parameter
1493 declarations.
1494
1495 C99 requires declaration specifiers in a function definition; the
1496 absence is diagnosed through the diagnosis of implicit int. In GNU
1497 C we also allow but diagnose declarations without declaration
1498 specifiers, but only at top level (elsewhere they conflict with
1499 other syntax).
1500
1501 In Objective-C, declarations of the looping variable in a foreach
1502 statement are exceptionally terminated by 'in' (for example, 'for
1503 (NSObject *object in array) { ... }').
1504
1505 OpenMP:
1506
1507 declaration:
1508 threadprivate-directive */
1509
1510 static void
1511 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1512 bool static_assert_ok, bool empty_ok,
1513 bool nested, bool start_attr_ok,
1514 tree *objc_foreach_object_declaration,
1515 vec<c_token> omp_declare_simd_clauses,
1516 tree oacc_routine_clauses)
1517 {
1518 struct c_declspecs *specs;
1519 tree prefix_attrs;
1520 tree all_prefix_attrs;
1521 bool diagnosed_no_specs = false;
1522 location_t here = c_parser_peek_token (parser)->location;
1523
1524 if (static_assert_ok
1525 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1526 {
1527 c_parser_static_assert_declaration (parser);
1528 return;
1529 }
1530 specs = build_null_declspecs ();
1531
1532 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1533 if (c_parser_peek_token (parser)->type == CPP_NAME
1534 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1535 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1536 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1537 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1538 {
1539 tree name = c_parser_peek_token (parser)->value;
1540 error_at (here, "unknown type name %qE", name);
1541 /* Give a hint to the user. This is not C++ with its implicit
1542 typedef. */
1543 if (tag_exists_p (RECORD_TYPE, name))
1544 inform (here, "use %<struct%> keyword to refer to the type");
1545 else if (tag_exists_p (UNION_TYPE, name))
1546 inform (here, "use %<union%> keyword to refer to the type");
1547 else if (tag_exists_p (ENUMERAL_TYPE, name))
1548 inform (here, "use %<enum%> keyword to refer to the type");
1549
1550 /* Parse declspecs normally to get a correct pointer type, but avoid
1551 a further "fails to be a type name" error. Refuse nested functions
1552 since it is not how the user likely wants us to recover. */
1553 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1554 c_parser_peek_token (parser)->keyword = RID_VOID;
1555 c_parser_peek_token (parser)->value = error_mark_node;
1556 fndef_ok = !nested;
1557 }
1558
1559 c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1560 true, true, cla_nonabstract_decl);
1561 if (parser->error)
1562 {
1563 c_parser_skip_to_end_of_block_or_statement (parser);
1564 return;
1565 }
1566 if (nested && !specs->declspecs_seen_p)
1567 {
1568 c_parser_error (parser, "expected declaration specifiers");
1569 c_parser_skip_to_end_of_block_or_statement (parser);
1570 return;
1571 }
1572 finish_declspecs (specs);
1573 bool auto_type_p = specs->typespec_word == cts_auto_type;
1574 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1575 {
1576 if (auto_type_p)
1577 error_at (here, "%<__auto_type%> in empty declaration");
1578 else if (empty_ok)
1579 shadow_tag (specs);
1580 else
1581 {
1582 shadow_tag_warned (specs, 1);
1583 pedwarn (here, 0, "empty declaration");
1584 }
1585 c_parser_consume_token (parser);
1586 if (oacc_routine_clauses)
1587 c_finish_oacc_routine (parser, NULL_TREE,
1588 oacc_routine_clauses, false, true, false);
1589 return;
1590 }
1591
1592 /* Provide better error recovery. Note that a type name here is usually
1593 better diagnosed as a redeclaration. */
1594 if (empty_ok
1595 && specs->typespec_kind == ctsk_tagdef
1596 && c_parser_next_token_starts_declspecs (parser)
1597 && !c_parser_next_token_is (parser, CPP_NAME))
1598 {
1599 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1600 parser->error = false;
1601 shadow_tag_warned (specs, 1);
1602 return;
1603 }
1604 else if (c_dialect_objc () && !auto_type_p)
1605 {
1606 /* Prefix attributes are an error on method decls. */
1607 switch (c_parser_peek_token (parser)->type)
1608 {
1609 case CPP_PLUS:
1610 case CPP_MINUS:
1611 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1612 return;
1613 if (specs->attrs)
1614 {
1615 warning_at (c_parser_peek_token (parser)->location,
1616 OPT_Wattributes,
1617 "prefix attributes are ignored for methods");
1618 specs->attrs = NULL_TREE;
1619 }
1620 if (fndef_ok)
1621 c_parser_objc_method_definition (parser);
1622 else
1623 c_parser_objc_methodproto (parser);
1624 return;
1625 break;
1626 default:
1627 break;
1628 }
1629 /* This is where we parse 'attributes @interface ...',
1630 'attributes @implementation ...', 'attributes @protocol ...'
1631 (where attributes could be, for example, __attribute__
1632 ((deprecated)).
1633 */
1634 switch (c_parser_peek_token (parser)->keyword)
1635 {
1636 case RID_AT_INTERFACE:
1637 {
1638 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1639 return;
1640 c_parser_objc_class_definition (parser, specs->attrs);
1641 return;
1642 }
1643 break;
1644 case RID_AT_IMPLEMENTATION:
1645 {
1646 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1647 return;
1648 if (specs->attrs)
1649 {
1650 warning_at (c_parser_peek_token (parser)->location,
1651 OPT_Wattributes,
1652 "prefix attributes are ignored for implementations");
1653 specs->attrs = NULL_TREE;
1654 }
1655 c_parser_objc_class_definition (parser, NULL_TREE);
1656 return;
1657 }
1658 break;
1659 case RID_AT_PROTOCOL:
1660 {
1661 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1662 return;
1663 c_parser_objc_protocol_definition (parser, specs->attrs);
1664 return;
1665 }
1666 break;
1667 case RID_AT_ALIAS:
1668 case RID_AT_CLASS:
1669 case RID_AT_END:
1670 case RID_AT_PROPERTY:
1671 if (specs->attrs)
1672 {
1673 c_parser_error (parser, "unexpected attribute");
1674 specs->attrs = NULL;
1675 }
1676 break;
1677 default:
1678 break;
1679 }
1680 }
1681
1682 pending_xref_error ();
1683 prefix_attrs = specs->attrs;
1684 all_prefix_attrs = prefix_attrs;
1685 specs->attrs = NULL_TREE;
1686 for (bool first = true;; first = false)
1687 {
1688 struct c_declarator *declarator;
1689 bool dummy = false;
1690 timevar_id_t tv;
1691 tree fnbody;
1692 /* Declaring either one or more declarators (in which case we
1693 should diagnose if there were no declaration specifiers) or a
1694 function definition (in which case the diagnostic for
1695 implicit int suffices). */
1696 declarator = c_parser_declarator (parser,
1697 specs->typespec_kind != ctsk_none,
1698 C_DTR_NORMAL, &dummy);
1699 if (declarator == NULL)
1700 {
1701 if (omp_declare_simd_clauses.exists ()
1702 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1703 c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1704 omp_declare_simd_clauses);
1705 if (oacc_routine_clauses)
1706 c_finish_oacc_routine (parser, NULL_TREE,
1707 oacc_routine_clauses,
1708 false, first, false);
1709 c_parser_skip_to_end_of_block_or_statement (parser);
1710 return;
1711 }
1712 if (auto_type_p && declarator->kind != cdk_id)
1713 {
1714 error_at (here,
1715 "%<__auto_type%> requires a plain identifier"
1716 " as declarator");
1717 c_parser_skip_to_end_of_block_or_statement (parser);
1718 return;
1719 }
1720 if (c_parser_next_token_is (parser, CPP_EQ)
1721 || c_parser_next_token_is (parser, CPP_COMMA)
1722 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1723 || c_parser_next_token_is_keyword (parser, RID_ASM)
1724 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1725 || c_parser_next_token_is_keyword (parser, RID_IN))
1726 {
1727 tree asm_name = NULL_TREE;
1728 tree postfix_attrs = NULL_TREE;
1729 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1730 {
1731 diagnosed_no_specs = true;
1732 pedwarn (here, 0, "data definition has no type or storage class");
1733 }
1734 /* Having seen a data definition, there cannot now be a
1735 function definition. */
1736 fndef_ok = false;
1737 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1738 asm_name = c_parser_simple_asm_expr (parser);
1739 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1740 {
1741 postfix_attrs = c_parser_attributes (parser);
1742 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1743 {
1744 /* This means there is an attribute specifier after
1745 the declarator in a function definition. Provide
1746 some more information for the user. */
1747 error_at (here, "attributes should be specified before the "
1748 "declarator in a function definition");
1749 c_parser_skip_to_end_of_block_or_statement (parser);
1750 return;
1751 }
1752 }
1753 if (c_parser_next_token_is (parser, CPP_EQ))
1754 {
1755 tree d;
1756 struct c_expr init;
1757 location_t init_loc;
1758 c_parser_consume_token (parser);
1759 if (auto_type_p)
1760 {
1761 start_init (NULL_TREE, asm_name, global_bindings_p ());
1762 init_loc = c_parser_peek_token (parser)->location;
1763 init = c_parser_expr_no_commas (parser, NULL);
1764 if (TREE_CODE (init.value) == COMPONENT_REF
1765 && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
1766 error_at (here,
1767 "%<__auto_type%> used with a bit-field"
1768 " initializer");
1769 init = convert_lvalue_to_rvalue (init_loc, init, true, true);
1770 tree init_type = TREE_TYPE (init.value);
1771 /* As with typeof, remove all qualifiers from atomic types. */
1772 if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
1773 init_type
1774 = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
1775 bool vm_type = variably_modified_type_p (init_type,
1776 NULL_TREE);
1777 if (vm_type)
1778 init.value = c_save_expr (init.value);
1779 finish_init ();
1780 specs->typespec_kind = ctsk_typeof;
1781 specs->locations[cdw_typedef] = init_loc;
1782 specs->typedef_p = true;
1783 specs->type = init_type;
1784 if (vm_type)
1785 {
1786 bool maybe_const = true;
1787 tree type_expr = c_fully_fold (init.value, false,
1788 &maybe_const);
1789 specs->expr_const_operands &= maybe_const;
1790 if (specs->expr)
1791 specs->expr = build2 (COMPOUND_EXPR,
1792 TREE_TYPE (type_expr),
1793 specs->expr, type_expr);
1794 else
1795 specs->expr = type_expr;
1796 }
1797 d = start_decl (declarator, specs, true,
1798 chainon (postfix_attrs, all_prefix_attrs));
1799 if (!d)
1800 d = error_mark_node;
1801 if (omp_declare_simd_clauses.exists ()
1802 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1803 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1804 omp_declare_simd_clauses);
1805 }
1806 else
1807 {
1808 /* The declaration of the variable is in effect while
1809 its initializer is parsed. */
1810 d = start_decl (declarator, specs, true,
1811 chainon (postfix_attrs, all_prefix_attrs));
1812 if (!d)
1813 d = error_mark_node;
1814 if (omp_declare_simd_clauses.exists ()
1815 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1816 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1817 omp_declare_simd_clauses);
1818 start_init (d, asm_name, global_bindings_p ());
1819 init_loc = c_parser_peek_token (parser)->location;
1820 init = c_parser_initializer (parser);
1821 finish_init ();
1822 }
1823 if (oacc_routine_clauses)
1824 c_finish_oacc_routine (parser, d, oacc_routine_clauses,
1825 false, first, false);
1826 if (d != error_mark_node)
1827 {
1828 maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
1829 finish_decl (d, init_loc, init.value,
1830 init.original_type, asm_name);
1831 }
1832 }
1833 else
1834 {
1835 if (auto_type_p)
1836 {
1837 error_at (here,
1838 "%<__auto_type%> requires an initialized "
1839 "data declaration");
1840 c_parser_skip_to_end_of_block_or_statement (parser);
1841 return;
1842 }
1843 tree d = start_decl (declarator, specs, false,
1844 chainon (postfix_attrs,
1845 all_prefix_attrs));
1846 if (omp_declare_simd_clauses.exists ()
1847 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1848 {
1849 tree parms = NULL_TREE;
1850 if (d && TREE_CODE (d) == FUNCTION_DECL)
1851 {
1852 struct c_declarator *ce = declarator;
1853 while (ce != NULL)
1854 if (ce->kind == cdk_function)
1855 {
1856 parms = ce->u.arg_info->parms;
1857 break;
1858 }
1859 else
1860 ce = ce->declarator;
1861 }
1862 if (parms)
1863 temp_store_parm_decls (d, parms);
1864 c_finish_omp_declare_simd (parser, d, parms,
1865 omp_declare_simd_clauses);
1866 if (parms)
1867 temp_pop_parm_decls ();
1868 }
1869 if (oacc_routine_clauses)
1870 c_finish_oacc_routine (parser, d, oacc_routine_clauses,
1871 false, first, false);
1872 if (d)
1873 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1874 NULL_TREE, asm_name);
1875
1876 if (c_parser_next_token_is_keyword (parser, RID_IN))
1877 {
1878 if (d)
1879 *objc_foreach_object_declaration = d;
1880 else
1881 *objc_foreach_object_declaration = error_mark_node;
1882 }
1883 }
1884 if (c_parser_next_token_is (parser, CPP_COMMA))
1885 {
1886 if (auto_type_p)
1887 {
1888 error_at (here,
1889 "%<__auto_type%> may only be used with"
1890 " a single declarator");
1891 c_parser_skip_to_end_of_block_or_statement (parser);
1892 return;
1893 }
1894 c_parser_consume_token (parser);
1895 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1896 all_prefix_attrs = chainon (c_parser_attributes (parser),
1897 prefix_attrs);
1898 else
1899 all_prefix_attrs = prefix_attrs;
1900 continue;
1901 }
1902 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1903 {
1904 c_parser_consume_token (parser);
1905 return;
1906 }
1907 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1908 {
1909 /* This can only happen in Objective-C: we found the
1910 'in' that terminates the declaration inside an
1911 Objective-C foreach statement. Do not consume the
1912 token, so that the caller can use it to determine
1913 that this indeed is a foreach context. */
1914 return;
1915 }
1916 else
1917 {
1918 c_parser_error (parser, "expected %<,%> or %<;%>");
1919 c_parser_skip_to_end_of_block_or_statement (parser);
1920 return;
1921 }
1922 }
1923 else if (auto_type_p)
1924 {
1925 error_at (here,
1926 "%<__auto_type%> requires an initialized data declaration");
1927 c_parser_skip_to_end_of_block_or_statement (parser);
1928 return;
1929 }
1930 else if (!fndef_ok)
1931 {
1932 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1933 "%<asm%> or %<__attribute__%>");
1934 c_parser_skip_to_end_of_block_or_statement (parser);
1935 return;
1936 }
1937 /* Function definition (nested or otherwise). */
1938 if (nested)
1939 {
1940 pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
1941 c_push_function_context ();
1942 }
1943 if (!start_function (specs, declarator, all_prefix_attrs))
1944 {
1945 /* This can appear in many cases looking nothing like a
1946 function definition, so we don't give a more specific
1947 error suggesting there was one. */
1948 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1949 "or %<__attribute__%>");
1950 if (nested)
1951 c_pop_function_context ();
1952 break;
1953 }
1954
1955 if (DECL_DECLARED_INLINE_P (current_function_decl))
1956 tv = TV_PARSE_INLINE;
1957 else
1958 tv = TV_PARSE_FUNC;
1959 timevar_push (tv);
1960
1961 /* Parse old-style parameter declarations. ??? Attributes are
1962 not allowed to start declaration specifiers here because of a
1963 syntax conflict between a function declaration with attribute
1964 suffix and a function definition with an attribute prefix on
1965 first old-style parameter declaration. Following the old
1966 parser, they are not accepted on subsequent old-style
1967 parameter declarations either. However, there is no
1968 ambiguity after the first declaration, nor indeed on the
1969 first as long as we don't allow postfix attributes after a
1970 declarator with a nonempty identifier list in a definition;
1971 and postfix attributes have never been accepted here in
1972 function definitions either. */
1973 while (c_parser_next_token_is_not (parser, CPP_EOF)
1974 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1975 c_parser_declaration_or_fndef (parser, false, false, false,
1976 true, false, NULL, vNULL);
1977 store_parm_decls ();
1978 if (omp_declare_simd_clauses.exists ()
1979 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1980 c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
1981 omp_declare_simd_clauses);
1982 if (oacc_routine_clauses)
1983 c_finish_oacc_routine (parser, current_function_decl,
1984 oacc_routine_clauses, false, first, true);
1985 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1986 = c_parser_peek_token (parser)->location;
1987 fnbody = c_parser_compound_statement (parser);
1988 if (flag_cilkplus && contains_array_notation_expr (fnbody))
1989 fnbody = expand_array_notation_exprs (fnbody);
1990 if (nested)
1991 {
1992 tree decl = current_function_decl;
1993 /* Mark nested functions as needing static-chain initially.
1994 lower_nested_functions will recompute it but the
1995 DECL_STATIC_CHAIN flag is also used before that happens,
1996 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1997 DECL_STATIC_CHAIN (decl) = 1;
1998 add_stmt (fnbody);
1999 finish_function ();
2000 c_pop_function_context ();
2001 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
2002 }
2003 else
2004 {
2005 add_stmt (fnbody);
2006 finish_function ();
2007 }
2008
2009 timevar_pop (tv);
2010 break;
2011 }
2012 }
2013
2014 /* Parse an asm-definition (asm() outside a function body). This is a
2015 GNU extension.
2016
2017 asm-definition:
2018 simple-asm-expr ;
2019 */
2020
2021 static void
2022 c_parser_asm_definition (c_parser *parser)
2023 {
2024 tree asm_str = c_parser_simple_asm_expr (parser);
2025 if (asm_str)
2026 symtab->finalize_toplevel_asm (asm_str);
2027 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2028 }
2029
2030 /* Parse a static assertion (C11 6.7.10).
2031
2032 static_assert-declaration:
2033 static_assert-declaration-no-semi ;
2034 */
2035
2036 static void
2037 c_parser_static_assert_declaration (c_parser *parser)
2038 {
2039 c_parser_static_assert_declaration_no_semi (parser);
2040 if (parser->error
2041 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2042 c_parser_skip_to_end_of_block_or_statement (parser);
2043 }
2044
2045 /* Parse a static assertion (C11 6.7.10), without the trailing
2046 semicolon.
2047
2048 static_assert-declaration-no-semi:
2049 _Static_assert ( constant-expression , string-literal )
2050 */
2051
2052 static void
2053 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2054 {
2055 location_t assert_loc, value_loc;
2056 tree value;
2057 tree string;
2058
2059 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2060 assert_loc = c_parser_peek_token (parser)->location;
2061 if (flag_isoc99)
2062 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2063 "ISO C99 does not support %<_Static_assert%>");
2064 else
2065 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2066 "ISO C90 does not support %<_Static_assert%>");
2067 c_parser_consume_token (parser);
2068 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2069 return;
2070 value_loc = c_parser_peek_token (parser)->location;
2071 value = c_parser_expr_no_commas (parser, NULL).value;
2072 parser->lex_untranslated_string = true;
2073 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2074 {
2075 parser->lex_untranslated_string = false;
2076 return;
2077 }
2078 switch (c_parser_peek_token (parser)->type)
2079 {
2080 case CPP_STRING:
2081 case CPP_STRING16:
2082 case CPP_STRING32:
2083 case CPP_WSTRING:
2084 case CPP_UTF8STRING:
2085 string = c_parser_peek_token (parser)->value;
2086 c_parser_consume_token (parser);
2087 parser->lex_untranslated_string = false;
2088 break;
2089 default:
2090 c_parser_error (parser, "expected string literal");
2091 parser->lex_untranslated_string = false;
2092 return;
2093 }
2094 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2095
2096 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2097 {
2098 error_at (value_loc, "expression in static assertion is not an integer");
2099 return;
2100 }
2101 if (TREE_CODE (value) != INTEGER_CST)
2102 {
2103 value = c_fully_fold (value, false, NULL);
2104 /* Strip no-op conversions. */
2105 STRIP_TYPE_NOPS (value);
2106 if (TREE_CODE (value) == INTEGER_CST)
2107 pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2108 "is not an integer constant expression");
2109 }
2110 if (TREE_CODE (value) != INTEGER_CST)
2111 {
2112 error_at (value_loc, "expression in static assertion is not constant");
2113 return;
2114 }
2115 constant_expression_warning (value);
2116 if (integer_zerop (value))
2117 error_at (assert_loc, "static assertion failed: %E", string);
2118 }
2119
2120 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2121 6.7), adding them to SPECS (which may already include some).
2122 Storage class specifiers are accepted iff SCSPEC_OK; type
2123 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2124 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2125 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2126
2127 declaration-specifiers:
2128 storage-class-specifier declaration-specifiers[opt]
2129 type-specifier declaration-specifiers[opt]
2130 type-qualifier declaration-specifiers[opt]
2131 function-specifier declaration-specifiers[opt]
2132 alignment-specifier declaration-specifiers[opt]
2133
2134 Function specifiers (inline) are from C99, and are currently
2135 handled as storage class specifiers, as is __thread. Alignment
2136 specifiers are from C11.
2137
2138 C90 6.5.1, C99 6.7.1:
2139 storage-class-specifier:
2140 typedef
2141 extern
2142 static
2143 auto
2144 register
2145 _Thread_local
2146
2147 (_Thread_local is new in C11.)
2148
2149 C99 6.7.4:
2150 function-specifier:
2151 inline
2152 _Noreturn
2153
2154 (_Noreturn is new in C11.)
2155
2156 C90 6.5.2, C99 6.7.2:
2157 type-specifier:
2158 void
2159 char
2160 short
2161 int
2162 long
2163 float
2164 double
2165 signed
2166 unsigned
2167 _Bool
2168 _Complex
2169 [_Imaginary removed in C99 TC2]
2170 struct-or-union-specifier
2171 enum-specifier
2172 typedef-name
2173 atomic-type-specifier
2174
2175 (_Bool and _Complex are new in C99.)
2176 (atomic-type-specifier is new in C11.)
2177
2178 C90 6.5.3, C99 6.7.3:
2179
2180 type-qualifier:
2181 const
2182 restrict
2183 volatile
2184 address-space-qualifier
2185 _Atomic
2186
2187 (restrict is new in C99.)
2188 (_Atomic is new in C11.)
2189
2190 GNU extensions:
2191
2192 declaration-specifiers:
2193 attributes declaration-specifiers[opt]
2194
2195 type-qualifier:
2196 address-space
2197
2198 address-space:
2199 identifier recognized by the target
2200
2201 storage-class-specifier:
2202 __thread
2203
2204 type-specifier:
2205 typeof-specifier
2206 __auto_type
2207 __intN
2208 _Decimal32
2209 _Decimal64
2210 _Decimal128
2211 _Fract
2212 _Accum
2213 _Sat
2214
2215 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2216 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2217
2218 atomic-type-specifier
2219 _Atomic ( type-name )
2220
2221 Objective-C:
2222
2223 type-specifier:
2224 class-name objc-protocol-refs[opt]
2225 typedef-name objc-protocol-refs
2226 objc-protocol-refs
2227 */
2228
2229 static void
2230 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2231 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2232 bool alignspec_ok, bool auto_type_ok,
2233 enum c_lookahead_kind la)
2234 {
2235 bool attrs_ok = start_attr_ok;
2236 bool seen_type = specs->typespec_kind != ctsk_none;
2237
2238 if (!typespec_ok)
2239 gcc_assert (la == cla_prefer_id);
2240
2241 while (c_parser_next_token_is (parser, CPP_NAME)
2242 || c_parser_next_token_is (parser, CPP_KEYWORD)
2243 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2244 {
2245 struct c_typespec t;
2246 tree attrs;
2247 tree align;
2248 location_t loc = c_parser_peek_token (parser)->location;
2249
2250 /* If we cannot accept a type, exit if the next token must start
2251 one. Also, if we already have seen a tagged definition,
2252 a typename would be an error anyway and likely the user
2253 has simply forgotten a semicolon, so we exit. */
2254 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2255 && c_parser_next_tokens_start_typename (parser, la)
2256 && !c_parser_next_token_is_qualifier (parser))
2257 break;
2258
2259 if (c_parser_next_token_is (parser, CPP_NAME))
2260 {
2261 c_token *name_token = c_parser_peek_token (parser);
2262 tree value = name_token->value;
2263 c_id_kind kind = name_token->id_kind;
2264
2265 if (kind == C_ID_ADDRSPACE)
2266 {
2267 addr_space_t as
2268 = name_token->keyword - RID_FIRST_ADDR_SPACE;
2269 declspecs_add_addrspace (name_token->location, specs, as);
2270 c_parser_consume_token (parser);
2271 attrs_ok = true;
2272 continue;
2273 }
2274
2275 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2276
2277 /* If we cannot accept a type, and the next token must start one,
2278 exit. Do the same if we already have seen a tagged definition,
2279 since it would be an error anyway and likely the user has simply
2280 forgotten a semicolon. */
2281 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2282 break;
2283
2284 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2285 a C_ID_CLASSNAME. */
2286 c_parser_consume_token (parser);
2287 seen_type = true;
2288 attrs_ok = true;
2289 if (kind == C_ID_ID)
2290 {
2291 error_at (loc, "unknown type name %qE", value);
2292 t.kind = ctsk_typedef;
2293 t.spec = error_mark_node;
2294 }
2295 else if (kind == C_ID_TYPENAME
2296 && (!c_dialect_objc ()
2297 || c_parser_next_token_is_not (parser, CPP_LESS)))
2298 {
2299 t.kind = ctsk_typedef;
2300 /* For a typedef name, record the meaning, not the name.
2301 In case of 'foo foo, bar;'. */
2302 t.spec = lookup_name (value);
2303 }
2304 else
2305 {
2306 tree proto = NULL_TREE;
2307 gcc_assert (c_dialect_objc ());
2308 t.kind = ctsk_objc;
2309 if (c_parser_next_token_is (parser, CPP_LESS))
2310 proto = c_parser_objc_protocol_refs (parser);
2311 t.spec = objc_get_protocol_qualified_type (value, proto);
2312 }
2313 t.expr = NULL_TREE;
2314 t.expr_const_operands = true;
2315 declspecs_add_type (name_token->location, specs, t);
2316 continue;
2317 }
2318 if (c_parser_next_token_is (parser, CPP_LESS))
2319 {
2320 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2321 nisse@lysator.liu.se. */
2322 tree proto;
2323 gcc_assert (c_dialect_objc ());
2324 if (!typespec_ok || seen_type)
2325 break;
2326 proto = c_parser_objc_protocol_refs (parser);
2327 t.kind = ctsk_objc;
2328 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2329 t.expr = NULL_TREE;
2330 t.expr_const_operands = true;
2331 declspecs_add_type (loc, specs, t);
2332 continue;
2333 }
2334 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2335 switch (c_parser_peek_token (parser)->keyword)
2336 {
2337 case RID_STATIC:
2338 case RID_EXTERN:
2339 case RID_REGISTER:
2340 case RID_TYPEDEF:
2341 case RID_INLINE:
2342 case RID_NORETURN:
2343 case RID_AUTO:
2344 case RID_THREAD:
2345 if (!scspec_ok)
2346 goto out;
2347 attrs_ok = true;
2348 /* TODO: Distinguish between function specifiers (inline, noreturn)
2349 and storage class specifiers, either here or in
2350 declspecs_add_scspec. */
2351 declspecs_add_scspec (loc, specs,
2352 c_parser_peek_token (parser)->value);
2353 c_parser_consume_token (parser);
2354 break;
2355 case RID_AUTO_TYPE:
2356 if (!auto_type_ok)
2357 goto out;
2358 /* Fall through. */
2359 case RID_UNSIGNED:
2360 case RID_LONG:
2361 case RID_SHORT:
2362 case RID_SIGNED:
2363 case RID_COMPLEX:
2364 case RID_INT:
2365 case RID_CHAR:
2366 case RID_FLOAT:
2367 case RID_DOUBLE:
2368 case RID_VOID:
2369 case RID_DFLOAT32:
2370 case RID_DFLOAT64:
2371 case RID_DFLOAT128:
2372 case RID_BOOL:
2373 case RID_FRACT:
2374 case RID_ACCUM:
2375 case RID_SAT:
2376 case RID_INT_N_0:
2377 case RID_INT_N_1:
2378 case RID_INT_N_2:
2379 case RID_INT_N_3:
2380 if (!typespec_ok)
2381 goto out;
2382 attrs_ok = true;
2383 seen_type = true;
2384 if (c_dialect_objc ())
2385 parser->objc_need_raw_identifier = true;
2386 t.kind = ctsk_resword;
2387 t.spec = c_parser_peek_token (parser)->value;
2388 t.expr = NULL_TREE;
2389 t.expr_const_operands = true;
2390 declspecs_add_type (loc, specs, t);
2391 c_parser_consume_token (parser);
2392 break;
2393 case RID_ENUM:
2394 if (!typespec_ok)
2395 goto out;
2396 attrs_ok = true;
2397 seen_type = true;
2398 t = c_parser_enum_specifier (parser);
2399 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2400 declspecs_add_type (loc, specs, t);
2401 break;
2402 case RID_STRUCT:
2403 case RID_UNION:
2404 if (!typespec_ok)
2405 goto out;
2406 attrs_ok = true;
2407 seen_type = true;
2408 t = c_parser_struct_or_union_specifier (parser);
2409 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2410 declspecs_add_type (loc, specs, t);
2411 break;
2412 case RID_TYPEOF:
2413 /* ??? The old parser rejected typeof after other type
2414 specifiers, but is a syntax error the best way of
2415 handling this? */
2416 if (!typespec_ok || seen_type)
2417 goto out;
2418 attrs_ok = true;
2419 seen_type = true;
2420 t = c_parser_typeof_specifier (parser);
2421 declspecs_add_type (loc, specs, t);
2422 break;
2423 case RID_ATOMIC:
2424 /* C parser handling of Objective-C constructs needs
2425 checking for correct lvalue-to-rvalue conversions, and
2426 the code in build_modify_expr handling various
2427 Objective-C cases, and that in build_unary_op handling
2428 Objective-C cases for increment / decrement, also needs
2429 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2430 and objc_types_are_equivalent may also need updates. */
2431 if (c_dialect_objc ())
2432 sorry ("%<_Atomic%> in Objective-C");
2433 /* C parser handling of OpenMP constructs needs checking for
2434 correct lvalue-to-rvalue conversions. */
2435 if (flag_openmp)
2436 sorry ("%<_Atomic%> with OpenMP");
2437 if (flag_isoc99)
2438 pedwarn_c99 (loc, OPT_Wpedantic,
2439 "ISO C99 does not support the %<_Atomic%> qualifier");
2440 else
2441 pedwarn_c99 (loc, OPT_Wpedantic,
2442 "ISO C90 does not support the %<_Atomic%> qualifier");
2443 attrs_ok = true;
2444 tree value;
2445 value = c_parser_peek_token (parser)->value;
2446 c_parser_consume_token (parser);
2447 if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2448 {
2449 /* _Atomic ( type-name ). */
2450 seen_type = true;
2451 c_parser_consume_token (parser);
2452 struct c_type_name *type = c_parser_type_name (parser);
2453 t.kind = ctsk_typeof;
2454 t.spec = error_mark_node;
2455 t.expr = NULL_TREE;
2456 t.expr_const_operands = true;
2457 if (type != NULL)
2458 t.spec = groktypename (type, &t.expr,
2459 &t.expr_const_operands);
2460 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2461 "expected %<)%>");
2462 if (t.spec != error_mark_node)
2463 {
2464 if (TREE_CODE (t.spec) == ARRAY_TYPE)
2465 error_at (loc, "%<_Atomic%>-qualified array type");
2466 else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2467 error_at (loc, "%<_Atomic%>-qualified function type");
2468 else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2469 error_at (loc, "%<_Atomic%> applied to a qualified type");
2470 else
2471 t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2472 }
2473 declspecs_add_type (loc, specs, t);
2474 }
2475 else
2476 declspecs_add_qual (loc, specs, value);
2477 break;
2478 case RID_CONST:
2479 case RID_VOLATILE:
2480 case RID_RESTRICT:
2481 attrs_ok = true;
2482 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2483 c_parser_consume_token (parser);
2484 break;
2485 case RID_ATTRIBUTE:
2486 if (!attrs_ok)
2487 goto out;
2488 attrs = c_parser_attributes (parser);
2489 declspecs_add_attrs (loc, specs, attrs);
2490 break;
2491 case RID_ALIGNAS:
2492 if (!alignspec_ok)
2493 goto out;
2494 align = c_parser_alignas_specifier (parser);
2495 declspecs_add_alignas (loc, specs, align);
2496 break;
2497 default:
2498 goto out;
2499 }
2500 }
2501 out: ;
2502 }
2503
2504 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2505
2506 enum-specifier:
2507 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2508 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2509 enum attributes[opt] identifier
2510
2511 The form with trailing comma is new in C99. The forms with
2512 attributes are GNU extensions. In GNU C, we accept any expression
2513 without commas in the syntax (assignment expressions, not just
2514 conditional expressions); assignment expressions will be diagnosed
2515 as non-constant.
2516
2517 enumerator-list:
2518 enumerator
2519 enumerator-list , enumerator
2520
2521 enumerator:
2522 enumeration-constant
2523 enumeration-constant = constant-expression
2524
2525 GNU Extensions:
2526
2527 enumerator:
2528 enumeration-constant attributes[opt]
2529 enumeration-constant attributes[opt] = constant-expression
2530
2531 */
2532
2533 static struct c_typespec
2534 c_parser_enum_specifier (c_parser *parser)
2535 {
2536 struct c_typespec ret;
2537 tree attrs;
2538 tree ident = NULL_TREE;
2539 location_t enum_loc;
2540 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2541 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2542 enum_loc = c_parser_peek_token (parser)->location;
2543 c_parser_consume_token (parser);
2544 attrs = c_parser_attributes (parser);
2545 enum_loc = c_parser_peek_token (parser)->location;
2546 /* Set the location in case we create a decl now. */
2547 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2548 if (c_parser_next_token_is (parser, CPP_NAME))
2549 {
2550 ident = c_parser_peek_token (parser)->value;
2551 ident_loc = c_parser_peek_token (parser)->location;
2552 enum_loc = ident_loc;
2553 c_parser_consume_token (parser);
2554 }
2555 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2556 {
2557 /* Parse an enum definition. */
2558 struct c_enum_contents the_enum;
2559 tree type;
2560 tree postfix_attrs;
2561 /* We chain the enumerators in reverse order, then put them in
2562 forward order at the end. */
2563 tree values;
2564 timevar_push (TV_PARSE_ENUM);
2565 type = start_enum (enum_loc, &the_enum, ident);
2566 values = NULL_TREE;
2567 c_parser_consume_token (parser);
2568 while (true)
2569 {
2570 tree enum_id;
2571 tree enum_value;
2572 tree enum_decl;
2573 bool seen_comma;
2574 c_token *token;
2575 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2576 location_t decl_loc, value_loc;
2577 if (c_parser_next_token_is_not (parser, CPP_NAME))
2578 {
2579 /* Give a nicer error for "enum {}". */
2580 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2581 && !parser->error)
2582 {
2583 error_at (c_parser_peek_token (parser)->location,
2584 "empty enum is invalid");
2585 parser->error = true;
2586 }
2587 else
2588 c_parser_error (parser, "expected identifier");
2589 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2590 values = error_mark_node;
2591 break;
2592 }
2593 token = c_parser_peek_token (parser);
2594 enum_id = token->value;
2595 /* Set the location in case we create a decl now. */
2596 c_parser_set_source_position_from_token (token);
2597 decl_loc = value_loc = token->location;
2598 c_parser_consume_token (parser);
2599 /* Parse any specified attributes. */
2600 tree enum_attrs = c_parser_attributes (parser);
2601 if (c_parser_next_token_is (parser, CPP_EQ))
2602 {
2603 c_parser_consume_token (parser);
2604 value_loc = c_parser_peek_token (parser)->location;
2605 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2606 }
2607 else
2608 enum_value = NULL_TREE;
2609 enum_decl = build_enumerator (decl_loc, value_loc,
2610 &the_enum, enum_id, enum_value);
2611 if (enum_attrs)
2612 decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0);
2613 TREE_CHAIN (enum_decl) = values;
2614 values = enum_decl;
2615 seen_comma = false;
2616 if (c_parser_next_token_is (parser, CPP_COMMA))
2617 {
2618 comma_loc = c_parser_peek_token (parser)->location;
2619 seen_comma = true;
2620 c_parser_consume_token (parser);
2621 }
2622 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2623 {
2624 if (seen_comma)
2625 pedwarn_c90 (comma_loc, OPT_Wpedantic,
2626 "comma at end of enumerator list");
2627 c_parser_consume_token (parser);
2628 break;
2629 }
2630 if (!seen_comma)
2631 {
2632 c_parser_error (parser, "expected %<,%> or %<}%>");
2633 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2634 values = error_mark_node;
2635 break;
2636 }
2637 }
2638 postfix_attrs = c_parser_attributes (parser);
2639 ret.spec = finish_enum (type, nreverse (values),
2640 chainon (attrs, postfix_attrs));
2641 ret.kind = ctsk_tagdef;
2642 ret.expr = NULL_TREE;
2643 ret.expr_const_operands = true;
2644 timevar_pop (TV_PARSE_ENUM);
2645 return ret;
2646 }
2647 else if (!ident)
2648 {
2649 c_parser_error (parser, "expected %<{%>");
2650 ret.spec = error_mark_node;
2651 ret.kind = ctsk_tagref;
2652 ret.expr = NULL_TREE;
2653 ret.expr_const_operands = true;
2654 return ret;
2655 }
2656 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2657 /* In ISO C, enumerated types can be referred to only if already
2658 defined. */
2659 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2660 {
2661 gcc_assert (ident);
2662 pedwarn (enum_loc, OPT_Wpedantic,
2663 "ISO C forbids forward references to %<enum%> types");
2664 }
2665 return ret;
2666 }
2667
2668 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2669
2670 struct-or-union-specifier:
2671 struct-or-union attributes[opt] identifier[opt]
2672 { struct-contents } attributes[opt]
2673 struct-or-union attributes[opt] identifier
2674
2675 struct-contents:
2676 struct-declaration-list
2677
2678 struct-declaration-list:
2679 struct-declaration ;
2680 struct-declaration-list struct-declaration ;
2681
2682 GNU extensions:
2683
2684 struct-contents:
2685 empty
2686 struct-declaration
2687 struct-declaration-list struct-declaration
2688
2689 struct-declaration-list:
2690 struct-declaration-list ;
2691 ;
2692
2693 (Note that in the syntax here, unlike that in ISO C, the semicolons
2694 are included here rather than in struct-declaration, in order to
2695 describe the syntax with extra semicolons and missing semicolon at
2696 end.)
2697
2698 Objective-C:
2699
2700 struct-declaration-list:
2701 @defs ( class-name )
2702
2703 (Note this does not include a trailing semicolon, but can be
2704 followed by further declarations, and gets a pedwarn-if-pedantic
2705 when followed by a semicolon.) */
2706
2707 static struct c_typespec
2708 c_parser_struct_or_union_specifier (c_parser *parser)
2709 {
2710 struct c_typespec ret;
2711 tree attrs;
2712 tree ident = NULL_TREE;
2713 location_t struct_loc;
2714 location_t ident_loc = UNKNOWN_LOCATION;
2715 enum tree_code code;
2716 switch (c_parser_peek_token (parser)->keyword)
2717 {
2718 case RID_STRUCT:
2719 code = RECORD_TYPE;
2720 break;
2721 case RID_UNION:
2722 code = UNION_TYPE;
2723 break;
2724 default:
2725 gcc_unreachable ();
2726 }
2727 struct_loc = c_parser_peek_token (parser)->location;
2728 c_parser_consume_token (parser);
2729 attrs = c_parser_attributes (parser);
2730
2731 /* Set the location in case we create a decl now. */
2732 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2733
2734 if (c_parser_next_token_is (parser, CPP_NAME))
2735 {
2736 ident = c_parser_peek_token (parser)->value;
2737 ident_loc = c_parser_peek_token (parser)->location;
2738 struct_loc = ident_loc;
2739 c_parser_consume_token (parser);
2740 }
2741 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2742 {
2743 /* Parse a struct or union definition. Start the scope of the
2744 tag before parsing components. */
2745 struct c_struct_parse_info *struct_info;
2746 tree type = start_struct (struct_loc, code, ident, &struct_info);
2747 tree postfix_attrs;
2748 /* We chain the components in reverse order, then put them in
2749 forward order at the end. Each struct-declaration may
2750 declare multiple components (comma-separated), so we must use
2751 chainon to join them, although when parsing each
2752 struct-declaration we can use TREE_CHAIN directly.
2753
2754 The theory behind all this is that there will be more
2755 semicolon separated fields than comma separated fields, and
2756 so we'll be minimizing the number of node traversals required
2757 by chainon. */
2758 tree contents;
2759 timevar_push (TV_PARSE_STRUCT);
2760 contents = NULL_TREE;
2761 c_parser_consume_token (parser);
2762 /* Handle the Objective-C @defs construct,
2763 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2764 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2765 {
2766 tree name;
2767 gcc_assert (c_dialect_objc ());
2768 c_parser_consume_token (parser);
2769 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2770 goto end_at_defs;
2771 if (c_parser_next_token_is (parser, CPP_NAME)
2772 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2773 {
2774 name = c_parser_peek_token (parser)->value;
2775 c_parser_consume_token (parser);
2776 }
2777 else
2778 {
2779 c_parser_error (parser, "expected class name");
2780 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2781 goto end_at_defs;
2782 }
2783 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2784 "expected %<)%>");
2785 contents = nreverse (objc_get_class_ivars (name));
2786 }
2787 end_at_defs:
2788 /* Parse the struct-declarations and semicolons. Problems with
2789 semicolons are diagnosed here; empty structures are diagnosed
2790 elsewhere. */
2791 while (true)
2792 {
2793 tree decls;
2794 /* Parse any stray semicolon. */
2795 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2796 {
2797 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2798 "extra semicolon in struct or union specified");
2799 c_parser_consume_token (parser);
2800 continue;
2801 }
2802 /* Stop if at the end of the struct or union contents. */
2803 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2804 {
2805 c_parser_consume_token (parser);
2806 break;
2807 }
2808 /* Accept #pragmas at struct scope. */
2809 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2810 {
2811 c_parser_pragma (parser, pragma_struct);
2812 continue;
2813 }
2814 /* Parse some comma-separated declarations, but not the
2815 trailing semicolon if any. */
2816 decls = c_parser_struct_declaration (parser);
2817 contents = chainon (decls, contents);
2818 /* If no semicolon follows, either we have a parse error or
2819 are at the end of the struct or union and should
2820 pedwarn. */
2821 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2822 c_parser_consume_token (parser);
2823 else
2824 {
2825 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2826 pedwarn (c_parser_peek_token (parser)->location, 0,
2827 "no semicolon at end of struct or union");
2828 else if (parser->error
2829 || !c_parser_next_token_starts_declspecs (parser))
2830 {
2831 c_parser_error (parser, "expected %<;%>");
2832 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2833 break;
2834 }
2835
2836 /* If we come here, we have already emitted an error
2837 for an expected `;', identifier or `(', and we also
2838 recovered already. Go on with the next field. */
2839 }
2840 }
2841 postfix_attrs = c_parser_attributes (parser);
2842 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2843 chainon (attrs, postfix_attrs), struct_info);
2844 ret.kind = ctsk_tagdef;
2845 ret.expr = NULL_TREE;
2846 ret.expr_const_operands = true;
2847 timevar_pop (TV_PARSE_STRUCT);
2848 return ret;
2849 }
2850 else if (!ident)
2851 {
2852 c_parser_error (parser, "expected %<{%>");
2853 ret.spec = error_mark_node;
2854 ret.kind = ctsk_tagref;
2855 ret.expr = NULL_TREE;
2856 ret.expr_const_operands = true;
2857 return ret;
2858 }
2859 ret = parser_xref_tag (ident_loc, code, ident);
2860 return ret;
2861 }
2862
2863 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2864 the trailing semicolon.
2865
2866 struct-declaration:
2867 specifier-qualifier-list struct-declarator-list
2868 static_assert-declaration-no-semi
2869
2870 specifier-qualifier-list:
2871 type-specifier specifier-qualifier-list[opt]
2872 type-qualifier specifier-qualifier-list[opt]
2873 attributes specifier-qualifier-list[opt]
2874
2875 struct-declarator-list:
2876 struct-declarator
2877 struct-declarator-list , attributes[opt] struct-declarator
2878
2879 struct-declarator:
2880 declarator attributes[opt]
2881 declarator[opt] : constant-expression attributes[opt]
2882
2883 GNU extensions:
2884
2885 struct-declaration:
2886 __extension__ struct-declaration
2887 specifier-qualifier-list
2888
2889 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2890 of attributes where shown is a GNU extension. In GNU C, we accept
2891 any expression without commas in the syntax (assignment
2892 expressions, not just conditional expressions); assignment
2893 expressions will be diagnosed as non-constant. */
2894
2895 static tree
2896 c_parser_struct_declaration (c_parser *parser)
2897 {
2898 struct c_declspecs *specs;
2899 tree prefix_attrs;
2900 tree all_prefix_attrs;
2901 tree decls;
2902 location_t decl_loc;
2903 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2904 {
2905 int ext;
2906 tree decl;
2907 ext = disable_extension_diagnostics ();
2908 c_parser_consume_token (parser);
2909 decl = c_parser_struct_declaration (parser);
2910 restore_extension_diagnostics (ext);
2911 return decl;
2912 }
2913 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2914 {
2915 c_parser_static_assert_declaration_no_semi (parser);
2916 return NULL_TREE;
2917 }
2918 specs = build_null_declspecs ();
2919 decl_loc = c_parser_peek_token (parser)->location;
2920 /* Strictly by the standard, we shouldn't allow _Alignas here,
2921 but it appears to have been intended to allow it there, so
2922 we're keeping it as it is until WG14 reaches a conclusion
2923 of N1731.
2924 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2925 c_parser_declspecs (parser, specs, false, true, true,
2926 true, false, cla_nonabstract_decl);
2927 if (parser->error)
2928 return NULL_TREE;
2929 if (!specs->declspecs_seen_p)
2930 {
2931 c_parser_error (parser, "expected specifier-qualifier-list");
2932 return NULL_TREE;
2933 }
2934 finish_declspecs (specs);
2935 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2936 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2937 {
2938 tree ret;
2939 if (specs->typespec_kind == ctsk_none)
2940 {
2941 pedwarn (decl_loc, OPT_Wpedantic,
2942 "ISO C forbids member declarations with no members");
2943 shadow_tag_warned (specs, pedantic);
2944 ret = NULL_TREE;
2945 }
2946 else
2947 {
2948 /* Support for unnamed structs or unions as members of
2949 structs or unions (which is [a] useful and [b] supports
2950 MS P-SDK). */
2951 tree attrs = NULL;
2952
2953 ret = grokfield (c_parser_peek_token (parser)->location,
2954 build_id_declarator (NULL_TREE), specs,
2955 NULL_TREE, &attrs);
2956 if (ret)
2957 decl_attributes (&ret, attrs, 0);
2958 }
2959 return ret;
2960 }
2961
2962 /* Provide better error recovery. Note that a type name here is valid,
2963 and will be treated as a field name. */
2964 if (specs->typespec_kind == ctsk_tagdef
2965 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2966 && c_parser_next_token_starts_declspecs (parser)
2967 && !c_parser_next_token_is (parser, CPP_NAME))
2968 {
2969 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2970 parser->error = false;
2971 return NULL_TREE;
2972 }
2973
2974 pending_xref_error ();
2975 prefix_attrs = specs->attrs;
2976 all_prefix_attrs = prefix_attrs;
2977 specs->attrs = NULL_TREE;
2978 decls = NULL_TREE;
2979 while (true)
2980 {
2981 /* Declaring one or more declarators or un-named bit-fields. */
2982 struct c_declarator *declarator;
2983 bool dummy = false;
2984 if (c_parser_next_token_is (parser, CPP_COLON))
2985 declarator = build_id_declarator (NULL_TREE);
2986 else
2987 declarator = c_parser_declarator (parser,
2988 specs->typespec_kind != ctsk_none,
2989 C_DTR_NORMAL, &dummy);
2990 if (declarator == NULL)
2991 {
2992 c_parser_skip_to_end_of_block_or_statement (parser);
2993 break;
2994 }
2995 if (c_parser_next_token_is (parser, CPP_COLON)
2996 || c_parser_next_token_is (parser, CPP_COMMA)
2997 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2998 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2999 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3000 {
3001 tree postfix_attrs = NULL_TREE;
3002 tree width = NULL_TREE;
3003 tree d;
3004 if (c_parser_next_token_is (parser, CPP_COLON))
3005 {
3006 c_parser_consume_token (parser);
3007 width = c_parser_expr_no_commas (parser, NULL).value;
3008 }
3009 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3010 postfix_attrs = c_parser_attributes (parser);
3011 d = grokfield (c_parser_peek_token (parser)->location,
3012 declarator, specs, width, &all_prefix_attrs);
3013 decl_attributes (&d, chainon (postfix_attrs,
3014 all_prefix_attrs), 0);
3015 DECL_CHAIN (d) = decls;
3016 decls = d;
3017 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3018 all_prefix_attrs = chainon (c_parser_attributes (parser),
3019 prefix_attrs);
3020 else
3021 all_prefix_attrs = prefix_attrs;
3022 if (c_parser_next_token_is (parser, CPP_COMMA))
3023 c_parser_consume_token (parser);
3024 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3025 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3026 {
3027 /* Semicolon consumed in caller. */
3028 break;
3029 }
3030 else
3031 {
3032 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3033 break;
3034 }
3035 }
3036 else
3037 {
3038 c_parser_error (parser,
3039 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3040 "%<__attribute__%>");
3041 break;
3042 }
3043 }
3044 return decls;
3045 }
3046
3047 /* Parse a typeof specifier (a GNU extension).
3048
3049 typeof-specifier:
3050 typeof ( expression )
3051 typeof ( type-name )
3052 */
3053
3054 static struct c_typespec
3055 c_parser_typeof_specifier (c_parser *parser)
3056 {
3057 struct c_typespec ret;
3058 ret.kind = ctsk_typeof;
3059 ret.spec = error_mark_node;
3060 ret.expr = NULL_TREE;
3061 ret.expr_const_operands = true;
3062 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3063 c_parser_consume_token (parser);
3064 c_inhibit_evaluation_warnings++;
3065 in_typeof++;
3066 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3067 {
3068 c_inhibit_evaluation_warnings--;
3069 in_typeof--;
3070 return ret;
3071 }
3072 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3073 {
3074 struct c_type_name *type = c_parser_type_name (parser);
3075 c_inhibit_evaluation_warnings--;
3076 in_typeof--;
3077 if (type != NULL)
3078 {
3079 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3080 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3081 }
3082 }
3083 else
3084 {
3085 bool was_vm;
3086 location_t here = c_parser_peek_token (parser)->location;
3087 struct c_expr expr = c_parser_expression (parser);
3088 c_inhibit_evaluation_warnings--;
3089 in_typeof--;
3090 if (TREE_CODE (expr.value) == COMPONENT_REF
3091 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3092 error_at (here, "%<typeof%> applied to a bit-field");
3093 mark_exp_read (expr.value);
3094 ret.spec = TREE_TYPE (expr.value);
3095 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3096 /* This is returned with the type so that when the type is
3097 evaluated, this can be evaluated. */
3098 if (was_vm)
3099 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3100 pop_maybe_used (was_vm);
3101 /* For use in macros such as those in <stdatomic.h>, remove all
3102 qualifiers from atomic types. (const can be an issue for more macros
3103 using typeof than just the <stdatomic.h> ones.) */
3104 if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3105 ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3106 }
3107 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3108 return ret;
3109 }
3110
3111 /* Parse an alignment-specifier.
3112
3113 C11 6.7.5:
3114
3115 alignment-specifier:
3116 _Alignas ( type-name )
3117 _Alignas ( constant-expression )
3118 */
3119
3120 static tree
3121 c_parser_alignas_specifier (c_parser * parser)
3122 {
3123 tree ret = error_mark_node;
3124 location_t loc = c_parser_peek_token (parser)->location;
3125 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3126 c_parser_consume_token (parser);
3127 if (flag_isoc99)
3128 pedwarn_c99 (loc, OPT_Wpedantic,
3129 "ISO C99 does not support %<_Alignas%>");
3130 else
3131 pedwarn_c99 (loc, OPT_Wpedantic,
3132 "ISO C90 does not support %<_Alignas%>");
3133 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3134 return ret;
3135 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3136 {
3137 struct c_type_name *type = c_parser_type_name (parser);
3138 if (type != NULL)
3139 ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3140 false, true, 1);
3141 }
3142 else
3143 ret = c_parser_expr_no_commas (parser, NULL).value;
3144 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3145 return ret;
3146 }
3147
3148 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3149 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3150 be redeclared; otherwise it may not. KIND indicates which kind of
3151 declarator is wanted. Returns a valid declarator except in the
3152 case of a syntax error in which case NULL is returned. *SEEN_ID is
3153 set to true if an identifier being declared is seen; this is used
3154 to diagnose bad forms of abstract array declarators and to
3155 determine whether an identifier list is syntactically permitted.
3156
3157 declarator:
3158 pointer[opt] direct-declarator
3159
3160 direct-declarator:
3161 identifier
3162 ( attributes[opt] declarator )
3163 direct-declarator array-declarator
3164 direct-declarator ( parameter-type-list )
3165 direct-declarator ( identifier-list[opt] )
3166
3167 pointer:
3168 * type-qualifier-list[opt]
3169 * type-qualifier-list[opt] pointer
3170
3171 type-qualifier-list:
3172 type-qualifier
3173 attributes
3174 type-qualifier-list type-qualifier
3175 type-qualifier-list attributes
3176
3177 array-declarator:
3178 [ type-qualifier-list[opt] assignment-expression[opt] ]
3179 [ static type-qualifier-list[opt] assignment-expression ]
3180 [ type-qualifier-list static assignment-expression ]
3181 [ type-qualifier-list[opt] * ]
3182
3183 parameter-type-list:
3184 parameter-list
3185 parameter-list , ...
3186
3187 parameter-list:
3188 parameter-declaration
3189 parameter-list , parameter-declaration
3190
3191 parameter-declaration:
3192 declaration-specifiers declarator attributes[opt]
3193 declaration-specifiers abstract-declarator[opt] attributes[opt]
3194
3195 identifier-list:
3196 identifier
3197 identifier-list , identifier
3198
3199 abstract-declarator:
3200 pointer
3201 pointer[opt] direct-abstract-declarator
3202
3203 direct-abstract-declarator:
3204 ( attributes[opt] abstract-declarator )
3205 direct-abstract-declarator[opt] array-declarator
3206 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3207
3208 GNU extensions:
3209
3210 direct-declarator:
3211 direct-declarator ( parameter-forward-declarations
3212 parameter-type-list[opt] )
3213
3214 direct-abstract-declarator:
3215 direct-abstract-declarator[opt] ( parameter-forward-declarations
3216 parameter-type-list[opt] )
3217
3218 parameter-forward-declarations:
3219 parameter-list ;
3220 parameter-forward-declarations parameter-list ;
3221
3222 The uses of attributes shown above are GNU extensions.
3223
3224 Some forms of array declarator are not included in C99 in the
3225 syntax for abstract declarators; these are disallowed elsewhere.
3226 This may be a defect (DR#289).
3227
3228 This function also accepts an omitted abstract declarator as being
3229 an abstract declarator, although not part of the formal syntax. */
3230
3231 static struct c_declarator *
3232 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3233 bool *seen_id)
3234 {
3235 /* Parse any initial pointer part. */
3236 if (c_parser_next_token_is (parser, CPP_MULT))
3237 {
3238 struct c_declspecs *quals_attrs = build_null_declspecs ();
3239 struct c_declarator *inner;
3240 c_parser_consume_token (parser);
3241 c_parser_declspecs (parser, quals_attrs, false, false, true,
3242 false, false, cla_prefer_id);
3243 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3244 if (inner == NULL)
3245 return NULL;
3246 else
3247 return make_pointer_declarator (quals_attrs, inner);
3248 }
3249 /* Now we have a direct declarator, direct abstract declarator or
3250 nothing (which counts as a direct abstract declarator here). */
3251 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3252 }
3253
3254 /* Parse a direct declarator or direct abstract declarator; arguments
3255 as c_parser_declarator. */
3256
3257 static struct c_declarator *
3258 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3259 bool *seen_id)
3260 {
3261 /* The direct declarator must start with an identifier (possibly
3262 omitted) or a parenthesized declarator (possibly abstract). In
3263 an ordinary declarator, initial parentheses must start a
3264 parenthesized declarator. In an abstract declarator or parameter
3265 declarator, they could start a parenthesized declarator or a
3266 parameter list. To tell which, the open parenthesis and any
3267 following attributes must be read. If a declaration specifier
3268 follows, then it is a parameter list; if the specifier is a
3269 typedef name, there might be an ambiguity about redeclaring it,
3270 which is resolved in the direction of treating it as a typedef
3271 name. If a close parenthesis follows, it is also an empty
3272 parameter list, as the syntax does not permit empty abstract
3273 declarators. Otherwise, it is a parenthesized declarator (in
3274 which case the analysis may be repeated inside it, recursively).
3275
3276 ??? There is an ambiguity in a parameter declaration "int
3277 (__attribute__((foo)) x)", where x is not a typedef name: it
3278 could be an abstract declarator for a function, or declare x with
3279 parentheses. The proper resolution of this ambiguity needs
3280 documenting. At present we follow an accident of the old
3281 parser's implementation, whereby the first parameter must have
3282 some declaration specifiers other than just attributes. Thus as
3283 a parameter declaration it is treated as a parenthesized
3284 parameter named x, and as an abstract declarator it is
3285 rejected.
3286
3287 ??? Also following the old parser, attributes inside an empty
3288 parameter list are ignored, making it a list not yielding a
3289 prototype, rather than giving an error or making it have one
3290 parameter with implicit type int.
3291
3292 ??? Also following the old parser, typedef names may be
3293 redeclared in declarators, but not Objective-C class names. */
3294
3295 if (kind != C_DTR_ABSTRACT
3296 && c_parser_next_token_is (parser, CPP_NAME)
3297 && ((type_seen_p
3298 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3299 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3300 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3301 {
3302 struct c_declarator *inner
3303 = build_id_declarator (c_parser_peek_token (parser)->value);
3304 *seen_id = true;
3305 inner->id_loc = c_parser_peek_token (parser)->location;
3306 c_parser_consume_token (parser);
3307 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3308 }
3309
3310 if (kind != C_DTR_NORMAL
3311 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3312 {
3313 struct c_declarator *inner = build_id_declarator (NULL_TREE);
3314 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3315 }
3316
3317 /* Either we are at the end of an abstract declarator, or we have
3318 parentheses. */
3319
3320 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3321 {
3322 tree attrs;
3323 struct c_declarator *inner;
3324 c_parser_consume_token (parser);
3325 attrs = c_parser_attributes (parser);
3326 if (kind != C_DTR_NORMAL
3327 && (c_parser_next_token_starts_declspecs (parser)
3328 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3329 {
3330 struct c_arg_info *args
3331 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3332 attrs);
3333 if (args == NULL)
3334 return NULL;
3335 else
3336 {
3337 inner
3338 = build_function_declarator (args,
3339 build_id_declarator (NULL_TREE));
3340 return c_parser_direct_declarator_inner (parser, *seen_id,
3341 inner);
3342 }
3343 }
3344 /* A parenthesized declarator. */
3345 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3346 if (inner != NULL && attrs != NULL)
3347 inner = build_attrs_declarator (attrs, inner);
3348 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3349 {
3350 c_parser_consume_token (parser);
3351 if (inner == NULL)
3352 return NULL;
3353 else
3354 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3355 }
3356 else
3357 {
3358 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3359 "expected %<)%>");
3360 return NULL;
3361 }
3362 }
3363 else
3364 {
3365 if (kind == C_DTR_NORMAL)
3366 {
3367 c_parser_error (parser, "expected identifier or %<(%>");
3368 return NULL;
3369 }
3370 else
3371 return build_id_declarator (NULL_TREE);
3372 }
3373 }
3374
3375 /* Parse part of a direct declarator or direct abstract declarator,
3376 given that some (in INNER) has already been parsed; ID_PRESENT is
3377 true if an identifier is present, false for an abstract
3378 declarator. */
3379
3380 static struct c_declarator *
3381 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3382 struct c_declarator *inner)
3383 {
3384 /* Parse a sequence of array declarators and parameter lists. */
3385 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3386 {
3387 location_t brace_loc = c_parser_peek_token (parser)->location;
3388 struct c_declarator *declarator;
3389 struct c_declspecs *quals_attrs = build_null_declspecs ();
3390 bool static_seen;
3391 bool star_seen;
3392 struct c_expr dimen;
3393 dimen.value = NULL_TREE;
3394 dimen.original_code = ERROR_MARK;
3395 dimen.original_type = NULL_TREE;
3396 c_parser_consume_token (parser);
3397 c_parser_declspecs (parser, quals_attrs, false, false, true,
3398 false, false, cla_prefer_id);
3399 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3400 if (static_seen)
3401 c_parser_consume_token (parser);
3402 if (static_seen && !quals_attrs->declspecs_seen_p)
3403 c_parser_declspecs (parser, quals_attrs, false, false, true,
3404 false, false, cla_prefer_id);
3405 if (!quals_attrs->declspecs_seen_p)
3406 quals_attrs = NULL;
3407 /* If "static" is present, there must be an array dimension.
3408 Otherwise, there may be a dimension, "*", or no
3409 dimension. */
3410 if (static_seen)
3411 {
3412 star_seen = false;
3413 dimen = c_parser_expr_no_commas (parser, NULL);
3414 }
3415 else
3416 {
3417 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3418 {
3419 dimen.value = NULL_TREE;
3420 star_seen = false;
3421 }
3422 else if (flag_cilkplus
3423 && c_parser_next_token_is (parser, CPP_COLON))
3424 {
3425 dimen.value = error_mark_node;
3426 star_seen = false;
3427 error_at (c_parser_peek_token (parser)->location,
3428 "array notations cannot be used in declaration");
3429 c_parser_consume_token (parser);
3430 }
3431 else if (c_parser_next_token_is (parser, CPP_MULT))
3432 {
3433 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3434 {
3435 dimen.value = NULL_TREE;
3436 star_seen = true;
3437 c_parser_consume_token (parser);
3438 }
3439 else
3440 {
3441 star_seen = false;
3442 dimen = c_parser_expr_no_commas (parser, NULL);
3443 }
3444 }
3445 else
3446 {
3447 star_seen = false;
3448 dimen = c_parser_expr_no_commas (parser, NULL);
3449 }
3450 }
3451 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3452 c_parser_consume_token (parser);
3453 else if (flag_cilkplus
3454 && c_parser_next_token_is (parser, CPP_COLON))
3455 {
3456 error_at (c_parser_peek_token (parser)->location,
3457 "array notations cannot be used in declaration");
3458 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
3459 return NULL;
3460 }
3461 else
3462 {
3463 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3464 "expected %<]%>");
3465 return NULL;
3466 }
3467 if (dimen.value)
3468 dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3469 declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3470 static_seen, star_seen);
3471 if (declarator == NULL)
3472 return NULL;
3473 inner = set_array_declarator_inner (declarator, inner);
3474 return c_parser_direct_declarator_inner (parser, id_present, inner);
3475 }
3476 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3477 {
3478 tree attrs;
3479 struct c_arg_info *args;
3480 c_parser_consume_token (parser);
3481 attrs = c_parser_attributes (parser);
3482 args = c_parser_parms_declarator (parser, id_present, attrs);
3483 if (args == NULL)
3484 return NULL;
3485 else
3486 {
3487 inner = build_function_declarator (args, inner);
3488 return c_parser_direct_declarator_inner (parser, id_present, inner);
3489 }
3490 }
3491 return inner;
3492 }
3493
3494 /* Parse a parameter list or identifier list, including the closing
3495 parenthesis but not the opening one. ATTRS are the attributes at
3496 the start of the list. ID_LIST_OK is true if an identifier list is
3497 acceptable; such a list must not have attributes at the start. */
3498
3499 static struct c_arg_info *
3500 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3501 {
3502 push_scope ();
3503 declare_parm_level ();
3504 /* If the list starts with an identifier, it is an identifier list.
3505 Otherwise, it is either a prototype list or an empty list. */
3506 if (id_list_ok
3507 && !attrs
3508 && c_parser_next_token_is (parser, CPP_NAME)
3509 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3510
3511 /* Look ahead to detect typos in type names. */
3512 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3513 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3514 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3515 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3516 {
3517 tree list = NULL_TREE, *nextp = &list;
3518 while (c_parser_next_token_is (parser, CPP_NAME)
3519 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3520 {
3521 *nextp = build_tree_list (NULL_TREE,
3522 c_parser_peek_token (parser)->value);
3523 nextp = & TREE_CHAIN (*nextp);
3524 c_parser_consume_token (parser);
3525 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3526 break;
3527 c_parser_consume_token (parser);
3528 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3529 {
3530 c_parser_error (parser, "expected identifier");
3531 break;
3532 }
3533 }
3534 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3535 {
3536 struct c_arg_info *ret = build_arg_info ();
3537 ret->types = list;
3538 c_parser_consume_token (parser);
3539 pop_scope ();
3540 return ret;
3541 }
3542 else
3543 {
3544 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3545 "expected %<)%>");
3546 pop_scope ();
3547 return NULL;
3548 }
3549 }
3550 else
3551 {
3552 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3553 NULL);
3554 pop_scope ();
3555 return ret;
3556 }
3557 }
3558
3559 /* Parse a parameter list (possibly empty), including the closing
3560 parenthesis but not the opening one. ATTRS are the attributes at
3561 the start of the list. EXPR is NULL or an expression that needs to
3562 be evaluated for the side effects of array size expressions in the
3563 parameters. */
3564
3565 static struct c_arg_info *
3566 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3567 {
3568 bool bad_parm = false;
3569
3570 /* ??? Following the old parser, forward parameter declarations may
3571 use abstract declarators, and if no real parameter declarations
3572 follow the forward declarations then this is not diagnosed. Also
3573 note as above that attributes are ignored as the only contents of
3574 the parentheses, or as the only contents after forward
3575 declarations. */
3576 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3577 {
3578 struct c_arg_info *ret = build_arg_info ();
3579 c_parser_consume_token (parser);
3580 return ret;
3581 }
3582 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3583 {
3584 struct c_arg_info *ret = build_arg_info ();
3585
3586 if (flag_allow_parameterless_variadic_functions)
3587 {
3588 /* F (...) is allowed. */
3589 ret->types = NULL_TREE;
3590 }
3591 else
3592 {
3593 /* Suppress -Wold-style-definition for this case. */
3594 ret->types = error_mark_node;
3595 error_at (c_parser_peek_token (parser)->location,
3596 "ISO C requires a named argument before %<...%>");
3597 }
3598 c_parser_consume_token (parser);
3599 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3600 {
3601 c_parser_consume_token (parser);
3602 return ret;
3603 }
3604 else
3605 {
3606 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3607 "expected %<)%>");
3608 return NULL;
3609 }
3610 }
3611 /* Nonempty list of parameters, either terminated with semicolon
3612 (forward declarations; recurse) or with close parenthesis (normal
3613 function) or with ", ... )" (variadic function). */
3614 while (true)
3615 {
3616 /* Parse a parameter. */
3617 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3618 attrs = NULL_TREE;
3619 if (parm == NULL)
3620 bad_parm = true;
3621 else
3622 push_parm_decl (parm, &expr);
3623 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3624 {
3625 tree new_attrs;
3626 c_parser_consume_token (parser);
3627 mark_forward_parm_decls ();
3628 new_attrs = c_parser_attributes (parser);
3629 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3630 }
3631 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3632 {
3633 c_parser_consume_token (parser);
3634 if (bad_parm)
3635 return NULL;
3636 else
3637 return get_parm_info (false, expr);
3638 }
3639 if (!c_parser_require (parser, CPP_COMMA,
3640 "expected %<;%>, %<,%> or %<)%>"))
3641 {
3642 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3643 return NULL;
3644 }
3645 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3646 {
3647 c_parser_consume_token (parser);
3648 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3649 {
3650 c_parser_consume_token (parser);
3651 if (bad_parm)
3652 return NULL;
3653 else
3654 return get_parm_info (true, expr);
3655 }
3656 else
3657 {
3658 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3659 "expected %<)%>");
3660 return NULL;
3661 }
3662 }
3663 }
3664 }
3665
3666 /* Parse a parameter declaration. ATTRS are the attributes at the
3667 start of the declaration if it is the first parameter. */
3668
3669 static struct c_parm *
3670 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3671 {
3672 struct c_declspecs *specs;
3673 struct c_declarator *declarator;
3674 tree prefix_attrs;
3675 tree postfix_attrs = NULL_TREE;
3676 bool dummy = false;
3677
3678 /* Accept #pragmas between parameter declarations. */
3679 while (c_parser_next_token_is (parser, CPP_PRAGMA))
3680 c_parser_pragma (parser, pragma_param);
3681
3682 if (!c_parser_next_token_starts_declspecs (parser))
3683 {
3684 c_token *token = c_parser_peek_token (parser);
3685 if (parser->error)
3686 return NULL;
3687 c_parser_set_source_position_from_token (token);
3688 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3689 {
3690 error_at (token->location, "unknown type name %qE", token->value);
3691 parser->error = true;
3692 }
3693 /* ??? In some Objective-C cases '...' isn't applicable so there
3694 should be a different message. */
3695 else
3696 c_parser_error (parser,
3697 "expected declaration specifiers or %<...%>");
3698 c_parser_skip_to_end_of_parameter (parser);
3699 return NULL;
3700 }
3701 specs = build_null_declspecs ();
3702 if (attrs)
3703 {
3704 declspecs_add_attrs (input_location, specs, attrs);
3705 attrs = NULL_TREE;
3706 }
3707 c_parser_declspecs (parser, specs, true, true, true, true, false,
3708 cla_nonabstract_decl);
3709 finish_declspecs (specs);
3710 pending_xref_error ();
3711 prefix_attrs = specs->attrs;
3712 specs->attrs = NULL_TREE;
3713 declarator = c_parser_declarator (parser,
3714 specs->typespec_kind != ctsk_none,
3715 C_DTR_PARM, &dummy);
3716 if (declarator == NULL)
3717 {
3718 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3719 return NULL;
3720 }
3721 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3722 postfix_attrs = c_parser_attributes (parser);
3723 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3724 declarator);
3725 }
3726
3727 /* Parse a string literal in an asm expression. It should not be
3728 translated, and wide string literals are an error although
3729 permitted by the syntax. This is a GNU extension.
3730
3731 asm-string-literal:
3732 string-literal
3733
3734 ??? At present, following the old parser, the caller needs to have
3735 set lex_untranslated_string to 1. It would be better to follow the
3736 C++ parser rather than using this kludge. */
3737
3738 static tree
3739 c_parser_asm_string_literal (c_parser *parser)
3740 {
3741 tree str;
3742 int save_flag = warn_overlength_strings;
3743 warn_overlength_strings = 0;
3744 if (c_parser_next_token_is (parser, CPP_STRING))
3745 {
3746 str = c_parser_peek_token (parser)->value;
3747 c_parser_consume_token (parser);
3748 }
3749 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3750 {
3751 error_at (c_parser_peek_token (parser)->location,
3752 "wide string literal in %<asm%>");
3753 str = build_string (1, "");
3754 c_parser_consume_token (parser);
3755 }
3756 else
3757 {
3758 c_parser_error (parser, "expected string literal");
3759 str = NULL_TREE;
3760 }
3761 warn_overlength_strings = save_flag;
3762 return str;
3763 }
3764
3765 /* Parse a simple asm expression. This is used in restricted
3766 contexts, where a full expression with inputs and outputs does not
3767 make sense. This is a GNU extension.
3768
3769 simple-asm-expr:
3770 asm ( asm-string-literal )
3771 */
3772
3773 static tree
3774 c_parser_simple_asm_expr (c_parser *parser)
3775 {
3776 tree str;
3777 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3778 /* ??? Follow the C++ parser rather than using the
3779 lex_untranslated_string kludge. */
3780 parser->lex_untranslated_string = true;
3781 c_parser_consume_token (parser);
3782 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3783 {
3784 parser->lex_untranslated_string = false;
3785 return NULL_TREE;
3786 }
3787 str = c_parser_asm_string_literal (parser);
3788 parser->lex_untranslated_string = false;
3789 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3790 {
3791 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3792 return NULL_TREE;
3793 }
3794 return str;
3795 }
3796
3797 static tree
3798 c_parser_attribute_any_word (c_parser *parser)
3799 {
3800 tree attr_name = NULL_TREE;
3801
3802 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3803 {
3804 /* ??? See comment above about what keywords are accepted here. */
3805 bool ok;
3806 switch (c_parser_peek_token (parser)->keyword)
3807 {
3808 case RID_STATIC:
3809 case RID_UNSIGNED:
3810 case RID_LONG:
3811 case RID_CONST:
3812 case RID_EXTERN:
3813 case RID_REGISTER:
3814 case RID_TYPEDEF:
3815 case RID_SHORT:
3816 case RID_INLINE:
3817 case RID_NORETURN:
3818 case RID_VOLATILE:
3819 case RID_SIGNED:
3820 case RID_AUTO:
3821 case RID_RESTRICT:
3822 case RID_COMPLEX:
3823 case RID_THREAD:
3824 case RID_INT:
3825 case RID_CHAR:
3826 case RID_FLOAT:
3827 case RID_DOUBLE:
3828 case RID_VOID:
3829 case RID_DFLOAT32:
3830 case RID_DFLOAT64:
3831 case RID_DFLOAT128:
3832 case RID_BOOL:
3833 case RID_FRACT:
3834 case RID_ACCUM:
3835 case RID_SAT:
3836 case RID_TRANSACTION_ATOMIC:
3837 case RID_TRANSACTION_CANCEL:
3838 case RID_ATOMIC:
3839 case RID_AUTO_TYPE:
3840 case RID_INT_N_0:
3841 case RID_INT_N_1:
3842 case RID_INT_N_2:
3843 case RID_INT_N_3:
3844 ok = true;
3845 break;
3846 default:
3847 ok = false;
3848 break;
3849 }
3850 if (!ok)
3851 return NULL_TREE;
3852
3853 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3854 attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3855 }
3856 else if (c_parser_next_token_is (parser, CPP_NAME))
3857 attr_name = c_parser_peek_token (parser)->value;
3858
3859 return attr_name;
3860 }
3861
3862 #define CILK_SIMD_FN_CLAUSE_MASK \
3863 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3864 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3865 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3866 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3867 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3868
3869 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3870 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3871 pushed into the token list.
3872 Syntax:
3873 vector
3874 vector (<vector attributes>). */
3875
3876 static void
3877 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token)
3878 {
3879 gcc_assert (is_cilkplus_vector_p (vec_token.value));
3880
3881 int paren_scope = 0;
3882 vec_safe_push (parser->cilk_simd_fn_tokens, vec_token);
3883 /* Consume the "vector" token. */
3884 c_parser_consume_token (parser);
3885
3886 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3887 {
3888 c_parser_consume_token (parser);
3889 paren_scope++;
3890 }
3891 while (paren_scope > 0)
3892 {
3893 c_token *token = c_parser_peek_token (parser);
3894 if (token->type == CPP_OPEN_PAREN)
3895 paren_scope++;
3896 else if (token->type == CPP_CLOSE_PAREN)
3897 paren_scope--;
3898 /* Do not push the last ')' since we are not pushing the '('. */
3899 if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0))
3900 vec_safe_push (parser->cilk_simd_fn_tokens, *token);
3901 c_parser_consume_token (parser);
3902 }
3903
3904 /* Since we are converting an attribute to a pragma, we need to end the
3905 attribute with PRAGMA_EOL. */
3906 c_token eol_token;
3907 memset (&eol_token, 0, sizeof (eol_token));
3908 eol_token.type = CPP_PRAGMA_EOL;
3909 vec_safe_push (parser->cilk_simd_fn_tokens, eol_token);
3910 }
3911
3912 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3913
3914 static void
3915 c_finish_cilk_simd_fn_tokens (c_parser *parser)
3916 {
3917 c_token last_token = parser->cilk_simd_fn_tokens->last ();
3918
3919 /* c_parser_attributes is called in several places, so if these EOF
3920 tokens are already inserted, then don't do them again. */
3921 if (last_token.type == CPP_EOF)
3922 return;
3923
3924 /* Two CPP_EOF token are added as a safety net since the normal C
3925 front-end has two token look-ahead. */
3926 c_token eof_token;
3927 eof_token.type = CPP_EOF;
3928 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3929 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3930 }
3931
3932 /* Parse (possibly empty) attributes. This is a GNU extension.
3933
3934 attributes:
3935 empty
3936 attributes attribute
3937
3938 attribute:
3939 __attribute__ ( ( attribute-list ) )
3940
3941 attribute-list:
3942 attrib
3943 attribute_list , attrib
3944
3945 attrib:
3946 empty
3947 any-word
3948 any-word ( identifier )
3949 any-word ( identifier , nonempty-expr-list )
3950 any-word ( expr-list )
3951
3952 where the "identifier" must not be declared as a type, and
3953 "any-word" may be any identifier (including one declared as a
3954 type), a reserved word storage class specifier, type specifier or
3955 type qualifier. ??? This still leaves out most reserved keywords
3956 (following the old parser), shouldn't we include them, and why not
3957 allow identifiers declared as types to start the arguments? */
3958
3959 static tree
3960 c_parser_attributes (c_parser *parser)
3961 {
3962 tree attrs = NULL_TREE;
3963 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3964 {
3965 /* ??? Follow the C++ parser rather than using the
3966 lex_untranslated_string kludge. */
3967 parser->lex_untranslated_string = true;
3968 /* Consume the `__attribute__' keyword. */
3969 c_parser_consume_token (parser);
3970 /* Look for the two `(' tokens. */
3971 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3972 {
3973 parser->lex_untranslated_string = false;
3974 return attrs;
3975 }
3976 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3977 {
3978 parser->lex_untranslated_string = false;
3979 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3980 return attrs;
3981 }
3982 /* Parse the attribute list. */
3983 while (c_parser_next_token_is (parser, CPP_COMMA)
3984 || c_parser_next_token_is (parser, CPP_NAME)
3985 || c_parser_next_token_is (parser, CPP_KEYWORD))
3986 {
3987 tree attr, attr_name, attr_args;
3988 vec<tree, va_gc> *expr_list;
3989 if (c_parser_next_token_is (parser, CPP_COMMA))
3990 {
3991 c_parser_consume_token (parser);
3992 continue;
3993 }
3994
3995 attr_name = c_parser_attribute_any_word (parser);
3996 if (attr_name == NULL)
3997 break;
3998 if (is_cilkplus_vector_p (attr_name))
3999 {
4000 c_token *v_token = c_parser_peek_token (parser);
4001 c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
4002 /* If the next token isn't a comma, we're done. */
4003 if (!c_parser_next_token_is (parser, CPP_COMMA))
4004 break;
4005 continue;
4006 }
4007 c_parser_consume_token (parser);
4008 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
4009 {
4010 attr = build_tree_list (attr_name, NULL_TREE);
4011 /* Add this attribute to the list. */
4012 attrs = chainon (attrs, attr);
4013 /* If the next token isn't a comma, we're done. */
4014 if (!c_parser_next_token_is (parser, CPP_COMMA))
4015 break;
4016 continue;
4017 }
4018 c_parser_consume_token (parser);
4019 /* Parse the attribute contents. If they start with an
4020 identifier which is followed by a comma or close
4021 parenthesis, then the arguments start with that
4022 identifier; otherwise they are an expression list.
4023 In objective-c the identifier may be a classname. */
4024 if (c_parser_next_token_is (parser, CPP_NAME)
4025 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4026 || (c_dialect_objc ()
4027 && c_parser_peek_token (parser)->id_kind
4028 == C_ID_CLASSNAME))
4029 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4030 || (c_parser_peek_2nd_token (parser)->type
4031 == CPP_CLOSE_PAREN))
4032 && (attribute_takes_identifier_p (attr_name)
4033 || (c_dialect_objc ()
4034 && c_parser_peek_token (parser)->id_kind
4035 == C_ID_CLASSNAME)))
4036 {
4037 tree arg1 = c_parser_peek_token (parser)->value;
4038 c_parser_consume_token (parser);
4039 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4040 attr_args = build_tree_list (NULL_TREE, arg1);
4041 else
4042 {
4043 tree tree_list;
4044 c_parser_consume_token (parser);
4045 expr_list = c_parser_expr_list (parser, false, true,
4046 NULL, NULL, NULL, NULL);
4047 tree_list = build_tree_list_vec (expr_list);
4048 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4049 release_tree_vector (expr_list);
4050 }
4051 }
4052 else
4053 {
4054 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4055 attr_args = NULL_TREE;
4056 else
4057 {
4058 expr_list = c_parser_expr_list (parser, false, true,
4059 NULL, NULL, NULL, NULL);
4060 attr_args = build_tree_list_vec (expr_list);
4061 release_tree_vector (expr_list);
4062 }
4063 }
4064 attr = build_tree_list (attr_name, attr_args);
4065 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4066 c_parser_consume_token (parser);
4067 else
4068 {
4069 parser->lex_untranslated_string = false;
4070 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4071 "expected %<)%>");
4072 return attrs;
4073 }
4074 /* Add this attribute to the list. */
4075 attrs = chainon (attrs, attr);
4076 /* If the next token isn't a comma, we're done. */
4077 if (!c_parser_next_token_is (parser, CPP_COMMA))
4078 break;
4079 }
4080 /* Look for the two `)' tokens. */
4081 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4082 c_parser_consume_token (parser);
4083 else
4084 {
4085 parser->lex_untranslated_string = false;
4086 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4087 "expected %<)%>");
4088 return attrs;
4089 }
4090 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4091 c_parser_consume_token (parser);
4092 else
4093 {
4094 parser->lex_untranslated_string = false;
4095 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4096 "expected %<)%>");
4097 return attrs;
4098 }
4099 parser->lex_untranslated_string = false;
4100 }
4101
4102 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
4103 c_finish_cilk_simd_fn_tokens (parser);
4104 return attrs;
4105 }
4106
4107 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4108
4109 type-name:
4110 specifier-qualifier-list abstract-declarator[opt]
4111 */
4112
4113 static struct c_type_name *
4114 c_parser_type_name (c_parser *parser)
4115 {
4116 struct c_declspecs *specs = build_null_declspecs ();
4117 struct c_declarator *declarator;
4118 struct c_type_name *ret;
4119 bool dummy = false;
4120 c_parser_declspecs (parser, specs, false, true, true, false, false,
4121 cla_prefer_type);
4122 if (!specs->declspecs_seen_p)
4123 {
4124 c_parser_error (parser, "expected specifier-qualifier-list");
4125 return NULL;
4126 }
4127 if (specs->type != error_mark_node)
4128 {
4129 pending_xref_error ();
4130 finish_declspecs (specs);
4131 }
4132 declarator = c_parser_declarator (parser,
4133 specs->typespec_kind != ctsk_none,
4134 C_DTR_ABSTRACT, &dummy);
4135 if (declarator == NULL)
4136 return NULL;
4137 ret = XOBNEW (&parser_obstack, struct c_type_name);
4138 ret->specs = specs;
4139 ret->declarator = declarator;
4140 return ret;
4141 }
4142
4143 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4144
4145 initializer:
4146 assignment-expression
4147 { initializer-list }
4148 { initializer-list , }
4149
4150 initializer-list:
4151 designation[opt] initializer
4152 initializer-list , designation[opt] initializer
4153
4154 designation:
4155 designator-list =
4156
4157 designator-list:
4158 designator
4159 designator-list designator
4160
4161 designator:
4162 array-designator
4163 . identifier
4164
4165 array-designator:
4166 [ constant-expression ]
4167
4168 GNU extensions:
4169
4170 initializer:
4171 { }
4172
4173 designation:
4174 array-designator
4175 identifier :
4176
4177 array-designator:
4178 [ constant-expression ... constant-expression ]
4179
4180 Any expression without commas is accepted in the syntax for the
4181 constant-expressions, with non-constant expressions rejected later.
4182
4183 This function is only used for top-level initializers; for nested
4184 ones, see c_parser_initval. */
4185
4186 static struct c_expr
4187 c_parser_initializer (c_parser *parser)
4188 {
4189 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4190 return c_parser_braced_init (parser, NULL_TREE, false);
4191 else
4192 {
4193 struct c_expr ret;
4194 location_t loc = c_parser_peek_token (parser)->location;
4195 ret = c_parser_expr_no_commas (parser, NULL);
4196 if (TREE_CODE (ret.value) != STRING_CST
4197 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4198 ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4199 return ret;
4200 }
4201 }
4202
4203 /* Parse a braced initializer list. TYPE is the type specified for a
4204 compound literal, and NULL_TREE for other initializers and for
4205 nested braced lists. NESTED_P is true for nested braced lists,
4206 false for the list of a compound literal or the list that is the
4207 top-level initializer in a declaration. */
4208
4209 static struct c_expr
4210 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
4211 {
4212 struct c_expr ret;
4213 struct obstack braced_init_obstack;
4214 location_t brace_loc = c_parser_peek_token (parser)->location;
4215 gcc_obstack_init (&braced_init_obstack);
4216 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4217 c_parser_consume_token (parser);
4218 if (nested_p)
4219 push_init_level (brace_loc, 0, &braced_init_obstack);
4220 else
4221 really_start_incremental_init (type);
4222 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4223 {
4224 pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4225 }
4226 else
4227 {
4228 /* Parse a non-empty initializer list, possibly with a trailing
4229 comma. */
4230 while (true)
4231 {
4232 c_parser_initelt (parser, &braced_init_obstack);
4233 if (parser->error)
4234 break;
4235 if (c_parser_next_token_is (parser, CPP_COMMA))
4236 c_parser_consume_token (parser);
4237 else
4238 break;
4239 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4240 break;
4241 }
4242 }
4243 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4244 {
4245 ret.value = error_mark_node;
4246 ret.original_code = ERROR_MARK;
4247 ret.original_type = NULL;
4248 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
4249 pop_init_level (brace_loc, 0, &braced_init_obstack);
4250 obstack_free (&braced_init_obstack, NULL);
4251 return ret;
4252 }
4253 c_parser_consume_token (parser);
4254 ret = pop_init_level (brace_loc, 0, &braced_init_obstack);
4255 obstack_free (&braced_init_obstack, NULL);
4256 return ret;
4257 }
4258
4259 /* Parse a nested initializer, including designators. */
4260
4261 static void
4262 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4263 {
4264 /* Parse any designator or designator list. A single array
4265 designator may have the subsequent "=" omitted in GNU C, but a
4266 longer list or a structure member designator may not. */
4267 if (c_parser_next_token_is (parser, CPP_NAME)
4268 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4269 {
4270 /* Old-style structure member designator. */
4271 set_init_label (c_parser_peek_token (parser)->location,
4272 c_parser_peek_token (parser)->value,
4273 braced_init_obstack);
4274 /* Use the colon as the error location. */
4275 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4276 "obsolete use of designated initializer with %<:%>");
4277 c_parser_consume_token (parser);
4278 c_parser_consume_token (parser);
4279 }
4280 else
4281 {
4282 /* des_seen is 0 if there have been no designators, 1 if there
4283 has been a single array designator and 2 otherwise. */
4284 int des_seen = 0;
4285 /* Location of a designator. */
4286 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4287 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4288 || c_parser_next_token_is (parser, CPP_DOT))
4289 {
4290 int des_prev = des_seen;
4291 if (!des_seen)
4292 des_loc = c_parser_peek_token (parser)->location;
4293 if (des_seen < 2)
4294 des_seen++;
4295 if (c_parser_next_token_is (parser, CPP_DOT))
4296 {
4297 des_seen = 2;
4298 c_parser_consume_token (parser);
4299 if (c_parser_next_token_is (parser, CPP_NAME))
4300 {
4301 set_init_label (des_loc, c_parser_peek_token (parser)->value,
4302 braced_init_obstack);
4303 c_parser_consume_token (parser);
4304 }
4305 else
4306 {
4307 struct c_expr init;
4308 init.value = error_mark_node;
4309 init.original_code = ERROR_MARK;
4310 init.original_type = NULL;
4311 c_parser_error (parser, "expected identifier");
4312 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4313 process_init_element (input_location, init, false,
4314 braced_init_obstack);
4315 return;
4316 }
4317 }
4318 else
4319 {
4320 tree first, second;
4321 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4322 location_t array_index_loc = UNKNOWN_LOCATION;
4323 /* ??? Following the old parser, [ objc-receiver
4324 objc-message-args ] is accepted as an initializer,
4325 being distinguished from a designator by what follows
4326 the first assignment expression inside the square
4327 brackets, but after a first array designator a
4328 subsequent square bracket is for Objective-C taken to
4329 start an expression, using the obsolete form of
4330 designated initializer without '=', rather than
4331 possibly being a second level of designation: in LALR
4332 terms, the '[' is shifted rather than reducing
4333 designator to designator-list. */
4334 if (des_prev == 1 && c_dialect_objc ())
4335 {
4336 des_seen = des_prev;
4337 break;
4338 }
4339 if (des_prev == 0 && c_dialect_objc ())
4340 {
4341 /* This might be an array designator or an
4342 Objective-C message expression. If the former,
4343 continue parsing here; if the latter, parse the
4344 remainder of the initializer given the starting
4345 primary-expression. ??? It might make sense to
4346 distinguish when des_prev == 1 as well; see
4347 previous comment. */
4348 tree rec, args;
4349 struct c_expr mexpr;
4350 c_parser_consume_token (parser);
4351 if (c_parser_peek_token (parser)->type == CPP_NAME
4352 && ((c_parser_peek_token (parser)->id_kind
4353 == C_ID_TYPENAME)
4354 || (c_parser_peek_token (parser)->id_kind
4355 == C_ID_CLASSNAME)))
4356 {
4357 /* Type name receiver. */
4358 tree id = c_parser_peek_token (parser)->value;
4359 c_parser_consume_token (parser);
4360 rec = objc_get_class_reference (id);
4361 goto parse_message_args;
4362 }
4363 first = c_parser_expr_no_commas (parser, NULL).value;
4364 mark_exp_read (first);
4365 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4366 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4367 goto array_desig_after_first;
4368 /* Expression receiver. So far only one part
4369 without commas has been parsed; there might be
4370 more of the expression. */
4371 rec = first;
4372 while (c_parser_next_token_is (parser, CPP_COMMA))
4373 {
4374 struct c_expr next;
4375 location_t comma_loc, exp_loc;
4376 comma_loc = c_parser_peek_token (parser)->location;
4377 c_parser_consume_token (parser);
4378 exp_loc = c_parser_peek_token (parser)->location;
4379 next = c_parser_expr_no_commas (parser, NULL);
4380 next = convert_lvalue_to_rvalue (exp_loc, next,
4381 true, true);
4382 rec = build_compound_expr (comma_loc, rec, next.value);
4383 }
4384 parse_message_args:
4385 /* Now parse the objc-message-args. */
4386 args = c_parser_objc_message_args (parser);
4387 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4388 "expected %<]%>");
4389 mexpr.value
4390 = objc_build_message_expr (rec, args);
4391 mexpr.original_code = ERROR_MARK;
4392 mexpr.original_type = NULL;
4393 /* Now parse and process the remainder of the
4394 initializer, starting with this message
4395 expression as a primary-expression. */
4396 c_parser_initval (parser, &mexpr, braced_init_obstack);
4397 return;
4398 }
4399 c_parser_consume_token (parser);
4400 array_index_loc = c_parser_peek_token (parser)->location;
4401 first = c_parser_expr_no_commas (parser, NULL).value;
4402 mark_exp_read (first);
4403 array_desig_after_first:
4404 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4405 {
4406 ellipsis_loc = c_parser_peek_token (parser)->location;
4407 c_parser_consume_token (parser);
4408 second = c_parser_expr_no_commas (parser, NULL).value;
4409 mark_exp_read (second);
4410 }
4411 else
4412 second = NULL_TREE;
4413 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4414 {
4415 c_parser_consume_token (parser);
4416 set_init_index (array_index_loc, first, second,
4417 braced_init_obstack);
4418 if (second)
4419 pedwarn (ellipsis_loc, OPT_Wpedantic,
4420 "ISO C forbids specifying range of elements to initialize");
4421 }
4422 else
4423 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4424 "expected %<]%>");
4425 }
4426 }
4427 if (des_seen >= 1)
4428 {
4429 if (c_parser_next_token_is (parser, CPP_EQ))
4430 {
4431 pedwarn_c90 (des_loc, OPT_Wpedantic,
4432 "ISO C90 forbids specifying subobject "
4433 "to initialize");
4434 c_parser_consume_token (parser);
4435 }
4436 else
4437 {
4438 if (des_seen == 1)
4439 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4440 "obsolete use of designated initializer without %<=%>");
4441 else
4442 {
4443 struct c_expr init;
4444 init.value = error_mark_node;
4445 init.original_code = ERROR_MARK;
4446 init.original_type = NULL;
4447 c_parser_error (parser, "expected %<=%>");
4448 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4449 process_init_element (input_location, init, false,
4450 braced_init_obstack);
4451 return;
4452 }
4453 }
4454 }
4455 }
4456 c_parser_initval (parser, NULL, braced_init_obstack);
4457 }
4458
4459 /* Parse a nested initializer; as c_parser_initializer but parses
4460 initializers within braced lists, after any designators have been
4461 applied. If AFTER is not NULL then it is an Objective-C message
4462 expression which is the primary-expression starting the
4463 initializer. */
4464
4465 static void
4466 c_parser_initval (c_parser *parser, struct c_expr *after,
4467 struct obstack * braced_init_obstack)
4468 {
4469 struct c_expr init;
4470 gcc_assert (!after || c_dialect_objc ());
4471 location_t loc = c_parser_peek_token (parser)->location;
4472
4473 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4474 init = c_parser_braced_init (parser, NULL_TREE, true);
4475 else
4476 {
4477 init = c_parser_expr_no_commas (parser, after);
4478 if (init.value != NULL_TREE
4479 && TREE_CODE (init.value) != STRING_CST
4480 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4481 init = convert_lvalue_to_rvalue (loc, init, true, true);
4482 }
4483 process_init_element (loc, init, false, braced_init_obstack);
4484 }
4485
4486 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4487 C99 6.8.2).
4488
4489 compound-statement:
4490 { block-item-list[opt] }
4491 { label-declarations block-item-list }
4492
4493 block-item-list:
4494 block-item
4495 block-item-list block-item
4496
4497 block-item:
4498 nested-declaration
4499 statement
4500
4501 nested-declaration:
4502 declaration
4503
4504 GNU extensions:
4505
4506 compound-statement:
4507 { label-declarations block-item-list }
4508
4509 nested-declaration:
4510 __extension__ nested-declaration
4511 nested-function-definition
4512
4513 label-declarations:
4514 label-declaration
4515 label-declarations label-declaration
4516
4517 label-declaration:
4518 __label__ identifier-list ;
4519
4520 Allowing the mixing of declarations and code is new in C99. The
4521 GNU syntax also permits (not shown above) labels at the end of
4522 compound statements, which yield an error. We don't allow labels
4523 on declarations; this might seem like a natural extension, but
4524 there would be a conflict between attributes on the label and
4525 prefix attributes on the declaration. ??? The syntax follows the
4526 old parser in requiring something after label declarations.
4527 Although they are erroneous if the labels declared aren't defined,
4528 is it useful for the syntax to be this way?
4529
4530 OpenACC:
4531
4532 block-item:
4533 openacc-directive
4534
4535 openacc-directive:
4536 update-directive
4537
4538 OpenMP:
4539
4540 block-item:
4541 openmp-directive
4542
4543 openmp-directive:
4544 barrier-directive
4545 flush-directive
4546 taskwait-directive
4547 taskyield-directive
4548 cancel-directive
4549 cancellation-point-directive */
4550
4551 static tree
4552 c_parser_compound_statement (c_parser *parser)
4553 {
4554 tree stmt;
4555 location_t brace_loc;
4556 brace_loc = c_parser_peek_token (parser)->location;
4557 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4558 {
4559 /* Ensure a scope is entered and left anyway to avoid confusion
4560 if we have just prepared to enter a function body. */
4561 stmt = c_begin_compound_stmt (true);
4562 c_end_compound_stmt (brace_loc, stmt, true);
4563 return error_mark_node;
4564 }
4565 stmt = c_begin_compound_stmt (true);
4566 c_parser_compound_statement_nostart (parser);
4567
4568 /* If the compound stmt contains array notations, then we expand them. */
4569 if (flag_cilkplus && contains_array_notation_expr (stmt))
4570 stmt = expand_array_notation_exprs (stmt);
4571 return c_end_compound_stmt (brace_loc, stmt, true);
4572 }
4573
4574 /* Parse a compound statement except for the opening brace. This is
4575 used for parsing both compound statements and statement expressions
4576 (which follow different paths to handling the opening). */
4577
4578 static void
4579 c_parser_compound_statement_nostart (c_parser *parser)
4580 {
4581 bool last_stmt = false;
4582 bool last_label = false;
4583 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4584 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4585 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4586 {
4587 c_parser_consume_token (parser);
4588 return;
4589 }
4590 mark_valid_location_for_stdc_pragma (true);
4591 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4592 {
4593 /* Read zero or more forward-declarations for labels that nested
4594 functions can jump to. */
4595 mark_valid_location_for_stdc_pragma (false);
4596 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4597 {
4598 label_loc = c_parser_peek_token (parser)->location;
4599 c_parser_consume_token (parser);
4600 /* Any identifiers, including those declared as type names,
4601 are OK here. */
4602 while (true)
4603 {
4604 tree label;
4605 if (c_parser_next_token_is_not (parser, CPP_NAME))
4606 {
4607 c_parser_error (parser, "expected identifier");
4608 break;
4609 }
4610 label
4611 = declare_label (c_parser_peek_token (parser)->value);
4612 C_DECLARED_LABEL_FLAG (label) = 1;
4613 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4614 c_parser_consume_token (parser);
4615 if (c_parser_next_token_is (parser, CPP_COMMA))
4616 c_parser_consume_token (parser);
4617 else
4618 break;
4619 }
4620 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4621 }
4622 pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4623 }
4624 /* We must now have at least one statement, label or declaration. */
4625 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4626 {
4627 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4628 c_parser_error (parser, "expected declaration or statement");
4629 c_parser_consume_token (parser);
4630 return;
4631 }
4632 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4633 {
4634 location_t loc = c_parser_peek_token (parser)->location;
4635 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4636 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4637 || (c_parser_next_token_is (parser, CPP_NAME)
4638 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4639 {
4640 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4641 label_loc = c_parser_peek_2nd_token (parser)->location;
4642 else
4643 label_loc = c_parser_peek_token (parser)->location;
4644 last_label = true;
4645 last_stmt = false;
4646 mark_valid_location_for_stdc_pragma (false);
4647 c_parser_label (parser);
4648 }
4649 else if (!last_label
4650 && c_parser_next_tokens_start_declaration (parser))
4651 {
4652 last_label = false;
4653 mark_valid_location_for_stdc_pragma (false);
4654 c_parser_declaration_or_fndef (parser, true, true, true, true,
4655 true, NULL, vNULL);
4656 if (last_stmt)
4657 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4658 "ISO C90 forbids mixed declarations and code");
4659 last_stmt = false;
4660 }
4661 else if (!last_label
4662 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4663 {
4664 /* __extension__ can start a declaration, but is also an
4665 unary operator that can start an expression. Consume all
4666 but the last of a possible series of __extension__ to
4667 determine which. */
4668 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4669 && (c_parser_peek_2nd_token (parser)->keyword
4670 == RID_EXTENSION))
4671 c_parser_consume_token (parser);
4672 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4673 {
4674 int ext;
4675 ext = disable_extension_diagnostics ();
4676 c_parser_consume_token (parser);
4677 last_label = false;
4678 mark_valid_location_for_stdc_pragma (false);
4679 c_parser_declaration_or_fndef (parser, true, true, true, true,
4680 true, NULL, vNULL);
4681 /* Following the old parser, __extension__ does not
4682 disable this diagnostic. */
4683 restore_extension_diagnostics (ext);
4684 if (last_stmt)
4685 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4686 "ISO C90 forbids mixed declarations and code");
4687 last_stmt = false;
4688 }
4689 else
4690 goto statement;
4691 }
4692 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4693 {
4694 /* External pragmas, and some omp pragmas, are not associated
4695 with regular c code, and so are not to be considered statements
4696 syntactically. This ensures that the user doesn't put them
4697 places that would turn into syntax errors if the directive
4698 were ignored. */
4699 if (c_parser_pragma (parser, pragma_compound))
4700 last_label = false, last_stmt = true;
4701 }
4702 else if (c_parser_next_token_is (parser, CPP_EOF))
4703 {
4704 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4705 c_parser_error (parser, "expected declaration or statement");
4706 return;
4707 }
4708 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4709 {
4710 if (parser->in_if_block)
4711 {
4712 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4713 error_at (loc, """expected %<}%> before %<else%>");
4714 return;
4715 }
4716 else
4717 {
4718 error_at (loc, "%<else%> without a previous %<if%>");
4719 c_parser_consume_token (parser);
4720 continue;
4721 }
4722 }
4723 else
4724 {
4725 statement:
4726 last_label = false;
4727 last_stmt = true;
4728 mark_valid_location_for_stdc_pragma (false);
4729 c_parser_statement_after_labels (parser);
4730 }
4731
4732 parser->error = false;
4733 }
4734 if (last_label)
4735 error_at (label_loc, "label at end of compound statement");
4736 c_parser_consume_token (parser);
4737 /* Restore the value we started with. */
4738 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4739 }
4740
4741 /* Parse all consecutive labels. */
4742
4743 static void
4744 c_parser_all_labels (c_parser *parser)
4745 {
4746 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4747 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4748 || (c_parser_next_token_is (parser, CPP_NAME)
4749 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4750 c_parser_label (parser);
4751 }
4752
4753 /* Parse a label (C90 6.6.1, C99 6.8.1).
4754
4755 label:
4756 identifier : attributes[opt]
4757 case constant-expression :
4758 default :
4759
4760 GNU extensions:
4761
4762 label:
4763 case constant-expression ... constant-expression :
4764
4765 The use of attributes on labels is a GNU extension. The syntax in
4766 GNU C accepts any expressions without commas, non-constant
4767 expressions being rejected later. */
4768
4769 static void
4770 c_parser_label (c_parser *parser)
4771 {
4772 location_t loc1 = c_parser_peek_token (parser)->location;
4773 tree label = NULL_TREE;
4774 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4775 {
4776 tree exp1, exp2;
4777 c_parser_consume_token (parser);
4778 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4779 if (c_parser_next_token_is (parser, CPP_COLON))
4780 {
4781 c_parser_consume_token (parser);
4782 label = do_case (loc1, exp1, NULL_TREE);
4783 }
4784 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4785 {
4786 c_parser_consume_token (parser);
4787 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4788 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4789 label = do_case (loc1, exp1, exp2);
4790 }
4791 else
4792 c_parser_error (parser, "expected %<:%> or %<...%>");
4793 }
4794 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4795 {
4796 c_parser_consume_token (parser);
4797 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4798 label = do_case (loc1, NULL_TREE, NULL_TREE);
4799 }
4800 else
4801 {
4802 tree name = c_parser_peek_token (parser)->value;
4803 tree tlab;
4804 tree attrs;
4805 location_t loc2 = c_parser_peek_token (parser)->location;
4806 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4807 c_parser_consume_token (parser);
4808 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4809 c_parser_consume_token (parser);
4810 attrs = c_parser_attributes (parser);
4811 tlab = define_label (loc2, name);
4812 if (tlab)
4813 {
4814 decl_attributes (&tlab, attrs, 0);
4815 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4816 }
4817 }
4818 if (label)
4819 {
4820 if (c_parser_next_tokens_start_declaration (parser))
4821 {
4822 error_at (c_parser_peek_token (parser)->location,
4823 "a label can only be part of a statement and "
4824 "a declaration is not a statement");
4825 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4826 /*static_assert_ok*/ true,
4827 /*empty_ok*/ true, /*nested*/ true,
4828 /*start_attr_ok*/ true, NULL,
4829 vNULL);
4830 }
4831 }
4832 }
4833
4834 /* Parse a statement (C90 6.6, C99 6.8).
4835
4836 statement:
4837 labeled-statement
4838 compound-statement
4839 expression-statement
4840 selection-statement
4841 iteration-statement
4842 jump-statement
4843
4844 labeled-statement:
4845 label statement
4846
4847 expression-statement:
4848 expression[opt] ;
4849
4850 selection-statement:
4851 if-statement
4852 switch-statement
4853
4854 iteration-statement:
4855 while-statement
4856 do-statement
4857 for-statement
4858
4859 jump-statement:
4860 goto identifier ;
4861 continue ;
4862 break ;
4863 return expression[opt] ;
4864
4865 GNU extensions:
4866
4867 statement:
4868 asm-statement
4869
4870 jump-statement:
4871 goto * expression ;
4872
4873 Objective-C:
4874
4875 statement:
4876 objc-throw-statement
4877 objc-try-catch-statement
4878 objc-synchronized-statement
4879
4880 objc-throw-statement:
4881 @throw expression ;
4882 @throw ;
4883
4884 OpenACC:
4885
4886 statement:
4887 openacc-construct
4888
4889 openacc-construct:
4890 parallel-construct
4891 kernels-construct
4892 data-construct
4893 loop-construct
4894
4895 parallel-construct:
4896 parallel-directive structured-block
4897
4898 kernels-construct:
4899 kernels-directive structured-block
4900
4901 data-construct:
4902 data-directive structured-block
4903
4904 loop-construct:
4905 loop-directive structured-block
4906
4907 OpenMP:
4908
4909 statement:
4910 openmp-construct
4911
4912 openmp-construct:
4913 parallel-construct
4914 for-construct
4915 simd-construct
4916 for-simd-construct
4917 sections-construct
4918 single-construct
4919 parallel-for-construct
4920 parallel-for-simd-construct
4921 parallel-sections-construct
4922 master-construct
4923 critical-construct
4924 atomic-construct
4925 ordered-construct
4926
4927 parallel-construct:
4928 parallel-directive structured-block
4929
4930 for-construct:
4931 for-directive iteration-statement
4932
4933 simd-construct:
4934 simd-directive iteration-statements
4935
4936 for-simd-construct:
4937 for-simd-directive iteration-statements
4938
4939 sections-construct:
4940 sections-directive section-scope
4941
4942 single-construct:
4943 single-directive structured-block
4944
4945 parallel-for-construct:
4946 parallel-for-directive iteration-statement
4947
4948 parallel-for-simd-construct:
4949 parallel-for-simd-directive iteration-statement
4950
4951 parallel-sections-construct:
4952 parallel-sections-directive section-scope
4953
4954 master-construct:
4955 master-directive structured-block
4956
4957 critical-construct:
4958 critical-directive structured-block
4959
4960 atomic-construct:
4961 atomic-directive expression-statement
4962
4963 ordered-construct:
4964 ordered-directive structured-block
4965
4966 Transactional Memory:
4967
4968 statement:
4969 transaction-statement
4970 transaction-cancel-statement
4971 */
4972
4973 static void
4974 c_parser_statement (c_parser *parser)
4975 {
4976 c_parser_all_labels (parser);
4977 c_parser_statement_after_labels (parser);
4978 }
4979
4980 /* Parse a statement, other than a labeled statement. CHAIN is a vector
4981 of if-else-if conditions. */
4982
4983 static void
4984 c_parser_statement_after_labels (c_parser *parser, vec<tree> *chain)
4985 {
4986 location_t loc = c_parser_peek_token (parser)->location;
4987 tree stmt = NULL_TREE;
4988 bool in_if_block = parser->in_if_block;
4989 parser->in_if_block = false;
4990 switch (c_parser_peek_token (parser)->type)
4991 {
4992 case CPP_OPEN_BRACE:
4993 add_stmt (c_parser_compound_statement (parser));
4994 break;
4995 case CPP_KEYWORD:
4996 switch (c_parser_peek_token (parser)->keyword)
4997 {
4998 case RID_IF:
4999 c_parser_if_statement (parser, chain);
5000 break;
5001 case RID_SWITCH:
5002 c_parser_switch_statement (parser);
5003 break;
5004 case RID_WHILE:
5005 c_parser_while_statement (parser, false);
5006 break;
5007 case RID_DO:
5008 c_parser_do_statement (parser, false);
5009 break;
5010 case RID_FOR:
5011 c_parser_for_statement (parser, false);
5012 break;
5013 case RID_CILK_FOR:
5014 if (!flag_cilkplus)
5015 {
5016 error_at (c_parser_peek_token (parser)->location,
5017 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5018 c_parser_skip_to_end_of_block_or_statement (parser);
5019 }
5020 else
5021 c_parser_cilk_for (parser, integer_zero_node);
5022 break;
5023 case RID_CILK_SYNC:
5024 c_parser_consume_token (parser);
5025 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5026 if (!flag_cilkplus)
5027 error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5028 else
5029 add_stmt (build_cilk_sync ());
5030 break;
5031 case RID_GOTO:
5032 c_parser_consume_token (parser);
5033 if (c_parser_next_token_is (parser, CPP_NAME))
5034 {
5035 stmt = c_finish_goto_label (loc,
5036 c_parser_peek_token (parser)->value);
5037 c_parser_consume_token (parser);
5038 }
5039 else if (c_parser_next_token_is (parser, CPP_MULT))
5040 {
5041 struct c_expr val;
5042
5043 c_parser_consume_token (parser);
5044 val = c_parser_expression (parser);
5045 if (check_no_cilk (val.value,
5046 "Cilk array notation cannot be used as a computed goto expression",
5047 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5048 loc))
5049 val.value = error_mark_node;
5050 val = convert_lvalue_to_rvalue (loc, val, false, true);
5051 stmt = c_finish_goto_ptr (loc, val.value);
5052 }
5053 else
5054 c_parser_error (parser, "expected identifier or %<*%>");
5055 goto expect_semicolon;
5056 case RID_CONTINUE:
5057 c_parser_consume_token (parser);
5058 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5059 goto expect_semicolon;
5060 case RID_BREAK:
5061 c_parser_consume_token (parser);
5062 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5063 goto expect_semicolon;
5064 case RID_RETURN:
5065 c_parser_consume_token (parser);
5066 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5067 {
5068 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5069 c_parser_consume_token (parser);
5070 }
5071 else
5072 {
5073 location_t xloc = c_parser_peek_token (parser)->location;
5074 struct c_expr expr = c_parser_expression_conv (parser);
5075 mark_exp_read (expr.value);
5076 stmt = c_finish_return (xloc, expr.value, expr.original_type);
5077 goto expect_semicolon;
5078 }
5079 break;
5080 case RID_ASM:
5081 stmt = c_parser_asm_statement (parser);
5082 break;
5083 case RID_TRANSACTION_ATOMIC:
5084 case RID_TRANSACTION_RELAXED:
5085 stmt = c_parser_transaction (parser,
5086 c_parser_peek_token (parser)->keyword);
5087 break;
5088 case RID_TRANSACTION_CANCEL:
5089 stmt = c_parser_transaction_cancel (parser);
5090 goto expect_semicolon;
5091 case RID_AT_THROW:
5092 gcc_assert (c_dialect_objc ());
5093 c_parser_consume_token (parser);
5094 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5095 {
5096 stmt = objc_build_throw_stmt (loc, NULL_TREE);
5097 c_parser_consume_token (parser);
5098 }
5099 else
5100 {
5101 struct c_expr expr = c_parser_expression (parser);
5102 expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5103 if (check_no_cilk (expr.value,
5104 "Cilk array notation cannot be used for a throw expression",
5105 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5106 expr.value = error_mark_node;
5107 else
5108 {
5109 expr.value = c_fully_fold (expr.value, false, NULL);
5110 stmt = objc_build_throw_stmt (loc, expr.value);
5111 }
5112 goto expect_semicolon;
5113 }
5114 break;
5115 case RID_AT_TRY:
5116 gcc_assert (c_dialect_objc ());
5117 c_parser_objc_try_catch_finally_statement (parser);
5118 break;
5119 case RID_AT_SYNCHRONIZED:
5120 gcc_assert (c_dialect_objc ());
5121 c_parser_objc_synchronized_statement (parser);
5122 break;
5123 default:
5124 goto expr_stmt;
5125 }
5126 break;
5127 case CPP_SEMICOLON:
5128 c_parser_consume_token (parser);
5129 break;
5130 case CPP_CLOSE_PAREN:
5131 case CPP_CLOSE_SQUARE:
5132 /* Avoid infinite loop in error recovery:
5133 c_parser_skip_until_found stops at a closing nesting
5134 delimiter without consuming it, but here we need to consume
5135 it to proceed further. */
5136 c_parser_error (parser, "expected statement");
5137 c_parser_consume_token (parser);
5138 break;
5139 case CPP_PRAGMA:
5140 c_parser_pragma (parser, pragma_stmt);
5141 break;
5142 default:
5143 expr_stmt:
5144 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5145 expect_semicolon:
5146 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5147 break;
5148 }
5149 /* Two cases cannot and do not have line numbers associated: If stmt
5150 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5151 cannot hold line numbers. But that's OK because the statement
5152 will either be changed to a MODIFY_EXPR during gimplification of
5153 the statement expr, or discarded. If stmt was compound, but
5154 without new variables, we will have skipped the creation of a
5155 BIND and will have a bare STATEMENT_LIST. But that's OK because
5156 (recursively) all of the component statements should already have
5157 line numbers assigned. ??? Can we discard no-op statements
5158 earlier? */
5159 if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5160 protected_set_expr_location (stmt, loc);
5161
5162 parser->in_if_block = in_if_block;
5163 }
5164
5165 /* Parse the condition from an if, do, while or for statements. */
5166
5167 static tree
5168 c_parser_condition (c_parser *parser)
5169 {
5170 location_t loc = c_parser_peek_token (parser)->location;
5171 tree cond;
5172 cond = c_parser_expression_conv (parser).value;
5173 cond = c_objc_common_truthvalue_conversion (loc, cond);
5174 cond = c_fully_fold (cond, false, NULL);
5175 if (warn_sequence_point)
5176 verify_sequence_points (cond);
5177 return cond;
5178 }
5179
5180 /* Parse a parenthesized condition from an if, do or while statement.
5181
5182 condition:
5183 ( expression )
5184 */
5185 static tree
5186 c_parser_paren_condition (c_parser *parser)
5187 {
5188 tree cond;
5189 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5190 return error_mark_node;
5191 cond = c_parser_condition (parser);
5192 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5193 return cond;
5194 }
5195
5196 /* Parse a statement which is a block in C99. */
5197
5198 static tree
5199 c_parser_c99_block_statement (c_parser *parser)
5200 {
5201 tree block = c_begin_compound_stmt (flag_isoc99);
5202 location_t loc = c_parser_peek_token (parser)->location;
5203 c_parser_statement (parser);
5204 return c_end_compound_stmt (loc, block, flag_isoc99);
5205 }
5206
5207 /* Parse the body of an if statement. This is just parsing a
5208 statement but (a) it is a block in C99, (b) we track whether the
5209 body is an if statement for the sake of -Wparentheses warnings, (c)
5210 we handle an empty body specially for the sake of -Wempty-body
5211 warnings, and (d) we call parser_compound_statement directly
5212 because c_parser_statement_after_labels resets
5213 parser->in_if_block. */
5214
5215 static tree
5216 c_parser_if_body (c_parser *parser, bool *if_p,
5217 const token_indent_info &if_tinfo)
5218 {
5219 tree block = c_begin_compound_stmt (flag_isoc99);
5220 location_t body_loc = c_parser_peek_token (parser)->location;
5221 token_indent_info body_tinfo
5222 = get_token_indent_info (c_parser_peek_token (parser));
5223
5224 c_parser_all_labels (parser);
5225 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
5226 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5227 {
5228 location_t loc = c_parser_peek_token (parser)->location;
5229 add_stmt (build_empty_stmt (loc));
5230 c_parser_consume_token (parser);
5231 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5232 warning_at (loc, OPT_Wempty_body,
5233 "suggest braces around empty body in an %<if%> statement");
5234 }
5235 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5236 add_stmt (c_parser_compound_statement (parser));
5237 else
5238 c_parser_statement_after_labels (parser);
5239
5240 token_indent_info next_tinfo
5241 = get_token_indent_info (c_parser_peek_token (parser));
5242 warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo);
5243
5244 return c_end_compound_stmt (body_loc, block, flag_isoc99);
5245 }
5246
5247 /* Parse the else body of an if statement. This is just parsing a
5248 statement but (a) it is a block in C99, (b) we handle an empty body
5249 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5250 of if-else-if conditions. */
5251
5252 static tree
5253 c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
5254 vec<tree> *chain)
5255 {
5256 location_t body_loc = c_parser_peek_token (parser)->location;
5257 tree block = c_begin_compound_stmt (flag_isoc99);
5258 token_indent_info body_tinfo
5259 = get_token_indent_info (c_parser_peek_token (parser));
5260
5261 c_parser_all_labels (parser);
5262 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5263 {
5264 location_t loc = c_parser_peek_token (parser)->location;
5265 warning_at (loc,
5266 OPT_Wempty_body,
5267 "suggest braces around empty body in an %<else%> statement");
5268 add_stmt (build_empty_stmt (loc));
5269 c_parser_consume_token (parser);
5270 }
5271 else
5272 c_parser_statement_after_labels (parser, chain);
5273
5274 token_indent_info next_tinfo
5275 = get_token_indent_info (c_parser_peek_token (parser));
5276 warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo);
5277
5278 return c_end_compound_stmt (body_loc, block, flag_isoc99);
5279 }
5280
5281 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5282
5283 if-statement:
5284 if ( expression ) statement
5285 if ( expression ) statement else statement
5286
5287 CHAIN is a vector of if-else-if conditions. */
5288
5289 static void
5290 c_parser_if_statement (c_parser *parser, vec<tree> *chain)
5291 {
5292 tree block;
5293 location_t loc;
5294 tree cond;
5295 bool first_if = false;
5296 tree first_body, second_body;
5297 bool in_if_block;
5298 tree if_stmt;
5299
5300 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5301 token_indent_info if_tinfo
5302 = get_token_indent_info (c_parser_peek_token (parser));
5303 c_parser_consume_token (parser);
5304 block = c_begin_compound_stmt (flag_isoc99);
5305 loc = c_parser_peek_token (parser)->location;
5306 cond = c_parser_paren_condition (parser);
5307 if (flag_cilkplus && contains_cilk_spawn_stmt (cond))
5308 {
5309 error_at (loc, "if statement cannot contain %<Cilk_spawn%>");
5310 cond = error_mark_node;
5311 }
5312 in_if_block = parser->in_if_block;
5313 parser->in_if_block = true;
5314 first_body = c_parser_if_body (parser, &first_if, if_tinfo);
5315 parser->in_if_block = in_if_block;
5316
5317 if (warn_duplicated_cond)
5318 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain);
5319
5320 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5321 {
5322 token_indent_info else_tinfo
5323 = get_token_indent_info (c_parser_peek_token (parser));
5324 c_parser_consume_token (parser);
5325 if (warn_duplicated_cond)
5326 {
5327 if (c_parser_next_token_is_keyword (parser, RID_IF)
5328 && chain == NULL)
5329 {
5330 /* We've got "if (COND) else if (COND2)". Start the
5331 condition chain and add COND as the first element. */
5332 chain = new vec<tree> ();
5333 if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond))
5334 chain->safe_push (cond);
5335 }
5336 else if (!c_parser_next_token_is_keyword (parser, RID_IF))
5337 {
5338 /* This is if-else without subsequent if. Zap the condition
5339 chain; we would have already warned at this point. */
5340 delete chain;
5341 chain = NULL;
5342 }
5343 }
5344 second_body = c_parser_else_body (parser, else_tinfo, chain);
5345 }
5346 else
5347 {
5348 second_body = NULL_TREE;
5349 if (warn_duplicated_cond)
5350 {
5351 /* This if statement does not have an else clause. We don't
5352 need the condition chain anymore. */
5353 delete chain;
5354 chain = NULL;
5355 }
5356 }
5357 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
5358 if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
5359
5360 /* If the if statement contains array notations, then we expand them. */
5361 if (flag_cilkplus && contains_array_notation_expr (if_stmt))
5362 if_stmt = fix_conditional_array_notations (if_stmt);
5363 add_stmt (if_stmt);
5364 }
5365
5366 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5367
5368 switch-statement:
5369 switch (expression) statement
5370 */
5371
5372 static void
5373 c_parser_switch_statement (c_parser *parser)
5374 {
5375 struct c_expr ce;
5376 tree block, expr, body, save_break;
5377 location_t switch_loc = c_parser_peek_token (parser)->location;
5378 location_t switch_cond_loc;
5379 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5380 c_parser_consume_token (parser);
5381 block = c_begin_compound_stmt (flag_isoc99);
5382 bool explicit_cast_p = false;
5383 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5384 {
5385 switch_cond_loc = c_parser_peek_token (parser)->location;
5386 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5387 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5388 explicit_cast_p = true;
5389 ce = c_parser_expression (parser);
5390 ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5391 expr = ce.value;
5392 /* ??? expr has no valid location? */
5393 if (check_no_cilk (expr,
5394 "Cilk array notation cannot be used as a condition for switch statement",
5395 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5396 switch_cond_loc))
5397 expr = error_mark_node;
5398 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5399 }
5400 else
5401 {
5402 switch_cond_loc = UNKNOWN_LOCATION;
5403 expr = error_mark_node;
5404 }
5405 c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5406 save_break = c_break_label;
5407 c_break_label = NULL_TREE;
5408 body = c_parser_c99_block_statement (parser);
5409 c_finish_case (body, ce.original_type);
5410 if (c_break_label)
5411 {
5412 location_t here = c_parser_peek_token (parser)->location;
5413 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5414 SET_EXPR_LOCATION (t, here);
5415 add_stmt (t);
5416 }
5417 c_break_label = save_break;
5418 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5419 }
5420
5421 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5422
5423 while-statement:
5424 while (expression) statement
5425 */
5426
5427 static void
5428 c_parser_while_statement (c_parser *parser, bool ivdep)
5429 {
5430 tree block, cond, body, save_break, save_cont;
5431 location_t loc;
5432 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5433 token_indent_info while_tinfo
5434 = get_token_indent_info (c_parser_peek_token (parser));
5435 c_parser_consume_token (parser);
5436 block = c_begin_compound_stmt (flag_isoc99);
5437 loc = c_parser_peek_token (parser)->location;
5438 cond = c_parser_paren_condition (parser);
5439 if (check_no_cilk (cond,
5440 "Cilk array notation cannot be used as a condition for while statement",
5441 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5442 cond = error_mark_node;
5443 if (ivdep && cond != error_mark_node)
5444 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5445 build_int_cst (integer_type_node,
5446 annot_expr_ivdep_kind));
5447 save_break = c_break_label;
5448 c_break_label = NULL_TREE;
5449 save_cont = c_cont_label;
5450 c_cont_label = NULL_TREE;
5451
5452 token_indent_info body_tinfo
5453 = get_token_indent_info (c_parser_peek_token (parser));
5454
5455 body = c_parser_c99_block_statement (parser);
5456 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5457 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5458
5459 token_indent_info next_tinfo
5460 = get_token_indent_info (c_parser_peek_token (parser));
5461 warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo);
5462
5463 c_break_label = save_break;
5464 c_cont_label = save_cont;
5465 }
5466
5467 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5468
5469 do-statement:
5470 do statement while ( expression ) ;
5471 */
5472
5473 static void
5474 c_parser_do_statement (c_parser *parser, bool ivdep)
5475 {
5476 tree block, cond, body, save_break, save_cont, new_break, new_cont;
5477 location_t loc;
5478 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5479 c_parser_consume_token (parser);
5480 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5481 warning_at (c_parser_peek_token (parser)->location,
5482 OPT_Wempty_body,
5483 "suggest braces around empty body in %<do%> statement");
5484 block = c_begin_compound_stmt (flag_isoc99);
5485 loc = c_parser_peek_token (parser)->location;
5486 save_break = c_break_label;
5487 c_break_label = NULL_TREE;
5488 save_cont = c_cont_label;
5489 c_cont_label = NULL_TREE;
5490 body = c_parser_c99_block_statement (parser);
5491 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5492 new_break = c_break_label;
5493 c_break_label = save_break;
5494 new_cont = c_cont_label;
5495 c_cont_label = save_cont;
5496 cond = c_parser_paren_condition (parser);
5497 if (check_no_cilk (cond,
5498 "Cilk array notation cannot be used as a condition for a do-while statement",
5499 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5500 cond = error_mark_node;
5501 if (ivdep && cond != error_mark_node)
5502 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5503 build_int_cst (integer_type_node,
5504 annot_expr_ivdep_kind));
5505 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5506 c_parser_skip_to_end_of_block_or_statement (parser);
5507 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5508 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5509 }
5510
5511 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5512
5513 for-statement:
5514 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5515 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5516
5517 The form with a declaration is new in C99.
5518
5519 ??? In accordance with the old parser, the declaration may be a
5520 nested function, which is then rejected in check_for_loop_decls,
5521 but does it make any sense for this to be included in the grammar?
5522 Note in particular that the nested function does not include a
5523 trailing ';', whereas the "declaration" production includes one.
5524 Also, can we reject bad declarations earlier and cheaper than
5525 check_for_loop_decls?
5526
5527 In Objective-C, there are two additional variants:
5528
5529 foreach-statement:
5530 for ( expression in expresssion ) statement
5531 for ( declaration in expression ) statement
5532
5533 This is inconsistent with C, because the second variant is allowed
5534 even if c99 is not enabled.
5535
5536 The rest of the comment documents these Objective-C foreach-statement.
5537
5538 Here is the canonical example of the first variant:
5539 for (object in array) { do something with object }
5540 we call the first expression ("object") the "object_expression" and
5541 the second expression ("array") the "collection_expression".
5542 object_expression must be an lvalue of type "id" (a generic Objective-C
5543 object) because the loop works by assigning to object_expression the
5544 various objects from the collection_expression. collection_expression
5545 must evaluate to something of type "id" which responds to the method
5546 countByEnumeratingWithState:objects:count:.
5547
5548 The canonical example of the second variant is:
5549 for (id object in array) { do something with object }
5550 which is completely equivalent to
5551 {
5552 id object;
5553 for (object in array) { do something with object }
5554 }
5555 Note that initizializing 'object' in some way (eg, "for ((object =
5556 xxx) in array) { do something with object }") is possibly
5557 technically valid, but completely pointless as 'object' will be
5558 assigned to something else as soon as the loop starts. We should
5559 most likely reject it (TODO).
5560
5561 The beginning of the Objective-C foreach-statement looks exactly
5562 like the beginning of the for-statement, and we can tell it is a
5563 foreach-statement only because the initial declaration or
5564 expression is terminated by 'in' instead of ';'.
5565 */
5566
5567 static void
5568 c_parser_for_statement (c_parser *parser, bool ivdep)
5569 {
5570 tree block, cond, incr, save_break, save_cont, body;
5571 /* The following are only used when parsing an ObjC foreach statement. */
5572 tree object_expression;
5573 /* Silence the bogus uninitialized warning. */
5574 tree collection_expression = NULL;
5575 location_t loc = c_parser_peek_token (parser)->location;
5576 location_t for_loc = c_parser_peek_token (parser)->location;
5577 bool is_foreach_statement = false;
5578 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
5579 token_indent_info for_tinfo
5580 = get_token_indent_info (c_parser_peek_token (parser));
5581 c_parser_consume_token (parser);
5582 /* Open a compound statement in Objective-C as well, just in case this is
5583 as foreach expression. */
5584 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
5585 cond = error_mark_node;
5586 incr = error_mark_node;
5587 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5588 {
5589 /* Parse the initialization declaration or expression. */
5590 object_expression = error_mark_node;
5591 parser->objc_could_be_foreach_context = c_dialect_objc ();
5592 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5593 {
5594 parser->objc_could_be_foreach_context = false;
5595 c_parser_consume_token (parser);
5596 c_finish_expr_stmt (loc, NULL_TREE);
5597 }
5598 else if (c_parser_next_tokens_start_declaration (parser))
5599 {
5600 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
5601 &object_expression, vNULL);
5602 parser->objc_could_be_foreach_context = false;
5603
5604 if (c_parser_next_token_is_keyword (parser, RID_IN))
5605 {
5606 c_parser_consume_token (parser);
5607 is_foreach_statement = true;
5608 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5609 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5610 }
5611 else
5612 check_for_loop_decls (for_loc, flag_isoc99);
5613 }
5614 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5615 {
5616 /* __extension__ can start a declaration, but is also an
5617 unary operator that can start an expression. Consume all
5618 but the last of a possible series of __extension__ to
5619 determine which. */
5620 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5621 && (c_parser_peek_2nd_token (parser)->keyword
5622 == RID_EXTENSION))
5623 c_parser_consume_token (parser);
5624 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5625 {
5626 int ext;
5627 ext = disable_extension_diagnostics ();
5628 c_parser_consume_token (parser);
5629 c_parser_declaration_or_fndef (parser, true, true, true, true,
5630 true, &object_expression, vNULL);
5631 parser->objc_could_be_foreach_context = false;
5632
5633 restore_extension_diagnostics (ext);
5634 if (c_parser_next_token_is_keyword (parser, RID_IN))
5635 {
5636 c_parser_consume_token (parser);
5637 is_foreach_statement = true;
5638 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5639 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5640 }
5641 else
5642 check_for_loop_decls (for_loc, flag_isoc99);
5643 }
5644 else
5645 goto init_expr;
5646 }
5647 else
5648 {
5649 init_expr:
5650 {
5651 struct c_expr ce;
5652 tree init_expression;
5653 ce = c_parser_expression (parser);
5654 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5655 level statement", but it works just fine, so allow it. */
5656 init_expression = ce.value;
5657 parser->objc_could_be_foreach_context = false;
5658 if (c_parser_next_token_is_keyword (parser, RID_IN))
5659 {
5660 c_parser_consume_token (parser);
5661 is_foreach_statement = true;
5662 if (! lvalue_p (init_expression))
5663 c_parser_error (parser, "invalid iterating variable in fast enumeration");
5664 object_expression = c_fully_fold (init_expression, false, NULL);
5665 }
5666 else
5667 {
5668 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5669 init_expression = ce.value;
5670 c_finish_expr_stmt (loc, init_expression);
5671 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5672 }
5673 }
5674 }
5675 /* Parse the loop condition. In the case of a foreach
5676 statement, there is no loop condition. */
5677 gcc_assert (!parser->objc_could_be_foreach_context);
5678 if (!is_foreach_statement)
5679 {
5680 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5681 {
5682 if (ivdep)
5683 {
5684 c_parser_error (parser, "missing loop condition in loop with "
5685 "%<GCC ivdep%> pragma");
5686 cond = error_mark_node;
5687 }
5688 else
5689 {
5690 c_parser_consume_token (parser);
5691 cond = NULL_TREE;
5692 }
5693 }
5694 else
5695 {
5696 cond = c_parser_condition (parser);
5697 if (check_no_cilk (cond,
5698 "Cilk array notation cannot be used in a condition for a for-loop",
5699 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5700 cond = error_mark_node;
5701 c_parser_skip_until_found (parser, CPP_SEMICOLON,
5702 "expected %<;%>");
5703 }
5704 if (ivdep && cond != error_mark_node)
5705 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5706 build_int_cst (integer_type_node,
5707 annot_expr_ivdep_kind));
5708 }
5709 /* Parse the increment expression (the third expression in a
5710 for-statement). In the case of a foreach-statement, this is
5711 the expression that follows the 'in'. */
5712 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5713 {
5714 if (is_foreach_statement)
5715 {
5716 c_parser_error (parser, "missing collection in fast enumeration");
5717 collection_expression = error_mark_node;
5718 }
5719 else
5720 incr = c_process_expr_stmt (loc, NULL_TREE);
5721 }
5722 else
5723 {
5724 if (is_foreach_statement)
5725 collection_expression = c_fully_fold (c_parser_expression (parser).value,
5726 false, NULL);
5727 else
5728 {
5729 struct c_expr ce = c_parser_expression (parser);
5730 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5731 incr = c_process_expr_stmt (loc, ce.value);
5732 }
5733 }
5734 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5735 }
5736 save_break = c_break_label;
5737 c_break_label = NULL_TREE;
5738 save_cont = c_cont_label;
5739 c_cont_label = NULL_TREE;
5740
5741 token_indent_info body_tinfo
5742 = get_token_indent_info (c_parser_peek_token (parser));
5743
5744 body = c_parser_c99_block_statement (parser);
5745
5746 if (is_foreach_statement)
5747 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5748 else
5749 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5750 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5751
5752 /* We might need to reclassify any previously-lexed identifier, e.g.
5753 when we've left a for loop with an if-statement without else in the
5754 body - we might have used a wrong scope for the token. See PR67784. */
5755 if (c_parser_next_token_is (parser, CPP_NAME))
5756 {
5757 c_token *token = c_parser_peek_token (parser);
5758 tree decl = lookup_name (token->value);
5759 if (decl == NULL_TREE)
5760 ;
5761 else if (TREE_CODE (decl) == TYPE_DECL)
5762 token->id_kind = C_ID_TYPENAME;
5763 else if (VAR_P (decl))
5764 token->id_kind = C_ID_ID;
5765 }
5766
5767 token_indent_info next_tinfo
5768 = get_token_indent_info (c_parser_peek_token (parser));
5769 warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo);
5770
5771 c_break_label = save_break;
5772 c_cont_label = save_cont;
5773 }
5774
5775 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5776 statement with inputs, outputs, clobbers, and volatile tag
5777 allowed.
5778
5779 asm-statement:
5780 asm type-qualifier[opt] ( asm-argument ) ;
5781 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5782
5783 asm-argument:
5784 asm-string-literal
5785 asm-string-literal : asm-operands[opt]
5786 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5787 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5788
5789 asm-goto-argument:
5790 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5791 : asm-goto-operands
5792
5793 Qualifiers other than volatile are accepted in the syntax but
5794 warned for. */
5795
5796 static tree
5797 c_parser_asm_statement (c_parser *parser)
5798 {
5799 tree quals, str, outputs, inputs, clobbers, labels, ret;
5800 bool simple, is_goto;
5801 location_t asm_loc = c_parser_peek_token (parser)->location;
5802 int section, nsections;
5803
5804 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5805 c_parser_consume_token (parser);
5806 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5807 {
5808 quals = c_parser_peek_token (parser)->value;
5809 c_parser_consume_token (parser);
5810 }
5811 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5812 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5813 {
5814 warning_at (c_parser_peek_token (parser)->location,
5815 0,
5816 "%E qualifier ignored on asm",
5817 c_parser_peek_token (parser)->value);
5818 quals = NULL_TREE;
5819 c_parser_consume_token (parser);
5820 }
5821 else
5822 quals = NULL_TREE;
5823
5824 is_goto = false;
5825 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5826 {
5827 c_parser_consume_token (parser);
5828 is_goto = true;
5829 }
5830
5831 /* ??? Follow the C++ parser rather than using the
5832 lex_untranslated_string kludge. */
5833 parser->lex_untranslated_string = true;
5834 ret = NULL;
5835
5836 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5837 goto error;
5838
5839 str = c_parser_asm_string_literal (parser);
5840 if (str == NULL_TREE)
5841 goto error_close_paren;
5842
5843 simple = true;
5844 outputs = NULL_TREE;
5845 inputs = NULL_TREE;
5846 clobbers = NULL_TREE;
5847 labels = NULL_TREE;
5848
5849 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5850 goto done_asm;
5851
5852 /* Parse each colon-delimited section of operands. */
5853 nsections = 3 + is_goto;
5854 for (section = 0; section < nsections; ++section)
5855 {
5856 if (!c_parser_require (parser, CPP_COLON,
5857 is_goto
5858 ? "expected %<:%>"
5859 : "expected %<:%> or %<)%>"))
5860 goto error_close_paren;
5861
5862 /* Once past any colon, we're no longer a simple asm. */
5863 simple = false;
5864
5865 if ((!c_parser_next_token_is (parser, CPP_COLON)
5866 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5867 || section == 3)
5868 switch (section)
5869 {
5870 case 0:
5871 /* For asm goto, we don't allow output operands, but reserve
5872 the slot for a future extension that does allow them. */
5873 if (!is_goto)
5874 outputs = c_parser_asm_operands (parser);
5875 break;
5876 case 1:
5877 inputs = c_parser_asm_operands (parser);
5878 break;
5879 case 2:
5880 clobbers = c_parser_asm_clobbers (parser);
5881 break;
5882 case 3:
5883 labels = c_parser_asm_goto_operands (parser);
5884 break;
5885 default:
5886 gcc_unreachable ();
5887 }
5888
5889 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5890 goto done_asm;
5891 }
5892
5893 done_asm:
5894 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5895 {
5896 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5897 goto error;
5898 }
5899
5900 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5901 c_parser_skip_to_end_of_block_or_statement (parser);
5902
5903 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5904 clobbers, labels, simple));
5905
5906 error:
5907 parser->lex_untranslated_string = false;
5908 return ret;
5909
5910 error_close_paren:
5911 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5912 goto error;
5913 }
5914
5915 /* Parse asm operands, a GNU extension.
5916
5917 asm-operands:
5918 asm-operand
5919 asm-operands , asm-operand
5920
5921 asm-operand:
5922 asm-string-literal ( expression )
5923 [ identifier ] asm-string-literal ( expression )
5924 */
5925
5926 static tree
5927 c_parser_asm_operands (c_parser *parser)
5928 {
5929 tree list = NULL_TREE;
5930 while (true)
5931 {
5932 tree name, str;
5933 struct c_expr expr;
5934 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5935 {
5936 c_parser_consume_token (parser);
5937 if (c_parser_next_token_is (parser, CPP_NAME))
5938 {
5939 tree id = c_parser_peek_token (parser)->value;
5940 c_parser_consume_token (parser);
5941 name = build_string (IDENTIFIER_LENGTH (id),
5942 IDENTIFIER_POINTER (id));
5943 }
5944 else
5945 {
5946 c_parser_error (parser, "expected identifier");
5947 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5948 return NULL_TREE;
5949 }
5950 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5951 "expected %<]%>");
5952 }
5953 else
5954 name = NULL_TREE;
5955 str = c_parser_asm_string_literal (parser);
5956 if (str == NULL_TREE)
5957 return NULL_TREE;
5958 parser->lex_untranslated_string = false;
5959 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5960 {
5961 parser->lex_untranslated_string = true;
5962 return NULL_TREE;
5963 }
5964 expr = c_parser_expression (parser);
5965 mark_exp_read (expr.value);
5966 parser->lex_untranslated_string = true;
5967 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5968 {
5969 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5970 return NULL_TREE;
5971 }
5972 list = chainon (list, build_tree_list (build_tree_list (name, str),
5973 expr.value));
5974 if (c_parser_next_token_is (parser, CPP_COMMA))
5975 c_parser_consume_token (parser);
5976 else
5977 break;
5978 }
5979 return list;
5980 }
5981
5982 /* Parse asm clobbers, a GNU extension.
5983
5984 asm-clobbers:
5985 asm-string-literal
5986 asm-clobbers , asm-string-literal
5987 */
5988
5989 static tree
5990 c_parser_asm_clobbers (c_parser *parser)
5991 {
5992 tree list = NULL_TREE;
5993 while (true)
5994 {
5995 tree str = c_parser_asm_string_literal (parser);
5996 if (str)
5997 list = tree_cons (NULL_TREE, str, list);
5998 else
5999 return NULL_TREE;
6000 if (c_parser_next_token_is (parser, CPP_COMMA))
6001 c_parser_consume_token (parser);
6002 else
6003 break;
6004 }
6005 return list;
6006 }
6007
6008 /* Parse asm goto labels, a GNU extension.
6009
6010 asm-goto-operands:
6011 identifier
6012 asm-goto-operands , identifier
6013 */
6014
6015 static tree
6016 c_parser_asm_goto_operands (c_parser *parser)
6017 {
6018 tree list = NULL_TREE;
6019 while (true)
6020 {
6021 tree name, label;
6022
6023 if (c_parser_next_token_is (parser, CPP_NAME))
6024 {
6025 c_token *tok = c_parser_peek_token (parser);
6026 name = tok->value;
6027 label = lookup_label_for_goto (tok->location, name);
6028 c_parser_consume_token (parser);
6029 TREE_USED (label) = 1;
6030 }
6031 else
6032 {
6033 c_parser_error (parser, "expected identifier");
6034 return NULL_TREE;
6035 }
6036
6037 name = build_string (IDENTIFIER_LENGTH (name),
6038 IDENTIFIER_POINTER (name));
6039 list = tree_cons (name, label, list);
6040 if (c_parser_next_token_is (parser, CPP_COMMA))
6041 c_parser_consume_token (parser);
6042 else
6043 return nreverse (list);
6044 }
6045 }
6046
6047 /* Parse an expression other than a compound expression; that is, an
6048 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6049 NULL then it is an Objective-C message expression which is the
6050 primary-expression starting the expression as an initializer.
6051
6052 assignment-expression:
6053 conditional-expression
6054 unary-expression assignment-operator assignment-expression
6055
6056 assignment-operator: one of
6057 = *= /= %= += -= <<= >>= &= ^= |=
6058
6059 In GNU C we accept any conditional expression on the LHS and
6060 diagnose the invalid lvalue rather than producing a syntax
6061 error. */
6062
6063 static struct c_expr
6064 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
6065 tree omp_atomic_lhs)
6066 {
6067 struct c_expr lhs, rhs, ret;
6068 enum tree_code code;
6069 location_t op_location, exp_location;
6070 gcc_assert (!after || c_dialect_objc ());
6071 lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
6072 op_location = c_parser_peek_token (parser)->location;
6073 switch (c_parser_peek_token (parser)->type)
6074 {
6075 case CPP_EQ:
6076 code = NOP_EXPR;
6077 break;
6078 case CPP_MULT_EQ:
6079 code = MULT_EXPR;
6080 break;
6081 case CPP_DIV_EQ:
6082 code = TRUNC_DIV_EXPR;
6083 break;
6084 case CPP_MOD_EQ:
6085 code = TRUNC_MOD_EXPR;
6086 break;
6087 case CPP_PLUS_EQ:
6088 code = PLUS_EXPR;
6089 break;
6090 case CPP_MINUS_EQ:
6091 code = MINUS_EXPR;
6092 break;
6093 case CPP_LSHIFT_EQ:
6094 code = LSHIFT_EXPR;
6095 break;
6096 case CPP_RSHIFT_EQ:
6097 code = RSHIFT_EXPR;
6098 break;
6099 case CPP_AND_EQ:
6100 code = BIT_AND_EXPR;
6101 break;
6102 case CPP_XOR_EQ:
6103 code = BIT_XOR_EXPR;
6104 break;
6105 case CPP_OR_EQ:
6106 code = BIT_IOR_EXPR;
6107 break;
6108 default:
6109 return lhs;
6110 }
6111 c_parser_consume_token (parser);
6112 exp_location = c_parser_peek_token (parser)->location;
6113 rhs = c_parser_expr_no_commas (parser, NULL);
6114 rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
6115
6116 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
6117 code, exp_location, rhs.value,
6118 rhs.original_type);
6119 if (code == NOP_EXPR)
6120 ret.original_code = MODIFY_EXPR;
6121 else
6122 {
6123 TREE_NO_WARNING (ret.value) = 1;
6124 ret.original_code = ERROR_MARK;
6125 }
6126 ret.original_type = NULL;
6127 return ret;
6128 }
6129
6130 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6131 is not NULL then it is an Objective-C message expression which is
6132 the primary-expression starting the expression as an initializer.
6133
6134 conditional-expression:
6135 logical-OR-expression
6136 logical-OR-expression ? expression : conditional-expression
6137
6138 GNU extensions:
6139
6140 conditional-expression:
6141 logical-OR-expression ? : conditional-expression
6142 */
6143
6144 static struct c_expr
6145 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6146 tree omp_atomic_lhs)
6147 {
6148 struct c_expr cond, exp1, exp2, ret;
6149 location_t cond_loc, colon_loc, middle_loc;
6150
6151 gcc_assert (!after || c_dialect_objc ());
6152
6153 cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6154
6155 if (c_parser_next_token_is_not (parser, CPP_QUERY))
6156 return cond;
6157 cond_loc = c_parser_peek_token (parser)->location;
6158 cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6159 c_parser_consume_token (parser);
6160 if (c_parser_next_token_is (parser, CPP_COLON))
6161 {
6162 tree eptype = NULL_TREE;
6163
6164 middle_loc = c_parser_peek_token (parser)->location;
6165 pedwarn (middle_loc, OPT_Wpedantic,
6166 "ISO C forbids omitting the middle term of a ?: expression");
6167 warn_for_omitted_condop (middle_loc, cond.value);
6168 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6169 {
6170 eptype = TREE_TYPE (cond.value);
6171 cond.value = TREE_OPERAND (cond.value, 0);
6172 }
6173 /* Make sure first operand is calculated only once. */
6174 exp1.value = c_save_expr (default_conversion (cond.value));
6175 if (eptype)
6176 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6177 exp1.original_type = NULL;
6178 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6179 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6180 }
6181 else
6182 {
6183 cond.value
6184 = c_objc_common_truthvalue_conversion
6185 (cond_loc, default_conversion (cond.value));
6186 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6187 exp1 = c_parser_expression_conv (parser);
6188 mark_exp_read (exp1.value);
6189 c_inhibit_evaluation_warnings +=
6190 ((cond.value == truthvalue_true_node)
6191 - (cond.value == truthvalue_false_node));
6192 }
6193
6194 colon_loc = c_parser_peek_token (parser)->location;
6195 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6196 {
6197 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6198 ret.value = error_mark_node;
6199 ret.original_code = ERROR_MARK;
6200 ret.original_type = NULL;
6201 return ret;
6202 }
6203 {
6204 location_t exp2_loc = c_parser_peek_token (parser)->location;
6205 exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6206 exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6207 }
6208 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6209 ret.value = build_conditional_expr (colon_loc, cond.value,
6210 cond.original_code == C_MAYBE_CONST_EXPR,
6211 exp1.value, exp1.original_type,
6212 exp2.value, exp2.original_type);
6213 ret.original_code = ERROR_MARK;
6214 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6215 ret.original_type = NULL;
6216 else
6217 {
6218 tree t1, t2;
6219
6220 /* If both sides are enum type, the default conversion will have
6221 made the type of the result be an integer type. We want to
6222 remember the enum types we started with. */
6223 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6224 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6225 ret.original_type = ((t1 != error_mark_node
6226 && t2 != error_mark_node
6227 && (TYPE_MAIN_VARIANT (t1)
6228 == TYPE_MAIN_VARIANT (t2)))
6229 ? t1
6230 : NULL);
6231 }
6232 return ret;
6233 }
6234
6235 /* Parse a binary expression; that is, a logical-OR-expression (C90
6236 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6237 an Objective-C message expression which is the primary-expression
6238 starting the expression as an initializer.
6239
6240 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6241 when it should be the unfolded lhs. In a valid OpenMP source,
6242 one of the operands of the toplevel binary expression must be equal
6243 to it. In that case, just return a build2 created binary operation
6244 rather than result of parser_build_binary_op.
6245
6246 multiplicative-expression:
6247 cast-expression
6248 multiplicative-expression * cast-expression
6249 multiplicative-expression / cast-expression
6250 multiplicative-expression % cast-expression
6251
6252 additive-expression:
6253 multiplicative-expression
6254 additive-expression + multiplicative-expression
6255 additive-expression - multiplicative-expression
6256
6257 shift-expression:
6258 additive-expression
6259 shift-expression << additive-expression
6260 shift-expression >> additive-expression
6261
6262 relational-expression:
6263 shift-expression
6264 relational-expression < shift-expression
6265 relational-expression > shift-expression
6266 relational-expression <= shift-expression
6267 relational-expression >= shift-expression
6268
6269 equality-expression:
6270 relational-expression
6271 equality-expression == relational-expression
6272 equality-expression != relational-expression
6273
6274 AND-expression:
6275 equality-expression
6276 AND-expression & equality-expression
6277
6278 exclusive-OR-expression:
6279 AND-expression
6280 exclusive-OR-expression ^ AND-expression
6281
6282 inclusive-OR-expression:
6283 exclusive-OR-expression
6284 inclusive-OR-expression | exclusive-OR-expression
6285
6286 logical-AND-expression:
6287 inclusive-OR-expression
6288 logical-AND-expression && inclusive-OR-expression
6289
6290 logical-OR-expression:
6291 logical-AND-expression
6292 logical-OR-expression || logical-AND-expression
6293 */
6294
6295 static struct c_expr
6296 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6297 tree omp_atomic_lhs)
6298 {
6299 /* A binary expression is parsed using operator-precedence parsing,
6300 with the operands being cast expressions. All the binary
6301 operators are left-associative. Thus a binary expression is of
6302 form:
6303
6304 E0 op1 E1 op2 E2 ...
6305
6306 which we represent on a stack. On the stack, the precedence
6307 levels are strictly increasing. When a new operator is
6308 encountered of higher precedence than that at the top of the
6309 stack, it is pushed; its LHS is the top expression, and its RHS
6310 is everything parsed until it is popped. When a new operator is
6311 encountered with precedence less than or equal to that at the top
6312 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6313 by the result of the operation until the operator at the top of
6314 the stack has lower precedence than the new operator or there is
6315 only one element on the stack; then the top expression is the LHS
6316 of the new operator. In the case of logical AND and OR
6317 expressions, we also need to adjust c_inhibit_evaluation_warnings
6318 as appropriate when the operators are pushed and popped. */
6319
6320 struct {
6321 /* The expression at this stack level. */
6322 struct c_expr expr;
6323 /* The precedence of the operator on its left, PREC_NONE at the
6324 bottom of the stack. */
6325 enum c_parser_prec prec;
6326 /* The operation on its left. */
6327 enum tree_code op;
6328 /* The source location of this operation. */
6329 location_t loc;
6330 } stack[NUM_PRECS];
6331 int sp;
6332 /* Location of the binary operator. */
6333 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
6334 #define POP \
6335 do { \
6336 switch (stack[sp].op) \
6337 { \
6338 case TRUTH_ANDIF_EXPR: \
6339 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6340 == truthvalue_false_node); \
6341 break; \
6342 case TRUTH_ORIF_EXPR: \
6343 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6344 == truthvalue_true_node); \
6345 break; \
6346 default: \
6347 break; \
6348 } \
6349 stack[sp - 1].expr \
6350 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6351 stack[sp - 1].expr, true, true); \
6352 stack[sp].expr \
6353 = convert_lvalue_to_rvalue (stack[sp].loc, \
6354 stack[sp].expr, true, true); \
6355 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6356 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6357 && ((1 << stack[sp].prec) \
6358 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6359 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6360 && stack[sp].op != TRUNC_MOD_EXPR \
6361 && stack[0].expr.value != error_mark_node \
6362 && stack[1].expr.value != error_mark_node \
6363 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6364 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6365 stack[0].expr.value \
6366 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6367 stack[0].expr.value, stack[1].expr.value); \
6368 else \
6369 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6370 stack[sp].op, \
6371 stack[sp - 1].expr, \
6372 stack[sp].expr); \
6373 sp--; \
6374 } while (0)
6375 gcc_assert (!after || c_dialect_objc ());
6376 stack[0].loc = c_parser_peek_token (parser)->location;
6377 stack[0].expr = c_parser_cast_expression (parser, after);
6378 stack[0].prec = PREC_NONE;
6379 sp = 0;
6380 while (true)
6381 {
6382 enum c_parser_prec oprec;
6383 enum tree_code ocode;
6384 if (parser->error)
6385 goto out;
6386 switch (c_parser_peek_token (parser)->type)
6387 {
6388 case CPP_MULT:
6389 oprec = PREC_MULT;
6390 ocode = MULT_EXPR;
6391 break;
6392 case CPP_DIV:
6393 oprec = PREC_MULT;
6394 ocode = TRUNC_DIV_EXPR;
6395 break;
6396 case CPP_MOD:
6397 oprec = PREC_MULT;
6398 ocode = TRUNC_MOD_EXPR;
6399 break;
6400 case CPP_PLUS:
6401 oprec = PREC_ADD;
6402 ocode = PLUS_EXPR;
6403 break;
6404 case CPP_MINUS:
6405 oprec = PREC_ADD;
6406 ocode = MINUS_EXPR;
6407 break;
6408 case CPP_LSHIFT:
6409 oprec = PREC_SHIFT;
6410 ocode = LSHIFT_EXPR;
6411 break;
6412 case CPP_RSHIFT:
6413 oprec = PREC_SHIFT;
6414 ocode = RSHIFT_EXPR;
6415 break;
6416 case CPP_LESS:
6417 oprec = PREC_REL;
6418 ocode = LT_EXPR;
6419 break;
6420 case CPP_GREATER:
6421 oprec = PREC_REL;
6422 ocode = GT_EXPR;
6423 break;
6424 case CPP_LESS_EQ:
6425 oprec = PREC_REL;
6426 ocode = LE_EXPR;
6427 break;
6428 case CPP_GREATER_EQ:
6429 oprec = PREC_REL;
6430 ocode = GE_EXPR;
6431 break;
6432 case CPP_EQ_EQ:
6433 oprec = PREC_EQ;
6434 ocode = EQ_EXPR;
6435 break;
6436 case CPP_NOT_EQ:
6437 oprec = PREC_EQ;
6438 ocode = NE_EXPR;
6439 break;
6440 case CPP_AND:
6441 oprec = PREC_BITAND;
6442 ocode = BIT_AND_EXPR;
6443 break;
6444 case CPP_XOR:
6445 oprec = PREC_BITXOR;
6446 ocode = BIT_XOR_EXPR;
6447 break;
6448 case CPP_OR:
6449 oprec = PREC_BITOR;
6450 ocode = BIT_IOR_EXPR;
6451 break;
6452 case CPP_AND_AND:
6453 oprec = PREC_LOGAND;
6454 ocode = TRUTH_ANDIF_EXPR;
6455 break;
6456 case CPP_OR_OR:
6457 oprec = PREC_LOGOR;
6458 ocode = TRUTH_ORIF_EXPR;
6459 break;
6460 default:
6461 /* Not a binary operator, so end of the binary
6462 expression. */
6463 goto out;
6464 }
6465 binary_loc = c_parser_peek_token (parser)->location;
6466 while (oprec <= stack[sp].prec)
6467 POP;
6468 c_parser_consume_token (parser);
6469 switch (ocode)
6470 {
6471 case TRUTH_ANDIF_EXPR:
6472 stack[sp].expr
6473 = convert_lvalue_to_rvalue (stack[sp].loc,
6474 stack[sp].expr, true, true);
6475 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6476 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6477 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6478 == truthvalue_false_node);
6479 break;
6480 case TRUTH_ORIF_EXPR:
6481 stack[sp].expr
6482 = convert_lvalue_to_rvalue (stack[sp].loc,
6483 stack[sp].expr, true, true);
6484 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6485 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6486 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6487 == truthvalue_true_node);
6488 break;
6489 default:
6490 break;
6491 }
6492 sp++;
6493 stack[sp].loc = binary_loc;
6494 stack[sp].expr = c_parser_cast_expression (parser, NULL);
6495 stack[sp].prec = oprec;
6496 stack[sp].op = ocode;
6497 }
6498 out:
6499 while (sp > 0)
6500 POP;
6501 return stack[0].expr;
6502 #undef POP
6503 }
6504
6505 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6506 NULL then it is an Objective-C message expression which is the
6507 primary-expression starting the expression as an initializer.
6508
6509 cast-expression:
6510 unary-expression
6511 ( type-name ) unary-expression
6512 */
6513
6514 static struct c_expr
6515 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
6516 {
6517 location_t cast_loc = c_parser_peek_token (parser)->location;
6518 gcc_assert (!after || c_dialect_objc ());
6519 if (after)
6520 return c_parser_postfix_expression_after_primary (parser,
6521 cast_loc, *after);
6522 /* If the expression begins with a parenthesized type name, it may
6523 be either a cast or a compound literal; we need to see whether
6524 the next character is '{' to tell the difference. If not, it is
6525 an unary expression. Full detection of unknown typenames here
6526 would require a 3-token lookahead. */
6527 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6528 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6529 {
6530 struct c_type_name *type_name;
6531 struct c_expr ret;
6532 struct c_expr expr;
6533 c_parser_consume_token (parser);
6534 type_name = c_parser_type_name (parser);
6535 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6536 if (type_name == NULL)
6537 {
6538 ret.value = error_mark_node;
6539 ret.original_code = ERROR_MARK;
6540 ret.original_type = NULL;
6541 return ret;
6542 }
6543
6544 /* Save casted types in the function's used types hash table. */
6545 used_types_insert (type_name->specs->type);
6546
6547 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6548 return c_parser_postfix_expression_after_paren_type (parser, type_name,
6549 cast_loc);
6550 {
6551 location_t expr_loc = c_parser_peek_token (parser)->location;
6552 expr = c_parser_cast_expression (parser, NULL);
6553 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
6554 }
6555 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
6556 ret.original_code = ERROR_MARK;
6557 ret.original_type = NULL;
6558 return ret;
6559 }
6560 else
6561 return c_parser_unary_expression (parser);
6562 }
6563
6564 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6565
6566 unary-expression:
6567 postfix-expression
6568 ++ unary-expression
6569 -- unary-expression
6570 unary-operator cast-expression
6571 sizeof unary-expression
6572 sizeof ( type-name )
6573
6574 unary-operator: one of
6575 & * + - ~ !
6576
6577 GNU extensions:
6578
6579 unary-expression:
6580 __alignof__ unary-expression
6581 __alignof__ ( type-name )
6582 && identifier
6583
6584 (C11 permits _Alignof with type names only.)
6585
6586 unary-operator: one of
6587 __extension__ __real__ __imag__
6588
6589 Transactional Memory:
6590
6591 unary-expression:
6592 transaction-expression
6593
6594 In addition, the GNU syntax treats ++ and -- as unary operators, so
6595 they may be applied to cast expressions with errors for non-lvalues
6596 given later. */
6597
6598 static struct c_expr
6599 c_parser_unary_expression (c_parser *parser)
6600 {
6601 int ext;
6602 struct c_expr ret, op;
6603 location_t op_loc = c_parser_peek_token (parser)->location;
6604 location_t exp_loc;
6605 ret.original_code = ERROR_MARK;
6606 ret.original_type = NULL;
6607 switch (c_parser_peek_token (parser)->type)
6608 {
6609 case CPP_PLUS_PLUS:
6610 c_parser_consume_token (parser);
6611 exp_loc = c_parser_peek_token (parser)->location;
6612 op = c_parser_cast_expression (parser, NULL);
6613
6614 /* If there is array notations in op, we expand them. */
6615 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6616 return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op);
6617 else
6618 {
6619 op = default_function_array_read_conversion (exp_loc, op);
6620 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
6621 }
6622 case CPP_MINUS_MINUS:
6623 c_parser_consume_token (parser);
6624 exp_loc = c_parser_peek_token (parser)->location;
6625 op = c_parser_cast_expression (parser, NULL);
6626
6627 /* If there is array notations in op, we expand them. */
6628 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6629 return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op);
6630 else
6631 {
6632 op = default_function_array_read_conversion (exp_loc, op);
6633 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
6634 }
6635 case CPP_AND:
6636 c_parser_consume_token (parser);
6637 op = c_parser_cast_expression (parser, NULL);
6638 mark_exp_read (op.value);
6639 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
6640 case CPP_MULT:
6641 c_parser_consume_token (parser);
6642 exp_loc = c_parser_peek_token (parser)->location;
6643 op = c_parser_cast_expression (parser, NULL);
6644 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6645 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
6646 return ret;
6647 case CPP_PLUS:
6648 if (!c_dialect_objc () && !in_system_header_at (input_location))
6649 warning_at (op_loc,
6650 OPT_Wtraditional,
6651 "traditional C rejects the unary plus operator");
6652 c_parser_consume_token (parser);
6653 exp_loc = c_parser_peek_token (parser)->location;
6654 op = c_parser_cast_expression (parser, NULL);
6655 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6656 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
6657 case CPP_MINUS:
6658 c_parser_consume_token (parser);
6659 exp_loc = c_parser_peek_token (parser)->location;
6660 op = c_parser_cast_expression (parser, NULL);
6661 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6662 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
6663 case CPP_COMPL:
6664 c_parser_consume_token (parser);
6665 exp_loc = c_parser_peek_token (parser)->location;
6666 op = c_parser_cast_expression (parser, NULL);
6667 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6668 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
6669 case CPP_NOT:
6670 c_parser_consume_token (parser);
6671 exp_loc = c_parser_peek_token (parser)->location;
6672 op = c_parser_cast_expression (parser, NULL);
6673 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6674 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
6675 case CPP_AND_AND:
6676 /* Refer to the address of a label as a pointer. */
6677 c_parser_consume_token (parser);
6678 if (c_parser_next_token_is (parser, CPP_NAME))
6679 {
6680 ret.value = finish_label_address_expr
6681 (c_parser_peek_token (parser)->value, op_loc);
6682 c_parser_consume_token (parser);
6683 }
6684 else
6685 {
6686 c_parser_error (parser, "expected identifier");
6687 ret.value = error_mark_node;
6688 }
6689 return ret;
6690 case CPP_KEYWORD:
6691 switch (c_parser_peek_token (parser)->keyword)
6692 {
6693 case RID_SIZEOF:
6694 return c_parser_sizeof_expression (parser);
6695 case RID_ALIGNOF:
6696 return c_parser_alignof_expression (parser);
6697 case RID_EXTENSION:
6698 c_parser_consume_token (parser);
6699 ext = disable_extension_diagnostics ();
6700 ret = c_parser_cast_expression (parser, NULL);
6701 restore_extension_diagnostics (ext);
6702 return ret;
6703 case RID_REALPART:
6704 c_parser_consume_token (parser);
6705 exp_loc = c_parser_peek_token (parser)->location;
6706 op = c_parser_cast_expression (parser, NULL);
6707 op = default_function_array_conversion (exp_loc, op);
6708 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
6709 case RID_IMAGPART:
6710 c_parser_consume_token (parser);
6711 exp_loc = c_parser_peek_token (parser)->location;
6712 op = c_parser_cast_expression (parser, NULL);
6713 op = default_function_array_conversion (exp_loc, op);
6714 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
6715 case RID_TRANSACTION_ATOMIC:
6716 case RID_TRANSACTION_RELAXED:
6717 return c_parser_transaction_expression (parser,
6718 c_parser_peek_token (parser)->keyword);
6719 default:
6720 return c_parser_postfix_expression (parser);
6721 }
6722 default:
6723 return c_parser_postfix_expression (parser);
6724 }
6725 }
6726
6727 /* Parse a sizeof expression. */
6728
6729 static struct c_expr
6730 c_parser_sizeof_expression (c_parser *parser)
6731 {
6732 struct c_expr expr;
6733 location_t expr_loc;
6734 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
6735 c_parser_consume_token (parser);
6736 c_inhibit_evaluation_warnings++;
6737 in_sizeof++;
6738 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6739 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6740 {
6741 /* Either sizeof ( type-name ) or sizeof unary-expression
6742 starting with a compound literal. */
6743 struct c_type_name *type_name;
6744 c_parser_consume_token (parser);
6745 expr_loc = c_parser_peek_token (parser)->location;
6746 type_name = c_parser_type_name (parser);
6747 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6748 if (type_name == NULL)
6749 {
6750 struct c_expr ret;
6751 c_inhibit_evaluation_warnings--;
6752 in_sizeof--;
6753 ret.value = error_mark_node;
6754 ret.original_code = ERROR_MARK;
6755 ret.original_type = NULL;
6756 return ret;
6757 }
6758 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6759 {
6760 expr = c_parser_postfix_expression_after_paren_type (parser,
6761 type_name,
6762 expr_loc);
6763 goto sizeof_expr;
6764 }
6765 /* sizeof ( type-name ). */
6766 c_inhibit_evaluation_warnings--;
6767 in_sizeof--;
6768 return c_expr_sizeof_type (expr_loc, type_name);
6769 }
6770 else
6771 {
6772 expr_loc = c_parser_peek_token (parser)->location;
6773 expr = c_parser_unary_expression (parser);
6774 sizeof_expr:
6775 c_inhibit_evaluation_warnings--;
6776 in_sizeof--;
6777 mark_exp_read (expr.value);
6778 if (TREE_CODE (expr.value) == COMPONENT_REF
6779 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
6780 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
6781 return c_expr_sizeof_expr (expr_loc, expr);
6782 }
6783 }
6784
6785 /* Parse an alignof expression. */
6786
6787 static struct c_expr
6788 c_parser_alignof_expression (c_parser *parser)
6789 {
6790 struct c_expr expr;
6791 location_t loc = c_parser_peek_token (parser)->location;
6792 tree alignof_spelling = c_parser_peek_token (parser)->value;
6793 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
6794 bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
6795 "_Alignof") == 0;
6796 /* A diagnostic is not required for the use of this identifier in
6797 the implementation namespace; only diagnose it for the C11
6798 spelling because of existing code using the other spellings. */
6799 if (is_c11_alignof)
6800 {
6801 if (flag_isoc99)
6802 pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
6803 alignof_spelling);
6804 else
6805 pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
6806 alignof_spelling);
6807 }
6808 c_parser_consume_token (parser);
6809 c_inhibit_evaluation_warnings++;
6810 in_alignof++;
6811 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6812 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6813 {
6814 /* Either __alignof__ ( type-name ) or __alignof__
6815 unary-expression starting with a compound literal. */
6816 location_t loc;
6817 struct c_type_name *type_name;
6818 struct c_expr ret;
6819 c_parser_consume_token (parser);
6820 loc = c_parser_peek_token (parser)->location;
6821 type_name = c_parser_type_name (parser);
6822 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6823 if (type_name == NULL)
6824 {
6825 struct c_expr ret;
6826 c_inhibit_evaluation_warnings--;
6827 in_alignof--;
6828 ret.value = error_mark_node;
6829 ret.original_code = ERROR_MARK;
6830 ret.original_type = NULL;
6831 return ret;
6832 }
6833 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6834 {
6835 expr = c_parser_postfix_expression_after_paren_type (parser,
6836 type_name,
6837 loc);
6838 goto alignof_expr;
6839 }
6840 /* alignof ( type-name ). */
6841 c_inhibit_evaluation_warnings--;
6842 in_alignof--;
6843 ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
6844 NULL, NULL),
6845 false, is_c11_alignof, 1);
6846 ret.original_code = ERROR_MARK;
6847 ret.original_type = NULL;
6848 return ret;
6849 }
6850 else
6851 {
6852 struct c_expr ret;
6853 expr = c_parser_unary_expression (parser);
6854 alignof_expr:
6855 mark_exp_read (expr.value);
6856 c_inhibit_evaluation_warnings--;
6857 in_alignof--;
6858 pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
6859 alignof_spelling);
6860 ret.value = c_alignof_expr (loc, expr.value);
6861 ret.original_code = ERROR_MARK;
6862 ret.original_type = NULL;
6863 return ret;
6864 }
6865 }
6866
6867 /* Helper function to read arguments of builtins which are interfaces
6868 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6869 others. The name of the builtin is passed using BNAME parameter.
6870 Function returns true if there were no errors while parsing and
6871 stores the arguments in CEXPR_LIST. */
6872 static bool
6873 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6874 vec<c_expr_t, va_gc> **ret_cexpr_list,
6875 bool choose_expr_p)
6876 {
6877 location_t loc = c_parser_peek_token (parser)->location;
6878 vec<c_expr_t, va_gc> *cexpr_list;
6879 c_expr_t expr;
6880 bool saved_force_folding_builtin_constant_p;
6881
6882 *ret_cexpr_list = NULL;
6883 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6884 {
6885 error_at (loc, "cannot take address of %qs", bname);
6886 return false;
6887 }
6888
6889 c_parser_consume_token (parser);
6890
6891 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6892 {
6893 c_parser_consume_token (parser);
6894 return true;
6895 }
6896
6897 saved_force_folding_builtin_constant_p
6898 = force_folding_builtin_constant_p;
6899 force_folding_builtin_constant_p |= choose_expr_p;
6900 expr = c_parser_expr_no_commas (parser, NULL);
6901 force_folding_builtin_constant_p
6902 = saved_force_folding_builtin_constant_p;
6903 vec_alloc (cexpr_list, 1);
6904 vec_safe_push (cexpr_list, expr);
6905 while (c_parser_next_token_is (parser, CPP_COMMA))
6906 {
6907 c_parser_consume_token (parser);
6908 expr = c_parser_expr_no_commas (parser, NULL);
6909 vec_safe_push (cexpr_list, expr);
6910 }
6911
6912 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6913 return false;
6914
6915 *ret_cexpr_list = cexpr_list;
6916 return true;
6917 }
6918
6919 /* This represents a single generic-association. */
6920
6921 struct c_generic_association
6922 {
6923 /* The location of the starting token of the type. */
6924 location_t type_location;
6925 /* The association's type, or NULL_TREE for 'default'. */
6926 tree type;
6927 /* The association's expression. */
6928 struct c_expr expression;
6929 };
6930
6931 /* Parse a generic-selection. (C11 6.5.1.1).
6932
6933 generic-selection:
6934 _Generic ( assignment-expression , generic-assoc-list )
6935
6936 generic-assoc-list:
6937 generic-association
6938 generic-assoc-list , generic-association
6939
6940 generic-association:
6941 type-name : assignment-expression
6942 default : assignment-expression
6943 */
6944
6945 static struct c_expr
6946 c_parser_generic_selection (c_parser *parser)
6947 {
6948 vec<c_generic_association> associations = vNULL;
6949 struct c_expr selector, error_expr;
6950 tree selector_type;
6951 struct c_generic_association matched_assoc;
6952 bool match_found = false;
6953 location_t generic_loc, selector_loc;
6954
6955 error_expr.original_code = ERROR_MARK;
6956 error_expr.original_type = NULL;
6957 error_expr.value = error_mark_node;
6958 matched_assoc.type_location = UNKNOWN_LOCATION;
6959 matched_assoc.type = NULL_TREE;
6960 matched_assoc.expression = error_expr;
6961
6962 gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
6963 generic_loc = c_parser_peek_token (parser)->location;
6964 c_parser_consume_token (parser);
6965 if (flag_isoc99)
6966 pedwarn_c99 (generic_loc, OPT_Wpedantic,
6967 "ISO C99 does not support %<_Generic%>");
6968 else
6969 pedwarn_c99 (generic_loc, OPT_Wpedantic,
6970 "ISO C90 does not support %<_Generic%>");
6971
6972 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6973 return error_expr;
6974
6975 c_inhibit_evaluation_warnings++;
6976 selector_loc = c_parser_peek_token (parser)->location;
6977 selector = c_parser_expr_no_commas (parser, NULL);
6978 selector = default_function_array_conversion (selector_loc, selector);
6979 c_inhibit_evaluation_warnings--;
6980
6981 if (selector.value == error_mark_node)
6982 {
6983 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6984 return selector;
6985 }
6986 selector_type = TREE_TYPE (selector.value);
6987 /* In ISO C terms, rvalues (including the controlling expression of
6988 _Generic) do not have qualified types. */
6989 if (TREE_CODE (selector_type) != ARRAY_TYPE)
6990 selector_type = TYPE_MAIN_VARIANT (selector_type);
6991 /* In ISO C terms, _Noreturn is not part of the type of expressions
6992 such as &abort, but in GCC it is represented internally as a type
6993 qualifier. */
6994 if (FUNCTION_POINTER_TYPE_P (selector_type)
6995 && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
6996 selector_type
6997 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
6998
6999 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7000 {
7001 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7002 return error_expr;
7003 }
7004
7005 while (1)
7006 {
7007 struct c_generic_association assoc, *iter;
7008 unsigned int ix;
7009 c_token *token = c_parser_peek_token (parser);
7010
7011 assoc.type_location = token->location;
7012 if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
7013 {
7014 c_parser_consume_token (parser);
7015 assoc.type = NULL_TREE;
7016 }
7017 else
7018 {
7019 struct c_type_name *type_name;
7020
7021 type_name = c_parser_type_name (parser);
7022 if (type_name == NULL)
7023 {
7024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7025 goto error_exit;
7026 }
7027 assoc.type = groktypename (type_name, NULL, NULL);
7028 if (assoc.type == error_mark_node)
7029 {
7030 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7031 goto error_exit;
7032 }
7033
7034 if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
7035 error_at (assoc.type_location,
7036 "%<_Generic%> association has function type");
7037 else if (!COMPLETE_TYPE_P (assoc.type))
7038 error_at (assoc.type_location,
7039 "%<_Generic%> association has incomplete type");
7040
7041 if (variably_modified_type_p (assoc.type, NULL_TREE))
7042 error_at (assoc.type_location,
7043 "%<_Generic%> association has "
7044 "variable length type");
7045 }
7046
7047 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7048 {
7049 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7050 goto error_exit;
7051 }
7052
7053 assoc.expression = c_parser_expr_no_commas (parser, NULL);
7054 if (assoc.expression.value == error_mark_node)
7055 {
7056 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7057 goto error_exit;
7058 }
7059
7060 for (ix = 0; associations.iterate (ix, &iter); ++ix)
7061 {
7062 if (assoc.type == NULL_TREE)
7063 {
7064 if (iter->type == NULL_TREE)
7065 {
7066 error_at (assoc.type_location,
7067 "duplicate %<default%> case in %<_Generic%>");
7068 inform (iter->type_location, "original %<default%> is here");
7069 }
7070 }
7071 else if (iter->type != NULL_TREE)
7072 {
7073 if (comptypes (assoc.type, iter->type))
7074 {
7075 error_at (assoc.type_location,
7076 "%<_Generic%> specifies two compatible types");
7077 inform (iter->type_location, "compatible type is here");
7078 }
7079 }
7080 }
7081
7082 if (assoc.type == NULL_TREE)
7083 {
7084 if (!match_found)
7085 {
7086 matched_assoc = assoc;
7087 match_found = true;
7088 }
7089 }
7090 else if (comptypes (assoc.type, selector_type))
7091 {
7092 if (!match_found || matched_assoc.type == NULL_TREE)
7093 {
7094 matched_assoc = assoc;
7095 match_found = true;
7096 }
7097 else
7098 {
7099 error_at (assoc.type_location,
7100 "%<_Generic> selector matches multiple associations");
7101 inform (matched_assoc.type_location,
7102 "other match is here");
7103 }
7104 }
7105
7106 associations.safe_push (assoc);
7107
7108 if (c_parser_peek_token (parser)->type != CPP_COMMA)
7109 break;
7110 c_parser_consume_token (parser);
7111 }
7112
7113 associations.release ();
7114
7115 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7116 {
7117 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7118 return error_expr;
7119 }
7120
7121 if (!match_found)
7122 {
7123 error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7124 "compatible with any association",
7125 selector_type);
7126 return error_expr;
7127 }
7128
7129 return matched_assoc.expression;
7130
7131 error_exit:
7132 associations.release ();
7133 return error_expr;
7134 }
7135
7136 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7137
7138 postfix-expression:
7139 primary-expression
7140 postfix-expression [ expression ]
7141 postfix-expression ( argument-expression-list[opt] )
7142 postfix-expression . identifier
7143 postfix-expression -> identifier
7144 postfix-expression ++
7145 postfix-expression --
7146 ( type-name ) { initializer-list }
7147 ( type-name ) { initializer-list , }
7148
7149 argument-expression-list:
7150 argument-expression
7151 argument-expression-list , argument-expression
7152
7153 primary-expression:
7154 identifier
7155 constant
7156 string-literal
7157 ( expression )
7158 generic-selection
7159
7160 GNU extensions:
7161
7162 primary-expression:
7163 __func__
7164 (treated as a keyword in GNU C)
7165 __FUNCTION__
7166 __PRETTY_FUNCTION__
7167 ( compound-statement )
7168 __builtin_va_arg ( assignment-expression , type-name )
7169 __builtin_offsetof ( type-name , offsetof-member-designator )
7170 __builtin_choose_expr ( assignment-expression ,
7171 assignment-expression ,
7172 assignment-expression )
7173 __builtin_types_compatible_p ( type-name , type-name )
7174 __builtin_complex ( assignment-expression , assignment-expression )
7175 __builtin_shuffle ( assignment-expression , assignment-expression )
7176 __builtin_shuffle ( assignment-expression ,
7177 assignment-expression ,
7178 assignment-expression, )
7179
7180 offsetof-member-designator:
7181 identifier
7182 offsetof-member-designator . identifier
7183 offsetof-member-designator [ expression ]
7184
7185 Objective-C:
7186
7187 primary-expression:
7188 [ objc-receiver objc-message-args ]
7189 @selector ( objc-selector-arg )
7190 @protocol ( identifier )
7191 @encode ( type-name )
7192 objc-string-literal
7193 Classname . identifier
7194 */
7195
7196 static struct c_expr
7197 c_parser_postfix_expression (c_parser *parser)
7198 {
7199 struct c_expr expr, e1;
7200 struct c_type_name *t1, *t2;
7201 location_t loc = c_parser_peek_token (parser)->location;;
7202 expr.original_code = ERROR_MARK;
7203 expr.original_type = NULL;
7204 switch (c_parser_peek_token (parser)->type)
7205 {
7206 case CPP_NUMBER:
7207 expr.value = c_parser_peek_token (parser)->value;
7208 loc = c_parser_peek_token (parser)->location;
7209 c_parser_consume_token (parser);
7210 if (TREE_CODE (expr.value) == FIXED_CST
7211 && !targetm.fixed_point_supported_p ())
7212 {
7213 error_at (loc, "fixed-point types not supported for this target");
7214 expr.value = error_mark_node;
7215 }
7216 break;
7217 case CPP_CHAR:
7218 case CPP_CHAR16:
7219 case CPP_CHAR32:
7220 case CPP_WCHAR:
7221 expr.value = c_parser_peek_token (parser)->value;
7222 c_parser_consume_token (parser);
7223 break;
7224 case CPP_STRING:
7225 case CPP_STRING16:
7226 case CPP_STRING32:
7227 case CPP_WSTRING:
7228 case CPP_UTF8STRING:
7229 expr.value = c_parser_peek_token (parser)->value;
7230 expr.original_code = STRING_CST;
7231 c_parser_consume_token (parser);
7232 break;
7233 case CPP_OBJC_STRING:
7234 gcc_assert (c_dialect_objc ());
7235 expr.value
7236 = objc_build_string_object (c_parser_peek_token (parser)->value);
7237 c_parser_consume_token (parser);
7238 break;
7239 case CPP_NAME:
7240 switch (c_parser_peek_token (parser)->id_kind)
7241 {
7242 case C_ID_ID:
7243 {
7244 tree id = c_parser_peek_token (parser)->value;
7245 c_parser_consume_token (parser);
7246 expr.value = build_external_ref (loc, id,
7247 (c_parser_peek_token (parser)->type
7248 == CPP_OPEN_PAREN),
7249 &expr.original_type);
7250 break;
7251 }
7252 case C_ID_CLASSNAME:
7253 {
7254 /* Here we parse the Objective-C 2.0 Class.name dot
7255 syntax. */
7256 tree class_name = c_parser_peek_token (parser)->value;
7257 tree component;
7258 c_parser_consume_token (parser);
7259 gcc_assert (c_dialect_objc ());
7260 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7261 {
7262 expr.value = error_mark_node;
7263 break;
7264 }
7265 if (c_parser_next_token_is_not (parser, CPP_NAME))
7266 {
7267 c_parser_error (parser, "expected identifier");
7268 expr.value = error_mark_node;
7269 break;
7270 }
7271 component = c_parser_peek_token (parser)->value;
7272 c_parser_consume_token (parser);
7273 expr.value = objc_build_class_component_ref (class_name,
7274 component);
7275 break;
7276 }
7277 default:
7278 c_parser_error (parser, "expected expression");
7279 expr.value = error_mark_node;
7280 break;
7281 }
7282 break;
7283 case CPP_OPEN_PAREN:
7284 /* A parenthesized expression, statement expression or compound
7285 literal. */
7286 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7287 {
7288 /* A statement expression. */
7289 tree stmt;
7290 location_t brace_loc;
7291 c_parser_consume_token (parser);
7292 brace_loc = c_parser_peek_token (parser)->location;
7293 c_parser_consume_token (parser);
7294 if (!building_stmt_list_p ())
7295 {
7296 error_at (loc, "braced-group within expression allowed "
7297 "only inside a function");
7298 parser->error = true;
7299 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7300 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7301 expr.value = error_mark_node;
7302 break;
7303 }
7304 stmt = c_begin_stmt_expr ();
7305 c_parser_compound_statement_nostart (parser);
7306 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7307 "expected %<)%>");
7308 pedwarn (loc, OPT_Wpedantic,
7309 "ISO C forbids braced-groups within expressions");
7310 expr.value = c_finish_stmt_expr (brace_loc, stmt);
7311 mark_exp_read (expr.value);
7312 }
7313 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7314 {
7315 /* A compound literal. ??? Can we actually get here rather
7316 than going directly to
7317 c_parser_postfix_expression_after_paren_type from
7318 elsewhere? */
7319 location_t loc;
7320 struct c_type_name *type_name;
7321 c_parser_consume_token (parser);
7322 loc = c_parser_peek_token (parser)->location;
7323 type_name = c_parser_type_name (parser);
7324 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7325 "expected %<)%>");
7326 if (type_name == NULL)
7327 {
7328 expr.value = error_mark_node;
7329 }
7330 else
7331 expr = c_parser_postfix_expression_after_paren_type (parser,
7332 type_name,
7333 loc);
7334 }
7335 else
7336 {
7337 /* A parenthesized expression. */
7338 c_parser_consume_token (parser);
7339 expr = c_parser_expression (parser);
7340 if (TREE_CODE (expr.value) == MODIFY_EXPR)
7341 TREE_NO_WARNING (expr.value) = 1;
7342 if (expr.original_code != C_MAYBE_CONST_EXPR)
7343 expr.original_code = ERROR_MARK;
7344 /* Don't change EXPR.ORIGINAL_TYPE. */
7345 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7346 "expected %<)%>");
7347 }
7348 break;
7349 case CPP_KEYWORD:
7350 switch (c_parser_peek_token (parser)->keyword)
7351 {
7352 case RID_FUNCTION_NAME:
7353 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7354 "%<__FUNCTION__%> predefined identifier");
7355 expr.value = fname_decl (loc,
7356 c_parser_peek_token (parser)->keyword,
7357 c_parser_peek_token (parser)->value);
7358 c_parser_consume_token (parser);
7359 break;
7360 case RID_PRETTY_FUNCTION_NAME:
7361 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7362 "%<__PRETTY_FUNCTION__%> predefined identifier");
7363 expr.value = fname_decl (loc,
7364 c_parser_peek_token (parser)->keyword,
7365 c_parser_peek_token (parser)->value);
7366 c_parser_consume_token (parser);
7367 break;
7368 case RID_C99_FUNCTION_NAME:
7369 pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support "
7370 "%<__func__%> predefined identifier");
7371 expr.value = fname_decl (loc,
7372 c_parser_peek_token (parser)->keyword,
7373 c_parser_peek_token (parser)->value);
7374 c_parser_consume_token (parser);
7375 break;
7376 case RID_VA_ARG:
7377 c_parser_consume_token (parser);
7378 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7379 {
7380 expr.value = error_mark_node;
7381 break;
7382 }
7383 e1 = c_parser_expr_no_commas (parser, NULL);
7384 mark_exp_read (e1.value);
7385 e1.value = c_fully_fold (e1.value, false, NULL);
7386 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7387 {
7388 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7389 expr.value = error_mark_node;
7390 break;
7391 }
7392 loc = c_parser_peek_token (parser)->location;
7393 t1 = c_parser_type_name (parser);
7394 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7395 "expected %<)%>");
7396 if (t1 == NULL)
7397 {
7398 expr.value = error_mark_node;
7399 }
7400 else
7401 {
7402 tree type_expr = NULL_TREE;
7403 expr.value = c_build_va_arg (loc, e1.value,
7404 groktypename (t1, &type_expr, NULL));
7405 if (type_expr)
7406 {
7407 expr.value = build2 (C_MAYBE_CONST_EXPR,
7408 TREE_TYPE (expr.value), type_expr,
7409 expr.value);
7410 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
7411 }
7412 }
7413 break;
7414 case RID_OFFSETOF:
7415 c_parser_consume_token (parser);
7416 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7417 {
7418 expr.value = error_mark_node;
7419 break;
7420 }
7421 t1 = c_parser_type_name (parser);
7422 if (t1 == NULL)
7423 parser->error = true;
7424 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7425 gcc_assert (parser->error);
7426 if (parser->error)
7427 {
7428 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7429 expr.value = error_mark_node;
7430 break;
7431 }
7432
7433 {
7434 tree type = groktypename (t1, NULL, NULL);
7435 tree offsetof_ref;
7436 if (type == error_mark_node)
7437 offsetof_ref = error_mark_node;
7438 else
7439 {
7440 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
7441 SET_EXPR_LOCATION (offsetof_ref, loc);
7442 }
7443 /* Parse the second argument to __builtin_offsetof. We
7444 must have one identifier, and beyond that we want to
7445 accept sub structure and sub array references. */
7446 if (c_parser_next_token_is (parser, CPP_NAME))
7447 {
7448 offsetof_ref = build_component_ref
7449 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
7450 c_parser_consume_token (parser);
7451 while (c_parser_next_token_is (parser, CPP_DOT)
7452 || c_parser_next_token_is (parser,
7453 CPP_OPEN_SQUARE)
7454 || c_parser_next_token_is (parser,
7455 CPP_DEREF))
7456 {
7457 if (c_parser_next_token_is (parser, CPP_DEREF))
7458 {
7459 loc = c_parser_peek_token (parser)->location;
7460 offsetof_ref = build_array_ref (loc,
7461 offsetof_ref,
7462 integer_zero_node);
7463 goto do_dot;
7464 }
7465 else if (c_parser_next_token_is (parser, CPP_DOT))
7466 {
7467 do_dot:
7468 c_parser_consume_token (parser);
7469 if (c_parser_next_token_is_not (parser,
7470 CPP_NAME))
7471 {
7472 c_parser_error (parser, "expected identifier");
7473 break;
7474 }
7475 offsetof_ref = build_component_ref
7476 (loc, offsetof_ref,
7477 c_parser_peek_token (parser)->value);
7478 c_parser_consume_token (parser);
7479 }
7480 else
7481 {
7482 struct c_expr ce;
7483 tree idx;
7484 loc = c_parser_peek_token (parser)->location;
7485 c_parser_consume_token (parser);
7486 ce = c_parser_expression (parser);
7487 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
7488 idx = ce.value;
7489 idx = c_fully_fold (idx, false, NULL);
7490 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7491 "expected %<]%>");
7492 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
7493 }
7494 }
7495 }
7496 else
7497 c_parser_error (parser, "expected identifier");
7498 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7499 "expected %<)%>");
7500 expr.value = fold_offsetof (offsetof_ref);
7501 }
7502 break;
7503 case RID_CHOOSE_EXPR:
7504 {
7505 vec<c_expr_t, va_gc> *cexpr_list;
7506 c_expr_t *e1_p, *e2_p, *e3_p;
7507 tree c;
7508
7509 c_parser_consume_token (parser);
7510 if (!c_parser_get_builtin_args (parser,
7511 "__builtin_choose_expr",
7512 &cexpr_list, true))
7513 {
7514 expr.value = error_mark_node;
7515 break;
7516 }
7517
7518 if (vec_safe_length (cexpr_list) != 3)
7519 {
7520 error_at (loc, "wrong number of arguments to "
7521 "%<__builtin_choose_expr%>");
7522 expr.value = error_mark_node;
7523 break;
7524 }
7525
7526 e1_p = &(*cexpr_list)[0];
7527 e2_p = &(*cexpr_list)[1];
7528 e3_p = &(*cexpr_list)[2];
7529
7530 c = e1_p->value;
7531 mark_exp_read (e2_p->value);
7532 mark_exp_read (e3_p->value);
7533 if (TREE_CODE (c) != INTEGER_CST
7534 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
7535 error_at (loc,
7536 "first argument to %<__builtin_choose_expr%> not"
7537 " a constant");
7538 constant_expression_warning (c);
7539 expr = integer_zerop (c) ? *e3_p : *e2_p;
7540 break;
7541 }
7542 case RID_TYPES_COMPATIBLE_P:
7543 c_parser_consume_token (parser);
7544 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7545 {
7546 expr.value = error_mark_node;
7547 break;
7548 }
7549 t1 = c_parser_type_name (parser);
7550 if (t1 == NULL)
7551 {
7552 expr.value = error_mark_node;
7553 break;
7554 }
7555 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7556 {
7557 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7558 expr.value = error_mark_node;
7559 break;
7560 }
7561 t2 = c_parser_type_name (parser);
7562 if (t2 == NULL)
7563 {
7564 expr.value = error_mark_node;
7565 break;
7566 }
7567 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7568 "expected %<)%>");
7569 {
7570 tree e1, e2;
7571 e1 = groktypename (t1, NULL, NULL);
7572 e2 = groktypename (t2, NULL, NULL);
7573 if (e1 == error_mark_node || e2 == error_mark_node)
7574 {
7575 expr.value = error_mark_node;
7576 break;
7577 }
7578
7579 e1 = TYPE_MAIN_VARIANT (e1);
7580 e2 = TYPE_MAIN_VARIANT (e2);
7581
7582 expr.value
7583 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
7584 }
7585 break;
7586 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
7587 {
7588 vec<c_expr_t, va_gc> *cexpr_list;
7589 c_expr_t *e2_p;
7590 tree chain_value;
7591
7592 c_parser_consume_token (parser);
7593 if (!c_parser_get_builtin_args (parser,
7594 "__builtin_call_with_static_chain",
7595 &cexpr_list, false))
7596 {
7597 expr.value = error_mark_node;
7598 break;
7599 }
7600 if (vec_safe_length (cexpr_list) != 2)
7601 {
7602 error_at (loc, "wrong number of arguments to "
7603 "%<__builtin_call_with_static_chain%>");
7604 expr.value = error_mark_node;
7605 break;
7606 }
7607
7608 expr = (*cexpr_list)[0];
7609 e2_p = &(*cexpr_list)[1];
7610 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7611 chain_value = e2_p->value;
7612 mark_exp_read (chain_value);
7613
7614 if (TREE_CODE (expr.value) != CALL_EXPR)
7615 error_at (loc, "first argument to "
7616 "%<__builtin_call_with_static_chain%> "
7617 "must be a call expression");
7618 else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
7619 error_at (loc, "second argument to "
7620 "%<__builtin_call_with_static_chain%> "
7621 "must be a pointer type");
7622 else
7623 CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
7624 break;
7625 }
7626 case RID_BUILTIN_COMPLEX:
7627 {
7628 vec<c_expr_t, va_gc> *cexpr_list;
7629 c_expr_t *e1_p, *e2_p;
7630
7631 c_parser_consume_token (parser);
7632 if (!c_parser_get_builtin_args (parser,
7633 "__builtin_complex",
7634 &cexpr_list, false))
7635 {
7636 expr.value = error_mark_node;
7637 break;
7638 }
7639
7640 if (vec_safe_length (cexpr_list) != 2)
7641 {
7642 error_at (loc, "wrong number of arguments to "
7643 "%<__builtin_complex%>");
7644 expr.value = error_mark_node;
7645 break;
7646 }
7647
7648 e1_p = &(*cexpr_list)[0];
7649 e2_p = &(*cexpr_list)[1];
7650
7651 *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
7652 if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
7653 e1_p->value = convert (TREE_TYPE (e1_p->value),
7654 TREE_OPERAND (e1_p->value, 0));
7655 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7656 if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
7657 e2_p->value = convert (TREE_TYPE (e2_p->value),
7658 TREE_OPERAND (e2_p->value, 0));
7659 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7660 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7661 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
7662 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
7663 {
7664 error_at (loc, "%<__builtin_complex%> operand "
7665 "not of real binary floating-point type");
7666 expr.value = error_mark_node;
7667 break;
7668 }
7669 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
7670 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
7671 {
7672 error_at (loc,
7673 "%<__builtin_complex%> operands of different types");
7674 expr.value = error_mark_node;
7675 break;
7676 }
7677 pedwarn_c90 (loc, OPT_Wpedantic,
7678 "ISO C90 does not support complex types");
7679 expr.value = build2 (COMPLEX_EXPR,
7680 build_complex_type
7681 (TYPE_MAIN_VARIANT
7682 (TREE_TYPE (e1_p->value))),
7683 e1_p->value, e2_p->value);
7684 break;
7685 }
7686 case RID_BUILTIN_SHUFFLE:
7687 {
7688 vec<c_expr_t, va_gc> *cexpr_list;
7689 unsigned int i;
7690 c_expr_t *p;
7691
7692 c_parser_consume_token (parser);
7693 if (!c_parser_get_builtin_args (parser,
7694 "__builtin_shuffle",
7695 &cexpr_list, false))
7696 {
7697 expr.value = error_mark_node;
7698 break;
7699 }
7700
7701 FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
7702 *p = convert_lvalue_to_rvalue (loc, *p, true, true);
7703
7704 if (vec_safe_length (cexpr_list) == 2)
7705 expr.value =
7706 c_build_vec_perm_expr
7707 (loc, (*cexpr_list)[0].value,
7708 NULL_TREE, (*cexpr_list)[1].value);
7709
7710 else if (vec_safe_length (cexpr_list) == 3)
7711 expr.value =
7712 c_build_vec_perm_expr
7713 (loc, (*cexpr_list)[0].value,
7714 (*cexpr_list)[1].value,
7715 (*cexpr_list)[2].value);
7716 else
7717 {
7718 error_at (loc, "wrong number of arguments to "
7719 "%<__builtin_shuffle%>");
7720 expr.value = error_mark_node;
7721 }
7722 break;
7723 }
7724 case RID_AT_SELECTOR:
7725 gcc_assert (c_dialect_objc ());
7726 c_parser_consume_token (parser);
7727 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7728 {
7729 expr.value = error_mark_node;
7730 break;
7731 }
7732 {
7733 tree sel = c_parser_objc_selector_arg (parser);
7734 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7735 "expected %<)%>");
7736 expr.value = objc_build_selector_expr (loc, sel);
7737 }
7738 break;
7739 case RID_AT_PROTOCOL:
7740 gcc_assert (c_dialect_objc ());
7741 c_parser_consume_token (parser);
7742 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7743 {
7744 expr.value = error_mark_node;
7745 break;
7746 }
7747 if (c_parser_next_token_is_not (parser, CPP_NAME))
7748 {
7749 c_parser_error (parser, "expected identifier");
7750 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7751 expr.value = error_mark_node;
7752 break;
7753 }
7754 {
7755 tree id = c_parser_peek_token (parser)->value;
7756 c_parser_consume_token (parser);
7757 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7758 "expected %<)%>");
7759 expr.value = objc_build_protocol_expr (id);
7760 }
7761 break;
7762 case RID_AT_ENCODE:
7763 /* Extension to support C-structures in the archiver. */
7764 gcc_assert (c_dialect_objc ());
7765 c_parser_consume_token (parser);
7766 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7767 {
7768 expr.value = error_mark_node;
7769 break;
7770 }
7771 t1 = c_parser_type_name (parser);
7772 if (t1 == NULL)
7773 {
7774 expr.value = error_mark_node;
7775 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7776 break;
7777 }
7778 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7779 "expected %<)%>");
7780 {
7781 tree type = groktypename (t1, NULL, NULL);
7782 expr.value = objc_build_encode_expr (type);
7783 }
7784 break;
7785 case RID_GENERIC:
7786 expr = c_parser_generic_selection (parser);
7787 break;
7788 case RID_CILK_SPAWN:
7789 c_parser_consume_token (parser);
7790 if (!flag_cilkplus)
7791 {
7792 error_at (loc, "-fcilkplus must be enabled to use "
7793 "%<_Cilk_spawn%>");
7794 expr = c_parser_postfix_expression (parser);
7795 expr.value = error_mark_node;
7796 }
7797 else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7798 {
7799 error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
7800 "are not permitted");
7801 /* Now flush out all the _Cilk_spawns. */
7802 while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7803 c_parser_consume_token (parser);
7804 expr = c_parser_postfix_expression (parser);
7805 }
7806 else
7807 {
7808 expr = c_parser_postfix_expression (parser);
7809 expr.value = build_cilk_spawn (loc, expr.value);
7810 }
7811 break;
7812 default:
7813 c_parser_error (parser, "expected expression");
7814 expr.value = error_mark_node;
7815 break;
7816 }
7817 break;
7818 case CPP_OPEN_SQUARE:
7819 if (c_dialect_objc ())
7820 {
7821 tree receiver, args;
7822 c_parser_consume_token (parser);
7823 receiver = c_parser_objc_receiver (parser);
7824 args = c_parser_objc_message_args (parser);
7825 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7826 "expected %<]%>");
7827 expr.value = objc_build_message_expr (receiver, args);
7828 break;
7829 }
7830 /* Else fall through to report error. */
7831 default:
7832 c_parser_error (parser, "expected expression");
7833 expr.value = error_mark_node;
7834 break;
7835 }
7836 return c_parser_postfix_expression_after_primary (parser, loc, expr);
7837 }
7838
7839 /* Parse a postfix expression after a parenthesized type name: the
7840 brace-enclosed initializer of a compound literal, possibly followed
7841 by some postfix operators. This is separate because it is not
7842 possible to tell until after the type name whether a cast
7843 expression has a cast or a compound literal, or whether the operand
7844 of sizeof is a parenthesized type name or starts with a compound
7845 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7846 location of the first token after the parentheses around the type
7847 name. */
7848
7849 static struct c_expr
7850 c_parser_postfix_expression_after_paren_type (c_parser *parser,
7851 struct c_type_name *type_name,
7852 location_t type_loc)
7853 {
7854 tree type;
7855 struct c_expr init;
7856 bool non_const;
7857 struct c_expr expr;
7858 location_t start_loc;
7859 tree type_expr = NULL_TREE;
7860 bool type_expr_const = true;
7861 check_compound_literal_type (type_loc, type_name);
7862 start_init (NULL_TREE, NULL, 0);
7863 type = groktypename (type_name, &type_expr, &type_expr_const);
7864 start_loc = c_parser_peek_token (parser)->location;
7865 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
7866 {
7867 error_at (type_loc, "compound literal has variable size");
7868 type = error_mark_node;
7869 }
7870 init = c_parser_braced_init (parser, type, false);
7871 finish_init ();
7872 maybe_warn_string_init (type_loc, type, init);
7873
7874 if (type != error_mark_node
7875 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
7876 && current_function_decl)
7877 {
7878 error ("compound literal qualified by address-space qualifier");
7879 type = error_mark_node;
7880 }
7881
7882 pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
7883 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
7884 ? CONSTRUCTOR_NON_CONST (init.value)
7885 : init.original_code == C_MAYBE_CONST_EXPR);
7886 non_const |= !type_expr_const;
7887 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
7888 expr.original_code = ERROR_MARK;
7889 expr.original_type = NULL;
7890 if (type != error_mark_node && type_expr)
7891 {
7892 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
7893 {
7894 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
7895 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
7896 }
7897 else
7898 {
7899 gcc_assert (!non_const);
7900 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
7901 type_expr, expr.value);
7902 }
7903 }
7904 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
7905 }
7906
7907 /* Callback function for sizeof_pointer_memaccess_warning to compare
7908 types. */
7909
7910 static bool
7911 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
7912 {
7913 return comptypes (type1, type2) == 1;
7914 }
7915
7916 /* Parse a postfix expression after the initial primary or compound
7917 literal; that is, parse a series of postfix operators.
7918
7919 EXPR_LOC is the location of the primary expression. */
7920
7921 static struct c_expr
7922 c_parser_postfix_expression_after_primary (c_parser *parser,
7923 location_t expr_loc,
7924 struct c_expr expr)
7925 {
7926 struct c_expr orig_expr;
7927 tree ident, idx;
7928 location_t sizeof_arg_loc[3];
7929 tree sizeof_arg[3];
7930 unsigned int literal_zero_mask;
7931 unsigned int i;
7932 vec<tree, va_gc> *exprlist;
7933 vec<tree, va_gc> *origtypes = NULL;
7934 vec<location_t> arg_loc = vNULL;
7935
7936 while (true)
7937 {
7938 location_t op_loc = c_parser_peek_token (parser)->location;
7939 switch (c_parser_peek_token (parser)->type)
7940 {
7941 case CPP_OPEN_SQUARE:
7942 /* Array reference. */
7943 c_parser_consume_token (parser);
7944 if (flag_cilkplus
7945 && c_parser_peek_token (parser)->type == CPP_COLON)
7946 /* If we are here, then we have something like this:
7947 Array [ : ]
7948 */
7949 expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE,
7950 expr.value);
7951 else
7952 {
7953 idx = c_parser_expression (parser).value;
7954 /* Here we have 3 options:
7955 1. Array [EXPR] -- Normal Array call.
7956 2. Array [EXPR : EXPR] -- Array notation without stride.
7957 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7958
7959 For 1, we just handle it just like a normal array expression.
7960 For 2 and 3 we handle it like we handle array notations. The
7961 idx value we have above becomes the initial/start index.
7962 */
7963 if (flag_cilkplus
7964 && c_parser_peek_token (parser)->type == CPP_COLON)
7965 expr.value = c_parser_array_notation (expr_loc, parser, idx,
7966 expr.value);
7967 else
7968 {
7969 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7970 "expected %<]%>");
7971 expr.value = build_array_ref (op_loc, expr.value, idx);
7972 }
7973 }
7974 expr.original_code = ERROR_MARK;
7975 expr.original_type = NULL;
7976 break;
7977 case CPP_OPEN_PAREN:
7978 /* Function call. */
7979 c_parser_consume_token (parser);
7980 for (i = 0; i < 3; i++)
7981 {
7982 sizeof_arg[i] = NULL_TREE;
7983 sizeof_arg_loc[i] = UNKNOWN_LOCATION;
7984 }
7985 literal_zero_mask = 0;
7986 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7987 exprlist = NULL;
7988 else
7989 exprlist = c_parser_expr_list (parser, true, false, &origtypes,
7990 sizeof_arg_loc, sizeof_arg,
7991 &arg_loc, &literal_zero_mask);
7992 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7993 "expected %<)%>");
7994 orig_expr = expr;
7995 mark_exp_read (expr.value);
7996 if (warn_sizeof_pointer_memaccess)
7997 sizeof_pointer_memaccess_warning (sizeof_arg_loc,
7998 expr.value, exprlist,
7999 sizeof_arg,
8000 sizeof_ptr_memacc_comptypes);
8001 if (warn_memset_transposed_args
8002 && TREE_CODE (expr.value) == FUNCTION_DECL
8003 && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
8004 && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
8005 && vec_safe_length (exprlist) == 3
8006 && integer_zerop ((*exprlist)[2])
8007 && (literal_zero_mask & (1 << 2)) != 0
8008 && (!integer_zerop ((*exprlist)[1])
8009 || (literal_zero_mask & (1 << 1)) == 0))
8010 warning_at (expr_loc, OPT_Wmemset_transposed_args,
8011 "%<memset%> used with constant zero length parameter; "
8012 "this could be due to transposed parameters");
8013
8014 expr.value
8015 = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
8016 exprlist, origtypes);
8017 expr.original_code = ERROR_MARK;
8018 if (TREE_CODE (expr.value) == INTEGER_CST
8019 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
8020 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
8021 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
8022 expr.original_code = C_MAYBE_CONST_EXPR;
8023 expr.original_type = NULL;
8024 if (exprlist)
8025 {
8026 release_tree_vector (exprlist);
8027 release_tree_vector (origtypes);
8028 }
8029 arg_loc.release ();
8030 break;
8031 case CPP_DOT:
8032 /* Structure element reference. */
8033 c_parser_consume_token (parser);
8034 expr = default_function_array_conversion (expr_loc, expr);
8035 if (c_parser_next_token_is (parser, CPP_NAME))
8036 ident = c_parser_peek_token (parser)->value;
8037 else
8038 {
8039 c_parser_error (parser, "expected identifier");
8040 expr.value = error_mark_node;
8041 expr.original_code = ERROR_MARK;
8042 expr.original_type = NULL;
8043 return expr;
8044 }
8045 c_parser_consume_token (parser);
8046 expr.value = build_component_ref (op_loc, expr.value, ident);
8047 expr.original_code = ERROR_MARK;
8048 if (TREE_CODE (expr.value) != COMPONENT_REF)
8049 expr.original_type = NULL;
8050 else
8051 {
8052 /* Remember the original type of a bitfield. */
8053 tree field = TREE_OPERAND (expr.value, 1);
8054 if (TREE_CODE (field) != FIELD_DECL)
8055 expr.original_type = NULL;
8056 else
8057 expr.original_type = DECL_BIT_FIELD_TYPE (field);
8058 }
8059 break;
8060 case CPP_DEREF:
8061 /* Structure element reference. */
8062 c_parser_consume_token (parser);
8063 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
8064 if (c_parser_next_token_is (parser, CPP_NAME))
8065 ident = c_parser_peek_token (parser)->value;
8066 else
8067 {
8068 c_parser_error (parser, "expected identifier");
8069 expr.value = error_mark_node;
8070 expr.original_code = ERROR_MARK;
8071 expr.original_type = NULL;
8072 return expr;
8073 }
8074 c_parser_consume_token (parser);
8075 expr.value = build_component_ref (op_loc,
8076 build_indirect_ref (op_loc,
8077 expr.value,
8078 RO_ARROW),
8079 ident);
8080 expr.original_code = ERROR_MARK;
8081 if (TREE_CODE (expr.value) != COMPONENT_REF)
8082 expr.original_type = NULL;
8083 else
8084 {
8085 /* Remember the original type of a bitfield. */
8086 tree field = TREE_OPERAND (expr.value, 1);
8087 if (TREE_CODE (field) != FIELD_DECL)
8088 expr.original_type = NULL;
8089 else
8090 expr.original_type = DECL_BIT_FIELD_TYPE (field);
8091 }
8092 break;
8093 case CPP_PLUS_PLUS:
8094 /* Postincrement. */
8095 c_parser_consume_token (parser);
8096 /* If the expressions have array notations, we expand them. */
8097 if (flag_cilkplus
8098 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8099 expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr);
8100 else
8101 {
8102 expr = default_function_array_read_conversion (expr_loc, expr);
8103 expr.value = build_unary_op (op_loc,
8104 POSTINCREMENT_EXPR, expr.value, 0);
8105 }
8106 expr.original_code = ERROR_MARK;
8107 expr.original_type = NULL;
8108 break;
8109 case CPP_MINUS_MINUS:
8110 /* Postdecrement. */
8111 c_parser_consume_token (parser);
8112 /* If the expressions have array notations, we expand them. */
8113 if (flag_cilkplus
8114 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8115 expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr);
8116 else
8117 {
8118 expr = default_function_array_read_conversion (expr_loc, expr);
8119 expr.value = build_unary_op (op_loc,
8120 POSTDECREMENT_EXPR, expr.value, 0);
8121 }
8122 expr.original_code = ERROR_MARK;
8123 expr.original_type = NULL;
8124 break;
8125 default:
8126 return expr;
8127 }
8128 }
8129 }
8130
8131 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8132
8133 expression:
8134 assignment-expression
8135 expression , assignment-expression
8136 */
8137
8138 static struct c_expr
8139 c_parser_expression (c_parser *parser)
8140 {
8141 location_t tloc = c_parser_peek_token (parser)->location;
8142 struct c_expr expr;
8143 expr = c_parser_expr_no_commas (parser, NULL);
8144 if (c_parser_next_token_is (parser, CPP_COMMA))
8145 expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
8146 while (c_parser_next_token_is (parser, CPP_COMMA))
8147 {
8148 struct c_expr next;
8149 tree lhsval;
8150 location_t loc = c_parser_peek_token (parser)->location;
8151 location_t expr_loc;
8152 c_parser_consume_token (parser);
8153 expr_loc = c_parser_peek_token (parser)->location;
8154 lhsval = expr.value;
8155 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
8156 lhsval = TREE_OPERAND (lhsval, 1);
8157 if (DECL_P (lhsval) || handled_component_p (lhsval))
8158 mark_exp_read (lhsval);
8159 next = c_parser_expr_no_commas (parser, NULL);
8160 next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
8161 expr.value = build_compound_expr (loc, expr.value, next.value);
8162 expr.original_code = COMPOUND_EXPR;
8163 expr.original_type = next.original_type;
8164 }
8165 return expr;
8166 }
8167
8168 /* Parse an expression and convert functions or arrays to pointers and
8169 lvalues to rvalues. */
8170
8171 static struct c_expr
8172 c_parser_expression_conv (c_parser *parser)
8173 {
8174 struct c_expr expr;
8175 location_t loc = c_parser_peek_token (parser)->location;
8176 expr = c_parser_expression (parser);
8177 expr = convert_lvalue_to_rvalue (loc, expr, true, false);
8178 return expr;
8179 }
8180
8181 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8182 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8183
8184 static inline void
8185 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
8186 unsigned int idx)
8187 {
8188 if (idx >= HOST_BITS_PER_INT)
8189 return;
8190
8191 c_token *tok = c_parser_peek_token (parser);
8192 switch (tok->type)
8193 {
8194 case CPP_NUMBER:
8195 case CPP_CHAR:
8196 case CPP_WCHAR:
8197 case CPP_CHAR16:
8198 case CPP_CHAR32:
8199 /* If a parameter is literal zero alone, remember it
8200 for -Wmemset-transposed-args warning. */
8201 if (integer_zerop (tok->value)
8202 && !TREE_OVERFLOW (tok->value)
8203 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8204 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
8205 *literal_zero_mask |= 1U << idx;
8206 default:
8207 break;
8208 }
8209 }
8210
8211 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8212 functions and arrays to pointers and lvalues to rvalues. If
8213 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8214 locations of function arguments into this vector.
8215
8216 nonempty-expr-list:
8217 assignment-expression
8218 nonempty-expr-list , assignment-expression
8219 */
8220
8221 static vec<tree, va_gc> *
8222 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
8223 vec<tree, va_gc> **p_orig_types,
8224 location_t *sizeof_arg_loc, tree *sizeof_arg,
8225 vec<location_t> *locations,
8226 unsigned int *literal_zero_mask)
8227 {
8228 vec<tree, va_gc> *ret;
8229 vec<tree, va_gc> *orig_types;
8230 struct c_expr expr;
8231 location_t loc = c_parser_peek_token (parser)->location;
8232 location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8233 unsigned int idx = 0;
8234
8235 ret = make_tree_vector ();
8236 if (p_orig_types == NULL)
8237 orig_types = NULL;
8238 else
8239 orig_types = make_tree_vector ();
8240
8241 if (sizeof_arg != NULL
8242 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8243 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8244 if (literal_zero_mask)
8245 c_parser_check_literal_zero (parser, literal_zero_mask, 0);
8246 expr = c_parser_expr_no_commas (parser, NULL);
8247 if (convert_p)
8248 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8249 if (fold_p)
8250 expr.value = c_fully_fold (expr.value, false, NULL);
8251 ret->quick_push (expr.value);
8252 if (orig_types)
8253 orig_types->quick_push (expr.original_type);
8254 if (locations)
8255 locations->safe_push (loc);
8256 if (sizeof_arg != NULL
8257 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8258 && expr.original_code == SIZEOF_EXPR)
8259 {
8260 sizeof_arg[0] = c_last_sizeof_arg;
8261 sizeof_arg_loc[0] = cur_sizeof_arg_loc;
8262 }
8263 while (c_parser_next_token_is (parser, CPP_COMMA))
8264 {
8265 c_parser_consume_token (parser);
8266 loc = c_parser_peek_token (parser)->location;
8267 if (sizeof_arg != NULL
8268 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8269 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8270 else
8271 cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8272 if (literal_zero_mask)
8273 c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
8274 expr = c_parser_expr_no_commas (parser, NULL);
8275 if (convert_p)
8276 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8277 if (fold_p)
8278 expr.value = c_fully_fold (expr.value, false, NULL);
8279 vec_safe_push (ret, expr.value);
8280 if (orig_types)
8281 vec_safe_push (orig_types, expr.original_type);
8282 if (locations)
8283 locations->safe_push (loc);
8284 if (++idx < 3
8285 && sizeof_arg != NULL
8286 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8287 && expr.original_code == SIZEOF_EXPR)
8288 {
8289 sizeof_arg[idx] = c_last_sizeof_arg;
8290 sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
8291 }
8292 }
8293 if (orig_types)
8294 *p_orig_types = orig_types;
8295 return ret;
8296 }
8297 \f
8298 /* Parse Objective-C-specific constructs. */
8299
8300 /* Parse an objc-class-definition.
8301
8302 objc-class-definition:
8303 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8304 objc-class-instance-variables[opt] objc-methodprotolist @end
8305 @implementation identifier objc-superclass[opt]
8306 objc-class-instance-variables[opt]
8307 @interface identifier ( identifier ) objc-protocol-refs[opt]
8308 objc-methodprotolist @end
8309 @interface identifier ( ) objc-protocol-refs[opt]
8310 objc-methodprotolist @end
8311 @implementation identifier ( identifier )
8312
8313 objc-superclass:
8314 : identifier
8315
8316 "@interface identifier (" must start "@interface identifier (
8317 identifier ) ...": objc-methodprotolist in the first production may
8318 not start with a parenthesized identifier as a declarator of a data
8319 definition with no declaration specifiers if the objc-superclass,
8320 objc-protocol-refs and objc-class-instance-variables are omitted. */
8321
8322 static void
8323 c_parser_objc_class_definition (c_parser *parser, tree attributes)
8324 {
8325 bool iface_p;
8326 tree id1;
8327 tree superclass;
8328 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
8329 iface_p = true;
8330 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
8331 iface_p = false;
8332 else
8333 gcc_unreachable ();
8334
8335 c_parser_consume_token (parser);
8336 if (c_parser_next_token_is_not (parser, CPP_NAME))
8337 {
8338 c_parser_error (parser, "expected identifier");
8339 return;
8340 }
8341 id1 = c_parser_peek_token (parser)->value;
8342 c_parser_consume_token (parser);
8343 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8344 {
8345 /* We have a category or class extension. */
8346 tree id2;
8347 tree proto = NULL_TREE;
8348 c_parser_consume_token (parser);
8349 if (c_parser_next_token_is_not (parser, CPP_NAME))
8350 {
8351 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8352 {
8353 /* We have a class extension. */
8354 id2 = NULL_TREE;
8355 }
8356 else
8357 {
8358 c_parser_error (parser, "expected identifier or %<)%>");
8359 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8360 return;
8361 }
8362 }
8363 else
8364 {
8365 id2 = c_parser_peek_token (parser)->value;
8366 c_parser_consume_token (parser);
8367 }
8368 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8369 if (!iface_p)
8370 {
8371 objc_start_category_implementation (id1, id2);
8372 return;
8373 }
8374 if (c_parser_next_token_is (parser, CPP_LESS))
8375 proto = c_parser_objc_protocol_refs (parser);
8376 objc_start_category_interface (id1, id2, proto, attributes);
8377 c_parser_objc_methodprotolist (parser);
8378 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8379 objc_finish_interface ();
8380 return;
8381 }
8382 if (c_parser_next_token_is (parser, CPP_COLON))
8383 {
8384 c_parser_consume_token (parser);
8385 if (c_parser_next_token_is_not (parser, CPP_NAME))
8386 {
8387 c_parser_error (parser, "expected identifier");
8388 return;
8389 }
8390 superclass = c_parser_peek_token (parser)->value;
8391 c_parser_consume_token (parser);
8392 }
8393 else
8394 superclass = NULL_TREE;
8395 if (iface_p)
8396 {
8397 tree proto = NULL_TREE;
8398 if (c_parser_next_token_is (parser, CPP_LESS))
8399 proto = c_parser_objc_protocol_refs (parser);
8400 objc_start_class_interface (id1, superclass, proto, attributes);
8401 }
8402 else
8403 objc_start_class_implementation (id1, superclass);
8404 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8405 c_parser_objc_class_instance_variables (parser);
8406 if (iface_p)
8407 {
8408 objc_continue_interface ();
8409 c_parser_objc_methodprotolist (parser);
8410 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8411 objc_finish_interface ();
8412 }
8413 else
8414 {
8415 objc_continue_implementation ();
8416 return;
8417 }
8418 }
8419
8420 /* Parse objc-class-instance-variables.
8421
8422 objc-class-instance-variables:
8423 { objc-instance-variable-decl-list[opt] }
8424
8425 objc-instance-variable-decl-list:
8426 objc-visibility-spec
8427 objc-instance-variable-decl ;
8428 ;
8429 objc-instance-variable-decl-list objc-visibility-spec
8430 objc-instance-variable-decl-list objc-instance-variable-decl ;
8431 objc-instance-variable-decl-list ;
8432
8433 objc-visibility-spec:
8434 @private
8435 @protected
8436 @public
8437
8438 objc-instance-variable-decl:
8439 struct-declaration
8440 */
8441
8442 static void
8443 c_parser_objc_class_instance_variables (c_parser *parser)
8444 {
8445 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
8446 c_parser_consume_token (parser);
8447 while (c_parser_next_token_is_not (parser, CPP_EOF))
8448 {
8449 tree decls;
8450 /* Parse any stray semicolon. */
8451 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8452 {
8453 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8454 "extra semicolon");
8455 c_parser_consume_token (parser);
8456 continue;
8457 }
8458 /* Stop if at the end of the instance variables. */
8459 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8460 {
8461 c_parser_consume_token (parser);
8462 break;
8463 }
8464 /* Parse any objc-visibility-spec. */
8465 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
8466 {
8467 c_parser_consume_token (parser);
8468 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
8469 continue;
8470 }
8471 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
8472 {
8473 c_parser_consume_token (parser);
8474 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
8475 continue;
8476 }
8477 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
8478 {
8479 c_parser_consume_token (parser);
8480 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
8481 continue;
8482 }
8483 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
8484 {
8485 c_parser_consume_token (parser);
8486 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
8487 continue;
8488 }
8489 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
8490 {
8491 c_parser_pragma (parser, pragma_external);
8492 continue;
8493 }
8494
8495 /* Parse some comma-separated declarations. */
8496 decls = c_parser_struct_declaration (parser);
8497 if (decls == NULL)
8498 {
8499 /* There is a syntax error. We want to skip the offending
8500 tokens up to the next ';' (included) or '}'
8501 (excluded). */
8502
8503 /* First, skip manually a ')' or ']'. This is because they
8504 reduce the nesting level, so c_parser_skip_until_found()
8505 wouldn't be able to skip past them. */
8506 c_token *token = c_parser_peek_token (parser);
8507 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
8508 c_parser_consume_token (parser);
8509
8510 /* Then, do the standard skipping. */
8511 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8512
8513 /* We hopefully recovered. Start normal parsing again. */
8514 parser->error = false;
8515 continue;
8516 }
8517 else
8518 {
8519 /* Comma-separated instance variables are chained together
8520 in reverse order; add them one by one. */
8521 tree ivar = nreverse (decls);
8522 for (; ivar; ivar = DECL_CHAIN (ivar))
8523 objc_add_instance_variable (copy_node (ivar));
8524 }
8525 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8526 }
8527 }
8528
8529 /* Parse an objc-class-declaration.
8530
8531 objc-class-declaration:
8532 @class identifier-list ;
8533 */
8534
8535 static void
8536 c_parser_objc_class_declaration (c_parser *parser)
8537 {
8538 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
8539 c_parser_consume_token (parser);
8540 /* Any identifiers, including those declared as type names, are OK
8541 here. */
8542 while (true)
8543 {
8544 tree id;
8545 if (c_parser_next_token_is_not (parser, CPP_NAME))
8546 {
8547 c_parser_error (parser, "expected identifier");
8548 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8549 parser->error = false;
8550 return;
8551 }
8552 id = c_parser_peek_token (parser)->value;
8553 objc_declare_class (id);
8554 c_parser_consume_token (parser);
8555 if (c_parser_next_token_is (parser, CPP_COMMA))
8556 c_parser_consume_token (parser);
8557 else
8558 break;
8559 }
8560 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8561 }
8562
8563 /* Parse an objc-alias-declaration.
8564
8565 objc-alias-declaration:
8566 @compatibility_alias identifier identifier ;
8567 */
8568
8569 static void
8570 c_parser_objc_alias_declaration (c_parser *parser)
8571 {
8572 tree id1, id2;
8573 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
8574 c_parser_consume_token (parser);
8575 if (c_parser_next_token_is_not (parser, CPP_NAME))
8576 {
8577 c_parser_error (parser, "expected identifier");
8578 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8579 return;
8580 }
8581 id1 = c_parser_peek_token (parser)->value;
8582 c_parser_consume_token (parser);
8583 if (c_parser_next_token_is_not (parser, CPP_NAME))
8584 {
8585 c_parser_error (parser, "expected identifier");
8586 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8587 return;
8588 }
8589 id2 = c_parser_peek_token (parser)->value;
8590 c_parser_consume_token (parser);
8591 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8592 objc_declare_alias (id1, id2);
8593 }
8594
8595 /* Parse an objc-protocol-definition.
8596
8597 objc-protocol-definition:
8598 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8599 @protocol identifier-list ;
8600
8601 "@protocol identifier ;" should be resolved as "@protocol
8602 identifier-list ;": objc-methodprotolist may not start with a
8603 semicolon in the first alternative if objc-protocol-refs are
8604 omitted. */
8605
8606 static void
8607 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
8608 {
8609 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
8610
8611 c_parser_consume_token (parser);
8612 if (c_parser_next_token_is_not (parser, CPP_NAME))
8613 {
8614 c_parser_error (parser, "expected identifier");
8615 return;
8616 }
8617 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8618 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
8619 {
8620 /* Any identifiers, including those declared as type names, are
8621 OK here. */
8622 while (true)
8623 {
8624 tree id;
8625 if (c_parser_next_token_is_not (parser, CPP_NAME))
8626 {
8627 c_parser_error (parser, "expected identifier");
8628 break;
8629 }
8630 id = c_parser_peek_token (parser)->value;
8631 objc_declare_protocol (id, attributes);
8632 c_parser_consume_token (parser);
8633 if (c_parser_next_token_is (parser, CPP_COMMA))
8634 c_parser_consume_token (parser);
8635 else
8636 break;
8637 }
8638 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8639 }
8640 else
8641 {
8642 tree id = c_parser_peek_token (parser)->value;
8643 tree proto = NULL_TREE;
8644 c_parser_consume_token (parser);
8645 if (c_parser_next_token_is (parser, CPP_LESS))
8646 proto = c_parser_objc_protocol_refs (parser);
8647 parser->objc_pq_context = true;
8648 objc_start_protocol (id, proto, attributes);
8649 c_parser_objc_methodprotolist (parser);
8650 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8651 parser->objc_pq_context = false;
8652 objc_finish_interface ();
8653 }
8654 }
8655
8656 /* Parse an objc-method-type.
8657
8658 objc-method-type:
8659 +
8660 -
8661
8662 Return true if it is a class method (+) and false if it is
8663 an instance method (-).
8664 */
8665 static inline bool
8666 c_parser_objc_method_type (c_parser *parser)
8667 {
8668 switch (c_parser_peek_token (parser)->type)
8669 {
8670 case CPP_PLUS:
8671 c_parser_consume_token (parser);
8672 return true;
8673 case CPP_MINUS:
8674 c_parser_consume_token (parser);
8675 return false;
8676 default:
8677 gcc_unreachable ();
8678 }
8679 }
8680
8681 /* Parse an objc-method-definition.
8682
8683 objc-method-definition:
8684 objc-method-type objc-method-decl ;[opt] compound-statement
8685 */
8686
8687 static void
8688 c_parser_objc_method_definition (c_parser *parser)
8689 {
8690 bool is_class_method = c_parser_objc_method_type (parser);
8691 tree decl, attributes = NULL_TREE, expr = NULL_TREE;
8692 parser->objc_pq_context = true;
8693 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8694 &expr);
8695 if (decl == error_mark_node)
8696 return; /* Bail here. */
8697
8698 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8699 {
8700 c_parser_consume_token (parser);
8701 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8702 "extra semicolon in method definition specified");
8703 }
8704
8705 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8706 {
8707 c_parser_error (parser, "expected %<{%>");
8708 return;
8709 }
8710
8711 parser->objc_pq_context = false;
8712 if (objc_start_method_definition (is_class_method, decl, attributes, expr))
8713 {
8714 add_stmt (c_parser_compound_statement (parser));
8715 objc_finish_method_definition (current_function_decl);
8716 }
8717 else
8718 {
8719 /* This code is executed when we find a method definition
8720 outside of an @implementation context (or invalid for other
8721 reasons). Parse the method (to keep going) but do not emit
8722 any code.
8723 */
8724 c_parser_compound_statement (parser);
8725 }
8726 }
8727
8728 /* Parse an objc-methodprotolist.
8729
8730 objc-methodprotolist:
8731 empty
8732 objc-methodprotolist objc-methodproto
8733 objc-methodprotolist declaration
8734 objc-methodprotolist ;
8735 @optional
8736 @required
8737
8738 The declaration is a data definition, which may be missing
8739 declaration specifiers under the same rules and diagnostics as
8740 other data definitions outside functions, and the stray semicolon
8741 is diagnosed the same way as a stray semicolon outside a
8742 function. */
8743
8744 static void
8745 c_parser_objc_methodprotolist (c_parser *parser)
8746 {
8747 while (true)
8748 {
8749 /* The list is terminated by @end. */
8750 switch (c_parser_peek_token (parser)->type)
8751 {
8752 case CPP_SEMICOLON:
8753 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8754 "ISO C does not allow extra %<;%> outside of a function");
8755 c_parser_consume_token (parser);
8756 break;
8757 case CPP_PLUS:
8758 case CPP_MINUS:
8759 c_parser_objc_methodproto (parser);
8760 break;
8761 case CPP_PRAGMA:
8762 c_parser_pragma (parser, pragma_external);
8763 break;
8764 case CPP_EOF:
8765 return;
8766 default:
8767 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
8768 return;
8769 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
8770 c_parser_objc_at_property_declaration (parser);
8771 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
8772 {
8773 objc_set_method_opt (true);
8774 c_parser_consume_token (parser);
8775 }
8776 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
8777 {
8778 objc_set_method_opt (false);
8779 c_parser_consume_token (parser);
8780 }
8781 else
8782 c_parser_declaration_or_fndef (parser, false, false, true,
8783 false, true, NULL, vNULL);
8784 break;
8785 }
8786 }
8787 }
8788
8789 /* Parse an objc-methodproto.
8790
8791 objc-methodproto:
8792 objc-method-type objc-method-decl ;
8793 */
8794
8795 static void
8796 c_parser_objc_methodproto (c_parser *parser)
8797 {
8798 bool is_class_method = c_parser_objc_method_type (parser);
8799 tree decl, attributes = NULL_TREE;
8800
8801 /* Remember protocol qualifiers in prototypes. */
8802 parser->objc_pq_context = true;
8803 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8804 NULL);
8805 /* Forget protocol qualifiers now. */
8806 parser->objc_pq_context = false;
8807
8808 /* Do not allow the presence of attributes to hide an erroneous
8809 method implementation in the interface section. */
8810 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
8811 {
8812 c_parser_error (parser, "expected %<;%>");
8813 return;
8814 }
8815
8816 if (decl != error_mark_node)
8817 objc_add_method_declaration (is_class_method, decl, attributes);
8818
8819 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8820 }
8821
8822 /* If we are at a position that method attributes may be present, check that
8823 there are not any parsed already (a syntax error) and then collect any
8824 specified at the current location. Finally, if new attributes were present,
8825 check that the next token is legal ( ';' for decls and '{' for defs). */
8826
8827 static bool
8828 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
8829 {
8830 bool bad = false;
8831 if (*attributes)
8832 {
8833 c_parser_error (parser,
8834 "method attributes must be specified at the end only");
8835 *attributes = NULL_TREE;
8836 bad = true;
8837 }
8838
8839 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8840 *attributes = c_parser_attributes (parser);
8841
8842 /* If there were no attributes here, just report any earlier error. */
8843 if (*attributes == NULL_TREE || bad)
8844 return bad;
8845
8846 /* If the attributes are followed by a ; or {, then just report any earlier
8847 error. */
8848 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
8849 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8850 return bad;
8851
8852 /* We've got attributes, but not at the end. */
8853 c_parser_error (parser,
8854 "expected %<;%> or %<{%> after method attribute definition");
8855 return true;
8856 }
8857
8858 /* Parse an objc-method-decl.
8859
8860 objc-method-decl:
8861 ( objc-type-name ) objc-selector
8862 objc-selector
8863 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8864 objc-keyword-selector objc-optparmlist
8865 attributes
8866
8867 objc-keyword-selector:
8868 objc-keyword-decl
8869 objc-keyword-selector objc-keyword-decl
8870
8871 objc-keyword-decl:
8872 objc-selector : ( objc-type-name ) identifier
8873 objc-selector : identifier
8874 : ( objc-type-name ) identifier
8875 : identifier
8876
8877 objc-optparmlist:
8878 objc-optparms objc-optellipsis
8879
8880 objc-optparms:
8881 empty
8882 objc-opt-parms , parameter-declaration
8883
8884 objc-optellipsis:
8885 empty
8886 , ...
8887 */
8888
8889 static tree
8890 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
8891 tree *attributes, tree *expr)
8892 {
8893 tree type = NULL_TREE;
8894 tree sel;
8895 tree parms = NULL_TREE;
8896 bool ellipsis = false;
8897 bool attr_err = false;
8898
8899 *attributes = NULL_TREE;
8900 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8901 {
8902 c_parser_consume_token (parser);
8903 type = c_parser_objc_type_name (parser);
8904 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8905 }
8906 sel = c_parser_objc_selector (parser);
8907 /* If there is no selector, or a colon follows, we have an
8908 objc-keyword-selector. If there is a selector, and a colon does
8909 not follow, that selector ends the objc-method-decl. */
8910 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
8911 {
8912 tree tsel = sel;
8913 tree list = NULL_TREE;
8914 while (true)
8915 {
8916 tree atype = NULL_TREE, id, keyworddecl;
8917 tree param_attr = NULL_TREE;
8918 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8919 break;
8920 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8921 {
8922 c_parser_consume_token (parser);
8923 atype = c_parser_objc_type_name (parser);
8924 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8925 "expected %<)%>");
8926 }
8927 /* New ObjC allows attributes on method parameters. */
8928 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8929 param_attr = c_parser_attributes (parser);
8930 if (c_parser_next_token_is_not (parser, CPP_NAME))
8931 {
8932 c_parser_error (parser, "expected identifier");
8933 return error_mark_node;
8934 }
8935 id = c_parser_peek_token (parser)->value;
8936 c_parser_consume_token (parser);
8937 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
8938 list = chainon (list, keyworddecl);
8939 tsel = c_parser_objc_selector (parser);
8940 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
8941 break;
8942 }
8943
8944 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8945
8946 /* Parse the optional parameter list. Optional Objective-C
8947 method parameters follow the C syntax, and may include '...'
8948 to denote a variable number of arguments. */
8949 parms = make_node (TREE_LIST);
8950 while (c_parser_next_token_is (parser, CPP_COMMA))
8951 {
8952 struct c_parm *parm;
8953 c_parser_consume_token (parser);
8954 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8955 {
8956 ellipsis = true;
8957 c_parser_consume_token (parser);
8958 attr_err |= c_parser_objc_maybe_method_attributes
8959 (parser, attributes) ;
8960 break;
8961 }
8962 parm = c_parser_parameter_declaration (parser, NULL_TREE);
8963 if (parm == NULL)
8964 break;
8965 parms = chainon (parms,
8966 build_tree_list (NULL_TREE, grokparm (parm, expr)));
8967 }
8968 sel = list;
8969 }
8970 else
8971 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8972
8973 if (sel == NULL)
8974 {
8975 c_parser_error (parser, "objective-c method declaration is expected");
8976 return error_mark_node;
8977 }
8978
8979 if (attr_err)
8980 return error_mark_node;
8981
8982 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
8983 }
8984
8985 /* Parse an objc-type-name.
8986
8987 objc-type-name:
8988 objc-type-qualifiers[opt] type-name
8989 objc-type-qualifiers[opt]
8990
8991 objc-type-qualifiers:
8992 objc-type-qualifier
8993 objc-type-qualifiers objc-type-qualifier
8994
8995 objc-type-qualifier: one of
8996 in out inout bycopy byref oneway
8997 */
8998
8999 static tree
9000 c_parser_objc_type_name (c_parser *parser)
9001 {
9002 tree quals = NULL_TREE;
9003 struct c_type_name *type_name = NULL;
9004 tree type = NULL_TREE;
9005 while (true)
9006 {
9007 c_token *token = c_parser_peek_token (parser);
9008 if (token->type == CPP_KEYWORD
9009 && (token->keyword == RID_IN
9010 || token->keyword == RID_OUT
9011 || token->keyword == RID_INOUT
9012 || token->keyword == RID_BYCOPY
9013 || token->keyword == RID_BYREF
9014 || token->keyword == RID_ONEWAY))
9015 {
9016 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
9017 c_parser_consume_token (parser);
9018 }
9019 else
9020 break;
9021 }
9022 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
9023 type_name = c_parser_type_name (parser);
9024 if (type_name)
9025 type = groktypename (type_name, NULL, NULL);
9026
9027 /* If the type is unknown, and error has already been produced and
9028 we need to recover from the error. In that case, use NULL_TREE
9029 for the type, as if no type had been specified; this will use the
9030 default type ('id') which is good for error recovery. */
9031 if (type == error_mark_node)
9032 type = NULL_TREE;
9033
9034 return build_tree_list (quals, type);
9035 }
9036
9037 /* Parse objc-protocol-refs.
9038
9039 objc-protocol-refs:
9040 < identifier-list >
9041 */
9042
9043 static tree
9044 c_parser_objc_protocol_refs (c_parser *parser)
9045 {
9046 tree list = NULL_TREE;
9047 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
9048 c_parser_consume_token (parser);
9049 /* Any identifiers, including those declared as type names, are OK
9050 here. */
9051 while (true)
9052 {
9053 tree id;
9054 if (c_parser_next_token_is_not (parser, CPP_NAME))
9055 {
9056 c_parser_error (parser, "expected identifier");
9057 break;
9058 }
9059 id = c_parser_peek_token (parser)->value;
9060 list = chainon (list, build_tree_list (NULL_TREE, id));
9061 c_parser_consume_token (parser);
9062 if (c_parser_next_token_is (parser, CPP_COMMA))
9063 c_parser_consume_token (parser);
9064 else
9065 break;
9066 }
9067 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
9068 return list;
9069 }
9070
9071 /* Parse an objc-try-catch-finally-statement.
9072
9073 objc-try-catch-finally-statement:
9074 @try compound-statement objc-catch-list[opt]
9075 @try compound-statement objc-catch-list[opt] @finally compound-statement
9076
9077 objc-catch-list:
9078 @catch ( objc-catch-parameter-declaration ) compound-statement
9079 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9080
9081 objc-catch-parameter-declaration:
9082 parameter-declaration
9083 '...'
9084
9085 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9086
9087 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9088 for C++. Keep them in sync. */
9089
9090 static void
9091 c_parser_objc_try_catch_finally_statement (c_parser *parser)
9092 {
9093 location_t location;
9094 tree stmt;
9095
9096 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
9097 c_parser_consume_token (parser);
9098 location = c_parser_peek_token (parser)->location;
9099 objc_maybe_warn_exceptions (location);
9100 stmt = c_parser_compound_statement (parser);
9101 objc_begin_try_stmt (location, stmt);
9102
9103 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
9104 {
9105 struct c_parm *parm;
9106 tree parameter_declaration = error_mark_node;
9107 bool seen_open_paren = false;
9108
9109 c_parser_consume_token (parser);
9110 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9111 seen_open_paren = true;
9112 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
9113 {
9114 /* We have "@catch (...)" (where the '...' are literally
9115 what is in the code). Skip the '...'.
9116 parameter_declaration is set to NULL_TREE, and
9117 objc_being_catch_clauses() knows that that means
9118 '...'. */
9119 c_parser_consume_token (parser);
9120 parameter_declaration = NULL_TREE;
9121 }
9122 else
9123 {
9124 /* We have "@catch (NSException *exception)" or something
9125 like that. Parse the parameter declaration. */
9126 parm = c_parser_parameter_declaration (parser, NULL_TREE);
9127 if (parm == NULL)
9128 parameter_declaration = error_mark_node;
9129 else
9130 parameter_declaration = grokparm (parm, NULL);
9131 }
9132 if (seen_open_paren)
9133 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9134 else
9135 {
9136 /* If there was no open parenthesis, we are recovering from
9137 an error, and we are trying to figure out what mistake
9138 the user has made. */
9139
9140 /* If there is an immediate closing parenthesis, the user
9141 probably forgot the opening one (ie, they typed "@catch
9142 NSException *e)". Parse the closing parenthesis and keep
9143 going. */
9144 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9145 c_parser_consume_token (parser);
9146
9147 /* If these is no immediate closing parenthesis, the user
9148 probably doesn't know that parenthesis are required at
9149 all (ie, they typed "@catch NSException *e"). So, just
9150 forget about the closing parenthesis and keep going. */
9151 }
9152 objc_begin_catch_clause (parameter_declaration);
9153 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9154 c_parser_compound_statement_nostart (parser);
9155 objc_finish_catch_clause ();
9156 }
9157 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
9158 {
9159 c_parser_consume_token (parser);
9160 location = c_parser_peek_token (parser)->location;
9161 stmt = c_parser_compound_statement (parser);
9162 objc_build_finally_clause (location, stmt);
9163 }
9164 objc_finish_try_stmt ();
9165 }
9166
9167 /* Parse an objc-synchronized-statement.
9168
9169 objc-synchronized-statement:
9170 @synchronized ( expression ) compound-statement
9171 */
9172
9173 static void
9174 c_parser_objc_synchronized_statement (c_parser *parser)
9175 {
9176 location_t loc;
9177 tree expr, stmt;
9178 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
9179 c_parser_consume_token (parser);
9180 loc = c_parser_peek_token (parser)->location;
9181 objc_maybe_warn_exceptions (loc);
9182 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9183 {
9184 struct c_expr ce = c_parser_expression (parser);
9185 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9186 expr = ce.value;
9187 expr = c_fully_fold (expr, false, NULL);
9188 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9189 }
9190 else
9191 expr = error_mark_node;
9192 stmt = c_parser_compound_statement (parser);
9193 objc_build_synchronized (loc, expr, stmt);
9194 }
9195
9196 /* Parse an objc-selector; return NULL_TREE without an error if the
9197 next token is not an objc-selector.
9198
9199 objc-selector:
9200 identifier
9201 one of
9202 enum struct union if else while do for switch case default
9203 break continue return goto asm sizeof typeof __alignof
9204 unsigned long const short volatile signed restrict _Complex
9205 in out inout bycopy byref oneway int char float double void _Bool
9206 _Atomic
9207
9208 ??? Why this selection of keywords but not, for example, storage
9209 class specifiers? */
9210
9211 static tree
9212 c_parser_objc_selector (c_parser *parser)
9213 {
9214 c_token *token = c_parser_peek_token (parser);
9215 tree value = token->value;
9216 if (token->type == CPP_NAME)
9217 {
9218 c_parser_consume_token (parser);
9219 return value;
9220 }
9221 if (token->type != CPP_KEYWORD)
9222 return NULL_TREE;
9223 switch (token->keyword)
9224 {
9225 case RID_ENUM:
9226 case RID_STRUCT:
9227 case RID_UNION:
9228 case RID_IF:
9229 case RID_ELSE:
9230 case RID_WHILE:
9231 case RID_DO:
9232 case RID_FOR:
9233 case RID_SWITCH:
9234 case RID_CASE:
9235 case RID_DEFAULT:
9236 case RID_BREAK:
9237 case RID_CONTINUE:
9238 case RID_RETURN:
9239 case RID_GOTO:
9240 case RID_ASM:
9241 case RID_SIZEOF:
9242 case RID_TYPEOF:
9243 case RID_ALIGNOF:
9244 case RID_UNSIGNED:
9245 case RID_LONG:
9246 case RID_CONST:
9247 case RID_SHORT:
9248 case RID_VOLATILE:
9249 case RID_SIGNED:
9250 case RID_RESTRICT:
9251 case RID_COMPLEX:
9252 case RID_IN:
9253 case RID_OUT:
9254 case RID_INOUT:
9255 case RID_BYCOPY:
9256 case RID_BYREF:
9257 case RID_ONEWAY:
9258 case RID_INT:
9259 case RID_CHAR:
9260 case RID_FLOAT:
9261 case RID_DOUBLE:
9262 case RID_VOID:
9263 case RID_BOOL:
9264 case RID_ATOMIC:
9265 case RID_AUTO_TYPE:
9266 case RID_INT_N_0:
9267 case RID_INT_N_1:
9268 case RID_INT_N_2:
9269 case RID_INT_N_3:
9270 c_parser_consume_token (parser);
9271 return value;
9272 default:
9273 return NULL_TREE;
9274 }
9275 }
9276
9277 /* Parse an objc-selector-arg.
9278
9279 objc-selector-arg:
9280 objc-selector
9281 objc-keywordname-list
9282
9283 objc-keywordname-list:
9284 objc-keywordname
9285 objc-keywordname-list objc-keywordname
9286
9287 objc-keywordname:
9288 objc-selector :
9289 :
9290 */
9291
9292 static tree
9293 c_parser_objc_selector_arg (c_parser *parser)
9294 {
9295 tree sel = c_parser_objc_selector (parser);
9296 tree list = NULL_TREE;
9297 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9298 return sel;
9299 while (true)
9300 {
9301 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9302 return list;
9303 list = chainon (list, build_tree_list (sel, NULL_TREE));
9304 sel = c_parser_objc_selector (parser);
9305 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9306 break;
9307 }
9308 return list;
9309 }
9310
9311 /* Parse an objc-receiver.
9312
9313 objc-receiver:
9314 expression
9315 class-name
9316 type-name
9317 */
9318
9319 static tree
9320 c_parser_objc_receiver (c_parser *parser)
9321 {
9322 location_t loc = c_parser_peek_token (parser)->location;
9323
9324 if (c_parser_peek_token (parser)->type == CPP_NAME
9325 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
9326 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
9327 {
9328 tree id = c_parser_peek_token (parser)->value;
9329 c_parser_consume_token (parser);
9330 return objc_get_class_reference (id);
9331 }
9332 struct c_expr ce = c_parser_expression (parser);
9333 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9334 return c_fully_fold (ce.value, false, NULL);
9335 }
9336
9337 /* Parse objc-message-args.
9338
9339 objc-message-args:
9340 objc-selector
9341 objc-keywordarg-list
9342
9343 objc-keywordarg-list:
9344 objc-keywordarg
9345 objc-keywordarg-list objc-keywordarg
9346
9347 objc-keywordarg:
9348 objc-selector : objc-keywordexpr
9349 : objc-keywordexpr
9350 */
9351
9352 static tree
9353 c_parser_objc_message_args (c_parser *parser)
9354 {
9355 tree sel = c_parser_objc_selector (parser);
9356 tree list = NULL_TREE;
9357 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9358 return sel;
9359 while (true)
9360 {
9361 tree keywordexpr;
9362 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9363 return error_mark_node;
9364 keywordexpr = c_parser_objc_keywordexpr (parser);
9365 list = chainon (list, build_tree_list (sel, keywordexpr));
9366 sel = c_parser_objc_selector (parser);
9367 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9368 break;
9369 }
9370 return list;
9371 }
9372
9373 /* Parse an objc-keywordexpr.
9374
9375 objc-keywordexpr:
9376 nonempty-expr-list
9377 */
9378
9379 static tree
9380 c_parser_objc_keywordexpr (c_parser *parser)
9381 {
9382 tree ret;
9383 vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
9384 NULL, NULL, NULL, NULL);
9385 if (vec_safe_length (expr_list) == 1)
9386 {
9387 /* Just return the expression, remove a level of
9388 indirection. */
9389 ret = (*expr_list)[0];
9390 }
9391 else
9392 {
9393 /* We have a comma expression, we will collapse later. */
9394 ret = build_tree_list_vec (expr_list);
9395 }
9396 release_tree_vector (expr_list);
9397 return ret;
9398 }
9399
9400 /* A check, needed in several places, that ObjC interface, implementation or
9401 method definitions are not prefixed by incorrect items. */
9402 static bool
9403 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
9404 struct c_declspecs *specs)
9405 {
9406 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
9407 || specs->typespec_kind != ctsk_none)
9408 {
9409 c_parser_error (parser,
9410 "no type or storage class may be specified here,");
9411 c_parser_skip_to_end_of_block_or_statement (parser);
9412 return true;
9413 }
9414 return false;
9415 }
9416
9417 /* Parse an Objective-C @property declaration. The syntax is:
9418
9419 objc-property-declaration:
9420 '@property' objc-property-attributes[opt] struct-declaration ;
9421
9422 objc-property-attributes:
9423 '(' objc-property-attribute-list ')'
9424
9425 objc-property-attribute-list:
9426 objc-property-attribute
9427 objc-property-attribute-list, objc-property-attribute
9428
9429 objc-property-attribute
9430 'getter' = identifier
9431 'setter' = identifier
9432 'readonly'
9433 'readwrite'
9434 'assign'
9435 'retain'
9436 'copy'
9437 'nonatomic'
9438
9439 For example:
9440 @property NSString *name;
9441 @property (readonly) id object;
9442 @property (retain, nonatomic, getter=getTheName) id name;
9443 @property int a, b, c;
9444
9445 PS: This function is identical to cp_parser_objc_at_propery_declaration
9446 for C++. Keep them in sync. */
9447 static void
9448 c_parser_objc_at_property_declaration (c_parser *parser)
9449 {
9450 /* The following variables hold the attributes of the properties as
9451 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9452 seen. When we see an attribute, we set them to 'true' (if they
9453 are boolean properties) or to the identifier (if they have an
9454 argument, ie, for getter and setter). Note that here we only
9455 parse the list of attributes, check the syntax and accumulate the
9456 attributes that we find. objc_add_property_declaration() will
9457 then process the information. */
9458 bool property_assign = false;
9459 bool property_copy = false;
9460 tree property_getter_ident = NULL_TREE;
9461 bool property_nonatomic = false;
9462 bool property_readonly = false;
9463 bool property_readwrite = false;
9464 bool property_retain = false;
9465 tree property_setter_ident = NULL_TREE;
9466
9467 /* 'properties' is the list of properties that we read. Usually a
9468 single one, but maybe more (eg, in "@property int a, b, c;" there
9469 are three). */
9470 tree properties;
9471 location_t loc;
9472
9473 loc = c_parser_peek_token (parser)->location;
9474 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
9475
9476 c_parser_consume_token (parser); /* Eat '@property'. */
9477
9478 /* Parse the optional attribute list... */
9479 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9480 {
9481 /* Eat the '(' */
9482 c_parser_consume_token (parser);
9483
9484 /* Property attribute keywords are valid now. */
9485 parser->objc_property_attr_context = true;
9486
9487 while (true)
9488 {
9489 bool syntax_error = false;
9490 c_token *token = c_parser_peek_token (parser);
9491 enum rid keyword;
9492
9493 if (token->type != CPP_KEYWORD)
9494 {
9495 if (token->type == CPP_CLOSE_PAREN)
9496 c_parser_error (parser, "expected identifier");
9497 else
9498 {
9499 c_parser_consume_token (parser);
9500 c_parser_error (parser, "unknown property attribute");
9501 }
9502 break;
9503 }
9504 keyword = token->keyword;
9505 c_parser_consume_token (parser);
9506 switch (keyword)
9507 {
9508 case RID_ASSIGN: property_assign = true; break;
9509 case RID_COPY: property_copy = true; break;
9510 case RID_NONATOMIC: property_nonatomic = true; break;
9511 case RID_READONLY: property_readonly = true; break;
9512 case RID_READWRITE: property_readwrite = true; break;
9513 case RID_RETAIN: property_retain = true; break;
9514
9515 case RID_GETTER:
9516 case RID_SETTER:
9517 if (c_parser_next_token_is_not (parser, CPP_EQ))
9518 {
9519 if (keyword == RID_GETTER)
9520 c_parser_error (parser,
9521 "missing %<=%> (after %<getter%> attribute)");
9522 else
9523 c_parser_error (parser,
9524 "missing %<=%> (after %<setter%> attribute)");
9525 syntax_error = true;
9526 break;
9527 }
9528 c_parser_consume_token (parser); /* eat the = */
9529 if (c_parser_next_token_is_not (parser, CPP_NAME))
9530 {
9531 c_parser_error (parser, "expected identifier");
9532 syntax_error = true;
9533 break;
9534 }
9535 if (keyword == RID_SETTER)
9536 {
9537 if (property_setter_ident != NULL_TREE)
9538 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
9539 else
9540 property_setter_ident = c_parser_peek_token (parser)->value;
9541 c_parser_consume_token (parser);
9542 if (c_parser_next_token_is_not (parser, CPP_COLON))
9543 c_parser_error (parser, "setter name must terminate with %<:%>");
9544 else
9545 c_parser_consume_token (parser);
9546 }
9547 else
9548 {
9549 if (property_getter_ident != NULL_TREE)
9550 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
9551 else
9552 property_getter_ident = c_parser_peek_token (parser)->value;
9553 c_parser_consume_token (parser);
9554 }
9555 break;
9556 default:
9557 c_parser_error (parser, "unknown property attribute");
9558 syntax_error = true;
9559 break;
9560 }
9561
9562 if (syntax_error)
9563 break;
9564
9565 if (c_parser_next_token_is (parser, CPP_COMMA))
9566 c_parser_consume_token (parser);
9567 else
9568 break;
9569 }
9570 parser->objc_property_attr_context = false;
9571 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9572 }
9573 /* ... and the property declaration(s). */
9574 properties = c_parser_struct_declaration (parser);
9575
9576 if (properties == error_mark_node)
9577 {
9578 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9579 parser->error = false;
9580 return;
9581 }
9582
9583 if (properties == NULL_TREE)
9584 c_parser_error (parser, "expected identifier");
9585 else
9586 {
9587 /* Comma-separated properties are chained together in
9588 reverse order; add them one by one. */
9589 properties = nreverse (properties);
9590
9591 for (; properties; properties = TREE_CHAIN (properties))
9592 objc_add_property_declaration (loc, copy_node (properties),
9593 property_readonly, property_readwrite,
9594 property_assign, property_retain,
9595 property_copy, property_nonatomic,
9596 property_getter_ident, property_setter_ident);
9597 }
9598
9599 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9600 parser->error = false;
9601 }
9602
9603 /* Parse an Objective-C @synthesize declaration. The syntax is:
9604
9605 objc-synthesize-declaration:
9606 @synthesize objc-synthesize-identifier-list ;
9607
9608 objc-synthesize-identifier-list:
9609 objc-synthesize-identifier
9610 objc-synthesize-identifier-list, objc-synthesize-identifier
9611
9612 objc-synthesize-identifier
9613 identifier
9614 identifier = identifier
9615
9616 For example:
9617 @synthesize MyProperty;
9618 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9619
9620 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9621 for C++. Keep them in sync.
9622 */
9623 static void
9624 c_parser_objc_at_synthesize_declaration (c_parser *parser)
9625 {
9626 tree list = NULL_TREE;
9627 location_t loc;
9628 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
9629 loc = c_parser_peek_token (parser)->location;
9630
9631 c_parser_consume_token (parser);
9632 while (true)
9633 {
9634 tree property, ivar;
9635 if (c_parser_next_token_is_not (parser, CPP_NAME))
9636 {
9637 c_parser_error (parser, "expected identifier");
9638 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9639 /* Once we find the semicolon, we can resume normal parsing.
9640 We have to reset parser->error manually because
9641 c_parser_skip_until_found() won't reset it for us if the
9642 next token is precisely a semicolon. */
9643 parser->error = false;
9644 return;
9645 }
9646 property = c_parser_peek_token (parser)->value;
9647 c_parser_consume_token (parser);
9648 if (c_parser_next_token_is (parser, CPP_EQ))
9649 {
9650 c_parser_consume_token (parser);
9651 if (c_parser_next_token_is_not (parser, CPP_NAME))
9652 {
9653 c_parser_error (parser, "expected identifier");
9654 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9655 parser->error = false;
9656 return;
9657 }
9658 ivar = c_parser_peek_token (parser)->value;
9659 c_parser_consume_token (parser);
9660 }
9661 else
9662 ivar = NULL_TREE;
9663 list = chainon (list, build_tree_list (ivar, property));
9664 if (c_parser_next_token_is (parser, CPP_COMMA))
9665 c_parser_consume_token (parser);
9666 else
9667 break;
9668 }
9669 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9670 objc_add_synthesize_declaration (loc, list);
9671 }
9672
9673 /* Parse an Objective-C @dynamic declaration. The syntax is:
9674
9675 objc-dynamic-declaration:
9676 @dynamic identifier-list ;
9677
9678 For example:
9679 @dynamic MyProperty;
9680 @dynamic MyProperty, AnotherProperty;
9681
9682 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9683 for C++. Keep them in sync.
9684 */
9685 static void
9686 c_parser_objc_at_dynamic_declaration (c_parser *parser)
9687 {
9688 tree list = NULL_TREE;
9689 location_t loc;
9690 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
9691 loc = c_parser_peek_token (parser)->location;
9692
9693 c_parser_consume_token (parser);
9694 while (true)
9695 {
9696 tree property;
9697 if (c_parser_next_token_is_not (parser, CPP_NAME))
9698 {
9699 c_parser_error (parser, "expected identifier");
9700 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9701 parser->error = false;
9702 return;
9703 }
9704 property = c_parser_peek_token (parser)->value;
9705 list = chainon (list, build_tree_list (NULL_TREE, property));
9706 c_parser_consume_token (parser);
9707 if (c_parser_next_token_is (parser, CPP_COMMA))
9708 c_parser_consume_token (parser);
9709 else
9710 break;
9711 }
9712 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9713 objc_add_dynamic_declaration (loc, list);
9714 }
9715
9716 \f
9717 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9718 should be considered, statements. ALLOW_STMT is true if we're within
9719 the context of a function and such pragmas are to be allowed. Returns
9720 true if we actually parsed such a pragma. */
9721
9722 static bool
9723 c_parser_pragma (c_parser *parser, enum pragma_context context)
9724 {
9725 unsigned int id;
9726
9727 id = c_parser_peek_token (parser)->pragma_kind;
9728 gcc_assert (id != PRAGMA_NONE);
9729
9730 switch (id)
9731 {
9732 case PRAGMA_OACC_ENTER_DATA:
9733 c_parser_oacc_enter_exit_data (parser, true);
9734 return false;
9735
9736 case PRAGMA_OACC_EXIT_DATA:
9737 c_parser_oacc_enter_exit_data (parser, false);
9738 return false;
9739
9740 case PRAGMA_OACC_ROUTINE:
9741 c_parser_oacc_routine (parser, context);
9742 return false;
9743
9744 case PRAGMA_OACC_UPDATE:
9745 if (context != pragma_compound)
9746 {
9747 if (context == pragma_stmt)
9748 c_parser_error (parser, "%<#pragma acc update%> may only be "
9749 "used in compound statements");
9750 goto bad_stmt;
9751 }
9752 c_parser_oacc_update (parser);
9753 return false;
9754
9755 case PRAGMA_OMP_BARRIER:
9756 if (context != pragma_compound)
9757 {
9758 if (context == pragma_stmt)
9759 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
9760 "used in compound statements");
9761 goto bad_stmt;
9762 }
9763 c_parser_omp_barrier (parser);
9764 return false;
9765
9766 case PRAGMA_OMP_FLUSH:
9767 if (context != pragma_compound)
9768 {
9769 if (context == pragma_stmt)
9770 c_parser_error (parser, "%<#pragma omp flush%> may only be "
9771 "used in compound statements");
9772 goto bad_stmt;
9773 }
9774 c_parser_omp_flush (parser);
9775 return false;
9776
9777 case PRAGMA_OMP_TASKWAIT:
9778 if (context != pragma_compound)
9779 {
9780 if (context == pragma_stmt)
9781 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
9782 "used in compound statements");
9783 goto bad_stmt;
9784 }
9785 c_parser_omp_taskwait (parser);
9786 return false;
9787
9788 case PRAGMA_OMP_TASKYIELD:
9789 if (context != pragma_compound)
9790 {
9791 if (context == pragma_stmt)
9792 c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
9793 "used in compound statements");
9794 goto bad_stmt;
9795 }
9796 c_parser_omp_taskyield (parser);
9797 return false;
9798
9799 case PRAGMA_OMP_CANCEL:
9800 if (context != pragma_compound)
9801 {
9802 if (context == pragma_stmt)
9803 c_parser_error (parser, "%<#pragma omp cancel%> may only be "
9804 "used in compound statements");
9805 goto bad_stmt;
9806 }
9807 c_parser_omp_cancel (parser);
9808 return false;
9809
9810 case PRAGMA_OMP_CANCELLATION_POINT:
9811 if (context != pragma_compound)
9812 {
9813 if (context == pragma_stmt)
9814 c_parser_error (parser, "%<#pragma omp cancellation point%> may "
9815 "only be used in compound statements");
9816 goto bad_stmt;
9817 }
9818 c_parser_omp_cancellation_point (parser);
9819 return false;
9820
9821 case PRAGMA_OMP_THREADPRIVATE:
9822 c_parser_omp_threadprivate (parser);
9823 return false;
9824
9825 case PRAGMA_OMP_TARGET:
9826 return c_parser_omp_target (parser, context);
9827
9828 case PRAGMA_OMP_END_DECLARE_TARGET:
9829 c_parser_omp_end_declare_target (parser);
9830 return false;
9831
9832 case PRAGMA_OMP_SECTION:
9833 error_at (c_parser_peek_token (parser)->location,
9834 "%<#pragma omp section%> may only be used in "
9835 "%<#pragma omp sections%> construct");
9836 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9837 return false;
9838
9839 case PRAGMA_OMP_DECLARE_REDUCTION:
9840 c_parser_omp_declare (parser, context);
9841 return false;
9842
9843 case PRAGMA_OMP_ORDERED:
9844 return c_parser_omp_ordered (parser, context);
9845
9846 case PRAGMA_IVDEP:
9847 c_parser_consume_pragma (parser);
9848 c_parser_skip_to_pragma_eol (parser);
9849 if (!c_parser_next_token_is_keyword (parser, RID_FOR)
9850 && !c_parser_next_token_is_keyword (parser, RID_WHILE)
9851 && !c_parser_next_token_is_keyword (parser, RID_DO))
9852 {
9853 c_parser_error (parser, "for, while or do statement expected");
9854 return false;
9855 }
9856 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9857 c_parser_for_statement (parser, true);
9858 else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
9859 c_parser_while_statement (parser, true);
9860 else
9861 c_parser_do_statement (parser, true);
9862 return false;
9863
9864 case PRAGMA_GCC_PCH_PREPROCESS:
9865 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
9866 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9867 return false;
9868
9869 case PRAGMA_CILK_SIMD:
9870 if (!c_parser_cilk_verify_simd (parser, context))
9871 return false;
9872 c_parser_consume_pragma (parser);
9873 c_parser_cilk_simd (parser);
9874 return false;
9875 case PRAGMA_CILK_GRAINSIZE:
9876 if (!flag_cilkplus)
9877 {
9878 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9879 " enabled");
9880 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9881 return false;
9882 }
9883 if (context == pragma_external)
9884 {
9885 error_at (c_parser_peek_token (parser)->location,
9886 "%<#pragma grainsize%> must be inside a function");
9887 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9888 return false;
9889 }
9890 c_parser_cilk_grainsize (parser);
9891 return false;
9892
9893 default:
9894 if (id < PRAGMA_FIRST_EXTERNAL)
9895 {
9896 if (context != pragma_stmt && context != pragma_compound)
9897 {
9898 bad_stmt:
9899 c_parser_error (parser, "expected declaration specifiers");
9900 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9901 return false;
9902 }
9903 c_parser_omp_construct (parser);
9904 return true;
9905 }
9906 break;
9907 }
9908
9909 c_parser_consume_pragma (parser);
9910 c_invoke_pragma_handler (id);
9911
9912 /* Skip to EOL, but suppress any error message. Those will have been
9913 generated by the handler routine through calling error, as opposed
9914 to calling c_parser_error. */
9915 parser->error = true;
9916 c_parser_skip_to_pragma_eol (parser);
9917
9918 return false;
9919 }
9920
9921 /* The interface the pragma parsers have to the lexer. */
9922
9923 enum cpp_ttype
9924 pragma_lex (tree *value, location_t *loc)
9925 {
9926 c_token *tok = c_parser_peek_token (the_parser);
9927 enum cpp_ttype ret = tok->type;
9928
9929 *value = tok->value;
9930 if (loc)
9931 *loc = tok->location;
9932
9933 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
9934 ret = CPP_EOF;
9935 else
9936 {
9937 if (ret == CPP_KEYWORD)
9938 ret = CPP_NAME;
9939 c_parser_consume_token (the_parser);
9940 }
9941
9942 return ret;
9943 }
9944
9945 static void
9946 c_parser_pragma_pch_preprocess (c_parser *parser)
9947 {
9948 tree name = NULL;
9949
9950 c_parser_consume_pragma (parser);
9951 if (c_parser_next_token_is (parser, CPP_STRING))
9952 {
9953 name = c_parser_peek_token (parser)->value;
9954 c_parser_consume_token (parser);
9955 }
9956 else
9957 c_parser_error (parser, "expected string literal");
9958 c_parser_skip_to_pragma_eol (parser);
9959
9960 if (name)
9961 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
9962 }
9963 \f
9964 /* OpenACC and OpenMP parsing routines. */
9965
9966 /* Returns name of the next clause.
9967 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9968 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9969 returned and the token is consumed. */
9970
9971 static pragma_omp_clause
9972 c_parser_omp_clause_name (c_parser *parser)
9973 {
9974 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
9975
9976 if (c_parser_next_token_is_keyword (parser, RID_AUTO))
9977 result = PRAGMA_OACC_CLAUSE_AUTO;
9978 else if (c_parser_next_token_is_keyword (parser, RID_IF))
9979 result = PRAGMA_OMP_CLAUSE_IF;
9980 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
9981 result = PRAGMA_OMP_CLAUSE_DEFAULT;
9982 else if (c_parser_next_token_is_keyword (parser, RID_FOR))
9983 result = PRAGMA_OMP_CLAUSE_FOR;
9984 else if (c_parser_next_token_is (parser, CPP_NAME))
9985 {
9986 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9987
9988 switch (p[0])
9989 {
9990 case 'a':
9991 if (!strcmp ("aligned", p))
9992 result = PRAGMA_OMP_CLAUSE_ALIGNED;
9993 else if (!strcmp ("async", p))
9994 result = PRAGMA_OACC_CLAUSE_ASYNC;
9995 break;
9996 case 'c':
9997 if (!strcmp ("collapse", p))
9998 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
9999 else if (!strcmp ("copy", p))
10000 result = PRAGMA_OACC_CLAUSE_COPY;
10001 else if (!strcmp ("copyin", p))
10002 result = PRAGMA_OMP_CLAUSE_COPYIN;
10003 else if (!strcmp ("copyout", p))
10004 result = PRAGMA_OACC_CLAUSE_COPYOUT;
10005 else if (!strcmp ("copyprivate", p))
10006 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
10007 else if (!strcmp ("create", p))
10008 result = PRAGMA_OACC_CLAUSE_CREATE;
10009 break;
10010 case 'd':
10011 if (!strcmp ("defaultmap", p))
10012 result = PRAGMA_OMP_CLAUSE_DEFAULTMAP;
10013 else if (!strcmp ("delete", p))
10014 result = PRAGMA_OACC_CLAUSE_DELETE;
10015 else if (!strcmp ("depend", p))
10016 result = PRAGMA_OMP_CLAUSE_DEPEND;
10017 else if (!strcmp ("device", p))
10018 result = PRAGMA_OMP_CLAUSE_DEVICE;
10019 else if (!strcmp ("deviceptr", p))
10020 result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
10021 else if (!strcmp ("dist_schedule", p))
10022 result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
10023 break;
10024 case 'f':
10025 if (!strcmp ("final", p))
10026 result = PRAGMA_OMP_CLAUSE_FINAL;
10027 else if (!strcmp ("firstprivate", p))
10028 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
10029 else if (!strcmp ("from", p))
10030 result = PRAGMA_OMP_CLAUSE_FROM;
10031 break;
10032 case 'g':
10033 if (!strcmp ("gang", p))
10034 result = PRAGMA_OACC_CLAUSE_GANG;
10035 else if (!strcmp ("grainsize", p))
10036 result = PRAGMA_OMP_CLAUSE_GRAINSIZE;
10037 break;
10038 case 'h':
10039 if (!strcmp ("hint", p))
10040 result = PRAGMA_OMP_CLAUSE_HINT;
10041 else if (!strcmp ("host", p))
10042 result = PRAGMA_OACC_CLAUSE_HOST;
10043 break;
10044 case 'i':
10045 if (!strcmp ("inbranch", p))
10046 result = PRAGMA_OMP_CLAUSE_INBRANCH;
10047 else if (!strcmp ("independent", p))
10048 result = PRAGMA_OACC_CLAUSE_INDEPENDENT;
10049 else if (!strcmp ("is_device_ptr", p))
10050 result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR;
10051 break;
10052 case 'l':
10053 if (!strcmp ("lastprivate", p))
10054 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
10055 else if (!strcmp ("linear", p))
10056 result = PRAGMA_OMP_CLAUSE_LINEAR;
10057 else if (!strcmp ("link", p))
10058 result = PRAGMA_OMP_CLAUSE_LINK;
10059 break;
10060 case 'm':
10061 if (!strcmp ("map", p))
10062 result = PRAGMA_OMP_CLAUSE_MAP;
10063 else if (!strcmp ("mergeable", p))
10064 result = PRAGMA_OMP_CLAUSE_MERGEABLE;
10065 else if (flag_cilkplus && !strcmp ("mask", p))
10066 result = PRAGMA_CILK_CLAUSE_MASK;
10067 break;
10068 case 'n':
10069 if (!strcmp ("nogroup", p))
10070 result = PRAGMA_OMP_CLAUSE_NOGROUP;
10071 else if (!strcmp ("notinbranch", p))
10072 result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
10073 else if (!strcmp ("nowait", p))
10074 result = PRAGMA_OMP_CLAUSE_NOWAIT;
10075 else if (!strcmp ("num_gangs", p))
10076 result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
10077 else if (!strcmp ("num_tasks", p))
10078 result = PRAGMA_OMP_CLAUSE_NUM_TASKS;
10079 else if (!strcmp ("num_teams", p))
10080 result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
10081 else if (!strcmp ("num_threads", p))
10082 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
10083 else if (!strcmp ("num_workers", p))
10084 result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
10085 else if (flag_cilkplus && !strcmp ("nomask", p))
10086 result = PRAGMA_CILK_CLAUSE_NOMASK;
10087 break;
10088 case 'o':
10089 if (!strcmp ("ordered", p))
10090 result = PRAGMA_OMP_CLAUSE_ORDERED;
10091 break;
10092 case 'p':
10093 if (!strcmp ("parallel", p))
10094 result = PRAGMA_OMP_CLAUSE_PARALLEL;
10095 else if (!strcmp ("present", p))
10096 result = PRAGMA_OACC_CLAUSE_PRESENT;
10097 else if (!strcmp ("present_or_copy", p)
10098 || !strcmp ("pcopy", p))
10099 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
10100 else if (!strcmp ("present_or_copyin", p)
10101 || !strcmp ("pcopyin", p))
10102 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
10103 else if (!strcmp ("present_or_copyout", p)
10104 || !strcmp ("pcopyout", p))
10105 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
10106 else if (!strcmp ("present_or_create", p)
10107 || !strcmp ("pcreate", p))
10108 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
10109 else if (!strcmp ("priority", p))
10110 result = PRAGMA_OMP_CLAUSE_PRIORITY;
10111 else if (!strcmp ("private", p))
10112 result = PRAGMA_OMP_CLAUSE_PRIVATE;
10113 else if (!strcmp ("proc_bind", p))
10114 result = PRAGMA_OMP_CLAUSE_PROC_BIND;
10115 break;
10116 case 'r':
10117 if (!strcmp ("reduction", p))
10118 result = PRAGMA_OMP_CLAUSE_REDUCTION;
10119 break;
10120 case 's':
10121 if (!strcmp ("safelen", p))
10122 result = PRAGMA_OMP_CLAUSE_SAFELEN;
10123 else if (!strcmp ("schedule", p))
10124 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
10125 else if (!strcmp ("sections", p))
10126 result = PRAGMA_OMP_CLAUSE_SECTIONS;
10127 else if (!strcmp ("seq", p))
10128 result = PRAGMA_OACC_CLAUSE_SEQ;
10129 else if (!strcmp ("shared", p))
10130 result = PRAGMA_OMP_CLAUSE_SHARED;
10131 else if (!strcmp ("simd", p))
10132 result = PRAGMA_OMP_CLAUSE_SIMD;
10133 else if (!strcmp ("simdlen", p))
10134 result = PRAGMA_OMP_CLAUSE_SIMDLEN;
10135 else if (!strcmp ("self", p))
10136 result = PRAGMA_OACC_CLAUSE_SELF;
10137 break;
10138 case 't':
10139 if (!strcmp ("taskgroup", p))
10140 result = PRAGMA_OMP_CLAUSE_TASKGROUP;
10141 else if (!strcmp ("thread_limit", p))
10142 result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
10143 else if (!strcmp ("threads", p))
10144 result = PRAGMA_OMP_CLAUSE_THREADS;
10145 else if (!strcmp ("tile", p))
10146 result = PRAGMA_OACC_CLAUSE_TILE;
10147 else if (!strcmp ("to", p))
10148 result = PRAGMA_OMP_CLAUSE_TO;
10149 break;
10150 case 'u':
10151 if (!strcmp ("uniform", p))
10152 result = PRAGMA_OMP_CLAUSE_UNIFORM;
10153 else if (!strcmp ("untied", p))
10154 result = PRAGMA_OMP_CLAUSE_UNTIED;
10155 else if (!strcmp ("use_device_ptr", p))
10156 result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR;
10157 break;
10158 case 'v':
10159 if (!strcmp ("vector", p))
10160 result = PRAGMA_OACC_CLAUSE_VECTOR;
10161 else if (!strcmp ("vector_length", p))
10162 result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
10163 else if (flag_cilkplus && !strcmp ("vectorlength", p))
10164 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
10165 break;
10166 case 'w':
10167 if (!strcmp ("wait", p))
10168 result = PRAGMA_OACC_CLAUSE_WAIT;
10169 else if (!strcmp ("worker", p))
10170 result = PRAGMA_OACC_CLAUSE_WORKER;
10171 break;
10172 }
10173 }
10174
10175 if (result != PRAGMA_OMP_CLAUSE_NONE)
10176 c_parser_consume_token (parser);
10177
10178 return result;
10179 }
10180
10181 /* Validate that a clause of the given type does not already exist. */
10182
10183 static void
10184 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
10185 const char *name)
10186 {
10187 tree c;
10188
10189 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
10190 if (OMP_CLAUSE_CODE (c) == code)
10191 {
10192 location_t loc = OMP_CLAUSE_LOCATION (c);
10193 error_at (loc, "too many %qs clauses", name);
10194 break;
10195 }
10196 }
10197
10198 /* OpenACC 2.0
10199 Parse wait clause or wait directive parameters. */
10200
10201 static tree
10202 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
10203 {
10204 vec<tree, va_gc> *args;
10205 tree t, args_tree;
10206
10207 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10208 return list;
10209
10210 args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
10211
10212 if (args->length () == 0)
10213 {
10214 c_parser_error (parser, "expected integer expression before ')'");
10215 release_tree_vector (args);
10216 return list;
10217 }
10218
10219 args_tree = build_tree_list_vec (args);
10220
10221 for (t = args_tree; t; t = TREE_CHAIN (t))
10222 {
10223 tree targ = TREE_VALUE (t);
10224
10225 if (targ != error_mark_node)
10226 {
10227 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
10228 {
10229 c_parser_error (parser, "expression must be integral");
10230 targ = error_mark_node;
10231 }
10232 else
10233 {
10234 tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
10235
10236 OMP_CLAUSE_DECL (c) = targ;
10237 OMP_CLAUSE_CHAIN (c) = list;
10238 list = c;
10239 }
10240 }
10241 }
10242
10243 release_tree_vector (args);
10244 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10245 return list;
10246 }
10247
10248 /* OpenACC 2.0, OpenMP 2.5:
10249 variable-list:
10250 identifier
10251 variable-list , identifier
10252
10253 If KIND is nonzero, create the appropriate node and install the
10254 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10255 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10256
10257 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10258 return the list created. */
10259
10260 static tree
10261 c_parser_omp_variable_list (c_parser *parser,
10262 location_t clause_loc,
10263 enum omp_clause_code kind, tree list)
10264 {
10265 if (c_parser_next_token_is_not (parser, CPP_NAME)
10266 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
10267 c_parser_error (parser, "expected identifier");
10268
10269 while (c_parser_next_token_is (parser, CPP_NAME)
10270 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
10271 {
10272 tree t = lookup_name (c_parser_peek_token (parser)->value);
10273
10274 if (t == NULL_TREE)
10275 {
10276 undeclared_variable (c_parser_peek_token (parser)->location,
10277 c_parser_peek_token (parser)->value);
10278 t = error_mark_node;
10279 }
10280
10281 c_parser_consume_token (parser);
10282
10283 if (t == error_mark_node)
10284 ;
10285 else if (kind != 0)
10286 {
10287 switch (kind)
10288 {
10289 case OMP_CLAUSE__CACHE_:
10290 if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
10291 {
10292 c_parser_error (parser, "expected %<[%>");
10293 t = error_mark_node;
10294 break;
10295 }
10296 /* FALLTHROUGH */
10297 case OMP_CLAUSE_MAP:
10298 case OMP_CLAUSE_FROM:
10299 case OMP_CLAUSE_TO:
10300 while (c_parser_next_token_is (parser, CPP_DOT))
10301 {
10302 location_t op_loc = c_parser_peek_token (parser)->location;
10303 c_parser_consume_token (parser);
10304 if (!c_parser_next_token_is (parser, CPP_NAME))
10305 {
10306 c_parser_error (parser, "expected identifier");
10307 t = error_mark_node;
10308 break;
10309 }
10310 tree ident = c_parser_peek_token (parser)->value;
10311 c_parser_consume_token (parser);
10312 t = build_component_ref (op_loc, t, ident);
10313 }
10314 /* FALLTHROUGH */
10315 case OMP_CLAUSE_DEPEND:
10316 case OMP_CLAUSE_REDUCTION:
10317 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
10318 {
10319 tree low_bound = NULL_TREE, length = NULL_TREE;
10320
10321 c_parser_consume_token (parser);
10322 if (!c_parser_next_token_is (parser, CPP_COLON))
10323 {
10324 low_bound = c_parser_expression (parser).value;
10325 mark_exp_read (low_bound);
10326 }
10327 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10328 length = integer_one_node;
10329 else
10330 {
10331 /* Look for `:'. */
10332 if (!c_parser_require (parser, CPP_COLON,
10333 "expected %<:%>"))
10334 {
10335 t = error_mark_node;
10336 break;
10337 }
10338 if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10339 {
10340 length = c_parser_expression (parser).value;
10341 mark_exp_read (length);
10342 }
10343 }
10344 /* Look for the closing `]'. */
10345 if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
10346 "expected %<]%>"))
10347 {
10348 t = error_mark_node;
10349 break;
10350 }
10351
10352 if (kind == OMP_CLAUSE__CACHE_)
10353 {
10354 if (TREE_CODE (low_bound) != INTEGER_CST
10355 && !TREE_READONLY (low_bound))
10356 {
10357 error_at (clause_loc,
10358 "%qD is not a constant", low_bound);
10359 t = error_mark_node;
10360 }
10361
10362 if (TREE_CODE (length) != INTEGER_CST
10363 && !TREE_READONLY (length))
10364 {
10365 error_at (clause_loc,
10366 "%qD is not a constant", length);
10367 t = error_mark_node;
10368 }
10369 }
10370
10371 t = tree_cons (low_bound, length, t);
10372 }
10373 break;
10374 default:
10375 break;
10376 }
10377
10378 if (t != error_mark_node)
10379 {
10380 tree u = build_omp_clause (clause_loc, kind);
10381 OMP_CLAUSE_DECL (u) = t;
10382 OMP_CLAUSE_CHAIN (u) = list;
10383 list = u;
10384 }
10385 }
10386 else
10387 list = tree_cons (t, NULL_TREE, list);
10388
10389 if (c_parser_next_token_is_not (parser, CPP_COMMA))
10390 break;
10391
10392 c_parser_consume_token (parser);
10393 }
10394
10395 return list;
10396 }
10397
10398 /* Similarly, but expect leading and trailing parenthesis. This is a very
10399 common case for OpenACC and OpenMP clauses. */
10400
10401 static tree
10402 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
10403 tree list)
10404 {
10405 /* The clauses location. */
10406 location_t loc = c_parser_peek_token (parser)->location;
10407
10408 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10409 {
10410 list = c_parser_omp_variable_list (parser, loc, kind, list);
10411 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10412 }
10413 return list;
10414 }
10415
10416 /* OpenACC 2.0:
10417 copy ( variable-list )
10418 copyin ( variable-list )
10419 copyout ( variable-list )
10420 create ( variable-list )
10421 delete ( variable-list )
10422 present ( variable-list )
10423 present_or_copy ( variable-list )
10424 pcopy ( variable-list )
10425 present_or_copyin ( variable-list )
10426 pcopyin ( variable-list )
10427 present_or_copyout ( variable-list )
10428 pcopyout ( variable-list )
10429 present_or_create ( variable-list )
10430 pcreate ( variable-list ) */
10431
10432 static tree
10433 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
10434 tree list)
10435 {
10436 enum gomp_map_kind kind;
10437 switch (c_kind)
10438 {
10439 case PRAGMA_OACC_CLAUSE_COPY:
10440 kind = GOMP_MAP_FORCE_TOFROM;
10441 break;
10442 case PRAGMA_OACC_CLAUSE_COPYIN:
10443 kind = GOMP_MAP_FORCE_TO;
10444 break;
10445 case PRAGMA_OACC_CLAUSE_COPYOUT:
10446 kind = GOMP_MAP_FORCE_FROM;
10447 break;
10448 case PRAGMA_OACC_CLAUSE_CREATE:
10449 kind = GOMP_MAP_FORCE_ALLOC;
10450 break;
10451 case PRAGMA_OACC_CLAUSE_DELETE:
10452 kind = GOMP_MAP_FORCE_DEALLOC;
10453 break;
10454 case PRAGMA_OACC_CLAUSE_DEVICE:
10455 kind = GOMP_MAP_FORCE_TO;
10456 break;
10457 case PRAGMA_OACC_CLAUSE_HOST:
10458 case PRAGMA_OACC_CLAUSE_SELF:
10459 kind = GOMP_MAP_FORCE_FROM;
10460 break;
10461 case PRAGMA_OACC_CLAUSE_PRESENT:
10462 kind = GOMP_MAP_FORCE_PRESENT;
10463 break;
10464 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
10465 kind = GOMP_MAP_TOFROM;
10466 break;
10467 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
10468 kind = GOMP_MAP_TO;
10469 break;
10470 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
10471 kind = GOMP_MAP_FROM;
10472 break;
10473 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
10474 kind = GOMP_MAP_ALLOC;
10475 break;
10476 default:
10477 gcc_unreachable ();
10478 }
10479 tree nl, c;
10480 nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
10481
10482 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10483 OMP_CLAUSE_SET_MAP_KIND (c, kind);
10484
10485 return nl;
10486 }
10487
10488 /* OpenACC 2.0:
10489 deviceptr ( variable-list ) */
10490
10491 static tree
10492 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
10493 {
10494 location_t loc = c_parser_peek_token (parser)->location;
10495 tree vars, t;
10496
10497 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10498 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10499 variable-list must only allow for pointer variables. */
10500 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10501 for (t = vars; t && t; t = TREE_CHAIN (t))
10502 {
10503 tree v = TREE_PURPOSE (t);
10504
10505 /* FIXME diagnostics: Ideally we should keep individual
10506 locations for all the variables in the var list to make the
10507 following errors more precise. Perhaps
10508 c_parser_omp_var_list_parens() should construct a list of
10509 locations to go along with the var list. */
10510
10511 if (!VAR_P (v))
10512 error_at (loc, "%qD is not a variable", v);
10513 else if (TREE_TYPE (v) == error_mark_node)
10514 ;
10515 else if (!POINTER_TYPE_P (TREE_TYPE (v)))
10516 error_at (loc, "%qD is not a pointer variable", v);
10517
10518 tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
10519 OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
10520 OMP_CLAUSE_DECL (u) = v;
10521 OMP_CLAUSE_CHAIN (u) = list;
10522 list = u;
10523 }
10524
10525 return list;
10526 }
10527
10528 /* OpenACC 2.0, OpenMP 3.0:
10529 collapse ( constant-expression ) */
10530
10531 static tree
10532 c_parser_omp_clause_collapse (c_parser *parser, tree list)
10533 {
10534 tree c, num = error_mark_node;
10535 HOST_WIDE_INT n;
10536 location_t loc;
10537
10538 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
10539
10540 loc = c_parser_peek_token (parser)->location;
10541 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10542 {
10543 num = c_parser_expr_no_commas (parser, NULL).value;
10544 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10545 }
10546 if (num == error_mark_node)
10547 return list;
10548 mark_exp_read (num);
10549 num = c_fully_fold (num, false, NULL);
10550 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
10551 || !tree_fits_shwi_p (num)
10552 || (n = tree_to_shwi (num)) <= 0
10553 || (int) n != n)
10554 {
10555 error_at (loc,
10556 "collapse argument needs positive constant integer expression");
10557 return list;
10558 }
10559 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
10560 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
10561 OMP_CLAUSE_CHAIN (c) = list;
10562 return c;
10563 }
10564
10565 /* OpenMP 2.5:
10566 copyin ( variable-list ) */
10567
10568 static tree
10569 c_parser_omp_clause_copyin (c_parser *parser, tree list)
10570 {
10571 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
10572 }
10573
10574 /* OpenMP 2.5:
10575 copyprivate ( variable-list ) */
10576
10577 static tree
10578 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
10579 {
10580 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
10581 }
10582
10583 /* OpenMP 2.5:
10584 default ( shared | none )
10585
10586 OpenACC 2.0:
10587 default (none) */
10588
10589 static tree
10590 c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc)
10591 {
10592 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
10593 location_t loc = c_parser_peek_token (parser)->location;
10594 tree c;
10595
10596 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10597 return list;
10598 if (c_parser_next_token_is (parser, CPP_NAME))
10599 {
10600 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10601
10602 switch (p[0])
10603 {
10604 case 'n':
10605 if (strcmp ("none", p) != 0)
10606 goto invalid_kind;
10607 kind = OMP_CLAUSE_DEFAULT_NONE;
10608 break;
10609
10610 case 's':
10611 if (strcmp ("shared", p) != 0 || is_oacc)
10612 goto invalid_kind;
10613 kind = OMP_CLAUSE_DEFAULT_SHARED;
10614 break;
10615
10616 default:
10617 goto invalid_kind;
10618 }
10619
10620 c_parser_consume_token (parser);
10621 }
10622 else
10623 {
10624 invalid_kind:
10625 if (is_oacc)
10626 c_parser_error (parser, "expected %<none%>");
10627 else
10628 c_parser_error (parser, "expected %<none%> or %<shared%>");
10629 }
10630 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10631
10632 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
10633 return list;
10634
10635 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
10636 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
10637 OMP_CLAUSE_CHAIN (c) = list;
10638 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
10639
10640 return c;
10641 }
10642
10643 /* OpenMP 2.5:
10644 firstprivate ( variable-list ) */
10645
10646 static tree
10647 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
10648 {
10649 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
10650 }
10651
10652 /* OpenMP 3.1:
10653 final ( expression ) */
10654
10655 static tree
10656 c_parser_omp_clause_final (c_parser *parser, tree list)
10657 {
10658 location_t loc = c_parser_peek_token (parser)->location;
10659 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10660 {
10661 tree t = c_parser_paren_condition (parser);
10662 tree c;
10663
10664 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
10665
10666 c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
10667 OMP_CLAUSE_FINAL_EXPR (c) = t;
10668 OMP_CLAUSE_CHAIN (c) = list;
10669 list = c;
10670 }
10671 else
10672 c_parser_error (parser, "expected %<(%>");
10673
10674 return list;
10675 }
10676
10677 /* OpenACC, OpenMP 2.5:
10678 if ( expression )
10679
10680 OpenMP 4.5:
10681 if ( directive-name-modifier : expression )
10682
10683 directive-name-modifier:
10684 parallel | task | taskloop | target data | target | target update
10685 | target enter data | target exit data */
10686
10687 static tree
10688 c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp)
10689 {
10690 location_t location = c_parser_peek_token (parser)->location;
10691 enum tree_code if_modifier = ERROR_MARK;
10692
10693 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10694 return list;
10695
10696 if (is_omp && c_parser_next_token_is (parser, CPP_NAME))
10697 {
10698 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10699 int n = 2;
10700 if (strcmp (p, "parallel") == 0)
10701 if_modifier = OMP_PARALLEL;
10702 else if (strcmp (p, "task") == 0)
10703 if_modifier = OMP_TASK;
10704 else if (strcmp (p, "taskloop") == 0)
10705 if_modifier = OMP_TASKLOOP;
10706 else if (strcmp (p, "target") == 0)
10707 {
10708 if_modifier = OMP_TARGET;
10709 if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
10710 {
10711 p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value);
10712 if (strcmp ("data", p) == 0)
10713 if_modifier = OMP_TARGET_DATA;
10714 else if (strcmp ("update", p) == 0)
10715 if_modifier = OMP_TARGET_UPDATE;
10716 else if (strcmp ("enter", p) == 0)
10717 if_modifier = OMP_TARGET_ENTER_DATA;
10718 else if (strcmp ("exit", p) == 0)
10719 if_modifier = OMP_TARGET_EXIT_DATA;
10720 if (if_modifier != OMP_TARGET)
10721 {
10722 n = 3;
10723 c_parser_consume_token (parser);
10724 }
10725 else
10726 {
10727 location_t loc = c_parser_peek_2nd_token (parser)->location;
10728 error_at (loc, "expected %<data%>, %<update%>, %<enter%> "
10729 "or %<exit%>");
10730 if_modifier = ERROR_MARK;
10731 }
10732 if (if_modifier == OMP_TARGET_ENTER_DATA
10733 || if_modifier == OMP_TARGET_EXIT_DATA)
10734 {
10735 if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
10736 {
10737 p = IDENTIFIER_POINTER
10738 (c_parser_peek_2nd_token (parser)->value);
10739 if (strcmp ("data", p) == 0)
10740 n = 4;
10741 }
10742 if (n == 4)
10743 c_parser_consume_token (parser);
10744 else
10745 {
10746 location_t loc
10747 = c_parser_peek_2nd_token (parser)->location;
10748 error_at (loc, "expected %<data%>");
10749 if_modifier = ERROR_MARK;
10750 }
10751 }
10752 }
10753 }
10754 if (if_modifier != ERROR_MARK)
10755 {
10756 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
10757 {
10758 c_parser_consume_token (parser);
10759 c_parser_consume_token (parser);
10760 }
10761 else
10762 {
10763 if (n > 2)
10764 {
10765 location_t loc = c_parser_peek_2nd_token (parser)->location;
10766 error_at (loc, "expected %<:%>");
10767 }
10768 if_modifier = ERROR_MARK;
10769 }
10770 }
10771 }
10772
10773 tree t = c_parser_condition (parser), c;
10774 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10775
10776 for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
10777 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF)
10778 {
10779 if (if_modifier != ERROR_MARK
10780 && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
10781 {
10782 const char *p = NULL;
10783 switch (if_modifier)
10784 {
10785 case OMP_PARALLEL: p = "parallel"; break;
10786 case OMP_TASK: p = "task"; break;
10787 case OMP_TASKLOOP: p = "taskloop"; break;
10788 case OMP_TARGET_DATA: p = "target data"; break;
10789 case OMP_TARGET: p = "target"; break;
10790 case OMP_TARGET_UPDATE: p = "target update"; break;
10791 case OMP_TARGET_ENTER_DATA: p = "enter data"; break;
10792 case OMP_TARGET_EXIT_DATA: p = "exit data"; break;
10793 default: gcc_unreachable ();
10794 }
10795 error_at (location, "too many %<if%> clauses with %qs modifier",
10796 p);
10797 return list;
10798 }
10799 else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
10800 {
10801 if (!is_omp)
10802 error_at (location, "too many %<if%> clauses");
10803 else
10804 error_at (location, "too many %<if%> clauses without modifier");
10805 return list;
10806 }
10807 else if (if_modifier == ERROR_MARK
10808 || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK)
10809 {
10810 error_at (location, "if any %<if%> clause has modifier, then all "
10811 "%<if%> clauses have to use modifier");
10812 return list;
10813 }
10814 }
10815
10816 c = build_omp_clause (location, OMP_CLAUSE_IF);
10817 OMP_CLAUSE_IF_MODIFIER (c) = if_modifier;
10818 OMP_CLAUSE_IF_EXPR (c) = t;
10819 OMP_CLAUSE_CHAIN (c) = list;
10820 return c;
10821 }
10822
10823 /* OpenMP 2.5:
10824 lastprivate ( variable-list ) */
10825
10826 static tree
10827 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
10828 {
10829 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
10830 }
10831
10832 /* OpenMP 3.1:
10833 mergeable */
10834
10835 static tree
10836 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10837 {
10838 tree c;
10839
10840 /* FIXME: Should we allow duplicates? */
10841 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
10842
10843 c = build_omp_clause (c_parser_peek_token (parser)->location,
10844 OMP_CLAUSE_MERGEABLE);
10845 OMP_CLAUSE_CHAIN (c) = list;
10846
10847 return c;
10848 }
10849
10850 /* OpenMP 2.5:
10851 nowait */
10852
10853 static tree
10854 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10855 {
10856 tree c;
10857 location_t loc = c_parser_peek_token (parser)->location;
10858
10859 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
10860
10861 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
10862 OMP_CLAUSE_CHAIN (c) = list;
10863 return c;
10864 }
10865
10866 /* OpenACC:
10867 num_gangs ( expression ) */
10868
10869 static tree
10870 c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
10871 {
10872 location_t num_gangs_loc = c_parser_peek_token (parser)->location;
10873 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10874 {
10875 location_t expr_loc = c_parser_peek_token (parser)->location;
10876 tree c, t = c_parser_expression (parser).value;
10877 mark_exp_read (t);
10878 t = c_fully_fold (t, false, NULL);
10879
10880 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10881
10882 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10883 {
10884 c_parser_error (parser, "expected integer expression");
10885 return list;
10886 }
10887
10888 /* Attempt to statically determine when the number isn't positive. */
10889 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10890 build_int_cst (TREE_TYPE (t), 0));
10891 protected_set_expr_location (c, expr_loc);
10892 if (c == boolean_true_node)
10893 {
10894 warning_at (expr_loc, 0,
10895 "%<num_gangs%> value must be positive");
10896 t = integer_one_node;
10897 }
10898
10899 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
10900
10901 c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
10902 OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
10903 OMP_CLAUSE_CHAIN (c) = list;
10904 list = c;
10905 }
10906
10907 return list;
10908 }
10909
10910 /* OpenMP 2.5:
10911 num_threads ( expression ) */
10912
10913 static tree
10914 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
10915 {
10916 location_t num_threads_loc = c_parser_peek_token (parser)->location;
10917 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10918 {
10919 location_t expr_loc = c_parser_peek_token (parser)->location;
10920 tree c, t = c_parser_expression (parser).value;
10921 mark_exp_read (t);
10922 t = c_fully_fold (t, false, NULL);
10923
10924 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10925
10926 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10927 {
10928 c_parser_error (parser, "expected integer expression");
10929 return list;
10930 }
10931
10932 /* Attempt to statically determine when the number isn't positive. */
10933 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10934 build_int_cst (TREE_TYPE (t), 0));
10935 protected_set_expr_location (c, expr_loc);
10936 if (c == boolean_true_node)
10937 {
10938 warning_at (expr_loc, 0,
10939 "%<num_threads%> value must be positive");
10940 t = integer_one_node;
10941 }
10942
10943 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
10944
10945 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
10946 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
10947 OMP_CLAUSE_CHAIN (c) = list;
10948 list = c;
10949 }
10950
10951 return list;
10952 }
10953
10954 /* OpenMP 4.5:
10955 num_tasks ( expression ) */
10956
10957 static tree
10958 c_parser_omp_clause_num_tasks (c_parser *parser, tree list)
10959 {
10960 location_t num_tasks_loc = c_parser_peek_token (parser)->location;
10961 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10962 {
10963 location_t expr_loc = c_parser_peek_token (parser)->location;
10964 tree c, t = c_parser_expression (parser).value;
10965 mark_exp_read (t);
10966 t = c_fully_fold (t, false, NULL);
10967
10968 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10969
10970 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10971 {
10972 c_parser_error (parser, "expected integer expression");
10973 return list;
10974 }
10975
10976 /* Attempt to statically determine when the number isn't positive. */
10977 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10978 build_int_cst (TREE_TYPE (t), 0));
10979 if (CAN_HAVE_LOCATION_P (c))
10980 SET_EXPR_LOCATION (c, expr_loc);
10981 if (c == boolean_true_node)
10982 {
10983 warning_at (expr_loc, 0, "%<num_tasks%> value must be positive");
10984 t = integer_one_node;
10985 }
10986
10987 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks");
10988
10989 c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS);
10990 OMP_CLAUSE_NUM_TASKS_EXPR (c) = t;
10991 OMP_CLAUSE_CHAIN (c) = list;
10992 list = c;
10993 }
10994
10995 return list;
10996 }
10997
10998 /* OpenMP 4.5:
10999 grainsize ( expression ) */
11000
11001 static tree
11002 c_parser_omp_clause_grainsize (c_parser *parser, tree list)
11003 {
11004 location_t grainsize_loc = c_parser_peek_token (parser)->location;
11005 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11006 {
11007 location_t expr_loc = c_parser_peek_token (parser)->location;
11008 tree c, t = c_parser_expression (parser).value;
11009 mark_exp_read (t);
11010 t = c_fully_fold (t, false, NULL);
11011
11012 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11013
11014 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11015 {
11016 c_parser_error (parser, "expected integer expression");
11017 return list;
11018 }
11019
11020 /* Attempt to statically determine when the number isn't positive. */
11021 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11022 build_int_cst (TREE_TYPE (t), 0));
11023 if (CAN_HAVE_LOCATION_P (c))
11024 SET_EXPR_LOCATION (c, expr_loc);
11025 if (c == boolean_true_node)
11026 {
11027 warning_at (expr_loc, 0, "%<grainsize%> value must be positive");
11028 t = integer_one_node;
11029 }
11030
11031 check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize");
11032
11033 c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE);
11034 OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
11035 OMP_CLAUSE_CHAIN (c) = list;
11036 list = c;
11037 }
11038
11039 return list;
11040 }
11041
11042 /* OpenMP 4.5:
11043 priority ( expression ) */
11044
11045 static tree
11046 c_parser_omp_clause_priority (c_parser *parser, tree list)
11047 {
11048 location_t priority_loc = c_parser_peek_token (parser)->location;
11049 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11050 {
11051 location_t expr_loc = c_parser_peek_token (parser)->location;
11052 tree c, t = c_parser_expression (parser).value;
11053 mark_exp_read (t);
11054 t = c_fully_fold (t, false, NULL);
11055
11056 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11057
11058 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11059 {
11060 c_parser_error (parser, "expected integer expression");
11061 return list;
11062 }
11063
11064 /* Attempt to statically determine when the number isn't
11065 non-negative. */
11066 c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t,
11067 build_int_cst (TREE_TYPE (t), 0));
11068 if (CAN_HAVE_LOCATION_P (c))
11069 SET_EXPR_LOCATION (c, expr_loc);
11070 if (c == boolean_true_node)
11071 {
11072 warning_at (expr_loc, 0, "%<priority%> value must be non-negative");
11073 t = integer_one_node;
11074 }
11075
11076 check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority");
11077
11078 c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY);
11079 OMP_CLAUSE_PRIORITY_EXPR (c) = t;
11080 OMP_CLAUSE_CHAIN (c) = list;
11081 list = c;
11082 }
11083
11084 return list;
11085 }
11086
11087 /* OpenMP 4.5:
11088 hint ( expression ) */
11089
11090 static tree
11091 c_parser_omp_clause_hint (c_parser *parser, tree list)
11092 {
11093 location_t hint_loc = c_parser_peek_token (parser)->location;
11094 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11095 {
11096 tree c, t = c_parser_expression (parser).value;
11097 mark_exp_read (t);
11098 t = c_fully_fold (t, false, NULL);
11099
11100 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11101
11102 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11103 {
11104 c_parser_error (parser, "expected integer expression");
11105 return list;
11106 }
11107
11108 check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint");
11109
11110 c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT);
11111 OMP_CLAUSE_HINT_EXPR (c) = t;
11112 OMP_CLAUSE_CHAIN (c) = list;
11113 list = c;
11114 }
11115
11116 return list;
11117 }
11118
11119 /* OpenMP 4.5:
11120 defaultmap ( tofrom : scalar ) */
11121
11122 static tree
11123 c_parser_omp_clause_defaultmap (c_parser *parser, tree list)
11124 {
11125 location_t loc = c_parser_peek_token (parser)->location;
11126 tree c;
11127 const char *p;
11128
11129 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11130 return list;
11131 if (!c_parser_next_token_is (parser, CPP_NAME))
11132 {
11133 c_parser_error (parser, "expected %<tofrom%>");
11134 goto out_err;
11135 }
11136 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11137 if (strcmp (p, "tofrom") != 0)
11138 {
11139 c_parser_error (parser, "expected %<tofrom%>");
11140 goto out_err;
11141 }
11142 c_parser_consume_token (parser);
11143 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11144 goto out_err;
11145 if (!c_parser_next_token_is (parser, CPP_NAME))
11146 {
11147 c_parser_error (parser, "expected %<scalar%>");
11148 goto out_err;
11149 }
11150 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11151 if (strcmp (p, "scalar") != 0)
11152 {
11153 c_parser_error (parser, "expected %<scalar%>");
11154 goto out_err;
11155 }
11156 c_parser_consume_token (parser);
11157 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11158 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap");
11159 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP);
11160 OMP_CLAUSE_CHAIN (c) = list;
11161 return c;
11162
11163 out_err:
11164 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11165 return list;
11166 }
11167
11168 /* OpenMP 4.5:
11169 use_device_ptr ( variable-list ) */
11170
11171 static tree
11172 c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list)
11173 {
11174 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR,
11175 list);
11176 }
11177
11178 /* OpenMP 4.5:
11179 is_device_ptr ( variable-list ) */
11180
11181 static tree
11182 c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list)
11183 {
11184 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list);
11185 }
11186
11187 /* OpenACC:
11188 num_workers ( expression ) */
11189
11190 static tree
11191 c_parser_omp_clause_num_workers (c_parser *parser, tree list)
11192 {
11193 location_t num_workers_loc = c_parser_peek_token (parser)->location;
11194 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11195 {
11196 location_t expr_loc = c_parser_peek_token (parser)->location;
11197 tree c, t = c_parser_expression (parser).value;
11198 mark_exp_read (t);
11199 t = c_fully_fold (t, false, NULL);
11200
11201 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11202
11203 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11204 {
11205 c_parser_error (parser, "expected integer expression");
11206 return list;
11207 }
11208
11209 /* Attempt to statically determine when the number isn't positive. */
11210 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11211 build_int_cst (TREE_TYPE (t), 0));
11212 protected_set_expr_location (c, expr_loc);
11213 if (c == boolean_true_node)
11214 {
11215 warning_at (expr_loc, 0,
11216 "%<num_workers%> value must be positive");
11217 t = integer_one_node;
11218 }
11219
11220 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
11221
11222 c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
11223 OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
11224 OMP_CLAUSE_CHAIN (c) = list;
11225 list = c;
11226 }
11227
11228 return list;
11229 }
11230
11231 /* OpenACC:
11232
11233 gang [( gang-arg-list )]
11234 worker [( [num:] int-expr )]
11235 vector [( [length:] int-expr )]
11236
11237 where gang-arg is one of:
11238
11239 [num:] int-expr
11240 static: size-expr
11241
11242 and size-expr may be:
11243
11244 *
11245 int-expr
11246 */
11247
11248 static tree
11249 c_parser_oacc_shape_clause (c_parser *parser, omp_clause_code kind,
11250 const char *str, tree list)
11251 {
11252 const char *id = "num";
11253 tree ops[2] = { NULL_TREE, NULL_TREE }, c;
11254 location_t loc = c_parser_peek_token (parser)->location;
11255
11256 if (kind == OMP_CLAUSE_VECTOR)
11257 id = "length";
11258
11259 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11260 {
11261 c_parser_consume_token (parser);
11262
11263 do
11264 {
11265 c_token *next = c_parser_peek_token (parser);
11266 int idx = 0;
11267
11268 /* Gang static argument. */
11269 if (kind == OMP_CLAUSE_GANG
11270 && c_parser_next_token_is_keyword (parser, RID_STATIC))
11271 {
11272 c_parser_consume_token (parser);
11273
11274 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11275 goto cleanup_error;
11276
11277 idx = 1;
11278 if (ops[idx] != NULL_TREE)
11279 {
11280 c_parser_error (parser, "too many %<static%> arguments");
11281 goto cleanup_error;
11282 }
11283
11284 /* Check for the '*' argument. */
11285 if (c_parser_next_token_is (parser, CPP_MULT)
11286 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
11287 || c_parser_peek_2nd_token (parser)->type
11288 == CPP_CLOSE_PAREN))
11289 {
11290 c_parser_consume_token (parser);
11291 ops[idx] = integer_minus_one_node;
11292
11293 if (c_parser_next_token_is (parser, CPP_COMMA))
11294 {
11295 c_parser_consume_token (parser);
11296 continue;
11297 }
11298 else
11299 break;
11300 }
11301 }
11302 /* Worker num: argument and vector length: arguments. */
11303 else if (c_parser_next_token_is (parser, CPP_NAME)
11304 && strcmp (id, IDENTIFIER_POINTER (next->value)) == 0
11305 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11306 {
11307 c_parser_consume_token (parser); /* id */
11308 c_parser_consume_token (parser); /* ':' */
11309 }
11310
11311 /* Now collect the actual argument. */
11312 if (ops[idx] != NULL_TREE)
11313 {
11314 c_parser_error (parser, "unexpected argument");
11315 goto cleanup_error;
11316 }
11317
11318 location_t expr_loc = c_parser_peek_token (parser)->location;
11319 tree expr = c_parser_expr_no_commas (parser, NULL).value;
11320 if (expr == error_mark_node)
11321 goto cleanup_error;
11322
11323 mark_exp_read (expr);
11324 expr = c_fully_fold (expr, false, NULL);
11325
11326 /* Attempt to statically determine when the number isn't a
11327 positive integer. */
11328
11329 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)))
11330 {
11331 c_parser_error (parser, "expected integer expression");
11332 return list;
11333 }
11334
11335 tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr,
11336 build_int_cst (TREE_TYPE (expr), 0));
11337 if (c == boolean_true_node)
11338 {
11339 warning_at (loc, 0,
11340 "%<%s%> value must be positive", str);
11341 expr = integer_one_node;
11342 }
11343
11344 ops[idx] = expr;
11345
11346 if (kind == OMP_CLAUSE_GANG
11347 && c_parser_next_token_is (parser, CPP_COMMA))
11348 {
11349 c_parser_consume_token (parser);
11350 continue;
11351 }
11352 break;
11353 }
11354 while (1);
11355
11356 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
11357 goto cleanup_error;
11358 }
11359
11360 check_no_duplicate_clause (list, kind, str);
11361
11362 c = build_omp_clause (loc, kind);
11363
11364 if (ops[1])
11365 OMP_CLAUSE_OPERAND (c, 1) = ops[1];
11366
11367 OMP_CLAUSE_OPERAND (c, 0) = ops[0];
11368 OMP_CLAUSE_CHAIN (c) = list;
11369
11370 return c;
11371
11372 cleanup_error:
11373 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
11374 return list;
11375 }
11376
11377 /* OpenACC:
11378 auto
11379 independent
11380 nohost
11381 seq */
11382
11383 static tree
11384 c_parser_oacc_simple_clause (c_parser *parser, enum omp_clause_code code,
11385 tree list)
11386 {
11387 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11388
11389 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11390 OMP_CLAUSE_CHAIN (c) = list;
11391
11392 return c;
11393 }
11394
11395 /* OpenACC:
11396 async [( int-expr )] */
11397
11398 static tree
11399 c_parser_oacc_clause_async (c_parser *parser, tree list)
11400 {
11401 tree c, t;
11402 location_t loc = c_parser_peek_token (parser)->location;
11403
11404 t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
11405
11406 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
11407 {
11408 c_parser_consume_token (parser);
11409
11410 t = c_parser_expression (parser).value;
11411 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11412 c_parser_error (parser, "expected integer expression");
11413 else if (t == error_mark_node
11414 || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
11415 return list;
11416 }
11417 else
11418 t = c_fully_fold (t, false, NULL);
11419
11420 check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
11421
11422 c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
11423 OMP_CLAUSE_ASYNC_EXPR (c) = t;
11424 OMP_CLAUSE_CHAIN (c) = list;
11425 list = c;
11426
11427 return list;
11428 }
11429
11430 /* OpenACC 2.0:
11431 tile ( size-expr-list ) */
11432
11433 static tree
11434 c_parser_oacc_clause_tile (c_parser *parser, tree list)
11435 {
11436 tree c, expr = error_mark_node;
11437 location_t loc, expr_loc;
11438 tree tile = NULL_TREE;
11439
11440 check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
11441
11442 loc = c_parser_peek_token (parser)->location;
11443 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11444 return list;
11445
11446 do
11447 {
11448 if (c_parser_next_token_is (parser, CPP_MULT)
11449 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
11450 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
11451 {
11452 c_parser_consume_token (parser);
11453 expr = integer_minus_one_node;
11454 }
11455 else
11456 {
11457 expr_loc = c_parser_peek_token (parser)->location;
11458 expr = c_parser_expr_no_commas (parser, NULL).value;
11459
11460 if (expr == error_mark_node)
11461 {
11462 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11463 "expected %<)%>");
11464 return list;
11465 }
11466
11467 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)))
11468 {
11469 c_parser_error (parser, "%<tile%> value must be integral");
11470 return list;
11471 }
11472
11473 mark_exp_read (expr);
11474 expr = c_fully_fold (expr, false, NULL);
11475
11476 /* Attempt to statically determine when expr isn't positive. */
11477 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr,
11478 build_int_cst (TREE_TYPE (expr), 0));
11479 protected_set_expr_location (c, expr_loc);
11480 if (c == boolean_true_node)
11481 {
11482 warning_at (expr_loc, 0,"%<tile%> value must be positive");
11483 expr = integer_one_node;
11484 }
11485 }
11486
11487 tile = tree_cons (NULL_TREE, expr, tile);
11488 if (c_parser_next_token_is (parser, CPP_COMMA))
11489 c_parser_consume_token (parser);
11490 }
11491 while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN));
11492
11493 /* Consume the trailing ')'. */
11494 c_parser_consume_token (parser);
11495
11496 c = build_omp_clause (loc, OMP_CLAUSE_TILE);
11497 tile = nreverse (tile);
11498 OMP_CLAUSE_TILE_LIST (c) = tile;
11499 OMP_CLAUSE_CHAIN (c) = list;
11500 return c;
11501 }
11502
11503 /* OpenACC:
11504 wait ( int-expr-list ) */
11505
11506 static tree
11507 c_parser_oacc_clause_wait (c_parser *parser, tree list)
11508 {
11509 location_t clause_loc = c_parser_peek_token (parser)->location;
11510
11511 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
11512 list = c_parser_oacc_wait_list (parser, clause_loc, list);
11513
11514 return list;
11515 }
11516
11517 /* OpenMP 2.5:
11518 ordered
11519
11520 OpenMP 4.5:
11521 ordered ( constant-expression ) */
11522
11523 static tree
11524 c_parser_omp_clause_ordered (c_parser *parser, tree list)
11525 {
11526 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
11527
11528 tree c, num = NULL_TREE;
11529 HOST_WIDE_INT n;
11530 location_t loc = c_parser_peek_token (parser)->location;
11531 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11532 {
11533 c_parser_consume_token (parser);
11534 num = c_parser_expr_no_commas (parser, NULL).value;
11535 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11536 }
11537 if (num == error_mark_node)
11538 return list;
11539 if (num)
11540 {
11541 mark_exp_read (num);
11542 num = c_fully_fold (num, false, NULL);
11543 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
11544 || !tree_fits_shwi_p (num)
11545 || (n = tree_to_shwi (num)) <= 0
11546 || (int) n != n)
11547 {
11548 error_at (loc, "ordered argument needs positive "
11549 "constant integer expression");
11550 return list;
11551 }
11552 }
11553 c = build_omp_clause (loc, OMP_CLAUSE_ORDERED);
11554 OMP_CLAUSE_ORDERED_EXPR (c) = num;
11555 OMP_CLAUSE_CHAIN (c) = list;
11556 return c;
11557 }
11558
11559 /* OpenMP 2.5:
11560 private ( variable-list ) */
11561
11562 static tree
11563 c_parser_omp_clause_private (c_parser *parser, tree list)
11564 {
11565 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
11566 }
11567
11568 /* OpenMP 2.5:
11569 reduction ( reduction-operator : variable-list )
11570
11571 reduction-operator:
11572 One of: + * - & ^ | && ||
11573
11574 OpenMP 3.1:
11575
11576 reduction-operator:
11577 One of: + * - & ^ | && || max min
11578
11579 OpenMP 4.0:
11580
11581 reduction-operator:
11582 One of: + * - & ^ | && ||
11583 identifier */
11584
11585 static tree
11586 c_parser_omp_clause_reduction (c_parser *parser, tree list)
11587 {
11588 location_t clause_loc = c_parser_peek_token (parser)->location;
11589 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11590 {
11591 enum tree_code code = ERROR_MARK;
11592 tree reduc_id = NULL_TREE;
11593
11594 switch (c_parser_peek_token (parser)->type)
11595 {
11596 case CPP_PLUS:
11597 code = PLUS_EXPR;
11598 break;
11599 case CPP_MULT:
11600 code = MULT_EXPR;
11601 break;
11602 case CPP_MINUS:
11603 code = MINUS_EXPR;
11604 break;
11605 case CPP_AND:
11606 code = BIT_AND_EXPR;
11607 break;
11608 case CPP_XOR:
11609 code = BIT_XOR_EXPR;
11610 break;
11611 case CPP_OR:
11612 code = BIT_IOR_EXPR;
11613 break;
11614 case CPP_AND_AND:
11615 code = TRUTH_ANDIF_EXPR;
11616 break;
11617 case CPP_OR_OR:
11618 code = TRUTH_ORIF_EXPR;
11619 break;
11620 case CPP_NAME:
11621 {
11622 const char *p
11623 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11624 if (strcmp (p, "min") == 0)
11625 {
11626 code = MIN_EXPR;
11627 break;
11628 }
11629 if (strcmp (p, "max") == 0)
11630 {
11631 code = MAX_EXPR;
11632 break;
11633 }
11634 reduc_id = c_parser_peek_token (parser)->value;
11635 break;
11636 }
11637 default:
11638 c_parser_error (parser,
11639 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
11640 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
11641 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
11642 return list;
11643 }
11644 c_parser_consume_token (parser);
11645 reduc_id = c_omp_reduction_id (code, reduc_id);
11646 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11647 {
11648 tree nl, c;
11649
11650 nl = c_parser_omp_variable_list (parser, clause_loc,
11651 OMP_CLAUSE_REDUCTION, list);
11652 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11653 {
11654 tree d = OMP_CLAUSE_DECL (c), type;
11655 if (TREE_CODE (d) != TREE_LIST)
11656 type = TREE_TYPE (d);
11657 else
11658 {
11659 int cnt = 0;
11660 tree t;
11661 for (t = d; TREE_CODE (t) == TREE_LIST; t = TREE_CHAIN (t))
11662 cnt++;
11663 type = TREE_TYPE (t);
11664 while (cnt > 0)
11665 {
11666 if (TREE_CODE (type) != POINTER_TYPE
11667 && TREE_CODE (type) != ARRAY_TYPE)
11668 break;
11669 type = TREE_TYPE (type);
11670 cnt--;
11671 }
11672 }
11673 while (TREE_CODE (type) == ARRAY_TYPE)
11674 type = TREE_TYPE (type);
11675 OMP_CLAUSE_REDUCTION_CODE (c) = code;
11676 if (code == ERROR_MARK
11677 || !(INTEGRAL_TYPE_P (type)
11678 || TREE_CODE (type) == REAL_TYPE
11679 || TREE_CODE (type) == COMPLEX_TYPE))
11680 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
11681 = c_omp_reduction_lookup (reduc_id,
11682 TYPE_MAIN_VARIANT (type));
11683 }
11684
11685 list = nl;
11686 }
11687 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11688 }
11689 return list;
11690 }
11691
11692 /* OpenMP 2.5:
11693 schedule ( schedule-kind )
11694 schedule ( schedule-kind , expression )
11695
11696 schedule-kind:
11697 static | dynamic | guided | runtime | auto
11698
11699 OpenMP 4.5:
11700 schedule ( schedule-modifier : schedule-kind )
11701 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
11702
11703 schedule-modifier:
11704 simd
11705 monotonic
11706 nonmonotonic */
11707
11708 static tree
11709 c_parser_omp_clause_schedule (c_parser *parser, tree list)
11710 {
11711 tree c, t;
11712 location_t loc = c_parser_peek_token (parser)->location;
11713 int modifiers = 0, nmodifiers = 0;
11714
11715 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11716 return list;
11717
11718 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
11719
11720 while (c_parser_next_token_is (parser, CPP_NAME))
11721 {
11722 tree kind = c_parser_peek_token (parser)->value;
11723 const char *p = IDENTIFIER_POINTER (kind);
11724 if (strcmp ("simd", p) == 0)
11725 OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
11726 else if (strcmp ("monotonic", p) == 0)
11727 modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC;
11728 else if (strcmp ("nonmonotonic", p) == 0)
11729 modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC;
11730 else
11731 break;
11732 c_parser_consume_token (parser);
11733 if (nmodifiers++ == 0
11734 && c_parser_next_token_is (parser, CPP_COMMA))
11735 c_parser_consume_token (parser);
11736 else
11737 {
11738 c_parser_require (parser, CPP_COLON, "expected %<:%>");
11739 break;
11740 }
11741 }
11742
11743 if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC
11744 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
11745 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
11746 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
11747 {
11748 error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers "
11749 "specified");
11750 modifiers = 0;
11751 }
11752
11753 if (c_parser_next_token_is (parser, CPP_NAME))
11754 {
11755 tree kind = c_parser_peek_token (parser)->value;
11756 const char *p = IDENTIFIER_POINTER (kind);
11757
11758 switch (p[0])
11759 {
11760 case 'd':
11761 if (strcmp ("dynamic", p) != 0)
11762 goto invalid_kind;
11763 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
11764 break;
11765
11766 case 'g':
11767 if (strcmp ("guided", p) != 0)
11768 goto invalid_kind;
11769 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
11770 break;
11771
11772 case 'r':
11773 if (strcmp ("runtime", p) != 0)
11774 goto invalid_kind;
11775 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
11776 break;
11777
11778 default:
11779 goto invalid_kind;
11780 }
11781 }
11782 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
11783 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
11784 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
11785 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
11786 else
11787 goto invalid_kind;
11788
11789 c_parser_consume_token (parser);
11790 if (c_parser_next_token_is (parser, CPP_COMMA))
11791 {
11792 location_t here;
11793 c_parser_consume_token (parser);
11794
11795 here = c_parser_peek_token (parser)->location;
11796 t = c_parser_expr_no_commas (parser, NULL).value;
11797 mark_exp_read (t);
11798 t = c_fully_fold (t, false, NULL);
11799
11800 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
11801 error_at (here, "schedule %<runtime%> does not take "
11802 "a %<chunk_size%> parameter");
11803 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
11804 error_at (here,
11805 "schedule %<auto%> does not take "
11806 "a %<chunk_size%> parameter");
11807 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
11808 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
11809 else
11810 c_parser_error (parser, "expected integer expression");
11811
11812 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11813 }
11814 else
11815 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11816 "expected %<,%> or %<)%>");
11817
11818 OMP_CLAUSE_SCHEDULE_KIND (c)
11819 = (enum omp_clause_schedule_kind)
11820 (OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers);
11821
11822 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
11823 OMP_CLAUSE_CHAIN (c) = list;
11824 return c;
11825
11826 invalid_kind:
11827 c_parser_error (parser, "invalid schedule kind");
11828 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
11829 return list;
11830 }
11831
11832 /* OpenMP 2.5:
11833 shared ( variable-list ) */
11834
11835 static tree
11836 c_parser_omp_clause_shared (c_parser *parser, tree list)
11837 {
11838 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
11839 }
11840
11841 /* OpenMP 3.0:
11842 untied */
11843
11844 static tree
11845 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
11846 {
11847 tree c;
11848
11849 /* FIXME: Should we allow duplicates? */
11850 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
11851
11852 c = build_omp_clause (c_parser_peek_token (parser)->location,
11853 OMP_CLAUSE_UNTIED);
11854 OMP_CLAUSE_CHAIN (c) = list;
11855
11856 return c;
11857 }
11858
11859 /* OpenACC:
11860 vector_length ( expression ) */
11861
11862 static tree
11863 c_parser_omp_clause_vector_length (c_parser *parser, tree list)
11864 {
11865 location_t vector_length_loc = c_parser_peek_token (parser)->location;
11866 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11867 {
11868 location_t expr_loc = c_parser_peek_token (parser)->location;
11869 tree c, t = c_parser_expression (parser).value;
11870 mark_exp_read (t);
11871 t = c_fully_fold (t, false, NULL);
11872
11873 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11874
11875 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11876 {
11877 c_parser_error (parser, "expected integer expression");
11878 return list;
11879 }
11880
11881 /* Attempt to statically determine when the number isn't positive. */
11882 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11883 build_int_cst (TREE_TYPE (t), 0));
11884 protected_set_expr_location (c, expr_loc);
11885 if (c == boolean_true_node)
11886 {
11887 warning_at (expr_loc, 0,
11888 "%<vector_length%> value must be positive");
11889 t = integer_one_node;
11890 }
11891
11892 check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
11893
11894 c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
11895 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
11896 OMP_CLAUSE_CHAIN (c) = list;
11897 list = c;
11898 }
11899
11900 return list;
11901 }
11902
11903 /* OpenMP 4.0:
11904 inbranch
11905 notinbranch */
11906
11907 static tree
11908 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
11909 enum omp_clause_code code, tree list)
11910 {
11911 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11912
11913 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11914 OMP_CLAUSE_CHAIN (c) = list;
11915
11916 return c;
11917 }
11918
11919 /* OpenMP 4.0:
11920 parallel
11921 for
11922 sections
11923 taskgroup */
11924
11925 static tree
11926 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
11927 enum omp_clause_code code, tree list)
11928 {
11929 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11930 OMP_CLAUSE_CHAIN (c) = list;
11931
11932 return c;
11933 }
11934
11935 /* OpenMP 4.5:
11936 nogroup */
11937
11938 static tree
11939 c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list)
11940 {
11941 check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup");
11942 tree c = build_omp_clause (c_parser_peek_token (parser)->location,
11943 OMP_CLAUSE_NOGROUP);
11944 OMP_CLAUSE_CHAIN (c) = list;
11945 return c;
11946 }
11947
11948 /* OpenMP 4.5:
11949 simd
11950 threads */
11951
11952 static tree
11953 c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED,
11954 enum omp_clause_code code, tree list)
11955 {
11956 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11957 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11958 OMP_CLAUSE_CHAIN (c) = list;
11959 return c;
11960 }
11961
11962 /* OpenMP 4.0:
11963 num_teams ( expression ) */
11964
11965 static tree
11966 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
11967 {
11968 location_t num_teams_loc = c_parser_peek_token (parser)->location;
11969 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11970 {
11971 location_t expr_loc = c_parser_peek_token (parser)->location;
11972 tree c, t = c_parser_expression (parser).value;
11973 mark_exp_read (t);
11974 t = c_fully_fold (t, false, NULL);
11975
11976 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11977
11978 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11979 {
11980 c_parser_error (parser, "expected integer expression");
11981 return list;
11982 }
11983
11984 /* Attempt to statically determine when the number isn't positive. */
11985 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11986 build_int_cst (TREE_TYPE (t), 0));
11987 protected_set_expr_location (c, expr_loc);
11988 if (c == boolean_true_node)
11989 {
11990 warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
11991 t = integer_one_node;
11992 }
11993
11994 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
11995
11996 c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
11997 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
11998 OMP_CLAUSE_CHAIN (c) = list;
11999 list = c;
12000 }
12001
12002 return list;
12003 }
12004
12005 /* OpenMP 4.0:
12006 thread_limit ( expression ) */
12007
12008 static tree
12009 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
12010 {
12011 location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
12012 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12013 {
12014 location_t expr_loc = c_parser_peek_token (parser)->location;
12015 tree c, t = c_parser_expression (parser).value;
12016 mark_exp_read (t);
12017 t = c_fully_fold (t, false, NULL);
12018
12019 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12020
12021 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12022 {
12023 c_parser_error (parser, "expected integer expression");
12024 return list;
12025 }
12026
12027 /* Attempt to statically determine when the number isn't positive. */
12028 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12029 build_int_cst (TREE_TYPE (t), 0));
12030 protected_set_expr_location (c, expr_loc);
12031 if (c == boolean_true_node)
12032 {
12033 warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
12034 t = integer_one_node;
12035 }
12036
12037 check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
12038 "thread_limit");
12039
12040 c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
12041 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
12042 OMP_CLAUSE_CHAIN (c) = list;
12043 list = c;
12044 }
12045
12046 return list;
12047 }
12048
12049 /* OpenMP 4.0:
12050 aligned ( variable-list )
12051 aligned ( variable-list : constant-expression ) */
12052
12053 static tree
12054 c_parser_omp_clause_aligned (c_parser *parser, tree list)
12055 {
12056 location_t clause_loc = c_parser_peek_token (parser)->location;
12057 tree nl, c;
12058
12059 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12060 return list;
12061
12062 nl = c_parser_omp_variable_list (parser, clause_loc,
12063 OMP_CLAUSE_ALIGNED, list);
12064
12065 if (c_parser_next_token_is (parser, CPP_COLON))
12066 {
12067 c_parser_consume_token (parser);
12068 tree alignment = c_parser_expr_no_commas (parser, NULL).value;
12069 mark_exp_read (alignment);
12070 alignment = c_fully_fold (alignment, false, NULL);
12071 if (TREE_CODE (alignment) != INTEGER_CST
12072 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
12073 || tree_int_cst_sgn (alignment) != 1)
12074 {
12075 error_at (clause_loc, "%<aligned%> clause alignment expression must "
12076 "be positive constant integer expression");
12077 alignment = NULL_TREE;
12078 }
12079
12080 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12081 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
12082 }
12083
12084 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12085 return nl;
12086 }
12087
12088 /* OpenMP 4.0:
12089 linear ( variable-list )
12090 linear ( variable-list : expression )
12091
12092 OpenMP 4.5:
12093 linear ( modifier ( variable-list ) )
12094 linear ( modifier ( variable-list ) : expression ) */
12095
12096 static tree
12097 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn)
12098 {
12099 location_t clause_loc = c_parser_peek_token (parser)->location;
12100 tree nl, c, step;
12101 enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT;
12102
12103 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12104 return list;
12105
12106 if (!is_cilk_simd_fn
12107 && c_parser_next_token_is (parser, CPP_NAME))
12108 {
12109 c_token *tok = c_parser_peek_token (parser);
12110 const char *p = IDENTIFIER_POINTER (tok->value);
12111 if (strcmp ("val", p) == 0)
12112 kind = OMP_CLAUSE_LINEAR_VAL;
12113 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN)
12114 kind = OMP_CLAUSE_LINEAR_DEFAULT;
12115 if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
12116 {
12117 c_parser_consume_token (parser);
12118 c_parser_consume_token (parser);
12119 }
12120 }
12121
12122 nl = c_parser_omp_variable_list (parser, clause_loc,
12123 OMP_CLAUSE_LINEAR, list);
12124
12125 if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
12126 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12127
12128 if (c_parser_next_token_is (parser, CPP_COLON))
12129 {
12130 c_parser_consume_token (parser);
12131 step = c_parser_expression (parser).value;
12132 mark_exp_read (step);
12133 step = c_fully_fold (step, false, NULL);
12134 if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL)
12135 {
12136 sorry ("using parameters for %<linear%> step is not supported yet");
12137 step = integer_one_node;
12138 }
12139 if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
12140 {
12141 error_at (clause_loc, "%<linear%> clause step expression must "
12142 "be integral");
12143 step = integer_one_node;
12144 }
12145
12146 }
12147 else
12148 step = integer_one_node;
12149
12150 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12151 {
12152 OMP_CLAUSE_LINEAR_STEP (c) = step;
12153 OMP_CLAUSE_LINEAR_KIND (c) = kind;
12154 }
12155
12156 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12157 return nl;
12158 }
12159
12160 /* OpenMP 4.0:
12161 safelen ( constant-expression ) */
12162
12163 static tree
12164 c_parser_omp_clause_safelen (c_parser *parser, tree list)
12165 {
12166 location_t clause_loc = c_parser_peek_token (parser)->location;
12167 tree c, t;
12168
12169 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12170 return list;
12171
12172 t = c_parser_expr_no_commas (parser, NULL).value;
12173 mark_exp_read (t);
12174 t = c_fully_fold (t, false, NULL);
12175 if (TREE_CODE (t) != INTEGER_CST
12176 || !INTEGRAL_TYPE_P (TREE_TYPE (t))
12177 || tree_int_cst_sgn (t) != 1)
12178 {
12179 error_at (clause_loc, "%<safelen%> clause expression must "
12180 "be positive constant integer expression");
12181 t = NULL_TREE;
12182 }
12183
12184 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12185 if (t == NULL_TREE || t == error_mark_node)
12186 return list;
12187
12188 check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
12189
12190 c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
12191 OMP_CLAUSE_SAFELEN_EXPR (c) = t;
12192 OMP_CLAUSE_CHAIN (c) = list;
12193 return c;
12194 }
12195
12196 /* OpenMP 4.0:
12197 simdlen ( constant-expression ) */
12198
12199 static tree
12200 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
12201 {
12202 location_t clause_loc = c_parser_peek_token (parser)->location;
12203 tree c, t;
12204
12205 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12206 return list;
12207
12208 t = c_parser_expr_no_commas (parser, NULL).value;
12209 mark_exp_read (t);
12210 t = c_fully_fold (t, false, NULL);
12211 if (TREE_CODE (t) != INTEGER_CST
12212 || !INTEGRAL_TYPE_P (TREE_TYPE (t))
12213 || tree_int_cst_sgn (t) != 1)
12214 {
12215 error_at (clause_loc, "%<simdlen%> clause expression must "
12216 "be positive constant integer expression");
12217 t = NULL_TREE;
12218 }
12219
12220 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12221 if (t == NULL_TREE || t == error_mark_node)
12222 return list;
12223
12224 check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
12225
12226 c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
12227 OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
12228 OMP_CLAUSE_CHAIN (c) = list;
12229 return c;
12230 }
12231
12232 /* OpenMP 4.5:
12233 vec:
12234 identifier [+/- integer]
12235 vec , identifier [+/- integer]
12236 */
12237
12238 static tree
12239 c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc,
12240 tree list)
12241 {
12242 tree vec = NULL;
12243 if (c_parser_next_token_is_not (parser, CPP_NAME)
12244 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
12245 {
12246 c_parser_error (parser, "expected identifier");
12247 return list;
12248 }
12249
12250 while (c_parser_next_token_is (parser, CPP_NAME)
12251 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
12252 {
12253 tree t = lookup_name (c_parser_peek_token (parser)->value);
12254 tree addend = NULL;
12255
12256 if (t == NULL_TREE)
12257 {
12258 undeclared_variable (c_parser_peek_token (parser)->location,
12259 c_parser_peek_token (parser)->value);
12260 t = error_mark_node;
12261 }
12262
12263 c_parser_consume_token (parser);
12264
12265 bool neg = false;
12266 if (c_parser_next_token_is (parser, CPP_MINUS))
12267 neg = true;
12268 else if (!c_parser_next_token_is (parser, CPP_PLUS))
12269 {
12270 addend = integer_zero_node;
12271 neg = false;
12272 goto add_to_vector;
12273 }
12274 c_parser_consume_token (parser);
12275
12276 if (c_parser_next_token_is_not (parser, CPP_NUMBER))
12277 {
12278 c_parser_error (parser, "expected integer");
12279 return list;
12280 }
12281
12282 addend = c_parser_peek_token (parser)->value;
12283 if (TREE_CODE (addend) != INTEGER_CST)
12284 {
12285 c_parser_error (parser, "expected integer");
12286 return list;
12287 }
12288 c_parser_consume_token (parser);
12289
12290 add_to_vector:
12291 if (t != error_mark_node)
12292 {
12293 vec = tree_cons (addend, t, vec);
12294 if (neg)
12295 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1;
12296 }
12297
12298 if (c_parser_next_token_is_not (parser, CPP_COMMA))
12299 break;
12300
12301 c_parser_consume_token (parser);
12302 }
12303
12304 if (vec == NULL_TREE)
12305 return list;
12306
12307 tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
12308 OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK;
12309 OMP_CLAUSE_DECL (u) = nreverse (vec);
12310 OMP_CLAUSE_CHAIN (u) = list;
12311 return u;
12312 }
12313
12314 /* OpenMP 4.0:
12315 depend ( depend-kind: variable-list )
12316
12317 depend-kind:
12318 in | out | inout
12319
12320 OpenMP 4.5:
12321 depend ( source )
12322
12323 depend ( sink : vec ) */
12324
12325 static tree
12326 c_parser_omp_clause_depend (c_parser *parser, tree list)
12327 {
12328 location_t clause_loc = c_parser_peek_token (parser)->location;
12329 enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
12330 tree nl, c;
12331
12332 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12333 return list;
12334
12335 if (c_parser_next_token_is (parser, CPP_NAME))
12336 {
12337 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12338 if (strcmp ("in", p) == 0)
12339 kind = OMP_CLAUSE_DEPEND_IN;
12340 else if (strcmp ("inout", p) == 0)
12341 kind = OMP_CLAUSE_DEPEND_INOUT;
12342 else if (strcmp ("out", p) == 0)
12343 kind = OMP_CLAUSE_DEPEND_OUT;
12344 else if (strcmp ("source", p) == 0)
12345 kind = OMP_CLAUSE_DEPEND_SOURCE;
12346 else if (strcmp ("sink", p) == 0)
12347 kind = OMP_CLAUSE_DEPEND_SINK;
12348 else
12349 goto invalid_kind;
12350 }
12351 else
12352 goto invalid_kind;
12353
12354 c_parser_consume_token (parser);
12355
12356 if (kind == OMP_CLAUSE_DEPEND_SOURCE)
12357 {
12358 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
12359 OMP_CLAUSE_DEPEND_KIND (c) = kind;
12360 OMP_CLAUSE_DECL (c) = NULL_TREE;
12361 OMP_CLAUSE_CHAIN (c) = list;
12362 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12363 return c;
12364 }
12365
12366 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12367 goto resync_fail;
12368
12369 if (kind == OMP_CLAUSE_DEPEND_SINK)
12370 nl = c_parser_omp_clause_depend_sink (parser, clause_loc, list);
12371 else
12372 {
12373 nl = c_parser_omp_variable_list (parser, clause_loc,
12374 OMP_CLAUSE_DEPEND, list);
12375
12376 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12377 OMP_CLAUSE_DEPEND_KIND (c) = kind;
12378 }
12379
12380 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12381 return nl;
12382
12383 invalid_kind:
12384 c_parser_error (parser, "invalid depend kind");
12385 resync_fail:
12386 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12387 return list;
12388 }
12389
12390 /* OpenMP 4.0:
12391 map ( map-kind: variable-list )
12392 map ( variable-list )
12393
12394 map-kind:
12395 alloc | to | from | tofrom
12396
12397 OpenMP 4.5:
12398 map-kind:
12399 alloc | to | from | tofrom | release | delete
12400
12401 map ( always [,] map-kind: variable-list ) */
12402
12403 static tree
12404 c_parser_omp_clause_map (c_parser *parser, tree list)
12405 {
12406 location_t clause_loc = c_parser_peek_token (parser)->location;
12407 enum gomp_map_kind kind = GOMP_MAP_TOFROM;
12408 int always = 0;
12409 enum c_id_kind always_id_kind = C_ID_NONE;
12410 location_t always_loc = UNKNOWN_LOCATION;
12411 tree always_id = NULL_TREE;
12412 tree nl, c;
12413
12414 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12415 return list;
12416
12417 if (c_parser_next_token_is (parser, CPP_NAME))
12418 {
12419 c_token *tok = c_parser_peek_token (parser);
12420 const char *p = IDENTIFIER_POINTER (tok->value);
12421 always_id_kind = tok->id_kind;
12422 always_loc = tok->location;
12423 always_id = tok->value;
12424 if (strcmp ("always", p) == 0)
12425 {
12426 c_token *sectok = c_parser_peek_2nd_token (parser);
12427 if (sectok->type == CPP_COMMA)
12428 {
12429 c_parser_consume_token (parser);
12430 c_parser_consume_token (parser);
12431 always = 2;
12432 }
12433 else if (sectok->type == CPP_NAME)
12434 {
12435 p = IDENTIFIER_POINTER (sectok->value);
12436 if (strcmp ("alloc", p) == 0
12437 || strcmp ("to", p) == 0
12438 || strcmp ("from", p) == 0
12439 || strcmp ("tofrom", p) == 0
12440 || strcmp ("release", p) == 0
12441 || strcmp ("delete", p) == 0)
12442 {
12443 c_parser_consume_token (parser);
12444 always = 1;
12445 }
12446 }
12447 }
12448 }
12449
12450 if (c_parser_next_token_is (parser, CPP_NAME)
12451 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
12452 {
12453 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12454 if (strcmp ("alloc", p) == 0)
12455 kind = GOMP_MAP_ALLOC;
12456 else if (strcmp ("to", p) == 0)
12457 kind = always ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO;
12458 else if (strcmp ("from", p) == 0)
12459 kind = always ? GOMP_MAP_ALWAYS_FROM : GOMP_MAP_FROM;
12460 else if (strcmp ("tofrom", p) == 0)
12461 kind = always ? GOMP_MAP_ALWAYS_TOFROM : GOMP_MAP_TOFROM;
12462 else if (strcmp ("release", p) == 0)
12463 kind = GOMP_MAP_RELEASE;
12464 else if (strcmp ("delete", p) == 0)
12465 kind = GOMP_MAP_DELETE;
12466 else
12467 {
12468 c_parser_error (parser, "invalid map kind");
12469 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12470 "expected %<)%>");
12471 return list;
12472 }
12473 c_parser_consume_token (parser);
12474 c_parser_consume_token (parser);
12475 }
12476 else if (always)
12477 {
12478 if (always_id_kind != C_ID_ID)
12479 {
12480 c_parser_error (parser, "expected identifier");
12481 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12482 return list;
12483 }
12484
12485 tree t = lookup_name (always_id);
12486 if (t == NULL_TREE)
12487 {
12488 undeclared_variable (always_loc, always_id);
12489 t = error_mark_node;
12490 }
12491 if (t != error_mark_node)
12492 {
12493 tree u = build_omp_clause (clause_loc, OMP_CLAUSE_MAP);
12494 OMP_CLAUSE_DECL (u) = t;
12495 OMP_CLAUSE_CHAIN (u) = list;
12496 OMP_CLAUSE_SET_MAP_KIND (u, kind);
12497 list = u;
12498 }
12499 if (always == 1)
12500 {
12501 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12502 return list;
12503 }
12504 }
12505
12506 nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
12507
12508 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12509 OMP_CLAUSE_SET_MAP_KIND (c, kind);
12510
12511 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12512 return nl;
12513 }
12514
12515 /* OpenMP 4.0:
12516 device ( expression ) */
12517
12518 static tree
12519 c_parser_omp_clause_device (c_parser *parser, tree list)
12520 {
12521 location_t clause_loc = c_parser_peek_token (parser)->location;
12522 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12523 {
12524 tree c, t = c_parser_expr_no_commas (parser, NULL).value;
12525 mark_exp_read (t);
12526 t = c_fully_fold (t, false, NULL);
12527
12528 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12529
12530 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12531 {
12532 c_parser_error (parser, "expected integer expression");
12533 return list;
12534 }
12535
12536 check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
12537
12538 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
12539 OMP_CLAUSE_DEVICE_ID (c) = t;
12540 OMP_CLAUSE_CHAIN (c) = list;
12541 list = c;
12542 }
12543
12544 return list;
12545 }
12546
12547 /* OpenMP 4.0:
12548 dist_schedule ( static )
12549 dist_schedule ( static , expression ) */
12550
12551 static tree
12552 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
12553 {
12554 tree c, t = NULL_TREE;
12555 location_t loc = c_parser_peek_token (parser)->location;
12556
12557 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12558 return list;
12559
12560 if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
12561 {
12562 c_parser_error (parser, "invalid dist_schedule kind");
12563 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12564 "expected %<)%>");
12565 return list;
12566 }
12567
12568 c_parser_consume_token (parser);
12569 if (c_parser_next_token_is (parser, CPP_COMMA))
12570 {
12571 c_parser_consume_token (parser);
12572
12573 t = c_parser_expr_no_commas (parser, NULL).value;
12574 mark_exp_read (t);
12575 t = c_fully_fold (t, false, NULL);
12576 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12577 }
12578 else
12579 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12580 "expected %<,%> or %<)%>");
12581
12582 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
12583 if (t == error_mark_node)
12584 return list;
12585
12586 c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
12587 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
12588 OMP_CLAUSE_CHAIN (c) = list;
12589 return c;
12590 }
12591
12592 /* OpenMP 4.0:
12593 proc_bind ( proc-bind-kind )
12594
12595 proc-bind-kind:
12596 master | close | spread */
12597
12598 static tree
12599 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
12600 {
12601 location_t clause_loc = c_parser_peek_token (parser)->location;
12602 enum omp_clause_proc_bind_kind kind;
12603 tree c;
12604
12605 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12606 return list;
12607
12608 if (c_parser_next_token_is (parser, CPP_NAME))
12609 {
12610 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12611 if (strcmp ("master", p) == 0)
12612 kind = OMP_CLAUSE_PROC_BIND_MASTER;
12613 else if (strcmp ("close", p) == 0)
12614 kind = OMP_CLAUSE_PROC_BIND_CLOSE;
12615 else if (strcmp ("spread", p) == 0)
12616 kind = OMP_CLAUSE_PROC_BIND_SPREAD;
12617 else
12618 goto invalid_kind;
12619 }
12620 else
12621 goto invalid_kind;
12622
12623 c_parser_consume_token (parser);
12624 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12625 c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
12626 OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
12627 OMP_CLAUSE_CHAIN (c) = list;
12628 return c;
12629
12630 invalid_kind:
12631 c_parser_error (parser, "invalid proc_bind kind");
12632 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12633 return list;
12634 }
12635
12636 /* OpenMP 4.0:
12637 to ( variable-list ) */
12638
12639 static tree
12640 c_parser_omp_clause_to (c_parser *parser, tree list)
12641 {
12642 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
12643 }
12644
12645 /* OpenMP 4.0:
12646 from ( variable-list ) */
12647
12648 static tree
12649 c_parser_omp_clause_from (c_parser *parser, tree list)
12650 {
12651 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
12652 }
12653
12654 /* OpenMP 4.0:
12655 uniform ( variable-list ) */
12656
12657 static tree
12658 c_parser_omp_clause_uniform (c_parser *parser, tree list)
12659 {
12660 /* The clauses location. */
12661 location_t loc = c_parser_peek_token (parser)->location;
12662
12663 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12664 {
12665 list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
12666 list);
12667 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12668 }
12669 return list;
12670 }
12671
12672 /* Parse all OpenACC clauses. The set clauses allowed by the directive
12673 is a bitmask in MASK. Return the list of clauses found. */
12674
12675 static tree
12676 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
12677 const char *where, bool finish_p = true)
12678 {
12679 tree clauses = NULL;
12680 bool first = true;
12681
12682 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12683 {
12684 location_t here;
12685 pragma_omp_clause c_kind;
12686 const char *c_name;
12687 tree prev = clauses;
12688
12689 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
12690 c_parser_consume_token (parser);
12691
12692 here = c_parser_peek_token (parser)->location;
12693 c_kind = c_parser_omp_clause_name (parser);
12694
12695 switch (c_kind)
12696 {
12697 case PRAGMA_OACC_CLAUSE_ASYNC:
12698 clauses = c_parser_oacc_clause_async (parser, clauses);
12699 c_name = "async";
12700 break;
12701 case PRAGMA_OACC_CLAUSE_AUTO:
12702 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_AUTO,
12703 clauses);
12704 c_name = "auto";
12705 break;
12706 case PRAGMA_OACC_CLAUSE_COLLAPSE:
12707 clauses = c_parser_omp_clause_collapse (parser, clauses);
12708 c_name = "collapse";
12709 break;
12710 case PRAGMA_OACC_CLAUSE_COPY:
12711 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12712 c_name = "copy";
12713 break;
12714 case PRAGMA_OACC_CLAUSE_COPYIN:
12715 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12716 c_name = "copyin";
12717 break;
12718 case PRAGMA_OACC_CLAUSE_COPYOUT:
12719 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12720 c_name = "copyout";
12721 break;
12722 case PRAGMA_OACC_CLAUSE_CREATE:
12723 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12724 c_name = "create";
12725 break;
12726 case PRAGMA_OACC_CLAUSE_DELETE:
12727 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12728 c_name = "delete";
12729 break;
12730 case PRAGMA_OMP_CLAUSE_DEFAULT:
12731 clauses = c_parser_omp_clause_default (parser, clauses, true);
12732 c_name = "default";
12733 break;
12734 case PRAGMA_OACC_CLAUSE_DEVICE:
12735 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12736 c_name = "device";
12737 break;
12738 case PRAGMA_OACC_CLAUSE_DEVICEPTR:
12739 clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
12740 c_name = "deviceptr";
12741 break;
12742 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
12743 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
12744 c_name = "firstprivate";
12745 break;
12746 case PRAGMA_OACC_CLAUSE_GANG:
12747 c_name = "gang";
12748 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_GANG,
12749 c_name, clauses);
12750 break;
12751 case PRAGMA_OACC_CLAUSE_HOST:
12752 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12753 c_name = "host";
12754 break;
12755 case PRAGMA_OACC_CLAUSE_IF:
12756 clauses = c_parser_omp_clause_if (parser, clauses, false);
12757 c_name = "if";
12758 break;
12759 case PRAGMA_OACC_CLAUSE_INDEPENDENT:
12760 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_INDEPENDENT,
12761 clauses);
12762 c_name = "independent";
12763 break;
12764 case PRAGMA_OACC_CLAUSE_NUM_GANGS:
12765 clauses = c_parser_omp_clause_num_gangs (parser, clauses);
12766 c_name = "num_gangs";
12767 break;
12768 case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
12769 clauses = c_parser_omp_clause_num_workers (parser, clauses);
12770 c_name = "num_workers";
12771 break;
12772 case PRAGMA_OACC_CLAUSE_PRESENT:
12773 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12774 c_name = "present";
12775 break;
12776 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
12777 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12778 c_name = "present_or_copy";
12779 break;
12780 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
12781 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12782 c_name = "present_or_copyin";
12783 break;
12784 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
12785 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12786 c_name = "present_or_copyout";
12787 break;
12788 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
12789 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12790 c_name = "present_or_create";
12791 break;
12792 case PRAGMA_OACC_CLAUSE_PRIVATE:
12793 clauses = c_parser_omp_clause_private (parser, clauses);
12794 c_name = "private";
12795 break;
12796 case PRAGMA_OACC_CLAUSE_REDUCTION:
12797 clauses = c_parser_omp_clause_reduction (parser, clauses);
12798 c_name = "reduction";
12799 break;
12800 case PRAGMA_OACC_CLAUSE_SELF:
12801 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12802 c_name = "self";
12803 break;
12804 case PRAGMA_OACC_CLAUSE_SEQ:
12805 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ,
12806 clauses);
12807 c_name = "seq";
12808 break;
12809 case PRAGMA_OACC_CLAUSE_TILE:
12810 clauses = c_parser_oacc_clause_tile (parser, clauses);
12811 c_name = "tile";
12812 break;
12813 case PRAGMA_OACC_CLAUSE_VECTOR:
12814 c_name = "vector";
12815 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_VECTOR,
12816 c_name, clauses);
12817 break;
12818 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
12819 clauses = c_parser_omp_clause_vector_length (parser, clauses);
12820 c_name = "vector_length";
12821 break;
12822 case PRAGMA_OACC_CLAUSE_WAIT:
12823 clauses = c_parser_oacc_clause_wait (parser, clauses);
12824 c_name = "wait";
12825 break;
12826 case PRAGMA_OACC_CLAUSE_WORKER:
12827 c_name = "worker";
12828 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_WORKER,
12829 c_name, clauses);
12830 break;
12831 default:
12832 c_parser_error (parser, "expected %<#pragma acc%> clause");
12833 goto saw_error;
12834 }
12835
12836 first = false;
12837
12838 if (((mask >> c_kind) & 1) == 0)
12839 {
12840 /* Remove the invalid clause(s) from the list to avoid
12841 confusing the rest of the compiler. */
12842 clauses = prev;
12843 error_at (here, "%qs is not valid for %qs", c_name, where);
12844 }
12845 }
12846
12847 saw_error:
12848 c_parser_skip_to_pragma_eol (parser);
12849
12850 if (finish_p)
12851 return c_finish_omp_clauses (clauses, false);
12852
12853 return clauses;
12854 }
12855
12856 /* Parse all OpenMP clauses. The set clauses allowed by the directive
12857 is a bitmask in MASK. Return the list of clauses found. */
12858
12859 static tree
12860 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
12861 const char *where, bool finish_p = true)
12862 {
12863 tree clauses = NULL;
12864 bool first = true, cilk_simd_fn = false;
12865
12866 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12867 {
12868 location_t here;
12869 pragma_omp_clause c_kind;
12870 const char *c_name;
12871 tree prev = clauses;
12872
12873 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
12874 c_parser_consume_token (parser);
12875
12876 here = c_parser_peek_token (parser)->location;
12877 c_kind = c_parser_omp_clause_name (parser);
12878
12879 switch (c_kind)
12880 {
12881 case PRAGMA_OMP_CLAUSE_COLLAPSE:
12882 clauses = c_parser_omp_clause_collapse (parser, clauses);
12883 c_name = "collapse";
12884 break;
12885 case PRAGMA_OMP_CLAUSE_COPYIN:
12886 clauses = c_parser_omp_clause_copyin (parser, clauses);
12887 c_name = "copyin";
12888 break;
12889 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
12890 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
12891 c_name = "copyprivate";
12892 break;
12893 case PRAGMA_OMP_CLAUSE_DEFAULT:
12894 clauses = c_parser_omp_clause_default (parser, clauses, false);
12895 c_name = "default";
12896 break;
12897 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
12898 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
12899 c_name = "firstprivate";
12900 break;
12901 case PRAGMA_OMP_CLAUSE_FINAL:
12902 clauses = c_parser_omp_clause_final (parser, clauses);
12903 c_name = "final";
12904 break;
12905 case PRAGMA_OMP_CLAUSE_GRAINSIZE:
12906 clauses = c_parser_omp_clause_grainsize (parser, clauses);
12907 c_name = "grainsize";
12908 break;
12909 case PRAGMA_OMP_CLAUSE_HINT:
12910 clauses = c_parser_omp_clause_hint (parser, clauses);
12911 c_name = "hint";
12912 break;
12913 case PRAGMA_OMP_CLAUSE_DEFAULTMAP:
12914 clauses = c_parser_omp_clause_defaultmap (parser, clauses);
12915 c_name = "defaultmap";
12916 break;
12917 case PRAGMA_OMP_CLAUSE_IF:
12918 clauses = c_parser_omp_clause_if (parser, clauses, true);
12919 c_name = "if";
12920 break;
12921 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
12922 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
12923 c_name = "lastprivate";
12924 break;
12925 case PRAGMA_OMP_CLAUSE_MERGEABLE:
12926 clauses = c_parser_omp_clause_mergeable (parser, clauses);
12927 c_name = "mergeable";
12928 break;
12929 case PRAGMA_OMP_CLAUSE_NOWAIT:
12930 clauses = c_parser_omp_clause_nowait (parser, clauses);
12931 c_name = "nowait";
12932 break;
12933 case PRAGMA_OMP_CLAUSE_NUM_TASKS:
12934 clauses = c_parser_omp_clause_num_tasks (parser, clauses);
12935 c_name = "num_tasks";
12936 break;
12937 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
12938 clauses = c_parser_omp_clause_num_threads (parser, clauses);
12939 c_name = "num_threads";
12940 break;
12941 case PRAGMA_OMP_CLAUSE_ORDERED:
12942 clauses = c_parser_omp_clause_ordered (parser, clauses);
12943 c_name = "ordered";
12944 break;
12945 case PRAGMA_OMP_CLAUSE_PRIORITY:
12946 clauses = c_parser_omp_clause_priority (parser, clauses);
12947 c_name = "priority";
12948 break;
12949 case PRAGMA_OMP_CLAUSE_PRIVATE:
12950 clauses = c_parser_omp_clause_private (parser, clauses);
12951 c_name = "private";
12952 break;
12953 case PRAGMA_OMP_CLAUSE_REDUCTION:
12954 clauses = c_parser_omp_clause_reduction (parser, clauses);
12955 c_name = "reduction";
12956 break;
12957 case PRAGMA_OMP_CLAUSE_SCHEDULE:
12958 clauses = c_parser_omp_clause_schedule (parser, clauses);
12959 c_name = "schedule";
12960 break;
12961 case PRAGMA_OMP_CLAUSE_SHARED:
12962 clauses = c_parser_omp_clause_shared (parser, clauses);
12963 c_name = "shared";
12964 break;
12965 case PRAGMA_OMP_CLAUSE_UNTIED:
12966 clauses = c_parser_omp_clause_untied (parser, clauses);
12967 c_name = "untied";
12968 break;
12969 case PRAGMA_OMP_CLAUSE_INBRANCH:
12970 case PRAGMA_CILK_CLAUSE_MASK:
12971 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
12972 clauses);
12973 c_name = "inbranch";
12974 break;
12975 case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
12976 case PRAGMA_CILK_CLAUSE_NOMASK:
12977 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
12978 clauses);
12979 c_name = "notinbranch";
12980 break;
12981 case PRAGMA_OMP_CLAUSE_PARALLEL:
12982 clauses
12983 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
12984 clauses);
12985 c_name = "parallel";
12986 if (!first)
12987 {
12988 clause_not_first:
12989 error_at (here, "%qs must be the first clause of %qs",
12990 c_name, where);
12991 clauses = prev;
12992 }
12993 break;
12994 case PRAGMA_OMP_CLAUSE_FOR:
12995 clauses
12996 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
12997 clauses);
12998 c_name = "for";
12999 if (!first)
13000 goto clause_not_first;
13001 break;
13002 case PRAGMA_OMP_CLAUSE_SECTIONS:
13003 clauses
13004 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
13005 clauses);
13006 c_name = "sections";
13007 if (!first)
13008 goto clause_not_first;
13009 break;
13010 case PRAGMA_OMP_CLAUSE_TASKGROUP:
13011 clauses
13012 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
13013 clauses);
13014 c_name = "taskgroup";
13015 if (!first)
13016 goto clause_not_first;
13017 break;
13018 case PRAGMA_OMP_CLAUSE_LINK:
13019 clauses
13020 = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses);
13021 c_name = "link";
13022 break;
13023 case PRAGMA_OMP_CLAUSE_TO:
13024 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0)
13025 clauses
13026 = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
13027 clauses);
13028 else
13029 clauses = c_parser_omp_clause_to (parser, clauses);
13030 c_name = "to";
13031 break;
13032 case PRAGMA_OMP_CLAUSE_FROM:
13033 clauses = c_parser_omp_clause_from (parser, clauses);
13034 c_name = "from";
13035 break;
13036 case PRAGMA_OMP_CLAUSE_UNIFORM:
13037 clauses = c_parser_omp_clause_uniform (parser, clauses);
13038 c_name = "uniform";
13039 break;
13040 case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
13041 clauses = c_parser_omp_clause_num_teams (parser, clauses);
13042 c_name = "num_teams";
13043 break;
13044 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
13045 clauses = c_parser_omp_clause_thread_limit (parser, clauses);
13046 c_name = "thread_limit";
13047 break;
13048 case PRAGMA_OMP_CLAUSE_ALIGNED:
13049 clauses = c_parser_omp_clause_aligned (parser, clauses);
13050 c_name = "aligned";
13051 break;
13052 case PRAGMA_OMP_CLAUSE_LINEAR:
13053 if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0)
13054 cilk_simd_fn = true;
13055 clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn);
13056 c_name = "linear";
13057 break;
13058 case PRAGMA_OMP_CLAUSE_DEPEND:
13059 clauses = c_parser_omp_clause_depend (parser, clauses);
13060 c_name = "depend";
13061 break;
13062 case PRAGMA_OMP_CLAUSE_MAP:
13063 clauses = c_parser_omp_clause_map (parser, clauses);
13064 c_name = "map";
13065 break;
13066 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR:
13067 clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
13068 c_name = "use_device_ptr";
13069 break;
13070 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR:
13071 clauses = c_parser_omp_clause_is_device_ptr (parser, clauses);
13072 c_name = "is_device_ptr";
13073 break;
13074 case PRAGMA_OMP_CLAUSE_DEVICE:
13075 clauses = c_parser_omp_clause_device (parser, clauses);
13076 c_name = "device";
13077 break;
13078 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
13079 clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
13080 c_name = "dist_schedule";
13081 break;
13082 case PRAGMA_OMP_CLAUSE_PROC_BIND:
13083 clauses = c_parser_omp_clause_proc_bind (parser, clauses);
13084 c_name = "proc_bind";
13085 break;
13086 case PRAGMA_OMP_CLAUSE_SAFELEN:
13087 clauses = c_parser_omp_clause_safelen (parser, clauses);
13088 c_name = "safelen";
13089 break;
13090 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
13091 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true);
13092 c_name = "simdlen";
13093 break;
13094 case PRAGMA_OMP_CLAUSE_SIMDLEN:
13095 clauses = c_parser_omp_clause_simdlen (parser, clauses);
13096 c_name = "simdlen";
13097 break;
13098 case PRAGMA_OMP_CLAUSE_NOGROUP:
13099 clauses = c_parser_omp_clause_nogroup (parser, clauses);
13100 c_name = "nogroup";
13101 break;
13102 case PRAGMA_OMP_CLAUSE_THREADS:
13103 clauses
13104 = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS,
13105 clauses);
13106 c_name = "threads";
13107 break;
13108 case PRAGMA_OMP_CLAUSE_SIMD:
13109 clauses
13110 = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD,
13111 clauses);
13112 c_name = "simd";
13113 break;
13114 default:
13115 c_parser_error (parser, "expected %<#pragma omp%> clause");
13116 goto saw_error;
13117 }
13118
13119 first = false;
13120
13121 if (((mask >> c_kind) & 1) == 0)
13122 {
13123 /* Remove the invalid clause(s) from the list to avoid
13124 confusing the rest of the compiler. */
13125 clauses = prev;
13126 error_at (here, "%qs is not valid for %qs", c_name, where);
13127 }
13128 }
13129
13130 saw_error:
13131 c_parser_skip_to_pragma_eol (parser);
13132
13133 if (finish_p)
13134 {
13135 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0)
13136 return c_finish_omp_clauses (clauses, true, true);
13137 return c_finish_omp_clauses (clauses, true);
13138 }
13139
13140 return clauses;
13141 }
13142
13143 /* OpenACC 2.0, OpenMP 2.5:
13144 structured-block:
13145 statement
13146
13147 In practice, we're also interested in adding the statement to an
13148 outer node. So it is convenient if we work around the fact that
13149 c_parser_statement calls add_stmt. */
13150
13151 static tree
13152 c_parser_omp_structured_block (c_parser *parser)
13153 {
13154 tree stmt = push_stmt_list ();
13155 c_parser_statement (parser);
13156 return pop_stmt_list (stmt);
13157 }
13158
13159 /* OpenACC 2.0:
13160 # pragma acc cache (variable-list) new-line
13161
13162 LOC is the location of the #pragma token.
13163 */
13164
13165 static tree
13166 c_parser_oacc_cache (location_t loc, c_parser *parser)
13167 {
13168 tree stmt, clauses;
13169
13170 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
13171 clauses = c_finish_omp_clauses (clauses, false);
13172
13173 c_parser_skip_to_pragma_eol (parser);
13174
13175 stmt = make_node (OACC_CACHE);
13176 TREE_TYPE (stmt) = void_type_node;
13177 OACC_CACHE_CLAUSES (stmt) = clauses;
13178 SET_EXPR_LOCATION (stmt, loc);
13179 add_stmt (stmt);
13180
13181 return stmt;
13182 }
13183
13184 /* OpenACC 2.0:
13185 # pragma acc data oacc-data-clause[optseq] new-line
13186 structured-block
13187
13188 LOC is the location of the #pragma token.
13189 */
13190
13191 #define OACC_DATA_CLAUSE_MASK \
13192 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13193 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13194 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13195 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13196 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13197 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13198 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13199 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13200 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13201 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13202 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13203
13204 static tree
13205 c_parser_oacc_data (location_t loc, c_parser *parser)
13206 {
13207 tree stmt, clauses, block;
13208
13209 clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
13210 "#pragma acc data");
13211
13212 block = c_begin_omp_parallel ();
13213 add_stmt (c_parser_omp_structured_block (parser));
13214
13215 stmt = c_finish_oacc_data (loc, clauses, block);
13216
13217 return stmt;
13218 }
13219
13220 /* OpenACC 2.0:
13221 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13222
13223 or
13224
13225 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13226
13227
13228 LOC is the location of the #pragma token.
13229 */
13230
13231 #define OACC_ENTER_DATA_CLAUSE_MASK \
13232 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13233 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13234 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13239
13240 #define OACC_EXIT_DATA_CLAUSE_MASK \
13241 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13243 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13246
13247 static void
13248 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
13249 {
13250 location_t loc = c_parser_peek_token (parser)->location;
13251 tree clauses, stmt;
13252
13253 c_parser_consume_pragma (parser);
13254
13255 if (!c_parser_next_token_is (parser, CPP_NAME))
13256 {
13257 c_parser_error (parser, enter
13258 ? "expected %<data%> in %<#pragma acc enter data%>"
13259 : "expected %<data%> in %<#pragma acc exit data%>");
13260 c_parser_skip_to_pragma_eol (parser);
13261 return;
13262 }
13263
13264 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13265 if (strcmp (p, "data") != 0)
13266 {
13267 c_parser_error (parser, "invalid pragma");
13268 c_parser_skip_to_pragma_eol (parser);
13269 return;
13270 }
13271
13272 c_parser_consume_token (parser);
13273
13274 if (enter)
13275 clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
13276 "#pragma acc enter data");
13277 else
13278 clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
13279 "#pragma acc exit data");
13280
13281 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
13282 {
13283 error_at (loc, enter
13284 ? "%<#pragma acc enter data%> has no data movement clause"
13285 : "%<#pragma acc exit data%> has no data movement clause");
13286 return;
13287 }
13288
13289 stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);
13290 TREE_TYPE (stmt) = void_type_node;
13291 OMP_STANDALONE_CLAUSES (stmt) = clauses;
13292 SET_EXPR_LOCATION (stmt, loc);
13293 add_stmt (stmt);
13294 }
13295
13296
13297 /* OpenACC 2.0:
13298
13299 # pragma acc loop oacc-loop-clause[optseq] new-line
13300 structured-block
13301
13302 LOC is the location of the #pragma token.
13303 */
13304
13305 #define OACC_LOOP_CLAUSE_MASK \
13306 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
13307 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13308 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13309 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13311 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
13313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
13314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
13315 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
13316 static tree
13317 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name,
13318 omp_clause_mask mask, tree *cclauses)
13319 {
13320 strcat (p_name, " loop");
13321 mask |= OACC_LOOP_CLAUSE_MASK;
13322
13323 tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name,
13324 cclauses == NULL);
13325 if (cclauses)
13326 {
13327 clauses = c_oacc_split_loop_clauses (clauses, cclauses);
13328 if (*cclauses)
13329 c_finish_omp_clauses (*cclauses, false);
13330 if (clauses)
13331 c_finish_omp_clauses (clauses, false);
13332 }
13333
13334 tree block = c_begin_compound_stmt (true);
13335 tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL);
13336 block = c_end_compound_stmt (loc, block, true);
13337 add_stmt (block);
13338
13339 return stmt;
13340 }
13341
13342 /* OpenACC 2.0:
13343 # pragma acc kernels oacc-kernels-clause[optseq] new-line
13344 structured-block
13345
13346 or
13347
13348 # pragma acc parallel oacc-parallel-clause[optseq] new-line
13349 structured-block
13350
13351 LOC is the location of the #pragma token.
13352 */
13353
13354 #define OACC_KERNELS_CLAUSE_MASK \
13355 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13357 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13358 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13359 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13360 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13361 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13362 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13363 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13364 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13365 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13366 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13367 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13368 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13369
13370 #define OACC_PARALLEL_CLAUSE_MASK \
13371 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13372 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13373 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13374 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13375 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13376 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13377 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13378 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13379 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13380 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
13381 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
13382 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
13383 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13384 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13385 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13386 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13387 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13388 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13389 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
13390 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13391
13392 static tree
13393 c_parser_oacc_kernels_parallel (location_t loc, c_parser *parser,
13394 enum pragma_kind p_kind, char *p_name)
13395 {
13396 omp_clause_mask mask;
13397 enum tree_code code;
13398 switch (p_kind)
13399 {
13400 case PRAGMA_OACC_KERNELS:
13401 strcat (p_name, " kernels");
13402 mask = OACC_KERNELS_CLAUSE_MASK;
13403 code = OACC_KERNELS;
13404 break;
13405 case PRAGMA_OACC_PARALLEL:
13406 strcat (p_name, " parallel");
13407 mask = OACC_PARALLEL_CLAUSE_MASK;
13408 code = OACC_PARALLEL;
13409 break;
13410 default:
13411 gcc_unreachable ();
13412 }
13413
13414 if (c_parser_next_token_is (parser, CPP_NAME))
13415 {
13416 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13417 if (strcmp (p, "loop") == 0)
13418 {
13419 c_parser_consume_token (parser);
13420 mask |= OACC_LOOP_CLAUSE_MASK;
13421
13422 tree block = c_begin_omp_parallel ();
13423 tree clauses;
13424 c_parser_oacc_loop (loc, parser, p_name, mask, &clauses);
13425 return c_finish_omp_construct (loc, code, block, clauses);
13426 }
13427 }
13428
13429 tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name);
13430
13431 tree block = c_begin_omp_parallel ();
13432 add_stmt (c_parser_omp_structured_block (parser));
13433
13434 return c_finish_omp_construct (loc, code, block, clauses);
13435 }
13436
13437 /* OpenACC 2.0:
13438 # pragma acc routine oacc-routine-clause[optseq] new-line
13439 function-definition
13440
13441 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
13442 */
13443
13444 #define OACC_ROUTINE_CLAUSE_MASK \
13445 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13446 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13447 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13448 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
13449
13450 /* Parse an OpenACC routine directive. For named directives, we apply
13451 immediately to the named function. For unnamed ones we then parse
13452 a declaration or definition, which must be for a function. */
13453
13454 static void
13455 c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
13456 {
13457 tree decl = NULL_TREE;
13458 /* Create a dummy claue, to record location. */
13459 tree c_head = build_omp_clause (c_parser_peek_token (parser)->location,
13460 OMP_CLAUSE_SEQ);
13461
13462 if (context != pragma_external)
13463 c_parser_error (parser, "%<#pragma acc routine%> not at file scope");
13464
13465 c_parser_consume_pragma (parser);
13466
13467 /* Scan for optional '( name )'. */
13468 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
13469 {
13470 c_parser_consume_token (parser);
13471
13472 c_token *token = c_parser_peek_token (parser);
13473
13474 if (token->type == CPP_NAME && (token->id_kind == C_ID_ID
13475 || token->id_kind == C_ID_TYPENAME))
13476 {
13477 decl = lookup_name (token->value);
13478 if (!decl)
13479 {
13480 error_at (token->location, "%qE has not been declared",
13481 token->value);
13482 decl = error_mark_node;
13483 }
13484 }
13485 else
13486 c_parser_error (parser, "expected function name");
13487
13488 if (token->type != CPP_CLOSE_PAREN)
13489 c_parser_consume_token (parser);
13490
13491 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
13492 }
13493
13494 /* Build a chain of clauses. */
13495 parser->in_pragma = true;
13496 tree clauses = c_parser_oacc_all_clauses
13497 (parser, OACC_ROUTINE_CLAUSE_MASK, "#pragma acc routine");
13498
13499 /* Force clauses to be non-null, by attaching context to it. */
13500 clauses = tree_cons (c_head, clauses, NULL_TREE);
13501
13502 if (decl)
13503 c_finish_oacc_routine (parser, decl, clauses, true, true, false);
13504 else if (c_parser_peek_token (parser)->type == CPP_PRAGMA)
13505 /* This will emit an error. */
13506 c_finish_oacc_routine (parser, NULL_TREE, clauses, false, true, false);
13507 else
13508 c_parser_declaration_or_fndef (parser, true, false, false, false,
13509 true, NULL, vNULL, clauses);
13510 }
13511
13512 /* Finalize an OpenACC routine pragma, applying it to FNDECL. CLAUSES
13513 are the parsed clauses. IS_DEFN is true if we're applying it to
13514 the definition (so expect FNDEF to look somewhat defined. */
13515
13516 static void
13517 c_finish_oacc_routine (c_parser *ARG_UNUSED (parser), tree fndecl,
13518 tree clauses, bool named, bool first, bool is_defn)
13519 {
13520 location_t loc = OMP_CLAUSE_LOCATION (TREE_PURPOSE (clauses));
13521
13522 if (!fndecl || TREE_CODE (fndecl) != FUNCTION_DECL || !first)
13523 {
13524 if (fndecl != error_mark_node)
13525 error_at (loc, "%<#pragma acc routine%> %s",
13526 named ? "does not refer to a function"
13527 : "not followed by single function");
13528 return;
13529 }
13530
13531 if (get_oacc_fn_attrib (fndecl))
13532 error_at (loc, "%<#pragma acc routine%> already applied to %D", fndecl);
13533
13534 if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
13535 error_at (loc, "%<#pragma acc routine%> must be applied before %s",
13536 TREE_USED (fndecl) ? "use" : "definition");
13537
13538 /* Process for function attrib */
13539 tree dims = build_oacc_routine_dims (TREE_VALUE (clauses));
13540 replace_oacc_fn_attrib (fndecl, dims);
13541
13542 /* Also attach as a declare. */
13543 DECL_ATTRIBUTES (fndecl)
13544 = tree_cons (get_identifier ("omp declare target"),
13545 clauses, DECL_ATTRIBUTES (fndecl));
13546 }
13547
13548 /* OpenACC 2.0:
13549 # pragma acc update oacc-update-clause[optseq] new-line
13550 */
13551
13552 #define OACC_UPDATE_CLAUSE_MASK \
13553 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13554 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
13555 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
13556 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13557 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
13558 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13559
13560 static void
13561 c_parser_oacc_update (c_parser *parser)
13562 {
13563 location_t loc = c_parser_peek_token (parser)->location;
13564
13565 c_parser_consume_pragma (parser);
13566
13567 tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
13568 "#pragma acc update");
13569 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
13570 {
13571 error_at (loc,
13572 "%<#pragma acc update%> must contain at least one "
13573 "%<device%> or %<host%> or %<self%> clause");
13574 return;
13575 }
13576
13577 if (parser->error)
13578 return;
13579
13580 tree stmt = make_node (OACC_UPDATE);
13581 TREE_TYPE (stmt) = void_type_node;
13582 OACC_UPDATE_CLAUSES (stmt) = clauses;
13583 SET_EXPR_LOCATION (stmt, loc);
13584 add_stmt (stmt);
13585 }
13586
13587 /* OpenACC 2.0:
13588 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
13589
13590 LOC is the location of the #pragma token.
13591 */
13592
13593 #define OACC_WAIT_CLAUSE_MASK \
13594 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
13595
13596 static tree
13597 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
13598 {
13599 tree clauses, list = NULL_TREE, stmt = NULL_TREE;
13600
13601 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
13602 list = c_parser_oacc_wait_list (parser, loc, list);
13603
13604 strcpy (p_name, " wait");
13605 clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
13606 stmt = c_finish_oacc_wait (loc, list, clauses);
13607
13608 return stmt;
13609 }
13610
13611 /* OpenMP 2.5:
13612 # pragma omp atomic new-line
13613 expression-stmt
13614
13615 expression-stmt:
13616 x binop= expr | x++ | ++x | x-- | --x
13617 binop:
13618 +, *, -, /, &, ^, |, <<, >>
13619
13620 where x is an lvalue expression with scalar type.
13621
13622 OpenMP 3.1:
13623 # pragma omp atomic new-line
13624 update-stmt
13625
13626 # pragma omp atomic read new-line
13627 read-stmt
13628
13629 # pragma omp atomic write new-line
13630 write-stmt
13631
13632 # pragma omp atomic update new-line
13633 update-stmt
13634
13635 # pragma omp atomic capture new-line
13636 capture-stmt
13637
13638 # pragma omp atomic capture new-line
13639 capture-block
13640
13641 read-stmt:
13642 v = x
13643 write-stmt:
13644 x = expr
13645 update-stmt:
13646 expression-stmt | x = x binop expr
13647 capture-stmt:
13648 v = expression-stmt
13649 capture-block:
13650 { v = x; update-stmt; } | { update-stmt; v = x; }
13651
13652 OpenMP 4.0:
13653 update-stmt:
13654 expression-stmt | x = x binop expr | x = expr binop x
13655 capture-stmt:
13656 v = update-stmt
13657 capture-block:
13658 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
13659
13660 where x and v are lvalue expressions with scalar type.
13661
13662 LOC is the location of the #pragma token. */
13663
13664 static void
13665 c_parser_omp_atomic (location_t loc, c_parser *parser)
13666 {
13667 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
13668 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
13669 tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
13670 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
13671 struct c_expr expr;
13672 location_t eloc;
13673 bool structured_block = false;
13674 bool swapped = false;
13675 bool seq_cst = false;
13676 bool non_lvalue_p;
13677
13678 if (c_parser_next_token_is (parser, CPP_NAME))
13679 {
13680 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13681 if (!strcmp (p, "seq_cst"))
13682 {
13683 seq_cst = true;
13684 c_parser_consume_token (parser);
13685 if (c_parser_next_token_is (parser, CPP_COMMA)
13686 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
13687 c_parser_consume_token (parser);
13688 }
13689 }
13690 if (c_parser_next_token_is (parser, CPP_NAME))
13691 {
13692 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13693
13694 if (!strcmp (p, "read"))
13695 code = OMP_ATOMIC_READ;
13696 else if (!strcmp (p, "write"))
13697 code = NOP_EXPR;
13698 else if (!strcmp (p, "update"))
13699 code = OMP_ATOMIC;
13700 else if (!strcmp (p, "capture"))
13701 code = OMP_ATOMIC_CAPTURE_NEW;
13702 else
13703 p = NULL;
13704 if (p)
13705 c_parser_consume_token (parser);
13706 }
13707 if (!seq_cst)
13708 {
13709 if (c_parser_next_token_is (parser, CPP_COMMA)
13710 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
13711 c_parser_consume_token (parser);
13712
13713 if (c_parser_next_token_is (parser, CPP_NAME))
13714 {
13715 const char *p
13716 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13717 if (!strcmp (p, "seq_cst"))
13718 {
13719 seq_cst = true;
13720 c_parser_consume_token (parser);
13721 }
13722 }
13723 }
13724 c_parser_skip_to_pragma_eol (parser);
13725
13726 switch (code)
13727 {
13728 case OMP_ATOMIC_READ:
13729 case NOP_EXPR: /* atomic write */
13730 v = c_parser_cast_expression (parser, NULL).value;
13731 non_lvalue_p = !lvalue_p (v);
13732 v = c_fully_fold (v, false, NULL);
13733 if (v == error_mark_node)
13734 goto saw_error;
13735 if (non_lvalue_p)
13736 v = non_lvalue (v);
13737 loc = c_parser_peek_token (parser)->location;
13738 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
13739 goto saw_error;
13740 if (code == NOP_EXPR)
13741 {
13742 lhs = c_parser_expression (parser).value;
13743 lhs = c_fully_fold (lhs, false, NULL);
13744 if (lhs == error_mark_node)
13745 goto saw_error;
13746 }
13747 else
13748 {
13749 lhs = c_parser_cast_expression (parser, NULL).value;
13750 non_lvalue_p = !lvalue_p (lhs);
13751 lhs = c_fully_fold (lhs, false, NULL);
13752 if (lhs == error_mark_node)
13753 goto saw_error;
13754 if (non_lvalue_p)
13755 lhs = non_lvalue (lhs);
13756 }
13757 if (code == NOP_EXPR)
13758 {
13759 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
13760 opcode. */
13761 code = OMP_ATOMIC;
13762 rhs = lhs;
13763 lhs = v;
13764 v = NULL_TREE;
13765 }
13766 goto done;
13767 case OMP_ATOMIC_CAPTURE_NEW:
13768 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
13769 {
13770 c_parser_consume_token (parser);
13771 structured_block = true;
13772 }
13773 else
13774 {
13775 v = c_parser_cast_expression (parser, NULL).value;
13776 non_lvalue_p = !lvalue_p (v);
13777 v = c_fully_fold (v, false, NULL);
13778 if (v == error_mark_node)
13779 goto saw_error;
13780 if (non_lvalue_p)
13781 v = non_lvalue (v);
13782 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
13783 goto saw_error;
13784 }
13785 break;
13786 default:
13787 break;
13788 }
13789
13790 /* For structured_block case we don't know yet whether
13791 old or new x should be captured. */
13792 restart:
13793 eloc = c_parser_peek_token (parser)->location;
13794 expr = c_parser_cast_expression (parser, NULL);
13795 lhs = expr.value;
13796 expr = default_function_array_conversion (eloc, expr);
13797 unfolded_lhs = expr.value;
13798 lhs = c_fully_fold (lhs, false, NULL);
13799 orig_lhs = lhs;
13800 switch (TREE_CODE (lhs))
13801 {
13802 case ERROR_MARK:
13803 saw_error:
13804 c_parser_skip_to_end_of_block_or_statement (parser);
13805 if (structured_block)
13806 {
13807 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13808 c_parser_consume_token (parser);
13809 else if (code == OMP_ATOMIC_CAPTURE_NEW)
13810 {
13811 c_parser_skip_to_end_of_block_or_statement (parser);
13812 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13813 c_parser_consume_token (parser);
13814 }
13815 }
13816 return;
13817
13818 case POSTINCREMENT_EXPR:
13819 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
13820 code = OMP_ATOMIC_CAPTURE_OLD;
13821 /* FALLTHROUGH */
13822 case PREINCREMENT_EXPR:
13823 lhs = TREE_OPERAND (lhs, 0);
13824 unfolded_lhs = NULL_TREE;
13825 opcode = PLUS_EXPR;
13826 rhs = integer_one_node;
13827 break;
13828
13829 case POSTDECREMENT_EXPR:
13830 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
13831 code = OMP_ATOMIC_CAPTURE_OLD;
13832 /* FALLTHROUGH */
13833 case PREDECREMENT_EXPR:
13834 lhs = TREE_OPERAND (lhs, 0);
13835 unfolded_lhs = NULL_TREE;
13836 opcode = MINUS_EXPR;
13837 rhs = integer_one_node;
13838 break;
13839
13840 case COMPOUND_EXPR:
13841 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
13842 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
13843 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
13844 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
13845 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
13846 (TREE_OPERAND (lhs, 1), 0), 0)))
13847 == BOOLEAN_TYPE)
13848 /* Undo effects of boolean_increment for post {in,de}crement. */
13849 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
13850 /* FALLTHRU */
13851 case MODIFY_EXPR:
13852 if (TREE_CODE (lhs) == MODIFY_EXPR
13853 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
13854 {
13855 /* Undo effects of boolean_increment. */
13856 if (integer_onep (TREE_OPERAND (lhs, 1)))
13857 {
13858 /* This is pre or post increment. */
13859 rhs = TREE_OPERAND (lhs, 1);
13860 lhs = TREE_OPERAND (lhs, 0);
13861 unfolded_lhs = NULL_TREE;
13862 opcode = NOP_EXPR;
13863 if (code == OMP_ATOMIC_CAPTURE_NEW
13864 && !structured_block
13865 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
13866 code = OMP_ATOMIC_CAPTURE_OLD;
13867 break;
13868 }
13869 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
13870 && TREE_OPERAND (lhs, 0)
13871 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
13872 {
13873 /* This is pre or post decrement. */
13874 rhs = TREE_OPERAND (lhs, 1);
13875 lhs = TREE_OPERAND (lhs, 0);
13876 unfolded_lhs = NULL_TREE;
13877 opcode = NOP_EXPR;
13878 if (code == OMP_ATOMIC_CAPTURE_NEW
13879 && !structured_block
13880 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
13881 code = OMP_ATOMIC_CAPTURE_OLD;
13882 break;
13883 }
13884 }
13885 /* FALLTHRU */
13886 default:
13887 if (!lvalue_p (unfolded_lhs))
13888 lhs = non_lvalue (lhs);
13889 switch (c_parser_peek_token (parser)->type)
13890 {
13891 case CPP_MULT_EQ:
13892 opcode = MULT_EXPR;
13893 break;
13894 case CPP_DIV_EQ:
13895 opcode = TRUNC_DIV_EXPR;
13896 break;
13897 case CPP_PLUS_EQ:
13898 opcode = PLUS_EXPR;
13899 break;
13900 case CPP_MINUS_EQ:
13901 opcode = MINUS_EXPR;
13902 break;
13903 case CPP_LSHIFT_EQ:
13904 opcode = LSHIFT_EXPR;
13905 break;
13906 case CPP_RSHIFT_EQ:
13907 opcode = RSHIFT_EXPR;
13908 break;
13909 case CPP_AND_EQ:
13910 opcode = BIT_AND_EXPR;
13911 break;
13912 case CPP_OR_EQ:
13913 opcode = BIT_IOR_EXPR;
13914 break;
13915 case CPP_XOR_EQ:
13916 opcode = BIT_XOR_EXPR;
13917 break;
13918 case CPP_EQ:
13919 c_parser_consume_token (parser);
13920 eloc = c_parser_peek_token (parser)->location;
13921 expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
13922 rhs1 = expr.value;
13923 switch (TREE_CODE (rhs1))
13924 {
13925 case MULT_EXPR:
13926 case TRUNC_DIV_EXPR:
13927 case RDIV_EXPR:
13928 case PLUS_EXPR:
13929 case MINUS_EXPR:
13930 case LSHIFT_EXPR:
13931 case RSHIFT_EXPR:
13932 case BIT_AND_EXPR:
13933 case BIT_IOR_EXPR:
13934 case BIT_XOR_EXPR:
13935 if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
13936 {
13937 opcode = TREE_CODE (rhs1);
13938 rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
13939 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
13940 goto stmt_done;
13941 }
13942 if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
13943 {
13944 opcode = TREE_CODE (rhs1);
13945 rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
13946 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
13947 swapped = !commutative_tree_code (opcode);
13948 goto stmt_done;
13949 }
13950 break;
13951 case ERROR_MARK:
13952 goto saw_error;
13953 default:
13954 break;
13955 }
13956 if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
13957 {
13958 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
13959 {
13960 code = OMP_ATOMIC_CAPTURE_OLD;
13961 v = lhs;
13962 lhs = NULL_TREE;
13963 expr = default_function_array_read_conversion (eloc, expr);
13964 unfolded_lhs1 = expr.value;
13965 lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
13966 rhs1 = NULL_TREE;
13967 c_parser_consume_token (parser);
13968 goto restart;
13969 }
13970 if (structured_block)
13971 {
13972 opcode = NOP_EXPR;
13973 expr = default_function_array_read_conversion (eloc, expr);
13974 rhs = c_fully_fold (expr.value, false, NULL);
13975 rhs1 = NULL_TREE;
13976 goto stmt_done;
13977 }
13978 }
13979 c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
13980 goto saw_error;
13981 default:
13982 c_parser_error (parser,
13983 "invalid operator for %<#pragma omp atomic%>");
13984 goto saw_error;
13985 }
13986
13987 /* Arrange to pass the location of the assignment operator to
13988 c_finish_omp_atomic. */
13989 loc = c_parser_peek_token (parser)->location;
13990 c_parser_consume_token (parser);
13991 eloc = c_parser_peek_token (parser)->location;
13992 expr = c_parser_expression (parser);
13993 expr = default_function_array_read_conversion (eloc, expr);
13994 rhs = expr.value;
13995 rhs = c_fully_fold (rhs, false, NULL);
13996 break;
13997 }
13998 stmt_done:
13999 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
14000 {
14001 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
14002 goto saw_error;
14003 v = c_parser_cast_expression (parser, NULL).value;
14004 non_lvalue_p = !lvalue_p (v);
14005 v = c_fully_fold (v, false, NULL);
14006 if (v == error_mark_node)
14007 goto saw_error;
14008 if (non_lvalue_p)
14009 v = non_lvalue (v);
14010 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
14011 goto saw_error;
14012 eloc = c_parser_peek_token (parser)->location;
14013 expr = c_parser_cast_expression (parser, NULL);
14014 lhs1 = expr.value;
14015 expr = default_function_array_read_conversion (eloc, expr);
14016 unfolded_lhs1 = expr.value;
14017 lhs1 = c_fully_fold (lhs1, false, NULL);
14018 if (lhs1 == error_mark_node)
14019 goto saw_error;
14020 if (!lvalue_p (unfolded_lhs1))
14021 lhs1 = non_lvalue (lhs1);
14022 }
14023 if (structured_block)
14024 {
14025 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14026 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
14027 }
14028 done:
14029 if (unfolded_lhs && unfolded_lhs1
14030 && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
14031 {
14032 error ("%<#pragma omp atomic capture%> uses two different "
14033 "expressions for memory");
14034 stmt = error_mark_node;
14035 }
14036 else
14037 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
14038 swapped, seq_cst);
14039 if (stmt != error_mark_node)
14040 add_stmt (stmt);
14041
14042 if (!structured_block)
14043 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14044 }
14045
14046
14047 /* OpenMP 2.5:
14048 # pragma omp barrier new-line
14049 */
14050
14051 static void
14052 c_parser_omp_barrier (c_parser *parser)
14053 {
14054 location_t loc = c_parser_peek_token (parser)->location;
14055 c_parser_consume_pragma (parser);
14056 c_parser_skip_to_pragma_eol (parser);
14057
14058 c_finish_omp_barrier (loc);
14059 }
14060
14061 /* OpenMP 2.5:
14062 # pragma omp critical [(name)] new-line
14063 structured-block
14064
14065 OpenMP 4.5:
14066 # pragma omp critical [(name) [hint(expression)]] new-line
14067
14068 LOC is the location of the #pragma itself. */
14069
14070 #define OMP_CRITICAL_CLAUSE_MASK \
14071 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14072
14073 static tree
14074 c_parser_omp_critical (location_t loc, c_parser *parser)
14075 {
14076 tree stmt, name = NULL_TREE, clauses = NULL_TREE;
14077
14078 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14079 {
14080 c_parser_consume_token (parser);
14081 if (c_parser_next_token_is (parser, CPP_NAME))
14082 {
14083 name = c_parser_peek_token (parser)->value;
14084 c_parser_consume_token (parser);
14085 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14086 }
14087 else
14088 c_parser_error (parser, "expected identifier");
14089
14090 clauses = c_parser_omp_all_clauses (parser,
14091 OMP_CRITICAL_CLAUSE_MASK,
14092 "#pragma omp critical");
14093 }
14094 else
14095 {
14096 if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14097 c_parser_error (parser, "expected %<(%> or end of line");
14098 c_parser_skip_to_pragma_eol (parser);
14099 }
14100
14101 stmt = c_parser_omp_structured_block (parser);
14102 return c_finish_omp_critical (loc, stmt, name, clauses);
14103 }
14104
14105 /* OpenMP 2.5:
14106 # pragma omp flush flush-vars[opt] new-line
14107
14108 flush-vars:
14109 ( variable-list ) */
14110
14111 static void
14112 c_parser_omp_flush (c_parser *parser)
14113 {
14114 location_t loc = c_parser_peek_token (parser)->location;
14115 c_parser_consume_pragma (parser);
14116 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14117 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
14118 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14119 c_parser_error (parser, "expected %<(%> or end of line");
14120 c_parser_skip_to_pragma_eol (parser);
14121
14122 c_finish_omp_flush (loc);
14123 }
14124
14125 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14126 The real trick here is to determine the loop control variable early
14127 so that we can push a new decl if necessary to make it private.
14128 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14129 respectively. */
14130
14131 static tree
14132 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
14133 tree clauses, tree *cclauses)
14134 {
14135 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
14136 tree declv, condv, incrv, initv, ret = NULL_TREE;
14137 tree pre_body = NULL_TREE, this_pre_body;
14138 tree ordered_cl = NULL_TREE;
14139 bool fail = false, open_brace_parsed = false;
14140 int i, collapse = 1, ordered = 0, count, nbraces = 0;
14141 location_t for_loc;
14142 vec<tree, va_gc> *for_block = make_tree_vector ();
14143
14144 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
14145 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
14146 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
14147 else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
14148 && OMP_CLAUSE_ORDERED_EXPR (cl))
14149 {
14150 ordered_cl = cl;
14151 ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl));
14152 }
14153
14154 if (ordered && ordered < collapse)
14155 {
14156 error_at (OMP_CLAUSE_LOCATION (ordered_cl),
14157 "%<ordered%> clause parameter is less than %<collapse%>");
14158 OMP_CLAUSE_ORDERED_EXPR (ordered_cl)
14159 = build_int_cst (NULL_TREE, collapse);
14160 ordered = collapse;
14161 }
14162 if (ordered)
14163 {
14164 for (tree *pc = &clauses; *pc; )
14165 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR)
14166 {
14167 error_at (OMP_CLAUSE_LOCATION (*pc),
14168 "%<linear%> clause may not be specified together "
14169 "with %<ordered%> clause with a parameter");
14170 *pc = OMP_CLAUSE_CHAIN (*pc);
14171 }
14172 else
14173 pc = &OMP_CLAUSE_CHAIN (*pc);
14174 }
14175
14176 gcc_assert (collapse >= 1 && ordered >= 0);
14177 count = ordered ? ordered : collapse;
14178
14179 declv = make_tree_vec (count);
14180 initv = make_tree_vec (count);
14181 condv = make_tree_vec (count);
14182 incrv = make_tree_vec (count);
14183
14184 if (code != CILK_FOR
14185 && !c_parser_next_token_is_keyword (parser, RID_FOR))
14186 {
14187 c_parser_error (parser, "for statement expected");
14188 return NULL;
14189 }
14190 if (code == CILK_FOR
14191 && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR))
14192 {
14193 c_parser_error (parser, "_Cilk_for statement expected");
14194 return NULL;
14195 }
14196 for_loc = c_parser_peek_token (parser)->location;
14197 c_parser_consume_token (parser);
14198
14199 for (i = 0; i < count; i++)
14200 {
14201 int bracecount = 0;
14202
14203 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14204 goto pop_scopes;
14205
14206 /* Parse the initialization declaration or expression. */
14207 if (c_parser_next_tokens_start_declaration (parser))
14208 {
14209 if (i > 0)
14210 vec_safe_push (for_block, c_begin_compound_stmt (true));
14211 this_pre_body = push_stmt_list ();
14212 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
14213 NULL, vNULL);
14214 if (this_pre_body)
14215 {
14216 this_pre_body = pop_stmt_list (this_pre_body);
14217 if (pre_body)
14218 {
14219 tree t = pre_body;
14220 pre_body = push_stmt_list ();
14221 add_stmt (t);
14222 add_stmt (this_pre_body);
14223 pre_body = pop_stmt_list (pre_body);
14224 }
14225 else
14226 pre_body = this_pre_body;
14227 }
14228 decl = check_for_loop_decls (for_loc, flag_isoc99);
14229 if (decl == NULL)
14230 goto error_init;
14231 if (DECL_INITIAL (decl) == error_mark_node)
14232 decl = error_mark_node;
14233 init = decl;
14234 }
14235 else if (c_parser_next_token_is (parser, CPP_NAME)
14236 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
14237 {
14238 struct c_expr decl_exp;
14239 struct c_expr init_exp;
14240 location_t init_loc;
14241
14242 decl_exp = c_parser_postfix_expression (parser);
14243 decl = decl_exp.value;
14244
14245 c_parser_require (parser, CPP_EQ, "expected %<=%>");
14246
14247 init_loc = c_parser_peek_token (parser)->location;
14248 init_exp = c_parser_expr_no_commas (parser, NULL);
14249 init_exp = default_function_array_read_conversion (init_loc,
14250 init_exp);
14251 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
14252 NOP_EXPR, init_loc, init_exp.value,
14253 init_exp.original_type);
14254 init = c_process_expr_stmt (init_loc, init);
14255
14256 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14257 }
14258 else
14259 {
14260 error_init:
14261 c_parser_error (parser,
14262 "expected iteration declaration or initialization");
14263 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
14264 "expected %<)%>");
14265 fail = true;
14266 goto parse_next;
14267 }
14268
14269 /* Parse the loop condition. */
14270 cond = NULL_TREE;
14271 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
14272 {
14273 location_t cond_loc = c_parser_peek_token (parser)->location;
14274 struct c_expr cond_expr
14275 = c_parser_binary_expression (parser, NULL, NULL_TREE);
14276
14277 cond = cond_expr.value;
14278 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
14279 cond = c_fully_fold (cond, false, NULL);
14280 switch (cond_expr.original_code)
14281 {
14282 case GT_EXPR:
14283 case GE_EXPR:
14284 case LT_EXPR:
14285 case LE_EXPR:
14286 break;
14287 case NE_EXPR:
14288 if (code == CILK_SIMD || code == CILK_FOR)
14289 break;
14290 /* FALLTHRU. */
14291 default:
14292 /* Can't be cond = error_mark_node, because we want to preserve
14293 the location until c_finish_omp_for. */
14294 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
14295 break;
14296 }
14297 protected_set_expr_location (cond, cond_loc);
14298 }
14299 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14300
14301 /* Parse the increment expression. */
14302 incr = NULL_TREE;
14303 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
14304 {
14305 location_t incr_loc = c_parser_peek_token (parser)->location;
14306
14307 incr = c_process_expr_stmt (incr_loc,
14308 c_parser_expression (parser).value);
14309 }
14310 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14311
14312 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
14313 fail = true;
14314 else
14315 {
14316 TREE_VEC_ELT (declv, i) = decl;
14317 TREE_VEC_ELT (initv, i) = init;
14318 TREE_VEC_ELT (condv, i) = cond;
14319 TREE_VEC_ELT (incrv, i) = incr;
14320 }
14321
14322 parse_next:
14323 if (i == count - 1)
14324 break;
14325
14326 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
14327 in between the collapsed for loops to be still considered perfectly
14328 nested. Hopefully the final version clarifies this.
14329 For now handle (multiple) {'s and empty statements. */
14330 do
14331 {
14332 if (c_parser_next_token_is_keyword (parser, RID_FOR))
14333 {
14334 c_parser_consume_token (parser);
14335 break;
14336 }
14337 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
14338 {
14339 c_parser_consume_token (parser);
14340 bracecount++;
14341 }
14342 else if (bracecount
14343 && c_parser_next_token_is (parser, CPP_SEMICOLON))
14344 c_parser_consume_token (parser);
14345 else
14346 {
14347 c_parser_error (parser, "not enough perfectly nested loops");
14348 if (bracecount)
14349 {
14350 open_brace_parsed = true;
14351 bracecount--;
14352 }
14353 fail = true;
14354 count = 0;
14355 break;
14356 }
14357 }
14358 while (1);
14359
14360 nbraces += bracecount;
14361 }
14362
14363 save_break = c_break_label;
14364 if (code == CILK_SIMD)
14365 c_break_label = build_int_cst (size_type_node, 2);
14366 else
14367 c_break_label = size_one_node;
14368 save_cont = c_cont_label;
14369 c_cont_label = NULL_TREE;
14370 body = push_stmt_list ();
14371
14372 if (open_brace_parsed)
14373 {
14374 location_t here = c_parser_peek_token (parser)->location;
14375 stmt = c_begin_compound_stmt (true);
14376 c_parser_compound_statement_nostart (parser);
14377 add_stmt (c_end_compound_stmt (here, stmt, true));
14378 }
14379 else
14380 add_stmt (c_parser_c99_block_statement (parser));
14381 if (c_cont_label)
14382 {
14383 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
14384 SET_EXPR_LOCATION (t, loc);
14385 add_stmt (t);
14386 }
14387
14388 body = pop_stmt_list (body);
14389 c_break_label = save_break;
14390 c_cont_label = save_cont;
14391
14392 while (nbraces)
14393 {
14394 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
14395 {
14396 c_parser_consume_token (parser);
14397 nbraces--;
14398 }
14399 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
14400 c_parser_consume_token (parser);
14401 else
14402 {
14403 c_parser_error (parser, "collapsed loops not perfectly nested");
14404 while (nbraces)
14405 {
14406 location_t here = c_parser_peek_token (parser)->location;
14407 stmt = c_begin_compound_stmt (true);
14408 add_stmt (body);
14409 c_parser_compound_statement_nostart (parser);
14410 body = c_end_compound_stmt (here, stmt, true);
14411 nbraces--;
14412 }
14413 goto pop_scopes;
14414 }
14415 }
14416
14417 /* Only bother calling c_finish_omp_for if we haven't already generated
14418 an error from the initialization parsing. */
14419 if (!fail)
14420 {
14421 stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv,
14422 incrv, body, pre_body);
14423
14424 /* Check for iterators appearing in lb, b or incr expressions. */
14425 if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL))
14426 stmt = NULL_TREE;
14427
14428 if (stmt)
14429 {
14430 add_stmt (stmt);
14431
14432 if (cclauses != NULL
14433 && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
14434 {
14435 tree *c;
14436 for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
14437 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
14438 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
14439 c = &OMP_CLAUSE_CHAIN (*c);
14440 else
14441 {
14442 for (i = 0; i < count; i++)
14443 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
14444 break;
14445 if (i == count)
14446 c = &OMP_CLAUSE_CHAIN (*c);
14447 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
14448 {
14449 error_at (loc,
14450 "iteration variable %qD should not be firstprivate",
14451 OMP_CLAUSE_DECL (*c));
14452 *c = OMP_CLAUSE_CHAIN (*c);
14453 }
14454 else
14455 {
14456 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
14457 tree l = *c;
14458 *c = OMP_CLAUSE_CHAIN (*c);
14459 if (code == OMP_SIMD)
14460 {
14461 OMP_CLAUSE_CHAIN (l)
14462 = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
14463 cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
14464 }
14465 else
14466 {
14467 OMP_CLAUSE_CHAIN (l) = clauses;
14468 clauses = l;
14469 }
14470 }
14471 }
14472 }
14473 OMP_FOR_CLAUSES (stmt) = clauses;
14474 }
14475 ret = stmt;
14476 }
14477 pop_scopes:
14478 while (!for_block->is_empty ())
14479 {
14480 /* FIXME diagnostics: LOC below should be the actual location of
14481 this particular for block. We need to build a list of
14482 locations to go along with FOR_BLOCK. */
14483 stmt = c_end_compound_stmt (loc, for_block->pop (), true);
14484 add_stmt (stmt);
14485 }
14486 release_tree_vector (for_block);
14487 return ret;
14488 }
14489
14490 /* Helper function for OpenMP parsing, split clauses and call
14491 finish_omp_clauses on each of the set of clauses afterwards. */
14492
14493 static void
14494 omp_split_clauses (location_t loc, enum tree_code code,
14495 omp_clause_mask mask, tree clauses, tree *cclauses)
14496 {
14497 int i;
14498 c_omp_split_clauses (loc, code, mask, clauses, cclauses);
14499 for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
14500 if (cclauses[i])
14501 cclauses[i] = c_finish_omp_clauses (cclauses[i], true);
14502 }
14503
14504 /* OpenMP 4.0:
14505 #pragma omp simd simd-clause[optseq] new-line
14506 for-loop
14507
14508 LOC is the location of the #pragma token.
14509 */
14510
14511 #define OMP_SIMD_CLAUSE_MASK \
14512 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
14513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
14514 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14515 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
14516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14518 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14519 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
14520
14521 static tree
14522 c_parser_omp_simd (location_t loc, c_parser *parser,
14523 char *p_name, omp_clause_mask mask, tree *cclauses)
14524 {
14525 tree block, clauses, ret;
14526
14527 strcat (p_name, " simd");
14528 mask |= OMP_SIMD_CLAUSE_MASK;
14529
14530 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
14531 if (cclauses)
14532 {
14533 omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
14534 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
14535 tree c = find_omp_clause (cclauses[C_OMP_CLAUSE_SPLIT_FOR],
14536 OMP_CLAUSE_ORDERED);
14537 if (c && OMP_CLAUSE_ORDERED_EXPR (c))
14538 {
14539 error_at (OMP_CLAUSE_LOCATION (c),
14540 "%<ordered%> clause with parameter may not be specified "
14541 "on %qs construct", p_name);
14542 OMP_CLAUSE_ORDERED_EXPR (c) = NULL_TREE;
14543 }
14544 }
14545
14546 block = c_begin_compound_stmt (true);
14547 ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses);
14548 block = c_end_compound_stmt (loc, block, true);
14549 add_stmt (block);
14550
14551 return ret;
14552 }
14553
14554 /* OpenMP 2.5:
14555 #pragma omp for for-clause[optseq] new-line
14556 for-loop
14557
14558 OpenMP 4.0:
14559 #pragma omp for simd for-simd-clause[optseq] new-line
14560 for-loop
14561
14562 LOC is the location of the #pragma token.
14563 */
14564
14565 #define OMP_FOR_CLAUSE_MASK \
14566 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14568 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14569 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14570 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14571 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
14572 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
14573 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
14574 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14575
14576 static tree
14577 c_parser_omp_for (location_t loc, c_parser *parser,
14578 char *p_name, omp_clause_mask mask, tree *cclauses)
14579 {
14580 tree block, clauses, ret;
14581
14582 strcat (p_name, " for");
14583 mask |= OMP_FOR_CLAUSE_MASK;
14584 if (cclauses)
14585 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
14586 /* Composite distribute parallel for{, simd} disallows ordered clause. */
14587 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
14588 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
14589
14590 if (c_parser_next_token_is (parser, CPP_NAME))
14591 {
14592 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14593
14594 if (strcmp (p, "simd") == 0)
14595 {
14596 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
14597 if (cclauses == NULL)
14598 cclauses = cclauses_buf;
14599
14600 c_parser_consume_token (parser);
14601 if (!flag_openmp) /* flag_openmp_simd */
14602 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
14603 block = c_begin_compound_stmt (true);
14604 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
14605 block = c_end_compound_stmt (loc, block, true);
14606 if (ret == NULL_TREE)
14607 return ret;
14608 ret = make_node (OMP_FOR);
14609 TREE_TYPE (ret) = void_type_node;
14610 OMP_FOR_BODY (ret) = block;
14611 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
14612 SET_EXPR_LOCATION (ret, loc);
14613 add_stmt (ret);
14614 return ret;
14615 }
14616 }
14617 if (!flag_openmp) /* flag_openmp_simd */
14618 {
14619 c_parser_skip_to_pragma_eol (parser, false);
14620 return NULL_TREE;
14621 }
14622
14623 /* Composite distribute parallel for disallows linear clause. */
14624 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
14625 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR);
14626
14627 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
14628 if (cclauses)
14629 {
14630 omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
14631 clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
14632 }
14633
14634 block = c_begin_compound_stmt (true);
14635 ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses);
14636 block = c_end_compound_stmt (loc, block, true);
14637 add_stmt (block);
14638
14639 return ret;
14640 }
14641
14642 /* OpenMP 2.5:
14643 # pragma omp master new-line
14644 structured-block
14645
14646 LOC is the location of the #pragma token.
14647 */
14648
14649 static tree
14650 c_parser_omp_master (location_t loc, c_parser *parser)
14651 {
14652 c_parser_skip_to_pragma_eol (parser);
14653 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
14654 }
14655
14656 /* OpenMP 2.5:
14657 # pragma omp ordered new-line
14658 structured-block
14659
14660 OpenMP 4.5:
14661 # pragma omp ordered ordered-clauses new-line
14662 structured-block
14663
14664 # pragma omp ordered depend-clauses new-line */
14665
14666 #define OMP_ORDERED_CLAUSE_MASK \
14667 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
14668 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
14669
14670 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
14671 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
14672
14673 static bool
14674 c_parser_omp_ordered (c_parser *parser, enum pragma_context context)
14675 {
14676 location_t loc = c_parser_peek_token (parser)->location;
14677 c_parser_consume_pragma (parser);
14678
14679 if (context != pragma_stmt && context != pragma_compound)
14680 {
14681 c_parser_error (parser, "expected declaration specifiers");
14682 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14683 return false;
14684 }
14685
14686 if (c_parser_next_token_is (parser, CPP_NAME))
14687 {
14688 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14689
14690 if (!strcmp ("depend", p))
14691 {
14692 if (context == pragma_stmt)
14693 {
14694 error_at (loc,
14695 "%<#pragma omp ordered%> with %<depend> clause may "
14696 "only be used in compound statements");
14697 c_parser_skip_to_pragma_eol (parser);
14698 return false;
14699 }
14700
14701 tree clauses
14702 = c_parser_omp_all_clauses (parser,
14703 OMP_ORDERED_DEPEND_CLAUSE_MASK,
14704 "#pragma omp ordered");
14705 c_finish_omp_ordered (loc, clauses, NULL_TREE);
14706 return false;
14707 }
14708 }
14709
14710 tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK,
14711 "#pragma omp ordered");
14712 c_finish_omp_ordered (loc, clauses,
14713 c_parser_omp_structured_block (parser));
14714 return true;
14715 }
14716
14717 /* OpenMP 2.5:
14718
14719 section-scope:
14720 { section-sequence }
14721
14722 section-sequence:
14723 section-directive[opt] structured-block
14724 section-sequence section-directive structured-block
14725
14726 SECTIONS_LOC is the location of the #pragma omp sections. */
14727
14728 static tree
14729 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
14730 {
14731 tree stmt, substmt;
14732 bool error_suppress = false;
14733 location_t loc;
14734
14735 loc = c_parser_peek_token (parser)->location;
14736 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
14737 {
14738 /* Avoid skipping until the end of the block. */
14739 parser->error = false;
14740 return NULL_TREE;
14741 }
14742
14743 stmt = push_stmt_list ();
14744
14745 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
14746 {
14747 substmt = c_parser_omp_structured_block (parser);
14748 substmt = build1 (OMP_SECTION, void_type_node, substmt);
14749 SET_EXPR_LOCATION (substmt, loc);
14750 add_stmt (substmt);
14751 }
14752
14753 while (1)
14754 {
14755 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
14756 break;
14757 if (c_parser_next_token_is (parser, CPP_EOF))
14758 break;
14759
14760 loc = c_parser_peek_token (parser)->location;
14761 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
14762 {
14763 c_parser_consume_pragma (parser);
14764 c_parser_skip_to_pragma_eol (parser);
14765 error_suppress = false;
14766 }
14767 else if (!error_suppress)
14768 {
14769 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
14770 error_suppress = true;
14771 }
14772
14773 substmt = c_parser_omp_structured_block (parser);
14774 substmt = build1 (OMP_SECTION, void_type_node, substmt);
14775 SET_EXPR_LOCATION (substmt, loc);
14776 add_stmt (substmt);
14777 }
14778 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
14779 "expected %<#pragma omp section%> or %<}%>");
14780
14781 substmt = pop_stmt_list (stmt);
14782
14783 stmt = make_node (OMP_SECTIONS);
14784 SET_EXPR_LOCATION (stmt, sections_loc);
14785 TREE_TYPE (stmt) = void_type_node;
14786 OMP_SECTIONS_BODY (stmt) = substmt;
14787
14788 return add_stmt (stmt);
14789 }
14790
14791 /* OpenMP 2.5:
14792 # pragma omp sections sections-clause[optseq] newline
14793 sections-scope
14794
14795 LOC is the location of the #pragma token.
14796 */
14797
14798 #define OMP_SECTIONS_CLAUSE_MASK \
14799 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14800 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14804
14805 static tree
14806 c_parser_omp_sections (location_t loc, c_parser *parser,
14807 char *p_name, omp_clause_mask mask, tree *cclauses)
14808 {
14809 tree block, clauses, ret;
14810
14811 strcat (p_name, " sections");
14812 mask |= OMP_SECTIONS_CLAUSE_MASK;
14813 if (cclauses)
14814 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
14815
14816 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
14817 if (cclauses)
14818 {
14819 omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
14820 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
14821 }
14822
14823 block = c_begin_compound_stmt (true);
14824 ret = c_parser_omp_sections_scope (loc, parser);
14825 if (ret)
14826 OMP_SECTIONS_CLAUSES (ret) = clauses;
14827 block = c_end_compound_stmt (loc, block, true);
14828 add_stmt (block);
14829
14830 return ret;
14831 }
14832
14833 /* OpenMP 2.5:
14834 # pragma omp parallel parallel-clause[optseq] new-line
14835 structured-block
14836 # pragma omp parallel for parallel-for-clause[optseq] new-line
14837 structured-block
14838 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
14839 structured-block
14840
14841 OpenMP 4.0:
14842 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
14843 structured-block
14844
14845 LOC is the location of the #pragma token.
14846 */
14847
14848 #define OMP_PARALLEL_CLAUSE_MASK \
14849 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
14850 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14851 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14852 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
14853 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14854 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
14855 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14856 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
14857 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
14858
14859 static tree
14860 c_parser_omp_parallel (location_t loc, c_parser *parser,
14861 char *p_name, omp_clause_mask mask, tree *cclauses)
14862 {
14863 tree stmt, clauses, block;
14864
14865 strcat (p_name, " parallel");
14866 mask |= OMP_PARALLEL_CLAUSE_MASK;
14867 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
14868 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0
14869 && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0)
14870 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN);
14871
14872 if (c_parser_next_token_is_keyword (parser, RID_FOR))
14873 {
14874 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
14875 if (cclauses == NULL)
14876 cclauses = cclauses_buf;
14877
14878 c_parser_consume_token (parser);
14879 if (!flag_openmp) /* flag_openmp_simd */
14880 return c_parser_omp_for (loc, parser, p_name, mask, cclauses);
14881 block = c_begin_omp_parallel ();
14882 tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses);
14883 stmt
14884 = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
14885 block);
14886 if (ret == NULL_TREE)
14887 return ret;
14888 OMP_PARALLEL_COMBINED (stmt) = 1;
14889 return stmt;
14890 }
14891 /* When combined with distribute, parallel has to be followed by for.
14892 #pragma omp target parallel is allowed though. */
14893 else if (cclauses
14894 && (mask & (OMP_CLAUSE_MASK_1
14895 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
14896 {
14897 error_at (loc, "expected %<for%> after %qs", p_name);
14898 c_parser_skip_to_pragma_eol (parser);
14899 return NULL_TREE;
14900 }
14901 else if (!flag_openmp) /* flag_openmp_simd */
14902 {
14903 c_parser_skip_to_pragma_eol (parser, false);
14904 return NULL_TREE;
14905 }
14906 else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME))
14907 {
14908 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14909 if (strcmp (p, "sections") == 0)
14910 {
14911 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
14912 if (cclauses == NULL)
14913 cclauses = cclauses_buf;
14914
14915 c_parser_consume_token (parser);
14916 block = c_begin_omp_parallel ();
14917 c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
14918 stmt = c_finish_omp_parallel (loc,
14919 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
14920 block);
14921 OMP_PARALLEL_COMBINED (stmt) = 1;
14922 return stmt;
14923 }
14924 }
14925
14926 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
14927 if (cclauses)
14928 {
14929 omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses);
14930 clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
14931 }
14932
14933 block = c_begin_omp_parallel ();
14934 c_parser_statement (parser);
14935 stmt = c_finish_omp_parallel (loc, clauses, block);
14936
14937 return stmt;
14938 }
14939
14940 /* OpenMP 2.5:
14941 # pragma omp single single-clause[optseq] new-line
14942 structured-block
14943
14944 LOC is the location of the #pragma.
14945 */
14946
14947 #define OMP_SINGLE_CLAUSE_MASK \
14948 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14949 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14950 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
14951 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14952
14953 static tree
14954 c_parser_omp_single (location_t loc, c_parser *parser)
14955 {
14956 tree stmt = make_node (OMP_SINGLE);
14957 SET_EXPR_LOCATION (stmt, loc);
14958 TREE_TYPE (stmt) = void_type_node;
14959
14960 OMP_SINGLE_CLAUSES (stmt)
14961 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
14962 "#pragma omp single");
14963 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
14964
14965 return add_stmt (stmt);
14966 }
14967
14968 /* OpenMP 3.0:
14969 # pragma omp task task-clause[optseq] new-line
14970
14971 LOC is the location of the #pragma.
14972 */
14973
14974 #define OMP_TASK_CLAUSE_MASK \
14975 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
14976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
14977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
14978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14981 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
14982 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
14983 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
14984 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
14985
14986 static tree
14987 c_parser_omp_task (location_t loc, c_parser *parser)
14988 {
14989 tree clauses, block;
14990
14991 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
14992 "#pragma omp task");
14993
14994 block = c_begin_omp_task ();
14995 c_parser_statement (parser);
14996 return c_finish_omp_task (loc, clauses, block);
14997 }
14998
14999 /* OpenMP 3.0:
15000 # pragma omp taskwait new-line
15001 */
15002
15003 static void
15004 c_parser_omp_taskwait (c_parser *parser)
15005 {
15006 location_t loc = c_parser_peek_token (parser)->location;
15007 c_parser_consume_pragma (parser);
15008 c_parser_skip_to_pragma_eol (parser);
15009
15010 c_finish_omp_taskwait (loc);
15011 }
15012
15013 /* OpenMP 3.1:
15014 # pragma omp taskyield new-line
15015 */
15016
15017 static void
15018 c_parser_omp_taskyield (c_parser *parser)
15019 {
15020 location_t loc = c_parser_peek_token (parser)->location;
15021 c_parser_consume_pragma (parser);
15022 c_parser_skip_to_pragma_eol (parser);
15023
15024 c_finish_omp_taskyield (loc);
15025 }
15026
15027 /* OpenMP 4.0:
15028 # pragma omp taskgroup new-line
15029 */
15030
15031 static tree
15032 c_parser_omp_taskgroup (c_parser *parser)
15033 {
15034 location_t loc = c_parser_peek_token (parser)->location;
15035 c_parser_skip_to_pragma_eol (parser);
15036 return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser));
15037 }
15038
15039 /* OpenMP 4.0:
15040 # pragma omp cancel cancel-clause[optseq] new-line
15041
15042 LOC is the location of the #pragma.
15043 */
15044
15045 #define OMP_CANCEL_CLAUSE_MASK \
15046 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
15050 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15051
15052 static void
15053 c_parser_omp_cancel (c_parser *parser)
15054 {
15055 location_t loc = c_parser_peek_token (parser)->location;
15056
15057 c_parser_consume_pragma (parser);
15058 tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
15059 "#pragma omp cancel");
15060
15061 c_finish_omp_cancel (loc, clauses);
15062 }
15063
15064 /* OpenMP 4.0:
15065 # pragma omp cancellation point cancelpt-clause[optseq] new-line
15066
15067 LOC is the location of the #pragma.
15068 */
15069
15070 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
15071 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15075
15076 static void
15077 c_parser_omp_cancellation_point (c_parser *parser)
15078 {
15079 location_t loc = c_parser_peek_token (parser)->location;
15080 tree clauses;
15081 bool point_seen = false;
15082
15083 c_parser_consume_pragma (parser);
15084 if (c_parser_next_token_is (parser, CPP_NAME))
15085 {
15086 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15087 if (strcmp (p, "point") == 0)
15088 {
15089 c_parser_consume_token (parser);
15090 point_seen = true;
15091 }
15092 }
15093 if (!point_seen)
15094 {
15095 c_parser_error (parser, "expected %<point%>");
15096 c_parser_skip_to_pragma_eol (parser);
15097 return;
15098 }
15099
15100 clauses
15101 = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
15102 "#pragma omp cancellation point");
15103
15104 c_finish_omp_cancellation_point (loc, clauses);
15105 }
15106
15107 /* OpenMP 4.0:
15108 #pragma omp distribute distribute-clause[optseq] new-line
15109 for-loop */
15110
15111 #define OMP_DISTRIBUTE_CLAUSE_MASK \
15112 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15113 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15114 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15115 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15116 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15117
15118 static tree
15119 c_parser_omp_distribute (location_t loc, c_parser *parser,
15120 char *p_name, omp_clause_mask mask, tree *cclauses)
15121 {
15122 tree clauses, block, ret;
15123
15124 strcat (p_name, " distribute");
15125 mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
15126
15127 if (c_parser_next_token_is (parser, CPP_NAME))
15128 {
15129 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15130 bool simd = false;
15131 bool parallel = false;
15132
15133 if (strcmp (p, "simd") == 0)
15134 simd = true;
15135 else
15136 parallel = strcmp (p, "parallel") == 0;
15137 if (parallel || simd)
15138 {
15139 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
15140 if (cclauses == NULL)
15141 cclauses = cclauses_buf;
15142 c_parser_consume_token (parser);
15143 if (!flag_openmp) /* flag_openmp_simd */
15144 {
15145 if (simd)
15146 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
15147 else
15148 return c_parser_omp_parallel (loc, parser, p_name, mask,
15149 cclauses);
15150 }
15151 block = c_begin_compound_stmt (true);
15152 if (simd)
15153 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
15154 else
15155 ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses);
15156 block = c_end_compound_stmt (loc, block, true);
15157 if (ret == NULL)
15158 return ret;
15159 ret = make_node (OMP_DISTRIBUTE);
15160 TREE_TYPE (ret) = void_type_node;
15161 OMP_FOR_BODY (ret) = block;
15162 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
15163 SET_EXPR_LOCATION (ret, loc);
15164 add_stmt (ret);
15165 return ret;
15166 }
15167 }
15168 if (!flag_openmp) /* flag_openmp_simd */
15169 {
15170 c_parser_skip_to_pragma_eol (parser, false);
15171 return NULL_TREE;
15172 }
15173
15174 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15175 if (cclauses)
15176 {
15177 omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
15178 clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
15179 }
15180
15181 block = c_begin_compound_stmt (true);
15182 ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL);
15183 block = c_end_compound_stmt (loc, block, true);
15184 add_stmt (block);
15185
15186 return ret;
15187 }
15188
15189 /* OpenMP 4.0:
15190 # pragma omp teams teams-clause[optseq] new-line
15191 structured-block */
15192
15193 #define OMP_TEAMS_CLAUSE_MASK \
15194 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15195 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15196 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15197 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15198 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
15199 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
15200 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
15201
15202 static tree
15203 c_parser_omp_teams (location_t loc, c_parser *parser,
15204 char *p_name, omp_clause_mask mask, tree *cclauses)
15205 {
15206 tree clauses, block, ret;
15207
15208 strcat (p_name, " teams");
15209 mask |= OMP_TEAMS_CLAUSE_MASK;
15210
15211 if (c_parser_next_token_is (parser, CPP_NAME))
15212 {
15213 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15214 if (strcmp (p, "distribute") == 0)
15215 {
15216 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
15217 if (cclauses == NULL)
15218 cclauses = cclauses_buf;
15219
15220 c_parser_consume_token (parser);
15221 if (!flag_openmp) /* flag_openmp_simd */
15222 return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
15223 block = c_begin_compound_stmt (true);
15224 ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
15225 block = c_end_compound_stmt (loc, block, true);
15226 if (ret == NULL)
15227 return ret;
15228 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
15229 ret = make_node (OMP_TEAMS);
15230 TREE_TYPE (ret) = void_type_node;
15231 OMP_TEAMS_CLAUSES (ret) = clauses;
15232 OMP_TEAMS_BODY (ret) = block;
15233 OMP_TEAMS_COMBINED (ret) = 1;
15234 return add_stmt (ret);
15235 }
15236 }
15237 if (!flag_openmp) /* flag_openmp_simd */
15238 {
15239 c_parser_skip_to_pragma_eol (parser, false);
15240 return NULL_TREE;
15241 }
15242
15243 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15244 if (cclauses)
15245 {
15246 omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
15247 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
15248 }
15249
15250 tree stmt = make_node (OMP_TEAMS);
15251 TREE_TYPE (stmt) = void_type_node;
15252 OMP_TEAMS_CLAUSES (stmt) = clauses;
15253 OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser);
15254
15255 return add_stmt (stmt);
15256 }
15257
15258 /* OpenMP 4.0:
15259 # pragma omp target data target-data-clause[optseq] new-line
15260 structured-block */
15261
15262 #define OMP_TARGET_DATA_CLAUSE_MASK \
15263 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15264 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15265 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
15267
15268 static tree
15269 c_parser_omp_target_data (location_t loc, c_parser *parser)
15270 {
15271 tree clauses
15272 = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
15273 "#pragma omp target data");
15274 int map_seen = 0;
15275 for (tree *pc = &clauses; *pc;)
15276 {
15277 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
15278 switch (OMP_CLAUSE_MAP_KIND (*pc))
15279 {
15280 case GOMP_MAP_TO:
15281 case GOMP_MAP_ALWAYS_TO:
15282 case GOMP_MAP_FROM:
15283 case GOMP_MAP_ALWAYS_FROM:
15284 case GOMP_MAP_TOFROM:
15285 case GOMP_MAP_ALWAYS_TOFROM:
15286 case GOMP_MAP_ALLOC:
15287 map_seen = 3;
15288 break;
15289 case GOMP_MAP_FIRSTPRIVATE_POINTER:
15290 case GOMP_MAP_ALWAYS_POINTER:
15291 break;
15292 default:
15293 map_seen |= 1;
15294 error_at (OMP_CLAUSE_LOCATION (*pc),
15295 "%<#pragma omp target data%> with map-type other "
15296 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
15297 "on %<map%> clause");
15298 *pc = OMP_CLAUSE_CHAIN (*pc);
15299 continue;
15300 }
15301 pc = &OMP_CLAUSE_CHAIN (*pc);
15302 }
15303
15304 if (map_seen != 3)
15305 {
15306 if (map_seen == 0)
15307 error_at (loc,
15308 "%<#pragma omp target data%> must contain at least "
15309 "one %<map%> clause");
15310 return NULL_TREE;
15311 }
15312
15313 tree stmt = make_node (OMP_TARGET_DATA);
15314 TREE_TYPE (stmt) = void_type_node;
15315 OMP_TARGET_DATA_CLAUSES (stmt) = clauses;
15316 keep_next_level ();
15317 tree block = c_begin_compound_stmt (true);
15318 add_stmt (c_parser_omp_structured_block (parser));
15319 OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
15320
15321 SET_EXPR_LOCATION (stmt, loc);
15322 return add_stmt (stmt);
15323 }
15324
15325 /* OpenMP 4.0:
15326 # pragma omp target update target-update-clause[optseq] new-line */
15327
15328 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
15329 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
15330 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
15331 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15332 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15333 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15334 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15335
15336 static bool
15337 c_parser_omp_target_update (location_t loc, c_parser *parser,
15338 enum pragma_context context)
15339 {
15340 if (context == pragma_stmt)
15341 {
15342 error_at (loc,
15343 "%<#pragma omp target update%> may only be "
15344 "used in compound statements");
15345 c_parser_skip_to_pragma_eol (parser);
15346 return false;
15347 }
15348
15349 tree clauses
15350 = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
15351 "#pragma omp target update");
15352 if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
15353 && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
15354 {
15355 error_at (loc,
15356 "%<#pragma omp target update%> must contain at least one "
15357 "%<from%> or %<to%> clauses");
15358 return false;
15359 }
15360
15361 tree stmt = make_node (OMP_TARGET_UPDATE);
15362 TREE_TYPE (stmt) = void_type_node;
15363 OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
15364 SET_EXPR_LOCATION (stmt, loc);
15365 add_stmt (stmt);
15366 return false;
15367 }
15368
15369 /* OpenMP 4.5:
15370 # pragma omp target enter data target-data-clause[optseq] new-line */
15371
15372 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
15373 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15374 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15375 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15376 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15377 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15378
15379 static tree
15380 c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
15381 enum pragma_context context)
15382 {
15383 bool data_seen = false;
15384 if (c_parser_next_token_is (parser, CPP_NAME))
15385 {
15386 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15387 if (strcmp (p, "data") == 0)
15388 {
15389 c_parser_consume_token (parser);
15390 data_seen = true;
15391 }
15392 }
15393 if (!data_seen)
15394 {
15395 c_parser_error (parser, "expected %<data%>");
15396 c_parser_skip_to_pragma_eol (parser);
15397 return NULL_TREE;
15398 }
15399
15400 if (context == pragma_stmt)
15401 {
15402 error_at (loc,
15403 "%<#pragma omp target enter data%> may only be "
15404 "used in compound statements");
15405 c_parser_skip_to_pragma_eol (parser);
15406 return NULL_TREE;
15407 }
15408
15409 tree clauses
15410 = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK,
15411 "#pragma omp target enter data");
15412 int map_seen = 0;
15413 for (tree *pc = &clauses; *pc;)
15414 {
15415 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
15416 switch (OMP_CLAUSE_MAP_KIND (*pc))
15417 {
15418 case GOMP_MAP_TO:
15419 case GOMP_MAP_ALWAYS_TO:
15420 case GOMP_MAP_ALLOC:
15421 map_seen = 3;
15422 break;
15423 case GOMP_MAP_FIRSTPRIVATE_POINTER:
15424 case GOMP_MAP_ALWAYS_POINTER:
15425 break;
15426 default:
15427 map_seen |= 1;
15428 error_at (OMP_CLAUSE_LOCATION (*pc),
15429 "%<#pragma omp target enter data%> with map-type other "
15430 "than %<to%> or %<alloc%> on %<map%> clause");
15431 *pc = OMP_CLAUSE_CHAIN (*pc);
15432 continue;
15433 }
15434 pc = &OMP_CLAUSE_CHAIN (*pc);
15435 }
15436
15437 if (map_seen != 3)
15438 {
15439 if (map_seen == 0)
15440 error_at (loc,
15441 "%<#pragma omp target enter data%> must contain at least "
15442 "one %<map%> clause");
15443 return NULL_TREE;
15444 }
15445
15446 tree stmt = make_node (OMP_TARGET_ENTER_DATA);
15447 TREE_TYPE (stmt) = void_type_node;
15448 OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses;
15449 SET_EXPR_LOCATION (stmt, loc);
15450 add_stmt (stmt);
15451 return stmt;
15452 }
15453
15454 /* OpenMP 4.5:
15455 # pragma omp target exit data target-data-clause[optseq] new-line */
15456
15457 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
15458 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15459 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15460 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15461 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15462 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15463
15464 static tree
15465 c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
15466 enum pragma_context context)
15467 {
15468 bool data_seen = false;
15469 if (c_parser_next_token_is (parser, CPP_NAME))
15470 {
15471 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15472 if (strcmp (p, "data") == 0)
15473 {
15474 c_parser_consume_token (parser);
15475 data_seen = true;
15476 }
15477 }
15478 if (!data_seen)
15479 {
15480 c_parser_error (parser, "expected %<data%>");
15481 c_parser_skip_to_pragma_eol (parser);
15482 return NULL_TREE;
15483 }
15484
15485 if (context == pragma_stmt)
15486 {
15487 error_at (loc,
15488 "%<#pragma omp target exit data%> may only be "
15489 "used in compound statements");
15490 c_parser_skip_to_pragma_eol (parser);
15491 return NULL_TREE;
15492 }
15493
15494 tree clauses
15495 = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK,
15496 "#pragma omp target exit data");
15497
15498 int map_seen = 0;
15499 for (tree *pc = &clauses; *pc;)
15500 {
15501 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
15502 switch (OMP_CLAUSE_MAP_KIND (*pc))
15503 {
15504 case GOMP_MAP_FROM:
15505 case GOMP_MAP_ALWAYS_FROM:
15506 case GOMP_MAP_RELEASE:
15507 case GOMP_MAP_DELETE:
15508 map_seen = 3;
15509 break;
15510 case GOMP_MAP_FIRSTPRIVATE_POINTER:
15511 case GOMP_MAP_ALWAYS_POINTER:
15512 break;
15513 default:
15514 map_seen |= 1;
15515 error_at (OMP_CLAUSE_LOCATION (*pc),
15516 "%<#pragma omp target exit data%> with map-type other "
15517 "than %<from%>, %<release> or %<delete%> on %<map%>"
15518 " clause");
15519 *pc = OMP_CLAUSE_CHAIN (*pc);
15520 continue;
15521 }
15522 pc = &OMP_CLAUSE_CHAIN (*pc);
15523 }
15524
15525 if (map_seen != 3)
15526 {
15527 if (map_seen == 0)
15528 error_at (loc,
15529 "%<#pragma omp target exit data%> must contain at least one "
15530 "%<map%> clause");
15531 return NULL_TREE;
15532 }
15533
15534 tree stmt = make_node (OMP_TARGET_EXIT_DATA);
15535 TREE_TYPE (stmt) = void_type_node;
15536 OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses;
15537 SET_EXPR_LOCATION (stmt, loc);
15538 add_stmt (stmt);
15539 return stmt;
15540 }
15541
15542 /* OpenMP 4.0:
15543 # pragma omp target target-clause[optseq] new-line
15544 structured-block */
15545
15546 #define OMP_TARGET_CLAUSE_MASK \
15547 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15548 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15549 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15551 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
15552 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15553 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15554 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
15555 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
15556
15557 static bool
15558 c_parser_omp_target (c_parser *parser, enum pragma_context context)
15559 {
15560 location_t loc = c_parser_peek_token (parser)->location;
15561 c_parser_consume_pragma (parser);
15562 tree *pc = NULL, stmt, block;
15563
15564 if (context != pragma_stmt && context != pragma_compound)
15565 {
15566 c_parser_error (parser, "expected declaration specifiers");
15567 c_parser_skip_to_pragma_eol (parser);
15568 return false;
15569 }
15570
15571 if (c_parser_next_token_is (parser, CPP_NAME))
15572 {
15573 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15574 enum tree_code ccode = ERROR_MARK;
15575
15576 if (strcmp (p, "teams") == 0)
15577 ccode = OMP_TEAMS;
15578 else if (strcmp (p, "parallel") == 0)
15579 ccode = OMP_PARALLEL;
15580 else if (strcmp (p, "simd") == 0)
15581 ccode = OMP_SIMD;
15582 if (ccode != ERROR_MARK)
15583 {
15584 tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
15585 char p_name[sizeof ("#pragma omp target teams distribute "
15586 "parallel for simd")];
15587
15588 c_parser_consume_token (parser);
15589 strcpy (p_name, "#pragma omp target");
15590 if (!flag_openmp) /* flag_openmp_simd */
15591 {
15592 tree stmt;
15593 switch (ccode)
15594 {
15595 case OMP_TEAMS:
15596 stmt = c_parser_omp_teams (loc, parser, p_name,
15597 OMP_TARGET_CLAUSE_MASK,
15598 cclauses);
15599 break;
15600 case OMP_PARALLEL:
15601 stmt = c_parser_omp_parallel (loc, parser, p_name,
15602 OMP_TARGET_CLAUSE_MASK,
15603 cclauses);
15604 break;
15605 case OMP_SIMD:
15606 stmt = c_parser_omp_simd (loc, parser, p_name,
15607 OMP_TARGET_CLAUSE_MASK,
15608 cclauses);
15609 break;
15610 default:
15611 gcc_unreachable ();
15612 }
15613 return stmt != NULL_TREE;
15614 }
15615 keep_next_level ();
15616 tree block = c_begin_compound_stmt (true), ret;
15617 switch (ccode)
15618 {
15619 case OMP_TEAMS:
15620 ret = c_parser_omp_teams (loc, parser, p_name,
15621 OMP_TARGET_CLAUSE_MASK, cclauses);
15622 break;
15623 case OMP_PARALLEL:
15624 ret = c_parser_omp_parallel (loc, parser, p_name,
15625 OMP_TARGET_CLAUSE_MASK, cclauses);
15626 break;
15627 case OMP_SIMD:
15628 ret = c_parser_omp_simd (loc, parser, p_name,
15629 OMP_TARGET_CLAUSE_MASK, cclauses);
15630 break;
15631 default:
15632 gcc_unreachable ();
15633 }
15634 block = c_end_compound_stmt (loc, block, true);
15635 if (ret == NULL_TREE)
15636 return false;
15637 if (ccode == OMP_TEAMS)
15638 {
15639 /* For combined target teams, ensure the num_teams and
15640 thread_limit clause expressions are evaluated on the host,
15641 before entering the target construct. */
15642 tree c;
15643 for (c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
15644 c; c = OMP_CLAUSE_CHAIN (c))
15645 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
15646 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT)
15647 && TREE_CODE (OMP_CLAUSE_OPERAND (c, 0)) != INTEGER_CST)
15648 {
15649 tree expr = OMP_CLAUSE_OPERAND (c, 0);
15650 tree tmp = create_tmp_var_raw (TREE_TYPE (expr));
15651 expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp,
15652 expr, NULL_TREE, NULL_TREE);
15653 add_stmt (expr);
15654 OMP_CLAUSE_OPERAND (c, 0) = expr;
15655 tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c),
15656 OMP_CLAUSE_FIRSTPRIVATE);
15657 OMP_CLAUSE_DECL (tc) = tmp;
15658 OMP_CLAUSE_CHAIN (tc)
15659 = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
15660 cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc;
15661 }
15662 }
15663 tree stmt = make_node (OMP_TARGET);
15664 TREE_TYPE (stmt) = void_type_node;
15665 OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
15666 OMP_TARGET_BODY (stmt) = block;
15667 OMP_TARGET_COMBINED (stmt) = 1;
15668 add_stmt (stmt);
15669 pc = &OMP_TARGET_CLAUSES (stmt);
15670 goto check_clauses;
15671 }
15672 else if (!flag_openmp) /* flag_openmp_simd */
15673 {
15674 c_parser_skip_to_pragma_eol (parser, false);
15675 return false;
15676 }
15677 else if (strcmp (p, "data") == 0)
15678 {
15679 c_parser_consume_token (parser);
15680 c_parser_omp_target_data (loc, parser);
15681 return true;
15682 }
15683 else if (strcmp (p, "enter") == 0)
15684 {
15685 c_parser_consume_token (parser);
15686 c_parser_omp_target_enter_data (loc, parser, context);
15687 return false;
15688 }
15689 else if (strcmp (p, "exit") == 0)
15690 {
15691 c_parser_consume_token (parser);
15692 c_parser_omp_target_exit_data (loc, parser, context);
15693 return false;
15694 }
15695 else if (strcmp (p, "update") == 0)
15696 {
15697 c_parser_consume_token (parser);
15698 return c_parser_omp_target_update (loc, parser, context);
15699 }
15700 }
15701
15702 stmt = make_node (OMP_TARGET);
15703 TREE_TYPE (stmt) = void_type_node;
15704
15705 OMP_TARGET_CLAUSES (stmt)
15706 = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
15707 "#pragma omp target");
15708 pc = &OMP_TARGET_CLAUSES (stmt);
15709 keep_next_level ();
15710 block = c_begin_compound_stmt (true);
15711 add_stmt (c_parser_omp_structured_block (parser));
15712 OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
15713
15714 SET_EXPR_LOCATION (stmt, loc);
15715 add_stmt (stmt);
15716
15717 check_clauses:
15718 while (*pc)
15719 {
15720 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
15721 switch (OMP_CLAUSE_MAP_KIND (*pc))
15722 {
15723 case GOMP_MAP_TO:
15724 case GOMP_MAP_ALWAYS_TO:
15725 case GOMP_MAP_FROM:
15726 case GOMP_MAP_ALWAYS_FROM:
15727 case GOMP_MAP_TOFROM:
15728 case GOMP_MAP_ALWAYS_TOFROM:
15729 case GOMP_MAP_ALLOC:
15730 case GOMP_MAP_FIRSTPRIVATE_POINTER:
15731 case GOMP_MAP_ALWAYS_POINTER:
15732 break;
15733 default:
15734 error_at (OMP_CLAUSE_LOCATION (*pc),
15735 "%<#pragma omp target%> with map-type other "
15736 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
15737 "on %<map%> clause");
15738 *pc = OMP_CLAUSE_CHAIN (*pc);
15739 continue;
15740 }
15741 pc = &OMP_CLAUSE_CHAIN (*pc);
15742 }
15743 return true;
15744 }
15745
15746 /* OpenMP 4.0:
15747 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
15748
15749 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
15750 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15753 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
15754 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
15755 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
15756
15757 static void
15758 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
15759 {
15760 vec<c_token> clauses = vNULL;
15761 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15762 {
15763 c_token *token = c_parser_peek_token (parser);
15764 if (token->type == CPP_EOF)
15765 {
15766 c_parser_skip_to_pragma_eol (parser);
15767 clauses.release ();
15768 return;
15769 }
15770 clauses.safe_push (*token);
15771 c_parser_consume_token (parser);
15772 }
15773 clauses.safe_push (*c_parser_peek_token (parser));
15774 c_parser_skip_to_pragma_eol (parser);
15775
15776 while (c_parser_next_token_is (parser, CPP_PRAGMA))
15777 {
15778 if (c_parser_peek_token (parser)->pragma_kind
15779 != PRAGMA_OMP_DECLARE_REDUCTION
15780 || c_parser_peek_2nd_token (parser)->type != CPP_NAME
15781 || strcmp (IDENTIFIER_POINTER
15782 (c_parser_peek_2nd_token (parser)->value),
15783 "simd") != 0)
15784 {
15785 c_parser_error (parser,
15786 "%<#pragma omp declare simd%> must be followed by "
15787 "function declaration or definition or another "
15788 "%<#pragma omp declare simd%>");
15789 clauses.release ();
15790 return;
15791 }
15792 c_parser_consume_pragma (parser);
15793 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15794 {
15795 c_token *token = c_parser_peek_token (parser);
15796 if (token->type == CPP_EOF)
15797 {
15798 c_parser_skip_to_pragma_eol (parser);
15799 clauses.release ();
15800 return;
15801 }
15802 clauses.safe_push (*token);
15803 c_parser_consume_token (parser);
15804 }
15805 clauses.safe_push (*c_parser_peek_token (parser));
15806 c_parser_skip_to_pragma_eol (parser);
15807 }
15808
15809 /* Make sure nothing tries to read past the end of the tokens. */
15810 c_token eof_token;
15811 memset (&eof_token, 0, sizeof (eof_token));
15812 eof_token.type = CPP_EOF;
15813 clauses.safe_push (eof_token);
15814 clauses.safe_push (eof_token);
15815
15816 switch (context)
15817 {
15818 case pragma_external:
15819 if (c_parser_next_token_is (parser, CPP_KEYWORD)
15820 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
15821 {
15822 int ext = disable_extension_diagnostics ();
15823 do
15824 c_parser_consume_token (parser);
15825 while (c_parser_next_token_is (parser, CPP_KEYWORD)
15826 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
15827 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
15828 NULL, clauses);
15829 restore_extension_diagnostics (ext);
15830 }
15831 else
15832 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
15833 NULL, clauses);
15834 break;
15835 case pragma_struct:
15836 case pragma_param:
15837 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
15838 "function declaration or definition");
15839 break;
15840 case pragma_compound:
15841 case pragma_stmt:
15842 if (c_parser_next_token_is (parser, CPP_KEYWORD)
15843 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
15844 {
15845 int ext = disable_extension_diagnostics ();
15846 do
15847 c_parser_consume_token (parser);
15848 while (c_parser_next_token_is (parser, CPP_KEYWORD)
15849 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
15850 if (c_parser_next_tokens_start_declaration (parser))
15851 {
15852 c_parser_declaration_or_fndef (parser, true, true, true, true,
15853 true, NULL, clauses);
15854 restore_extension_diagnostics (ext);
15855 break;
15856 }
15857 restore_extension_diagnostics (ext);
15858 }
15859 else if (c_parser_next_tokens_start_declaration (parser))
15860 {
15861 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
15862 NULL, clauses);
15863 break;
15864 }
15865 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
15866 "function declaration or definition");
15867 break;
15868 default:
15869 gcc_unreachable ();
15870 }
15871 clauses.release ();
15872 }
15873
15874 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
15875 and put that into "omp declare simd" attribute. */
15876
15877 static void
15878 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
15879 vec<c_token> clauses)
15880 {
15881 if (flag_cilkplus
15882 && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
15883 {
15884 error ("%<#pragma omp declare simd%> cannot be used in the same "
15885 "function marked as a Cilk Plus SIMD-enabled function");
15886 vec_free (parser->cilk_simd_fn_tokens);
15887 return;
15888 }
15889
15890 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
15891 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
15892 has already processed the tokens. */
15893 if (clauses.exists () && clauses[0].type == CPP_EOF)
15894 return;
15895 if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
15896 {
15897 error ("%<#pragma omp declare simd%> not immediately followed by "
15898 "a function declaration or definition");
15899 clauses[0].type = CPP_EOF;
15900 return;
15901 }
15902 if (clauses.exists () && clauses[0].type != CPP_NAME)
15903 {
15904 error_at (DECL_SOURCE_LOCATION (fndecl),
15905 "%<#pragma omp declare simd%> not immediately followed by "
15906 "a single function declaration or definition");
15907 clauses[0].type = CPP_EOF;
15908 return;
15909 }
15910
15911 if (parms == NULL_TREE)
15912 parms = DECL_ARGUMENTS (fndecl);
15913
15914 unsigned int tokens_avail = parser->tokens_avail;
15915 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
15916 bool is_cilkplus_cilk_simd_fn = false;
15917
15918 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
15919 {
15920 parser->tokens = parser->cilk_simd_fn_tokens->address ();
15921 parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens);
15922 is_cilkplus_cilk_simd_fn = true;
15923 }
15924 else
15925 {
15926 parser->tokens = clauses.address ();
15927 parser->tokens_avail = clauses.length ();
15928 }
15929
15930 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
15931 while (parser->tokens_avail > 3)
15932 {
15933 c_token *token = c_parser_peek_token (parser);
15934 if (!is_cilkplus_cilk_simd_fn)
15935 gcc_assert (token->type == CPP_NAME
15936 && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
15937 else
15938 gcc_assert (token->type == CPP_NAME
15939 && is_cilkplus_vector_p (token->value));
15940 c_parser_consume_token (parser);
15941 parser->in_pragma = true;
15942
15943 tree c = NULL_TREE;
15944 if (is_cilkplus_cilk_simd_fn)
15945 c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
15946 "SIMD-enabled functions attribute");
15947 else
15948 c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
15949 "#pragma omp declare simd");
15950 c = c_omp_declare_simd_clauses_to_numbers (parms, c);
15951 if (c != NULL_TREE)
15952 c = tree_cons (NULL_TREE, c, NULL_TREE);
15953 if (is_cilkplus_cilk_simd_fn)
15954 {
15955 tree k = build_tree_list (get_identifier ("cilk simd function"),
15956 NULL_TREE);
15957 TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
15958 DECL_ATTRIBUTES (fndecl) = k;
15959 }
15960 c = build_tree_list (get_identifier ("omp declare simd"), c);
15961 TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
15962 DECL_ATTRIBUTES (fndecl) = c;
15963 }
15964
15965 parser->tokens = &parser->tokens_buf[0];
15966 parser->tokens_avail = tokens_avail;
15967 if (clauses.exists ())
15968 clauses[0].type = CPP_PRAGMA;
15969
15970 if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens))
15971 vec_free (parser->cilk_simd_fn_tokens);
15972 }
15973
15974
15975 /* OpenMP 4.0:
15976 # pragma omp declare target new-line
15977 declarations and definitions
15978 # pragma omp end declare target new-line
15979
15980 OpenMP 4.5:
15981 # pragma omp declare target ( extended-list ) new-line
15982
15983 # pragma omp declare target declare-target-clauses[seq] new-line */
15984
15985 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
15986 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
15987 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
15988
15989 static void
15990 c_parser_omp_declare_target (c_parser *parser)
15991 {
15992 location_t loc = c_parser_peek_token (parser)->location;
15993 tree clauses = NULL_TREE;
15994 if (c_parser_next_token_is (parser, CPP_NAME))
15995 clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK,
15996 "#pragma omp declare target");
15997 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15998 {
15999 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
16000 clauses);
16001 clauses = c_finish_omp_clauses (clauses, true);
16002 c_parser_skip_to_pragma_eol (parser);
16003 }
16004 else
16005 {
16006 c_parser_skip_to_pragma_eol (parser);
16007 current_omp_declare_target_attribute++;
16008 return;
16009 }
16010 if (current_omp_declare_target_attribute)
16011 error_at (loc, "%<#pragma omp declare target%> with clauses in between "
16012 "%<#pragma omp declare target%> without clauses and "
16013 "%<#pragma omp end declare target%>");
16014 for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
16015 {
16016 tree t = OMP_CLAUSE_DECL (c), id;
16017 tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
16018 tree at2 = lookup_attribute ("omp declare target link",
16019 DECL_ATTRIBUTES (t));
16020 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
16021 {
16022 id = get_identifier ("omp declare target link");
16023 std::swap (at1, at2);
16024 }
16025 else
16026 id = get_identifier ("omp declare target");
16027 if (at2)
16028 {
16029 error_at (OMP_CLAUSE_LOCATION (c),
16030 "%qD specified both in declare target %<link%> and %<to%>"
16031 " clauses", t);
16032 continue;
16033 }
16034 if (!at1)
16035 {
16036 symtab_node *node = symtab_node::get (t);
16037 DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
16038 if (node != NULL)
16039 {
16040 node->offloadable = 1;
16041 #ifdef ENABLE_OFFLOADING
16042 g->have_offload = true;
16043 if (is_a <varpool_node *> (node))
16044 {
16045 vec_safe_push (offload_vars, t);
16046 node->force_output = 1;
16047 }
16048 #endif
16049 }
16050 }
16051 }
16052 }
16053
16054 static void
16055 c_parser_omp_end_declare_target (c_parser *parser)
16056 {
16057 location_t loc = c_parser_peek_token (parser)->location;
16058 c_parser_consume_pragma (parser);
16059 if (c_parser_next_token_is (parser, CPP_NAME)
16060 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
16061 "declare") == 0)
16062 {
16063 c_parser_consume_token (parser);
16064 if (c_parser_next_token_is (parser, CPP_NAME)
16065 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
16066 "target") == 0)
16067 c_parser_consume_token (parser);
16068 else
16069 {
16070 c_parser_error (parser, "expected %<target%>");
16071 c_parser_skip_to_pragma_eol (parser);
16072 return;
16073 }
16074 }
16075 else
16076 {
16077 c_parser_error (parser, "expected %<declare%>");
16078 c_parser_skip_to_pragma_eol (parser);
16079 return;
16080 }
16081 c_parser_skip_to_pragma_eol (parser);
16082 if (!current_omp_declare_target_attribute)
16083 error_at (loc, "%<#pragma omp end declare target%> without corresponding "
16084 "%<#pragma omp declare target%>");
16085 else
16086 current_omp_declare_target_attribute--;
16087 }
16088
16089
16090 /* OpenMP 4.0
16091 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16092 initializer-clause[opt] new-line
16093
16094 initializer-clause:
16095 initializer (omp_priv = initializer)
16096 initializer (function-name (argument-list)) */
16097
16098 static void
16099 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
16100 {
16101 unsigned int tokens_avail = 0, i;
16102 vec<tree> types = vNULL;
16103 vec<c_token> clauses = vNULL;
16104 enum tree_code reduc_code = ERROR_MARK;
16105 tree reduc_id = NULL_TREE;
16106 tree type;
16107 location_t rloc = c_parser_peek_token (parser)->location;
16108
16109 if (context == pragma_struct || context == pragma_param)
16110 {
16111 error ("%<#pragma omp declare reduction%> not at file or block scope");
16112 goto fail;
16113 }
16114
16115 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
16116 goto fail;
16117
16118 switch (c_parser_peek_token (parser)->type)
16119 {
16120 case CPP_PLUS:
16121 reduc_code = PLUS_EXPR;
16122 break;
16123 case CPP_MULT:
16124 reduc_code = MULT_EXPR;
16125 break;
16126 case CPP_MINUS:
16127 reduc_code = MINUS_EXPR;
16128 break;
16129 case CPP_AND:
16130 reduc_code = BIT_AND_EXPR;
16131 break;
16132 case CPP_XOR:
16133 reduc_code = BIT_XOR_EXPR;
16134 break;
16135 case CPP_OR:
16136 reduc_code = BIT_IOR_EXPR;
16137 break;
16138 case CPP_AND_AND:
16139 reduc_code = TRUTH_ANDIF_EXPR;
16140 break;
16141 case CPP_OR_OR:
16142 reduc_code = TRUTH_ORIF_EXPR;
16143 break;
16144 case CPP_NAME:
16145 const char *p;
16146 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16147 if (strcmp (p, "min") == 0)
16148 {
16149 reduc_code = MIN_EXPR;
16150 break;
16151 }
16152 if (strcmp (p, "max") == 0)
16153 {
16154 reduc_code = MAX_EXPR;
16155 break;
16156 }
16157 reduc_id = c_parser_peek_token (parser)->value;
16158 break;
16159 default:
16160 c_parser_error (parser,
16161 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
16162 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
16163 goto fail;
16164 }
16165
16166 tree orig_reduc_id, reduc_decl;
16167 orig_reduc_id = reduc_id;
16168 reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
16169 reduc_decl = c_omp_reduction_decl (reduc_id);
16170 c_parser_consume_token (parser);
16171
16172 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
16173 goto fail;
16174
16175 while (true)
16176 {
16177 location_t loc = c_parser_peek_token (parser)->location;
16178 struct c_type_name *ctype = c_parser_type_name (parser);
16179 if (ctype != NULL)
16180 {
16181 type = groktypename (ctype, NULL, NULL);
16182 if (type == error_mark_node)
16183 ;
16184 else if ((INTEGRAL_TYPE_P (type)
16185 || TREE_CODE (type) == REAL_TYPE
16186 || TREE_CODE (type) == COMPLEX_TYPE)
16187 && orig_reduc_id == NULL_TREE)
16188 error_at (loc, "predeclared arithmetic type in "
16189 "%<#pragma omp declare reduction%>");
16190 else if (TREE_CODE (type) == FUNCTION_TYPE
16191 || TREE_CODE (type) == ARRAY_TYPE)
16192 error_at (loc, "function or array type in "
16193 "%<#pragma omp declare reduction%>");
16194 else if (TYPE_QUALS_NO_ADDR_SPACE (type))
16195 error_at (loc, "const, volatile or restrict qualified type in "
16196 "%<#pragma omp declare reduction%>");
16197 else
16198 {
16199 tree t;
16200 for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
16201 if (comptypes (TREE_PURPOSE (t), type))
16202 {
16203 error_at (loc, "redeclaration of %qs "
16204 "%<#pragma omp declare reduction%> for "
16205 "type %qT",
16206 IDENTIFIER_POINTER (reduc_id)
16207 + sizeof ("omp declare reduction ") - 1,
16208 type);
16209 location_t ploc
16210 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
16211 0));
16212 error_at (ploc, "previous %<#pragma omp declare "
16213 "reduction%>");
16214 break;
16215 }
16216 if (t == NULL_TREE)
16217 types.safe_push (type);
16218 }
16219 if (c_parser_next_token_is (parser, CPP_COMMA))
16220 c_parser_consume_token (parser);
16221 else
16222 break;
16223 }
16224 else
16225 break;
16226 }
16227
16228 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
16229 || types.is_empty ())
16230 {
16231 fail:
16232 clauses.release ();
16233 types.release ();
16234 while (true)
16235 {
16236 c_token *token = c_parser_peek_token (parser);
16237 if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
16238 break;
16239 c_parser_consume_token (parser);
16240 }
16241 c_parser_skip_to_pragma_eol (parser);
16242 return;
16243 }
16244
16245 if (types.length () > 1)
16246 {
16247 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
16248 {
16249 c_token *token = c_parser_peek_token (parser);
16250 if (token->type == CPP_EOF)
16251 goto fail;
16252 clauses.safe_push (*token);
16253 c_parser_consume_token (parser);
16254 }
16255 clauses.safe_push (*c_parser_peek_token (parser));
16256 c_parser_skip_to_pragma_eol (parser);
16257
16258 /* Make sure nothing tries to read past the end of the tokens. */
16259 c_token eof_token;
16260 memset (&eof_token, 0, sizeof (eof_token));
16261 eof_token.type = CPP_EOF;
16262 clauses.safe_push (eof_token);
16263 clauses.safe_push (eof_token);
16264 }
16265
16266 int errs = errorcount;
16267 FOR_EACH_VEC_ELT (types, i, type)
16268 {
16269 tokens_avail = parser->tokens_avail;
16270 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
16271 if (!clauses.is_empty ())
16272 {
16273 parser->tokens = clauses.address ();
16274 parser->tokens_avail = clauses.length ();
16275 parser->in_pragma = true;
16276 }
16277
16278 bool nested = current_function_decl != NULL_TREE;
16279 if (nested)
16280 c_push_function_context ();
16281 tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
16282 reduc_id, default_function_type);
16283 current_function_decl = fndecl;
16284 allocate_struct_function (fndecl, true);
16285 push_scope ();
16286 tree stmt = push_stmt_list ();
16287 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
16288 warn about these. */
16289 tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
16290 get_identifier ("omp_out"), type);
16291 DECL_ARTIFICIAL (omp_out) = 1;
16292 DECL_CONTEXT (omp_out) = fndecl;
16293 pushdecl (omp_out);
16294 tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
16295 get_identifier ("omp_in"), type);
16296 DECL_ARTIFICIAL (omp_in) = 1;
16297 DECL_CONTEXT (omp_in) = fndecl;
16298 pushdecl (omp_in);
16299 struct c_expr combiner = c_parser_expression (parser);
16300 struct c_expr initializer;
16301 tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
16302 bool bad = false;
16303 initializer.value = error_mark_node;
16304 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
16305 bad = true;
16306 else if (c_parser_next_token_is (parser, CPP_NAME)
16307 && strcmp (IDENTIFIER_POINTER
16308 (c_parser_peek_token (parser)->value),
16309 "initializer") == 0)
16310 {
16311 c_parser_consume_token (parser);
16312 pop_scope ();
16313 push_scope ();
16314 omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
16315 get_identifier ("omp_priv"), type);
16316 DECL_ARTIFICIAL (omp_priv) = 1;
16317 DECL_INITIAL (omp_priv) = error_mark_node;
16318 DECL_CONTEXT (omp_priv) = fndecl;
16319 pushdecl (omp_priv);
16320 omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
16321 get_identifier ("omp_orig"), type);
16322 DECL_ARTIFICIAL (omp_orig) = 1;
16323 DECL_CONTEXT (omp_orig) = fndecl;
16324 pushdecl (omp_orig);
16325 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
16326 bad = true;
16327 else if (!c_parser_next_token_is (parser, CPP_NAME))
16328 {
16329 c_parser_error (parser, "expected %<omp_priv%> or "
16330 "function-name");
16331 bad = true;
16332 }
16333 else if (strcmp (IDENTIFIER_POINTER
16334 (c_parser_peek_token (parser)->value),
16335 "omp_priv") != 0)
16336 {
16337 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
16338 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
16339 {
16340 c_parser_error (parser, "expected function-name %<(%>");
16341 bad = true;
16342 }
16343 else
16344 initializer = c_parser_postfix_expression (parser);
16345 if (initializer.value
16346 && TREE_CODE (initializer.value) == CALL_EXPR)
16347 {
16348 int j;
16349 tree c = initializer.value;
16350 for (j = 0; j < call_expr_nargs (c); j++)
16351 {
16352 tree a = CALL_EXPR_ARG (c, j);
16353 STRIP_NOPS (a);
16354 if (TREE_CODE (a) == ADDR_EXPR
16355 && TREE_OPERAND (a, 0) == omp_priv)
16356 break;
16357 }
16358 if (j == call_expr_nargs (c))
16359 error ("one of the initializer call arguments should be "
16360 "%<&omp_priv%>");
16361 }
16362 }
16363 else
16364 {
16365 c_parser_consume_token (parser);
16366 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
16367 bad = true;
16368 else
16369 {
16370 tree st = push_stmt_list ();
16371 start_init (omp_priv, NULL_TREE, 0);
16372 location_t loc = c_parser_peek_token (parser)->location;
16373 struct c_expr init = c_parser_initializer (parser);
16374 finish_init ();
16375 finish_decl (omp_priv, loc, init.value,
16376 init.original_type, NULL_TREE);
16377 pop_stmt_list (st);
16378 }
16379 }
16380 if (!bad
16381 && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
16382 bad = true;
16383 }
16384
16385 if (!bad)
16386 {
16387 c_parser_skip_to_pragma_eol (parser);
16388
16389 tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
16390 DECL_INITIAL (reduc_decl));
16391 DECL_INITIAL (reduc_decl) = t;
16392 DECL_SOURCE_LOCATION (omp_out) = rloc;
16393 TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
16394 TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
16395 TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
16396 walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
16397 &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
16398 if (omp_priv)
16399 {
16400 DECL_SOURCE_LOCATION (omp_priv) = rloc;
16401 TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
16402 TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
16403 TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
16404 walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
16405 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
16406 walk_tree (&DECL_INITIAL (omp_priv),
16407 c_check_omp_declare_reduction_r,
16408 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
16409 }
16410 }
16411
16412 pop_stmt_list (stmt);
16413 pop_scope ();
16414 if (cfun->language != NULL)
16415 {
16416 ggc_free (cfun->language);
16417 cfun->language = NULL;
16418 }
16419 set_cfun (NULL);
16420 current_function_decl = NULL_TREE;
16421 if (nested)
16422 c_pop_function_context ();
16423
16424 if (!clauses.is_empty ())
16425 {
16426 parser->tokens = &parser->tokens_buf[0];
16427 parser->tokens_avail = tokens_avail;
16428 }
16429 if (bad)
16430 goto fail;
16431 if (errs != errorcount)
16432 break;
16433 }
16434
16435 clauses.release ();
16436 types.release ();
16437 }
16438
16439
16440 /* OpenMP 4.0
16441 #pragma omp declare simd declare-simd-clauses[optseq] new-line
16442 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16443 initializer-clause[opt] new-line
16444 #pragma omp declare target new-line */
16445
16446 static void
16447 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
16448 {
16449 c_parser_consume_pragma (parser);
16450 if (c_parser_next_token_is (parser, CPP_NAME))
16451 {
16452 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16453 if (strcmp (p, "simd") == 0)
16454 {
16455 /* c_parser_consume_token (parser); done in
16456 c_parser_omp_declare_simd. */
16457 c_parser_omp_declare_simd (parser, context);
16458 return;
16459 }
16460 if (strcmp (p, "reduction") == 0)
16461 {
16462 c_parser_consume_token (parser);
16463 c_parser_omp_declare_reduction (parser, context);
16464 return;
16465 }
16466 if (!flag_openmp) /* flag_openmp_simd */
16467 {
16468 c_parser_skip_to_pragma_eol (parser, false);
16469 return;
16470 }
16471 if (strcmp (p, "target") == 0)
16472 {
16473 c_parser_consume_token (parser);
16474 c_parser_omp_declare_target (parser);
16475 return;
16476 }
16477 }
16478
16479 c_parser_error (parser, "expected %<simd%> or %<reduction%> "
16480 "or %<target%>");
16481 c_parser_skip_to_pragma_eol (parser);
16482 }
16483
16484 /* OpenMP 4.5:
16485 #pragma omp taskloop taskloop-clause[optseq] new-line
16486 for-loop
16487
16488 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
16489 for-loop */
16490
16491 #define OMP_TASKLOOP_CLAUSE_MASK \
16492 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16493 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16494 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16495 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16496 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
16498 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
16499 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16500 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16501 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16502 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16503 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16504 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
16505 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16506
16507 static tree
16508 c_parser_omp_taskloop (location_t loc, c_parser *parser,
16509 char *p_name, omp_clause_mask mask, tree *cclauses)
16510 {
16511 tree clauses, block, ret;
16512
16513 strcat (p_name, " taskloop");
16514 mask |= OMP_TASKLOOP_CLAUSE_MASK;
16515
16516 if (c_parser_next_token_is (parser, CPP_NAME))
16517 {
16518 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16519
16520 if (strcmp (p, "simd") == 0)
16521 {
16522 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16523 if (cclauses == NULL)
16524 cclauses = cclauses_buf;
16525 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION);
16526 c_parser_consume_token (parser);
16527 if (!flag_openmp) /* flag_openmp_simd */
16528 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
16529 block = c_begin_compound_stmt (true);
16530 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
16531 block = c_end_compound_stmt (loc, block, true);
16532 if (ret == NULL)
16533 return ret;
16534 ret = make_node (OMP_TASKLOOP);
16535 TREE_TYPE (ret) = void_type_node;
16536 OMP_FOR_BODY (ret) = block;
16537 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
16538 SET_EXPR_LOCATION (ret, loc);
16539 add_stmt (ret);
16540 return ret;
16541 }
16542 }
16543 if (!flag_openmp) /* flag_openmp_simd */
16544 {
16545 c_parser_skip_to_pragma_eol (parser, false);
16546 return NULL_TREE;
16547 }
16548
16549 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16550 if (cclauses)
16551 {
16552 omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses);
16553 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
16554 }
16555
16556 block = c_begin_compound_stmt (true);
16557 ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL);
16558 block = c_end_compound_stmt (loc, block, true);
16559 add_stmt (block);
16560
16561 return ret;
16562 }
16563
16564 /* Main entry point to parsing most OpenMP pragmas. */
16565
16566 static void
16567 c_parser_omp_construct (c_parser *parser)
16568 {
16569 enum pragma_kind p_kind;
16570 location_t loc;
16571 tree stmt;
16572 char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
16573 omp_clause_mask mask (0);
16574
16575 loc = c_parser_peek_token (parser)->location;
16576 p_kind = c_parser_peek_token (parser)->pragma_kind;
16577 c_parser_consume_pragma (parser);
16578
16579 switch (p_kind)
16580 {
16581 case PRAGMA_OACC_ATOMIC:
16582 c_parser_omp_atomic (loc, parser);
16583 return;
16584 case PRAGMA_OACC_CACHE:
16585 strcpy (p_name, "#pragma acc");
16586 stmt = c_parser_oacc_cache (loc, parser);
16587 break;
16588 case PRAGMA_OACC_DATA:
16589 stmt = c_parser_oacc_data (loc, parser);
16590 break;
16591 case PRAGMA_OACC_KERNELS:
16592 case PRAGMA_OACC_PARALLEL:
16593 strcpy (p_name, "#pragma acc");
16594 stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name);
16595 break;
16596 case PRAGMA_OACC_LOOP:
16597 strcpy (p_name, "#pragma acc");
16598 stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL);
16599 break;
16600 case PRAGMA_OACC_WAIT:
16601 strcpy (p_name, "#pragma wait");
16602 stmt = c_parser_oacc_wait (loc, parser, p_name);
16603 break;
16604 case PRAGMA_OMP_ATOMIC:
16605 c_parser_omp_atomic (loc, parser);
16606 return;
16607 case PRAGMA_OMP_CRITICAL:
16608 stmt = c_parser_omp_critical (loc, parser);
16609 break;
16610 case PRAGMA_OMP_DISTRIBUTE:
16611 strcpy (p_name, "#pragma omp");
16612 stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL);
16613 break;
16614 case PRAGMA_OMP_FOR:
16615 strcpy (p_name, "#pragma omp");
16616 stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL);
16617 break;
16618 case PRAGMA_OMP_MASTER:
16619 stmt = c_parser_omp_master (loc, parser);
16620 break;
16621 case PRAGMA_OMP_PARALLEL:
16622 strcpy (p_name, "#pragma omp");
16623 stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL);
16624 break;
16625 case PRAGMA_OMP_SECTIONS:
16626 strcpy (p_name, "#pragma omp");
16627 stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
16628 break;
16629 case PRAGMA_OMP_SIMD:
16630 strcpy (p_name, "#pragma omp");
16631 stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL);
16632 break;
16633 case PRAGMA_OMP_SINGLE:
16634 stmt = c_parser_omp_single (loc, parser);
16635 break;
16636 case PRAGMA_OMP_TASK:
16637 stmt = c_parser_omp_task (loc, parser);
16638 break;
16639 case PRAGMA_OMP_TASKGROUP:
16640 stmt = c_parser_omp_taskgroup (parser);
16641 break;
16642 case PRAGMA_OMP_TASKLOOP:
16643 strcpy (p_name, "#pragma omp");
16644 stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL);
16645 break;
16646 case PRAGMA_OMP_TEAMS:
16647 strcpy (p_name, "#pragma omp");
16648 stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL);
16649 break;
16650 default:
16651 gcc_unreachable ();
16652 }
16653
16654 if (stmt)
16655 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
16656 }
16657
16658
16659 /* OpenMP 2.5:
16660 # pragma omp threadprivate (variable-list) */
16661
16662 static void
16663 c_parser_omp_threadprivate (c_parser *parser)
16664 {
16665 tree vars, t;
16666 location_t loc;
16667
16668 c_parser_consume_pragma (parser);
16669 loc = c_parser_peek_token (parser)->location;
16670 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
16671
16672 /* Mark every variable in VARS to be assigned thread local storage. */
16673 for (t = vars; t; t = TREE_CHAIN (t))
16674 {
16675 tree v = TREE_PURPOSE (t);
16676
16677 /* FIXME diagnostics: Ideally we should keep individual
16678 locations for all the variables in the var list to make the
16679 following errors more precise. Perhaps
16680 c_parser_omp_var_list_parens() should construct a list of
16681 locations to go along with the var list. */
16682
16683 /* If V had already been marked threadprivate, it doesn't matter
16684 whether it had been used prior to this point. */
16685 if (!VAR_P (v))
16686 error_at (loc, "%qD is not a variable", v);
16687 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
16688 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
16689 else if (! is_global_var (v))
16690 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
16691 else if (TREE_TYPE (v) == error_mark_node)
16692 ;
16693 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
16694 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
16695 else
16696 {
16697 if (! DECL_THREAD_LOCAL_P (v))
16698 {
16699 set_decl_tls_model (v, decl_default_tls_model (v));
16700 /* If rtl has been already set for this var, call
16701 make_decl_rtl once again, so that encode_section_info
16702 has a chance to look at the new decl flags. */
16703 if (DECL_RTL_SET_P (v))
16704 make_decl_rtl (v);
16705 }
16706 C_DECL_THREADPRIVATE_P (v) = 1;
16707 }
16708 }
16709
16710 c_parser_skip_to_pragma_eol (parser);
16711 }
16712 \f
16713 /* Cilk Plus <#pragma simd> parsing routines. */
16714
16715 /* Helper function for c_parser_pragma. Perform some sanity checking
16716 for <#pragma simd> constructs. Returns FALSE if there was a
16717 problem. */
16718
16719 static bool
16720 c_parser_cilk_verify_simd (c_parser *parser,
16721 enum pragma_context context)
16722 {
16723 if (!flag_cilkplus)
16724 {
16725 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
16726 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16727 return false;
16728 }
16729 if (context == pragma_external)
16730 {
16731 c_parser_error (parser,"pragma simd must be inside a function");
16732 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
16733 return false;
16734 }
16735 return true;
16736 }
16737
16738 /* Cilk Plus:
16739 This function is shared by SIMD-enabled functions and #pragma simd.
16740 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
16741 CLAUSES is unused. The main purpose of this function is to parse a
16742 vectorlength attribute or clause and check for parse errors.
16743 When IS_SIMD_FN is true then the function is merely caching the tokens
16744 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
16745 cache is cleared since there is no reason to continue.
16746 Syntax:
16747 vectorlength ( constant-expression ) */
16748
16749 static tree
16750 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses,
16751 bool is_simd_fn)
16752 {
16753 if (is_simd_fn)
16754 check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength");
16755 else
16756 /* The vectorlength clause behaves exactly like OpenMP's safelen
16757 clause. Represent it in OpenMP terms. */
16758 check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
16759
16760 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
16761 return clauses;
16762
16763 location_t loc = c_parser_peek_token (parser)->location;
16764 tree expr = c_parser_expr_no_commas (parser, NULL).value;
16765 expr = c_fully_fold (expr, false, NULL);
16766
16767 /* If expr is an error_mark_node then the above function would have
16768 emitted an error. No reason to do it twice. */
16769 if (expr == error_mark_node)
16770 ;
16771 else if (!TREE_TYPE (expr)
16772 || !TREE_CONSTANT (expr)
16773 || !INTEGRAL_TYPE_P (TREE_TYPE (expr)))
16774
16775 error_at (loc, "vectorlength must be an integer constant");
16776 else if (wi::exact_log2 (expr) == -1)
16777 error_at (loc, "vectorlength must be a power of 2");
16778 else
16779 {
16780 if (is_simd_fn)
16781 {
16782 tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN);
16783 OMP_CLAUSE_SIMDLEN_EXPR (u) = expr;
16784 OMP_CLAUSE_CHAIN (u) = clauses;
16785 clauses = u;
16786 }
16787 else
16788 {
16789 tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN);
16790 OMP_CLAUSE_SAFELEN_EXPR (u) = expr;
16791 OMP_CLAUSE_CHAIN (u) = clauses;
16792 clauses = u;
16793 }
16794 }
16795
16796 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
16797
16798 return clauses;
16799 }
16800
16801 /* Cilk Plus:
16802 linear ( simd-linear-variable-list )
16803
16804 simd-linear-variable-list:
16805 simd-linear-variable
16806 simd-linear-variable-list , simd-linear-variable
16807
16808 simd-linear-variable:
16809 id-expression
16810 id-expression : simd-linear-step
16811
16812 simd-linear-step:
16813 conditional-expression */
16814
16815 static tree
16816 c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
16817 {
16818 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
16819 return clauses;
16820
16821 location_t loc = c_parser_peek_token (parser)->location;
16822
16823 if (c_parser_next_token_is_not (parser, CPP_NAME)
16824 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
16825 c_parser_error (parser, "expected identifier");
16826
16827 while (c_parser_next_token_is (parser, CPP_NAME)
16828 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
16829 {
16830 tree var = lookup_name (c_parser_peek_token (parser)->value);
16831
16832 if (var == NULL)
16833 {
16834 undeclared_variable (c_parser_peek_token (parser)->location,
16835 c_parser_peek_token (parser)->value);
16836 c_parser_consume_token (parser);
16837 }
16838 else if (var == error_mark_node)
16839 c_parser_consume_token (parser);
16840 else
16841 {
16842 tree step = integer_one_node;
16843
16844 /* Parse the linear step if present. */
16845 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
16846 {
16847 c_parser_consume_token (parser);
16848 c_parser_consume_token (parser);
16849
16850 tree expr = c_parser_expr_no_commas (parser, NULL).value;
16851 expr = c_fully_fold (expr, false, NULL);
16852
16853 if (TREE_TYPE (expr)
16854 && INTEGRAL_TYPE_P (TREE_TYPE (expr))
16855 && (TREE_CONSTANT (expr)
16856 || DECL_P (expr)))
16857 step = expr;
16858 else
16859 c_parser_error (parser,
16860 "step size must be an integer constant "
16861 "expression or an integer variable");
16862 }
16863 else
16864 c_parser_consume_token (parser);
16865
16866 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
16867 tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR);
16868 OMP_CLAUSE_DECL (u) = var;
16869 OMP_CLAUSE_LINEAR_STEP (u) = step;
16870 OMP_CLAUSE_CHAIN (u) = clauses;
16871 clauses = u;
16872 }
16873
16874 if (c_parser_next_token_is_not (parser, CPP_COMMA))
16875 break;
16876
16877 c_parser_consume_token (parser);
16878 }
16879
16880 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
16881
16882 return clauses;
16883 }
16884
16885 /* Returns the name of the next clause. If the clause is not
16886 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
16887 not consumed. Otherwise, the appropriate pragma_simd_clause is
16888 returned and the token is consumed. */
16889
16890 static pragma_omp_clause
16891 c_parser_cilk_clause_name (c_parser *parser)
16892 {
16893 pragma_omp_clause result;
16894 c_token *token = c_parser_peek_token (parser);
16895
16896 if (!token->value || token->type != CPP_NAME)
16897 return PRAGMA_CILK_CLAUSE_NONE;
16898
16899 const char *p = IDENTIFIER_POINTER (token->value);
16900
16901 if (!strcmp (p, "vectorlength"))
16902 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
16903 else if (!strcmp (p, "linear"))
16904 result = PRAGMA_CILK_CLAUSE_LINEAR;
16905 else if (!strcmp (p, "private"))
16906 result = PRAGMA_CILK_CLAUSE_PRIVATE;
16907 else if (!strcmp (p, "firstprivate"))
16908 result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
16909 else if (!strcmp (p, "lastprivate"))
16910 result = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
16911 else if (!strcmp (p, "reduction"))
16912 result = PRAGMA_CILK_CLAUSE_REDUCTION;
16913 else
16914 return PRAGMA_CILK_CLAUSE_NONE;
16915
16916 c_parser_consume_token (parser);
16917 return result;
16918 }
16919
16920 /* Parse all #<pragma simd> clauses. Return the list of clauses
16921 found. */
16922
16923 static tree
16924 c_parser_cilk_all_clauses (c_parser *parser)
16925 {
16926 tree clauses = NULL;
16927
16928 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
16929 {
16930 pragma_omp_clause c_kind;
16931
16932 c_kind = c_parser_cilk_clause_name (parser);
16933
16934 switch (c_kind)
16935 {
16936 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
16937 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false);
16938 break;
16939 case PRAGMA_CILK_CLAUSE_LINEAR:
16940 clauses = c_parser_cilk_clause_linear (parser, clauses);
16941 break;
16942 case PRAGMA_CILK_CLAUSE_PRIVATE:
16943 /* Use the OpenMP counterpart. */
16944 clauses = c_parser_omp_clause_private (parser, clauses);
16945 break;
16946 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE:
16947 /* Use the OpenMP counterpart. */
16948 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
16949 break;
16950 case PRAGMA_CILK_CLAUSE_LASTPRIVATE:
16951 /* Use the OpenMP counterpart. */
16952 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
16953 break;
16954 case PRAGMA_CILK_CLAUSE_REDUCTION:
16955 /* Use the OpenMP counterpart. */
16956 clauses = c_parser_omp_clause_reduction (parser, clauses);
16957 break;
16958 default:
16959 c_parser_error (parser, "expected %<#pragma simd%> clause");
16960 goto saw_error;
16961 }
16962 }
16963
16964 saw_error:
16965 c_parser_skip_to_pragma_eol (parser);
16966 return c_finish_cilk_clauses (clauses);
16967 }
16968
16969 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
16970 Here is the correct syntax of this pragma:
16971 #pragma cilk grainsize = <EXP>
16972 */
16973
16974 static void
16975 c_parser_cilk_grainsize (c_parser *parser)
16976 {
16977 extern tree convert_to_integer (tree, tree);
16978
16979 /* consume the 'grainsize' keyword. */
16980 c_parser_consume_pragma (parser);
16981
16982 if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0)
16983 {
16984 struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL);
16985 if (g_expr.value == error_mark_node)
16986 {
16987 c_parser_skip_to_pragma_eol (parser);
16988 return;
16989 }
16990 tree grain = convert_to_integer (long_integer_type_node,
16991 c_fully_fold (g_expr.value, false,
16992 NULL));
16993 c_parser_skip_to_pragma_eol (parser);
16994 c_token *token = c_parser_peek_token (parser);
16995 if (token && token->type == CPP_KEYWORD
16996 && token->keyword == RID_CILK_FOR)
16997 {
16998 if (grain == NULL_TREE || grain == error_mark_node)
16999 grain = integer_zero_node;
17000 c_parser_cilk_for (parser, grain);
17001 }
17002 else
17003 warning (0, "%<#pragma cilk grainsize%> is not followed by "
17004 "%<_Cilk_for%>");
17005 }
17006 else
17007 c_parser_skip_to_pragma_eol (parser);
17008 }
17009
17010 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
17011
17012 static void
17013 c_parser_cilk_simd (c_parser *parser)
17014 {
17015 tree clauses = c_parser_cilk_all_clauses (parser);
17016 tree block = c_begin_compound_stmt (true);
17017 location_t loc = c_parser_peek_token (parser)->location;
17018 c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL);
17019 block = c_end_compound_stmt (loc, block, true);
17020 add_stmt (block);
17021 }
17022
17023 /* Create an artificial decl with TYPE and emit initialization of it with
17024 INIT. */
17025
17026 static tree
17027 c_get_temp_regvar (tree type, tree init)
17028 {
17029 location_t loc = EXPR_LOCATION (init);
17030 tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
17031 DECL_ARTIFICIAL (decl) = 1;
17032 DECL_IGNORED_P (decl) = 1;
17033 pushdecl (decl);
17034 tree t = build2 (INIT_EXPR, type, decl, init);
17035 add_stmt (t);
17036 return decl;
17037 }
17038
17039 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17040 GRAIN is the grain value passed in through pragma or 0. */
17041
17042 static void
17043 c_parser_cilk_for (c_parser *parser, tree grain)
17044 {
17045 tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE);
17046 OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR;
17047 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain;
17048 clauses = c_finish_omp_clauses (clauses, false);
17049
17050 tree block = c_begin_compound_stmt (true);
17051 tree sb = push_stmt_list ();
17052 location_t loc = c_parser_peek_token (parser)->location;
17053 tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL);
17054 sb = pop_stmt_list (sb);
17055
17056 if (omp_for)
17057 {
17058 tree omp_par = make_node (OMP_PARALLEL);
17059 TREE_TYPE (omp_par) = void_type_node;
17060 OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE;
17061 tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
17062 TREE_SIDE_EFFECTS (bind) = 1;
17063 BIND_EXPR_BODY (bind) = sb;
17064 OMP_PARALLEL_BODY (omp_par) = bind;
17065 if (OMP_FOR_PRE_BODY (omp_for))
17066 {
17067 add_stmt (OMP_FOR_PRE_BODY (omp_for));
17068 OMP_FOR_PRE_BODY (omp_for) = NULL_TREE;
17069 }
17070 tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0);
17071 tree decl = TREE_OPERAND (init, 0);
17072 tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0);
17073 tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
17074 tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE;
17075 if (TREE_CODE (t) != INTEGER_CST)
17076 {
17077 TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
17078 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
17079 OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1);
17080 OMP_CLAUSE_CHAIN (c) = clauses;
17081 clauses = c;
17082 }
17083 if (TREE_CODE (incr) == MODIFY_EXPR)
17084 {
17085 t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
17086 if (TREE_CODE (t) != INTEGER_CST)
17087 {
17088 TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
17089 = c_get_temp_regvar (TREE_TYPE (t), t);
17090 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
17091 OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
17092 OMP_CLAUSE_CHAIN (c) = clauses;
17093 clauses = c;
17094 }
17095 }
17096 t = TREE_OPERAND (init, 1);
17097 if (TREE_CODE (t) != INTEGER_CST)
17098 {
17099 TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
17100 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
17101 OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1);
17102 OMP_CLAUSE_CHAIN (c) = clauses;
17103 clauses = c;
17104 }
17105 c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
17106 OMP_CLAUSE_DECL (c) = decl;
17107 OMP_CLAUSE_CHAIN (c) = clauses;
17108 clauses = c;
17109 c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_);
17110 OMP_CLAUSE_OPERAND (c, 0)
17111 = cilk_for_number_of_iterations (omp_for);
17112 OMP_CLAUSE_CHAIN (c) = clauses;
17113 OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c, true);
17114 add_stmt (omp_par);
17115 }
17116
17117 block = c_end_compound_stmt (loc, block, true);
17118 add_stmt (block);
17119 }
17120
17121 \f
17122 /* Parse a transaction attribute (GCC Extension).
17123
17124 transaction-attribute:
17125 attributes
17126 [ [ any-word ] ]
17127
17128 The transactional memory language description is written for C++,
17129 and uses the C++0x attribute syntax. For compatibility, allow the
17130 bracket style for transactions in C as well. */
17131
17132 static tree
17133 c_parser_transaction_attributes (c_parser *parser)
17134 {
17135 tree attr_name, attr = NULL;
17136
17137 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
17138 return c_parser_attributes (parser);
17139
17140 if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
17141 return NULL_TREE;
17142 c_parser_consume_token (parser);
17143 if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
17144 goto error1;
17145
17146 attr_name = c_parser_attribute_any_word (parser);
17147 if (attr_name)
17148 {
17149 c_parser_consume_token (parser);
17150 attr = build_tree_list (attr_name, NULL_TREE);
17151 }
17152 else
17153 c_parser_error (parser, "expected identifier");
17154
17155 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
17156 error1:
17157 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
17158 return attr;
17159 }
17160
17161 /* Parse a __transaction_atomic or __transaction_relaxed statement
17162 (GCC Extension).
17163
17164 transaction-statement:
17165 __transaction_atomic transaction-attribute[opt] compound-statement
17166 __transaction_relaxed compound-statement
17167
17168 Note that the only valid attribute is: "outer".
17169 */
17170
17171 static tree
17172 c_parser_transaction (c_parser *parser, enum rid keyword)
17173 {
17174 unsigned int old_in = parser->in_transaction;
17175 unsigned int this_in = 1, new_in;
17176 location_t loc = c_parser_peek_token (parser)->location;
17177 tree stmt, attrs;
17178
17179 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
17180 || keyword == RID_TRANSACTION_RELAXED)
17181 && c_parser_next_token_is_keyword (parser, keyword));
17182 c_parser_consume_token (parser);
17183
17184 if (keyword == RID_TRANSACTION_RELAXED)
17185 this_in |= TM_STMT_ATTR_RELAXED;
17186 else
17187 {
17188 attrs = c_parser_transaction_attributes (parser);
17189 if (attrs)
17190 this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
17191 }
17192
17193 /* Keep track if we're in the lexical scope of an outer transaction. */
17194 new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
17195
17196 parser->in_transaction = new_in;
17197 stmt = c_parser_compound_statement (parser);
17198 parser->in_transaction = old_in;
17199
17200 if (flag_tm)
17201 stmt = c_finish_transaction (loc, stmt, this_in);
17202 else
17203 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
17204 "%<__transaction_atomic%> without transactional memory support enabled"
17205 : "%<__transaction_relaxed %> "
17206 "without transactional memory support enabled"));
17207
17208 return stmt;
17209 }
17210
17211 /* Parse a __transaction_atomic or __transaction_relaxed expression
17212 (GCC Extension).
17213
17214 transaction-expression:
17215 __transaction_atomic ( expression )
17216 __transaction_relaxed ( expression )
17217 */
17218
17219 static struct c_expr
17220 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
17221 {
17222 struct c_expr ret;
17223 unsigned int old_in = parser->in_transaction;
17224 unsigned int this_in = 1;
17225 location_t loc = c_parser_peek_token (parser)->location;
17226 tree attrs;
17227
17228 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
17229 || keyword == RID_TRANSACTION_RELAXED)
17230 && c_parser_next_token_is_keyword (parser, keyword));
17231 c_parser_consume_token (parser);
17232
17233 if (keyword == RID_TRANSACTION_RELAXED)
17234 this_in |= TM_STMT_ATTR_RELAXED;
17235 else
17236 {
17237 attrs = c_parser_transaction_attributes (parser);
17238 if (attrs)
17239 this_in |= parse_tm_stmt_attr (attrs, 0);
17240 }
17241
17242 parser->in_transaction = this_in;
17243 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17244 {
17245 tree expr = c_parser_expression (parser).value;
17246 ret.original_type = TREE_TYPE (expr);
17247 ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
17248 if (this_in & TM_STMT_ATTR_RELAXED)
17249 TRANSACTION_EXPR_RELAXED (ret.value) = 1;
17250 SET_EXPR_LOCATION (ret.value, loc);
17251 ret.original_code = TRANSACTION_EXPR;
17252 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
17253 {
17254 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
17255 goto error;
17256 }
17257 }
17258 else
17259 {
17260 error:
17261 ret.value = error_mark_node;
17262 ret.original_code = ERROR_MARK;
17263 ret.original_type = NULL;
17264 }
17265 parser->in_transaction = old_in;
17266
17267 if (!flag_tm)
17268 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
17269 "%<__transaction_atomic%> without transactional memory support enabled"
17270 : "%<__transaction_relaxed %> "
17271 "without transactional memory support enabled"));
17272
17273 return ret;
17274 }
17275
17276 /* Parse a __transaction_cancel statement (GCC Extension).
17277
17278 transaction-cancel-statement:
17279 __transaction_cancel transaction-attribute[opt] ;
17280
17281 Note that the only valid attribute is "outer".
17282 */
17283
17284 static tree
17285 c_parser_transaction_cancel (c_parser *parser)
17286 {
17287 location_t loc = c_parser_peek_token (parser)->location;
17288 tree attrs;
17289 bool is_outer = false;
17290
17291 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
17292 c_parser_consume_token (parser);
17293
17294 attrs = c_parser_transaction_attributes (parser);
17295 if (attrs)
17296 is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
17297
17298 if (!flag_tm)
17299 {
17300 error_at (loc, "%<__transaction_cancel%> without "
17301 "transactional memory support enabled");
17302 goto ret_error;
17303 }
17304 else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
17305 {
17306 error_at (loc, "%<__transaction_cancel%> within a "
17307 "%<__transaction_relaxed%>");
17308 goto ret_error;
17309 }
17310 else if (is_outer)
17311 {
17312 if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
17313 && !is_tm_may_cancel_outer (current_function_decl))
17314 {
17315 error_at (loc, "outer %<__transaction_cancel%> not "
17316 "within outer %<__transaction_atomic%>");
17317 error_at (loc, " or a %<transaction_may_cancel_outer%> function");
17318 goto ret_error;
17319 }
17320 }
17321 else if (parser->in_transaction == 0)
17322 {
17323 error_at (loc, "%<__transaction_cancel%> not within "
17324 "%<__transaction_atomic%>");
17325 goto ret_error;
17326 }
17327
17328 return add_stmt (build_tm_abort_call (loc, is_outer));
17329
17330 ret_error:
17331 return build1 (NOP_EXPR, void_type_node, error_mark_node);
17332 }
17333 \f
17334 /* Parse a single source file. */
17335
17336 void
17337 c_parse_file (void)
17338 {
17339 /* Use local storage to begin. If the first token is a pragma, parse it.
17340 If it is #pragma GCC pch_preprocess, then this will load a PCH file
17341 which will cause garbage collection. */
17342 c_parser tparser;
17343
17344 memset (&tparser, 0, sizeof tparser);
17345 tparser.tokens = &tparser.tokens_buf[0];
17346 the_parser = &tparser;
17347
17348 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
17349 c_parser_pragma_pch_preprocess (&tparser);
17350
17351 the_parser = ggc_alloc<c_parser> ();
17352 *the_parser = tparser;
17353 if (tparser.tokens == &tparser.tokens_buf[0])
17354 the_parser->tokens = &the_parser->tokens_buf[0];
17355
17356 /* Initialize EH, if we've been told to do so. */
17357 if (flag_exceptions)
17358 using_eh_for_cleanups ();
17359
17360 c_parser_translation_unit (the_parser);
17361 the_parser = NULL;
17362 }
17363
17364 /* This function parses Cilk Plus array notation. The starting index is
17365 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
17366 return value of this function is a tree_node called VALUE_TREE of type
17367 ARRAY_NOTATION_REF. */
17368
17369 static tree
17370 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
17371 tree array_value)
17372 {
17373 c_token *token = NULL;
17374 tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE;
17375 tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE;
17376 tree array_type_domain = NULL_TREE;
17377
17378 if (array_value == error_mark_node || initial_index == error_mark_node)
17379 {
17380 /* No need to continue. If either of these 2 were true, then an error
17381 must be emitted already. Thus, no need to emit them twice. */
17382 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
17383 return error_mark_node;
17384 }
17385
17386 array_type = TREE_TYPE (array_value);
17387 gcc_assert (array_type);
17388 if (TREE_CODE (array_type) != ARRAY_TYPE
17389 && TREE_CODE (array_type) != POINTER_TYPE)
17390 {
17391 error_at (loc, "base of array section must be pointer or array type");
17392 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
17393 return error_mark_node;
17394 }
17395 type = TREE_TYPE (array_type);
17396 token = c_parser_peek_token (parser);
17397
17398 if (token->type == CPP_EOF)
17399 {
17400 c_parser_error (parser, "expected %<:%> or numeral");
17401 return value_tree;
17402 }
17403 else if (token->type == CPP_COLON)
17404 {
17405 if (!initial_index)
17406 {
17407 /* If we are here, then we have a case like this A[:]. */
17408 c_parser_consume_token (parser);
17409 if (TREE_CODE (array_type) == POINTER_TYPE)
17410 {
17411 error_at (loc, "start-index and length fields necessary for "
17412 "using array notations in pointers");
17413 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
17414 return error_mark_node;
17415 }
17416 if (TREE_CODE (array_type) == FUNCTION_TYPE)
17417 {
17418 error_at (loc, "array notations cannot be used with function "
17419 "type");
17420 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
17421 return error_mark_node;
17422 }
17423 array_type_domain = TYPE_DOMAIN (array_type);
17424
17425 if (!array_type_domain)
17426 {
17427 error_at (loc, "start-index and length fields necessary for "
17428 "using array notations in dimensionless arrays");
17429 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
17430 return error_mark_node;
17431 }
17432
17433 start_index = TYPE_MINVAL (array_type_domain);
17434 start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node,
17435 start_index);
17436 if (!TYPE_MAXVAL (array_type_domain)
17437 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain)))
17438 {
17439 error_at (loc, "start-index and length fields necessary for "
17440 "using array notations in variable-length arrays");
17441 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
17442 return error_mark_node;
17443 }
17444 end_index = TYPE_MAXVAL (array_type_domain);
17445 end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index),
17446 end_index, integer_one_node);
17447 end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index);
17448 stride = build_int_cst (integer_type_node, 1);
17449 stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride);
17450 }
17451 else if (initial_index != error_mark_node)
17452 {
17453 /* If we are here, then there should be 2 possibilities:
17454 1. Array [EXPR : EXPR]
17455 2. Array [EXPR : EXPR : EXPR]
17456 */
17457 start_index = initial_index;
17458
17459 if (TREE_CODE (array_type) == FUNCTION_TYPE)
17460 {
17461 error_at (loc, "array notations cannot be used with function "
17462 "type");
17463 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
17464 return error_mark_node;
17465 }
17466 c_parser_consume_token (parser); /* consume the ':' */
17467 struct c_expr ce = c_parser_expression (parser);
17468 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
17469 end_index = ce.value;
17470 if (!end_index || end_index == error_mark_node)
17471 {
17472 c_parser_skip_to_end_of_block_or_statement (parser);
17473 return error_mark_node;
17474 }
17475 if (c_parser_peek_token (parser)->type == CPP_COLON)
17476 {
17477 c_parser_consume_token (parser);
17478 ce = c_parser_expression (parser);
17479 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
17480 stride = ce.value;
17481 if (!stride || stride == error_mark_node)
17482 {
17483 c_parser_skip_to_end_of_block_or_statement (parser);
17484 return error_mark_node;
17485 }
17486 }
17487 }
17488 else
17489 c_parser_error (parser, "expected array notation expression");
17490 }
17491 else
17492 c_parser_error (parser, "expected array notation expression");
17493
17494 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
17495
17496 value_tree = build_array_notation_ref (loc, array_value, start_index,
17497 end_index, stride, type);
17498 if (value_tree != error_mark_node)
17499 SET_EXPR_LOCATION (value_tree, loc);
17500 return value_tree;
17501 }
17502
17503 #include "gt-c-c-parser.h"