Merge trunk version 221103 into gupc branch.
[official-gcc.git] / gcc / c / c-parser.c
blob1249d5f255e4b327de464502b730008b704df343
1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
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.
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.
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/>. */
23 /* TODO:
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.
29 Add testcases covering every input symbol in every state in old and
30 new parsers.
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
38 #include "config.h"
39 #include "system.h"
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
42 #include "hash-set.h"
43 #include "vec.h"
44 #include "symtab.h"
45 #include "input.h"
46 #include "alias.h"
47 #include "double-int.h"
48 #include "machmode.h"
49 #include "flags.h"
50 #include "inchash.h"
51 #include "tree.h"
52 #include "fold-const.h"
53 #include "stringpool.h"
54 #include "attribs.h"
55 #include "stor-layout.h"
56 #include "varasm.h"
57 #include "trans-mem.h"
58 #include "langhooks.h"
59 #include "input.h"
60 #include "cpplib.h"
61 #include "timevar.h"
62 #include "c-family/c-pragma.h"
63 #include "c-tree.h"
64 #include "c-lang.h"
65 #include "flags.h"
66 #include "ggc.h"
67 #include "c-family/c-common.h"
68 #include "c-family/c-objc.h"
69 #include "c-family/c-upc.h"
70 #include "c-family/c-upc-gasp.h"
71 #include "c-family/c-upc-pts-ops.h"
72 #include "output.h"
73 #include "vec.h"
74 #include "target.h"
75 #include "hash-map.h"
76 #include "is-a.h"
77 #include "plugin-api.h"
78 #include "hashtab.h"
79 #include "hash-set.h"
80 #include "machmode.h"
81 #include "hard-reg-set.h"
82 #include "function.h"
83 #include "ipa-ref.h"
84 #include "cgraph.h"
85 #include "plugin.h"
86 #include "omp-low.h"
87 #include "builtins.h"
88 #include "gomp-constants.h"
91 /* Initialization routine for this file. */
93 void
94 c_parse_init (void)
96 /* The only initialization required is of the reserved word
97 identifiers. */
98 unsigned int i;
99 tree id;
100 int mask = 0;
102 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
103 the c_token structure. */
104 gcc_assert (RID_MAX <= 255);
106 mask |= D_CXXONLY;
107 if (!flag_isoc99)
108 mask |= D_C99;
109 if (flag_no_asm)
111 mask |= D_ASM | D_EXT;
112 if (!flag_isoc99)
113 mask |= D_EXT89;
115 if (!c_dialect_objc ())
116 mask |= D_OBJC | D_CXX_OBJC;
118 if (!flag_upc)
119 mask |= D_UPC;
121 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
122 for (i = 0; i < num_c_common_reswords; i++)
124 /* If a keyword is disabled, do not enter it into the table
125 and so create a canonical spelling that isn't a keyword. */
126 if (c_common_reswords[i].disable & mask)
128 if (warn_cxx_compat
129 && (c_common_reswords[i].disable & D_CXXWARN))
131 id = get_identifier (c_common_reswords[i].word);
132 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
133 C_IS_RESERVED_WORD (id) = 1;
135 continue;
138 id = get_identifier (c_common_reswords[i].word);
139 C_SET_RID_CODE (id, c_common_reswords[i].rid);
140 C_IS_RESERVED_WORD (id) = 1;
141 ridpointers [(int) c_common_reswords[i].rid] = id;
144 for (i = 0; i < NUM_INT_N_ENTS; i++)
146 /* We always create the symbols but they aren't always supported. */
147 char name[50];
148 sprintf (name, "__int%d", int_n_data[i].bitsize);
149 id = get_identifier (xstrdup (name));
150 C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
151 C_IS_RESERVED_WORD (id) = 1;
155 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
156 and the C parser. Unlike the C++ lexer, the parser structure
157 stores the lexer information instead of using a separate structure.
158 Identifiers are separated into ordinary identifiers, type names,
159 keywords and some other Objective-C types of identifiers, and some
160 look-ahead is maintained.
162 ??? It might be a good idea to lex the whole file up front (as for
163 C++). It would then be possible to share more of the C and C++
164 lexer code, if desired. */
166 /* More information about the type of a CPP_NAME token. */
167 typedef enum c_id_kind {
168 /* An ordinary identifier. */
169 C_ID_ID,
170 /* An identifier declared as a typedef name. */
171 C_ID_TYPENAME,
172 /* An identifier declared as an Objective-C class name. */
173 C_ID_CLASSNAME,
174 /* An address space identifier. */
175 C_ID_ADDRSPACE,
176 /* Not an identifier. */
177 C_ID_NONE
178 } c_id_kind;
180 /* A single C token after string literal concatenation and conversion
181 of preprocessing tokens to tokens. */
182 typedef struct GTY (()) c_token {
183 /* The kind of token. */
184 ENUM_BITFIELD (cpp_ttype) type : 8;
185 /* If this token is a CPP_NAME, this value indicates whether also
186 declared as some kind of type. Otherwise, it is C_ID_NONE. */
187 ENUM_BITFIELD (c_id_kind) id_kind : 8;
188 /* If this token is a keyword, this value indicates which keyword.
189 Otherwise, this value is RID_MAX. */
190 ENUM_BITFIELD (rid) keyword : 8;
191 /* If this token is a CPP_PRAGMA, this indicates the pragma that
192 was seen. Otherwise it is PRAGMA_NONE. */
193 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
194 /* The location at which this token was found. */
195 location_t location;
196 /* The value associated with this token, if any. */
197 tree value;
198 } c_token;
200 /* A parser structure recording information about the state and
201 context of parsing. Includes lexer information with up to two
202 tokens of look-ahead; more are not needed for C. */
203 typedef struct GTY(()) c_parser {
204 /* The look-ahead tokens. */
205 c_token * GTY((skip)) tokens;
206 /* Buffer for look-ahead tokens. */
207 c_token tokens_buf[2];
208 /* How many look-ahead tokens are available (0, 1 or 2, or
209 more if parsing from pre-lexed tokens). */
210 unsigned int tokens_avail;
211 /* True if a syntax error is being recovered from; false otherwise.
212 c_parser_error sets this flag. It should clear this flag when
213 enough tokens have been consumed to recover from the error. */
214 BOOL_BITFIELD error : 1;
215 /* True if we're processing a pragma, and shouldn't automatically
216 consume CPP_PRAGMA_EOL. */
217 BOOL_BITFIELD in_pragma : 1;
218 /* True if we're parsing the outermost block of an if statement. */
219 BOOL_BITFIELD in_if_block : 1;
220 /* True if we want to lex an untranslated string. */
221 BOOL_BITFIELD lex_untranslated_string : 1;
223 /* Objective-C specific parser/lexer information. */
225 /* True if we are in a context where the Objective-C "PQ" keywords
226 are considered keywords. */
227 BOOL_BITFIELD objc_pq_context : 1;
228 /* True if we are parsing a (potential) Objective-C foreach
229 statement. This is set to true after we parsed 'for (' and while
230 we wait for 'in' or ';' to decide if it's a standard C for loop or an
231 Objective-C foreach loop. */
232 BOOL_BITFIELD objc_could_be_foreach_context : 1;
233 /* The following flag is needed to contextualize Objective-C lexical
234 analysis. In some cases (e.g., 'int NSObject;'), it is
235 undesirable to bind an identifier to an Objective-C class, even
236 if a class with that name exists. */
237 BOOL_BITFIELD objc_need_raw_identifier : 1;
238 /* Nonzero if we're processing a __transaction statement. The value
239 is 1 | TM_STMT_ATTR_*. */
240 unsigned int in_transaction : 4;
241 /* True if we are in a context where the Objective-C "Property attribute"
242 keywords are valid. */
243 BOOL_BITFIELD objc_property_attr_context : 1;
245 /* Cilk Plus specific parser/lexer information. */
247 /* Buffer to hold all the tokens from parsing the vector attribute for the
248 SIMD-enabled functions (formerly known as elemental functions). */
249 vec <c_token, va_gc> *cilk_simd_fn_tokens;
250 } c_parser;
253 /* The actual parser and external interface. ??? Does this need to be
254 garbage-collected? */
256 static GTY (()) c_parser *the_parser;
258 /* Read in and lex a single token, storing it in *TOKEN. */
260 static void
261 c_lex_one_token (c_parser *parser, c_token *token)
263 timevar_push (TV_LEX);
265 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
266 (parser->lex_untranslated_string
267 ? C_LEX_STRING_NO_TRANSLATE : 0));
268 token->id_kind = C_ID_NONE;
269 token->keyword = RID_MAX;
270 token->pragma_kind = PRAGMA_NONE;
272 switch (token->type)
274 case CPP_NAME:
276 tree decl;
278 bool objc_force_identifier = parser->objc_need_raw_identifier;
279 if (c_dialect_objc ())
280 parser->objc_need_raw_identifier = false;
282 if (C_IS_RESERVED_WORD (token->value))
284 enum rid rid_code = C_RID_CODE (token->value);
286 if (rid_code == RID_CXX_COMPAT_WARN)
288 warning_at (token->location,
289 OPT_Wc___compat,
290 "identifier %qE conflicts with C++ keyword",
291 token->value);
293 else if (rid_code >= RID_FIRST_ADDR_SPACE
294 && rid_code <= RID_LAST_ADDR_SPACE)
296 token->id_kind = C_ID_ADDRSPACE;
297 token->keyword = rid_code;
298 break;
300 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
302 /* We found an Objective-C "pq" keyword (in, out,
303 inout, bycopy, byref, oneway). They need special
304 care because the interpretation depends on the
305 context. */
306 if (parser->objc_pq_context)
308 token->type = CPP_KEYWORD;
309 token->keyword = rid_code;
310 break;
312 else if (parser->objc_could_be_foreach_context
313 && rid_code == RID_IN)
315 /* We are in Objective-C, inside a (potential)
316 foreach context (which means after having
317 parsed 'for (', but before having parsed ';'),
318 and we found 'in'. We consider it the keyword
319 which terminates the declaration at the
320 beginning of a foreach-statement. Note that
321 this means you can't use 'in' for anything else
322 in that context; in particular, in Objective-C
323 you can't use 'in' as the name of the running
324 variable in a C for loop. We could potentially
325 try to add code here to disambiguate, but it
326 seems a reasonable limitation. */
327 token->type = CPP_KEYWORD;
328 token->keyword = rid_code;
329 break;
331 /* Else, "pq" keywords outside of the "pq" context are
332 not keywords, and we fall through to the code for
333 normal tokens. */
335 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
337 /* We found an Objective-C "property attribute"
338 keyword (getter, setter, readonly, etc). These are
339 only valid in the property context. */
340 if (parser->objc_property_attr_context)
342 token->type = CPP_KEYWORD;
343 token->keyword = rid_code;
344 break;
346 /* Else they are not special keywords.
349 else if (c_dialect_objc ()
350 && (OBJC_IS_AT_KEYWORD (rid_code)
351 || OBJC_IS_CXX_KEYWORD (rid_code)))
353 /* We found one of the Objective-C "@" keywords (defs,
354 selector, synchronized, etc) or one of the
355 Objective-C "cxx" keywords (class, private,
356 protected, public, try, catch, throw) without a
357 preceding '@' sign. Do nothing and fall through to
358 the code for normal tokens (in C++ we would still
359 consider the CXX ones keywords, but not in C). */
362 else
364 token->type = CPP_KEYWORD;
365 token->keyword = rid_code;
366 break;
370 decl = lookup_name (token->value);
371 if (decl)
373 if (TREE_CODE (decl) == TYPE_DECL)
375 token->id_kind = C_ID_TYPENAME;
376 break;
379 else if (c_dialect_objc ())
381 tree objc_interface_decl = objc_is_class_name (token->value);
382 /* Objective-C class names are in the same namespace as
383 variables and typedefs, and hence are shadowed by local
384 declarations. */
385 if (objc_interface_decl
386 && (!objc_force_identifier || global_bindings_p ()))
388 token->value = objc_interface_decl;
389 token->id_kind = C_ID_CLASSNAME;
390 break;
393 token->id_kind = C_ID_ID;
395 break;
396 case CPP_AT_NAME:
397 /* This only happens in Objective-C; it must be a keyword. */
398 token->type = CPP_KEYWORD;
399 switch (C_RID_CODE (token->value))
401 /* Replace 'class' with '@class', 'private' with '@private',
402 etc. This prevents confusion with the C++ keyword
403 'class', and makes the tokens consistent with other
404 Objective-C 'AT' keywords. For example '@class' is
405 reported as RID_AT_CLASS which is consistent with
406 '@synchronized', which is reported as
407 RID_AT_SYNCHRONIZED.
409 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
410 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
411 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
412 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
413 case RID_THROW: token->keyword = RID_AT_THROW; break;
414 case RID_TRY: token->keyword = RID_AT_TRY; break;
415 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
416 default: token->keyword = C_RID_CODE (token->value);
418 break;
419 case CPP_COLON:
420 case CPP_COMMA:
421 case CPP_CLOSE_PAREN:
422 case CPP_SEMICOLON:
423 /* These tokens may affect the interpretation of any identifiers
424 following, if doing Objective-C. */
425 if (c_dialect_objc ())
426 parser->objc_need_raw_identifier = false;
427 break;
428 case CPP_PRAGMA:
429 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
430 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
431 token->value = NULL;
432 break;
433 default:
434 break;
436 timevar_pop (TV_LEX);
439 /* Return a pointer to the next token from PARSER, reading it in if
440 necessary. */
442 static inline c_token *
443 c_parser_peek_token (c_parser *parser)
445 if (parser->tokens_avail == 0)
447 c_lex_one_token (parser, &parser->tokens[0]);
448 parser->tokens_avail = 1;
450 return &parser->tokens[0];
453 /* Return true if the next token from PARSER has the indicated
454 TYPE. */
456 static inline bool
457 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
459 return c_parser_peek_token (parser)->type == type;
462 /* Return true if the next token from PARSER does not have the
463 indicated TYPE. */
465 static inline bool
466 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
468 return !c_parser_next_token_is (parser, type);
471 /* Return true if the next token from PARSER is the indicated
472 KEYWORD. */
474 static inline bool
475 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
477 return c_parser_peek_token (parser)->keyword == keyword;
480 /* Return a pointer to the next-but-one token from PARSER, reading it
481 in if necessary. The next token is already read in. */
483 static c_token *
484 c_parser_peek_2nd_token (c_parser *parser)
486 if (parser->tokens_avail >= 2)
487 return &parser->tokens[1];
488 gcc_assert (parser->tokens_avail == 1);
489 gcc_assert (parser->tokens[0].type != CPP_EOF);
490 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
491 c_lex_one_token (parser, &parser->tokens[1]);
492 parser->tokens_avail = 2;
493 return &parser->tokens[1];
496 /* Return true if TOKEN can start a type name,
497 false otherwise. */
498 static bool
499 c_token_starts_typename (c_token *token)
501 switch (token->type)
503 case CPP_NAME:
504 switch (token->id_kind)
506 case C_ID_ID:
507 return false;
508 case C_ID_ADDRSPACE:
509 return true;
510 case C_ID_TYPENAME:
511 return true;
512 case C_ID_CLASSNAME:
513 gcc_assert (c_dialect_objc ());
514 return true;
515 default:
516 gcc_unreachable ();
518 case CPP_KEYWORD:
519 switch (token->keyword)
521 case RID_UNSIGNED:
522 case RID_LONG:
523 case RID_SHORT:
524 case RID_SIGNED:
525 case RID_COMPLEX:
526 case RID_INT:
527 case RID_CHAR:
528 case RID_FLOAT:
529 case RID_DOUBLE:
530 case RID_VOID:
531 case RID_DFLOAT32:
532 case RID_DFLOAT64:
533 case RID_DFLOAT128:
534 case RID_BOOL:
535 case RID_ENUM:
536 case RID_STRUCT:
537 case RID_UNION:
538 case RID_TYPEOF:
539 case RID_CONST:
540 case RID_ATOMIC:
541 case RID_VOLATILE:
542 case RID_RESTRICT:
543 case RID_ATTRIBUTE:
544 case RID_FRACT:
545 case RID_ACCUM:
546 case RID_SAT:
547 case RID_AUTO_TYPE:
548 return true;
549 /* UPC qualifiers */
550 case RID_SHARED:
551 case RID_STRICT:
552 case RID_RELAXED:
553 return true;
554 default:
555 if (token->keyword >= RID_FIRST_INT_N
556 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
557 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
558 return true;
559 return false;
561 case CPP_LESS:
562 if (c_dialect_objc ())
563 return true;
564 return false;
565 default:
566 return false;
570 enum c_lookahead_kind {
571 /* Always treat unknown identifiers as typenames. */
572 cla_prefer_type,
574 /* Could be parsing a nonabstract declarator. Only treat an identifier
575 as a typename if followed by another identifier or a star. */
576 cla_nonabstract_decl,
578 /* Never treat identifiers as typenames. */
579 cla_prefer_id
582 /* Return true if the next token from PARSER can start a type name,
583 false otherwise. LA specifies how to do lookahead in order to
584 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
586 static inline bool
587 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
589 c_token *token = c_parser_peek_token (parser);
590 if (c_token_starts_typename (token))
591 return true;
593 /* Try a bit harder to detect an unknown typename. */
594 if (la != cla_prefer_id
595 && token->type == CPP_NAME
596 && token->id_kind == C_ID_ID
598 /* Do not try too hard when we could have "object in array". */
599 && !parser->objc_could_be_foreach_context
601 && (la == cla_prefer_type
602 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
603 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
605 /* Only unknown identifiers. */
606 && !lookup_name (token->value))
607 return true;
609 return false;
612 /* Return true if TOKEN is a type qualifier, false otherwise. */
613 static bool
614 c_token_is_qualifier (c_token *token)
616 switch (token->type)
618 case CPP_NAME:
619 switch (token->id_kind)
621 case C_ID_ADDRSPACE:
622 return true;
623 default:
624 return false;
626 case CPP_KEYWORD:
627 switch (token->keyword)
629 case RID_CONST:
630 case RID_VOLATILE:
631 case RID_RESTRICT:
632 case RID_ATTRIBUTE:
633 case RID_ATOMIC:
634 return true;
635 case RID_SHARED:
636 case RID_STRICT:
637 case RID_RELAXED:
638 /* UPC qualifiers */
639 return true;
640 default:
641 return false;
643 case CPP_LESS:
644 return false;
645 default:
646 gcc_unreachable ();
650 /* Return true if the next token from PARSER is a type qualifier,
651 false otherwise. */
652 static inline bool
653 c_parser_next_token_is_qualifier (c_parser *parser)
655 c_token *token = c_parser_peek_token (parser);
656 return c_token_is_qualifier (token);
659 /* Return true if TOKEN can start declaration specifiers, false
660 otherwise. */
661 static bool
662 c_token_starts_declspecs (c_token *token)
664 switch (token->type)
666 case CPP_NAME:
667 switch (token->id_kind)
669 case C_ID_ID:
670 return false;
671 case C_ID_ADDRSPACE:
672 return true;
673 case C_ID_TYPENAME:
674 return true;
675 case C_ID_CLASSNAME:
676 gcc_assert (c_dialect_objc ());
677 return true;
678 default:
679 gcc_unreachable ();
681 case CPP_KEYWORD:
682 switch (token->keyword)
684 case RID_STATIC:
685 case RID_EXTERN:
686 case RID_REGISTER:
687 case RID_TYPEDEF:
688 case RID_INLINE:
689 case RID_NORETURN:
690 case RID_AUTO:
691 case RID_THREAD:
692 case RID_UNSIGNED:
693 case RID_LONG:
694 case RID_SHORT:
695 case RID_SIGNED:
696 case RID_COMPLEX:
697 case RID_INT:
698 case RID_CHAR:
699 case RID_FLOAT:
700 case RID_DOUBLE:
701 case RID_VOID:
702 case RID_DFLOAT32:
703 case RID_DFLOAT64:
704 case RID_DFLOAT128:
705 case RID_BOOL:
706 case RID_ENUM:
707 case RID_STRUCT:
708 case RID_UNION:
709 case RID_TYPEOF:
710 case RID_CONST:
711 case RID_VOLATILE:
712 case RID_RESTRICT:
713 case RID_ATTRIBUTE:
714 case RID_FRACT:
715 case RID_ACCUM:
716 case RID_SAT:
717 case RID_ALIGNAS:
718 case RID_ATOMIC:
719 case RID_AUTO_TYPE:
720 return true;
721 /* UPC qualifiers */
722 case RID_SHARED:
723 case RID_STRICT:
724 case RID_RELAXED:
725 return true;
726 default:
727 if (token->keyword >= RID_FIRST_INT_N
728 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
729 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
730 return true;
731 return false;
733 case CPP_LESS:
734 if (c_dialect_objc ())
735 return true;
736 return false;
737 default:
738 return false;
743 /* Return true if TOKEN can start declaration specifiers or a static
744 assertion, false otherwise. */
745 static bool
746 c_token_starts_declaration (c_token *token)
748 if (c_token_starts_declspecs (token)
749 || token->keyword == RID_STATIC_ASSERT)
750 return true;
751 else
752 return false;
755 /* Return true if the next token from PARSER can start declaration
756 specifiers, false otherwise. */
757 static inline bool
758 c_parser_next_token_starts_declspecs (c_parser *parser)
760 c_token *token = c_parser_peek_token (parser);
762 /* In Objective-C, a classname normally starts a declspecs unless it
763 is immediately followed by a dot. In that case, it is the
764 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
765 setter/getter on the class. c_token_starts_declspecs() can't
766 differentiate between the two cases because it only checks the
767 current token, so we have a special check here. */
768 if (c_dialect_objc ()
769 && token->type == CPP_NAME
770 && token->id_kind == C_ID_CLASSNAME
771 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
772 return false;
774 return c_token_starts_declspecs (token);
777 /* Return true if the next tokens from PARSER can start declaration
778 specifiers or a static assertion, false otherwise. */
779 static inline bool
780 c_parser_next_tokens_start_declaration (c_parser *parser)
782 c_token *token = c_parser_peek_token (parser);
784 /* Same as above. */
785 if (c_dialect_objc ()
786 && token->type == CPP_NAME
787 && token->id_kind == C_ID_CLASSNAME
788 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
789 return false;
791 /* Labels do not start declarations. */
792 if (token->type == CPP_NAME
793 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
794 return false;
796 if (c_token_starts_declaration (token))
797 return true;
799 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
800 return true;
802 return false;
805 /* Consume the next token from PARSER. */
807 static void
808 c_parser_consume_token (c_parser *parser)
810 gcc_assert (parser->tokens_avail >= 1);
811 gcc_assert (parser->tokens[0].type != CPP_EOF);
812 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
813 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
814 if (parser->tokens != &parser->tokens_buf[0])
815 parser->tokens++;
816 else if (parser->tokens_avail == 2)
817 parser->tokens[0] = parser->tokens[1];
818 parser->tokens_avail--;
821 /* Expect the current token to be a #pragma. Consume it and remember
822 that we've begun parsing a pragma. */
824 static void
825 c_parser_consume_pragma (c_parser *parser)
827 gcc_assert (!parser->in_pragma);
828 gcc_assert (parser->tokens_avail >= 1);
829 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
830 if (parser->tokens != &parser->tokens_buf[0])
831 parser->tokens++;
832 else if (parser->tokens_avail == 2)
833 parser->tokens[0] = parser->tokens[1];
834 parser->tokens_avail--;
835 parser->in_pragma = true;
838 /* Update the global input_location from TOKEN. */
839 static inline void
840 c_parser_set_source_position_from_token (c_token *token)
842 if (token->type != CPP_EOF)
844 input_location = token->location;
848 /* Issue a diagnostic of the form
849 FILE:LINE: MESSAGE before TOKEN
850 where TOKEN is the next token in the input stream of PARSER.
851 MESSAGE (specified by the caller) is usually of the form "expected
852 OTHER-TOKEN".
854 Do not issue a diagnostic if still recovering from an error.
856 ??? This is taken from the C++ parser, but building up messages in
857 this way is not i18n-friendly and some other approach should be
858 used. */
860 static void
861 c_parser_error (c_parser *parser, const char *gmsgid)
863 c_token *token = c_parser_peek_token (parser);
864 if (parser->error)
865 return;
866 parser->error = true;
867 if (!gmsgid)
868 return;
869 /* This diagnostic makes more sense if it is tagged to the line of
870 the token we just peeked at. */
871 c_parser_set_source_position_from_token (token);
872 c_parse_error (gmsgid,
873 /* Because c_parse_error does not understand
874 CPP_KEYWORD, keywords are treated like
875 identifiers. */
876 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
877 /* ??? The C parser does not save the cpp flags of a
878 token, we need to pass 0 here and we will not get
879 the source spelling of some tokens but rather the
880 canonical spelling. */
881 token->value, /*flags=*/0);
884 /* If the next token is of the indicated TYPE, consume it. Otherwise,
885 issue the error MSGID. If MSGID is NULL then a message has already
886 been produced and no message will be produced this time. Returns
887 true if found, false otherwise. */
889 static bool
890 c_parser_require (c_parser *parser,
891 enum cpp_ttype type,
892 const char *msgid)
894 if (c_parser_next_token_is (parser, type))
896 c_parser_consume_token (parser);
897 return true;
899 else
901 c_parser_error (parser, msgid);
902 return false;
906 /* If the next token is the indicated keyword, consume it. Otherwise,
907 issue the error MSGID. Returns true if found, false otherwise. */
909 static bool
910 c_parser_require_keyword (c_parser *parser,
911 enum rid keyword,
912 const char *msgid)
914 if (c_parser_next_token_is_keyword (parser, keyword))
916 c_parser_consume_token (parser);
917 return true;
919 else
921 c_parser_error (parser, msgid);
922 return false;
926 /* Like c_parser_require, except that tokens will be skipped until the
927 desired token is found. An error message is still produced if the
928 next token is not as expected. If MSGID is NULL then a message has
929 already been produced and no message will be produced this
930 time. */
932 static void
933 c_parser_skip_until_found (c_parser *parser,
934 enum cpp_ttype type,
935 const char *msgid)
937 unsigned nesting_depth = 0;
939 if (c_parser_require (parser, type, msgid))
940 return;
942 /* Skip tokens until the desired token is found. */
943 while (true)
945 /* Peek at the next token. */
946 c_token *token = c_parser_peek_token (parser);
947 /* If we've reached the token we want, consume it and stop. */
948 if (token->type == type && !nesting_depth)
950 c_parser_consume_token (parser);
951 break;
954 /* If we've run out of tokens, stop. */
955 if (token->type == CPP_EOF)
956 return;
957 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
958 return;
959 if (token->type == CPP_OPEN_BRACE
960 || token->type == CPP_OPEN_PAREN
961 || token->type == CPP_OPEN_SQUARE)
962 ++nesting_depth;
963 else if (token->type == CPP_CLOSE_BRACE
964 || token->type == CPP_CLOSE_PAREN
965 || token->type == CPP_CLOSE_SQUARE)
967 if (nesting_depth-- == 0)
968 break;
970 /* Consume this token. */
971 c_parser_consume_token (parser);
973 parser->error = false;
976 /* Skip tokens until the end of a parameter is found, but do not
977 consume the comma, semicolon or closing delimiter. */
979 static void
980 c_parser_skip_to_end_of_parameter (c_parser *parser)
982 unsigned nesting_depth = 0;
984 while (true)
986 c_token *token = c_parser_peek_token (parser);
987 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
988 && !nesting_depth)
989 break;
990 /* If we've run out of tokens, stop. */
991 if (token->type == CPP_EOF)
992 return;
993 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
994 return;
995 if (token->type == CPP_OPEN_BRACE
996 || token->type == CPP_OPEN_PAREN
997 || token->type == CPP_OPEN_SQUARE)
998 ++nesting_depth;
999 else if (token->type == CPP_CLOSE_BRACE
1000 || token->type == CPP_CLOSE_PAREN
1001 || token->type == CPP_CLOSE_SQUARE)
1003 if (nesting_depth-- == 0)
1004 break;
1006 /* Consume this token. */
1007 c_parser_consume_token (parser);
1009 parser->error = false;
1012 /* Expect to be at the end of the pragma directive and consume an
1013 end of line marker. */
1015 static void
1016 c_parser_skip_to_pragma_eol (c_parser *parser)
1018 gcc_assert (parser->in_pragma);
1019 parser->in_pragma = false;
1021 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
1022 while (true)
1024 c_token *token = c_parser_peek_token (parser);
1025 if (token->type == CPP_EOF)
1026 break;
1027 if (token->type == CPP_PRAGMA_EOL)
1029 c_parser_consume_token (parser);
1030 break;
1032 c_parser_consume_token (parser);
1035 parser->error = false;
1038 /* Skip tokens until we have consumed an entire block, or until we
1039 have consumed a non-nested ';'. */
1041 static void
1042 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1044 unsigned nesting_depth = 0;
1045 bool save_error = parser->error;
1047 while (true)
1049 c_token *token;
1051 /* Peek at the next token. */
1052 token = c_parser_peek_token (parser);
1054 switch (token->type)
1056 case CPP_EOF:
1057 return;
1059 case CPP_PRAGMA_EOL:
1060 if (parser->in_pragma)
1061 return;
1062 break;
1064 case CPP_SEMICOLON:
1065 /* If the next token is a ';', we have reached the
1066 end of the statement. */
1067 if (!nesting_depth)
1069 /* Consume the ';'. */
1070 c_parser_consume_token (parser);
1071 goto finished;
1073 break;
1075 case CPP_CLOSE_BRACE:
1076 /* If the next token is a non-nested '}', then we have
1077 reached the end of the current block. */
1078 if (nesting_depth == 0 || --nesting_depth == 0)
1080 c_parser_consume_token (parser);
1081 goto finished;
1083 break;
1085 case CPP_OPEN_BRACE:
1086 /* If it the next token is a '{', then we are entering a new
1087 block. Consume the entire block. */
1088 ++nesting_depth;
1089 break;
1091 case CPP_PRAGMA:
1092 /* If we see a pragma, consume the whole thing at once. We
1093 have some safeguards against consuming pragmas willy-nilly.
1094 Normally, we'd expect to be here with parser->error set,
1095 which disables these safeguards. But it's possible to get
1096 here for secondary error recovery, after parser->error has
1097 been cleared. */
1098 c_parser_consume_pragma (parser);
1099 c_parser_skip_to_pragma_eol (parser);
1100 parser->error = save_error;
1101 continue;
1103 default:
1104 break;
1107 c_parser_consume_token (parser);
1110 finished:
1111 parser->error = false;
1114 /* CPP's options (initialized by c-opts.c). */
1115 extern cpp_options *cpp_opts;
1117 /* Save the warning flags which are controlled by __extension__. */
1119 static inline int
1120 disable_extension_diagnostics (void)
1122 int ret = (pedantic
1123 | (warn_pointer_arith << 1)
1124 | (warn_traditional << 2)
1125 | (flag_iso << 3)
1126 | (warn_long_long << 4)
1127 | (warn_cxx_compat << 5)
1128 | (warn_overlength_strings << 6)
1129 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1130 play tricks to properly restore it. */
1131 | ((warn_c90_c99_compat == 1) << 7)
1132 | ((warn_c90_c99_compat == -1) << 8)
1133 /* Similarly for warn_c99_c11_compat. */
1134 | ((warn_c99_c11_compat == 1) << 9)
1135 | ((warn_c99_c11_compat == -1) << 10)
1137 cpp_opts->cpp_pedantic = pedantic = 0;
1138 warn_pointer_arith = 0;
1139 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1140 flag_iso = 0;
1141 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1142 warn_cxx_compat = 0;
1143 warn_overlength_strings = 0;
1144 warn_c90_c99_compat = 0;
1145 warn_c99_c11_compat = 0;
1146 return ret;
1149 /* Restore the warning flags which are controlled by __extension__.
1150 FLAGS is the return value from disable_extension_diagnostics. */
1152 static inline void
1153 restore_extension_diagnostics (int flags)
1155 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1156 warn_pointer_arith = (flags >> 1) & 1;
1157 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1158 flag_iso = (flags >> 3) & 1;
1159 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1160 warn_cxx_compat = (flags >> 5) & 1;
1161 warn_overlength_strings = (flags >> 6) & 1;
1162 /* See above for why is this needed. */
1163 warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1164 warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1167 /* Possibly kinds of declarator to parse. */
1168 typedef enum c_dtr_syn {
1169 /* A normal declarator with an identifier. */
1170 C_DTR_NORMAL,
1171 /* An abstract declarator (maybe empty). */
1172 C_DTR_ABSTRACT,
1173 /* A parameter declarator: may be either, but after a type name does
1174 not redeclare a typedef name as an identifier if it can
1175 alternatively be interpreted as a typedef name; see DR#009,
1176 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1177 following DR#249. For example, given a typedef T, "int T" and
1178 "int *T" are valid parameter declarations redeclaring T, while
1179 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1180 abstract declarators rather than involving redundant parentheses;
1181 the same applies with attributes inside the parentheses before
1182 "T". */
1183 C_DTR_PARM
1184 } c_dtr_syn;
1186 /* The binary operation precedence levels, where 0 is a dummy lowest level
1187 used for the bottom of the stack. */
1188 enum c_parser_prec {
1189 PREC_NONE,
1190 PREC_LOGOR,
1191 PREC_LOGAND,
1192 PREC_BITOR,
1193 PREC_BITXOR,
1194 PREC_BITAND,
1195 PREC_EQ,
1196 PREC_REL,
1197 PREC_SHIFT,
1198 PREC_ADD,
1199 PREC_MULT,
1200 NUM_PRECS
1203 static void c_parser_external_declaration (c_parser *);
1204 static void c_parser_asm_definition (c_parser *);
1205 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1206 bool, bool, tree *, vec<c_token>);
1207 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1208 static void c_parser_static_assert_declaration (c_parser *);
1209 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1210 bool, bool, bool, enum c_lookahead_kind);
1211 static struct c_typespec c_parser_enum_specifier (c_parser *);
1212 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1213 static tree c_parser_struct_declaration (c_parser *);
1214 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1215 static tree c_parser_alignas_specifier (c_parser *);
1216 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1217 bool *);
1218 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1219 c_dtr_syn, bool *);
1220 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1221 bool,
1222 struct c_declarator *);
1223 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1224 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1225 tree);
1226 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1227 static tree c_parser_simple_asm_expr (c_parser *);
1228 static tree c_parser_attributes (c_parser *);
1229 static struct c_type_name *c_parser_type_name (c_parser *);
1230 static struct c_expr c_parser_initializer (c_parser *);
1231 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1232 static void c_parser_initelt (c_parser *, struct obstack *);
1233 static void c_parser_initval (c_parser *, struct c_expr *,
1234 struct obstack *);
1235 static tree c_parser_compound_statement (c_parser *);
1236 static void c_parser_compound_statement_nostart (c_parser *);
1237 static void c_parser_label (c_parser *);
1238 static void c_parser_statement (c_parser *);
1239 static void c_parser_statement_after_labels (c_parser *);
1240 static void c_parser_if_statement (c_parser *);
1241 static void c_parser_switch_statement (c_parser *);
1242 static void c_parser_while_statement (c_parser *, bool);
1243 static void c_parser_do_statement (c_parser *, bool);
1244 static void c_parser_for_statement (c_parser *, bool);
1245 static tree c_parser_asm_statement (c_parser *);
1246 static tree c_parser_asm_operands (c_parser *);
1247 static tree c_parser_asm_goto_operands (c_parser *);
1248 static tree c_parser_asm_clobbers (c_parser *);
1249 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1250 tree = NULL_TREE);
1251 static struct c_expr c_parser_conditional_expression (c_parser *,
1252 struct c_expr *, tree);
1253 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1254 tree);
1255 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1256 static struct c_expr c_parser_unary_expression (c_parser *);
1257 static struct c_expr c_parser_sizeof_expression (c_parser *);
1258 static struct c_expr c_parser_alignof_expression (c_parser *);
1259 static struct c_expr c_parser_postfix_expression (c_parser *);
1260 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1261 struct c_type_name *,
1262 location_t);
1263 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1264 location_t loc,
1265 struct c_expr);
1266 static tree c_parser_transaction (c_parser *, enum rid);
1267 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1268 static tree c_parser_transaction_cancel (c_parser *);
1269 static struct c_expr c_parser_expression (c_parser *);
1270 static struct c_expr c_parser_expression_conv (c_parser *);
1271 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1272 vec<tree, va_gc> **, location_t *,
1273 tree *, vec<location_t> *,
1274 unsigned int * = NULL);
1275 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1276 static void c_parser_oacc_update (c_parser *);
1277 static tree c_parser_oacc_loop (location_t, c_parser *, char *);
1278 static void c_parser_omp_construct (c_parser *);
1279 static void c_parser_omp_threadprivate (c_parser *);
1280 static void c_parser_omp_barrier (c_parser *);
1281 static void c_parser_omp_flush (c_parser *);
1282 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1283 tree, tree *);
1284 static void c_parser_omp_taskwait (c_parser *);
1285 static void c_parser_omp_taskyield (c_parser *);
1286 static void c_parser_omp_cancel (c_parser *);
1287 static void c_parser_omp_cancellation_point (c_parser *);
1289 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1290 pragma_stmt, pragma_compound };
1291 static bool c_parser_pragma (c_parser *, enum pragma_context);
1292 static bool c_parser_omp_target (c_parser *, enum pragma_context);
1293 static void c_parser_omp_end_declare_target (c_parser *);
1294 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1296 /* These Objective-C parser functions are only ever called when
1297 compiling Objective-C. */
1298 static void c_parser_objc_class_definition (c_parser *, tree);
1299 static void c_parser_objc_class_instance_variables (c_parser *);
1300 static void c_parser_objc_class_declaration (c_parser *);
1301 static void c_parser_objc_alias_declaration (c_parser *);
1302 static void c_parser_objc_protocol_definition (c_parser *, tree);
1303 static bool c_parser_objc_method_type (c_parser *);
1304 static void c_parser_objc_method_definition (c_parser *);
1305 static void c_parser_objc_methodprotolist (c_parser *);
1306 static void c_parser_objc_methodproto (c_parser *);
1307 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1308 static tree c_parser_objc_type_name (c_parser *);
1309 static tree c_parser_objc_protocol_refs (c_parser *);
1310 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1311 static void c_parser_objc_synchronized_statement (c_parser *);
1312 static tree c_parser_objc_selector (c_parser *);
1313 static tree c_parser_objc_selector_arg (c_parser *);
1314 static tree c_parser_objc_receiver (c_parser *);
1315 static tree c_parser_objc_message_args (c_parser *);
1316 static tree c_parser_objc_keywordexpr (c_parser *);
1317 static void c_parser_objc_at_property_declaration (c_parser *);
1318 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1319 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1320 static bool c_parser_objc_diagnose_bad_element_prefix
1321 (c_parser *, struct c_declspecs *);
1323 /* Cilk Plus supporting routines. */
1324 static void c_parser_cilk_simd (c_parser *);
1325 static void c_parser_cilk_for (c_parser *, tree);
1326 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
1327 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
1328 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
1329 static void c_parser_cilk_grainsize (c_parser *);
1331 /* These UPC parser functions are only ever called when
1332 compiling UPC. */
1333 static void c_parser_upc_forall_statement (c_parser *);
1334 static void c_parser_upc_sync_statement (c_parser *, int);
1335 static void c_parser_upc_shared_qual (source_location,
1336 c_parser *,
1337 struct c_declspecs *);
1339 /* Parse a translation unit (C90 6.7, C99 6.9).
1341 translation-unit:
1342 external-declarations
1344 external-declarations:
1345 external-declaration
1346 external-declarations external-declaration
1348 GNU extensions:
1350 translation-unit:
1351 empty
1354 static void
1355 c_parser_translation_unit (c_parser *parser)
1357 if (c_parser_next_token_is (parser, CPP_EOF))
1359 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1360 "ISO C forbids an empty translation unit");
1362 else
1364 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1365 mark_valid_location_for_stdc_pragma (false);
1368 ggc_collect ();
1369 c_parser_external_declaration (parser);
1370 obstack_free (&parser_obstack, obstack_position);
1372 while (c_parser_next_token_is_not (parser, CPP_EOF));
1376 /* Parse an external declaration (C90 6.7, C99 6.9).
1378 external-declaration:
1379 function-definition
1380 declaration
1382 GNU extensions:
1384 external-declaration:
1385 asm-definition
1387 __extension__ external-declaration
1389 Objective-C:
1391 external-declaration:
1392 objc-class-definition
1393 objc-class-declaration
1394 objc-alias-declaration
1395 objc-protocol-definition
1396 objc-method-definition
1397 @end
1400 static void
1401 c_parser_external_declaration (c_parser *parser)
1403 int ext;
1404 switch (c_parser_peek_token (parser)->type)
1406 case CPP_KEYWORD:
1407 switch (c_parser_peek_token (parser)->keyword)
1409 case RID_EXTENSION:
1410 ext = disable_extension_diagnostics ();
1411 c_parser_consume_token (parser);
1412 c_parser_external_declaration (parser);
1413 restore_extension_diagnostics (ext);
1414 break;
1415 case RID_ASM:
1416 c_parser_asm_definition (parser);
1417 break;
1418 case RID_AT_INTERFACE:
1419 case RID_AT_IMPLEMENTATION:
1420 gcc_assert (c_dialect_objc ());
1421 c_parser_objc_class_definition (parser, NULL_TREE);
1422 break;
1423 case RID_AT_CLASS:
1424 gcc_assert (c_dialect_objc ());
1425 c_parser_objc_class_declaration (parser);
1426 break;
1427 case RID_AT_ALIAS:
1428 gcc_assert (c_dialect_objc ());
1429 c_parser_objc_alias_declaration (parser);
1430 break;
1431 case RID_AT_PROTOCOL:
1432 gcc_assert (c_dialect_objc ());
1433 c_parser_objc_protocol_definition (parser, NULL_TREE);
1434 break;
1435 case RID_AT_PROPERTY:
1436 gcc_assert (c_dialect_objc ());
1437 c_parser_objc_at_property_declaration (parser);
1438 break;
1439 case RID_AT_SYNTHESIZE:
1440 gcc_assert (c_dialect_objc ());
1441 c_parser_objc_at_synthesize_declaration (parser);
1442 break;
1443 case RID_AT_DYNAMIC:
1444 gcc_assert (c_dialect_objc ());
1445 c_parser_objc_at_dynamic_declaration (parser);
1446 break;
1447 case RID_AT_END:
1448 gcc_assert (c_dialect_objc ());
1449 c_parser_consume_token (parser);
1450 objc_finish_implementation ();
1451 break;
1452 default:
1453 goto decl_or_fndef;
1455 break;
1456 case CPP_SEMICOLON:
1457 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1458 "ISO C does not allow extra %<;%> outside of a function");
1459 c_parser_consume_token (parser);
1460 break;
1461 case CPP_PRAGMA:
1462 mark_valid_location_for_stdc_pragma (true);
1463 c_parser_pragma (parser, pragma_external);
1464 mark_valid_location_for_stdc_pragma (false);
1465 break;
1466 case CPP_PLUS:
1467 case CPP_MINUS:
1468 if (c_dialect_objc ())
1470 c_parser_objc_method_definition (parser);
1471 break;
1473 /* Else fall through, and yield a syntax error trying to parse
1474 as a declaration or function definition. */
1475 default:
1476 decl_or_fndef:
1477 /* A declaration or a function definition (or, in Objective-C,
1478 an @interface or @protocol with prefix attributes). We can
1479 only tell which after parsing the declaration specifiers, if
1480 any, and the first declarator. */
1481 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1482 NULL, vNULL);
1483 break;
1487 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1489 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1490 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1491 accepted; otherwise (old-style parameter declarations) only other
1492 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1493 assertion is accepted; otherwise (old-style parameter declarations)
1494 it is not. If NESTED is true, we are inside a function or parsing
1495 old-style parameter declarations; any functions encountered are
1496 nested functions and declaration specifiers are required; otherwise
1497 we are at top level and functions are normal functions and
1498 declaration specifiers may be optional. If EMPTY_OK is true, empty
1499 declarations are OK (subject to all other constraints); otherwise
1500 (old-style parameter declarations) they are diagnosed. If
1501 START_ATTR_OK is true, the declaration specifiers may start with
1502 attributes; otherwise they may not.
1503 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1504 declaration when parsing an Objective-C foreach statement.
1506 declaration:
1507 declaration-specifiers init-declarator-list[opt] ;
1508 static_assert-declaration
1510 function-definition:
1511 declaration-specifiers[opt] declarator declaration-list[opt]
1512 compound-statement
1514 declaration-list:
1515 declaration
1516 declaration-list declaration
1518 init-declarator-list:
1519 init-declarator
1520 init-declarator-list , init-declarator
1522 init-declarator:
1523 declarator simple-asm-expr[opt] attributes[opt]
1524 declarator simple-asm-expr[opt] attributes[opt] = initializer
1526 GNU extensions:
1528 nested-function-definition:
1529 declaration-specifiers declarator declaration-list[opt]
1530 compound-statement
1532 Objective-C:
1533 attributes objc-class-definition
1534 attributes objc-category-definition
1535 attributes objc-protocol-definition
1537 The simple-asm-expr and attributes are GNU extensions.
1539 This function does not handle __extension__; that is handled in its
1540 callers. ??? Following the old parser, __extension__ may start
1541 external declarations, declarations in functions and declarations
1542 at the start of "for" loops, but not old-style parameter
1543 declarations.
1545 C99 requires declaration specifiers in a function definition; the
1546 absence is diagnosed through the diagnosis of implicit int. In GNU
1547 C we also allow but diagnose declarations without declaration
1548 specifiers, but only at top level (elsewhere they conflict with
1549 other syntax).
1551 In Objective-C, declarations of the looping variable in a foreach
1552 statement are exceptionally terminated by 'in' (for example, 'for
1553 (NSObject *object in array) { ... }').
1555 OpenMP:
1557 declaration:
1558 threadprivate-directive */
1560 static void
1561 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1562 bool static_assert_ok, bool empty_ok,
1563 bool nested, bool start_attr_ok,
1564 tree *objc_foreach_object_declaration,
1565 vec<c_token> omp_declare_simd_clauses)
1567 struct c_declspecs *specs;
1568 tree prefix_attrs;
1569 tree all_prefix_attrs;
1570 bool diagnosed_no_specs = false;
1571 location_t here = c_parser_peek_token (parser)->location;
1573 if (static_assert_ok
1574 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1576 c_parser_static_assert_declaration (parser);
1577 return;
1579 specs = build_null_declspecs ();
1581 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1582 if (c_parser_peek_token (parser)->type == CPP_NAME
1583 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1584 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1585 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1586 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1588 error_at (here, "unknown type name %qE",
1589 c_parser_peek_token (parser)->value);
1591 /* Parse declspecs normally to get a correct pointer type, but avoid
1592 a further "fails to be a type name" error. Refuse nested functions
1593 since it is not how the user likely wants us to recover. */
1594 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1595 c_parser_peek_token (parser)->keyword = RID_VOID;
1596 c_parser_peek_token (parser)->value = error_mark_node;
1597 fndef_ok = !nested;
1600 c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1601 true, true, cla_nonabstract_decl);
1602 if (parser->error)
1604 c_parser_skip_to_end_of_block_or_statement (parser);
1605 return;
1607 if (nested && !specs->declspecs_seen_p)
1609 c_parser_error (parser, "expected declaration specifiers");
1610 c_parser_skip_to_end_of_block_or_statement (parser);
1611 return;
1613 finish_declspecs (specs);
1614 bool auto_type_p = specs->typespec_word == cts_auto_type;
1615 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1617 if (auto_type_p)
1618 error_at (here, "%<__auto_type%> in empty declaration");
1619 else if (empty_ok)
1620 shadow_tag (specs);
1621 else
1623 shadow_tag_warned (specs, 1);
1624 pedwarn (here, 0, "empty declaration");
1626 c_parser_consume_token (parser);
1627 return;
1630 /* Provide better error recovery. Note that a type name here is usually
1631 better diagnosed as a redeclaration. */
1632 if (empty_ok
1633 && specs->typespec_kind == ctsk_tagdef
1634 && c_parser_next_token_starts_declspecs (parser)
1635 && !c_parser_next_token_is (parser, CPP_NAME))
1637 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1638 parser->error = false;
1639 shadow_tag_warned (specs, 1);
1640 return;
1642 else if (c_dialect_objc () && !auto_type_p)
1644 /* Prefix attributes are an error on method decls. */
1645 switch (c_parser_peek_token (parser)->type)
1647 case CPP_PLUS:
1648 case CPP_MINUS:
1649 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1650 return;
1651 if (specs->attrs)
1653 warning_at (c_parser_peek_token (parser)->location,
1654 OPT_Wattributes,
1655 "prefix attributes are ignored for methods");
1656 specs->attrs = NULL_TREE;
1658 if (fndef_ok)
1659 c_parser_objc_method_definition (parser);
1660 else
1661 c_parser_objc_methodproto (parser);
1662 return;
1663 break;
1664 default:
1665 break;
1667 /* This is where we parse 'attributes @interface ...',
1668 'attributes @implementation ...', 'attributes @protocol ...'
1669 (where attributes could be, for example, __attribute__
1670 ((deprecated)).
1672 switch (c_parser_peek_token (parser)->keyword)
1674 case RID_AT_INTERFACE:
1676 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1677 return;
1678 c_parser_objc_class_definition (parser, specs->attrs);
1679 return;
1681 break;
1682 case RID_AT_IMPLEMENTATION:
1684 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1685 return;
1686 if (specs->attrs)
1688 warning_at (c_parser_peek_token (parser)->location,
1689 OPT_Wattributes,
1690 "prefix attributes are ignored for implementations");
1691 specs->attrs = NULL_TREE;
1693 c_parser_objc_class_definition (parser, NULL_TREE);
1694 return;
1696 break;
1697 case RID_AT_PROTOCOL:
1699 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1700 return;
1701 c_parser_objc_protocol_definition (parser, specs->attrs);
1702 return;
1704 break;
1705 case RID_AT_ALIAS:
1706 case RID_AT_CLASS:
1707 case RID_AT_END:
1708 case RID_AT_PROPERTY:
1709 if (specs->attrs)
1711 c_parser_error (parser, "unexpected attribute");
1712 specs->attrs = NULL;
1714 break;
1715 default:
1716 break;
1720 pending_xref_error ();
1721 prefix_attrs = specs->attrs;
1722 all_prefix_attrs = prefix_attrs;
1723 specs->attrs = NULL_TREE;
1724 while (true)
1726 struct c_declarator *declarator;
1727 bool dummy = false;
1728 timevar_id_t tv;
1729 tree fnbody;
1730 /* Declaring either one or more declarators (in which case we
1731 should diagnose if there were no declaration specifiers) or a
1732 function definition (in which case the diagnostic for
1733 implicit int suffices). */
1734 declarator = c_parser_declarator (parser,
1735 specs->typespec_kind != ctsk_none,
1736 C_DTR_NORMAL, &dummy);
1737 if (declarator == NULL)
1739 if (omp_declare_simd_clauses.exists ()
1740 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1741 c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1742 omp_declare_simd_clauses);
1743 c_parser_skip_to_end_of_block_or_statement (parser);
1744 return;
1746 if (auto_type_p && declarator->kind != cdk_id)
1748 error_at (here,
1749 "%<__auto_type%> requires a plain identifier"
1750 " as declarator");
1751 c_parser_skip_to_end_of_block_or_statement (parser);
1752 return;
1754 if (c_parser_next_token_is (parser, CPP_EQ)
1755 || c_parser_next_token_is (parser, CPP_COMMA)
1756 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1757 || c_parser_next_token_is_keyword (parser, RID_ASM)
1758 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1759 || c_parser_next_token_is_keyword (parser, RID_IN))
1761 tree asm_name = NULL_TREE;
1762 tree postfix_attrs = NULL_TREE;
1763 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1765 diagnosed_no_specs = true;
1766 pedwarn (here, 0, "data definition has no type or storage class");
1768 /* Having seen a data definition, there cannot now be a
1769 function definition. */
1770 fndef_ok = false;
1771 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1772 asm_name = c_parser_simple_asm_expr (parser);
1773 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1775 postfix_attrs = c_parser_attributes (parser);
1776 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1778 /* This means there is an attribute specifier after
1779 the declarator in a function definition. Provide
1780 some more information for the user. */
1781 error_at (here, "attributes should be specified before the "
1782 "declarator in a function definition");
1783 c_parser_skip_to_end_of_block_or_statement (parser);
1784 return;
1787 if (c_parser_next_token_is (parser, CPP_EQ))
1789 tree d;
1790 struct c_expr init;
1791 location_t init_loc;
1792 c_parser_consume_token (parser);
1793 if (auto_type_p)
1795 start_init (NULL_TREE, asm_name, global_bindings_p ());
1796 init_loc = c_parser_peek_token (parser)->location;
1797 init = c_parser_expr_no_commas (parser, NULL);
1798 if (TREE_CODE (init.value) == COMPONENT_REF
1799 && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
1800 error_at (here,
1801 "%<__auto_type%> used with a bit-field"
1802 " initializer");
1803 init = convert_lvalue_to_rvalue (init_loc, init, true, true);
1804 tree init_type = TREE_TYPE (init.value);
1805 /* As with typeof, remove all qualifiers from atomic types. */
1806 if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
1807 init_type
1808 = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
1809 bool vm_type = variably_modified_type_p (init_type,
1810 NULL_TREE);
1811 if (vm_type)
1812 init.value = c_save_expr (init.value);
1813 finish_init ();
1814 specs->typespec_kind = ctsk_typeof;
1815 specs->locations[cdw_typedef] = init_loc;
1816 specs->typedef_p = true;
1817 specs->type = init_type;
1818 if (vm_type)
1820 bool maybe_const = true;
1821 tree type_expr = c_fully_fold (init.value, false,
1822 &maybe_const);
1823 specs->expr_const_operands &= maybe_const;
1824 if (specs->expr)
1825 specs->expr = build2 (COMPOUND_EXPR,
1826 TREE_TYPE (type_expr),
1827 specs->expr, type_expr);
1828 else
1829 specs->expr = type_expr;
1831 d = start_decl (declarator, specs, true,
1832 chainon (postfix_attrs, all_prefix_attrs));
1833 if (!d)
1834 d = error_mark_node;
1835 if (omp_declare_simd_clauses.exists ()
1836 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1837 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1838 omp_declare_simd_clauses);
1840 else
1842 /* The declaration of the variable is in effect while
1843 its initializer is parsed. */
1844 d = start_decl (declarator, specs, true,
1845 chainon (postfix_attrs, all_prefix_attrs));
1846 if (!d)
1847 d = error_mark_node;
1848 if (omp_declare_simd_clauses.exists ()
1849 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1850 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1851 omp_declare_simd_clauses);
1852 start_init (d, asm_name, global_bindings_p ());
1853 init_loc = c_parser_peek_token (parser)->location;
1854 init = c_parser_initializer (parser);
1855 finish_init ();
1857 if (d != error_mark_node)
1859 maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
1860 finish_decl (d, init_loc, init.value,
1861 init.original_type, asm_name);
1864 else
1866 if (auto_type_p)
1868 error_at (here,
1869 "%<__auto_type%> requires an initialized "
1870 "data declaration");
1871 c_parser_skip_to_end_of_block_or_statement (parser);
1872 return;
1874 tree d = start_decl (declarator, specs, false,
1875 chainon (postfix_attrs,
1876 all_prefix_attrs));
1877 if (omp_declare_simd_clauses.exists ()
1878 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1880 tree parms = NULL_TREE;
1881 if (d && TREE_CODE (d) == FUNCTION_DECL)
1883 struct c_declarator *ce = declarator;
1884 while (ce != NULL)
1885 if (ce->kind == cdk_function)
1887 parms = ce->u.arg_info->parms;
1888 break;
1890 else
1891 ce = ce->declarator;
1893 if (parms)
1894 temp_store_parm_decls (d, parms);
1895 c_finish_omp_declare_simd (parser, d, parms,
1896 omp_declare_simd_clauses);
1897 if (parms)
1898 temp_pop_parm_decls ();
1900 if (d)
1901 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1902 NULL_TREE, asm_name);
1904 if (c_parser_next_token_is_keyword (parser, RID_IN))
1906 if (d)
1907 *objc_foreach_object_declaration = d;
1908 else
1909 *objc_foreach_object_declaration = error_mark_node;
1912 if (c_parser_next_token_is (parser, CPP_COMMA))
1914 if (auto_type_p)
1916 error_at (here,
1917 "%<__auto_type%> may only be used with"
1918 " a single declarator");
1919 c_parser_skip_to_end_of_block_or_statement (parser);
1920 return;
1922 c_parser_consume_token (parser);
1923 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1924 all_prefix_attrs = chainon (c_parser_attributes (parser),
1925 prefix_attrs);
1926 else
1927 all_prefix_attrs = prefix_attrs;
1928 continue;
1930 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1932 c_parser_consume_token (parser);
1933 return;
1935 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1937 /* This can only happen in Objective-C: we found the
1938 'in' that terminates the declaration inside an
1939 Objective-C foreach statement. Do not consume the
1940 token, so that the caller can use it to determine
1941 that this indeed is a foreach context. */
1942 return;
1944 else
1946 c_parser_error (parser, "expected %<,%> or %<;%>");
1947 c_parser_skip_to_end_of_block_or_statement (parser);
1948 return;
1951 else if (auto_type_p)
1953 error_at (here,
1954 "%<__auto_type%> requires an initialized data declaration");
1955 c_parser_skip_to_end_of_block_or_statement (parser);
1956 return;
1958 else if (!fndef_ok)
1960 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1961 "%<asm%> or %<__attribute__%>");
1962 c_parser_skip_to_end_of_block_or_statement (parser);
1963 return;
1965 /* Function definition (nested or otherwise). */
1966 if (nested)
1968 pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
1969 c_push_function_context ();
1971 if (!start_function (specs, declarator, all_prefix_attrs))
1973 /* This can appear in many cases looking nothing like a
1974 function definition, so we don't give a more specific
1975 error suggesting there was one. */
1976 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1977 "or %<__attribute__%>");
1978 if (nested)
1979 c_pop_function_context ();
1980 break;
1983 if (DECL_DECLARED_INLINE_P (current_function_decl))
1984 tv = TV_PARSE_INLINE;
1985 else
1986 tv = TV_PARSE_FUNC;
1987 timevar_push (tv);
1989 /* Parse old-style parameter declarations. ??? Attributes are
1990 not allowed to start declaration specifiers here because of a
1991 syntax conflict between a function declaration with attribute
1992 suffix and a function definition with an attribute prefix on
1993 first old-style parameter declaration. Following the old
1994 parser, they are not accepted on subsequent old-style
1995 parameter declarations either. However, there is no
1996 ambiguity after the first declaration, nor indeed on the
1997 first as long as we don't allow postfix attributes after a
1998 declarator with a nonempty identifier list in a definition;
1999 and postfix attributes have never been accepted here in
2000 function definitions either. */
2001 while (c_parser_next_token_is_not (parser, CPP_EOF)
2002 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
2003 c_parser_declaration_or_fndef (parser, false, false, false,
2004 true, false, NULL, vNULL);
2005 store_parm_decls ();
2006 if (omp_declare_simd_clauses.exists ()
2007 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
2008 c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
2009 omp_declare_simd_clauses);
2010 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
2011 = c_parser_peek_token (parser)->location;
2012 fnbody = c_parser_compound_statement (parser);
2013 if (flag_cilkplus && contains_array_notation_expr (fnbody))
2014 fnbody = expand_array_notation_exprs (fnbody);
2015 if (nested)
2017 tree decl = current_function_decl;
2018 /* Mark nested functions as needing static-chain initially.
2019 lower_nested_functions will recompute it but the
2020 DECL_STATIC_CHAIN flag is also used before that happens,
2021 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2022 DECL_STATIC_CHAIN (decl) = 1;
2023 add_stmt (fnbody);
2024 finish_function ();
2025 c_pop_function_context ();
2026 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
2028 else
2030 add_stmt (fnbody);
2031 finish_function ();
2034 timevar_pop (tv);
2035 break;
2039 /* Parse an asm-definition (asm() outside a function body). This is a
2040 GNU extension.
2042 asm-definition:
2043 simple-asm-expr ;
2046 static void
2047 c_parser_asm_definition (c_parser *parser)
2049 tree asm_str = c_parser_simple_asm_expr (parser);
2050 if (asm_str)
2051 symtab->finalize_toplevel_asm (asm_str);
2052 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2055 /* Parse a static assertion (C11 6.7.10).
2057 static_assert-declaration:
2058 static_assert-declaration-no-semi ;
2061 static void
2062 c_parser_static_assert_declaration (c_parser *parser)
2064 c_parser_static_assert_declaration_no_semi (parser);
2065 if (parser->error
2066 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2067 c_parser_skip_to_end_of_block_or_statement (parser);
2070 /* Parse a static assertion (C11 6.7.10), without the trailing
2071 semicolon.
2073 static_assert-declaration-no-semi:
2074 _Static_assert ( constant-expression , string-literal )
2077 static void
2078 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2080 location_t assert_loc, value_loc;
2081 tree value;
2082 tree string;
2084 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2085 assert_loc = c_parser_peek_token (parser)->location;
2086 if (flag_isoc99)
2087 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2088 "ISO C99 does not support %<_Static_assert%>");
2089 else
2090 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2091 "ISO C90 does not support %<_Static_assert%>");
2092 c_parser_consume_token (parser);
2093 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2094 return;
2095 value_loc = c_parser_peek_token (parser)->location;
2096 value = c_parser_expr_no_commas (parser, NULL).value;
2097 parser->lex_untranslated_string = true;
2098 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2100 parser->lex_untranslated_string = false;
2101 return;
2103 switch (c_parser_peek_token (parser)->type)
2105 case CPP_STRING:
2106 case CPP_STRING16:
2107 case CPP_STRING32:
2108 case CPP_WSTRING:
2109 case CPP_UTF8STRING:
2110 string = c_parser_peek_token (parser)->value;
2111 c_parser_consume_token (parser);
2112 parser->lex_untranslated_string = false;
2113 break;
2114 default:
2115 c_parser_error (parser, "expected string literal");
2116 parser->lex_untranslated_string = false;
2117 return;
2119 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2121 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2123 error_at (value_loc, "expression in static assertion is not an integer");
2124 return;
2126 if (TREE_CODE (value) != INTEGER_CST)
2128 value = c_fully_fold (value, false, NULL);
2129 /* Strip no-op conversions. */
2130 STRIP_TYPE_NOPS (value);
2131 if (TREE_CODE (value) == INTEGER_CST)
2132 pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2133 "is not an integer constant expression");
2135 if (TREE_CODE (value) != INTEGER_CST)
2137 error_at (value_loc, "expression in static assertion is not constant");
2138 return;
2140 constant_expression_warning (value);
2141 if (integer_zerop (value))
2142 error_at (assert_loc, "static assertion failed: %E", string);
2145 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2146 6.7), adding them to SPECS (which may already include some).
2147 Storage class specifiers are accepted iff SCSPEC_OK; type
2148 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2149 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2150 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2152 declaration-specifiers:
2153 storage-class-specifier declaration-specifiers[opt]
2154 type-specifier declaration-specifiers[opt]
2155 type-qualifier declaration-specifiers[opt]
2156 function-specifier declaration-specifiers[opt]
2157 alignment-specifier declaration-specifiers[opt]
2159 Function specifiers (inline) are from C99, and are currently
2160 handled as storage class specifiers, as is __thread. Alignment
2161 specifiers are from C11.
2163 C90 6.5.1, C99 6.7.1:
2164 storage-class-specifier:
2165 typedef
2166 extern
2167 static
2168 auto
2169 register
2170 _Thread_local
2172 (_Thread_local is new in C11.)
2174 C99 6.7.4:
2175 function-specifier:
2176 inline
2177 _Noreturn
2179 (_Noreturn is new in C11.)
2181 C90 6.5.2, C99 6.7.2:
2182 type-specifier:
2183 void
2184 char
2185 short
2187 long
2188 float
2189 double
2190 signed
2191 unsigned
2192 _Bool
2193 _Complex
2194 [_Imaginary removed in C99 TC2]
2195 struct-or-union-specifier
2196 enum-specifier
2197 typedef-name
2198 atomic-type-specifier
2200 (_Bool and _Complex are new in C99.)
2201 (atomic-type-specifier is new in C11.)
2203 C90 6.5.3, C99 6.7.3:
2205 type-qualifier:
2206 const
2207 restrict
2208 volatile
2209 address-space-qualifier
2210 _Atomic
2212 (restrict is new in C99.)
2213 (_Atomic is new in C11.)
2215 GNU extensions:
2217 declaration-specifiers:
2218 attributes declaration-specifiers[opt]
2220 type-qualifier:
2221 address-space
2223 address-space:
2224 identifier recognized by the target
2226 storage-class-specifier:
2227 __thread
2229 type-specifier:
2230 typeof-specifier
2231 __auto_type
2232 __intN
2233 _Decimal32
2234 _Decimal64
2235 _Decimal128
2236 _Fract
2237 _Accum
2238 _Sat
2240 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2241 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2243 atomic-type-specifier
2244 _Atomic ( type-name )
2246 Objective-C:
2248 type-specifier:
2249 class-name objc-protocol-refs[opt]
2250 typedef-name objc-protocol-refs
2251 objc-protocol-refs
2254 static void
2255 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2256 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2257 bool alignspec_ok, bool auto_type_ok,
2258 enum c_lookahead_kind la)
2260 bool attrs_ok = start_attr_ok;
2261 bool seen_type = specs->typespec_kind != ctsk_none;
2263 if (!typespec_ok)
2264 gcc_assert (la == cla_prefer_id);
2266 while (c_parser_next_token_is (parser, CPP_NAME)
2267 || c_parser_next_token_is (parser, CPP_KEYWORD)
2268 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2270 struct c_typespec t;
2271 tree attrs;
2272 tree align;
2273 location_t loc = c_parser_peek_token (parser)->location;
2275 /* If we cannot accept a type, exit if the next token must start
2276 one. Also, if we already have seen a tagged definition,
2277 a typename would be an error anyway and likely the user
2278 has simply forgotten a semicolon, so we exit. */
2279 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2280 && c_parser_next_tokens_start_typename (parser, la)
2281 && !c_parser_next_token_is_qualifier (parser))
2282 break;
2284 if (c_parser_next_token_is (parser, CPP_NAME))
2286 c_token *name_token = c_parser_peek_token (parser);
2287 tree value = name_token->value;
2288 c_id_kind kind = name_token->id_kind;
2290 if (kind == C_ID_ADDRSPACE)
2292 addr_space_t as
2293 = name_token->keyword - RID_FIRST_ADDR_SPACE;
2294 declspecs_add_addrspace (name_token->location, specs, as);
2295 c_parser_consume_token (parser);
2296 attrs_ok = true;
2297 continue;
2300 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2302 /* If we cannot accept a type, and the next token must start one,
2303 exit. Do the same if we already have seen a tagged definition,
2304 since it would be an error anyway and likely the user has simply
2305 forgotten a semicolon. */
2306 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2307 break;
2309 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2310 a C_ID_CLASSNAME. */
2311 c_parser_consume_token (parser);
2312 seen_type = true;
2313 attrs_ok = true;
2314 if (kind == C_ID_ID)
2316 error_at (loc, "unknown type name %qE", value);
2317 t.kind = ctsk_typedef;
2318 t.spec = error_mark_node;
2320 else if (kind == C_ID_TYPENAME
2321 && (!c_dialect_objc ()
2322 || c_parser_next_token_is_not (parser, CPP_LESS)))
2324 t.kind = ctsk_typedef;
2325 /* For a typedef name, record the meaning, not the name.
2326 In case of 'foo foo, bar;'. */
2327 t.spec = lookup_name (value);
2329 else
2331 tree proto = NULL_TREE;
2332 gcc_assert (c_dialect_objc ());
2333 t.kind = ctsk_objc;
2334 if (c_parser_next_token_is (parser, CPP_LESS))
2335 proto = c_parser_objc_protocol_refs (parser);
2336 t.spec = objc_get_protocol_qualified_type (value, proto);
2338 t.expr = NULL_TREE;
2339 t.expr_const_operands = true;
2340 declspecs_add_type (name_token->location, specs, t);
2341 continue;
2343 if (c_parser_next_token_is (parser, CPP_LESS))
2345 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2346 nisse@lysator.liu.se. */
2347 tree proto;
2348 gcc_assert (c_dialect_objc ());
2349 if (!typespec_ok || seen_type)
2350 break;
2351 proto = c_parser_objc_protocol_refs (parser);
2352 t.kind = ctsk_objc;
2353 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2354 t.expr = NULL_TREE;
2355 t.expr_const_operands = true;
2356 declspecs_add_type (loc, specs, t);
2357 continue;
2359 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2360 switch (c_parser_peek_token (parser)->keyword)
2362 case RID_STATIC:
2363 case RID_EXTERN:
2364 case RID_REGISTER:
2365 case RID_TYPEDEF:
2366 case RID_INLINE:
2367 case RID_NORETURN:
2368 case RID_AUTO:
2369 case RID_THREAD:
2370 if (!scspec_ok)
2371 goto out;
2372 attrs_ok = true;
2373 /* TODO: Distinguish between function specifiers (inline, noreturn)
2374 and storage class specifiers, either here or in
2375 declspecs_add_scspec. */
2376 declspecs_add_scspec (loc, specs,
2377 c_parser_peek_token (parser)->value);
2378 c_parser_consume_token (parser);
2379 break;
2380 case RID_AUTO_TYPE:
2381 if (!auto_type_ok)
2382 goto out;
2383 /* Fall through. */
2384 case RID_UNSIGNED:
2385 case RID_LONG:
2386 case RID_SHORT:
2387 case RID_SIGNED:
2388 case RID_COMPLEX:
2389 case RID_INT:
2390 case RID_CHAR:
2391 case RID_FLOAT:
2392 case RID_DOUBLE:
2393 case RID_VOID:
2394 case RID_DFLOAT32:
2395 case RID_DFLOAT64:
2396 case RID_DFLOAT128:
2397 case RID_BOOL:
2398 case RID_FRACT:
2399 case RID_ACCUM:
2400 case RID_SAT:
2401 case RID_INT_N_0:
2402 case RID_INT_N_1:
2403 case RID_INT_N_2:
2404 case RID_INT_N_3:
2405 if (!typespec_ok)
2406 goto out;
2407 attrs_ok = true;
2408 seen_type = true;
2409 if (c_dialect_objc ())
2410 parser->objc_need_raw_identifier = true;
2411 t.kind = ctsk_resword;
2412 t.spec = c_parser_peek_token (parser)->value;
2413 t.expr = NULL_TREE;
2414 t.expr_const_operands = true;
2415 declspecs_add_type (loc, specs, t);
2416 c_parser_consume_token (parser);
2417 break;
2418 case RID_ENUM:
2419 if (!typespec_ok)
2420 goto out;
2421 attrs_ok = true;
2422 seen_type = true;
2423 t = c_parser_enum_specifier (parser);
2424 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2425 declspecs_add_type (loc, specs, t);
2426 break;
2427 case RID_STRUCT:
2428 case RID_UNION:
2429 if (!typespec_ok)
2430 goto out;
2431 attrs_ok = true;
2432 seen_type = true;
2433 t = c_parser_struct_or_union_specifier (parser);
2434 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2435 declspecs_add_type (loc, specs, t);
2436 break;
2437 case RID_TYPEOF:
2438 /* ??? The old parser rejected typeof after other type
2439 specifiers, but is a syntax error the best way of
2440 handling this? */
2441 if (!typespec_ok || seen_type)
2442 goto out;
2443 attrs_ok = true;
2444 seen_type = true;
2445 t = c_parser_typeof_specifier (parser);
2446 declspecs_add_type (loc, specs, t);
2447 break;
2448 case RID_ATOMIC:
2449 /* C parser handling of Objective-C constructs needs
2450 checking for correct lvalue-to-rvalue conversions, and
2451 the code in build_modify_expr handling various
2452 Objective-C cases, and that in build_unary_op handling
2453 Objective-C cases for increment / decrement, also needs
2454 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2455 and objc_types_are_equivalent may also need updates. */
2456 if (c_dialect_objc ())
2457 sorry ("%<_Atomic%> in Objective-C");
2458 /* C parser handling of OpenMP constructs needs checking for
2459 correct lvalue-to-rvalue conversions. */
2460 if (flag_openmp)
2461 sorry ("%<_Atomic%> with OpenMP");
2462 if (flag_isoc99)
2463 pedwarn_c99 (loc, OPT_Wpedantic,
2464 "ISO C99 does not support the %<_Atomic%> qualifier");
2465 else
2466 pedwarn_c99 (loc, OPT_Wpedantic,
2467 "ISO C90 does not support the %<_Atomic%> qualifier");
2468 attrs_ok = true;
2469 tree value;
2470 value = c_parser_peek_token (parser)->value;
2471 c_parser_consume_token (parser);
2472 if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2474 /* _Atomic ( type-name ). */
2475 seen_type = true;
2476 c_parser_consume_token (parser);
2477 struct c_type_name *type = c_parser_type_name (parser);
2478 t.kind = ctsk_typeof;
2479 t.spec = error_mark_node;
2480 t.expr = NULL_TREE;
2481 t.expr_const_operands = true;
2482 if (type != NULL)
2483 t.spec = groktypename (type, &t.expr,
2484 &t.expr_const_operands);
2485 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2486 "expected %<)%>");
2487 if (t.spec != error_mark_node)
2489 if (TREE_CODE (t.spec) == ARRAY_TYPE)
2490 error_at (loc, "%<_Atomic%>-qualified array type");
2491 else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2492 error_at (loc, "%<_Atomic%>-qualified function type");
2493 else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2494 error_at (loc, "%<_Atomic%> applied to a qualified type");
2495 else
2496 t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2498 declspecs_add_type (loc, specs, t);
2500 else
2501 declspecs_add_qual (loc, specs, value);
2502 break;
2503 case RID_CONST:
2504 case RID_VOLATILE:
2505 case RID_RESTRICT:
2506 attrs_ok = true;
2507 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2508 c_parser_consume_token (parser);
2509 break;
2510 /* UPC qualifiers */
2511 case RID_SHARED:
2512 attrs_ok = true;
2513 c_parser_upc_shared_qual (loc, parser, specs);
2514 break;
2515 case RID_STRICT:
2516 case RID_RELAXED:
2517 attrs_ok = true;
2518 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2519 c_parser_consume_token (parser);
2520 break;
2521 case RID_ATTRIBUTE:
2522 if (!attrs_ok)
2523 goto out;
2524 attrs = c_parser_attributes (parser);
2525 declspecs_add_attrs (loc, specs, attrs);
2526 break;
2527 case RID_ALIGNAS:
2528 if (!alignspec_ok)
2529 goto out;
2530 align = c_parser_alignas_specifier (parser);
2531 declspecs_add_alignas (loc, specs, align);
2532 break;
2533 default:
2534 goto out;
2537 out: ;
2540 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2542 enum-specifier:
2543 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2544 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2545 enum attributes[opt] identifier
2547 The form with trailing comma is new in C99. The forms with
2548 attributes are GNU extensions. In GNU C, we accept any expression
2549 without commas in the syntax (assignment expressions, not just
2550 conditional expressions); assignment expressions will be diagnosed
2551 as non-constant.
2553 enumerator-list:
2554 enumerator
2555 enumerator-list , enumerator
2557 enumerator:
2558 enumeration-constant
2559 enumeration-constant = constant-expression
2562 static struct c_typespec
2563 c_parser_enum_specifier (c_parser *parser)
2565 struct c_typespec ret;
2566 tree attrs;
2567 tree ident = NULL_TREE;
2568 location_t enum_loc;
2569 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2570 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2571 enum_loc = c_parser_peek_token (parser)->location;
2572 c_parser_consume_token (parser);
2573 attrs = c_parser_attributes (parser);
2574 enum_loc = c_parser_peek_token (parser)->location;
2575 /* Set the location in case we create a decl now. */
2576 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2577 if (c_parser_next_token_is (parser, CPP_NAME))
2579 ident = c_parser_peek_token (parser)->value;
2580 ident_loc = c_parser_peek_token (parser)->location;
2581 enum_loc = ident_loc;
2582 c_parser_consume_token (parser);
2584 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2586 /* Parse an enum definition. */
2587 struct c_enum_contents the_enum;
2588 tree type;
2589 tree postfix_attrs;
2590 /* We chain the enumerators in reverse order, then put them in
2591 forward order at the end. */
2592 tree values;
2593 timevar_push (TV_PARSE_ENUM);
2594 type = start_enum (enum_loc, &the_enum, ident);
2595 values = NULL_TREE;
2596 c_parser_consume_token (parser);
2597 while (true)
2599 tree enum_id;
2600 tree enum_value;
2601 tree enum_decl;
2602 bool seen_comma;
2603 c_token *token;
2604 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2605 location_t decl_loc, value_loc;
2606 if (c_parser_next_token_is_not (parser, CPP_NAME))
2608 c_parser_error (parser, "expected identifier");
2609 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2610 values = error_mark_node;
2611 break;
2613 token = c_parser_peek_token (parser);
2614 enum_id = token->value;
2615 /* Set the location in case we create a decl now. */
2616 c_parser_set_source_position_from_token (token);
2617 decl_loc = value_loc = token->location;
2618 c_parser_consume_token (parser);
2619 if (c_parser_next_token_is (parser, CPP_EQ))
2621 c_parser_consume_token (parser);
2622 value_loc = c_parser_peek_token (parser)->location;
2623 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2625 else
2626 enum_value = NULL_TREE;
2627 enum_decl = build_enumerator (decl_loc, value_loc,
2628 &the_enum, enum_id, enum_value);
2629 TREE_CHAIN (enum_decl) = values;
2630 values = enum_decl;
2631 seen_comma = false;
2632 if (c_parser_next_token_is (parser, CPP_COMMA))
2634 comma_loc = c_parser_peek_token (parser)->location;
2635 seen_comma = true;
2636 c_parser_consume_token (parser);
2638 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2640 if (seen_comma)
2641 pedwarn_c90 (comma_loc, OPT_Wpedantic,
2642 "comma at end of enumerator list");
2643 c_parser_consume_token (parser);
2644 break;
2646 if (!seen_comma)
2648 c_parser_error (parser, "expected %<,%> or %<}%>");
2649 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2650 values = error_mark_node;
2651 break;
2654 postfix_attrs = c_parser_attributes (parser);
2655 ret.spec = finish_enum (type, nreverse (values),
2656 chainon (attrs, postfix_attrs));
2657 ret.kind = ctsk_tagdef;
2658 ret.expr = NULL_TREE;
2659 ret.expr_const_operands = true;
2660 timevar_pop (TV_PARSE_ENUM);
2661 return ret;
2663 else if (!ident)
2665 c_parser_error (parser, "expected %<{%>");
2666 ret.spec = error_mark_node;
2667 ret.kind = ctsk_tagref;
2668 ret.expr = NULL_TREE;
2669 ret.expr_const_operands = true;
2670 return ret;
2672 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2673 /* In ISO C, enumerated types can be referred to only if already
2674 defined. */
2675 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2677 gcc_assert (ident);
2678 pedwarn (enum_loc, OPT_Wpedantic,
2679 "ISO C forbids forward references to %<enum%> types");
2681 return ret;
2684 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2686 struct-or-union-specifier:
2687 struct-or-union attributes[opt] identifier[opt]
2688 { struct-contents } attributes[opt]
2689 struct-or-union attributes[opt] identifier
2691 struct-contents:
2692 struct-declaration-list
2694 struct-declaration-list:
2695 struct-declaration ;
2696 struct-declaration-list struct-declaration ;
2698 GNU extensions:
2700 struct-contents:
2701 empty
2702 struct-declaration
2703 struct-declaration-list struct-declaration
2705 struct-declaration-list:
2706 struct-declaration-list ;
2709 (Note that in the syntax here, unlike that in ISO C, the semicolons
2710 are included here rather than in struct-declaration, in order to
2711 describe the syntax with extra semicolons and missing semicolon at
2712 end.)
2714 Objective-C:
2716 struct-declaration-list:
2717 @defs ( class-name )
2719 (Note this does not include a trailing semicolon, but can be
2720 followed by further declarations, and gets a pedwarn-if-pedantic
2721 when followed by a semicolon.) */
2723 static struct c_typespec
2724 c_parser_struct_or_union_specifier (c_parser *parser)
2726 struct c_typespec ret;
2727 tree attrs;
2728 tree ident = NULL_TREE;
2729 location_t struct_loc;
2730 location_t ident_loc = UNKNOWN_LOCATION;
2731 enum tree_code code;
2732 switch (c_parser_peek_token (parser)->keyword)
2734 case RID_STRUCT:
2735 code = RECORD_TYPE;
2736 break;
2737 case RID_UNION:
2738 code = UNION_TYPE;
2739 break;
2740 default:
2741 gcc_unreachable ();
2743 struct_loc = c_parser_peek_token (parser)->location;
2744 c_parser_consume_token (parser);
2745 attrs = c_parser_attributes (parser);
2747 /* Set the location in case we create a decl now. */
2748 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2750 if (c_parser_next_token_is (parser, CPP_NAME))
2752 ident = c_parser_peek_token (parser)->value;
2753 ident_loc = c_parser_peek_token (parser)->location;
2754 struct_loc = ident_loc;
2755 c_parser_consume_token (parser);
2757 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2759 /* Parse a struct or union definition. Start the scope of the
2760 tag before parsing components. */
2761 struct c_struct_parse_info *struct_info;
2762 tree type = start_struct (struct_loc, code, ident, &struct_info);
2763 tree postfix_attrs;
2764 /* We chain the components in reverse order, then put them in
2765 forward order at the end. Each struct-declaration may
2766 declare multiple components (comma-separated), so we must use
2767 chainon to join them, although when parsing each
2768 struct-declaration we can use TREE_CHAIN directly.
2770 The theory behind all this is that there will be more
2771 semicolon separated fields than comma separated fields, and
2772 so we'll be minimizing the number of node traversals required
2773 by chainon. */
2774 tree contents;
2775 timevar_push (TV_PARSE_STRUCT);
2776 contents = NULL_TREE;
2777 c_parser_consume_token (parser);
2778 /* Handle the Objective-C @defs construct,
2779 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2780 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2782 tree name;
2783 gcc_assert (c_dialect_objc ());
2784 c_parser_consume_token (parser);
2785 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2786 goto end_at_defs;
2787 if (c_parser_next_token_is (parser, CPP_NAME)
2788 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2790 name = c_parser_peek_token (parser)->value;
2791 c_parser_consume_token (parser);
2793 else
2795 c_parser_error (parser, "expected class name");
2796 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2797 goto end_at_defs;
2799 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2800 "expected %<)%>");
2801 contents = nreverse (objc_get_class_ivars (name));
2803 end_at_defs:
2804 /* Parse the struct-declarations and semicolons. Problems with
2805 semicolons are diagnosed here; empty structures are diagnosed
2806 elsewhere. */
2807 while (true)
2809 tree decls;
2810 /* Parse any stray semicolon. */
2811 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2813 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2814 "extra semicolon in struct or union specified");
2815 c_parser_consume_token (parser);
2816 continue;
2818 /* Stop if at the end of the struct or union contents. */
2819 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2821 c_parser_consume_token (parser);
2822 break;
2824 /* Accept #pragmas at struct scope. */
2825 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2827 c_parser_pragma (parser, pragma_struct);
2828 continue;
2830 /* Parse some comma-separated declarations, but not the
2831 trailing semicolon if any. */
2832 decls = c_parser_struct_declaration (parser);
2833 contents = chainon (decls, contents);
2834 /* If no semicolon follows, either we have a parse error or
2835 are at the end of the struct or union and should
2836 pedwarn. */
2837 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2838 c_parser_consume_token (parser);
2839 else
2841 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2842 pedwarn (c_parser_peek_token (parser)->location, 0,
2843 "no semicolon at end of struct or union");
2844 else if (parser->error
2845 || !c_parser_next_token_starts_declspecs (parser))
2847 c_parser_error (parser, "expected %<;%>");
2848 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2849 break;
2852 /* If we come here, we have already emitted an error
2853 for an expected `;', identifier or `(', and we also
2854 recovered already. Go on with the next field. */
2857 postfix_attrs = c_parser_attributes (parser);
2858 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2859 chainon (attrs, postfix_attrs), struct_info);
2860 ret.kind = ctsk_tagdef;
2861 ret.expr = NULL_TREE;
2862 ret.expr_const_operands = true;
2863 timevar_pop (TV_PARSE_STRUCT);
2864 return ret;
2866 else if (!ident)
2868 c_parser_error (parser, "expected %<{%>");
2869 ret.spec = error_mark_node;
2870 ret.kind = ctsk_tagref;
2871 ret.expr = NULL_TREE;
2872 ret.expr_const_operands = true;
2873 return ret;
2875 ret = parser_xref_tag (ident_loc, code, ident);
2876 return ret;
2879 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2880 the trailing semicolon.
2882 struct-declaration:
2883 specifier-qualifier-list struct-declarator-list
2884 static_assert-declaration-no-semi
2886 specifier-qualifier-list:
2887 type-specifier specifier-qualifier-list[opt]
2888 type-qualifier specifier-qualifier-list[opt]
2889 attributes specifier-qualifier-list[opt]
2891 struct-declarator-list:
2892 struct-declarator
2893 struct-declarator-list , attributes[opt] struct-declarator
2895 struct-declarator:
2896 declarator attributes[opt]
2897 declarator[opt] : constant-expression attributes[opt]
2899 GNU extensions:
2901 struct-declaration:
2902 __extension__ struct-declaration
2903 specifier-qualifier-list
2905 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2906 of attributes where shown is a GNU extension. In GNU C, we accept
2907 any expression without commas in the syntax (assignment
2908 expressions, not just conditional expressions); assignment
2909 expressions will be diagnosed as non-constant. */
2911 static tree
2912 c_parser_struct_declaration (c_parser *parser)
2914 struct c_declspecs *specs;
2915 tree prefix_attrs;
2916 tree all_prefix_attrs;
2917 tree decls;
2918 location_t decl_loc;
2919 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2921 int ext;
2922 tree decl;
2923 ext = disable_extension_diagnostics ();
2924 c_parser_consume_token (parser);
2925 decl = c_parser_struct_declaration (parser);
2926 restore_extension_diagnostics (ext);
2927 return decl;
2929 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2931 c_parser_static_assert_declaration_no_semi (parser);
2932 return NULL_TREE;
2934 specs = build_null_declspecs ();
2935 decl_loc = c_parser_peek_token (parser)->location;
2936 /* Strictly by the standard, we shouldn't allow _Alignas here,
2937 but it appears to have been intended to allow it there, so
2938 we're keeping it as it is until WG14 reaches a conclusion
2939 of N1731.
2940 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2941 c_parser_declspecs (parser, specs, false, true, true,
2942 true, false, cla_nonabstract_decl);
2943 if (parser->error)
2944 return NULL_TREE;
2945 if (!specs->declspecs_seen_p)
2947 c_parser_error (parser, "expected specifier-qualifier-list");
2948 return NULL_TREE;
2950 finish_declspecs (specs);
2951 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2952 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2954 tree ret;
2955 if (specs->typespec_kind == ctsk_none)
2957 pedwarn (decl_loc, OPT_Wpedantic,
2958 "ISO C forbids member declarations with no members");
2959 shadow_tag_warned (specs, pedantic);
2960 ret = NULL_TREE;
2962 else
2964 /* Support for unnamed structs or unions as members of
2965 structs or unions (which is [a] useful and [b] supports
2966 MS P-SDK). */
2967 tree attrs = NULL;
2969 ret = grokfield (c_parser_peek_token (parser)->location,
2970 build_id_declarator (NULL_TREE), specs,
2971 NULL_TREE, &attrs);
2972 if (ret)
2973 decl_attributes (&ret, attrs, 0);
2975 return ret;
2978 /* Provide better error recovery. Note that a type name here is valid,
2979 and will be treated as a field name. */
2980 if (specs->typespec_kind == ctsk_tagdef
2981 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2982 && c_parser_next_token_starts_declspecs (parser)
2983 && !c_parser_next_token_is (parser, CPP_NAME))
2985 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2986 parser->error = false;
2987 return NULL_TREE;
2990 pending_xref_error ();
2991 prefix_attrs = specs->attrs;
2992 all_prefix_attrs = prefix_attrs;
2993 specs->attrs = NULL_TREE;
2994 decls = NULL_TREE;
2995 while (true)
2997 /* Declaring one or more declarators or un-named bit-fields. */
2998 struct c_declarator *declarator;
2999 bool dummy = false;
3000 if (c_parser_next_token_is (parser, CPP_COLON))
3001 declarator = build_id_declarator (NULL_TREE);
3002 else
3003 declarator = c_parser_declarator (parser,
3004 specs->typespec_kind != ctsk_none,
3005 C_DTR_NORMAL, &dummy);
3006 if (declarator == NULL)
3008 c_parser_skip_to_end_of_block_or_statement (parser);
3009 break;
3011 if (c_parser_next_token_is (parser, CPP_COLON)
3012 || c_parser_next_token_is (parser, CPP_COMMA)
3013 || c_parser_next_token_is (parser, CPP_SEMICOLON)
3014 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
3015 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3017 tree postfix_attrs = NULL_TREE;
3018 tree width = NULL_TREE;
3019 tree d;
3020 if (c_parser_next_token_is (parser, CPP_COLON))
3022 c_parser_consume_token (parser);
3023 width = c_parser_expr_no_commas (parser, NULL).value;
3025 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3026 postfix_attrs = c_parser_attributes (parser);
3027 d = grokfield (c_parser_peek_token (parser)->location,
3028 declarator, specs, width, &all_prefix_attrs);
3029 decl_attributes (&d, chainon (postfix_attrs,
3030 all_prefix_attrs), 0);
3031 DECL_CHAIN (d) = decls;
3032 decls = d;
3033 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3034 all_prefix_attrs = chainon (c_parser_attributes (parser),
3035 prefix_attrs);
3036 else
3037 all_prefix_attrs = prefix_attrs;
3038 if (c_parser_next_token_is (parser, CPP_COMMA))
3039 c_parser_consume_token (parser);
3040 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3041 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3043 /* Semicolon consumed in caller. */
3044 break;
3046 else
3048 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3049 break;
3052 else
3054 c_parser_error (parser,
3055 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3056 "%<__attribute__%>");
3057 break;
3060 return decls;
3063 /* Parse a typeof specifier (a GNU extension).
3065 typeof-specifier:
3066 typeof ( expression )
3067 typeof ( type-name )
3070 static struct c_typespec
3071 c_parser_typeof_specifier (c_parser *parser)
3073 struct c_typespec ret;
3074 ret.kind = ctsk_typeof;
3075 ret.spec = error_mark_node;
3076 ret.expr = NULL_TREE;
3077 ret.expr_const_operands = true;
3078 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3079 c_parser_consume_token (parser);
3080 c_inhibit_evaluation_warnings++;
3081 in_typeof++;
3082 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3084 c_inhibit_evaluation_warnings--;
3085 in_typeof--;
3086 return ret;
3088 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3090 struct c_type_name *type = c_parser_type_name (parser);
3091 c_inhibit_evaluation_warnings--;
3092 in_typeof--;
3093 if (type != NULL)
3095 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3096 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3099 else
3101 bool was_vm;
3102 location_t here = c_parser_peek_token (parser)->location;
3103 struct c_expr expr = c_parser_expression (parser);
3104 c_inhibit_evaluation_warnings--;
3105 in_typeof--;
3106 if (TREE_CODE (expr.value) == COMPONENT_REF
3107 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3108 error_at (here, "%<typeof%> applied to a bit-field");
3109 mark_exp_read (expr.value);
3110 ret.spec = TREE_TYPE (expr.value);
3111 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3112 /* This is returned with the type so that when the type is
3113 evaluated, this can be evaluated. */
3114 if (was_vm)
3115 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3116 pop_maybe_used (was_vm);
3117 /* For use in macros such as those in <stdatomic.h>, remove all
3118 qualifiers from atomic types. (const can be an issue for more macros
3119 using typeof than just the <stdatomic.h> ones.) */
3120 if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3121 ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3123 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3124 return ret;
3127 /* Parse an alignment-specifier.
3129 C11 6.7.5:
3131 alignment-specifier:
3132 _Alignas ( type-name )
3133 _Alignas ( constant-expression )
3136 static tree
3137 c_parser_alignas_specifier (c_parser * parser)
3139 tree ret = error_mark_node;
3140 location_t loc = c_parser_peek_token (parser)->location;
3141 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3142 c_parser_consume_token (parser);
3143 if (flag_isoc99)
3144 pedwarn_c99 (loc, OPT_Wpedantic,
3145 "ISO C99 does not support %<_Alignas%>");
3146 else
3147 pedwarn_c99 (loc, OPT_Wpedantic,
3148 "ISO C90 does not support %<_Alignas%>");
3149 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3150 return ret;
3151 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3153 struct c_type_name *type = c_parser_type_name (parser);
3154 if (type != NULL)
3155 ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3156 false, true, 1);
3158 else
3159 ret = c_parser_expr_no_commas (parser, NULL).value;
3160 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3161 return ret;
3164 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3165 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3166 be redeclared; otherwise it may not. KIND indicates which kind of
3167 declarator is wanted. Returns a valid declarator except in the
3168 case of a syntax error in which case NULL is returned. *SEEN_ID is
3169 set to true if an identifier being declared is seen; this is used
3170 to diagnose bad forms of abstract array declarators and to
3171 determine whether an identifier list is syntactically permitted.
3173 declarator:
3174 pointer[opt] direct-declarator
3176 direct-declarator:
3177 identifier
3178 ( attributes[opt] declarator )
3179 direct-declarator array-declarator
3180 direct-declarator ( parameter-type-list )
3181 direct-declarator ( identifier-list[opt] )
3183 pointer:
3184 * type-qualifier-list[opt]
3185 * type-qualifier-list[opt] pointer
3187 type-qualifier-list:
3188 type-qualifier
3189 attributes
3190 type-qualifier-list type-qualifier
3191 type-qualifier-list attributes
3193 array-declarator:
3194 [ type-qualifier-list[opt] assignment-expression[opt] ]
3195 [ static type-qualifier-list[opt] assignment-expression ]
3196 [ type-qualifier-list static assignment-expression ]
3197 [ type-qualifier-list[opt] * ]
3199 parameter-type-list:
3200 parameter-list
3201 parameter-list , ...
3203 parameter-list:
3204 parameter-declaration
3205 parameter-list , parameter-declaration
3207 parameter-declaration:
3208 declaration-specifiers declarator attributes[opt]
3209 declaration-specifiers abstract-declarator[opt] attributes[opt]
3211 identifier-list:
3212 identifier
3213 identifier-list , identifier
3215 abstract-declarator:
3216 pointer
3217 pointer[opt] direct-abstract-declarator
3219 direct-abstract-declarator:
3220 ( attributes[opt] abstract-declarator )
3221 direct-abstract-declarator[opt] array-declarator
3222 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3224 GNU extensions:
3226 direct-declarator:
3227 direct-declarator ( parameter-forward-declarations
3228 parameter-type-list[opt] )
3230 direct-abstract-declarator:
3231 direct-abstract-declarator[opt] ( parameter-forward-declarations
3232 parameter-type-list[opt] )
3234 parameter-forward-declarations:
3235 parameter-list ;
3236 parameter-forward-declarations parameter-list ;
3238 The uses of attributes shown above are GNU extensions.
3240 Some forms of array declarator are not included in C99 in the
3241 syntax for abstract declarators; these are disallowed elsewhere.
3242 This may be a defect (DR#289).
3244 This function also accepts an omitted abstract declarator as being
3245 an abstract declarator, although not part of the formal syntax. */
3247 static struct c_declarator *
3248 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3249 bool *seen_id)
3251 /* Parse any initial pointer part. */
3252 if (c_parser_next_token_is (parser, CPP_MULT))
3254 struct c_declspecs *quals_attrs = build_null_declspecs ();
3255 struct c_declarator *inner;
3256 c_parser_consume_token (parser);
3257 c_parser_declspecs (parser, quals_attrs, false, false, true,
3258 false, false, cla_prefer_id);
3259 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3260 if (inner == NULL)
3261 return NULL;
3262 else
3263 return make_pointer_declarator (quals_attrs, inner);
3265 /* Now we have a direct declarator, direct abstract declarator or
3266 nothing (which counts as a direct abstract declarator here). */
3267 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3270 /* Parse a direct declarator or direct abstract declarator; arguments
3271 as c_parser_declarator. */
3273 static struct c_declarator *
3274 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3275 bool *seen_id)
3277 /* The direct declarator must start with an identifier (possibly
3278 omitted) or a parenthesized declarator (possibly abstract). In
3279 an ordinary declarator, initial parentheses must start a
3280 parenthesized declarator. In an abstract declarator or parameter
3281 declarator, they could start a parenthesized declarator or a
3282 parameter list. To tell which, the open parenthesis and any
3283 following attributes must be read. If a declaration specifier
3284 follows, then it is a parameter list; if the specifier is a
3285 typedef name, there might be an ambiguity about redeclaring it,
3286 which is resolved in the direction of treating it as a typedef
3287 name. If a close parenthesis follows, it is also an empty
3288 parameter list, as the syntax does not permit empty abstract
3289 declarators. Otherwise, it is a parenthesized declarator (in
3290 which case the analysis may be repeated inside it, recursively).
3292 ??? There is an ambiguity in a parameter declaration "int
3293 (__attribute__((foo)) x)", where x is not a typedef name: it
3294 could be an abstract declarator for a function, or declare x with
3295 parentheses. The proper resolution of this ambiguity needs
3296 documenting. At present we follow an accident of the old
3297 parser's implementation, whereby the first parameter must have
3298 some declaration specifiers other than just attributes. Thus as
3299 a parameter declaration it is treated as a parenthesized
3300 parameter named x, and as an abstract declarator it is
3301 rejected.
3303 ??? Also following the old parser, attributes inside an empty
3304 parameter list are ignored, making it a list not yielding a
3305 prototype, rather than giving an error or making it have one
3306 parameter with implicit type int.
3308 ??? Also following the old parser, typedef names may be
3309 redeclared in declarators, but not Objective-C class names. */
3311 if (kind != C_DTR_ABSTRACT
3312 && c_parser_next_token_is (parser, CPP_NAME)
3313 && ((type_seen_p
3314 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3315 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3316 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3318 struct c_declarator *inner
3319 = build_id_declarator (c_parser_peek_token (parser)->value);
3320 *seen_id = true;
3321 inner->id_loc = c_parser_peek_token (parser)->location;
3322 c_parser_consume_token (parser);
3323 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3326 if (kind != C_DTR_NORMAL
3327 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3329 struct c_declarator *inner = build_id_declarator (NULL_TREE);
3330 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3333 /* Either we are at the end of an abstract declarator, or we have
3334 parentheses. */
3336 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3338 tree attrs;
3339 struct c_declarator *inner;
3340 c_parser_consume_token (parser);
3341 attrs = c_parser_attributes (parser);
3342 if (kind != C_DTR_NORMAL
3343 && (c_parser_next_token_starts_declspecs (parser)
3344 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3346 struct c_arg_info *args
3347 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3348 attrs);
3349 if (args == NULL)
3350 return NULL;
3351 else
3353 inner
3354 = build_function_declarator (args,
3355 build_id_declarator (NULL_TREE));
3356 return c_parser_direct_declarator_inner (parser, *seen_id,
3357 inner);
3360 /* A parenthesized declarator. */
3361 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3362 if (inner != NULL && attrs != NULL)
3363 inner = build_attrs_declarator (attrs, inner);
3364 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3366 c_parser_consume_token (parser);
3367 if (inner == NULL)
3368 return NULL;
3369 else
3370 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3372 else
3374 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3375 "expected %<)%>");
3376 return NULL;
3379 else
3381 if (kind == C_DTR_NORMAL)
3383 c_parser_error (parser, "expected identifier or %<(%>");
3384 return NULL;
3386 else
3387 return build_id_declarator (NULL_TREE);
3391 /* Parse part of a direct declarator or direct abstract declarator,
3392 given that some (in INNER) has already been parsed; ID_PRESENT is
3393 true if an identifier is present, false for an abstract
3394 declarator. */
3396 static struct c_declarator *
3397 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3398 struct c_declarator *inner)
3400 /* Parse a sequence of array declarators and parameter lists. */
3401 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3403 location_t brace_loc = c_parser_peek_token (parser)->location;
3404 struct c_declarator *declarator;
3405 struct c_declspecs *quals_attrs = build_null_declspecs ();
3406 bool static_seen;
3407 bool star_seen;
3408 struct c_expr dimen;
3409 dimen.value = NULL_TREE;
3410 dimen.original_code = ERROR_MARK;
3411 dimen.original_type = NULL_TREE;
3412 c_parser_consume_token (parser);
3413 c_parser_declspecs (parser, quals_attrs, false, false, true,
3414 false, false, cla_prefer_id);
3415 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3416 if (static_seen)
3417 c_parser_consume_token (parser);
3418 if (static_seen && !quals_attrs->declspecs_seen_p)
3419 c_parser_declspecs (parser, quals_attrs, false, false, true,
3420 false, false, cla_prefer_id);
3421 if (!quals_attrs->declspecs_seen_p)
3422 quals_attrs = NULL;
3423 /* If "static" is present, there must be an array dimension.
3424 Otherwise, there may be a dimension, "*", or no
3425 dimension. */
3426 if (static_seen)
3428 star_seen = false;
3429 dimen = c_parser_expr_no_commas (parser, NULL);
3431 else
3433 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3435 dimen.value = NULL_TREE;
3436 star_seen = false;
3438 else if (flag_cilkplus
3439 && c_parser_next_token_is (parser, CPP_COLON))
3441 dimen.value = error_mark_node;
3442 star_seen = false;
3443 error_at (c_parser_peek_token (parser)->location,
3444 "array notations cannot be used in declaration");
3445 c_parser_consume_token (parser);
3447 else if (c_parser_next_token_is (parser, CPP_MULT))
3449 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3451 dimen.value = NULL_TREE;
3452 star_seen = true;
3453 c_parser_consume_token (parser);
3455 else
3457 star_seen = false;
3458 dimen = c_parser_expr_no_commas (parser, NULL);
3461 else
3463 star_seen = false;
3464 dimen = c_parser_expr_no_commas (parser, NULL);
3467 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3468 c_parser_consume_token (parser);
3469 else if (flag_cilkplus
3470 && c_parser_next_token_is (parser, CPP_COLON))
3472 error_at (c_parser_peek_token (parser)->location,
3473 "array notations cannot be used in declaration");
3474 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
3475 return NULL;
3477 else
3479 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3480 "expected %<]%>");
3481 return NULL;
3483 if (dimen.value)
3484 dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3485 declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3486 static_seen, star_seen);
3487 if (declarator == NULL)
3488 return NULL;
3489 inner = set_array_declarator_inner (declarator, inner);
3490 return c_parser_direct_declarator_inner (parser, id_present, inner);
3492 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3494 tree attrs;
3495 struct c_arg_info *args;
3496 c_parser_consume_token (parser);
3497 attrs = c_parser_attributes (parser);
3498 args = c_parser_parms_declarator (parser, id_present, attrs);
3499 if (args == NULL)
3500 return NULL;
3501 else
3503 inner = build_function_declarator (args, inner);
3504 return c_parser_direct_declarator_inner (parser, id_present, inner);
3507 return inner;
3510 /* Parse a parameter list or identifier list, including the closing
3511 parenthesis but not the opening one. ATTRS are the attributes at
3512 the start of the list. ID_LIST_OK is true if an identifier list is
3513 acceptable; such a list must not have attributes at the start. */
3515 static struct c_arg_info *
3516 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3518 push_scope ();
3519 declare_parm_level ();
3520 /* If the list starts with an identifier, it is an identifier list.
3521 Otherwise, it is either a prototype list or an empty list. */
3522 if (id_list_ok
3523 && !attrs
3524 && c_parser_next_token_is (parser, CPP_NAME)
3525 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3527 /* Look ahead to detect typos in type names. */
3528 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3529 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3530 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3531 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3533 tree list = NULL_TREE, *nextp = &list;
3534 while (c_parser_next_token_is (parser, CPP_NAME)
3535 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3537 *nextp = build_tree_list (NULL_TREE,
3538 c_parser_peek_token (parser)->value);
3539 nextp = & TREE_CHAIN (*nextp);
3540 c_parser_consume_token (parser);
3541 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3542 break;
3543 c_parser_consume_token (parser);
3544 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3546 c_parser_error (parser, "expected identifier");
3547 break;
3550 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3552 struct c_arg_info *ret = build_arg_info ();
3553 ret->types = list;
3554 c_parser_consume_token (parser);
3555 pop_scope ();
3556 return ret;
3558 else
3560 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3561 "expected %<)%>");
3562 pop_scope ();
3563 return NULL;
3566 else
3568 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3569 NULL);
3570 pop_scope ();
3571 return ret;
3575 /* Parse a parameter list (possibly empty), including the closing
3576 parenthesis but not the opening one. ATTRS are the attributes at
3577 the start of the list. EXPR is NULL or an expression that needs to
3578 be evaluated for the side effects of array size expressions in the
3579 parameters. */
3581 static struct c_arg_info *
3582 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3584 bool bad_parm = false;
3586 /* ??? Following the old parser, forward parameter declarations may
3587 use abstract declarators, and if no real parameter declarations
3588 follow the forward declarations then this is not diagnosed. Also
3589 note as above that attributes are ignored as the only contents of
3590 the parentheses, or as the only contents after forward
3591 declarations. */
3592 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3594 struct c_arg_info *ret = build_arg_info ();
3595 c_parser_consume_token (parser);
3596 return ret;
3598 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3600 struct c_arg_info *ret = build_arg_info ();
3602 if (flag_allow_parameterless_variadic_functions)
3604 /* F (...) is allowed. */
3605 ret->types = NULL_TREE;
3607 else
3609 /* Suppress -Wold-style-definition for this case. */
3610 ret->types = error_mark_node;
3611 error_at (c_parser_peek_token (parser)->location,
3612 "ISO C requires a named argument before %<...%>");
3614 c_parser_consume_token (parser);
3615 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3617 c_parser_consume_token (parser);
3618 return ret;
3620 else
3622 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3623 "expected %<)%>");
3624 return NULL;
3627 /* Nonempty list of parameters, either terminated with semicolon
3628 (forward declarations; recurse) or with close parenthesis (normal
3629 function) or with ", ... )" (variadic function). */
3630 while (true)
3632 /* Parse a parameter. */
3633 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3634 attrs = NULL_TREE;
3635 if (parm == NULL)
3636 bad_parm = true;
3637 else
3638 push_parm_decl (parm, &expr);
3639 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3641 tree new_attrs;
3642 c_parser_consume_token (parser);
3643 mark_forward_parm_decls ();
3644 new_attrs = c_parser_attributes (parser);
3645 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3647 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3649 c_parser_consume_token (parser);
3650 if (bad_parm)
3651 return NULL;
3652 else
3653 return get_parm_info (false, expr);
3655 if (!c_parser_require (parser, CPP_COMMA,
3656 "expected %<;%>, %<,%> or %<)%>"))
3658 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3659 return NULL;
3661 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3663 c_parser_consume_token (parser);
3664 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3666 c_parser_consume_token (parser);
3667 if (bad_parm)
3668 return NULL;
3669 else
3670 return get_parm_info (true, expr);
3672 else
3674 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3675 "expected %<)%>");
3676 return NULL;
3682 /* Parse a parameter declaration. ATTRS are the attributes at the
3683 start of the declaration if it is the first parameter. */
3685 static struct c_parm *
3686 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3688 struct c_declspecs *specs;
3689 struct c_declarator *declarator;
3690 tree prefix_attrs;
3691 tree postfix_attrs = NULL_TREE;
3692 bool dummy = false;
3694 /* Accept #pragmas between parameter declarations. */
3695 while (c_parser_next_token_is (parser, CPP_PRAGMA))
3696 c_parser_pragma (parser, pragma_param);
3698 if (!c_parser_next_token_starts_declspecs (parser))
3700 c_token *token = c_parser_peek_token (parser);
3701 if (parser->error)
3702 return NULL;
3703 c_parser_set_source_position_from_token (token);
3704 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3706 error_at (token->location, "unknown type name %qE", token->value);
3707 parser->error = true;
3709 /* ??? In some Objective-C cases '...' isn't applicable so there
3710 should be a different message. */
3711 else
3712 c_parser_error (parser,
3713 "expected declaration specifiers or %<...%>");
3714 c_parser_skip_to_end_of_parameter (parser);
3715 return NULL;
3717 specs = build_null_declspecs ();
3718 if (attrs)
3720 declspecs_add_attrs (input_location, specs, attrs);
3721 attrs = NULL_TREE;
3723 c_parser_declspecs (parser, specs, true, true, true, true, false,
3724 cla_nonabstract_decl);
3725 finish_declspecs (specs);
3726 pending_xref_error ();
3727 prefix_attrs = specs->attrs;
3728 specs->attrs = NULL_TREE;
3729 declarator = c_parser_declarator (parser,
3730 specs->typespec_kind != ctsk_none,
3731 C_DTR_PARM, &dummy);
3732 if (declarator == NULL)
3734 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3735 return NULL;
3737 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3738 postfix_attrs = c_parser_attributes (parser);
3739 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3740 declarator);
3743 /* Parse a string literal in an asm expression. It should not be
3744 translated, and wide string literals are an error although
3745 permitted by the syntax. This is a GNU extension.
3747 asm-string-literal:
3748 string-literal
3750 ??? At present, following the old parser, the caller needs to have
3751 set lex_untranslated_string to 1. It would be better to follow the
3752 C++ parser rather than using this kludge. */
3754 static tree
3755 c_parser_asm_string_literal (c_parser *parser)
3757 tree str;
3758 int save_flag = warn_overlength_strings;
3759 warn_overlength_strings = 0;
3760 if (c_parser_next_token_is (parser, CPP_STRING))
3762 str = c_parser_peek_token (parser)->value;
3763 c_parser_consume_token (parser);
3765 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3767 error_at (c_parser_peek_token (parser)->location,
3768 "wide string literal in %<asm%>");
3769 str = build_string (1, "");
3770 c_parser_consume_token (parser);
3772 else
3774 c_parser_error (parser, "expected string literal");
3775 str = NULL_TREE;
3777 warn_overlength_strings = save_flag;
3778 return str;
3781 /* Parse a simple asm expression. This is used in restricted
3782 contexts, where a full expression with inputs and outputs does not
3783 make sense. This is a GNU extension.
3785 simple-asm-expr:
3786 asm ( asm-string-literal )
3789 static tree
3790 c_parser_simple_asm_expr (c_parser *parser)
3792 tree str;
3793 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3794 /* ??? Follow the C++ parser rather than using the
3795 lex_untranslated_string kludge. */
3796 parser->lex_untranslated_string = true;
3797 c_parser_consume_token (parser);
3798 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3800 parser->lex_untranslated_string = false;
3801 return NULL_TREE;
3803 str = c_parser_asm_string_literal (parser);
3804 parser->lex_untranslated_string = false;
3805 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3807 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3808 return NULL_TREE;
3810 return str;
3813 static tree
3814 c_parser_attribute_any_word (c_parser *parser)
3816 tree attr_name = NULL_TREE;
3818 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3820 /* ??? See comment above about what keywords are accepted here. */
3821 bool ok;
3822 switch (c_parser_peek_token (parser)->keyword)
3824 case RID_STATIC:
3825 case RID_UNSIGNED:
3826 case RID_LONG:
3827 case RID_CONST:
3828 case RID_EXTERN:
3829 case RID_REGISTER:
3830 case RID_TYPEDEF:
3831 case RID_SHORT:
3832 case RID_INLINE:
3833 case RID_NORETURN:
3834 case RID_VOLATILE:
3835 case RID_SIGNED:
3836 case RID_AUTO:
3837 case RID_RESTRICT:
3838 case RID_COMPLEX:
3839 case RID_THREAD:
3840 case RID_INT:
3841 case RID_CHAR:
3842 case RID_FLOAT:
3843 case RID_DOUBLE:
3844 case RID_VOID:
3845 case RID_DFLOAT32:
3846 case RID_DFLOAT64:
3847 case RID_DFLOAT128:
3848 case RID_BOOL:
3849 case RID_FRACT:
3850 case RID_ACCUM:
3851 case RID_SAT:
3852 case RID_TRANSACTION_ATOMIC:
3853 case RID_TRANSACTION_CANCEL:
3854 case RID_ATOMIC:
3855 case RID_AUTO_TYPE:
3856 case RID_INT_N_0:
3857 case RID_INT_N_1:
3858 case RID_INT_N_2:
3859 case RID_INT_N_3:
3860 ok = true;
3861 break;
3862 default:
3863 ok = false;
3864 break;
3866 if (!ok)
3867 return NULL_TREE;
3869 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3870 attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3872 else if (c_parser_next_token_is (parser, CPP_NAME))
3873 attr_name = c_parser_peek_token (parser)->value;
3875 return attr_name;
3878 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3879 "__vector" or "__vector__." */
3881 static inline bool
3882 is_cilkplus_vector_p (tree name)
3884 if (flag_cilkplus && is_attribute_p ("vector", name))
3885 return true;
3886 return false;
3889 #define CILK_SIMD_FN_CLAUSE_MASK \
3890 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3891 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3892 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3893 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3894 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3896 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3897 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3898 pushed into the token list.
3899 Syntax:
3900 vector
3901 vector (<vector attributes>). */
3903 static void
3904 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token)
3906 gcc_assert (is_cilkplus_vector_p (vec_token.value));
3908 int paren_scope = 0;
3909 vec_safe_push (parser->cilk_simd_fn_tokens, vec_token);
3910 /* Consume the "vector" token. */
3911 c_parser_consume_token (parser);
3913 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3915 c_parser_consume_token (parser);
3916 paren_scope++;
3918 while (paren_scope > 0)
3920 c_token *token = c_parser_peek_token (parser);
3921 if (token->type == CPP_OPEN_PAREN)
3922 paren_scope++;
3923 else if (token->type == CPP_CLOSE_PAREN)
3924 paren_scope--;
3925 /* Do not push the last ')' since we are not pushing the '('. */
3926 if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0))
3927 vec_safe_push (parser->cilk_simd_fn_tokens, *token);
3928 c_parser_consume_token (parser);
3931 /* Since we are converting an attribute to a pragma, we need to end the
3932 attribute with PRAGMA_EOL. */
3933 c_token eol_token;
3934 memset (&eol_token, 0, sizeof (eol_token));
3935 eol_token.type = CPP_PRAGMA_EOL;
3936 vec_safe_push (parser->cilk_simd_fn_tokens, eol_token);
3939 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3941 static void
3942 c_finish_cilk_simd_fn_tokens (c_parser *parser)
3944 c_token last_token = parser->cilk_simd_fn_tokens->last ();
3946 /* c_parser_attributes is called in several places, so if these EOF
3947 tokens are already inserted, then don't do them again. */
3948 if (last_token.type == CPP_EOF)
3949 return;
3951 /* Two CPP_EOF token are added as a safety net since the normal C
3952 front-end has two token look-ahead. */
3953 c_token eof_token;
3954 eof_token.type = CPP_EOF;
3955 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3956 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3959 /* Parse (possibly empty) attributes. This is a GNU extension.
3961 attributes:
3962 empty
3963 attributes attribute
3965 attribute:
3966 __attribute__ ( ( attribute-list ) )
3968 attribute-list:
3969 attrib
3970 attribute_list , attrib
3972 attrib:
3973 empty
3974 any-word
3975 any-word ( identifier )
3976 any-word ( identifier , nonempty-expr-list )
3977 any-word ( expr-list )
3979 where the "identifier" must not be declared as a type, and
3980 "any-word" may be any identifier (including one declared as a
3981 type), a reserved word storage class specifier, type specifier or
3982 type qualifier. ??? This still leaves out most reserved keywords
3983 (following the old parser), shouldn't we include them, and why not
3984 allow identifiers declared as types to start the arguments? */
3986 static tree
3987 c_parser_attributes (c_parser *parser)
3989 tree attrs = NULL_TREE;
3990 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3992 /* ??? Follow the C++ parser rather than using the
3993 lex_untranslated_string kludge. */
3994 parser->lex_untranslated_string = true;
3995 c_parser_consume_token (parser);
3996 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3998 parser->lex_untranslated_string = false;
3999 return attrs;
4001 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4003 parser->lex_untranslated_string = false;
4004 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4005 return attrs;
4007 /* Parse the attribute list. */
4008 while (c_parser_next_token_is (parser, CPP_COMMA)
4009 || c_parser_next_token_is (parser, CPP_NAME)
4010 || c_parser_next_token_is (parser, CPP_KEYWORD))
4012 tree attr, attr_name, attr_args;
4013 vec<tree, va_gc> *expr_list;
4014 if (c_parser_next_token_is (parser, CPP_COMMA))
4016 c_parser_consume_token (parser);
4017 continue;
4020 attr_name = c_parser_attribute_any_word (parser);
4021 if (attr_name == NULL)
4022 break;
4023 if (is_cilkplus_vector_p (attr_name))
4025 c_token *v_token = c_parser_peek_token (parser);
4026 c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
4027 continue;
4029 c_parser_consume_token (parser);
4030 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
4032 attr = build_tree_list (attr_name, NULL_TREE);
4033 attrs = chainon (attrs, attr);
4034 continue;
4036 c_parser_consume_token (parser);
4037 /* Parse the attribute contents. If they start with an
4038 identifier which is followed by a comma or close
4039 parenthesis, then the arguments start with that
4040 identifier; otherwise they are an expression list.
4041 In objective-c the identifier may be a classname. */
4042 if (c_parser_next_token_is (parser, CPP_NAME)
4043 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4044 || (c_dialect_objc ()
4045 && c_parser_peek_token (parser)->id_kind
4046 == C_ID_CLASSNAME))
4047 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4048 || (c_parser_peek_2nd_token (parser)->type
4049 == CPP_CLOSE_PAREN))
4050 && (attribute_takes_identifier_p (attr_name)
4051 || (c_dialect_objc ()
4052 && c_parser_peek_token (parser)->id_kind
4053 == C_ID_CLASSNAME)))
4055 tree arg1 = c_parser_peek_token (parser)->value;
4056 c_parser_consume_token (parser);
4057 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4058 attr_args = build_tree_list (NULL_TREE, arg1);
4059 else
4061 tree tree_list;
4062 c_parser_consume_token (parser);
4063 expr_list = c_parser_expr_list (parser, false, true,
4064 NULL, NULL, NULL, NULL);
4065 tree_list = build_tree_list_vec (expr_list);
4066 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4067 release_tree_vector (expr_list);
4070 else
4072 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4073 attr_args = NULL_TREE;
4074 else
4076 expr_list = c_parser_expr_list (parser, false, true,
4077 NULL, NULL, NULL, NULL);
4078 attr_args = build_tree_list_vec (expr_list);
4079 release_tree_vector (expr_list);
4082 attr = build_tree_list (attr_name, attr_args);
4083 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4084 c_parser_consume_token (parser);
4085 else
4087 parser->lex_untranslated_string = false;
4088 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4089 "expected %<)%>");
4090 return attrs;
4092 attrs = chainon (attrs, attr);
4094 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4095 c_parser_consume_token (parser);
4096 else
4098 parser->lex_untranslated_string = false;
4099 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4100 "expected %<)%>");
4101 return attrs;
4103 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4104 c_parser_consume_token (parser);
4105 else
4107 parser->lex_untranslated_string = false;
4108 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4109 "expected %<)%>");
4110 return attrs;
4112 parser->lex_untranslated_string = false;
4115 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
4116 c_finish_cilk_simd_fn_tokens (parser);
4117 return attrs;
4120 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4122 type-name:
4123 specifier-qualifier-list abstract-declarator[opt]
4126 static struct c_type_name *
4127 c_parser_type_name (c_parser *parser)
4129 struct c_declspecs *specs = build_null_declspecs ();
4130 struct c_declarator *declarator;
4131 struct c_type_name *ret;
4132 bool dummy = false;
4133 c_parser_declspecs (parser, specs, false, true, true, false, false,
4134 cla_prefer_type);
4135 if (!specs->declspecs_seen_p)
4137 c_parser_error (parser, "expected specifier-qualifier-list");
4138 return NULL;
4140 if (specs->type != error_mark_node)
4142 pending_xref_error ();
4143 finish_declspecs (specs);
4145 declarator = c_parser_declarator (parser,
4146 specs->typespec_kind != ctsk_none,
4147 C_DTR_ABSTRACT, &dummy);
4148 if (declarator == NULL)
4149 return NULL;
4150 ret = XOBNEW (&parser_obstack, struct c_type_name);
4151 ret->specs = specs;
4152 ret->declarator = declarator;
4153 return ret;
4156 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4158 initializer:
4159 assignment-expression
4160 { initializer-list }
4161 { initializer-list , }
4163 initializer-list:
4164 designation[opt] initializer
4165 initializer-list , designation[opt] initializer
4167 designation:
4168 designator-list =
4170 designator-list:
4171 designator
4172 designator-list designator
4174 designator:
4175 array-designator
4176 . identifier
4178 array-designator:
4179 [ constant-expression ]
4181 GNU extensions:
4183 initializer:
4186 designation:
4187 array-designator
4188 identifier :
4190 array-designator:
4191 [ constant-expression ... constant-expression ]
4193 Any expression without commas is accepted in the syntax for the
4194 constant-expressions, with non-constant expressions rejected later.
4196 This function is only used for top-level initializers; for nested
4197 ones, see c_parser_initval. */
4199 static struct c_expr
4200 c_parser_initializer (c_parser *parser)
4202 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4203 return c_parser_braced_init (parser, NULL_TREE, false);
4204 else
4206 struct c_expr ret;
4207 location_t loc = c_parser_peek_token (parser)->location;
4208 ret = c_parser_expr_no_commas (parser, NULL);
4209 if (TREE_CODE (ret.value) != STRING_CST
4210 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4211 ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4212 return ret;
4216 /* Parse a braced initializer list. TYPE is the type specified for a
4217 compound literal, and NULL_TREE for other initializers and for
4218 nested braced lists. NESTED_P is true for nested braced lists,
4219 false for the list of a compound literal or the list that is the
4220 top-level initializer in a declaration. */
4222 static struct c_expr
4223 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
4225 struct c_expr ret;
4226 struct obstack braced_init_obstack;
4227 location_t brace_loc = c_parser_peek_token (parser)->location;
4228 gcc_obstack_init (&braced_init_obstack);
4229 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4230 c_parser_consume_token (parser);
4231 if (nested_p)
4232 push_init_level (brace_loc, 0, &braced_init_obstack);
4233 else
4234 really_start_incremental_init (type);
4235 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4237 pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4239 else
4241 /* Parse a non-empty initializer list, possibly with a trailing
4242 comma. */
4243 while (true)
4245 c_parser_initelt (parser, &braced_init_obstack);
4246 if (parser->error)
4247 break;
4248 if (c_parser_next_token_is (parser, CPP_COMMA))
4249 c_parser_consume_token (parser);
4250 else
4251 break;
4252 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4253 break;
4256 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4258 ret.value = error_mark_node;
4259 ret.original_code = ERROR_MARK;
4260 ret.original_type = NULL;
4261 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
4262 pop_init_level (brace_loc, 0, &braced_init_obstack);
4263 obstack_free (&braced_init_obstack, NULL);
4264 return ret;
4266 c_parser_consume_token (parser);
4267 ret = pop_init_level (brace_loc, 0, &braced_init_obstack);
4268 obstack_free (&braced_init_obstack, NULL);
4269 return ret;
4272 /* Parse a nested initializer, including designators. */
4274 static void
4275 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4277 /* Parse any designator or designator list. A single array
4278 designator may have the subsequent "=" omitted in GNU C, but a
4279 longer list or a structure member designator may not. */
4280 if (c_parser_next_token_is (parser, CPP_NAME)
4281 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4283 /* Old-style structure member designator. */
4284 set_init_label (c_parser_peek_token (parser)->location,
4285 c_parser_peek_token (parser)->value,
4286 braced_init_obstack);
4287 /* Use the colon as the error location. */
4288 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4289 "obsolete use of designated initializer with %<:%>");
4290 c_parser_consume_token (parser);
4291 c_parser_consume_token (parser);
4293 else
4295 /* des_seen is 0 if there have been no designators, 1 if there
4296 has been a single array designator and 2 otherwise. */
4297 int des_seen = 0;
4298 /* Location of a designator. */
4299 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4300 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4301 || c_parser_next_token_is (parser, CPP_DOT))
4303 int des_prev = des_seen;
4304 if (!des_seen)
4305 des_loc = c_parser_peek_token (parser)->location;
4306 if (des_seen < 2)
4307 des_seen++;
4308 if (c_parser_next_token_is (parser, CPP_DOT))
4310 des_seen = 2;
4311 c_parser_consume_token (parser);
4312 if (c_parser_next_token_is (parser, CPP_NAME))
4314 set_init_label (des_loc, c_parser_peek_token (parser)->value,
4315 braced_init_obstack);
4316 c_parser_consume_token (parser);
4318 else
4320 struct c_expr init;
4321 init.value = error_mark_node;
4322 init.original_code = ERROR_MARK;
4323 init.original_type = NULL;
4324 c_parser_error (parser, "expected identifier");
4325 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4326 process_init_element (input_location, init, false,
4327 braced_init_obstack);
4328 return;
4331 else
4333 tree first, second;
4334 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4335 location_t array_index_loc = UNKNOWN_LOCATION;
4336 /* ??? Following the old parser, [ objc-receiver
4337 objc-message-args ] is accepted as an initializer,
4338 being distinguished from a designator by what follows
4339 the first assignment expression inside the square
4340 brackets, but after a first array designator a
4341 subsequent square bracket is for Objective-C taken to
4342 start an expression, using the obsolete form of
4343 designated initializer without '=', rather than
4344 possibly being a second level of designation: in LALR
4345 terms, the '[' is shifted rather than reducing
4346 designator to designator-list. */
4347 if (des_prev == 1 && c_dialect_objc ())
4349 des_seen = des_prev;
4350 break;
4352 if (des_prev == 0 && c_dialect_objc ())
4354 /* This might be an array designator or an
4355 Objective-C message expression. If the former,
4356 continue parsing here; if the latter, parse the
4357 remainder of the initializer given the starting
4358 primary-expression. ??? It might make sense to
4359 distinguish when des_prev == 1 as well; see
4360 previous comment. */
4361 tree rec, args;
4362 struct c_expr mexpr;
4363 c_parser_consume_token (parser);
4364 if (c_parser_peek_token (parser)->type == CPP_NAME
4365 && ((c_parser_peek_token (parser)->id_kind
4366 == C_ID_TYPENAME)
4367 || (c_parser_peek_token (parser)->id_kind
4368 == C_ID_CLASSNAME)))
4370 /* Type name receiver. */
4371 tree id = c_parser_peek_token (parser)->value;
4372 c_parser_consume_token (parser);
4373 rec = objc_get_class_reference (id);
4374 goto parse_message_args;
4376 first = c_parser_expr_no_commas (parser, NULL).value;
4377 mark_exp_read (first);
4378 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4379 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4380 goto array_desig_after_first;
4381 /* Expression receiver. So far only one part
4382 without commas has been parsed; there might be
4383 more of the expression. */
4384 rec = first;
4385 while (c_parser_next_token_is (parser, CPP_COMMA))
4387 struct c_expr next;
4388 location_t comma_loc, exp_loc;
4389 comma_loc = c_parser_peek_token (parser)->location;
4390 c_parser_consume_token (parser);
4391 exp_loc = c_parser_peek_token (parser)->location;
4392 next = c_parser_expr_no_commas (parser, NULL);
4393 next = convert_lvalue_to_rvalue (exp_loc, next,
4394 true, true);
4395 rec = build_compound_expr (comma_loc, rec, next.value);
4397 parse_message_args:
4398 /* Now parse the objc-message-args. */
4399 args = c_parser_objc_message_args (parser);
4400 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4401 "expected %<]%>");
4402 mexpr.value
4403 = objc_build_message_expr (rec, args);
4404 mexpr.original_code = ERROR_MARK;
4405 mexpr.original_type = NULL;
4406 /* Now parse and process the remainder of the
4407 initializer, starting with this message
4408 expression as a primary-expression. */
4409 c_parser_initval (parser, &mexpr, braced_init_obstack);
4410 return;
4412 c_parser_consume_token (parser);
4413 array_index_loc = c_parser_peek_token (parser)->location;
4414 first = c_parser_expr_no_commas (parser, NULL).value;
4415 mark_exp_read (first);
4416 array_desig_after_first:
4417 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4419 ellipsis_loc = c_parser_peek_token (parser)->location;
4420 c_parser_consume_token (parser);
4421 second = c_parser_expr_no_commas (parser, NULL).value;
4422 mark_exp_read (second);
4424 else
4425 second = NULL_TREE;
4426 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4428 c_parser_consume_token (parser);
4429 set_init_index (array_index_loc, first, second,
4430 braced_init_obstack);
4431 if (second)
4432 pedwarn (ellipsis_loc, OPT_Wpedantic,
4433 "ISO C forbids specifying range of elements to initialize");
4435 else
4436 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4437 "expected %<]%>");
4440 if (des_seen >= 1)
4442 if (c_parser_next_token_is (parser, CPP_EQ))
4444 pedwarn_c90 (des_loc, OPT_Wpedantic,
4445 "ISO C90 forbids specifying subobject "
4446 "to initialize");
4447 c_parser_consume_token (parser);
4449 else
4451 if (des_seen == 1)
4452 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4453 "obsolete use of designated initializer without %<=%>");
4454 else
4456 struct c_expr init;
4457 init.value = error_mark_node;
4458 init.original_code = ERROR_MARK;
4459 init.original_type = NULL;
4460 c_parser_error (parser, "expected %<=%>");
4461 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4462 process_init_element (input_location, init, false,
4463 braced_init_obstack);
4464 return;
4469 c_parser_initval (parser, NULL, braced_init_obstack);
4472 /* Parse a nested initializer; as c_parser_initializer but parses
4473 initializers within braced lists, after any designators have been
4474 applied. If AFTER is not NULL then it is an Objective-C message
4475 expression which is the primary-expression starting the
4476 initializer. */
4478 static void
4479 c_parser_initval (c_parser *parser, struct c_expr *after,
4480 struct obstack * braced_init_obstack)
4482 struct c_expr init;
4483 gcc_assert (!after || c_dialect_objc ());
4484 location_t loc = c_parser_peek_token (parser)->location;
4486 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4487 init = c_parser_braced_init (parser, NULL_TREE, true);
4488 else
4490 init = c_parser_expr_no_commas (parser, after);
4491 if (init.value != NULL_TREE
4492 && TREE_CODE (init.value) != STRING_CST
4493 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4494 init = convert_lvalue_to_rvalue (loc, init, true, true);
4496 process_init_element (loc, init, false, braced_init_obstack);
4499 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4500 C99 6.8.2).
4502 compound-statement:
4503 { block-item-list[opt] }
4504 { label-declarations block-item-list }
4506 block-item-list:
4507 block-item
4508 block-item-list block-item
4510 block-item:
4511 nested-declaration
4512 statement
4514 nested-declaration:
4515 declaration
4517 GNU extensions:
4519 compound-statement:
4520 { label-declarations block-item-list }
4522 nested-declaration:
4523 __extension__ nested-declaration
4524 nested-function-definition
4526 label-declarations:
4527 label-declaration
4528 label-declarations label-declaration
4530 label-declaration:
4531 __label__ identifier-list ;
4533 Allowing the mixing of declarations and code is new in C99. The
4534 GNU syntax also permits (not shown above) labels at the end of
4535 compound statements, which yield an error. We don't allow labels
4536 on declarations; this might seem like a natural extension, but
4537 there would be a conflict between attributes on the label and
4538 prefix attributes on the declaration. ??? The syntax follows the
4539 old parser in requiring something after label declarations.
4540 Although they are erroneous if the labels declared aren't defined,
4541 is it useful for the syntax to be this way?
4543 OpenACC:
4545 block-item:
4546 openacc-directive
4548 openacc-directive:
4549 update-directive
4551 OpenMP:
4553 block-item:
4554 openmp-directive
4556 openmp-directive:
4557 barrier-directive
4558 flush-directive
4559 taskwait-directive
4560 taskyield-directive
4561 cancel-directive
4562 cancellation-point-directive */
4564 static tree
4565 c_parser_compound_statement (c_parser *parser)
4567 tree stmt;
4568 location_t brace_loc;
4569 brace_loc = c_parser_peek_token (parser)->location;
4570 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4572 /* Ensure a scope is entered and left anyway to avoid confusion
4573 if we have just prepared to enter a function body. */
4574 stmt = c_begin_compound_stmt (true);
4575 c_end_compound_stmt (brace_loc, stmt, true);
4576 return error_mark_node;
4578 stmt = c_begin_compound_stmt (true);
4579 c_parser_compound_statement_nostart (parser);
4581 /* If the compound stmt contains array notations, then we expand them. */
4582 if (flag_cilkplus && contains_array_notation_expr (stmt))
4583 stmt = expand_array_notation_exprs (stmt);
4584 return c_end_compound_stmt (brace_loc, stmt, true);
4587 /* Parse a compound statement except for the opening brace. This is
4588 used for parsing both compound statements and statement expressions
4589 (which follow different paths to handling the opening). */
4591 static void
4592 c_parser_compound_statement_nostart (c_parser *parser)
4594 bool last_stmt = false;
4595 bool last_label = false;
4596 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4597 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4598 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4600 c_parser_consume_token (parser);
4601 return;
4603 mark_valid_location_for_stdc_pragma (true);
4604 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4606 /* Read zero or more forward-declarations for labels that nested
4607 functions can jump to. */
4608 mark_valid_location_for_stdc_pragma (false);
4609 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4611 label_loc = c_parser_peek_token (parser)->location;
4612 c_parser_consume_token (parser);
4613 /* Any identifiers, including those declared as type names,
4614 are OK here. */
4615 while (true)
4617 tree label;
4618 if (c_parser_next_token_is_not (parser, CPP_NAME))
4620 c_parser_error (parser, "expected identifier");
4621 break;
4623 label
4624 = declare_label (c_parser_peek_token (parser)->value);
4625 C_DECLARED_LABEL_FLAG (label) = 1;
4626 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4627 c_parser_consume_token (parser);
4628 if (c_parser_next_token_is (parser, CPP_COMMA))
4629 c_parser_consume_token (parser);
4630 else
4631 break;
4633 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4635 pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4637 /* We must now have at least one statement, label or declaration. */
4638 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4640 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4641 c_parser_error (parser, "expected declaration or statement");
4642 c_parser_consume_token (parser);
4643 return;
4645 /* Process all #pragma's just after the opening brace. This
4646 handles #pragma upc, which can only appear just after
4647 the opening brace, when it appears within a function body. */
4648 push_upc_consistency_mode ();
4649 permit_pragma_upc ();
4650 while (c_parser_next_token_is (parser, CPP_PRAGMA))
4652 location_t loc ATTRIBUTE_UNUSED = c_parser_peek_token (parser)->location;
4653 if (c_parser_pragma (parser, pragma_compound))
4654 last_label = false, last_stmt = true;
4655 parser->error = false;
4657 deny_pragma_upc ();
4658 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4660 location_t loc = c_parser_peek_token (parser)->location;
4661 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4662 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4663 || (c_parser_next_token_is (parser, CPP_NAME)
4664 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4666 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4667 label_loc = c_parser_peek_2nd_token (parser)->location;
4668 else
4669 label_loc = c_parser_peek_token (parser)->location;
4670 last_label = true;
4671 last_stmt = false;
4672 mark_valid_location_for_stdc_pragma (false);
4673 c_parser_label (parser);
4675 else if (!last_label
4676 && c_parser_next_tokens_start_declaration (parser))
4678 last_label = false;
4679 mark_valid_location_for_stdc_pragma (false);
4680 c_parser_declaration_or_fndef (parser, true, true, true, true,
4681 true, NULL, vNULL);
4682 if (last_stmt)
4683 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4684 "ISO C90 forbids mixed declarations and code");
4685 last_stmt = false;
4687 else if (!last_label
4688 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4690 /* __extension__ can start a declaration, but is also an
4691 unary operator that can start an expression. Consume all
4692 but the last of a possible series of __extension__ to
4693 determine which. */
4694 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4695 && (c_parser_peek_2nd_token (parser)->keyword
4696 == RID_EXTENSION))
4697 c_parser_consume_token (parser);
4698 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4700 int ext;
4701 ext = disable_extension_diagnostics ();
4702 c_parser_consume_token (parser);
4703 last_label = false;
4704 mark_valid_location_for_stdc_pragma (false);
4705 c_parser_declaration_or_fndef (parser, true, true, true, true,
4706 true, NULL, vNULL);
4707 /* Following the old parser, __extension__ does not
4708 disable this diagnostic. */
4709 restore_extension_diagnostics (ext);
4710 if (last_stmt)
4711 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4712 "ISO C90 forbids mixed declarations and code");
4713 last_stmt = false;
4715 else
4716 goto statement;
4718 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4720 /* External pragmas, and some omp pragmas, are not associated
4721 with regular c code, and so are not to be considered statements
4722 syntactically. This ensures that the user doesn't put them
4723 places that would turn into syntax errors if the directive
4724 were ignored. */
4725 if (c_parser_pragma (parser, pragma_compound))
4726 last_label = false, last_stmt = true;
4728 else if (c_parser_next_token_is (parser, CPP_EOF))
4730 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4731 c_parser_error (parser, "expected declaration or statement");
4732 return;
4734 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4736 if (parser->in_if_block)
4738 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4739 error_at (loc, """expected %<}%> before %<else%>");
4740 return;
4742 else
4744 error_at (loc, "%<else%> without a previous %<if%>");
4745 c_parser_consume_token (parser);
4746 continue;
4749 else
4751 statement:
4752 last_label = false;
4753 last_stmt = true;
4754 mark_valid_location_for_stdc_pragma (false);
4755 c_parser_statement_after_labels (parser);
4758 parser->error = false;
4760 if (last_label)
4761 error_at (label_loc, "label at end of compound statement");
4762 c_parser_consume_token (parser);
4763 pop_upc_consistency_mode ();
4764 /* Restore the value we started with. */
4765 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4768 /* Parse all consecutive labels. */
4770 static void
4771 c_parser_all_labels (c_parser *parser)
4773 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4774 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4775 || (c_parser_next_token_is (parser, CPP_NAME)
4776 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4777 c_parser_label (parser);
4780 /* Parse a label (C90 6.6.1, C99 6.8.1).
4782 label:
4783 identifier : attributes[opt]
4784 case constant-expression :
4785 default :
4787 GNU extensions:
4789 label:
4790 case constant-expression ... constant-expression :
4792 The use of attributes on labels is a GNU extension. The syntax in
4793 GNU C accepts any expressions without commas, non-constant
4794 expressions being rejected later. */
4796 static void
4797 c_parser_label (c_parser *parser)
4799 location_t loc1 = c_parser_peek_token (parser)->location;
4800 tree label = NULL_TREE;
4801 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4803 tree exp1, exp2;
4804 c_parser_consume_token (parser);
4805 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4806 if (c_parser_next_token_is (parser, CPP_COLON))
4808 c_parser_consume_token (parser);
4809 label = do_case (loc1, exp1, NULL_TREE);
4811 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4813 c_parser_consume_token (parser);
4814 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4815 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4816 label = do_case (loc1, exp1, exp2);
4818 else
4819 c_parser_error (parser, "expected %<:%> or %<...%>");
4821 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4823 c_parser_consume_token (parser);
4824 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4825 label = do_case (loc1, NULL_TREE, NULL_TREE);
4827 else
4829 tree name = c_parser_peek_token (parser)->value;
4830 tree tlab;
4831 tree attrs;
4832 location_t loc2 = c_parser_peek_token (parser)->location;
4833 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4834 c_parser_consume_token (parser);
4835 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4836 c_parser_consume_token (parser);
4837 attrs = c_parser_attributes (parser);
4838 tlab = define_label (loc2, name);
4839 if (tlab)
4841 decl_attributes (&tlab, attrs, 0);
4842 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4845 if (label)
4847 if (c_parser_next_tokens_start_declaration (parser))
4849 error_at (c_parser_peek_token (parser)->location,
4850 "a label can only be part of a statement and "
4851 "a declaration is not a statement");
4852 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4853 /*static_assert_ok*/ true,
4854 /*empty_ok*/ true, /*nested*/ true,
4855 /*start_attr_ok*/ true, NULL,
4856 vNULL);
4861 /* Parse a statement (C90 6.6, C99 6.8).
4863 statement:
4864 labeled-statement
4865 compound-statement
4866 expression-statement
4867 selection-statement
4868 iteration-statement
4869 jump-statement
4871 labeled-statement:
4872 label statement
4874 expression-statement:
4875 expression[opt] ;
4877 selection-statement:
4878 if-statement
4879 switch-statement
4881 iteration-statement:
4882 while-statement
4883 do-statement
4884 for-statement
4886 jump-statement:
4887 goto identifier ;
4888 continue ;
4889 break ;
4890 return expression[opt] ;
4892 GNU extensions:
4894 statement:
4895 asm-statement
4897 jump-statement:
4898 goto * expression ;
4900 Objective-C:
4902 statement:
4903 objc-throw-statement
4904 objc-try-catch-statement
4905 objc-synchronized-statement
4907 objc-throw-statement:
4908 @throw expression ;
4909 @throw ;
4911 OpenACC:
4913 statement:
4914 openacc-construct
4916 openacc-construct:
4917 parallel-construct
4918 kernels-construct
4919 data-construct
4920 loop-construct
4922 parallel-construct:
4923 parallel-directive structured-block
4925 kernels-construct:
4926 kernels-directive structured-block
4928 data-construct:
4929 data-directive structured-block
4931 loop-construct:
4932 loop-directive structured-block
4934 OpenMP:
4936 statement:
4937 openmp-construct
4939 openmp-construct:
4940 parallel-construct
4941 for-construct
4942 simd-construct
4943 for-simd-construct
4944 sections-construct
4945 single-construct
4946 parallel-for-construct
4947 parallel-for-simd-construct
4948 parallel-sections-construct
4949 master-construct
4950 critical-construct
4951 atomic-construct
4952 ordered-construct
4954 parallel-construct:
4955 parallel-directive structured-block
4957 for-construct:
4958 for-directive iteration-statement
4960 simd-construct:
4961 simd-directive iteration-statements
4963 for-simd-construct:
4964 for-simd-directive iteration-statements
4966 sections-construct:
4967 sections-directive section-scope
4969 single-construct:
4970 single-directive structured-block
4972 parallel-for-construct:
4973 parallel-for-directive iteration-statement
4975 parallel-for-simd-construct:
4976 parallel-for-simd-directive iteration-statement
4978 parallel-sections-construct:
4979 parallel-sections-directive section-scope
4981 master-construct:
4982 master-directive structured-block
4984 critical-construct:
4985 critical-directive structured-block
4987 atomic-construct:
4988 atomic-directive expression-statement
4990 ordered-construct:
4991 ordered-directive structured-block
4993 Transactional Memory:
4995 statement:
4996 transaction-statement
4997 transaction-cancel-statement
5000 static void
5001 c_parser_statement (c_parser *parser)
5003 c_parser_all_labels (parser);
5004 c_parser_statement_after_labels (parser);
5007 /* Parse a statement, other than a labeled statement. */
5009 static void
5010 c_parser_statement_after_labels (c_parser *parser)
5012 location_t loc = c_parser_peek_token (parser)->location;
5013 tree stmt = NULL_TREE;
5014 bool in_if_block = parser->in_if_block;
5015 parser->in_if_block = false;
5016 switch (c_parser_peek_token (parser)->type)
5018 case CPP_OPEN_BRACE:
5019 add_stmt (c_parser_compound_statement (parser));
5020 break;
5021 case CPP_KEYWORD:
5022 switch (c_parser_peek_token (parser)->keyword)
5024 case RID_IF:
5025 c_parser_if_statement (parser);
5026 break;
5027 case RID_SWITCH:
5028 c_parser_switch_statement (parser);
5029 break;
5030 case RID_WHILE:
5031 c_parser_while_statement (parser, false);
5032 break;
5033 case RID_DO:
5034 c_parser_do_statement (parser, false);
5035 break;
5036 case RID_FOR:
5037 c_parser_for_statement (parser, false);
5038 break;
5039 case RID_CILK_FOR:
5040 if (!flag_cilkplus)
5042 error_at (c_parser_peek_token (parser)->location,
5043 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5044 c_parser_skip_to_end_of_block_or_statement (parser);
5046 else
5047 c_parser_cilk_for (parser, integer_zero_node);
5048 break;
5049 case RID_CILK_SYNC:
5050 c_parser_consume_token (parser);
5051 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5052 if (!flag_cilkplus)
5053 error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5054 else
5055 add_stmt (build_cilk_sync ());
5056 break;
5057 case RID_GOTO:
5058 c_parser_consume_token (parser);
5059 if (c_parser_next_token_is (parser, CPP_NAME))
5061 stmt = c_finish_goto_label (loc,
5062 c_parser_peek_token (parser)->value);
5063 c_parser_consume_token (parser);
5065 else if (c_parser_next_token_is (parser, CPP_MULT))
5067 struct c_expr val;
5069 c_parser_consume_token (parser);
5070 val = c_parser_expression (parser);
5071 if (check_no_cilk (val.value,
5072 "Cilk array notation cannot be used as a computed goto expression",
5073 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5074 loc))
5075 val.value = error_mark_node;
5076 val = convert_lvalue_to_rvalue (loc, val, false, true);
5077 stmt = c_finish_goto_ptr (loc, val.value);
5079 else
5080 c_parser_error (parser, "expected identifier or %<*%>");
5081 goto expect_semicolon;
5082 case RID_CONTINUE:
5083 c_parser_consume_token (parser);
5084 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5085 goto expect_semicolon;
5086 case RID_BREAK:
5087 c_parser_consume_token (parser);
5088 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5089 goto expect_semicolon;
5090 case RID_RETURN:
5091 c_parser_consume_token (parser);
5092 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5094 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5095 c_parser_consume_token (parser);
5097 else
5099 location_t xloc = c_parser_peek_token (parser)->location;
5100 struct c_expr expr = c_parser_expression_conv (parser);
5101 mark_exp_read (expr.value);
5102 stmt = c_finish_return (xloc, expr.value, expr.original_type);
5103 goto expect_semicolon;
5105 break;
5106 case RID_ASM:
5107 stmt = c_parser_asm_statement (parser);
5108 break;
5109 case RID_TRANSACTION_ATOMIC:
5110 case RID_TRANSACTION_RELAXED:
5111 stmt = c_parser_transaction (parser,
5112 c_parser_peek_token (parser)->keyword);
5113 break;
5114 case RID_TRANSACTION_CANCEL:
5115 stmt = c_parser_transaction_cancel (parser);
5116 goto expect_semicolon;
5117 case RID_AT_THROW:
5118 gcc_assert (c_dialect_objc ());
5119 c_parser_consume_token (parser);
5120 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5122 stmt = objc_build_throw_stmt (loc, NULL_TREE);
5123 c_parser_consume_token (parser);
5125 else
5127 struct c_expr expr = c_parser_expression (parser);
5128 expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5129 if (check_no_cilk (expr.value,
5130 "Cilk array notation cannot be used for a throw expression",
5131 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5132 expr.value = error_mark_node;
5133 else
5135 expr.value = c_fully_fold (expr.value, false, NULL);
5136 stmt = objc_build_throw_stmt (loc, expr.value);
5138 goto expect_semicolon;
5140 break;
5141 case RID_AT_TRY:
5142 gcc_assert (c_dialect_objc ());
5143 c_parser_objc_try_catch_finally_statement (parser);
5144 break;
5145 case RID_AT_SYNCHRONIZED:
5146 gcc_assert (c_dialect_objc ());
5147 c_parser_objc_synchronized_statement (parser);
5148 break;
5149 case RID_UPC_FORALL:
5150 gcc_assert (flag_upc);
5151 c_parser_upc_forall_statement (parser);
5152 break;
5153 case RID_UPC_NOTIFY:
5154 gcc_assert (flag_upc);
5155 c_parser_upc_sync_statement (parser, UPC_SYNC_NOTIFY_OP);
5156 goto expect_semicolon;
5157 case RID_UPC_WAIT:
5158 gcc_assert (flag_upc);
5159 c_parser_upc_sync_statement (parser, UPC_SYNC_WAIT_OP);
5160 goto expect_semicolon;
5161 case RID_UPC_BARRIER:
5162 gcc_assert (flag_upc);
5163 c_parser_upc_sync_statement (parser, UPC_SYNC_BARRIER_OP);
5164 goto expect_semicolon;
5165 default:
5166 goto expr_stmt;
5168 break;
5169 case CPP_SEMICOLON:
5170 c_parser_consume_token (parser);
5171 break;
5172 case CPP_CLOSE_PAREN:
5173 case CPP_CLOSE_SQUARE:
5174 /* Avoid infinite loop in error recovery:
5175 c_parser_skip_until_found stops at a closing nesting
5176 delimiter without consuming it, but here we need to consume
5177 it to proceed further. */
5178 c_parser_error (parser, "expected statement");
5179 c_parser_consume_token (parser);
5180 break;
5181 case CPP_PRAGMA:
5182 c_parser_pragma (parser, pragma_stmt);
5183 break;
5184 default:
5185 expr_stmt:
5186 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5187 expect_semicolon:
5188 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5189 break;
5191 /* Two cases cannot and do not have line numbers associated: If stmt
5192 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5193 cannot hold line numbers. But that's OK because the statement
5194 will either be changed to a MODIFY_EXPR during gimplification of
5195 the statement expr, or discarded. If stmt was compound, but
5196 without new variables, we will have skipped the creation of a
5197 BIND and will have a bare STATEMENT_LIST. But that's OK because
5198 (recursively) all of the component statements should already have
5199 line numbers assigned. ??? Can we discard no-op statements
5200 earlier? */
5201 if (CAN_HAVE_LOCATION_P (stmt)
5202 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5203 SET_EXPR_LOCATION (stmt, loc);
5205 parser->in_if_block = in_if_block;
5208 /* Parse the condition from an if, do, while or for statements. */
5210 static tree
5211 c_parser_condition (c_parser *parser)
5213 location_t loc ATTRIBUTE_UNUSED = c_parser_peek_token (parser)->location;
5214 tree cond;
5215 cond = c_parser_expression_conv (parser).value;
5216 cond = c_objc_common_truthvalue_conversion (loc, cond);
5217 cond = c_fully_fold (cond, false, NULL);
5218 if (warn_sequence_point)
5219 verify_sequence_points (cond);
5220 return cond;
5223 /* Parse a parenthesized condition from an if, do or while statement.
5225 condition:
5226 ( expression )
5228 static tree
5229 c_parser_paren_condition (c_parser *parser)
5231 tree cond;
5232 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5233 return error_mark_node;
5234 cond = c_parser_condition (parser);
5235 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5236 return cond;
5239 /* Parse a statement which is a block in C99. */
5241 static tree
5242 c_parser_c99_block_statement (c_parser *parser)
5244 tree block = c_begin_compound_stmt (flag_isoc99);
5245 location_t loc = c_parser_peek_token (parser)->location;
5246 c_parser_statement (parser);
5247 return c_end_compound_stmt (loc, block, flag_isoc99);
5250 /* Parse the body of an if statement. This is just parsing a
5251 statement but (a) it is a block in C99, (b) we track whether the
5252 body is an if statement for the sake of -Wparentheses warnings, (c)
5253 we handle an empty body specially for the sake of -Wempty-body
5254 warnings, and (d) we call parser_compound_statement directly
5255 because c_parser_statement_after_labels resets
5256 parser->in_if_block. */
5258 static tree
5259 c_parser_if_body (c_parser *parser, bool *if_p)
5261 tree block = c_begin_compound_stmt (flag_isoc99);
5262 location_t body_loc = c_parser_peek_token (parser)->location;
5263 c_parser_all_labels (parser);
5264 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
5265 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5267 location_t loc = c_parser_peek_token (parser)->location;
5268 add_stmt (build_empty_stmt (loc));
5269 c_parser_consume_token (parser);
5270 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5271 warning_at (loc, OPT_Wempty_body,
5272 "suggest braces around empty body in an %<if%> statement");
5274 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5275 add_stmt (c_parser_compound_statement (parser));
5276 else
5277 c_parser_statement_after_labels (parser);
5278 return c_end_compound_stmt (body_loc, block, flag_isoc99);
5281 /* Parse the else body of an if statement. This is just parsing a
5282 statement but (a) it is a block in C99, (b) we handle an empty body
5283 specially for the sake of -Wempty-body warnings. */
5285 static tree
5286 c_parser_else_body (c_parser *parser)
5288 location_t else_loc = c_parser_peek_token (parser)->location;
5289 tree block = c_begin_compound_stmt (flag_isoc99);
5290 c_parser_all_labels (parser);
5291 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5293 location_t loc = c_parser_peek_token (parser)->location;
5294 warning_at (loc,
5295 OPT_Wempty_body,
5296 "suggest braces around empty body in an %<else%> statement");
5297 add_stmt (build_empty_stmt (loc));
5298 c_parser_consume_token (parser);
5300 else
5301 c_parser_statement_after_labels (parser);
5302 return c_end_compound_stmt (else_loc, block, flag_isoc99);
5305 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5307 if-statement:
5308 if ( expression ) statement
5309 if ( expression ) statement else statement
5312 static void
5313 c_parser_if_statement (c_parser *parser)
5315 tree block;
5316 location_t loc;
5317 tree cond;
5318 bool first_if = false;
5319 tree first_body, second_body;
5320 bool in_if_block;
5321 tree if_stmt;
5323 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5324 c_parser_consume_token (parser);
5325 block = c_begin_compound_stmt (flag_isoc99);
5326 loc = c_parser_peek_token (parser)->location;
5327 cond = c_parser_paren_condition (parser);
5328 if (flag_cilkplus && contains_cilk_spawn_stmt (cond))
5330 error_at (loc, "if statement cannot contain %<Cilk_spawn%>");
5331 cond = error_mark_node;
5333 in_if_block = parser->in_if_block;
5334 parser->in_if_block = true;
5335 first_body = c_parser_if_body (parser, &first_if);
5336 parser->in_if_block = in_if_block;
5337 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5339 c_parser_consume_token (parser);
5340 second_body = c_parser_else_body (parser);
5342 else
5343 second_body = NULL_TREE;
5344 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
5345 if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
5347 /* If the if statement contains array notations, then we expand them. */
5348 if (flag_cilkplus && contains_array_notation_expr (if_stmt))
5349 if_stmt = fix_conditional_array_notations (if_stmt);
5350 add_stmt (if_stmt);
5353 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5355 switch-statement:
5356 switch (expression) statement
5359 static void
5360 c_parser_switch_statement (c_parser *parser)
5362 struct c_expr ce;
5363 tree block, expr, body, save_break;
5364 location_t switch_loc = c_parser_peek_token (parser)->location;
5365 location_t switch_cond_loc;
5366 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5367 c_parser_consume_token (parser);
5368 block = c_begin_compound_stmt (flag_isoc99);
5369 bool explicit_cast_p = false;
5370 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5372 switch_cond_loc = c_parser_peek_token (parser)->location;
5373 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5374 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5375 explicit_cast_p = true;
5376 ce = c_parser_expression (parser);
5377 ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5378 expr = ce.value;
5379 /* ??? expr has no valid location? */
5380 if (check_no_cilk (expr,
5381 "Cilk array notation cannot be used as a condition for switch statement",
5382 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5383 switch_cond_loc))
5384 expr = error_mark_node;
5385 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5387 else
5389 switch_cond_loc = UNKNOWN_LOCATION;
5390 expr = error_mark_node;
5392 c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5393 save_break = c_break_label;
5394 c_break_label = NULL_TREE;
5395 body = c_parser_c99_block_statement (parser);
5396 c_finish_case (body, ce.original_type);
5397 if (c_break_label)
5399 location_t here = c_parser_peek_token (parser)->location;
5400 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5401 SET_EXPR_LOCATION (t, here);
5402 add_stmt (t);
5404 c_break_label = save_break;
5405 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5408 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5410 while-statement:
5411 while (expression) statement
5414 static void
5415 c_parser_while_statement (c_parser *parser, bool ivdep)
5417 tree block, cond, body, save_break, save_cont;
5418 location_t loc;
5419 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5420 c_parser_consume_token (parser);
5421 block = c_begin_compound_stmt (flag_isoc99);
5422 loc = c_parser_peek_token (parser)->location;
5423 cond = c_parser_paren_condition (parser);
5424 if (check_no_cilk (cond,
5425 "Cilk array notation cannot be used as a condition for while statement",
5426 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5427 cond = error_mark_node;
5428 if (ivdep && cond != error_mark_node)
5429 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5430 build_int_cst (integer_type_node,
5431 annot_expr_ivdep_kind));
5432 save_break = c_break_label;
5433 c_break_label = NULL_TREE;
5434 save_cont = c_cont_label;
5435 c_cont_label = NULL_TREE;
5436 body = c_parser_c99_block_statement (parser);
5437 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5438 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5439 c_break_label = save_break;
5440 c_cont_label = save_cont;
5443 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5445 do-statement:
5446 do statement while ( expression ) ;
5449 static void
5450 c_parser_do_statement (c_parser *parser, bool ivdep)
5452 tree block, cond, body, save_break, save_cont, new_break, new_cont;
5453 location_t loc;
5454 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5455 c_parser_consume_token (parser);
5456 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5457 warning_at (c_parser_peek_token (parser)->location,
5458 OPT_Wempty_body,
5459 "suggest braces around empty body in %<do%> statement");
5460 block = c_begin_compound_stmt (flag_isoc99);
5461 loc = c_parser_peek_token (parser)->location;
5462 save_break = c_break_label;
5463 c_break_label = NULL_TREE;
5464 save_cont = c_cont_label;
5465 c_cont_label = NULL_TREE;
5466 body = c_parser_c99_block_statement (parser);
5467 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5468 new_break = c_break_label;
5469 c_break_label = save_break;
5470 new_cont = c_cont_label;
5471 c_cont_label = save_cont;
5472 cond = c_parser_paren_condition (parser);
5473 if (check_no_cilk (cond,
5474 "Cilk array notation cannot be used as a condition for a do-while statement",
5475 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5476 cond = error_mark_node;
5477 if (ivdep && cond != error_mark_node)
5478 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5479 build_int_cst (integer_type_node,
5480 annot_expr_ivdep_kind));
5481 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5482 c_parser_skip_to_end_of_block_or_statement (parser);
5483 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5484 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5487 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5489 for-statement:
5490 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5491 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5493 The form with a declaration is new in C99.
5495 ??? In accordance with the old parser, the declaration may be a
5496 nested function, which is then rejected in check_for_loop_decls,
5497 but does it make any sense for this to be included in the grammar?
5498 Note in particular that the nested function does not include a
5499 trailing ';', whereas the "declaration" production includes one.
5500 Also, can we reject bad declarations earlier and cheaper than
5501 check_for_loop_decls?
5503 In Objective-C, there are two additional variants:
5505 foreach-statement:
5506 for ( expression in expresssion ) statement
5507 for ( declaration in expression ) statement
5509 This is inconsistent with C, because the second variant is allowed
5510 even if c99 is not enabled.
5512 The rest of the comment documents these Objective-C foreach-statement.
5514 Here is the canonical example of the first variant:
5515 for (object in array) { do something with object }
5516 we call the first expression ("object") the "object_expression" and
5517 the second expression ("array") the "collection_expression".
5518 object_expression must be an lvalue of type "id" (a generic Objective-C
5519 object) because the loop works by assigning to object_expression the
5520 various objects from the collection_expression. collection_expression
5521 must evaluate to something of type "id" which responds to the method
5522 countByEnumeratingWithState:objects:count:.
5524 The canonical example of the second variant is:
5525 for (id object in array) { do something with object }
5526 which is completely equivalent to
5528 id object;
5529 for (object in array) { do something with object }
5531 Note that initizializing 'object' in some way (eg, "for ((object =
5532 xxx) in array) { do something with object }") is possibly
5533 technically valid, but completely pointless as 'object' will be
5534 assigned to something else as soon as the loop starts. We should
5535 most likely reject it (TODO).
5537 The beginning of the Objective-C foreach-statement looks exactly
5538 like the beginning of the for-statement, and we can tell it is a
5539 foreach-statement only because the initial declaration or
5540 expression is terminated by 'in' instead of ';'.
5543 static void
5544 c_parser_for_statement (c_parser *parser, bool ivdep)
5546 tree block, cond, incr, save_break, save_cont, body;
5547 /* The following are only used when parsing an ObjC foreach statement. */
5548 tree object_expression;
5549 /* Silence the bogus uninitialized warning. */
5550 tree collection_expression = NULL;
5551 location_t loc = c_parser_peek_token (parser)->location;
5552 location_t for_loc = c_parser_peek_token (parser)->location;
5553 bool is_foreach_statement = false;
5554 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
5555 c_parser_consume_token (parser);
5556 /* Open a compound statement in Objective-C as well, just in case this is
5557 as foreach expression. */
5558 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
5559 cond = error_mark_node;
5560 incr = error_mark_node;
5561 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5563 /* Parse the initialization declaration or expression. */
5564 object_expression = error_mark_node;
5565 parser->objc_could_be_foreach_context = c_dialect_objc ();
5566 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5568 parser->objc_could_be_foreach_context = false;
5569 c_parser_consume_token (parser);
5570 c_finish_expr_stmt (loc, NULL_TREE);
5572 else if (c_parser_next_tokens_start_declaration (parser))
5574 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
5575 &object_expression, vNULL);
5576 parser->objc_could_be_foreach_context = false;
5578 if (c_parser_next_token_is_keyword (parser, RID_IN))
5580 c_parser_consume_token (parser);
5581 is_foreach_statement = true;
5582 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5583 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5585 else
5586 check_for_loop_decls (for_loc, flag_isoc99);
5588 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5590 /* __extension__ can start a declaration, but is also an
5591 unary operator that can start an expression. Consume all
5592 but the last of a possible series of __extension__ to
5593 determine which. */
5594 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5595 && (c_parser_peek_2nd_token (parser)->keyword
5596 == RID_EXTENSION))
5597 c_parser_consume_token (parser);
5598 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5600 int ext;
5601 ext = disable_extension_diagnostics ();
5602 c_parser_consume_token (parser);
5603 c_parser_declaration_or_fndef (parser, true, true, true, true,
5604 true, &object_expression, vNULL);
5605 parser->objc_could_be_foreach_context = false;
5607 restore_extension_diagnostics (ext);
5608 if (c_parser_next_token_is_keyword (parser, RID_IN))
5610 c_parser_consume_token (parser);
5611 is_foreach_statement = true;
5612 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5613 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5615 else
5616 check_for_loop_decls (for_loc, flag_isoc99);
5618 else
5619 goto init_expr;
5621 else
5623 init_expr:
5625 struct c_expr ce;
5626 tree init_expression;
5627 ce = c_parser_expression (parser);
5628 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5629 level statement", but it works just fine, so allow it. */
5630 init_expression = ce.value;
5631 parser->objc_could_be_foreach_context = false;
5632 if (c_parser_next_token_is_keyword (parser, RID_IN))
5634 c_parser_consume_token (parser);
5635 is_foreach_statement = true;
5636 if (! lvalue_p (init_expression))
5637 c_parser_error (parser, "invalid iterating variable in fast enumeration");
5638 object_expression = c_fully_fold (init_expression, false, NULL);
5640 else
5642 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5643 init_expression = ce.value;
5644 c_finish_expr_stmt (loc, init_expression);
5645 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5649 /* Parse the loop condition. In the case of a foreach
5650 statement, there is no loop condition. */
5651 gcc_assert (!parser->objc_could_be_foreach_context);
5652 if (!is_foreach_statement)
5654 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5656 if (ivdep)
5658 c_parser_error (parser, "missing loop condition in loop with "
5659 "%<GCC ivdep%> pragma");
5660 cond = error_mark_node;
5662 else
5664 c_parser_consume_token (parser);
5665 cond = NULL_TREE;
5668 else
5670 cond = c_parser_condition (parser);
5671 if (check_no_cilk (cond,
5672 "Cilk array notation cannot be used in a condition for a for-loop",
5673 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5674 cond = error_mark_node;
5675 c_parser_skip_until_found (parser, CPP_SEMICOLON,
5676 "expected %<;%>");
5678 if (ivdep && cond != error_mark_node)
5679 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5680 build_int_cst (integer_type_node,
5681 annot_expr_ivdep_kind));
5683 /* Parse the increment expression (the third expression in a
5684 for-statement). In the case of a foreach-statement, this is
5685 the expression that follows the 'in'. */
5686 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5688 if (is_foreach_statement)
5690 c_parser_error (parser, "missing collection in fast enumeration");
5691 collection_expression = error_mark_node;
5693 else
5694 incr = c_process_expr_stmt (loc, NULL_TREE);
5696 else
5698 if (is_foreach_statement)
5699 collection_expression = c_fully_fold (c_parser_expression (parser).value,
5700 false, NULL);
5701 else
5703 struct c_expr ce = c_parser_expression (parser);
5704 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5705 incr = c_process_expr_stmt (loc, ce.value);
5708 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5710 save_break = c_break_label;
5711 c_break_label = NULL_TREE;
5712 save_cont = c_cont_label;
5713 c_cont_label = NULL_TREE;
5714 body = c_parser_c99_block_statement (parser);
5715 if (is_foreach_statement)
5716 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5717 else
5718 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5719 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5720 c_break_label = save_break;
5721 c_cont_label = save_cont;
5724 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5725 statement with inputs, outputs, clobbers, and volatile tag
5726 allowed.
5728 asm-statement:
5729 asm type-qualifier[opt] ( asm-argument ) ;
5730 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5732 asm-argument:
5733 asm-string-literal
5734 asm-string-literal : asm-operands[opt]
5735 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5736 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5738 asm-goto-argument:
5739 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5740 : asm-goto-operands
5742 Qualifiers other than volatile are accepted in the syntax but
5743 warned for. */
5745 static tree
5746 c_parser_asm_statement (c_parser *parser)
5748 tree quals, str, outputs, inputs, clobbers, labels, ret;
5749 bool simple, is_goto;
5750 location_t asm_loc = c_parser_peek_token (parser)->location;
5751 int section, nsections;
5753 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5754 c_parser_consume_token (parser);
5755 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5757 quals = c_parser_peek_token (parser)->value;
5758 c_parser_consume_token (parser);
5760 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5761 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5763 warning_at (c_parser_peek_token (parser)->location,
5765 "%E qualifier ignored on asm",
5766 c_parser_peek_token (parser)->value);
5767 quals = NULL_TREE;
5768 c_parser_consume_token (parser);
5770 else
5771 quals = NULL_TREE;
5773 is_goto = false;
5774 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5776 c_parser_consume_token (parser);
5777 is_goto = true;
5780 /* ??? Follow the C++ parser rather than using the
5781 lex_untranslated_string kludge. */
5782 parser->lex_untranslated_string = true;
5783 ret = NULL;
5785 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5786 goto error;
5788 str = c_parser_asm_string_literal (parser);
5789 if (str == NULL_TREE)
5790 goto error_close_paren;
5792 simple = true;
5793 outputs = NULL_TREE;
5794 inputs = NULL_TREE;
5795 clobbers = NULL_TREE;
5796 labels = NULL_TREE;
5798 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5799 goto done_asm;
5801 /* Parse each colon-delimited section of operands. */
5802 nsections = 3 + is_goto;
5803 for (section = 0; section < nsections; ++section)
5805 if (!c_parser_require (parser, CPP_COLON,
5806 is_goto
5807 ? "expected %<:%>"
5808 : "expected %<:%> or %<)%>"))
5809 goto error_close_paren;
5811 /* Once past any colon, we're no longer a simple asm. */
5812 simple = false;
5814 if ((!c_parser_next_token_is (parser, CPP_COLON)
5815 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5816 || section == 3)
5817 switch (section)
5819 case 0:
5820 /* For asm goto, we don't allow output operands, but reserve
5821 the slot for a future extension that does allow them. */
5822 if (!is_goto)
5823 outputs = c_parser_asm_operands (parser);
5824 break;
5825 case 1:
5826 inputs = c_parser_asm_operands (parser);
5827 break;
5828 case 2:
5829 clobbers = c_parser_asm_clobbers (parser);
5830 break;
5831 case 3:
5832 labels = c_parser_asm_goto_operands (parser);
5833 break;
5834 default:
5835 gcc_unreachable ();
5838 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5839 goto done_asm;
5842 done_asm:
5843 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5845 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5846 goto error;
5849 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5850 c_parser_skip_to_end_of_block_or_statement (parser);
5852 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5853 clobbers, labels, simple));
5855 error:
5856 parser->lex_untranslated_string = false;
5857 return ret;
5859 error_close_paren:
5860 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5861 goto error;
5864 /* Parse asm operands, a GNU extension.
5866 asm-operands:
5867 asm-operand
5868 asm-operands , asm-operand
5870 asm-operand:
5871 asm-string-literal ( expression )
5872 [ identifier ] asm-string-literal ( expression )
5875 static tree
5876 c_parser_asm_operands (c_parser *parser)
5878 tree list = NULL_TREE;
5879 while (true)
5881 tree name, str;
5882 struct c_expr expr;
5883 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5885 c_parser_consume_token (parser);
5886 if (c_parser_next_token_is (parser, CPP_NAME))
5888 tree id = c_parser_peek_token (parser)->value;
5889 c_parser_consume_token (parser);
5890 name = build_string (IDENTIFIER_LENGTH (id),
5891 IDENTIFIER_POINTER (id));
5893 else
5895 c_parser_error (parser, "expected identifier");
5896 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5897 return NULL_TREE;
5899 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5900 "expected %<]%>");
5902 else
5903 name = NULL_TREE;
5904 str = c_parser_asm_string_literal (parser);
5905 if (str == NULL_TREE)
5906 return NULL_TREE;
5907 parser->lex_untranslated_string = false;
5908 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5910 parser->lex_untranslated_string = true;
5911 return NULL_TREE;
5913 expr = c_parser_expression (parser);
5914 mark_exp_read (expr.value);
5915 parser->lex_untranslated_string = true;
5916 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5918 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5919 return NULL_TREE;
5921 list = chainon (list, build_tree_list (build_tree_list (name, str),
5922 expr.value));
5923 if (c_parser_next_token_is (parser, CPP_COMMA))
5924 c_parser_consume_token (parser);
5925 else
5926 break;
5928 return list;
5931 /* Parse asm clobbers, a GNU extension.
5933 asm-clobbers:
5934 asm-string-literal
5935 asm-clobbers , asm-string-literal
5938 static tree
5939 c_parser_asm_clobbers (c_parser *parser)
5941 tree list = NULL_TREE;
5942 while (true)
5944 tree str = c_parser_asm_string_literal (parser);
5945 if (str)
5946 list = tree_cons (NULL_TREE, str, list);
5947 else
5948 return NULL_TREE;
5949 if (c_parser_next_token_is (parser, CPP_COMMA))
5950 c_parser_consume_token (parser);
5951 else
5952 break;
5954 return list;
5957 /* Parse asm goto labels, a GNU extension.
5959 asm-goto-operands:
5960 identifier
5961 asm-goto-operands , identifier
5964 static tree
5965 c_parser_asm_goto_operands (c_parser *parser)
5967 tree list = NULL_TREE;
5968 while (true)
5970 tree name, label;
5972 if (c_parser_next_token_is (parser, CPP_NAME))
5974 c_token *tok = c_parser_peek_token (parser);
5975 name = tok->value;
5976 label = lookup_label_for_goto (tok->location, name);
5977 c_parser_consume_token (parser);
5978 TREE_USED (label) = 1;
5980 else
5982 c_parser_error (parser, "expected identifier");
5983 return NULL_TREE;
5986 name = build_string (IDENTIFIER_LENGTH (name),
5987 IDENTIFIER_POINTER (name));
5988 list = tree_cons (name, label, list);
5989 if (c_parser_next_token_is (parser, CPP_COMMA))
5990 c_parser_consume_token (parser);
5991 else
5992 return nreverse (list);
5996 /* Parse an expression other than a compound expression; that is, an
5997 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5998 NULL then it is an Objective-C message expression which is the
5999 primary-expression starting the expression as an initializer.
6001 assignment-expression:
6002 conditional-expression
6003 unary-expression assignment-operator assignment-expression
6005 assignment-operator: one of
6006 = *= /= %= += -= <<= >>= &= ^= |=
6008 In GNU C we accept any conditional expression on the LHS and
6009 diagnose the invalid lvalue rather than producing a syntax
6010 error. */
6012 static struct c_expr
6013 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
6014 tree omp_atomic_lhs)
6016 struct c_expr lhs, rhs, ret;
6017 enum tree_code code;
6018 location_t op_location, exp_location;
6019 gcc_assert (!after || c_dialect_objc ());
6020 lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
6021 op_location = c_parser_peek_token (parser)->location;
6022 switch (c_parser_peek_token (parser)->type)
6024 case CPP_EQ:
6025 code = NOP_EXPR;
6026 break;
6027 case CPP_MULT_EQ:
6028 code = MULT_EXPR;
6029 break;
6030 case CPP_DIV_EQ:
6031 code = TRUNC_DIV_EXPR;
6032 break;
6033 case CPP_MOD_EQ:
6034 code = TRUNC_MOD_EXPR;
6035 break;
6036 case CPP_PLUS_EQ:
6037 code = PLUS_EXPR;
6038 break;
6039 case CPP_MINUS_EQ:
6040 code = MINUS_EXPR;
6041 break;
6042 case CPP_LSHIFT_EQ:
6043 code = LSHIFT_EXPR;
6044 break;
6045 case CPP_RSHIFT_EQ:
6046 code = RSHIFT_EXPR;
6047 break;
6048 case CPP_AND_EQ:
6049 code = BIT_AND_EXPR;
6050 break;
6051 case CPP_XOR_EQ:
6052 code = BIT_XOR_EXPR;
6053 break;
6054 case CPP_OR_EQ:
6055 code = BIT_IOR_EXPR;
6056 break;
6057 default:
6058 return lhs;
6060 c_parser_consume_token (parser);
6061 exp_location = c_parser_peek_token (parser)->location;
6062 rhs = c_parser_expr_no_commas (parser, NULL);
6063 rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
6065 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
6066 code, exp_location, rhs.value,
6067 rhs.original_type);
6068 if (code == NOP_EXPR)
6069 ret.original_code = MODIFY_EXPR;
6070 else
6072 TREE_NO_WARNING (ret.value) = 1;
6073 ret.original_code = ERROR_MARK;
6075 ret.original_type = NULL;
6076 return ret;
6079 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6080 is not NULL then it is an Objective-C message expression which is
6081 the primary-expression starting the expression as an initializer.
6083 conditional-expression:
6084 logical-OR-expression
6085 logical-OR-expression ? expression : conditional-expression
6087 GNU extensions:
6089 conditional-expression:
6090 logical-OR-expression ? : conditional-expression
6093 static struct c_expr
6094 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6095 tree omp_atomic_lhs)
6097 struct c_expr cond, exp1, exp2, ret;
6098 location_t cond_loc, colon_loc, middle_loc;
6100 gcc_assert (!after || c_dialect_objc ());
6102 cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6104 if (c_parser_next_token_is_not (parser, CPP_QUERY))
6105 return cond;
6106 cond_loc = c_parser_peek_token (parser)->location;
6107 cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6108 c_parser_consume_token (parser);
6109 if (c_parser_next_token_is (parser, CPP_COLON))
6111 tree eptype = NULL_TREE;
6113 middle_loc = c_parser_peek_token (parser)->location;
6114 pedwarn (middle_loc, OPT_Wpedantic,
6115 "ISO C forbids omitting the middle term of a ?: expression");
6116 warn_for_omitted_condop (middle_loc, cond.value);
6117 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6119 eptype = TREE_TYPE (cond.value);
6120 cond.value = TREE_OPERAND (cond.value, 0);
6122 /* Make sure first operand is calculated only once. */
6123 exp1.value = c_save_expr (default_conversion (cond.value));
6124 if (eptype)
6125 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6126 exp1.original_type = NULL;
6127 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6128 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6130 else
6132 cond.value
6133 = c_objc_common_truthvalue_conversion
6134 (cond_loc, default_conversion (cond.value));
6135 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6136 exp1 = c_parser_expression_conv (parser);
6137 mark_exp_read (exp1.value);
6138 c_inhibit_evaluation_warnings +=
6139 ((cond.value == truthvalue_true_node)
6140 - (cond.value == truthvalue_false_node));
6143 colon_loc = c_parser_peek_token (parser)->location;
6144 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6146 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6147 ret.value = error_mark_node;
6148 ret.original_code = ERROR_MARK;
6149 ret.original_type = NULL;
6150 return ret;
6153 location_t exp2_loc = c_parser_peek_token (parser)->location;
6154 exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6155 exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6157 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6158 ret.value = build_conditional_expr (colon_loc, cond.value,
6159 cond.original_code == C_MAYBE_CONST_EXPR,
6160 exp1.value, exp1.original_type,
6161 exp2.value, exp2.original_type);
6162 ret.original_code = ERROR_MARK;
6163 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6164 ret.original_type = NULL;
6165 else
6167 tree t1, t2;
6169 /* If both sides are enum type, the default conversion will have
6170 made the type of the result be an integer type. We want to
6171 remember the enum types we started with. */
6172 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6173 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6174 ret.original_type = ((t1 != error_mark_node
6175 && t2 != error_mark_node
6176 && (TYPE_MAIN_VARIANT (t1)
6177 == TYPE_MAIN_VARIANT (t2)))
6178 ? t1
6179 : NULL);
6181 return ret;
6184 /* Parse a binary expression; that is, a logical-OR-expression (C90
6185 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6186 an Objective-C message expression which is the primary-expression
6187 starting the expression as an initializer.
6189 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6190 when it should be the unfolded lhs. In a valid OpenMP source,
6191 one of the operands of the toplevel binary expression must be equal
6192 to it. In that case, just return a build2 created binary operation
6193 rather than result of parser_build_binary_op.
6195 multiplicative-expression:
6196 cast-expression
6197 multiplicative-expression * cast-expression
6198 multiplicative-expression / cast-expression
6199 multiplicative-expression % cast-expression
6201 additive-expression:
6202 multiplicative-expression
6203 additive-expression + multiplicative-expression
6204 additive-expression - multiplicative-expression
6206 shift-expression:
6207 additive-expression
6208 shift-expression << additive-expression
6209 shift-expression >> additive-expression
6211 relational-expression:
6212 shift-expression
6213 relational-expression < shift-expression
6214 relational-expression > shift-expression
6215 relational-expression <= shift-expression
6216 relational-expression >= shift-expression
6218 equality-expression:
6219 relational-expression
6220 equality-expression == relational-expression
6221 equality-expression != relational-expression
6223 AND-expression:
6224 equality-expression
6225 AND-expression & equality-expression
6227 exclusive-OR-expression:
6228 AND-expression
6229 exclusive-OR-expression ^ AND-expression
6231 inclusive-OR-expression:
6232 exclusive-OR-expression
6233 inclusive-OR-expression | exclusive-OR-expression
6235 logical-AND-expression:
6236 inclusive-OR-expression
6237 logical-AND-expression && inclusive-OR-expression
6239 logical-OR-expression:
6240 logical-AND-expression
6241 logical-OR-expression || logical-AND-expression
6244 static struct c_expr
6245 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6246 tree omp_atomic_lhs)
6248 /* A binary expression is parsed using operator-precedence parsing,
6249 with the operands being cast expressions. All the binary
6250 operators are left-associative. Thus a binary expression is of
6251 form:
6253 E0 op1 E1 op2 E2 ...
6255 which we represent on a stack. On the stack, the precedence
6256 levels are strictly increasing. When a new operator is
6257 encountered of higher precedence than that at the top of the
6258 stack, it is pushed; its LHS is the top expression, and its RHS
6259 is everything parsed until it is popped. When a new operator is
6260 encountered with precedence less than or equal to that at the top
6261 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6262 by the result of the operation until the operator at the top of
6263 the stack has lower precedence than the new operator or there is
6264 only one element on the stack; then the top expression is the LHS
6265 of the new operator. In the case of logical AND and OR
6266 expressions, we also need to adjust c_inhibit_evaluation_warnings
6267 as appropriate when the operators are pushed and popped. */
6269 struct {
6270 /* The expression at this stack level. */
6271 struct c_expr expr;
6272 /* The precedence of the operator on its left, PREC_NONE at the
6273 bottom of the stack. */
6274 enum c_parser_prec prec;
6275 /* The operation on its left. */
6276 enum tree_code op;
6277 /* The source location of this operation. */
6278 location_t loc;
6279 } stack[NUM_PRECS];
6280 int sp;
6281 /* Location of the binary operator. */
6282 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
6283 #define POP \
6284 do { \
6285 switch (stack[sp].op) \
6287 case TRUTH_ANDIF_EXPR: \
6288 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6289 == truthvalue_false_node); \
6290 break; \
6291 case TRUTH_ORIF_EXPR: \
6292 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6293 == truthvalue_true_node); \
6294 break; \
6295 default: \
6296 break; \
6298 stack[sp - 1].expr \
6299 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6300 stack[sp - 1].expr, true, true); \
6301 stack[sp].expr \
6302 = convert_lvalue_to_rvalue (stack[sp].loc, \
6303 stack[sp].expr, true, true); \
6304 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6305 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6306 && ((1 << stack[sp].prec) \
6307 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6308 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6309 && stack[sp].op != TRUNC_MOD_EXPR \
6310 && stack[0].expr.value != error_mark_node \
6311 && stack[1].expr.value != error_mark_node \
6312 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6313 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6314 stack[0].expr.value \
6315 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6316 stack[0].expr.value, stack[1].expr.value); \
6317 else \
6318 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6319 stack[sp].op, \
6320 stack[sp - 1].expr, \
6321 stack[sp].expr); \
6322 sp--; \
6323 } while (0)
6324 gcc_assert (!after || c_dialect_objc ());
6325 stack[0].loc = c_parser_peek_token (parser)->location;
6326 stack[0].expr = c_parser_cast_expression (parser, after);
6327 stack[0].prec = PREC_NONE;
6328 sp = 0;
6329 while (true)
6331 enum c_parser_prec oprec;
6332 enum tree_code ocode;
6333 if (parser->error)
6334 goto out;
6335 switch (c_parser_peek_token (parser)->type)
6337 case CPP_MULT:
6338 oprec = PREC_MULT;
6339 ocode = MULT_EXPR;
6340 break;
6341 case CPP_DIV:
6342 oprec = PREC_MULT;
6343 ocode = TRUNC_DIV_EXPR;
6344 break;
6345 case CPP_MOD:
6346 oprec = PREC_MULT;
6347 ocode = TRUNC_MOD_EXPR;
6348 break;
6349 case CPP_PLUS:
6350 oprec = PREC_ADD;
6351 ocode = PLUS_EXPR;
6352 break;
6353 case CPP_MINUS:
6354 oprec = PREC_ADD;
6355 ocode = MINUS_EXPR;
6356 break;
6357 case CPP_LSHIFT:
6358 oprec = PREC_SHIFT;
6359 ocode = LSHIFT_EXPR;
6360 break;
6361 case CPP_RSHIFT:
6362 oprec = PREC_SHIFT;
6363 ocode = RSHIFT_EXPR;
6364 break;
6365 case CPP_LESS:
6366 oprec = PREC_REL;
6367 ocode = LT_EXPR;
6368 break;
6369 case CPP_GREATER:
6370 oprec = PREC_REL;
6371 ocode = GT_EXPR;
6372 break;
6373 case CPP_LESS_EQ:
6374 oprec = PREC_REL;
6375 ocode = LE_EXPR;
6376 break;
6377 case CPP_GREATER_EQ:
6378 oprec = PREC_REL;
6379 ocode = GE_EXPR;
6380 break;
6381 case CPP_EQ_EQ:
6382 oprec = PREC_EQ;
6383 ocode = EQ_EXPR;
6384 break;
6385 case CPP_NOT_EQ:
6386 oprec = PREC_EQ;
6387 ocode = NE_EXPR;
6388 break;
6389 case CPP_AND:
6390 oprec = PREC_BITAND;
6391 ocode = BIT_AND_EXPR;
6392 break;
6393 case CPP_XOR:
6394 oprec = PREC_BITXOR;
6395 ocode = BIT_XOR_EXPR;
6396 break;
6397 case CPP_OR:
6398 oprec = PREC_BITOR;
6399 ocode = BIT_IOR_EXPR;
6400 break;
6401 case CPP_AND_AND:
6402 oprec = PREC_LOGAND;
6403 ocode = TRUTH_ANDIF_EXPR;
6404 break;
6405 case CPP_OR_OR:
6406 oprec = PREC_LOGOR;
6407 ocode = TRUTH_ORIF_EXPR;
6408 break;
6409 default:
6410 /* Not a binary operator, so end of the binary
6411 expression. */
6412 goto out;
6414 binary_loc = c_parser_peek_token (parser)->location;
6415 while (oprec <= stack[sp].prec)
6416 POP;
6417 c_parser_consume_token (parser);
6418 switch (ocode)
6420 case TRUTH_ANDIF_EXPR:
6421 stack[sp].expr
6422 = convert_lvalue_to_rvalue (stack[sp].loc,
6423 stack[sp].expr, true, true);
6424 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6425 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6426 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6427 == truthvalue_false_node);
6428 break;
6429 case TRUTH_ORIF_EXPR:
6430 stack[sp].expr
6431 = convert_lvalue_to_rvalue (stack[sp].loc,
6432 stack[sp].expr, true, true);
6433 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6434 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6435 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6436 == truthvalue_true_node);
6437 break;
6438 default:
6439 break;
6441 sp++;
6442 stack[sp].loc = binary_loc;
6443 stack[sp].expr = c_parser_cast_expression (parser, NULL);
6444 stack[sp].prec = oprec;
6445 stack[sp].op = ocode;
6446 stack[sp].loc = binary_loc;
6448 out:
6449 while (sp > 0)
6450 POP;
6451 return stack[0].expr;
6452 #undef POP
6455 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6456 NULL then it is an Objective-C message expression which is the
6457 primary-expression starting the expression as an initializer.
6459 cast-expression:
6460 unary-expression
6461 ( type-name ) unary-expression
6464 static struct c_expr
6465 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
6467 location_t cast_loc = c_parser_peek_token (parser)->location;
6468 gcc_assert (!after || c_dialect_objc ());
6469 if (after)
6470 return c_parser_postfix_expression_after_primary (parser,
6471 cast_loc, *after);
6472 /* If the expression begins with a parenthesized type name, it may
6473 be either a cast or a compound literal; we need to see whether
6474 the next character is '{' to tell the difference. If not, it is
6475 an unary expression. Full detection of unknown typenames here
6476 would require a 3-token lookahead. */
6477 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6478 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6480 struct c_type_name *type_name;
6481 struct c_expr ret;
6482 struct c_expr expr;
6483 c_parser_consume_token (parser);
6484 type_name = c_parser_type_name (parser);
6485 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6486 if (type_name == NULL)
6488 ret.value = error_mark_node;
6489 ret.original_code = ERROR_MARK;
6490 ret.original_type = NULL;
6491 return ret;
6494 /* Save casted types in the function's used types hash table. */
6495 used_types_insert (type_name->specs->type);
6497 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6498 return c_parser_postfix_expression_after_paren_type (parser, type_name,
6499 cast_loc);
6501 location_t expr_loc = c_parser_peek_token (parser)->location;
6502 expr = c_parser_cast_expression (parser, NULL);
6503 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
6505 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
6506 ret.original_code = ERROR_MARK;
6507 ret.original_type = NULL;
6508 return ret;
6510 else
6511 return c_parser_unary_expression (parser);
6514 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6516 unary-expression:
6517 postfix-expression
6518 ++ unary-expression
6519 -- unary-expression
6520 unary-operator cast-expression
6521 sizeof unary-expression
6522 sizeof ( type-name )
6524 unary-operator: one of
6525 & * + - ~ !
6527 GNU extensions:
6529 unary-expression:
6530 __alignof__ unary-expression
6531 __alignof__ ( type-name )
6532 && identifier
6534 (C11 permits _Alignof with type names only.)
6536 unary-operator: one of
6537 __extension__ __real__ __imag__
6539 Transactional Memory:
6541 unary-expression:
6542 transaction-expression
6544 In addition, the GNU syntax treats ++ and -- as unary operators, so
6545 they may be applied to cast expressions with errors for non-lvalues
6546 given later. */
6548 static struct c_expr
6549 c_parser_unary_expression (c_parser *parser)
6551 int ext;
6552 struct c_expr ret, op;
6553 location_t op_loc = c_parser_peek_token (parser)->location;
6554 location_t exp_loc;
6555 ret.original_code = ERROR_MARK;
6556 ret.original_type = NULL;
6557 switch (c_parser_peek_token (parser)->type)
6559 case CPP_PLUS_PLUS:
6560 c_parser_consume_token (parser);
6561 exp_loc = c_parser_peek_token (parser)->location;
6562 op = c_parser_cast_expression (parser, NULL);
6564 /* If there is array notations in op, we expand them. */
6565 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6566 return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op);
6567 else
6569 op = default_function_array_read_conversion (exp_loc, op);
6570 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
6572 case CPP_MINUS_MINUS:
6573 c_parser_consume_token (parser);
6574 exp_loc = c_parser_peek_token (parser)->location;
6575 op = c_parser_cast_expression (parser, NULL);
6577 /* If there is array notations in op, we expand them. */
6578 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6579 return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op);
6580 else
6582 op = default_function_array_read_conversion (exp_loc, op);
6583 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
6585 case CPP_AND:
6586 c_parser_consume_token (parser);
6587 op = c_parser_cast_expression (parser, NULL);
6588 mark_exp_read (op.value);
6589 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
6590 case CPP_MULT:
6591 c_parser_consume_token (parser);
6592 exp_loc = c_parser_peek_token (parser)->location;
6593 op = c_parser_cast_expression (parser, NULL);
6594 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6595 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
6596 return ret;
6597 case CPP_PLUS:
6598 if (!c_dialect_objc () && !in_system_header_at (input_location))
6599 warning_at (op_loc,
6600 OPT_Wtraditional,
6601 "traditional C rejects the unary plus operator");
6602 c_parser_consume_token (parser);
6603 exp_loc = c_parser_peek_token (parser)->location;
6604 op = c_parser_cast_expression (parser, NULL);
6605 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6606 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
6607 case CPP_MINUS:
6608 c_parser_consume_token (parser);
6609 exp_loc = c_parser_peek_token (parser)->location;
6610 op = c_parser_cast_expression (parser, NULL);
6611 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6612 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
6613 case CPP_COMPL:
6614 c_parser_consume_token (parser);
6615 exp_loc = c_parser_peek_token (parser)->location;
6616 op = c_parser_cast_expression (parser, NULL);
6617 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6618 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
6619 case CPP_NOT:
6620 c_parser_consume_token (parser);
6621 exp_loc = c_parser_peek_token (parser)->location;
6622 op = c_parser_cast_expression (parser, NULL);
6623 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6624 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
6625 case CPP_AND_AND:
6626 /* Refer to the address of a label as a pointer. */
6627 c_parser_consume_token (parser);
6628 if (c_parser_next_token_is (parser, CPP_NAME))
6630 ret.value = finish_label_address_expr
6631 (c_parser_peek_token (parser)->value, op_loc);
6632 c_parser_consume_token (parser);
6634 else
6636 c_parser_error (parser, "expected identifier");
6637 ret.value = error_mark_node;
6639 return ret;
6640 case CPP_KEYWORD:
6641 switch (c_parser_peek_token (parser)->keyword)
6643 case RID_SIZEOF:
6644 return c_parser_sizeof_expression (parser);
6645 case RID_UPC_BLOCKSIZEOF:
6646 case RID_UPC_ELEMSIZEOF:
6647 case RID_UPC_LOCALSIZEOF:
6648 gcc_assert (flag_upc);
6649 return c_parser_sizeof_expression (parser);
6650 case RID_ALIGNOF:
6651 return c_parser_alignof_expression (parser);
6652 case RID_EXTENSION:
6653 c_parser_consume_token (parser);
6654 ext = disable_extension_diagnostics ();
6655 ret = c_parser_cast_expression (parser, NULL);
6656 restore_extension_diagnostics (ext);
6657 return ret;
6658 case RID_REALPART:
6659 c_parser_consume_token (parser);
6660 exp_loc = c_parser_peek_token (parser)->location;
6661 op = c_parser_cast_expression (parser, NULL);
6662 op = default_function_array_conversion (exp_loc, op);
6663 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
6664 case RID_IMAGPART:
6665 c_parser_consume_token (parser);
6666 exp_loc = c_parser_peek_token (parser)->location;
6667 op = c_parser_cast_expression (parser, NULL);
6668 op = default_function_array_conversion (exp_loc, op);
6669 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
6670 case RID_TRANSACTION_ATOMIC:
6671 case RID_TRANSACTION_RELAXED:
6672 return c_parser_transaction_expression (parser,
6673 c_parser_peek_token (parser)->keyword);
6674 default:
6675 return c_parser_postfix_expression (parser);
6677 default:
6678 return c_parser_postfix_expression (parser);
6682 /* Return the result of upc_blocksizeof applied to EXPR. */
6684 static
6685 struct c_expr
6686 upc_blocksizeof_expr (location_t loc, struct c_expr expr)
6688 struct c_expr ret;
6689 ret.original_code = ERROR_MARK;
6690 ret.original_type = NULL_TREE;
6691 if (expr.value == error_mark_node)
6693 ret.value = error_mark_node;
6694 pop_maybe_used (false);
6696 else
6698 ret.value = upc_blocksizeof (loc, TREE_TYPE (expr.value));
6699 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr.value)));
6701 return ret;
6704 /* Return the result of upc_blocksizeof applied to T, a structure
6705 for the type name passed to sizeof (rather than the type itself). */
6707 static
6708 struct c_expr
6709 upc_blocksizeof_type (location_t loc, struct c_type_name *t)
6711 tree type;
6712 struct c_expr ret;
6713 ret.original_code = ERROR_MARK;
6714 ret.original_type = NULL_TREE;
6715 type = groktypename (t, NULL, NULL);
6716 if (type == error_mark_node)
6718 ret.value = error_mark_node;
6719 pop_maybe_used (false);
6721 else
6723 ret.value = upc_blocksizeof (loc, type);
6724 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type));
6726 return ret;
6729 /* Return the result of upc_elemsizeof applied to EXPR. */
6731 static
6732 struct c_expr
6733 upc_elemsizeof_expr (location_t loc, struct c_expr expr)
6735 struct c_expr ret;
6736 ret.original_code = ERROR_MARK;
6737 ret.original_type = NULL_TREE;
6738 if (expr.value == error_mark_node)
6740 ret.value = error_mark_node;
6741 pop_maybe_used (false);
6743 else
6745 ret.value = upc_elemsizeof (loc, TREE_TYPE (expr.value));
6746 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr.value)));
6748 return ret;
6751 /* Return the result of upc_elemsizeof applied to T, a structure
6752 for the type name passed to sizeof (rather than the type itself). */
6754 static
6755 struct c_expr
6756 upc_elemsizeof_type (location_t loc, struct c_type_name *t)
6758 tree type;
6759 struct c_expr ret;
6760 ret.original_code = ERROR_MARK;
6761 ret.original_type = NULL_TREE;
6762 type = groktypename (t, NULL, NULL);
6763 if (type == error_mark_node)
6765 ret.value = error_mark_node;
6766 pop_maybe_used (false);
6768 else
6770 ret.value = upc_elemsizeof (loc, type);
6771 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type));
6773 return ret;
6776 /* Return the result of upc_localsizeof applied to EXPR. */
6778 static
6779 struct c_expr
6780 upc_localsizeof_expr (location_t loc, struct c_expr expr)
6782 struct c_expr ret;
6783 ret.original_code = ERROR_MARK;
6784 ret.original_type = NULL_TREE;
6785 if (expr.value == error_mark_node)
6787 ret.value = error_mark_node;
6788 pop_maybe_used (false);
6790 else
6792 ret.value = upc_localsizeof (loc, TREE_TYPE (expr.value));
6793 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr.value)));
6795 return ret;
6798 /* Return the result of upc_localsizeof applied to T, a structure
6799 for the type name passed to sizeof (rather than the type itself). */
6801 static
6802 struct c_expr
6803 upc_localsizeof_type (location_t loc, struct c_type_name *t)
6805 tree type;
6806 struct c_expr ret;
6807 ret.original_code = ERROR_MARK;
6808 ret.original_type = NULL_TREE;
6809 type = groktypename (t, NULL, NULL);
6810 if (type == error_mark_node)
6812 ret.value = error_mark_node;
6813 pop_maybe_used (false);
6815 else
6817 ret.value = upc_localsizeof (loc, type);
6818 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type));
6820 return ret;
6823 /* Parse a sizeof expression. */
6825 static struct c_expr
6826 c_parser_sizeof_expression (c_parser *parser)
6828 struct c_expr expr;
6829 location_t expr_loc;
6830 enum rid keyword = c_parser_peek_token (parser)->keyword;
6831 c_parser_consume_token (parser);
6832 c_inhibit_evaluation_warnings++;
6833 in_sizeof++;
6834 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6835 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6837 /* Either sizeof ( type-name ) or sizeof unary-expression
6838 starting with a compound literal. */
6839 struct c_type_name *type_name;
6840 c_parser_consume_token (parser);
6841 expr_loc = c_parser_peek_token (parser)->location;
6842 type_name = c_parser_type_name (parser);
6843 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6844 if (type_name == NULL)
6846 struct c_expr ret;
6847 c_inhibit_evaluation_warnings--;
6848 in_sizeof--;
6849 ret.value = error_mark_node;
6850 ret.original_code = ERROR_MARK;
6851 ret.original_type = NULL;
6852 return ret;
6854 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6856 expr = c_parser_postfix_expression_after_paren_type (parser,
6857 type_name,
6858 expr_loc);
6859 goto sizeof_expr;
6861 /* sizeof ( type-name ). */
6862 c_inhibit_evaluation_warnings--;
6863 in_sizeof--;
6864 /* Handle upc_*_sizeof (type) operations. */
6865 switch (keyword)
6867 case RID_UPC_BLOCKSIZEOF:
6868 return upc_blocksizeof_type (expr_loc, type_name);
6869 case RID_UPC_ELEMSIZEOF:
6870 return upc_elemsizeof_type (expr_loc, type_name);
6871 case RID_UPC_LOCALSIZEOF:
6872 return upc_localsizeof_type (expr_loc, type_name);
6873 default: break;
6875 return c_expr_sizeof_type (expr_loc, type_name);
6877 else
6879 expr_loc = c_parser_peek_token (parser)->location;
6880 expr = c_parser_unary_expression (parser);
6881 sizeof_expr:
6882 c_inhibit_evaluation_warnings--;
6883 in_sizeof--;
6884 mark_exp_read (expr.value);
6885 if (TREE_CODE (expr.value) == COMPONENT_REF
6886 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
6887 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
6888 /* Handle upc_*_sizeof (expr) operations. */
6889 switch (keyword)
6891 case RID_UPC_BLOCKSIZEOF:
6892 return upc_blocksizeof_expr (expr_loc, expr);
6893 case RID_UPC_ELEMSIZEOF:
6894 return upc_elemsizeof_expr (expr_loc, expr);
6895 case RID_UPC_LOCALSIZEOF:
6896 return upc_localsizeof_expr (expr_loc, expr);
6897 case RID_SIZEOF:
6898 return c_expr_sizeof_expr (expr_loc, expr);
6899 default: break;
6901 return c_expr_sizeof_expr (expr_loc, expr);
6905 /* Parse an alignof expression. */
6907 static struct c_expr
6908 c_parser_alignof_expression (c_parser *parser)
6910 struct c_expr expr;
6911 location_t loc = c_parser_peek_token (parser)->location;
6912 tree alignof_spelling = c_parser_peek_token (parser)->value;
6913 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
6914 bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
6915 "_Alignof") == 0;
6916 /* A diagnostic is not required for the use of this identifier in
6917 the implementation namespace; only diagnose it for the C11
6918 spelling because of existing code using the other spellings. */
6919 if (is_c11_alignof)
6921 if (flag_isoc99)
6922 pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
6923 alignof_spelling);
6924 else
6925 pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
6926 alignof_spelling);
6928 c_parser_consume_token (parser);
6929 c_inhibit_evaluation_warnings++;
6930 in_alignof++;
6931 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6932 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6934 /* Either __alignof__ ( type-name ) or __alignof__
6935 unary-expression starting with a compound literal. */
6936 location_t loc;
6937 struct c_type_name *type_name;
6938 struct c_expr ret;
6939 c_parser_consume_token (parser);
6940 loc = c_parser_peek_token (parser)->location;
6941 type_name = c_parser_type_name (parser);
6942 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6943 if (type_name == NULL)
6945 struct c_expr ret;
6946 c_inhibit_evaluation_warnings--;
6947 in_alignof--;
6948 ret.value = error_mark_node;
6949 ret.original_code = ERROR_MARK;
6950 ret.original_type = NULL;
6951 return ret;
6953 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6955 expr = c_parser_postfix_expression_after_paren_type (parser,
6956 type_name,
6957 loc);
6958 goto alignof_expr;
6960 /* alignof ( type-name ). */
6961 c_inhibit_evaluation_warnings--;
6962 in_alignof--;
6963 ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
6964 NULL, NULL),
6965 false, is_c11_alignof, 1);
6966 ret.original_code = ERROR_MARK;
6967 ret.original_type = NULL;
6968 return ret;
6970 else
6972 struct c_expr ret;
6973 expr = c_parser_unary_expression (parser);
6974 alignof_expr:
6975 mark_exp_read (expr.value);
6976 c_inhibit_evaluation_warnings--;
6977 in_alignof--;
6978 pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
6979 alignof_spelling);
6980 ret.value = c_alignof_expr (loc, expr.value);
6981 ret.original_code = ERROR_MARK;
6982 ret.original_type = NULL;
6983 return ret;
6987 /* Helper function to read arguments of builtins which are interfaces
6988 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6989 others. The name of the builtin is passed using BNAME parameter.
6990 Function returns true if there were no errors while parsing and
6991 stores the arguments in CEXPR_LIST. */
6992 static bool
6993 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6994 vec<c_expr_t, va_gc> **ret_cexpr_list,
6995 bool choose_expr_p)
6997 location_t loc = c_parser_peek_token (parser)->location;
6998 vec<c_expr_t, va_gc> *cexpr_list;
6999 c_expr_t expr;
7000 bool saved_force_folding_builtin_constant_p;
7002 *ret_cexpr_list = NULL;
7003 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
7005 error_at (loc, "cannot take address of %qs", bname);
7006 return false;
7009 c_parser_consume_token (parser);
7011 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7013 c_parser_consume_token (parser);
7014 return true;
7017 saved_force_folding_builtin_constant_p
7018 = force_folding_builtin_constant_p;
7019 force_folding_builtin_constant_p |= choose_expr_p;
7020 expr = c_parser_expr_no_commas (parser, NULL);
7021 force_folding_builtin_constant_p
7022 = saved_force_folding_builtin_constant_p;
7023 vec_alloc (cexpr_list, 1);
7024 vec_safe_push (cexpr_list, expr);
7025 while (c_parser_next_token_is (parser, CPP_COMMA))
7027 c_parser_consume_token (parser);
7028 expr = c_parser_expr_no_commas (parser, NULL);
7029 vec_safe_push (cexpr_list, expr);
7032 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7033 return false;
7035 *ret_cexpr_list = cexpr_list;
7036 return true;
7039 /* This represents a single generic-association. */
7041 struct c_generic_association
7043 /* The location of the starting token of the type. */
7044 location_t type_location;
7045 /* The association's type, or NULL_TREE for 'default'. */
7046 tree type;
7047 /* The association's expression. */
7048 struct c_expr expression;
7051 /* Parse a generic-selection. (C11 6.5.1.1).
7053 generic-selection:
7054 _Generic ( assignment-expression , generic-assoc-list )
7056 generic-assoc-list:
7057 generic-association
7058 generic-assoc-list , generic-association
7060 generic-association:
7061 type-name : assignment-expression
7062 default : assignment-expression
7065 static struct c_expr
7066 c_parser_generic_selection (c_parser *parser)
7068 vec<c_generic_association> associations = vNULL;
7069 struct c_expr selector, error_expr;
7070 tree selector_type;
7071 struct c_generic_association matched_assoc;
7072 bool match_found = false;
7073 location_t generic_loc, selector_loc;
7075 error_expr.original_code = ERROR_MARK;
7076 error_expr.original_type = NULL;
7077 error_expr.value = error_mark_node;
7078 matched_assoc.type_location = UNKNOWN_LOCATION;
7079 matched_assoc.type = NULL_TREE;
7080 matched_assoc.expression = error_expr;
7082 gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
7083 generic_loc = c_parser_peek_token (parser)->location;
7084 c_parser_consume_token (parser);
7085 if (flag_isoc99)
7086 pedwarn_c99 (generic_loc, OPT_Wpedantic,
7087 "ISO C99 does not support %<_Generic%>");
7088 else
7089 pedwarn_c99 (generic_loc, OPT_Wpedantic,
7090 "ISO C90 does not support %<_Generic%>");
7092 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7093 return error_expr;
7095 c_inhibit_evaluation_warnings++;
7096 selector_loc = c_parser_peek_token (parser)->location;
7097 selector = c_parser_expr_no_commas (parser, NULL);
7098 selector = default_function_array_conversion (selector_loc, selector);
7099 c_inhibit_evaluation_warnings--;
7101 if (selector.value == error_mark_node)
7103 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7104 return selector;
7106 selector_type = TREE_TYPE (selector.value);
7107 /* In ISO C terms, rvalues (including the controlling expression of
7108 _Generic) do not have qualified types. */
7109 if (TREE_CODE (selector_type) != ARRAY_TYPE)
7110 selector_type = TYPE_MAIN_VARIANT (selector_type);
7111 /* In ISO C terms, _Noreturn is not part of the type of expressions
7112 such as &abort, but in GCC it is represented internally as a type
7113 qualifier. */
7114 if (FUNCTION_POINTER_TYPE_P (selector_type)
7115 && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
7116 selector_type
7117 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
7119 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7121 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7122 return error_expr;
7125 while (1)
7127 struct c_generic_association assoc, *iter;
7128 unsigned int ix;
7129 c_token *token = c_parser_peek_token (parser);
7131 assoc.type_location = token->location;
7132 if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
7134 c_parser_consume_token (parser);
7135 assoc.type = NULL_TREE;
7137 else
7139 struct c_type_name *type_name;
7141 type_name = c_parser_type_name (parser);
7142 if (type_name == NULL)
7144 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7145 goto error_exit;
7147 assoc.type = groktypename (type_name, NULL, NULL);
7148 if (assoc.type == error_mark_node)
7150 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7151 goto error_exit;
7154 if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
7155 error_at (assoc.type_location,
7156 "%<_Generic%> association has function type");
7157 else if (!COMPLETE_TYPE_P (assoc.type))
7158 error_at (assoc.type_location,
7159 "%<_Generic%> association has incomplete type");
7161 if (variably_modified_type_p (assoc.type, NULL_TREE))
7162 error_at (assoc.type_location,
7163 "%<_Generic%> association has "
7164 "variable length type");
7167 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7169 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7170 goto error_exit;
7173 assoc.expression = c_parser_expr_no_commas (parser, NULL);
7174 if (assoc.expression.value == error_mark_node)
7176 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7177 goto error_exit;
7180 for (ix = 0; associations.iterate (ix, &iter); ++ix)
7182 if (assoc.type == NULL_TREE)
7184 if (iter->type == NULL_TREE)
7186 error_at (assoc.type_location,
7187 "duplicate %<default%> case in %<_Generic%>");
7188 inform (iter->type_location, "original %<default%> is here");
7191 else if (iter->type != NULL_TREE)
7193 if (comptypes (assoc.type, iter->type))
7195 error_at (assoc.type_location,
7196 "%<_Generic%> specifies two compatible types");
7197 inform (iter->type_location, "compatible type is here");
7202 if (assoc.type == NULL_TREE)
7204 if (!match_found)
7206 matched_assoc = assoc;
7207 match_found = true;
7210 else if (comptypes (assoc.type, selector_type))
7212 if (!match_found || matched_assoc.type == NULL_TREE)
7214 matched_assoc = assoc;
7215 match_found = true;
7217 else
7219 error_at (assoc.type_location,
7220 "%<_Generic> selector matches multiple associations");
7221 inform (matched_assoc.type_location,
7222 "other match is here");
7226 associations.safe_push (assoc);
7228 if (c_parser_peek_token (parser)->type != CPP_COMMA)
7229 break;
7230 c_parser_consume_token (parser);
7233 associations.release ();
7235 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7237 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7238 return error_expr;
7241 if (!match_found)
7243 error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7244 "compatible with any association",
7245 selector_type);
7246 return error_expr;
7249 return matched_assoc.expression;
7251 error_exit:
7252 associations.release ();
7253 return error_expr;
7256 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7258 postfix-expression:
7259 primary-expression
7260 postfix-expression [ expression ]
7261 postfix-expression ( argument-expression-list[opt] )
7262 postfix-expression . identifier
7263 postfix-expression -> identifier
7264 postfix-expression ++
7265 postfix-expression --
7266 ( type-name ) { initializer-list }
7267 ( type-name ) { initializer-list , }
7269 argument-expression-list:
7270 argument-expression
7271 argument-expression-list , argument-expression
7273 primary-expression:
7274 identifier
7275 constant
7276 string-literal
7277 ( expression )
7278 generic-selection
7280 GNU extensions:
7282 primary-expression:
7283 __func__
7284 (treated as a keyword in GNU C)
7285 __FUNCTION__
7286 __PRETTY_FUNCTION__
7287 ( compound-statement )
7288 __builtin_va_arg ( assignment-expression , type-name )
7289 __builtin_offsetof ( type-name , offsetof-member-designator )
7290 __builtin_choose_expr ( assignment-expression ,
7291 assignment-expression ,
7292 assignment-expression )
7293 __builtin_types_compatible_p ( type-name , type-name )
7294 __builtin_complex ( assignment-expression , assignment-expression )
7295 __builtin_shuffle ( assignment-expression , assignment-expression )
7296 __builtin_shuffle ( assignment-expression ,
7297 assignment-expression ,
7298 assignment-expression, )
7300 offsetof-member-designator:
7301 identifier
7302 offsetof-member-designator . identifier
7303 offsetof-member-designator [ expression ]
7305 Objective-C:
7307 primary-expression:
7308 [ objc-receiver objc-message-args ]
7309 @selector ( objc-selector-arg )
7310 @protocol ( identifier )
7311 @encode ( type-name )
7312 objc-string-literal
7313 Classname . identifier
7316 static struct c_expr
7317 c_parser_postfix_expression (c_parser *parser)
7319 struct c_expr expr, e1;
7320 struct c_type_name *t1, *t2;
7321 location_t loc = c_parser_peek_token (parser)->location;;
7322 expr.original_code = ERROR_MARK;
7323 expr.original_type = NULL;
7324 switch (c_parser_peek_token (parser)->type)
7326 case CPP_NUMBER:
7327 expr.value = c_parser_peek_token (parser)->value;
7328 loc = c_parser_peek_token (parser)->location;
7329 c_parser_consume_token (parser);
7330 if (TREE_CODE (expr.value) == FIXED_CST
7331 && !targetm.fixed_point_supported_p ())
7333 error_at (loc, "fixed-point types not supported for this target");
7334 expr.value = error_mark_node;
7336 break;
7337 case CPP_CHAR:
7338 case CPP_CHAR16:
7339 case CPP_CHAR32:
7340 case CPP_WCHAR:
7341 expr.value = c_parser_peek_token (parser)->value;
7342 c_parser_consume_token (parser);
7343 break;
7344 case CPP_STRING:
7345 case CPP_STRING16:
7346 case CPP_STRING32:
7347 case CPP_WSTRING:
7348 case CPP_UTF8STRING:
7349 expr.value = c_parser_peek_token (parser)->value;
7350 expr.original_code = STRING_CST;
7351 c_parser_consume_token (parser);
7352 break;
7353 case CPP_OBJC_STRING:
7354 gcc_assert (c_dialect_objc ());
7355 expr.value
7356 = objc_build_string_object (c_parser_peek_token (parser)->value);
7357 c_parser_consume_token (parser);
7358 break;
7359 case CPP_NAME:
7360 switch (c_parser_peek_token (parser)->id_kind)
7362 case C_ID_ID:
7364 tree id = c_parser_peek_token (parser)->value;
7365 c_parser_consume_token (parser);
7366 expr.value = build_external_ref (loc, id,
7367 (c_parser_peek_token (parser)->type
7368 == CPP_OPEN_PAREN),
7369 &expr.original_type);
7370 break;
7372 case C_ID_CLASSNAME:
7374 /* Here we parse the Objective-C 2.0 Class.name dot
7375 syntax. */
7376 tree class_name = c_parser_peek_token (parser)->value;
7377 tree component;
7378 c_parser_consume_token (parser);
7379 gcc_assert (c_dialect_objc ());
7380 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7382 expr.value = error_mark_node;
7383 break;
7385 if (c_parser_next_token_is_not (parser, CPP_NAME))
7387 c_parser_error (parser, "expected identifier");
7388 expr.value = error_mark_node;
7389 break;
7391 component = c_parser_peek_token (parser)->value;
7392 c_parser_consume_token (parser);
7393 expr.value = objc_build_class_component_ref (class_name,
7394 component);
7395 break;
7397 default:
7398 c_parser_error (parser, "expected expression");
7399 expr.value = error_mark_node;
7400 break;
7402 break;
7403 case CPP_OPEN_PAREN:
7404 /* A parenthesized expression, statement expression or compound
7405 literal. */
7406 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7408 /* A statement expression. */
7409 tree stmt;
7410 location_t brace_loc;
7411 c_parser_consume_token (parser);
7412 brace_loc = c_parser_peek_token (parser)->location;
7413 c_parser_consume_token (parser);
7414 if (!building_stmt_list_p ())
7416 error_at (loc, "braced-group within expression allowed "
7417 "only inside a function");
7418 parser->error = true;
7419 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7420 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7421 expr.value = error_mark_node;
7422 break;
7424 stmt = c_begin_stmt_expr ();
7425 c_parser_compound_statement_nostart (parser);
7426 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7427 "expected %<)%>");
7428 pedwarn (loc, OPT_Wpedantic,
7429 "ISO C forbids braced-groups within expressions");
7430 expr.value = c_finish_stmt_expr (brace_loc, stmt);
7431 mark_exp_read (expr.value);
7433 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7435 /* A compound literal. ??? Can we actually get here rather
7436 than going directly to
7437 c_parser_postfix_expression_after_paren_type from
7438 elsewhere? */
7439 location_t loc;
7440 struct c_type_name *type_name;
7441 c_parser_consume_token (parser);
7442 loc = c_parser_peek_token (parser)->location;
7443 type_name = c_parser_type_name (parser);
7444 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7445 "expected %<)%>");
7446 if (type_name == NULL)
7448 expr.value = error_mark_node;
7450 else
7451 expr = c_parser_postfix_expression_after_paren_type (parser,
7452 type_name,
7453 loc);
7455 else
7457 /* A parenthesized expression. */
7458 c_parser_consume_token (parser);
7459 expr = c_parser_expression (parser);
7460 if (TREE_CODE (expr.value) == MODIFY_EXPR)
7461 TREE_NO_WARNING (expr.value) = 1;
7462 if (expr.original_code != C_MAYBE_CONST_EXPR)
7463 expr.original_code = ERROR_MARK;
7464 /* Don't change EXPR.ORIGINAL_TYPE. */
7465 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7466 "expected %<)%>");
7468 break;
7469 case CPP_KEYWORD:
7470 switch (c_parser_peek_token (parser)->keyword)
7472 case RID_FUNCTION_NAME:
7473 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7474 "%<__FUNCTION__%> predefined identifier");
7475 expr.value = fname_decl (loc,
7476 c_parser_peek_token (parser)->keyword,
7477 c_parser_peek_token (parser)->value);
7478 c_parser_consume_token (parser);
7479 break;
7480 case RID_PRETTY_FUNCTION_NAME:
7481 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7482 "%<__PRETTY_FUNCTION__%> predefined identifier");
7483 expr.value = fname_decl (loc,
7484 c_parser_peek_token (parser)->keyword,
7485 c_parser_peek_token (parser)->value);
7486 c_parser_consume_token (parser);
7487 break;
7488 case RID_C99_FUNCTION_NAME:
7489 pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support "
7490 "%<__func__%> predefined identifier");
7491 expr.value = fname_decl (loc,
7492 c_parser_peek_token (parser)->keyword,
7493 c_parser_peek_token (parser)->value);
7494 c_parser_consume_token (parser);
7495 break;
7496 case RID_VA_ARG:
7497 c_parser_consume_token (parser);
7498 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7500 expr.value = error_mark_node;
7501 break;
7503 e1 = c_parser_expr_no_commas (parser, NULL);
7504 mark_exp_read (e1.value);
7505 e1.value = c_fully_fold (e1.value, false, NULL);
7506 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7508 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7509 expr.value = error_mark_node;
7510 break;
7512 loc = c_parser_peek_token (parser)->location;
7513 t1 = c_parser_type_name (parser);
7514 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7515 "expected %<)%>");
7516 if (t1 == NULL)
7518 expr.value = error_mark_node;
7520 else
7522 tree type_expr = NULL_TREE;
7523 expr.value = c_build_va_arg (loc, e1.value,
7524 groktypename (t1, &type_expr, NULL));
7525 if (type_expr)
7527 expr.value = build2 (C_MAYBE_CONST_EXPR,
7528 TREE_TYPE (expr.value), type_expr,
7529 expr.value);
7530 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
7533 break;
7534 case RID_OFFSETOF:
7535 c_parser_consume_token (parser);
7536 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7538 expr.value = error_mark_node;
7539 break;
7541 t1 = c_parser_type_name (parser);
7542 if (t1 == NULL)
7543 parser->error = true;
7544 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7545 gcc_assert (parser->error);
7546 if (parser->error)
7548 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7549 expr.value = error_mark_node;
7550 break;
7554 tree type = groktypename (t1, NULL, NULL);
7555 tree offsetof_ref;
7556 if (type == error_mark_node)
7557 offsetof_ref = error_mark_node;
7558 else
7560 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
7561 SET_EXPR_LOCATION (offsetof_ref, loc);
7563 /* Parse the second argument to __builtin_offsetof. We
7564 must have one identifier, and beyond that we want to
7565 accept sub structure and sub array references. */
7566 if (c_parser_next_token_is (parser, CPP_NAME))
7568 offsetof_ref = build_component_ref
7569 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
7570 c_parser_consume_token (parser);
7571 while (c_parser_next_token_is (parser, CPP_DOT)
7572 || c_parser_next_token_is (parser,
7573 CPP_OPEN_SQUARE)
7574 || c_parser_next_token_is (parser,
7575 CPP_DEREF))
7577 if (c_parser_next_token_is (parser, CPP_DEREF))
7579 loc = c_parser_peek_token (parser)->location;
7580 offsetof_ref = build_array_ref (loc,
7581 offsetof_ref,
7582 integer_zero_node);
7583 goto do_dot;
7585 else if (c_parser_next_token_is (parser, CPP_DOT))
7587 do_dot:
7588 c_parser_consume_token (parser);
7589 if (c_parser_next_token_is_not (parser,
7590 CPP_NAME))
7592 c_parser_error (parser, "expected identifier");
7593 break;
7595 offsetof_ref = build_component_ref
7596 (loc, offsetof_ref,
7597 c_parser_peek_token (parser)->value);
7598 c_parser_consume_token (parser);
7600 else
7602 struct c_expr ce;
7603 tree idx;
7604 loc = c_parser_peek_token (parser)->location;
7605 c_parser_consume_token (parser);
7606 ce = c_parser_expression (parser);
7607 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
7608 idx = ce.value;
7609 idx = c_fully_fold (idx, false, NULL);
7610 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7611 "expected %<]%>");
7612 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
7616 else
7617 c_parser_error (parser, "expected identifier");
7618 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7619 "expected %<)%>");
7620 expr.value = fold_offsetof (offsetof_ref);
7622 break;
7623 case RID_CHOOSE_EXPR:
7625 vec<c_expr_t, va_gc> *cexpr_list;
7626 c_expr_t *e1_p, *e2_p, *e3_p;
7627 tree c;
7629 c_parser_consume_token (parser);
7630 if (!c_parser_get_builtin_args (parser,
7631 "__builtin_choose_expr",
7632 &cexpr_list, true))
7634 expr.value = error_mark_node;
7635 break;
7638 if (vec_safe_length (cexpr_list) != 3)
7640 error_at (loc, "wrong number of arguments to "
7641 "%<__builtin_choose_expr%>");
7642 expr.value = error_mark_node;
7643 break;
7646 e1_p = &(*cexpr_list)[0];
7647 e2_p = &(*cexpr_list)[1];
7648 e3_p = &(*cexpr_list)[2];
7650 c = e1_p->value;
7651 mark_exp_read (e2_p->value);
7652 mark_exp_read (e3_p->value);
7653 if (TREE_CODE (c) != INTEGER_CST
7654 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
7655 error_at (loc,
7656 "first argument to %<__builtin_choose_expr%> not"
7657 " a constant");
7658 constant_expression_warning (c);
7659 expr = integer_zerop (c) ? *e3_p : *e2_p;
7660 break;
7662 case RID_TYPES_COMPATIBLE_P:
7663 c_parser_consume_token (parser);
7664 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7666 expr.value = error_mark_node;
7667 break;
7669 t1 = c_parser_type_name (parser);
7670 if (t1 == NULL)
7672 expr.value = error_mark_node;
7673 break;
7675 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7677 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7678 expr.value = error_mark_node;
7679 break;
7681 t2 = c_parser_type_name (parser);
7682 if (t2 == NULL)
7684 expr.value = error_mark_node;
7685 break;
7687 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7688 "expected %<)%>");
7690 tree e1, e2;
7691 e1 = groktypename (t1, NULL, NULL);
7692 e2 = groktypename (t2, NULL, NULL);
7693 if (e1 == error_mark_node || e2 == error_mark_node)
7695 expr.value = error_mark_node;
7696 break;
7699 e1 = TYPE_MAIN_VARIANT (e1);
7700 e2 = TYPE_MAIN_VARIANT (e2);
7702 expr.value
7703 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
7705 break;
7706 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
7708 vec<c_expr_t, va_gc> *cexpr_list;
7709 c_expr_t *e2_p;
7710 tree chain_value;
7712 c_parser_consume_token (parser);
7713 if (!c_parser_get_builtin_args (parser,
7714 "__builtin_call_with_static_chain",
7715 &cexpr_list, false))
7717 expr.value = error_mark_node;
7718 break;
7720 if (vec_safe_length (cexpr_list) != 2)
7722 error_at (loc, "wrong number of arguments to "
7723 "%<__builtin_call_with_static_chain%>");
7724 expr.value = error_mark_node;
7725 break;
7728 expr = (*cexpr_list)[0];
7729 e2_p = &(*cexpr_list)[1];
7730 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7731 chain_value = e2_p->value;
7732 mark_exp_read (chain_value);
7734 if (TREE_CODE (expr.value) != CALL_EXPR)
7735 error_at (loc, "first argument to "
7736 "%<__builtin_call_with_static_chain%> "
7737 "must be a call expression");
7738 else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
7739 error_at (loc, "second argument to "
7740 "%<__builtin_call_with_static_chain%> "
7741 "must be a pointer type");
7742 else
7743 CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
7744 break;
7746 case RID_BUILTIN_COMPLEX:
7748 vec<c_expr_t, va_gc> *cexpr_list;
7749 c_expr_t *e1_p, *e2_p;
7751 c_parser_consume_token (parser);
7752 if (!c_parser_get_builtin_args (parser,
7753 "__builtin_complex",
7754 &cexpr_list, false))
7756 expr.value = error_mark_node;
7757 break;
7760 if (vec_safe_length (cexpr_list) != 2)
7762 error_at (loc, "wrong number of arguments to "
7763 "%<__builtin_complex%>");
7764 expr.value = error_mark_node;
7765 break;
7768 e1_p = &(*cexpr_list)[0];
7769 e2_p = &(*cexpr_list)[1];
7771 *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
7772 if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
7773 e1_p->value = convert (TREE_TYPE (e1_p->value),
7774 TREE_OPERAND (e1_p->value, 0));
7775 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7776 if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
7777 e2_p->value = convert (TREE_TYPE (e2_p->value),
7778 TREE_OPERAND (e2_p->value, 0));
7779 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7780 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7781 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
7782 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
7784 error_at (loc, "%<__builtin_complex%> operand "
7785 "not of real binary floating-point type");
7786 expr.value = error_mark_node;
7787 break;
7789 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
7790 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
7792 error_at (loc,
7793 "%<__builtin_complex%> operands of different types");
7794 expr.value = error_mark_node;
7795 break;
7797 pedwarn_c90 (loc, OPT_Wpedantic,
7798 "ISO C90 does not support complex types");
7799 expr.value = build2 (COMPLEX_EXPR,
7800 build_complex_type
7801 (TYPE_MAIN_VARIANT
7802 (TREE_TYPE (e1_p->value))),
7803 e1_p->value, e2_p->value);
7804 break;
7806 case RID_BUILTIN_SHUFFLE:
7808 vec<c_expr_t, va_gc> *cexpr_list;
7809 unsigned int i;
7810 c_expr_t *p;
7812 c_parser_consume_token (parser);
7813 if (!c_parser_get_builtin_args (parser,
7814 "__builtin_shuffle",
7815 &cexpr_list, false))
7817 expr.value = error_mark_node;
7818 break;
7821 FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
7822 *p = convert_lvalue_to_rvalue (loc, *p, true, true);
7824 if (vec_safe_length (cexpr_list) == 2)
7825 expr.value =
7826 c_build_vec_perm_expr
7827 (loc, (*cexpr_list)[0].value,
7828 NULL_TREE, (*cexpr_list)[1].value);
7830 else if (vec_safe_length (cexpr_list) == 3)
7831 expr.value =
7832 c_build_vec_perm_expr
7833 (loc, (*cexpr_list)[0].value,
7834 (*cexpr_list)[1].value,
7835 (*cexpr_list)[2].value);
7836 else
7838 error_at (loc, "wrong number of arguments to "
7839 "%<__builtin_shuffle%>");
7840 expr.value = error_mark_node;
7842 break;
7844 case RID_AT_SELECTOR:
7845 gcc_assert (c_dialect_objc ());
7846 c_parser_consume_token (parser);
7847 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7849 expr.value = error_mark_node;
7850 break;
7853 tree sel = c_parser_objc_selector_arg (parser);
7854 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7855 "expected %<)%>");
7856 expr.value = objc_build_selector_expr (loc, sel);
7858 break;
7859 case RID_AT_PROTOCOL:
7860 gcc_assert (c_dialect_objc ());
7861 c_parser_consume_token (parser);
7862 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7864 expr.value = error_mark_node;
7865 break;
7867 if (c_parser_next_token_is_not (parser, CPP_NAME))
7869 c_parser_error (parser, "expected identifier");
7870 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7871 expr.value = error_mark_node;
7872 break;
7875 tree id = c_parser_peek_token (parser)->value;
7876 c_parser_consume_token (parser);
7877 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7878 "expected %<)%>");
7879 expr.value = objc_build_protocol_expr (id);
7881 break;
7882 case RID_AT_ENCODE:
7883 /* Extension to support C-structures in the archiver. */
7884 gcc_assert (c_dialect_objc ());
7885 c_parser_consume_token (parser);
7886 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7888 expr.value = error_mark_node;
7889 break;
7891 t1 = c_parser_type_name (parser);
7892 if (t1 == NULL)
7894 expr.value = error_mark_node;
7895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7896 break;
7898 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7899 "expected %<)%>");
7901 tree type = groktypename (t1, NULL, NULL);
7902 expr.value = objc_build_encode_expr (type);
7904 break;
7905 case RID_GENERIC:
7906 expr = c_parser_generic_selection (parser);
7907 break;
7908 case RID_CILK_SPAWN:
7909 c_parser_consume_token (parser);
7910 if (!flag_cilkplus)
7912 error_at (loc, "-fcilkplus must be enabled to use "
7913 "%<_Cilk_spawn%>");
7914 expr = c_parser_postfix_expression (parser);
7915 expr.value = error_mark_node;
7917 else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7919 error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
7920 "are not permitted");
7921 /* Now flush out all the _Cilk_spawns. */
7922 while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7923 c_parser_consume_token (parser);
7924 expr = c_parser_postfix_expression (parser);
7926 else
7928 expr = c_parser_postfix_expression (parser);
7929 expr.value = build_cilk_spawn (loc, expr.value);
7931 break;
7932 default:
7933 c_parser_error (parser, "expected expression");
7934 expr.value = error_mark_node;
7935 break;
7937 break;
7938 case CPP_OPEN_SQUARE:
7939 if (c_dialect_objc ())
7941 tree receiver, args;
7942 c_parser_consume_token (parser);
7943 receiver = c_parser_objc_receiver (parser);
7944 args = c_parser_objc_message_args (parser);
7945 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7946 "expected %<]%>");
7947 expr.value = objc_build_message_expr (receiver, args);
7948 break;
7950 /* Else fall through to report error. */
7951 default:
7952 c_parser_error (parser, "expected expression");
7953 expr.value = error_mark_node;
7954 break;
7956 return c_parser_postfix_expression_after_primary (parser, loc, expr);
7959 /* Parse a postfix expression after a parenthesized type name: the
7960 brace-enclosed initializer of a compound literal, possibly followed
7961 by some postfix operators. This is separate because it is not
7962 possible to tell until after the type name whether a cast
7963 expression has a cast or a compound literal, or whether the operand
7964 of sizeof is a parenthesized type name or starts with a compound
7965 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7966 location of the first token after the parentheses around the type
7967 name. */
7969 static struct c_expr
7970 c_parser_postfix_expression_after_paren_type (c_parser *parser,
7971 struct c_type_name *type_name,
7972 location_t type_loc)
7974 tree type;
7975 struct c_expr init;
7976 bool non_const;
7977 struct c_expr expr;
7978 location_t start_loc;
7979 tree type_expr = NULL_TREE;
7980 bool type_expr_const = true;
7981 check_compound_literal_type (type_loc, type_name);
7982 start_init (NULL_TREE, NULL, 0);
7983 type = groktypename (type_name, &type_expr, &type_expr_const);
7984 start_loc = c_parser_peek_token (parser)->location;
7985 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
7987 error_at (type_loc, "compound literal has variable size");
7988 type = error_mark_node;
7990 init = c_parser_braced_init (parser, type, false);
7991 finish_init ();
7992 maybe_warn_string_init (type_loc, type, init);
7994 if (type != error_mark_node
7995 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
7996 && current_function_decl)
7998 error ("compound literal qualified by address-space qualifier");
7999 type = error_mark_node;
8002 pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
8003 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
8004 ? CONSTRUCTOR_NON_CONST (init.value)
8005 : init.original_code == C_MAYBE_CONST_EXPR);
8006 non_const |= !type_expr_const;
8007 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
8008 expr.original_code = ERROR_MARK;
8009 expr.original_type = NULL;
8010 if (type_expr)
8012 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
8014 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
8015 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
8017 else
8019 gcc_assert (!non_const);
8020 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
8021 type_expr, expr.value);
8024 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
8027 /* Callback function for sizeof_pointer_memaccess_warning to compare
8028 types. */
8030 static bool
8031 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
8033 return comptypes (type1, type2) == 1;
8036 /* Parse a postfix expression after the initial primary or compound
8037 literal; that is, parse a series of postfix operators.
8039 EXPR_LOC is the location of the primary expression. */
8041 static struct c_expr
8042 c_parser_postfix_expression_after_primary (c_parser *parser,
8043 location_t expr_loc,
8044 struct c_expr expr)
8046 struct c_expr orig_expr;
8047 tree ident, idx;
8048 location_t sizeof_arg_loc[3];
8049 tree sizeof_arg[3];
8050 unsigned int literal_zero_mask;
8051 unsigned int i;
8052 vec<tree, va_gc> *exprlist;
8053 vec<tree, va_gc> *origtypes = NULL;
8054 vec<location_t> arg_loc = vNULL;
8056 while (true)
8058 location_t op_loc = c_parser_peek_token (parser)->location;
8059 switch (c_parser_peek_token (parser)->type)
8061 case CPP_OPEN_SQUARE:
8062 /* Array reference. */
8063 c_parser_consume_token (parser);
8064 if (flag_cilkplus
8065 && c_parser_peek_token (parser)->type == CPP_COLON)
8066 /* If we are here, then we have something like this:
8067 Array [ : ]
8069 expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE,
8070 expr.value);
8071 else
8073 idx = c_parser_expression (parser).value;
8074 /* Here we have 3 options:
8075 1. Array [EXPR] -- Normal Array call.
8076 2. Array [EXPR : EXPR] -- Array notation without stride.
8077 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8079 For 1, we just handle it just like a normal array expression.
8080 For 2 and 3 we handle it like we handle array notations. The
8081 idx value we have above becomes the initial/start index.
8083 if (flag_cilkplus
8084 && c_parser_peek_token (parser)->type == CPP_COLON)
8085 expr.value = c_parser_array_notation (expr_loc, parser, idx,
8086 expr.value);
8087 else
8089 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
8090 "expected %<]%>");
8091 expr.value = build_array_ref (op_loc, expr.value, idx);
8094 expr.original_code = ERROR_MARK;
8095 expr.original_type = NULL;
8096 break;
8097 case CPP_OPEN_PAREN:
8098 /* Function call. */
8099 c_parser_consume_token (parser);
8100 for (i = 0; i < 3; i++)
8102 sizeof_arg[i] = NULL_TREE;
8103 sizeof_arg_loc[i] = UNKNOWN_LOCATION;
8105 literal_zero_mask = 0;
8106 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8107 exprlist = NULL;
8108 else
8109 exprlist = c_parser_expr_list (parser, true, false, &origtypes,
8110 sizeof_arg_loc, sizeof_arg,
8111 &arg_loc, &literal_zero_mask);
8112 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8113 "expected %<)%>");
8114 orig_expr = expr;
8115 mark_exp_read (expr.value);
8116 if (warn_sizeof_pointer_memaccess)
8117 sizeof_pointer_memaccess_warning (sizeof_arg_loc,
8118 expr.value, exprlist,
8119 sizeof_arg,
8120 sizeof_ptr_memacc_comptypes);
8121 if (warn_memset_transposed_args
8122 && TREE_CODE (expr.value) == FUNCTION_DECL
8123 && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
8124 && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
8125 && vec_safe_length (exprlist) == 3
8126 && integer_zerop ((*exprlist)[2])
8127 && (literal_zero_mask & (1 << 2)) != 0
8128 && (!integer_zerop ((*exprlist)[1])
8129 || (literal_zero_mask & (1 << 1)) == 0))
8130 warning_at (expr_loc, OPT_Wmemset_transposed_args,
8131 "%<memset%> used with constant zero length parameter; "
8132 "this could be due to transposed parameters");
8134 expr.value
8135 = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
8136 exprlist, origtypes);
8137 expr.original_code = ERROR_MARK;
8138 if (TREE_CODE (expr.value) == INTEGER_CST
8139 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
8140 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
8141 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
8142 expr.original_code = C_MAYBE_CONST_EXPR;
8143 expr.original_type = NULL;
8144 if (exprlist)
8146 release_tree_vector (exprlist);
8147 release_tree_vector (origtypes);
8149 arg_loc.release ();
8150 break;
8151 case CPP_DOT:
8152 /* Structure element reference. */
8153 c_parser_consume_token (parser);
8154 expr = default_function_array_conversion (expr_loc, expr);
8155 if (c_parser_next_token_is (parser, CPP_NAME))
8156 ident = c_parser_peek_token (parser)->value;
8157 else
8159 c_parser_error (parser, "expected identifier");
8160 expr.value = error_mark_node;
8161 expr.original_code = ERROR_MARK;
8162 expr.original_type = NULL;
8163 return expr;
8165 c_parser_consume_token (parser);
8166 expr.value = build_component_ref (op_loc, expr.value, ident);
8167 expr.original_code = ERROR_MARK;
8168 if (TREE_CODE (expr.value) != COMPONENT_REF)
8169 expr.original_type = NULL;
8170 else
8172 /* Remember the original type of a bitfield. */
8173 tree field = TREE_OPERAND (expr.value, 1);
8174 if (TREE_CODE (field) != FIELD_DECL)
8175 expr.original_type = NULL;
8176 else
8177 expr.original_type = DECL_BIT_FIELD_TYPE (field);
8179 break;
8180 case CPP_DEREF:
8181 /* Structure element reference. */
8182 c_parser_consume_token (parser);
8183 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
8184 if (c_parser_next_token_is (parser, CPP_NAME))
8185 ident = c_parser_peek_token (parser)->value;
8186 else
8188 c_parser_error (parser, "expected identifier");
8189 expr.value = error_mark_node;
8190 expr.original_code = ERROR_MARK;
8191 expr.original_type = NULL;
8192 return expr;
8194 c_parser_consume_token (parser);
8195 expr.value = build_component_ref (op_loc,
8196 build_indirect_ref (op_loc,
8197 expr.value,
8198 RO_ARROW),
8199 ident);
8200 expr.original_code = ERROR_MARK;
8201 if (TREE_CODE (expr.value) != COMPONENT_REF)
8202 expr.original_type = NULL;
8203 else
8205 /* Remember the original type of a bitfield. */
8206 tree field = TREE_OPERAND (expr.value, 1);
8207 if (TREE_CODE (field) != FIELD_DECL)
8208 expr.original_type = NULL;
8209 else
8210 expr.original_type = DECL_BIT_FIELD_TYPE (field);
8212 break;
8213 case CPP_PLUS_PLUS:
8214 /* Postincrement. */
8215 c_parser_consume_token (parser);
8216 /* If the expressions have array notations, we expand them. */
8217 if (flag_cilkplus
8218 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8219 expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr);
8220 else
8222 expr = default_function_array_read_conversion (expr_loc, expr);
8223 expr.value = build_unary_op (op_loc,
8224 POSTINCREMENT_EXPR, expr.value, 0);
8226 expr.original_code = ERROR_MARK;
8227 expr.original_type = NULL;
8228 break;
8229 case CPP_MINUS_MINUS:
8230 /* Postdecrement. */
8231 c_parser_consume_token (parser);
8232 /* If the expressions have array notations, we expand them. */
8233 if (flag_cilkplus
8234 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8235 expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr);
8236 else
8238 expr = default_function_array_read_conversion (expr_loc, expr);
8239 expr.value = build_unary_op (op_loc,
8240 POSTDECREMENT_EXPR, expr.value, 0);
8242 expr.original_code = ERROR_MARK;
8243 expr.original_type = NULL;
8244 break;
8245 default:
8246 return expr;
8251 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8253 expression:
8254 assignment-expression
8255 expression , assignment-expression
8258 static struct c_expr
8259 c_parser_expression (c_parser *parser)
8261 location_t tloc = c_parser_peek_token (parser)->location;
8262 struct c_expr expr;
8263 expr = c_parser_expr_no_commas (parser, NULL);
8264 if (c_parser_next_token_is (parser, CPP_COMMA))
8265 expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
8266 while (c_parser_next_token_is (parser, CPP_COMMA))
8268 struct c_expr next;
8269 tree lhsval;
8270 location_t loc = c_parser_peek_token (parser)->location;
8271 location_t expr_loc;
8272 c_parser_consume_token (parser);
8273 expr_loc = c_parser_peek_token (parser)->location;
8274 lhsval = expr.value;
8275 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
8276 lhsval = TREE_OPERAND (lhsval, 1);
8277 if (DECL_P (lhsval) || handled_component_p (lhsval))
8278 mark_exp_read (lhsval);
8279 next = c_parser_expr_no_commas (parser, NULL);
8280 next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
8281 expr.value = build_compound_expr (loc, expr.value, next.value);
8282 expr.original_code = COMPOUND_EXPR;
8283 expr.original_type = next.original_type;
8285 return expr;
8288 /* Parse an expression and convert functions or arrays to pointers and
8289 lvalues to rvalues. */
8291 static struct c_expr
8292 c_parser_expression_conv (c_parser *parser)
8294 struct c_expr expr;
8295 location_t loc = c_parser_peek_token (parser)->location;
8296 expr = c_parser_expression (parser);
8297 expr = convert_lvalue_to_rvalue (loc, expr, true, false);
8298 return expr;
8301 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8302 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8304 static inline void
8305 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
8306 unsigned int idx)
8308 if (idx >= HOST_BITS_PER_INT)
8309 return;
8311 c_token *tok = c_parser_peek_token (parser);
8312 switch (tok->type)
8314 case CPP_NUMBER:
8315 case CPP_CHAR:
8316 case CPP_WCHAR:
8317 case CPP_CHAR16:
8318 case CPP_CHAR32:
8319 /* If a parameter is literal zero alone, remember it
8320 for -Wmemset-transposed-args warning. */
8321 if (integer_zerop (tok->value)
8322 && !TREE_OVERFLOW (tok->value)
8323 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8324 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
8325 *literal_zero_mask |= 1U << idx;
8326 default:
8327 break;
8331 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8332 functions and arrays to pointers and lvalues to rvalues. If
8333 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8334 locations of function arguments into this vector.
8336 nonempty-expr-list:
8337 assignment-expression
8338 nonempty-expr-list , assignment-expression
8341 static vec<tree, va_gc> *
8342 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
8343 vec<tree, va_gc> **p_orig_types,
8344 location_t *sizeof_arg_loc, tree *sizeof_arg,
8345 vec<location_t> *locations,
8346 unsigned int *literal_zero_mask)
8348 vec<tree, va_gc> *ret;
8349 vec<tree, va_gc> *orig_types;
8350 struct c_expr expr;
8351 location_t loc = c_parser_peek_token (parser)->location;
8352 location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8353 unsigned int idx = 0;
8355 ret = make_tree_vector ();
8356 if (p_orig_types == NULL)
8357 orig_types = NULL;
8358 else
8359 orig_types = make_tree_vector ();
8361 if (sizeof_arg != NULL
8362 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8363 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8364 if (literal_zero_mask)
8365 c_parser_check_literal_zero (parser, literal_zero_mask, 0);
8366 expr = c_parser_expr_no_commas (parser, NULL);
8367 if (convert_p)
8368 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8369 if (fold_p)
8370 expr.value = c_fully_fold (expr.value, false, NULL);
8371 ret->quick_push (expr.value);
8372 if (orig_types)
8373 orig_types->quick_push (expr.original_type);
8374 if (locations)
8375 locations->safe_push (loc);
8376 if (sizeof_arg != NULL
8377 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8378 && expr.original_code == SIZEOF_EXPR)
8380 sizeof_arg[0] = c_last_sizeof_arg;
8381 sizeof_arg_loc[0] = cur_sizeof_arg_loc;
8383 while (c_parser_next_token_is (parser, CPP_COMMA))
8385 c_parser_consume_token (parser);
8386 loc = c_parser_peek_token (parser)->location;
8387 if (sizeof_arg != NULL
8388 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8389 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8390 else
8391 cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8392 if (literal_zero_mask)
8393 c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
8394 expr = c_parser_expr_no_commas (parser, NULL);
8395 if (convert_p)
8396 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8397 if (fold_p)
8398 expr.value = c_fully_fold (expr.value, false, NULL);
8399 vec_safe_push (ret, expr.value);
8400 if (orig_types)
8401 vec_safe_push (orig_types, expr.original_type);
8402 if (locations)
8403 locations->safe_push (loc);
8404 if (++idx < 3
8405 && sizeof_arg != NULL
8406 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8407 && expr.original_code == SIZEOF_EXPR)
8409 sizeof_arg[idx] = c_last_sizeof_arg;
8410 sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
8413 if (orig_types)
8414 *p_orig_types = orig_types;
8415 return ret;
8418 /* Parse Objective-C-specific constructs. */
8420 /* Parse an objc-class-definition.
8422 objc-class-definition:
8423 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8424 objc-class-instance-variables[opt] objc-methodprotolist @end
8425 @implementation identifier objc-superclass[opt]
8426 objc-class-instance-variables[opt]
8427 @interface identifier ( identifier ) objc-protocol-refs[opt]
8428 objc-methodprotolist @end
8429 @interface identifier ( ) objc-protocol-refs[opt]
8430 objc-methodprotolist @end
8431 @implementation identifier ( identifier )
8433 objc-superclass:
8434 : identifier
8436 "@interface identifier (" must start "@interface identifier (
8437 identifier ) ...": objc-methodprotolist in the first production may
8438 not start with a parenthesized identifier as a declarator of a data
8439 definition with no declaration specifiers if the objc-superclass,
8440 objc-protocol-refs and objc-class-instance-variables are omitted. */
8442 static void
8443 c_parser_objc_class_definition (c_parser *parser, tree attributes)
8445 bool iface_p;
8446 tree id1;
8447 tree superclass;
8448 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
8449 iface_p = true;
8450 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
8451 iface_p = false;
8452 else
8453 gcc_unreachable ();
8455 c_parser_consume_token (parser);
8456 if (c_parser_next_token_is_not (parser, CPP_NAME))
8458 c_parser_error (parser, "expected identifier");
8459 return;
8461 id1 = c_parser_peek_token (parser)->value;
8462 c_parser_consume_token (parser);
8463 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8465 /* We have a category or class extension. */
8466 tree id2;
8467 tree proto = NULL_TREE;
8468 c_parser_consume_token (parser);
8469 if (c_parser_next_token_is_not (parser, CPP_NAME))
8471 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8473 /* We have a class extension. */
8474 id2 = NULL_TREE;
8476 else
8478 c_parser_error (parser, "expected identifier or %<)%>");
8479 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8480 return;
8483 else
8485 id2 = c_parser_peek_token (parser)->value;
8486 c_parser_consume_token (parser);
8488 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8489 if (!iface_p)
8491 objc_start_category_implementation (id1, id2);
8492 return;
8494 if (c_parser_next_token_is (parser, CPP_LESS))
8495 proto = c_parser_objc_protocol_refs (parser);
8496 objc_start_category_interface (id1, id2, proto, attributes);
8497 c_parser_objc_methodprotolist (parser);
8498 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8499 objc_finish_interface ();
8500 return;
8502 if (c_parser_next_token_is (parser, CPP_COLON))
8504 c_parser_consume_token (parser);
8505 if (c_parser_next_token_is_not (parser, CPP_NAME))
8507 c_parser_error (parser, "expected identifier");
8508 return;
8510 superclass = c_parser_peek_token (parser)->value;
8511 c_parser_consume_token (parser);
8513 else
8514 superclass = NULL_TREE;
8515 if (iface_p)
8517 tree proto = NULL_TREE;
8518 if (c_parser_next_token_is (parser, CPP_LESS))
8519 proto = c_parser_objc_protocol_refs (parser);
8520 objc_start_class_interface (id1, superclass, proto, attributes);
8522 else
8523 objc_start_class_implementation (id1, superclass);
8524 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8525 c_parser_objc_class_instance_variables (parser);
8526 if (iface_p)
8528 objc_continue_interface ();
8529 c_parser_objc_methodprotolist (parser);
8530 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8531 objc_finish_interface ();
8533 else
8535 objc_continue_implementation ();
8536 return;
8540 /* Parse objc-class-instance-variables.
8542 objc-class-instance-variables:
8543 { objc-instance-variable-decl-list[opt] }
8545 objc-instance-variable-decl-list:
8546 objc-visibility-spec
8547 objc-instance-variable-decl ;
8549 objc-instance-variable-decl-list objc-visibility-spec
8550 objc-instance-variable-decl-list objc-instance-variable-decl ;
8551 objc-instance-variable-decl-list ;
8553 objc-visibility-spec:
8554 @private
8555 @protected
8556 @public
8558 objc-instance-variable-decl:
8559 struct-declaration
8562 static void
8563 c_parser_objc_class_instance_variables (c_parser *parser)
8565 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
8566 c_parser_consume_token (parser);
8567 while (c_parser_next_token_is_not (parser, CPP_EOF))
8569 tree decls;
8570 /* Parse any stray semicolon. */
8571 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8573 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8574 "extra semicolon");
8575 c_parser_consume_token (parser);
8576 continue;
8578 /* Stop if at the end of the instance variables. */
8579 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8581 c_parser_consume_token (parser);
8582 break;
8584 /* Parse any objc-visibility-spec. */
8585 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
8587 c_parser_consume_token (parser);
8588 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
8589 continue;
8591 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
8593 c_parser_consume_token (parser);
8594 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
8595 continue;
8597 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
8599 c_parser_consume_token (parser);
8600 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
8601 continue;
8603 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
8605 c_parser_consume_token (parser);
8606 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
8607 continue;
8609 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
8611 c_parser_pragma (parser, pragma_external);
8612 continue;
8615 /* Parse some comma-separated declarations. */
8616 decls = c_parser_struct_declaration (parser);
8617 if (decls == NULL)
8619 /* There is a syntax error. We want to skip the offending
8620 tokens up to the next ';' (included) or '}'
8621 (excluded). */
8623 /* First, skip manually a ')' or ']'. This is because they
8624 reduce the nesting level, so c_parser_skip_until_found()
8625 wouldn't be able to skip past them. */
8626 c_token *token = c_parser_peek_token (parser);
8627 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
8628 c_parser_consume_token (parser);
8630 /* Then, do the standard skipping. */
8631 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8633 /* We hopefully recovered. Start normal parsing again. */
8634 parser->error = false;
8635 continue;
8637 else
8639 /* Comma-separated instance variables are chained together
8640 in reverse order; add them one by one. */
8641 tree ivar = nreverse (decls);
8642 for (; ivar; ivar = DECL_CHAIN (ivar))
8643 objc_add_instance_variable (copy_node (ivar));
8645 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8649 /* Parse an objc-class-declaration.
8651 objc-class-declaration:
8652 @class identifier-list ;
8655 static void
8656 c_parser_objc_class_declaration (c_parser *parser)
8658 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
8659 c_parser_consume_token (parser);
8660 /* Any identifiers, including those declared as type names, are OK
8661 here. */
8662 while (true)
8664 tree id;
8665 if (c_parser_next_token_is_not (parser, CPP_NAME))
8667 c_parser_error (parser, "expected identifier");
8668 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8669 parser->error = false;
8670 return;
8672 id = c_parser_peek_token (parser)->value;
8673 objc_declare_class (id);
8674 c_parser_consume_token (parser);
8675 if (c_parser_next_token_is (parser, CPP_COMMA))
8676 c_parser_consume_token (parser);
8677 else
8678 break;
8680 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8683 /* Parse an objc-alias-declaration.
8685 objc-alias-declaration:
8686 @compatibility_alias identifier identifier ;
8689 static void
8690 c_parser_objc_alias_declaration (c_parser *parser)
8692 tree id1, id2;
8693 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
8694 c_parser_consume_token (parser);
8695 if (c_parser_next_token_is_not (parser, CPP_NAME))
8697 c_parser_error (parser, "expected identifier");
8698 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8699 return;
8701 id1 = c_parser_peek_token (parser)->value;
8702 c_parser_consume_token (parser);
8703 if (c_parser_next_token_is_not (parser, CPP_NAME))
8705 c_parser_error (parser, "expected identifier");
8706 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8707 return;
8709 id2 = c_parser_peek_token (parser)->value;
8710 c_parser_consume_token (parser);
8711 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8712 objc_declare_alias (id1, id2);
8715 /* Parse an objc-protocol-definition.
8717 objc-protocol-definition:
8718 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8719 @protocol identifier-list ;
8721 "@protocol identifier ;" should be resolved as "@protocol
8722 identifier-list ;": objc-methodprotolist may not start with a
8723 semicolon in the first alternative if objc-protocol-refs are
8724 omitted. */
8726 static void
8727 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
8729 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
8731 c_parser_consume_token (parser);
8732 if (c_parser_next_token_is_not (parser, CPP_NAME))
8734 c_parser_error (parser, "expected identifier");
8735 return;
8737 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8738 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
8740 /* Any identifiers, including those declared as type names, are
8741 OK here. */
8742 while (true)
8744 tree id;
8745 if (c_parser_next_token_is_not (parser, CPP_NAME))
8747 c_parser_error (parser, "expected identifier");
8748 break;
8750 id = c_parser_peek_token (parser)->value;
8751 objc_declare_protocol (id, attributes);
8752 c_parser_consume_token (parser);
8753 if (c_parser_next_token_is (parser, CPP_COMMA))
8754 c_parser_consume_token (parser);
8755 else
8756 break;
8758 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8760 else
8762 tree id = c_parser_peek_token (parser)->value;
8763 tree proto = NULL_TREE;
8764 c_parser_consume_token (parser);
8765 if (c_parser_next_token_is (parser, CPP_LESS))
8766 proto = c_parser_objc_protocol_refs (parser);
8767 parser->objc_pq_context = true;
8768 objc_start_protocol (id, proto, attributes);
8769 c_parser_objc_methodprotolist (parser);
8770 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8771 parser->objc_pq_context = false;
8772 objc_finish_interface ();
8776 /* Parse an objc-method-type.
8778 objc-method-type:
8782 Return true if it is a class method (+) and false if it is
8783 an instance method (-).
8785 static inline bool
8786 c_parser_objc_method_type (c_parser *parser)
8788 switch (c_parser_peek_token (parser)->type)
8790 case CPP_PLUS:
8791 c_parser_consume_token (parser);
8792 return true;
8793 case CPP_MINUS:
8794 c_parser_consume_token (parser);
8795 return false;
8796 default:
8797 gcc_unreachable ();
8801 /* Parse an objc-method-definition.
8803 objc-method-definition:
8804 objc-method-type objc-method-decl ;[opt] compound-statement
8807 static void
8808 c_parser_objc_method_definition (c_parser *parser)
8810 bool is_class_method = c_parser_objc_method_type (parser);
8811 tree decl, attributes = NULL_TREE, expr = NULL_TREE;
8812 parser->objc_pq_context = true;
8813 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8814 &expr);
8815 if (decl == error_mark_node)
8816 return; /* Bail here. */
8818 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8820 c_parser_consume_token (parser);
8821 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8822 "extra semicolon in method definition specified");
8825 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8827 c_parser_error (parser, "expected %<{%>");
8828 return;
8831 parser->objc_pq_context = false;
8832 if (objc_start_method_definition (is_class_method, decl, attributes, expr))
8834 add_stmt (c_parser_compound_statement (parser));
8835 objc_finish_method_definition (current_function_decl);
8837 else
8839 /* This code is executed when we find a method definition
8840 outside of an @implementation context (or invalid for other
8841 reasons). Parse the method (to keep going) but do not emit
8842 any code.
8844 c_parser_compound_statement (parser);
8848 /* Parse an objc-methodprotolist.
8850 objc-methodprotolist:
8851 empty
8852 objc-methodprotolist objc-methodproto
8853 objc-methodprotolist declaration
8854 objc-methodprotolist ;
8855 @optional
8856 @required
8858 The declaration is a data definition, which may be missing
8859 declaration specifiers under the same rules and diagnostics as
8860 other data definitions outside functions, and the stray semicolon
8861 is diagnosed the same way as a stray semicolon outside a
8862 function. */
8864 static void
8865 c_parser_objc_methodprotolist (c_parser *parser)
8867 while (true)
8869 /* The list is terminated by @end. */
8870 switch (c_parser_peek_token (parser)->type)
8872 case CPP_SEMICOLON:
8873 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8874 "ISO C does not allow extra %<;%> outside of a function");
8875 c_parser_consume_token (parser);
8876 break;
8877 case CPP_PLUS:
8878 case CPP_MINUS:
8879 c_parser_objc_methodproto (parser);
8880 break;
8881 case CPP_PRAGMA:
8882 c_parser_pragma (parser, pragma_external);
8883 break;
8884 case CPP_EOF:
8885 return;
8886 default:
8887 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
8888 return;
8889 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
8890 c_parser_objc_at_property_declaration (parser);
8891 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
8893 objc_set_method_opt (true);
8894 c_parser_consume_token (parser);
8896 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
8898 objc_set_method_opt (false);
8899 c_parser_consume_token (parser);
8901 else
8902 c_parser_declaration_or_fndef (parser, false, false, true,
8903 false, true, NULL, vNULL);
8904 break;
8909 /* Parse an objc-methodproto.
8911 objc-methodproto:
8912 objc-method-type objc-method-decl ;
8915 static void
8916 c_parser_objc_methodproto (c_parser *parser)
8918 bool is_class_method = c_parser_objc_method_type (parser);
8919 tree decl, attributes = NULL_TREE;
8921 /* Remember protocol qualifiers in prototypes. */
8922 parser->objc_pq_context = true;
8923 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8924 NULL);
8925 /* Forget protocol qualifiers now. */
8926 parser->objc_pq_context = false;
8928 /* Do not allow the presence of attributes to hide an erroneous
8929 method implementation in the interface section. */
8930 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
8932 c_parser_error (parser, "expected %<;%>");
8933 return;
8936 if (decl != error_mark_node)
8937 objc_add_method_declaration (is_class_method, decl, attributes);
8939 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8942 /* If we are at a position that method attributes may be present, check that
8943 there are not any parsed already (a syntax error) and then collect any
8944 specified at the current location. Finally, if new attributes were present,
8945 check that the next token is legal ( ';' for decls and '{' for defs). */
8947 static bool
8948 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
8950 bool bad = false;
8951 if (*attributes)
8953 c_parser_error (parser,
8954 "method attributes must be specified at the end only");
8955 *attributes = NULL_TREE;
8956 bad = true;
8959 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8960 *attributes = c_parser_attributes (parser);
8962 /* If there were no attributes here, just report any earlier error. */
8963 if (*attributes == NULL_TREE || bad)
8964 return bad;
8966 /* If the attributes are followed by a ; or {, then just report any earlier
8967 error. */
8968 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
8969 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8970 return bad;
8972 /* We've got attributes, but not at the end. */
8973 c_parser_error (parser,
8974 "expected %<;%> or %<{%> after method attribute definition");
8975 return true;
8978 /* Parse an objc-method-decl.
8980 objc-method-decl:
8981 ( objc-type-name ) objc-selector
8982 objc-selector
8983 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8984 objc-keyword-selector objc-optparmlist
8985 attributes
8987 objc-keyword-selector:
8988 objc-keyword-decl
8989 objc-keyword-selector objc-keyword-decl
8991 objc-keyword-decl:
8992 objc-selector : ( objc-type-name ) identifier
8993 objc-selector : identifier
8994 : ( objc-type-name ) identifier
8995 : identifier
8997 objc-optparmlist:
8998 objc-optparms objc-optellipsis
9000 objc-optparms:
9001 empty
9002 objc-opt-parms , parameter-declaration
9004 objc-optellipsis:
9005 empty
9006 , ...
9009 static tree
9010 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
9011 tree *attributes, tree *expr)
9013 tree type = NULL_TREE;
9014 tree sel;
9015 tree parms = NULL_TREE;
9016 bool ellipsis = false;
9017 bool attr_err = false;
9019 *attributes = NULL_TREE;
9020 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9022 c_parser_consume_token (parser);
9023 type = c_parser_objc_type_name (parser);
9024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9026 sel = c_parser_objc_selector (parser);
9027 /* If there is no selector, or a colon follows, we have an
9028 objc-keyword-selector. If there is a selector, and a colon does
9029 not follow, that selector ends the objc-method-decl. */
9030 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
9032 tree tsel = sel;
9033 tree list = NULL_TREE;
9034 while (true)
9036 tree atype = NULL_TREE, id, keyworddecl;
9037 tree param_attr = NULL_TREE;
9038 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9039 break;
9040 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9042 c_parser_consume_token (parser);
9043 atype = c_parser_objc_type_name (parser);
9044 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9045 "expected %<)%>");
9047 /* New ObjC allows attributes on method parameters. */
9048 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
9049 param_attr = c_parser_attributes (parser);
9050 if (c_parser_next_token_is_not (parser, CPP_NAME))
9052 c_parser_error (parser, "expected identifier");
9053 return error_mark_node;
9055 id = c_parser_peek_token (parser)->value;
9056 c_parser_consume_token (parser);
9057 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
9058 list = chainon (list, keyworddecl);
9059 tsel = c_parser_objc_selector (parser);
9060 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
9061 break;
9064 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
9066 /* Parse the optional parameter list. Optional Objective-C
9067 method parameters follow the C syntax, and may include '...'
9068 to denote a variable number of arguments. */
9069 parms = make_node (TREE_LIST);
9070 while (c_parser_next_token_is (parser, CPP_COMMA))
9072 struct c_parm *parm;
9073 c_parser_consume_token (parser);
9074 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
9076 ellipsis = true;
9077 c_parser_consume_token (parser);
9078 attr_err |= c_parser_objc_maybe_method_attributes
9079 (parser, attributes) ;
9080 break;
9082 parm = c_parser_parameter_declaration (parser, NULL_TREE);
9083 if (parm == NULL)
9084 break;
9085 parms = chainon (parms,
9086 build_tree_list (NULL_TREE, grokparm (parm, expr)));
9088 sel = list;
9090 else
9091 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
9093 if (sel == NULL)
9095 c_parser_error (parser, "objective-c method declaration is expected");
9096 return error_mark_node;
9099 if (attr_err)
9100 return error_mark_node;
9102 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
9105 /* Parse an objc-type-name.
9107 objc-type-name:
9108 objc-type-qualifiers[opt] type-name
9109 objc-type-qualifiers[opt]
9111 objc-type-qualifiers:
9112 objc-type-qualifier
9113 objc-type-qualifiers objc-type-qualifier
9115 objc-type-qualifier: one of
9116 in out inout bycopy byref oneway
9119 static tree
9120 c_parser_objc_type_name (c_parser *parser)
9122 tree quals = NULL_TREE;
9123 struct c_type_name *type_name = NULL;
9124 tree type = NULL_TREE;
9125 while (true)
9127 c_token *token = c_parser_peek_token (parser);
9128 if (token->type == CPP_KEYWORD
9129 && (token->keyword == RID_IN
9130 || token->keyword == RID_OUT
9131 || token->keyword == RID_INOUT
9132 || token->keyword == RID_BYCOPY
9133 || token->keyword == RID_BYREF
9134 || token->keyword == RID_ONEWAY))
9136 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
9137 c_parser_consume_token (parser);
9139 else
9140 break;
9142 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
9143 type_name = c_parser_type_name (parser);
9144 if (type_name)
9145 type = groktypename (type_name, NULL, NULL);
9147 /* If the type is unknown, and error has already been produced and
9148 we need to recover from the error. In that case, use NULL_TREE
9149 for the type, as if no type had been specified; this will use the
9150 default type ('id') which is good for error recovery. */
9151 if (type == error_mark_node)
9152 type = NULL_TREE;
9154 return build_tree_list (quals, type);
9157 /* Parse objc-protocol-refs.
9159 objc-protocol-refs:
9160 < identifier-list >
9163 static tree
9164 c_parser_objc_protocol_refs (c_parser *parser)
9166 tree list = NULL_TREE;
9167 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
9168 c_parser_consume_token (parser);
9169 /* Any identifiers, including those declared as type names, are OK
9170 here. */
9171 while (true)
9173 tree id;
9174 if (c_parser_next_token_is_not (parser, CPP_NAME))
9176 c_parser_error (parser, "expected identifier");
9177 break;
9179 id = c_parser_peek_token (parser)->value;
9180 list = chainon (list, build_tree_list (NULL_TREE, id));
9181 c_parser_consume_token (parser);
9182 if (c_parser_next_token_is (parser, CPP_COMMA))
9183 c_parser_consume_token (parser);
9184 else
9185 break;
9187 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
9188 return list;
9191 /* Parse an objc-try-catch-finally-statement.
9193 objc-try-catch-finally-statement:
9194 @try compound-statement objc-catch-list[opt]
9195 @try compound-statement objc-catch-list[opt] @finally compound-statement
9197 objc-catch-list:
9198 @catch ( objc-catch-parameter-declaration ) compound-statement
9199 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9201 objc-catch-parameter-declaration:
9202 parameter-declaration
9203 '...'
9205 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9207 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9208 for C++. Keep them in sync. */
9210 static void
9211 c_parser_objc_try_catch_finally_statement (c_parser *parser)
9213 location_t location;
9214 tree stmt;
9216 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
9217 c_parser_consume_token (parser);
9218 location = c_parser_peek_token (parser)->location;
9219 objc_maybe_warn_exceptions (location);
9220 stmt = c_parser_compound_statement (parser);
9221 objc_begin_try_stmt (location, stmt);
9223 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
9225 struct c_parm *parm;
9226 tree parameter_declaration = error_mark_node;
9227 bool seen_open_paren = false;
9229 c_parser_consume_token (parser);
9230 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9231 seen_open_paren = true;
9232 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
9234 /* We have "@catch (...)" (where the '...' are literally
9235 what is in the code). Skip the '...'.
9236 parameter_declaration is set to NULL_TREE, and
9237 objc_being_catch_clauses() knows that that means
9238 '...'. */
9239 c_parser_consume_token (parser);
9240 parameter_declaration = NULL_TREE;
9242 else
9244 /* We have "@catch (NSException *exception)" or something
9245 like that. Parse the parameter declaration. */
9246 parm = c_parser_parameter_declaration (parser, NULL_TREE);
9247 if (parm == NULL)
9248 parameter_declaration = error_mark_node;
9249 else
9250 parameter_declaration = grokparm (parm, NULL);
9252 if (seen_open_paren)
9253 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9254 else
9256 /* If there was no open parenthesis, we are recovering from
9257 an error, and we are trying to figure out what mistake
9258 the user has made. */
9260 /* If there is an immediate closing parenthesis, the user
9261 probably forgot the opening one (ie, they typed "@catch
9262 NSException *e)". Parse the closing parenthesis and keep
9263 going. */
9264 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9265 c_parser_consume_token (parser);
9267 /* If these is no immediate closing parenthesis, the user
9268 probably doesn't know that parenthesis are required at
9269 all (ie, they typed "@catch NSException *e"). So, just
9270 forget about the closing parenthesis and keep going. */
9272 objc_begin_catch_clause (parameter_declaration);
9273 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9274 c_parser_compound_statement_nostart (parser);
9275 objc_finish_catch_clause ();
9277 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
9279 c_parser_consume_token (parser);
9280 location = c_parser_peek_token (parser)->location;
9281 stmt = c_parser_compound_statement (parser);
9282 objc_build_finally_clause (location, stmt);
9284 objc_finish_try_stmt ();
9287 /* Parse an objc-synchronized-statement.
9289 objc-synchronized-statement:
9290 @synchronized ( expression ) compound-statement
9293 static void
9294 c_parser_objc_synchronized_statement (c_parser *parser)
9296 location_t loc;
9297 tree expr, stmt;
9298 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
9299 c_parser_consume_token (parser);
9300 loc = c_parser_peek_token (parser)->location;
9301 objc_maybe_warn_exceptions (loc);
9302 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9304 struct c_expr ce = c_parser_expression (parser);
9305 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9306 expr = ce.value;
9307 expr = c_fully_fold (expr, false, NULL);
9308 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9310 else
9311 expr = error_mark_node;
9312 stmt = c_parser_compound_statement (parser);
9313 objc_build_synchronized (loc, expr, stmt);
9316 /* Parse an objc-selector; return NULL_TREE without an error if the
9317 next token is not an objc-selector.
9319 objc-selector:
9320 identifier
9321 one of
9322 enum struct union if else while do for switch case default
9323 break continue return goto asm sizeof typeof __alignof
9324 unsigned long const short volatile signed restrict _Complex
9325 in out inout bycopy byref oneway int char float double void _Bool
9326 _Atomic
9328 ??? Why this selection of keywords but not, for example, storage
9329 class specifiers? */
9331 static tree
9332 c_parser_objc_selector (c_parser *parser)
9334 c_token *token = c_parser_peek_token (parser);
9335 tree value = token->value;
9336 if (token->type == CPP_NAME)
9338 c_parser_consume_token (parser);
9339 return value;
9341 if (token->type != CPP_KEYWORD)
9342 return NULL_TREE;
9343 switch (token->keyword)
9345 case RID_ENUM:
9346 case RID_STRUCT:
9347 case RID_UNION:
9348 case RID_IF:
9349 case RID_ELSE:
9350 case RID_WHILE:
9351 case RID_DO:
9352 case RID_FOR:
9353 case RID_SWITCH:
9354 case RID_CASE:
9355 case RID_DEFAULT:
9356 case RID_BREAK:
9357 case RID_CONTINUE:
9358 case RID_RETURN:
9359 case RID_GOTO:
9360 case RID_ASM:
9361 case RID_SIZEOF:
9362 case RID_TYPEOF:
9363 case RID_ALIGNOF:
9364 case RID_UNSIGNED:
9365 case RID_LONG:
9366 case RID_CONST:
9367 case RID_SHORT:
9368 case RID_VOLATILE:
9369 case RID_SIGNED:
9370 case RID_RESTRICT:
9371 case RID_COMPLEX:
9372 case RID_IN:
9373 case RID_OUT:
9374 case RID_INOUT:
9375 case RID_BYCOPY:
9376 case RID_BYREF:
9377 case RID_ONEWAY:
9378 case RID_INT:
9379 case RID_CHAR:
9380 case RID_FLOAT:
9381 case RID_DOUBLE:
9382 case RID_VOID:
9383 case RID_BOOL:
9384 case RID_ATOMIC:
9385 case RID_AUTO_TYPE:
9386 case RID_INT_N_0:
9387 case RID_INT_N_1:
9388 case RID_INT_N_2:
9389 case RID_INT_N_3:
9390 c_parser_consume_token (parser);
9391 return value;
9392 default:
9393 return NULL_TREE;
9397 /* Parse an objc-selector-arg.
9399 objc-selector-arg:
9400 objc-selector
9401 objc-keywordname-list
9403 objc-keywordname-list:
9404 objc-keywordname
9405 objc-keywordname-list objc-keywordname
9407 objc-keywordname:
9408 objc-selector :
9412 static tree
9413 c_parser_objc_selector_arg (c_parser *parser)
9415 tree sel = c_parser_objc_selector (parser);
9416 tree list = NULL_TREE;
9417 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9418 return sel;
9419 while (true)
9421 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9422 return list;
9423 list = chainon (list, build_tree_list (sel, NULL_TREE));
9424 sel = c_parser_objc_selector (parser);
9425 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9426 break;
9428 return list;
9431 /* Parse an objc-receiver.
9433 objc-receiver:
9434 expression
9435 class-name
9436 type-name
9439 static tree
9440 c_parser_objc_receiver (c_parser *parser)
9442 location_t loc = c_parser_peek_token (parser)->location;
9444 if (c_parser_peek_token (parser)->type == CPP_NAME
9445 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
9446 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
9448 tree id = c_parser_peek_token (parser)->value;
9449 c_parser_consume_token (parser);
9450 return objc_get_class_reference (id);
9452 struct c_expr ce = c_parser_expression (parser);
9453 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9454 return c_fully_fold (ce.value, false, NULL);
9457 /* Parse objc-message-args.
9459 objc-message-args:
9460 objc-selector
9461 objc-keywordarg-list
9463 objc-keywordarg-list:
9464 objc-keywordarg
9465 objc-keywordarg-list objc-keywordarg
9467 objc-keywordarg:
9468 objc-selector : objc-keywordexpr
9469 : objc-keywordexpr
9472 static tree
9473 c_parser_objc_message_args (c_parser *parser)
9475 tree sel = c_parser_objc_selector (parser);
9476 tree list = NULL_TREE;
9477 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9478 return sel;
9479 while (true)
9481 tree keywordexpr;
9482 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9483 return error_mark_node;
9484 keywordexpr = c_parser_objc_keywordexpr (parser);
9485 list = chainon (list, build_tree_list (sel, keywordexpr));
9486 sel = c_parser_objc_selector (parser);
9487 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9488 break;
9490 return list;
9493 /* Parse an objc-keywordexpr.
9495 objc-keywordexpr:
9496 nonempty-expr-list
9499 static tree
9500 c_parser_objc_keywordexpr (c_parser *parser)
9502 tree ret;
9503 vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
9504 NULL, NULL, NULL, NULL);
9505 if (vec_safe_length (expr_list) == 1)
9507 /* Just return the expression, remove a level of
9508 indirection. */
9509 ret = (*expr_list)[0];
9511 else
9513 /* We have a comma expression, we will collapse later. */
9514 ret = build_tree_list_vec (expr_list);
9516 release_tree_vector (expr_list);
9517 return ret;
9520 /* A check, needed in several places, that ObjC interface, implementation or
9521 method definitions are not prefixed by incorrect items. */
9522 static bool
9523 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
9524 struct c_declspecs *specs)
9526 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
9527 || specs->typespec_kind != ctsk_none)
9529 c_parser_error (parser,
9530 "no type or storage class may be specified here,");
9531 c_parser_skip_to_end_of_block_or_statement (parser);
9532 return true;
9534 return false;
9537 /* Parse an Objective-C @property declaration. The syntax is:
9539 objc-property-declaration:
9540 '@property' objc-property-attributes[opt] struct-declaration ;
9542 objc-property-attributes:
9543 '(' objc-property-attribute-list ')'
9545 objc-property-attribute-list:
9546 objc-property-attribute
9547 objc-property-attribute-list, objc-property-attribute
9549 objc-property-attribute
9550 'getter' = identifier
9551 'setter' = identifier
9552 'readonly'
9553 'readwrite'
9554 'assign'
9555 'retain'
9556 'copy'
9557 'nonatomic'
9559 For example:
9560 @property NSString *name;
9561 @property (readonly) id object;
9562 @property (retain, nonatomic, getter=getTheName) id name;
9563 @property int a, b, c;
9565 PS: This function is identical to cp_parser_objc_at_propery_declaration
9566 for C++. Keep them in sync. */
9567 static void
9568 c_parser_objc_at_property_declaration (c_parser *parser)
9570 /* The following variables hold the attributes of the properties as
9571 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9572 seen. When we see an attribute, we set them to 'true' (if they
9573 are boolean properties) or to the identifier (if they have an
9574 argument, ie, for getter and setter). Note that here we only
9575 parse the list of attributes, check the syntax and accumulate the
9576 attributes that we find. objc_add_property_declaration() will
9577 then process the information. */
9578 bool property_assign = false;
9579 bool property_copy = false;
9580 tree property_getter_ident = NULL_TREE;
9581 bool property_nonatomic = false;
9582 bool property_readonly = false;
9583 bool property_readwrite = false;
9584 bool property_retain = false;
9585 tree property_setter_ident = NULL_TREE;
9587 /* 'properties' is the list of properties that we read. Usually a
9588 single one, but maybe more (eg, in "@property int a, b, c;" there
9589 are three). */
9590 tree properties;
9591 location_t loc;
9593 loc = c_parser_peek_token (parser)->location;
9594 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
9596 c_parser_consume_token (parser); /* Eat '@property'. */
9598 /* Parse the optional attribute list... */
9599 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9601 /* Eat the '(' */
9602 c_parser_consume_token (parser);
9604 /* Property attribute keywords are valid now. */
9605 parser->objc_property_attr_context = true;
9607 while (true)
9609 bool syntax_error = false;
9610 c_token *token = c_parser_peek_token (parser);
9611 enum rid keyword;
9613 if (token->type != CPP_KEYWORD)
9615 if (token->type == CPP_CLOSE_PAREN)
9616 c_parser_error (parser, "expected identifier");
9617 else
9619 c_parser_consume_token (parser);
9620 c_parser_error (parser, "unknown property attribute");
9622 break;
9624 keyword = token->keyword;
9625 c_parser_consume_token (parser);
9626 switch (keyword)
9628 case RID_ASSIGN: property_assign = true; break;
9629 case RID_COPY: property_copy = true; break;
9630 case RID_NONATOMIC: property_nonatomic = true; break;
9631 case RID_READONLY: property_readonly = true; break;
9632 case RID_READWRITE: property_readwrite = true; break;
9633 case RID_RETAIN: property_retain = true; break;
9635 case RID_GETTER:
9636 case RID_SETTER:
9637 if (c_parser_next_token_is_not (parser, CPP_EQ))
9639 if (keyword == RID_GETTER)
9640 c_parser_error (parser,
9641 "missing %<=%> (after %<getter%> attribute)");
9642 else
9643 c_parser_error (parser,
9644 "missing %<=%> (after %<setter%> attribute)");
9645 syntax_error = true;
9646 break;
9648 c_parser_consume_token (parser); /* eat the = */
9649 if (c_parser_next_token_is_not (parser, CPP_NAME))
9651 c_parser_error (parser, "expected identifier");
9652 syntax_error = true;
9653 break;
9655 if (keyword == RID_SETTER)
9657 if (property_setter_ident != NULL_TREE)
9658 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
9659 else
9660 property_setter_ident = c_parser_peek_token (parser)->value;
9661 c_parser_consume_token (parser);
9662 if (c_parser_next_token_is_not (parser, CPP_COLON))
9663 c_parser_error (parser, "setter name must terminate with %<:%>");
9664 else
9665 c_parser_consume_token (parser);
9667 else
9669 if (property_getter_ident != NULL_TREE)
9670 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
9671 else
9672 property_getter_ident = c_parser_peek_token (parser)->value;
9673 c_parser_consume_token (parser);
9675 break;
9676 default:
9677 c_parser_error (parser, "unknown property attribute");
9678 syntax_error = true;
9679 break;
9682 if (syntax_error)
9683 break;
9685 if (c_parser_next_token_is (parser, CPP_COMMA))
9686 c_parser_consume_token (parser);
9687 else
9688 break;
9690 parser->objc_property_attr_context = false;
9691 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9693 /* ... and the property declaration(s). */
9694 properties = c_parser_struct_declaration (parser);
9696 if (properties == error_mark_node)
9698 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9699 parser->error = false;
9700 return;
9703 if (properties == NULL_TREE)
9704 c_parser_error (parser, "expected identifier");
9705 else
9707 /* Comma-separated properties are chained together in
9708 reverse order; add them one by one. */
9709 properties = nreverse (properties);
9711 for (; properties; properties = TREE_CHAIN (properties))
9712 objc_add_property_declaration (loc, copy_node (properties),
9713 property_readonly, property_readwrite,
9714 property_assign, property_retain,
9715 property_copy, property_nonatomic,
9716 property_getter_ident, property_setter_ident);
9719 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9720 parser->error = false;
9723 /* Parse an Objective-C @synthesize declaration. The syntax is:
9725 objc-synthesize-declaration:
9726 @synthesize objc-synthesize-identifier-list ;
9728 objc-synthesize-identifier-list:
9729 objc-synthesize-identifier
9730 objc-synthesize-identifier-list, objc-synthesize-identifier
9732 objc-synthesize-identifier
9733 identifier
9734 identifier = identifier
9736 For example:
9737 @synthesize MyProperty;
9738 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9740 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9741 for C++. Keep them in sync.
9743 static void
9744 c_parser_objc_at_synthesize_declaration (c_parser *parser)
9746 tree list = NULL_TREE;
9747 location_t loc;
9748 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
9749 loc = c_parser_peek_token (parser)->location;
9751 c_parser_consume_token (parser);
9752 while (true)
9754 tree property, ivar;
9755 if (c_parser_next_token_is_not (parser, CPP_NAME))
9757 c_parser_error (parser, "expected identifier");
9758 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9759 /* Once we find the semicolon, we can resume normal parsing.
9760 We have to reset parser->error manually because
9761 c_parser_skip_until_found() won't reset it for us if the
9762 next token is precisely a semicolon. */
9763 parser->error = false;
9764 return;
9766 property = c_parser_peek_token (parser)->value;
9767 c_parser_consume_token (parser);
9768 if (c_parser_next_token_is (parser, CPP_EQ))
9770 c_parser_consume_token (parser);
9771 if (c_parser_next_token_is_not (parser, CPP_NAME))
9773 c_parser_error (parser, "expected identifier");
9774 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9775 parser->error = false;
9776 return;
9778 ivar = c_parser_peek_token (parser)->value;
9779 c_parser_consume_token (parser);
9781 else
9782 ivar = NULL_TREE;
9783 list = chainon (list, build_tree_list (ivar, property));
9784 if (c_parser_next_token_is (parser, CPP_COMMA))
9785 c_parser_consume_token (parser);
9786 else
9787 break;
9789 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9790 objc_add_synthesize_declaration (loc, list);
9793 /* Parse an Objective-C @dynamic declaration. The syntax is:
9795 objc-dynamic-declaration:
9796 @dynamic identifier-list ;
9798 For example:
9799 @dynamic MyProperty;
9800 @dynamic MyProperty, AnotherProperty;
9802 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9803 for C++. Keep them in sync.
9805 static void
9806 c_parser_objc_at_dynamic_declaration (c_parser *parser)
9808 tree list = NULL_TREE;
9809 location_t loc;
9810 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
9811 loc = c_parser_peek_token (parser)->location;
9813 c_parser_consume_token (parser);
9814 while (true)
9816 tree property;
9817 if (c_parser_next_token_is_not (parser, CPP_NAME))
9819 c_parser_error (parser, "expected identifier");
9820 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9821 parser->error = false;
9822 return;
9824 property = c_parser_peek_token (parser)->value;
9825 list = chainon (list, build_tree_list (NULL_TREE, property));
9826 c_parser_consume_token (parser);
9827 if (c_parser_next_token_is (parser, CPP_COMMA))
9828 c_parser_consume_token (parser);
9829 else
9830 break;
9832 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9833 objc_add_dynamic_declaration (loc, list);
9836 /* Parse UPC shared qualifier
9838 shared-type-qualifier: shared layout-qualifier-opt
9839 layout-qualifier: [ constant-expression-opt ] | [ * ]
9842 static void
9843 c_parser_upc_shared_qual (source_location loc,
9844 c_parser *parser,
9845 struct c_declspecs *specs)
9847 tree array_qual, arg1;
9849 /* consume "shared" part */
9850 c_parser_consume_token (parser);
9852 /* check for shared array layout specifier */
9853 if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
9855 declspecs_add_qual (loc, specs, ridpointers[RID_SHARED]);
9856 return;
9858 c_parser_consume_token (parser);
9859 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
9861 /* [] layout specifier */
9862 arg1 = size_zero_node;
9864 else if (c_parser_next_token_is (parser, CPP_MULT))
9866 /* [*] layout specifier */
9867 arg1 = build1 (INDIRECT_REF, NULL_TREE, NULL_TREE);
9868 c_parser_consume_token (parser);
9870 else
9872 /* [ expression ] layout specifier */
9873 arg1 = c_parser_expression (parser).value;
9875 array_qual = build4 (ARRAY_REF, NULL_TREE, NULL_TREE,
9876 arg1, NULL_TREE, NULL_TREE);
9877 declspecs_add_qual (loc, specs, array_qual);
9879 if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
9881 c_parser_error (parser, "expected ]");
9883 c_parser_consume_token (parser);
9886 /* Implement UPC's upc_forall 'affinity' test.
9887 If the type of AFFINITY is a UPC pointer-to-shared type,
9888 rewrite it into:
9889 upc_threadof (AFFINITY) == MYTHREAD
9890 If AFFINITY is an integer expression, then
9891 rewrite it into:
9892 (AFFINITY % THREADS) == MYTHREAD */
9894 static tree
9895 upc_affinity_test (location_t loc, tree affinity)
9897 tree mythread;
9898 tree affinity_test;
9900 gcc_assert (affinity != NULL_TREE);
9902 if (TREE_CODE (TREE_TYPE (affinity)) == POINTER_TYPE
9903 && upc_shared_type_p (TREE_TYPE (TREE_TYPE (affinity))))
9905 /* We have a pointer to a UPC shared object and the affinity is
9906 determined by the thread component of the address. */
9907 const tree pts_rep = build1 (VIEW_CONVERT_EXPR, upc_pts_rep_type_node,
9908 save_expr (affinity));
9909 affinity = (*upc_pts.threadof) (loc, pts_rep);
9911 else if (TREE_CODE (TREE_TYPE (affinity)) == INTEGER_TYPE)
9913 tree n_threads = upc_num_threads ();
9914 affinity =
9915 build_binary_op (loc, FLOOR_MOD_EXPR, affinity, n_threads, 0);
9917 else
9919 error
9920 ("UPC affinity expression is neither an integer nor the address of "
9921 "a shared object");
9922 return error_mark_node;
9925 /* Generate an external reference to the "MYTHREAD" identifier. */
9927 mythread = lookup_name (get_identifier ("MYTHREAD"));
9928 gcc_assert (mythread != NULL_TREE);
9929 assemble_external (mythread);
9930 TREE_USED (mythread) = 1;
9932 /* AFFINITY now contains an integer value that can be compared to MY_THREAD.
9933 Create an expression that tests if AFFINITY is equal to MYTHREAD. */
9935 if (!c_types_compatible_p (TREE_TYPE (affinity), TREE_TYPE (mythread)))
9936 affinity = convert (TREE_TYPE (mythread), affinity);
9937 affinity_test = c_objc_common_truthvalue_conversion (loc,
9938 build_binary_op (loc, EQ_EXPR,
9939 affinity, mythread, 1));
9940 /* Remove any MAYBE_CONST_EXPR's. */
9942 affinity_test = c_fully_fold (affinity_test, false, NULL);
9944 return affinity_test;
9947 /* Parse a UPC upc_forall statement
9949 upc_forall-statement:
9950 upc_forall ( expression[opt] ; expression[opt] ;
9951 expression[opt] ; affinity[opt] ) statement
9952 affinity: experssion | continue */
9954 static void
9955 c_parser_upc_forall_statement (c_parser *parser)
9957 tree block, cond, incr, save_break, save_cont, body;
9958 tree affinity;
9959 location_t loc = c_parser_peek_token (parser)->location;
9960 location_t affinity_loc = UNKNOWN_LOCATION;
9961 const int profile_upc_forall = flag_upc_instrument && get_upc_pupc_mode();
9962 gcc_assert (c_parser_next_token_is_keyword (parser, RID_UPC_FORALL));
9963 c_parser_consume_token (parser);
9964 block = c_begin_compound_stmt (flag_isoc99);
9965 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9967 /* Parse the initialization declaration or expression. */
9968 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9970 c_parser_consume_token (parser);
9971 c_finish_expr_stmt (loc, NULL_TREE);
9973 else if (c_parser_next_token_starts_declspecs (parser))
9975 c_parser_declaration_or_fndef (parser, true, true, true,
9976 true, true, NULL, vNULL);
9977 check_for_loop_decls (loc, true);
9979 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
9981 /* __extension__ can start a declaration, but is also an
9982 unary operator that can start an expression. Consume all
9983 but the last of a possible series of __extension__ to
9984 determine which. */
9985 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
9986 && (c_parser_peek_2nd_token (parser)->keyword
9987 == RID_EXTENSION))
9988 c_parser_consume_token (parser);
9989 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
9991 int ext;
9992 ext = disable_extension_diagnostics ();
9993 c_parser_consume_token (parser);
9994 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
9995 NULL, vNULL);
9996 restore_extension_diagnostics (ext);
9997 check_for_loop_decls (loc, true);
9999 else
10000 goto init_expr;
10002 else
10004 init_expr:
10005 c_finish_expr_stmt (loc, c_parser_expression (parser).value);
10006 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10008 /* Parse the loop condition. */
10009 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
10011 c_parser_consume_token (parser);
10012 cond = NULL_TREE;
10014 else
10016 cond = c_parser_condition (parser);
10017 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10019 /* Parse the increment expression. */
10020 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
10021 incr = c_process_expr_stmt (loc, NULL_TREE);
10022 else
10023 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
10024 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10025 /* Parse the UPC affinity expression. */
10026 affinity_loc = c_parser_peek_token (parser)->location;
10027 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
10029 affinity = NULL_TREE;
10031 else if (c_parser_peek_token (parser)->type == CPP_KEYWORD
10032 && c_parser_peek_token (parser)->keyword == RID_CONTINUE)
10034 affinity = NULL_TREE;
10035 c_parser_consume_token (parser);
10037 else
10039 affinity = c_parser_expression_conv (parser).value;
10040 affinity = c_fully_fold (affinity, false, NULL);
10042 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10043 if (affinity)
10044 affinity = upc_affinity_test (affinity_loc, affinity);
10046 else
10048 cond = error_mark_node;
10049 incr = error_mark_node;
10050 affinity = error_mark_node;
10052 save_break = c_break_label;
10053 c_break_label = NULL_TREE;
10054 save_cont = c_cont_label;
10055 c_cont_label = NULL_TREE;
10056 body = c_parser_c99_block_statement (parser);
10057 if (profile_upc_forall)
10059 const tree gasp_start = upc_instrument_forall (loc, 1 /* start */);
10060 add_stmt (gasp_start);
10062 loc = c_parser_peek_token (parser)->location;
10063 if (affinity != NULL_TREE && affinity != error_mark_node)
10065 tree upc_forall_depth = upc_rts_forall_depth_var ();
10066 tree inc_depth, depth_gt_one;
10067 inc_depth = build_unary_op (loc, PREINCREMENT_EXPR, upc_forall_depth, 0);
10068 c_finish_expr_stmt (loc, inc_depth);
10069 depth_gt_one = build_binary_op (affinity_loc,
10070 GT_EXPR, upc_forall_depth, integer_one_node, 0);
10071 depth_gt_one = c_objc_common_truthvalue_conversion (affinity_loc, depth_gt_one);
10072 depth_gt_one = c_fully_fold (depth_gt_one, false, NULL);
10073 affinity = build_binary_op (affinity_loc, TRUTH_OR_EXPR,
10074 depth_gt_one, affinity, 0);
10075 body = build3 (COND_EXPR, void_type_node, affinity,
10076 body, NULL_TREE);
10077 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
10078 c_finish_expr_stmt (loc,
10079 build_unary_op (loc, PREDECREMENT_EXPR, upc_forall_depth, 0));
10081 else
10082 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
10083 if (profile_upc_forall)
10085 const tree gasp_end = upc_instrument_forall (loc, 0 /* start */);
10086 add_stmt (gasp_end);
10088 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
10089 c_break_label = save_break;
10090 c_cont_label = save_cont;
10093 /* For the given kind of UPC synchronization statement given
10094 by SYNC_KIND (UPC_SYNC_NOTIFY_OP, UPC_SYNC_WAIT_OP,
10095 or UPC_SYNC_BARRIER_OP), build a UPC_SYNC_STMT tree node,
10096 and add it to the current statement list. The value of
10097 SYNC_EXPR will be non-null if an expression is present
10098 in the UPC statement being compiled.
10100 If SYNC_EXPR is supplied, it must be assignment compatible
10101 with type 'int'. */
10103 static tree
10104 upc_build_sync_stmt (location_t loc, tree sync_kind, tree sync_expr)
10106 if (sync_expr != NULL_TREE)
10108 mark_exp_read (sync_expr);
10109 sync_expr = c_cvt_expr_for_assign (loc, integer_type_node, sync_expr);
10110 if (sync_expr == error_mark_node)
10112 inform (loc, "UPC synchronization statement expressions "
10113 "must be assignment compatible with type `int'");
10114 sync_expr = NULL_TREE;
10117 return add_stmt (build_stmt (loc, UPC_SYNC_STMT, sync_kind, sync_expr));
10120 /* Parse an upc-sync-statement.
10122 upc_barrier, upc_wait, upc_notify
10125 static void
10126 c_parser_upc_sync_statement (c_parser *parser, int sync_kind)
10128 location_t loc;
10129 tree expr = NULL_TREE;
10130 tree stmt;
10131 gcc_assert (c_parser_next_token_is_keyword (parser, RID_UPC_BARRIER) ||
10132 c_parser_next_token_is_keyword (parser, RID_UPC_NOTIFY) ||
10133 c_parser_next_token_is_keyword (parser, RID_UPC_WAIT));
10134 loc = c_parser_peek_token (parser)->location;
10135 c_parser_consume_token (parser);
10136 if (c_parser_peek_token (parser)->type != CPP_SEMICOLON)
10138 loc = c_parser_peek_token (parser)->location;
10139 expr = c_parser_expression (parser).value;
10140 if (expr == error_mark_node)
10141 expr = NULL;
10143 stmt = size_int (sync_kind);
10144 (void) upc_build_sync_stmt (loc, stmt, expr);
10148 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10149 should be considered, statements. ALLOW_STMT is true if we're within
10150 the context of a function and such pragmas are to be allowed. Returns
10151 true if we actually parsed such a pragma. */
10153 static bool
10154 c_parser_pragma (c_parser *parser, enum pragma_context context)
10156 unsigned int id;
10158 id = c_parser_peek_token (parser)->pragma_kind;
10159 gcc_assert (id != PRAGMA_NONE);
10161 switch (id)
10163 case PRAGMA_OACC_ENTER_DATA:
10164 c_parser_oacc_enter_exit_data (parser, true);
10165 return false;
10167 case PRAGMA_OACC_EXIT_DATA:
10168 c_parser_oacc_enter_exit_data (parser, false);
10169 return false;
10171 case PRAGMA_OACC_UPDATE:
10172 if (context != pragma_compound)
10174 if (context == pragma_stmt)
10175 c_parser_error (parser, "%<#pragma acc update%> may only be "
10176 "used in compound statements");
10177 goto bad_stmt;
10179 c_parser_oacc_update (parser);
10180 return false;
10182 case PRAGMA_OMP_BARRIER:
10183 if (context != pragma_compound)
10185 if (context == pragma_stmt)
10186 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
10187 "used in compound statements");
10188 goto bad_stmt;
10190 c_parser_omp_barrier (parser);
10191 return false;
10193 case PRAGMA_OMP_FLUSH:
10194 if (context != pragma_compound)
10196 if (context == pragma_stmt)
10197 c_parser_error (parser, "%<#pragma omp flush%> may only be "
10198 "used in compound statements");
10199 goto bad_stmt;
10201 c_parser_omp_flush (parser);
10202 return false;
10204 case PRAGMA_OMP_TASKWAIT:
10205 if (context != pragma_compound)
10207 if (context == pragma_stmt)
10208 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
10209 "used in compound statements");
10210 goto bad_stmt;
10212 c_parser_omp_taskwait (parser);
10213 return false;
10215 case PRAGMA_OMP_TASKYIELD:
10216 if (context != pragma_compound)
10218 if (context == pragma_stmt)
10219 c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
10220 "used in compound statements");
10221 goto bad_stmt;
10223 c_parser_omp_taskyield (parser);
10224 return false;
10226 case PRAGMA_OMP_CANCEL:
10227 if (context != pragma_compound)
10229 if (context == pragma_stmt)
10230 c_parser_error (parser, "%<#pragma omp cancel%> may only be "
10231 "used in compound statements");
10232 goto bad_stmt;
10234 c_parser_omp_cancel (parser);
10235 return false;
10237 case PRAGMA_OMP_CANCELLATION_POINT:
10238 if (context != pragma_compound)
10240 if (context == pragma_stmt)
10241 c_parser_error (parser, "%<#pragma omp cancellation point%> may "
10242 "only be used in compound statements");
10243 goto bad_stmt;
10245 c_parser_omp_cancellation_point (parser);
10246 return false;
10248 case PRAGMA_OMP_THREADPRIVATE:
10249 c_parser_omp_threadprivate (parser);
10250 return false;
10252 case PRAGMA_OMP_TARGET:
10253 return c_parser_omp_target (parser, context);
10255 case PRAGMA_OMP_END_DECLARE_TARGET:
10256 c_parser_omp_end_declare_target (parser);
10257 return false;
10259 case PRAGMA_OMP_SECTION:
10260 error_at (c_parser_peek_token (parser)->location,
10261 "%<#pragma omp section%> may only be used in "
10262 "%<#pragma omp sections%> construct");
10263 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10264 return false;
10266 case PRAGMA_OMP_DECLARE_REDUCTION:
10267 c_parser_omp_declare (parser, context);
10268 return false;
10269 case PRAGMA_IVDEP:
10270 c_parser_consume_pragma (parser);
10271 c_parser_skip_to_pragma_eol (parser);
10272 if (!c_parser_next_token_is_keyword (parser, RID_FOR)
10273 && !c_parser_next_token_is_keyword (parser, RID_WHILE)
10274 && !c_parser_next_token_is_keyword (parser, RID_DO))
10276 c_parser_error (parser, "for, while or do statement expected");
10277 return false;
10279 if (c_parser_next_token_is_keyword (parser, RID_FOR))
10280 c_parser_for_statement (parser, true);
10281 else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
10282 c_parser_while_statement (parser, true);
10283 else
10284 c_parser_do_statement (parser, true);
10285 return false;
10287 case PRAGMA_GCC_PCH_PREPROCESS:
10288 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
10289 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10290 return false;
10292 case PRAGMA_CILK_SIMD:
10293 if (!c_parser_cilk_verify_simd (parser, context))
10294 return false;
10295 c_parser_consume_pragma (parser);
10296 c_parser_cilk_simd (parser);
10297 return false;
10298 case PRAGMA_CILK_GRAINSIZE:
10299 if (!flag_cilkplus)
10301 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10302 " enabled");
10303 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10304 return false;
10306 if (context == pragma_external)
10308 error_at (c_parser_peek_token (parser)->location,
10309 "%<#pragma grainsize%> must be inside a function");
10310 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10311 return false;
10313 c_parser_cilk_grainsize (parser);
10314 return false;
10316 default:
10317 if (id < PRAGMA_FIRST_EXTERNAL)
10319 if (context != pragma_stmt && context != pragma_compound)
10321 bad_stmt:
10322 c_parser_error (parser, "expected declaration specifiers");
10323 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10324 return false;
10326 c_parser_omp_construct (parser);
10327 return true;
10329 break;
10332 c_parser_consume_pragma (parser);
10333 c_invoke_pragma_handler (id);
10335 /* Skip to EOL, but suppress any error message. Those will have been
10336 generated by the handler routine through calling error, as opposed
10337 to calling c_parser_error. */
10338 parser->error = true;
10339 c_parser_skip_to_pragma_eol (parser);
10341 return false;
10344 /* The interface the pragma parsers have to the lexer. */
10346 enum cpp_ttype
10347 pragma_lex (tree *value)
10349 c_token *tok = c_parser_peek_token (the_parser);
10350 enum cpp_ttype ret = tok->type;
10352 *value = tok->value;
10353 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
10354 ret = CPP_EOF;
10355 else
10357 if (ret == CPP_KEYWORD)
10358 ret = CPP_NAME;
10359 c_parser_consume_token (the_parser);
10362 return ret;
10365 static void
10366 c_parser_pragma_pch_preprocess (c_parser *parser)
10368 tree name = NULL;
10370 c_parser_consume_pragma (parser);
10371 if (c_parser_next_token_is (parser, CPP_STRING))
10373 name = c_parser_peek_token (parser)->value;
10374 c_parser_consume_token (parser);
10376 else
10377 c_parser_error (parser, "expected string literal");
10378 c_parser_skip_to_pragma_eol (parser);
10380 if (name)
10381 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
10384 /* OpenACC and OpenMP parsing routines. */
10386 /* Returns name of the next clause.
10387 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10388 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10389 returned and the token is consumed. */
10391 static pragma_omp_clause
10392 c_parser_omp_clause_name (c_parser *parser)
10394 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
10396 if (c_parser_next_token_is_keyword (parser, RID_AUTO))
10397 result = PRAGMA_OACC_CLAUSE_AUTO;
10398 else if (c_parser_next_token_is_keyword (parser, RID_IF))
10399 result = PRAGMA_OMP_CLAUSE_IF;
10400 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
10401 result = PRAGMA_OMP_CLAUSE_DEFAULT;
10402 else if (c_parser_next_token_is_keyword (parser, RID_FOR))
10403 result = PRAGMA_OMP_CLAUSE_FOR;
10404 else if (c_parser_next_token_is (parser, CPP_NAME))
10406 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10408 switch (p[0])
10410 case 'a':
10411 if (!strcmp ("aligned", p))
10412 result = PRAGMA_OMP_CLAUSE_ALIGNED;
10413 else if (!strcmp ("async", p))
10414 result = PRAGMA_OACC_CLAUSE_ASYNC;
10415 break;
10416 case 'c':
10417 if (!strcmp ("collapse", p))
10418 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
10419 else if (!strcmp ("copy", p))
10420 result = PRAGMA_OACC_CLAUSE_COPY;
10421 else if (!strcmp ("copyin", p))
10422 result = PRAGMA_OMP_CLAUSE_COPYIN;
10423 else if (!strcmp ("copyout", p))
10424 result = PRAGMA_OACC_CLAUSE_COPYOUT;
10425 else if (!strcmp ("copyprivate", p))
10426 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
10427 else if (!strcmp ("create", p))
10428 result = PRAGMA_OACC_CLAUSE_CREATE;
10429 break;
10430 case 'd':
10431 if (!strcmp ("delete", p))
10432 result = PRAGMA_OACC_CLAUSE_DELETE;
10433 else if (!strcmp ("depend", p))
10434 result = PRAGMA_OMP_CLAUSE_DEPEND;
10435 else if (!strcmp ("device", p))
10436 result = PRAGMA_OMP_CLAUSE_DEVICE;
10437 else if (!strcmp ("deviceptr", p))
10438 result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
10439 else if (!strcmp ("dist_schedule", p))
10440 result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
10441 break;
10442 case 'f':
10443 if (!strcmp ("final", p))
10444 result = PRAGMA_OMP_CLAUSE_FINAL;
10445 else if (!strcmp ("firstprivate", p))
10446 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
10447 else if (!strcmp ("from", p))
10448 result = PRAGMA_OMP_CLAUSE_FROM;
10449 break;
10450 case 'g':
10451 if (!strcmp ("gang", p))
10452 result = PRAGMA_OACC_CLAUSE_GANG;
10453 break;
10454 case 'h':
10455 if (!strcmp ("host", p))
10456 result = PRAGMA_OACC_CLAUSE_HOST;
10457 break;
10458 case 'i':
10459 if (!strcmp ("inbranch", p))
10460 result = PRAGMA_OMP_CLAUSE_INBRANCH;
10461 break;
10462 case 'l':
10463 if (!strcmp ("lastprivate", p))
10464 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
10465 else if (!strcmp ("linear", p))
10466 result = PRAGMA_OMP_CLAUSE_LINEAR;
10467 break;
10468 case 'm':
10469 if (!strcmp ("map", p))
10470 result = PRAGMA_OMP_CLAUSE_MAP;
10471 else if (!strcmp ("mergeable", p))
10472 result = PRAGMA_OMP_CLAUSE_MERGEABLE;
10473 else if (flag_cilkplus && !strcmp ("mask", p))
10474 result = PRAGMA_CILK_CLAUSE_MASK;
10475 break;
10476 case 'n':
10477 if (!strcmp ("notinbranch", p))
10478 result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
10479 else if (!strcmp ("nowait", p))
10480 result = PRAGMA_OMP_CLAUSE_NOWAIT;
10481 else if (!strcmp ("num_gangs", p))
10482 result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
10483 else if (!strcmp ("num_teams", p))
10484 result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
10485 else if (!strcmp ("num_threads", p))
10486 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
10487 else if (!strcmp ("num_workers", p))
10488 result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
10489 else if (flag_cilkplus && !strcmp ("nomask", p))
10490 result = PRAGMA_CILK_CLAUSE_NOMASK;
10491 break;
10492 case 'o':
10493 if (!strcmp ("ordered", p))
10494 result = PRAGMA_OMP_CLAUSE_ORDERED;
10495 break;
10496 case 'p':
10497 if (!strcmp ("parallel", p))
10498 result = PRAGMA_OMP_CLAUSE_PARALLEL;
10499 else if (!strcmp ("present", p))
10500 result = PRAGMA_OACC_CLAUSE_PRESENT;
10501 else if (!strcmp ("present_or_copy", p)
10502 || !strcmp ("pcopy", p))
10503 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
10504 else if (!strcmp ("present_or_copyin", p)
10505 || !strcmp ("pcopyin", p))
10506 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
10507 else if (!strcmp ("present_or_copyout", p)
10508 || !strcmp ("pcopyout", p))
10509 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
10510 else if (!strcmp ("present_or_create", p)
10511 || !strcmp ("pcreate", p))
10512 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
10513 else if (!strcmp ("private", p))
10514 result = PRAGMA_OMP_CLAUSE_PRIVATE;
10515 else if (!strcmp ("proc_bind", p))
10516 result = PRAGMA_OMP_CLAUSE_PROC_BIND;
10517 break;
10518 case 'r':
10519 if (!strcmp ("reduction", p))
10520 result = PRAGMA_OMP_CLAUSE_REDUCTION;
10521 break;
10522 case 's':
10523 if (!strcmp ("safelen", p))
10524 result = PRAGMA_OMP_CLAUSE_SAFELEN;
10525 else if (!strcmp ("schedule", p))
10526 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
10527 else if (!strcmp ("sections", p))
10528 result = PRAGMA_OMP_CLAUSE_SECTIONS;
10529 else if (!strcmp ("seq", p))
10530 result = PRAGMA_OACC_CLAUSE_SEQ;
10531 else if (!strcmp ("shared", p))
10532 result = PRAGMA_OMP_CLAUSE_SHARED;
10533 else if (!strcmp ("simdlen", p))
10534 result = PRAGMA_OMP_CLAUSE_SIMDLEN;
10535 else if (!strcmp ("self", p))
10536 result = PRAGMA_OACC_CLAUSE_SELF;
10537 break;
10538 case 't':
10539 if (!strcmp ("taskgroup", p))
10540 result = PRAGMA_OMP_CLAUSE_TASKGROUP;
10541 else if (!strcmp ("thread_limit", p))
10542 result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
10543 else if (!strcmp ("to", p))
10544 result = PRAGMA_OMP_CLAUSE_TO;
10545 break;
10546 case 'u':
10547 if (!strcmp ("uniform", p))
10548 result = PRAGMA_OMP_CLAUSE_UNIFORM;
10549 else if (!strcmp ("untied", p))
10550 result = PRAGMA_OMP_CLAUSE_UNTIED;
10551 break;
10552 case 'v':
10553 if (!strcmp ("vector", p))
10554 result = PRAGMA_OACC_CLAUSE_VECTOR;
10555 else if (!strcmp ("vector_length", p))
10556 result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
10557 else if (flag_cilkplus && !strcmp ("vectorlength", p))
10558 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
10559 break;
10560 case 'w':
10561 if (!strcmp ("wait", p))
10562 result = PRAGMA_OACC_CLAUSE_WAIT;
10563 else if (!strcmp ("worker", p))
10564 result = PRAGMA_OACC_CLAUSE_WORKER;
10565 break;
10569 if (result != PRAGMA_OMP_CLAUSE_NONE)
10570 c_parser_consume_token (parser);
10572 return result;
10575 /* Validate that a clause of the given type does not already exist. */
10577 static void
10578 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
10579 const char *name)
10581 tree c;
10583 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
10584 if (OMP_CLAUSE_CODE (c) == code)
10586 location_t loc = OMP_CLAUSE_LOCATION (c);
10587 error_at (loc, "too many %qs clauses", name);
10588 break;
10592 /* OpenACC 2.0
10593 Parse wait clause or wait directive parameters. */
10595 static tree
10596 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
10598 vec<tree, va_gc> *args;
10599 tree t, args_tree;
10601 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10602 return list;
10604 args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
10606 if (args->length () == 0)
10608 c_parser_error (parser, "expected integer expression before ')'");
10609 release_tree_vector (args);
10610 return list;
10613 args_tree = build_tree_list_vec (args);
10615 for (t = args_tree; t; t = TREE_CHAIN (t))
10617 tree targ = TREE_VALUE (t);
10619 if (targ != error_mark_node)
10621 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
10623 c_parser_error (parser, "expression must be integral");
10624 targ = error_mark_node;
10626 else
10628 tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
10630 OMP_CLAUSE_DECL (c) = targ;
10631 OMP_CLAUSE_CHAIN (c) = list;
10632 list = c;
10637 release_tree_vector (args);
10638 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10639 return list;
10642 /* OpenACC 2.0, OpenMP 2.5:
10643 variable-list:
10644 identifier
10645 variable-list , identifier
10647 If KIND is nonzero, create the appropriate node and install the
10648 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10649 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10651 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10652 return the list created. */
10654 static tree
10655 c_parser_omp_variable_list (c_parser *parser,
10656 location_t clause_loc,
10657 enum omp_clause_code kind, tree list)
10659 if (c_parser_next_token_is_not (parser, CPP_NAME)
10660 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
10661 c_parser_error (parser, "expected identifier");
10663 while (c_parser_next_token_is (parser, CPP_NAME)
10664 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
10666 tree t = lookup_name (c_parser_peek_token (parser)->value);
10668 if (t == NULL_TREE)
10670 undeclared_variable (c_parser_peek_token (parser)->location,
10671 c_parser_peek_token (parser)->value);
10672 t = error_mark_node;
10675 c_parser_consume_token (parser);
10677 if (t == error_mark_node)
10679 else if (kind != 0)
10681 switch (kind)
10683 case OMP_CLAUSE__CACHE_:
10684 if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
10686 c_parser_error (parser, "expected %<[%>");
10687 t = error_mark_node;
10688 break;
10690 /* FALL THROUGH. */
10691 case OMP_CLAUSE_MAP:
10692 case OMP_CLAUSE_FROM:
10693 case OMP_CLAUSE_TO:
10694 case OMP_CLAUSE_DEPEND:
10695 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
10697 tree low_bound = NULL_TREE, length = NULL_TREE;
10699 c_parser_consume_token (parser);
10700 if (!c_parser_next_token_is (parser, CPP_COLON))
10702 low_bound = c_parser_expression (parser).value;
10703 mark_exp_read (low_bound);
10705 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10706 length = integer_one_node;
10707 else
10709 /* Look for `:'. */
10710 if (!c_parser_require (parser, CPP_COLON,
10711 "expected %<:%>"))
10713 t = error_mark_node;
10714 break;
10716 if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10718 length = c_parser_expression (parser).value;
10719 mark_exp_read (length);
10722 /* Look for the closing `]'. */
10723 if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
10724 "expected %<]%>"))
10726 t = error_mark_node;
10727 break;
10730 if (kind == OMP_CLAUSE__CACHE_)
10732 if (TREE_CODE (low_bound) != INTEGER_CST
10733 && !TREE_READONLY (low_bound))
10735 error_at (clause_loc,
10736 "%qD is not a constant", low_bound);
10737 t = error_mark_node;
10740 if (TREE_CODE (length) != INTEGER_CST
10741 && !TREE_READONLY (length))
10743 error_at (clause_loc,
10744 "%qD is not a constant", length);
10745 t = error_mark_node;
10749 t = tree_cons (low_bound, length, t);
10751 break;
10752 default:
10753 break;
10756 if (t != error_mark_node)
10758 tree u = build_omp_clause (clause_loc, kind);
10759 OMP_CLAUSE_DECL (u) = t;
10760 OMP_CLAUSE_CHAIN (u) = list;
10761 list = u;
10764 else
10765 list = tree_cons (t, NULL_TREE, list);
10767 if (c_parser_next_token_is_not (parser, CPP_COMMA))
10768 break;
10770 c_parser_consume_token (parser);
10773 return list;
10776 /* Similarly, but expect leading and trailing parenthesis. This is a very
10777 common case for OpenACC and OpenMP clauses. */
10779 static tree
10780 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
10781 tree list)
10783 /* The clauses location. */
10784 location_t loc = c_parser_peek_token (parser)->location;
10786 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10788 list = c_parser_omp_variable_list (parser, loc, kind, list);
10789 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10791 return list;
10794 /* OpenACC 2.0:
10795 copy ( variable-list )
10796 copyin ( variable-list )
10797 copyout ( variable-list )
10798 create ( variable-list )
10799 delete ( variable-list )
10800 present ( variable-list )
10801 present_or_copy ( variable-list )
10802 pcopy ( variable-list )
10803 present_or_copyin ( variable-list )
10804 pcopyin ( variable-list )
10805 present_or_copyout ( variable-list )
10806 pcopyout ( variable-list )
10807 present_or_create ( variable-list )
10808 pcreate ( variable-list ) */
10810 static tree
10811 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
10812 tree list)
10814 enum gomp_map_kind kind;
10815 switch (c_kind)
10817 case PRAGMA_OACC_CLAUSE_COPY:
10818 kind = GOMP_MAP_FORCE_TOFROM;
10819 break;
10820 case PRAGMA_OACC_CLAUSE_COPYIN:
10821 kind = GOMP_MAP_FORCE_TO;
10822 break;
10823 case PRAGMA_OACC_CLAUSE_COPYOUT:
10824 kind = GOMP_MAP_FORCE_FROM;
10825 break;
10826 case PRAGMA_OACC_CLAUSE_CREATE:
10827 kind = GOMP_MAP_FORCE_ALLOC;
10828 break;
10829 case PRAGMA_OACC_CLAUSE_DELETE:
10830 kind = GOMP_MAP_FORCE_DEALLOC;
10831 break;
10832 case PRAGMA_OACC_CLAUSE_DEVICE:
10833 kind = GOMP_MAP_FORCE_TO;
10834 break;
10835 case PRAGMA_OACC_CLAUSE_HOST:
10836 case PRAGMA_OACC_CLAUSE_SELF:
10837 kind = GOMP_MAP_FORCE_FROM;
10838 break;
10839 case PRAGMA_OACC_CLAUSE_PRESENT:
10840 kind = GOMP_MAP_FORCE_PRESENT;
10841 break;
10842 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
10843 kind = GOMP_MAP_TOFROM;
10844 break;
10845 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
10846 kind = GOMP_MAP_TO;
10847 break;
10848 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
10849 kind = GOMP_MAP_FROM;
10850 break;
10851 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
10852 kind = GOMP_MAP_ALLOC;
10853 break;
10854 default:
10855 gcc_unreachable ();
10857 tree nl, c;
10858 nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
10860 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10861 OMP_CLAUSE_SET_MAP_KIND (c, kind);
10863 return nl;
10866 /* OpenACC 2.0:
10867 deviceptr ( variable-list ) */
10869 static tree
10870 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
10872 location_t loc = c_parser_peek_token (parser)->location;
10873 tree vars, t;
10875 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10876 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10877 variable-list must only allow for pointer variables. */
10878 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10879 for (t = vars; t && t; t = TREE_CHAIN (t))
10881 tree v = TREE_PURPOSE (t);
10883 /* FIXME diagnostics: Ideally we should keep individual
10884 locations for all the variables in the var list to make the
10885 following errors more precise. Perhaps
10886 c_parser_omp_var_list_parens() should construct a list of
10887 locations to go along with the var list. */
10889 if (TREE_CODE (v) != VAR_DECL)
10890 error_at (loc, "%qD is not a variable", v);
10891 else if (TREE_TYPE (v) == error_mark_node)
10893 else if (!POINTER_TYPE_P (TREE_TYPE (v)))
10894 error_at (loc, "%qD is not a pointer variable", v);
10896 tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
10897 OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
10898 OMP_CLAUSE_DECL (u) = v;
10899 OMP_CLAUSE_CHAIN (u) = list;
10900 list = u;
10903 return list;
10906 /* OpenACC 2.0, OpenMP 3.0:
10907 collapse ( constant-expression ) */
10909 static tree
10910 c_parser_omp_clause_collapse (c_parser *parser, tree list)
10912 tree c, num = error_mark_node;
10913 HOST_WIDE_INT n;
10914 location_t loc;
10916 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
10918 loc = c_parser_peek_token (parser)->location;
10919 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10921 num = c_parser_expr_no_commas (parser, NULL).value;
10922 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10924 if (num == error_mark_node)
10925 return list;
10926 mark_exp_read (num);
10927 num = c_fully_fold (num, false, NULL);
10928 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
10929 || !tree_fits_shwi_p (num)
10930 || (n = tree_to_shwi (num)) <= 0
10931 || (int) n != n)
10933 error_at (loc,
10934 "collapse argument needs positive constant integer expression");
10935 return list;
10937 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
10938 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
10939 OMP_CLAUSE_CHAIN (c) = list;
10940 return c;
10943 /* OpenMP 2.5:
10944 copyin ( variable-list ) */
10946 static tree
10947 c_parser_omp_clause_copyin (c_parser *parser, tree list)
10949 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
10952 /* OpenMP 2.5:
10953 copyprivate ( variable-list ) */
10955 static tree
10956 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
10958 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
10961 /* OpenMP 2.5:
10962 default ( shared | none ) */
10964 static tree
10965 c_parser_omp_clause_default (c_parser *parser, tree list)
10967 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
10968 location_t loc = c_parser_peek_token (parser)->location;
10969 tree c;
10971 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10972 return list;
10973 if (c_parser_next_token_is (parser, CPP_NAME))
10975 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10977 switch (p[0])
10979 case 'n':
10980 if (strcmp ("none", p) != 0)
10981 goto invalid_kind;
10982 kind = OMP_CLAUSE_DEFAULT_NONE;
10983 break;
10985 case 's':
10986 if (strcmp ("shared", p) != 0)
10987 goto invalid_kind;
10988 kind = OMP_CLAUSE_DEFAULT_SHARED;
10989 break;
10991 default:
10992 goto invalid_kind;
10995 c_parser_consume_token (parser);
10997 else
10999 invalid_kind:
11000 c_parser_error (parser, "expected %<none%> or %<shared%>");
11002 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11004 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
11005 return list;
11007 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
11008 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
11009 OMP_CLAUSE_CHAIN (c) = list;
11010 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
11012 return c;
11015 /* OpenMP 2.5:
11016 firstprivate ( variable-list ) */
11018 static tree
11019 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
11021 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
11024 /* OpenMP 3.1:
11025 final ( expression ) */
11027 static tree
11028 c_parser_omp_clause_final (c_parser *parser, tree list)
11030 location_t loc = c_parser_peek_token (parser)->location;
11031 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11033 tree t = c_parser_paren_condition (parser);
11034 tree c;
11036 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
11038 c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
11039 OMP_CLAUSE_FINAL_EXPR (c) = t;
11040 OMP_CLAUSE_CHAIN (c) = list;
11041 list = c;
11043 else
11044 c_parser_error (parser, "expected %<(%>");
11046 return list;
11049 /* OpenACC, OpenMP 2.5:
11050 if ( expression ) */
11052 static tree
11053 c_parser_omp_clause_if (c_parser *parser, tree list)
11055 location_t loc = c_parser_peek_token (parser)->location;
11056 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11058 tree t = c_parser_paren_condition (parser);
11059 tree c;
11061 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
11063 c = build_omp_clause (loc, OMP_CLAUSE_IF);
11064 OMP_CLAUSE_IF_EXPR (c) = t;
11065 OMP_CLAUSE_CHAIN (c) = list;
11066 list = c;
11068 else
11069 c_parser_error (parser, "expected %<(%>");
11071 return list;
11074 /* OpenMP 2.5:
11075 lastprivate ( variable-list ) */
11077 static tree
11078 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
11080 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
11083 /* OpenMP 3.1:
11084 mergeable */
11086 static tree
11087 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
11089 tree c;
11091 /* FIXME: Should we allow duplicates? */
11092 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
11094 c = build_omp_clause (c_parser_peek_token (parser)->location,
11095 OMP_CLAUSE_MERGEABLE);
11096 OMP_CLAUSE_CHAIN (c) = list;
11098 return c;
11101 /* OpenMP 2.5:
11102 nowait */
11104 static tree
11105 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
11107 tree c;
11108 location_t loc = c_parser_peek_token (parser)->location;
11110 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
11112 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
11113 OMP_CLAUSE_CHAIN (c) = list;
11114 return c;
11117 /* OpenACC:
11118 num_gangs ( expression ) */
11120 static tree
11121 c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
11123 location_t num_gangs_loc = c_parser_peek_token (parser)->location;
11124 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11126 location_t expr_loc = c_parser_peek_token (parser)->location;
11127 tree c, t = c_parser_expression (parser).value;
11128 mark_exp_read (t);
11129 t = c_fully_fold (t, false, NULL);
11131 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11133 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11135 c_parser_error (parser, "expected integer expression");
11136 return list;
11139 /* Attempt to statically determine when the number isn't positive. */
11140 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11141 build_int_cst (TREE_TYPE (t), 0));
11142 if (CAN_HAVE_LOCATION_P (c))
11143 SET_EXPR_LOCATION (c, expr_loc);
11144 if (c == boolean_true_node)
11146 warning_at (expr_loc, 0,
11147 "%<num_gangs%> value must be positive");
11148 t = integer_one_node;
11151 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
11153 c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
11154 OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
11155 OMP_CLAUSE_CHAIN (c) = list;
11156 list = c;
11159 return list;
11162 /* OpenMP 2.5:
11163 num_threads ( expression ) */
11165 static tree
11166 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
11168 location_t num_threads_loc = c_parser_peek_token (parser)->location;
11169 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11171 location_t expr_loc = c_parser_peek_token (parser)->location;
11172 tree c, t = c_parser_expression (parser).value;
11173 mark_exp_read (t);
11174 t = c_fully_fold (t, false, NULL);
11176 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11178 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11180 c_parser_error (parser, "expected integer expression");
11181 return list;
11184 /* Attempt to statically determine when the number isn't positive. */
11185 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11186 build_int_cst (TREE_TYPE (t), 0));
11187 if (CAN_HAVE_LOCATION_P (c))
11188 SET_EXPR_LOCATION (c, expr_loc);
11189 if (c == boolean_true_node)
11191 warning_at (expr_loc, 0,
11192 "%<num_threads%> value must be positive");
11193 t = integer_one_node;
11196 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
11198 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
11199 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
11200 OMP_CLAUSE_CHAIN (c) = list;
11201 list = c;
11204 return list;
11207 /* OpenACC:
11208 num_workers ( expression ) */
11210 static tree
11211 c_parser_omp_clause_num_workers (c_parser *parser, tree list)
11213 location_t num_workers_loc = c_parser_peek_token (parser)->location;
11214 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11216 location_t expr_loc = c_parser_peek_token (parser)->location;
11217 tree c, t = c_parser_expression (parser).value;
11218 mark_exp_read (t);
11219 t = c_fully_fold (t, false, NULL);
11221 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11223 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11225 c_parser_error (parser, "expected integer expression");
11226 return list;
11229 /* Attempt to statically determine when the number isn't positive. */
11230 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11231 build_int_cst (TREE_TYPE (t), 0));
11232 if (CAN_HAVE_LOCATION_P (c))
11233 SET_EXPR_LOCATION (c, expr_loc);
11234 if (c == boolean_true_node)
11236 warning_at (expr_loc, 0,
11237 "%<num_workers%> value must be positive");
11238 t = integer_one_node;
11241 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
11243 c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
11244 OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
11245 OMP_CLAUSE_CHAIN (c) = list;
11246 list = c;
11249 return list;
11252 /* OpenACC:
11253 async [( int-expr )] */
11255 static tree
11256 c_parser_oacc_clause_async (c_parser *parser, tree list)
11258 tree c, t;
11259 location_t loc = c_parser_peek_token (parser)->location;
11261 t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
11263 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
11265 c_parser_consume_token (parser);
11267 t = c_parser_expression (parser).value;
11268 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11269 c_parser_error (parser, "expected integer expression");
11270 else if (t == error_mark_node
11271 || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
11272 return list;
11274 else
11275 t = c_fully_fold (t, false, NULL);
11277 check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
11279 c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
11280 OMP_CLAUSE_ASYNC_EXPR (c) = t;
11281 OMP_CLAUSE_CHAIN (c) = list;
11282 list = c;
11284 return list;
11287 /* OpenACC:
11288 wait ( int-expr-list ) */
11290 static tree
11291 c_parser_oacc_clause_wait (c_parser *parser, tree list)
11293 location_t clause_loc = c_parser_peek_token (parser)->location;
11295 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
11296 list = c_parser_oacc_wait_list (parser, clause_loc, list);
11298 return list;
11301 /* OpenMP 2.5:
11302 ordered */
11304 static tree
11305 c_parser_omp_clause_ordered (c_parser *parser, tree list)
11307 tree c;
11309 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
11311 c = build_omp_clause (c_parser_peek_token (parser)->location,
11312 OMP_CLAUSE_ORDERED);
11313 OMP_CLAUSE_CHAIN (c) = list;
11315 return c;
11318 /* OpenMP 2.5:
11319 private ( variable-list ) */
11321 static tree
11322 c_parser_omp_clause_private (c_parser *parser, tree list)
11324 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
11327 /* OpenMP 2.5:
11328 reduction ( reduction-operator : variable-list )
11330 reduction-operator:
11331 One of: + * - & ^ | && ||
11333 OpenMP 3.1:
11335 reduction-operator:
11336 One of: + * - & ^ | && || max min
11338 OpenMP 4.0:
11340 reduction-operator:
11341 One of: + * - & ^ | && ||
11342 identifier */
11344 static tree
11345 c_parser_omp_clause_reduction (c_parser *parser, tree list)
11347 location_t clause_loc = c_parser_peek_token (parser)->location;
11348 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11350 enum tree_code code = ERROR_MARK;
11351 tree reduc_id = NULL_TREE;
11353 switch (c_parser_peek_token (parser)->type)
11355 case CPP_PLUS:
11356 code = PLUS_EXPR;
11357 break;
11358 case CPP_MULT:
11359 code = MULT_EXPR;
11360 break;
11361 case CPP_MINUS:
11362 code = MINUS_EXPR;
11363 break;
11364 case CPP_AND:
11365 code = BIT_AND_EXPR;
11366 break;
11367 case CPP_XOR:
11368 code = BIT_XOR_EXPR;
11369 break;
11370 case CPP_OR:
11371 code = BIT_IOR_EXPR;
11372 break;
11373 case CPP_AND_AND:
11374 code = TRUTH_ANDIF_EXPR;
11375 break;
11376 case CPP_OR_OR:
11377 code = TRUTH_ORIF_EXPR;
11378 break;
11379 case CPP_NAME:
11381 const char *p
11382 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11383 if (strcmp (p, "min") == 0)
11385 code = MIN_EXPR;
11386 break;
11388 if (strcmp (p, "max") == 0)
11390 code = MAX_EXPR;
11391 break;
11393 reduc_id = c_parser_peek_token (parser)->value;
11394 break;
11396 default:
11397 c_parser_error (parser,
11398 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
11399 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
11400 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
11401 return list;
11403 c_parser_consume_token (parser);
11404 reduc_id = c_omp_reduction_id (code, reduc_id);
11405 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11407 tree nl, c;
11409 nl = c_parser_omp_variable_list (parser, clause_loc,
11410 OMP_CLAUSE_REDUCTION, list);
11411 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11413 tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
11414 OMP_CLAUSE_REDUCTION_CODE (c) = code;
11415 if (code == ERROR_MARK
11416 || !(INTEGRAL_TYPE_P (type)
11417 || TREE_CODE (type) == REAL_TYPE
11418 || TREE_CODE (type) == COMPLEX_TYPE))
11419 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
11420 = c_omp_reduction_lookup (reduc_id,
11421 TYPE_MAIN_VARIANT (type));
11424 list = nl;
11426 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11428 return list;
11431 /* OpenMP 2.5:
11432 schedule ( schedule-kind )
11433 schedule ( schedule-kind , expression )
11435 schedule-kind:
11436 static | dynamic | guided | runtime | auto
11439 static tree
11440 c_parser_omp_clause_schedule (c_parser *parser, tree list)
11442 tree c, t;
11443 location_t loc = c_parser_peek_token (parser)->location;
11445 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11446 return list;
11448 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
11450 if (c_parser_next_token_is (parser, CPP_NAME))
11452 tree kind = c_parser_peek_token (parser)->value;
11453 const char *p = IDENTIFIER_POINTER (kind);
11455 switch (p[0])
11457 case 'd':
11458 if (strcmp ("dynamic", p) != 0)
11459 goto invalid_kind;
11460 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
11461 break;
11463 case 'g':
11464 if (strcmp ("guided", p) != 0)
11465 goto invalid_kind;
11466 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
11467 break;
11469 case 'r':
11470 if (strcmp ("runtime", p) != 0)
11471 goto invalid_kind;
11472 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
11473 break;
11475 default:
11476 goto invalid_kind;
11479 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
11480 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
11481 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
11482 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
11483 else
11484 goto invalid_kind;
11486 c_parser_consume_token (parser);
11487 if (c_parser_next_token_is (parser, CPP_COMMA))
11489 location_t here;
11490 c_parser_consume_token (parser);
11492 here = c_parser_peek_token (parser)->location;
11493 t = c_parser_expr_no_commas (parser, NULL).value;
11494 mark_exp_read (t);
11495 t = c_fully_fold (t, false, NULL);
11497 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
11498 error_at (here, "schedule %<runtime%> does not take "
11499 "a %<chunk_size%> parameter");
11500 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
11501 error_at (here,
11502 "schedule %<auto%> does not take "
11503 "a %<chunk_size%> parameter");
11504 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
11505 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
11506 else
11507 c_parser_error (parser, "expected integer expression");
11509 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11511 else
11512 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11513 "expected %<,%> or %<)%>");
11515 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
11516 OMP_CLAUSE_CHAIN (c) = list;
11517 return c;
11519 invalid_kind:
11520 c_parser_error (parser, "invalid schedule kind");
11521 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
11522 return list;
11525 /* OpenMP 2.5:
11526 shared ( variable-list ) */
11528 static tree
11529 c_parser_omp_clause_shared (c_parser *parser, tree list)
11531 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
11534 /* OpenMP 3.0:
11535 untied */
11537 static tree
11538 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
11540 tree c;
11542 /* FIXME: Should we allow duplicates? */
11543 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
11545 c = build_omp_clause (c_parser_peek_token (parser)->location,
11546 OMP_CLAUSE_UNTIED);
11547 OMP_CLAUSE_CHAIN (c) = list;
11549 return c;
11552 /* OpenACC:
11553 vector_length ( expression ) */
11555 static tree
11556 c_parser_omp_clause_vector_length (c_parser *parser, tree list)
11558 location_t vector_length_loc = c_parser_peek_token (parser)->location;
11559 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11561 location_t expr_loc = c_parser_peek_token (parser)->location;
11562 tree c, t = c_parser_expression (parser).value;
11563 mark_exp_read (t);
11564 t = c_fully_fold (t, false, NULL);
11566 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11568 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11570 c_parser_error (parser, "expected integer expression");
11571 return list;
11574 /* Attempt to statically determine when the number isn't positive. */
11575 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11576 build_int_cst (TREE_TYPE (t), 0));
11577 if (CAN_HAVE_LOCATION_P (c))
11578 SET_EXPR_LOCATION (c, expr_loc);
11579 if (c == boolean_true_node)
11581 warning_at (expr_loc, 0,
11582 "%<vector_length%> value must be positive");
11583 t = integer_one_node;
11586 check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
11588 c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
11589 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
11590 OMP_CLAUSE_CHAIN (c) = list;
11591 list = c;
11594 return list;
11597 /* OpenMP 4.0:
11598 inbranch
11599 notinbranch */
11601 static tree
11602 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
11603 enum omp_clause_code code, tree list)
11605 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11607 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11608 OMP_CLAUSE_CHAIN (c) = list;
11610 return c;
11613 /* OpenMP 4.0:
11614 parallel
11616 sections
11617 taskgroup */
11619 static tree
11620 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
11621 enum omp_clause_code code, tree list)
11623 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11624 OMP_CLAUSE_CHAIN (c) = list;
11626 return c;
11629 /* OpenMP 4.0:
11630 num_teams ( expression ) */
11632 static tree
11633 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
11635 location_t num_teams_loc = c_parser_peek_token (parser)->location;
11636 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11638 location_t expr_loc = c_parser_peek_token (parser)->location;
11639 tree c, t = c_parser_expression (parser).value;
11640 mark_exp_read (t);
11641 t = c_fully_fold (t, false, NULL);
11643 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11645 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11647 c_parser_error (parser, "expected integer expression");
11648 return list;
11651 /* Attempt to statically determine when the number isn't positive. */
11652 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11653 build_int_cst (TREE_TYPE (t), 0));
11654 if (CAN_HAVE_LOCATION_P (c))
11655 SET_EXPR_LOCATION (c, expr_loc);
11656 if (c == boolean_true_node)
11658 warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
11659 t = integer_one_node;
11662 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
11664 c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
11665 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
11666 OMP_CLAUSE_CHAIN (c) = list;
11667 list = c;
11670 return list;
11673 /* OpenMP 4.0:
11674 thread_limit ( expression ) */
11676 static tree
11677 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
11679 location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
11680 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11682 location_t expr_loc = c_parser_peek_token (parser)->location;
11683 tree c, t = c_parser_expression (parser).value;
11684 mark_exp_read (t);
11685 t = c_fully_fold (t, false, NULL);
11687 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11689 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11691 c_parser_error (parser, "expected integer expression");
11692 return list;
11695 /* Attempt to statically determine when the number isn't positive. */
11696 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11697 build_int_cst (TREE_TYPE (t), 0));
11698 if (CAN_HAVE_LOCATION_P (c))
11699 SET_EXPR_LOCATION (c, expr_loc);
11700 if (c == boolean_true_node)
11702 warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
11703 t = integer_one_node;
11706 check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
11707 "thread_limit");
11709 c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
11710 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
11711 OMP_CLAUSE_CHAIN (c) = list;
11712 list = c;
11715 return list;
11718 /* OpenMP 4.0:
11719 aligned ( variable-list )
11720 aligned ( variable-list : constant-expression ) */
11722 static tree
11723 c_parser_omp_clause_aligned (c_parser *parser, tree list)
11725 location_t clause_loc = c_parser_peek_token (parser)->location;
11726 tree nl, c;
11728 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11729 return list;
11731 nl = c_parser_omp_variable_list (parser, clause_loc,
11732 OMP_CLAUSE_ALIGNED, list);
11734 if (c_parser_next_token_is (parser, CPP_COLON))
11736 c_parser_consume_token (parser);
11737 tree alignment = c_parser_expr_no_commas (parser, NULL).value;
11738 mark_exp_read (alignment);
11739 alignment = c_fully_fold (alignment, false, NULL);
11740 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment))
11741 && TREE_CODE (alignment) != INTEGER_CST
11742 && tree_int_cst_sgn (alignment) != 1)
11744 error_at (clause_loc, "%<aligned%> clause alignment expression must "
11745 "be positive constant integer expression");
11746 alignment = NULL_TREE;
11749 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11750 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
11753 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11754 return nl;
11757 /* OpenMP 4.0:
11758 linear ( variable-list )
11759 linear ( variable-list : expression ) */
11761 static tree
11762 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn)
11764 location_t clause_loc = c_parser_peek_token (parser)->location;
11765 tree nl, c, step;
11767 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11768 return list;
11770 nl = c_parser_omp_variable_list (parser, clause_loc,
11771 OMP_CLAUSE_LINEAR, list);
11773 if (c_parser_next_token_is (parser, CPP_COLON))
11775 c_parser_consume_token (parser);
11776 step = c_parser_expression (parser).value;
11777 mark_exp_read (step);
11778 step = c_fully_fold (step, false, NULL);
11779 if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL)
11781 sorry ("using parameters for %<linear%> step is not supported yet");
11782 step = integer_one_node;
11784 if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
11786 error_at (clause_loc, "%<linear%> clause step expression must "
11787 "be integral");
11788 step = integer_one_node;
11792 else
11793 step = integer_one_node;
11795 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11797 OMP_CLAUSE_LINEAR_STEP (c) = step;
11800 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11801 return nl;
11804 /* OpenMP 4.0:
11805 safelen ( constant-expression ) */
11807 static tree
11808 c_parser_omp_clause_safelen (c_parser *parser, tree list)
11810 location_t clause_loc = c_parser_peek_token (parser)->location;
11811 tree c, t;
11813 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11814 return list;
11816 t = c_parser_expr_no_commas (parser, NULL).value;
11817 mark_exp_read (t);
11818 t = c_fully_fold (t, false, NULL);
11819 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
11820 && TREE_CODE (t) != INTEGER_CST
11821 && tree_int_cst_sgn (t) != 1)
11823 error_at (clause_loc, "%<safelen%> clause expression must "
11824 "be positive constant integer expression");
11825 t = NULL_TREE;
11828 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11829 if (t == NULL_TREE || t == error_mark_node)
11830 return list;
11832 check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
11834 c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
11835 OMP_CLAUSE_SAFELEN_EXPR (c) = t;
11836 OMP_CLAUSE_CHAIN (c) = list;
11837 return c;
11840 /* OpenMP 4.0:
11841 simdlen ( constant-expression ) */
11843 static tree
11844 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
11846 location_t clause_loc = c_parser_peek_token (parser)->location;
11847 tree c, t;
11849 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11850 return list;
11852 t = c_parser_expr_no_commas (parser, NULL).value;
11853 mark_exp_read (t);
11854 t = c_fully_fold (t, false, NULL);
11855 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
11856 && TREE_CODE (t) != INTEGER_CST
11857 && tree_int_cst_sgn (t) != 1)
11859 error_at (clause_loc, "%<simdlen%> clause expression must "
11860 "be positive constant integer expression");
11861 t = NULL_TREE;
11864 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11865 if (t == NULL_TREE || t == error_mark_node)
11866 return list;
11868 check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
11870 c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
11871 OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
11872 OMP_CLAUSE_CHAIN (c) = list;
11873 return c;
11876 /* OpenMP 4.0:
11877 depend ( depend-kind: variable-list )
11879 depend-kind:
11880 in | out | inout */
11882 static tree
11883 c_parser_omp_clause_depend (c_parser *parser, tree list)
11885 location_t clause_loc = c_parser_peek_token (parser)->location;
11886 enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
11887 tree nl, c;
11889 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11890 return list;
11892 if (c_parser_next_token_is (parser, CPP_NAME))
11894 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11895 if (strcmp ("in", p) == 0)
11896 kind = OMP_CLAUSE_DEPEND_IN;
11897 else if (strcmp ("inout", p) == 0)
11898 kind = OMP_CLAUSE_DEPEND_INOUT;
11899 else if (strcmp ("out", p) == 0)
11900 kind = OMP_CLAUSE_DEPEND_OUT;
11901 else
11902 goto invalid_kind;
11904 else
11905 goto invalid_kind;
11907 c_parser_consume_token (parser);
11908 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11909 goto resync_fail;
11911 nl = c_parser_omp_variable_list (parser, clause_loc,
11912 OMP_CLAUSE_DEPEND, list);
11914 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11915 OMP_CLAUSE_DEPEND_KIND (c) = kind;
11917 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11918 return nl;
11920 invalid_kind:
11921 c_parser_error (parser, "invalid depend kind");
11922 resync_fail:
11923 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11924 return list;
11927 /* OpenMP 4.0:
11928 map ( map-kind: variable-list )
11929 map ( variable-list )
11931 map-kind:
11932 alloc | to | from | tofrom */
11934 static tree
11935 c_parser_omp_clause_map (c_parser *parser, tree list)
11937 location_t clause_loc = c_parser_peek_token (parser)->location;
11938 enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11939 tree nl, c;
11941 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11942 return list;
11944 if (c_parser_next_token_is (parser, CPP_NAME)
11945 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11947 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11948 if (strcmp ("alloc", p) == 0)
11949 kind = GOMP_MAP_ALLOC;
11950 else if (strcmp ("to", p) == 0)
11951 kind = GOMP_MAP_TO;
11952 else if (strcmp ("from", p) == 0)
11953 kind = GOMP_MAP_FROM;
11954 else if (strcmp ("tofrom", p) == 0)
11955 kind = GOMP_MAP_TOFROM;
11956 else
11958 c_parser_error (parser, "invalid map kind");
11959 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11960 "expected %<)%>");
11961 return list;
11963 c_parser_consume_token (parser);
11964 c_parser_consume_token (parser);
11967 nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
11969 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11970 OMP_CLAUSE_SET_MAP_KIND (c, kind);
11972 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11973 return nl;
11976 /* OpenMP 4.0:
11977 device ( expression ) */
11979 static tree
11980 c_parser_omp_clause_device (c_parser *parser, tree list)
11982 location_t clause_loc = c_parser_peek_token (parser)->location;
11983 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11985 tree c, t = c_parser_expr_no_commas (parser, NULL).value;
11986 mark_exp_read (t);
11987 t = c_fully_fold (t, false, NULL);
11989 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11991 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11993 c_parser_error (parser, "expected integer expression");
11994 return list;
11997 check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
11999 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
12000 OMP_CLAUSE_DEVICE_ID (c) = t;
12001 OMP_CLAUSE_CHAIN (c) = list;
12002 list = c;
12005 return list;
12008 /* OpenMP 4.0:
12009 dist_schedule ( static )
12010 dist_schedule ( static , expression ) */
12012 static tree
12013 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
12015 tree c, t = NULL_TREE;
12016 location_t loc = c_parser_peek_token (parser)->location;
12018 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12019 return list;
12021 if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
12023 c_parser_error (parser, "invalid dist_schedule kind");
12024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12025 "expected %<)%>");
12026 return list;
12029 c_parser_consume_token (parser);
12030 if (c_parser_next_token_is (parser, CPP_COMMA))
12032 c_parser_consume_token (parser);
12034 t = c_parser_expr_no_commas (parser, NULL).value;
12035 mark_exp_read (t);
12036 t = c_fully_fold (t, false, NULL);
12037 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12039 else
12040 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12041 "expected %<,%> or %<)%>");
12043 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
12044 if (t == error_mark_node)
12045 return list;
12047 c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
12048 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
12049 OMP_CLAUSE_CHAIN (c) = list;
12050 return c;
12053 /* OpenMP 4.0:
12054 proc_bind ( proc-bind-kind )
12056 proc-bind-kind:
12057 master | close | spread */
12059 static tree
12060 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
12062 location_t clause_loc = c_parser_peek_token (parser)->location;
12063 enum omp_clause_proc_bind_kind kind;
12064 tree c;
12066 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12067 return list;
12069 if (c_parser_next_token_is (parser, CPP_NAME))
12071 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12072 if (strcmp ("master", p) == 0)
12073 kind = OMP_CLAUSE_PROC_BIND_MASTER;
12074 else if (strcmp ("close", p) == 0)
12075 kind = OMP_CLAUSE_PROC_BIND_CLOSE;
12076 else if (strcmp ("spread", p) == 0)
12077 kind = OMP_CLAUSE_PROC_BIND_SPREAD;
12078 else
12079 goto invalid_kind;
12081 else
12082 goto invalid_kind;
12084 c_parser_consume_token (parser);
12085 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12086 c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
12087 OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
12088 OMP_CLAUSE_CHAIN (c) = list;
12089 return c;
12091 invalid_kind:
12092 c_parser_error (parser, "invalid proc_bind kind");
12093 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12094 return list;
12097 /* OpenMP 4.0:
12098 to ( variable-list ) */
12100 static tree
12101 c_parser_omp_clause_to (c_parser *parser, tree list)
12103 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
12106 /* OpenMP 4.0:
12107 from ( variable-list ) */
12109 static tree
12110 c_parser_omp_clause_from (c_parser *parser, tree list)
12112 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
12115 /* OpenMP 4.0:
12116 uniform ( variable-list ) */
12118 static tree
12119 c_parser_omp_clause_uniform (c_parser *parser, tree list)
12121 /* The clauses location. */
12122 location_t loc = c_parser_peek_token (parser)->location;
12124 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12126 list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
12127 list);
12128 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12130 return list;
12133 /* Parse all OpenACC clauses. The set clauses allowed by the directive
12134 is a bitmask in MASK. Return the list of clauses found. */
12136 static tree
12137 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
12138 const char *where, bool finish_p = true)
12140 tree clauses = NULL;
12141 bool first = true;
12143 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12145 location_t here;
12146 pragma_omp_clause c_kind;
12147 const char *c_name;
12148 tree prev = clauses;
12150 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
12151 c_parser_consume_token (parser);
12153 here = c_parser_peek_token (parser)->location;
12154 c_kind = c_parser_omp_clause_name (parser);
12156 switch (c_kind)
12158 case PRAGMA_OACC_CLAUSE_ASYNC:
12159 clauses = c_parser_oacc_clause_async (parser, clauses);
12160 c_name = "async";
12161 break;
12162 case PRAGMA_OACC_CLAUSE_COLLAPSE:
12163 clauses = c_parser_omp_clause_collapse (parser, clauses);
12164 c_name = "collapse";
12165 break;
12166 case PRAGMA_OACC_CLAUSE_COPY:
12167 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12168 c_name = "copy";
12169 break;
12170 case PRAGMA_OACC_CLAUSE_COPYIN:
12171 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12172 c_name = "copyin";
12173 break;
12174 case PRAGMA_OACC_CLAUSE_COPYOUT:
12175 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12176 c_name = "copyout";
12177 break;
12178 case PRAGMA_OACC_CLAUSE_CREATE:
12179 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12180 c_name = "create";
12181 break;
12182 case PRAGMA_OACC_CLAUSE_DELETE:
12183 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12184 c_name = "delete";
12185 break;
12186 case PRAGMA_OACC_CLAUSE_DEVICE:
12187 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12188 c_name = "device";
12189 break;
12190 case PRAGMA_OACC_CLAUSE_DEVICEPTR:
12191 clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
12192 c_name = "deviceptr";
12193 break;
12194 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
12195 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
12196 c_name = "firstprivate";
12197 break;
12198 case PRAGMA_OACC_CLAUSE_HOST:
12199 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12200 c_name = "host";
12201 break;
12202 case PRAGMA_OACC_CLAUSE_IF:
12203 clauses = c_parser_omp_clause_if (parser, clauses);
12204 c_name = "if";
12205 break;
12206 case PRAGMA_OACC_CLAUSE_NUM_GANGS:
12207 clauses = c_parser_omp_clause_num_gangs (parser, clauses);
12208 c_name = "num_gangs";
12209 break;
12210 case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
12211 clauses = c_parser_omp_clause_num_workers (parser, clauses);
12212 c_name = "num_workers";
12213 break;
12214 case PRAGMA_OACC_CLAUSE_PRESENT:
12215 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12216 c_name = "present";
12217 break;
12218 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
12219 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12220 c_name = "present_or_copy";
12221 break;
12222 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
12223 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12224 c_name = "present_or_copyin";
12225 break;
12226 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
12227 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12228 c_name = "present_or_copyout";
12229 break;
12230 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
12231 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12232 c_name = "present_or_create";
12233 break;
12234 case PRAGMA_OACC_CLAUSE_PRIVATE:
12235 clauses = c_parser_omp_clause_private (parser, clauses);
12236 c_name = "private";
12237 break;
12238 case PRAGMA_OACC_CLAUSE_REDUCTION:
12239 clauses = c_parser_omp_clause_reduction (parser, clauses);
12240 c_name = "reduction";
12241 break;
12242 case PRAGMA_OACC_CLAUSE_SELF:
12243 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
12244 c_name = "self";
12245 break;
12246 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
12247 clauses = c_parser_omp_clause_vector_length (parser, clauses);
12248 c_name = "vector_length";
12249 break;
12250 case PRAGMA_OACC_CLAUSE_WAIT:
12251 clauses = c_parser_oacc_clause_wait (parser, clauses);
12252 c_name = "wait";
12253 break;
12254 default:
12255 c_parser_error (parser, "expected %<#pragma acc%> clause");
12256 goto saw_error;
12259 first = false;
12261 if (((mask >> c_kind) & 1) == 0 && !parser->error)
12263 /* Remove the invalid clause(s) from the list to avoid
12264 confusing the rest of the compiler. */
12265 clauses = prev;
12266 error_at (here, "%qs is not valid for %qs", c_name, where);
12270 saw_error:
12271 c_parser_skip_to_pragma_eol (parser);
12273 if (finish_p)
12274 return c_finish_omp_clauses (clauses);
12276 return clauses;
12279 /* Parse all OpenMP clauses. The set clauses allowed by the directive
12280 is a bitmask in MASK. Return the list of clauses found. */
12282 static tree
12283 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
12284 const char *where, bool finish_p = true)
12286 tree clauses = NULL;
12287 bool first = true, cilk_simd_fn = false;
12289 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12291 location_t here;
12292 pragma_omp_clause c_kind;
12293 const char *c_name;
12294 tree prev = clauses;
12296 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
12297 c_parser_consume_token (parser);
12299 here = c_parser_peek_token (parser)->location;
12300 c_kind = c_parser_omp_clause_name (parser);
12302 switch (c_kind)
12304 case PRAGMA_OMP_CLAUSE_COLLAPSE:
12305 clauses = c_parser_omp_clause_collapse (parser, clauses);
12306 c_name = "collapse";
12307 break;
12308 case PRAGMA_OMP_CLAUSE_COPYIN:
12309 clauses = c_parser_omp_clause_copyin (parser, clauses);
12310 c_name = "copyin";
12311 break;
12312 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
12313 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
12314 c_name = "copyprivate";
12315 break;
12316 case PRAGMA_OMP_CLAUSE_DEFAULT:
12317 clauses = c_parser_omp_clause_default (parser, clauses);
12318 c_name = "default";
12319 break;
12320 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
12321 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
12322 c_name = "firstprivate";
12323 break;
12324 case PRAGMA_OMP_CLAUSE_FINAL:
12325 clauses = c_parser_omp_clause_final (parser, clauses);
12326 c_name = "final";
12327 break;
12328 case PRAGMA_OMP_CLAUSE_IF:
12329 clauses = c_parser_omp_clause_if (parser, clauses);
12330 c_name = "if";
12331 break;
12332 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
12333 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
12334 c_name = "lastprivate";
12335 break;
12336 case PRAGMA_OMP_CLAUSE_MERGEABLE:
12337 clauses = c_parser_omp_clause_mergeable (parser, clauses);
12338 c_name = "mergeable";
12339 break;
12340 case PRAGMA_OMP_CLAUSE_NOWAIT:
12341 clauses = c_parser_omp_clause_nowait (parser, clauses);
12342 c_name = "nowait";
12343 break;
12344 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
12345 clauses = c_parser_omp_clause_num_threads (parser, clauses);
12346 c_name = "num_threads";
12347 break;
12348 case PRAGMA_OMP_CLAUSE_ORDERED:
12349 clauses = c_parser_omp_clause_ordered (parser, clauses);
12350 c_name = "ordered";
12351 break;
12352 case PRAGMA_OMP_CLAUSE_PRIVATE:
12353 clauses = c_parser_omp_clause_private (parser, clauses);
12354 c_name = "private";
12355 break;
12356 case PRAGMA_OMP_CLAUSE_REDUCTION:
12357 clauses = c_parser_omp_clause_reduction (parser, clauses);
12358 c_name = "reduction";
12359 break;
12360 case PRAGMA_OMP_CLAUSE_SCHEDULE:
12361 clauses = c_parser_omp_clause_schedule (parser, clauses);
12362 c_name = "schedule";
12363 break;
12364 case PRAGMA_OMP_CLAUSE_SHARED:
12365 clauses = c_parser_omp_clause_shared (parser, clauses);
12366 c_name = "shared";
12367 break;
12368 case PRAGMA_OMP_CLAUSE_UNTIED:
12369 clauses = c_parser_omp_clause_untied (parser, clauses);
12370 c_name = "untied";
12371 break;
12372 case PRAGMA_OMP_CLAUSE_INBRANCH:
12373 case PRAGMA_CILK_CLAUSE_MASK:
12374 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
12375 clauses);
12376 c_name = "inbranch";
12377 break;
12378 case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
12379 case PRAGMA_CILK_CLAUSE_NOMASK:
12380 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
12381 clauses);
12382 c_name = "notinbranch";
12383 break;
12384 case PRAGMA_OMP_CLAUSE_PARALLEL:
12385 clauses
12386 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
12387 clauses);
12388 c_name = "parallel";
12389 if (!first)
12391 clause_not_first:
12392 error_at (here, "%qs must be the first clause of %qs",
12393 c_name, where);
12394 clauses = prev;
12396 break;
12397 case PRAGMA_OMP_CLAUSE_FOR:
12398 clauses
12399 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
12400 clauses);
12401 c_name = "for";
12402 if (!first)
12403 goto clause_not_first;
12404 break;
12405 case PRAGMA_OMP_CLAUSE_SECTIONS:
12406 clauses
12407 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
12408 clauses);
12409 c_name = "sections";
12410 if (!first)
12411 goto clause_not_first;
12412 break;
12413 case PRAGMA_OMP_CLAUSE_TASKGROUP:
12414 clauses
12415 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
12416 clauses);
12417 c_name = "taskgroup";
12418 if (!first)
12419 goto clause_not_first;
12420 break;
12421 case PRAGMA_OMP_CLAUSE_TO:
12422 clauses = c_parser_omp_clause_to (parser, clauses);
12423 c_name = "to";
12424 break;
12425 case PRAGMA_OMP_CLAUSE_FROM:
12426 clauses = c_parser_omp_clause_from (parser, clauses);
12427 c_name = "from";
12428 break;
12429 case PRAGMA_OMP_CLAUSE_UNIFORM:
12430 clauses = c_parser_omp_clause_uniform (parser, clauses);
12431 c_name = "uniform";
12432 break;
12433 case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
12434 clauses = c_parser_omp_clause_num_teams (parser, clauses);
12435 c_name = "num_teams";
12436 break;
12437 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
12438 clauses = c_parser_omp_clause_thread_limit (parser, clauses);
12439 c_name = "thread_limit";
12440 break;
12441 case PRAGMA_OMP_CLAUSE_ALIGNED:
12442 clauses = c_parser_omp_clause_aligned (parser, clauses);
12443 c_name = "aligned";
12444 break;
12445 case PRAGMA_OMP_CLAUSE_LINEAR:
12446 if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0)
12447 cilk_simd_fn = true;
12448 clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn);
12449 c_name = "linear";
12450 break;
12451 case PRAGMA_OMP_CLAUSE_DEPEND:
12452 clauses = c_parser_omp_clause_depend (parser, clauses);
12453 c_name = "depend";
12454 break;
12455 case PRAGMA_OMP_CLAUSE_MAP:
12456 clauses = c_parser_omp_clause_map (parser, clauses);
12457 c_name = "map";
12458 break;
12459 case PRAGMA_OMP_CLAUSE_DEVICE:
12460 clauses = c_parser_omp_clause_device (parser, clauses);
12461 c_name = "device";
12462 break;
12463 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
12464 clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
12465 c_name = "dist_schedule";
12466 break;
12467 case PRAGMA_OMP_CLAUSE_PROC_BIND:
12468 clauses = c_parser_omp_clause_proc_bind (parser, clauses);
12469 c_name = "proc_bind";
12470 break;
12471 case PRAGMA_OMP_CLAUSE_SAFELEN:
12472 clauses = c_parser_omp_clause_safelen (parser, clauses);
12473 c_name = "safelen";
12474 break;
12475 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
12476 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true);
12477 c_name = "simdlen";
12478 break;
12479 case PRAGMA_OMP_CLAUSE_SIMDLEN:
12480 clauses = c_parser_omp_clause_simdlen (parser, clauses);
12481 c_name = "simdlen";
12482 break;
12483 default:
12484 c_parser_error (parser, "expected %<#pragma omp%> clause");
12485 goto saw_error;
12488 first = false;
12490 if (((mask >> c_kind) & 1) == 0 && !parser->error)
12492 /* Remove the invalid clause(s) from the list to avoid
12493 confusing the rest of the compiler. */
12494 clauses = prev;
12495 error_at (here, "%qs is not valid for %qs", c_name, where);
12499 saw_error:
12500 c_parser_skip_to_pragma_eol (parser);
12502 if (finish_p)
12503 return c_finish_omp_clauses (clauses);
12505 return clauses;
12508 /* OpenACC 2.0, OpenMP 2.5:
12509 structured-block:
12510 statement
12512 In practice, we're also interested in adding the statement to an
12513 outer node. So it is convenient if we work around the fact that
12514 c_parser_statement calls add_stmt. */
12516 static tree
12517 c_parser_omp_structured_block (c_parser *parser)
12519 tree stmt = push_stmt_list ();
12520 c_parser_statement (parser);
12521 return pop_stmt_list (stmt);
12524 /* OpenACC 2.0:
12525 # pragma acc cache (variable-list) new-line
12527 LOC is the location of the #pragma token.
12530 static tree
12531 c_parser_oacc_cache (location_t loc, c_parser *parser)
12533 tree stmt, clauses;
12535 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
12536 clauses = c_finish_omp_clauses (clauses);
12538 c_parser_skip_to_pragma_eol (parser);
12540 stmt = make_node (OACC_CACHE);
12541 TREE_TYPE (stmt) = void_type_node;
12542 OACC_CACHE_CLAUSES (stmt) = clauses;
12543 SET_EXPR_LOCATION (stmt, loc);
12544 add_stmt (stmt);
12546 return stmt;
12549 /* OpenACC 2.0:
12550 # pragma acc data oacc-data-clause[optseq] new-line
12551 structured-block
12553 LOC is the location of the #pragma token.
12556 #define OACC_DATA_CLAUSE_MASK \
12557 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12558 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12559 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12560 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12561 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12562 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12569 static tree
12570 c_parser_oacc_data (location_t loc, c_parser *parser)
12572 tree stmt, clauses, block;
12574 clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
12575 "#pragma acc data");
12577 block = c_begin_omp_parallel ();
12578 add_stmt (c_parser_omp_structured_block (parser));
12580 stmt = c_finish_oacc_data (loc, clauses, block);
12582 return stmt;
12585 /* OpenACC 2.0:
12586 # pragma acc kernels oacc-kernels-clause[optseq] new-line
12587 structured-block
12589 LOC is the location of the #pragma token.
12592 #define OACC_KERNELS_CLAUSE_MASK \
12593 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12595 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12596 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12597 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12598 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12599 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12600 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12602 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12607 static tree
12608 c_parser_oacc_kernels (location_t loc, c_parser *parser, char *p_name)
12610 tree stmt, clauses = NULL_TREE, block;
12612 strcat (p_name, " kernels");
12614 if (c_parser_next_token_is (parser, CPP_NAME))
12616 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12617 if (strcmp (p, "loop") == 0)
12619 c_parser_consume_token (parser);
12620 block = c_begin_omp_parallel ();
12621 c_parser_oacc_loop (loc, parser, p_name);
12622 stmt = c_finish_oacc_kernels (loc, clauses, block);
12623 OACC_KERNELS_COMBINED (stmt) = 1;
12624 return stmt;
12628 clauses = c_parser_oacc_all_clauses (parser, OACC_KERNELS_CLAUSE_MASK,
12629 p_name);
12631 block = c_begin_omp_parallel ();
12632 add_stmt (c_parser_omp_structured_block (parser));
12634 stmt = c_finish_oacc_kernels (loc, clauses, block);
12636 return stmt;
12639 /* OpenACC 2.0:
12640 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12644 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12647 LOC is the location of the #pragma token.
12650 #define OACC_ENTER_DATA_CLAUSE_MASK \
12651 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12652 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12653 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12654 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12655 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12656 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12657 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12659 #define OACC_EXIT_DATA_CLAUSE_MASK \
12660 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12663 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
12664 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12666 static void
12667 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
12669 location_t loc = c_parser_peek_token (parser)->location;
12670 tree clauses, stmt;
12672 c_parser_consume_pragma (parser);
12674 if (!c_parser_next_token_is (parser, CPP_NAME))
12676 c_parser_error (parser, enter
12677 ? "expected %<data%> in %<#pragma acc enter data%>"
12678 : "expected %<data%> in %<#pragma acc exit data%>");
12679 c_parser_skip_to_pragma_eol (parser);
12680 return;
12683 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12684 if (strcmp (p, "data") != 0)
12686 c_parser_error (parser, "invalid pragma");
12687 c_parser_skip_to_pragma_eol (parser);
12688 return;
12691 c_parser_consume_token (parser);
12693 if (enter)
12694 clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
12695 "#pragma acc enter data");
12696 else
12697 clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
12698 "#pragma acc exit data");
12700 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12702 error_at (loc, enter
12703 ? "%<#pragma acc enter data%> has no data movement clause"
12704 : "%<#pragma acc exit data%> has no data movement clause");
12705 return;
12708 stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);;
12709 TREE_TYPE (stmt) = void_type_node;
12710 if (enter)
12711 OACC_ENTER_DATA_CLAUSES (stmt) = clauses;
12712 else
12713 OACC_EXIT_DATA_CLAUSES (stmt) = clauses;
12714 SET_EXPR_LOCATION (stmt, loc);
12715 add_stmt (stmt);
12719 /* OpenACC 2.0:
12721 # pragma acc loop oacc-loop-clause[optseq] new-line
12722 structured-block
12724 LOC is the location of the #pragma token.
12727 #define OACC_LOOP_CLAUSE_MASK \
12728 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
12729 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12731 static tree
12732 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name)
12734 tree stmt, clauses, block;
12736 strcat (p_name, " loop");
12738 clauses = c_parser_oacc_all_clauses (parser, OACC_LOOP_CLAUSE_MASK, p_name);
12740 block = c_begin_compound_stmt (true);
12741 stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL);
12742 block = c_end_compound_stmt (loc, block, true);
12743 add_stmt (block);
12745 return stmt;
12748 /* OpenACC 2.0:
12749 # pragma acc parallel oacc-parallel-clause[optseq] new-line
12750 structured-block
12752 LOC is the location of the #pragma token.
12755 #define OACC_PARALLEL_CLAUSE_MASK \
12756 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
12764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
12765 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12766 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12767 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12768 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12769 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12770 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
12771 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
12772 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12774 static tree
12775 c_parser_oacc_parallel (location_t loc, c_parser *parser, char *p_name)
12777 tree stmt, clauses = NULL_TREE, block;
12779 strcat (p_name, " parallel");
12781 if (c_parser_next_token_is (parser, CPP_NAME))
12783 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12784 if (strcmp (p, "loop") == 0)
12786 c_parser_consume_token (parser);
12787 block = c_begin_omp_parallel ();
12788 c_parser_oacc_loop (loc, parser, p_name);
12789 stmt = c_finish_oacc_parallel (loc, clauses, block);
12790 OACC_PARALLEL_COMBINED (stmt) = 1;
12791 return stmt;
12795 clauses = c_parser_oacc_all_clauses (parser, OACC_PARALLEL_CLAUSE_MASK,
12796 p_name);
12798 block = c_begin_omp_parallel ();
12799 add_stmt (c_parser_omp_structured_block (parser));
12801 stmt = c_finish_oacc_parallel (loc, clauses, block);
12803 return stmt;
12806 /* OpenACC 2.0:
12807 # pragma acc update oacc-update-clause[optseq] new-line
12810 #define OACC_UPDATE_CLAUSE_MASK \
12811 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
12813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
12814 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12815 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
12816 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12818 static void
12819 c_parser_oacc_update (c_parser *parser)
12821 location_t loc = c_parser_peek_token (parser)->location;
12823 c_parser_consume_pragma (parser);
12825 tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
12826 "#pragma acc update");
12827 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12829 error_at (loc,
12830 "%<#pragma acc update%> must contain at least one "
12831 "%<device%> or %<host/self%> clause");
12832 return;
12835 if (parser->error)
12836 return;
12838 tree stmt = make_node (OACC_UPDATE);
12839 TREE_TYPE (stmt) = void_type_node;
12840 OACC_UPDATE_CLAUSES (stmt) = clauses;
12841 SET_EXPR_LOCATION (stmt, loc);
12842 add_stmt (stmt);
12845 /* OpenACC 2.0:
12846 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12848 LOC is the location of the #pragma token.
12851 #define OACC_WAIT_CLAUSE_MASK \
12852 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12854 static tree
12855 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
12857 tree clauses, list = NULL_TREE, stmt = NULL_TREE;
12859 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12860 list = c_parser_oacc_wait_list (parser, loc, list);
12862 strcpy (p_name, " wait");
12863 clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
12864 stmt = c_finish_oacc_wait (loc, list, clauses);
12866 return stmt;
12869 /* OpenMP 2.5:
12870 # pragma omp atomic new-line
12871 expression-stmt
12873 expression-stmt:
12874 x binop= expr | x++ | ++x | x-- | --x
12875 binop:
12876 +, *, -, /, &, ^, |, <<, >>
12878 where x is an lvalue expression with scalar type.
12880 OpenMP 3.1:
12881 # pragma omp atomic new-line
12882 update-stmt
12884 # pragma omp atomic read new-line
12885 read-stmt
12887 # pragma omp atomic write new-line
12888 write-stmt
12890 # pragma omp atomic update new-line
12891 update-stmt
12893 # pragma omp atomic capture new-line
12894 capture-stmt
12896 # pragma omp atomic capture new-line
12897 capture-block
12899 read-stmt:
12900 v = x
12901 write-stmt:
12902 x = expr
12903 update-stmt:
12904 expression-stmt | x = x binop expr
12905 capture-stmt:
12906 v = expression-stmt
12907 capture-block:
12908 { v = x; update-stmt; } | { update-stmt; v = x; }
12910 OpenMP 4.0:
12911 update-stmt:
12912 expression-stmt | x = x binop expr | x = expr binop x
12913 capture-stmt:
12914 v = update-stmt
12915 capture-block:
12916 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12918 where x and v are lvalue expressions with scalar type.
12920 LOC is the location of the #pragma token. */
12922 static void
12923 c_parser_omp_atomic (location_t loc, c_parser *parser)
12925 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
12926 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
12927 tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
12928 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
12929 struct c_expr expr;
12930 location_t eloc;
12931 bool structured_block = false;
12932 bool swapped = false;
12933 bool seq_cst = false;
12935 if (c_parser_next_token_is (parser, CPP_NAME))
12937 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12938 if (!strcmp (p, "seq_cst"))
12940 seq_cst = true;
12941 c_parser_consume_token (parser);
12942 if (c_parser_next_token_is (parser, CPP_COMMA)
12943 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12944 c_parser_consume_token (parser);
12947 if (c_parser_next_token_is (parser, CPP_NAME))
12949 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12951 if (!strcmp (p, "read"))
12952 code = OMP_ATOMIC_READ;
12953 else if (!strcmp (p, "write"))
12954 code = NOP_EXPR;
12955 else if (!strcmp (p, "update"))
12956 code = OMP_ATOMIC;
12957 else if (!strcmp (p, "capture"))
12958 code = OMP_ATOMIC_CAPTURE_NEW;
12959 else
12960 p = NULL;
12961 if (p)
12962 c_parser_consume_token (parser);
12964 if (!seq_cst)
12966 if (c_parser_next_token_is (parser, CPP_COMMA)
12967 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12968 c_parser_consume_token (parser);
12970 if (c_parser_next_token_is (parser, CPP_NAME))
12972 const char *p
12973 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12974 if (!strcmp (p, "seq_cst"))
12976 seq_cst = true;
12977 c_parser_consume_token (parser);
12981 c_parser_skip_to_pragma_eol (parser);
12983 switch (code)
12985 case OMP_ATOMIC_READ:
12986 case NOP_EXPR: /* atomic write */
12987 v = c_parser_unary_expression (parser).value;
12988 v = c_fully_fold (v, false, NULL);
12989 if (v == error_mark_node)
12990 goto saw_error;
12991 loc = c_parser_peek_token (parser)->location;
12992 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12993 goto saw_error;
12994 if (code == NOP_EXPR)
12995 lhs = c_parser_expression (parser).value;
12996 else
12997 lhs = c_parser_unary_expression (parser).value;
12998 lhs = c_fully_fold (lhs, false, NULL);
12999 if (lhs == error_mark_node)
13000 goto saw_error;
13001 if (code == NOP_EXPR)
13003 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
13004 opcode. */
13005 code = OMP_ATOMIC;
13006 rhs = lhs;
13007 lhs = v;
13008 v = NULL_TREE;
13010 goto done;
13011 case OMP_ATOMIC_CAPTURE_NEW:
13012 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
13014 c_parser_consume_token (parser);
13015 structured_block = true;
13017 else
13019 v = c_parser_unary_expression (parser).value;
13020 v = c_fully_fold (v, false, NULL);
13021 if (v == error_mark_node)
13022 goto saw_error;
13023 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
13024 goto saw_error;
13026 break;
13027 default:
13028 break;
13031 /* For structured_block case we don't know yet whether
13032 old or new x should be captured. */
13033 restart:
13034 eloc = c_parser_peek_token (parser)->location;
13035 expr = c_parser_unary_expression (parser);
13036 lhs = expr.value;
13037 expr = default_function_array_conversion (eloc, expr);
13038 unfolded_lhs = expr.value;
13039 lhs = c_fully_fold (lhs, false, NULL);
13040 orig_lhs = lhs;
13041 switch (TREE_CODE (lhs))
13043 case ERROR_MARK:
13044 saw_error:
13045 c_parser_skip_to_end_of_block_or_statement (parser);
13046 if (structured_block)
13048 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13049 c_parser_consume_token (parser);
13050 else if (code == OMP_ATOMIC_CAPTURE_NEW)
13052 c_parser_skip_to_end_of_block_or_statement (parser);
13053 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13054 c_parser_consume_token (parser);
13057 return;
13059 case POSTINCREMENT_EXPR:
13060 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
13061 code = OMP_ATOMIC_CAPTURE_OLD;
13062 /* FALLTHROUGH */
13063 case PREINCREMENT_EXPR:
13064 lhs = TREE_OPERAND (lhs, 0);
13065 unfolded_lhs = NULL_TREE;
13066 opcode = PLUS_EXPR;
13067 rhs = integer_one_node;
13068 break;
13070 case POSTDECREMENT_EXPR:
13071 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
13072 code = OMP_ATOMIC_CAPTURE_OLD;
13073 /* FALLTHROUGH */
13074 case PREDECREMENT_EXPR:
13075 lhs = TREE_OPERAND (lhs, 0);
13076 unfolded_lhs = NULL_TREE;
13077 opcode = MINUS_EXPR;
13078 rhs = integer_one_node;
13079 break;
13081 case COMPOUND_EXPR:
13082 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
13083 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
13084 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
13085 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
13086 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
13087 (TREE_OPERAND (lhs, 1), 0), 0)))
13088 == BOOLEAN_TYPE)
13089 /* Undo effects of boolean_increment for post {in,de}crement. */
13090 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
13091 /* FALLTHRU */
13092 case MODIFY_EXPR:
13093 if (TREE_CODE (lhs) == MODIFY_EXPR
13094 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
13096 /* Undo effects of boolean_increment. */
13097 if (integer_onep (TREE_OPERAND (lhs, 1)))
13099 /* This is pre or post increment. */
13100 rhs = TREE_OPERAND (lhs, 1);
13101 lhs = TREE_OPERAND (lhs, 0);
13102 unfolded_lhs = NULL_TREE;
13103 opcode = NOP_EXPR;
13104 if (code == OMP_ATOMIC_CAPTURE_NEW
13105 && !structured_block
13106 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
13107 code = OMP_ATOMIC_CAPTURE_OLD;
13108 break;
13110 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
13111 && TREE_OPERAND (lhs, 0)
13112 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
13114 /* This is pre or post decrement. */
13115 rhs = TREE_OPERAND (lhs, 1);
13116 lhs = TREE_OPERAND (lhs, 0);
13117 unfolded_lhs = NULL_TREE;
13118 opcode = NOP_EXPR;
13119 if (code == OMP_ATOMIC_CAPTURE_NEW
13120 && !structured_block
13121 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
13122 code = OMP_ATOMIC_CAPTURE_OLD;
13123 break;
13126 /* FALLTHRU */
13127 default:
13128 switch (c_parser_peek_token (parser)->type)
13130 case CPP_MULT_EQ:
13131 opcode = MULT_EXPR;
13132 break;
13133 case CPP_DIV_EQ:
13134 opcode = TRUNC_DIV_EXPR;
13135 break;
13136 case CPP_PLUS_EQ:
13137 opcode = PLUS_EXPR;
13138 break;
13139 case CPP_MINUS_EQ:
13140 opcode = MINUS_EXPR;
13141 break;
13142 case CPP_LSHIFT_EQ:
13143 opcode = LSHIFT_EXPR;
13144 break;
13145 case CPP_RSHIFT_EQ:
13146 opcode = RSHIFT_EXPR;
13147 break;
13148 case CPP_AND_EQ:
13149 opcode = BIT_AND_EXPR;
13150 break;
13151 case CPP_OR_EQ:
13152 opcode = BIT_IOR_EXPR;
13153 break;
13154 case CPP_XOR_EQ:
13155 opcode = BIT_XOR_EXPR;
13156 break;
13157 case CPP_EQ:
13158 c_parser_consume_token (parser);
13159 eloc = c_parser_peek_token (parser)->location;
13160 expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
13161 rhs1 = expr.value;
13162 switch (TREE_CODE (rhs1))
13164 case MULT_EXPR:
13165 case TRUNC_DIV_EXPR:
13166 case RDIV_EXPR:
13167 case PLUS_EXPR:
13168 case MINUS_EXPR:
13169 case LSHIFT_EXPR:
13170 case RSHIFT_EXPR:
13171 case BIT_AND_EXPR:
13172 case BIT_IOR_EXPR:
13173 case BIT_XOR_EXPR:
13174 if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
13176 opcode = TREE_CODE (rhs1);
13177 rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
13178 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
13179 goto stmt_done;
13181 if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
13183 opcode = TREE_CODE (rhs1);
13184 rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
13185 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
13186 swapped = !commutative_tree_code (opcode);
13187 goto stmt_done;
13189 break;
13190 case ERROR_MARK:
13191 goto saw_error;
13192 default:
13193 break;
13195 if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
13197 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
13199 code = OMP_ATOMIC_CAPTURE_OLD;
13200 v = lhs;
13201 lhs = NULL_TREE;
13202 expr = default_function_array_read_conversion (eloc, expr);
13203 unfolded_lhs1 = expr.value;
13204 lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
13205 rhs1 = NULL_TREE;
13206 c_parser_consume_token (parser);
13207 goto restart;
13209 if (structured_block)
13211 opcode = NOP_EXPR;
13212 expr = default_function_array_read_conversion (eloc, expr);
13213 rhs = c_fully_fold (expr.value, false, NULL);
13214 rhs1 = NULL_TREE;
13215 goto stmt_done;
13218 c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
13219 goto saw_error;
13220 default:
13221 c_parser_error (parser,
13222 "invalid operator for %<#pragma omp atomic%>");
13223 goto saw_error;
13226 /* Arrange to pass the location of the assignment operator to
13227 c_finish_omp_atomic. */
13228 loc = c_parser_peek_token (parser)->location;
13229 c_parser_consume_token (parser);
13230 eloc = c_parser_peek_token (parser)->location;
13231 expr = c_parser_expression (parser);
13232 expr = default_function_array_read_conversion (eloc, expr);
13233 rhs = expr.value;
13234 rhs = c_fully_fold (rhs, false, NULL);
13235 break;
13237 stmt_done:
13238 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
13240 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
13241 goto saw_error;
13242 v = c_parser_unary_expression (parser).value;
13243 v = c_fully_fold (v, false, NULL);
13244 if (v == error_mark_node)
13245 goto saw_error;
13246 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
13247 goto saw_error;
13248 eloc = c_parser_peek_token (parser)->location;
13249 expr = c_parser_unary_expression (parser);
13250 lhs1 = expr.value;
13251 expr = default_function_array_read_conversion (eloc, expr);
13252 unfolded_lhs1 = expr.value;
13253 lhs1 = c_fully_fold (lhs1, false, NULL);
13254 if (lhs1 == error_mark_node)
13255 goto saw_error;
13257 if (structured_block)
13259 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
13260 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
13262 done:
13263 if (unfolded_lhs && unfolded_lhs1
13264 && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
13266 error ("%<#pragma omp atomic capture%> uses two different "
13267 "expressions for memory");
13268 stmt = error_mark_node;
13270 else
13271 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
13272 swapped, seq_cst);
13273 if (stmt != error_mark_node)
13274 add_stmt (stmt);
13276 if (!structured_block)
13277 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
13281 /* OpenMP 2.5:
13282 # pragma omp barrier new-line
13285 static void
13286 c_parser_omp_barrier (c_parser *parser)
13288 location_t loc = c_parser_peek_token (parser)->location;
13289 c_parser_consume_pragma (parser);
13290 c_parser_skip_to_pragma_eol (parser);
13292 c_finish_omp_barrier (loc);
13295 /* OpenMP 2.5:
13296 # pragma omp critical [(name)] new-line
13297 structured-block
13299 LOC is the location of the #pragma itself. */
13301 static tree
13302 c_parser_omp_critical (location_t loc, c_parser *parser)
13304 tree stmt, name = NULL;
13306 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
13308 c_parser_consume_token (parser);
13309 if (c_parser_next_token_is (parser, CPP_NAME))
13311 name = c_parser_peek_token (parser)->value;
13312 c_parser_consume_token (parser);
13313 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13315 else
13316 c_parser_error (parser, "expected identifier");
13318 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13319 c_parser_error (parser, "expected %<(%> or end of line");
13320 c_parser_skip_to_pragma_eol (parser);
13322 stmt = c_parser_omp_structured_block (parser);
13323 return c_finish_omp_critical (loc, stmt, name);
13326 /* OpenMP 2.5:
13327 # pragma omp flush flush-vars[opt] new-line
13329 flush-vars:
13330 ( variable-list ) */
13332 static void
13333 c_parser_omp_flush (c_parser *parser)
13335 location_t loc = c_parser_peek_token (parser)->location;
13336 c_parser_consume_pragma (parser);
13337 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
13338 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
13339 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13340 c_parser_error (parser, "expected %<(%> or end of line");
13341 c_parser_skip_to_pragma_eol (parser);
13343 c_finish_omp_flush (loc);
13346 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
13347 The real trick here is to determine the loop control variable early
13348 so that we can push a new decl if necessary to make it private.
13349 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
13350 respectively. */
13352 static tree
13353 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
13354 tree clauses, tree *cclauses)
13356 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
13357 tree declv, condv, incrv, initv, ret = NULL;
13358 bool fail = false, open_brace_parsed = false;
13359 int i, collapse = 1, nbraces = 0;
13360 location_t for_loc;
13361 vec<tree, va_gc> *for_block = make_tree_vector ();
13363 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
13364 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
13365 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
13367 gcc_assert (collapse >= 1);
13369 declv = make_tree_vec (collapse);
13370 initv = make_tree_vec (collapse);
13371 condv = make_tree_vec (collapse);
13372 incrv = make_tree_vec (collapse);
13374 if (code != CILK_FOR
13375 && !c_parser_next_token_is_keyword (parser, RID_FOR))
13377 c_parser_error (parser, "for statement expected");
13378 return NULL;
13380 if (code == CILK_FOR
13381 && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR))
13383 c_parser_error (parser, "_Cilk_for statement expected");
13384 return NULL;
13386 for_loc = c_parser_peek_token (parser)->location;
13387 c_parser_consume_token (parser);
13389 for (i = 0; i < collapse; i++)
13391 int bracecount = 0;
13393 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
13394 goto pop_scopes;
13396 /* Parse the initialization declaration or expression. */
13397 if (c_parser_next_tokens_start_declaration (parser))
13399 if (i > 0)
13400 vec_safe_push (for_block, c_begin_compound_stmt (true));
13401 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
13402 NULL, vNULL);
13403 decl = check_for_loop_decls (for_loc, flag_isoc99);
13404 if (decl == NULL)
13405 goto error_init;
13406 if (DECL_INITIAL (decl) == error_mark_node)
13407 decl = error_mark_node;
13408 init = decl;
13410 else if (c_parser_next_token_is (parser, CPP_NAME)
13411 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
13413 struct c_expr decl_exp;
13414 struct c_expr init_exp;
13415 location_t init_loc;
13417 decl_exp = c_parser_postfix_expression (parser);
13418 decl = decl_exp.value;
13420 c_parser_require (parser, CPP_EQ, "expected %<=%>");
13422 init_loc = c_parser_peek_token (parser)->location;
13423 init_exp = c_parser_expr_no_commas (parser, NULL);
13424 init_exp = default_function_array_read_conversion (init_loc,
13425 init_exp);
13426 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
13427 NOP_EXPR, init_loc, init_exp.value,
13428 init_exp.original_type);
13429 init = c_process_expr_stmt (init_loc, init);
13431 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
13433 else
13435 error_init:
13436 c_parser_error (parser,
13437 "expected iteration declaration or initialization");
13438 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13439 "expected %<)%>");
13440 fail = true;
13441 goto parse_next;
13444 /* Parse the loop condition. */
13445 cond = NULL_TREE;
13446 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
13448 location_t cond_loc = c_parser_peek_token (parser)->location;
13449 struct c_expr cond_expr
13450 = c_parser_binary_expression (parser, NULL, NULL_TREE);
13452 cond = cond_expr.value;
13453 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
13454 cond = c_fully_fold (cond, false, NULL);
13455 switch (cond_expr.original_code)
13457 case GT_EXPR:
13458 case GE_EXPR:
13459 case LT_EXPR:
13460 case LE_EXPR:
13461 break;
13462 case NE_EXPR:
13463 if (code == CILK_SIMD || code == CILK_FOR)
13464 break;
13465 /* FALLTHRU. */
13466 default:
13467 /* Can't be cond = error_mark_node, because we want to preserve
13468 the location until c_finish_omp_for. */
13469 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
13470 break;
13472 protected_set_expr_location (cond, cond_loc);
13474 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
13476 /* Parse the increment expression. */
13477 incr = NULL_TREE;
13478 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
13480 location_t incr_loc = c_parser_peek_token (parser)->location;
13482 incr = c_process_expr_stmt (incr_loc,
13483 c_parser_expression (parser).value);
13485 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13487 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
13488 fail = true;
13489 else
13491 TREE_VEC_ELT (declv, i) = decl;
13492 TREE_VEC_ELT (initv, i) = init;
13493 TREE_VEC_ELT (condv, i) = cond;
13494 TREE_VEC_ELT (incrv, i) = incr;
13497 parse_next:
13498 if (i == collapse - 1)
13499 break;
13501 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
13502 in between the collapsed for loops to be still considered perfectly
13503 nested. Hopefully the final version clarifies this.
13504 For now handle (multiple) {'s and empty statements. */
13507 if (c_parser_next_token_is_keyword (parser, RID_FOR))
13509 c_parser_consume_token (parser);
13510 break;
13512 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
13514 c_parser_consume_token (parser);
13515 bracecount++;
13517 else if (bracecount
13518 && c_parser_next_token_is (parser, CPP_SEMICOLON))
13519 c_parser_consume_token (parser);
13520 else
13522 c_parser_error (parser, "not enough perfectly nested loops");
13523 if (bracecount)
13525 open_brace_parsed = true;
13526 bracecount--;
13528 fail = true;
13529 collapse = 0;
13530 break;
13533 while (1);
13535 nbraces += bracecount;
13538 save_break = c_break_label;
13539 if (code == CILK_SIMD)
13540 c_break_label = build_int_cst (size_type_node, 2);
13541 else
13542 c_break_label = size_one_node;
13543 save_cont = c_cont_label;
13544 c_cont_label = NULL_TREE;
13545 body = push_stmt_list ();
13547 if (open_brace_parsed)
13549 location_t here = c_parser_peek_token (parser)->location;
13550 stmt = c_begin_compound_stmt (true);
13551 c_parser_compound_statement_nostart (parser);
13552 add_stmt (c_end_compound_stmt (here, stmt, true));
13554 else
13555 add_stmt (c_parser_c99_block_statement (parser));
13556 if (c_cont_label)
13558 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
13559 SET_EXPR_LOCATION (t, loc);
13560 add_stmt (t);
13563 body = pop_stmt_list (body);
13564 c_break_label = save_break;
13565 c_cont_label = save_cont;
13567 while (nbraces)
13569 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13571 c_parser_consume_token (parser);
13572 nbraces--;
13574 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
13575 c_parser_consume_token (parser);
13576 else
13578 c_parser_error (parser, "collapsed loops not perfectly nested");
13579 while (nbraces)
13581 location_t here = c_parser_peek_token (parser)->location;
13582 stmt = c_begin_compound_stmt (true);
13583 add_stmt (body);
13584 c_parser_compound_statement_nostart (parser);
13585 body = c_end_compound_stmt (here, stmt, true);
13586 nbraces--;
13588 goto pop_scopes;
13592 /* Only bother calling c_finish_omp_for if we haven't already generated
13593 an error from the initialization parsing. */
13594 if (!fail)
13596 stmt = c_finish_omp_for (loc, code, declv, initv, condv,
13597 incrv, body, NULL);
13598 if (stmt)
13600 if (cclauses != NULL
13601 && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
13603 tree *c;
13604 for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
13605 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
13606 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
13607 c = &OMP_CLAUSE_CHAIN (*c);
13608 else
13610 for (i = 0; i < collapse; i++)
13611 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
13612 break;
13613 if (i == collapse)
13614 c = &OMP_CLAUSE_CHAIN (*c);
13615 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
13617 error_at (loc,
13618 "iteration variable %qD should not be firstprivate",
13619 OMP_CLAUSE_DECL (*c));
13620 *c = OMP_CLAUSE_CHAIN (*c);
13622 else
13624 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
13625 change it to shared (decl) in
13626 OMP_PARALLEL_CLAUSES. */
13627 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
13628 OMP_CLAUSE_LASTPRIVATE);
13629 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
13630 if (code == OMP_SIMD)
13632 OMP_CLAUSE_CHAIN (l)
13633 = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13634 cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
13636 else
13638 OMP_CLAUSE_CHAIN (l) = clauses;
13639 clauses = l;
13641 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
13645 OMP_FOR_CLAUSES (stmt) = clauses;
13647 ret = stmt;
13649 pop_scopes:
13650 while (!for_block->is_empty ())
13652 /* FIXME diagnostics: LOC below should be the actual location of
13653 this particular for block. We need to build a list of
13654 locations to go along with FOR_BLOCK. */
13655 stmt = c_end_compound_stmt (loc, for_block->pop (), true);
13656 add_stmt (stmt);
13658 release_tree_vector (for_block);
13659 return ret;
13662 /* Helper function for OpenMP parsing, split clauses and call
13663 finish_omp_clauses on each of the set of clauses afterwards. */
13665 static void
13666 omp_split_clauses (location_t loc, enum tree_code code,
13667 omp_clause_mask mask, tree clauses, tree *cclauses)
13669 int i;
13670 c_omp_split_clauses (loc, code, mask, clauses, cclauses);
13671 for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
13672 if (cclauses[i])
13673 cclauses[i] = c_finish_omp_clauses (cclauses[i]);
13676 /* OpenMP 4.0:
13677 #pragma omp simd simd-clause[optseq] new-line
13678 for-loop
13680 LOC is the location of the #pragma token.
13683 #define OMP_SIMD_CLAUSE_MASK \
13684 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
13685 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13686 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13687 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13688 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13689 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13690 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13692 static tree
13693 c_parser_omp_simd (location_t loc, c_parser *parser,
13694 char *p_name, omp_clause_mask mask, tree *cclauses)
13696 tree block, clauses, ret;
13698 strcat (p_name, " simd");
13699 mask |= OMP_SIMD_CLAUSE_MASK;
13700 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
13702 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13703 if (cclauses)
13705 omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
13706 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
13709 block = c_begin_compound_stmt (true);
13710 ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses);
13711 block = c_end_compound_stmt (loc, block, true);
13712 add_stmt (block);
13714 return ret;
13717 /* OpenMP 2.5:
13718 #pragma omp for for-clause[optseq] new-line
13719 for-loop
13721 OpenMP 4.0:
13722 #pragma omp for simd for-simd-clause[optseq] new-line
13723 for-loop
13725 LOC is the location of the #pragma token.
13728 #define OMP_FOR_CLAUSE_MASK \
13729 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
13734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
13735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
13736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13738 static tree
13739 c_parser_omp_for (location_t loc, c_parser *parser,
13740 char *p_name, omp_clause_mask mask, tree *cclauses)
13742 tree block, clauses, ret;
13744 strcat (p_name, " for");
13745 mask |= OMP_FOR_CLAUSE_MASK;
13746 if (cclauses)
13747 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13749 if (c_parser_next_token_is (parser, CPP_NAME))
13751 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13753 if (strcmp (p, "simd") == 0)
13755 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13756 if (cclauses == NULL)
13757 cclauses = cclauses_buf;
13759 c_parser_consume_token (parser);
13760 if (!flag_openmp) /* flag_openmp_simd */
13761 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13762 block = c_begin_compound_stmt (true);
13763 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13764 block = c_end_compound_stmt (loc, block, true);
13765 if (ret == NULL_TREE)
13766 return ret;
13767 ret = make_node (OMP_FOR);
13768 TREE_TYPE (ret) = void_type_node;
13769 OMP_FOR_BODY (ret) = block;
13770 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13771 SET_EXPR_LOCATION (ret, loc);
13772 add_stmt (ret);
13773 return ret;
13776 if (!flag_openmp) /* flag_openmp_simd */
13778 c_parser_skip_to_pragma_eol (parser);
13779 return NULL_TREE;
13782 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13783 if (cclauses)
13785 omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
13786 clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13789 block = c_begin_compound_stmt (true);
13790 ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses);
13791 block = c_end_compound_stmt (loc, block, true);
13792 add_stmt (block);
13794 return ret;
13797 /* OpenMP 2.5:
13798 # pragma omp master new-line
13799 structured-block
13801 LOC is the location of the #pragma token.
13804 static tree
13805 c_parser_omp_master (location_t loc, c_parser *parser)
13807 c_parser_skip_to_pragma_eol (parser);
13808 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
13811 /* OpenMP 2.5:
13812 # pragma omp ordered new-line
13813 structured-block
13815 LOC is the location of the #pragma itself.
13818 static tree
13819 c_parser_omp_ordered (location_t loc, c_parser *parser)
13821 c_parser_skip_to_pragma_eol (parser);
13822 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
13825 /* OpenMP 2.5:
13827 section-scope:
13828 { section-sequence }
13830 section-sequence:
13831 section-directive[opt] structured-block
13832 section-sequence section-directive structured-block
13834 SECTIONS_LOC is the location of the #pragma omp sections. */
13836 static tree
13837 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
13839 tree stmt, substmt;
13840 bool error_suppress = false;
13841 location_t loc;
13843 loc = c_parser_peek_token (parser)->location;
13844 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
13846 /* Avoid skipping until the end of the block. */
13847 parser->error = false;
13848 return NULL_TREE;
13851 stmt = push_stmt_list ();
13853 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
13855 substmt = c_parser_omp_structured_block (parser);
13856 substmt = build1 (OMP_SECTION, void_type_node, substmt);
13857 SET_EXPR_LOCATION (substmt, loc);
13858 add_stmt (substmt);
13861 while (1)
13863 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13864 break;
13865 if (c_parser_next_token_is (parser, CPP_EOF))
13866 break;
13868 loc = c_parser_peek_token (parser)->location;
13869 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
13871 c_parser_consume_pragma (parser);
13872 c_parser_skip_to_pragma_eol (parser);
13873 error_suppress = false;
13875 else if (!error_suppress)
13877 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
13878 error_suppress = true;
13881 substmt = c_parser_omp_structured_block (parser);
13882 substmt = build1 (OMP_SECTION, void_type_node, substmt);
13883 SET_EXPR_LOCATION (substmt, loc);
13884 add_stmt (substmt);
13886 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
13887 "expected %<#pragma omp section%> or %<}%>");
13889 substmt = pop_stmt_list (stmt);
13891 stmt = make_node (OMP_SECTIONS);
13892 SET_EXPR_LOCATION (stmt, sections_loc);
13893 TREE_TYPE (stmt) = void_type_node;
13894 OMP_SECTIONS_BODY (stmt) = substmt;
13896 return add_stmt (stmt);
13899 /* OpenMP 2.5:
13900 # pragma omp sections sections-clause[optseq] newline
13901 sections-scope
13903 LOC is the location of the #pragma token.
13906 #define OMP_SECTIONS_CLAUSE_MASK \
13907 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13913 static tree
13914 c_parser_omp_sections (location_t loc, c_parser *parser,
13915 char *p_name, omp_clause_mask mask, tree *cclauses)
13917 tree block, clauses, ret;
13919 strcat (p_name, " sections");
13920 mask |= OMP_SECTIONS_CLAUSE_MASK;
13921 if (cclauses)
13922 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13924 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13925 if (cclauses)
13927 omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
13928 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
13931 block = c_begin_compound_stmt (true);
13932 ret = c_parser_omp_sections_scope (loc, parser);
13933 if (ret)
13934 OMP_SECTIONS_CLAUSES (ret) = clauses;
13935 block = c_end_compound_stmt (loc, block, true);
13936 add_stmt (block);
13938 return ret;
13941 /* OpenMP 2.5:
13942 # pragma omp parallel parallel-clause[optseq] new-line
13943 structured-block
13944 # pragma omp parallel for parallel-for-clause[optseq] new-line
13945 structured-block
13946 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13947 structured-block
13949 OpenMP 4.0:
13950 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13951 structured-block
13953 LOC is the location of the #pragma token.
13956 #define OMP_PARALLEL_CLAUSE_MASK \
13957 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13958 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13959 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13960 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13967 static tree
13968 c_parser_omp_parallel (location_t loc, c_parser *parser,
13969 char *p_name, omp_clause_mask mask, tree *cclauses)
13971 tree stmt, clauses, block;
13973 strcat (p_name, " parallel");
13974 mask |= OMP_PARALLEL_CLAUSE_MASK;
13976 if (c_parser_next_token_is_keyword (parser, RID_FOR))
13978 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13979 if (cclauses == NULL)
13980 cclauses = cclauses_buf;
13982 c_parser_consume_token (parser);
13983 if (!flag_openmp) /* flag_openmp_simd */
13984 return c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13985 block = c_begin_omp_parallel ();
13986 tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13987 stmt
13988 = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
13989 block);
13990 if (ret == NULL_TREE)
13991 return ret;
13992 OMP_PARALLEL_COMBINED (stmt) = 1;
13993 return stmt;
13995 else if (cclauses)
13997 error_at (loc, "expected %<for%> after %qs", p_name);
13998 c_parser_skip_to_pragma_eol (parser);
13999 return NULL_TREE;
14001 else if (!flag_openmp) /* flag_openmp_simd */
14003 c_parser_skip_to_pragma_eol (parser);
14004 return NULL_TREE;
14006 else if (c_parser_next_token_is (parser, CPP_NAME))
14008 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14009 if (strcmp (p, "sections") == 0)
14011 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
14012 if (cclauses == NULL)
14013 cclauses = cclauses_buf;
14015 c_parser_consume_token (parser);
14016 block = c_begin_omp_parallel ();
14017 c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
14018 stmt = c_finish_omp_parallel (loc,
14019 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
14020 block);
14021 OMP_PARALLEL_COMBINED (stmt) = 1;
14022 return stmt;
14026 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
14028 block = c_begin_omp_parallel ();
14029 c_parser_statement (parser);
14030 stmt = c_finish_omp_parallel (loc, clauses, block);
14032 return stmt;
14035 /* OpenMP 2.5:
14036 # pragma omp single single-clause[optseq] new-line
14037 structured-block
14039 LOC is the location of the #pragma.
14042 #define OMP_SINGLE_CLAUSE_MASK \
14043 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
14046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14048 static tree
14049 c_parser_omp_single (location_t loc, c_parser *parser)
14051 tree stmt = make_node (OMP_SINGLE);
14052 SET_EXPR_LOCATION (stmt, loc);
14053 TREE_TYPE (stmt) = void_type_node;
14055 OMP_SINGLE_CLAUSES (stmt)
14056 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
14057 "#pragma omp single");
14058 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
14060 return add_stmt (stmt);
14063 /* OpenMP 3.0:
14064 # pragma omp task task-clause[optseq] new-line
14066 LOC is the location of the #pragma.
14069 #define OMP_TASK_CLAUSE_MASK \
14070 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
14071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
14072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
14073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
14077 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
14078 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
14080 static tree
14081 c_parser_omp_task (location_t loc, c_parser *parser)
14083 tree clauses, block;
14085 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
14086 "#pragma omp task");
14088 block = c_begin_omp_task ();
14089 c_parser_statement (parser);
14090 return c_finish_omp_task (loc, clauses, block);
14093 /* OpenMP 3.0:
14094 # pragma omp taskwait new-line
14097 static void
14098 c_parser_omp_taskwait (c_parser *parser)
14100 location_t loc = c_parser_peek_token (parser)->location;
14101 c_parser_consume_pragma (parser);
14102 c_parser_skip_to_pragma_eol (parser);
14104 c_finish_omp_taskwait (loc);
14107 /* OpenMP 3.1:
14108 # pragma omp taskyield new-line
14111 static void
14112 c_parser_omp_taskyield (c_parser *parser)
14114 location_t loc = c_parser_peek_token (parser)->location;
14115 c_parser_consume_pragma (parser);
14116 c_parser_skip_to_pragma_eol (parser);
14118 c_finish_omp_taskyield (loc);
14121 /* OpenMP 4.0:
14122 # pragma omp taskgroup new-line
14125 static tree
14126 c_parser_omp_taskgroup (c_parser *parser)
14128 location_t loc = c_parser_peek_token (parser)->location;
14129 c_parser_skip_to_pragma_eol (parser);
14130 return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser));
14133 /* OpenMP 4.0:
14134 # pragma omp cancel cancel-clause[optseq] new-line
14136 LOC is the location of the #pragma.
14139 #define OMP_CANCEL_CLAUSE_MASK \
14140 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
14141 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
14142 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
14143 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
14144 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14146 static void
14147 c_parser_omp_cancel (c_parser *parser)
14149 location_t loc = c_parser_peek_token (parser)->location;
14151 c_parser_consume_pragma (parser);
14152 tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
14153 "#pragma omp cancel");
14155 c_finish_omp_cancel (loc, clauses);
14158 /* OpenMP 4.0:
14159 # pragma omp cancellation point cancelpt-clause[optseq] new-line
14161 LOC is the location of the #pragma.
14164 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
14165 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
14166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
14167 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
14168 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
14170 static void
14171 c_parser_omp_cancellation_point (c_parser *parser)
14173 location_t loc = c_parser_peek_token (parser)->location;
14174 tree clauses;
14175 bool point_seen = false;
14177 c_parser_consume_pragma (parser);
14178 if (c_parser_next_token_is (parser, CPP_NAME))
14180 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14181 if (strcmp (p, "point") == 0)
14183 c_parser_consume_token (parser);
14184 point_seen = true;
14187 if (!point_seen)
14189 c_parser_error (parser, "expected %<point%>");
14190 c_parser_skip_to_pragma_eol (parser);
14191 return;
14194 clauses
14195 = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
14196 "#pragma omp cancellation point");
14198 c_finish_omp_cancellation_point (loc, clauses);
14201 /* OpenMP 4.0:
14202 #pragma omp distribute distribute-clause[optseq] new-line
14203 for-loop */
14205 #define OMP_DISTRIBUTE_CLAUSE_MASK \
14206 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14207 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
14209 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
14211 static tree
14212 c_parser_omp_distribute (location_t loc, c_parser *parser,
14213 char *p_name, omp_clause_mask mask, tree *cclauses)
14215 tree clauses, block, ret;
14217 strcat (p_name, " distribute");
14218 mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
14220 if (c_parser_next_token_is (parser, CPP_NAME))
14222 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14223 bool simd = false;
14224 bool parallel = false;
14226 if (strcmp (p, "simd") == 0)
14227 simd = true;
14228 else
14229 parallel = strcmp (p, "parallel") == 0;
14230 if (parallel || simd)
14232 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
14233 if (cclauses == NULL)
14234 cclauses = cclauses_buf;
14235 c_parser_consume_token (parser);
14236 if (!flag_openmp) /* flag_openmp_simd */
14238 if (simd)
14239 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
14240 else
14241 return c_parser_omp_parallel (loc, parser, p_name, mask,
14242 cclauses);
14244 block = c_begin_compound_stmt (true);
14245 if (simd)
14246 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
14247 else
14248 ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses);
14249 block = c_end_compound_stmt (loc, block, true);
14250 if (ret == NULL)
14251 return ret;
14252 ret = make_node (OMP_DISTRIBUTE);
14253 TREE_TYPE (ret) = void_type_node;
14254 OMP_FOR_BODY (ret) = block;
14255 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
14256 SET_EXPR_LOCATION (ret, loc);
14257 add_stmt (ret);
14258 return ret;
14261 if (!flag_openmp) /* flag_openmp_simd */
14263 c_parser_skip_to_pragma_eol (parser);
14264 return NULL_TREE;
14267 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
14268 if (cclauses)
14270 omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
14271 clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
14274 block = c_begin_compound_stmt (true);
14275 ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL);
14276 block = c_end_compound_stmt (loc, block, true);
14277 add_stmt (block);
14279 return ret;
14282 /* OpenMP 4.0:
14283 # pragma omp teams teams-clause[optseq] new-line
14284 structured-block */
14286 #define OMP_TEAMS_CLAUSE_MASK \
14287 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
14292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
14293 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
14295 static tree
14296 c_parser_omp_teams (location_t loc, c_parser *parser,
14297 char *p_name, omp_clause_mask mask, tree *cclauses)
14299 tree clauses, block, ret;
14301 strcat (p_name, " teams");
14302 mask |= OMP_TEAMS_CLAUSE_MASK;
14304 if (c_parser_next_token_is (parser, CPP_NAME))
14306 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14307 if (strcmp (p, "distribute") == 0)
14309 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
14310 if (cclauses == NULL)
14311 cclauses = cclauses_buf;
14313 c_parser_consume_token (parser);
14314 if (!flag_openmp) /* flag_openmp_simd */
14315 return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
14316 block = c_begin_compound_stmt (true);
14317 ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
14318 block = c_end_compound_stmt (loc, block, true);
14319 if (ret == NULL)
14320 return ret;
14321 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
14322 ret = make_node (OMP_TEAMS);
14323 TREE_TYPE (ret) = void_type_node;
14324 OMP_TEAMS_CLAUSES (ret) = clauses;
14325 OMP_TEAMS_BODY (ret) = block;
14326 return add_stmt (ret);
14329 if (!flag_openmp) /* flag_openmp_simd */
14331 c_parser_skip_to_pragma_eol (parser);
14332 return NULL_TREE;
14335 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
14336 if (cclauses)
14338 omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
14339 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
14342 tree stmt = make_node (OMP_TEAMS);
14343 TREE_TYPE (stmt) = void_type_node;
14344 OMP_TEAMS_CLAUSES (stmt) = clauses;
14345 OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser);
14347 return add_stmt (stmt);
14350 /* OpenMP 4.0:
14351 # pragma omp target data target-data-clause[optseq] new-line
14352 structured-block */
14354 #define OMP_TARGET_DATA_CLAUSE_MASK \
14355 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
14356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
14357 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14359 static tree
14360 c_parser_omp_target_data (location_t loc, c_parser *parser)
14362 tree stmt = make_node (OMP_TARGET_DATA);
14363 TREE_TYPE (stmt) = void_type_node;
14365 OMP_TARGET_DATA_CLAUSES (stmt)
14366 = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
14367 "#pragma omp target data");
14368 keep_next_level ();
14369 tree block = c_begin_compound_stmt (true);
14370 add_stmt (c_parser_omp_structured_block (parser));
14371 OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
14373 SET_EXPR_LOCATION (stmt, loc);
14374 return add_stmt (stmt);
14377 /* OpenMP 4.0:
14378 # pragma omp target update target-update-clause[optseq] new-line */
14380 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
14381 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
14382 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
14383 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
14384 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14386 static bool
14387 c_parser_omp_target_update (location_t loc, c_parser *parser,
14388 enum pragma_context context)
14390 if (context == pragma_stmt)
14392 error_at (loc,
14393 "%<#pragma omp target update%> may only be "
14394 "used in compound statements");
14395 c_parser_skip_to_pragma_eol (parser);
14396 return false;
14399 tree clauses
14400 = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
14401 "#pragma omp target update");
14402 if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
14403 && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
14405 error_at (loc,
14406 "%<#pragma omp target update must contain at least one "
14407 "%<from%> or %<to%> clauses");
14408 return false;
14411 tree stmt = make_node (OMP_TARGET_UPDATE);
14412 TREE_TYPE (stmt) = void_type_node;
14413 OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
14414 SET_EXPR_LOCATION (stmt, loc);
14415 add_stmt (stmt);
14416 return false;
14419 /* OpenMP 4.0:
14420 # pragma omp target target-clause[optseq] new-line
14421 structured-block */
14423 #define OMP_TARGET_CLAUSE_MASK \
14424 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
14425 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
14426 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14428 static bool
14429 c_parser_omp_target (c_parser *parser, enum pragma_context context)
14431 location_t loc = c_parser_peek_token (parser)->location;
14432 c_parser_consume_pragma (parser);
14434 if (context != pragma_stmt && context != pragma_compound)
14436 c_parser_error (parser, "expected declaration specifiers");
14437 c_parser_skip_to_pragma_eol (parser);
14438 return false;
14441 if (c_parser_next_token_is (parser, CPP_NAME))
14443 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14445 if (strcmp (p, "teams") == 0)
14447 tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
14448 char p_name[sizeof ("#pragma omp target teams distribute "
14449 "parallel for simd")];
14451 c_parser_consume_token (parser);
14452 strcpy (p_name, "#pragma omp target");
14453 if (!flag_openmp) /* flag_openmp_simd */
14455 tree stmt = c_parser_omp_teams (loc, parser, p_name,
14456 OMP_TARGET_CLAUSE_MASK,
14457 cclauses);
14458 return stmt != NULL_TREE;
14460 keep_next_level ();
14461 tree block = c_begin_compound_stmt (true);
14462 tree ret = c_parser_omp_teams (loc, parser, p_name,
14463 OMP_TARGET_CLAUSE_MASK, cclauses);
14464 block = c_end_compound_stmt (loc, block, true);
14465 if (ret == NULL_TREE)
14466 return false;
14467 tree stmt = make_node (OMP_TARGET);
14468 TREE_TYPE (stmt) = void_type_node;
14469 OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
14470 OMP_TARGET_BODY (stmt) = block;
14471 add_stmt (stmt);
14472 return true;
14474 else if (!flag_openmp) /* flag_openmp_simd */
14476 c_parser_skip_to_pragma_eol (parser);
14477 return false;
14479 else if (strcmp (p, "data") == 0)
14481 c_parser_consume_token (parser);
14482 c_parser_omp_target_data (loc, parser);
14483 return true;
14485 else if (strcmp (p, "update") == 0)
14487 c_parser_consume_token (parser);
14488 return c_parser_omp_target_update (loc, parser, context);
14492 tree stmt = make_node (OMP_TARGET);
14493 TREE_TYPE (stmt) = void_type_node;
14495 OMP_TARGET_CLAUSES (stmt)
14496 = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
14497 "#pragma omp target");
14498 keep_next_level ();
14499 tree block = c_begin_compound_stmt (true);
14500 add_stmt (c_parser_omp_structured_block (parser));
14501 OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
14503 SET_EXPR_LOCATION (stmt, loc);
14504 add_stmt (stmt);
14505 return true;
14508 /* OpenMP 4.0:
14509 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
14511 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
14512 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
14513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14514 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
14515 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
14516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
14517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
14519 static void
14520 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
14522 vec<c_token> clauses = vNULL;
14523 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14525 c_token *token = c_parser_peek_token (parser);
14526 if (token->type == CPP_EOF)
14528 c_parser_skip_to_pragma_eol (parser);
14529 clauses.release ();
14530 return;
14532 clauses.safe_push (*token);
14533 c_parser_consume_token (parser);
14535 clauses.safe_push (*c_parser_peek_token (parser));
14536 c_parser_skip_to_pragma_eol (parser);
14538 while (c_parser_next_token_is (parser, CPP_PRAGMA))
14540 if (c_parser_peek_token (parser)->pragma_kind
14541 != PRAGMA_OMP_DECLARE_REDUCTION
14542 || c_parser_peek_2nd_token (parser)->type != CPP_NAME
14543 || strcmp (IDENTIFIER_POINTER
14544 (c_parser_peek_2nd_token (parser)->value),
14545 "simd") != 0)
14547 c_parser_error (parser,
14548 "%<#pragma omp declare simd%> must be followed by "
14549 "function declaration or definition or another "
14550 "%<#pragma omp declare simd%>");
14551 clauses.release ();
14552 return;
14554 c_parser_consume_pragma (parser);
14555 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14557 c_token *token = c_parser_peek_token (parser);
14558 if (token->type == CPP_EOF)
14560 c_parser_skip_to_pragma_eol (parser);
14561 clauses.release ();
14562 return;
14564 clauses.safe_push (*token);
14565 c_parser_consume_token (parser);
14567 clauses.safe_push (*c_parser_peek_token (parser));
14568 c_parser_skip_to_pragma_eol (parser);
14571 /* Make sure nothing tries to read past the end of the tokens. */
14572 c_token eof_token;
14573 memset (&eof_token, 0, sizeof (eof_token));
14574 eof_token.type = CPP_EOF;
14575 clauses.safe_push (eof_token);
14576 clauses.safe_push (eof_token);
14578 switch (context)
14580 case pragma_external:
14581 if (c_parser_next_token_is (parser, CPP_KEYWORD)
14582 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14584 int ext = disable_extension_diagnostics ();
14586 c_parser_consume_token (parser);
14587 while (c_parser_next_token_is (parser, CPP_KEYWORD)
14588 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14589 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14590 NULL, clauses);
14591 restore_extension_diagnostics (ext);
14593 else
14594 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14595 NULL, clauses);
14596 break;
14597 case pragma_struct:
14598 case pragma_param:
14599 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14600 "function declaration or definition");
14601 break;
14602 case pragma_compound:
14603 case pragma_stmt:
14604 if (c_parser_next_token_is (parser, CPP_KEYWORD)
14605 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14607 int ext = disable_extension_diagnostics ();
14609 c_parser_consume_token (parser);
14610 while (c_parser_next_token_is (parser, CPP_KEYWORD)
14611 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14612 if (c_parser_next_tokens_start_declaration (parser))
14614 c_parser_declaration_or_fndef (parser, true, true, true, true,
14615 true, NULL, clauses);
14616 restore_extension_diagnostics (ext);
14617 break;
14619 restore_extension_diagnostics (ext);
14621 else if (c_parser_next_tokens_start_declaration (parser))
14623 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
14624 NULL, clauses);
14625 break;
14627 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14628 "function declaration or definition");
14629 break;
14630 default:
14631 gcc_unreachable ();
14633 clauses.release ();
14636 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14637 and put that into "omp declare simd" attribute. */
14639 static void
14640 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
14641 vec<c_token> clauses)
14643 if (flag_cilkplus
14644 && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14646 error ("%<#pragma omp declare simd%> cannot be used in the same "
14647 "function marked as a Cilk Plus SIMD-enabled function");
14648 vec_free (parser->cilk_simd_fn_tokens);
14649 return;
14652 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
14653 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14654 has already processed the tokens. */
14655 if (clauses.exists () && clauses[0].type == CPP_EOF)
14656 return;
14657 if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
14659 error ("%<#pragma omp declare simd%> not immediately followed by "
14660 "a function declaration or definition");
14661 clauses[0].type = CPP_EOF;
14662 return;
14664 if (clauses.exists () && clauses[0].type != CPP_NAME)
14666 error_at (DECL_SOURCE_LOCATION (fndecl),
14667 "%<#pragma omp declare simd%> not immediately followed by "
14668 "a single function declaration or definition");
14669 clauses[0].type = CPP_EOF;
14670 return;
14673 if (parms == NULL_TREE)
14674 parms = DECL_ARGUMENTS (fndecl);
14676 unsigned int tokens_avail = parser->tokens_avail;
14677 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14678 bool is_cilkplus_cilk_simd_fn = false;
14680 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14682 parser->tokens = parser->cilk_simd_fn_tokens->address ();
14683 parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens);
14684 is_cilkplus_cilk_simd_fn = true;
14686 else
14688 parser->tokens = clauses.address ();
14689 parser->tokens_avail = clauses.length ();
14692 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
14693 while (parser->tokens_avail > 3)
14695 c_token *token = c_parser_peek_token (parser);
14696 if (!is_cilkplus_cilk_simd_fn)
14697 gcc_assert (token->type == CPP_NAME
14698 && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
14699 else
14700 gcc_assert (token->type == CPP_NAME
14701 && is_cilkplus_vector_p (token->value));
14702 c_parser_consume_token (parser);
14703 parser->in_pragma = true;
14705 tree c = NULL_TREE;
14706 if (is_cilkplus_cilk_simd_fn)
14707 c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
14708 "SIMD-enabled functions attribute");
14709 else
14710 c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
14711 "#pragma omp declare simd");
14712 c = c_omp_declare_simd_clauses_to_numbers (parms, c);
14713 if (c != NULL_TREE)
14714 c = tree_cons (NULL_TREE, c, NULL_TREE);
14715 if (is_cilkplus_cilk_simd_fn)
14717 tree k = build_tree_list (get_identifier ("cilk simd function"),
14718 NULL_TREE);
14719 TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
14720 DECL_ATTRIBUTES (fndecl) = k;
14722 c = build_tree_list (get_identifier ("omp declare simd"), c);
14723 TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
14724 DECL_ATTRIBUTES (fndecl) = c;
14727 parser->tokens = &parser->tokens_buf[0];
14728 parser->tokens_avail = tokens_avail;
14729 if (clauses.exists ())
14730 clauses[0].type = CPP_PRAGMA;
14732 if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14733 vec_free (parser->cilk_simd_fn_tokens);
14737 /* OpenMP 4.0:
14738 # pragma omp declare target new-line
14739 declarations and definitions
14740 # pragma omp end declare target new-line */
14742 static void
14743 c_parser_omp_declare_target (c_parser *parser)
14745 c_parser_skip_to_pragma_eol (parser);
14746 current_omp_declare_target_attribute++;
14749 static void
14750 c_parser_omp_end_declare_target (c_parser *parser)
14752 location_t loc = c_parser_peek_token (parser)->location;
14753 c_parser_consume_pragma (parser);
14754 if (c_parser_next_token_is (parser, CPP_NAME)
14755 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14756 "declare") == 0)
14758 c_parser_consume_token (parser);
14759 if (c_parser_next_token_is (parser, CPP_NAME)
14760 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14761 "target") == 0)
14762 c_parser_consume_token (parser);
14763 else
14765 c_parser_error (parser, "expected %<target%>");
14766 c_parser_skip_to_pragma_eol (parser);
14767 return;
14770 else
14772 c_parser_error (parser, "expected %<declare%>");
14773 c_parser_skip_to_pragma_eol (parser);
14774 return;
14776 c_parser_skip_to_pragma_eol (parser);
14777 if (!current_omp_declare_target_attribute)
14778 error_at (loc, "%<#pragma omp end declare target%> without corresponding "
14779 "%<#pragma omp declare target%>");
14780 else
14781 current_omp_declare_target_attribute--;
14785 /* OpenMP 4.0
14786 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14787 initializer-clause[opt] new-line
14789 initializer-clause:
14790 initializer (omp_priv = initializer)
14791 initializer (function-name (argument-list)) */
14793 static void
14794 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
14796 unsigned int tokens_avail = 0, i;
14797 vec<tree> types = vNULL;
14798 vec<c_token> clauses = vNULL;
14799 enum tree_code reduc_code = ERROR_MARK;
14800 tree reduc_id = NULL_TREE;
14801 tree type;
14802 location_t rloc = c_parser_peek_token (parser)->location;
14804 if (context == pragma_struct || context == pragma_param)
14806 error ("%<#pragma omp declare reduction%> not at file or block scope");
14807 goto fail;
14810 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14811 goto fail;
14813 switch (c_parser_peek_token (parser)->type)
14815 case CPP_PLUS:
14816 reduc_code = PLUS_EXPR;
14817 break;
14818 case CPP_MULT:
14819 reduc_code = MULT_EXPR;
14820 break;
14821 case CPP_MINUS:
14822 reduc_code = MINUS_EXPR;
14823 break;
14824 case CPP_AND:
14825 reduc_code = BIT_AND_EXPR;
14826 break;
14827 case CPP_XOR:
14828 reduc_code = BIT_XOR_EXPR;
14829 break;
14830 case CPP_OR:
14831 reduc_code = BIT_IOR_EXPR;
14832 break;
14833 case CPP_AND_AND:
14834 reduc_code = TRUTH_ANDIF_EXPR;
14835 break;
14836 case CPP_OR_OR:
14837 reduc_code = TRUTH_ORIF_EXPR;
14838 break;
14839 case CPP_NAME:
14840 const char *p;
14841 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14842 if (strcmp (p, "min") == 0)
14844 reduc_code = MIN_EXPR;
14845 break;
14847 if (strcmp (p, "max") == 0)
14849 reduc_code = MAX_EXPR;
14850 break;
14852 reduc_id = c_parser_peek_token (parser)->value;
14853 break;
14854 default:
14855 c_parser_error (parser,
14856 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14857 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14858 goto fail;
14861 tree orig_reduc_id, reduc_decl;
14862 orig_reduc_id = reduc_id;
14863 reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
14864 reduc_decl = c_omp_reduction_decl (reduc_id);
14865 c_parser_consume_token (parser);
14867 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
14868 goto fail;
14870 while (true)
14872 location_t loc = c_parser_peek_token (parser)->location;
14873 struct c_type_name *ctype = c_parser_type_name (parser);
14874 if (ctype != NULL)
14876 type = groktypename (ctype, NULL, NULL);
14877 if (type == error_mark_node)
14879 else if ((INTEGRAL_TYPE_P (type)
14880 || TREE_CODE (type) == REAL_TYPE
14881 || TREE_CODE (type) == COMPLEX_TYPE)
14882 && orig_reduc_id == NULL_TREE)
14883 error_at (loc, "predeclared arithmetic type in "
14884 "%<#pragma omp declare reduction%>");
14885 else if (TREE_CODE (type) == FUNCTION_TYPE
14886 || TREE_CODE (type) == ARRAY_TYPE)
14887 error_at (loc, "function or array type in "
14888 "%<#pragma omp declare reduction%>");
14889 else if (TYPE_QUALS_NO_ADDR_SPACE (type))
14890 error_at (loc, "const, volatile or restrict qualified type in "
14891 "%<#pragma omp declare reduction%>");
14892 else
14894 tree t;
14895 for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
14896 if (comptypes (TREE_PURPOSE (t), type))
14898 error_at (loc, "redeclaration of %qs "
14899 "%<#pragma omp declare reduction%> for "
14900 "type %qT",
14901 IDENTIFIER_POINTER (reduc_id)
14902 + sizeof ("omp declare reduction ") - 1,
14903 type);
14904 location_t ploc
14905 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
14906 0));
14907 error_at (ploc, "previous %<#pragma omp declare "
14908 "reduction%>");
14909 break;
14911 if (t == NULL_TREE)
14912 types.safe_push (type);
14914 if (c_parser_next_token_is (parser, CPP_COMMA))
14915 c_parser_consume_token (parser);
14916 else
14917 break;
14919 else
14920 break;
14923 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
14924 || types.is_empty ())
14926 fail:
14927 clauses.release ();
14928 types.release ();
14929 while (true)
14931 c_token *token = c_parser_peek_token (parser);
14932 if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
14933 break;
14934 c_parser_consume_token (parser);
14936 c_parser_skip_to_pragma_eol (parser);
14937 return;
14940 if (types.length () > 1)
14942 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14944 c_token *token = c_parser_peek_token (parser);
14945 if (token->type == CPP_EOF)
14946 goto fail;
14947 clauses.safe_push (*token);
14948 c_parser_consume_token (parser);
14950 clauses.safe_push (*c_parser_peek_token (parser));
14951 c_parser_skip_to_pragma_eol (parser);
14953 /* Make sure nothing tries to read past the end of the tokens. */
14954 c_token eof_token;
14955 memset (&eof_token, 0, sizeof (eof_token));
14956 eof_token.type = CPP_EOF;
14957 clauses.safe_push (eof_token);
14958 clauses.safe_push (eof_token);
14961 int errs = errorcount;
14962 FOR_EACH_VEC_ELT (types, i, type)
14964 tokens_avail = parser->tokens_avail;
14965 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14966 if (!clauses.is_empty ())
14968 parser->tokens = clauses.address ();
14969 parser->tokens_avail = clauses.length ();
14970 parser->in_pragma = true;
14973 bool nested = current_function_decl != NULL_TREE;
14974 if (nested)
14975 c_push_function_context ();
14976 tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
14977 reduc_id, default_function_type);
14978 current_function_decl = fndecl;
14979 allocate_struct_function (fndecl, true);
14980 push_scope ();
14981 tree stmt = push_stmt_list ();
14982 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14983 warn about these. */
14984 tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
14985 get_identifier ("omp_out"), type);
14986 DECL_ARTIFICIAL (omp_out) = 1;
14987 DECL_CONTEXT (omp_out) = fndecl;
14988 pushdecl (omp_out);
14989 tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
14990 get_identifier ("omp_in"), type);
14991 DECL_ARTIFICIAL (omp_in) = 1;
14992 DECL_CONTEXT (omp_in) = fndecl;
14993 pushdecl (omp_in);
14994 struct c_expr combiner = c_parser_expression (parser);
14995 struct c_expr initializer;
14996 tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
14997 bool bad = false;
14998 initializer.value = error_mark_node;
14999 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
15000 bad = true;
15001 else if (c_parser_next_token_is (parser, CPP_NAME)
15002 && strcmp (IDENTIFIER_POINTER
15003 (c_parser_peek_token (parser)->value),
15004 "initializer") == 0)
15006 c_parser_consume_token (parser);
15007 pop_scope ();
15008 push_scope ();
15009 omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
15010 get_identifier ("omp_priv"), type);
15011 DECL_ARTIFICIAL (omp_priv) = 1;
15012 DECL_INITIAL (omp_priv) = error_mark_node;
15013 DECL_CONTEXT (omp_priv) = fndecl;
15014 pushdecl (omp_priv);
15015 omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
15016 get_identifier ("omp_orig"), type);
15017 DECL_ARTIFICIAL (omp_orig) = 1;
15018 DECL_CONTEXT (omp_orig) = fndecl;
15019 pushdecl (omp_orig);
15020 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15021 bad = true;
15022 else if (!c_parser_next_token_is (parser, CPP_NAME))
15024 c_parser_error (parser, "expected %<omp_priv%> or "
15025 "function-name");
15026 bad = true;
15028 else if (strcmp (IDENTIFIER_POINTER
15029 (c_parser_peek_token (parser)->value),
15030 "omp_priv") != 0)
15032 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
15033 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
15035 c_parser_error (parser, "expected function-name %<(%>");
15036 bad = true;
15038 else
15039 initializer = c_parser_postfix_expression (parser);
15040 if (initializer.value
15041 && TREE_CODE (initializer.value) == CALL_EXPR)
15043 int j;
15044 tree c = initializer.value;
15045 for (j = 0; j < call_expr_nargs (c); j++)
15046 if (TREE_CODE (CALL_EXPR_ARG (c, j)) == ADDR_EXPR
15047 && TREE_OPERAND (CALL_EXPR_ARG (c, j), 0) == omp_priv)
15048 break;
15049 if (j == call_expr_nargs (c))
15050 error ("one of the initializer call arguments should be "
15051 "%<&omp_priv%>");
15054 else
15056 c_parser_consume_token (parser);
15057 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
15058 bad = true;
15059 else
15061 tree st = push_stmt_list ();
15062 start_init (omp_priv, NULL_TREE, 0);
15063 location_t loc = c_parser_peek_token (parser)->location;
15064 struct c_expr init = c_parser_initializer (parser);
15065 finish_init ();
15066 finish_decl (omp_priv, loc, init.value,
15067 init.original_type, NULL_TREE);
15068 pop_stmt_list (st);
15071 if (!bad
15072 && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
15073 bad = true;
15076 if (!bad)
15078 c_parser_skip_to_pragma_eol (parser);
15080 tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
15081 DECL_INITIAL (reduc_decl));
15082 DECL_INITIAL (reduc_decl) = t;
15083 DECL_SOURCE_LOCATION (omp_out) = rloc;
15084 TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
15085 TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
15086 TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
15087 walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
15088 &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
15089 if (omp_priv)
15091 DECL_SOURCE_LOCATION (omp_priv) = rloc;
15092 TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
15093 TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
15094 TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
15095 walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
15096 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
15097 walk_tree (&DECL_INITIAL (omp_priv),
15098 c_check_omp_declare_reduction_r,
15099 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
15103 pop_stmt_list (stmt);
15104 pop_scope ();
15105 if (cfun->language != NULL)
15107 ggc_free (cfun->language);
15108 cfun->language = NULL;
15110 set_cfun (NULL);
15111 current_function_decl = NULL_TREE;
15112 if (nested)
15113 c_pop_function_context ();
15115 if (!clauses.is_empty ())
15117 parser->tokens = &parser->tokens_buf[0];
15118 parser->tokens_avail = tokens_avail;
15120 if (bad)
15121 goto fail;
15122 if (errs != errorcount)
15123 break;
15126 clauses.release ();
15127 types.release ();
15131 /* OpenMP 4.0
15132 #pragma omp declare simd declare-simd-clauses[optseq] new-line
15133 #pragma omp declare reduction (reduction-id : typename-list : expression) \
15134 initializer-clause[opt] new-line
15135 #pragma omp declare target new-line */
15137 static void
15138 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
15140 c_parser_consume_pragma (parser);
15141 if (c_parser_next_token_is (parser, CPP_NAME))
15143 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15144 if (strcmp (p, "simd") == 0)
15146 /* c_parser_consume_token (parser); done in
15147 c_parser_omp_declare_simd. */
15148 c_parser_omp_declare_simd (parser, context);
15149 return;
15151 if (strcmp (p, "reduction") == 0)
15153 c_parser_consume_token (parser);
15154 c_parser_omp_declare_reduction (parser, context);
15155 return;
15157 if (!flag_openmp) /* flag_openmp_simd */
15159 c_parser_skip_to_pragma_eol (parser);
15160 return;
15162 if (strcmp (p, "target") == 0)
15164 c_parser_consume_token (parser);
15165 c_parser_omp_declare_target (parser);
15166 return;
15170 c_parser_error (parser, "expected %<simd%> or %<reduction%> "
15171 "or %<target%>");
15172 c_parser_skip_to_pragma_eol (parser);
15175 /* Main entry point to parsing most OpenMP pragmas. */
15177 static void
15178 c_parser_omp_construct (c_parser *parser)
15180 enum pragma_kind p_kind;
15181 location_t loc;
15182 tree stmt;
15183 char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
15184 omp_clause_mask mask (0);
15186 loc = c_parser_peek_token (parser)->location;
15187 p_kind = c_parser_peek_token (parser)->pragma_kind;
15188 c_parser_consume_pragma (parser);
15190 switch (p_kind)
15192 case PRAGMA_OACC_CACHE:
15193 strcpy (p_name, "#pragma acc");
15194 stmt = c_parser_oacc_cache (loc, parser);
15195 break;
15196 case PRAGMA_OACC_DATA:
15197 stmt = c_parser_oacc_data (loc, parser);
15198 break;
15199 case PRAGMA_OACC_KERNELS:
15200 strcpy (p_name, "#pragma acc");
15201 stmt = c_parser_oacc_kernels (loc, parser, p_name);
15202 break;
15203 case PRAGMA_OACC_LOOP:
15204 strcpy (p_name, "#pragma acc");
15205 stmt = c_parser_oacc_loop (loc, parser, p_name);
15206 break;
15207 case PRAGMA_OACC_PARALLEL:
15208 strcpy (p_name, "#pragma acc");
15209 stmt = c_parser_oacc_parallel (loc, parser, p_name);
15210 break;
15211 case PRAGMA_OACC_WAIT:
15212 strcpy (p_name, "#pragma wait");
15213 stmt = c_parser_oacc_wait (loc, parser, p_name);
15214 break;
15215 case PRAGMA_OMP_ATOMIC:
15216 c_parser_omp_atomic (loc, parser);
15217 return;
15218 case PRAGMA_OMP_CRITICAL:
15219 stmt = c_parser_omp_critical (loc, parser);
15220 break;
15221 case PRAGMA_OMP_DISTRIBUTE:
15222 strcpy (p_name, "#pragma omp");
15223 stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL);
15224 break;
15225 case PRAGMA_OMP_FOR:
15226 strcpy (p_name, "#pragma omp");
15227 stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL);
15228 break;
15229 case PRAGMA_OMP_MASTER:
15230 stmt = c_parser_omp_master (loc, parser);
15231 break;
15232 case PRAGMA_OMP_ORDERED:
15233 stmt = c_parser_omp_ordered (loc, parser);
15234 break;
15235 case PRAGMA_OMP_PARALLEL:
15236 strcpy (p_name, "#pragma omp");
15237 stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL);
15238 break;
15239 case PRAGMA_OMP_SECTIONS:
15240 strcpy (p_name, "#pragma omp");
15241 stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
15242 break;
15243 case PRAGMA_OMP_SIMD:
15244 strcpy (p_name, "#pragma omp");
15245 stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL);
15246 break;
15247 case PRAGMA_OMP_SINGLE:
15248 stmt = c_parser_omp_single (loc, parser);
15249 break;
15250 case PRAGMA_OMP_TASK:
15251 stmt = c_parser_omp_task (loc, parser);
15252 break;
15253 case PRAGMA_OMP_TASKGROUP:
15254 stmt = c_parser_omp_taskgroup (parser);
15255 break;
15256 case PRAGMA_OMP_TEAMS:
15257 strcpy (p_name, "#pragma omp");
15258 stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL);
15259 break;
15260 default:
15261 gcc_unreachable ();
15264 if (stmt)
15265 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
15269 /* OpenMP 2.5:
15270 # pragma omp threadprivate (variable-list) */
15272 static void
15273 c_parser_omp_threadprivate (c_parser *parser)
15275 tree vars, t;
15276 location_t loc;
15278 c_parser_consume_pragma (parser);
15279 loc = c_parser_peek_token (parser)->location;
15280 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
15282 /* Mark every variable in VARS to be assigned thread local storage. */
15283 for (t = vars; t; t = TREE_CHAIN (t))
15285 tree v = TREE_PURPOSE (t);
15287 /* FIXME diagnostics: Ideally we should keep individual
15288 locations for all the variables in the var list to make the
15289 following errors more precise. Perhaps
15290 c_parser_omp_var_list_parens() should construct a list of
15291 locations to go along with the var list. */
15293 /* If V had already been marked threadprivate, it doesn't matter
15294 whether it had been used prior to this point. */
15295 if (TREE_CODE (v) != VAR_DECL)
15296 error_at (loc, "%qD is not a variable", v);
15297 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
15298 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
15299 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
15300 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
15301 else if (TREE_TYPE (v) == error_mark_node)
15303 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
15304 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
15305 else
15307 if (! DECL_THREAD_LOCAL_P (v))
15309 set_decl_tls_model (v, decl_default_tls_model (v));
15310 /* If rtl has been already set for this var, call
15311 make_decl_rtl once again, so that encode_section_info
15312 has a chance to look at the new decl flags. */
15313 if (DECL_RTL_SET_P (v))
15314 make_decl_rtl (v);
15316 C_DECL_THREADPRIVATE_P (v) = 1;
15320 c_parser_skip_to_pragma_eol (parser);
15323 /* Cilk Plus <#pragma simd> parsing routines. */
15325 /* Helper function for c_parser_pragma. Perform some sanity checking
15326 for <#pragma simd> constructs. Returns FALSE if there was a
15327 problem. */
15329 static bool
15330 c_parser_cilk_verify_simd (c_parser *parser,
15331 enum pragma_context context)
15333 if (!flag_cilkplus)
15335 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
15336 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
15337 return false;
15339 if (context == pragma_external)
15341 c_parser_error (parser,"pragma simd must be inside a function");
15342 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
15343 return false;
15345 return true;
15348 /* Cilk Plus:
15349 This function is shared by SIMD-enabled functions and #pragma simd.
15350 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
15351 CLAUSES is unused. The main purpose of this function is to parse a
15352 vectorlength attribute or clause and check for parse errors.
15353 When IS_SIMD_FN is true then the function is merely caching the tokens
15354 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
15355 cache is cleared since there is no reason to continue.
15356 Syntax:
15357 vectorlength ( constant-expression ) */
15359 static tree
15360 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses,
15361 bool is_simd_fn)
15363 if (is_simd_fn)
15364 check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength");
15365 else
15366 /* The vectorlength clause behaves exactly like OpenMP's safelen
15367 clause. Represent it in OpenMP terms. */
15368 check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
15370 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15371 return clauses;
15373 location_t loc = c_parser_peek_token (parser)->location;
15374 tree expr = c_parser_expr_no_commas (parser, NULL).value;
15375 expr = c_fully_fold (expr, false, NULL);
15377 /* If expr is an error_mark_node then the above function would have
15378 emitted an error. No reason to do it twice. */
15379 if (expr == error_mark_node)
15381 else if (!TREE_TYPE (expr)
15382 || !TREE_CONSTANT (expr)
15383 || !INTEGRAL_TYPE_P (TREE_TYPE (expr)))
15385 error_at (loc, "vectorlength must be an integer constant");
15386 else if (wi::exact_log2 (expr) == -1)
15387 error_at (loc, "vectorlength must be a power of 2");
15388 else
15390 if (is_simd_fn)
15392 tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN);
15393 OMP_CLAUSE_SIMDLEN_EXPR (u) = expr;
15394 OMP_CLAUSE_CHAIN (u) = clauses;
15395 clauses = u;
15397 else
15399 tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN);
15400 OMP_CLAUSE_SAFELEN_EXPR (u) = expr;
15401 OMP_CLAUSE_CHAIN (u) = clauses;
15402 clauses = u;
15406 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
15408 return clauses;
15411 /* Cilk Plus:
15412 linear ( simd-linear-variable-list )
15414 simd-linear-variable-list:
15415 simd-linear-variable
15416 simd-linear-variable-list , simd-linear-variable
15418 simd-linear-variable:
15419 id-expression
15420 id-expression : simd-linear-step
15422 simd-linear-step:
15423 conditional-expression */
15425 static tree
15426 c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
15428 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15429 return clauses;
15431 location_t loc = c_parser_peek_token (parser)->location;
15433 if (c_parser_next_token_is_not (parser, CPP_NAME)
15434 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
15435 c_parser_error (parser, "expected identifier");
15437 while (c_parser_next_token_is (parser, CPP_NAME)
15438 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
15440 tree var = lookup_name (c_parser_peek_token (parser)->value);
15442 if (var == NULL)
15444 undeclared_variable (c_parser_peek_token (parser)->location,
15445 c_parser_peek_token (parser)->value);
15446 c_parser_consume_token (parser);
15448 else if (var == error_mark_node)
15449 c_parser_consume_token (parser);
15450 else
15452 tree step = integer_one_node;
15454 /* Parse the linear step if present. */
15455 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
15457 c_parser_consume_token (parser);
15458 c_parser_consume_token (parser);
15460 tree expr = c_parser_expr_no_commas (parser, NULL).value;
15461 expr = c_fully_fold (expr, false, NULL);
15463 if (TREE_TYPE (expr)
15464 && INTEGRAL_TYPE_P (TREE_TYPE (expr))
15465 && (TREE_CONSTANT (expr)
15466 || DECL_P (expr)))
15467 step = expr;
15468 else
15469 c_parser_error (parser,
15470 "step size must be an integer constant "
15471 "expression or an integer variable");
15473 else
15474 c_parser_consume_token (parser);
15476 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
15477 tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR);
15478 OMP_CLAUSE_DECL (u) = var;
15479 OMP_CLAUSE_LINEAR_STEP (u) = step;
15480 OMP_CLAUSE_CHAIN (u) = clauses;
15481 clauses = u;
15484 if (c_parser_next_token_is_not (parser, CPP_COMMA))
15485 break;
15487 c_parser_consume_token (parser);
15490 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
15492 return clauses;
15495 /* Returns the name of the next clause. If the clause is not
15496 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
15497 not consumed. Otherwise, the appropriate pragma_simd_clause is
15498 returned and the token is consumed. */
15500 static pragma_omp_clause
15501 c_parser_cilk_clause_name (c_parser *parser)
15503 pragma_omp_clause result;
15504 c_token *token = c_parser_peek_token (parser);
15506 if (!token->value || token->type != CPP_NAME)
15507 return PRAGMA_CILK_CLAUSE_NONE;
15509 const char *p = IDENTIFIER_POINTER (token->value);
15511 if (!strcmp (p, "vectorlength"))
15512 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
15513 else if (!strcmp (p, "linear"))
15514 result = PRAGMA_CILK_CLAUSE_LINEAR;
15515 else if (!strcmp (p, "private"))
15516 result = PRAGMA_CILK_CLAUSE_PRIVATE;
15517 else if (!strcmp (p, "firstprivate"))
15518 result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
15519 else if (!strcmp (p, "lastprivate"))
15520 result = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
15521 else if (!strcmp (p, "reduction"))
15522 result = PRAGMA_CILK_CLAUSE_REDUCTION;
15523 else
15524 return PRAGMA_CILK_CLAUSE_NONE;
15526 c_parser_consume_token (parser);
15527 return result;
15530 /* Parse all #<pragma simd> clauses. Return the list of clauses
15531 found. */
15533 static tree
15534 c_parser_cilk_all_clauses (c_parser *parser)
15536 tree clauses = NULL;
15538 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15540 pragma_omp_clause c_kind;
15542 c_kind = c_parser_cilk_clause_name (parser);
15544 switch (c_kind)
15546 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
15547 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false);
15548 break;
15549 case PRAGMA_CILK_CLAUSE_LINEAR:
15550 clauses = c_parser_cilk_clause_linear (parser, clauses);
15551 break;
15552 case PRAGMA_CILK_CLAUSE_PRIVATE:
15553 /* Use the OpenMP counterpart. */
15554 clauses = c_parser_omp_clause_private (parser, clauses);
15555 break;
15556 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE:
15557 /* Use the OpenMP counterpart. */
15558 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
15559 break;
15560 case PRAGMA_CILK_CLAUSE_LASTPRIVATE:
15561 /* Use the OpenMP counterpart. */
15562 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
15563 break;
15564 case PRAGMA_CILK_CLAUSE_REDUCTION:
15565 /* Use the OpenMP counterpart. */
15566 clauses = c_parser_omp_clause_reduction (parser, clauses);
15567 break;
15568 default:
15569 c_parser_error (parser, "expected %<#pragma simd%> clause");
15570 goto saw_error;
15574 saw_error:
15575 c_parser_skip_to_pragma_eol (parser);
15576 return c_finish_cilk_clauses (clauses);
15579 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15580 Here is the correct syntax of this pragma:
15581 #pragma cilk grainsize = <EXP>
15584 static void
15585 c_parser_cilk_grainsize (c_parser *parser)
15587 extern tree convert_to_integer (tree, tree);
15589 /* consume the 'grainsize' keyword. */
15590 c_parser_consume_pragma (parser);
15592 if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0)
15594 struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL);
15595 if (g_expr.value == error_mark_node)
15597 c_parser_skip_to_pragma_eol (parser);
15598 return;
15600 tree grain = convert_to_integer (long_integer_type_node,
15601 c_fully_fold (g_expr.value, false,
15602 NULL));
15603 c_parser_skip_to_pragma_eol (parser);
15604 c_token *token = c_parser_peek_token (parser);
15605 if (token && token->type == CPP_KEYWORD
15606 && token->keyword == RID_CILK_FOR)
15608 if (grain == NULL_TREE || grain == error_mark_node)
15609 grain = integer_zero_node;
15610 c_parser_cilk_for (parser, grain);
15612 else
15613 warning (0, "%<#pragma cilk grainsize%> is not followed by "
15614 "%<_Cilk_for%>");
15616 else
15617 c_parser_skip_to_pragma_eol (parser);
15620 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
15622 static void
15623 c_parser_cilk_simd (c_parser *parser)
15625 tree clauses = c_parser_cilk_all_clauses (parser);
15626 tree block = c_begin_compound_stmt (true);
15627 location_t loc = c_parser_peek_token (parser)->location;
15628 c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL);
15629 block = c_end_compound_stmt (loc, block, true);
15630 add_stmt (block);
15633 /* Create an artificial decl with TYPE and emit initialization of it with
15634 INIT. */
15636 static tree
15637 c_get_temp_regvar (tree type, tree init)
15639 location_t loc = EXPR_LOCATION (init);
15640 tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
15641 DECL_ARTIFICIAL (decl) = 1;
15642 DECL_IGNORED_P (decl) = 1;
15643 pushdecl (decl);
15644 tree t = build2 (INIT_EXPR, type, decl, init);
15645 add_stmt (t);
15646 return decl;
15649 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15650 GRAIN is the grain value passed in through pragma or 0. */
15652 static void
15653 c_parser_cilk_for (c_parser *parser, tree grain)
15655 tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE);
15656 OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR;
15657 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain;
15658 clauses = c_finish_omp_clauses (clauses);
15660 tree block = c_begin_compound_stmt (true);
15661 tree sb = push_stmt_list ();
15662 location_t loc = c_parser_peek_token (parser)->location;
15663 tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL);
15664 sb = pop_stmt_list (sb);
15666 if (omp_for)
15668 tree omp_par = make_node (OMP_PARALLEL);
15669 TREE_TYPE (omp_par) = void_type_node;
15670 OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE;
15671 tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
15672 TREE_SIDE_EFFECTS (bind) = 1;
15673 BIND_EXPR_BODY (bind) = sb;
15674 OMP_PARALLEL_BODY (omp_par) = bind;
15675 if (OMP_FOR_PRE_BODY (omp_for))
15677 add_stmt (OMP_FOR_PRE_BODY (omp_for));
15678 OMP_FOR_PRE_BODY (omp_for) = NULL_TREE;
15680 tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0);
15681 tree decl = TREE_OPERAND (init, 0);
15682 tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0);
15683 tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
15684 tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE;
15685 if (TREE_CODE (t) != INTEGER_CST)
15687 TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15688 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15689 OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1);
15690 OMP_CLAUSE_CHAIN (c) = clauses;
15691 clauses = c;
15693 if (TREE_CODE (incr) == MODIFY_EXPR)
15695 t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15696 if (TREE_CODE (t) != INTEGER_CST)
15698 TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
15699 = c_get_temp_regvar (TREE_TYPE (t), t);
15700 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15701 OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15702 OMP_CLAUSE_CHAIN (c) = clauses;
15703 clauses = c;
15706 t = TREE_OPERAND (init, 1);
15707 if (TREE_CODE (t) != INTEGER_CST)
15709 TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15710 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15711 OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1);
15712 OMP_CLAUSE_CHAIN (c) = clauses;
15713 clauses = c;
15715 c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
15716 OMP_CLAUSE_DECL (c) = decl;
15717 OMP_CLAUSE_CHAIN (c) = clauses;
15718 clauses = c;
15719 c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_);
15720 OMP_CLAUSE_OPERAND (c, 0)
15721 = cilk_for_number_of_iterations (omp_for);
15722 OMP_CLAUSE_CHAIN (c) = clauses;
15723 OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c);
15724 add_stmt (omp_par);
15727 block = c_end_compound_stmt (loc, block, true);
15728 add_stmt (block);
15732 /* Parse a transaction attribute (GCC Extension).
15734 transaction-attribute:
15735 attributes
15736 [ [ any-word ] ]
15738 The transactional memory language description is written for C++,
15739 and uses the C++0x attribute syntax. For compatibility, allow the
15740 bracket style for transactions in C as well. */
15742 static tree
15743 c_parser_transaction_attributes (c_parser *parser)
15745 tree attr_name, attr = NULL;
15747 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
15748 return c_parser_attributes (parser);
15750 if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
15751 return NULL_TREE;
15752 c_parser_consume_token (parser);
15753 if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
15754 goto error1;
15756 attr_name = c_parser_attribute_any_word (parser);
15757 if (attr_name)
15759 c_parser_consume_token (parser);
15760 attr = build_tree_list (attr_name, NULL_TREE);
15762 else
15763 c_parser_error (parser, "expected identifier");
15765 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15766 error1:
15767 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15768 return attr;
15771 /* Parse a __transaction_atomic or __transaction_relaxed statement
15772 (GCC Extension).
15774 transaction-statement:
15775 __transaction_atomic transaction-attribute[opt] compound-statement
15776 __transaction_relaxed compound-statement
15778 Note that the only valid attribute is: "outer".
15781 static tree
15782 c_parser_transaction (c_parser *parser, enum rid keyword)
15784 unsigned int old_in = parser->in_transaction;
15785 unsigned int this_in = 1, new_in;
15786 location_t loc = c_parser_peek_token (parser)->location;
15787 tree stmt, attrs;
15789 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15790 || keyword == RID_TRANSACTION_RELAXED)
15791 && c_parser_next_token_is_keyword (parser, keyword));
15792 c_parser_consume_token (parser);
15794 if (keyword == RID_TRANSACTION_RELAXED)
15795 this_in |= TM_STMT_ATTR_RELAXED;
15796 else
15798 attrs = c_parser_transaction_attributes (parser);
15799 if (attrs)
15800 this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
15803 /* Keep track if we're in the lexical scope of an outer transaction. */
15804 new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
15806 parser->in_transaction = new_in;
15807 stmt = c_parser_compound_statement (parser);
15808 parser->in_transaction = old_in;
15810 if (flag_tm)
15811 stmt = c_finish_transaction (loc, stmt, this_in);
15812 else
15813 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15814 "%<__transaction_atomic%> without transactional memory support enabled"
15815 : "%<__transaction_relaxed %> "
15816 "without transactional memory support enabled"));
15818 return stmt;
15821 /* Parse a __transaction_atomic or __transaction_relaxed expression
15822 (GCC Extension).
15824 transaction-expression:
15825 __transaction_atomic ( expression )
15826 __transaction_relaxed ( expression )
15829 static struct c_expr
15830 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
15832 struct c_expr ret;
15833 unsigned int old_in = parser->in_transaction;
15834 unsigned int this_in = 1;
15835 location_t loc = c_parser_peek_token (parser)->location;
15836 tree attrs;
15838 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15839 || keyword == RID_TRANSACTION_RELAXED)
15840 && c_parser_next_token_is_keyword (parser, keyword));
15841 c_parser_consume_token (parser);
15843 if (keyword == RID_TRANSACTION_RELAXED)
15844 this_in |= TM_STMT_ATTR_RELAXED;
15845 else
15847 attrs = c_parser_transaction_attributes (parser);
15848 if (attrs)
15849 this_in |= parse_tm_stmt_attr (attrs, 0);
15852 parser->in_transaction = this_in;
15853 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15855 tree expr = c_parser_expression (parser).value;
15856 ret.original_type = TREE_TYPE (expr);
15857 ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
15858 if (this_in & TM_STMT_ATTR_RELAXED)
15859 TRANSACTION_EXPR_RELAXED (ret.value) = 1;
15860 SET_EXPR_LOCATION (ret.value, loc);
15861 ret.original_code = TRANSACTION_EXPR;
15862 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
15864 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
15865 goto error;
15868 else
15870 error:
15871 ret.value = error_mark_node;
15872 ret.original_code = ERROR_MARK;
15873 ret.original_type = NULL;
15875 parser->in_transaction = old_in;
15877 if (!flag_tm)
15878 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15879 "%<__transaction_atomic%> without transactional memory support enabled"
15880 : "%<__transaction_relaxed %> "
15881 "without transactional memory support enabled"));
15883 return ret;
15886 /* Parse a __transaction_cancel statement (GCC Extension).
15888 transaction-cancel-statement:
15889 __transaction_cancel transaction-attribute[opt] ;
15891 Note that the only valid attribute is "outer".
15894 static tree
15895 c_parser_transaction_cancel (c_parser *parser)
15897 location_t loc = c_parser_peek_token (parser)->location;
15898 tree attrs;
15899 bool is_outer = false;
15901 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
15902 c_parser_consume_token (parser);
15904 attrs = c_parser_transaction_attributes (parser);
15905 if (attrs)
15906 is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
15908 if (!flag_tm)
15910 error_at (loc, "%<__transaction_cancel%> without "
15911 "transactional memory support enabled");
15912 goto ret_error;
15914 else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
15916 error_at (loc, "%<__transaction_cancel%> within a "
15917 "%<__transaction_relaxed%>");
15918 goto ret_error;
15920 else if (is_outer)
15922 if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
15923 && !is_tm_may_cancel_outer (current_function_decl))
15925 error_at (loc, "outer %<__transaction_cancel%> not "
15926 "within outer %<__transaction_atomic%>");
15927 error_at (loc, " or a %<transaction_may_cancel_outer%> function");
15928 goto ret_error;
15931 else if (parser->in_transaction == 0)
15933 error_at (loc, "%<__transaction_cancel%> not within "
15934 "%<__transaction_atomic%>");
15935 goto ret_error;
15938 return add_stmt (build_tm_abort_call (loc, is_outer));
15940 ret_error:
15941 return build1 (NOP_EXPR, void_type_node, error_mark_node);
15944 /* Parse a single source file. */
15946 void
15947 c_parse_file (void)
15949 /* Use local storage to begin. If the first token is a pragma, parse it.
15950 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15951 which will cause garbage collection. */
15952 c_parser tparser;
15954 memset (&tparser, 0, sizeof tparser);
15955 tparser.tokens = &tparser.tokens_buf[0];
15956 the_parser = &tparser;
15958 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
15959 c_parser_pragma_pch_preprocess (&tparser);
15961 the_parser = ggc_alloc<c_parser> ();
15962 *the_parser = tparser;
15963 if (tparser.tokens == &tparser.tokens_buf[0])
15964 the_parser->tokens = &the_parser->tokens_buf[0];
15966 /* Initialize EH, if we've been told to do so. */
15967 if (flag_exceptions)
15968 using_eh_for_cleanups ();
15970 c_parser_translation_unit (the_parser);
15971 the_parser = NULL;
15974 /* This function parses Cilk Plus array notation. The starting index is
15975 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15976 return value of this function is a tree_node called VALUE_TREE of type
15977 ARRAY_NOTATION_REF. */
15979 static tree
15980 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
15981 tree array_value)
15983 c_token *token = NULL;
15984 tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE;
15985 tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE;
15986 tree array_type_domain = NULL_TREE;
15988 if (array_value == error_mark_node || initial_index == error_mark_node)
15990 /* No need to continue. If either of these 2 were true, then an error
15991 must be emitted already. Thus, no need to emit them twice. */
15992 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15993 return error_mark_node;
15996 array_type = TREE_TYPE (array_value);
15997 gcc_assert (array_type);
15998 if (TREE_CODE (array_type) != ARRAY_TYPE
15999 && TREE_CODE (array_type) != POINTER_TYPE)
16001 error_at (loc, "base of array section must be pointer or array type");
16002 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
16003 return error_mark_node;
16005 type = TREE_TYPE (array_type);
16006 token = c_parser_peek_token (parser);
16008 if (token->type == CPP_EOF)
16010 c_parser_error (parser, "expected %<:%> or numeral");
16011 return value_tree;
16013 else if (token->type == CPP_COLON)
16015 if (!initial_index)
16017 /* If we are here, then we have a case like this A[:]. */
16018 c_parser_consume_token (parser);
16019 if (TREE_CODE (array_type) == POINTER_TYPE)
16021 error_at (loc, "start-index and length fields necessary for "
16022 "using array notations in pointers");
16023 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
16024 return error_mark_node;
16026 if (TREE_CODE (array_type) == FUNCTION_TYPE)
16028 error_at (loc, "array notations cannot be used with function "
16029 "type");
16030 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
16031 return error_mark_node;
16033 array_type_domain = TYPE_DOMAIN (array_type);
16035 if (!array_type_domain)
16037 error_at (loc, "start-index and length fields necessary for "
16038 "using array notations in dimensionless arrays");
16039 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
16040 return error_mark_node;
16043 start_index = TYPE_MINVAL (array_type_domain);
16044 start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node,
16045 start_index);
16046 if (!TYPE_MAXVAL (array_type_domain)
16047 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain)))
16049 error_at (loc, "start-index and length fields necessary for "
16050 "using array notations in variable-length arrays");
16051 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
16052 return error_mark_node;
16054 end_index = TYPE_MAXVAL (array_type_domain);
16055 end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index),
16056 end_index, integer_one_node);
16057 end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index);
16058 stride = build_int_cst (integer_type_node, 1);
16059 stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride);
16061 else if (initial_index != error_mark_node)
16063 /* If we are here, then there should be 2 possibilities:
16064 1. Array [EXPR : EXPR]
16065 2. Array [EXPR : EXPR : EXPR]
16067 start_index = initial_index;
16069 if (TREE_CODE (array_type) == FUNCTION_TYPE)
16071 error_at (loc, "array notations cannot be used with function "
16072 "type");
16073 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
16074 return error_mark_node;
16076 c_parser_consume_token (parser); /* consume the ':' */
16077 struct c_expr ce = c_parser_expression (parser);
16078 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
16079 end_index = ce.value;
16080 if (!end_index || end_index == error_mark_node)
16082 c_parser_skip_to_end_of_block_or_statement (parser);
16083 return error_mark_node;
16085 if (c_parser_peek_token (parser)->type == CPP_COLON)
16087 c_parser_consume_token (parser);
16088 ce = c_parser_expression (parser);
16089 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
16090 stride = ce.value;
16091 if (!stride || stride == error_mark_node)
16093 c_parser_skip_to_end_of_block_or_statement (parser);
16094 return error_mark_node;
16098 else
16099 c_parser_error (parser, "expected array notation expression");
16101 else
16102 c_parser_error (parser, "expected array notation expression");
16104 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
16106 value_tree = build_array_notation_ref (loc, array_value, start_index,
16107 end_index, stride, type);
16108 if (value_tree != error_mark_node)
16109 SET_EXPR_LOCATION (value_tree, loc);
16110 return value_tree;
16113 #include "gt-c-c-parser.h"