xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/c/c-parser.c (revision d909946ca08dceb44d7d0f22ec9488679695d976)
1 /* Parser for C and Objective-C.
2    Copyright (C) 1987-2013 Free Software Foundation, Inc.
3 
4    Parser actions based on the old Bison parser; structure somewhat
5    influenced by and fragments based on the C++ parser.
6 
7 This file is part of GCC.
8 
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13 
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22 
23 /* TODO:
24 
25    Make sure all relevant comments, and all relevant code from all
26    actions, brought over from old parser.  Verify exact correspondence
27    of syntax accepted.
28 
29    Add testcases covering every input symbol in every state in old and
30    new parsers.
31 
32    Include full syntax for GNU C, including erroneous cases accepted
33    with error messages, in syntax productions in comments.
34 
35    Make more diagnostics in the front end generally take an explicit
36    location rather than implicitly using input_location.  */
37 
38 #include "config.h"
39 #include "system.h"
40 #include "coretypes.h"
41 #include "tm.h"			/* For rtl.h: needs enum reg_class.  */
42 #include "tree.h"
43 #include "langhooks.h"
44 #include "input.h"
45 #include "cpplib.h"
46 #include "timevar.h"
47 #include "c-family/c-pragma.h"
48 #include "c-tree.h"
49 #include "flags.h"
50 #include "ggc.h"
51 #include "c-family/c-common.h"
52 #include "c-family/c-objc.h"
53 #include "vec.h"
54 #include "target.h"
55 #include "cgraph.h"
56 #include "plugin.h"
57 
58 
59 /* Initialization routine for this file.  */
60 
61 void
62 c_parse_init (void)
63 {
64   /* The only initialization required is of the reserved word
65      identifiers.  */
66   unsigned int i;
67   tree id;
68   int mask = 0;
69 
70   /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
71      the c_token structure.  */
72   gcc_assert (RID_MAX <= 255);
73 
74   mask |= D_CXXONLY;
75   if (!flag_isoc99)
76     mask |= D_C99;
77   if (flag_no_asm)
78     {
79       mask |= D_ASM | D_EXT;
80       if (!flag_isoc99)
81 	mask |= D_EXT89;
82     }
83   if (!c_dialect_objc ())
84     mask |= D_OBJC | D_CXX_OBJC;
85 
86   ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
87   for (i = 0; i < num_c_common_reswords; i++)
88     {
89       /* If a keyword is disabled, do not enter it into the table
90 	 and so create a canonical spelling that isn't a keyword.  */
91       if (c_common_reswords[i].disable & mask)
92 	{
93 	  if (warn_cxx_compat
94 	      && (c_common_reswords[i].disable & D_CXXWARN))
95 	    {
96 	      id = get_identifier (c_common_reswords[i].word);
97 	      C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
98 	      C_IS_RESERVED_WORD (id) = 1;
99 	    }
100 	  continue;
101 	}
102 
103       id = get_identifier (c_common_reswords[i].word);
104       C_SET_RID_CODE (id, c_common_reswords[i].rid);
105       C_IS_RESERVED_WORD (id) = 1;
106       ridpointers [(int) c_common_reswords[i].rid] = id;
107     }
108 }
109 
110 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
111    and the C parser.  Unlike the C++ lexer, the parser structure
112    stores the lexer information instead of using a separate structure.
113    Identifiers are separated into ordinary identifiers, type names,
114    keywords and some other Objective-C types of identifiers, and some
115    look-ahead is maintained.
116 
117    ??? It might be a good idea to lex the whole file up front (as for
118    C++).  It would then be possible to share more of the C and C++
119    lexer code, if desired.  */
120 
121 /* The following local token type is used.  */
122 
123 /* A keyword.  */
124 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
125 
126 /* More information about the type of a CPP_NAME token.  */
127 typedef enum c_id_kind {
128   /* An ordinary identifier.  */
129   C_ID_ID,
130   /* An identifier declared as a typedef name.  */
131   C_ID_TYPENAME,
132   /* An identifier declared as an Objective-C class name.  */
133   C_ID_CLASSNAME,
134   /* An address space identifier.  */
135   C_ID_ADDRSPACE,
136   /* Not an identifier.  */
137   C_ID_NONE
138 } c_id_kind;
139 
140 /* A single C token after string literal concatenation and conversion
141    of preprocessing tokens to tokens.  */
142 typedef struct GTY (()) c_token {
143   /* The kind of token.  */
144   ENUM_BITFIELD (cpp_ttype) type : 8;
145   /* If this token is a CPP_NAME, this value indicates whether also
146      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
147   ENUM_BITFIELD (c_id_kind) id_kind : 8;
148   /* If this token is a keyword, this value indicates which keyword.
149      Otherwise, this value is RID_MAX.  */
150   ENUM_BITFIELD (rid) keyword : 8;
151   /* If this token is a CPP_PRAGMA, this indicates the pragma that
152      was seen.  Otherwise it is PRAGMA_NONE.  */
153   ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
154   /* The location at which this token was found.  */
155   location_t location;
156   /* The value associated with this token, if any.  */
157   tree value;
158 } c_token;
159 
160 /* A parser structure recording information about the state and
161    context of parsing.  Includes lexer information with up to two
162    tokens of look-ahead; more are not needed for C.  */
163 typedef struct GTY(()) c_parser {
164   /* The look-ahead tokens.  */
165   c_token tokens[2];
166   /* How many look-ahead tokens are available (0, 1 or 2).  */
167   short tokens_avail;
168   /* True if a syntax error is being recovered from; false otherwise.
169      c_parser_error sets this flag.  It should clear this flag when
170      enough tokens have been consumed to recover from the error.  */
171   BOOL_BITFIELD error : 1;
172   /* True if we're processing a pragma, and shouldn't automatically
173      consume CPP_PRAGMA_EOL.  */
174   BOOL_BITFIELD in_pragma : 1;
175   /* True if we're parsing the outermost block of an if statement.  */
176   BOOL_BITFIELD in_if_block : 1;
177   /* True if we want to lex an untranslated string.  */
178   BOOL_BITFIELD lex_untranslated_string : 1;
179 
180   /* Objective-C specific parser/lexer information.  */
181 
182   /* True if we are in a context where the Objective-C "PQ" keywords
183      are considered keywords.  */
184   BOOL_BITFIELD objc_pq_context : 1;
185   /* True if we are parsing a (potential) Objective-C foreach
186      statement.  This is set to true after we parsed 'for (' and while
187      we wait for 'in' or ';' to decide if it's a standard C for loop or an
188      Objective-C foreach loop.  */
189   BOOL_BITFIELD objc_could_be_foreach_context : 1;
190   /* The following flag is needed to contextualize Objective-C lexical
191      analysis.  In some cases (e.g., 'int NSObject;'), it is
192      undesirable to bind an identifier to an Objective-C class, even
193      if a class with that name exists.  */
194   BOOL_BITFIELD objc_need_raw_identifier : 1;
195   /* Nonzero if we're processing a __transaction statement.  The value
196      is 1 | TM_STMT_ATTR_*.  */
197   unsigned int in_transaction : 4;
198   /* True if we are in a context where the Objective-C "Property attribute"
199      keywords are valid.  */
200   BOOL_BITFIELD objc_property_attr_context : 1;
201 } c_parser;
202 
203 
204 /* The actual parser and external interface.  ??? Does this need to be
205    garbage-collected?  */
206 
207 static GTY (()) c_parser *the_parser;
208 
209 /* Read in and lex a single token, storing it in *TOKEN.  */
210 
211 static void
212 c_lex_one_token (c_parser *parser, c_token *token)
213 {
214   timevar_push (TV_LEX);
215 
216   token->type = c_lex_with_flags (&token->value, &token->location, NULL,
217 				  (parser->lex_untranslated_string
218 				   ? C_LEX_STRING_NO_TRANSLATE : 0));
219   token->id_kind = C_ID_NONE;
220   token->keyword = RID_MAX;
221   token->pragma_kind = PRAGMA_NONE;
222 
223   switch (token->type)
224     {
225     case CPP_NAME:
226       {
227 	tree decl;
228 
229 	bool objc_force_identifier = parser->objc_need_raw_identifier;
230 	if (c_dialect_objc ())
231 	  parser->objc_need_raw_identifier = false;
232 
233 	if (C_IS_RESERVED_WORD (token->value))
234 	  {
235 	    enum rid rid_code = C_RID_CODE (token->value);
236 
237 	    if (rid_code == RID_CXX_COMPAT_WARN)
238 	      {
239 		warning_at (token->location,
240 			    OPT_Wc___compat,
241 			    "identifier %qE conflicts with C++ keyword",
242 			    token->value);
243 	      }
244 	    else if (rid_code >= RID_FIRST_ADDR_SPACE
245 		     && rid_code <= RID_LAST_ADDR_SPACE)
246 	      {
247 		token->id_kind = C_ID_ADDRSPACE;
248 		token->keyword = rid_code;
249 		break;
250 	      }
251 	    else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
252 	      {
253 		/* We found an Objective-C "pq" keyword (in, out,
254 		   inout, bycopy, byref, oneway).  They need special
255 		   care because the interpretation depends on the
256 		   context.  */
257 		if (parser->objc_pq_context)
258 		  {
259 		    token->type = CPP_KEYWORD;
260 		    token->keyword = rid_code;
261 		    break;
262 		  }
263 		else if (parser->objc_could_be_foreach_context
264 			 && rid_code == RID_IN)
265 		  {
266 		    /* We are in Objective-C, inside a (potential)
267 		       foreach context (which means after having
268 		       parsed 'for (', but before having parsed ';'),
269 		       and we found 'in'.  We consider it the keyword
270 		       which terminates the declaration at the
271 		       beginning of a foreach-statement.  Note that
272 		       this means you can't use 'in' for anything else
273 		       in that context; in particular, in Objective-C
274 		       you can't use 'in' as the name of the running
275 		       variable in a C for loop.  We could potentially
276 		       try to add code here to disambiguate, but it
277 		       seems a reasonable limitation.  */
278 		    token->type = CPP_KEYWORD;
279 		    token->keyword = rid_code;
280 		    break;
281 		  }
282 		/* Else, "pq" keywords outside of the "pq" context are
283 		   not keywords, and we fall through to the code for
284 		   normal tokens.  */
285 	      }
286 	    else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
287 	      {
288 		/* We found an Objective-C "property attribute"
289 		   keyword (getter, setter, readonly, etc). These are
290 		   only valid in the property context.  */
291 		if (parser->objc_property_attr_context)
292 		  {
293 		    token->type = CPP_KEYWORD;
294 		    token->keyword = rid_code;
295 		    break;
296 		  }
297 		/* Else they are not special keywords.
298 		*/
299 	      }
300 	    else if (c_dialect_objc ()
301 		     && (OBJC_IS_AT_KEYWORD (rid_code)
302 			 || OBJC_IS_CXX_KEYWORD (rid_code)))
303 	      {
304 		/* We found one of the Objective-C "@" keywords (defs,
305 		   selector, synchronized, etc) or one of the
306 		   Objective-C "cxx" keywords (class, private,
307 		   protected, public, try, catch, throw) without a
308 		   preceding '@' sign.  Do nothing and fall through to
309 		   the code for normal tokens (in C++ we would still
310 		   consider the CXX ones keywords, but not in C).  */
311 		;
312 	      }
313 	    else
314 	      {
315 		token->type = CPP_KEYWORD;
316 		token->keyword = rid_code;
317 		break;
318 	      }
319 	  }
320 
321 	decl = lookup_name (token->value);
322 	if (decl)
323 	  {
324 	    if (TREE_CODE (decl) == TYPE_DECL)
325 	      {
326 		token->id_kind = C_ID_TYPENAME;
327 		break;
328 	      }
329 	  }
330 	else if (c_dialect_objc ())
331 	  {
332 	    tree objc_interface_decl = objc_is_class_name (token->value);
333 	    /* Objective-C class names are in the same namespace as
334 	       variables and typedefs, and hence are shadowed by local
335 	       declarations.  */
336 	    if (objc_interface_decl
337                 && (!objc_force_identifier || global_bindings_p ()))
338 	      {
339 		token->value = objc_interface_decl;
340 		token->id_kind = C_ID_CLASSNAME;
341 		break;
342 	      }
343 	  }
344         token->id_kind = C_ID_ID;
345       }
346       break;
347     case CPP_AT_NAME:
348       /* This only happens in Objective-C; it must be a keyword.  */
349       token->type = CPP_KEYWORD;
350       switch (C_RID_CODE (token->value))
351 	{
352 	  /* Replace 'class' with '@class', 'private' with '@private',
353 	     etc.  This prevents confusion with the C++ keyword
354 	     'class', and makes the tokens consistent with other
355 	     Objective-C 'AT' keywords.  For example '@class' is
356 	     reported as RID_AT_CLASS which is consistent with
357 	     '@synchronized', which is reported as
358 	     RID_AT_SYNCHRONIZED.
359 	  */
360 	case RID_CLASS:     token->keyword = RID_AT_CLASS; break;
361 	case RID_PRIVATE:   token->keyword = RID_AT_PRIVATE; break;
362 	case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
363 	case RID_PUBLIC:    token->keyword = RID_AT_PUBLIC; break;
364 	case RID_THROW:     token->keyword = RID_AT_THROW; break;
365 	case RID_TRY:       token->keyword = RID_AT_TRY; break;
366 	case RID_CATCH:     token->keyword = RID_AT_CATCH; break;
367 	default:            token->keyword = C_RID_CODE (token->value);
368 	}
369       break;
370     case CPP_COLON:
371     case CPP_COMMA:
372     case CPP_CLOSE_PAREN:
373     case CPP_SEMICOLON:
374       /* These tokens may affect the interpretation of any identifiers
375 	 following, if doing Objective-C.  */
376       if (c_dialect_objc ())
377 	parser->objc_need_raw_identifier = false;
378       break;
379     case CPP_PRAGMA:
380       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
381       token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
382       token->value = NULL;
383       break;
384     default:
385       break;
386     }
387   timevar_pop (TV_LEX);
388 }
389 
390 /* Return a pointer to the next token from PARSER, reading it in if
391    necessary.  */
392 
393 static inline c_token *
394 c_parser_peek_token (c_parser *parser)
395 {
396   if (parser->tokens_avail == 0)
397     {
398       c_lex_one_token (parser, &parser->tokens[0]);
399       parser->tokens_avail = 1;
400     }
401   return &parser->tokens[0];
402 }
403 
404 /* Return true if the next token from PARSER has the indicated
405    TYPE.  */
406 
407 static inline bool
408 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
409 {
410   return c_parser_peek_token (parser)->type == type;
411 }
412 
413 /* Return true if the next token from PARSER does not have the
414    indicated TYPE.  */
415 
416 static inline bool
417 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
418 {
419   return !c_parser_next_token_is (parser, type);
420 }
421 
422 /* Return true if the next token from PARSER is the indicated
423    KEYWORD.  */
424 
425 static inline bool
426 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
427 {
428   return c_parser_peek_token (parser)->keyword == keyword;
429 }
430 
431 /* Return a pointer to the next-but-one token from PARSER, reading it
432    in if necessary.  The next token is already read in.  */
433 
434 static c_token *
435 c_parser_peek_2nd_token (c_parser *parser)
436 {
437   if (parser->tokens_avail >= 2)
438     return &parser->tokens[1];
439   gcc_assert (parser->tokens_avail == 1);
440   gcc_assert (parser->tokens[0].type != CPP_EOF);
441   gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
442   c_lex_one_token (parser, &parser->tokens[1]);
443   parser->tokens_avail = 2;
444   return &parser->tokens[1];
445 }
446 
447 /* Return true if TOKEN can start a type name,
448    false otherwise.  */
449 static bool
450 c_token_starts_typename (c_token *token)
451 {
452   switch (token->type)
453     {
454     case CPP_NAME:
455       switch (token->id_kind)
456 	{
457 	case C_ID_ID:
458 	  return false;
459 	case C_ID_ADDRSPACE:
460 	  return true;
461 	case C_ID_TYPENAME:
462 	  return true;
463 	case C_ID_CLASSNAME:
464 	  gcc_assert (c_dialect_objc ());
465 	  return true;
466 	default:
467 	  gcc_unreachable ();
468 	}
469     case CPP_KEYWORD:
470       switch (token->keyword)
471 	{
472 	case RID_UNSIGNED:
473 	case RID_LONG:
474 	case RID_INT128:
475 	case RID_SHORT:
476 	case RID_SIGNED:
477 	case RID_COMPLEX:
478 	case RID_INT:
479 	case RID_CHAR:
480 	case RID_FLOAT:
481 	case RID_DOUBLE:
482 	case RID_VOID:
483 	case RID_DFLOAT32:
484 	case RID_DFLOAT64:
485 	case RID_DFLOAT128:
486 	case RID_BOOL:
487 	case RID_ENUM:
488 	case RID_STRUCT:
489 	case RID_UNION:
490 	case RID_TYPEOF:
491 	case RID_CONST:
492 	case RID_VOLATILE:
493 	case RID_RESTRICT:
494 	case RID_ATTRIBUTE:
495 	case RID_FRACT:
496 	case RID_ACCUM:
497 	case RID_SAT:
498 	  return true;
499 	default:
500 	  return false;
501 	}
502     case CPP_LESS:
503       if (c_dialect_objc ())
504 	return true;
505       return false;
506     default:
507       return false;
508     }
509 }
510 
511 enum c_lookahead_kind {
512   /* Always treat unknown identifiers as typenames.  */
513   cla_prefer_type,
514 
515   /* Could be parsing a nonabstract declarator.  Only treat an identifier
516      as a typename if followed by another identifier or a star.  */
517   cla_nonabstract_decl,
518 
519   /* Never treat identifiers as typenames.  */
520   cla_prefer_id
521 };
522 
523 /* Return true if the next token from PARSER can start a type name,
524    false otherwise.  LA specifies how to do lookahead in order to
525    detect unknown type names.  If unsure, pick CLA_PREFER_ID.  */
526 
527 static inline bool
528 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
529 {
530   c_token *token = c_parser_peek_token (parser);
531   if (c_token_starts_typename (token))
532     return true;
533 
534   /* Try a bit harder to detect an unknown typename.  */
535   if (la != cla_prefer_id
536       && token->type == CPP_NAME
537       && token->id_kind == C_ID_ID
538 
539       /* Do not try too hard when we could have "object in array".  */
540       && !parser->objc_could_be_foreach_context
541 
542       && (la == cla_prefer_type
543 	  || c_parser_peek_2nd_token (parser)->type == CPP_NAME
544 	  || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
545 
546       /* Only unknown identifiers.  */
547       && !lookup_name (token->value))
548     return true;
549 
550   return false;
551 }
552 
553 /* Return true if TOKEN is a type qualifier, false otherwise.  */
554 static bool
555 c_token_is_qualifier (c_token *token)
556 {
557   switch (token->type)
558     {
559     case CPP_NAME:
560       switch (token->id_kind)
561 	{
562 	case C_ID_ADDRSPACE:
563 	  return true;
564 	default:
565 	  return false;
566 	}
567     case CPP_KEYWORD:
568       switch (token->keyword)
569 	{
570 	case RID_CONST:
571 	case RID_VOLATILE:
572 	case RID_RESTRICT:
573 	case RID_ATTRIBUTE:
574 	  return true;
575 	default:
576 	  return false;
577 	}
578     case CPP_LESS:
579       return false;
580     default:
581       gcc_unreachable ();
582     }
583 }
584 
585 /* Return true if the next token from PARSER is a type qualifier,
586    false otherwise.  */
587 static inline bool
588 c_parser_next_token_is_qualifier (c_parser *parser)
589 {
590   c_token *token = c_parser_peek_token (parser);
591   return c_token_is_qualifier (token);
592 }
593 
594 /* Return true if TOKEN can start declaration specifiers, false
595    otherwise.  */
596 static bool
597 c_token_starts_declspecs (c_token *token)
598 {
599   switch (token->type)
600     {
601     case CPP_NAME:
602       switch (token->id_kind)
603 	{
604 	case C_ID_ID:
605 	  return false;
606 	case C_ID_ADDRSPACE:
607 	  return true;
608 	case C_ID_TYPENAME:
609 	  return true;
610 	case C_ID_CLASSNAME:
611 	  gcc_assert (c_dialect_objc ());
612 	  return true;
613 	default:
614 	  gcc_unreachable ();
615 	}
616     case CPP_KEYWORD:
617       switch (token->keyword)
618 	{
619 	case RID_STATIC:
620 	case RID_EXTERN:
621 	case RID_REGISTER:
622 	case RID_TYPEDEF:
623 	case RID_INLINE:
624 	case RID_NORETURN:
625 	case RID_AUTO:
626 	case RID_THREAD:
627 	case RID_UNSIGNED:
628 	case RID_LONG:
629 	case RID_INT128:
630 	case RID_SHORT:
631 	case RID_SIGNED:
632 	case RID_COMPLEX:
633 	case RID_INT:
634 	case RID_CHAR:
635 	case RID_FLOAT:
636 	case RID_DOUBLE:
637 	case RID_VOID:
638 	case RID_DFLOAT32:
639 	case RID_DFLOAT64:
640 	case RID_DFLOAT128:
641 	case RID_BOOL:
642 	case RID_ENUM:
643 	case RID_STRUCT:
644 	case RID_UNION:
645 	case RID_TYPEOF:
646 	case RID_CONST:
647 	case RID_VOLATILE:
648 	case RID_RESTRICT:
649 	case RID_ATTRIBUTE:
650 	case RID_FRACT:
651 	case RID_ACCUM:
652 	case RID_SAT:
653 	case RID_ALIGNAS:
654 	  return true;
655 	default:
656 	  return false;
657 	}
658     case CPP_LESS:
659       if (c_dialect_objc ())
660 	return true;
661       return false;
662     default:
663       return false;
664     }
665 }
666 
667 
668 /* Return true if TOKEN can start declaration specifiers or a static
669    assertion, false otherwise.  */
670 static bool
671 c_token_starts_declaration (c_token *token)
672 {
673   if (c_token_starts_declspecs (token)
674       || token->keyword == RID_STATIC_ASSERT)
675     return true;
676   else
677     return false;
678 }
679 
680 /* Return true if the next token from PARSER can start declaration
681    specifiers, false otherwise.  */
682 static inline bool
683 c_parser_next_token_starts_declspecs (c_parser *parser)
684 {
685   c_token *token = c_parser_peek_token (parser);
686 
687   /* In Objective-C, a classname normally starts a declspecs unless it
688      is immediately followed by a dot.  In that case, it is the
689      Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
690      setter/getter on the class.  c_token_starts_declspecs() can't
691      differentiate between the two cases because it only checks the
692      current token, so we have a special check here.  */
693   if (c_dialect_objc ()
694       && token->type == CPP_NAME
695       && token->id_kind == C_ID_CLASSNAME
696       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
697     return false;
698 
699   return c_token_starts_declspecs (token);
700 }
701 
702 /* Return true if the next tokens from PARSER can start declaration
703    specifiers or a static assertion, false otherwise.  */
704 static inline bool
705 c_parser_next_tokens_start_declaration (c_parser *parser)
706 {
707   c_token *token = c_parser_peek_token (parser);
708 
709   /* Same as above.  */
710   if (c_dialect_objc ()
711       && token->type == CPP_NAME
712       && token->id_kind == C_ID_CLASSNAME
713       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
714     return false;
715 
716   /* Labels do not start declarations.  */
717   if (token->type == CPP_NAME
718       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
719     return false;
720 
721   if (c_token_starts_declaration (token))
722     return true;
723 
724   if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
725     return true;
726 
727   return false;
728 }
729 
730 /* Consume the next token from PARSER.  */
731 
732 static void
733 c_parser_consume_token (c_parser *parser)
734 {
735   gcc_assert (parser->tokens_avail >= 1);
736   gcc_assert (parser->tokens[0].type != CPP_EOF);
737   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
738   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
739   if (parser->tokens_avail == 2)
740     parser->tokens[0] = parser->tokens[1];
741   parser->tokens_avail--;
742 }
743 
744 /* Expect the current token to be a #pragma.  Consume it and remember
745    that we've begun parsing a pragma.  */
746 
747 static void
748 c_parser_consume_pragma (c_parser *parser)
749 {
750   gcc_assert (!parser->in_pragma);
751   gcc_assert (parser->tokens_avail >= 1);
752   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
753   if (parser->tokens_avail == 2)
754     parser->tokens[0] = parser->tokens[1];
755   parser->tokens_avail--;
756   parser->in_pragma = true;
757 }
758 
759 /* Update the globals input_location and in_system_header from
760    TOKEN.  */
761 static inline void
762 c_parser_set_source_position_from_token (c_token *token)
763 {
764   if (token->type != CPP_EOF)
765     {
766       input_location = token->location;
767     }
768 }
769 
770 /* Issue a diagnostic of the form
771       FILE:LINE: MESSAGE before TOKEN
772    where TOKEN is the next token in the input stream of PARSER.
773    MESSAGE (specified by the caller) is usually of the form "expected
774    OTHER-TOKEN".
775 
776    Do not issue a diagnostic if still recovering from an error.
777 
778    ??? This is taken from the C++ parser, but building up messages in
779    this way is not i18n-friendly and some other approach should be
780    used.  */
781 
782 static void
783 c_parser_error (c_parser *parser, const char *gmsgid)
784 {
785   c_token *token = c_parser_peek_token (parser);
786   if (parser->error)
787     return;
788   parser->error = true;
789   if (!gmsgid)
790     return;
791   /* This diagnostic makes more sense if it is tagged to the line of
792      the token we just peeked at.  */
793   c_parser_set_source_position_from_token (token);
794   c_parse_error (gmsgid,
795 		 /* Because c_parse_error does not understand
796 		    CPP_KEYWORD, keywords are treated like
797 		    identifiers.  */
798 		 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
799 		 /* ??? The C parser does not save the cpp flags of a
800 		    token, we need to pass 0 here and we will not get
801 		    the source spelling of some tokens but rather the
802 		    canonical spelling.  */
803 		 token->value, /*flags=*/0);
804 }
805 
806 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
807    issue the error MSGID.  If MSGID is NULL then a message has already
808    been produced and no message will be produced this time.  Returns
809    true if found, false otherwise.  */
810 
811 static bool
812 c_parser_require (c_parser *parser,
813 		  enum cpp_ttype type,
814 		  const char *msgid)
815 {
816   if (c_parser_next_token_is (parser, type))
817     {
818       c_parser_consume_token (parser);
819       return true;
820     }
821   else
822     {
823       c_parser_error (parser, msgid);
824       return false;
825     }
826 }
827 
828 /* If the next token is the indicated keyword, consume it.  Otherwise,
829    issue the error MSGID.  Returns true if found, false otherwise.  */
830 
831 static bool
832 c_parser_require_keyword (c_parser *parser,
833 			  enum rid keyword,
834 			  const char *msgid)
835 {
836   if (c_parser_next_token_is_keyword (parser, keyword))
837     {
838       c_parser_consume_token (parser);
839       return true;
840     }
841   else
842     {
843       c_parser_error (parser, msgid);
844       return false;
845     }
846 }
847 
848 /* Like c_parser_require, except that tokens will be skipped until the
849    desired token is found.  An error message is still produced if the
850    next token is not as expected.  If MSGID is NULL then a message has
851    already been produced and no message will be produced this
852    time.  */
853 
854 static void
855 c_parser_skip_until_found (c_parser *parser,
856 			   enum cpp_ttype type,
857 			   const char *msgid)
858 {
859   unsigned nesting_depth = 0;
860 
861   if (c_parser_require (parser, type, msgid))
862     return;
863 
864   /* Skip tokens until the desired token is found.  */
865   while (true)
866     {
867       /* Peek at the next token.  */
868       c_token *token = c_parser_peek_token (parser);
869       /* If we've reached the token we want, consume it and stop.  */
870       if (token->type == type && !nesting_depth)
871 	{
872 	  c_parser_consume_token (parser);
873 	  break;
874 	}
875 
876       /* If we've run out of tokens, stop.  */
877       if (token->type == CPP_EOF)
878 	return;
879       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
880 	return;
881       if (token->type == CPP_OPEN_BRACE
882 	  || token->type == CPP_OPEN_PAREN
883 	  || token->type == CPP_OPEN_SQUARE)
884 	++nesting_depth;
885       else if (token->type == CPP_CLOSE_BRACE
886 	       || token->type == CPP_CLOSE_PAREN
887 	       || token->type == CPP_CLOSE_SQUARE)
888 	{
889 	  if (nesting_depth-- == 0)
890 	    break;
891 	}
892       /* Consume this token.  */
893       c_parser_consume_token (parser);
894     }
895   parser->error = false;
896 }
897 
898 /* Skip tokens until the end of a parameter is found, but do not
899    consume the comma, semicolon or closing delimiter.  */
900 
901 static void
902 c_parser_skip_to_end_of_parameter (c_parser *parser)
903 {
904   unsigned nesting_depth = 0;
905 
906   while (true)
907     {
908       c_token *token = c_parser_peek_token (parser);
909       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
910 	  && !nesting_depth)
911 	break;
912       /* If we've run out of tokens, stop.  */
913       if (token->type == CPP_EOF)
914 	return;
915       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
916 	return;
917       if (token->type == CPP_OPEN_BRACE
918 	  || token->type == CPP_OPEN_PAREN
919 	  || token->type == CPP_OPEN_SQUARE)
920 	++nesting_depth;
921       else if (token->type == CPP_CLOSE_BRACE
922 	       || token->type == CPP_CLOSE_PAREN
923 	       || token->type == CPP_CLOSE_SQUARE)
924 	{
925 	  if (nesting_depth-- == 0)
926 	    break;
927 	}
928       /* Consume this token.  */
929       c_parser_consume_token (parser);
930     }
931   parser->error = false;
932 }
933 
934 /* Expect to be at the end of the pragma directive and consume an
935    end of line marker.  */
936 
937 static void
938 c_parser_skip_to_pragma_eol (c_parser *parser)
939 {
940   gcc_assert (parser->in_pragma);
941   parser->in_pragma = false;
942 
943   if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
944     while (true)
945       {
946 	c_token *token = c_parser_peek_token (parser);
947 	if (token->type == CPP_EOF)
948 	  break;
949 	if (token->type == CPP_PRAGMA_EOL)
950 	  {
951 	    c_parser_consume_token (parser);
952 	    break;
953 	  }
954 	c_parser_consume_token (parser);
955       }
956 
957   parser->error = false;
958 }
959 
960 /* Skip tokens until we have consumed an entire block, or until we
961    have consumed a non-nested ';'.  */
962 
963 static void
964 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
965 {
966   unsigned nesting_depth = 0;
967   bool save_error = parser->error;
968 
969   while (true)
970     {
971       c_token *token;
972 
973       /* Peek at the next token.  */
974       token = c_parser_peek_token (parser);
975 
976       switch (token->type)
977 	{
978 	case CPP_EOF:
979 	  return;
980 
981 	case CPP_PRAGMA_EOL:
982 	  if (parser->in_pragma)
983 	    return;
984 	  break;
985 
986 	case CPP_SEMICOLON:
987 	  /* If the next token is a ';', we have reached the
988 	     end of the statement.  */
989 	  if (!nesting_depth)
990 	    {
991 	      /* Consume the ';'.  */
992 	      c_parser_consume_token (parser);
993 	      goto finished;
994 	    }
995 	  break;
996 
997 	case CPP_CLOSE_BRACE:
998 	  /* If the next token is a non-nested '}', then we have
999 	     reached the end of the current block.  */
1000 	  if (nesting_depth == 0 || --nesting_depth == 0)
1001 	    {
1002 	      c_parser_consume_token (parser);
1003 	      goto finished;
1004 	    }
1005 	  break;
1006 
1007 	case CPP_OPEN_BRACE:
1008 	  /* If it the next token is a '{', then we are entering a new
1009 	     block.  Consume the entire block.  */
1010 	  ++nesting_depth;
1011 	  break;
1012 
1013 	case CPP_PRAGMA:
1014 	  /* If we see a pragma, consume the whole thing at once.  We
1015 	     have some safeguards against consuming pragmas willy-nilly.
1016 	     Normally, we'd expect to be here with parser->error set,
1017 	     which disables these safeguards.  But it's possible to get
1018 	     here for secondary error recovery, after parser->error has
1019 	     been cleared.  */
1020 	  c_parser_consume_pragma (parser);
1021 	  c_parser_skip_to_pragma_eol (parser);
1022 	  parser->error = save_error;
1023 	  continue;
1024 
1025 	default:
1026 	  break;
1027 	}
1028 
1029       c_parser_consume_token (parser);
1030     }
1031 
1032  finished:
1033   parser->error = false;
1034 }
1035 
1036 /* CPP's options (initialized by c-opts.c).  */
1037 extern cpp_options *cpp_opts;
1038 
1039 /* Save the warning flags which are controlled by __extension__.  */
1040 
1041 static inline int
1042 disable_extension_diagnostics (void)
1043 {
1044   int ret = (pedantic
1045 	     | (warn_pointer_arith << 1)
1046 	     | (warn_traditional << 2)
1047 	     | (flag_iso << 3)
1048 	     | (warn_long_long << 4)
1049 	     | (warn_cxx_compat << 5)
1050 	     | (warn_overlength_strings << 6));
1051   cpp_opts->cpp_pedantic = pedantic = 0;
1052   warn_pointer_arith = 0;
1053   cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1054   flag_iso = 0;
1055   cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1056   warn_cxx_compat = 0;
1057   warn_overlength_strings = 0;
1058   return ret;
1059 }
1060 
1061 /* Restore the warning flags which are controlled by __extension__.
1062    FLAGS is the return value from disable_extension_diagnostics.  */
1063 
1064 static inline void
1065 restore_extension_diagnostics (int flags)
1066 {
1067   cpp_opts->cpp_pedantic = pedantic = flags & 1;
1068   warn_pointer_arith = (flags >> 1) & 1;
1069   cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1070   flag_iso = (flags >> 3) & 1;
1071   cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1072   warn_cxx_compat = (flags >> 5) & 1;
1073   warn_overlength_strings = (flags >> 6) & 1;
1074 }
1075 
1076 /* Possibly kinds of declarator to parse.  */
1077 typedef enum c_dtr_syn {
1078   /* A normal declarator with an identifier.  */
1079   C_DTR_NORMAL,
1080   /* An abstract declarator (maybe empty).  */
1081   C_DTR_ABSTRACT,
1082   /* A parameter declarator: may be either, but after a type name does
1083      not redeclare a typedef name as an identifier if it can
1084      alternatively be interpreted as a typedef name; see DR#009,
1085      applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1086      following DR#249.  For example, given a typedef T, "int T" and
1087      "int *T" are valid parameter declarations redeclaring T, while
1088      "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1089      abstract declarators rather than involving redundant parentheses;
1090      the same applies with attributes inside the parentheses before
1091      "T".  */
1092   C_DTR_PARM
1093 } c_dtr_syn;
1094 
1095 /* The binary operation precedence levels, where 0 is a dummy lowest level
1096    used for the bottom of the stack.  */
1097 enum c_parser_prec {
1098   PREC_NONE,
1099   PREC_LOGOR,
1100   PREC_LOGAND,
1101   PREC_BITOR,
1102   PREC_BITXOR,
1103   PREC_BITAND,
1104   PREC_EQ,
1105   PREC_REL,
1106   PREC_SHIFT,
1107   PREC_ADD,
1108   PREC_MULT,
1109   NUM_PRECS
1110 };
1111 
1112 static void c_parser_external_declaration (c_parser *);
1113 static void c_parser_asm_definition (c_parser *);
1114 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1115 					   bool, bool, tree *);
1116 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1117 static void c_parser_static_assert_declaration (c_parser *);
1118 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1119 				bool, enum c_lookahead_kind);
1120 static struct c_typespec c_parser_enum_specifier (c_parser *);
1121 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1122 static tree c_parser_struct_declaration (c_parser *);
1123 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1124 static tree c_parser_alignas_specifier (c_parser *);
1125 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1126 						 bool *);
1127 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1128 							c_dtr_syn, bool *);
1129 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1130 							      bool,
1131 							      struct c_declarator *);
1132 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1133 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1134 							  tree);
1135 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1136 static tree c_parser_simple_asm_expr (c_parser *);
1137 static tree c_parser_attributes (c_parser *);
1138 static struct c_type_name *c_parser_type_name (c_parser *);
1139 static struct c_expr c_parser_initializer (c_parser *);
1140 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1141 static void c_parser_initelt (c_parser *, struct obstack *);
1142 static void c_parser_initval (c_parser *, struct c_expr *,
1143 			      struct obstack *);
1144 static tree c_parser_compound_statement (c_parser *);
1145 static void c_parser_compound_statement_nostart (c_parser *);
1146 static void c_parser_label (c_parser *);
1147 static void c_parser_statement (c_parser *);
1148 static void c_parser_statement_after_labels (c_parser *);
1149 static void c_parser_if_statement (c_parser *);
1150 static void c_parser_switch_statement (c_parser *);
1151 static void c_parser_while_statement (c_parser *);
1152 static void c_parser_do_statement (c_parser *);
1153 static void c_parser_for_statement (c_parser *);
1154 static tree c_parser_asm_statement (c_parser *);
1155 static tree c_parser_asm_operands (c_parser *);
1156 static tree c_parser_asm_goto_operands (c_parser *);
1157 static tree c_parser_asm_clobbers (c_parser *);
1158 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1159 static struct c_expr c_parser_conditional_expression (c_parser *,
1160 						      struct c_expr *);
1161 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1162 						 enum c_parser_prec);
1163 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1164 static struct c_expr c_parser_unary_expression (c_parser *);
1165 static struct c_expr c_parser_sizeof_expression (c_parser *);
1166 static struct c_expr c_parser_alignof_expression (c_parser *);
1167 static struct c_expr c_parser_postfix_expression (c_parser *);
1168 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1169 								   struct c_type_name *,
1170 								   location_t);
1171 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1172 								location_t loc,
1173 								struct c_expr);
1174 static tree c_parser_transaction (c_parser *, enum rid);
1175 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1176 static tree c_parser_transaction_cancel (c_parser *);
1177 static struct c_expr c_parser_expression (c_parser *);
1178 static struct c_expr c_parser_expression_conv (c_parser *);
1179 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1180 					     vec<tree, va_gc> **, location_t *,
1181 					     tree *);
1182 static void c_parser_omp_construct (c_parser *);
1183 static void c_parser_omp_threadprivate (c_parser *);
1184 static void c_parser_omp_barrier (c_parser *);
1185 static void c_parser_omp_flush (c_parser *);
1186 static void c_parser_omp_taskwait (c_parser *);
1187 static void c_parser_omp_taskyield (c_parser *);
1188 
1189 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1190 static bool c_parser_pragma (c_parser *, enum pragma_context);
1191 
1192 /* These Objective-C parser functions are only ever called when
1193    compiling Objective-C.  */
1194 static void c_parser_objc_class_definition (c_parser *, tree);
1195 static void c_parser_objc_class_instance_variables (c_parser *);
1196 static void c_parser_objc_class_declaration (c_parser *);
1197 static void c_parser_objc_alias_declaration (c_parser *);
1198 static void c_parser_objc_protocol_definition (c_parser *, tree);
1199 static bool c_parser_objc_method_type (c_parser *);
1200 static void c_parser_objc_method_definition (c_parser *);
1201 static void c_parser_objc_methodprotolist (c_parser *);
1202 static void c_parser_objc_methodproto (c_parser *);
1203 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1204 static tree c_parser_objc_type_name (c_parser *);
1205 static tree c_parser_objc_protocol_refs (c_parser *);
1206 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1207 static void c_parser_objc_synchronized_statement (c_parser *);
1208 static tree c_parser_objc_selector (c_parser *);
1209 static tree c_parser_objc_selector_arg (c_parser *);
1210 static tree c_parser_objc_receiver (c_parser *);
1211 static tree c_parser_objc_message_args (c_parser *);
1212 static tree c_parser_objc_keywordexpr (c_parser *);
1213 static void c_parser_objc_at_property_declaration (c_parser *);
1214 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1215 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1216 static bool c_parser_objc_diagnose_bad_element_prefix
1217   (c_parser *, struct c_declspecs *);
1218 
1219 /* Parse a translation unit (C90 6.7, C99 6.9).
1220 
1221    translation-unit:
1222      external-declarations
1223 
1224    external-declarations:
1225      external-declaration
1226      external-declarations external-declaration
1227 
1228    GNU extensions:
1229 
1230    translation-unit:
1231      empty
1232 */
1233 
1234 static void
1235 c_parser_translation_unit (c_parser *parser)
1236 {
1237   if (c_parser_next_token_is (parser, CPP_EOF))
1238     {
1239       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1240 	       "ISO C forbids an empty translation unit");
1241     }
1242   else
1243     {
1244       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1245       mark_valid_location_for_stdc_pragma (false);
1246       do
1247 	{
1248 	  ggc_collect ();
1249 	  c_parser_external_declaration (parser);
1250 	  obstack_free (&parser_obstack, obstack_position);
1251 	}
1252       while (c_parser_next_token_is_not (parser, CPP_EOF));
1253     }
1254 }
1255 
1256 /* Parse an external declaration (C90 6.7, C99 6.9).
1257 
1258    external-declaration:
1259      function-definition
1260      declaration
1261 
1262    GNU extensions:
1263 
1264    external-declaration:
1265      asm-definition
1266      ;
1267      __extension__ external-declaration
1268 
1269    Objective-C:
1270 
1271    external-declaration:
1272      objc-class-definition
1273      objc-class-declaration
1274      objc-alias-declaration
1275      objc-protocol-definition
1276      objc-method-definition
1277      @end
1278 */
1279 
1280 static void
1281 c_parser_external_declaration (c_parser *parser)
1282 {
1283   int ext;
1284   switch (c_parser_peek_token (parser)->type)
1285     {
1286     case CPP_KEYWORD:
1287       switch (c_parser_peek_token (parser)->keyword)
1288 	{
1289 	case RID_EXTENSION:
1290 	  ext = disable_extension_diagnostics ();
1291 	  c_parser_consume_token (parser);
1292 	  c_parser_external_declaration (parser);
1293 	  restore_extension_diagnostics (ext);
1294 	  break;
1295 	case RID_ASM:
1296 	  c_parser_asm_definition (parser);
1297 	  break;
1298 	case RID_AT_INTERFACE:
1299 	case RID_AT_IMPLEMENTATION:
1300 	  gcc_assert (c_dialect_objc ());
1301 	  c_parser_objc_class_definition (parser, NULL_TREE);
1302 	  break;
1303 	case RID_AT_CLASS:
1304 	  gcc_assert (c_dialect_objc ());
1305 	  c_parser_objc_class_declaration (parser);
1306 	  break;
1307 	case RID_AT_ALIAS:
1308 	  gcc_assert (c_dialect_objc ());
1309 	  c_parser_objc_alias_declaration (parser);
1310 	  break;
1311 	case RID_AT_PROTOCOL:
1312 	  gcc_assert (c_dialect_objc ());
1313 	  c_parser_objc_protocol_definition (parser, NULL_TREE);
1314 	  break;
1315 	case RID_AT_PROPERTY:
1316 	  gcc_assert (c_dialect_objc ());
1317 	  c_parser_objc_at_property_declaration (parser);
1318 	  break;
1319 	case RID_AT_SYNTHESIZE:
1320 	  gcc_assert (c_dialect_objc ());
1321 	  c_parser_objc_at_synthesize_declaration (parser);
1322 	  break;
1323 	case RID_AT_DYNAMIC:
1324 	  gcc_assert (c_dialect_objc ());
1325 	  c_parser_objc_at_dynamic_declaration (parser);
1326 	  break;
1327 	case RID_AT_END:
1328 	  gcc_assert (c_dialect_objc ());
1329 	  c_parser_consume_token (parser);
1330 	  objc_finish_implementation ();
1331 	  break;
1332 	default:
1333 	  goto decl_or_fndef;
1334 	}
1335       break;
1336     case CPP_SEMICOLON:
1337       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1338 	       "ISO C does not allow extra %<;%> outside of a function");
1339       c_parser_consume_token (parser);
1340       break;
1341     case CPP_PRAGMA:
1342       mark_valid_location_for_stdc_pragma (true);
1343       c_parser_pragma (parser, pragma_external);
1344       mark_valid_location_for_stdc_pragma (false);
1345       break;
1346     case CPP_PLUS:
1347     case CPP_MINUS:
1348       if (c_dialect_objc ())
1349 	{
1350 	  c_parser_objc_method_definition (parser);
1351 	  break;
1352 	}
1353       /* Else fall through, and yield a syntax error trying to parse
1354 	 as a declaration or function definition.  */
1355     default:
1356     decl_or_fndef:
1357       /* A declaration or a function definition (or, in Objective-C,
1358 	 an @interface or @protocol with prefix attributes).  We can
1359 	 only tell which after parsing the declaration specifiers, if
1360 	 any, and the first declarator.  */
1361       c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1362       break;
1363     }
1364 }
1365 
1366 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1367    6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
1368    accepted; otherwise (old-style parameter declarations) only other
1369    declarations are accepted.  If STATIC_ASSERT_OK is true, a static
1370    assertion is accepted; otherwise (old-style parameter declarations)
1371    it is not.  If NESTED is true, we are inside a function or parsing
1372    old-style parameter declarations; any functions encountered are
1373    nested functions and declaration specifiers are required; otherwise
1374    we are at top level and functions are normal functions and
1375    declaration specifiers may be optional.  If EMPTY_OK is true, empty
1376    declarations are OK (subject to all other constraints); otherwise
1377    (old-style parameter declarations) they are diagnosed.  If
1378    START_ATTR_OK is true, the declaration specifiers may start with
1379    attributes; otherwise they may not.
1380    OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1381    declaration when parsing an Objective-C foreach statement.
1382 
1383    declaration:
1384      declaration-specifiers init-declarator-list[opt] ;
1385      static_assert-declaration
1386 
1387    function-definition:
1388      declaration-specifiers[opt] declarator declaration-list[opt]
1389        compound-statement
1390 
1391    declaration-list:
1392      declaration
1393      declaration-list declaration
1394 
1395    init-declarator-list:
1396      init-declarator
1397      init-declarator-list , init-declarator
1398 
1399    init-declarator:
1400      declarator simple-asm-expr[opt] attributes[opt]
1401      declarator simple-asm-expr[opt] attributes[opt] = initializer
1402 
1403    GNU extensions:
1404 
1405    nested-function-definition:
1406      declaration-specifiers declarator declaration-list[opt]
1407        compound-statement
1408 
1409    Objective-C:
1410      attributes objc-class-definition
1411      attributes objc-category-definition
1412      attributes objc-protocol-definition
1413 
1414    The simple-asm-expr and attributes are GNU extensions.
1415 
1416    This function does not handle __extension__; that is handled in its
1417    callers.  ??? Following the old parser, __extension__ may start
1418    external declarations, declarations in functions and declarations
1419    at the start of "for" loops, but not old-style parameter
1420    declarations.
1421 
1422    C99 requires declaration specifiers in a function definition; the
1423    absence is diagnosed through the diagnosis of implicit int.  In GNU
1424    C we also allow but diagnose declarations without declaration
1425    specifiers, but only at top level (elsewhere they conflict with
1426    other syntax).
1427 
1428    In Objective-C, declarations of the looping variable in a foreach
1429    statement are exceptionally terminated by 'in' (for example, 'for
1430    (NSObject *object in array) { ... }').
1431 
1432    OpenMP:
1433 
1434    declaration:
1435      threadprivate-directive  */
1436 
1437 static void
1438 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1439 			       bool static_assert_ok, bool empty_ok,
1440 			       bool nested, bool start_attr_ok,
1441 			       tree *objc_foreach_object_declaration)
1442 {
1443   struct c_declspecs *specs;
1444   tree prefix_attrs;
1445   tree all_prefix_attrs;
1446   bool diagnosed_no_specs = false;
1447   location_t here = c_parser_peek_token (parser)->location;
1448 
1449   if (static_assert_ok
1450       && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1451     {
1452       c_parser_static_assert_declaration (parser);
1453       return;
1454     }
1455   specs = build_null_declspecs ();
1456 
1457   /* Try to detect an unknown type name when we have "A B" or "A *B".  */
1458   if (c_parser_peek_token (parser)->type == CPP_NAME
1459       && c_parser_peek_token (parser)->id_kind == C_ID_ID
1460       && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1461           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1462       && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1463     {
1464       error_at (here, "unknown type name %qE",
1465                 c_parser_peek_token (parser)->value);
1466 
1467       /* Parse declspecs normally to get a correct pointer type, but avoid
1468          a further "fails to be a type name" error.  Refuse nested functions
1469          since it is not how the user likely wants us to recover.  */
1470       c_parser_peek_token (parser)->type = CPP_KEYWORD;
1471       c_parser_peek_token (parser)->keyword = RID_VOID;
1472       c_parser_peek_token (parser)->value = error_mark_node;
1473       fndef_ok = !nested;
1474     }
1475 
1476   c_parser_declspecs (parser, specs, true, true, start_attr_ok, cla_nonabstract_decl);
1477   if (parser->error)
1478     {
1479       c_parser_skip_to_end_of_block_or_statement (parser);
1480       return;
1481     }
1482   if (nested && !specs->declspecs_seen_p)
1483     {
1484       c_parser_error (parser, "expected declaration specifiers");
1485       c_parser_skip_to_end_of_block_or_statement (parser);
1486       return;
1487     }
1488   finish_declspecs (specs);
1489   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1490     {
1491       if (empty_ok)
1492 	shadow_tag (specs);
1493       else
1494 	{
1495 	  shadow_tag_warned (specs, 1);
1496 	  pedwarn (here, 0, "empty declaration");
1497 	}
1498       c_parser_consume_token (parser);
1499       return;
1500     }
1501 
1502   /* Provide better error recovery.  Note that a type name here is usually
1503      better diagnosed as a redeclaration.  */
1504   if (empty_ok
1505       && specs->typespec_kind == ctsk_tagdef
1506       && c_parser_next_token_starts_declspecs (parser)
1507       && !c_parser_next_token_is (parser, CPP_NAME))
1508     {
1509       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1510       parser->error = false;
1511       shadow_tag_warned (specs, 1);
1512       return;
1513     }
1514   else if (c_dialect_objc ())
1515     {
1516       /* Prefix attributes are an error on method decls.  */
1517       switch (c_parser_peek_token (parser)->type)
1518 	{
1519 	  case CPP_PLUS:
1520 	  case CPP_MINUS:
1521 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1522 	      return;
1523 	    if (specs->attrs)
1524 	      {
1525 		warning_at (c_parser_peek_token (parser)->location,
1526 			    OPT_Wattributes,
1527 	       		    "prefix attributes are ignored for methods");
1528 		specs->attrs = NULL_TREE;
1529 	      }
1530 	    if (fndef_ok)
1531 	      c_parser_objc_method_definition (parser);
1532 	    else
1533 	      c_parser_objc_methodproto (parser);
1534 	    return;
1535 	    break;
1536 	  default:
1537 	    break;
1538 	}
1539       /* This is where we parse 'attributes @interface ...',
1540 	 'attributes @implementation ...', 'attributes @protocol ...'
1541 	 (where attributes could be, for example, __attribute__
1542 	 ((deprecated)).
1543       */
1544       switch (c_parser_peek_token (parser)->keyword)
1545 	{
1546 	case RID_AT_INTERFACE:
1547 	  {
1548 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1549 	      return;
1550 	    c_parser_objc_class_definition (parser, specs->attrs);
1551 	    return;
1552 	  }
1553 	  break;
1554 	case RID_AT_IMPLEMENTATION:
1555 	  {
1556 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1557 	      return;
1558 	    if (specs->attrs)
1559 	      {
1560 		warning_at (c_parser_peek_token (parser)->location,
1561 			OPT_Wattributes,
1562 			"prefix attributes are ignored for implementations");
1563 		specs->attrs = NULL_TREE;
1564 	      }
1565 	    c_parser_objc_class_definition (parser, NULL_TREE);
1566 	    return;
1567 	  }
1568 	  break;
1569 	case RID_AT_PROTOCOL:
1570 	  {
1571 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1572 	      return;
1573 	    c_parser_objc_protocol_definition (parser, specs->attrs);
1574 	    return;
1575 	  }
1576 	  break;
1577 	case RID_AT_ALIAS:
1578 	case RID_AT_CLASS:
1579 	case RID_AT_END:
1580 	case RID_AT_PROPERTY:
1581 	  if (specs->attrs)
1582 	    {
1583 	      c_parser_error (parser, "unexpected attribute");
1584 	      specs->attrs = NULL;
1585 	    }
1586 	  break;
1587 	default:
1588 	  break;
1589 	}
1590     }
1591 
1592   pending_xref_error ();
1593   prefix_attrs = specs->attrs;
1594   all_prefix_attrs = prefix_attrs;
1595   specs->attrs = NULL_TREE;
1596   while (true)
1597     {
1598       struct c_declarator *declarator;
1599       bool dummy = false;
1600       timevar_id_t tv;
1601       tree fnbody;
1602       /* Declaring either one or more declarators (in which case we
1603 	 should diagnose if there were no declaration specifiers) or a
1604 	 function definition (in which case the diagnostic for
1605 	 implicit int suffices).  */
1606       declarator = c_parser_declarator (parser,
1607 					specs->typespec_kind != ctsk_none,
1608 					C_DTR_NORMAL, &dummy);
1609       if (declarator == NULL)
1610 	{
1611 	  c_parser_skip_to_end_of_block_or_statement (parser);
1612 	  return;
1613 	}
1614       if (c_parser_next_token_is (parser, CPP_EQ)
1615 	  || c_parser_next_token_is (parser, CPP_COMMA)
1616 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
1617 	  || c_parser_next_token_is_keyword (parser, RID_ASM)
1618 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1619 	  || c_parser_next_token_is_keyword (parser, RID_IN))
1620 	{
1621 	  tree asm_name = NULL_TREE;
1622 	  tree postfix_attrs = NULL_TREE;
1623 	  if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1624 	    {
1625 	      diagnosed_no_specs = true;
1626 	      pedwarn (here, 0, "data definition has no type or storage class");
1627 	    }
1628 	  /* Having seen a data definition, there cannot now be a
1629 	     function definition.  */
1630 	  fndef_ok = false;
1631 	  if (c_parser_next_token_is_keyword (parser, RID_ASM))
1632 	    asm_name = c_parser_simple_asm_expr (parser);
1633 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1634 	    postfix_attrs = c_parser_attributes (parser);
1635 	  if (c_parser_next_token_is (parser, CPP_EQ))
1636 	    {
1637 	      tree d;
1638 	      struct c_expr init;
1639 	      location_t init_loc;
1640 	      c_parser_consume_token (parser);
1641 	      /* The declaration of the variable is in effect while
1642 		 its initializer is parsed.  */
1643 	      d = start_decl (declarator, specs, true,
1644 			      chainon (postfix_attrs, all_prefix_attrs));
1645 	      if (!d)
1646 		d = error_mark_node;
1647 	      start_init (d, asm_name, global_bindings_p ());
1648 	      init_loc = c_parser_peek_token (parser)->location;
1649 	      init = c_parser_initializer (parser);
1650 	      finish_init ();
1651 	      if (d != error_mark_node)
1652 		{
1653 		  maybe_warn_string_init (TREE_TYPE (d), init);
1654 		  finish_decl (d, init_loc, init.value,
1655 		      	       init.original_type, asm_name);
1656 		}
1657 	    }
1658 	  else
1659 	    {
1660 	      tree d = start_decl (declarator, specs, false,
1661 				   chainon (postfix_attrs,
1662 					    all_prefix_attrs));
1663 	      if (d)
1664 		finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1665 			     NULL_TREE, asm_name);
1666 
1667 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
1668 		{
1669 		  if (d)
1670 		    *objc_foreach_object_declaration = d;
1671 		  else
1672 		    *objc_foreach_object_declaration = error_mark_node;
1673 		}
1674 	    }
1675 	  if (c_parser_next_token_is (parser, CPP_COMMA))
1676 	    {
1677 	      c_parser_consume_token (parser);
1678 	      if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1679 		all_prefix_attrs = chainon (c_parser_attributes (parser),
1680 					    prefix_attrs);
1681 	      else
1682 		all_prefix_attrs = prefix_attrs;
1683 	      continue;
1684 	    }
1685 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1686 	    {
1687 	      c_parser_consume_token (parser);
1688 	      return;
1689 	    }
1690 	  else if (c_parser_next_token_is_keyword (parser, RID_IN))
1691 	    {
1692 	      /* This can only happen in Objective-C: we found the
1693 		 'in' that terminates the declaration inside an
1694 		 Objective-C foreach statement.  Do not consume the
1695 		 token, so that the caller can use it to determine
1696 		 that this indeed is a foreach context.  */
1697 	      return;
1698 	    }
1699 	  else
1700 	    {
1701 	      c_parser_error (parser, "expected %<,%> or %<;%>");
1702 	      c_parser_skip_to_end_of_block_or_statement (parser);
1703 	      return;
1704 	    }
1705 	}
1706       else if (!fndef_ok)
1707 	{
1708 	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1709 			  "%<asm%> or %<__attribute__%>");
1710 	  c_parser_skip_to_end_of_block_or_statement (parser);
1711 	  return;
1712 	}
1713       /* Function definition (nested or otherwise).  */
1714       if (nested)
1715 	{
1716 	  pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
1717 	  c_push_function_context ();
1718 	}
1719       if (!start_function (specs, declarator, all_prefix_attrs))
1720 	{
1721 	  /* This can appear in many cases looking nothing like a
1722 	     function definition, so we don't give a more specific
1723 	     error suggesting there was one.  */
1724 	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1725 			  "or %<__attribute__%>");
1726 	  if (nested)
1727 	    c_pop_function_context ();
1728 	  break;
1729 	}
1730 
1731       if (DECL_DECLARED_INLINE_P (current_function_decl))
1732         tv = TV_PARSE_INLINE;
1733       else
1734         tv = TV_PARSE_FUNC;
1735       timevar_push (tv);
1736 
1737       /* Parse old-style parameter declarations.  ??? Attributes are
1738 	 not allowed to start declaration specifiers here because of a
1739 	 syntax conflict between a function declaration with attribute
1740 	 suffix and a function definition with an attribute prefix on
1741 	 first old-style parameter declaration.  Following the old
1742 	 parser, they are not accepted on subsequent old-style
1743 	 parameter declarations either.  However, there is no
1744 	 ambiguity after the first declaration, nor indeed on the
1745 	 first as long as we don't allow postfix attributes after a
1746 	 declarator with a nonempty identifier list in a definition;
1747 	 and postfix attributes have never been accepted here in
1748 	 function definitions either.  */
1749       while (c_parser_next_token_is_not (parser, CPP_EOF)
1750 	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1751 	c_parser_declaration_or_fndef (parser, false, false, false,
1752 				       true, false, NULL);
1753       store_parm_decls ();
1754       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1755 	= c_parser_peek_token (parser)->location;
1756       fnbody = c_parser_compound_statement (parser);
1757       if (nested)
1758 	{
1759 	  tree decl = current_function_decl;
1760 	  /* Mark nested functions as needing static-chain initially.
1761 	     lower_nested_functions will recompute it but the
1762 	     DECL_STATIC_CHAIN flag is also used before that happens,
1763 	     by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
1764 	  DECL_STATIC_CHAIN (decl) = 1;
1765 	  add_stmt (fnbody);
1766 	  finish_function ();
1767 	  c_pop_function_context ();
1768 	  add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1769 	}
1770       else
1771 	{
1772 	  add_stmt (fnbody);
1773 	  finish_function ();
1774 	}
1775 
1776       timevar_pop (tv);
1777       break;
1778     }
1779 }
1780 
1781 /* Parse an asm-definition (asm() outside a function body).  This is a
1782    GNU extension.
1783 
1784    asm-definition:
1785      simple-asm-expr ;
1786 */
1787 
1788 static void
1789 c_parser_asm_definition (c_parser *parser)
1790 {
1791   tree asm_str = c_parser_simple_asm_expr (parser);
1792   if (asm_str)
1793     add_asm_node (asm_str);
1794   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1795 }
1796 
1797 /* Parse a static assertion (C11 6.7.10).
1798 
1799    static_assert-declaration:
1800      static_assert-declaration-no-semi ;
1801 */
1802 
1803 static void
1804 c_parser_static_assert_declaration (c_parser *parser)
1805 {
1806   c_parser_static_assert_declaration_no_semi (parser);
1807   if (parser->error
1808       || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1809     c_parser_skip_to_end_of_block_or_statement (parser);
1810 }
1811 
1812 /* Parse a static assertion (C11 6.7.10), without the trailing
1813    semicolon.
1814 
1815    static_assert-declaration-no-semi:
1816      _Static_assert ( constant-expression , string-literal )
1817 */
1818 
1819 static void
1820 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1821 {
1822   location_t assert_loc, value_loc;
1823   tree value;
1824   tree string;
1825 
1826   gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1827   assert_loc = c_parser_peek_token (parser)->location;
1828   if (!flag_isoc11)
1829     {
1830       if (flag_isoc99)
1831 	pedwarn (assert_loc, OPT_Wpedantic,
1832 		 "ISO C99 does not support %<_Static_assert%>");
1833       else
1834 	pedwarn (assert_loc, OPT_Wpedantic,
1835 		 "ISO C90 does not support %<_Static_assert%>");
1836     }
1837   c_parser_consume_token (parser);
1838   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1839     return;
1840   value_loc = c_parser_peek_token (parser)->location;
1841   value = c_parser_expr_no_commas (parser, NULL).value;
1842   parser->lex_untranslated_string = true;
1843   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1844     {
1845       parser->lex_untranslated_string = false;
1846       return;
1847     }
1848   switch (c_parser_peek_token (parser)->type)
1849     {
1850     case CPP_STRING:
1851     case CPP_STRING16:
1852     case CPP_STRING32:
1853     case CPP_WSTRING:
1854     case CPP_UTF8STRING:
1855       string = c_parser_peek_token (parser)->value;
1856       c_parser_consume_token (parser);
1857       parser->lex_untranslated_string = false;
1858       break;
1859     default:
1860       c_parser_error (parser, "expected string literal");
1861       parser->lex_untranslated_string = false;
1862       return;
1863     }
1864   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1865 
1866   if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1867     {
1868       error_at (value_loc, "expression in static assertion is not an integer");
1869       return;
1870     }
1871   if (TREE_CODE (value) != INTEGER_CST)
1872     {
1873       value = c_fully_fold (value, false, NULL);
1874       if (TREE_CODE (value) == INTEGER_CST)
1875 	pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
1876 		 "is not an integer constant expression");
1877     }
1878   if (TREE_CODE (value) != INTEGER_CST)
1879     {
1880       error_at (value_loc, "expression in static assertion is not constant");
1881       return;
1882     }
1883   constant_expression_warning (value);
1884   if (integer_zerop (value))
1885     error_at (assert_loc, "static assertion failed: %E", string);
1886 }
1887 
1888 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1889    6.7), adding them to SPECS (which may already include some).
1890    Storage class specifiers are accepted iff SCSPEC_OK; type
1891    specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1892    the start iff START_ATTR_OK.
1893 
1894    declaration-specifiers:
1895      storage-class-specifier declaration-specifiers[opt]
1896      type-specifier declaration-specifiers[opt]
1897      type-qualifier declaration-specifiers[opt]
1898      function-specifier declaration-specifiers[opt]
1899      alignment-specifier declaration-specifiers[opt]
1900 
1901    Function specifiers (inline) are from C99, and are currently
1902    handled as storage class specifiers, as is __thread.  Alignment
1903    specifiers are from C11.
1904 
1905    C90 6.5.1, C99 6.7.1:
1906    storage-class-specifier:
1907      typedef
1908      extern
1909      static
1910      auto
1911      register
1912 
1913    C99 6.7.4:
1914    function-specifier:
1915      inline
1916      _Noreturn
1917 
1918    (_Noreturn is new in C11.)
1919 
1920    C90 6.5.2, C99 6.7.2:
1921    type-specifier:
1922      void
1923      char
1924      short
1925      int
1926      long
1927      float
1928      double
1929      signed
1930      unsigned
1931      _Bool
1932      _Complex
1933      [_Imaginary removed in C99 TC2]
1934      struct-or-union-specifier
1935      enum-specifier
1936      typedef-name
1937 
1938    (_Bool and _Complex are new in C99.)
1939 
1940    C90 6.5.3, C99 6.7.3:
1941 
1942    type-qualifier:
1943      const
1944      restrict
1945      volatile
1946      address-space-qualifier
1947 
1948    (restrict is new in C99.)
1949 
1950    GNU extensions:
1951 
1952    declaration-specifiers:
1953      attributes declaration-specifiers[opt]
1954 
1955    type-qualifier:
1956      address-space
1957 
1958    address-space:
1959      identifier recognized by the target
1960 
1961    storage-class-specifier:
1962      __thread
1963 
1964    type-specifier:
1965      typeof-specifier
1966      __int128
1967      _Decimal32
1968      _Decimal64
1969      _Decimal128
1970      _Fract
1971      _Accum
1972      _Sat
1973 
1974   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1975    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1976 
1977    Objective-C:
1978 
1979    type-specifier:
1980      class-name objc-protocol-refs[opt]
1981      typedef-name objc-protocol-refs
1982      objc-protocol-refs
1983 */
1984 
1985 static void
1986 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1987 		    bool scspec_ok, bool typespec_ok, bool start_attr_ok,
1988 		    enum c_lookahead_kind la)
1989 {
1990   bool attrs_ok = start_attr_ok;
1991   bool seen_type = specs->typespec_kind != ctsk_none;
1992 
1993   if (!typespec_ok)
1994     gcc_assert (la == cla_prefer_id);
1995 
1996   while (c_parser_next_token_is (parser, CPP_NAME)
1997 	 || c_parser_next_token_is (parser, CPP_KEYWORD)
1998 	 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1999     {
2000       struct c_typespec t;
2001       tree attrs;
2002       tree align;
2003       location_t loc = c_parser_peek_token (parser)->location;
2004 
2005       /* If we cannot accept a type, exit if the next token must start
2006 	 one.  Also, if we already have seen a tagged definition,
2007 	 a typename would be an error anyway and likely the user
2008 	 has simply forgotten a semicolon, so we exit.  */
2009       if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2010 	  && c_parser_next_tokens_start_typename (parser, la)
2011 	  && !c_parser_next_token_is_qualifier (parser))
2012 	break;
2013 
2014       if (c_parser_next_token_is (parser, CPP_NAME))
2015 	{
2016 	  c_token *name_token = c_parser_peek_token (parser);
2017 	  tree value = name_token->value;
2018 	  c_id_kind kind = name_token->id_kind;
2019 
2020 	  if (kind == C_ID_ADDRSPACE)
2021 	    {
2022 	      addr_space_t as
2023 		= name_token->keyword - RID_FIRST_ADDR_SPACE;
2024 	      declspecs_add_addrspace (name_token->location, specs, as);
2025 	      c_parser_consume_token (parser);
2026 	      attrs_ok = true;
2027 	      continue;
2028 	    }
2029 
2030 	  gcc_assert (!c_parser_next_token_is_qualifier (parser));
2031 
2032 	  /* If we cannot accept a type, and the next token must start one,
2033 	     exit.  Do the same if we already have seen a tagged definition,
2034 	     since it would be an error anyway and likely the user has simply
2035 	     forgotten a semicolon.  */
2036 	  if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2037 	    break;
2038 
2039 	  /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2040 	     a C_ID_CLASSNAME.  */
2041 	  c_parser_consume_token (parser);
2042 	  seen_type = true;
2043 	  attrs_ok = true;
2044 	  if (kind == C_ID_ID)
2045 	    {
2046 	      error ("unknown type name %qE", value);
2047 	      t.kind = ctsk_typedef;
2048 	      t.spec = error_mark_node;
2049 	    }
2050 	  else if (kind == C_ID_TYPENAME
2051 	           && (!c_dialect_objc ()
2052 	               || c_parser_next_token_is_not (parser, CPP_LESS)))
2053 	    {
2054 	      t.kind = ctsk_typedef;
2055 	      /* For a typedef name, record the meaning, not the name.
2056 		 In case of 'foo foo, bar;'.  */
2057 	      t.spec = lookup_name (value);
2058 	    }
2059 	  else
2060 	    {
2061 	      tree proto = NULL_TREE;
2062 	      gcc_assert (c_dialect_objc ());
2063 	      t.kind = ctsk_objc;
2064 	      if (c_parser_next_token_is (parser, CPP_LESS))
2065 		proto = c_parser_objc_protocol_refs (parser);
2066 	      t.spec = objc_get_protocol_qualified_type (value, proto);
2067 	    }
2068 	  t.expr = NULL_TREE;
2069 	  t.expr_const_operands = true;
2070 	  declspecs_add_type (name_token->location, specs, t);
2071 	  continue;
2072 	}
2073       if (c_parser_next_token_is (parser, CPP_LESS))
2074 	{
2075 	  /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2076 	     nisse@lysator.liu.se.  */
2077 	  tree proto;
2078 	  gcc_assert (c_dialect_objc ());
2079 	  if (!typespec_ok || seen_type)
2080 	    break;
2081 	  proto = c_parser_objc_protocol_refs (parser);
2082 	  t.kind = ctsk_objc;
2083 	  t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2084 	  t.expr = NULL_TREE;
2085 	  t.expr_const_operands = true;
2086 	  declspecs_add_type (loc, specs, t);
2087 	  continue;
2088 	}
2089       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2090       switch (c_parser_peek_token (parser)->keyword)
2091 	{
2092 	case RID_STATIC:
2093 	case RID_EXTERN:
2094 	case RID_REGISTER:
2095 	case RID_TYPEDEF:
2096 	case RID_INLINE:
2097 	case RID_NORETURN:
2098 	case RID_AUTO:
2099 	case RID_THREAD:
2100 	  if (!scspec_ok)
2101 	    goto out;
2102 	  attrs_ok = true;
2103 	  /* TODO: Distinguish between function specifiers (inline, noreturn)
2104 	     and storage class specifiers, either here or in
2105 	     declspecs_add_scspec.  */
2106 	  declspecs_add_scspec (loc, specs,
2107 				c_parser_peek_token (parser)->value);
2108 	  c_parser_consume_token (parser);
2109 	  break;
2110 	case RID_UNSIGNED:
2111 	case RID_LONG:
2112 	case RID_INT128:
2113 	case RID_SHORT:
2114 	case RID_SIGNED:
2115 	case RID_COMPLEX:
2116 	case RID_INT:
2117 	case RID_CHAR:
2118 	case RID_FLOAT:
2119 	case RID_DOUBLE:
2120 	case RID_VOID:
2121 	case RID_DFLOAT32:
2122 	case RID_DFLOAT64:
2123 	case RID_DFLOAT128:
2124 	case RID_BOOL:
2125 	case RID_FRACT:
2126 	case RID_ACCUM:
2127 	case RID_SAT:
2128 	  if (!typespec_ok)
2129 	    goto out;
2130 	  attrs_ok = true;
2131 	  seen_type = true;
2132 	  if (c_dialect_objc ())
2133 	    parser->objc_need_raw_identifier = true;
2134 	  t.kind = ctsk_resword;
2135 	  t.spec = c_parser_peek_token (parser)->value;
2136 	  t.expr = NULL_TREE;
2137 	  t.expr_const_operands = true;
2138 	  declspecs_add_type (loc, specs, t);
2139 	  c_parser_consume_token (parser);
2140 	  break;
2141 	case RID_ENUM:
2142 	  if (!typespec_ok)
2143 	    goto out;
2144 	  attrs_ok = true;
2145 	  seen_type = true;
2146 	  t = c_parser_enum_specifier (parser);
2147 	  declspecs_add_type (loc, specs, t);
2148 	  break;
2149 	case RID_STRUCT:
2150 	case RID_UNION:
2151 	  if (!typespec_ok)
2152 	    goto out;
2153 	  attrs_ok = true;
2154 	  seen_type = true;
2155 	  t = c_parser_struct_or_union_specifier (parser);
2156           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2157 	  declspecs_add_type (loc, specs, t);
2158 	  break;
2159 	case RID_TYPEOF:
2160 	  /* ??? The old parser rejected typeof after other type
2161 	     specifiers, but is a syntax error the best way of
2162 	     handling this?  */
2163 	  if (!typespec_ok || seen_type)
2164 	    goto out;
2165 	  attrs_ok = true;
2166 	  seen_type = true;
2167 	  t = c_parser_typeof_specifier (parser);
2168 	  declspecs_add_type (loc, specs, t);
2169 	  break;
2170 	case RID_CONST:
2171 	case RID_VOLATILE:
2172 	case RID_RESTRICT:
2173 	  attrs_ok = true;
2174 	  declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2175 	  c_parser_consume_token (parser);
2176 	  break;
2177 	case RID_ATTRIBUTE:
2178 	  if (!attrs_ok)
2179 	    goto out;
2180 	  attrs = c_parser_attributes (parser);
2181 	  declspecs_add_attrs (loc, specs, attrs);
2182 	  break;
2183 	case RID_ALIGNAS:
2184 	  align = c_parser_alignas_specifier (parser);
2185 	  declspecs_add_alignas (loc, specs, align);
2186 	  break;
2187 	default:
2188 	  goto out;
2189 	}
2190     }
2191  out: ;
2192 }
2193 
2194 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2195 
2196    enum-specifier:
2197      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2198      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2199      enum attributes[opt] identifier
2200 
2201    The form with trailing comma is new in C99.  The forms with
2202    attributes are GNU extensions.  In GNU C, we accept any expression
2203    without commas in the syntax (assignment expressions, not just
2204    conditional expressions); assignment expressions will be diagnosed
2205    as non-constant.
2206 
2207    enumerator-list:
2208      enumerator
2209      enumerator-list , enumerator
2210 
2211    enumerator:
2212      enumeration-constant
2213      enumeration-constant = constant-expression
2214 */
2215 
2216 static struct c_typespec
2217 c_parser_enum_specifier (c_parser *parser)
2218 {
2219   struct c_typespec ret;
2220   tree attrs;
2221   tree ident = NULL_TREE;
2222   location_t enum_loc;
2223   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2224   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2225   enum_loc = c_parser_peek_token (parser)->location;
2226   c_parser_consume_token (parser);
2227   attrs = c_parser_attributes (parser);
2228   enum_loc = c_parser_peek_token (parser)->location;
2229   /* Set the location in case we create a decl now.  */
2230   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2231   if (c_parser_next_token_is (parser, CPP_NAME))
2232     {
2233       ident = c_parser_peek_token (parser)->value;
2234       ident_loc = c_parser_peek_token (parser)->location;
2235       enum_loc = ident_loc;
2236       c_parser_consume_token (parser);
2237     }
2238   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2239     {
2240       /* Parse an enum definition.  */
2241       struct c_enum_contents the_enum;
2242       tree type;
2243       tree postfix_attrs;
2244       /* We chain the enumerators in reverse order, then put them in
2245 	 forward order at the end.  */
2246       tree values;
2247       timevar_push (TV_PARSE_ENUM);
2248       type = start_enum (enum_loc, &the_enum, ident);
2249       values = NULL_TREE;
2250       c_parser_consume_token (parser);
2251       while (true)
2252 	{
2253 	  tree enum_id;
2254 	  tree enum_value;
2255 	  tree enum_decl;
2256 	  bool seen_comma;
2257 	  c_token *token;
2258 	  location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2259 	  location_t decl_loc, value_loc;
2260 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
2261 	    {
2262 	      c_parser_error (parser, "expected identifier");
2263 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2264 	      values = error_mark_node;
2265 	      break;
2266 	    }
2267 	  token = c_parser_peek_token (parser);
2268 	  enum_id = token->value;
2269 	  /* Set the location in case we create a decl now.  */
2270 	  c_parser_set_source_position_from_token (token);
2271 	  decl_loc = value_loc = token->location;
2272 	  c_parser_consume_token (parser);
2273 	  if (c_parser_next_token_is (parser, CPP_EQ))
2274 	    {
2275 	      c_parser_consume_token (parser);
2276 	      value_loc = c_parser_peek_token (parser)->location;
2277 	      enum_value = c_parser_expr_no_commas (parser, NULL).value;
2278 	    }
2279 	  else
2280 	    enum_value = NULL_TREE;
2281 	  enum_decl = build_enumerator (decl_loc, value_loc,
2282 	      				&the_enum, enum_id, enum_value);
2283 	  TREE_CHAIN (enum_decl) = values;
2284 	  values = enum_decl;
2285 	  seen_comma = false;
2286 	  if (c_parser_next_token_is (parser, CPP_COMMA))
2287 	    {
2288 	      comma_loc = c_parser_peek_token (parser)->location;
2289 	      seen_comma = true;
2290 	      c_parser_consume_token (parser);
2291 	    }
2292 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2293 	    {
2294 	      if (seen_comma && !flag_isoc99)
2295 		pedwarn (comma_loc, OPT_Wpedantic, "comma at end of enumerator list");
2296 	      c_parser_consume_token (parser);
2297 	      break;
2298 	    }
2299 	  if (!seen_comma)
2300 	    {
2301 	      c_parser_error (parser, "expected %<,%> or %<}%>");
2302 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2303 	      values = error_mark_node;
2304 	      break;
2305 	    }
2306 	}
2307       postfix_attrs = c_parser_attributes (parser);
2308       ret.spec = finish_enum (type, nreverse (values),
2309 			      chainon (attrs, postfix_attrs));
2310       ret.kind = ctsk_tagdef;
2311       ret.expr = NULL_TREE;
2312       ret.expr_const_operands = true;
2313       timevar_pop (TV_PARSE_ENUM);
2314       return ret;
2315     }
2316   else if (!ident)
2317     {
2318       c_parser_error (parser, "expected %<{%>");
2319       ret.spec = error_mark_node;
2320       ret.kind = ctsk_tagref;
2321       ret.expr = NULL_TREE;
2322       ret.expr_const_operands = true;
2323       return ret;
2324     }
2325   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2326   /* In ISO C, enumerated types can be referred to only if already
2327      defined.  */
2328   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2329     {
2330       gcc_assert (ident);
2331       pedwarn (enum_loc, OPT_Wpedantic,
2332 	       "ISO C forbids forward references to %<enum%> types");
2333     }
2334   return ret;
2335 }
2336 
2337 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2338 
2339    struct-or-union-specifier:
2340      struct-or-union attributes[opt] identifier[opt]
2341        { struct-contents } attributes[opt]
2342      struct-or-union attributes[opt] identifier
2343 
2344    struct-contents:
2345      struct-declaration-list
2346 
2347    struct-declaration-list:
2348      struct-declaration ;
2349      struct-declaration-list struct-declaration ;
2350 
2351    GNU extensions:
2352 
2353    struct-contents:
2354      empty
2355      struct-declaration
2356      struct-declaration-list struct-declaration
2357 
2358    struct-declaration-list:
2359      struct-declaration-list ;
2360      ;
2361 
2362    (Note that in the syntax here, unlike that in ISO C, the semicolons
2363    are included here rather than in struct-declaration, in order to
2364    describe the syntax with extra semicolons and missing semicolon at
2365    end.)
2366 
2367    Objective-C:
2368 
2369    struct-declaration-list:
2370      @defs ( class-name )
2371 
2372    (Note this does not include a trailing semicolon, but can be
2373    followed by further declarations, and gets a pedwarn-if-pedantic
2374    when followed by a semicolon.)  */
2375 
2376 static struct c_typespec
2377 c_parser_struct_or_union_specifier (c_parser *parser)
2378 {
2379   struct c_typespec ret;
2380   tree attrs;
2381   tree ident = NULL_TREE;
2382   location_t struct_loc;
2383   location_t ident_loc = UNKNOWN_LOCATION;
2384   enum tree_code code;
2385   switch (c_parser_peek_token (parser)->keyword)
2386     {
2387     case RID_STRUCT:
2388       code = RECORD_TYPE;
2389       break;
2390     case RID_UNION:
2391       code = UNION_TYPE;
2392       break;
2393     default:
2394       gcc_unreachable ();
2395     }
2396   struct_loc = c_parser_peek_token (parser)->location;
2397   c_parser_consume_token (parser);
2398   attrs = c_parser_attributes (parser);
2399 
2400   /* Set the location in case we create a decl now.  */
2401   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2402 
2403   if (c_parser_next_token_is (parser, CPP_NAME))
2404     {
2405       ident = c_parser_peek_token (parser)->value;
2406       ident_loc = c_parser_peek_token (parser)->location;
2407       struct_loc = ident_loc;
2408       c_parser_consume_token (parser);
2409     }
2410   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2411     {
2412       /* Parse a struct or union definition.  Start the scope of the
2413 	 tag before parsing components.  */
2414       struct c_struct_parse_info *struct_info;
2415       tree type = start_struct (struct_loc, code, ident, &struct_info);
2416       tree postfix_attrs;
2417       /* We chain the components in reverse order, then put them in
2418 	 forward order at the end.  Each struct-declaration may
2419 	 declare multiple components (comma-separated), so we must use
2420 	 chainon to join them, although when parsing each
2421 	 struct-declaration we can use TREE_CHAIN directly.
2422 
2423 	 The theory behind all this is that there will be more
2424 	 semicolon separated fields than comma separated fields, and
2425 	 so we'll be minimizing the number of node traversals required
2426 	 by chainon.  */
2427       tree contents;
2428       timevar_push (TV_PARSE_STRUCT);
2429       contents = NULL_TREE;
2430       c_parser_consume_token (parser);
2431       /* Handle the Objective-C @defs construct,
2432 	 e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
2433       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2434 	{
2435 	  tree name;
2436 	  gcc_assert (c_dialect_objc ());
2437 	  c_parser_consume_token (parser);
2438 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2439 	    goto end_at_defs;
2440 	  if (c_parser_next_token_is (parser, CPP_NAME)
2441 	      && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2442 	    {
2443 	      name = c_parser_peek_token (parser)->value;
2444 	      c_parser_consume_token (parser);
2445 	    }
2446 	  else
2447 	    {
2448 	      c_parser_error (parser, "expected class name");
2449 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2450 	      goto end_at_defs;
2451 	    }
2452 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2453 				     "expected %<)%>");
2454 	  contents = nreverse (objc_get_class_ivars (name));
2455 	}
2456     end_at_defs:
2457       /* Parse the struct-declarations and semicolons.  Problems with
2458 	 semicolons are diagnosed here; empty structures are diagnosed
2459 	 elsewhere.  */
2460       while (true)
2461 	{
2462 	  tree decls;
2463 	  /* Parse any stray semicolon.  */
2464 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2465 	    {
2466 	      pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2467 		       "extra semicolon in struct or union specified");
2468 	      c_parser_consume_token (parser);
2469 	      continue;
2470 	    }
2471 	  /* Stop if at the end of the struct or union contents.  */
2472 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2473 	    {
2474 	      c_parser_consume_token (parser);
2475 	      break;
2476 	    }
2477 	  /* Accept #pragmas at struct scope.  */
2478 	  if (c_parser_next_token_is (parser, CPP_PRAGMA))
2479 	    {
2480 	      c_parser_pragma (parser, pragma_external);
2481 	      continue;
2482 	    }
2483 	  /* Parse some comma-separated declarations, but not the
2484 	     trailing semicolon if any.  */
2485 	  decls = c_parser_struct_declaration (parser);
2486 	  contents = chainon (decls, contents);
2487 	  /* If no semicolon follows, either we have a parse error or
2488 	     are at the end of the struct or union and should
2489 	     pedwarn.  */
2490 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2491 	    c_parser_consume_token (parser);
2492 	  else
2493 	    {
2494 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2495 		pedwarn (c_parser_peek_token (parser)->location, 0,
2496 			 "no semicolon at end of struct or union");
2497 	      else if (parser->error
2498 		       || !c_parser_next_token_starts_declspecs (parser))
2499 		{
2500 		  c_parser_error (parser, "expected %<;%>");
2501 		  c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2502 		  break;
2503 		}
2504 
2505 	      /* If we come here, we have already emitted an error
2506 		 for an expected `;', identifier or `(', and we also
2507 	         recovered already.  Go on with the next field. */
2508 	    }
2509 	}
2510       postfix_attrs = c_parser_attributes (parser);
2511       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2512 				chainon (attrs, postfix_attrs), struct_info);
2513       ret.kind = ctsk_tagdef;
2514       ret.expr = NULL_TREE;
2515       ret.expr_const_operands = true;
2516       timevar_pop (TV_PARSE_STRUCT);
2517       return ret;
2518     }
2519   else if (!ident)
2520     {
2521       c_parser_error (parser, "expected %<{%>");
2522       ret.spec = error_mark_node;
2523       ret.kind = ctsk_tagref;
2524       ret.expr = NULL_TREE;
2525       ret.expr_const_operands = true;
2526       return ret;
2527     }
2528   ret = parser_xref_tag (ident_loc, code, ident);
2529   return ret;
2530 }
2531 
2532 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2533    the trailing semicolon.
2534 
2535    struct-declaration:
2536      specifier-qualifier-list struct-declarator-list
2537      static_assert-declaration-no-semi
2538 
2539    specifier-qualifier-list:
2540      type-specifier specifier-qualifier-list[opt]
2541      type-qualifier specifier-qualifier-list[opt]
2542      attributes specifier-qualifier-list[opt]
2543 
2544    struct-declarator-list:
2545      struct-declarator
2546      struct-declarator-list , attributes[opt] struct-declarator
2547 
2548    struct-declarator:
2549      declarator attributes[opt]
2550      declarator[opt] : constant-expression attributes[opt]
2551 
2552    GNU extensions:
2553 
2554    struct-declaration:
2555      __extension__ struct-declaration
2556      specifier-qualifier-list
2557 
2558    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
2559    of attributes where shown is a GNU extension.  In GNU C, we accept
2560    any expression without commas in the syntax (assignment
2561    expressions, not just conditional expressions); assignment
2562    expressions will be diagnosed as non-constant.  */
2563 
2564 static tree
2565 c_parser_struct_declaration (c_parser *parser)
2566 {
2567   struct c_declspecs *specs;
2568   tree prefix_attrs;
2569   tree all_prefix_attrs;
2570   tree decls;
2571   location_t decl_loc;
2572   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2573     {
2574       int ext;
2575       tree decl;
2576       ext = disable_extension_diagnostics ();
2577       c_parser_consume_token (parser);
2578       decl = c_parser_struct_declaration (parser);
2579       restore_extension_diagnostics (ext);
2580       return decl;
2581     }
2582   if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2583     {
2584       c_parser_static_assert_declaration_no_semi (parser);
2585       return NULL_TREE;
2586     }
2587   specs = build_null_declspecs ();
2588   decl_loc = c_parser_peek_token (parser)->location;
2589   c_parser_declspecs (parser, specs, false, true, true, cla_nonabstract_decl);
2590   if (parser->error)
2591     return NULL_TREE;
2592   if (!specs->declspecs_seen_p)
2593     {
2594       c_parser_error (parser, "expected specifier-qualifier-list");
2595       return NULL_TREE;
2596     }
2597   finish_declspecs (specs);
2598   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2599       || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2600     {
2601       tree ret;
2602       if (specs->typespec_kind == ctsk_none)
2603 	{
2604 	  pedwarn (decl_loc, OPT_Wpedantic,
2605 		   "ISO C forbids member declarations with no members");
2606 	  shadow_tag_warned (specs, pedantic);
2607 	  ret = NULL_TREE;
2608 	}
2609       else
2610 	{
2611 	  /* Support for unnamed structs or unions as members of
2612 	     structs or unions (which is [a] useful and [b] supports
2613 	     MS P-SDK).  */
2614 	  tree attrs = NULL;
2615 
2616 	  ret = grokfield (c_parser_peek_token (parser)->location,
2617 			   build_id_declarator (NULL_TREE), specs,
2618 			   NULL_TREE, &attrs);
2619 	  if (ret)
2620 	    decl_attributes (&ret, attrs, 0);
2621 	}
2622       return ret;
2623     }
2624 
2625   /* Provide better error recovery.  Note that a type name here is valid,
2626      and will be treated as a field name.  */
2627   if (specs->typespec_kind == ctsk_tagdef
2628       && TREE_CODE (specs->type) != ENUMERAL_TYPE
2629       && c_parser_next_token_starts_declspecs (parser)
2630       && !c_parser_next_token_is (parser, CPP_NAME))
2631     {
2632       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2633       parser->error = false;
2634       return NULL_TREE;
2635     }
2636 
2637   pending_xref_error ();
2638   prefix_attrs = specs->attrs;
2639   all_prefix_attrs = prefix_attrs;
2640   specs->attrs = NULL_TREE;
2641   decls = NULL_TREE;
2642   while (true)
2643     {
2644       /* Declaring one or more declarators or un-named bit-fields.  */
2645       struct c_declarator *declarator;
2646       bool dummy = false;
2647       if (c_parser_next_token_is (parser, CPP_COLON))
2648 	declarator = build_id_declarator (NULL_TREE);
2649       else
2650 	declarator = c_parser_declarator (parser,
2651 					  specs->typespec_kind != ctsk_none,
2652 					  C_DTR_NORMAL, &dummy);
2653       if (declarator == NULL)
2654 	{
2655 	  c_parser_skip_to_end_of_block_or_statement (parser);
2656 	  break;
2657 	}
2658       if (c_parser_next_token_is (parser, CPP_COLON)
2659 	  || c_parser_next_token_is (parser, CPP_COMMA)
2660 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
2661 	  || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2662 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2663 	{
2664 	  tree postfix_attrs = NULL_TREE;
2665 	  tree width = NULL_TREE;
2666 	  tree d;
2667 	  if (c_parser_next_token_is (parser, CPP_COLON))
2668 	    {
2669 	      c_parser_consume_token (parser);
2670 	      width = c_parser_expr_no_commas (parser, NULL).value;
2671 	    }
2672 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2673 	    postfix_attrs = c_parser_attributes (parser);
2674 	  d = grokfield (c_parser_peek_token (parser)->location,
2675 			 declarator, specs, width, &all_prefix_attrs);
2676 	  decl_attributes (&d, chainon (postfix_attrs,
2677 					all_prefix_attrs), 0);
2678 	  DECL_CHAIN (d) = decls;
2679 	  decls = d;
2680 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2681 	    all_prefix_attrs = chainon (c_parser_attributes (parser),
2682 					prefix_attrs);
2683 	  else
2684 	    all_prefix_attrs = prefix_attrs;
2685 	  if (c_parser_next_token_is (parser, CPP_COMMA))
2686 	    c_parser_consume_token (parser);
2687 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2688 		   || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2689 	    {
2690 	      /* Semicolon consumed in caller.  */
2691 	      break;
2692 	    }
2693 	  else
2694 	    {
2695 	      c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2696 	      break;
2697 	    }
2698 	}
2699       else
2700 	{
2701 	  c_parser_error (parser,
2702 			  "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2703 			  "%<__attribute__%>");
2704 	  break;
2705 	}
2706     }
2707   return decls;
2708 }
2709 
2710 /* Parse a typeof specifier (a GNU extension).
2711 
2712    typeof-specifier:
2713      typeof ( expression )
2714      typeof ( type-name )
2715 */
2716 
2717 static struct c_typespec
2718 c_parser_typeof_specifier (c_parser *parser)
2719 {
2720   struct c_typespec ret;
2721   ret.kind = ctsk_typeof;
2722   ret.spec = error_mark_node;
2723   ret.expr = NULL_TREE;
2724   ret.expr_const_operands = true;
2725   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2726   c_parser_consume_token (parser);
2727   c_inhibit_evaluation_warnings++;
2728   in_typeof++;
2729   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2730     {
2731       c_inhibit_evaluation_warnings--;
2732       in_typeof--;
2733       return ret;
2734     }
2735   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2736     {
2737       struct c_type_name *type = c_parser_type_name (parser);
2738       c_inhibit_evaluation_warnings--;
2739       in_typeof--;
2740       if (type != NULL)
2741 	{
2742 	  ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2743 	  pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2744 	}
2745     }
2746   else
2747     {
2748       bool was_vm;
2749       location_t here = c_parser_peek_token (parser)->location;
2750       struct c_expr expr = c_parser_expression (parser);
2751       c_inhibit_evaluation_warnings--;
2752       in_typeof--;
2753       if (TREE_CODE (expr.value) == COMPONENT_REF
2754 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2755 	error_at (here, "%<typeof%> applied to a bit-field");
2756       mark_exp_read (expr.value);
2757       ret.spec = TREE_TYPE (expr.value);
2758       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2759       /* This is returned with the type so that when the type is
2760 	 evaluated, this can be evaluated.  */
2761       if (was_vm)
2762 	ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2763       pop_maybe_used (was_vm);
2764     }
2765   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2766   return ret;
2767 }
2768 
2769 /* Parse an alignment-specifier.
2770 
2771    C11 6.7.5:
2772 
2773    alignment-specifier:
2774      _Alignas ( type-name )
2775      _Alignas ( constant-expression )
2776 */
2777 
2778 static tree
2779 c_parser_alignas_specifier (c_parser * parser)
2780 {
2781   tree ret = error_mark_node;
2782   location_t loc = c_parser_peek_token (parser)->location;
2783   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
2784   c_parser_consume_token (parser);
2785   if (!flag_isoc11)
2786     {
2787       if (flag_isoc99)
2788 	pedwarn (loc, OPT_Wpedantic,
2789 		 "ISO C99 does not support %<_Alignas%>");
2790       else
2791 	pedwarn (loc, OPT_Wpedantic,
2792 		 "ISO C90 does not support %<_Alignas%>");
2793     }
2794   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2795     return ret;
2796   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2797     {
2798       struct c_type_name *type = c_parser_type_name (parser);
2799       if (type != NULL)
2800 	ret = c_alignof (loc, groktypename (type, NULL, NULL));
2801     }
2802   else
2803     ret = c_parser_expr_no_commas (parser, NULL).value;
2804   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2805   return ret;
2806 }
2807 
2808 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2809    6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
2810    be redeclared; otherwise it may not.  KIND indicates which kind of
2811    declarator is wanted.  Returns a valid declarator except in the
2812    case of a syntax error in which case NULL is returned.  *SEEN_ID is
2813    set to true if an identifier being declared is seen; this is used
2814    to diagnose bad forms of abstract array declarators and to
2815    determine whether an identifier list is syntactically permitted.
2816 
2817    declarator:
2818      pointer[opt] direct-declarator
2819 
2820    direct-declarator:
2821      identifier
2822      ( attributes[opt] declarator )
2823      direct-declarator array-declarator
2824      direct-declarator ( parameter-type-list )
2825      direct-declarator ( identifier-list[opt] )
2826 
2827    pointer:
2828      * type-qualifier-list[opt]
2829      * type-qualifier-list[opt] pointer
2830 
2831    type-qualifier-list:
2832      type-qualifier
2833      attributes
2834      type-qualifier-list type-qualifier
2835      type-qualifier-list attributes
2836 
2837    parameter-type-list:
2838      parameter-list
2839      parameter-list , ...
2840 
2841    parameter-list:
2842      parameter-declaration
2843      parameter-list , parameter-declaration
2844 
2845    parameter-declaration:
2846      declaration-specifiers declarator attributes[opt]
2847      declaration-specifiers abstract-declarator[opt] attributes[opt]
2848 
2849    identifier-list:
2850      identifier
2851      identifier-list , identifier
2852 
2853    abstract-declarator:
2854      pointer
2855      pointer[opt] direct-abstract-declarator
2856 
2857    direct-abstract-declarator:
2858      ( attributes[opt] abstract-declarator )
2859      direct-abstract-declarator[opt] array-declarator
2860      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2861 
2862    GNU extensions:
2863 
2864    direct-declarator:
2865      direct-declarator ( parameter-forward-declarations
2866 			 parameter-type-list[opt] )
2867 
2868    direct-abstract-declarator:
2869      direct-abstract-declarator[opt] ( parameter-forward-declarations
2870 				       parameter-type-list[opt] )
2871 
2872    parameter-forward-declarations:
2873      parameter-list ;
2874      parameter-forward-declarations parameter-list ;
2875 
2876    The uses of attributes shown above are GNU extensions.
2877 
2878    Some forms of array declarator are not included in C99 in the
2879    syntax for abstract declarators; these are disallowed elsewhere.
2880    This may be a defect (DR#289).
2881 
2882    This function also accepts an omitted abstract declarator as being
2883    an abstract declarator, although not part of the formal syntax.  */
2884 
2885 static struct c_declarator *
2886 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2887 		     bool *seen_id)
2888 {
2889   /* Parse any initial pointer part.  */
2890   if (c_parser_next_token_is (parser, CPP_MULT))
2891     {
2892       struct c_declspecs *quals_attrs = build_null_declspecs ();
2893       struct c_declarator *inner;
2894       c_parser_consume_token (parser);
2895       c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2896       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2897       if (inner == NULL)
2898 	return NULL;
2899       else
2900 	return make_pointer_declarator (quals_attrs, inner);
2901     }
2902   /* Now we have a direct declarator, direct abstract declarator or
2903      nothing (which counts as a direct abstract declarator here).  */
2904   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2905 }
2906 
2907 /* Parse a direct declarator or direct abstract declarator; arguments
2908    as c_parser_declarator.  */
2909 
2910 static struct c_declarator *
2911 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2912 			    bool *seen_id)
2913 {
2914   /* The direct declarator must start with an identifier (possibly
2915      omitted) or a parenthesized declarator (possibly abstract).  In
2916      an ordinary declarator, initial parentheses must start a
2917      parenthesized declarator.  In an abstract declarator or parameter
2918      declarator, they could start a parenthesized declarator or a
2919      parameter list.  To tell which, the open parenthesis and any
2920      following attributes must be read.  If a declaration specifier
2921      follows, then it is a parameter list; if the specifier is a
2922      typedef name, there might be an ambiguity about redeclaring it,
2923      which is resolved in the direction of treating it as a typedef
2924      name.  If a close parenthesis follows, it is also an empty
2925      parameter list, as the syntax does not permit empty abstract
2926      declarators.  Otherwise, it is a parenthesized declarator (in
2927      which case the analysis may be repeated inside it, recursively).
2928 
2929      ??? There is an ambiguity in a parameter declaration "int
2930      (__attribute__((foo)) x)", where x is not a typedef name: it
2931      could be an abstract declarator for a function, or declare x with
2932      parentheses.  The proper resolution of this ambiguity needs
2933      documenting.  At present we follow an accident of the old
2934      parser's implementation, whereby the first parameter must have
2935      some declaration specifiers other than just attributes.  Thus as
2936      a parameter declaration it is treated as a parenthesized
2937      parameter named x, and as an abstract declarator it is
2938      rejected.
2939 
2940      ??? Also following the old parser, attributes inside an empty
2941      parameter list are ignored, making it a list not yielding a
2942      prototype, rather than giving an error or making it have one
2943      parameter with implicit type int.
2944 
2945      ??? Also following the old parser, typedef names may be
2946      redeclared in declarators, but not Objective-C class names.  */
2947 
2948   if (kind != C_DTR_ABSTRACT
2949       && c_parser_next_token_is (parser, CPP_NAME)
2950       && ((type_seen_p
2951 	   && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2952 	       || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2953 	  || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2954     {
2955       struct c_declarator *inner
2956 	= build_id_declarator (c_parser_peek_token (parser)->value);
2957       *seen_id = true;
2958       inner->id_loc = c_parser_peek_token (parser)->location;
2959       c_parser_consume_token (parser);
2960       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2961     }
2962 
2963   if (kind != C_DTR_NORMAL
2964       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2965     {
2966       struct c_declarator *inner = build_id_declarator (NULL_TREE);
2967       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2968     }
2969 
2970   /* Either we are at the end of an abstract declarator, or we have
2971      parentheses.  */
2972 
2973   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2974     {
2975       tree attrs;
2976       struct c_declarator *inner;
2977       c_parser_consume_token (parser);
2978       attrs = c_parser_attributes (parser);
2979       if (kind != C_DTR_NORMAL
2980 	  && (c_parser_next_token_starts_declspecs (parser)
2981 	      || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2982 	{
2983 	  struct c_arg_info *args
2984 	    = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2985 					 attrs);
2986 	  if (args == NULL)
2987 	    return NULL;
2988 	  else
2989 	    {
2990 	      inner
2991 		= build_function_declarator (args,
2992 					     build_id_declarator (NULL_TREE));
2993 	      return c_parser_direct_declarator_inner (parser, *seen_id,
2994 						       inner);
2995 	    }
2996 	}
2997       /* A parenthesized declarator.  */
2998       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2999       if (inner != NULL && attrs != NULL)
3000 	inner = build_attrs_declarator (attrs, inner);
3001       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3002 	{
3003 	  c_parser_consume_token (parser);
3004 	  if (inner == NULL)
3005 	    return NULL;
3006 	  else
3007 	    return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3008 	}
3009       else
3010 	{
3011 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3012 				     "expected %<)%>");
3013 	  return NULL;
3014 	}
3015     }
3016   else
3017     {
3018       if (kind == C_DTR_NORMAL)
3019 	{
3020 	  c_parser_error (parser, "expected identifier or %<(%>");
3021 	  return NULL;
3022 	}
3023       else
3024 	return build_id_declarator (NULL_TREE);
3025     }
3026 }
3027 
3028 /* Parse part of a direct declarator or direct abstract declarator,
3029    given that some (in INNER) has already been parsed; ID_PRESENT is
3030    true if an identifier is present, false for an abstract
3031    declarator.  */
3032 
3033 static struct c_declarator *
3034 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3035 				  struct c_declarator *inner)
3036 {
3037   /* Parse a sequence of array declarators and parameter lists.  */
3038   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3039     {
3040       location_t brace_loc = c_parser_peek_token (parser)->location;
3041       struct c_declarator *declarator;
3042       struct c_declspecs *quals_attrs = build_null_declspecs ();
3043       bool static_seen;
3044       bool star_seen;
3045       tree dimen;
3046       c_parser_consume_token (parser);
3047       c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
3048       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3049       if (static_seen)
3050 	c_parser_consume_token (parser);
3051       if (static_seen && !quals_attrs->declspecs_seen_p)
3052 	c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
3053       if (!quals_attrs->declspecs_seen_p)
3054 	quals_attrs = NULL;
3055       /* If "static" is present, there must be an array dimension.
3056 	 Otherwise, there may be a dimension, "*", or no
3057 	 dimension.  */
3058       if (static_seen)
3059 	{
3060 	  star_seen = false;
3061 	  dimen = c_parser_expr_no_commas (parser, NULL).value;
3062 	}
3063       else
3064 	{
3065 	  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3066 	    {
3067 	      dimen = NULL_TREE;
3068 	      star_seen = false;
3069 	    }
3070 	  else if (c_parser_next_token_is (parser, CPP_MULT))
3071 	    {
3072 	      if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3073 		{
3074 		  dimen = NULL_TREE;
3075 		  star_seen = true;
3076 		  c_parser_consume_token (parser);
3077 		}
3078 	      else
3079 		{
3080 		  star_seen = false;
3081 		  dimen = c_parser_expr_no_commas (parser, NULL).value;
3082 		}
3083 	    }
3084 	  else
3085 	    {
3086 	      star_seen = false;
3087 	      dimen = c_parser_expr_no_commas (parser, NULL).value;
3088 	    }
3089 	}
3090       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3091 	c_parser_consume_token (parser);
3092       else
3093 	{
3094 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3095 				     "expected %<]%>");
3096 	  return NULL;
3097 	}
3098       if (dimen)
3099 	mark_exp_read (dimen);
3100       declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
3101 					   static_seen, star_seen);
3102       if (declarator == NULL)
3103 	return NULL;
3104       inner = set_array_declarator_inner (declarator, inner);
3105       return c_parser_direct_declarator_inner (parser, id_present, inner);
3106     }
3107   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3108     {
3109       tree attrs;
3110       struct c_arg_info *args;
3111       c_parser_consume_token (parser);
3112       attrs = c_parser_attributes (parser);
3113       args = c_parser_parms_declarator (parser, id_present, attrs);
3114       if (args == NULL)
3115 	return NULL;
3116       else
3117 	{
3118 	  inner = build_function_declarator (args, inner);
3119 	  return c_parser_direct_declarator_inner (parser, id_present, inner);
3120 	}
3121     }
3122   return inner;
3123 }
3124 
3125 /* Parse a parameter list or identifier list, including the closing
3126    parenthesis but not the opening one.  ATTRS are the attributes at
3127    the start of the list.  ID_LIST_OK is true if an identifier list is
3128    acceptable; such a list must not have attributes at the start.  */
3129 
3130 static struct c_arg_info *
3131 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3132 {
3133   push_scope ();
3134   declare_parm_level ();
3135   /* If the list starts with an identifier, it is an identifier list.
3136      Otherwise, it is either a prototype list or an empty list.  */
3137   if (id_list_ok
3138       && !attrs
3139       && c_parser_next_token_is (parser, CPP_NAME)
3140       && c_parser_peek_token (parser)->id_kind == C_ID_ID
3141 
3142       /* Look ahead to detect typos in type names.  */
3143       && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3144       && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3145       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3146       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3147     {
3148       tree list = NULL_TREE, *nextp = &list;
3149       while (c_parser_next_token_is (parser, CPP_NAME)
3150 	     && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3151 	{
3152 	  *nextp = build_tree_list (NULL_TREE,
3153 				    c_parser_peek_token (parser)->value);
3154 	  nextp = & TREE_CHAIN (*nextp);
3155 	  c_parser_consume_token (parser);
3156 	  if (c_parser_next_token_is_not (parser, CPP_COMMA))
3157 	    break;
3158 	  c_parser_consume_token (parser);
3159 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3160 	    {
3161 	      c_parser_error (parser, "expected identifier");
3162 	      break;
3163 	    }
3164 	}
3165       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3166 	{
3167 	  struct c_arg_info *ret = build_arg_info ();
3168 	  ret->types = list;
3169 	  c_parser_consume_token (parser);
3170 	  pop_scope ();
3171 	  return ret;
3172 	}
3173       else
3174 	{
3175 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3176 				     "expected %<)%>");
3177 	  pop_scope ();
3178 	  return NULL;
3179 	}
3180     }
3181   else
3182     {
3183       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3184 							       NULL);
3185       pop_scope ();
3186       return ret;
3187     }
3188 }
3189 
3190 /* Parse a parameter list (possibly empty), including the closing
3191    parenthesis but not the opening one.  ATTRS are the attributes at
3192    the start of the list.  EXPR is NULL or an expression that needs to
3193    be evaluated for the side effects of array size expressions in the
3194    parameters.  */
3195 
3196 static struct c_arg_info *
3197 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3198 {
3199   bool bad_parm = false;
3200 
3201   /* ??? Following the old parser, forward parameter declarations may
3202      use abstract declarators, and if no real parameter declarations
3203      follow the forward declarations then this is not diagnosed.  Also
3204      note as above that attributes are ignored as the only contents of
3205      the parentheses, or as the only contents after forward
3206      declarations.  */
3207   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3208     {
3209       struct c_arg_info *ret = build_arg_info ();
3210       c_parser_consume_token (parser);
3211       return ret;
3212     }
3213   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3214     {
3215       struct c_arg_info *ret = build_arg_info ();
3216 
3217       if (flag_allow_parameterless_variadic_functions)
3218         {
3219           /* F (...) is allowed.  */
3220           ret->types = NULL_TREE;
3221         }
3222       else
3223         {
3224           /* Suppress -Wold-style-definition for this case.  */
3225           ret->types = error_mark_node;
3226           error_at (c_parser_peek_token (parser)->location,
3227                     "ISO C requires a named argument before %<...%>");
3228         }
3229       c_parser_consume_token (parser);
3230       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3231 	{
3232 	  c_parser_consume_token (parser);
3233 	  return ret;
3234 	}
3235       else
3236 	{
3237 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3238 				     "expected %<)%>");
3239 	  return NULL;
3240 	}
3241     }
3242   /* Nonempty list of parameters, either terminated with semicolon
3243      (forward declarations; recurse) or with close parenthesis (normal
3244      function) or with ", ... )" (variadic function).  */
3245   while (true)
3246     {
3247       /* Parse a parameter.  */
3248       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3249       attrs = NULL_TREE;
3250       if (parm == NULL)
3251 	bad_parm = true;
3252       else
3253 	push_parm_decl (parm, &expr);
3254       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3255 	{
3256 	  tree new_attrs;
3257 	  c_parser_consume_token (parser);
3258 	  mark_forward_parm_decls ();
3259 	  new_attrs = c_parser_attributes (parser);
3260 	  return c_parser_parms_list_declarator (parser, new_attrs, expr);
3261 	}
3262       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3263 	{
3264 	  c_parser_consume_token (parser);
3265 	  if (bad_parm)
3266 	    return NULL;
3267 	  else
3268 	    return get_parm_info (false, expr);
3269 	}
3270       if (!c_parser_require (parser, CPP_COMMA,
3271 			     "expected %<;%>, %<,%> or %<)%>"))
3272 	{
3273 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3274 	  return NULL;
3275 	}
3276       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3277 	{
3278 	  c_parser_consume_token (parser);
3279 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3280 	    {
3281 	      c_parser_consume_token (parser);
3282 	      if (bad_parm)
3283 		return NULL;
3284 	      else
3285 		return get_parm_info (true, expr);
3286 	    }
3287 	  else
3288 	    {
3289 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3290 					 "expected %<)%>");
3291 	      return NULL;
3292 	    }
3293 	}
3294     }
3295 }
3296 
3297 /* Parse a parameter declaration.  ATTRS are the attributes at the
3298    start of the declaration if it is the first parameter.  */
3299 
3300 static struct c_parm *
3301 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3302 {
3303   struct c_declspecs *specs;
3304   struct c_declarator *declarator;
3305   tree prefix_attrs;
3306   tree postfix_attrs = NULL_TREE;
3307   bool dummy = false;
3308 
3309   /* Accept #pragmas between parameter declarations.  */
3310   while (c_parser_next_token_is (parser, CPP_PRAGMA))
3311     c_parser_pragma (parser, pragma_external);
3312 
3313   if (!c_parser_next_token_starts_declspecs (parser))
3314     {
3315       c_token *token = c_parser_peek_token (parser);
3316       if (parser->error)
3317 	return NULL;
3318       c_parser_set_source_position_from_token (token);
3319       if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3320 	{
3321 	  error ("unknown type name %qE", token->value);
3322 	  parser->error = true;
3323 	}
3324       /* ??? In some Objective-C cases '...' isn't applicable so there
3325 	 should be a different message.  */
3326       else
3327 	c_parser_error (parser,
3328 			"expected declaration specifiers or %<...%>");
3329       c_parser_skip_to_end_of_parameter (parser);
3330       return NULL;
3331     }
3332   specs = build_null_declspecs ();
3333   if (attrs)
3334     {
3335       declspecs_add_attrs (input_location, specs, attrs);
3336       attrs = NULL_TREE;
3337     }
3338   c_parser_declspecs (parser, specs, true, true, true, cla_nonabstract_decl);
3339   finish_declspecs (specs);
3340   pending_xref_error ();
3341   prefix_attrs = specs->attrs;
3342   specs->attrs = NULL_TREE;
3343   declarator = c_parser_declarator (parser,
3344 				    specs->typespec_kind != ctsk_none,
3345 				    C_DTR_PARM, &dummy);
3346   if (declarator == NULL)
3347     {
3348       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3349       return NULL;
3350     }
3351   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3352     postfix_attrs = c_parser_attributes (parser);
3353   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3354 		       declarator);
3355 }
3356 
3357 /* Parse a string literal in an asm expression.  It should not be
3358    translated, and wide string literals are an error although
3359    permitted by the syntax.  This is a GNU extension.
3360 
3361    asm-string-literal:
3362      string-literal
3363 
3364    ??? At present, following the old parser, the caller needs to have
3365    set lex_untranslated_string to 1.  It would be better to follow the
3366    C++ parser rather than using this kludge.  */
3367 
3368 static tree
3369 c_parser_asm_string_literal (c_parser *parser)
3370 {
3371   tree str;
3372   int save_flag = warn_overlength_strings;
3373   warn_overlength_strings = 0;
3374   if (c_parser_next_token_is (parser, CPP_STRING))
3375     {
3376       str = c_parser_peek_token (parser)->value;
3377       c_parser_consume_token (parser);
3378     }
3379   else if (c_parser_next_token_is (parser, CPP_WSTRING))
3380     {
3381       error_at (c_parser_peek_token (parser)->location,
3382 		"wide string literal in %<asm%>");
3383       str = build_string (1, "");
3384       c_parser_consume_token (parser);
3385     }
3386   else
3387     {
3388       c_parser_error (parser, "expected string literal");
3389       str = NULL_TREE;
3390     }
3391   warn_overlength_strings = save_flag;
3392   return str;
3393 }
3394 
3395 /* Parse a simple asm expression.  This is used in restricted
3396    contexts, where a full expression with inputs and outputs does not
3397    make sense.  This is a GNU extension.
3398 
3399    simple-asm-expr:
3400      asm ( asm-string-literal )
3401 */
3402 
3403 static tree
3404 c_parser_simple_asm_expr (c_parser *parser)
3405 {
3406   tree str;
3407   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3408   /* ??? Follow the C++ parser rather than using the
3409      lex_untranslated_string kludge.  */
3410   parser->lex_untranslated_string = true;
3411   c_parser_consume_token (parser);
3412   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3413     {
3414       parser->lex_untranslated_string = false;
3415       return NULL_TREE;
3416     }
3417   str = c_parser_asm_string_literal (parser);
3418   parser->lex_untranslated_string = false;
3419   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3420     {
3421       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3422       return NULL_TREE;
3423     }
3424   return str;
3425 }
3426 
3427 static tree
3428 c_parser_attribute_any_word (c_parser *parser)
3429 {
3430   tree attr_name = NULL_TREE;
3431 
3432   if (c_parser_next_token_is (parser, CPP_KEYWORD))
3433     {
3434       /* ??? See comment above about what keywords are accepted here.  */
3435       bool ok;
3436       switch (c_parser_peek_token (parser)->keyword)
3437 	{
3438 	case RID_STATIC:
3439 	case RID_UNSIGNED:
3440 	case RID_LONG:
3441 	case RID_INT128:
3442 	case RID_CONST:
3443 	case RID_EXTERN:
3444 	case RID_REGISTER:
3445 	case RID_TYPEDEF:
3446 	case RID_SHORT:
3447 	case RID_INLINE:
3448 	case RID_NORETURN:
3449 	case RID_VOLATILE:
3450 	case RID_SIGNED:
3451 	case RID_AUTO:
3452 	case RID_RESTRICT:
3453 	case RID_COMPLEX:
3454 	case RID_THREAD:
3455 	case RID_INT:
3456 	case RID_CHAR:
3457 	case RID_FLOAT:
3458 	case RID_DOUBLE:
3459 	case RID_VOID:
3460 	case RID_DFLOAT32:
3461 	case RID_DFLOAT64:
3462 	case RID_DFLOAT128:
3463 	case RID_BOOL:
3464 	case RID_FRACT:
3465 	case RID_ACCUM:
3466 	case RID_SAT:
3467 	case RID_TRANSACTION_ATOMIC:
3468 	case RID_TRANSACTION_CANCEL:
3469 	  ok = true;
3470 	  break;
3471 	default:
3472 	  ok = false;
3473 	  break;
3474 	}
3475       if (!ok)
3476 	return NULL_TREE;
3477 
3478       /* Accept __attribute__((__const)) as __attribute__((const)) etc.  */
3479       attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3480     }
3481   else if (c_parser_next_token_is (parser, CPP_NAME))
3482     attr_name = c_parser_peek_token (parser)->value;
3483 
3484   return attr_name;
3485 }
3486 
3487 /* Parse (possibly empty) attributes.  This is a GNU extension.
3488 
3489    attributes:
3490      empty
3491      attributes attribute
3492 
3493    attribute:
3494      __attribute__ ( ( attribute-list ) )
3495 
3496    attribute-list:
3497      attrib
3498      attribute_list , attrib
3499 
3500    attrib:
3501      empty
3502      any-word
3503      any-word ( identifier )
3504      any-word ( identifier , nonempty-expr-list )
3505      any-word ( expr-list )
3506 
3507    where the "identifier" must not be declared as a type, and
3508    "any-word" may be any identifier (including one declared as a
3509    type), a reserved word storage class specifier, type specifier or
3510    type qualifier.  ??? This still leaves out most reserved keywords
3511    (following the old parser), shouldn't we include them, and why not
3512    allow identifiers declared as types to start the arguments?  */
3513 
3514 static tree
3515 c_parser_attributes (c_parser *parser)
3516 {
3517   tree attrs = NULL_TREE;
3518   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3519     {
3520       /* ??? Follow the C++ parser rather than using the
3521 	 lex_untranslated_string kludge.  */
3522       parser->lex_untranslated_string = true;
3523       c_parser_consume_token (parser);
3524       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3525 	{
3526 	  parser->lex_untranslated_string = false;
3527 	  return attrs;
3528 	}
3529       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3530 	{
3531 	  parser->lex_untranslated_string = false;
3532 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3533 	  return attrs;
3534 	}
3535       /* Parse the attribute list.  */
3536       while (c_parser_next_token_is (parser, CPP_COMMA)
3537 	     || c_parser_next_token_is (parser, CPP_NAME)
3538 	     || c_parser_next_token_is (parser, CPP_KEYWORD))
3539 	{
3540 	  tree attr, attr_name, attr_args;
3541 	  vec<tree, va_gc> *expr_list;
3542 	  if (c_parser_next_token_is (parser, CPP_COMMA))
3543 	    {
3544 	      c_parser_consume_token (parser);
3545 	      continue;
3546 	    }
3547 
3548 	  attr_name = c_parser_attribute_any_word (parser);
3549 	  if (attr_name == NULL)
3550 	    break;
3551 	  c_parser_consume_token (parser);
3552 	  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3553 	    {
3554 	      attr = build_tree_list (attr_name, NULL_TREE);
3555 	      attrs = chainon (attrs, attr);
3556 	      continue;
3557 	    }
3558 	  c_parser_consume_token (parser);
3559 	  /* Parse the attribute contents.  If they start with an
3560 	     identifier which is followed by a comma or close
3561 	     parenthesis, then the arguments start with that
3562 	     identifier; otherwise they are an expression list.
3563 	     In objective-c the identifier may be a classname.  */
3564 	  if (c_parser_next_token_is (parser, CPP_NAME)
3565 	      && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3566 		  || (c_dialect_objc ()
3567 		      && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3568 	      && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3569 		  || (c_parser_peek_2nd_token (parser)->type
3570 		      == CPP_CLOSE_PAREN)))
3571 	    {
3572 	      tree arg1 = c_parser_peek_token (parser)->value;
3573 	      c_parser_consume_token (parser);
3574 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3575 		attr_args = build_tree_list (NULL_TREE, arg1);
3576 	      else
3577 		{
3578 		  tree tree_list;
3579 		  c_parser_consume_token (parser);
3580 		  expr_list = c_parser_expr_list (parser, false, true,
3581 						  NULL, NULL, NULL);
3582 		  tree_list = build_tree_list_vec (expr_list);
3583 		  attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3584 		  release_tree_vector (expr_list);
3585 		}
3586 	    }
3587 	  else
3588 	    {
3589 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3590 		attr_args = NULL_TREE;
3591 	      else
3592 		{
3593 		  expr_list = c_parser_expr_list (parser, false, true,
3594 						  NULL, NULL, NULL);
3595 		  attr_args = build_tree_list_vec (expr_list);
3596 		  release_tree_vector (expr_list);
3597 		}
3598 	    }
3599 	  attr = build_tree_list (attr_name, attr_args);
3600 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3601 	    c_parser_consume_token (parser);
3602 	  else
3603 	    {
3604 	      parser->lex_untranslated_string = false;
3605 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3606 					 "expected %<)%>");
3607 	      return attrs;
3608 	    }
3609 	  attrs = chainon (attrs, attr);
3610 	}
3611       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3612 	c_parser_consume_token (parser);
3613       else
3614 	{
3615 	  parser->lex_untranslated_string = false;
3616 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3617 				     "expected %<)%>");
3618 	  return attrs;
3619 	}
3620       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3621 	c_parser_consume_token (parser);
3622       else
3623 	{
3624 	  parser->lex_untranslated_string = false;
3625 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3626 				     "expected %<)%>");
3627 	  return attrs;
3628 	}
3629       parser->lex_untranslated_string = false;
3630     }
3631   return attrs;
3632 }
3633 
3634 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3635 
3636    type-name:
3637      specifier-qualifier-list abstract-declarator[opt]
3638 */
3639 
3640 static struct c_type_name *
3641 c_parser_type_name (c_parser *parser)
3642 {
3643   struct c_declspecs *specs = build_null_declspecs ();
3644   struct c_declarator *declarator;
3645   struct c_type_name *ret;
3646   bool dummy = false;
3647   c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
3648   if (!specs->declspecs_seen_p)
3649     {
3650       c_parser_error (parser, "expected specifier-qualifier-list");
3651       return NULL;
3652     }
3653   if (specs->type != error_mark_node)
3654     {
3655       pending_xref_error ();
3656       finish_declspecs (specs);
3657     }
3658   declarator = c_parser_declarator (parser,
3659 				    specs->typespec_kind != ctsk_none,
3660 				    C_DTR_ABSTRACT, &dummy);
3661   if (declarator == NULL)
3662     return NULL;
3663   ret = XOBNEW (&parser_obstack, struct c_type_name);
3664   ret->specs = specs;
3665   ret->declarator = declarator;
3666   return ret;
3667 }
3668 
3669 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3670 
3671    initializer:
3672      assignment-expression
3673      { initializer-list }
3674      { initializer-list , }
3675 
3676    initializer-list:
3677      designation[opt] initializer
3678      initializer-list , designation[opt] initializer
3679 
3680    designation:
3681      designator-list =
3682 
3683    designator-list:
3684      designator
3685      designator-list designator
3686 
3687    designator:
3688      array-designator
3689      . identifier
3690 
3691    array-designator:
3692      [ constant-expression ]
3693 
3694    GNU extensions:
3695 
3696    initializer:
3697      { }
3698 
3699    designation:
3700      array-designator
3701      identifier :
3702 
3703    array-designator:
3704      [ constant-expression ... constant-expression ]
3705 
3706    Any expression without commas is accepted in the syntax for the
3707    constant-expressions, with non-constant expressions rejected later.
3708 
3709    This function is only used for top-level initializers; for nested
3710    ones, see c_parser_initval.  */
3711 
3712 static struct c_expr
3713 c_parser_initializer (c_parser *parser)
3714 {
3715   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3716     return c_parser_braced_init (parser, NULL_TREE, false);
3717   else
3718     {
3719       struct c_expr ret;
3720       location_t loc = c_parser_peek_token (parser)->location;
3721       ret = c_parser_expr_no_commas (parser, NULL);
3722       if (TREE_CODE (ret.value) != STRING_CST
3723 	  && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3724 	ret = default_function_array_read_conversion (loc, ret);
3725       return ret;
3726     }
3727 }
3728 
3729 /* Parse a braced initializer list.  TYPE is the type specified for a
3730    compound literal, and NULL_TREE for other initializers and for
3731    nested braced lists.  NESTED_P is true for nested braced lists,
3732    false for the list of a compound literal or the list that is the
3733    top-level initializer in a declaration.  */
3734 
3735 static struct c_expr
3736 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3737 {
3738   struct c_expr ret;
3739   struct obstack braced_init_obstack;
3740   location_t brace_loc = c_parser_peek_token (parser)->location;
3741   gcc_obstack_init (&braced_init_obstack);
3742   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3743   c_parser_consume_token (parser);
3744   if (nested_p)
3745     push_init_level (0, &braced_init_obstack);
3746   else
3747     really_start_incremental_init (type);
3748   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3749     {
3750       pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
3751     }
3752   else
3753     {
3754       /* Parse a non-empty initializer list, possibly with a trailing
3755 	 comma.  */
3756       while (true)
3757 	{
3758 	  c_parser_initelt (parser, &braced_init_obstack);
3759 	  if (parser->error)
3760 	    break;
3761 	  if (c_parser_next_token_is (parser, CPP_COMMA))
3762 	    c_parser_consume_token (parser);
3763 	  else
3764 	    break;
3765 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3766 	    break;
3767 	}
3768     }
3769   if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3770     {
3771       ret.value = error_mark_node;
3772       ret.original_code = ERROR_MARK;
3773       ret.original_type = NULL;
3774       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3775       pop_init_level (0, &braced_init_obstack);
3776       obstack_free (&braced_init_obstack, NULL);
3777       return ret;
3778     }
3779   c_parser_consume_token (parser);
3780   ret = pop_init_level (0, &braced_init_obstack);
3781   obstack_free (&braced_init_obstack, NULL);
3782   return ret;
3783 }
3784 
3785 /* Parse a nested initializer, including designators.  */
3786 
3787 static void
3788 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3789 {
3790   /* Parse any designator or designator list.  A single array
3791      designator may have the subsequent "=" omitted in GNU C, but a
3792      longer list or a structure member designator may not.  */
3793   if (c_parser_next_token_is (parser, CPP_NAME)
3794       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3795     {
3796       /* Old-style structure member designator.  */
3797       set_init_label (c_parser_peek_token (parser)->value,
3798 		      braced_init_obstack);
3799       /* Use the colon as the error location.  */
3800       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
3801 	       "obsolete use of designated initializer with %<:%>");
3802       c_parser_consume_token (parser);
3803       c_parser_consume_token (parser);
3804     }
3805   else
3806     {
3807       /* des_seen is 0 if there have been no designators, 1 if there
3808 	 has been a single array designator and 2 otherwise.  */
3809       int des_seen = 0;
3810       /* Location of a designator.  */
3811       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3812       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3813 	     || c_parser_next_token_is (parser, CPP_DOT))
3814 	{
3815 	  int des_prev = des_seen;
3816 	  if (!des_seen)
3817 	    des_loc = c_parser_peek_token (parser)->location;
3818 	  if (des_seen < 2)
3819 	    des_seen++;
3820 	  if (c_parser_next_token_is (parser, CPP_DOT))
3821 	    {
3822 	      des_seen = 2;
3823 	      c_parser_consume_token (parser);
3824 	      if (c_parser_next_token_is (parser, CPP_NAME))
3825 		{
3826 		  set_init_label (c_parser_peek_token (parser)->value,
3827 				  braced_init_obstack);
3828 		  c_parser_consume_token (parser);
3829 		}
3830 	      else
3831 		{
3832 		  struct c_expr init;
3833 		  init.value = error_mark_node;
3834 		  init.original_code = ERROR_MARK;
3835 		  init.original_type = NULL;
3836 		  c_parser_error (parser, "expected identifier");
3837 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3838 		  process_init_element (init, false, braced_init_obstack);
3839 		  return;
3840 		}
3841 	    }
3842 	  else
3843 	    {
3844 	      tree first, second;
3845 	      location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3846 	      /* ??? Following the old parser, [ objc-receiver
3847 		 objc-message-args ] is accepted as an initializer,
3848 		 being distinguished from a designator by what follows
3849 		 the first assignment expression inside the square
3850 		 brackets, but after a first array designator a
3851 		 subsequent square bracket is for Objective-C taken to
3852 		 start an expression, using the obsolete form of
3853 		 designated initializer without '=', rather than
3854 		 possibly being a second level of designation: in LALR
3855 		 terms, the '[' is shifted rather than reducing
3856 		 designator to designator-list.  */
3857 	      if (des_prev == 1 && c_dialect_objc ())
3858 		{
3859 		  des_seen = des_prev;
3860 		  break;
3861 		}
3862 	      if (des_prev == 0 && c_dialect_objc ())
3863 		{
3864 		  /* This might be an array designator or an
3865 		     Objective-C message expression.  If the former,
3866 		     continue parsing here; if the latter, parse the
3867 		     remainder of the initializer given the starting
3868 		     primary-expression.  ??? It might make sense to
3869 		     distinguish when des_prev == 1 as well; see
3870 		     previous comment.  */
3871 		  tree rec, args;
3872 		  struct c_expr mexpr;
3873 		  c_parser_consume_token (parser);
3874 		  if (c_parser_peek_token (parser)->type == CPP_NAME
3875 		      && ((c_parser_peek_token (parser)->id_kind
3876 			   == C_ID_TYPENAME)
3877 			  || (c_parser_peek_token (parser)->id_kind
3878 			      == C_ID_CLASSNAME)))
3879 		    {
3880 		      /* Type name receiver.  */
3881 		      tree id = c_parser_peek_token (parser)->value;
3882 		      c_parser_consume_token (parser);
3883 		      rec = objc_get_class_reference (id);
3884 		      goto parse_message_args;
3885 		    }
3886 		  first = c_parser_expr_no_commas (parser, NULL).value;
3887 		  mark_exp_read (first);
3888 		  if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3889 		      || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3890 		    goto array_desig_after_first;
3891 		  /* Expression receiver.  So far only one part
3892 		     without commas has been parsed; there might be
3893 		     more of the expression.  */
3894 		  rec = first;
3895 		  while (c_parser_next_token_is (parser, CPP_COMMA))
3896 		    {
3897 		      struct c_expr next;
3898 		      location_t comma_loc, exp_loc;
3899 		      comma_loc = c_parser_peek_token (parser)->location;
3900 		      c_parser_consume_token (parser);
3901 		      exp_loc = c_parser_peek_token (parser)->location;
3902 		      next = c_parser_expr_no_commas (parser, NULL);
3903 		      next = default_function_array_read_conversion (exp_loc,
3904 								     next);
3905 		      rec = build_compound_expr (comma_loc, rec, next.value);
3906 		    }
3907 		parse_message_args:
3908 		  /* Now parse the objc-message-args.  */
3909 		  args = c_parser_objc_message_args (parser);
3910 		  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3911 					     "expected %<]%>");
3912 		  mexpr.value
3913 		    = objc_build_message_expr (rec, args);
3914 		  mexpr.original_code = ERROR_MARK;
3915 		  mexpr.original_type = NULL;
3916 		  /* Now parse and process the remainder of the
3917 		     initializer, starting with this message
3918 		     expression as a primary-expression.  */
3919 		  c_parser_initval (parser, &mexpr, braced_init_obstack);
3920 		  return;
3921 		}
3922 	      c_parser_consume_token (parser);
3923 	      first = c_parser_expr_no_commas (parser, NULL).value;
3924 	      mark_exp_read (first);
3925 	    array_desig_after_first:
3926 	      if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3927 		{
3928 		  ellipsis_loc = c_parser_peek_token (parser)->location;
3929 		  c_parser_consume_token (parser);
3930 		  second = c_parser_expr_no_commas (parser, NULL).value;
3931 		  mark_exp_read (second);
3932 		}
3933 	      else
3934 		second = NULL_TREE;
3935 	      if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3936 		{
3937 		  c_parser_consume_token (parser);
3938 		  set_init_index (first, second, braced_init_obstack);
3939 		  if (second)
3940 		    pedwarn (ellipsis_loc, OPT_Wpedantic,
3941 			     "ISO C forbids specifying range of elements to initialize");
3942 		}
3943 	      else
3944 		c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3945 					   "expected %<]%>");
3946 	    }
3947 	}
3948       if (des_seen >= 1)
3949 	{
3950 	  if (c_parser_next_token_is (parser, CPP_EQ))
3951 	    {
3952 	      if (!flag_isoc99)
3953 		pedwarn (des_loc, OPT_Wpedantic,
3954 			 "ISO C90 forbids specifying subobject to initialize");
3955 	      c_parser_consume_token (parser);
3956 	    }
3957 	  else
3958 	    {
3959 	      if (des_seen == 1)
3960 		pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
3961 			 "obsolete use of designated initializer without %<=%>");
3962 	      else
3963 		{
3964 		  struct c_expr init;
3965 		  init.value = error_mark_node;
3966 		  init.original_code = ERROR_MARK;
3967 		  init.original_type = NULL;
3968 		  c_parser_error (parser, "expected %<=%>");
3969 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3970 		  process_init_element (init, false, braced_init_obstack);
3971 		  return;
3972 		}
3973 	    }
3974 	}
3975     }
3976   c_parser_initval (parser, NULL, braced_init_obstack);
3977 }
3978 
3979 /* Parse a nested initializer; as c_parser_initializer but parses
3980    initializers within braced lists, after any designators have been
3981    applied.  If AFTER is not NULL then it is an Objective-C message
3982    expression which is the primary-expression starting the
3983    initializer.  */
3984 
3985 static void
3986 c_parser_initval (c_parser *parser, struct c_expr *after,
3987 		  struct obstack * braced_init_obstack)
3988 {
3989   struct c_expr init;
3990   gcc_assert (!after || c_dialect_objc ());
3991   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3992     init = c_parser_braced_init (parser, NULL_TREE, true);
3993   else
3994     {
3995       location_t loc = c_parser_peek_token (parser)->location;
3996       init = c_parser_expr_no_commas (parser, after);
3997       if (init.value != NULL_TREE
3998 	  && TREE_CODE (init.value) != STRING_CST
3999 	  && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4000 	init = default_function_array_read_conversion (loc, init);
4001     }
4002   process_init_element (init, false, braced_init_obstack);
4003 }
4004 
4005 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4006    C99 6.8.2).
4007 
4008    compound-statement:
4009      { block-item-list[opt] }
4010      { label-declarations block-item-list }
4011 
4012    block-item-list:
4013      block-item
4014      block-item-list block-item
4015 
4016    block-item:
4017      nested-declaration
4018      statement
4019 
4020    nested-declaration:
4021      declaration
4022 
4023    GNU extensions:
4024 
4025    compound-statement:
4026      { label-declarations block-item-list }
4027 
4028    nested-declaration:
4029      __extension__ nested-declaration
4030      nested-function-definition
4031 
4032    label-declarations:
4033      label-declaration
4034      label-declarations label-declaration
4035 
4036    label-declaration:
4037      __label__ identifier-list ;
4038 
4039    Allowing the mixing of declarations and code is new in C99.  The
4040    GNU syntax also permits (not shown above) labels at the end of
4041    compound statements, which yield an error.  We don't allow labels
4042    on declarations; this might seem like a natural extension, but
4043    there would be a conflict between attributes on the label and
4044    prefix attributes on the declaration.  ??? The syntax follows the
4045    old parser in requiring something after label declarations.
4046    Although they are erroneous if the labels declared aren't defined,
4047    is it useful for the syntax to be this way?
4048 
4049    OpenMP:
4050 
4051    block-item:
4052      openmp-directive
4053 
4054    openmp-directive:
4055      barrier-directive
4056      flush-directive  */
4057 
4058 static tree
4059 c_parser_compound_statement (c_parser *parser)
4060 {
4061   tree stmt;
4062   location_t brace_loc;
4063   brace_loc = c_parser_peek_token (parser)->location;
4064   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4065     {
4066       /* Ensure a scope is entered and left anyway to avoid confusion
4067 	 if we have just prepared to enter a function body.  */
4068       stmt = c_begin_compound_stmt (true);
4069       c_end_compound_stmt (brace_loc, stmt, true);
4070       return error_mark_node;
4071     }
4072   stmt = c_begin_compound_stmt (true);
4073   c_parser_compound_statement_nostart (parser);
4074   return c_end_compound_stmt (brace_loc, stmt, true);
4075 }
4076 
4077 /* Parse a compound statement except for the opening brace.  This is
4078    used for parsing both compound statements and statement expressions
4079    (which follow different paths to handling the opening).  */
4080 
4081 static void
4082 c_parser_compound_statement_nostart (c_parser *parser)
4083 {
4084   bool last_stmt = false;
4085   bool last_label = false;
4086   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4087   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4088   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4089     {
4090       c_parser_consume_token (parser);
4091       return;
4092     }
4093   mark_valid_location_for_stdc_pragma (true);
4094   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4095     {
4096       /* Read zero or more forward-declarations for labels that nested
4097 	 functions can jump to.  */
4098       mark_valid_location_for_stdc_pragma (false);
4099       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4100 	{
4101 	  label_loc = c_parser_peek_token (parser)->location;
4102 	  c_parser_consume_token (parser);
4103 	  /* Any identifiers, including those declared as type names,
4104 	     are OK here.  */
4105 	  while (true)
4106 	    {
4107 	      tree label;
4108 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
4109 		{
4110 		  c_parser_error (parser, "expected identifier");
4111 		  break;
4112 		}
4113 	      label
4114 		= declare_label (c_parser_peek_token (parser)->value);
4115 	      C_DECLARED_LABEL_FLAG (label) = 1;
4116 	      add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4117 	      c_parser_consume_token (parser);
4118 	      if (c_parser_next_token_is (parser, CPP_COMMA))
4119 		c_parser_consume_token (parser);
4120 	      else
4121 		break;
4122 	    }
4123 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4124 	}
4125       pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4126     }
4127   /* We must now have at least one statement, label or declaration.  */
4128   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4129     {
4130       mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4131       c_parser_error (parser, "expected declaration or statement");
4132       c_parser_consume_token (parser);
4133       return;
4134     }
4135   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4136     {
4137       location_t loc = c_parser_peek_token (parser)->location;
4138       if (c_parser_next_token_is_keyword (parser, RID_CASE)
4139 	  || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4140 	  || (c_parser_next_token_is (parser, CPP_NAME)
4141 	      && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4142 	{
4143 	  if (c_parser_next_token_is_keyword (parser, RID_CASE))
4144 	    label_loc = c_parser_peek_2nd_token (parser)->location;
4145 	  else
4146 	    label_loc = c_parser_peek_token (parser)->location;
4147 	  last_label = true;
4148 	  last_stmt = false;
4149 	  mark_valid_location_for_stdc_pragma (false);
4150 	  c_parser_label (parser);
4151 	}
4152       else if (!last_label
4153 	       && c_parser_next_tokens_start_declaration (parser))
4154 	{
4155 	  last_label = false;
4156 	  mark_valid_location_for_stdc_pragma (false);
4157 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
4158 	  if (last_stmt)
4159 	    pedwarn_c90 (loc,
4160 			 (pedantic && !flag_isoc99)
4161 			 ? OPT_Wpedantic
4162 			 : OPT_Wdeclaration_after_statement,
4163 			 "ISO C90 forbids mixed declarations and code");
4164 	  last_stmt = false;
4165 	}
4166       else if (!last_label
4167 	       && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4168 	{
4169 	  /* __extension__ can start a declaration, but is also an
4170 	     unary operator that can start an expression.  Consume all
4171 	     but the last of a possible series of __extension__ to
4172 	     determine which.  */
4173 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4174 		 && (c_parser_peek_2nd_token (parser)->keyword
4175 		     == RID_EXTENSION))
4176 	    c_parser_consume_token (parser);
4177 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4178 	    {
4179 	      int ext;
4180 	      ext = disable_extension_diagnostics ();
4181 	      c_parser_consume_token (parser);
4182 	      last_label = false;
4183 	      mark_valid_location_for_stdc_pragma (false);
4184 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
4185 					     true, NULL);
4186 	      /* Following the old parser, __extension__ does not
4187 		 disable this diagnostic.  */
4188 	      restore_extension_diagnostics (ext);
4189 	      if (last_stmt)
4190 		pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4191 			     ? OPT_Wpedantic
4192 			     : OPT_Wdeclaration_after_statement,
4193 			     "ISO C90 forbids mixed declarations and code");
4194 	      last_stmt = false;
4195 	    }
4196 	  else
4197 	    goto statement;
4198 	}
4199       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4200 	{
4201 	  /* External pragmas, and some omp pragmas, are not associated
4202 	     with regular c code, and so are not to be considered statements
4203 	     syntactically.  This ensures that the user doesn't put them
4204 	     places that would turn into syntax errors if the directive
4205 	     were ignored.  */
4206 	  if (c_parser_pragma (parser, pragma_compound))
4207 	    last_label = false, last_stmt = true;
4208 	}
4209       else if (c_parser_next_token_is (parser, CPP_EOF))
4210 	{
4211 	  mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4212 	  c_parser_error (parser, "expected declaration or statement");
4213 	  return;
4214 	}
4215       else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4216         {
4217           if (parser->in_if_block)
4218             {
4219 	      mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4220               error_at (loc, """expected %<}%> before %<else%>");
4221               return;
4222             }
4223           else
4224             {
4225               error_at (loc, "%<else%> without a previous %<if%>");
4226               c_parser_consume_token (parser);
4227               continue;
4228             }
4229         }
4230       else
4231 	{
4232 	statement:
4233 	  last_label = false;
4234 	  last_stmt = true;
4235 	  mark_valid_location_for_stdc_pragma (false);
4236 	  c_parser_statement_after_labels (parser);
4237 	}
4238 
4239       parser->error = false;
4240     }
4241   if (last_label)
4242     error_at (label_loc, "label at end of compound statement");
4243   c_parser_consume_token (parser);
4244   /* Restore the value we started with.  */
4245   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4246 }
4247 
4248 /* Parse a label (C90 6.6.1, C99 6.8.1).
4249 
4250    label:
4251      identifier : attributes[opt]
4252      case constant-expression :
4253      default :
4254 
4255    GNU extensions:
4256 
4257    label:
4258      case constant-expression ... constant-expression :
4259 
4260    The use of attributes on labels is a GNU extension.  The syntax in
4261    GNU C accepts any expressions without commas, non-constant
4262    expressions being rejected later.  */
4263 
4264 static void
4265 c_parser_label (c_parser *parser)
4266 {
4267   location_t loc1 = c_parser_peek_token (parser)->location;
4268   tree label = NULL_TREE;
4269   if (c_parser_next_token_is_keyword (parser, RID_CASE))
4270     {
4271       tree exp1, exp2;
4272       c_parser_consume_token (parser);
4273       exp1 = c_parser_expr_no_commas (parser, NULL).value;
4274       if (c_parser_next_token_is (parser, CPP_COLON))
4275 	{
4276 	  c_parser_consume_token (parser);
4277 	  label = do_case (loc1, exp1, NULL_TREE);
4278 	}
4279       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4280 	{
4281 	  c_parser_consume_token (parser);
4282 	  exp2 = c_parser_expr_no_commas (parser, NULL).value;
4283 	  if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4284 	    label = do_case (loc1, exp1, exp2);
4285 	}
4286       else
4287 	c_parser_error (parser, "expected %<:%> or %<...%>");
4288     }
4289   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4290     {
4291       c_parser_consume_token (parser);
4292       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4293 	label = do_case (loc1, NULL_TREE, NULL_TREE);
4294     }
4295   else
4296     {
4297       tree name = c_parser_peek_token (parser)->value;
4298       tree tlab;
4299       tree attrs;
4300       location_t loc2 = c_parser_peek_token (parser)->location;
4301       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4302       c_parser_consume_token (parser);
4303       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4304       c_parser_consume_token (parser);
4305       attrs = c_parser_attributes (parser);
4306       tlab = define_label (loc2, name);
4307       if (tlab)
4308 	{
4309 	  decl_attributes (&tlab, attrs, 0);
4310 	  label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4311 	}
4312     }
4313   if (label)
4314     {
4315       if (c_parser_next_tokens_start_declaration (parser))
4316 	{
4317 	  error_at (c_parser_peek_token (parser)->location,
4318 		    "a label can only be part of a statement and "
4319 		    "a declaration is not a statement");
4320 	  c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4321 					 /*static_assert_ok*/ true,
4322 					 /*empty_ok*/ true, /*nested*/ true,
4323 					 /*start_attr_ok*/ true, NULL);
4324 	}
4325     }
4326 }
4327 
4328 /* Parse a statement (C90 6.6, C99 6.8).
4329 
4330    statement:
4331      labeled-statement
4332      compound-statement
4333      expression-statement
4334      selection-statement
4335      iteration-statement
4336      jump-statement
4337 
4338    labeled-statement:
4339      label statement
4340 
4341    expression-statement:
4342      expression[opt] ;
4343 
4344    selection-statement:
4345      if-statement
4346      switch-statement
4347 
4348    iteration-statement:
4349      while-statement
4350      do-statement
4351      for-statement
4352 
4353    jump-statement:
4354      goto identifier ;
4355      continue ;
4356      break ;
4357      return expression[opt] ;
4358 
4359    GNU extensions:
4360 
4361    statement:
4362      asm-statement
4363 
4364    jump-statement:
4365      goto * expression ;
4366 
4367    Objective-C:
4368 
4369    statement:
4370      objc-throw-statement
4371      objc-try-catch-statement
4372      objc-synchronized-statement
4373 
4374    objc-throw-statement:
4375      @throw expression ;
4376      @throw ;
4377 
4378    OpenMP:
4379 
4380    statement:
4381      openmp-construct
4382 
4383    openmp-construct:
4384      parallel-construct
4385      for-construct
4386      sections-construct
4387      single-construct
4388      parallel-for-construct
4389      parallel-sections-construct
4390      master-construct
4391      critical-construct
4392      atomic-construct
4393      ordered-construct
4394 
4395    parallel-construct:
4396      parallel-directive structured-block
4397 
4398    for-construct:
4399      for-directive iteration-statement
4400 
4401    sections-construct:
4402      sections-directive section-scope
4403 
4404    single-construct:
4405      single-directive structured-block
4406 
4407    parallel-for-construct:
4408      parallel-for-directive iteration-statement
4409 
4410    parallel-sections-construct:
4411      parallel-sections-directive section-scope
4412 
4413    master-construct:
4414      master-directive structured-block
4415 
4416    critical-construct:
4417      critical-directive structured-block
4418 
4419    atomic-construct:
4420      atomic-directive expression-statement
4421 
4422    ordered-construct:
4423      ordered-directive structured-block
4424 
4425    Transactional Memory:
4426 
4427    statement:
4428      transaction-statement
4429      transaction-cancel-statement
4430 */
4431 
4432 static void
4433 c_parser_statement (c_parser *parser)
4434 {
4435   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4436 	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4437 	 || (c_parser_next_token_is (parser, CPP_NAME)
4438 	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4439     c_parser_label (parser);
4440   c_parser_statement_after_labels (parser);
4441 }
4442 
4443 /* Parse a statement, other than a labeled statement.  */
4444 
4445 static void
4446 c_parser_statement_after_labels (c_parser *parser)
4447 {
4448   location_t loc = c_parser_peek_token (parser)->location;
4449   tree stmt = NULL_TREE;
4450   bool in_if_block = parser->in_if_block;
4451   parser->in_if_block = false;
4452   switch (c_parser_peek_token (parser)->type)
4453     {
4454     case CPP_OPEN_BRACE:
4455       add_stmt (c_parser_compound_statement (parser));
4456       break;
4457     case CPP_KEYWORD:
4458       switch (c_parser_peek_token (parser)->keyword)
4459 	{
4460 	case RID_IF:
4461 	  c_parser_if_statement (parser);
4462 	  break;
4463 	case RID_SWITCH:
4464 	  c_parser_switch_statement (parser);
4465 	  break;
4466 	case RID_WHILE:
4467 	  c_parser_while_statement (parser);
4468 	  break;
4469 	case RID_DO:
4470 	  c_parser_do_statement (parser);
4471 	  break;
4472 	case RID_FOR:
4473 	  c_parser_for_statement (parser);
4474 	  break;
4475 	case RID_GOTO:
4476 	  c_parser_consume_token (parser);
4477 	  if (c_parser_next_token_is (parser, CPP_NAME))
4478 	    {
4479 	      stmt = c_finish_goto_label (loc,
4480 					  c_parser_peek_token (parser)->value);
4481 	      c_parser_consume_token (parser);
4482 	    }
4483 	  else if (c_parser_next_token_is (parser, CPP_MULT))
4484 	    {
4485 	      tree val;
4486 
4487 	      c_parser_consume_token (parser);
4488 	      val = c_parser_expression (parser).value;
4489 	      mark_exp_read (val);
4490 	      stmt = c_finish_goto_ptr (loc, val);
4491 	    }
4492 	  else
4493 	    c_parser_error (parser, "expected identifier or %<*%>");
4494 	  goto expect_semicolon;
4495 	case RID_CONTINUE:
4496 	  c_parser_consume_token (parser);
4497 	  stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4498 	  goto expect_semicolon;
4499 	case RID_BREAK:
4500 	  c_parser_consume_token (parser);
4501 	  stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4502 	  goto expect_semicolon;
4503 	case RID_RETURN:
4504 	  c_parser_consume_token (parser);
4505 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4506 	    {
4507 	      stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4508 	      c_parser_consume_token (parser);
4509 	    }
4510 	  else
4511 	    {
4512 	      struct c_expr expr = c_parser_expression_conv (parser);
4513 	      mark_exp_read (expr.value);
4514 	      stmt = c_finish_return (loc, expr.value, expr.original_type);
4515 	      goto expect_semicolon;
4516 	    }
4517 	  break;
4518 	case RID_ASM:
4519 	  stmt = c_parser_asm_statement (parser);
4520 	  break;
4521 	case RID_TRANSACTION_ATOMIC:
4522 	case RID_TRANSACTION_RELAXED:
4523 	  stmt = c_parser_transaction (parser,
4524 	      c_parser_peek_token (parser)->keyword);
4525 	  break;
4526 	case RID_TRANSACTION_CANCEL:
4527 	  stmt = c_parser_transaction_cancel (parser);
4528 	  goto expect_semicolon;
4529 	case RID_AT_THROW:
4530 	  gcc_assert (c_dialect_objc ());
4531 	  c_parser_consume_token (parser);
4532 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4533 	    {
4534 	      stmt = objc_build_throw_stmt (loc, NULL_TREE);
4535 	      c_parser_consume_token (parser);
4536 	    }
4537 	  else
4538 	    {
4539 	      tree expr = c_parser_expression (parser).value;
4540 	      expr = c_fully_fold (expr, false, NULL);
4541 	      stmt = objc_build_throw_stmt (loc, expr);
4542 	      goto expect_semicolon;
4543 	    }
4544 	  break;
4545 	case RID_AT_TRY:
4546 	  gcc_assert (c_dialect_objc ());
4547 	  c_parser_objc_try_catch_finally_statement (parser);
4548 	  break;
4549 	case RID_AT_SYNCHRONIZED:
4550 	  gcc_assert (c_dialect_objc ());
4551 	  c_parser_objc_synchronized_statement (parser);
4552 	  break;
4553 	default:
4554 	  goto expr_stmt;
4555 	}
4556       break;
4557     case CPP_SEMICOLON:
4558       c_parser_consume_token (parser);
4559       break;
4560     case CPP_CLOSE_PAREN:
4561     case CPP_CLOSE_SQUARE:
4562       /* Avoid infinite loop in error recovery:
4563 	 c_parser_skip_until_found stops at a closing nesting
4564 	 delimiter without consuming it, but here we need to consume
4565 	 it to proceed further.  */
4566       c_parser_error (parser, "expected statement");
4567       c_parser_consume_token (parser);
4568       break;
4569     case CPP_PRAGMA:
4570       c_parser_pragma (parser, pragma_stmt);
4571       break;
4572     default:
4573     expr_stmt:
4574       stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4575     expect_semicolon:
4576       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4577       break;
4578     }
4579   /* Two cases cannot and do not have line numbers associated: If stmt
4580      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4581      cannot hold line numbers.  But that's OK because the statement
4582      will either be changed to a MODIFY_EXPR during gimplification of
4583      the statement expr, or discarded.  If stmt was compound, but
4584      without new variables, we will have skipped the creation of a
4585      BIND and will have a bare STATEMENT_LIST.  But that's OK because
4586      (recursively) all of the component statements should already have
4587      line numbers assigned.  ??? Can we discard no-op statements
4588      earlier?  */
4589   if (CAN_HAVE_LOCATION_P (stmt)
4590       && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4591     SET_EXPR_LOCATION (stmt, loc);
4592 
4593   parser->in_if_block = in_if_block;
4594 }
4595 
4596 /* Parse the condition from an if, do, while or for statements.  */
4597 
4598 static tree
4599 c_parser_condition (c_parser *parser)
4600 {
4601   location_t loc = c_parser_peek_token (parser)->location;
4602   tree cond;
4603   cond = c_parser_expression_conv (parser).value;
4604   cond = c_objc_common_truthvalue_conversion (loc, cond);
4605   cond = c_fully_fold (cond, false, NULL);
4606   if (warn_sequence_point)
4607     verify_sequence_points (cond);
4608   return cond;
4609 }
4610 
4611 /* Parse a parenthesized condition from an if, do or while statement.
4612 
4613    condition:
4614      ( expression )
4615 */
4616 static tree
4617 c_parser_paren_condition (c_parser *parser)
4618 {
4619   tree cond;
4620   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4621     return error_mark_node;
4622   cond = c_parser_condition (parser);
4623   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4624   return cond;
4625 }
4626 
4627 /* Parse a statement which is a block in C99.  */
4628 
4629 static tree
4630 c_parser_c99_block_statement (c_parser *parser)
4631 {
4632   tree block = c_begin_compound_stmt (flag_isoc99);
4633   location_t loc = c_parser_peek_token (parser)->location;
4634   c_parser_statement (parser);
4635   return c_end_compound_stmt (loc, block, flag_isoc99);
4636 }
4637 
4638 /* Parse the body of an if statement.  This is just parsing a
4639    statement but (a) it is a block in C99, (b) we track whether the
4640    body is an if statement for the sake of -Wparentheses warnings, (c)
4641    we handle an empty body specially for the sake of -Wempty-body
4642    warnings, and (d) we call parser_compound_statement directly
4643    because c_parser_statement_after_labels resets
4644    parser->in_if_block.  */
4645 
4646 static tree
4647 c_parser_if_body (c_parser *parser, bool *if_p)
4648 {
4649   tree block = c_begin_compound_stmt (flag_isoc99);
4650   location_t body_loc = c_parser_peek_token (parser)->location;
4651   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4652 	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4653 	 || (c_parser_next_token_is (parser, CPP_NAME)
4654 	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4655     c_parser_label (parser);
4656   *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4657   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4658     {
4659       location_t loc = c_parser_peek_token (parser)->location;
4660       add_stmt (build_empty_stmt (loc));
4661       c_parser_consume_token (parser);
4662       if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4663 	warning_at (loc, OPT_Wempty_body,
4664 		    "suggest braces around empty body in an %<if%> statement");
4665     }
4666   else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4667     add_stmt (c_parser_compound_statement (parser));
4668   else
4669     c_parser_statement_after_labels (parser);
4670   return c_end_compound_stmt (body_loc, block, flag_isoc99);
4671 }
4672 
4673 /* Parse the else body of an if statement.  This is just parsing a
4674    statement but (a) it is a block in C99, (b) we handle an empty body
4675    specially for the sake of -Wempty-body warnings.  */
4676 
4677 static tree
4678 c_parser_else_body (c_parser *parser)
4679 {
4680   location_t else_loc = c_parser_peek_token (parser)->location;
4681   tree block = c_begin_compound_stmt (flag_isoc99);
4682   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4683 	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4684 	 || (c_parser_next_token_is (parser, CPP_NAME)
4685 	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4686     c_parser_label (parser);
4687   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4688     {
4689       location_t loc = c_parser_peek_token (parser)->location;
4690       warning_at (loc,
4691 		  OPT_Wempty_body,
4692 	         "suggest braces around empty body in an %<else%> statement");
4693       add_stmt (build_empty_stmt (loc));
4694       c_parser_consume_token (parser);
4695     }
4696   else
4697     c_parser_statement_after_labels (parser);
4698   return c_end_compound_stmt (else_loc, block, flag_isoc99);
4699 }
4700 
4701 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4702 
4703    if-statement:
4704      if ( expression ) statement
4705      if ( expression ) statement else statement
4706 */
4707 
4708 static void
4709 c_parser_if_statement (c_parser *parser)
4710 {
4711   tree block;
4712   location_t loc;
4713   tree cond;
4714   bool first_if = false;
4715   tree first_body, second_body;
4716   bool in_if_block;
4717 
4718   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4719   c_parser_consume_token (parser);
4720   block = c_begin_compound_stmt (flag_isoc99);
4721   loc = c_parser_peek_token (parser)->location;
4722   cond = c_parser_paren_condition (parser);
4723   in_if_block = parser->in_if_block;
4724   parser->in_if_block = true;
4725   first_body = c_parser_if_body (parser, &first_if);
4726   parser->in_if_block = in_if_block;
4727   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4728     {
4729       c_parser_consume_token (parser);
4730       second_body = c_parser_else_body (parser);
4731     }
4732   else
4733     second_body = NULL_TREE;
4734   c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4735   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4736 }
4737 
4738 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4739 
4740    switch-statement:
4741      switch (expression) statement
4742 */
4743 
4744 static void
4745 c_parser_switch_statement (c_parser *parser)
4746 {
4747   tree block, expr, body, save_break;
4748   location_t switch_loc = c_parser_peek_token (parser)->location;
4749   location_t switch_cond_loc;
4750   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4751   c_parser_consume_token (parser);
4752   block = c_begin_compound_stmt (flag_isoc99);
4753   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4754     {
4755       switch_cond_loc = c_parser_peek_token (parser)->location;
4756       expr = c_parser_expression (parser).value;
4757       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4758     }
4759   else
4760     {
4761       switch_cond_loc = UNKNOWN_LOCATION;
4762       expr = error_mark_node;
4763     }
4764   c_start_case (switch_loc, switch_cond_loc, expr);
4765   save_break = c_break_label;
4766   c_break_label = NULL_TREE;
4767   body = c_parser_c99_block_statement (parser);
4768   c_finish_case (body);
4769   if (c_break_label)
4770     {
4771       location_t here = c_parser_peek_token (parser)->location;
4772       tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4773       SET_EXPR_LOCATION (t, here);
4774       add_stmt (t);
4775     }
4776   c_break_label = save_break;
4777   add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4778 }
4779 
4780 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4781 
4782    while-statement:
4783       while (expression) statement
4784 */
4785 
4786 static void
4787 c_parser_while_statement (c_parser *parser)
4788 {
4789   tree block, cond, body, save_break, save_cont;
4790   location_t loc;
4791   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4792   c_parser_consume_token (parser);
4793   block = c_begin_compound_stmt (flag_isoc99);
4794   loc = c_parser_peek_token (parser)->location;
4795   cond = c_parser_paren_condition (parser);
4796   save_break = c_break_label;
4797   c_break_label = NULL_TREE;
4798   save_cont = c_cont_label;
4799   c_cont_label = NULL_TREE;
4800   body = c_parser_c99_block_statement (parser);
4801   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4802   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4803   c_break_label = save_break;
4804   c_cont_label = save_cont;
4805 }
4806 
4807 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4808 
4809    do-statement:
4810      do statement while ( expression ) ;
4811 */
4812 
4813 static void
4814 c_parser_do_statement (c_parser *parser)
4815 {
4816   tree block, cond, body, save_break, save_cont, new_break, new_cont;
4817   location_t loc;
4818   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4819   c_parser_consume_token (parser);
4820   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4821     warning_at (c_parser_peek_token (parser)->location,
4822 		OPT_Wempty_body,
4823 		"suggest braces around empty body in %<do%> statement");
4824   block = c_begin_compound_stmt (flag_isoc99);
4825   loc = c_parser_peek_token (parser)->location;
4826   save_break = c_break_label;
4827   c_break_label = NULL_TREE;
4828   save_cont = c_cont_label;
4829   c_cont_label = NULL_TREE;
4830   body = c_parser_c99_block_statement (parser);
4831   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4832   new_break = c_break_label;
4833   c_break_label = save_break;
4834   new_cont = c_cont_label;
4835   c_cont_label = save_cont;
4836   cond = c_parser_paren_condition (parser);
4837   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4838     c_parser_skip_to_end_of_block_or_statement (parser);
4839   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4840   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4841 }
4842 
4843 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4844 
4845    for-statement:
4846      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4847      for ( nested-declaration expression[opt] ; expression[opt] ) statement
4848 
4849    The form with a declaration is new in C99.
4850 
4851    ??? In accordance with the old parser, the declaration may be a
4852    nested function, which is then rejected in check_for_loop_decls,
4853    but does it make any sense for this to be included in the grammar?
4854    Note in particular that the nested function does not include a
4855    trailing ';', whereas the "declaration" production includes one.
4856    Also, can we reject bad declarations earlier and cheaper than
4857    check_for_loop_decls?
4858 
4859    In Objective-C, there are two additional variants:
4860 
4861    foreach-statement:
4862      for ( expression in expresssion ) statement
4863      for ( declaration in expression ) statement
4864 
4865    This is inconsistent with C, because the second variant is allowed
4866    even if c99 is not enabled.
4867 
4868    The rest of the comment documents these Objective-C foreach-statement.
4869 
4870    Here is the canonical example of the first variant:
4871     for (object in array)    { do something with object }
4872    we call the first expression ("object") the "object_expression" and
4873    the second expression ("array") the "collection_expression".
4874    object_expression must be an lvalue of type "id" (a generic Objective-C
4875    object) because the loop works by assigning to object_expression the
4876    various objects from the collection_expression.  collection_expression
4877    must evaluate to something of type "id" which responds to the method
4878    countByEnumeratingWithState:objects:count:.
4879 
4880    The canonical example of the second variant is:
4881     for (id object in array)    { do something with object }
4882    which is completely equivalent to
4883     {
4884       id object;
4885       for (object in array) { do something with object }
4886     }
4887    Note that initizializing 'object' in some way (eg, "for ((object =
4888    xxx) in array) { do something with object }") is possibly
4889    technically valid, but completely pointless as 'object' will be
4890    assigned to something else as soon as the loop starts.  We should
4891    most likely reject it (TODO).
4892 
4893    The beginning of the Objective-C foreach-statement looks exactly
4894    like the beginning of the for-statement, and we can tell it is a
4895    foreach-statement only because the initial declaration or
4896    expression is terminated by 'in' instead of ';'.
4897 */
4898 
4899 static void
4900 c_parser_for_statement (c_parser *parser)
4901 {
4902   tree block, cond, incr, save_break, save_cont, body;
4903   /* The following are only used when parsing an ObjC foreach statement.  */
4904   tree object_expression;
4905   /* Silence the bogus uninitialized warning.  */
4906   tree collection_expression = NULL;
4907   location_t loc = c_parser_peek_token (parser)->location;
4908   location_t for_loc = c_parser_peek_token (parser)->location;
4909   bool is_foreach_statement = false;
4910   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4911   c_parser_consume_token (parser);
4912   /* Open a compound statement in Objective-C as well, just in case this is
4913      as foreach expression.  */
4914   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4915   cond = error_mark_node;
4916   incr = error_mark_node;
4917   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4918     {
4919       /* Parse the initialization declaration or expression.  */
4920       object_expression = error_mark_node;
4921       parser->objc_could_be_foreach_context = c_dialect_objc ();
4922       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4923 	{
4924 	  parser->objc_could_be_foreach_context = false;
4925 	  c_parser_consume_token (parser);
4926 	  c_finish_expr_stmt (loc, NULL_TREE);
4927 	}
4928       else if (c_parser_next_tokens_start_declaration (parser))
4929 	{
4930 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4931 					 &object_expression);
4932 	  parser->objc_could_be_foreach_context = false;
4933 
4934 	  if (c_parser_next_token_is_keyword (parser, RID_IN))
4935 	    {
4936 	      c_parser_consume_token (parser);
4937 	      is_foreach_statement = true;
4938 	      if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4939 		c_parser_error (parser, "multiple iterating variables in fast enumeration");
4940 	    }
4941 	  else
4942 	    check_for_loop_decls (for_loc, flag_isoc99);
4943 	}
4944       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4945 	{
4946 	  /* __extension__ can start a declaration, but is also an
4947 	     unary operator that can start an expression.  Consume all
4948 	     but the last of a possible series of __extension__ to
4949 	     determine which.  */
4950 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4951 		 && (c_parser_peek_2nd_token (parser)->keyword
4952 		     == RID_EXTENSION))
4953 	    c_parser_consume_token (parser);
4954 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4955 	    {
4956 	      int ext;
4957 	      ext = disable_extension_diagnostics ();
4958 	      c_parser_consume_token (parser);
4959 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
4960 					     true, &object_expression);
4961 	      parser->objc_could_be_foreach_context = false;
4962 
4963 	      restore_extension_diagnostics (ext);
4964 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
4965 		{
4966 		  c_parser_consume_token (parser);
4967 		  is_foreach_statement = true;
4968 		  if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4969 		    c_parser_error (parser, "multiple iterating variables in fast enumeration");
4970 		}
4971 	      else
4972 		check_for_loop_decls (for_loc, flag_isoc99);
4973 	    }
4974 	  else
4975 	    goto init_expr;
4976 	}
4977       else
4978 	{
4979 	init_expr:
4980 	  {
4981 	    tree init_expression;
4982 	    init_expression = c_parser_expression (parser).value;
4983 	    parser->objc_could_be_foreach_context = false;
4984 	    if (c_parser_next_token_is_keyword (parser, RID_IN))
4985 	      {
4986 		c_parser_consume_token (parser);
4987 		is_foreach_statement = true;
4988 		if (! lvalue_p (init_expression))
4989 		  c_parser_error (parser, "invalid iterating variable in fast enumeration");
4990 		object_expression = c_fully_fold (init_expression, false, NULL);
4991 	      }
4992 	    else
4993 	      {
4994 		c_finish_expr_stmt (loc, init_expression);
4995 		c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4996 	      }
4997 	  }
4998 	}
4999       /* Parse the loop condition.  In the case of a foreach
5000 	 statement, there is no loop condition.  */
5001       gcc_assert (!parser->objc_could_be_foreach_context);
5002       if (!is_foreach_statement)
5003 	{
5004 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5005 	    {
5006 	      c_parser_consume_token (parser);
5007 	      cond = NULL_TREE;
5008 	    }
5009 	  else
5010 	    {
5011 	      cond = c_parser_condition (parser);
5012 	      c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5013 	    }
5014 	}
5015       /* Parse the increment expression (the third expression in a
5016 	 for-statement).  In the case of a foreach-statement, this is
5017 	 the expression that follows the 'in'.  */
5018       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5019 	{
5020 	  if (is_foreach_statement)
5021 	    {
5022 	      c_parser_error (parser, "missing collection in fast enumeration");
5023 	      collection_expression = error_mark_node;
5024 	    }
5025 	  else
5026 	    incr = c_process_expr_stmt (loc, NULL_TREE);
5027 	}
5028       else
5029 	{
5030 	  if (is_foreach_statement)
5031 	    collection_expression = c_fully_fold (c_parser_expression (parser).value,
5032 						  false, NULL);
5033 	  else
5034 	    incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
5035 	}
5036       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5037     }
5038   save_break = c_break_label;
5039   c_break_label = NULL_TREE;
5040   save_cont = c_cont_label;
5041   c_cont_label = NULL_TREE;
5042   body = c_parser_c99_block_statement (parser);
5043   if (is_foreach_statement)
5044     objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5045   else
5046     c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5047   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5048   c_break_label = save_break;
5049   c_cont_label = save_cont;
5050 }
5051 
5052 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
5053    statement with inputs, outputs, clobbers, and volatile tag
5054    allowed.
5055 
5056    asm-statement:
5057      asm type-qualifier[opt] ( asm-argument ) ;
5058      asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5059 
5060    asm-argument:
5061      asm-string-literal
5062      asm-string-literal : asm-operands[opt]
5063      asm-string-literal : asm-operands[opt] : asm-operands[opt]
5064      asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5065 
5066    asm-goto-argument:
5067      asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5068        : asm-goto-operands
5069 
5070    Qualifiers other than volatile are accepted in the syntax but
5071    warned for.  */
5072 
5073 static tree
5074 c_parser_asm_statement (c_parser *parser)
5075 {
5076   tree quals, str, outputs, inputs, clobbers, labels, ret;
5077   bool simple, is_goto;
5078   location_t asm_loc = c_parser_peek_token (parser)->location;
5079   int section, nsections;
5080 
5081   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5082   c_parser_consume_token (parser);
5083   if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5084     {
5085       quals = c_parser_peek_token (parser)->value;
5086       c_parser_consume_token (parser);
5087     }
5088   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5089 	   || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5090     {
5091       warning_at (c_parser_peek_token (parser)->location,
5092 		  0,
5093 		  "%E qualifier ignored on asm",
5094 		  c_parser_peek_token (parser)->value);
5095       quals = NULL_TREE;
5096       c_parser_consume_token (parser);
5097     }
5098   else
5099     quals = NULL_TREE;
5100 
5101   is_goto = false;
5102   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5103     {
5104       c_parser_consume_token (parser);
5105       is_goto = true;
5106     }
5107 
5108   /* ??? Follow the C++ parser rather than using the
5109      lex_untranslated_string kludge.  */
5110   parser->lex_untranslated_string = true;
5111   ret = NULL;
5112 
5113   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5114     goto error;
5115 
5116   str = c_parser_asm_string_literal (parser);
5117   if (str == NULL_TREE)
5118     goto error_close_paren;
5119 
5120   simple = true;
5121   outputs = NULL_TREE;
5122   inputs = NULL_TREE;
5123   clobbers = NULL_TREE;
5124   labels = NULL_TREE;
5125 
5126   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5127     goto done_asm;
5128 
5129   /* Parse each colon-delimited section of operands.  */
5130   nsections = 3 + is_goto;
5131   for (section = 0; section < nsections; ++section)
5132     {
5133       if (!c_parser_require (parser, CPP_COLON,
5134 			     is_goto
5135 			     ? "expected %<:%>"
5136 			     : "expected %<:%> or %<)%>"))
5137 	goto error_close_paren;
5138 
5139       /* Once past any colon, we're no longer a simple asm.  */
5140       simple = false;
5141 
5142       if ((!c_parser_next_token_is (parser, CPP_COLON)
5143 	   && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5144 	  || section == 3)
5145 	switch (section)
5146 	  {
5147 	  case 0:
5148 	    /* For asm goto, we don't allow output operands, but reserve
5149 	       the slot for a future extension that does allow them.  */
5150 	    if (!is_goto)
5151 	      outputs = c_parser_asm_operands (parser);
5152 	    break;
5153 	  case 1:
5154 	    inputs = c_parser_asm_operands (parser);
5155 	    break;
5156 	  case 2:
5157 	    clobbers = c_parser_asm_clobbers (parser);
5158 	    break;
5159 	  case 3:
5160 	    labels = c_parser_asm_goto_operands (parser);
5161 	    break;
5162 	  default:
5163 	    gcc_unreachable ();
5164 	  }
5165 
5166       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5167 	goto done_asm;
5168     }
5169 
5170  done_asm:
5171   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5172     {
5173       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5174       goto error;
5175     }
5176 
5177   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5178     c_parser_skip_to_end_of_block_or_statement (parser);
5179 
5180   ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5181 					       clobbers, labels, simple));
5182 
5183  error:
5184   parser->lex_untranslated_string = false;
5185   return ret;
5186 
5187  error_close_paren:
5188   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5189   goto error;
5190 }
5191 
5192 /* Parse asm operands, a GNU extension.
5193 
5194    asm-operands:
5195      asm-operand
5196      asm-operands , asm-operand
5197 
5198    asm-operand:
5199      asm-string-literal ( expression )
5200      [ identifier ] asm-string-literal ( expression )
5201 */
5202 
5203 static tree
5204 c_parser_asm_operands (c_parser *parser)
5205 {
5206   tree list = NULL_TREE;
5207   while (true)
5208     {
5209       tree name, str;
5210       struct c_expr expr;
5211       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5212 	{
5213 	  c_parser_consume_token (parser);
5214 	  if (c_parser_next_token_is (parser, CPP_NAME))
5215 	    {
5216 	      tree id = c_parser_peek_token (parser)->value;
5217 	      c_parser_consume_token (parser);
5218 	      name = build_string (IDENTIFIER_LENGTH (id),
5219 				   IDENTIFIER_POINTER (id));
5220 	    }
5221 	  else
5222 	    {
5223 	      c_parser_error (parser, "expected identifier");
5224 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5225 	      return NULL_TREE;
5226 	    }
5227 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5228 				     "expected %<]%>");
5229 	}
5230       else
5231 	name = NULL_TREE;
5232       str = c_parser_asm_string_literal (parser);
5233       if (str == NULL_TREE)
5234 	return NULL_TREE;
5235       parser->lex_untranslated_string = false;
5236       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5237 	{
5238 	  parser->lex_untranslated_string = true;
5239 	  return NULL_TREE;
5240 	}
5241       expr = c_parser_expression (parser);
5242       mark_exp_read (expr.value);
5243       parser->lex_untranslated_string = true;
5244       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5245 	{
5246 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5247 	  return NULL_TREE;
5248 	}
5249       list = chainon (list, build_tree_list (build_tree_list (name, str),
5250 					     expr.value));
5251       if (c_parser_next_token_is (parser, CPP_COMMA))
5252 	c_parser_consume_token (parser);
5253       else
5254 	break;
5255     }
5256   return list;
5257 }
5258 
5259 /* Parse asm clobbers, a GNU extension.
5260 
5261    asm-clobbers:
5262      asm-string-literal
5263      asm-clobbers , asm-string-literal
5264 */
5265 
5266 static tree
5267 c_parser_asm_clobbers (c_parser *parser)
5268 {
5269   tree list = NULL_TREE;
5270   while (true)
5271     {
5272       tree str = c_parser_asm_string_literal (parser);
5273       if (str)
5274 	list = tree_cons (NULL_TREE, str, list);
5275       else
5276 	return NULL_TREE;
5277       if (c_parser_next_token_is (parser, CPP_COMMA))
5278 	c_parser_consume_token (parser);
5279       else
5280 	break;
5281     }
5282   return list;
5283 }
5284 
5285 /* Parse asm goto labels, a GNU extension.
5286 
5287    asm-goto-operands:
5288      identifier
5289      asm-goto-operands , identifier
5290 */
5291 
5292 static tree
5293 c_parser_asm_goto_operands (c_parser *parser)
5294 {
5295   tree list = NULL_TREE;
5296   while (true)
5297     {
5298       tree name, label;
5299 
5300       if (c_parser_next_token_is (parser, CPP_NAME))
5301 	{
5302 	  c_token *tok = c_parser_peek_token (parser);
5303 	  name = tok->value;
5304 	  label = lookup_label_for_goto (tok->location, name);
5305 	  c_parser_consume_token (parser);
5306 	  TREE_USED (label) = 1;
5307 	}
5308       else
5309 	{
5310 	  c_parser_error (parser, "expected identifier");
5311 	  return NULL_TREE;
5312 	}
5313 
5314       name = build_string (IDENTIFIER_LENGTH (name),
5315 			   IDENTIFIER_POINTER (name));
5316       list = tree_cons (name, label, list);
5317       if (c_parser_next_token_is (parser, CPP_COMMA))
5318 	c_parser_consume_token (parser);
5319       else
5320 	return nreverse (list);
5321     }
5322 }
5323 
5324 /* Parse an expression other than a compound expression; that is, an
5325    assignment expression (C90 6.3.16, C99 6.5.16).  If AFTER is not
5326    NULL then it is an Objective-C message expression which is the
5327    primary-expression starting the expression as an initializer.
5328 
5329    assignment-expression:
5330      conditional-expression
5331      unary-expression assignment-operator assignment-expression
5332 
5333    assignment-operator: one of
5334      = *= /= %= += -= <<= >>= &= ^= |=
5335 
5336    In GNU C we accept any conditional expression on the LHS and
5337    diagnose the invalid lvalue rather than producing a syntax
5338    error.  */
5339 
5340 static struct c_expr
5341 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5342 {
5343   struct c_expr lhs, rhs, ret;
5344   enum tree_code code;
5345   location_t op_location, exp_location;
5346   gcc_assert (!after || c_dialect_objc ());
5347   lhs = c_parser_conditional_expression (parser, after);
5348   op_location = c_parser_peek_token (parser)->location;
5349   switch (c_parser_peek_token (parser)->type)
5350     {
5351     case CPP_EQ:
5352       code = NOP_EXPR;
5353       break;
5354     case CPP_MULT_EQ:
5355       code = MULT_EXPR;
5356       break;
5357     case CPP_DIV_EQ:
5358       code = TRUNC_DIV_EXPR;
5359       break;
5360     case CPP_MOD_EQ:
5361       code = TRUNC_MOD_EXPR;
5362       break;
5363     case CPP_PLUS_EQ:
5364       code = PLUS_EXPR;
5365       break;
5366     case CPP_MINUS_EQ:
5367       code = MINUS_EXPR;
5368       break;
5369     case CPP_LSHIFT_EQ:
5370       code = LSHIFT_EXPR;
5371       break;
5372     case CPP_RSHIFT_EQ:
5373       code = RSHIFT_EXPR;
5374       break;
5375     case CPP_AND_EQ:
5376       code = BIT_AND_EXPR;
5377       break;
5378     case CPP_XOR_EQ:
5379       code = BIT_XOR_EXPR;
5380       break;
5381     case CPP_OR_EQ:
5382       code = BIT_IOR_EXPR;
5383       break;
5384     default:
5385       return lhs;
5386     }
5387   c_parser_consume_token (parser);
5388   exp_location = c_parser_peek_token (parser)->location;
5389   rhs = c_parser_expr_no_commas (parser, NULL);
5390   rhs = default_function_array_read_conversion (exp_location, rhs);
5391   ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5392 				 code, exp_location, rhs.value,
5393 				 rhs.original_type);
5394   if (code == NOP_EXPR)
5395     ret.original_code = MODIFY_EXPR;
5396   else
5397     {
5398       TREE_NO_WARNING (ret.value) = 1;
5399       ret.original_code = ERROR_MARK;
5400     }
5401   ret.original_type = NULL;
5402   return ret;
5403 }
5404 
5405 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15).  If AFTER
5406    is not NULL then it is an Objective-C message expression which is
5407    the primary-expression starting the expression as an initializer.
5408 
5409    conditional-expression:
5410      logical-OR-expression
5411      logical-OR-expression ? expression : conditional-expression
5412 
5413    GNU extensions:
5414 
5415    conditional-expression:
5416      logical-OR-expression ? : conditional-expression
5417 */
5418 
5419 static struct c_expr
5420 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5421 {
5422   struct c_expr cond, exp1, exp2, ret;
5423   location_t cond_loc, colon_loc, middle_loc;
5424 
5425   gcc_assert (!after || c_dialect_objc ());
5426 
5427   cond = c_parser_binary_expression (parser, after, PREC_NONE);
5428 
5429   if (c_parser_next_token_is_not (parser, CPP_QUERY))
5430     return cond;
5431   cond_loc = c_parser_peek_token (parser)->location;
5432   cond = default_function_array_read_conversion (cond_loc, cond);
5433   c_parser_consume_token (parser);
5434   if (c_parser_next_token_is (parser, CPP_COLON))
5435     {
5436       tree eptype = NULL_TREE;
5437 
5438       middle_loc = c_parser_peek_token (parser)->location;
5439       pedwarn (middle_loc, OPT_Wpedantic,
5440 	       "ISO C forbids omitting the middle term of a ?: expression");
5441       warn_for_omitted_condop (middle_loc, cond.value);
5442       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5443 	{
5444 	  eptype = TREE_TYPE (cond.value);
5445 	  cond.value = TREE_OPERAND (cond.value, 0);
5446 	}
5447       /* Make sure first operand is calculated only once.  */
5448       exp1.value = c_save_expr (default_conversion (cond.value));
5449       if (eptype)
5450 	exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5451       exp1.original_type = NULL;
5452       cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5453       c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5454     }
5455   else
5456     {
5457       cond.value
5458 	= c_objc_common_truthvalue_conversion
5459 	(cond_loc, default_conversion (cond.value));
5460       c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5461       exp1 = c_parser_expression_conv (parser);
5462       mark_exp_read (exp1.value);
5463       c_inhibit_evaluation_warnings +=
5464 	((cond.value == truthvalue_true_node)
5465 	 - (cond.value == truthvalue_false_node));
5466     }
5467 
5468   colon_loc = c_parser_peek_token (parser)->location;
5469   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5470     {
5471       c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5472       ret.value = error_mark_node;
5473       ret.original_code = ERROR_MARK;
5474       ret.original_type = NULL;
5475       return ret;
5476     }
5477   {
5478     location_t exp2_loc = c_parser_peek_token (parser)->location;
5479     exp2 = c_parser_conditional_expression (parser, NULL);
5480     exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5481   }
5482   c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5483   ret.value = build_conditional_expr (colon_loc, cond.value,
5484 				      cond.original_code == C_MAYBE_CONST_EXPR,
5485 				      exp1.value, exp1.original_type,
5486 				      exp2.value, exp2.original_type);
5487   ret.original_code = ERROR_MARK;
5488   if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5489     ret.original_type = NULL;
5490   else
5491     {
5492       tree t1, t2;
5493 
5494       /* If both sides are enum type, the default conversion will have
5495 	 made the type of the result be an integer type.  We want to
5496 	 remember the enum types we started with.  */
5497       t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5498       t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5499       ret.original_type = ((t1 != error_mark_node
5500 			    && t2 != error_mark_node
5501 			    && (TYPE_MAIN_VARIANT (t1)
5502 				== TYPE_MAIN_VARIANT (t2)))
5503 			   ? t1
5504 			   : NULL);
5505     }
5506   return ret;
5507 }
5508 
5509 /* Parse a binary expression; that is, a logical-OR-expression (C90
5510    6.3.5-6.3.14, C99 6.5.5-6.5.14).  If AFTER is not NULL then it is
5511    an Objective-C message expression which is the primary-expression
5512    starting the expression as an initializer.  PREC is the starting
5513    precedence, usually PREC_NONE.
5514 
5515    multiplicative-expression:
5516      cast-expression
5517      multiplicative-expression * cast-expression
5518      multiplicative-expression / cast-expression
5519      multiplicative-expression % cast-expression
5520 
5521    additive-expression:
5522      multiplicative-expression
5523      additive-expression + multiplicative-expression
5524      additive-expression - multiplicative-expression
5525 
5526    shift-expression:
5527      additive-expression
5528      shift-expression << additive-expression
5529      shift-expression >> additive-expression
5530 
5531    relational-expression:
5532      shift-expression
5533      relational-expression < shift-expression
5534      relational-expression > shift-expression
5535      relational-expression <= shift-expression
5536      relational-expression >= shift-expression
5537 
5538    equality-expression:
5539      relational-expression
5540      equality-expression == relational-expression
5541      equality-expression != relational-expression
5542 
5543    AND-expression:
5544      equality-expression
5545      AND-expression & equality-expression
5546 
5547    exclusive-OR-expression:
5548      AND-expression
5549      exclusive-OR-expression ^ AND-expression
5550 
5551    inclusive-OR-expression:
5552      exclusive-OR-expression
5553      inclusive-OR-expression | exclusive-OR-expression
5554 
5555    logical-AND-expression:
5556      inclusive-OR-expression
5557      logical-AND-expression && inclusive-OR-expression
5558 
5559    logical-OR-expression:
5560      logical-AND-expression
5561      logical-OR-expression || logical-AND-expression
5562 */
5563 
5564 static struct c_expr
5565 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
5566 			    enum c_parser_prec prec)
5567 {
5568   /* A binary expression is parsed using operator-precedence parsing,
5569      with the operands being cast expressions.  All the binary
5570      operators are left-associative.  Thus a binary expression is of
5571      form:
5572 
5573      E0 op1 E1 op2 E2 ...
5574 
5575      which we represent on a stack.  On the stack, the precedence
5576      levels are strictly increasing.  When a new operator is
5577      encountered of higher precedence than that at the top of the
5578      stack, it is pushed; its LHS is the top expression, and its RHS
5579      is everything parsed until it is popped.  When a new operator is
5580      encountered with precedence less than or equal to that at the top
5581      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5582      by the result of the operation until the operator at the top of
5583      the stack has lower precedence than the new operator or there is
5584      only one element on the stack; then the top expression is the LHS
5585      of the new operator.  In the case of logical AND and OR
5586      expressions, we also need to adjust c_inhibit_evaluation_warnings
5587      as appropriate when the operators are pushed and popped.  */
5588 
5589   struct {
5590     /* The expression at this stack level.  */
5591     struct c_expr expr;
5592     /* The precedence of the operator on its left, PREC_NONE at the
5593        bottom of the stack.  */
5594     enum c_parser_prec prec;
5595     /* The operation on its left.  */
5596     enum tree_code op;
5597     /* The source location of this operation.  */
5598     location_t loc;
5599   } stack[NUM_PRECS];
5600   int sp;
5601   /* Location of the binary operator.  */
5602   location_t binary_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
5603 #define POP								      \
5604   do {									      \
5605     switch (stack[sp].op)						      \
5606       {									      \
5607       case TRUTH_ANDIF_EXPR:						      \
5608 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
5609 					  == truthvalue_false_node);	      \
5610 	break;								      \
5611       case TRUTH_ORIF_EXPR:						      \
5612 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
5613 					  == truthvalue_true_node);	      \
5614 	break;								      \
5615       default:								      \
5616 	break;								      \
5617       }									      \
5618     stack[sp - 1].expr							      \
5619       = default_function_array_read_conversion (stack[sp - 1].loc,	      \
5620 						stack[sp - 1].expr);	      \
5621     stack[sp].expr							      \
5622       = default_function_array_read_conversion (stack[sp].loc,		      \
5623 						stack[sp].expr);	      \
5624     stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc,		      \
5625 						 stack[sp].op,		      \
5626 						 stack[sp - 1].expr,	      \
5627 						 stack[sp].expr);	      \
5628     sp--;								      \
5629   } while (0)
5630   gcc_assert (!after || c_dialect_objc ());
5631   stack[0].loc = c_parser_peek_token (parser)->location;
5632   stack[0].expr = c_parser_cast_expression (parser, after);
5633   stack[0].prec = prec;
5634   sp = 0;
5635   while (true)
5636     {
5637       enum c_parser_prec oprec;
5638       enum tree_code ocode;
5639       if (parser->error)
5640 	goto out;
5641       switch (c_parser_peek_token (parser)->type)
5642 	{
5643 	case CPP_MULT:
5644 	  oprec = PREC_MULT;
5645 	  ocode = MULT_EXPR;
5646 	  break;
5647 	case CPP_DIV:
5648 	  oprec = PREC_MULT;
5649 	  ocode = TRUNC_DIV_EXPR;
5650 	  break;
5651 	case CPP_MOD:
5652 	  oprec = PREC_MULT;
5653 	  ocode = TRUNC_MOD_EXPR;
5654 	  break;
5655 	case CPP_PLUS:
5656 	  oprec = PREC_ADD;
5657 	  ocode = PLUS_EXPR;
5658 	  break;
5659 	case CPP_MINUS:
5660 	  oprec = PREC_ADD;
5661 	  ocode = MINUS_EXPR;
5662 	  break;
5663 	case CPP_LSHIFT:
5664 	  oprec = PREC_SHIFT;
5665 	  ocode = LSHIFT_EXPR;
5666 	  break;
5667 	case CPP_RSHIFT:
5668 	  oprec = PREC_SHIFT;
5669 	  ocode = RSHIFT_EXPR;
5670 	  break;
5671 	case CPP_LESS:
5672 	  oprec = PREC_REL;
5673 	  ocode = LT_EXPR;
5674 	  break;
5675 	case CPP_GREATER:
5676 	  oprec = PREC_REL;
5677 	  ocode = GT_EXPR;
5678 	  break;
5679 	case CPP_LESS_EQ:
5680 	  oprec = PREC_REL;
5681 	  ocode = LE_EXPR;
5682 	  break;
5683 	case CPP_GREATER_EQ:
5684 	  oprec = PREC_REL;
5685 	  ocode = GE_EXPR;
5686 	  break;
5687 	case CPP_EQ_EQ:
5688 	  oprec = PREC_EQ;
5689 	  ocode = EQ_EXPR;
5690 	  break;
5691 	case CPP_NOT_EQ:
5692 	  oprec = PREC_EQ;
5693 	  ocode = NE_EXPR;
5694 	  break;
5695 	case CPP_AND:
5696 	  oprec = PREC_BITAND;
5697 	  ocode = BIT_AND_EXPR;
5698 	  break;
5699 	case CPP_XOR:
5700 	  oprec = PREC_BITXOR;
5701 	  ocode = BIT_XOR_EXPR;
5702 	  break;
5703 	case CPP_OR:
5704 	  oprec = PREC_BITOR;
5705 	  ocode = BIT_IOR_EXPR;
5706 	  break;
5707 	case CPP_AND_AND:
5708 	  oprec = PREC_LOGAND;
5709 	  ocode = TRUTH_ANDIF_EXPR;
5710 	  break;
5711 	case CPP_OR_OR:
5712 	  oprec = PREC_LOGOR;
5713 	  ocode = TRUTH_ORIF_EXPR;
5714 	  break;
5715 	default:
5716 	  /* Not a binary operator, so end of the binary
5717 	     expression.  */
5718 	  goto out;
5719 	}
5720       binary_loc = c_parser_peek_token (parser)->location;
5721       while (oprec <= stack[sp].prec)
5722 	{
5723 	  if (sp == 0)
5724 	    goto out;
5725 	  POP;
5726 	}
5727       c_parser_consume_token (parser);
5728       switch (ocode)
5729 	{
5730 	case TRUTH_ANDIF_EXPR:
5731 	  stack[sp].expr
5732 	    = default_function_array_read_conversion (stack[sp].loc,
5733 						      stack[sp].expr);
5734 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
5735 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
5736 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
5737 					    == truthvalue_false_node);
5738 	  break;
5739 	case TRUTH_ORIF_EXPR:
5740 	  stack[sp].expr
5741 	    = default_function_array_read_conversion (stack[sp].loc,
5742 						      stack[sp].expr);
5743 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
5744 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
5745 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
5746 					    == truthvalue_true_node);
5747 	  break;
5748 	default:
5749 	  break;
5750 	}
5751       sp++;
5752       stack[sp].loc = binary_loc;
5753       stack[sp].expr = c_parser_cast_expression (parser, NULL);
5754       stack[sp].prec = oprec;
5755       stack[sp].op = ocode;
5756       stack[sp].loc = binary_loc;
5757     }
5758  out:
5759   while (sp > 0)
5760     POP;
5761   return stack[0].expr;
5762 #undef POP
5763 }
5764 
5765 /* Parse a cast expression (C90 6.3.4, C99 6.5.4).  If AFTER is not
5766    NULL then it is an Objective-C message expression which is the
5767    primary-expression starting the expression as an initializer.
5768 
5769    cast-expression:
5770      unary-expression
5771      ( type-name ) unary-expression
5772 */
5773 
5774 static struct c_expr
5775 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5776 {
5777   location_t cast_loc = c_parser_peek_token (parser)->location;
5778   gcc_assert (!after || c_dialect_objc ());
5779   if (after)
5780     return c_parser_postfix_expression_after_primary (parser,
5781 						      cast_loc, *after);
5782   /* If the expression begins with a parenthesized type name, it may
5783      be either a cast or a compound literal; we need to see whether
5784      the next character is '{' to tell the difference.  If not, it is
5785      an unary expression.  Full detection of unknown typenames here
5786      would require a 3-token lookahead.  */
5787   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5788       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5789     {
5790       struct c_type_name *type_name;
5791       struct c_expr ret;
5792       struct c_expr expr;
5793       c_parser_consume_token (parser);
5794       type_name = c_parser_type_name (parser);
5795       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5796       if (type_name == NULL)
5797 	{
5798 	  ret.value = error_mark_node;
5799 	  ret.original_code = ERROR_MARK;
5800 	  ret.original_type = NULL;
5801 	  return ret;
5802 	}
5803 
5804       /* Save casted types in the function's used types hash table.  */
5805       used_types_insert (type_name->specs->type);
5806 
5807       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5808 	return c_parser_postfix_expression_after_paren_type (parser, type_name,
5809 							     cast_loc);
5810       {
5811 	location_t expr_loc = c_parser_peek_token (parser)->location;
5812 	expr = c_parser_cast_expression (parser, NULL);
5813 	expr = default_function_array_read_conversion (expr_loc, expr);
5814       }
5815       ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5816       ret.original_code = ERROR_MARK;
5817       ret.original_type = NULL;
5818       return ret;
5819     }
5820   else
5821     return c_parser_unary_expression (parser);
5822 }
5823 
5824 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5825 
5826    unary-expression:
5827      postfix-expression
5828      ++ unary-expression
5829      -- unary-expression
5830      unary-operator cast-expression
5831      sizeof unary-expression
5832      sizeof ( type-name )
5833 
5834    unary-operator: one of
5835      & * + - ~ !
5836 
5837    GNU extensions:
5838 
5839    unary-expression:
5840      __alignof__ unary-expression
5841      __alignof__ ( type-name )
5842      && identifier
5843 
5844    (C11 permits _Alignof with type names only.)
5845 
5846    unary-operator: one of
5847      __extension__ __real__ __imag__
5848 
5849    Transactional Memory:
5850 
5851    unary-expression:
5852      transaction-expression
5853 
5854    In addition, the GNU syntax treats ++ and -- as unary operators, so
5855    they may be applied to cast expressions with errors for non-lvalues
5856    given later.  */
5857 
5858 static struct c_expr
5859 c_parser_unary_expression (c_parser *parser)
5860 {
5861   int ext;
5862   struct c_expr ret, op;
5863   location_t op_loc = c_parser_peek_token (parser)->location;
5864   location_t exp_loc;
5865   ret.original_code = ERROR_MARK;
5866   ret.original_type = NULL;
5867   switch (c_parser_peek_token (parser)->type)
5868     {
5869     case CPP_PLUS_PLUS:
5870       c_parser_consume_token (parser);
5871       exp_loc = c_parser_peek_token (parser)->location;
5872       op = c_parser_cast_expression (parser, NULL);
5873       op = default_function_array_read_conversion (exp_loc, op);
5874       return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5875     case CPP_MINUS_MINUS:
5876       c_parser_consume_token (parser);
5877       exp_loc = c_parser_peek_token (parser)->location;
5878       op = c_parser_cast_expression (parser, NULL);
5879       op = default_function_array_read_conversion (exp_loc, op);
5880       return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5881     case CPP_AND:
5882       c_parser_consume_token (parser);
5883       op = c_parser_cast_expression (parser, NULL);
5884       mark_exp_read (op.value);
5885       return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5886     case CPP_MULT:
5887       c_parser_consume_token (parser);
5888       exp_loc = c_parser_peek_token (parser)->location;
5889       op = c_parser_cast_expression (parser, NULL);
5890       op = default_function_array_read_conversion (exp_loc, op);
5891       ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5892       return ret;
5893     case CPP_PLUS:
5894       if (!c_dialect_objc () && !in_system_header)
5895 	warning_at (op_loc,
5896 		    OPT_Wtraditional,
5897 		    "traditional C rejects the unary plus operator");
5898       c_parser_consume_token (parser);
5899       exp_loc = c_parser_peek_token (parser)->location;
5900       op = c_parser_cast_expression (parser, NULL);
5901       op = default_function_array_read_conversion (exp_loc, op);
5902       return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5903     case CPP_MINUS:
5904       c_parser_consume_token (parser);
5905       exp_loc = c_parser_peek_token (parser)->location;
5906       op = c_parser_cast_expression (parser, NULL);
5907       op = default_function_array_read_conversion (exp_loc, op);
5908       return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5909     case CPP_COMPL:
5910       c_parser_consume_token (parser);
5911       exp_loc = c_parser_peek_token (parser)->location;
5912       op = c_parser_cast_expression (parser, NULL);
5913       op = default_function_array_read_conversion (exp_loc, op);
5914       return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5915     case CPP_NOT:
5916       c_parser_consume_token (parser);
5917       exp_loc = c_parser_peek_token (parser)->location;
5918       op = c_parser_cast_expression (parser, NULL);
5919       op = default_function_array_read_conversion (exp_loc, op);
5920       return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5921     case CPP_AND_AND:
5922       /* Refer to the address of a label as a pointer.  */
5923       c_parser_consume_token (parser);
5924       if (c_parser_next_token_is (parser, CPP_NAME))
5925 	{
5926 	  ret.value = finish_label_address_expr
5927 	    (c_parser_peek_token (parser)->value, op_loc);
5928 	  c_parser_consume_token (parser);
5929 	}
5930       else
5931 	{
5932 	  c_parser_error (parser, "expected identifier");
5933 	  ret.value = error_mark_node;
5934 	}
5935 	return ret;
5936     case CPP_KEYWORD:
5937       switch (c_parser_peek_token (parser)->keyword)
5938 	{
5939 	case RID_SIZEOF:
5940 	  return c_parser_sizeof_expression (parser);
5941 	case RID_ALIGNOF:
5942 	  return c_parser_alignof_expression (parser);
5943 	case RID_EXTENSION:
5944 	  c_parser_consume_token (parser);
5945 	  ext = disable_extension_diagnostics ();
5946 	  ret = c_parser_cast_expression (parser, NULL);
5947 	  restore_extension_diagnostics (ext);
5948 	  return ret;
5949 	case RID_REALPART:
5950 	  c_parser_consume_token (parser);
5951 	  exp_loc = c_parser_peek_token (parser)->location;
5952 	  op = c_parser_cast_expression (parser, NULL);
5953 	  op = default_function_array_conversion (exp_loc, op);
5954 	  return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5955 	case RID_IMAGPART:
5956 	  c_parser_consume_token (parser);
5957 	  exp_loc = c_parser_peek_token (parser)->location;
5958 	  op = c_parser_cast_expression (parser, NULL);
5959 	  op = default_function_array_conversion (exp_loc, op);
5960 	  return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5961 	case RID_TRANSACTION_ATOMIC:
5962 	case RID_TRANSACTION_RELAXED:
5963 	  return c_parser_transaction_expression (parser,
5964 	      c_parser_peek_token (parser)->keyword);
5965 	default:
5966 	  return c_parser_postfix_expression (parser);
5967 	}
5968     default:
5969       return c_parser_postfix_expression (parser);
5970     }
5971 }
5972 
5973 /* Parse a sizeof expression.  */
5974 
5975 static struct c_expr
5976 c_parser_sizeof_expression (c_parser *parser)
5977 {
5978   struct c_expr expr;
5979   location_t expr_loc;
5980   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5981   c_parser_consume_token (parser);
5982   c_inhibit_evaluation_warnings++;
5983   in_sizeof++;
5984   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5985       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5986     {
5987       /* Either sizeof ( type-name ) or sizeof unary-expression
5988 	 starting with a compound literal.  */
5989       struct c_type_name *type_name;
5990       c_parser_consume_token (parser);
5991       expr_loc = c_parser_peek_token (parser)->location;
5992       type_name = c_parser_type_name (parser);
5993       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5994       if (type_name == NULL)
5995 	{
5996 	  struct c_expr ret;
5997 	  c_inhibit_evaluation_warnings--;
5998 	  in_sizeof--;
5999 	  ret.value = error_mark_node;
6000 	  ret.original_code = ERROR_MARK;
6001 	  ret.original_type = NULL;
6002 	  return ret;
6003 	}
6004       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6005 	{
6006 	  expr = c_parser_postfix_expression_after_paren_type (parser,
6007 							       type_name,
6008 							       expr_loc);
6009 	  goto sizeof_expr;
6010 	}
6011       /* sizeof ( type-name ).  */
6012       c_inhibit_evaluation_warnings--;
6013       in_sizeof--;
6014       return c_expr_sizeof_type (expr_loc, type_name);
6015     }
6016   else
6017     {
6018       expr_loc = c_parser_peek_token (parser)->location;
6019       expr = c_parser_unary_expression (parser);
6020     sizeof_expr:
6021       c_inhibit_evaluation_warnings--;
6022       in_sizeof--;
6023       mark_exp_read (expr.value);
6024       if (TREE_CODE (expr.value) == COMPONENT_REF
6025 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
6026 	error_at (expr_loc, "%<sizeof%> applied to a bit-field");
6027       return c_expr_sizeof_expr (expr_loc, expr);
6028     }
6029 }
6030 
6031 /* Parse an alignof expression.  */
6032 
6033 static struct c_expr
6034 c_parser_alignof_expression (c_parser *parser)
6035 {
6036   struct c_expr expr;
6037   location_t loc = c_parser_peek_token (parser)->location;
6038   tree alignof_spelling = c_parser_peek_token (parser)->value;
6039   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
6040   /* A diagnostic is not required for the use of this identifier in
6041      the implementation namespace; only diagnose it for the C11
6042      spelling because of existing code using the other spellings.  */
6043   if (!flag_isoc11
6044       && strcmp (IDENTIFIER_POINTER (alignof_spelling), "_Alignof") == 0)
6045     {
6046       if (flag_isoc99)
6047 	pedwarn (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
6048 		 alignof_spelling);
6049       else
6050 	pedwarn (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
6051 		 alignof_spelling);
6052     }
6053   c_parser_consume_token (parser);
6054   c_inhibit_evaluation_warnings++;
6055   in_alignof++;
6056   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6057       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6058     {
6059       /* Either __alignof__ ( type-name ) or __alignof__
6060 	 unary-expression starting with a compound literal.  */
6061       location_t loc;
6062       struct c_type_name *type_name;
6063       struct c_expr ret;
6064       c_parser_consume_token (parser);
6065       loc = c_parser_peek_token (parser)->location;
6066       type_name = c_parser_type_name (parser);
6067       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6068       if (type_name == NULL)
6069 	{
6070 	  struct c_expr ret;
6071 	  c_inhibit_evaluation_warnings--;
6072 	  in_alignof--;
6073 	  ret.value = error_mark_node;
6074 	  ret.original_code = ERROR_MARK;
6075 	  ret.original_type = NULL;
6076 	  return ret;
6077 	}
6078       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6079 	{
6080 	  expr = c_parser_postfix_expression_after_paren_type (parser,
6081 							       type_name,
6082 							       loc);
6083 	  goto alignof_expr;
6084 	}
6085       /* alignof ( type-name ).  */
6086       c_inhibit_evaluation_warnings--;
6087       in_alignof--;
6088       ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
6089       ret.original_code = ERROR_MARK;
6090       ret.original_type = NULL;
6091       return ret;
6092     }
6093   else
6094     {
6095       struct c_expr ret;
6096       expr = c_parser_unary_expression (parser);
6097     alignof_expr:
6098       mark_exp_read (expr.value);
6099       c_inhibit_evaluation_warnings--;
6100       in_alignof--;
6101       pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
6102 	       alignof_spelling);
6103       ret.value = c_alignof_expr (loc, expr.value);
6104       ret.original_code = ERROR_MARK;
6105       ret.original_type = NULL;
6106       return ret;
6107     }
6108 }
6109 
6110 /* Helper function to read arguments of builtins which are interfaces
6111    for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6112    others.  The name of the builtin is passed using BNAME parameter.
6113    Function returns true if there were no errors while parsing and
6114    stores the arguments in CEXPR_LIST.  */
6115 static bool
6116 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6117 			   vec<c_expr_t, va_gc> **ret_cexpr_list)
6118 {
6119   location_t loc = c_parser_peek_token (parser)->location;
6120   vec<c_expr_t, va_gc> *cexpr_list;
6121   c_expr_t expr;
6122 
6123   *ret_cexpr_list = NULL;
6124   if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6125     {
6126       error_at (loc, "cannot take address of %qs", bname);
6127       return false;
6128     }
6129 
6130   c_parser_consume_token (parser);
6131 
6132   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6133     {
6134       c_parser_consume_token (parser);
6135       return true;
6136     }
6137 
6138   expr = c_parser_expr_no_commas (parser, NULL);
6139   vec_alloc (cexpr_list, 1);
6140   C_EXPR_APPEND (cexpr_list, expr);
6141   while (c_parser_next_token_is (parser, CPP_COMMA))
6142     {
6143       c_parser_consume_token (parser);
6144       expr = c_parser_expr_no_commas (parser, NULL);
6145       C_EXPR_APPEND (cexpr_list, expr);
6146     }
6147 
6148   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6149     return false;
6150 
6151   *ret_cexpr_list = cexpr_list;
6152   return true;
6153 }
6154 
6155 
6156 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6157 
6158    postfix-expression:
6159      primary-expression
6160      postfix-expression [ expression ]
6161      postfix-expression ( argument-expression-list[opt] )
6162      postfix-expression . identifier
6163      postfix-expression -> identifier
6164      postfix-expression ++
6165      postfix-expression --
6166      ( type-name ) { initializer-list }
6167      ( type-name ) { initializer-list , }
6168 
6169    argument-expression-list:
6170      argument-expression
6171      argument-expression-list , argument-expression
6172 
6173    primary-expression:
6174      identifier
6175      constant
6176      string-literal
6177      ( expression )
6178 
6179    GNU extensions:
6180 
6181    primary-expression:
6182      __func__
6183        (treated as a keyword in GNU C)
6184      __FUNCTION__
6185      __PRETTY_FUNCTION__
6186      ( compound-statement )
6187      __builtin_va_arg ( assignment-expression , type-name )
6188      __builtin_offsetof ( type-name , offsetof-member-designator )
6189      __builtin_choose_expr ( assignment-expression ,
6190 			     assignment-expression ,
6191 			     assignment-expression )
6192      __builtin_types_compatible_p ( type-name , type-name )
6193      __builtin_complex ( assignment-expression , assignment-expression )
6194      __builtin_shuffle ( assignment-expression , assignment-expression )
6195      __builtin_shuffle ( assignment-expression ,
6196 			 assignment-expression ,
6197 			 assignment-expression, )
6198 
6199    offsetof-member-designator:
6200      identifier
6201      offsetof-member-designator . identifier
6202      offsetof-member-designator [ expression ]
6203 
6204    Objective-C:
6205 
6206    primary-expression:
6207      [ objc-receiver objc-message-args ]
6208      @selector ( objc-selector-arg )
6209      @protocol ( identifier )
6210      @encode ( type-name )
6211      objc-string-literal
6212      Classname . identifier
6213 */
6214 
6215 static struct c_expr
6216 c_parser_postfix_expression (c_parser *parser)
6217 {
6218   struct c_expr expr, e1;
6219   struct c_type_name *t1, *t2;
6220   location_t loc = c_parser_peek_token (parser)->location;;
6221   expr.original_code = ERROR_MARK;
6222   expr.original_type = NULL;
6223   switch (c_parser_peek_token (parser)->type)
6224     {
6225     case CPP_NUMBER:
6226       expr.value = c_parser_peek_token (parser)->value;
6227       loc = c_parser_peek_token (parser)->location;
6228       c_parser_consume_token (parser);
6229       if (TREE_CODE (expr.value) == FIXED_CST
6230 	  && !targetm.fixed_point_supported_p ())
6231 	{
6232 	  error_at (loc, "fixed-point types not supported for this target");
6233 	  expr.value = error_mark_node;
6234 	}
6235       break;
6236     case CPP_CHAR:
6237     case CPP_CHAR16:
6238     case CPP_CHAR32:
6239     case CPP_WCHAR:
6240       expr.value = c_parser_peek_token (parser)->value;
6241       c_parser_consume_token (parser);
6242       break;
6243     case CPP_STRING:
6244     case CPP_STRING16:
6245     case CPP_STRING32:
6246     case CPP_WSTRING:
6247     case CPP_UTF8STRING:
6248       expr.value = c_parser_peek_token (parser)->value;
6249       expr.original_code = STRING_CST;
6250       c_parser_consume_token (parser);
6251       break;
6252     case CPP_OBJC_STRING:
6253       gcc_assert (c_dialect_objc ());
6254       expr.value
6255 	= objc_build_string_object (c_parser_peek_token (parser)->value);
6256       c_parser_consume_token (parser);
6257       break;
6258     case CPP_NAME:
6259       switch (c_parser_peek_token (parser)->id_kind)
6260 	{
6261 	case C_ID_ID:
6262 	  {
6263 	    tree id = c_parser_peek_token (parser)->value;
6264 	    c_parser_consume_token (parser);
6265 	    expr.value = build_external_ref (loc, id,
6266 					     (c_parser_peek_token (parser)->type
6267 					      == CPP_OPEN_PAREN),
6268 					     &expr.original_type);
6269 	    break;
6270 	  }
6271 	case C_ID_CLASSNAME:
6272 	  {
6273 	    /* Here we parse the Objective-C 2.0 Class.name dot
6274 	       syntax.  */
6275 	    tree class_name = c_parser_peek_token (parser)->value;
6276 	    tree component;
6277 	    c_parser_consume_token (parser);
6278 	    gcc_assert (c_dialect_objc ());
6279 	    if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6280 	      {
6281 		expr.value = error_mark_node;
6282 		break;
6283 	      }
6284 	    if (c_parser_next_token_is_not (parser, CPP_NAME))
6285 	      {
6286 		c_parser_error (parser, "expected identifier");
6287 		expr.value = error_mark_node;
6288 		break;
6289 	      }
6290 	    component = c_parser_peek_token (parser)->value;
6291 	    c_parser_consume_token (parser);
6292 	    expr.value = objc_build_class_component_ref (class_name,
6293 							 component);
6294 	    break;
6295 	  }
6296 	default:
6297 	  c_parser_error (parser, "expected expression");
6298 	  expr.value = error_mark_node;
6299 	  break;
6300 	}
6301       break;
6302     case CPP_OPEN_PAREN:
6303       /* A parenthesized expression, statement expression or compound
6304 	 literal.  */
6305       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
6306 	{
6307 	  /* A statement expression.  */
6308 	  tree stmt;
6309 	  location_t brace_loc;
6310 	  c_parser_consume_token (parser);
6311 	  brace_loc = c_parser_peek_token (parser)->location;
6312 	  c_parser_consume_token (parser);
6313 	  if (!building_stmt_list_p ())
6314 	    {
6315 	      error_at (loc, "braced-group within expression allowed "
6316 			"only inside a function");
6317 	      parser->error = true;
6318 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
6319 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6320 	      expr.value = error_mark_node;
6321 	      break;
6322 	    }
6323 	  stmt = c_begin_stmt_expr ();
6324 	  c_parser_compound_statement_nostart (parser);
6325 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6326 				     "expected %<)%>");
6327 	  pedwarn (loc, OPT_Wpedantic,
6328 		   "ISO C forbids braced-groups within expressions");
6329 	  expr.value = c_finish_stmt_expr (brace_loc, stmt);
6330 	  mark_exp_read (expr.value);
6331 	}
6332       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6333 	{
6334 	  /* A compound literal.  ??? Can we actually get here rather
6335 	     than going directly to
6336 	     c_parser_postfix_expression_after_paren_type from
6337 	     elsewhere?  */
6338 	  location_t loc;
6339 	  struct c_type_name *type_name;
6340 	  c_parser_consume_token (parser);
6341 	  loc = c_parser_peek_token (parser)->location;
6342 	  type_name = c_parser_type_name (parser);
6343 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6344 				     "expected %<)%>");
6345 	  if (type_name == NULL)
6346 	    {
6347 	      expr.value = error_mark_node;
6348 	    }
6349 	  else
6350 	    expr = c_parser_postfix_expression_after_paren_type (parser,
6351 								 type_name,
6352 								 loc);
6353 	}
6354       else
6355 	{
6356 	  /* A parenthesized expression.  */
6357 	  c_parser_consume_token (parser);
6358 	  expr = c_parser_expression (parser);
6359 	  if (TREE_CODE (expr.value) == MODIFY_EXPR)
6360 	    TREE_NO_WARNING (expr.value) = 1;
6361 	  if (expr.original_code != C_MAYBE_CONST_EXPR)
6362 	    expr.original_code = ERROR_MARK;
6363 	  /* Don't change EXPR.ORIGINAL_TYPE.  */
6364 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6365 				     "expected %<)%>");
6366 	}
6367       break;
6368     case CPP_KEYWORD:
6369       switch (c_parser_peek_token (parser)->keyword)
6370 	{
6371 	case RID_FUNCTION_NAME:
6372 	case RID_PRETTY_FUNCTION_NAME:
6373 	case RID_C99_FUNCTION_NAME:
6374 	  expr.value = fname_decl (loc,
6375 				   c_parser_peek_token (parser)->keyword,
6376 				   c_parser_peek_token (parser)->value);
6377 	  c_parser_consume_token (parser);
6378 	  break;
6379 	case RID_VA_ARG:
6380 	  c_parser_consume_token (parser);
6381 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6382 	    {
6383 	      expr.value = error_mark_node;
6384 	      break;
6385 	    }
6386 	  e1 = c_parser_expr_no_commas (parser, NULL);
6387 	  mark_exp_read (e1.value);
6388 	  e1.value = c_fully_fold (e1.value, false, NULL);
6389 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6390 	    {
6391 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6392 	      expr.value = error_mark_node;
6393 	      break;
6394 	    }
6395 	  loc = c_parser_peek_token (parser)->location;
6396 	  t1 = c_parser_type_name (parser);
6397 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6398 				     "expected %<)%>");
6399 	  if (t1 == NULL)
6400 	    {
6401 	      expr.value = error_mark_node;
6402 	    }
6403 	  else
6404 	    {
6405 	      tree type_expr = NULL_TREE;
6406 	      expr.value = c_build_va_arg (loc, e1.value,
6407 					   groktypename (t1, &type_expr, NULL));
6408 	      if (type_expr)
6409 		{
6410 		  expr.value = build2 (C_MAYBE_CONST_EXPR,
6411 				       TREE_TYPE (expr.value), type_expr,
6412 				       expr.value);
6413 		  C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6414 		}
6415 	    }
6416 	  break;
6417 	case RID_OFFSETOF:
6418 	  c_parser_consume_token (parser);
6419 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6420 	    {
6421 	      expr.value = error_mark_node;
6422 	      break;
6423 	    }
6424 	  t1 = c_parser_type_name (parser);
6425 	  if (t1 == NULL)
6426 	    parser->error = true;
6427 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6428             gcc_assert (parser->error);
6429 	  if (parser->error)
6430 	    {
6431 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6432 	      expr.value = error_mark_node;
6433 	      break;
6434 	    }
6435 
6436 	  {
6437 	    tree type = groktypename (t1, NULL, NULL);
6438 	    tree offsetof_ref;
6439 	    if (type == error_mark_node)
6440 	      offsetof_ref = error_mark_node;
6441 	    else
6442 	      {
6443 		offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6444 		SET_EXPR_LOCATION (offsetof_ref, loc);
6445 	      }
6446 	    /* Parse the second argument to __builtin_offsetof.  We
6447 	       must have one identifier, and beyond that we want to
6448 	       accept sub structure and sub array references.  */
6449 	    if (c_parser_next_token_is (parser, CPP_NAME))
6450 	      {
6451 		offsetof_ref = build_component_ref
6452 		  (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6453 		c_parser_consume_token (parser);
6454 		while (c_parser_next_token_is (parser, CPP_DOT)
6455 		       || c_parser_next_token_is (parser,
6456 						  CPP_OPEN_SQUARE)
6457 		       || c_parser_next_token_is (parser,
6458 						  CPP_DEREF))
6459 		  {
6460 		    if (c_parser_next_token_is (parser, CPP_DEREF))
6461 		      {
6462 			loc = c_parser_peek_token (parser)->location;
6463 			offsetof_ref = build_array_ref (loc,
6464 							offsetof_ref,
6465 							integer_zero_node);
6466 			goto do_dot;
6467 		      }
6468 		    else if (c_parser_next_token_is (parser, CPP_DOT))
6469 		      {
6470 		      do_dot:
6471 			c_parser_consume_token (parser);
6472 			if (c_parser_next_token_is_not (parser,
6473 							CPP_NAME))
6474 			  {
6475 			    c_parser_error (parser, "expected identifier");
6476 			    break;
6477 			  }
6478 			offsetof_ref = build_component_ref
6479 			  (loc, offsetof_ref,
6480 			   c_parser_peek_token (parser)->value);
6481 			c_parser_consume_token (parser);
6482 		      }
6483 		    else
6484 		      {
6485 			tree idx;
6486 			loc = c_parser_peek_token (parser)->location;
6487 			c_parser_consume_token (parser);
6488 			idx = c_parser_expression (parser).value;
6489 			idx = c_fully_fold (idx, false, NULL);
6490 			c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6491 						   "expected %<]%>");
6492 			offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6493 		      }
6494 		  }
6495 	      }
6496 	    else
6497 	      c_parser_error (parser, "expected identifier");
6498 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6499 				       "expected %<)%>");
6500 	    expr.value = fold_offsetof (offsetof_ref);
6501 	  }
6502 	  break;
6503 	case RID_CHOOSE_EXPR:
6504 	  {
6505 	    vec<c_expr_t, va_gc> *cexpr_list;
6506 	    c_expr_t *e1_p, *e2_p, *e3_p;
6507 	    tree c;
6508 
6509 	    c_parser_consume_token (parser);
6510 	    if (!c_parser_get_builtin_args (parser,
6511 					    "__builtin_choose_expr",
6512 					    &cexpr_list))
6513 	      {
6514 		expr.value = error_mark_node;
6515 		break;
6516 	      }
6517 
6518 	    if (vec_safe_length (cexpr_list) != 3)
6519 	      {
6520 		error_at (loc, "wrong number of arguments to "
6521 			       "%<__builtin_choose_expr%>");
6522 		expr.value = error_mark_node;
6523 		break;
6524 	      }
6525 
6526 	    e1_p = &(*cexpr_list)[0];
6527 	    e2_p = &(*cexpr_list)[1];
6528 	    e3_p = &(*cexpr_list)[2];
6529 
6530 	    c = e1_p->value;
6531 	    mark_exp_read (e2_p->value);
6532 	    mark_exp_read (e3_p->value);
6533 	    if (TREE_CODE (c) != INTEGER_CST
6534 		|| !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6535 	      error_at (loc,
6536 			"first argument to %<__builtin_choose_expr%> not"
6537 			" a constant");
6538 	    constant_expression_warning (c);
6539 	    expr = integer_zerop (c) ? *e3_p : *e2_p;
6540 	    break;
6541 	  }
6542 	case RID_TYPES_COMPATIBLE_P:
6543 	  c_parser_consume_token (parser);
6544 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6545 	    {
6546 	      expr.value = error_mark_node;
6547 	      break;
6548 	    }
6549 	  t1 = c_parser_type_name (parser);
6550 	  if (t1 == NULL)
6551 	    {
6552 	      expr.value = error_mark_node;
6553 	      break;
6554 	    }
6555 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6556 	    {
6557 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6558 	      expr.value = error_mark_node;
6559 	      break;
6560 	    }
6561 	  t2 = c_parser_type_name (parser);
6562 	  if (t2 == NULL)
6563 	    {
6564 	      expr.value = error_mark_node;
6565 	      break;
6566 	    }
6567 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6568 				     "expected %<)%>");
6569 	  {
6570 	    tree e1, e2;
6571 	    e1 = groktypename (t1, NULL, NULL);
6572 	    e2 = groktypename (t2, NULL, NULL);
6573 	    if (e1 == error_mark_node || e2 == error_mark_node)
6574 	      {
6575 		expr.value = error_mark_node;
6576 		break;
6577 	      }
6578 
6579 	    e1 = TYPE_MAIN_VARIANT (e1);
6580 	    e2 = TYPE_MAIN_VARIANT (e2);
6581 
6582 	    expr.value
6583 	      = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6584 	  }
6585 	  break;
6586 	case RID_BUILTIN_COMPLEX:
6587 	  {
6588 	    vec<c_expr_t, va_gc> *cexpr_list;
6589 	    c_expr_t *e1_p, *e2_p;
6590 
6591 	    c_parser_consume_token (parser);
6592 	    if (!c_parser_get_builtin_args (parser,
6593 					    "__builtin_complex",
6594 					    &cexpr_list))
6595 	      {
6596 		expr.value = error_mark_node;
6597 		break;
6598 	      }
6599 
6600 	    if (vec_safe_length (cexpr_list) != 2)
6601 	      {
6602 		error_at (loc, "wrong number of arguments to "
6603 			       "%<__builtin_complex%>");
6604 		expr.value = error_mark_node;
6605 		break;
6606 	      }
6607 
6608 	    e1_p = &(*cexpr_list)[0];
6609 	    e2_p = &(*cexpr_list)[1];
6610 
6611 	    mark_exp_read (e1_p->value);
6612 	    if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
6613 	      e1_p->value = convert (TREE_TYPE (e1_p->value),
6614 				     TREE_OPERAND (e1_p->value, 0));
6615 	    mark_exp_read (e2_p->value);
6616 	    if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
6617 	      e2_p->value = convert (TREE_TYPE (e2_p->value),
6618 				     TREE_OPERAND (e2_p->value, 0));
6619 	    if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
6620 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
6621 		|| !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
6622 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
6623 	      {
6624 		error_at (loc, "%<__builtin_complex%> operand "
6625 			  "not of real binary floating-point type");
6626 		expr.value = error_mark_node;
6627 		break;
6628 	      }
6629 	    if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
6630 		!= TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
6631 	      {
6632 		error_at (loc,
6633 			  "%<__builtin_complex%> operands of different types");
6634 		expr.value = error_mark_node;
6635 		break;
6636 	      }
6637 	    if (!flag_isoc99)
6638 	      pedwarn (loc, OPT_Wpedantic,
6639 		       "ISO C90 does not support complex types");
6640 	    expr.value = build2 (COMPLEX_EXPR,
6641 				 build_complex_type
6642 				   (TYPE_MAIN_VARIANT
6643 				     (TREE_TYPE (e1_p->value))),
6644 				 e1_p->value, e2_p->value);
6645 	    break;
6646 	  }
6647 	case RID_BUILTIN_SHUFFLE:
6648 	  {
6649 	    vec<c_expr_t, va_gc> *cexpr_list;
6650 	    unsigned int i;
6651 	    c_expr_t *p;
6652 
6653 	    c_parser_consume_token (parser);
6654 	    if (!c_parser_get_builtin_args (parser,
6655 					    "__builtin_shuffle",
6656 					    &cexpr_list))
6657 	      {
6658 		expr.value = error_mark_node;
6659 		break;
6660 	      }
6661 
6662 	    FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
6663 	      mark_exp_read (p->value);
6664 
6665 	    if (vec_safe_length (cexpr_list) == 2)
6666 	      expr.value =
6667 		c_build_vec_perm_expr
6668 		  (loc, (*cexpr_list)[0].value,
6669 		   NULL_TREE, (*cexpr_list)[1].value);
6670 
6671 	    else if (vec_safe_length (cexpr_list) == 3)
6672 	      expr.value =
6673 		c_build_vec_perm_expr
6674 		  (loc, (*cexpr_list)[0].value,
6675 		   (*cexpr_list)[1].value,
6676 		   (*cexpr_list)[2].value);
6677 	    else
6678 	      {
6679 		error_at (loc, "wrong number of arguments to "
6680 			       "%<__builtin_shuffle%>");
6681 		expr.value = error_mark_node;
6682 	      }
6683 	    break;
6684 	  }
6685 	case RID_AT_SELECTOR:
6686 	  gcc_assert (c_dialect_objc ());
6687 	  c_parser_consume_token (parser);
6688 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6689 	    {
6690 	      expr.value = error_mark_node;
6691 	      break;
6692 	    }
6693 	  {
6694 	    tree sel = c_parser_objc_selector_arg (parser);
6695 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6696 				       "expected %<)%>");
6697 	    expr.value = objc_build_selector_expr (loc, sel);
6698 	  }
6699 	  break;
6700 	case RID_AT_PROTOCOL:
6701 	  gcc_assert (c_dialect_objc ());
6702 	  c_parser_consume_token (parser);
6703 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6704 	    {
6705 	      expr.value = error_mark_node;
6706 	      break;
6707 	    }
6708 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
6709 	    {
6710 	      c_parser_error (parser, "expected identifier");
6711 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6712 	      expr.value = error_mark_node;
6713 	      break;
6714 	    }
6715 	  {
6716 	    tree id = c_parser_peek_token (parser)->value;
6717 	    c_parser_consume_token (parser);
6718 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6719 				       "expected %<)%>");
6720 	    expr.value = objc_build_protocol_expr (id);
6721 	  }
6722 	  break;
6723 	case RID_AT_ENCODE:
6724 	  /* Extension to support C-structures in the archiver.  */
6725 	  gcc_assert (c_dialect_objc ());
6726 	  c_parser_consume_token (parser);
6727 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6728 	    {
6729 	      expr.value = error_mark_node;
6730 	      break;
6731 	    }
6732 	  t1 = c_parser_type_name (parser);
6733 	  if (t1 == NULL)
6734 	    {
6735 	      expr.value = error_mark_node;
6736 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6737 	      break;
6738 	    }
6739 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6740 				     "expected %<)%>");
6741 	  {
6742 	    tree type = groktypename (t1, NULL, NULL);
6743 	    expr.value = objc_build_encode_expr (type);
6744 	  }
6745 	  break;
6746 	default:
6747 	  c_parser_error (parser, "expected expression");
6748 	  expr.value = error_mark_node;
6749 	  break;
6750 	}
6751       break;
6752     case CPP_OPEN_SQUARE:
6753       if (c_dialect_objc ())
6754 	{
6755 	  tree receiver, args;
6756 	  c_parser_consume_token (parser);
6757 	  receiver = c_parser_objc_receiver (parser);
6758 	  args = c_parser_objc_message_args (parser);
6759 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6760 				     "expected %<]%>");
6761 	  expr.value = objc_build_message_expr (receiver, args);
6762 	  break;
6763 	}
6764       /* Else fall through to report error.  */
6765     default:
6766       c_parser_error (parser, "expected expression");
6767       expr.value = error_mark_node;
6768       break;
6769     }
6770   return c_parser_postfix_expression_after_primary (parser, loc, expr);
6771 }
6772 
6773 /* Parse a postfix expression after a parenthesized type name: the
6774    brace-enclosed initializer of a compound literal, possibly followed
6775    by some postfix operators.  This is separate because it is not
6776    possible to tell until after the type name whether a cast
6777    expression has a cast or a compound literal, or whether the operand
6778    of sizeof is a parenthesized type name or starts with a compound
6779    literal.  TYPE_LOC is the location where TYPE_NAME starts--the
6780    location of the first token after the parentheses around the type
6781    name.  */
6782 
6783 static struct c_expr
6784 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6785 					      struct c_type_name *type_name,
6786 					      location_t type_loc)
6787 {
6788   tree type;
6789   struct c_expr init;
6790   bool non_const;
6791   struct c_expr expr;
6792   location_t start_loc;
6793   tree type_expr = NULL_TREE;
6794   bool type_expr_const = true;
6795   check_compound_literal_type (type_loc, type_name);
6796   start_init (NULL_TREE, NULL, 0);
6797   type = groktypename (type_name, &type_expr, &type_expr_const);
6798   start_loc = c_parser_peek_token (parser)->location;
6799   if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6800     {
6801       error_at (type_loc, "compound literal has variable size");
6802       type = error_mark_node;
6803     }
6804   init = c_parser_braced_init (parser, type, false);
6805   finish_init ();
6806   maybe_warn_string_init (type, init);
6807 
6808   if (type != error_mark_node
6809       && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6810       && current_function_decl)
6811     {
6812       error ("compound literal qualified by address-space qualifier");
6813       type = error_mark_node;
6814     }
6815 
6816   if (!flag_isoc99)
6817     pedwarn (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
6818   non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6819 	       ? CONSTRUCTOR_NON_CONST (init.value)
6820 	       : init.original_code == C_MAYBE_CONST_EXPR);
6821   non_const |= !type_expr_const;
6822   expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6823   expr.original_code = ERROR_MARK;
6824   expr.original_type = NULL;
6825   if (type_expr)
6826     {
6827       if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6828 	{
6829 	  gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6830 	  C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6831 	}
6832       else
6833 	{
6834 	  gcc_assert (!non_const);
6835 	  expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6836 			       type_expr, expr.value);
6837 	}
6838     }
6839   return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6840 }
6841 
6842 /* Callback function for sizeof_pointer_memaccess_warning to compare
6843    types.  */
6844 
6845 static bool
6846 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
6847 {
6848   return comptypes (type1, type2) == 1;
6849 }
6850 
6851 /* Parse a postfix expression after the initial primary or compound
6852    literal; that is, parse a series of postfix operators.
6853 
6854    EXPR_LOC is the location of the primary expression.  */
6855 
6856 static struct c_expr
6857 c_parser_postfix_expression_after_primary (c_parser *parser,
6858 					   location_t expr_loc,
6859 					   struct c_expr expr)
6860 {
6861   struct c_expr orig_expr;
6862   tree ident, idx;
6863   location_t sizeof_arg_loc[3];
6864   tree sizeof_arg[3];
6865   unsigned int i;
6866   vec<tree, va_gc> *exprlist;
6867   vec<tree, va_gc> *origtypes = NULL;
6868   while (true)
6869     {
6870       location_t op_loc = c_parser_peek_token (parser)->location;
6871       switch (c_parser_peek_token (parser)->type)
6872 	{
6873 	case CPP_OPEN_SQUARE:
6874 	  /* Array reference.  */
6875 	  c_parser_consume_token (parser);
6876 	  idx = c_parser_expression (parser).value;
6877 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6878 				     "expected %<]%>");
6879 	  expr.value = build_array_ref (op_loc, expr.value, idx);
6880 	  expr.original_code = ERROR_MARK;
6881 	  expr.original_type = NULL;
6882 	  break;
6883 	case CPP_OPEN_PAREN:
6884 	  /* Function call.  */
6885 	  c_parser_consume_token (parser);
6886 	  for (i = 0; i < 3; i++)
6887 	    {
6888 	      sizeof_arg[i] = NULL_TREE;
6889 	      sizeof_arg_loc[i] = UNKNOWN_LOCATION;
6890 	    }
6891 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6892 	    exprlist = NULL;
6893 	  else
6894 	    exprlist = c_parser_expr_list (parser, true, false, &origtypes,
6895 					   sizeof_arg_loc, sizeof_arg);
6896 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6897 				     "expected %<)%>");
6898 	  orig_expr = expr;
6899 	  mark_exp_read (expr.value);
6900 	  if (warn_sizeof_pointer_memaccess)
6901 	    sizeof_pointer_memaccess_warning (sizeof_arg_loc,
6902 					      expr.value, exprlist,
6903 					      sizeof_arg,
6904 					      sizeof_ptr_memacc_comptypes);
6905 	  /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6906 	     "(" after the FUNCNAME, which is what we have now.    */
6907 	  expr.value = c_build_function_call_vec (op_loc, expr.value, exprlist,
6908 						  origtypes);
6909 	  expr.original_code = ERROR_MARK;
6910 	  if (TREE_CODE (expr.value) == INTEGER_CST
6911 	      && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6912 	      && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6913 	      && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6914 	    expr.original_code = C_MAYBE_CONST_EXPR;
6915 	  expr.original_type = NULL;
6916 	  if (exprlist)
6917 	    {
6918 	      release_tree_vector (exprlist);
6919 	      release_tree_vector (origtypes);
6920 	    }
6921 	  break;
6922 	case CPP_DOT:
6923 	  /* Structure element reference.  */
6924 	  c_parser_consume_token (parser);
6925 	  expr = default_function_array_conversion (expr_loc, expr);
6926 	  if (c_parser_next_token_is (parser, CPP_NAME))
6927 	    ident = c_parser_peek_token (parser)->value;
6928 	  else
6929 	    {
6930 	      c_parser_error (parser, "expected identifier");
6931 	      expr.value = error_mark_node;
6932 	      expr.original_code = ERROR_MARK;
6933               expr.original_type = NULL;
6934 	      return expr;
6935 	    }
6936 	  c_parser_consume_token (parser);
6937 	  expr.value = build_component_ref (op_loc, expr.value, ident);
6938 	  expr.original_code = ERROR_MARK;
6939 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
6940 	    expr.original_type = NULL;
6941 	  else
6942 	    {
6943 	      /* Remember the original type of a bitfield.  */
6944 	      tree field = TREE_OPERAND (expr.value, 1);
6945 	      if (TREE_CODE (field) != FIELD_DECL)
6946 		expr.original_type = NULL;
6947 	      else
6948 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
6949 	    }
6950 	  break;
6951 	case CPP_DEREF:
6952 	  /* Structure element reference.  */
6953 	  c_parser_consume_token (parser);
6954 	  expr = default_function_array_conversion (expr_loc, expr);
6955 	  if (c_parser_next_token_is (parser, CPP_NAME))
6956 	    ident = c_parser_peek_token (parser)->value;
6957 	  else
6958 	    {
6959 	      c_parser_error (parser, "expected identifier");
6960 	      expr.value = error_mark_node;
6961 	      expr.original_code = ERROR_MARK;
6962 	      expr.original_type = NULL;
6963 	      return expr;
6964 	    }
6965 	  c_parser_consume_token (parser);
6966 	  expr.value = build_component_ref (op_loc,
6967 					    build_indirect_ref (op_loc,
6968 								expr.value,
6969 								RO_ARROW),
6970 					    ident);
6971 	  expr.original_code = ERROR_MARK;
6972 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
6973 	    expr.original_type = NULL;
6974 	  else
6975 	    {
6976 	      /* Remember the original type of a bitfield.  */
6977 	      tree field = TREE_OPERAND (expr.value, 1);
6978 	      if (TREE_CODE (field) != FIELD_DECL)
6979 		expr.original_type = NULL;
6980 	      else
6981 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
6982 	    }
6983 	  break;
6984 	case CPP_PLUS_PLUS:
6985 	  /* Postincrement.  */
6986 	  c_parser_consume_token (parser);
6987 	  expr = default_function_array_read_conversion (expr_loc, expr);
6988 	  expr.value = build_unary_op (op_loc,
6989 				       POSTINCREMENT_EXPR, expr.value, 0);
6990 	  expr.original_code = ERROR_MARK;
6991 	  expr.original_type = NULL;
6992 	  break;
6993 	case CPP_MINUS_MINUS:
6994 	  /* Postdecrement.  */
6995 	  c_parser_consume_token (parser);
6996 	  expr = default_function_array_read_conversion (expr_loc, expr);
6997 	  expr.value = build_unary_op (op_loc,
6998 				       POSTDECREMENT_EXPR, expr.value, 0);
6999 	  expr.original_code = ERROR_MARK;
7000 	  expr.original_type = NULL;
7001 	  break;
7002 	default:
7003 	  return expr;
7004 	}
7005     }
7006 }
7007 
7008 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7009 
7010    expression:
7011      assignment-expression
7012      expression , assignment-expression
7013 */
7014 
7015 static struct c_expr
7016 c_parser_expression (c_parser *parser)
7017 {
7018   struct c_expr expr;
7019   expr = c_parser_expr_no_commas (parser, NULL);
7020   while (c_parser_next_token_is (parser, CPP_COMMA))
7021     {
7022       struct c_expr next;
7023       tree lhsval;
7024       location_t loc = c_parser_peek_token (parser)->location;
7025       location_t expr_loc;
7026       c_parser_consume_token (parser);
7027       expr_loc = c_parser_peek_token (parser)->location;
7028       lhsval = expr.value;
7029       while (TREE_CODE (lhsval) == COMPOUND_EXPR)
7030 	lhsval = TREE_OPERAND (lhsval, 1);
7031       if (DECL_P (lhsval) || handled_component_p (lhsval))
7032 	mark_exp_read (lhsval);
7033       next = c_parser_expr_no_commas (parser, NULL);
7034       next = default_function_array_conversion (expr_loc, next);
7035       expr.value = build_compound_expr (loc, expr.value, next.value);
7036       expr.original_code = COMPOUND_EXPR;
7037       expr.original_type = next.original_type;
7038     }
7039   return expr;
7040 }
7041 
7042 /* Parse an expression and convert functions or arrays to
7043    pointers.  */
7044 
7045 static struct c_expr
7046 c_parser_expression_conv (c_parser *parser)
7047 {
7048   struct c_expr expr;
7049   location_t loc = c_parser_peek_token (parser)->location;
7050   expr = c_parser_expression (parser);
7051   expr = default_function_array_conversion (loc, expr);
7052   return expr;
7053 }
7054 
7055 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
7056    functions and arrays to pointers.  If FOLD_P, fold the expressions.
7057 
7058    nonempty-expr-list:
7059      assignment-expression
7060      nonempty-expr-list , assignment-expression
7061 */
7062 
7063 static vec<tree, va_gc> *
7064 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
7065 		    vec<tree, va_gc> **p_orig_types,
7066 		    location_t *sizeof_arg_loc, tree *sizeof_arg)
7067 {
7068   vec<tree, va_gc> *ret;
7069   vec<tree, va_gc> *orig_types;
7070   struct c_expr expr;
7071   location_t loc = c_parser_peek_token (parser)->location;
7072   location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
7073   unsigned int idx = 0;
7074 
7075   ret = make_tree_vector ();
7076   if (p_orig_types == NULL)
7077     orig_types = NULL;
7078   else
7079     orig_types = make_tree_vector ();
7080 
7081   if (sizeof_arg != NULL
7082       && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
7083     cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
7084   expr = c_parser_expr_no_commas (parser, NULL);
7085   if (convert_p)
7086     expr = default_function_array_read_conversion (loc, expr);
7087   if (fold_p)
7088     expr.value = c_fully_fold (expr.value, false, NULL);
7089   ret->quick_push (expr.value);
7090   if (orig_types)
7091     orig_types->quick_push (expr.original_type);
7092   if (sizeof_arg != NULL
7093       && cur_sizeof_arg_loc != UNKNOWN_LOCATION
7094       && expr.original_code == SIZEOF_EXPR)
7095     {
7096       sizeof_arg[0] = c_last_sizeof_arg;
7097       sizeof_arg_loc[0] = cur_sizeof_arg_loc;
7098     }
7099   while (c_parser_next_token_is (parser, CPP_COMMA))
7100     {
7101       c_parser_consume_token (parser);
7102       loc = c_parser_peek_token (parser)->location;
7103       if (sizeof_arg != NULL
7104 	  && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
7105 	cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
7106       else
7107 	cur_sizeof_arg_loc = UNKNOWN_LOCATION;
7108       expr = c_parser_expr_no_commas (parser, NULL);
7109       if (convert_p)
7110 	expr = default_function_array_read_conversion (loc, expr);
7111       if (fold_p)
7112 	expr.value = c_fully_fold (expr.value, false, NULL);
7113       vec_safe_push (ret, expr.value);
7114       if (orig_types)
7115 	vec_safe_push (orig_types, expr.original_type);
7116       if (++idx < 3
7117 	  && sizeof_arg != NULL
7118 	  && cur_sizeof_arg_loc != UNKNOWN_LOCATION
7119 	  && expr.original_code == SIZEOF_EXPR)
7120 	{
7121 	  sizeof_arg[idx] = c_last_sizeof_arg;
7122 	  sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
7123 	}
7124     }
7125   if (orig_types)
7126     *p_orig_types = orig_types;
7127   return ret;
7128 }
7129 
7130 /* Parse Objective-C-specific constructs.  */
7131 
7132 /* Parse an objc-class-definition.
7133 
7134    objc-class-definition:
7135      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7136        objc-class-instance-variables[opt] objc-methodprotolist @end
7137      @implementation identifier objc-superclass[opt]
7138        objc-class-instance-variables[opt]
7139      @interface identifier ( identifier ) objc-protocol-refs[opt]
7140        objc-methodprotolist @end
7141      @interface identifier ( ) objc-protocol-refs[opt]
7142        objc-methodprotolist @end
7143      @implementation identifier ( identifier )
7144 
7145    objc-superclass:
7146      : identifier
7147 
7148    "@interface identifier (" must start "@interface identifier (
7149    identifier ) ...": objc-methodprotolist in the first production may
7150    not start with a parenthesized identifier as a declarator of a data
7151    definition with no declaration specifiers if the objc-superclass,
7152    objc-protocol-refs and objc-class-instance-variables are omitted.  */
7153 
7154 static void
7155 c_parser_objc_class_definition (c_parser *parser, tree attributes)
7156 {
7157   bool iface_p;
7158   tree id1;
7159   tree superclass;
7160   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
7161     iface_p = true;
7162   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
7163     iface_p = false;
7164   else
7165     gcc_unreachable ();
7166 
7167   c_parser_consume_token (parser);
7168   if (c_parser_next_token_is_not (parser, CPP_NAME))
7169     {
7170       c_parser_error (parser, "expected identifier");
7171       return;
7172     }
7173   id1 = c_parser_peek_token (parser)->value;
7174   c_parser_consume_token (parser);
7175   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7176     {
7177       /* We have a category or class extension.  */
7178       tree id2;
7179       tree proto = NULL_TREE;
7180       c_parser_consume_token (parser);
7181       if (c_parser_next_token_is_not (parser, CPP_NAME))
7182 	{
7183 	  if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7184 	    {
7185 	      /* We have a class extension.  */
7186 	      id2 = NULL_TREE;
7187 	    }
7188 	  else
7189 	    {
7190 	      c_parser_error (parser, "expected identifier or %<)%>");
7191 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7192 	      return;
7193 	    }
7194 	}
7195       else
7196 	{
7197 	  id2 = c_parser_peek_token (parser)->value;
7198 	  c_parser_consume_token (parser);
7199 	}
7200       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7201       if (!iface_p)
7202 	{
7203 	  objc_start_category_implementation (id1, id2);
7204 	  return;
7205 	}
7206       if (c_parser_next_token_is (parser, CPP_LESS))
7207 	proto = c_parser_objc_protocol_refs (parser);
7208       objc_start_category_interface (id1, id2, proto, attributes);
7209       c_parser_objc_methodprotolist (parser);
7210       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7211       objc_finish_interface ();
7212       return;
7213     }
7214   if (c_parser_next_token_is (parser, CPP_COLON))
7215     {
7216       c_parser_consume_token (parser);
7217       if (c_parser_next_token_is_not (parser, CPP_NAME))
7218 	{
7219 	  c_parser_error (parser, "expected identifier");
7220 	  return;
7221 	}
7222       superclass = c_parser_peek_token (parser)->value;
7223       c_parser_consume_token (parser);
7224     }
7225   else
7226     superclass = NULL_TREE;
7227   if (iface_p)
7228     {
7229       tree proto = NULL_TREE;
7230       if (c_parser_next_token_is (parser, CPP_LESS))
7231 	proto = c_parser_objc_protocol_refs (parser);
7232       objc_start_class_interface (id1, superclass, proto, attributes);
7233     }
7234   else
7235     objc_start_class_implementation (id1, superclass);
7236   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7237     c_parser_objc_class_instance_variables (parser);
7238   if (iface_p)
7239     {
7240       objc_continue_interface ();
7241       c_parser_objc_methodprotolist (parser);
7242       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7243       objc_finish_interface ();
7244     }
7245   else
7246     {
7247       objc_continue_implementation ();
7248       return;
7249     }
7250 }
7251 
7252 /* Parse objc-class-instance-variables.
7253 
7254    objc-class-instance-variables:
7255      { objc-instance-variable-decl-list[opt] }
7256 
7257    objc-instance-variable-decl-list:
7258      objc-visibility-spec
7259      objc-instance-variable-decl ;
7260      ;
7261      objc-instance-variable-decl-list objc-visibility-spec
7262      objc-instance-variable-decl-list objc-instance-variable-decl ;
7263      objc-instance-variable-decl-list ;
7264 
7265    objc-visibility-spec:
7266      @private
7267      @protected
7268      @public
7269 
7270    objc-instance-variable-decl:
7271      struct-declaration
7272 */
7273 
7274 static void
7275 c_parser_objc_class_instance_variables (c_parser *parser)
7276 {
7277   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
7278   c_parser_consume_token (parser);
7279   while (c_parser_next_token_is_not (parser, CPP_EOF))
7280     {
7281       tree decls;
7282       /* Parse any stray semicolon.  */
7283       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7284 	{
7285 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
7286 		   "extra semicolon");
7287 	  c_parser_consume_token (parser);
7288 	  continue;
7289 	}
7290       /* Stop if at the end of the instance variables.  */
7291       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7292 	{
7293 	  c_parser_consume_token (parser);
7294 	  break;
7295 	}
7296       /* Parse any objc-visibility-spec.  */
7297       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
7298 	{
7299 	  c_parser_consume_token (parser);
7300 	  objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
7301 	  continue;
7302 	}
7303       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
7304 	{
7305 	  c_parser_consume_token (parser);
7306 	  objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
7307 	  continue;
7308 	}
7309       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
7310 	{
7311 	  c_parser_consume_token (parser);
7312 	  objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
7313 	  continue;
7314 	}
7315       else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
7316 	{
7317 	  c_parser_consume_token (parser);
7318 	  objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
7319 	  continue;
7320 	}
7321       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
7322 	{
7323 	  c_parser_pragma (parser, pragma_external);
7324 	  continue;
7325 	}
7326 
7327       /* Parse some comma-separated declarations.  */
7328       decls = c_parser_struct_declaration (parser);
7329       if (decls == NULL)
7330 	{
7331 	  /* There is a syntax error.  We want to skip the offending
7332 	     tokens up to the next ';' (included) or '}'
7333 	     (excluded).  */
7334 
7335 	  /* First, skip manually a ')' or ']'.  This is because they
7336 	     reduce the nesting level, so c_parser_skip_until_found()
7337 	     wouldn't be able to skip past them.  */
7338 	  c_token *token = c_parser_peek_token (parser);
7339 	  if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
7340 	    c_parser_consume_token (parser);
7341 
7342 	  /* Then, do the standard skipping.  */
7343 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7344 
7345 	  /* We hopefully recovered.  Start normal parsing again.  */
7346 	  parser->error = false;
7347 	  continue;
7348 	}
7349       else
7350 	{
7351 	  /* Comma-separated instance variables are chained together
7352 	     in reverse order; add them one by one.  */
7353 	  tree ivar = nreverse (decls);
7354 	  for (; ivar; ivar = DECL_CHAIN (ivar))
7355 	    objc_add_instance_variable (copy_node (ivar));
7356 	}
7357       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7358     }
7359 }
7360 
7361 /* Parse an objc-class-declaration.
7362 
7363    objc-class-declaration:
7364      @class identifier-list ;
7365 */
7366 
7367 static void
7368 c_parser_objc_class_declaration (c_parser *parser)
7369 {
7370   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
7371   c_parser_consume_token (parser);
7372   /* Any identifiers, including those declared as type names, are OK
7373      here.  */
7374   while (true)
7375     {
7376       tree id;
7377       if (c_parser_next_token_is_not (parser, CPP_NAME))
7378 	{
7379 	  c_parser_error (parser, "expected identifier");
7380 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7381 	  parser->error = false;
7382 	  return;
7383 	}
7384       id = c_parser_peek_token (parser)->value;
7385       objc_declare_class (id);
7386       c_parser_consume_token (parser);
7387       if (c_parser_next_token_is (parser, CPP_COMMA))
7388 	c_parser_consume_token (parser);
7389       else
7390 	break;
7391     }
7392   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7393 }
7394 
7395 /* Parse an objc-alias-declaration.
7396 
7397    objc-alias-declaration:
7398      @compatibility_alias identifier identifier ;
7399 */
7400 
7401 static void
7402 c_parser_objc_alias_declaration (c_parser *parser)
7403 {
7404   tree id1, id2;
7405   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
7406   c_parser_consume_token (parser);
7407   if (c_parser_next_token_is_not (parser, CPP_NAME))
7408     {
7409       c_parser_error (parser, "expected identifier");
7410       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7411       return;
7412     }
7413   id1 = c_parser_peek_token (parser)->value;
7414   c_parser_consume_token (parser);
7415   if (c_parser_next_token_is_not (parser, CPP_NAME))
7416     {
7417       c_parser_error (parser, "expected identifier");
7418       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7419       return;
7420     }
7421   id2 = c_parser_peek_token (parser)->value;
7422   c_parser_consume_token (parser);
7423   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7424   objc_declare_alias (id1, id2);
7425 }
7426 
7427 /* Parse an objc-protocol-definition.
7428 
7429    objc-protocol-definition:
7430      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7431      @protocol identifier-list ;
7432 
7433    "@protocol identifier ;" should be resolved as "@protocol
7434    identifier-list ;": objc-methodprotolist may not start with a
7435    semicolon in the first alternative if objc-protocol-refs are
7436    omitted.  */
7437 
7438 static void
7439 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
7440 {
7441   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7442 
7443   c_parser_consume_token (parser);
7444   if (c_parser_next_token_is_not (parser, CPP_NAME))
7445     {
7446       c_parser_error (parser, "expected identifier");
7447       return;
7448     }
7449   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
7450       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
7451     {
7452       /* Any identifiers, including those declared as type names, are
7453 	 OK here.  */
7454       while (true)
7455 	{
7456 	  tree id;
7457 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
7458 	    {
7459 	      c_parser_error (parser, "expected identifier");
7460 	      break;
7461 	    }
7462 	  id = c_parser_peek_token (parser)->value;
7463 	  objc_declare_protocol (id, attributes);
7464 	  c_parser_consume_token (parser);
7465 	  if (c_parser_next_token_is (parser, CPP_COMMA))
7466 	    c_parser_consume_token (parser);
7467 	  else
7468 	    break;
7469 	}
7470       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7471     }
7472   else
7473     {
7474       tree id = c_parser_peek_token (parser)->value;
7475       tree proto = NULL_TREE;
7476       c_parser_consume_token (parser);
7477       if (c_parser_next_token_is (parser, CPP_LESS))
7478 	proto = c_parser_objc_protocol_refs (parser);
7479       parser->objc_pq_context = true;
7480       objc_start_protocol (id, proto, attributes);
7481       c_parser_objc_methodprotolist (parser);
7482       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7483       parser->objc_pq_context = false;
7484       objc_finish_interface ();
7485     }
7486 }
7487 
7488 /* Parse an objc-method-type.
7489 
7490    objc-method-type:
7491      +
7492      -
7493 
7494    Return true if it is a class method (+) and false if it is
7495    an instance method (-).
7496 */
7497 static inline bool
7498 c_parser_objc_method_type (c_parser *parser)
7499 {
7500   switch (c_parser_peek_token (parser)->type)
7501     {
7502     case CPP_PLUS:
7503       c_parser_consume_token (parser);
7504       return true;
7505     case CPP_MINUS:
7506       c_parser_consume_token (parser);
7507       return false;
7508     default:
7509       gcc_unreachable ();
7510     }
7511 }
7512 
7513 /* Parse an objc-method-definition.
7514 
7515    objc-method-definition:
7516      objc-method-type objc-method-decl ;[opt] compound-statement
7517 */
7518 
7519 static void
7520 c_parser_objc_method_definition (c_parser *parser)
7521 {
7522   bool is_class_method = c_parser_objc_method_type (parser);
7523   tree decl, attributes = NULL_TREE, expr = NULL_TREE;
7524   parser->objc_pq_context = true;
7525   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
7526 				    &expr);
7527   if (decl == error_mark_node)
7528     return;  /* Bail here. */
7529 
7530   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7531     {
7532       c_parser_consume_token (parser);
7533       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
7534 	       "extra semicolon in method definition specified");
7535     }
7536 
7537   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7538     {
7539       c_parser_error (parser, "expected %<{%>");
7540       return;
7541     }
7542 
7543   parser->objc_pq_context = false;
7544   if (objc_start_method_definition (is_class_method, decl, attributes, expr))
7545     {
7546       add_stmt (c_parser_compound_statement (parser));
7547       objc_finish_method_definition (current_function_decl);
7548     }
7549   else
7550     {
7551       /* This code is executed when we find a method definition
7552 	 outside of an @implementation context (or invalid for other
7553 	 reasons).  Parse the method (to keep going) but do not emit
7554 	 any code.
7555       */
7556       c_parser_compound_statement (parser);
7557     }
7558 }
7559 
7560 /* Parse an objc-methodprotolist.
7561 
7562    objc-methodprotolist:
7563      empty
7564      objc-methodprotolist objc-methodproto
7565      objc-methodprotolist declaration
7566      objc-methodprotolist ;
7567      @optional
7568      @required
7569 
7570    The declaration is a data definition, which may be missing
7571    declaration specifiers under the same rules and diagnostics as
7572    other data definitions outside functions, and the stray semicolon
7573    is diagnosed the same way as a stray semicolon outside a
7574    function.  */
7575 
7576 static void
7577 c_parser_objc_methodprotolist (c_parser *parser)
7578 {
7579   while (true)
7580     {
7581       /* The list is terminated by @end.  */
7582       switch (c_parser_peek_token (parser)->type)
7583 	{
7584 	case CPP_SEMICOLON:
7585 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
7586 		   "ISO C does not allow extra %<;%> outside of a function");
7587 	  c_parser_consume_token (parser);
7588 	  break;
7589 	case CPP_PLUS:
7590 	case CPP_MINUS:
7591 	  c_parser_objc_methodproto (parser);
7592 	  break;
7593 	case CPP_PRAGMA:
7594 	  c_parser_pragma (parser, pragma_external);
7595 	  break;
7596 	case CPP_EOF:
7597 	  return;
7598 	default:
7599 	  if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7600 	    return;
7601 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7602 	    c_parser_objc_at_property_declaration (parser);
7603 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7604 	    {
7605 	      objc_set_method_opt (true);
7606 	      c_parser_consume_token (parser);
7607 	    }
7608 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7609 	    {
7610 	      objc_set_method_opt (false);
7611 	      c_parser_consume_token (parser);
7612 	    }
7613 	  else
7614 	    c_parser_declaration_or_fndef (parser, false, false, true,
7615 					   false, true, NULL);
7616 	  break;
7617 	}
7618     }
7619 }
7620 
7621 /* Parse an objc-methodproto.
7622 
7623    objc-methodproto:
7624      objc-method-type objc-method-decl ;
7625 */
7626 
7627 static void
7628 c_parser_objc_methodproto (c_parser *parser)
7629 {
7630   bool is_class_method = c_parser_objc_method_type (parser);
7631   tree decl, attributes = NULL_TREE;
7632 
7633   /* Remember protocol qualifiers in prototypes.  */
7634   parser->objc_pq_context = true;
7635   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
7636 				    NULL);
7637   /* Forget protocol qualifiers now.  */
7638   parser->objc_pq_context = false;
7639 
7640   /* Do not allow the presence of attributes to hide an erroneous
7641      method implementation in the interface section.  */
7642   if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7643     {
7644       c_parser_error (parser, "expected %<;%>");
7645       return;
7646     }
7647 
7648   if (decl != error_mark_node)
7649     objc_add_method_declaration (is_class_method, decl, attributes);
7650 
7651   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7652 }
7653 
7654 /* If we are at a position that method attributes may be present, check that
7655    there are not any parsed already (a syntax error) and then collect any
7656    specified at the current location.  Finally, if new attributes were present,
7657    check that the next token is legal ( ';' for decls and '{' for defs).  */
7658 
7659 static bool
7660 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7661 {
7662   bool bad = false;
7663   if (*attributes)
7664     {
7665       c_parser_error (parser,
7666 		    "method attributes must be specified at the end only");
7667       *attributes = NULL_TREE;
7668       bad = true;
7669     }
7670 
7671   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7672     *attributes = c_parser_attributes (parser);
7673 
7674   /* If there were no attributes here, just report any earlier error.  */
7675   if (*attributes == NULL_TREE || bad)
7676     return bad;
7677 
7678   /* If the attributes are followed by a ; or {, then just report any earlier
7679      error.  */
7680   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7681       || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7682     return bad;
7683 
7684   /* We've got attributes, but not at the end.  */
7685   c_parser_error (parser,
7686 		  "expected %<;%> or %<{%> after method attribute definition");
7687   return true;
7688 }
7689 
7690 /* Parse an objc-method-decl.
7691 
7692    objc-method-decl:
7693      ( objc-type-name ) objc-selector
7694      objc-selector
7695      ( objc-type-name ) objc-keyword-selector objc-optparmlist
7696      objc-keyword-selector objc-optparmlist
7697      attributes
7698 
7699    objc-keyword-selector:
7700      objc-keyword-decl
7701      objc-keyword-selector objc-keyword-decl
7702 
7703    objc-keyword-decl:
7704      objc-selector : ( objc-type-name ) identifier
7705      objc-selector : identifier
7706      : ( objc-type-name ) identifier
7707      : identifier
7708 
7709    objc-optparmlist:
7710      objc-optparms objc-optellipsis
7711 
7712    objc-optparms:
7713      empty
7714      objc-opt-parms , parameter-declaration
7715 
7716    objc-optellipsis:
7717      empty
7718      , ...
7719 */
7720 
7721 static tree
7722 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
7723 			   tree *attributes, tree *expr)
7724 {
7725   tree type = NULL_TREE;
7726   tree sel;
7727   tree parms = NULL_TREE;
7728   bool ellipsis = false;
7729   bool attr_err = false;
7730 
7731   *attributes = NULL_TREE;
7732   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7733     {
7734       c_parser_consume_token (parser);
7735       type = c_parser_objc_type_name (parser);
7736       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7737     }
7738   sel = c_parser_objc_selector (parser);
7739   /* If there is no selector, or a colon follows, we have an
7740      objc-keyword-selector.  If there is a selector, and a colon does
7741      not follow, that selector ends the objc-method-decl.  */
7742   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7743     {
7744       tree tsel = sel;
7745       tree list = NULL_TREE;
7746       while (true)
7747 	{
7748 	  tree atype = NULL_TREE, id, keyworddecl;
7749 	  tree param_attr = NULL_TREE;
7750 	  if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7751 	    break;
7752 	  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7753 	    {
7754 	      c_parser_consume_token (parser);
7755 	      atype = c_parser_objc_type_name (parser);
7756 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7757 					 "expected %<)%>");
7758 	    }
7759 	  /* New ObjC allows attributes on method parameters.  */
7760 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7761 	    param_attr = c_parser_attributes (parser);
7762 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
7763 	    {
7764 	      c_parser_error (parser, "expected identifier");
7765 	      return error_mark_node;
7766 	    }
7767 	  id = c_parser_peek_token (parser)->value;
7768 	  c_parser_consume_token (parser);
7769 	  keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7770 	  list = chainon (list, keyworddecl);
7771 	  tsel = c_parser_objc_selector (parser);
7772 	  if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7773 	    break;
7774 	}
7775 
7776       attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7777 
7778       /* Parse the optional parameter list.  Optional Objective-C
7779 	 method parameters follow the C syntax, and may include '...'
7780 	 to denote a variable number of arguments.  */
7781       parms = make_node (TREE_LIST);
7782       while (c_parser_next_token_is (parser, CPP_COMMA))
7783 	{
7784 	  struct c_parm *parm;
7785 	  c_parser_consume_token (parser);
7786 	  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7787 	    {
7788 	      ellipsis = true;
7789 	      c_parser_consume_token (parser);
7790 	      attr_err |= c_parser_objc_maybe_method_attributes
7791 						(parser, attributes) ;
7792 	      break;
7793 	    }
7794 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
7795 	  if (parm == NULL)
7796 	    break;
7797 	  parms = chainon (parms,
7798 			   build_tree_list (NULL_TREE, grokparm (parm, expr)));
7799 	}
7800       sel = list;
7801     }
7802   else
7803     attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7804 
7805   if (sel == NULL)
7806     {
7807       c_parser_error (parser, "objective-c method declaration is expected");
7808       return error_mark_node;
7809     }
7810 
7811   if (attr_err)
7812     return error_mark_node;
7813 
7814   return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7815 }
7816 
7817 /* Parse an objc-type-name.
7818 
7819    objc-type-name:
7820      objc-type-qualifiers[opt] type-name
7821      objc-type-qualifiers[opt]
7822 
7823    objc-type-qualifiers:
7824      objc-type-qualifier
7825      objc-type-qualifiers objc-type-qualifier
7826 
7827    objc-type-qualifier: one of
7828      in out inout bycopy byref oneway
7829 */
7830 
7831 static tree
7832 c_parser_objc_type_name (c_parser *parser)
7833 {
7834   tree quals = NULL_TREE;
7835   struct c_type_name *type_name = NULL;
7836   tree type = NULL_TREE;
7837   while (true)
7838     {
7839       c_token *token = c_parser_peek_token (parser);
7840       if (token->type == CPP_KEYWORD
7841 	  && (token->keyword == RID_IN
7842 	      || token->keyword == RID_OUT
7843 	      || token->keyword == RID_INOUT
7844 	      || token->keyword == RID_BYCOPY
7845 	      || token->keyword == RID_BYREF
7846 	      || token->keyword == RID_ONEWAY))
7847 	{
7848 	  quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7849 	  c_parser_consume_token (parser);
7850 	}
7851       else
7852 	break;
7853     }
7854   if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
7855     type_name = c_parser_type_name (parser);
7856   if (type_name)
7857     type = groktypename (type_name, NULL, NULL);
7858 
7859   /* If the type is unknown, and error has already been produced and
7860      we need to recover from the error.  In that case, use NULL_TREE
7861      for the type, as if no type had been specified; this will use the
7862      default type ('id') which is good for error recovery.  */
7863   if (type == error_mark_node)
7864     type = NULL_TREE;
7865 
7866   return build_tree_list (quals, type);
7867 }
7868 
7869 /* Parse objc-protocol-refs.
7870 
7871    objc-protocol-refs:
7872      < identifier-list >
7873 */
7874 
7875 static tree
7876 c_parser_objc_protocol_refs (c_parser *parser)
7877 {
7878   tree list = NULL_TREE;
7879   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7880   c_parser_consume_token (parser);
7881   /* Any identifiers, including those declared as type names, are OK
7882      here.  */
7883   while (true)
7884     {
7885       tree id;
7886       if (c_parser_next_token_is_not (parser, CPP_NAME))
7887 	{
7888 	  c_parser_error (parser, "expected identifier");
7889 	  break;
7890 	}
7891       id = c_parser_peek_token (parser)->value;
7892       list = chainon (list, build_tree_list (NULL_TREE, id));
7893       c_parser_consume_token (parser);
7894       if (c_parser_next_token_is (parser, CPP_COMMA))
7895 	c_parser_consume_token (parser);
7896       else
7897 	break;
7898     }
7899   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7900   return list;
7901 }
7902 
7903 /* Parse an objc-try-catch-finally-statement.
7904 
7905    objc-try-catch-finally-statement:
7906      @try compound-statement objc-catch-list[opt]
7907      @try compound-statement objc-catch-list[opt] @finally compound-statement
7908 
7909    objc-catch-list:
7910      @catch ( objc-catch-parameter-declaration ) compound-statement
7911      objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7912 
7913    objc-catch-parameter-declaration:
7914      parameter-declaration
7915      '...'
7916 
7917    where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7918 
7919    PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7920    for C++.  Keep them in sync.  */
7921 
7922 static void
7923 c_parser_objc_try_catch_finally_statement (c_parser *parser)
7924 {
7925   location_t location;
7926   tree stmt;
7927 
7928   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7929   c_parser_consume_token (parser);
7930   location = c_parser_peek_token (parser)->location;
7931   objc_maybe_warn_exceptions (location);
7932   stmt = c_parser_compound_statement (parser);
7933   objc_begin_try_stmt (location, stmt);
7934 
7935   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7936     {
7937       struct c_parm *parm;
7938       tree parameter_declaration = error_mark_node;
7939       bool seen_open_paren = false;
7940 
7941       c_parser_consume_token (parser);
7942       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7943 	seen_open_paren = true;
7944       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7945 	{
7946 	  /* We have "@catch (...)" (where the '...' are literally
7947 	     what is in the code).  Skip the '...'.
7948 	     parameter_declaration is set to NULL_TREE, and
7949 	     objc_being_catch_clauses() knows that that means
7950 	     '...'.  */
7951 	  c_parser_consume_token (parser);
7952 	  parameter_declaration = NULL_TREE;
7953 	}
7954       else
7955 	{
7956 	  /* We have "@catch (NSException *exception)" or something
7957 	     like that.  Parse the parameter declaration.  */
7958 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
7959 	  if (parm == NULL)
7960 	    parameter_declaration = error_mark_node;
7961 	  else
7962 	    parameter_declaration = grokparm (parm, NULL);
7963 	}
7964       if (seen_open_paren)
7965 	c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7966       else
7967 	{
7968 	  /* If there was no open parenthesis, we are recovering from
7969 	     an error, and we are trying to figure out what mistake
7970 	     the user has made.  */
7971 
7972 	  /* If there is an immediate closing parenthesis, the user
7973 	     probably forgot the opening one (ie, they typed "@catch
7974 	     NSException *e)".  Parse the closing parenthesis and keep
7975 	     going.  */
7976 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7977 	    c_parser_consume_token (parser);
7978 
7979 	  /* If these is no immediate closing parenthesis, the user
7980 	     probably doesn't know that parenthesis are required at
7981 	     all (ie, they typed "@catch NSException *e").  So, just
7982 	     forget about the closing parenthesis and keep going.  */
7983 	}
7984       objc_begin_catch_clause (parameter_declaration);
7985       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7986 	c_parser_compound_statement_nostart (parser);
7987       objc_finish_catch_clause ();
7988     }
7989   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7990     {
7991       c_parser_consume_token (parser);
7992       location = c_parser_peek_token (parser)->location;
7993       stmt = c_parser_compound_statement (parser);
7994       objc_build_finally_clause (location, stmt);
7995     }
7996   objc_finish_try_stmt ();
7997 }
7998 
7999 /* Parse an objc-synchronized-statement.
8000 
8001    objc-synchronized-statement:
8002      @synchronized ( expression ) compound-statement
8003 */
8004 
8005 static void
8006 c_parser_objc_synchronized_statement (c_parser *parser)
8007 {
8008   location_t loc;
8009   tree expr, stmt;
8010   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
8011   c_parser_consume_token (parser);
8012   loc = c_parser_peek_token (parser)->location;
8013   objc_maybe_warn_exceptions (loc);
8014   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8015     {
8016       expr = c_parser_expression (parser).value;
8017       expr = c_fully_fold (expr, false, NULL);
8018       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8019     }
8020   else
8021     expr = error_mark_node;
8022   stmt = c_parser_compound_statement (parser);
8023   objc_build_synchronized (loc, expr, stmt);
8024 }
8025 
8026 /* Parse an objc-selector; return NULL_TREE without an error if the
8027    next token is not an objc-selector.
8028 
8029    objc-selector:
8030      identifier
8031      one of
8032        enum struct union if else while do for switch case default
8033        break continue return goto asm sizeof typeof __alignof
8034        unsigned long const short volatile signed restrict _Complex
8035        in out inout bycopy byref oneway int char float double void _Bool
8036 
8037    ??? Why this selection of keywords but not, for example, storage
8038    class specifiers?  */
8039 
8040 static tree
8041 c_parser_objc_selector (c_parser *parser)
8042 {
8043   c_token *token = c_parser_peek_token (parser);
8044   tree value = token->value;
8045   if (token->type == CPP_NAME)
8046     {
8047       c_parser_consume_token (parser);
8048       return value;
8049     }
8050   if (token->type != CPP_KEYWORD)
8051     return NULL_TREE;
8052   switch (token->keyword)
8053     {
8054     case RID_ENUM:
8055     case RID_STRUCT:
8056     case RID_UNION:
8057     case RID_IF:
8058     case RID_ELSE:
8059     case RID_WHILE:
8060     case RID_DO:
8061     case RID_FOR:
8062     case RID_SWITCH:
8063     case RID_CASE:
8064     case RID_DEFAULT:
8065     case RID_BREAK:
8066     case RID_CONTINUE:
8067     case RID_RETURN:
8068     case RID_GOTO:
8069     case RID_ASM:
8070     case RID_SIZEOF:
8071     case RID_TYPEOF:
8072     case RID_ALIGNOF:
8073     case RID_UNSIGNED:
8074     case RID_LONG:
8075     case RID_INT128:
8076     case RID_CONST:
8077     case RID_SHORT:
8078     case RID_VOLATILE:
8079     case RID_SIGNED:
8080     case RID_RESTRICT:
8081     case RID_COMPLEX:
8082     case RID_IN:
8083     case RID_OUT:
8084     case RID_INOUT:
8085     case RID_BYCOPY:
8086     case RID_BYREF:
8087     case RID_ONEWAY:
8088     case RID_INT:
8089     case RID_CHAR:
8090     case RID_FLOAT:
8091     case RID_DOUBLE:
8092     case RID_VOID:
8093     case RID_BOOL:
8094       c_parser_consume_token (parser);
8095       return value;
8096     default:
8097       return NULL_TREE;
8098     }
8099 }
8100 
8101 /* Parse an objc-selector-arg.
8102 
8103    objc-selector-arg:
8104      objc-selector
8105      objc-keywordname-list
8106 
8107    objc-keywordname-list:
8108      objc-keywordname
8109      objc-keywordname-list objc-keywordname
8110 
8111    objc-keywordname:
8112      objc-selector :
8113      :
8114 */
8115 
8116 static tree
8117 c_parser_objc_selector_arg (c_parser *parser)
8118 {
8119   tree sel = c_parser_objc_selector (parser);
8120   tree list = NULL_TREE;
8121   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
8122     return sel;
8123   while (true)
8124     {
8125       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8126 	return list;
8127       list = chainon (list, build_tree_list (sel, NULL_TREE));
8128       sel = c_parser_objc_selector (parser);
8129       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
8130 	break;
8131     }
8132   return list;
8133 }
8134 
8135 /* Parse an objc-receiver.
8136 
8137    objc-receiver:
8138      expression
8139      class-name
8140      type-name
8141 */
8142 
8143 static tree
8144 c_parser_objc_receiver (c_parser *parser)
8145 {
8146   if (c_parser_peek_token (parser)->type == CPP_NAME
8147       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
8148 	  || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
8149     {
8150       tree id = c_parser_peek_token (parser)->value;
8151       c_parser_consume_token (parser);
8152       return objc_get_class_reference (id);
8153     }
8154   return c_fully_fold (c_parser_expression (parser).value, false, NULL);
8155 }
8156 
8157 /* Parse objc-message-args.
8158 
8159    objc-message-args:
8160      objc-selector
8161      objc-keywordarg-list
8162 
8163    objc-keywordarg-list:
8164      objc-keywordarg
8165      objc-keywordarg-list objc-keywordarg
8166 
8167    objc-keywordarg:
8168      objc-selector : objc-keywordexpr
8169      : objc-keywordexpr
8170 */
8171 
8172 static tree
8173 c_parser_objc_message_args (c_parser *parser)
8174 {
8175   tree sel = c_parser_objc_selector (parser);
8176   tree list = NULL_TREE;
8177   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
8178     return sel;
8179   while (true)
8180     {
8181       tree keywordexpr;
8182       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8183 	return error_mark_node;
8184       keywordexpr = c_parser_objc_keywordexpr (parser);
8185       list = chainon (list, build_tree_list (sel, keywordexpr));
8186       sel = c_parser_objc_selector (parser);
8187       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
8188 	break;
8189     }
8190   return list;
8191 }
8192 
8193 /* Parse an objc-keywordexpr.
8194 
8195    objc-keywordexpr:
8196      nonempty-expr-list
8197 */
8198 
8199 static tree
8200 c_parser_objc_keywordexpr (c_parser *parser)
8201 {
8202   tree ret;
8203   vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
8204 						NULL, NULL, NULL);
8205   if (vec_safe_length (expr_list) == 1)
8206     {
8207       /* Just return the expression, remove a level of
8208 	 indirection.  */
8209       ret = (*expr_list)[0];
8210     }
8211   else
8212     {
8213       /* We have a comma expression, we will collapse later.  */
8214       ret = build_tree_list_vec (expr_list);
8215     }
8216   release_tree_vector (expr_list);
8217   return ret;
8218 }
8219 
8220 /* A check, needed in several places, that ObjC interface, implementation or
8221    method definitions are not prefixed by incorrect items.  */
8222 static bool
8223 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
8224 					   struct c_declspecs *specs)
8225 {
8226   if (!specs->declspecs_seen_p || specs->non_sc_seen_p
8227       || specs->typespec_kind != ctsk_none)
8228     {
8229       c_parser_error (parser,
8230       		      "no type or storage class may be specified here,");
8231       c_parser_skip_to_end_of_block_or_statement (parser);
8232       return true;
8233     }
8234   return false;
8235 }
8236 
8237 /* Parse an Objective-C @property declaration.  The syntax is:
8238 
8239    objc-property-declaration:
8240      '@property' objc-property-attributes[opt] struct-declaration ;
8241 
8242    objc-property-attributes:
8243     '(' objc-property-attribute-list ')'
8244 
8245    objc-property-attribute-list:
8246      objc-property-attribute
8247      objc-property-attribute-list, objc-property-attribute
8248 
8249    objc-property-attribute
8250      'getter' = identifier
8251      'setter' = identifier
8252      'readonly'
8253      'readwrite'
8254      'assign'
8255      'retain'
8256      'copy'
8257      'nonatomic'
8258 
8259   For example:
8260     @property NSString *name;
8261     @property (readonly) id object;
8262     @property (retain, nonatomic, getter=getTheName) id name;
8263     @property int a, b, c;
8264 
8265   PS: This function is identical to cp_parser_objc_at_propery_declaration
8266   for C++.  Keep them in sync.  */
8267 static void
8268 c_parser_objc_at_property_declaration (c_parser *parser)
8269 {
8270   /* The following variables hold the attributes of the properties as
8271      parsed.  They are 'false' or 'NULL_TREE' if the attribute was not
8272      seen.  When we see an attribute, we set them to 'true' (if they
8273      are boolean properties) or to the identifier (if they have an
8274      argument, ie, for getter and setter).  Note that here we only
8275      parse the list of attributes, check the syntax and accumulate the
8276      attributes that we find.  objc_add_property_declaration() will
8277      then process the information.  */
8278   bool property_assign = false;
8279   bool property_copy = false;
8280   tree property_getter_ident = NULL_TREE;
8281   bool property_nonatomic = false;
8282   bool property_readonly = false;
8283   bool property_readwrite = false;
8284   bool property_retain = false;
8285   tree property_setter_ident = NULL_TREE;
8286 
8287   /* 'properties' is the list of properties that we read.  Usually a
8288      single one, but maybe more (eg, in "@property int a, b, c;" there
8289      are three).  */
8290   tree properties;
8291   location_t loc;
8292 
8293   loc = c_parser_peek_token (parser)->location;
8294   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
8295 
8296   c_parser_consume_token (parser);  /* Eat '@property'.  */
8297 
8298   /* Parse the optional attribute list...  */
8299   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8300     {
8301       /* Eat the '(' */
8302       c_parser_consume_token (parser);
8303 
8304       /* Property attribute keywords are valid now.  */
8305       parser->objc_property_attr_context = true;
8306 
8307       while (true)
8308 	{
8309 	  bool syntax_error = false;
8310 	  c_token *token = c_parser_peek_token (parser);
8311 	  enum rid keyword;
8312 
8313 	  if (token->type != CPP_KEYWORD)
8314 	    {
8315 	      if (token->type == CPP_CLOSE_PAREN)
8316 		c_parser_error (parser, "expected identifier");
8317 	      else
8318 		{
8319 		  c_parser_consume_token (parser);
8320 		  c_parser_error (parser, "unknown property attribute");
8321 		}
8322 	      break;
8323 	    }
8324 	  keyword = token->keyword;
8325 	  c_parser_consume_token (parser);
8326 	  switch (keyword)
8327 	    {
8328 	    case RID_ASSIGN:    property_assign = true;    break;
8329 	    case RID_COPY:      property_copy = true;      break;
8330 	    case RID_NONATOMIC: property_nonatomic = true; break;
8331 	    case RID_READONLY:  property_readonly = true;  break;
8332 	    case RID_READWRITE: property_readwrite = true; break;
8333 	    case RID_RETAIN:    property_retain = true;    break;
8334 
8335 	    case RID_GETTER:
8336 	    case RID_SETTER:
8337 	      if (c_parser_next_token_is_not (parser, CPP_EQ))
8338 		{
8339 		  if (keyword == RID_GETTER)
8340 		    c_parser_error (parser,
8341 				    "missing %<=%> (after %<getter%> attribute)");
8342 		  else
8343 		    c_parser_error (parser,
8344 				    "missing %<=%> (after %<setter%> attribute)");
8345 		  syntax_error = true;
8346 		  break;
8347 		}
8348 	      c_parser_consume_token (parser); /* eat the = */
8349 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
8350 		{
8351 		  c_parser_error (parser, "expected identifier");
8352 		  syntax_error = true;
8353 		  break;
8354 		}
8355 	      if (keyword == RID_SETTER)
8356 		{
8357 		  if (property_setter_ident != NULL_TREE)
8358 		    c_parser_error (parser, "the %<setter%> attribute may only be specified once");
8359 		  else
8360 		    property_setter_ident = c_parser_peek_token (parser)->value;
8361 		  c_parser_consume_token (parser);
8362 		  if (c_parser_next_token_is_not (parser, CPP_COLON))
8363 		    c_parser_error (parser, "setter name must terminate with %<:%>");
8364 		  else
8365 		    c_parser_consume_token (parser);
8366 		}
8367 	      else
8368 		{
8369 		  if (property_getter_ident != NULL_TREE)
8370 		    c_parser_error (parser, "the %<getter%> attribute may only be specified once");
8371 		  else
8372 		    property_getter_ident = c_parser_peek_token (parser)->value;
8373 		  c_parser_consume_token (parser);
8374 		}
8375 	      break;
8376 	    default:
8377 	      c_parser_error (parser, "unknown property attribute");
8378 	      syntax_error = true;
8379 	      break;
8380 	    }
8381 
8382 	  if (syntax_error)
8383 	    break;
8384 
8385 	  if (c_parser_next_token_is (parser, CPP_COMMA))
8386 	    c_parser_consume_token (parser);
8387 	  else
8388 	    break;
8389 	}
8390       parser->objc_property_attr_context = false;
8391       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8392     }
8393   /* ... and the property declaration(s).  */
8394   properties = c_parser_struct_declaration (parser);
8395 
8396   if (properties == error_mark_node)
8397     {
8398       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8399       parser->error = false;
8400       return;
8401     }
8402 
8403   if (properties == NULL_TREE)
8404     c_parser_error (parser, "expected identifier");
8405   else
8406     {
8407       /* Comma-separated properties are chained together in
8408 	 reverse order; add them one by one.  */
8409       properties = nreverse (properties);
8410 
8411       for (; properties; properties = TREE_CHAIN (properties))
8412 	objc_add_property_declaration (loc, copy_node (properties),
8413 				       property_readonly, property_readwrite,
8414 				       property_assign, property_retain,
8415 				       property_copy, property_nonatomic,
8416 				       property_getter_ident, property_setter_ident);
8417     }
8418 
8419   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8420   parser->error = false;
8421 }
8422 
8423 /* Parse an Objective-C @synthesize declaration.  The syntax is:
8424 
8425    objc-synthesize-declaration:
8426      @synthesize objc-synthesize-identifier-list ;
8427 
8428    objc-synthesize-identifier-list:
8429      objc-synthesize-identifier
8430      objc-synthesize-identifier-list, objc-synthesize-identifier
8431 
8432    objc-synthesize-identifier
8433      identifier
8434      identifier = identifier
8435 
8436   For example:
8437     @synthesize MyProperty;
8438     @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8439 
8440   PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8441   for C++.  Keep them in sync.
8442 */
8443 static void
8444 c_parser_objc_at_synthesize_declaration (c_parser *parser)
8445 {
8446   tree list = NULL_TREE;
8447   location_t loc;
8448   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
8449   loc = c_parser_peek_token (parser)->location;
8450 
8451   c_parser_consume_token (parser);
8452   while (true)
8453     {
8454       tree property, ivar;
8455       if (c_parser_next_token_is_not (parser, CPP_NAME))
8456 	{
8457 	  c_parser_error (parser, "expected identifier");
8458 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8459 	  /* Once we find the semicolon, we can resume normal parsing.
8460 	     We have to reset parser->error manually because
8461 	     c_parser_skip_until_found() won't reset it for us if the
8462 	     next token is precisely a semicolon.  */
8463 	  parser->error = false;
8464 	  return;
8465 	}
8466       property = c_parser_peek_token (parser)->value;
8467       c_parser_consume_token (parser);
8468       if (c_parser_next_token_is (parser, CPP_EQ))
8469 	{
8470 	  c_parser_consume_token (parser);
8471 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
8472 	    {
8473 	      c_parser_error (parser, "expected identifier");
8474 	      c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8475 	      parser->error = false;
8476 	      return;
8477 	    }
8478 	  ivar = c_parser_peek_token (parser)->value;
8479 	  c_parser_consume_token (parser);
8480 	}
8481       else
8482 	ivar = NULL_TREE;
8483       list = chainon (list, build_tree_list (ivar, property));
8484       if (c_parser_next_token_is (parser, CPP_COMMA))
8485 	c_parser_consume_token (parser);
8486       else
8487 	break;
8488     }
8489   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8490   objc_add_synthesize_declaration (loc, list);
8491 }
8492 
8493 /* Parse an Objective-C @dynamic declaration.  The syntax is:
8494 
8495    objc-dynamic-declaration:
8496      @dynamic identifier-list ;
8497 
8498    For example:
8499      @dynamic MyProperty;
8500      @dynamic MyProperty, AnotherProperty;
8501 
8502   PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8503   for C++.  Keep them in sync.
8504 */
8505 static void
8506 c_parser_objc_at_dynamic_declaration (c_parser *parser)
8507 {
8508   tree list = NULL_TREE;
8509   location_t loc;
8510   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
8511   loc = c_parser_peek_token (parser)->location;
8512 
8513   c_parser_consume_token (parser);
8514   while (true)
8515     {
8516       tree property;
8517       if (c_parser_next_token_is_not (parser, CPP_NAME))
8518 	{
8519 	  c_parser_error (parser, "expected identifier");
8520 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8521 	  parser->error = false;
8522 	  return;
8523 	}
8524       property = c_parser_peek_token (parser)->value;
8525       list = chainon (list, build_tree_list (NULL_TREE, property));
8526       c_parser_consume_token (parser);
8527       if (c_parser_next_token_is (parser, CPP_COMMA))
8528 	c_parser_consume_token (parser);
8529       else
8530 	break;
8531     }
8532   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8533   objc_add_dynamic_declaration (loc, list);
8534 }
8535 
8536 
8537 /* Handle pragmas.  Some OpenMP pragmas are associated with, and therefore
8538    should be considered, statements.  ALLOW_STMT is true if we're within
8539    the context of a function and such pragmas are to be allowed.  Returns
8540    true if we actually parsed such a pragma.  */
8541 
8542 static bool
8543 c_parser_pragma (c_parser *parser, enum pragma_context context)
8544 {
8545   unsigned int id;
8546 
8547   id = c_parser_peek_token (parser)->pragma_kind;
8548   gcc_assert (id != PRAGMA_NONE);
8549 
8550   switch (id)
8551     {
8552     case PRAGMA_OMP_BARRIER:
8553       if (context != pragma_compound)
8554 	{
8555 	  if (context == pragma_stmt)
8556 	    c_parser_error (parser, "%<#pragma omp barrier%> may only be "
8557 			    "used in compound statements");
8558 	  goto bad_stmt;
8559 	}
8560       c_parser_omp_barrier (parser);
8561       return false;
8562 
8563     case PRAGMA_OMP_FLUSH:
8564       if (context != pragma_compound)
8565 	{
8566 	  if (context == pragma_stmt)
8567 	    c_parser_error (parser, "%<#pragma omp flush%> may only be "
8568 			    "used in compound statements");
8569 	  goto bad_stmt;
8570 	}
8571       c_parser_omp_flush (parser);
8572       return false;
8573 
8574     case PRAGMA_OMP_TASKWAIT:
8575       if (context != pragma_compound)
8576 	{
8577 	  if (context == pragma_stmt)
8578 	    c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
8579 			    "used in compound statements");
8580 	  goto bad_stmt;
8581 	}
8582       c_parser_omp_taskwait (parser);
8583       return false;
8584 
8585     case PRAGMA_OMP_TASKYIELD:
8586       if (context != pragma_compound)
8587 	{
8588 	  if (context == pragma_stmt)
8589 	    c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
8590 			    "used in compound statements");
8591 	  goto bad_stmt;
8592 	}
8593       c_parser_omp_taskyield (parser);
8594       return false;
8595 
8596     case PRAGMA_OMP_THREADPRIVATE:
8597       c_parser_omp_threadprivate (parser);
8598       return false;
8599 
8600     case PRAGMA_OMP_SECTION:
8601       error_at (c_parser_peek_token (parser)->location,
8602 		"%<#pragma omp section%> may only be used in "
8603 		"%<#pragma omp sections%> construct");
8604       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8605       return false;
8606 
8607     case PRAGMA_GCC_PCH_PREPROCESS:
8608       c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
8609       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8610       return false;
8611 
8612     default:
8613       if (id < PRAGMA_FIRST_EXTERNAL)
8614 	{
8615 	  if (context == pragma_external)
8616 	    {
8617 	    bad_stmt:
8618 	      c_parser_error (parser, "expected declaration specifiers");
8619 	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8620 	      return false;
8621 	    }
8622 	  c_parser_omp_construct (parser);
8623 	  return true;
8624 	}
8625       break;
8626     }
8627 
8628   c_parser_consume_pragma (parser);
8629   c_invoke_pragma_handler (id);
8630 
8631   /* Skip to EOL, but suppress any error message.  Those will have been
8632      generated by the handler routine through calling error, as opposed
8633      to calling c_parser_error.  */
8634   parser->error = true;
8635   c_parser_skip_to_pragma_eol (parser);
8636 
8637   return false;
8638 }
8639 
8640 /* The interface the pragma parsers have to the lexer.  */
8641 
8642 enum cpp_ttype
8643 pragma_lex (tree *value)
8644 {
8645   c_token *tok = c_parser_peek_token (the_parser);
8646   enum cpp_ttype ret = tok->type;
8647 
8648   *value = tok->value;
8649   if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8650     ret = CPP_EOF;
8651   else
8652     {
8653       if (ret == CPP_KEYWORD)
8654 	ret = CPP_NAME;
8655       c_parser_consume_token (the_parser);
8656     }
8657 
8658   return ret;
8659 }
8660 
8661 static void
8662 c_parser_pragma_pch_preprocess (c_parser *parser)
8663 {
8664   tree name = NULL;
8665 
8666   c_parser_consume_pragma (parser);
8667   if (c_parser_next_token_is (parser, CPP_STRING))
8668     {
8669       name = c_parser_peek_token (parser)->value;
8670       c_parser_consume_token (parser);
8671     }
8672   else
8673     c_parser_error (parser, "expected string literal");
8674   c_parser_skip_to_pragma_eol (parser);
8675 
8676   if (name)
8677     c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8678 }
8679 
8680 /* OpenMP 2.5 parsing routines.  */
8681 
8682 /* Returns name of the next clause.
8683    If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8684    the token is not consumed.  Otherwise appropriate pragma_omp_clause is
8685    returned and the token is consumed.  */
8686 
8687 static pragma_omp_clause
8688 c_parser_omp_clause_name (c_parser *parser)
8689 {
8690   pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8691 
8692   if (c_parser_next_token_is_keyword (parser, RID_IF))
8693     result = PRAGMA_OMP_CLAUSE_IF;
8694   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8695     result = PRAGMA_OMP_CLAUSE_DEFAULT;
8696   else if (c_parser_next_token_is (parser, CPP_NAME))
8697     {
8698       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8699 
8700       switch (p[0])
8701 	{
8702 	case 'c':
8703 	  if (!strcmp ("collapse", p))
8704 	    result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8705 	  else if (!strcmp ("copyin", p))
8706 	    result = PRAGMA_OMP_CLAUSE_COPYIN;
8707           else if (!strcmp ("copyprivate", p))
8708 	    result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8709 	  break;
8710 	case 'f':
8711 	  if (!strcmp ("final", p))
8712 	    result = PRAGMA_OMP_CLAUSE_FINAL;
8713 	  else if (!strcmp ("firstprivate", p))
8714 	    result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8715 	  break;
8716 	case 'l':
8717 	  if (!strcmp ("lastprivate", p))
8718 	    result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8719 	  break;
8720 	case 'm':
8721 	  if (!strcmp ("mergeable", p))
8722 	    result = PRAGMA_OMP_CLAUSE_MERGEABLE;
8723 	  break;
8724 	case 'n':
8725 	  if (!strcmp ("nowait", p))
8726 	    result = PRAGMA_OMP_CLAUSE_NOWAIT;
8727 	  else if (!strcmp ("num_threads", p))
8728 	    result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8729 	  break;
8730 	case 'o':
8731 	  if (!strcmp ("ordered", p))
8732 	    result = PRAGMA_OMP_CLAUSE_ORDERED;
8733 	  break;
8734 	case 'p':
8735 	  if (!strcmp ("private", p))
8736 	    result = PRAGMA_OMP_CLAUSE_PRIVATE;
8737 	  break;
8738 	case 'r':
8739 	  if (!strcmp ("reduction", p))
8740 	    result = PRAGMA_OMP_CLAUSE_REDUCTION;
8741 	  break;
8742 	case 's':
8743 	  if (!strcmp ("schedule", p))
8744 	    result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8745 	  else if (!strcmp ("shared", p))
8746 	    result = PRAGMA_OMP_CLAUSE_SHARED;
8747 	  break;
8748 	case 'u':
8749 	  if (!strcmp ("untied", p))
8750 	    result = PRAGMA_OMP_CLAUSE_UNTIED;
8751 	  break;
8752 	}
8753     }
8754 
8755   if (result != PRAGMA_OMP_CLAUSE_NONE)
8756     c_parser_consume_token (parser);
8757 
8758   return result;
8759 }
8760 
8761 /* Validate that a clause of the given type does not already exist.  */
8762 
8763 static void
8764 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8765 			   const char *name)
8766 {
8767   tree c;
8768 
8769   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8770     if (OMP_CLAUSE_CODE (c) == code)
8771       {
8772 	location_t loc = OMP_CLAUSE_LOCATION (c);
8773 	error_at (loc, "too many %qs clauses", name);
8774 	break;
8775       }
8776 }
8777 
8778 /* OpenMP 2.5:
8779    variable-list:
8780      identifier
8781      variable-list , identifier
8782 
8783    If KIND is nonzero, create the appropriate node and install the
8784    decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8785    If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8786 
8787    If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8788    return the list created.  */
8789 
8790 static tree
8791 c_parser_omp_variable_list (c_parser *parser,
8792 			    location_t clause_loc,
8793 			    enum omp_clause_code kind,
8794                             tree list)
8795 {
8796   if (c_parser_next_token_is_not (parser, CPP_NAME)
8797       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8798     c_parser_error (parser, "expected identifier");
8799 
8800   while (c_parser_next_token_is (parser, CPP_NAME)
8801 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8802     {
8803       tree t = lookup_name (c_parser_peek_token (parser)->value);
8804 
8805       if (t == NULL_TREE)
8806 	undeclared_variable (c_parser_peek_token (parser)->location,
8807 			     c_parser_peek_token (parser)->value);
8808       else if (t == error_mark_node)
8809 	;
8810       else if (kind != 0)
8811 	{
8812 	  tree u = build_omp_clause (clause_loc, kind);
8813 	  OMP_CLAUSE_DECL (u) = t;
8814 	  OMP_CLAUSE_CHAIN (u) = list;
8815 	  list = u;
8816 	}
8817       else
8818 	list = tree_cons (t, NULL_TREE, list);
8819 
8820       c_parser_consume_token (parser);
8821 
8822       if (c_parser_next_token_is_not (parser, CPP_COMMA))
8823 	break;
8824 
8825       c_parser_consume_token (parser);
8826     }
8827 
8828   return list;
8829 }
8830 
8831 /* Similarly, but expect leading and trailing parenthesis.  This is a very
8832    common case for omp clauses.  */
8833 
8834 static tree
8835 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8836 			      tree list)
8837 {
8838   /* The clauses location.  */
8839   location_t loc = c_parser_peek_token (parser)->location;
8840 
8841   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8842     {
8843       list = c_parser_omp_variable_list (parser, loc, kind, list);
8844       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8845     }
8846   return list;
8847 }
8848 
8849 /* OpenMP 3.0:
8850    collapse ( constant-expression ) */
8851 
8852 static tree
8853 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8854 {
8855   tree c, num = error_mark_node;
8856   HOST_WIDE_INT n;
8857   location_t loc;
8858 
8859   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8860 
8861   loc = c_parser_peek_token (parser)->location;
8862   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8863     {
8864       num = c_parser_expr_no_commas (parser, NULL).value;
8865       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8866     }
8867   if (num == error_mark_node)
8868     return list;
8869   if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8870       || !host_integerp (num, 0)
8871       || (n = tree_low_cst (num, 0)) <= 0
8872       || (int) n != n)
8873     {
8874       error_at (loc,
8875 		"collapse argument needs positive constant integer expression");
8876       return list;
8877     }
8878   c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8879   OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8880   OMP_CLAUSE_CHAIN (c) = list;
8881   return c;
8882 }
8883 
8884 /* OpenMP 2.5:
8885    copyin ( variable-list ) */
8886 
8887 static tree
8888 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8889 {
8890   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8891 }
8892 
8893 /* OpenMP 2.5:
8894    copyprivate ( variable-list ) */
8895 
8896 static tree
8897 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8898 {
8899   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8900 }
8901 
8902 /* OpenMP 2.5:
8903    default ( shared | none ) */
8904 
8905 static tree
8906 c_parser_omp_clause_default (c_parser *parser, tree list)
8907 {
8908   enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8909   location_t loc = c_parser_peek_token (parser)->location;
8910   tree c;
8911 
8912   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8913     return list;
8914   if (c_parser_next_token_is (parser, CPP_NAME))
8915     {
8916       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8917 
8918       switch (p[0])
8919 	{
8920 	case 'n':
8921 	  if (strcmp ("none", p) != 0)
8922 	    goto invalid_kind;
8923 	  kind = OMP_CLAUSE_DEFAULT_NONE;
8924 	  break;
8925 
8926 	case 's':
8927 	  if (strcmp ("shared", p) != 0)
8928 	    goto invalid_kind;
8929 	  kind = OMP_CLAUSE_DEFAULT_SHARED;
8930 	  break;
8931 
8932 	default:
8933 	  goto invalid_kind;
8934 	}
8935 
8936       c_parser_consume_token (parser);
8937     }
8938   else
8939     {
8940     invalid_kind:
8941       c_parser_error (parser, "expected %<none%> or %<shared%>");
8942     }
8943   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8944 
8945   if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8946     return list;
8947 
8948   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8949   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8950   OMP_CLAUSE_CHAIN (c) = list;
8951   OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8952 
8953   return c;
8954 }
8955 
8956 /* OpenMP 2.5:
8957    firstprivate ( variable-list ) */
8958 
8959 static tree
8960 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8961 {
8962   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8963 }
8964 
8965 /* OpenMP 3.1:
8966    final ( expression ) */
8967 
8968 static tree
8969 c_parser_omp_clause_final (c_parser *parser, tree list)
8970 {
8971   location_t loc = c_parser_peek_token (parser)->location;
8972   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8973     {
8974       tree t = c_parser_paren_condition (parser);
8975       tree c;
8976 
8977       check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
8978 
8979       c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
8980       OMP_CLAUSE_FINAL_EXPR (c) = t;
8981       OMP_CLAUSE_CHAIN (c) = list;
8982       list = c;
8983     }
8984   else
8985     c_parser_error (parser, "expected %<(%>");
8986 
8987   return list;
8988 }
8989 
8990 /* OpenMP 2.5:
8991    if ( expression ) */
8992 
8993 static tree
8994 c_parser_omp_clause_if (c_parser *parser, tree list)
8995 {
8996   location_t loc = c_parser_peek_token (parser)->location;
8997   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8998     {
8999       tree t = c_parser_paren_condition (parser);
9000       tree c;
9001 
9002       check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
9003 
9004       c = build_omp_clause (loc, OMP_CLAUSE_IF);
9005       OMP_CLAUSE_IF_EXPR (c) = t;
9006       OMP_CLAUSE_CHAIN (c) = list;
9007       list = c;
9008     }
9009   else
9010     c_parser_error (parser, "expected %<(%>");
9011 
9012   return list;
9013 }
9014 
9015 /* OpenMP 2.5:
9016    lastprivate ( variable-list ) */
9017 
9018 static tree
9019 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
9020 {
9021   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
9022 }
9023 
9024 /* OpenMP 3.1:
9025    mergeable */
9026 
9027 static tree
9028 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
9029 {
9030   tree c;
9031 
9032   /* FIXME: Should we allow duplicates?  */
9033   check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
9034 
9035   c = build_omp_clause (c_parser_peek_token (parser)->location,
9036 			OMP_CLAUSE_MERGEABLE);
9037   OMP_CLAUSE_CHAIN (c) = list;
9038 
9039   return c;
9040 }
9041 
9042 /* OpenMP 2.5:
9043    nowait */
9044 
9045 static tree
9046 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
9047 {
9048   tree c;
9049   location_t loc = c_parser_peek_token (parser)->location;
9050 
9051   check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
9052 
9053   c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
9054   OMP_CLAUSE_CHAIN (c) = list;
9055   return c;
9056 }
9057 
9058 /* OpenMP 2.5:
9059    num_threads ( expression ) */
9060 
9061 static tree
9062 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
9063 {
9064   location_t num_threads_loc = c_parser_peek_token (parser)->location;
9065   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9066     {
9067       location_t expr_loc = c_parser_peek_token (parser)->location;
9068       tree c, t = c_parser_expression (parser).value;
9069       mark_exp_read (t);
9070       t = c_fully_fold (t, false, NULL);
9071 
9072       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9073 
9074       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
9075 	{
9076 	  c_parser_error (parser, "expected integer expression");
9077 	  return list;
9078 	}
9079 
9080       /* Attempt to statically determine when the number isn't positive.  */
9081       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
9082 		       build_int_cst (TREE_TYPE (t), 0));
9083       if (CAN_HAVE_LOCATION_P (c))
9084 	SET_EXPR_LOCATION (c, expr_loc);
9085       if (c == boolean_true_node)
9086 	{
9087 	  warning_at (expr_loc, 0,
9088 		      "%<num_threads%> value must be positive");
9089 	  t = integer_one_node;
9090 	}
9091 
9092       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
9093 
9094       c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
9095       OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
9096       OMP_CLAUSE_CHAIN (c) = list;
9097       list = c;
9098     }
9099 
9100   return list;
9101 }
9102 
9103 /* OpenMP 2.5:
9104    ordered */
9105 
9106 static tree
9107 c_parser_omp_clause_ordered (c_parser *parser, tree list)
9108 {
9109   tree c;
9110 
9111   check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
9112 
9113   c = build_omp_clause (c_parser_peek_token (parser)->location,
9114 			OMP_CLAUSE_ORDERED);
9115   OMP_CLAUSE_CHAIN (c) = list;
9116 
9117   return c;
9118 }
9119 
9120 /* OpenMP 2.5:
9121    private ( variable-list ) */
9122 
9123 static tree
9124 c_parser_omp_clause_private (c_parser *parser, tree list)
9125 {
9126   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
9127 }
9128 
9129 /* OpenMP 2.5:
9130    reduction ( reduction-operator : variable-list )
9131 
9132    reduction-operator:
9133      One of: + * - & ^ | && ||
9134 
9135    OpenMP 3.1:
9136 
9137    reduction-operator:
9138      One of: + * - & ^ | && || max min  */
9139 
9140 static tree
9141 c_parser_omp_clause_reduction (c_parser *parser, tree list)
9142 {
9143   location_t clause_loc = c_parser_peek_token (parser)->location;
9144   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9145     {
9146       enum tree_code code;
9147 
9148       switch (c_parser_peek_token (parser)->type)
9149 	{
9150 	case CPP_PLUS:
9151 	  code = PLUS_EXPR;
9152 	  break;
9153 	case CPP_MULT:
9154 	  code = MULT_EXPR;
9155 	  break;
9156 	case CPP_MINUS:
9157 	  code = MINUS_EXPR;
9158 	  break;
9159 	case CPP_AND:
9160 	  code = BIT_AND_EXPR;
9161 	  break;
9162 	case CPP_XOR:
9163 	  code = BIT_XOR_EXPR;
9164 	  break;
9165 	case CPP_OR:
9166 	  code = BIT_IOR_EXPR;
9167 	  break;
9168 	case CPP_AND_AND:
9169 	  code = TRUTH_ANDIF_EXPR;
9170 	  break;
9171 	case CPP_OR_OR:
9172 	  code = TRUTH_ORIF_EXPR;
9173 	  break;
9174         case CPP_NAME:
9175 	  {
9176 	    const char *p
9177 	      = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9178 	    if (strcmp (p, "min") == 0)
9179 	      {
9180 		code = MIN_EXPR;
9181 		break;
9182 	      }
9183 	    if (strcmp (p, "max") == 0)
9184 	      {
9185 		code = MAX_EXPR;
9186 		break;
9187 	      }
9188 	  }
9189 	  /* FALLTHRU */
9190 	default:
9191 	  c_parser_error (parser,
9192 			  "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9193 			  "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9194 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
9195 	  return list;
9196 	}
9197       c_parser_consume_token (parser);
9198       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9199 	{
9200 	  tree nl, c;
9201 
9202 	  nl = c_parser_omp_variable_list (parser, clause_loc,
9203 					   OMP_CLAUSE_REDUCTION, list);
9204 	  for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
9205 	    OMP_CLAUSE_REDUCTION_CODE (c) = code;
9206 
9207 	  list = nl;
9208 	}
9209       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9210     }
9211   return list;
9212 }
9213 
9214 /* OpenMP 2.5:
9215    schedule ( schedule-kind )
9216    schedule ( schedule-kind , expression )
9217 
9218    schedule-kind:
9219      static | dynamic | guided | runtime | auto
9220 */
9221 
9222 static tree
9223 c_parser_omp_clause_schedule (c_parser *parser, tree list)
9224 {
9225   tree c, t;
9226   location_t loc = c_parser_peek_token (parser)->location;
9227 
9228   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9229     return list;
9230 
9231   c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
9232 
9233   if (c_parser_next_token_is (parser, CPP_NAME))
9234     {
9235       tree kind = c_parser_peek_token (parser)->value;
9236       const char *p = IDENTIFIER_POINTER (kind);
9237 
9238       switch (p[0])
9239 	{
9240 	case 'd':
9241 	  if (strcmp ("dynamic", p) != 0)
9242 	    goto invalid_kind;
9243 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
9244 	  break;
9245 
9246         case 'g':
9247 	  if (strcmp ("guided", p) != 0)
9248 	    goto invalid_kind;
9249 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
9250 	  break;
9251 
9252 	case 'r':
9253 	  if (strcmp ("runtime", p) != 0)
9254 	    goto invalid_kind;
9255 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
9256 	  break;
9257 
9258 	default:
9259 	  goto invalid_kind;
9260 	}
9261     }
9262   else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
9263     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
9264   else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
9265     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
9266   else
9267     goto invalid_kind;
9268 
9269   c_parser_consume_token (parser);
9270   if (c_parser_next_token_is (parser, CPP_COMMA))
9271     {
9272       location_t here;
9273       c_parser_consume_token (parser);
9274 
9275       here = c_parser_peek_token (parser)->location;
9276       t = c_parser_expr_no_commas (parser, NULL).value;
9277       mark_exp_read (t);
9278       t = c_fully_fold (t, false, NULL);
9279 
9280       if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
9281 	error_at (here, "schedule %<runtime%> does not take "
9282 		  "a %<chunk_size%> parameter");
9283       else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
9284 	error_at (here,
9285 		  "schedule %<auto%> does not take "
9286 		  "a %<chunk_size%> parameter");
9287       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
9288 	OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
9289       else
9290 	c_parser_error (parser, "expected integer expression");
9291 
9292       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9293     }
9294   else
9295     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9296 			       "expected %<,%> or %<)%>");
9297 
9298   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
9299   OMP_CLAUSE_CHAIN (c) = list;
9300   return c;
9301 
9302  invalid_kind:
9303   c_parser_error (parser, "invalid schedule kind");
9304   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
9305   return list;
9306 }
9307 
9308 /* OpenMP 2.5:
9309    shared ( variable-list ) */
9310 
9311 static tree
9312 c_parser_omp_clause_shared (c_parser *parser, tree list)
9313 {
9314   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
9315 }
9316 
9317 /* OpenMP 3.0:
9318    untied */
9319 
9320 static tree
9321 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
9322 {
9323   tree c;
9324 
9325   /* FIXME: Should we allow duplicates?  */
9326   check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
9327 
9328   c = build_omp_clause (c_parser_peek_token (parser)->location,
9329 			OMP_CLAUSE_UNTIED);
9330   OMP_CLAUSE_CHAIN (c) = list;
9331 
9332   return c;
9333 }
9334 
9335 /* Parse all OpenMP clauses.  The set clauses allowed by the directive
9336    is a bitmask in MASK.  Return the list of clauses found; the result
9337    of clause default goes in *pdefault.  */
9338 
9339 static tree
9340 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
9341 			  const char *where)
9342 {
9343   tree clauses = NULL;
9344   bool first = true;
9345 
9346   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9347     {
9348       location_t here;
9349       pragma_omp_clause c_kind;
9350       const char *c_name;
9351       tree prev = clauses;
9352 
9353       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
9354 	c_parser_consume_token (parser);
9355 
9356       first = false;
9357       here = c_parser_peek_token (parser)->location;
9358       c_kind = c_parser_omp_clause_name (parser);
9359 
9360       switch (c_kind)
9361 	{
9362 	case PRAGMA_OMP_CLAUSE_COLLAPSE:
9363 	  clauses = c_parser_omp_clause_collapse (parser, clauses);
9364 	  c_name = "collapse";
9365 	  break;
9366 	case PRAGMA_OMP_CLAUSE_COPYIN:
9367 	  clauses = c_parser_omp_clause_copyin (parser, clauses);
9368 	  c_name = "copyin";
9369 	  break;
9370 	case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
9371 	  clauses = c_parser_omp_clause_copyprivate (parser, clauses);
9372 	  c_name = "copyprivate";
9373 	  break;
9374 	case PRAGMA_OMP_CLAUSE_DEFAULT:
9375 	  clauses = c_parser_omp_clause_default (parser, clauses);
9376 	  c_name = "default";
9377 	  break;
9378 	case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
9379 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
9380 	  c_name = "firstprivate";
9381 	  break;
9382 	case PRAGMA_OMP_CLAUSE_FINAL:
9383 	  clauses = c_parser_omp_clause_final (parser, clauses);
9384 	  c_name = "final";
9385 	  break;
9386 	case PRAGMA_OMP_CLAUSE_IF:
9387 	  clauses = c_parser_omp_clause_if (parser, clauses);
9388 	  c_name = "if";
9389 	  break;
9390 	case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
9391 	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
9392 	  c_name = "lastprivate";
9393 	  break;
9394 	case PRAGMA_OMP_CLAUSE_MERGEABLE:
9395 	  clauses = c_parser_omp_clause_mergeable (parser, clauses);
9396 	  c_name = "mergeable";
9397 	  break;
9398 	case PRAGMA_OMP_CLAUSE_NOWAIT:
9399 	  clauses = c_parser_omp_clause_nowait (parser, clauses);
9400 	  c_name = "nowait";
9401 	  break;
9402 	case PRAGMA_OMP_CLAUSE_NUM_THREADS:
9403 	  clauses = c_parser_omp_clause_num_threads (parser, clauses);
9404 	  c_name = "num_threads";
9405 	  break;
9406 	case PRAGMA_OMP_CLAUSE_ORDERED:
9407 	  clauses = c_parser_omp_clause_ordered (parser, clauses);
9408 	  c_name = "ordered";
9409 	  break;
9410 	case PRAGMA_OMP_CLAUSE_PRIVATE:
9411 	  clauses = c_parser_omp_clause_private (parser, clauses);
9412 	  c_name = "private";
9413 	  break;
9414 	case PRAGMA_OMP_CLAUSE_REDUCTION:
9415 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
9416 	  c_name = "reduction";
9417 	  break;
9418 	case PRAGMA_OMP_CLAUSE_SCHEDULE:
9419 	  clauses = c_parser_omp_clause_schedule (parser, clauses);
9420 	  c_name = "schedule";
9421 	  break;
9422 	case PRAGMA_OMP_CLAUSE_SHARED:
9423 	  clauses = c_parser_omp_clause_shared (parser, clauses);
9424 	  c_name = "shared";
9425 	  break;
9426 	case PRAGMA_OMP_CLAUSE_UNTIED:
9427 	  clauses = c_parser_omp_clause_untied (parser, clauses);
9428 	  c_name = "untied";
9429 	  break;
9430 	default:
9431 	  c_parser_error (parser, "expected %<#pragma omp%> clause");
9432 	  goto saw_error;
9433 	}
9434 
9435       if (((mask >> c_kind) & 1) == 0 && !parser->error)
9436 	{
9437 	  /* Remove the invalid clause(s) from the list to avoid
9438 	     confusing the rest of the compiler.  */
9439 	  clauses = prev;
9440 	  error_at (here, "%qs is not valid for %qs", c_name, where);
9441 	}
9442     }
9443 
9444  saw_error:
9445   c_parser_skip_to_pragma_eol (parser);
9446 
9447   return c_finish_omp_clauses (clauses);
9448 }
9449 
9450 /* OpenMP 2.5:
9451    structured-block:
9452      statement
9453 
9454    In practice, we're also interested in adding the statement to an
9455    outer node.  So it is convenient if we work around the fact that
9456    c_parser_statement calls add_stmt.  */
9457 
9458 static tree
9459 c_parser_omp_structured_block (c_parser *parser)
9460 {
9461   tree stmt = push_stmt_list ();
9462   c_parser_statement (parser);
9463   return pop_stmt_list (stmt);
9464 }
9465 
9466 /* OpenMP 2.5:
9467    # pragma omp atomic new-line
9468      expression-stmt
9469 
9470    expression-stmt:
9471      x binop= expr | x++ | ++x | x-- | --x
9472    binop:
9473      +, *, -, /, &, ^, |, <<, >>
9474 
9475   where x is an lvalue expression with scalar type.
9476 
9477    OpenMP 3.1:
9478    # pragma omp atomic new-line
9479      update-stmt
9480 
9481    # pragma omp atomic read new-line
9482      read-stmt
9483 
9484    # pragma omp atomic write new-line
9485      write-stmt
9486 
9487    # pragma omp atomic update new-line
9488      update-stmt
9489 
9490    # pragma omp atomic capture new-line
9491      capture-stmt
9492 
9493    # pragma omp atomic capture new-line
9494      capture-block
9495 
9496    read-stmt:
9497      v = x
9498    write-stmt:
9499      x = expr
9500    update-stmt:
9501      expression-stmt | x = x binop expr
9502    capture-stmt:
9503      v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9504    capture-block:
9505      { v = x; update-stmt; } | { update-stmt; v = x; }
9506 
9507   where x and v are lvalue expressions with scalar type.
9508 
9509   LOC is the location of the #pragma token.  */
9510 
9511 static void
9512 c_parser_omp_atomic (location_t loc, c_parser *parser)
9513 {
9514   tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
9515   tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
9516   tree stmt, orig_lhs;
9517   enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
9518   struct c_expr rhs_expr;
9519   bool structured_block = false;
9520 
9521   if (c_parser_next_token_is (parser, CPP_NAME))
9522     {
9523       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9524 
9525       if (!strcmp (p, "read"))
9526 	code = OMP_ATOMIC_READ;
9527       else if (!strcmp (p, "write"))
9528 	code = NOP_EXPR;
9529       else if (!strcmp (p, "update"))
9530 	code = OMP_ATOMIC;
9531       else if (!strcmp (p, "capture"))
9532 	code = OMP_ATOMIC_CAPTURE_NEW;
9533       else
9534 	p = NULL;
9535       if (p)
9536 	c_parser_consume_token (parser);
9537     }
9538   c_parser_skip_to_pragma_eol (parser);
9539 
9540   switch (code)
9541     {
9542     case OMP_ATOMIC_READ:
9543     case NOP_EXPR: /* atomic write */
9544       v = c_parser_unary_expression (parser).value;
9545       v = c_fully_fold (v, false, NULL);
9546       if (v == error_mark_node)
9547 	goto saw_error;
9548       loc = c_parser_peek_token (parser)->location;
9549       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9550 	goto saw_error;
9551       if (code == NOP_EXPR)
9552 	lhs = c_parser_expression (parser).value;
9553       else
9554 	lhs = c_parser_unary_expression (parser).value;
9555       lhs = c_fully_fold (lhs, false, NULL);
9556       if (lhs == error_mark_node)
9557 	goto saw_error;
9558       if (code == NOP_EXPR)
9559 	{
9560 	  /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9561 	     opcode.  */
9562 	  code = OMP_ATOMIC;
9563 	  rhs = lhs;
9564 	  lhs = v;
9565 	  v = NULL_TREE;
9566 	}
9567       goto done;
9568     case OMP_ATOMIC_CAPTURE_NEW:
9569       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9570 	{
9571 	  c_parser_consume_token (parser);
9572 	  structured_block = true;
9573 	}
9574       else
9575 	{
9576 	  v = c_parser_unary_expression (parser).value;
9577 	  v = c_fully_fold (v, false, NULL);
9578 	  if (v == error_mark_node)
9579 	    goto saw_error;
9580 	  if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9581 	    goto saw_error;
9582 	}
9583       break;
9584     default:
9585       break;
9586     }
9587 
9588   /* For structured_block case we don't know yet whether
9589      old or new x should be captured.  */
9590 restart:
9591   lhs = c_parser_unary_expression (parser).value;
9592   lhs = c_fully_fold (lhs, false, NULL);
9593   orig_lhs = lhs;
9594   switch (TREE_CODE (lhs))
9595     {
9596     case ERROR_MARK:
9597     saw_error:
9598       c_parser_skip_to_end_of_block_or_statement (parser);
9599       if (structured_block)
9600 	{
9601 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9602 	    c_parser_consume_token (parser);
9603 	  else if (code == OMP_ATOMIC_CAPTURE_NEW)
9604 	    {
9605 	      c_parser_skip_to_end_of_block_or_statement (parser);
9606 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9607 		c_parser_consume_token (parser);
9608 	    }
9609 	}
9610       return;
9611 
9612     case POSTINCREMENT_EXPR:
9613       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
9614 	code = OMP_ATOMIC_CAPTURE_OLD;
9615       /* FALLTHROUGH */
9616     case PREINCREMENT_EXPR:
9617       lhs = TREE_OPERAND (lhs, 0);
9618       opcode = PLUS_EXPR;
9619       rhs = integer_one_node;
9620       break;
9621 
9622     case POSTDECREMENT_EXPR:
9623       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
9624 	code = OMP_ATOMIC_CAPTURE_OLD;
9625       /* FALLTHROUGH */
9626     case PREDECREMENT_EXPR:
9627       lhs = TREE_OPERAND (lhs, 0);
9628       opcode = MINUS_EXPR;
9629       rhs = integer_one_node;
9630       break;
9631 
9632     case COMPOUND_EXPR:
9633       if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
9634 	  && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
9635 	  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
9636 	  && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
9637 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9638 					      (TREE_OPERAND (lhs, 1), 0), 0)))
9639 	     == BOOLEAN_TYPE)
9640 	/* Undo effects of boolean_increment for post {in,de}crement.  */
9641 	lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
9642       /* FALLTHRU */
9643     case MODIFY_EXPR:
9644       if (TREE_CODE (lhs) == MODIFY_EXPR
9645 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
9646 	{
9647 	  /* Undo effects of boolean_increment.  */
9648 	  if (integer_onep (TREE_OPERAND (lhs, 1)))
9649 	    {
9650 	      /* This is pre or post increment.  */
9651 	      rhs = TREE_OPERAND (lhs, 1);
9652 	      lhs = TREE_OPERAND (lhs, 0);
9653 	      opcode = NOP_EXPR;
9654 	      if (code == OMP_ATOMIC_CAPTURE_NEW
9655 		  && !structured_block
9656 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
9657 		code = OMP_ATOMIC_CAPTURE_OLD;
9658 	      break;
9659 	    }
9660 	  if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
9661 	      && TREE_OPERAND (lhs, 0)
9662 		 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
9663 	    {
9664 	      /* This is pre or post decrement.  */
9665 	      rhs = TREE_OPERAND (lhs, 1);
9666 	      lhs = TREE_OPERAND (lhs, 0);
9667 	      opcode = NOP_EXPR;
9668 	      if (code == OMP_ATOMIC_CAPTURE_NEW
9669 		  && !structured_block
9670 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
9671 		code = OMP_ATOMIC_CAPTURE_OLD;
9672 	      break;
9673 	    }
9674 	}
9675       /* FALLTHRU */
9676     default:
9677       switch (c_parser_peek_token (parser)->type)
9678 	{
9679 	case CPP_MULT_EQ:
9680 	  opcode = MULT_EXPR;
9681 	  break;
9682 	case CPP_DIV_EQ:
9683 	  opcode = TRUNC_DIV_EXPR;
9684 	  break;
9685 	case CPP_PLUS_EQ:
9686 	  opcode = PLUS_EXPR;
9687 	  break;
9688 	case CPP_MINUS_EQ:
9689 	  opcode = MINUS_EXPR;
9690 	  break;
9691 	case CPP_LSHIFT_EQ:
9692 	  opcode = LSHIFT_EXPR;
9693 	  break;
9694 	case CPP_RSHIFT_EQ:
9695 	  opcode = RSHIFT_EXPR;
9696 	  break;
9697 	case CPP_AND_EQ:
9698 	  opcode = BIT_AND_EXPR;
9699 	  break;
9700 	case CPP_OR_EQ:
9701 	  opcode = BIT_IOR_EXPR;
9702 	  break;
9703 	case CPP_XOR_EQ:
9704 	  opcode = BIT_XOR_EXPR;
9705 	  break;
9706 	case CPP_EQ:
9707 	  if (structured_block || code == OMP_ATOMIC)
9708 	    {
9709 	      location_t aloc = c_parser_peek_token (parser)->location;
9710 	      location_t rhs_loc;
9711 	      enum c_parser_prec oprec = PREC_NONE;
9712 
9713 	      c_parser_consume_token (parser);
9714 	      rhs1 = c_parser_unary_expression (parser).value;
9715 	      rhs1 = c_fully_fold (rhs1, false, NULL);
9716 	      if (rhs1 == error_mark_node)
9717 		goto saw_error;
9718 	      switch (c_parser_peek_token (parser)->type)
9719 		{
9720 		case CPP_SEMICOLON:
9721 		  if (code == OMP_ATOMIC_CAPTURE_NEW)
9722 		    {
9723 		      code = OMP_ATOMIC_CAPTURE_OLD;
9724 		      v = lhs;
9725 		      lhs = NULL_TREE;
9726 		      lhs1 = rhs1;
9727 		      rhs1 = NULL_TREE;
9728 		      c_parser_consume_token (parser);
9729 		      goto restart;
9730 		    }
9731 		  c_parser_error (parser,
9732 				  "invalid form of %<#pragma omp atomic%>");
9733 		  goto saw_error;
9734 		case CPP_MULT:
9735 		  opcode = MULT_EXPR;
9736 		  oprec = PREC_MULT;
9737 		  break;
9738 		case CPP_DIV:
9739 		  opcode = TRUNC_DIV_EXPR;
9740 		  oprec = PREC_MULT;
9741 		  break;
9742 		case CPP_PLUS:
9743 		  opcode = PLUS_EXPR;
9744 		  oprec = PREC_ADD;
9745 		  break;
9746 		case CPP_MINUS:
9747 		  opcode = MINUS_EXPR;
9748 		  oprec = PREC_ADD;
9749 		  break;
9750 		case CPP_LSHIFT:
9751 		  opcode = LSHIFT_EXPR;
9752 		  oprec = PREC_SHIFT;
9753 		  break;
9754 		case CPP_RSHIFT:
9755 		  opcode = RSHIFT_EXPR;
9756 		  oprec = PREC_SHIFT;
9757 		  break;
9758 		case CPP_AND:
9759 		  opcode = BIT_AND_EXPR;
9760 		  oprec = PREC_BITAND;
9761 		  break;
9762 		case CPP_OR:
9763 		  opcode = BIT_IOR_EXPR;
9764 		  oprec = PREC_BITOR;
9765 		  break;
9766 		case CPP_XOR:
9767 		  opcode = BIT_XOR_EXPR;
9768 		  oprec = PREC_BITXOR;
9769 		  break;
9770 		default:
9771 		  c_parser_error (parser,
9772 				  "invalid operator for %<#pragma omp atomic%>");
9773 		  goto saw_error;
9774 		}
9775 	      loc = aloc;
9776 	      c_parser_consume_token (parser);
9777 	      rhs_loc = c_parser_peek_token (parser)->location;
9778 	      if (commutative_tree_code (opcode))
9779 		oprec = (enum c_parser_prec) (oprec - 1);
9780 	      rhs_expr = c_parser_binary_expression (parser, NULL, oprec);
9781 	      rhs_expr = default_function_array_read_conversion (rhs_loc,
9782 								 rhs_expr);
9783 	      rhs = rhs_expr.value;
9784 	      rhs = c_fully_fold (rhs, false, NULL);
9785 	      goto stmt_done;
9786 	    }
9787 	  /* FALLTHROUGH */
9788 	default:
9789 	  c_parser_error (parser,
9790 			  "invalid operator for %<#pragma omp atomic%>");
9791 	  goto saw_error;
9792 	}
9793 
9794       /* Arrange to pass the location of the assignment operator to
9795 	 c_finish_omp_atomic.  */
9796       loc = c_parser_peek_token (parser)->location;
9797       c_parser_consume_token (parser);
9798       {
9799 	location_t rhs_loc = c_parser_peek_token (parser)->location;
9800 	rhs_expr = c_parser_expression (parser);
9801 	rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
9802       }
9803       rhs = rhs_expr.value;
9804       rhs = c_fully_fold (rhs, false, NULL);
9805       break;
9806     }
9807 stmt_done:
9808   if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
9809     {
9810       if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
9811 	goto saw_error;
9812       v = c_parser_unary_expression (parser).value;
9813       v = c_fully_fold (v, false, NULL);
9814       if (v == error_mark_node)
9815 	goto saw_error;
9816       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9817 	goto saw_error;
9818       lhs1 = c_parser_unary_expression (parser).value;
9819       lhs1 = c_fully_fold (lhs1, false, NULL);
9820       if (lhs1 == error_mark_node)
9821 	goto saw_error;
9822     }
9823   if (structured_block)
9824     {
9825       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9826       c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
9827     }
9828 done:
9829   stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1);
9830   if (stmt != error_mark_node)
9831     add_stmt (stmt);
9832 
9833   if (!structured_block)
9834     c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9835 }
9836 
9837 
9838 /* OpenMP 2.5:
9839    # pragma omp barrier new-line
9840 */
9841 
9842 static void
9843 c_parser_omp_barrier (c_parser *parser)
9844 {
9845   location_t loc = c_parser_peek_token (parser)->location;
9846   c_parser_consume_pragma (parser);
9847   c_parser_skip_to_pragma_eol (parser);
9848 
9849   c_finish_omp_barrier (loc);
9850 }
9851 
9852 /* OpenMP 2.5:
9853    # pragma omp critical [(name)] new-line
9854      structured-block
9855 
9856   LOC is the location of the #pragma itself.  */
9857 
9858 static tree
9859 c_parser_omp_critical (location_t loc, c_parser *parser)
9860 {
9861   tree stmt, name = NULL;
9862 
9863   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9864     {
9865       c_parser_consume_token (parser);
9866       if (c_parser_next_token_is (parser, CPP_NAME))
9867 	{
9868 	  name = c_parser_peek_token (parser)->value;
9869 	  c_parser_consume_token (parser);
9870 	  c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9871 	}
9872       else
9873 	c_parser_error (parser, "expected identifier");
9874     }
9875   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9876     c_parser_error (parser, "expected %<(%> or end of line");
9877   c_parser_skip_to_pragma_eol (parser);
9878 
9879   stmt = c_parser_omp_structured_block (parser);
9880   return c_finish_omp_critical (loc, stmt, name);
9881 }
9882 
9883 /* OpenMP 2.5:
9884    # pragma omp flush flush-vars[opt] new-line
9885 
9886    flush-vars:
9887      ( variable-list ) */
9888 
9889 static void
9890 c_parser_omp_flush (c_parser *parser)
9891 {
9892   location_t loc = c_parser_peek_token (parser)->location;
9893   c_parser_consume_pragma (parser);
9894   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9895     c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9896   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9897     c_parser_error (parser, "expected %<(%> or end of line");
9898   c_parser_skip_to_pragma_eol (parser);
9899 
9900   c_finish_omp_flush (loc);
9901 }
9902 
9903 /* Parse the restricted form of the for statement allowed by OpenMP.
9904    The real trick here is to determine the loop control variable early
9905    so that we can push a new decl if necessary to make it private.
9906    LOC is the location of the OMP in "#pragma omp".  */
9907 
9908 static tree
9909 c_parser_omp_for_loop (location_t loc,
9910 		       c_parser *parser, tree clauses, tree *par_clauses)
9911 {
9912   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
9913   tree declv, condv, incrv, initv, ret = NULL;
9914   bool fail = false, open_brace_parsed = false;
9915   int i, collapse = 1, nbraces = 0;
9916   location_t for_loc;
9917   vec<tree, va_gc> *for_block = make_tree_vector ();
9918 
9919   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
9920     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
9921       collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
9922 
9923   gcc_assert (collapse >= 1);
9924 
9925   declv = make_tree_vec (collapse);
9926   initv = make_tree_vec (collapse);
9927   condv = make_tree_vec (collapse);
9928   incrv = make_tree_vec (collapse);
9929 
9930   if (!c_parser_next_token_is_keyword (parser, RID_FOR))
9931     {
9932       c_parser_error (parser, "for statement expected");
9933       return NULL;
9934     }
9935   for_loc = c_parser_peek_token (parser)->location;
9936   c_parser_consume_token (parser);
9937 
9938   for (i = 0; i < collapse; i++)
9939     {
9940       int bracecount = 0;
9941 
9942       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9943 	goto pop_scopes;
9944 
9945       /* Parse the initialization declaration or expression.  */
9946       if (c_parser_next_tokens_start_declaration (parser))
9947 	{
9948 	  if (i > 0)
9949 	    vec_safe_push (for_block, c_begin_compound_stmt (true));
9950 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9951 	  decl = check_for_loop_decls (for_loc, flag_isoc99);
9952 	  if (decl == NULL)
9953 	    goto error_init;
9954 	  if (DECL_INITIAL (decl) == error_mark_node)
9955 	    decl = error_mark_node;
9956 	  init = decl;
9957 	}
9958       else if (c_parser_next_token_is (parser, CPP_NAME)
9959 	       && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9960 	{
9961 	  struct c_expr decl_exp;
9962 	  struct c_expr init_exp;
9963 	  location_t init_loc;
9964 
9965 	  decl_exp = c_parser_postfix_expression (parser);
9966 	  decl = decl_exp.value;
9967 
9968 	  c_parser_require (parser, CPP_EQ, "expected %<=%>");
9969 
9970 	  init_loc = c_parser_peek_token (parser)->location;
9971 	  init_exp = c_parser_expr_no_commas (parser, NULL);
9972 	  init_exp = default_function_array_read_conversion (init_loc,
9973 							     init_exp);
9974 	  init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9975 				    NOP_EXPR, init_loc, init_exp.value,
9976 				    init_exp.original_type);
9977 	  init = c_process_expr_stmt (init_loc, init);
9978 
9979 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9980 	}
9981       else
9982 	{
9983 	error_init:
9984 	  c_parser_error (parser,
9985 			  "expected iteration declaration or initialization");
9986 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9987 				     "expected %<)%>");
9988 	  fail = true;
9989 	  goto parse_next;
9990 	}
9991 
9992       /* Parse the loop condition.  */
9993       cond = NULL_TREE;
9994       if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9995 	{
9996 	  location_t cond_loc = c_parser_peek_token (parser)->location;
9997 	  struct c_expr cond_expr = c_parser_binary_expression (parser, NULL,
9998 								PREC_NONE);
9999 
10000 	  cond = cond_expr.value;
10001 	  cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
10002 	  cond = c_fully_fold (cond, false, NULL);
10003 	  switch (cond_expr.original_code)
10004 	    {
10005 	    case GT_EXPR:
10006 	    case GE_EXPR:
10007 	    case LT_EXPR:
10008 	    case LE_EXPR:
10009 	      break;
10010 	    default:
10011 	      /* Can't be cond = error_mark_node, because we want to preserve
10012 		 the location until c_finish_omp_for.  */
10013 	      cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
10014 	      break;
10015 	    }
10016 	  protected_set_expr_location (cond, cond_loc);
10017 	}
10018       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10019 
10020       /* Parse the increment expression.  */
10021       incr = NULL_TREE;
10022       if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
10023 	{
10024 	  location_t incr_loc = c_parser_peek_token (parser)->location;
10025 
10026 	  incr = c_process_expr_stmt (incr_loc,
10027 				      c_parser_expression (parser).value);
10028 	}
10029       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10030 
10031       if (decl == NULL || decl == error_mark_node || init == error_mark_node)
10032 	fail = true;
10033       else
10034 	{
10035 	  TREE_VEC_ELT (declv, i) = decl;
10036 	  TREE_VEC_ELT (initv, i) = init;
10037 	  TREE_VEC_ELT (condv, i) = cond;
10038 	  TREE_VEC_ELT (incrv, i) = incr;
10039 	}
10040 
10041     parse_next:
10042       if (i == collapse - 1)
10043 	break;
10044 
10045       /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10046 	 in between the collapsed for loops to be still considered perfectly
10047 	 nested.  Hopefully the final version clarifies this.
10048 	 For now handle (multiple) {'s and empty statements.  */
10049       do
10050 	{
10051 	  if (c_parser_next_token_is_keyword (parser, RID_FOR))
10052 	    {
10053 	      c_parser_consume_token (parser);
10054 	      break;
10055 	    }
10056 	  else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
10057 	    {
10058 	      c_parser_consume_token (parser);
10059 	      bracecount++;
10060 	    }
10061 	  else if (bracecount
10062 		   && c_parser_next_token_is (parser, CPP_SEMICOLON))
10063 	    c_parser_consume_token (parser);
10064 	  else
10065 	    {
10066 	      c_parser_error (parser, "not enough perfectly nested loops");
10067 	      if (bracecount)
10068 		{
10069 		  open_brace_parsed = true;
10070 		  bracecount--;
10071 		}
10072 	      fail = true;
10073 	      collapse = 0;
10074 	      break;
10075 	    }
10076 	}
10077       while (1);
10078 
10079       nbraces += bracecount;
10080     }
10081 
10082   save_break = c_break_label;
10083   c_break_label = size_one_node;
10084   save_cont = c_cont_label;
10085   c_cont_label = NULL_TREE;
10086   body = push_stmt_list ();
10087 
10088   if (open_brace_parsed)
10089     {
10090       location_t here = c_parser_peek_token (parser)->location;
10091       stmt = c_begin_compound_stmt (true);
10092       c_parser_compound_statement_nostart (parser);
10093       add_stmt (c_end_compound_stmt (here, stmt, true));
10094     }
10095   else
10096     add_stmt (c_parser_c99_block_statement (parser));
10097   if (c_cont_label)
10098     {
10099       tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
10100       SET_EXPR_LOCATION (t, loc);
10101       add_stmt (t);
10102     }
10103 
10104   body = pop_stmt_list (body);
10105   c_break_label = save_break;
10106   c_cont_label = save_cont;
10107 
10108   while (nbraces)
10109     {
10110       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
10111 	{
10112 	  c_parser_consume_token (parser);
10113 	  nbraces--;
10114 	}
10115       else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
10116 	c_parser_consume_token (parser);
10117       else
10118 	{
10119 	  c_parser_error (parser, "collapsed loops not perfectly nested");
10120 	  while (nbraces)
10121 	    {
10122 	      location_t here = c_parser_peek_token (parser)->location;
10123 	      stmt = c_begin_compound_stmt (true);
10124 	      add_stmt (body);
10125 	      c_parser_compound_statement_nostart (parser);
10126 	      body = c_end_compound_stmt (here, stmt, true);
10127 	      nbraces--;
10128 	    }
10129 	  goto pop_scopes;
10130 	}
10131     }
10132 
10133   /* Only bother calling c_finish_omp_for if we haven't already generated
10134      an error from the initialization parsing.  */
10135   if (!fail)
10136     {
10137       stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
10138       if (stmt)
10139 	{
10140 	  if (par_clauses != NULL)
10141 	    {
10142 	      tree *c;
10143 	      for (c = par_clauses; *c ; )
10144 		if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
10145 		    && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
10146 		  c = &OMP_CLAUSE_CHAIN (*c);
10147 		else
10148 		  {
10149 		    for (i = 0; i < collapse; i++)
10150 		      if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
10151 			break;
10152 		    if (i == collapse)
10153 		      c = &OMP_CLAUSE_CHAIN (*c);
10154 		    else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
10155 		      {
10156 			error_at (loc,
10157 				  "iteration variable %qD should not be firstprivate",
10158 				  OMP_CLAUSE_DECL (*c));
10159 			*c = OMP_CLAUSE_CHAIN (*c);
10160 		      }
10161 		    else
10162 		      {
10163 			/* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10164 			   change it to shared (decl) in
10165 			   OMP_PARALLEL_CLAUSES.  */
10166 			tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
10167 						   OMP_CLAUSE_LASTPRIVATE);
10168 			OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
10169 			OMP_CLAUSE_CHAIN (l) = clauses;
10170 			clauses = l;
10171 			OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
10172 		      }
10173 		  }
10174 	    }
10175 	  OMP_FOR_CLAUSES (stmt) = clauses;
10176 	}
10177       ret = stmt;
10178     }
10179 pop_scopes:
10180   while (!for_block->is_empty ())
10181     {
10182       /* FIXME diagnostics: LOC below should be the actual location of
10183 	 this particular for block.  We need to build a list of
10184 	 locations to go along with FOR_BLOCK.  */
10185       stmt = c_end_compound_stmt (loc, for_block->pop (), true);
10186       add_stmt (stmt);
10187     }
10188   release_tree_vector (for_block);
10189   return ret;
10190 }
10191 
10192 /* OpenMP 2.5:
10193    #pragma omp for for-clause[optseq] new-line
10194      for-loop
10195 
10196    LOC is the location of the #pragma token.
10197 */
10198 
10199 #define OMP_FOR_CLAUSE_MASK				\
10200 	( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
10201 	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
10202 	| (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE)		\
10203 	| (1u << PRAGMA_OMP_CLAUSE_REDUCTION)		\
10204 	| (1u << PRAGMA_OMP_CLAUSE_ORDERED)		\
10205 	| (1u << PRAGMA_OMP_CLAUSE_SCHEDULE)		\
10206 	| (1u << PRAGMA_OMP_CLAUSE_COLLAPSE)		\
10207 	| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10208 
10209 static tree
10210 c_parser_omp_for (location_t loc, c_parser *parser)
10211 {
10212   tree block, clauses, ret;
10213 
10214   clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
10215 				      "#pragma omp for");
10216 
10217   block = c_begin_compound_stmt (true);
10218   ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
10219   block = c_end_compound_stmt (loc, block, true);
10220   add_stmt (block);
10221 
10222   return ret;
10223 }
10224 
10225 /* OpenMP 2.5:
10226    # pragma omp master new-line
10227      structured-block
10228 
10229    LOC is the location of the #pragma token.
10230 */
10231 
10232 static tree
10233 c_parser_omp_master (location_t loc, c_parser *parser)
10234 {
10235   c_parser_skip_to_pragma_eol (parser);
10236   return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
10237 }
10238 
10239 /* OpenMP 2.5:
10240    # pragma omp ordered new-line
10241      structured-block
10242 
10243    LOC is the location of the #pragma itself.
10244 */
10245 
10246 static tree
10247 c_parser_omp_ordered (location_t loc, c_parser *parser)
10248 {
10249   c_parser_skip_to_pragma_eol (parser);
10250   return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
10251 }
10252 
10253 /* OpenMP 2.5:
10254 
10255    section-scope:
10256      { section-sequence }
10257 
10258    section-sequence:
10259      section-directive[opt] structured-block
10260      section-sequence section-directive structured-block
10261 
10262     SECTIONS_LOC is the location of the #pragma omp sections.  */
10263 
10264 static tree
10265 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
10266 {
10267   tree stmt, substmt;
10268   bool error_suppress = false;
10269   location_t loc;
10270 
10271   loc = c_parser_peek_token (parser)->location;
10272   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
10273     {
10274       /* Avoid skipping until the end of the block.  */
10275       parser->error = false;
10276       return NULL_TREE;
10277     }
10278 
10279   stmt = push_stmt_list ();
10280 
10281   if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
10282     {
10283       substmt = push_stmt_list ();
10284 
10285       while (1)
10286 	{
10287           c_parser_statement (parser);
10288 
10289 	  if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
10290 	    break;
10291 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
10292 	    break;
10293 	  if (c_parser_next_token_is (parser, CPP_EOF))
10294 	    break;
10295 	}
10296 
10297       substmt = pop_stmt_list (substmt);
10298       substmt = build1 (OMP_SECTION, void_type_node, substmt);
10299       SET_EXPR_LOCATION (substmt, loc);
10300       add_stmt (substmt);
10301     }
10302 
10303   while (1)
10304     {
10305       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
10306 	break;
10307       if (c_parser_next_token_is (parser, CPP_EOF))
10308 	break;
10309 
10310       loc = c_parser_peek_token (parser)->location;
10311       if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
10312 	{
10313 	  c_parser_consume_pragma (parser);
10314 	  c_parser_skip_to_pragma_eol (parser);
10315 	  error_suppress = false;
10316 	}
10317       else if (!error_suppress)
10318 	{
10319 	  error_at (loc, "expected %<#pragma omp section%> or %<}%>");
10320 	  error_suppress = true;
10321 	}
10322 
10323       substmt = c_parser_omp_structured_block (parser);
10324       substmt = build1 (OMP_SECTION, void_type_node, substmt);
10325       SET_EXPR_LOCATION (substmt, loc);
10326       add_stmt (substmt);
10327     }
10328   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
10329 			     "expected %<#pragma omp section%> or %<}%>");
10330 
10331   substmt = pop_stmt_list (stmt);
10332 
10333   stmt = make_node (OMP_SECTIONS);
10334   SET_EXPR_LOCATION (stmt, sections_loc);
10335   TREE_TYPE (stmt) = void_type_node;
10336   OMP_SECTIONS_BODY (stmt) = substmt;
10337 
10338   return add_stmt (stmt);
10339 }
10340 
10341 /* OpenMP 2.5:
10342    # pragma omp sections sections-clause[optseq] newline
10343      sections-scope
10344 
10345    LOC is the location of the #pragma token.
10346 */
10347 
10348 #define OMP_SECTIONS_CLAUSE_MASK			\
10349 	( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
10350 	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
10351 	| (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE)		\
10352 	| (1u << PRAGMA_OMP_CLAUSE_REDUCTION)		\
10353 	| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10354 
10355 static tree
10356 c_parser_omp_sections (location_t loc, c_parser *parser)
10357 {
10358   tree block, clauses, ret;
10359 
10360   clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
10361 				      "#pragma omp sections");
10362 
10363   block = c_begin_compound_stmt (true);
10364   ret = c_parser_omp_sections_scope (loc, parser);
10365   if (ret)
10366     OMP_SECTIONS_CLAUSES (ret) = clauses;
10367   block = c_end_compound_stmt (loc, block, true);
10368   add_stmt (block);
10369 
10370   return ret;
10371 }
10372 
10373 /* OpenMP 2.5:
10374    # pragma parallel parallel-clause new-line
10375    # pragma parallel for parallel-for-clause new-line
10376    # pragma parallel sections parallel-sections-clause new-line
10377 
10378    LOC is the location of the #pragma token.
10379 */
10380 
10381 #define OMP_PARALLEL_CLAUSE_MASK			\
10382 	( (1u << PRAGMA_OMP_CLAUSE_IF)			\
10383 	| (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
10384 	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
10385 	| (1u << PRAGMA_OMP_CLAUSE_DEFAULT)		\
10386 	| (1u << PRAGMA_OMP_CLAUSE_SHARED)		\
10387 	| (1u << PRAGMA_OMP_CLAUSE_COPYIN)		\
10388 	| (1u << PRAGMA_OMP_CLAUSE_REDUCTION)		\
10389 	| (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10390 
10391 static tree
10392 c_parser_omp_parallel (location_t loc, c_parser *parser)
10393 {
10394   enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
10395   const char *p_name = "#pragma omp parallel";
10396   tree stmt, clauses, par_clause, ws_clause, block;
10397   unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
10398 
10399   if (c_parser_next_token_is_keyword (parser, RID_FOR))
10400     {
10401       c_parser_consume_token (parser);
10402       p_kind = PRAGMA_OMP_PARALLEL_FOR;
10403       p_name = "#pragma omp parallel for";
10404       mask |= OMP_FOR_CLAUSE_MASK;
10405       mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
10406     }
10407   else if (c_parser_next_token_is (parser, CPP_NAME))
10408     {
10409       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10410       if (strcmp (p, "sections") == 0)
10411 	{
10412 	  c_parser_consume_token (parser);
10413 	  p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
10414 	  p_name = "#pragma omp parallel sections";
10415 	  mask |= OMP_SECTIONS_CLAUSE_MASK;
10416 	  mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
10417 	}
10418     }
10419 
10420   clauses = c_parser_omp_all_clauses (parser, mask, p_name);
10421 
10422   switch (p_kind)
10423     {
10424     case PRAGMA_OMP_PARALLEL:
10425       block = c_begin_omp_parallel ();
10426       c_parser_statement (parser);
10427       stmt = c_finish_omp_parallel (loc, clauses, block);
10428       break;
10429 
10430     case PRAGMA_OMP_PARALLEL_FOR:
10431       block = c_begin_omp_parallel ();
10432       c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
10433       c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
10434       stmt = c_finish_omp_parallel (loc, par_clause, block);
10435       OMP_PARALLEL_COMBINED (stmt) = 1;
10436       break;
10437 
10438     case PRAGMA_OMP_PARALLEL_SECTIONS:
10439       block = c_begin_omp_parallel ();
10440       c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
10441       stmt = c_parser_omp_sections_scope (loc, parser);
10442       if (stmt)
10443 	OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
10444       stmt = c_finish_omp_parallel (loc, par_clause, block);
10445       OMP_PARALLEL_COMBINED (stmt) = 1;
10446       break;
10447 
10448     default:
10449       gcc_unreachable ();
10450     }
10451 
10452   return stmt;
10453 }
10454 
10455 /* OpenMP 2.5:
10456    # pragma omp single single-clause[optseq] new-line
10457      structured-block
10458 
10459    LOC is the location of the #pragma.
10460 */
10461 
10462 #define OMP_SINGLE_CLAUSE_MASK				\
10463 	( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
10464 	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
10465 	| (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE)		\
10466 	| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10467 
10468 static tree
10469 c_parser_omp_single (location_t loc, c_parser *parser)
10470 {
10471   tree stmt = make_node (OMP_SINGLE);
10472   SET_EXPR_LOCATION (stmt, loc);
10473   TREE_TYPE (stmt) = void_type_node;
10474 
10475   OMP_SINGLE_CLAUSES (stmt)
10476     = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
10477 				"#pragma omp single");
10478   OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
10479 
10480   return add_stmt (stmt);
10481 }
10482 
10483 /* OpenMP 3.0:
10484    # pragma omp task task-clause[optseq] new-line
10485 
10486    LOC is the location of the #pragma.
10487 */
10488 
10489 #define OMP_TASK_CLAUSE_MASK				\
10490 	( (1u << PRAGMA_OMP_CLAUSE_IF)			\
10491 	| (1u << PRAGMA_OMP_CLAUSE_UNTIED)		\
10492 	| (1u << PRAGMA_OMP_CLAUSE_DEFAULT)		\
10493 	| (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
10494 	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
10495 	| (1u << PRAGMA_OMP_CLAUSE_SHARED)		\
10496 	| (1u << PRAGMA_OMP_CLAUSE_FINAL)		\
10497 	| (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10498 
10499 static tree
10500 c_parser_omp_task (location_t loc, c_parser *parser)
10501 {
10502   tree clauses, block;
10503 
10504   clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
10505 				      "#pragma omp task");
10506 
10507   block = c_begin_omp_task ();
10508   c_parser_statement (parser);
10509   return c_finish_omp_task (loc, clauses, block);
10510 }
10511 
10512 /* OpenMP 3.0:
10513    # pragma omp taskwait new-line
10514 */
10515 
10516 static void
10517 c_parser_omp_taskwait (c_parser *parser)
10518 {
10519   location_t loc = c_parser_peek_token (parser)->location;
10520   c_parser_consume_pragma (parser);
10521   c_parser_skip_to_pragma_eol (parser);
10522 
10523   c_finish_omp_taskwait (loc);
10524 }
10525 
10526 /* OpenMP 3.1:
10527    # pragma omp taskyield new-line
10528 */
10529 
10530 static void
10531 c_parser_omp_taskyield (c_parser *parser)
10532 {
10533   location_t loc = c_parser_peek_token (parser)->location;
10534   c_parser_consume_pragma (parser);
10535   c_parser_skip_to_pragma_eol (parser);
10536 
10537   c_finish_omp_taskyield (loc);
10538 }
10539 
10540 /* Main entry point to parsing most OpenMP pragmas.  */
10541 
10542 static void
10543 c_parser_omp_construct (c_parser *parser)
10544 {
10545   enum pragma_kind p_kind;
10546   location_t loc;
10547   tree stmt;
10548 
10549   loc = c_parser_peek_token (parser)->location;
10550   p_kind = c_parser_peek_token (parser)->pragma_kind;
10551   c_parser_consume_pragma (parser);
10552 
10553   switch (p_kind)
10554     {
10555     case PRAGMA_OMP_ATOMIC:
10556       c_parser_omp_atomic (loc, parser);
10557       return;
10558     case PRAGMA_OMP_CRITICAL:
10559       stmt = c_parser_omp_critical (loc, parser);
10560       break;
10561     case PRAGMA_OMP_FOR:
10562       stmt = c_parser_omp_for (loc, parser);
10563       break;
10564     case PRAGMA_OMP_MASTER:
10565       stmt = c_parser_omp_master (loc, parser);
10566       break;
10567     case PRAGMA_OMP_ORDERED:
10568       stmt = c_parser_omp_ordered (loc, parser);
10569       break;
10570     case PRAGMA_OMP_PARALLEL:
10571       stmt = c_parser_omp_parallel (loc, parser);
10572       break;
10573     case PRAGMA_OMP_SECTIONS:
10574       stmt = c_parser_omp_sections (loc, parser);
10575       break;
10576     case PRAGMA_OMP_SINGLE:
10577       stmt = c_parser_omp_single (loc, parser);
10578       break;
10579     case PRAGMA_OMP_TASK:
10580       stmt = c_parser_omp_task (loc, parser);
10581       break;
10582     default:
10583       gcc_unreachable ();
10584     }
10585 
10586   if (stmt)
10587     gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
10588 }
10589 
10590 
10591 /* OpenMP 2.5:
10592    # pragma omp threadprivate (variable-list) */
10593 
10594 static void
10595 c_parser_omp_threadprivate (c_parser *parser)
10596 {
10597   tree vars, t;
10598   location_t loc;
10599 
10600   c_parser_consume_pragma (parser);
10601   loc = c_parser_peek_token (parser)->location;
10602   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10603 
10604   /* Mark every variable in VARS to be assigned thread local storage.  */
10605   for (t = vars; t; t = TREE_CHAIN (t))
10606     {
10607       tree v = TREE_PURPOSE (t);
10608 
10609       /* FIXME diagnostics: Ideally we should keep individual
10610 	 locations for all the variables in the var list to make the
10611 	 following errors more precise.  Perhaps
10612 	 c_parser_omp_var_list_parens() should construct a list of
10613 	 locations to go along with the var list.  */
10614 
10615       /* If V had already been marked threadprivate, it doesn't matter
10616 	 whether it had been used prior to this point.  */
10617       if (TREE_CODE (v) != VAR_DECL)
10618 	error_at (loc, "%qD is not a variable", v);
10619       else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
10620 	error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10621       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10622 	error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10623       else if (TREE_TYPE (v) == error_mark_node)
10624 	;
10625       else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
10626 	error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10627       else
10628 	{
10629 	  if (! DECL_THREAD_LOCAL_P (v))
10630 	    {
10631 	      DECL_TLS_MODEL (v) = decl_default_tls_model (v);
10632 	      /* If rtl has been already set for this var, call
10633 		 make_decl_rtl once again, so that encode_section_info
10634 		 has a chance to look at the new decl flags.  */
10635 	      if (DECL_RTL_SET_P (v))
10636 		make_decl_rtl (v);
10637 	    }
10638 	  C_DECL_THREADPRIVATE_P (v) = 1;
10639 	}
10640     }
10641 
10642   c_parser_skip_to_pragma_eol (parser);
10643 }
10644 
10645 /* Parse a transaction attribute (GCC Extension).
10646 
10647    transaction-attribute:
10648      attributes
10649      [ [ any-word ] ]
10650 
10651    The transactional memory language description is written for C++,
10652    and uses the C++0x attribute syntax.  For compatibility, allow the
10653    bracket style for transactions in C as well.  */
10654 
10655 static tree
10656 c_parser_transaction_attributes (c_parser *parser)
10657 {
10658   tree attr_name, attr = NULL;
10659 
10660   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
10661     return c_parser_attributes (parser);
10662 
10663   if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
10664     return NULL_TREE;
10665   c_parser_consume_token (parser);
10666   if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
10667     goto error1;
10668 
10669   attr_name = c_parser_attribute_any_word (parser);
10670   if (attr_name)
10671     {
10672       c_parser_consume_token (parser);
10673       attr = build_tree_list (attr_name, NULL_TREE);
10674     }
10675   else
10676     c_parser_error (parser, "expected identifier");
10677 
10678   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
10679  error1:
10680   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
10681   return attr;
10682 }
10683 
10684 /* Parse a __transaction_atomic or __transaction_relaxed statement
10685    (GCC Extension).
10686 
10687    transaction-statement:
10688      __transaction_atomic transaction-attribute[opt] compound-statement
10689      __transaction_relaxed compound-statement
10690 
10691    Note that the only valid attribute is: "outer".
10692 */
10693 
10694 static tree
10695 c_parser_transaction (c_parser *parser, enum rid keyword)
10696 {
10697   unsigned int old_in = parser->in_transaction;
10698   unsigned int this_in = 1, new_in;
10699   location_t loc = c_parser_peek_token (parser)->location;
10700   tree stmt, attrs;
10701 
10702   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
10703       || keyword == RID_TRANSACTION_RELAXED)
10704       && c_parser_next_token_is_keyword (parser, keyword));
10705   c_parser_consume_token (parser);
10706 
10707   if (keyword == RID_TRANSACTION_RELAXED)
10708     this_in |= TM_STMT_ATTR_RELAXED;
10709   else
10710     {
10711       attrs = c_parser_transaction_attributes (parser);
10712       if (attrs)
10713 	this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
10714     }
10715 
10716   /* Keep track if we're in the lexical scope of an outer transaction.  */
10717   new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
10718 
10719   parser->in_transaction = new_in;
10720   stmt = c_parser_compound_statement (parser);
10721   parser->in_transaction = old_in;
10722 
10723   if (flag_tm)
10724     stmt = c_finish_transaction (loc, stmt, this_in);
10725   else
10726     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
10727 	"%<__transaction_atomic%> without transactional memory support enabled"
10728 	: "%<__transaction_relaxed %> "
10729 	"without transactional memory support enabled"));
10730 
10731   return stmt;
10732 }
10733 
10734 /* Parse a __transaction_atomic or __transaction_relaxed expression
10735    (GCC Extension).
10736 
10737    transaction-expression:
10738      __transaction_atomic ( expression )
10739      __transaction_relaxed ( expression )
10740 */
10741 
10742 static struct c_expr
10743 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
10744 {
10745   struct c_expr ret;
10746   unsigned int old_in = parser->in_transaction;
10747   unsigned int this_in = 1;
10748   location_t loc = c_parser_peek_token (parser)->location;
10749   tree attrs;
10750 
10751   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
10752       || keyword == RID_TRANSACTION_RELAXED)
10753       && c_parser_next_token_is_keyword (parser, keyword));
10754   c_parser_consume_token (parser);
10755 
10756   if (keyword == RID_TRANSACTION_RELAXED)
10757     this_in |= TM_STMT_ATTR_RELAXED;
10758   else
10759     {
10760       attrs = c_parser_transaction_attributes (parser);
10761       if (attrs)
10762 	this_in |= parse_tm_stmt_attr (attrs, 0);
10763     }
10764 
10765   parser->in_transaction = this_in;
10766   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10767     {
10768       tree expr = c_parser_expression (parser).value;
10769       ret.original_type = TREE_TYPE (expr);
10770       ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
10771       if (this_in & TM_STMT_ATTR_RELAXED)
10772 	TRANSACTION_EXPR_RELAXED (ret.value) = 1;
10773       SET_EXPR_LOCATION (ret.value, loc);
10774       ret.original_code = TRANSACTION_EXPR;
10775       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
10776 	{
10777 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
10778 	  goto error;
10779 	}
10780     }
10781   else
10782     {
10783      error:
10784       ret.value = error_mark_node;
10785       ret.original_code = ERROR_MARK;
10786       ret.original_type = NULL;
10787     }
10788   parser->in_transaction = old_in;
10789 
10790   if (!flag_tm)
10791     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
10792 	"%<__transaction_atomic%> without transactional memory support enabled"
10793 	: "%<__transaction_relaxed %> "
10794 	"without transactional memory support enabled"));
10795 
10796   return ret;
10797 }
10798 
10799 /* Parse a __transaction_cancel statement (GCC Extension).
10800 
10801    transaction-cancel-statement:
10802      __transaction_cancel transaction-attribute[opt] ;
10803 
10804    Note that the only valid attribute is "outer".
10805 */
10806 
10807 static tree
10808 c_parser_transaction_cancel(c_parser *parser)
10809 {
10810   location_t loc = c_parser_peek_token (parser)->location;
10811   tree attrs;
10812   bool is_outer = false;
10813 
10814   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
10815   c_parser_consume_token (parser);
10816 
10817   attrs = c_parser_transaction_attributes (parser);
10818   if (attrs)
10819     is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
10820 
10821   if (!flag_tm)
10822     {
10823       error_at (loc, "%<__transaction_cancel%> without "
10824 		"transactional memory support enabled");
10825       goto ret_error;
10826     }
10827   else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
10828     {
10829       error_at (loc, "%<__transaction_cancel%> within a "
10830 		"%<__transaction_relaxed%>");
10831       goto ret_error;
10832     }
10833   else if (is_outer)
10834     {
10835       if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
10836 	  && !is_tm_may_cancel_outer (current_function_decl))
10837 	{
10838 	  error_at (loc, "outer %<__transaction_cancel%> not "
10839 		    "within outer %<__transaction_atomic%>");
10840 	  error_at (loc, "  or a %<transaction_may_cancel_outer%> function");
10841 	  goto ret_error;
10842 	}
10843     }
10844   else if (parser->in_transaction == 0)
10845     {
10846       error_at (loc, "%<__transaction_cancel%> not within "
10847 		"%<__transaction_atomic%>");
10848       goto ret_error;
10849     }
10850 
10851   return add_stmt (build_tm_abort_call (loc, is_outer));
10852 
10853  ret_error:
10854   return build1 (NOP_EXPR, void_type_node, error_mark_node);
10855 }
10856 
10857 /* Parse a single source file.  */
10858 
10859 void
10860 c_parse_file (void)
10861 {
10862   /* Use local storage to begin.  If the first token is a pragma, parse it.
10863      If it is #pragma GCC pch_preprocess, then this will load a PCH file
10864      which will cause garbage collection.  */
10865   c_parser tparser;
10866 
10867   memset (&tparser, 0, sizeof tparser);
10868   the_parser = &tparser;
10869 
10870   if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
10871     c_parser_pragma_pch_preprocess (&tparser);
10872 
10873   the_parser = ggc_alloc_c_parser ();
10874   *the_parser = tparser;
10875 
10876   /* Initialize EH, if we've been told to do so.  */
10877   if (flag_exceptions)
10878     using_eh_for_cleanups ();
10879 
10880   c_parser_translation_unit (the_parser);
10881   the_parser = NULL;
10882 }
10883 
10884 #include "gt-c-c-parser.h"
10885