Unsupported OpenACC clauses: sorry message instead of aborting.
[official-gcc.git] / gcc / c / c-parser.c
blob626992311f504f4caa09289ce576e9314ba55ecb
1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2014 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 "tree.h"
43 #include "stringpool.h"
44 #include "attribs.h"
45 #include "stor-layout.h"
46 #include "varasm.h"
47 #include "trans-mem.h"
48 #include "langhooks.h"
49 #include "input.h"
50 #include "cpplib.h"
51 #include "timevar.h"
52 #include "c-family/c-pragma.h"
53 #include "c-tree.h"
54 #include "c-lang.h"
55 #include "flags.h"
56 #include "ggc.h"
57 #include "c-family/c-common.h"
58 #include "c-family/c-objc.h"
59 #include "vec.h"
60 #include "target.h"
61 #include "cgraph.h"
62 #include "plugin.h"
63 #include "omp-low.h"
66 /* Initialization routine for this file. */
68 void
69 c_parse_init (void)
71 /* The only initialization required is of the reserved word
72 identifiers. */
73 unsigned int i;
74 tree id;
75 int mask = 0;
77 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
78 the c_token structure. */
79 gcc_assert (RID_MAX <= 255);
81 mask |= D_CXXONLY;
82 if (!flag_isoc99)
83 mask |= D_C99;
84 if (flag_no_asm)
86 mask |= D_ASM | D_EXT;
87 if (!flag_isoc99)
88 mask |= D_EXT89;
90 if (!c_dialect_objc ())
91 mask |= D_OBJC | D_CXX_OBJC;
93 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
94 for (i = 0; i < num_c_common_reswords; i++)
96 /* If a keyword is disabled, do not enter it into the table
97 and so create a canonical spelling that isn't a keyword. */
98 if (c_common_reswords[i].disable & mask)
100 if (warn_cxx_compat
101 && (c_common_reswords[i].disable & D_CXXWARN))
103 id = get_identifier (c_common_reswords[i].word);
104 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
105 C_IS_RESERVED_WORD (id) = 1;
107 continue;
110 id = get_identifier (c_common_reswords[i].word);
111 C_SET_RID_CODE (id, c_common_reswords[i].rid);
112 C_IS_RESERVED_WORD (id) = 1;
113 ridpointers [(int) c_common_reswords[i].rid] = id;
117 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
118 and the C parser. Unlike the C++ lexer, the parser structure
119 stores the lexer information instead of using a separate structure.
120 Identifiers are separated into ordinary identifiers, type names,
121 keywords and some other Objective-C types of identifiers, and some
122 look-ahead is maintained.
124 ??? It might be a good idea to lex the whole file up front (as for
125 C++). It would then be possible to share more of the C and C++
126 lexer code, if desired. */
128 /* The following local token type is used. */
130 /* A keyword. */
131 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
133 /* More information about the type of a CPP_NAME token. */
134 typedef enum c_id_kind {
135 /* An ordinary identifier. */
136 C_ID_ID,
137 /* An identifier declared as a typedef name. */
138 C_ID_TYPENAME,
139 /* An identifier declared as an Objective-C class name. */
140 C_ID_CLASSNAME,
141 /* An address space identifier. */
142 C_ID_ADDRSPACE,
143 /* Not an identifier. */
144 C_ID_NONE
145 } c_id_kind;
147 /* A single C token after string literal concatenation and conversion
148 of preprocessing tokens to tokens. */
149 typedef struct GTY (()) c_token {
150 /* The kind of token. */
151 ENUM_BITFIELD (cpp_ttype) type : 8;
152 /* If this token is a CPP_NAME, this value indicates whether also
153 declared as some kind of type. Otherwise, it is C_ID_NONE. */
154 ENUM_BITFIELD (c_id_kind) id_kind : 8;
155 /* If this token is a keyword, this value indicates which keyword.
156 Otherwise, this value is RID_MAX. */
157 ENUM_BITFIELD (rid) keyword : 8;
158 /* If this token is a CPP_PRAGMA, this indicates the pragma that
159 was seen. Otherwise it is PRAGMA_NONE. */
160 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
161 /* The location at which this token was found. */
162 location_t location;
163 /* The value associated with this token, if any. */
164 tree value;
165 } c_token;
167 /* A parser structure recording information about the state and
168 context of parsing. Includes lexer information with up to two
169 tokens of look-ahead; more are not needed for C. */
170 typedef struct GTY(()) c_parser {
171 /* The look-ahead tokens. */
172 c_token * GTY((skip)) tokens;
173 /* Buffer for look-ahead tokens. */
174 c_token tokens_buf[2];
175 /* How many look-ahead tokens are available (0, 1 or 2, or
176 more if parsing from pre-lexed tokens). */
177 unsigned int tokens_avail;
178 /* True if a syntax error is being recovered from; false otherwise.
179 c_parser_error sets this flag. It should clear this flag when
180 enough tokens have been consumed to recover from the error. */
181 BOOL_BITFIELD error : 1;
182 /* True if we're processing a pragma, and shouldn't automatically
183 consume CPP_PRAGMA_EOL. */
184 BOOL_BITFIELD in_pragma : 1;
185 /* True if we're parsing the outermost block of an if statement. */
186 BOOL_BITFIELD in_if_block : 1;
187 /* True if we want to lex an untranslated string. */
188 BOOL_BITFIELD lex_untranslated_string : 1;
190 /* Objective-C specific parser/lexer information. */
192 /* True if we are in a context where the Objective-C "PQ" keywords
193 are considered keywords. */
194 BOOL_BITFIELD objc_pq_context : 1;
195 /* True if we are parsing a (potential) Objective-C foreach
196 statement. This is set to true after we parsed 'for (' and while
197 we wait for 'in' or ';' to decide if it's a standard C for loop or an
198 Objective-C foreach loop. */
199 BOOL_BITFIELD objc_could_be_foreach_context : 1;
200 /* The following flag is needed to contextualize Objective-C lexical
201 analysis. In some cases (e.g., 'int NSObject;'), it is
202 undesirable to bind an identifier to an Objective-C class, even
203 if a class with that name exists. */
204 BOOL_BITFIELD objc_need_raw_identifier : 1;
205 /* Nonzero if we're processing a __transaction statement. The value
206 is 1 | TM_STMT_ATTR_*. */
207 unsigned int in_transaction : 4;
208 /* True if we are in a context where the Objective-C "Property attribute"
209 keywords are valid. */
210 BOOL_BITFIELD objc_property_attr_context : 1;
212 /* Cilk Plus specific parser/lexer information. */
214 /* Buffer to hold all the tokens from parsing the vector attribute for the
215 SIMD-enabled functions (formerly known as elemental functions). */
216 vec <c_token, va_gc> *cilk_simd_fn_tokens;
217 } c_parser;
220 /* The actual parser and external interface. ??? Does this need to be
221 garbage-collected? */
223 static GTY (()) c_parser *the_parser;
225 /* Read in and lex a single token, storing it in *TOKEN. */
227 static void
228 c_lex_one_token (c_parser *parser, c_token *token)
230 timevar_push (TV_LEX);
232 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
233 (parser->lex_untranslated_string
234 ? C_LEX_STRING_NO_TRANSLATE : 0));
235 token->id_kind = C_ID_NONE;
236 token->keyword = RID_MAX;
237 token->pragma_kind = PRAGMA_NONE;
239 switch (token->type)
241 case CPP_NAME:
243 tree decl;
245 bool objc_force_identifier = parser->objc_need_raw_identifier;
246 if (c_dialect_objc ())
247 parser->objc_need_raw_identifier = false;
249 if (C_IS_RESERVED_WORD (token->value))
251 enum rid rid_code = C_RID_CODE (token->value);
253 if (rid_code == RID_CXX_COMPAT_WARN)
255 warning_at (token->location,
256 OPT_Wc___compat,
257 "identifier %qE conflicts with C++ keyword",
258 token->value);
260 else if (rid_code >= RID_FIRST_ADDR_SPACE
261 && rid_code <= RID_LAST_ADDR_SPACE)
263 token->id_kind = C_ID_ADDRSPACE;
264 token->keyword = rid_code;
265 break;
267 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
269 /* We found an Objective-C "pq" keyword (in, out,
270 inout, bycopy, byref, oneway). They need special
271 care because the interpretation depends on the
272 context. */
273 if (parser->objc_pq_context)
275 token->type = CPP_KEYWORD;
276 token->keyword = rid_code;
277 break;
279 else if (parser->objc_could_be_foreach_context
280 && rid_code == RID_IN)
282 /* We are in Objective-C, inside a (potential)
283 foreach context (which means after having
284 parsed 'for (', but before having parsed ';'),
285 and we found 'in'. We consider it the keyword
286 which terminates the declaration at the
287 beginning of a foreach-statement. Note that
288 this means you can't use 'in' for anything else
289 in that context; in particular, in Objective-C
290 you can't use 'in' as the name of the running
291 variable in a C for loop. We could potentially
292 try to add code here to disambiguate, but it
293 seems a reasonable limitation. */
294 token->type = CPP_KEYWORD;
295 token->keyword = rid_code;
296 break;
298 /* Else, "pq" keywords outside of the "pq" context are
299 not keywords, and we fall through to the code for
300 normal tokens. */
302 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
304 /* We found an Objective-C "property attribute"
305 keyword (getter, setter, readonly, etc). These are
306 only valid in the property context. */
307 if (parser->objc_property_attr_context)
309 token->type = CPP_KEYWORD;
310 token->keyword = rid_code;
311 break;
313 /* Else they are not special keywords.
316 else if (c_dialect_objc ()
317 && (OBJC_IS_AT_KEYWORD (rid_code)
318 || OBJC_IS_CXX_KEYWORD (rid_code)))
320 /* We found one of the Objective-C "@" keywords (defs,
321 selector, synchronized, etc) or one of the
322 Objective-C "cxx" keywords (class, private,
323 protected, public, try, catch, throw) without a
324 preceding '@' sign. Do nothing and fall through to
325 the code for normal tokens (in C++ we would still
326 consider the CXX ones keywords, but not in C). */
329 else
331 token->type = CPP_KEYWORD;
332 token->keyword = rid_code;
333 break;
337 decl = lookup_name (token->value);
338 if (decl)
340 if (TREE_CODE (decl) == TYPE_DECL)
342 token->id_kind = C_ID_TYPENAME;
343 break;
346 else if (c_dialect_objc ())
348 tree objc_interface_decl = objc_is_class_name (token->value);
349 /* Objective-C class names are in the same namespace as
350 variables and typedefs, and hence are shadowed by local
351 declarations. */
352 if (objc_interface_decl
353 && (!objc_force_identifier || global_bindings_p ()))
355 token->value = objc_interface_decl;
356 token->id_kind = C_ID_CLASSNAME;
357 break;
360 token->id_kind = C_ID_ID;
362 break;
363 case CPP_AT_NAME:
364 /* This only happens in Objective-C; it must be a keyword. */
365 token->type = CPP_KEYWORD;
366 switch (C_RID_CODE (token->value))
368 /* Replace 'class' with '@class', 'private' with '@private',
369 etc. This prevents confusion with the C++ keyword
370 'class', and makes the tokens consistent with other
371 Objective-C 'AT' keywords. For example '@class' is
372 reported as RID_AT_CLASS which is consistent with
373 '@synchronized', which is reported as
374 RID_AT_SYNCHRONIZED.
376 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
377 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
378 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
379 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
380 case RID_THROW: token->keyword = RID_AT_THROW; break;
381 case RID_TRY: token->keyword = RID_AT_TRY; break;
382 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
383 default: token->keyword = C_RID_CODE (token->value);
385 break;
386 case CPP_COLON:
387 case CPP_COMMA:
388 case CPP_CLOSE_PAREN:
389 case CPP_SEMICOLON:
390 /* These tokens may affect the interpretation of any identifiers
391 following, if doing Objective-C. */
392 if (c_dialect_objc ())
393 parser->objc_need_raw_identifier = false;
394 break;
395 case CPP_PRAGMA:
396 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
397 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
398 token->value = NULL;
399 break;
400 default:
401 break;
403 timevar_pop (TV_LEX);
406 /* Return a pointer to the next token from PARSER, reading it in if
407 necessary. */
409 static inline c_token *
410 c_parser_peek_token (c_parser *parser)
412 if (parser->tokens_avail == 0)
414 c_lex_one_token (parser, &parser->tokens[0]);
415 parser->tokens_avail = 1;
417 return &parser->tokens[0];
420 /* Return true if the next token from PARSER has the indicated
421 TYPE. */
423 static inline bool
424 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
426 return c_parser_peek_token (parser)->type == type;
429 /* Return true if the next token from PARSER does not have the
430 indicated TYPE. */
432 static inline bool
433 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
435 return !c_parser_next_token_is (parser, type);
438 /* Return true if the next token from PARSER is the indicated
439 KEYWORD. */
441 static inline bool
442 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
444 return c_parser_peek_token (parser)->keyword == keyword;
447 /* Return a pointer to the next-but-one token from PARSER, reading it
448 in if necessary. The next token is already read in. */
450 static c_token *
451 c_parser_peek_2nd_token (c_parser *parser)
453 if (parser->tokens_avail >= 2)
454 return &parser->tokens[1];
455 gcc_assert (parser->tokens_avail == 1);
456 gcc_assert (parser->tokens[0].type != CPP_EOF);
457 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
458 c_lex_one_token (parser, &parser->tokens[1]);
459 parser->tokens_avail = 2;
460 return &parser->tokens[1];
463 /* Return true if TOKEN can start a type name,
464 false otherwise. */
465 static bool
466 c_token_starts_typename (c_token *token)
468 switch (token->type)
470 case CPP_NAME:
471 switch (token->id_kind)
473 case C_ID_ID:
474 return false;
475 case C_ID_ADDRSPACE:
476 return true;
477 case C_ID_TYPENAME:
478 return true;
479 case C_ID_CLASSNAME:
480 gcc_assert (c_dialect_objc ());
481 return true;
482 default:
483 gcc_unreachable ();
485 case CPP_KEYWORD:
486 switch (token->keyword)
488 case RID_UNSIGNED:
489 case RID_LONG:
490 case RID_INT128:
491 case RID_SHORT:
492 case RID_SIGNED:
493 case RID_COMPLEX:
494 case RID_INT:
495 case RID_CHAR:
496 case RID_FLOAT:
497 case RID_DOUBLE:
498 case RID_VOID:
499 case RID_DFLOAT32:
500 case RID_DFLOAT64:
501 case RID_DFLOAT128:
502 case RID_BOOL:
503 case RID_ENUM:
504 case RID_STRUCT:
505 case RID_UNION:
506 case RID_TYPEOF:
507 case RID_CONST:
508 case RID_ATOMIC:
509 case RID_VOLATILE:
510 case RID_RESTRICT:
511 case RID_ATTRIBUTE:
512 case RID_FRACT:
513 case RID_ACCUM:
514 case RID_SAT:
515 case RID_AUTO_TYPE:
516 return true;
517 default:
518 return false;
520 case CPP_LESS:
521 if (c_dialect_objc ())
522 return true;
523 return false;
524 default:
525 return false;
529 enum c_lookahead_kind {
530 /* Always treat unknown identifiers as typenames. */
531 cla_prefer_type,
533 /* Could be parsing a nonabstract declarator. Only treat an identifier
534 as a typename if followed by another identifier or a star. */
535 cla_nonabstract_decl,
537 /* Never treat identifiers as typenames. */
538 cla_prefer_id
541 /* Return true if the next token from PARSER can start a type name,
542 false otherwise. LA specifies how to do lookahead in order to
543 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
545 static inline bool
546 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
548 c_token *token = c_parser_peek_token (parser);
549 if (c_token_starts_typename (token))
550 return true;
552 /* Try a bit harder to detect an unknown typename. */
553 if (la != cla_prefer_id
554 && token->type == CPP_NAME
555 && token->id_kind == C_ID_ID
557 /* Do not try too hard when we could have "object in array". */
558 && !parser->objc_could_be_foreach_context
560 && (la == cla_prefer_type
561 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
562 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
564 /* Only unknown identifiers. */
565 && !lookup_name (token->value))
566 return true;
568 return false;
571 /* Return true if TOKEN is a type qualifier, false otherwise. */
572 static bool
573 c_token_is_qualifier (c_token *token)
575 switch (token->type)
577 case CPP_NAME:
578 switch (token->id_kind)
580 case C_ID_ADDRSPACE:
581 return true;
582 default:
583 return false;
585 case CPP_KEYWORD:
586 switch (token->keyword)
588 case RID_CONST:
589 case RID_VOLATILE:
590 case RID_RESTRICT:
591 case RID_ATTRIBUTE:
592 case RID_ATOMIC:
593 return true;
594 default:
595 return false;
597 case CPP_LESS:
598 return false;
599 default:
600 gcc_unreachable ();
604 /* Return true if the next token from PARSER is a type qualifier,
605 false otherwise. */
606 static inline bool
607 c_parser_next_token_is_qualifier (c_parser *parser)
609 c_token *token = c_parser_peek_token (parser);
610 return c_token_is_qualifier (token);
613 /* Return true if TOKEN can start declaration specifiers, false
614 otherwise. */
615 static bool
616 c_token_starts_declspecs (c_token *token)
618 switch (token->type)
620 case CPP_NAME:
621 switch (token->id_kind)
623 case C_ID_ID:
624 return false;
625 case C_ID_ADDRSPACE:
626 return true;
627 case C_ID_TYPENAME:
628 return true;
629 case C_ID_CLASSNAME:
630 gcc_assert (c_dialect_objc ());
631 return true;
632 default:
633 gcc_unreachable ();
635 case CPP_KEYWORD:
636 switch (token->keyword)
638 case RID_STATIC:
639 case RID_EXTERN:
640 case RID_REGISTER:
641 case RID_TYPEDEF:
642 case RID_INLINE:
643 case RID_NORETURN:
644 case RID_AUTO:
645 case RID_THREAD:
646 case RID_UNSIGNED:
647 case RID_LONG:
648 case RID_INT128:
649 case RID_SHORT:
650 case RID_SIGNED:
651 case RID_COMPLEX:
652 case RID_INT:
653 case RID_CHAR:
654 case RID_FLOAT:
655 case RID_DOUBLE:
656 case RID_VOID:
657 case RID_DFLOAT32:
658 case RID_DFLOAT64:
659 case RID_DFLOAT128:
660 case RID_BOOL:
661 case RID_ENUM:
662 case RID_STRUCT:
663 case RID_UNION:
664 case RID_TYPEOF:
665 case RID_CONST:
666 case RID_VOLATILE:
667 case RID_RESTRICT:
668 case RID_ATTRIBUTE:
669 case RID_FRACT:
670 case RID_ACCUM:
671 case RID_SAT:
672 case RID_ALIGNAS:
673 case RID_ATOMIC:
674 case RID_AUTO_TYPE:
675 return true;
676 default:
677 return false;
679 case CPP_LESS:
680 if (c_dialect_objc ())
681 return true;
682 return false;
683 default:
684 return false;
689 /* Return true if TOKEN can start declaration specifiers or a static
690 assertion, false otherwise. */
691 static bool
692 c_token_starts_declaration (c_token *token)
694 if (c_token_starts_declspecs (token)
695 || token->keyword == RID_STATIC_ASSERT)
696 return true;
697 else
698 return false;
701 /* Return true if the next token from PARSER can start declaration
702 specifiers, false otherwise. */
703 static inline bool
704 c_parser_next_token_starts_declspecs (c_parser *parser)
706 c_token *token = c_parser_peek_token (parser);
708 /* In Objective-C, a classname normally starts a declspecs unless it
709 is immediately followed by a dot. In that case, it is the
710 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
711 setter/getter on the class. c_token_starts_declspecs() can't
712 differentiate between the two cases because it only checks the
713 current token, so we have a special check here. */
714 if (c_dialect_objc ()
715 && token->type == CPP_NAME
716 && token->id_kind == C_ID_CLASSNAME
717 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
718 return false;
720 return c_token_starts_declspecs (token);
723 /* Return true if the next tokens from PARSER can start declaration
724 specifiers or a static assertion, false otherwise. */
725 static inline bool
726 c_parser_next_tokens_start_declaration (c_parser *parser)
728 c_token *token = c_parser_peek_token (parser);
730 /* Same as above. */
731 if (c_dialect_objc ()
732 && token->type == CPP_NAME
733 && token->id_kind == C_ID_CLASSNAME
734 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
735 return false;
737 /* Labels do not start declarations. */
738 if (token->type == CPP_NAME
739 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
740 return false;
742 if (c_token_starts_declaration (token))
743 return true;
745 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
746 return true;
748 return false;
751 /* Consume the next token from PARSER. */
753 static void
754 c_parser_consume_token (c_parser *parser)
756 gcc_assert (parser->tokens_avail >= 1);
757 gcc_assert (parser->tokens[0].type != CPP_EOF);
758 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
759 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
760 if (parser->tokens != &parser->tokens_buf[0])
761 parser->tokens++;
762 else if (parser->tokens_avail == 2)
763 parser->tokens[0] = parser->tokens[1];
764 parser->tokens_avail--;
767 /* Expect the current token to be a #pragma. Consume it and remember
768 that we've begun parsing a pragma. */
770 static void
771 c_parser_consume_pragma (c_parser *parser)
773 gcc_assert (!parser->in_pragma);
774 gcc_assert (parser->tokens_avail >= 1);
775 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
776 if (parser->tokens != &parser->tokens_buf[0])
777 parser->tokens++;
778 else if (parser->tokens_avail == 2)
779 parser->tokens[0] = parser->tokens[1];
780 parser->tokens_avail--;
781 parser->in_pragma = true;
784 /* Update the global input_location from TOKEN. */
785 static inline void
786 c_parser_set_source_position_from_token (c_token *token)
788 if (token->type != CPP_EOF)
790 input_location = token->location;
794 /* Issue a diagnostic of the form
795 FILE:LINE: MESSAGE before TOKEN
796 where TOKEN is the next token in the input stream of PARSER.
797 MESSAGE (specified by the caller) is usually of the form "expected
798 OTHER-TOKEN".
800 Do not issue a diagnostic if still recovering from an error.
802 ??? This is taken from the C++ parser, but building up messages in
803 this way is not i18n-friendly and some other approach should be
804 used. */
806 static void
807 c_parser_error (c_parser *parser, const char *gmsgid)
809 c_token *token = c_parser_peek_token (parser);
810 if (parser->error)
811 return;
812 parser->error = true;
813 if (!gmsgid)
814 return;
815 /* This diagnostic makes more sense if it is tagged to the line of
816 the token we just peeked at. */
817 c_parser_set_source_position_from_token (token);
818 c_parse_error (gmsgid,
819 /* Because c_parse_error does not understand
820 CPP_KEYWORD, keywords are treated like
821 identifiers. */
822 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
823 /* ??? The C parser does not save the cpp flags of a
824 token, we need to pass 0 here and we will not get
825 the source spelling of some tokens but rather the
826 canonical spelling. */
827 token->value, /*flags=*/0);
830 /* If the next token is of the indicated TYPE, consume it. Otherwise,
831 issue the error MSGID. If MSGID is NULL then a message has already
832 been produced and no message will be produced this time. Returns
833 true if found, false otherwise. */
835 static bool
836 c_parser_require (c_parser *parser,
837 enum cpp_ttype type,
838 const char *msgid)
840 if (c_parser_next_token_is (parser, type))
842 c_parser_consume_token (parser);
843 return true;
845 else
847 c_parser_error (parser, msgid);
848 return false;
852 /* If the next token is the indicated keyword, consume it. Otherwise,
853 issue the error MSGID. Returns true if found, false otherwise. */
855 static bool
856 c_parser_require_keyword (c_parser *parser,
857 enum rid keyword,
858 const char *msgid)
860 if (c_parser_next_token_is_keyword (parser, keyword))
862 c_parser_consume_token (parser);
863 return true;
865 else
867 c_parser_error (parser, msgid);
868 return false;
872 /* Like c_parser_require, except that tokens will be skipped until the
873 desired token is found. An error message is still produced if the
874 next token is not as expected. If MSGID is NULL then a message has
875 already been produced and no message will be produced this
876 time. */
878 static void
879 c_parser_skip_until_found (c_parser *parser,
880 enum cpp_ttype type,
881 const char *msgid)
883 unsigned nesting_depth = 0;
885 if (c_parser_require (parser, type, msgid))
886 return;
888 /* Skip tokens until the desired token is found. */
889 while (true)
891 /* Peek at the next token. */
892 c_token *token = c_parser_peek_token (parser);
893 /* If we've reached the token we want, consume it and stop. */
894 if (token->type == type && !nesting_depth)
896 c_parser_consume_token (parser);
897 break;
900 /* If we've run out of tokens, stop. */
901 if (token->type == CPP_EOF)
902 return;
903 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
904 return;
905 if (token->type == CPP_OPEN_BRACE
906 || token->type == CPP_OPEN_PAREN
907 || token->type == CPP_OPEN_SQUARE)
908 ++nesting_depth;
909 else if (token->type == CPP_CLOSE_BRACE
910 || token->type == CPP_CLOSE_PAREN
911 || token->type == CPP_CLOSE_SQUARE)
913 if (nesting_depth-- == 0)
914 break;
916 /* Consume this token. */
917 c_parser_consume_token (parser);
919 parser->error = false;
922 /* Skip tokens until the end of a parameter is found, but do not
923 consume the comma, semicolon or closing delimiter. */
925 static void
926 c_parser_skip_to_end_of_parameter (c_parser *parser)
928 unsigned nesting_depth = 0;
930 while (true)
932 c_token *token = c_parser_peek_token (parser);
933 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
934 && !nesting_depth)
935 break;
936 /* If we've run out of tokens, stop. */
937 if (token->type == CPP_EOF)
938 return;
939 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
940 return;
941 if (token->type == CPP_OPEN_BRACE
942 || token->type == CPP_OPEN_PAREN
943 || token->type == CPP_OPEN_SQUARE)
944 ++nesting_depth;
945 else if (token->type == CPP_CLOSE_BRACE
946 || token->type == CPP_CLOSE_PAREN
947 || token->type == CPP_CLOSE_SQUARE)
949 if (nesting_depth-- == 0)
950 break;
952 /* Consume this token. */
953 c_parser_consume_token (parser);
955 parser->error = false;
958 /* Expect to be at the end of the pragma directive and consume an
959 end of line marker. */
961 static void
962 c_parser_skip_to_pragma_eol (c_parser *parser)
964 gcc_assert (parser->in_pragma);
965 parser->in_pragma = false;
967 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
968 while (true)
970 c_token *token = c_parser_peek_token (parser);
971 if (token->type == CPP_EOF)
972 break;
973 if (token->type == CPP_PRAGMA_EOL)
975 c_parser_consume_token (parser);
976 break;
978 c_parser_consume_token (parser);
981 parser->error = false;
984 /* Skip tokens until we have consumed an entire block, or until we
985 have consumed a non-nested ';'. */
987 static void
988 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
990 unsigned nesting_depth = 0;
991 bool save_error = parser->error;
993 while (true)
995 c_token *token;
997 /* Peek at the next token. */
998 token = c_parser_peek_token (parser);
1000 switch (token->type)
1002 case CPP_EOF:
1003 return;
1005 case CPP_PRAGMA_EOL:
1006 if (parser->in_pragma)
1007 return;
1008 break;
1010 case CPP_SEMICOLON:
1011 /* If the next token is a ';', we have reached the
1012 end of the statement. */
1013 if (!nesting_depth)
1015 /* Consume the ';'. */
1016 c_parser_consume_token (parser);
1017 goto finished;
1019 break;
1021 case CPP_CLOSE_BRACE:
1022 /* If the next token is a non-nested '}', then we have
1023 reached the end of the current block. */
1024 if (nesting_depth == 0 || --nesting_depth == 0)
1026 c_parser_consume_token (parser);
1027 goto finished;
1029 break;
1031 case CPP_OPEN_BRACE:
1032 /* If it the next token is a '{', then we are entering a new
1033 block. Consume the entire block. */
1034 ++nesting_depth;
1035 break;
1037 case CPP_PRAGMA:
1038 /* If we see a pragma, consume the whole thing at once. We
1039 have some safeguards against consuming pragmas willy-nilly.
1040 Normally, we'd expect to be here with parser->error set,
1041 which disables these safeguards. But it's possible to get
1042 here for secondary error recovery, after parser->error has
1043 been cleared. */
1044 c_parser_consume_pragma (parser);
1045 c_parser_skip_to_pragma_eol (parser);
1046 parser->error = save_error;
1047 continue;
1049 default:
1050 break;
1053 c_parser_consume_token (parser);
1056 finished:
1057 parser->error = false;
1060 /* CPP's options (initialized by c-opts.c). */
1061 extern cpp_options *cpp_opts;
1063 /* Save the warning flags which are controlled by __extension__. */
1065 static inline int
1066 disable_extension_diagnostics (void)
1068 int ret = (pedantic
1069 | (warn_pointer_arith << 1)
1070 | (warn_traditional << 2)
1071 | (flag_iso << 3)
1072 | (warn_long_long << 4)
1073 | (warn_cxx_compat << 5)
1074 | (warn_overlength_strings << 6));
1075 cpp_opts->cpp_pedantic = pedantic = 0;
1076 warn_pointer_arith = 0;
1077 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1078 flag_iso = 0;
1079 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1080 warn_cxx_compat = 0;
1081 warn_overlength_strings = 0;
1082 return ret;
1085 /* Restore the warning flags which are controlled by __extension__.
1086 FLAGS is the return value from disable_extension_diagnostics. */
1088 static inline void
1089 restore_extension_diagnostics (int flags)
1091 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1092 warn_pointer_arith = (flags >> 1) & 1;
1093 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1094 flag_iso = (flags >> 3) & 1;
1095 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1096 warn_cxx_compat = (flags >> 5) & 1;
1097 warn_overlength_strings = (flags >> 6) & 1;
1100 /* Possibly kinds of declarator to parse. */
1101 typedef enum c_dtr_syn {
1102 /* A normal declarator with an identifier. */
1103 C_DTR_NORMAL,
1104 /* An abstract declarator (maybe empty). */
1105 C_DTR_ABSTRACT,
1106 /* A parameter declarator: may be either, but after a type name does
1107 not redeclare a typedef name as an identifier if it can
1108 alternatively be interpreted as a typedef name; see DR#009,
1109 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1110 following DR#249. For example, given a typedef T, "int T" and
1111 "int *T" are valid parameter declarations redeclaring T, while
1112 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1113 abstract declarators rather than involving redundant parentheses;
1114 the same applies with attributes inside the parentheses before
1115 "T". */
1116 C_DTR_PARM
1117 } c_dtr_syn;
1119 /* The binary operation precedence levels, where 0 is a dummy lowest level
1120 used for the bottom of the stack. */
1121 enum c_parser_prec {
1122 PREC_NONE,
1123 PREC_LOGOR,
1124 PREC_LOGAND,
1125 PREC_BITOR,
1126 PREC_BITXOR,
1127 PREC_BITAND,
1128 PREC_EQ,
1129 PREC_REL,
1130 PREC_SHIFT,
1131 PREC_ADD,
1132 PREC_MULT,
1133 NUM_PRECS
1136 static void c_parser_external_declaration (c_parser *);
1137 static void c_parser_asm_definition (c_parser *);
1138 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1139 bool, bool, tree *, vec<c_token>);
1140 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1141 static void c_parser_static_assert_declaration (c_parser *);
1142 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1143 bool, bool, bool, enum c_lookahead_kind);
1144 static struct c_typespec c_parser_enum_specifier (c_parser *);
1145 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1146 static tree c_parser_struct_declaration (c_parser *);
1147 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1148 static tree c_parser_alignas_specifier (c_parser *);
1149 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1150 bool *);
1151 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1152 c_dtr_syn, bool *);
1153 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1154 bool,
1155 struct c_declarator *);
1156 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1157 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1158 tree);
1159 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1160 static tree c_parser_simple_asm_expr (c_parser *);
1161 static tree c_parser_attributes (c_parser *);
1162 static struct c_type_name *c_parser_type_name (c_parser *);
1163 static struct c_expr c_parser_initializer (c_parser *);
1164 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1165 static void c_parser_initelt (c_parser *, struct obstack *);
1166 static void c_parser_initval (c_parser *, struct c_expr *,
1167 struct obstack *);
1168 static tree c_parser_compound_statement (c_parser *);
1169 static void c_parser_compound_statement_nostart (c_parser *);
1170 static void c_parser_label (c_parser *);
1171 static void c_parser_statement (c_parser *);
1172 static void c_parser_statement_after_labels (c_parser *);
1173 static void c_parser_if_statement (c_parser *);
1174 static void c_parser_switch_statement (c_parser *);
1175 static void c_parser_while_statement (c_parser *, bool);
1176 static void c_parser_do_statement (c_parser *, bool);
1177 static void c_parser_for_statement (c_parser *, bool);
1178 static tree c_parser_asm_statement (c_parser *);
1179 static tree c_parser_asm_operands (c_parser *);
1180 static tree c_parser_asm_goto_operands (c_parser *);
1181 static tree c_parser_asm_clobbers (c_parser *);
1182 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1183 tree = NULL_TREE);
1184 static struct c_expr c_parser_conditional_expression (c_parser *,
1185 struct c_expr *, tree);
1186 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1187 tree);
1188 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1189 static struct c_expr c_parser_unary_expression (c_parser *);
1190 static struct c_expr c_parser_sizeof_expression (c_parser *);
1191 static struct c_expr c_parser_alignof_expression (c_parser *);
1192 static struct c_expr c_parser_postfix_expression (c_parser *);
1193 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1194 struct c_type_name *,
1195 location_t);
1196 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1197 location_t loc,
1198 struct c_expr);
1199 static tree c_parser_transaction (c_parser *, enum rid);
1200 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1201 static tree c_parser_transaction_cancel (c_parser *);
1202 static struct c_expr c_parser_expression (c_parser *);
1203 static struct c_expr c_parser_expression_conv (c_parser *);
1204 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1205 vec<tree, va_gc> **, location_t *,
1206 tree *, vec<location_t> *);
1207 static tree c_parser_oacc_loop (location_t, c_parser *, char *);
1208 static void c_parser_omp_construct (c_parser *);
1209 static void c_parser_omp_threadprivate (c_parser *);
1210 static void c_parser_oacc_update (c_parser *);
1211 static void c_parser_omp_barrier (c_parser *);
1212 static void c_parser_omp_flush (c_parser *);
1213 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1214 tree, tree *);
1215 static void c_parser_omp_taskwait (c_parser *);
1216 static void c_parser_omp_taskyield (c_parser *);
1217 static void c_parser_omp_cancel (c_parser *);
1218 static void c_parser_omp_cancellation_point (c_parser *);
1220 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1221 pragma_stmt, pragma_compound };
1222 static bool c_parser_pragma (c_parser *, enum pragma_context);
1223 static bool c_parser_omp_target (c_parser *, enum pragma_context);
1224 static void c_parser_omp_end_declare_target (c_parser *);
1225 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1227 /* These Objective-C parser functions are only ever called when
1228 compiling Objective-C. */
1229 static void c_parser_objc_class_definition (c_parser *, tree);
1230 static void c_parser_objc_class_instance_variables (c_parser *);
1231 static void c_parser_objc_class_declaration (c_parser *);
1232 static void c_parser_objc_alias_declaration (c_parser *);
1233 static void c_parser_objc_protocol_definition (c_parser *, tree);
1234 static bool c_parser_objc_method_type (c_parser *);
1235 static void c_parser_objc_method_definition (c_parser *);
1236 static void c_parser_objc_methodprotolist (c_parser *);
1237 static void c_parser_objc_methodproto (c_parser *);
1238 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1239 static tree c_parser_objc_type_name (c_parser *);
1240 static tree c_parser_objc_protocol_refs (c_parser *);
1241 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1242 static void c_parser_objc_synchronized_statement (c_parser *);
1243 static tree c_parser_objc_selector (c_parser *);
1244 static tree c_parser_objc_selector_arg (c_parser *);
1245 static tree c_parser_objc_receiver (c_parser *);
1246 static tree c_parser_objc_message_args (c_parser *);
1247 static tree c_parser_objc_keywordexpr (c_parser *);
1248 static void c_parser_objc_at_property_declaration (c_parser *);
1249 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1250 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1251 static bool c_parser_objc_diagnose_bad_element_prefix
1252 (c_parser *, struct c_declspecs *);
1254 /* Cilk Plus supporting routines. */
1255 static void c_parser_cilk_simd (c_parser *);
1256 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
1257 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
1258 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
1260 /* Parse a translation unit (C90 6.7, C99 6.9).
1262 translation-unit:
1263 external-declarations
1265 external-declarations:
1266 external-declaration
1267 external-declarations external-declaration
1269 GNU extensions:
1271 translation-unit:
1272 empty
1275 static void
1276 c_parser_translation_unit (c_parser *parser)
1278 if (c_parser_next_token_is (parser, CPP_EOF))
1280 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1281 "ISO C forbids an empty translation unit");
1283 else
1285 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1286 mark_valid_location_for_stdc_pragma (false);
1289 ggc_collect ();
1290 c_parser_external_declaration (parser);
1291 obstack_free (&parser_obstack, obstack_position);
1293 while (c_parser_next_token_is_not (parser, CPP_EOF));
1297 /* Parse an external declaration (C90 6.7, C99 6.9).
1299 external-declaration:
1300 function-definition
1301 declaration
1303 GNU extensions:
1305 external-declaration:
1306 asm-definition
1308 __extension__ external-declaration
1310 Objective-C:
1312 external-declaration:
1313 objc-class-definition
1314 objc-class-declaration
1315 objc-alias-declaration
1316 objc-protocol-definition
1317 objc-method-definition
1318 @end
1321 static void
1322 c_parser_external_declaration (c_parser *parser)
1324 int ext;
1325 switch (c_parser_peek_token (parser)->type)
1327 case CPP_KEYWORD:
1328 switch (c_parser_peek_token (parser)->keyword)
1330 case RID_EXTENSION:
1331 ext = disable_extension_diagnostics ();
1332 c_parser_consume_token (parser);
1333 c_parser_external_declaration (parser);
1334 restore_extension_diagnostics (ext);
1335 break;
1336 case RID_ASM:
1337 c_parser_asm_definition (parser);
1338 break;
1339 case RID_AT_INTERFACE:
1340 case RID_AT_IMPLEMENTATION:
1341 gcc_assert (c_dialect_objc ());
1342 c_parser_objc_class_definition (parser, NULL_TREE);
1343 break;
1344 case RID_AT_CLASS:
1345 gcc_assert (c_dialect_objc ());
1346 c_parser_objc_class_declaration (parser);
1347 break;
1348 case RID_AT_ALIAS:
1349 gcc_assert (c_dialect_objc ());
1350 c_parser_objc_alias_declaration (parser);
1351 break;
1352 case RID_AT_PROTOCOL:
1353 gcc_assert (c_dialect_objc ());
1354 c_parser_objc_protocol_definition (parser, NULL_TREE);
1355 break;
1356 case RID_AT_PROPERTY:
1357 gcc_assert (c_dialect_objc ());
1358 c_parser_objc_at_property_declaration (parser);
1359 break;
1360 case RID_AT_SYNTHESIZE:
1361 gcc_assert (c_dialect_objc ());
1362 c_parser_objc_at_synthesize_declaration (parser);
1363 break;
1364 case RID_AT_DYNAMIC:
1365 gcc_assert (c_dialect_objc ());
1366 c_parser_objc_at_dynamic_declaration (parser);
1367 break;
1368 case RID_AT_END:
1369 gcc_assert (c_dialect_objc ());
1370 c_parser_consume_token (parser);
1371 objc_finish_implementation ();
1372 break;
1373 default:
1374 goto decl_or_fndef;
1376 break;
1377 case CPP_SEMICOLON:
1378 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1379 "ISO C does not allow extra %<;%> outside of a function");
1380 c_parser_consume_token (parser);
1381 break;
1382 case CPP_PRAGMA:
1383 mark_valid_location_for_stdc_pragma (true);
1384 c_parser_pragma (parser, pragma_external);
1385 mark_valid_location_for_stdc_pragma (false);
1386 break;
1387 case CPP_PLUS:
1388 case CPP_MINUS:
1389 if (c_dialect_objc ())
1391 c_parser_objc_method_definition (parser);
1392 break;
1394 /* Else fall through, and yield a syntax error trying to parse
1395 as a declaration or function definition. */
1396 default:
1397 decl_or_fndef:
1398 /* A declaration or a function definition (or, in Objective-C,
1399 an @interface or @protocol with prefix attributes). We can
1400 only tell which after parsing the declaration specifiers, if
1401 any, and the first declarator. */
1402 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1403 NULL, vNULL);
1404 break;
1408 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1410 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1411 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1412 accepted; otherwise (old-style parameter declarations) only other
1413 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1414 assertion is accepted; otherwise (old-style parameter declarations)
1415 it is not. If NESTED is true, we are inside a function or parsing
1416 old-style parameter declarations; any functions encountered are
1417 nested functions and declaration specifiers are required; otherwise
1418 we are at top level and functions are normal functions and
1419 declaration specifiers may be optional. If EMPTY_OK is true, empty
1420 declarations are OK (subject to all other constraints); otherwise
1421 (old-style parameter declarations) they are diagnosed. If
1422 START_ATTR_OK is true, the declaration specifiers may start with
1423 attributes; otherwise they may not.
1424 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1425 declaration when parsing an Objective-C foreach statement.
1427 declaration:
1428 declaration-specifiers init-declarator-list[opt] ;
1429 static_assert-declaration
1431 function-definition:
1432 declaration-specifiers[opt] declarator declaration-list[opt]
1433 compound-statement
1435 declaration-list:
1436 declaration
1437 declaration-list declaration
1439 init-declarator-list:
1440 init-declarator
1441 init-declarator-list , init-declarator
1443 init-declarator:
1444 declarator simple-asm-expr[opt] attributes[opt]
1445 declarator simple-asm-expr[opt] attributes[opt] = initializer
1447 GNU extensions:
1449 nested-function-definition:
1450 declaration-specifiers declarator declaration-list[opt]
1451 compound-statement
1453 Objective-C:
1454 attributes objc-class-definition
1455 attributes objc-category-definition
1456 attributes objc-protocol-definition
1458 The simple-asm-expr and attributes are GNU extensions.
1460 This function does not handle __extension__; that is handled in its
1461 callers. ??? Following the old parser, __extension__ may start
1462 external declarations, declarations in functions and declarations
1463 at the start of "for" loops, but not old-style parameter
1464 declarations.
1466 C99 requires declaration specifiers in a function definition; the
1467 absence is diagnosed through the diagnosis of implicit int. In GNU
1468 C we also allow but diagnose declarations without declaration
1469 specifiers, but only at top level (elsewhere they conflict with
1470 other syntax).
1472 In Objective-C, declarations of the looping variable in a foreach
1473 statement are exceptionally terminated by 'in' (for example, 'for
1474 (NSObject *object in array) { ... }').
1476 OpenMP:
1478 declaration:
1479 threadprivate-directive */
1481 static void
1482 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1483 bool static_assert_ok, bool empty_ok,
1484 bool nested, bool start_attr_ok,
1485 tree *objc_foreach_object_declaration,
1486 vec<c_token> omp_declare_simd_clauses)
1488 struct c_declspecs *specs;
1489 tree prefix_attrs;
1490 tree all_prefix_attrs;
1491 bool diagnosed_no_specs = false;
1492 location_t here = c_parser_peek_token (parser)->location;
1494 if (static_assert_ok
1495 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1497 c_parser_static_assert_declaration (parser);
1498 return;
1500 specs = build_null_declspecs ();
1502 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1503 if (c_parser_peek_token (parser)->type == CPP_NAME
1504 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1505 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1506 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1507 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1509 error_at (here, "unknown type name %qE",
1510 c_parser_peek_token (parser)->value);
1512 /* Parse declspecs normally to get a correct pointer type, but avoid
1513 a further "fails to be a type name" error. Refuse nested functions
1514 since it is not how the user likely wants us to recover. */
1515 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1516 c_parser_peek_token (parser)->keyword = RID_VOID;
1517 c_parser_peek_token (parser)->value = error_mark_node;
1518 fndef_ok = !nested;
1521 c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1522 true, true, cla_nonabstract_decl);
1523 if (parser->error)
1525 c_parser_skip_to_end_of_block_or_statement (parser);
1526 return;
1528 if (nested && !specs->declspecs_seen_p)
1530 c_parser_error (parser, "expected declaration specifiers");
1531 c_parser_skip_to_end_of_block_or_statement (parser);
1532 return;
1534 finish_declspecs (specs);
1535 bool auto_type_p = specs->typespec_word == cts_auto_type;
1536 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1538 if (auto_type_p)
1539 error_at (here, "%<__auto_type%> in empty declaration");
1540 else if (empty_ok)
1541 shadow_tag (specs);
1542 else
1544 shadow_tag_warned (specs, 1);
1545 pedwarn (here, 0, "empty declaration");
1547 c_parser_consume_token (parser);
1548 return;
1551 /* Provide better error recovery. Note that a type name here is usually
1552 better diagnosed as a redeclaration. */
1553 if (empty_ok
1554 && specs->typespec_kind == ctsk_tagdef
1555 && c_parser_next_token_starts_declspecs (parser)
1556 && !c_parser_next_token_is (parser, CPP_NAME))
1558 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1559 parser->error = false;
1560 shadow_tag_warned (specs, 1);
1561 return;
1563 else if (c_dialect_objc () && !auto_type_p)
1565 /* Prefix attributes are an error on method decls. */
1566 switch (c_parser_peek_token (parser)->type)
1568 case CPP_PLUS:
1569 case CPP_MINUS:
1570 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1571 return;
1572 if (specs->attrs)
1574 warning_at (c_parser_peek_token (parser)->location,
1575 OPT_Wattributes,
1576 "prefix attributes are ignored for methods");
1577 specs->attrs = NULL_TREE;
1579 if (fndef_ok)
1580 c_parser_objc_method_definition (parser);
1581 else
1582 c_parser_objc_methodproto (parser);
1583 return;
1584 break;
1585 default:
1586 break;
1588 /* This is where we parse 'attributes @interface ...',
1589 'attributes @implementation ...', 'attributes @protocol ...'
1590 (where attributes could be, for example, __attribute__
1591 ((deprecated)).
1593 switch (c_parser_peek_token (parser)->keyword)
1595 case RID_AT_INTERFACE:
1597 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1598 return;
1599 c_parser_objc_class_definition (parser, specs->attrs);
1600 return;
1602 break;
1603 case RID_AT_IMPLEMENTATION:
1605 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1606 return;
1607 if (specs->attrs)
1609 warning_at (c_parser_peek_token (parser)->location,
1610 OPT_Wattributes,
1611 "prefix attributes are ignored for implementations");
1612 specs->attrs = NULL_TREE;
1614 c_parser_objc_class_definition (parser, NULL_TREE);
1615 return;
1617 break;
1618 case RID_AT_PROTOCOL:
1620 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1621 return;
1622 c_parser_objc_protocol_definition (parser, specs->attrs);
1623 return;
1625 break;
1626 case RID_AT_ALIAS:
1627 case RID_AT_CLASS:
1628 case RID_AT_END:
1629 case RID_AT_PROPERTY:
1630 if (specs->attrs)
1632 c_parser_error (parser, "unexpected attribute");
1633 specs->attrs = NULL;
1635 break;
1636 default:
1637 break;
1641 pending_xref_error ();
1642 prefix_attrs = specs->attrs;
1643 all_prefix_attrs = prefix_attrs;
1644 specs->attrs = NULL_TREE;
1645 while (true)
1647 struct c_declarator *declarator;
1648 bool dummy = false;
1649 timevar_id_t tv;
1650 tree fnbody;
1651 /* Declaring either one or more declarators (in which case we
1652 should diagnose if there were no declaration specifiers) or a
1653 function definition (in which case the diagnostic for
1654 implicit int suffices). */
1655 declarator = c_parser_declarator (parser,
1656 specs->typespec_kind != ctsk_none,
1657 C_DTR_NORMAL, &dummy);
1658 if (declarator == NULL)
1660 if (omp_declare_simd_clauses.exists ()
1661 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1662 c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1663 omp_declare_simd_clauses);
1664 c_parser_skip_to_end_of_block_or_statement (parser);
1665 return;
1667 if (auto_type_p && declarator->kind != cdk_id)
1669 error_at (here,
1670 "%<__auto_type%> requires a plain identifier"
1671 " as declarator");
1672 c_parser_skip_to_end_of_block_or_statement (parser);
1673 return;
1675 if (c_parser_next_token_is (parser, CPP_EQ)
1676 || c_parser_next_token_is (parser, CPP_COMMA)
1677 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1678 || c_parser_next_token_is_keyword (parser, RID_ASM)
1679 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1680 || c_parser_next_token_is_keyword (parser, RID_IN))
1682 tree asm_name = NULL_TREE;
1683 tree postfix_attrs = NULL_TREE;
1684 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1686 diagnosed_no_specs = true;
1687 pedwarn (here, 0, "data definition has no type or storage class");
1689 /* Having seen a data definition, there cannot now be a
1690 function definition. */
1691 fndef_ok = false;
1692 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1693 asm_name = c_parser_simple_asm_expr (parser);
1694 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1696 postfix_attrs = c_parser_attributes (parser);
1697 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1699 /* This means there is an attribute specifier after
1700 the declarator in a function definition. Provide
1701 some more information for the user. */
1702 error_at (here, "attributes should be specified before the "
1703 "declarator in a function definition");
1704 c_parser_skip_to_end_of_block_or_statement (parser);
1705 return;
1708 if (c_parser_next_token_is (parser, CPP_EQ))
1710 tree d;
1711 struct c_expr init;
1712 location_t init_loc;
1713 c_parser_consume_token (parser);
1714 if (auto_type_p)
1716 start_init (NULL_TREE, asm_name, global_bindings_p ());
1717 init_loc = c_parser_peek_token (parser)->location;
1718 init = c_parser_expr_no_commas (parser, NULL);
1719 if (TREE_CODE (init.value) == COMPONENT_REF
1720 && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
1721 error_at (here,
1722 "%<__auto_type%> used with a bit-field"
1723 " initializer");
1724 init = convert_lvalue_to_rvalue (init_loc, init, true, true);
1725 tree init_type = TREE_TYPE (init.value);
1726 /* As with typeof, remove _Atomic and const
1727 qualifiers from atomic types. */
1728 if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
1729 init_type
1730 = c_build_qualified_type (init_type,
1731 (TYPE_QUALS (init_type)
1732 & ~(TYPE_QUAL_ATOMIC
1733 | TYPE_QUAL_CONST)));
1734 bool vm_type = variably_modified_type_p (init_type,
1735 NULL_TREE);
1736 if (vm_type)
1737 init.value = c_save_expr (init.value);
1738 finish_init ();
1739 specs->typespec_kind = ctsk_typeof;
1740 specs->locations[cdw_typedef] = init_loc;
1741 specs->typedef_p = true;
1742 specs->type = init_type;
1743 if (vm_type)
1745 bool maybe_const = true;
1746 tree type_expr = c_fully_fold (init.value, false,
1747 &maybe_const);
1748 specs->expr_const_operands &= maybe_const;
1749 if (specs->expr)
1750 specs->expr = build2 (COMPOUND_EXPR,
1751 TREE_TYPE (type_expr),
1752 specs->expr, type_expr);
1753 else
1754 specs->expr = type_expr;
1756 d = start_decl (declarator, specs, true,
1757 chainon (postfix_attrs, all_prefix_attrs));
1758 if (!d)
1759 d = error_mark_node;
1760 if (omp_declare_simd_clauses.exists ()
1761 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1762 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1763 omp_declare_simd_clauses);
1765 else
1767 /* The declaration of the variable is in effect while
1768 its initializer is parsed. */
1769 d = start_decl (declarator, specs, true,
1770 chainon (postfix_attrs, all_prefix_attrs));
1771 if (!d)
1772 d = error_mark_node;
1773 if (omp_declare_simd_clauses.exists ()
1774 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1775 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1776 omp_declare_simd_clauses);
1777 start_init (d, asm_name, global_bindings_p ());
1778 init_loc = c_parser_peek_token (parser)->location;
1779 init = c_parser_initializer (parser);
1780 finish_init ();
1782 if (d != error_mark_node)
1784 maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
1785 finish_decl (d, init_loc, init.value,
1786 init.original_type, asm_name);
1789 else
1791 if (auto_type_p)
1793 error_at (here,
1794 "%<__auto_type%> requires an initialized "
1795 "data declaration");
1796 c_parser_skip_to_end_of_block_or_statement (parser);
1797 return;
1799 tree d = start_decl (declarator, specs, false,
1800 chainon (postfix_attrs,
1801 all_prefix_attrs));
1802 if (omp_declare_simd_clauses.exists ()
1803 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1805 tree parms = NULL_TREE;
1806 if (d && TREE_CODE (d) == FUNCTION_DECL)
1808 struct c_declarator *ce = declarator;
1809 while (ce != NULL)
1810 if (ce->kind == cdk_function)
1812 parms = ce->u.arg_info->parms;
1813 break;
1815 else
1816 ce = ce->declarator;
1818 if (parms)
1819 temp_store_parm_decls (d, parms);
1820 c_finish_omp_declare_simd (parser, d, parms,
1821 omp_declare_simd_clauses);
1822 if (parms)
1823 temp_pop_parm_decls ();
1825 if (d)
1826 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1827 NULL_TREE, asm_name);
1829 if (c_parser_next_token_is_keyword (parser, RID_IN))
1831 if (d)
1832 *objc_foreach_object_declaration = d;
1833 else
1834 *objc_foreach_object_declaration = error_mark_node;
1837 if (c_parser_next_token_is (parser, CPP_COMMA))
1839 if (auto_type_p)
1841 error_at (here,
1842 "%<__auto_type%> may only be used with"
1843 " a single declarator");
1844 c_parser_skip_to_end_of_block_or_statement (parser);
1845 return;
1847 c_parser_consume_token (parser);
1848 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1849 all_prefix_attrs = chainon (c_parser_attributes (parser),
1850 prefix_attrs);
1851 else
1852 all_prefix_attrs = prefix_attrs;
1853 continue;
1855 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1857 c_parser_consume_token (parser);
1858 return;
1860 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1862 /* This can only happen in Objective-C: we found the
1863 'in' that terminates the declaration inside an
1864 Objective-C foreach statement. Do not consume the
1865 token, so that the caller can use it to determine
1866 that this indeed is a foreach context. */
1867 return;
1869 else
1871 c_parser_error (parser, "expected %<,%> or %<;%>");
1872 c_parser_skip_to_end_of_block_or_statement (parser);
1873 return;
1876 else if (auto_type_p)
1878 error_at (here,
1879 "%<__auto_type%> requires an initialized data declaration");
1880 c_parser_skip_to_end_of_block_or_statement (parser);
1881 return;
1883 else if (!fndef_ok)
1885 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1886 "%<asm%> or %<__attribute__%>");
1887 c_parser_skip_to_end_of_block_or_statement (parser);
1888 return;
1890 /* Function definition (nested or otherwise). */
1891 if (nested)
1893 pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
1894 c_push_function_context ();
1896 if (!start_function (specs, declarator, all_prefix_attrs))
1898 /* This can appear in many cases looking nothing like a
1899 function definition, so we don't give a more specific
1900 error suggesting there was one. */
1901 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1902 "or %<__attribute__%>");
1903 if (nested)
1904 c_pop_function_context ();
1905 break;
1908 if (DECL_DECLARED_INLINE_P (current_function_decl))
1909 tv = TV_PARSE_INLINE;
1910 else
1911 tv = TV_PARSE_FUNC;
1912 timevar_push (tv);
1914 /* Parse old-style parameter declarations. ??? Attributes are
1915 not allowed to start declaration specifiers here because of a
1916 syntax conflict between a function declaration with attribute
1917 suffix and a function definition with an attribute prefix on
1918 first old-style parameter declaration. Following the old
1919 parser, they are not accepted on subsequent old-style
1920 parameter declarations either. However, there is no
1921 ambiguity after the first declaration, nor indeed on the
1922 first as long as we don't allow postfix attributes after a
1923 declarator with a nonempty identifier list in a definition;
1924 and postfix attributes have never been accepted here in
1925 function definitions either. */
1926 while (c_parser_next_token_is_not (parser, CPP_EOF)
1927 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1928 c_parser_declaration_or_fndef (parser, false, false, false,
1929 true, false, NULL, vNULL);
1930 store_parm_decls ();
1931 if (omp_declare_simd_clauses.exists ()
1932 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1933 c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
1934 omp_declare_simd_clauses);
1935 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1936 = c_parser_peek_token (parser)->location;
1937 fnbody = c_parser_compound_statement (parser);
1938 if (flag_cilkplus && contains_array_notation_expr (fnbody))
1939 fnbody = expand_array_notation_exprs (fnbody);
1940 if (nested)
1942 tree decl = current_function_decl;
1943 /* Mark nested functions as needing static-chain initially.
1944 lower_nested_functions will recompute it but the
1945 DECL_STATIC_CHAIN flag is also used before that happens,
1946 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1947 DECL_STATIC_CHAIN (decl) = 1;
1948 add_stmt (fnbody);
1949 finish_function ();
1950 c_pop_function_context ();
1951 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1953 else
1955 add_stmt (fnbody);
1956 finish_function ();
1959 timevar_pop (tv);
1960 break;
1964 /* Parse an asm-definition (asm() outside a function body). This is a
1965 GNU extension.
1967 asm-definition:
1968 simple-asm-expr ;
1971 static void
1972 c_parser_asm_definition (c_parser *parser)
1974 tree asm_str = c_parser_simple_asm_expr (parser);
1975 if (asm_str)
1976 add_asm_node (asm_str);
1977 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1980 /* Parse a static assertion (C11 6.7.10).
1982 static_assert-declaration:
1983 static_assert-declaration-no-semi ;
1986 static void
1987 c_parser_static_assert_declaration (c_parser *parser)
1989 c_parser_static_assert_declaration_no_semi (parser);
1990 if (parser->error
1991 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1992 c_parser_skip_to_end_of_block_or_statement (parser);
1995 /* Parse a static assertion (C11 6.7.10), without the trailing
1996 semicolon.
1998 static_assert-declaration-no-semi:
1999 _Static_assert ( constant-expression , string-literal )
2002 static void
2003 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2005 location_t assert_loc, value_loc;
2006 tree value;
2007 tree string;
2009 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2010 assert_loc = c_parser_peek_token (parser)->location;
2011 if (!flag_isoc11)
2013 if (flag_isoc99)
2014 pedwarn (assert_loc, OPT_Wpedantic,
2015 "ISO C99 does not support %<_Static_assert%>");
2016 else
2017 pedwarn (assert_loc, OPT_Wpedantic,
2018 "ISO C90 does not support %<_Static_assert%>");
2020 c_parser_consume_token (parser);
2021 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2022 return;
2023 value_loc = c_parser_peek_token (parser)->location;
2024 value = c_parser_expr_no_commas (parser, NULL).value;
2025 parser->lex_untranslated_string = true;
2026 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2028 parser->lex_untranslated_string = false;
2029 return;
2031 switch (c_parser_peek_token (parser)->type)
2033 case CPP_STRING:
2034 case CPP_STRING16:
2035 case CPP_STRING32:
2036 case CPP_WSTRING:
2037 case CPP_UTF8STRING:
2038 string = c_parser_peek_token (parser)->value;
2039 c_parser_consume_token (parser);
2040 parser->lex_untranslated_string = false;
2041 break;
2042 default:
2043 c_parser_error (parser, "expected string literal");
2044 parser->lex_untranslated_string = false;
2045 return;
2047 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2049 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2051 error_at (value_loc, "expression in static assertion is not an integer");
2052 return;
2054 if (TREE_CODE (value) != INTEGER_CST)
2056 value = c_fully_fold (value, false, NULL);
2057 if (TREE_CODE (value) == INTEGER_CST)
2058 pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2059 "is not an integer constant expression");
2061 if (TREE_CODE (value) != INTEGER_CST)
2063 error_at (value_loc, "expression in static assertion is not constant");
2064 return;
2066 constant_expression_warning (value);
2067 if (integer_zerop (value))
2068 error_at (assert_loc, "static assertion failed: %E", string);
2071 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2072 6.7), adding them to SPECS (which may already include some).
2073 Storage class specifiers are accepted iff SCSPEC_OK; type
2074 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2075 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2076 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2078 declaration-specifiers:
2079 storage-class-specifier declaration-specifiers[opt]
2080 type-specifier declaration-specifiers[opt]
2081 type-qualifier declaration-specifiers[opt]
2082 function-specifier declaration-specifiers[opt]
2083 alignment-specifier declaration-specifiers[opt]
2085 Function specifiers (inline) are from C99, and are currently
2086 handled as storage class specifiers, as is __thread. Alignment
2087 specifiers are from C11.
2089 C90 6.5.1, C99 6.7.1:
2090 storage-class-specifier:
2091 typedef
2092 extern
2093 static
2094 auto
2095 register
2096 _Thread_local
2098 (_Thread_local is new in C11.)
2100 C99 6.7.4:
2101 function-specifier:
2102 inline
2103 _Noreturn
2105 (_Noreturn is new in C11.)
2107 C90 6.5.2, C99 6.7.2:
2108 type-specifier:
2109 void
2110 char
2111 short
2113 long
2114 float
2115 double
2116 signed
2117 unsigned
2118 _Bool
2119 _Complex
2120 [_Imaginary removed in C99 TC2]
2121 struct-or-union-specifier
2122 enum-specifier
2123 typedef-name
2124 atomic-type-specifier
2126 (_Bool and _Complex are new in C99.)
2127 (atomic-type-specifier is new in C11.)
2129 C90 6.5.3, C99 6.7.3:
2131 type-qualifier:
2132 const
2133 restrict
2134 volatile
2135 address-space-qualifier
2136 _Atomic
2138 (restrict is new in C99.)
2139 (_Atomic is new in C11.)
2141 GNU extensions:
2143 declaration-specifiers:
2144 attributes declaration-specifiers[opt]
2146 type-qualifier:
2147 address-space
2149 address-space:
2150 identifier recognized by the target
2152 storage-class-specifier:
2153 __thread
2155 type-specifier:
2156 typeof-specifier
2157 __auto_type
2158 __int128
2159 _Decimal32
2160 _Decimal64
2161 _Decimal128
2162 _Fract
2163 _Accum
2164 _Sat
2166 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2167 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2169 atomic-type-specifier
2170 _Atomic ( type-name )
2172 Objective-C:
2174 type-specifier:
2175 class-name objc-protocol-refs[opt]
2176 typedef-name objc-protocol-refs
2177 objc-protocol-refs
2180 static void
2181 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2182 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2183 bool alignspec_ok, bool auto_type_ok,
2184 enum c_lookahead_kind la)
2186 bool attrs_ok = start_attr_ok;
2187 bool seen_type = specs->typespec_kind != ctsk_none;
2189 if (!typespec_ok)
2190 gcc_assert (la == cla_prefer_id);
2192 while (c_parser_next_token_is (parser, CPP_NAME)
2193 || c_parser_next_token_is (parser, CPP_KEYWORD)
2194 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2196 struct c_typespec t;
2197 tree attrs;
2198 tree align;
2199 location_t loc = c_parser_peek_token (parser)->location;
2201 /* If we cannot accept a type, exit if the next token must start
2202 one. Also, if we already have seen a tagged definition,
2203 a typename would be an error anyway and likely the user
2204 has simply forgotten a semicolon, so we exit. */
2205 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2206 && c_parser_next_tokens_start_typename (parser, la)
2207 && !c_parser_next_token_is_qualifier (parser))
2208 break;
2210 if (c_parser_next_token_is (parser, CPP_NAME))
2212 c_token *name_token = c_parser_peek_token (parser);
2213 tree value = name_token->value;
2214 c_id_kind kind = name_token->id_kind;
2216 if (kind == C_ID_ADDRSPACE)
2218 addr_space_t as
2219 = name_token->keyword - RID_FIRST_ADDR_SPACE;
2220 declspecs_add_addrspace (name_token->location, specs, as);
2221 c_parser_consume_token (parser);
2222 attrs_ok = true;
2223 continue;
2226 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2228 /* If we cannot accept a type, and the next token must start one,
2229 exit. Do the same if we already have seen a tagged definition,
2230 since it would be an error anyway and likely the user has simply
2231 forgotten a semicolon. */
2232 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2233 break;
2235 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2236 a C_ID_CLASSNAME. */
2237 c_parser_consume_token (parser);
2238 seen_type = true;
2239 attrs_ok = true;
2240 if (kind == C_ID_ID)
2242 error_at (loc, "unknown type name %qE", value);
2243 t.kind = ctsk_typedef;
2244 t.spec = error_mark_node;
2246 else if (kind == C_ID_TYPENAME
2247 && (!c_dialect_objc ()
2248 || c_parser_next_token_is_not (parser, CPP_LESS)))
2250 t.kind = ctsk_typedef;
2251 /* For a typedef name, record the meaning, not the name.
2252 In case of 'foo foo, bar;'. */
2253 t.spec = lookup_name (value);
2255 else
2257 tree proto = NULL_TREE;
2258 gcc_assert (c_dialect_objc ());
2259 t.kind = ctsk_objc;
2260 if (c_parser_next_token_is (parser, CPP_LESS))
2261 proto = c_parser_objc_protocol_refs (parser);
2262 t.spec = objc_get_protocol_qualified_type (value, proto);
2264 t.expr = NULL_TREE;
2265 t.expr_const_operands = true;
2266 declspecs_add_type (name_token->location, specs, t);
2267 continue;
2269 if (c_parser_next_token_is (parser, CPP_LESS))
2271 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2272 nisse@lysator.liu.se. */
2273 tree proto;
2274 gcc_assert (c_dialect_objc ());
2275 if (!typespec_ok || seen_type)
2276 break;
2277 proto = c_parser_objc_protocol_refs (parser);
2278 t.kind = ctsk_objc;
2279 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2280 t.expr = NULL_TREE;
2281 t.expr_const_operands = true;
2282 declspecs_add_type (loc, specs, t);
2283 continue;
2285 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2286 switch (c_parser_peek_token (parser)->keyword)
2288 case RID_STATIC:
2289 case RID_EXTERN:
2290 case RID_REGISTER:
2291 case RID_TYPEDEF:
2292 case RID_INLINE:
2293 case RID_NORETURN:
2294 case RID_AUTO:
2295 case RID_THREAD:
2296 if (!scspec_ok)
2297 goto out;
2298 attrs_ok = true;
2299 /* TODO: Distinguish between function specifiers (inline, noreturn)
2300 and storage class specifiers, either here or in
2301 declspecs_add_scspec. */
2302 declspecs_add_scspec (loc, specs,
2303 c_parser_peek_token (parser)->value);
2304 c_parser_consume_token (parser);
2305 break;
2306 case RID_AUTO_TYPE:
2307 if (!auto_type_ok)
2308 goto out;
2309 /* Fall through. */
2310 case RID_UNSIGNED:
2311 case RID_LONG:
2312 case RID_INT128:
2313 case RID_SHORT:
2314 case RID_SIGNED:
2315 case RID_COMPLEX:
2316 case RID_INT:
2317 case RID_CHAR:
2318 case RID_FLOAT:
2319 case RID_DOUBLE:
2320 case RID_VOID:
2321 case RID_DFLOAT32:
2322 case RID_DFLOAT64:
2323 case RID_DFLOAT128:
2324 case RID_BOOL:
2325 case RID_FRACT:
2326 case RID_ACCUM:
2327 case RID_SAT:
2328 if (!typespec_ok)
2329 goto out;
2330 attrs_ok = true;
2331 seen_type = true;
2332 if (c_dialect_objc ())
2333 parser->objc_need_raw_identifier = true;
2334 t.kind = ctsk_resword;
2335 t.spec = c_parser_peek_token (parser)->value;
2336 t.expr = NULL_TREE;
2337 t.expr_const_operands = true;
2338 declspecs_add_type (loc, specs, t);
2339 c_parser_consume_token (parser);
2340 break;
2341 case RID_ENUM:
2342 if (!typespec_ok)
2343 goto out;
2344 attrs_ok = true;
2345 seen_type = true;
2346 t = c_parser_enum_specifier (parser);
2347 declspecs_add_type (loc, specs, t);
2348 break;
2349 case RID_STRUCT:
2350 case RID_UNION:
2351 if (!typespec_ok)
2352 goto out;
2353 attrs_ok = true;
2354 seen_type = true;
2355 t = c_parser_struct_or_union_specifier (parser);
2356 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2357 declspecs_add_type (loc, specs, t);
2358 break;
2359 case RID_TYPEOF:
2360 /* ??? The old parser rejected typeof after other type
2361 specifiers, but is a syntax error the best way of
2362 handling this? */
2363 if (!typespec_ok || seen_type)
2364 goto out;
2365 attrs_ok = true;
2366 seen_type = true;
2367 t = c_parser_typeof_specifier (parser);
2368 declspecs_add_type (loc, specs, t);
2369 break;
2370 case RID_ATOMIC:
2371 /* C parser handling of Objective-C constructs needs
2372 checking for correct lvalue-to-rvalue conversions, and
2373 the code in build_modify_expr handling various
2374 Objective-C cases, and that in build_unary_op handling
2375 Objective-C cases for increment / decrement, also needs
2376 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2377 and objc_types_are_equivalent may also need updates. */
2378 if (c_dialect_objc ())
2379 sorry ("%<_Atomic%> in Objective-C");
2380 /* C parser handling of OpenMP constructs needs checking for
2381 correct lvalue-to-rvalue conversions. */
2382 if (flag_openmp)
2383 sorry ("%<_Atomic%> with OpenMP");
2384 if (!flag_isoc11)
2386 if (flag_isoc99)
2387 pedwarn (loc, OPT_Wpedantic,
2388 "ISO C99 does not support the %<_Atomic%> qualifier");
2389 else
2390 pedwarn (loc, OPT_Wpedantic,
2391 "ISO C90 does not support the %<_Atomic%> qualifier");
2393 attrs_ok = true;
2394 tree value;
2395 value = c_parser_peek_token (parser)->value;
2396 c_parser_consume_token (parser);
2397 if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2399 /* _Atomic ( type-name ). */
2400 seen_type = true;
2401 c_parser_consume_token (parser);
2402 struct c_type_name *type = c_parser_type_name (parser);
2403 t.kind = ctsk_typeof;
2404 t.spec = error_mark_node;
2405 t.expr = NULL_TREE;
2406 t.expr_const_operands = true;
2407 if (type != NULL)
2408 t.spec = groktypename (type, &t.expr,
2409 &t.expr_const_operands);
2410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2411 "expected %<)%>");
2412 if (t.spec != error_mark_node)
2414 if (TREE_CODE (t.spec) == ARRAY_TYPE)
2415 error_at (loc, "%<_Atomic%>-qualified array type");
2416 else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2417 error_at (loc, "%<_Atomic%>-qualified function type");
2418 else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2419 error_at (loc, "%<_Atomic%> applied to a qualified type");
2420 else
2421 t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2423 declspecs_add_type (loc, specs, t);
2425 else
2426 declspecs_add_qual (loc, specs, value);
2427 break;
2428 case RID_CONST:
2429 case RID_VOLATILE:
2430 case RID_RESTRICT:
2431 attrs_ok = true;
2432 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2433 c_parser_consume_token (parser);
2434 break;
2435 case RID_ATTRIBUTE:
2436 if (!attrs_ok)
2437 goto out;
2438 attrs = c_parser_attributes (parser);
2439 declspecs_add_attrs (loc, specs, attrs);
2440 break;
2441 case RID_ALIGNAS:
2442 if (!alignspec_ok)
2443 goto out;
2444 align = c_parser_alignas_specifier (parser);
2445 declspecs_add_alignas (loc, specs, align);
2446 break;
2447 default:
2448 goto out;
2451 out: ;
2454 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2456 enum-specifier:
2457 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2458 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2459 enum attributes[opt] identifier
2461 The form with trailing comma is new in C99. The forms with
2462 attributes are GNU extensions. In GNU C, we accept any expression
2463 without commas in the syntax (assignment expressions, not just
2464 conditional expressions); assignment expressions will be diagnosed
2465 as non-constant.
2467 enumerator-list:
2468 enumerator
2469 enumerator-list , enumerator
2471 enumerator:
2472 enumeration-constant
2473 enumeration-constant = constant-expression
2476 static struct c_typespec
2477 c_parser_enum_specifier (c_parser *parser)
2479 struct c_typespec ret;
2480 tree attrs;
2481 tree ident = NULL_TREE;
2482 location_t enum_loc;
2483 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2484 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2485 enum_loc = c_parser_peek_token (parser)->location;
2486 c_parser_consume_token (parser);
2487 attrs = c_parser_attributes (parser);
2488 enum_loc = c_parser_peek_token (parser)->location;
2489 /* Set the location in case we create a decl now. */
2490 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2491 if (c_parser_next_token_is (parser, CPP_NAME))
2493 ident = c_parser_peek_token (parser)->value;
2494 ident_loc = c_parser_peek_token (parser)->location;
2495 enum_loc = ident_loc;
2496 c_parser_consume_token (parser);
2498 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2500 /* Parse an enum definition. */
2501 struct c_enum_contents the_enum;
2502 tree type;
2503 tree postfix_attrs;
2504 /* We chain the enumerators in reverse order, then put them in
2505 forward order at the end. */
2506 tree values;
2507 timevar_push (TV_PARSE_ENUM);
2508 type = start_enum (enum_loc, &the_enum, ident);
2509 values = NULL_TREE;
2510 c_parser_consume_token (parser);
2511 while (true)
2513 tree enum_id;
2514 tree enum_value;
2515 tree enum_decl;
2516 bool seen_comma;
2517 c_token *token;
2518 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2519 location_t decl_loc, value_loc;
2520 if (c_parser_next_token_is_not (parser, CPP_NAME))
2522 c_parser_error (parser, "expected identifier");
2523 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2524 values = error_mark_node;
2525 break;
2527 token = c_parser_peek_token (parser);
2528 enum_id = token->value;
2529 /* Set the location in case we create a decl now. */
2530 c_parser_set_source_position_from_token (token);
2531 decl_loc = value_loc = token->location;
2532 c_parser_consume_token (parser);
2533 if (c_parser_next_token_is (parser, CPP_EQ))
2535 c_parser_consume_token (parser);
2536 value_loc = c_parser_peek_token (parser)->location;
2537 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2539 else
2540 enum_value = NULL_TREE;
2541 enum_decl = build_enumerator (decl_loc, value_loc,
2542 &the_enum, enum_id, enum_value);
2543 TREE_CHAIN (enum_decl) = values;
2544 values = enum_decl;
2545 seen_comma = false;
2546 if (c_parser_next_token_is (parser, CPP_COMMA))
2548 comma_loc = c_parser_peek_token (parser)->location;
2549 seen_comma = true;
2550 c_parser_consume_token (parser);
2552 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2554 if (seen_comma && !flag_isoc99)
2555 pedwarn (comma_loc, OPT_Wpedantic, "comma at end of enumerator list");
2556 c_parser_consume_token (parser);
2557 break;
2559 if (!seen_comma)
2561 c_parser_error (parser, "expected %<,%> or %<}%>");
2562 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2563 values = error_mark_node;
2564 break;
2567 postfix_attrs = c_parser_attributes (parser);
2568 ret.spec = finish_enum (type, nreverse (values),
2569 chainon (attrs, postfix_attrs));
2570 ret.kind = ctsk_tagdef;
2571 ret.expr = NULL_TREE;
2572 ret.expr_const_operands = true;
2573 timevar_pop (TV_PARSE_ENUM);
2574 return ret;
2576 else if (!ident)
2578 c_parser_error (parser, "expected %<{%>");
2579 ret.spec = error_mark_node;
2580 ret.kind = ctsk_tagref;
2581 ret.expr = NULL_TREE;
2582 ret.expr_const_operands = true;
2583 return ret;
2585 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2586 /* In ISO C, enumerated types can be referred to only if already
2587 defined. */
2588 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2590 gcc_assert (ident);
2591 pedwarn (enum_loc, OPT_Wpedantic,
2592 "ISO C forbids forward references to %<enum%> types");
2594 return ret;
2597 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2599 struct-or-union-specifier:
2600 struct-or-union attributes[opt] identifier[opt]
2601 { struct-contents } attributes[opt]
2602 struct-or-union attributes[opt] identifier
2604 struct-contents:
2605 struct-declaration-list
2607 struct-declaration-list:
2608 struct-declaration ;
2609 struct-declaration-list struct-declaration ;
2611 GNU extensions:
2613 struct-contents:
2614 empty
2615 struct-declaration
2616 struct-declaration-list struct-declaration
2618 struct-declaration-list:
2619 struct-declaration-list ;
2622 (Note that in the syntax here, unlike that in ISO C, the semicolons
2623 are included here rather than in struct-declaration, in order to
2624 describe the syntax with extra semicolons and missing semicolon at
2625 end.)
2627 Objective-C:
2629 struct-declaration-list:
2630 @defs ( class-name )
2632 (Note this does not include a trailing semicolon, but can be
2633 followed by further declarations, and gets a pedwarn-if-pedantic
2634 when followed by a semicolon.) */
2636 static struct c_typespec
2637 c_parser_struct_or_union_specifier (c_parser *parser)
2639 struct c_typespec ret;
2640 tree attrs;
2641 tree ident = NULL_TREE;
2642 location_t struct_loc;
2643 location_t ident_loc = UNKNOWN_LOCATION;
2644 enum tree_code code;
2645 switch (c_parser_peek_token (parser)->keyword)
2647 case RID_STRUCT:
2648 code = RECORD_TYPE;
2649 break;
2650 case RID_UNION:
2651 code = UNION_TYPE;
2652 break;
2653 default:
2654 gcc_unreachable ();
2656 struct_loc = c_parser_peek_token (parser)->location;
2657 c_parser_consume_token (parser);
2658 attrs = c_parser_attributes (parser);
2660 /* Set the location in case we create a decl now. */
2661 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2663 if (c_parser_next_token_is (parser, CPP_NAME))
2665 ident = c_parser_peek_token (parser)->value;
2666 ident_loc = c_parser_peek_token (parser)->location;
2667 struct_loc = ident_loc;
2668 c_parser_consume_token (parser);
2670 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2672 /* Parse a struct or union definition. Start the scope of the
2673 tag before parsing components. */
2674 struct c_struct_parse_info *struct_info;
2675 tree type = start_struct (struct_loc, code, ident, &struct_info);
2676 tree postfix_attrs;
2677 /* We chain the components in reverse order, then put them in
2678 forward order at the end. Each struct-declaration may
2679 declare multiple components (comma-separated), so we must use
2680 chainon to join them, although when parsing each
2681 struct-declaration we can use TREE_CHAIN directly.
2683 The theory behind all this is that there will be more
2684 semicolon separated fields than comma separated fields, and
2685 so we'll be minimizing the number of node traversals required
2686 by chainon. */
2687 tree contents;
2688 timevar_push (TV_PARSE_STRUCT);
2689 contents = NULL_TREE;
2690 c_parser_consume_token (parser);
2691 /* Handle the Objective-C @defs construct,
2692 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2693 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2695 tree name;
2696 gcc_assert (c_dialect_objc ());
2697 c_parser_consume_token (parser);
2698 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2699 goto end_at_defs;
2700 if (c_parser_next_token_is (parser, CPP_NAME)
2701 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2703 name = c_parser_peek_token (parser)->value;
2704 c_parser_consume_token (parser);
2706 else
2708 c_parser_error (parser, "expected class name");
2709 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2710 goto end_at_defs;
2712 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2713 "expected %<)%>");
2714 contents = nreverse (objc_get_class_ivars (name));
2716 end_at_defs:
2717 /* Parse the struct-declarations and semicolons. Problems with
2718 semicolons are diagnosed here; empty structures are diagnosed
2719 elsewhere. */
2720 while (true)
2722 tree decls;
2723 /* Parse any stray semicolon. */
2724 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2726 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2727 "extra semicolon in struct or union specified");
2728 c_parser_consume_token (parser);
2729 continue;
2731 /* Stop if at the end of the struct or union contents. */
2732 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2734 c_parser_consume_token (parser);
2735 break;
2737 /* Accept #pragmas at struct scope. */
2738 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2740 c_parser_pragma (parser, pragma_struct);
2741 continue;
2743 /* Parse some comma-separated declarations, but not the
2744 trailing semicolon if any. */
2745 decls = c_parser_struct_declaration (parser);
2746 contents = chainon (decls, contents);
2747 /* If no semicolon follows, either we have a parse error or
2748 are at the end of the struct or union and should
2749 pedwarn. */
2750 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2751 c_parser_consume_token (parser);
2752 else
2754 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2755 pedwarn (c_parser_peek_token (parser)->location, 0,
2756 "no semicolon at end of struct or union");
2757 else if (parser->error
2758 || !c_parser_next_token_starts_declspecs (parser))
2760 c_parser_error (parser, "expected %<;%>");
2761 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2762 break;
2765 /* If we come here, we have already emitted an error
2766 for an expected `;', identifier or `(', and we also
2767 recovered already. Go on with the next field. */
2770 postfix_attrs = c_parser_attributes (parser);
2771 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2772 chainon (attrs, postfix_attrs), struct_info);
2773 ret.kind = ctsk_tagdef;
2774 ret.expr = NULL_TREE;
2775 ret.expr_const_operands = true;
2776 timevar_pop (TV_PARSE_STRUCT);
2777 return ret;
2779 else if (!ident)
2781 c_parser_error (parser, "expected %<{%>");
2782 ret.spec = error_mark_node;
2783 ret.kind = ctsk_tagref;
2784 ret.expr = NULL_TREE;
2785 ret.expr_const_operands = true;
2786 return ret;
2788 ret = parser_xref_tag (ident_loc, code, ident);
2789 return ret;
2792 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2793 the trailing semicolon.
2795 struct-declaration:
2796 specifier-qualifier-list struct-declarator-list
2797 static_assert-declaration-no-semi
2799 specifier-qualifier-list:
2800 type-specifier specifier-qualifier-list[opt]
2801 type-qualifier specifier-qualifier-list[opt]
2802 attributes specifier-qualifier-list[opt]
2804 struct-declarator-list:
2805 struct-declarator
2806 struct-declarator-list , attributes[opt] struct-declarator
2808 struct-declarator:
2809 declarator attributes[opt]
2810 declarator[opt] : constant-expression attributes[opt]
2812 GNU extensions:
2814 struct-declaration:
2815 __extension__ struct-declaration
2816 specifier-qualifier-list
2818 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2819 of attributes where shown is a GNU extension. In GNU C, we accept
2820 any expression without commas in the syntax (assignment
2821 expressions, not just conditional expressions); assignment
2822 expressions will be diagnosed as non-constant. */
2824 static tree
2825 c_parser_struct_declaration (c_parser *parser)
2827 struct c_declspecs *specs;
2828 tree prefix_attrs;
2829 tree all_prefix_attrs;
2830 tree decls;
2831 location_t decl_loc;
2832 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2834 int ext;
2835 tree decl;
2836 ext = disable_extension_diagnostics ();
2837 c_parser_consume_token (parser);
2838 decl = c_parser_struct_declaration (parser);
2839 restore_extension_diagnostics (ext);
2840 return decl;
2842 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2844 c_parser_static_assert_declaration_no_semi (parser);
2845 return NULL_TREE;
2847 specs = build_null_declspecs ();
2848 decl_loc = c_parser_peek_token (parser)->location;
2849 /* Strictly by the standard, we shouldn't allow _Alignas here,
2850 but it appears to have been intended to allow it there, so
2851 we're keeping it as it is until WG14 reaches a conclusion
2852 of N1731.
2853 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2854 c_parser_declspecs (parser, specs, false, true, true,
2855 true, false, cla_nonabstract_decl);
2856 if (parser->error)
2857 return NULL_TREE;
2858 if (!specs->declspecs_seen_p)
2860 c_parser_error (parser, "expected specifier-qualifier-list");
2861 return NULL_TREE;
2863 finish_declspecs (specs);
2864 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2865 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2867 tree ret;
2868 if (specs->typespec_kind == ctsk_none)
2870 pedwarn (decl_loc, OPT_Wpedantic,
2871 "ISO C forbids member declarations with no members");
2872 shadow_tag_warned (specs, pedantic);
2873 ret = NULL_TREE;
2875 else
2877 /* Support for unnamed structs or unions as members of
2878 structs or unions (which is [a] useful and [b] supports
2879 MS P-SDK). */
2880 tree attrs = NULL;
2882 ret = grokfield (c_parser_peek_token (parser)->location,
2883 build_id_declarator (NULL_TREE), specs,
2884 NULL_TREE, &attrs);
2885 if (ret)
2886 decl_attributes (&ret, attrs, 0);
2888 return ret;
2891 /* Provide better error recovery. Note that a type name here is valid,
2892 and will be treated as a field name. */
2893 if (specs->typespec_kind == ctsk_tagdef
2894 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2895 && c_parser_next_token_starts_declspecs (parser)
2896 && !c_parser_next_token_is (parser, CPP_NAME))
2898 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2899 parser->error = false;
2900 return NULL_TREE;
2903 pending_xref_error ();
2904 prefix_attrs = specs->attrs;
2905 all_prefix_attrs = prefix_attrs;
2906 specs->attrs = NULL_TREE;
2907 decls = NULL_TREE;
2908 while (true)
2910 /* Declaring one or more declarators or un-named bit-fields. */
2911 struct c_declarator *declarator;
2912 bool dummy = false;
2913 if (c_parser_next_token_is (parser, CPP_COLON))
2914 declarator = build_id_declarator (NULL_TREE);
2915 else
2916 declarator = c_parser_declarator (parser,
2917 specs->typespec_kind != ctsk_none,
2918 C_DTR_NORMAL, &dummy);
2919 if (declarator == NULL)
2921 c_parser_skip_to_end_of_block_or_statement (parser);
2922 break;
2924 if (c_parser_next_token_is (parser, CPP_COLON)
2925 || c_parser_next_token_is (parser, CPP_COMMA)
2926 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2927 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2928 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2930 tree postfix_attrs = NULL_TREE;
2931 tree width = NULL_TREE;
2932 tree d;
2933 if (c_parser_next_token_is (parser, CPP_COLON))
2935 c_parser_consume_token (parser);
2936 width = c_parser_expr_no_commas (parser, NULL).value;
2938 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2939 postfix_attrs = c_parser_attributes (parser);
2940 d = grokfield (c_parser_peek_token (parser)->location,
2941 declarator, specs, width, &all_prefix_attrs);
2942 decl_attributes (&d, chainon (postfix_attrs,
2943 all_prefix_attrs), 0);
2944 DECL_CHAIN (d) = decls;
2945 decls = d;
2946 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2947 all_prefix_attrs = chainon (c_parser_attributes (parser),
2948 prefix_attrs);
2949 else
2950 all_prefix_attrs = prefix_attrs;
2951 if (c_parser_next_token_is (parser, CPP_COMMA))
2952 c_parser_consume_token (parser);
2953 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2954 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2956 /* Semicolon consumed in caller. */
2957 break;
2959 else
2961 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2962 break;
2965 else
2967 c_parser_error (parser,
2968 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2969 "%<__attribute__%>");
2970 break;
2973 return decls;
2976 /* Parse a typeof specifier (a GNU extension).
2978 typeof-specifier:
2979 typeof ( expression )
2980 typeof ( type-name )
2983 static struct c_typespec
2984 c_parser_typeof_specifier (c_parser *parser)
2986 struct c_typespec ret;
2987 ret.kind = ctsk_typeof;
2988 ret.spec = error_mark_node;
2989 ret.expr = NULL_TREE;
2990 ret.expr_const_operands = true;
2991 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2992 c_parser_consume_token (parser);
2993 c_inhibit_evaluation_warnings++;
2994 in_typeof++;
2995 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2997 c_inhibit_evaluation_warnings--;
2998 in_typeof--;
2999 return ret;
3001 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3003 struct c_type_name *type = c_parser_type_name (parser);
3004 c_inhibit_evaluation_warnings--;
3005 in_typeof--;
3006 if (type != NULL)
3008 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3009 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3012 else
3014 bool was_vm;
3015 location_t here = c_parser_peek_token (parser)->location;
3016 struct c_expr expr = c_parser_expression (parser);
3017 c_inhibit_evaluation_warnings--;
3018 in_typeof--;
3019 if (TREE_CODE (expr.value) == COMPONENT_REF
3020 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3021 error_at (here, "%<typeof%> applied to a bit-field");
3022 mark_exp_read (expr.value);
3023 ret.spec = TREE_TYPE (expr.value);
3024 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3025 /* This is returned with the type so that when the type is
3026 evaluated, this can be evaluated. */
3027 if (was_vm)
3028 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3029 pop_maybe_used (was_vm);
3030 /* For use in macros such as those in <stdatomic.h>, remove
3031 _Atomic and const qualifiers from atomic types. (Possibly
3032 all qualifiers should be removed; const can be an issue for
3033 more macros using typeof than just the <stdatomic.h>
3034 ones.) */
3035 if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3036 ret.spec = c_build_qualified_type (ret.spec,
3037 (TYPE_QUALS (ret.spec)
3038 & ~(TYPE_QUAL_ATOMIC
3039 | TYPE_QUAL_CONST)));
3041 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3042 return ret;
3045 /* Parse an alignment-specifier.
3047 C11 6.7.5:
3049 alignment-specifier:
3050 _Alignas ( type-name )
3051 _Alignas ( constant-expression )
3054 static tree
3055 c_parser_alignas_specifier (c_parser * parser)
3057 tree ret = error_mark_node;
3058 location_t loc = c_parser_peek_token (parser)->location;
3059 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3060 c_parser_consume_token (parser);
3061 if (!flag_isoc11)
3063 if (flag_isoc99)
3064 pedwarn (loc, OPT_Wpedantic,
3065 "ISO C99 does not support %<_Alignas%>");
3066 else
3067 pedwarn (loc, OPT_Wpedantic,
3068 "ISO C90 does not support %<_Alignas%>");
3070 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3071 return ret;
3072 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3074 struct c_type_name *type = c_parser_type_name (parser);
3075 if (type != NULL)
3076 ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3077 false, true, 1);
3079 else
3080 ret = c_parser_expr_no_commas (parser, NULL).value;
3081 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3082 return ret;
3085 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3086 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3087 be redeclared; otherwise it may not. KIND indicates which kind of
3088 declarator is wanted. Returns a valid declarator except in the
3089 case of a syntax error in which case NULL is returned. *SEEN_ID is
3090 set to true if an identifier being declared is seen; this is used
3091 to diagnose bad forms of abstract array declarators and to
3092 determine whether an identifier list is syntactically permitted.
3094 declarator:
3095 pointer[opt] direct-declarator
3097 direct-declarator:
3098 identifier
3099 ( attributes[opt] declarator )
3100 direct-declarator array-declarator
3101 direct-declarator ( parameter-type-list )
3102 direct-declarator ( identifier-list[opt] )
3104 pointer:
3105 * type-qualifier-list[opt]
3106 * type-qualifier-list[opt] pointer
3108 type-qualifier-list:
3109 type-qualifier
3110 attributes
3111 type-qualifier-list type-qualifier
3112 type-qualifier-list attributes
3114 array-declarator:
3115 [ type-qualifier-list[opt] assignment-expression[opt] ]
3116 [ static type-qualifier-list[opt] assignment-expression ]
3117 [ type-qualifier-list static assignment-expression ]
3118 [ type-qualifier-list[opt] * ]
3120 parameter-type-list:
3121 parameter-list
3122 parameter-list , ...
3124 parameter-list:
3125 parameter-declaration
3126 parameter-list , parameter-declaration
3128 parameter-declaration:
3129 declaration-specifiers declarator attributes[opt]
3130 declaration-specifiers abstract-declarator[opt] attributes[opt]
3132 identifier-list:
3133 identifier
3134 identifier-list , identifier
3136 abstract-declarator:
3137 pointer
3138 pointer[opt] direct-abstract-declarator
3140 direct-abstract-declarator:
3141 ( attributes[opt] abstract-declarator )
3142 direct-abstract-declarator[opt] array-declarator
3143 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3145 GNU extensions:
3147 direct-declarator:
3148 direct-declarator ( parameter-forward-declarations
3149 parameter-type-list[opt] )
3151 direct-abstract-declarator:
3152 direct-abstract-declarator[opt] ( parameter-forward-declarations
3153 parameter-type-list[opt] )
3155 parameter-forward-declarations:
3156 parameter-list ;
3157 parameter-forward-declarations parameter-list ;
3159 The uses of attributes shown above are GNU extensions.
3161 Some forms of array declarator are not included in C99 in the
3162 syntax for abstract declarators; these are disallowed elsewhere.
3163 This may be a defect (DR#289).
3165 This function also accepts an omitted abstract declarator as being
3166 an abstract declarator, although not part of the formal syntax. */
3168 static struct c_declarator *
3169 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3170 bool *seen_id)
3172 /* Parse any initial pointer part. */
3173 if (c_parser_next_token_is (parser, CPP_MULT))
3175 struct c_declspecs *quals_attrs = build_null_declspecs ();
3176 struct c_declarator *inner;
3177 c_parser_consume_token (parser);
3178 c_parser_declspecs (parser, quals_attrs, false, false, true,
3179 false, false, cla_prefer_id);
3180 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3181 if (inner == NULL)
3182 return NULL;
3183 else
3184 return make_pointer_declarator (quals_attrs, inner);
3186 /* Now we have a direct declarator, direct abstract declarator or
3187 nothing (which counts as a direct abstract declarator here). */
3188 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3191 /* Parse a direct declarator or direct abstract declarator; arguments
3192 as c_parser_declarator. */
3194 static struct c_declarator *
3195 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3196 bool *seen_id)
3198 /* The direct declarator must start with an identifier (possibly
3199 omitted) or a parenthesized declarator (possibly abstract). In
3200 an ordinary declarator, initial parentheses must start a
3201 parenthesized declarator. In an abstract declarator or parameter
3202 declarator, they could start a parenthesized declarator or a
3203 parameter list. To tell which, the open parenthesis and any
3204 following attributes must be read. If a declaration specifier
3205 follows, then it is a parameter list; if the specifier is a
3206 typedef name, there might be an ambiguity about redeclaring it,
3207 which is resolved in the direction of treating it as a typedef
3208 name. If a close parenthesis follows, it is also an empty
3209 parameter list, as the syntax does not permit empty abstract
3210 declarators. Otherwise, it is a parenthesized declarator (in
3211 which case the analysis may be repeated inside it, recursively).
3213 ??? There is an ambiguity in a parameter declaration "int
3214 (__attribute__((foo)) x)", where x is not a typedef name: it
3215 could be an abstract declarator for a function, or declare x with
3216 parentheses. The proper resolution of this ambiguity needs
3217 documenting. At present we follow an accident of the old
3218 parser's implementation, whereby the first parameter must have
3219 some declaration specifiers other than just attributes. Thus as
3220 a parameter declaration it is treated as a parenthesized
3221 parameter named x, and as an abstract declarator it is
3222 rejected.
3224 ??? Also following the old parser, attributes inside an empty
3225 parameter list are ignored, making it a list not yielding a
3226 prototype, rather than giving an error or making it have one
3227 parameter with implicit type int.
3229 ??? Also following the old parser, typedef names may be
3230 redeclared in declarators, but not Objective-C class names. */
3232 if (kind != C_DTR_ABSTRACT
3233 && c_parser_next_token_is (parser, CPP_NAME)
3234 && ((type_seen_p
3235 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3236 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3237 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3239 struct c_declarator *inner
3240 = build_id_declarator (c_parser_peek_token (parser)->value);
3241 *seen_id = true;
3242 inner->id_loc = c_parser_peek_token (parser)->location;
3243 c_parser_consume_token (parser);
3244 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3247 if (kind != C_DTR_NORMAL
3248 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3250 struct c_declarator *inner = build_id_declarator (NULL_TREE);
3251 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3254 /* Either we are at the end of an abstract declarator, or we have
3255 parentheses. */
3257 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3259 tree attrs;
3260 struct c_declarator *inner;
3261 c_parser_consume_token (parser);
3262 attrs = c_parser_attributes (parser);
3263 if (kind != C_DTR_NORMAL
3264 && (c_parser_next_token_starts_declspecs (parser)
3265 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3267 struct c_arg_info *args
3268 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3269 attrs);
3270 if (args == NULL)
3271 return NULL;
3272 else
3274 inner
3275 = build_function_declarator (args,
3276 build_id_declarator (NULL_TREE));
3277 return c_parser_direct_declarator_inner (parser, *seen_id,
3278 inner);
3281 /* A parenthesized declarator. */
3282 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3283 if (inner != NULL && attrs != NULL)
3284 inner = build_attrs_declarator (attrs, inner);
3285 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3287 c_parser_consume_token (parser);
3288 if (inner == NULL)
3289 return NULL;
3290 else
3291 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3293 else
3295 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3296 "expected %<)%>");
3297 return NULL;
3300 else
3302 if (kind == C_DTR_NORMAL)
3304 c_parser_error (parser, "expected identifier or %<(%>");
3305 return NULL;
3307 else
3308 return build_id_declarator (NULL_TREE);
3312 /* Parse part of a direct declarator or direct abstract declarator,
3313 given that some (in INNER) has already been parsed; ID_PRESENT is
3314 true if an identifier is present, false for an abstract
3315 declarator. */
3317 static struct c_declarator *
3318 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3319 struct c_declarator *inner)
3321 /* Parse a sequence of array declarators and parameter lists. */
3322 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3324 location_t brace_loc = c_parser_peek_token (parser)->location;
3325 struct c_declarator *declarator;
3326 struct c_declspecs *quals_attrs = build_null_declspecs ();
3327 bool static_seen;
3328 bool star_seen;
3329 struct c_expr dimen;
3330 dimen.value = NULL_TREE;
3331 dimen.original_code = ERROR_MARK;
3332 dimen.original_type = NULL_TREE;
3333 c_parser_consume_token (parser);
3334 c_parser_declspecs (parser, quals_attrs, false, false, true,
3335 false, false, cla_prefer_id);
3336 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3337 if (static_seen)
3338 c_parser_consume_token (parser);
3339 if (static_seen && !quals_attrs->declspecs_seen_p)
3340 c_parser_declspecs (parser, quals_attrs, false, false, true,
3341 false, false, cla_prefer_id);
3342 if (!quals_attrs->declspecs_seen_p)
3343 quals_attrs = NULL;
3344 /* If "static" is present, there must be an array dimension.
3345 Otherwise, there may be a dimension, "*", or no
3346 dimension. */
3347 if (static_seen)
3349 star_seen = false;
3350 dimen = c_parser_expr_no_commas (parser, NULL);
3352 else
3354 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3356 dimen.value = NULL_TREE;
3357 star_seen = false;
3359 else if (flag_cilkplus
3360 && c_parser_next_token_is (parser, CPP_COLON))
3362 dimen.value = error_mark_node;
3363 star_seen = false;
3364 error_at (c_parser_peek_token (parser)->location,
3365 "array notations cannot be used in declaration");
3366 c_parser_consume_token (parser);
3368 else if (c_parser_next_token_is (parser, CPP_MULT))
3370 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3372 dimen.value = NULL_TREE;
3373 star_seen = true;
3374 c_parser_consume_token (parser);
3376 else
3378 star_seen = false;
3379 dimen = c_parser_expr_no_commas (parser, NULL);
3382 else
3384 star_seen = false;
3385 dimen = c_parser_expr_no_commas (parser, NULL);
3388 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3389 c_parser_consume_token (parser);
3390 else if (flag_cilkplus
3391 && c_parser_next_token_is (parser, CPP_COLON))
3393 error_at (c_parser_peek_token (parser)->location,
3394 "array notations cannot be used in declaration");
3395 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
3396 return NULL;
3398 else
3400 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3401 "expected %<]%>");
3402 return NULL;
3404 if (dimen.value)
3405 dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3406 declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3407 static_seen, star_seen);
3408 if (declarator == NULL)
3409 return NULL;
3410 inner = set_array_declarator_inner (declarator, inner);
3411 return c_parser_direct_declarator_inner (parser, id_present, inner);
3413 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3415 tree attrs;
3416 struct c_arg_info *args;
3417 c_parser_consume_token (parser);
3418 attrs = c_parser_attributes (parser);
3419 args = c_parser_parms_declarator (parser, id_present, attrs);
3420 if (args == NULL)
3421 return NULL;
3422 else
3424 inner = build_function_declarator (args, inner);
3425 return c_parser_direct_declarator_inner (parser, id_present, inner);
3428 return inner;
3431 /* Parse a parameter list or identifier list, including the closing
3432 parenthesis but not the opening one. ATTRS are the attributes at
3433 the start of the list. ID_LIST_OK is true if an identifier list is
3434 acceptable; such a list must not have attributes at the start. */
3436 static struct c_arg_info *
3437 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3439 push_scope ();
3440 declare_parm_level ();
3441 /* If the list starts with an identifier, it is an identifier list.
3442 Otherwise, it is either a prototype list or an empty list. */
3443 if (id_list_ok
3444 && !attrs
3445 && c_parser_next_token_is (parser, CPP_NAME)
3446 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3448 /* Look ahead to detect typos in type names. */
3449 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3450 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3451 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3452 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3454 tree list = NULL_TREE, *nextp = &list;
3455 while (c_parser_next_token_is (parser, CPP_NAME)
3456 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3458 *nextp = build_tree_list (NULL_TREE,
3459 c_parser_peek_token (parser)->value);
3460 nextp = & TREE_CHAIN (*nextp);
3461 c_parser_consume_token (parser);
3462 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3463 break;
3464 c_parser_consume_token (parser);
3465 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3467 c_parser_error (parser, "expected identifier");
3468 break;
3471 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3473 struct c_arg_info *ret = build_arg_info ();
3474 ret->types = list;
3475 c_parser_consume_token (parser);
3476 pop_scope ();
3477 return ret;
3479 else
3481 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3482 "expected %<)%>");
3483 pop_scope ();
3484 return NULL;
3487 else
3489 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3490 NULL);
3491 pop_scope ();
3492 return ret;
3496 /* Parse a parameter list (possibly empty), including the closing
3497 parenthesis but not the opening one. ATTRS are the attributes at
3498 the start of the list. EXPR is NULL or an expression that needs to
3499 be evaluated for the side effects of array size expressions in the
3500 parameters. */
3502 static struct c_arg_info *
3503 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3505 bool bad_parm = false;
3507 /* ??? Following the old parser, forward parameter declarations may
3508 use abstract declarators, and if no real parameter declarations
3509 follow the forward declarations then this is not diagnosed. Also
3510 note as above that attributes are ignored as the only contents of
3511 the parentheses, or as the only contents after forward
3512 declarations. */
3513 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3515 struct c_arg_info *ret = build_arg_info ();
3516 c_parser_consume_token (parser);
3517 return ret;
3519 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3521 struct c_arg_info *ret = build_arg_info ();
3523 if (flag_allow_parameterless_variadic_functions)
3525 /* F (...) is allowed. */
3526 ret->types = NULL_TREE;
3528 else
3530 /* Suppress -Wold-style-definition for this case. */
3531 ret->types = error_mark_node;
3532 error_at (c_parser_peek_token (parser)->location,
3533 "ISO C requires a named argument before %<...%>");
3535 c_parser_consume_token (parser);
3536 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3538 c_parser_consume_token (parser);
3539 return ret;
3541 else
3543 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3544 "expected %<)%>");
3545 return NULL;
3548 /* Nonempty list of parameters, either terminated with semicolon
3549 (forward declarations; recurse) or with close parenthesis (normal
3550 function) or with ", ... )" (variadic function). */
3551 while (true)
3553 /* Parse a parameter. */
3554 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3555 attrs = NULL_TREE;
3556 if (parm == NULL)
3557 bad_parm = true;
3558 else
3559 push_parm_decl (parm, &expr);
3560 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3562 tree new_attrs;
3563 c_parser_consume_token (parser);
3564 mark_forward_parm_decls ();
3565 new_attrs = c_parser_attributes (parser);
3566 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3568 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3570 c_parser_consume_token (parser);
3571 if (bad_parm)
3572 return NULL;
3573 else
3574 return get_parm_info (false, expr);
3576 if (!c_parser_require (parser, CPP_COMMA,
3577 "expected %<;%>, %<,%> or %<)%>"))
3579 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3580 return NULL;
3582 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3584 c_parser_consume_token (parser);
3585 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3587 c_parser_consume_token (parser);
3588 if (bad_parm)
3589 return NULL;
3590 else
3591 return get_parm_info (true, expr);
3593 else
3595 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3596 "expected %<)%>");
3597 return NULL;
3603 /* Parse a parameter declaration. ATTRS are the attributes at the
3604 start of the declaration if it is the first parameter. */
3606 static struct c_parm *
3607 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3609 struct c_declspecs *specs;
3610 struct c_declarator *declarator;
3611 tree prefix_attrs;
3612 tree postfix_attrs = NULL_TREE;
3613 bool dummy = false;
3615 /* Accept #pragmas between parameter declarations. */
3616 while (c_parser_next_token_is (parser, CPP_PRAGMA))
3617 c_parser_pragma (parser, pragma_param);
3619 if (!c_parser_next_token_starts_declspecs (parser))
3621 c_token *token = c_parser_peek_token (parser);
3622 if (parser->error)
3623 return NULL;
3624 c_parser_set_source_position_from_token (token);
3625 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3627 error_at (token->location, "unknown type name %qE", token->value);
3628 parser->error = true;
3630 /* ??? In some Objective-C cases '...' isn't applicable so there
3631 should be a different message. */
3632 else
3633 c_parser_error (parser,
3634 "expected declaration specifiers or %<...%>");
3635 c_parser_skip_to_end_of_parameter (parser);
3636 return NULL;
3638 specs = build_null_declspecs ();
3639 if (attrs)
3641 declspecs_add_attrs (input_location, specs, attrs);
3642 attrs = NULL_TREE;
3644 c_parser_declspecs (parser, specs, true, true, true, true, false,
3645 cla_nonabstract_decl);
3646 finish_declspecs (specs);
3647 pending_xref_error ();
3648 prefix_attrs = specs->attrs;
3649 specs->attrs = NULL_TREE;
3650 declarator = c_parser_declarator (parser,
3651 specs->typespec_kind != ctsk_none,
3652 C_DTR_PARM, &dummy);
3653 if (declarator == NULL)
3655 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3656 return NULL;
3658 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3659 postfix_attrs = c_parser_attributes (parser);
3660 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3661 declarator);
3664 /* Parse a string literal in an asm expression. It should not be
3665 translated, and wide string literals are an error although
3666 permitted by the syntax. This is a GNU extension.
3668 asm-string-literal:
3669 string-literal
3671 ??? At present, following the old parser, the caller needs to have
3672 set lex_untranslated_string to 1. It would be better to follow the
3673 C++ parser rather than using this kludge. */
3675 static tree
3676 c_parser_asm_string_literal (c_parser *parser)
3678 tree str;
3679 int save_flag = warn_overlength_strings;
3680 warn_overlength_strings = 0;
3681 if (c_parser_next_token_is (parser, CPP_STRING))
3683 str = c_parser_peek_token (parser)->value;
3684 c_parser_consume_token (parser);
3686 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3688 error_at (c_parser_peek_token (parser)->location,
3689 "wide string literal in %<asm%>");
3690 str = build_string (1, "");
3691 c_parser_consume_token (parser);
3693 else
3695 c_parser_error (parser, "expected string literal");
3696 str = NULL_TREE;
3698 warn_overlength_strings = save_flag;
3699 return str;
3702 /* Parse a simple asm expression. This is used in restricted
3703 contexts, where a full expression with inputs and outputs does not
3704 make sense. This is a GNU extension.
3706 simple-asm-expr:
3707 asm ( asm-string-literal )
3710 static tree
3711 c_parser_simple_asm_expr (c_parser *parser)
3713 tree str;
3714 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3715 /* ??? Follow the C++ parser rather than using the
3716 lex_untranslated_string kludge. */
3717 parser->lex_untranslated_string = true;
3718 c_parser_consume_token (parser);
3719 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3721 parser->lex_untranslated_string = false;
3722 return NULL_TREE;
3724 str = c_parser_asm_string_literal (parser);
3725 parser->lex_untranslated_string = false;
3726 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3728 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3729 return NULL_TREE;
3731 return str;
3734 static tree
3735 c_parser_attribute_any_word (c_parser *parser)
3737 tree attr_name = NULL_TREE;
3739 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3741 /* ??? See comment above about what keywords are accepted here. */
3742 bool ok;
3743 switch (c_parser_peek_token (parser)->keyword)
3745 case RID_STATIC:
3746 case RID_UNSIGNED:
3747 case RID_LONG:
3748 case RID_INT128:
3749 case RID_CONST:
3750 case RID_EXTERN:
3751 case RID_REGISTER:
3752 case RID_TYPEDEF:
3753 case RID_SHORT:
3754 case RID_INLINE:
3755 case RID_NORETURN:
3756 case RID_VOLATILE:
3757 case RID_SIGNED:
3758 case RID_AUTO:
3759 case RID_RESTRICT:
3760 case RID_COMPLEX:
3761 case RID_THREAD:
3762 case RID_INT:
3763 case RID_CHAR:
3764 case RID_FLOAT:
3765 case RID_DOUBLE:
3766 case RID_VOID:
3767 case RID_DFLOAT32:
3768 case RID_DFLOAT64:
3769 case RID_DFLOAT128:
3770 case RID_BOOL:
3771 case RID_FRACT:
3772 case RID_ACCUM:
3773 case RID_SAT:
3774 case RID_TRANSACTION_ATOMIC:
3775 case RID_TRANSACTION_CANCEL:
3776 case RID_ATOMIC:
3777 case RID_AUTO_TYPE:
3778 ok = true;
3779 break;
3780 default:
3781 ok = false;
3782 break;
3784 if (!ok)
3785 return NULL_TREE;
3787 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3788 attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3790 else if (c_parser_next_token_is (parser, CPP_NAME))
3791 attr_name = c_parser_peek_token (parser)->value;
3793 return attr_name;
3796 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3797 "__vector" or "__vector__." */
3799 static inline bool
3800 is_cilkplus_vector_p (tree name)
3802 if (flag_cilkplus && is_attribute_p ("vector", name))
3803 return true;
3804 return false;
3807 #define CILK_SIMD_FN_CLAUSE_MASK \
3808 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3809 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3810 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3811 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3812 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3814 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3815 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3816 pushed into the token list.
3817 Syntax:
3818 vector
3819 vector (<vector attributes>). */
3821 static void
3822 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token)
3824 gcc_assert (is_cilkplus_vector_p (vec_token.value));
3826 int paren_scope = 0;
3827 vec_safe_push (parser->cilk_simd_fn_tokens, vec_token);
3828 /* Consume the "vector" token. */
3829 c_parser_consume_token (parser);
3831 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3833 c_parser_consume_token (parser);
3834 paren_scope++;
3836 while (paren_scope > 0)
3838 c_token *token = c_parser_peek_token (parser);
3839 if (token->type == CPP_OPEN_PAREN)
3840 paren_scope++;
3841 else if (token->type == CPP_CLOSE_PAREN)
3842 paren_scope--;
3843 /* Do not push the last ')' since we are not pushing the '('. */
3844 if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0))
3845 vec_safe_push (parser->cilk_simd_fn_tokens, *token);
3846 c_parser_consume_token (parser);
3849 /* Since we are converting an attribute to a pragma, we need to end the
3850 attribute with PRAGMA_EOL. */
3851 c_token eol_token;
3852 memset (&eol_token, 0, sizeof (eol_token));
3853 eol_token.type = CPP_PRAGMA_EOL;
3854 vec_safe_push (parser->cilk_simd_fn_tokens, eol_token);
3857 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3859 static void
3860 c_finish_cilk_simd_fn_tokens (c_parser *parser)
3862 c_token last_token = parser->cilk_simd_fn_tokens->last ();
3864 /* c_parser_attributes is called in several places, so if these EOF
3865 tokens are already inserted, then don't do them again. */
3866 if (last_token.type == CPP_EOF)
3867 return;
3869 /* Two CPP_EOF token are added as a safety net since the normal C
3870 front-end has two token look-ahead. */
3871 c_token eof_token;
3872 eof_token.type = CPP_EOF;
3873 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3874 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3877 /* Parse (possibly empty) attributes. This is a GNU extension.
3879 attributes:
3880 empty
3881 attributes attribute
3883 attribute:
3884 __attribute__ ( ( attribute-list ) )
3886 attribute-list:
3887 attrib
3888 attribute_list , attrib
3890 attrib:
3891 empty
3892 any-word
3893 any-word ( identifier )
3894 any-word ( identifier , nonempty-expr-list )
3895 any-word ( expr-list )
3897 where the "identifier" must not be declared as a type, and
3898 "any-word" may be any identifier (including one declared as a
3899 type), a reserved word storage class specifier, type specifier or
3900 type qualifier. ??? This still leaves out most reserved keywords
3901 (following the old parser), shouldn't we include them, and why not
3902 allow identifiers declared as types to start the arguments? */
3904 static tree
3905 c_parser_attributes (c_parser *parser)
3907 tree attrs = NULL_TREE;
3908 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3910 /* ??? Follow the C++ parser rather than using the
3911 lex_untranslated_string kludge. */
3912 parser->lex_untranslated_string = true;
3913 c_parser_consume_token (parser);
3914 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3916 parser->lex_untranslated_string = false;
3917 return attrs;
3919 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3921 parser->lex_untranslated_string = false;
3922 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3923 return attrs;
3925 /* Parse the attribute list. */
3926 while (c_parser_next_token_is (parser, CPP_COMMA)
3927 || c_parser_next_token_is (parser, CPP_NAME)
3928 || c_parser_next_token_is (parser, CPP_KEYWORD))
3930 tree attr, attr_name, attr_args;
3931 vec<tree, va_gc> *expr_list;
3932 if (c_parser_next_token_is (parser, CPP_COMMA))
3934 c_parser_consume_token (parser);
3935 continue;
3938 attr_name = c_parser_attribute_any_word (parser);
3939 if (attr_name == NULL)
3940 break;
3941 if (is_cilkplus_vector_p (attr_name))
3943 c_token *v_token = c_parser_peek_token (parser);
3944 c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
3945 continue;
3947 c_parser_consume_token (parser);
3948 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3950 attr = build_tree_list (attr_name, NULL_TREE);
3951 attrs = chainon (attrs, attr);
3952 continue;
3954 c_parser_consume_token (parser);
3955 /* Parse the attribute contents. If they start with an
3956 identifier which is followed by a comma or close
3957 parenthesis, then the arguments start with that
3958 identifier; otherwise they are an expression list.
3959 In objective-c the identifier may be a classname. */
3960 if (c_parser_next_token_is (parser, CPP_NAME)
3961 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3962 || (c_dialect_objc ()
3963 && c_parser_peek_token (parser)->id_kind
3964 == C_ID_CLASSNAME))
3965 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3966 || (c_parser_peek_2nd_token (parser)->type
3967 == CPP_CLOSE_PAREN))
3968 && (attribute_takes_identifier_p (attr_name)
3969 || (c_dialect_objc ()
3970 && c_parser_peek_token (parser)->id_kind
3971 == C_ID_CLASSNAME)))
3973 tree arg1 = c_parser_peek_token (parser)->value;
3974 c_parser_consume_token (parser);
3975 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3976 attr_args = build_tree_list (NULL_TREE, arg1);
3977 else
3979 tree tree_list;
3980 c_parser_consume_token (parser);
3981 expr_list = c_parser_expr_list (parser, false, true,
3982 NULL, NULL, NULL, NULL);
3983 tree_list = build_tree_list_vec (expr_list);
3984 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3985 release_tree_vector (expr_list);
3988 else
3990 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3991 attr_args = NULL_TREE;
3992 else
3994 expr_list = c_parser_expr_list (parser, false, true,
3995 NULL, NULL, NULL, NULL);
3996 attr_args = build_tree_list_vec (expr_list);
3997 release_tree_vector (expr_list);
4000 attr = build_tree_list (attr_name, attr_args);
4001 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4002 c_parser_consume_token (parser);
4003 else
4005 parser->lex_untranslated_string = false;
4006 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4007 "expected %<)%>");
4008 return attrs;
4010 attrs = chainon (attrs, attr);
4012 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4013 c_parser_consume_token (parser);
4014 else
4016 parser->lex_untranslated_string = false;
4017 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4018 "expected %<)%>");
4019 return attrs;
4021 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4022 c_parser_consume_token (parser);
4023 else
4025 parser->lex_untranslated_string = false;
4026 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4027 "expected %<)%>");
4028 return attrs;
4030 parser->lex_untranslated_string = false;
4033 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
4034 c_finish_cilk_simd_fn_tokens (parser);
4035 return attrs;
4038 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4040 type-name:
4041 specifier-qualifier-list abstract-declarator[opt]
4044 static struct c_type_name *
4045 c_parser_type_name (c_parser *parser)
4047 struct c_declspecs *specs = build_null_declspecs ();
4048 struct c_declarator *declarator;
4049 struct c_type_name *ret;
4050 bool dummy = false;
4051 c_parser_declspecs (parser, specs, false, true, true, false, false,
4052 cla_prefer_type);
4053 if (!specs->declspecs_seen_p)
4055 c_parser_error (parser, "expected specifier-qualifier-list");
4056 return NULL;
4058 if (specs->type != error_mark_node)
4060 pending_xref_error ();
4061 finish_declspecs (specs);
4063 declarator = c_parser_declarator (parser,
4064 specs->typespec_kind != ctsk_none,
4065 C_DTR_ABSTRACT, &dummy);
4066 if (declarator == NULL)
4067 return NULL;
4068 ret = XOBNEW (&parser_obstack, struct c_type_name);
4069 ret->specs = specs;
4070 ret->declarator = declarator;
4071 return ret;
4074 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4076 initializer:
4077 assignment-expression
4078 { initializer-list }
4079 { initializer-list , }
4081 initializer-list:
4082 designation[opt] initializer
4083 initializer-list , designation[opt] initializer
4085 designation:
4086 designator-list =
4088 designator-list:
4089 designator
4090 designator-list designator
4092 designator:
4093 array-designator
4094 . identifier
4096 array-designator:
4097 [ constant-expression ]
4099 GNU extensions:
4101 initializer:
4104 designation:
4105 array-designator
4106 identifier :
4108 array-designator:
4109 [ constant-expression ... constant-expression ]
4111 Any expression without commas is accepted in the syntax for the
4112 constant-expressions, with non-constant expressions rejected later.
4114 This function is only used for top-level initializers; for nested
4115 ones, see c_parser_initval. */
4117 static struct c_expr
4118 c_parser_initializer (c_parser *parser)
4120 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4121 return c_parser_braced_init (parser, NULL_TREE, false);
4122 else
4124 struct c_expr ret;
4125 location_t loc = c_parser_peek_token (parser)->location;
4126 ret = c_parser_expr_no_commas (parser, NULL);
4127 if (TREE_CODE (ret.value) != STRING_CST
4128 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4129 ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4130 return ret;
4134 /* Parse a braced initializer list. TYPE is the type specified for a
4135 compound literal, and NULL_TREE for other initializers and for
4136 nested braced lists. NESTED_P is true for nested braced lists,
4137 false for the list of a compound literal or the list that is the
4138 top-level initializer in a declaration. */
4140 static struct c_expr
4141 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
4143 struct c_expr ret;
4144 struct obstack braced_init_obstack;
4145 location_t brace_loc = c_parser_peek_token (parser)->location;
4146 gcc_obstack_init (&braced_init_obstack);
4147 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4148 c_parser_consume_token (parser);
4149 if (nested_p)
4150 push_init_level (brace_loc, 0, &braced_init_obstack);
4151 else
4152 really_start_incremental_init (type);
4153 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4155 pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4157 else
4159 /* Parse a non-empty initializer list, possibly with a trailing
4160 comma. */
4161 while (true)
4163 c_parser_initelt (parser, &braced_init_obstack);
4164 if (parser->error)
4165 break;
4166 if (c_parser_next_token_is (parser, CPP_COMMA))
4167 c_parser_consume_token (parser);
4168 else
4169 break;
4170 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4171 break;
4174 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4176 ret.value = error_mark_node;
4177 ret.original_code = ERROR_MARK;
4178 ret.original_type = NULL;
4179 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
4180 pop_init_level (brace_loc, 0, &braced_init_obstack);
4181 obstack_free (&braced_init_obstack, NULL);
4182 return ret;
4184 c_parser_consume_token (parser);
4185 ret = pop_init_level (brace_loc, 0, &braced_init_obstack);
4186 obstack_free (&braced_init_obstack, NULL);
4187 return ret;
4190 /* Parse a nested initializer, including designators. */
4192 static void
4193 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4195 /* Parse any designator or designator list. A single array
4196 designator may have the subsequent "=" omitted in GNU C, but a
4197 longer list or a structure member designator may not. */
4198 if (c_parser_next_token_is (parser, CPP_NAME)
4199 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4201 /* Old-style structure member designator. */
4202 set_init_label (c_parser_peek_token (parser)->location,
4203 c_parser_peek_token (parser)->value,
4204 braced_init_obstack);
4205 /* Use the colon as the error location. */
4206 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4207 "obsolete use of designated initializer with %<:%>");
4208 c_parser_consume_token (parser);
4209 c_parser_consume_token (parser);
4211 else
4213 /* des_seen is 0 if there have been no designators, 1 if there
4214 has been a single array designator and 2 otherwise. */
4215 int des_seen = 0;
4216 /* Location of a designator. */
4217 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4218 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4219 || c_parser_next_token_is (parser, CPP_DOT))
4221 int des_prev = des_seen;
4222 if (!des_seen)
4223 des_loc = c_parser_peek_token (parser)->location;
4224 if (des_seen < 2)
4225 des_seen++;
4226 if (c_parser_next_token_is (parser, CPP_DOT))
4228 des_seen = 2;
4229 c_parser_consume_token (parser);
4230 if (c_parser_next_token_is (parser, CPP_NAME))
4232 set_init_label (des_loc, c_parser_peek_token (parser)->value,
4233 braced_init_obstack);
4234 c_parser_consume_token (parser);
4236 else
4238 struct c_expr init;
4239 init.value = error_mark_node;
4240 init.original_code = ERROR_MARK;
4241 init.original_type = NULL;
4242 c_parser_error (parser, "expected identifier");
4243 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4244 process_init_element (input_location, init, false,
4245 braced_init_obstack);
4246 return;
4249 else
4251 tree first, second;
4252 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4253 location_t array_index_loc = UNKNOWN_LOCATION;
4254 /* ??? Following the old parser, [ objc-receiver
4255 objc-message-args ] is accepted as an initializer,
4256 being distinguished from a designator by what follows
4257 the first assignment expression inside the square
4258 brackets, but after a first array designator a
4259 subsequent square bracket is for Objective-C taken to
4260 start an expression, using the obsolete form of
4261 designated initializer without '=', rather than
4262 possibly being a second level of designation: in LALR
4263 terms, the '[' is shifted rather than reducing
4264 designator to designator-list. */
4265 if (des_prev == 1 && c_dialect_objc ())
4267 des_seen = des_prev;
4268 break;
4270 if (des_prev == 0 && c_dialect_objc ())
4272 /* This might be an array designator or an
4273 Objective-C message expression. If the former,
4274 continue parsing here; if the latter, parse the
4275 remainder of the initializer given the starting
4276 primary-expression. ??? It might make sense to
4277 distinguish when des_prev == 1 as well; see
4278 previous comment. */
4279 tree rec, args;
4280 struct c_expr mexpr;
4281 c_parser_consume_token (parser);
4282 if (c_parser_peek_token (parser)->type == CPP_NAME
4283 && ((c_parser_peek_token (parser)->id_kind
4284 == C_ID_TYPENAME)
4285 || (c_parser_peek_token (parser)->id_kind
4286 == C_ID_CLASSNAME)))
4288 /* Type name receiver. */
4289 tree id = c_parser_peek_token (parser)->value;
4290 c_parser_consume_token (parser);
4291 rec = objc_get_class_reference (id);
4292 goto parse_message_args;
4294 first = c_parser_expr_no_commas (parser, NULL).value;
4295 mark_exp_read (first);
4296 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4297 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4298 goto array_desig_after_first;
4299 /* Expression receiver. So far only one part
4300 without commas has been parsed; there might be
4301 more of the expression. */
4302 rec = first;
4303 while (c_parser_next_token_is (parser, CPP_COMMA))
4305 struct c_expr next;
4306 location_t comma_loc, exp_loc;
4307 comma_loc = c_parser_peek_token (parser)->location;
4308 c_parser_consume_token (parser);
4309 exp_loc = c_parser_peek_token (parser)->location;
4310 next = c_parser_expr_no_commas (parser, NULL);
4311 next = convert_lvalue_to_rvalue (exp_loc, next,
4312 true, true);
4313 rec = build_compound_expr (comma_loc, rec, next.value);
4315 parse_message_args:
4316 /* Now parse the objc-message-args. */
4317 args = c_parser_objc_message_args (parser);
4318 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4319 "expected %<]%>");
4320 mexpr.value
4321 = objc_build_message_expr (rec, args);
4322 mexpr.original_code = ERROR_MARK;
4323 mexpr.original_type = NULL;
4324 /* Now parse and process the remainder of the
4325 initializer, starting with this message
4326 expression as a primary-expression. */
4327 c_parser_initval (parser, &mexpr, braced_init_obstack);
4328 return;
4330 c_parser_consume_token (parser);
4331 array_index_loc = c_parser_peek_token (parser)->location;
4332 first = c_parser_expr_no_commas (parser, NULL).value;
4333 mark_exp_read (first);
4334 array_desig_after_first:
4335 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4337 ellipsis_loc = c_parser_peek_token (parser)->location;
4338 c_parser_consume_token (parser);
4339 second = c_parser_expr_no_commas (parser, NULL).value;
4340 mark_exp_read (second);
4342 else
4343 second = NULL_TREE;
4344 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4346 c_parser_consume_token (parser);
4347 set_init_index (array_index_loc, first, second,
4348 braced_init_obstack);
4349 if (second)
4350 pedwarn (ellipsis_loc, OPT_Wpedantic,
4351 "ISO C forbids specifying range of elements to initialize");
4353 else
4354 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4355 "expected %<]%>");
4358 if (des_seen >= 1)
4360 if (c_parser_next_token_is (parser, CPP_EQ))
4362 if (!flag_isoc99)
4363 pedwarn (des_loc, OPT_Wpedantic,
4364 "ISO C90 forbids specifying subobject to initialize");
4365 c_parser_consume_token (parser);
4367 else
4369 if (des_seen == 1)
4370 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4371 "obsolete use of designated initializer without %<=%>");
4372 else
4374 struct c_expr init;
4375 init.value = error_mark_node;
4376 init.original_code = ERROR_MARK;
4377 init.original_type = NULL;
4378 c_parser_error (parser, "expected %<=%>");
4379 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4380 process_init_element (input_location, init, false,
4381 braced_init_obstack);
4382 return;
4387 c_parser_initval (parser, NULL, braced_init_obstack);
4390 /* Parse a nested initializer; as c_parser_initializer but parses
4391 initializers within braced lists, after any designators have been
4392 applied. If AFTER is not NULL then it is an Objective-C message
4393 expression which is the primary-expression starting the
4394 initializer. */
4396 static void
4397 c_parser_initval (c_parser *parser, struct c_expr *after,
4398 struct obstack * braced_init_obstack)
4400 struct c_expr init;
4401 gcc_assert (!after || c_dialect_objc ());
4402 location_t loc = c_parser_peek_token (parser)->location;
4404 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4405 init = c_parser_braced_init (parser, NULL_TREE, true);
4406 else
4408 init = c_parser_expr_no_commas (parser, after);
4409 if (init.value != NULL_TREE
4410 && TREE_CODE (init.value) != STRING_CST
4411 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4412 init = convert_lvalue_to_rvalue (loc, init, true, true);
4414 process_init_element (loc, init, false, braced_init_obstack);
4417 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4418 C99 6.8.2).
4420 compound-statement:
4421 { block-item-list[opt] }
4422 { label-declarations block-item-list }
4424 block-item-list:
4425 block-item
4426 block-item-list block-item
4428 block-item:
4429 nested-declaration
4430 statement
4432 nested-declaration:
4433 declaration
4435 GNU extensions:
4437 compound-statement:
4438 { label-declarations block-item-list }
4440 nested-declaration:
4441 __extension__ nested-declaration
4442 nested-function-definition
4444 label-declarations:
4445 label-declaration
4446 label-declarations label-declaration
4448 label-declaration:
4449 __label__ identifier-list ;
4451 Allowing the mixing of declarations and code is new in C99. The
4452 GNU syntax also permits (not shown above) labels at the end of
4453 compound statements, which yield an error. We don't allow labels
4454 on declarations; this might seem like a natural extension, but
4455 there would be a conflict between attributes on the label and
4456 prefix attributes on the declaration. ??? The syntax follows the
4457 old parser in requiring something after label declarations.
4458 Although they are erroneous if the labels declared aren't defined,
4459 is it useful for the syntax to be this way?
4461 OpenACC:
4463 block-item:
4464 openacc-directive
4466 openacc-directive:
4467 update-directive
4469 OpenMP:
4471 block-item:
4472 openmp-directive
4474 openmp-directive:
4475 barrier-directive
4476 flush-directive
4477 taskwait-directive
4478 taskyield-directive
4479 cancel-directive
4480 cancellation-point-directive */
4482 static tree
4483 c_parser_compound_statement (c_parser *parser)
4485 tree stmt;
4486 location_t brace_loc;
4487 brace_loc = c_parser_peek_token (parser)->location;
4488 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4490 /* Ensure a scope is entered and left anyway to avoid confusion
4491 if we have just prepared to enter a function body. */
4492 stmt = c_begin_compound_stmt (true);
4493 c_end_compound_stmt (brace_loc, stmt, true);
4494 return error_mark_node;
4496 stmt = c_begin_compound_stmt (true);
4497 c_parser_compound_statement_nostart (parser);
4499 /* If the compound stmt contains array notations, then we expand them. */
4500 if (flag_cilkplus && contains_array_notation_expr (stmt))
4501 stmt = expand_array_notation_exprs (stmt);
4502 return c_end_compound_stmt (brace_loc, stmt, true);
4505 /* Parse a compound statement except for the opening brace. This is
4506 used for parsing both compound statements and statement expressions
4507 (which follow different paths to handling the opening). */
4509 static void
4510 c_parser_compound_statement_nostart (c_parser *parser)
4512 bool last_stmt = false;
4513 bool last_label = false;
4514 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4515 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4516 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4518 c_parser_consume_token (parser);
4519 return;
4521 mark_valid_location_for_stdc_pragma (true);
4522 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4524 /* Read zero or more forward-declarations for labels that nested
4525 functions can jump to. */
4526 mark_valid_location_for_stdc_pragma (false);
4527 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4529 label_loc = c_parser_peek_token (parser)->location;
4530 c_parser_consume_token (parser);
4531 /* Any identifiers, including those declared as type names,
4532 are OK here. */
4533 while (true)
4535 tree label;
4536 if (c_parser_next_token_is_not (parser, CPP_NAME))
4538 c_parser_error (parser, "expected identifier");
4539 break;
4541 label
4542 = declare_label (c_parser_peek_token (parser)->value);
4543 C_DECLARED_LABEL_FLAG (label) = 1;
4544 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4545 c_parser_consume_token (parser);
4546 if (c_parser_next_token_is (parser, CPP_COMMA))
4547 c_parser_consume_token (parser);
4548 else
4549 break;
4551 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4553 pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4555 /* We must now have at least one statement, label or declaration. */
4556 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4558 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4559 c_parser_error (parser, "expected declaration or statement");
4560 c_parser_consume_token (parser);
4561 return;
4563 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4565 location_t loc = c_parser_peek_token (parser)->location;
4566 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4567 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4568 || (c_parser_next_token_is (parser, CPP_NAME)
4569 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4571 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4572 label_loc = c_parser_peek_2nd_token (parser)->location;
4573 else
4574 label_loc = c_parser_peek_token (parser)->location;
4575 last_label = true;
4576 last_stmt = false;
4577 mark_valid_location_for_stdc_pragma (false);
4578 c_parser_label (parser);
4580 else if (!last_label
4581 && c_parser_next_tokens_start_declaration (parser))
4583 last_label = false;
4584 mark_valid_location_for_stdc_pragma (false);
4585 c_parser_declaration_or_fndef (parser, true, true, true, true,
4586 true, NULL, vNULL);
4587 if (last_stmt)
4588 pedwarn_c90 (loc,
4589 (pedantic && !flag_isoc99)
4590 ? OPT_Wpedantic
4591 : OPT_Wdeclaration_after_statement,
4592 "ISO C90 forbids mixed declarations and code");
4593 last_stmt = false;
4595 else if (!last_label
4596 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4598 /* __extension__ can start a declaration, but is also an
4599 unary operator that can start an expression. Consume all
4600 but the last of a possible series of __extension__ to
4601 determine which. */
4602 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4603 && (c_parser_peek_2nd_token (parser)->keyword
4604 == RID_EXTENSION))
4605 c_parser_consume_token (parser);
4606 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4608 int ext;
4609 ext = disable_extension_diagnostics ();
4610 c_parser_consume_token (parser);
4611 last_label = false;
4612 mark_valid_location_for_stdc_pragma (false);
4613 c_parser_declaration_or_fndef (parser, true, true, true, true,
4614 true, NULL, vNULL);
4615 /* Following the old parser, __extension__ does not
4616 disable this diagnostic. */
4617 restore_extension_diagnostics (ext);
4618 if (last_stmt)
4619 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4620 ? OPT_Wpedantic
4621 : OPT_Wdeclaration_after_statement,
4622 "ISO C90 forbids mixed declarations and code");
4623 last_stmt = false;
4625 else
4626 goto statement;
4628 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4630 /* External pragmas, and some omp pragmas, are not associated
4631 with regular c code, and so are not to be considered statements
4632 syntactically. This ensures that the user doesn't put them
4633 places that would turn into syntax errors if the directive
4634 were ignored. */
4635 if (c_parser_pragma (parser, pragma_compound))
4636 last_label = false, last_stmt = true;
4638 else if (c_parser_next_token_is (parser, CPP_EOF))
4640 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4641 c_parser_error (parser, "expected declaration or statement");
4642 return;
4644 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4646 if (parser->in_if_block)
4648 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4649 error_at (loc, """expected %<}%> before %<else%>");
4650 return;
4652 else
4654 error_at (loc, "%<else%> without a previous %<if%>");
4655 c_parser_consume_token (parser);
4656 continue;
4659 else
4661 statement:
4662 last_label = false;
4663 last_stmt = true;
4664 mark_valid_location_for_stdc_pragma (false);
4665 c_parser_statement_after_labels (parser);
4668 parser->error = false;
4670 if (last_label)
4671 error_at (label_loc, "label at end of compound statement");
4672 c_parser_consume_token (parser);
4673 /* Restore the value we started with. */
4674 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4677 /* Parse a label (C90 6.6.1, C99 6.8.1).
4679 label:
4680 identifier : attributes[opt]
4681 case constant-expression :
4682 default :
4684 GNU extensions:
4686 label:
4687 case constant-expression ... constant-expression :
4689 The use of attributes on labels is a GNU extension. The syntax in
4690 GNU C accepts any expressions without commas, non-constant
4691 expressions being rejected later. */
4693 static void
4694 c_parser_label (c_parser *parser)
4696 location_t loc1 = c_parser_peek_token (parser)->location;
4697 tree label = NULL_TREE;
4698 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4700 tree exp1, exp2;
4701 c_parser_consume_token (parser);
4702 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4703 if (c_parser_next_token_is (parser, CPP_COLON))
4705 c_parser_consume_token (parser);
4706 label = do_case (loc1, exp1, NULL_TREE);
4708 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4710 c_parser_consume_token (parser);
4711 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4712 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4713 label = do_case (loc1, exp1, exp2);
4715 else
4716 c_parser_error (parser, "expected %<:%> or %<...%>");
4718 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4720 c_parser_consume_token (parser);
4721 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4722 label = do_case (loc1, NULL_TREE, NULL_TREE);
4724 else
4726 tree name = c_parser_peek_token (parser)->value;
4727 tree tlab;
4728 tree attrs;
4729 location_t loc2 = c_parser_peek_token (parser)->location;
4730 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4731 c_parser_consume_token (parser);
4732 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4733 c_parser_consume_token (parser);
4734 attrs = c_parser_attributes (parser);
4735 tlab = define_label (loc2, name);
4736 if (tlab)
4738 decl_attributes (&tlab, attrs, 0);
4739 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4742 if (label)
4744 if (c_parser_next_tokens_start_declaration (parser))
4746 error_at (c_parser_peek_token (parser)->location,
4747 "a label can only be part of a statement and "
4748 "a declaration is not a statement");
4749 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4750 /*static_assert_ok*/ true,
4751 /*empty_ok*/ true, /*nested*/ true,
4752 /*start_attr_ok*/ true, NULL,
4753 vNULL);
4758 /* Parse a statement (C90 6.6, C99 6.8).
4760 statement:
4761 labeled-statement
4762 compound-statement
4763 expression-statement
4764 selection-statement
4765 iteration-statement
4766 jump-statement
4768 labeled-statement:
4769 label statement
4771 expression-statement:
4772 expression[opt] ;
4774 selection-statement:
4775 if-statement
4776 switch-statement
4778 iteration-statement:
4779 while-statement
4780 do-statement
4781 for-statement
4783 jump-statement:
4784 goto identifier ;
4785 continue ;
4786 break ;
4787 return expression[opt] ;
4789 GNU extensions:
4791 statement:
4792 asm-statement
4794 jump-statement:
4795 goto * expression ;
4797 Objective-C:
4799 statement:
4800 objc-throw-statement
4801 objc-try-catch-statement
4802 objc-synchronized-statement
4804 objc-throw-statement:
4805 @throw expression ;
4806 @throw ;
4808 OpenACC:
4810 statement:
4811 openacc-construct
4813 openacc-construct:
4814 parallel-construct
4815 kernels-construct
4816 data-construct
4817 loop-construct
4819 parallel-construct:
4820 parallel-directive structured-block
4822 kernels-construct:
4823 kernels-directive structured-block
4825 data-construct:
4826 data-directive structured-block
4828 loop-construct:
4829 loop-directive structured-block
4831 OpenMP:
4833 statement:
4834 openmp-construct
4836 openmp-construct:
4837 parallel-construct
4838 for-construct
4839 simd-construct
4840 for-simd-construct
4841 sections-construct
4842 single-construct
4843 parallel-for-construct
4844 parallel-for-simd-construct
4845 parallel-sections-construct
4846 master-construct
4847 critical-construct
4848 atomic-construct
4849 ordered-construct
4851 parallel-construct:
4852 parallel-directive structured-block
4854 for-construct:
4855 for-directive iteration-statement
4857 simd-construct:
4858 simd-directive iteration-statements
4860 for-simd-construct:
4861 for-simd-directive iteration-statements
4863 sections-construct:
4864 sections-directive section-scope
4866 single-construct:
4867 single-directive structured-block
4869 parallel-for-construct:
4870 parallel-for-directive iteration-statement
4872 parallel-for-simd-construct:
4873 parallel-for-simd-directive iteration-statement
4875 parallel-sections-construct:
4876 parallel-sections-directive section-scope
4878 master-construct:
4879 master-directive structured-block
4881 critical-construct:
4882 critical-directive structured-block
4884 atomic-construct:
4885 atomic-directive expression-statement
4887 ordered-construct:
4888 ordered-directive structured-block
4890 Transactional Memory:
4892 statement:
4893 transaction-statement
4894 transaction-cancel-statement
4897 static void
4898 c_parser_statement (c_parser *parser)
4900 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4901 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4902 || (c_parser_next_token_is (parser, CPP_NAME)
4903 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4904 c_parser_label (parser);
4905 c_parser_statement_after_labels (parser);
4908 /* Parse a statement, other than a labeled statement. */
4910 static void
4911 c_parser_statement_after_labels (c_parser *parser)
4913 location_t loc = c_parser_peek_token (parser)->location;
4914 tree stmt = NULL_TREE;
4915 bool in_if_block = parser->in_if_block;
4916 parser->in_if_block = false;
4917 switch (c_parser_peek_token (parser)->type)
4919 case CPP_OPEN_BRACE:
4920 add_stmt (c_parser_compound_statement (parser));
4921 break;
4922 case CPP_KEYWORD:
4923 switch (c_parser_peek_token (parser)->keyword)
4925 case RID_IF:
4926 c_parser_if_statement (parser);
4927 break;
4928 case RID_SWITCH:
4929 c_parser_switch_statement (parser);
4930 break;
4931 case RID_WHILE:
4932 c_parser_while_statement (parser, false);
4933 break;
4934 case RID_DO:
4935 c_parser_do_statement (parser, false);
4936 break;
4937 case RID_FOR:
4938 c_parser_for_statement (parser, false);
4939 break;
4940 case RID_CILK_SYNC:
4941 c_parser_consume_token (parser);
4942 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4943 if (!flag_cilkplus)
4944 error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4945 else
4946 add_stmt (build_cilk_sync ());
4947 break;
4948 case RID_GOTO:
4949 c_parser_consume_token (parser);
4950 if (c_parser_next_token_is (parser, CPP_NAME))
4952 stmt = c_finish_goto_label (loc,
4953 c_parser_peek_token (parser)->value);
4954 c_parser_consume_token (parser);
4956 else if (c_parser_next_token_is (parser, CPP_MULT))
4958 struct c_expr val;
4960 c_parser_consume_token (parser);
4961 val = c_parser_expression (parser);
4962 val = convert_lvalue_to_rvalue (loc, val, false, true);
4963 stmt = c_finish_goto_ptr (loc, val.value);
4965 else
4966 c_parser_error (parser, "expected identifier or %<*%>");
4967 goto expect_semicolon;
4968 case RID_CONTINUE:
4969 c_parser_consume_token (parser);
4970 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4971 goto expect_semicolon;
4972 case RID_BREAK:
4973 c_parser_consume_token (parser);
4974 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4975 goto expect_semicolon;
4976 case RID_RETURN:
4977 c_parser_consume_token (parser);
4978 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4980 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4981 c_parser_consume_token (parser);
4983 else
4985 struct c_expr expr = c_parser_expression_conv (parser);
4986 mark_exp_read (expr.value);
4987 stmt = c_finish_return (loc, expr.value, expr.original_type);
4988 goto expect_semicolon;
4990 break;
4991 case RID_ASM:
4992 stmt = c_parser_asm_statement (parser);
4993 break;
4994 case RID_TRANSACTION_ATOMIC:
4995 case RID_TRANSACTION_RELAXED:
4996 stmt = c_parser_transaction (parser,
4997 c_parser_peek_token (parser)->keyword);
4998 break;
4999 case RID_TRANSACTION_CANCEL:
5000 stmt = c_parser_transaction_cancel (parser);
5001 goto expect_semicolon;
5002 case RID_AT_THROW:
5003 gcc_assert (c_dialect_objc ());
5004 c_parser_consume_token (parser);
5005 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5007 stmt = objc_build_throw_stmt (loc, NULL_TREE);
5008 c_parser_consume_token (parser);
5010 else
5012 struct c_expr expr = c_parser_expression (parser);
5013 expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5014 expr.value = c_fully_fold (expr.value, false, NULL);
5015 stmt = objc_build_throw_stmt (loc, expr.value);
5016 goto expect_semicolon;
5018 break;
5019 case RID_AT_TRY:
5020 gcc_assert (c_dialect_objc ());
5021 c_parser_objc_try_catch_finally_statement (parser);
5022 break;
5023 case RID_AT_SYNCHRONIZED:
5024 gcc_assert (c_dialect_objc ());
5025 c_parser_objc_synchronized_statement (parser);
5026 break;
5027 default:
5028 goto expr_stmt;
5030 break;
5031 case CPP_SEMICOLON:
5032 c_parser_consume_token (parser);
5033 break;
5034 case CPP_CLOSE_PAREN:
5035 case CPP_CLOSE_SQUARE:
5036 /* Avoid infinite loop in error recovery:
5037 c_parser_skip_until_found stops at a closing nesting
5038 delimiter without consuming it, but here we need to consume
5039 it to proceed further. */
5040 c_parser_error (parser, "expected statement");
5041 c_parser_consume_token (parser);
5042 break;
5043 case CPP_PRAGMA:
5044 c_parser_pragma (parser, pragma_stmt);
5045 break;
5046 default:
5047 expr_stmt:
5048 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5049 expect_semicolon:
5050 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5051 break;
5053 /* Two cases cannot and do not have line numbers associated: If stmt
5054 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5055 cannot hold line numbers. But that's OK because the statement
5056 will either be changed to a MODIFY_EXPR during gimplification of
5057 the statement expr, or discarded. If stmt was compound, but
5058 without new variables, we will have skipped the creation of a
5059 BIND and will have a bare STATEMENT_LIST. But that's OK because
5060 (recursively) all of the component statements should already have
5061 line numbers assigned. ??? Can we discard no-op statements
5062 earlier? */
5063 if (CAN_HAVE_LOCATION_P (stmt)
5064 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5065 SET_EXPR_LOCATION (stmt, loc);
5067 parser->in_if_block = in_if_block;
5070 /* Parse the condition from an if, do, while or for statements. */
5072 static tree
5073 c_parser_condition (c_parser *parser)
5075 location_t loc = c_parser_peek_token (parser)->location;
5076 tree cond;
5077 cond = c_parser_expression_conv (parser).value;
5078 cond = c_objc_common_truthvalue_conversion (loc, cond);
5079 cond = c_fully_fold (cond, false, NULL);
5080 if (warn_sequence_point)
5081 verify_sequence_points (cond);
5082 return cond;
5085 /* Parse a parenthesized condition from an if, do or while statement.
5087 condition:
5088 ( expression )
5090 static tree
5091 c_parser_paren_condition (c_parser *parser)
5093 tree cond;
5094 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5095 return error_mark_node;
5096 cond = c_parser_condition (parser);
5097 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5098 return cond;
5101 /* Parse a statement which is a block in C99. */
5103 static tree
5104 c_parser_c99_block_statement (c_parser *parser)
5106 tree block = c_begin_compound_stmt (flag_isoc99);
5107 location_t loc = c_parser_peek_token (parser)->location;
5108 c_parser_statement (parser);
5109 return c_end_compound_stmt (loc, block, flag_isoc99);
5112 /* Parse the body of an if statement. This is just parsing a
5113 statement but (a) it is a block in C99, (b) we track whether the
5114 body is an if statement for the sake of -Wparentheses warnings, (c)
5115 we handle an empty body specially for the sake of -Wempty-body
5116 warnings, and (d) we call parser_compound_statement directly
5117 because c_parser_statement_after_labels resets
5118 parser->in_if_block. */
5120 static tree
5121 c_parser_if_body (c_parser *parser, bool *if_p)
5123 tree block = c_begin_compound_stmt (flag_isoc99);
5124 location_t body_loc = c_parser_peek_token (parser)->location;
5125 while (c_parser_next_token_is_keyword (parser, RID_CASE)
5126 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
5127 || (c_parser_next_token_is (parser, CPP_NAME)
5128 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
5129 c_parser_label (parser);
5130 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
5131 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5133 location_t loc = c_parser_peek_token (parser)->location;
5134 add_stmt (build_empty_stmt (loc));
5135 c_parser_consume_token (parser);
5136 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5137 warning_at (loc, OPT_Wempty_body,
5138 "suggest braces around empty body in an %<if%> statement");
5140 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5141 add_stmt (c_parser_compound_statement (parser));
5142 else
5143 c_parser_statement_after_labels (parser);
5144 return c_end_compound_stmt (body_loc, block, flag_isoc99);
5147 /* Parse the else body of an if statement. This is just parsing a
5148 statement but (a) it is a block in C99, (b) we handle an empty body
5149 specially for the sake of -Wempty-body warnings. */
5151 static tree
5152 c_parser_else_body (c_parser *parser)
5154 location_t else_loc = c_parser_peek_token (parser)->location;
5155 tree block = c_begin_compound_stmt (flag_isoc99);
5156 while (c_parser_next_token_is_keyword (parser, RID_CASE)
5157 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
5158 || (c_parser_next_token_is (parser, CPP_NAME)
5159 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
5160 c_parser_label (parser);
5161 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5163 location_t loc = c_parser_peek_token (parser)->location;
5164 warning_at (loc,
5165 OPT_Wempty_body,
5166 "suggest braces around empty body in an %<else%> statement");
5167 add_stmt (build_empty_stmt (loc));
5168 c_parser_consume_token (parser);
5170 else
5171 c_parser_statement_after_labels (parser);
5172 return c_end_compound_stmt (else_loc, block, flag_isoc99);
5175 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5177 if-statement:
5178 if ( expression ) statement
5179 if ( expression ) statement else statement
5182 static void
5183 c_parser_if_statement (c_parser *parser)
5185 tree block;
5186 location_t loc;
5187 tree cond;
5188 bool first_if = false;
5189 tree first_body, second_body;
5190 bool in_if_block;
5191 tree if_stmt;
5193 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5194 c_parser_consume_token (parser);
5195 block = c_begin_compound_stmt (flag_isoc99);
5196 loc = c_parser_peek_token (parser)->location;
5197 cond = c_parser_paren_condition (parser);
5198 in_if_block = parser->in_if_block;
5199 parser->in_if_block = true;
5200 first_body = c_parser_if_body (parser, &first_if);
5201 parser->in_if_block = in_if_block;
5202 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5204 c_parser_consume_token (parser);
5205 second_body = c_parser_else_body (parser);
5207 else
5208 second_body = NULL_TREE;
5209 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
5210 if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
5212 /* If the if statement contains array notations, then we expand them. */
5213 if (flag_cilkplus && contains_array_notation_expr (if_stmt))
5214 if_stmt = fix_conditional_array_notations (if_stmt);
5215 add_stmt (if_stmt);
5218 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5220 switch-statement:
5221 switch (expression) statement
5224 static void
5225 c_parser_switch_statement (c_parser *parser)
5227 struct c_expr ce;
5228 tree block, expr, body, save_break;
5229 location_t switch_loc = c_parser_peek_token (parser)->location;
5230 location_t switch_cond_loc;
5231 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5232 c_parser_consume_token (parser);
5233 block = c_begin_compound_stmt (flag_isoc99);
5234 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5236 switch_cond_loc = c_parser_peek_token (parser)->location;
5237 ce = c_parser_expression (parser);
5238 ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5239 expr = ce.value;
5240 if (flag_cilkplus && contains_array_notation_expr (expr))
5242 error_at (switch_cond_loc,
5243 "array notations cannot be used as a condition for switch "
5244 "statement");
5245 expr = error_mark_node;
5247 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5249 else
5251 switch_cond_loc = UNKNOWN_LOCATION;
5252 expr = error_mark_node;
5254 c_start_case (switch_loc, switch_cond_loc, expr);
5255 save_break = c_break_label;
5256 c_break_label = NULL_TREE;
5257 body = c_parser_c99_block_statement (parser);
5258 c_finish_case (body);
5259 if (c_break_label)
5261 location_t here = c_parser_peek_token (parser)->location;
5262 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5263 SET_EXPR_LOCATION (t, here);
5264 add_stmt (t);
5266 c_break_label = save_break;
5267 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5270 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5272 while-statement:
5273 while (expression) statement
5276 static void
5277 c_parser_while_statement (c_parser *parser, bool ivdep)
5279 tree block, cond, body, save_break, save_cont;
5280 location_t loc;
5281 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5282 c_parser_consume_token (parser);
5283 block = c_begin_compound_stmt (flag_isoc99);
5284 loc = c_parser_peek_token (parser)->location;
5285 cond = c_parser_paren_condition (parser);
5286 if (flag_cilkplus && contains_array_notation_expr (cond))
5288 error_at (loc, "array notations cannot be used as a condition for while "
5289 "statement");
5290 cond = error_mark_node;
5293 if (ivdep && cond != error_mark_node)
5294 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5295 build_int_cst (integer_type_node,
5296 annot_expr_ivdep_kind));
5297 save_break = c_break_label;
5298 c_break_label = NULL_TREE;
5299 save_cont = c_cont_label;
5300 c_cont_label = NULL_TREE;
5301 body = c_parser_c99_block_statement (parser);
5302 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5303 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5304 c_break_label = save_break;
5305 c_cont_label = save_cont;
5308 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5310 do-statement:
5311 do statement while ( expression ) ;
5314 static void
5315 c_parser_do_statement (c_parser *parser, bool ivdep)
5317 tree block, cond, body, save_break, save_cont, new_break, new_cont;
5318 location_t loc;
5319 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5320 c_parser_consume_token (parser);
5321 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5322 warning_at (c_parser_peek_token (parser)->location,
5323 OPT_Wempty_body,
5324 "suggest braces around empty body in %<do%> statement");
5325 block = c_begin_compound_stmt (flag_isoc99);
5326 loc = c_parser_peek_token (parser)->location;
5327 save_break = c_break_label;
5328 c_break_label = NULL_TREE;
5329 save_cont = c_cont_label;
5330 c_cont_label = NULL_TREE;
5331 body = c_parser_c99_block_statement (parser);
5332 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5333 new_break = c_break_label;
5334 c_break_label = save_break;
5335 new_cont = c_cont_label;
5336 c_cont_label = save_cont;
5337 cond = c_parser_paren_condition (parser);
5338 if (flag_cilkplus && contains_array_notation_expr (cond))
5340 error_at (loc, "array notations cannot be used as a condition for a "
5341 "do-while statement");
5342 cond = error_mark_node;
5344 if (ivdep && cond != error_mark_node)
5345 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5346 build_int_cst (integer_type_node,
5347 annot_expr_ivdep_kind));
5348 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5349 c_parser_skip_to_end_of_block_or_statement (parser);
5350 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5351 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5354 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5356 for-statement:
5357 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5358 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5360 The form with a declaration is new in C99.
5362 ??? In accordance with the old parser, the declaration may be a
5363 nested function, which is then rejected in check_for_loop_decls,
5364 but does it make any sense for this to be included in the grammar?
5365 Note in particular that the nested function does not include a
5366 trailing ';', whereas the "declaration" production includes one.
5367 Also, can we reject bad declarations earlier and cheaper than
5368 check_for_loop_decls?
5370 In Objective-C, there are two additional variants:
5372 foreach-statement:
5373 for ( expression in expresssion ) statement
5374 for ( declaration in expression ) statement
5376 This is inconsistent with C, because the second variant is allowed
5377 even if c99 is not enabled.
5379 The rest of the comment documents these Objective-C foreach-statement.
5381 Here is the canonical example of the first variant:
5382 for (object in array) { do something with object }
5383 we call the first expression ("object") the "object_expression" and
5384 the second expression ("array") the "collection_expression".
5385 object_expression must be an lvalue of type "id" (a generic Objective-C
5386 object) because the loop works by assigning to object_expression the
5387 various objects from the collection_expression. collection_expression
5388 must evaluate to something of type "id" which responds to the method
5389 countByEnumeratingWithState:objects:count:.
5391 The canonical example of the second variant is:
5392 for (id object in array) { do something with object }
5393 which is completely equivalent to
5395 id object;
5396 for (object in array) { do something with object }
5398 Note that initizializing 'object' in some way (eg, "for ((object =
5399 xxx) in array) { do something with object }") is possibly
5400 technically valid, but completely pointless as 'object' will be
5401 assigned to something else as soon as the loop starts. We should
5402 most likely reject it (TODO).
5404 The beginning of the Objective-C foreach-statement looks exactly
5405 like the beginning of the for-statement, and we can tell it is a
5406 foreach-statement only because the initial declaration or
5407 expression is terminated by 'in' instead of ';'.
5410 static void
5411 c_parser_for_statement (c_parser *parser, bool ivdep)
5413 tree block, cond, incr, save_break, save_cont, body;
5414 /* The following are only used when parsing an ObjC foreach statement. */
5415 tree object_expression;
5416 /* Silence the bogus uninitialized warning. */
5417 tree collection_expression = NULL;
5418 location_t loc = c_parser_peek_token (parser)->location;
5419 location_t for_loc = c_parser_peek_token (parser)->location;
5420 bool is_foreach_statement = false;
5421 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
5422 c_parser_consume_token (parser);
5423 /* Open a compound statement in Objective-C as well, just in case this is
5424 as foreach expression. */
5425 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
5426 cond = error_mark_node;
5427 incr = error_mark_node;
5428 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5430 /* Parse the initialization declaration or expression. */
5431 object_expression = error_mark_node;
5432 parser->objc_could_be_foreach_context = c_dialect_objc ();
5433 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5435 parser->objc_could_be_foreach_context = false;
5436 c_parser_consume_token (parser);
5437 c_finish_expr_stmt (loc, NULL_TREE);
5439 else if (c_parser_next_tokens_start_declaration (parser))
5441 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
5442 &object_expression, vNULL);
5443 parser->objc_could_be_foreach_context = false;
5445 if (c_parser_next_token_is_keyword (parser, RID_IN))
5447 c_parser_consume_token (parser);
5448 is_foreach_statement = true;
5449 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5450 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5452 else
5453 check_for_loop_decls (for_loc, flag_isoc99);
5455 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5457 /* __extension__ can start a declaration, but is also an
5458 unary operator that can start an expression. Consume all
5459 but the last of a possible series of __extension__ to
5460 determine which. */
5461 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5462 && (c_parser_peek_2nd_token (parser)->keyword
5463 == RID_EXTENSION))
5464 c_parser_consume_token (parser);
5465 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5467 int ext;
5468 ext = disable_extension_diagnostics ();
5469 c_parser_consume_token (parser);
5470 c_parser_declaration_or_fndef (parser, true, true, true, true,
5471 true, &object_expression, vNULL);
5472 parser->objc_could_be_foreach_context = false;
5474 restore_extension_diagnostics (ext);
5475 if (c_parser_next_token_is_keyword (parser, RID_IN))
5477 c_parser_consume_token (parser);
5478 is_foreach_statement = true;
5479 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5480 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5482 else
5483 check_for_loop_decls (for_loc, flag_isoc99);
5485 else
5486 goto init_expr;
5488 else
5490 init_expr:
5492 struct c_expr ce;
5493 tree init_expression;
5494 ce = c_parser_expression (parser);
5495 init_expression = ce.value;
5496 parser->objc_could_be_foreach_context = false;
5497 if (c_parser_next_token_is_keyword (parser, RID_IN))
5499 c_parser_consume_token (parser);
5500 is_foreach_statement = true;
5501 if (! lvalue_p (init_expression))
5502 c_parser_error (parser, "invalid iterating variable in fast enumeration");
5503 object_expression = c_fully_fold (init_expression, false, NULL);
5505 else
5507 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5508 init_expression = ce.value;
5509 c_finish_expr_stmt (loc, init_expression);
5510 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5514 /* Parse the loop condition. In the case of a foreach
5515 statement, there is no loop condition. */
5516 gcc_assert (!parser->objc_could_be_foreach_context);
5517 if (!is_foreach_statement)
5519 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5521 if (ivdep)
5523 c_parser_error (parser, "missing loop condition in loop with "
5524 "%<GCC ivdep%> pragma");
5525 cond = error_mark_node;
5527 else
5529 c_parser_consume_token (parser);
5530 cond = NULL_TREE;
5533 else
5535 cond = c_parser_condition (parser);
5536 if (flag_cilkplus && contains_array_notation_expr (cond))
5538 error_at (loc, "array notations cannot be used in a "
5539 "condition for a for-loop");
5540 cond = error_mark_node;
5542 c_parser_skip_until_found (parser, CPP_SEMICOLON,
5543 "expected %<;%>");
5545 if (ivdep && cond != error_mark_node)
5546 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5547 build_int_cst (integer_type_node,
5548 annot_expr_ivdep_kind));
5550 /* Parse the increment expression (the third expression in a
5551 for-statement). In the case of a foreach-statement, this is
5552 the expression that follows the 'in'. */
5553 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5555 if (is_foreach_statement)
5557 c_parser_error (parser, "missing collection in fast enumeration");
5558 collection_expression = error_mark_node;
5560 else
5561 incr = c_process_expr_stmt (loc, NULL_TREE);
5563 else
5565 if (is_foreach_statement)
5566 collection_expression = c_fully_fold (c_parser_expression (parser).value,
5567 false, NULL);
5568 else
5570 struct c_expr ce = c_parser_expression (parser);
5571 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5572 incr = c_process_expr_stmt (loc, ce.value);
5575 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5577 save_break = c_break_label;
5578 c_break_label = NULL_TREE;
5579 save_cont = c_cont_label;
5580 c_cont_label = NULL_TREE;
5581 body = c_parser_c99_block_statement (parser);
5582 if (is_foreach_statement)
5583 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5584 else
5585 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5586 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5587 c_break_label = save_break;
5588 c_cont_label = save_cont;
5591 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5592 statement with inputs, outputs, clobbers, and volatile tag
5593 allowed.
5595 asm-statement:
5596 asm type-qualifier[opt] ( asm-argument ) ;
5597 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5599 asm-argument:
5600 asm-string-literal
5601 asm-string-literal : asm-operands[opt]
5602 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5603 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5605 asm-goto-argument:
5606 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5607 : asm-goto-operands
5609 Qualifiers other than volatile are accepted in the syntax but
5610 warned for. */
5612 static tree
5613 c_parser_asm_statement (c_parser *parser)
5615 tree quals, str, outputs, inputs, clobbers, labels, ret;
5616 bool simple, is_goto;
5617 location_t asm_loc = c_parser_peek_token (parser)->location;
5618 int section, nsections;
5620 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5621 c_parser_consume_token (parser);
5622 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5624 quals = c_parser_peek_token (parser)->value;
5625 c_parser_consume_token (parser);
5627 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5628 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5630 warning_at (c_parser_peek_token (parser)->location,
5632 "%E qualifier ignored on asm",
5633 c_parser_peek_token (parser)->value);
5634 quals = NULL_TREE;
5635 c_parser_consume_token (parser);
5637 else
5638 quals = NULL_TREE;
5640 is_goto = false;
5641 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5643 c_parser_consume_token (parser);
5644 is_goto = true;
5647 /* ??? Follow the C++ parser rather than using the
5648 lex_untranslated_string kludge. */
5649 parser->lex_untranslated_string = true;
5650 ret = NULL;
5652 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5653 goto error;
5655 str = c_parser_asm_string_literal (parser);
5656 if (str == NULL_TREE)
5657 goto error_close_paren;
5659 simple = true;
5660 outputs = NULL_TREE;
5661 inputs = NULL_TREE;
5662 clobbers = NULL_TREE;
5663 labels = NULL_TREE;
5665 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5666 goto done_asm;
5668 /* Parse each colon-delimited section of operands. */
5669 nsections = 3 + is_goto;
5670 for (section = 0; section < nsections; ++section)
5672 if (!c_parser_require (parser, CPP_COLON,
5673 is_goto
5674 ? "expected %<:%>"
5675 : "expected %<:%> or %<)%>"))
5676 goto error_close_paren;
5678 /* Once past any colon, we're no longer a simple asm. */
5679 simple = false;
5681 if ((!c_parser_next_token_is (parser, CPP_COLON)
5682 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5683 || section == 3)
5684 switch (section)
5686 case 0:
5687 /* For asm goto, we don't allow output operands, but reserve
5688 the slot for a future extension that does allow them. */
5689 if (!is_goto)
5690 outputs = c_parser_asm_operands (parser);
5691 break;
5692 case 1:
5693 inputs = c_parser_asm_operands (parser);
5694 break;
5695 case 2:
5696 clobbers = c_parser_asm_clobbers (parser);
5697 break;
5698 case 3:
5699 labels = c_parser_asm_goto_operands (parser);
5700 break;
5701 default:
5702 gcc_unreachable ();
5705 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5706 goto done_asm;
5709 done_asm:
5710 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5712 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5713 goto error;
5716 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5717 c_parser_skip_to_end_of_block_or_statement (parser);
5719 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5720 clobbers, labels, simple));
5722 error:
5723 parser->lex_untranslated_string = false;
5724 return ret;
5726 error_close_paren:
5727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5728 goto error;
5731 /* Parse asm operands, a GNU extension.
5733 asm-operands:
5734 asm-operand
5735 asm-operands , asm-operand
5737 asm-operand:
5738 asm-string-literal ( expression )
5739 [ identifier ] asm-string-literal ( expression )
5742 static tree
5743 c_parser_asm_operands (c_parser *parser)
5745 tree list = NULL_TREE;
5746 while (true)
5748 tree name, str;
5749 struct c_expr expr;
5750 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5752 c_parser_consume_token (parser);
5753 if (c_parser_next_token_is (parser, CPP_NAME))
5755 tree id = c_parser_peek_token (parser)->value;
5756 c_parser_consume_token (parser);
5757 name = build_string (IDENTIFIER_LENGTH (id),
5758 IDENTIFIER_POINTER (id));
5760 else
5762 c_parser_error (parser, "expected identifier");
5763 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5764 return NULL_TREE;
5766 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5767 "expected %<]%>");
5769 else
5770 name = NULL_TREE;
5771 str = c_parser_asm_string_literal (parser);
5772 if (str == NULL_TREE)
5773 return NULL_TREE;
5774 parser->lex_untranslated_string = false;
5775 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5777 parser->lex_untranslated_string = true;
5778 return NULL_TREE;
5780 expr = c_parser_expression (parser);
5781 mark_exp_read (expr.value);
5782 parser->lex_untranslated_string = true;
5783 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5785 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5786 return NULL_TREE;
5788 list = chainon (list, build_tree_list (build_tree_list (name, str),
5789 expr.value));
5790 if (c_parser_next_token_is (parser, CPP_COMMA))
5791 c_parser_consume_token (parser);
5792 else
5793 break;
5795 return list;
5798 /* Parse asm clobbers, a GNU extension.
5800 asm-clobbers:
5801 asm-string-literal
5802 asm-clobbers , asm-string-literal
5805 static tree
5806 c_parser_asm_clobbers (c_parser *parser)
5808 tree list = NULL_TREE;
5809 while (true)
5811 tree str = c_parser_asm_string_literal (parser);
5812 if (str)
5813 list = tree_cons (NULL_TREE, str, list);
5814 else
5815 return NULL_TREE;
5816 if (c_parser_next_token_is (parser, CPP_COMMA))
5817 c_parser_consume_token (parser);
5818 else
5819 break;
5821 return list;
5824 /* Parse asm goto labels, a GNU extension.
5826 asm-goto-operands:
5827 identifier
5828 asm-goto-operands , identifier
5831 static tree
5832 c_parser_asm_goto_operands (c_parser *parser)
5834 tree list = NULL_TREE;
5835 while (true)
5837 tree name, label;
5839 if (c_parser_next_token_is (parser, CPP_NAME))
5841 c_token *tok = c_parser_peek_token (parser);
5842 name = tok->value;
5843 label = lookup_label_for_goto (tok->location, name);
5844 c_parser_consume_token (parser);
5845 TREE_USED (label) = 1;
5847 else
5849 c_parser_error (parser, "expected identifier");
5850 return NULL_TREE;
5853 name = build_string (IDENTIFIER_LENGTH (name),
5854 IDENTIFIER_POINTER (name));
5855 list = tree_cons (name, label, list);
5856 if (c_parser_next_token_is (parser, CPP_COMMA))
5857 c_parser_consume_token (parser);
5858 else
5859 return nreverse (list);
5863 /* Parse an expression other than a compound expression; that is, an
5864 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5865 NULL then it is an Objective-C message expression which is the
5866 primary-expression starting the expression as an initializer.
5868 assignment-expression:
5869 conditional-expression
5870 unary-expression assignment-operator assignment-expression
5872 assignment-operator: one of
5873 = *= /= %= += -= <<= >>= &= ^= |=
5875 In GNU C we accept any conditional expression on the LHS and
5876 diagnose the invalid lvalue rather than producing a syntax
5877 error. */
5879 static struct c_expr
5880 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
5881 tree omp_atomic_lhs)
5883 struct c_expr lhs, rhs, ret;
5884 enum tree_code code;
5885 location_t op_location, exp_location;
5886 gcc_assert (!after || c_dialect_objc ());
5887 lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
5888 op_location = c_parser_peek_token (parser)->location;
5889 switch (c_parser_peek_token (parser)->type)
5891 case CPP_EQ:
5892 code = NOP_EXPR;
5893 break;
5894 case CPP_MULT_EQ:
5895 code = MULT_EXPR;
5896 break;
5897 case CPP_DIV_EQ:
5898 code = TRUNC_DIV_EXPR;
5899 break;
5900 case CPP_MOD_EQ:
5901 code = TRUNC_MOD_EXPR;
5902 break;
5903 case CPP_PLUS_EQ:
5904 code = PLUS_EXPR;
5905 break;
5906 case CPP_MINUS_EQ:
5907 code = MINUS_EXPR;
5908 break;
5909 case CPP_LSHIFT_EQ:
5910 code = LSHIFT_EXPR;
5911 break;
5912 case CPP_RSHIFT_EQ:
5913 code = RSHIFT_EXPR;
5914 break;
5915 case CPP_AND_EQ:
5916 code = BIT_AND_EXPR;
5917 break;
5918 case CPP_XOR_EQ:
5919 code = BIT_XOR_EXPR;
5920 break;
5921 case CPP_OR_EQ:
5922 code = BIT_IOR_EXPR;
5923 break;
5924 default:
5925 return lhs;
5927 c_parser_consume_token (parser);
5928 exp_location = c_parser_peek_token (parser)->location;
5929 rhs = c_parser_expr_no_commas (parser, NULL);
5930 rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
5932 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5933 code, exp_location, rhs.value,
5934 rhs.original_type);
5935 if (code == NOP_EXPR)
5936 ret.original_code = MODIFY_EXPR;
5937 else
5939 TREE_NO_WARNING (ret.value) = 1;
5940 ret.original_code = ERROR_MARK;
5942 ret.original_type = NULL;
5943 return ret;
5946 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5947 is not NULL then it is an Objective-C message expression which is
5948 the primary-expression starting the expression as an initializer.
5950 conditional-expression:
5951 logical-OR-expression
5952 logical-OR-expression ? expression : conditional-expression
5954 GNU extensions:
5956 conditional-expression:
5957 logical-OR-expression ? : conditional-expression
5960 static struct c_expr
5961 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
5962 tree omp_atomic_lhs)
5964 struct c_expr cond, exp1, exp2, ret;
5965 location_t cond_loc, colon_loc, middle_loc;
5967 gcc_assert (!after || c_dialect_objc ());
5969 cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
5971 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5972 return cond;
5973 cond_loc = c_parser_peek_token (parser)->location;
5974 cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
5975 c_parser_consume_token (parser);
5976 if (c_parser_next_token_is (parser, CPP_COLON))
5978 tree eptype = NULL_TREE;
5980 middle_loc = c_parser_peek_token (parser)->location;
5981 pedwarn (middle_loc, OPT_Wpedantic,
5982 "ISO C forbids omitting the middle term of a ?: expression");
5983 warn_for_omitted_condop (middle_loc, cond.value);
5984 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5986 eptype = TREE_TYPE (cond.value);
5987 cond.value = TREE_OPERAND (cond.value, 0);
5989 /* Make sure first operand is calculated only once. */
5990 exp1.value = c_save_expr (default_conversion (cond.value));
5991 if (eptype)
5992 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5993 exp1.original_type = NULL;
5994 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5995 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5997 else
5999 cond.value
6000 = c_objc_common_truthvalue_conversion
6001 (cond_loc, default_conversion (cond.value));
6002 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6003 exp1 = c_parser_expression_conv (parser);
6004 mark_exp_read (exp1.value);
6005 c_inhibit_evaluation_warnings +=
6006 ((cond.value == truthvalue_true_node)
6007 - (cond.value == truthvalue_false_node));
6010 colon_loc = c_parser_peek_token (parser)->location;
6011 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6013 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6014 ret.value = error_mark_node;
6015 ret.original_code = ERROR_MARK;
6016 ret.original_type = NULL;
6017 return ret;
6020 location_t exp2_loc = c_parser_peek_token (parser)->location;
6021 exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6022 exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6024 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6025 ret.value = build_conditional_expr (colon_loc, cond.value,
6026 cond.original_code == C_MAYBE_CONST_EXPR,
6027 exp1.value, exp1.original_type,
6028 exp2.value, exp2.original_type);
6029 ret.original_code = ERROR_MARK;
6030 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6031 ret.original_type = NULL;
6032 else
6034 tree t1, t2;
6036 /* If both sides are enum type, the default conversion will have
6037 made the type of the result be an integer type. We want to
6038 remember the enum types we started with. */
6039 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6040 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6041 ret.original_type = ((t1 != error_mark_node
6042 && t2 != error_mark_node
6043 && (TYPE_MAIN_VARIANT (t1)
6044 == TYPE_MAIN_VARIANT (t2)))
6045 ? t1
6046 : NULL);
6048 return ret;
6051 /* Parse a binary expression; that is, a logical-OR-expression (C90
6052 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6053 an Objective-C message expression which is the primary-expression
6054 starting the expression as an initializer.
6056 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6057 when it should be the unfolded lhs. In a valid OpenMP source,
6058 one of the operands of the toplevel binary expression must be equal
6059 to it. In that case, just return a build2 created binary operation
6060 rather than result of parser_build_binary_op.
6062 multiplicative-expression:
6063 cast-expression
6064 multiplicative-expression * cast-expression
6065 multiplicative-expression / cast-expression
6066 multiplicative-expression % cast-expression
6068 additive-expression:
6069 multiplicative-expression
6070 additive-expression + multiplicative-expression
6071 additive-expression - multiplicative-expression
6073 shift-expression:
6074 additive-expression
6075 shift-expression << additive-expression
6076 shift-expression >> additive-expression
6078 relational-expression:
6079 shift-expression
6080 relational-expression < shift-expression
6081 relational-expression > shift-expression
6082 relational-expression <= shift-expression
6083 relational-expression >= shift-expression
6085 equality-expression:
6086 relational-expression
6087 equality-expression == relational-expression
6088 equality-expression != relational-expression
6090 AND-expression:
6091 equality-expression
6092 AND-expression & equality-expression
6094 exclusive-OR-expression:
6095 AND-expression
6096 exclusive-OR-expression ^ AND-expression
6098 inclusive-OR-expression:
6099 exclusive-OR-expression
6100 inclusive-OR-expression | exclusive-OR-expression
6102 logical-AND-expression:
6103 inclusive-OR-expression
6104 logical-AND-expression && inclusive-OR-expression
6106 logical-OR-expression:
6107 logical-AND-expression
6108 logical-OR-expression || logical-AND-expression
6111 static struct c_expr
6112 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6113 tree omp_atomic_lhs)
6115 /* A binary expression is parsed using operator-precedence parsing,
6116 with the operands being cast expressions. All the binary
6117 operators are left-associative. Thus a binary expression is of
6118 form:
6120 E0 op1 E1 op2 E2 ...
6122 which we represent on a stack. On the stack, the precedence
6123 levels are strictly increasing. When a new operator is
6124 encountered of higher precedence than that at the top of the
6125 stack, it is pushed; its LHS is the top expression, and its RHS
6126 is everything parsed until it is popped. When a new operator is
6127 encountered with precedence less than or equal to that at the top
6128 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6129 by the result of the operation until the operator at the top of
6130 the stack has lower precedence than the new operator or there is
6131 only one element on the stack; then the top expression is the LHS
6132 of the new operator. In the case of logical AND and OR
6133 expressions, we also need to adjust c_inhibit_evaluation_warnings
6134 as appropriate when the operators are pushed and popped. */
6136 struct {
6137 /* The expression at this stack level. */
6138 struct c_expr expr;
6139 /* The precedence of the operator on its left, PREC_NONE at the
6140 bottom of the stack. */
6141 enum c_parser_prec prec;
6142 /* The operation on its left. */
6143 enum tree_code op;
6144 /* The source location of this operation. */
6145 location_t loc;
6146 } stack[NUM_PRECS];
6147 int sp;
6148 /* Location of the binary operator. */
6149 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
6150 #define POP \
6151 do { \
6152 switch (stack[sp].op) \
6154 case TRUTH_ANDIF_EXPR: \
6155 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6156 == truthvalue_false_node); \
6157 break; \
6158 case TRUTH_ORIF_EXPR: \
6159 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6160 == truthvalue_true_node); \
6161 break; \
6162 default: \
6163 break; \
6165 stack[sp - 1].expr \
6166 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6167 stack[sp - 1].expr, true, true); \
6168 stack[sp].expr \
6169 = convert_lvalue_to_rvalue (stack[sp].loc, \
6170 stack[sp].expr, true, true); \
6171 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6172 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6173 && ((1 << stack[sp].prec) \
6174 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6175 | PREC_ADD | PREC_MULT))) \
6176 && stack[sp].op != TRUNC_MOD_EXPR \
6177 && stack[0].expr.value != error_mark_node \
6178 && stack[1].expr.value != error_mark_node \
6179 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6180 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6181 stack[0].expr.value \
6182 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6183 stack[0].expr.value, stack[1].expr.value); \
6184 else \
6185 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6186 stack[sp].op, \
6187 stack[sp - 1].expr, \
6188 stack[sp].expr); \
6189 sp--; \
6190 } while (0)
6191 gcc_assert (!after || c_dialect_objc ());
6192 stack[0].loc = c_parser_peek_token (parser)->location;
6193 stack[0].expr = c_parser_cast_expression (parser, after);
6194 stack[0].prec = PREC_NONE;
6195 sp = 0;
6196 while (true)
6198 enum c_parser_prec oprec;
6199 enum tree_code ocode;
6200 if (parser->error)
6201 goto out;
6202 switch (c_parser_peek_token (parser)->type)
6204 case CPP_MULT:
6205 oprec = PREC_MULT;
6206 ocode = MULT_EXPR;
6207 break;
6208 case CPP_DIV:
6209 oprec = PREC_MULT;
6210 ocode = TRUNC_DIV_EXPR;
6211 break;
6212 case CPP_MOD:
6213 oprec = PREC_MULT;
6214 ocode = TRUNC_MOD_EXPR;
6215 break;
6216 case CPP_PLUS:
6217 oprec = PREC_ADD;
6218 ocode = PLUS_EXPR;
6219 break;
6220 case CPP_MINUS:
6221 oprec = PREC_ADD;
6222 ocode = MINUS_EXPR;
6223 break;
6224 case CPP_LSHIFT:
6225 oprec = PREC_SHIFT;
6226 ocode = LSHIFT_EXPR;
6227 break;
6228 case CPP_RSHIFT:
6229 oprec = PREC_SHIFT;
6230 ocode = RSHIFT_EXPR;
6231 break;
6232 case CPP_LESS:
6233 oprec = PREC_REL;
6234 ocode = LT_EXPR;
6235 break;
6236 case CPP_GREATER:
6237 oprec = PREC_REL;
6238 ocode = GT_EXPR;
6239 break;
6240 case CPP_LESS_EQ:
6241 oprec = PREC_REL;
6242 ocode = LE_EXPR;
6243 break;
6244 case CPP_GREATER_EQ:
6245 oprec = PREC_REL;
6246 ocode = GE_EXPR;
6247 break;
6248 case CPP_EQ_EQ:
6249 oprec = PREC_EQ;
6250 ocode = EQ_EXPR;
6251 break;
6252 case CPP_NOT_EQ:
6253 oprec = PREC_EQ;
6254 ocode = NE_EXPR;
6255 break;
6256 case CPP_AND:
6257 oprec = PREC_BITAND;
6258 ocode = BIT_AND_EXPR;
6259 break;
6260 case CPP_XOR:
6261 oprec = PREC_BITXOR;
6262 ocode = BIT_XOR_EXPR;
6263 break;
6264 case CPP_OR:
6265 oprec = PREC_BITOR;
6266 ocode = BIT_IOR_EXPR;
6267 break;
6268 case CPP_AND_AND:
6269 oprec = PREC_LOGAND;
6270 ocode = TRUTH_ANDIF_EXPR;
6271 break;
6272 case CPP_OR_OR:
6273 oprec = PREC_LOGOR;
6274 ocode = TRUTH_ORIF_EXPR;
6275 break;
6276 default:
6277 /* Not a binary operator, so end of the binary
6278 expression. */
6279 goto out;
6281 binary_loc = c_parser_peek_token (parser)->location;
6282 while (oprec <= stack[sp].prec)
6283 POP;
6284 c_parser_consume_token (parser);
6285 switch (ocode)
6287 case TRUTH_ANDIF_EXPR:
6288 stack[sp].expr
6289 = convert_lvalue_to_rvalue (stack[sp].loc,
6290 stack[sp].expr, true, true);
6291 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6292 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6293 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6294 == truthvalue_false_node);
6295 break;
6296 case TRUTH_ORIF_EXPR:
6297 stack[sp].expr
6298 = convert_lvalue_to_rvalue (stack[sp].loc,
6299 stack[sp].expr, true, true);
6300 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6301 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6302 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6303 == truthvalue_true_node);
6304 break;
6305 default:
6306 break;
6308 sp++;
6309 stack[sp].loc = binary_loc;
6310 stack[sp].expr = c_parser_cast_expression (parser, NULL);
6311 stack[sp].prec = oprec;
6312 stack[sp].op = ocode;
6313 stack[sp].loc = binary_loc;
6315 out:
6316 while (sp > 0)
6317 POP;
6318 return stack[0].expr;
6319 #undef POP
6322 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6323 NULL then it is an Objective-C message expression which is the
6324 primary-expression starting the expression as an initializer.
6326 cast-expression:
6327 unary-expression
6328 ( type-name ) unary-expression
6331 static struct c_expr
6332 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
6334 location_t cast_loc = c_parser_peek_token (parser)->location;
6335 gcc_assert (!after || c_dialect_objc ());
6336 if (after)
6337 return c_parser_postfix_expression_after_primary (parser,
6338 cast_loc, *after);
6339 /* If the expression begins with a parenthesized type name, it may
6340 be either a cast or a compound literal; we need to see whether
6341 the next character is '{' to tell the difference. If not, it is
6342 an unary expression. Full detection of unknown typenames here
6343 would require a 3-token lookahead. */
6344 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6345 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6347 struct c_type_name *type_name;
6348 struct c_expr ret;
6349 struct c_expr expr;
6350 c_parser_consume_token (parser);
6351 type_name = c_parser_type_name (parser);
6352 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6353 if (type_name == NULL)
6355 ret.value = error_mark_node;
6356 ret.original_code = ERROR_MARK;
6357 ret.original_type = NULL;
6358 return ret;
6361 /* Save casted types in the function's used types hash table. */
6362 used_types_insert (type_name->specs->type);
6364 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6365 return c_parser_postfix_expression_after_paren_type (parser, type_name,
6366 cast_loc);
6368 location_t expr_loc = c_parser_peek_token (parser)->location;
6369 expr = c_parser_cast_expression (parser, NULL);
6370 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
6372 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
6373 ret.original_code = ERROR_MARK;
6374 ret.original_type = NULL;
6375 return ret;
6377 else
6378 return c_parser_unary_expression (parser);
6381 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6383 unary-expression:
6384 postfix-expression
6385 ++ unary-expression
6386 -- unary-expression
6387 unary-operator cast-expression
6388 sizeof unary-expression
6389 sizeof ( type-name )
6391 unary-operator: one of
6392 & * + - ~ !
6394 GNU extensions:
6396 unary-expression:
6397 __alignof__ unary-expression
6398 __alignof__ ( type-name )
6399 && identifier
6401 (C11 permits _Alignof with type names only.)
6403 unary-operator: one of
6404 __extension__ __real__ __imag__
6406 Transactional Memory:
6408 unary-expression:
6409 transaction-expression
6411 In addition, the GNU syntax treats ++ and -- as unary operators, so
6412 they may be applied to cast expressions with errors for non-lvalues
6413 given later. */
6415 static struct c_expr
6416 c_parser_unary_expression (c_parser *parser)
6418 int ext;
6419 struct c_expr ret, op;
6420 location_t op_loc = c_parser_peek_token (parser)->location;
6421 location_t exp_loc;
6422 ret.original_code = ERROR_MARK;
6423 ret.original_type = NULL;
6424 switch (c_parser_peek_token (parser)->type)
6426 case CPP_PLUS_PLUS:
6427 c_parser_consume_token (parser);
6428 exp_loc = c_parser_peek_token (parser)->location;
6429 op = c_parser_cast_expression (parser, NULL);
6431 /* If there is array notations in op, we expand them. */
6432 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6433 return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op);
6434 else
6436 op = default_function_array_read_conversion (exp_loc, op);
6437 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
6439 case CPP_MINUS_MINUS:
6440 c_parser_consume_token (parser);
6441 exp_loc = c_parser_peek_token (parser)->location;
6442 op = c_parser_cast_expression (parser, NULL);
6444 /* If there is array notations in op, we expand them. */
6445 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6446 return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op);
6447 else
6449 op = default_function_array_read_conversion (exp_loc, op);
6450 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
6452 case CPP_AND:
6453 c_parser_consume_token (parser);
6454 op = c_parser_cast_expression (parser, NULL);
6455 mark_exp_read (op.value);
6456 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
6457 case CPP_MULT:
6458 c_parser_consume_token (parser);
6459 exp_loc = c_parser_peek_token (parser)->location;
6460 op = c_parser_cast_expression (parser, NULL);
6461 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6462 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
6463 return ret;
6464 case CPP_PLUS:
6465 if (!c_dialect_objc () && !in_system_header_at (input_location))
6466 warning_at (op_loc,
6467 OPT_Wtraditional,
6468 "traditional C rejects the unary plus operator");
6469 c_parser_consume_token (parser);
6470 exp_loc = c_parser_peek_token (parser)->location;
6471 op = c_parser_cast_expression (parser, NULL);
6472 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6473 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
6474 case CPP_MINUS:
6475 c_parser_consume_token (parser);
6476 exp_loc = c_parser_peek_token (parser)->location;
6477 op = c_parser_cast_expression (parser, NULL);
6478 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6479 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
6480 case CPP_COMPL:
6481 c_parser_consume_token (parser);
6482 exp_loc = c_parser_peek_token (parser)->location;
6483 op = c_parser_cast_expression (parser, NULL);
6484 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6485 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
6486 case CPP_NOT:
6487 c_parser_consume_token (parser);
6488 exp_loc = c_parser_peek_token (parser)->location;
6489 op = c_parser_cast_expression (parser, NULL);
6490 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6491 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
6492 case CPP_AND_AND:
6493 /* Refer to the address of a label as a pointer. */
6494 c_parser_consume_token (parser);
6495 if (c_parser_next_token_is (parser, CPP_NAME))
6497 ret.value = finish_label_address_expr
6498 (c_parser_peek_token (parser)->value, op_loc);
6499 c_parser_consume_token (parser);
6501 else
6503 c_parser_error (parser, "expected identifier");
6504 ret.value = error_mark_node;
6506 return ret;
6507 case CPP_KEYWORD:
6508 switch (c_parser_peek_token (parser)->keyword)
6510 case RID_SIZEOF:
6511 return c_parser_sizeof_expression (parser);
6512 case RID_ALIGNOF:
6513 return c_parser_alignof_expression (parser);
6514 case RID_EXTENSION:
6515 c_parser_consume_token (parser);
6516 ext = disable_extension_diagnostics ();
6517 ret = c_parser_cast_expression (parser, NULL);
6518 restore_extension_diagnostics (ext);
6519 return ret;
6520 case RID_REALPART:
6521 c_parser_consume_token (parser);
6522 exp_loc = c_parser_peek_token (parser)->location;
6523 op = c_parser_cast_expression (parser, NULL);
6524 op = default_function_array_conversion (exp_loc, op);
6525 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
6526 case RID_IMAGPART:
6527 c_parser_consume_token (parser);
6528 exp_loc = c_parser_peek_token (parser)->location;
6529 op = c_parser_cast_expression (parser, NULL);
6530 op = default_function_array_conversion (exp_loc, op);
6531 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
6532 case RID_TRANSACTION_ATOMIC:
6533 case RID_TRANSACTION_RELAXED:
6534 return c_parser_transaction_expression (parser,
6535 c_parser_peek_token (parser)->keyword);
6536 default:
6537 return c_parser_postfix_expression (parser);
6539 default:
6540 return c_parser_postfix_expression (parser);
6544 /* Parse a sizeof expression. */
6546 static struct c_expr
6547 c_parser_sizeof_expression (c_parser *parser)
6549 struct c_expr expr;
6550 location_t expr_loc;
6551 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
6552 c_parser_consume_token (parser);
6553 c_inhibit_evaluation_warnings++;
6554 in_sizeof++;
6555 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6556 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6558 /* Either sizeof ( type-name ) or sizeof unary-expression
6559 starting with a compound literal. */
6560 struct c_type_name *type_name;
6561 c_parser_consume_token (parser);
6562 expr_loc = c_parser_peek_token (parser)->location;
6563 type_name = c_parser_type_name (parser);
6564 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6565 if (type_name == NULL)
6567 struct c_expr ret;
6568 c_inhibit_evaluation_warnings--;
6569 in_sizeof--;
6570 ret.value = error_mark_node;
6571 ret.original_code = ERROR_MARK;
6572 ret.original_type = NULL;
6573 return ret;
6575 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6577 expr = c_parser_postfix_expression_after_paren_type (parser,
6578 type_name,
6579 expr_loc);
6580 goto sizeof_expr;
6582 /* sizeof ( type-name ). */
6583 c_inhibit_evaluation_warnings--;
6584 in_sizeof--;
6585 return c_expr_sizeof_type (expr_loc, type_name);
6587 else
6589 expr_loc = c_parser_peek_token (parser)->location;
6590 expr = c_parser_unary_expression (parser);
6591 sizeof_expr:
6592 c_inhibit_evaluation_warnings--;
6593 in_sizeof--;
6594 mark_exp_read (expr.value);
6595 if (TREE_CODE (expr.value) == COMPONENT_REF
6596 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
6597 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
6598 return c_expr_sizeof_expr (expr_loc, expr);
6602 /* Parse an alignof expression. */
6604 static struct c_expr
6605 c_parser_alignof_expression (c_parser *parser)
6607 struct c_expr expr;
6608 location_t loc = c_parser_peek_token (parser)->location;
6609 tree alignof_spelling = c_parser_peek_token (parser)->value;
6610 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
6611 bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
6612 "_Alignof") == 0;
6613 /* A diagnostic is not required for the use of this identifier in
6614 the implementation namespace; only diagnose it for the C11
6615 spelling because of existing code using the other spellings. */
6616 if (!flag_isoc11 && is_c11_alignof)
6618 if (flag_isoc99)
6619 pedwarn (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
6620 alignof_spelling);
6621 else
6622 pedwarn (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
6623 alignof_spelling);
6625 c_parser_consume_token (parser);
6626 c_inhibit_evaluation_warnings++;
6627 in_alignof++;
6628 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6629 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6631 /* Either __alignof__ ( type-name ) or __alignof__
6632 unary-expression starting with a compound literal. */
6633 location_t loc;
6634 struct c_type_name *type_name;
6635 struct c_expr ret;
6636 c_parser_consume_token (parser);
6637 loc = c_parser_peek_token (parser)->location;
6638 type_name = c_parser_type_name (parser);
6639 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6640 if (type_name == NULL)
6642 struct c_expr ret;
6643 c_inhibit_evaluation_warnings--;
6644 in_alignof--;
6645 ret.value = error_mark_node;
6646 ret.original_code = ERROR_MARK;
6647 ret.original_type = NULL;
6648 return ret;
6650 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6652 expr = c_parser_postfix_expression_after_paren_type (parser,
6653 type_name,
6654 loc);
6655 goto alignof_expr;
6657 /* alignof ( type-name ). */
6658 c_inhibit_evaluation_warnings--;
6659 in_alignof--;
6660 ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
6661 NULL, NULL),
6662 false, is_c11_alignof, 1);
6663 ret.original_code = ERROR_MARK;
6664 ret.original_type = NULL;
6665 return ret;
6667 else
6669 struct c_expr ret;
6670 expr = c_parser_unary_expression (parser);
6671 alignof_expr:
6672 mark_exp_read (expr.value);
6673 c_inhibit_evaluation_warnings--;
6674 in_alignof--;
6675 pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
6676 alignof_spelling);
6677 ret.value = c_alignof_expr (loc, expr.value);
6678 ret.original_code = ERROR_MARK;
6679 ret.original_type = NULL;
6680 return ret;
6684 /* Helper function to read arguments of builtins which are interfaces
6685 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6686 others. The name of the builtin is passed using BNAME parameter.
6687 Function returns true if there were no errors while parsing and
6688 stores the arguments in CEXPR_LIST. */
6689 static bool
6690 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6691 vec<c_expr_t, va_gc> **ret_cexpr_list,
6692 bool choose_expr_p)
6694 location_t loc = c_parser_peek_token (parser)->location;
6695 vec<c_expr_t, va_gc> *cexpr_list;
6696 c_expr_t expr;
6697 bool saved_force_folding_builtin_constant_p;
6699 *ret_cexpr_list = NULL;
6700 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6702 error_at (loc, "cannot take address of %qs", bname);
6703 return false;
6706 c_parser_consume_token (parser);
6708 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6710 c_parser_consume_token (parser);
6711 return true;
6714 saved_force_folding_builtin_constant_p
6715 = force_folding_builtin_constant_p;
6716 force_folding_builtin_constant_p |= choose_expr_p;
6717 expr = c_parser_expr_no_commas (parser, NULL);
6718 force_folding_builtin_constant_p
6719 = saved_force_folding_builtin_constant_p;
6720 vec_alloc (cexpr_list, 1);
6721 vec_safe_push (cexpr_list, expr);
6722 while (c_parser_next_token_is (parser, CPP_COMMA))
6724 c_parser_consume_token (parser);
6725 expr = c_parser_expr_no_commas (parser, NULL);
6726 vec_safe_push (cexpr_list, expr);
6729 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6730 return false;
6732 *ret_cexpr_list = cexpr_list;
6733 return true;
6736 /* This represents a single generic-association. */
6738 struct c_generic_association
6740 /* The location of the starting token of the type. */
6741 location_t type_location;
6742 /* The association's type, or NULL_TREE for 'default'. */
6743 tree type;
6744 /* The association's expression. */
6745 struct c_expr expression;
6748 /* Parse a generic-selection. (C11 6.5.1.1).
6750 generic-selection:
6751 _Generic ( assignment-expression , generic-assoc-list )
6753 generic-assoc-list:
6754 generic-association
6755 generic-assoc-list , generic-association
6757 generic-association:
6758 type-name : assignment-expression
6759 default : assignment-expression
6762 static struct c_expr
6763 c_parser_generic_selection (c_parser *parser)
6765 vec<c_generic_association> associations = vNULL;
6766 struct c_expr selector, error_expr;
6767 tree selector_type;
6768 struct c_generic_association matched_assoc;
6769 bool match_found = false;
6770 location_t generic_loc, selector_loc;
6772 error_expr.original_code = ERROR_MARK;
6773 error_expr.original_type = NULL;
6774 error_expr.value = error_mark_node;
6775 matched_assoc.type_location = UNKNOWN_LOCATION;
6776 matched_assoc.type = NULL_TREE;
6777 matched_assoc.expression = error_expr;
6779 gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
6780 generic_loc = c_parser_peek_token (parser)->location;
6781 c_parser_consume_token (parser);
6782 if (!flag_isoc11)
6784 if (flag_isoc99)
6785 pedwarn (generic_loc, OPT_Wpedantic,
6786 "ISO C99 does not support %<_Generic%>");
6787 else
6788 pedwarn (generic_loc, OPT_Wpedantic,
6789 "ISO C90 does not support %<_Generic%>");
6792 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6793 return error_expr;
6795 c_inhibit_evaluation_warnings++;
6796 selector_loc = c_parser_peek_token (parser)->location;
6797 selector = c_parser_expr_no_commas (parser, NULL);
6798 selector = default_function_array_conversion (selector_loc, selector);
6799 c_inhibit_evaluation_warnings--;
6801 if (selector.value == error_mark_node)
6803 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6804 return selector;
6806 selector_type = TREE_TYPE (selector.value);
6807 /* In ISO C terms, rvalues (including the controlling expression of
6808 _Generic) do not have qualified types. */
6809 if (TREE_CODE (selector_type) != ARRAY_TYPE)
6810 selector_type = TYPE_MAIN_VARIANT (selector_type);
6811 /* In ISO C terms, _Noreturn is not part of the type of expressions
6812 such as &abort, but in GCC it is represented internally as a type
6813 qualifier. */
6814 if (FUNCTION_POINTER_TYPE_P (selector_type)
6815 && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
6816 selector_type
6817 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
6819 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6821 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6822 return error_expr;
6825 while (1)
6827 struct c_generic_association assoc, *iter;
6828 unsigned int ix;
6829 c_token *token = c_parser_peek_token (parser);
6831 assoc.type_location = token->location;
6832 if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
6834 c_parser_consume_token (parser);
6835 assoc.type = NULL_TREE;
6837 else
6839 struct c_type_name *type_name;
6841 type_name = c_parser_type_name (parser);
6842 if (type_name == NULL)
6844 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6845 goto error_exit;
6847 assoc.type = groktypename (type_name, NULL, NULL);
6848 if (assoc.type == error_mark_node)
6850 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6851 goto error_exit;
6854 if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
6855 error_at (assoc.type_location,
6856 "%<_Generic%> association has function type");
6857 else if (!COMPLETE_TYPE_P (assoc.type))
6858 error_at (assoc.type_location,
6859 "%<_Generic%> association has incomplete type");
6861 if (variably_modified_type_p (assoc.type, NULL_TREE))
6862 error_at (assoc.type_location,
6863 "%<_Generic%> association has "
6864 "variable length type");
6867 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6869 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6870 goto error_exit;
6873 assoc.expression = c_parser_expr_no_commas (parser, NULL);
6874 if (assoc.expression.value == error_mark_node)
6876 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6877 goto error_exit;
6880 for (ix = 0; associations.iterate (ix, &iter); ++ix)
6882 if (assoc.type == NULL_TREE)
6884 if (iter->type == NULL_TREE)
6886 error_at (assoc.type_location,
6887 "duplicate %<default%> case in %<_Generic%>");
6888 inform (iter->type_location, "original %<default%> is here");
6891 else if (iter->type != NULL_TREE)
6893 if (comptypes (assoc.type, iter->type))
6895 error_at (assoc.type_location,
6896 "%<_Generic%> specifies two compatible types");
6897 inform (iter->type_location, "compatible type is here");
6902 if (assoc.type == NULL_TREE)
6904 if (!match_found)
6906 matched_assoc = assoc;
6907 match_found = true;
6910 else if (comptypes (assoc.type, selector_type))
6912 if (!match_found || matched_assoc.type == NULL_TREE)
6914 matched_assoc = assoc;
6915 match_found = true;
6917 else
6919 error_at (assoc.type_location,
6920 "%<_Generic> selector matches multiple associations");
6921 inform (matched_assoc.type_location,
6922 "other match is here");
6926 associations.safe_push (assoc);
6928 if (c_parser_peek_token (parser)->type != CPP_COMMA)
6929 break;
6930 c_parser_consume_token (parser);
6933 associations.release ();
6935 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6937 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6938 return error_expr;
6941 if (!match_found)
6943 error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
6944 "compatible with any association",
6945 selector_type);
6946 return error_expr;
6949 return matched_assoc.expression;
6951 error_exit:
6952 associations.release ();
6953 return error_expr;
6956 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6958 postfix-expression:
6959 primary-expression
6960 postfix-expression [ expression ]
6961 postfix-expression ( argument-expression-list[opt] )
6962 postfix-expression . identifier
6963 postfix-expression -> identifier
6964 postfix-expression ++
6965 postfix-expression --
6966 ( type-name ) { initializer-list }
6967 ( type-name ) { initializer-list , }
6969 argument-expression-list:
6970 argument-expression
6971 argument-expression-list , argument-expression
6973 primary-expression:
6974 identifier
6975 constant
6976 string-literal
6977 ( expression )
6978 generic-selection
6980 GNU extensions:
6982 primary-expression:
6983 __func__
6984 (treated as a keyword in GNU C)
6985 __FUNCTION__
6986 __PRETTY_FUNCTION__
6987 ( compound-statement )
6988 __builtin_va_arg ( assignment-expression , type-name )
6989 __builtin_offsetof ( type-name , offsetof-member-designator )
6990 __builtin_choose_expr ( assignment-expression ,
6991 assignment-expression ,
6992 assignment-expression )
6993 __builtin_types_compatible_p ( type-name , type-name )
6994 __builtin_complex ( assignment-expression , assignment-expression )
6995 __builtin_shuffle ( assignment-expression , assignment-expression )
6996 __builtin_shuffle ( assignment-expression ,
6997 assignment-expression ,
6998 assignment-expression, )
7000 offsetof-member-designator:
7001 identifier
7002 offsetof-member-designator . identifier
7003 offsetof-member-designator [ expression ]
7005 Objective-C:
7007 primary-expression:
7008 [ objc-receiver objc-message-args ]
7009 @selector ( objc-selector-arg )
7010 @protocol ( identifier )
7011 @encode ( type-name )
7012 objc-string-literal
7013 Classname . identifier
7016 static struct c_expr
7017 c_parser_postfix_expression (c_parser *parser)
7019 struct c_expr expr, e1;
7020 struct c_type_name *t1, *t2;
7021 location_t loc = c_parser_peek_token (parser)->location;;
7022 expr.original_code = ERROR_MARK;
7023 expr.original_type = NULL;
7024 switch (c_parser_peek_token (parser)->type)
7026 case CPP_NUMBER:
7027 expr.value = c_parser_peek_token (parser)->value;
7028 loc = c_parser_peek_token (parser)->location;
7029 c_parser_consume_token (parser);
7030 if (TREE_CODE (expr.value) == FIXED_CST
7031 && !targetm.fixed_point_supported_p ())
7033 error_at (loc, "fixed-point types not supported for this target");
7034 expr.value = error_mark_node;
7036 break;
7037 case CPP_CHAR:
7038 case CPP_CHAR16:
7039 case CPP_CHAR32:
7040 case CPP_WCHAR:
7041 expr.value = c_parser_peek_token (parser)->value;
7042 c_parser_consume_token (parser);
7043 break;
7044 case CPP_STRING:
7045 case CPP_STRING16:
7046 case CPP_STRING32:
7047 case CPP_WSTRING:
7048 case CPP_UTF8STRING:
7049 expr.value = c_parser_peek_token (parser)->value;
7050 expr.original_code = STRING_CST;
7051 c_parser_consume_token (parser);
7052 break;
7053 case CPP_OBJC_STRING:
7054 gcc_assert (c_dialect_objc ());
7055 expr.value
7056 = objc_build_string_object (c_parser_peek_token (parser)->value);
7057 c_parser_consume_token (parser);
7058 break;
7059 case CPP_NAME:
7060 switch (c_parser_peek_token (parser)->id_kind)
7062 case C_ID_ID:
7064 tree id = c_parser_peek_token (parser)->value;
7065 c_parser_consume_token (parser);
7066 expr.value = build_external_ref (loc, id,
7067 (c_parser_peek_token (parser)->type
7068 == CPP_OPEN_PAREN),
7069 &expr.original_type);
7070 break;
7072 case C_ID_CLASSNAME:
7074 /* Here we parse the Objective-C 2.0 Class.name dot
7075 syntax. */
7076 tree class_name = c_parser_peek_token (parser)->value;
7077 tree component;
7078 c_parser_consume_token (parser);
7079 gcc_assert (c_dialect_objc ());
7080 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7082 expr.value = error_mark_node;
7083 break;
7085 if (c_parser_next_token_is_not (parser, CPP_NAME))
7087 c_parser_error (parser, "expected identifier");
7088 expr.value = error_mark_node;
7089 break;
7091 component = c_parser_peek_token (parser)->value;
7092 c_parser_consume_token (parser);
7093 expr.value = objc_build_class_component_ref (class_name,
7094 component);
7095 break;
7097 default:
7098 c_parser_error (parser, "expected expression");
7099 expr.value = error_mark_node;
7100 break;
7102 break;
7103 case CPP_OPEN_PAREN:
7104 /* A parenthesized expression, statement expression or compound
7105 literal. */
7106 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7108 /* A statement expression. */
7109 tree stmt;
7110 location_t brace_loc;
7111 c_parser_consume_token (parser);
7112 brace_loc = c_parser_peek_token (parser)->location;
7113 c_parser_consume_token (parser);
7114 if (!building_stmt_list_p ())
7116 error_at (loc, "braced-group within expression allowed "
7117 "only inside a function");
7118 parser->error = true;
7119 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7120 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7121 expr.value = error_mark_node;
7122 break;
7124 stmt = c_begin_stmt_expr ();
7125 c_parser_compound_statement_nostart (parser);
7126 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7127 "expected %<)%>");
7128 pedwarn (loc, OPT_Wpedantic,
7129 "ISO C forbids braced-groups within expressions");
7130 expr.value = c_finish_stmt_expr (brace_loc, stmt);
7131 mark_exp_read (expr.value);
7133 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7135 /* A compound literal. ??? Can we actually get here rather
7136 than going directly to
7137 c_parser_postfix_expression_after_paren_type from
7138 elsewhere? */
7139 location_t loc;
7140 struct c_type_name *type_name;
7141 c_parser_consume_token (parser);
7142 loc = c_parser_peek_token (parser)->location;
7143 type_name = c_parser_type_name (parser);
7144 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7145 "expected %<)%>");
7146 if (type_name == NULL)
7148 expr.value = error_mark_node;
7150 else
7151 expr = c_parser_postfix_expression_after_paren_type (parser,
7152 type_name,
7153 loc);
7155 else
7157 /* A parenthesized expression. */
7158 c_parser_consume_token (parser);
7159 expr = c_parser_expression (parser);
7160 if (TREE_CODE (expr.value) == MODIFY_EXPR)
7161 TREE_NO_WARNING (expr.value) = 1;
7162 if (expr.original_code != C_MAYBE_CONST_EXPR)
7163 expr.original_code = ERROR_MARK;
7164 /* Don't change EXPR.ORIGINAL_TYPE. */
7165 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7166 "expected %<)%>");
7168 break;
7169 case CPP_KEYWORD:
7170 switch (c_parser_peek_token (parser)->keyword)
7172 case RID_FUNCTION_NAME:
7173 case RID_PRETTY_FUNCTION_NAME:
7174 case RID_C99_FUNCTION_NAME:
7175 expr.value = fname_decl (loc,
7176 c_parser_peek_token (parser)->keyword,
7177 c_parser_peek_token (parser)->value);
7178 c_parser_consume_token (parser);
7179 break;
7180 case RID_VA_ARG:
7181 c_parser_consume_token (parser);
7182 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7184 expr.value = error_mark_node;
7185 break;
7187 e1 = c_parser_expr_no_commas (parser, NULL);
7188 mark_exp_read (e1.value);
7189 e1.value = c_fully_fold (e1.value, false, NULL);
7190 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7192 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7193 expr.value = error_mark_node;
7194 break;
7196 loc = c_parser_peek_token (parser)->location;
7197 t1 = c_parser_type_name (parser);
7198 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7199 "expected %<)%>");
7200 if (t1 == NULL)
7202 expr.value = error_mark_node;
7204 else
7206 tree type_expr = NULL_TREE;
7207 expr.value = c_build_va_arg (loc, e1.value,
7208 groktypename (t1, &type_expr, NULL));
7209 if (type_expr)
7211 expr.value = build2 (C_MAYBE_CONST_EXPR,
7212 TREE_TYPE (expr.value), type_expr,
7213 expr.value);
7214 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
7217 break;
7218 case RID_OFFSETOF:
7219 c_parser_consume_token (parser);
7220 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7222 expr.value = error_mark_node;
7223 break;
7225 t1 = c_parser_type_name (parser);
7226 if (t1 == NULL)
7227 parser->error = true;
7228 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7229 gcc_assert (parser->error);
7230 if (parser->error)
7232 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7233 expr.value = error_mark_node;
7234 break;
7238 tree type = groktypename (t1, NULL, NULL);
7239 tree offsetof_ref;
7240 if (type == error_mark_node)
7241 offsetof_ref = error_mark_node;
7242 else
7244 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
7245 SET_EXPR_LOCATION (offsetof_ref, loc);
7247 /* Parse the second argument to __builtin_offsetof. We
7248 must have one identifier, and beyond that we want to
7249 accept sub structure and sub array references. */
7250 if (c_parser_next_token_is (parser, CPP_NAME))
7252 offsetof_ref = build_component_ref
7253 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
7254 c_parser_consume_token (parser);
7255 while (c_parser_next_token_is (parser, CPP_DOT)
7256 || c_parser_next_token_is (parser,
7257 CPP_OPEN_SQUARE)
7258 || c_parser_next_token_is (parser,
7259 CPP_DEREF))
7261 if (c_parser_next_token_is (parser, CPP_DEREF))
7263 loc = c_parser_peek_token (parser)->location;
7264 offsetof_ref = build_array_ref (loc,
7265 offsetof_ref,
7266 integer_zero_node);
7267 goto do_dot;
7269 else if (c_parser_next_token_is (parser, CPP_DOT))
7271 do_dot:
7272 c_parser_consume_token (parser);
7273 if (c_parser_next_token_is_not (parser,
7274 CPP_NAME))
7276 c_parser_error (parser, "expected identifier");
7277 break;
7279 offsetof_ref = build_component_ref
7280 (loc, offsetof_ref,
7281 c_parser_peek_token (parser)->value);
7282 c_parser_consume_token (parser);
7284 else
7286 struct c_expr ce;
7287 tree idx;
7288 loc = c_parser_peek_token (parser)->location;
7289 c_parser_consume_token (parser);
7290 ce = c_parser_expression (parser);
7291 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
7292 idx = ce.value;
7293 idx = c_fully_fold (idx, false, NULL);
7294 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7295 "expected %<]%>");
7296 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
7300 else
7301 c_parser_error (parser, "expected identifier");
7302 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7303 "expected %<)%>");
7304 expr.value = fold_offsetof (offsetof_ref);
7306 break;
7307 case RID_CHOOSE_EXPR:
7309 vec<c_expr_t, va_gc> *cexpr_list;
7310 c_expr_t *e1_p, *e2_p, *e3_p;
7311 tree c;
7313 c_parser_consume_token (parser);
7314 if (!c_parser_get_builtin_args (parser,
7315 "__builtin_choose_expr",
7316 &cexpr_list, true))
7318 expr.value = error_mark_node;
7319 break;
7322 if (vec_safe_length (cexpr_list) != 3)
7324 error_at (loc, "wrong number of arguments to "
7325 "%<__builtin_choose_expr%>");
7326 expr.value = error_mark_node;
7327 break;
7330 e1_p = &(*cexpr_list)[0];
7331 e2_p = &(*cexpr_list)[1];
7332 e3_p = &(*cexpr_list)[2];
7334 c = e1_p->value;
7335 mark_exp_read (e2_p->value);
7336 mark_exp_read (e3_p->value);
7337 if (TREE_CODE (c) != INTEGER_CST
7338 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
7339 error_at (loc,
7340 "first argument to %<__builtin_choose_expr%> not"
7341 " a constant");
7342 constant_expression_warning (c);
7343 expr = integer_zerop (c) ? *e3_p : *e2_p;
7344 break;
7346 case RID_TYPES_COMPATIBLE_P:
7347 c_parser_consume_token (parser);
7348 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7350 expr.value = error_mark_node;
7351 break;
7353 t1 = c_parser_type_name (parser);
7354 if (t1 == NULL)
7356 expr.value = error_mark_node;
7357 break;
7359 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7361 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7362 expr.value = error_mark_node;
7363 break;
7365 t2 = c_parser_type_name (parser);
7366 if (t2 == NULL)
7368 expr.value = error_mark_node;
7369 break;
7371 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7372 "expected %<)%>");
7374 tree e1, e2;
7375 e1 = groktypename (t1, NULL, NULL);
7376 e2 = groktypename (t2, NULL, NULL);
7377 if (e1 == error_mark_node || e2 == error_mark_node)
7379 expr.value = error_mark_node;
7380 break;
7383 e1 = TYPE_MAIN_VARIANT (e1);
7384 e2 = TYPE_MAIN_VARIANT (e2);
7386 expr.value
7387 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
7389 break;
7390 case RID_BUILTIN_COMPLEX:
7392 vec<c_expr_t, va_gc> *cexpr_list;
7393 c_expr_t *e1_p, *e2_p;
7395 c_parser_consume_token (parser);
7396 if (!c_parser_get_builtin_args (parser,
7397 "__builtin_complex",
7398 &cexpr_list, false))
7400 expr.value = error_mark_node;
7401 break;
7404 if (vec_safe_length (cexpr_list) != 2)
7406 error_at (loc, "wrong number of arguments to "
7407 "%<__builtin_complex%>");
7408 expr.value = error_mark_node;
7409 break;
7412 e1_p = &(*cexpr_list)[0];
7413 e2_p = &(*cexpr_list)[1];
7415 *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
7416 if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
7417 e1_p->value = convert (TREE_TYPE (e1_p->value),
7418 TREE_OPERAND (e1_p->value, 0));
7419 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7420 if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
7421 e2_p->value = convert (TREE_TYPE (e2_p->value),
7422 TREE_OPERAND (e2_p->value, 0));
7423 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7424 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7425 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
7426 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
7428 error_at (loc, "%<__builtin_complex%> operand "
7429 "not of real binary floating-point type");
7430 expr.value = error_mark_node;
7431 break;
7433 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
7434 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
7436 error_at (loc,
7437 "%<__builtin_complex%> operands of different types");
7438 expr.value = error_mark_node;
7439 break;
7441 if (!flag_isoc99)
7442 pedwarn (loc, OPT_Wpedantic,
7443 "ISO C90 does not support complex types");
7444 expr.value = build2 (COMPLEX_EXPR,
7445 build_complex_type
7446 (TYPE_MAIN_VARIANT
7447 (TREE_TYPE (e1_p->value))),
7448 e1_p->value, e2_p->value);
7449 break;
7451 case RID_BUILTIN_SHUFFLE:
7453 vec<c_expr_t, va_gc> *cexpr_list;
7454 unsigned int i;
7455 c_expr_t *p;
7457 c_parser_consume_token (parser);
7458 if (!c_parser_get_builtin_args (parser,
7459 "__builtin_shuffle",
7460 &cexpr_list, false))
7462 expr.value = error_mark_node;
7463 break;
7466 FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
7467 *p = convert_lvalue_to_rvalue (loc, *p, true, true);
7469 if (vec_safe_length (cexpr_list) == 2)
7470 expr.value =
7471 c_build_vec_perm_expr
7472 (loc, (*cexpr_list)[0].value,
7473 NULL_TREE, (*cexpr_list)[1].value);
7475 else if (vec_safe_length (cexpr_list) == 3)
7476 expr.value =
7477 c_build_vec_perm_expr
7478 (loc, (*cexpr_list)[0].value,
7479 (*cexpr_list)[1].value,
7480 (*cexpr_list)[2].value);
7481 else
7483 error_at (loc, "wrong number of arguments to "
7484 "%<__builtin_shuffle%>");
7485 expr.value = error_mark_node;
7487 break;
7489 case RID_AT_SELECTOR:
7490 gcc_assert (c_dialect_objc ());
7491 c_parser_consume_token (parser);
7492 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7494 expr.value = error_mark_node;
7495 break;
7498 tree sel = c_parser_objc_selector_arg (parser);
7499 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7500 "expected %<)%>");
7501 expr.value = objc_build_selector_expr (loc, sel);
7503 break;
7504 case RID_AT_PROTOCOL:
7505 gcc_assert (c_dialect_objc ());
7506 c_parser_consume_token (parser);
7507 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7509 expr.value = error_mark_node;
7510 break;
7512 if (c_parser_next_token_is_not (parser, CPP_NAME))
7514 c_parser_error (parser, "expected identifier");
7515 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7516 expr.value = error_mark_node;
7517 break;
7520 tree id = c_parser_peek_token (parser)->value;
7521 c_parser_consume_token (parser);
7522 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7523 "expected %<)%>");
7524 expr.value = objc_build_protocol_expr (id);
7526 break;
7527 case RID_AT_ENCODE:
7528 /* Extension to support C-structures in the archiver. */
7529 gcc_assert (c_dialect_objc ());
7530 c_parser_consume_token (parser);
7531 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7533 expr.value = error_mark_node;
7534 break;
7536 t1 = c_parser_type_name (parser);
7537 if (t1 == NULL)
7539 expr.value = error_mark_node;
7540 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7541 break;
7543 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7544 "expected %<)%>");
7546 tree type = groktypename (t1, NULL, NULL);
7547 expr.value = objc_build_encode_expr (type);
7549 break;
7550 case RID_GENERIC:
7551 expr = c_parser_generic_selection (parser);
7552 break;
7553 case RID_CILK_SPAWN:
7554 c_parser_consume_token (parser);
7555 if (!flag_cilkplus)
7557 error_at (loc, "-fcilkplus must be enabled to use "
7558 "%<_Cilk_spawn%>");
7559 expr = c_parser_postfix_expression (parser);
7560 expr.value = error_mark_node;
7562 else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7564 error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
7565 "are not permitted");
7566 /* Now flush out all the _Cilk_spawns. */
7567 while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7568 c_parser_consume_token (parser);
7569 expr = c_parser_postfix_expression (parser);
7571 else
7573 expr = c_parser_postfix_expression (parser);
7574 expr.value = build_cilk_spawn (loc, expr.value);
7576 break;
7577 default:
7578 c_parser_error (parser, "expected expression");
7579 expr.value = error_mark_node;
7580 break;
7582 break;
7583 case CPP_OPEN_SQUARE:
7584 if (c_dialect_objc ())
7586 tree receiver, args;
7587 c_parser_consume_token (parser);
7588 receiver = c_parser_objc_receiver (parser);
7589 args = c_parser_objc_message_args (parser);
7590 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7591 "expected %<]%>");
7592 expr.value = objc_build_message_expr (receiver, args);
7593 break;
7595 /* Else fall through to report error. */
7596 default:
7597 c_parser_error (parser, "expected expression");
7598 expr.value = error_mark_node;
7599 break;
7601 return c_parser_postfix_expression_after_primary (parser, loc, expr);
7604 /* Parse a postfix expression after a parenthesized type name: the
7605 brace-enclosed initializer of a compound literal, possibly followed
7606 by some postfix operators. This is separate because it is not
7607 possible to tell until after the type name whether a cast
7608 expression has a cast or a compound literal, or whether the operand
7609 of sizeof is a parenthesized type name or starts with a compound
7610 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7611 location of the first token after the parentheses around the type
7612 name. */
7614 static struct c_expr
7615 c_parser_postfix_expression_after_paren_type (c_parser *parser,
7616 struct c_type_name *type_name,
7617 location_t type_loc)
7619 tree type;
7620 struct c_expr init;
7621 bool non_const;
7622 struct c_expr expr;
7623 location_t start_loc;
7624 tree type_expr = NULL_TREE;
7625 bool type_expr_const = true;
7626 check_compound_literal_type (type_loc, type_name);
7627 start_init (NULL_TREE, NULL, 0);
7628 type = groktypename (type_name, &type_expr, &type_expr_const);
7629 start_loc = c_parser_peek_token (parser)->location;
7630 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
7632 error_at (type_loc, "compound literal has variable size");
7633 type = error_mark_node;
7635 init = c_parser_braced_init (parser, type, false);
7636 finish_init ();
7637 maybe_warn_string_init (type_loc, type, init);
7639 if (type != error_mark_node
7640 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
7641 && current_function_decl)
7643 error ("compound literal qualified by address-space qualifier");
7644 type = error_mark_node;
7647 if (!flag_isoc99)
7648 pedwarn (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
7649 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
7650 ? CONSTRUCTOR_NON_CONST (init.value)
7651 : init.original_code == C_MAYBE_CONST_EXPR);
7652 non_const |= !type_expr_const;
7653 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
7654 expr.original_code = ERROR_MARK;
7655 expr.original_type = NULL;
7656 if (type_expr)
7658 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
7660 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
7661 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
7663 else
7665 gcc_assert (!non_const);
7666 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
7667 type_expr, expr.value);
7670 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
7673 /* Callback function for sizeof_pointer_memaccess_warning to compare
7674 types. */
7676 static bool
7677 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
7679 return comptypes (type1, type2) == 1;
7682 /* Parse a postfix expression after the initial primary or compound
7683 literal; that is, parse a series of postfix operators.
7685 EXPR_LOC is the location of the primary expression. */
7687 static struct c_expr
7688 c_parser_postfix_expression_after_primary (c_parser *parser,
7689 location_t expr_loc,
7690 struct c_expr expr)
7692 struct c_expr orig_expr;
7693 tree ident, idx;
7694 location_t sizeof_arg_loc[3];
7695 tree sizeof_arg[3];
7696 unsigned int i;
7697 vec<tree, va_gc> *exprlist;
7698 vec<tree, va_gc> *origtypes = NULL;
7699 vec<location_t> arg_loc = vNULL;
7701 while (true)
7703 location_t op_loc = c_parser_peek_token (parser)->location;
7704 switch (c_parser_peek_token (parser)->type)
7706 case CPP_OPEN_SQUARE:
7707 /* Array reference. */
7708 c_parser_consume_token (parser);
7709 if (flag_cilkplus
7710 && c_parser_peek_token (parser)->type == CPP_COLON)
7711 /* If we are here, then we have something like this:
7712 Array [ : ]
7714 expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE,
7715 expr.value);
7716 else
7718 idx = c_parser_expression (parser).value;
7719 /* Here we have 3 options:
7720 1. Array [EXPR] -- Normal Array call.
7721 2. Array [EXPR : EXPR] -- Array notation without stride.
7722 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7724 For 1, we just handle it just like a normal array expression.
7725 For 2 and 3 we handle it like we handle array notations. The
7726 idx value we have above becomes the initial/start index.
7728 if (flag_cilkplus
7729 && c_parser_peek_token (parser)->type == CPP_COLON)
7730 expr.value = c_parser_array_notation (expr_loc, parser, idx,
7731 expr.value);
7732 else
7734 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7735 "expected %<]%>");
7736 expr.value = build_array_ref (op_loc, expr.value, idx);
7739 expr.original_code = ERROR_MARK;
7740 expr.original_type = NULL;
7741 break;
7742 case CPP_OPEN_PAREN:
7743 /* Function call. */
7744 c_parser_consume_token (parser);
7745 for (i = 0; i < 3; i++)
7747 sizeof_arg[i] = NULL_TREE;
7748 sizeof_arg_loc[i] = UNKNOWN_LOCATION;
7750 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7751 exprlist = NULL;
7752 else
7753 exprlist = c_parser_expr_list (parser, true, false, &origtypes,
7754 sizeof_arg_loc, sizeof_arg,
7755 &arg_loc);
7756 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7757 "expected %<)%>");
7758 orig_expr = expr;
7759 mark_exp_read (expr.value);
7760 if (warn_sizeof_pointer_memaccess)
7761 sizeof_pointer_memaccess_warning (sizeof_arg_loc,
7762 expr.value, exprlist,
7763 sizeof_arg,
7764 sizeof_ptr_memacc_comptypes);
7765 expr.value
7766 = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
7767 exprlist, origtypes);
7768 expr.original_code = ERROR_MARK;
7769 if (TREE_CODE (expr.value) == INTEGER_CST
7770 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
7771 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
7772 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
7773 expr.original_code = C_MAYBE_CONST_EXPR;
7774 expr.original_type = NULL;
7775 if (exprlist)
7777 release_tree_vector (exprlist);
7778 release_tree_vector (origtypes);
7780 arg_loc.release ();
7781 break;
7782 case CPP_DOT:
7783 /* Structure element reference. */
7784 c_parser_consume_token (parser);
7785 expr = default_function_array_conversion (expr_loc, expr);
7786 if (c_parser_next_token_is (parser, CPP_NAME))
7787 ident = c_parser_peek_token (parser)->value;
7788 else
7790 c_parser_error (parser, "expected identifier");
7791 expr.value = error_mark_node;
7792 expr.original_code = ERROR_MARK;
7793 expr.original_type = NULL;
7794 return expr;
7796 c_parser_consume_token (parser);
7797 expr.value = build_component_ref (op_loc, expr.value, ident);
7798 expr.original_code = ERROR_MARK;
7799 if (TREE_CODE (expr.value) != COMPONENT_REF)
7800 expr.original_type = NULL;
7801 else
7803 /* Remember the original type of a bitfield. */
7804 tree field = TREE_OPERAND (expr.value, 1);
7805 if (TREE_CODE (field) != FIELD_DECL)
7806 expr.original_type = NULL;
7807 else
7808 expr.original_type = DECL_BIT_FIELD_TYPE (field);
7810 break;
7811 case CPP_DEREF:
7812 /* Structure element reference. */
7813 c_parser_consume_token (parser);
7814 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
7815 if (c_parser_next_token_is (parser, CPP_NAME))
7816 ident = c_parser_peek_token (parser)->value;
7817 else
7819 c_parser_error (parser, "expected identifier");
7820 expr.value = error_mark_node;
7821 expr.original_code = ERROR_MARK;
7822 expr.original_type = NULL;
7823 return expr;
7825 c_parser_consume_token (parser);
7826 expr.value = build_component_ref (op_loc,
7827 build_indirect_ref (op_loc,
7828 expr.value,
7829 RO_ARROW),
7830 ident);
7831 expr.original_code = ERROR_MARK;
7832 if (TREE_CODE (expr.value) != COMPONENT_REF)
7833 expr.original_type = NULL;
7834 else
7836 /* Remember the original type of a bitfield. */
7837 tree field = TREE_OPERAND (expr.value, 1);
7838 if (TREE_CODE (field) != FIELD_DECL)
7839 expr.original_type = NULL;
7840 else
7841 expr.original_type = DECL_BIT_FIELD_TYPE (field);
7843 break;
7844 case CPP_PLUS_PLUS:
7845 /* Postincrement. */
7846 c_parser_consume_token (parser);
7847 /* If the expressions have array notations, we expand them. */
7848 if (flag_cilkplus
7849 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
7850 expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr);
7851 else
7853 expr = default_function_array_read_conversion (expr_loc, expr);
7854 expr.value = build_unary_op (op_loc,
7855 POSTINCREMENT_EXPR, expr.value, 0);
7857 expr.original_code = ERROR_MARK;
7858 expr.original_type = NULL;
7859 break;
7860 case CPP_MINUS_MINUS:
7861 /* Postdecrement. */
7862 c_parser_consume_token (parser);
7863 /* If the expressions have array notations, we expand them. */
7864 if (flag_cilkplus
7865 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
7866 expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr);
7867 else
7869 expr = default_function_array_read_conversion (expr_loc, expr);
7870 expr.value = build_unary_op (op_loc,
7871 POSTDECREMENT_EXPR, expr.value, 0);
7873 expr.original_code = ERROR_MARK;
7874 expr.original_type = NULL;
7875 break;
7876 default:
7877 return expr;
7882 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7884 expression:
7885 assignment-expression
7886 expression , assignment-expression
7889 static struct c_expr
7890 c_parser_expression (c_parser *parser)
7892 location_t tloc = c_parser_peek_token (parser)->location;
7893 struct c_expr expr;
7894 expr = c_parser_expr_no_commas (parser, NULL);
7895 if (c_parser_next_token_is (parser, CPP_COMMA))
7896 expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
7897 while (c_parser_next_token_is (parser, CPP_COMMA))
7899 struct c_expr next;
7900 tree lhsval;
7901 location_t loc = c_parser_peek_token (parser)->location;
7902 location_t expr_loc;
7903 c_parser_consume_token (parser);
7904 expr_loc = c_parser_peek_token (parser)->location;
7905 lhsval = expr.value;
7906 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
7907 lhsval = TREE_OPERAND (lhsval, 1);
7908 if (DECL_P (lhsval) || handled_component_p (lhsval))
7909 mark_exp_read (lhsval);
7910 next = c_parser_expr_no_commas (parser, NULL);
7911 next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
7912 expr.value = build_compound_expr (loc, expr.value, next.value);
7913 expr.original_code = COMPOUND_EXPR;
7914 expr.original_type = next.original_type;
7916 return expr;
7919 /* Parse an expression and convert functions or arrays to pointers and
7920 lvalues to rvalues. */
7922 static struct c_expr
7923 c_parser_expression_conv (c_parser *parser)
7925 struct c_expr expr;
7926 location_t loc = c_parser_peek_token (parser)->location;
7927 expr = c_parser_expression (parser);
7928 expr = convert_lvalue_to_rvalue (loc, expr, true, false);
7929 return expr;
7932 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7933 functions and arrays to pointers and lvalues to rvalues. If
7934 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7935 locations of function arguments into this vector.
7937 nonempty-expr-list:
7938 assignment-expression
7939 nonempty-expr-list , assignment-expression
7942 static vec<tree, va_gc> *
7943 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
7944 vec<tree, va_gc> **p_orig_types,
7945 location_t *sizeof_arg_loc, tree *sizeof_arg,
7946 vec<location_t> *locations)
7948 vec<tree, va_gc> *ret;
7949 vec<tree, va_gc> *orig_types;
7950 struct c_expr expr;
7951 location_t loc = c_parser_peek_token (parser)->location;
7952 location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
7953 unsigned int idx = 0;
7955 ret = make_tree_vector ();
7956 if (p_orig_types == NULL)
7957 orig_types = NULL;
7958 else
7959 orig_types = make_tree_vector ();
7961 if (sizeof_arg != NULL
7962 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
7963 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
7964 expr = c_parser_expr_no_commas (parser, NULL);
7965 if (convert_p)
7966 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
7967 if (fold_p)
7968 expr.value = c_fully_fold (expr.value, false, NULL);
7969 ret->quick_push (expr.value);
7970 if (orig_types)
7971 orig_types->quick_push (expr.original_type);
7972 if (locations)
7973 locations->safe_push (loc);
7974 if (sizeof_arg != NULL
7975 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
7976 && expr.original_code == SIZEOF_EXPR)
7978 sizeof_arg[0] = c_last_sizeof_arg;
7979 sizeof_arg_loc[0] = cur_sizeof_arg_loc;
7981 while (c_parser_next_token_is (parser, CPP_COMMA))
7983 c_parser_consume_token (parser);
7984 loc = c_parser_peek_token (parser)->location;
7985 if (sizeof_arg != NULL
7986 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
7987 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
7988 else
7989 cur_sizeof_arg_loc = UNKNOWN_LOCATION;
7990 expr = c_parser_expr_no_commas (parser, NULL);
7991 if (convert_p)
7992 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
7993 if (fold_p)
7994 expr.value = c_fully_fold (expr.value, false, NULL);
7995 vec_safe_push (ret, expr.value);
7996 if (orig_types)
7997 vec_safe_push (orig_types, expr.original_type);
7998 if (locations)
7999 locations->safe_push (loc);
8000 if (++idx < 3
8001 && sizeof_arg != NULL
8002 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8003 && expr.original_code == SIZEOF_EXPR)
8005 sizeof_arg[idx] = c_last_sizeof_arg;
8006 sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
8009 if (orig_types)
8010 *p_orig_types = orig_types;
8011 return ret;
8014 /* Parse Objective-C-specific constructs. */
8016 /* Parse an objc-class-definition.
8018 objc-class-definition:
8019 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8020 objc-class-instance-variables[opt] objc-methodprotolist @end
8021 @implementation identifier objc-superclass[opt]
8022 objc-class-instance-variables[opt]
8023 @interface identifier ( identifier ) objc-protocol-refs[opt]
8024 objc-methodprotolist @end
8025 @interface identifier ( ) objc-protocol-refs[opt]
8026 objc-methodprotolist @end
8027 @implementation identifier ( identifier )
8029 objc-superclass:
8030 : identifier
8032 "@interface identifier (" must start "@interface identifier (
8033 identifier ) ...": objc-methodprotolist in the first production may
8034 not start with a parenthesized identifier as a declarator of a data
8035 definition with no declaration specifiers if the objc-superclass,
8036 objc-protocol-refs and objc-class-instance-variables are omitted. */
8038 static void
8039 c_parser_objc_class_definition (c_parser *parser, tree attributes)
8041 bool iface_p;
8042 tree id1;
8043 tree superclass;
8044 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
8045 iface_p = true;
8046 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
8047 iface_p = false;
8048 else
8049 gcc_unreachable ();
8051 c_parser_consume_token (parser);
8052 if (c_parser_next_token_is_not (parser, CPP_NAME))
8054 c_parser_error (parser, "expected identifier");
8055 return;
8057 id1 = c_parser_peek_token (parser)->value;
8058 c_parser_consume_token (parser);
8059 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8061 /* We have a category or class extension. */
8062 tree id2;
8063 tree proto = NULL_TREE;
8064 c_parser_consume_token (parser);
8065 if (c_parser_next_token_is_not (parser, CPP_NAME))
8067 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8069 /* We have a class extension. */
8070 id2 = NULL_TREE;
8072 else
8074 c_parser_error (parser, "expected identifier or %<)%>");
8075 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8076 return;
8079 else
8081 id2 = c_parser_peek_token (parser)->value;
8082 c_parser_consume_token (parser);
8084 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8085 if (!iface_p)
8087 objc_start_category_implementation (id1, id2);
8088 return;
8090 if (c_parser_next_token_is (parser, CPP_LESS))
8091 proto = c_parser_objc_protocol_refs (parser);
8092 objc_start_category_interface (id1, id2, proto, attributes);
8093 c_parser_objc_methodprotolist (parser);
8094 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8095 objc_finish_interface ();
8096 return;
8098 if (c_parser_next_token_is (parser, CPP_COLON))
8100 c_parser_consume_token (parser);
8101 if (c_parser_next_token_is_not (parser, CPP_NAME))
8103 c_parser_error (parser, "expected identifier");
8104 return;
8106 superclass = c_parser_peek_token (parser)->value;
8107 c_parser_consume_token (parser);
8109 else
8110 superclass = NULL_TREE;
8111 if (iface_p)
8113 tree proto = NULL_TREE;
8114 if (c_parser_next_token_is (parser, CPP_LESS))
8115 proto = c_parser_objc_protocol_refs (parser);
8116 objc_start_class_interface (id1, superclass, proto, attributes);
8118 else
8119 objc_start_class_implementation (id1, superclass);
8120 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8121 c_parser_objc_class_instance_variables (parser);
8122 if (iface_p)
8124 objc_continue_interface ();
8125 c_parser_objc_methodprotolist (parser);
8126 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8127 objc_finish_interface ();
8129 else
8131 objc_continue_implementation ();
8132 return;
8136 /* Parse objc-class-instance-variables.
8138 objc-class-instance-variables:
8139 { objc-instance-variable-decl-list[opt] }
8141 objc-instance-variable-decl-list:
8142 objc-visibility-spec
8143 objc-instance-variable-decl ;
8145 objc-instance-variable-decl-list objc-visibility-spec
8146 objc-instance-variable-decl-list objc-instance-variable-decl ;
8147 objc-instance-variable-decl-list ;
8149 objc-visibility-spec:
8150 @private
8151 @protected
8152 @public
8154 objc-instance-variable-decl:
8155 struct-declaration
8158 static void
8159 c_parser_objc_class_instance_variables (c_parser *parser)
8161 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
8162 c_parser_consume_token (parser);
8163 while (c_parser_next_token_is_not (parser, CPP_EOF))
8165 tree decls;
8166 /* Parse any stray semicolon. */
8167 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8169 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8170 "extra semicolon");
8171 c_parser_consume_token (parser);
8172 continue;
8174 /* Stop if at the end of the instance variables. */
8175 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8177 c_parser_consume_token (parser);
8178 break;
8180 /* Parse any objc-visibility-spec. */
8181 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
8183 c_parser_consume_token (parser);
8184 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
8185 continue;
8187 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
8189 c_parser_consume_token (parser);
8190 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
8191 continue;
8193 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
8195 c_parser_consume_token (parser);
8196 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
8197 continue;
8199 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
8201 c_parser_consume_token (parser);
8202 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
8203 continue;
8205 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
8207 c_parser_pragma (parser, pragma_external);
8208 continue;
8211 /* Parse some comma-separated declarations. */
8212 decls = c_parser_struct_declaration (parser);
8213 if (decls == NULL)
8215 /* There is a syntax error. We want to skip the offending
8216 tokens up to the next ';' (included) or '}'
8217 (excluded). */
8219 /* First, skip manually a ')' or ']'. This is because they
8220 reduce the nesting level, so c_parser_skip_until_found()
8221 wouldn't be able to skip past them. */
8222 c_token *token = c_parser_peek_token (parser);
8223 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
8224 c_parser_consume_token (parser);
8226 /* Then, do the standard skipping. */
8227 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8229 /* We hopefully recovered. Start normal parsing again. */
8230 parser->error = false;
8231 continue;
8233 else
8235 /* Comma-separated instance variables are chained together
8236 in reverse order; add them one by one. */
8237 tree ivar = nreverse (decls);
8238 for (; ivar; ivar = DECL_CHAIN (ivar))
8239 objc_add_instance_variable (copy_node (ivar));
8241 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8245 /* Parse an objc-class-declaration.
8247 objc-class-declaration:
8248 @class identifier-list ;
8251 static void
8252 c_parser_objc_class_declaration (c_parser *parser)
8254 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
8255 c_parser_consume_token (parser);
8256 /* Any identifiers, including those declared as type names, are OK
8257 here. */
8258 while (true)
8260 tree id;
8261 if (c_parser_next_token_is_not (parser, CPP_NAME))
8263 c_parser_error (parser, "expected identifier");
8264 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8265 parser->error = false;
8266 return;
8268 id = c_parser_peek_token (parser)->value;
8269 objc_declare_class (id);
8270 c_parser_consume_token (parser);
8271 if (c_parser_next_token_is (parser, CPP_COMMA))
8272 c_parser_consume_token (parser);
8273 else
8274 break;
8276 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8279 /* Parse an objc-alias-declaration.
8281 objc-alias-declaration:
8282 @compatibility_alias identifier identifier ;
8285 static void
8286 c_parser_objc_alias_declaration (c_parser *parser)
8288 tree id1, id2;
8289 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
8290 c_parser_consume_token (parser);
8291 if (c_parser_next_token_is_not (parser, CPP_NAME))
8293 c_parser_error (parser, "expected identifier");
8294 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8295 return;
8297 id1 = c_parser_peek_token (parser)->value;
8298 c_parser_consume_token (parser);
8299 if (c_parser_next_token_is_not (parser, CPP_NAME))
8301 c_parser_error (parser, "expected identifier");
8302 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8303 return;
8305 id2 = c_parser_peek_token (parser)->value;
8306 c_parser_consume_token (parser);
8307 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8308 objc_declare_alias (id1, id2);
8311 /* Parse an objc-protocol-definition.
8313 objc-protocol-definition:
8314 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8315 @protocol identifier-list ;
8317 "@protocol identifier ;" should be resolved as "@protocol
8318 identifier-list ;": objc-methodprotolist may not start with a
8319 semicolon in the first alternative if objc-protocol-refs are
8320 omitted. */
8322 static void
8323 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
8325 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
8327 c_parser_consume_token (parser);
8328 if (c_parser_next_token_is_not (parser, CPP_NAME))
8330 c_parser_error (parser, "expected identifier");
8331 return;
8333 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8334 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
8336 /* Any identifiers, including those declared as type names, are
8337 OK here. */
8338 while (true)
8340 tree id;
8341 if (c_parser_next_token_is_not (parser, CPP_NAME))
8343 c_parser_error (parser, "expected identifier");
8344 break;
8346 id = c_parser_peek_token (parser)->value;
8347 objc_declare_protocol (id, attributes);
8348 c_parser_consume_token (parser);
8349 if (c_parser_next_token_is (parser, CPP_COMMA))
8350 c_parser_consume_token (parser);
8351 else
8352 break;
8354 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8356 else
8358 tree id = c_parser_peek_token (parser)->value;
8359 tree proto = NULL_TREE;
8360 c_parser_consume_token (parser);
8361 if (c_parser_next_token_is (parser, CPP_LESS))
8362 proto = c_parser_objc_protocol_refs (parser);
8363 parser->objc_pq_context = true;
8364 objc_start_protocol (id, proto, attributes);
8365 c_parser_objc_methodprotolist (parser);
8366 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8367 parser->objc_pq_context = false;
8368 objc_finish_interface ();
8372 /* Parse an objc-method-type.
8374 objc-method-type:
8378 Return true if it is a class method (+) and false if it is
8379 an instance method (-).
8381 static inline bool
8382 c_parser_objc_method_type (c_parser *parser)
8384 switch (c_parser_peek_token (parser)->type)
8386 case CPP_PLUS:
8387 c_parser_consume_token (parser);
8388 return true;
8389 case CPP_MINUS:
8390 c_parser_consume_token (parser);
8391 return false;
8392 default:
8393 gcc_unreachable ();
8397 /* Parse an objc-method-definition.
8399 objc-method-definition:
8400 objc-method-type objc-method-decl ;[opt] compound-statement
8403 static void
8404 c_parser_objc_method_definition (c_parser *parser)
8406 bool is_class_method = c_parser_objc_method_type (parser);
8407 tree decl, attributes = NULL_TREE, expr = NULL_TREE;
8408 parser->objc_pq_context = true;
8409 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8410 &expr);
8411 if (decl == error_mark_node)
8412 return; /* Bail here. */
8414 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8416 c_parser_consume_token (parser);
8417 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8418 "extra semicolon in method definition specified");
8421 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8423 c_parser_error (parser, "expected %<{%>");
8424 return;
8427 parser->objc_pq_context = false;
8428 if (objc_start_method_definition (is_class_method, decl, attributes, expr))
8430 add_stmt (c_parser_compound_statement (parser));
8431 objc_finish_method_definition (current_function_decl);
8433 else
8435 /* This code is executed when we find a method definition
8436 outside of an @implementation context (or invalid for other
8437 reasons). Parse the method (to keep going) but do not emit
8438 any code.
8440 c_parser_compound_statement (parser);
8444 /* Parse an objc-methodprotolist.
8446 objc-methodprotolist:
8447 empty
8448 objc-methodprotolist objc-methodproto
8449 objc-methodprotolist declaration
8450 objc-methodprotolist ;
8451 @optional
8452 @required
8454 The declaration is a data definition, which may be missing
8455 declaration specifiers under the same rules and diagnostics as
8456 other data definitions outside functions, and the stray semicolon
8457 is diagnosed the same way as a stray semicolon outside a
8458 function. */
8460 static void
8461 c_parser_objc_methodprotolist (c_parser *parser)
8463 while (true)
8465 /* The list is terminated by @end. */
8466 switch (c_parser_peek_token (parser)->type)
8468 case CPP_SEMICOLON:
8469 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8470 "ISO C does not allow extra %<;%> outside of a function");
8471 c_parser_consume_token (parser);
8472 break;
8473 case CPP_PLUS:
8474 case CPP_MINUS:
8475 c_parser_objc_methodproto (parser);
8476 break;
8477 case CPP_PRAGMA:
8478 c_parser_pragma (parser, pragma_external);
8479 break;
8480 case CPP_EOF:
8481 return;
8482 default:
8483 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
8484 return;
8485 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
8486 c_parser_objc_at_property_declaration (parser);
8487 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
8489 objc_set_method_opt (true);
8490 c_parser_consume_token (parser);
8492 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
8494 objc_set_method_opt (false);
8495 c_parser_consume_token (parser);
8497 else
8498 c_parser_declaration_or_fndef (parser, false, false, true,
8499 false, true, NULL, vNULL);
8500 break;
8505 /* Parse an objc-methodproto.
8507 objc-methodproto:
8508 objc-method-type objc-method-decl ;
8511 static void
8512 c_parser_objc_methodproto (c_parser *parser)
8514 bool is_class_method = c_parser_objc_method_type (parser);
8515 tree decl, attributes = NULL_TREE;
8517 /* Remember protocol qualifiers in prototypes. */
8518 parser->objc_pq_context = true;
8519 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8520 NULL);
8521 /* Forget protocol qualifiers now. */
8522 parser->objc_pq_context = false;
8524 /* Do not allow the presence of attributes to hide an erroneous
8525 method implementation in the interface section. */
8526 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
8528 c_parser_error (parser, "expected %<;%>");
8529 return;
8532 if (decl != error_mark_node)
8533 objc_add_method_declaration (is_class_method, decl, attributes);
8535 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8538 /* If we are at a position that method attributes may be present, check that
8539 there are not any parsed already (a syntax error) and then collect any
8540 specified at the current location. Finally, if new attributes were present,
8541 check that the next token is legal ( ';' for decls and '{' for defs). */
8543 static bool
8544 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
8546 bool bad = false;
8547 if (*attributes)
8549 c_parser_error (parser,
8550 "method attributes must be specified at the end only");
8551 *attributes = NULL_TREE;
8552 bad = true;
8555 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8556 *attributes = c_parser_attributes (parser);
8558 /* If there were no attributes here, just report any earlier error. */
8559 if (*attributes == NULL_TREE || bad)
8560 return bad;
8562 /* If the attributes are followed by a ; or {, then just report any earlier
8563 error. */
8564 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
8565 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8566 return bad;
8568 /* We've got attributes, but not at the end. */
8569 c_parser_error (parser,
8570 "expected %<;%> or %<{%> after method attribute definition");
8571 return true;
8574 /* Parse an objc-method-decl.
8576 objc-method-decl:
8577 ( objc-type-name ) objc-selector
8578 objc-selector
8579 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8580 objc-keyword-selector objc-optparmlist
8581 attributes
8583 objc-keyword-selector:
8584 objc-keyword-decl
8585 objc-keyword-selector objc-keyword-decl
8587 objc-keyword-decl:
8588 objc-selector : ( objc-type-name ) identifier
8589 objc-selector : identifier
8590 : ( objc-type-name ) identifier
8591 : identifier
8593 objc-optparmlist:
8594 objc-optparms objc-optellipsis
8596 objc-optparms:
8597 empty
8598 objc-opt-parms , parameter-declaration
8600 objc-optellipsis:
8601 empty
8602 , ...
8605 static tree
8606 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
8607 tree *attributes, tree *expr)
8609 tree type = NULL_TREE;
8610 tree sel;
8611 tree parms = NULL_TREE;
8612 bool ellipsis = false;
8613 bool attr_err = false;
8615 *attributes = NULL_TREE;
8616 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8618 c_parser_consume_token (parser);
8619 type = c_parser_objc_type_name (parser);
8620 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8622 sel = c_parser_objc_selector (parser);
8623 /* If there is no selector, or a colon follows, we have an
8624 objc-keyword-selector. If there is a selector, and a colon does
8625 not follow, that selector ends the objc-method-decl. */
8626 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
8628 tree tsel = sel;
8629 tree list = NULL_TREE;
8630 while (true)
8632 tree atype = NULL_TREE, id, keyworddecl;
8633 tree param_attr = NULL_TREE;
8634 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8635 break;
8636 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8638 c_parser_consume_token (parser);
8639 atype = c_parser_objc_type_name (parser);
8640 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8641 "expected %<)%>");
8643 /* New ObjC allows attributes on method parameters. */
8644 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8645 param_attr = c_parser_attributes (parser);
8646 if (c_parser_next_token_is_not (parser, CPP_NAME))
8648 c_parser_error (parser, "expected identifier");
8649 return error_mark_node;
8651 id = c_parser_peek_token (parser)->value;
8652 c_parser_consume_token (parser);
8653 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
8654 list = chainon (list, keyworddecl);
8655 tsel = c_parser_objc_selector (parser);
8656 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
8657 break;
8660 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8662 /* Parse the optional parameter list. Optional Objective-C
8663 method parameters follow the C syntax, and may include '...'
8664 to denote a variable number of arguments. */
8665 parms = make_node (TREE_LIST);
8666 while (c_parser_next_token_is (parser, CPP_COMMA))
8668 struct c_parm *parm;
8669 c_parser_consume_token (parser);
8670 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8672 ellipsis = true;
8673 c_parser_consume_token (parser);
8674 attr_err |= c_parser_objc_maybe_method_attributes
8675 (parser, attributes) ;
8676 break;
8678 parm = c_parser_parameter_declaration (parser, NULL_TREE);
8679 if (parm == NULL)
8680 break;
8681 parms = chainon (parms,
8682 build_tree_list (NULL_TREE, grokparm (parm, expr)));
8684 sel = list;
8686 else
8687 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8689 if (sel == NULL)
8691 c_parser_error (parser, "objective-c method declaration is expected");
8692 return error_mark_node;
8695 if (attr_err)
8696 return error_mark_node;
8698 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
8701 /* Parse an objc-type-name.
8703 objc-type-name:
8704 objc-type-qualifiers[opt] type-name
8705 objc-type-qualifiers[opt]
8707 objc-type-qualifiers:
8708 objc-type-qualifier
8709 objc-type-qualifiers objc-type-qualifier
8711 objc-type-qualifier: one of
8712 in out inout bycopy byref oneway
8715 static tree
8716 c_parser_objc_type_name (c_parser *parser)
8718 tree quals = NULL_TREE;
8719 struct c_type_name *type_name = NULL;
8720 tree type = NULL_TREE;
8721 while (true)
8723 c_token *token = c_parser_peek_token (parser);
8724 if (token->type == CPP_KEYWORD
8725 && (token->keyword == RID_IN
8726 || token->keyword == RID_OUT
8727 || token->keyword == RID_INOUT
8728 || token->keyword == RID_BYCOPY
8729 || token->keyword == RID_BYREF
8730 || token->keyword == RID_ONEWAY))
8732 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
8733 c_parser_consume_token (parser);
8735 else
8736 break;
8738 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
8739 type_name = c_parser_type_name (parser);
8740 if (type_name)
8741 type = groktypename (type_name, NULL, NULL);
8743 /* If the type is unknown, and error has already been produced and
8744 we need to recover from the error. In that case, use NULL_TREE
8745 for the type, as if no type had been specified; this will use the
8746 default type ('id') which is good for error recovery. */
8747 if (type == error_mark_node)
8748 type = NULL_TREE;
8750 return build_tree_list (quals, type);
8753 /* Parse objc-protocol-refs.
8755 objc-protocol-refs:
8756 < identifier-list >
8759 static tree
8760 c_parser_objc_protocol_refs (c_parser *parser)
8762 tree list = NULL_TREE;
8763 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
8764 c_parser_consume_token (parser);
8765 /* Any identifiers, including those declared as type names, are OK
8766 here. */
8767 while (true)
8769 tree id;
8770 if (c_parser_next_token_is_not (parser, CPP_NAME))
8772 c_parser_error (parser, "expected identifier");
8773 break;
8775 id = c_parser_peek_token (parser)->value;
8776 list = chainon (list, build_tree_list (NULL_TREE, id));
8777 c_parser_consume_token (parser);
8778 if (c_parser_next_token_is (parser, CPP_COMMA))
8779 c_parser_consume_token (parser);
8780 else
8781 break;
8783 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
8784 return list;
8787 /* Parse an objc-try-catch-finally-statement.
8789 objc-try-catch-finally-statement:
8790 @try compound-statement objc-catch-list[opt]
8791 @try compound-statement objc-catch-list[opt] @finally compound-statement
8793 objc-catch-list:
8794 @catch ( objc-catch-parameter-declaration ) compound-statement
8795 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8797 objc-catch-parameter-declaration:
8798 parameter-declaration
8799 '...'
8801 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8803 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8804 for C++. Keep them in sync. */
8806 static void
8807 c_parser_objc_try_catch_finally_statement (c_parser *parser)
8809 location_t location;
8810 tree stmt;
8812 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
8813 c_parser_consume_token (parser);
8814 location = c_parser_peek_token (parser)->location;
8815 objc_maybe_warn_exceptions (location);
8816 stmt = c_parser_compound_statement (parser);
8817 objc_begin_try_stmt (location, stmt);
8819 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
8821 struct c_parm *parm;
8822 tree parameter_declaration = error_mark_node;
8823 bool seen_open_paren = false;
8825 c_parser_consume_token (parser);
8826 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8827 seen_open_paren = true;
8828 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8830 /* We have "@catch (...)" (where the '...' are literally
8831 what is in the code). Skip the '...'.
8832 parameter_declaration is set to NULL_TREE, and
8833 objc_being_catch_clauses() knows that that means
8834 '...'. */
8835 c_parser_consume_token (parser);
8836 parameter_declaration = NULL_TREE;
8838 else
8840 /* We have "@catch (NSException *exception)" or something
8841 like that. Parse the parameter declaration. */
8842 parm = c_parser_parameter_declaration (parser, NULL_TREE);
8843 if (parm == NULL)
8844 parameter_declaration = error_mark_node;
8845 else
8846 parameter_declaration = grokparm (parm, NULL);
8848 if (seen_open_paren)
8849 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8850 else
8852 /* If there was no open parenthesis, we are recovering from
8853 an error, and we are trying to figure out what mistake
8854 the user has made. */
8856 /* If there is an immediate closing parenthesis, the user
8857 probably forgot the opening one (ie, they typed "@catch
8858 NSException *e)". Parse the closing parenthesis and keep
8859 going. */
8860 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8861 c_parser_consume_token (parser);
8863 /* If these is no immediate closing parenthesis, the user
8864 probably doesn't know that parenthesis are required at
8865 all (ie, they typed "@catch NSException *e"). So, just
8866 forget about the closing parenthesis and keep going. */
8868 objc_begin_catch_clause (parameter_declaration);
8869 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8870 c_parser_compound_statement_nostart (parser);
8871 objc_finish_catch_clause ();
8873 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
8875 c_parser_consume_token (parser);
8876 location = c_parser_peek_token (parser)->location;
8877 stmt = c_parser_compound_statement (parser);
8878 objc_build_finally_clause (location, stmt);
8880 objc_finish_try_stmt ();
8883 /* Parse an objc-synchronized-statement.
8885 objc-synchronized-statement:
8886 @synchronized ( expression ) compound-statement
8889 static void
8890 c_parser_objc_synchronized_statement (c_parser *parser)
8892 location_t loc;
8893 tree expr, stmt;
8894 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
8895 c_parser_consume_token (parser);
8896 loc = c_parser_peek_token (parser)->location;
8897 objc_maybe_warn_exceptions (loc);
8898 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8900 struct c_expr ce = c_parser_expression (parser);
8901 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
8902 expr = ce.value;
8903 expr = c_fully_fold (expr, false, NULL);
8904 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8906 else
8907 expr = error_mark_node;
8908 stmt = c_parser_compound_statement (parser);
8909 objc_build_synchronized (loc, expr, stmt);
8912 /* Parse an objc-selector; return NULL_TREE without an error if the
8913 next token is not an objc-selector.
8915 objc-selector:
8916 identifier
8917 one of
8918 enum struct union if else while do for switch case default
8919 break continue return goto asm sizeof typeof __alignof
8920 unsigned long const short volatile signed restrict _Complex
8921 in out inout bycopy byref oneway int char float double void _Bool
8922 _Atomic
8924 ??? Why this selection of keywords but not, for example, storage
8925 class specifiers? */
8927 static tree
8928 c_parser_objc_selector (c_parser *parser)
8930 c_token *token = c_parser_peek_token (parser);
8931 tree value = token->value;
8932 if (token->type == CPP_NAME)
8934 c_parser_consume_token (parser);
8935 return value;
8937 if (token->type != CPP_KEYWORD)
8938 return NULL_TREE;
8939 switch (token->keyword)
8941 case RID_ENUM:
8942 case RID_STRUCT:
8943 case RID_UNION:
8944 case RID_IF:
8945 case RID_ELSE:
8946 case RID_WHILE:
8947 case RID_DO:
8948 case RID_FOR:
8949 case RID_SWITCH:
8950 case RID_CASE:
8951 case RID_DEFAULT:
8952 case RID_BREAK:
8953 case RID_CONTINUE:
8954 case RID_RETURN:
8955 case RID_GOTO:
8956 case RID_ASM:
8957 case RID_SIZEOF:
8958 case RID_TYPEOF:
8959 case RID_ALIGNOF:
8960 case RID_UNSIGNED:
8961 case RID_LONG:
8962 case RID_INT128:
8963 case RID_CONST:
8964 case RID_SHORT:
8965 case RID_VOLATILE:
8966 case RID_SIGNED:
8967 case RID_RESTRICT:
8968 case RID_COMPLEX:
8969 case RID_IN:
8970 case RID_OUT:
8971 case RID_INOUT:
8972 case RID_BYCOPY:
8973 case RID_BYREF:
8974 case RID_ONEWAY:
8975 case RID_INT:
8976 case RID_CHAR:
8977 case RID_FLOAT:
8978 case RID_DOUBLE:
8979 case RID_VOID:
8980 case RID_BOOL:
8981 case RID_ATOMIC:
8982 case RID_AUTO_TYPE:
8983 c_parser_consume_token (parser);
8984 return value;
8985 default:
8986 return NULL_TREE;
8990 /* Parse an objc-selector-arg.
8992 objc-selector-arg:
8993 objc-selector
8994 objc-keywordname-list
8996 objc-keywordname-list:
8997 objc-keywordname
8998 objc-keywordname-list objc-keywordname
9000 objc-keywordname:
9001 objc-selector :
9005 static tree
9006 c_parser_objc_selector_arg (c_parser *parser)
9008 tree sel = c_parser_objc_selector (parser);
9009 tree list = NULL_TREE;
9010 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9011 return sel;
9012 while (true)
9014 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9015 return list;
9016 list = chainon (list, build_tree_list (sel, NULL_TREE));
9017 sel = c_parser_objc_selector (parser);
9018 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9019 break;
9021 return list;
9024 /* Parse an objc-receiver.
9026 objc-receiver:
9027 expression
9028 class-name
9029 type-name
9032 static tree
9033 c_parser_objc_receiver (c_parser *parser)
9035 location_t loc = c_parser_peek_token (parser)->location;
9037 if (c_parser_peek_token (parser)->type == CPP_NAME
9038 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
9039 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
9041 tree id = c_parser_peek_token (parser)->value;
9042 c_parser_consume_token (parser);
9043 return objc_get_class_reference (id);
9045 struct c_expr ce = c_parser_expression (parser);
9046 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9047 return c_fully_fold (ce.value, false, NULL);
9050 /* Parse objc-message-args.
9052 objc-message-args:
9053 objc-selector
9054 objc-keywordarg-list
9056 objc-keywordarg-list:
9057 objc-keywordarg
9058 objc-keywordarg-list objc-keywordarg
9060 objc-keywordarg:
9061 objc-selector : objc-keywordexpr
9062 : objc-keywordexpr
9065 static tree
9066 c_parser_objc_message_args (c_parser *parser)
9068 tree sel = c_parser_objc_selector (parser);
9069 tree list = NULL_TREE;
9070 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9071 return sel;
9072 while (true)
9074 tree keywordexpr;
9075 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9076 return error_mark_node;
9077 keywordexpr = c_parser_objc_keywordexpr (parser);
9078 list = chainon (list, build_tree_list (sel, keywordexpr));
9079 sel = c_parser_objc_selector (parser);
9080 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9081 break;
9083 return list;
9086 /* Parse an objc-keywordexpr.
9088 objc-keywordexpr:
9089 nonempty-expr-list
9092 static tree
9093 c_parser_objc_keywordexpr (c_parser *parser)
9095 tree ret;
9096 vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
9097 NULL, NULL, NULL, NULL);
9098 if (vec_safe_length (expr_list) == 1)
9100 /* Just return the expression, remove a level of
9101 indirection. */
9102 ret = (*expr_list)[0];
9104 else
9106 /* We have a comma expression, we will collapse later. */
9107 ret = build_tree_list_vec (expr_list);
9109 release_tree_vector (expr_list);
9110 return ret;
9113 /* A check, needed in several places, that ObjC interface, implementation or
9114 method definitions are not prefixed by incorrect items. */
9115 static bool
9116 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
9117 struct c_declspecs *specs)
9119 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
9120 || specs->typespec_kind != ctsk_none)
9122 c_parser_error (parser,
9123 "no type or storage class may be specified here,");
9124 c_parser_skip_to_end_of_block_or_statement (parser);
9125 return true;
9127 return false;
9130 /* Parse an Objective-C @property declaration. The syntax is:
9132 objc-property-declaration:
9133 '@property' objc-property-attributes[opt] struct-declaration ;
9135 objc-property-attributes:
9136 '(' objc-property-attribute-list ')'
9138 objc-property-attribute-list:
9139 objc-property-attribute
9140 objc-property-attribute-list, objc-property-attribute
9142 objc-property-attribute
9143 'getter' = identifier
9144 'setter' = identifier
9145 'readonly'
9146 'readwrite'
9147 'assign'
9148 'retain'
9149 'copy'
9150 'nonatomic'
9152 For example:
9153 @property NSString *name;
9154 @property (readonly) id object;
9155 @property (retain, nonatomic, getter=getTheName) id name;
9156 @property int a, b, c;
9158 PS: This function is identical to cp_parser_objc_at_propery_declaration
9159 for C++. Keep them in sync. */
9160 static void
9161 c_parser_objc_at_property_declaration (c_parser *parser)
9163 /* The following variables hold the attributes of the properties as
9164 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9165 seen. When we see an attribute, we set them to 'true' (if they
9166 are boolean properties) or to the identifier (if they have an
9167 argument, ie, for getter and setter). Note that here we only
9168 parse the list of attributes, check the syntax and accumulate the
9169 attributes that we find. objc_add_property_declaration() will
9170 then process the information. */
9171 bool property_assign = false;
9172 bool property_copy = false;
9173 tree property_getter_ident = NULL_TREE;
9174 bool property_nonatomic = false;
9175 bool property_readonly = false;
9176 bool property_readwrite = false;
9177 bool property_retain = false;
9178 tree property_setter_ident = NULL_TREE;
9180 /* 'properties' is the list of properties that we read. Usually a
9181 single one, but maybe more (eg, in "@property int a, b, c;" there
9182 are three). */
9183 tree properties;
9184 location_t loc;
9186 loc = c_parser_peek_token (parser)->location;
9187 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
9189 c_parser_consume_token (parser); /* Eat '@property'. */
9191 /* Parse the optional attribute list... */
9192 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9194 /* Eat the '(' */
9195 c_parser_consume_token (parser);
9197 /* Property attribute keywords are valid now. */
9198 parser->objc_property_attr_context = true;
9200 while (true)
9202 bool syntax_error = false;
9203 c_token *token = c_parser_peek_token (parser);
9204 enum rid keyword;
9206 if (token->type != CPP_KEYWORD)
9208 if (token->type == CPP_CLOSE_PAREN)
9209 c_parser_error (parser, "expected identifier");
9210 else
9212 c_parser_consume_token (parser);
9213 c_parser_error (parser, "unknown property attribute");
9215 break;
9217 keyword = token->keyword;
9218 c_parser_consume_token (parser);
9219 switch (keyword)
9221 case RID_ASSIGN: property_assign = true; break;
9222 case RID_COPY: property_copy = true; break;
9223 case RID_NONATOMIC: property_nonatomic = true; break;
9224 case RID_READONLY: property_readonly = true; break;
9225 case RID_READWRITE: property_readwrite = true; break;
9226 case RID_RETAIN: property_retain = true; break;
9228 case RID_GETTER:
9229 case RID_SETTER:
9230 if (c_parser_next_token_is_not (parser, CPP_EQ))
9232 if (keyword == RID_GETTER)
9233 c_parser_error (parser,
9234 "missing %<=%> (after %<getter%> attribute)");
9235 else
9236 c_parser_error (parser,
9237 "missing %<=%> (after %<setter%> attribute)");
9238 syntax_error = true;
9239 break;
9241 c_parser_consume_token (parser); /* eat the = */
9242 if (c_parser_next_token_is_not (parser, CPP_NAME))
9244 c_parser_error (parser, "expected identifier");
9245 syntax_error = true;
9246 break;
9248 if (keyword == RID_SETTER)
9250 if (property_setter_ident != NULL_TREE)
9251 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
9252 else
9253 property_setter_ident = c_parser_peek_token (parser)->value;
9254 c_parser_consume_token (parser);
9255 if (c_parser_next_token_is_not (parser, CPP_COLON))
9256 c_parser_error (parser, "setter name must terminate with %<:%>");
9257 else
9258 c_parser_consume_token (parser);
9260 else
9262 if (property_getter_ident != NULL_TREE)
9263 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
9264 else
9265 property_getter_ident = c_parser_peek_token (parser)->value;
9266 c_parser_consume_token (parser);
9268 break;
9269 default:
9270 c_parser_error (parser, "unknown property attribute");
9271 syntax_error = true;
9272 break;
9275 if (syntax_error)
9276 break;
9278 if (c_parser_next_token_is (parser, CPP_COMMA))
9279 c_parser_consume_token (parser);
9280 else
9281 break;
9283 parser->objc_property_attr_context = false;
9284 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9286 /* ... and the property declaration(s). */
9287 properties = c_parser_struct_declaration (parser);
9289 if (properties == error_mark_node)
9291 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9292 parser->error = false;
9293 return;
9296 if (properties == NULL_TREE)
9297 c_parser_error (parser, "expected identifier");
9298 else
9300 /* Comma-separated properties are chained together in
9301 reverse order; add them one by one. */
9302 properties = nreverse (properties);
9304 for (; properties; properties = TREE_CHAIN (properties))
9305 objc_add_property_declaration (loc, copy_node (properties),
9306 property_readonly, property_readwrite,
9307 property_assign, property_retain,
9308 property_copy, property_nonatomic,
9309 property_getter_ident, property_setter_ident);
9312 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9313 parser->error = false;
9316 /* Parse an Objective-C @synthesize declaration. The syntax is:
9318 objc-synthesize-declaration:
9319 @synthesize objc-synthesize-identifier-list ;
9321 objc-synthesize-identifier-list:
9322 objc-synthesize-identifier
9323 objc-synthesize-identifier-list, objc-synthesize-identifier
9325 objc-synthesize-identifier
9326 identifier
9327 identifier = identifier
9329 For example:
9330 @synthesize MyProperty;
9331 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9333 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9334 for C++. Keep them in sync.
9336 static void
9337 c_parser_objc_at_synthesize_declaration (c_parser *parser)
9339 tree list = NULL_TREE;
9340 location_t loc;
9341 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
9342 loc = c_parser_peek_token (parser)->location;
9344 c_parser_consume_token (parser);
9345 while (true)
9347 tree property, ivar;
9348 if (c_parser_next_token_is_not (parser, CPP_NAME))
9350 c_parser_error (parser, "expected identifier");
9351 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9352 /* Once we find the semicolon, we can resume normal parsing.
9353 We have to reset parser->error manually because
9354 c_parser_skip_until_found() won't reset it for us if the
9355 next token is precisely a semicolon. */
9356 parser->error = false;
9357 return;
9359 property = c_parser_peek_token (parser)->value;
9360 c_parser_consume_token (parser);
9361 if (c_parser_next_token_is (parser, CPP_EQ))
9363 c_parser_consume_token (parser);
9364 if (c_parser_next_token_is_not (parser, CPP_NAME))
9366 c_parser_error (parser, "expected identifier");
9367 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9368 parser->error = false;
9369 return;
9371 ivar = c_parser_peek_token (parser)->value;
9372 c_parser_consume_token (parser);
9374 else
9375 ivar = NULL_TREE;
9376 list = chainon (list, build_tree_list (ivar, property));
9377 if (c_parser_next_token_is (parser, CPP_COMMA))
9378 c_parser_consume_token (parser);
9379 else
9380 break;
9382 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9383 objc_add_synthesize_declaration (loc, list);
9386 /* Parse an Objective-C @dynamic declaration. The syntax is:
9388 objc-dynamic-declaration:
9389 @dynamic identifier-list ;
9391 For example:
9392 @dynamic MyProperty;
9393 @dynamic MyProperty, AnotherProperty;
9395 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9396 for C++. Keep them in sync.
9398 static void
9399 c_parser_objc_at_dynamic_declaration (c_parser *parser)
9401 tree list = NULL_TREE;
9402 location_t loc;
9403 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
9404 loc = c_parser_peek_token (parser)->location;
9406 c_parser_consume_token (parser);
9407 while (true)
9409 tree property;
9410 if (c_parser_next_token_is_not (parser, CPP_NAME))
9412 c_parser_error (parser, "expected identifier");
9413 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9414 parser->error = false;
9415 return;
9417 property = c_parser_peek_token (parser)->value;
9418 list = chainon (list, build_tree_list (NULL_TREE, property));
9419 c_parser_consume_token (parser);
9420 if (c_parser_next_token_is (parser, CPP_COMMA))
9421 c_parser_consume_token (parser);
9422 else
9423 break;
9425 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9426 objc_add_dynamic_declaration (loc, list);
9430 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9431 should be considered, statements. ALLOW_STMT is true if we're within
9432 the context of a function and such pragmas are to be allowed. Returns
9433 true if we actually parsed such a pragma. */
9435 static bool
9436 c_parser_pragma (c_parser *parser, enum pragma_context context)
9438 unsigned int id;
9440 id = c_parser_peek_token (parser)->pragma_kind;
9441 gcc_assert (id != PRAGMA_NONE);
9443 switch (id)
9445 case PRAGMA_OACC_UPDATE:
9446 if (context != pragma_compound)
9448 if (context == pragma_stmt)
9449 c_parser_error (parser, "%<#pragma acc update%> may only be "
9450 "used in compound statements");
9451 goto bad_stmt;
9453 c_parser_oacc_update (parser);
9454 return false;
9456 case PRAGMA_OMP_BARRIER:
9457 if (context != pragma_compound)
9459 if (context == pragma_stmt)
9460 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
9461 "used in compound statements");
9462 goto bad_stmt;
9464 c_parser_omp_barrier (parser);
9465 return false;
9467 case PRAGMA_OMP_FLUSH:
9468 if (context != pragma_compound)
9470 if (context == pragma_stmt)
9471 c_parser_error (parser, "%<#pragma omp flush%> may only be "
9472 "used in compound statements");
9473 goto bad_stmt;
9475 c_parser_omp_flush (parser);
9476 return false;
9478 case PRAGMA_OMP_TASKWAIT:
9479 if (context != pragma_compound)
9481 if (context == pragma_stmt)
9482 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
9483 "used in compound statements");
9484 goto bad_stmt;
9486 c_parser_omp_taskwait (parser);
9487 return false;
9489 case PRAGMA_OMP_TASKYIELD:
9490 if (context != pragma_compound)
9492 if (context == pragma_stmt)
9493 c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
9494 "used in compound statements");
9495 goto bad_stmt;
9497 c_parser_omp_taskyield (parser);
9498 return false;
9500 case PRAGMA_OMP_CANCEL:
9501 if (context != pragma_compound)
9503 if (context == pragma_stmt)
9504 c_parser_error (parser, "%<#pragma omp cancel%> may only be "
9505 "used in compound statements");
9506 goto bad_stmt;
9508 c_parser_omp_cancel (parser);
9509 return false;
9511 case PRAGMA_OMP_CANCELLATION_POINT:
9512 if (context != pragma_compound)
9514 if (context == pragma_stmt)
9515 c_parser_error (parser, "%<#pragma omp cancellation point%> may "
9516 "only be used in compound statements");
9517 goto bad_stmt;
9519 c_parser_omp_cancellation_point (parser);
9520 return false;
9522 case PRAGMA_OMP_THREADPRIVATE:
9523 c_parser_omp_threadprivate (parser);
9524 return false;
9526 case PRAGMA_OMP_TARGET:
9527 return c_parser_omp_target (parser, context);
9529 case PRAGMA_OMP_END_DECLARE_TARGET:
9530 c_parser_omp_end_declare_target (parser);
9531 return false;
9533 case PRAGMA_OMP_SECTION:
9534 error_at (c_parser_peek_token (parser)->location,
9535 "%<#pragma omp section%> may only be used in "
9536 "%<#pragma omp sections%> construct");
9537 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9538 return false;
9540 case PRAGMA_OMP_DECLARE_REDUCTION:
9541 c_parser_omp_declare (parser, context);
9542 return false;
9543 case PRAGMA_IVDEP:
9544 c_parser_consume_pragma (parser);
9545 c_parser_skip_to_pragma_eol (parser);
9546 if (!c_parser_next_token_is_keyword (parser, RID_FOR)
9547 && !c_parser_next_token_is_keyword (parser, RID_WHILE)
9548 && !c_parser_next_token_is_keyword (parser, RID_DO))
9550 c_parser_error (parser, "for, while or do statement expected");
9551 return false;
9553 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9554 c_parser_for_statement (parser, true);
9555 else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
9556 c_parser_while_statement (parser, true);
9557 else
9558 c_parser_do_statement (parser, true);
9559 return false;
9561 case PRAGMA_GCC_PCH_PREPROCESS:
9562 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
9563 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9564 return false;
9566 case PRAGMA_CILK_SIMD:
9567 if (!c_parser_cilk_verify_simd (parser, context))
9568 return false;
9569 c_parser_consume_pragma (parser);
9570 c_parser_cilk_simd (parser);
9571 return false;
9573 default:
9574 if (id < PRAGMA_FIRST_EXTERNAL)
9576 if (context != pragma_stmt && context != pragma_compound)
9578 bad_stmt:
9579 c_parser_error (parser, "expected declaration specifiers");
9580 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9581 return false;
9583 c_parser_omp_construct (parser);
9584 return true;
9586 break;
9589 c_parser_consume_pragma (parser);
9590 c_invoke_pragma_handler (id);
9592 /* Skip to EOL, but suppress any error message. Those will have been
9593 generated by the handler routine through calling error, as opposed
9594 to calling c_parser_error. */
9595 parser->error = true;
9596 c_parser_skip_to_pragma_eol (parser);
9598 return false;
9601 /* The interface the pragma parsers have to the lexer. */
9603 enum cpp_ttype
9604 pragma_lex (tree *value)
9606 c_token *tok = c_parser_peek_token (the_parser);
9607 enum cpp_ttype ret = tok->type;
9609 *value = tok->value;
9610 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
9611 ret = CPP_EOF;
9612 else
9614 if (ret == CPP_KEYWORD)
9615 ret = CPP_NAME;
9616 c_parser_consume_token (the_parser);
9619 return ret;
9622 static void
9623 c_parser_pragma_pch_preprocess (c_parser *parser)
9625 tree name = NULL;
9627 c_parser_consume_pragma (parser);
9628 if (c_parser_next_token_is (parser, CPP_STRING))
9630 name = c_parser_peek_token (parser)->value;
9631 c_parser_consume_token (parser);
9633 else
9634 c_parser_error (parser, "expected string literal");
9635 c_parser_skip_to_pragma_eol (parser);
9637 if (name)
9638 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
9641 /* OpenACC and OpenMP parsing routines. */
9643 /* Returns name of the next clause.
9644 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9645 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9646 returned and the token is consumed. */
9648 static pragma_omp_clause
9649 c_parser_omp_clause_name (c_parser *parser)
9651 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
9653 if (c_parser_next_token_is_keyword (parser, RID_IF))
9654 result = PRAGMA_OMP_CLAUSE_IF;
9655 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
9656 result = PRAGMA_OMP_CLAUSE_DEFAULT;
9657 else if (c_parser_next_token_is_keyword (parser, RID_FOR))
9658 result = PRAGMA_OMP_CLAUSE_FOR;
9659 else if (c_parser_next_token_is (parser, CPP_NAME))
9661 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9663 switch (p[0])
9665 case 'a':
9666 if (!strcmp ("aligned", p))
9667 result = PRAGMA_OMP_CLAUSE_ALIGNED;
9668 break;
9669 case 'c':
9670 if (!strcmp ("collapse", p))
9671 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
9672 else if (!strcmp ("copy", p))
9673 result = PRAGMA_OMP_CLAUSE_COPY;
9674 else if (!strcmp ("copyin", p))
9675 result = PRAGMA_OMP_CLAUSE_COPYIN;
9676 else if (!strcmp ("copyout", p))
9677 result = PRAGMA_OMP_CLAUSE_COPYOUT;
9678 else if (!strcmp ("copyprivate", p))
9679 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
9680 else if (!strcmp ("create", p))
9681 result = PRAGMA_OMP_CLAUSE_CREATE;
9682 break;
9683 case 'd':
9684 if (!strcmp ("delete", p))
9685 result = PRAGMA_OMP_CLAUSE_DELETE;
9686 else if (!strcmp ("depend", p))
9687 result = PRAGMA_OMP_CLAUSE_DEPEND;
9688 else if (!strcmp ("device", p))
9689 result = PRAGMA_OMP_CLAUSE_DEVICE;
9690 else if (!strcmp ("deviceptr", p))
9691 result = PRAGMA_OMP_CLAUSE_DEVICEPTR;
9692 else if (!strcmp ("dist_schedule", p))
9693 result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
9694 break;
9695 case 'f':
9696 if (!strcmp ("final", p))
9697 result = PRAGMA_OMP_CLAUSE_FINAL;
9698 else if (!strcmp ("firstprivate", p))
9699 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
9700 else if (!strcmp ("from", p))
9701 result = PRAGMA_OMP_CLAUSE_FROM;
9702 break;
9703 case 'h':
9704 if (!strcmp ("host", p))
9705 result = PRAGMA_OMP_CLAUSE_SELF;
9706 break;
9707 case 'i':
9708 if (!strcmp ("inbranch", p))
9709 result = PRAGMA_OMP_CLAUSE_INBRANCH;
9710 break;
9711 case 'l':
9712 if (!strcmp ("lastprivate", p))
9713 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
9714 else if (!strcmp ("linear", p))
9715 result = PRAGMA_OMP_CLAUSE_LINEAR;
9716 break;
9717 case 'm':
9718 if (!strcmp ("map", p))
9719 result = PRAGMA_OMP_CLAUSE_MAP;
9720 else if (!strcmp ("mergeable", p))
9721 result = PRAGMA_OMP_CLAUSE_MERGEABLE;
9722 else if (flag_cilkplus && !strcmp ("mask", p))
9723 result = PRAGMA_CILK_CLAUSE_MASK;
9724 break;
9725 case 'n':
9726 if (!strcmp ("notinbranch", p))
9727 result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
9728 else if (!strcmp ("nowait", p))
9729 result = PRAGMA_OMP_CLAUSE_NOWAIT;
9730 else if (!strcmp ("num_gangs", p))
9731 result = PRAGMA_OMP_CLAUSE_NUM_GANGS;
9732 else if (!strcmp ("num_teams", p))
9733 result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
9734 else if (!strcmp ("num_threads", p))
9735 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
9736 else if (!strcmp ("num_workers", p))
9737 result = PRAGMA_OMP_CLAUSE_NUM_WORKERS;
9738 else if (flag_cilkplus && !strcmp ("nomask", p))
9739 result = PRAGMA_CILK_CLAUSE_NOMASK;
9740 break;
9741 case 'o':
9742 if (!strcmp ("ordered", p))
9743 result = PRAGMA_OMP_CLAUSE_ORDERED;
9744 break;
9745 case 'p':
9746 if (!strcmp ("parallel", p))
9747 result = PRAGMA_OMP_CLAUSE_PARALLEL;
9748 else if (!strcmp ("present", p))
9749 result = PRAGMA_OMP_CLAUSE_PRESENT;
9750 else if (!strcmp ("present_or_copy", p)
9751 || !strcmp ("pcopy", p))
9752 result = PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY;
9753 else if (!strcmp ("present_or_copyin", p)
9754 || !strcmp ("pcopyin", p))
9755 result = PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN;
9756 else if (!strcmp ("present_or_copyout", p)
9757 || !strcmp ("pcopyout", p))
9758 result = PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT;
9759 else if (!strcmp ("present_or_create", p)
9760 || !strcmp ("pcreate", p))
9761 result = PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE;
9762 else if (!strcmp ("private", p))
9763 result = PRAGMA_OMP_CLAUSE_PRIVATE;
9764 else if (!strcmp ("proc_bind", p))
9765 result = PRAGMA_OMP_CLAUSE_PROC_BIND;
9766 break;
9767 case 'r':
9768 if (!strcmp ("reduction", p))
9769 result = PRAGMA_OMP_CLAUSE_REDUCTION;
9770 break;
9771 case 's':
9772 if (!strcmp ("safelen", p))
9773 result = PRAGMA_OMP_CLAUSE_SAFELEN;
9774 else if (!strcmp ("schedule", p))
9775 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
9776 else if (!strcmp ("sections", p))
9777 result = PRAGMA_OMP_CLAUSE_SECTIONS;
9778 else if (!strcmp ("shared", p))
9779 result = PRAGMA_OMP_CLAUSE_SHARED;
9780 else if (!strcmp ("simdlen", p))
9781 result = PRAGMA_OMP_CLAUSE_SIMDLEN;
9782 else if (!strcmp ("self", p))
9783 result = PRAGMA_OMP_CLAUSE_SELF;
9784 break;
9785 case 't':
9786 if (!strcmp ("taskgroup", p))
9787 result = PRAGMA_OMP_CLAUSE_TASKGROUP;
9788 else if (!strcmp ("thread_limit", p))
9789 result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
9790 else if (!strcmp ("to", p))
9791 result = PRAGMA_OMP_CLAUSE_TO;
9792 break;
9793 case 'u':
9794 if (!strcmp ("uniform", p))
9795 result = PRAGMA_OMP_CLAUSE_UNIFORM;
9796 else if (!strcmp ("untied", p))
9797 result = PRAGMA_OMP_CLAUSE_UNTIED;
9798 break;
9799 case 'v':
9800 if (!strcmp ("vector_length", p))
9801 result = PRAGMA_OMP_CLAUSE_VECTOR_LENGTH;
9802 else if (flag_cilkplus && !strcmp ("vectorlength", p))
9803 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
9804 break;
9808 if (result != PRAGMA_OMP_CLAUSE_NONE)
9809 c_parser_consume_token (parser);
9811 return result;
9814 /* Validate that a clause of the given type does not already exist. */
9816 static void
9817 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
9818 const char *name)
9820 tree c;
9822 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
9823 if (OMP_CLAUSE_CODE (c) == code)
9825 location_t loc = OMP_CLAUSE_LOCATION (c);
9826 error_at (loc, "too many %qs clauses", name);
9827 break;
9831 /* OpenACC 2.0, OpenMP 2.5:
9832 variable-list:
9833 identifier
9834 variable-list , identifier
9836 If KIND is nonzero, create the appropriate node and install the
9837 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9838 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9840 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9841 return the list created. */
9843 static tree
9844 c_parser_omp_variable_list (c_parser *parser,
9845 location_t clause_loc,
9846 enum omp_clause_code kind, tree list)
9848 if (c_parser_next_token_is_not (parser, CPP_NAME)
9849 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
9850 c_parser_error (parser, "expected identifier");
9852 while (c_parser_next_token_is (parser, CPP_NAME)
9853 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
9855 tree t = lookup_name (c_parser_peek_token (parser)->value);
9857 if (t == NULL_TREE)
9859 undeclared_variable (c_parser_peek_token (parser)->location,
9860 c_parser_peek_token (parser)->value);
9861 t = error_mark_node;
9864 c_parser_consume_token (parser);
9866 if (t == error_mark_node)
9868 else if (kind != 0)
9870 switch (kind)
9872 case OMP_CLAUSE_MAP:
9873 case OMP_CLAUSE_FROM:
9874 case OMP_CLAUSE_TO:
9875 case OMP_CLAUSE_DEPEND:
9876 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
9878 tree low_bound = NULL_TREE, length = NULL_TREE;
9880 c_parser_consume_token (parser);
9881 if (!c_parser_next_token_is (parser, CPP_COLON))
9882 low_bound = c_parser_expression (parser).value;
9883 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
9884 length = integer_one_node;
9885 else
9887 /* Look for `:'. */
9888 if (!c_parser_require (parser, CPP_COLON,
9889 "expected %<:%>"))
9891 t = error_mark_node;
9892 break;
9894 if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
9895 length = c_parser_expression (parser).value;
9897 /* Look for the closing `]'. */
9898 if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
9899 "expected %<]%>"))
9901 t = error_mark_node;
9902 break;
9904 t = tree_cons (low_bound, length, t);
9906 break;
9907 default:
9908 break;
9911 if (t != error_mark_node)
9913 tree u = build_omp_clause (clause_loc, kind);
9914 OMP_CLAUSE_DECL (u) = t;
9915 OMP_CLAUSE_CHAIN (u) = list;
9916 list = u;
9919 else
9920 list = tree_cons (t, NULL_TREE, list);
9922 if (c_parser_next_token_is_not (parser, CPP_COMMA))
9923 break;
9925 c_parser_consume_token (parser);
9928 return list;
9931 /* Similarly, but expect leading and trailing parenthesis. This is a very
9932 common case for OpenACC and OpenMP clauses. */
9934 static tree
9935 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
9936 tree list)
9938 /* The clauses location. */
9939 location_t loc = c_parser_peek_token (parser)->location;
9941 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9943 list = c_parser_omp_variable_list (parser, loc, kind, list);
9944 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9946 return list;
9949 /* OpenACC 2.0:
9950 copy ( variable-list )
9951 copyin ( variable-list )
9952 copyout ( variable-list )
9953 create ( variable-list )
9954 delete ( variable-list )
9955 present ( variable-list )
9956 present_or_copy ( variable-list )
9957 pcopy ( variable-list )
9958 present_or_copyin ( variable-list )
9959 pcopyin ( variable-list )
9960 present_or_copyout ( variable-list )
9961 pcopyout ( variable-list )
9962 present_or_create ( variable-list )
9963 pcreate ( variable-list ) */
9965 static tree
9966 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
9967 tree list)
9969 enum omp_clause_map_kind kind;
9970 switch (c_kind)
9972 default:
9973 gcc_unreachable ();
9974 case PRAGMA_OMP_CLAUSE_COPY:
9975 kind = OMP_CLAUSE_MAP_FORCE_TOFROM;
9976 break;
9977 case PRAGMA_OMP_CLAUSE_COPYIN:
9978 kind = OMP_CLAUSE_MAP_FORCE_TO;
9979 break;
9980 case PRAGMA_OMP_CLAUSE_COPYOUT:
9981 kind = OMP_CLAUSE_MAP_FORCE_FROM;
9982 break;
9983 case PRAGMA_OMP_CLAUSE_CREATE:
9984 kind = OMP_CLAUSE_MAP_FORCE_ALLOC;
9985 break;
9986 case PRAGMA_OMP_CLAUSE_DELETE:
9987 kind = OMP_CLAUSE_MAP_FORCE_DEALLOC;
9988 break;
9989 case PRAGMA_OMP_CLAUSE_DEVICE:
9990 kind = OMP_CLAUSE_MAP_FORCE_TO;
9991 break;
9992 case PRAGMA_OMP_CLAUSE_HOST:
9993 kind = OMP_CLAUSE_MAP_FORCE_FROM;
9994 break;
9995 case PRAGMA_OMP_CLAUSE_PRESENT:
9996 kind = OMP_CLAUSE_MAP_FORCE_PRESENT;
9997 break;
9998 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY:
9999 kind = OMP_CLAUSE_MAP_TOFROM;
10000 break;
10001 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN:
10002 kind = OMP_CLAUSE_MAP_TO;
10003 break;
10004 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT:
10005 kind = OMP_CLAUSE_MAP_FROM;
10006 break;
10007 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE:
10008 kind = OMP_CLAUSE_MAP_ALLOC;
10009 break;
10010 case PRAGMA_OMP_CLAUSE_SELF:
10011 kind = OMP_CLAUSE_MAP_FORCE_FROM;
10012 break;
10014 tree nl, c;
10015 nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
10017 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10018 OMP_CLAUSE_MAP_KIND (c) = kind;
10020 return nl;
10023 /* OpenACC 2.0:
10024 deviceptr ( variable-list ) */
10026 static tree
10027 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
10029 location_t loc = c_parser_peek_token (parser)->location;
10030 tree vars, t;
10032 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10033 c_parser_oacc_data_clause), as for PRAGMA_OMP_CLAUSE_DEVICEPTR,
10034 variable-list must only allow for pointer variables. */
10035 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10036 for (t = vars; t && t; t = TREE_CHAIN (t))
10038 tree v = TREE_PURPOSE (t);
10040 /* FIXME diagnostics: Ideally we should keep individual
10041 locations for all the variables in the var list to make the
10042 following errors more precise. Perhaps
10043 c_parser_omp_var_list_parens() should construct a list of
10044 locations to go along with the var list. */
10046 if (TREE_CODE (v) != VAR_DECL)
10047 error_at (loc, "%qD is not a variable", v);
10048 else if (TREE_TYPE (v) == error_mark_node)
10050 else if (!POINTER_TYPE_P (TREE_TYPE (v)))
10051 error_at (loc, "%qD is not a pointer variable", v);
10053 tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
10054 OMP_CLAUSE_MAP_KIND (u) = OMP_CLAUSE_MAP_FORCE_DEVICEPTR;
10055 OMP_CLAUSE_DECL (u) = v;
10056 OMP_CLAUSE_CHAIN (u) = list;
10057 list = u;
10060 return list;
10063 /* OpenMP 3.0:
10064 collapse ( constant-expression ) */
10066 static tree
10067 c_parser_omp_clause_collapse (c_parser *parser, tree list)
10069 tree c, num = error_mark_node;
10070 HOST_WIDE_INT n;
10071 location_t loc;
10073 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
10075 loc = c_parser_peek_token (parser)->location;
10076 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10078 num = c_parser_expr_no_commas (parser, NULL).value;
10079 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10081 if (num == error_mark_node)
10082 return list;
10083 mark_exp_read (num);
10084 num = c_fully_fold (num, false, NULL);
10085 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
10086 || !tree_fits_shwi_p (num)
10087 || (n = tree_to_shwi (num)) <= 0
10088 || (int) n != n)
10090 error_at (loc,
10091 "collapse argument needs positive constant integer expression");
10092 return list;
10094 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
10095 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
10096 OMP_CLAUSE_CHAIN (c) = list;
10097 return c;
10100 /* OpenMP 2.5:
10101 copyin ( variable-list ) */
10103 static tree
10104 c_parser_omp_clause_copyin (c_parser *parser, tree list)
10106 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
10109 /* OpenMP 2.5:
10110 copyprivate ( variable-list ) */
10112 static tree
10113 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
10115 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
10118 /* OpenMP 2.5:
10119 default ( shared | none ) */
10121 static tree
10122 c_parser_omp_clause_default (c_parser *parser, tree list)
10124 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
10125 location_t loc = c_parser_peek_token (parser)->location;
10126 tree c;
10128 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10129 return list;
10130 if (c_parser_next_token_is (parser, CPP_NAME))
10132 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10134 switch (p[0])
10136 case 'n':
10137 if (strcmp ("none", p) != 0)
10138 goto invalid_kind;
10139 kind = OMP_CLAUSE_DEFAULT_NONE;
10140 break;
10142 case 's':
10143 if (strcmp ("shared", p) != 0)
10144 goto invalid_kind;
10145 kind = OMP_CLAUSE_DEFAULT_SHARED;
10146 break;
10148 default:
10149 goto invalid_kind;
10152 c_parser_consume_token (parser);
10154 else
10156 invalid_kind:
10157 c_parser_error (parser, "expected %<none%> or %<shared%>");
10159 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10161 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
10162 return list;
10164 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
10165 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
10166 OMP_CLAUSE_CHAIN (c) = list;
10167 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
10169 return c;
10172 /* OpenMP 2.5:
10173 firstprivate ( variable-list ) */
10175 static tree
10176 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
10178 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
10181 /* OpenMP 3.1:
10182 final ( expression ) */
10184 static tree
10185 c_parser_omp_clause_final (c_parser *parser, tree list)
10187 location_t loc = c_parser_peek_token (parser)->location;
10188 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10190 tree t = c_parser_paren_condition (parser);
10191 tree c;
10193 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
10195 c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
10196 OMP_CLAUSE_FINAL_EXPR (c) = t;
10197 OMP_CLAUSE_CHAIN (c) = list;
10198 list = c;
10200 else
10201 c_parser_error (parser, "expected %<(%>");
10203 return list;
10206 /* OpenACC, OpenMP 2.5:
10207 if ( expression ) */
10209 static tree
10210 c_parser_omp_clause_if (c_parser *parser, tree list)
10212 location_t loc = c_parser_peek_token (parser)->location;
10213 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10215 tree t = c_parser_paren_condition (parser);
10216 tree c;
10218 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
10220 c = build_omp_clause (loc, OMP_CLAUSE_IF);
10221 OMP_CLAUSE_IF_EXPR (c) = t;
10222 OMP_CLAUSE_CHAIN (c) = list;
10223 list = c;
10225 else
10226 c_parser_error (parser, "expected %<(%>");
10228 return list;
10231 /* OpenMP 2.5:
10232 lastprivate ( variable-list ) */
10234 static tree
10235 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
10237 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
10240 /* OpenMP 3.1:
10241 mergeable */
10243 static tree
10244 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10246 tree c;
10248 /* FIXME: Should we allow duplicates? */
10249 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
10251 c = build_omp_clause (c_parser_peek_token (parser)->location,
10252 OMP_CLAUSE_MERGEABLE);
10253 OMP_CLAUSE_CHAIN (c) = list;
10255 return c;
10258 /* OpenMP 2.5:
10259 nowait */
10261 static tree
10262 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10264 tree c;
10265 location_t loc = c_parser_peek_token (parser)->location;
10267 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
10269 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
10270 OMP_CLAUSE_CHAIN (c) = list;
10271 return c;
10274 /* OpenACC:
10275 num_gangs ( expression ) */
10277 static tree
10278 c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
10280 location_t num_gangs_loc = c_parser_peek_token (parser)->location;
10281 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10283 location_t expr_loc = c_parser_peek_token (parser)->location;
10284 tree c, t = c_parser_expression (parser).value;
10285 mark_exp_read (t);
10286 t = c_fully_fold (t, false, NULL);
10288 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10290 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10292 c_parser_error (parser, "expected integer expression");
10293 return list;
10296 /* Attempt to statically determine when the number isn't positive. */
10297 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10298 build_int_cst (TREE_TYPE (t), 0));
10299 if (CAN_HAVE_LOCATION_P (c))
10300 SET_EXPR_LOCATION (c, expr_loc);
10301 if (c == boolean_true_node)
10303 warning_at (expr_loc, 0,
10304 "%<num_gangs%> value must be positive");
10305 t = integer_one_node;
10308 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
10310 c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
10311 OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
10312 OMP_CLAUSE_CHAIN (c) = list;
10313 list = c;
10316 return list;
10319 /* OpenMP 2.5:
10320 num_threads ( expression ) */
10322 static tree
10323 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
10325 location_t num_threads_loc = c_parser_peek_token (parser)->location;
10326 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10328 location_t expr_loc = c_parser_peek_token (parser)->location;
10329 tree c, t = c_parser_expression (parser).value;
10330 mark_exp_read (t);
10331 t = c_fully_fold (t, false, NULL);
10333 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10335 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10337 c_parser_error (parser, "expected integer expression");
10338 return list;
10341 /* Attempt to statically determine when the number isn't positive. */
10342 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10343 build_int_cst (TREE_TYPE (t), 0));
10344 if (CAN_HAVE_LOCATION_P (c))
10345 SET_EXPR_LOCATION (c, expr_loc);
10346 if (c == boolean_true_node)
10348 warning_at (expr_loc, 0,
10349 "%<num_threads%> value must be positive");
10350 t = integer_one_node;
10353 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
10355 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
10356 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
10357 OMP_CLAUSE_CHAIN (c) = list;
10358 list = c;
10361 return list;
10364 /* OpenACC:
10365 num_workers ( expression ) */
10367 static tree
10368 c_parser_omp_clause_num_workers (c_parser *parser, tree list)
10370 location_t num_workers_loc = c_parser_peek_token (parser)->location;
10371 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10373 location_t expr_loc = c_parser_peek_token (parser)->location;
10374 tree c, t = c_parser_expression (parser).value;
10375 mark_exp_read (t);
10376 t = c_fully_fold (t, false, NULL);
10378 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10380 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10382 c_parser_error (parser, "expected integer expression");
10383 return list;
10386 /* Attempt to statically determine when the number isn't positive. */
10387 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10388 build_int_cst (TREE_TYPE (t), 0));
10389 if (CAN_HAVE_LOCATION_P (c))
10390 SET_EXPR_LOCATION (c, expr_loc);
10391 if (c == boolean_true_node)
10393 warning_at (expr_loc, 0,
10394 "%<num_workers%> value must be positive");
10395 t = integer_one_node;
10398 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
10400 c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
10401 OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
10402 OMP_CLAUSE_CHAIN (c) = list;
10403 list = c;
10406 return list;
10409 /* OpenMP 2.5:
10410 ordered */
10412 static tree
10413 c_parser_omp_clause_ordered (c_parser *parser, tree list)
10415 tree c;
10417 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
10419 c = build_omp_clause (c_parser_peek_token (parser)->location,
10420 OMP_CLAUSE_ORDERED);
10421 OMP_CLAUSE_CHAIN (c) = list;
10423 return c;
10426 /* OpenMP 2.5:
10427 private ( variable-list ) */
10429 static tree
10430 c_parser_omp_clause_private (c_parser *parser, tree list)
10432 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
10435 /* OpenMP 2.5:
10436 reduction ( reduction-operator : variable-list )
10438 reduction-operator:
10439 One of: + * - & ^ | && ||
10441 OpenMP 3.1:
10443 reduction-operator:
10444 One of: + * - & ^ | && || max min
10446 OpenMP 4.0:
10448 reduction-operator:
10449 One of: + * - & ^ | && ||
10450 identifier */
10452 static tree
10453 c_parser_omp_clause_reduction (c_parser *parser, tree list)
10455 location_t clause_loc = c_parser_peek_token (parser)->location;
10456 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10458 enum tree_code code = ERROR_MARK;
10459 tree reduc_id = NULL_TREE;
10461 switch (c_parser_peek_token (parser)->type)
10463 case CPP_PLUS:
10464 code = PLUS_EXPR;
10465 break;
10466 case CPP_MULT:
10467 code = MULT_EXPR;
10468 break;
10469 case CPP_MINUS:
10470 code = MINUS_EXPR;
10471 break;
10472 case CPP_AND:
10473 code = BIT_AND_EXPR;
10474 break;
10475 case CPP_XOR:
10476 code = BIT_XOR_EXPR;
10477 break;
10478 case CPP_OR:
10479 code = BIT_IOR_EXPR;
10480 break;
10481 case CPP_AND_AND:
10482 code = TRUTH_ANDIF_EXPR;
10483 break;
10484 case CPP_OR_OR:
10485 code = TRUTH_ORIF_EXPR;
10486 break;
10487 case CPP_NAME:
10489 const char *p
10490 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10491 if (strcmp (p, "min") == 0)
10493 code = MIN_EXPR;
10494 break;
10496 if (strcmp (p, "max") == 0)
10498 code = MAX_EXPR;
10499 break;
10501 reduc_id = c_parser_peek_token (parser)->value;
10502 break;
10504 default:
10505 c_parser_error (parser,
10506 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10507 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10508 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10509 return list;
10511 c_parser_consume_token (parser);
10512 reduc_id = c_omp_reduction_id (code, reduc_id);
10513 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10515 tree nl, c;
10517 nl = c_parser_omp_variable_list (parser, clause_loc,
10518 OMP_CLAUSE_REDUCTION, list);
10519 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10521 tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
10522 OMP_CLAUSE_REDUCTION_CODE (c) = code;
10523 if (code == ERROR_MARK
10524 || !(INTEGRAL_TYPE_P (type)
10525 || TREE_CODE (type) == REAL_TYPE
10526 || TREE_CODE (type) == COMPLEX_TYPE))
10527 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
10528 = c_omp_reduction_lookup (reduc_id,
10529 TYPE_MAIN_VARIANT (type));
10532 list = nl;
10534 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10536 return list;
10539 /* OpenMP 2.5:
10540 schedule ( schedule-kind )
10541 schedule ( schedule-kind , expression )
10543 schedule-kind:
10544 static | dynamic | guided | runtime | auto
10547 static tree
10548 c_parser_omp_clause_schedule (c_parser *parser, tree list)
10550 tree c, t;
10551 location_t loc = c_parser_peek_token (parser)->location;
10553 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10554 return list;
10556 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
10558 if (c_parser_next_token_is (parser, CPP_NAME))
10560 tree kind = c_parser_peek_token (parser)->value;
10561 const char *p = IDENTIFIER_POINTER (kind);
10563 switch (p[0])
10565 case 'd':
10566 if (strcmp ("dynamic", p) != 0)
10567 goto invalid_kind;
10568 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
10569 break;
10571 case 'g':
10572 if (strcmp ("guided", p) != 0)
10573 goto invalid_kind;
10574 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
10575 break;
10577 case 'r':
10578 if (strcmp ("runtime", p) != 0)
10579 goto invalid_kind;
10580 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
10581 break;
10583 default:
10584 goto invalid_kind;
10587 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
10588 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
10589 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
10590 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
10591 else
10592 goto invalid_kind;
10594 c_parser_consume_token (parser);
10595 if (c_parser_next_token_is (parser, CPP_COMMA))
10597 location_t here;
10598 c_parser_consume_token (parser);
10600 here = c_parser_peek_token (parser)->location;
10601 t = c_parser_expr_no_commas (parser, NULL).value;
10602 mark_exp_read (t);
10603 t = c_fully_fold (t, false, NULL);
10605 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
10606 error_at (here, "schedule %<runtime%> does not take "
10607 "a %<chunk_size%> parameter");
10608 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
10609 error_at (here,
10610 "schedule %<auto%> does not take "
10611 "a %<chunk_size%> parameter");
10612 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
10613 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
10614 else
10615 c_parser_error (parser, "expected integer expression");
10617 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10619 else
10620 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
10621 "expected %<,%> or %<)%>");
10623 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
10624 OMP_CLAUSE_CHAIN (c) = list;
10625 return c;
10627 invalid_kind:
10628 c_parser_error (parser, "invalid schedule kind");
10629 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10630 return list;
10633 /* OpenMP 2.5:
10634 shared ( variable-list ) */
10636 static tree
10637 c_parser_omp_clause_shared (c_parser *parser, tree list)
10639 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
10642 /* OpenMP 3.0:
10643 untied */
10645 static tree
10646 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10648 tree c;
10650 /* FIXME: Should we allow duplicates? */
10651 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
10653 c = build_omp_clause (c_parser_peek_token (parser)->location,
10654 OMP_CLAUSE_UNTIED);
10655 OMP_CLAUSE_CHAIN (c) = list;
10657 return c;
10660 /* OpenACC:
10661 vector_length ( expression ) */
10663 static tree
10664 c_parser_omp_clause_vector_length (c_parser *parser, tree list)
10666 location_t vector_length_loc = c_parser_peek_token (parser)->location;
10667 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10669 location_t expr_loc = c_parser_peek_token (parser)->location;
10670 tree c, t = c_parser_expression (parser).value;
10671 mark_exp_read (t);
10672 t = c_fully_fold (t, false, NULL);
10674 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10676 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10678 c_parser_error (parser, "expected integer expression");
10679 return list;
10682 /* Attempt to statically determine when the number isn't positive. */
10683 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10684 build_int_cst (TREE_TYPE (t), 0));
10685 if (CAN_HAVE_LOCATION_P (c))
10686 SET_EXPR_LOCATION (c, expr_loc);
10687 if (c == boolean_true_node)
10689 warning_at (expr_loc, 0,
10690 "%<vector_length%> value must be positive");
10691 t = integer_one_node;
10694 check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
10696 c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
10697 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
10698 OMP_CLAUSE_CHAIN (c) = list;
10699 list = c;
10702 return list;
10705 /* OpenMP 4.0:
10706 inbranch
10707 notinbranch */
10709 static tree
10710 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
10711 enum omp_clause_code code, tree list)
10713 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
10715 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
10716 OMP_CLAUSE_CHAIN (c) = list;
10718 return c;
10721 /* OpenMP 4.0:
10722 parallel
10724 sections
10725 taskgroup */
10727 static tree
10728 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
10729 enum omp_clause_code code, tree list)
10731 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
10732 OMP_CLAUSE_CHAIN (c) = list;
10734 return c;
10737 /* OpenMP 4.0:
10738 num_teams ( expression ) */
10740 static tree
10741 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
10743 location_t num_teams_loc = c_parser_peek_token (parser)->location;
10744 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10746 location_t expr_loc = c_parser_peek_token (parser)->location;
10747 tree c, t = c_parser_expression (parser).value;
10748 mark_exp_read (t);
10749 t = c_fully_fold (t, false, NULL);
10751 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10753 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10755 c_parser_error (parser, "expected integer expression");
10756 return list;
10759 /* Attempt to statically determine when the number isn't positive. */
10760 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10761 build_int_cst (TREE_TYPE (t), 0));
10762 if (CAN_HAVE_LOCATION_P (c))
10763 SET_EXPR_LOCATION (c, expr_loc);
10764 if (c == boolean_true_node)
10766 warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
10767 t = integer_one_node;
10770 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
10772 c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
10773 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
10774 OMP_CLAUSE_CHAIN (c) = list;
10775 list = c;
10778 return list;
10781 /* OpenMP 4.0:
10782 thread_limit ( expression ) */
10784 static tree
10785 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
10787 location_t num_teams_loc = c_parser_peek_token (parser)->location;
10788 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10790 location_t expr_loc = c_parser_peek_token (parser)->location;
10791 tree c, t = c_parser_expression (parser).value;
10792 mark_exp_read (t);
10793 t = c_fully_fold (t, false, NULL);
10795 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10797 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10799 c_parser_error (parser, "expected integer expression");
10800 return list;
10803 /* Attempt to statically determine when the number isn't positive. */
10804 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10805 build_int_cst (TREE_TYPE (t), 0));
10806 if (CAN_HAVE_LOCATION_P (c))
10807 SET_EXPR_LOCATION (c, expr_loc);
10808 if (c == boolean_true_node)
10810 warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
10811 t = integer_one_node;
10814 check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
10815 "thread_limit");
10817 c = build_omp_clause (num_teams_loc, OMP_CLAUSE_THREAD_LIMIT);
10818 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
10819 OMP_CLAUSE_CHAIN (c) = list;
10820 list = c;
10823 return list;
10826 /* OpenMP 4.0:
10827 aligned ( variable-list )
10828 aligned ( variable-list : constant-expression ) */
10830 static tree
10831 c_parser_omp_clause_aligned (c_parser *parser, tree list)
10833 location_t clause_loc = c_parser_peek_token (parser)->location;
10834 tree nl, c;
10836 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10837 return list;
10839 nl = c_parser_omp_variable_list (parser, clause_loc,
10840 OMP_CLAUSE_ALIGNED, list);
10842 if (c_parser_next_token_is (parser, CPP_COLON))
10844 c_parser_consume_token (parser);
10845 tree alignment = c_parser_expr_no_commas (parser, NULL).value;
10846 mark_exp_read (alignment);
10847 alignment = c_fully_fold (alignment, false, NULL);
10848 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment))
10849 && TREE_CODE (alignment) != INTEGER_CST
10850 && tree_int_cst_sgn (alignment) != 1)
10852 error_at (clause_loc, "%<aligned%> clause alignment expression must "
10853 "be positive constant integer expression");
10854 alignment = NULL_TREE;
10857 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10858 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
10861 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10862 return nl;
10865 /* OpenMP 4.0:
10866 linear ( variable-list )
10867 linear ( variable-list : expression ) */
10869 static tree
10870 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn)
10872 location_t clause_loc = c_parser_peek_token (parser)->location;
10873 tree nl, c, step;
10875 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10876 return list;
10878 nl = c_parser_omp_variable_list (parser, clause_loc,
10879 OMP_CLAUSE_LINEAR, list);
10881 if (c_parser_next_token_is (parser, CPP_COLON))
10883 c_parser_consume_token (parser);
10884 step = c_parser_expression (parser).value;
10885 mark_exp_read (step);
10886 step = c_fully_fold (step, false, NULL);
10887 if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL)
10889 sorry ("using parameters for %<linear%> step is not supported yet");
10890 step = integer_one_node;
10892 if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
10894 error_at (clause_loc, "%<linear%> clause step expression must "
10895 "be integral");
10896 step = integer_one_node;
10900 else
10901 step = integer_one_node;
10903 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10905 OMP_CLAUSE_LINEAR_STEP (c) = step;
10908 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10909 return nl;
10912 /* OpenMP 4.0:
10913 safelen ( constant-expression ) */
10915 static tree
10916 c_parser_omp_clause_safelen (c_parser *parser, tree list)
10918 location_t clause_loc = c_parser_peek_token (parser)->location;
10919 tree c, t;
10921 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10922 return list;
10924 t = c_parser_expr_no_commas (parser, NULL).value;
10925 mark_exp_read (t);
10926 t = c_fully_fold (t, false, NULL);
10927 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10928 && TREE_CODE (t) != INTEGER_CST
10929 && tree_int_cst_sgn (t) != 1)
10931 error_at (clause_loc, "%<safelen%> clause expression must "
10932 "be positive constant integer expression");
10933 t = NULL_TREE;
10936 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10937 if (t == NULL_TREE || t == error_mark_node)
10938 return list;
10940 check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
10942 c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
10943 OMP_CLAUSE_SAFELEN_EXPR (c) = t;
10944 OMP_CLAUSE_CHAIN (c) = list;
10945 return c;
10948 /* OpenMP 4.0:
10949 simdlen ( constant-expression ) */
10951 static tree
10952 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
10954 location_t clause_loc = c_parser_peek_token (parser)->location;
10955 tree c, t;
10957 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10958 return list;
10960 t = c_parser_expr_no_commas (parser, NULL).value;
10961 mark_exp_read (t);
10962 t = c_fully_fold (t, false, NULL);
10963 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10964 && TREE_CODE (t) != INTEGER_CST
10965 && tree_int_cst_sgn (t) != 1)
10967 error_at (clause_loc, "%<simdlen%> clause expression must "
10968 "be positive constant integer expression");
10969 t = NULL_TREE;
10972 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10973 if (t == NULL_TREE || t == error_mark_node)
10974 return list;
10976 check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
10978 c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
10979 OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
10980 OMP_CLAUSE_CHAIN (c) = list;
10981 return c;
10984 /* OpenMP 4.0:
10985 depend ( depend-kind: variable-list )
10987 depend-kind:
10988 in | out | inout */
10990 static tree
10991 c_parser_omp_clause_depend (c_parser *parser, tree list)
10993 location_t clause_loc = c_parser_peek_token (parser)->location;
10994 enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
10995 tree nl, c;
10997 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10998 return list;
11000 if (c_parser_next_token_is (parser, CPP_NAME))
11002 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11003 if (strcmp ("in", p) == 0)
11004 kind = OMP_CLAUSE_DEPEND_IN;
11005 else if (strcmp ("inout", p) == 0)
11006 kind = OMP_CLAUSE_DEPEND_INOUT;
11007 else if (strcmp ("out", p) == 0)
11008 kind = OMP_CLAUSE_DEPEND_OUT;
11009 else
11010 goto invalid_kind;
11012 else
11013 goto invalid_kind;
11015 c_parser_consume_token (parser);
11016 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11017 goto resync_fail;
11019 nl = c_parser_omp_variable_list (parser, clause_loc,
11020 OMP_CLAUSE_DEPEND, list);
11022 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11023 OMP_CLAUSE_DEPEND_KIND (c) = kind;
11025 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11026 return nl;
11028 invalid_kind:
11029 c_parser_error (parser, "invalid depend kind");
11030 resync_fail:
11031 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11032 return list;
11035 /* OpenMP 4.0:
11036 map ( map-kind: variable-list )
11037 map ( variable-list )
11039 map-kind:
11040 alloc | to | from | tofrom */
11042 static tree
11043 c_parser_omp_clause_map (c_parser *parser, tree list)
11045 location_t clause_loc = c_parser_peek_token (parser)->location;
11046 enum omp_clause_map_kind kind = OMP_CLAUSE_MAP_TOFROM;
11047 tree nl, c;
11049 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11050 return list;
11052 if (c_parser_next_token_is (parser, CPP_NAME)
11053 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11055 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11056 if (strcmp ("alloc", p) == 0)
11057 kind = OMP_CLAUSE_MAP_ALLOC;
11058 else if (strcmp ("to", p) == 0)
11059 kind = OMP_CLAUSE_MAP_TO;
11060 else if (strcmp ("from", p) == 0)
11061 kind = OMP_CLAUSE_MAP_FROM;
11062 else if (strcmp ("tofrom", p) == 0)
11063 kind = OMP_CLAUSE_MAP_TOFROM;
11064 else
11066 c_parser_error (parser, "invalid map kind");
11067 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11068 "expected %<)%>");
11069 return list;
11071 c_parser_consume_token (parser);
11072 c_parser_consume_token (parser);
11075 nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
11077 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11078 OMP_CLAUSE_MAP_KIND (c) = kind;
11080 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11081 return nl;
11084 /* OpenMP 4.0:
11085 device ( expression ) */
11087 static tree
11088 c_parser_omp_clause_device (c_parser *parser, tree list)
11090 location_t clause_loc = c_parser_peek_token (parser)->location;
11091 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11093 tree c, t = c_parser_expr_no_commas (parser, NULL).value;
11094 mark_exp_read (t);
11095 t = c_fully_fold (t, false, NULL);
11097 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11099 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11101 c_parser_error (parser, "expected integer expression");
11102 return list;
11105 check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
11107 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
11108 OMP_CLAUSE_DEVICE_ID (c) = t;
11109 OMP_CLAUSE_CHAIN (c) = list;
11110 list = c;
11113 return list;
11116 /* OpenMP 4.0:
11117 dist_schedule ( static )
11118 dist_schedule ( static , expression ) */
11120 static tree
11121 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
11123 tree c, t = NULL_TREE;
11124 location_t loc = c_parser_peek_token (parser)->location;
11126 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11127 return list;
11129 if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
11131 c_parser_error (parser, "invalid dist_schedule kind");
11132 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11133 "expected %<)%>");
11134 return list;
11137 c_parser_consume_token (parser);
11138 if (c_parser_next_token_is (parser, CPP_COMMA))
11140 c_parser_consume_token (parser);
11142 t = c_parser_expr_no_commas (parser, NULL).value;
11143 mark_exp_read (t);
11144 t = c_fully_fold (t, false, NULL);
11145 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11147 else
11148 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11149 "expected %<,%> or %<)%>");
11151 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
11152 if (t == error_mark_node)
11153 return list;
11155 c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
11156 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
11157 OMP_CLAUSE_CHAIN (c) = list;
11158 return c;
11161 /* OpenMP 4.0:
11162 proc_bind ( proc-bind-kind )
11164 proc-bind-kind:
11165 master | close | spread */
11167 static tree
11168 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
11170 location_t clause_loc = c_parser_peek_token (parser)->location;
11171 enum omp_clause_proc_bind_kind kind;
11172 tree c;
11174 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11175 return list;
11177 if (c_parser_next_token_is (parser, CPP_NAME))
11179 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11180 if (strcmp ("master", p) == 0)
11181 kind = OMP_CLAUSE_PROC_BIND_MASTER;
11182 else if (strcmp ("close", p) == 0)
11183 kind = OMP_CLAUSE_PROC_BIND_CLOSE;
11184 else if (strcmp ("spread", p) == 0)
11185 kind = OMP_CLAUSE_PROC_BIND_SPREAD;
11186 else
11187 goto invalid_kind;
11189 else
11190 goto invalid_kind;
11192 c_parser_consume_token (parser);
11193 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11194 c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
11195 OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
11196 OMP_CLAUSE_CHAIN (c) = list;
11197 return c;
11199 invalid_kind:
11200 c_parser_error (parser, "invalid proc_bind kind");
11201 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11202 return list;
11205 /* OpenMP 4.0:
11206 to ( variable-list ) */
11208 static tree
11209 c_parser_omp_clause_to (c_parser *parser, tree list)
11211 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
11214 /* OpenMP 4.0:
11215 from ( variable-list ) */
11217 static tree
11218 c_parser_omp_clause_from (c_parser *parser, tree list)
11220 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
11223 /* OpenMP 4.0:
11224 uniform ( variable-list ) */
11226 static tree
11227 c_parser_omp_clause_uniform (c_parser *parser, tree list)
11229 /* The clauses location. */
11230 location_t loc = c_parser_peek_token (parser)->location;
11232 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11234 list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
11235 list);
11236 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11238 return list;
11241 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11242 is a bitmask in MASK. Return the list of clauses found. */
11244 static tree
11245 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
11246 const char *where, bool finish_p = true)
11248 tree clauses = NULL;
11249 bool first = true;
11251 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11253 location_t here;
11254 pragma_omp_clause c_kind;
11255 const char *c_name;
11256 tree prev = clauses;
11258 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11259 c_parser_consume_token (parser);
11261 here = c_parser_peek_token (parser)->location;
11262 c_kind = c_parser_omp_clause_name (parser);
11264 switch (c_kind)
11266 case PRAGMA_OMP_CLAUSE_COPY:
11267 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11268 c_name = "copy";
11269 break;
11270 case PRAGMA_OMP_CLAUSE_COPYIN:
11271 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11272 c_name = "copyin";
11273 break;
11274 case PRAGMA_OMP_CLAUSE_COPYOUT:
11275 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11276 c_name = "copyout";
11277 break;
11278 case PRAGMA_OMP_CLAUSE_CREATE:
11279 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11280 c_name = "create";
11281 break;
11282 case PRAGMA_OMP_CLAUSE_DELETE:
11283 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11284 c_name = "delete";
11285 break;
11286 case PRAGMA_OMP_CLAUSE_DEVICE:
11287 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11288 c_name = "device";
11289 break;
11290 case PRAGMA_OMP_CLAUSE_DEVICEPTR:
11291 clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
11292 c_name = "deviceptr";
11293 break;
11294 case PRAGMA_OMP_CLAUSE_HOST:
11295 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11296 c_name = "host";
11297 break;
11298 case PRAGMA_OMP_CLAUSE_IF:
11299 clauses = c_parser_omp_clause_if (parser, clauses);
11300 c_name = "if";
11301 break;
11302 case PRAGMA_OMP_CLAUSE_NUM_GANGS:
11303 clauses = c_parser_omp_clause_num_gangs (parser, clauses);
11304 c_name = "num_gangs";
11305 break;
11306 case PRAGMA_OMP_CLAUSE_NUM_WORKERS:
11307 clauses = c_parser_omp_clause_num_workers (parser, clauses);
11308 c_name = "num_workers";
11309 break;
11310 case PRAGMA_OMP_CLAUSE_PRESENT:
11311 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11312 c_name = "present";
11313 break;
11314 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY:
11315 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11316 c_name = "present_or_copy";
11317 break;
11318 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN:
11319 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11320 c_name = "present_or_copyin";
11321 break;
11322 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT:
11323 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11324 c_name = "present_or_copyout";
11325 break;
11326 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE:
11327 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11328 c_name = "present_or_create";
11329 break;
11330 case PRAGMA_OMP_CLAUSE_SELF:
11331 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11332 c_name = "self";
11333 break;
11334 case PRAGMA_OMP_CLAUSE_VECTOR_LENGTH:
11335 clauses = c_parser_omp_clause_vector_length (parser, clauses);
11336 c_name = "vector_length";
11337 break;
11338 default:
11339 c_parser_error (parser, "expected clause");
11340 goto saw_error;
11343 first = false;
11345 if (((mask >> c_kind) & 1) == 0 && !parser->error)
11347 /* Remove the invalid clause(s) from the list to avoid
11348 confusing the rest of the compiler. */
11349 clauses = prev;
11350 error_at (here, "%qs is not valid for %qs", c_name, where);
11354 saw_error:
11355 c_parser_skip_to_pragma_eol (parser);
11357 if (finish_p)
11358 return c_finish_omp_clauses (clauses);
11360 return clauses;
11363 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11364 is a bitmask in MASK. Return the list of clauses found. */
11366 static tree
11367 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
11368 const char *where, bool finish_p = true)
11370 tree clauses = NULL;
11371 bool first = true, cilk_simd_fn = false;
11373 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11375 location_t here;
11376 pragma_omp_clause c_kind;
11377 const char *c_name;
11378 tree prev = clauses;
11380 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11381 c_parser_consume_token (parser);
11383 here = c_parser_peek_token (parser)->location;
11384 c_kind = c_parser_omp_clause_name (parser);
11386 switch (c_kind)
11388 case PRAGMA_OMP_CLAUSE_COLLAPSE:
11389 clauses = c_parser_omp_clause_collapse (parser, clauses);
11390 c_name = "collapse";
11391 break;
11392 case PRAGMA_OMP_CLAUSE_COPYIN:
11393 clauses = c_parser_omp_clause_copyin (parser, clauses);
11394 c_name = "copyin";
11395 break;
11396 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
11397 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
11398 c_name = "copyprivate";
11399 break;
11400 case PRAGMA_OMP_CLAUSE_DEFAULT:
11401 clauses = c_parser_omp_clause_default (parser, clauses);
11402 c_name = "default";
11403 break;
11404 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
11405 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
11406 c_name = "firstprivate";
11407 break;
11408 case PRAGMA_OMP_CLAUSE_FINAL:
11409 clauses = c_parser_omp_clause_final (parser, clauses);
11410 c_name = "final";
11411 break;
11412 case PRAGMA_OMP_CLAUSE_IF:
11413 clauses = c_parser_omp_clause_if (parser, clauses);
11414 c_name = "if";
11415 break;
11416 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
11417 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
11418 c_name = "lastprivate";
11419 break;
11420 case PRAGMA_OMP_CLAUSE_MERGEABLE:
11421 clauses = c_parser_omp_clause_mergeable (parser, clauses);
11422 c_name = "mergeable";
11423 break;
11424 case PRAGMA_OMP_CLAUSE_NOWAIT:
11425 clauses = c_parser_omp_clause_nowait (parser, clauses);
11426 c_name = "nowait";
11427 break;
11428 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
11429 clauses = c_parser_omp_clause_num_threads (parser, clauses);
11430 c_name = "num_threads";
11431 break;
11432 case PRAGMA_OMP_CLAUSE_ORDERED:
11433 clauses = c_parser_omp_clause_ordered (parser, clauses);
11434 c_name = "ordered";
11435 break;
11436 case PRAGMA_OMP_CLAUSE_PRIVATE:
11437 clauses = c_parser_omp_clause_private (parser, clauses);
11438 c_name = "private";
11439 break;
11440 case PRAGMA_OMP_CLAUSE_REDUCTION:
11441 clauses = c_parser_omp_clause_reduction (parser, clauses);
11442 c_name = "reduction";
11443 break;
11444 case PRAGMA_OMP_CLAUSE_SCHEDULE:
11445 clauses = c_parser_omp_clause_schedule (parser, clauses);
11446 c_name = "schedule";
11447 break;
11448 case PRAGMA_OMP_CLAUSE_SHARED:
11449 clauses = c_parser_omp_clause_shared (parser, clauses);
11450 c_name = "shared";
11451 break;
11452 case PRAGMA_OMP_CLAUSE_UNTIED:
11453 clauses = c_parser_omp_clause_untied (parser, clauses);
11454 c_name = "untied";
11455 break;
11456 case PRAGMA_OMP_CLAUSE_INBRANCH:
11457 case PRAGMA_CILK_CLAUSE_MASK:
11458 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
11459 clauses);
11460 c_name = "inbranch";
11461 break;
11462 case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
11463 case PRAGMA_CILK_CLAUSE_NOMASK:
11464 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
11465 clauses);
11466 c_name = "notinbranch";
11467 break;
11468 case PRAGMA_OMP_CLAUSE_PARALLEL:
11469 clauses
11470 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
11471 clauses);
11472 c_name = "parallel";
11473 if (!first)
11475 clause_not_first:
11476 error_at (here, "%qs must be the first clause of %qs",
11477 c_name, where);
11478 clauses = prev;
11480 break;
11481 case PRAGMA_OMP_CLAUSE_FOR:
11482 clauses
11483 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
11484 clauses);
11485 c_name = "for";
11486 if (!first)
11487 goto clause_not_first;
11488 break;
11489 case PRAGMA_OMP_CLAUSE_SECTIONS:
11490 clauses
11491 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
11492 clauses);
11493 c_name = "sections";
11494 if (!first)
11495 goto clause_not_first;
11496 break;
11497 case PRAGMA_OMP_CLAUSE_TASKGROUP:
11498 clauses
11499 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
11500 clauses);
11501 c_name = "taskgroup";
11502 if (!first)
11503 goto clause_not_first;
11504 break;
11505 case PRAGMA_OMP_CLAUSE_TO:
11506 clauses = c_parser_omp_clause_to (parser, clauses);
11507 c_name = "to";
11508 break;
11509 case PRAGMA_OMP_CLAUSE_FROM:
11510 clauses = c_parser_omp_clause_from (parser, clauses);
11511 c_name = "from";
11512 break;
11513 case PRAGMA_OMP_CLAUSE_UNIFORM:
11514 clauses = c_parser_omp_clause_uniform (parser, clauses);
11515 c_name = "uniform";
11516 break;
11517 case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
11518 clauses = c_parser_omp_clause_num_teams (parser, clauses);
11519 c_name = "num_teams";
11520 break;
11521 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
11522 clauses = c_parser_omp_clause_thread_limit (parser, clauses);
11523 c_name = "thread_limit";
11524 break;
11525 case PRAGMA_OMP_CLAUSE_ALIGNED:
11526 clauses = c_parser_omp_clause_aligned (parser, clauses);
11527 c_name = "aligned";
11528 break;
11529 case PRAGMA_OMP_CLAUSE_LINEAR:
11530 if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0)
11531 cilk_simd_fn = true;
11532 clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn);
11533 c_name = "linear";
11534 break;
11535 case PRAGMA_OMP_CLAUSE_DEPEND:
11536 clauses = c_parser_omp_clause_depend (parser, clauses);
11537 c_name = "depend";
11538 break;
11539 case PRAGMA_OMP_CLAUSE_MAP:
11540 clauses = c_parser_omp_clause_map (parser, clauses);
11541 c_name = "map";
11542 break;
11543 case PRAGMA_OMP_CLAUSE_DEVICE:
11544 clauses = c_parser_omp_clause_device (parser, clauses);
11545 c_name = "device";
11546 break;
11547 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
11548 clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
11549 c_name = "dist_schedule";
11550 break;
11551 case PRAGMA_OMP_CLAUSE_PROC_BIND:
11552 clauses = c_parser_omp_clause_proc_bind (parser, clauses);
11553 c_name = "proc_bind";
11554 break;
11555 case PRAGMA_OMP_CLAUSE_SAFELEN:
11556 clauses = c_parser_omp_clause_safelen (parser, clauses);
11557 c_name = "safelen";
11558 break;
11559 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
11560 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true);
11561 c_name = "simdlen";
11562 break;
11563 case PRAGMA_OMP_CLAUSE_SIMDLEN:
11564 clauses = c_parser_omp_clause_simdlen (parser, clauses);
11565 c_name = "simdlen";
11566 break;
11567 default:
11568 c_parser_error (parser, "expected clause");
11569 goto saw_error;
11572 first = false;
11574 if (((mask >> c_kind) & 1) == 0 && !parser->error)
11576 /* Remove the invalid clause(s) from the list to avoid
11577 confusing the rest of the compiler. */
11578 clauses = prev;
11579 error_at (here, "%qs is not valid for %qs", c_name, where);
11583 saw_error:
11584 c_parser_skip_to_pragma_eol (parser);
11586 if (finish_p)
11587 return c_finish_omp_clauses (clauses);
11589 return clauses;
11592 /* OpenACC 2.0, OpenMP 2.5:
11593 structured-block:
11594 statement
11596 In practice, we're also interested in adding the statement to an
11597 outer node. So it is convenient if we work around the fact that
11598 c_parser_statement calls add_stmt. */
11600 static tree
11601 c_parser_omp_structured_block (c_parser *parser)
11603 tree stmt = push_stmt_list ();
11604 c_parser_statement (parser);
11605 return pop_stmt_list (stmt);
11608 /* OpenACC 2.0:
11609 # pragma acc data oacc-data-clause[optseq] new-line
11610 structured-block
11612 LOC is the location of the #pragma token.
11615 #define OACC_DATA_CLAUSE_MASK \
11616 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11622 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) )
11628 static tree
11629 c_parser_oacc_data (location_t loc, c_parser *parser)
11631 tree stmt, clauses, block;
11633 clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
11634 "#pragma acc data");
11636 block = c_begin_omp_parallel ();
11637 add_stmt (c_parser_omp_structured_block (parser));
11639 stmt = c_finish_oacc_data (loc, clauses, block);
11641 return stmt;
11644 /* OpenACC 2.0:
11645 # pragma acc kernels oacc-kernels-clause[optseq] new-line
11646 structured-block
11648 LOC is the location of the #pragma token.
11651 #define OACC_KERNELS_CLAUSE_MASK \
11652 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11653 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11654 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11655 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11656 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11657 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11658 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11659 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11660 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) )
11664 static tree
11665 c_parser_oacc_kernels (location_t loc, c_parser *parser, char *p_name)
11667 tree stmt, clauses = NULL_TREE, block;
11669 strcat (p_name, " kernels");
11671 if (c_parser_next_token_is (parser, CPP_NAME))
11673 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11674 if (strcmp (p, "loop") == 0)
11676 c_parser_consume_token (parser);
11677 block = c_begin_omp_parallel ();
11678 c_parser_oacc_loop (loc, parser, p_name);
11679 stmt = c_finish_oacc_kernels (loc, clauses, block);
11680 OACC_KERNELS_COMBINED (stmt) = 1;
11681 return stmt;
11685 clauses = c_parser_oacc_all_clauses (parser, OACC_KERNELS_CLAUSE_MASK,
11686 p_name);
11688 block = c_begin_omp_parallel ();
11689 add_stmt (c_parser_omp_structured_block (parser));
11691 stmt = c_finish_oacc_kernels (loc, clauses, block);
11693 return stmt;
11696 /* OpenACC 2.0:
11697 # pragma acc loop oacc-loop-clause[optseq] new-line
11698 structured-block
11700 LOC is the location of the #pragma token.
11703 #define OACC_LOOP_CLAUSE_MASK \
11704 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONE)
11706 static tree
11707 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name)
11709 tree stmt, clauses, block;
11711 strcat (p_name, " loop");
11713 clauses = c_parser_oacc_all_clauses (parser, OACC_LOOP_CLAUSE_MASK, p_name);
11715 block = c_begin_compound_stmt (true);
11716 stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL);
11717 block = c_end_compound_stmt (loc, block, true);
11718 add_stmt (block);
11720 return stmt;
11723 /* OpenACC 2.0:
11724 # pragma acc parallel oacc-parallel-clause[optseq] new-line
11725 structured-block
11727 LOC is the location of the #pragma token.
11730 #define OACC_PARALLEL_CLAUSE_MASK \
11731 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_GANGS) \
11738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_WORKERS) \
11739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
11744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_VECTOR_LENGTH) )
11746 static tree
11747 c_parser_oacc_parallel (location_t loc, c_parser *parser, char *p_name)
11749 tree stmt, clauses = NULL_TREE, block;
11751 strcat (p_name, " parallel");
11753 if (c_parser_next_token_is (parser, CPP_NAME))
11755 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11756 if (strcmp (p, "loop") == 0)
11758 c_parser_consume_token (parser);
11759 block = c_begin_omp_parallel ();
11760 c_parser_oacc_loop (loc, parser, p_name);
11761 stmt = c_finish_oacc_parallel (loc, clauses, block);
11762 OACC_PARALLEL_COMBINED (stmt) = 1;
11763 return stmt;
11767 clauses = c_parser_oacc_all_clauses (parser, OACC_PARALLEL_CLAUSE_MASK,
11768 p_name);
11770 block = c_begin_omp_parallel ();
11771 add_stmt (c_parser_omp_structured_block (parser));
11773 stmt = c_finish_oacc_parallel (loc, clauses, block);
11775 return stmt;
11778 /* OpenACC 2.0:
11779 # pragma acc update oacc-update-clause[optseq] new-line
11782 #define OACC_UPDATE_CLAUSE_MASK \
11783 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
11784 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HOST) \
11785 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11786 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SELF) )
11788 static void
11789 c_parser_oacc_update (c_parser *parser)
11791 location_t loc = c_parser_peek_token (parser)->location;
11793 c_parser_consume_pragma (parser);
11795 tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
11796 "#pragma acc update");
11797 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
11799 error_at (loc,
11800 "%<#pragma acc update%> must contain at least one "
11801 "%<device%> or %<host/self%> clause");
11802 return;
11805 tree stmt = make_node (OACC_UPDATE);
11806 TREE_TYPE (stmt) = void_type_node;
11807 OACC_UPDATE_CLAUSES (stmt) = clauses;
11808 SET_EXPR_LOCATION (stmt, loc);
11809 add_stmt (stmt);
11812 /* OpenMP 2.5:
11813 # pragma omp atomic new-line
11814 expression-stmt
11816 expression-stmt:
11817 x binop= expr | x++ | ++x | x-- | --x
11818 binop:
11819 +, *, -, /, &, ^, |, <<, >>
11821 where x is an lvalue expression with scalar type.
11823 OpenMP 3.1:
11824 # pragma omp atomic new-line
11825 update-stmt
11827 # pragma omp atomic read new-line
11828 read-stmt
11830 # pragma omp atomic write new-line
11831 write-stmt
11833 # pragma omp atomic update new-line
11834 update-stmt
11836 # pragma omp atomic capture new-line
11837 capture-stmt
11839 # pragma omp atomic capture new-line
11840 capture-block
11842 read-stmt:
11843 v = x
11844 write-stmt:
11845 x = expr
11846 update-stmt:
11847 expression-stmt | x = x binop expr
11848 capture-stmt:
11849 v = expression-stmt
11850 capture-block:
11851 { v = x; update-stmt; } | { update-stmt; v = x; }
11853 OpenMP 4.0:
11854 update-stmt:
11855 expression-stmt | x = x binop expr | x = expr binop x
11856 capture-stmt:
11857 v = update-stmt
11858 capture-block:
11859 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11861 where x and v are lvalue expressions with scalar type.
11863 LOC is the location of the #pragma token. */
11865 static void
11866 c_parser_omp_atomic (location_t loc, c_parser *parser)
11868 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
11869 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
11870 tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
11871 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
11872 struct c_expr expr;
11873 location_t eloc;
11874 bool structured_block = false;
11875 bool swapped = false;
11876 bool seq_cst = false;
11878 if (c_parser_next_token_is (parser, CPP_NAME))
11880 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11881 if (!strcmp (p, "seq_cst"))
11883 seq_cst = true;
11884 c_parser_consume_token (parser);
11885 if (c_parser_next_token_is (parser, CPP_COMMA)
11886 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11887 c_parser_consume_token (parser);
11890 if (c_parser_next_token_is (parser, CPP_NAME))
11892 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11894 if (!strcmp (p, "read"))
11895 code = OMP_ATOMIC_READ;
11896 else if (!strcmp (p, "write"))
11897 code = NOP_EXPR;
11898 else if (!strcmp (p, "update"))
11899 code = OMP_ATOMIC;
11900 else if (!strcmp (p, "capture"))
11901 code = OMP_ATOMIC_CAPTURE_NEW;
11902 else
11903 p = NULL;
11904 if (p)
11905 c_parser_consume_token (parser);
11907 if (!seq_cst)
11909 if (c_parser_next_token_is (parser, CPP_COMMA)
11910 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11911 c_parser_consume_token (parser);
11913 if (c_parser_next_token_is (parser, CPP_NAME))
11915 const char *p
11916 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11917 if (!strcmp (p, "seq_cst"))
11919 seq_cst = true;
11920 c_parser_consume_token (parser);
11924 c_parser_skip_to_pragma_eol (parser);
11926 switch (code)
11928 case OMP_ATOMIC_READ:
11929 case NOP_EXPR: /* atomic write */
11930 v = c_parser_unary_expression (parser).value;
11931 v = c_fully_fold (v, false, NULL);
11932 if (v == error_mark_node)
11933 goto saw_error;
11934 loc = c_parser_peek_token (parser)->location;
11935 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
11936 goto saw_error;
11937 if (code == NOP_EXPR)
11938 lhs = c_parser_expression (parser).value;
11939 else
11940 lhs = c_parser_unary_expression (parser).value;
11941 lhs = c_fully_fold (lhs, false, NULL);
11942 if (lhs == error_mark_node)
11943 goto saw_error;
11944 if (code == NOP_EXPR)
11946 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11947 opcode. */
11948 code = OMP_ATOMIC;
11949 rhs = lhs;
11950 lhs = v;
11951 v = NULL_TREE;
11953 goto done;
11954 case OMP_ATOMIC_CAPTURE_NEW:
11955 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
11957 c_parser_consume_token (parser);
11958 structured_block = true;
11960 else
11962 v = c_parser_unary_expression (parser).value;
11963 v = c_fully_fold (v, false, NULL);
11964 if (v == error_mark_node)
11965 goto saw_error;
11966 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
11967 goto saw_error;
11969 break;
11970 default:
11971 break;
11974 /* For structured_block case we don't know yet whether
11975 old or new x should be captured. */
11976 restart:
11977 eloc = c_parser_peek_token (parser)->location;
11978 expr = c_parser_unary_expression (parser);
11979 lhs = expr.value;
11980 expr = default_function_array_conversion (eloc, expr);
11981 unfolded_lhs = expr.value;
11982 lhs = c_fully_fold (lhs, false, NULL);
11983 orig_lhs = lhs;
11984 switch (TREE_CODE (lhs))
11986 case ERROR_MARK:
11987 saw_error:
11988 c_parser_skip_to_end_of_block_or_statement (parser);
11989 if (structured_block)
11991 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
11992 c_parser_consume_token (parser);
11993 else if (code == OMP_ATOMIC_CAPTURE_NEW)
11995 c_parser_skip_to_end_of_block_or_statement (parser);
11996 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
11997 c_parser_consume_token (parser);
12000 return;
12002 case POSTINCREMENT_EXPR:
12003 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12004 code = OMP_ATOMIC_CAPTURE_OLD;
12005 /* FALLTHROUGH */
12006 case PREINCREMENT_EXPR:
12007 lhs = TREE_OPERAND (lhs, 0);
12008 unfolded_lhs = NULL_TREE;
12009 opcode = PLUS_EXPR;
12010 rhs = integer_one_node;
12011 break;
12013 case POSTDECREMENT_EXPR:
12014 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12015 code = OMP_ATOMIC_CAPTURE_OLD;
12016 /* FALLTHROUGH */
12017 case PREDECREMENT_EXPR:
12018 lhs = TREE_OPERAND (lhs, 0);
12019 unfolded_lhs = NULL_TREE;
12020 opcode = MINUS_EXPR;
12021 rhs = integer_one_node;
12022 break;
12024 case COMPOUND_EXPR:
12025 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
12026 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
12027 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
12028 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
12029 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12030 (TREE_OPERAND (lhs, 1), 0), 0)))
12031 == BOOLEAN_TYPE)
12032 /* Undo effects of boolean_increment for post {in,de}crement. */
12033 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
12034 /* FALLTHRU */
12035 case MODIFY_EXPR:
12036 if (TREE_CODE (lhs) == MODIFY_EXPR
12037 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
12039 /* Undo effects of boolean_increment. */
12040 if (integer_onep (TREE_OPERAND (lhs, 1)))
12042 /* This is pre or post increment. */
12043 rhs = TREE_OPERAND (lhs, 1);
12044 lhs = TREE_OPERAND (lhs, 0);
12045 unfolded_lhs = NULL_TREE;
12046 opcode = NOP_EXPR;
12047 if (code == OMP_ATOMIC_CAPTURE_NEW
12048 && !structured_block
12049 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12050 code = OMP_ATOMIC_CAPTURE_OLD;
12051 break;
12053 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
12054 && TREE_OPERAND (lhs, 0)
12055 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
12057 /* This is pre or post decrement. */
12058 rhs = TREE_OPERAND (lhs, 1);
12059 lhs = TREE_OPERAND (lhs, 0);
12060 unfolded_lhs = NULL_TREE;
12061 opcode = NOP_EXPR;
12062 if (code == OMP_ATOMIC_CAPTURE_NEW
12063 && !structured_block
12064 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12065 code = OMP_ATOMIC_CAPTURE_OLD;
12066 break;
12069 /* FALLTHRU */
12070 default:
12071 switch (c_parser_peek_token (parser)->type)
12073 case CPP_MULT_EQ:
12074 opcode = MULT_EXPR;
12075 break;
12076 case CPP_DIV_EQ:
12077 opcode = TRUNC_DIV_EXPR;
12078 break;
12079 case CPP_PLUS_EQ:
12080 opcode = PLUS_EXPR;
12081 break;
12082 case CPP_MINUS_EQ:
12083 opcode = MINUS_EXPR;
12084 break;
12085 case CPP_LSHIFT_EQ:
12086 opcode = LSHIFT_EXPR;
12087 break;
12088 case CPP_RSHIFT_EQ:
12089 opcode = RSHIFT_EXPR;
12090 break;
12091 case CPP_AND_EQ:
12092 opcode = BIT_AND_EXPR;
12093 break;
12094 case CPP_OR_EQ:
12095 opcode = BIT_IOR_EXPR;
12096 break;
12097 case CPP_XOR_EQ:
12098 opcode = BIT_XOR_EXPR;
12099 break;
12100 case CPP_EQ:
12101 c_parser_consume_token (parser);
12102 eloc = c_parser_peek_token (parser)->location;
12103 expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
12104 rhs1 = expr.value;
12105 switch (TREE_CODE (rhs1))
12107 case MULT_EXPR:
12108 case TRUNC_DIV_EXPR:
12109 case PLUS_EXPR:
12110 case MINUS_EXPR:
12111 case LSHIFT_EXPR:
12112 case RSHIFT_EXPR:
12113 case BIT_AND_EXPR:
12114 case BIT_IOR_EXPR:
12115 case BIT_XOR_EXPR:
12116 if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
12118 opcode = TREE_CODE (rhs1);
12119 rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12120 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12121 goto stmt_done;
12123 if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
12125 opcode = TREE_CODE (rhs1);
12126 rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12127 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12128 swapped = !commutative_tree_code (opcode);
12129 goto stmt_done;
12131 break;
12132 case ERROR_MARK:
12133 goto saw_error;
12134 default:
12135 break;
12137 if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
12139 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12141 code = OMP_ATOMIC_CAPTURE_OLD;
12142 v = lhs;
12143 lhs = NULL_TREE;
12144 expr = default_function_array_read_conversion (eloc, expr);
12145 unfolded_lhs1 = expr.value;
12146 lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
12147 rhs1 = NULL_TREE;
12148 c_parser_consume_token (parser);
12149 goto restart;
12151 if (structured_block)
12153 opcode = NOP_EXPR;
12154 expr = default_function_array_read_conversion (eloc, expr);
12155 rhs = c_fully_fold (expr.value, false, NULL);
12156 rhs1 = NULL_TREE;
12157 goto stmt_done;
12160 c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
12161 goto saw_error;
12162 default:
12163 c_parser_error (parser,
12164 "invalid operator for %<#pragma omp atomic%>");
12165 goto saw_error;
12168 /* Arrange to pass the location of the assignment operator to
12169 c_finish_omp_atomic. */
12170 loc = c_parser_peek_token (parser)->location;
12171 c_parser_consume_token (parser);
12172 eloc = c_parser_peek_token (parser)->location;
12173 expr = c_parser_expression (parser);
12174 expr = default_function_array_read_conversion (eloc, expr);
12175 rhs = expr.value;
12176 rhs = c_fully_fold (rhs, false, NULL);
12177 break;
12179 stmt_done:
12180 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12182 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
12183 goto saw_error;
12184 v = c_parser_unary_expression (parser).value;
12185 v = c_fully_fold (v, false, NULL);
12186 if (v == error_mark_node)
12187 goto saw_error;
12188 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12189 goto saw_error;
12190 eloc = c_parser_peek_token (parser)->location;
12191 expr = c_parser_unary_expression (parser);
12192 lhs1 = expr.value;
12193 expr = default_function_array_read_conversion (eloc, expr);
12194 unfolded_lhs1 = expr.value;
12195 lhs1 = c_fully_fold (lhs1, false, NULL);
12196 if (lhs1 == error_mark_node)
12197 goto saw_error;
12199 if (structured_block)
12201 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12202 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
12204 done:
12205 if (unfolded_lhs && unfolded_lhs1
12206 && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
12208 error ("%<#pragma omp atomic capture%> uses two different "
12209 "expressions for memory");
12210 stmt = error_mark_node;
12212 else
12213 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
12214 swapped, seq_cst);
12215 if (stmt != error_mark_node)
12216 add_stmt (stmt);
12218 if (!structured_block)
12219 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12223 /* OpenMP 2.5:
12224 # pragma omp barrier new-line
12227 static void
12228 c_parser_omp_barrier (c_parser *parser)
12230 location_t loc = c_parser_peek_token (parser)->location;
12231 c_parser_consume_pragma (parser);
12232 c_parser_skip_to_pragma_eol (parser);
12234 c_finish_omp_barrier (loc);
12237 /* OpenMP 2.5:
12238 # pragma omp critical [(name)] new-line
12239 structured-block
12241 LOC is the location of the #pragma itself. */
12243 static tree
12244 c_parser_omp_critical (location_t loc, c_parser *parser)
12246 tree stmt, name = NULL;
12248 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12250 c_parser_consume_token (parser);
12251 if (c_parser_next_token_is (parser, CPP_NAME))
12253 name = c_parser_peek_token (parser)->value;
12254 c_parser_consume_token (parser);
12255 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12257 else
12258 c_parser_error (parser, "expected identifier");
12260 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12261 c_parser_error (parser, "expected %<(%> or end of line");
12262 c_parser_skip_to_pragma_eol (parser);
12264 stmt = c_parser_omp_structured_block (parser);
12265 return c_finish_omp_critical (loc, stmt, name);
12268 /* OpenMP 2.5:
12269 # pragma omp flush flush-vars[opt] new-line
12271 flush-vars:
12272 ( variable-list ) */
12274 static void
12275 c_parser_omp_flush (c_parser *parser)
12277 location_t loc = c_parser_peek_token (parser)->location;
12278 c_parser_consume_pragma (parser);
12279 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12280 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
12281 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12282 c_parser_error (parser, "expected %<(%> or end of line");
12283 c_parser_skip_to_pragma_eol (parser);
12285 c_finish_omp_flush (loc);
12288 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12289 The real trick here is to determine the loop control variable early
12290 so that we can push a new decl if necessary to make it private.
12291 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12292 respectively. */
12294 static tree
12295 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
12296 tree clauses, tree *cclauses)
12298 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
12299 tree declv, condv, incrv, initv, ret = NULL;
12300 bool fail = false, open_brace_parsed = false;
12301 int i, collapse = 1, nbraces = 0;
12302 location_t for_loc;
12303 vec<tree, va_gc> *for_block = make_tree_vector ();
12305 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
12306 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
12308 gcc_assert (code != OACC_LOOP);
12309 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
12312 gcc_assert (collapse >= 1);
12314 declv = make_tree_vec (collapse);
12315 initv = make_tree_vec (collapse);
12316 condv = make_tree_vec (collapse);
12317 incrv = make_tree_vec (collapse);
12319 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
12321 c_parser_error (parser, "for statement expected");
12322 return NULL;
12324 for_loc = c_parser_peek_token (parser)->location;
12325 c_parser_consume_token (parser);
12327 for (i = 0; i < collapse; i++)
12329 int bracecount = 0;
12331 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12332 goto pop_scopes;
12334 /* Parse the initialization declaration or expression. */
12335 if (c_parser_next_tokens_start_declaration (parser))
12337 if (i > 0)
12338 vec_safe_push (for_block, c_begin_compound_stmt (true));
12339 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
12340 NULL, vNULL);
12341 decl = check_for_loop_decls (for_loc, flag_isoc99);
12342 if (decl == NULL)
12343 goto error_init;
12344 if (DECL_INITIAL (decl) == error_mark_node)
12345 decl = error_mark_node;
12346 init = decl;
12348 else if (c_parser_next_token_is (parser, CPP_NAME)
12349 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
12351 struct c_expr decl_exp;
12352 struct c_expr init_exp;
12353 location_t init_loc;
12355 decl_exp = c_parser_postfix_expression (parser);
12356 decl = decl_exp.value;
12358 c_parser_require (parser, CPP_EQ, "expected %<=%>");
12360 init_loc = c_parser_peek_token (parser)->location;
12361 init_exp = c_parser_expr_no_commas (parser, NULL);
12362 init_exp = default_function_array_read_conversion (init_loc,
12363 init_exp);
12364 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
12365 NOP_EXPR, init_loc, init_exp.value,
12366 init_exp.original_type);
12367 init = c_process_expr_stmt (init_loc, init);
12369 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12371 else
12373 error_init:
12374 c_parser_error (parser,
12375 "expected iteration declaration or initialization");
12376 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12377 "expected %<)%>");
12378 fail = true;
12379 goto parse_next;
12382 /* Parse the loop condition. */
12383 cond = NULL_TREE;
12384 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
12386 location_t cond_loc = c_parser_peek_token (parser)->location;
12387 struct c_expr cond_expr
12388 = c_parser_binary_expression (parser, NULL, NULL_TREE);
12390 cond = cond_expr.value;
12391 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
12392 cond = c_fully_fold (cond, false, NULL);
12393 switch (cond_expr.original_code)
12395 case GT_EXPR:
12396 case GE_EXPR:
12397 case LT_EXPR:
12398 case LE_EXPR:
12399 break;
12400 case NE_EXPR:
12401 if (code == CILK_SIMD)
12402 break;
12403 /* FALLTHRU. */
12404 default:
12405 /* Can't be cond = error_mark_node, because we want to preserve
12406 the location until c_finish_omp_for. */
12407 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
12408 break;
12410 protected_set_expr_location (cond, cond_loc);
12412 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12414 /* Parse the increment expression. */
12415 incr = NULL_TREE;
12416 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
12418 location_t incr_loc = c_parser_peek_token (parser)->location;
12420 incr = c_process_expr_stmt (incr_loc,
12421 c_parser_expression (parser).value);
12423 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12425 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
12426 fail = true;
12427 else
12429 TREE_VEC_ELT (declv, i) = decl;
12430 TREE_VEC_ELT (initv, i) = init;
12431 TREE_VEC_ELT (condv, i) = cond;
12432 TREE_VEC_ELT (incrv, i) = incr;
12435 parse_next:
12436 if (i == collapse - 1)
12437 break;
12439 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12440 in between the collapsed for loops to be still considered perfectly
12441 nested. Hopefully the final version clarifies this.
12442 For now handle (multiple) {'s and empty statements. */
12445 if (c_parser_next_token_is_keyword (parser, RID_FOR))
12447 c_parser_consume_token (parser);
12448 break;
12450 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
12452 c_parser_consume_token (parser);
12453 bracecount++;
12455 else if (bracecount
12456 && c_parser_next_token_is (parser, CPP_SEMICOLON))
12457 c_parser_consume_token (parser);
12458 else
12460 c_parser_error (parser, "not enough perfectly nested loops");
12461 if (bracecount)
12463 open_brace_parsed = true;
12464 bracecount--;
12466 fail = true;
12467 collapse = 0;
12468 break;
12471 while (1);
12473 nbraces += bracecount;
12476 save_break = c_break_label;
12477 if (code == CILK_SIMD)
12478 c_break_label = build_int_cst (size_type_node, 2);
12479 else
12480 c_break_label = size_one_node;
12481 save_cont = c_cont_label;
12482 c_cont_label = NULL_TREE;
12483 body = push_stmt_list ();
12485 if (open_brace_parsed)
12487 location_t here = c_parser_peek_token (parser)->location;
12488 stmt = c_begin_compound_stmt (true);
12489 c_parser_compound_statement_nostart (parser);
12490 add_stmt (c_end_compound_stmt (here, stmt, true));
12492 else
12493 add_stmt (c_parser_c99_block_statement (parser));
12494 if (c_cont_label)
12496 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
12497 SET_EXPR_LOCATION (t, loc);
12498 add_stmt (t);
12501 body = pop_stmt_list (body);
12502 c_break_label = save_break;
12503 c_cont_label = save_cont;
12505 while (nbraces)
12507 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12509 c_parser_consume_token (parser);
12510 nbraces--;
12512 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
12513 c_parser_consume_token (parser);
12514 else
12516 c_parser_error (parser, "collapsed loops not perfectly nested");
12517 while (nbraces)
12519 location_t here = c_parser_peek_token (parser)->location;
12520 stmt = c_begin_compound_stmt (true);
12521 add_stmt (body);
12522 c_parser_compound_statement_nostart (parser);
12523 body = c_end_compound_stmt (here, stmt, true);
12524 nbraces--;
12526 goto pop_scopes;
12530 /* Only bother calling c_finish_omp_for if we haven't already generated
12531 an error from the initialization parsing. */
12532 if (!fail)
12534 stmt = c_finish_omp_for (loc, code, declv, initv, condv,
12535 incrv, body, NULL);
12536 if (stmt)
12538 if (cclauses != NULL
12539 && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
12541 gcc_assert (code != OACC_LOOP);
12542 tree *c;
12543 for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
12544 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
12545 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
12546 c = &OMP_CLAUSE_CHAIN (*c);
12547 else
12549 for (i = 0; i < collapse; i++)
12550 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
12551 break;
12552 if (i == collapse)
12553 c = &OMP_CLAUSE_CHAIN (*c);
12554 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
12556 error_at (loc,
12557 "iteration variable %qD should not be firstprivate",
12558 OMP_CLAUSE_DECL (*c));
12559 *c = OMP_CLAUSE_CHAIN (*c);
12561 else
12563 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
12564 change it to shared (decl) in
12565 OMP_PARALLEL_CLAUSES. */
12566 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
12567 OMP_CLAUSE_LASTPRIVATE);
12568 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
12569 OMP_CLAUSE_CHAIN (l) = clauses;
12570 clauses = l;
12571 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
12575 OMP_FOR_CLAUSES (stmt) = clauses;
12577 ret = stmt;
12579 pop_scopes:
12580 while (!for_block->is_empty ())
12582 /* FIXME diagnostics: LOC below should be the actual location of
12583 this particular for block. We need to build a list of
12584 locations to go along with FOR_BLOCK. */
12585 stmt = c_end_compound_stmt (loc, for_block->pop (), true);
12586 add_stmt (stmt);
12588 release_tree_vector (for_block);
12589 return ret;
12592 /* Helper function for OpenMP parsing, split clauses and call
12593 finish_omp_clauses on each of the set of clauses afterwards. */
12595 static void
12596 omp_split_clauses (location_t loc, enum tree_code code,
12597 omp_clause_mask mask, tree clauses, tree *cclauses)
12599 int i;
12600 c_omp_split_clauses (loc, code, mask, clauses, cclauses);
12601 for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
12602 if (cclauses[i])
12603 cclauses[i] = c_finish_omp_clauses (cclauses[i]);
12606 /* OpenMP 4.0:
12607 #pragma omp simd simd-clause[optseq] new-line
12608 for-loop
12610 LOC is the location of the #pragma token.
12613 #define OMP_SIMD_CLAUSE_MASK \
12614 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12622 static tree
12623 c_parser_omp_simd (location_t loc, c_parser *parser,
12624 char *p_name, omp_clause_mask mask, tree *cclauses)
12626 tree block, clauses, ret;
12628 strcat (p_name, " simd");
12629 mask |= OMP_SIMD_CLAUSE_MASK;
12630 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
12632 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
12633 if (cclauses)
12635 omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
12636 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
12639 block = c_begin_compound_stmt (true);
12640 ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses);
12641 block = c_end_compound_stmt (loc, block, true);
12642 add_stmt (block);
12644 return ret;
12647 /* OpenMP 2.5:
12648 #pragma omp for for-clause[optseq] new-line
12649 for-loop
12651 OpenMP 4.0:
12652 #pragma omp for simd for-simd-clause[optseq] new-line
12653 for-loop
12655 LOC is the location of the #pragma token.
12658 #define OMP_FOR_CLAUSE_MASK \
12659 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12660 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12663 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12664 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12665 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12666 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12668 static tree
12669 c_parser_omp_for (location_t loc, c_parser *parser,
12670 char *p_name, omp_clause_mask mask, tree *cclauses)
12672 tree block, clauses, ret;
12674 strcat (p_name, " for");
12675 mask |= OMP_FOR_CLAUSE_MASK;
12676 if (cclauses)
12677 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
12679 if (c_parser_next_token_is (parser, CPP_NAME))
12681 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12683 if (strcmp (p, "simd") == 0)
12685 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
12686 if (cclauses == NULL)
12687 cclauses = cclauses_buf;
12689 c_parser_consume_token (parser);
12690 if (!flag_openmp) /* flag_openmp_simd */
12691 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
12692 block = c_begin_compound_stmt (true);
12693 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
12694 block = c_end_compound_stmt (loc, block, true);
12695 if (ret == NULL_TREE)
12696 return ret;
12697 ret = make_node (OMP_FOR);
12698 TREE_TYPE (ret) = void_type_node;
12699 OMP_FOR_BODY (ret) = block;
12700 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
12701 SET_EXPR_LOCATION (ret, loc);
12702 add_stmt (ret);
12703 return ret;
12706 if (!flag_openmp) /* flag_openmp_simd */
12708 c_parser_skip_to_pragma_eol (parser);
12709 return NULL_TREE;
12712 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
12713 if (cclauses)
12715 omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
12716 clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
12719 block = c_begin_compound_stmt (true);
12720 ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses);
12721 block = c_end_compound_stmt (loc, block, true);
12722 add_stmt (block);
12724 return ret;
12727 /* OpenMP 2.5:
12728 # pragma omp master new-line
12729 structured-block
12731 LOC is the location of the #pragma token.
12734 static tree
12735 c_parser_omp_master (location_t loc, c_parser *parser)
12737 c_parser_skip_to_pragma_eol (parser);
12738 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
12741 /* OpenMP 2.5:
12742 # pragma omp ordered new-line
12743 structured-block
12745 LOC is the location of the #pragma itself.
12748 static tree
12749 c_parser_omp_ordered (location_t loc, c_parser *parser)
12751 c_parser_skip_to_pragma_eol (parser);
12752 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
12755 /* OpenMP 2.5:
12757 section-scope:
12758 { section-sequence }
12760 section-sequence:
12761 section-directive[opt] structured-block
12762 section-sequence section-directive structured-block
12764 SECTIONS_LOC is the location of the #pragma omp sections. */
12766 static tree
12767 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
12769 tree stmt, substmt;
12770 bool error_suppress = false;
12771 location_t loc;
12773 loc = c_parser_peek_token (parser)->location;
12774 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
12776 /* Avoid skipping until the end of the block. */
12777 parser->error = false;
12778 return NULL_TREE;
12781 stmt = push_stmt_list ();
12783 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
12785 substmt = c_parser_omp_structured_block (parser);
12786 substmt = build1 (OMP_SECTION, void_type_node, substmt);
12787 SET_EXPR_LOCATION (substmt, loc);
12788 add_stmt (substmt);
12791 while (1)
12793 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12794 break;
12795 if (c_parser_next_token_is (parser, CPP_EOF))
12796 break;
12798 loc = c_parser_peek_token (parser)->location;
12799 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
12801 c_parser_consume_pragma (parser);
12802 c_parser_skip_to_pragma_eol (parser);
12803 error_suppress = false;
12805 else if (!error_suppress)
12807 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
12808 error_suppress = true;
12811 substmt = c_parser_omp_structured_block (parser);
12812 substmt = build1 (OMP_SECTION, void_type_node, substmt);
12813 SET_EXPR_LOCATION (substmt, loc);
12814 add_stmt (substmt);
12816 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
12817 "expected %<#pragma omp section%> or %<}%>");
12819 substmt = pop_stmt_list (stmt);
12821 stmt = make_node (OMP_SECTIONS);
12822 SET_EXPR_LOCATION (stmt, sections_loc);
12823 TREE_TYPE (stmt) = void_type_node;
12824 OMP_SECTIONS_BODY (stmt) = substmt;
12826 return add_stmt (stmt);
12829 /* OpenMP 2.5:
12830 # pragma omp sections sections-clause[optseq] newline
12831 sections-scope
12833 LOC is the location of the #pragma token.
12836 #define OMP_SECTIONS_CLAUSE_MASK \
12837 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12843 static tree
12844 c_parser_omp_sections (location_t loc, c_parser *parser,
12845 char *p_name, omp_clause_mask mask, tree *cclauses)
12847 tree block, clauses, ret;
12849 strcat (p_name, " sections");
12850 mask |= OMP_SECTIONS_CLAUSE_MASK;
12851 if (cclauses)
12852 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
12854 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
12855 if (cclauses)
12857 omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
12858 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
12861 block = c_begin_compound_stmt (true);
12862 ret = c_parser_omp_sections_scope (loc, parser);
12863 if (ret)
12864 OMP_SECTIONS_CLAUSES (ret) = clauses;
12865 block = c_end_compound_stmt (loc, block, true);
12866 add_stmt (block);
12868 return ret;
12871 /* OpenMP 2.5:
12872 # pragma omp parallel parallel-clause[optseq] new-line
12873 structured-block
12874 # pragma omp parallel for parallel-for-clause[optseq] new-line
12875 structured-block
12876 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12877 structured-block
12879 OpenMP 4.0:
12880 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12881 structured-block
12883 LOC is the location of the #pragma token.
12886 #define OMP_PARALLEL_CLAUSE_MASK \
12887 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12888 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12897 static tree
12898 c_parser_omp_parallel (location_t loc, c_parser *parser,
12899 char *p_name, omp_clause_mask mask, tree *cclauses)
12901 tree stmt, clauses, block;
12903 strcat (p_name, " parallel");
12904 mask |= OMP_PARALLEL_CLAUSE_MASK;
12906 if (c_parser_next_token_is_keyword (parser, RID_FOR))
12908 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
12909 if (cclauses == NULL)
12910 cclauses = cclauses_buf;
12912 c_parser_consume_token (parser);
12913 if (!flag_openmp) /* flag_openmp_simd */
12914 return c_parser_omp_for (loc, parser, p_name, mask, cclauses);
12915 block = c_begin_omp_parallel ();
12916 tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses);
12917 stmt
12918 = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
12919 block);
12920 if (ret == NULL_TREE)
12921 return ret;
12922 OMP_PARALLEL_COMBINED (stmt) = 1;
12923 return stmt;
12925 else if (cclauses)
12927 error_at (loc, "expected %<for%> after %qs", p_name);
12928 c_parser_skip_to_pragma_eol (parser);
12929 return NULL_TREE;
12931 else if (!flag_openmp) /* flag_openmp_simd */
12933 c_parser_skip_to_pragma_eol (parser);
12934 return NULL_TREE;
12936 else if (c_parser_next_token_is (parser, CPP_NAME))
12938 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12939 if (strcmp (p, "sections") == 0)
12941 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
12942 if (cclauses == NULL)
12943 cclauses = cclauses_buf;
12945 c_parser_consume_token (parser);
12946 block = c_begin_omp_parallel ();
12947 c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
12948 stmt = c_finish_omp_parallel (loc,
12949 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
12950 block);
12951 OMP_PARALLEL_COMBINED (stmt) = 1;
12952 return stmt;
12956 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
12958 block = c_begin_omp_parallel ();
12959 c_parser_statement (parser);
12960 stmt = c_finish_omp_parallel (loc, clauses, block);
12962 return stmt;
12965 /* OpenMP 2.5:
12966 # pragma omp single single-clause[optseq] new-line
12967 structured-block
12969 LOC is the location of the #pragma.
12972 #define OMP_SINGLE_CLAUSE_MASK \
12973 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12978 static tree
12979 c_parser_omp_single (location_t loc, c_parser *parser)
12981 tree stmt = make_node (OMP_SINGLE);
12982 SET_EXPR_LOCATION (stmt, loc);
12983 TREE_TYPE (stmt) = void_type_node;
12985 OMP_SINGLE_CLAUSES (stmt)
12986 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
12987 "#pragma omp single");
12988 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
12990 return add_stmt (stmt);
12993 /* OpenMP 3.0:
12994 # pragma omp task task-clause[optseq] new-line
12996 LOC is the location of the #pragma.
12999 #define OMP_TASK_CLAUSE_MASK \
13000 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13001 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13002 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13003 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13004 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13010 static tree
13011 c_parser_omp_task (location_t loc, c_parser *parser)
13013 tree clauses, block;
13015 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
13016 "#pragma omp task");
13018 block = c_begin_omp_task ();
13019 c_parser_statement (parser);
13020 return c_finish_omp_task (loc, clauses, block);
13023 /* OpenMP 3.0:
13024 # pragma omp taskwait new-line
13027 static void
13028 c_parser_omp_taskwait (c_parser *parser)
13030 location_t loc = c_parser_peek_token (parser)->location;
13031 c_parser_consume_pragma (parser);
13032 c_parser_skip_to_pragma_eol (parser);
13034 c_finish_omp_taskwait (loc);
13037 /* OpenMP 3.1:
13038 # pragma omp taskyield new-line
13041 static void
13042 c_parser_omp_taskyield (c_parser *parser)
13044 location_t loc = c_parser_peek_token (parser)->location;
13045 c_parser_consume_pragma (parser);
13046 c_parser_skip_to_pragma_eol (parser);
13048 c_finish_omp_taskyield (loc);
13051 /* OpenMP 4.0:
13052 # pragma omp taskgroup new-line
13055 static tree
13056 c_parser_omp_taskgroup (c_parser *parser)
13058 location_t loc = c_parser_peek_token (parser)->location;
13059 c_parser_skip_to_pragma_eol (parser);
13060 return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser));
13063 /* OpenMP 4.0:
13064 # pragma omp cancel cancel-clause[optseq] new-line
13066 LOC is the location of the #pragma.
13069 #define OMP_CANCEL_CLAUSE_MASK \
13070 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13076 static void
13077 c_parser_omp_cancel (c_parser *parser)
13079 location_t loc = c_parser_peek_token (parser)->location;
13081 c_parser_consume_pragma (parser);
13082 tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
13083 "#pragma omp cancel");
13085 c_finish_omp_cancel (loc, clauses);
13088 /* OpenMP 4.0:
13089 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13091 LOC is the location of the #pragma.
13094 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13095 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13096 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13097 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13100 static void
13101 c_parser_omp_cancellation_point (c_parser *parser)
13103 location_t loc = c_parser_peek_token (parser)->location;
13104 tree clauses;
13105 bool point_seen = false;
13107 c_parser_consume_pragma (parser);
13108 if (c_parser_next_token_is (parser, CPP_NAME))
13110 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13111 if (strcmp (p, "point") == 0)
13113 c_parser_consume_token (parser);
13114 point_seen = true;
13117 if (!point_seen)
13119 c_parser_error (parser, "expected %<point%>");
13120 c_parser_skip_to_pragma_eol (parser);
13121 return;
13124 clauses
13125 = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
13126 "#pragma omp cancellation point");
13128 c_finish_omp_cancellation_point (loc, clauses);
13131 /* OpenMP 4.0:
13132 #pragma omp distribute distribute-clause[optseq] new-line
13133 for-loop */
13135 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13136 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13138 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13139 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13141 static tree
13142 c_parser_omp_distribute (location_t loc, c_parser *parser,
13143 char *p_name, omp_clause_mask mask, tree *cclauses)
13145 tree clauses, block, ret;
13147 strcat (p_name, " distribute");
13148 mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
13150 if (c_parser_next_token_is (parser, CPP_NAME))
13152 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13153 bool simd = false;
13154 bool parallel = false;
13156 if (strcmp (p, "simd") == 0)
13157 simd = true;
13158 else
13159 parallel = strcmp (p, "parallel") == 0;
13160 if (parallel || simd)
13162 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13163 if (cclauses == NULL)
13164 cclauses = cclauses_buf;
13165 c_parser_consume_token (parser);
13166 if (!flag_openmp) /* flag_openmp_simd */
13168 if (simd)
13169 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13170 else
13171 return c_parser_omp_parallel (loc, parser, p_name, mask,
13172 cclauses);
13174 block = c_begin_compound_stmt (true);
13175 if (simd)
13176 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13177 else
13178 ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses);
13179 block = c_end_compound_stmt (loc, block, true);
13180 if (ret == NULL)
13181 return ret;
13182 ret = make_node (OMP_DISTRIBUTE);
13183 TREE_TYPE (ret) = void_type_node;
13184 OMP_FOR_BODY (ret) = block;
13185 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13186 SET_EXPR_LOCATION (ret, loc);
13187 add_stmt (ret);
13188 return ret;
13191 if (!flag_openmp) /* flag_openmp_simd */
13193 c_parser_skip_to_pragma_eol (parser);
13194 return NULL_TREE;
13197 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13198 if (cclauses)
13200 omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
13201 clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13204 block = c_begin_compound_stmt (true);
13205 ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL);
13206 block = c_end_compound_stmt (loc, block, true);
13207 add_stmt (block);
13209 return ret;
13212 /* OpenMP 4.0:
13213 # pragma omp teams teams-clause[optseq] new-line
13214 structured-block */
13216 #define OMP_TEAMS_CLAUSE_MASK \
13217 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13218 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13221 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13222 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13225 static tree
13226 c_parser_omp_teams (location_t loc, c_parser *parser,
13227 char *p_name, omp_clause_mask mask, tree *cclauses)
13229 tree clauses, block, ret;
13231 strcat (p_name, " teams");
13232 mask |= OMP_TEAMS_CLAUSE_MASK;
13234 if (c_parser_next_token_is (parser, CPP_NAME))
13236 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13237 if (strcmp (p, "distribute") == 0)
13239 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13240 if (cclauses == NULL)
13241 cclauses = cclauses_buf;
13243 c_parser_consume_token (parser);
13244 if (!flag_openmp) /* flag_openmp_simd */
13245 return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13246 block = c_begin_compound_stmt (true);
13247 ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13248 block = c_end_compound_stmt (loc, block, true);
13249 if (ret == NULL)
13250 return ret;
13251 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13252 ret = make_node (OMP_TEAMS);
13253 TREE_TYPE (ret) = void_type_node;
13254 OMP_TEAMS_CLAUSES (ret) = clauses;
13255 OMP_TEAMS_BODY (ret) = block;
13256 return add_stmt (ret);
13259 if (!flag_openmp) /* flag_openmp_simd */
13261 c_parser_skip_to_pragma_eol (parser);
13262 return NULL_TREE;
13265 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13266 if (cclauses)
13268 omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
13269 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13272 tree stmt = make_node (OMP_TEAMS);
13273 TREE_TYPE (stmt) = void_type_node;
13274 OMP_TEAMS_CLAUSES (stmt) = clauses;
13275 OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser);
13277 return add_stmt (stmt);
13280 /* OpenMP 4.0:
13281 # pragma omp target data target-data-clause[optseq] new-line
13282 structured-block */
13284 #define OMP_TARGET_DATA_CLAUSE_MASK \
13285 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13286 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13287 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13289 static tree
13290 c_parser_omp_target_data (location_t loc, c_parser *parser)
13292 tree stmt = make_node (OMP_TARGET_DATA);
13293 TREE_TYPE (stmt) = void_type_node;
13295 OMP_TARGET_DATA_CLAUSES (stmt)
13296 = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
13297 "#pragma omp target data");
13298 keep_next_level ();
13299 tree block = c_begin_compound_stmt (true);
13300 add_stmt (c_parser_omp_structured_block (parser));
13301 OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13303 SET_EXPR_LOCATION (stmt, loc);
13304 return add_stmt (stmt);
13307 /* OpenMP 4.0:
13308 # pragma omp target update target-update-clause[optseq] new-line */
13310 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13311 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13316 static bool
13317 c_parser_omp_target_update (location_t loc, c_parser *parser,
13318 enum pragma_context context)
13320 if (context == pragma_stmt)
13322 error_at (loc,
13323 "%<#pragma omp target update%> may only be "
13324 "used in compound statements");
13325 c_parser_skip_to_pragma_eol (parser);
13326 return false;
13329 tree clauses
13330 = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
13331 "#pragma omp target update");
13332 if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
13333 && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
13335 error_at (loc,
13336 "%<#pragma omp target update must contain at least one "
13337 "%<from%> or %<to%> clauses");
13338 return false;
13341 tree stmt = make_node (OMP_TARGET_UPDATE);
13342 TREE_TYPE (stmt) = void_type_node;
13343 OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
13344 SET_EXPR_LOCATION (stmt, loc);
13345 add_stmt (stmt);
13346 return false;
13349 /* OpenMP 4.0:
13350 # pragma omp target target-clause[optseq] new-line
13351 structured-block */
13353 #define OMP_TARGET_CLAUSE_MASK \
13354 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13355 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13358 static bool
13359 c_parser_omp_target (c_parser *parser, enum pragma_context context)
13361 location_t loc = c_parser_peek_token (parser)->location;
13362 c_parser_consume_pragma (parser);
13364 if (context != pragma_stmt && context != pragma_compound)
13366 c_parser_error (parser, "expected declaration specifiers");
13367 c_parser_skip_to_pragma_eol (parser);
13368 return false;
13371 if (c_parser_next_token_is (parser, CPP_NAME))
13373 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13375 if (strcmp (p, "teams") == 0)
13377 tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
13378 char p_name[sizeof ("#pragma omp target teams distribute "
13379 "parallel for simd")];
13381 c_parser_consume_token (parser);
13382 strcpy (p_name, "#pragma omp target");
13383 if (!flag_openmp) /* flag_openmp_simd */
13384 return c_parser_omp_teams (loc, parser, p_name,
13385 OMP_TARGET_CLAUSE_MASK, cclauses);
13386 keep_next_level ();
13387 tree block = c_begin_compound_stmt (true);
13388 tree ret = c_parser_omp_teams (loc, parser, p_name,
13389 OMP_TARGET_CLAUSE_MASK, cclauses);
13390 block = c_end_compound_stmt (loc, block, true);
13391 if (ret == NULL)
13392 return ret;
13393 tree stmt = make_node (OMP_TARGET);
13394 TREE_TYPE (stmt) = void_type_node;
13395 OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
13396 OMP_TARGET_BODY (stmt) = block;
13397 add_stmt (stmt);
13398 return true;
13400 else if (!flag_openmp) /* flag_openmp_simd */
13402 c_parser_skip_to_pragma_eol (parser);
13403 return NULL_TREE;
13405 else if (strcmp (p, "data") == 0)
13407 c_parser_consume_token (parser);
13408 c_parser_omp_target_data (loc, parser);
13409 return true;
13411 else if (strcmp (p, "update") == 0)
13413 c_parser_consume_token (parser);
13414 return c_parser_omp_target_update (loc, parser, context);
13418 tree stmt = make_node (OMP_TARGET);
13419 TREE_TYPE (stmt) = void_type_node;
13421 OMP_TARGET_CLAUSES (stmt)
13422 = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
13423 "#pragma omp target");
13424 keep_next_level ();
13425 tree block = c_begin_compound_stmt (true);
13426 add_stmt (c_parser_omp_structured_block (parser));
13427 OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13429 SET_EXPR_LOCATION (stmt, loc);
13430 add_stmt (stmt);
13431 return true;
13434 /* OpenMP 4.0:
13435 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13437 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13438 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13443 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13445 static void
13446 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
13448 vec<c_token> clauses = vNULL;
13449 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13451 c_token *token = c_parser_peek_token (parser);
13452 if (token->type == CPP_EOF)
13454 c_parser_skip_to_pragma_eol (parser);
13455 clauses.release ();
13456 return;
13458 clauses.safe_push (*token);
13459 c_parser_consume_token (parser);
13461 clauses.safe_push (*c_parser_peek_token (parser));
13462 c_parser_skip_to_pragma_eol (parser);
13464 while (c_parser_next_token_is (parser, CPP_PRAGMA))
13466 if (c_parser_peek_token (parser)->pragma_kind
13467 != PRAGMA_OMP_DECLARE_REDUCTION
13468 || c_parser_peek_2nd_token (parser)->type != CPP_NAME
13469 || strcmp (IDENTIFIER_POINTER
13470 (c_parser_peek_2nd_token (parser)->value),
13471 "simd") != 0)
13473 c_parser_error (parser,
13474 "%<#pragma omp declare simd%> must be followed by "
13475 "function declaration or definition or another "
13476 "%<#pragma omp declare simd%>");
13477 clauses.release ();
13478 return;
13480 c_parser_consume_pragma (parser);
13481 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13483 c_token *token = c_parser_peek_token (parser);
13484 if (token->type == CPP_EOF)
13486 c_parser_skip_to_pragma_eol (parser);
13487 clauses.release ();
13488 return;
13490 clauses.safe_push (*token);
13491 c_parser_consume_token (parser);
13493 clauses.safe_push (*c_parser_peek_token (parser));
13494 c_parser_skip_to_pragma_eol (parser);
13497 /* Make sure nothing tries to read past the end of the tokens. */
13498 c_token eof_token;
13499 memset (&eof_token, 0, sizeof (eof_token));
13500 eof_token.type = CPP_EOF;
13501 clauses.safe_push (eof_token);
13502 clauses.safe_push (eof_token);
13504 switch (context)
13506 case pragma_external:
13507 if (c_parser_next_token_is (parser, CPP_KEYWORD)
13508 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
13510 int ext = disable_extension_diagnostics ();
13512 c_parser_consume_token (parser);
13513 while (c_parser_next_token_is (parser, CPP_KEYWORD)
13514 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
13515 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
13516 NULL, clauses);
13517 restore_extension_diagnostics (ext);
13519 else
13520 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
13521 NULL, clauses);
13522 break;
13523 case pragma_struct:
13524 case pragma_param:
13525 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
13526 "function declaration or definition");
13527 break;
13528 case pragma_compound:
13529 case pragma_stmt:
13530 if (c_parser_next_token_is (parser, CPP_KEYWORD)
13531 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
13533 int ext = disable_extension_diagnostics ();
13535 c_parser_consume_token (parser);
13536 while (c_parser_next_token_is (parser, CPP_KEYWORD)
13537 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
13538 if (c_parser_next_tokens_start_declaration (parser))
13540 c_parser_declaration_or_fndef (parser, true, true, true, true,
13541 true, NULL, clauses);
13542 restore_extension_diagnostics (ext);
13543 break;
13545 restore_extension_diagnostics (ext);
13547 else if (c_parser_next_tokens_start_declaration (parser))
13549 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
13550 NULL, clauses);
13551 break;
13553 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
13554 "function declaration or definition");
13555 break;
13556 default:
13557 gcc_unreachable ();
13559 clauses.release ();
13562 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
13563 and put that into "omp declare simd" attribute. */
13565 static void
13566 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
13567 vec<c_token> clauses)
13569 if (flag_cilkplus
13570 && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
13572 error ("%<#pragma omp declare simd%> cannot be used in the same "
13573 "function marked as a Cilk Plus SIMD-enabled function");
13574 vec_free (parser->cilk_simd_fn_tokens);
13575 return;
13578 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
13579 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
13580 has already processed the tokens. */
13581 if (clauses.exists () && clauses[0].type == CPP_EOF)
13582 return;
13583 if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
13585 error ("%<#pragma omp declare simd%> not immediately followed by "
13586 "a function declaration or definition");
13587 clauses[0].type = CPP_EOF;
13588 return;
13590 if (clauses.exists () && clauses[0].type != CPP_NAME)
13592 error_at (DECL_SOURCE_LOCATION (fndecl),
13593 "%<#pragma omp declare simd%> not immediately followed by "
13594 "a single function declaration or definition");
13595 clauses[0].type = CPP_EOF;
13596 return;
13599 if (parms == NULL_TREE)
13600 parms = DECL_ARGUMENTS (fndecl);
13602 unsigned int tokens_avail = parser->tokens_avail;
13603 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
13604 bool is_cilkplus_cilk_simd_fn = false;
13606 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
13608 parser->tokens = parser->cilk_simd_fn_tokens->address ();
13609 parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens);
13610 is_cilkplus_cilk_simd_fn = true;
13612 else
13614 parser->tokens = clauses.address ();
13615 parser->tokens_avail = clauses.length ();
13618 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13619 while (parser->tokens_avail > 3)
13621 c_token *token = c_parser_peek_token (parser);
13622 if (!is_cilkplus_cilk_simd_fn)
13623 gcc_assert (token->type == CPP_NAME
13624 && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
13625 else
13626 gcc_assert (token->type == CPP_NAME
13627 && is_cilkplus_vector_p (token->value));
13628 c_parser_consume_token (parser);
13629 parser->in_pragma = true;
13631 tree c = NULL_TREE;
13632 if (is_cilkplus_cilk_simd_fn)
13633 c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
13634 "SIMD-enabled functions attribute");
13635 else
13636 c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
13637 "#pragma omp declare simd");
13638 c = c_omp_declare_simd_clauses_to_numbers (parms, c);
13639 if (c != NULL_TREE)
13640 c = tree_cons (NULL_TREE, c, NULL_TREE);
13641 if (is_cilkplus_cilk_simd_fn)
13643 tree k = build_tree_list (get_identifier ("cilk simd function"),
13644 NULL_TREE);
13645 TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
13646 DECL_ATTRIBUTES (fndecl) = k;
13648 c = build_tree_list (get_identifier ("omp declare simd"), c);
13649 TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
13650 DECL_ATTRIBUTES (fndecl) = c;
13653 parser->tokens = &parser->tokens_buf[0];
13654 parser->tokens_avail = tokens_avail;
13655 if (clauses.exists ())
13656 clauses[0].type = CPP_PRAGMA;
13658 if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens))
13659 vec_free (parser->cilk_simd_fn_tokens);
13663 /* OpenMP 4.0:
13664 # pragma omp declare target new-line
13665 declarations and definitions
13666 # pragma omp end declare target new-line */
13668 static void
13669 c_parser_omp_declare_target (c_parser *parser)
13671 c_parser_skip_to_pragma_eol (parser);
13672 current_omp_declare_target_attribute++;
13675 static void
13676 c_parser_omp_end_declare_target (c_parser *parser)
13678 location_t loc = c_parser_peek_token (parser)->location;
13679 c_parser_consume_pragma (parser);
13680 if (c_parser_next_token_is (parser, CPP_NAME)
13681 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
13682 "declare") == 0)
13684 c_parser_consume_token (parser);
13685 if (c_parser_next_token_is (parser, CPP_NAME)
13686 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
13687 "target") == 0)
13688 c_parser_consume_token (parser);
13689 else
13691 c_parser_error (parser, "expected %<target%>");
13692 c_parser_skip_to_pragma_eol (parser);
13693 return;
13696 else
13698 c_parser_error (parser, "expected %<declare%>");
13699 c_parser_skip_to_pragma_eol (parser);
13700 return;
13702 c_parser_skip_to_pragma_eol (parser);
13703 if (!current_omp_declare_target_attribute)
13704 error_at (loc, "%<#pragma omp end declare target%> without corresponding "
13705 "%<#pragma omp declare target%>");
13706 else
13707 current_omp_declare_target_attribute--;
13711 /* OpenMP 4.0
13712 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13713 initializer-clause[opt] new-line
13715 initializer-clause:
13716 initializer (omp_priv = initializer)
13717 initializer (function-name (argument-list)) */
13719 static void
13720 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
13722 unsigned int tokens_avail = 0, i;
13723 vec<tree> types = vNULL;
13724 vec<c_token> clauses = vNULL;
13725 enum tree_code reduc_code = ERROR_MARK;
13726 tree reduc_id = NULL_TREE;
13727 tree type;
13728 location_t rloc = c_parser_peek_token (parser)->location;
13730 if (context == pragma_struct || context == pragma_param)
13732 error ("%<#pragma omp declare reduction%> not at file or block scope");
13733 goto fail;
13736 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
13737 goto fail;
13739 switch (c_parser_peek_token (parser)->type)
13741 case CPP_PLUS:
13742 reduc_code = PLUS_EXPR;
13743 break;
13744 case CPP_MULT:
13745 reduc_code = MULT_EXPR;
13746 break;
13747 case CPP_MINUS:
13748 reduc_code = MINUS_EXPR;
13749 break;
13750 case CPP_AND:
13751 reduc_code = BIT_AND_EXPR;
13752 break;
13753 case CPP_XOR:
13754 reduc_code = BIT_XOR_EXPR;
13755 break;
13756 case CPP_OR:
13757 reduc_code = BIT_IOR_EXPR;
13758 break;
13759 case CPP_AND_AND:
13760 reduc_code = TRUTH_ANDIF_EXPR;
13761 break;
13762 case CPP_OR_OR:
13763 reduc_code = TRUTH_ORIF_EXPR;
13764 break;
13765 case CPP_NAME:
13766 const char *p;
13767 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13768 if (strcmp (p, "min") == 0)
13770 reduc_code = MIN_EXPR;
13771 break;
13773 if (strcmp (p, "max") == 0)
13775 reduc_code = MAX_EXPR;
13776 break;
13778 reduc_id = c_parser_peek_token (parser)->value;
13779 break;
13780 default:
13781 c_parser_error (parser,
13782 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13783 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13784 goto fail;
13787 tree orig_reduc_id, reduc_decl;
13788 orig_reduc_id = reduc_id;
13789 reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
13790 reduc_decl = c_omp_reduction_decl (reduc_id);
13791 c_parser_consume_token (parser);
13793 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
13794 goto fail;
13796 while (true)
13798 location_t loc = c_parser_peek_token (parser)->location;
13799 struct c_type_name *ctype = c_parser_type_name (parser);
13800 if (ctype != NULL)
13802 type = groktypename (ctype, NULL, NULL);
13803 if (type == error_mark_node)
13805 else if ((INTEGRAL_TYPE_P (type)
13806 || TREE_CODE (type) == REAL_TYPE
13807 || TREE_CODE (type) == COMPLEX_TYPE)
13808 && orig_reduc_id == NULL_TREE)
13809 error_at (loc, "predeclared arithmetic type in "
13810 "%<#pragma omp declare reduction%>");
13811 else if (TREE_CODE (type) == FUNCTION_TYPE
13812 || TREE_CODE (type) == ARRAY_TYPE)
13813 error_at (loc, "function or array type in "
13814 "%<#pragma omp declare reduction%>");
13815 else if (TYPE_QUALS_NO_ADDR_SPACE (type))
13816 error_at (loc, "const, volatile or restrict qualified type in "
13817 "%<#pragma omp declare reduction%>");
13818 else
13820 tree t;
13821 for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
13822 if (comptypes (TREE_PURPOSE (t), type))
13824 error_at (loc, "redeclaration of %qs "
13825 "%<#pragma omp declare reduction%> for "
13826 "type %qT",
13827 IDENTIFIER_POINTER (reduc_id)
13828 + sizeof ("omp declare reduction ") - 1,
13829 type);
13830 location_t ploc
13831 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
13832 0));
13833 error_at (ploc, "previous %<#pragma omp declare "
13834 "reduction%>");
13835 break;
13837 if (t == NULL_TREE)
13838 types.safe_push (type);
13840 if (c_parser_next_token_is (parser, CPP_COMMA))
13841 c_parser_consume_token (parser);
13842 else
13843 break;
13845 else
13846 break;
13849 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
13850 || types.is_empty ())
13852 fail:
13853 clauses.release ();
13854 types.release ();
13855 while (true)
13857 c_token *token = c_parser_peek_token (parser);
13858 if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
13859 break;
13860 c_parser_consume_token (parser);
13862 c_parser_skip_to_pragma_eol (parser);
13863 return;
13866 if (types.length () > 1)
13868 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13870 c_token *token = c_parser_peek_token (parser);
13871 if (token->type == CPP_EOF)
13872 goto fail;
13873 clauses.safe_push (*token);
13874 c_parser_consume_token (parser);
13876 clauses.safe_push (*c_parser_peek_token (parser));
13877 c_parser_skip_to_pragma_eol (parser);
13879 /* Make sure nothing tries to read past the end of the tokens. */
13880 c_token eof_token;
13881 memset (&eof_token, 0, sizeof (eof_token));
13882 eof_token.type = CPP_EOF;
13883 clauses.safe_push (eof_token);
13884 clauses.safe_push (eof_token);
13887 int errs = errorcount;
13888 FOR_EACH_VEC_ELT (types, i, type)
13890 tokens_avail = parser->tokens_avail;
13891 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
13892 if (!clauses.is_empty ())
13894 parser->tokens = clauses.address ();
13895 parser->tokens_avail = clauses.length ();
13896 parser->in_pragma = true;
13899 bool nested = current_function_decl != NULL_TREE;
13900 if (nested)
13901 c_push_function_context ();
13902 tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
13903 reduc_id, default_function_type);
13904 current_function_decl = fndecl;
13905 allocate_struct_function (fndecl, true);
13906 push_scope ();
13907 tree stmt = push_stmt_list ();
13908 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13909 warn about these. */
13910 tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
13911 get_identifier ("omp_out"), type);
13912 DECL_ARTIFICIAL (omp_out) = 1;
13913 DECL_CONTEXT (omp_out) = fndecl;
13914 pushdecl (omp_out);
13915 tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
13916 get_identifier ("omp_in"), type);
13917 DECL_ARTIFICIAL (omp_in) = 1;
13918 DECL_CONTEXT (omp_in) = fndecl;
13919 pushdecl (omp_in);
13920 struct c_expr combiner = c_parser_expression (parser);
13921 struct c_expr initializer;
13922 tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
13923 bool bad = false;
13924 initializer.value = error_mark_node;
13925 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
13926 bad = true;
13927 else if (c_parser_next_token_is (parser, CPP_NAME)
13928 && strcmp (IDENTIFIER_POINTER
13929 (c_parser_peek_token (parser)->value),
13930 "initializer") == 0)
13932 c_parser_consume_token (parser);
13933 pop_scope ();
13934 push_scope ();
13935 omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
13936 get_identifier ("omp_priv"), type);
13937 DECL_ARTIFICIAL (omp_priv) = 1;
13938 DECL_INITIAL (omp_priv) = error_mark_node;
13939 DECL_CONTEXT (omp_priv) = fndecl;
13940 pushdecl (omp_priv);
13941 omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
13942 get_identifier ("omp_orig"), type);
13943 DECL_ARTIFICIAL (omp_orig) = 1;
13944 DECL_CONTEXT (omp_orig) = fndecl;
13945 pushdecl (omp_orig);
13946 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
13947 bad = true;
13948 else if (!c_parser_next_token_is (parser, CPP_NAME))
13950 c_parser_error (parser, "expected %<omp_priv%> or "
13951 "function-name");
13952 bad = true;
13954 else if (strcmp (IDENTIFIER_POINTER
13955 (c_parser_peek_token (parser)->value),
13956 "omp_priv") != 0)
13958 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
13959 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
13961 c_parser_error (parser, "expected function-name %<(%>");
13962 bad = true;
13964 else
13965 initializer = c_parser_postfix_expression (parser);
13966 if (initializer.value
13967 && TREE_CODE (initializer.value) == CALL_EXPR)
13969 int j;
13970 tree c = initializer.value;
13971 for (j = 0; j < call_expr_nargs (c); j++)
13972 if (TREE_CODE (CALL_EXPR_ARG (c, j)) == ADDR_EXPR
13973 && TREE_OPERAND (CALL_EXPR_ARG (c, j), 0) == omp_priv)
13974 break;
13975 if (j == call_expr_nargs (c))
13976 error ("one of the initializer call arguments should be "
13977 "%<&omp_priv%>");
13980 else
13982 c_parser_consume_token (parser);
13983 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
13984 bad = true;
13985 else
13987 tree st = push_stmt_list ();
13988 start_init (omp_priv, NULL_TREE, 0);
13989 location_t loc = c_parser_peek_token (parser)->location;
13990 struct c_expr init = c_parser_initializer (parser);
13991 finish_init ();
13992 finish_decl (omp_priv, loc, init.value,
13993 init.original_type, NULL_TREE);
13994 pop_stmt_list (st);
13997 if (!bad
13998 && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
13999 bad = true;
14002 if (!bad)
14004 c_parser_skip_to_pragma_eol (parser);
14006 tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
14007 DECL_INITIAL (reduc_decl));
14008 DECL_INITIAL (reduc_decl) = t;
14009 DECL_SOURCE_LOCATION (omp_out) = rloc;
14010 TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
14011 TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
14012 TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
14013 walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
14014 &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
14015 if (omp_priv)
14017 DECL_SOURCE_LOCATION (omp_priv) = rloc;
14018 TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
14019 TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
14020 TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
14021 walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
14022 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14023 walk_tree (&DECL_INITIAL (omp_priv),
14024 c_check_omp_declare_reduction_r,
14025 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14029 pop_stmt_list (stmt);
14030 pop_scope ();
14031 if (cfun->language != NULL)
14033 ggc_free (cfun->language);
14034 cfun->language = NULL;
14036 set_cfun (NULL);
14037 current_function_decl = NULL_TREE;
14038 if (nested)
14039 c_pop_function_context ();
14041 if (!clauses.is_empty ())
14043 parser->tokens = &parser->tokens_buf[0];
14044 parser->tokens_avail = tokens_avail;
14046 if (bad)
14047 goto fail;
14048 if (errs != errorcount)
14049 break;
14052 clauses.release ();
14053 types.release ();
14057 /* OpenMP 4.0
14058 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14059 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14060 initializer-clause[opt] new-line
14061 #pragma omp declare target new-line */
14063 static void
14064 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
14066 c_parser_consume_pragma (parser);
14067 if (c_parser_next_token_is (parser, CPP_NAME))
14069 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14070 if (strcmp (p, "simd") == 0)
14072 /* c_parser_consume_token (parser); done in
14073 c_parser_omp_declare_simd. */
14074 c_parser_omp_declare_simd (parser, context);
14075 return;
14077 if (strcmp (p, "reduction") == 0)
14079 c_parser_consume_token (parser);
14080 c_parser_omp_declare_reduction (parser, context);
14081 return;
14083 if (!flag_openmp) /* flag_openmp_simd */
14085 c_parser_skip_to_pragma_eol (parser);
14086 return;
14088 if (strcmp (p, "target") == 0)
14090 c_parser_consume_token (parser);
14091 c_parser_omp_declare_target (parser);
14092 return;
14096 c_parser_error (parser, "expected %<simd%> or %<reduction%> "
14097 "or %<target%>");
14098 c_parser_skip_to_pragma_eol (parser);
14101 /* Main entry point to parsing most OpenMP pragmas. */
14103 static void
14104 c_parser_omp_construct (c_parser *parser)
14106 enum pragma_kind p_kind;
14107 location_t loc;
14108 tree stmt;
14109 char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
14110 omp_clause_mask mask (0);
14112 loc = c_parser_peek_token (parser)->location;
14113 p_kind = c_parser_peek_token (parser)->pragma_kind;
14114 c_parser_consume_pragma (parser);
14116 switch (p_kind)
14118 case PRAGMA_OACC_DATA:
14119 stmt = c_parser_oacc_data (loc, parser);
14120 break;
14121 case PRAGMA_OACC_KERNELS:
14122 strcpy (p_name, "#pragma acc");
14123 stmt = c_parser_oacc_kernels (loc, parser, p_name);
14124 break;
14125 case PRAGMA_OACC_LOOP:
14126 strcpy (p_name, "#pragma acc");
14127 stmt = c_parser_oacc_loop (loc, parser, p_name);
14128 break;
14129 case PRAGMA_OACC_PARALLEL:
14130 strcpy (p_name, "#pragma acc");
14131 stmt = c_parser_oacc_parallel (loc, parser, p_name);
14132 break;
14133 case PRAGMA_OMP_ATOMIC:
14134 c_parser_omp_atomic (loc, parser);
14135 return;
14136 case PRAGMA_OMP_CRITICAL:
14137 stmt = c_parser_omp_critical (loc, parser);
14138 break;
14139 case PRAGMA_OMP_DISTRIBUTE:
14140 strcpy (p_name, "#pragma omp");
14141 stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL);
14142 break;
14143 case PRAGMA_OMP_FOR:
14144 strcpy (p_name, "#pragma omp");
14145 stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL);
14146 break;
14147 case PRAGMA_OMP_MASTER:
14148 stmt = c_parser_omp_master (loc, parser);
14149 break;
14150 case PRAGMA_OMP_ORDERED:
14151 stmt = c_parser_omp_ordered (loc, parser);
14152 break;
14153 case PRAGMA_OMP_PARALLEL:
14154 strcpy (p_name, "#pragma omp");
14155 stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL);
14156 break;
14157 case PRAGMA_OMP_SECTIONS:
14158 strcpy (p_name, "#pragma omp");
14159 stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
14160 break;
14161 case PRAGMA_OMP_SIMD:
14162 strcpy (p_name, "#pragma omp");
14163 stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL);
14164 break;
14165 case PRAGMA_OMP_SINGLE:
14166 stmt = c_parser_omp_single (loc, parser);
14167 break;
14168 case PRAGMA_OMP_TASK:
14169 stmt = c_parser_omp_task (loc, parser);
14170 break;
14171 case PRAGMA_OMP_TASKGROUP:
14172 stmt = c_parser_omp_taskgroup (parser);
14173 break;
14174 case PRAGMA_OMP_TEAMS:
14175 strcpy (p_name, "#pragma omp");
14176 stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL);
14177 break;
14178 default:
14179 gcc_unreachable ();
14182 if (stmt)
14183 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
14187 /* OpenMP 2.5:
14188 # pragma omp threadprivate (variable-list) */
14190 static void
14191 c_parser_omp_threadprivate (c_parser *parser)
14193 tree vars, t;
14194 location_t loc;
14196 c_parser_consume_pragma (parser);
14197 loc = c_parser_peek_token (parser)->location;
14198 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
14200 /* Mark every variable in VARS to be assigned thread local storage. */
14201 for (t = vars; t; t = TREE_CHAIN (t))
14203 tree v = TREE_PURPOSE (t);
14205 /* FIXME diagnostics: Ideally we should keep individual
14206 locations for all the variables in the var list to make the
14207 following errors more precise. Perhaps
14208 c_parser_omp_var_list_parens() should construct a list of
14209 locations to go along with the var list. */
14211 /* If V had already been marked threadprivate, it doesn't matter
14212 whether it had been used prior to this point. */
14213 if (TREE_CODE (v) != VAR_DECL)
14214 error_at (loc, "%qD is not a variable", v);
14215 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
14216 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
14217 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
14218 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
14219 else if (TREE_TYPE (v) == error_mark_node)
14221 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
14222 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
14223 else
14225 if (! DECL_THREAD_LOCAL_P (v))
14227 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
14228 /* If rtl has been already set for this var, call
14229 make_decl_rtl once again, so that encode_section_info
14230 has a chance to look at the new decl flags. */
14231 if (DECL_RTL_SET_P (v))
14232 make_decl_rtl (v);
14234 C_DECL_THREADPRIVATE_P (v) = 1;
14238 c_parser_skip_to_pragma_eol (parser);
14241 /* Cilk Plus <#pragma simd> parsing routines. */
14243 /* Helper function for c_parser_pragma. Perform some sanity checking
14244 for <#pragma simd> constructs. Returns FALSE if there was a
14245 problem. */
14247 static bool
14248 c_parser_cilk_verify_simd (c_parser *parser,
14249 enum pragma_context context)
14251 if (!flag_cilkplus)
14253 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14254 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14255 return false;
14257 if (context == pragma_external)
14259 c_parser_error (parser,"pragma simd must be inside a function");
14260 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14261 return false;
14263 return true;
14266 /* Cilk Plus:
14267 This function is shared by SIMD-enabled functions and #pragma simd.
14268 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14269 CLAUSES is unused. The main purpose of this function is to parse a
14270 vectorlength attribute or clause and check for parse errors.
14271 When IS_SIMD_FN is true then the function is merely caching the tokens
14272 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14273 cache is cleared since there is no reason to continue.
14274 Syntax:
14275 vectorlength ( constant-expression ) */
14277 static tree
14278 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses,
14279 bool is_simd_fn)
14281 if (is_simd_fn)
14282 check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength");
14283 else
14284 /* The vectorlength clause behaves exactly like OpenMP's safelen
14285 clause. Represent it in OpenMP terms. */
14286 check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
14288 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14289 return clauses;
14291 location_t loc = c_parser_peek_token (parser)->location;
14292 tree expr = c_parser_expr_no_commas (parser, NULL).value;
14293 expr = c_fully_fold (expr, false, NULL);
14295 /* If expr is an error_mark_node then the above function would have
14296 emitted an error. No reason to do it twice. */
14297 if (expr == error_mark_node)
14299 else if (!TREE_TYPE (expr)
14300 || !TREE_CONSTANT (expr)
14301 || !INTEGRAL_TYPE_P (TREE_TYPE (expr)))
14303 error_at (loc, "vectorlength must be an integer constant");
14304 else if (wi::exact_log2 (expr) == -1)
14305 error_at (loc, "vectorlength must be a power of 2");
14306 else
14308 if (is_simd_fn)
14310 tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN);
14311 OMP_CLAUSE_SIMDLEN_EXPR (u) = expr;
14312 OMP_CLAUSE_CHAIN (u) = clauses;
14313 clauses = u;
14315 else
14317 tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN);
14318 OMP_CLAUSE_SAFELEN_EXPR (u) = expr;
14319 OMP_CLAUSE_CHAIN (u) = clauses;
14320 clauses = u;
14324 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14326 return clauses;
14329 /* Cilk Plus:
14330 linear ( simd-linear-variable-list )
14332 simd-linear-variable-list:
14333 simd-linear-variable
14334 simd-linear-variable-list , simd-linear-variable
14336 simd-linear-variable:
14337 id-expression
14338 id-expression : simd-linear-step
14340 simd-linear-step:
14341 conditional-expression */
14343 static tree
14344 c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
14346 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14347 return clauses;
14349 location_t loc = c_parser_peek_token (parser)->location;
14351 if (c_parser_next_token_is_not (parser, CPP_NAME)
14352 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
14353 c_parser_error (parser, "expected identifier");
14355 while (c_parser_next_token_is (parser, CPP_NAME)
14356 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
14358 tree var = lookup_name (c_parser_peek_token (parser)->value);
14360 if (var == NULL)
14362 undeclared_variable (c_parser_peek_token (parser)->location,
14363 c_parser_peek_token (parser)->value);
14364 c_parser_consume_token (parser);
14366 else if (var == error_mark_node)
14367 c_parser_consume_token (parser);
14368 else
14370 tree step = integer_one_node;
14372 /* Parse the linear step if present. */
14373 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
14375 c_parser_consume_token (parser);
14376 c_parser_consume_token (parser);
14378 tree expr = c_parser_expr_no_commas (parser, NULL).value;
14379 expr = c_fully_fold (expr, false, NULL);
14381 if (TREE_TYPE (expr)
14382 && INTEGRAL_TYPE_P (TREE_TYPE (expr))
14383 && (TREE_CONSTANT (expr)
14384 || DECL_P (expr)))
14385 step = expr;
14386 else
14387 c_parser_error (parser,
14388 "step size must be an integer constant "
14389 "expression or an integer variable");
14391 else
14392 c_parser_consume_token (parser);
14394 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14395 tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR);
14396 OMP_CLAUSE_DECL (u) = var;
14397 OMP_CLAUSE_LINEAR_STEP (u) = step;
14398 OMP_CLAUSE_CHAIN (u) = clauses;
14399 clauses = u;
14402 if (c_parser_next_token_is_not (parser, CPP_COMMA))
14403 break;
14405 c_parser_consume_token (parser);
14408 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14410 return clauses;
14413 /* Returns the name of the next clause. If the clause is not
14414 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14415 not consumed. Otherwise, the appropriate pragma_simd_clause is
14416 returned and the token is consumed. */
14418 static pragma_omp_clause
14419 c_parser_cilk_clause_name (c_parser *parser)
14421 pragma_omp_clause result;
14422 c_token *token = c_parser_peek_token (parser);
14424 if (!token->value || token->type != CPP_NAME)
14425 return PRAGMA_CILK_CLAUSE_NONE;
14427 const char *p = IDENTIFIER_POINTER (token->value);
14429 if (!strcmp (p, "vectorlength"))
14430 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
14431 else if (!strcmp (p, "linear"))
14432 result = PRAGMA_CILK_CLAUSE_LINEAR;
14433 else if (!strcmp (p, "private"))
14434 result = PRAGMA_CILK_CLAUSE_PRIVATE;
14435 else if (!strcmp (p, "firstprivate"))
14436 result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
14437 else if (!strcmp (p, "lastprivate"))
14438 result = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
14439 else if (!strcmp (p, "reduction"))
14440 result = PRAGMA_CILK_CLAUSE_REDUCTION;
14441 else
14442 return PRAGMA_CILK_CLAUSE_NONE;
14444 c_parser_consume_token (parser);
14445 return result;
14448 /* Parse all #<pragma simd> clauses. Return the list of clauses
14449 found. */
14451 static tree
14452 c_parser_cilk_all_clauses (c_parser *parser)
14454 tree clauses = NULL;
14456 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14458 pragma_omp_clause c_kind;
14460 c_kind = c_parser_cilk_clause_name (parser);
14462 switch (c_kind)
14464 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
14465 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false);
14466 break;
14467 case PRAGMA_CILK_CLAUSE_LINEAR:
14468 clauses = c_parser_cilk_clause_linear (parser, clauses);
14469 break;
14470 case PRAGMA_CILK_CLAUSE_PRIVATE:
14471 /* Use the OpenMP counterpart. */
14472 clauses = c_parser_omp_clause_private (parser, clauses);
14473 break;
14474 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE:
14475 /* Use the OpenMP counterpart. */
14476 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
14477 break;
14478 case PRAGMA_CILK_CLAUSE_LASTPRIVATE:
14479 /* Use the OpenMP counterpart. */
14480 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
14481 break;
14482 case PRAGMA_CILK_CLAUSE_REDUCTION:
14483 /* Use the OpenMP counterpart. */
14484 clauses = c_parser_omp_clause_reduction (parser, clauses);
14485 break;
14486 default:
14487 c_parser_error (parser, "expected %<#pragma simd%> clause");
14488 goto saw_error;
14492 saw_error:
14493 c_parser_skip_to_pragma_eol (parser);
14494 return c_finish_cilk_clauses (clauses);
14497 /* Main entry point for parsing Cilk Plus <#pragma simd> for
14498 loops. */
14500 static void
14501 c_parser_cilk_simd (c_parser *parser)
14503 tree clauses = c_parser_cilk_all_clauses (parser);
14504 tree block = c_begin_compound_stmt (true);
14505 location_t loc = c_parser_peek_token (parser)->location;
14506 c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL);
14507 block = c_end_compound_stmt (loc, block, true);
14508 add_stmt (block);
14511 /* Parse a transaction attribute (GCC Extension).
14513 transaction-attribute:
14514 attributes
14515 [ [ any-word ] ]
14517 The transactional memory language description is written for C++,
14518 and uses the C++0x attribute syntax. For compatibility, allow the
14519 bracket style for transactions in C as well. */
14521 static tree
14522 c_parser_transaction_attributes (c_parser *parser)
14524 tree attr_name, attr = NULL;
14526 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
14527 return c_parser_attributes (parser);
14529 if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
14530 return NULL_TREE;
14531 c_parser_consume_token (parser);
14532 if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
14533 goto error1;
14535 attr_name = c_parser_attribute_any_word (parser);
14536 if (attr_name)
14538 c_parser_consume_token (parser);
14539 attr = build_tree_list (attr_name, NULL_TREE);
14541 else
14542 c_parser_error (parser, "expected identifier");
14544 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
14545 error1:
14546 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
14547 return attr;
14550 /* Parse a __transaction_atomic or __transaction_relaxed statement
14551 (GCC Extension).
14553 transaction-statement:
14554 __transaction_atomic transaction-attribute[opt] compound-statement
14555 __transaction_relaxed compound-statement
14557 Note that the only valid attribute is: "outer".
14560 static tree
14561 c_parser_transaction (c_parser *parser, enum rid keyword)
14563 unsigned int old_in = parser->in_transaction;
14564 unsigned int this_in = 1, new_in;
14565 location_t loc = c_parser_peek_token (parser)->location;
14566 tree stmt, attrs;
14568 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
14569 || keyword == RID_TRANSACTION_RELAXED)
14570 && c_parser_next_token_is_keyword (parser, keyword));
14571 c_parser_consume_token (parser);
14573 if (keyword == RID_TRANSACTION_RELAXED)
14574 this_in |= TM_STMT_ATTR_RELAXED;
14575 else
14577 attrs = c_parser_transaction_attributes (parser);
14578 if (attrs)
14579 this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
14582 /* Keep track if we're in the lexical scope of an outer transaction. */
14583 new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
14585 parser->in_transaction = new_in;
14586 stmt = c_parser_compound_statement (parser);
14587 parser->in_transaction = old_in;
14589 if (flag_tm)
14590 stmt = c_finish_transaction (loc, stmt, this_in);
14591 else
14592 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
14593 "%<__transaction_atomic%> without transactional memory support enabled"
14594 : "%<__transaction_relaxed %> "
14595 "without transactional memory support enabled"));
14597 return stmt;
14600 /* Parse a __transaction_atomic or __transaction_relaxed expression
14601 (GCC Extension).
14603 transaction-expression:
14604 __transaction_atomic ( expression )
14605 __transaction_relaxed ( expression )
14608 static struct c_expr
14609 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
14611 struct c_expr ret;
14612 unsigned int old_in = parser->in_transaction;
14613 unsigned int this_in = 1;
14614 location_t loc = c_parser_peek_token (parser)->location;
14615 tree attrs;
14617 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
14618 || keyword == RID_TRANSACTION_RELAXED)
14619 && c_parser_next_token_is_keyword (parser, keyword));
14620 c_parser_consume_token (parser);
14622 if (keyword == RID_TRANSACTION_RELAXED)
14623 this_in |= TM_STMT_ATTR_RELAXED;
14624 else
14626 attrs = c_parser_transaction_attributes (parser);
14627 if (attrs)
14628 this_in |= parse_tm_stmt_attr (attrs, 0);
14631 parser->in_transaction = this_in;
14632 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14634 tree expr = c_parser_expression (parser).value;
14635 ret.original_type = TREE_TYPE (expr);
14636 ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
14637 if (this_in & TM_STMT_ATTR_RELAXED)
14638 TRANSACTION_EXPR_RELAXED (ret.value) = 1;
14639 SET_EXPR_LOCATION (ret.value, loc);
14640 ret.original_code = TRANSACTION_EXPR;
14641 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14643 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
14644 goto error;
14647 else
14649 error:
14650 ret.value = error_mark_node;
14651 ret.original_code = ERROR_MARK;
14652 ret.original_type = NULL;
14654 parser->in_transaction = old_in;
14656 if (!flag_tm)
14657 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
14658 "%<__transaction_atomic%> without transactional memory support enabled"
14659 : "%<__transaction_relaxed %> "
14660 "without transactional memory support enabled"));
14662 return ret;
14665 /* Parse a __transaction_cancel statement (GCC Extension).
14667 transaction-cancel-statement:
14668 __transaction_cancel transaction-attribute[opt] ;
14670 Note that the only valid attribute is "outer".
14673 static tree
14674 c_parser_transaction_cancel (c_parser *parser)
14676 location_t loc = c_parser_peek_token (parser)->location;
14677 tree attrs;
14678 bool is_outer = false;
14680 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
14681 c_parser_consume_token (parser);
14683 attrs = c_parser_transaction_attributes (parser);
14684 if (attrs)
14685 is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
14687 if (!flag_tm)
14689 error_at (loc, "%<__transaction_cancel%> without "
14690 "transactional memory support enabled");
14691 goto ret_error;
14693 else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
14695 error_at (loc, "%<__transaction_cancel%> within a "
14696 "%<__transaction_relaxed%>");
14697 goto ret_error;
14699 else if (is_outer)
14701 if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
14702 && !is_tm_may_cancel_outer (current_function_decl))
14704 error_at (loc, "outer %<__transaction_cancel%> not "
14705 "within outer %<__transaction_atomic%>");
14706 error_at (loc, " or a %<transaction_may_cancel_outer%> function");
14707 goto ret_error;
14710 else if (parser->in_transaction == 0)
14712 error_at (loc, "%<__transaction_cancel%> not within "
14713 "%<__transaction_atomic%>");
14714 goto ret_error;
14717 return add_stmt (build_tm_abort_call (loc, is_outer));
14719 ret_error:
14720 return build1 (NOP_EXPR, void_type_node, error_mark_node);
14723 /* Parse a single source file. */
14725 void
14726 c_parse_file (void)
14728 /* Use local storage to begin. If the first token is a pragma, parse it.
14729 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14730 which will cause garbage collection. */
14731 c_parser tparser;
14733 memset (&tparser, 0, sizeof tparser);
14734 tparser.tokens = &tparser.tokens_buf[0];
14735 the_parser = &tparser;
14737 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
14738 c_parser_pragma_pch_preprocess (&tparser);
14740 the_parser = ggc_alloc<c_parser> ();
14741 *the_parser = tparser;
14742 if (tparser.tokens == &tparser.tokens_buf[0])
14743 the_parser->tokens = &the_parser->tokens_buf[0];
14745 /* Initialize EH, if we've been told to do so. */
14746 if (flag_exceptions)
14747 using_eh_for_cleanups ();
14749 c_parser_translation_unit (the_parser);
14750 the_parser = NULL;
14753 /* This function parses Cilk Plus array notation. The starting index is
14754 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14755 return value of this function is a tree_node called VALUE_TREE of type
14756 ARRAY_NOTATION_REF. */
14758 static tree
14759 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
14760 tree array_value)
14762 c_token *token = NULL;
14763 tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE;
14764 tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE;
14765 tree array_type_domain = NULL_TREE;
14767 if (array_value == error_mark_node)
14769 /* No need to continue. If either of these 2 were true, then an error
14770 must be emitted already. Thus, no need to emit them twice. */
14771 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
14772 return error_mark_node;
14775 array_type = TREE_TYPE (array_value);
14776 gcc_assert (array_type);
14777 type = TREE_TYPE (array_type);
14778 token = c_parser_peek_token (parser);
14780 if (token->type == CPP_EOF)
14782 c_parser_error (parser, "expected %<:%> or numeral");
14783 return value_tree;
14785 else if (token->type == CPP_COLON)
14787 if (!initial_index)
14789 /* If we are here, then we have a case like this A[:]. */
14790 c_parser_consume_token (parser);
14791 if (TREE_CODE (array_type) == POINTER_TYPE)
14793 error_at (loc, "start-index and length fields necessary for "
14794 "using array notations in pointers");
14795 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
14796 return error_mark_node;
14798 if (TREE_CODE (array_type) == FUNCTION_TYPE)
14800 error_at (loc, "array notations cannot be used with function "
14801 "type");
14802 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
14803 return error_mark_node;
14805 array_type_domain = TYPE_DOMAIN (array_type);
14807 if (!array_type_domain)
14809 error_at (loc, "start-index and length fields necessary for "
14810 "using array notations in dimensionless arrays");
14811 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
14812 return error_mark_node;
14815 start_index = TYPE_MINVAL (array_type_domain);
14816 start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node,
14817 start_index);
14818 if (!TYPE_MAXVAL (array_type_domain)
14819 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain)))
14821 error_at (loc, "start-index and length fields necessary for "
14822 "using array notations in variable-length arrays");
14823 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
14824 return error_mark_node;
14826 end_index = TYPE_MAXVAL (array_type_domain);
14827 end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index),
14828 end_index, integer_one_node);
14829 end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index);
14830 stride = build_int_cst (integer_type_node, 1);
14831 stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride);
14833 else if (initial_index != error_mark_node)
14835 /* If we are here, then there should be 2 possibilities:
14836 1. Array [EXPR : EXPR]
14837 2. Array [EXPR : EXPR : EXPR]
14839 start_index = initial_index;
14841 if (TREE_CODE (array_type) == FUNCTION_TYPE)
14843 error_at (loc, "array notations cannot be used with function "
14844 "type");
14845 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
14846 return error_mark_node;
14848 c_parser_consume_token (parser); /* consume the ':' */
14849 struct c_expr ce = c_parser_expression (parser);
14850 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
14851 end_index = ce.value;
14852 if (!end_index || end_index == error_mark_node)
14854 c_parser_skip_to_end_of_block_or_statement (parser);
14855 return error_mark_node;
14857 if (c_parser_peek_token (parser)->type == CPP_COLON)
14859 c_parser_consume_token (parser);
14860 ce = c_parser_expression (parser);
14861 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
14862 stride = ce.value;
14863 if (!stride || stride == error_mark_node)
14865 c_parser_skip_to_end_of_block_or_statement (parser);
14866 return error_mark_node;
14870 else
14871 c_parser_error (parser, "expected array notation expression");
14873 else
14874 c_parser_error (parser, "expected array notation expression");
14876 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
14878 value_tree = build_array_notation_ref (loc, array_value, start_index,
14879 end_index, stride, type);
14880 if (value_tree != error_mark_node)
14881 SET_EXPR_LOCATION (value_tree, loc);
14882 return value_tree;
14885 #include "gt-c-c-parser.h"