xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/c/c-parser.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* Parser for C and Objective-C.
2    Copyright (C) 1987-2015 Free Software Foundation, Inc.
3 
4    Parser actions based on the old Bison parser; structure somewhat
5    influenced by and fragments based on the C++ parser.
6 
7 This file is part of GCC.
8 
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13 
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22 
23 /* TODO:
24 
25    Make sure all relevant comments, and all relevant code from all
26    actions, brought over from old parser.  Verify exact correspondence
27    of syntax accepted.
28 
29    Add testcases covering every input symbol in every state in old and
30    new parsers.
31 
32    Include full syntax for GNU C, including erroneous cases accepted
33    with error messages, in syntax productions in comments.
34 
35    Make more diagnostics in the front end generally take an explicit
36    location rather than implicitly using input_location.  */
37 
38 #include "config.h"
39 #include "system.h"
40 #include "coretypes.h"
41 #include "tm.h"			/* For rtl.h: needs enum reg_class.  */
42 #include "hash-set.h"
43 #include "vec.h"
44 #include "symtab.h"
45 #include "input.h"
46 #include "alias.h"
47 #include "double-int.h"
48 #include "machmode.h"
49 #include "flags.h"
50 #include "inchash.h"
51 #include "tree.h"
52 #include "fold-const.h"
53 #include "stringpool.h"
54 #include "attribs.h"
55 #include "stor-layout.h"
56 #include "varasm.h"
57 #include "trans-mem.h"
58 #include "langhooks.h"
59 #include "input.h"
60 #include "cpplib.h"
61 #include "timevar.h"
62 #include "c-family/c-pragma.h"
63 #include "c-tree.h"
64 #include "c-lang.h"
65 #include "flags.h"
66 #include "ggc.h"
67 #include "c-family/c-common.h"
68 #include "c-family/c-objc.h"
69 #include "vec.h"
70 #include "target.h"
71 #include "hash-map.h"
72 #include "is-a.h"
73 #include "plugin-api.h"
74 #include "hashtab.h"
75 #include "hash-set.h"
76 #include "machmode.h"
77 #include "hard-reg-set.h"
78 #include "function.h"
79 #include "ipa-ref.h"
80 #include "cgraph.h"
81 #include "plugin.h"
82 #include "omp-low.h"
83 #include "builtins.h"
84 #include "gomp-constants.h"
85 
86 
87 /* Initialization routine for this file.  */
88 
89 void
90 c_parse_init (void)
91 {
92   /* The only initialization required is of the reserved word
93      identifiers.  */
94   unsigned int i;
95   tree id;
96   int mask = 0;
97 
98   /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
99      the c_token structure.  */
100   gcc_assert (RID_MAX <= 255);
101 
102   mask |= D_CXXONLY;
103   if (!flag_isoc99)
104     mask |= D_C99;
105   if (flag_no_asm)
106     {
107       mask |= D_ASM | D_EXT;
108       if (!flag_isoc99)
109 	mask |= D_EXT89;
110     }
111   if (!c_dialect_objc ())
112     mask |= D_OBJC | D_CXX_OBJC;
113 
114   ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
115   for (i = 0; i < num_c_common_reswords; i++)
116     {
117       /* If a keyword is disabled, do not enter it into the table
118 	 and so create a canonical spelling that isn't a keyword.  */
119       if (c_common_reswords[i].disable & mask)
120 	{
121 	  if (warn_cxx_compat
122 	      && (c_common_reswords[i].disable & D_CXXWARN))
123 	    {
124 	      id = get_identifier (c_common_reswords[i].word);
125 	      C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
126 	      C_IS_RESERVED_WORD (id) = 1;
127 	    }
128 	  continue;
129 	}
130 
131       id = get_identifier (c_common_reswords[i].word);
132       C_SET_RID_CODE (id, c_common_reswords[i].rid);
133       C_IS_RESERVED_WORD (id) = 1;
134       ridpointers [(int) c_common_reswords[i].rid] = id;
135     }
136 
137   for (i = 0; i < NUM_INT_N_ENTS; i++)
138     {
139       /* We always create the symbols but they aren't always supported.  */
140       char name[50];
141       sprintf (name, "__int%d", int_n_data[i].bitsize);
142       id = get_identifier (name);
143       C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
144       C_IS_RESERVED_WORD (id) = 1;
145     }
146 }
147 
148 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
149    and the C parser.  Unlike the C++ lexer, the parser structure
150    stores the lexer information instead of using a separate structure.
151    Identifiers are separated into ordinary identifiers, type names,
152    keywords and some other Objective-C types of identifiers, and some
153    look-ahead is maintained.
154 
155    ??? It might be a good idea to lex the whole file up front (as for
156    C++).  It would then be possible to share more of the C and C++
157    lexer code, if desired.  */
158 
159 /* More information about the type of a CPP_NAME token.  */
160 typedef enum c_id_kind {
161   /* An ordinary identifier.  */
162   C_ID_ID,
163   /* An identifier declared as a typedef name.  */
164   C_ID_TYPENAME,
165   /* An identifier declared as an Objective-C class name.  */
166   C_ID_CLASSNAME,
167   /* An address space identifier.  */
168   C_ID_ADDRSPACE,
169   /* Not an identifier.  */
170   C_ID_NONE
171 } c_id_kind;
172 
173 /* A single C token after string literal concatenation and conversion
174    of preprocessing tokens to tokens.  */
175 typedef struct GTY (()) c_token {
176   /* The kind of token.  */
177   ENUM_BITFIELD (cpp_ttype) type : 8;
178   /* If this token is a CPP_NAME, this value indicates whether also
179      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
180   ENUM_BITFIELD (c_id_kind) id_kind : 8;
181   /* If this token is a keyword, this value indicates which keyword.
182      Otherwise, this value is RID_MAX.  */
183   ENUM_BITFIELD (rid) keyword : 8;
184   /* If this token is a CPP_PRAGMA, this indicates the pragma that
185      was seen.  Otherwise it is PRAGMA_NONE.  */
186   ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
187   /* The location at which this token was found.  */
188   location_t location;
189   /* The value associated with this token, if any.  */
190   tree value;
191 } c_token;
192 
193 /* A parser structure recording information about the state and
194    context of parsing.  Includes lexer information with up to two
195    tokens of look-ahead; more are not needed for C.  */
196 typedef struct GTY(()) c_parser {
197   /* The look-ahead tokens.  */
198   c_token * GTY((skip)) tokens;
199   /* Buffer for look-ahead tokens.  */
200   c_token tokens_buf[2];
201   /* How many look-ahead tokens are available (0, 1 or 2, or
202      more if parsing from pre-lexed tokens).  */
203   unsigned int tokens_avail;
204   /* True if a syntax error is being recovered from; false otherwise.
205      c_parser_error sets this flag.  It should clear this flag when
206      enough tokens have been consumed to recover from the error.  */
207   BOOL_BITFIELD error : 1;
208   /* True if we're processing a pragma, and shouldn't automatically
209      consume CPP_PRAGMA_EOL.  */
210   BOOL_BITFIELD in_pragma : 1;
211   /* True if we're parsing the outermost block of an if statement.  */
212   BOOL_BITFIELD in_if_block : 1;
213   /* True if we want to lex an untranslated string.  */
214   BOOL_BITFIELD lex_untranslated_string : 1;
215 
216   /* Objective-C specific parser/lexer information.  */
217 
218   /* True if we are in a context where the Objective-C "PQ" keywords
219      are considered keywords.  */
220   BOOL_BITFIELD objc_pq_context : 1;
221   /* True if we are parsing a (potential) Objective-C foreach
222      statement.  This is set to true after we parsed 'for (' and while
223      we wait for 'in' or ';' to decide if it's a standard C for loop or an
224      Objective-C foreach loop.  */
225   BOOL_BITFIELD objc_could_be_foreach_context : 1;
226   /* The following flag is needed to contextualize Objective-C lexical
227      analysis.  In some cases (e.g., 'int NSObject;'), it is
228      undesirable to bind an identifier to an Objective-C class, even
229      if a class with that name exists.  */
230   BOOL_BITFIELD objc_need_raw_identifier : 1;
231   /* Nonzero if we're processing a __transaction statement.  The value
232      is 1 | TM_STMT_ATTR_*.  */
233   unsigned int in_transaction : 4;
234   /* True if we are in a context where the Objective-C "Property attribute"
235      keywords are valid.  */
236   BOOL_BITFIELD objc_property_attr_context : 1;
237 
238   /* Cilk Plus specific parser/lexer information.  */
239 
240   /* Buffer to hold all the tokens from parsing the vector attribute for the
241      SIMD-enabled functions (formerly known as elemental functions).  */
242   vec <c_token, va_gc> *cilk_simd_fn_tokens;
243 } c_parser;
244 
245 
246 /* The actual parser and external interface.  ??? Does this need to be
247    garbage-collected?  */
248 
249 static GTY (()) c_parser *the_parser;
250 
251 /* Read in and lex a single token, storing it in *TOKEN.  */
252 
253 static void
254 c_lex_one_token (c_parser *parser, c_token *token)
255 {
256   timevar_push (TV_LEX);
257 
258   token->type = c_lex_with_flags (&token->value, &token->location, NULL,
259 				  (parser->lex_untranslated_string
260 				   ? C_LEX_STRING_NO_TRANSLATE : 0));
261   token->id_kind = C_ID_NONE;
262   token->keyword = RID_MAX;
263   token->pragma_kind = PRAGMA_NONE;
264 
265   switch (token->type)
266     {
267     case CPP_NAME:
268       {
269 	tree decl;
270 
271 	bool objc_force_identifier = parser->objc_need_raw_identifier;
272 	if (c_dialect_objc ())
273 	  parser->objc_need_raw_identifier = false;
274 
275 	if (C_IS_RESERVED_WORD (token->value))
276 	  {
277 	    enum rid rid_code = C_RID_CODE (token->value);
278 
279 	    if (rid_code == RID_CXX_COMPAT_WARN)
280 	      {
281 		warning_at (token->location,
282 			    OPT_Wc___compat,
283 			    "identifier %qE conflicts with C++ keyword",
284 			    token->value);
285 	      }
286 	    else if (rid_code >= RID_FIRST_ADDR_SPACE
287 		     && rid_code <= RID_LAST_ADDR_SPACE)
288 	      {
289 		token->id_kind = C_ID_ADDRSPACE;
290 		token->keyword = rid_code;
291 		break;
292 	      }
293 	    else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
294 	      {
295 		/* We found an Objective-C "pq" keyword (in, out,
296 		   inout, bycopy, byref, oneway).  They need special
297 		   care because the interpretation depends on the
298 		   context.  */
299 		if (parser->objc_pq_context)
300 		  {
301 		    token->type = CPP_KEYWORD;
302 		    token->keyword = rid_code;
303 		    break;
304 		  }
305 		else if (parser->objc_could_be_foreach_context
306 			 && rid_code == RID_IN)
307 		  {
308 		    /* We are in Objective-C, inside a (potential)
309 		       foreach context (which means after having
310 		       parsed 'for (', but before having parsed ';'),
311 		       and we found 'in'.  We consider it the keyword
312 		       which terminates the declaration at the
313 		       beginning of a foreach-statement.  Note that
314 		       this means you can't use 'in' for anything else
315 		       in that context; in particular, in Objective-C
316 		       you can't use 'in' as the name of the running
317 		       variable in a C for loop.  We could potentially
318 		       try to add code here to disambiguate, but it
319 		       seems a reasonable limitation.  */
320 		    token->type = CPP_KEYWORD;
321 		    token->keyword = rid_code;
322 		    break;
323 		  }
324 		/* Else, "pq" keywords outside of the "pq" context are
325 		   not keywords, and we fall through to the code for
326 		   normal tokens.  */
327 	      }
328 	    else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
329 	      {
330 		/* We found an Objective-C "property attribute"
331 		   keyword (getter, setter, readonly, etc). These are
332 		   only valid in the property context.  */
333 		if (parser->objc_property_attr_context)
334 		  {
335 		    token->type = CPP_KEYWORD;
336 		    token->keyword = rid_code;
337 		    break;
338 		  }
339 		/* Else they are not special keywords.
340 		*/
341 	      }
342 	    else if (c_dialect_objc ()
343 		     && (OBJC_IS_AT_KEYWORD (rid_code)
344 			 || OBJC_IS_CXX_KEYWORD (rid_code)))
345 	      {
346 		/* We found one of the Objective-C "@" keywords (defs,
347 		   selector, synchronized, etc) or one of the
348 		   Objective-C "cxx" keywords (class, private,
349 		   protected, public, try, catch, throw) without a
350 		   preceding '@' sign.  Do nothing and fall through to
351 		   the code for normal tokens (in C++ we would still
352 		   consider the CXX ones keywords, but not in C).  */
353 		;
354 	      }
355 	    else
356 	      {
357 		token->type = CPP_KEYWORD;
358 		token->keyword = rid_code;
359 		break;
360 	      }
361 	  }
362 
363 	decl = lookup_name (token->value);
364 	if (decl)
365 	  {
366 	    if (TREE_CODE (decl) == TYPE_DECL)
367 	      {
368 		token->id_kind = C_ID_TYPENAME;
369 		break;
370 	      }
371 	  }
372 	else if (c_dialect_objc ())
373 	  {
374 	    tree objc_interface_decl = objc_is_class_name (token->value);
375 	    /* Objective-C class names are in the same namespace as
376 	       variables and typedefs, and hence are shadowed by local
377 	       declarations.  */
378 	    if (objc_interface_decl
379                 && (!objc_force_identifier || global_bindings_p ()))
380 	      {
381 		token->value = objc_interface_decl;
382 		token->id_kind = C_ID_CLASSNAME;
383 		break;
384 	      }
385 	  }
386         token->id_kind = C_ID_ID;
387       }
388       break;
389     case CPP_AT_NAME:
390       /* This only happens in Objective-C; it must be a keyword.  */
391       token->type = CPP_KEYWORD;
392       switch (C_RID_CODE (token->value))
393 	{
394 	  /* Replace 'class' with '@class', 'private' with '@private',
395 	     etc.  This prevents confusion with the C++ keyword
396 	     'class', and makes the tokens consistent with other
397 	     Objective-C 'AT' keywords.  For example '@class' is
398 	     reported as RID_AT_CLASS which is consistent with
399 	     '@synchronized', which is reported as
400 	     RID_AT_SYNCHRONIZED.
401 	  */
402 	case RID_CLASS:     token->keyword = RID_AT_CLASS; break;
403 	case RID_PRIVATE:   token->keyword = RID_AT_PRIVATE; break;
404 	case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
405 	case RID_PUBLIC:    token->keyword = RID_AT_PUBLIC; break;
406 	case RID_THROW:     token->keyword = RID_AT_THROW; break;
407 	case RID_TRY:       token->keyword = RID_AT_TRY; break;
408 	case RID_CATCH:     token->keyword = RID_AT_CATCH; break;
409 	default:            token->keyword = C_RID_CODE (token->value);
410 	}
411       break;
412     case CPP_COLON:
413     case CPP_COMMA:
414     case CPP_CLOSE_PAREN:
415     case CPP_SEMICOLON:
416       /* These tokens may affect the interpretation of any identifiers
417 	 following, if doing Objective-C.  */
418       if (c_dialect_objc ())
419 	parser->objc_need_raw_identifier = false;
420       break;
421     case CPP_PRAGMA:
422       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
423       token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
424       token->value = NULL;
425       break;
426     default:
427       break;
428     }
429   timevar_pop (TV_LEX);
430 }
431 
432 /* Return a pointer to the next token from PARSER, reading it in if
433    necessary.  */
434 
435 static inline c_token *
436 c_parser_peek_token (c_parser *parser)
437 {
438   if (parser->tokens_avail == 0)
439     {
440       c_lex_one_token (parser, &parser->tokens[0]);
441       parser->tokens_avail = 1;
442     }
443   return &parser->tokens[0];
444 }
445 
446 /* Return true if the next token from PARSER has the indicated
447    TYPE.  */
448 
449 static inline bool
450 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
451 {
452   return c_parser_peek_token (parser)->type == type;
453 }
454 
455 /* Return true if the next token from PARSER does not have the
456    indicated TYPE.  */
457 
458 static inline bool
459 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
460 {
461   return !c_parser_next_token_is (parser, type);
462 }
463 
464 /* Return true if the next token from PARSER is the indicated
465    KEYWORD.  */
466 
467 static inline bool
468 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
469 {
470   return c_parser_peek_token (parser)->keyword == keyword;
471 }
472 
473 /* Return a pointer to the next-but-one token from PARSER, reading it
474    in if necessary.  The next token is already read in.  */
475 
476 static c_token *
477 c_parser_peek_2nd_token (c_parser *parser)
478 {
479   if (parser->tokens_avail >= 2)
480     return &parser->tokens[1];
481   gcc_assert (parser->tokens_avail == 1);
482   gcc_assert (parser->tokens[0].type != CPP_EOF);
483   gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
484   c_lex_one_token (parser, &parser->tokens[1]);
485   parser->tokens_avail = 2;
486   return &parser->tokens[1];
487 }
488 
489 /* Return true if TOKEN can start a type name,
490    false otherwise.  */
491 static bool
492 c_token_starts_typename (c_token *token)
493 {
494   switch (token->type)
495     {
496     case CPP_NAME:
497       switch (token->id_kind)
498 	{
499 	case C_ID_ID:
500 	  return false;
501 	case C_ID_ADDRSPACE:
502 	  return true;
503 	case C_ID_TYPENAME:
504 	  return true;
505 	case C_ID_CLASSNAME:
506 	  gcc_assert (c_dialect_objc ());
507 	  return true;
508 	default:
509 	  gcc_unreachable ();
510 	}
511     case CPP_KEYWORD:
512       switch (token->keyword)
513 	{
514 	case RID_UNSIGNED:
515 	case RID_LONG:
516 	case RID_SHORT:
517 	case RID_SIGNED:
518 	case RID_COMPLEX:
519 	case RID_INT:
520 	case RID_CHAR:
521 	case RID_FLOAT:
522 	case RID_DOUBLE:
523 	case RID_VOID:
524 	case RID_DFLOAT32:
525 	case RID_DFLOAT64:
526 	case RID_DFLOAT128:
527 	case RID_BOOL:
528 	case RID_ENUM:
529 	case RID_STRUCT:
530 	case RID_UNION:
531 	case RID_TYPEOF:
532 	case RID_CONST:
533 	case RID_ATOMIC:
534 	case RID_VOLATILE:
535 	case RID_RESTRICT:
536 	case RID_ATTRIBUTE:
537 	case RID_FRACT:
538 	case RID_ACCUM:
539 	case RID_SAT:
540 	case RID_AUTO_TYPE:
541 	  return true;
542 	default:
543 	  if (token->keyword >= RID_FIRST_INT_N
544 	      && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
545 	      && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
546 	    return true;
547 	  return false;
548 	}
549     case CPP_LESS:
550       if (c_dialect_objc ())
551 	return true;
552       return false;
553     default:
554       return false;
555     }
556 }
557 
558 enum c_lookahead_kind {
559   /* Always treat unknown identifiers as typenames.  */
560   cla_prefer_type,
561 
562   /* Could be parsing a nonabstract declarator.  Only treat an identifier
563      as a typename if followed by another identifier or a star.  */
564   cla_nonabstract_decl,
565 
566   /* Never treat identifiers as typenames.  */
567   cla_prefer_id
568 };
569 
570 /* Return true if the next token from PARSER can start a type name,
571    false otherwise.  LA specifies how to do lookahead in order to
572    detect unknown type names.  If unsure, pick CLA_PREFER_ID.  */
573 
574 static inline bool
575 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
576 {
577   c_token *token = c_parser_peek_token (parser);
578   if (c_token_starts_typename (token))
579     return true;
580 
581   /* Try a bit harder to detect an unknown typename.  */
582   if (la != cla_prefer_id
583       && token->type == CPP_NAME
584       && token->id_kind == C_ID_ID
585 
586       /* Do not try too hard when we could have "object in array".  */
587       && !parser->objc_could_be_foreach_context
588 
589       && (la == cla_prefer_type
590 	  || c_parser_peek_2nd_token (parser)->type == CPP_NAME
591 	  || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
592 
593       /* Only unknown identifiers.  */
594       && !lookup_name (token->value))
595     return true;
596 
597   return false;
598 }
599 
600 /* Return true if TOKEN is a type qualifier, false otherwise.  */
601 static bool
602 c_token_is_qualifier (c_token *token)
603 {
604   switch (token->type)
605     {
606     case CPP_NAME:
607       switch (token->id_kind)
608 	{
609 	case C_ID_ADDRSPACE:
610 	  return true;
611 	default:
612 	  return false;
613 	}
614     case CPP_KEYWORD:
615       switch (token->keyword)
616 	{
617 	case RID_CONST:
618 	case RID_VOLATILE:
619 	case RID_RESTRICT:
620 	case RID_ATTRIBUTE:
621 	case RID_ATOMIC:
622 	  return true;
623 	default:
624 	  return false;
625 	}
626     case CPP_LESS:
627       return false;
628     default:
629       gcc_unreachable ();
630     }
631 }
632 
633 /* Return true if the next token from PARSER is a type qualifier,
634    false otherwise.  */
635 static inline bool
636 c_parser_next_token_is_qualifier (c_parser *parser)
637 {
638   c_token *token = c_parser_peek_token (parser);
639   return c_token_is_qualifier (token);
640 }
641 
642 /* Return true if TOKEN can start declaration specifiers, false
643    otherwise.  */
644 static bool
645 c_token_starts_declspecs (c_token *token)
646 {
647   switch (token->type)
648     {
649     case CPP_NAME:
650       switch (token->id_kind)
651 	{
652 	case C_ID_ID:
653 	  return false;
654 	case C_ID_ADDRSPACE:
655 	  return true;
656 	case C_ID_TYPENAME:
657 	  return true;
658 	case C_ID_CLASSNAME:
659 	  gcc_assert (c_dialect_objc ());
660 	  return true;
661 	default:
662 	  gcc_unreachable ();
663 	}
664     case CPP_KEYWORD:
665       switch (token->keyword)
666 	{
667 	case RID_STATIC:
668 	case RID_EXTERN:
669 	case RID_REGISTER:
670 	case RID_TYPEDEF:
671 	case RID_INLINE:
672 	case RID_NORETURN:
673 	case RID_AUTO:
674 	case RID_THREAD:
675 	case RID_UNSIGNED:
676 	case RID_LONG:
677 	case RID_SHORT:
678 	case RID_SIGNED:
679 	case RID_COMPLEX:
680 	case RID_INT:
681 	case RID_CHAR:
682 	case RID_FLOAT:
683 	case RID_DOUBLE:
684 	case RID_VOID:
685 	case RID_DFLOAT32:
686 	case RID_DFLOAT64:
687 	case RID_DFLOAT128:
688 	case RID_BOOL:
689 	case RID_ENUM:
690 	case RID_STRUCT:
691 	case RID_UNION:
692 	case RID_TYPEOF:
693 	case RID_CONST:
694 	case RID_VOLATILE:
695 	case RID_RESTRICT:
696 	case RID_ATTRIBUTE:
697 	case RID_FRACT:
698 	case RID_ACCUM:
699 	case RID_SAT:
700 	case RID_ALIGNAS:
701 	case RID_ATOMIC:
702 	case RID_AUTO_TYPE:
703 	  return true;
704 	default:
705 	  if (token->keyword >= RID_FIRST_INT_N
706 	      && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
707 	      && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
708 	    return true;
709 	  return false;
710 	}
711     case CPP_LESS:
712       if (c_dialect_objc ())
713 	return true;
714       return false;
715     default:
716       return false;
717     }
718 }
719 
720 
721 /* Return true if TOKEN can start declaration specifiers or a static
722    assertion, false otherwise.  */
723 static bool
724 c_token_starts_declaration (c_token *token)
725 {
726   if (c_token_starts_declspecs (token)
727       || token->keyword == RID_STATIC_ASSERT)
728     return true;
729   else
730     return false;
731 }
732 
733 /* Return true if the next token from PARSER can start declaration
734    specifiers, false otherwise.  */
735 static inline bool
736 c_parser_next_token_starts_declspecs (c_parser *parser)
737 {
738   c_token *token = c_parser_peek_token (parser);
739 
740   /* In Objective-C, a classname normally starts a declspecs unless it
741      is immediately followed by a dot.  In that case, it is the
742      Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
743      setter/getter on the class.  c_token_starts_declspecs() can't
744      differentiate between the two cases because it only checks the
745      current token, so we have a special check here.  */
746   if (c_dialect_objc ()
747       && token->type == CPP_NAME
748       && token->id_kind == C_ID_CLASSNAME
749       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
750     return false;
751 
752   return c_token_starts_declspecs (token);
753 }
754 
755 /* Return true if the next tokens from PARSER can start declaration
756    specifiers or a static assertion, false otherwise.  */
757 static inline bool
758 c_parser_next_tokens_start_declaration (c_parser *parser)
759 {
760   c_token *token = c_parser_peek_token (parser);
761 
762   /* Same as above.  */
763   if (c_dialect_objc ()
764       && token->type == CPP_NAME
765       && token->id_kind == C_ID_CLASSNAME
766       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
767     return false;
768 
769   /* Labels do not start declarations.  */
770   if (token->type == CPP_NAME
771       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
772     return false;
773 
774   if (c_token_starts_declaration (token))
775     return true;
776 
777   if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
778     return true;
779 
780   return false;
781 }
782 
783 /* Consume the next token from PARSER.  */
784 
785 static void
786 c_parser_consume_token (c_parser *parser)
787 {
788   gcc_assert (parser->tokens_avail >= 1);
789   gcc_assert (parser->tokens[0].type != CPP_EOF);
790   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
791   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
792   if (parser->tokens != &parser->tokens_buf[0])
793     parser->tokens++;
794   else if (parser->tokens_avail == 2)
795     parser->tokens[0] = parser->tokens[1];
796   parser->tokens_avail--;
797 }
798 
799 /* Expect the current token to be a #pragma.  Consume it and remember
800    that we've begun parsing a pragma.  */
801 
802 static void
803 c_parser_consume_pragma (c_parser *parser)
804 {
805   gcc_assert (!parser->in_pragma);
806   gcc_assert (parser->tokens_avail >= 1);
807   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
808   if (parser->tokens != &parser->tokens_buf[0])
809     parser->tokens++;
810   else if (parser->tokens_avail == 2)
811     parser->tokens[0] = parser->tokens[1];
812   parser->tokens_avail--;
813   parser->in_pragma = true;
814 }
815 
816 /* Update the global input_location from TOKEN.  */
817 static inline void
818 c_parser_set_source_position_from_token (c_token *token)
819 {
820   if (token->type != CPP_EOF)
821     {
822       input_location = token->location;
823     }
824 }
825 
826 /* Issue a diagnostic of the form
827       FILE:LINE: MESSAGE before TOKEN
828    where TOKEN is the next token in the input stream of PARSER.
829    MESSAGE (specified by the caller) is usually of the form "expected
830    OTHER-TOKEN".
831 
832    Do not issue a diagnostic if still recovering from an error.
833 
834    ??? This is taken from the C++ parser, but building up messages in
835    this way is not i18n-friendly and some other approach should be
836    used.  */
837 
838 static void
839 c_parser_error (c_parser *parser, const char *gmsgid)
840 {
841   c_token *token = c_parser_peek_token (parser);
842   if (parser->error)
843     return;
844   parser->error = true;
845   if (!gmsgid)
846     return;
847   /* This diagnostic makes more sense if it is tagged to the line of
848      the token we just peeked at.  */
849   c_parser_set_source_position_from_token (token);
850   c_parse_error (gmsgid,
851 		 /* Because c_parse_error does not understand
852 		    CPP_KEYWORD, keywords are treated like
853 		    identifiers.  */
854 		 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
855 		 /* ??? The C parser does not save the cpp flags of a
856 		    token, we need to pass 0 here and we will not get
857 		    the source spelling of some tokens but rather the
858 		    canonical spelling.  */
859 		 token->value, /*flags=*/0);
860 }
861 
862 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
863    issue the error MSGID.  If MSGID is NULL then a message has already
864    been produced and no message will be produced this time.  Returns
865    true if found, false otherwise.  */
866 
867 static bool
868 c_parser_require (c_parser *parser,
869 		  enum cpp_ttype type,
870 		  const char *msgid)
871 {
872   if (c_parser_next_token_is (parser, type))
873     {
874       c_parser_consume_token (parser);
875       return true;
876     }
877   else
878     {
879       c_parser_error (parser, msgid);
880       return false;
881     }
882 }
883 
884 /* If the next token is the indicated keyword, consume it.  Otherwise,
885    issue the error MSGID.  Returns true if found, false otherwise.  */
886 
887 static bool
888 c_parser_require_keyword (c_parser *parser,
889 			  enum rid keyword,
890 			  const char *msgid)
891 {
892   if (c_parser_next_token_is_keyword (parser, keyword))
893     {
894       c_parser_consume_token (parser);
895       return true;
896     }
897   else
898     {
899       c_parser_error (parser, msgid);
900       return false;
901     }
902 }
903 
904 /* Like c_parser_require, except that tokens will be skipped until the
905    desired token is found.  An error message is still produced if the
906    next token is not as expected.  If MSGID is NULL then a message has
907    already been produced and no message will be produced this
908    time.  */
909 
910 static void
911 c_parser_skip_until_found (c_parser *parser,
912 			   enum cpp_ttype type,
913 			   const char *msgid)
914 {
915   unsigned nesting_depth = 0;
916 
917   if (c_parser_require (parser, type, msgid))
918     return;
919 
920   /* Skip tokens until the desired token is found.  */
921   while (true)
922     {
923       /* Peek at the next token.  */
924       c_token *token = c_parser_peek_token (parser);
925       /* If we've reached the token we want, consume it and stop.  */
926       if (token->type == type && !nesting_depth)
927 	{
928 	  c_parser_consume_token (parser);
929 	  break;
930 	}
931 
932       /* If we've run out of tokens, stop.  */
933       if (token->type == CPP_EOF)
934 	return;
935       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
936 	return;
937       if (token->type == CPP_OPEN_BRACE
938 	  || token->type == CPP_OPEN_PAREN
939 	  || token->type == CPP_OPEN_SQUARE)
940 	++nesting_depth;
941       else if (token->type == CPP_CLOSE_BRACE
942 	       || token->type == CPP_CLOSE_PAREN
943 	       || token->type == CPP_CLOSE_SQUARE)
944 	{
945 	  if (nesting_depth-- == 0)
946 	    break;
947 	}
948       /* Consume this token.  */
949       c_parser_consume_token (parser);
950     }
951   parser->error = false;
952 }
953 
954 /* Skip tokens until the end of a parameter is found, but do not
955    consume the comma, semicolon or closing delimiter.  */
956 
957 static void
958 c_parser_skip_to_end_of_parameter (c_parser *parser)
959 {
960   unsigned nesting_depth = 0;
961 
962   while (true)
963     {
964       c_token *token = c_parser_peek_token (parser);
965       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
966 	  && !nesting_depth)
967 	break;
968       /* If we've run out of tokens, stop.  */
969       if (token->type == CPP_EOF)
970 	return;
971       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
972 	return;
973       if (token->type == CPP_OPEN_BRACE
974 	  || token->type == CPP_OPEN_PAREN
975 	  || token->type == CPP_OPEN_SQUARE)
976 	++nesting_depth;
977       else if (token->type == CPP_CLOSE_BRACE
978 	       || token->type == CPP_CLOSE_PAREN
979 	       || token->type == CPP_CLOSE_SQUARE)
980 	{
981 	  if (nesting_depth-- == 0)
982 	    break;
983 	}
984       /* Consume this token.  */
985       c_parser_consume_token (parser);
986     }
987   parser->error = false;
988 }
989 
990 /* Expect to be at the end of the pragma directive and consume an
991    end of line marker.  */
992 
993 static void
994 c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
995 {
996   gcc_assert (parser->in_pragma);
997   parser->in_pragma = false;
998 
999   if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
1000     c_parser_error (parser, "expected end of line");
1001 
1002   cpp_ttype token_type;
1003   do
1004     {
1005       c_token *token = c_parser_peek_token (parser);
1006       token_type = token->type;
1007       if (token_type == CPP_EOF)
1008 	break;
1009       c_parser_consume_token (parser);
1010     }
1011   while (token_type != CPP_PRAGMA_EOL);
1012 
1013   parser->error = false;
1014 }
1015 
1016 /* Skip tokens until we have consumed an entire block, or until we
1017    have consumed a non-nested ';'.  */
1018 
1019 static void
1020 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1021 {
1022   unsigned nesting_depth = 0;
1023   bool save_error = parser->error;
1024 
1025   while (true)
1026     {
1027       c_token *token;
1028 
1029       /* Peek at the next token.  */
1030       token = c_parser_peek_token (parser);
1031 
1032       switch (token->type)
1033 	{
1034 	case CPP_EOF:
1035 	  return;
1036 
1037 	case CPP_PRAGMA_EOL:
1038 	  if (parser->in_pragma)
1039 	    return;
1040 	  break;
1041 
1042 	case CPP_SEMICOLON:
1043 	  /* If the next token is a ';', we have reached the
1044 	     end of the statement.  */
1045 	  if (!nesting_depth)
1046 	    {
1047 	      /* Consume the ';'.  */
1048 	      c_parser_consume_token (parser);
1049 	      goto finished;
1050 	    }
1051 	  break;
1052 
1053 	case CPP_CLOSE_BRACE:
1054 	  /* If the next token is a non-nested '}', then we have
1055 	     reached the end of the current block.  */
1056 	  if (nesting_depth == 0 || --nesting_depth == 0)
1057 	    {
1058 	      c_parser_consume_token (parser);
1059 	      goto finished;
1060 	    }
1061 	  break;
1062 
1063 	case CPP_OPEN_BRACE:
1064 	  /* If it the next token is a '{', then we are entering a new
1065 	     block.  Consume the entire block.  */
1066 	  ++nesting_depth;
1067 	  break;
1068 
1069 	case CPP_PRAGMA:
1070 	  /* If we see a pragma, consume the whole thing at once.  We
1071 	     have some safeguards against consuming pragmas willy-nilly.
1072 	     Normally, we'd expect to be here with parser->error set,
1073 	     which disables these safeguards.  But it's possible to get
1074 	     here for secondary error recovery, after parser->error has
1075 	     been cleared.  */
1076 	  c_parser_consume_pragma (parser);
1077 	  c_parser_skip_to_pragma_eol (parser);
1078 	  parser->error = save_error;
1079 	  continue;
1080 
1081 	default:
1082 	  break;
1083 	}
1084 
1085       c_parser_consume_token (parser);
1086     }
1087 
1088  finished:
1089   parser->error = false;
1090 }
1091 
1092 /* CPP's options (initialized by c-opts.c).  */
1093 extern cpp_options *cpp_opts;
1094 
1095 /* Save the warning flags which are controlled by __extension__.  */
1096 
1097 static inline int
1098 disable_extension_diagnostics (void)
1099 {
1100   int ret = (pedantic
1101 	     | (warn_pointer_arith << 1)
1102 	     | (warn_traditional << 2)
1103 	     | (flag_iso << 3)
1104 	     | (warn_long_long << 4)
1105 	     | (warn_cxx_compat << 5)
1106 	     | (warn_overlength_strings << 6)
1107 	     /* warn_c90_c99_compat has three states: -1/0/1, so we must
1108 		play tricks to properly restore it.  */
1109 	     | ((warn_c90_c99_compat == 1) << 7)
1110 	     | ((warn_c90_c99_compat == -1) << 8)
1111 	     /* Similarly for warn_c99_c11_compat.  */
1112 	     | ((warn_c99_c11_compat == 1) << 9)
1113 	     | ((warn_c99_c11_compat == -1) << 10)
1114 	     );
1115   cpp_opts->cpp_pedantic = pedantic = 0;
1116   warn_pointer_arith = 0;
1117   cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1118   flag_iso = 0;
1119   cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1120   warn_cxx_compat = 0;
1121   warn_overlength_strings = 0;
1122   warn_c90_c99_compat = 0;
1123   warn_c99_c11_compat = 0;
1124   return ret;
1125 }
1126 
1127 /* Restore the warning flags which are controlled by __extension__.
1128    FLAGS is the return value from disable_extension_diagnostics.  */
1129 
1130 static inline void
1131 restore_extension_diagnostics (int flags)
1132 {
1133   cpp_opts->cpp_pedantic = pedantic = flags & 1;
1134   warn_pointer_arith = (flags >> 1) & 1;
1135   cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1136   flag_iso = (flags >> 3) & 1;
1137   cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1138   warn_cxx_compat = (flags >> 5) & 1;
1139   warn_overlength_strings = (flags >> 6) & 1;
1140   /* See above for why is this needed.  */
1141   warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1142   warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1143 }
1144 
1145 /* Possibly kinds of declarator to parse.  */
1146 typedef enum c_dtr_syn {
1147   /* A normal declarator with an identifier.  */
1148   C_DTR_NORMAL,
1149   /* An abstract declarator (maybe empty).  */
1150   C_DTR_ABSTRACT,
1151   /* A parameter declarator: may be either, but after a type name does
1152      not redeclare a typedef name as an identifier if it can
1153      alternatively be interpreted as a typedef name; see DR#009,
1154      applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1155      following DR#249.  For example, given a typedef T, "int T" and
1156      "int *T" are valid parameter declarations redeclaring T, while
1157      "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1158      abstract declarators rather than involving redundant parentheses;
1159      the same applies with attributes inside the parentheses before
1160      "T".  */
1161   C_DTR_PARM
1162 } c_dtr_syn;
1163 
1164 /* The binary operation precedence levels, where 0 is a dummy lowest level
1165    used for the bottom of the stack.  */
1166 enum c_parser_prec {
1167   PREC_NONE,
1168   PREC_LOGOR,
1169   PREC_LOGAND,
1170   PREC_BITOR,
1171   PREC_BITXOR,
1172   PREC_BITAND,
1173   PREC_EQ,
1174   PREC_REL,
1175   PREC_SHIFT,
1176   PREC_ADD,
1177   PREC_MULT,
1178   NUM_PRECS
1179 };
1180 
1181 static void c_parser_external_declaration (c_parser *);
1182 static void c_parser_asm_definition (c_parser *);
1183 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1184 					   bool, bool, tree *, vec<c_token>);
1185 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1186 static void c_parser_static_assert_declaration (c_parser *);
1187 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1188 				bool, bool, bool, enum c_lookahead_kind);
1189 static struct c_typespec c_parser_enum_specifier (c_parser *);
1190 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1191 static tree c_parser_struct_declaration (c_parser *);
1192 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1193 static tree c_parser_alignas_specifier (c_parser *);
1194 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1195 						 bool *);
1196 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1197 							c_dtr_syn, bool *);
1198 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1199 							      bool,
1200 							      struct c_declarator *);
1201 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1202 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1203 							  tree);
1204 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1205 static tree c_parser_simple_asm_expr (c_parser *);
1206 static tree c_parser_attributes (c_parser *);
1207 static struct c_type_name *c_parser_type_name (c_parser *);
1208 static struct c_expr c_parser_initializer (c_parser *);
1209 static struct c_expr c_parser_braced_init (c_parser *, tree, bool,
1210 					   struct obstack *);
1211 static void c_parser_initelt (c_parser *, struct obstack *);
1212 static void c_parser_initval (c_parser *, struct c_expr *,
1213 			      struct obstack *);
1214 static tree c_parser_compound_statement (c_parser *);
1215 static void c_parser_compound_statement_nostart (c_parser *);
1216 static void c_parser_label (c_parser *);
1217 static void c_parser_statement (c_parser *);
1218 static void c_parser_statement_after_labels (c_parser *);
1219 static void c_parser_if_statement (c_parser *);
1220 static void c_parser_switch_statement (c_parser *);
1221 static void c_parser_while_statement (c_parser *, bool);
1222 static void c_parser_do_statement (c_parser *, bool);
1223 static void c_parser_for_statement (c_parser *, bool);
1224 static tree c_parser_asm_statement (c_parser *);
1225 static tree c_parser_asm_operands (c_parser *);
1226 static tree c_parser_asm_goto_operands (c_parser *);
1227 static tree c_parser_asm_clobbers (c_parser *);
1228 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1229 					      tree = NULL_TREE);
1230 static struct c_expr c_parser_conditional_expression (c_parser *,
1231 						      struct c_expr *, tree);
1232 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1233 						 tree);
1234 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1235 static struct c_expr c_parser_unary_expression (c_parser *);
1236 static struct c_expr c_parser_sizeof_expression (c_parser *);
1237 static struct c_expr c_parser_alignof_expression (c_parser *);
1238 static struct c_expr c_parser_postfix_expression (c_parser *);
1239 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1240 								   struct c_type_name *,
1241 								   location_t);
1242 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1243 								location_t loc,
1244 								struct c_expr);
1245 static tree c_parser_transaction (c_parser *, enum rid);
1246 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1247 static tree c_parser_transaction_cancel (c_parser *);
1248 static struct c_expr c_parser_expression (c_parser *);
1249 static struct c_expr c_parser_expression_conv (c_parser *);
1250 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1251 					     vec<tree, va_gc> **, location_t *,
1252 					     tree *, vec<location_t> *,
1253 					     unsigned int * = NULL);
1254 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1255 static void c_parser_oacc_update (c_parser *);
1256 static tree c_parser_oacc_loop (location_t, c_parser *, char *);
1257 static void c_parser_omp_construct (c_parser *);
1258 static void c_parser_omp_threadprivate (c_parser *);
1259 static void c_parser_omp_barrier (c_parser *);
1260 static void c_parser_omp_flush (c_parser *);
1261 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1262 				   tree, tree *);
1263 static void c_parser_omp_taskwait (c_parser *);
1264 static void c_parser_omp_taskyield (c_parser *);
1265 static void c_parser_omp_cancel (c_parser *);
1266 static void c_parser_omp_cancellation_point (c_parser *);
1267 
1268 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1269 		      pragma_stmt, pragma_compound };
1270 static bool c_parser_pragma (c_parser *, enum pragma_context);
1271 static bool c_parser_omp_target (c_parser *, enum pragma_context);
1272 static void c_parser_omp_end_declare_target (c_parser *);
1273 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1274 
1275 /* These Objective-C parser functions are only ever called when
1276    compiling Objective-C.  */
1277 static void c_parser_objc_class_definition (c_parser *, tree);
1278 static void c_parser_objc_class_instance_variables (c_parser *);
1279 static void c_parser_objc_class_declaration (c_parser *);
1280 static void c_parser_objc_alias_declaration (c_parser *);
1281 static void c_parser_objc_protocol_definition (c_parser *, tree);
1282 static bool c_parser_objc_method_type (c_parser *);
1283 static void c_parser_objc_method_definition (c_parser *);
1284 static void c_parser_objc_methodprotolist (c_parser *);
1285 static void c_parser_objc_methodproto (c_parser *);
1286 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1287 static tree c_parser_objc_type_name (c_parser *);
1288 static tree c_parser_objc_protocol_refs (c_parser *);
1289 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1290 static void c_parser_objc_synchronized_statement (c_parser *);
1291 static tree c_parser_objc_selector (c_parser *);
1292 static tree c_parser_objc_selector_arg (c_parser *);
1293 static tree c_parser_objc_receiver (c_parser *);
1294 static tree c_parser_objc_message_args (c_parser *);
1295 static tree c_parser_objc_keywordexpr (c_parser *);
1296 static void c_parser_objc_at_property_declaration (c_parser *);
1297 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1298 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1299 static bool c_parser_objc_diagnose_bad_element_prefix
1300   (c_parser *, struct c_declspecs *);
1301 
1302 /* Cilk Plus supporting routines.  */
1303 static void c_parser_cilk_simd (c_parser *);
1304 static void c_parser_cilk_for (c_parser *, tree);
1305 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
1306 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
1307 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
1308 static void c_parser_cilk_grainsize (c_parser *);
1309 
1310 /* Parse a translation unit (C90 6.7, C99 6.9).
1311 
1312    translation-unit:
1313      external-declarations
1314 
1315    external-declarations:
1316      external-declaration
1317      external-declarations external-declaration
1318 
1319    GNU extensions:
1320 
1321    translation-unit:
1322      empty
1323 */
1324 
1325 static void
1326 c_parser_translation_unit (c_parser *parser)
1327 {
1328   if (c_parser_next_token_is (parser, CPP_EOF))
1329     {
1330       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1331 	       "ISO C forbids an empty translation unit");
1332     }
1333   else
1334     {
1335       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1336       mark_valid_location_for_stdc_pragma (false);
1337       do
1338 	{
1339 	  ggc_collect ();
1340 	  c_parser_external_declaration (parser);
1341 	  obstack_free (&parser_obstack, obstack_position);
1342 	}
1343       while (c_parser_next_token_is_not (parser, CPP_EOF));
1344     }
1345 }
1346 
1347 /* Parse an external declaration (C90 6.7, C99 6.9).
1348 
1349    external-declaration:
1350      function-definition
1351      declaration
1352 
1353    GNU extensions:
1354 
1355    external-declaration:
1356      asm-definition
1357      ;
1358      __extension__ external-declaration
1359 
1360    Objective-C:
1361 
1362    external-declaration:
1363      objc-class-definition
1364      objc-class-declaration
1365      objc-alias-declaration
1366      objc-protocol-definition
1367      objc-method-definition
1368      @end
1369 */
1370 
1371 static void
1372 c_parser_external_declaration (c_parser *parser)
1373 {
1374   int ext;
1375   switch (c_parser_peek_token (parser)->type)
1376     {
1377     case CPP_KEYWORD:
1378       switch (c_parser_peek_token (parser)->keyword)
1379 	{
1380 	case RID_EXTENSION:
1381 	  ext = disable_extension_diagnostics ();
1382 	  c_parser_consume_token (parser);
1383 	  c_parser_external_declaration (parser);
1384 	  restore_extension_diagnostics (ext);
1385 	  break;
1386 	case RID_ASM:
1387 	  c_parser_asm_definition (parser);
1388 	  break;
1389 	case RID_AT_INTERFACE:
1390 	case RID_AT_IMPLEMENTATION:
1391 	  gcc_assert (c_dialect_objc ());
1392 	  c_parser_objc_class_definition (parser, NULL_TREE);
1393 	  break;
1394 	case RID_AT_CLASS:
1395 	  gcc_assert (c_dialect_objc ());
1396 	  c_parser_objc_class_declaration (parser);
1397 	  break;
1398 	case RID_AT_ALIAS:
1399 	  gcc_assert (c_dialect_objc ());
1400 	  c_parser_objc_alias_declaration (parser);
1401 	  break;
1402 	case RID_AT_PROTOCOL:
1403 	  gcc_assert (c_dialect_objc ());
1404 	  c_parser_objc_protocol_definition (parser, NULL_TREE);
1405 	  break;
1406 	case RID_AT_PROPERTY:
1407 	  gcc_assert (c_dialect_objc ());
1408 	  c_parser_objc_at_property_declaration (parser);
1409 	  break;
1410 	case RID_AT_SYNTHESIZE:
1411 	  gcc_assert (c_dialect_objc ());
1412 	  c_parser_objc_at_synthesize_declaration (parser);
1413 	  break;
1414 	case RID_AT_DYNAMIC:
1415 	  gcc_assert (c_dialect_objc ());
1416 	  c_parser_objc_at_dynamic_declaration (parser);
1417 	  break;
1418 	case RID_AT_END:
1419 	  gcc_assert (c_dialect_objc ());
1420 	  c_parser_consume_token (parser);
1421 	  objc_finish_implementation ();
1422 	  break;
1423 	default:
1424 	  goto decl_or_fndef;
1425 	}
1426       break;
1427     case CPP_SEMICOLON:
1428       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1429 	       "ISO C does not allow extra %<;%> outside of a function");
1430       c_parser_consume_token (parser);
1431       break;
1432     case CPP_PRAGMA:
1433       mark_valid_location_for_stdc_pragma (true);
1434       c_parser_pragma (parser, pragma_external);
1435       mark_valid_location_for_stdc_pragma (false);
1436       break;
1437     case CPP_PLUS:
1438     case CPP_MINUS:
1439       if (c_dialect_objc ())
1440 	{
1441 	  c_parser_objc_method_definition (parser);
1442 	  break;
1443 	}
1444       /* Else fall through, and yield a syntax error trying to parse
1445 	 as a declaration or function definition.  */
1446     default:
1447     decl_or_fndef:
1448       /* A declaration or a function definition (or, in Objective-C,
1449 	 an @interface or @protocol with prefix attributes).  We can
1450 	 only tell which after parsing the declaration specifiers, if
1451 	 any, and the first declarator.  */
1452       c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1453 				     NULL, vNULL);
1454       break;
1455     }
1456 }
1457 
1458 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1459 
1460 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1461    6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
1462    accepted; otherwise (old-style parameter declarations) only other
1463    declarations are accepted.  If STATIC_ASSERT_OK is true, a static
1464    assertion is accepted; otherwise (old-style parameter declarations)
1465    it is not.  If NESTED is true, we are inside a function or parsing
1466    old-style parameter declarations; any functions encountered are
1467    nested functions and declaration specifiers are required; otherwise
1468    we are at top level and functions are normal functions and
1469    declaration specifiers may be optional.  If EMPTY_OK is true, empty
1470    declarations are OK (subject to all other constraints); otherwise
1471    (old-style parameter declarations) they are diagnosed.  If
1472    START_ATTR_OK is true, the declaration specifiers may start with
1473    attributes; otherwise they may not.
1474    OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1475    declaration when parsing an Objective-C foreach statement.
1476 
1477    declaration:
1478      declaration-specifiers init-declarator-list[opt] ;
1479      static_assert-declaration
1480 
1481    function-definition:
1482      declaration-specifiers[opt] declarator declaration-list[opt]
1483        compound-statement
1484 
1485    declaration-list:
1486      declaration
1487      declaration-list declaration
1488 
1489    init-declarator-list:
1490      init-declarator
1491      init-declarator-list , init-declarator
1492 
1493    init-declarator:
1494      declarator simple-asm-expr[opt] attributes[opt]
1495      declarator simple-asm-expr[opt] attributes[opt] = initializer
1496 
1497    GNU extensions:
1498 
1499    nested-function-definition:
1500      declaration-specifiers declarator declaration-list[opt]
1501        compound-statement
1502 
1503    Objective-C:
1504      attributes objc-class-definition
1505      attributes objc-category-definition
1506      attributes objc-protocol-definition
1507 
1508    The simple-asm-expr and attributes are GNU extensions.
1509 
1510    This function does not handle __extension__; that is handled in its
1511    callers.  ??? Following the old parser, __extension__ may start
1512    external declarations, declarations in functions and declarations
1513    at the start of "for" loops, but not old-style parameter
1514    declarations.
1515 
1516    C99 requires declaration specifiers in a function definition; the
1517    absence is diagnosed through the diagnosis of implicit int.  In GNU
1518    C we also allow but diagnose declarations without declaration
1519    specifiers, but only at top level (elsewhere they conflict with
1520    other syntax).
1521 
1522    In Objective-C, declarations of the looping variable in a foreach
1523    statement are exceptionally terminated by 'in' (for example, 'for
1524    (NSObject *object in array) { ... }').
1525 
1526    OpenMP:
1527 
1528    declaration:
1529      threadprivate-directive  */
1530 
1531 static void
1532 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1533 			       bool static_assert_ok, bool empty_ok,
1534 			       bool nested, bool start_attr_ok,
1535 			       tree *objc_foreach_object_declaration,
1536 			       vec<c_token> omp_declare_simd_clauses)
1537 {
1538   struct c_declspecs *specs;
1539   tree prefix_attrs;
1540   tree all_prefix_attrs;
1541   bool diagnosed_no_specs = false;
1542   location_t here = c_parser_peek_token (parser)->location;
1543 
1544   if (static_assert_ok
1545       && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1546     {
1547       c_parser_static_assert_declaration (parser);
1548       return;
1549     }
1550   specs = build_null_declspecs ();
1551 
1552   /* Try to detect an unknown type name when we have "A B" or "A *B".  */
1553   if (c_parser_peek_token (parser)->type == CPP_NAME
1554       && c_parser_peek_token (parser)->id_kind == C_ID_ID
1555       && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1556           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1557       && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1558     {
1559       error_at (here, "unknown type name %qE",
1560                 c_parser_peek_token (parser)->value);
1561 
1562       /* Parse declspecs normally to get a correct pointer type, but avoid
1563          a further "fails to be a type name" error.  Refuse nested functions
1564          since it is not how the user likely wants us to recover.  */
1565       c_parser_peek_token (parser)->type = CPP_KEYWORD;
1566       c_parser_peek_token (parser)->keyword = RID_VOID;
1567       c_parser_peek_token (parser)->value = error_mark_node;
1568       fndef_ok = !nested;
1569     }
1570 
1571   c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1572 		      true, true, cla_nonabstract_decl);
1573   if (parser->error)
1574     {
1575       c_parser_skip_to_end_of_block_or_statement (parser);
1576       return;
1577     }
1578   if (nested && !specs->declspecs_seen_p)
1579     {
1580       c_parser_error (parser, "expected declaration specifiers");
1581       c_parser_skip_to_end_of_block_or_statement (parser);
1582       return;
1583     }
1584   finish_declspecs (specs);
1585   bool auto_type_p = specs->typespec_word == cts_auto_type;
1586   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1587     {
1588       if (auto_type_p)
1589 	error_at (here, "%<__auto_type%> in empty declaration");
1590       else if (empty_ok)
1591 	shadow_tag (specs);
1592       else
1593 	{
1594 	  shadow_tag_warned (specs, 1);
1595 	  pedwarn (here, 0, "empty declaration");
1596 	}
1597       c_parser_consume_token (parser);
1598       return;
1599     }
1600 
1601   /* Provide better error recovery.  Note that a type name here is usually
1602      better diagnosed as a redeclaration.  */
1603   if (empty_ok
1604       && specs->typespec_kind == ctsk_tagdef
1605       && c_parser_next_token_starts_declspecs (parser)
1606       && !c_parser_next_token_is (parser, CPP_NAME))
1607     {
1608       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1609       parser->error = false;
1610       shadow_tag_warned (specs, 1);
1611       return;
1612     }
1613   else if (c_dialect_objc () && !auto_type_p)
1614     {
1615       /* Prefix attributes are an error on method decls.  */
1616       switch (c_parser_peek_token (parser)->type)
1617 	{
1618 	  case CPP_PLUS:
1619 	  case CPP_MINUS:
1620 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1621 	      return;
1622 	    if (specs->attrs)
1623 	      {
1624 		warning_at (c_parser_peek_token (parser)->location,
1625 			    OPT_Wattributes,
1626 	       		    "prefix attributes are ignored for methods");
1627 		specs->attrs = NULL_TREE;
1628 	      }
1629 	    if (fndef_ok)
1630 	      c_parser_objc_method_definition (parser);
1631 	    else
1632 	      c_parser_objc_methodproto (parser);
1633 	    return;
1634 	    break;
1635 	  default:
1636 	    break;
1637 	}
1638       /* This is where we parse 'attributes @interface ...',
1639 	 'attributes @implementation ...', 'attributes @protocol ...'
1640 	 (where attributes could be, for example, __attribute__
1641 	 ((deprecated)).
1642       */
1643       switch (c_parser_peek_token (parser)->keyword)
1644 	{
1645 	case RID_AT_INTERFACE:
1646 	  {
1647 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1648 	      return;
1649 	    c_parser_objc_class_definition (parser, specs->attrs);
1650 	    return;
1651 	  }
1652 	  break;
1653 	case RID_AT_IMPLEMENTATION:
1654 	  {
1655 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1656 	      return;
1657 	    if (specs->attrs)
1658 	      {
1659 		warning_at (c_parser_peek_token (parser)->location,
1660 			OPT_Wattributes,
1661 			"prefix attributes are ignored for implementations");
1662 		specs->attrs = NULL_TREE;
1663 	      }
1664 	    c_parser_objc_class_definition (parser, NULL_TREE);
1665 	    return;
1666 	  }
1667 	  break;
1668 	case RID_AT_PROTOCOL:
1669 	  {
1670 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1671 	      return;
1672 	    c_parser_objc_protocol_definition (parser, specs->attrs);
1673 	    return;
1674 	  }
1675 	  break;
1676 	case RID_AT_ALIAS:
1677 	case RID_AT_CLASS:
1678 	case RID_AT_END:
1679 	case RID_AT_PROPERTY:
1680 	  if (specs->attrs)
1681 	    {
1682 	      c_parser_error (parser, "unexpected attribute");
1683 	      specs->attrs = NULL;
1684 	    }
1685 	  break;
1686 	default:
1687 	  break;
1688 	}
1689     }
1690 
1691   pending_xref_error ();
1692   prefix_attrs = specs->attrs;
1693   all_prefix_attrs = prefix_attrs;
1694   specs->attrs = NULL_TREE;
1695   while (true)
1696     {
1697       struct c_declarator *declarator;
1698       bool dummy = false;
1699       timevar_id_t tv;
1700       tree fnbody;
1701       /* Declaring either one or more declarators (in which case we
1702 	 should diagnose if there were no declaration specifiers) or a
1703 	 function definition (in which case the diagnostic for
1704 	 implicit int suffices).  */
1705       declarator = c_parser_declarator (parser,
1706 					specs->typespec_kind != ctsk_none,
1707 					C_DTR_NORMAL, &dummy);
1708       if (declarator == NULL)
1709 	{
1710 	  if (omp_declare_simd_clauses.exists ()
1711 	      || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1712 	    c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1713 				       omp_declare_simd_clauses);
1714 	  c_parser_skip_to_end_of_block_or_statement (parser);
1715 	  return;
1716 	}
1717       if (auto_type_p && declarator->kind != cdk_id)
1718 	{
1719 	  error_at (here,
1720 		    "%<__auto_type%> requires a plain identifier"
1721 		    " as declarator");
1722 	  c_parser_skip_to_end_of_block_or_statement (parser);
1723 	  return;
1724 	}
1725       if (c_parser_next_token_is (parser, CPP_EQ)
1726 	  || c_parser_next_token_is (parser, CPP_COMMA)
1727 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
1728 	  || c_parser_next_token_is_keyword (parser, RID_ASM)
1729 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1730 	  || c_parser_next_token_is_keyword (parser, RID_IN))
1731 	{
1732 	  tree asm_name = NULL_TREE;
1733 	  tree postfix_attrs = NULL_TREE;
1734 	  if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1735 	    {
1736 	      diagnosed_no_specs = true;
1737 	      pedwarn (here, 0, "data definition has no type or storage class");
1738 	    }
1739 	  /* Having seen a data definition, there cannot now be a
1740 	     function definition.  */
1741 	  fndef_ok = false;
1742 	  if (c_parser_next_token_is_keyword (parser, RID_ASM))
1743 	    asm_name = c_parser_simple_asm_expr (parser);
1744 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1745 	    {
1746 	      postfix_attrs = c_parser_attributes (parser);
1747 	      if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1748 		{
1749 		  /* This means there is an attribute specifier after
1750 		     the declarator in a function definition.  Provide
1751 		     some more information for the user.  */
1752 		  error_at (here, "attributes should be specified before the "
1753 			    "declarator in a function definition");
1754 		  c_parser_skip_to_end_of_block_or_statement (parser);
1755 		  return;
1756 		}
1757 	    }
1758 	  if (c_parser_next_token_is (parser, CPP_EQ))
1759 	    {
1760 	      tree d;
1761 	      struct c_expr init;
1762 	      location_t init_loc;
1763 	      c_parser_consume_token (parser);
1764 	      if (auto_type_p)
1765 		{
1766 		  start_init (NULL_TREE, asm_name, global_bindings_p ());
1767 		  init_loc = c_parser_peek_token (parser)->location;
1768 		  init = c_parser_expr_no_commas (parser, NULL);
1769 		  if (TREE_CODE (init.value) == COMPONENT_REF
1770 		      && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
1771 		    error_at (here,
1772 			      "%<__auto_type%> used with a bit-field"
1773 			      " initializer");
1774 		  init = convert_lvalue_to_rvalue (init_loc, init, true, true);
1775 		  tree init_type = TREE_TYPE (init.value);
1776 		  /* As with typeof, remove all qualifiers from atomic types.  */
1777 		  if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
1778 		    init_type
1779 		      = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
1780 		  bool vm_type = variably_modified_type_p (init_type,
1781 							   NULL_TREE);
1782 		  if (vm_type)
1783 		    init.value = c_save_expr (init.value);
1784 		  finish_init ();
1785 		  specs->typespec_kind = ctsk_typeof;
1786 		  specs->locations[cdw_typedef] = init_loc;
1787 		  specs->typedef_p = true;
1788 		  specs->type = init_type;
1789 		  if (vm_type)
1790 		    {
1791 		      bool maybe_const = true;
1792 		      tree type_expr = c_fully_fold (init.value, false,
1793 						     &maybe_const);
1794 		      specs->expr_const_operands &= maybe_const;
1795 		      if (specs->expr)
1796 			specs->expr = build2 (COMPOUND_EXPR,
1797 					      TREE_TYPE (type_expr),
1798 					      specs->expr, type_expr);
1799 		      else
1800 			specs->expr = type_expr;
1801 		    }
1802 		  d = start_decl (declarator, specs, true,
1803 				  chainon (postfix_attrs, all_prefix_attrs));
1804 		  if (!d)
1805 		    d = error_mark_node;
1806 		  if (omp_declare_simd_clauses.exists ()
1807 		      || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1808 		    c_finish_omp_declare_simd (parser, d, NULL_TREE,
1809 					       omp_declare_simd_clauses);
1810 		}
1811 	      else
1812 		{
1813 		  /* The declaration of the variable is in effect while
1814 		     its initializer is parsed.  */
1815 		  d = start_decl (declarator, specs, true,
1816 				  chainon (postfix_attrs, all_prefix_attrs));
1817 		  if (!d)
1818 		    d = error_mark_node;
1819 		  if (omp_declare_simd_clauses.exists ()
1820 		      || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1821 		    c_finish_omp_declare_simd (parser, d, NULL_TREE,
1822 					       omp_declare_simd_clauses);
1823 		  start_init (d, asm_name, global_bindings_p ());
1824 		  init_loc = c_parser_peek_token (parser)->location;
1825 		  init = c_parser_initializer (parser);
1826 		  finish_init ();
1827 		}
1828 	      if (d != error_mark_node)
1829 		{
1830 		  maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
1831 		  finish_decl (d, init_loc, init.value,
1832 			       init.original_type, asm_name);
1833 		}
1834 	    }
1835 	  else
1836 	    {
1837 	      if (auto_type_p)
1838 		{
1839 		  error_at (here,
1840 			    "%<__auto_type%> requires an initialized "
1841 			    "data declaration");
1842 		  c_parser_skip_to_end_of_block_or_statement (parser);
1843 		  return;
1844 		}
1845 	      tree d = start_decl (declarator, specs, false,
1846 				   chainon (postfix_attrs,
1847 					    all_prefix_attrs));
1848 	      if (omp_declare_simd_clauses.exists ()
1849 		  || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1850 		{
1851 		  tree parms = NULL_TREE;
1852 		  if (d && TREE_CODE (d) == FUNCTION_DECL)
1853 		    {
1854 		      struct c_declarator *ce = declarator;
1855 		      while (ce != NULL)
1856 			if (ce->kind == cdk_function)
1857 			  {
1858 			    parms = ce->u.arg_info->parms;
1859 			    break;
1860 			  }
1861 			else
1862 			  ce = ce->declarator;
1863 		    }
1864 		  if (parms)
1865 		    temp_store_parm_decls (d, parms);
1866 		  c_finish_omp_declare_simd (parser, d, parms,
1867 					     omp_declare_simd_clauses);
1868 		  if (parms)
1869 		    temp_pop_parm_decls ();
1870 		}
1871 	      if (d)
1872 		finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1873 			     NULL_TREE, asm_name);
1874 
1875 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
1876 		{
1877 		  if (d)
1878 		    *objc_foreach_object_declaration = d;
1879 		  else
1880 		    *objc_foreach_object_declaration = error_mark_node;
1881 		}
1882 	    }
1883 	  if (c_parser_next_token_is (parser, CPP_COMMA))
1884 	    {
1885 	      if (auto_type_p)
1886 		{
1887 		  error_at (here,
1888 			    "%<__auto_type%> may only be used with"
1889 			    " a single declarator");
1890 		  c_parser_skip_to_end_of_block_or_statement (parser);
1891 		  return;
1892 		}
1893 	      c_parser_consume_token (parser);
1894 	      if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1895 		all_prefix_attrs = chainon (c_parser_attributes (parser),
1896 					    prefix_attrs);
1897 	      else
1898 		all_prefix_attrs = prefix_attrs;
1899 	      continue;
1900 	    }
1901 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1902 	    {
1903 	      c_parser_consume_token (parser);
1904 	      return;
1905 	    }
1906 	  else if (c_parser_next_token_is_keyword (parser, RID_IN))
1907 	    {
1908 	      /* This can only happen in Objective-C: we found the
1909 		 'in' that terminates the declaration inside an
1910 		 Objective-C foreach statement.  Do not consume the
1911 		 token, so that the caller can use it to determine
1912 		 that this indeed is a foreach context.  */
1913 	      return;
1914 	    }
1915 	  else
1916 	    {
1917 	      c_parser_error (parser, "expected %<,%> or %<;%>");
1918 	      c_parser_skip_to_end_of_block_or_statement (parser);
1919 	      return;
1920 	    }
1921 	}
1922       else if (auto_type_p)
1923 	{
1924 	  error_at (here,
1925 		    "%<__auto_type%> requires an initialized data declaration");
1926 	  c_parser_skip_to_end_of_block_or_statement (parser);
1927 	  return;
1928 	}
1929       else if (!fndef_ok)
1930 	{
1931 	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1932 			  "%<asm%> or %<__attribute__%>");
1933 	  c_parser_skip_to_end_of_block_or_statement (parser);
1934 	  return;
1935 	}
1936       /* Function definition (nested or otherwise).  */
1937       if (nested)
1938 	{
1939 	  pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
1940 	  c_push_function_context ();
1941 	}
1942       if (!start_function (specs, declarator, all_prefix_attrs))
1943 	{
1944 	  /* This can appear in many cases looking nothing like a
1945 	     function definition, so we don't give a more specific
1946 	     error suggesting there was one.  */
1947 	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1948 			  "or %<__attribute__%>");
1949 	  if (nested)
1950 	    c_pop_function_context ();
1951 	  break;
1952 	}
1953 
1954       if (DECL_DECLARED_INLINE_P (current_function_decl))
1955         tv = TV_PARSE_INLINE;
1956       else
1957         tv = TV_PARSE_FUNC;
1958       timevar_push (tv);
1959 
1960       /* Parse old-style parameter declarations.  ??? Attributes are
1961 	 not allowed to start declaration specifiers here because of a
1962 	 syntax conflict between a function declaration with attribute
1963 	 suffix and a function definition with an attribute prefix on
1964 	 first old-style parameter declaration.  Following the old
1965 	 parser, they are not accepted on subsequent old-style
1966 	 parameter declarations either.  However, there is no
1967 	 ambiguity after the first declaration, nor indeed on the
1968 	 first as long as we don't allow postfix attributes after a
1969 	 declarator with a nonempty identifier list in a definition;
1970 	 and postfix attributes have never been accepted here in
1971 	 function definitions either.  */
1972       while (c_parser_next_token_is_not (parser, CPP_EOF)
1973 	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1974 	c_parser_declaration_or_fndef (parser, false, false, false,
1975 				       true, false, NULL, vNULL);
1976       store_parm_decls ();
1977       if (omp_declare_simd_clauses.exists ()
1978 	  || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1979 	c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
1980 				   omp_declare_simd_clauses);
1981       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1982 	= c_parser_peek_token (parser)->location;
1983       fnbody = c_parser_compound_statement (parser);
1984       if (flag_cilkplus && contains_array_notation_expr (fnbody))
1985 	fnbody = expand_array_notation_exprs (fnbody);
1986       if (nested)
1987 	{
1988 	  tree decl = current_function_decl;
1989 	  /* Mark nested functions as needing static-chain initially.
1990 	     lower_nested_functions will recompute it but the
1991 	     DECL_STATIC_CHAIN flag is also used before that happens,
1992 	     by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
1993 	  DECL_STATIC_CHAIN (decl) = 1;
1994 	  add_stmt (fnbody);
1995 	  finish_function ();
1996 	  c_pop_function_context ();
1997 	  add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1998 	}
1999       else
2000 	{
2001 	  add_stmt (fnbody);
2002 	  finish_function ();
2003 	}
2004 
2005       timevar_pop (tv);
2006       break;
2007     }
2008 }
2009 
2010 /* Parse an asm-definition (asm() outside a function body).  This is a
2011    GNU extension.
2012 
2013    asm-definition:
2014      simple-asm-expr ;
2015 */
2016 
2017 static void
2018 c_parser_asm_definition (c_parser *parser)
2019 {
2020   tree asm_str = c_parser_simple_asm_expr (parser);
2021   if (asm_str)
2022     symtab->finalize_toplevel_asm (asm_str);
2023   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2024 }
2025 
2026 /* Parse a static assertion (C11 6.7.10).
2027 
2028    static_assert-declaration:
2029      static_assert-declaration-no-semi ;
2030 */
2031 
2032 static void
2033 c_parser_static_assert_declaration (c_parser *parser)
2034 {
2035   c_parser_static_assert_declaration_no_semi (parser);
2036   if (parser->error
2037       || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2038     c_parser_skip_to_end_of_block_or_statement (parser);
2039 }
2040 
2041 /* Parse a static assertion (C11 6.7.10), without the trailing
2042    semicolon.
2043 
2044    static_assert-declaration-no-semi:
2045      _Static_assert ( constant-expression , string-literal )
2046 */
2047 
2048 static void
2049 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2050 {
2051   location_t assert_loc, value_loc;
2052   tree value;
2053   tree string;
2054 
2055   gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2056   assert_loc = c_parser_peek_token (parser)->location;
2057   if (flag_isoc99)
2058     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2059 		 "ISO C99 does not support %<_Static_assert%>");
2060   else
2061     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2062 		 "ISO C90 does not support %<_Static_assert%>");
2063   c_parser_consume_token (parser);
2064   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2065     return;
2066   value_loc = c_parser_peek_token (parser)->location;
2067   value = c_parser_expr_no_commas (parser, NULL).value;
2068   parser->lex_untranslated_string = true;
2069   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2070     {
2071       parser->lex_untranslated_string = false;
2072       return;
2073     }
2074   switch (c_parser_peek_token (parser)->type)
2075     {
2076     case CPP_STRING:
2077     case CPP_STRING16:
2078     case CPP_STRING32:
2079     case CPP_WSTRING:
2080     case CPP_UTF8STRING:
2081       string = c_parser_peek_token (parser)->value;
2082       c_parser_consume_token (parser);
2083       parser->lex_untranslated_string = false;
2084       break;
2085     default:
2086       c_parser_error (parser, "expected string literal");
2087       parser->lex_untranslated_string = false;
2088       return;
2089     }
2090   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2091 
2092   if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2093     {
2094       error_at (value_loc, "expression in static assertion is not an integer");
2095       return;
2096     }
2097   if (TREE_CODE (value) != INTEGER_CST)
2098     {
2099       value = c_fully_fold (value, false, NULL);
2100       /* Strip no-op conversions.  */
2101       STRIP_TYPE_NOPS (value);
2102       if (TREE_CODE (value) == INTEGER_CST)
2103 	pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2104 		 "is not an integer constant expression");
2105     }
2106   if (TREE_CODE (value) != INTEGER_CST)
2107     {
2108       error_at (value_loc, "expression in static assertion is not constant");
2109       return;
2110     }
2111   constant_expression_warning (value);
2112   if (integer_zerop (value))
2113     error_at (assert_loc, "static assertion failed: %E", string);
2114 }
2115 
2116 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2117    6.7), adding them to SPECS (which may already include some).
2118    Storage class specifiers are accepted iff SCSPEC_OK; type
2119    specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2120    accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2121    iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2122 
2123    declaration-specifiers:
2124      storage-class-specifier declaration-specifiers[opt]
2125      type-specifier declaration-specifiers[opt]
2126      type-qualifier declaration-specifiers[opt]
2127      function-specifier declaration-specifiers[opt]
2128      alignment-specifier declaration-specifiers[opt]
2129 
2130    Function specifiers (inline) are from C99, and are currently
2131    handled as storage class specifiers, as is __thread.  Alignment
2132    specifiers are from C11.
2133 
2134    C90 6.5.1, C99 6.7.1:
2135    storage-class-specifier:
2136      typedef
2137      extern
2138      static
2139      auto
2140      register
2141      _Thread_local
2142 
2143    (_Thread_local is new in C11.)
2144 
2145    C99 6.7.4:
2146    function-specifier:
2147      inline
2148      _Noreturn
2149 
2150    (_Noreturn is new in C11.)
2151 
2152    C90 6.5.2, C99 6.7.2:
2153    type-specifier:
2154      void
2155      char
2156      short
2157      int
2158      long
2159      float
2160      double
2161      signed
2162      unsigned
2163      _Bool
2164      _Complex
2165      [_Imaginary removed in C99 TC2]
2166      struct-or-union-specifier
2167      enum-specifier
2168      typedef-name
2169      atomic-type-specifier
2170 
2171    (_Bool and _Complex are new in C99.)
2172    (atomic-type-specifier is new in C11.)
2173 
2174    C90 6.5.3, C99 6.7.3:
2175 
2176    type-qualifier:
2177      const
2178      restrict
2179      volatile
2180      address-space-qualifier
2181      _Atomic
2182 
2183    (restrict is new in C99.)
2184    (_Atomic is new in C11.)
2185 
2186    GNU extensions:
2187 
2188    declaration-specifiers:
2189      attributes declaration-specifiers[opt]
2190 
2191    type-qualifier:
2192      address-space
2193 
2194    address-space:
2195      identifier recognized by the target
2196 
2197    storage-class-specifier:
2198      __thread
2199 
2200    type-specifier:
2201      typeof-specifier
2202      __auto_type
2203      __intN
2204      _Decimal32
2205      _Decimal64
2206      _Decimal128
2207      _Fract
2208      _Accum
2209      _Sat
2210 
2211   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2212    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2213 
2214    atomic-type-specifier
2215     _Atomic ( type-name )
2216 
2217    Objective-C:
2218 
2219    type-specifier:
2220      class-name objc-protocol-refs[opt]
2221      typedef-name objc-protocol-refs
2222      objc-protocol-refs
2223 */
2224 
2225 static void
2226 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2227 		    bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2228 		    bool alignspec_ok, bool auto_type_ok,
2229 		    enum c_lookahead_kind la)
2230 {
2231   bool attrs_ok = start_attr_ok;
2232   bool seen_type = specs->typespec_kind != ctsk_none;
2233 
2234   if (!typespec_ok)
2235     gcc_assert (la == cla_prefer_id);
2236 
2237   while (c_parser_next_token_is (parser, CPP_NAME)
2238 	 || c_parser_next_token_is (parser, CPP_KEYWORD)
2239 	 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2240     {
2241       struct c_typespec t;
2242       tree attrs;
2243       tree align;
2244       location_t loc = c_parser_peek_token (parser)->location;
2245 
2246       /* If we cannot accept a type, exit if the next token must start
2247 	 one.  Also, if we already have seen a tagged definition,
2248 	 a typename would be an error anyway and likely the user
2249 	 has simply forgotten a semicolon, so we exit.  */
2250       if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2251 	  && c_parser_next_tokens_start_typename (parser, la)
2252 	  && !c_parser_next_token_is_qualifier (parser))
2253 	break;
2254 
2255       if (c_parser_next_token_is (parser, CPP_NAME))
2256 	{
2257 	  c_token *name_token = c_parser_peek_token (parser);
2258 	  tree value = name_token->value;
2259 	  c_id_kind kind = name_token->id_kind;
2260 
2261 	  if (kind == C_ID_ADDRSPACE)
2262 	    {
2263 	      addr_space_t as
2264 		= name_token->keyword - RID_FIRST_ADDR_SPACE;
2265 	      declspecs_add_addrspace (name_token->location, specs, as);
2266 	      c_parser_consume_token (parser);
2267 	      attrs_ok = true;
2268 	      continue;
2269 	    }
2270 
2271 	  gcc_assert (!c_parser_next_token_is_qualifier (parser));
2272 
2273 	  /* If we cannot accept a type, and the next token must start one,
2274 	     exit.  Do the same if we already have seen a tagged definition,
2275 	     since it would be an error anyway and likely the user has simply
2276 	     forgotten a semicolon.  */
2277 	  if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2278 	    break;
2279 
2280 	  /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2281 	     a C_ID_CLASSNAME.  */
2282 	  c_parser_consume_token (parser);
2283 	  seen_type = true;
2284 	  attrs_ok = true;
2285 	  if (kind == C_ID_ID)
2286 	    {
2287 	      error_at (loc, "unknown type name %qE", value);
2288 	      t.kind = ctsk_typedef;
2289 	      t.spec = error_mark_node;
2290 	    }
2291 	  else if (kind == C_ID_TYPENAME
2292 	           && (!c_dialect_objc ()
2293 	               || c_parser_next_token_is_not (parser, CPP_LESS)))
2294 	    {
2295 	      t.kind = ctsk_typedef;
2296 	      /* For a typedef name, record the meaning, not the name.
2297 		 In case of 'foo foo, bar;'.  */
2298 	      t.spec = lookup_name (value);
2299 	    }
2300 	  else
2301 	    {
2302 	      tree proto = NULL_TREE;
2303 	      gcc_assert (c_dialect_objc ());
2304 	      t.kind = ctsk_objc;
2305 	      if (c_parser_next_token_is (parser, CPP_LESS))
2306 		proto = c_parser_objc_protocol_refs (parser);
2307 	      t.spec = objc_get_protocol_qualified_type (value, proto);
2308 	    }
2309 	  t.expr = NULL_TREE;
2310 	  t.expr_const_operands = true;
2311 	  declspecs_add_type (name_token->location, specs, t);
2312 	  continue;
2313 	}
2314       if (c_parser_next_token_is (parser, CPP_LESS))
2315 	{
2316 	  /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2317 	     nisse@lysator.liu.se.  */
2318 	  tree proto;
2319 	  gcc_assert (c_dialect_objc ());
2320 	  if (!typespec_ok || seen_type)
2321 	    break;
2322 	  proto = c_parser_objc_protocol_refs (parser);
2323 	  t.kind = ctsk_objc;
2324 	  t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2325 	  t.expr = NULL_TREE;
2326 	  t.expr_const_operands = true;
2327 	  declspecs_add_type (loc, specs, t);
2328 	  continue;
2329 	}
2330       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2331       switch (c_parser_peek_token (parser)->keyword)
2332 	{
2333 	case RID_STATIC:
2334 	case RID_EXTERN:
2335 	case RID_REGISTER:
2336 	case RID_TYPEDEF:
2337 	case RID_INLINE:
2338 	case RID_NORETURN:
2339 	case RID_AUTO:
2340 	case RID_THREAD:
2341 	  if (!scspec_ok)
2342 	    goto out;
2343 	  attrs_ok = true;
2344 	  /* TODO: Distinguish between function specifiers (inline, noreturn)
2345 	     and storage class specifiers, either here or in
2346 	     declspecs_add_scspec.  */
2347 	  declspecs_add_scspec (loc, specs,
2348 				c_parser_peek_token (parser)->value);
2349 	  c_parser_consume_token (parser);
2350 	  break;
2351 	case RID_AUTO_TYPE:
2352 	  if (!auto_type_ok)
2353 	    goto out;
2354 	  /* Fall through.  */
2355 	case RID_UNSIGNED:
2356 	case RID_LONG:
2357 	case RID_SHORT:
2358 	case RID_SIGNED:
2359 	case RID_COMPLEX:
2360 	case RID_INT:
2361 	case RID_CHAR:
2362 	case RID_FLOAT:
2363 	case RID_DOUBLE:
2364 	case RID_VOID:
2365 	case RID_DFLOAT32:
2366 	case RID_DFLOAT64:
2367 	case RID_DFLOAT128:
2368 	case RID_BOOL:
2369 	case RID_FRACT:
2370 	case RID_ACCUM:
2371 	case RID_SAT:
2372 	case RID_INT_N_0:
2373 	case RID_INT_N_1:
2374 	case RID_INT_N_2:
2375 	case RID_INT_N_3:
2376 	  if (!typespec_ok)
2377 	    goto out;
2378 	  attrs_ok = true;
2379 	  seen_type = true;
2380 	  if (c_dialect_objc ())
2381 	    parser->objc_need_raw_identifier = true;
2382 	  t.kind = ctsk_resword;
2383 	  t.spec = c_parser_peek_token (parser)->value;
2384 	  t.expr = NULL_TREE;
2385 	  t.expr_const_operands = true;
2386 	  declspecs_add_type (loc, specs, t);
2387 	  c_parser_consume_token (parser);
2388 	  break;
2389 	case RID_ENUM:
2390 	  if (!typespec_ok)
2391 	    goto out;
2392 	  attrs_ok = true;
2393 	  seen_type = true;
2394 	  t = c_parser_enum_specifier (parser);
2395           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2396 	  declspecs_add_type (loc, specs, t);
2397 	  break;
2398 	case RID_STRUCT:
2399 	case RID_UNION:
2400 	  if (!typespec_ok)
2401 	    goto out;
2402 	  attrs_ok = true;
2403 	  seen_type = true;
2404 	  t = c_parser_struct_or_union_specifier (parser);
2405           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2406 	  declspecs_add_type (loc, specs, t);
2407 	  break;
2408 	case RID_TYPEOF:
2409 	  /* ??? The old parser rejected typeof after other type
2410 	     specifiers, but is a syntax error the best way of
2411 	     handling this?  */
2412 	  if (!typespec_ok || seen_type)
2413 	    goto out;
2414 	  attrs_ok = true;
2415 	  seen_type = true;
2416 	  t = c_parser_typeof_specifier (parser);
2417 	  declspecs_add_type (loc, specs, t);
2418 	  break;
2419 	case RID_ATOMIC:
2420 	  /* C parser handling of Objective-C constructs needs
2421 	     checking for correct lvalue-to-rvalue conversions, and
2422 	     the code in build_modify_expr handling various
2423 	     Objective-C cases, and that in build_unary_op handling
2424 	     Objective-C cases for increment / decrement, also needs
2425 	     updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2426 	     and objc_types_are_equivalent may also need updates.  */
2427 	  if (c_dialect_objc ())
2428 	    sorry ("%<_Atomic%> in Objective-C");
2429 	  /* C parser handling of OpenMP constructs needs checking for
2430 	     correct lvalue-to-rvalue conversions.  */
2431 	  if (flag_openmp)
2432 	    sorry ("%<_Atomic%> with OpenMP");
2433 	  if (flag_isoc99)
2434 	    pedwarn_c99 (loc, OPT_Wpedantic,
2435 			 "ISO C99 does not support the %<_Atomic%> qualifier");
2436 	  else
2437 	    pedwarn_c99 (loc, OPT_Wpedantic,
2438 			 "ISO C90 does not support the %<_Atomic%> qualifier");
2439 	  attrs_ok = true;
2440 	  tree value;
2441 	  value = c_parser_peek_token (parser)->value;
2442 	  c_parser_consume_token (parser);
2443 	  if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2444 	    {
2445 	      /* _Atomic ( type-name ).  */
2446 	      seen_type = true;
2447 	      c_parser_consume_token (parser);
2448 	      struct c_type_name *type = c_parser_type_name (parser);
2449 	      t.kind = ctsk_typeof;
2450 	      t.spec = error_mark_node;
2451 	      t.expr = NULL_TREE;
2452 	      t.expr_const_operands = true;
2453 	      if (type != NULL)
2454 		t.spec = groktypename (type, &t.expr,
2455 				       &t.expr_const_operands);
2456 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2457 					 "expected %<)%>");
2458 	      if (t.spec != error_mark_node)
2459 		{
2460 		  if (TREE_CODE (t.spec) == ARRAY_TYPE)
2461 		    error_at (loc, "%<_Atomic%>-qualified array type");
2462 		  else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2463 		    error_at (loc, "%<_Atomic%>-qualified function type");
2464 		  else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2465 		    error_at (loc, "%<_Atomic%> applied to a qualified type");
2466 		  else
2467 		    t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2468 		}
2469 	      declspecs_add_type (loc, specs, t);
2470 	    }
2471 	  else
2472 	    declspecs_add_qual (loc, specs, value);
2473 	  break;
2474 	case RID_CONST:
2475 	case RID_VOLATILE:
2476 	case RID_RESTRICT:
2477 	  attrs_ok = true;
2478 	  declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2479 	  c_parser_consume_token (parser);
2480 	  break;
2481 	case RID_ATTRIBUTE:
2482 	  if (!attrs_ok)
2483 	    goto out;
2484 	  attrs = c_parser_attributes (parser);
2485 	  declspecs_add_attrs (loc, specs, attrs);
2486 	  break;
2487 	case RID_ALIGNAS:
2488 	  if (!alignspec_ok)
2489 	    goto out;
2490 	  align = c_parser_alignas_specifier (parser);
2491 	  declspecs_add_alignas (loc, specs, align);
2492 	  break;
2493 	default:
2494 	  goto out;
2495 	}
2496     }
2497  out: ;
2498 }
2499 
2500 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2501 
2502    enum-specifier:
2503      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2504      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2505      enum attributes[opt] identifier
2506 
2507    The form with trailing comma is new in C99.  The forms with
2508    attributes are GNU extensions.  In GNU C, we accept any expression
2509    without commas in the syntax (assignment expressions, not just
2510    conditional expressions); assignment expressions will be diagnosed
2511    as non-constant.
2512 
2513    enumerator-list:
2514      enumerator
2515      enumerator-list , enumerator
2516 
2517    enumerator:
2518      enumeration-constant
2519      enumeration-constant = constant-expression
2520 */
2521 
2522 static struct c_typespec
2523 c_parser_enum_specifier (c_parser *parser)
2524 {
2525   struct c_typespec ret;
2526   tree attrs;
2527   tree ident = NULL_TREE;
2528   location_t enum_loc;
2529   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2530   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2531   enum_loc = c_parser_peek_token (parser)->location;
2532   c_parser_consume_token (parser);
2533   attrs = c_parser_attributes (parser);
2534   enum_loc = c_parser_peek_token (parser)->location;
2535   /* Set the location in case we create a decl now.  */
2536   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2537   if (c_parser_next_token_is (parser, CPP_NAME))
2538     {
2539       ident = c_parser_peek_token (parser)->value;
2540       ident_loc = c_parser_peek_token (parser)->location;
2541       enum_loc = ident_loc;
2542       c_parser_consume_token (parser);
2543     }
2544   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2545     {
2546       /* Parse an enum definition.  */
2547       struct c_enum_contents the_enum;
2548       tree type;
2549       tree postfix_attrs;
2550       /* We chain the enumerators in reverse order, then put them in
2551 	 forward order at the end.  */
2552       tree values;
2553       timevar_push (TV_PARSE_ENUM);
2554       type = start_enum (enum_loc, &the_enum, ident);
2555       values = NULL_TREE;
2556       c_parser_consume_token (parser);
2557       while (true)
2558 	{
2559 	  tree enum_id;
2560 	  tree enum_value;
2561 	  tree enum_decl;
2562 	  bool seen_comma;
2563 	  c_token *token;
2564 	  location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2565 	  location_t decl_loc, value_loc;
2566 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
2567 	    {
2568 	      c_parser_error (parser, "expected identifier");
2569 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2570 	      values = error_mark_node;
2571 	      break;
2572 	    }
2573 	  token = c_parser_peek_token (parser);
2574 	  enum_id = token->value;
2575 	  /* Set the location in case we create a decl now.  */
2576 	  c_parser_set_source_position_from_token (token);
2577 	  decl_loc = value_loc = token->location;
2578 	  c_parser_consume_token (parser);
2579 	  if (c_parser_next_token_is (parser, CPP_EQ))
2580 	    {
2581 	      c_parser_consume_token (parser);
2582 	      value_loc = c_parser_peek_token (parser)->location;
2583 	      enum_value = c_parser_expr_no_commas (parser, NULL).value;
2584 	    }
2585 	  else
2586 	    enum_value = NULL_TREE;
2587 	  enum_decl = build_enumerator (decl_loc, value_loc,
2588 	      				&the_enum, enum_id, enum_value);
2589 	  TREE_CHAIN (enum_decl) = values;
2590 	  values = enum_decl;
2591 	  seen_comma = false;
2592 	  if (c_parser_next_token_is (parser, CPP_COMMA))
2593 	    {
2594 	      comma_loc = c_parser_peek_token (parser)->location;
2595 	      seen_comma = true;
2596 	      c_parser_consume_token (parser);
2597 	    }
2598 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2599 	    {
2600 	      if (seen_comma)
2601 		pedwarn_c90 (comma_loc, OPT_Wpedantic,
2602 			     "comma at end of enumerator list");
2603 	      c_parser_consume_token (parser);
2604 	      break;
2605 	    }
2606 	  if (!seen_comma)
2607 	    {
2608 	      c_parser_error (parser, "expected %<,%> or %<}%>");
2609 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2610 	      values = error_mark_node;
2611 	      break;
2612 	    }
2613 	}
2614       postfix_attrs = c_parser_attributes (parser);
2615       ret.spec = finish_enum (type, nreverse (values),
2616 			      chainon (attrs, postfix_attrs));
2617       ret.kind = ctsk_tagdef;
2618       ret.expr = NULL_TREE;
2619       ret.expr_const_operands = true;
2620       timevar_pop (TV_PARSE_ENUM);
2621       return ret;
2622     }
2623   else if (!ident)
2624     {
2625       c_parser_error (parser, "expected %<{%>");
2626       ret.spec = error_mark_node;
2627       ret.kind = ctsk_tagref;
2628       ret.expr = NULL_TREE;
2629       ret.expr_const_operands = true;
2630       return ret;
2631     }
2632   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2633   /* In ISO C, enumerated types can be referred to only if already
2634      defined.  */
2635   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2636     {
2637       gcc_assert (ident);
2638       pedwarn (enum_loc, OPT_Wpedantic,
2639 	       "ISO C forbids forward references to %<enum%> types");
2640     }
2641   return ret;
2642 }
2643 
2644 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2645 
2646    struct-or-union-specifier:
2647      struct-or-union attributes[opt] identifier[opt]
2648        { struct-contents } attributes[opt]
2649      struct-or-union attributes[opt] identifier
2650 
2651    struct-contents:
2652      struct-declaration-list
2653 
2654    struct-declaration-list:
2655      struct-declaration ;
2656      struct-declaration-list struct-declaration ;
2657 
2658    GNU extensions:
2659 
2660    struct-contents:
2661      empty
2662      struct-declaration
2663      struct-declaration-list struct-declaration
2664 
2665    struct-declaration-list:
2666      struct-declaration-list ;
2667      ;
2668 
2669    (Note that in the syntax here, unlike that in ISO C, the semicolons
2670    are included here rather than in struct-declaration, in order to
2671    describe the syntax with extra semicolons and missing semicolon at
2672    end.)
2673 
2674    Objective-C:
2675 
2676    struct-declaration-list:
2677      @defs ( class-name )
2678 
2679    (Note this does not include a trailing semicolon, but can be
2680    followed by further declarations, and gets a pedwarn-if-pedantic
2681    when followed by a semicolon.)  */
2682 
2683 static struct c_typespec
2684 c_parser_struct_or_union_specifier (c_parser *parser)
2685 {
2686   struct c_typespec ret;
2687   tree attrs;
2688   tree ident = NULL_TREE;
2689   location_t struct_loc;
2690   location_t ident_loc = UNKNOWN_LOCATION;
2691   enum tree_code code;
2692   switch (c_parser_peek_token (parser)->keyword)
2693     {
2694     case RID_STRUCT:
2695       code = RECORD_TYPE;
2696       break;
2697     case RID_UNION:
2698       code = UNION_TYPE;
2699       break;
2700     default:
2701       gcc_unreachable ();
2702     }
2703   struct_loc = c_parser_peek_token (parser)->location;
2704   c_parser_consume_token (parser);
2705   attrs = c_parser_attributes (parser);
2706 
2707   /* Set the location in case we create a decl now.  */
2708   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2709 
2710   if (c_parser_next_token_is (parser, CPP_NAME))
2711     {
2712       ident = c_parser_peek_token (parser)->value;
2713       ident_loc = c_parser_peek_token (parser)->location;
2714       struct_loc = ident_loc;
2715       c_parser_consume_token (parser);
2716     }
2717   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2718     {
2719       /* Parse a struct or union definition.  Start the scope of the
2720 	 tag before parsing components.  */
2721       struct c_struct_parse_info *struct_info;
2722       tree type = start_struct (struct_loc, code, ident, &struct_info);
2723       tree postfix_attrs;
2724       /* We chain the components in reverse order, then put them in
2725 	 forward order at the end.  Each struct-declaration may
2726 	 declare multiple components (comma-separated), so we must use
2727 	 chainon to join them, although when parsing each
2728 	 struct-declaration we can use TREE_CHAIN directly.
2729 
2730 	 The theory behind all this is that there will be more
2731 	 semicolon separated fields than comma separated fields, and
2732 	 so we'll be minimizing the number of node traversals required
2733 	 by chainon.  */
2734       tree contents;
2735       timevar_push (TV_PARSE_STRUCT);
2736       contents = NULL_TREE;
2737       c_parser_consume_token (parser);
2738       /* Handle the Objective-C @defs construct,
2739 	 e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
2740       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2741 	{
2742 	  tree name;
2743 	  gcc_assert (c_dialect_objc ());
2744 	  c_parser_consume_token (parser);
2745 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2746 	    goto end_at_defs;
2747 	  if (c_parser_next_token_is (parser, CPP_NAME)
2748 	      && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2749 	    {
2750 	      name = c_parser_peek_token (parser)->value;
2751 	      c_parser_consume_token (parser);
2752 	    }
2753 	  else
2754 	    {
2755 	      c_parser_error (parser, "expected class name");
2756 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2757 	      goto end_at_defs;
2758 	    }
2759 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2760 				     "expected %<)%>");
2761 	  contents = nreverse (objc_get_class_ivars (name));
2762 	}
2763     end_at_defs:
2764       /* Parse the struct-declarations and semicolons.  Problems with
2765 	 semicolons are diagnosed here; empty structures are diagnosed
2766 	 elsewhere.  */
2767       while (true)
2768 	{
2769 	  tree decls;
2770 	  /* Parse any stray semicolon.  */
2771 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2772 	    {
2773 	      pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2774 		       "extra semicolon in struct or union specified");
2775 	      c_parser_consume_token (parser);
2776 	      continue;
2777 	    }
2778 	  /* Stop if at the end of the struct or union contents.  */
2779 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2780 	    {
2781 	      c_parser_consume_token (parser);
2782 	      break;
2783 	    }
2784 	  /* Accept #pragmas at struct scope.  */
2785 	  if (c_parser_next_token_is (parser, CPP_PRAGMA))
2786 	    {
2787 	      c_parser_pragma (parser, pragma_struct);
2788 	      continue;
2789 	    }
2790 	  /* Parse some comma-separated declarations, but not the
2791 	     trailing semicolon if any.  */
2792 	  decls = c_parser_struct_declaration (parser);
2793 	  contents = chainon (decls, contents);
2794 	  /* If no semicolon follows, either we have a parse error or
2795 	     are at the end of the struct or union and should
2796 	     pedwarn.  */
2797 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2798 	    c_parser_consume_token (parser);
2799 	  else
2800 	    {
2801 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2802 		pedwarn (c_parser_peek_token (parser)->location, 0,
2803 			 "no semicolon at end of struct or union");
2804 	      else if (parser->error
2805 		       || !c_parser_next_token_starts_declspecs (parser))
2806 		{
2807 		  c_parser_error (parser, "expected %<;%>");
2808 		  c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2809 		  break;
2810 		}
2811 
2812 	      /* If we come here, we have already emitted an error
2813 		 for an expected `;', identifier or `(', and we also
2814 	         recovered already.  Go on with the next field. */
2815 	    }
2816 	}
2817       postfix_attrs = c_parser_attributes (parser);
2818       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2819 				chainon (attrs, postfix_attrs), struct_info);
2820       ret.kind = ctsk_tagdef;
2821       ret.expr = NULL_TREE;
2822       ret.expr_const_operands = true;
2823       timevar_pop (TV_PARSE_STRUCT);
2824       return ret;
2825     }
2826   else if (!ident)
2827     {
2828       c_parser_error (parser, "expected %<{%>");
2829       ret.spec = error_mark_node;
2830       ret.kind = ctsk_tagref;
2831       ret.expr = NULL_TREE;
2832       ret.expr_const_operands = true;
2833       return ret;
2834     }
2835   ret = parser_xref_tag (ident_loc, code, ident);
2836   return ret;
2837 }
2838 
2839 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2840    the trailing semicolon.
2841 
2842    struct-declaration:
2843      specifier-qualifier-list struct-declarator-list
2844      static_assert-declaration-no-semi
2845 
2846    specifier-qualifier-list:
2847      type-specifier specifier-qualifier-list[opt]
2848      type-qualifier specifier-qualifier-list[opt]
2849      attributes specifier-qualifier-list[opt]
2850 
2851    struct-declarator-list:
2852      struct-declarator
2853      struct-declarator-list , attributes[opt] struct-declarator
2854 
2855    struct-declarator:
2856      declarator attributes[opt]
2857      declarator[opt] : constant-expression attributes[opt]
2858 
2859    GNU extensions:
2860 
2861    struct-declaration:
2862      __extension__ struct-declaration
2863      specifier-qualifier-list
2864 
2865    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
2866    of attributes where shown is a GNU extension.  In GNU C, we accept
2867    any expression without commas in the syntax (assignment
2868    expressions, not just conditional expressions); assignment
2869    expressions will be diagnosed as non-constant.  */
2870 
2871 static tree
2872 c_parser_struct_declaration (c_parser *parser)
2873 {
2874   struct c_declspecs *specs;
2875   tree prefix_attrs;
2876   tree all_prefix_attrs;
2877   tree decls;
2878   location_t decl_loc;
2879   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2880     {
2881       int ext;
2882       tree decl;
2883       ext = disable_extension_diagnostics ();
2884       c_parser_consume_token (parser);
2885       decl = c_parser_struct_declaration (parser);
2886       restore_extension_diagnostics (ext);
2887       return decl;
2888     }
2889   if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2890     {
2891       c_parser_static_assert_declaration_no_semi (parser);
2892       return NULL_TREE;
2893     }
2894   specs = build_null_declspecs ();
2895   decl_loc = c_parser_peek_token (parser)->location;
2896   /* Strictly by the standard, we shouldn't allow _Alignas here,
2897      but it appears to have been intended to allow it there, so
2898      we're keeping it as it is until WG14 reaches a conclusion
2899      of N1731.
2900      <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf>  */
2901   c_parser_declspecs (parser, specs, false, true, true,
2902 		      true, false, cla_nonabstract_decl);
2903   if (parser->error)
2904     return NULL_TREE;
2905   if (!specs->declspecs_seen_p)
2906     {
2907       c_parser_error (parser, "expected specifier-qualifier-list");
2908       return NULL_TREE;
2909     }
2910   finish_declspecs (specs);
2911   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2912       || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2913     {
2914       tree ret;
2915       if (specs->typespec_kind == ctsk_none)
2916 	{
2917 	  pedwarn (decl_loc, OPT_Wpedantic,
2918 		   "ISO C forbids member declarations with no members");
2919 	  shadow_tag_warned (specs, pedantic);
2920 	  ret = NULL_TREE;
2921 	}
2922       else
2923 	{
2924 	  /* Support for unnamed structs or unions as members of
2925 	     structs or unions (which is [a] useful and [b] supports
2926 	     MS P-SDK).  */
2927 	  tree attrs = NULL;
2928 
2929 	  ret = grokfield (c_parser_peek_token (parser)->location,
2930 			   build_id_declarator (NULL_TREE), specs,
2931 			   NULL_TREE, &attrs);
2932 	  if (ret)
2933 	    decl_attributes (&ret, attrs, 0);
2934 	}
2935       return ret;
2936     }
2937 
2938   /* Provide better error recovery.  Note that a type name here is valid,
2939      and will be treated as a field name.  */
2940   if (specs->typespec_kind == ctsk_tagdef
2941       && TREE_CODE (specs->type) != ENUMERAL_TYPE
2942       && c_parser_next_token_starts_declspecs (parser)
2943       && !c_parser_next_token_is (parser, CPP_NAME))
2944     {
2945       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2946       parser->error = false;
2947       return NULL_TREE;
2948     }
2949 
2950   pending_xref_error ();
2951   prefix_attrs = specs->attrs;
2952   all_prefix_attrs = prefix_attrs;
2953   specs->attrs = NULL_TREE;
2954   decls = NULL_TREE;
2955   while (true)
2956     {
2957       /* Declaring one or more declarators or un-named bit-fields.  */
2958       struct c_declarator *declarator;
2959       bool dummy = false;
2960       if (c_parser_next_token_is (parser, CPP_COLON))
2961 	declarator = build_id_declarator (NULL_TREE);
2962       else
2963 	declarator = c_parser_declarator (parser,
2964 					  specs->typespec_kind != ctsk_none,
2965 					  C_DTR_NORMAL, &dummy);
2966       if (declarator == NULL)
2967 	{
2968 	  c_parser_skip_to_end_of_block_or_statement (parser);
2969 	  break;
2970 	}
2971       if (c_parser_next_token_is (parser, CPP_COLON)
2972 	  || c_parser_next_token_is (parser, CPP_COMMA)
2973 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
2974 	  || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2975 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2976 	{
2977 	  tree postfix_attrs = NULL_TREE;
2978 	  tree width = NULL_TREE;
2979 	  tree d;
2980 	  if (c_parser_next_token_is (parser, CPP_COLON))
2981 	    {
2982 	      c_parser_consume_token (parser);
2983 	      width = c_parser_expr_no_commas (parser, NULL).value;
2984 	    }
2985 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2986 	    postfix_attrs = c_parser_attributes (parser);
2987 	  d = grokfield (c_parser_peek_token (parser)->location,
2988 			 declarator, specs, width, &all_prefix_attrs);
2989 	  decl_attributes (&d, chainon (postfix_attrs,
2990 					all_prefix_attrs), 0);
2991 	  DECL_CHAIN (d) = decls;
2992 	  decls = d;
2993 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2994 	    all_prefix_attrs = chainon (c_parser_attributes (parser),
2995 					prefix_attrs);
2996 	  else
2997 	    all_prefix_attrs = prefix_attrs;
2998 	  if (c_parser_next_token_is (parser, CPP_COMMA))
2999 	    c_parser_consume_token (parser);
3000 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3001 		   || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3002 	    {
3003 	      /* Semicolon consumed in caller.  */
3004 	      break;
3005 	    }
3006 	  else
3007 	    {
3008 	      c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3009 	      break;
3010 	    }
3011 	}
3012       else
3013 	{
3014 	  c_parser_error (parser,
3015 			  "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3016 			  "%<__attribute__%>");
3017 	  break;
3018 	}
3019     }
3020   return decls;
3021 }
3022 
3023 /* Parse a typeof specifier (a GNU extension).
3024 
3025    typeof-specifier:
3026      typeof ( expression )
3027      typeof ( type-name )
3028 */
3029 
3030 static struct c_typespec
3031 c_parser_typeof_specifier (c_parser *parser)
3032 {
3033   struct c_typespec ret;
3034   ret.kind = ctsk_typeof;
3035   ret.spec = error_mark_node;
3036   ret.expr = NULL_TREE;
3037   ret.expr_const_operands = true;
3038   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3039   c_parser_consume_token (parser);
3040   c_inhibit_evaluation_warnings++;
3041   in_typeof++;
3042   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3043     {
3044       c_inhibit_evaluation_warnings--;
3045       in_typeof--;
3046       return ret;
3047     }
3048   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3049     {
3050       struct c_type_name *type = c_parser_type_name (parser);
3051       c_inhibit_evaluation_warnings--;
3052       in_typeof--;
3053       if (type != NULL)
3054 	{
3055 	  ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3056 	  pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3057 	}
3058     }
3059   else
3060     {
3061       bool was_vm;
3062       location_t here = c_parser_peek_token (parser)->location;
3063       struct c_expr expr = c_parser_expression (parser);
3064       c_inhibit_evaluation_warnings--;
3065       in_typeof--;
3066       if (TREE_CODE (expr.value) == COMPONENT_REF
3067 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3068 	error_at (here, "%<typeof%> applied to a bit-field");
3069       mark_exp_read (expr.value);
3070       ret.spec = TREE_TYPE (expr.value);
3071       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3072       /* This is returned with the type so that when the type is
3073 	 evaluated, this can be evaluated.  */
3074       if (was_vm)
3075 	ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3076       pop_maybe_used (was_vm);
3077       /* For use in macros such as those in <stdatomic.h>, remove all
3078 	 qualifiers from atomic types.  (const can be an issue for more macros
3079 	 using typeof than just the <stdatomic.h> ones.)  */
3080       if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3081 	ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3082     }
3083   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3084   return ret;
3085 }
3086 
3087 /* Parse an alignment-specifier.
3088 
3089    C11 6.7.5:
3090 
3091    alignment-specifier:
3092      _Alignas ( type-name )
3093      _Alignas ( constant-expression )
3094 */
3095 
3096 static tree
3097 c_parser_alignas_specifier (c_parser * parser)
3098 {
3099   tree ret = error_mark_node;
3100   location_t loc = c_parser_peek_token (parser)->location;
3101   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3102   c_parser_consume_token (parser);
3103   if (flag_isoc99)
3104     pedwarn_c99 (loc, OPT_Wpedantic,
3105 		 "ISO C99 does not support %<_Alignas%>");
3106   else
3107     pedwarn_c99 (loc, OPT_Wpedantic,
3108 		 "ISO C90 does not support %<_Alignas%>");
3109   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3110     return ret;
3111   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3112     {
3113       struct c_type_name *type = c_parser_type_name (parser);
3114       if (type != NULL)
3115 	ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3116 					false, true, 1);
3117     }
3118   else
3119     ret = c_parser_expr_no_commas (parser, NULL).value;
3120   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3121   return ret;
3122 }
3123 
3124 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3125    6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
3126    be redeclared; otherwise it may not.  KIND indicates which kind of
3127    declarator is wanted.  Returns a valid declarator except in the
3128    case of a syntax error in which case NULL is returned.  *SEEN_ID is
3129    set to true if an identifier being declared is seen; this is used
3130    to diagnose bad forms of abstract array declarators and to
3131    determine whether an identifier list is syntactically permitted.
3132 
3133    declarator:
3134      pointer[opt] direct-declarator
3135 
3136    direct-declarator:
3137      identifier
3138      ( attributes[opt] declarator )
3139      direct-declarator array-declarator
3140      direct-declarator ( parameter-type-list )
3141      direct-declarator ( identifier-list[opt] )
3142 
3143    pointer:
3144      * type-qualifier-list[opt]
3145      * type-qualifier-list[opt] pointer
3146 
3147    type-qualifier-list:
3148      type-qualifier
3149      attributes
3150      type-qualifier-list type-qualifier
3151      type-qualifier-list attributes
3152 
3153    array-declarator:
3154      [ type-qualifier-list[opt] assignment-expression[opt] ]
3155      [ static type-qualifier-list[opt] assignment-expression ]
3156      [ type-qualifier-list static assignment-expression ]
3157      [ type-qualifier-list[opt] * ]
3158 
3159    parameter-type-list:
3160      parameter-list
3161      parameter-list , ...
3162 
3163    parameter-list:
3164      parameter-declaration
3165      parameter-list , parameter-declaration
3166 
3167    parameter-declaration:
3168      declaration-specifiers declarator attributes[opt]
3169      declaration-specifiers abstract-declarator[opt] attributes[opt]
3170 
3171    identifier-list:
3172      identifier
3173      identifier-list , identifier
3174 
3175    abstract-declarator:
3176      pointer
3177      pointer[opt] direct-abstract-declarator
3178 
3179    direct-abstract-declarator:
3180      ( attributes[opt] abstract-declarator )
3181      direct-abstract-declarator[opt] array-declarator
3182      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3183 
3184    GNU extensions:
3185 
3186    direct-declarator:
3187      direct-declarator ( parameter-forward-declarations
3188 			 parameter-type-list[opt] )
3189 
3190    direct-abstract-declarator:
3191      direct-abstract-declarator[opt] ( parameter-forward-declarations
3192 				       parameter-type-list[opt] )
3193 
3194    parameter-forward-declarations:
3195      parameter-list ;
3196      parameter-forward-declarations parameter-list ;
3197 
3198    The uses of attributes shown above are GNU extensions.
3199 
3200    Some forms of array declarator are not included in C99 in the
3201    syntax for abstract declarators; these are disallowed elsewhere.
3202    This may be a defect (DR#289).
3203 
3204    This function also accepts an omitted abstract declarator as being
3205    an abstract declarator, although not part of the formal syntax.  */
3206 
3207 static struct c_declarator *
3208 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3209 		     bool *seen_id)
3210 {
3211   /* Parse any initial pointer part.  */
3212   if (c_parser_next_token_is (parser, CPP_MULT))
3213     {
3214       struct c_declspecs *quals_attrs = build_null_declspecs ();
3215       struct c_declarator *inner;
3216       c_parser_consume_token (parser);
3217       c_parser_declspecs (parser, quals_attrs, false, false, true,
3218 			  false, false, cla_prefer_id);
3219       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3220       if (inner == NULL)
3221 	return NULL;
3222       else
3223 	return make_pointer_declarator (quals_attrs, inner);
3224     }
3225   /* Now we have a direct declarator, direct abstract declarator or
3226      nothing (which counts as a direct abstract declarator here).  */
3227   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3228 }
3229 
3230 /* Parse a direct declarator or direct abstract declarator; arguments
3231    as c_parser_declarator.  */
3232 
3233 static struct c_declarator *
3234 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3235 			    bool *seen_id)
3236 {
3237   /* The direct declarator must start with an identifier (possibly
3238      omitted) or a parenthesized declarator (possibly abstract).  In
3239      an ordinary declarator, initial parentheses must start a
3240      parenthesized declarator.  In an abstract declarator or parameter
3241      declarator, they could start a parenthesized declarator or a
3242      parameter list.  To tell which, the open parenthesis and any
3243      following attributes must be read.  If a declaration specifier
3244      follows, then it is a parameter list; if the specifier is a
3245      typedef name, there might be an ambiguity about redeclaring it,
3246      which is resolved in the direction of treating it as a typedef
3247      name.  If a close parenthesis follows, it is also an empty
3248      parameter list, as the syntax does not permit empty abstract
3249      declarators.  Otherwise, it is a parenthesized declarator (in
3250      which case the analysis may be repeated inside it, recursively).
3251 
3252      ??? There is an ambiguity in a parameter declaration "int
3253      (__attribute__((foo)) x)", where x is not a typedef name: it
3254      could be an abstract declarator for a function, or declare x with
3255      parentheses.  The proper resolution of this ambiguity needs
3256      documenting.  At present we follow an accident of the old
3257      parser's implementation, whereby the first parameter must have
3258      some declaration specifiers other than just attributes.  Thus as
3259      a parameter declaration it is treated as a parenthesized
3260      parameter named x, and as an abstract declarator it is
3261      rejected.
3262 
3263      ??? Also following the old parser, attributes inside an empty
3264      parameter list are ignored, making it a list not yielding a
3265      prototype, rather than giving an error or making it have one
3266      parameter with implicit type int.
3267 
3268      ??? Also following the old parser, typedef names may be
3269      redeclared in declarators, but not Objective-C class names.  */
3270 
3271   if (kind != C_DTR_ABSTRACT
3272       && c_parser_next_token_is (parser, CPP_NAME)
3273       && ((type_seen_p
3274 	   && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3275 	       || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3276 	  || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3277     {
3278       struct c_declarator *inner
3279 	= build_id_declarator (c_parser_peek_token (parser)->value);
3280       *seen_id = true;
3281       inner->id_loc = c_parser_peek_token (parser)->location;
3282       c_parser_consume_token (parser);
3283       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3284     }
3285 
3286   if (kind != C_DTR_NORMAL
3287       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3288     {
3289       struct c_declarator *inner = build_id_declarator (NULL_TREE);
3290       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3291     }
3292 
3293   /* Either we are at the end of an abstract declarator, or we have
3294      parentheses.  */
3295 
3296   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3297     {
3298       tree attrs;
3299       struct c_declarator *inner;
3300       c_parser_consume_token (parser);
3301       attrs = c_parser_attributes (parser);
3302       if (kind != C_DTR_NORMAL
3303 	  && (c_parser_next_token_starts_declspecs (parser)
3304 	      || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3305 	{
3306 	  struct c_arg_info *args
3307 	    = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3308 					 attrs);
3309 	  if (args == NULL)
3310 	    return NULL;
3311 	  else
3312 	    {
3313 	      inner
3314 		= build_function_declarator (args,
3315 					     build_id_declarator (NULL_TREE));
3316 	      return c_parser_direct_declarator_inner (parser, *seen_id,
3317 						       inner);
3318 	    }
3319 	}
3320       /* A parenthesized declarator.  */
3321       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3322       if (inner != NULL && attrs != NULL)
3323 	inner = build_attrs_declarator (attrs, inner);
3324       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3325 	{
3326 	  c_parser_consume_token (parser);
3327 	  if (inner == NULL)
3328 	    return NULL;
3329 	  else
3330 	    return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3331 	}
3332       else
3333 	{
3334 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3335 				     "expected %<)%>");
3336 	  return NULL;
3337 	}
3338     }
3339   else
3340     {
3341       if (kind == C_DTR_NORMAL)
3342 	{
3343 	  c_parser_error (parser, "expected identifier or %<(%>");
3344 	  return NULL;
3345 	}
3346       else
3347 	return build_id_declarator (NULL_TREE);
3348     }
3349 }
3350 
3351 /* Parse part of a direct declarator or direct abstract declarator,
3352    given that some (in INNER) has already been parsed; ID_PRESENT is
3353    true if an identifier is present, false for an abstract
3354    declarator.  */
3355 
3356 static struct c_declarator *
3357 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3358 				  struct c_declarator *inner)
3359 {
3360   /* Parse a sequence of array declarators and parameter lists.  */
3361   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3362     {
3363       location_t brace_loc = c_parser_peek_token (parser)->location;
3364       struct c_declarator *declarator;
3365       struct c_declspecs *quals_attrs = build_null_declspecs ();
3366       bool static_seen;
3367       bool star_seen;
3368       struct c_expr dimen;
3369       dimen.value = NULL_TREE;
3370       dimen.original_code = ERROR_MARK;
3371       dimen.original_type = NULL_TREE;
3372       c_parser_consume_token (parser);
3373       c_parser_declspecs (parser, quals_attrs, false, false, true,
3374 			  false, false, cla_prefer_id);
3375       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3376       if (static_seen)
3377 	c_parser_consume_token (parser);
3378       if (static_seen && !quals_attrs->declspecs_seen_p)
3379 	c_parser_declspecs (parser, quals_attrs, false, false, true,
3380 			    false, false, cla_prefer_id);
3381       if (!quals_attrs->declspecs_seen_p)
3382 	quals_attrs = NULL;
3383       /* If "static" is present, there must be an array dimension.
3384 	 Otherwise, there may be a dimension, "*", or no
3385 	 dimension.  */
3386       if (static_seen)
3387 	{
3388 	  star_seen = false;
3389 	  dimen = c_parser_expr_no_commas (parser, NULL);
3390 	}
3391       else
3392 	{
3393 	  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3394 	    {
3395 	      dimen.value = NULL_TREE;
3396 	      star_seen = false;
3397 	    }
3398 	  else if (flag_cilkplus
3399 		   && c_parser_next_token_is (parser, CPP_COLON))
3400 	    {
3401 	      dimen.value = error_mark_node;
3402 	      star_seen = false;
3403 	      error_at (c_parser_peek_token (parser)->location,
3404 			"array notations cannot be used in declaration");
3405 	      c_parser_consume_token (parser);
3406 	    }
3407 	  else if (c_parser_next_token_is (parser, CPP_MULT))
3408 	    {
3409 	      if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3410 		{
3411 		  dimen.value = NULL_TREE;
3412 		  star_seen = true;
3413 		  c_parser_consume_token (parser);
3414 		}
3415 	      else
3416 		{
3417 		  star_seen = false;
3418 		  dimen = c_parser_expr_no_commas (parser, NULL);
3419 		}
3420 	    }
3421 	  else
3422 	    {
3423 	      star_seen = false;
3424 	      dimen = c_parser_expr_no_commas (parser, NULL);
3425 	    }
3426 	}
3427       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3428 	c_parser_consume_token (parser);
3429       else if (flag_cilkplus
3430 	       && c_parser_next_token_is (parser, CPP_COLON))
3431 	{
3432 	  error_at (c_parser_peek_token (parser)->location,
3433 		    "array notations cannot be used in declaration");
3434 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
3435 	  return NULL;
3436 	}
3437       else
3438 	{
3439 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3440 				     "expected %<]%>");
3441 	  return NULL;
3442 	}
3443       if (dimen.value)
3444 	dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3445       declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3446 					   static_seen, star_seen);
3447       if (declarator == NULL)
3448 	return NULL;
3449       inner = set_array_declarator_inner (declarator, inner);
3450       return c_parser_direct_declarator_inner (parser, id_present, inner);
3451     }
3452   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3453     {
3454       tree attrs;
3455       struct c_arg_info *args;
3456       c_parser_consume_token (parser);
3457       attrs = c_parser_attributes (parser);
3458       args = c_parser_parms_declarator (parser, id_present, attrs);
3459       if (args == NULL)
3460 	return NULL;
3461       else
3462 	{
3463 	  inner = build_function_declarator (args, inner);
3464 	  return c_parser_direct_declarator_inner (parser, id_present, inner);
3465 	}
3466     }
3467   return inner;
3468 }
3469 
3470 /* Parse a parameter list or identifier list, including the closing
3471    parenthesis but not the opening one.  ATTRS are the attributes at
3472    the start of the list.  ID_LIST_OK is true if an identifier list is
3473    acceptable; such a list must not have attributes at the start.  */
3474 
3475 static struct c_arg_info *
3476 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3477 {
3478   push_scope ();
3479   declare_parm_level ();
3480   /* If the list starts with an identifier, it is an identifier list.
3481      Otherwise, it is either a prototype list or an empty list.  */
3482   if (id_list_ok
3483       && !attrs
3484       && c_parser_next_token_is (parser, CPP_NAME)
3485       && c_parser_peek_token (parser)->id_kind == C_ID_ID
3486 
3487       /* Look ahead to detect typos in type names.  */
3488       && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3489       && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3490       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3491       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3492     {
3493       tree list = NULL_TREE, *nextp = &list;
3494       while (c_parser_next_token_is (parser, CPP_NAME)
3495 	     && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3496 	{
3497 	  *nextp = build_tree_list (NULL_TREE,
3498 				    c_parser_peek_token (parser)->value);
3499 	  nextp = & TREE_CHAIN (*nextp);
3500 	  c_parser_consume_token (parser);
3501 	  if (c_parser_next_token_is_not (parser, CPP_COMMA))
3502 	    break;
3503 	  c_parser_consume_token (parser);
3504 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3505 	    {
3506 	      c_parser_error (parser, "expected identifier");
3507 	      break;
3508 	    }
3509 	}
3510       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3511 	{
3512 	  struct c_arg_info *ret = build_arg_info ();
3513 	  ret->types = list;
3514 	  c_parser_consume_token (parser);
3515 	  pop_scope ();
3516 	  return ret;
3517 	}
3518       else
3519 	{
3520 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3521 				     "expected %<)%>");
3522 	  pop_scope ();
3523 	  return NULL;
3524 	}
3525     }
3526   else
3527     {
3528       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3529 							       NULL);
3530       pop_scope ();
3531       return ret;
3532     }
3533 }
3534 
3535 /* Parse a parameter list (possibly empty), including the closing
3536    parenthesis but not the opening one.  ATTRS are the attributes at
3537    the start of the list.  EXPR is NULL or an expression that needs to
3538    be evaluated for the side effects of array size expressions in the
3539    parameters.  */
3540 
3541 static struct c_arg_info *
3542 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3543 {
3544   bool bad_parm = false;
3545 
3546   /* ??? Following the old parser, forward parameter declarations may
3547      use abstract declarators, and if no real parameter declarations
3548      follow the forward declarations then this is not diagnosed.  Also
3549      note as above that attributes are ignored as the only contents of
3550      the parentheses, or as the only contents after forward
3551      declarations.  */
3552   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3553     {
3554       struct c_arg_info *ret = build_arg_info ();
3555       c_parser_consume_token (parser);
3556       return ret;
3557     }
3558   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3559     {
3560       struct c_arg_info *ret = build_arg_info ();
3561 
3562       if (flag_allow_parameterless_variadic_functions)
3563         {
3564           /* F (...) is allowed.  */
3565           ret->types = NULL_TREE;
3566         }
3567       else
3568         {
3569           /* Suppress -Wold-style-definition for this case.  */
3570           ret->types = error_mark_node;
3571           error_at (c_parser_peek_token (parser)->location,
3572                     "ISO C requires a named argument before %<...%>");
3573         }
3574       c_parser_consume_token (parser);
3575       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3576 	{
3577 	  c_parser_consume_token (parser);
3578 	  return ret;
3579 	}
3580       else
3581 	{
3582 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3583 				     "expected %<)%>");
3584 	  return NULL;
3585 	}
3586     }
3587   /* Nonempty list of parameters, either terminated with semicolon
3588      (forward declarations; recurse) or with close parenthesis (normal
3589      function) or with ", ... )" (variadic function).  */
3590   while (true)
3591     {
3592       /* Parse a parameter.  */
3593       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3594       attrs = NULL_TREE;
3595       if (parm == NULL)
3596 	bad_parm = true;
3597       else
3598 	push_parm_decl (parm, &expr);
3599       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3600 	{
3601 	  tree new_attrs;
3602 	  c_parser_consume_token (parser);
3603 	  mark_forward_parm_decls ();
3604 	  new_attrs = c_parser_attributes (parser);
3605 	  return c_parser_parms_list_declarator (parser, new_attrs, expr);
3606 	}
3607       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3608 	{
3609 	  c_parser_consume_token (parser);
3610 	  if (bad_parm)
3611 	    return NULL;
3612 	  else
3613 	    return get_parm_info (false, expr);
3614 	}
3615       if (!c_parser_require (parser, CPP_COMMA,
3616 			     "expected %<;%>, %<,%> or %<)%>"))
3617 	{
3618 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3619 	  return NULL;
3620 	}
3621       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3622 	{
3623 	  c_parser_consume_token (parser);
3624 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3625 	    {
3626 	      c_parser_consume_token (parser);
3627 	      if (bad_parm)
3628 		return NULL;
3629 	      else
3630 		return get_parm_info (true, expr);
3631 	    }
3632 	  else
3633 	    {
3634 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3635 					 "expected %<)%>");
3636 	      return NULL;
3637 	    }
3638 	}
3639     }
3640 }
3641 
3642 /* Parse a parameter declaration.  ATTRS are the attributes at the
3643    start of the declaration if it is the first parameter.  */
3644 
3645 static struct c_parm *
3646 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3647 {
3648   struct c_declspecs *specs;
3649   struct c_declarator *declarator;
3650   tree prefix_attrs;
3651   tree postfix_attrs = NULL_TREE;
3652   bool dummy = false;
3653 
3654   /* Accept #pragmas between parameter declarations.  */
3655   while (c_parser_next_token_is (parser, CPP_PRAGMA))
3656     c_parser_pragma (parser, pragma_param);
3657 
3658   if (!c_parser_next_token_starts_declspecs (parser))
3659     {
3660       c_token *token = c_parser_peek_token (parser);
3661       if (parser->error)
3662 	return NULL;
3663       c_parser_set_source_position_from_token (token);
3664       if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3665 	{
3666 	  error_at (token->location, "unknown type name %qE", token->value);
3667 	  parser->error = true;
3668 	}
3669       /* ??? In some Objective-C cases '...' isn't applicable so there
3670 	 should be a different message.  */
3671       else
3672 	c_parser_error (parser,
3673 			"expected declaration specifiers or %<...%>");
3674       c_parser_skip_to_end_of_parameter (parser);
3675       return NULL;
3676     }
3677   specs = build_null_declspecs ();
3678   if (attrs)
3679     {
3680       declspecs_add_attrs (input_location, specs, attrs);
3681       attrs = NULL_TREE;
3682     }
3683   c_parser_declspecs (parser, specs, true, true, true, true, false,
3684 		      cla_nonabstract_decl);
3685   finish_declspecs (specs);
3686   pending_xref_error ();
3687   prefix_attrs = specs->attrs;
3688   specs->attrs = NULL_TREE;
3689   declarator = c_parser_declarator (parser,
3690 				    specs->typespec_kind != ctsk_none,
3691 				    C_DTR_PARM, &dummy);
3692   if (declarator == NULL)
3693     {
3694       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3695       return NULL;
3696     }
3697   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3698     postfix_attrs = c_parser_attributes (parser);
3699   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3700 		       declarator);
3701 }
3702 
3703 /* Parse a string literal in an asm expression.  It should not be
3704    translated, and wide string literals are an error although
3705    permitted by the syntax.  This is a GNU extension.
3706 
3707    asm-string-literal:
3708      string-literal
3709 
3710    ??? At present, following the old parser, the caller needs to have
3711    set lex_untranslated_string to 1.  It would be better to follow the
3712    C++ parser rather than using this kludge.  */
3713 
3714 static tree
3715 c_parser_asm_string_literal (c_parser *parser)
3716 {
3717   tree str;
3718   int save_flag = warn_overlength_strings;
3719   warn_overlength_strings = 0;
3720   if (c_parser_next_token_is (parser, CPP_STRING))
3721     {
3722       str = c_parser_peek_token (parser)->value;
3723       c_parser_consume_token (parser);
3724     }
3725   else if (c_parser_next_token_is (parser, CPP_WSTRING))
3726     {
3727       error_at (c_parser_peek_token (parser)->location,
3728 		"wide string literal in %<asm%>");
3729       str = build_string (1, "");
3730       c_parser_consume_token (parser);
3731     }
3732   else
3733     {
3734       c_parser_error (parser, "expected string literal");
3735       str = NULL_TREE;
3736     }
3737   warn_overlength_strings = save_flag;
3738   return str;
3739 }
3740 
3741 /* Parse a simple asm expression.  This is used in restricted
3742    contexts, where a full expression with inputs and outputs does not
3743    make sense.  This is a GNU extension.
3744 
3745    simple-asm-expr:
3746      asm ( asm-string-literal )
3747 */
3748 
3749 static tree
3750 c_parser_simple_asm_expr (c_parser *parser)
3751 {
3752   tree str;
3753   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3754   /* ??? Follow the C++ parser rather than using the
3755      lex_untranslated_string kludge.  */
3756   parser->lex_untranslated_string = true;
3757   c_parser_consume_token (parser);
3758   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3759     {
3760       parser->lex_untranslated_string = false;
3761       return NULL_TREE;
3762     }
3763   str = c_parser_asm_string_literal (parser);
3764   parser->lex_untranslated_string = false;
3765   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3766     {
3767       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3768       return NULL_TREE;
3769     }
3770   return str;
3771 }
3772 
3773 static tree
3774 c_parser_attribute_any_word (c_parser *parser)
3775 {
3776   tree attr_name = NULL_TREE;
3777 
3778   if (c_parser_next_token_is (parser, CPP_KEYWORD))
3779     {
3780       /* ??? See comment above about what keywords are accepted here.  */
3781       bool ok;
3782       switch (c_parser_peek_token (parser)->keyword)
3783 	{
3784 	case RID_STATIC:
3785 	case RID_UNSIGNED:
3786 	case RID_LONG:
3787 	case RID_CONST:
3788 	case RID_EXTERN:
3789 	case RID_REGISTER:
3790 	case RID_TYPEDEF:
3791 	case RID_SHORT:
3792 	case RID_INLINE:
3793 	case RID_NORETURN:
3794 	case RID_VOLATILE:
3795 	case RID_SIGNED:
3796 	case RID_AUTO:
3797 	case RID_RESTRICT:
3798 	case RID_COMPLEX:
3799 	case RID_THREAD:
3800 	case RID_INT:
3801 	case RID_CHAR:
3802 	case RID_FLOAT:
3803 	case RID_DOUBLE:
3804 	case RID_VOID:
3805 	case RID_DFLOAT32:
3806 	case RID_DFLOAT64:
3807 	case RID_DFLOAT128:
3808 	case RID_BOOL:
3809 	case RID_FRACT:
3810 	case RID_ACCUM:
3811 	case RID_SAT:
3812 	case RID_TRANSACTION_ATOMIC:
3813 	case RID_TRANSACTION_CANCEL:
3814 	case RID_ATOMIC:
3815 	case RID_AUTO_TYPE:
3816 	case RID_INT_N_0:
3817 	case RID_INT_N_1:
3818 	case RID_INT_N_2:
3819 	case RID_INT_N_3:
3820 	  ok = true;
3821 	  break;
3822 	default:
3823 	  ok = false;
3824 	  break;
3825 	}
3826       if (!ok)
3827 	return NULL_TREE;
3828 
3829       /* Accept __attribute__((__const)) as __attribute__((const)) etc.  */
3830       attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3831     }
3832   else if (c_parser_next_token_is (parser, CPP_NAME))
3833     attr_name = c_parser_peek_token (parser)->value;
3834 
3835   return attr_name;
3836 }
3837 
3838 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3839    "__vector" or "__vector__."  */
3840 
3841 static inline bool
3842 is_cilkplus_vector_p (tree name)
3843 {
3844   if (flag_cilkplus && is_attribute_p ("vector", name))
3845     return true;
3846   return false;
3847 }
3848 
3849 #define CILK_SIMD_FN_CLAUSE_MASK				  \
3850 	((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH)	  \
3851 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR)	  \
3852 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM)	  \
3853 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK)	  \
3854 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3855 
3856 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3857    VEC_TOKEN is the "vector" token that is replaced with "simd" and
3858    pushed into the token list.
3859    Syntax:
3860    vector
3861    vector (<vector attributes>).  */
3862 
3863 static void
3864 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token)
3865 {
3866   gcc_assert (is_cilkplus_vector_p (vec_token.value));
3867 
3868   int paren_scope = 0;
3869   vec_safe_push (parser->cilk_simd_fn_tokens, vec_token);
3870   /* Consume the "vector" token.  */
3871   c_parser_consume_token (parser);
3872 
3873   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3874     {
3875       c_parser_consume_token (parser);
3876       paren_scope++;
3877     }
3878   while (paren_scope > 0)
3879     {
3880       c_token *token = c_parser_peek_token (parser);
3881       if (token->type == CPP_OPEN_PAREN)
3882         paren_scope++;
3883       else if (token->type == CPP_CLOSE_PAREN)
3884         paren_scope--;
3885       /* Do not push the last ')' since we are not pushing the '('.  */
3886       if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0))
3887 	vec_safe_push (parser->cilk_simd_fn_tokens, *token);
3888       c_parser_consume_token (parser);
3889     }
3890 
3891   /* Since we are converting an attribute to a pragma, we need to end the
3892      attribute with PRAGMA_EOL.  */
3893   c_token eol_token;
3894   memset (&eol_token, 0, sizeof (eol_token));
3895   eol_token.type = CPP_PRAGMA_EOL;
3896   vec_safe_push (parser->cilk_simd_fn_tokens, eol_token);
3897 }
3898 
3899 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector.  */
3900 
3901 static void
3902 c_finish_cilk_simd_fn_tokens (c_parser *parser)
3903 {
3904   c_token last_token = parser->cilk_simd_fn_tokens->last ();
3905 
3906   /* c_parser_attributes is called in several places, so if these EOF
3907      tokens are already inserted, then don't do them again.  */
3908   if (last_token.type == CPP_EOF)
3909     return;
3910 
3911   /* Two CPP_EOF token are added as a safety net since the normal C
3912      front-end has two token look-ahead.  */
3913   c_token eof_token;
3914   eof_token.type = CPP_EOF;
3915   vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3916   vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3917 }
3918 
3919 /* Parse (possibly empty) attributes.  This is a GNU extension.
3920 
3921    attributes:
3922      empty
3923      attributes attribute
3924 
3925    attribute:
3926      __attribute__ ( ( attribute-list ) )
3927 
3928    attribute-list:
3929      attrib
3930      attribute_list , attrib
3931 
3932    attrib:
3933      empty
3934      any-word
3935      any-word ( identifier )
3936      any-word ( identifier , nonempty-expr-list )
3937      any-word ( expr-list )
3938 
3939    where the "identifier" must not be declared as a type, and
3940    "any-word" may be any identifier (including one declared as a
3941    type), a reserved word storage class specifier, type specifier or
3942    type qualifier.  ??? This still leaves out most reserved keywords
3943    (following the old parser), shouldn't we include them, and why not
3944    allow identifiers declared as types to start the arguments?  */
3945 
3946 static tree
3947 c_parser_attributes (c_parser *parser)
3948 {
3949   tree attrs = NULL_TREE;
3950   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3951     {
3952       /* ??? Follow the C++ parser rather than using the
3953 	 lex_untranslated_string kludge.  */
3954       parser->lex_untranslated_string = true;
3955       c_parser_consume_token (parser);
3956       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3957 	{
3958 	  parser->lex_untranslated_string = false;
3959 	  return attrs;
3960 	}
3961       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3962 	{
3963 	  parser->lex_untranslated_string = false;
3964 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3965 	  return attrs;
3966 	}
3967       /* Parse the attribute list.  */
3968       while (c_parser_next_token_is (parser, CPP_COMMA)
3969 	     || c_parser_next_token_is (parser, CPP_NAME)
3970 	     || c_parser_next_token_is (parser, CPP_KEYWORD))
3971 	{
3972 	  tree attr, attr_name, attr_args;
3973 	  vec<tree, va_gc> *expr_list;
3974 	  if (c_parser_next_token_is (parser, CPP_COMMA))
3975 	    {
3976 	      c_parser_consume_token (parser);
3977 	      continue;
3978 	    }
3979 
3980 	  attr_name = c_parser_attribute_any_word (parser);
3981 	  if (attr_name == NULL)
3982 	    break;
3983 	  if (is_cilkplus_vector_p (attr_name))
3984 	    {
3985 	      c_token *v_token = c_parser_peek_token (parser);
3986 	      c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
3987 	      continue;
3988 	    }
3989 	  c_parser_consume_token (parser);
3990 	  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3991 	    {
3992 	      attr = build_tree_list (attr_name, NULL_TREE);
3993 	      attrs = chainon (attrs, attr);
3994 	      continue;
3995 	    }
3996 	  c_parser_consume_token (parser);
3997 	  /* Parse the attribute contents.  If they start with an
3998 	     identifier which is followed by a comma or close
3999 	     parenthesis, then the arguments start with that
4000 	     identifier; otherwise they are an expression list.
4001 	     In objective-c the identifier may be a classname.  */
4002 	  if (c_parser_next_token_is (parser, CPP_NAME)
4003 	      && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4004 		  || (c_dialect_objc ()
4005 		      && c_parser_peek_token (parser)->id_kind
4006 			 == C_ID_CLASSNAME))
4007 	      && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4008 		  || (c_parser_peek_2nd_token (parser)->type
4009 		      == CPP_CLOSE_PAREN))
4010 	      && (attribute_takes_identifier_p (attr_name)
4011 		  || (c_dialect_objc ()
4012 		      && c_parser_peek_token (parser)->id_kind
4013 			 == C_ID_CLASSNAME)))
4014 	    {
4015 	      tree arg1 = c_parser_peek_token (parser)->value;
4016 	      c_parser_consume_token (parser);
4017 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4018 		attr_args = build_tree_list (NULL_TREE, arg1);
4019 	      else
4020 		{
4021 		  tree tree_list;
4022 		  c_parser_consume_token (parser);
4023 		  expr_list = c_parser_expr_list (parser, false, true,
4024 						  NULL, NULL, NULL, NULL);
4025 		  tree_list = build_tree_list_vec (expr_list);
4026 		  attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4027 		  release_tree_vector (expr_list);
4028 		}
4029 	    }
4030 	  else
4031 	    {
4032 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4033 		attr_args = NULL_TREE;
4034 	      else
4035 		{
4036 		  expr_list = c_parser_expr_list (parser, false, true,
4037 						  NULL, NULL, NULL, NULL);
4038 		  attr_args = build_tree_list_vec (expr_list);
4039 		  release_tree_vector (expr_list);
4040 		}
4041 	    }
4042 	  attr = build_tree_list (attr_name, attr_args);
4043 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4044 	    c_parser_consume_token (parser);
4045 	  else
4046 	    {
4047 	      parser->lex_untranslated_string = false;
4048 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4049 					 "expected %<)%>");
4050 	      return attrs;
4051 	    }
4052 	  attrs = chainon (attrs, attr);
4053 	}
4054       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4055 	c_parser_consume_token (parser);
4056       else
4057 	{
4058 	  parser->lex_untranslated_string = false;
4059 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4060 				     "expected %<)%>");
4061 	  return attrs;
4062 	}
4063       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4064 	c_parser_consume_token (parser);
4065       else
4066 	{
4067 	  parser->lex_untranslated_string = false;
4068 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4069 				     "expected %<)%>");
4070 	  return attrs;
4071 	}
4072       parser->lex_untranslated_string = false;
4073     }
4074 
4075   if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
4076     c_finish_cilk_simd_fn_tokens (parser);
4077   return attrs;
4078 }
4079 
4080 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4081 
4082    type-name:
4083      specifier-qualifier-list abstract-declarator[opt]
4084 */
4085 
4086 static struct c_type_name *
4087 c_parser_type_name (c_parser *parser)
4088 {
4089   struct c_declspecs *specs = build_null_declspecs ();
4090   struct c_declarator *declarator;
4091   struct c_type_name *ret;
4092   bool dummy = false;
4093   c_parser_declspecs (parser, specs, false, true, true, false, false,
4094 		      cla_prefer_type);
4095   if (!specs->declspecs_seen_p)
4096     {
4097       c_parser_error (parser, "expected specifier-qualifier-list");
4098       return NULL;
4099     }
4100   if (specs->type != error_mark_node)
4101     {
4102       pending_xref_error ();
4103       finish_declspecs (specs);
4104     }
4105   declarator = c_parser_declarator (parser,
4106 				    specs->typespec_kind != ctsk_none,
4107 				    C_DTR_ABSTRACT, &dummy);
4108   if (declarator == NULL)
4109     return NULL;
4110   ret = XOBNEW (&parser_obstack, struct c_type_name);
4111   ret->specs = specs;
4112   ret->declarator = declarator;
4113   return ret;
4114 }
4115 
4116 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4117 
4118    initializer:
4119      assignment-expression
4120      { initializer-list }
4121      { initializer-list , }
4122 
4123    initializer-list:
4124      designation[opt] initializer
4125      initializer-list , designation[opt] initializer
4126 
4127    designation:
4128      designator-list =
4129 
4130    designator-list:
4131      designator
4132      designator-list designator
4133 
4134    designator:
4135      array-designator
4136      . identifier
4137 
4138    array-designator:
4139      [ constant-expression ]
4140 
4141    GNU extensions:
4142 
4143    initializer:
4144      { }
4145 
4146    designation:
4147      array-designator
4148      identifier :
4149 
4150    array-designator:
4151      [ constant-expression ... constant-expression ]
4152 
4153    Any expression without commas is accepted in the syntax for the
4154    constant-expressions, with non-constant expressions rejected later.
4155 
4156    This function is only used for top-level initializers; for nested
4157    ones, see c_parser_initval.  */
4158 
4159 static struct c_expr
4160 c_parser_initializer (c_parser *parser)
4161 {
4162   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4163     return c_parser_braced_init (parser, NULL_TREE, false, NULL);
4164   else
4165     {
4166       struct c_expr ret;
4167       location_t loc = c_parser_peek_token (parser)->location;
4168       ret = c_parser_expr_no_commas (parser, NULL);
4169       if (TREE_CODE (ret.value) != STRING_CST
4170 	  && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4171 	ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4172       return ret;
4173     }
4174 }
4175 
4176 /* Parse a braced initializer list.  TYPE is the type specified for a
4177    compound literal, and NULL_TREE for other initializers and for
4178    nested braced lists.  NESTED_P is true for nested braced lists,
4179    false for the list of a compound literal or the list that is the
4180    top-level initializer in a declaration.  */
4181 
4182 static struct c_expr
4183 c_parser_braced_init (c_parser *parser, tree type, bool nested_p,
4184 		      struct obstack *outer_obstack)
4185 {
4186   struct c_expr ret;
4187   struct obstack braced_init_obstack;
4188   location_t brace_loc = c_parser_peek_token (parser)->location;
4189   gcc_obstack_init (&braced_init_obstack);
4190   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4191   c_parser_consume_token (parser);
4192   if (nested_p)
4193     {
4194       finish_implicit_inits (brace_loc, outer_obstack);
4195       push_init_level (brace_loc, 0, &braced_init_obstack);
4196     }
4197   else
4198     really_start_incremental_init (type);
4199   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4200     {
4201       pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4202     }
4203   else
4204     {
4205       /* Parse a non-empty initializer list, possibly with a trailing
4206 	 comma.  */
4207       while (true)
4208 	{
4209 	  c_parser_initelt (parser, &braced_init_obstack);
4210 	  if (parser->error)
4211 	    break;
4212 	  if (c_parser_next_token_is (parser, CPP_COMMA))
4213 	    c_parser_consume_token (parser);
4214 	  else
4215 	    break;
4216 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4217 	    break;
4218 	}
4219     }
4220   if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4221     {
4222       ret.value = error_mark_node;
4223       ret.original_code = ERROR_MARK;
4224       ret.original_type = NULL;
4225       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
4226       pop_init_level (brace_loc, 0, &braced_init_obstack);
4227       obstack_free (&braced_init_obstack, NULL);
4228       return ret;
4229     }
4230   c_parser_consume_token (parser);
4231   ret = pop_init_level (brace_loc, 0, &braced_init_obstack);
4232   obstack_free (&braced_init_obstack, NULL);
4233   return ret;
4234 }
4235 
4236 /* Parse a nested initializer, including designators.  */
4237 
4238 static void
4239 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4240 {
4241   /* Parse any designator or designator list.  A single array
4242      designator may have the subsequent "=" omitted in GNU C, but a
4243      longer list or a structure member designator may not.  */
4244   if (c_parser_next_token_is (parser, CPP_NAME)
4245       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4246     {
4247       /* Old-style structure member designator.  */
4248       set_init_label (c_parser_peek_token (parser)->location,
4249 		      c_parser_peek_token (parser)->value,
4250 		      braced_init_obstack);
4251       /* Use the colon as the error location.  */
4252       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4253 	       "obsolete use of designated initializer with %<:%>");
4254       c_parser_consume_token (parser);
4255       c_parser_consume_token (parser);
4256     }
4257   else
4258     {
4259       /* des_seen is 0 if there have been no designators, 1 if there
4260 	 has been a single array designator and 2 otherwise.  */
4261       int des_seen = 0;
4262       /* Location of a designator.  */
4263       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4264       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4265 	     || c_parser_next_token_is (parser, CPP_DOT))
4266 	{
4267 	  int des_prev = des_seen;
4268 	  if (!des_seen)
4269 	    des_loc = c_parser_peek_token (parser)->location;
4270 	  if (des_seen < 2)
4271 	    des_seen++;
4272 	  if (c_parser_next_token_is (parser, CPP_DOT))
4273 	    {
4274 	      des_seen = 2;
4275 	      c_parser_consume_token (parser);
4276 	      if (c_parser_next_token_is (parser, CPP_NAME))
4277 		{
4278 		  set_init_label (des_loc, c_parser_peek_token (parser)->value,
4279 				  braced_init_obstack);
4280 		  c_parser_consume_token (parser);
4281 		}
4282 	      else
4283 		{
4284 		  struct c_expr init;
4285 		  init.value = error_mark_node;
4286 		  init.original_code = ERROR_MARK;
4287 		  init.original_type = NULL;
4288 		  c_parser_error (parser, "expected identifier");
4289 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4290 		  process_init_element (input_location, init, false,
4291 					braced_init_obstack);
4292 		  return;
4293 		}
4294 	    }
4295 	  else
4296 	    {
4297 	      tree first, second;
4298 	      location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4299 	      location_t array_index_loc = UNKNOWN_LOCATION;
4300 	      /* ??? Following the old parser, [ objc-receiver
4301 		 objc-message-args ] is accepted as an initializer,
4302 		 being distinguished from a designator by what follows
4303 		 the first assignment expression inside the square
4304 		 brackets, but after a first array designator a
4305 		 subsequent square bracket is for Objective-C taken to
4306 		 start an expression, using the obsolete form of
4307 		 designated initializer without '=', rather than
4308 		 possibly being a second level of designation: in LALR
4309 		 terms, the '[' is shifted rather than reducing
4310 		 designator to designator-list.  */
4311 	      if (des_prev == 1 && c_dialect_objc ())
4312 		{
4313 		  des_seen = des_prev;
4314 		  break;
4315 		}
4316 	      if (des_prev == 0 && c_dialect_objc ())
4317 		{
4318 		  /* This might be an array designator or an
4319 		     Objective-C message expression.  If the former,
4320 		     continue parsing here; if the latter, parse the
4321 		     remainder of the initializer given the starting
4322 		     primary-expression.  ??? It might make sense to
4323 		     distinguish when des_prev == 1 as well; see
4324 		     previous comment.  */
4325 		  tree rec, args;
4326 		  struct c_expr mexpr;
4327 		  c_parser_consume_token (parser);
4328 		  if (c_parser_peek_token (parser)->type == CPP_NAME
4329 		      && ((c_parser_peek_token (parser)->id_kind
4330 			   == C_ID_TYPENAME)
4331 			  || (c_parser_peek_token (parser)->id_kind
4332 			      == C_ID_CLASSNAME)))
4333 		    {
4334 		      /* Type name receiver.  */
4335 		      tree id = c_parser_peek_token (parser)->value;
4336 		      c_parser_consume_token (parser);
4337 		      rec = objc_get_class_reference (id);
4338 		      goto parse_message_args;
4339 		    }
4340 		  first = c_parser_expr_no_commas (parser, NULL).value;
4341 		  mark_exp_read (first);
4342 		  if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4343 		      || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4344 		    goto array_desig_after_first;
4345 		  /* Expression receiver.  So far only one part
4346 		     without commas has been parsed; there might be
4347 		     more of the expression.  */
4348 		  rec = first;
4349 		  while (c_parser_next_token_is (parser, CPP_COMMA))
4350 		    {
4351 		      struct c_expr next;
4352 		      location_t comma_loc, exp_loc;
4353 		      comma_loc = c_parser_peek_token (parser)->location;
4354 		      c_parser_consume_token (parser);
4355 		      exp_loc = c_parser_peek_token (parser)->location;
4356 		      next = c_parser_expr_no_commas (parser, NULL);
4357 		      next = convert_lvalue_to_rvalue (exp_loc, next,
4358 						       true, true);
4359 		      rec = build_compound_expr (comma_loc, rec, next.value);
4360 		    }
4361 		parse_message_args:
4362 		  /* Now parse the objc-message-args.  */
4363 		  args = c_parser_objc_message_args (parser);
4364 		  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4365 					     "expected %<]%>");
4366 		  mexpr.value
4367 		    = objc_build_message_expr (rec, args);
4368 		  mexpr.original_code = ERROR_MARK;
4369 		  mexpr.original_type = NULL;
4370 		  /* Now parse and process the remainder of the
4371 		     initializer, starting with this message
4372 		     expression as a primary-expression.  */
4373 		  c_parser_initval (parser, &mexpr, braced_init_obstack);
4374 		  return;
4375 		}
4376 	      c_parser_consume_token (parser);
4377 	      array_index_loc = c_parser_peek_token (parser)->location;
4378 	      first = c_parser_expr_no_commas (parser, NULL).value;
4379 	      mark_exp_read (first);
4380 	    array_desig_after_first:
4381 	      if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4382 		{
4383 		  ellipsis_loc = c_parser_peek_token (parser)->location;
4384 		  c_parser_consume_token (parser);
4385 		  second = c_parser_expr_no_commas (parser, NULL).value;
4386 		  mark_exp_read (second);
4387 		}
4388 	      else
4389 		second = NULL_TREE;
4390 	      if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4391 		{
4392 		  c_parser_consume_token (parser);
4393 		  set_init_index (array_index_loc, first, second,
4394 				  braced_init_obstack);
4395 		  if (second)
4396 		    pedwarn (ellipsis_loc, OPT_Wpedantic,
4397 			     "ISO C forbids specifying range of elements to initialize");
4398 		}
4399 	      else
4400 		c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4401 					   "expected %<]%>");
4402 	    }
4403 	}
4404       if (des_seen >= 1)
4405 	{
4406 	  if (c_parser_next_token_is (parser, CPP_EQ))
4407 	    {
4408 	      pedwarn_c90 (des_loc, OPT_Wpedantic,
4409 			   "ISO C90 forbids specifying subobject "
4410 			   "to initialize");
4411 	      c_parser_consume_token (parser);
4412 	    }
4413 	  else
4414 	    {
4415 	      if (des_seen == 1)
4416 		pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4417 			 "obsolete use of designated initializer without %<=%>");
4418 	      else
4419 		{
4420 		  struct c_expr init;
4421 		  init.value = error_mark_node;
4422 		  init.original_code = ERROR_MARK;
4423 		  init.original_type = NULL;
4424 		  c_parser_error (parser, "expected %<=%>");
4425 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4426 		  process_init_element (input_location, init, false,
4427 					braced_init_obstack);
4428 		  return;
4429 		}
4430 	    }
4431 	}
4432     }
4433   c_parser_initval (parser, NULL, braced_init_obstack);
4434 }
4435 
4436 /* Parse a nested initializer; as c_parser_initializer but parses
4437    initializers within braced lists, after any designators have been
4438    applied.  If AFTER is not NULL then it is an Objective-C message
4439    expression which is the primary-expression starting the
4440    initializer.  */
4441 
4442 static void
4443 c_parser_initval (c_parser *parser, struct c_expr *after,
4444 		  struct obstack * braced_init_obstack)
4445 {
4446   struct c_expr init;
4447   gcc_assert (!after || c_dialect_objc ());
4448   location_t loc = c_parser_peek_token (parser)->location;
4449 
4450   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4451     init = c_parser_braced_init (parser, NULL_TREE, true,
4452 				 braced_init_obstack);
4453   else
4454     {
4455       init = c_parser_expr_no_commas (parser, after);
4456       if (init.value != NULL_TREE
4457 	  && TREE_CODE (init.value) != STRING_CST
4458 	  && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4459 	init = convert_lvalue_to_rvalue (loc, init, true, true);
4460     }
4461   process_init_element (loc, init, false, braced_init_obstack);
4462 }
4463 
4464 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4465    C99 6.8.2).
4466 
4467    compound-statement:
4468      { block-item-list[opt] }
4469      { label-declarations block-item-list }
4470 
4471    block-item-list:
4472      block-item
4473      block-item-list block-item
4474 
4475    block-item:
4476      nested-declaration
4477      statement
4478 
4479    nested-declaration:
4480      declaration
4481 
4482    GNU extensions:
4483 
4484    compound-statement:
4485      { label-declarations block-item-list }
4486 
4487    nested-declaration:
4488      __extension__ nested-declaration
4489      nested-function-definition
4490 
4491    label-declarations:
4492      label-declaration
4493      label-declarations label-declaration
4494 
4495    label-declaration:
4496      __label__ identifier-list ;
4497 
4498    Allowing the mixing of declarations and code is new in C99.  The
4499    GNU syntax also permits (not shown above) labels at the end of
4500    compound statements, which yield an error.  We don't allow labels
4501    on declarations; this might seem like a natural extension, but
4502    there would be a conflict between attributes on the label and
4503    prefix attributes on the declaration.  ??? The syntax follows the
4504    old parser in requiring something after label declarations.
4505    Although they are erroneous if the labels declared aren't defined,
4506    is it useful for the syntax to be this way?
4507 
4508    OpenACC:
4509 
4510    block-item:
4511      openacc-directive
4512 
4513    openacc-directive:
4514      update-directive
4515 
4516    OpenMP:
4517 
4518    block-item:
4519      openmp-directive
4520 
4521    openmp-directive:
4522      barrier-directive
4523      flush-directive
4524      taskwait-directive
4525      taskyield-directive
4526      cancel-directive
4527      cancellation-point-directive  */
4528 
4529 static tree
4530 c_parser_compound_statement (c_parser *parser)
4531 {
4532   tree stmt;
4533   location_t brace_loc;
4534   brace_loc = c_parser_peek_token (parser)->location;
4535   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4536     {
4537       /* Ensure a scope is entered and left anyway to avoid confusion
4538 	 if we have just prepared to enter a function body.  */
4539       stmt = c_begin_compound_stmt (true);
4540       c_end_compound_stmt (brace_loc, stmt, true);
4541       return error_mark_node;
4542     }
4543   stmt = c_begin_compound_stmt (true);
4544   c_parser_compound_statement_nostart (parser);
4545 
4546   /* If the compound stmt contains array notations, then we expand them.  */
4547   if (flag_cilkplus && contains_array_notation_expr (stmt))
4548     stmt = expand_array_notation_exprs (stmt);
4549   return c_end_compound_stmt (brace_loc, stmt, true);
4550 }
4551 
4552 /* Parse a compound statement except for the opening brace.  This is
4553    used for parsing both compound statements and statement expressions
4554    (which follow different paths to handling the opening).  */
4555 
4556 static void
4557 c_parser_compound_statement_nostart (c_parser *parser)
4558 {
4559   bool last_stmt = false;
4560   bool last_label = false;
4561   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4562   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4563   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4564     {
4565       c_parser_consume_token (parser);
4566       return;
4567     }
4568   mark_valid_location_for_stdc_pragma (true);
4569   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4570     {
4571       /* Read zero or more forward-declarations for labels that nested
4572 	 functions can jump to.  */
4573       mark_valid_location_for_stdc_pragma (false);
4574       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4575 	{
4576 	  label_loc = c_parser_peek_token (parser)->location;
4577 	  c_parser_consume_token (parser);
4578 	  /* Any identifiers, including those declared as type names,
4579 	     are OK here.  */
4580 	  while (true)
4581 	    {
4582 	      tree label;
4583 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
4584 		{
4585 		  c_parser_error (parser, "expected identifier");
4586 		  break;
4587 		}
4588 	      label
4589 		= declare_label (c_parser_peek_token (parser)->value);
4590 	      C_DECLARED_LABEL_FLAG (label) = 1;
4591 	      add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4592 	      c_parser_consume_token (parser);
4593 	      if (c_parser_next_token_is (parser, CPP_COMMA))
4594 		c_parser_consume_token (parser);
4595 	      else
4596 		break;
4597 	    }
4598 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4599 	}
4600       pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4601     }
4602   /* We must now have at least one statement, label or declaration.  */
4603   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4604     {
4605       mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4606       c_parser_error (parser, "expected declaration or statement");
4607       c_parser_consume_token (parser);
4608       return;
4609     }
4610   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4611     {
4612       location_t loc = c_parser_peek_token (parser)->location;
4613       if (c_parser_next_token_is_keyword (parser, RID_CASE)
4614 	  || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4615 	  || (c_parser_next_token_is (parser, CPP_NAME)
4616 	      && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4617 	{
4618 	  if (c_parser_next_token_is_keyword (parser, RID_CASE))
4619 	    label_loc = c_parser_peek_2nd_token (parser)->location;
4620 	  else
4621 	    label_loc = c_parser_peek_token (parser)->location;
4622 	  last_label = true;
4623 	  last_stmt = false;
4624 	  mark_valid_location_for_stdc_pragma (false);
4625 	  c_parser_label (parser);
4626 	}
4627       else if (!last_label
4628 	       && c_parser_next_tokens_start_declaration (parser))
4629 	{
4630 	  last_label = false;
4631 	  mark_valid_location_for_stdc_pragma (false);
4632 	  c_parser_declaration_or_fndef (parser, true, true, true, true,
4633 					 true, NULL, vNULL);
4634 	  if (last_stmt)
4635 	    pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4636 			 "ISO C90 forbids mixed declarations and code");
4637 	  last_stmt = false;
4638 	}
4639       else if (!last_label
4640 	       && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4641 	{
4642 	  /* __extension__ can start a declaration, but is also an
4643 	     unary operator that can start an expression.  Consume all
4644 	     but the last of a possible series of __extension__ to
4645 	     determine which.  */
4646 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4647 		 && (c_parser_peek_2nd_token (parser)->keyword
4648 		     == RID_EXTENSION))
4649 	    c_parser_consume_token (parser);
4650 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4651 	    {
4652 	      int ext;
4653 	      ext = disable_extension_diagnostics ();
4654 	      c_parser_consume_token (parser);
4655 	      last_label = false;
4656 	      mark_valid_location_for_stdc_pragma (false);
4657 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
4658 					     true, NULL, vNULL);
4659 	      /* Following the old parser, __extension__ does not
4660 		 disable this diagnostic.  */
4661 	      restore_extension_diagnostics (ext);
4662 	      if (last_stmt)
4663 		pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4664 			     "ISO C90 forbids mixed declarations and code");
4665 	      last_stmt = false;
4666 	    }
4667 	  else
4668 	    goto statement;
4669 	}
4670       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4671 	{
4672 	  /* External pragmas, and some omp pragmas, are not associated
4673 	     with regular c code, and so are not to be considered statements
4674 	     syntactically.  This ensures that the user doesn't put them
4675 	     places that would turn into syntax errors if the directive
4676 	     were ignored.  */
4677 	  if (c_parser_pragma (parser, pragma_compound))
4678 	    last_label = false, last_stmt = true;
4679 	}
4680       else if (c_parser_next_token_is (parser, CPP_EOF))
4681 	{
4682 	  mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4683 	  c_parser_error (parser, "expected declaration or statement");
4684 	  return;
4685 	}
4686       else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4687         {
4688           if (parser->in_if_block)
4689             {
4690 	      mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4691               error_at (loc, """expected %<}%> before %<else%>");
4692               return;
4693             }
4694           else
4695             {
4696               error_at (loc, "%<else%> without a previous %<if%>");
4697               c_parser_consume_token (parser);
4698               continue;
4699             }
4700         }
4701       else
4702 	{
4703 	statement:
4704 	  last_label = false;
4705 	  last_stmt = true;
4706 	  mark_valid_location_for_stdc_pragma (false);
4707 	  c_parser_statement_after_labels (parser);
4708 	}
4709 
4710       parser->error = false;
4711     }
4712   if (last_label)
4713     error_at (label_loc, "label at end of compound statement");
4714   c_parser_consume_token (parser);
4715   /* Restore the value we started with.  */
4716   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4717 }
4718 
4719 /* Parse all consecutive labels. */
4720 
4721 static void
4722 c_parser_all_labels (c_parser *parser)
4723 {
4724   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4725 	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4726 	 || (c_parser_next_token_is (parser, CPP_NAME)
4727 	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4728     c_parser_label (parser);
4729 }
4730 
4731 /* Parse a label (C90 6.6.1, C99 6.8.1).
4732 
4733    label:
4734      identifier : attributes[opt]
4735      case constant-expression :
4736      default :
4737 
4738    GNU extensions:
4739 
4740    label:
4741      case constant-expression ... constant-expression :
4742 
4743    The use of attributes on labels is a GNU extension.  The syntax in
4744    GNU C accepts any expressions without commas, non-constant
4745    expressions being rejected later.  */
4746 
4747 static void
4748 c_parser_label (c_parser *parser)
4749 {
4750   location_t loc1 = c_parser_peek_token (parser)->location;
4751   tree label = NULL_TREE;
4752   if (c_parser_next_token_is_keyword (parser, RID_CASE))
4753     {
4754       tree exp1, exp2;
4755       c_parser_consume_token (parser);
4756       exp1 = c_parser_expr_no_commas (parser, NULL).value;
4757       if (c_parser_next_token_is (parser, CPP_COLON))
4758 	{
4759 	  c_parser_consume_token (parser);
4760 	  label = do_case (loc1, exp1, NULL_TREE);
4761 	}
4762       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4763 	{
4764 	  c_parser_consume_token (parser);
4765 	  exp2 = c_parser_expr_no_commas (parser, NULL).value;
4766 	  if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4767 	    label = do_case (loc1, exp1, exp2);
4768 	}
4769       else
4770 	c_parser_error (parser, "expected %<:%> or %<...%>");
4771     }
4772   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4773     {
4774       c_parser_consume_token (parser);
4775       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4776 	label = do_case (loc1, NULL_TREE, NULL_TREE);
4777     }
4778   else
4779     {
4780       tree name = c_parser_peek_token (parser)->value;
4781       tree tlab;
4782       tree attrs;
4783       location_t loc2 = c_parser_peek_token (parser)->location;
4784       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4785       c_parser_consume_token (parser);
4786       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4787       c_parser_consume_token (parser);
4788       attrs = c_parser_attributes (parser);
4789       tlab = define_label (loc2, name);
4790       if (tlab)
4791 	{
4792 	  decl_attributes (&tlab, attrs, 0);
4793 	  label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4794 	}
4795     }
4796   if (label)
4797     {
4798       if (c_parser_next_tokens_start_declaration (parser))
4799 	{
4800 	  error_at (c_parser_peek_token (parser)->location,
4801 		    "a label can only be part of a statement and "
4802 		    "a declaration is not a statement");
4803 	  c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4804 					 /*static_assert_ok*/ true,
4805 					 /*empty_ok*/ true, /*nested*/ true,
4806 					 /*start_attr_ok*/ true, NULL,
4807 					 vNULL);
4808 	}
4809     }
4810 }
4811 
4812 /* Parse a statement (C90 6.6, C99 6.8).
4813 
4814    statement:
4815      labeled-statement
4816      compound-statement
4817      expression-statement
4818      selection-statement
4819      iteration-statement
4820      jump-statement
4821 
4822    labeled-statement:
4823      label statement
4824 
4825    expression-statement:
4826      expression[opt] ;
4827 
4828    selection-statement:
4829      if-statement
4830      switch-statement
4831 
4832    iteration-statement:
4833      while-statement
4834      do-statement
4835      for-statement
4836 
4837    jump-statement:
4838      goto identifier ;
4839      continue ;
4840      break ;
4841      return expression[opt] ;
4842 
4843    GNU extensions:
4844 
4845    statement:
4846      asm-statement
4847 
4848    jump-statement:
4849      goto * expression ;
4850 
4851    Objective-C:
4852 
4853    statement:
4854      objc-throw-statement
4855      objc-try-catch-statement
4856      objc-synchronized-statement
4857 
4858    objc-throw-statement:
4859      @throw expression ;
4860      @throw ;
4861 
4862    OpenACC:
4863 
4864    statement:
4865      openacc-construct
4866 
4867    openacc-construct:
4868      parallel-construct
4869      kernels-construct
4870      data-construct
4871      loop-construct
4872 
4873    parallel-construct:
4874      parallel-directive structured-block
4875 
4876    kernels-construct:
4877      kernels-directive structured-block
4878 
4879    data-construct:
4880      data-directive structured-block
4881 
4882    loop-construct:
4883      loop-directive structured-block
4884 
4885    OpenMP:
4886 
4887    statement:
4888      openmp-construct
4889 
4890    openmp-construct:
4891      parallel-construct
4892      for-construct
4893      simd-construct
4894      for-simd-construct
4895      sections-construct
4896      single-construct
4897      parallel-for-construct
4898      parallel-for-simd-construct
4899      parallel-sections-construct
4900      master-construct
4901      critical-construct
4902      atomic-construct
4903      ordered-construct
4904 
4905    parallel-construct:
4906      parallel-directive structured-block
4907 
4908    for-construct:
4909      for-directive iteration-statement
4910 
4911    simd-construct:
4912      simd-directive iteration-statements
4913 
4914    for-simd-construct:
4915      for-simd-directive iteration-statements
4916 
4917    sections-construct:
4918      sections-directive section-scope
4919 
4920    single-construct:
4921      single-directive structured-block
4922 
4923    parallel-for-construct:
4924      parallel-for-directive iteration-statement
4925 
4926    parallel-for-simd-construct:
4927      parallel-for-simd-directive iteration-statement
4928 
4929    parallel-sections-construct:
4930      parallel-sections-directive section-scope
4931 
4932    master-construct:
4933      master-directive structured-block
4934 
4935    critical-construct:
4936      critical-directive structured-block
4937 
4938    atomic-construct:
4939      atomic-directive expression-statement
4940 
4941    ordered-construct:
4942      ordered-directive structured-block
4943 
4944    Transactional Memory:
4945 
4946    statement:
4947      transaction-statement
4948      transaction-cancel-statement
4949 */
4950 
4951 static void
4952 c_parser_statement (c_parser *parser)
4953 {
4954   c_parser_all_labels (parser);
4955   c_parser_statement_after_labels (parser);
4956 }
4957 
4958 /* Parse a statement, other than a labeled statement.  */
4959 
4960 static void
4961 c_parser_statement_after_labels (c_parser *parser)
4962 {
4963   location_t loc = c_parser_peek_token (parser)->location;
4964   tree stmt = NULL_TREE;
4965   bool in_if_block = parser->in_if_block;
4966   parser->in_if_block = false;
4967   switch (c_parser_peek_token (parser)->type)
4968     {
4969     case CPP_OPEN_BRACE:
4970       add_stmt (c_parser_compound_statement (parser));
4971       break;
4972     case CPP_KEYWORD:
4973       switch (c_parser_peek_token (parser)->keyword)
4974 	{
4975 	case RID_IF:
4976 	  c_parser_if_statement (parser);
4977 	  break;
4978 	case RID_SWITCH:
4979 	  c_parser_switch_statement (parser);
4980 	  break;
4981 	case RID_WHILE:
4982 	  c_parser_while_statement (parser, false);
4983 	  break;
4984 	case RID_DO:
4985 	  c_parser_do_statement (parser, false);
4986 	  break;
4987 	case RID_FOR:
4988 	  c_parser_for_statement (parser, false);
4989 	  break;
4990 	case RID_CILK_FOR:
4991 	  if (!flag_cilkplus)
4992 	    {
4993 	      error_at (c_parser_peek_token (parser)->location,
4994 			"-fcilkplus must be enabled to use %<_Cilk_for%>");
4995 	      c_parser_skip_to_end_of_block_or_statement (parser);
4996 	    }
4997 	  else
4998 	    c_parser_cilk_for (parser, integer_zero_node);
4999 	  break;
5000 	case RID_CILK_SYNC:
5001 	  c_parser_consume_token (parser);
5002 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5003 	  if (!flag_cilkplus)
5004 	    error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5005 	  else
5006 	    add_stmt (build_cilk_sync ());
5007 	  break;
5008 	case RID_GOTO:
5009 	  c_parser_consume_token (parser);
5010 	  if (c_parser_next_token_is (parser, CPP_NAME))
5011 	    {
5012 	      stmt = c_finish_goto_label (loc,
5013 					  c_parser_peek_token (parser)->value);
5014 	      c_parser_consume_token (parser);
5015 	    }
5016 	  else if (c_parser_next_token_is (parser, CPP_MULT))
5017 	    {
5018 	      struct c_expr val;
5019 
5020 	      c_parser_consume_token (parser);
5021 	      val = c_parser_expression (parser);
5022 	      if (check_no_cilk (val.value,
5023 				 "Cilk array notation cannot be used as a computed goto expression",
5024 				 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5025 				 loc))
5026 	        val.value = error_mark_node;
5027 	      val = convert_lvalue_to_rvalue (loc, val, false, true);
5028 	      stmt = c_finish_goto_ptr (loc, val.value);
5029 	    }
5030 	  else
5031 	    c_parser_error (parser, "expected identifier or %<*%>");
5032 	  goto expect_semicolon;
5033 	case RID_CONTINUE:
5034 	  c_parser_consume_token (parser);
5035 	  stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5036 	  goto expect_semicolon;
5037 	case RID_BREAK:
5038 	  c_parser_consume_token (parser);
5039 	  stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5040 	  goto expect_semicolon;
5041 	case RID_RETURN:
5042 	  c_parser_consume_token (parser);
5043 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5044 	    {
5045 	      stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5046 	      c_parser_consume_token (parser);
5047 	    }
5048 	  else
5049 	    {
5050 	      location_t xloc = c_parser_peek_token (parser)->location;
5051 	      struct c_expr expr = c_parser_expression_conv (parser);
5052 	      mark_exp_read (expr.value);
5053 	      stmt = c_finish_return (xloc, expr.value, expr.original_type);
5054 	      goto expect_semicolon;
5055 	    }
5056 	  break;
5057 	case RID_ASM:
5058 	  stmt = c_parser_asm_statement (parser);
5059 	  break;
5060 	case RID_TRANSACTION_ATOMIC:
5061 	case RID_TRANSACTION_RELAXED:
5062 	  stmt = c_parser_transaction (parser,
5063 	      c_parser_peek_token (parser)->keyword);
5064 	  break;
5065 	case RID_TRANSACTION_CANCEL:
5066 	  stmt = c_parser_transaction_cancel (parser);
5067 	  goto expect_semicolon;
5068 	case RID_AT_THROW:
5069 	  gcc_assert (c_dialect_objc ());
5070 	  c_parser_consume_token (parser);
5071 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5072 	    {
5073 	      stmt = objc_build_throw_stmt (loc, NULL_TREE);
5074 	      c_parser_consume_token (parser);
5075 	    }
5076 	  else
5077 	    {
5078 	      struct c_expr expr = c_parser_expression (parser);
5079 	      expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5080 	      if (check_no_cilk (expr.value,
5081 		 "Cilk array notation cannot be used for a throw expression",
5082 		 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5083 	        expr.value = error_mark_node;
5084 	      else
5085 		{
5086 	          expr.value = c_fully_fold (expr.value, false, NULL);
5087 	          stmt = objc_build_throw_stmt (loc, expr.value);
5088 		}
5089 	      goto expect_semicolon;
5090 	    }
5091 	  break;
5092 	case RID_AT_TRY:
5093 	  gcc_assert (c_dialect_objc ());
5094 	  c_parser_objc_try_catch_finally_statement (parser);
5095 	  break;
5096 	case RID_AT_SYNCHRONIZED:
5097 	  gcc_assert (c_dialect_objc ());
5098 	  c_parser_objc_synchronized_statement (parser);
5099 	  break;
5100 	default:
5101 	  goto expr_stmt;
5102 	}
5103       break;
5104     case CPP_SEMICOLON:
5105       c_parser_consume_token (parser);
5106       break;
5107     case CPP_CLOSE_PAREN:
5108     case CPP_CLOSE_SQUARE:
5109       /* Avoid infinite loop in error recovery:
5110 	 c_parser_skip_until_found stops at a closing nesting
5111 	 delimiter without consuming it, but here we need to consume
5112 	 it to proceed further.  */
5113       c_parser_error (parser, "expected statement");
5114       c_parser_consume_token (parser);
5115       break;
5116     case CPP_PRAGMA:
5117       c_parser_pragma (parser, pragma_stmt);
5118       break;
5119     default:
5120     expr_stmt:
5121       stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5122     expect_semicolon:
5123       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5124       break;
5125     }
5126   /* Two cases cannot and do not have line numbers associated: If stmt
5127      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5128      cannot hold line numbers.  But that's OK because the statement
5129      will either be changed to a MODIFY_EXPR during gimplification of
5130      the statement expr, or discarded.  If stmt was compound, but
5131      without new variables, we will have skipped the creation of a
5132      BIND and will have a bare STATEMENT_LIST.  But that's OK because
5133      (recursively) all of the component statements should already have
5134      line numbers assigned.  ??? Can we discard no-op statements
5135      earlier?  */
5136   if (CAN_HAVE_LOCATION_P (stmt)
5137       && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5138     SET_EXPR_LOCATION (stmt, loc);
5139 
5140   parser->in_if_block = in_if_block;
5141 }
5142 
5143 /* Parse the condition from an if, do, while or for statements.  */
5144 
5145 static tree
5146 c_parser_condition (c_parser *parser)
5147 {
5148   location_t loc = c_parser_peek_token (parser)->location;
5149   tree cond;
5150   cond = c_parser_expression_conv (parser).value;
5151   cond = c_objc_common_truthvalue_conversion (loc, cond);
5152   cond = c_fully_fold (cond, false, NULL);
5153   if (warn_sequence_point)
5154     verify_sequence_points (cond);
5155   return cond;
5156 }
5157 
5158 /* Parse a parenthesized condition from an if, do or while statement.
5159 
5160    condition:
5161      ( expression )
5162 */
5163 static tree
5164 c_parser_paren_condition (c_parser *parser)
5165 {
5166   tree cond;
5167   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5168     return error_mark_node;
5169   cond = c_parser_condition (parser);
5170   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5171   return cond;
5172 }
5173 
5174 /* Parse a statement which is a block in C99.  */
5175 
5176 static tree
5177 c_parser_c99_block_statement (c_parser *parser)
5178 {
5179   tree block = c_begin_compound_stmt (flag_isoc99);
5180   location_t loc = c_parser_peek_token (parser)->location;
5181   c_parser_statement (parser);
5182   return c_end_compound_stmt (loc, block, flag_isoc99);
5183 }
5184 
5185 /* Parse the body of an if statement.  This is just parsing a
5186    statement but (a) it is a block in C99, (b) we track whether the
5187    body is an if statement for the sake of -Wparentheses warnings, (c)
5188    we handle an empty body specially for the sake of -Wempty-body
5189    warnings, and (d) we call parser_compound_statement directly
5190    because c_parser_statement_after_labels resets
5191    parser->in_if_block.  */
5192 
5193 static tree
5194 c_parser_if_body (c_parser *parser, bool *if_p)
5195 {
5196   tree block = c_begin_compound_stmt (flag_isoc99);
5197   location_t body_loc = c_parser_peek_token (parser)->location;
5198   c_parser_all_labels (parser);
5199   *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
5200   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5201     {
5202       location_t loc = c_parser_peek_token (parser)->location;
5203       add_stmt (build_empty_stmt (loc));
5204       c_parser_consume_token (parser);
5205       if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5206 	warning_at (loc, OPT_Wempty_body,
5207 		    "suggest braces around empty body in an %<if%> statement");
5208     }
5209   else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5210     add_stmt (c_parser_compound_statement (parser));
5211   else
5212     c_parser_statement_after_labels (parser);
5213   return c_end_compound_stmt (body_loc, block, flag_isoc99);
5214 }
5215 
5216 /* Parse the else body of an if statement.  This is just parsing a
5217    statement but (a) it is a block in C99, (b) we handle an empty body
5218    specially for the sake of -Wempty-body warnings.  */
5219 
5220 static tree
5221 c_parser_else_body (c_parser *parser)
5222 {
5223   location_t else_loc = c_parser_peek_token (parser)->location;
5224   tree block = c_begin_compound_stmt (flag_isoc99);
5225   c_parser_all_labels (parser);
5226   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5227     {
5228       location_t loc = c_parser_peek_token (parser)->location;
5229       warning_at (loc,
5230 		  OPT_Wempty_body,
5231 	         "suggest braces around empty body in an %<else%> statement");
5232       add_stmt (build_empty_stmt (loc));
5233       c_parser_consume_token (parser);
5234     }
5235   else
5236     c_parser_statement_after_labels (parser);
5237   return c_end_compound_stmt (else_loc, block, flag_isoc99);
5238 }
5239 
5240 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5241 
5242    if-statement:
5243      if ( expression ) statement
5244      if ( expression ) statement else statement
5245 */
5246 
5247 static void
5248 c_parser_if_statement (c_parser *parser)
5249 {
5250   tree block;
5251   location_t loc;
5252   tree cond;
5253   bool first_if = false;
5254   tree first_body, second_body;
5255   bool in_if_block;
5256   tree if_stmt;
5257 
5258   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5259   c_parser_consume_token (parser);
5260   block = c_begin_compound_stmt (flag_isoc99);
5261   loc = c_parser_peek_token (parser)->location;
5262   cond = c_parser_paren_condition (parser);
5263   if (flag_cilkplus && contains_cilk_spawn_stmt (cond))
5264     {
5265       error_at (loc, "if statement cannot contain %<Cilk_spawn%>");
5266       cond = error_mark_node;
5267     }
5268   in_if_block = parser->in_if_block;
5269   parser->in_if_block = true;
5270   first_body = c_parser_if_body (parser, &first_if);
5271   parser->in_if_block = in_if_block;
5272   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5273     {
5274       c_parser_consume_token (parser);
5275       second_body = c_parser_else_body (parser);
5276     }
5277   else
5278     second_body = NULL_TREE;
5279   c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
5280   if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
5281 
5282   /* If the if statement contains array notations, then we expand them.  */
5283   if (flag_cilkplus && contains_array_notation_expr (if_stmt))
5284     if_stmt = fix_conditional_array_notations (if_stmt);
5285   add_stmt (if_stmt);
5286 }
5287 
5288 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5289 
5290    switch-statement:
5291      switch (expression) statement
5292 */
5293 
5294 static void
5295 c_parser_switch_statement (c_parser *parser)
5296 {
5297   struct c_expr ce;
5298   tree block, expr, body, save_break;
5299   location_t switch_loc = c_parser_peek_token (parser)->location;
5300   location_t switch_cond_loc;
5301   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5302   c_parser_consume_token (parser);
5303   block = c_begin_compound_stmt (flag_isoc99);
5304   bool explicit_cast_p = false;
5305   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5306     {
5307       switch_cond_loc = c_parser_peek_token (parser)->location;
5308       if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5309 	  && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5310 	explicit_cast_p = true;
5311       ce = c_parser_expression (parser);
5312       ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5313       expr = ce.value;
5314       /* ??? expr has no valid location?  */
5315       if (check_no_cilk (expr,
5316 	 "Cilk array notation cannot be used as a condition for switch statement",
5317 	 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5318 			 switch_cond_loc))
5319         expr = error_mark_node;
5320       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5321     }
5322   else
5323     {
5324       switch_cond_loc = UNKNOWN_LOCATION;
5325       expr = error_mark_node;
5326     }
5327   c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5328   save_break = c_break_label;
5329   c_break_label = NULL_TREE;
5330   body = c_parser_c99_block_statement (parser);
5331   c_finish_case (body, ce.original_type);
5332   if (c_break_label)
5333     {
5334       location_t here = c_parser_peek_token (parser)->location;
5335       tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5336       SET_EXPR_LOCATION (t, here);
5337       add_stmt (t);
5338     }
5339   c_break_label = save_break;
5340   add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5341 }
5342 
5343 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5344 
5345    while-statement:
5346       while (expression) statement
5347 */
5348 
5349 static void
5350 c_parser_while_statement (c_parser *parser, bool ivdep)
5351 {
5352   tree block, cond, body, save_break, save_cont;
5353   location_t loc;
5354   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5355   c_parser_consume_token (parser);
5356   block = c_begin_compound_stmt (flag_isoc99);
5357   loc = c_parser_peek_token (parser)->location;
5358   cond = c_parser_paren_condition (parser);
5359   if (check_no_cilk (cond,
5360          "Cilk array notation cannot be used as a condition for while statement",
5361 	 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5362     cond = error_mark_node;
5363   if (ivdep && cond != error_mark_node)
5364     cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5365 		   build_int_cst (integer_type_node,
5366 		   annot_expr_ivdep_kind));
5367   save_break = c_break_label;
5368   c_break_label = NULL_TREE;
5369   save_cont = c_cont_label;
5370   c_cont_label = NULL_TREE;
5371   body = c_parser_c99_block_statement (parser);
5372   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5373   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5374   c_break_label = save_break;
5375   c_cont_label = save_cont;
5376 }
5377 
5378 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5379 
5380    do-statement:
5381      do statement while ( expression ) ;
5382 */
5383 
5384 static void
5385 c_parser_do_statement (c_parser *parser, bool ivdep)
5386 {
5387   tree block, cond, body, save_break, save_cont, new_break, new_cont;
5388   location_t loc;
5389   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5390   c_parser_consume_token (parser);
5391   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5392     warning_at (c_parser_peek_token (parser)->location,
5393 		OPT_Wempty_body,
5394 		"suggest braces around empty body in %<do%> statement");
5395   block = c_begin_compound_stmt (flag_isoc99);
5396   loc = c_parser_peek_token (parser)->location;
5397   save_break = c_break_label;
5398   c_break_label = NULL_TREE;
5399   save_cont = c_cont_label;
5400   c_cont_label = NULL_TREE;
5401   body = c_parser_c99_block_statement (parser);
5402   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5403   new_break = c_break_label;
5404   c_break_label = save_break;
5405   new_cont = c_cont_label;
5406   c_cont_label = save_cont;
5407   cond = c_parser_paren_condition (parser);
5408   if (check_no_cilk (cond,
5409 	 "Cilk array notation cannot be used as a condition for a do-while statement",
5410 	 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5411     cond = error_mark_node;
5412   if (ivdep && cond != error_mark_node)
5413     cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5414 		   build_int_cst (integer_type_node,
5415 		   annot_expr_ivdep_kind));
5416   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5417     c_parser_skip_to_end_of_block_or_statement (parser);
5418   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5419   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5420 }
5421 
5422 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5423 
5424    for-statement:
5425      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5426      for ( nested-declaration expression[opt] ; expression[opt] ) statement
5427 
5428    The form with a declaration is new in C99.
5429 
5430    ??? In accordance with the old parser, the declaration may be a
5431    nested function, which is then rejected in check_for_loop_decls,
5432    but does it make any sense for this to be included in the grammar?
5433    Note in particular that the nested function does not include a
5434    trailing ';', whereas the "declaration" production includes one.
5435    Also, can we reject bad declarations earlier and cheaper than
5436    check_for_loop_decls?
5437 
5438    In Objective-C, there are two additional variants:
5439 
5440    foreach-statement:
5441      for ( expression in expresssion ) statement
5442      for ( declaration in expression ) statement
5443 
5444    This is inconsistent with C, because the second variant is allowed
5445    even if c99 is not enabled.
5446 
5447    The rest of the comment documents these Objective-C foreach-statement.
5448 
5449    Here is the canonical example of the first variant:
5450     for (object in array)    { do something with object }
5451    we call the first expression ("object") the "object_expression" and
5452    the second expression ("array") the "collection_expression".
5453    object_expression must be an lvalue of type "id" (a generic Objective-C
5454    object) because the loop works by assigning to object_expression the
5455    various objects from the collection_expression.  collection_expression
5456    must evaluate to something of type "id" which responds to the method
5457    countByEnumeratingWithState:objects:count:.
5458 
5459    The canonical example of the second variant is:
5460     for (id object in array)    { do something with object }
5461    which is completely equivalent to
5462     {
5463       id object;
5464       for (object in array) { do something with object }
5465     }
5466    Note that initizializing 'object' in some way (eg, "for ((object =
5467    xxx) in array) { do something with object }") is possibly
5468    technically valid, but completely pointless as 'object' will be
5469    assigned to something else as soon as the loop starts.  We should
5470    most likely reject it (TODO).
5471 
5472    The beginning of the Objective-C foreach-statement looks exactly
5473    like the beginning of the for-statement, and we can tell it is a
5474    foreach-statement only because the initial declaration or
5475    expression is terminated by 'in' instead of ';'.
5476 */
5477 
5478 static void
5479 c_parser_for_statement (c_parser *parser, bool ivdep)
5480 {
5481   tree block, cond, incr, save_break, save_cont, body;
5482   /* The following are only used when parsing an ObjC foreach statement.  */
5483   tree object_expression;
5484   /* Silence the bogus uninitialized warning.  */
5485   tree collection_expression = NULL;
5486   location_t loc = c_parser_peek_token (parser)->location;
5487   location_t for_loc = c_parser_peek_token (parser)->location;
5488   bool is_foreach_statement = false;
5489   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
5490   c_parser_consume_token (parser);
5491   /* Open a compound statement in Objective-C as well, just in case this is
5492      as foreach expression.  */
5493   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
5494   cond = error_mark_node;
5495   incr = error_mark_node;
5496   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5497     {
5498       /* Parse the initialization declaration or expression.  */
5499       object_expression = error_mark_node;
5500       parser->objc_could_be_foreach_context = c_dialect_objc ();
5501       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5502 	{
5503 	  parser->objc_could_be_foreach_context = false;
5504 	  c_parser_consume_token (parser);
5505 	  c_finish_expr_stmt (loc, NULL_TREE);
5506 	}
5507       else if (c_parser_next_tokens_start_declaration (parser))
5508 	{
5509 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
5510 					 &object_expression, vNULL);
5511 	  parser->objc_could_be_foreach_context = false;
5512 
5513 	  if (c_parser_next_token_is_keyword (parser, RID_IN))
5514 	    {
5515 	      c_parser_consume_token (parser);
5516 	      is_foreach_statement = true;
5517 	      if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5518 		c_parser_error (parser, "multiple iterating variables in fast enumeration");
5519 	    }
5520 	  else
5521 	    check_for_loop_decls (for_loc, flag_isoc99);
5522 	}
5523       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5524 	{
5525 	  /* __extension__ can start a declaration, but is also an
5526 	     unary operator that can start an expression.  Consume all
5527 	     but the last of a possible series of __extension__ to
5528 	     determine which.  */
5529 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5530 		 && (c_parser_peek_2nd_token (parser)->keyword
5531 		     == RID_EXTENSION))
5532 	    c_parser_consume_token (parser);
5533 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5534 	    {
5535 	      int ext;
5536 	      ext = disable_extension_diagnostics ();
5537 	      c_parser_consume_token (parser);
5538 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
5539 					     true, &object_expression, vNULL);
5540 	      parser->objc_could_be_foreach_context = false;
5541 
5542 	      restore_extension_diagnostics (ext);
5543 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
5544 		{
5545 		  c_parser_consume_token (parser);
5546 		  is_foreach_statement = true;
5547 		  if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5548 		    c_parser_error (parser, "multiple iterating variables in fast enumeration");
5549 		}
5550 	      else
5551 		check_for_loop_decls (for_loc, flag_isoc99);
5552 	    }
5553 	  else
5554 	    goto init_expr;
5555 	}
5556       else
5557 	{
5558 	init_expr:
5559 	  {
5560 	    struct c_expr ce;
5561 	    tree init_expression;
5562 	    ce = c_parser_expression (parser);
5563 	    /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5564 	       level statement", but it works just fine, so allow it.  */
5565 	    init_expression = ce.value;
5566 	    parser->objc_could_be_foreach_context = false;
5567 	    if (c_parser_next_token_is_keyword (parser, RID_IN))
5568 	      {
5569 		c_parser_consume_token (parser);
5570 		is_foreach_statement = true;
5571 		if (! lvalue_p (init_expression))
5572 		  c_parser_error (parser, "invalid iterating variable in fast enumeration");
5573 		object_expression = c_fully_fold (init_expression, false, NULL);
5574 	      }
5575 	    else
5576 	      {
5577 		ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5578 		init_expression = ce.value;
5579 		c_finish_expr_stmt (loc, init_expression);
5580 		c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5581 	      }
5582 	  }
5583 	}
5584       /* Parse the loop condition.  In the case of a foreach
5585 	 statement, there is no loop condition.  */
5586       gcc_assert (!parser->objc_could_be_foreach_context);
5587       if (!is_foreach_statement)
5588 	{
5589 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5590 	    {
5591 	      if (ivdep)
5592 		{
5593 		  c_parser_error (parser, "missing loop condition in loop with "
5594 				  "%<GCC ivdep%> pragma");
5595 		  cond = error_mark_node;
5596 		}
5597 	      else
5598 		{
5599 		  c_parser_consume_token (parser);
5600 		  cond = NULL_TREE;
5601 		}
5602 	    }
5603 	  else
5604 	    {
5605 	      cond = c_parser_condition (parser);
5606 	      if (check_no_cilk (cond,
5607 		 "Cilk array notation cannot be used in a condition for a for-loop",
5608 		 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5609 		cond = error_mark_node;
5610 	      c_parser_skip_until_found (parser, CPP_SEMICOLON,
5611 					 "expected %<;%>");
5612 	    }
5613 	  if (ivdep && cond != error_mark_node)
5614 	    cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5615 			   build_int_cst (integer_type_node,
5616 			   annot_expr_ivdep_kind));
5617 	}
5618       /* Parse the increment expression (the third expression in a
5619 	 for-statement).  In the case of a foreach-statement, this is
5620 	 the expression that follows the 'in'.  */
5621       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5622 	{
5623 	  if (is_foreach_statement)
5624 	    {
5625 	      c_parser_error (parser, "missing collection in fast enumeration");
5626 	      collection_expression = error_mark_node;
5627 	    }
5628 	  else
5629 	    incr = c_process_expr_stmt (loc, NULL_TREE);
5630 	}
5631       else
5632 	{
5633 	  if (is_foreach_statement)
5634 	    collection_expression = c_fully_fold (c_parser_expression (parser).value,
5635 						  false, NULL);
5636 	  else
5637 	    {
5638 	      struct c_expr ce = c_parser_expression (parser);
5639 	      ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5640 	      incr = c_process_expr_stmt (loc, ce.value);
5641 	    }
5642 	}
5643       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5644     }
5645   save_break = c_break_label;
5646   c_break_label = NULL_TREE;
5647   save_cont = c_cont_label;
5648   c_cont_label = NULL_TREE;
5649   body = c_parser_c99_block_statement (parser);
5650   if (is_foreach_statement)
5651     objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5652   else
5653     c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5654   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5655   c_break_label = save_break;
5656   c_cont_label = save_cont;
5657 }
5658 
5659 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
5660    statement with inputs, outputs, clobbers, and volatile tag
5661    allowed.
5662 
5663    asm-statement:
5664      asm type-qualifier[opt] ( asm-argument ) ;
5665      asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5666 
5667    asm-argument:
5668      asm-string-literal
5669      asm-string-literal : asm-operands[opt]
5670      asm-string-literal : asm-operands[opt] : asm-operands[opt]
5671      asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5672 
5673    asm-goto-argument:
5674      asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5675        : asm-goto-operands
5676 
5677    Qualifiers other than volatile are accepted in the syntax but
5678    warned for.  */
5679 
5680 static tree
5681 c_parser_asm_statement (c_parser *parser)
5682 {
5683   tree quals, str, outputs, inputs, clobbers, labels, ret;
5684   bool simple, is_goto;
5685   location_t asm_loc = c_parser_peek_token (parser)->location;
5686   int section, nsections;
5687 
5688   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5689   c_parser_consume_token (parser);
5690   if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5691     {
5692       quals = c_parser_peek_token (parser)->value;
5693       c_parser_consume_token (parser);
5694     }
5695   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5696 	   || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5697     {
5698       warning_at (c_parser_peek_token (parser)->location,
5699 		  0,
5700 		  "%E qualifier ignored on asm",
5701 		  c_parser_peek_token (parser)->value);
5702       quals = NULL_TREE;
5703       c_parser_consume_token (parser);
5704     }
5705   else
5706     quals = NULL_TREE;
5707 
5708   is_goto = false;
5709   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5710     {
5711       c_parser_consume_token (parser);
5712       is_goto = true;
5713     }
5714 
5715   /* ??? Follow the C++ parser rather than using the
5716      lex_untranslated_string kludge.  */
5717   parser->lex_untranslated_string = true;
5718   ret = NULL;
5719 
5720   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5721     goto error;
5722 
5723   str = c_parser_asm_string_literal (parser);
5724   if (str == NULL_TREE)
5725     goto error_close_paren;
5726 
5727   simple = true;
5728   outputs = NULL_TREE;
5729   inputs = NULL_TREE;
5730   clobbers = NULL_TREE;
5731   labels = NULL_TREE;
5732 
5733   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5734     goto done_asm;
5735 
5736   /* Parse each colon-delimited section of operands.  */
5737   nsections = 3 + is_goto;
5738   for (section = 0; section < nsections; ++section)
5739     {
5740       if (!c_parser_require (parser, CPP_COLON,
5741 			     is_goto
5742 			     ? "expected %<:%>"
5743 			     : "expected %<:%> or %<)%>"))
5744 	goto error_close_paren;
5745 
5746       /* Once past any colon, we're no longer a simple asm.  */
5747       simple = false;
5748 
5749       if ((!c_parser_next_token_is (parser, CPP_COLON)
5750 	   && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5751 	  || section == 3)
5752 	switch (section)
5753 	  {
5754 	  case 0:
5755 	    /* For asm goto, we don't allow output operands, but reserve
5756 	       the slot for a future extension that does allow them.  */
5757 	    if (!is_goto)
5758 	      outputs = c_parser_asm_operands (parser);
5759 	    break;
5760 	  case 1:
5761 	    inputs = c_parser_asm_operands (parser);
5762 	    break;
5763 	  case 2:
5764 	    clobbers = c_parser_asm_clobbers (parser);
5765 	    break;
5766 	  case 3:
5767 	    labels = c_parser_asm_goto_operands (parser);
5768 	    break;
5769 	  default:
5770 	    gcc_unreachable ();
5771 	  }
5772 
5773       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5774 	goto done_asm;
5775     }
5776 
5777  done_asm:
5778   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5779     {
5780       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5781       goto error;
5782     }
5783 
5784   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5785     c_parser_skip_to_end_of_block_or_statement (parser);
5786 
5787   ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5788 					       clobbers, labels, simple));
5789 
5790  error:
5791   parser->lex_untranslated_string = false;
5792   return ret;
5793 
5794  error_close_paren:
5795   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5796   goto error;
5797 }
5798 
5799 /* Parse asm operands, a GNU extension.
5800 
5801    asm-operands:
5802      asm-operand
5803      asm-operands , asm-operand
5804 
5805    asm-operand:
5806      asm-string-literal ( expression )
5807      [ identifier ] asm-string-literal ( expression )
5808 */
5809 
5810 static tree
5811 c_parser_asm_operands (c_parser *parser)
5812 {
5813   tree list = NULL_TREE;
5814   while (true)
5815     {
5816       tree name, str;
5817       struct c_expr expr;
5818       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5819 	{
5820 	  c_parser_consume_token (parser);
5821 	  if (c_parser_next_token_is (parser, CPP_NAME))
5822 	    {
5823 	      tree id = c_parser_peek_token (parser)->value;
5824 	      c_parser_consume_token (parser);
5825 	      name = build_string (IDENTIFIER_LENGTH (id),
5826 				   IDENTIFIER_POINTER (id));
5827 	    }
5828 	  else
5829 	    {
5830 	      c_parser_error (parser, "expected identifier");
5831 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5832 	      return NULL_TREE;
5833 	    }
5834 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5835 				     "expected %<]%>");
5836 	}
5837       else
5838 	name = NULL_TREE;
5839       str = c_parser_asm_string_literal (parser);
5840       if (str == NULL_TREE)
5841 	return NULL_TREE;
5842       parser->lex_untranslated_string = false;
5843       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5844 	{
5845 	  parser->lex_untranslated_string = true;
5846 	  return NULL_TREE;
5847 	}
5848       expr = c_parser_expression (parser);
5849       mark_exp_read (expr.value);
5850       parser->lex_untranslated_string = true;
5851       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5852 	{
5853 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5854 	  return NULL_TREE;
5855 	}
5856       list = chainon (list, build_tree_list (build_tree_list (name, str),
5857 					     expr.value));
5858       if (c_parser_next_token_is (parser, CPP_COMMA))
5859 	c_parser_consume_token (parser);
5860       else
5861 	break;
5862     }
5863   return list;
5864 }
5865 
5866 /* Parse asm clobbers, a GNU extension.
5867 
5868    asm-clobbers:
5869      asm-string-literal
5870      asm-clobbers , asm-string-literal
5871 */
5872 
5873 static tree
5874 c_parser_asm_clobbers (c_parser *parser)
5875 {
5876   tree list = NULL_TREE;
5877   while (true)
5878     {
5879       tree str = c_parser_asm_string_literal (parser);
5880       if (str)
5881 	list = tree_cons (NULL_TREE, str, list);
5882       else
5883 	return NULL_TREE;
5884       if (c_parser_next_token_is (parser, CPP_COMMA))
5885 	c_parser_consume_token (parser);
5886       else
5887 	break;
5888     }
5889   return list;
5890 }
5891 
5892 /* Parse asm goto labels, a GNU extension.
5893 
5894    asm-goto-operands:
5895      identifier
5896      asm-goto-operands , identifier
5897 */
5898 
5899 static tree
5900 c_parser_asm_goto_operands (c_parser *parser)
5901 {
5902   tree list = NULL_TREE;
5903   while (true)
5904     {
5905       tree name, label;
5906 
5907       if (c_parser_next_token_is (parser, CPP_NAME))
5908 	{
5909 	  c_token *tok = c_parser_peek_token (parser);
5910 	  name = tok->value;
5911 	  label = lookup_label_for_goto (tok->location, name);
5912 	  c_parser_consume_token (parser);
5913 	  TREE_USED (label) = 1;
5914 	}
5915       else
5916 	{
5917 	  c_parser_error (parser, "expected identifier");
5918 	  return NULL_TREE;
5919 	}
5920 
5921       name = build_string (IDENTIFIER_LENGTH (name),
5922 			   IDENTIFIER_POINTER (name));
5923       list = tree_cons (name, label, list);
5924       if (c_parser_next_token_is (parser, CPP_COMMA))
5925 	c_parser_consume_token (parser);
5926       else
5927 	return nreverse (list);
5928     }
5929 }
5930 
5931 /* Parse an expression other than a compound expression; that is, an
5932    assignment expression (C90 6.3.16, C99 6.5.16).  If AFTER is not
5933    NULL then it is an Objective-C message expression which is the
5934    primary-expression starting the expression as an initializer.
5935 
5936    assignment-expression:
5937      conditional-expression
5938      unary-expression assignment-operator assignment-expression
5939 
5940    assignment-operator: one of
5941      = *= /= %= += -= <<= >>= &= ^= |=
5942 
5943    In GNU C we accept any conditional expression on the LHS and
5944    diagnose the invalid lvalue rather than producing a syntax
5945    error.  */
5946 
5947 static struct c_expr
5948 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
5949 			 tree omp_atomic_lhs)
5950 {
5951   struct c_expr lhs, rhs, ret;
5952   enum tree_code code;
5953   location_t op_location, exp_location;
5954   gcc_assert (!after || c_dialect_objc ());
5955   lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
5956   op_location = c_parser_peek_token (parser)->location;
5957   switch (c_parser_peek_token (parser)->type)
5958     {
5959     case CPP_EQ:
5960       code = NOP_EXPR;
5961       break;
5962     case CPP_MULT_EQ:
5963       code = MULT_EXPR;
5964       break;
5965     case CPP_DIV_EQ:
5966       code = TRUNC_DIV_EXPR;
5967       break;
5968     case CPP_MOD_EQ:
5969       code = TRUNC_MOD_EXPR;
5970       break;
5971     case CPP_PLUS_EQ:
5972       code = PLUS_EXPR;
5973       break;
5974     case CPP_MINUS_EQ:
5975       code = MINUS_EXPR;
5976       break;
5977     case CPP_LSHIFT_EQ:
5978       code = LSHIFT_EXPR;
5979       break;
5980     case CPP_RSHIFT_EQ:
5981       code = RSHIFT_EXPR;
5982       break;
5983     case CPP_AND_EQ:
5984       code = BIT_AND_EXPR;
5985       break;
5986     case CPP_XOR_EQ:
5987       code = BIT_XOR_EXPR;
5988       break;
5989     case CPP_OR_EQ:
5990       code = BIT_IOR_EXPR;
5991       break;
5992     default:
5993       return lhs;
5994     }
5995   c_parser_consume_token (parser);
5996   exp_location = c_parser_peek_token (parser)->location;
5997   rhs = c_parser_expr_no_commas (parser, NULL);
5998   rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
5999 
6000   ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
6001 				 code, exp_location, rhs.value,
6002 				 rhs.original_type);
6003   if (code == NOP_EXPR)
6004     ret.original_code = MODIFY_EXPR;
6005   else
6006     {
6007       TREE_NO_WARNING (ret.value) = 1;
6008       ret.original_code = ERROR_MARK;
6009     }
6010   ret.original_type = NULL;
6011   return ret;
6012 }
6013 
6014 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15).  If AFTER
6015    is not NULL then it is an Objective-C message expression which is
6016    the primary-expression starting the expression as an initializer.
6017 
6018    conditional-expression:
6019      logical-OR-expression
6020      logical-OR-expression ? expression : conditional-expression
6021 
6022    GNU extensions:
6023 
6024    conditional-expression:
6025      logical-OR-expression ? : conditional-expression
6026 */
6027 
6028 static struct c_expr
6029 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6030 				 tree omp_atomic_lhs)
6031 {
6032   struct c_expr cond, exp1, exp2, ret;
6033   location_t cond_loc, colon_loc, middle_loc;
6034 
6035   gcc_assert (!after || c_dialect_objc ());
6036 
6037   cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6038 
6039   if (c_parser_next_token_is_not (parser, CPP_QUERY))
6040     return cond;
6041   cond_loc = c_parser_peek_token (parser)->location;
6042   cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6043   c_parser_consume_token (parser);
6044   if (c_parser_next_token_is (parser, CPP_COLON))
6045     {
6046       tree eptype = NULL_TREE;
6047 
6048       middle_loc = c_parser_peek_token (parser)->location;
6049       pedwarn (middle_loc, OPT_Wpedantic,
6050 	       "ISO C forbids omitting the middle term of a ?: expression");
6051       warn_for_omitted_condop (middle_loc, cond.value);
6052       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6053 	{
6054 	  eptype = TREE_TYPE (cond.value);
6055 	  cond.value = TREE_OPERAND (cond.value, 0);
6056 	}
6057       /* Make sure first operand is calculated only once.  */
6058       exp1.value = c_save_expr (default_conversion (cond.value));
6059       if (eptype)
6060 	exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6061       exp1.original_type = NULL;
6062       cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6063       c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6064     }
6065   else
6066     {
6067       cond.value
6068 	= c_objc_common_truthvalue_conversion
6069 	(cond_loc, default_conversion (cond.value));
6070       c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6071       exp1 = c_parser_expression_conv (parser);
6072       mark_exp_read (exp1.value);
6073       c_inhibit_evaluation_warnings +=
6074 	((cond.value == truthvalue_true_node)
6075 	 - (cond.value == truthvalue_false_node));
6076     }
6077 
6078   colon_loc = c_parser_peek_token (parser)->location;
6079   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6080     {
6081       c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6082       ret.value = error_mark_node;
6083       ret.original_code = ERROR_MARK;
6084       ret.original_type = NULL;
6085       return ret;
6086     }
6087   {
6088     location_t exp2_loc = c_parser_peek_token (parser)->location;
6089     exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6090     exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6091   }
6092   c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6093   ret.value = build_conditional_expr (colon_loc, cond.value,
6094 				      cond.original_code == C_MAYBE_CONST_EXPR,
6095 				      exp1.value, exp1.original_type,
6096 				      exp2.value, exp2.original_type);
6097   ret.original_code = ERROR_MARK;
6098   if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6099     ret.original_type = NULL;
6100   else
6101     {
6102       tree t1, t2;
6103 
6104       /* If both sides are enum type, the default conversion will have
6105 	 made the type of the result be an integer type.  We want to
6106 	 remember the enum types we started with.  */
6107       t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6108       t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6109       ret.original_type = ((t1 != error_mark_node
6110 			    && t2 != error_mark_node
6111 			    && (TYPE_MAIN_VARIANT (t1)
6112 				== TYPE_MAIN_VARIANT (t2)))
6113 			   ? t1
6114 			   : NULL);
6115     }
6116   return ret;
6117 }
6118 
6119 /* Parse a binary expression; that is, a logical-OR-expression (C90
6120    6.3.5-6.3.14, C99 6.5.5-6.5.14).  If AFTER is not NULL then it is
6121    an Objective-C message expression which is the primary-expression
6122    starting the expression as an initializer.
6123 
6124    OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6125    when it should be the unfolded lhs.  In a valid OpenMP source,
6126    one of the operands of the toplevel binary expression must be equal
6127    to it.  In that case, just return a build2 created binary operation
6128    rather than result of parser_build_binary_op.
6129 
6130    multiplicative-expression:
6131      cast-expression
6132      multiplicative-expression * cast-expression
6133      multiplicative-expression / cast-expression
6134      multiplicative-expression % cast-expression
6135 
6136    additive-expression:
6137      multiplicative-expression
6138      additive-expression + multiplicative-expression
6139      additive-expression - multiplicative-expression
6140 
6141    shift-expression:
6142      additive-expression
6143      shift-expression << additive-expression
6144      shift-expression >> additive-expression
6145 
6146    relational-expression:
6147      shift-expression
6148      relational-expression < shift-expression
6149      relational-expression > shift-expression
6150      relational-expression <= shift-expression
6151      relational-expression >= shift-expression
6152 
6153    equality-expression:
6154      relational-expression
6155      equality-expression == relational-expression
6156      equality-expression != relational-expression
6157 
6158    AND-expression:
6159      equality-expression
6160      AND-expression & equality-expression
6161 
6162    exclusive-OR-expression:
6163      AND-expression
6164      exclusive-OR-expression ^ AND-expression
6165 
6166    inclusive-OR-expression:
6167      exclusive-OR-expression
6168      inclusive-OR-expression | exclusive-OR-expression
6169 
6170    logical-AND-expression:
6171      inclusive-OR-expression
6172      logical-AND-expression && inclusive-OR-expression
6173 
6174    logical-OR-expression:
6175      logical-AND-expression
6176      logical-OR-expression || logical-AND-expression
6177 */
6178 
6179 static struct c_expr
6180 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6181 			    tree omp_atomic_lhs)
6182 {
6183   /* A binary expression is parsed using operator-precedence parsing,
6184      with the operands being cast expressions.  All the binary
6185      operators are left-associative.  Thus a binary expression is of
6186      form:
6187 
6188      E0 op1 E1 op2 E2 ...
6189 
6190      which we represent on a stack.  On the stack, the precedence
6191      levels are strictly increasing.  When a new operator is
6192      encountered of higher precedence than that at the top of the
6193      stack, it is pushed; its LHS is the top expression, and its RHS
6194      is everything parsed until it is popped.  When a new operator is
6195      encountered with precedence less than or equal to that at the top
6196      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6197      by the result of the operation until the operator at the top of
6198      the stack has lower precedence than the new operator or there is
6199      only one element on the stack; then the top expression is the LHS
6200      of the new operator.  In the case of logical AND and OR
6201      expressions, we also need to adjust c_inhibit_evaluation_warnings
6202      as appropriate when the operators are pushed and popped.  */
6203 
6204   struct {
6205     /* The expression at this stack level.  */
6206     struct c_expr expr;
6207     /* The precedence of the operator on its left, PREC_NONE at the
6208        bottom of the stack.  */
6209     enum c_parser_prec prec;
6210     /* The operation on its left.  */
6211     enum tree_code op;
6212     /* The source location of this operation.  */
6213     location_t loc;
6214   } stack[NUM_PRECS];
6215   int sp;
6216   /* Location of the binary operator.  */
6217   location_t binary_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
6218 #define POP								      \
6219   do {									      \
6220     switch (stack[sp].op)						      \
6221       {									      \
6222       case TRUTH_ANDIF_EXPR:						      \
6223 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
6224 					  == truthvalue_false_node);	      \
6225 	break;								      \
6226       case TRUTH_ORIF_EXPR:						      \
6227 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
6228 					  == truthvalue_true_node);	      \
6229 	break;								      \
6230       default:								      \
6231 	break;								      \
6232       }									      \
6233     stack[sp - 1].expr							      \
6234       = convert_lvalue_to_rvalue (stack[sp - 1].loc,			      \
6235 				  stack[sp - 1].expr, true, true);	      \
6236     stack[sp].expr							      \
6237       = convert_lvalue_to_rvalue (stack[sp].loc,			      \
6238 				  stack[sp].expr, true, true);		      \
6239     if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1	      \
6240 	&& c_parser_peek_token (parser)->type == CPP_SEMICOLON		      \
6241 	&& ((1 << stack[sp].prec)					      \
6242 	    & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND)    \
6243 	       | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT)))     \
6244 	&& stack[sp].op != TRUNC_MOD_EXPR				      \
6245 	&& stack[0].expr.value != error_mark_node			      \
6246 	&& stack[1].expr.value != error_mark_node			      \
6247 	&& (c_tree_equal (stack[0].expr.value, omp_atomic_lhs)		      \
6248 	    || c_tree_equal (stack[1].expr.value, omp_atomic_lhs)))	      \
6249       stack[0].expr.value						      \
6250 	= build2 (stack[1].op, TREE_TYPE (stack[0].expr.value),		      \
6251 		  stack[0].expr.value, stack[1].expr.value);		      \
6252     else								      \
6253       stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc,	      \
6254 						   stack[sp].op,	      \
6255 						   stack[sp - 1].expr,	      \
6256 						   stack[sp].expr);	      \
6257     sp--;								      \
6258   } while (0)
6259   gcc_assert (!after || c_dialect_objc ());
6260   stack[0].loc = c_parser_peek_token (parser)->location;
6261   stack[0].expr = c_parser_cast_expression (parser, after);
6262   stack[0].prec = PREC_NONE;
6263   sp = 0;
6264   while (true)
6265     {
6266       enum c_parser_prec oprec;
6267       enum tree_code ocode;
6268       if (parser->error)
6269 	goto out;
6270       switch (c_parser_peek_token (parser)->type)
6271 	{
6272 	case CPP_MULT:
6273 	  oprec = PREC_MULT;
6274 	  ocode = MULT_EXPR;
6275 	  break;
6276 	case CPP_DIV:
6277 	  oprec = PREC_MULT;
6278 	  ocode = TRUNC_DIV_EXPR;
6279 	  break;
6280 	case CPP_MOD:
6281 	  oprec = PREC_MULT;
6282 	  ocode = TRUNC_MOD_EXPR;
6283 	  break;
6284 	case CPP_PLUS:
6285 	  oprec = PREC_ADD;
6286 	  ocode = PLUS_EXPR;
6287 	  break;
6288 	case CPP_MINUS:
6289 	  oprec = PREC_ADD;
6290 	  ocode = MINUS_EXPR;
6291 	  break;
6292 	case CPP_LSHIFT:
6293 	  oprec = PREC_SHIFT;
6294 	  ocode = LSHIFT_EXPR;
6295 	  break;
6296 	case CPP_RSHIFT:
6297 	  oprec = PREC_SHIFT;
6298 	  ocode = RSHIFT_EXPR;
6299 	  break;
6300 	case CPP_LESS:
6301 	  oprec = PREC_REL;
6302 	  ocode = LT_EXPR;
6303 	  break;
6304 	case CPP_GREATER:
6305 	  oprec = PREC_REL;
6306 	  ocode = GT_EXPR;
6307 	  break;
6308 	case CPP_LESS_EQ:
6309 	  oprec = PREC_REL;
6310 	  ocode = LE_EXPR;
6311 	  break;
6312 	case CPP_GREATER_EQ:
6313 	  oprec = PREC_REL;
6314 	  ocode = GE_EXPR;
6315 	  break;
6316 	case CPP_EQ_EQ:
6317 	  oprec = PREC_EQ;
6318 	  ocode = EQ_EXPR;
6319 	  break;
6320 	case CPP_NOT_EQ:
6321 	  oprec = PREC_EQ;
6322 	  ocode = NE_EXPR;
6323 	  break;
6324 	case CPP_AND:
6325 	  oprec = PREC_BITAND;
6326 	  ocode = BIT_AND_EXPR;
6327 	  break;
6328 	case CPP_XOR:
6329 	  oprec = PREC_BITXOR;
6330 	  ocode = BIT_XOR_EXPR;
6331 	  break;
6332 	case CPP_OR:
6333 	  oprec = PREC_BITOR;
6334 	  ocode = BIT_IOR_EXPR;
6335 	  break;
6336 	case CPP_AND_AND:
6337 	  oprec = PREC_LOGAND;
6338 	  ocode = TRUTH_ANDIF_EXPR;
6339 	  break;
6340 	case CPP_OR_OR:
6341 	  oprec = PREC_LOGOR;
6342 	  ocode = TRUTH_ORIF_EXPR;
6343 	  break;
6344 	default:
6345 	  /* Not a binary operator, so end of the binary
6346 	     expression.  */
6347 	  goto out;
6348 	}
6349       binary_loc = c_parser_peek_token (parser)->location;
6350       while (oprec <= stack[sp].prec)
6351 	POP;
6352       c_parser_consume_token (parser);
6353       switch (ocode)
6354 	{
6355 	case TRUTH_ANDIF_EXPR:
6356 	  stack[sp].expr
6357 	    = convert_lvalue_to_rvalue (stack[sp].loc,
6358 					stack[sp].expr, true, true);
6359 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
6360 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
6361 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
6362 					    == truthvalue_false_node);
6363 	  break;
6364 	case TRUTH_ORIF_EXPR:
6365 	  stack[sp].expr
6366 	    = convert_lvalue_to_rvalue (stack[sp].loc,
6367 					stack[sp].expr, true, true);
6368 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
6369 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
6370 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
6371 					    == truthvalue_true_node);
6372 	  break;
6373 	default:
6374 	  break;
6375 	}
6376       sp++;
6377       stack[sp].loc = binary_loc;
6378       stack[sp].expr = c_parser_cast_expression (parser, NULL);
6379       stack[sp].prec = oprec;
6380       stack[sp].op = ocode;
6381       stack[sp].loc = binary_loc;
6382     }
6383  out:
6384   while (sp > 0)
6385     POP;
6386   return stack[0].expr;
6387 #undef POP
6388 }
6389 
6390 /* Parse a cast expression (C90 6.3.4, C99 6.5.4).  If AFTER is not
6391    NULL then it is an Objective-C message expression which is the
6392    primary-expression starting the expression as an initializer.
6393 
6394    cast-expression:
6395      unary-expression
6396      ( type-name ) unary-expression
6397 */
6398 
6399 static struct c_expr
6400 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
6401 {
6402   location_t cast_loc = c_parser_peek_token (parser)->location;
6403   gcc_assert (!after || c_dialect_objc ());
6404   if (after)
6405     return c_parser_postfix_expression_after_primary (parser,
6406 						      cast_loc, *after);
6407   /* If the expression begins with a parenthesized type name, it may
6408      be either a cast or a compound literal; we need to see whether
6409      the next character is '{' to tell the difference.  If not, it is
6410      an unary expression.  Full detection of unknown typenames here
6411      would require a 3-token lookahead.  */
6412   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6413       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6414     {
6415       struct c_type_name *type_name;
6416       struct c_expr ret;
6417       struct c_expr expr;
6418       c_parser_consume_token (parser);
6419       type_name = c_parser_type_name (parser);
6420       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6421       if (type_name == NULL)
6422 	{
6423 	  ret.value = error_mark_node;
6424 	  ret.original_code = ERROR_MARK;
6425 	  ret.original_type = NULL;
6426 	  return ret;
6427 	}
6428 
6429       /* Save casted types in the function's used types hash table.  */
6430       used_types_insert (type_name->specs->type);
6431 
6432       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6433 	return c_parser_postfix_expression_after_paren_type (parser, type_name,
6434 							     cast_loc);
6435       {
6436 	location_t expr_loc = c_parser_peek_token (parser)->location;
6437 	expr = c_parser_cast_expression (parser, NULL);
6438 	expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
6439       }
6440       ret.value = c_cast_expr (cast_loc, type_name, expr.value);
6441       ret.original_code = ERROR_MARK;
6442       ret.original_type = NULL;
6443       return ret;
6444     }
6445   else
6446     return c_parser_unary_expression (parser);
6447 }
6448 
6449 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6450 
6451    unary-expression:
6452      postfix-expression
6453      ++ unary-expression
6454      -- unary-expression
6455      unary-operator cast-expression
6456      sizeof unary-expression
6457      sizeof ( type-name )
6458 
6459    unary-operator: one of
6460      & * + - ~ !
6461 
6462    GNU extensions:
6463 
6464    unary-expression:
6465      __alignof__ unary-expression
6466      __alignof__ ( type-name )
6467      && identifier
6468 
6469    (C11 permits _Alignof with type names only.)
6470 
6471    unary-operator: one of
6472      __extension__ __real__ __imag__
6473 
6474    Transactional Memory:
6475 
6476    unary-expression:
6477      transaction-expression
6478 
6479    In addition, the GNU syntax treats ++ and -- as unary operators, so
6480    they may be applied to cast expressions with errors for non-lvalues
6481    given later.  */
6482 
6483 static struct c_expr
6484 c_parser_unary_expression (c_parser *parser)
6485 {
6486   int ext;
6487   struct c_expr ret, op;
6488   location_t op_loc = c_parser_peek_token (parser)->location;
6489   location_t exp_loc;
6490   ret.original_code = ERROR_MARK;
6491   ret.original_type = NULL;
6492   switch (c_parser_peek_token (parser)->type)
6493     {
6494     case CPP_PLUS_PLUS:
6495       c_parser_consume_token (parser);
6496       exp_loc = c_parser_peek_token (parser)->location;
6497       op = c_parser_cast_expression (parser, NULL);
6498 
6499       /* If there is array notations in op, we expand them.  */
6500       if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6501 	return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op);
6502       else
6503 	{
6504 	  op = default_function_array_read_conversion (exp_loc, op);
6505 	  return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
6506 	}
6507     case CPP_MINUS_MINUS:
6508       c_parser_consume_token (parser);
6509       exp_loc = c_parser_peek_token (parser)->location;
6510       op = c_parser_cast_expression (parser, NULL);
6511 
6512       /* If there is array notations in op, we expand them.  */
6513       if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6514 	return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op);
6515       else
6516 	{
6517 	  op = default_function_array_read_conversion (exp_loc, op);
6518 	  return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
6519 	}
6520     case CPP_AND:
6521       c_parser_consume_token (parser);
6522       op = c_parser_cast_expression (parser, NULL);
6523       mark_exp_read (op.value);
6524       return parser_build_unary_op (op_loc, ADDR_EXPR, op);
6525     case CPP_MULT:
6526       c_parser_consume_token (parser);
6527       exp_loc = c_parser_peek_token (parser)->location;
6528       op = c_parser_cast_expression (parser, NULL);
6529       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6530       ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
6531       return ret;
6532     case CPP_PLUS:
6533       if (!c_dialect_objc () && !in_system_header_at (input_location))
6534 	warning_at (op_loc,
6535 		    OPT_Wtraditional,
6536 		    "traditional C rejects the unary plus operator");
6537       c_parser_consume_token (parser);
6538       exp_loc = c_parser_peek_token (parser)->location;
6539       op = c_parser_cast_expression (parser, NULL);
6540       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6541       return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
6542     case CPP_MINUS:
6543       c_parser_consume_token (parser);
6544       exp_loc = c_parser_peek_token (parser)->location;
6545       op = c_parser_cast_expression (parser, NULL);
6546       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6547       return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
6548     case CPP_COMPL:
6549       c_parser_consume_token (parser);
6550       exp_loc = c_parser_peek_token (parser)->location;
6551       op = c_parser_cast_expression (parser, NULL);
6552       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6553       return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
6554     case CPP_NOT:
6555       c_parser_consume_token (parser);
6556       exp_loc = c_parser_peek_token (parser)->location;
6557       op = c_parser_cast_expression (parser, NULL);
6558       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6559       return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
6560     case CPP_AND_AND:
6561       /* Refer to the address of a label as a pointer.  */
6562       c_parser_consume_token (parser);
6563       if (c_parser_next_token_is (parser, CPP_NAME))
6564 	{
6565 	  ret.value = finish_label_address_expr
6566 	    (c_parser_peek_token (parser)->value, op_loc);
6567 	  c_parser_consume_token (parser);
6568 	}
6569       else
6570 	{
6571 	  c_parser_error (parser, "expected identifier");
6572 	  ret.value = error_mark_node;
6573 	}
6574 	return ret;
6575     case CPP_KEYWORD:
6576       switch (c_parser_peek_token (parser)->keyword)
6577 	{
6578 	case RID_SIZEOF:
6579 	  return c_parser_sizeof_expression (parser);
6580 	case RID_ALIGNOF:
6581 	  return c_parser_alignof_expression (parser);
6582 	case RID_EXTENSION:
6583 	  c_parser_consume_token (parser);
6584 	  ext = disable_extension_diagnostics ();
6585 	  ret = c_parser_cast_expression (parser, NULL);
6586 	  restore_extension_diagnostics (ext);
6587 	  return ret;
6588 	case RID_REALPART:
6589 	  c_parser_consume_token (parser);
6590 	  exp_loc = c_parser_peek_token (parser)->location;
6591 	  op = c_parser_cast_expression (parser, NULL);
6592 	  op = default_function_array_conversion (exp_loc, op);
6593 	  return parser_build_unary_op (op_loc, REALPART_EXPR, op);
6594 	case RID_IMAGPART:
6595 	  c_parser_consume_token (parser);
6596 	  exp_loc = c_parser_peek_token (parser)->location;
6597 	  op = c_parser_cast_expression (parser, NULL);
6598 	  op = default_function_array_conversion (exp_loc, op);
6599 	  return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
6600 	case RID_TRANSACTION_ATOMIC:
6601 	case RID_TRANSACTION_RELAXED:
6602 	  return c_parser_transaction_expression (parser,
6603 	      c_parser_peek_token (parser)->keyword);
6604 	default:
6605 	  return c_parser_postfix_expression (parser);
6606 	}
6607     default:
6608       return c_parser_postfix_expression (parser);
6609     }
6610 }
6611 
6612 /* Parse a sizeof expression.  */
6613 
6614 static struct c_expr
6615 c_parser_sizeof_expression (c_parser *parser)
6616 {
6617   struct c_expr expr;
6618   location_t expr_loc;
6619   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
6620   c_parser_consume_token (parser);
6621   c_inhibit_evaluation_warnings++;
6622   in_sizeof++;
6623   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6624       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6625     {
6626       /* Either sizeof ( type-name ) or sizeof unary-expression
6627 	 starting with a compound literal.  */
6628       struct c_type_name *type_name;
6629       c_parser_consume_token (parser);
6630       expr_loc = c_parser_peek_token (parser)->location;
6631       type_name = c_parser_type_name (parser);
6632       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6633       if (type_name == NULL)
6634 	{
6635 	  struct c_expr ret;
6636 	  c_inhibit_evaluation_warnings--;
6637 	  in_sizeof--;
6638 	  ret.value = error_mark_node;
6639 	  ret.original_code = ERROR_MARK;
6640 	  ret.original_type = NULL;
6641 	  return ret;
6642 	}
6643       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6644 	{
6645 	  expr = c_parser_postfix_expression_after_paren_type (parser,
6646 							       type_name,
6647 							       expr_loc);
6648 	  goto sizeof_expr;
6649 	}
6650       /* sizeof ( type-name ).  */
6651       c_inhibit_evaluation_warnings--;
6652       in_sizeof--;
6653       return c_expr_sizeof_type (expr_loc, type_name);
6654     }
6655   else
6656     {
6657       expr_loc = c_parser_peek_token (parser)->location;
6658       expr = c_parser_unary_expression (parser);
6659     sizeof_expr:
6660       c_inhibit_evaluation_warnings--;
6661       in_sizeof--;
6662       mark_exp_read (expr.value);
6663       if (TREE_CODE (expr.value) == COMPONENT_REF
6664 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
6665 	error_at (expr_loc, "%<sizeof%> applied to a bit-field");
6666       return c_expr_sizeof_expr (expr_loc, expr);
6667     }
6668 }
6669 
6670 /* Parse an alignof expression.  */
6671 
6672 static struct c_expr
6673 c_parser_alignof_expression (c_parser *parser)
6674 {
6675   struct c_expr expr;
6676   location_t loc = c_parser_peek_token (parser)->location;
6677   tree alignof_spelling = c_parser_peek_token (parser)->value;
6678   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
6679   bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
6680 				"_Alignof") == 0;
6681   /* A diagnostic is not required for the use of this identifier in
6682      the implementation namespace; only diagnose it for the C11
6683      spelling because of existing code using the other spellings.  */
6684   if (is_c11_alignof)
6685     {
6686       if (flag_isoc99)
6687 	pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
6688 		     alignof_spelling);
6689       else
6690 	pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
6691 		     alignof_spelling);
6692     }
6693   c_parser_consume_token (parser);
6694   c_inhibit_evaluation_warnings++;
6695   in_alignof++;
6696   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6697       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6698     {
6699       /* Either __alignof__ ( type-name ) or __alignof__
6700 	 unary-expression starting with a compound literal.  */
6701       location_t loc;
6702       struct c_type_name *type_name;
6703       struct c_expr ret;
6704       c_parser_consume_token (parser);
6705       loc = c_parser_peek_token (parser)->location;
6706       type_name = c_parser_type_name (parser);
6707       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6708       if (type_name == NULL)
6709 	{
6710 	  struct c_expr ret;
6711 	  c_inhibit_evaluation_warnings--;
6712 	  in_alignof--;
6713 	  ret.value = error_mark_node;
6714 	  ret.original_code = ERROR_MARK;
6715 	  ret.original_type = NULL;
6716 	  return ret;
6717 	}
6718       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6719 	{
6720 	  expr = c_parser_postfix_expression_after_paren_type (parser,
6721 							       type_name,
6722 							       loc);
6723 	  goto alignof_expr;
6724 	}
6725       /* alignof ( type-name ).  */
6726       c_inhibit_evaluation_warnings--;
6727       in_alignof--;
6728       ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
6729 							       NULL, NULL),
6730 					    false, is_c11_alignof, 1);
6731       ret.original_code = ERROR_MARK;
6732       ret.original_type = NULL;
6733       return ret;
6734     }
6735   else
6736     {
6737       struct c_expr ret;
6738       expr = c_parser_unary_expression (parser);
6739     alignof_expr:
6740       mark_exp_read (expr.value);
6741       c_inhibit_evaluation_warnings--;
6742       in_alignof--;
6743       pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
6744 	       alignof_spelling);
6745       ret.value = c_alignof_expr (loc, expr.value);
6746       ret.original_code = ERROR_MARK;
6747       ret.original_type = NULL;
6748       return ret;
6749     }
6750 }
6751 
6752 /* Helper function to read arguments of builtins which are interfaces
6753    for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6754    others.  The name of the builtin is passed using BNAME parameter.
6755    Function returns true if there were no errors while parsing and
6756    stores the arguments in CEXPR_LIST.  */
6757 static bool
6758 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6759 			   vec<c_expr_t, va_gc> **ret_cexpr_list,
6760 			   bool choose_expr_p)
6761 {
6762   location_t loc = c_parser_peek_token (parser)->location;
6763   vec<c_expr_t, va_gc> *cexpr_list;
6764   c_expr_t expr;
6765   bool saved_force_folding_builtin_constant_p;
6766 
6767   *ret_cexpr_list = NULL;
6768   if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6769     {
6770       error_at (loc, "cannot take address of %qs", bname);
6771       return false;
6772     }
6773 
6774   c_parser_consume_token (parser);
6775 
6776   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6777     {
6778       c_parser_consume_token (parser);
6779       return true;
6780     }
6781 
6782   saved_force_folding_builtin_constant_p
6783     = force_folding_builtin_constant_p;
6784   force_folding_builtin_constant_p |= choose_expr_p;
6785   expr = c_parser_expr_no_commas (parser, NULL);
6786   force_folding_builtin_constant_p
6787     = saved_force_folding_builtin_constant_p;
6788   vec_alloc (cexpr_list, 1);
6789   vec_safe_push (cexpr_list, expr);
6790   while (c_parser_next_token_is (parser, CPP_COMMA))
6791     {
6792       c_parser_consume_token (parser);
6793       expr = c_parser_expr_no_commas (parser, NULL);
6794       vec_safe_push (cexpr_list, expr);
6795     }
6796 
6797   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6798     return false;
6799 
6800   *ret_cexpr_list = cexpr_list;
6801   return true;
6802 }
6803 
6804 /* This represents a single generic-association.  */
6805 
6806 struct c_generic_association
6807 {
6808   /* The location of the starting token of the type.  */
6809   location_t type_location;
6810   /* The association's type, or NULL_TREE for 'default'.  */
6811   tree type;
6812   /* The association's expression.  */
6813   struct c_expr expression;
6814 };
6815 
6816 /* Parse a generic-selection.  (C11 6.5.1.1).
6817 
6818    generic-selection:
6819      _Generic ( assignment-expression , generic-assoc-list )
6820 
6821    generic-assoc-list:
6822      generic-association
6823      generic-assoc-list , generic-association
6824 
6825    generic-association:
6826      type-name : assignment-expression
6827      default : assignment-expression
6828 */
6829 
6830 static struct c_expr
6831 c_parser_generic_selection (c_parser *parser)
6832 {
6833   vec<c_generic_association> associations = vNULL;
6834   struct c_expr selector, error_expr;
6835   tree selector_type;
6836   struct c_generic_association matched_assoc;
6837   bool match_found = false;
6838   location_t generic_loc, selector_loc;
6839 
6840   error_expr.original_code = ERROR_MARK;
6841   error_expr.original_type = NULL;
6842   error_expr.value = error_mark_node;
6843   matched_assoc.type_location = UNKNOWN_LOCATION;
6844   matched_assoc.type = NULL_TREE;
6845   matched_assoc.expression = error_expr;
6846 
6847   gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
6848   generic_loc = c_parser_peek_token (parser)->location;
6849   c_parser_consume_token (parser);
6850   if (flag_isoc99)
6851     pedwarn_c99 (generic_loc, OPT_Wpedantic,
6852 		 "ISO C99 does not support %<_Generic%>");
6853   else
6854     pedwarn_c99 (generic_loc, OPT_Wpedantic,
6855 		 "ISO C90 does not support %<_Generic%>");
6856 
6857   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6858     return error_expr;
6859 
6860   c_inhibit_evaluation_warnings++;
6861   selector_loc = c_parser_peek_token (parser)->location;
6862   selector = c_parser_expr_no_commas (parser, NULL);
6863   selector = default_function_array_conversion (selector_loc, selector);
6864   c_inhibit_evaluation_warnings--;
6865 
6866   if (selector.value == error_mark_node)
6867     {
6868       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6869       return selector;
6870     }
6871   selector_type = TREE_TYPE (selector.value);
6872   /* In ISO C terms, rvalues (including the controlling expression of
6873      _Generic) do not have qualified types.  */
6874   if (TREE_CODE (selector_type) != ARRAY_TYPE)
6875     selector_type = TYPE_MAIN_VARIANT (selector_type);
6876   /* In ISO C terms, _Noreturn is not part of the type of expressions
6877      such as &abort, but in GCC it is represented internally as a type
6878      qualifier.  */
6879   if (FUNCTION_POINTER_TYPE_P (selector_type)
6880       && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
6881     selector_type
6882       = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
6883 
6884   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6885     {
6886       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6887       return error_expr;
6888     }
6889 
6890   while (1)
6891     {
6892       struct c_generic_association assoc, *iter;
6893       unsigned int ix;
6894       c_token *token = c_parser_peek_token (parser);
6895 
6896       assoc.type_location = token->location;
6897       if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
6898 	{
6899 	  c_parser_consume_token (parser);
6900 	  assoc.type = NULL_TREE;
6901 	}
6902       else
6903 	{
6904 	  struct c_type_name *type_name;
6905 
6906 	  type_name = c_parser_type_name (parser);
6907 	  if (type_name == NULL)
6908 	    {
6909 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6910 	      goto error_exit;
6911 	    }
6912 	  assoc.type = groktypename (type_name, NULL, NULL);
6913 	  if (assoc.type == error_mark_node)
6914 	    {
6915 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6916 	      goto error_exit;
6917 	    }
6918 
6919 	  if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
6920 	    error_at (assoc.type_location,
6921 		      "%<_Generic%> association has function type");
6922 	  else if (!COMPLETE_TYPE_P (assoc.type))
6923 	    error_at (assoc.type_location,
6924 		      "%<_Generic%> association has incomplete type");
6925 
6926 	  if (variably_modified_type_p (assoc.type, NULL_TREE))
6927 	    error_at (assoc.type_location,
6928 		      "%<_Generic%> association has "
6929 		      "variable length type");
6930 	}
6931 
6932       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6933 	{
6934 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6935 	  goto error_exit;
6936 	}
6937 
6938       assoc.expression = c_parser_expr_no_commas (parser, NULL);
6939       if (assoc.expression.value == error_mark_node)
6940 	{
6941 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6942 	  goto error_exit;
6943 	}
6944 
6945       for (ix = 0; associations.iterate (ix, &iter); ++ix)
6946 	{
6947 	  if (assoc.type == NULL_TREE)
6948 	    {
6949 	      if (iter->type == NULL_TREE)
6950 		{
6951 		  error_at (assoc.type_location,
6952 			    "duplicate %<default%> case in %<_Generic%>");
6953 		  inform (iter->type_location, "original %<default%> is here");
6954 		}
6955 	    }
6956 	  else if (iter->type != NULL_TREE)
6957 	    {
6958 	      if (comptypes (assoc.type, iter->type))
6959 		{
6960 		  error_at (assoc.type_location,
6961 			    "%<_Generic%> specifies two compatible types");
6962 		  inform (iter->type_location, "compatible type is here");
6963 		}
6964 	    }
6965 	}
6966 
6967       if (assoc.type == NULL_TREE)
6968 	{
6969 	  if (!match_found)
6970 	    {
6971 	      matched_assoc = assoc;
6972 	      match_found = true;
6973 	    }
6974 	}
6975       else if (comptypes (assoc.type, selector_type))
6976 	{
6977 	  if (!match_found || matched_assoc.type == NULL_TREE)
6978 	    {
6979 	      matched_assoc = assoc;
6980 	      match_found = true;
6981 	    }
6982 	  else
6983 	    {
6984 	      error_at (assoc.type_location,
6985 			"%<_Generic> selector matches multiple associations");
6986 	      inform (matched_assoc.type_location,
6987 		      "other match is here");
6988 	    }
6989 	}
6990 
6991       associations.safe_push (assoc);
6992 
6993       if (c_parser_peek_token (parser)->type != CPP_COMMA)
6994 	break;
6995       c_parser_consume_token (parser);
6996     }
6997 
6998   associations.release ();
6999 
7000   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7001     {
7002       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7003       return error_expr;
7004     }
7005 
7006   if (!match_found)
7007     {
7008       error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7009 		"compatible with any association",
7010 		selector_type);
7011       return error_expr;
7012     }
7013 
7014   return matched_assoc.expression;
7015 
7016  error_exit:
7017   associations.release ();
7018   return error_expr;
7019 }
7020 
7021 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7022 
7023    postfix-expression:
7024      primary-expression
7025      postfix-expression [ expression ]
7026      postfix-expression ( argument-expression-list[opt] )
7027      postfix-expression . identifier
7028      postfix-expression -> identifier
7029      postfix-expression ++
7030      postfix-expression --
7031      ( type-name ) { initializer-list }
7032      ( type-name ) { initializer-list , }
7033 
7034    argument-expression-list:
7035      argument-expression
7036      argument-expression-list , argument-expression
7037 
7038    primary-expression:
7039      identifier
7040      constant
7041      string-literal
7042      ( expression )
7043      generic-selection
7044 
7045    GNU extensions:
7046 
7047    primary-expression:
7048      __func__
7049        (treated as a keyword in GNU C)
7050      __FUNCTION__
7051      __PRETTY_FUNCTION__
7052      ( compound-statement )
7053      __builtin_va_arg ( assignment-expression , type-name )
7054      __builtin_offsetof ( type-name , offsetof-member-designator )
7055      __builtin_choose_expr ( assignment-expression ,
7056 			     assignment-expression ,
7057 			     assignment-expression )
7058      __builtin_types_compatible_p ( type-name , type-name )
7059      __builtin_complex ( assignment-expression , assignment-expression )
7060      __builtin_shuffle ( assignment-expression , assignment-expression )
7061      __builtin_shuffle ( assignment-expression ,
7062 			 assignment-expression ,
7063 			 assignment-expression, )
7064 
7065    offsetof-member-designator:
7066      identifier
7067      offsetof-member-designator . identifier
7068      offsetof-member-designator [ expression ]
7069 
7070    Objective-C:
7071 
7072    primary-expression:
7073      [ objc-receiver objc-message-args ]
7074      @selector ( objc-selector-arg )
7075      @protocol ( identifier )
7076      @encode ( type-name )
7077      objc-string-literal
7078      Classname . identifier
7079 */
7080 
7081 static struct c_expr
7082 c_parser_postfix_expression (c_parser *parser)
7083 {
7084   struct c_expr expr, e1;
7085   struct c_type_name *t1, *t2;
7086   location_t loc = c_parser_peek_token (parser)->location;;
7087   expr.original_code = ERROR_MARK;
7088   expr.original_type = NULL;
7089   switch (c_parser_peek_token (parser)->type)
7090     {
7091     case CPP_NUMBER:
7092       expr.value = c_parser_peek_token (parser)->value;
7093       loc = c_parser_peek_token (parser)->location;
7094       c_parser_consume_token (parser);
7095       if (TREE_CODE (expr.value) == FIXED_CST
7096 	  && !targetm.fixed_point_supported_p ())
7097 	{
7098 	  error_at (loc, "fixed-point types not supported for this target");
7099 	  expr.value = error_mark_node;
7100 	}
7101       break;
7102     case CPP_CHAR:
7103     case CPP_CHAR16:
7104     case CPP_CHAR32:
7105     case CPP_WCHAR:
7106       expr.value = c_parser_peek_token (parser)->value;
7107       c_parser_consume_token (parser);
7108       break;
7109     case CPP_STRING:
7110     case CPP_STRING16:
7111     case CPP_STRING32:
7112     case CPP_WSTRING:
7113     case CPP_UTF8STRING:
7114       expr.value = c_parser_peek_token (parser)->value;
7115       expr.original_code = STRING_CST;
7116       c_parser_consume_token (parser);
7117       break;
7118     case CPP_OBJC_STRING:
7119       gcc_assert (c_dialect_objc ());
7120       expr.value
7121 	= objc_build_string_object (c_parser_peek_token (parser)->value);
7122       c_parser_consume_token (parser);
7123       break;
7124     case CPP_NAME:
7125       switch (c_parser_peek_token (parser)->id_kind)
7126 	{
7127 	case C_ID_ID:
7128 	  {
7129 	    tree id = c_parser_peek_token (parser)->value;
7130 	    c_parser_consume_token (parser);
7131 	    expr.value = build_external_ref (loc, id,
7132 					     (c_parser_peek_token (parser)->type
7133 					      == CPP_OPEN_PAREN),
7134 					     &expr.original_type);
7135 	    break;
7136 	  }
7137 	case C_ID_CLASSNAME:
7138 	  {
7139 	    /* Here we parse the Objective-C 2.0 Class.name dot
7140 	       syntax.  */
7141 	    tree class_name = c_parser_peek_token (parser)->value;
7142 	    tree component;
7143 	    c_parser_consume_token (parser);
7144 	    gcc_assert (c_dialect_objc ());
7145 	    if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7146 	      {
7147 		expr.value = error_mark_node;
7148 		break;
7149 	      }
7150 	    if (c_parser_next_token_is_not (parser, CPP_NAME))
7151 	      {
7152 		c_parser_error (parser, "expected identifier");
7153 		expr.value = error_mark_node;
7154 		break;
7155 	      }
7156 	    component = c_parser_peek_token (parser)->value;
7157 	    c_parser_consume_token (parser);
7158 	    expr.value = objc_build_class_component_ref (class_name,
7159 							 component);
7160 	    break;
7161 	  }
7162 	default:
7163 	  c_parser_error (parser, "expected expression");
7164 	  expr.value = error_mark_node;
7165 	  break;
7166 	}
7167       break;
7168     case CPP_OPEN_PAREN:
7169       /* A parenthesized expression, statement expression or compound
7170 	 literal.  */
7171       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7172 	{
7173 	  /* A statement expression.  */
7174 	  tree stmt;
7175 	  location_t brace_loc;
7176 	  c_parser_consume_token (parser);
7177 	  brace_loc = c_parser_peek_token (parser)->location;
7178 	  c_parser_consume_token (parser);
7179 	  if (!building_stmt_list_p ())
7180 	    {
7181 	      error_at (loc, "braced-group within expression allowed "
7182 			"only inside a function");
7183 	      parser->error = true;
7184 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7185 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7186 	      expr.value = error_mark_node;
7187 	      break;
7188 	    }
7189 	  stmt = c_begin_stmt_expr ();
7190 	  c_parser_compound_statement_nostart (parser);
7191 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7192 				     "expected %<)%>");
7193 	  pedwarn (loc, OPT_Wpedantic,
7194 		   "ISO C forbids braced-groups within expressions");
7195 	  expr.value = c_finish_stmt_expr (brace_loc, stmt);
7196 	  mark_exp_read (expr.value);
7197 	}
7198       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7199 	{
7200 	  /* A compound literal.  ??? Can we actually get here rather
7201 	     than going directly to
7202 	     c_parser_postfix_expression_after_paren_type from
7203 	     elsewhere?  */
7204 	  location_t loc;
7205 	  struct c_type_name *type_name;
7206 	  c_parser_consume_token (parser);
7207 	  loc = c_parser_peek_token (parser)->location;
7208 	  type_name = c_parser_type_name (parser);
7209 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7210 				     "expected %<)%>");
7211 	  if (type_name == NULL)
7212 	    {
7213 	      expr.value = error_mark_node;
7214 	    }
7215 	  else
7216 	    expr = c_parser_postfix_expression_after_paren_type (parser,
7217 								 type_name,
7218 								 loc);
7219 	}
7220       else
7221 	{
7222 	  /* A parenthesized expression.  */
7223 	  c_parser_consume_token (parser);
7224 	  expr = c_parser_expression (parser);
7225 	  if (TREE_CODE (expr.value) == MODIFY_EXPR)
7226 	    TREE_NO_WARNING (expr.value) = 1;
7227 	  if (expr.original_code != C_MAYBE_CONST_EXPR)
7228 	    expr.original_code = ERROR_MARK;
7229 	  /* Don't change EXPR.ORIGINAL_TYPE.  */
7230 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7231 				     "expected %<)%>");
7232 	}
7233       break;
7234     case CPP_KEYWORD:
7235       switch (c_parser_peek_token (parser)->keyword)
7236 	{
7237 	case RID_FUNCTION_NAME:
7238 	  pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7239 		   "%<__FUNCTION__%> predefined identifier");
7240 	  expr.value = fname_decl (loc,
7241 				   c_parser_peek_token (parser)->keyword,
7242 				   c_parser_peek_token (parser)->value);
7243 	  c_parser_consume_token (parser);
7244 	  break;
7245 	case RID_PRETTY_FUNCTION_NAME:
7246 	  pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7247 		   "%<__PRETTY_FUNCTION__%> predefined identifier");
7248 	  expr.value = fname_decl (loc,
7249 				   c_parser_peek_token (parser)->keyword,
7250 				   c_parser_peek_token (parser)->value);
7251 	  c_parser_consume_token (parser);
7252 	  break;
7253 	case RID_C99_FUNCTION_NAME:
7254 	  pedwarn_c90 (loc, OPT_Wpedantic,  "ISO C90 does not support "
7255 		   "%<__func__%> predefined identifier");
7256 	  expr.value = fname_decl (loc,
7257 				   c_parser_peek_token (parser)->keyword,
7258 				   c_parser_peek_token (parser)->value);
7259 	  c_parser_consume_token (parser);
7260 	  break;
7261 	case RID_VA_ARG:
7262 	  c_parser_consume_token (parser);
7263 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7264 	    {
7265 	      expr.value = error_mark_node;
7266 	      break;
7267 	    }
7268 	  e1 = c_parser_expr_no_commas (parser, NULL);
7269 	  mark_exp_read (e1.value);
7270 	  e1.value = c_fully_fold (e1.value, false, NULL);
7271 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7272 	    {
7273 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7274 	      expr.value = error_mark_node;
7275 	      break;
7276 	    }
7277 	  loc = c_parser_peek_token (parser)->location;
7278 	  t1 = c_parser_type_name (parser);
7279 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7280 				     "expected %<)%>");
7281 	  if (t1 == NULL)
7282 	    {
7283 	      expr.value = error_mark_node;
7284 	    }
7285 	  else
7286 	    {
7287 	      tree type_expr = NULL_TREE;
7288 	      expr.value = c_build_va_arg (loc, e1.value,
7289 					   groktypename (t1, &type_expr, NULL));
7290 	      if (type_expr)
7291 		{
7292 		  expr.value = build2 (C_MAYBE_CONST_EXPR,
7293 				       TREE_TYPE (expr.value), type_expr,
7294 				       expr.value);
7295 		  C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
7296 		}
7297 	    }
7298 	  break;
7299 	case RID_OFFSETOF:
7300 	  c_parser_consume_token (parser);
7301 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7302 	    {
7303 	      expr.value = error_mark_node;
7304 	      break;
7305 	    }
7306 	  t1 = c_parser_type_name (parser);
7307 	  if (t1 == NULL)
7308 	    parser->error = true;
7309 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7310             gcc_assert (parser->error);
7311 	  if (parser->error)
7312 	    {
7313 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7314 	      expr.value = error_mark_node;
7315 	      break;
7316 	    }
7317 
7318 	  {
7319 	    tree type = groktypename (t1, NULL, NULL);
7320 	    tree offsetof_ref;
7321 	    if (type == error_mark_node)
7322 	      offsetof_ref = error_mark_node;
7323 	    else
7324 	      {
7325 		offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
7326 		SET_EXPR_LOCATION (offsetof_ref, loc);
7327 	      }
7328 	    /* Parse the second argument to __builtin_offsetof.  We
7329 	       must have one identifier, and beyond that we want to
7330 	       accept sub structure and sub array references.  */
7331 	    if (c_parser_next_token_is (parser, CPP_NAME))
7332 	      {
7333 		offsetof_ref = build_component_ref
7334 		  (loc, offsetof_ref, c_parser_peek_token (parser)->value);
7335 		c_parser_consume_token (parser);
7336 		while (c_parser_next_token_is (parser, CPP_DOT)
7337 		       || c_parser_next_token_is (parser,
7338 						  CPP_OPEN_SQUARE)
7339 		       || c_parser_next_token_is (parser,
7340 						  CPP_DEREF))
7341 		  {
7342 		    if (c_parser_next_token_is (parser, CPP_DEREF))
7343 		      {
7344 			loc = c_parser_peek_token (parser)->location;
7345 			offsetof_ref = build_array_ref (loc,
7346 							offsetof_ref,
7347 							integer_zero_node);
7348 			goto do_dot;
7349 		      }
7350 		    else if (c_parser_next_token_is (parser, CPP_DOT))
7351 		      {
7352 		      do_dot:
7353 			c_parser_consume_token (parser);
7354 			if (c_parser_next_token_is_not (parser,
7355 							CPP_NAME))
7356 			  {
7357 			    c_parser_error (parser, "expected identifier");
7358 			    break;
7359 			  }
7360 			offsetof_ref = build_component_ref
7361 			  (loc, offsetof_ref,
7362 			   c_parser_peek_token (parser)->value);
7363 			c_parser_consume_token (parser);
7364 		      }
7365 		    else
7366 		      {
7367 			struct c_expr ce;
7368 			tree idx;
7369 			loc = c_parser_peek_token (parser)->location;
7370 			c_parser_consume_token (parser);
7371 			ce = c_parser_expression (parser);
7372 			ce = convert_lvalue_to_rvalue (loc, ce, false, false);
7373 			idx = ce.value;
7374 			idx = c_fully_fold (idx, false, NULL);
7375 			c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7376 						   "expected %<]%>");
7377 			offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
7378 		      }
7379 		  }
7380 	      }
7381 	    else
7382 	      c_parser_error (parser, "expected identifier");
7383 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7384 				       "expected %<)%>");
7385 	    expr.value = fold_offsetof (offsetof_ref);
7386 	  }
7387 	  break;
7388 	case RID_CHOOSE_EXPR:
7389 	  {
7390 	    vec<c_expr_t, va_gc> *cexpr_list;
7391 	    c_expr_t *e1_p, *e2_p, *e3_p;
7392 	    tree c;
7393 
7394 	    c_parser_consume_token (parser);
7395 	    if (!c_parser_get_builtin_args (parser,
7396 					    "__builtin_choose_expr",
7397 					    &cexpr_list, true))
7398 	      {
7399 		expr.value = error_mark_node;
7400 		break;
7401 	      }
7402 
7403 	    if (vec_safe_length (cexpr_list) != 3)
7404 	      {
7405 		error_at (loc, "wrong number of arguments to "
7406 			       "%<__builtin_choose_expr%>");
7407 		expr.value = error_mark_node;
7408 		break;
7409 	      }
7410 
7411 	    e1_p = &(*cexpr_list)[0];
7412 	    e2_p = &(*cexpr_list)[1];
7413 	    e3_p = &(*cexpr_list)[2];
7414 
7415 	    c = e1_p->value;
7416 	    mark_exp_read (e2_p->value);
7417 	    mark_exp_read (e3_p->value);
7418 	    if (TREE_CODE (c) != INTEGER_CST
7419 		|| !INTEGRAL_TYPE_P (TREE_TYPE (c)))
7420 	      error_at (loc,
7421 			"first argument to %<__builtin_choose_expr%> not"
7422 			" a constant");
7423 	    constant_expression_warning (c);
7424 	    expr = integer_zerop (c) ? *e3_p : *e2_p;
7425 	    break;
7426 	  }
7427 	case RID_TYPES_COMPATIBLE_P:
7428 	  c_parser_consume_token (parser);
7429 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7430 	    {
7431 	      expr.value = error_mark_node;
7432 	      break;
7433 	    }
7434 	  t1 = c_parser_type_name (parser);
7435 	  if (t1 == NULL)
7436 	    {
7437 	      expr.value = error_mark_node;
7438 	      break;
7439 	    }
7440 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7441 	    {
7442 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7443 	      expr.value = error_mark_node;
7444 	      break;
7445 	    }
7446 	  t2 = c_parser_type_name (parser);
7447 	  if (t2 == NULL)
7448 	    {
7449 	      expr.value = error_mark_node;
7450 	      break;
7451 	    }
7452 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7453 				     "expected %<)%>");
7454 	  {
7455 	    tree e1, e2;
7456 	    e1 = groktypename (t1, NULL, NULL);
7457 	    e2 = groktypename (t2, NULL, NULL);
7458 	    if (e1 == error_mark_node || e2 == error_mark_node)
7459 	      {
7460 		expr.value = error_mark_node;
7461 		break;
7462 	      }
7463 
7464 	    e1 = TYPE_MAIN_VARIANT (e1);
7465 	    e2 = TYPE_MAIN_VARIANT (e2);
7466 
7467 	    expr.value
7468 	      = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
7469 	  }
7470 	  break;
7471 	case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
7472 	  {
7473 	    vec<c_expr_t, va_gc> *cexpr_list;
7474 	    c_expr_t *e2_p;
7475 	    tree chain_value;
7476 
7477 	    c_parser_consume_token (parser);
7478 	    if (!c_parser_get_builtin_args (parser,
7479 					    "__builtin_call_with_static_chain",
7480 					    &cexpr_list, false))
7481 	      {
7482 		expr.value = error_mark_node;
7483 		break;
7484 	      }
7485 	    if (vec_safe_length (cexpr_list) != 2)
7486 	      {
7487 		error_at (loc, "wrong number of arguments to "
7488 			       "%<__builtin_call_with_static_chain%>");
7489 		expr.value = error_mark_node;
7490 		break;
7491 	      }
7492 
7493 	    expr = (*cexpr_list)[0];
7494 	    e2_p = &(*cexpr_list)[1];
7495 	    *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7496 	    chain_value = e2_p->value;
7497 	    mark_exp_read (chain_value);
7498 
7499 	    if (TREE_CODE (expr.value) != CALL_EXPR)
7500 	      error_at (loc, "first argument to "
7501 			"%<__builtin_call_with_static_chain%> "
7502 			"must be a call expression");
7503 	    else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
7504 	      error_at (loc, "second argument to "
7505 			"%<__builtin_call_with_static_chain%> "
7506 			"must be a pointer type");
7507 	    else
7508 	      CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
7509 	    break;
7510 	  }
7511 	case RID_BUILTIN_COMPLEX:
7512 	  {
7513 	    vec<c_expr_t, va_gc> *cexpr_list;
7514 	    c_expr_t *e1_p, *e2_p;
7515 
7516 	    c_parser_consume_token (parser);
7517 	    if (!c_parser_get_builtin_args (parser,
7518 					    "__builtin_complex",
7519 					    &cexpr_list, false))
7520 	      {
7521 		expr.value = error_mark_node;
7522 		break;
7523 	      }
7524 
7525 	    if (vec_safe_length (cexpr_list) != 2)
7526 	      {
7527 		error_at (loc, "wrong number of arguments to "
7528 			       "%<__builtin_complex%>");
7529 		expr.value = error_mark_node;
7530 		break;
7531 	      }
7532 
7533 	    e1_p = &(*cexpr_list)[0];
7534 	    e2_p = &(*cexpr_list)[1];
7535 
7536 	    *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
7537 	    if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
7538 	      e1_p->value = convert (TREE_TYPE (e1_p->value),
7539 				     TREE_OPERAND (e1_p->value, 0));
7540 	    *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7541 	    if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
7542 	      e2_p->value = convert (TREE_TYPE (e2_p->value),
7543 				     TREE_OPERAND (e2_p->value, 0));
7544 	    if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7545 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7546 		|| !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
7547 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
7548 	      {
7549 		error_at (loc, "%<__builtin_complex%> operand "
7550 			  "not of real binary floating-point type");
7551 		expr.value = error_mark_node;
7552 		break;
7553 	      }
7554 	    if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
7555 		!= TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
7556 	      {
7557 		error_at (loc,
7558 			  "%<__builtin_complex%> operands of different types");
7559 		expr.value = error_mark_node;
7560 		break;
7561 	      }
7562 	    pedwarn_c90 (loc, OPT_Wpedantic,
7563 			 "ISO C90 does not support complex types");
7564 	    expr.value = build2 (COMPLEX_EXPR,
7565 				 build_complex_type
7566 				   (TYPE_MAIN_VARIANT
7567 				     (TREE_TYPE (e1_p->value))),
7568 				 e1_p->value, e2_p->value);
7569 	    break;
7570 	  }
7571 	case RID_BUILTIN_SHUFFLE:
7572 	  {
7573 	    vec<c_expr_t, va_gc> *cexpr_list;
7574 	    unsigned int i;
7575 	    c_expr_t *p;
7576 
7577 	    c_parser_consume_token (parser);
7578 	    if (!c_parser_get_builtin_args (parser,
7579 					    "__builtin_shuffle",
7580 					    &cexpr_list, false))
7581 	      {
7582 		expr.value = error_mark_node;
7583 		break;
7584 	      }
7585 
7586 	    FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
7587 	      *p = convert_lvalue_to_rvalue (loc, *p, true, true);
7588 
7589 	    if (vec_safe_length (cexpr_list) == 2)
7590 	      expr.value =
7591 		c_build_vec_perm_expr
7592 		  (loc, (*cexpr_list)[0].value,
7593 		   NULL_TREE, (*cexpr_list)[1].value);
7594 
7595 	    else if (vec_safe_length (cexpr_list) == 3)
7596 	      expr.value =
7597 		c_build_vec_perm_expr
7598 		  (loc, (*cexpr_list)[0].value,
7599 		   (*cexpr_list)[1].value,
7600 		   (*cexpr_list)[2].value);
7601 	    else
7602 	      {
7603 		error_at (loc, "wrong number of arguments to "
7604 			       "%<__builtin_shuffle%>");
7605 		expr.value = error_mark_node;
7606 	      }
7607 	    break;
7608 	  }
7609 	case RID_AT_SELECTOR:
7610 	  gcc_assert (c_dialect_objc ());
7611 	  c_parser_consume_token (parser);
7612 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7613 	    {
7614 	      expr.value = error_mark_node;
7615 	      break;
7616 	    }
7617 	  {
7618 	    tree sel = c_parser_objc_selector_arg (parser);
7619 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7620 				       "expected %<)%>");
7621 	    expr.value = objc_build_selector_expr (loc, sel);
7622 	  }
7623 	  break;
7624 	case RID_AT_PROTOCOL:
7625 	  gcc_assert (c_dialect_objc ());
7626 	  c_parser_consume_token (parser);
7627 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7628 	    {
7629 	      expr.value = error_mark_node;
7630 	      break;
7631 	    }
7632 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
7633 	    {
7634 	      c_parser_error (parser, "expected identifier");
7635 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7636 	      expr.value = error_mark_node;
7637 	      break;
7638 	    }
7639 	  {
7640 	    tree id = c_parser_peek_token (parser)->value;
7641 	    c_parser_consume_token (parser);
7642 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7643 				       "expected %<)%>");
7644 	    expr.value = objc_build_protocol_expr (id);
7645 	  }
7646 	  break;
7647 	case RID_AT_ENCODE:
7648 	  /* Extension to support C-structures in the archiver.  */
7649 	  gcc_assert (c_dialect_objc ());
7650 	  c_parser_consume_token (parser);
7651 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7652 	    {
7653 	      expr.value = error_mark_node;
7654 	      break;
7655 	    }
7656 	  t1 = c_parser_type_name (parser);
7657 	  if (t1 == NULL)
7658 	    {
7659 	      expr.value = error_mark_node;
7660 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7661 	      break;
7662 	    }
7663 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7664 				     "expected %<)%>");
7665 	  {
7666 	    tree type = groktypename (t1, NULL, NULL);
7667 	    expr.value = objc_build_encode_expr (type);
7668 	  }
7669 	  break;
7670 	case RID_GENERIC:
7671 	  expr = c_parser_generic_selection (parser);
7672 	  break;
7673 	case RID_CILK_SPAWN:
7674 	  c_parser_consume_token (parser);
7675 	  if (!flag_cilkplus)
7676 	    {
7677 	      error_at (loc, "-fcilkplus must be enabled to use "
7678 			"%<_Cilk_spawn%>");
7679 	      expr = c_parser_postfix_expression (parser);
7680 	      expr.value = error_mark_node;
7681 	    }
7682 	  else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7683 	    {
7684 	      error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
7685 			"are not permitted");
7686 	      /* Now flush out all the _Cilk_spawns.  */
7687 	      while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7688 		c_parser_consume_token (parser);
7689 	      expr = c_parser_postfix_expression (parser);
7690 	    }
7691 	  else
7692 	    {
7693 	      expr = c_parser_postfix_expression (parser);
7694 	      expr.value = build_cilk_spawn (loc, expr.value);
7695 	    }
7696 	  break;
7697 	default:
7698 	  c_parser_error (parser, "expected expression");
7699 	  expr.value = error_mark_node;
7700 	  break;
7701 	}
7702       break;
7703     case CPP_OPEN_SQUARE:
7704       if (c_dialect_objc ())
7705 	{
7706 	  tree receiver, args;
7707 	  c_parser_consume_token (parser);
7708 	  receiver = c_parser_objc_receiver (parser);
7709 	  args = c_parser_objc_message_args (parser);
7710 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7711 				     "expected %<]%>");
7712 	  expr.value = objc_build_message_expr (receiver, args);
7713 	  break;
7714 	}
7715       /* Else fall through to report error.  */
7716     default:
7717       c_parser_error (parser, "expected expression");
7718       expr.value = error_mark_node;
7719       break;
7720     }
7721   return c_parser_postfix_expression_after_primary (parser, loc, expr);
7722 }
7723 
7724 /* Parse a postfix expression after a parenthesized type name: the
7725    brace-enclosed initializer of a compound literal, possibly followed
7726    by some postfix operators.  This is separate because it is not
7727    possible to tell until after the type name whether a cast
7728    expression has a cast or a compound literal, or whether the operand
7729    of sizeof is a parenthesized type name or starts with a compound
7730    literal.  TYPE_LOC is the location where TYPE_NAME starts--the
7731    location of the first token after the parentheses around the type
7732    name.  */
7733 
7734 static struct c_expr
7735 c_parser_postfix_expression_after_paren_type (c_parser *parser,
7736 					      struct c_type_name *type_name,
7737 					      location_t type_loc)
7738 {
7739   tree type;
7740   struct c_expr init;
7741   bool non_const;
7742   struct c_expr expr;
7743   location_t start_loc;
7744   tree type_expr = NULL_TREE;
7745   bool type_expr_const = true;
7746   check_compound_literal_type (type_loc, type_name);
7747   start_init (NULL_TREE, NULL, 0);
7748   type = groktypename (type_name, &type_expr, &type_expr_const);
7749   start_loc = c_parser_peek_token (parser)->location;
7750   if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
7751     {
7752       error_at (type_loc, "compound literal has variable size");
7753       type = error_mark_node;
7754     }
7755   init = c_parser_braced_init (parser, type, false, NULL);
7756   finish_init ();
7757   maybe_warn_string_init (type_loc, type, init);
7758 
7759   if (type != error_mark_node
7760       && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
7761       && current_function_decl)
7762     {
7763       error ("compound literal qualified by address-space qualifier");
7764       type = error_mark_node;
7765     }
7766 
7767   pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
7768   non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
7769 	       ? CONSTRUCTOR_NON_CONST (init.value)
7770 	       : init.original_code == C_MAYBE_CONST_EXPR);
7771   non_const |= !type_expr_const;
7772   expr.value = build_compound_literal (start_loc, type, init.value, non_const);
7773   expr.original_code = ERROR_MARK;
7774   expr.original_type = NULL;
7775   if (type_expr)
7776     {
7777       if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
7778 	{
7779 	  gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
7780 	  C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
7781 	}
7782       else
7783 	{
7784 	  gcc_assert (!non_const);
7785 	  expr.value = build2 (C_MAYBE_CONST_EXPR, type,
7786 			       type_expr, expr.value);
7787 	}
7788     }
7789   return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
7790 }
7791 
7792 /* Callback function for sizeof_pointer_memaccess_warning to compare
7793    types.  */
7794 
7795 static bool
7796 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
7797 {
7798   return comptypes (type1, type2) == 1;
7799 }
7800 
7801 /* Parse a postfix expression after the initial primary or compound
7802    literal; that is, parse a series of postfix operators.
7803 
7804    EXPR_LOC is the location of the primary expression.  */
7805 
7806 static struct c_expr
7807 c_parser_postfix_expression_after_primary (c_parser *parser,
7808 					   location_t expr_loc,
7809 					   struct c_expr expr)
7810 {
7811   struct c_expr orig_expr;
7812   tree ident, idx;
7813   location_t sizeof_arg_loc[3];
7814   tree sizeof_arg[3];
7815   unsigned int literal_zero_mask;
7816   unsigned int i;
7817   vec<tree, va_gc> *exprlist;
7818   vec<tree, va_gc> *origtypes = NULL;
7819   vec<location_t> arg_loc = vNULL;
7820 
7821   while (true)
7822     {
7823       location_t op_loc = c_parser_peek_token (parser)->location;
7824       switch (c_parser_peek_token (parser)->type)
7825 	{
7826 	case CPP_OPEN_SQUARE:
7827 	  /* Array reference.  */
7828 	  c_parser_consume_token (parser);
7829 	  if (flag_cilkplus
7830 	      && c_parser_peek_token (parser)->type == CPP_COLON)
7831 	    /* If we are here, then we have something like this:
7832 	       Array [ : ]
7833 	    */
7834 	    expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE,
7835 						  expr.value);
7836 	  else
7837 	    {
7838 	      idx = c_parser_expression (parser).value;
7839 	      /* Here we have 3 options:
7840 		 1. Array [EXPR] -- Normal Array call.
7841 		 2. Array [EXPR : EXPR] -- Array notation without stride.
7842 		 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7843 
7844 		 For 1, we just handle it just like a normal array expression.
7845 		 For 2 and 3 we handle it like we handle array notations.  The
7846 		 idx value we have above becomes the initial/start index.
7847 	      */
7848 	      if (flag_cilkplus
7849 		  && c_parser_peek_token (parser)->type == CPP_COLON)
7850 		expr.value = c_parser_array_notation (expr_loc, parser, idx,
7851 						      expr.value);
7852 	      else
7853 		{
7854 		  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7855 					     "expected %<]%>");
7856 		  expr.value = build_array_ref (op_loc, expr.value, idx);
7857 		}
7858 	    }
7859 	  expr.original_code = ERROR_MARK;
7860 	  expr.original_type = NULL;
7861 	  break;
7862 	case CPP_OPEN_PAREN:
7863 	  /* Function call.  */
7864 	  c_parser_consume_token (parser);
7865 	  for (i = 0; i < 3; i++)
7866 	    {
7867 	      sizeof_arg[i] = NULL_TREE;
7868 	      sizeof_arg_loc[i] = UNKNOWN_LOCATION;
7869 	    }
7870 	  literal_zero_mask = 0;
7871 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7872 	    exprlist = NULL;
7873 	  else
7874 	    exprlist = c_parser_expr_list (parser, true, false, &origtypes,
7875 					   sizeof_arg_loc, sizeof_arg,
7876 					   &arg_loc, &literal_zero_mask);
7877 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7878 				     "expected %<)%>");
7879 	  orig_expr = expr;
7880 	  mark_exp_read (expr.value);
7881 	  if (warn_sizeof_pointer_memaccess)
7882 	    sizeof_pointer_memaccess_warning (sizeof_arg_loc,
7883 					      expr.value, exprlist,
7884 					      sizeof_arg,
7885 					      sizeof_ptr_memacc_comptypes);
7886 	  if (warn_memset_transposed_args
7887 	      && TREE_CODE (expr.value) == FUNCTION_DECL
7888 	      && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
7889 	      && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
7890 	      && vec_safe_length (exprlist) == 3
7891 	      && integer_zerop ((*exprlist)[2])
7892 	      && (literal_zero_mask & (1 << 2)) != 0
7893 	      && (!integer_zerop ((*exprlist)[1])
7894 		  || (literal_zero_mask & (1 << 1)) == 0))
7895 	    warning_at (expr_loc, OPT_Wmemset_transposed_args,
7896 			"%<memset%> used with constant zero length parameter; "
7897 			"this could be due to transposed parameters");
7898 
7899 	  expr.value
7900 	    = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
7901 					 exprlist, origtypes);
7902 	  expr.original_code = ERROR_MARK;
7903 	  if (TREE_CODE (expr.value) == INTEGER_CST
7904 	      && TREE_CODE (orig_expr.value) == FUNCTION_DECL
7905 	      && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
7906 	      && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
7907 	    expr.original_code = C_MAYBE_CONST_EXPR;
7908 	  expr.original_type = NULL;
7909 	  if (exprlist)
7910 	    {
7911 	      release_tree_vector (exprlist);
7912 	      release_tree_vector (origtypes);
7913 	    }
7914 	  arg_loc.release ();
7915 	  break;
7916 	case CPP_DOT:
7917 	  /* Structure element reference.  */
7918 	  c_parser_consume_token (parser);
7919 	  expr = default_function_array_conversion (expr_loc, expr);
7920 	  if (c_parser_next_token_is (parser, CPP_NAME))
7921 	    ident = c_parser_peek_token (parser)->value;
7922 	  else
7923 	    {
7924 	      c_parser_error (parser, "expected identifier");
7925 	      expr.value = error_mark_node;
7926 	      expr.original_code = ERROR_MARK;
7927               expr.original_type = NULL;
7928 	      return expr;
7929 	    }
7930 	  c_parser_consume_token (parser);
7931 	  expr.value = build_component_ref (op_loc, expr.value, ident);
7932 	  expr.original_code = ERROR_MARK;
7933 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
7934 	    expr.original_type = NULL;
7935 	  else
7936 	    {
7937 	      /* Remember the original type of a bitfield.  */
7938 	      tree field = TREE_OPERAND (expr.value, 1);
7939 	      if (TREE_CODE (field) != FIELD_DECL)
7940 		expr.original_type = NULL;
7941 	      else
7942 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
7943 	    }
7944 	  break;
7945 	case CPP_DEREF:
7946 	  /* Structure element reference.  */
7947 	  c_parser_consume_token (parser);
7948 	  expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
7949 	  if (c_parser_next_token_is (parser, CPP_NAME))
7950 	    ident = c_parser_peek_token (parser)->value;
7951 	  else
7952 	    {
7953 	      c_parser_error (parser, "expected identifier");
7954 	      expr.value = error_mark_node;
7955 	      expr.original_code = ERROR_MARK;
7956 	      expr.original_type = NULL;
7957 	      return expr;
7958 	    }
7959 	  c_parser_consume_token (parser);
7960 	  expr.value = build_component_ref (op_loc,
7961 					    build_indirect_ref (op_loc,
7962 								expr.value,
7963 								RO_ARROW),
7964 					    ident);
7965 	  expr.original_code = ERROR_MARK;
7966 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
7967 	    expr.original_type = NULL;
7968 	  else
7969 	    {
7970 	      /* Remember the original type of a bitfield.  */
7971 	      tree field = TREE_OPERAND (expr.value, 1);
7972 	      if (TREE_CODE (field) != FIELD_DECL)
7973 		expr.original_type = NULL;
7974 	      else
7975 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
7976 	    }
7977 	  break;
7978 	case CPP_PLUS_PLUS:
7979 	  /* Postincrement.  */
7980 	  c_parser_consume_token (parser);
7981 	  /* If the expressions have array notations, we expand them.  */
7982 	  if (flag_cilkplus
7983 	      && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
7984 	    expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr);
7985 	  else
7986 	    {
7987 	      expr = default_function_array_read_conversion (expr_loc, expr);
7988 	      expr.value = build_unary_op (op_loc,
7989 					   POSTINCREMENT_EXPR, expr.value, 0);
7990 	    }
7991 	  expr.original_code = ERROR_MARK;
7992 	  expr.original_type = NULL;
7993 	  break;
7994 	case CPP_MINUS_MINUS:
7995 	  /* Postdecrement.  */
7996 	  c_parser_consume_token (parser);
7997 	  /* If the expressions have array notations, we expand them.  */
7998 	  if (flag_cilkplus
7999 	      && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8000 	    expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr);
8001 	  else
8002 	    {
8003 	      expr = default_function_array_read_conversion (expr_loc, expr);
8004 	      expr.value = build_unary_op (op_loc,
8005 					   POSTDECREMENT_EXPR, expr.value, 0);
8006 	    }
8007 	  expr.original_code = ERROR_MARK;
8008 	  expr.original_type = NULL;
8009 	  break;
8010 	default:
8011 	  return expr;
8012 	}
8013     }
8014 }
8015 
8016 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8017 
8018    expression:
8019      assignment-expression
8020      expression , assignment-expression
8021 */
8022 
8023 static struct c_expr
8024 c_parser_expression (c_parser *parser)
8025 {
8026   location_t tloc = c_parser_peek_token (parser)->location;
8027   struct c_expr expr;
8028   expr = c_parser_expr_no_commas (parser, NULL);
8029   if (c_parser_next_token_is (parser, CPP_COMMA))
8030     expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
8031   while (c_parser_next_token_is (parser, CPP_COMMA))
8032     {
8033       struct c_expr next;
8034       tree lhsval;
8035       location_t loc = c_parser_peek_token (parser)->location;
8036       location_t expr_loc;
8037       c_parser_consume_token (parser);
8038       expr_loc = c_parser_peek_token (parser)->location;
8039       lhsval = expr.value;
8040       while (TREE_CODE (lhsval) == COMPOUND_EXPR)
8041 	lhsval = TREE_OPERAND (lhsval, 1);
8042       if (DECL_P (lhsval) || handled_component_p (lhsval))
8043 	mark_exp_read (lhsval);
8044       next = c_parser_expr_no_commas (parser, NULL);
8045       next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
8046       expr.value = build_compound_expr (loc, expr.value, next.value);
8047       expr.original_code = COMPOUND_EXPR;
8048       expr.original_type = next.original_type;
8049     }
8050   return expr;
8051 }
8052 
8053 /* Parse an expression and convert functions or arrays to pointers and
8054    lvalues to rvalues.  */
8055 
8056 static struct c_expr
8057 c_parser_expression_conv (c_parser *parser)
8058 {
8059   struct c_expr expr;
8060   location_t loc = c_parser_peek_token (parser)->location;
8061   expr = c_parser_expression (parser);
8062   expr = convert_lvalue_to_rvalue (loc, expr, true, false);
8063   return expr;
8064 }
8065 
8066 /* Helper function of c_parser_expr_list.  Check if IDXth (0 based)
8067    argument is a literal zero alone and if so, set it in literal_zero_mask.  */
8068 
8069 static inline void
8070 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
8071 			     unsigned int idx)
8072 {
8073   if (idx >= HOST_BITS_PER_INT)
8074     return;
8075 
8076   c_token *tok = c_parser_peek_token (parser);
8077   switch (tok->type)
8078     {
8079     case CPP_NUMBER:
8080     case CPP_CHAR:
8081     case CPP_WCHAR:
8082     case CPP_CHAR16:
8083     case CPP_CHAR32:
8084       /* If a parameter is literal zero alone, remember it
8085 	 for -Wmemset-transposed-args warning.  */
8086       if (integer_zerop (tok->value)
8087 	  && !TREE_OVERFLOW (tok->value)
8088 	  && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8089 	      || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
8090 	*literal_zero_mask |= 1U << idx;
8091     default:
8092       break;
8093     }
8094 }
8095 
8096 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
8097    functions and arrays to pointers and lvalues to rvalues.  If
8098    FOLD_P, fold the expressions.  If LOCATIONS is non-NULL, save the
8099    locations of function arguments into this vector.
8100 
8101    nonempty-expr-list:
8102      assignment-expression
8103      nonempty-expr-list , assignment-expression
8104 */
8105 
8106 static vec<tree, va_gc> *
8107 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
8108 		    vec<tree, va_gc> **p_orig_types,
8109 		    location_t *sizeof_arg_loc, tree *sizeof_arg,
8110 		    vec<location_t> *locations,
8111 		    unsigned int *literal_zero_mask)
8112 {
8113   vec<tree, va_gc> *ret;
8114   vec<tree, va_gc> *orig_types;
8115   struct c_expr expr;
8116   location_t loc = c_parser_peek_token (parser)->location;
8117   location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8118   unsigned int idx = 0;
8119 
8120   ret = make_tree_vector ();
8121   if (p_orig_types == NULL)
8122     orig_types = NULL;
8123   else
8124     orig_types = make_tree_vector ();
8125 
8126   if (sizeof_arg != NULL
8127       && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8128     cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8129   if (literal_zero_mask)
8130     c_parser_check_literal_zero (parser, literal_zero_mask, 0);
8131   expr = c_parser_expr_no_commas (parser, NULL);
8132   if (convert_p)
8133     expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8134   if (fold_p)
8135     expr.value = c_fully_fold (expr.value, false, NULL);
8136   ret->quick_push (expr.value);
8137   if (orig_types)
8138     orig_types->quick_push (expr.original_type);
8139   if (locations)
8140     locations->safe_push (loc);
8141   if (sizeof_arg != NULL
8142       && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8143       && expr.original_code == SIZEOF_EXPR)
8144     {
8145       sizeof_arg[0] = c_last_sizeof_arg;
8146       sizeof_arg_loc[0] = cur_sizeof_arg_loc;
8147     }
8148   while (c_parser_next_token_is (parser, CPP_COMMA))
8149     {
8150       c_parser_consume_token (parser);
8151       loc = c_parser_peek_token (parser)->location;
8152       if (sizeof_arg != NULL
8153 	  && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8154 	cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8155       else
8156 	cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8157       if (literal_zero_mask)
8158 	c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
8159       expr = c_parser_expr_no_commas (parser, NULL);
8160       if (convert_p)
8161 	expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8162       if (fold_p)
8163 	expr.value = c_fully_fold (expr.value, false, NULL);
8164       vec_safe_push (ret, expr.value);
8165       if (orig_types)
8166 	vec_safe_push (orig_types, expr.original_type);
8167       if (locations)
8168 	locations->safe_push (loc);
8169       if (++idx < 3
8170 	  && sizeof_arg != NULL
8171 	  && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8172 	  && expr.original_code == SIZEOF_EXPR)
8173 	{
8174 	  sizeof_arg[idx] = c_last_sizeof_arg;
8175 	  sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
8176 	}
8177     }
8178   if (orig_types)
8179     *p_orig_types = orig_types;
8180   return ret;
8181 }
8182 
8183 /* Parse Objective-C-specific constructs.  */
8184 
8185 /* Parse an objc-class-definition.
8186 
8187    objc-class-definition:
8188      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8189        objc-class-instance-variables[opt] objc-methodprotolist @end
8190      @implementation identifier objc-superclass[opt]
8191        objc-class-instance-variables[opt]
8192      @interface identifier ( identifier ) objc-protocol-refs[opt]
8193        objc-methodprotolist @end
8194      @interface identifier ( ) objc-protocol-refs[opt]
8195        objc-methodprotolist @end
8196      @implementation identifier ( identifier )
8197 
8198    objc-superclass:
8199      : identifier
8200 
8201    "@interface identifier (" must start "@interface identifier (
8202    identifier ) ...": objc-methodprotolist in the first production may
8203    not start with a parenthesized identifier as a declarator of a data
8204    definition with no declaration specifiers if the objc-superclass,
8205    objc-protocol-refs and objc-class-instance-variables are omitted.  */
8206 
8207 static void
8208 c_parser_objc_class_definition (c_parser *parser, tree attributes)
8209 {
8210   bool iface_p;
8211   tree id1;
8212   tree superclass;
8213   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
8214     iface_p = true;
8215   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
8216     iface_p = false;
8217   else
8218     gcc_unreachable ();
8219 
8220   c_parser_consume_token (parser);
8221   if (c_parser_next_token_is_not (parser, CPP_NAME))
8222     {
8223       c_parser_error (parser, "expected identifier");
8224       return;
8225     }
8226   id1 = c_parser_peek_token (parser)->value;
8227   c_parser_consume_token (parser);
8228   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8229     {
8230       /* We have a category or class extension.  */
8231       tree id2;
8232       tree proto = NULL_TREE;
8233       c_parser_consume_token (parser);
8234       if (c_parser_next_token_is_not (parser, CPP_NAME))
8235 	{
8236 	  if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8237 	    {
8238 	      /* We have a class extension.  */
8239 	      id2 = NULL_TREE;
8240 	    }
8241 	  else
8242 	    {
8243 	      c_parser_error (parser, "expected identifier or %<)%>");
8244 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8245 	      return;
8246 	    }
8247 	}
8248       else
8249 	{
8250 	  id2 = c_parser_peek_token (parser)->value;
8251 	  c_parser_consume_token (parser);
8252 	}
8253       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8254       if (!iface_p)
8255 	{
8256 	  objc_start_category_implementation (id1, id2);
8257 	  return;
8258 	}
8259       if (c_parser_next_token_is (parser, CPP_LESS))
8260 	proto = c_parser_objc_protocol_refs (parser);
8261       objc_start_category_interface (id1, id2, proto, attributes);
8262       c_parser_objc_methodprotolist (parser);
8263       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8264       objc_finish_interface ();
8265       return;
8266     }
8267   if (c_parser_next_token_is (parser, CPP_COLON))
8268     {
8269       c_parser_consume_token (parser);
8270       if (c_parser_next_token_is_not (parser, CPP_NAME))
8271 	{
8272 	  c_parser_error (parser, "expected identifier");
8273 	  return;
8274 	}
8275       superclass = c_parser_peek_token (parser)->value;
8276       c_parser_consume_token (parser);
8277     }
8278   else
8279     superclass = NULL_TREE;
8280   if (iface_p)
8281     {
8282       tree proto = NULL_TREE;
8283       if (c_parser_next_token_is (parser, CPP_LESS))
8284 	proto = c_parser_objc_protocol_refs (parser);
8285       objc_start_class_interface (id1, superclass, proto, attributes);
8286     }
8287   else
8288     objc_start_class_implementation (id1, superclass);
8289   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8290     c_parser_objc_class_instance_variables (parser);
8291   if (iface_p)
8292     {
8293       objc_continue_interface ();
8294       c_parser_objc_methodprotolist (parser);
8295       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8296       objc_finish_interface ();
8297     }
8298   else
8299     {
8300       objc_continue_implementation ();
8301       return;
8302     }
8303 }
8304 
8305 /* Parse objc-class-instance-variables.
8306 
8307    objc-class-instance-variables:
8308      { objc-instance-variable-decl-list[opt] }
8309 
8310    objc-instance-variable-decl-list:
8311      objc-visibility-spec
8312      objc-instance-variable-decl ;
8313      ;
8314      objc-instance-variable-decl-list objc-visibility-spec
8315      objc-instance-variable-decl-list objc-instance-variable-decl ;
8316      objc-instance-variable-decl-list ;
8317 
8318    objc-visibility-spec:
8319      @private
8320      @protected
8321      @public
8322 
8323    objc-instance-variable-decl:
8324      struct-declaration
8325 */
8326 
8327 static void
8328 c_parser_objc_class_instance_variables (c_parser *parser)
8329 {
8330   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
8331   c_parser_consume_token (parser);
8332   while (c_parser_next_token_is_not (parser, CPP_EOF))
8333     {
8334       tree decls;
8335       /* Parse any stray semicolon.  */
8336       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8337 	{
8338 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8339 		   "extra semicolon");
8340 	  c_parser_consume_token (parser);
8341 	  continue;
8342 	}
8343       /* Stop if at the end of the instance variables.  */
8344       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8345 	{
8346 	  c_parser_consume_token (parser);
8347 	  break;
8348 	}
8349       /* Parse any objc-visibility-spec.  */
8350       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
8351 	{
8352 	  c_parser_consume_token (parser);
8353 	  objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
8354 	  continue;
8355 	}
8356       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
8357 	{
8358 	  c_parser_consume_token (parser);
8359 	  objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
8360 	  continue;
8361 	}
8362       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
8363 	{
8364 	  c_parser_consume_token (parser);
8365 	  objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
8366 	  continue;
8367 	}
8368       else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
8369 	{
8370 	  c_parser_consume_token (parser);
8371 	  objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
8372 	  continue;
8373 	}
8374       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
8375 	{
8376 	  c_parser_pragma (parser, pragma_external);
8377 	  continue;
8378 	}
8379 
8380       /* Parse some comma-separated declarations.  */
8381       decls = c_parser_struct_declaration (parser);
8382       if (decls == NULL)
8383 	{
8384 	  /* There is a syntax error.  We want to skip the offending
8385 	     tokens up to the next ';' (included) or '}'
8386 	     (excluded).  */
8387 
8388 	  /* First, skip manually a ')' or ']'.  This is because they
8389 	     reduce the nesting level, so c_parser_skip_until_found()
8390 	     wouldn't be able to skip past them.  */
8391 	  c_token *token = c_parser_peek_token (parser);
8392 	  if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
8393 	    c_parser_consume_token (parser);
8394 
8395 	  /* Then, do the standard skipping.  */
8396 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8397 
8398 	  /* We hopefully recovered.  Start normal parsing again.  */
8399 	  parser->error = false;
8400 	  continue;
8401 	}
8402       else
8403 	{
8404 	  /* Comma-separated instance variables are chained together
8405 	     in reverse order; add them one by one.  */
8406 	  tree ivar = nreverse (decls);
8407 	  for (; ivar; ivar = DECL_CHAIN (ivar))
8408 	    objc_add_instance_variable (copy_node (ivar));
8409 	}
8410       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8411     }
8412 }
8413 
8414 /* Parse an objc-class-declaration.
8415 
8416    objc-class-declaration:
8417      @class identifier-list ;
8418 */
8419 
8420 static void
8421 c_parser_objc_class_declaration (c_parser *parser)
8422 {
8423   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
8424   c_parser_consume_token (parser);
8425   /* Any identifiers, including those declared as type names, are OK
8426      here.  */
8427   while (true)
8428     {
8429       tree id;
8430       if (c_parser_next_token_is_not (parser, CPP_NAME))
8431 	{
8432 	  c_parser_error (parser, "expected identifier");
8433 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8434 	  parser->error = false;
8435 	  return;
8436 	}
8437       id = c_parser_peek_token (parser)->value;
8438       objc_declare_class (id);
8439       c_parser_consume_token (parser);
8440       if (c_parser_next_token_is (parser, CPP_COMMA))
8441 	c_parser_consume_token (parser);
8442       else
8443 	break;
8444     }
8445   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8446 }
8447 
8448 /* Parse an objc-alias-declaration.
8449 
8450    objc-alias-declaration:
8451      @compatibility_alias identifier identifier ;
8452 */
8453 
8454 static void
8455 c_parser_objc_alias_declaration (c_parser *parser)
8456 {
8457   tree id1, id2;
8458   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
8459   c_parser_consume_token (parser);
8460   if (c_parser_next_token_is_not (parser, CPP_NAME))
8461     {
8462       c_parser_error (parser, "expected identifier");
8463       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8464       return;
8465     }
8466   id1 = c_parser_peek_token (parser)->value;
8467   c_parser_consume_token (parser);
8468   if (c_parser_next_token_is_not (parser, CPP_NAME))
8469     {
8470       c_parser_error (parser, "expected identifier");
8471       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8472       return;
8473     }
8474   id2 = c_parser_peek_token (parser)->value;
8475   c_parser_consume_token (parser);
8476   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8477   objc_declare_alias (id1, id2);
8478 }
8479 
8480 /* Parse an objc-protocol-definition.
8481 
8482    objc-protocol-definition:
8483      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8484      @protocol identifier-list ;
8485 
8486    "@protocol identifier ;" should be resolved as "@protocol
8487    identifier-list ;": objc-methodprotolist may not start with a
8488    semicolon in the first alternative if objc-protocol-refs are
8489    omitted.  */
8490 
8491 static void
8492 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
8493 {
8494   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
8495 
8496   c_parser_consume_token (parser);
8497   if (c_parser_next_token_is_not (parser, CPP_NAME))
8498     {
8499       c_parser_error (parser, "expected identifier");
8500       return;
8501     }
8502   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8503       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
8504     {
8505       /* Any identifiers, including those declared as type names, are
8506 	 OK here.  */
8507       while (true)
8508 	{
8509 	  tree id;
8510 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
8511 	    {
8512 	      c_parser_error (parser, "expected identifier");
8513 	      break;
8514 	    }
8515 	  id = c_parser_peek_token (parser)->value;
8516 	  objc_declare_protocol (id, attributes);
8517 	  c_parser_consume_token (parser);
8518 	  if (c_parser_next_token_is (parser, CPP_COMMA))
8519 	    c_parser_consume_token (parser);
8520 	  else
8521 	    break;
8522 	}
8523       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8524     }
8525   else
8526     {
8527       tree id = c_parser_peek_token (parser)->value;
8528       tree proto = NULL_TREE;
8529       c_parser_consume_token (parser);
8530       if (c_parser_next_token_is (parser, CPP_LESS))
8531 	proto = c_parser_objc_protocol_refs (parser);
8532       parser->objc_pq_context = true;
8533       objc_start_protocol (id, proto, attributes);
8534       c_parser_objc_methodprotolist (parser);
8535       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8536       parser->objc_pq_context = false;
8537       objc_finish_interface ();
8538     }
8539 }
8540 
8541 /* Parse an objc-method-type.
8542 
8543    objc-method-type:
8544      +
8545      -
8546 
8547    Return true if it is a class method (+) and false if it is
8548    an instance method (-).
8549 */
8550 static inline bool
8551 c_parser_objc_method_type (c_parser *parser)
8552 {
8553   switch (c_parser_peek_token (parser)->type)
8554     {
8555     case CPP_PLUS:
8556       c_parser_consume_token (parser);
8557       return true;
8558     case CPP_MINUS:
8559       c_parser_consume_token (parser);
8560       return false;
8561     default:
8562       gcc_unreachable ();
8563     }
8564 }
8565 
8566 /* Parse an objc-method-definition.
8567 
8568    objc-method-definition:
8569      objc-method-type objc-method-decl ;[opt] compound-statement
8570 */
8571 
8572 static void
8573 c_parser_objc_method_definition (c_parser *parser)
8574 {
8575   bool is_class_method = c_parser_objc_method_type (parser);
8576   tree decl, attributes = NULL_TREE, expr = NULL_TREE;
8577   parser->objc_pq_context = true;
8578   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8579 				    &expr);
8580   if (decl == error_mark_node)
8581     return;  /* Bail here. */
8582 
8583   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8584     {
8585       c_parser_consume_token (parser);
8586       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8587 	       "extra semicolon in method definition specified");
8588     }
8589 
8590   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8591     {
8592       c_parser_error (parser, "expected %<{%>");
8593       return;
8594     }
8595 
8596   parser->objc_pq_context = false;
8597   if (objc_start_method_definition (is_class_method, decl, attributes, expr))
8598     {
8599       add_stmt (c_parser_compound_statement (parser));
8600       objc_finish_method_definition (current_function_decl);
8601     }
8602   else
8603     {
8604       /* This code is executed when we find a method definition
8605 	 outside of an @implementation context (or invalid for other
8606 	 reasons).  Parse the method (to keep going) but do not emit
8607 	 any code.
8608       */
8609       c_parser_compound_statement (parser);
8610     }
8611 }
8612 
8613 /* Parse an objc-methodprotolist.
8614 
8615    objc-methodprotolist:
8616      empty
8617      objc-methodprotolist objc-methodproto
8618      objc-methodprotolist declaration
8619      objc-methodprotolist ;
8620      @optional
8621      @required
8622 
8623    The declaration is a data definition, which may be missing
8624    declaration specifiers under the same rules and diagnostics as
8625    other data definitions outside functions, and the stray semicolon
8626    is diagnosed the same way as a stray semicolon outside a
8627    function.  */
8628 
8629 static void
8630 c_parser_objc_methodprotolist (c_parser *parser)
8631 {
8632   while (true)
8633     {
8634       /* The list is terminated by @end.  */
8635       switch (c_parser_peek_token (parser)->type)
8636 	{
8637 	case CPP_SEMICOLON:
8638 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8639 		   "ISO C does not allow extra %<;%> outside of a function");
8640 	  c_parser_consume_token (parser);
8641 	  break;
8642 	case CPP_PLUS:
8643 	case CPP_MINUS:
8644 	  c_parser_objc_methodproto (parser);
8645 	  break;
8646 	case CPP_PRAGMA:
8647 	  c_parser_pragma (parser, pragma_external);
8648 	  break;
8649 	case CPP_EOF:
8650 	  return;
8651 	default:
8652 	  if (c_parser_next_token_is_keyword (parser, RID_AT_END))
8653 	    return;
8654 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
8655 	    c_parser_objc_at_property_declaration (parser);
8656 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
8657 	    {
8658 	      objc_set_method_opt (true);
8659 	      c_parser_consume_token (parser);
8660 	    }
8661 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
8662 	    {
8663 	      objc_set_method_opt (false);
8664 	      c_parser_consume_token (parser);
8665 	    }
8666 	  else
8667 	    c_parser_declaration_or_fndef (parser, false, false, true,
8668 					   false, true, NULL, vNULL);
8669 	  break;
8670 	}
8671     }
8672 }
8673 
8674 /* Parse an objc-methodproto.
8675 
8676    objc-methodproto:
8677      objc-method-type objc-method-decl ;
8678 */
8679 
8680 static void
8681 c_parser_objc_methodproto (c_parser *parser)
8682 {
8683   bool is_class_method = c_parser_objc_method_type (parser);
8684   tree decl, attributes = NULL_TREE;
8685 
8686   /* Remember protocol qualifiers in prototypes.  */
8687   parser->objc_pq_context = true;
8688   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8689 				    NULL);
8690   /* Forget protocol qualifiers now.  */
8691   parser->objc_pq_context = false;
8692 
8693   /* Do not allow the presence of attributes to hide an erroneous
8694      method implementation in the interface section.  */
8695   if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
8696     {
8697       c_parser_error (parser, "expected %<;%>");
8698       return;
8699     }
8700 
8701   if (decl != error_mark_node)
8702     objc_add_method_declaration (is_class_method, decl, attributes);
8703 
8704   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8705 }
8706 
8707 /* If we are at a position that method attributes may be present, check that
8708    there are not any parsed already (a syntax error) and then collect any
8709    specified at the current location.  Finally, if new attributes were present,
8710    check that the next token is legal ( ';' for decls and '{' for defs).  */
8711 
8712 static bool
8713 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
8714 {
8715   bool bad = false;
8716   if (*attributes)
8717     {
8718       c_parser_error (parser,
8719 		    "method attributes must be specified at the end only");
8720       *attributes = NULL_TREE;
8721       bad = true;
8722     }
8723 
8724   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8725     *attributes = c_parser_attributes (parser);
8726 
8727   /* If there were no attributes here, just report any earlier error.  */
8728   if (*attributes == NULL_TREE || bad)
8729     return bad;
8730 
8731   /* If the attributes are followed by a ; or {, then just report any earlier
8732      error.  */
8733   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
8734       || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8735     return bad;
8736 
8737   /* We've got attributes, but not at the end.  */
8738   c_parser_error (parser,
8739 		  "expected %<;%> or %<{%> after method attribute definition");
8740   return true;
8741 }
8742 
8743 /* Parse an objc-method-decl.
8744 
8745    objc-method-decl:
8746      ( objc-type-name ) objc-selector
8747      objc-selector
8748      ( objc-type-name ) objc-keyword-selector objc-optparmlist
8749      objc-keyword-selector objc-optparmlist
8750      attributes
8751 
8752    objc-keyword-selector:
8753      objc-keyword-decl
8754      objc-keyword-selector objc-keyword-decl
8755 
8756    objc-keyword-decl:
8757      objc-selector : ( objc-type-name ) identifier
8758      objc-selector : identifier
8759      : ( objc-type-name ) identifier
8760      : identifier
8761 
8762    objc-optparmlist:
8763      objc-optparms objc-optellipsis
8764 
8765    objc-optparms:
8766      empty
8767      objc-opt-parms , parameter-declaration
8768 
8769    objc-optellipsis:
8770      empty
8771      , ...
8772 */
8773 
8774 static tree
8775 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
8776 			   tree *attributes, tree *expr)
8777 {
8778   tree type = NULL_TREE;
8779   tree sel;
8780   tree parms = NULL_TREE;
8781   bool ellipsis = false;
8782   bool attr_err = false;
8783 
8784   *attributes = NULL_TREE;
8785   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8786     {
8787       c_parser_consume_token (parser);
8788       type = c_parser_objc_type_name (parser);
8789       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8790     }
8791   sel = c_parser_objc_selector (parser);
8792   /* If there is no selector, or a colon follows, we have an
8793      objc-keyword-selector.  If there is a selector, and a colon does
8794      not follow, that selector ends the objc-method-decl.  */
8795   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
8796     {
8797       tree tsel = sel;
8798       tree list = NULL_TREE;
8799       while (true)
8800 	{
8801 	  tree atype = NULL_TREE, id, keyworddecl;
8802 	  tree param_attr = NULL_TREE;
8803 	  if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8804 	    break;
8805 	  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8806 	    {
8807 	      c_parser_consume_token (parser);
8808 	      atype = c_parser_objc_type_name (parser);
8809 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8810 					 "expected %<)%>");
8811 	    }
8812 	  /* New ObjC allows attributes on method parameters.  */
8813 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8814 	    param_attr = c_parser_attributes (parser);
8815 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
8816 	    {
8817 	      c_parser_error (parser, "expected identifier");
8818 	      return error_mark_node;
8819 	    }
8820 	  id = c_parser_peek_token (parser)->value;
8821 	  c_parser_consume_token (parser);
8822 	  keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
8823 	  list = chainon (list, keyworddecl);
8824 	  tsel = c_parser_objc_selector (parser);
8825 	  if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
8826 	    break;
8827 	}
8828 
8829       attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8830 
8831       /* Parse the optional parameter list.  Optional Objective-C
8832 	 method parameters follow the C syntax, and may include '...'
8833 	 to denote a variable number of arguments.  */
8834       parms = make_node (TREE_LIST);
8835       while (c_parser_next_token_is (parser, CPP_COMMA))
8836 	{
8837 	  struct c_parm *parm;
8838 	  c_parser_consume_token (parser);
8839 	  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8840 	    {
8841 	      ellipsis = true;
8842 	      c_parser_consume_token (parser);
8843 	      attr_err |= c_parser_objc_maybe_method_attributes
8844 						(parser, attributes) ;
8845 	      break;
8846 	    }
8847 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
8848 	  if (parm == NULL)
8849 	    break;
8850 	  parms = chainon (parms,
8851 			   build_tree_list (NULL_TREE, grokparm (parm, expr)));
8852 	}
8853       sel = list;
8854     }
8855   else
8856     attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8857 
8858   if (sel == NULL)
8859     {
8860       c_parser_error (parser, "objective-c method declaration is expected");
8861       return error_mark_node;
8862     }
8863 
8864   if (attr_err)
8865     return error_mark_node;
8866 
8867   return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
8868 }
8869 
8870 /* Parse an objc-type-name.
8871 
8872    objc-type-name:
8873      objc-type-qualifiers[opt] type-name
8874      objc-type-qualifiers[opt]
8875 
8876    objc-type-qualifiers:
8877      objc-type-qualifier
8878      objc-type-qualifiers objc-type-qualifier
8879 
8880    objc-type-qualifier: one of
8881      in out inout bycopy byref oneway
8882 */
8883 
8884 static tree
8885 c_parser_objc_type_name (c_parser *parser)
8886 {
8887   tree quals = NULL_TREE;
8888   struct c_type_name *type_name = NULL;
8889   tree type = NULL_TREE;
8890   while (true)
8891     {
8892       c_token *token = c_parser_peek_token (parser);
8893       if (token->type == CPP_KEYWORD
8894 	  && (token->keyword == RID_IN
8895 	      || token->keyword == RID_OUT
8896 	      || token->keyword == RID_INOUT
8897 	      || token->keyword == RID_BYCOPY
8898 	      || token->keyword == RID_BYREF
8899 	      || token->keyword == RID_ONEWAY))
8900 	{
8901 	  quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
8902 	  c_parser_consume_token (parser);
8903 	}
8904       else
8905 	break;
8906     }
8907   if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
8908     type_name = c_parser_type_name (parser);
8909   if (type_name)
8910     type = groktypename (type_name, NULL, NULL);
8911 
8912   /* If the type is unknown, and error has already been produced and
8913      we need to recover from the error.  In that case, use NULL_TREE
8914      for the type, as if no type had been specified; this will use the
8915      default type ('id') which is good for error recovery.  */
8916   if (type == error_mark_node)
8917     type = NULL_TREE;
8918 
8919   return build_tree_list (quals, type);
8920 }
8921 
8922 /* Parse objc-protocol-refs.
8923 
8924    objc-protocol-refs:
8925      < identifier-list >
8926 */
8927 
8928 static tree
8929 c_parser_objc_protocol_refs (c_parser *parser)
8930 {
8931   tree list = NULL_TREE;
8932   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
8933   c_parser_consume_token (parser);
8934   /* Any identifiers, including those declared as type names, are OK
8935      here.  */
8936   while (true)
8937     {
8938       tree id;
8939       if (c_parser_next_token_is_not (parser, CPP_NAME))
8940 	{
8941 	  c_parser_error (parser, "expected identifier");
8942 	  break;
8943 	}
8944       id = c_parser_peek_token (parser)->value;
8945       list = chainon (list, build_tree_list (NULL_TREE, id));
8946       c_parser_consume_token (parser);
8947       if (c_parser_next_token_is (parser, CPP_COMMA))
8948 	c_parser_consume_token (parser);
8949       else
8950 	break;
8951     }
8952   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
8953   return list;
8954 }
8955 
8956 /* Parse an objc-try-catch-finally-statement.
8957 
8958    objc-try-catch-finally-statement:
8959      @try compound-statement objc-catch-list[opt]
8960      @try compound-statement objc-catch-list[opt] @finally compound-statement
8961 
8962    objc-catch-list:
8963      @catch ( objc-catch-parameter-declaration ) compound-statement
8964      objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8965 
8966    objc-catch-parameter-declaration:
8967      parameter-declaration
8968      '...'
8969 
8970    where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8971 
8972    PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8973    for C++.  Keep them in sync.  */
8974 
8975 static void
8976 c_parser_objc_try_catch_finally_statement (c_parser *parser)
8977 {
8978   location_t location;
8979   tree stmt;
8980 
8981   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
8982   c_parser_consume_token (parser);
8983   location = c_parser_peek_token (parser)->location;
8984   objc_maybe_warn_exceptions (location);
8985   stmt = c_parser_compound_statement (parser);
8986   objc_begin_try_stmt (location, stmt);
8987 
8988   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
8989     {
8990       struct c_parm *parm;
8991       tree parameter_declaration = error_mark_node;
8992       bool seen_open_paren = false;
8993 
8994       c_parser_consume_token (parser);
8995       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8996 	seen_open_paren = true;
8997       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8998 	{
8999 	  /* We have "@catch (...)" (where the '...' are literally
9000 	     what is in the code).  Skip the '...'.
9001 	     parameter_declaration is set to NULL_TREE, and
9002 	     objc_being_catch_clauses() knows that that means
9003 	     '...'.  */
9004 	  c_parser_consume_token (parser);
9005 	  parameter_declaration = NULL_TREE;
9006 	}
9007       else
9008 	{
9009 	  /* We have "@catch (NSException *exception)" or something
9010 	     like that.  Parse the parameter declaration.  */
9011 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
9012 	  if (parm == NULL)
9013 	    parameter_declaration = error_mark_node;
9014 	  else
9015 	    parameter_declaration = grokparm (parm, NULL);
9016 	}
9017       if (seen_open_paren)
9018 	c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9019       else
9020 	{
9021 	  /* If there was no open parenthesis, we are recovering from
9022 	     an error, and we are trying to figure out what mistake
9023 	     the user has made.  */
9024 
9025 	  /* If there is an immediate closing parenthesis, the user
9026 	     probably forgot the opening one (ie, they typed "@catch
9027 	     NSException *e)".  Parse the closing parenthesis and keep
9028 	     going.  */
9029 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9030 	    c_parser_consume_token (parser);
9031 
9032 	  /* If these is no immediate closing parenthesis, the user
9033 	     probably doesn't know that parenthesis are required at
9034 	     all (ie, they typed "@catch NSException *e").  So, just
9035 	     forget about the closing parenthesis and keep going.  */
9036 	}
9037       objc_begin_catch_clause (parameter_declaration);
9038       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9039 	c_parser_compound_statement_nostart (parser);
9040       objc_finish_catch_clause ();
9041     }
9042   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
9043     {
9044       c_parser_consume_token (parser);
9045       location = c_parser_peek_token (parser)->location;
9046       stmt = c_parser_compound_statement (parser);
9047       objc_build_finally_clause (location, stmt);
9048     }
9049   objc_finish_try_stmt ();
9050 }
9051 
9052 /* Parse an objc-synchronized-statement.
9053 
9054    objc-synchronized-statement:
9055      @synchronized ( expression ) compound-statement
9056 */
9057 
9058 static void
9059 c_parser_objc_synchronized_statement (c_parser *parser)
9060 {
9061   location_t loc;
9062   tree expr, stmt;
9063   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
9064   c_parser_consume_token (parser);
9065   loc = c_parser_peek_token (parser)->location;
9066   objc_maybe_warn_exceptions (loc);
9067   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9068     {
9069       struct c_expr ce = c_parser_expression (parser);
9070       ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9071       expr = ce.value;
9072       expr = c_fully_fold (expr, false, NULL);
9073       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9074     }
9075   else
9076     expr = error_mark_node;
9077   stmt = c_parser_compound_statement (parser);
9078   objc_build_synchronized (loc, expr, stmt);
9079 }
9080 
9081 /* Parse an objc-selector; return NULL_TREE without an error if the
9082    next token is not an objc-selector.
9083 
9084    objc-selector:
9085      identifier
9086      one of
9087        enum struct union if else while do for switch case default
9088        break continue return goto asm sizeof typeof __alignof
9089        unsigned long const short volatile signed restrict _Complex
9090        in out inout bycopy byref oneway int char float double void _Bool
9091        _Atomic
9092 
9093    ??? Why this selection of keywords but not, for example, storage
9094    class specifiers?  */
9095 
9096 static tree
9097 c_parser_objc_selector (c_parser *parser)
9098 {
9099   c_token *token = c_parser_peek_token (parser);
9100   tree value = token->value;
9101   if (token->type == CPP_NAME)
9102     {
9103       c_parser_consume_token (parser);
9104       return value;
9105     }
9106   if (token->type != CPP_KEYWORD)
9107     return NULL_TREE;
9108   switch (token->keyword)
9109     {
9110     case RID_ENUM:
9111     case RID_STRUCT:
9112     case RID_UNION:
9113     case RID_IF:
9114     case RID_ELSE:
9115     case RID_WHILE:
9116     case RID_DO:
9117     case RID_FOR:
9118     case RID_SWITCH:
9119     case RID_CASE:
9120     case RID_DEFAULT:
9121     case RID_BREAK:
9122     case RID_CONTINUE:
9123     case RID_RETURN:
9124     case RID_GOTO:
9125     case RID_ASM:
9126     case RID_SIZEOF:
9127     case RID_TYPEOF:
9128     case RID_ALIGNOF:
9129     case RID_UNSIGNED:
9130     case RID_LONG:
9131     case RID_CONST:
9132     case RID_SHORT:
9133     case RID_VOLATILE:
9134     case RID_SIGNED:
9135     case RID_RESTRICT:
9136     case RID_COMPLEX:
9137     case RID_IN:
9138     case RID_OUT:
9139     case RID_INOUT:
9140     case RID_BYCOPY:
9141     case RID_BYREF:
9142     case RID_ONEWAY:
9143     case RID_INT:
9144     case RID_CHAR:
9145     case RID_FLOAT:
9146     case RID_DOUBLE:
9147     case RID_VOID:
9148     case RID_BOOL:
9149     case RID_ATOMIC:
9150     case RID_AUTO_TYPE:
9151     case RID_INT_N_0:
9152     case RID_INT_N_1:
9153     case RID_INT_N_2:
9154     case RID_INT_N_3:
9155       c_parser_consume_token (parser);
9156       return value;
9157     default:
9158       return NULL_TREE;
9159     }
9160 }
9161 
9162 /* Parse an objc-selector-arg.
9163 
9164    objc-selector-arg:
9165      objc-selector
9166      objc-keywordname-list
9167 
9168    objc-keywordname-list:
9169      objc-keywordname
9170      objc-keywordname-list objc-keywordname
9171 
9172    objc-keywordname:
9173      objc-selector :
9174      :
9175 */
9176 
9177 static tree
9178 c_parser_objc_selector_arg (c_parser *parser)
9179 {
9180   tree sel = c_parser_objc_selector (parser);
9181   tree list = NULL_TREE;
9182   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9183     return sel;
9184   while (true)
9185     {
9186       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9187 	return list;
9188       list = chainon (list, build_tree_list (sel, NULL_TREE));
9189       sel = c_parser_objc_selector (parser);
9190       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9191 	break;
9192     }
9193   return list;
9194 }
9195 
9196 /* Parse an objc-receiver.
9197 
9198    objc-receiver:
9199      expression
9200      class-name
9201      type-name
9202 */
9203 
9204 static tree
9205 c_parser_objc_receiver (c_parser *parser)
9206 {
9207   location_t loc = c_parser_peek_token (parser)->location;
9208 
9209   if (c_parser_peek_token (parser)->type == CPP_NAME
9210       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
9211 	  || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
9212     {
9213       tree id = c_parser_peek_token (parser)->value;
9214       c_parser_consume_token (parser);
9215       return objc_get_class_reference (id);
9216     }
9217   struct c_expr ce = c_parser_expression (parser);
9218   ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9219   return c_fully_fold (ce.value, false, NULL);
9220 }
9221 
9222 /* Parse objc-message-args.
9223 
9224    objc-message-args:
9225      objc-selector
9226      objc-keywordarg-list
9227 
9228    objc-keywordarg-list:
9229      objc-keywordarg
9230      objc-keywordarg-list objc-keywordarg
9231 
9232    objc-keywordarg:
9233      objc-selector : objc-keywordexpr
9234      : objc-keywordexpr
9235 */
9236 
9237 static tree
9238 c_parser_objc_message_args (c_parser *parser)
9239 {
9240   tree sel = c_parser_objc_selector (parser);
9241   tree list = NULL_TREE;
9242   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9243     return sel;
9244   while (true)
9245     {
9246       tree keywordexpr;
9247       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9248 	return error_mark_node;
9249       keywordexpr = c_parser_objc_keywordexpr (parser);
9250       list = chainon (list, build_tree_list (sel, keywordexpr));
9251       sel = c_parser_objc_selector (parser);
9252       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9253 	break;
9254     }
9255   return list;
9256 }
9257 
9258 /* Parse an objc-keywordexpr.
9259 
9260    objc-keywordexpr:
9261      nonempty-expr-list
9262 */
9263 
9264 static tree
9265 c_parser_objc_keywordexpr (c_parser *parser)
9266 {
9267   tree ret;
9268   vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
9269 						NULL, NULL, NULL, NULL);
9270   if (vec_safe_length (expr_list) == 1)
9271     {
9272       /* Just return the expression, remove a level of
9273 	 indirection.  */
9274       ret = (*expr_list)[0];
9275     }
9276   else
9277     {
9278       /* We have a comma expression, we will collapse later.  */
9279       ret = build_tree_list_vec (expr_list);
9280     }
9281   release_tree_vector (expr_list);
9282   return ret;
9283 }
9284 
9285 /* A check, needed in several places, that ObjC interface, implementation or
9286    method definitions are not prefixed by incorrect items.  */
9287 static bool
9288 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
9289 					   struct c_declspecs *specs)
9290 {
9291   if (!specs->declspecs_seen_p || specs->non_sc_seen_p
9292       || specs->typespec_kind != ctsk_none)
9293     {
9294       c_parser_error (parser,
9295       		      "no type or storage class may be specified here,");
9296       c_parser_skip_to_end_of_block_or_statement (parser);
9297       return true;
9298     }
9299   return false;
9300 }
9301 
9302 /* Parse an Objective-C @property declaration.  The syntax is:
9303 
9304    objc-property-declaration:
9305      '@property' objc-property-attributes[opt] struct-declaration ;
9306 
9307    objc-property-attributes:
9308     '(' objc-property-attribute-list ')'
9309 
9310    objc-property-attribute-list:
9311      objc-property-attribute
9312      objc-property-attribute-list, objc-property-attribute
9313 
9314    objc-property-attribute
9315      'getter' = identifier
9316      'setter' = identifier
9317      'readonly'
9318      'readwrite'
9319      'assign'
9320      'retain'
9321      'copy'
9322      'nonatomic'
9323 
9324   For example:
9325     @property NSString *name;
9326     @property (readonly) id object;
9327     @property (retain, nonatomic, getter=getTheName) id name;
9328     @property int a, b, c;
9329 
9330   PS: This function is identical to cp_parser_objc_at_propery_declaration
9331   for C++.  Keep them in sync.  */
9332 static void
9333 c_parser_objc_at_property_declaration (c_parser *parser)
9334 {
9335   /* The following variables hold the attributes of the properties as
9336      parsed.  They are 'false' or 'NULL_TREE' if the attribute was not
9337      seen.  When we see an attribute, we set them to 'true' (if they
9338      are boolean properties) or to the identifier (if they have an
9339      argument, ie, for getter and setter).  Note that here we only
9340      parse the list of attributes, check the syntax and accumulate the
9341      attributes that we find.  objc_add_property_declaration() will
9342      then process the information.  */
9343   bool property_assign = false;
9344   bool property_copy = false;
9345   tree property_getter_ident = NULL_TREE;
9346   bool property_nonatomic = false;
9347   bool property_readonly = false;
9348   bool property_readwrite = false;
9349   bool property_retain = false;
9350   tree property_setter_ident = NULL_TREE;
9351 
9352   /* 'properties' is the list of properties that we read.  Usually a
9353      single one, but maybe more (eg, in "@property int a, b, c;" there
9354      are three).  */
9355   tree properties;
9356   location_t loc;
9357 
9358   loc = c_parser_peek_token (parser)->location;
9359   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
9360 
9361   c_parser_consume_token (parser);  /* Eat '@property'.  */
9362 
9363   /* Parse the optional attribute list...  */
9364   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9365     {
9366       /* Eat the '(' */
9367       c_parser_consume_token (parser);
9368 
9369       /* Property attribute keywords are valid now.  */
9370       parser->objc_property_attr_context = true;
9371 
9372       while (true)
9373 	{
9374 	  bool syntax_error = false;
9375 	  c_token *token = c_parser_peek_token (parser);
9376 	  enum rid keyword;
9377 
9378 	  if (token->type != CPP_KEYWORD)
9379 	    {
9380 	      if (token->type == CPP_CLOSE_PAREN)
9381 		c_parser_error (parser, "expected identifier");
9382 	      else
9383 		{
9384 		  c_parser_consume_token (parser);
9385 		  c_parser_error (parser, "unknown property attribute");
9386 		}
9387 	      break;
9388 	    }
9389 	  keyword = token->keyword;
9390 	  c_parser_consume_token (parser);
9391 	  switch (keyword)
9392 	    {
9393 	    case RID_ASSIGN:    property_assign = true;    break;
9394 	    case RID_COPY:      property_copy = true;      break;
9395 	    case RID_NONATOMIC: property_nonatomic = true; break;
9396 	    case RID_READONLY:  property_readonly = true;  break;
9397 	    case RID_READWRITE: property_readwrite = true; break;
9398 	    case RID_RETAIN:    property_retain = true;    break;
9399 
9400 	    case RID_GETTER:
9401 	    case RID_SETTER:
9402 	      if (c_parser_next_token_is_not (parser, CPP_EQ))
9403 		{
9404 		  if (keyword == RID_GETTER)
9405 		    c_parser_error (parser,
9406 				    "missing %<=%> (after %<getter%> attribute)");
9407 		  else
9408 		    c_parser_error (parser,
9409 				    "missing %<=%> (after %<setter%> attribute)");
9410 		  syntax_error = true;
9411 		  break;
9412 		}
9413 	      c_parser_consume_token (parser); /* eat the = */
9414 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
9415 		{
9416 		  c_parser_error (parser, "expected identifier");
9417 		  syntax_error = true;
9418 		  break;
9419 		}
9420 	      if (keyword == RID_SETTER)
9421 		{
9422 		  if (property_setter_ident != NULL_TREE)
9423 		    c_parser_error (parser, "the %<setter%> attribute may only be specified once");
9424 		  else
9425 		    property_setter_ident = c_parser_peek_token (parser)->value;
9426 		  c_parser_consume_token (parser);
9427 		  if (c_parser_next_token_is_not (parser, CPP_COLON))
9428 		    c_parser_error (parser, "setter name must terminate with %<:%>");
9429 		  else
9430 		    c_parser_consume_token (parser);
9431 		}
9432 	      else
9433 		{
9434 		  if (property_getter_ident != NULL_TREE)
9435 		    c_parser_error (parser, "the %<getter%> attribute may only be specified once");
9436 		  else
9437 		    property_getter_ident = c_parser_peek_token (parser)->value;
9438 		  c_parser_consume_token (parser);
9439 		}
9440 	      break;
9441 	    default:
9442 	      c_parser_error (parser, "unknown property attribute");
9443 	      syntax_error = true;
9444 	      break;
9445 	    }
9446 
9447 	  if (syntax_error)
9448 	    break;
9449 
9450 	  if (c_parser_next_token_is (parser, CPP_COMMA))
9451 	    c_parser_consume_token (parser);
9452 	  else
9453 	    break;
9454 	}
9455       parser->objc_property_attr_context = false;
9456       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9457     }
9458   /* ... and the property declaration(s).  */
9459   properties = c_parser_struct_declaration (parser);
9460 
9461   if (properties == error_mark_node)
9462     {
9463       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9464       parser->error = false;
9465       return;
9466     }
9467 
9468   if (properties == NULL_TREE)
9469     c_parser_error (parser, "expected identifier");
9470   else
9471     {
9472       /* Comma-separated properties are chained together in
9473 	 reverse order; add them one by one.  */
9474       properties = nreverse (properties);
9475 
9476       for (; properties; properties = TREE_CHAIN (properties))
9477 	objc_add_property_declaration (loc, copy_node (properties),
9478 				       property_readonly, property_readwrite,
9479 				       property_assign, property_retain,
9480 				       property_copy, property_nonatomic,
9481 				       property_getter_ident, property_setter_ident);
9482     }
9483 
9484   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9485   parser->error = false;
9486 }
9487 
9488 /* Parse an Objective-C @synthesize declaration.  The syntax is:
9489 
9490    objc-synthesize-declaration:
9491      @synthesize objc-synthesize-identifier-list ;
9492 
9493    objc-synthesize-identifier-list:
9494      objc-synthesize-identifier
9495      objc-synthesize-identifier-list, objc-synthesize-identifier
9496 
9497    objc-synthesize-identifier
9498      identifier
9499      identifier = identifier
9500 
9501   For example:
9502     @synthesize MyProperty;
9503     @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9504 
9505   PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9506   for C++.  Keep them in sync.
9507 */
9508 static void
9509 c_parser_objc_at_synthesize_declaration (c_parser *parser)
9510 {
9511   tree list = NULL_TREE;
9512   location_t loc;
9513   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
9514   loc = c_parser_peek_token (parser)->location;
9515 
9516   c_parser_consume_token (parser);
9517   while (true)
9518     {
9519       tree property, ivar;
9520       if (c_parser_next_token_is_not (parser, CPP_NAME))
9521 	{
9522 	  c_parser_error (parser, "expected identifier");
9523 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9524 	  /* Once we find the semicolon, we can resume normal parsing.
9525 	     We have to reset parser->error manually because
9526 	     c_parser_skip_until_found() won't reset it for us if the
9527 	     next token is precisely a semicolon.  */
9528 	  parser->error = false;
9529 	  return;
9530 	}
9531       property = c_parser_peek_token (parser)->value;
9532       c_parser_consume_token (parser);
9533       if (c_parser_next_token_is (parser, CPP_EQ))
9534 	{
9535 	  c_parser_consume_token (parser);
9536 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
9537 	    {
9538 	      c_parser_error (parser, "expected identifier");
9539 	      c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9540 	      parser->error = false;
9541 	      return;
9542 	    }
9543 	  ivar = c_parser_peek_token (parser)->value;
9544 	  c_parser_consume_token (parser);
9545 	}
9546       else
9547 	ivar = NULL_TREE;
9548       list = chainon (list, build_tree_list (ivar, property));
9549       if (c_parser_next_token_is (parser, CPP_COMMA))
9550 	c_parser_consume_token (parser);
9551       else
9552 	break;
9553     }
9554   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9555   objc_add_synthesize_declaration (loc, list);
9556 }
9557 
9558 /* Parse an Objective-C @dynamic declaration.  The syntax is:
9559 
9560    objc-dynamic-declaration:
9561      @dynamic identifier-list ;
9562 
9563    For example:
9564      @dynamic MyProperty;
9565      @dynamic MyProperty, AnotherProperty;
9566 
9567   PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9568   for C++.  Keep them in sync.
9569 */
9570 static void
9571 c_parser_objc_at_dynamic_declaration (c_parser *parser)
9572 {
9573   tree list = NULL_TREE;
9574   location_t loc;
9575   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
9576   loc = c_parser_peek_token (parser)->location;
9577 
9578   c_parser_consume_token (parser);
9579   while (true)
9580     {
9581       tree property;
9582       if (c_parser_next_token_is_not (parser, CPP_NAME))
9583 	{
9584 	  c_parser_error (parser, "expected identifier");
9585 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9586 	  parser->error = false;
9587 	  return;
9588 	}
9589       property = c_parser_peek_token (parser)->value;
9590       list = chainon (list, build_tree_list (NULL_TREE, property));
9591       c_parser_consume_token (parser);
9592       if (c_parser_next_token_is (parser, CPP_COMMA))
9593 	c_parser_consume_token (parser);
9594       else
9595 	break;
9596     }
9597   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9598   objc_add_dynamic_declaration (loc, list);
9599 }
9600 
9601 
9602 /* Handle pragmas.  Some OpenMP pragmas are associated with, and therefore
9603    should be considered, statements.  ALLOW_STMT is true if we're within
9604    the context of a function and such pragmas are to be allowed.  Returns
9605    true if we actually parsed such a pragma.  */
9606 
9607 static bool
9608 c_parser_pragma (c_parser *parser, enum pragma_context context)
9609 {
9610   unsigned int id;
9611 
9612   id = c_parser_peek_token (parser)->pragma_kind;
9613   gcc_assert (id != PRAGMA_NONE);
9614 
9615   switch (id)
9616     {
9617     case PRAGMA_OACC_ENTER_DATA:
9618       c_parser_oacc_enter_exit_data (parser, true);
9619       return false;
9620 
9621     case PRAGMA_OACC_EXIT_DATA:
9622       c_parser_oacc_enter_exit_data (parser, false);
9623       return false;
9624 
9625     case PRAGMA_OACC_UPDATE:
9626       if (context != pragma_compound)
9627 	{
9628 	  if (context == pragma_stmt)
9629 	    c_parser_error (parser, "%<#pragma acc update%> may only be "
9630 			    "used in compound statements");
9631 	  goto bad_stmt;
9632 	}
9633       c_parser_oacc_update (parser);
9634       return false;
9635 
9636     case PRAGMA_OMP_BARRIER:
9637       if (context != pragma_compound)
9638 	{
9639 	  if (context == pragma_stmt)
9640 	    c_parser_error (parser, "%<#pragma omp barrier%> may only be "
9641 			    "used in compound statements");
9642 	  goto bad_stmt;
9643 	}
9644       c_parser_omp_barrier (parser);
9645       return false;
9646 
9647     case PRAGMA_OMP_FLUSH:
9648       if (context != pragma_compound)
9649 	{
9650 	  if (context == pragma_stmt)
9651 	    c_parser_error (parser, "%<#pragma omp flush%> may only be "
9652 			    "used in compound statements");
9653 	  goto bad_stmt;
9654 	}
9655       c_parser_omp_flush (parser);
9656       return false;
9657 
9658     case PRAGMA_OMP_TASKWAIT:
9659       if (context != pragma_compound)
9660 	{
9661 	  if (context == pragma_stmt)
9662 	    c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
9663 			    "used in compound statements");
9664 	  goto bad_stmt;
9665 	}
9666       c_parser_omp_taskwait (parser);
9667       return false;
9668 
9669     case PRAGMA_OMP_TASKYIELD:
9670       if (context != pragma_compound)
9671 	{
9672 	  if (context == pragma_stmt)
9673 	    c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
9674 			    "used in compound statements");
9675 	  goto bad_stmt;
9676 	}
9677       c_parser_omp_taskyield (parser);
9678       return false;
9679 
9680     case PRAGMA_OMP_CANCEL:
9681       if (context != pragma_compound)
9682 	{
9683 	  if (context == pragma_stmt)
9684 	    c_parser_error (parser, "%<#pragma omp cancel%> may only be "
9685 			    "used in compound statements");
9686 	  goto bad_stmt;
9687 	}
9688       c_parser_omp_cancel (parser);
9689       return false;
9690 
9691     case PRAGMA_OMP_CANCELLATION_POINT:
9692       if (context != pragma_compound)
9693 	{
9694 	  if (context == pragma_stmt)
9695 	    c_parser_error (parser, "%<#pragma omp cancellation point%> may "
9696 				    "only be used in compound statements");
9697 	  goto bad_stmt;
9698 	}
9699       c_parser_omp_cancellation_point (parser);
9700       return false;
9701 
9702     case PRAGMA_OMP_THREADPRIVATE:
9703       c_parser_omp_threadprivate (parser);
9704       return false;
9705 
9706     case PRAGMA_OMP_TARGET:
9707       return c_parser_omp_target (parser, context);
9708 
9709     case PRAGMA_OMP_END_DECLARE_TARGET:
9710       c_parser_omp_end_declare_target (parser);
9711       return false;
9712 
9713     case PRAGMA_OMP_SECTION:
9714       error_at (c_parser_peek_token (parser)->location,
9715 		"%<#pragma omp section%> may only be used in "
9716 		"%<#pragma omp sections%> construct");
9717       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9718       return false;
9719 
9720     case PRAGMA_OMP_DECLARE_REDUCTION:
9721       c_parser_omp_declare (parser, context);
9722       return false;
9723     case PRAGMA_IVDEP:
9724       c_parser_consume_pragma (parser);
9725       c_parser_skip_to_pragma_eol (parser);
9726       if (!c_parser_next_token_is_keyword (parser, RID_FOR)
9727 	  && !c_parser_next_token_is_keyword (parser, RID_WHILE)
9728 	  && !c_parser_next_token_is_keyword (parser, RID_DO))
9729 	{
9730 	  c_parser_error (parser, "for, while or do statement expected");
9731 	  return false;
9732 	}
9733       if (c_parser_next_token_is_keyword (parser, RID_FOR))
9734 	c_parser_for_statement (parser, true);
9735       else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
9736 	c_parser_while_statement (parser, true);
9737       else
9738 	c_parser_do_statement (parser, true);
9739       return false;
9740 
9741     case PRAGMA_GCC_PCH_PREPROCESS:
9742       c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
9743       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9744       return false;
9745 
9746     case PRAGMA_CILK_SIMD:
9747       if (!c_parser_cilk_verify_simd (parser, context))
9748 	return false;
9749       c_parser_consume_pragma (parser);
9750       c_parser_cilk_simd (parser);
9751       return false;
9752     case PRAGMA_CILK_GRAINSIZE:
9753       if (!flag_cilkplus)
9754 	{
9755 	  warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9756 		   " enabled");
9757 	  c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9758 	  return false;
9759 	}
9760       if (context == pragma_external)
9761 	{
9762 	  error_at (c_parser_peek_token (parser)->location,
9763 		    "%<#pragma grainsize%> must be inside a function");
9764 	  c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9765 	  return false;
9766 	}
9767       c_parser_cilk_grainsize (parser);
9768       return false;
9769 
9770     default:
9771       if (id < PRAGMA_FIRST_EXTERNAL)
9772 	{
9773 	  if (context != pragma_stmt && context != pragma_compound)
9774 	    {
9775 	    bad_stmt:
9776 	      c_parser_error (parser, "expected declaration specifiers");
9777 	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9778 	      return false;
9779 	    }
9780 	  c_parser_omp_construct (parser);
9781 	  return true;
9782 	}
9783       break;
9784     }
9785 
9786   c_parser_consume_pragma (parser);
9787   c_invoke_pragma_handler (id);
9788 
9789   /* Skip to EOL, but suppress any error message.  Those will have been
9790      generated by the handler routine through calling error, as opposed
9791      to calling c_parser_error.  */
9792   parser->error = true;
9793   c_parser_skip_to_pragma_eol (parser);
9794 
9795   return false;
9796 }
9797 
9798 /* The interface the pragma parsers have to the lexer.  */
9799 
9800 enum cpp_ttype
9801 pragma_lex (tree *value)
9802 {
9803   c_token *tok = c_parser_peek_token (the_parser);
9804   enum cpp_ttype ret = tok->type;
9805 
9806   *value = tok->value;
9807   if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
9808     ret = CPP_EOF;
9809   else
9810     {
9811       if (ret == CPP_KEYWORD)
9812 	ret = CPP_NAME;
9813       c_parser_consume_token (the_parser);
9814     }
9815 
9816   return ret;
9817 }
9818 
9819 static void
9820 c_parser_pragma_pch_preprocess (c_parser *parser)
9821 {
9822   tree name = NULL;
9823 
9824   c_parser_consume_pragma (parser);
9825   if (c_parser_next_token_is (parser, CPP_STRING))
9826     {
9827       name = c_parser_peek_token (parser)->value;
9828       c_parser_consume_token (parser);
9829     }
9830   else
9831     c_parser_error (parser, "expected string literal");
9832   c_parser_skip_to_pragma_eol (parser);
9833 
9834   if (name)
9835     c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
9836 }
9837 
9838 /* OpenACC and OpenMP parsing routines.  */
9839 
9840 /* Returns name of the next clause.
9841    If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9842    the token is not consumed.  Otherwise appropriate pragma_omp_clause is
9843    returned and the token is consumed.  */
9844 
9845 static pragma_omp_clause
9846 c_parser_omp_clause_name (c_parser *parser)
9847 {
9848   pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
9849 
9850   if (c_parser_next_token_is_keyword (parser, RID_AUTO))
9851     result = PRAGMA_OACC_CLAUSE_AUTO;
9852   else if (c_parser_next_token_is_keyword (parser, RID_IF))
9853     result = PRAGMA_OMP_CLAUSE_IF;
9854   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
9855     result = PRAGMA_OMP_CLAUSE_DEFAULT;
9856   else if (c_parser_next_token_is_keyword (parser, RID_FOR))
9857     result = PRAGMA_OMP_CLAUSE_FOR;
9858   else if (c_parser_next_token_is (parser, CPP_NAME))
9859     {
9860       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9861 
9862       switch (p[0])
9863 	{
9864 	case 'a':
9865 	  if (!strcmp ("aligned", p))
9866 	    result = PRAGMA_OMP_CLAUSE_ALIGNED;
9867 	  else if (!strcmp ("async", p))
9868 	    result = PRAGMA_OACC_CLAUSE_ASYNC;
9869 	  break;
9870 	case 'c':
9871 	  if (!strcmp ("collapse", p))
9872 	    result = PRAGMA_OMP_CLAUSE_COLLAPSE;
9873 	  else if (!strcmp ("copy", p))
9874 	    result = PRAGMA_OACC_CLAUSE_COPY;
9875 	  else if (!strcmp ("copyin", p))
9876 	    result = PRAGMA_OMP_CLAUSE_COPYIN;
9877 	  else if (!strcmp ("copyout", p))
9878 	    result = PRAGMA_OACC_CLAUSE_COPYOUT;
9879           else if (!strcmp ("copyprivate", p))
9880 	    result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
9881 	  else if (!strcmp ("create", p))
9882 	    result = PRAGMA_OACC_CLAUSE_CREATE;
9883 	  break;
9884 	case 'd':
9885 	  if (!strcmp ("delete", p))
9886 	    result = PRAGMA_OACC_CLAUSE_DELETE;
9887 	  else if (!strcmp ("depend", p))
9888 	    result = PRAGMA_OMP_CLAUSE_DEPEND;
9889 	  else if (!strcmp ("device", p))
9890 	    result = PRAGMA_OMP_CLAUSE_DEVICE;
9891 	  else if (!strcmp ("deviceptr", p))
9892 	    result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
9893 	  else if (!strcmp ("dist_schedule", p))
9894 	    result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
9895 	  break;
9896 	case 'f':
9897 	  if (!strcmp ("final", p))
9898 	    result = PRAGMA_OMP_CLAUSE_FINAL;
9899 	  else if (!strcmp ("firstprivate", p))
9900 	    result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
9901 	  else if (!strcmp ("from", p))
9902 	    result = PRAGMA_OMP_CLAUSE_FROM;
9903 	  break;
9904 	case 'g':
9905 	  if (!strcmp ("gang", p))
9906 	    result = PRAGMA_OACC_CLAUSE_GANG;
9907 	  break;
9908 	case 'h':
9909 	  if (!strcmp ("host", p))
9910 	    result = PRAGMA_OACC_CLAUSE_HOST;
9911 	  break;
9912 	case 'i':
9913 	  if (!strcmp ("inbranch", p))
9914 	    result = PRAGMA_OMP_CLAUSE_INBRANCH;
9915 	  break;
9916 	case 'l':
9917 	  if (!strcmp ("lastprivate", p))
9918 	    result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
9919 	  else if (!strcmp ("linear", p))
9920 	    result = PRAGMA_OMP_CLAUSE_LINEAR;
9921 	  break;
9922 	case 'm':
9923 	  if (!strcmp ("map", p))
9924 	    result = PRAGMA_OMP_CLAUSE_MAP;
9925 	  else if (!strcmp ("mergeable", p))
9926 	    result = PRAGMA_OMP_CLAUSE_MERGEABLE;
9927 	  else if (flag_cilkplus && !strcmp ("mask", p))
9928 	    result = PRAGMA_CILK_CLAUSE_MASK;
9929 	  break;
9930 	case 'n':
9931 	  if (!strcmp ("notinbranch", p))
9932 	    result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
9933 	  else if (!strcmp ("nowait", p))
9934 	    result = PRAGMA_OMP_CLAUSE_NOWAIT;
9935 	  else if (!strcmp ("num_gangs", p))
9936 	    result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
9937 	  else if (!strcmp ("num_teams", p))
9938 	    result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
9939 	  else if (!strcmp ("num_threads", p))
9940 	    result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
9941 	  else if (!strcmp ("num_workers", p))
9942 	    result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
9943 	  else if (flag_cilkplus && !strcmp ("nomask", p))
9944 	    result = PRAGMA_CILK_CLAUSE_NOMASK;
9945 	  break;
9946 	case 'o':
9947 	  if (!strcmp ("ordered", p))
9948 	    result = PRAGMA_OMP_CLAUSE_ORDERED;
9949 	  break;
9950 	case 'p':
9951 	  if (!strcmp ("parallel", p))
9952 	    result = PRAGMA_OMP_CLAUSE_PARALLEL;
9953 	  else if (!strcmp ("present", p))
9954 	    result = PRAGMA_OACC_CLAUSE_PRESENT;
9955 	  else if (!strcmp ("present_or_copy", p)
9956 		   || !strcmp ("pcopy", p))
9957 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
9958 	  else if (!strcmp ("present_or_copyin", p)
9959 		   || !strcmp ("pcopyin", p))
9960 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
9961 	  else if (!strcmp ("present_or_copyout", p)
9962 		   || !strcmp ("pcopyout", p))
9963 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
9964 	  else if (!strcmp ("present_or_create", p)
9965 		   || !strcmp ("pcreate", p))
9966 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
9967 	  else if (!strcmp ("private", p))
9968 	    result = PRAGMA_OMP_CLAUSE_PRIVATE;
9969 	  else if (!strcmp ("proc_bind", p))
9970 	    result = PRAGMA_OMP_CLAUSE_PROC_BIND;
9971 	  break;
9972 	case 'r':
9973 	  if (!strcmp ("reduction", p))
9974 	    result = PRAGMA_OMP_CLAUSE_REDUCTION;
9975 	  break;
9976 	case 's':
9977 	  if (!strcmp ("safelen", p))
9978 	    result = PRAGMA_OMP_CLAUSE_SAFELEN;
9979 	  else if (!strcmp ("schedule", p))
9980 	    result = PRAGMA_OMP_CLAUSE_SCHEDULE;
9981 	  else if (!strcmp ("sections", p))
9982 	    result = PRAGMA_OMP_CLAUSE_SECTIONS;
9983 	  else if (!strcmp ("seq", p))
9984 	    result = PRAGMA_OACC_CLAUSE_SEQ;
9985 	  else if (!strcmp ("shared", p))
9986 	    result = PRAGMA_OMP_CLAUSE_SHARED;
9987 	  else if (!strcmp ("simdlen", p))
9988 	    result = PRAGMA_OMP_CLAUSE_SIMDLEN;
9989 	  else if (!strcmp ("self", p))
9990 	    result = PRAGMA_OACC_CLAUSE_SELF;
9991 	  break;
9992 	case 't':
9993 	  if (!strcmp ("taskgroup", p))
9994 	    result = PRAGMA_OMP_CLAUSE_TASKGROUP;
9995 	  else if (!strcmp ("thread_limit", p))
9996 	    result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
9997 	  else if (!strcmp ("to", p))
9998 	    result = PRAGMA_OMP_CLAUSE_TO;
9999 	  break;
10000 	case 'u':
10001 	  if (!strcmp ("uniform", p))
10002 	    result = PRAGMA_OMP_CLAUSE_UNIFORM;
10003 	  else if (!strcmp ("untied", p))
10004 	    result = PRAGMA_OMP_CLAUSE_UNTIED;
10005 	  break;
10006 	case 'v':
10007 	  if (!strcmp ("vector", p))
10008 	    result = PRAGMA_OACC_CLAUSE_VECTOR;
10009 	  else if (!strcmp ("vector_length", p))
10010 	    result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
10011 	  else if (flag_cilkplus && !strcmp ("vectorlength", p))
10012 	    result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
10013 	  break;
10014 	case 'w':
10015 	  if (!strcmp ("wait", p))
10016 	    result = PRAGMA_OACC_CLAUSE_WAIT;
10017 	  else if (!strcmp ("worker", p))
10018 	    result = PRAGMA_OACC_CLAUSE_WORKER;
10019 	  break;
10020 	}
10021     }
10022 
10023   if (result != PRAGMA_OMP_CLAUSE_NONE)
10024     c_parser_consume_token (parser);
10025 
10026   return result;
10027 }
10028 
10029 /* Validate that a clause of the given type does not already exist.  */
10030 
10031 static void
10032 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
10033 			   const char *name)
10034 {
10035   tree c;
10036 
10037   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
10038     if (OMP_CLAUSE_CODE (c) == code)
10039       {
10040 	location_t loc = OMP_CLAUSE_LOCATION (c);
10041 	error_at (loc, "too many %qs clauses", name);
10042 	break;
10043       }
10044 }
10045 
10046 /* OpenACC 2.0
10047    Parse wait clause or wait directive parameters.  */
10048 
10049 static tree
10050 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
10051 {
10052   vec<tree, va_gc> *args;
10053   tree t, args_tree;
10054 
10055   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10056     return list;
10057 
10058   args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
10059 
10060   if (args->length () == 0)
10061     {
10062       c_parser_error (parser, "expected integer expression before ')'");
10063       release_tree_vector (args);
10064       return list;
10065     }
10066 
10067   args_tree = build_tree_list_vec (args);
10068 
10069   for (t = args_tree; t; t = TREE_CHAIN (t))
10070     {
10071       tree targ = TREE_VALUE (t);
10072 
10073       if (targ != error_mark_node)
10074 	{
10075 	  if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
10076 	    {
10077 	      c_parser_error (parser, "expression must be integral");
10078 	      targ = error_mark_node;
10079 	    }
10080 	  else
10081 	    {
10082 	      tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
10083 
10084 	      OMP_CLAUSE_DECL (c) = targ;
10085 	      OMP_CLAUSE_CHAIN (c) = list;
10086 	      list = c;
10087 	    }
10088 	}
10089     }
10090 
10091   release_tree_vector (args);
10092   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10093   return list;
10094 }
10095 
10096 /* OpenACC 2.0, OpenMP 2.5:
10097    variable-list:
10098      identifier
10099      variable-list , identifier
10100 
10101    If KIND is nonzero, create the appropriate node and install the
10102    decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10103    If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10104 
10105    If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10106    return the list created.  */
10107 
10108 static tree
10109 c_parser_omp_variable_list (c_parser *parser,
10110 			    location_t clause_loc,
10111 			    enum omp_clause_code kind, tree list)
10112 {
10113   if (c_parser_next_token_is_not (parser, CPP_NAME)
10114       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
10115     c_parser_error (parser, "expected identifier");
10116 
10117   while (c_parser_next_token_is (parser, CPP_NAME)
10118 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
10119     {
10120       tree t = lookup_name (c_parser_peek_token (parser)->value);
10121 
10122       if (t == NULL_TREE)
10123 	{
10124 	  undeclared_variable (c_parser_peek_token (parser)->location,
10125 			       c_parser_peek_token (parser)->value);
10126 	  t = error_mark_node;
10127 	}
10128 
10129       c_parser_consume_token (parser);
10130 
10131       if (t == error_mark_node)
10132 	;
10133       else if (kind != 0)
10134 	{
10135 	  switch (kind)
10136 	    {
10137 	    case OMP_CLAUSE__CACHE_:
10138 	      if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
10139 		{
10140 		  c_parser_error (parser, "expected %<[%>");
10141 		  t = error_mark_node;
10142 		  break;
10143 		}
10144 	      /* FALL THROUGH.  */
10145 	    case OMP_CLAUSE_MAP:
10146 	    case OMP_CLAUSE_FROM:
10147 	    case OMP_CLAUSE_TO:
10148 	    case OMP_CLAUSE_DEPEND:
10149 	      while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
10150 		{
10151 		  tree low_bound = NULL_TREE, length = NULL_TREE;
10152 
10153 		  c_parser_consume_token (parser);
10154 		  if (!c_parser_next_token_is (parser, CPP_COLON))
10155 		    {
10156 		      low_bound = c_parser_expression (parser).value;
10157 		      mark_exp_read (low_bound);
10158 		    }
10159 		  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10160 		    length = integer_one_node;
10161 		  else
10162 		    {
10163 		      /* Look for `:'.  */
10164 		      if (!c_parser_require (parser, CPP_COLON,
10165 					     "expected %<:%>"))
10166 			{
10167 			  t = error_mark_node;
10168 			  break;
10169 			}
10170 		      if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10171 			{
10172 			  length = c_parser_expression (parser).value;
10173 			  mark_exp_read (length);
10174 			}
10175 		    }
10176 		  /* Look for the closing `]'.  */
10177 		  if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
10178 					 "expected %<]%>"))
10179 		    {
10180 		      t = error_mark_node;
10181 		      break;
10182 		    }
10183 
10184 		  if (kind == OMP_CLAUSE__CACHE_)
10185 		    {
10186 		      if (TREE_CODE (low_bound) != INTEGER_CST
10187 			  && !TREE_READONLY (low_bound))
10188 			{
10189 			  error_at (clause_loc,
10190 					"%qD is not a constant", low_bound);
10191 			  t = error_mark_node;
10192 			}
10193 
10194 		      if (TREE_CODE (length) != INTEGER_CST
10195 			  && !TREE_READONLY (length))
10196 			{
10197 			  error_at (clause_loc,
10198 					"%qD is not a constant", length);
10199 			  t = error_mark_node;
10200 			}
10201 		    }
10202 
10203 		  t = tree_cons (low_bound, length, t);
10204 		}
10205 	      break;
10206 	    default:
10207 	      break;
10208 	    }
10209 
10210 	  if (t != error_mark_node)
10211 	    {
10212 	      tree u = build_omp_clause (clause_loc, kind);
10213 	      OMP_CLAUSE_DECL (u) = t;
10214 	      OMP_CLAUSE_CHAIN (u) = list;
10215 	      list = u;
10216 	    }
10217 	}
10218       else
10219 	list = tree_cons (t, NULL_TREE, list);
10220 
10221       if (c_parser_next_token_is_not (parser, CPP_COMMA))
10222 	break;
10223 
10224       c_parser_consume_token (parser);
10225     }
10226 
10227   return list;
10228 }
10229 
10230 /* Similarly, but expect leading and trailing parenthesis.  This is a very
10231    common case for OpenACC and OpenMP clauses.  */
10232 
10233 static tree
10234 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
10235 			      tree list)
10236 {
10237   /* The clauses location.  */
10238   location_t loc = c_parser_peek_token (parser)->location;
10239 
10240   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10241     {
10242       list = c_parser_omp_variable_list (parser, loc, kind, list);
10243       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10244     }
10245   return list;
10246 }
10247 
10248 /* OpenACC 2.0:
10249    copy ( variable-list )
10250    copyin ( variable-list )
10251    copyout ( variable-list )
10252    create ( variable-list )
10253    delete ( variable-list )
10254    present ( variable-list )
10255    present_or_copy ( variable-list )
10256      pcopy ( variable-list )
10257    present_or_copyin ( variable-list )
10258      pcopyin ( variable-list )
10259    present_or_copyout ( variable-list )
10260      pcopyout ( variable-list )
10261    present_or_create ( variable-list )
10262      pcreate ( variable-list ) */
10263 
10264 static tree
10265 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
10266 			   tree list)
10267 {
10268   enum gomp_map_kind kind;
10269   switch (c_kind)
10270     {
10271     case PRAGMA_OACC_CLAUSE_COPY:
10272       kind = GOMP_MAP_FORCE_TOFROM;
10273       break;
10274     case PRAGMA_OACC_CLAUSE_COPYIN:
10275       kind = GOMP_MAP_FORCE_TO;
10276       break;
10277     case PRAGMA_OACC_CLAUSE_COPYOUT:
10278       kind = GOMP_MAP_FORCE_FROM;
10279       break;
10280     case PRAGMA_OACC_CLAUSE_CREATE:
10281       kind = GOMP_MAP_FORCE_ALLOC;
10282       break;
10283     case PRAGMA_OACC_CLAUSE_DELETE:
10284       kind = GOMP_MAP_FORCE_DEALLOC;
10285       break;
10286     case PRAGMA_OACC_CLAUSE_DEVICE:
10287       kind = GOMP_MAP_FORCE_TO;
10288       break;
10289     case PRAGMA_OACC_CLAUSE_HOST:
10290     case PRAGMA_OACC_CLAUSE_SELF:
10291       kind = GOMP_MAP_FORCE_FROM;
10292       break;
10293     case PRAGMA_OACC_CLAUSE_PRESENT:
10294       kind = GOMP_MAP_FORCE_PRESENT;
10295       break;
10296     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
10297       kind = GOMP_MAP_TOFROM;
10298       break;
10299     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
10300       kind = GOMP_MAP_TO;
10301       break;
10302     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
10303       kind = GOMP_MAP_FROM;
10304       break;
10305     case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
10306       kind = GOMP_MAP_ALLOC;
10307       break;
10308     default:
10309       gcc_unreachable ();
10310     }
10311   tree nl, c;
10312   nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
10313 
10314   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10315     OMP_CLAUSE_SET_MAP_KIND (c, kind);
10316 
10317   return nl;
10318 }
10319 
10320 /* OpenACC 2.0:
10321    deviceptr ( variable-list ) */
10322 
10323 static tree
10324 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
10325 {
10326   location_t loc = c_parser_peek_token (parser)->location;
10327   tree vars, t;
10328 
10329   /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10330      c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10331      variable-list must only allow for pointer variables.  */
10332   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10333   for (t = vars; t && t; t = TREE_CHAIN (t))
10334     {
10335       tree v = TREE_PURPOSE (t);
10336 
10337       /* FIXME diagnostics: Ideally we should keep individual
10338 	 locations for all the variables in the var list to make the
10339 	 following errors more precise.  Perhaps
10340 	 c_parser_omp_var_list_parens() should construct a list of
10341 	 locations to go along with the var list.  */
10342 
10343       if (TREE_CODE (v) != VAR_DECL)
10344 	error_at (loc, "%qD is not a variable", v);
10345       else if (TREE_TYPE (v) == error_mark_node)
10346 	;
10347       else if (!POINTER_TYPE_P (TREE_TYPE (v)))
10348 	error_at (loc, "%qD is not a pointer variable", v);
10349 
10350       tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
10351       OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
10352       OMP_CLAUSE_DECL (u) = v;
10353       OMP_CLAUSE_CHAIN (u) = list;
10354       list = u;
10355     }
10356 
10357   return list;
10358 }
10359 
10360 /* OpenACC 2.0, OpenMP 3.0:
10361    collapse ( constant-expression ) */
10362 
10363 static tree
10364 c_parser_omp_clause_collapse (c_parser *parser, tree list)
10365 {
10366   tree c, num = error_mark_node;
10367   HOST_WIDE_INT n;
10368   location_t loc;
10369 
10370   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
10371 
10372   loc = c_parser_peek_token (parser)->location;
10373   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10374     {
10375       num = c_parser_expr_no_commas (parser, NULL).value;
10376       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10377     }
10378   if (num == error_mark_node)
10379     return list;
10380   mark_exp_read (num);
10381   num = c_fully_fold (num, false, NULL);
10382   if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
10383       || !tree_fits_shwi_p (num)
10384       || (n = tree_to_shwi (num)) <= 0
10385       || (int) n != n)
10386     {
10387       error_at (loc,
10388 		"collapse argument needs positive constant integer expression");
10389       return list;
10390     }
10391   c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
10392   OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
10393   OMP_CLAUSE_CHAIN (c) = list;
10394   return c;
10395 }
10396 
10397 /* OpenMP 2.5:
10398    copyin ( variable-list ) */
10399 
10400 static tree
10401 c_parser_omp_clause_copyin (c_parser *parser, tree list)
10402 {
10403   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
10404 }
10405 
10406 /* OpenMP 2.5:
10407    copyprivate ( variable-list ) */
10408 
10409 static tree
10410 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
10411 {
10412   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
10413 }
10414 
10415 /* OpenMP 2.5:
10416    default ( shared | none ) */
10417 
10418 static tree
10419 c_parser_omp_clause_default (c_parser *parser, tree list)
10420 {
10421   enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
10422   location_t loc = c_parser_peek_token (parser)->location;
10423   tree c;
10424 
10425   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10426     return list;
10427   if (c_parser_next_token_is (parser, CPP_NAME))
10428     {
10429       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10430 
10431       switch (p[0])
10432 	{
10433 	case 'n':
10434 	  if (strcmp ("none", p) != 0)
10435 	    goto invalid_kind;
10436 	  kind = OMP_CLAUSE_DEFAULT_NONE;
10437 	  break;
10438 
10439 	case 's':
10440 	  if (strcmp ("shared", p) != 0)
10441 	    goto invalid_kind;
10442 	  kind = OMP_CLAUSE_DEFAULT_SHARED;
10443 	  break;
10444 
10445 	default:
10446 	  goto invalid_kind;
10447 	}
10448 
10449       c_parser_consume_token (parser);
10450     }
10451   else
10452     {
10453     invalid_kind:
10454       c_parser_error (parser, "expected %<none%> or %<shared%>");
10455     }
10456   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10457 
10458   if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
10459     return list;
10460 
10461   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
10462   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
10463   OMP_CLAUSE_CHAIN (c) = list;
10464   OMP_CLAUSE_DEFAULT_KIND (c) = kind;
10465 
10466   return c;
10467 }
10468 
10469 /* OpenMP 2.5:
10470    firstprivate ( variable-list ) */
10471 
10472 static tree
10473 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
10474 {
10475   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
10476 }
10477 
10478 /* OpenMP 3.1:
10479    final ( expression ) */
10480 
10481 static tree
10482 c_parser_omp_clause_final (c_parser *parser, tree list)
10483 {
10484   location_t loc = c_parser_peek_token (parser)->location;
10485   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10486     {
10487       tree t = c_parser_paren_condition (parser);
10488       tree c;
10489 
10490       check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
10491 
10492       c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
10493       OMP_CLAUSE_FINAL_EXPR (c) = t;
10494       OMP_CLAUSE_CHAIN (c) = list;
10495       list = c;
10496     }
10497   else
10498     c_parser_error (parser, "expected %<(%>");
10499 
10500   return list;
10501 }
10502 
10503 /* OpenACC, OpenMP 2.5:
10504    if ( expression ) */
10505 
10506 static tree
10507 c_parser_omp_clause_if (c_parser *parser, tree list)
10508 {
10509   location_t loc = c_parser_peek_token (parser)->location;
10510   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10511     {
10512       tree t = c_parser_paren_condition (parser);
10513       tree c;
10514 
10515       check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
10516 
10517       c = build_omp_clause (loc, OMP_CLAUSE_IF);
10518       OMP_CLAUSE_IF_EXPR (c) = t;
10519       OMP_CLAUSE_CHAIN (c) = list;
10520       list = c;
10521     }
10522   else
10523     c_parser_error (parser, "expected %<(%>");
10524 
10525   return list;
10526 }
10527 
10528 /* OpenMP 2.5:
10529    lastprivate ( variable-list ) */
10530 
10531 static tree
10532 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
10533 {
10534   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
10535 }
10536 
10537 /* OpenMP 3.1:
10538    mergeable */
10539 
10540 static tree
10541 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10542 {
10543   tree c;
10544 
10545   /* FIXME: Should we allow duplicates?  */
10546   check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
10547 
10548   c = build_omp_clause (c_parser_peek_token (parser)->location,
10549 			OMP_CLAUSE_MERGEABLE);
10550   OMP_CLAUSE_CHAIN (c) = list;
10551 
10552   return c;
10553 }
10554 
10555 /* OpenMP 2.5:
10556    nowait */
10557 
10558 static tree
10559 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10560 {
10561   tree c;
10562   location_t loc = c_parser_peek_token (parser)->location;
10563 
10564   check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
10565 
10566   c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
10567   OMP_CLAUSE_CHAIN (c) = list;
10568   return c;
10569 }
10570 
10571 /* OpenACC:
10572    num_gangs ( expression ) */
10573 
10574 static tree
10575 c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
10576 {
10577   location_t num_gangs_loc = c_parser_peek_token (parser)->location;
10578   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10579     {
10580       location_t expr_loc = c_parser_peek_token (parser)->location;
10581       tree c, t = c_parser_expression (parser).value;
10582       mark_exp_read (t);
10583       t = c_fully_fold (t, false, NULL);
10584 
10585       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10586 
10587       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10588 	{
10589 	  c_parser_error (parser, "expected integer expression");
10590 	  return list;
10591 	}
10592 
10593       /* Attempt to statically determine when the number isn't positive.  */
10594       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10595 		       build_int_cst (TREE_TYPE (t), 0));
10596       if (CAN_HAVE_LOCATION_P (c))
10597 	SET_EXPR_LOCATION (c, expr_loc);
10598       if (c == boolean_true_node)
10599 	{
10600 	  warning_at (expr_loc, 0,
10601 		      "%<num_gangs%> value must be positive");
10602 	  t = integer_one_node;
10603 	}
10604 
10605       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
10606 
10607       c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
10608       OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
10609       OMP_CLAUSE_CHAIN (c) = list;
10610       list = c;
10611     }
10612 
10613   return list;
10614 }
10615 
10616 /* OpenMP 2.5:
10617    num_threads ( expression ) */
10618 
10619 static tree
10620 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
10621 {
10622   location_t num_threads_loc = c_parser_peek_token (parser)->location;
10623   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10624     {
10625       location_t expr_loc = c_parser_peek_token (parser)->location;
10626       tree c, t = c_parser_expression (parser).value;
10627       mark_exp_read (t);
10628       t = c_fully_fold (t, false, NULL);
10629 
10630       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10631 
10632       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10633 	{
10634 	  c_parser_error (parser, "expected integer expression");
10635 	  return list;
10636 	}
10637 
10638       /* Attempt to statically determine when the number isn't positive.  */
10639       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10640 		       build_int_cst (TREE_TYPE (t), 0));
10641       if (CAN_HAVE_LOCATION_P (c))
10642 	SET_EXPR_LOCATION (c, expr_loc);
10643       if (c == boolean_true_node)
10644 	{
10645 	  warning_at (expr_loc, 0,
10646 		      "%<num_threads%> value must be positive");
10647 	  t = integer_one_node;
10648 	}
10649 
10650       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
10651 
10652       c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
10653       OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
10654       OMP_CLAUSE_CHAIN (c) = list;
10655       list = c;
10656     }
10657 
10658   return list;
10659 }
10660 
10661 /* OpenACC:
10662    num_workers ( expression ) */
10663 
10664 static tree
10665 c_parser_omp_clause_num_workers (c_parser *parser, tree list)
10666 {
10667   location_t num_workers_loc = c_parser_peek_token (parser)->location;
10668   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10669     {
10670       location_t expr_loc = c_parser_peek_token (parser)->location;
10671       tree c, t = c_parser_expression (parser).value;
10672       mark_exp_read (t);
10673       t = c_fully_fold (t, false, NULL);
10674 
10675       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10676 
10677       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10678 	{
10679 	  c_parser_error (parser, "expected integer expression");
10680 	  return list;
10681 	}
10682 
10683       /* Attempt to statically determine when the number isn't positive.  */
10684       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10685 		       build_int_cst (TREE_TYPE (t), 0));
10686       if (CAN_HAVE_LOCATION_P (c))
10687 	SET_EXPR_LOCATION (c, expr_loc);
10688       if (c == boolean_true_node)
10689 	{
10690 	  warning_at (expr_loc, 0,
10691 		      "%<num_workers%> value must be positive");
10692 	  t = integer_one_node;
10693 	}
10694 
10695       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
10696 
10697       c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
10698       OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
10699       OMP_CLAUSE_CHAIN (c) = list;
10700       list = c;
10701     }
10702 
10703   return list;
10704 }
10705 
10706 /* OpenACC:
10707    async [( int-expr )] */
10708 
10709 static tree
10710 c_parser_oacc_clause_async (c_parser *parser, tree list)
10711 {
10712   tree c, t;
10713   location_t loc = c_parser_peek_token (parser)->location;
10714 
10715   t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
10716 
10717   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
10718     {
10719       c_parser_consume_token (parser);
10720 
10721       t = c_parser_expression (parser).value;
10722       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10723 	c_parser_error (parser, "expected integer expression");
10724       else if (t == error_mark_node
10725 	  || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
10726 	return list;
10727     }
10728   else
10729     t = c_fully_fold (t, false, NULL);
10730 
10731   check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
10732 
10733   c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
10734   OMP_CLAUSE_ASYNC_EXPR (c) = t;
10735   OMP_CLAUSE_CHAIN (c) = list;
10736   list = c;
10737 
10738   return list;
10739 }
10740 
10741 /* OpenACC:
10742    wait ( int-expr-list ) */
10743 
10744 static tree
10745 c_parser_oacc_clause_wait (c_parser *parser, tree list)
10746 {
10747   location_t clause_loc = c_parser_peek_token (parser)->location;
10748 
10749   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
10750     list = c_parser_oacc_wait_list (parser, clause_loc, list);
10751 
10752   return list;
10753 }
10754 
10755 /* OpenMP 2.5:
10756    ordered */
10757 
10758 static tree
10759 c_parser_omp_clause_ordered (c_parser *parser, tree list)
10760 {
10761   tree c;
10762 
10763   check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
10764 
10765   c = build_omp_clause (c_parser_peek_token (parser)->location,
10766 			OMP_CLAUSE_ORDERED);
10767   OMP_CLAUSE_CHAIN (c) = list;
10768 
10769   return c;
10770 }
10771 
10772 /* OpenMP 2.5:
10773    private ( variable-list ) */
10774 
10775 static tree
10776 c_parser_omp_clause_private (c_parser *parser, tree list)
10777 {
10778   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
10779 }
10780 
10781 /* OpenMP 2.5:
10782    reduction ( reduction-operator : variable-list )
10783 
10784    reduction-operator:
10785      One of: + * - & ^ | && ||
10786 
10787    OpenMP 3.1:
10788 
10789    reduction-operator:
10790      One of: + * - & ^ | && || max min
10791 
10792    OpenMP 4.0:
10793 
10794    reduction-operator:
10795      One of: + * - & ^ | && ||
10796      identifier  */
10797 
10798 static tree
10799 c_parser_omp_clause_reduction (c_parser *parser, tree list)
10800 {
10801   location_t clause_loc = c_parser_peek_token (parser)->location;
10802   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10803     {
10804       enum tree_code code = ERROR_MARK;
10805       tree reduc_id = NULL_TREE;
10806 
10807       switch (c_parser_peek_token (parser)->type)
10808 	{
10809 	case CPP_PLUS:
10810 	  code = PLUS_EXPR;
10811 	  break;
10812 	case CPP_MULT:
10813 	  code = MULT_EXPR;
10814 	  break;
10815 	case CPP_MINUS:
10816 	  code = MINUS_EXPR;
10817 	  break;
10818 	case CPP_AND:
10819 	  code = BIT_AND_EXPR;
10820 	  break;
10821 	case CPP_XOR:
10822 	  code = BIT_XOR_EXPR;
10823 	  break;
10824 	case CPP_OR:
10825 	  code = BIT_IOR_EXPR;
10826 	  break;
10827 	case CPP_AND_AND:
10828 	  code = TRUTH_ANDIF_EXPR;
10829 	  break;
10830 	case CPP_OR_OR:
10831 	  code = TRUTH_ORIF_EXPR;
10832 	  break;
10833         case CPP_NAME:
10834 	  {
10835 	    const char *p
10836 	      = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10837 	    if (strcmp (p, "min") == 0)
10838 	      {
10839 		code = MIN_EXPR;
10840 		break;
10841 	      }
10842 	    if (strcmp (p, "max") == 0)
10843 	      {
10844 		code = MAX_EXPR;
10845 		break;
10846 	      }
10847 	    reduc_id = c_parser_peek_token (parser)->value;
10848 	    break;
10849 	  }
10850 	default:
10851 	  c_parser_error (parser,
10852 			  "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10853 			  "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10854 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10855 	  return list;
10856 	}
10857       c_parser_consume_token (parser);
10858       reduc_id = c_omp_reduction_id (code, reduc_id);
10859       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10860 	{
10861 	  tree nl, c;
10862 
10863 	  nl = c_parser_omp_variable_list (parser, clause_loc,
10864 					   OMP_CLAUSE_REDUCTION, list);
10865 	  for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10866 	    {
10867 	      tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
10868 	      OMP_CLAUSE_REDUCTION_CODE (c) = code;
10869 	      if (code == ERROR_MARK
10870 		  || !(INTEGRAL_TYPE_P (type)
10871 		       || TREE_CODE (type) == REAL_TYPE
10872 		       || TREE_CODE (type) == COMPLEX_TYPE))
10873 		OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
10874 		  = c_omp_reduction_lookup (reduc_id,
10875 					    TYPE_MAIN_VARIANT (type));
10876 	    }
10877 
10878 	  list = nl;
10879 	}
10880       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10881     }
10882   return list;
10883 }
10884 
10885 /* OpenMP 2.5:
10886    schedule ( schedule-kind )
10887    schedule ( schedule-kind , expression )
10888 
10889    schedule-kind:
10890      static | dynamic | guided | runtime | auto
10891 */
10892 
10893 static tree
10894 c_parser_omp_clause_schedule (c_parser *parser, tree list)
10895 {
10896   tree c, t;
10897   location_t loc = c_parser_peek_token (parser)->location;
10898 
10899   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10900     return list;
10901 
10902   c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
10903 
10904   if (c_parser_next_token_is (parser, CPP_NAME))
10905     {
10906       tree kind = c_parser_peek_token (parser)->value;
10907       const char *p = IDENTIFIER_POINTER (kind);
10908 
10909       switch (p[0])
10910 	{
10911 	case 'd':
10912 	  if (strcmp ("dynamic", p) != 0)
10913 	    goto invalid_kind;
10914 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
10915 	  break;
10916 
10917         case 'g':
10918 	  if (strcmp ("guided", p) != 0)
10919 	    goto invalid_kind;
10920 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
10921 	  break;
10922 
10923 	case 'r':
10924 	  if (strcmp ("runtime", p) != 0)
10925 	    goto invalid_kind;
10926 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
10927 	  break;
10928 
10929 	default:
10930 	  goto invalid_kind;
10931 	}
10932     }
10933   else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
10934     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
10935   else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
10936     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
10937   else
10938     goto invalid_kind;
10939 
10940   c_parser_consume_token (parser);
10941   if (c_parser_next_token_is (parser, CPP_COMMA))
10942     {
10943       location_t here;
10944       c_parser_consume_token (parser);
10945 
10946       here = c_parser_peek_token (parser)->location;
10947       t = c_parser_expr_no_commas (parser, NULL).value;
10948       mark_exp_read (t);
10949       t = c_fully_fold (t, false, NULL);
10950 
10951       if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
10952 	error_at (here, "schedule %<runtime%> does not take "
10953 		  "a %<chunk_size%> parameter");
10954       else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
10955 	error_at (here,
10956 		  "schedule %<auto%> does not take "
10957 		  "a %<chunk_size%> parameter");
10958       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
10959 	OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
10960       else
10961 	c_parser_error (parser, "expected integer expression");
10962 
10963       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10964     }
10965   else
10966     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
10967 			       "expected %<,%> or %<)%>");
10968 
10969   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
10970   OMP_CLAUSE_CHAIN (c) = list;
10971   return c;
10972 
10973  invalid_kind:
10974   c_parser_error (parser, "invalid schedule kind");
10975   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10976   return list;
10977 }
10978 
10979 /* OpenMP 2.5:
10980    shared ( variable-list ) */
10981 
10982 static tree
10983 c_parser_omp_clause_shared (c_parser *parser, tree list)
10984 {
10985   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
10986 }
10987 
10988 /* OpenMP 3.0:
10989    untied */
10990 
10991 static tree
10992 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10993 {
10994   tree c;
10995 
10996   /* FIXME: Should we allow duplicates?  */
10997   check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
10998 
10999   c = build_omp_clause (c_parser_peek_token (parser)->location,
11000 			OMP_CLAUSE_UNTIED);
11001   OMP_CLAUSE_CHAIN (c) = list;
11002 
11003   return c;
11004 }
11005 
11006 /* OpenACC:
11007    vector_length ( expression ) */
11008 
11009 static tree
11010 c_parser_omp_clause_vector_length (c_parser *parser, tree list)
11011 {
11012   location_t vector_length_loc = c_parser_peek_token (parser)->location;
11013   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11014     {
11015       location_t expr_loc = c_parser_peek_token (parser)->location;
11016       tree c, t = c_parser_expression (parser).value;
11017       mark_exp_read (t);
11018       t = c_fully_fold (t, false, NULL);
11019 
11020       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11021 
11022       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11023 	{
11024 	  c_parser_error (parser, "expected integer expression");
11025 	  return list;
11026 	}
11027 
11028       /* Attempt to statically determine when the number isn't positive.  */
11029       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11030 		       build_int_cst (TREE_TYPE (t), 0));
11031       if (CAN_HAVE_LOCATION_P (c))
11032 	SET_EXPR_LOCATION (c, expr_loc);
11033       if (c == boolean_true_node)
11034 	{
11035 	  warning_at (expr_loc, 0,
11036 		      "%<vector_length%> value must be positive");
11037 	  t = integer_one_node;
11038 	}
11039 
11040       check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
11041 
11042       c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
11043       OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
11044       OMP_CLAUSE_CHAIN (c) = list;
11045       list = c;
11046     }
11047 
11048   return list;
11049 }
11050 
11051 /* OpenMP 4.0:
11052    inbranch
11053    notinbranch */
11054 
11055 static tree
11056 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
11057 			    enum omp_clause_code code, tree list)
11058 {
11059   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11060 
11061   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11062   OMP_CLAUSE_CHAIN (c) = list;
11063 
11064   return c;
11065 }
11066 
11067 /* OpenMP 4.0:
11068    parallel
11069    for
11070    sections
11071    taskgroup */
11072 
11073 static tree
11074 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
11075 				enum omp_clause_code code, tree list)
11076 {
11077   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11078   OMP_CLAUSE_CHAIN (c) = list;
11079 
11080   return c;
11081 }
11082 
11083 /* OpenMP 4.0:
11084    num_teams ( expression ) */
11085 
11086 static tree
11087 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
11088 {
11089   location_t num_teams_loc = c_parser_peek_token (parser)->location;
11090   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11091     {
11092       location_t expr_loc = c_parser_peek_token (parser)->location;
11093       tree c, t = c_parser_expression (parser).value;
11094       mark_exp_read (t);
11095       t = c_fully_fold (t, false, NULL);
11096 
11097       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11098 
11099       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11100 	{
11101 	  c_parser_error (parser, "expected integer expression");
11102 	  return list;
11103 	}
11104 
11105       /* Attempt to statically determine when the number isn't positive.  */
11106       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11107 			   build_int_cst (TREE_TYPE (t), 0));
11108       if (CAN_HAVE_LOCATION_P (c))
11109 	SET_EXPR_LOCATION (c, expr_loc);
11110       if (c == boolean_true_node)
11111 	{
11112 	  warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
11113 	  t = integer_one_node;
11114 	}
11115 
11116       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
11117 
11118       c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
11119       OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
11120       OMP_CLAUSE_CHAIN (c) = list;
11121       list = c;
11122     }
11123 
11124   return list;
11125 }
11126 
11127 /* OpenMP 4.0:
11128    thread_limit ( expression ) */
11129 
11130 static tree
11131 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
11132 {
11133   location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
11134   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11135     {
11136       location_t expr_loc = c_parser_peek_token (parser)->location;
11137       tree c, t = c_parser_expression (parser).value;
11138       mark_exp_read (t);
11139       t = c_fully_fold (t, false, NULL);
11140 
11141       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11142 
11143       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11144 	{
11145 	  c_parser_error (parser, "expected integer expression");
11146 	  return list;
11147 	}
11148 
11149       /* Attempt to statically determine when the number isn't positive.  */
11150       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11151 			   build_int_cst (TREE_TYPE (t), 0));
11152       if (CAN_HAVE_LOCATION_P (c))
11153 	SET_EXPR_LOCATION (c, expr_loc);
11154       if (c == boolean_true_node)
11155 	{
11156 	  warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
11157 	  t = integer_one_node;
11158 	}
11159 
11160       check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
11161 				 "thread_limit");
11162 
11163       c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
11164       OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
11165       OMP_CLAUSE_CHAIN (c) = list;
11166       list = c;
11167     }
11168 
11169   return list;
11170 }
11171 
11172 /* OpenMP 4.0:
11173    aligned ( variable-list )
11174    aligned ( variable-list : constant-expression ) */
11175 
11176 static tree
11177 c_parser_omp_clause_aligned (c_parser *parser, tree list)
11178 {
11179   location_t clause_loc = c_parser_peek_token (parser)->location;
11180   tree nl, c;
11181 
11182   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11183     return list;
11184 
11185   nl = c_parser_omp_variable_list (parser, clause_loc,
11186 				   OMP_CLAUSE_ALIGNED, list);
11187 
11188   if (c_parser_next_token_is (parser, CPP_COLON))
11189     {
11190       c_parser_consume_token (parser);
11191       tree alignment = c_parser_expr_no_commas (parser, NULL).value;
11192       mark_exp_read (alignment);
11193       alignment = c_fully_fold (alignment, false, NULL);
11194       if (TREE_CODE (alignment) != INTEGER_CST
11195 	  || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
11196 	  || tree_int_cst_sgn (alignment) != 1)
11197 	{
11198 	  error_at (clause_loc, "%<aligned%> clause alignment expression must "
11199 				"be positive constant integer expression");
11200 	  alignment = NULL_TREE;
11201 	}
11202 
11203       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11204 	OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
11205     }
11206 
11207   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11208   return nl;
11209 }
11210 
11211 /* OpenMP 4.0:
11212    linear ( variable-list )
11213    linear ( variable-list : expression ) */
11214 
11215 static tree
11216 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn)
11217 {
11218   location_t clause_loc = c_parser_peek_token (parser)->location;
11219   tree nl, c, step;
11220 
11221   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11222     return list;
11223 
11224   nl = c_parser_omp_variable_list (parser, clause_loc,
11225 				   OMP_CLAUSE_LINEAR, list);
11226 
11227   if (c_parser_next_token_is (parser, CPP_COLON))
11228     {
11229       c_parser_consume_token (parser);
11230       step = c_parser_expression (parser).value;
11231       mark_exp_read (step);
11232       step = c_fully_fold (step, false, NULL);
11233       if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL)
11234 	{
11235 	  sorry ("using parameters for %<linear%> step is not supported yet");
11236 	  step = integer_one_node;
11237 	}
11238       if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
11239 	{
11240 	  error_at (clause_loc, "%<linear%> clause step expression must "
11241 				"be integral");
11242 	  step = integer_one_node;
11243 	}
11244 
11245     }
11246   else
11247     step = integer_one_node;
11248 
11249   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11250     {
11251       OMP_CLAUSE_LINEAR_STEP (c) = step;
11252     }
11253 
11254   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11255   return nl;
11256 }
11257 
11258 /* OpenMP 4.0:
11259    safelen ( constant-expression ) */
11260 
11261 static tree
11262 c_parser_omp_clause_safelen (c_parser *parser, tree list)
11263 {
11264   location_t clause_loc = c_parser_peek_token (parser)->location;
11265   tree c, t;
11266 
11267   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11268     return list;
11269 
11270   t = c_parser_expr_no_commas (parser, NULL).value;
11271   mark_exp_read (t);
11272   t = c_fully_fold (t, false, NULL);
11273   if (TREE_CODE (t) != INTEGER_CST
11274       || !INTEGRAL_TYPE_P (TREE_TYPE (t))
11275       || tree_int_cst_sgn (t) != 1)
11276     {
11277       error_at (clause_loc, "%<safelen%> clause expression must "
11278 			    "be positive constant integer expression");
11279       t = NULL_TREE;
11280     }
11281 
11282   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11283   if (t == NULL_TREE || t == error_mark_node)
11284     return list;
11285 
11286   check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
11287 
11288   c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
11289   OMP_CLAUSE_SAFELEN_EXPR (c) = t;
11290   OMP_CLAUSE_CHAIN (c) = list;
11291   return c;
11292 }
11293 
11294 /* OpenMP 4.0:
11295    simdlen ( constant-expression ) */
11296 
11297 static tree
11298 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
11299 {
11300   location_t clause_loc = c_parser_peek_token (parser)->location;
11301   tree c, t;
11302 
11303   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11304     return list;
11305 
11306   t = c_parser_expr_no_commas (parser, NULL).value;
11307   mark_exp_read (t);
11308   t = c_fully_fold (t, false, NULL);
11309   if (TREE_CODE (t) != INTEGER_CST
11310       || !INTEGRAL_TYPE_P (TREE_TYPE (t))
11311       || tree_int_cst_sgn (t) != 1)
11312     {
11313       error_at (clause_loc, "%<simdlen%> clause expression must "
11314 			    "be positive constant integer expression");
11315       t = NULL_TREE;
11316     }
11317 
11318   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11319   if (t == NULL_TREE || t == error_mark_node)
11320     return list;
11321 
11322   check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
11323 
11324   c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
11325   OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
11326   OMP_CLAUSE_CHAIN (c) = list;
11327   return c;
11328 }
11329 
11330 /* OpenMP 4.0:
11331    depend ( depend-kind: variable-list )
11332 
11333    depend-kind:
11334      in | out | inout  */
11335 
11336 static tree
11337 c_parser_omp_clause_depend (c_parser *parser, tree list)
11338 {
11339   location_t clause_loc = c_parser_peek_token (parser)->location;
11340   enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
11341   tree nl, c;
11342 
11343   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11344     return list;
11345 
11346   if (c_parser_next_token_is (parser, CPP_NAME))
11347     {
11348       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11349       if (strcmp ("in", p) == 0)
11350 	kind = OMP_CLAUSE_DEPEND_IN;
11351       else if (strcmp ("inout", p) == 0)
11352 	kind = OMP_CLAUSE_DEPEND_INOUT;
11353       else if (strcmp ("out", p) == 0)
11354 	kind = OMP_CLAUSE_DEPEND_OUT;
11355       else
11356 	goto invalid_kind;
11357     }
11358   else
11359     goto invalid_kind;
11360 
11361   c_parser_consume_token (parser);
11362   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11363     goto resync_fail;
11364 
11365   nl = c_parser_omp_variable_list (parser, clause_loc,
11366 				   OMP_CLAUSE_DEPEND, list);
11367 
11368   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11369     OMP_CLAUSE_DEPEND_KIND (c) = kind;
11370 
11371   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11372   return nl;
11373 
11374  invalid_kind:
11375   c_parser_error (parser, "invalid depend kind");
11376  resync_fail:
11377   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11378   return list;
11379 }
11380 
11381 /* OpenMP 4.0:
11382    map ( map-kind: variable-list )
11383    map ( variable-list )
11384 
11385    map-kind:
11386      alloc | to | from | tofrom  */
11387 
11388 static tree
11389 c_parser_omp_clause_map (c_parser *parser, tree list)
11390 {
11391   location_t clause_loc = c_parser_peek_token (parser)->location;
11392   enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11393   tree nl, c;
11394 
11395   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11396     return list;
11397 
11398   if (c_parser_next_token_is (parser, CPP_NAME)
11399       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11400     {
11401       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11402       if (strcmp ("alloc", p) == 0)
11403 	kind = GOMP_MAP_ALLOC;
11404       else if (strcmp ("to", p) == 0)
11405 	kind = GOMP_MAP_TO;
11406       else if (strcmp ("from", p) == 0)
11407 	kind = GOMP_MAP_FROM;
11408       else if (strcmp ("tofrom", p) == 0)
11409 	kind = GOMP_MAP_TOFROM;
11410       else
11411 	{
11412 	  c_parser_error (parser, "invalid map kind");
11413 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11414 				     "expected %<)%>");
11415 	  return list;
11416 	}
11417       c_parser_consume_token (parser);
11418       c_parser_consume_token (parser);
11419     }
11420 
11421   nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
11422 
11423   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11424     OMP_CLAUSE_SET_MAP_KIND (c, kind);
11425 
11426   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11427   return nl;
11428 }
11429 
11430 /* OpenMP 4.0:
11431    device ( expression ) */
11432 
11433 static tree
11434 c_parser_omp_clause_device (c_parser *parser, tree list)
11435 {
11436   location_t clause_loc = c_parser_peek_token (parser)->location;
11437   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11438     {
11439       tree c, t = c_parser_expr_no_commas (parser, NULL).value;
11440       mark_exp_read (t);
11441       t = c_fully_fold (t, false, NULL);
11442 
11443       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11444 
11445       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11446 	{
11447 	  c_parser_error (parser, "expected integer expression");
11448 	  return list;
11449 	}
11450 
11451       check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
11452 
11453       c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
11454       OMP_CLAUSE_DEVICE_ID (c) = t;
11455       OMP_CLAUSE_CHAIN (c) = list;
11456       list = c;
11457     }
11458 
11459   return list;
11460 }
11461 
11462 /* OpenMP 4.0:
11463    dist_schedule ( static )
11464    dist_schedule ( static , expression ) */
11465 
11466 static tree
11467 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
11468 {
11469   tree c, t = NULL_TREE;
11470   location_t loc = c_parser_peek_token (parser)->location;
11471 
11472   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11473     return list;
11474 
11475   if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
11476     {
11477       c_parser_error (parser, "invalid dist_schedule kind");
11478       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11479 				 "expected %<)%>");
11480       return list;
11481     }
11482 
11483   c_parser_consume_token (parser);
11484   if (c_parser_next_token_is (parser, CPP_COMMA))
11485     {
11486       c_parser_consume_token (parser);
11487 
11488       t = c_parser_expr_no_commas (parser, NULL).value;
11489       mark_exp_read (t);
11490       t = c_fully_fold (t, false, NULL);
11491       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11492     }
11493   else
11494     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11495 			       "expected %<,%> or %<)%>");
11496 
11497   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
11498   if (t == error_mark_node)
11499     return list;
11500 
11501   c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
11502   OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
11503   OMP_CLAUSE_CHAIN (c) = list;
11504   return c;
11505 }
11506 
11507 /* OpenMP 4.0:
11508    proc_bind ( proc-bind-kind )
11509 
11510    proc-bind-kind:
11511      master | close | spread  */
11512 
11513 static tree
11514 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
11515 {
11516   location_t clause_loc = c_parser_peek_token (parser)->location;
11517   enum omp_clause_proc_bind_kind kind;
11518   tree c;
11519 
11520   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11521     return list;
11522 
11523   if (c_parser_next_token_is (parser, CPP_NAME))
11524     {
11525       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11526       if (strcmp ("master", p) == 0)
11527 	kind = OMP_CLAUSE_PROC_BIND_MASTER;
11528       else if (strcmp ("close", p) == 0)
11529 	kind = OMP_CLAUSE_PROC_BIND_CLOSE;
11530       else if (strcmp ("spread", p) == 0)
11531 	kind = OMP_CLAUSE_PROC_BIND_SPREAD;
11532       else
11533 	goto invalid_kind;
11534     }
11535   else
11536     goto invalid_kind;
11537 
11538   c_parser_consume_token (parser);
11539   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11540   c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
11541   OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
11542   OMP_CLAUSE_CHAIN (c) = list;
11543   return c;
11544 
11545  invalid_kind:
11546   c_parser_error (parser, "invalid proc_bind kind");
11547   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11548   return list;
11549 }
11550 
11551 /* OpenMP 4.0:
11552    to ( variable-list ) */
11553 
11554 static tree
11555 c_parser_omp_clause_to (c_parser *parser, tree list)
11556 {
11557   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
11558 }
11559 
11560 /* OpenMP 4.0:
11561    from ( variable-list ) */
11562 
11563 static tree
11564 c_parser_omp_clause_from (c_parser *parser, tree list)
11565 {
11566   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
11567 }
11568 
11569 /* OpenMP 4.0:
11570    uniform ( variable-list ) */
11571 
11572 static tree
11573 c_parser_omp_clause_uniform (c_parser *parser, tree list)
11574 {
11575   /* The clauses location.  */
11576   location_t loc = c_parser_peek_token (parser)->location;
11577 
11578   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11579     {
11580       list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
11581 					 list);
11582       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11583     }
11584   return list;
11585 }
11586 
11587 /* Parse all OpenACC clauses.  The set clauses allowed by the directive
11588    is a bitmask in MASK.  Return the list of clauses found.  */
11589 
11590 static tree
11591 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
11592 			   const char *where, bool finish_p = true)
11593 {
11594   tree clauses = NULL;
11595   bool first = true;
11596 
11597   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11598     {
11599       location_t here;
11600       pragma_omp_clause c_kind;
11601       const char *c_name;
11602       tree prev = clauses;
11603 
11604       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11605 	c_parser_consume_token (parser);
11606 
11607       here = c_parser_peek_token (parser)->location;
11608       c_kind = c_parser_omp_clause_name (parser);
11609 
11610       switch (c_kind)
11611 	{
11612 	case PRAGMA_OACC_CLAUSE_ASYNC:
11613 	  clauses = c_parser_oacc_clause_async (parser, clauses);
11614 	  c_name = "async";
11615 	  break;
11616 	case PRAGMA_OACC_CLAUSE_COLLAPSE:
11617 	  clauses = c_parser_omp_clause_collapse (parser, clauses);
11618 	  c_name = "collapse";
11619 	  break;
11620 	case PRAGMA_OACC_CLAUSE_COPY:
11621 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11622 	  c_name = "copy";
11623 	  break;
11624 	case PRAGMA_OACC_CLAUSE_COPYIN:
11625 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11626 	  c_name = "copyin";
11627 	  break;
11628 	case PRAGMA_OACC_CLAUSE_COPYOUT:
11629 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11630 	  c_name = "copyout";
11631 	  break;
11632 	case PRAGMA_OACC_CLAUSE_CREATE:
11633 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11634 	  c_name = "create";
11635 	  break;
11636 	case PRAGMA_OACC_CLAUSE_DELETE:
11637 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11638 	  c_name = "delete";
11639 	  break;
11640 	case PRAGMA_OACC_CLAUSE_DEVICE:
11641 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11642 	  c_name = "device";
11643 	  break;
11644 	case PRAGMA_OACC_CLAUSE_DEVICEPTR:
11645 	  clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
11646 	  c_name = "deviceptr";
11647 	  break;
11648 	case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
11649 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
11650 	  c_name = "firstprivate";
11651 	  break;
11652 	case PRAGMA_OACC_CLAUSE_HOST:
11653 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11654 	  c_name = "host";
11655 	  break;
11656 	case PRAGMA_OACC_CLAUSE_IF:
11657 	  clauses = c_parser_omp_clause_if (parser, clauses);
11658 	  c_name = "if";
11659 	  break;
11660 	case PRAGMA_OACC_CLAUSE_NUM_GANGS:
11661 	  clauses = c_parser_omp_clause_num_gangs (parser, clauses);
11662 	  c_name = "num_gangs";
11663 	  break;
11664 	case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
11665 	  clauses = c_parser_omp_clause_num_workers (parser, clauses);
11666 	  c_name = "num_workers";
11667 	  break;
11668 	case PRAGMA_OACC_CLAUSE_PRESENT:
11669 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11670 	  c_name = "present";
11671 	  break;
11672 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
11673 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11674 	  c_name = "present_or_copy";
11675 	  break;
11676 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
11677 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11678 	  c_name = "present_or_copyin";
11679 	  break;
11680 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
11681 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11682 	  c_name = "present_or_copyout";
11683 	  break;
11684 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
11685 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11686 	  c_name = "present_or_create";
11687 	  break;
11688 	case PRAGMA_OACC_CLAUSE_PRIVATE:
11689 	  clauses = c_parser_omp_clause_private (parser, clauses);
11690 	  c_name = "private";
11691 	  break;
11692 	case PRAGMA_OACC_CLAUSE_REDUCTION:
11693 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
11694 	  c_name = "reduction";
11695 	  break;
11696 	case PRAGMA_OACC_CLAUSE_SELF:
11697 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11698 	  c_name = "self";
11699 	  break;
11700 	case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
11701 	  clauses = c_parser_omp_clause_vector_length (parser, clauses);
11702 	  c_name = "vector_length";
11703 	  break;
11704 	case PRAGMA_OACC_CLAUSE_WAIT:
11705 	  clauses = c_parser_oacc_clause_wait (parser, clauses);
11706 	  c_name = "wait";
11707 	  break;
11708 	default:
11709 	  c_parser_error (parser, "expected %<#pragma acc%> clause");
11710 	  goto saw_error;
11711 	}
11712 
11713       first = false;
11714 
11715       if (((mask >> c_kind) & 1) == 0)
11716 	{
11717 	  /* Remove the invalid clause(s) from the list to avoid
11718 	     confusing the rest of the compiler.  */
11719 	  clauses = prev;
11720 	  error_at (here, "%qs is not valid for %qs", c_name, where);
11721 	}
11722     }
11723 
11724  saw_error:
11725   c_parser_skip_to_pragma_eol (parser);
11726 
11727   if (finish_p)
11728     return c_finish_omp_clauses (clauses);
11729 
11730   return clauses;
11731 }
11732 
11733 /* Parse all OpenMP clauses.  The set clauses allowed by the directive
11734    is a bitmask in MASK.  Return the list of clauses found.  */
11735 
11736 static tree
11737 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
11738 			  const char *where, bool finish_p = true)
11739 {
11740   tree clauses = NULL;
11741   bool first = true, cilk_simd_fn = false;
11742 
11743   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11744     {
11745       location_t here;
11746       pragma_omp_clause c_kind;
11747       const char *c_name;
11748       tree prev = clauses;
11749 
11750       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11751 	c_parser_consume_token (parser);
11752 
11753       here = c_parser_peek_token (parser)->location;
11754       c_kind = c_parser_omp_clause_name (parser);
11755 
11756       switch (c_kind)
11757 	{
11758 	case PRAGMA_OMP_CLAUSE_COLLAPSE:
11759 	  clauses = c_parser_omp_clause_collapse (parser, clauses);
11760 	  c_name = "collapse";
11761 	  break;
11762 	case PRAGMA_OMP_CLAUSE_COPYIN:
11763 	  clauses = c_parser_omp_clause_copyin (parser, clauses);
11764 	  c_name = "copyin";
11765 	  break;
11766 	case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
11767 	  clauses = c_parser_omp_clause_copyprivate (parser, clauses);
11768 	  c_name = "copyprivate";
11769 	  break;
11770 	case PRAGMA_OMP_CLAUSE_DEFAULT:
11771 	  clauses = c_parser_omp_clause_default (parser, clauses);
11772 	  c_name = "default";
11773 	  break;
11774 	case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
11775 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
11776 	  c_name = "firstprivate";
11777 	  break;
11778 	case PRAGMA_OMP_CLAUSE_FINAL:
11779 	  clauses = c_parser_omp_clause_final (parser, clauses);
11780 	  c_name = "final";
11781 	  break;
11782 	case PRAGMA_OMP_CLAUSE_IF:
11783 	  clauses = c_parser_omp_clause_if (parser, clauses);
11784 	  c_name = "if";
11785 	  break;
11786 	case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
11787 	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
11788 	  c_name = "lastprivate";
11789 	  break;
11790 	case PRAGMA_OMP_CLAUSE_MERGEABLE:
11791 	  clauses = c_parser_omp_clause_mergeable (parser, clauses);
11792 	  c_name = "mergeable";
11793 	  break;
11794 	case PRAGMA_OMP_CLAUSE_NOWAIT:
11795 	  clauses = c_parser_omp_clause_nowait (parser, clauses);
11796 	  c_name = "nowait";
11797 	  break;
11798 	case PRAGMA_OMP_CLAUSE_NUM_THREADS:
11799 	  clauses = c_parser_omp_clause_num_threads (parser, clauses);
11800 	  c_name = "num_threads";
11801 	  break;
11802 	case PRAGMA_OMP_CLAUSE_ORDERED:
11803 	  clauses = c_parser_omp_clause_ordered (parser, clauses);
11804 	  c_name = "ordered";
11805 	  break;
11806 	case PRAGMA_OMP_CLAUSE_PRIVATE:
11807 	  clauses = c_parser_omp_clause_private (parser, clauses);
11808 	  c_name = "private";
11809 	  break;
11810 	case PRAGMA_OMP_CLAUSE_REDUCTION:
11811 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
11812 	  c_name = "reduction";
11813 	  break;
11814 	case PRAGMA_OMP_CLAUSE_SCHEDULE:
11815 	  clauses = c_parser_omp_clause_schedule (parser, clauses);
11816 	  c_name = "schedule";
11817 	  break;
11818 	case PRAGMA_OMP_CLAUSE_SHARED:
11819 	  clauses = c_parser_omp_clause_shared (parser, clauses);
11820 	  c_name = "shared";
11821 	  break;
11822 	case PRAGMA_OMP_CLAUSE_UNTIED:
11823 	  clauses = c_parser_omp_clause_untied (parser, clauses);
11824 	  c_name = "untied";
11825 	  break;
11826 	case PRAGMA_OMP_CLAUSE_INBRANCH:
11827 	case PRAGMA_CILK_CLAUSE_MASK:
11828 	  clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
11829 						clauses);
11830 	  c_name = "inbranch";
11831 	  break;
11832 	case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
11833 	case PRAGMA_CILK_CLAUSE_NOMASK:
11834 	  clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
11835 						clauses);
11836 	  c_name = "notinbranch";
11837 	  break;
11838 	case PRAGMA_OMP_CLAUSE_PARALLEL:
11839 	  clauses
11840 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
11841 					      clauses);
11842 	  c_name = "parallel";
11843 	  if (!first)
11844 	    {
11845 	     clause_not_first:
11846 	      error_at (here, "%qs must be the first clause of %qs",
11847 			c_name, where);
11848 	      clauses = prev;
11849 	    }
11850 	  break;
11851 	case PRAGMA_OMP_CLAUSE_FOR:
11852 	  clauses
11853 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
11854 					      clauses);
11855 	  c_name = "for";
11856 	  if (!first)
11857 	    goto clause_not_first;
11858 	  break;
11859 	case PRAGMA_OMP_CLAUSE_SECTIONS:
11860 	  clauses
11861 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
11862 					      clauses);
11863 	  c_name = "sections";
11864 	  if (!first)
11865 	    goto clause_not_first;
11866 	  break;
11867 	case PRAGMA_OMP_CLAUSE_TASKGROUP:
11868 	  clauses
11869 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
11870 					      clauses);
11871 	  c_name = "taskgroup";
11872 	  if (!first)
11873 	    goto clause_not_first;
11874 	  break;
11875 	case PRAGMA_OMP_CLAUSE_TO:
11876 	  clauses = c_parser_omp_clause_to (parser, clauses);
11877 	  c_name = "to";
11878 	  break;
11879 	case PRAGMA_OMP_CLAUSE_FROM:
11880 	  clauses = c_parser_omp_clause_from (parser, clauses);
11881 	  c_name = "from";
11882 	  break;
11883 	case PRAGMA_OMP_CLAUSE_UNIFORM:
11884 	  clauses = c_parser_omp_clause_uniform (parser, clauses);
11885 	  c_name = "uniform";
11886 	  break;
11887 	case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
11888 	  clauses = c_parser_omp_clause_num_teams (parser, clauses);
11889 	  c_name = "num_teams";
11890 	  break;
11891 	case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
11892 	  clauses = c_parser_omp_clause_thread_limit (parser, clauses);
11893 	  c_name = "thread_limit";
11894 	  break;
11895 	case PRAGMA_OMP_CLAUSE_ALIGNED:
11896 	  clauses = c_parser_omp_clause_aligned (parser, clauses);
11897 	  c_name = "aligned";
11898 	  break;
11899 	case PRAGMA_OMP_CLAUSE_LINEAR:
11900 	  if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0)
11901 	   cilk_simd_fn = true;
11902 	  clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn);
11903 	  c_name = "linear";
11904 	  break;
11905 	case PRAGMA_OMP_CLAUSE_DEPEND:
11906 	  clauses = c_parser_omp_clause_depend (parser, clauses);
11907 	  c_name = "depend";
11908 	  break;
11909 	case PRAGMA_OMP_CLAUSE_MAP:
11910 	  clauses = c_parser_omp_clause_map (parser, clauses);
11911 	  c_name = "map";
11912 	  break;
11913 	case PRAGMA_OMP_CLAUSE_DEVICE:
11914 	  clauses = c_parser_omp_clause_device (parser, clauses);
11915 	  c_name = "device";
11916 	  break;
11917 	case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
11918 	  clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
11919 	  c_name = "dist_schedule";
11920 	  break;
11921 	case PRAGMA_OMP_CLAUSE_PROC_BIND:
11922 	  clauses = c_parser_omp_clause_proc_bind (parser, clauses);
11923 	  c_name = "proc_bind";
11924 	  break;
11925 	case PRAGMA_OMP_CLAUSE_SAFELEN:
11926 	  clauses = c_parser_omp_clause_safelen (parser, clauses);
11927 	  c_name = "safelen";
11928 	  break;
11929 	case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
11930 	  clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true);
11931 	  c_name = "simdlen";
11932 	  break;
11933 	case PRAGMA_OMP_CLAUSE_SIMDLEN:
11934 	  clauses = c_parser_omp_clause_simdlen (parser, clauses);
11935 	  c_name = "simdlen";
11936 	  break;
11937 	default:
11938 	  c_parser_error (parser, "expected %<#pragma omp%> clause");
11939 	  goto saw_error;
11940 	}
11941 
11942       first = false;
11943 
11944       if (((mask >> c_kind) & 1) == 0)
11945 	{
11946 	  /* Remove the invalid clause(s) from the list to avoid
11947 	     confusing the rest of the compiler.  */
11948 	  clauses = prev;
11949 	  error_at (here, "%qs is not valid for %qs", c_name, where);
11950 	}
11951     }
11952 
11953  saw_error:
11954   c_parser_skip_to_pragma_eol (parser);
11955 
11956   if (finish_p)
11957     return c_finish_omp_clauses (clauses);
11958 
11959   return clauses;
11960 }
11961 
11962 /* OpenACC 2.0, OpenMP 2.5:
11963    structured-block:
11964      statement
11965 
11966    In practice, we're also interested in adding the statement to an
11967    outer node.  So it is convenient if we work around the fact that
11968    c_parser_statement calls add_stmt.  */
11969 
11970 static tree
11971 c_parser_omp_structured_block (c_parser *parser)
11972 {
11973   tree stmt = push_stmt_list ();
11974   c_parser_statement (parser);
11975   return pop_stmt_list (stmt);
11976 }
11977 
11978 /* OpenACC 2.0:
11979    # pragma acc cache (variable-list) new-line
11980 
11981    LOC is the location of the #pragma token.
11982 */
11983 
11984 static tree
11985 c_parser_oacc_cache (location_t loc, c_parser *parser)
11986 {
11987   tree stmt, clauses;
11988 
11989   clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
11990   clauses = c_finish_omp_clauses (clauses);
11991 
11992   c_parser_skip_to_pragma_eol (parser);
11993 
11994   stmt = make_node (OACC_CACHE);
11995   TREE_TYPE (stmt) = void_type_node;
11996   OACC_CACHE_CLAUSES (stmt) = clauses;
11997   SET_EXPR_LOCATION (stmt, loc);
11998   add_stmt (stmt);
11999 
12000   return stmt;
12001 }
12002 
12003 /* OpenACC 2.0:
12004    # pragma acc data oacc-data-clause[optseq] new-line
12005      structured-block
12006 
12007    LOC is the location of the #pragma token.
12008 */
12009 
12010 #define OACC_DATA_CLAUSE_MASK						\
12011 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
12012 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
12013 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
12014 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
12015 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
12016 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
12017 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
12018 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
12019 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
12020 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
12021 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12022 
12023 static tree
12024 c_parser_oacc_data (location_t loc, c_parser *parser)
12025 {
12026   tree stmt, clauses, block;
12027 
12028   clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
12029 				       "#pragma acc data");
12030 
12031   block = c_begin_omp_parallel ();
12032   add_stmt (c_parser_omp_structured_block (parser));
12033 
12034   stmt = c_finish_oacc_data (loc, clauses, block);
12035 
12036   return stmt;
12037 }
12038 
12039 /* OpenACC 2.0:
12040    # pragma acc kernels oacc-kernels-clause[optseq] new-line
12041      structured-block
12042 
12043    LOC is the location of the #pragma token.
12044 */
12045 
12046 #define OACC_KERNELS_CLAUSE_MASK					\
12047 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
12048 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
12049 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
12050 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
12051 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
12052 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
12053 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
12054 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
12055 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
12056 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
12057 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
12058 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
12059 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12060 
12061 static tree
12062 c_parser_oacc_kernels (location_t loc, c_parser *parser, char *p_name)
12063 {
12064   tree stmt, clauses = NULL_TREE, block;
12065 
12066   strcat (p_name, " kernels");
12067 
12068   if (c_parser_next_token_is (parser, CPP_NAME))
12069     {
12070       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12071       if (strcmp (p, "loop") == 0)
12072 	{
12073 	  c_parser_consume_token (parser);
12074 	  block = c_begin_omp_parallel ();
12075 	  c_parser_oacc_loop (loc, parser, p_name);
12076 	  stmt = c_finish_oacc_kernels (loc, clauses, block);
12077 	  OACC_KERNELS_COMBINED (stmt) = 1;
12078 	  return stmt;
12079 	}
12080     }
12081 
12082   clauses =  c_parser_oacc_all_clauses (parser, OACC_KERNELS_CLAUSE_MASK,
12083 					p_name);
12084 
12085   block = c_begin_omp_parallel ();
12086   add_stmt (c_parser_omp_structured_block (parser));
12087 
12088   stmt = c_finish_oacc_kernels (loc, clauses, block);
12089 
12090   return stmt;
12091 }
12092 
12093 /* OpenACC 2.0:
12094    # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12095 
12096    or
12097 
12098    # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12099 
12100 
12101    LOC is the location of the #pragma token.
12102 */
12103 
12104 #define OACC_ENTER_DATA_CLAUSE_MASK					\
12105 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
12106 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
12107 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
12108 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
12109 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
12110 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
12111 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12112 
12113 #define OACC_EXIT_DATA_CLAUSE_MASK					\
12114 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
12115 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
12116 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
12117 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) 		\
12118 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12119 
12120 static void
12121 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
12122 {
12123   location_t loc = c_parser_peek_token (parser)->location;
12124   tree clauses, stmt;
12125 
12126   c_parser_consume_pragma (parser);
12127 
12128   if (!c_parser_next_token_is (parser, CPP_NAME))
12129     {
12130       c_parser_error (parser, enter
12131 		      ? "expected %<data%> in %<#pragma acc enter data%>"
12132 		      : "expected %<data%> in %<#pragma acc exit data%>");
12133       c_parser_skip_to_pragma_eol (parser);
12134       return;
12135     }
12136 
12137   const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12138   if (strcmp (p, "data") != 0)
12139     {
12140       c_parser_error (parser, "invalid pragma");
12141       c_parser_skip_to_pragma_eol (parser);
12142       return;
12143     }
12144 
12145   c_parser_consume_token (parser);
12146 
12147   if (enter)
12148     clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
12149 					 "#pragma acc enter data");
12150   else
12151     clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
12152 					 "#pragma acc exit data");
12153 
12154   if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12155     {
12156       error_at (loc, enter
12157 		? "%<#pragma acc enter data%> has no data movement clause"
12158 		: "%<#pragma acc exit data%> has no data movement clause");
12159       return;
12160     }
12161 
12162   stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);
12163   TREE_TYPE (stmt) = void_type_node;
12164   if (enter)
12165     OACC_ENTER_DATA_CLAUSES (stmt) = clauses;
12166   else
12167     OACC_EXIT_DATA_CLAUSES (stmt) = clauses;
12168   SET_EXPR_LOCATION (stmt, loc);
12169   add_stmt (stmt);
12170 }
12171 
12172 
12173 /* OpenACC 2.0:
12174 
12175    # pragma acc loop oacc-loop-clause[optseq] new-line
12176      structured-block
12177 
12178    LOC is the location of the #pragma token.
12179 */
12180 
12181 #define OACC_LOOP_CLAUSE_MASK						\
12182 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE)		\
12183 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12184 
12185 static tree
12186 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name)
12187 {
12188   tree stmt, clauses, block;
12189 
12190   strcat (p_name, " loop");
12191 
12192   clauses = c_parser_oacc_all_clauses (parser, OACC_LOOP_CLAUSE_MASK, p_name);
12193 
12194   block = c_begin_compound_stmt (true);
12195   stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL);
12196   block = c_end_compound_stmt (loc, block, true);
12197   add_stmt (block);
12198 
12199   return stmt;
12200 }
12201 
12202 /* OpenACC 2.0:
12203    # pragma acc parallel oacc-parallel-clause[optseq] new-line
12204      structured-block
12205 
12206    LOC is the location of the #pragma token.
12207 */
12208 
12209 #define OACC_PARALLEL_CLAUSE_MASK					\
12210 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
12211 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
12212 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
12213 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
12214 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
12215 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
12216 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
12217 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS)		\
12218 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS)		\
12219 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
12220 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
12221 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
12222 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
12223 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
12224 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION)		\
12225 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH)	\
12226 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12227 
12228 static tree
12229 c_parser_oacc_parallel (location_t loc, c_parser *parser, char *p_name)
12230 {
12231   tree stmt, clauses = NULL_TREE, block;
12232 
12233   strcat (p_name, " parallel");
12234 
12235   if (c_parser_next_token_is (parser, CPP_NAME))
12236     {
12237       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12238       if (strcmp (p, "loop") == 0)
12239 	{
12240 	  c_parser_consume_token (parser);
12241 	  block = c_begin_omp_parallel ();
12242 	  c_parser_oacc_loop (loc, parser, p_name);
12243 	  stmt = c_finish_oacc_parallel (loc, clauses, block);
12244 	  OACC_PARALLEL_COMBINED (stmt) = 1;
12245 	  return stmt;
12246 	}
12247     }
12248 
12249   clauses =  c_parser_oacc_all_clauses (parser, OACC_PARALLEL_CLAUSE_MASK,
12250 					p_name);
12251 
12252   block = c_begin_omp_parallel ();
12253   add_stmt (c_parser_omp_structured_block (parser));
12254 
12255   stmt = c_finish_oacc_parallel (loc, clauses, block);
12256 
12257   return stmt;
12258 }
12259 
12260 /* OpenACC 2.0:
12261    # pragma acc update oacc-update-clause[optseq] new-line
12262 */
12263 
12264 #define OACC_UPDATE_CLAUSE_MASK						\
12265 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
12266 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE)		\
12267 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)		\
12268 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
12269 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF)		\
12270 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12271 
12272 static void
12273 c_parser_oacc_update (c_parser *parser)
12274 {
12275   location_t loc = c_parser_peek_token (parser)->location;
12276 
12277   c_parser_consume_pragma (parser);
12278 
12279   tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
12280 					    "#pragma acc update");
12281   if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12282     {
12283       error_at (loc,
12284 		"%<#pragma acc update%> must contain at least one "
12285 		"%<device%> or %<host/self%> clause");
12286       return;
12287     }
12288 
12289   if (parser->error)
12290     return;
12291 
12292   tree stmt = make_node (OACC_UPDATE);
12293   TREE_TYPE (stmt) = void_type_node;
12294   OACC_UPDATE_CLAUSES (stmt) = clauses;
12295   SET_EXPR_LOCATION (stmt, loc);
12296   add_stmt (stmt);
12297 }
12298 
12299 /* OpenACC 2.0:
12300    # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12301 
12302    LOC is the location of the #pragma token.
12303 */
12304 
12305 #define OACC_WAIT_CLAUSE_MASK						\
12306 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12307 
12308 static tree
12309 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
12310 {
12311   tree clauses, list = NULL_TREE, stmt = NULL_TREE;
12312 
12313   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12314     list = c_parser_oacc_wait_list (parser, loc, list);
12315 
12316   strcpy (p_name, " wait");
12317   clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
12318   stmt = c_finish_oacc_wait (loc, list, clauses);
12319 
12320   return stmt;
12321 }
12322 
12323 /* OpenMP 2.5:
12324    # pragma omp atomic new-line
12325      expression-stmt
12326 
12327    expression-stmt:
12328      x binop= expr | x++ | ++x | x-- | --x
12329    binop:
12330      +, *, -, /, &, ^, |, <<, >>
12331 
12332   where x is an lvalue expression with scalar type.
12333 
12334    OpenMP 3.1:
12335    # pragma omp atomic new-line
12336      update-stmt
12337 
12338    # pragma omp atomic read new-line
12339      read-stmt
12340 
12341    # pragma omp atomic write new-line
12342      write-stmt
12343 
12344    # pragma omp atomic update new-line
12345      update-stmt
12346 
12347    # pragma omp atomic capture new-line
12348      capture-stmt
12349 
12350    # pragma omp atomic capture new-line
12351      capture-block
12352 
12353    read-stmt:
12354      v = x
12355    write-stmt:
12356      x = expr
12357    update-stmt:
12358      expression-stmt | x = x binop expr
12359    capture-stmt:
12360      v = expression-stmt
12361    capture-block:
12362      { v = x; update-stmt; } | { update-stmt; v = x; }
12363 
12364    OpenMP 4.0:
12365    update-stmt:
12366      expression-stmt | x = x binop expr | x = expr binop x
12367    capture-stmt:
12368      v = update-stmt
12369    capture-block:
12370      { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12371 
12372   where x and v are lvalue expressions with scalar type.
12373 
12374   LOC is the location of the #pragma token.  */
12375 
12376 static void
12377 c_parser_omp_atomic (location_t loc, c_parser *parser)
12378 {
12379   tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
12380   tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
12381   tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
12382   enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
12383   struct c_expr expr;
12384   location_t eloc;
12385   bool structured_block = false;
12386   bool swapped = false;
12387   bool seq_cst = false;
12388   bool non_lvalue_p;
12389 
12390   if (c_parser_next_token_is (parser, CPP_NAME))
12391     {
12392       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12393       if (!strcmp (p, "seq_cst"))
12394 	{
12395 	  seq_cst = true;
12396 	  c_parser_consume_token (parser);
12397 	  if (c_parser_next_token_is (parser, CPP_COMMA)
12398 	      && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12399 	    c_parser_consume_token (parser);
12400 	}
12401     }
12402   if (c_parser_next_token_is (parser, CPP_NAME))
12403     {
12404       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12405 
12406       if (!strcmp (p, "read"))
12407 	code = OMP_ATOMIC_READ;
12408       else if (!strcmp (p, "write"))
12409 	code = NOP_EXPR;
12410       else if (!strcmp (p, "update"))
12411 	code = OMP_ATOMIC;
12412       else if (!strcmp (p, "capture"))
12413 	code = OMP_ATOMIC_CAPTURE_NEW;
12414       else
12415 	p = NULL;
12416       if (p)
12417 	c_parser_consume_token (parser);
12418     }
12419   if (!seq_cst)
12420     {
12421       if (c_parser_next_token_is (parser, CPP_COMMA)
12422 	  && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12423 	c_parser_consume_token (parser);
12424 
12425       if (c_parser_next_token_is (parser, CPP_NAME))
12426 	{
12427 	  const char *p
12428 	    = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12429 	  if (!strcmp (p, "seq_cst"))
12430 	    {
12431 	      seq_cst = true;
12432 	      c_parser_consume_token (parser);
12433 	    }
12434 	}
12435     }
12436   c_parser_skip_to_pragma_eol (parser);
12437 
12438   switch (code)
12439     {
12440     case OMP_ATOMIC_READ:
12441     case NOP_EXPR: /* atomic write */
12442       v = c_parser_cast_expression (parser, NULL).value;
12443       non_lvalue_p = !lvalue_p (v);
12444       v = c_fully_fold (v, false, NULL);
12445       if (v == error_mark_node)
12446 	goto saw_error;
12447       if (non_lvalue_p)
12448 	v = non_lvalue (v);
12449       loc = c_parser_peek_token (parser)->location;
12450       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12451 	goto saw_error;
12452       if (code == NOP_EXPR)
12453 	{
12454 	  lhs = c_parser_expression (parser).value;
12455 	  lhs = c_fully_fold (lhs, false, NULL);
12456 	  if (lhs == error_mark_node)
12457 	    goto saw_error;
12458 	}
12459       else
12460 	{
12461 	  lhs = c_parser_cast_expression (parser, NULL).value;
12462 	  non_lvalue_p = !lvalue_p (lhs);
12463 	  lhs = c_fully_fold (lhs, false, NULL);
12464 	  if (lhs == error_mark_node)
12465 	    goto saw_error;
12466 	  if (non_lvalue_p)
12467 	    lhs = non_lvalue (lhs);
12468 	}
12469       if (code == NOP_EXPR)
12470 	{
12471 	  /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12472 	     opcode.  */
12473 	  code = OMP_ATOMIC;
12474 	  rhs = lhs;
12475 	  lhs = v;
12476 	  v = NULL_TREE;
12477 	}
12478       goto done;
12479     case OMP_ATOMIC_CAPTURE_NEW:
12480       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
12481 	{
12482 	  c_parser_consume_token (parser);
12483 	  structured_block = true;
12484 	}
12485       else
12486 	{
12487 	  v = c_parser_cast_expression (parser, NULL).value;
12488 	  non_lvalue_p = !lvalue_p (v);
12489 	  v = c_fully_fold (v, false, NULL);
12490 	  if (v == error_mark_node)
12491 	    goto saw_error;
12492 	  if (non_lvalue_p)
12493 	    v = non_lvalue (v);
12494 	  if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12495 	    goto saw_error;
12496 	}
12497       break;
12498     default:
12499       break;
12500     }
12501 
12502   /* For structured_block case we don't know yet whether
12503      old or new x should be captured.  */
12504 restart:
12505   eloc = c_parser_peek_token (parser)->location;
12506   expr = c_parser_cast_expression (parser, NULL);
12507   lhs = expr.value;
12508   expr = default_function_array_conversion (eloc, expr);
12509   unfolded_lhs = expr.value;
12510   lhs = c_fully_fold (lhs, false, NULL);
12511   orig_lhs = lhs;
12512   switch (TREE_CODE (lhs))
12513     {
12514     case ERROR_MARK:
12515     saw_error:
12516       c_parser_skip_to_end_of_block_or_statement (parser);
12517       if (structured_block)
12518 	{
12519 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12520 	    c_parser_consume_token (parser);
12521 	  else if (code == OMP_ATOMIC_CAPTURE_NEW)
12522 	    {
12523 	      c_parser_skip_to_end_of_block_or_statement (parser);
12524 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12525 		c_parser_consume_token (parser);
12526 	    }
12527 	}
12528       return;
12529 
12530     case POSTINCREMENT_EXPR:
12531       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12532 	code = OMP_ATOMIC_CAPTURE_OLD;
12533       /* FALLTHROUGH */
12534     case PREINCREMENT_EXPR:
12535       lhs = TREE_OPERAND (lhs, 0);
12536       unfolded_lhs = NULL_TREE;
12537       opcode = PLUS_EXPR;
12538       rhs = integer_one_node;
12539       break;
12540 
12541     case POSTDECREMENT_EXPR:
12542       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12543 	code = OMP_ATOMIC_CAPTURE_OLD;
12544       /* FALLTHROUGH */
12545     case PREDECREMENT_EXPR:
12546       lhs = TREE_OPERAND (lhs, 0);
12547       unfolded_lhs = NULL_TREE;
12548       opcode = MINUS_EXPR;
12549       rhs = integer_one_node;
12550       break;
12551 
12552     case COMPOUND_EXPR:
12553       if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
12554 	  && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
12555 	  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
12556 	  && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
12557 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12558 					      (TREE_OPERAND (lhs, 1), 0), 0)))
12559 	     == BOOLEAN_TYPE)
12560 	/* Undo effects of boolean_increment for post {in,de}crement.  */
12561 	lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
12562       /* FALLTHRU */
12563     case MODIFY_EXPR:
12564       if (TREE_CODE (lhs) == MODIFY_EXPR
12565 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
12566 	{
12567 	  /* Undo effects of boolean_increment.  */
12568 	  if (integer_onep (TREE_OPERAND (lhs, 1)))
12569 	    {
12570 	      /* This is pre or post increment.  */
12571 	      rhs = TREE_OPERAND (lhs, 1);
12572 	      lhs = TREE_OPERAND (lhs, 0);
12573 	      unfolded_lhs = NULL_TREE;
12574 	      opcode = NOP_EXPR;
12575 	      if (code == OMP_ATOMIC_CAPTURE_NEW
12576 		  && !structured_block
12577 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12578 		code = OMP_ATOMIC_CAPTURE_OLD;
12579 	      break;
12580 	    }
12581 	  if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
12582 	      && TREE_OPERAND (lhs, 0)
12583 		 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
12584 	    {
12585 	      /* This is pre or post decrement.  */
12586 	      rhs = TREE_OPERAND (lhs, 1);
12587 	      lhs = TREE_OPERAND (lhs, 0);
12588 	      unfolded_lhs = NULL_TREE;
12589 	      opcode = NOP_EXPR;
12590 	      if (code == OMP_ATOMIC_CAPTURE_NEW
12591 		  && !structured_block
12592 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12593 		code = OMP_ATOMIC_CAPTURE_OLD;
12594 	      break;
12595 	    }
12596 	}
12597       /* FALLTHRU */
12598     default:
12599       if (!lvalue_p (unfolded_lhs))
12600 	lhs = non_lvalue (lhs);
12601       switch (c_parser_peek_token (parser)->type)
12602 	{
12603 	case CPP_MULT_EQ:
12604 	  opcode = MULT_EXPR;
12605 	  break;
12606 	case CPP_DIV_EQ:
12607 	  opcode = TRUNC_DIV_EXPR;
12608 	  break;
12609 	case CPP_PLUS_EQ:
12610 	  opcode = PLUS_EXPR;
12611 	  break;
12612 	case CPP_MINUS_EQ:
12613 	  opcode = MINUS_EXPR;
12614 	  break;
12615 	case CPP_LSHIFT_EQ:
12616 	  opcode = LSHIFT_EXPR;
12617 	  break;
12618 	case CPP_RSHIFT_EQ:
12619 	  opcode = RSHIFT_EXPR;
12620 	  break;
12621 	case CPP_AND_EQ:
12622 	  opcode = BIT_AND_EXPR;
12623 	  break;
12624 	case CPP_OR_EQ:
12625 	  opcode = BIT_IOR_EXPR;
12626 	  break;
12627 	case CPP_XOR_EQ:
12628 	  opcode = BIT_XOR_EXPR;
12629 	  break;
12630 	case CPP_EQ:
12631 	  c_parser_consume_token (parser);
12632 	  eloc = c_parser_peek_token (parser)->location;
12633 	  expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
12634 	  rhs1 = expr.value;
12635 	  switch (TREE_CODE (rhs1))
12636 	    {
12637 	    case MULT_EXPR:
12638 	    case TRUNC_DIV_EXPR:
12639 	    case RDIV_EXPR:
12640 	    case PLUS_EXPR:
12641 	    case MINUS_EXPR:
12642 	    case LSHIFT_EXPR:
12643 	    case RSHIFT_EXPR:
12644 	    case BIT_AND_EXPR:
12645 	    case BIT_IOR_EXPR:
12646 	    case BIT_XOR_EXPR:
12647 	      if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
12648 		{
12649 		  opcode = TREE_CODE (rhs1);
12650 		  rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12651 		  rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12652 		  goto stmt_done;
12653 		}
12654 	      if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
12655 		{
12656 		  opcode = TREE_CODE (rhs1);
12657 		  rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12658 		  rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12659 		  swapped = !commutative_tree_code (opcode);
12660 		  goto stmt_done;
12661 		}
12662 	      break;
12663 	    case ERROR_MARK:
12664 	      goto saw_error;
12665 	    default:
12666 	      break;
12667 	    }
12668 	  if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
12669 	    {
12670 	      if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12671 		{
12672 		  code = OMP_ATOMIC_CAPTURE_OLD;
12673 		  v = lhs;
12674 		  lhs = NULL_TREE;
12675 		  expr = default_function_array_read_conversion (eloc, expr);
12676 		  unfolded_lhs1 = expr.value;
12677 		  lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
12678 		  rhs1 = NULL_TREE;
12679 		  c_parser_consume_token (parser);
12680 		  goto restart;
12681 		}
12682 	      if (structured_block)
12683 		{
12684 		  opcode = NOP_EXPR;
12685 		  expr = default_function_array_read_conversion (eloc, expr);
12686 		  rhs = c_fully_fold (expr.value, false, NULL);
12687 		  rhs1 = NULL_TREE;
12688 		  goto stmt_done;
12689 		}
12690 	    }
12691 	  c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
12692 	  goto saw_error;
12693 	default:
12694 	  c_parser_error (parser,
12695 			  "invalid operator for %<#pragma omp atomic%>");
12696 	  goto saw_error;
12697 	}
12698 
12699       /* Arrange to pass the location of the assignment operator to
12700 	 c_finish_omp_atomic.  */
12701       loc = c_parser_peek_token (parser)->location;
12702       c_parser_consume_token (parser);
12703       eloc = c_parser_peek_token (parser)->location;
12704       expr = c_parser_expression (parser);
12705       expr = default_function_array_read_conversion (eloc, expr);
12706       rhs = expr.value;
12707       rhs = c_fully_fold (rhs, false, NULL);
12708       break;
12709     }
12710 stmt_done:
12711   if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12712     {
12713       if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
12714 	goto saw_error;
12715       v = c_parser_cast_expression (parser, NULL).value;
12716       non_lvalue_p = !lvalue_p (v);
12717       v = c_fully_fold (v, false, NULL);
12718       if (v == error_mark_node)
12719 	goto saw_error;
12720       if (non_lvalue_p)
12721 	v = non_lvalue (v);
12722       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12723 	goto saw_error;
12724       eloc = c_parser_peek_token (parser)->location;
12725       expr = c_parser_cast_expression (parser, NULL);
12726       lhs1 = expr.value;
12727       expr = default_function_array_read_conversion (eloc, expr);
12728       unfolded_lhs1 = expr.value;
12729       lhs1 = c_fully_fold (lhs1, false, NULL);
12730       if (lhs1 == error_mark_node)
12731 	goto saw_error;
12732       if (!lvalue_p (unfolded_lhs1))
12733 	lhs1 = non_lvalue (lhs1);
12734     }
12735   if (structured_block)
12736     {
12737       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12738       c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
12739     }
12740 done:
12741   if (unfolded_lhs && unfolded_lhs1
12742       && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
12743     {
12744       error ("%<#pragma omp atomic capture%> uses two different "
12745 	     "expressions for memory");
12746       stmt = error_mark_node;
12747     }
12748   else
12749     stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
12750 				swapped, seq_cst);
12751   if (stmt != error_mark_node)
12752     add_stmt (stmt);
12753 
12754   if (!structured_block)
12755     c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12756 }
12757 
12758 
12759 /* OpenMP 2.5:
12760    # pragma omp barrier new-line
12761 */
12762 
12763 static void
12764 c_parser_omp_barrier (c_parser *parser)
12765 {
12766   location_t loc = c_parser_peek_token (parser)->location;
12767   c_parser_consume_pragma (parser);
12768   c_parser_skip_to_pragma_eol (parser);
12769 
12770   c_finish_omp_barrier (loc);
12771 }
12772 
12773 /* OpenMP 2.5:
12774    # pragma omp critical [(name)] new-line
12775      structured-block
12776 
12777   LOC is the location of the #pragma itself.  */
12778 
12779 static tree
12780 c_parser_omp_critical (location_t loc, c_parser *parser)
12781 {
12782   tree stmt, name = NULL;
12783 
12784   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12785     {
12786       c_parser_consume_token (parser);
12787       if (c_parser_next_token_is (parser, CPP_NAME))
12788 	{
12789 	  name = c_parser_peek_token (parser)->value;
12790 	  c_parser_consume_token (parser);
12791 	  c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12792 	}
12793       else
12794 	c_parser_error (parser, "expected identifier");
12795     }
12796   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12797     c_parser_error (parser, "expected %<(%> or end of line");
12798   c_parser_skip_to_pragma_eol (parser);
12799 
12800   stmt = c_parser_omp_structured_block (parser);
12801   return c_finish_omp_critical (loc, stmt, name);
12802 }
12803 
12804 /* OpenMP 2.5:
12805    # pragma omp flush flush-vars[opt] new-line
12806 
12807    flush-vars:
12808      ( variable-list ) */
12809 
12810 static void
12811 c_parser_omp_flush (c_parser *parser)
12812 {
12813   location_t loc = c_parser_peek_token (parser)->location;
12814   c_parser_consume_pragma (parser);
12815   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12816     c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
12817   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12818     c_parser_error (parser, "expected %<(%> or end of line");
12819   c_parser_skip_to_pragma_eol (parser);
12820 
12821   c_finish_omp_flush (loc);
12822 }
12823 
12824 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12825    The real trick here is to determine the loop control variable early
12826    so that we can push a new decl if necessary to make it private.
12827    LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12828    respectively.  */
12829 
12830 static tree
12831 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
12832 		       tree clauses, tree *cclauses)
12833 {
12834   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
12835   tree declv, condv, incrv, initv, ret = NULL_TREE;
12836   tree pre_body = NULL_TREE, this_pre_body;
12837   bool fail = false, open_brace_parsed = false;
12838   int i, collapse = 1, nbraces = 0;
12839   location_t for_loc;
12840   vec<tree, va_gc> *for_block = make_tree_vector ();
12841 
12842   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
12843     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
12844       collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
12845 
12846   gcc_assert (collapse >= 1);
12847 
12848   declv = make_tree_vec (collapse);
12849   initv = make_tree_vec (collapse);
12850   condv = make_tree_vec (collapse);
12851   incrv = make_tree_vec (collapse);
12852 
12853   if (code != CILK_FOR
12854       && !c_parser_next_token_is_keyword (parser, RID_FOR))
12855     {
12856       c_parser_error (parser, "for statement expected");
12857       return NULL;
12858     }
12859   if (code == CILK_FOR
12860       && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR))
12861     {
12862       c_parser_error (parser, "_Cilk_for statement expected");
12863       return NULL;
12864     }
12865   for_loc = c_parser_peek_token (parser)->location;
12866   c_parser_consume_token (parser);
12867 
12868   for (i = 0; i < collapse; i++)
12869     {
12870       int bracecount = 0;
12871 
12872       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12873 	goto pop_scopes;
12874 
12875       /* Parse the initialization declaration or expression.  */
12876       if (c_parser_next_tokens_start_declaration (parser))
12877 	{
12878 	  if (i > 0)
12879 	    vec_safe_push (for_block, c_begin_compound_stmt (true));
12880 	  this_pre_body = push_stmt_list ();
12881 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
12882 					 NULL, vNULL);
12883 	  if (this_pre_body)
12884 	    {
12885 	      this_pre_body = pop_stmt_list (this_pre_body);
12886 	      if (pre_body)
12887 		{
12888 		  tree t = pre_body;
12889 		  pre_body = push_stmt_list ();
12890 		  add_stmt (t);
12891 		  add_stmt (this_pre_body);
12892 		  pre_body = pop_stmt_list (pre_body);
12893 		}
12894 	      else
12895 		pre_body = this_pre_body;
12896 	    }
12897 	  decl = check_for_loop_decls (for_loc, flag_isoc99);
12898 	  if (decl == NULL)
12899 	    goto error_init;
12900 	  if (DECL_INITIAL (decl) == error_mark_node)
12901 	    decl = error_mark_node;
12902 	  init = decl;
12903 	}
12904       else if (c_parser_next_token_is (parser, CPP_NAME)
12905 	       && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
12906 	{
12907 	  struct c_expr decl_exp;
12908 	  struct c_expr init_exp;
12909 	  location_t init_loc;
12910 
12911 	  decl_exp = c_parser_postfix_expression (parser);
12912 	  decl = decl_exp.value;
12913 
12914 	  c_parser_require (parser, CPP_EQ, "expected %<=%>");
12915 
12916 	  init_loc = c_parser_peek_token (parser)->location;
12917 	  init_exp = c_parser_expr_no_commas (parser, NULL);
12918 	  init_exp = default_function_array_read_conversion (init_loc,
12919 							     init_exp);
12920 	  init = build_modify_expr (init_loc, decl, decl_exp.original_type,
12921 				    NOP_EXPR, init_loc, init_exp.value,
12922 				    init_exp.original_type);
12923 	  init = c_process_expr_stmt (init_loc, init);
12924 
12925 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12926 	}
12927       else
12928 	{
12929 	error_init:
12930 	  c_parser_error (parser,
12931 			  "expected iteration declaration or initialization");
12932 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12933 				     "expected %<)%>");
12934 	  fail = true;
12935 	  goto parse_next;
12936 	}
12937 
12938       /* Parse the loop condition.  */
12939       cond = NULL_TREE;
12940       if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
12941 	{
12942 	  location_t cond_loc = c_parser_peek_token (parser)->location;
12943 	  struct c_expr cond_expr
12944 	    = c_parser_binary_expression (parser, NULL, NULL_TREE);
12945 
12946 	  cond = cond_expr.value;
12947 	  cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
12948 	  cond = c_fully_fold (cond, false, NULL);
12949 	  switch (cond_expr.original_code)
12950 	    {
12951 	    case GT_EXPR:
12952 	    case GE_EXPR:
12953 	    case LT_EXPR:
12954 	    case LE_EXPR:
12955 	      break;
12956 	    case NE_EXPR:
12957 	      if (code == CILK_SIMD || code == CILK_FOR)
12958 		break;
12959 	      /* FALLTHRU.  */
12960 	    default:
12961 	      /* Can't be cond = error_mark_node, because we want to preserve
12962 		 the location until c_finish_omp_for.  */
12963 	      cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
12964 	      break;
12965 	    }
12966 	  protected_set_expr_location (cond, cond_loc);
12967 	}
12968       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12969 
12970       /* Parse the increment expression.  */
12971       incr = NULL_TREE;
12972       if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
12973 	{
12974 	  location_t incr_loc = c_parser_peek_token (parser)->location;
12975 
12976 	  incr = c_process_expr_stmt (incr_loc,
12977 				      c_parser_expression (parser).value);
12978 	}
12979       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12980 
12981       if (decl == NULL || decl == error_mark_node || init == error_mark_node)
12982 	fail = true;
12983       else
12984 	{
12985 	  TREE_VEC_ELT (declv, i) = decl;
12986 	  TREE_VEC_ELT (initv, i) = init;
12987 	  TREE_VEC_ELT (condv, i) = cond;
12988 	  TREE_VEC_ELT (incrv, i) = incr;
12989 	}
12990 
12991     parse_next:
12992       if (i == collapse - 1)
12993 	break;
12994 
12995       /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12996 	 in between the collapsed for loops to be still considered perfectly
12997 	 nested.  Hopefully the final version clarifies this.
12998 	 For now handle (multiple) {'s and empty statements.  */
12999       do
13000 	{
13001 	  if (c_parser_next_token_is_keyword (parser, RID_FOR))
13002 	    {
13003 	      c_parser_consume_token (parser);
13004 	      break;
13005 	    }
13006 	  else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
13007 	    {
13008 	      c_parser_consume_token (parser);
13009 	      bracecount++;
13010 	    }
13011 	  else if (bracecount
13012 		   && c_parser_next_token_is (parser, CPP_SEMICOLON))
13013 	    c_parser_consume_token (parser);
13014 	  else
13015 	    {
13016 	      c_parser_error (parser, "not enough perfectly nested loops");
13017 	      if (bracecount)
13018 		{
13019 		  open_brace_parsed = true;
13020 		  bracecount--;
13021 		}
13022 	      fail = true;
13023 	      collapse = 0;
13024 	      break;
13025 	    }
13026 	}
13027       while (1);
13028 
13029       nbraces += bracecount;
13030     }
13031 
13032   save_break = c_break_label;
13033   if (code == CILK_SIMD)
13034     c_break_label = build_int_cst (size_type_node, 2);
13035   else
13036     c_break_label = size_one_node;
13037   save_cont = c_cont_label;
13038   c_cont_label = NULL_TREE;
13039   body = push_stmt_list ();
13040 
13041   if (open_brace_parsed)
13042     {
13043       location_t here = c_parser_peek_token (parser)->location;
13044       stmt = c_begin_compound_stmt (true);
13045       c_parser_compound_statement_nostart (parser);
13046       add_stmt (c_end_compound_stmt (here, stmt, true));
13047     }
13048   else
13049     add_stmt (c_parser_c99_block_statement (parser));
13050   if (c_cont_label)
13051     {
13052       tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
13053       SET_EXPR_LOCATION (t, loc);
13054       add_stmt (t);
13055     }
13056 
13057   body = pop_stmt_list (body);
13058   c_break_label = save_break;
13059   c_cont_label = save_cont;
13060 
13061   while (nbraces)
13062     {
13063       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13064 	{
13065 	  c_parser_consume_token (parser);
13066 	  nbraces--;
13067 	}
13068       else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
13069 	c_parser_consume_token (parser);
13070       else
13071 	{
13072 	  c_parser_error (parser, "collapsed loops not perfectly nested");
13073 	  while (nbraces)
13074 	    {
13075 	      location_t here = c_parser_peek_token (parser)->location;
13076 	      stmt = c_begin_compound_stmt (true);
13077 	      add_stmt (body);
13078 	      c_parser_compound_statement_nostart (parser);
13079 	      body = c_end_compound_stmt (here, stmt, true);
13080 	      nbraces--;
13081 	    }
13082 	  goto pop_scopes;
13083 	}
13084     }
13085 
13086   /* Only bother calling c_finish_omp_for if we haven't already generated
13087      an error from the initialization parsing.  */
13088   if (!fail)
13089     {
13090       stmt = c_finish_omp_for (loc, code, declv, initv, condv,
13091 			       incrv, body, pre_body);
13092       if (stmt)
13093 	{
13094 	  if (cclauses != NULL
13095 	      && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
13096 	    {
13097 	      tree *c;
13098 	      for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
13099 		if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
13100 		    && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
13101 		  c = &OMP_CLAUSE_CHAIN (*c);
13102 		else
13103 		  {
13104 		    for (i = 0; i < collapse; i++)
13105 		      if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
13106 			break;
13107 		    if (i == collapse)
13108 		      c = &OMP_CLAUSE_CHAIN (*c);
13109 		    else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
13110 		      {
13111 			error_at (loc,
13112 				  "iteration variable %qD should not be firstprivate",
13113 				  OMP_CLAUSE_DECL (*c));
13114 			*c = OMP_CLAUSE_CHAIN (*c);
13115 		      }
13116 		    else
13117 		      {
13118 			/* Move lastprivate (decl) clause to OMP_FOR_CLAUSES.  */
13119 			tree l = *c;
13120 			*c = OMP_CLAUSE_CHAIN (*c);
13121 			if (code == OMP_SIMD)
13122 			  {
13123 			    OMP_CLAUSE_CHAIN (l)
13124 			      = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13125 			    cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
13126 			  }
13127 			else
13128 			  {
13129 			    OMP_CLAUSE_CHAIN (l) = clauses;
13130 			    clauses = l;
13131 			  }
13132 		      }
13133 		  }
13134 	    }
13135 	  OMP_FOR_CLAUSES (stmt) = clauses;
13136 	}
13137       ret = stmt;
13138     }
13139 pop_scopes:
13140   while (!for_block->is_empty ())
13141     {
13142       /* FIXME diagnostics: LOC below should be the actual location of
13143 	 this particular for block.  We need to build a list of
13144 	 locations to go along with FOR_BLOCK.  */
13145       stmt = c_end_compound_stmt (loc, for_block->pop (), true);
13146       add_stmt (stmt);
13147     }
13148   release_tree_vector (for_block);
13149   return ret;
13150 }
13151 
13152 /* Helper function for OpenMP parsing, split clauses and call
13153    finish_omp_clauses on each of the set of clauses afterwards.  */
13154 
13155 static void
13156 omp_split_clauses (location_t loc, enum tree_code code,
13157 		   omp_clause_mask mask, tree clauses, tree *cclauses)
13158 {
13159   int i;
13160   c_omp_split_clauses (loc, code, mask, clauses, cclauses);
13161   for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
13162     if (cclauses[i])
13163       cclauses[i] = c_finish_omp_clauses (cclauses[i]);
13164 }
13165 
13166 /* OpenMP 4.0:
13167    #pragma omp simd simd-clause[optseq] new-line
13168      for-loop
13169 
13170    LOC is the location of the #pragma token.
13171 */
13172 
13173 #define OMP_SIMD_CLAUSE_MASK					\
13174 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN)	\
13175 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
13176 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)	\
13177 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13178 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
13179 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
13180 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13181 
13182 static tree
13183 c_parser_omp_simd (location_t loc, c_parser *parser,
13184 		   char *p_name, omp_clause_mask mask, tree *cclauses)
13185 {
13186   tree block, clauses, ret;
13187 
13188   strcat (p_name, " simd");
13189   mask |= OMP_SIMD_CLAUSE_MASK;
13190   mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
13191 
13192   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13193   if (cclauses)
13194     {
13195       omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
13196       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
13197     }
13198 
13199   block = c_begin_compound_stmt (true);
13200   ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses);
13201   block = c_end_compound_stmt (loc, block, true);
13202   add_stmt (block);
13203 
13204   return ret;
13205 }
13206 
13207 /* OpenMP 2.5:
13208    #pragma omp for for-clause[optseq] new-line
13209      for-loop
13210 
13211    OpenMP 4.0:
13212    #pragma omp for simd for-simd-clause[optseq] new-line
13213      for-loop
13214 
13215    LOC is the location of the #pragma token.
13216 */
13217 
13218 #define OMP_FOR_CLAUSE_MASK					\
13219 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13220 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
13221 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
13222 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
13223 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED)	\
13224 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)	\
13225 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)	\
13226 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13227 
13228 static tree
13229 c_parser_omp_for (location_t loc, c_parser *parser,
13230 		  char *p_name, omp_clause_mask mask, tree *cclauses)
13231 {
13232   tree block, clauses, ret;
13233 
13234   strcat (p_name, " for");
13235   mask |= OMP_FOR_CLAUSE_MASK;
13236   if (cclauses)
13237     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13238 
13239   if (c_parser_next_token_is (parser, CPP_NAME))
13240     {
13241       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13242 
13243       if (strcmp (p, "simd") == 0)
13244 	{
13245 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13246 	  if (cclauses == NULL)
13247 	    cclauses = cclauses_buf;
13248 
13249 	  c_parser_consume_token (parser);
13250 	  if (!flag_openmp)  /* flag_openmp_simd  */
13251 	    return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13252 	  block = c_begin_compound_stmt (true);
13253 	  ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13254 	  block = c_end_compound_stmt (loc, block, true);
13255 	  if (ret == NULL_TREE)
13256 	    return ret;
13257 	  ret = make_node (OMP_FOR);
13258 	  TREE_TYPE (ret) = void_type_node;
13259 	  OMP_FOR_BODY (ret) = block;
13260 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13261 	  SET_EXPR_LOCATION (ret, loc);
13262 	  add_stmt (ret);
13263 	  return ret;
13264 	}
13265     }
13266   if (!flag_openmp)  /* flag_openmp_simd  */
13267     {
13268       c_parser_skip_to_pragma_eol (parser, false);
13269       return NULL_TREE;
13270     }
13271 
13272   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13273   if (cclauses)
13274     {
13275       omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
13276       clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13277     }
13278 
13279   block = c_begin_compound_stmt (true);
13280   ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses);
13281   block = c_end_compound_stmt (loc, block, true);
13282   add_stmt (block);
13283 
13284   return ret;
13285 }
13286 
13287 /* OpenMP 2.5:
13288    # pragma omp master new-line
13289      structured-block
13290 
13291    LOC is the location of the #pragma token.
13292 */
13293 
13294 static tree
13295 c_parser_omp_master (location_t loc, c_parser *parser)
13296 {
13297   c_parser_skip_to_pragma_eol (parser);
13298   return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
13299 }
13300 
13301 /* OpenMP 2.5:
13302    # pragma omp ordered new-line
13303      structured-block
13304 
13305    LOC is the location of the #pragma itself.
13306 */
13307 
13308 static tree
13309 c_parser_omp_ordered (location_t loc, c_parser *parser)
13310 {
13311   c_parser_skip_to_pragma_eol (parser);
13312   return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
13313 }
13314 
13315 /* OpenMP 2.5:
13316 
13317    section-scope:
13318      { section-sequence }
13319 
13320    section-sequence:
13321      section-directive[opt] structured-block
13322      section-sequence section-directive structured-block
13323 
13324     SECTIONS_LOC is the location of the #pragma omp sections.  */
13325 
13326 static tree
13327 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
13328 {
13329   tree stmt, substmt;
13330   bool error_suppress = false;
13331   location_t loc;
13332 
13333   loc = c_parser_peek_token (parser)->location;
13334   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
13335     {
13336       /* Avoid skipping until the end of the block.  */
13337       parser->error = false;
13338       return NULL_TREE;
13339     }
13340 
13341   stmt = push_stmt_list ();
13342 
13343   if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
13344     {
13345       substmt = c_parser_omp_structured_block (parser);
13346       substmt = build1 (OMP_SECTION, void_type_node, substmt);
13347       SET_EXPR_LOCATION (substmt, loc);
13348       add_stmt (substmt);
13349     }
13350 
13351   while (1)
13352     {
13353       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13354 	break;
13355       if (c_parser_next_token_is (parser, CPP_EOF))
13356 	break;
13357 
13358       loc = c_parser_peek_token (parser)->location;
13359       if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
13360 	{
13361 	  c_parser_consume_pragma (parser);
13362 	  c_parser_skip_to_pragma_eol (parser);
13363 	  error_suppress = false;
13364 	}
13365       else if (!error_suppress)
13366 	{
13367 	  error_at (loc, "expected %<#pragma omp section%> or %<}%>");
13368 	  error_suppress = true;
13369 	}
13370 
13371       substmt = c_parser_omp_structured_block (parser);
13372       substmt = build1 (OMP_SECTION, void_type_node, substmt);
13373       SET_EXPR_LOCATION (substmt, loc);
13374       add_stmt (substmt);
13375     }
13376   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
13377 			     "expected %<#pragma omp section%> or %<}%>");
13378 
13379   substmt = pop_stmt_list (stmt);
13380 
13381   stmt = make_node (OMP_SECTIONS);
13382   SET_EXPR_LOCATION (stmt, sections_loc);
13383   TREE_TYPE (stmt) = void_type_node;
13384   OMP_SECTIONS_BODY (stmt) = substmt;
13385 
13386   return add_stmt (stmt);
13387 }
13388 
13389 /* OpenMP 2.5:
13390    # pragma omp sections sections-clause[optseq] newline
13391      sections-scope
13392 
13393    LOC is the location of the #pragma token.
13394 */
13395 
13396 #define OMP_SECTIONS_CLAUSE_MASK				\
13397 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13398 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
13399 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
13400 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
13401 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13402 
13403 static tree
13404 c_parser_omp_sections (location_t loc, c_parser *parser,
13405 		       char *p_name, omp_clause_mask mask, tree *cclauses)
13406 {
13407   tree block, clauses, ret;
13408 
13409   strcat (p_name, " sections");
13410   mask |= OMP_SECTIONS_CLAUSE_MASK;
13411   if (cclauses)
13412     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13413 
13414   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13415   if (cclauses)
13416     {
13417       omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
13418       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
13419     }
13420 
13421   block = c_begin_compound_stmt (true);
13422   ret = c_parser_omp_sections_scope (loc, parser);
13423   if (ret)
13424     OMP_SECTIONS_CLAUSES (ret) = clauses;
13425   block = c_end_compound_stmt (loc, block, true);
13426   add_stmt (block);
13427 
13428   return ret;
13429 }
13430 
13431 /* OpenMP 2.5:
13432    # pragma omp parallel parallel-clause[optseq] new-line
13433      structured-block
13434    # pragma omp parallel for parallel-for-clause[optseq] new-line
13435      structured-block
13436    # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13437      structured-block
13438 
13439    OpenMP 4.0:
13440    # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13441      structured-block
13442 
13443    LOC is the location of the #pragma token.
13444 */
13445 
13446 #define OMP_PARALLEL_CLAUSE_MASK				\
13447 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
13448 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13449 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
13450 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
13451 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
13452 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN)	\
13453 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
13454 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)	\
13455 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13456 
13457 static tree
13458 c_parser_omp_parallel (location_t loc, c_parser *parser,
13459 		       char *p_name, omp_clause_mask mask, tree *cclauses)
13460 {
13461   tree stmt, clauses, block;
13462 
13463   strcat (p_name, " parallel");
13464   mask |= OMP_PARALLEL_CLAUSE_MASK;
13465 
13466   if (c_parser_next_token_is_keyword (parser, RID_FOR))
13467     {
13468       tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13469       if (cclauses == NULL)
13470 	cclauses = cclauses_buf;
13471 
13472       c_parser_consume_token (parser);
13473       if (!flag_openmp)  /* flag_openmp_simd  */
13474 	return c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13475       block = c_begin_omp_parallel ();
13476       tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13477       stmt
13478 	= c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
13479 				 block);
13480       if (ret == NULL_TREE)
13481 	return ret;
13482       OMP_PARALLEL_COMBINED (stmt) = 1;
13483       return stmt;
13484     }
13485   else if (cclauses)
13486     {
13487       error_at (loc, "expected %<for%> after %qs", p_name);
13488       c_parser_skip_to_pragma_eol (parser);
13489       return NULL_TREE;
13490     }
13491   else if (!flag_openmp)  /* flag_openmp_simd  */
13492     {
13493       c_parser_skip_to_pragma_eol (parser, false);
13494       return NULL_TREE;
13495     }
13496   else if (c_parser_next_token_is (parser, CPP_NAME))
13497     {
13498       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13499       if (strcmp (p, "sections") == 0)
13500 	{
13501 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13502 	  if (cclauses == NULL)
13503 	    cclauses = cclauses_buf;
13504 
13505 	  c_parser_consume_token (parser);
13506 	  block = c_begin_omp_parallel ();
13507 	  c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
13508 	  stmt = c_finish_omp_parallel (loc,
13509 					cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
13510 					block);
13511 	  OMP_PARALLEL_COMBINED (stmt) = 1;
13512 	  return stmt;
13513 	}
13514     }
13515 
13516   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13517 
13518   block = c_begin_omp_parallel ();
13519   c_parser_statement (parser);
13520   stmt = c_finish_omp_parallel (loc, clauses, block);
13521 
13522   return stmt;
13523 }
13524 
13525 /* OpenMP 2.5:
13526    # pragma omp single single-clause[optseq] new-line
13527      structured-block
13528 
13529    LOC is the location of the #pragma.
13530 */
13531 
13532 #define OMP_SINGLE_CLAUSE_MASK					\
13533 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13534 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
13535 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE)	\
13536 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13537 
13538 static tree
13539 c_parser_omp_single (location_t loc, c_parser *parser)
13540 {
13541   tree stmt = make_node (OMP_SINGLE);
13542   SET_EXPR_LOCATION (stmt, loc);
13543   TREE_TYPE (stmt) = void_type_node;
13544 
13545   OMP_SINGLE_CLAUSES (stmt)
13546     = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
13547 				"#pragma omp single");
13548   OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
13549 
13550   return add_stmt (stmt);
13551 }
13552 
13553 /* OpenMP 3.0:
13554    # pragma omp task task-clause[optseq] new-line
13555 
13556    LOC is the location of the #pragma.
13557 */
13558 
13559 #define OMP_TASK_CLAUSE_MASK					\
13560 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
13561 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED)	\
13562 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
13563 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13564 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
13565 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
13566 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
13567 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
13568 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13569 
13570 static tree
13571 c_parser_omp_task (location_t loc, c_parser *parser)
13572 {
13573   tree clauses, block;
13574 
13575   clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
13576 				      "#pragma omp task");
13577 
13578   block = c_begin_omp_task ();
13579   c_parser_statement (parser);
13580   return c_finish_omp_task (loc, clauses, block);
13581 }
13582 
13583 /* OpenMP 3.0:
13584    # pragma omp taskwait new-line
13585 */
13586 
13587 static void
13588 c_parser_omp_taskwait (c_parser *parser)
13589 {
13590   location_t loc = c_parser_peek_token (parser)->location;
13591   c_parser_consume_pragma (parser);
13592   c_parser_skip_to_pragma_eol (parser);
13593 
13594   c_finish_omp_taskwait (loc);
13595 }
13596 
13597 /* OpenMP 3.1:
13598    # pragma omp taskyield new-line
13599 */
13600 
13601 static void
13602 c_parser_omp_taskyield (c_parser *parser)
13603 {
13604   location_t loc = c_parser_peek_token (parser)->location;
13605   c_parser_consume_pragma (parser);
13606   c_parser_skip_to_pragma_eol (parser);
13607 
13608   c_finish_omp_taskyield (loc);
13609 }
13610 
13611 /* OpenMP 4.0:
13612    # pragma omp taskgroup new-line
13613 */
13614 
13615 static tree
13616 c_parser_omp_taskgroup (c_parser *parser)
13617 {
13618   location_t loc = c_parser_peek_token (parser)->location;
13619   c_parser_skip_to_pragma_eol (parser);
13620   return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser));
13621 }
13622 
13623 /* OpenMP 4.0:
13624    # pragma omp cancel cancel-clause[optseq] new-line
13625 
13626    LOC is the location of the #pragma.
13627 */
13628 
13629 #define OMP_CANCEL_CLAUSE_MASK					\
13630 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)	\
13631 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)		\
13632 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
13633 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)	\
13634 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13635 
13636 static void
13637 c_parser_omp_cancel (c_parser *parser)
13638 {
13639   location_t loc = c_parser_peek_token (parser)->location;
13640 
13641   c_parser_consume_pragma (parser);
13642   tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
13643 					   "#pragma omp cancel");
13644 
13645   c_finish_omp_cancel (loc, clauses);
13646 }
13647 
13648 /* OpenMP 4.0:
13649    # pragma omp cancellation point cancelpt-clause[optseq] new-line
13650 
13651    LOC is the location of the #pragma.
13652 */
13653 
13654 #define OMP_CANCELLATION_POINT_CLAUSE_MASK			\
13655 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)	\
13656 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)		\
13657 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
13658 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13659 
13660 static void
13661 c_parser_omp_cancellation_point (c_parser *parser)
13662 {
13663   location_t loc = c_parser_peek_token (parser)->location;
13664   tree clauses;
13665   bool point_seen = false;
13666 
13667   c_parser_consume_pragma (parser);
13668   if (c_parser_next_token_is (parser, CPP_NAME))
13669     {
13670       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13671       if (strcmp (p, "point") == 0)
13672 	{
13673 	  c_parser_consume_token (parser);
13674 	  point_seen = true;
13675 	}
13676     }
13677   if (!point_seen)
13678     {
13679       c_parser_error (parser, "expected %<point%>");
13680       c_parser_skip_to_pragma_eol (parser);
13681       return;
13682     }
13683 
13684   clauses
13685     = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
13686 				"#pragma omp cancellation point");
13687 
13688   c_finish_omp_cancellation_point (loc, clauses);
13689 }
13690 
13691 /* OpenMP 4.0:
13692    #pragma omp distribute distribute-clause[optseq] new-line
13693      for-loop  */
13694 
13695 #define OMP_DISTRIBUTE_CLAUSE_MASK				\
13696 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13697 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
13698 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13699 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13700 
13701 static tree
13702 c_parser_omp_distribute (location_t loc, c_parser *parser,
13703 			 char *p_name, omp_clause_mask mask, tree *cclauses)
13704 {
13705   tree clauses, block, ret;
13706 
13707   strcat (p_name, " distribute");
13708   mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
13709 
13710   if (c_parser_next_token_is (parser, CPP_NAME))
13711     {
13712       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13713       bool simd = false;
13714       bool parallel = false;
13715 
13716       if (strcmp (p, "simd") == 0)
13717 	simd = true;
13718       else
13719 	parallel = strcmp (p, "parallel") == 0;
13720       if (parallel || simd)
13721 	{
13722 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13723 	  if (cclauses == NULL)
13724 	    cclauses = cclauses_buf;
13725 	  c_parser_consume_token (parser);
13726 	  if (!flag_openmp)  /* flag_openmp_simd  */
13727 	    {
13728 	      if (simd)
13729 		return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13730 	      else
13731 		return c_parser_omp_parallel (loc, parser, p_name, mask,
13732 					      cclauses);
13733 	    }
13734 	  block = c_begin_compound_stmt (true);
13735 	  if (simd)
13736 	    ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13737 	  else
13738 	    ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses);
13739 	  block = c_end_compound_stmt (loc, block, true);
13740 	  if (ret == NULL)
13741 	    return ret;
13742 	  ret = make_node (OMP_DISTRIBUTE);
13743 	  TREE_TYPE (ret) = void_type_node;
13744 	  OMP_FOR_BODY (ret) = block;
13745 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13746 	  SET_EXPR_LOCATION (ret, loc);
13747 	  add_stmt (ret);
13748 	  return ret;
13749 	}
13750     }
13751   if (!flag_openmp)  /* flag_openmp_simd  */
13752     {
13753       c_parser_skip_to_pragma_eol (parser, false);
13754       return NULL_TREE;
13755     }
13756 
13757   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13758   if (cclauses)
13759     {
13760       omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
13761       clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13762     }
13763 
13764   block = c_begin_compound_stmt (true);
13765   ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL);
13766   block = c_end_compound_stmt (loc, block, true);
13767   add_stmt (block);
13768 
13769   return ret;
13770 }
13771 
13772 /* OpenMP 4.0:
13773    # pragma omp teams teams-clause[optseq] new-line
13774      structured-block  */
13775 
13776 #define OMP_TEAMS_CLAUSE_MASK					\
13777 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
13778 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
13779 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
13780 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
13781 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS)	\
13782 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT)	\
13783 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13784 
13785 static tree
13786 c_parser_omp_teams (location_t loc, c_parser *parser,
13787 		    char *p_name, omp_clause_mask mask, tree *cclauses)
13788 {
13789   tree clauses, block, ret;
13790 
13791   strcat (p_name, " teams");
13792   mask |= OMP_TEAMS_CLAUSE_MASK;
13793 
13794   if (c_parser_next_token_is (parser, CPP_NAME))
13795     {
13796       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13797       if (strcmp (p, "distribute") == 0)
13798 	{
13799 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13800 	  if (cclauses == NULL)
13801 	    cclauses = cclauses_buf;
13802 
13803 	  c_parser_consume_token (parser);
13804 	  if (!flag_openmp)  /* flag_openmp_simd  */
13805 	    return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13806 	  block = c_begin_compound_stmt (true);
13807 	  ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13808 	  block = c_end_compound_stmt (loc, block, true);
13809 	  if (ret == NULL)
13810 	    return ret;
13811 	  clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13812 	  ret = make_node (OMP_TEAMS);
13813 	  TREE_TYPE (ret) = void_type_node;
13814 	  OMP_TEAMS_CLAUSES (ret) = clauses;
13815 	  OMP_TEAMS_BODY (ret) = block;
13816 	  OMP_TEAMS_COMBINED (ret) = 1;
13817 	  return add_stmt (ret);
13818 	}
13819     }
13820   if (!flag_openmp)  /* flag_openmp_simd  */
13821     {
13822       c_parser_skip_to_pragma_eol (parser, false);
13823       return NULL_TREE;
13824     }
13825 
13826   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13827   if (cclauses)
13828     {
13829       omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
13830       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13831     }
13832 
13833   tree stmt = make_node (OMP_TEAMS);
13834   TREE_TYPE (stmt) = void_type_node;
13835   OMP_TEAMS_CLAUSES (stmt) = clauses;
13836   OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser);
13837 
13838   return add_stmt (stmt);
13839 }
13840 
13841 /* OpenMP 4.0:
13842    # pragma omp target data target-data-clause[optseq] new-line
13843      structured-block  */
13844 
13845 #define OMP_TARGET_DATA_CLAUSE_MASK				\
13846 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
13847 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
13848 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13849 
13850 static tree
13851 c_parser_omp_target_data (location_t loc, c_parser *parser)
13852 {
13853   tree stmt = make_node (OMP_TARGET_DATA);
13854   TREE_TYPE (stmt) = void_type_node;
13855 
13856   OMP_TARGET_DATA_CLAUSES (stmt)
13857     = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
13858 				"#pragma omp target data");
13859   keep_next_level ();
13860   tree block = c_begin_compound_stmt (true);
13861   add_stmt (c_parser_omp_structured_block (parser));
13862   OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13863 
13864   SET_EXPR_LOCATION (stmt, loc);
13865   return add_stmt (stmt);
13866 }
13867 
13868 /* OpenMP 4.0:
13869    # pragma omp target update target-update-clause[optseq] new-line */
13870 
13871 #define OMP_TARGET_UPDATE_CLAUSE_MASK				\
13872 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM)		\
13873 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)		\
13874 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
13875 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13876 
13877 static bool
13878 c_parser_omp_target_update (location_t loc, c_parser *parser,
13879 			    enum pragma_context context)
13880 {
13881   if (context == pragma_stmt)
13882     {
13883       error_at (loc,
13884 		"%<#pragma omp target update%> may only be "
13885 		"used in compound statements");
13886       c_parser_skip_to_pragma_eol (parser);
13887       return false;
13888     }
13889 
13890   tree clauses
13891     = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
13892 				"#pragma omp target update");
13893   if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
13894       && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
13895     {
13896       error_at (loc,
13897 		"%<#pragma omp target update%> must contain at least one "
13898 		"%<from%> or %<to%> clauses");
13899       return false;
13900     }
13901 
13902   tree stmt = make_node (OMP_TARGET_UPDATE);
13903   TREE_TYPE (stmt) = void_type_node;
13904   OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
13905   SET_EXPR_LOCATION (stmt, loc);
13906   add_stmt (stmt);
13907   return false;
13908 }
13909 
13910 /* OpenMP 4.0:
13911    # pragma omp target target-clause[optseq] new-line
13912      structured-block  */
13913 
13914 #define OMP_TARGET_CLAUSE_MASK					\
13915 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
13916 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
13917 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13918 
13919 static bool
13920 c_parser_omp_target (c_parser *parser, enum pragma_context context)
13921 {
13922   location_t loc = c_parser_peek_token (parser)->location;
13923   c_parser_consume_pragma (parser);
13924 
13925   if (context != pragma_stmt && context != pragma_compound)
13926     {
13927       c_parser_error (parser, "expected declaration specifiers");
13928       c_parser_skip_to_pragma_eol (parser);
13929       return false;
13930     }
13931 
13932   if (c_parser_next_token_is (parser, CPP_NAME))
13933     {
13934       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13935 
13936       if (strcmp (p, "teams") == 0)
13937 	{
13938 	  tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
13939 	  char p_name[sizeof ("#pragma omp target teams distribute "
13940 			      "parallel for simd")];
13941 
13942 	  c_parser_consume_token (parser);
13943 	  strcpy (p_name, "#pragma omp target");
13944 	  if (!flag_openmp)  /* flag_openmp_simd  */
13945 	    {
13946 	      tree stmt = c_parser_omp_teams (loc, parser, p_name,
13947 					      OMP_TARGET_CLAUSE_MASK,
13948 					      cclauses);
13949 	      return stmt != NULL_TREE;
13950 	    }
13951 	  keep_next_level ();
13952 	  tree block = c_begin_compound_stmt (true);
13953 	  tree ret = c_parser_omp_teams (loc, parser, p_name,
13954 					 OMP_TARGET_CLAUSE_MASK, cclauses);
13955 	  block = c_end_compound_stmt (loc, block, true);
13956 	  if (ret == NULL_TREE)
13957 	    return false;
13958 	  tree stmt = make_node (OMP_TARGET);
13959 	  TREE_TYPE (stmt) = void_type_node;
13960 	  OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
13961 	  OMP_TARGET_BODY (stmt) = block;
13962 	  add_stmt (stmt);
13963 	  return true;
13964 	}
13965       else if (!flag_openmp)  /* flag_openmp_simd  */
13966 	{
13967 	  c_parser_skip_to_pragma_eol (parser, false);
13968 	  return false;
13969 	}
13970       else if (strcmp (p, "data") == 0)
13971 	{
13972 	  c_parser_consume_token (parser);
13973 	  c_parser_omp_target_data (loc, parser);
13974 	  return true;
13975 	}
13976       else if (strcmp (p, "update") == 0)
13977 	{
13978 	  c_parser_consume_token (parser);
13979 	  return c_parser_omp_target_update (loc, parser, context);
13980 	}
13981     }
13982 
13983   if (!flag_openmp) /* flag_openmp_simd  */
13984     {
13985       c_parser_skip_to_pragma_eol (parser, false);
13986       return false;
13987     }
13988   tree stmt = make_node (OMP_TARGET);
13989   TREE_TYPE (stmt) = void_type_node;
13990 
13991   OMP_TARGET_CLAUSES (stmt)
13992     = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
13993 				"#pragma omp target");
13994   keep_next_level ();
13995   tree block = c_begin_compound_stmt (true);
13996   add_stmt (c_parser_omp_structured_block (parser));
13997   OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13998 
13999   SET_EXPR_LOCATION (stmt, loc);
14000   add_stmt (stmt);
14001   return true;
14002 }
14003 
14004 /* OpenMP 4.0:
14005    # pragma omp declare simd declare-simd-clauses[optseq] new-line  */
14006 
14007 #define OMP_DECLARE_SIMD_CLAUSE_MASK				\
14008 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN)	\
14009 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
14010 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)	\
14011 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)	\
14012 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH)	\
14013 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
14014 
14015 static void
14016 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
14017 {
14018   vec<c_token> clauses = vNULL;
14019   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14020     {
14021       c_token *token = c_parser_peek_token (parser);
14022       if (token->type == CPP_EOF)
14023 	{
14024 	  c_parser_skip_to_pragma_eol (parser);
14025 	  clauses.release ();
14026 	  return;
14027 	}
14028       clauses.safe_push (*token);
14029       c_parser_consume_token (parser);
14030     }
14031   clauses.safe_push (*c_parser_peek_token (parser));
14032   c_parser_skip_to_pragma_eol (parser);
14033 
14034   while (c_parser_next_token_is (parser, CPP_PRAGMA))
14035     {
14036       if (c_parser_peek_token (parser)->pragma_kind
14037 	  != PRAGMA_OMP_DECLARE_REDUCTION
14038 	  || c_parser_peek_2nd_token (parser)->type != CPP_NAME
14039 	  || strcmp (IDENTIFIER_POINTER
14040 				(c_parser_peek_2nd_token (parser)->value),
14041 		     "simd") != 0)
14042 	{
14043 	  c_parser_error (parser,
14044 			  "%<#pragma omp declare simd%> must be followed by "
14045 			  "function declaration or definition or another "
14046 			  "%<#pragma omp declare simd%>");
14047 	  clauses.release ();
14048 	  return;
14049 	}
14050       c_parser_consume_pragma (parser);
14051       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14052 	{
14053 	  c_token *token = c_parser_peek_token (parser);
14054 	  if (token->type == CPP_EOF)
14055 	    {
14056 	      c_parser_skip_to_pragma_eol (parser);
14057 	      clauses.release ();
14058 	      return;
14059 	    }
14060 	  clauses.safe_push (*token);
14061 	  c_parser_consume_token (parser);
14062 	}
14063       clauses.safe_push (*c_parser_peek_token (parser));
14064       c_parser_skip_to_pragma_eol (parser);
14065     }
14066 
14067   /* Make sure nothing tries to read past the end of the tokens.  */
14068   c_token eof_token;
14069   memset (&eof_token, 0, sizeof (eof_token));
14070   eof_token.type = CPP_EOF;
14071   clauses.safe_push (eof_token);
14072   clauses.safe_push (eof_token);
14073 
14074   switch (context)
14075     {
14076     case pragma_external:
14077       if (c_parser_next_token_is (parser, CPP_KEYWORD)
14078 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14079 	{
14080 	  int ext = disable_extension_diagnostics ();
14081 	  do
14082 	    c_parser_consume_token (parser);
14083 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
14084 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14085 	  c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14086 					 NULL, clauses);
14087 	  restore_extension_diagnostics (ext);
14088 	}
14089       else
14090 	c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14091 				       NULL, clauses);
14092       break;
14093     case pragma_struct:
14094     case pragma_param:
14095       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14096 			      "function declaration or definition");
14097       break;
14098     case pragma_compound:
14099     case pragma_stmt:
14100       if (c_parser_next_token_is (parser, CPP_KEYWORD)
14101 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14102 	{
14103 	  int ext = disable_extension_diagnostics ();
14104 	  do
14105 	    c_parser_consume_token (parser);
14106 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
14107 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14108 	  if (c_parser_next_tokens_start_declaration (parser))
14109 	    {
14110 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
14111 					     true, NULL, clauses);
14112 	      restore_extension_diagnostics (ext);
14113 	      break;
14114 	    }
14115 	  restore_extension_diagnostics (ext);
14116 	}
14117       else if (c_parser_next_tokens_start_declaration (parser))
14118 	{
14119 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
14120 					 NULL, clauses);
14121 	  break;
14122 	}
14123       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14124 			      "function declaration or definition");
14125       break;
14126     default:
14127       gcc_unreachable ();
14128     }
14129   clauses.release ();
14130 }
14131 
14132 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14133    and put that into "omp declare simd" attribute.  */
14134 
14135 static void
14136 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
14137 			   vec<c_token> clauses)
14138 {
14139   if (flag_cilkplus
14140       && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14141     {
14142       error ("%<#pragma omp declare simd%> cannot be used in the same "
14143 	     "function marked as a Cilk Plus SIMD-enabled function");
14144       vec_free (parser->cilk_simd_fn_tokens);
14145       return;
14146     }
14147 
14148   /* Normally first token is CPP_NAME "simd".  CPP_EOF there indicates
14149      error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14150      has already processed the tokens.  */
14151   if (clauses.exists () && clauses[0].type == CPP_EOF)
14152     return;
14153   if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
14154     {
14155       error ("%<#pragma omp declare simd%> not immediately followed by "
14156 	     "a function declaration or definition");
14157       clauses[0].type = CPP_EOF;
14158       return;
14159     }
14160   if (clauses.exists () && clauses[0].type != CPP_NAME)
14161     {
14162       error_at (DECL_SOURCE_LOCATION (fndecl),
14163 		"%<#pragma omp declare simd%> not immediately followed by "
14164 		"a single function declaration or definition");
14165       clauses[0].type = CPP_EOF;
14166       return;
14167     }
14168 
14169   if (parms == NULL_TREE)
14170     parms = DECL_ARGUMENTS (fndecl);
14171 
14172   unsigned int tokens_avail = parser->tokens_avail;
14173   gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14174   bool is_cilkplus_cilk_simd_fn = false;
14175 
14176   if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14177     {
14178       parser->tokens = parser->cilk_simd_fn_tokens->address ();
14179       parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens);
14180       is_cilkplus_cilk_simd_fn = true;
14181     }
14182   else
14183     {
14184       parser->tokens = clauses.address ();
14185       parser->tokens_avail = clauses.length ();
14186     }
14187 
14188   /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end.  */
14189   while (parser->tokens_avail > 3)
14190     {
14191       c_token *token = c_parser_peek_token (parser);
14192       if (!is_cilkplus_cilk_simd_fn)
14193 	gcc_assert (token->type == CPP_NAME
14194 		    && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
14195       else
14196 	gcc_assert (token->type == CPP_NAME
14197 		    && is_cilkplus_vector_p (token->value));
14198       c_parser_consume_token (parser);
14199       parser->in_pragma = true;
14200 
14201       tree c = NULL_TREE;
14202       if (is_cilkplus_cilk_simd_fn)
14203 	c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
14204 				      "SIMD-enabled functions attribute");
14205       else
14206 	c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
14207 				      "#pragma omp declare simd");
14208       c = c_omp_declare_simd_clauses_to_numbers (parms, c);
14209       if (c != NULL_TREE)
14210 	c = tree_cons (NULL_TREE, c, NULL_TREE);
14211       if (is_cilkplus_cilk_simd_fn)
14212 	{
14213 	  tree k = build_tree_list (get_identifier ("cilk simd function"),
14214 				    NULL_TREE);
14215 	  TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
14216 	  DECL_ATTRIBUTES (fndecl) = k;
14217 	}
14218       c = build_tree_list (get_identifier ("omp declare simd"), c);
14219       TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
14220       DECL_ATTRIBUTES (fndecl) = c;
14221     }
14222 
14223   parser->tokens = &parser->tokens_buf[0];
14224   parser->tokens_avail = tokens_avail;
14225   if (clauses.exists ())
14226     clauses[0].type = CPP_PRAGMA;
14227 
14228   if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14229     vec_free (parser->cilk_simd_fn_tokens);
14230 }
14231 
14232 
14233 /* OpenMP 4.0:
14234    # pragma omp declare target new-line
14235    declarations and definitions
14236    # pragma omp end declare target new-line  */
14237 
14238 static void
14239 c_parser_omp_declare_target (c_parser *parser)
14240 {
14241   c_parser_skip_to_pragma_eol (parser);
14242   current_omp_declare_target_attribute++;
14243 }
14244 
14245 static void
14246 c_parser_omp_end_declare_target (c_parser *parser)
14247 {
14248   location_t loc = c_parser_peek_token (parser)->location;
14249   c_parser_consume_pragma (parser);
14250   if (c_parser_next_token_is (parser, CPP_NAME)
14251       && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14252 		 "declare") == 0)
14253     {
14254       c_parser_consume_token (parser);
14255       if (c_parser_next_token_is (parser, CPP_NAME)
14256 	  && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14257 		     "target") == 0)
14258 	c_parser_consume_token (parser);
14259       else
14260 	{
14261 	  c_parser_error (parser, "expected %<target%>");
14262 	  c_parser_skip_to_pragma_eol (parser);
14263 	  return;
14264 	}
14265     }
14266   else
14267     {
14268       c_parser_error (parser, "expected %<declare%>");
14269       c_parser_skip_to_pragma_eol (parser);
14270       return;
14271     }
14272   c_parser_skip_to_pragma_eol (parser);
14273   if (!current_omp_declare_target_attribute)
14274     error_at (loc, "%<#pragma omp end declare target%> without corresponding "
14275 		   "%<#pragma omp declare target%>");
14276   else
14277     current_omp_declare_target_attribute--;
14278 }
14279 
14280 
14281 /* OpenMP 4.0
14282    #pragma omp declare reduction (reduction-id : typename-list : expression) \
14283       initializer-clause[opt] new-line
14284 
14285    initializer-clause:
14286       initializer (omp_priv = initializer)
14287       initializer (function-name (argument-list))  */
14288 
14289 static void
14290 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
14291 {
14292   unsigned int tokens_avail = 0, i;
14293   vec<tree> types = vNULL;
14294   vec<c_token> clauses = vNULL;
14295   enum tree_code reduc_code = ERROR_MARK;
14296   tree reduc_id = NULL_TREE;
14297   tree type;
14298   location_t rloc = c_parser_peek_token (parser)->location;
14299 
14300   if (context == pragma_struct || context == pragma_param)
14301     {
14302       error ("%<#pragma omp declare reduction%> not at file or block scope");
14303       goto fail;
14304     }
14305 
14306   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14307     goto fail;
14308 
14309   switch (c_parser_peek_token (parser)->type)
14310     {
14311     case CPP_PLUS:
14312       reduc_code = PLUS_EXPR;
14313       break;
14314     case CPP_MULT:
14315       reduc_code = MULT_EXPR;
14316       break;
14317     case CPP_MINUS:
14318       reduc_code = MINUS_EXPR;
14319       break;
14320     case CPP_AND:
14321       reduc_code = BIT_AND_EXPR;
14322       break;
14323     case CPP_XOR:
14324       reduc_code = BIT_XOR_EXPR;
14325       break;
14326     case CPP_OR:
14327       reduc_code = BIT_IOR_EXPR;
14328       break;
14329     case CPP_AND_AND:
14330       reduc_code = TRUTH_ANDIF_EXPR;
14331       break;
14332     case CPP_OR_OR:
14333       reduc_code = TRUTH_ORIF_EXPR;
14334       break;
14335     case CPP_NAME:
14336       const char *p;
14337       p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14338       if (strcmp (p, "min") == 0)
14339 	{
14340 	  reduc_code = MIN_EXPR;
14341 	  break;
14342 	}
14343       if (strcmp (p, "max") == 0)
14344 	{
14345 	  reduc_code = MAX_EXPR;
14346 	  break;
14347 	}
14348       reduc_id = c_parser_peek_token (parser)->value;
14349       break;
14350     default:
14351       c_parser_error (parser,
14352 		      "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14353 		      "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14354       goto fail;
14355     }
14356 
14357   tree orig_reduc_id, reduc_decl;
14358   orig_reduc_id = reduc_id;
14359   reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
14360   reduc_decl = c_omp_reduction_decl (reduc_id);
14361   c_parser_consume_token (parser);
14362 
14363   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
14364     goto fail;
14365 
14366   while (true)
14367     {
14368       location_t loc = c_parser_peek_token (parser)->location;
14369       struct c_type_name *ctype = c_parser_type_name (parser);
14370       if (ctype != NULL)
14371 	{
14372 	  type = groktypename (ctype, NULL, NULL);
14373 	  if (type == error_mark_node)
14374 	    ;
14375 	  else if ((INTEGRAL_TYPE_P (type)
14376 		    || TREE_CODE (type) == REAL_TYPE
14377 		    || TREE_CODE (type) == COMPLEX_TYPE)
14378 		   && orig_reduc_id == NULL_TREE)
14379 	    error_at (loc, "predeclared arithmetic type in "
14380 			   "%<#pragma omp declare reduction%>");
14381 	  else if (TREE_CODE (type) == FUNCTION_TYPE
14382 		   || TREE_CODE (type) == ARRAY_TYPE)
14383 	    error_at (loc, "function or array type in "
14384 		      "%<#pragma omp declare reduction%>");
14385 	  else if (TYPE_QUALS_NO_ADDR_SPACE (type))
14386 	    error_at (loc, "const, volatile or restrict qualified type in "
14387 			   "%<#pragma omp declare reduction%>");
14388 	  else
14389 	    {
14390 	      tree t;
14391 	      for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
14392 		if (comptypes (TREE_PURPOSE (t), type))
14393 		  {
14394 		    error_at (loc, "redeclaration of %qs "
14395 				   "%<#pragma omp declare reduction%> for "
14396 				   "type %qT",
14397 				   IDENTIFIER_POINTER (reduc_id)
14398 				   + sizeof ("omp declare reduction ") - 1,
14399 				   type);
14400 		    location_t ploc
14401 		      = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
14402 							    0));
14403 		    error_at (ploc, "previous %<#pragma omp declare "
14404 				    "reduction%>");
14405 		    break;
14406 		  }
14407 	      if (t == NULL_TREE)
14408 		types.safe_push (type);
14409 	    }
14410 	  if (c_parser_next_token_is (parser, CPP_COMMA))
14411 	    c_parser_consume_token (parser);
14412 	  else
14413 	    break;
14414 	}
14415       else
14416 	break;
14417     }
14418 
14419   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
14420       || types.is_empty ())
14421     {
14422      fail:
14423       clauses.release ();
14424       types.release ();
14425       while (true)
14426 	{
14427 	  c_token *token = c_parser_peek_token (parser);
14428 	  if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
14429 	    break;
14430 	  c_parser_consume_token (parser);
14431 	}
14432       c_parser_skip_to_pragma_eol (parser);
14433       return;
14434     }
14435 
14436   if (types.length () > 1)
14437     {
14438       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14439 	{
14440 	  c_token *token = c_parser_peek_token (parser);
14441 	  if (token->type == CPP_EOF)
14442 	    goto fail;
14443 	  clauses.safe_push (*token);
14444 	  c_parser_consume_token (parser);
14445 	}
14446       clauses.safe_push (*c_parser_peek_token (parser));
14447       c_parser_skip_to_pragma_eol (parser);
14448 
14449       /* Make sure nothing tries to read past the end of the tokens.  */
14450       c_token eof_token;
14451       memset (&eof_token, 0, sizeof (eof_token));
14452       eof_token.type = CPP_EOF;
14453       clauses.safe_push (eof_token);
14454       clauses.safe_push (eof_token);
14455     }
14456 
14457   int errs = errorcount;
14458   FOR_EACH_VEC_ELT (types, i, type)
14459     {
14460       tokens_avail = parser->tokens_avail;
14461       gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14462       if (!clauses.is_empty ())
14463 	{
14464 	  parser->tokens = clauses.address ();
14465 	  parser->tokens_avail = clauses.length ();
14466 	  parser->in_pragma = true;
14467 	}
14468 
14469       bool nested = current_function_decl != NULL_TREE;
14470       if (nested)
14471 	c_push_function_context ();
14472       tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
14473 				reduc_id, default_function_type);
14474       current_function_decl = fndecl;
14475       allocate_struct_function (fndecl, true);
14476       push_scope ();
14477       tree stmt = push_stmt_list ();
14478       /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14479 	 warn about these.  */
14480       tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
14481 				 get_identifier ("omp_out"), type);
14482       DECL_ARTIFICIAL (omp_out) = 1;
14483       DECL_CONTEXT (omp_out) = fndecl;
14484       pushdecl (omp_out);
14485       tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
14486 				get_identifier ("omp_in"), type);
14487       DECL_ARTIFICIAL (omp_in) = 1;
14488       DECL_CONTEXT (omp_in) = fndecl;
14489       pushdecl (omp_in);
14490       struct c_expr combiner = c_parser_expression (parser);
14491       struct c_expr initializer;
14492       tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
14493       bool bad = false;
14494       initializer.value = error_mark_node;
14495       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14496 	bad = true;
14497       else if (c_parser_next_token_is (parser, CPP_NAME)
14498 	       && strcmp (IDENTIFIER_POINTER
14499 				(c_parser_peek_token (parser)->value),
14500 			  "initializer") == 0)
14501 	{
14502 	  c_parser_consume_token (parser);
14503 	  pop_scope ();
14504 	  push_scope ();
14505 	  omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
14506 				 get_identifier ("omp_priv"), type);
14507 	  DECL_ARTIFICIAL (omp_priv) = 1;
14508 	  DECL_INITIAL (omp_priv) = error_mark_node;
14509 	  DECL_CONTEXT (omp_priv) = fndecl;
14510 	  pushdecl (omp_priv);
14511 	  omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
14512 				 get_identifier ("omp_orig"), type);
14513 	  DECL_ARTIFICIAL (omp_orig) = 1;
14514 	  DECL_CONTEXT (omp_orig) = fndecl;
14515 	  pushdecl (omp_orig);
14516 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14517 	    bad = true;
14518 	  else if (!c_parser_next_token_is (parser, CPP_NAME))
14519 	    {
14520 	      c_parser_error (parser, "expected %<omp_priv%> or "
14521 				      "function-name");
14522 	      bad = true;
14523 	    }
14524 	  else if (strcmp (IDENTIFIER_POINTER
14525 				(c_parser_peek_token (parser)->value),
14526 			   "omp_priv") != 0)
14527 	    {
14528 	      if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
14529 		  || c_parser_peek_token (parser)->id_kind != C_ID_ID)
14530 		{
14531 		  c_parser_error (parser, "expected function-name %<(%>");
14532 		  bad = true;
14533 		}
14534 	      else
14535 		initializer = c_parser_postfix_expression (parser);
14536 	      if (initializer.value
14537 		  && TREE_CODE (initializer.value) == CALL_EXPR)
14538 		{
14539 		  int j;
14540 		  tree c = initializer.value;
14541 		  for (j = 0; j < call_expr_nargs (c); j++)
14542 		    if (TREE_CODE (CALL_EXPR_ARG (c, j)) == ADDR_EXPR
14543 			&& TREE_OPERAND (CALL_EXPR_ARG (c, j), 0) == omp_priv)
14544 		      break;
14545 		  if (j == call_expr_nargs (c))
14546 		    error ("one of the initializer call arguments should be "
14547 			   "%<&omp_priv%>");
14548 		}
14549 	    }
14550 	  else
14551 	    {
14552 	      c_parser_consume_token (parser);
14553 	      if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
14554 		bad = true;
14555 	      else
14556 		{
14557 		  tree st = push_stmt_list ();
14558 		  start_init (omp_priv, NULL_TREE, 0);
14559 		  location_t loc = c_parser_peek_token (parser)->location;
14560 		  struct c_expr init = c_parser_initializer (parser);
14561 		  finish_init ();
14562 		  finish_decl (omp_priv, loc, init.value,
14563 		      	       init.original_type, NULL_TREE);
14564 		  pop_stmt_list (st);
14565 		}
14566 	    }
14567 	  if (!bad
14568 	      && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14569 	    bad = true;
14570 	}
14571 
14572       if (!bad)
14573 	{
14574 	  c_parser_skip_to_pragma_eol (parser);
14575 
14576 	  tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
14577 			      DECL_INITIAL (reduc_decl));
14578 	  DECL_INITIAL (reduc_decl) = t;
14579 	  DECL_SOURCE_LOCATION (omp_out) = rloc;
14580 	  TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
14581 	  TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
14582 	  TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
14583 	  walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
14584 		     &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
14585 	  if (omp_priv)
14586 	    {
14587 	      DECL_SOURCE_LOCATION (omp_priv) = rloc;
14588 	      TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
14589 	      TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
14590 	      TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
14591 	      walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
14592 			 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14593 	      walk_tree (&DECL_INITIAL (omp_priv),
14594 			 c_check_omp_declare_reduction_r,
14595 			 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14596 	    }
14597 	}
14598 
14599       pop_stmt_list (stmt);
14600       pop_scope ();
14601       if (cfun->language != NULL)
14602 	{
14603 	  ggc_free (cfun->language);
14604 	  cfun->language = NULL;
14605 	}
14606       set_cfun (NULL);
14607       current_function_decl = NULL_TREE;
14608       if (nested)
14609 	c_pop_function_context ();
14610 
14611       if (!clauses.is_empty ())
14612 	{
14613 	  parser->tokens = &parser->tokens_buf[0];
14614 	  parser->tokens_avail = tokens_avail;
14615 	}
14616       if (bad)
14617 	goto fail;
14618       if (errs != errorcount)
14619 	break;
14620     }
14621 
14622   clauses.release ();
14623   types.release ();
14624 }
14625 
14626 
14627 /* OpenMP 4.0
14628    #pragma omp declare simd declare-simd-clauses[optseq] new-line
14629    #pragma omp declare reduction (reduction-id : typename-list : expression) \
14630       initializer-clause[opt] new-line
14631    #pragma omp declare target new-line  */
14632 
14633 static void
14634 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
14635 {
14636   c_parser_consume_pragma (parser);
14637   if (c_parser_next_token_is (parser, CPP_NAME))
14638     {
14639       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14640       if (strcmp (p, "simd") == 0)
14641 	{
14642 	  /* c_parser_consume_token (parser); done in
14643 	     c_parser_omp_declare_simd.  */
14644 	  c_parser_omp_declare_simd (parser, context);
14645 	  return;
14646 	}
14647       if (strcmp (p, "reduction") == 0)
14648 	{
14649 	  c_parser_consume_token (parser);
14650 	  c_parser_omp_declare_reduction (parser, context);
14651 	  return;
14652 	}
14653       if (!flag_openmp)  /* flag_openmp_simd  */
14654 	{
14655 	  c_parser_skip_to_pragma_eol (parser, false);
14656 	  return;
14657 	}
14658       if (strcmp (p, "target") == 0)
14659 	{
14660 	  c_parser_consume_token (parser);
14661 	  c_parser_omp_declare_target (parser);
14662 	  return;
14663 	}
14664     }
14665 
14666   c_parser_error (parser, "expected %<simd%> or %<reduction%> "
14667 			  "or %<target%>");
14668   c_parser_skip_to_pragma_eol (parser);
14669 }
14670 
14671 /* Main entry point to parsing most OpenMP pragmas.  */
14672 
14673 static void
14674 c_parser_omp_construct (c_parser *parser)
14675 {
14676   enum pragma_kind p_kind;
14677   location_t loc;
14678   tree stmt;
14679   char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
14680   omp_clause_mask mask (0);
14681 
14682   loc = c_parser_peek_token (parser)->location;
14683   p_kind = c_parser_peek_token (parser)->pragma_kind;
14684   c_parser_consume_pragma (parser);
14685 
14686   switch (p_kind)
14687     {
14688     case PRAGMA_OACC_CACHE:
14689       strcpy (p_name, "#pragma acc");
14690       stmt = c_parser_oacc_cache (loc, parser);
14691       break;
14692     case PRAGMA_OACC_DATA:
14693       stmt = c_parser_oacc_data (loc, parser);
14694       break;
14695     case PRAGMA_OACC_KERNELS:
14696       strcpy (p_name, "#pragma acc");
14697       stmt = c_parser_oacc_kernels (loc, parser, p_name);
14698       break;
14699     case PRAGMA_OACC_LOOP:
14700       strcpy (p_name, "#pragma acc");
14701       stmt = c_parser_oacc_loop (loc, parser, p_name);
14702       break;
14703     case PRAGMA_OACC_PARALLEL:
14704       strcpy (p_name, "#pragma acc");
14705       stmt = c_parser_oacc_parallel (loc, parser, p_name);
14706       break;
14707     case PRAGMA_OACC_WAIT:
14708       strcpy (p_name, "#pragma wait");
14709       stmt = c_parser_oacc_wait (loc, parser, p_name);
14710       break;
14711     case PRAGMA_OMP_ATOMIC:
14712       c_parser_omp_atomic (loc, parser);
14713       return;
14714     case PRAGMA_OMP_CRITICAL:
14715       stmt = c_parser_omp_critical (loc, parser);
14716       break;
14717     case PRAGMA_OMP_DISTRIBUTE:
14718       strcpy (p_name, "#pragma omp");
14719       stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL);
14720       break;
14721     case PRAGMA_OMP_FOR:
14722       strcpy (p_name, "#pragma omp");
14723       stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL);
14724       break;
14725     case PRAGMA_OMP_MASTER:
14726       stmt = c_parser_omp_master (loc, parser);
14727       break;
14728     case PRAGMA_OMP_ORDERED:
14729       stmt = c_parser_omp_ordered (loc, parser);
14730       break;
14731     case PRAGMA_OMP_PARALLEL:
14732       strcpy (p_name, "#pragma omp");
14733       stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL);
14734       break;
14735     case PRAGMA_OMP_SECTIONS:
14736       strcpy (p_name, "#pragma omp");
14737       stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
14738       break;
14739     case PRAGMA_OMP_SIMD:
14740       strcpy (p_name, "#pragma omp");
14741       stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL);
14742       break;
14743     case PRAGMA_OMP_SINGLE:
14744       stmt = c_parser_omp_single (loc, parser);
14745       break;
14746     case PRAGMA_OMP_TASK:
14747       stmt = c_parser_omp_task (loc, parser);
14748       break;
14749     case PRAGMA_OMP_TASKGROUP:
14750       stmt = c_parser_omp_taskgroup (parser);
14751       break;
14752     case PRAGMA_OMP_TEAMS:
14753       strcpy (p_name, "#pragma omp");
14754       stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL);
14755       break;
14756     default:
14757       gcc_unreachable ();
14758     }
14759 
14760   if (stmt)
14761     gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
14762 }
14763 
14764 
14765 /* OpenMP 2.5:
14766    # pragma omp threadprivate (variable-list) */
14767 
14768 static void
14769 c_parser_omp_threadprivate (c_parser *parser)
14770 {
14771   tree vars, t;
14772   location_t loc;
14773 
14774   c_parser_consume_pragma (parser);
14775   loc = c_parser_peek_token (parser)->location;
14776   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
14777 
14778   /* Mark every variable in VARS to be assigned thread local storage.  */
14779   for (t = vars; t; t = TREE_CHAIN (t))
14780     {
14781       tree v = TREE_PURPOSE (t);
14782 
14783       /* FIXME diagnostics: Ideally we should keep individual
14784 	 locations for all the variables in the var list to make the
14785 	 following errors more precise.  Perhaps
14786 	 c_parser_omp_var_list_parens() should construct a list of
14787 	 locations to go along with the var list.  */
14788 
14789       /* If V had already been marked threadprivate, it doesn't matter
14790 	 whether it had been used prior to this point.  */
14791       if (TREE_CODE (v) != VAR_DECL)
14792 	error_at (loc, "%qD is not a variable", v);
14793       else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
14794 	error_at (loc, "%qE declared %<threadprivate%> after first use", v);
14795       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
14796 	error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
14797       else if (TREE_TYPE (v) == error_mark_node)
14798 	;
14799       else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
14800 	error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
14801       else
14802 	{
14803 	  if (! DECL_THREAD_LOCAL_P (v))
14804 	    {
14805 	      set_decl_tls_model (v, decl_default_tls_model (v));
14806 	      /* If rtl has been already set for this var, call
14807 		 make_decl_rtl once again, so that encode_section_info
14808 		 has a chance to look at the new decl flags.  */
14809 	      if (DECL_RTL_SET_P (v))
14810 		make_decl_rtl (v);
14811 	    }
14812 	  C_DECL_THREADPRIVATE_P (v) = 1;
14813 	}
14814     }
14815 
14816   c_parser_skip_to_pragma_eol (parser);
14817 }
14818 
14819 /* Cilk Plus <#pragma simd> parsing routines.  */
14820 
14821 /* Helper function for c_parser_pragma.  Perform some sanity checking
14822    for <#pragma simd> constructs.  Returns FALSE if there was a
14823    problem.  */
14824 
14825 static bool
14826 c_parser_cilk_verify_simd (c_parser *parser,
14827 				  enum pragma_context context)
14828 {
14829   if (!flag_cilkplus)
14830     {
14831       warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14832       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14833       return false;
14834     }
14835   if (context == pragma_external)
14836     {
14837       c_parser_error (parser,"pragma simd must be inside a function");
14838       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14839       return false;
14840     }
14841   return true;
14842 }
14843 
14844 /* Cilk Plus:
14845    This function is shared by SIMD-enabled functions and #pragma simd.
14846    If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14847    CLAUSES is unused.  The main purpose of this function is to parse a
14848    vectorlength attribute or clause and check for parse errors.
14849    When IS_SIMD_FN is true then the function is merely caching the tokens
14850    in PARSER->CILK_SIMD_FN_TOKENS.  If errors are found then the token
14851    cache is cleared since there is no reason to continue.
14852    Syntax:
14853    vectorlength ( constant-expression )  */
14854 
14855 static tree
14856 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses,
14857 				   bool is_simd_fn)
14858 {
14859   if (is_simd_fn)
14860     check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength");
14861   else
14862   /* The vectorlength clause behaves exactly like OpenMP's safelen
14863      clause.  Represent it in OpenMP terms.  */
14864     check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
14865 
14866   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14867     return clauses;
14868 
14869   location_t loc = c_parser_peek_token (parser)->location;
14870   tree expr = c_parser_expr_no_commas (parser, NULL).value;
14871   expr = c_fully_fold (expr, false, NULL);
14872 
14873   /* If expr is an error_mark_node then the above function would have
14874      emitted an error.  No reason to do it twice.  */
14875   if (expr == error_mark_node)
14876     ;
14877   else if (!TREE_TYPE (expr)
14878 	   || !TREE_CONSTANT (expr)
14879 	   || !INTEGRAL_TYPE_P (TREE_TYPE (expr)))
14880 
14881     error_at (loc, "vectorlength must be an integer constant");
14882   else if (wi::exact_log2 (expr) == -1)
14883     error_at (loc, "vectorlength must be a power of 2");
14884   else
14885     {
14886       if (is_simd_fn)
14887 	{
14888 	  tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN);
14889 	  OMP_CLAUSE_SIMDLEN_EXPR (u) = expr;
14890 	  OMP_CLAUSE_CHAIN (u) = clauses;
14891 	  clauses = u;
14892 	}
14893       else
14894 	{
14895 	  tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN);
14896 	  OMP_CLAUSE_SAFELEN_EXPR (u) = expr;
14897 	  OMP_CLAUSE_CHAIN (u) = clauses;
14898 	  clauses = u;
14899 	}
14900     }
14901 
14902   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14903 
14904   return clauses;
14905 }
14906 
14907 /* Cilk Plus:
14908    linear ( simd-linear-variable-list )
14909 
14910    simd-linear-variable-list:
14911      simd-linear-variable
14912      simd-linear-variable-list , simd-linear-variable
14913 
14914    simd-linear-variable:
14915      id-expression
14916      id-expression : simd-linear-step
14917 
14918    simd-linear-step:
14919    conditional-expression */
14920 
14921 static tree
14922 c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
14923 {
14924   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14925     return clauses;
14926 
14927   location_t loc = c_parser_peek_token (parser)->location;
14928 
14929   if (c_parser_next_token_is_not (parser, CPP_NAME)
14930       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
14931     c_parser_error (parser, "expected identifier");
14932 
14933   while (c_parser_next_token_is (parser, CPP_NAME)
14934 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
14935     {
14936       tree var = lookup_name (c_parser_peek_token (parser)->value);
14937 
14938       if (var == NULL)
14939 	{
14940 	  undeclared_variable (c_parser_peek_token (parser)->location,
14941 			       c_parser_peek_token (parser)->value);
14942 	c_parser_consume_token (parser);
14943 	}
14944       else if (var == error_mark_node)
14945 	c_parser_consume_token (parser);
14946       else
14947 	{
14948 	  tree step = integer_one_node;
14949 
14950 	  /* Parse the linear step if present.  */
14951 	  if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
14952 	    {
14953 	      c_parser_consume_token (parser);
14954 	      c_parser_consume_token (parser);
14955 
14956 	      tree expr = c_parser_expr_no_commas (parser, NULL).value;
14957 	      expr = c_fully_fold (expr, false, NULL);
14958 
14959 	      if (TREE_TYPE (expr)
14960 		  && INTEGRAL_TYPE_P (TREE_TYPE (expr))
14961 		  && (TREE_CONSTANT (expr)
14962 		      || DECL_P (expr)))
14963 		step = expr;
14964 	      else
14965 		c_parser_error (parser,
14966 				"step size must be an integer constant "
14967 				"expression or an integer variable");
14968 	    }
14969 	  else
14970 	    c_parser_consume_token (parser);
14971 
14972 	  /* Use OMP_CLAUSE_LINEAR, which has the same semantics.  */
14973 	  tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR);
14974 	  OMP_CLAUSE_DECL (u) = var;
14975 	  OMP_CLAUSE_LINEAR_STEP (u) = step;
14976 	  OMP_CLAUSE_CHAIN (u) = clauses;
14977 	  clauses = u;
14978 	}
14979 
14980       if (c_parser_next_token_is_not (parser, CPP_COMMA))
14981 	break;
14982 
14983       c_parser_consume_token (parser);
14984     }
14985 
14986   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14987 
14988   return clauses;
14989 }
14990 
14991 /* Returns the name of the next clause.  If the clause is not
14992    recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14993    not consumed.  Otherwise, the appropriate pragma_simd_clause is
14994    returned and the token is consumed.  */
14995 
14996 static pragma_omp_clause
14997 c_parser_cilk_clause_name (c_parser *parser)
14998 {
14999   pragma_omp_clause result;
15000   c_token *token = c_parser_peek_token (parser);
15001 
15002   if (!token->value || token->type != CPP_NAME)
15003     return PRAGMA_CILK_CLAUSE_NONE;
15004 
15005   const char *p = IDENTIFIER_POINTER (token->value);
15006 
15007   if (!strcmp (p, "vectorlength"))
15008     result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
15009   else if (!strcmp (p, "linear"))
15010     result = PRAGMA_CILK_CLAUSE_LINEAR;
15011   else if (!strcmp (p, "private"))
15012     result = PRAGMA_CILK_CLAUSE_PRIVATE;
15013   else if (!strcmp (p, "firstprivate"))
15014     result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
15015   else if (!strcmp (p, "lastprivate"))
15016     result = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
15017   else if (!strcmp (p, "reduction"))
15018     result = PRAGMA_CILK_CLAUSE_REDUCTION;
15019   else
15020     return PRAGMA_CILK_CLAUSE_NONE;
15021 
15022   c_parser_consume_token (parser);
15023   return result;
15024 }
15025 
15026 /* Parse all #<pragma simd> clauses.  Return the list of clauses
15027    found.  */
15028 
15029 static tree
15030 c_parser_cilk_all_clauses (c_parser *parser)
15031 {
15032   tree clauses = NULL;
15033 
15034   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15035     {
15036       pragma_omp_clause c_kind;
15037 
15038       c_kind = c_parser_cilk_clause_name (parser);
15039 
15040       switch (c_kind)
15041 	{
15042 	case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
15043 	  clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false);
15044 	  break;
15045 	case PRAGMA_CILK_CLAUSE_LINEAR:
15046 	  clauses = c_parser_cilk_clause_linear (parser, clauses);
15047 	  break;
15048 	case PRAGMA_CILK_CLAUSE_PRIVATE:
15049 	  /* Use the OpenMP counterpart.  */
15050 	  clauses = c_parser_omp_clause_private (parser, clauses);
15051 	  break;
15052 	case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE:
15053 	  /* Use the OpenMP counterpart.  */
15054 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
15055 	  break;
15056 	case PRAGMA_CILK_CLAUSE_LASTPRIVATE:
15057 	  /* Use the OpenMP counterpart.  */
15058 	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
15059 	  break;
15060 	case PRAGMA_CILK_CLAUSE_REDUCTION:
15061 	  /* Use the OpenMP counterpart.  */
15062 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
15063 	  break;
15064 	default:
15065 	  c_parser_error (parser, "expected %<#pragma simd%> clause");
15066 	  goto saw_error;
15067 	}
15068     }
15069 
15070  saw_error:
15071   c_parser_skip_to_pragma_eol (parser);
15072   return c_finish_cilk_clauses (clauses);
15073 }
15074 
15075 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15076    Here is the correct syntax of this pragma:
15077 	    #pragma cilk grainsize = <EXP>
15078  */
15079 
15080 static void
15081 c_parser_cilk_grainsize (c_parser *parser)
15082 {
15083   extern tree convert_to_integer (tree, tree);
15084 
15085   /* consume the 'grainsize' keyword.  */
15086   c_parser_consume_pragma (parser);
15087 
15088   if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0)
15089     {
15090       struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL);
15091       if (g_expr.value == error_mark_node)
15092 	{
15093 	  c_parser_skip_to_pragma_eol (parser);
15094 	  return;
15095 	}
15096       tree grain = convert_to_integer (long_integer_type_node,
15097 				       c_fully_fold (g_expr.value, false,
15098 						     NULL));
15099       c_parser_skip_to_pragma_eol (parser);
15100       c_token *token = c_parser_peek_token (parser);
15101       if (token && token->type == CPP_KEYWORD
15102 	  && token->keyword == RID_CILK_FOR)
15103 	{
15104 	  if (grain == NULL_TREE || grain == error_mark_node)
15105 	    grain = integer_zero_node;
15106 	  c_parser_cilk_for (parser, grain);
15107 	}
15108       else
15109 	warning (0, "%<#pragma cilk grainsize%> is not followed by "
15110 		    "%<_Cilk_for%>");
15111     }
15112   else
15113     c_parser_skip_to_pragma_eol (parser);
15114 }
15115 
15116 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops.  */
15117 
15118 static void
15119 c_parser_cilk_simd (c_parser *parser)
15120 {
15121   tree clauses = c_parser_cilk_all_clauses (parser);
15122   tree block = c_begin_compound_stmt (true);
15123   location_t loc = c_parser_peek_token (parser)->location;
15124   c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL);
15125   block = c_end_compound_stmt (loc, block, true);
15126   add_stmt (block);
15127 }
15128 
15129 /* Create an artificial decl with TYPE and emit initialization of it with
15130    INIT.  */
15131 
15132 static tree
15133 c_get_temp_regvar (tree type, tree init)
15134 {
15135   location_t loc = EXPR_LOCATION (init);
15136   tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
15137   DECL_ARTIFICIAL (decl) = 1;
15138   DECL_IGNORED_P (decl) = 1;
15139   pushdecl (decl);
15140   tree t = build2 (INIT_EXPR, type, decl, init);
15141   add_stmt (t);
15142   return decl;
15143 }
15144 
15145 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15146   GRAIN is the grain value passed in through pragma or 0.  */
15147 
15148 static void
15149 c_parser_cilk_for (c_parser *parser, tree grain)
15150 {
15151   tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE);
15152   OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR;
15153   OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain;
15154   clauses = c_finish_omp_clauses (clauses);
15155 
15156   tree block = c_begin_compound_stmt (true);
15157   tree sb = push_stmt_list ();
15158   location_t loc = c_parser_peek_token (parser)->location;
15159   tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL);
15160   sb = pop_stmt_list (sb);
15161 
15162   if (omp_for)
15163     {
15164       tree omp_par = make_node (OMP_PARALLEL);
15165       TREE_TYPE (omp_par) = void_type_node;
15166       OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE;
15167       tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
15168       TREE_SIDE_EFFECTS (bind) = 1;
15169       BIND_EXPR_BODY (bind) = sb;
15170       OMP_PARALLEL_BODY (omp_par) = bind;
15171       if (OMP_FOR_PRE_BODY (omp_for))
15172 	{
15173 	  add_stmt (OMP_FOR_PRE_BODY (omp_for));
15174 	  OMP_FOR_PRE_BODY (omp_for) = NULL_TREE;
15175 	}
15176       tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0);
15177       tree decl = TREE_OPERAND (init, 0);
15178       tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0);
15179       tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
15180       tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE;
15181       if (TREE_CODE (t) != INTEGER_CST)
15182 	{
15183 	  TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15184 	  c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15185 	  OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1);
15186 	  OMP_CLAUSE_CHAIN (c) = clauses;
15187 	  clauses = c;
15188 	}
15189       if (TREE_CODE (incr) == MODIFY_EXPR)
15190 	{
15191 	  t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15192 	  if (TREE_CODE (t) != INTEGER_CST)
15193 	    {
15194 	      TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
15195 		= c_get_temp_regvar (TREE_TYPE (t), t);
15196 	      c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15197 	      OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15198 	      OMP_CLAUSE_CHAIN (c) = clauses;
15199 	      clauses = c;
15200 	    }
15201 	}
15202       t = TREE_OPERAND (init, 1);
15203       if (TREE_CODE (t) != INTEGER_CST)
15204 	{
15205 	  TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15206 	  c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15207 	  OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1);
15208 	  OMP_CLAUSE_CHAIN (c) = clauses;
15209 	  clauses = c;
15210 	}
15211       c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
15212       OMP_CLAUSE_DECL (c) = decl;
15213       OMP_CLAUSE_CHAIN (c) = clauses;
15214       clauses = c;
15215       c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_);
15216       OMP_CLAUSE_OPERAND (c, 0)
15217 	= cilk_for_number_of_iterations (omp_for);
15218       OMP_CLAUSE_CHAIN (c) = clauses;
15219       OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c);
15220       add_stmt (omp_par);
15221     }
15222 
15223   block = c_end_compound_stmt (loc, block, true);
15224   add_stmt (block);
15225 }
15226 
15227 
15228 /* Parse a transaction attribute (GCC Extension).
15229 
15230    transaction-attribute:
15231      attributes
15232      [ [ any-word ] ]
15233 
15234    The transactional memory language description is written for C++,
15235    and uses the C++0x attribute syntax.  For compatibility, allow the
15236    bracket style for transactions in C as well.  */
15237 
15238 static tree
15239 c_parser_transaction_attributes (c_parser *parser)
15240 {
15241   tree attr_name, attr = NULL;
15242 
15243   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
15244     return c_parser_attributes (parser);
15245 
15246   if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
15247     return NULL_TREE;
15248   c_parser_consume_token (parser);
15249   if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
15250     goto error1;
15251 
15252   attr_name = c_parser_attribute_any_word (parser);
15253   if (attr_name)
15254     {
15255       c_parser_consume_token (parser);
15256       attr = build_tree_list (attr_name, NULL_TREE);
15257     }
15258   else
15259     c_parser_error (parser, "expected identifier");
15260 
15261   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15262  error1:
15263   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15264   return attr;
15265 }
15266 
15267 /* Parse a __transaction_atomic or __transaction_relaxed statement
15268    (GCC Extension).
15269 
15270    transaction-statement:
15271      __transaction_atomic transaction-attribute[opt] compound-statement
15272      __transaction_relaxed compound-statement
15273 
15274    Note that the only valid attribute is: "outer".
15275 */
15276 
15277 static tree
15278 c_parser_transaction (c_parser *parser, enum rid keyword)
15279 {
15280   unsigned int old_in = parser->in_transaction;
15281   unsigned int this_in = 1, new_in;
15282   location_t loc = c_parser_peek_token (parser)->location;
15283   tree stmt, attrs;
15284 
15285   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15286       || keyword == RID_TRANSACTION_RELAXED)
15287       && c_parser_next_token_is_keyword (parser, keyword));
15288   c_parser_consume_token (parser);
15289 
15290   if (keyword == RID_TRANSACTION_RELAXED)
15291     this_in |= TM_STMT_ATTR_RELAXED;
15292   else
15293     {
15294       attrs = c_parser_transaction_attributes (parser);
15295       if (attrs)
15296 	this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
15297     }
15298 
15299   /* Keep track if we're in the lexical scope of an outer transaction.  */
15300   new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
15301 
15302   parser->in_transaction = new_in;
15303   stmt = c_parser_compound_statement (parser);
15304   parser->in_transaction = old_in;
15305 
15306   if (flag_tm)
15307     stmt = c_finish_transaction (loc, stmt, this_in);
15308   else
15309     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15310 	"%<__transaction_atomic%> without transactional memory support enabled"
15311 	: "%<__transaction_relaxed %> "
15312 	"without transactional memory support enabled"));
15313 
15314   return stmt;
15315 }
15316 
15317 /* Parse a __transaction_atomic or __transaction_relaxed expression
15318    (GCC Extension).
15319 
15320    transaction-expression:
15321      __transaction_atomic ( expression )
15322      __transaction_relaxed ( expression )
15323 */
15324 
15325 static struct c_expr
15326 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
15327 {
15328   struct c_expr ret;
15329   unsigned int old_in = parser->in_transaction;
15330   unsigned int this_in = 1;
15331   location_t loc = c_parser_peek_token (parser)->location;
15332   tree attrs;
15333 
15334   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15335       || keyword == RID_TRANSACTION_RELAXED)
15336       && c_parser_next_token_is_keyword (parser, keyword));
15337   c_parser_consume_token (parser);
15338 
15339   if (keyword == RID_TRANSACTION_RELAXED)
15340     this_in |= TM_STMT_ATTR_RELAXED;
15341   else
15342     {
15343       attrs = c_parser_transaction_attributes (parser);
15344       if (attrs)
15345 	this_in |= parse_tm_stmt_attr (attrs, 0);
15346     }
15347 
15348   parser->in_transaction = this_in;
15349   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15350     {
15351       tree expr = c_parser_expression (parser).value;
15352       ret.original_type = TREE_TYPE (expr);
15353       ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
15354       if (this_in & TM_STMT_ATTR_RELAXED)
15355 	TRANSACTION_EXPR_RELAXED (ret.value) = 1;
15356       SET_EXPR_LOCATION (ret.value, loc);
15357       ret.original_code = TRANSACTION_EXPR;
15358       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
15359 	{
15360 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
15361 	  goto error;
15362 	}
15363     }
15364   else
15365     {
15366      error:
15367       ret.value = error_mark_node;
15368       ret.original_code = ERROR_MARK;
15369       ret.original_type = NULL;
15370     }
15371   parser->in_transaction = old_in;
15372 
15373   if (!flag_tm)
15374     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15375 	"%<__transaction_atomic%> without transactional memory support enabled"
15376 	: "%<__transaction_relaxed %> "
15377 	"without transactional memory support enabled"));
15378 
15379   return ret;
15380 }
15381 
15382 /* Parse a __transaction_cancel statement (GCC Extension).
15383 
15384    transaction-cancel-statement:
15385      __transaction_cancel transaction-attribute[opt] ;
15386 
15387    Note that the only valid attribute is "outer".
15388 */
15389 
15390 static tree
15391 c_parser_transaction_cancel (c_parser *parser)
15392 {
15393   location_t loc = c_parser_peek_token (parser)->location;
15394   tree attrs;
15395   bool is_outer = false;
15396 
15397   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
15398   c_parser_consume_token (parser);
15399 
15400   attrs = c_parser_transaction_attributes (parser);
15401   if (attrs)
15402     is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
15403 
15404   if (!flag_tm)
15405     {
15406       error_at (loc, "%<__transaction_cancel%> without "
15407 		"transactional memory support enabled");
15408       goto ret_error;
15409     }
15410   else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
15411     {
15412       error_at (loc, "%<__transaction_cancel%> within a "
15413 		"%<__transaction_relaxed%>");
15414       goto ret_error;
15415     }
15416   else if (is_outer)
15417     {
15418       if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
15419 	  && !is_tm_may_cancel_outer (current_function_decl))
15420 	{
15421 	  error_at (loc, "outer %<__transaction_cancel%> not "
15422 		    "within outer %<__transaction_atomic%>");
15423 	  error_at (loc, "  or a %<transaction_may_cancel_outer%> function");
15424 	  goto ret_error;
15425 	}
15426     }
15427   else if (parser->in_transaction == 0)
15428     {
15429       error_at (loc, "%<__transaction_cancel%> not within "
15430 		"%<__transaction_atomic%>");
15431       goto ret_error;
15432     }
15433 
15434   return add_stmt (build_tm_abort_call (loc, is_outer));
15435 
15436  ret_error:
15437   return build1 (NOP_EXPR, void_type_node, error_mark_node);
15438 }
15439 
15440 /* Parse a single source file.  */
15441 
15442 void
15443 c_parse_file (void)
15444 {
15445   /* Use local storage to begin.  If the first token is a pragma, parse it.
15446      If it is #pragma GCC pch_preprocess, then this will load a PCH file
15447      which will cause garbage collection.  */
15448   c_parser tparser;
15449 
15450   memset (&tparser, 0, sizeof tparser);
15451   tparser.tokens = &tparser.tokens_buf[0];
15452   the_parser = &tparser;
15453 
15454   if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
15455     c_parser_pragma_pch_preprocess (&tparser);
15456 
15457   the_parser = ggc_alloc<c_parser> ();
15458   *the_parser = tparser;
15459   if (tparser.tokens == &tparser.tokens_buf[0])
15460     the_parser->tokens = &the_parser->tokens_buf[0];
15461 
15462   /* Initialize EH, if we've been told to do so.  */
15463   if (flag_exceptions)
15464     using_eh_for_cleanups ();
15465 
15466   c_parser_translation_unit (the_parser);
15467   the_parser = NULL;
15468 }
15469 
15470 /* This function parses Cilk Plus array notation.  The starting index is
15471    passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE.  The
15472    return value of this function is a tree_node called VALUE_TREE of type
15473    ARRAY_NOTATION_REF.  */
15474 
15475 static tree
15476 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
15477 			 tree array_value)
15478 {
15479   c_token *token = NULL;
15480   tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE;
15481   tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE;
15482   tree array_type_domain = NULL_TREE;
15483 
15484   if (array_value == error_mark_node || initial_index == error_mark_node)
15485     {
15486       /* No need to continue.  If either of these 2 were true, then an error
15487 	 must be emitted already.  Thus, no need to emit them twice.  */
15488       c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15489       return error_mark_node;
15490     }
15491 
15492   array_type = TREE_TYPE (array_value);
15493   gcc_assert (array_type);
15494   if (TREE_CODE (array_type) != ARRAY_TYPE
15495       && TREE_CODE (array_type) != POINTER_TYPE)
15496     {
15497       error_at (loc, "base of array section must be pointer or array type");
15498       c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15499       return error_mark_node;
15500     }
15501   type = TREE_TYPE (array_type);
15502   token = c_parser_peek_token (parser);
15503 
15504   if (token->type == CPP_EOF)
15505     {
15506       c_parser_error (parser, "expected %<:%> or numeral");
15507       return value_tree;
15508     }
15509   else if (token->type == CPP_COLON)
15510     {
15511       if (!initial_index)
15512 	{
15513 	  /* If we are here, then we have a case like this A[:].  */
15514 	  c_parser_consume_token (parser);
15515 	  if (TREE_CODE (array_type) == POINTER_TYPE)
15516 	    {
15517 	      error_at (loc, "start-index and length fields necessary for "
15518 			"using array notations in pointers");
15519 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15520 	      return error_mark_node;
15521 	    }
15522 	  if (TREE_CODE (array_type) == FUNCTION_TYPE)
15523 	    {
15524 	      error_at (loc, "array notations cannot be used with function "
15525 			"type");
15526 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15527 	      return error_mark_node;
15528 	    }
15529 	  array_type_domain = TYPE_DOMAIN (array_type);
15530 
15531 	  if (!array_type_domain)
15532 	    {
15533 	      error_at (loc, "start-index and length fields necessary for "
15534 			"using array notations in dimensionless arrays");
15535 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15536 	      return error_mark_node;
15537 	    }
15538 
15539 	  start_index = TYPE_MINVAL (array_type_domain);
15540 	  start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node,
15541 				     start_index);
15542 	  if (!TYPE_MAXVAL (array_type_domain)
15543 	      || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain)))
15544 	    {
15545 	      error_at (loc, "start-index and length fields necessary for "
15546 			"using array notations in variable-length arrays");
15547 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15548 	      return error_mark_node;
15549 	    }
15550 	  end_index = TYPE_MAXVAL (array_type_domain);
15551 	  end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index),
15552 				   end_index, integer_one_node);
15553 	  end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index);
15554 	  stride = build_int_cst (integer_type_node, 1);
15555 	  stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride);
15556 	}
15557       else if (initial_index != error_mark_node)
15558 	{
15559 	  /* If we are here, then there should be 2 possibilities:
15560 	     1. Array [EXPR : EXPR]
15561 	     2. Array [EXPR : EXPR : EXPR]
15562 	  */
15563 	  start_index = initial_index;
15564 
15565 	  if (TREE_CODE (array_type) == FUNCTION_TYPE)
15566 	    {
15567 	      error_at (loc, "array notations cannot be used with function "
15568 			"type");
15569 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15570 	      return error_mark_node;
15571 	    }
15572 	  c_parser_consume_token (parser); /* consume the ':' */
15573 	  struct c_expr ce = c_parser_expression (parser);
15574 	  ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15575 	  end_index = ce.value;
15576 	  if (!end_index || end_index == error_mark_node)
15577 	    {
15578 	      c_parser_skip_to_end_of_block_or_statement (parser);
15579 	      return error_mark_node;
15580 	    }
15581 	  if (c_parser_peek_token (parser)->type == CPP_COLON)
15582 	    {
15583 	      c_parser_consume_token (parser);
15584 	      ce = c_parser_expression (parser);
15585 	      ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15586 	      stride = ce.value;
15587 	      if (!stride || stride == error_mark_node)
15588 		{
15589 		  c_parser_skip_to_end_of_block_or_statement (parser);
15590 		  return error_mark_node;
15591 		}
15592 	    }
15593 	}
15594       else
15595 	c_parser_error (parser, "expected array notation expression");
15596     }
15597   else
15598     c_parser_error (parser, "expected array notation expression");
15599 
15600   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15601 
15602   value_tree = build_array_notation_ref (loc, array_value, start_index,
15603 					 end_index, stride, type);
15604   if (value_tree != error_mark_node)
15605     SET_EXPR_LOCATION (value_tree, loc);
15606   return value_tree;
15607 }
15608 
15609 #include "gt-c-c-parser.h"
15610