1/* Parser for C and Objective-C.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
3
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
6
7This file is part of GCC.
8
9GCC is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 3, or (at your option) any later
12version.
13
14GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17for more details.
18
19You should have received a copy of the GNU General Public License
20along with GCC; see the file COPYING3. If not see
21<http://www.gnu.org/licenses/>. */
22
23/* TODO:
24
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
27 of syntax accepted.
28
29 Add testcases covering every input symbol in every state in old and
30 new parsers.
31
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
34
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
37
38#include "config.h"
39#define INCLUDE_UNIQUE_PTR
40#include "system.h"
41#include "coretypes.h"
42#include "target.h"
43#include "function.h"
44#include "c-tree.h"
45#include "timevar.h"
46#include "stringpool.h"
47#include "cgraph.h"
48#include "attribs.h"
49#include "stor-layout.h"
50#include "varasm.h"
51#include "trans-mem.h"
52#include "c-family/c-pragma.h"
53#include "c-lang.h"
54#include "c-family/c-objc.h"
55#include "plugin.h"
56#include "omp-general.h"
57#include "omp-offload.h"
58#include "builtins.h"
59#include "gomp-constants.h"
60#include "c-family/c-indentation.h"
61#include "gimple-expr.h"
62#include "context.h"
63#include "gcc-rich-location.h"
64#include "c-parser.h"
65#include "gimple-parser.h"
66#include "read-rtl-function.h"
67#include "run-rtl-passes.h"
68#include "intl.h"
69#include "c-family/name-hint.h"
70#include "tree-iterator.h"
71
72/* We need to walk over decls with incomplete struct/union/enum types
73 after parsing the whole translation unit.
74 In finish_decl(), if the decl is static, has incomplete
75 struct/union/enum type, it is appeneded to incomplete_record_decls.
76 In c_parser_translation_unit(), we iterate over incomplete_record_decls
77 and report error if any of the decls are still incomplete. */
78
79vec<tree> incomplete_record_decls;
80
81void
82set_c_expr_source_range (c_expr *expr,
83 location_t start, location_t finish)
84{
85 expr->src_range.m_start = start;
86 expr->src_range.m_finish = finish;
87 if (expr->value)
88 set_source_range (expr->value, start, finish);
89}
90
91void
92set_c_expr_source_range (c_expr *expr,
93 source_range src_range)
94{
95 expr->src_range = src_range;
96 if (expr->value)
97 set_source_range (expr->value, src_range);
98}
99
100
101/* Initialization routine for this file. */
102
103void
104c_parse_init (void)
105{
106 /* The only initialization required is of the reserved word
107 identifiers. */
108 unsigned int i;
109 tree id;
110 int mask = 0;
111
112 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
113 the c_token structure. */
114 gcc_assert (RID_MAX <= 255);
115
116 mask |= D_CXXONLY;
117 if (!flag_isoc99)
118 mask |= D_C99;
119 if (flag_no_asm)
120 {
121 mask |= D_ASM | D_EXT;
122 if (!flag_isoc99)
123 mask |= D_EXT89;
124 }
125 if (!c_dialect_objc ())
126 mask |= D_OBJC | D_CXX_OBJC;
127
128 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
129 for (i = 0; i < num_c_common_reswords; i++)
130 {
131 /* If a keyword is disabled, do not enter it into the table
132 and so create a canonical spelling that isn't a keyword. */
133 if (c_common_reswords[i].disable & mask)
134 {
135 if (warn_cxx_compat
136 && (c_common_reswords[i].disable & D_CXXWARN))
137 {
138 id = get_identifier (c_common_reswords[i].word);
139 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
140 C_IS_RESERVED_WORD (id) = 1;
141 }
142 continue;
143 }
144
145 id = get_identifier (c_common_reswords[i].word);
146 C_SET_RID_CODE (id, c_common_reswords[i].rid);
147 C_IS_RESERVED_WORD (id) = 1;
148 ridpointers [(int) c_common_reswords[i].rid] = id;
149 }
150
151 for (i = 0; i < NUM_INT_N_ENTS; i++)
152 {
153 /* We always create the symbols but they aren't always supported. */
154 char name[50];
155 sprintf (name, "__int%d", int_n_data[i].bitsize);
156 id = get_identifier (name);
157 C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
158 C_IS_RESERVED_WORD (id) = 1;
159 }
160}
161
162/* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165struct GTY(()) c_parser {
166 /* The look-ahead tokens. */
167 c_token * GTY((skip)) tokens;
168 /* Buffer for look-ahead tokens. */
169 c_token tokens_buf[4];
170 /* How many look-ahead tokens are available (0 - 4, or
171 more if parsing from pre-lexed tokens). */
172 unsigned int tokens_avail;
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error : 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma : 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block : 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string : 1;
184
185 /* Objective-C specific parser/lexer information. */
186
187 /* True if we are in a context where the Objective-C "PQ" keywords
188 are considered keywords. */
189 BOOL_BITFIELD objc_pq_context : 1;
190 /* True if we are parsing a (potential) Objective-C foreach
191 statement. This is set to true after we parsed 'for (' and while
192 we wait for 'in' or ';' to decide if it's a standard C for loop or an
193 Objective-C foreach loop. */
194 BOOL_BITFIELD objc_could_be_foreach_context : 1;
195 /* The following flag is needed to contextualize Objective-C lexical
196 analysis. In some cases (e.g., 'int NSObject;'), it is
197 undesirable to bind an identifier to an Objective-C class, even
198 if a class with that name exists. */
199 BOOL_BITFIELD objc_need_raw_identifier : 1;
200 /* Nonzero if we're processing a __transaction statement. The value
201 is 1 | TM_STMT_ATTR_*. */
202 unsigned int in_transaction : 4;
203 /* True if we are in a context where the Objective-C "Property attribute"
204 keywords are valid. */
205 BOOL_BITFIELD objc_property_attr_context : 1;
206
207 /* Location of the last consumed token. */
208 location_t last_token_location;
209};
210
211/* Return a pointer to the Nth token in PARSERs tokens_buf. */
212
213c_token *
214c_parser_tokens_buf (c_parser *parser, unsigned n)
215{
216 return &parser->tokens_buf[n];
217}
218
219/* Return the error state of PARSER. */
220
221bool
222c_parser_error (c_parser *parser)
223{
224 return parser->error;
225}
226
227/* Set the error state of PARSER to ERR. */
228
229void
230c_parser_set_error (c_parser *parser, bool err)
231{
232 parser->error = err;
233}
234
235
236/* The actual parser and external interface. ??? Does this need to be
237 garbage-collected? */
238
239static GTY (()) c_parser *the_parser;
240
241/* Read in and lex a single token, storing it in *TOKEN. */
242
243static void
244c_lex_one_token (c_parser *parser, c_token *token)
245{
246 timevar_push (TV_LEX);
247
248 token->type = c_lex_with_flags (&token->value, &token->location,
249 &token->flags,
250 (parser->lex_untranslated_string
251 ? C_LEX_STRING_NO_TRANSLATE : 0));
252 token->id_kind = C_ID_NONE;
253 token->keyword = RID_MAX;
254 token->pragma_kind = PRAGMA_NONE;
255
256 switch (token->type)
257 {
258 case CPP_NAME:
259 {
260 tree decl;
261
262 bool objc_force_identifier = parser->objc_need_raw_identifier;
263 if (c_dialect_objc ())
264 parser->objc_need_raw_identifier = false;
265
266 if (C_IS_RESERVED_WORD (token->value))
267 {
268 enum rid rid_code = C_RID_CODE (token->value);
269
270 if (rid_code == RID_CXX_COMPAT_WARN)
271 {
272 warning_at (token->location,
273 OPT_Wc___compat,
274 "identifier %qE conflicts with C++ keyword",
275 token->value);
276 }
277 else if (rid_code >= RID_FIRST_ADDR_SPACE
278 && rid_code <= RID_LAST_ADDR_SPACE)
279 {
280 addr_space_t as;
281 as = (addr_space_t) (rid_code - RID_FIRST_ADDR_SPACE);
282 targetm.addr_space.diagnose_usage (as, token->location);
283 token->id_kind = C_ID_ADDRSPACE;
284 token->keyword = rid_code;
285 break;
286 }
287 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
288 {
289 /* We found an Objective-C "pq" keyword (in, out,
290 inout, bycopy, byref, oneway). They need special
291 care because the interpretation depends on the
292 context. */
293 if (parser->objc_pq_context)
294 {
295 token->type = CPP_KEYWORD;
296 token->keyword = rid_code;
297 break;
298 }
299 else if (parser->objc_could_be_foreach_context
300 && rid_code == RID_IN)
301 {
302 /* We are in Objective-C, inside a (potential)
303 foreach context (which means after having
304 parsed 'for (', but before having parsed ';'),
305 and we found 'in'. We consider it the keyword
306 which terminates the declaration at the
307 beginning of a foreach-statement. Note that
308 this means you can't use 'in' for anything else
309 in that context; in particular, in Objective-C
310 you can't use 'in' as the name of the running
311 variable in a C for loop. We could potentially
312 try to add code here to disambiguate, but it
313 seems a reasonable limitation. */
314 token->type = CPP_KEYWORD;
315 token->keyword = rid_code;
316 break;
317 }
318 /* Else, "pq" keywords outside of the "pq" context are
319 not keywords, and we fall through to the code for
320 normal tokens. */
321 }
322 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
323 {
324 /* We found an Objective-C "property attribute"
325 keyword (getter, setter, readonly, etc). These are
326 only valid in the property context. */
327 if (parser->objc_property_attr_context)
328 {
329 token->type = CPP_KEYWORD;
330 token->keyword = rid_code;
331 break;
332 }
333 /* Else they are not special keywords.
334 */
335 }
336 else if (c_dialect_objc ()
337 && (OBJC_IS_AT_KEYWORD (rid_code)
338 || OBJC_IS_CXX_KEYWORD (rid_code)))
339 {
340 /* We found one of the Objective-C "@" keywords (defs,
341 selector, synchronized, etc) or one of the
342 Objective-C "cxx" keywords (class, private,
343 protected, public, try, catch, throw) without a
344 preceding '@' sign. Do nothing and fall through to
345 the code for normal tokens (in C++ we would still
346 consider the CXX ones keywords, but not in C). */
347 ;
348 }
349 else
350 {
351 token->type = CPP_KEYWORD;
352 token->keyword = rid_code;
353 break;
354 }
355 }
356
357 decl = lookup_name (token->value);
358 if (decl)
359 {
360 if (TREE_CODE (decl) == TYPE_DECL)
361 {
362 token->id_kind = C_ID_TYPENAME;
363 break;
364 }
365 }
366 else if (c_dialect_objc ())
367 {
368 tree objc_interface_decl = objc_is_class_name (token->value);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
371 declarations. */
372 if (objc_interface_decl
373 && (!objc_force_identifier || global_bindings_p ()))
374 {
375 token->value = objc_interface_decl;
376 token->id_kind = C_ID_CLASSNAME;
377 break;
378 }
379 }
380 token->id_kind = C_ID_ID;
381 }
382 break;
383 case CPP_AT_NAME:
384 /* This only happens in Objective-C; it must be a keyword. */
385 token->type = CPP_KEYWORD;
386 switch (C_RID_CODE (token->value))
387 {
388 /* Replace 'class' with '@class', 'private' with '@private',
389 etc. This prevents confusion with the C++ keyword
390 'class', and makes the tokens consistent with other
391 Objective-C 'AT' keywords. For example '@class' is
392 reported as RID_AT_CLASS which is consistent with
393 '@synchronized', which is reported as
394 RID_AT_SYNCHRONIZED.
395 */
396 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
397 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
398 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
399 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
400 case RID_THROW: token->keyword = RID_AT_THROW; break;
401 case RID_TRY: token->keyword = RID_AT_TRY; break;
402 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
403 case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break;
404 default: token->keyword = C_RID_CODE (token->value);
405 }
406 break;
407 case CPP_COLON:
408 case CPP_COMMA:
409 case CPP_CLOSE_PAREN:
410 case CPP_SEMICOLON:
411 /* These tokens may affect the interpretation of any identifiers
412 following, if doing Objective-C. */
413 if (c_dialect_objc ())
414 parser->objc_need_raw_identifier = false;
415 break;
416 case CPP_PRAGMA:
417 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
418 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
419 token->value = NULL;
420 break;
421 default:
422 break;
423 }
424 timevar_pop (TV_LEX);
425}
426
427/* Return a pointer to the next token from PARSER, reading it in if
428 necessary. */
429
430c_token *
431c_parser_peek_token (c_parser *parser)
432{
433 if (parser->tokens_avail == 0)
434 {
435 c_lex_one_token (parser, &parser->tokens[0]);
436 parser->tokens_avail = 1;
437 }
438 return &parser->tokens[0];
439}
440
441/* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
443
444c_token *
445c_parser_peek_2nd_token (c_parser *parser)
446{
447 if (parser->tokens_avail >= 2)
448 return &parser->tokens[1];
449 gcc_assert (parser->tokens_avail == 1);
450 gcc_assert (parser->tokens[0].type != CPP_EOF);
451 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
452 c_lex_one_token (parser, &parser->tokens[1]);
453 parser->tokens_avail = 2;
454 return &parser->tokens[1];
455}
456
457/* Return a pointer to the Nth token from PARSER, reading it
458 in if necessary. The N-1th token is already read in. */
459
460c_token *
461c_parser_peek_nth_token (c_parser *parser, unsigned int n)
462{
463 /* N is 1-based, not zero-based. */
464 gcc_assert (n > 0);
465
466 if (parser->tokens_avail >= n)
467 return &parser->tokens[n - 1];
468 gcc_assert (parser->tokens_avail == n - 1);
469 c_lex_one_token (parser, &parser->tokens[n - 1]);
470 parser->tokens_avail = n;
471 return &parser->tokens[n - 1];
472}
473
474bool
475c_keyword_starts_typename (enum rid keyword)
476{
477 switch (keyword)
478 {
479 case RID_UNSIGNED:
480 case RID_LONG:
481 case RID_SHORT:
482 case RID_SIGNED:
483 case RID_COMPLEX:
484 case RID_INT:
485 case RID_CHAR:
486 case RID_FLOAT:
487 case RID_DOUBLE:
488 case RID_VOID:
489 case RID_DFLOAT32:
490 case RID_DFLOAT64:
491 case RID_DFLOAT128:
492 CASE_RID_FLOATN_NX:
493 case RID_BOOL:
494 case RID_ENUM:
495 case RID_STRUCT:
496 case RID_UNION:
497 case RID_TYPEOF:
498 case RID_CONST:
499 case RID_ATOMIC:
500 case RID_VOLATILE:
501 case RID_RESTRICT:
502 case RID_ATTRIBUTE:
503 case RID_FRACT:
504 case RID_ACCUM:
505 case RID_SAT:
506 case RID_AUTO_TYPE:
507 case RID_ALIGNAS:
508 return true;
509 default:
510 if (keyword >= RID_FIRST_INT_N
511 && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
512 && int_n_enabled_p[keyword - RID_FIRST_INT_N])
513 return true;
514 return false;
515 }
516}
517
518/* Return true if TOKEN can start a type name,
519 false otherwise. */
520bool
521c_token_starts_typename (c_token *token)
522{
523 switch (token->type)
524 {
525 case CPP_NAME:
526 switch (token->id_kind)
527 {
528 case C_ID_ID:
529 return false;
530 case C_ID_ADDRSPACE:
531 return true;
532 case C_ID_TYPENAME:
533 return true;
534 case C_ID_CLASSNAME:
535 gcc_assert (c_dialect_objc ());
536 return true;
537 default:
538 gcc_unreachable ();
539 }
540 case CPP_KEYWORD:
541 return c_keyword_starts_typename (token->keyword);
542 case CPP_LESS:
543 if (c_dialect_objc ())
544 return true;
545 return false;
546 default:
547 return false;
548 }
549}
550
551/* Return true if the next token from PARSER can start a type name,
552 false otherwise. LA specifies how to do lookahead in order to
553 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
554
555static inline bool
556c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
557{
558 c_token *token = c_parser_peek_token (parser);
559 if (c_token_starts_typename (token))
560 return true;
561
562 /* Try a bit harder to detect an unknown typename. */
563 if (la != cla_prefer_id
564 && token->type == CPP_NAME
565 && token->id_kind == C_ID_ID
566
567 /* Do not try too hard when we could have "object in array". */
568 && !parser->objc_could_be_foreach_context
569
570 && (la == cla_prefer_type
571 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
572 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
573
574 /* Only unknown identifiers. */
575 && !lookup_name (token->value))
576 return true;
577
578 return false;
579}
580
581/* Return true if TOKEN is a type qualifier, false otherwise. */
582static bool
583c_token_is_qualifier (c_token *token)
584{
585 switch (token->type)
586 {
587 case CPP_NAME:
588 switch (token->id_kind)
589 {
590 case C_ID_ADDRSPACE:
591 return true;
592 default:
593 return false;
594 }
595 case CPP_KEYWORD:
596 switch (token->keyword)
597 {
598 case RID_CONST:
599 case RID_VOLATILE:
600 case RID_RESTRICT:
601 case RID_ATTRIBUTE:
602 case RID_ATOMIC:
603 return true;
604 default:
605 return false;
606 }
607 case CPP_LESS:
608 return false;
609 default:
610 gcc_unreachable ();
611 }
612}
613
614/* Return true if the next token from PARSER is a type qualifier,
615 false otherwise. */
616static inline bool
617c_parser_next_token_is_qualifier (c_parser *parser)
618{
619 c_token *token = c_parser_peek_token (parser);
620 return c_token_is_qualifier (token);
621}
622
623/* Return true if TOKEN can start declaration specifiers, false
624 otherwise. */
625static bool
626c_token_starts_declspecs (c_token *token)
627{
628 switch (token->type)
629 {
630 case CPP_NAME:
631 switch (token->id_kind)
632 {
633 case C_ID_ID:
634 return false;
635 case C_ID_ADDRSPACE:
636 return true;
637 case C_ID_TYPENAME:
638 return true;
639 case C_ID_CLASSNAME:
640 gcc_assert (c_dialect_objc ());
641 return true;
642 default:
643 gcc_unreachable ();
644 }
645 case CPP_KEYWORD:
646 switch (token->keyword)
647 {
648 case RID_STATIC:
649 case RID_EXTERN:
650 case RID_REGISTER:
651 case RID_TYPEDEF:
652 case RID_INLINE:
653 case RID_NORETURN:
654 case RID_AUTO:
655 case RID_THREAD:
656 case RID_UNSIGNED:
657 case RID_LONG:
658 case RID_SHORT:
659 case RID_SIGNED:
660 case RID_COMPLEX:
661 case RID_INT:
662 case RID_CHAR:
663 case RID_FLOAT:
664 case RID_DOUBLE:
665 case RID_VOID:
666 case RID_DFLOAT32:
667 case RID_DFLOAT64:
668 case RID_DFLOAT128:
669 CASE_RID_FLOATN_NX:
670 case RID_BOOL:
671 case RID_ENUM:
672 case RID_STRUCT:
673 case RID_UNION:
674 case RID_TYPEOF:
675 case RID_CONST:
676 case RID_VOLATILE:
677 case RID_RESTRICT:
678 case RID_ATTRIBUTE:
679 case RID_FRACT:
680 case RID_ACCUM:
681 case RID_SAT:
682 case RID_ALIGNAS:
683 case RID_ATOMIC:
684 case RID_AUTO_TYPE:
685 return true;
686 default:
687 if (token->keyword >= RID_FIRST_INT_N
688 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
689 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
690 return true;
691 return false;
692 }
693 case CPP_LESS:
694 if (c_dialect_objc ())
695 return true;
696 return false;
697 default:
698 return false;
699 }
700}
701
702
703/* Return true if TOKEN can start declaration specifiers or a static
704 assertion, false otherwise. */
705static bool
706c_token_starts_declaration (c_token *token)
707{
708 if (c_token_starts_declspecs (token)
709 || token->keyword == RID_STATIC_ASSERT)
710 return true;
711 else
712 return false;
713}
714
715/* Return true if the next token from PARSER can start declaration
716 specifiers, false otherwise. */
717bool
718c_parser_next_token_starts_declspecs (c_parser *parser)
719{
720 c_token *token = c_parser_peek_token (parser);
721
722 /* In Objective-C, a classname normally starts a declspecs unless it
723 is immediately followed by a dot. In that case, it is the
724 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
725 setter/getter on the class. c_token_starts_declspecs() can't
726 differentiate between the two cases because it only checks the
727 current token, so we have a special check here. */
728 if (c_dialect_objc ()
729 && token->type == CPP_NAME
730 && token->id_kind == C_ID_CLASSNAME
731 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
732 return false;
733
734 return c_token_starts_declspecs (token);
735}
736
737/* Return true if the next tokens from PARSER can start declaration
738 specifiers or a static assertion, false otherwise. */
739bool
740c_parser_next_tokens_start_declaration (c_parser *parser)
741{
742 c_token *token = c_parser_peek_token (parser);
743
744 /* Same as above. */
745 if (c_dialect_objc ()
746 && token->type == CPP_NAME
747 && token->id_kind == C_ID_CLASSNAME
748 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
749 return false;
750
751 /* Labels do not start declarations. */
752 if (token->type == CPP_NAME
753 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
754 return false;
755
756 if (c_token_starts_declaration (token))
757 return true;
758
759 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
760 return true;
761
762 return false;
763}
764
765/* Consume the next token from PARSER. */
766
767void
768c_parser_consume_token (c_parser *parser)
769{
770 gcc_assert (parser->tokens_avail >= 1);
771 gcc_assert (parser->tokens[0].type != CPP_EOF);
772 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
773 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
774 parser->last_token_location = parser->tokens[0].location;
775 if (parser->tokens != &parser->tokens_buf[0])
776 parser->tokens++;
777 else if (parser->tokens_avail == 2)
778 parser->tokens[0] = parser->tokens[1];
779 parser->tokens_avail--;
780}
781
782/* Expect the current token to be a #pragma. Consume it and remember
783 that we've begun parsing a pragma. */
784
785static void
786c_parser_consume_pragma (c_parser *parser)
787{
788 gcc_assert (!parser->in_pragma);
789 gcc_assert (parser->tokens_avail >= 1);
790 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
791 if (parser->tokens != &parser->tokens_buf[0])
792 parser->tokens++;
793 else if (parser->tokens_avail == 2)
794 parser->tokens[0] = parser->tokens[1];
795 parser->tokens_avail--;
796 parser->in_pragma = true;
797}
798
799/* Update the global input_location from TOKEN. */
800static inline void
801c_parser_set_source_position_from_token (c_token *token)
802{
803 if (token->type != CPP_EOF)
804 {
805 input_location = token->location;
806 }
807}
808
809/* Helper function for c_parser_error.
810 Having peeked a token of kind TOK1_KIND that might signify
811 a conflict marker, peek successor tokens to determine
812 if we actually do have a conflict marker.
813 Specifically, we consider a run of 7 '<', '=' or '>' characters
814 at the start of a line as a conflict marker.
815 These come through the lexer as three pairs and a single,
816 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
817 If it returns true, *OUT_LOC is written to with the location/range
818 of the marker. */
819
820static bool
821c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind,
822 location_t *out_loc)
823{
824 c_token *token2 = c_parser_peek_2nd_token (parser);
825 if (token2->type != tok1_kind)
826 return false;
827 c_token *token3 = c_parser_peek_nth_token (parser, 3);
828 if (token3->type != tok1_kind)
829 return false;
830 c_token *token4 = c_parser_peek_nth_token (parser, 4);
831 if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind))
832 return false;
833
834 /* It must be at the start of the line. */
835 location_t start_loc = c_parser_peek_token (parser)->location;
836 if (LOCATION_COLUMN (start_loc) != 1)
837 return false;
838
839 /* We have a conflict marker. Construct a location of the form:
840 <<<<<<<
841 ^~~~~~~
842 with start == caret, finishing at the end of the marker. */
843 location_t finish_loc = get_finish (token4->location);
844 *out_loc = make_location (start_loc, start_loc, finish_loc);
845
846 return true;
847}
848
849/* Issue a diagnostic of the form
850 FILE:LINE: MESSAGE before TOKEN
851 where TOKEN is the next token in the input stream of PARSER.
852 MESSAGE (specified by the caller) is usually of the form "expected
853 OTHER-TOKEN".
854
855 Use RICHLOC as the location of the diagnostic.
856
857 Do not issue a diagnostic if still recovering from an error.
858
859 Return true iff an error was actually emitted.
860
861 ??? This is taken from the C++ parser, but building up messages in
862 this way is not i18n-friendly and some other approach should be
863 used. */
864
865static bool
866c_parser_error_richloc (c_parser *parser, const char *gmsgid,
867 rich_location *richloc)
868{
869 c_token *token = c_parser_peek_token (parser);
870 if (parser->error)
871 return false;
872 parser->error = true;
873 if (!gmsgid)
874 return false;
875
876 /* If this is actually a conflict marker, report it as such. */
877 if (token->type == CPP_LSHIFT
878 || token->type == CPP_RSHIFT
879 || token->type == CPP_EQ_EQ)
880 {
881 location_t loc;
882 if (c_parser_peek_conflict_marker (parser, token->type, &loc))
883 {
884 error_at (loc, "version control conflict marker in file");
885 return true;
886 }
887 }
888
889 c_parse_error (gmsgid,
890 /* Because c_parse_error does not understand
891 CPP_KEYWORD, keywords are treated like
892 identifiers. */
893 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
894 /* ??? The C parser does not save the cpp flags of a
895 token, we need to pass 0 here and we will not get
896 the source spelling of some tokens but rather the
897 canonical spelling. */
898 token->value, /*flags=*/0, richloc);
899 return true;
900}
901
902/* As c_parser_error_richloc, but issue the message at the
903 location of PARSER's next token, or at input_location
904 if the next token is EOF. */
905
906bool
907c_parser_error (c_parser *parser, const char *gmsgid)
908{
909 c_token *token = c_parser_peek_token (parser);
910 c_parser_set_source_position_from_token (token);
911 rich_location richloc (line_table, input_location);
912 return c_parser_error_richloc (parser, gmsgid, &richloc);
913}
914
915/* Some tokens naturally come in pairs e.g.'(' and ')'.
916 This class is for tracking such a matching pair of symbols.
917 In particular, it tracks the location of the first token,
918 so that if the second token is missing, we can highlight the
919 location of the first token when notifying the user about the
920 problem. */
921
922template <typename traits_t>
923class token_pair
924{
925 public:
926 /* token_pair's ctor. */
927 token_pair () : m_open_loc (UNKNOWN_LOCATION) {}
928
929 /* If the next token is the opening symbol for this pair, consume it and
930 return true.
931 Otherwise, issue an error and return false.
932 In either case, record the location of the opening token. */
933
934 bool require_open (c_parser *parser)
935 {
936 c_token *token = c_parser_peek_token (parser);
937 if (token)
938 m_open_loc = token->location;
939
940 return c_parser_require (parser, traits_t::open_token_type,
941 traits_t::open_gmsgid);
942 }
943
944 /* Consume the next token from PARSER, recording its location as
945 that of the opening token within the pair. */
946
947 void consume_open (c_parser *parser)
948 {
949 c_token *token = c_parser_peek_token (parser);
950 gcc_assert (token->type == traits_t::open_token_type);
951 m_open_loc = token->location;
952 c_parser_consume_token (parser);
953 }
954
955 /* If the next token is the closing symbol for this pair, consume it
956 and return true.
957 Otherwise, issue an error, highlighting the location of the
958 corresponding opening token, and return false. */
959
960 bool require_close (c_parser *parser) const
961 {
962 return c_parser_require (parser, traits_t::close_token_type,
963 traits_t::close_gmsgid, m_open_loc);
964 }
965
966 /* Like token_pair::require_close, except that tokens will be skipped
967 until the desired token is found. An error message is still produced
968 if the next token is not as expected. */
969
970 void skip_until_found_close (c_parser *parser) const
971 {
972 c_parser_skip_until_found (parser, traits_t::close_token_type,
973 traits_t::close_gmsgid, m_open_loc);
974 }
975
976 private:
977 location_t m_open_loc;
978};
979
980/* Traits for token_pair<T> for tracking matching pairs of parentheses. */
981
982struct matching_paren_traits
983{
984 static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN;
985 static const char * const open_gmsgid;
986 static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN;
987 static const char * const close_gmsgid;
988};
989
990const char * const matching_paren_traits::open_gmsgid = "expected %<(%>";
991const char * const matching_paren_traits::close_gmsgid = "expected %<)%>";
992
993/* "matching_parens" is a token_pair<T> class for tracking matching
994 pairs of parentheses. */
995
996typedef token_pair<matching_paren_traits> matching_parens;
997
998/* Traits for token_pair<T> for tracking matching pairs of braces. */
999
1000struct matching_brace_traits
1001{
1002 static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE;
1003 static const char * const open_gmsgid;
1004 static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE;
1005 static const char * const close_gmsgid;
1006};
1007
1008const char * const matching_brace_traits::open_gmsgid = "expected %<{%>";
1009const char * const matching_brace_traits::close_gmsgid = "expected %<}%>";
1010
1011/* "matching_braces" is a token_pair<T> class for tracking matching
1012 pairs of braces. */
1013
1014typedef token_pair<matching_brace_traits> matching_braces;
1015
1016/* Get a description of the matching symbol to TYPE e.g. "(" for
1017 CPP_CLOSE_PAREN. */
1018
1019static const char *
1020get_matching_symbol (enum cpp_ttype type)
1021{
1022 switch (type)
1023 {
1024 default:
1025 gcc_unreachable ();
1026 return "";
1027 case CPP_CLOSE_PAREN:
1028 return "(";
1029 case CPP_CLOSE_BRACE:
1030 return "{";
1031 }
1032}
1033
1034/* If the next token is of the indicated TYPE, consume it. Otherwise,
1035 issue the error MSGID. If MSGID is NULL then a message has already
1036 been produced and no message will be produced this time. Returns
1037 true if found, false otherwise.
1038
1039 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1040 within any error as the location of an "opening" token matching
1041 the close token TYPE (e.g. the location of the '(' when TYPE is
1042 CPP_CLOSE_PAREN).
1043
1044 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1045 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1046 attempt to generate a fix-it hint for the problem.
1047 Otherwise msgid describes multiple token types (e.g.
1048 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1049 generate a fix-it hint. */
1050
1051bool
1052c_parser_require (c_parser *parser,
1053 enum cpp_ttype type,
1054 const char *msgid,
1055 location_t matching_location,
1056 bool type_is_unique)
1057{
1058 if (c_parser_next_token_is (parser, type))
1059 {
1060 c_parser_consume_token (parser);
1061 return true;
1062 }
1063 else
1064 {
1065 location_t next_token_loc = c_parser_peek_token (parser)->location;
1066 gcc_rich_location richloc (next_token_loc);
1067
1068 /* Potentially supply a fix-it hint, suggesting to add the
1069 missing token immediately after the *previous* token.
1070 This may move the primary location within richloc. */
1071 if (!parser->error && type_is_unique)
1072 maybe_suggest_missing_token_insertion (&richloc, type,
1073 parser->last_token_location);
1074
1075 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1076 Attempt to consolidate diagnostics by printing it as a
1077 secondary range within the main diagnostic. */
1078 bool added_matching_location = false;
1079 if (matching_location != UNKNOWN_LOCATION)
1080 added_matching_location
1081 = richloc.add_location_if_nearby (matching_location);
1082
1083 if (c_parser_error_richloc (parser, msgid, &richloc))
1084 /* If we weren't able to consolidate matching_location, then
1085 print it as a secondary diagnostic. */
1086 if (matching_location != UNKNOWN_LOCATION && !added_matching_location)
1087 inform (matching_location, "to match this %qs",
1088 get_matching_symbol (type));
1089
1090 return false;
1091 }
1092}
1093
1094/* If the next token is the indicated keyword, consume it. Otherwise,
1095 issue the error MSGID. Returns true if found, false otherwise. */
1096
1097static bool
1098c_parser_require_keyword (c_parser *parser,
1099 enum rid keyword,
1100 const char *msgid)
1101{
1102 if (c_parser_next_token_is_keyword (parser, keyword))
1103 {
1104 c_parser_consume_token (parser);
1105 return true;
1106 }
1107 else
1108 {
1109 c_parser_error (parser, msgid);
1110 return false;
1111 }
1112}
1113
1114/* Like c_parser_require, except that tokens will be skipped until the
1115 desired token is found. An error message is still produced if the
1116 next token is not as expected. If MSGID is NULL then a message has
1117 already been produced and no message will be produced this
1118 time.
1119
1120 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1121 within any error as the location of an "opening" token matching
1122 the close token TYPE (e.g. the location of the '(' when TYPE is
1123 CPP_CLOSE_PAREN). */
1124
1125void
1126c_parser_skip_until_found (c_parser *parser,
1127 enum cpp_ttype type,
1128 const char *msgid,
1129 location_t matching_location)
1130{
1131 unsigned nesting_depth = 0;
1132
1133 if (c_parser_require (parser, type, msgid, matching_location))
1134 return;
1135
1136 /* Skip tokens until the desired token is found. */
1137 while (true)
1138 {
1139 /* Peek at the next token. */
1140 c_token *token = c_parser_peek_token (parser);
1141 /* If we've reached the token we want, consume it and stop. */
1142 if (token->type == type && !nesting_depth)
1143 {
1144 c_parser_consume_token (parser);
1145 break;
1146 }
1147
1148 /* If we've run out of tokens, stop. */
1149 if (token->type == CPP_EOF)
1150 return;
1151 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1152 return;
1153 if (token->type == CPP_OPEN_BRACE
1154 || token->type == CPP_OPEN_PAREN
1155 || token->type == CPP_OPEN_SQUARE)
1156 ++nesting_depth;
1157 else if (token->type == CPP_CLOSE_BRACE
1158 || token->type == CPP_CLOSE_PAREN
1159 || token->type == CPP_CLOSE_SQUARE)
1160 {
1161 if (nesting_depth-- == 0)
1162 break;
1163 }
1164 /* Consume this token. */
1165 c_parser_consume_token (parser);
1166 }
1167 parser->error = false;
1168}
1169
1170/* Skip tokens until the end of a parameter is found, but do not
1171 consume the comma, semicolon or closing delimiter. */
1172
1173static void
1174c_parser_skip_to_end_of_parameter (c_parser *parser)
1175{
1176 unsigned nesting_depth = 0;
1177
1178 while (true)
1179 {
1180 c_token *token = c_parser_peek_token (parser);
1181 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
1182 && !nesting_depth)
1183 break;
1184 /* If we've run out of tokens, stop. */
1185 if (token->type == CPP_EOF)
1186 return;
1187 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1188 return;
1189 if (token->type == CPP_OPEN_BRACE
1190 || token->type == CPP_OPEN_PAREN
1191 || token->type == CPP_OPEN_SQUARE)
1192 ++nesting_depth;
1193 else if (token->type == CPP_CLOSE_BRACE
1194 || token->type == CPP_CLOSE_PAREN
1195 || token->type == CPP_CLOSE_SQUARE)
1196 {
1197 if (nesting_depth-- == 0)
1198 break;
1199 }
1200 /* Consume this token. */
1201 c_parser_consume_token (parser);
1202 }
1203 parser->error = false;
1204}
1205
1206/* Expect to be at the end of the pragma directive and consume an
1207 end of line marker. */
1208
1209static void
1210c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
1211{
1212 gcc_assert (parser->in_pragma);
1213 parser->in_pragma = false;
1214
1215 if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
1216 c_parser_error (parser, "expected end of line");
1217
1218 cpp_ttype token_type;
1219 do
1220 {
1221 c_token *token = c_parser_peek_token (parser);
1222 token_type = token->type;
1223 if (token_type == CPP_EOF)
1224 break;
1225 c_parser_consume_token (parser);
1226 }
1227 while (token_type != CPP_PRAGMA_EOL);
1228
1229 parser->error = false;
1230}
1231
1232/* Skip tokens until we have consumed an entire block, or until we
1233 have consumed a non-nested ';'. */
1234
1235static void
1236c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1237{
1238 unsigned nesting_depth = 0;
1239 bool save_error = parser->error;
1240
1241 while (true)
1242 {
1243 c_token *token;
1244
1245 /* Peek at the next token. */
1246 token = c_parser_peek_token (parser);
1247
1248 switch (token->type)
1249 {
1250 case CPP_EOF:
1251 return;
1252
1253 case CPP_PRAGMA_EOL:
1254 if (parser->in_pragma)
1255 return;
1256 break;
1257
1258 case CPP_SEMICOLON:
1259 /* If the next token is a ';', we have reached the
1260 end of the statement. */
1261 if (!nesting_depth)
1262 {
1263 /* Consume the ';'. */
1264 c_parser_consume_token (parser);
1265 goto finished;
1266 }
1267 break;
1268
1269 case CPP_CLOSE_BRACE:
1270 /* If the next token is a non-nested '}', then we have
1271 reached the end of the current block. */
1272 if (nesting_depth == 0 || --nesting_depth == 0)
1273 {
1274 c_parser_consume_token (parser);
1275 goto finished;
1276 }
1277 break;
1278
1279 case CPP_OPEN_BRACE:
1280 /* If it the next token is a '{', then we are entering a new
1281 block. Consume the entire block. */
1282 ++nesting_depth;
1283 break;
1284
1285 case CPP_PRAGMA:
1286 /* If we see a pragma, consume the whole thing at once. We
1287 have some safeguards against consuming pragmas willy-nilly.
1288 Normally, we'd expect to be here with parser->error set,
1289 which disables these safeguards. But it's possible to get
1290 here for secondary error recovery, after parser->error has
1291 been cleared. */
1292 c_parser_consume_pragma (parser);
1293 c_parser_skip_to_pragma_eol (parser);
1294 parser->error = save_error;
1295 continue;
1296
1297 default:
1298 break;
1299 }
1300
1301 c_parser_consume_token (parser);
1302 }
1303
1304 finished:
1305 parser->error = false;
1306}
1307
1308/* CPP's options (initialized by c-opts.c). */
1309extern cpp_options *cpp_opts;
1310
1311/* Save the warning flags which are controlled by __extension__. */
1312
1313static inline int
1314disable_extension_diagnostics (void)
1315{
1316 int ret = (pedantic
1317 | (warn_pointer_arith << 1)
1318 | (warn_traditional << 2)
1319 | (flag_iso << 3)
1320 | (warn_long_long << 4)
1321 | (warn_cxx_compat << 5)
1322 | (warn_overlength_strings << 6)
1323 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1324 play tricks to properly restore it. */
1325 | ((warn_c90_c99_compat == 1) << 7)
1326 | ((warn_c90_c99_compat == -1) << 8)
1327 /* Similarly for warn_c99_c11_compat. */
1328 | ((warn_c99_c11_compat == 1) << 9)
1329 | ((warn_c99_c11_compat == -1) << 10)
1330 );
1331 cpp_opts->cpp_pedantic = pedantic = 0;
1332 warn_pointer_arith = 0;
1333 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1334 flag_iso = 0;
1335 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1336 warn_cxx_compat = 0;
1337 warn_overlength_strings = 0;
1338 warn_c90_c99_compat = 0;
1339 warn_c99_c11_compat = 0;
1340 return ret;
1341}
1342
1343/* Restore the warning flags which are controlled by __extension__.
1344 FLAGS is the return value from disable_extension_diagnostics. */
1345
1346static inline void
1347restore_extension_diagnostics (int flags)
1348{
1349 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1350 warn_pointer_arith = (flags >> 1) & 1;
1351 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1352 flag_iso = (flags >> 3) & 1;
1353 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1354 warn_cxx_compat = (flags >> 5) & 1;
1355 warn_overlength_strings = (flags >> 6) & 1;
1356 /* See above for why is this needed. */
1357 warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1358 warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1359}
1360
1361/* Helper data structure for parsing #pragma acc routine. */
1362struct oacc_routine_data {
1363 bool error_seen; /* Set if error has been reported. */
1364 bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */
1365 tree clauses;
1366 location_t loc;
1367};
1368
1369static void c_parser_external_declaration (c_parser *);
1370static void c_parser_asm_definition (c_parser *);
1371static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1372 bool, bool, tree *, vec<c_token>,
1373 struct oacc_routine_data * = NULL,
1374 bool * = NULL);
1375static void c_parser_static_assert_declaration_no_semi (c_parser *);
1376static void c_parser_static_assert_declaration (c_parser *);
1377static struct c_typespec c_parser_enum_specifier (c_parser *);
1378static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1379static tree c_parser_struct_declaration (c_parser *);
1380static struct c_typespec c_parser_typeof_specifier (c_parser *);
1381static tree c_parser_alignas_specifier (c_parser *);
1382static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1383 c_dtr_syn, bool *);
1384static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1385 bool,
1386 struct c_declarator *);
1387static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1388static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1389 tree);
1390static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1391static tree c_parser_simple_asm_expr (c_parser *);
1392static tree c_parser_attributes (c_parser *);
1393static struct c_expr c_parser_initializer (c_parser *);
1394static struct c_expr c_parser_braced_init (c_parser *, tree, bool,
1395 struct obstack *);
1396static void c_parser_initelt (c_parser *, struct obstack *);
1397static void c_parser_initval (c_parser *, struct c_expr *,
1398 struct obstack *);
1399static tree c_parser_compound_statement (c_parser *);
1400static void c_parser_compound_statement_nostart (c_parser *);
1401static void c_parser_label (c_parser *);
1402static void c_parser_statement (c_parser *, bool *, location_t * = NULL);
1403static void c_parser_statement_after_labels (c_parser *, bool *,
1404 vec<tree> * = NULL);
1405static tree c_parser_c99_block_statement (c_parser *, bool *,
1406 location_t * = NULL);
1407static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
1408static void c_parser_switch_statement (c_parser *, bool *);
1409static void c_parser_while_statement (c_parser *, bool, bool *);
1410static void c_parser_do_statement (c_parser *, bool);
1411static void c_parser_for_statement (c_parser *, bool, bool *);
1412static tree c_parser_asm_statement (c_parser *);
1413static tree c_parser_asm_operands (c_parser *);
1414static tree c_parser_asm_goto_operands (c_parser *);
1415static tree c_parser_asm_clobbers (c_parser *);
1416static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1417 tree = NULL_TREE);
1418static struct c_expr c_parser_conditional_expression (c_parser *,
1419 struct c_expr *, tree);
1420static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1421 tree);
1422static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1423static struct c_expr c_parser_unary_expression (c_parser *);
1424static struct c_expr c_parser_sizeof_expression (c_parser *);
1425static struct c_expr c_parser_alignof_expression (c_parser *);
1426static struct c_expr c_parser_postfix_expression (c_parser *);
1427static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1428 struct c_type_name *,
1429 location_t);
1430static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1431 location_t loc,
1432 struct c_expr);
1433static tree c_parser_transaction (c_parser *, enum rid);
1434static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1435static tree c_parser_transaction_cancel (c_parser *);
1436static struct c_expr c_parser_expression (c_parser *);
1437static struct c_expr c_parser_expression_conv (c_parser *);
1438static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1439 vec<tree, va_gc> **, location_t *,
1440 tree *, vec<location_t> *,
1441 unsigned int * = NULL);
1442static void c_parser_oacc_declare (c_parser *);
1443static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1444static void c_parser_oacc_update (c_parser *);
1445static void c_parser_omp_construct (c_parser *, bool *);
1446static void c_parser_omp_threadprivate (c_parser *);
1447static void c_parser_omp_barrier (c_parser *);
1448static void c_parser_omp_flush (c_parser *);
1449static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1450 tree, tree *, bool *);
1451static void c_parser_omp_taskwait (c_parser *);
1452static void c_parser_omp_taskyield (c_parser *);
1453static void c_parser_omp_cancel (c_parser *);
1454
1455enum pragma_context { pragma_external, pragma_struct, pragma_param,
1456 pragma_stmt, pragma_compound };
1457static bool c_parser_pragma (c_parser *, enum pragma_context, bool *);
1458static void c_parser_omp_cancellation_point (c_parser *, enum pragma_context);
1459static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
1460static void c_parser_omp_end_declare_target (c_parser *);
1461static void c_parser_omp_declare (c_parser *, enum pragma_context);
1462static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
1463static void c_parser_oacc_routine (c_parser *, enum pragma_context);
1464
1465/* These Objective-C parser functions are only ever called when
1466 compiling Objective-C. */
1467static void c_parser_objc_class_definition (c_parser *, tree);
1468static void c_parser_objc_class_instance_variables (c_parser *);
1469static void c_parser_objc_class_declaration (c_parser *);
1470static void c_parser_objc_alias_declaration (c_parser *);
1471static void c_parser_objc_protocol_definition (c_parser *, tree);
1472static bool c_parser_objc_method_type (c_parser *);
1473static void c_parser_objc_method_definition (c_parser *);
1474static void c_parser_objc_methodprotolist (c_parser *);
1475static void c_parser_objc_methodproto (c_parser *);
1476static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1477static tree c_parser_objc_type_name (c_parser *);
1478static tree c_parser_objc_protocol_refs (c_parser *);
1479static void c_parser_objc_try_catch_finally_statement (c_parser *);
1480static void c_parser_objc_synchronized_statement (c_parser *);
1481static tree c_parser_objc_selector (c_parser *);
1482static tree c_parser_objc_selector_arg (c_parser *);
1483static tree c_parser_objc_receiver (c_parser *);
1484static tree c_parser_objc_message_args (c_parser *);
1485static tree c_parser_objc_keywordexpr (c_parser *);
1486static void c_parser_objc_at_property_declaration (c_parser *);
1487static void c_parser_objc_at_synthesize_declaration (c_parser *);
1488static void c_parser_objc_at_dynamic_declaration (c_parser *);
1489static bool c_parser_objc_diagnose_bad_element_prefix
1490 (c_parser *, struct c_declspecs *);
1491
1492static void c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass);
1493
1494/* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1495
1496 translation-unit:
1497 external-declarations
1498
1499 external-declarations:
1500 external-declaration
1501 external-declarations external-declaration
1502
1503 GNU extensions:
1504
1505 translation-unit:
1506 empty
1507*/
1508
1509static void
1510c_parser_translation_unit (c_parser *parser)
1511{
1512 if (c_parser_next_token_is (parser, CPP_EOF))
1513 {
1514 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1515 "ISO C forbids an empty translation unit");
1516 }
1517 else
1518 {
1519 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1520 mark_valid_location_for_stdc_pragma (false);
1521 do
1522 {
1523 ggc_collect ();
1524 c_parser_external_declaration (parser);
1525 obstack_free (&parser_obstack, obstack_position);
1526 }
1527 while (c_parser_next_token_is_not (parser, CPP_EOF));
1528 }
1529
1530 unsigned int i;
1531 tree decl;
1532 FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl)
1533 if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node)
1534 error ("storage size of %q+D isn%'t known", decl);
1535}
1536
1537/* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1538
1539 external-declaration:
1540 function-definition
1541 declaration
1542
1543 GNU extensions:
1544
1545 external-declaration:
1546 asm-definition
1547 ;
1548 __extension__ external-declaration
1549
1550 Objective-C:
1551
1552 external-declaration:
1553 objc-class-definition
1554 objc-class-declaration
1555 objc-alias-declaration
1556 objc-protocol-definition
1557 objc-method-definition
1558 @end
1559*/
1560
1561static void
1562c_parser_external_declaration (c_parser *parser)
1563{
1564 int ext;
1565 switch (c_parser_peek_token (parser)->type)
1566 {
1567 case CPP_KEYWORD:
1568 switch (c_parser_peek_token (parser)->keyword)
1569 {
1570 case RID_EXTENSION:
1571 ext = disable_extension_diagnostics ();
1572 c_parser_consume_token (parser);
1573 c_parser_external_declaration (parser);
1574 restore_extension_diagnostics (ext);
1575 break;
1576 case RID_ASM:
1577 c_parser_asm_definition (parser);
1578 break;
1579 case RID_AT_INTERFACE:
1580 case RID_AT_IMPLEMENTATION:
1581 gcc_assert (c_dialect_objc ());
1582 c_parser_objc_class_definition (parser, NULL_TREE);
1583 break;
1584 case RID_AT_CLASS:
1585 gcc_assert (c_dialect_objc ());
1586 c_parser_objc_class_declaration (parser);
1587 break;
1588 case RID_AT_ALIAS:
1589 gcc_assert (c_dialect_objc ());
1590 c_parser_objc_alias_declaration (parser);
1591 break;
1592 case RID_AT_PROTOCOL:
1593 gcc_assert (c_dialect_objc ());
1594 c_parser_objc_protocol_definition (parser, NULL_TREE);
1595 break;
1596 case RID_AT_PROPERTY:
1597 gcc_assert (c_dialect_objc ());
1598 c_parser_objc_at_property_declaration (parser);
1599 break;
1600 case RID_AT_SYNTHESIZE:
1601 gcc_assert (c_dialect_objc ());
1602 c_parser_objc_at_synthesize_declaration (parser);
1603 break;
1604 case RID_AT_DYNAMIC:
1605 gcc_assert (c_dialect_objc ());
1606 c_parser_objc_at_dynamic_declaration (parser);
1607 break;
1608 case RID_AT_END:
1609 gcc_assert (c_dialect_objc ());
1610 c_parser_consume_token (parser);
1611 objc_finish_implementation ();
1612 break;
1613 default:
1614 goto decl_or_fndef;
1615 }
1616 break;
1617 case CPP_SEMICOLON:
1618 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1619 "ISO C does not allow extra %<;%> outside of a function");
1620 c_parser_consume_token (parser);
1621 break;
1622 case CPP_PRAGMA:
1623 mark_valid_location_for_stdc_pragma (true);
1624 c_parser_pragma (parser, pragma_external, NULL);
1625 mark_valid_location_for_stdc_pragma (false);
1626 break;
1627 case CPP_PLUS:
1628 case CPP_MINUS:
1629 if (c_dialect_objc ())
1630 {
1631 c_parser_objc_method_definition (parser);
1632 break;
1633 }
1634 /* Else fall through, and yield a syntax error trying to parse
1635 as a declaration or function definition. */
1636 /* FALLTHRU */
1637 default:
1638 decl_or_fndef:
1639 /* A declaration or a function definition (or, in Objective-C,
1640 an @interface or @protocol with prefix attributes). We can
1641 only tell which after parsing the declaration specifiers, if
1642 any, and the first declarator. */
1643 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1644 NULL, vNULL);
1645 break;
1646 }
1647}
1648
1649static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1650static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool);
1651
1652/* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */
1653
1654static void
1655add_debug_begin_stmt (location_t loc)
1656{
1657 if (!MAY_HAVE_DEBUG_MARKER_STMTS)
1658 return;
1659
1660 tree stmt = build0 (DEBUG_BEGIN_STMT, void_type_node);
1661 SET_EXPR_LOCATION (stmt, loc);
1662 add_stmt (stmt);
1663}
1664
1665/* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1666 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1667 is accepted; otherwise (old-style parameter declarations) only other
1668 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1669 assertion is accepted; otherwise (old-style parameter declarations)
1670 it is not. If NESTED is true, we are inside a function or parsing
1671 old-style parameter declarations; any functions encountered are
1672 nested functions and declaration specifiers are required; otherwise
1673 we are at top level and functions are normal functions and
1674 declaration specifiers may be optional. If EMPTY_OK is true, empty
1675 declarations are OK (subject to all other constraints); otherwise
1676 (old-style parameter declarations) they are diagnosed. If
1677 START_ATTR_OK is true, the declaration specifiers may start with
1678 attributes; otherwise they may not.
1679 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1680 declaration when parsing an Objective-C foreach statement.
1681 FALLTHRU_ATTR_P is used to signal whether this function parsed
1682 "__attribute__((fallthrough));".
1683
1684 declaration:
1685 declaration-specifiers init-declarator-list[opt] ;
1686 static_assert-declaration
1687
1688 function-definition:
1689 declaration-specifiers[opt] declarator declaration-list[opt]
1690 compound-statement
1691
1692 declaration-list:
1693 declaration
1694 declaration-list declaration
1695
1696 init-declarator-list:
1697 init-declarator
1698 init-declarator-list , init-declarator
1699
1700 init-declarator:
1701 declarator simple-asm-expr[opt] attributes[opt]
1702 declarator simple-asm-expr[opt] attributes[opt] = initializer
1703
1704 GNU extensions:
1705
1706 nested-function-definition:
1707 declaration-specifiers declarator declaration-list[opt]
1708 compound-statement
1709
1710 attribute ;
1711
1712 Objective-C:
1713 attributes objc-class-definition
1714 attributes objc-category-definition
1715 attributes objc-protocol-definition
1716
1717 The simple-asm-expr and attributes are GNU extensions.
1718
1719 This function does not handle __extension__; that is handled in its
1720 callers. ??? Following the old parser, __extension__ may start
1721 external declarations, declarations in functions and declarations
1722 at the start of "for" loops, but not old-style parameter
1723 declarations.
1724
1725 C99 requires declaration specifiers in a function definition; the
1726 absence is diagnosed through the diagnosis of implicit int. In GNU
1727 C we also allow but diagnose declarations without declaration
1728 specifiers, but only at top level (elsewhere they conflict with
1729 other syntax).
1730
1731 In Objective-C, declarations of the looping variable in a foreach
1732 statement are exceptionally terminated by 'in' (for example, 'for
1733 (NSObject *object in array) { ... }').
1734
1735 OpenMP:
1736
1737 declaration:
1738 threadprivate-directive
1739
1740 GIMPLE:
1741
1742 gimple-function-definition:
1743 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1744 declaration-list[opt] compound-statement
1745
1746 rtl-function-definition:
1747 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1748 declaration-list[opt] compound-statement */
1749
1750static void
1751c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1752 bool static_assert_ok, bool empty_ok,
1753 bool nested, bool start_attr_ok,
1754 tree *objc_foreach_object_declaration,
1755 vec<c_token> omp_declare_simd_clauses,
1756 struct oacc_routine_data *oacc_routine_data,
1757 bool *fallthru_attr_p)
1758{
1759 struct c_declspecs *specs;
1760 tree prefix_attrs;
1761 tree all_prefix_attrs;
1762 bool diagnosed_no_specs = false;
1763 location_t here = c_parser_peek_token (parser)->location;
1764
1765 add_debug_begin_stmt (c_parser_peek_token (parser)->location);
1766
1767 if (static_assert_ok
1768 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1769 {
1770 c_parser_static_assert_declaration (parser);
1771 return;
1772 }
1773 specs = build_null_declspecs ();
1774
1775 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1776 if (c_parser_peek_token (parser)->type == CPP_NAME
1777 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1778 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1779 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1780 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1781 {
1782 tree name = c_parser_peek_token (parser)->value;
1783
1784 /* Issue a warning about NAME being an unknown type name, perhaps
1785 with some kind of hint.
1786 If the user forgot a "struct" etc, suggest inserting
1787 it. Otherwise, attempt to look for misspellings. */
1788 gcc_rich_location richloc (here);
1789 if (tag_exists_p (RECORD_TYPE, name))
1790 {
1791 /* This is not C++ with its implicit typedef. */
1792 richloc.add_fixit_insert_before ("struct ");
1793 error_at (&richloc,
1794 "unknown type name %qE;"
1795 " use %<struct%> keyword to refer to the type",
1796 name);
1797 }
1798 else if (tag_exists_p (UNION_TYPE, name))
1799 {
1800 richloc.add_fixit_insert_before ("union ");
1801 error_at (&richloc,
1802 "unknown type name %qE;"
1803 " use %<union%> keyword to refer to the type",
1804 name);
1805 }
1806 else if (tag_exists_p (ENUMERAL_TYPE, name))
1807 {
1808 richloc.add_fixit_insert_before ("enum ");
1809 error_at (&richloc,
1810 "unknown type name %qE;"
1811 " use %<enum%> keyword to refer to the type",
1812 name);
1813 }
1814 else
1815 {
1816 name_hint hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME,
1817 here);
1818 if (hint)
1819 {
1820 richloc.add_fixit_replace (hint.suggestion ());
1821 error_at (&richloc,
1822 "unknown type name %qE; did you mean %qs?",
1823 name, hint.suggestion ());
1824 }
1825 else
1826 error_at (here, "unknown type name %qE", name);
1827 }
1828
1829 /* Parse declspecs normally to get a correct pointer type, but avoid
1830 a further "fails to be a type name" error. Refuse nested functions
1831 since it is not how the user likely wants us to recover. */
1832 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1833 c_parser_peek_token (parser)->keyword = RID_VOID;
1834 c_parser_peek_token (parser)->value = error_mark_node;
1835 fndef_ok = !nested;
1836 }
1837
1838 c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1839 true, true, cla_nonabstract_decl);
1840 if (parser->error)
1841 {
1842 c_parser_skip_to_end_of_block_or_statement (parser);
1843 return;
1844 }
1845 if (nested && !specs->declspecs_seen_p)
1846 {
1847 c_parser_error (parser, "expected declaration specifiers");
1848 c_parser_skip_to_end_of_block_or_statement (parser);
1849 return;
1850 }
1851
1852 finish_declspecs (specs);
1853 bool auto_type_p = specs->typespec_word == cts_auto_type;
1854 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1855 {
1856 if (auto_type_p)
1857 error_at (here, "%<__auto_type%> in empty declaration");
1858 else if (specs->typespec_kind == ctsk_none
1859 && attribute_fallthrough_p (specs->attrs))
1860 {
1861 if (fallthru_attr_p != NULL)
1862 *fallthru_attr_p = true;
1863 tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH,
1864 void_type_node, 0);
1865 add_stmt (fn);
1866 }
1867 else if (empty_ok)
1868 shadow_tag (specs);
1869 else
1870 {
1871 shadow_tag_warned (specs, 1);
1872 pedwarn (here, 0, "empty declaration");
1873 }
1874 c_parser_consume_token (parser);
1875 if (oacc_routine_data)
1876 c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1877 return;
1878 }
1879
1880 /* Provide better error recovery. Note that a type name here is usually
1881 better diagnosed as a redeclaration. */
1882 if (empty_ok
1883 && specs->typespec_kind == ctsk_tagdef
1884 && c_parser_next_token_starts_declspecs (parser)
1885 && !c_parser_next_token_is (parser, CPP_NAME))
1886 {
1887 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1888 parser->error = false;
1889 shadow_tag_warned (specs, 1);
1890 return;
1891 }
1892 else if (c_dialect_objc () && !auto_type_p)
1893 {
1894 /* Prefix attributes are an error on method decls. */
1895 switch (c_parser_peek_token (parser)->type)
1896 {
1897 case CPP_PLUS:
1898 case CPP_MINUS:
1899 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1900 return;
1901 if (specs->attrs)
1902 {
1903 warning_at (c_parser_peek_token (parser)->location,
1904 OPT_Wattributes,
1905 "prefix attributes are ignored for methods");
1906 specs->attrs = NULL_TREE;
1907 }
1908 if (fndef_ok)
1909 c_parser_objc_method_definition (parser);
1910 else
1911 c_parser_objc_methodproto (parser);
1912 return;
1913 break;
1914 default:
1915 break;
1916 }
1917 /* This is where we parse 'attributes @interface ...',
1918 'attributes @implementation ...', 'attributes @protocol ...'
1919 (where attributes could be, for example, __attribute__
1920 ((deprecated)).
1921 */
1922 switch (c_parser_peek_token (parser)->keyword)
1923 {
1924 case RID_AT_INTERFACE:
1925 {
1926 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1927 return;
1928 c_parser_objc_class_definition (parser, specs->attrs);
1929 return;
1930 }
1931 break;
1932 case RID_AT_IMPLEMENTATION:
1933 {
1934 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1935 return;
1936 if (specs->attrs)
1937 {
1938 warning_at (c_parser_peek_token (parser)->location,
1939 OPT_Wattributes,
1940 "prefix attributes are ignored for implementations");
1941 specs->attrs = NULL_TREE;
1942 }
1943 c_parser_objc_class_definition (parser, NULL_TREE);
1944 return;
1945 }
1946 break;
1947 case RID_AT_PROTOCOL:
1948 {
1949 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1950 return;
1951 c_parser_objc_protocol_definition (parser, specs->attrs);
1952 return;
1953 }
1954 break;
1955 case RID_AT_ALIAS:
1956 case RID_AT_CLASS:
1957 case RID_AT_END:
1958 case RID_AT_PROPERTY:
1959 if (specs->attrs)
1960 {
1961 c_parser_error (parser, "unexpected attribute");
1962 specs->attrs = NULL;
1963 }
1964 break;
1965 default:
1966 break;
1967 }
1968 }
1969 else if (attribute_fallthrough_p (specs->attrs))
1970 warning_at (here, OPT_Wattributes,
1971 "%<fallthrough%> attribute not followed by %<;%>");
1972
1973 pending_xref_error ();
1974 prefix_attrs = specs->attrs;
1975 all_prefix_attrs = prefix_attrs;
1976 specs->attrs = NULL_TREE;
1977 while (true)
1978 {
1979 struct c_declarator *declarator;
1980 bool dummy = false;
1981 timevar_id_t tv;
1982 tree fnbody = NULL_TREE;
1983 /* Declaring either one or more declarators (in which case we
1984 should diagnose if there were no declaration specifiers) or a
1985 function definition (in which case the diagnostic for
1986 implicit int suffices). */
1987 declarator = c_parser_declarator (parser,
1988 specs->typespec_kind != ctsk_none,
1989 C_DTR_NORMAL, &dummy);
1990 if (declarator == NULL)
1991 {
1992 if (omp_declare_simd_clauses.exists ())
1993 c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1994 omp_declare_simd_clauses);
1995 if (oacc_routine_data)
1996 c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1997 c_parser_skip_to_end_of_block_or_statement (parser);
1998 return;
1999 }
2000 if (auto_type_p && declarator->kind != cdk_id)
2001 {
2002 error_at (here,
2003 "%<__auto_type%> requires a plain identifier"
2004 " as declarator");
2005 c_parser_skip_to_end_of_block_or_statement (parser);
2006 return;
2007 }
2008 if (c_parser_next_token_is (parser, CPP_EQ)
2009 || c_parser_next_token_is (parser, CPP_COMMA)
2010 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2011 || c_parser_next_token_is_keyword (parser, RID_ASM)
2012 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
2013 || c_parser_next_token_is_keyword (parser, RID_IN))
2014 {
2015 tree asm_name = NULL_TREE;
2016 tree postfix_attrs = NULL_TREE;
2017 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
2018 {
2019 diagnosed_no_specs = true;
2020 pedwarn (here, 0, "data definition has no type or storage class");
2021 }
2022 /* Having seen a data definition, there cannot now be a
2023 function definition. */
2024 fndef_ok = false;
2025 if (c_parser_next_token_is_keyword (parser, RID_ASM))
2026 asm_name = c_parser_simple_asm_expr (parser);
2027 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2028 {
2029 postfix_attrs = c_parser_attributes (parser);
2030 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2031 {
2032 /* This means there is an attribute specifier after
2033 the declarator in a function definition. Provide
2034 some more information for the user. */
2035 error_at (here, "attributes should be specified before the "
2036 "declarator in a function definition");
2037 c_parser_skip_to_end_of_block_or_statement (parser);
2038 return;
2039 }
2040 }
2041 if (c_parser_next_token_is (parser, CPP_EQ))
2042 {
2043 tree d;
2044 struct c_expr init;
2045 location_t init_loc;
2046 c_parser_consume_token (parser);
2047 if (auto_type_p)
2048 {
2049 init_loc = c_parser_peek_token (parser)->location;
2050 rich_location richloc (line_table, init_loc);
2051 start_init (NULL_TREE, asm_name, global_bindings_p (), &richloc);
2052 /* A parameter is initialized, which is invalid. Don't
2053 attempt to instrument the initializer. */
2054 int flag_sanitize_save = flag_sanitize;
2055 if (nested && !empty_ok)
2056 flag_sanitize = 0;
2057 init = c_parser_expr_no_commas (parser, NULL);
2058 flag_sanitize = flag_sanitize_save;
2059 if (TREE_CODE (init.value) == COMPONENT_REF
2060 && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
2061 error_at (here,
2062 "%<__auto_type%> used with a bit-field"
2063 " initializer");
2064 init = convert_lvalue_to_rvalue (init_loc, init, true, true);
2065 tree init_type = TREE_TYPE (init.value);
2066 /* As with typeof, remove all qualifiers from atomic types. */
2067 if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
2068 init_type
2069 = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
2070 bool vm_type = variably_modified_type_p (init_type,
2071 NULL_TREE);
2072 if (vm_type)
2073 init.value = save_expr (init.value);
2074 finish_init ();
2075 specs->typespec_kind = ctsk_typeof;
2076 specs->locations[cdw_typedef] = init_loc;
2077 specs->typedef_p = true;
2078 specs->type = init_type;
2079 if (vm_type)
2080 {
2081 bool maybe_const = true;
2082 tree type_expr = c_fully_fold (init.value, false,
2083 &maybe_const);
2084 specs->expr_const_operands &= maybe_const;
2085 if (specs->expr)
2086 specs->expr = build2 (COMPOUND_EXPR,
2087 TREE_TYPE (type_expr),
2088 specs->expr, type_expr);
2089 else
2090 specs->expr = type_expr;
2091 }
2092 d = start_decl (declarator, specs, true,
2093 chainon (postfix_attrs, all_prefix_attrs));
2094 if (!d)
2095 d = error_mark_node;
2096 if (omp_declare_simd_clauses.exists ())
2097 c_finish_omp_declare_simd (parser, d, NULL_TREE,
2098 omp_declare_simd_clauses);
2099 }
2100 else
2101 {
2102 /* The declaration of the variable is in effect while
2103 its initializer is parsed. */
2104 d = start_decl (declarator, specs, true,
2105 chainon (postfix_attrs, all_prefix_attrs));
2106 if (!d)
2107 d = error_mark_node;
2108 if (omp_declare_simd_clauses.exists ())
2109 c_finish_omp_declare_simd (parser, d, NULL_TREE,
2110 omp_declare_simd_clauses);
2111 init_loc = c_parser_peek_token (parser)->location;
2112 rich_location richloc (line_table, init_loc);
2113 start_init (d, asm_name, global_bindings_p (), &richloc);
2114 /* A parameter is initialized, which is invalid. Don't
2115 attempt to instrument the initializer. */
2116 int flag_sanitize_save = flag_sanitize;
2117 if (TREE_CODE (d) == PARM_DECL)
2118 flag_sanitize = 0;
2119 init = c_parser_initializer (parser);
2120 flag_sanitize = flag_sanitize_save;
2121 finish_init ();
2122 }
2123 if (oacc_routine_data)
2124 c_finish_oacc_routine (oacc_routine_data, d, false);
2125 if (d != error_mark_node)
2126 {
2127 maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
2128 finish_decl (d, init_loc, init.value,
2129 init.original_type, asm_name);
2130 }
2131 }
2132 else
2133 {
2134 if (auto_type_p)
2135 {
2136 error_at (here,
2137 "%<__auto_type%> requires an initialized "
2138 "data declaration");
2139 c_parser_skip_to_end_of_block_or_statement (parser);
2140 return;
2141 }
2142 tree d = start_decl (declarator, specs, false,
2143 chainon (postfix_attrs,
2144 all_prefix_attrs));
2145 if (d && TREE_CODE (d) == FUNCTION_DECL)
2146 if (declarator->kind == cdk_function)
2147 if (DECL_ARGUMENTS (d) == NULL_TREE)
2148 DECL_ARGUMENTS (d) = declarator->u.arg_info->parms;
2149 if (omp_declare_simd_clauses.exists ())
2150 {
2151 tree parms = NULL_TREE;
2152 if (d && TREE_CODE (d) == FUNCTION_DECL)
2153 {
2154 struct c_declarator *ce = declarator;
2155 while (ce != NULL)
2156 if (ce->kind == cdk_function)
2157 {
2158 parms = ce->u.arg_info->parms;
2159 break;
2160 }
2161 else
2162 ce = ce->declarator;
2163 }
2164 if (parms)
2165 temp_store_parm_decls (d, parms);
2166 c_finish_omp_declare_simd (parser, d, parms,
2167 omp_declare_simd_clauses);
2168 if (parms)
2169 temp_pop_parm_decls ();
2170 }
2171 if (oacc_routine_data)
2172 c_finish_oacc_routine (oacc_routine_data, d, false);
2173 if (d)
2174 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
2175 NULL_TREE, asm_name);
2176
2177 if (c_parser_next_token_is_keyword (parser, RID_IN))
2178 {
2179 if (d)
2180 *objc_foreach_object_declaration = d;
2181 else
2182 *objc_foreach_object_declaration = error_mark_node;
2183 }
2184 }
2185 if (c_parser_next_token_is (parser, CPP_COMMA))
2186 {
2187 if (auto_type_p)
2188 {
2189 error_at (here,
2190 "%<__auto_type%> may only be used with"
2191 " a single declarator");
2192 c_parser_skip_to_end_of_block_or_statement (parser);
2193 return;
2194 }
2195 c_parser_consume_token (parser);
2196 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2197 all_prefix_attrs = chainon (c_parser_attributes (parser),
2198 prefix_attrs);
2199 else
2200 all_prefix_attrs = prefix_attrs;
2201 continue;
2202 }
2203 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2204 {
2205 c_parser_consume_token (parser);
2206 return;
2207 }
2208 else if (c_parser_next_token_is_keyword (parser, RID_IN))
2209 {
2210 /* This can only happen in Objective-C: we found the
2211 'in' that terminates the declaration inside an
2212 Objective-C foreach statement. Do not consume the
2213 token, so that the caller can use it to determine
2214 that this indeed is a foreach context. */
2215 return;
2216 }
2217 else
2218 {
2219 c_parser_error (parser, "expected %<,%> or %<;%>");
2220 c_parser_skip_to_end_of_block_or_statement (parser);
2221 return;
2222 }
2223 }
2224 else if (auto_type_p)
2225 {
2226 error_at (here,
2227 "%<__auto_type%> requires an initialized data declaration");
2228 c_parser_skip_to_end_of_block_or_statement (parser);
2229 return;
2230 }
2231 else if (!fndef_ok)
2232 {
2233 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
2234 "%<asm%> or %<__attribute__%>");
2235 c_parser_skip_to_end_of_block_or_statement (parser);
2236 return;
2237 }
2238 /* Function definition (nested or otherwise). */
2239 if (nested)
2240 {
2241 pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
2242 c_push_function_context ();
2243 }
2244 if (!start_function (specs, declarator, all_prefix_attrs))
2245 {
2246 /* At this point we've consumed:
2247 declaration-specifiers declarator
2248 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2249 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2250 but the
2251 declaration-specifiers declarator
2252 aren't grokkable as a function definition, so we have
2253 an error. */
2254 gcc_assert (!c_parser_next_token_is (parser, CPP_SEMICOLON));
2255 if (c_parser_next_token_starts_declspecs (parser))
2256 {
2257 /* If we have
2258 declaration-specifiers declarator decl-specs
2259 then assume we have a missing semicolon, which would
2260 give us:
2261 declaration-specifiers declarator decl-specs
2262 ^
2263 ;
2264 <~~~~~~~~~ declaration ~~~~~~~~~~>
2265 Use c_parser_require to get an error with a fix-it hint. */
2266 c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>");
2267 parser->error = false;
2268 }
2269 else
2270 {
2271 /* This can appear in many cases looking nothing like a
2272 function definition, so we don't give a more specific
2273 error suggesting there was one. */
2274 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2275 "or %<__attribute__%>");
2276 }
2277 if (nested)
2278 c_pop_function_context ();
2279 break;
2280 }
2281
2282 if (DECL_DECLARED_INLINE_P (current_function_decl))
2283 tv = TV_PARSE_INLINE;
2284 else
2285 tv = TV_PARSE_FUNC;
2286 auto_timevar at (g_timer, tv);
2287
2288 /* Parse old-style parameter declarations. ??? Attributes are
2289 not allowed to start declaration specifiers here because of a
2290 syntax conflict between a function declaration with attribute
2291 suffix and a function definition with an attribute prefix on
2292 first old-style parameter declaration. Following the old
2293 parser, they are not accepted on subsequent old-style
2294 parameter declarations either. However, there is no
2295 ambiguity after the first declaration, nor indeed on the
2296 first as long as we don't allow postfix attributes after a
2297 declarator with a nonempty identifier list in a definition;
2298 and postfix attributes have never been accepted here in
2299 function definitions either. */
2300 while (c_parser_next_token_is_not (parser, CPP_EOF)
2301 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
2302 c_parser_declaration_or_fndef (parser, false, false, false,
2303 true, false, NULL, vNULL);
2304 store_parm_decls ();
2305 if (omp_declare_simd_clauses.exists ())
2306 c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
2307 omp_declare_simd_clauses);
2308 if (oacc_routine_data)
2309 c_finish_oacc_routine (oacc_routine_data, current_function_decl, true);
2310 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
2311 = c_parser_peek_token (parser)->location;
2312
2313 /* If the definition was marked with __GIMPLE then parse the
2314 function body as GIMPLE. */
2315 if (specs->gimple_p)
2316 {
2317 cfun->pass_startwith = specs->gimple_or_rtl_pass;
2318 bool saved = in_late_binary_op;
2319 in_late_binary_op = true;
2320 c_parser_parse_gimple_body (parser);
2321 in_late_binary_op = saved;
2322 }
2323 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2324 consuming the function body. */
2325 else if (specs->rtl_p)
2326 {
2327 c_parser_parse_rtl_body (parser, specs->gimple_or_rtl_pass);
2328
2329 /* Normally, store_parm_decls sets next_is_function_body,
2330 anticipating a function body. We need a push_scope/pop_scope
2331 pair to flush out this state, or subsequent function parsing
2332 will go wrong. */
2333 push_scope ();
2334 pop_scope ();
2335
2336 finish_function ();
2337 return;
2338 }
2339 else
2340 fnbody = c_parser_compound_statement (parser);
2341 tree fndecl = current_function_decl;
2342 if (nested)
2343 {
2344 tree decl = current_function_decl;
2345 /* Mark nested functions as needing static-chain initially.
2346 lower_nested_functions will recompute it but the
2347 DECL_STATIC_CHAIN flag is also used before that happens,
2348 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2349 DECL_STATIC_CHAIN (decl) = 1;
2350 add_stmt (fnbody);
2351 finish_function ();
2352 c_pop_function_context ();
2353 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
2354 }
2355 else
2356 {
2357 if (fnbody)
2358 add_stmt (fnbody);
2359 finish_function ();
2360 }
2361 /* Get rid of the empty stmt list for GIMPLE. */
2362 if (specs->gimple_p)
2363 DECL_SAVED_TREE (fndecl) = NULL_TREE;
2364
2365 break;
2366 }
2367}
2368
2369/* Parse an asm-definition (asm() outside a function body). This is a
2370 GNU extension.
2371
2372 asm-definition:
2373 simple-asm-expr ;
2374*/
2375
2376static void
2377c_parser_asm_definition (c_parser *parser)
2378{
2379 tree asm_str = c_parser_simple_asm_expr (parser);
2380 if (asm_str)
2381 symtab->finalize_toplevel_asm (asm_str);
2382 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2383}
2384
2385/* Parse a static assertion (C11 6.7.10).
2386
2387 static_assert-declaration:
2388 static_assert-declaration-no-semi ;
2389*/
2390
2391static void
2392c_parser_static_assert_declaration (c_parser *parser)
2393{
2394 c_parser_static_assert_declaration_no_semi (parser);
2395 if (parser->error
2396 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2397 c_parser_skip_to_end_of_block_or_statement (parser);
2398}
2399
2400/* Parse a static assertion (C11 6.7.10), without the trailing
2401 semicolon.
2402
2403 static_assert-declaration-no-semi:
2404 _Static_assert ( constant-expression , string-literal )
2405*/
2406
2407static void
2408c_parser_static_assert_declaration_no_semi (c_parser *parser)
2409{
2410 location_t assert_loc, value_loc;
2411 tree value;
2412 tree string;
2413
2414 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2415 assert_loc = c_parser_peek_token (parser)->location;
2416 if (flag_isoc99)
2417 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2418 "ISO C99 does not support %<_Static_assert%>");
2419 else
2420 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2421 "ISO C90 does not support %<_Static_assert%>");
2422 c_parser_consume_token (parser);
2423 matching_parens parens;
2424 if (!parens.require_open (parser))
2425 return;
2426 location_t value_tok_loc = c_parser_peek_token (parser)->location;
2427 value = c_parser_expr_no_commas (parser, NULL).value;
2428 value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc);
2429 parser->lex_untranslated_string = true;
2430 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2431 {
2432 parser->lex_untranslated_string = false;
2433 return;
2434 }
2435 switch (c_parser_peek_token (parser)->type)
2436 {
2437 case CPP_STRING:
2438 case CPP_STRING16:
2439 case CPP_STRING32:
2440 case CPP_WSTRING:
2441 case CPP_UTF8STRING:
2442 string = c_parser_peek_token (parser)->value;
2443 c_parser_consume_token (parser);
2444 parser->lex_untranslated_string = false;
2445 break;
2446 default:
2447 c_parser_error (parser, "expected string literal");
2448 parser->lex_untranslated_string = false;
2449 return;
2450 }
2451 parens.require_close (parser);
2452
2453 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2454 {
2455 error_at (value_loc, "expression in static assertion is not an integer");
2456 return;
2457 }
2458 if (TREE_CODE (value) != INTEGER_CST)
2459 {
2460 value = c_fully_fold (value, false, NULL);
2461 /* Strip no-op conversions. */
2462 STRIP_TYPE_NOPS (value);
2463 if (TREE_CODE (value) == INTEGER_CST)
2464 pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2465 "is not an integer constant expression");
2466 }
2467 if (TREE_CODE (value) != INTEGER_CST)
2468 {
2469 error_at (value_loc, "expression in static assertion is not constant");
2470 return;
2471 }
2472 constant_expression_warning (value);
2473 if (integer_zerop (value))
2474 error_at (assert_loc, "static assertion failed: %E", string);
2475}
2476
2477/* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2478 6.7, C11 6.7), adding them to SPECS (which may already include some).
2479 Storage class specifiers are accepted iff SCSPEC_OK; type
2480 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2481 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2482 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2483
2484 declaration-specifiers:
2485 storage-class-specifier declaration-specifiers[opt]
2486 type-specifier declaration-specifiers[opt]
2487 type-qualifier declaration-specifiers[opt]
2488 function-specifier declaration-specifiers[opt]
2489 alignment-specifier declaration-specifiers[opt]
2490
2491 Function specifiers (inline) are from C99, and are currently
2492 handled as storage class specifiers, as is __thread. Alignment
2493 specifiers are from C11.
2494
2495 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2496 storage-class-specifier:
2497 typedef
2498 extern
2499 static
2500 auto
2501 register
2502 _Thread_local
2503
2504 (_Thread_local is new in C11.)
2505
2506 C99 6.7.4, C11 6.7.4:
2507 function-specifier:
2508 inline
2509 _Noreturn
2510
2511 (_Noreturn is new in C11.)
2512
2513 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2514 type-specifier:
2515 void
2516 char
2517 short
2518 int
2519 long
2520 float
2521 double
2522 signed
2523 unsigned
2524 _Bool
2525 _Complex
2526 [_Imaginary removed in C99 TC2]
2527 struct-or-union-specifier
2528 enum-specifier
2529 typedef-name
2530 atomic-type-specifier
2531
2532 (_Bool and _Complex are new in C99.)
2533 (atomic-type-specifier is new in C11.)
2534
2535 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2536
2537 type-qualifier:
2538 const
2539 restrict
2540 volatile
2541 address-space-qualifier
2542 _Atomic
2543
2544 (restrict is new in C99.)
2545 (_Atomic is new in C11.)
2546
2547 GNU extensions:
2548
2549 declaration-specifiers:
2550 attributes declaration-specifiers[opt]
2551
2552 type-qualifier:
2553 address-space
2554
2555 address-space:
2556 identifier recognized by the target
2557
2558 storage-class-specifier:
2559 __thread
2560
2561 type-specifier:
2562 typeof-specifier
2563 __auto_type
2564 __intN
2565 _Decimal32
2566 _Decimal64
2567 _Decimal128
2568 _Fract
2569 _Accum
2570 _Sat
2571
2572 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2573 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2574
2575 atomic-type-specifier
2576 _Atomic ( type-name )
2577
2578 Objective-C:
2579
2580 type-specifier:
2581 class-name objc-protocol-refs[opt]
2582 typedef-name objc-protocol-refs
2583 objc-protocol-refs
2584*/
2585
2586void
2587c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2588 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2589 bool alignspec_ok, bool auto_type_ok,
2590 enum c_lookahead_kind la)
2591{
2592 bool attrs_ok = start_attr_ok;
2593 bool seen_type = specs->typespec_kind != ctsk_none;
2594
2595 if (!typespec_ok)
2596 gcc_assert (la == cla_prefer_id);
2597
2598 while (c_parser_next_token_is (parser, CPP_NAME)
2599 || c_parser_next_token_is (parser, CPP_KEYWORD)
2600 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2601 {
2602 struct c_typespec t;
2603 tree attrs;
2604 tree align;
2605 location_t loc = c_parser_peek_token (parser)->location;
2606
2607 /* If we cannot accept a type, exit if the next token must start
2608 one. Also, if we already have seen a tagged definition,
2609 a typename would be an error anyway and likely the user
2610 has simply forgotten a semicolon, so we exit. */
2611 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2612 && c_parser_next_tokens_start_typename (parser, la)
2613 && !c_parser_next_token_is_qualifier (parser)
2614 && !c_parser_next_token_is_keyword (parser, RID_ALIGNAS))
2615 break;
2616
2617 if (c_parser_next_token_is (parser, CPP_NAME))
2618 {
2619 c_token *name_token = c_parser_peek_token (parser);
2620 tree value = name_token->value;
2621 c_id_kind kind = name_token->id_kind;
2622
2623 if (kind == C_ID_ADDRSPACE)
2624 {
2625 addr_space_t as
2626 = name_token->keyword - RID_FIRST_ADDR_SPACE;
2627 declspecs_add_addrspace (name_token->location, specs, as);
2628 c_parser_consume_token (parser);
2629 attrs_ok = true;
2630 continue;
2631 }
2632
2633 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2634
2635 /* If we cannot accept a type, and the next token must start one,
2636 exit. Do the same if we already have seen a tagged definition,
2637 since it would be an error anyway and likely the user has simply
2638 forgotten a semicolon. */
2639 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2640 break;
2641
2642 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2643 a C_ID_CLASSNAME. */
2644 c_parser_consume_token (parser);
2645 seen_type = true;
2646 attrs_ok = true;
2647 if (kind == C_ID_ID)
2648 {
2649 error_at (loc, "unknown type name %qE", value);
2650 t.kind = ctsk_typedef;
2651 t.spec = error_mark_node;
2652 }
2653 else if (kind == C_ID_TYPENAME
2654 && (!c_dialect_objc ()
2655 || c_parser_next_token_is_not (parser, CPP_LESS)))
2656 {
2657 t.kind = ctsk_typedef;
2658 /* For a typedef name, record the meaning, not the name.
2659 In case of 'foo foo, bar;'. */
2660 t.spec = lookup_name (value);
2661 }
2662 else
2663 {
2664 tree proto = NULL_TREE;
2665 gcc_assert (c_dialect_objc ());
2666 t.kind = ctsk_objc;
2667 if (c_parser_next_token_is (parser, CPP_LESS))
2668 proto = c_parser_objc_protocol_refs (parser);
2669 t.spec = objc_get_protocol_qualified_type (value, proto);
2670 }
2671 t.expr = NULL_TREE;
2672 t.expr_const_operands = true;
2673 declspecs_add_type (name_token->location, specs, t);
2674 continue;
2675 }
2676 if (c_parser_next_token_is (parser, CPP_LESS))
2677 {
2678 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2679 nisse@lysator.liu.se. */
2680 tree proto;
2681 gcc_assert (c_dialect_objc ());
2682 if (!typespec_ok || seen_type)
2683 break;
2684 proto = c_parser_objc_protocol_refs (parser);
2685 t.kind = ctsk_objc;
2686 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2687 t.expr = NULL_TREE;
2688 t.expr_const_operands = true;
2689 declspecs_add_type (loc, specs, t);
2690 continue;
2691 }
2692 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2693 switch (c_parser_peek_token (parser)->keyword)
2694 {
2695 case RID_STATIC:
2696 case RID_EXTERN:
2697 case RID_REGISTER:
2698 case RID_TYPEDEF:
2699 case RID_INLINE:
2700 case RID_NORETURN:
2701 case RID_AUTO:
2702 case RID_THREAD:
2703 if (!scspec_ok)
2704 goto out;
2705 attrs_ok = true;
2706 /* TODO: Distinguish between function specifiers (inline, noreturn)
2707 and storage class specifiers, either here or in
2708 declspecs_add_scspec. */
2709 declspecs_add_scspec (loc, specs,
2710 c_parser_peek_token (parser)->value);
2711 c_parser_consume_token (parser);
2712 break;
2713 case RID_AUTO_TYPE:
2714 if (!auto_type_ok)
2715 goto out;
2716 /* Fall through. */
2717 case RID_UNSIGNED:
2718 case RID_LONG:
2719 case RID_SHORT:
2720 case RID_SIGNED:
2721 case RID_COMPLEX:
2722 case RID_INT:
2723 case RID_CHAR:
2724 case RID_FLOAT:
2725 case RID_DOUBLE:
2726 case RID_VOID:
2727 case RID_DFLOAT32:
2728 case RID_DFLOAT64:
2729 case RID_DFLOAT128:
2730 CASE_RID_FLOATN_NX:
2731 case RID_BOOL:
2732 case RID_FRACT:
2733 case RID_ACCUM:
2734 case RID_SAT:
2735 case RID_INT_N_0:
2736 case RID_INT_N_1:
2737 case RID_INT_N_2:
2738 case RID_INT_N_3:
2739 if (!typespec_ok)
2740 goto out;
2741 attrs_ok = true;
2742 seen_type = true;
2743 if (c_dialect_objc ())
2744 parser->objc_need_raw_identifier = true;
2745 t.kind = ctsk_resword;
2746 t.spec = c_parser_peek_token (parser)->value;
2747 t.expr = NULL_TREE;
2748 t.expr_const_operands = true;
2749 declspecs_add_type (loc, specs, t);
2750 c_parser_consume_token (parser);
2751 break;
2752 case RID_ENUM:
2753 if (!typespec_ok)
2754 goto out;
2755 attrs_ok = true;
2756 seen_type = true;
2757 t = c_parser_enum_specifier (parser);
2758 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2759 declspecs_add_type (loc, specs, t);
2760 break;
2761 case RID_STRUCT:
2762 case RID_UNION:
2763 if (!typespec_ok)
2764 goto out;
2765 attrs_ok = true;
2766 seen_type = true;
2767 t = c_parser_struct_or_union_specifier (parser);
2768 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2769 declspecs_add_type (loc, specs, t);
2770 break;
2771 case RID_TYPEOF:
2772 /* ??? The old parser rejected typeof after other type
2773 specifiers, but is a syntax error the best way of
2774 handling this? */
2775 if (!typespec_ok || seen_type)
2776 goto out;
2777 attrs_ok = true;
2778 seen_type = true;
2779 t = c_parser_typeof_specifier (parser);
2780 declspecs_add_type (loc, specs, t);
2781 break;
2782 case RID_ATOMIC:
2783 /* C parser handling of Objective-C constructs needs
2784 checking for correct lvalue-to-rvalue conversions, and
2785 the code in build_modify_expr handling various
2786 Objective-C cases, and that in build_unary_op handling
2787 Objective-C cases for increment / decrement, also needs
2788 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2789 and objc_types_are_equivalent may also need updates. */
2790 if (c_dialect_objc ())
2791 sorry ("%<_Atomic%> in Objective-C");
2792 if (flag_isoc99)
2793 pedwarn_c99 (loc, OPT_Wpedantic,
2794 "ISO C99 does not support the %<_Atomic%> qualifier");
2795 else
2796 pedwarn_c99 (loc, OPT_Wpedantic,
2797 "ISO C90 does not support the %<_Atomic%> qualifier");
2798 attrs_ok = true;
2799 tree value;
2800 value = c_parser_peek_token (parser)->value;
2801 c_parser_consume_token (parser);
2802 if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2803 {
2804 /* _Atomic ( type-name ). */
2805 seen_type = true;
2806 c_parser_consume_token (parser);
2807 struct c_type_name *type = c_parser_type_name (parser);
2808 t.kind = ctsk_typeof;
2809 t.spec = error_mark_node;
2810 t.expr = NULL_TREE;
2811 t.expr_const_operands = true;
2812 if (type != NULL)
2813 t.spec = groktypename (type, &t.expr,
2814 &t.expr_const_operands);
2815 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2816 "expected %<)%>");
2817 if (t.spec != error_mark_node)
2818 {
2819 if (TREE_CODE (t.spec) == ARRAY_TYPE)
2820 error_at (loc, "%<_Atomic%>-qualified array type");
2821 else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2822 error_at (loc, "%<_Atomic%>-qualified function type");
2823 else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2824 error_at (loc, "%<_Atomic%> applied to a qualified type");
2825 else
2826 t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2827 }
2828 declspecs_add_type (loc, specs, t);
2829 }
2830 else
2831 declspecs_add_qual (loc, specs, value);
2832 break;
2833 case RID_CONST:
2834 case RID_VOLATILE:
2835 case RID_RESTRICT:
2836 attrs_ok = true;
2837 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2838 c_parser_consume_token (parser);
2839 break;
2840 case RID_ATTRIBUTE:
2841 if (!attrs_ok)
2842 goto out;
2843 attrs = c_parser_attributes (parser);
2844 declspecs_add_attrs (loc, specs, attrs);
2845 break;
2846 case RID_ALIGNAS:
2847 if (!alignspec_ok)
2848 goto out;
2849 align = c_parser_alignas_specifier (parser);
2850 declspecs_add_alignas (loc, specs, align);
2851 break;
2852 case RID_GIMPLE:
2853 if (! flag_gimple)
2854 error_at (loc, "%<__GIMPLE%> only valid with -fgimple");
2855 c_parser_consume_token (parser);
2856 specs->gimple_p = true;
2857 specs->locations[cdw_gimple] = loc;
2858 specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2859 break;
2860 case RID_RTL:
2861 c_parser_consume_token (parser);
2862 specs->rtl_p = true;
2863 specs->locations[cdw_rtl] = loc;
2864 specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2865 break;
2866 default:
2867 goto out;
2868 }
2869 }
2870 out: ;
2871}
2872
2873/* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2874
2875 enum-specifier:
2876 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2877 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2878 enum attributes[opt] identifier
2879
2880 The form with trailing comma is new in C99. The forms with
2881 attributes are GNU extensions. In GNU C, we accept any expression
2882 without commas in the syntax (assignment expressions, not just
2883 conditional expressions); assignment expressions will be diagnosed
2884 as non-constant.
2885
2886 enumerator-list:
2887 enumerator
2888 enumerator-list , enumerator
2889
2890 enumerator:
2891 enumeration-constant
2892 enumeration-constant = constant-expression
2893
2894 GNU Extensions:
2895
2896 enumerator:
2897 enumeration-constant attributes[opt]
2898 enumeration-constant attributes[opt] = constant-expression
2899
2900*/
2901
2902static struct c_typespec
2903c_parser_enum_specifier (c_parser *parser)
2904{
2905 struct c_typespec ret;
2906 tree attrs;
2907 tree ident = NULL_TREE;
2908 location_t enum_loc;
2909 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2910 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2911 c_parser_consume_token (parser);
2912 attrs = c_parser_attributes (parser);
2913 enum_loc = c_parser_peek_token (parser)->location;
2914 /* Set the location in case we create a decl now. */
2915 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2916 if (c_parser_next_token_is (parser, CPP_NAME))
2917 {
2918 ident = c_parser_peek_token (parser)->value;
2919 ident_loc = c_parser_peek_token (parser)->location;
2920 enum_loc = ident_loc;
2921 c_parser_consume_token (parser);
2922 }
2923 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2924 {
2925 /* Parse an enum definition. */
2926 struct c_enum_contents the_enum;
2927 tree type;
2928 tree postfix_attrs;
2929 /* We chain the enumerators in reverse order, then put them in
2930 forward order at the end. */
2931 tree values;
2932 timevar_push (TV_PARSE_ENUM);
2933 type = start_enum (enum_loc, &the_enum, ident);
2934 values = NULL_TREE;
2935 c_parser_consume_token (parser);
2936 while (true)
2937 {
2938 tree enum_id;
2939 tree enum_value;
2940 tree enum_decl;
2941 bool seen_comma;
2942 c_token *token;
2943 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2944 location_t decl_loc, value_loc;
2945 if (c_parser_next_token_is_not (parser, CPP_NAME))
2946 {
2947 /* Give a nicer error for "enum {}". */
2948 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2949 && !parser->error)
2950 {
2951 error_at (c_parser_peek_token (parser)->location,
2952 "empty enum is invalid");
2953 parser->error = true;
2954 }
2955 else
2956 c_parser_error (parser, "expected identifier");
2957 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2958 values = error_mark_node;
2959 break;
2960 }
2961 token = c_parser_peek_token (parser);
2962 enum_id = token->value;
2963 /* Set the location in case we create a decl now. */
2964 c_parser_set_source_position_from_token (token);
2965 decl_loc = value_loc = token->location;
2966 c_parser_consume_token (parser);
2967 /* Parse any specified attributes. */
2968 tree enum_attrs = c_parser_attributes (parser);
2969 if (c_parser_next_token_is (parser, CPP_EQ))
2970 {
2971 c_parser_consume_token (parser);
2972 value_loc = c_parser_peek_token (parser)->location;
2973 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2974 }
2975 else
2976 enum_value = NULL_TREE;
2977 enum_decl = build_enumerator (decl_loc, value_loc,
2978 &the_enum, enum_id, enum_value);
2979 if (enum_attrs)
2980 decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0);
2981 TREE_CHAIN (enum_decl) = values;
2982 values = enum_decl;
2983 seen_comma = false;
2984 if (c_parser_next_token_is (parser, CPP_COMMA))
2985 {
2986 comma_loc = c_parser_peek_token (parser)->location;
2987 seen_comma = true;
2988 c_parser_consume_token (parser);
2989 }
2990 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2991 {
2992 if (seen_comma)
2993 pedwarn_c90 (comma_loc, OPT_Wpedantic,
2994 "comma at end of enumerator list");
2995 c_parser_consume_token (parser);
2996 break;
2997 }
2998 if (!seen_comma)
2999 {
3000 c_parser_error (parser, "expected %<,%> or %<}%>");
3001 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
3002 values = error_mark_node;
3003 break;
3004 }
3005 }
3006 postfix_attrs = c_parser_attributes (parser);
3007 ret.spec = finish_enum (type, nreverse (values),
3008 chainon (attrs, postfix_attrs));
3009 ret.kind = ctsk_tagdef;
3010 ret.expr = NULL_TREE;
3011 ret.expr_const_operands = true;
3012 timevar_pop (TV_PARSE_ENUM);
3013 return ret;
3014 }
3015 else if (!ident)
3016 {
3017 c_parser_error (parser, "expected %<{%>");
3018 ret.spec = error_mark_node;
3019 ret.kind = ctsk_tagref;
3020 ret.expr = NULL_TREE;
3021 ret.expr_const_operands = true;
3022 return ret;
3023 }
3024 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
3025 /* In ISO C, enumerated types can be referred to only if already
3026 defined. */
3027 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
3028 {
3029 gcc_assert (ident);
3030 pedwarn (enum_loc, OPT_Wpedantic,
3031 "ISO C forbids forward references to %<enum%> types");
3032 }
3033 return ret;
3034}
3035
3036/* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3037
3038 struct-or-union-specifier:
3039 struct-or-union attributes[opt] identifier[opt]
3040 { struct-contents } attributes[opt]
3041 struct-or-union attributes[opt] identifier
3042
3043 struct-contents:
3044 struct-declaration-list
3045
3046 struct-declaration-list:
3047 struct-declaration ;
3048 struct-declaration-list struct-declaration ;
3049
3050 GNU extensions:
3051
3052 struct-contents:
3053 empty
3054 struct-declaration
3055 struct-declaration-list struct-declaration
3056
3057 struct-declaration-list:
3058 struct-declaration-list ;
3059 ;
3060
3061 (Note that in the syntax here, unlike that in ISO C, the semicolons
3062 are included here rather than in struct-declaration, in order to
3063 describe the syntax with extra semicolons and missing semicolon at
3064 end.)
3065
3066 Objective-C:
3067
3068 struct-declaration-list:
3069 @defs ( class-name )
3070
3071 (Note this does not include a trailing semicolon, but can be
3072 followed by further declarations, and gets a pedwarn-if-pedantic
3073 when followed by a semicolon.) */
3074
3075static struct c_typespec
3076c_parser_struct_or_union_specifier (c_parser *parser)
3077{
3078 struct c_typespec ret;
3079 tree attrs;
3080 tree ident = NULL_TREE;
3081 location_t struct_loc;
3082 location_t ident_loc = UNKNOWN_LOCATION;
3083 enum tree_code code;
3084 switch (c_parser_peek_token (parser)->keyword)
3085 {
3086 case RID_STRUCT:
3087 code = RECORD_TYPE;
3088 break;
3089 case RID_UNION:
3090 code = UNION_TYPE;
3091 break;
3092 default:
3093 gcc_unreachable ();
3094 }
3095 struct_loc = c_parser_peek_token (parser)->location;
3096 c_parser_consume_token (parser);
3097 attrs = c_parser_attributes (parser);
3098
3099 /* Set the location in case we create a decl now. */
3100 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
3101
3102 if (c_parser_next_token_is (parser, CPP_NAME))
3103 {
3104 ident = c_parser_peek_token (parser)->value;
3105 ident_loc = c_parser_peek_token (parser)->location;
3106 struct_loc = ident_loc;
3107 c_parser_consume_token (parser);
3108 }
3109 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3110 {
3111 /* Parse a struct or union definition. Start the scope of the
3112 tag before parsing components. */
3113 struct c_struct_parse_info *struct_info;
3114 tree type = start_struct (struct_loc, code, ident, &struct_info);
3115 tree postfix_attrs;
3116 /* We chain the components in reverse order, then put them in
3117 forward order at the end. Each struct-declaration may
3118 declare multiple components (comma-separated), so we must use
3119 chainon to join them, although when parsing each
3120 struct-declaration we can use TREE_CHAIN directly.
3121
3122 The theory behind all this is that there will be more
3123 semicolon separated fields than comma separated fields, and
3124 so we'll be minimizing the number of node traversals required
3125 by chainon. */
3126 tree contents;
3127 timevar_push (TV_PARSE_STRUCT);
3128 contents = NULL_TREE;
3129 c_parser_consume_token (parser);
3130 /* Handle the Objective-C @defs construct,
3131 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3132 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
3133 {
3134 tree name;
3135 gcc_assert (c_dialect_objc ());
3136 c_parser_consume_token (parser);
3137 matching_parens parens;
3138 if (!parens.require_open (parser))
3139 goto end_at_defs;
3140 if (c_parser_next_token_is (parser, CPP_NAME)
3141 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
3142 {
3143 name = c_parser_peek_token (parser)->value;
3144 c_parser_consume_token (parser);
3145 }
3146 else
3147 {
3148 c_parser_error (parser, "expected class name");
3149 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3150 goto end_at_defs;
3151 }
3152 parens.skip_until_found_close (parser);
3153 contents = nreverse (objc_get_class_ivars (name));
3154 }
3155 end_at_defs:
3156 /* Parse the struct-declarations and semicolons. Problems with
3157 semicolons are diagnosed here; empty structures are diagnosed
3158 elsewhere. */
3159 while (true)
3160 {
3161 tree decls;
3162 /* Parse any stray semicolon. */
3163 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3164 {
3165 location_t semicolon_loc
3166 = c_parser_peek_token (parser)->location;
3167 gcc_rich_location richloc (semicolon_loc);
3168 richloc.add_fixit_remove ();
3169 pedwarn (&richloc, OPT_Wpedantic,
3170 "extra semicolon in struct or union specified");
3171 c_parser_consume_token (parser);
3172 continue;
3173 }
3174 /* Stop if at the end of the struct or union contents. */
3175 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3176 {
3177 c_parser_consume_token (parser);
3178 break;
3179 }
3180 /* Accept #pragmas at struct scope. */
3181 if (c_parser_next_token_is (parser, CPP_PRAGMA))
3182 {
3183 c_parser_pragma (parser, pragma_struct, NULL);
3184 continue;
3185 }
3186 /* Parse some comma-separated declarations, but not the
3187 trailing semicolon if any. */
3188 decls = c_parser_struct_declaration (parser);
3189 contents = chainon (decls, contents);
3190 /* If no semicolon follows, either we have a parse error or
3191 are at the end of the struct or union and should
3192 pedwarn. */
3193 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3194 c_parser_consume_token (parser);
3195 else
3196 {
3197 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3198 pedwarn (c_parser_peek_token (parser)->location, 0,
3199 "no semicolon at end of struct or union");
3200 else if (parser->error
3201 || !c_parser_next_token_starts_declspecs (parser))
3202 {
3203 c_parser_error (parser, "expected %<;%>");
3204 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
3205 break;
3206 }
3207
3208 /* If we come here, we have already emitted an error
3209 for an expected `;', identifier or `(', and we also
3210 recovered already. Go on with the next field. */
3211 }
3212 }
3213 postfix_attrs = c_parser_attributes (parser);
3214 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
3215 chainon (attrs, postfix_attrs), struct_info);
3216 ret.kind = ctsk_tagdef;
3217 ret.expr = NULL_TREE;
3218 ret.expr_const_operands = true;
3219 timevar_pop (TV_PARSE_STRUCT);
3220 return ret;
3221 }
3222 else if (!ident)
3223 {
3224 c_parser_error (parser, "expected %<{%>");
3225 ret.spec = error_mark_node;
3226 ret.kind = ctsk_tagref;
3227 ret.expr = NULL_TREE;
3228 ret.expr_const_operands = true;
3229 return ret;
3230 }
3231 ret = parser_xref_tag (ident_loc, code, ident);
3232 return ret;
3233}
3234
3235/* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3236 *without* the trailing semicolon.
3237
3238 struct-declaration:
3239 specifier-qualifier-list struct-declarator-list
3240 static_assert-declaration-no-semi
3241
3242 specifier-qualifier-list:
3243 type-specifier specifier-qualifier-list[opt]
3244 type-qualifier specifier-qualifier-list[opt]
3245 alignment-specifier specifier-qualifier-list[opt]
3246 attributes specifier-qualifier-list[opt]
3247
3248 struct-declarator-list:
3249 struct-declarator
3250 struct-declarator-list , attributes[opt] struct-declarator
3251
3252 struct-declarator:
3253 declarator attributes[opt]
3254 declarator[opt] : constant-expression attributes[opt]
3255
3256 GNU extensions:
3257
3258 struct-declaration:
3259 __extension__ struct-declaration
3260 specifier-qualifier-list
3261
3262 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3263 of attributes where shown is a GNU extension. In GNU C, we accept
3264 any expression without commas in the syntax (assignment
3265 expressions, not just conditional expressions); assignment
3266 expressions will be diagnosed as non-constant. */
3267
3268static tree
3269c_parser_struct_declaration (c_parser *parser)
3270{
3271 struct c_declspecs *specs;
3272 tree prefix_attrs;
3273 tree all_prefix_attrs;
3274 tree decls;
3275 location_t decl_loc;
3276 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3277 {
3278 int ext;
3279 tree decl;
3280 ext = disable_extension_diagnostics ();
3281 c_parser_consume_token (parser);
3282 decl = c_parser_struct_declaration (parser);
3283 restore_extension_diagnostics (ext);
3284 return decl;
3285 }
3286 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
3287 {
3288 c_parser_static_assert_declaration_no_semi (parser);
3289 return NULL_TREE;
3290 }
3291 specs = build_null_declspecs ();
3292 decl_loc = c_parser_peek_token (parser)->location;
3293 /* Strictly by the standard, we shouldn't allow _Alignas here,
3294 but it appears to have been intended to allow it there, so
3295 we're keeping it as it is until WG14 reaches a conclusion
3296 of N1731.
3297 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3298 c_parser_declspecs (parser, specs, false, true, true,
3299 true, false, cla_nonabstract_decl);
3300 if (parser->error)
3301 return NULL_TREE;
3302 if (!specs->declspecs_seen_p)
3303 {
3304 c_parser_error (parser, "expected specifier-qualifier-list");
3305 return NULL_TREE;
3306 }
3307 finish_declspecs (specs);
3308 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3309 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3310 {
3311 tree ret;
3312 if (specs->typespec_kind == ctsk_none)
3313 {
3314 pedwarn (decl_loc, OPT_Wpedantic,
3315 "ISO C forbids member declarations with no members");
3316 shadow_tag_warned (specs, pedantic);
3317 ret = NULL_TREE;
3318 }
3319 else
3320 {
3321 /* Support for unnamed structs or unions as members of
3322 structs or unions (which is [a] useful and [b] supports
3323 MS P-SDK). */
3324 tree attrs = NULL;
3325
3326 ret = grokfield (c_parser_peek_token (parser)->location,
3327 build_id_declarator (NULL_TREE), specs,
3328 NULL_TREE, &attrs);
3329 if (ret)
3330 decl_attributes (&ret, attrs, 0);
3331 }
3332 return ret;
3333 }
3334
3335 /* Provide better error recovery. Note that a type name here is valid,
3336 and will be treated as a field name. */
3337 if (specs->typespec_kind == ctsk_tagdef
3338 && TREE_CODE (specs->type) != ENUMERAL_TYPE
3339 && c_parser_next_token_starts_declspecs (parser)
3340 && !c_parser_next_token_is (parser, CPP_NAME))
3341 {
3342 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
3343 parser->error = false;
3344 return NULL_TREE;
3345 }
3346
3347 pending_xref_error ();
3348 prefix_attrs = specs->attrs;
3349 all_prefix_attrs = prefix_attrs;
3350 specs->attrs = NULL_TREE;
3351 decls = NULL_TREE;
3352 while (true)
3353 {
3354 /* Declaring one or more declarators or un-named bit-fields. */
3355 struct c_declarator *declarator;
3356 bool dummy = false;
3357 if (c_parser_next_token_is (parser, CPP_COLON))
3358 declarator = build_id_declarator (NULL_TREE);
3359 else
3360 declarator = c_parser_declarator (parser,
3361 specs->typespec_kind != ctsk_none,
3362 C_DTR_NORMAL, &dummy);
3363 if (declarator == NULL)
3364 {
3365 c_parser_skip_to_end_of_block_or_statement (parser);
3366 break;
3367 }
3368 if (c_parser_next_token_is (parser, CPP_COLON)
3369 || c_parser_next_token_is (parser, CPP_COMMA)
3370 || c_parser_next_token_is (parser, CPP_SEMICOLON)
3371 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
3372 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3373 {
3374 tree postfix_attrs = NULL_TREE;
3375 tree width = NULL_TREE;
3376 tree d;
3377 if (c_parser_next_token_is (parser, CPP_COLON))
3378 {
3379 c_parser_consume_token (parser);
3380 width = c_parser_expr_no_commas (parser, NULL).value;
3381 }
3382 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3383 postfix_attrs = c_parser_attributes (parser);
3384 d = grokfield (c_parser_peek_token (parser)->location,
3385 declarator, specs, width, &all_prefix_attrs);
3386 decl_attributes (&d, chainon (postfix_attrs,
3387 all_prefix_attrs), 0);
3388 DECL_CHAIN (d) = decls;
3389 decls = d;
3390 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3391 all_prefix_attrs = chainon (c_parser_attributes (parser),
3392 prefix_attrs);
3393 else
3394 all_prefix_attrs = prefix_attrs;
3395 if (c_parser_next_token_is (parser, CPP_COMMA))
3396 c_parser_consume_token (parser);
3397 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3398 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3399 {
3400 /* Semicolon consumed in caller. */
3401 break;
3402 }
3403 else
3404 {
3405 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3406 break;
3407 }
3408 }
3409 else
3410 {
3411 c_parser_error (parser,
3412 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3413 "%<__attribute__%>");
3414 break;
3415 }
3416 }
3417 return decls;
3418}
3419
3420/* Parse a typeof specifier (a GNU extension).
3421
3422 typeof-specifier:
3423 typeof ( expression )
3424 typeof ( type-name )
3425*/
3426
3427static struct c_typespec
3428c_parser_typeof_specifier (c_parser *parser)
3429{
3430 struct c_typespec ret;
3431 ret.kind = ctsk_typeof;
3432 ret.spec = error_mark_node;
3433 ret.expr = NULL_TREE;
3434 ret.expr_const_operands = true;
3435 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3436 c_parser_consume_token (parser);
3437 c_inhibit_evaluation_warnings++;
3438 in_typeof++;
3439 matching_parens parens;
3440 if (!parens.require_open (parser))
3441 {
3442 c_inhibit_evaluation_warnings--;
3443 in_typeof--;
3444 return ret;
3445 }
3446 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3447 {
3448 struct c_type_name *type = c_parser_type_name (parser);
3449 c_inhibit_evaluation_warnings--;
3450 in_typeof--;
3451 if (type != NULL)
3452 {
3453 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3454 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3455 }
3456 }
3457 else
3458 {
3459 bool was_vm;
3460 location_t here = c_parser_peek_token (parser)->location;
3461 struct c_expr expr = c_parser_expression (parser);
3462 c_inhibit_evaluation_warnings--;
3463 in_typeof--;
3464 if (TREE_CODE (expr.value) == COMPONENT_REF
3465 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3466 error_at (here, "%<typeof%> applied to a bit-field");
3467 mark_exp_read (expr.value);
3468 ret.spec = TREE_TYPE (expr.value);
3469 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3470 /* This is returned with the type so that when the type is
3471 evaluated, this can be evaluated. */
3472 if (was_vm)
3473 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3474 pop_maybe_used (was_vm);
3475 /* For use in macros such as those in <stdatomic.h>, remove all
3476 qualifiers from atomic types. (const can be an issue for more macros
3477 using typeof than just the <stdatomic.h> ones.) */
3478 if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3479 ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3480 }
3481 parens.skip_until_found_close (parser);
3482 return ret;
3483}
3484
3485/* Parse an alignment-specifier.
3486
3487 C11 6.7.5:
3488
3489 alignment-specifier:
3490 _Alignas ( type-name )
3491 _Alignas ( constant-expression )
3492*/
3493
3494static tree
3495c_parser_alignas_specifier (c_parser * parser)
3496{
3497 tree ret = error_mark_node;
3498 location_t loc = c_parser_peek_token (parser)->location;
3499 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3500 c_parser_consume_token (parser);
3501 if (flag_isoc99)
3502 pedwarn_c99 (loc, OPT_Wpedantic,
3503 "ISO C99 does not support %<_Alignas%>");
3504 else
3505 pedwarn_c99 (loc, OPT_Wpedantic,
3506 "ISO C90 does not support %<_Alignas%>");
3507 matching_parens parens;
3508 if (!parens.require_open (parser))
3509 return ret;
3510 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3511 {
3512 struct c_type_name *type = c_parser_type_name (parser);
3513 if (type != NULL)
3514 ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3515 false, true, 1);
3516 }
3517 else
3518 ret = c_parser_expr_no_commas (parser, NULL).value;
3519 parens.skip_until_found_close (parser);
3520 return ret;
3521}
3522
3523/* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3524 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3525 a typedef name may be redeclared; otherwise it may not. KIND
3526 indicates which kind of declarator is wanted. Returns a valid
3527 declarator except in the case of a syntax error in which case NULL is
3528 returned. *SEEN_ID is set to true if an identifier being declared is
3529 seen; this is used to diagnose bad forms of abstract array declarators
3530 and to determine whether an identifier list is syntactically permitted.
3531
3532 declarator:
3533 pointer[opt] direct-declarator
3534
3535 direct-declarator:
3536 identifier
3537 ( attributes[opt] declarator )
3538 direct-declarator array-declarator
3539 direct-declarator ( parameter-type-list )
3540 direct-declarator ( identifier-list[opt] )
3541
3542 pointer:
3543 * type-qualifier-list[opt]
3544 * type-qualifier-list[opt] pointer
3545
3546 type-qualifier-list:
3547 type-qualifier
3548 attributes
3549 type-qualifier-list type-qualifier
3550 type-qualifier-list attributes
3551
3552 array-declarator:
3553 [ type-qualifier-list[opt] assignment-expression[opt] ]
3554 [ static type-qualifier-list[opt] assignment-expression ]
3555 [ type-qualifier-list static assignment-expression ]
3556 [ type-qualifier-list[opt] * ]
3557
3558 parameter-type-list:
3559 parameter-list
3560 parameter-list , ...
3561
3562 parameter-list:
3563 parameter-declaration
3564 parameter-list , parameter-declaration
3565
3566 parameter-declaration:
3567 declaration-specifiers declarator attributes[opt]
3568 declaration-specifiers abstract-declarator[opt] attributes[opt]
3569
3570 identifier-list:
3571 identifier
3572 identifier-list , identifier
3573
3574 abstract-declarator:
3575 pointer
3576 pointer[opt] direct-abstract-declarator
3577
3578 direct-abstract-declarator:
3579 ( attributes[opt] abstract-declarator )
3580 direct-abstract-declarator[opt] array-declarator
3581 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3582
3583 GNU extensions:
3584
3585 direct-declarator:
3586 direct-declarator ( parameter-forward-declarations
3587 parameter-type-list[opt] )
3588
3589 direct-abstract-declarator:
3590 direct-abstract-declarator[opt] ( parameter-forward-declarations
3591 parameter-type-list[opt] )
3592
3593 parameter-forward-declarations:
3594 parameter-list ;
3595 parameter-forward-declarations parameter-list ;
3596
3597 The uses of attributes shown above are GNU extensions.
3598
3599 Some forms of array declarator are not included in C99 in the
3600 syntax for abstract declarators; these are disallowed elsewhere.
3601 This may be a defect (DR#289).
3602
3603 This function also accepts an omitted abstract declarator as being
3604 an abstract declarator, although not part of the formal syntax. */
3605
3606struct c_declarator *
3607c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3608 bool *seen_id)
3609{
3610 /* Parse any initial pointer part. */
3611 if (c_parser_next_token_is (parser, CPP_MULT))
3612 {
3613 struct c_declspecs *quals_attrs = build_null_declspecs ();
3614 struct c_declarator *inner;
3615 c_parser_consume_token (parser);
3616 c_parser_declspecs (parser, quals_attrs, false, false, true,
3617 false, false, cla_prefer_id);
3618 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3619 if (inner == NULL)
3620 return NULL;
3621 else
3622 return make_pointer_declarator (quals_attrs, inner);
3623 }
3624 /* Now we have a direct declarator, direct abstract declarator or
3625 nothing (which counts as a direct abstract declarator here). */
3626 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3627}
3628
3629/* Parse a direct declarator or direct abstract declarator; arguments
3630 as c_parser_declarator. */
3631
3632static struct c_declarator *
3633c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3634 bool *seen_id)
3635{
3636 /* The direct declarator must start with an identifier (possibly
3637 omitted) or a parenthesized declarator (possibly abstract). In
3638 an ordinary declarator, initial parentheses must start a
3639 parenthesized declarator. In an abstract declarator or parameter
3640 declarator, they could start a parenthesized declarator or a
3641 parameter list. To tell which, the open parenthesis and any
3642 following attributes must be read. If a declaration specifier
3643 follows, then it is a parameter list; if the specifier is a
3644 typedef name, there might be an ambiguity about redeclaring it,
3645 which is resolved in the direction of treating it as a typedef
3646 name. If a close parenthesis follows, it is also an empty
3647 parameter list, as the syntax does not permit empty abstract
3648 declarators. Otherwise, it is a parenthesized declarator (in
3649 which case the analysis may be repeated inside it, recursively).
3650
3651 ??? There is an ambiguity in a parameter declaration "int
3652 (__attribute__((foo)) x)", where x is not a typedef name: it
3653 could be an abstract declarator for a function, or declare x with
3654 parentheses. The proper resolution of this ambiguity needs
3655 documenting. At present we follow an accident of the old
3656 parser's implementation, whereby the first parameter must have
3657 some declaration specifiers other than just attributes. Thus as
3658 a parameter declaration it is treated as a parenthesized
3659 parameter named x, and as an abstract declarator it is
3660 rejected.
3661
3662 ??? Also following the old parser, attributes inside an empty
3663 parameter list are ignored, making it a list not yielding a
3664 prototype, rather than giving an error or making it have one
3665 parameter with implicit type int.
3666
3667 ??? Also following the old parser, typedef names may be
3668 redeclared in declarators, but not Objective-C class names. */
3669
3670 if (kind != C_DTR_ABSTRACT
3671 && c_parser_next_token_is (parser, CPP_NAME)
3672 && ((type_seen_p
3673 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3674 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3675 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3676 {
3677 struct c_declarator *inner
3678 = build_id_declarator (c_parser_peek_token (parser)->value);
3679 *seen_id = true;
3680 inner->id_loc = c_parser_peek_token (parser)->location;
3681 c_parser_consume_token (parser);
3682 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3683 }
3684
3685 if (kind != C_DTR_NORMAL
3686 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3687 {
3688 struct c_declarator *inner = build_id_declarator (NULL_TREE);
3689 inner->id_loc = c_parser_peek_token (parser)->location;
3690 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3691 }
3692
3693 /* Either we are at the end of an abstract declarator, or we have
3694 parentheses. */
3695
3696 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3697 {
3698 tree attrs;
3699 struct c_declarator *inner;
3700 c_parser_consume_token (parser);
3701 attrs = c_parser_attributes (parser);
3702 if (kind != C_DTR_NORMAL
3703 && (c_parser_next_token_starts_declspecs (parser)
3704 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3705 {
3706 struct c_arg_info *args
3707 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3708 attrs);
3709 if (args == NULL)
3710 return NULL;
3711 else
3712 {
3713 inner
3714 = build_function_declarator (args,
3715 build_id_declarator (NULL_TREE));
3716 return c_parser_direct_declarator_inner (parser, *seen_id,
3717 inner);
3718 }
3719 }
3720 /* A parenthesized declarator. */
3721 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3722 if (inner != NULL && attrs != NULL)
3723 inner = build_attrs_declarator (attrs, inner);
3724 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3725 {
3726 c_parser_consume_token (parser);
3727 if (inner == NULL)
3728 return NULL;
3729 else
3730 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3731 }
3732 else
3733 {
3734 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3735 "expected %<)%>");
3736 return NULL;
3737 }
3738 }
3739 else
3740 {
3741 if (kind == C_DTR_NORMAL)
3742 {
3743 c_parser_error (parser, "expected identifier or %<(%>");
3744 return NULL;
3745 }
3746 else
3747 return build_id_declarator (NULL_TREE);
3748 }
3749}
3750
3751/* Parse part of a direct declarator or direct abstract declarator,
3752 given that some (in INNER) has already been parsed; ID_PRESENT is
3753 true if an identifier is present, false for an abstract
3754 declarator. */
3755
3756static struct c_declarator *
3757c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3758 struct c_declarator *inner)
3759{
3760 /* Parse a sequence of array declarators and parameter lists. */
3761 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3762 {
3763 location_t brace_loc = c_parser_peek_token (parser)->location;
3764 struct c_declarator *declarator;
3765 struct c_declspecs *quals_attrs = build_null_declspecs ();
3766 bool static_seen;
3767 bool star_seen;
3768 struct c_expr dimen;
3769 dimen.value = NULL_TREE;
3770 dimen.original_code = ERROR_MARK;
3771 dimen.original_type = NULL_TREE;
3772 c_parser_consume_token (parser);
3773 c_parser_declspecs (parser, quals_attrs, false, false, true,
3774 false, false, cla_prefer_id);
3775 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3776 if (static_seen)
3777 c_parser_consume_token (parser);
3778 if (static_seen && !quals_attrs->declspecs_seen_p)
3779 c_parser_declspecs (parser, quals_attrs, false, false, true,
3780 false, false, cla_prefer_id);
3781 if (!quals_attrs->declspecs_seen_p)
3782 quals_attrs = NULL;
3783 /* If "static" is present, there must be an array dimension.
3784 Otherwise, there may be a dimension, "*", or no
3785 dimension. */
3786 if (static_seen)
3787 {
3788 star_seen = false;
3789 dimen = c_parser_expr_no_commas (parser, NULL);
3790 }
3791 else
3792 {
3793 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3794 {
3795 dimen.value = NULL_TREE;
3796 star_seen = false;
3797 }
3798 else if (c_parser_next_token_is (parser, CPP_MULT))
3799 {
3800 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3801 {
3802 dimen.value = NULL_TREE;
3803 star_seen = true;
3804 c_parser_consume_token (parser);
3805 }
3806 else
3807 {
3808 star_seen = false;
3809 dimen = c_parser_expr_no_commas (parser, NULL);
3810 }
3811 }
3812 else
3813 {
3814 star_seen = false;
3815 dimen = c_parser_expr_no_commas (parser, NULL);
3816 }
3817 }
3818 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3819 c_parser_consume_token (parser);
3820 else
3821 {
3822 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3823 "expected %<]%>");
3824 return NULL;
3825 }
3826 if (dimen.value)
3827 dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3828 declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3829 static_seen, star_seen);
3830 if (declarator == NULL)
3831 return NULL;
3832 inner = set_array_declarator_inner (declarator, inner);
3833 return c_parser_direct_declarator_inner (parser, id_present, inner);
3834 }
3835 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3836 {
3837 tree attrs;
3838 struct c_arg_info *args;
3839 c_parser_consume_token (parser);
3840 attrs = c_parser_attributes (parser);
3841 args = c_parser_parms_declarator (parser, id_present, attrs);
3842 if (args == NULL)
3843 return NULL;
3844 else
3845 {
3846 inner = build_function_declarator (args, inner);
3847 return c_parser_direct_declarator_inner (parser, id_present, inner);
3848 }
3849 }
3850 return inner;
3851}
3852
3853/* Parse a parameter list or identifier list, including the closing
3854 parenthesis but not the opening one. ATTRS are the attributes at
3855 the start of the list. ID_LIST_OK is true if an identifier list is
3856 acceptable; such a list must not have attributes at the start. */
3857
3858static struct c_arg_info *
3859c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3860{
3861 push_scope ();
3862 declare_parm_level ();
3863 /* If the list starts with an identifier, it is an identifier list.
3864 Otherwise, it is either a prototype list or an empty list. */
3865 if (id_list_ok
3866 && !attrs
3867 && c_parser_next_token_is (parser, CPP_NAME)
3868 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3869
3870 /* Look ahead to detect typos in type names. */
3871 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3872 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3873 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3874 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE
3875 && c_parser_peek_2nd_token (parser)->type != CPP_KEYWORD)
3876 {
3877 tree list = NULL_TREE, *nextp = &list;
3878 while (c_parser_next_token_is (parser, CPP_NAME)
3879 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3880 {
3881 *nextp = build_tree_list (NULL_TREE,
3882 c_parser_peek_token (parser)->value);
3883 nextp = & TREE_CHAIN (*nextp);
3884 c_parser_consume_token (parser);
3885 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3886 break;
3887 c_parser_consume_token (parser);
3888 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3889 {
3890 c_parser_error (parser, "expected identifier");
3891 break;
3892 }
3893 }
3894 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3895 {
3896 struct c_arg_info *ret = build_arg_info ();
3897 ret->types = list;
3898 c_parser_consume_token (parser);
3899 pop_scope ();
3900 return ret;
3901 }
3902 else
3903 {
3904 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3905 "expected %<)%>");
3906 pop_scope ();
3907 return NULL;
3908 }
3909 }
3910 else
3911 {
3912 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3913 NULL);
3914 pop_scope ();
3915 return ret;
3916 }
3917}
3918
3919/* Parse a parameter list (possibly empty), including the closing
3920 parenthesis but not the opening one. ATTRS are the attributes at
3921 the start of the list. EXPR is NULL or an expression that needs to
3922 be evaluated for the side effects of array size expressions in the
3923 parameters. */
3924
3925static struct c_arg_info *
3926c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3927{
3928 bool bad_parm = false;
3929
3930 /* ??? Following the old parser, forward parameter declarations may
3931 use abstract declarators, and if no real parameter declarations
3932 follow the forward declarations then this is not diagnosed. Also
3933 note as above that attributes are ignored as the only contents of
3934 the parentheses, or as the only contents after forward
3935 declarations. */
3936 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3937 {
3938 struct c_arg_info *ret = build_arg_info ();
3939 c_parser_consume_token (parser);
3940 return ret;
3941 }
3942 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3943 {
3944 struct c_arg_info *ret = build_arg_info ();
3945
3946 if (flag_allow_parameterless_variadic_functions)
3947 {
3948 /* F (...) is allowed. */
3949 ret->types = NULL_TREE;
3950 }
3951 else
3952 {
3953 /* Suppress -Wold-style-definition for this case. */
3954 ret->types = error_mark_node;
3955 error_at (c_parser_peek_token (parser)->location,
3956 "ISO C requires a named argument before %<...%>");
3957 }
3958 c_parser_consume_token (parser);
3959 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3960 {
3961 c_parser_consume_token (parser);
3962 return ret;
3963 }
3964 else
3965 {
3966 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3967 "expected %<)%>");
3968 return NULL;
3969 }
3970 }
3971 /* Nonempty list of parameters, either terminated with semicolon
3972 (forward declarations; recurse) or with close parenthesis (normal
3973 function) or with ", ... )" (variadic function). */
3974 while (true)
3975 {
3976 /* Parse a parameter. */
3977 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3978 attrs = NULL_TREE;
3979 if (parm == NULL)
3980 bad_parm = true;
3981 else
3982 push_parm_decl (parm, &expr);
3983 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3984 {
3985 tree new_attrs;
3986 c_parser_consume_token (parser);
3987 mark_forward_parm_decls ();
3988 new_attrs = c_parser_attributes (parser);
3989 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3990 }
3991 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3992 {
3993 c_parser_consume_token (parser);
3994 if (bad_parm)
3995 return NULL;
3996 else
3997 return get_parm_info (false, expr);
3998 }
3999 if (!c_parser_require (parser, CPP_COMMA,
4000 "expected %<;%>, %<,%> or %<)%>",
4001 UNKNOWN_LOCATION, false))
4002 {
4003 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4004 return NULL;
4005 }
4006 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4007 {
4008 c_parser_consume_token (parser);
4009 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4010 {
4011 c_parser_consume_token (parser);
4012 if (bad_parm)
4013 return NULL;
4014 else
4015 return get_parm_info (true, expr);
4016 }
4017 else
4018 {
4019 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4020 "expected %<)%>");
4021 return NULL;
4022 }
4023 }
4024 }
4025}
4026
4027/* Parse a parameter declaration. ATTRS are the attributes at the
4028 start of the declaration if it is the first parameter. */
4029
4030static struct c_parm *
4031c_parser_parameter_declaration (c_parser *parser, tree attrs)
4032{
4033 struct c_declspecs *specs;
4034 struct c_declarator *declarator;
4035 tree prefix_attrs;
4036 tree postfix_attrs = NULL_TREE;
4037 bool dummy = false;
4038
4039 /* Accept #pragmas between parameter declarations. */
4040 while (c_parser_next_token_is (parser, CPP_PRAGMA))
4041 c_parser_pragma (parser, pragma_param, NULL);
4042
4043 if (!c_parser_next_token_starts_declspecs (parser))
4044 {
4045 c_token *token = c_parser_peek_token (parser);
4046 if (parser->error)
4047 return NULL;
4048 c_parser_set_source_position_from_token (token);
4049 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
4050 {
4051 name_hint hint = lookup_name_fuzzy (token->value,
4052 FUZZY_LOOKUP_TYPENAME,
4053 token->location);
4054 if (hint)
4055 {
4056 gcc_rich_location richloc (token->location);
4057 richloc.add_fixit_replace (hint.suggestion ());
4058 error_at (&richloc,
4059 "unknown type name %qE; did you mean %qs?",
4060 token->value, hint.suggestion ());
4061 }
4062 else
4063 error_at (token->location, "unknown type name %qE", token->value);
4064 parser->error = true;
4065 }
4066 /* ??? In some Objective-C cases '...' isn't applicable so there
4067 should be a different message. */
4068 else
4069 c_parser_error (parser,
4070 "expected declaration specifiers or %<...%>");
4071 c_parser_skip_to_end_of_parameter (parser);
4072 return NULL;
4073 }
4074
4075 location_t start_loc = c_parser_peek_token (parser)->location;
4076
4077 specs = build_null_declspecs ();
4078 if (attrs)
4079 {
4080 declspecs_add_attrs (input_location, specs, attrs);
4081 attrs = NULL_TREE;
4082 }
4083 c_parser_declspecs (parser, specs, true, true, true, true, false,
4084 cla_nonabstract_decl);
4085 finish_declspecs (specs);
4086 pending_xref_error ();
4087 prefix_attrs = specs->attrs;
4088 specs->attrs = NULL_TREE;
4089 declarator = c_parser_declarator (parser,
4090 specs->typespec_kind != ctsk_none,
4091 C_DTR_PARM, &dummy);
4092 if (declarator == NULL)
4093 {
4094 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4095 return NULL;
4096 }
4097 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4098 postfix_attrs = c_parser_attributes (parser);
4099
4100 /* Generate a location for the parameter, ranging from the start of the
4101 initial token to the end of the final token.
4102
4103 If we have a identifier, then use it for the caret location, e.g.
4104
4105 extern int callee (int one, int (*two)(int, int), float three);
4106 ~~~~~~^~~~~~~~~~~~~~
4107
4108 otherwise, reuse the start location for the caret location e.g.:
4109
4110 extern int callee (int one, int (*)(int, int), float three);
4111 ^~~~~~~~~~~~~~~~~
4112 */
4113 location_t end_loc = parser->last_token_location;
4114
4115 /* Find any cdk_id declarator; determine if we have an identifier. */
4116 c_declarator *id_declarator = declarator;
4117 while (id_declarator && id_declarator->kind != cdk_id)
4118 id_declarator = id_declarator->declarator;
4119 location_t caret_loc = (id_declarator->u.id
4120 ? id_declarator->id_loc
4121 : start_loc);
4122 location_t param_loc = make_location (caret_loc, start_loc, end_loc);
4123
4124 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
4125 declarator, param_loc);
4126}
4127
4128/* Parse a string literal in an asm expression. It should not be
4129 translated, and wide string literals are an error although
4130 permitted by the syntax. This is a GNU extension.
4131
4132 asm-string-literal:
4133 string-literal
4134
4135 ??? At present, following the old parser, the caller needs to have
4136 set lex_untranslated_string to 1. It would be better to follow the
4137 C++ parser rather than using this kludge. */
4138
4139static tree
4140c_parser_asm_string_literal (c_parser *parser)
4141{
4142 tree str;
4143 int save_flag = warn_overlength_strings;
4144 warn_overlength_strings = 0;
4145 if (c_parser_next_token_is (parser, CPP_STRING))
4146 {
4147 str = c_parser_peek_token (parser)->value;
4148 c_parser_consume_token (parser);
4149 }
4150 else if (c_parser_next_token_is (parser, CPP_WSTRING))
4151 {
4152 error_at (c_parser_peek_token (parser)->location,
4153 "wide string literal in %<asm%>");
4154 str = build_string (1, "");
4155 c_parser_consume_token (parser);
4156 }
4157 else
4158 {
4159 c_parser_error (parser, "expected string literal");
4160 str = NULL_TREE;
4161 }
4162 warn_overlength_strings = save_flag;
4163 return str;
4164}
4165
4166/* Parse a simple asm expression. This is used in restricted
4167 contexts, where a full expression with inputs and outputs does not
4168 make sense. This is a GNU extension.
4169
4170 simple-asm-expr:
4171 asm ( asm-string-literal )
4172*/
4173
4174static tree
4175c_parser_simple_asm_expr (c_parser *parser)
4176{
4177 tree str;
4178 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4179 /* ??? Follow the C++ parser rather than using the
4180 lex_untranslated_string kludge. */
4181 parser->lex_untranslated_string = true;
4182 c_parser_consume_token (parser);
4183 matching_parens parens;
4184 if (!parens.require_open (parser))
4185 {
4186 parser->lex_untranslated_string = false;
4187 return NULL_TREE;
4188 }
4189 str = c_parser_asm_string_literal (parser);
4190 parser->lex_untranslated_string = false;
4191 if (!parens.require_close (parser))
4192 {
4193 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4194 return NULL_TREE;
4195 }
4196 return str;
4197}
4198
4199static tree
4200c_parser_attribute_any_word (c_parser *parser)
4201{
4202 tree attr_name = NULL_TREE;
4203
4204 if (c_parser_next_token_is (parser, CPP_KEYWORD))
4205 {
4206 /* ??? See comment above about what keywords are accepted here. */
4207 bool ok;
4208 switch (c_parser_peek_token (parser)->keyword)
4209 {
4210 case RID_STATIC:
4211 case RID_UNSIGNED:
4212 case RID_LONG:
4213 case RID_CONST:
4214 case RID_EXTERN:
4215 case RID_REGISTER:
4216 case RID_TYPEDEF:
4217 case RID_SHORT:
4218 case RID_INLINE:
4219 case RID_NORETURN:
4220 case RID_VOLATILE:
4221 case RID_SIGNED:
4222 case RID_AUTO:
4223 case RID_RESTRICT:
4224 case RID_COMPLEX:
4225 case RID_THREAD:
4226 case RID_INT:
4227 case RID_CHAR:
4228 case RID_FLOAT:
4229 case RID_DOUBLE:
4230 case RID_VOID:
4231 case RID_DFLOAT32:
4232 case RID_DFLOAT64:
4233 case RID_DFLOAT128:
4234 CASE_RID_FLOATN_NX:
4235 case RID_BOOL:
4236 case RID_FRACT:
4237 case RID_ACCUM:
4238 case RID_SAT:
4239 case RID_TRANSACTION_ATOMIC:
4240 case RID_TRANSACTION_CANCEL:
4241 case RID_ATOMIC:
4242 case RID_AUTO_TYPE:
4243 case RID_INT_N_0:
4244 case RID_INT_N_1:
4245 case RID_INT_N_2:
4246 case RID_INT_N_3:
4247 ok = true;
4248 break;
4249 default:
4250 ok = false;
4251 break;
4252 }
4253 if (!ok)
4254 return NULL_TREE;
4255
4256 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4257 attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
4258 }
4259 else if (c_parser_next_token_is (parser, CPP_NAME))
4260 attr_name = c_parser_peek_token (parser)->value;
4261
4262 return attr_name;
4263}
4264
4265/* Parse (possibly empty) attributes. This is a GNU extension.
4266
4267 attributes:
4268 empty
4269 attributes attribute
4270
4271 attribute:
4272 __attribute__ ( ( attribute-list ) )
4273
4274 attribute-list:
4275 attrib
4276 attribute_list , attrib
4277
4278 attrib:
4279 empty
4280 any-word
4281 any-word ( identifier )
4282 any-word ( identifier , nonempty-expr-list )
4283 any-word ( expr-list )
4284
4285 where the "identifier" must not be declared as a type, and
4286 "any-word" may be any identifier (including one declared as a
4287 type), a reserved word storage class specifier, type specifier or
4288 type qualifier. ??? This still leaves out most reserved keywords
4289 (following the old parser), shouldn't we include them, and why not
4290 allow identifiers declared as types to start the arguments? */
4291
4292static tree
4293c_parser_attributes (c_parser *parser)
4294{
4295 tree attrs = NULL_TREE;
4296 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4297 {
4298 /* ??? Follow the C++ parser rather than using the
4299 lex_untranslated_string kludge. */
4300 parser->lex_untranslated_string = true;
4301 /* Consume the `__attribute__' keyword. */
4302 c_parser_consume_token (parser);
4303 /* Look for the two `(' tokens. */
4304 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4305 {
4306 parser->lex_untranslated_string = false;
4307 return attrs;
4308 }
4309 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4310 {
4311 parser->lex_untranslated_string = false;
4312 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4313 return attrs;
4314 }
4315 /* Parse the attribute list. */
4316 while (c_parser_next_token_is (parser, CPP_COMMA)
4317 || c_parser_next_token_is (parser, CPP_NAME)
4318 || c_parser_next_token_is (parser, CPP_KEYWORD))
4319 {
4320 tree attr, attr_name, attr_args;
4321 vec<tree, va_gc> *expr_list;
4322 if (c_parser_next_token_is (parser, CPP_COMMA))
4323 {
4324 c_parser_consume_token (parser);
4325 continue;
4326 }
4327
4328 attr_name = c_parser_attribute_any_word (parser);
4329 if (attr_name == NULL)
4330 break;
4331 attr_name = canonicalize_attr_name (attr_name);
4332 c_parser_consume_token (parser);
4333 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
4334 {
4335 attr = build_tree_list (attr_name, NULL_TREE);
4336 /* Add this attribute to the list. */
4337 attrs = chainon (attrs, attr);
4338 /* If the next token isn't a comma, we're done. */
4339 if (!c_parser_next_token_is (parser, CPP_COMMA))
4340 break;
4341 continue;
4342 }
4343 c_parser_consume_token (parser);
4344 /* Parse the attribute contents. If they start with an
4345 identifier which is followed by a comma or close
4346 parenthesis, then the arguments start with that
4347 identifier; otherwise they are an expression list.
4348 In objective-c the identifier may be a classname. */
4349 if (c_parser_next_token_is (parser, CPP_NAME)
4350 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4351 || (c_dialect_objc ()
4352 && c_parser_peek_token (parser)->id_kind
4353 == C_ID_CLASSNAME))
4354 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4355 || (c_parser_peek_2nd_token (parser)->type
4356 == CPP_CLOSE_PAREN))
4357 && (attribute_takes_identifier_p (attr_name)
4358 || (c_dialect_objc ()
4359 && c_parser_peek_token (parser)->id_kind
4360 == C_ID_CLASSNAME)))
4361 {
4362 tree arg1 = c_parser_peek_token (parser)->value;
4363 c_parser_consume_token (parser);
4364 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4365 attr_args = build_tree_list (NULL_TREE, arg1);
4366 else
4367 {
4368 tree tree_list;
4369 c_parser_consume_token (parser);
4370 expr_list = c_parser_expr_list (parser, false, true,
4371 NULL, NULL, NULL, NULL);
4372 tree_list = build_tree_list_vec (expr_list);
4373 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4374 release_tree_vector (expr_list);
4375 }
4376 }
4377 else
4378 {
4379 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4380 attr_args = NULL_TREE;
4381 else
4382 {
4383 expr_list = c_parser_expr_list (parser, false, true,
4384 NULL, NULL, NULL, NULL);
4385 attr_args = build_tree_list_vec (expr_list);
4386 release_tree_vector (expr_list);
4387 }
4388 }
4389
4390 attr = build_tree_list (attr_name, attr_args);
4391 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4392 c_parser_consume_token (parser);
4393 else
4394 {
4395 parser->lex_untranslated_string = false;
4396 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4397 "expected %<)%>");
4398 return attrs;
4399 }
4400 /* Add this attribute to the list. */
4401 attrs = chainon (attrs, attr);
4402 /* If the next token isn't a comma, we're done. */
4403 if (!c_parser_next_token_is (parser, CPP_COMMA))
4404 break;
4405 }
4406 /* Look for the two `)' tokens. */
4407 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4408 c_parser_consume_token (parser);
4409 else
4410 {
4411 parser->lex_untranslated_string = false;
4412 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4413 "expected %<)%>");
4414 return attrs;
4415 }
4416 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4417 c_parser_consume_token (parser);
4418 else
4419 {
4420 parser->lex_untranslated_string = false;
4421 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4422 "expected %<)%>");
4423 return attrs;
4424 }
4425 parser->lex_untranslated_string = false;
4426 }
4427
4428 return attrs;
4429}
4430
4431/* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4432 says whether alignment specifiers are OK (only in cases that might
4433 be the type name of a compound literal).
4434
4435 type-name:
4436 specifier-qualifier-list abstract-declarator[opt]
4437*/
4438
4439struct c_type_name *
4440c_parser_type_name (c_parser *parser, bool alignas_ok)
4441{
4442 struct c_declspecs *specs = build_null_declspecs ();
4443 struct c_declarator *declarator;
4444 struct c_type_name *ret;
4445 bool dummy = false;
4446 c_parser_declspecs (parser, specs, false, true, true, alignas_ok, false,
4447 cla_prefer_type);
4448 if (!specs->declspecs_seen_p)
4449 {
4450 c_parser_error (parser, "expected specifier-qualifier-list");
4451 return NULL;
4452 }
4453 if (specs->type != error_mark_node)
4454 {
4455 pending_xref_error ();
4456 finish_declspecs (specs);
4457 }
4458 declarator = c_parser_declarator (parser,
4459 specs->typespec_kind != ctsk_none,
4460 C_DTR_ABSTRACT, &dummy);
4461 if (declarator == NULL)
4462 return NULL;
4463 ret = XOBNEW (&parser_obstack, struct c_type_name);
4464 ret->specs = specs;
4465 ret->declarator = declarator;
4466 return ret;
4467}
4468
4469/* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4470
4471 initializer:
4472 assignment-expression
4473 { initializer-list }
4474 { initializer-list , }
4475
4476 initializer-list:
4477 designation[opt] initializer
4478 initializer-list , designation[opt] initializer
4479
4480 designation:
4481 designator-list =
4482
4483 designator-list:
4484 designator
4485 designator-list designator
4486
4487 designator:
4488 array-designator
4489 . identifier
4490
4491 array-designator:
4492 [ constant-expression ]
4493
4494 GNU extensions:
4495
4496 initializer:
4497 { }
4498
4499 designation:
4500 array-designator
4501 identifier :
4502
4503 array-designator:
4504 [ constant-expression ... constant-expression ]
4505
4506 Any expression without commas is accepted in the syntax for the
4507 constant-expressions, with non-constant expressions rejected later.
4508
4509 This function is only used for top-level initializers; for nested
4510 ones, see c_parser_initval. */
4511
4512static struct c_expr
4513c_parser_initializer (c_parser *parser)
4514{
4515 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4516 return c_parser_braced_init (parser, NULL_TREE, false, NULL);
4517 else
4518 {
4519 struct c_expr ret;
4520 location_t loc = c_parser_peek_token (parser)->location;
4521 ret = c_parser_expr_no_commas (parser, NULL);
4522 if (TREE_CODE (ret.value) != STRING_CST
4523 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4524 ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4525 return ret;
4526 }
4527}
4528
4529/* The location of the last comma within the current initializer list,
4530 or UNKNOWN_LOCATION if not within one. */
4531
4532location_t last_init_list_comma;
4533
4534/* Parse a braced initializer list. TYPE is the type specified for a
4535 compound literal, and NULL_TREE for other initializers and for
4536 nested braced lists. NESTED_P is true for nested braced lists,
4537 false for the list of a compound literal or the list that is the
4538 top-level initializer in a declaration. */
4539
4540static struct c_expr
4541c_parser_braced_init (c_parser *parser, tree type, bool nested_p,
4542 struct obstack *outer_obstack)
4543{
4544 struct c_expr ret;
4545 struct obstack braced_init_obstack;
4546 location_t brace_loc = c_parser_peek_token (parser)->location;
4547 gcc_obstack_init (&braced_init_obstack);
4548 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4549 matching_braces braces;
4550 braces.consume_open (parser);
4551 if (nested_p)
4552 {
4553 finish_implicit_inits (brace_loc, outer_obstack);
4554 push_init_level (brace_loc, 0, &braced_init_obstack);
4555 }
4556 else
4557 really_start_incremental_init (type);
4558 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4559 {
4560 pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4561 }
4562 else
4563 {
4564 /* Parse a non-empty initializer list, possibly with a trailing
4565 comma. */
4566 while (true)
4567 {
4568 c_parser_initelt (parser, &braced_init_obstack);
4569 if (parser->error)
4570 break;
4571 if (c_parser_next_token_is (parser, CPP_COMMA))
4572 {
4573 last_init_list_comma = c_parser_peek_token (parser)->location;
4574 c_parser_consume_token (parser);
4575 }
4576 else
4577 break;
4578 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4579 break;
4580 }
4581 }
4582 c_token *next_tok = c_parser_peek_token (parser);
4583 if (next_tok->type != CPP_CLOSE_BRACE)
4584 {
4585 ret.value = error_mark_node;
4586 ret.original_code = ERROR_MARK;
4587 ret.original_type = NULL;
4588 braces.skip_until_found_close (parser);
4589 pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma);
4590 obstack_free (&braced_init_obstack, NULL);
4591 return ret;
4592 }
4593 location_t close_loc = next_tok->location;
4594 c_parser_consume_token (parser);
4595 ret = pop_init_level (brace_loc, 0, &braced_init_obstack, close_loc);
4596 obstack_free (&braced_init_obstack, NULL);
4597 set_c_expr_source_range (&ret, brace_loc, close_loc);
4598 return ret;
4599}
4600
4601/* Parse a nested initializer, including designators. */
4602
4603static void
4604c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4605{
4606 /* Parse any designator or designator list. A single array
4607 designator may have the subsequent "=" omitted in GNU C, but a
4608 longer list or a structure member designator may not. */
4609 if (c_parser_next_token_is (parser, CPP_NAME)
4610 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4611 {
4612 /* Old-style structure member designator. */
4613 set_init_label (c_parser_peek_token (parser)->location,
4614 c_parser_peek_token (parser)->value,
4615 c_parser_peek_token (parser)->location,
4616 braced_init_obstack);
4617 /* Use the colon as the error location. */
4618 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4619 "obsolete use of designated initializer with %<:%>");
4620 c_parser_consume_token (parser);
4621 c_parser_consume_token (parser);
4622 }
4623 else
4624 {
4625 /* des_seen is 0 if there have been no designators, 1 if there
4626 has been a single array designator and 2 otherwise. */
4627 int des_seen = 0;
4628 /* Location of a designator. */
4629 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4630 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4631 || c_parser_next_token_is (parser, CPP_DOT))
4632 {
4633 int des_prev = des_seen;
4634 if (!des_seen)
4635 des_loc = c_parser_peek_token (parser)->location;
4636 if (des_seen < 2)
4637 des_seen++;
4638 if (c_parser_next_token_is (parser, CPP_DOT))
4639 {
4640 des_seen = 2;
4641 c_parser_consume_token (parser);
4642 if (c_parser_next_token_is (parser, CPP_NAME))
4643 {
4644 set_init_label (des_loc, c_parser_peek_token (parser)->value,
4645 c_parser_peek_token (parser)->location,
4646 braced_init_obstack);
4647 c_parser_consume_token (parser);
4648 }
4649 else
4650 {
4651 struct c_expr init;
4652 init.value = error_mark_node;
4653 init.original_code = ERROR_MARK;
4654 init.original_type = NULL;
4655 c_parser_error (parser, "expected identifier");
4656 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4657 process_init_element (input_location, init, false,
4658 braced_init_obstack);
4659 return;
4660