xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/c/c-parser.c (revision cef8759bd76c1b621f8eab8faa6f208faabc2e15)
1 /* Parser for C and Objective-C.
2    Copyright (C) 1987-2017 Free Software Foundation, Inc.
3 
4    Parser actions based on the old Bison parser; structure somewhat
5    influenced by and fragments based on the C++ parser.
6 
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 "target.h"
42 #include "function.h"
43 #include "c-tree.h"
44 #include "timevar.h"
45 #include "stringpool.h"
46 #include "cgraph.h"
47 #include "attribs.h"
48 #include "stor-layout.h"
49 #include "varasm.h"
50 #include "trans-mem.h"
51 #include "c-family/c-pragma.h"
52 #include "c-lang.h"
53 #include "c-family/c-objc.h"
54 #include "plugin.h"
55 #include "omp-general.h"
56 #include "omp-offload.h"
57 #include "builtins.h"
58 #include "gomp-constants.h"
59 #include "c-family/c-indentation.h"
60 #include "gimple-expr.h"
61 #include "context.h"
62 #include "gcc-rich-location.h"
63 #include "c-parser.h"
64 #include "gimple-parser.h"
65 #include "read-rtl-function.h"
66 #include "run-rtl-passes.h"
67 #include "intl.h"
68 
69 /* We need to walk over decls with incomplete struct/union/enum types
70    after parsing the whole translation unit.
71    In finish_decl(), if the decl is static, has incomplete
72    struct/union/enum type, it is appeneded to incomplete_record_decls.
73    In c_parser_translation_unit(), we iterate over incomplete_record_decls
74    and report error if any of the decls are still incomplete.  */
75 
76 vec<tree> incomplete_record_decls;
77 
78 void
79 set_c_expr_source_range (c_expr *expr,
80 			 location_t start, location_t finish)
81 {
82   expr->src_range.m_start = start;
83   expr->src_range.m_finish = finish;
84   if (expr->value)
85     set_source_range (expr->value, start, finish);
86 }
87 
88 void
89 set_c_expr_source_range (c_expr *expr,
90 			 source_range src_range)
91 {
92   expr->src_range = src_range;
93   if (expr->value)
94     set_source_range (expr->value, src_range);
95 }
96 
97 
98 /* Initialization routine for this file.  */
99 
100 void
101 c_parse_init (void)
102 {
103   /* The only initialization required is of the reserved word
104      identifiers.  */
105   unsigned int i;
106   tree id;
107   int mask = 0;
108 
109   /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
110      the c_token structure.  */
111   gcc_assert (RID_MAX <= 255);
112 
113   mask |= D_CXXONLY;
114   if (!flag_isoc99)
115     mask |= D_C99;
116   if (flag_no_asm)
117     {
118       mask |= D_ASM | D_EXT;
119       if (!flag_isoc99)
120 	mask |= D_EXT89;
121     }
122   if (!c_dialect_objc ())
123     mask |= D_OBJC | D_CXX_OBJC;
124 
125   ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
126   for (i = 0; i < num_c_common_reswords; i++)
127     {
128       /* If a keyword is disabled, do not enter it into the table
129 	 and so create a canonical spelling that isn't a keyword.  */
130       if (c_common_reswords[i].disable & mask)
131 	{
132 	  if (warn_cxx_compat
133 	      && (c_common_reswords[i].disable & D_CXXWARN))
134 	    {
135 	      id = get_identifier (c_common_reswords[i].word);
136 	      C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
137 	      C_IS_RESERVED_WORD (id) = 1;
138 	    }
139 	  continue;
140 	}
141 
142       id = get_identifier (c_common_reswords[i].word);
143       C_SET_RID_CODE (id, c_common_reswords[i].rid);
144       C_IS_RESERVED_WORD (id) = 1;
145       ridpointers [(int) c_common_reswords[i].rid] = id;
146     }
147 
148   for (i = 0; i < NUM_INT_N_ENTS; i++)
149     {
150       /* We always create the symbols but they aren't always supported.  */
151       char name[50];
152       sprintf (name, "__int%d", int_n_data[i].bitsize);
153       id = get_identifier (name);
154       C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
155       C_IS_RESERVED_WORD (id) = 1;
156     }
157 }
158 
159 /* A parser structure recording information about the state and
160    context of parsing.  Includes lexer information with up to two
161    tokens of look-ahead; more are not needed for C.  */
162 struct GTY(()) c_parser {
163   /* The look-ahead tokens.  */
164   c_token * GTY((skip)) tokens;
165   /* Buffer for look-ahead tokens.  */
166   c_token tokens_buf[4];
167   /* How many look-ahead tokens are available (0 - 4, or
168      more if parsing from pre-lexed tokens).  */
169   unsigned int tokens_avail;
170   /* True if a syntax error is being recovered from; false otherwise.
171      c_parser_error sets this flag.  It should clear this flag when
172      enough tokens have been consumed to recover from the error.  */
173   BOOL_BITFIELD error : 1;
174   /* True if we're processing a pragma, and shouldn't automatically
175      consume CPP_PRAGMA_EOL.  */
176   BOOL_BITFIELD in_pragma : 1;
177   /* True if we're parsing the outermost block of an if statement.  */
178   BOOL_BITFIELD in_if_block : 1;
179   /* True if we want to lex an untranslated string.  */
180   BOOL_BITFIELD lex_untranslated_string : 1;
181 
182   /* Objective-C specific parser/lexer information.  */
183 
184   /* True if we are in a context where the Objective-C "PQ" keywords
185      are considered keywords.  */
186   BOOL_BITFIELD objc_pq_context : 1;
187   /* True if we are parsing a (potential) Objective-C foreach
188      statement.  This is set to true after we parsed 'for (' and while
189      we wait for 'in' or ';' to decide if it's a standard C for loop or an
190      Objective-C foreach loop.  */
191   BOOL_BITFIELD objc_could_be_foreach_context : 1;
192   /* The following flag is needed to contextualize Objective-C lexical
193      analysis.  In some cases (e.g., 'int NSObject;'), it is
194      undesirable to bind an identifier to an Objective-C class, even
195      if a class with that name exists.  */
196   BOOL_BITFIELD objc_need_raw_identifier : 1;
197   /* Nonzero if we're processing a __transaction statement.  The value
198      is 1 | TM_STMT_ATTR_*.  */
199   unsigned int in_transaction : 4;
200   /* True if we are in a context where the Objective-C "Property attribute"
201      keywords are valid.  */
202   BOOL_BITFIELD objc_property_attr_context : 1;
203 
204   /* Cilk Plus specific parser/lexer information.  */
205 
206   /* Buffer to hold all the tokens from parsing the vector attribute for the
207      SIMD-enabled functions (formerly known as elemental functions).  */
208   vec <c_token, va_gc> *cilk_simd_fn_tokens;
209 };
210 
211 /* Return a pointer to the Nth token in PARSERs tokens_buf.  */
212 
213 c_token *
214 c_parser_tokens_buf (c_parser *parser, unsigned n)
215 {
216   return &parser->tokens_buf[n];
217 }
218 
219 /* Return the error state of PARSER.  */
220 
221 bool
222 c_parser_error (c_parser *parser)
223 {
224   return parser->error;
225 }
226 
227 /* Set the error state of PARSER to ERR.  */
228 
229 void
230 c_parser_set_error (c_parser *parser, bool err)
231 {
232   parser->error = err;
233 }
234 
235 
236 /* The actual parser and external interface.  ??? Does this need to be
237    garbage-collected?  */
238 
239 static GTY (()) c_parser *the_parser;
240 
241 /* Read in and lex a single token, storing it in *TOKEN.  */
242 
243 static void
244 c_lex_one_token (c_parser *parser, c_token *token)
245 {
246   timevar_push (TV_LEX);
247 
248   token->type = c_lex_with_flags (&token->value, &token->location,
249 				  &token->flags,
250 				  (parser->lex_untranslated_string
251 				   ? C_LEX_STRING_NO_TRANSLATE : 0));
252   token->id_kind = C_ID_NONE;
253   token->keyword = RID_MAX;
254   token->pragma_kind = PRAGMA_NONE;
255 
256   switch (token->type)
257     {
258     case CPP_NAME:
259       {
260 	tree decl;
261 
262 	bool objc_force_identifier = parser->objc_need_raw_identifier;
263 	if (c_dialect_objc ())
264 	  parser->objc_need_raw_identifier = false;
265 
266 	if (C_IS_RESERVED_WORD (token->value))
267 	  {
268 	    enum rid rid_code = C_RID_CODE (token->value);
269 
270 	    if (rid_code == RID_CXX_COMPAT_WARN)
271 	      {
272 		warning_at (token->location,
273 			    OPT_Wc___compat,
274 			    "identifier %qE conflicts with C++ keyword",
275 			    token->value);
276 	      }
277 	    else if (rid_code >= RID_FIRST_ADDR_SPACE
278 		     && rid_code <= RID_LAST_ADDR_SPACE)
279 	      {
280 		addr_space_t as;
281 		as = (addr_space_t) (rid_code - RID_FIRST_ADDR_SPACE);
282 		targetm.addr_space.diagnose_usage (as, token->location);
283 		token->id_kind = C_ID_ADDRSPACE;
284 		token->keyword = rid_code;
285 		break;
286 	      }
287 	    else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
288 	      {
289 		/* We found an Objective-C "pq" keyword (in, out,
290 		   inout, bycopy, byref, oneway).  They need special
291 		   care because the interpretation depends on the
292 		   context.  */
293 		if (parser->objc_pq_context)
294 		  {
295 		    token->type = CPP_KEYWORD;
296 		    token->keyword = rid_code;
297 		    break;
298 		  }
299 		else if (parser->objc_could_be_foreach_context
300 			 && rid_code == RID_IN)
301 		  {
302 		    /* We are in Objective-C, inside a (potential)
303 		       foreach context (which means after having
304 		       parsed 'for (', but before having parsed ';'),
305 		       and we found 'in'.  We consider it the keyword
306 		       which terminates the declaration at the
307 		       beginning of a foreach-statement.  Note that
308 		       this means you can't use 'in' for anything else
309 		       in that context; in particular, in Objective-C
310 		       you can't use 'in' as the name of the running
311 		       variable in a C for loop.  We could potentially
312 		       try to add code here to disambiguate, but it
313 		       seems a reasonable limitation.  */
314 		    token->type = CPP_KEYWORD;
315 		    token->keyword = rid_code;
316 		    break;
317 		  }
318 		/* Else, "pq" keywords outside of the "pq" context are
319 		   not keywords, and we fall through to the code for
320 		   normal tokens.  */
321 	      }
322 	    else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
323 	      {
324 		/* We found an Objective-C "property attribute"
325 		   keyword (getter, setter, readonly, etc). These are
326 		   only valid in the property context.  */
327 		if (parser->objc_property_attr_context)
328 		  {
329 		    token->type = CPP_KEYWORD;
330 		    token->keyword = rid_code;
331 		    break;
332 		  }
333 		/* Else they are not special keywords.
334 		*/
335 	      }
336 	    else if (c_dialect_objc ()
337 		     && (OBJC_IS_AT_KEYWORD (rid_code)
338 			 || OBJC_IS_CXX_KEYWORD (rid_code)))
339 	      {
340 		/* We found one of the Objective-C "@" keywords (defs,
341 		   selector, synchronized, etc) or one of the
342 		   Objective-C "cxx" keywords (class, private,
343 		   protected, public, try, catch, throw) without a
344 		   preceding '@' sign.  Do nothing and fall through to
345 		   the code for normal tokens (in C++ we would still
346 		   consider the CXX ones keywords, but not in C).  */
347 		;
348 	      }
349 	    else
350 	      {
351 		token->type = CPP_KEYWORD;
352 		token->keyword = rid_code;
353 		break;
354 	      }
355 	  }
356 
357 	decl = lookup_name (token->value);
358 	if (decl)
359 	  {
360 	    if (TREE_CODE (decl) == TYPE_DECL)
361 	      {
362 		token->id_kind = C_ID_TYPENAME;
363 		break;
364 	      }
365 	  }
366 	else if (c_dialect_objc ())
367 	  {
368 	    tree objc_interface_decl = objc_is_class_name (token->value);
369 	    /* Objective-C class names are in the same namespace as
370 	       variables and typedefs, and hence are shadowed by local
371 	       declarations.  */
372 	    if (objc_interface_decl
373                 && (!objc_force_identifier || global_bindings_p ()))
374 	      {
375 		token->value = objc_interface_decl;
376 		token->id_kind = C_ID_CLASSNAME;
377 		break;
378 	      }
379 	  }
380         token->id_kind = C_ID_ID;
381       }
382       break;
383     case CPP_AT_NAME:
384       /* This only happens in Objective-C; it must be a keyword.  */
385       token->type = CPP_KEYWORD;
386       switch (C_RID_CODE (token->value))
387 	{
388 	  /* Replace 'class' with '@class', 'private' with '@private',
389 	     etc.  This prevents confusion with the C++ keyword
390 	     'class', and makes the tokens consistent with other
391 	     Objective-C 'AT' keywords.  For example '@class' is
392 	     reported as RID_AT_CLASS which is consistent with
393 	     '@synchronized', which is reported as
394 	     RID_AT_SYNCHRONIZED.
395 	  */
396 	case RID_CLASS:     token->keyword = RID_AT_CLASS; break;
397 	case RID_PRIVATE:   token->keyword = RID_AT_PRIVATE; break;
398 	case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
399 	case RID_PUBLIC:    token->keyword = RID_AT_PUBLIC; break;
400 	case RID_THROW:     token->keyword = RID_AT_THROW; break;
401 	case RID_TRY:       token->keyword = RID_AT_TRY; break;
402 	case RID_CATCH:     token->keyword = RID_AT_CATCH; break;
403 	case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break;
404 	default:            token->keyword = C_RID_CODE (token->value);
405 	}
406       break;
407     case CPP_COLON:
408     case CPP_COMMA:
409     case CPP_CLOSE_PAREN:
410     case CPP_SEMICOLON:
411       /* These tokens may affect the interpretation of any identifiers
412 	 following, if doing Objective-C.  */
413       if (c_dialect_objc ())
414 	parser->objc_need_raw_identifier = false;
415       break;
416     case CPP_PRAGMA:
417       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
418       token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
419       token->value = NULL;
420       break;
421     default:
422       break;
423     }
424   timevar_pop (TV_LEX);
425 }
426 
427 /* Return a pointer to the next token from PARSER, reading it in if
428    necessary.  */
429 
430 c_token *
431 c_parser_peek_token (c_parser *parser)
432 {
433   if (parser->tokens_avail == 0)
434     {
435       c_lex_one_token (parser, &parser->tokens[0]);
436       parser->tokens_avail = 1;
437     }
438   return &parser->tokens[0];
439 }
440 
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442    in if necessary.  The next token is already read in.  */
443 
444 c_token *
445 c_parser_peek_2nd_token (c_parser *parser)
446 {
447   if (parser->tokens_avail >= 2)
448     return &parser->tokens[1];
449   gcc_assert (parser->tokens_avail == 1);
450   gcc_assert (parser->tokens[0].type != CPP_EOF);
451   gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
452   c_lex_one_token (parser, &parser->tokens[1]);
453   parser->tokens_avail = 2;
454   return &parser->tokens[1];
455 }
456 
457 /* Return a pointer to the Nth token from PARSER, reading it
458    in if necessary.  The N-1th token is already read in.  */
459 
460 c_token *
461 c_parser_peek_nth_token (c_parser *parser, unsigned int n)
462 {
463   /* N is 1-based, not zero-based.  */
464   gcc_assert (n > 0);
465 
466   if (parser->tokens_avail >= n)
467     return &parser->tokens[n - 1];
468   gcc_assert (parser->tokens_avail == n - 1);
469   c_lex_one_token (parser, &parser->tokens[n - 1]);
470   parser->tokens_avail = n;
471   return &parser->tokens[n - 1];
472 }
473 
474 bool
475 c_keyword_starts_typename (enum rid keyword)
476 {
477   switch (keyword)
478     {
479     case RID_UNSIGNED:
480     case RID_LONG:
481     case RID_SHORT:
482     case RID_SIGNED:
483     case RID_COMPLEX:
484     case RID_INT:
485     case RID_CHAR:
486     case RID_FLOAT:
487     case RID_DOUBLE:
488     case RID_VOID:
489     case RID_DFLOAT32:
490     case RID_DFLOAT64:
491     case RID_DFLOAT128:
492     CASE_RID_FLOATN_NX:
493     case RID_BOOL:
494     case RID_ENUM:
495     case RID_STRUCT:
496     case RID_UNION:
497     case RID_TYPEOF:
498     case RID_CONST:
499     case RID_ATOMIC:
500     case RID_VOLATILE:
501     case RID_RESTRICT:
502     case RID_ATTRIBUTE:
503     case RID_FRACT:
504     case RID_ACCUM:
505     case RID_SAT:
506     case RID_AUTO_TYPE:
507       return true;
508     default:
509       if (keyword >= RID_FIRST_INT_N
510 	  && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
511 	  && int_n_enabled_p[keyword - RID_FIRST_INT_N])
512 	return true;
513       return false;
514     }
515 }
516 
517 /* Return true if TOKEN can start a type name,
518    false otherwise.  */
519 bool
520 c_token_starts_typename (c_token *token)
521 {
522   switch (token->type)
523     {
524     case CPP_NAME:
525       switch (token->id_kind)
526 	{
527 	case C_ID_ID:
528 	  return false;
529 	case C_ID_ADDRSPACE:
530 	  return true;
531 	case C_ID_TYPENAME:
532 	  return true;
533 	case C_ID_CLASSNAME:
534 	  gcc_assert (c_dialect_objc ());
535 	  return true;
536 	default:
537 	  gcc_unreachable ();
538 	}
539     case CPP_KEYWORD:
540       return c_keyword_starts_typename (token->keyword);
541     case CPP_LESS:
542       if (c_dialect_objc ())
543 	return true;
544       return false;
545     default:
546       return false;
547     }
548 }
549 
550 /* Return true if the next token from PARSER can start a type name,
551    false otherwise.  LA specifies how to do lookahead in order to
552    detect unknown type names.  If unsure, pick CLA_PREFER_ID.  */
553 
554 static inline bool
555 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
556 {
557   c_token *token = c_parser_peek_token (parser);
558   if (c_token_starts_typename (token))
559     return true;
560 
561   /* Try a bit harder to detect an unknown typename.  */
562   if (la != cla_prefer_id
563       && token->type == CPP_NAME
564       && token->id_kind == C_ID_ID
565 
566       /* Do not try too hard when we could have "object in array".  */
567       && !parser->objc_could_be_foreach_context
568 
569       && (la == cla_prefer_type
570 	  || c_parser_peek_2nd_token (parser)->type == CPP_NAME
571 	  || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
572 
573       /* Only unknown identifiers.  */
574       && !lookup_name (token->value))
575     return true;
576 
577   return false;
578 }
579 
580 /* Return true if TOKEN is a type qualifier, false otherwise.  */
581 static bool
582 c_token_is_qualifier (c_token *token)
583 {
584   switch (token->type)
585     {
586     case CPP_NAME:
587       switch (token->id_kind)
588 	{
589 	case C_ID_ADDRSPACE:
590 	  return true;
591 	default:
592 	  return false;
593 	}
594     case CPP_KEYWORD:
595       switch (token->keyword)
596 	{
597 	case RID_CONST:
598 	case RID_VOLATILE:
599 	case RID_RESTRICT:
600 	case RID_ATTRIBUTE:
601 	case RID_ATOMIC:
602 	  return true;
603 	default:
604 	  return false;
605 	}
606     case CPP_LESS:
607       return false;
608     default:
609       gcc_unreachable ();
610     }
611 }
612 
613 /* Return true if the next token from PARSER is a type qualifier,
614    false otherwise.  */
615 static inline bool
616 c_parser_next_token_is_qualifier (c_parser *parser)
617 {
618   c_token *token = c_parser_peek_token (parser);
619   return c_token_is_qualifier (token);
620 }
621 
622 /* Return true if TOKEN can start declaration specifiers, false
623    otherwise.  */
624 static bool
625 c_token_starts_declspecs (c_token *token)
626 {
627   switch (token->type)
628     {
629     case CPP_NAME:
630       switch (token->id_kind)
631 	{
632 	case C_ID_ID:
633 	  return false;
634 	case C_ID_ADDRSPACE:
635 	  return true;
636 	case C_ID_TYPENAME:
637 	  return true;
638 	case C_ID_CLASSNAME:
639 	  gcc_assert (c_dialect_objc ());
640 	  return true;
641 	default:
642 	  gcc_unreachable ();
643 	}
644     case CPP_KEYWORD:
645       switch (token->keyword)
646 	{
647 	case RID_STATIC:
648 	case RID_EXTERN:
649 	case RID_REGISTER:
650 	case RID_TYPEDEF:
651 	case RID_INLINE:
652 	case RID_NORETURN:
653 	case RID_AUTO:
654 	case RID_THREAD:
655 	case RID_UNSIGNED:
656 	case RID_LONG:
657 	case RID_SHORT:
658 	case RID_SIGNED:
659 	case RID_COMPLEX:
660 	case RID_INT:
661 	case RID_CHAR:
662 	case RID_FLOAT:
663 	case RID_DOUBLE:
664 	case RID_VOID:
665 	case RID_DFLOAT32:
666 	case RID_DFLOAT64:
667 	case RID_DFLOAT128:
668 	CASE_RID_FLOATN_NX:
669 	case RID_BOOL:
670 	case RID_ENUM:
671 	case RID_STRUCT:
672 	case RID_UNION:
673 	case RID_TYPEOF:
674 	case RID_CONST:
675 	case RID_VOLATILE:
676 	case RID_RESTRICT:
677 	case RID_ATTRIBUTE:
678 	case RID_FRACT:
679 	case RID_ACCUM:
680 	case RID_SAT:
681 	case RID_ALIGNAS:
682 	case RID_ATOMIC:
683 	case RID_AUTO_TYPE:
684 	  return true;
685 	default:
686 	  if (token->keyword >= RID_FIRST_INT_N
687 	      && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
688 	      && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
689 	    return true;
690 	  return false;
691 	}
692     case CPP_LESS:
693       if (c_dialect_objc ())
694 	return true;
695       return false;
696     default:
697       return false;
698     }
699 }
700 
701 
702 /* Return true if TOKEN can start declaration specifiers or a static
703    assertion, false otherwise.  */
704 static bool
705 c_token_starts_declaration (c_token *token)
706 {
707   if (c_token_starts_declspecs (token)
708       || token->keyword == RID_STATIC_ASSERT)
709     return true;
710   else
711     return false;
712 }
713 
714 /* Return true if the next token from PARSER can start declaration
715    specifiers, false otherwise.  */
716 bool
717 c_parser_next_token_starts_declspecs (c_parser *parser)
718 {
719   c_token *token = c_parser_peek_token (parser);
720 
721   /* In Objective-C, a classname normally starts a declspecs unless it
722      is immediately followed by a dot.  In that case, it is the
723      Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
724      setter/getter on the class.  c_token_starts_declspecs() can't
725      differentiate between the two cases because it only checks the
726      current token, so we have a special check here.  */
727   if (c_dialect_objc ()
728       && token->type == CPP_NAME
729       && token->id_kind == C_ID_CLASSNAME
730       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
731     return false;
732 
733   return c_token_starts_declspecs (token);
734 }
735 
736 /* Return true if the next tokens from PARSER can start declaration
737    specifiers or a static assertion, false otherwise.  */
738 bool
739 c_parser_next_tokens_start_declaration (c_parser *parser)
740 {
741   c_token *token = c_parser_peek_token (parser);
742 
743   /* Same as above.  */
744   if (c_dialect_objc ()
745       && token->type == CPP_NAME
746       && token->id_kind == C_ID_CLASSNAME
747       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
748     return false;
749 
750   /* Labels do not start declarations.  */
751   if (token->type == CPP_NAME
752       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
753     return false;
754 
755   if (c_token_starts_declaration (token))
756     return true;
757 
758   if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
759     return true;
760 
761   return false;
762 }
763 
764 /* Consume the next token from PARSER.  */
765 
766 void
767 c_parser_consume_token (c_parser *parser)
768 {
769   gcc_assert (parser->tokens_avail >= 1);
770   gcc_assert (parser->tokens[0].type != CPP_EOF);
771   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
772   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
773   if (parser->tokens != &parser->tokens_buf[0])
774     parser->tokens++;
775   else if (parser->tokens_avail == 2)
776     parser->tokens[0] = parser->tokens[1];
777   parser->tokens_avail--;
778 }
779 
780 /* Expect the current token to be a #pragma.  Consume it and remember
781    that we've begun parsing a pragma.  */
782 
783 static void
784 c_parser_consume_pragma (c_parser *parser)
785 {
786   gcc_assert (!parser->in_pragma);
787   gcc_assert (parser->tokens_avail >= 1);
788   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
789   if (parser->tokens != &parser->tokens_buf[0])
790     parser->tokens++;
791   else if (parser->tokens_avail == 2)
792     parser->tokens[0] = parser->tokens[1];
793   parser->tokens_avail--;
794   parser->in_pragma = true;
795 }
796 
797 /* Update the global input_location from TOKEN.  */
798 static inline void
799 c_parser_set_source_position_from_token (c_token *token)
800 {
801   if (token->type != CPP_EOF)
802     {
803       input_location = token->location;
804     }
805 }
806 
807 /* Helper function for c_parser_error.
808    Having peeked a token of kind TOK1_KIND that might signify
809    a conflict marker, peek successor tokens to determine
810    if we actually do have a conflict marker.
811    Specifically, we consider a run of 7 '<', '=' or '>' characters
812    at the start of a line as a conflict marker.
813    These come through the lexer as three pairs and a single,
814    e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
815    If it returns true, *OUT_LOC is written to with the location/range
816    of the marker.  */
817 
818 static bool
819 c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind,
820 			       location_t *out_loc)
821 {
822   c_token *token2 = c_parser_peek_2nd_token (parser);
823   if (token2->type != tok1_kind)
824     return false;
825   c_token *token3 = c_parser_peek_nth_token (parser, 3);
826   if (token3->type != tok1_kind)
827     return false;
828   c_token *token4 = c_parser_peek_nth_token (parser, 4);
829   if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind))
830     return false;
831 
832   /* It must be at the start of the line.  */
833   location_t start_loc = c_parser_peek_token (parser)->location;
834   if (LOCATION_COLUMN (start_loc) != 1)
835     return false;
836 
837   /* We have a conflict marker.  Construct a location of the form:
838        <<<<<<<
839        ^~~~~~~
840      with start == caret, finishing at the end of the marker.  */
841   location_t finish_loc = get_finish (token4->location);
842   *out_loc = make_location (start_loc, start_loc, finish_loc);
843 
844   return true;
845 }
846 
847 /* Issue a diagnostic of the form
848       FILE:LINE: MESSAGE before TOKEN
849    where TOKEN is the next token in the input stream of PARSER.
850    MESSAGE (specified by the caller) is usually of the form "expected
851    OTHER-TOKEN".
852 
853    Do not issue a diagnostic if still recovering from an error.
854 
855    ??? This is taken from the C++ parser, but building up messages in
856    this way is not i18n-friendly and some other approach should be
857    used.  */
858 
859 void
860 c_parser_error (c_parser *parser, const char *gmsgid)
861 {
862   c_token *token = c_parser_peek_token (parser);
863   if (parser->error)
864     return;
865   parser->error = true;
866   if (!gmsgid)
867     return;
868 
869   /* If this is actually a conflict marker, report it as such.  */
870   if (token->type == CPP_LSHIFT
871       || token->type == CPP_RSHIFT
872       || token->type == CPP_EQ_EQ)
873     {
874       location_t loc;
875       if (c_parser_peek_conflict_marker (parser, token->type, &loc))
876 	{
877 	  error_at (loc, "version control conflict marker in file");
878 	  return;
879 	}
880     }
881 
882   /* This diagnostic makes more sense if it is tagged to the line of
883      the token we just peeked at.  */
884   c_parser_set_source_position_from_token (token);
885   c_parse_error (gmsgid,
886 		 /* Because c_parse_error does not understand
887 		    CPP_KEYWORD, keywords are treated like
888 		    identifiers.  */
889 		 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
890 		 /* ??? The C parser does not save the cpp flags of a
891 		    token, we need to pass 0 here and we will not get
892 		    the source spelling of some tokens but rather the
893 		    canonical spelling.  */
894 		 token->value, /*flags=*/0);
895 }
896 
897 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
898    issue the error MSGID.  If MSGID is NULL then a message has already
899    been produced and no message will be produced this time.  Returns
900    true if found, false otherwise.  */
901 
902 bool
903 c_parser_require (c_parser *parser,
904 		  enum cpp_ttype type,
905 		  const char *msgid)
906 {
907   if (c_parser_next_token_is (parser, type))
908     {
909       c_parser_consume_token (parser);
910       return true;
911     }
912   else
913     {
914       c_parser_error (parser, msgid);
915       return false;
916     }
917 }
918 
919 /* If the next token is the indicated keyword, consume it.  Otherwise,
920    issue the error MSGID.  Returns true if found, false otherwise.  */
921 
922 static bool
923 c_parser_require_keyword (c_parser *parser,
924 			  enum rid keyword,
925 			  const char *msgid)
926 {
927   if (c_parser_next_token_is_keyword (parser, keyword))
928     {
929       c_parser_consume_token (parser);
930       return true;
931     }
932   else
933     {
934       c_parser_error (parser, msgid);
935       return false;
936     }
937 }
938 
939 /* Like c_parser_require, except that tokens will be skipped until the
940    desired token is found.  An error message is still produced if the
941    next token is not as expected.  If MSGID is NULL then a message has
942    already been produced and no message will be produced this
943    time.  */
944 
945 void
946 c_parser_skip_until_found (c_parser *parser,
947 			   enum cpp_ttype type,
948 			   const char *msgid)
949 {
950   unsigned nesting_depth = 0;
951 
952   if (c_parser_require (parser, type, msgid))
953     return;
954 
955   /* Skip tokens until the desired token is found.  */
956   while (true)
957     {
958       /* Peek at the next token.  */
959       c_token *token = c_parser_peek_token (parser);
960       /* If we've reached the token we want, consume it and stop.  */
961       if (token->type == type && !nesting_depth)
962 	{
963 	  c_parser_consume_token (parser);
964 	  break;
965 	}
966 
967       /* If we've run out of tokens, stop.  */
968       if (token->type == CPP_EOF)
969 	return;
970       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
971 	return;
972       if (token->type == CPP_OPEN_BRACE
973 	  || token->type == CPP_OPEN_PAREN
974 	  || token->type == CPP_OPEN_SQUARE)
975 	++nesting_depth;
976       else if (token->type == CPP_CLOSE_BRACE
977 	       || token->type == CPP_CLOSE_PAREN
978 	       || token->type == CPP_CLOSE_SQUARE)
979 	{
980 	  if (nesting_depth-- == 0)
981 	    break;
982 	}
983       /* Consume this token.  */
984       c_parser_consume_token (parser);
985     }
986   parser->error = false;
987 }
988 
989 /* Skip tokens until the end of a parameter is found, but do not
990    consume the comma, semicolon or closing delimiter.  */
991 
992 static void
993 c_parser_skip_to_end_of_parameter (c_parser *parser)
994 {
995   unsigned nesting_depth = 0;
996 
997   while (true)
998     {
999       c_token *token = c_parser_peek_token (parser);
1000       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
1001 	  && !nesting_depth)
1002 	break;
1003       /* If we've run out of tokens, stop.  */
1004       if (token->type == CPP_EOF)
1005 	return;
1006       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1007 	return;
1008       if (token->type == CPP_OPEN_BRACE
1009 	  || token->type == CPP_OPEN_PAREN
1010 	  || token->type == CPP_OPEN_SQUARE)
1011 	++nesting_depth;
1012       else if (token->type == CPP_CLOSE_BRACE
1013 	       || token->type == CPP_CLOSE_PAREN
1014 	       || token->type == CPP_CLOSE_SQUARE)
1015 	{
1016 	  if (nesting_depth-- == 0)
1017 	    break;
1018 	}
1019       /* Consume this token.  */
1020       c_parser_consume_token (parser);
1021     }
1022   parser->error = false;
1023 }
1024 
1025 /* Expect to be at the end of the pragma directive and consume an
1026    end of line marker.  */
1027 
1028 static void
1029 c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
1030 {
1031   gcc_assert (parser->in_pragma);
1032   parser->in_pragma = false;
1033 
1034   if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
1035     c_parser_error (parser, "expected end of line");
1036 
1037   cpp_ttype token_type;
1038   do
1039     {
1040       c_token *token = c_parser_peek_token (parser);
1041       token_type = token->type;
1042       if (token_type == CPP_EOF)
1043 	break;
1044       c_parser_consume_token (parser);
1045     }
1046   while (token_type != CPP_PRAGMA_EOL);
1047 
1048   parser->error = false;
1049 }
1050 
1051 /* Skip tokens until we have consumed an entire block, or until we
1052    have consumed a non-nested ';'.  */
1053 
1054 static void
1055 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1056 {
1057   unsigned nesting_depth = 0;
1058   bool save_error = parser->error;
1059 
1060   while (true)
1061     {
1062       c_token *token;
1063 
1064       /* Peek at the next token.  */
1065       token = c_parser_peek_token (parser);
1066 
1067       switch (token->type)
1068 	{
1069 	case CPP_EOF:
1070 	  return;
1071 
1072 	case CPP_PRAGMA_EOL:
1073 	  if (parser->in_pragma)
1074 	    return;
1075 	  break;
1076 
1077 	case CPP_SEMICOLON:
1078 	  /* If the next token is a ';', we have reached the
1079 	     end of the statement.  */
1080 	  if (!nesting_depth)
1081 	    {
1082 	      /* Consume the ';'.  */
1083 	      c_parser_consume_token (parser);
1084 	      goto finished;
1085 	    }
1086 	  break;
1087 
1088 	case CPP_CLOSE_BRACE:
1089 	  /* If the next token is a non-nested '}', then we have
1090 	     reached the end of the current block.  */
1091 	  if (nesting_depth == 0 || --nesting_depth == 0)
1092 	    {
1093 	      c_parser_consume_token (parser);
1094 	      goto finished;
1095 	    }
1096 	  break;
1097 
1098 	case CPP_OPEN_BRACE:
1099 	  /* If it the next token is a '{', then we are entering a new
1100 	     block.  Consume the entire block.  */
1101 	  ++nesting_depth;
1102 	  break;
1103 
1104 	case CPP_PRAGMA:
1105 	  /* If we see a pragma, consume the whole thing at once.  We
1106 	     have some safeguards against consuming pragmas willy-nilly.
1107 	     Normally, we'd expect to be here with parser->error set,
1108 	     which disables these safeguards.  But it's possible to get
1109 	     here for secondary error recovery, after parser->error has
1110 	     been cleared.  */
1111 	  c_parser_consume_pragma (parser);
1112 	  c_parser_skip_to_pragma_eol (parser);
1113 	  parser->error = save_error;
1114 	  continue;
1115 
1116 	default:
1117 	  break;
1118 	}
1119 
1120       c_parser_consume_token (parser);
1121     }
1122 
1123  finished:
1124   parser->error = false;
1125 }
1126 
1127 /* CPP's options (initialized by c-opts.c).  */
1128 extern cpp_options *cpp_opts;
1129 
1130 /* Save the warning flags which are controlled by __extension__.  */
1131 
1132 static inline int
1133 disable_extension_diagnostics (void)
1134 {
1135   int ret = (pedantic
1136 	     | (warn_pointer_arith << 1)
1137 	     | (warn_traditional << 2)
1138 	     | (flag_iso << 3)
1139 	     | (warn_long_long << 4)
1140 	     | (warn_cxx_compat << 5)
1141 	     | (warn_overlength_strings << 6)
1142 	     /* warn_c90_c99_compat has three states: -1/0/1, so we must
1143 		play tricks to properly restore it.  */
1144 	     | ((warn_c90_c99_compat == 1) << 7)
1145 	     | ((warn_c90_c99_compat == -1) << 8)
1146 	     /* Similarly for warn_c99_c11_compat.  */
1147 	     | ((warn_c99_c11_compat == 1) << 9)
1148 	     | ((warn_c99_c11_compat == -1) << 10)
1149 	     );
1150   cpp_opts->cpp_pedantic = pedantic = 0;
1151   warn_pointer_arith = 0;
1152   cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1153   flag_iso = 0;
1154   cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1155   warn_cxx_compat = 0;
1156   warn_overlength_strings = 0;
1157   warn_c90_c99_compat = 0;
1158   warn_c99_c11_compat = 0;
1159   return ret;
1160 }
1161 
1162 /* Restore the warning flags which are controlled by __extension__.
1163    FLAGS is the return value from disable_extension_diagnostics.  */
1164 
1165 static inline void
1166 restore_extension_diagnostics (int flags)
1167 {
1168   cpp_opts->cpp_pedantic = pedantic = flags & 1;
1169   warn_pointer_arith = (flags >> 1) & 1;
1170   cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1171   flag_iso = (flags >> 3) & 1;
1172   cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1173   warn_cxx_compat = (flags >> 5) & 1;
1174   warn_overlength_strings = (flags >> 6) & 1;
1175   /* See above for why is this needed.  */
1176   warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1177   warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1178 }
1179 
1180 /* Helper data structure for parsing #pragma acc routine.  */
1181 struct oacc_routine_data {
1182   bool error_seen; /* Set if error has been reported.  */
1183   bool fndecl_seen; /* Set if one fn decl/definition has been seen already.  */
1184   tree clauses;
1185   location_t loc;
1186 };
1187 
1188 static void c_parser_external_declaration (c_parser *);
1189 static void c_parser_asm_definition (c_parser *);
1190 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1191 					   bool, bool, tree *, vec<c_token>,
1192 					   struct oacc_routine_data * = NULL,
1193 					   bool * = NULL);
1194 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1195 static void c_parser_static_assert_declaration (c_parser *);
1196 static struct c_typespec c_parser_enum_specifier (c_parser *);
1197 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1198 static tree c_parser_struct_declaration (c_parser *);
1199 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1200 static tree c_parser_alignas_specifier (c_parser *);
1201 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1202 							c_dtr_syn, bool *);
1203 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1204 							      bool,
1205 							      struct c_declarator *);
1206 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1207 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1208 							  tree);
1209 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1210 static tree c_parser_simple_asm_expr (c_parser *);
1211 static tree c_parser_attributes (c_parser *);
1212 static struct c_expr c_parser_initializer (c_parser *);
1213 static struct c_expr c_parser_braced_init (c_parser *, tree, bool,
1214 					   struct obstack *);
1215 static void c_parser_initelt (c_parser *, struct obstack *);
1216 static void c_parser_initval (c_parser *, struct c_expr *,
1217 			      struct obstack *);
1218 static tree c_parser_compound_statement (c_parser *);
1219 static void c_parser_compound_statement_nostart (c_parser *);
1220 static void c_parser_label (c_parser *);
1221 static void c_parser_statement (c_parser *, bool *);
1222 static void c_parser_statement_after_labels (c_parser *, bool *,
1223 					     vec<tree> * = NULL);
1224 static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
1225 static void c_parser_switch_statement (c_parser *, bool *);
1226 static void c_parser_while_statement (c_parser *, bool, bool *);
1227 static void c_parser_do_statement (c_parser *, bool);
1228 static void c_parser_for_statement (c_parser *, bool, bool *);
1229 static tree c_parser_asm_statement (c_parser *);
1230 static tree c_parser_asm_operands (c_parser *);
1231 static tree c_parser_asm_goto_operands (c_parser *);
1232 static tree c_parser_asm_clobbers (c_parser *);
1233 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1234 					      tree = NULL_TREE);
1235 static struct c_expr c_parser_conditional_expression (c_parser *,
1236 						      struct c_expr *, tree);
1237 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1238 						 tree);
1239 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1240 static struct c_expr c_parser_unary_expression (c_parser *);
1241 static struct c_expr c_parser_sizeof_expression (c_parser *);
1242 static struct c_expr c_parser_alignof_expression (c_parser *);
1243 static struct c_expr c_parser_postfix_expression (c_parser *);
1244 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1245 								   struct c_type_name *,
1246 								   location_t);
1247 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1248 								location_t loc,
1249 								struct c_expr);
1250 static tree c_parser_transaction (c_parser *, enum rid);
1251 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1252 static tree c_parser_transaction_cancel (c_parser *);
1253 static struct c_expr c_parser_expression (c_parser *);
1254 static struct c_expr c_parser_expression_conv (c_parser *);
1255 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1256 					     vec<tree, va_gc> **, location_t *,
1257 					     tree *, vec<location_t> *,
1258 					     unsigned int * = NULL);
1259 static void c_parser_oacc_declare (c_parser *);
1260 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1261 static void c_parser_oacc_update (c_parser *);
1262 static void c_parser_omp_construct (c_parser *, bool *);
1263 static void c_parser_omp_threadprivate (c_parser *);
1264 static void c_parser_omp_barrier (c_parser *);
1265 static void c_parser_omp_flush (c_parser *);
1266 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1267 				   tree, tree *, bool *);
1268 static void c_parser_omp_taskwait (c_parser *);
1269 static void c_parser_omp_taskyield (c_parser *);
1270 static void c_parser_omp_cancel (c_parser *);
1271 
1272 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1273 		      pragma_stmt, pragma_compound };
1274 static bool c_parser_pragma (c_parser *, enum pragma_context, bool *);
1275 static void c_parser_omp_cancellation_point (c_parser *, enum pragma_context);
1276 static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
1277 static void c_parser_omp_end_declare_target (c_parser *);
1278 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1279 static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
1280 static void c_parser_oacc_routine (c_parser *, enum pragma_context);
1281 
1282 /* These Objective-C parser functions are only ever called when
1283    compiling Objective-C.  */
1284 static void c_parser_objc_class_definition (c_parser *, tree);
1285 static void c_parser_objc_class_instance_variables (c_parser *);
1286 static void c_parser_objc_class_declaration (c_parser *);
1287 static void c_parser_objc_alias_declaration (c_parser *);
1288 static void c_parser_objc_protocol_definition (c_parser *, tree);
1289 static bool c_parser_objc_method_type (c_parser *);
1290 static void c_parser_objc_method_definition (c_parser *);
1291 static void c_parser_objc_methodprotolist (c_parser *);
1292 static void c_parser_objc_methodproto (c_parser *);
1293 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1294 static tree c_parser_objc_type_name (c_parser *);
1295 static tree c_parser_objc_protocol_refs (c_parser *);
1296 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1297 static void c_parser_objc_synchronized_statement (c_parser *);
1298 static tree c_parser_objc_selector (c_parser *);
1299 static tree c_parser_objc_selector_arg (c_parser *);
1300 static tree c_parser_objc_receiver (c_parser *);
1301 static tree c_parser_objc_message_args (c_parser *);
1302 static tree c_parser_objc_keywordexpr (c_parser *);
1303 static void c_parser_objc_at_property_declaration (c_parser *);
1304 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1305 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1306 static bool c_parser_objc_diagnose_bad_element_prefix
1307   (c_parser *, struct c_declspecs *);
1308 
1309 /* Cilk Plus supporting routines.  */
1310 static void c_parser_cilk_simd (c_parser *, bool *);
1311 static void c_parser_cilk_for (c_parser *, tree, bool *);
1312 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
1313 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
1314 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
1315 static void c_parser_cilk_grainsize (c_parser *, bool *);
1316 
1317 static void c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass);
1318 
1319 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1320 
1321    translation-unit:
1322      external-declarations
1323 
1324    external-declarations:
1325      external-declaration
1326      external-declarations external-declaration
1327 
1328    GNU extensions:
1329 
1330    translation-unit:
1331      empty
1332 */
1333 
1334 static void
1335 c_parser_translation_unit (c_parser *parser)
1336 {
1337   if (c_parser_next_token_is (parser, CPP_EOF))
1338     {
1339       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1340 	       "ISO C forbids an empty translation unit");
1341     }
1342   else
1343     {
1344       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1345       mark_valid_location_for_stdc_pragma (false);
1346       do
1347 	{
1348 	  ggc_collect ();
1349 	  c_parser_external_declaration (parser);
1350 	  obstack_free (&parser_obstack, obstack_position);
1351 	}
1352       while (c_parser_next_token_is_not (parser, CPP_EOF));
1353     }
1354 
1355   unsigned int i;
1356   tree decl;
1357   FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl)
1358     if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node)
1359       error ("storage size of %q+D isn%'t known", decl);
1360 }
1361 
1362 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1363 
1364    external-declaration:
1365      function-definition
1366      declaration
1367 
1368    GNU extensions:
1369 
1370    external-declaration:
1371      asm-definition
1372      ;
1373      __extension__ external-declaration
1374 
1375    Objective-C:
1376 
1377    external-declaration:
1378      objc-class-definition
1379      objc-class-declaration
1380      objc-alias-declaration
1381      objc-protocol-definition
1382      objc-method-definition
1383      @end
1384 */
1385 
1386 static void
1387 c_parser_external_declaration (c_parser *parser)
1388 {
1389   int ext;
1390   switch (c_parser_peek_token (parser)->type)
1391     {
1392     case CPP_KEYWORD:
1393       switch (c_parser_peek_token (parser)->keyword)
1394 	{
1395 	case RID_EXTENSION:
1396 	  ext = disable_extension_diagnostics ();
1397 	  c_parser_consume_token (parser);
1398 	  c_parser_external_declaration (parser);
1399 	  restore_extension_diagnostics (ext);
1400 	  break;
1401 	case RID_ASM:
1402 	  c_parser_asm_definition (parser);
1403 	  break;
1404 	case RID_AT_INTERFACE:
1405 	case RID_AT_IMPLEMENTATION:
1406 	  gcc_assert (c_dialect_objc ());
1407 	  c_parser_objc_class_definition (parser, NULL_TREE);
1408 	  break;
1409 	case RID_AT_CLASS:
1410 	  gcc_assert (c_dialect_objc ());
1411 	  c_parser_objc_class_declaration (parser);
1412 	  break;
1413 	case RID_AT_ALIAS:
1414 	  gcc_assert (c_dialect_objc ());
1415 	  c_parser_objc_alias_declaration (parser);
1416 	  break;
1417 	case RID_AT_PROTOCOL:
1418 	  gcc_assert (c_dialect_objc ());
1419 	  c_parser_objc_protocol_definition (parser, NULL_TREE);
1420 	  break;
1421 	case RID_AT_PROPERTY:
1422 	  gcc_assert (c_dialect_objc ());
1423 	  c_parser_objc_at_property_declaration (parser);
1424 	  break;
1425 	case RID_AT_SYNTHESIZE:
1426 	  gcc_assert (c_dialect_objc ());
1427 	  c_parser_objc_at_synthesize_declaration (parser);
1428 	  break;
1429 	case RID_AT_DYNAMIC:
1430 	  gcc_assert (c_dialect_objc ());
1431 	  c_parser_objc_at_dynamic_declaration (parser);
1432 	  break;
1433 	case RID_AT_END:
1434 	  gcc_assert (c_dialect_objc ());
1435 	  c_parser_consume_token (parser);
1436 	  objc_finish_implementation ();
1437 	  break;
1438 	default:
1439 	  goto decl_or_fndef;
1440 	}
1441       break;
1442     case CPP_SEMICOLON:
1443       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1444 	       "ISO C does not allow extra %<;%> outside of a function");
1445       c_parser_consume_token (parser);
1446       break;
1447     case CPP_PRAGMA:
1448       mark_valid_location_for_stdc_pragma (true);
1449       c_parser_pragma (parser, pragma_external, NULL);
1450       mark_valid_location_for_stdc_pragma (false);
1451       break;
1452     case CPP_PLUS:
1453     case CPP_MINUS:
1454       if (c_dialect_objc ())
1455 	{
1456 	  c_parser_objc_method_definition (parser);
1457 	  break;
1458 	}
1459       /* Else fall through, and yield a syntax error trying to parse
1460 	 as a declaration or function definition.  */
1461       /* FALLTHRU */
1462     default:
1463     decl_or_fndef:
1464       /* A declaration or a function definition (or, in Objective-C,
1465 	 an @interface or @protocol with prefix attributes).  We can
1466 	 only tell which after parsing the declaration specifiers, if
1467 	 any, and the first declarator.  */
1468       c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1469 				     NULL, vNULL);
1470       break;
1471     }
1472 }
1473 
1474 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1475 static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool);
1476 
1477 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1478    6.7, 6.9.1, C11 6.7, 6.9.1).  If FNDEF_OK is true, a function definition
1479    is accepted; otherwise (old-style parameter declarations) only other
1480    declarations are accepted.  If STATIC_ASSERT_OK is true, a static
1481    assertion is accepted; otherwise (old-style parameter declarations)
1482    it is not.  If NESTED is true, we are inside a function or parsing
1483    old-style parameter declarations; any functions encountered are
1484    nested functions and declaration specifiers are required; otherwise
1485    we are at top level and functions are normal functions and
1486    declaration specifiers may be optional.  If EMPTY_OK is true, empty
1487    declarations are OK (subject to all other constraints); otherwise
1488    (old-style parameter declarations) they are diagnosed.  If
1489    START_ATTR_OK is true, the declaration specifiers may start with
1490    attributes; otherwise they may not.
1491    OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1492    declaration when parsing an Objective-C foreach statement.
1493    FALLTHRU_ATTR_P is used to signal whether this function parsed
1494    "__attribute__((fallthrough));".
1495 
1496    declaration:
1497      declaration-specifiers init-declarator-list[opt] ;
1498      static_assert-declaration
1499 
1500    function-definition:
1501      declaration-specifiers[opt] declarator declaration-list[opt]
1502        compound-statement
1503 
1504    declaration-list:
1505      declaration
1506      declaration-list declaration
1507 
1508    init-declarator-list:
1509      init-declarator
1510      init-declarator-list , init-declarator
1511 
1512    init-declarator:
1513      declarator simple-asm-expr[opt] attributes[opt]
1514      declarator simple-asm-expr[opt] attributes[opt] = initializer
1515 
1516    GNU extensions:
1517 
1518    nested-function-definition:
1519      declaration-specifiers declarator declaration-list[opt]
1520        compound-statement
1521 
1522    attribute ;
1523 
1524    Objective-C:
1525      attributes objc-class-definition
1526      attributes objc-category-definition
1527      attributes objc-protocol-definition
1528 
1529    The simple-asm-expr and attributes are GNU extensions.
1530 
1531    This function does not handle __extension__; that is handled in its
1532    callers.  ??? Following the old parser, __extension__ may start
1533    external declarations, declarations in functions and declarations
1534    at the start of "for" loops, but not old-style parameter
1535    declarations.
1536 
1537    C99 requires declaration specifiers in a function definition; the
1538    absence is diagnosed through the diagnosis of implicit int.  In GNU
1539    C we also allow but diagnose declarations without declaration
1540    specifiers, but only at top level (elsewhere they conflict with
1541    other syntax).
1542 
1543    In Objective-C, declarations of the looping variable in a foreach
1544    statement are exceptionally terminated by 'in' (for example, 'for
1545    (NSObject *object in array) { ... }').
1546 
1547    OpenMP:
1548 
1549    declaration:
1550      threadprivate-directive
1551 
1552    GIMPLE:
1553 
1554    gimple-function-definition:
1555      declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1556        declaration-list[opt] compound-statement
1557 
1558    rtl-function-definition:
1559      declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1560        declaration-list[opt] compound-statement  */
1561 
1562 static void
1563 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1564 			       bool static_assert_ok, bool empty_ok,
1565 			       bool nested, bool start_attr_ok,
1566 			       tree *objc_foreach_object_declaration,
1567 			       vec<c_token> omp_declare_simd_clauses,
1568 			       struct oacc_routine_data *oacc_routine_data,
1569 			       bool *fallthru_attr_p)
1570 {
1571   struct c_declspecs *specs;
1572   tree prefix_attrs;
1573   tree all_prefix_attrs;
1574   bool diagnosed_no_specs = false;
1575   location_t here = c_parser_peek_token (parser)->location;
1576 
1577   if (static_assert_ok
1578       && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1579     {
1580       c_parser_static_assert_declaration (parser);
1581       return;
1582     }
1583   specs = build_null_declspecs ();
1584 
1585   /* Try to detect an unknown type name when we have "A B" or "A *B".  */
1586   if (c_parser_peek_token (parser)->type == CPP_NAME
1587       && c_parser_peek_token (parser)->id_kind == C_ID_ID
1588       && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1589           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1590       && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1591     {
1592       tree name = c_parser_peek_token (parser)->value;
1593 
1594       /* Issue a warning about NAME being an unknown type name, perhaps
1595 	 with some kind of hint.
1596 	 If the user forgot a "struct" etc, suggest inserting
1597 	 it.  Otherwise, attempt to look for misspellings.  */
1598       gcc_rich_location richloc (here);
1599       if (tag_exists_p (RECORD_TYPE, name))
1600 	{
1601 	  /* This is not C++ with its implicit typedef.  */
1602 	  richloc.add_fixit_insert_before ("struct ");
1603 	  error_at_rich_loc (&richloc,
1604 			     "unknown type name %qE;"
1605 			     " use %<struct%> keyword to refer to the type",
1606 			     name);
1607 	}
1608       else if (tag_exists_p (UNION_TYPE, name))
1609 	{
1610 	  richloc.add_fixit_insert_before ("union ");
1611 	  error_at_rich_loc (&richloc,
1612 			     "unknown type name %qE;"
1613 			     " use %<union%> keyword to refer to the type",
1614 			     name);
1615 	}
1616       else if (tag_exists_p (ENUMERAL_TYPE, name))
1617 	{
1618 	  richloc.add_fixit_insert_before ("enum ");
1619 	  error_at_rich_loc (&richloc,
1620 			     "unknown type name %qE;"
1621 			     " use %<enum%> keyword to refer to the type",
1622 			     name);
1623 	}
1624       else
1625 	{
1626 	  const char *hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME);
1627 	  if (hint)
1628 	    {
1629 	      richloc.add_fixit_replace (hint);
1630 	      error_at_rich_loc (&richloc,
1631 				 "unknown type name %qE; did you mean %qs?",
1632 				 name, hint);
1633 	    }
1634 	  else
1635 	    error_at (here, "unknown type name %qE", name);
1636 	}
1637 
1638       /* Parse declspecs normally to get a correct pointer type, but avoid
1639          a further "fails to be a type name" error.  Refuse nested functions
1640          since it is not how the user likely wants us to recover.  */
1641       c_parser_peek_token (parser)->type = CPP_KEYWORD;
1642       c_parser_peek_token (parser)->keyword = RID_VOID;
1643       c_parser_peek_token (parser)->value = error_mark_node;
1644       fndef_ok = !nested;
1645     }
1646 
1647   c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1648 		      true, true, cla_nonabstract_decl);
1649   if (parser->error)
1650     {
1651       c_parser_skip_to_end_of_block_or_statement (parser);
1652       return;
1653     }
1654   if (nested && !specs->declspecs_seen_p)
1655     {
1656       c_parser_error (parser, "expected declaration specifiers");
1657       c_parser_skip_to_end_of_block_or_statement (parser);
1658       return;
1659     }
1660 
1661   finish_declspecs (specs);
1662   bool auto_type_p = specs->typespec_word == cts_auto_type;
1663   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1664     {
1665       if (auto_type_p)
1666 	error_at (here, "%<__auto_type%> in empty declaration");
1667       else if (specs->typespec_kind == ctsk_none
1668 	       && attribute_fallthrough_p (specs->attrs))
1669 	{
1670 	  if (fallthru_attr_p != NULL)
1671 	    *fallthru_attr_p = true;
1672 	  tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH,
1673 						  void_type_node, 0);
1674 	  add_stmt (fn);
1675 	}
1676       else if (empty_ok)
1677 	shadow_tag (specs);
1678       else
1679 	{
1680 	  shadow_tag_warned (specs, 1);
1681 	  pedwarn (here, 0, "empty declaration");
1682 	}
1683       c_parser_consume_token (parser);
1684       if (oacc_routine_data)
1685 	c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1686       return;
1687     }
1688 
1689   /* Provide better error recovery.  Note that a type name here is usually
1690      better diagnosed as a redeclaration.  */
1691   if (empty_ok
1692       && specs->typespec_kind == ctsk_tagdef
1693       && c_parser_next_token_starts_declspecs (parser)
1694       && !c_parser_next_token_is (parser, CPP_NAME))
1695     {
1696       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1697       parser->error = false;
1698       shadow_tag_warned (specs, 1);
1699       return;
1700     }
1701   else if (c_dialect_objc () && !auto_type_p)
1702     {
1703       /* Prefix attributes are an error on method decls.  */
1704       switch (c_parser_peek_token (parser)->type)
1705 	{
1706 	  case CPP_PLUS:
1707 	  case CPP_MINUS:
1708 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1709 	      return;
1710 	    if (specs->attrs)
1711 	      {
1712 		warning_at (c_parser_peek_token (parser)->location,
1713 			    OPT_Wattributes,
1714 	       		    "prefix attributes are ignored for methods");
1715 		specs->attrs = NULL_TREE;
1716 	      }
1717 	    if (fndef_ok)
1718 	      c_parser_objc_method_definition (parser);
1719 	    else
1720 	      c_parser_objc_methodproto (parser);
1721 	    return;
1722 	    break;
1723 	  default:
1724 	    break;
1725 	}
1726       /* This is where we parse 'attributes @interface ...',
1727 	 'attributes @implementation ...', 'attributes @protocol ...'
1728 	 (where attributes could be, for example, __attribute__
1729 	 ((deprecated)).
1730       */
1731       switch (c_parser_peek_token (parser)->keyword)
1732 	{
1733 	case RID_AT_INTERFACE:
1734 	  {
1735 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1736 	      return;
1737 	    c_parser_objc_class_definition (parser, specs->attrs);
1738 	    return;
1739 	  }
1740 	  break;
1741 	case RID_AT_IMPLEMENTATION:
1742 	  {
1743 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1744 	      return;
1745 	    if (specs->attrs)
1746 	      {
1747 		warning_at (c_parser_peek_token (parser)->location,
1748 			OPT_Wattributes,
1749 			"prefix attributes are ignored for implementations");
1750 		specs->attrs = NULL_TREE;
1751 	      }
1752 	    c_parser_objc_class_definition (parser, NULL_TREE);
1753 	    return;
1754 	  }
1755 	  break;
1756 	case RID_AT_PROTOCOL:
1757 	  {
1758 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1759 	      return;
1760 	    c_parser_objc_protocol_definition (parser, specs->attrs);
1761 	    return;
1762 	  }
1763 	  break;
1764 	case RID_AT_ALIAS:
1765 	case RID_AT_CLASS:
1766 	case RID_AT_END:
1767 	case RID_AT_PROPERTY:
1768 	  if (specs->attrs)
1769 	    {
1770 	      c_parser_error (parser, "unexpected attribute");
1771 	      specs->attrs = NULL;
1772 	    }
1773 	  break;
1774 	default:
1775 	  break;
1776 	}
1777     }
1778   else if (attribute_fallthrough_p (specs->attrs))
1779     warning_at (here, OPT_Wattributes,
1780 		"%<fallthrough%> attribute not followed by %<;%>");
1781 
1782   pending_xref_error ();
1783   prefix_attrs = specs->attrs;
1784   all_prefix_attrs = prefix_attrs;
1785   specs->attrs = NULL_TREE;
1786   while (true)
1787     {
1788       struct c_declarator *declarator;
1789       bool dummy = false;
1790       timevar_id_t tv;
1791       tree fnbody = NULL_TREE;
1792       /* Declaring either one or more declarators (in which case we
1793 	 should diagnose if there were no declaration specifiers) or a
1794 	 function definition (in which case the diagnostic for
1795 	 implicit int suffices).  */
1796       declarator = c_parser_declarator (parser,
1797 					specs->typespec_kind != ctsk_none,
1798 					C_DTR_NORMAL, &dummy);
1799       if (declarator == NULL)
1800 	{
1801 	  if (omp_declare_simd_clauses.exists ()
1802 	      || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1803 	    c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1804 				       omp_declare_simd_clauses);
1805 	  if (oacc_routine_data)
1806 	    c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1807 	  c_parser_skip_to_end_of_block_or_statement (parser);
1808 	  return;
1809 	}
1810       if (auto_type_p && declarator->kind != cdk_id)
1811 	{
1812 	  error_at (here,
1813 		    "%<__auto_type%> requires a plain identifier"
1814 		    " as declarator");
1815 	  c_parser_skip_to_end_of_block_or_statement (parser);
1816 	  return;
1817 	}
1818       if (c_parser_next_token_is (parser, CPP_EQ)
1819 	  || c_parser_next_token_is (parser, CPP_COMMA)
1820 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
1821 	  || c_parser_next_token_is_keyword (parser, RID_ASM)
1822 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1823 	  || c_parser_next_token_is_keyword (parser, RID_IN))
1824 	{
1825 	  tree asm_name = NULL_TREE;
1826 	  tree postfix_attrs = NULL_TREE;
1827 	  if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1828 	    {
1829 	      diagnosed_no_specs = true;
1830 	      pedwarn (here, 0, "data definition has no type or storage class");
1831 	    }
1832 	  /* Having seen a data definition, there cannot now be a
1833 	     function definition.  */
1834 	  fndef_ok = false;
1835 	  if (c_parser_next_token_is_keyword (parser, RID_ASM))
1836 	    asm_name = c_parser_simple_asm_expr (parser);
1837 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1838 	    {
1839 	      postfix_attrs = c_parser_attributes (parser);
1840 	      if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1841 		{
1842 		  /* This means there is an attribute specifier after
1843 		     the declarator in a function definition.  Provide
1844 		     some more information for the user.  */
1845 		  error_at (here, "attributes should be specified before the "
1846 			    "declarator in a function definition");
1847 		  c_parser_skip_to_end_of_block_or_statement (parser);
1848 		  return;
1849 		}
1850 	    }
1851 	  if (c_parser_next_token_is (parser, CPP_EQ))
1852 	    {
1853 	      tree d;
1854 	      struct c_expr init;
1855 	      location_t init_loc;
1856 	      c_parser_consume_token (parser);
1857 	      if (auto_type_p)
1858 		{
1859 		  init_loc = c_parser_peek_token (parser)->location;
1860 		  rich_location richloc (line_table, init_loc);
1861 		  start_init (NULL_TREE, asm_name, global_bindings_p (), &richloc);
1862 		  /* A parameter is initialized, which is invalid.  Don't
1863 		     attempt to instrument the initializer.  */
1864 		  int flag_sanitize_save = flag_sanitize;
1865 		  if (nested && !empty_ok)
1866 		    flag_sanitize = 0;
1867 		  init = c_parser_expr_no_commas (parser, NULL);
1868 		  flag_sanitize = flag_sanitize_save;
1869 		  if (TREE_CODE (init.value) == COMPONENT_REF
1870 		      && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
1871 		    error_at (here,
1872 			      "%<__auto_type%> used with a bit-field"
1873 			      " initializer");
1874 		  init = convert_lvalue_to_rvalue (init_loc, init, true, true);
1875 		  tree init_type = TREE_TYPE (init.value);
1876 		  /* As with typeof, remove all qualifiers from atomic types.  */
1877 		  if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
1878 		    init_type
1879 		      = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
1880 		  bool vm_type = variably_modified_type_p (init_type,
1881 							   NULL_TREE);
1882 		  if (vm_type)
1883 		    init.value = c_save_expr (init.value);
1884 		  finish_init ();
1885 		  specs->typespec_kind = ctsk_typeof;
1886 		  specs->locations[cdw_typedef] = init_loc;
1887 		  specs->typedef_p = true;
1888 		  specs->type = init_type;
1889 		  if (vm_type)
1890 		    {
1891 		      bool maybe_const = true;
1892 		      tree type_expr = c_fully_fold (init.value, false,
1893 						     &maybe_const);
1894 		      specs->expr_const_operands &= maybe_const;
1895 		      if (specs->expr)
1896 			specs->expr = build2 (COMPOUND_EXPR,
1897 					      TREE_TYPE (type_expr),
1898 					      specs->expr, type_expr);
1899 		      else
1900 			specs->expr = type_expr;
1901 		    }
1902 		  d = start_decl (declarator, specs, true,
1903 				  chainon (postfix_attrs, all_prefix_attrs));
1904 		  if (!d)
1905 		    d = error_mark_node;
1906 		  if (omp_declare_simd_clauses.exists ()
1907 		      || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1908 		    c_finish_omp_declare_simd (parser, d, NULL_TREE,
1909 					       omp_declare_simd_clauses);
1910 		}
1911 	      else
1912 		{
1913 		  /* The declaration of the variable is in effect while
1914 		     its initializer is parsed.  */
1915 		  d = start_decl (declarator, specs, true,
1916 				  chainon (postfix_attrs, all_prefix_attrs));
1917 		  if (!d)
1918 		    d = error_mark_node;
1919 		  if (omp_declare_simd_clauses.exists ()
1920 		      || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1921 		    c_finish_omp_declare_simd (parser, d, NULL_TREE,
1922 					       omp_declare_simd_clauses);
1923 		  init_loc = c_parser_peek_token (parser)->location;
1924 		  rich_location richloc (line_table, init_loc);
1925 		  start_init (d, asm_name, global_bindings_p (), &richloc);
1926 		  /* A parameter is initialized, which is invalid.  Don't
1927 		     attempt to instrument the initializer.  */
1928 		  int flag_sanitize_save = flag_sanitize;
1929 		  if (TREE_CODE (d) == PARM_DECL)
1930 		    flag_sanitize = 0;
1931 		  init = c_parser_initializer (parser);
1932 		  flag_sanitize = flag_sanitize_save;
1933 		  finish_init ();
1934 		}
1935 	      if (oacc_routine_data)
1936 		c_finish_oacc_routine (oacc_routine_data, d, false);
1937 	      if (d != error_mark_node)
1938 		{
1939 		  maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
1940 		  finish_decl (d, init_loc, init.value,
1941 			       init.original_type, asm_name);
1942 		}
1943 	    }
1944 	  else
1945 	    {
1946 	      if (auto_type_p)
1947 		{
1948 		  error_at (here,
1949 			    "%<__auto_type%> requires an initialized "
1950 			    "data declaration");
1951 		  c_parser_skip_to_end_of_block_or_statement (parser);
1952 		  return;
1953 		}
1954 	      tree d = start_decl (declarator, specs, false,
1955 				   chainon (postfix_attrs,
1956 					    all_prefix_attrs));
1957 	      if (omp_declare_simd_clauses.exists ()
1958 		  || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1959 		{
1960 		  tree parms = NULL_TREE;
1961 		  if (d && TREE_CODE (d) == FUNCTION_DECL)
1962 		    {
1963 		      struct c_declarator *ce = declarator;
1964 		      while (ce != NULL)
1965 			if (ce->kind == cdk_function)
1966 			  {
1967 			    parms = ce->u.arg_info->parms;
1968 			    break;
1969 			  }
1970 			else
1971 			  ce = ce->declarator;
1972 		    }
1973 		  if (parms)
1974 		    temp_store_parm_decls (d, parms);
1975 		  c_finish_omp_declare_simd (parser, d, parms,
1976 					     omp_declare_simd_clauses);
1977 		  if (parms)
1978 		    temp_pop_parm_decls ();
1979 		}
1980 	      if (oacc_routine_data)
1981 		c_finish_oacc_routine (oacc_routine_data, d, false);
1982 	      if (d)
1983 		finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1984 			     NULL_TREE, asm_name);
1985 
1986 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
1987 		{
1988 		  if (d)
1989 		    *objc_foreach_object_declaration = d;
1990 		  else
1991 		    *objc_foreach_object_declaration = error_mark_node;
1992 		}
1993 	    }
1994 	  if (c_parser_next_token_is (parser, CPP_COMMA))
1995 	    {
1996 	      if (auto_type_p)
1997 		{
1998 		  error_at (here,
1999 			    "%<__auto_type%> may only be used with"
2000 			    " a single declarator");
2001 		  c_parser_skip_to_end_of_block_or_statement (parser);
2002 		  return;
2003 		}
2004 	      c_parser_consume_token (parser);
2005 	      if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2006 		all_prefix_attrs = chainon (c_parser_attributes (parser),
2007 					    prefix_attrs);
2008 	      else
2009 		all_prefix_attrs = prefix_attrs;
2010 	      continue;
2011 	    }
2012 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2013 	    {
2014 	      c_parser_consume_token (parser);
2015 	      return;
2016 	    }
2017 	  else if (c_parser_next_token_is_keyword (parser, RID_IN))
2018 	    {
2019 	      /* This can only happen in Objective-C: we found the
2020 		 'in' that terminates the declaration inside an
2021 		 Objective-C foreach statement.  Do not consume the
2022 		 token, so that the caller can use it to determine
2023 		 that this indeed is a foreach context.  */
2024 	      return;
2025 	    }
2026 	  else
2027 	    {
2028 	      c_parser_error (parser, "expected %<,%> or %<;%>");
2029 	      c_parser_skip_to_end_of_block_or_statement (parser);
2030 	      return;
2031 	    }
2032 	}
2033       else if (auto_type_p)
2034 	{
2035 	  error_at (here,
2036 		    "%<__auto_type%> requires an initialized data declaration");
2037 	  c_parser_skip_to_end_of_block_or_statement (parser);
2038 	  return;
2039 	}
2040       else if (!fndef_ok)
2041 	{
2042 	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
2043 			  "%<asm%> or %<__attribute__%>");
2044 	  c_parser_skip_to_end_of_block_or_statement (parser);
2045 	  return;
2046 	}
2047       /* Function definition (nested or otherwise).  */
2048       if (nested)
2049 	{
2050 	  pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
2051 	  c_push_function_context ();
2052 	}
2053       if (!start_function (specs, declarator, all_prefix_attrs))
2054 	{
2055 	  /* This can appear in many cases looking nothing like a
2056 	     function definition, so we don't give a more specific
2057 	     error suggesting there was one.  */
2058 	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2059 			  "or %<__attribute__%>");
2060 	  if (nested)
2061 	    c_pop_function_context ();
2062 	  break;
2063 	}
2064 
2065       if (DECL_DECLARED_INLINE_P (current_function_decl))
2066         tv = TV_PARSE_INLINE;
2067       else
2068         tv = TV_PARSE_FUNC;
2069       auto_timevar at (g_timer, tv);
2070 
2071       /* Parse old-style parameter declarations.  ??? Attributes are
2072 	 not allowed to start declaration specifiers here because of a
2073 	 syntax conflict between a function declaration with attribute
2074 	 suffix and a function definition with an attribute prefix on
2075 	 first old-style parameter declaration.  Following the old
2076 	 parser, they are not accepted on subsequent old-style
2077 	 parameter declarations either.  However, there is no
2078 	 ambiguity after the first declaration, nor indeed on the
2079 	 first as long as we don't allow postfix attributes after a
2080 	 declarator with a nonempty identifier list in a definition;
2081 	 and postfix attributes have never been accepted here in
2082 	 function definitions either.  */
2083       while (c_parser_next_token_is_not (parser, CPP_EOF)
2084 	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
2085 	c_parser_declaration_or_fndef (parser, false, false, false,
2086 				       true, false, NULL, vNULL);
2087       store_parm_decls ();
2088       if (omp_declare_simd_clauses.exists ()
2089 	  || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
2090 	c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
2091 				   omp_declare_simd_clauses);
2092       if (oacc_routine_data)
2093 	c_finish_oacc_routine (oacc_routine_data, current_function_decl, true);
2094       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
2095 	= c_parser_peek_token (parser)->location;
2096 
2097       /* If the definition was marked with __GIMPLE then parse the
2098          function body as GIMPLE.  */
2099       if (specs->gimple_p)
2100 	{
2101 	  cfun->pass_startwith = specs->gimple_or_rtl_pass;
2102 	  bool saved = in_late_binary_op;
2103 	  in_late_binary_op = true;
2104 	  c_parser_parse_gimple_body (parser);
2105 	  in_late_binary_op = saved;
2106 	}
2107       /* Similarly, if it was marked with __RTL, use the RTL parser now,
2108 	 consuming the function body.  */
2109       else if (specs->rtl_p)
2110 	{
2111 	  c_parser_parse_rtl_body (parser, specs->gimple_or_rtl_pass);
2112 
2113 	  /* Normally, store_parm_decls sets next_is_function_body,
2114 	     anticipating a function body.  We need a push_scope/pop_scope
2115 	     pair to flush out this state, or subsequent function parsing
2116 	     will go wrong.  */
2117 	  push_scope ();
2118 	  pop_scope ();
2119 
2120 	  finish_function ();
2121 	  return;
2122 	}
2123       else
2124 	{
2125 	  fnbody = c_parser_compound_statement (parser);
2126 	  if (flag_cilkplus && contains_array_notation_expr (fnbody))
2127 	    fnbody = expand_array_notation_exprs (fnbody);
2128 	}
2129       tree fndecl = current_function_decl;
2130       if (nested)
2131 	{
2132 	  tree decl = current_function_decl;
2133 	  /* Mark nested functions as needing static-chain initially.
2134 	     lower_nested_functions will recompute it but the
2135 	     DECL_STATIC_CHAIN flag is also used before that happens,
2136 	     by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
2137 	  DECL_STATIC_CHAIN (decl) = 1;
2138 	  add_stmt (fnbody);
2139 	  finish_function ();
2140 	  c_pop_function_context ();
2141 	  add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
2142 	}
2143       else
2144 	{
2145 	  if (fnbody)
2146 	    add_stmt (fnbody);
2147 	  finish_function ();
2148 	}
2149       /* Get rid of the empty stmt list for GIMPLE.  */
2150       if (specs->gimple_p)
2151 	DECL_SAVED_TREE (fndecl) = NULL_TREE;
2152 
2153       break;
2154     }
2155 }
2156 
2157 /* Parse an asm-definition (asm() outside a function body).  This is a
2158    GNU extension.
2159 
2160    asm-definition:
2161      simple-asm-expr ;
2162 */
2163 
2164 static void
2165 c_parser_asm_definition (c_parser *parser)
2166 {
2167   tree asm_str = c_parser_simple_asm_expr (parser);
2168   if (asm_str)
2169     symtab->finalize_toplevel_asm (asm_str);
2170   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2171 }
2172 
2173 /* Parse a static assertion (C11 6.7.10).
2174 
2175    static_assert-declaration:
2176      static_assert-declaration-no-semi ;
2177 */
2178 
2179 static void
2180 c_parser_static_assert_declaration (c_parser *parser)
2181 {
2182   c_parser_static_assert_declaration_no_semi (parser);
2183   if (parser->error
2184       || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2185     c_parser_skip_to_end_of_block_or_statement (parser);
2186 }
2187 
2188 /* Parse a static assertion (C11 6.7.10), without the trailing
2189    semicolon.
2190 
2191    static_assert-declaration-no-semi:
2192      _Static_assert ( constant-expression , string-literal )
2193 */
2194 
2195 static void
2196 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2197 {
2198   location_t assert_loc, value_loc;
2199   tree value;
2200   tree string;
2201 
2202   gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2203   assert_loc = c_parser_peek_token (parser)->location;
2204   if (flag_isoc99)
2205     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2206 		 "ISO C99 does not support %<_Static_assert%>");
2207   else
2208     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2209 		 "ISO C90 does not support %<_Static_assert%>");
2210   c_parser_consume_token (parser);
2211   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2212     return;
2213   location_t value_tok_loc = c_parser_peek_token (parser)->location;
2214   value = c_parser_expr_no_commas (parser, NULL).value;
2215   value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc);
2216   parser->lex_untranslated_string = true;
2217   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2218     {
2219       parser->lex_untranslated_string = false;
2220       return;
2221     }
2222   switch (c_parser_peek_token (parser)->type)
2223     {
2224     case CPP_STRING:
2225     case CPP_STRING16:
2226     case CPP_STRING32:
2227     case CPP_WSTRING:
2228     case CPP_UTF8STRING:
2229       string = c_parser_peek_token (parser)->value;
2230       c_parser_consume_token (parser);
2231       parser->lex_untranslated_string = false;
2232       break;
2233     default:
2234       c_parser_error (parser, "expected string literal");
2235       parser->lex_untranslated_string = false;
2236       return;
2237     }
2238   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2239 
2240   if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2241     {
2242       error_at (value_loc, "expression in static assertion is not an integer");
2243       return;
2244     }
2245   if (TREE_CODE (value) != INTEGER_CST)
2246     {
2247       value = c_fully_fold (value, false, NULL);
2248       /* Strip no-op conversions.  */
2249       STRIP_TYPE_NOPS (value);
2250       if (TREE_CODE (value) == INTEGER_CST)
2251 	pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2252 		 "is not an integer constant expression");
2253     }
2254   if (TREE_CODE (value) != INTEGER_CST)
2255     {
2256       error_at (value_loc, "expression in static assertion is not constant");
2257       return;
2258     }
2259   constant_expression_warning (value);
2260   if (integer_zerop (value))
2261     error_at (assert_loc, "static assertion failed: %E", string);
2262 }
2263 
2264 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2265    6.7, C11 6.7), adding them to SPECS (which may already include some).
2266    Storage class specifiers are accepted iff SCSPEC_OK; type
2267    specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2268    accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2269    iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2270 
2271    declaration-specifiers:
2272      storage-class-specifier declaration-specifiers[opt]
2273      type-specifier declaration-specifiers[opt]
2274      type-qualifier declaration-specifiers[opt]
2275      function-specifier declaration-specifiers[opt]
2276      alignment-specifier declaration-specifiers[opt]
2277 
2278    Function specifiers (inline) are from C99, and are currently
2279    handled as storage class specifiers, as is __thread.  Alignment
2280    specifiers are from C11.
2281 
2282    C90 6.5.1, C99 6.7.1, C11 6.7.1:
2283    storage-class-specifier:
2284      typedef
2285      extern
2286      static
2287      auto
2288      register
2289      _Thread_local
2290 
2291    (_Thread_local is new in C11.)
2292 
2293    C99 6.7.4, C11 6.7.4:
2294    function-specifier:
2295      inline
2296      _Noreturn
2297 
2298    (_Noreturn is new in C11.)
2299 
2300    C90 6.5.2, C99 6.7.2, C11 6.7.2:
2301    type-specifier:
2302      void
2303      char
2304      short
2305      int
2306      long
2307      float
2308      double
2309      signed
2310      unsigned
2311      _Bool
2312      _Complex
2313      [_Imaginary removed in C99 TC2]
2314      struct-or-union-specifier
2315      enum-specifier
2316      typedef-name
2317      atomic-type-specifier
2318 
2319    (_Bool and _Complex are new in C99.)
2320    (atomic-type-specifier is new in C11.)
2321 
2322    C90 6.5.3, C99 6.7.3, C11 6.7.3:
2323 
2324    type-qualifier:
2325      const
2326      restrict
2327      volatile
2328      address-space-qualifier
2329      _Atomic
2330 
2331    (restrict is new in C99.)
2332    (_Atomic is new in C11.)
2333 
2334    GNU extensions:
2335 
2336    declaration-specifiers:
2337      attributes declaration-specifiers[opt]
2338 
2339    type-qualifier:
2340      address-space
2341 
2342    address-space:
2343      identifier recognized by the target
2344 
2345    storage-class-specifier:
2346      __thread
2347 
2348    type-specifier:
2349      typeof-specifier
2350      __auto_type
2351      __intN
2352      _Decimal32
2353      _Decimal64
2354      _Decimal128
2355      _Fract
2356      _Accum
2357      _Sat
2358 
2359   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2360    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2361 
2362    atomic-type-specifier
2363     _Atomic ( type-name )
2364 
2365    Objective-C:
2366 
2367    type-specifier:
2368      class-name objc-protocol-refs[opt]
2369      typedef-name objc-protocol-refs
2370      objc-protocol-refs
2371 */
2372 
2373 void
2374 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2375 		    bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2376 		    bool alignspec_ok, bool auto_type_ok,
2377 		    enum c_lookahead_kind la)
2378 {
2379   bool attrs_ok = start_attr_ok;
2380   bool seen_type = specs->typespec_kind != ctsk_none;
2381 
2382   if (!typespec_ok)
2383     gcc_assert (la == cla_prefer_id);
2384 
2385   while (c_parser_next_token_is (parser, CPP_NAME)
2386 	 || c_parser_next_token_is (parser, CPP_KEYWORD)
2387 	 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2388     {
2389       struct c_typespec t;
2390       tree attrs;
2391       tree align;
2392       location_t loc = c_parser_peek_token (parser)->location;
2393 
2394       /* If we cannot accept a type, exit if the next token must start
2395 	 one.  Also, if we already have seen a tagged definition,
2396 	 a typename would be an error anyway and likely the user
2397 	 has simply forgotten a semicolon, so we exit.  */
2398       if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2399 	  && c_parser_next_tokens_start_typename (parser, la)
2400 	  && !c_parser_next_token_is_qualifier (parser))
2401 	break;
2402 
2403       if (c_parser_next_token_is (parser, CPP_NAME))
2404 	{
2405 	  c_token *name_token = c_parser_peek_token (parser);
2406 	  tree value = name_token->value;
2407 	  c_id_kind kind = name_token->id_kind;
2408 
2409 	  if (kind == C_ID_ADDRSPACE)
2410 	    {
2411 	      addr_space_t as
2412 		= name_token->keyword - RID_FIRST_ADDR_SPACE;
2413 	      declspecs_add_addrspace (name_token->location, specs, as);
2414 	      c_parser_consume_token (parser);
2415 	      attrs_ok = true;
2416 	      continue;
2417 	    }
2418 
2419 	  gcc_assert (!c_parser_next_token_is_qualifier (parser));
2420 
2421 	  /* If we cannot accept a type, and the next token must start one,
2422 	     exit.  Do the same if we already have seen a tagged definition,
2423 	     since it would be an error anyway and likely the user has simply
2424 	     forgotten a semicolon.  */
2425 	  if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2426 	    break;
2427 
2428 	  /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2429 	     a C_ID_CLASSNAME.  */
2430 	  c_parser_consume_token (parser);
2431 	  seen_type = true;
2432 	  attrs_ok = true;
2433 	  if (kind == C_ID_ID)
2434 	    {
2435 	      error_at (loc, "unknown type name %qE", value);
2436 	      t.kind = ctsk_typedef;
2437 	      t.spec = error_mark_node;
2438 	    }
2439 	  else if (kind == C_ID_TYPENAME
2440 	           && (!c_dialect_objc ()
2441 	               || c_parser_next_token_is_not (parser, CPP_LESS)))
2442 	    {
2443 	      t.kind = ctsk_typedef;
2444 	      /* For a typedef name, record the meaning, not the name.
2445 		 In case of 'foo foo, bar;'.  */
2446 	      t.spec = lookup_name (value);
2447 	    }
2448 	  else
2449 	    {
2450 	      tree proto = NULL_TREE;
2451 	      gcc_assert (c_dialect_objc ());
2452 	      t.kind = ctsk_objc;
2453 	      if (c_parser_next_token_is (parser, CPP_LESS))
2454 		proto = c_parser_objc_protocol_refs (parser);
2455 	      t.spec = objc_get_protocol_qualified_type (value, proto);
2456 	    }
2457 	  t.expr = NULL_TREE;
2458 	  t.expr_const_operands = true;
2459 	  declspecs_add_type (name_token->location, specs, t);
2460 	  continue;
2461 	}
2462       if (c_parser_next_token_is (parser, CPP_LESS))
2463 	{
2464 	  /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2465 	     nisse@lysator.liu.se.  */
2466 	  tree proto;
2467 	  gcc_assert (c_dialect_objc ());
2468 	  if (!typespec_ok || seen_type)
2469 	    break;
2470 	  proto = c_parser_objc_protocol_refs (parser);
2471 	  t.kind = ctsk_objc;
2472 	  t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2473 	  t.expr = NULL_TREE;
2474 	  t.expr_const_operands = true;
2475 	  declspecs_add_type (loc, specs, t);
2476 	  continue;
2477 	}
2478       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2479       switch (c_parser_peek_token (parser)->keyword)
2480 	{
2481 	case RID_STATIC:
2482 	case RID_EXTERN:
2483 	case RID_REGISTER:
2484 	case RID_TYPEDEF:
2485 	case RID_INLINE:
2486 	case RID_NORETURN:
2487 	case RID_AUTO:
2488 	case RID_THREAD:
2489 	  if (!scspec_ok)
2490 	    goto out;
2491 	  attrs_ok = true;
2492 	  /* TODO: Distinguish between function specifiers (inline, noreturn)
2493 	     and storage class specifiers, either here or in
2494 	     declspecs_add_scspec.  */
2495 	  declspecs_add_scspec (loc, specs,
2496 				c_parser_peek_token (parser)->value);
2497 	  c_parser_consume_token (parser);
2498 	  break;
2499 	case RID_AUTO_TYPE:
2500 	  if (!auto_type_ok)
2501 	    goto out;
2502 	  /* Fall through.  */
2503 	case RID_UNSIGNED:
2504 	case RID_LONG:
2505 	case RID_SHORT:
2506 	case RID_SIGNED:
2507 	case RID_COMPLEX:
2508 	case RID_INT:
2509 	case RID_CHAR:
2510 	case RID_FLOAT:
2511 	case RID_DOUBLE:
2512 	case RID_VOID:
2513 	case RID_DFLOAT32:
2514 	case RID_DFLOAT64:
2515 	case RID_DFLOAT128:
2516 	CASE_RID_FLOATN_NX:
2517 	case RID_BOOL:
2518 	case RID_FRACT:
2519 	case RID_ACCUM:
2520 	case RID_SAT:
2521 	case RID_INT_N_0:
2522 	case RID_INT_N_1:
2523 	case RID_INT_N_2:
2524 	case RID_INT_N_3:
2525 	  if (!typespec_ok)
2526 	    goto out;
2527 	  attrs_ok = true;
2528 	  seen_type = true;
2529 	  if (c_dialect_objc ())
2530 	    parser->objc_need_raw_identifier = true;
2531 	  t.kind = ctsk_resword;
2532 	  t.spec = c_parser_peek_token (parser)->value;
2533 	  t.expr = NULL_TREE;
2534 	  t.expr_const_operands = true;
2535 	  declspecs_add_type (loc, specs, t);
2536 	  c_parser_consume_token (parser);
2537 	  break;
2538 	case RID_ENUM:
2539 	  if (!typespec_ok)
2540 	    goto out;
2541 	  attrs_ok = true;
2542 	  seen_type = true;
2543 	  t = c_parser_enum_specifier (parser);
2544           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2545 	  declspecs_add_type (loc, specs, t);
2546 	  break;
2547 	case RID_STRUCT:
2548 	case RID_UNION:
2549 	  if (!typespec_ok)
2550 	    goto out;
2551 	  attrs_ok = true;
2552 	  seen_type = true;
2553 	  t = c_parser_struct_or_union_specifier (parser);
2554           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2555 	  declspecs_add_type (loc, specs, t);
2556 	  break;
2557 	case RID_TYPEOF:
2558 	  /* ??? The old parser rejected typeof after other type
2559 	     specifiers, but is a syntax error the best way of
2560 	     handling this?  */
2561 	  if (!typespec_ok || seen_type)
2562 	    goto out;
2563 	  attrs_ok = true;
2564 	  seen_type = true;
2565 	  t = c_parser_typeof_specifier (parser);
2566 	  declspecs_add_type (loc, specs, t);
2567 	  break;
2568 	case RID_ATOMIC:
2569 	  /* C parser handling of Objective-C constructs needs
2570 	     checking for correct lvalue-to-rvalue conversions, and
2571 	     the code in build_modify_expr handling various
2572 	     Objective-C cases, and that in build_unary_op handling
2573 	     Objective-C cases for increment / decrement, also needs
2574 	     updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2575 	     and objc_types_are_equivalent may also need updates.  */
2576 	  if (c_dialect_objc ())
2577 	    sorry ("%<_Atomic%> in Objective-C");
2578 	  if (flag_isoc99)
2579 	    pedwarn_c99 (loc, OPT_Wpedantic,
2580 			 "ISO C99 does not support the %<_Atomic%> qualifier");
2581 	  else
2582 	    pedwarn_c99 (loc, OPT_Wpedantic,
2583 			 "ISO C90 does not support the %<_Atomic%> qualifier");
2584 	  attrs_ok = true;
2585 	  tree value;
2586 	  value = c_parser_peek_token (parser)->value;
2587 	  c_parser_consume_token (parser);
2588 	  if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2589 	    {
2590 	      /* _Atomic ( type-name ).  */
2591 	      seen_type = true;
2592 	      c_parser_consume_token (parser);
2593 	      struct c_type_name *type = c_parser_type_name (parser);
2594 	      t.kind = ctsk_typeof;
2595 	      t.spec = error_mark_node;
2596 	      t.expr = NULL_TREE;
2597 	      t.expr_const_operands = true;
2598 	      if (type != NULL)
2599 		t.spec = groktypename (type, &t.expr,
2600 				       &t.expr_const_operands);
2601 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2602 					 "expected %<)%>");
2603 	      if (t.spec != error_mark_node)
2604 		{
2605 		  if (TREE_CODE (t.spec) == ARRAY_TYPE)
2606 		    error_at (loc, "%<_Atomic%>-qualified array type");
2607 		  else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2608 		    error_at (loc, "%<_Atomic%>-qualified function type");
2609 		  else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2610 		    error_at (loc, "%<_Atomic%> applied to a qualified type");
2611 		  else
2612 		    t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2613 		}
2614 	      declspecs_add_type (loc, specs, t);
2615 	    }
2616 	  else
2617 	    declspecs_add_qual (loc, specs, value);
2618 	  break;
2619 	case RID_CONST:
2620 	case RID_VOLATILE:
2621 	case RID_RESTRICT:
2622 	  attrs_ok = true;
2623 	  declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2624 	  c_parser_consume_token (parser);
2625 	  break;
2626 	case RID_ATTRIBUTE:
2627 	  if (!attrs_ok)
2628 	    goto out;
2629 	  attrs = c_parser_attributes (parser);
2630 	  declspecs_add_attrs (loc, specs, attrs);
2631 	  break;
2632 	case RID_ALIGNAS:
2633 	  if (!alignspec_ok)
2634 	    goto out;
2635 	  align = c_parser_alignas_specifier (parser);
2636 	  declspecs_add_alignas (loc, specs, align);
2637 	  break;
2638 	case RID_GIMPLE:
2639 	  if (! flag_gimple)
2640 	    error_at (loc, "%<__GIMPLE%> only valid with -fgimple");
2641 	  c_parser_consume_token (parser);
2642 	  specs->gimple_p = true;
2643 	  specs->locations[cdw_gimple] = loc;
2644 	  specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2645 	  break;
2646 	case RID_RTL:
2647 	  c_parser_consume_token (parser);
2648 	  specs->rtl_p = true;
2649 	  specs->locations[cdw_rtl] = loc;
2650 	  specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2651 	  break;
2652 	default:
2653 	  goto out;
2654 	}
2655     }
2656  out: ;
2657 }
2658 
2659 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2660 
2661    enum-specifier:
2662      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2663      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2664      enum attributes[opt] identifier
2665 
2666    The form with trailing comma is new in C99.  The forms with
2667    attributes are GNU extensions.  In GNU C, we accept any expression
2668    without commas in the syntax (assignment expressions, not just
2669    conditional expressions); assignment expressions will be diagnosed
2670    as non-constant.
2671 
2672    enumerator-list:
2673      enumerator
2674      enumerator-list , enumerator
2675 
2676    enumerator:
2677      enumeration-constant
2678      enumeration-constant = constant-expression
2679 
2680    GNU Extensions:
2681 
2682    enumerator:
2683      enumeration-constant attributes[opt]
2684      enumeration-constant attributes[opt] = constant-expression
2685 
2686 */
2687 
2688 static struct c_typespec
2689 c_parser_enum_specifier (c_parser *parser)
2690 {
2691   struct c_typespec ret;
2692   tree attrs;
2693   tree ident = NULL_TREE;
2694   location_t enum_loc;
2695   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2696   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2697   c_parser_consume_token (parser);
2698   attrs = c_parser_attributes (parser);
2699   enum_loc = c_parser_peek_token (parser)->location;
2700   /* Set the location in case we create a decl now.  */
2701   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2702   if (c_parser_next_token_is (parser, CPP_NAME))
2703     {
2704       ident = c_parser_peek_token (parser)->value;
2705       ident_loc = c_parser_peek_token (parser)->location;
2706       enum_loc = ident_loc;
2707       c_parser_consume_token (parser);
2708     }
2709   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2710     {
2711       /* Parse an enum definition.  */
2712       struct c_enum_contents the_enum;
2713       tree type;
2714       tree postfix_attrs;
2715       /* We chain the enumerators in reverse order, then put them in
2716 	 forward order at the end.  */
2717       tree values;
2718       timevar_push (TV_PARSE_ENUM);
2719       type = start_enum (enum_loc, &the_enum, ident);
2720       values = NULL_TREE;
2721       c_parser_consume_token (parser);
2722       while (true)
2723 	{
2724 	  tree enum_id;
2725 	  tree enum_value;
2726 	  tree enum_decl;
2727 	  bool seen_comma;
2728 	  c_token *token;
2729 	  location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2730 	  location_t decl_loc, value_loc;
2731 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
2732 	    {
2733 	      /* Give a nicer error for "enum {}".  */
2734 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2735 		  && !parser->error)
2736 		{
2737 		  error_at (c_parser_peek_token (parser)->location,
2738 			    "empty enum is invalid");
2739 		  parser->error = true;
2740 		}
2741 	      else
2742 		c_parser_error (parser, "expected identifier");
2743 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2744 	      values = error_mark_node;
2745 	      break;
2746 	    }
2747 	  token = c_parser_peek_token (parser);
2748 	  enum_id = token->value;
2749 	  /* Set the location in case we create a decl now.  */
2750 	  c_parser_set_source_position_from_token (token);
2751 	  decl_loc = value_loc = token->location;
2752 	  c_parser_consume_token (parser);
2753 	  /* Parse any specified attributes.  */
2754 	  tree enum_attrs = c_parser_attributes (parser);
2755 	  if (c_parser_next_token_is (parser, CPP_EQ))
2756 	    {
2757 	      c_parser_consume_token (parser);
2758 	      value_loc = c_parser_peek_token (parser)->location;
2759 	      enum_value = c_parser_expr_no_commas (parser, NULL).value;
2760 	    }
2761 	  else
2762 	    enum_value = NULL_TREE;
2763 	  enum_decl = build_enumerator (decl_loc, value_loc,
2764 					&the_enum, enum_id, enum_value);
2765 	  if (enum_attrs)
2766 	    decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0);
2767 	  TREE_CHAIN (enum_decl) = values;
2768 	  values = enum_decl;
2769 	  seen_comma = false;
2770 	  if (c_parser_next_token_is (parser, CPP_COMMA))
2771 	    {
2772 	      comma_loc = c_parser_peek_token (parser)->location;
2773 	      seen_comma = true;
2774 	      c_parser_consume_token (parser);
2775 	    }
2776 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2777 	    {
2778 	      if (seen_comma)
2779 		pedwarn_c90 (comma_loc, OPT_Wpedantic,
2780 			     "comma at end of enumerator list");
2781 	      c_parser_consume_token (parser);
2782 	      break;
2783 	    }
2784 	  if (!seen_comma)
2785 	    {
2786 	      c_parser_error (parser, "expected %<,%> or %<}%>");
2787 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2788 	      values = error_mark_node;
2789 	      break;
2790 	    }
2791 	}
2792       postfix_attrs = c_parser_attributes (parser);
2793       ret.spec = finish_enum (type, nreverse (values),
2794 			      chainon (attrs, postfix_attrs));
2795       ret.kind = ctsk_tagdef;
2796       ret.expr = NULL_TREE;
2797       ret.expr_const_operands = true;
2798       timevar_pop (TV_PARSE_ENUM);
2799       return ret;
2800     }
2801   else if (!ident)
2802     {
2803       c_parser_error (parser, "expected %<{%>");
2804       ret.spec = error_mark_node;
2805       ret.kind = ctsk_tagref;
2806       ret.expr = NULL_TREE;
2807       ret.expr_const_operands = true;
2808       return ret;
2809     }
2810   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2811   /* In ISO C, enumerated types can be referred to only if already
2812      defined.  */
2813   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2814     {
2815       gcc_assert (ident);
2816       pedwarn (enum_loc, OPT_Wpedantic,
2817 	       "ISO C forbids forward references to %<enum%> types");
2818     }
2819   return ret;
2820 }
2821 
2822 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
2823 
2824    struct-or-union-specifier:
2825      struct-or-union attributes[opt] identifier[opt]
2826        { struct-contents } attributes[opt]
2827      struct-or-union attributes[opt] identifier
2828 
2829    struct-contents:
2830      struct-declaration-list
2831 
2832    struct-declaration-list:
2833      struct-declaration ;
2834      struct-declaration-list struct-declaration ;
2835 
2836    GNU extensions:
2837 
2838    struct-contents:
2839      empty
2840      struct-declaration
2841      struct-declaration-list struct-declaration
2842 
2843    struct-declaration-list:
2844      struct-declaration-list ;
2845      ;
2846 
2847    (Note that in the syntax here, unlike that in ISO C, the semicolons
2848    are included here rather than in struct-declaration, in order to
2849    describe the syntax with extra semicolons and missing semicolon at
2850    end.)
2851 
2852    Objective-C:
2853 
2854    struct-declaration-list:
2855      @defs ( class-name )
2856 
2857    (Note this does not include a trailing semicolon, but can be
2858    followed by further declarations, and gets a pedwarn-if-pedantic
2859    when followed by a semicolon.)  */
2860 
2861 static struct c_typespec
2862 c_parser_struct_or_union_specifier (c_parser *parser)
2863 {
2864   struct c_typespec ret;
2865   tree attrs;
2866   tree ident = NULL_TREE;
2867   location_t struct_loc;
2868   location_t ident_loc = UNKNOWN_LOCATION;
2869   enum tree_code code;
2870   switch (c_parser_peek_token (parser)->keyword)
2871     {
2872     case RID_STRUCT:
2873       code = RECORD_TYPE;
2874       break;
2875     case RID_UNION:
2876       code = UNION_TYPE;
2877       break;
2878     default:
2879       gcc_unreachable ();
2880     }
2881   struct_loc = c_parser_peek_token (parser)->location;
2882   c_parser_consume_token (parser);
2883   attrs = c_parser_attributes (parser);
2884 
2885   /* Set the location in case we create a decl now.  */
2886   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2887 
2888   if (c_parser_next_token_is (parser, CPP_NAME))
2889     {
2890       ident = c_parser_peek_token (parser)->value;
2891       ident_loc = c_parser_peek_token (parser)->location;
2892       struct_loc = ident_loc;
2893       c_parser_consume_token (parser);
2894     }
2895   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2896     {
2897       /* Parse a struct or union definition.  Start the scope of the
2898 	 tag before parsing components.  */
2899       struct c_struct_parse_info *struct_info;
2900       tree type = start_struct (struct_loc, code, ident, &struct_info);
2901       tree postfix_attrs;
2902       /* We chain the components in reverse order, then put them in
2903 	 forward order at the end.  Each struct-declaration may
2904 	 declare multiple components (comma-separated), so we must use
2905 	 chainon to join them, although when parsing each
2906 	 struct-declaration we can use TREE_CHAIN directly.
2907 
2908 	 The theory behind all this is that there will be more
2909 	 semicolon separated fields than comma separated fields, and
2910 	 so we'll be minimizing the number of node traversals required
2911 	 by chainon.  */
2912       tree contents;
2913       timevar_push (TV_PARSE_STRUCT);
2914       contents = NULL_TREE;
2915       c_parser_consume_token (parser);
2916       /* Handle the Objective-C @defs construct,
2917 	 e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
2918       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2919 	{
2920 	  tree name;
2921 	  gcc_assert (c_dialect_objc ());
2922 	  c_parser_consume_token (parser);
2923 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2924 	    goto end_at_defs;
2925 	  if (c_parser_next_token_is (parser, CPP_NAME)
2926 	      && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2927 	    {
2928 	      name = c_parser_peek_token (parser)->value;
2929 	      c_parser_consume_token (parser);
2930 	    }
2931 	  else
2932 	    {
2933 	      c_parser_error (parser, "expected class name");
2934 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2935 	      goto end_at_defs;
2936 	    }
2937 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2938 				     "expected %<)%>");
2939 	  contents = nreverse (objc_get_class_ivars (name));
2940 	}
2941     end_at_defs:
2942       /* Parse the struct-declarations and semicolons.  Problems with
2943 	 semicolons are diagnosed here; empty structures are diagnosed
2944 	 elsewhere.  */
2945       while (true)
2946 	{
2947 	  tree decls;
2948 	  /* Parse any stray semicolon.  */
2949 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2950 	    {
2951 	      pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2952 		       "extra semicolon in struct or union specified");
2953 	      c_parser_consume_token (parser);
2954 	      continue;
2955 	    }
2956 	  /* Stop if at the end of the struct or union contents.  */
2957 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2958 	    {
2959 	      c_parser_consume_token (parser);
2960 	      break;
2961 	    }
2962 	  /* Accept #pragmas at struct scope.  */
2963 	  if (c_parser_next_token_is (parser, CPP_PRAGMA))
2964 	    {
2965 	      c_parser_pragma (parser, pragma_struct, NULL);
2966 	      continue;
2967 	    }
2968 	  /* Parse some comma-separated declarations, but not the
2969 	     trailing semicolon if any.  */
2970 	  decls = c_parser_struct_declaration (parser);
2971 	  contents = chainon (decls, contents);
2972 	  /* If no semicolon follows, either we have a parse error or
2973 	     are at the end of the struct or union and should
2974 	     pedwarn.  */
2975 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2976 	    c_parser_consume_token (parser);
2977 	  else
2978 	    {
2979 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2980 		pedwarn (c_parser_peek_token (parser)->location, 0,
2981 			 "no semicolon at end of struct or union");
2982 	      else if (parser->error
2983 		       || !c_parser_next_token_starts_declspecs (parser))
2984 		{
2985 		  c_parser_error (parser, "expected %<;%>");
2986 		  c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2987 		  break;
2988 		}
2989 
2990 	      /* If we come here, we have already emitted an error
2991 		 for an expected `;', identifier or `(', and we also
2992 	         recovered already.  Go on with the next field. */
2993 	    }
2994 	}
2995       postfix_attrs = c_parser_attributes (parser);
2996       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2997 				chainon (attrs, postfix_attrs), struct_info);
2998       ret.kind = ctsk_tagdef;
2999       ret.expr = NULL_TREE;
3000       ret.expr_const_operands = true;
3001       timevar_pop (TV_PARSE_STRUCT);
3002       return ret;
3003     }
3004   else if (!ident)
3005     {
3006       c_parser_error (parser, "expected %<{%>");
3007       ret.spec = error_mark_node;
3008       ret.kind = ctsk_tagref;
3009       ret.expr = NULL_TREE;
3010       ret.expr_const_operands = true;
3011       return ret;
3012     }
3013   ret = parser_xref_tag (ident_loc, code, ident);
3014   return ret;
3015 }
3016 
3017 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3018    *without* the trailing semicolon.
3019 
3020    struct-declaration:
3021      specifier-qualifier-list struct-declarator-list
3022      static_assert-declaration-no-semi
3023 
3024    specifier-qualifier-list:
3025      type-specifier specifier-qualifier-list[opt]
3026      type-qualifier specifier-qualifier-list[opt]
3027      attributes specifier-qualifier-list[opt]
3028 
3029    struct-declarator-list:
3030      struct-declarator
3031      struct-declarator-list , attributes[opt] struct-declarator
3032 
3033    struct-declarator:
3034      declarator attributes[opt]
3035      declarator[opt] : constant-expression attributes[opt]
3036 
3037    GNU extensions:
3038 
3039    struct-declaration:
3040      __extension__ struct-declaration
3041      specifier-qualifier-list
3042 
3043    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
3044    of attributes where shown is a GNU extension.  In GNU C, we accept
3045    any expression without commas in the syntax (assignment
3046    expressions, not just conditional expressions); assignment
3047    expressions will be diagnosed as non-constant.  */
3048 
3049 static tree
3050 c_parser_struct_declaration (c_parser *parser)
3051 {
3052   struct c_declspecs *specs;
3053   tree prefix_attrs;
3054   tree all_prefix_attrs;
3055   tree decls;
3056   location_t decl_loc;
3057   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3058     {
3059       int ext;
3060       tree decl;
3061       ext = disable_extension_diagnostics ();
3062       c_parser_consume_token (parser);
3063       decl = c_parser_struct_declaration (parser);
3064       restore_extension_diagnostics (ext);
3065       return decl;
3066     }
3067   if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
3068     {
3069       c_parser_static_assert_declaration_no_semi (parser);
3070       return NULL_TREE;
3071     }
3072   specs = build_null_declspecs ();
3073   decl_loc = c_parser_peek_token (parser)->location;
3074   /* Strictly by the standard, we shouldn't allow _Alignas here,
3075      but it appears to have been intended to allow it there, so
3076      we're keeping it as it is until WG14 reaches a conclusion
3077      of N1731.
3078      <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf>  */
3079   c_parser_declspecs (parser, specs, false, true, true,
3080 		      true, false, cla_nonabstract_decl);
3081   if (parser->error)
3082     return NULL_TREE;
3083   if (!specs->declspecs_seen_p)
3084     {
3085       c_parser_error (parser, "expected specifier-qualifier-list");
3086       return NULL_TREE;
3087     }
3088   finish_declspecs (specs);
3089   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3090       || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3091     {
3092       tree ret;
3093       if (specs->typespec_kind == ctsk_none)
3094 	{
3095 	  pedwarn (decl_loc, OPT_Wpedantic,
3096 		   "ISO C forbids member declarations with no members");
3097 	  shadow_tag_warned (specs, pedantic);
3098 	  ret = NULL_TREE;
3099 	}
3100       else
3101 	{
3102 	  /* Support for unnamed structs or unions as members of
3103 	     structs or unions (which is [a] useful and [b] supports
3104 	     MS P-SDK).  */
3105 	  tree attrs = NULL;
3106 
3107 	  ret = grokfield (c_parser_peek_token (parser)->location,
3108 			   build_id_declarator (NULL_TREE), specs,
3109 			   NULL_TREE, &attrs);
3110 	  if (ret)
3111 	    decl_attributes (&ret, attrs, 0);
3112 	}
3113       return ret;
3114     }
3115 
3116   /* Provide better error recovery.  Note that a type name here is valid,
3117      and will be treated as a field name.  */
3118   if (specs->typespec_kind == ctsk_tagdef
3119       && TREE_CODE (specs->type) != ENUMERAL_TYPE
3120       && c_parser_next_token_starts_declspecs (parser)
3121       && !c_parser_next_token_is (parser, CPP_NAME))
3122     {
3123       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
3124       parser->error = false;
3125       return NULL_TREE;
3126     }
3127 
3128   pending_xref_error ();
3129   prefix_attrs = specs->attrs;
3130   all_prefix_attrs = prefix_attrs;
3131   specs->attrs = NULL_TREE;
3132   decls = NULL_TREE;
3133   while (true)
3134     {
3135       /* Declaring one or more declarators or un-named bit-fields.  */
3136       struct c_declarator *declarator;
3137       bool dummy = false;
3138       if (c_parser_next_token_is (parser, CPP_COLON))
3139 	declarator = build_id_declarator (NULL_TREE);
3140       else
3141 	declarator = c_parser_declarator (parser,
3142 					  specs->typespec_kind != ctsk_none,
3143 					  C_DTR_NORMAL, &dummy);
3144       if (declarator == NULL)
3145 	{
3146 	  c_parser_skip_to_end_of_block_or_statement (parser);
3147 	  break;
3148 	}
3149       if (c_parser_next_token_is (parser, CPP_COLON)
3150 	  || c_parser_next_token_is (parser, CPP_COMMA)
3151 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
3152 	  || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
3153 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3154 	{
3155 	  tree postfix_attrs = NULL_TREE;
3156 	  tree width = NULL_TREE;
3157 	  tree d;
3158 	  if (c_parser_next_token_is (parser, CPP_COLON))
3159 	    {
3160 	      c_parser_consume_token (parser);
3161 	      width = c_parser_expr_no_commas (parser, NULL).value;
3162 	    }
3163 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3164 	    postfix_attrs = c_parser_attributes (parser);
3165 	  d = grokfield (c_parser_peek_token (parser)->location,
3166 			 declarator, specs, width, &all_prefix_attrs);
3167 	  decl_attributes (&d, chainon (postfix_attrs,
3168 					all_prefix_attrs), 0);
3169 	  DECL_CHAIN (d) = decls;
3170 	  decls = d;
3171 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3172 	    all_prefix_attrs = chainon (c_parser_attributes (parser),
3173 					prefix_attrs);
3174 	  else
3175 	    all_prefix_attrs = prefix_attrs;
3176 	  if (c_parser_next_token_is (parser, CPP_COMMA))
3177 	    c_parser_consume_token (parser);
3178 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3179 		   || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3180 	    {
3181 	      /* Semicolon consumed in caller.  */
3182 	      break;
3183 	    }
3184 	  else
3185 	    {
3186 	      c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3187 	      break;
3188 	    }
3189 	}
3190       else
3191 	{
3192 	  c_parser_error (parser,
3193 			  "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3194 			  "%<__attribute__%>");
3195 	  break;
3196 	}
3197     }
3198   return decls;
3199 }
3200 
3201 /* Parse a typeof specifier (a GNU extension).
3202 
3203    typeof-specifier:
3204      typeof ( expression )
3205      typeof ( type-name )
3206 */
3207 
3208 static struct c_typespec
3209 c_parser_typeof_specifier (c_parser *parser)
3210 {
3211   struct c_typespec ret;
3212   ret.kind = ctsk_typeof;
3213   ret.spec = error_mark_node;
3214   ret.expr = NULL_TREE;
3215   ret.expr_const_operands = true;
3216   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3217   c_parser_consume_token (parser);
3218   c_inhibit_evaluation_warnings++;
3219   in_typeof++;
3220   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3221     {
3222       c_inhibit_evaluation_warnings--;
3223       in_typeof--;
3224       return ret;
3225     }
3226   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3227     {
3228       struct c_type_name *type = c_parser_type_name (parser);
3229       c_inhibit_evaluation_warnings--;
3230       in_typeof--;
3231       if (type != NULL)
3232 	{
3233 	  ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3234 	  pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3235 	}
3236     }
3237   else
3238     {
3239       bool was_vm;
3240       location_t here = c_parser_peek_token (parser)->location;
3241       struct c_expr expr = c_parser_expression (parser);
3242       c_inhibit_evaluation_warnings--;
3243       in_typeof--;
3244       if (TREE_CODE (expr.value) == COMPONENT_REF
3245 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3246 	error_at (here, "%<typeof%> applied to a bit-field");
3247       mark_exp_read (expr.value);
3248       ret.spec = TREE_TYPE (expr.value);
3249       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3250       /* This is returned with the type so that when the type is
3251 	 evaluated, this can be evaluated.  */
3252       if (was_vm)
3253 	ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3254       pop_maybe_used (was_vm);
3255       /* For use in macros such as those in <stdatomic.h>, remove all
3256 	 qualifiers from atomic types.  (const can be an issue for more macros
3257 	 using typeof than just the <stdatomic.h> ones.)  */
3258       if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3259 	ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3260     }
3261   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3262   return ret;
3263 }
3264 
3265 /* Parse an alignment-specifier.
3266 
3267    C11 6.7.5:
3268 
3269    alignment-specifier:
3270      _Alignas ( type-name )
3271      _Alignas ( constant-expression )
3272 */
3273 
3274 static tree
3275 c_parser_alignas_specifier (c_parser * parser)
3276 {
3277   tree ret = error_mark_node;
3278   location_t loc = c_parser_peek_token (parser)->location;
3279   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3280   c_parser_consume_token (parser);
3281   if (flag_isoc99)
3282     pedwarn_c99 (loc, OPT_Wpedantic,
3283 		 "ISO C99 does not support %<_Alignas%>");
3284   else
3285     pedwarn_c99 (loc, OPT_Wpedantic,
3286 		 "ISO C90 does not support %<_Alignas%>");
3287   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3288     return ret;
3289   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3290     {
3291       struct c_type_name *type = c_parser_type_name (parser);
3292       if (type != NULL)
3293 	ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3294 					false, true, 1);
3295     }
3296   else
3297     ret = c_parser_expr_no_commas (parser, NULL).value;
3298   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3299   return ret;
3300 }
3301 
3302 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3303    6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7).  If TYPE_SEEN_P then
3304    a typedef name may be redeclared; otherwise it may not.  KIND
3305    indicates which kind of declarator is wanted.  Returns a valid
3306    declarator except in the case of a syntax error in which case NULL is
3307    returned.  *SEEN_ID is set to true if an identifier being declared is
3308    seen; this is used to diagnose bad forms of abstract array declarators
3309    and to determine whether an identifier list is syntactically permitted.
3310 
3311    declarator:
3312      pointer[opt] direct-declarator
3313 
3314    direct-declarator:
3315      identifier
3316      ( attributes[opt] declarator )
3317      direct-declarator array-declarator
3318      direct-declarator ( parameter-type-list )
3319      direct-declarator ( identifier-list[opt] )
3320 
3321    pointer:
3322      * type-qualifier-list[opt]
3323      * type-qualifier-list[opt] pointer
3324 
3325    type-qualifier-list:
3326      type-qualifier
3327      attributes
3328      type-qualifier-list type-qualifier
3329      type-qualifier-list attributes
3330 
3331    array-declarator:
3332      [ type-qualifier-list[opt] assignment-expression[opt] ]
3333      [ static type-qualifier-list[opt] assignment-expression ]
3334      [ type-qualifier-list static assignment-expression ]
3335      [ type-qualifier-list[opt] * ]
3336 
3337    parameter-type-list:
3338      parameter-list
3339      parameter-list , ...
3340 
3341    parameter-list:
3342      parameter-declaration
3343      parameter-list , parameter-declaration
3344 
3345    parameter-declaration:
3346      declaration-specifiers declarator attributes[opt]
3347      declaration-specifiers abstract-declarator[opt] attributes[opt]
3348 
3349    identifier-list:
3350      identifier
3351      identifier-list , identifier
3352 
3353    abstract-declarator:
3354      pointer
3355      pointer[opt] direct-abstract-declarator
3356 
3357    direct-abstract-declarator:
3358      ( attributes[opt] abstract-declarator )
3359      direct-abstract-declarator[opt] array-declarator
3360      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3361 
3362    GNU extensions:
3363 
3364    direct-declarator:
3365      direct-declarator ( parameter-forward-declarations
3366 			 parameter-type-list[opt] )
3367 
3368    direct-abstract-declarator:
3369      direct-abstract-declarator[opt] ( parameter-forward-declarations
3370 				       parameter-type-list[opt] )
3371 
3372    parameter-forward-declarations:
3373      parameter-list ;
3374      parameter-forward-declarations parameter-list ;
3375 
3376    The uses of attributes shown above are GNU extensions.
3377 
3378    Some forms of array declarator are not included in C99 in the
3379    syntax for abstract declarators; these are disallowed elsewhere.
3380    This may be a defect (DR#289).
3381 
3382    This function also accepts an omitted abstract declarator as being
3383    an abstract declarator, although not part of the formal syntax.  */
3384 
3385 struct c_declarator *
3386 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3387 		     bool *seen_id)
3388 {
3389   /* Parse any initial pointer part.  */
3390   if (c_parser_next_token_is (parser, CPP_MULT))
3391     {
3392       struct c_declspecs *quals_attrs = build_null_declspecs ();
3393       struct c_declarator *inner;
3394       c_parser_consume_token (parser);
3395       c_parser_declspecs (parser, quals_attrs, false, false, true,
3396 			  false, false, cla_prefer_id);
3397       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3398       if (inner == NULL)
3399 	return NULL;
3400       else
3401 	return make_pointer_declarator (quals_attrs, inner);
3402     }
3403   /* Now we have a direct declarator, direct abstract declarator or
3404      nothing (which counts as a direct abstract declarator here).  */
3405   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3406 }
3407 
3408 /* Parse a direct declarator or direct abstract declarator; arguments
3409    as c_parser_declarator.  */
3410 
3411 static struct c_declarator *
3412 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3413 			    bool *seen_id)
3414 {
3415   /* The direct declarator must start with an identifier (possibly
3416      omitted) or a parenthesized declarator (possibly abstract).  In
3417      an ordinary declarator, initial parentheses must start a
3418      parenthesized declarator.  In an abstract declarator or parameter
3419      declarator, they could start a parenthesized declarator or a
3420      parameter list.  To tell which, the open parenthesis and any
3421      following attributes must be read.  If a declaration specifier
3422      follows, then it is a parameter list; if the specifier is a
3423      typedef name, there might be an ambiguity about redeclaring it,
3424      which is resolved in the direction of treating it as a typedef
3425      name.  If a close parenthesis follows, it is also an empty
3426      parameter list, as the syntax does not permit empty abstract
3427      declarators.  Otherwise, it is a parenthesized declarator (in
3428      which case the analysis may be repeated inside it, recursively).
3429 
3430      ??? There is an ambiguity in a parameter declaration "int
3431      (__attribute__((foo)) x)", where x is not a typedef name: it
3432      could be an abstract declarator for a function, or declare x with
3433      parentheses.  The proper resolution of this ambiguity needs
3434      documenting.  At present we follow an accident of the old
3435      parser's implementation, whereby the first parameter must have
3436      some declaration specifiers other than just attributes.  Thus as
3437      a parameter declaration it is treated as a parenthesized
3438      parameter named x, and as an abstract declarator it is
3439      rejected.
3440 
3441      ??? Also following the old parser, attributes inside an empty
3442      parameter list are ignored, making it a list not yielding a
3443      prototype, rather than giving an error or making it have one
3444      parameter with implicit type int.
3445 
3446      ??? Also following the old parser, typedef names may be
3447      redeclared in declarators, but not Objective-C class names.  */
3448 
3449   if (kind != C_DTR_ABSTRACT
3450       && c_parser_next_token_is (parser, CPP_NAME)
3451       && ((type_seen_p
3452 	   && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3453 	       || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3454 	  || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3455     {
3456       struct c_declarator *inner
3457 	= build_id_declarator (c_parser_peek_token (parser)->value);
3458       *seen_id = true;
3459       inner->id_loc = c_parser_peek_token (parser)->location;
3460       c_parser_consume_token (parser);
3461       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3462     }
3463 
3464   if (kind != C_DTR_NORMAL
3465       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3466     {
3467       struct c_declarator *inner = build_id_declarator (NULL_TREE);
3468       inner->id_loc = c_parser_peek_token (parser)->location;
3469       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3470     }
3471 
3472   /* Either we are at the end of an abstract declarator, or we have
3473      parentheses.  */
3474 
3475   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3476     {
3477       tree attrs;
3478       struct c_declarator *inner;
3479       c_parser_consume_token (parser);
3480       attrs = c_parser_attributes (parser);
3481       if (kind != C_DTR_NORMAL
3482 	  && (c_parser_next_token_starts_declspecs (parser)
3483 	      || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3484 	{
3485 	  struct c_arg_info *args
3486 	    = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3487 					 attrs);
3488 	  if (args == NULL)
3489 	    return NULL;
3490 	  else
3491 	    {
3492 	      inner
3493 		= build_function_declarator (args,
3494 					     build_id_declarator (NULL_TREE));
3495 	      return c_parser_direct_declarator_inner (parser, *seen_id,
3496 						       inner);
3497 	    }
3498 	}
3499       /* A parenthesized declarator.  */
3500       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3501       if (inner != NULL && attrs != NULL)
3502 	inner = build_attrs_declarator (attrs, inner);
3503       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3504 	{
3505 	  c_parser_consume_token (parser);
3506 	  if (inner == NULL)
3507 	    return NULL;
3508 	  else
3509 	    return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3510 	}
3511       else
3512 	{
3513 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3514 				     "expected %<)%>");
3515 	  return NULL;
3516 	}
3517     }
3518   else
3519     {
3520       if (kind == C_DTR_NORMAL)
3521 	{
3522 	  c_parser_error (parser, "expected identifier or %<(%>");
3523 	  return NULL;
3524 	}
3525       else
3526 	return build_id_declarator (NULL_TREE);
3527     }
3528 }
3529 
3530 /* Parse part of a direct declarator or direct abstract declarator,
3531    given that some (in INNER) has already been parsed; ID_PRESENT is
3532    true if an identifier is present, false for an abstract
3533    declarator.  */
3534 
3535 static struct c_declarator *
3536 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3537 				  struct c_declarator *inner)
3538 {
3539   /* Parse a sequence of array declarators and parameter lists.  */
3540   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3541     {
3542       location_t brace_loc = c_parser_peek_token (parser)->location;
3543       struct c_declarator *declarator;
3544       struct c_declspecs *quals_attrs = build_null_declspecs ();
3545       bool static_seen;
3546       bool star_seen;
3547       struct c_expr dimen;
3548       dimen.value = NULL_TREE;
3549       dimen.original_code = ERROR_MARK;
3550       dimen.original_type = NULL_TREE;
3551       c_parser_consume_token (parser);
3552       c_parser_declspecs (parser, quals_attrs, false, false, true,
3553 			  false, false, cla_prefer_id);
3554       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3555       if (static_seen)
3556 	c_parser_consume_token (parser);
3557       if (static_seen && !quals_attrs->declspecs_seen_p)
3558 	c_parser_declspecs (parser, quals_attrs, false, false, true,
3559 			    false, false, cla_prefer_id);
3560       if (!quals_attrs->declspecs_seen_p)
3561 	quals_attrs = NULL;
3562       /* If "static" is present, there must be an array dimension.
3563 	 Otherwise, there may be a dimension, "*", or no
3564 	 dimension.  */
3565       if (static_seen)
3566 	{
3567 	  star_seen = false;
3568 	  dimen = c_parser_expr_no_commas (parser, NULL);
3569 	}
3570       else
3571 	{
3572 	  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3573 	    {
3574 	      dimen.value = NULL_TREE;
3575 	      star_seen = false;
3576 	    }
3577 	  else if (flag_cilkplus
3578 		   && c_parser_next_token_is (parser, CPP_COLON))
3579 	    {
3580 	      dimen.value = error_mark_node;
3581 	      star_seen = false;
3582 	      error_at (c_parser_peek_token (parser)->location,
3583 			"array notations cannot be used in declaration");
3584 	      c_parser_consume_token (parser);
3585 	    }
3586 	  else if (c_parser_next_token_is (parser, CPP_MULT))
3587 	    {
3588 	      if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3589 		{
3590 		  dimen.value = NULL_TREE;
3591 		  star_seen = true;
3592 		  c_parser_consume_token (parser);
3593 		}
3594 	      else
3595 		{
3596 		  star_seen = false;
3597 		  dimen = c_parser_expr_no_commas (parser, NULL);
3598 		}
3599 	    }
3600 	  else
3601 	    {
3602 	      star_seen = false;
3603 	      dimen = c_parser_expr_no_commas (parser, NULL);
3604 	    }
3605 	}
3606       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3607 	c_parser_consume_token (parser);
3608       else if (flag_cilkplus
3609 	       && c_parser_next_token_is (parser, CPP_COLON))
3610 	{
3611 	  error_at (c_parser_peek_token (parser)->location,
3612 		    "array notations cannot be used in declaration");
3613 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
3614 	  return NULL;
3615 	}
3616       else
3617 	{
3618 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3619 				     "expected %<]%>");
3620 	  return NULL;
3621 	}
3622       if (dimen.value)
3623 	dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3624       declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3625 					   static_seen, star_seen);
3626       if (declarator == NULL)
3627 	return NULL;
3628       inner = set_array_declarator_inner (declarator, inner);
3629       return c_parser_direct_declarator_inner (parser, id_present, inner);
3630     }
3631   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3632     {
3633       tree attrs;
3634       struct c_arg_info *args;
3635       c_parser_consume_token (parser);
3636       attrs = c_parser_attributes (parser);
3637       args = c_parser_parms_declarator (parser, id_present, attrs);
3638       if (args == NULL)
3639 	return NULL;
3640       else
3641 	{
3642 	  inner = build_function_declarator (args, inner);
3643 	  return c_parser_direct_declarator_inner (parser, id_present, inner);
3644 	}
3645     }
3646   return inner;
3647 }
3648 
3649 /* Parse a parameter list or identifier list, including the closing
3650    parenthesis but not the opening one.  ATTRS are the attributes at
3651    the start of the list.  ID_LIST_OK is true if an identifier list is
3652    acceptable; such a list must not have attributes at the start.  */
3653 
3654 static struct c_arg_info *
3655 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3656 {
3657   push_scope ();
3658   declare_parm_level ();
3659   /* If the list starts with an identifier, it is an identifier list.
3660      Otherwise, it is either a prototype list or an empty list.  */
3661   if (id_list_ok
3662       && !attrs
3663       && c_parser_next_token_is (parser, CPP_NAME)
3664       && c_parser_peek_token (parser)->id_kind == C_ID_ID
3665 
3666       /* Look ahead to detect typos in type names.  */
3667       && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3668       && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3669       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3670       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE
3671       && c_parser_peek_2nd_token (parser)->type != CPP_KEYWORD)
3672     {
3673       tree list = NULL_TREE, *nextp = &list;
3674       while (c_parser_next_token_is (parser, CPP_NAME)
3675 	     && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3676 	{
3677 	  *nextp = build_tree_list (NULL_TREE,
3678 				    c_parser_peek_token (parser)->value);
3679 	  nextp = & TREE_CHAIN (*nextp);
3680 	  c_parser_consume_token (parser);
3681 	  if (c_parser_next_token_is_not (parser, CPP_COMMA))
3682 	    break;
3683 	  c_parser_consume_token (parser);
3684 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3685 	    {
3686 	      c_parser_error (parser, "expected identifier");
3687 	      break;
3688 	    }
3689 	}
3690       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3691 	{
3692 	  struct c_arg_info *ret = build_arg_info ();
3693 	  ret->types = list;
3694 	  c_parser_consume_token (parser);
3695 	  pop_scope ();
3696 	  return ret;
3697 	}
3698       else
3699 	{
3700 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3701 				     "expected %<)%>");
3702 	  pop_scope ();
3703 	  return NULL;
3704 	}
3705     }
3706   else
3707     {
3708       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3709 							       NULL);
3710       pop_scope ();
3711       return ret;
3712     }
3713 }
3714 
3715 /* Parse a parameter list (possibly empty), including the closing
3716    parenthesis but not the opening one.  ATTRS are the attributes at
3717    the start of the list.  EXPR is NULL or an expression that needs to
3718    be evaluated for the side effects of array size expressions in the
3719    parameters.  */
3720 
3721 static struct c_arg_info *
3722 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3723 {
3724   bool bad_parm = false;
3725 
3726   /* ??? Following the old parser, forward parameter declarations may
3727      use abstract declarators, and if no real parameter declarations
3728      follow the forward declarations then this is not diagnosed.  Also
3729      note as above that attributes are ignored as the only contents of
3730      the parentheses, or as the only contents after forward
3731      declarations.  */
3732   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3733     {
3734       struct c_arg_info *ret = build_arg_info ();
3735       c_parser_consume_token (parser);
3736       return ret;
3737     }
3738   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3739     {
3740       struct c_arg_info *ret = build_arg_info ();
3741 
3742       if (flag_allow_parameterless_variadic_functions)
3743         {
3744           /* F (...) is allowed.  */
3745           ret->types = NULL_TREE;
3746         }
3747       else
3748         {
3749           /* Suppress -Wold-style-definition for this case.  */
3750           ret->types = error_mark_node;
3751           error_at (c_parser_peek_token (parser)->location,
3752                     "ISO C requires a named argument before %<...%>");
3753         }
3754       c_parser_consume_token (parser);
3755       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3756 	{
3757 	  c_parser_consume_token (parser);
3758 	  return ret;
3759 	}
3760       else
3761 	{
3762 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3763 				     "expected %<)%>");
3764 	  return NULL;
3765 	}
3766     }
3767   /* Nonempty list of parameters, either terminated with semicolon
3768      (forward declarations; recurse) or with close parenthesis (normal
3769      function) or with ", ... )" (variadic function).  */
3770   while (true)
3771     {
3772       /* Parse a parameter.  */
3773       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3774       attrs = NULL_TREE;
3775       if (parm == NULL)
3776 	bad_parm = true;
3777       else
3778 	push_parm_decl (parm, &expr);
3779       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3780 	{
3781 	  tree new_attrs;
3782 	  c_parser_consume_token (parser);
3783 	  mark_forward_parm_decls ();
3784 	  new_attrs = c_parser_attributes (parser);
3785 	  return c_parser_parms_list_declarator (parser, new_attrs, expr);
3786 	}
3787       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3788 	{
3789 	  c_parser_consume_token (parser);
3790 	  if (bad_parm)
3791 	    return NULL;
3792 	  else
3793 	    return get_parm_info (false, expr);
3794 	}
3795       if (!c_parser_require (parser, CPP_COMMA,
3796 			     "expected %<;%>, %<,%> or %<)%>"))
3797 	{
3798 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3799 	  return NULL;
3800 	}
3801       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3802 	{
3803 	  c_parser_consume_token (parser);
3804 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3805 	    {
3806 	      c_parser_consume_token (parser);
3807 	      if (bad_parm)
3808 		return NULL;
3809 	      else
3810 		return get_parm_info (true, expr);
3811 	    }
3812 	  else
3813 	    {
3814 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3815 					 "expected %<)%>");
3816 	      return NULL;
3817 	    }
3818 	}
3819     }
3820 }
3821 
3822 /* Parse a parameter declaration.  ATTRS are the attributes at the
3823    start of the declaration if it is the first parameter.  */
3824 
3825 static struct c_parm *
3826 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3827 {
3828   struct c_declspecs *specs;
3829   struct c_declarator *declarator;
3830   tree prefix_attrs;
3831   tree postfix_attrs = NULL_TREE;
3832   bool dummy = false;
3833 
3834   /* Accept #pragmas between parameter declarations.  */
3835   while (c_parser_next_token_is (parser, CPP_PRAGMA))
3836     c_parser_pragma (parser, pragma_param, NULL);
3837 
3838   if (!c_parser_next_token_starts_declspecs (parser))
3839     {
3840       c_token *token = c_parser_peek_token (parser);
3841       if (parser->error)
3842 	return NULL;
3843       c_parser_set_source_position_from_token (token);
3844       if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3845 	{
3846 	  const char *hint = lookup_name_fuzzy (token->value,
3847 						FUZZY_LOOKUP_TYPENAME);
3848 	  if (hint)
3849 	    {
3850 	      gcc_rich_location richloc (token->location);
3851 	      richloc.add_fixit_replace (hint);
3852 	      error_at_rich_loc (&richloc,
3853 				 "unknown type name %qE; did you mean %qs?",
3854 				 token->value, hint);
3855 	    }
3856 	  else
3857 	    error_at (token->location, "unknown type name %qE", token->value);
3858 	  parser->error = true;
3859 	}
3860       /* ??? In some Objective-C cases '...' isn't applicable so there
3861 	 should be a different message.  */
3862       else
3863 	c_parser_error (parser,
3864 			"expected declaration specifiers or %<...%>");
3865       c_parser_skip_to_end_of_parameter (parser);
3866       return NULL;
3867     }
3868   specs = build_null_declspecs ();
3869   if (attrs)
3870     {
3871       declspecs_add_attrs (input_location, specs, attrs);
3872       attrs = NULL_TREE;
3873     }
3874   c_parser_declspecs (parser, specs, true, true, true, true, false,
3875 		      cla_nonabstract_decl);
3876   finish_declspecs (specs);
3877   pending_xref_error ();
3878   prefix_attrs = specs->attrs;
3879   specs->attrs = NULL_TREE;
3880   declarator = c_parser_declarator (parser,
3881 				    specs->typespec_kind != ctsk_none,
3882 				    C_DTR_PARM, &dummy);
3883   if (declarator == NULL)
3884     {
3885       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3886       return NULL;
3887     }
3888   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3889     postfix_attrs = c_parser_attributes (parser);
3890   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3891 		       declarator);
3892 }
3893 
3894 /* Parse a string literal in an asm expression.  It should not be
3895    translated, and wide string literals are an error although
3896    permitted by the syntax.  This is a GNU extension.
3897 
3898    asm-string-literal:
3899      string-literal
3900 
3901    ??? At present, following the old parser, the caller needs to have
3902    set lex_untranslated_string to 1.  It would be better to follow the
3903    C++ parser rather than using this kludge.  */
3904 
3905 static tree
3906 c_parser_asm_string_literal (c_parser *parser)
3907 {
3908   tree str;
3909   int save_flag = warn_overlength_strings;
3910   warn_overlength_strings = 0;
3911   if (c_parser_next_token_is (parser, CPP_STRING))
3912     {
3913       str = c_parser_peek_token (parser)->value;
3914       c_parser_consume_token (parser);
3915     }
3916   else if (c_parser_next_token_is (parser, CPP_WSTRING))
3917     {
3918       error_at (c_parser_peek_token (parser)->location,
3919 		"wide string literal in %<asm%>");
3920       str = build_string (1, "");
3921       c_parser_consume_token (parser);
3922     }
3923   else
3924     {
3925       c_parser_error (parser, "expected string literal");
3926       str = NULL_TREE;
3927     }
3928   warn_overlength_strings = save_flag;
3929   return str;
3930 }
3931 
3932 /* Parse a simple asm expression.  This is used in restricted
3933    contexts, where a full expression with inputs and outputs does not
3934    make sense.  This is a GNU extension.
3935 
3936    simple-asm-expr:
3937      asm ( asm-string-literal )
3938 */
3939 
3940 static tree
3941 c_parser_simple_asm_expr (c_parser *parser)
3942 {
3943   tree str;
3944   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3945   /* ??? Follow the C++ parser rather than using the
3946      lex_untranslated_string kludge.  */
3947   parser->lex_untranslated_string = true;
3948   c_parser_consume_token (parser);
3949   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3950     {
3951       parser->lex_untranslated_string = false;
3952       return NULL_TREE;
3953     }
3954   str = c_parser_asm_string_literal (parser);
3955   parser->lex_untranslated_string = false;
3956   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3957     {
3958       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3959       return NULL_TREE;
3960     }
3961   return str;
3962 }
3963 
3964 static tree
3965 c_parser_attribute_any_word (c_parser *parser)
3966 {
3967   tree attr_name = NULL_TREE;
3968 
3969   if (c_parser_next_token_is (parser, CPP_KEYWORD))
3970     {
3971       /* ??? See comment above about what keywords are accepted here.  */
3972       bool ok;
3973       switch (c_parser_peek_token (parser)->keyword)
3974 	{
3975 	case RID_STATIC:
3976 	case RID_UNSIGNED:
3977 	case RID_LONG:
3978 	case RID_CONST:
3979 	case RID_EXTERN:
3980 	case RID_REGISTER:
3981 	case RID_TYPEDEF:
3982 	case RID_SHORT:
3983 	case RID_INLINE:
3984 	case RID_NORETURN:
3985 	case RID_VOLATILE:
3986 	case RID_SIGNED:
3987 	case RID_AUTO:
3988 	case RID_RESTRICT:
3989 	case RID_COMPLEX:
3990 	case RID_THREAD:
3991 	case RID_INT:
3992 	case RID_CHAR:
3993 	case RID_FLOAT:
3994 	case RID_DOUBLE:
3995 	case RID_VOID:
3996 	case RID_DFLOAT32:
3997 	case RID_DFLOAT64:
3998 	case RID_DFLOAT128:
3999 	CASE_RID_FLOATN_NX:
4000 	case RID_BOOL:
4001 	case RID_FRACT:
4002 	case RID_ACCUM:
4003 	case RID_SAT:
4004 	case RID_TRANSACTION_ATOMIC:
4005 	case RID_TRANSACTION_CANCEL:
4006 	case RID_ATOMIC:
4007 	case RID_AUTO_TYPE:
4008 	case RID_INT_N_0:
4009 	case RID_INT_N_1:
4010 	case RID_INT_N_2:
4011 	case RID_INT_N_3:
4012 	  ok = true;
4013 	  break;
4014 	default:
4015 	  ok = false;
4016 	  break;
4017 	}
4018       if (!ok)
4019 	return NULL_TREE;
4020 
4021       /* Accept __attribute__((__const)) as __attribute__((const)) etc.  */
4022       attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
4023     }
4024   else if (c_parser_next_token_is (parser, CPP_NAME))
4025     attr_name = c_parser_peek_token (parser)->value;
4026 
4027   return attr_name;
4028 }
4029 
4030 #define CILK_SIMD_FN_CLAUSE_MASK				  \
4031 	((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH)	  \
4032 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR)	  \
4033 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM)	  \
4034 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK)	  \
4035 	 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
4036 
4037 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
4038    VEC_TOKEN is the "vector" token that is replaced with "simd" and
4039    pushed into the token list.
4040    Syntax:
4041    vector
4042    vector (<vector attributes>).  */
4043 
4044 static void
4045 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token)
4046 {
4047   gcc_assert (is_cilkplus_vector_p (vec_token.value));
4048 
4049   int paren_scope = 0;
4050   vec_safe_push (parser->cilk_simd_fn_tokens, vec_token);
4051   /* Consume the "vector" token.  */
4052   c_parser_consume_token (parser);
4053 
4054   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
4055     {
4056       c_parser_consume_token (parser);
4057       paren_scope++;
4058     }
4059   while (paren_scope > 0)
4060     {
4061       c_token *token = c_parser_peek_token (parser);
4062       if (token->type == CPP_OPEN_PAREN)
4063         paren_scope++;
4064       else if (token->type == CPP_CLOSE_PAREN)
4065         paren_scope--;
4066       /* Do not push the last ')' since we are not pushing the '('.  */
4067       if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0))
4068 	vec_safe_push (parser->cilk_simd_fn_tokens, *token);
4069       c_parser_consume_token (parser);
4070     }
4071 
4072   /* Since we are converting an attribute to a pragma, we need to end the
4073      attribute with PRAGMA_EOL.  */
4074   c_token eol_token;
4075   memset (&eol_token, 0, sizeof (eol_token));
4076   eol_token.type = CPP_PRAGMA_EOL;
4077   vec_safe_push (parser->cilk_simd_fn_tokens, eol_token);
4078 }
4079 
4080 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector.  */
4081 
4082 static void
4083 c_finish_cilk_simd_fn_tokens (c_parser *parser)
4084 {
4085   c_token last_token = parser->cilk_simd_fn_tokens->last ();
4086 
4087   /* c_parser_attributes is called in several places, so if these EOF
4088      tokens are already inserted, then don't do them again.  */
4089   if (last_token.type == CPP_EOF)
4090     return;
4091 
4092   /* Two CPP_EOF token are added as a safety net since the normal C
4093      front-end has two token look-ahead.  */
4094   c_token eof_token;
4095   eof_token.type = CPP_EOF;
4096   vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
4097   vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
4098 }
4099 
4100 /* Parse (possibly empty) attributes.  This is a GNU extension.
4101 
4102    attributes:
4103      empty
4104      attributes attribute
4105 
4106    attribute:
4107      __attribute__ ( ( attribute-list ) )
4108 
4109    attribute-list:
4110      attrib
4111      attribute_list , attrib
4112 
4113    attrib:
4114      empty
4115      any-word
4116      any-word ( identifier )
4117      any-word ( identifier , nonempty-expr-list )
4118      any-word ( expr-list )
4119 
4120    where the "identifier" must not be declared as a type, and
4121    "any-word" may be any identifier (including one declared as a
4122    type), a reserved word storage class specifier, type specifier or
4123    type qualifier.  ??? This still leaves out most reserved keywords
4124    (following the old parser), shouldn't we include them, and why not
4125    allow identifiers declared as types to start the arguments?  */
4126 
4127 static tree
4128 c_parser_attributes (c_parser *parser)
4129 {
4130   tree attrs = NULL_TREE;
4131   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4132     {
4133       /* ??? Follow the C++ parser rather than using the
4134 	 lex_untranslated_string kludge.  */
4135       parser->lex_untranslated_string = true;
4136       /* Consume the `__attribute__' keyword.  */
4137       c_parser_consume_token (parser);
4138       /* Look for the two `(' tokens.  */
4139       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4140 	{
4141 	  parser->lex_untranslated_string = false;
4142 	  return attrs;
4143 	}
4144       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4145 	{
4146 	  parser->lex_untranslated_string = false;
4147 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4148 	  return attrs;
4149 	}
4150       /* Parse the attribute list.  */
4151       while (c_parser_next_token_is (parser, CPP_COMMA)
4152 	     || c_parser_next_token_is (parser, CPP_NAME)
4153 	     || c_parser_next_token_is (parser, CPP_KEYWORD))
4154 	{
4155 	  tree attr, attr_name, attr_args;
4156 	  vec<tree, va_gc> *expr_list;
4157 	  if (c_parser_next_token_is (parser, CPP_COMMA))
4158 	    {
4159 	      c_parser_consume_token (parser);
4160 	      continue;
4161 	    }
4162 
4163 	  attr_name = c_parser_attribute_any_word (parser);
4164 	  if (attr_name == NULL)
4165 	    break;
4166 	  if (is_cilkplus_vector_p (attr_name))
4167 	    {
4168 	      c_token *v_token = c_parser_peek_token (parser);
4169 	      c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
4170 	      /* If the next token isn't a comma, we're done.  */
4171 	      if (!c_parser_next_token_is (parser, CPP_COMMA))
4172 		break;
4173 	      continue;
4174 	    }
4175 	  c_parser_consume_token (parser);
4176 	  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
4177 	    {
4178 	      attr = build_tree_list (attr_name, NULL_TREE);
4179 	      /* Add this attribute to the list.  */
4180 	      attrs = chainon (attrs, attr);
4181 	      /* If the next token isn't a comma, we're done.  */
4182 	      if (!c_parser_next_token_is (parser, CPP_COMMA))
4183 		break;
4184 	      continue;
4185 	    }
4186 	  c_parser_consume_token (parser);
4187 	  /* Parse the attribute contents.  If they start with an
4188 	     identifier which is followed by a comma or close
4189 	     parenthesis, then the arguments start with that
4190 	     identifier; otherwise they are an expression list.
4191 	     In objective-c the identifier may be a classname.  */
4192 	  if (c_parser_next_token_is (parser, CPP_NAME)
4193 	      && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4194 		  || (c_dialect_objc ()
4195 		      && c_parser_peek_token (parser)->id_kind
4196 			 == C_ID_CLASSNAME))
4197 	      && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4198 		  || (c_parser_peek_2nd_token (parser)->type
4199 		      == CPP_CLOSE_PAREN))
4200 	      && (attribute_takes_identifier_p (attr_name)
4201 		  || (c_dialect_objc ()
4202 		      && c_parser_peek_token (parser)->id_kind
4203 			 == C_ID_CLASSNAME)))
4204 	    {
4205 	      tree arg1 = c_parser_peek_token (parser)->value;
4206 	      c_parser_consume_token (parser);
4207 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4208 		attr_args = build_tree_list (NULL_TREE, arg1);
4209 	      else
4210 		{
4211 		  tree tree_list;
4212 		  c_parser_consume_token (parser);
4213 		  expr_list = c_parser_expr_list (parser, false, true,
4214 						  NULL, NULL, NULL, NULL);
4215 		  tree_list = build_tree_list_vec (expr_list);
4216 		  attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4217 		  release_tree_vector (expr_list);
4218 		}
4219 	    }
4220 	  else
4221 	    {
4222 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4223 		attr_args = NULL_TREE;
4224 	      else
4225 		{
4226 		  expr_list = c_parser_expr_list (parser, false, true,
4227 						  NULL, NULL, NULL, NULL);
4228 		  attr_args = build_tree_list_vec (expr_list);
4229 		  release_tree_vector (expr_list);
4230 		}
4231 	    }
4232 	  attr = build_tree_list (attr_name, attr_args);
4233 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4234 	    c_parser_consume_token (parser);
4235 	  else
4236 	    {
4237 	      parser->lex_untranslated_string = false;
4238 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4239 					 "expected %<)%>");
4240 	      return attrs;
4241 	    }
4242 	  /* Add this attribute to the list.  */
4243 	  attrs = chainon (attrs, attr);
4244 	  /* If the next token isn't a comma, we're done.  */
4245 	  if (!c_parser_next_token_is (parser, CPP_COMMA))
4246 	    break;
4247 	}
4248       /* Look for the two `)' tokens.  */
4249       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4250 	c_parser_consume_token (parser);
4251       else
4252 	{
4253 	  parser->lex_untranslated_string = false;
4254 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4255 				     "expected %<)%>");
4256 	  return attrs;
4257 	}
4258       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4259 	c_parser_consume_token (parser);
4260       else
4261 	{
4262 	  parser->lex_untranslated_string = false;
4263 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4264 				     "expected %<)%>");
4265 	  return attrs;
4266 	}
4267       parser->lex_untranslated_string = false;
4268     }
4269 
4270   if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
4271     c_finish_cilk_simd_fn_tokens (parser);
4272   return attrs;
4273 }
4274 
4275 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7).
4276 
4277    type-name:
4278      specifier-qualifier-list abstract-declarator[opt]
4279 */
4280 
4281 struct c_type_name *
4282 c_parser_type_name (c_parser *parser)
4283 {
4284   struct c_declspecs *specs = build_null_declspecs ();
4285   struct c_declarator *declarator;
4286   struct c_type_name *ret;
4287   bool dummy = false;
4288   c_parser_declspecs (parser, specs, false, true, true, false, false,
4289 		      cla_prefer_type);
4290   if (!specs->declspecs_seen_p)
4291     {
4292       c_parser_error (parser, "expected specifier-qualifier-list");
4293       return NULL;
4294     }
4295   if (specs->type != error_mark_node)
4296     {
4297       pending_xref_error ();
4298       finish_declspecs (specs);
4299     }
4300   declarator = c_parser_declarator (parser,
4301 				    specs->typespec_kind != ctsk_none,
4302 				    C_DTR_ABSTRACT, &dummy);
4303   if (declarator == NULL)
4304     return NULL;
4305   ret = XOBNEW (&parser_obstack, struct c_type_name);
4306   ret->specs = specs;
4307   ret->declarator = declarator;
4308   return ret;
4309 }
4310 
4311 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4312 
4313    initializer:
4314      assignment-expression
4315      { initializer-list }
4316      { initializer-list , }
4317 
4318    initializer-list:
4319      designation[opt] initializer
4320      initializer-list , designation[opt] initializer
4321 
4322    designation:
4323      designator-list =
4324 
4325    designator-list:
4326      designator
4327      designator-list designator
4328 
4329    designator:
4330      array-designator
4331      . identifier
4332 
4333    array-designator:
4334      [ constant-expression ]
4335 
4336    GNU extensions:
4337 
4338    initializer:
4339      { }
4340 
4341    designation:
4342      array-designator
4343      identifier :
4344 
4345    array-designator:
4346      [ constant-expression ... constant-expression ]
4347 
4348    Any expression without commas is accepted in the syntax for the
4349    constant-expressions, with non-constant expressions rejected later.
4350 
4351    This function is only used for top-level initializers; for nested
4352    ones, see c_parser_initval.  */
4353 
4354 static struct c_expr
4355 c_parser_initializer (c_parser *parser)
4356 {
4357   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4358     return c_parser_braced_init (parser, NULL_TREE, false, NULL);
4359   else
4360     {
4361       struct c_expr ret;
4362       location_t loc = c_parser_peek_token (parser)->location;
4363       ret = c_parser_expr_no_commas (parser, NULL);
4364       if (TREE_CODE (ret.value) != STRING_CST
4365 	  && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4366 	ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4367       return ret;
4368     }
4369 }
4370 
4371 /* The location of the last comma within the current initializer list,
4372    or UNKNOWN_LOCATION if not within one.  */
4373 
4374 location_t last_init_list_comma;
4375 
4376 /* Parse a braced initializer list.  TYPE is the type specified for a
4377    compound literal, and NULL_TREE for other initializers and for
4378    nested braced lists.  NESTED_P is true for nested braced lists,
4379    false for the list of a compound literal or the list that is the
4380    top-level initializer in a declaration.  */
4381 
4382 static struct c_expr
4383 c_parser_braced_init (c_parser *parser, tree type, bool nested_p,
4384 		      struct obstack *outer_obstack)
4385 {
4386   struct c_expr ret;
4387   struct obstack braced_init_obstack;
4388   location_t brace_loc = c_parser_peek_token (parser)->location;
4389   gcc_obstack_init (&braced_init_obstack);
4390   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4391   c_parser_consume_token (parser);
4392   if (nested_p)
4393     {
4394       finish_implicit_inits (brace_loc, outer_obstack);
4395       push_init_level (brace_loc, 0, &braced_init_obstack);
4396     }
4397   else
4398     really_start_incremental_init (type);
4399   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4400     {
4401       pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4402     }
4403   else
4404     {
4405       /* Parse a non-empty initializer list, possibly with a trailing
4406 	 comma.  */
4407       while (true)
4408 	{
4409 	  c_parser_initelt (parser, &braced_init_obstack);
4410 	  if (parser->error)
4411 	    break;
4412 	  if (c_parser_next_token_is (parser, CPP_COMMA))
4413 	    {
4414 	      last_init_list_comma = c_parser_peek_token (parser)->location;
4415 	      c_parser_consume_token (parser);
4416 	    }
4417 	  else
4418 	    break;
4419 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4420 	    break;
4421 	}
4422     }
4423   c_token *next_tok = c_parser_peek_token (parser);
4424   if (next_tok->type != CPP_CLOSE_BRACE)
4425     {
4426       ret.value = error_mark_node;
4427       ret.original_code = ERROR_MARK;
4428       ret.original_type = NULL;
4429       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
4430       pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma);
4431       obstack_free (&braced_init_obstack, NULL);
4432       return ret;
4433     }
4434   location_t close_loc = next_tok->location;
4435   c_parser_consume_token (parser);
4436   ret = pop_init_level (brace_loc, 0, &braced_init_obstack, close_loc);
4437   obstack_free (&braced_init_obstack, NULL);
4438   set_c_expr_source_range (&ret, brace_loc, close_loc);
4439   return ret;
4440 }
4441 
4442 /* Parse a nested initializer, including designators.  */
4443 
4444 static void
4445 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4446 {
4447   /* Parse any designator or designator list.  A single array
4448      designator may have the subsequent "=" omitted in GNU C, but a
4449      longer list or a structure member designator may not.  */
4450   if (c_parser_next_token_is (parser, CPP_NAME)
4451       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4452     {
4453       /* Old-style structure member designator.  */
4454       set_init_label (c_parser_peek_token (parser)->location,
4455 		      c_parser_peek_token (parser)->value,
4456 		      c_parser_peek_token (parser)->location,
4457 		      braced_init_obstack);
4458       /* Use the colon as the error location.  */
4459       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4460 	       "obsolete use of designated initializer with %<:%>");
4461       c_parser_consume_token (parser);
4462       c_parser_consume_token (parser);
4463     }
4464   else
4465     {
4466       /* des_seen is 0 if there have been no designators, 1 if there
4467 	 has been a single array designator and 2 otherwise.  */
4468       int des_seen = 0;
4469       /* Location of a designator.  */
4470       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4471       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4472 	     || c_parser_next_token_is (parser, CPP_DOT))
4473 	{
4474 	  int des_prev = des_seen;
4475 	  if (!des_seen)
4476 	    des_loc = c_parser_peek_token (parser)->location;
4477 	  if (des_seen < 2)
4478 	    des_seen++;
4479 	  if (c_parser_next_token_is (parser, CPP_DOT))
4480 	    {
4481 	      des_seen = 2;
4482 	      c_parser_consume_token (parser);
4483 	      if (c_parser_next_token_is (parser, CPP_NAME))
4484 		{
4485 		  set_init_label (des_loc, c_parser_peek_token (parser)->value,
4486 				  c_parser_peek_token (parser)->location,
4487 				  braced_init_obstack);
4488 		  c_parser_consume_token (parser);
4489 		}
4490 	      else
4491 		{
4492 		  struct c_expr init;
4493 		  init.value = error_mark_node;
4494 		  init.original_code = ERROR_MARK;
4495 		  init.original_type = NULL;
4496 		  c_parser_error (parser, "expected identifier");
4497 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4498 		  process_init_element (input_location, init, false,
4499 					braced_init_obstack);
4500 		  return;
4501 		}
4502 	    }
4503 	  else
4504 	    {
4505 	      tree first, second;
4506 	      location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4507 	      location_t array_index_loc = UNKNOWN_LOCATION;
4508 	      /* ??? Following the old parser, [ objc-receiver
4509 		 objc-message-args ] is accepted as an initializer,
4510 		 being distinguished from a designator by what follows
4511 		 the first assignment expression inside the square
4512 		 brackets, but after a first array designator a
4513 		 subsequent square bracket is for Objective-C taken to
4514 		 start an expression, using the obsolete form of
4515 		 designated initializer without '=', rather than
4516 		 possibly being a second level of designation: in LALR
4517 		 terms, the '[' is shifted rather than reducing
4518 		 designator to designator-list.  */
4519 	      if (des_prev == 1 && c_dialect_objc ())
4520 		{
4521 		  des_seen = des_prev;
4522 		  break;
4523 		}
4524 	      if (des_prev == 0 && c_dialect_objc ())
4525 		{
4526 		  /* This might be an array designator or an
4527 		     Objective-C message expression.  If the former,
4528 		     continue parsing here; if the latter, parse the
4529 		     remainder of the initializer given the starting
4530 		     primary-expression.  ??? It might make sense to
4531 		     distinguish when des_prev == 1 as well; see
4532 		     previous comment.  */
4533 		  tree rec, args;
4534 		  struct c_expr mexpr;
4535 		  c_parser_consume_token (parser);
4536 		  if (c_parser_peek_token (parser)->type == CPP_NAME
4537 		      && ((c_parser_peek_token (parser)->id_kind
4538 			   == C_ID_TYPENAME)
4539 			  || (c_parser_peek_token (parser)->id_kind
4540 			      == C_ID_CLASSNAME)))
4541 		    {
4542 		      /* Type name receiver.  */
4543 		      tree id = c_parser_peek_token (parser)->value;
4544 		      c_parser_consume_token (parser);
4545 		      rec = objc_get_class_reference (id);
4546 		      goto parse_message_args;
4547 		    }
4548 		  first = c_parser_expr_no_commas (parser, NULL).value;
4549 		  mark_exp_read (first);
4550 		  if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4551 		      || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4552 		    goto array_desig_after_first;
4553 		  /* Expression receiver.  So far only one part
4554 		     without commas has been parsed; there might be
4555 		     more of the expression.  */
4556 		  rec = first;
4557 		  while (c_parser_next_token_is (parser, CPP_COMMA))
4558 		    {
4559 		      struct c_expr next;
4560 		      location_t comma_loc, exp_loc;
4561 		      comma_loc = c_parser_peek_token (parser)->location;
4562 		      c_parser_consume_token (parser);
4563 		      exp_loc = c_parser_peek_token (parser)->location;
4564 		      next = c_parser_expr_no_commas (parser, NULL);
4565 		      next = convert_lvalue_to_rvalue (exp_loc, next,
4566 						       true, true);
4567 		      rec = build_compound_expr (comma_loc, rec, next.value);
4568 		    }
4569 		parse_message_args:
4570 		  /* Now parse the objc-message-args.  */
4571 		  args = c_parser_objc_message_args (parser);
4572 		  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4573 					     "expected %<]%>");
4574 		  mexpr.value
4575 		    = objc_build_message_expr (rec, args);
4576 		  mexpr.original_code = ERROR_MARK;
4577 		  mexpr.original_type = NULL;
4578 		  /* Now parse and process the remainder of the
4579 		     initializer, starting with this message
4580 		     expression as a primary-expression.  */
4581 		  c_parser_initval (parser, &mexpr, braced_init_obstack);
4582 		  return;
4583 		}
4584 	      c_parser_consume_token (parser);
4585 	      array_index_loc = c_parser_peek_token (parser)->location;
4586 	      first = c_parser_expr_no_commas (parser, NULL).value;
4587 	      mark_exp_read (first);
4588 	    array_desig_after_first:
4589 	      if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4590 		{
4591 		  ellipsis_loc = c_parser_peek_token (parser)->location;
4592 		  c_parser_consume_token (parser);
4593 		  second = c_parser_expr_no_commas (parser, NULL).value;
4594 		  mark_exp_read (second);
4595 		}
4596 	      else
4597 		second = NULL_TREE;
4598 	      if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4599 		{
4600 		  c_parser_consume_token (parser);
4601 		  set_init_index (array_index_loc, first, second,
4602 				  braced_init_obstack);
4603 		  if (second)
4604 		    pedwarn (ellipsis_loc, OPT_Wpedantic,
4605 			     "ISO C forbids specifying range of elements to initialize");
4606 		}
4607 	      else
4608 		c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4609 					   "expected %<]%>");
4610 	    }
4611 	}
4612       if (des_seen >= 1)
4613 	{
4614 	  if (c_parser_next_token_is (parser, CPP_EQ))
4615 	    {
4616 	      pedwarn_c90 (des_loc, OPT_Wpedantic,
4617 			   "ISO C90 forbids specifying subobject "
4618 			   "to initialize");
4619 	      c_parser_consume_token (parser);
4620 	    }
4621 	  else
4622 	    {
4623 	      if (des_seen == 1)
4624 		pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4625 			 "obsolete use of designated initializer without %<=%>");
4626 	      else
4627 		{
4628 		  struct c_expr init;
4629 		  init.value = error_mark_node;
4630 		  init.original_code = ERROR_MARK;
4631 		  init.original_type = NULL;
4632 		  c_parser_error (parser, "expected %<=%>");
4633 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4634 		  process_init_element (input_location, init, false,
4635 					braced_init_obstack);
4636 		  return;
4637 		}
4638 	    }
4639 	}
4640     }
4641   c_parser_initval (parser, NULL, braced_init_obstack);
4642 }
4643 
4644 /* Parse a nested initializer; as c_parser_initializer but parses
4645    initializers within braced lists, after any designators have been
4646    applied.  If AFTER is not NULL then it is an Objective-C message
4647    expression which is the primary-expression starting the
4648    initializer.  */
4649 
4650 static void
4651 c_parser_initval (c_parser *parser, struct c_expr *after,
4652 		  struct obstack * braced_init_obstack)
4653 {
4654   struct c_expr init;
4655   gcc_assert (!after || c_dialect_objc ());
4656   location_t loc = c_parser_peek_token (parser)->location;
4657 
4658   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4659     init = c_parser_braced_init (parser, NULL_TREE, true,
4660 				 braced_init_obstack);
4661   else
4662     {
4663       init = c_parser_expr_no_commas (parser, after);
4664       if (init.value != NULL_TREE
4665 	  && TREE_CODE (init.value) != STRING_CST
4666 	  && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4667 	init = convert_lvalue_to_rvalue (loc, init, true, true);
4668     }
4669   process_init_element (loc, init, false, braced_init_obstack);
4670 }
4671 
4672 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4673    C99 6.8.2, C11 6.8.2).
4674 
4675    compound-statement:
4676      { block-item-list[opt] }
4677      { label-declarations block-item-list }
4678 
4679    block-item-list:
4680      block-item
4681      block-item-list block-item
4682 
4683    block-item:
4684      nested-declaration
4685      statement
4686 
4687    nested-declaration:
4688      declaration
4689 
4690    GNU extensions:
4691 
4692    compound-statement:
4693      { label-declarations block-item-list }
4694 
4695    nested-declaration:
4696      __extension__ nested-declaration
4697      nested-function-definition
4698 
4699    label-declarations:
4700      label-declaration
4701      label-declarations label-declaration
4702 
4703    label-declaration:
4704      __label__ identifier-list ;
4705 
4706    Allowing the mixing of declarations and code is new in C99.  The
4707    GNU syntax also permits (not shown above) labels at the end of
4708    compound statements, which yield an error.  We don't allow labels
4709    on declarations; this might seem like a natural extension, but
4710    there would be a conflict between attributes on the label and
4711    prefix attributes on the declaration.  ??? The syntax follows the
4712    old parser in requiring something after label declarations.
4713    Although they are erroneous if the labels declared aren't defined,
4714    is it useful for the syntax to be this way?
4715 
4716    OpenACC:
4717 
4718    block-item:
4719      openacc-directive
4720 
4721    openacc-directive:
4722      update-directive
4723 
4724    OpenMP:
4725 
4726    block-item:
4727      openmp-directive
4728 
4729    openmp-directive:
4730      barrier-directive
4731      flush-directive
4732      taskwait-directive
4733      taskyield-directive
4734      cancel-directive
4735      cancellation-point-directive  */
4736 
4737 static tree
4738 c_parser_compound_statement (c_parser *parser)
4739 {
4740   tree stmt;
4741   location_t brace_loc;
4742   brace_loc = c_parser_peek_token (parser)->location;
4743   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4744     {
4745       /* Ensure a scope is entered and left anyway to avoid confusion
4746 	 if we have just prepared to enter a function body.  */
4747       stmt = c_begin_compound_stmt (true);
4748       c_end_compound_stmt (brace_loc, stmt, true);
4749       return error_mark_node;
4750     }
4751   stmt = c_begin_compound_stmt (true);
4752   c_parser_compound_statement_nostart (parser);
4753 
4754   /* If the compound stmt contains array notations, then we expand them.  */
4755   if (flag_cilkplus && contains_array_notation_expr (stmt))
4756     stmt = expand_array_notation_exprs (stmt);
4757   return c_end_compound_stmt (brace_loc, stmt, true);
4758 }
4759 
4760 /* Parse a compound statement except for the opening brace.  This is
4761    used for parsing both compound statements and statement expressions
4762    (which follow different paths to handling the opening).  */
4763 
4764 static void
4765 c_parser_compound_statement_nostart (c_parser *parser)
4766 {
4767   bool last_stmt = false;
4768   bool last_label = false;
4769   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4770   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4771   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4772     {
4773       c_parser_consume_token (parser);
4774       return;
4775     }
4776   mark_valid_location_for_stdc_pragma (true);
4777   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4778     {
4779       /* Read zero or more forward-declarations for labels that nested
4780 	 functions can jump to.  */
4781       mark_valid_location_for_stdc_pragma (false);
4782       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4783 	{
4784 	  label_loc = c_parser_peek_token (parser)->location;
4785 	  c_parser_consume_token (parser);
4786 	  /* Any identifiers, including those declared as type names,
4787 	     are OK here.  */
4788 	  while (true)
4789 	    {
4790 	      tree label;
4791 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
4792 		{
4793 		  c_parser_error (parser, "expected identifier");
4794 		  break;
4795 		}
4796 	      label
4797 		= declare_label (c_parser_peek_token (parser)->value);
4798 	      C_DECLARED_LABEL_FLAG (label) = 1;
4799 	      add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4800 	      c_parser_consume_token (parser);
4801 	      if (c_parser_next_token_is (parser, CPP_COMMA))
4802 		c_parser_consume_token (parser);
4803 	      else
4804 		break;
4805 	    }
4806 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4807 	}
4808       pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4809     }
4810   /* We must now have at least one statement, label or declaration.  */
4811   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4812     {
4813       mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4814       c_parser_error (parser, "expected declaration or statement");
4815       c_parser_consume_token (parser);
4816       return;
4817     }
4818   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4819     {
4820       location_t loc = c_parser_peek_token (parser)->location;
4821       if (c_parser_next_token_is_keyword (parser, RID_CASE)
4822 	  || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4823 	  || (c_parser_next_token_is (parser, CPP_NAME)
4824 	      && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4825 	{
4826 	  if (c_parser_next_token_is_keyword (parser, RID_CASE))
4827 	    label_loc = c_parser_peek_2nd_token (parser)->location;
4828 	  else
4829 	    label_loc = c_parser_peek_token (parser)->location;
4830 	  last_label = true;
4831 	  last_stmt = false;
4832 	  mark_valid_location_for_stdc_pragma (false);
4833 	  c_parser_label (parser);
4834 	}
4835       else if (!last_label
4836 	       && c_parser_next_tokens_start_declaration (parser))
4837 	{
4838 	  last_label = false;
4839 	  mark_valid_location_for_stdc_pragma (false);
4840 	  bool fallthru_attr_p = false;
4841 	  c_parser_declaration_or_fndef (parser, true, true, true, true,
4842 					 true, NULL, vNULL, NULL,
4843 					 &fallthru_attr_p);
4844 	  if (last_stmt && !fallthru_attr_p)
4845 	    pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4846 			 "ISO C90 forbids mixed declarations and code");
4847 	  last_stmt = fallthru_attr_p;
4848 	}
4849       else if (!last_label
4850 	       && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4851 	{
4852 	  /* __extension__ can start a declaration, but is also an
4853 	     unary operator that can start an expression.  Consume all
4854 	     but the last of a possible series of __extension__ to
4855 	     determine which.  */
4856 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4857 		 && (c_parser_peek_2nd_token (parser)->keyword
4858 		     == RID_EXTENSION))
4859 	    c_parser_consume_token (parser);
4860 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4861 	    {
4862 	      int ext;
4863 	      ext = disable_extension_diagnostics ();
4864 	      c_parser_consume_token (parser);
4865 	      last_label = false;
4866 	      mark_valid_location_for_stdc_pragma (false);
4867 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
4868 					     true, NULL, vNULL);
4869 	      /* Following the old parser, __extension__ does not
4870 		 disable this diagnostic.  */
4871 	      restore_extension_diagnostics (ext);
4872 	      if (last_stmt)
4873 		pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4874 			     "ISO C90 forbids mixed declarations and code");
4875 	      last_stmt = false;
4876 	    }
4877 	  else
4878 	    goto statement;
4879 	}
4880       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4881 	{
4882 	  /* External pragmas, and some omp pragmas, are not associated
4883 	     with regular c code, and so are not to be considered statements
4884 	     syntactically.  This ensures that the user doesn't put them
4885 	     places that would turn into syntax errors if the directive
4886 	     were ignored.  */
4887 	  if (c_parser_pragma (parser,
4888 			       last_label ? pragma_stmt : pragma_compound,
4889 			       NULL))
4890 	    last_label = false, last_stmt = true;
4891 	}
4892       else if (c_parser_next_token_is (parser, CPP_EOF))
4893 	{
4894 	  mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4895 	  c_parser_error (parser, "expected declaration or statement");
4896 	  return;
4897 	}
4898       else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4899         {
4900           if (parser->in_if_block)
4901             {
4902 	      mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4903               error_at (loc, """expected %<}%> before %<else%>");
4904               return;
4905             }
4906           else
4907             {
4908               error_at (loc, "%<else%> without a previous %<if%>");
4909               c_parser_consume_token (parser);
4910               continue;
4911             }
4912         }
4913       else
4914 	{
4915 	statement:
4916 	  last_label = false;
4917 	  last_stmt = true;
4918 	  mark_valid_location_for_stdc_pragma (false);
4919 	  c_parser_statement_after_labels (parser, NULL);
4920 	}
4921 
4922       parser->error = false;
4923     }
4924   if (last_label)
4925     error_at (label_loc, "label at end of compound statement");
4926   c_parser_consume_token (parser);
4927   /* Restore the value we started with.  */
4928   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4929 }
4930 
4931 /* Parse all consecutive labels. */
4932 
4933 static void
4934 c_parser_all_labels (c_parser *parser)
4935 {
4936   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4937 	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4938 	 || (c_parser_next_token_is (parser, CPP_NAME)
4939 	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4940     c_parser_label (parser);
4941 }
4942 
4943 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
4944 
4945    label:
4946      identifier : attributes[opt]
4947      case constant-expression :
4948      default :
4949 
4950    GNU extensions:
4951 
4952    label:
4953      case constant-expression ... constant-expression :
4954 
4955    The use of attributes on labels is a GNU extension.  The syntax in
4956    GNU C accepts any expressions without commas, non-constant
4957    expressions being rejected later.  */
4958 
4959 static void
4960 c_parser_label (c_parser *parser)
4961 {
4962   location_t loc1 = c_parser_peek_token (parser)->location;
4963   tree label = NULL_TREE;
4964 
4965   /* Remember whether this case or a user-defined label is allowed to fall
4966      through to.  */
4967   bool fallthrough_p = c_parser_peek_token (parser)->flags & PREV_FALLTHROUGH;
4968 
4969   if (c_parser_next_token_is_keyword (parser, RID_CASE))
4970     {
4971       tree exp1, exp2;
4972       c_parser_consume_token (parser);
4973       exp1 = c_parser_expr_no_commas (parser, NULL).value;
4974       if (c_parser_next_token_is (parser, CPP_COLON))
4975 	{
4976 	  c_parser_consume_token (parser);
4977 	  label = do_case (loc1, exp1, NULL_TREE);
4978 	}
4979       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4980 	{
4981 	  c_parser_consume_token (parser);
4982 	  exp2 = c_parser_expr_no_commas (parser, NULL).value;
4983 	  if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4984 	    label = do_case (loc1, exp1, exp2);
4985 	}
4986       else
4987 	c_parser_error (parser, "expected %<:%> or %<...%>");
4988     }
4989   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4990     {
4991       c_parser_consume_token (parser);
4992       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4993 	label = do_case (loc1, NULL_TREE, NULL_TREE);
4994     }
4995   else
4996     {
4997       tree name = c_parser_peek_token (parser)->value;
4998       tree tlab;
4999       tree attrs;
5000       location_t loc2 = c_parser_peek_token (parser)->location;
5001       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
5002       c_parser_consume_token (parser);
5003       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
5004       c_parser_consume_token (parser);
5005       attrs = c_parser_attributes (parser);
5006       tlab = define_label (loc2, name);
5007       if (tlab)
5008 	{
5009 	  decl_attributes (&tlab, attrs, 0);
5010 	  label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
5011 	}
5012     }
5013   if (label)
5014     {
5015       if (TREE_CODE (label) == LABEL_EXPR)
5016 	FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label)) = fallthrough_p;
5017       else
5018 	FALLTHROUGH_LABEL_P (CASE_LABEL (label)) = fallthrough_p;
5019 
5020       /* Allow '__attribute__((fallthrough));'.  */
5021       if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
5022 	{
5023 	  location_t loc = c_parser_peek_token (parser)->location;
5024 	  tree attrs = c_parser_attributes (parser);
5025 	  if (attribute_fallthrough_p (attrs))
5026 	    {
5027 	      if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5028 		{
5029 		  tree fn = build_call_expr_internal_loc (loc,
5030 							  IFN_FALLTHROUGH,
5031 							  void_type_node, 0);
5032 		  add_stmt (fn);
5033 		}
5034 	      else
5035 		warning_at (loc, OPT_Wattributes, "%<fallthrough%> attribute "
5036 			    "not followed by %<;%>");
5037 	    }
5038 	  else if (attrs != NULL_TREE)
5039 	    warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>"
5040 			" can be applied to a null statement");
5041 	}
5042       if (c_parser_next_tokens_start_declaration (parser))
5043 	{
5044 	  error_at (c_parser_peek_token (parser)->location,
5045 		    "a label can only be part of a statement and "
5046 		    "a declaration is not a statement");
5047 	  c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
5048 					 /*static_assert_ok*/ true,
5049 					 /*empty_ok*/ true, /*nested*/ true,
5050 					 /*start_attr_ok*/ true, NULL,
5051 					 vNULL);
5052 	}
5053     }
5054 }
5055 
5056 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5057 
5058    statement:
5059      labeled-statement
5060      compound-statement
5061      expression-statement
5062      selection-statement
5063      iteration-statement
5064      jump-statement
5065 
5066    labeled-statement:
5067      label statement
5068 
5069    expression-statement:
5070      expression[opt] ;
5071 
5072    selection-statement:
5073      if-statement
5074      switch-statement
5075 
5076    iteration-statement:
5077      while-statement
5078      do-statement
5079      for-statement
5080 
5081    jump-statement:
5082      goto identifier ;
5083      continue ;
5084      break ;
5085      return expression[opt] ;
5086 
5087    GNU extensions:
5088 
5089    statement:
5090      asm-statement
5091 
5092    jump-statement:
5093      goto * expression ;
5094 
5095    expression-statement:
5096      attributes ;
5097 
5098    Objective-C:
5099 
5100    statement:
5101      objc-throw-statement
5102      objc-try-catch-statement
5103      objc-synchronized-statement
5104 
5105    objc-throw-statement:
5106      @throw expression ;
5107      @throw ;
5108 
5109    OpenACC:
5110 
5111    statement:
5112      openacc-construct
5113 
5114    openacc-construct:
5115      parallel-construct
5116      kernels-construct
5117      data-construct
5118      loop-construct
5119 
5120    parallel-construct:
5121      parallel-directive structured-block
5122 
5123    kernels-construct:
5124      kernels-directive structured-block
5125 
5126    data-construct:
5127      data-directive structured-block
5128 
5129    loop-construct:
5130      loop-directive structured-block
5131 
5132    OpenMP:
5133 
5134    statement:
5135      openmp-construct
5136 
5137    openmp-construct:
5138      parallel-construct
5139      for-construct
5140      simd-construct
5141      for-simd-construct
5142      sections-construct
5143      single-construct
5144      parallel-for-construct
5145      parallel-for-simd-construct
5146      parallel-sections-construct
5147      master-construct
5148      critical-construct
5149      atomic-construct
5150      ordered-construct
5151 
5152    parallel-construct:
5153      parallel-directive structured-block
5154 
5155    for-construct:
5156      for-directive iteration-statement
5157 
5158    simd-construct:
5159      simd-directive iteration-statements
5160 
5161    for-simd-construct:
5162      for-simd-directive iteration-statements
5163 
5164    sections-construct:
5165      sections-directive section-scope
5166 
5167    single-construct:
5168      single-directive structured-block
5169 
5170    parallel-for-construct:
5171      parallel-for-directive iteration-statement
5172 
5173    parallel-for-simd-construct:
5174      parallel-for-simd-directive iteration-statement
5175 
5176    parallel-sections-construct:
5177      parallel-sections-directive section-scope
5178 
5179    master-construct:
5180      master-directive structured-block
5181 
5182    critical-construct:
5183      critical-directive structured-block
5184 
5185    atomic-construct:
5186      atomic-directive expression-statement
5187 
5188    ordered-construct:
5189      ordered-directive structured-block
5190 
5191    Transactional Memory:
5192 
5193    statement:
5194      transaction-statement
5195      transaction-cancel-statement
5196 
5197    IF_P is used to track whether there's a (possibly labeled) if statement
5198    which is not enclosed in braces and has an else clause.  This is used to
5199    implement -Wparentheses.  */
5200 
5201 static void
5202 c_parser_statement (c_parser *parser, bool *if_p)
5203 {
5204   c_parser_all_labels (parser);
5205   c_parser_statement_after_labels (parser, if_p, NULL);
5206 }
5207 
5208 /* Parse a statement, other than a labeled statement.  CHAIN is a vector
5209    of if-else-if conditions.
5210 
5211    IF_P is used to track whether there's a (possibly labeled) if statement
5212    which is not enclosed in braces and has an else clause.  This is used to
5213    implement -Wparentheses.  */
5214 
5215 static void
5216 c_parser_statement_after_labels (c_parser *parser, bool *if_p,
5217 				 vec<tree> *chain)
5218 {
5219   location_t loc = c_parser_peek_token (parser)->location;
5220   tree stmt = NULL_TREE;
5221   bool in_if_block = parser->in_if_block;
5222   parser->in_if_block = false;
5223   if (if_p != NULL)
5224     *if_p = false;
5225   switch (c_parser_peek_token (parser)->type)
5226     {
5227     case CPP_OPEN_BRACE:
5228       add_stmt (c_parser_compound_statement (parser));
5229       break;
5230     case CPP_KEYWORD:
5231       switch (c_parser_peek_token (parser)->keyword)
5232 	{
5233 	case RID_IF:
5234 	  c_parser_if_statement (parser, if_p, chain);
5235 	  break;
5236 	case RID_SWITCH:
5237 	  c_parser_switch_statement (parser, if_p);
5238 	  break;
5239 	case RID_WHILE:
5240 	  c_parser_while_statement (parser, false, if_p);
5241 	  break;
5242 	case RID_DO:
5243 	  c_parser_do_statement (parser, false);
5244 	  break;
5245 	case RID_FOR:
5246 	  c_parser_for_statement (parser, false, if_p);
5247 	  break;
5248 	case RID_CILK_FOR:
5249 	  if (!flag_cilkplus)
5250 	    {
5251 	      error_at (c_parser_peek_token (parser)->location,
5252 			"-fcilkplus must be enabled to use %<_Cilk_for%>");
5253 	      c_parser_skip_to_end_of_block_or_statement (parser);
5254 	    }
5255 	  else
5256 	    c_parser_cilk_for (parser, integer_zero_node, if_p);
5257 	  break;
5258 	case RID_CILK_SYNC:
5259 	  c_parser_consume_token (parser);
5260 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5261 	  if (!flag_cilkplus)
5262 	    error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5263 	  else
5264 	    add_stmt (build_cilk_sync ());
5265 	  break;
5266 	case RID_GOTO:
5267 	  c_parser_consume_token (parser);
5268 	  if (c_parser_next_token_is (parser, CPP_NAME))
5269 	    {
5270 	      stmt = c_finish_goto_label (loc,
5271 					  c_parser_peek_token (parser)->value);
5272 	      c_parser_consume_token (parser);
5273 	    }
5274 	  else if (c_parser_next_token_is (parser, CPP_MULT))
5275 	    {
5276 	      struct c_expr val;
5277 
5278 	      c_parser_consume_token (parser);
5279 	      val = c_parser_expression (parser);
5280 	      if (check_no_cilk (val.value,
5281 				 "Cilk array notation cannot be used as a computed goto expression",
5282 				 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5283 				 loc))
5284 	        val.value = error_mark_node;
5285 	      val = convert_lvalue_to_rvalue (loc, val, false, true);
5286 	      stmt = c_finish_goto_ptr (loc, val.value);
5287 	    }
5288 	  else
5289 	    c_parser_error (parser, "expected identifier or %<*%>");
5290 	  goto expect_semicolon;
5291 	case RID_CONTINUE:
5292 	  c_parser_consume_token (parser);
5293 	  stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5294 	  goto expect_semicolon;
5295 	case RID_BREAK:
5296 	  c_parser_consume_token (parser);
5297 	  stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5298 	  goto expect_semicolon;
5299 	case RID_RETURN:
5300 	  c_parser_consume_token (parser);
5301 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5302 	    {
5303 	      stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5304 	      c_parser_consume_token (parser);
5305 	    }
5306 	  else
5307 	    {
5308 	      location_t xloc = c_parser_peek_token (parser)->location;
5309 	      struct c_expr expr = c_parser_expression_conv (parser);
5310 	      mark_exp_read (expr.value);
5311 	      stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc),
5312 				      expr.value, expr.original_type);
5313 	      goto expect_semicolon;
5314 	    }
5315 	  break;
5316 	case RID_ASM:
5317 	  stmt = c_parser_asm_statement (parser);
5318 	  break;
5319 	case RID_TRANSACTION_ATOMIC:
5320 	case RID_TRANSACTION_RELAXED:
5321 	  stmt = c_parser_transaction (parser,
5322 	      c_parser_peek_token (parser)->keyword);
5323 	  break;
5324 	case RID_TRANSACTION_CANCEL:
5325 	  stmt = c_parser_transaction_cancel (parser);
5326 	  goto expect_semicolon;
5327 	case RID_AT_THROW:
5328 	  gcc_assert (c_dialect_objc ());
5329 	  c_parser_consume_token (parser);
5330 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5331 	    {
5332 	      stmt = objc_build_throw_stmt (loc, NULL_TREE);
5333 	      c_parser_consume_token (parser);
5334 	    }
5335 	  else
5336 	    {
5337 	      struct c_expr expr = c_parser_expression (parser);
5338 	      expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5339 	      if (check_no_cilk (expr.value,
5340 		 "Cilk array notation cannot be used for a throw expression",
5341 		 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5342 	        expr.value = error_mark_node;
5343 	      else
5344 		{
5345 	          expr.value = c_fully_fold (expr.value, false, NULL);
5346 	          stmt = objc_build_throw_stmt (loc, expr.value);
5347 		}
5348 	      goto expect_semicolon;
5349 	    }
5350 	  break;
5351 	case RID_AT_TRY:
5352 	  gcc_assert (c_dialect_objc ());
5353 	  c_parser_objc_try_catch_finally_statement (parser);
5354 	  break;
5355 	case RID_AT_SYNCHRONIZED:
5356 	  gcc_assert (c_dialect_objc ());
5357 	  c_parser_objc_synchronized_statement (parser);
5358 	  break;
5359 	case RID_ATTRIBUTE:
5360 	  {
5361 	    /* Allow '__attribute__((fallthrough));'.  */
5362 	    tree attrs = c_parser_attributes (parser);
5363 	    if (attribute_fallthrough_p (attrs))
5364 	      {
5365 		if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5366 		  {
5367 		    tree fn = build_call_expr_internal_loc (loc,
5368 							    IFN_FALLTHROUGH,
5369 							    void_type_node, 0);
5370 		    add_stmt (fn);
5371 		    /* Eat the ';'.  */
5372 		    c_parser_consume_token (parser);
5373 		  }
5374 		else
5375 		  warning_at (loc, OPT_Wattributes,
5376 			      "%<fallthrough%> attribute not followed "
5377 			      "by %<;%>");
5378 	      }
5379 	    else if (attrs != NULL_TREE)
5380 	      warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>"
5381 			  " can be applied to a null statement");
5382 	    break;
5383 	  }
5384 	default:
5385 	  goto expr_stmt;
5386 	}
5387       break;
5388     case CPP_SEMICOLON:
5389       c_parser_consume_token (parser);
5390       break;
5391     case CPP_CLOSE_PAREN:
5392     case CPP_CLOSE_SQUARE:
5393       /* Avoid infinite loop in error recovery:
5394 	 c_parser_skip_until_found stops at a closing nesting
5395 	 delimiter without consuming it, but here we need to consume
5396 	 it to proceed further.  */
5397       c_parser_error (parser, "expected statement");
5398       c_parser_consume_token (parser);
5399       break;
5400     case CPP_PRAGMA:
5401       c_parser_pragma (parser, pragma_stmt, if_p);
5402       break;
5403     default:
5404     expr_stmt:
5405       stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5406     expect_semicolon:
5407       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5408       break;
5409     }
5410   /* Two cases cannot and do not have line numbers associated: If stmt
5411      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5412      cannot hold line numbers.  But that's OK because the statement
5413      will either be changed to a MODIFY_EXPR during gimplification of
5414      the statement expr, or discarded.  If stmt was compound, but
5415      without new variables, we will have skipped the creation of a
5416      BIND and will have a bare STATEMENT_LIST.  But that's OK because
5417      (recursively) all of the component statements should already have
5418      line numbers assigned.  ??? Can we discard no-op statements
5419      earlier?  */
5420   if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5421     protected_set_expr_location (stmt, loc);
5422 
5423   parser->in_if_block = in_if_block;
5424 }
5425 
5426 /* Parse the condition from an if, do, while or for statements.  */
5427 
5428 static tree
5429 c_parser_condition (c_parser *parser)
5430 {
5431   location_t loc = c_parser_peek_token (parser)->location;
5432   tree cond;
5433   cond = c_parser_expression_conv (parser).value;
5434   cond = c_objc_common_truthvalue_conversion (loc, cond);
5435   cond = c_fully_fold (cond, false, NULL);
5436   if (warn_sequence_point)
5437     verify_sequence_points (cond);
5438   return cond;
5439 }
5440 
5441 /* Parse a parenthesized condition from an if, do or while statement.
5442 
5443    condition:
5444      ( expression )
5445 */
5446 static tree
5447 c_parser_paren_condition (c_parser *parser)
5448 {
5449   tree cond;
5450   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5451     return error_mark_node;
5452   cond = c_parser_condition (parser);
5453   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5454   return cond;
5455 }
5456 
5457 /* Parse a statement which is a block in C99.
5458 
5459    IF_P is used to track whether there's a (possibly labeled) if statement
5460    which is not enclosed in braces and has an else clause.  This is used to
5461    implement -Wparentheses.  */
5462 
5463 static tree
5464 c_parser_c99_block_statement (c_parser *parser, bool *if_p)
5465 {
5466   tree block = c_begin_compound_stmt (flag_isoc99);
5467   location_t loc = c_parser_peek_token (parser)->location;
5468   c_parser_statement (parser, if_p);
5469   return c_end_compound_stmt (loc, block, flag_isoc99);
5470 }
5471 
5472 /* Parse the body of an if statement.  This is just parsing a
5473    statement but (a) it is a block in C99, (b) we track whether the
5474    body is an if statement for the sake of -Wparentheses warnings, (c)
5475    we handle an empty body specially for the sake of -Wempty-body
5476    warnings, and (d) we call parser_compound_statement directly
5477    because c_parser_statement_after_labels resets
5478    parser->in_if_block.
5479 
5480    IF_P is used to track whether there's a (possibly labeled) if statement
5481    which is not enclosed in braces and has an else clause.  This is used to
5482    implement -Wparentheses.  */
5483 
5484 static tree
5485 c_parser_if_body (c_parser *parser, bool *if_p,
5486 		  const token_indent_info &if_tinfo)
5487 {
5488   tree block = c_begin_compound_stmt (flag_isoc99);
5489   location_t body_loc = c_parser_peek_token (parser)->location;
5490   token_indent_info body_tinfo
5491     = get_token_indent_info (c_parser_peek_token (parser));
5492 
5493   c_parser_all_labels (parser);
5494   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5495     {
5496       location_t loc = c_parser_peek_token (parser)->location;
5497       add_stmt (build_empty_stmt (loc));
5498       c_parser_consume_token (parser);
5499       if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5500 	warning_at (loc, OPT_Wempty_body,
5501 		    "suggest braces around empty body in an %<if%> statement");
5502     }
5503   else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5504     add_stmt (c_parser_compound_statement (parser));
5505   else
5506     c_parser_statement_after_labels (parser, if_p);
5507 
5508   token_indent_info next_tinfo
5509     = get_token_indent_info (c_parser_peek_token (parser));
5510   warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo);
5511 
5512   return c_end_compound_stmt (body_loc, block, flag_isoc99);
5513 }
5514 
5515 /* Parse the else body of an if statement.  This is just parsing a
5516    statement but (a) it is a block in C99, (b) we handle an empty body
5517    specially for the sake of -Wempty-body warnings.  CHAIN is a vector
5518    of if-else-if conditions.  */
5519 
5520 static tree
5521 c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
5522 		    vec<tree> *chain)
5523 {
5524   location_t body_loc = c_parser_peek_token (parser)->location;
5525   tree block = c_begin_compound_stmt (flag_isoc99);
5526   token_indent_info body_tinfo
5527     = get_token_indent_info (c_parser_peek_token (parser));
5528 
5529   c_parser_all_labels (parser);
5530   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5531     {
5532       location_t loc = c_parser_peek_token (parser)->location;
5533       warning_at (loc,
5534 		  OPT_Wempty_body,
5535 	         "suggest braces around empty body in an %<else%> statement");
5536       add_stmt (build_empty_stmt (loc));
5537       c_parser_consume_token (parser);
5538     }
5539   else
5540     c_parser_statement_after_labels (parser, NULL, chain);
5541 
5542   token_indent_info next_tinfo
5543     = get_token_indent_info (c_parser_peek_token (parser));
5544   warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo);
5545 
5546   return c_end_compound_stmt (body_loc, block, flag_isoc99);
5547 }
5548 
5549 /* We might need to reclassify any previously-lexed identifier, e.g.
5550    when we've left a for loop with an if-statement without else in the
5551    body - we might have used a wrong scope for the token.  See PR67784.  */
5552 
5553 static void
5554 c_parser_maybe_reclassify_token (c_parser *parser)
5555 {
5556   if (c_parser_next_token_is (parser, CPP_NAME))
5557     {
5558       c_token *token = c_parser_peek_token (parser);
5559 
5560       if (token->id_kind != C_ID_CLASSNAME)
5561 	{
5562 	  tree decl = lookup_name (token->value);
5563 
5564 	  token->id_kind = C_ID_ID;
5565 	  if (decl)
5566 	    {
5567 	      if (TREE_CODE (decl) == TYPE_DECL)
5568 		token->id_kind = C_ID_TYPENAME;
5569 	    }
5570 	  else if (c_dialect_objc ())
5571 	    {
5572 	      tree objc_interface_decl = objc_is_class_name (token->value);
5573 	      /* Objective-C class names are in the same namespace as
5574 		 variables and typedefs, and hence are shadowed by local
5575 		 declarations.  */
5576 	      if (objc_interface_decl)
5577 		{
5578 		  token->value = objc_interface_decl;
5579 		  token->id_kind = C_ID_CLASSNAME;
5580 		}
5581 	    }
5582 	}
5583     }
5584 }
5585 
5586 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5587 
5588    if-statement:
5589      if ( expression ) statement
5590      if ( expression ) statement else statement
5591 
5592    CHAIN is a vector of if-else-if conditions.
5593    IF_P is used to track whether there's a (possibly labeled) if statement
5594    which is not enclosed in braces and has an else clause.  This is used to
5595    implement -Wparentheses.  */
5596 
5597 static void
5598 c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
5599 {
5600   tree block;
5601   location_t loc;
5602   tree cond;
5603   bool nested_if = false;
5604   tree first_body, second_body;
5605   bool in_if_block;
5606   tree if_stmt;
5607 
5608   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5609   token_indent_info if_tinfo
5610     = get_token_indent_info (c_parser_peek_token (parser));
5611   c_parser_consume_token (parser);
5612   block = c_begin_compound_stmt (flag_isoc99);
5613   loc = c_parser_peek_token (parser)->location;
5614   cond = c_parser_paren_condition (parser);
5615   if (flag_cilkplus && contains_cilk_spawn_stmt (cond))
5616     {
5617       error_at (loc, "if statement cannot contain %<Cilk_spawn%>");
5618       cond = error_mark_node;
5619     }
5620   in_if_block = parser->in_if_block;
5621   parser->in_if_block = true;
5622   first_body = c_parser_if_body (parser, &nested_if, if_tinfo);
5623   parser->in_if_block = in_if_block;
5624 
5625   if (warn_duplicated_cond)
5626     warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain);
5627 
5628   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5629     {
5630       token_indent_info else_tinfo
5631 	= get_token_indent_info (c_parser_peek_token (parser));
5632       c_parser_consume_token (parser);
5633       if (warn_duplicated_cond)
5634 	{
5635 	  if (c_parser_next_token_is_keyword (parser, RID_IF)
5636 	      && chain == NULL)
5637 	    {
5638 	      /* We've got "if (COND) else if (COND2)".  Start the
5639 		 condition chain and add COND as the first element.  */
5640 	      chain = new vec<tree> ();
5641 	      if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond))
5642 		chain->safe_push (cond);
5643 	    }
5644 	  else if (!c_parser_next_token_is_keyword (parser, RID_IF))
5645 	    {
5646 	      /* This is if-else without subsequent if.  Zap the condition
5647 		 chain; we would have already warned at this point.  */
5648 	      delete chain;
5649 	      chain = NULL;
5650 	    }
5651 	}
5652       second_body = c_parser_else_body (parser, else_tinfo, chain);
5653       /* Set IF_P to true to indicate that this if statement has an
5654 	 else clause.  This may trigger the Wparentheses warning
5655 	 below when we get back up to the parent if statement.  */
5656       if (if_p != NULL)
5657 	*if_p = true;
5658     }
5659   else
5660     {
5661       second_body = NULL_TREE;
5662 
5663       /* Diagnose an ambiguous else if if-then-else is nested inside
5664 	 if-then.  */
5665       if (nested_if)
5666 	warning_at (loc, OPT_Wdangling_else,
5667 		    "suggest explicit braces to avoid ambiguous %<else%>");
5668 
5669       if (warn_duplicated_cond)
5670 	{
5671 	  /* This if statement does not have an else clause.  We don't
5672 	     need the condition chain anymore.  */
5673 	  delete chain;
5674 	  chain = NULL;
5675 	}
5676     }
5677   c_finish_if_stmt (loc, cond, first_body, second_body);
5678   if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
5679 
5680   /* If the if statement contains array notations, then we expand them.  */
5681   if (flag_cilkplus && contains_array_notation_expr (if_stmt))
5682     if_stmt = fix_conditional_array_notations (if_stmt);
5683   add_stmt (if_stmt);
5684   c_parser_maybe_reclassify_token (parser);
5685 }
5686 
5687 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5688 
5689    switch-statement:
5690      switch (expression) statement
5691 */
5692 
5693 static void
5694 c_parser_switch_statement (c_parser *parser, bool *if_p)
5695 {
5696   struct c_expr ce;
5697   tree block, expr, body, save_break;
5698   location_t switch_loc = c_parser_peek_token (parser)->location;
5699   location_t switch_cond_loc;
5700   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5701   c_parser_consume_token (parser);
5702   block = c_begin_compound_stmt (flag_isoc99);
5703   bool explicit_cast_p = false;
5704   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5705     {
5706       switch_cond_loc = c_parser_peek_token (parser)->location;
5707       if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5708 	  && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5709 	explicit_cast_p = true;
5710       ce = c_parser_expression (parser);
5711       ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5712       expr = ce.value;
5713       /* ??? expr has no valid location?  */
5714       if (check_no_cilk (expr,
5715 	 "Cilk array notation cannot be used as a condition for switch statement",
5716 	 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5717 			 switch_cond_loc))
5718         expr = error_mark_node;
5719       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5720     }
5721   else
5722     {
5723       switch_cond_loc = UNKNOWN_LOCATION;
5724       expr = error_mark_node;
5725       ce.original_type = error_mark_node;
5726     }
5727   c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5728   save_break = c_break_label;
5729   c_break_label = NULL_TREE;
5730   body = c_parser_c99_block_statement (parser, if_p);
5731   c_finish_case (body, ce.original_type);
5732   if (c_break_label)
5733     {
5734       location_t here = c_parser_peek_token (parser)->location;
5735       tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5736       SET_EXPR_LOCATION (t, here);
5737       add_stmt (t);
5738     }
5739   c_break_label = save_break;
5740   add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5741   c_parser_maybe_reclassify_token (parser);
5742 }
5743 
5744 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5745 
5746    while-statement:
5747       while (expression) statement
5748 
5749    IF_P is used to track whether there's a (possibly labeled) if statement
5750    which is not enclosed in braces and has an else clause.  This is used to
5751    implement -Wparentheses.  */
5752 
5753 static void
5754 c_parser_while_statement (c_parser *parser, bool ivdep, bool *if_p)
5755 {
5756   tree block, cond, body, save_break, save_cont;
5757   location_t loc;
5758   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5759   token_indent_info while_tinfo
5760     = get_token_indent_info (c_parser_peek_token (parser));
5761   c_parser_consume_token (parser);
5762   block = c_begin_compound_stmt (flag_isoc99);
5763   loc = c_parser_peek_token (parser)->location;
5764   cond = c_parser_paren_condition (parser);
5765   if (check_no_cilk (cond,
5766          "Cilk array notation cannot be used as a condition for while statement",
5767 	 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5768     cond = error_mark_node;
5769   if (ivdep && cond != error_mark_node)
5770     cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5771 		   build_int_cst (integer_type_node,
5772 		   annot_expr_ivdep_kind));
5773   save_break = c_break_label;
5774   c_break_label = NULL_TREE;
5775   save_cont = c_cont_label;
5776   c_cont_label = NULL_TREE;
5777 
5778   token_indent_info body_tinfo
5779     = get_token_indent_info (c_parser_peek_token (parser));
5780 
5781   body = c_parser_c99_block_statement (parser, if_p);
5782   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5783   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5784   c_parser_maybe_reclassify_token (parser);
5785 
5786   token_indent_info next_tinfo
5787     = get_token_indent_info (c_parser_peek_token (parser));
5788   warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo);
5789 
5790   c_break_label = save_break;
5791   c_cont_label = save_cont;
5792 }
5793 
5794 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5795 
5796    do-statement:
5797      do statement while ( expression ) ;
5798 */
5799 
5800 static void
5801 c_parser_do_statement (c_parser *parser, bool ivdep)
5802 {
5803   tree block, cond, body, save_break, save_cont, new_break, new_cont;
5804   location_t loc;
5805   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5806   c_parser_consume_token (parser);
5807   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5808     warning_at (c_parser_peek_token (parser)->location,
5809 		OPT_Wempty_body,
5810 		"suggest braces around empty body in %<do%> statement");
5811   block = c_begin_compound_stmt (flag_isoc99);
5812   loc = c_parser_peek_token (parser)->location;
5813   save_break = c_break_label;
5814   c_break_label = NULL_TREE;
5815   save_cont = c_cont_label;
5816   c_cont_label = NULL_TREE;
5817   body = c_parser_c99_block_statement (parser, NULL);
5818   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5819   new_break = c_break_label;
5820   c_break_label = save_break;
5821   new_cont = c_cont_label;
5822   c_cont_label = save_cont;
5823   cond = c_parser_paren_condition (parser);
5824   if (check_no_cilk (cond,
5825 	 "Cilk array notation cannot be used as a condition for a do-while statement",
5826 	 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5827     cond = error_mark_node;
5828   if (ivdep && cond != error_mark_node)
5829     cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5830 		   build_int_cst (integer_type_node,
5831 		   annot_expr_ivdep_kind));
5832   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5833     c_parser_skip_to_end_of_block_or_statement (parser);
5834   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5835   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5836 }
5837 
5838 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5839 
5840    for-statement:
5841      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5842      for ( nested-declaration expression[opt] ; expression[opt] ) statement
5843 
5844    The form with a declaration is new in C99.
5845 
5846    ??? In accordance with the old parser, the declaration may be a
5847    nested function, which is then rejected in check_for_loop_decls,
5848    but does it make any sense for this to be included in the grammar?
5849    Note in particular that the nested function does not include a
5850    trailing ';', whereas the "declaration" production includes one.
5851    Also, can we reject bad declarations earlier and cheaper than
5852    check_for_loop_decls?
5853 
5854    In Objective-C, there are two additional variants:
5855 
5856    foreach-statement:
5857      for ( expression in expresssion ) statement
5858      for ( declaration in expression ) statement
5859 
5860    This is inconsistent with C, because the second variant is allowed
5861    even if c99 is not enabled.
5862 
5863    The rest of the comment documents these Objective-C foreach-statement.
5864 
5865    Here is the canonical example of the first variant:
5866     for (object in array)    { do something with object }
5867    we call the first expression ("object") the "object_expression" and
5868    the second expression ("array") the "collection_expression".
5869    object_expression must be an lvalue of type "id" (a generic Objective-C
5870    object) because the loop works by assigning to object_expression the
5871    various objects from the collection_expression.  collection_expression
5872    must evaluate to something of type "id" which responds to the method
5873    countByEnumeratingWithState:objects:count:.
5874 
5875    The canonical example of the second variant is:
5876     for (id object in array)    { do something with object }
5877    which is completely equivalent to
5878     {
5879       id object;
5880       for (object in array) { do something with object }
5881     }
5882    Note that initizializing 'object' in some way (eg, "for ((object =
5883    xxx) in array) { do something with object }") is possibly
5884    technically valid, but completely pointless as 'object' will be
5885    assigned to something else as soon as the loop starts.  We should
5886    most likely reject it (TODO).
5887 
5888    The beginning of the Objective-C foreach-statement looks exactly
5889    like the beginning of the for-statement, and we can tell it is a
5890    foreach-statement only because the initial declaration or
5891    expression is terminated by 'in' instead of ';'.
5892 
5893    IF_P is used to track whether there's a (possibly labeled) if statement
5894    which is not enclosed in braces and has an else clause.  This is used to
5895    implement -Wparentheses.  */
5896 
5897 static void
5898 c_parser_for_statement (c_parser *parser, bool ivdep, bool *if_p)
5899 {
5900   tree block, cond, incr, save_break, save_cont, body;
5901   /* The following are only used when parsing an ObjC foreach statement.  */
5902   tree object_expression;
5903   /* Silence the bogus uninitialized warning.  */
5904   tree collection_expression = NULL;
5905   location_t loc = c_parser_peek_token (parser)->location;
5906   location_t for_loc = c_parser_peek_token (parser)->location;
5907   bool is_foreach_statement = false;
5908   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
5909   token_indent_info for_tinfo
5910     = get_token_indent_info (c_parser_peek_token (parser));
5911   c_parser_consume_token (parser);
5912   /* Open a compound statement in Objective-C as well, just in case this is
5913      as foreach expression.  */
5914   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
5915   cond = error_mark_node;
5916   incr = error_mark_node;
5917   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5918     {
5919       /* Parse the initialization declaration or expression.  */
5920       object_expression = error_mark_node;
5921       parser->objc_could_be_foreach_context = c_dialect_objc ();
5922       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5923 	{
5924 	  parser->objc_could_be_foreach_context = false;
5925 	  c_parser_consume_token (parser);
5926 	  c_finish_expr_stmt (loc, NULL_TREE);
5927 	}
5928       else if (c_parser_next_tokens_start_declaration (parser))
5929 	{
5930 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
5931 					 &object_expression, vNULL);
5932 	  parser->objc_could_be_foreach_context = false;
5933 
5934 	  if (c_parser_next_token_is_keyword (parser, RID_IN))
5935 	    {
5936 	      c_parser_consume_token (parser);
5937 	      is_foreach_statement = true;
5938 	      if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5939 		c_parser_error (parser, "multiple iterating variables in fast enumeration");
5940 	    }
5941 	  else
5942 	    check_for_loop_decls (for_loc, flag_isoc99);
5943 	}
5944       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5945 	{
5946 	  /* __extension__ can start a declaration, but is also an
5947 	     unary operator that can start an expression.  Consume all
5948 	     but the last of a possible series of __extension__ to
5949 	     determine which.  */
5950 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5951 		 && (c_parser_peek_2nd_token (parser)->keyword
5952 		     == RID_EXTENSION))
5953 	    c_parser_consume_token (parser);
5954 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5955 	    {
5956 	      int ext;
5957 	      ext = disable_extension_diagnostics ();
5958 	      c_parser_consume_token (parser);
5959 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
5960 					     true, &object_expression, vNULL);
5961 	      parser->objc_could_be_foreach_context = false;
5962 
5963 	      restore_extension_diagnostics (ext);
5964 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
5965 		{
5966 		  c_parser_consume_token (parser);
5967 		  is_foreach_statement = true;
5968 		  if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5969 		    c_parser_error (parser, "multiple iterating variables in fast enumeration");
5970 		}
5971 	      else
5972 		check_for_loop_decls (for_loc, flag_isoc99);
5973 	    }
5974 	  else
5975 	    goto init_expr;
5976 	}
5977       else
5978 	{
5979 	init_expr:
5980 	  {
5981 	    struct c_expr ce;
5982 	    tree init_expression;
5983 	    ce = c_parser_expression (parser);
5984 	    /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5985 	       level statement", but it works just fine, so allow it.  */
5986 	    init_expression = ce.value;
5987 	    parser->objc_could_be_foreach_context = false;
5988 	    if (c_parser_next_token_is_keyword (parser, RID_IN))
5989 	      {
5990 		c_parser_consume_token (parser);
5991 		is_foreach_statement = true;
5992 		if (! lvalue_p (init_expression))
5993 		  c_parser_error (parser, "invalid iterating variable in fast enumeration");
5994 		object_expression = c_fully_fold (init_expression, false, NULL);
5995 	      }
5996 	    else
5997 	      {
5998 		ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5999 		init_expression = ce.value;
6000 		c_finish_expr_stmt (loc, init_expression);
6001 		c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6002 	      }
6003 	  }
6004 	}
6005       /* Parse the loop condition.  In the case of a foreach
6006 	 statement, there is no loop condition.  */
6007       gcc_assert (!parser->objc_could_be_foreach_context);
6008       if (!is_foreach_statement)
6009 	{
6010 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6011 	    {
6012 	      if (ivdep)
6013 		{
6014 		  c_parser_error (parser, "missing loop condition in loop with "
6015 				  "%<GCC ivdep%> pragma");
6016 		  cond = error_mark_node;
6017 		}
6018 	      else
6019 		{
6020 		  c_parser_consume_token (parser);
6021 		  cond = NULL_TREE;
6022 		}
6023 	    }
6024 	  else
6025 	    {
6026 	      cond = c_parser_condition (parser);
6027 	      if (check_no_cilk (cond,
6028 		 "Cilk array notation cannot be used in a condition for a for-loop",
6029 		 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
6030 		cond = error_mark_node;
6031 	      c_parser_skip_until_found (parser, CPP_SEMICOLON,
6032 					 "expected %<;%>");
6033 	    }
6034 	  if (ivdep && cond != error_mark_node)
6035 	    cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
6036 			   build_int_cst (integer_type_node,
6037 			   annot_expr_ivdep_kind));
6038 	}
6039       /* Parse the increment expression (the third expression in a
6040 	 for-statement).  In the case of a foreach-statement, this is
6041 	 the expression that follows the 'in'.  */
6042       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6043 	{
6044 	  if (is_foreach_statement)
6045 	    {
6046 	      c_parser_error (parser, "missing collection in fast enumeration");
6047 	      collection_expression = error_mark_node;
6048 	    }
6049 	  else
6050 	    incr = c_process_expr_stmt (loc, NULL_TREE);
6051 	}
6052       else
6053 	{
6054 	  if (is_foreach_statement)
6055 	    collection_expression = c_fully_fold (c_parser_expression (parser).value,
6056 						  false, NULL);
6057 	  else
6058 	    {
6059 	      struct c_expr ce = c_parser_expression (parser);
6060 	      ce = convert_lvalue_to_rvalue (loc, ce, true, false);
6061 	      incr = c_process_expr_stmt (loc, ce.value);
6062 	    }
6063 	}
6064       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6065     }
6066   save_break = c_break_label;
6067   c_break_label = NULL_TREE;
6068   save_cont = c_cont_label;
6069   c_cont_label = NULL_TREE;
6070 
6071   token_indent_info body_tinfo
6072     = get_token_indent_info (c_parser_peek_token (parser));
6073 
6074   body = c_parser_c99_block_statement (parser, if_p);
6075 
6076   if (is_foreach_statement)
6077     objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
6078   else
6079     c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
6080   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
6081   c_parser_maybe_reclassify_token (parser);
6082 
6083   token_indent_info next_tinfo
6084     = get_token_indent_info (c_parser_peek_token (parser));
6085   warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo);
6086 
6087   c_break_label = save_break;
6088   c_cont_label = save_cont;
6089 }
6090 
6091 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
6092    statement with inputs, outputs, clobbers, and volatile, inline, and goto
6093    tags allowed.
6094 
6095    asm-qualifier:
6096      volatile
6097      inline
6098      goto
6099 
6100    asm-qualifier-list:
6101      asm-qualifier-list asm-qualifier
6102      asm-qualifier
6103 
6104    asm-statement:
6105      asm asm-qualifier-list[opt] ( asm-argument ) ;
6106 
6107    asm-argument:
6108      asm-string-literal
6109      asm-string-literal : asm-operands[opt]
6110      asm-string-literal : asm-operands[opt] : asm-operands[opt]
6111      asm-string-literal : asm-operands[opt] : asm-operands[opt] \
6112        : asm-clobbers[opt]
6113      asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6114        : asm-goto-operands
6115 
6116    The form with asm-goto-operands is valid if and only if the
6117    asm-qualifier-list contains goto, and is the only allowed form in that case.
6118    Duplicate asm-qualifiers are not allowed.  */
6119 
6120 static tree
6121 c_parser_asm_statement (c_parser *parser)
6122 {
6123   tree str, outputs, inputs, clobbers, labels, ret;
6124   bool simple;
6125   location_t asm_loc = c_parser_peek_token (parser)->location;
6126   int section, nsections;
6127 
6128   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
6129   c_parser_consume_token (parser);
6130 
6131   /* Handle the asm-qualifier-list.  */
6132   location_t volatile_loc = UNKNOWN_LOCATION;
6133   location_t inline_loc = UNKNOWN_LOCATION;
6134   location_t goto_loc = UNKNOWN_LOCATION;
6135   for (;;)
6136     {
6137       c_token *token = c_parser_peek_token (parser);
6138       location_t loc = token->location;
6139       switch (token->keyword)
6140 	{
6141 	case RID_VOLATILE:
6142 	  if (volatile_loc)
6143 	    {
6144 	      error_at (loc, "duplicate asm qualifier %qE", token->value);
6145 	      inform (volatile_loc, "first seen here");
6146 	    }
6147 	  else
6148 	    volatile_loc = loc;
6149 	  c_parser_consume_token (parser);
6150 	  continue;
6151 
6152 	case RID_INLINE:
6153 	  if (inline_loc)
6154 	    {
6155 	      error_at (loc, "duplicate asm qualifier %qE", token->value);
6156 	      inform (inline_loc, "first seen here");
6157 	    }
6158 	  else
6159 	    inline_loc = loc;
6160 	  c_parser_consume_token (parser);
6161 	  continue;
6162 
6163 	case RID_GOTO:
6164 	  if (goto_loc)
6165 	    {
6166 	      error_at (loc, "duplicate asm qualifier %qE", token->value);
6167 	      inform (goto_loc, "first seen here");
6168 	    }
6169 	  else
6170 	    goto_loc = loc;
6171 	  c_parser_consume_token (parser);
6172 	  continue;
6173 
6174 	case RID_CONST:
6175 	case RID_RESTRICT:
6176 	  warning_at (loc, 0, "%qE is not an asm qualifier", token->value);
6177 	  c_parser_consume_token (parser);
6178 	  continue;
6179 
6180 	default:
6181 	  break;
6182 	}
6183       break;
6184     }
6185 
6186   bool is_volatile = (volatile_loc != UNKNOWN_LOCATION);
6187   bool is_inline = (inline_loc != UNKNOWN_LOCATION);
6188   bool is_goto = (goto_loc != UNKNOWN_LOCATION);
6189 
6190   /* ??? Follow the C++ parser rather than using the
6191      lex_untranslated_string kludge.  */
6192   parser->lex_untranslated_string = true;
6193   ret = NULL;
6194 
6195   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6196     goto error;
6197 
6198   str = c_parser_asm_string_literal (parser);
6199   if (str == NULL_TREE)
6200     goto error_close_paren;
6201 
6202   simple = true;
6203   outputs = NULL_TREE;
6204   inputs = NULL_TREE;
6205   clobbers = NULL_TREE;
6206   labels = NULL_TREE;
6207 
6208   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
6209     goto done_asm;
6210 
6211   /* Parse each colon-delimited section of operands.  */
6212   nsections = 3 + is_goto;
6213   for (section = 0; section < nsections; ++section)
6214     {
6215       if (!c_parser_require (parser, CPP_COLON,
6216 			     is_goto
6217 			     ? G_("expected %<:%>")
6218 			     : G_("expected %<:%> or %<)%>")))
6219 	goto error_close_paren;
6220 
6221       /* Once past any colon, we're no longer a simple asm.  */
6222       simple = false;
6223 
6224       if ((!c_parser_next_token_is (parser, CPP_COLON)
6225 	   && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6226 	  || section == 3)
6227 	switch (section)
6228 	  {
6229 	  case 0:
6230 	    /* For asm goto, we don't allow output operands, but reserve
6231 	       the slot for a future extension that does allow them.  */
6232 	    if (!is_goto)
6233 	      outputs = c_parser_asm_operands (parser);
6234 	    break;
6235 	  case 1:
6236 	    inputs = c_parser_asm_operands (parser);
6237 	    break;
6238 	  case 2:
6239 	    clobbers = c_parser_asm_clobbers (parser);
6240 	    break;
6241 	  case 3:
6242 	    labels = c_parser_asm_goto_operands (parser);
6243 	    break;
6244 	  default:
6245 	    gcc_unreachable ();
6246 	  }
6247 
6248       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
6249 	goto done_asm;
6250     }
6251 
6252  done_asm:
6253   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6254     {
6255       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6256       goto error;
6257     }
6258 
6259   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
6260     c_parser_skip_to_end_of_block_or_statement (parser);
6261 
6262   ret = build_asm_stmt (is_volatile,
6263 			build_asm_expr (asm_loc, str, outputs, inputs,
6264 					clobbers, labels, simple, is_inline));
6265 
6266  error:
6267   parser->lex_untranslated_string = false;
6268   return ret;
6269 
6270  error_close_paren:
6271   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6272   goto error;
6273 }
6274 
6275 /* Parse asm operands, a GNU extension.
6276 
6277    asm-operands:
6278      asm-operand
6279      asm-operands , asm-operand
6280 
6281    asm-operand:
6282      asm-string-literal ( expression )
6283      [ identifier ] asm-string-literal ( expression )
6284 */
6285 
6286 static tree
6287 c_parser_asm_operands (c_parser *parser)
6288 {
6289   tree list = NULL_TREE;
6290   while (true)
6291     {
6292       tree name, str;
6293       struct c_expr expr;
6294       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
6295 	{
6296 	  c_parser_consume_token (parser);
6297 	  if (c_parser_next_token_is (parser, CPP_NAME))
6298 	    {
6299 	      tree id = c_parser_peek_token (parser)->value;
6300 	      c_parser_consume_token (parser);
6301 	      name = build_string (IDENTIFIER_LENGTH (id),
6302 				   IDENTIFIER_POINTER (id));
6303 	    }
6304 	  else
6305 	    {
6306 	      c_parser_error (parser, "expected identifier");
6307 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
6308 	      return NULL_TREE;
6309 	    }
6310 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6311 				     "expected %<]%>");
6312 	}
6313       else
6314 	name = NULL_TREE;
6315       str = c_parser_asm_string_literal (parser);
6316       if (str == NULL_TREE)
6317 	return NULL_TREE;
6318       parser->lex_untranslated_string = false;
6319       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6320 	{
6321 	  parser->lex_untranslated_string = true;
6322 	  return NULL_TREE;
6323 	}
6324       expr = c_parser_expression (parser);
6325       mark_exp_read (expr.value);
6326       parser->lex_untranslated_string = true;
6327       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6328 	{
6329 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6330 	  return NULL_TREE;
6331 	}
6332       list = chainon (list, build_tree_list (build_tree_list (name, str),
6333 					     expr.value));
6334       if (c_parser_next_token_is (parser, CPP_COMMA))
6335 	c_parser_consume_token (parser);
6336       else
6337 	break;
6338     }
6339   return list;
6340 }
6341 
6342 /* Parse asm clobbers, a GNU extension.
6343 
6344    asm-clobbers:
6345      asm-string-literal
6346      asm-clobbers , asm-string-literal
6347 */
6348 
6349 static tree
6350 c_parser_asm_clobbers (c_parser *parser)
6351 {
6352   tree list = NULL_TREE;
6353   while (true)
6354     {
6355       tree str = c_parser_asm_string_literal (parser);
6356       if (str)
6357 	list = tree_cons (NULL_TREE, str, list);
6358       else
6359 	return NULL_TREE;
6360       if (c_parser_next_token_is (parser, CPP_COMMA))
6361 	c_parser_consume_token (parser);
6362       else
6363 	break;
6364     }
6365   return list;
6366 }
6367 
6368 /* Parse asm goto labels, a GNU extension.
6369 
6370    asm-goto-operands:
6371      identifier
6372      asm-goto-operands , identifier
6373 */
6374 
6375 static tree
6376 c_parser_asm_goto_operands (c_parser *parser)
6377 {
6378   tree list = NULL_TREE;
6379   while (true)
6380     {
6381       tree name, label;
6382 
6383       if (c_parser_next_token_is (parser, CPP_NAME))
6384 	{
6385 	  c_token *tok = c_parser_peek_token (parser);
6386 	  name = tok->value;
6387 	  label = lookup_label_for_goto (tok->location, name);
6388 	  c_parser_consume_token (parser);
6389 	  TREE_USED (label) = 1;
6390 	}
6391       else
6392 	{
6393 	  c_parser_error (parser, "expected identifier");
6394 	  return NULL_TREE;
6395 	}
6396 
6397       name = build_string (IDENTIFIER_LENGTH (name),
6398 			   IDENTIFIER_POINTER (name));
6399       list = tree_cons (name, label, list);
6400       if (c_parser_next_token_is (parser, CPP_COMMA))
6401 	c_parser_consume_token (parser);
6402       else
6403 	return nreverse (list);
6404     }
6405 }
6406 
6407 /* Parse an expression other than a compound expression; that is, an
6408    assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16).  If
6409    AFTER is not NULL then it is an Objective-C message expression which
6410    is the primary-expression starting the expression as an initializer.
6411 
6412    assignment-expression:
6413      conditional-expression
6414      unary-expression assignment-operator assignment-expression
6415 
6416    assignment-operator: one of
6417      = *= /= %= += -= <<= >>= &= ^= |=
6418 
6419    In GNU C we accept any conditional expression on the LHS and
6420    diagnose the invalid lvalue rather than producing a syntax
6421    error.  */
6422 
6423 static struct c_expr
6424 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
6425 			 tree omp_atomic_lhs)
6426 {
6427   struct c_expr lhs, rhs, ret;
6428   enum tree_code code;
6429   location_t op_location, exp_location;
6430   gcc_assert (!after || c_dialect_objc ());
6431   lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
6432   op_location = c_parser_peek_token (parser)->location;
6433   switch (c_parser_peek_token (parser)->type)
6434     {
6435     case CPP_EQ:
6436       code = NOP_EXPR;
6437       break;
6438     case CPP_MULT_EQ:
6439       code = MULT_EXPR;
6440       break;
6441     case CPP_DIV_EQ:
6442       code = TRUNC_DIV_EXPR;
6443       break;
6444     case CPP_MOD_EQ:
6445       code = TRUNC_MOD_EXPR;
6446       break;
6447     case CPP_PLUS_EQ:
6448       code = PLUS_EXPR;
6449       break;
6450     case CPP_MINUS_EQ:
6451       code = MINUS_EXPR;
6452       break;
6453     case CPP_LSHIFT_EQ:
6454       code = LSHIFT_EXPR;
6455       break;
6456     case CPP_RSHIFT_EQ:
6457       code = RSHIFT_EXPR;
6458       break;
6459     case CPP_AND_EQ:
6460       code = BIT_AND_EXPR;
6461       break;
6462     case CPP_XOR_EQ:
6463       code = BIT_XOR_EXPR;
6464       break;
6465     case CPP_OR_EQ:
6466       code = BIT_IOR_EXPR;
6467       break;
6468     default:
6469       return lhs;
6470     }
6471   c_parser_consume_token (parser);
6472   exp_location = c_parser_peek_token (parser)->location;
6473   rhs = c_parser_expr_no_commas (parser, NULL);
6474   rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
6475 
6476   ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
6477 				 code, exp_location, rhs.value,
6478 				 rhs.original_type);
6479   set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ());
6480   if (code == NOP_EXPR)
6481     ret.original_code = MODIFY_EXPR;
6482   else
6483     {
6484       TREE_NO_WARNING (ret.value) = 1;
6485       ret.original_code = ERROR_MARK;
6486     }
6487   ret.original_type = NULL;
6488   return ret;
6489 }
6490 
6491 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15).  If
6492    AFTER is not NULL then it is an Objective-C message expression which is
6493    the primary-expression starting the expression as an initializer.
6494 
6495    conditional-expression:
6496      logical-OR-expression
6497      logical-OR-expression ? expression : conditional-expression
6498 
6499    GNU extensions:
6500 
6501    conditional-expression:
6502      logical-OR-expression ? : conditional-expression
6503 */
6504 
6505 static struct c_expr
6506 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6507 				 tree omp_atomic_lhs)
6508 {
6509   struct c_expr cond, exp1, exp2, ret;
6510   location_t start, cond_loc, colon_loc, middle_loc;
6511 
6512   gcc_assert (!after || c_dialect_objc ());
6513 
6514   cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6515 
6516   if (c_parser_next_token_is_not (parser, CPP_QUERY))
6517     return cond;
6518   if (cond.value != error_mark_node)
6519     start = cond.get_start ();
6520   else
6521     start = UNKNOWN_LOCATION;
6522   cond_loc = c_parser_peek_token (parser)->location;
6523   cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6524   c_parser_consume_token (parser);
6525   if (c_parser_next_token_is (parser, CPP_COLON))
6526     {
6527       tree eptype = NULL_TREE;
6528 
6529       middle_loc = c_parser_peek_token (parser)->location;
6530       pedwarn (middle_loc, OPT_Wpedantic,
6531 	       "ISO C forbids omitting the middle term of a ?: expression");
6532       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6533 	{
6534 	  eptype = TREE_TYPE (cond.value);
6535 	  cond.value = TREE_OPERAND (cond.value, 0);
6536 	}
6537       tree e = cond.value;
6538       while (TREE_CODE (e) == COMPOUND_EXPR)
6539 	e = TREE_OPERAND (e, 1);
6540       warn_for_omitted_condop (middle_loc, e);
6541       /* Make sure first operand is calculated only once.  */
6542       exp1.value = c_save_expr (default_conversion (cond.value));
6543       if (eptype)
6544 	exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6545       exp1.original_type = NULL;
6546       cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6547       c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6548     }
6549   else
6550     {
6551       cond.value
6552 	= c_objc_common_truthvalue_conversion
6553 	(cond_loc, default_conversion (cond.value));
6554       c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6555       exp1 = c_parser_expression_conv (parser);
6556       mark_exp_read (exp1.value);
6557       c_inhibit_evaluation_warnings +=
6558 	((cond.value == truthvalue_true_node)
6559 	 - (cond.value == truthvalue_false_node));
6560     }
6561 
6562   colon_loc = c_parser_peek_token (parser)->location;
6563   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6564     {
6565       c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6566       ret.value = error_mark_node;
6567       ret.original_code = ERROR_MARK;
6568       ret.original_type = NULL;
6569       return ret;
6570     }
6571   {
6572     location_t exp2_loc = c_parser_peek_token (parser)->location;
6573     exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6574     exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6575   }
6576   c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6577   ret.value = build_conditional_expr (colon_loc, cond.value,
6578 				      cond.original_code == C_MAYBE_CONST_EXPR,
6579 				      exp1.value, exp1.original_type,
6580 				      exp2.value, exp2.original_type);
6581   ret.original_code = ERROR_MARK;
6582   if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6583     ret.original_type = NULL;
6584   else
6585     {
6586       tree t1, t2;
6587 
6588       /* If both sides are enum type, the default conversion will have
6589 	 made the type of the result be an integer type.  We want to
6590 	 remember the enum types we started with.  */
6591       t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6592       t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6593       ret.original_type = ((t1 != error_mark_node
6594 			    && t2 != error_mark_node
6595 			    && (TYPE_MAIN_VARIANT (t1)
6596 				== TYPE_MAIN_VARIANT (t2)))
6597 			   ? t1
6598 			   : NULL);
6599     }
6600   set_c_expr_source_range (&ret, start, exp2.get_finish ());
6601   return ret;
6602 }
6603 
6604 /* Parse a binary expression; that is, a logical-OR-expression (C90
6605    6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14).  If AFTER is not
6606    NULL then it is an Objective-C message expression which is the
6607    primary-expression starting the expression as an initializer.
6608 
6609    OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6610    when it should be the unfolded lhs.  In a valid OpenMP source,
6611    one of the operands of the toplevel binary expression must be equal
6612    to it.  In that case, just return a build2 created binary operation
6613    rather than result of parser_build_binary_op.
6614 
6615    multiplicative-expression:
6616      cast-expression
6617      multiplicative-expression * cast-expression
6618      multiplicative-expression / cast-expression
6619      multiplicative-expression % cast-expression
6620 
6621    additive-expression:
6622      multiplicative-expression
6623      additive-expression + multiplicative-expression
6624      additive-expression - multiplicative-expression
6625 
6626    shift-expression:
6627      additive-expression
6628      shift-expression << additive-expression
6629      shift-expression >> additive-expression
6630 
6631    relational-expression:
6632      shift-expression
6633      relational-expression < shift-expression
6634      relational-expression > shift-expression
6635      relational-expression <= shift-expression
6636      relational-expression >= shift-expression
6637 
6638    equality-expression:
6639      relational-expression
6640      equality-expression == relational-expression
6641      equality-expression != relational-expression
6642 
6643    AND-expression:
6644      equality-expression
6645      AND-expression & equality-expression
6646 
6647    exclusive-OR-expression:
6648      AND-expression
6649      exclusive-OR-expression ^ AND-expression
6650 
6651    inclusive-OR-expression:
6652      exclusive-OR-expression
6653      inclusive-OR-expression | exclusive-OR-expression
6654 
6655    logical-AND-expression:
6656      inclusive-OR-expression
6657      logical-AND-expression && inclusive-OR-expression
6658 
6659    logical-OR-expression:
6660      logical-AND-expression
6661      logical-OR-expression || logical-AND-expression
6662 */
6663 
6664 static struct c_expr
6665 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6666 			    tree omp_atomic_lhs)
6667 {
6668   /* A binary expression is parsed using operator-precedence parsing,
6669      with the operands being cast expressions.  All the binary
6670      operators are left-associative.  Thus a binary expression is of
6671      form:
6672 
6673      E0 op1 E1 op2 E2 ...
6674 
6675      which we represent on a stack.  On the stack, the precedence
6676      levels are strictly increasing.  When a new operator is
6677      encountered of higher precedence than that at the top of the
6678      stack, it is pushed; its LHS is the top expression, and its RHS
6679      is everything parsed until it is popped.  When a new operator is
6680      encountered with precedence less than or equal to that at the top
6681      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6682      by the result of the operation until the operator at the top of
6683      the stack has lower precedence than the new operator or there is
6684      only one element on the stack; then the top expression is the LHS
6685      of the new operator.  In the case of logical AND and OR
6686      expressions, we also need to adjust c_inhibit_evaluation_warnings
6687      as appropriate when the operators are pushed and popped.  */
6688 
6689   struct {
6690     /* The expression at this stack level.  */
6691     struct c_expr expr;
6692     /* The precedence of the operator on its left, PREC_NONE at the
6693        bottom of the stack.  */
6694     enum c_parser_prec prec;
6695     /* The operation on its left.  */
6696     enum tree_code op;
6697     /* The source location of this operation.  */
6698     location_t loc;
6699   } stack[NUM_PRECS];
6700   int sp;
6701   /* Location of the binary operator.  */
6702   location_t binary_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
6703 #define POP								      \
6704   do {									      \
6705     switch (stack[sp].op)						      \
6706       {									      \
6707       case TRUTH_ANDIF_EXPR:						      \
6708 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
6709 					  == truthvalue_false_node);	      \
6710 	break;								      \
6711       case TRUTH_ORIF_EXPR:						      \
6712 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
6713 					  == truthvalue_true_node);	      \
6714 	break;								      \
6715       default:								      \
6716 	break;								      \
6717       }									      \
6718     stack[sp - 1].expr							      \
6719       = convert_lvalue_to_rvalue (stack[sp - 1].loc,			      \
6720 				  stack[sp - 1].expr, true, true);	      \
6721     stack[sp].expr							      \
6722       = convert_lvalue_to_rvalue (stack[sp].loc,			      \
6723 				  stack[sp].expr, true, true);		      \
6724     if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1	      \
6725 	&& c_parser_peek_token (parser)->type == CPP_SEMICOLON		      \
6726 	&& ((1 << stack[sp].prec)					      \
6727 	    & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND)    \
6728 	       | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT)))     \
6729 	&& stack[sp].op != TRUNC_MOD_EXPR				      \
6730 	&& stack[0].expr.value != error_mark_node			      \
6731 	&& stack[1].expr.value != error_mark_node			      \
6732 	&& (c_tree_equal (stack[0].expr.value, omp_atomic_lhs)		      \
6733 	    || c_tree_equal (stack[1].expr.value, omp_atomic_lhs)))	      \
6734       stack[0].expr.value						      \
6735 	= build2 (stack[1].op, TREE_TYPE (stack[0].expr.value),		      \
6736 		  stack[0].expr.value, stack[1].expr.value);		      \
6737     else								      \
6738       stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc,	      \
6739 						   stack[sp].op,	      \
6740 						   stack[sp - 1].expr,	      \
6741 						   stack[sp].expr);	      \
6742     sp--;								      \
6743   } while (0)
6744   gcc_assert (!after || c_dialect_objc ());
6745   stack[0].loc = c_parser_peek_token (parser)->location;
6746   stack[0].expr = c_parser_cast_expression (parser, after);
6747   stack[0].prec = PREC_NONE;
6748   sp = 0;
6749   while (true)
6750     {
6751       enum c_parser_prec oprec;
6752       enum tree_code ocode;
6753       source_range src_range;
6754       if (parser->error)
6755 	goto out;
6756       switch (c_parser_peek_token (parser)->type)
6757 	{
6758 	case CPP_MULT:
6759 	  oprec = PREC_MULT;
6760 	  ocode = MULT_EXPR;
6761 	  break;
6762 	case CPP_DIV:
6763 	  oprec = PREC_MULT;
6764 	  ocode = TRUNC_DIV_EXPR;
6765 	  break;
6766 	case CPP_MOD:
6767 	  oprec = PREC_MULT;
6768 	  ocode = TRUNC_MOD_EXPR;
6769 	  break;
6770 	case CPP_PLUS:
6771 	  oprec = PREC_ADD;
6772 	  ocode = PLUS_EXPR;
6773 	  break;
6774 	case CPP_MINUS:
6775 	  oprec = PREC_ADD;
6776 	  ocode = MINUS_EXPR;
6777 	  break;
6778 	case CPP_LSHIFT:
6779 	  oprec = PREC_SHIFT;
6780 	  ocode = LSHIFT_EXPR;
6781 	  break;
6782 	case CPP_RSHIFT:
6783 	  oprec = PREC_SHIFT;
6784 	  ocode = RSHIFT_EXPR;
6785 	  break;
6786 	case CPP_LESS:
6787 	  oprec = PREC_REL;
6788 	  ocode = LT_EXPR;
6789 	  break;
6790 	case CPP_GREATER:
6791 	  oprec = PREC_REL;
6792 	  ocode = GT_EXPR;
6793 	  break;
6794 	case CPP_LESS_EQ:
6795 	  oprec = PREC_REL;
6796 	  ocode = LE_EXPR;
6797 	  break;
6798 	case CPP_GREATER_EQ:
6799 	  oprec = PREC_REL;
6800 	  ocode = GE_EXPR;
6801 	  break;
6802 	case CPP_EQ_EQ:
6803 	  oprec = PREC_EQ;
6804 	  ocode = EQ_EXPR;
6805 	  break;
6806 	case CPP_NOT_EQ:
6807 	  oprec = PREC_EQ;
6808 	  ocode = NE_EXPR;
6809 	  break;
6810 	case CPP_AND:
6811 	  oprec = PREC_BITAND;
6812 	  ocode = BIT_AND_EXPR;
6813 	  break;
6814 	case CPP_XOR:
6815 	  oprec = PREC_BITXOR;
6816 	  ocode = BIT_XOR_EXPR;
6817 	  break;
6818 	case CPP_OR:
6819 	  oprec = PREC_BITOR;
6820 	  ocode = BIT_IOR_EXPR;
6821 	  break;
6822 	case CPP_AND_AND:
6823 	  oprec = PREC_LOGAND;
6824 	  ocode = TRUTH_ANDIF_EXPR;
6825 	  break;
6826 	case CPP_OR_OR:
6827 	  oprec = PREC_LOGOR;
6828 	  ocode = TRUTH_ORIF_EXPR;
6829 	  break;
6830 	default:
6831 	  /* Not a binary operator, so end of the binary
6832 	     expression.  */
6833 	  goto out;
6834 	}
6835       binary_loc = c_parser_peek_token (parser)->location;
6836       while (oprec <= stack[sp].prec)
6837 	POP;
6838       c_parser_consume_token (parser);
6839       switch (ocode)
6840 	{
6841 	case TRUTH_ANDIF_EXPR:
6842 	  src_range = stack[sp].expr.src_range;
6843 	  stack[sp].expr
6844 	    = convert_lvalue_to_rvalue (stack[sp].loc,
6845 					stack[sp].expr, true, true);
6846 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
6847 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
6848 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
6849 					    == truthvalue_false_node);
6850 	  set_c_expr_source_range (&stack[sp].expr, src_range);
6851 	  break;
6852 	case TRUTH_ORIF_EXPR:
6853 	  src_range = stack[sp].expr.src_range;
6854 	  stack[sp].expr
6855 	    = convert_lvalue_to_rvalue (stack[sp].loc,
6856 					stack[sp].expr, true, true);
6857 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
6858 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
6859 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
6860 					    == truthvalue_true_node);
6861 	  set_c_expr_source_range (&stack[sp].expr, src_range);
6862 	  break;
6863 	default:
6864 	  break;
6865 	}
6866       sp++;
6867       stack[sp].loc = binary_loc;
6868       stack[sp].expr = c_parser_cast_expression (parser, NULL);
6869       stack[sp].prec = oprec;
6870       stack[sp].op = ocode;
6871     }
6872  out:
6873   while (sp > 0)
6874     POP;
6875   return stack[0].expr;
6876 #undef POP
6877 }
6878 
6879 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4).  If AFTER
6880    is not NULL then it is an Objective-C message expression which is the
6881    primary-expression starting the expression as an initializer.
6882 
6883    cast-expression:
6884      unary-expression
6885      ( type-name ) unary-expression
6886 */
6887 
6888 static struct c_expr
6889 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
6890 {
6891   location_t cast_loc = c_parser_peek_token (parser)->location;
6892   gcc_assert (!after || c_dialect_objc ());
6893   if (after)
6894     return c_parser_postfix_expression_after_primary (parser,
6895 						      cast_loc, *after);
6896   /* If the expression begins with a parenthesized type name, it may
6897      be either a cast or a compound literal; we need to see whether
6898      the next character is '{' to tell the difference.  If not, it is
6899      an unary expression.  Full detection of unknown typenames here
6900      would require a 3-token lookahead.  */
6901   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6902       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6903     {
6904       struct c_type_name *type_name;
6905       struct c_expr ret;
6906       struct c_expr expr;
6907       c_parser_consume_token (parser);
6908       type_name = c_parser_type_name (parser);
6909       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6910       if (type_name == NULL)
6911 	{
6912 	  ret.value = error_mark_node;
6913 	  ret.original_code = ERROR_MARK;
6914 	  ret.original_type = NULL;
6915 	  return ret;
6916 	}
6917 
6918       /* Save casted types in the function's used types hash table.  */
6919       used_types_insert (type_name->specs->type);
6920 
6921       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6922 	return c_parser_postfix_expression_after_paren_type (parser, type_name,
6923 							     cast_loc);
6924       {
6925 	location_t expr_loc = c_parser_peek_token (parser)->location;
6926 	expr = c_parser_cast_expression (parser, NULL);
6927 	expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
6928       }
6929       ret.value = c_cast_expr (cast_loc, type_name, expr.value);
6930       if (ret.value && expr.value)
6931 	set_c_expr_source_range (&ret, cast_loc, expr.get_finish ());
6932       ret.original_code = ERROR_MARK;
6933       ret.original_type = NULL;
6934       return ret;
6935     }
6936   else
6937     return c_parser_unary_expression (parser);
6938 }
6939 
6940 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
6941 
6942    unary-expression:
6943      postfix-expression
6944      ++ unary-expression
6945      -- unary-expression
6946      unary-operator cast-expression
6947      sizeof unary-expression
6948      sizeof ( type-name )
6949 
6950    unary-operator: one of
6951      & * + - ~ !
6952 
6953    GNU extensions:
6954 
6955    unary-expression:
6956      __alignof__ unary-expression
6957      __alignof__ ( type-name )
6958      && identifier
6959 
6960    (C11 permits _Alignof with type names only.)
6961 
6962    unary-operator: one of
6963      __extension__ __real__ __imag__
6964 
6965    Transactional Memory:
6966 
6967    unary-expression:
6968      transaction-expression
6969 
6970    In addition, the GNU syntax treats ++ and -- as unary operators, so
6971    they may be applied to cast expressions with errors for non-lvalues
6972    given later.  */
6973 
6974 static struct c_expr
6975 c_parser_unary_expression (c_parser *parser)
6976 {
6977   int ext;
6978   struct c_expr ret, op;
6979   location_t op_loc = c_parser_peek_token (parser)->location;
6980   location_t exp_loc;
6981   location_t finish;
6982   ret.original_code = ERROR_MARK;
6983   ret.original_type = NULL;
6984   switch (c_parser_peek_token (parser)->type)
6985     {
6986     case CPP_PLUS_PLUS:
6987       c_parser_consume_token (parser);
6988       exp_loc = c_parser_peek_token (parser)->location;
6989       op = c_parser_cast_expression (parser, NULL);
6990 
6991       /* If there is array notations in op, we expand them.  */
6992       if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6993 	return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op);
6994       else
6995 	{
6996 	  op = default_function_array_read_conversion (exp_loc, op);
6997 	  return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
6998 	}
6999     case CPP_MINUS_MINUS:
7000       c_parser_consume_token (parser);
7001       exp_loc = c_parser_peek_token (parser)->location;
7002       op = c_parser_cast_expression (parser, NULL);
7003 
7004       /* If there is array notations in op, we expand them.  */
7005       if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
7006 	return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op);
7007       else
7008 	{
7009 	  op = default_function_array_read_conversion (exp_loc, op);
7010 	  return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
7011 	}
7012     case CPP_AND:
7013       c_parser_consume_token (parser);
7014       op = c_parser_cast_expression (parser, NULL);
7015       mark_exp_read (op.value);
7016       return parser_build_unary_op (op_loc, ADDR_EXPR, op);
7017     case CPP_MULT:
7018       {
7019 	c_parser_consume_token (parser);
7020 	exp_loc = c_parser_peek_token (parser)->location;
7021 	op = c_parser_cast_expression (parser, NULL);
7022 	finish = op.get_finish ();
7023 	op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7024 	location_t combined_loc = make_location (op_loc, op_loc, finish);
7025 	ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR);
7026 	ret.src_range.m_start = op_loc;
7027 	ret.src_range.m_finish = finish;
7028 	return ret;
7029       }
7030     case CPP_PLUS:
7031       if (!c_dialect_objc () && !in_system_header_at (input_location))
7032 	warning_at (op_loc,
7033 		    OPT_Wtraditional,
7034 		    "traditional C rejects the unary plus operator");
7035       c_parser_consume_token (parser);
7036       exp_loc = c_parser_peek_token (parser)->location;
7037       op = c_parser_cast_expression (parser, NULL);
7038       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7039       return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
7040     case CPP_MINUS:
7041       c_parser_consume_token (parser);
7042       exp_loc = c_parser_peek_token (parser)->location;
7043       op = c_parser_cast_expression (parser, NULL);
7044       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7045       return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
7046     case CPP_COMPL:
7047       c_parser_consume_token (parser);
7048       exp_loc = c_parser_peek_token (parser)->location;
7049       op = c_parser_cast_expression (parser, NULL);
7050       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7051       return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
7052     case CPP_NOT:
7053       c_parser_consume_token (parser);
7054       exp_loc = c_parser_peek_token (parser)->location;
7055       op = c_parser_cast_expression (parser, NULL);
7056       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7057       return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
7058     case CPP_AND_AND:
7059       /* Refer to the address of a label as a pointer.  */
7060       c_parser_consume_token (parser);
7061       if (c_parser_next_token_is (parser, CPP_NAME))
7062 	{
7063 	  ret.value = finish_label_address_expr
7064 	    (c_parser_peek_token (parser)->value, op_loc);
7065 	  set_c_expr_source_range (&ret, op_loc,
7066 				   c_parser_peek_token (parser)->get_finish ());
7067 	  c_parser_consume_token (parser);
7068 	}
7069       else
7070 	{
7071 	  c_parser_error (parser, "expected identifier");
7072 	  ret.value = error_mark_node;
7073 	}
7074 	return ret;
7075     case CPP_KEYWORD:
7076       switch (c_parser_peek_token (parser)->keyword)
7077 	{
7078 	case RID_SIZEOF:
7079 	  return c_parser_sizeof_expression (parser);
7080 	case RID_ALIGNOF:
7081 	  return c_parser_alignof_expression (parser);
7082 	case RID_EXTENSION:
7083 	  c_parser_consume_token (parser);
7084 	  ext = disable_extension_diagnostics ();
7085 	  ret = c_parser_cast_expression (parser, NULL);
7086 	  restore_extension_diagnostics (ext);
7087 	  return ret;
7088 	case RID_REALPART:
7089 	  c_parser_consume_token (parser);
7090 	  exp_loc = c_parser_peek_token (parser)->location;
7091 	  op = c_parser_cast_expression (parser, NULL);
7092 	  op = default_function_array_conversion (exp_loc, op);
7093 	  return parser_build_unary_op (op_loc, REALPART_EXPR, op);
7094 	case RID_IMAGPART:
7095 	  c_parser_consume_token (parser);
7096 	  exp_loc = c_parser_peek_token (parser)->location;
7097 	  op = c_parser_cast_expression (parser, NULL);
7098 	  op = default_function_array_conversion (exp_loc, op);
7099 	  return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
7100 	case RID_TRANSACTION_ATOMIC:
7101 	case RID_TRANSACTION_RELAXED:
7102 	  return c_parser_transaction_expression (parser,
7103 	      c_parser_peek_token (parser)->keyword);
7104 	default:
7105 	  return c_parser_postfix_expression (parser);
7106 	}
7107     default:
7108       return c_parser_postfix_expression (parser);
7109     }
7110 }
7111 
7112 /* Parse a sizeof expression.  */
7113 
7114 static struct c_expr
7115 c_parser_sizeof_expression (c_parser *parser)
7116 {
7117   struct c_expr expr;
7118   struct c_expr result;
7119   location_t expr_loc;
7120   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
7121 
7122   location_t start;
7123   location_t finish = UNKNOWN_LOCATION;
7124 
7125   start = c_parser_peek_token (parser)->location;
7126 
7127   c_parser_consume_token (parser);
7128   c_inhibit_evaluation_warnings++;
7129   in_sizeof++;
7130   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7131       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7132     {
7133       /* Either sizeof ( type-name ) or sizeof unary-expression
7134 	 starting with a compound literal.  */
7135       struct c_type_name *type_name;
7136       c_parser_consume_token (parser);
7137       expr_loc = c_parser_peek_token (parser)->location;
7138       type_name = c_parser_type_name (parser);
7139       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7140       finish = parser->tokens_buf[0].location;
7141       if (type_name == NULL)
7142 	{
7143 	  struct c_expr ret;
7144 	  c_inhibit_evaluation_warnings--;
7145 	  in_sizeof--;
7146 	  ret.value = error_mark_node;
7147 	  ret.original_code = ERROR_MARK;
7148 	  ret.original_type = NULL;
7149 	  return ret;
7150 	}
7151       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7152 	{
7153 	  expr = c_parser_postfix_expression_after_paren_type (parser,
7154 							       type_name,
7155 							       expr_loc);
7156 	  finish = expr.get_finish ();
7157 	  goto sizeof_expr;
7158 	}
7159       /* sizeof ( type-name ).  */
7160       c_inhibit_evaluation_warnings--;
7161       in_sizeof--;
7162       result = c_expr_sizeof_type (expr_loc, type_name);
7163     }
7164   else
7165     {
7166       expr_loc = c_parser_peek_token (parser)->location;
7167       expr = c_parser_unary_expression (parser);
7168       finish = expr.get_finish ();
7169     sizeof_expr:
7170       c_inhibit_evaluation_warnings--;
7171       in_sizeof--;
7172       mark_exp_read (expr.value);
7173       if (TREE_CODE (expr.value) == COMPONENT_REF
7174 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
7175 	error_at (expr_loc, "%<sizeof%> applied to a bit-field");
7176       result = c_expr_sizeof_expr (expr_loc, expr);
7177     }
7178   if (finish != UNKNOWN_LOCATION)
7179     set_c_expr_source_range (&result, start, finish);
7180   return result;
7181 }
7182 
7183 /* Parse an alignof expression.  */
7184 
7185 static struct c_expr
7186 c_parser_alignof_expression (c_parser *parser)
7187 {
7188   struct c_expr expr;
7189   location_t start_loc = c_parser_peek_token (parser)->location;
7190   location_t end_loc;
7191   tree alignof_spelling = c_parser_peek_token (parser)->value;
7192   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
7193   bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
7194 				"_Alignof") == 0;
7195   /* A diagnostic is not required for the use of this identifier in
7196      the implementation namespace; only diagnose it for the C11
7197      spelling because of existing code using the other spellings.  */
7198   if (is_c11_alignof)
7199     {
7200       if (flag_isoc99)
7201 	pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE",
7202 		     alignof_spelling);
7203       else
7204 	pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE",
7205 		     alignof_spelling);
7206     }
7207   c_parser_consume_token (parser);
7208   c_inhibit_evaluation_warnings++;
7209   in_alignof++;
7210   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7211       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7212     {
7213       /* Either __alignof__ ( type-name ) or __alignof__
7214 	 unary-expression starting with a compound literal.  */
7215       location_t loc;
7216       struct c_type_name *type_name;
7217       struct c_expr ret;
7218       c_parser_consume_token (parser);
7219       loc = c_parser_peek_token (parser)->location;
7220       type_name = c_parser_type_name (parser);
7221       end_loc = c_parser_peek_token (parser)->location;
7222       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7223       if (type_name == NULL)
7224 	{
7225 	  struct c_expr ret;
7226 	  c_inhibit_evaluation_warnings--;
7227 	  in_alignof--;
7228 	  ret.value = error_mark_node;
7229 	  ret.original_code = ERROR_MARK;
7230 	  ret.original_type = NULL;
7231 	  return ret;
7232 	}
7233       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7234 	{
7235 	  expr = c_parser_postfix_expression_after_paren_type (parser,
7236 							       type_name,
7237 							       loc);
7238 	  goto alignof_expr;
7239 	}
7240       /* alignof ( type-name ).  */
7241       c_inhibit_evaluation_warnings--;
7242       in_alignof--;
7243       ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
7244 							       NULL, NULL),
7245 					    false, is_c11_alignof, 1);
7246       ret.original_code = ERROR_MARK;
7247       ret.original_type = NULL;
7248       set_c_expr_source_range (&ret, start_loc, end_loc);
7249       return ret;
7250     }
7251   else
7252     {
7253       struct c_expr ret;
7254       expr = c_parser_unary_expression (parser);
7255       end_loc = expr.src_range.m_finish;
7256     alignof_expr:
7257       mark_exp_read (expr.value);
7258       c_inhibit_evaluation_warnings--;
7259       in_alignof--;
7260       if (is_c11_alignof)
7261 	pedwarn (start_loc,
7262 		 OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
7263 		 alignof_spelling);
7264       ret.value = c_alignof_expr (start_loc, expr.value);
7265       ret.original_code = ERROR_MARK;
7266       ret.original_type = NULL;
7267       set_c_expr_source_range (&ret, start_loc, end_loc);
7268       return ret;
7269     }
7270 }
7271 
7272 /* Helper function to read arguments of builtins which are interfaces
7273    for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7274    others.  The name of the builtin is passed using BNAME parameter.
7275    Function returns true if there were no errors while parsing and
7276    stores the arguments in CEXPR_LIST.  If it returns true,
7277    *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7278    parenthesis.  */
7279 static bool
7280 c_parser_get_builtin_args (c_parser *parser, const char *bname,
7281 			   vec<c_expr_t, va_gc> **ret_cexpr_list,
7282 			   bool choose_expr_p,
7283 			   location_t *out_close_paren_loc)
7284 {
7285   location_t loc = c_parser_peek_token (parser)->location;
7286   vec<c_expr_t, va_gc> *cexpr_list;
7287   c_expr_t expr;
7288   bool saved_force_folding_builtin_constant_p;
7289 
7290   *ret_cexpr_list = NULL;
7291   if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
7292     {
7293       error_at (loc, "cannot take address of %qs", bname);
7294       return false;
7295     }
7296 
7297   c_parser_consume_token (parser);
7298 
7299   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7300     {
7301       *out_close_paren_loc = c_parser_peek_token (parser)->location;
7302       c_parser_consume_token (parser);
7303       return true;
7304     }
7305 
7306   saved_force_folding_builtin_constant_p
7307     = force_folding_builtin_constant_p;
7308   force_folding_builtin_constant_p |= choose_expr_p;
7309   expr = c_parser_expr_no_commas (parser, NULL);
7310   force_folding_builtin_constant_p
7311     = saved_force_folding_builtin_constant_p;
7312   vec_alloc (cexpr_list, 1);
7313   vec_safe_push (cexpr_list, expr);
7314   while (c_parser_next_token_is (parser, CPP_COMMA))
7315     {
7316       c_parser_consume_token (parser);
7317       expr = c_parser_expr_no_commas (parser, NULL);
7318       vec_safe_push (cexpr_list, expr);
7319     }
7320 
7321   *out_close_paren_loc = c_parser_peek_token (parser)->location;
7322   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7323     return false;
7324 
7325   *ret_cexpr_list = cexpr_list;
7326   return true;
7327 }
7328 
7329 /* This represents a single generic-association.  */
7330 
7331 struct c_generic_association
7332 {
7333   /* The location of the starting token of the type.  */
7334   location_t type_location;
7335   /* The association's type, or NULL_TREE for 'default'.  */
7336   tree type;
7337   /* The association's expression.  */
7338   struct c_expr expression;
7339 };
7340 
7341 /* Parse a generic-selection.  (C11 6.5.1.1).
7342 
7343    generic-selection:
7344      _Generic ( assignment-expression , generic-assoc-list )
7345 
7346    generic-assoc-list:
7347      generic-association
7348      generic-assoc-list , generic-association
7349 
7350    generic-association:
7351      type-name : assignment-expression
7352      default : assignment-expression
7353 */
7354 
7355 static struct c_expr
7356 c_parser_generic_selection (c_parser *parser)
7357 {
7358   struct c_expr selector, error_expr;
7359   tree selector_type;
7360   struct c_generic_association matched_assoc;
7361   bool match_found = false;
7362   location_t generic_loc, selector_loc;
7363 
7364   error_expr.original_code = ERROR_MARK;
7365   error_expr.original_type = NULL;
7366   error_expr.set_error ();
7367   matched_assoc.type_location = UNKNOWN_LOCATION;
7368   matched_assoc.type = NULL_TREE;
7369   matched_assoc.expression = error_expr;
7370 
7371   gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
7372   generic_loc = c_parser_peek_token (parser)->location;
7373   c_parser_consume_token (parser);
7374   if (flag_isoc99)
7375     pedwarn_c99 (generic_loc, OPT_Wpedantic,
7376 		 "ISO C99 does not support %<_Generic%>");
7377   else
7378     pedwarn_c99 (generic_loc, OPT_Wpedantic,
7379 		 "ISO C90 does not support %<_Generic%>");
7380 
7381   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7382     return error_expr;
7383 
7384   c_inhibit_evaluation_warnings++;
7385   selector_loc = c_parser_peek_token (parser)->location;
7386   selector = c_parser_expr_no_commas (parser, NULL);
7387   selector = default_function_array_conversion (selector_loc, selector);
7388   c_inhibit_evaluation_warnings--;
7389 
7390   if (selector.value == error_mark_node)
7391     {
7392       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7393       return selector;
7394     }
7395   selector_type = TREE_TYPE (selector.value);
7396   /* In ISO C terms, rvalues (including the controlling expression of
7397      _Generic) do not have qualified types.  */
7398   if (TREE_CODE (selector_type) != ARRAY_TYPE)
7399     selector_type = TYPE_MAIN_VARIANT (selector_type);
7400   /* In ISO C terms, _Noreturn is not part of the type of expressions
7401      such as &abort, but in GCC it is represented internally as a type
7402      qualifier.  */
7403   if (FUNCTION_POINTER_TYPE_P (selector_type)
7404       && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
7405     selector_type
7406       = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
7407 
7408   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7409     {
7410       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7411       return error_expr;
7412     }
7413 
7414   auto_vec<c_generic_association> associations;
7415   while (1)
7416     {
7417       struct c_generic_association assoc, *iter;
7418       unsigned int ix;
7419       c_token *token = c_parser_peek_token (parser);
7420 
7421       assoc.type_location = token->location;
7422       if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
7423 	{
7424 	  c_parser_consume_token (parser);
7425 	  assoc.type = NULL_TREE;
7426 	}
7427       else
7428 	{
7429 	  struct c_type_name *type_name;
7430 
7431 	  type_name = c_parser_type_name (parser);
7432 	  if (type_name == NULL)
7433 	    {
7434 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7435 	      return error_expr;
7436 	    }
7437 	  assoc.type = groktypename (type_name, NULL, NULL);
7438 	  if (assoc.type == error_mark_node)
7439 	    {
7440 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7441 	      return error_expr;
7442 	    }
7443 
7444 	  if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
7445 	    error_at (assoc.type_location,
7446 		      "%<_Generic%> association has function type");
7447 	  else if (!COMPLETE_TYPE_P (assoc.type))
7448 	    error_at (assoc.type_location,
7449 		      "%<_Generic%> association has incomplete type");
7450 
7451 	  if (variably_modified_type_p (assoc.type, NULL_TREE))
7452 	    error_at (assoc.type_location,
7453 		      "%<_Generic%> association has "
7454 		      "variable length type");
7455 	}
7456 
7457       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7458 	{
7459 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7460 	  return error_expr;
7461 	}
7462 
7463       assoc.expression = c_parser_expr_no_commas (parser, NULL);
7464       if (assoc.expression.value == error_mark_node)
7465 	{
7466 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7467 	  return error_expr;
7468 	}
7469 
7470       for (ix = 0; associations.iterate (ix, &iter); ++ix)
7471 	{
7472 	  if (assoc.type == NULL_TREE)
7473 	    {
7474 	      if (iter->type == NULL_TREE)
7475 		{
7476 		  error_at (assoc.type_location,
7477 			    "duplicate %<default%> case in %<_Generic%>");
7478 		  inform (iter->type_location, "original %<default%> is here");
7479 		}
7480 	    }
7481 	  else if (iter->type != NULL_TREE)
7482 	    {
7483 	      if (comptypes (assoc.type, iter->type))
7484 		{
7485 		  error_at (assoc.type_location,
7486 			    "%<_Generic%> specifies two compatible types");
7487 		  inform (iter->type_location, "compatible type is here");
7488 		}
7489 	    }
7490 	}
7491 
7492       if (assoc.type == NULL_TREE)
7493 	{
7494 	  if (!match_found)
7495 	    {
7496 	      matched_assoc = assoc;
7497 	      match_found = true;
7498 	    }
7499 	}
7500       else if (comptypes (assoc.type, selector_type))
7501 	{
7502 	  if (!match_found || matched_assoc.type == NULL_TREE)
7503 	    {
7504 	      matched_assoc = assoc;
7505 	      match_found = true;
7506 	    }
7507 	  else
7508 	    {
7509 	      error_at (assoc.type_location,
7510 			"%<_Generic%> selector matches multiple associations");
7511 	      inform (matched_assoc.type_location,
7512 		      "other match is here");
7513 	    }
7514 	}
7515 
7516       associations.safe_push (assoc);
7517 
7518       if (c_parser_peek_token (parser)->type != CPP_COMMA)
7519 	break;
7520       c_parser_consume_token (parser);
7521     }
7522 
7523   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7524     {
7525       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7526       return error_expr;
7527     }
7528 
7529   if (!match_found)
7530     {
7531       error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7532 		"compatible with any association",
7533 		selector_type);
7534       return error_expr;
7535     }
7536 
7537   return matched_assoc.expression;
7538 }
7539 
7540 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7541    C11 6.5.1-6.5.2).
7542 
7543    postfix-expression:
7544      primary-expression
7545      postfix-expression [ expression ]
7546      postfix-expression ( argument-expression-list[opt] )
7547      postfix-expression . identifier
7548      postfix-expression -> identifier
7549      postfix-expression ++
7550      postfix-expression --
7551      ( type-name ) { initializer-list }
7552      ( type-name ) { initializer-list , }
7553 
7554    argument-expression-list:
7555      argument-expression
7556      argument-expression-list , argument-expression
7557 
7558    primary-expression:
7559      identifier
7560      constant
7561      string-literal
7562      ( expression )
7563      generic-selection
7564 
7565    GNU extensions:
7566 
7567    primary-expression:
7568      __func__
7569        (treated as a keyword in GNU C)
7570      __FUNCTION__
7571      __PRETTY_FUNCTION__
7572      ( compound-statement )
7573      __builtin_va_arg ( assignment-expression , type-name )
7574      __builtin_offsetof ( type-name , offsetof-member-designator )
7575      __builtin_choose_expr ( assignment-expression ,
7576 			     assignment-expression ,
7577 			     assignment-expression )
7578      __builtin_types_compatible_p ( type-name , type-name )
7579      __builtin_complex ( assignment-expression , assignment-expression )
7580      __builtin_shuffle ( assignment-expression , assignment-expression )
7581      __builtin_shuffle ( assignment-expression ,
7582 			 assignment-expression ,
7583 			 assignment-expression, )
7584 
7585    offsetof-member-designator:
7586      identifier
7587      offsetof-member-designator . identifier
7588      offsetof-member-designator [ expression ]
7589 
7590    Objective-C:
7591 
7592    primary-expression:
7593      [ objc-receiver objc-message-args ]
7594      @selector ( objc-selector-arg )
7595      @protocol ( identifier )
7596      @encode ( type-name )
7597      objc-string-literal
7598      Classname . identifier
7599 */
7600 
7601 static struct c_expr
7602 c_parser_postfix_expression (c_parser *parser)
7603 {
7604   struct c_expr expr, e1;
7605   struct c_type_name *t1, *t2;
7606   location_t loc = c_parser_peek_token (parser)->location;;
7607   source_range tok_range = c_parser_peek_token (parser)->get_range ();
7608   expr.original_code = ERROR_MARK;
7609   expr.original_type = NULL;
7610   switch (c_parser_peek_token (parser)->type)
7611     {
7612     case CPP_NUMBER:
7613       expr.value = c_parser_peek_token (parser)->value;
7614       set_c_expr_source_range (&expr, tok_range);
7615       loc = c_parser_peek_token (parser)->location;
7616       c_parser_consume_token (parser);
7617       if (TREE_CODE (expr.value) == FIXED_CST
7618 	  && !targetm.fixed_point_supported_p ())
7619 	{
7620 	  error_at (loc, "fixed-point types not supported for this target");
7621 	  expr.value = error_mark_node;
7622 	}
7623       break;
7624     case CPP_CHAR:
7625     case CPP_CHAR16:
7626     case CPP_CHAR32:
7627     case CPP_WCHAR:
7628       expr.value = c_parser_peek_token (parser)->value;
7629       /* For the purpose of warning when a pointer is compared with
7630 	 a zero character constant.  */
7631       expr.original_type = char_type_node;
7632       set_c_expr_source_range (&expr, tok_range);
7633       c_parser_consume_token (parser);
7634       break;
7635     case CPP_STRING:
7636     case CPP_STRING16:
7637     case CPP_STRING32:
7638     case CPP_WSTRING:
7639     case CPP_UTF8STRING:
7640       expr.value = c_parser_peek_token (parser)->value;
7641       set_c_expr_source_range (&expr, tok_range);
7642       expr.original_code = STRING_CST;
7643       c_parser_consume_token (parser);
7644       break;
7645     case CPP_OBJC_STRING:
7646       gcc_assert (c_dialect_objc ());
7647       expr.value
7648 	= objc_build_string_object (c_parser_peek_token (parser)->value);
7649       set_c_expr_source_range (&expr, tok_range);
7650       c_parser_consume_token (parser);
7651       break;
7652     case CPP_NAME:
7653       switch (c_parser_peek_token (parser)->id_kind)
7654 	{
7655 	case C_ID_ID:
7656 	  {
7657 	    tree id = c_parser_peek_token (parser)->value;
7658 	    c_parser_consume_token (parser);
7659 	    expr.value = build_external_ref (loc, id,
7660 					     (c_parser_peek_token (parser)->type
7661 					      == CPP_OPEN_PAREN),
7662 					     &expr.original_type);
7663 	    set_c_expr_source_range (&expr, tok_range);
7664 	    break;
7665 	  }
7666 	case C_ID_CLASSNAME:
7667 	  {
7668 	    /* Here we parse the Objective-C 2.0 Class.name dot
7669 	       syntax.  */
7670 	    tree class_name = c_parser_peek_token (parser)->value;
7671 	    tree component;
7672 	    c_parser_consume_token (parser);
7673 	    gcc_assert (c_dialect_objc ());
7674 	    if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7675 	      {
7676 		expr.set_error ();
7677 		break;
7678 	      }
7679 	    if (c_parser_next_token_is_not (parser, CPP_NAME))
7680 	      {
7681 		c_parser_error (parser, "expected identifier");
7682 		expr.set_error ();
7683 		break;
7684 	      }
7685 	    c_token *component_tok = c_parser_peek_token (parser);
7686 	    component = component_tok->value;
7687 	    location_t end_loc = component_tok->get_finish ();
7688 	    c_parser_consume_token (parser);
7689 	    expr.value = objc_build_class_component_ref (class_name,
7690 							 component);
7691 	    set_c_expr_source_range (&expr, loc, end_loc);
7692 	    break;
7693 	  }
7694 	default:
7695 	  c_parser_error (parser, "expected expression");
7696 	  expr.set_error ();
7697 	  break;
7698 	}
7699       break;
7700     case CPP_OPEN_PAREN:
7701       /* A parenthesized expression, statement expression or compound
7702 	 literal.  */
7703       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7704 	{
7705 	  /* A statement expression.  */
7706 	  tree stmt;
7707 	  location_t brace_loc;
7708 	  c_parser_consume_token (parser);
7709 	  brace_loc = c_parser_peek_token (parser)->location;
7710 	  c_parser_consume_token (parser);
7711 	  if (!building_stmt_list_p ())
7712 	    {
7713 	      error_at (loc, "braced-group within expression allowed "
7714 			"only inside a function");
7715 	      parser->error = true;
7716 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7717 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7718 	      expr.set_error ();
7719 	      break;
7720 	    }
7721 	  stmt = c_begin_stmt_expr ();
7722 	  c_parser_compound_statement_nostart (parser);
7723 	  location_t close_loc = c_parser_peek_token (parser)->location;
7724 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7725 				     "expected %<)%>");
7726 	  pedwarn (loc, OPT_Wpedantic,
7727 		   "ISO C forbids braced-groups within expressions");
7728 	  expr.value = c_finish_stmt_expr (brace_loc, stmt);
7729 	  set_c_expr_source_range (&expr, loc, close_loc);
7730 	  mark_exp_read (expr.value);
7731 	}
7732       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7733 	{
7734 	  /* A compound literal.  ??? Can we actually get here rather
7735 	     than going directly to
7736 	     c_parser_postfix_expression_after_paren_type from
7737 	     elsewhere?  */
7738 	  location_t loc;
7739 	  struct c_type_name *type_name;
7740 	  c_parser_consume_token (parser);
7741 	  loc = c_parser_peek_token (parser)->location;
7742 	  type_name = c_parser_type_name (parser);
7743 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7744 				     "expected %<)%>");
7745 	  if (type_name == NULL)
7746 	    {
7747 	      expr.set_error ();
7748 	    }
7749 	  else
7750 	    expr = c_parser_postfix_expression_after_paren_type (parser,
7751 								 type_name,
7752 								 loc);
7753 	}
7754       else
7755 	{
7756 	  /* A parenthesized expression.  */
7757 	  location_t loc_open_paren = c_parser_peek_token (parser)->location;
7758 	  c_parser_consume_token (parser);
7759 	  expr = c_parser_expression (parser);
7760 	  if (TREE_CODE (expr.value) == MODIFY_EXPR)
7761 	    TREE_NO_WARNING (expr.value) = 1;
7762 	  if (expr.original_code != C_MAYBE_CONST_EXPR)
7763 	    expr.original_code = ERROR_MARK;
7764 	  /* Don't change EXPR.ORIGINAL_TYPE.  */
7765 	  location_t loc_close_paren = c_parser_peek_token (parser)->location;
7766 	  set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren);
7767 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7768 				     "expected %<)%>");
7769 	}
7770       break;
7771     case CPP_KEYWORD:
7772       switch (c_parser_peek_token (parser)->keyword)
7773 	{
7774 	case RID_FUNCTION_NAME:
7775 	  pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7776 		   "%<__FUNCTION__%> predefined identifier");
7777 	  expr.value = fname_decl (loc,
7778 				   c_parser_peek_token (parser)->keyword,
7779 				   c_parser_peek_token (parser)->value);
7780 	  set_c_expr_source_range (&expr, loc, loc);
7781 	  c_parser_consume_token (parser);
7782 	  break;
7783 	case RID_PRETTY_FUNCTION_NAME:
7784 	  pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7785 		   "%<__PRETTY_FUNCTION__%> predefined identifier");
7786 	  expr.value = fname_decl (loc,
7787 				   c_parser_peek_token (parser)->keyword,
7788 				   c_parser_peek_token (parser)->value);
7789 	  set_c_expr_source_range (&expr, loc, loc);
7790 	  c_parser_consume_token (parser);
7791 	  break;
7792 	case RID_C99_FUNCTION_NAME:
7793 	  pedwarn_c90 (loc, OPT_Wpedantic,  "ISO C90 does not support "
7794 		   "%<__func__%> predefined identifier");
7795 	  expr.value = fname_decl (loc,
7796 				   c_parser_peek_token (parser)->keyword,
7797 				   c_parser_peek_token (parser)->value);
7798 	  set_c_expr_source_range (&expr, loc, loc);
7799 	  c_parser_consume_token (parser);
7800 	  break;
7801 	case RID_VA_ARG:
7802 	  {
7803 	    location_t start_loc = loc;
7804 	    c_parser_consume_token (parser);
7805 	    if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7806 	      {
7807 		expr.set_error ();
7808 		break;
7809 	      }
7810 	    e1 = c_parser_expr_no_commas (parser, NULL);
7811 	    mark_exp_read (e1.value);
7812 	    e1.value = c_fully_fold (e1.value, false, NULL);
7813 	    if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7814 	      {
7815 		c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7816 		expr.set_error ();
7817 		break;
7818 	      }
7819 	    loc = c_parser_peek_token (parser)->location;
7820 	    t1 = c_parser_type_name (parser);
7821 	    location_t end_loc = c_parser_peek_token (parser)->get_finish ();
7822 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7823 				       "expected %<)%>");
7824 	    if (t1 == NULL)
7825 	      {
7826 		expr.set_error ();
7827 	      }
7828 	    else
7829 	      {
7830 		tree type_expr = NULL_TREE;
7831 		expr.value = c_build_va_arg (start_loc, e1.value, loc,
7832 					     groktypename (t1, &type_expr, NULL));
7833 		if (type_expr)
7834 		  {
7835 		    expr.value = build2 (C_MAYBE_CONST_EXPR,
7836 					 TREE_TYPE (expr.value), type_expr,
7837 					 expr.value);
7838 		    C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
7839 		  }
7840 		set_c_expr_source_range (&expr, start_loc, end_loc);
7841 	      }
7842 	  }
7843 	  break;
7844 	case RID_OFFSETOF:
7845 	  c_parser_consume_token (parser);
7846 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7847 	    {
7848 	      expr.set_error ();
7849 	      break;
7850 	    }
7851 	  t1 = c_parser_type_name (parser);
7852 	  if (t1 == NULL)
7853 	    parser->error = true;
7854 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7855             gcc_assert (parser->error);
7856 	  if (parser->error)
7857 	    {
7858 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7859 	      expr.set_error ();
7860 	      break;
7861 	    }
7862 
7863 	  {
7864 	    tree type = groktypename (t1, NULL, NULL);
7865 	    tree offsetof_ref;
7866 	    if (type == error_mark_node)
7867 	      offsetof_ref = error_mark_node;
7868 	    else
7869 	      {
7870 		offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
7871 		SET_EXPR_LOCATION (offsetof_ref, loc);
7872 	      }
7873 	    /* Parse the second argument to __builtin_offsetof.  We
7874 	       must have one identifier, and beyond that we want to
7875 	       accept sub structure and sub array references.  */
7876 	    if (c_parser_next_token_is (parser, CPP_NAME))
7877 	      {
7878 		c_token *comp_tok = c_parser_peek_token (parser);
7879 		offsetof_ref = build_component_ref
7880 		  (loc, offsetof_ref, comp_tok->value, comp_tok->location);
7881 		c_parser_consume_token (parser);
7882 		while (c_parser_next_token_is (parser, CPP_DOT)
7883 		       || c_parser_next_token_is (parser,
7884 						  CPP_OPEN_SQUARE)
7885 		       || c_parser_next_token_is (parser,
7886 						  CPP_DEREF))
7887 		  {
7888 		    if (c_parser_next_token_is (parser, CPP_DEREF))
7889 		      {
7890 			loc = c_parser_peek_token (parser)->location;
7891 			offsetof_ref = build_array_ref (loc,
7892 							offsetof_ref,
7893 							integer_zero_node);
7894 			goto do_dot;
7895 		      }
7896 		    else if (c_parser_next_token_is (parser, CPP_DOT))
7897 		      {
7898 		      do_dot:
7899 			c_parser_consume_token (parser);
7900 			if (c_parser_next_token_is_not (parser,
7901 							CPP_NAME))
7902 			  {
7903 			    c_parser_error (parser, "expected identifier");
7904 			    break;
7905 			  }
7906 			c_token *comp_tok = c_parser_peek_token (parser);
7907 			offsetof_ref = build_component_ref
7908 			  (loc, offsetof_ref, comp_tok->value,
7909 			   comp_tok->location);
7910 			c_parser_consume_token (parser);
7911 		      }
7912 		    else
7913 		      {
7914 			struct c_expr ce;
7915 			tree idx;
7916 			loc = c_parser_peek_token (parser)->location;
7917 			c_parser_consume_token (parser);
7918 			ce = c_parser_expression (parser);
7919 			ce = convert_lvalue_to_rvalue (loc, ce, false, false);
7920 			idx = ce.value;
7921 			idx = c_fully_fold (idx, false, NULL);
7922 			c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7923 						   "expected %<]%>");
7924 			offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
7925 		      }
7926 		  }
7927 	      }
7928 	    else
7929 	      c_parser_error (parser, "expected identifier");
7930 	    location_t end_loc = c_parser_peek_token (parser)->get_finish ();
7931 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7932 				       "expected %<)%>");
7933 	    expr.value = fold_offsetof (offsetof_ref);
7934 	    set_c_expr_source_range (&expr, loc, end_loc);
7935 	  }
7936 	  break;
7937 	case RID_CHOOSE_EXPR:
7938 	  {
7939 	    vec<c_expr_t, va_gc> *cexpr_list;
7940 	    c_expr_t *e1_p, *e2_p, *e3_p;
7941 	    tree c;
7942 	    location_t close_paren_loc;
7943 
7944 	    c_parser_consume_token (parser);
7945 	    if (!c_parser_get_builtin_args (parser,
7946 					    "__builtin_choose_expr",
7947 					    &cexpr_list, true,
7948 					    &close_paren_loc))
7949 	      {
7950 		expr.set_error ();
7951 		break;
7952 	      }
7953 
7954 	    if (vec_safe_length (cexpr_list) != 3)
7955 	      {
7956 		error_at (loc, "wrong number of arguments to "
7957 			       "%<__builtin_choose_expr%>");
7958 		expr.set_error ();
7959 		break;
7960 	      }
7961 
7962 	    e1_p = &(*cexpr_list)[0];
7963 	    e2_p = &(*cexpr_list)[1];
7964 	    e3_p = &(*cexpr_list)[2];
7965 
7966 	    c = e1_p->value;
7967 	    mark_exp_read (e2_p->value);
7968 	    mark_exp_read (e3_p->value);
7969 	    if (TREE_CODE (c) != INTEGER_CST
7970 		|| !INTEGRAL_TYPE_P (TREE_TYPE (c)))
7971 	      error_at (loc,
7972 			"first argument to %<__builtin_choose_expr%> not"
7973 			" a constant");
7974 	    constant_expression_warning (c);
7975 	    expr = integer_zerop (c) ? *e3_p : *e2_p;
7976 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
7977 	    break;
7978 	  }
7979 	case RID_TYPES_COMPATIBLE_P:
7980 	  c_parser_consume_token (parser);
7981 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7982 	    {
7983 	      expr.set_error ();
7984 	      break;
7985 	    }
7986 	  t1 = c_parser_type_name (parser);
7987 	  if (t1 == NULL)
7988 	    {
7989 	      expr.set_error ();
7990 	      break;
7991 	    }
7992 	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7993 	    {
7994 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7995 	      expr.set_error ();
7996 	      break;
7997 	    }
7998 	  t2 = c_parser_type_name (parser);
7999 	  if (t2 == NULL)
8000 	    {
8001 	      expr.set_error ();
8002 	      break;
8003 	    }
8004 	  {
8005 	    location_t close_paren_loc = c_parser_peek_token (parser)->location;
8006 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8007 				       "expected %<)%>");
8008 	    tree e1, e2;
8009 	    e1 = groktypename (t1, NULL, NULL);
8010 	    e2 = groktypename (t2, NULL, NULL);
8011 	    if (e1 == error_mark_node || e2 == error_mark_node)
8012 	      {
8013 		expr.set_error ();
8014 		break;
8015 	      }
8016 
8017 	    e1 = TYPE_MAIN_VARIANT (e1);
8018 	    e2 = TYPE_MAIN_VARIANT (e2);
8019 
8020 	    expr.value
8021 	      = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
8022 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8023 	  }
8024 	  break;
8025 	case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
8026 	  {
8027 	    vec<c_expr_t, va_gc> *cexpr_list;
8028 	    c_expr_t *e2_p;
8029 	    tree chain_value;
8030 	    location_t close_paren_loc;
8031 
8032 	    c_parser_consume_token (parser);
8033 	    if (!c_parser_get_builtin_args (parser,
8034 					    "__builtin_call_with_static_chain",
8035 					    &cexpr_list, false,
8036 					    &close_paren_loc))
8037 	      {
8038 		expr.set_error ();
8039 		break;
8040 	      }
8041 	    if (vec_safe_length (cexpr_list) != 2)
8042 	      {
8043 		error_at (loc, "wrong number of arguments to "
8044 			       "%<__builtin_call_with_static_chain%>");
8045 		expr.set_error ();
8046 		break;
8047 	      }
8048 
8049 	    expr = (*cexpr_list)[0];
8050 	    e2_p = &(*cexpr_list)[1];
8051 	    *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
8052 	    chain_value = e2_p->value;
8053 	    mark_exp_read (chain_value);
8054 
8055 	    if (TREE_CODE (expr.value) != CALL_EXPR)
8056 	      error_at (loc, "first argument to "
8057 			"%<__builtin_call_with_static_chain%> "
8058 			"must be a call expression");
8059 	    else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
8060 	      error_at (loc, "second argument to "
8061 			"%<__builtin_call_with_static_chain%> "
8062 			"must be a pointer type");
8063 	    else
8064 	      CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
8065 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8066 	    break;
8067 	  }
8068 	case RID_BUILTIN_COMPLEX:
8069 	  {
8070 	    vec<c_expr_t, va_gc> *cexpr_list;
8071 	    c_expr_t *e1_p, *e2_p;
8072 	    location_t close_paren_loc;
8073 
8074 	    c_parser_consume_token (parser);
8075 	    if (!c_parser_get_builtin_args (parser,
8076 					    "__builtin_complex",
8077 					    &cexpr_list, false,
8078 					    &close_paren_loc))
8079 	      {
8080 		expr.set_error ();
8081 		break;
8082 	      }
8083 
8084 	    if (vec_safe_length (cexpr_list) != 2)
8085 	      {
8086 		error_at (loc, "wrong number of arguments to "
8087 			       "%<__builtin_complex%>");
8088 		expr.set_error ();
8089 		break;
8090 	      }
8091 
8092 	    e1_p = &(*cexpr_list)[0];
8093 	    e2_p = &(*cexpr_list)[1];
8094 
8095 	    *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
8096 	    if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
8097 	      e1_p->value = convert (TREE_TYPE (e1_p->value),
8098 				     TREE_OPERAND (e1_p->value, 0));
8099 	    *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
8100 	    if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
8101 	      e2_p->value = convert (TREE_TYPE (e2_p->value),
8102 				     TREE_OPERAND (e2_p->value, 0));
8103 	    if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
8104 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
8105 		|| !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
8106 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
8107 	      {
8108 		error_at (loc, "%<__builtin_complex%> operand "
8109 			  "not of real binary floating-point type");
8110 		expr.set_error ();
8111 		break;
8112 	      }
8113 	    if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
8114 		!= TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
8115 	      {
8116 		error_at (loc,
8117 			  "%<__builtin_complex%> operands of different types");
8118 		expr.set_error ();
8119 		break;
8120 	      }
8121 	    pedwarn_c90 (loc, OPT_Wpedantic,
8122 			 "ISO C90 does not support complex types");
8123 	    expr.value = build2_loc (loc, COMPLEX_EXPR,
8124 				     build_complex_type
8125 				     (TYPE_MAIN_VARIANT
8126 				      (TREE_TYPE (e1_p->value))),
8127 				     e1_p->value, e2_p->value);
8128 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8129 	    break;
8130 	  }
8131 	case RID_BUILTIN_SHUFFLE:
8132 	  {
8133 	    vec<c_expr_t, va_gc> *cexpr_list;
8134 	    unsigned int i;
8135 	    c_expr_t *p;
8136 	    location_t close_paren_loc;
8137 
8138 	    c_parser_consume_token (parser);
8139 	    if (!c_parser_get_builtin_args (parser,
8140 					    "__builtin_shuffle",
8141 					    &cexpr_list, false,
8142 					    &close_paren_loc))
8143 	      {
8144 		expr.set_error ();
8145 		break;
8146 	      }
8147 
8148 	    FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
8149 	      *p = convert_lvalue_to_rvalue (loc, *p, true, true);
8150 
8151 	    if (vec_safe_length (cexpr_list) == 2)
8152 	      expr.value =
8153 		c_build_vec_perm_expr
8154 		  (loc, (*cexpr_list)[0].value,
8155 		   NULL_TREE, (*cexpr_list)[1].value);
8156 
8157 	    else if (vec_safe_length (cexpr_list) == 3)
8158 	      expr.value =
8159 		c_build_vec_perm_expr
8160 		  (loc, (*cexpr_list)[0].value,
8161 		   (*cexpr_list)[1].value,
8162 		   (*cexpr_list)[2].value);
8163 	    else
8164 	      {
8165 		error_at (loc, "wrong number of arguments to "
8166 			       "%<__builtin_shuffle%>");
8167 		expr.set_error ();
8168 	      }
8169 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8170 	    break;
8171 	  }
8172 	case RID_AT_SELECTOR:
8173 	  gcc_assert (c_dialect_objc ());
8174 	  c_parser_consume_token (parser);
8175 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8176 	    {
8177 	      expr.set_error ();
8178 	      break;
8179 	    }
8180 	  {
8181 	    tree sel = c_parser_objc_selector_arg (parser);
8182 	    location_t close_loc = c_parser_peek_token (parser)->location;
8183 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8184 				       "expected %<)%>");
8185 	    expr.value = objc_build_selector_expr (loc, sel);
8186 	    set_c_expr_source_range (&expr, loc, close_loc);
8187 	  }
8188 	  break;
8189 	case RID_AT_PROTOCOL:
8190 	  gcc_assert (c_dialect_objc ());
8191 	  c_parser_consume_token (parser);
8192 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8193 	    {
8194 	      expr.set_error ();
8195 	      break;
8196 	    }
8197 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
8198 	    {
8199 	      c_parser_error (parser, "expected identifier");
8200 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8201 	      expr.set_error ();
8202 	      break;
8203 	    }
8204 	  {
8205 	    tree id = c_parser_peek_token (parser)->value;
8206 	    c_parser_consume_token (parser);
8207 	    location_t close_loc = c_parser_peek_token (parser)->location;
8208 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8209 				       "expected %<)%>");
8210 	    expr.value = objc_build_protocol_expr (id);
8211 	    set_c_expr_source_range (&expr, loc, close_loc);
8212 	  }
8213 	  break;
8214 	case RID_AT_ENCODE:
8215 	  /* Extension to support C-structures in the archiver.  */
8216 	  gcc_assert (c_dialect_objc ());
8217 	  c_parser_consume_token (parser);
8218 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8219 	    {
8220 	      expr.set_error ();
8221 	      break;
8222 	    }
8223 	  t1 = c_parser_type_name (parser);
8224 	  if (t1 == NULL)
8225 	    {
8226 	      expr.set_error ();
8227 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8228 	      break;
8229 	    }
8230 	  {
8231 	    location_t close_loc = c_parser_peek_token (parser)->location;
8232 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8233 				     "expected %<)%>");
8234 	    tree type = groktypename (t1, NULL, NULL);
8235 	    expr.value = objc_build_encode_expr (type);
8236 	    set_c_expr_source_range (&expr, loc, close_loc);
8237 	  }
8238 	  break;
8239 	case RID_GENERIC:
8240 	  expr = c_parser_generic_selection (parser);
8241 	  break;
8242 	case RID_CILK_SPAWN:
8243 	  c_parser_consume_token (parser);
8244 	  if (!flag_cilkplus)
8245 	    {
8246 	      error_at (loc, "-fcilkplus must be enabled to use "
8247 			"%<_Cilk_spawn%>");
8248 	      expr = c_parser_cast_expression (parser, NULL);
8249 	      expr.set_error ();
8250 	    }
8251 	  else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
8252 	    {
8253 	      error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
8254 			"are not permitted");
8255 	      /* Now flush out all the _Cilk_spawns.  */
8256 	      while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
8257 		c_parser_consume_token (parser);
8258 	      expr = c_parser_cast_expression (parser, NULL);
8259 	    }
8260 	  else
8261 	    {
8262 	      expr = c_parser_cast_expression (parser, NULL);
8263 	      expr.value = build_cilk_spawn (loc, expr.value);
8264 	    }
8265 	  break;
8266 	default:
8267 	  c_parser_error (parser, "expected expression");
8268 	  expr.set_error ();
8269 	  break;
8270 	}
8271       break;
8272     case CPP_OPEN_SQUARE:
8273       if (c_dialect_objc ())
8274 	{
8275 	  tree receiver, args;
8276 	  c_parser_consume_token (parser);
8277 	  receiver = c_parser_objc_receiver (parser);
8278 	  args = c_parser_objc_message_args (parser);
8279 	  location_t close_loc = c_parser_peek_token (parser)->location;
8280 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
8281 				     "expected %<]%>");
8282 	  expr.value = objc_build_message_expr (receiver, args);
8283 	  set_c_expr_source_range (&expr, loc, close_loc);
8284 	  break;
8285 	}
8286       /* Else fall through to report error.  */
8287       /* FALLTHRU */
8288     default:
8289       c_parser_error (parser, "expected expression");
8290       expr.set_error ();
8291       break;
8292     }
8293   return c_parser_postfix_expression_after_primary
8294     (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr);
8295 }
8296 
8297 /* Parse a postfix expression after a parenthesized type name: the
8298    brace-enclosed initializer of a compound literal, possibly followed
8299    by some postfix operators.  This is separate because it is not
8300    possible to tell until after the type name whether a cast
8301    expression has a cast or a compound literal, or whether the operand
8302    of sizeof is a parenthesized type name or starts with a compound
8303    literal.  TYPE_LOC is the location where TYPE_NAME starts--the
8304    location of the first token after the parentheses around the type
8305    name.  */
8306 
8307 static struct c_expr
8308 c_parser_postfix_expression_after_paren_type (c_parser *parser,
8309 					      struct c_type_name *type_name,
8310 					      location_t type_loc)
8311 {
8312   tree type;
8313   struct c_expr init;
8314   bool non_const;
8315   struct c_expr expr;
8316   location_t start_loc;
8317   tree type_expr = NULL_TREE;
8318   bool type_expr_const = true;
8319   check_compound_literal_type (type_loc, type_name);
8320   rich_location richloc (line_table, type_loc);
8321   start_init (NULL_TREE, NULL, 0, &richloc);
8322   type = groktypename (type_name, &type_expr, &type_expr_const);
8323   start_loc = c_parser_peek_token (parser)->location;
8324   if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
8325     {
8326       error_at (type_loc, "compound literal has variable size");
8327       type = error_mark_node;
8328     }
8329   init = c_parser_braced_init (parser, type, false, NULL);
8330   finish_init ();
8331   maybe_warn_string_init (type_loc, type, init);
8332 
8333   if (type != error_mark_node
8334       && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
8335       && current_function_decl)
8336     {
8337       error ("compound literal qualified by address-space qualifier");
8338       type = error_mark_node;
8339     }
8340 
8341   pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
8342   non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
8343 	       ? CONSTRUCTOR_NON_CONST (init.value)
8344 	       : init.original_code == C_MAYBE_CONST_EXPR);
8345   non_const |= !type_expr_const;
8346   expr.value = build_compound_literal (start_loc, type, init.value, non_const);
8347   set_c_expr_source_range (&expr, init.src_range);
8348   expr.original_code = ERROR_MARK;
8349   expr.original_type = NULL;
8350   if (type != error_mark_node
8351       && expr.value != error_mark_node
8352       && type_expr)
8353     {
8354       if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
8355 	{
8356 	  gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
8357 	  C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
8358 	}
8359       else
8360 	{
8361 	  gcc_assert (!non_const);
8362 	  expr.value = build2 (C_MAYBE_CONST_EXPR, type,
8363 			       type_expr, expr.value);
8364 	}
8365     }
8366   return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
8367 }
8368 
8369 /* Callback function for sizeof_pointer_memaccess_warning to compare
8370    types.  */
8371 
8372 static bool
8373 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
8374 {
8375   return comptypes (type1, type2) == 1;
8376 }
8377 
8378 /* Parse a postfix expression after the initial primary or compound
8379    literal; that is, parse a series of postfix operators.
8380 
8381    EXPR_LOC is the location of the primary expression.  */
8382 
8383 static struct c_expr
8384 c_parser_postfix_expression_after_primary (c_parser *parser,
8385 					   location_t expr_loc,
8386 					   struct c_expr expr)
8387 {
8388   struct c_expr orig_expr;
8389   tree ident, idx;
8390   location_t sizeof_arg_loc[3], comp_loc;
8391   tree sizeof_arg[3];
8392   unsigned int literal_zero_mask;
8393   unsigned int i;
8394   vec<tree, va_gc> *exprlist;
8395   vec<tree, va_gc> *origtypes = NULL;
8396   vec<location_t> arg_loc = vNULL;
8397   location_t start;
8398   location_t finish;
8399 
8400   while (true)
8401     {
8402       location_t op_loc = c_parser_peek_token (parser)->location;
8403       switch (c_parser_peek_token (parser)->type)
8404 	{
8405 	case CPP_OPEN_SQUARE:
8406 	  /* Array reference.  */
8407 	  c_parser_consume_token (parser);
8408 	  if (flag_cilkplus
8409 	      && c_parser_peek_token (parser)->type == CPP_COLON)
8410 	    /* If we are here, then we have something like this:
8411 	       Array [ : ]
8412 	    */
8413 	    expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE,
8414 						  expr.value);
8415 	  else
8416 	    {
8417 	      idx = c_parser_expression (parser).value;
8418 	      /* Here we have 3 options:
8419 		 1. Array [EXPR] -- Normal Array call.
8420 		 2. Array [EXPR : EXPR] -- Array notation without stride.
8421 		 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8422 
8423 		 For 1, we just handle it just like a normal array expression.
8424 		 For 2 and 3 we handle it like we handle array notations.  The
8425 		 idx value we have above becomes the initial/start index.
8426 	      */
8427 	      if (flag_cilkplus
8428 		  && c_parser_peek_token (parser)->type == CPP_COLON)
8429 		expr.value = c_parser_array_notation (expr_loc, parser, idx,
8430 						      expr.value);
8431 	      else
8432 		{
8433 		  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
8434 					     "expected %<]%>");
8435 		  start = expr.get_start ();
8436 		  finish = parser->tokens_buf[0].location;
8437 		  expr.value = build_array_ref (op_loc, expr.value, idx);
8438 		  set_c_expr_source_range (&expr, start, finish);
8439 		}
8440 	    }
8441 	  expr.original_code = ERROR_MARK;
8442 	  expr.original_type = NULL;
8443 	  break;
8444 	case CPP_OPEN_PAREN:
8445 	  /* Function call.  */
8446 	  c_parser_consume_token (parser);
8447 	  for (i = 0; i < 3; i++)
8448 	    {
8449 	      sizeof_arg[i] = NULL_TREE;
8450 	      sizeof_arg_loc[i] = UNKNOWN_LOCATION;
8451 	    }
8452 	  literal_zero_mask = 0;
8453 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8454 	    exprlist = NULL;
8455 	  else
8456 	    exprlist = c_parser_expr_list (parser, true, false, &origtypes,
8457 					   sizeof_arg_loc, sizeof_arg,
8458 					   &arg_loc, &literal_zero_mask);
8459 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8460 				     "expected %<)%>");
8461 	  orig_expr = expr;
8462 	  mark_exp_read (expr.value);
8463 	  if (warn_sizeof_pointer_memaccess)
8464 	    sizeof_pointer_memaccess_warning (sizeof_arg_loc,
8465 					      expr.value, exprlist,
8466 					      sizeof_arg,
8467 					      sizeof_ptr_memacc_comptypes);
8468 	  if (TREE_CODE (expr.value) == FUNCTION_DECL
8469 	      && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
8470 	      && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
8471 	      && vec_safe_length (exprlist) == 3)
8472 	    {
8473 	      tree arg0 = (*exprlist)[0];
8474 	      tree arg2 = (*exprlist)[2];
8475 	      warn_for_memset (expr_loc, arg0, arg2, literal_zero_mask);
8476 	    }
8477 
8478 	  start = expr.get_start ();
8479 	  finish = parser->tokens_buf[0].get_finish ();
8480 	  expr.value
8481 	    = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
8482 					 exprlist, origtypes);
8483 	  set_c_expr_source_range (&expr, start, finish);
8484 
8485 	  expr.original_code = ERROR_MARK;
8486 	  if (TREE_CODE (expr.value) == INTEGER_CST
8487 	      && TREE_CODE (orig_expr.value) == FUNCTION_DECL
8488 	      && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
8489 	      && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
8490 	    expr.original_code = C_MAYBE_CONST_EXPR;
8491 	  expr.original_type = NULL;
8492 	  if (exprlist)
8493 	    {
8494 	      release_tree_vector (exprlist);
8495 	      release_tree_vector (origtypes);
8496 	    }
8497 	  arg_loc.release ();
8498 	  break;
8499 	case CPP_DOT:
8500 	  /* Structure element reference.  */
8501 	  c_parser_consume_token (parser);
8502 	  expr = default_function_array_conversion (expr_loc, expr);
8503 	  if (c_parser_next_token_is (parser, CPP_NAME))
8504 	    {
8505 	      c_token *comp_tok = c_parser_peek_token (parser);
8506 	      ident = comp_tok->value;
8507 	      comp_loc = comp_tok->location;
8508 	    }
8509 	  else
8510 	    {
8511 	      c_parser_error (parser, "expected identifier");
8512 	      expr.set_error ();
8513 	      expr.original_code = ERROR_MARK;
8514               expr.original_type = NULL;
8515 	      return expr;
8516 	    }
8517 	  start = expr.get_start ();
8518 	  finish = c_parser_peek_token (parser)->get_finish ();
8519 	  c_parser_consume_token (parser);
8520 	  expr.value = build_component_ref (op_loc, expr.value, ident,
8521 					    comp_loc);
8522 	  set_c_expr_source_range (&expr, start, finish);
8523 	  expr.original_code = ERROR_MARK;
8524 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
8525 	    expr.original_type = NULL;
8526 	  else
8527 	    {
8528 	      /* Remember the original type of a bitfield.  */
8529 	      tree field = TREE_OPERAND (expr.value, 1);
8530 	      if (TREE_CODE (field) != FIELD_DECL)
8531 		expr.original_type = NULL;
8532 	      else
8533 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
8534 	    }
8535 	  break;
8536 	case CPP_DEREF:
8537 	  /* Structure element reference.  */
8538 	  c_parser_consume_token (parser);
8539 	  expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
8540 	  if (c_parser_next_token_is (parser, CPP_NAME))
8541 	    {
8542 	      c_token *comp_tok = c_parser_peek_token (parser);
8543 	      ident = comp_tok->value;
8544 	      comp_loc = comp_tok->location;
8545 	    }
8546 	  else
8547 	    {
8548 	      c_parser_error (parser, "expected identifier");
8549 	      expr.set_error ();
8550 	      expr.original_code = ERROR_MARK;
8551 	      expr.original_type = NULL;
8552 	      return expr;
8553 	    }
8554 	  start = expr.get_start ();
8555 	  finish = c_parser_peek_token (parser)->get_finish ();
8556 	  c_parser_consume_token (parser);
8557 	  expr.value = build_component_ref (op_loc,
8558 					    build_indirect_ref (op_loc,
8559 								expr.value,
8560 								RO_ARROW),
8561 					    ident, comp_loc);
8562 	  set_c_expr_source_range (&expr, start, finish);
8563 	  expr.original_code = ERROR_MARK;
8564 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
8565 	    expr.original_type = NULL;
8566 	  else
8567 	    {
8568 	      /* Remember the original type of a bitfield.  */
8569 	      tree field = TREE_OPERAND (expr.value, 1);
8570 	      if (TREE_CODE (field) != FIELD_DECL)
8571 		expr.original_type = NULL;
8572 	      else
8573 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
8574 	    }
8575 	  break;
8576 	case CPP_PLUS_PLUS:
8577 	  /* Postincrement.  */
8578 	  start = expr.get_start ();
8579 	  finish = c_parser_peek_token (parser)->get_finish ();
8580 	  c_parser_consume_token (parser);
8581 	  /* If the expressions have array notations, we expand them.  */
8582 	  if (flag_cilkplus
8583 	      && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8584 	    expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr);
8585 	  else
8586 	    {
8587 	      expr = default_function_array_read_conversion (expr_loc, expr);
8588 	      expr.value = build_unary_op (op_loc, POSTINCREMENT_EXPR,
8589 					   expr.value, false);
8590 	    }
8591 	  set_c_expr_source_range (&expr, start, finish);
8592 	  expr.original_code = ERROR_MARK;
8593 	  expr.original_type = NULL;
8594 	  break;
8595 	case CPP_MINUS_MINUS:
8596 	  /* Postdecrement.  */
8597 	  start = expr.get_start ();
8598 	  finish = c_parser_peek_token (parser)->get_finish ();
8599 	  c_parser_consume_token (parser);
8600 	  /* If the expressions have array notations, we expand them.  */
8601 	  if (flag_cilkplus
8602 	      && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8603 	    expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr);
8604 	  else
8605 	    {
8606 	      expr = default_function_array_read_conversion (expr_loc, expr);
8607 	      expr.value = build_unary_op (op_loc, POSTDECREMENT_EXPR,
8608 					   expr.value, false);
8609 	    }
8610 	  set_c_expr_source_range (&expr, start, finish);
8611 	  expr.original_code = ERROR_MARK;
8612 	  expr.original_type = NULL;
8613 	  break;
8614 	default:
8615 	  return expr;
8616 	}
8617     }
8618 }
8619 
8620 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
8621 
8622    expression:
8623      assignment-expression
8624      expression , assignment-expression
8625 */
8626 
8627 static struct c_expr
8628 c_parser_expression (c_parser *parser)
8629 {
8630   location_t tloc = c_parser_peek_token (parser)->location;
8631   struct c_expr expr;
8632   expr = c_parser_expr_no_commas (parser, NULL);
8633   if (c_parser_next_token_is (parser, CPP_COMMA))
8634     expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
8635   while (c_parser_next_token_is (parser, CPP_COMMA))
8636     {
8637       struct c_expr next;
8638       tree lhsval;
8639       location_t loc = c_parser_peek_token (parser)->location;
8640       location_t expr_loc;
8641       c_parser_consume_token (parser);
8642       expr_loc = c_parser_peek_token (parser)->location;
8643       lhsval = expr.value;
8644       while (TREE_CODE (lhsval) == COMPOUND_EXPR)
8645 	lhsval = TREE_OPERAND (lhsval, 1);
8646       if (DECL_P (lhsval) || handled_component_p (lhsval))
8647 	mark_exp_read (lhsval);
8648       next = c_parser_expr_no_commas (parser, NULL);
8649       next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
8650       expr.value = build_compound_expr (loc, expr.value, next.value);
8651       expr.original_code = COMPOUND_EXPR;
8652       expr.original_type = next.original_type;
8653     }
8654   return expr;
8655 }
8656 
8657 /* Parse an expression and convert functions or arrays to pointers and
8658    lvalues to rvalues.  */
8659 
8660 static struct c_expr
8661 c_parser_expression_conv (c_parser *parser)
8662 {
8663   struct c_expr expr;
8664   location_t loc = c_parser_peek_token (parser)->location;
8665   expr = c_parser_expression (parser);
8666   expr = convert_lvalue_to_rvalue (loc, expr, true, false);
8667   return expr;
8668 }
8669 
8670 /* Helper function of c_parser_expr_list.  Check if IDXth (0 based)
8671    argument is a literal zero alone and if so, set it in literal_zero_mask.  */
8672 
8673 static inline void
8674 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
8675 			     unsigned int idx)
8676 {
8677   if (idx >= HOST_BITS_PER_INT)
8678     return;
8679 
8680   c_token *tok = c_parser_peek_token (parser);
8681   switch (tok->type)
8682     {
8683     case CPP_NUMBER:
8684     case CPP_CHAR:
8685     case CPP_WCHAR:
8686     case CPP_CHAR16:
8687     case CPP_CHAR32:
8688       /* If a parameter is literal zero alone, remember it
8689 	 for -Wmemset-transposed-args warning.  */
8690       if (integer_zerop (tok->value)
8691 	  && !TREE_OVERFLOW (tok->value)
8692 	  && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8693 	      || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
8694 	*literal_zero_mask |= 1U << idx;
8695     default:
8696       break;
8697     }
8698 }
8699 
8700 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
8701    functions and arrays to pointers and lvalues to rvalues.  If
8702    FOLD_P, fold the expressions.  If LOCATIONS is non-NULL, save the
8703    locations of function arguments into this vector.
8704 
8705    nonempty-expr-list:
8706      assignment-expression
8707      nonempty-expr-list , assignment-expression
8708 */
8709 
8710 static vec<tree, va_gc> *
8711 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
8712 		    vec<tree, va_gc> **p_orig_types,
8713 		    location_t *sizeof_arg_loc, tree *sizeof_arg,
8714 		    vec<location_t> *locations,
8715 		    unsigned int *literal_zero_mask)
8716 {
8717   vec<tree, va_gc> *ret;
8718   vec<tree, va_gc> *orig_types;
8719   struct c_expr expr;
8720   location_t loc = c_parser_peek_token (parser)->location;
8721   location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8722   unsigned int idx = 0;
8723 
8724   ret = make_tree_vector ();
8725   if (p_orig_types == NULL)
8726     orig_types = NULL;
8727   else
8728     orig_types = make_tree_vector ();
8729 
8730   if (sizeof_arg != NULL
8731       && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8732     cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8733   if (literal_zero_mask)
8734     c_parser_check_literal_zero (parser, literal_zero_mask, 0);
8735   expr = c_parser_expr_no_commas (parser, NULL);
8736   if (convert_p)
8737     expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8738   if (fold_p)
8739     expr.value = c_fully_fold (expr.value, false, NULL);
8740   ret->quick_push (expr.value);
8741   if (orig_types)
8742     orig_types->quick_push (expr.original_type);
8743   if (locations)
8744     locations->safe_push (loc);
8745   if (sizeof_arg != NULL
8746       && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8747       && expr.original_code == SIZEOF_EXPR)
8748     {
8749       sizeof_arg[0] = c_last_sizeof_arg;
8750       sizeof_arg_loc[0] = cur_sizeof_arg_loc;
8751     }
8752   while (c_parser_next_token_is (parser, CPP_COMMA))
8753     {
8754       c_parser_consume_token (parser);
8755       loc = c_parser_peek_token (parser)->location;
8756       if (sizeof_arg != NULL
8757 	  && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8758 	cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8759       else
8760 	cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8761       if (literal_zero_mask)
8762 	c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
8763       expr = c_parser_expr_no_commas (parser, NULL);
8764       if (convert_p)
8765 	expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8766       if (fold_p)
8767 	expr.value = c_fully_fold (expr.value, false, NULL);
8768       vec_safe_push (ret, expr.value);
8769       if (orig_types)
8770 	vec_safe_push (orig_types, expr.original_type);
8771       if (locations)
8772 	locations->safe_push (loc);
8773       if (++idx < 3
8774 	  && sizeof_arg != NULL
8775 	  && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8776 	  && expr.original_code == SIZEOF_EXPR)
8777 	{
8778 	  sizeof_arg[idx] = c_last_sizeof_arg;
8779 	  sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
8780 	}
8781     }
8782   if (orig_types)
8783     *p_orig_types = orig_types;
8784   return ret;
8785 }
8786 
8787 /* Parse Objective-C-specific constructs.  */
8788 
8789 /* Parse an objc-class-definition.
8790 
8791    objc-class-definition:
8792      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8793        objc-class-instance-variables[opt] objc-methodprotolist @end
8794      @implementation identifier objc-superclass[opt]
8795        objc-class-instance-variables[opt]
8796      @interface identifier ( identifier ) objc-protocol-refs[opt]
8797        objc-methodprotolist @end
8798      @interface identifier ( ) objc-protocol-refs[opt]
8799        objc-methodprotolist @end
8800      @implementation identifier ( identifier )
8801 
8802    objc-superclass:
8803      : identifier
8804 
8805    "@interface identifier (" must start "@interface identifier (
8806    identifier ) ...": objc-methodprotolist in the first production may
8807    not start with a parenthesized identifier as a declarator of a data
8808    definition with no declaration specifiers if the objc-superclass,
8809    objc-protocol-refs and objc-class-instance-variables are omitted.  */
8810 
8811 static void
8812 c_parser_objc_class_definition (c_parser *parser, tree attributes)
8813 {
8814   bool iface_p;
8815   tree id1;
8816   tree superclass;
8817   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
8818     iface_p = true;
8819   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
8820     iface_p = false;
8821   else
8822     gcc_unreachable ();
8823 
8824   c_parser_consume_token (parser);
8825   if (c_parser_next_token_is_not (parser, CPP_NAME))
8826     {
8827       c_parser_error (parser, "expected identifier");
8828       return;
8829     }
8830   id1 = c_parser_peek_token (parser)->value;
8831   c_parser_consume_token (parser);
8832   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8833     {
8834       /* We have a category or class extension.  */
8835       tree id2;
8836       tree proto = NULL_TREE;
8837       c_parser_consume_token (parser);
8838       if (c_parser_next_token_is_not (parser, CPP_NAME))
8839 	{
8840 	  if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8841 	    {
8842 	      /* We have a class extension.  */
8843 	      id2 = NULL_TREE;
8844 	    }
8845 	  else
8846 	    {
8847 	      c_parser_error (parser, "expected identifier or %<)%>");
8848 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8849 	      return;
8850 	    }
8851 	}
8852       else
8853 	{
8854 	  id2 = c_parser_peek_token (parser)->value;
8855 	  c_parser_consume_token (parser);
8856 	}
8857       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8858       if (!iface_p)
8859 	{
8860 	  objc_start_category_implementation (id1, id2);
8861 	  return;
8862 	}
8863       if (c_parser_next_token_is (parser, CPP_LESS))
8864 	proto = c_parser_objc_protocol_refs (parser);
8865       objc_start_category_interface (id1, id2, proto, attributes);
8866       c_parser_objc_methodprotolist (parser);
8867       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8868       objc_finish_interface ();
8869       return;
8870     }
8871   if (c_parser_next_token_is (parser, CPP_COLON))
8872     {
8873       c_parser_consume_token (parser);
8874       if (c_parser_next_token_is_not (parser, CPP_NAME))
8875 	{
8876 	  c_parser_error (parser, "expected identifier");
8877 	  return;
8878 	}
8879       superclass = c_parser_peek_token (parser)->value;
8880       c_parser_consume_token (parser);
8881     }
8882   else
8883     superclass = NULL_TREE;
8884   if (iface_p)
8885     {
8886       tree proto = NULL_TREE;
8887       if (c_parser_next_token_is (parser, CPP_LESS))
8888 	proto = c_parser_objc_protocol_refs (parser);
8889       objc_start_class_interface (id1, superclass, proto, attributes);
8890     }
8891   else
8892     objc_start_class_implementation (id1, superclass);
8893   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8894     c_parser_objc_class_instance_variables (parser);
8895   if (iface_p)
8896     {
8897       objc_continue_interface ();
8898       c_parser_objc_methodprotolist (parser);
8899       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8900       objc_finish_interface ();
8901     }
8902   else
8903     {
8904       objc_continue_implementation ();
8905       return;
8906     }
8907 }
8908 
8909 /* Parse objc-class-instance-variables.
8910 
8911    objc-class-instance-variables:
8912      { objc-instance-variable-decl-list[opt] }
8913 
8914    objc-instance-variable-decl-list:
8915      objc-visibility-spec
8916      objc-instance-variable-decl ;
8917      ;
8918      objc-instance-variable-decl-list objc-visibility-spec
8919      objc-instance-variable-decl-list objc-instance-variable-decl ;
8920      objc-instance-variable-decl-list ;
8921 
8922    objc-visibility-spec:
8923      @private
8924      @protected
8925      @public
8926 
8927    objc-instance-variable-decl:
8928      struct-declaration
8929 */
8930 
8931 static void
8932 c_parser_objc_class_instance_variables (c_parser *parser)
8933 {
8934   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
8935   c_parser_consume_token (parser);
8936   while (c_parser_next_token_is_not (parser, CPP_EOF))
8937     {
8938       tree decls;
8939       /* Parse any stray semicolon.  */
8940       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8941 	{
8942 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8943 		   "extra semicolon");
8944 	  c_parser_consume_token (parser);
8945 	  continue;
8946 	}
8947       /* Stop if at the end of the instance variables.  */
8948       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8949 	{
8950 	  c_parser_consume_token (parser);
8951 	  break;
8952 	}
8953       /* Parse any objc-visibility-spec.  */
8954       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
8955 	{
8956 	  c_parser_consume_token (parser);
8957 	  objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
8958 	  continue;
8959 	}
8960       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
8961 	{
8962 	  c_parser_consume_token (parser);
8963 	  objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
8964 	  continue;
8965 	}
8966       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
8967 	{
8968 	  c_parser_consume_token (parser);
8969 	  objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
8970 	  continue;
8971 	}
8972       else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
8973 	{
8974 	  c_parser_consume_token (parser);
8975 	  objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
8976 	  continue;
8977 	}
8978       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
8979 	{
8980 	  c_parser_pragma (parser, pragma_external, NULL);
8981 	  continue;
8982 	}
8983 
8984       /* Parse some comma-separated declarations.  */
8985       decls = c_parser_struct_declaration (parser);
8986       if (decls == NULL)
8987 	{
8988 	  /* There is a syntax error.  We want to skip the offending
8989 	     tokens up to the next ';' (included) or '}'
8990 	     (excluded).  */
8991 
8992 	  /* First, skip manually a ')' or ']'.  This is because they
8993 	     reduce the nesting level, so c_parser_skip_until_found()
8994 	     wouldn't be able to skip past them.  */
8995 	  c_token *token = c_parser_peek_token (parser);
8996 	  if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
8997 	    c_parser_consume_token (parser);
8998 
8999 	  /* Then, do the standard skipping.  */
9000 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9001 
9002 	  /* We hopefully recovered.  Start normal parsing again.  */
9003 	  parser->error = false;
9004 	  continue;
9005 	}
9006       else
9007 	{
9008 	  /* Comma-separated instance variables are chained together
9009 	     in reverse order; add them one by one.  */
9010 	  tree ivar = nreverse (decls);
9011 	  for (; ivar; ivar = DECL_CHAIN (ivar))
9012 	    objc_add_instance_variable (copy_node (ivar));
9013 	}
9014       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9015     }
9016 }
9017 
9018 /* Parse an objc-class-declaration.
9019 
9020    objc-class-declaration:
9021      @class identifier-list ;
9022 */
9023 
9024 static void
9025 c_parser_objc_class_declaration (c_parser *parser)
9026 {
9027   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
9028   c_parser_consume_token (parser);
9029   /* Any identifiers, including those declared as type names, are OK
9030      here.  */
9031   while (true)
9032     {
9033       tree id;
9034       if (c_parser_next_token_is_not (parser, CPP_NAME))
9035 	{
9036 	  c_parser_error (parser, "expected identifier");
9037 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9038 	  parser->error = false;
9039 	  return;
9040 	}
9041       id = c_parser_peek_token (parser)->value;
9042       objc_declare_class (id);
9043       c_parser_consume_token (parser);
9044       if (c_parser_next_token_is (parser, CPP_COMMA))
9045 	c_parser_consume_token (parser);
9046       else
9047 	break;
9048     }
9049   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9050 }
9051 
9052 /* Parse an objc-alias-declaration.
9053 
9054    objc-alias-declaration:
9055      @compatibility_alias identifier identifier ;
9056 */
9057 
9058 static void
9059 c_parser_objc_alias_declaration (c_parser *parser)
9060 {
9061   tree id1, id2;
9062   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
9063   c_parser_consume_token (parser);
9064   if (c_parser_next_token_is_not (parser, CPP_NAME))
9065     {
9066       c_parser_error (parser, "expected identifier");
9067       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9068       return;
9069     }
9070   id1 = c_parser_peek_token (parser)->value;
9071   c_parser_consume_token (parser);
9072   if (c_parser_next_token_is_not (parser, CPP_NAME))
9073     {
9074       c_parser_error (parser, "expected identifier");
9075       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9076       return;
9077     }
9078   id2 = c_parser_peek_token (parser)->value;
9079   c_parser_consume_token (parser);
9080   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9081   objc_declare_alias (id1, id2);
9082 }
9083 
9084 /* Parse an objc-protocol-definition.
9085 
9086    objc-protocol-definition:
9087      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9088      @protocol identifier-list ;
9089 
9090    "@protocol identifier ;" should be resolved as "@protocol
9091    identifier-list ;": objc-methodprotolist may not start with a
9092    semicolon in the first alternative if objc-protocol-refs are
9093    omitted.  */
9094 
9095 static void
9096 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
9097 {
9098   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
9099 
9100   c_parser_consume_token (parser);
9101   if (c_parser_next_token_is_not (parser, CPP_NAME))
9102     {
9103       c_parser_error (parser, "expected identifier");
9104       return;
9105     }
9106   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
9107       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
9108     {
9109       /* Any identifiers, including those declared as type names, are
9110 	 OK here.  */
9111       while (true)
9112 	{
9113 	  tree id;
9114 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
9115 	    {
9116 	      c_parser_error (parser, "expected identifier");
9117 	      break;
9118 	    }
9119 	  id = c_parser_peek_token (parser)->value;
9120 	  objc_declare_protocol (id, attributes);
9121 	  c_parser_consume_token (parser);
9122 	  if (c_parser_next_token_is (parser, CPP_COMMA))
9123 	    c_parser_consume_token (parser);
9124 	  else
9125 	    break;
9126 	}
9127       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9128     }
9129   else
9130     {
9131       tree id = c_parser_peek_token (parser)->value;
9132       tree proto = NULL_TREE;
9133       c_parser_consume_token (parser);
9134       if (c_parser_next_token_is (parser, CPP_LESS))
9135 	proto = c_parser_objc_protocol_refs (parser);
9136       parser->objc_pq_context = true;
9137       objc_start_protocol (id, proto, attributes);
9138       c_parser_objc_methodprotolist (parser);
9139       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
9140       parser->objc_pq_context = false;
9141       objc_finish_interface ();
9142     }
9143 }
9144 
9145 /* Parse an objc-method-type.
9146 
9147    objc-method-type:
9148      +
9149      -
9150 
9151    Return true if it is a class method (+) and false if it is
9152    an instance method (-).
9153 */
9154 static inline bool
9155 c_parser_objc_method_type (c_parser *parser)
9156 {
9157   switch (c_parser_peek_token (parser)->type)
9158     {
9159     case CPP_PLUS:
9160       c_parser_consume_token (parser);
9161       return true;
9162     case CPP_MINUS:
9163       c_parser_consume_token (parser);
9164       return false;
9165     default:
9166       gcc_unreachable ();
9167     }
9168 }
9169 
9170 /* Parse an objc-method-definition.
9171 
9172    objc-method-definition:
9173      objc-method-type objc-method-decl ;[opt] compound-statement
9174 */
9175 
9176 static void
9177 c_parser_objc_method_definition (c_parser *parser)
9178 {
9179   bool is_class_method = c_parser_objc_method_type (parser);
9180   tree decl, attributes = NULL_TREE, expr = NULL_TREE;
9181   parser->objc_pq_context = true;
9182   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
9183 				    &expr);
9184   if (decl == error_mark_node)
9185     return;  /* Bail here. */
9186 
9187   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9188     {
9189       c_parser_consume_token (parser);
9190       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9191 	       "extra semicolon in method definition specified");
9192     }
9193 
9194   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9195     {
9196       c_parser_error (parser, "expected %<{%>");
9197       return;
9198     }
9199 
9200   parser->objc_pq_context = false;
9201   if (objc_start_method_definition (is_class_method, decl, attributes, expr))
9202     {
9203       add_stmt (c_parser_compound_statement (parser));
9204       objc_finish_method_definition (current_function_decl);
9205     }
9206   else
9207     {
9208       /* This code is executed when we find a method definition
9209 	 outside of an @implementation context (or invalid for other
9210 	 reasons).  Parse the method (to keep going) but do not emit
9211 	 any code.
9212       */
9213       c_parser_compound_statement (parser);
9214     }
9215 }
9216 
9217 /* Parse an objc-methodprotolist.
9218 
9219    objc-methodprotolist:
9220      empty
9221      objc-methodprotolist objc-methodproto
9222      objc-methodprotolist declaration
9223      objc-methodprotolist ;
9224      @optional
9225      @required
9226 
9227    The declaration is a data definition, which may be missing
9228    declaration specifiers under the same rules and diagnostics as
9229    other data definitions outside functions, and the stray semicolon
9230    is diagnosed the same way as a stray semicolon outside a
9231    function.  */
9232 
9233 static void
9234 c_parser_objc_methodprotolist (c_parser *parser)
9235 {
9236   while (true)
9237     {
9238       /* The list is terminated by @end.  */
9239       switch (c_parser_peek_token (parser)->type)
9240 	{
9241 	case CPP_SEMICOLON:
9242 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9243 		   "ISO C does not allow extra %<;%> outside of a function");
9244 	  c_parser_consume_token (parser);
9245 	  break;
9246 	case CPP_PLUS:
9247 	case CPP_MINUS:
9248 	  c_parser_objc_methodproto (parser);
9249 	  break;
9250 	case CPP_PRAGMA:
9251 	  c_parser_pragma (parser, pragma_external, NULL);
9252 	  break;
9253 	case CPP_EOF:
9254 	  return;
9255 	default:
9256 	  if (c_parser_next_token_is_keyword (parser, RID_AT_END))
9257 	    return;
9258 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
9259 	    c_parser_objc_at_property_declaration (parser);
9260 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
9261 	    {
9262 	      objc_set_method_opt (true);
9263 	      c_parser_consume_token (parser);
9264 	    }
9265 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
9266 	    {
9267 	      objc_set_method_opt (false);
9268 	      c_parser_consume_token (parser);
9269 	    }
9270 	  else
9271 	    c_parser_declaration_or_fndef (parser, false, false, true,
9272 					   false, true, NULL, vNULL);
9273 	  break;
9274 	}
9275     }
9276 }
9277 
9278 /* Parse an objc-methodproto.
9279 
9280    objc-methodproto:
9281      objc-method-type objc-method-decl ;
9282 */
9283 
9284 static void
9285 c_parser_objc_methodproto (c_parser *parser)
9286 {
9287   bool is_class_method = c_parser_objc_method_type (parser);
9288   tree decl, attributes = NULL_TREE;
9289 
9290   /* Remember protocol qualifiers in prototypes.  */
9291   parser->objc_pq_context = true;
9292   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
9293 				    NULL);
9294   /* Forget protocol qualifiers now.  */
9295   parser->objc_pq_context = false;
9296 
9297   /* Do not allow the presence of attributes to hide an erroneous
9298      method implementation in the interface section.  */
9299   if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
9300     {
9301       c_parser_error (parser, "expected %<;%>");
9302       return;
9303     }
9304 
9305   if (decl != error_mark_node)
9306     objc_add_method_declaration (is_class_method, decl, attributes);
9307 
9308   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9309 }
9310 
9311 /* If we are at a position that method attributes may be present, check that
9312    there are not any parsed already (a syntax error) and then collect any
9313    specified at the current location.  Finally, if new attributes were present,
9314    check that the next token is legal ( ';' for decls and '{' for defs).  */
9315 
9316 static bool
9317 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
9318 {
9319   bool bad = false;
9320   if (*attributes)
9321     {
9322       c_parser_error (parser,
9323 		    "method attributes must be specified at the end only");
9324       *attributes = NULL_TREE;
9325       bad = true;
9326     }
9327 
9328   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
9329     *attributes = c_parser_attributes (parser);
9330 
9331   /* If there were no attributes here, just report any earlier error.  */
9332   if (*attributes == NULL_TREE || bad)
9333     return bad;
9334 
9335   /* If the attributes are followed by a ; or {, then just report any earlier
9336      error.  */
9337   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
9338       || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9339     return bad;
9340 
9341   /* We've got attributes, but not at the end.  */
9342   c_parser_error (parser,
9343 		  "expected %<;%> or %<{%> after method attribute definition");
9344   return true;
9345 }
9346 
9347 /* Parse an objc-method-decl.
9348 
9349    objc-method-decl:
9350      ( objc-type-name ) objc-selector
9351      objc-selector
9352      ( objc-type-name ) objc-keyword-selector objc-optparmlist
9353      objc-keyword-selector objc-optparmlist
9354      attributes
9355 
9356    objc-keyword-selector:
9357      objc-keyword-decl
9358      objc-keyword-selector objc-keyword-decl
9359 
9360    objc-keyword-decl:
9361      objc-selector : ( objc-type-name ) identifier
9362      objc-selector : identifier
9363      : ( objc-type-name ) identifier
9364      : identifier
9365 
9366    objc-optparmlist:
9367      objc-optparms objc-optellipsis
9368 
9369    objc-optparms:
9370      empty
9371      objc-opt-parms , parameter-declaration
9372 
9373    objc-optellipsis:
9374      empty
9375      , ...
9376 */
9377 
9378 static tree
9379 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
9380 			   tree *attributes, tree *expr)
9381 {
9382   tree type = NULL_TREE;
9383   tree sel;
9384   tree parms = NULL_TREE;
9385   bool ellipsis = false;
9386   bool attr_err = false;
9387 
9388   *attributes = NULL_TREE;
9389   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9390     {
9391       c_parser_consume_token (parser);
9392       type = c_parser_objc_type_name (parser);
9393       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9394     }
9395   sel = c_parser_objc_selector (parser);
9396   /* If there is no selector, or a colon follows, we have an
9397      objc-keyword-selector.  If there is a selector, and a colon does
9398      not follow, that selector ends the objc-method-decl.  */
9399   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
9400     {
9401       tree tsel = sel;
9402       tree list = NULL_TREE;
9403       while (true)
9404 	{
9405 	  tree atype = NULL_TREE, id, keyworddecl;
9406 	  tree param_attr = NULL_TREE;
9407 	  if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9408 	    break;
9409 	  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9410 	    {
9411 	      c_parser_consume_token (parser);
9412 	      atype = c_parser_objc_type_name (parser);
9413 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9414 					 "expected %<)%>");
9415 	    }
9416 	  /* New ObjC allows attributes on method parameters.  */
9417 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
9418 	    param_attr = c_parser_attributes (parser);
9419 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
9420 	    {
9421 	      c_parser_error (parser, "expected identifier");
9422 	      return error_mark_node;
9423 	    }
9424 	  id = c_parser_peek_token (parser)->value;
9425 	  c_parser_consume_token (parser);
9426 	  keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
9427 	  list = chainon (list, keyworddecl);
9428 	  tsel = c_parser_objc_selector (parser);
9429 	  if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
9430 	    break;
9431 	}
9432 
9433       attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
9434 
9435       /* Parse the optional parameter list.  Optional Objective-C
9436 	 method parameters follow the C syntax, and may include '...'
9437 	 to denote a variable number of arguments.  */
9438       parms = make_node (TREE_LIST);
9439       while (c_parser_next_token_is (parser, CPP_COMMA))
9440 	{
9441 	  struct c_parm *parm;
9442 	  c_parser_consume_token (parser);
9443 	  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
9444 	    {
9445 	      ellipsis = true;
9446 	      c_parser_consume_token (parser);
9447 	      attr_err |= c_parser_objc_maybe_method_attributes
9448 						(parser, attributes) ;
9449 	      break;
9450 	    }
9451 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
9452 	  if (parm == NULL)
9453 	    break;
9454 	  parms = chainon (parms,
9455 			   build_tree_list (NULL_TREE, grokparm (parm, expr)));
9456 	}
9457       sel = list;
9458     }
9459   else
9460     attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
9461 
9462   if (sel == NULL)
9463     {
9464       c_parser_error (parser, "objective-c method declaration is expected");
9465       return error_mark_node;
9466     }
9467 
9468   if (attr_err)
9469     return error_mark_node;
9470 
9471   return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
9472 }
9473 
9474 /* Parse an objc-type-name.
9475 
9476    objc-type-name:
9477      objc-type-qualifiers[opt] type-name
9478      objc-type-qualifiers[opt]
9479 
9480    objc-type-qualifiers:
9481      objc-type-qualifier
9482      objc-type-qualifiers objc-type-qualifier
9483 
9484    objc-type-qualifier: one of
9485      in out inout bycopy byref oneway
9486 */
9487 
9488 static tree
9489 c_parser_objc_type_name (c_parser *parser)
9490 {
9491   tree quals = NULL_TREE;
9492   struct c_type_name *type_name = NULL;
9493   tree type = NULL_TREE;
9494   while (true)
9495     {
9496       c_token *token = c_parser_peek_token (parser);
9497       if (token->type == CPP_KEYWORD
9498 	  && (token->keyword == RID_IN
9499 	      || token->keyword == RID_OUT
9500 	      || token->keyword == RID_INOUT
9501 	      || token->keyword == RID_BYCOPY
9502 	      || token->keyword == RID_BYREF
9503 	      || token->keyword == RID_ONEWAY))
9504 	{
9505 	  quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
9506 	  c_parser_consume_token (parser);
9507 	}
9508       else
9509 	break;
9510     }
9511   if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
9512     type_name = c_parser_type_name (parser);
9513   if (type_name)
9514     type = groktypename (type_name, NULL, NULL);
9515 
9516   /* If the type is unknown, and error has already been produced and
9517      we need to recover from the error.  In that case, use NULL_TREE
9518      for the type, as if no type had been specified; this will use the
9519      default type ('id') which is good for error recovery.  */
9520   if (type == error_mark_node)
9521     type = NULL_TREE;
9522 
9523   return build_tree_list (quals, type);
9524 }
9525 
9526 /* Parse objc-protocol-refs.
9527 
9528    objc-protocol-refs:
9529      < identifier-list >
9530 */
9531 
9532 static tree
9533 c_parser_objc_protocol_refs (c_parser *parser)
9534 {
9535   tree list = NULL_TREE;
9536   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
9537   c_parser_consume_token (parser);
9538   /* Any identifiers, including those declared as type names, are OK
9539      here.  */
9540   while (true)
9541     {
9542       tree id;
9543       if (c_parser_next_token_is_not (parser, CPP_NAME))
9544 	{
9545 	  c_parser_error (parser, "expected identifier");
9546 	  break;
9547 	}
9548       id = c_parser_peek_token (parser)->value;
9549       list = chainon (list, build_tree_list (NULL_TREE, id));
9550       c_parser_consume_token (parser);
9551       if (c_parser_next_token_is (parser, CPP_COMMA))
9552 	c_parser_consume_token (parser);
9553       else
9554 	break;
9555     }
9556   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
9557   return list;
9558 }
9559 
9560 /* Parse an objc-try-catch-finally-statement.
9561 
9562    objc-try-catch-finally-statement:
9563      @try compound-statement objc-catch-list[opt]
9564      @try compound-statement objc-catch-list[opt] @finally compound-statement
9565 
9566    objc-catch-list:
9567      @catch ( objc-catch-parameter-declaration ) compound-statement
9568      objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9569 
9570    objc-catch-parameter-declaration:
9571      parameter-declaration
9572      '...'
9573 
9574    where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9575 
9576    PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9577    for C++.  Keep them in sync.  */
9578 
9579 static void
9580 c_parser_objc_try_catch_finally_statement (c_parser *parser)
9581 {
9582   location_t location;
9583   tree stmt;
9584 
9585   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
9586   c_parser_consume_token (parser);
9587   location = c_parser_peek_token (parser)->location;
9588   objc_maybe_warn_exceptions (location);
9589   stmt = c_parser_compound_statement (parser);
9590   objc_begin_try_stmt (location, stmt);
9591 
9592   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
9593     {
9594       struct c_parm *parm;
9595       tree parameter_declaration = error_mark_node;
9596       bool seen_open_paren = false;
9597 
9598       c_parser_consume_token (parser);
9599       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9600 	seen_open_paren = true;
9601       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
9602 	{
9603 	  /* We have "@catch (...)" (where the '...' are literally
9604 	     what is in the code).  Skip the '...'.
9605 	     parameter_declaration is set to NULL_TREE, and
9606 	     objc_being_catch_clauses() knows that that means
9607 	     '...'.  */
9608 	  c_parser_consume_token (parser);
9609 	  parameter_declaration = NULL_TREE;
9610 	}
9611       else
9612 	{
9613 	  /* We have "@catch (NSException *exception)" or something
9614 	     like that.  Parse the parameter declaration.  */
9615 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
9616 	  if (parm == NULL)
9617 	    parameter_declaration = error_mark_node;
9618 	  else
9619 	    parameter_declaration = grokparm (parm, NULL);
9620 	}
9621       if (seen_open_paren)
9622 	c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9623       else
9624 	{
9625 	  /* If there was no open parenthesis, we are recovering from
9626 	     an error, and we are trying to figure out what mistake
9627 	     the user has made.  */
9628 
9629 	  /* If there is an immediate closing parenthesis, the user
9630 	     probably forgot the opening one (ie, they typed "@catch
9631 	     NSException *e)".  Parse the closing parenthesis and keep
9632 	     going.  */
9633 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9634 	    c_parser_consume_token (parser);
9635 
9636 	  /* If these is no immediate closing parenthesis, the user
9637 	     probably doesn't know that parenthesis are required at
9638 	     all (ie, they typed "@catch NSException *e").  So, just
9639 	     forget about the closing parenthesis and keep going.  */
9640 	}
9641       objc_begin_catch_clause (parameter_declaration);
9642       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9643 	c_parser_compound_statement_nostart (parser);
9644       objc_finish_catch_clause ();
9645     }
9646   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
9647     {
9648       c_parser_consume_token (parser);
9649       location = c_parser_peek_token (parser)->location;
9650       stmt = c_parser_compound_statement (parser);
9651       objc_build_finally_clause (location, stmt);
9652     }
9653   objc_finish_try_stmt ();
9654 }
9655 
9656 /* Parse an objc-synchronized-statement.
9657 
9658    objc-synchronized-statement:
9659      @synchronized ( expression ) compound-statement
9660 */
9661 
9662 static void
9663 c_parser_objc_synchronized_statement (c_parser *parser)
9664 {
9665   location_t loc;
9666   tree expr, stmt;
9667   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
9668   c_parser_consume_token (parser);
9669   loc = c_parser_peek_token (parser)->location;
9670   objc_maybe_warn_exceptions (loc);
9671   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9672     {
9673       struct c_expr ce = c_parser_expression (parser);
9674       ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9675       expr = ce.value;
9676       expr = c_fully_fold (expr, false, NULL);
9677       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9678     }
9679   else
9680     expr = error_mark_node;
9681   stmt = c_parser_compound_statement (parser);
9682   objc_build_synchronized (loc, expr, stmt);
9683 }
9684 
9685 /* Parse an objc-selector; return NULL_TREE without an error if the
9686    next token is not an objc-selector.
9687 
9688    objc-selector:
9689      identifier
9690      one of
9691        enum struct union if else while do for switch case default
9692        break continue return goto asm sizeof typeof __alignof
9693        unsigned long const short volatile signed restrict _Complex
9694        in out inout bycopy byref oneway int char float double void _Bool
9695        _Atomic
9696 
9697    ??? Why this selection of keywords but not, for example, storage
9698    class specifiers?  */
9699 
9700 static tree
9701 c_parser_objc_selector (c_parser *parser)
9702 {
9703   c_token *token = c_parser_peek_token (parser);
9704   tree value = token->value;
9705   if (token->type == CPP_NAME)
9706     {
9707       c_parser_consume_token (parser);
9708       return value;
9709     }
9710   if (token->type != CPP_KEYWORD)
9711     return NULL_TREE;
9712   switch (token->keyword)
9713     {
9714     case RID_ENUM:
9715     case RID_STRUCT:
9716     case RID_UNION:
9717     case RID_IF:
9718     case RID_ELSE:
9719     case RID_WHILE:
9720     case RID_DO:
9721     case RID_FOR:
9722     case RID_SWITCH:
9723     case RID_CASE:
9724     case RID_DEFAULT:
9725     case RID_BREAK:
9726     case RID_CONTINUE:
9727     case RID_RETURN:
9728     case RID_GOTO:
9729     case RID_ASM:
9730     case RID_SIZEOF:
9731     case RID_TYPEOF:
9732     case RID_ALIGNOF:
9733     case RID_UNSIGNED:
9734     case RID_LONG:
9735     case RID_CONST:
9736     case RID_SHORT:
9737     case RID_VOLATILE:
9738     case RID_SIGNED:
9739     case RID_RESTRICT:
9740     case RID_COMPLEX:
9741     case RID_IN:
9742     case RID_OUT:
9743     case RID_INOUT:
9744     case RID_BYCOPY:
9745     case RID_BYREF:
9746     case RID_ONEWAY:
9747     case RID_INT:
9748     case RID_CHAR:
9749     case RID_FLOAT:
9750     case RID_DOUBLE:
9751     CASE_RID_FLOATN_NX:
9752     case RID_VOID:
9753     case RID_BOOL:
9754     case RID_ATOMIC:
9755     case RID_AUTO_TYPE:
9756     case RID_INT_N_0:
9757     case RID_INT_N_1:
9758     case RID_INT_N_2:
9759     case RID_INT_N_3:
9760       c_parser_consume_token (parser);
9761       return value;
9762     default:
9763       return NULL_TREE;
9764     }
9765 }
9766 
9767 /* Parse an objc-selector-arg.
9768 
9769    objc-selector-arg:
9770      objc-selector
9771      objc-keywordname-list
9772 
9773    objc-keywordname-list:
9774      objc-keywordname
9775      objc-keywordname-list objc-keywordname
9776 
9777    objc-keywordname:
9778      objc-selector :
9779      :
9780 */
9781 
9782 static tree
9783 c_parser_objc_selector_arg (c_parser *parser)
9784 {
9785   tree sel = c_parser_objc_selector (parser);
9786   tree list = NULL_TREE;
9787   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9788     return sel;
9789   while (true)
9790     {
9791       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9792 	return list;
9793       list = chainon (list, build_tree_list (sel, NULL_TREE));
9794       sel = c_parser_objc_selector (parser);
9795       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9796 	break;
9797     }
9798   return list;
9799 }
9800 
9801 /* Parse an objc-receiver.
9802 
9803    objc-receiver:
9804      expression
9805      class-name
9806      type-name
9807 */
9808 
9809 static tree
9810 c_parser_objc_receiver (c_parser *parser)
9811 {
9812   location_t loc = c_parser_peek_token (parser)->location;
9813 
9814   if (c_parser_peek_token (parser)->type == CPP_NAME
9815       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
9816 	  || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
9817     {
9818       tree id = c_parser_peek_token (parser)->value;
9819       c_parser_consume_token (parser);
9820       return objc_get_class_reference (id);
9821     }
9822   struct c_expr ce = c_parser_expression (parser);
9823   ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9824   return c_fully_fold (ce.value, false, NULL);
9825 }
9826 
9827 /* Parse objc-message-args.
9828 
9829    objc-message-args:
9830      objc-selector
9831      objc-keywordarg-list
9832 
9833    objc-keywordarg-list:
9834      objc-keywordarg
9835      objc-keywordarg-list objc-keywordarg
9836 
9837    objc-keywordarg:
9838      objc-selector : objc-keywordexpr
9839      : objc-keywordexpr
9840 */
9841 
9842 static tree
9843 c_parser_objc_message_args (c_parser *parser)
9844 {
9845   tree sel = c_parser_objc_selector (parser);
9846   tree list = NULL_TREE;
9847   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9848     return sel;
9849   while (true)
9850     {
9851       tree keywordexpr;
9852       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9853 	return error_mark_node;
9854       keywordexpr = c_parser_objc_keywordexpr (parser);
9855       list = chainon (list, build_tree_list (sel, keywordexpr));
9856       sel = c_parser_objc_selector (parser);
9857       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9858 	break;
9859     }
9860   return list;
9861 }
9862 
9863 /* Parse an objc-keywordexpr.
9864 
9865    objc-keywordexpr:
9866      nonempty-expr-list
9867 */
9868 
9869 static tree
9870 c_parser_objc_keywordexpr (c_parser *parser)
9871 {
9872   tree ret;
9873   vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
9874 						NULL, NULL, NULL, NULL);
9875   if (vec_safe_length (expr_list) == 1)
9876     {
9877       /* Just return the expression, remove a level of
9878 	 indirection.  */
9879       ret = (*expr_list)[0];
9880     }
9881   else
9882     {
9883       /* We have a comma expression, we will collapse later.  */
9884       ret = build_tree_list_vec (expr_list);
9885     }
9886   release_tree_vector (expr_list);
9887   return ret;
9888 }
9889 
9890 /* A check, needed in several places, that ObjC interface, implementation or
9891    method definitions are not prefixed by incorrect items.  */
9892 static bool
9893 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
9894 					   struct c_declspecs *specs)
9895 {
9896   if (!specs->declspecs_seen_p || specs->non_sc_seen_p
9897       || specs->typespec_kind != ctsk_none)
9898     {
9899       c_parser_error (parser,
9900       		      "no type or storage class may be specified here,");
9901       c_parser_skip_to_end_of_block_or_statement (parser);
9902       return true;
9903     }
9904   return false;
9905 }
9906 
9907 /* Parse an Objective-C @property declaration.  The syntax is:
9908 
9909    objc-property-declaration:
9910      '@property' objc-property-attributes[opt] struct-declaration ;
9911 
9912    objc-property-attributes:
9913     '(' objc-property-attribute-list ')'
9914 
9915    objc-property-attribute-list:
9916      objc-property-attribute
9917      objc-property-attribute-list, objc-property-attribute
9918 
9919    objc-property-attribute
9920      'getter' = identifier
9921      'setter' = identifier
9922      'readonly'
9923      'readwrite'
9924      'assign'
9925      'retain'
9926      'copy'
9927      'nonatomic'
9928 
9929   For example:
9930     @property NSString *name;
9931     @property (readonly) id object;
9932     @property (retain, nonatomic, getter=getTheName) id name;
9933     @property int a, b, c;
9934 
9935   PS: This function is identical to cp_parser_objc_at_propery_declaration
9936   for C++.  Keep them in sync.  */
9937 static void
9938 c_parser_objc_at_property_declaration (c_parser *parser)
9939 {
9940   /* The following variables hold the attributes of the properties as
9941      parsed.  They are 'false' or 'NULL_TREE' if the attribute was not
9942      seen.  When we see an attribute, we set them to 'true' (if they
9943      are boolean properties) or to the identifier (if they have an
9944      argument, ie, for getter and setter).  Note that here we only
9945      parse the list of attributes, check the syntax and accumulate the
9946      attributes that we find.  objc_add_property_declaration() will
9947      then process the information.  */
9948   bool property_assign = false;
9949   bool property_copy = false;
9950   tree property_getter_ident = NULL_TREE;
9951   bool property_nonatomic = false;
9952   bool property_readonly = false;
9953   bool property_readwrite = false;
9954   bool property_retain = false;
9955   tree property_setter_ident = NULL_TREE;
9956 
9957   /* 'properties' is the list of properties that we read.  Usually a
9958      single one, but maybe more (eg, in "@property int a, b, c;" there
9959      are three).  */
9960   tree properties;
9961   location_t loc;
9962 
9963   loc = c_parser_peek_token (parser)->location;
9964   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
9965 
9966   c_parser_consume_token (parser);  /* Eat '@property'.  */
9967 
9968   /* Parse the optional attribute list...  */
9969   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9970     {
9971       /* Eat the '(' */
9972       c_parser_consume_token (parser);
9973 
9974       /* Property attribute keywords are valid now.  */
9975       parser->objc_property_attr_context = true;
9976 
9977       while (true)
9978 	{
9979 	  bool syntax_error = false;
9980 	  c_token *token = c_parser_peek_token (parser);
9981 	  enum rid keyword;
9982 
9983 	  if (token->type != CPP_KEYWORD)
9984 	    {
9985 	      if (token->type == CPP_CLOSE_PAREN)
9986 		c_parser_error (parser, "expected identifier");
9987 	      else
9988 		{
9989 		  c_parser_consume_token (parser);
9990 		  c_parser_error (parser, "unknown property attribute");
9991 		}
9992 	      break;
9993 	    }
9994 	  keyword = token->keyword;
9995 	  c_parser_consume_token (parser);
9996 	  switch (keyword)
9997 	    {
9998 	    case RID_ASSIGN:    property_assign = true;    break;
9999 	    case RID_COPY:      property_copy = true;      break;
10000 	    case RID_NONATOMIC: property_nonatomic = true; break;
10001 	    case RID_READONLY:  property_readonly = true;  break;
10002 	    case RID_READWRITE: property_readwrite = true; break;
10003 	    case RID_RETAIN:    property_retain = true;    break;
10004 
10005 	    case RID_GETTER:
10006 	    case RID_SETTER:
10007 	      if (c_parser_next_token_is_not (parser, CPP_EQ))
10008 		{
10009 		  if (keyword == RID_GETTER)
10010 		    c_parser_error (parser,
10011 				    "missing %<=%> (after %<getter%> attribute)");
10012 		  else
10013 		    c_parser_error (parser,
10014 				    "missing %<=%> (after %<setter%> attribute)");
10015 		  syntax_error = true;
10016 		  break;
10017 		}
10018 	      c_parser_consume_token (parser); /* eat the = */
10019 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
10020 		{
10021 		  c_parser_error (parser, "expected identifier");
10022 		  syntax_error = true;
10023 		  break;
10024 		}
10025 	      if (keyword == RID_SETTER)
10026 		{
10027 		  if (property_setter_ident != NULL_TREE)
10028 		    c_parser_error (parser, "the %<setter%> attribute may only be specified once");
10029 		  else
10030 		    property_setter_ident = c_parser_peek_token (parser)->value;
10031 		  c_parser_consume_token (parser);
10032 		  if (c_parser_next_token_is_not (parser, CPP_COLON))
10033 		    c_parser_error (parser, "setter name must terminate with %<:%>");
10034 		  else
10035 		    c_parser_consume_token (parser);
10036 		}
10037 	      else
10038 		{
10039 		  if (property_getter_ident != NULL_TREE)
10040 		    c_parser_error (parser, "the %<getter%> attribute may only be specified once");
10041 		  else
10042 		    property_getter_ident = c_parser_peek_token (parser)->value;
10043 		  c_parser_consume_token (parser);
10044 		}
10045 	      break;
10046 	    default:
10047 	      c_parser_error (parser, "unknown property attribute");
10048 	      syntax_error = true;
10049 	      break;
10050 	    }
10051 
10052 	  if (syntax_error)
10053 	    break;
10054 
10055 	  if (c_parser_next_token_is (parser, CPP_COMMA))
10056 	    c_parser_consume_token (parser);
10057 	  else
10058 	    break;
10059 	}
10060       parser->objc_property_attr_context = false;
10061       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10062     }
10063   /* ... and the property declaration(s).  */
10064   properties = c_parser_struct_declaration (parser);
10065 
10066   if (properties == error_mark_node)
10067     {
10068       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10069       parser->error = false;
10070       return;
10071     }
10072 
10073   if (properties == NULL_TREE)
10074     c_parser_error (parser, "expected identifier");
10075   else
10076     {
10077       /* Comma-separated properties are chained together in
10078 	 reverse order; add them one by one.  */
10079       properties = nreverse (properties);
10080 
10081       for (; properties; properties = TREE_CHAIN (properties))
10082 	objc_add_property_declaration (loc, copy_node (properties),
10083 				       property_readonly, property_readwrite,
10084 				       property_assign, property_retain,
10085 				       property_copy, property_nonatomic,
10086 				       property_getter_ident, property_setter_ident);
10087     }
10088 
10089   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10090   parser->error = false;
10091 }
10092 
10093 /* Parse an Objective-C @synthesize declaration.  The syntax is:
10094 
10095    objc-synthesize-declaration:
10096      @synthesize objc-synthesize-identifier-list ;
10097 
10098    objc-synthesize-identifier-list:
10099      objc-synthesize-identifier
10100      objc-synthesize-identifier-list, objc-synthesize-identifier
10101 
10102    objc-synthesize-identifier
10103      identifier
10104      identifier = identifier
10105 
10106   For example:
10107     @synthesize MyProperty;
10108     @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10109 
10110   PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10111   for C++.  Keep them in sync.
10112 */
10113 static void
10114 c_parser_objc_at_synthesize_declaration (c_parser *parser)
10115 {
10116   tree list = NULL_TREE;
10117   location_t loc;
10118   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
10119   loc = c_parser_peek_token (parser)->location;
10120 
10121   c_parser_consume_token (parser);
10122   while (true)
10123     {
10124       tree property, ivar;
10125       if (c_parser_next_token_is_not (parser, CPP_NAME))
10126 	{
10127 	  c_parser_error (parser, "expected identifier");
10128 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10129 	  /* Once we find the semicolon, we can resume normal parsing.
10130 	     We have to reset parser->error manually because
10131 	     c_parser_skip_until_found() won't reset it for us if the
10132 	     next token is precisely a semicolon.  */
10133 	  parser->error = false;
10134 	  return;
10135 	}
10136       property = c_parser_peek_token (parser)->value;
10137       c_parser_consume_token (parser);
10138       if (c_parser_next_token_is (parser, CPP_EQ))
10139 	{
10140 	  c_parser_consume_token (parser);
10141 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
10142 	    {
10143 	      c_parser_error (parser, "expected identifier");
10144 	      c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10145 	      parser->error = false;
10146 	      return;
10147 	    }
10148 	  ivar = c_parser_peek_token (parser)->value;
10149 	  c_parser_consume_token (parser);
10150 	}
10151       else
10152 	ivar = NULL_TREE;
10153       list = chainon (list, build_tree_list (ivar, property));
10154       if (c_parser_next_token_is (parser, CPP_COMMA))
10155 	c_parser_consume_token (parser);
10156       else
10157 	break;
10158     }
10159   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10160   objc_add_synthesize_declaration (loc, list);
10161 }
10162 
10163 /* Parse an Objective-C @dynamic declaration.  The syntax is:
10164 
10165    objc-dynamic-declaration:
10166      @dynamic identifier-list ;
10167 
10168    For example:
10169      @dynamic MyProperty;
10170      @dynamic MyProperty, AnotherProperty;
10171 
10172   PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10173   for C++.  Keep them in sync.
10174 */
10175 static void
10176 c_parser_objc_at_dynamic_declaration (c_parser *parser)
10177 {
10178   tree list = NULL_TREE;
10179   location_t loc;
10180   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
10181   loc = c_parser_peek_token (parser)->location;
10182 
10183   c_parser_consume_token (parser);
10184   while (true)
10185     {
10186       tree property;
10187       if (c_parser_next_token_is_not (parser, CPP_NAME))
10188 	{
10189 	  c_parser_error (parser, "expected identifier");
10190 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10191 	  parser->error = false;
10192 	  return;
10193 	}
10194       property = c_parser_peek_token (parser)->value;
10195       list = chainon (list, build_tree_list (NULL_TREE, property));
10196       c_parser_consume_token (parser);
10197       if (c_parser_next_token_is (parser, CPP_COMMA))
10198 	c_parser_consume_token (parser);
10199       else
10200 	break;
10201     }
10202   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10203   objc_add_dynamic_declaration (loc, list);
10204 }
10205 
10206 
10207 /* Handle pragmas.  Some OpenMP pragmas are associated with, and therefore
10208    should be considered, statements.  ALLOW_STMT is true if we're within
10209    the context of a function and such pragmas are to be allowed.  Returns
10210    true if we actually parsed such a pragma.  */
10211 
10212 static bool
10213 c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p)
10214 {
10215   unsigned int id;
10216   const char *construct = NULL;
10217 
10218   id = c_parser_peek_token (parser)->pragma_kind;
10219   gcc_assert (id != PRAGMA_NONE);
10220 
10221   switch (id)
10222     {
10223     case PRAGMA_OACC_DECLARE:
10224       c_parser_oacc_declare (parser);
10225       return false;
10226 
10227     case PRAGMA_OACC_ENTER_DATA:
10228       if (context != pragma_compound)
10229 	{
10230 	  construct = "acc enter data";
10231 	in_compound:
10232 	  if (context == pragma_stmt)
10233 	    {
10234 	      error_at (c_parser_peek_token (parser)->location,
10235 			"%<#pragma %s%> may only be used in compound "
10236 			"statements", construct);
10237 	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10238 	      return false;
10239 	    }
10240 	  goto bad_stmt;
10241 	}
10242       c_parser_oacc_enter_exit_data (parser, true);
10243       return false;
10244 
10245     case PRAGMA_OACC_EXIT_DATA:
10246       if (context != pragma_compound)
10247 	{
10248 	  construct = "acc exit data";
10249 	  goto in_compound;
10250 	}
10251       c_parser_oacc_enter_exit_data (parser, false);
10252       return false;
10253 
10254     case PRAGMA_OACC_ROUTINE:
10255       if (context != pragma_external)
10256 	{
10257 	  error_at (c_parser_peek_token (parser)->location,
10258 		    "%<#pragma acc routine%> must be at file scope");
10259 	  c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10260 	  return false;
10261 	}
10262       c_parser_oacc_routine (parser, context);
10263       return false;
10264 
10265     case PRAGMA_OACC_UPDATE:
10266       if (context != pragma_compound)
10267 	{
10268 	  construct = "acc update";
10269 	  goto in_compound;
10270 	}
10271       c_parser_oacc_update (parser);
10272       return false;
10273 
10274     case PRAGMA_OMP_BARRIER:
10275       if (context != pragma_compound)
10276 	{
10277 	  construct = "omp barrier";
10278 	  goto in_compound;
10279 	}
10280       c_parser_omp_barrier (parser);
10281       return false;
10282 
10283     case PRAGMA_OMP_FLUSH:
10284       if (context != pragma_compound)
10285 	{
10286 	  construct = "omp flush";
10287 	  goto in_compound;
10288 	}
10289       c_parser_omp_flush (parser);
10290       return false;
10291 
10292     case PRAGMA_OMP_TASKWAIT:
10293       if (context != pragma_compound)
10294 	{
10295 	  construct = "omp taskwait";
10296 	  goto in_compound;
10297 	}
10298       c_parser_omp_taskwait (parser);
10299       return false;
10300 
10301     case PRAGMA_OMP_TASKYIELD:
10302       if (context != pragma_compound)
10303 	{
10304 	  construct = "omp taskyield";
10305 	  goto in_compound;
10306 	}
10307       c_parser_omp_taskyield (parser);
10308       return false;
10309 
10310     case PRAGMA_OMP_CANCEL:
10311       if (context != pragma_compound)
10312 	{
10313 	  construct = "omp cancel";
10314 	  goto in_compound;
10315 	}
10316       c_parser_omp_cancel (parser);
10317       return false;
10318 
10319     case PRAGMA_OMP_CANCELLATION_POINT:
10320       c_parser_omp_cancellation_point (parser, context);
10321       return false;
10322 
10323     case PRAGMA_OMP_THREADPRIVATE:
10324       c_parser_omp_threadprivate (parser);
10325       return false;
10326 
10327     case PRAGMA_OMP_TARGET:
10328       return c_parser_omp_target (parser, context, if_p);
10329 
10330     case PRAGMA_OMP_END_DECLARE_TARGET:
10331       c_parser_omp_end_declare_target (parser);
10332       return false;
10333 
10334     case PRAGMA_OMP_SECTION:
10335       error_at (c_parser_peek_token (parser)->location,
10336 		"%<#pragma omp section%> may only be used in "
10337 		"%<#pragma omp sections%> construct");
10338       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10339       return false;
10340 
10341     case PRAGMA_OMP_DECLARE:
10342       c_parser_omp_declare (parser, context);
10343       return false;
10344 
10345     case PRAGMA_OMP_ORDERED:
10346       return c_parser_omp_ordered (parser, context, if_p);
10347 
10348     case PRAGMA_IVDEP:
10349       c_parser_consume_pragma (parser);
10350       c_parser_skip_to_pragma_eol (parser);
10351       if (!c_parser_next_token_is_keyword (parser, RID_FOR)
10352 	  && !c_parser_next_token_is_keyword (parser, RID_WHILE)
10353 	  && !c_parser_next_token_is_keyword (parser, RID_DO))
10354 	{
10355 	  c_parser_error (parser, "for, while or do statement expected");
10356 	  return false;
10357 	}
10358       if (c_parser_next_token_is_keyword (parser, RID_FOR))
10359 	c_parser_for_statement (parser, true, if_p);
10360       else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
10361 	c_parser_while_statement (parser, true, if_p);
10362       else
10363 	c_parser_do_statement (parser, true);
10364       return false;
10365 
10366     case PRAGMA_GCC_PCH_PREPROCESS:
10367       c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
10368       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10369       return false;
10370 
10371     case PRAGMA_CILK_SIMD:
10372       if (!c_parser_cilk_verify_simd (parser, context))
10373 	return false;
10374       c_parser_consume_pragma (parser);
10375       c_parser_cilk_simd (parser, if_p);
10376       return false;
10377     case PRAGMA_CILK_GRAINSIZE:
10378       if (!flag_cilkplus)
10379 	{
10380 	  warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10381 		   " enabled");
10382 	  c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10383 	  return false;
10384 	}
10385       if (context == pragma_external)
10386 	{
10387 	  error_at (c_parser_peek_token (parser)->location,
10388 		    "%<#pragma grainsize%> must be inside a function");
10389 	  c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10390 	  return false;
10391 	}
10392       c_parser_cilk_grainsize (parser, if_p);
10393       return false;
10394 
10395     case PRAGMA_OACC_WAIT:
10396       if (context != pragma_compound)
10397 	{
10398 	  construct = "acc wait";
10399 	  goto in_compound;
10400 	}
10401 	/* FALL THROUGH.  */
10402 
10403     default:
10404       if (id < PRAGMA_FIRST_EXTERNAL)
10405 	{
10406 	  if (context != pragma_stmt && context != pragma_compound)
10407 	    {
10408 	    bad_stmt:
10409 	      c_parser_error (parser, "expected declaration specifiers");
10410 	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10411 	      return false;
10412 	    }
10413 	  c_parser_omp_construct (parser, if_p);
10414 	  return true;
10415 	}
10416       break;
10417     }
10418 
10419   c_parser_consume_pragma (parser);
10420   c_invoke_pragma_handler (id);
10421 
10422   /* Skip to EOL, but suppress any error message.  Those will have been
10423      generated by the handler routine through calling error, as opposed
10424      to calling c_parser_error.  */
10425   parser->error = true;
10426   c_parser_skip_to_pragma_eol (parser);
10427 
10428   return false;
10429 }
10430 
10431 /* The interface the pragma parsers have to the lexer.  */
10432 
10433 enum cpp_ttype
10434 pragma_lex (tree *value, location_t *loc)
10435 {
10436   c_token *tok = c_parser_peek_token (the_parser);
10437   enum cpp_ttype ret = tok->type;
10438 
10439   *value = tok->value;
10440   if (loc)
10441     *loc = tok->location;
10442 
10443   if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
10444     ret = CPP_EOF;
10445   else
10446     {
10447       if (ret == CPP_KEYWORD)
10448 	ret = CPP_NAME;
10449       c_parser_consume_token (the_parser);
10450     }
10451 
10452   return ret;
10453 }
10454 
10455 static void
10456 c_parser_pragma_pch_preprocess (c_parser *parser)
10457 {
10458   tree name = NULL;
10459 
10460   c_parser_consume_pragma (parser);
10461   if (c_parser_next_token_is (parser, CPP_STRING))
10462     {
10463       name = c_parser_peek_token (parser)->value;
10464       c_parser_consume_token (parser);
10465     }
10466   else
10467     c_parser_error (parser, "expected string literal");
10468   c_parser_skip_to_pragma_eol (parser);
10469 
10470   if (name)
10471     c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
10472 }
10473 
10474 /* OpenACC and OpenMP parsing routines.  */
10475 
10476 /* Returns name of the next clause.
10477    If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10478    the token is not consumed.  Otherwise appropriate pragma_omp_clause is
10479    returned and the token is consumed.  */
10480 
10481 static pragma_omp_clause
10482 c_parser_omp_clause_name (c_parser *parser)
10483 {
10484   pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
10485 
10486   if (c_parser_next_token_is_keyword (parser, RID_AUTO))
10487     result = PRAGMA_OACC_CLAUSE_AUTO;
10488   else if (c_parser_next_token_is_keyword (parser, RID_IF))
10489     result = PRAGMA_OMP_CLAUSE_IF;
10490   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
10491     result = PRAGMA_OMP_CLAUSE_DEFAULT;
10492   else if (c_parser_next_token_is_keyword (parser, RID_FOR))
10493     result = PRAGMA_OMP_CLAUSE_FOR;
10494   else if (c_parser_next_token_is (parser, CPP_NAME))
10495     {
10496       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10497 
10498       switch (p[0])
10499 	{
10500 	case 'a':
10501 	  if (!strcmp ("aligned", p))
10502 	    result = PRAGMA_OMP_CLAUSE_ALIGNED;
10503 	  else if (!strcmp ("async", p))
10504 	    result = PRAGMA_OACC_CLAUSE_ASYNC;
10505 	  break;
10506 	case 'c':
10507 	  if (!strcmp ("collapse", p))
10508 	    result = PRAGMA_OMP_CLAUSE_COLLAPSE;
10509 	  else if (!strcmp ("copy", p))
10510 	    result = PRAGMA_OACC_CLAUSE_COPY;
10511 	  else if (!strcmp ("copyin", p))
10512 	    result = PRAGMA_OMP_CLAUSE_COPYIN;
10513 	  else if (!strcmp ("copyout", p))
10514 	    result = PRAGMA_OACC_CLAUSE_COPYOUT;
10515           else if (!strcmp ("copyprivate", p))
10516 	    result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
10517 	  else if (!strcmp ("create", p))
10518 	    result = PRAGMA_OACC_CLAUSE_CREATE;
10519 	  break;
10520 	case 'd':
10521 	  if (!strcmp ("defaultmap", p))
10522 	    result = PRAGMA_OMP_CLAUSE_DEFAULTMAP;
10523 	  else if (!strcmp ("delete", p))
10524 	    result = PRAGMA_OACC_CLAUSE_DELETE;
10525 	  else if (!strcmp ("depend", p))
10526 	    result = PRAGMA_OMP_CLAUSE_DEPEND;
10527 	  else if (!strcmp ("device", p))
10528 	    result = PRAGMA_OMP_CLAUSE_DEVICE;
10529 	  else if (!strcmp ("deviceptr", p))
10530 	    result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
10531 	  else if (!strcmp ("device_resident", p))
10532 	    result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT;
10533 	  else if (!strcmp ("dist_schedule", p))
10534 	    result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
10535 	  break;
10536 	case 'f':
10537 	  if (!strcmp ("final", p))
10538 	    result = PRAGMA_OMP_CLAUSE_FINAL;
10539 	  else if (!strcmp ("firstprivate", p))
10540 	    result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
10541 	  else if (!strcmp ("from", p))
10542 	    result = PRAGMA_OMP_CLAUSE_FROM;
10543 	  break;
10544 	case 'g':
10545 	  if (!strcmp ("gang", p))
10546 	    result = PRAGMA_OACC_CLAUSE_GANG;
10547 	  else if (!strcmp ("grainsize", p))
10548 	    result = PRAGMA_OMP_CLAUSE_GRAINSIZE;
10549 	  break;
10550 	case 'h':
10551 	  if (!strcmp ("hint", p))
10552 	    result = PRAGMA_OMP_CLAUSE_HINT;
10553 	  else if (!strcmp ("host", p))
10554 	    result = PRAGMA_OACC_CLAUSE_HOST;
10555 	  break;
10556 	case 'i':
10557 	  if (!strcmp ("inbranch", p))
10558 	    result = PRAGMA_OMP_CLAUSE_INBRANCH;
10559 	  else if (!strcmp ("independent", p))
10560 	    result = PRAGMA_OACC_CLAUSE_INDEPENDENT;
10561 	  else if (!strcmp ("is_device_ptr", p))
10562 	    result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR;
10563 	  break;
10564 	case 'l':
10565 	  if (!strcmp ("lastprivate", p))
10566 	    result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
10567 	  else if (!strcmp ("linear", p))
10568 	    result = PRAGMA_OMP_CLAUSE_LINEAR;
10569 	  else if (!strcmp ("link", p))
10570 	    result = PRAGMA_OMP_CLAUSE_LINK;
10571 	  break;
10572 	case 'm':
10573 	  if (!strcmp ("map", p))
10574 	    result = PRAGMA_OMP_CLAUSE_MAP;
10575 	  else if (!strcmp ("mergeable", p))
10576 	    result = PRAGMA_OMP_CLAUSE_MERGEABLE;
10577 	  else if (flag_cilkplus && !strcmp ("mask", p))
10578 	    result = PRAGMA_CILK_CLAUSE_MASK;
10579 	  break;
10580 	case 'n':
10581 	  if (!strcmp ("nogroup", p))
10582 	    result = PRAGMA_OMP_CLAUSE_NOGROUP;
10583 	  else if (!strcmp ("notinbranch", p))
10584 	    result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
10585 	  else if (!strcmp ("nowait", p))
10586 	    result = PRAGMA_OMP_CLAUSE_NOWAIT;
10587 	  else if (!strcmp ("num_gangs", p))
10588 	    result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
10589 	  else if (!strcmp ("num_tasks", p))
10590 	    result = PRAGMA_OMP_CLAUSE_NUM_TASKS;
10591 	  else if (!strcmp ("num_teams", p))
10592 	    result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
10593 	  else if (!strcmp ("num_threads", p))
10594 	    result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
10595 	  else if (!strcmp ("num_workers", p))
10596 	    result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
10597 	  else if (flag_cilkplus && !strcmp ("nomask", p))
10598 	    result = PRAGMA_CILK_CLAUSE_NOMASK;
10599 	  break;
10600 	case 'o':
10601 	  if (!strcmp ("ordered", p))
10602 	    result = PRAGMA_OMP_CLAUSE_ORDERED;
10603 	  break;
10604 	case 'p':
10605 	  if (!strcmp ("parallel", p))
10606 	    result = PRAGMA_OMP_CLAUSE_PARALLEL;
10607 	  else if (!strcmp ("present", p))
10608 	    result = PRAGMA_OACC_CLAUSE_PRESENT;
10609 	  else if (!strcmp ("present_or_copy", p)
10610 		   || !strcmp ("pcopy", p))
10611 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
10612 	  else if (!strcmp ("present_or_copyin", p)
10613 		   || !strcmp ("pcopyin", p))
10614 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
10615 	  else if (!strcmp ("present_or_copyout", p)
10616 		   || !strcmp ("pcopyout", p))
10617 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
10618 	  else if (!strcmp ("present_or_create", p)
10619 		   || !strcmp ("pcreate", p))
10620 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
10621 	  else if (!strcmp ("priority", p))
10622 	    result = PRAGMA_OMP_CLAUSE_PRIORITY;
10623 	  else if (!strcmp ("private", p))
10624 	    result = PRAGMA_OMP_CLAUSE_PRIVATE;
10625 	  else if (!strcmp ("proc_bind", p))
10626 	    result = PRAGMA_OMP_CLAUSE_PROC_BIND;
10627 	  break;
10628 	case 'r':
10629 	  if (!strcmp ("reduction", p))
10630 	    result = PRAGMA_OMP_CLAUSE_REDUCTION;
10631 	  break;
10632 	case 's':
10633 	  if (!strcmp ("safelen", p))
10634 	    result = PRAGMA_OMP_CLAUSE_SAFELEN;
10635 	  else if (!strcmp ("schedule", p))
10636 	    result = PRAGMA_OMP_CLAUSE_SCHEDULE;
10637 	  else if (!strcmp ("sections", p))
10638 	    result = PRAGMA_OMP_CLAUSE_SECTIONS;
10639 	  else if (!strcmp ("seq", p))
10640 	    result = PRAGMA_OACC_CLAUSE_SEQ;
10641 	  else if (!strcmp ("shared", p))
10642 	    result = PRAGMA_OMP_CLAUSE_SHARED;
10643 	  else if (!strcmp ("simd", p))
10644 	    result = PRAGMA_OMP_CLAUSE_SIMD;
10645 	  else if (!strcmp ("simdlen", p))
10646 	    result = PRAGMA_OMP_CLAUSE_SIMDLEN;
10647 	  else if (!strcmp ("self", p))
10648 	    result = PRAGMA_OACC_CLAUSE_SELF;
10649 	  break;
10650 	case 't':
10651 	  if (!strcmp ("taskgroup", p))
10652 	    result = PRAGMA_OMP_CLAUSE_TASKGROUP;
10653 	  else if (!strcmp ("thread_limit", p))
10654 	    result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
10655 	  else if (!strcmp ("threads", p))
10656 	    result = PRAGMA_OMP_CLAUSE_THREADS;
10657 	  else if (!strcmp ("tile", p))
10658 	    result = PRAGMA_OACC_CLAUSE_TILE;
10659 	  else if (!strcmp ("to", p))
10660 	    result = PRAGMA_OMP_CLAUSE_TO;
10661 	  break;
10662 	case 'u':
10663 	  if (!strcmp ("uniform", p))
10664 	    result = PRAGMA_OMP_CLAUSE_UNIFORM;
10665 	  else if (!strcmp ("untied", p))
10666 	    result = PRAGMA_OMP_CLAUSE_UNTIED;
10667 	  else if (!strcmp ("use_device", p))
10668 	    result = PRAGMA_OACC_CLAUSE_USE_DEVICE;
10669 	  else if (!strcmp ("use_device_ptr", p))
10670 	    result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR;
10671 	  break;
10672 	case 'v':
10673 	  if (!strcmp ("vector", p))
10674 	    result = PRAGMA_OACC_CLAUSE_VECTOR;
10675 	  else if (!strcmp ("vector_length", p))
10676 	    result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
10677 	  else if (flag_cilkplus && !strcmp ("vectorlength", p))
10678 	    result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
10679 	  break;
10680 	case 'w':
10681 	  if (!strcmp ("wait", p))
10682 	    result = PRAGMA_OACC_CLAUSE_WAIT;
10683 	  else if (!strcmp ("worker", p))
10684 	    result = PRAGMA_OACC_CLAUSE_WORKER;
10685 	  break;
10686 	}
10687     }
10688 
10689   if (result != PRAGMA_OMP_CLAUSE_NONE)
10690     c_parser_consume_token (parser);
10691 
10692   return result;
10693 }
10694 
10695 /* Validate that a clause of the given type does not already exist.  */
10696 
10697 static void
10698 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
10699 			   const char *name)
10700 {
10701   tree c;
10702 
10703   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
10704     if (OMP_CLAUSE_CODE (c) == code)
10705       {
10706 	location_t loc = OMP_CLAUSE_LOCATION (c);
10707 	error_at (loc, "too many %qs clauses", name);
10708 	break;
10709       }
10710 }
10711 
10712 /* OpenACC 2.0
10713    Parse wait clause or wait directive parameters.  */
10714 
10715 static tree
10716 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
10717 {
10718   vec<tree, va_gc> *args;
10719   tree t, args_tree;
10720 
10721   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10722     return list;
10723 
10724   args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
10725 
10726   if (args->length () == 0)
10727     {
10728       c_parser_error (parser, "expected integer expression before ')'");
10729       release_tree_vector (args);
10730       return list;
10731     }
10732 
10733   args_tree = build_tree_list_vec (args);
10734 
10735   for (t = args_tree; t; t = TREE_CHAIN (t))
10736     {
10737       tree targ = TREE_VALUE (t);
10738 
10739       if (targ != error_mark_node)
10740 	{
10741 	  if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
10742 	    {
10743 	      c_parser_error (parser, "expression must be integral");
10744 	      targ = error_mark_node;
10745 	    }
10746 	  else
10747 	    {
10748 	      tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
10749 
10750 	      OMP_CLAUSE_DECL (c) = targ;
10751 	      OMP_CLAUSE_CHAIN (c) = list;
10752 	      list = c;
10753 	    }
10754 	}
10755     }
10756 
10757   release_tree_vector (args);
10758   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10759   return list;
10760 }
10761 
10762 /* OpenACC 2.0, OpenMP 2.5:
10763    variable-list:
10764      identifier
10765      variable-list , identifier
10766 
10767    If KIND is nonzero, create the appropriate node and install the
10768    decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10769    If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10770 
10771    If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10772    return the list created.  */
10773 
10774 static tree
10775 c_parser_omp_variable_list (c_parser *parser,
10776 			    location_t clause_loc,
10777 			    enum omp_clause_code kind, tree list)
10778 {
10779   if (c_parser_next_token_is_not (parser, CPP_NAME)
10780       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
10781     c_parser_error (parser, "expected identifier");
10782 
10783   while (c_parser_next_token_is (parser, CPP_NAME)
10784 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
10785     {
10786       tree t = lookup_name (c_parser_peek_token (parser)->value);
10787 
10788       if (t == NULL_TREE)
10789 	{
10790 	  undeclared_variable (c_parser_peek_token (parser)->location,
10791 			       c_parser_peek_token (parser)->value);
10792 	  t = error_mark_node;
10793 	}
10794 
10795       c_parser_consume_token (parser);
10796 
10797       if (t == error_mark_node)
10798 	;
10799       else if (kind != 0)
10800 	{
10801 	  switch (kind)
10802 	    {
10803 	    case OMP_CLAUSE__CACHE_:
10804 	      /* The OpenACC cache directive explicitly only allows "array
10805 		 elements or subarrays".  */
10806 	      if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
10807 		{
10808 		  c_parser_error (parser, "expected %<[%>");
10809 		  t = error_mark_node;
10810 		  break;
10811 		}
10812 	      /* FALLTHROUGH  */
10813 	    case OMP_CLAUSE_MAP:
10814 	    case OMP_CLAUSE_FROM:
10815 	    case OMP_CLAUSE_TO:
10816 	      while (c_parser_next_token_is (parser, CPP_DOT))
10817 		{
10818 		  location_t op_loc = c_parser_peek_token (parser)->location;
10819 		  c_parser_consume_token (parser);
10820 		  if (!c_parser_next_token_is (parser, CPP_NAME))
10821 		    {
10822 		      c_parser_error (parser, "expected identifier");
10823 		      t = error_mark_node;
10824 		      break;
10825 		    }
10826 
10827 		  c_token *comp_tok = c_parser_peek_token (parser);
10828 		  tree ident = comp_tok->value;
10829 		  location_t comp_loc = comp_tok->location;
10830 		  c_parser_consume_token (parser);
10831 		  t = build_component_ref (op_loc, t, ident, comp_loc);
10832 		}
10833 	      /* FALLTHROUGH  */
10834 	    case OMP_CLAUSE_DEPEND:
10835 	    case OMP_CLAUSE_REDUCTION:
10836 	      while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
10837 		{
10838 		  tree low_bound = NULL_TREE, length = NULL_TREE;
10839 
10840 		  c_parser_consume_token (parser);
10841 		  if (!c_parser_next_token_is (parser, CPP_COLON))
10842 		    {
10843 		      location_t expr_loc
10844 			= c_parser_peek_token (parser)->location;
10845 		      c_expr expr = c_parser_expression (parser);
10846 		      expr = convert_lvalue_to_rvalue (expr_loc, expr,
10847 						       false, true);
10848 		      low_bound = expr.value;
10849 		    }
10850 		  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10851 		    length = integer_one_node;
10852 		  else
10853 		    {
10854 		      /* Look for `:'.  */
10855 		      if (!c_parser_require (parser, CPP_COLON,
10856 					     "expected %<:%>"))
10857 			{
10858 			  t = error_mark_node;
10859 			  break;
10860 			}
10861 		      if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10862 			{
10863 			  location_t expr_loc
10864 			    = c_parser_peek_token (parser)->location;
10865 			  c_expr expr = c_parser_expression (parser);
10866 			  expr = convert_lvalue_to_rvalue (expr_loc, expr,
10867 							   false, true);
10868 			  length = expr.value;
10869 			}
10870 		    }
10871 		  /* Look for the closing `]'.  */
10872 		  if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
10873 					 "expected %<]%>"))
10874 		    {
10875 		      t = error_mark_node;
10876 		      break;
10877 		    }
10878 
10879 		  t = tree_cons (low_bound, length, t);
10880 		}
10881 	      break;
10882 	    default:
10883 	      break;
10884 	    }
10885 
10886 	  if (t != error_mark_node)
10887 	    {
10888 	      tree u = build_omp_clause (clause_loc, kind);
10889 	      OMP_CLAUSE_DECL (u) = t;
10890 	      OMP_CLAUSE_CHAIN (u) = list;
10891 	      list = u;
10892 	    }
10893 	}
10894       else
10895 	list = tree_cons (t, NULL_TREE, list);
10896 
10897       if (c_parser_next_token_is_not (parser, CPP_COMMA))
10898 	break;
10899 
10900       c_parser_consume_token (parser);
10901     }
10902 
10903   return list;
10904 }
10905 
10906 /* Similarly, but expect leading and trailing parenthesis.  This is a very
10907    common case for OpenACC and OpenMP clauses.  */
10908 
10909 static tree
10910 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
10911 			      tree list)
10912 {
10913   /* The clauses location.  */
10914   location_t loc = c_parser_peek_token (parser)->location;
10915 
10916   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10917     {
10918       list = c_parser_omp_variable_list (parser, loc, kind, list);
10919       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10920     }
10921   return list;
10922 }
10923 
10924 /* OpenACC 2.0:
10925    copy ( variable-list )
10926    copyin ( variable-list )
10927    copyout ( variable-list )
10928    create ( variable-list )
10929    delete ( variable-list )
10930    present ( variable-list )
10931    present_or_copy ( variable-list )
10932      pcopy ( variable-list )
10933    present_or_copyin ( variable-list )
10934      pcopyin ( variable-list )
10935    present_or_copyout ( variable-list )
10936      pcopyout ( variable-list )
10937    present_or_create ( variable-list )
10938      pcreate ( variable-list ) */
10939 
10940 static tree
10941 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
10942 			   tree list)
10943 {
10944   enum gomp_map_kind kind;
10945   switch (c_kind)
10946     {
10947     case PRAGMA_OACC_CLAUSE_COPY:
10948       kind = GOMP_MAP_FORCE_TOFROM;
10949       break;
10950     case PRAGMA_OACC_CLAUSE_COPYIN:
10951       kind = GOMP_MAP_FORCE_TO;
10952       break;
10953     case PRAGMA_OACC_CLAUSE_COPYOUT:
10954       kind = GOMP_MAP_FORCE_FROM;
10955       break;
10956     case PRAGMA_OACC_CLAUSE_CREATE:
10957       kind = GOMP_MAP_FORCE_ALLOC;
10958       break;
10959     case PRAGMA_OACC_CLAUSE_DELETE:
10960       kind = GOMP_MAP_DELETE;
10961       break;
10962     case PRAGMA_OACC_CLAUSE_DEVICE:
10963       kind = GOMP_MAP_FORCE_TO;
10964       break;
10965     case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
10966       kind = GOMP_MAP_DEVICE_RESIDENT;
10967       break;
10968     case PRAGMA_OACC_CLAUSE_HOST:
10969     case PRAGMA_OACC_CLAUSE_SELF:
10970       kind = GOMP_MAP_FORCE_FROM;
10971       break;
10972     case PRAGMA_OACC_CLAUSE_LINK:
10973       kind = GOMP_MAP_LINK;
10974       break;
10975     case PRAGMA_OACC_CLAUSE_PRESENT:
10976       kind = GOMP_MAP_FORCE_PRESENT;
10977       break;
10978     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
10979       kind = GOMP_MAP_TOFROM;
10980       break;
10981     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
10982       kind = GOMP_MAP_TO;
10983       break;
10984     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
10985       kind = GOMP_MAP_FROM;
10986       break;
10987     case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
10988       kind = GOMP_MAP_ALLOC;
10989       break;
10990     default:
10991       gcc_unreachable ();
10992     }
10993   tree nl, c;
10994   nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
10995 
10996   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10997     OMP_CLAUSE_SET_MAP_KIND (c, kind);
10998 
10999   return nl;
11000 }
11001 
11002 /* OpenACC 2.0:
11003    deviceptr ( variable-list ) */
11004 
11005 static tree
11006 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
11007 {
11008   location_t loc = c_parser_peek_token (parser)->location;
11009   tree vars, t;
11010 
11011   /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11012      c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11013      variable-list must only allow for pointer variables.  */
11014   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
11015   for (t = vars; t && t; t = TREE_CHAIN (t))
11016     {
11017       tree v = TREE_PURPOSE (t);
11018 
11019       /* FIXME diagnostics: Ideally we should keep individual
11020 	 locations for all the variables in the var list to make the
11021 	 following errors more precise.  Perhaps
11022 	 c_parser_omp_var_list_parens() should construct a list of
11023 	 locations to go along with the var list.  */
11024 
11025       if (!VAR_P (v) && TREE_CODE (v) != PARM_DECL)
11026 	error_at (loc, "%qD is not a variable", v);
11027       else if (TREE_TYPE (v) == error_mark_node)
11028 	;
11029       else if (!POINTER_TYPE_P (TREE_TYPE (v)))
11030 	error_at (loc, "%qD is not a pointer variable", v);
11031 
11032       tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
11033       OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
11034       OMP_CLAUSE_DECL (u) = v;
11035       OMP_CLAUSE_CHAIN (u) = list;
11036       list = u;
11037     }
11038 
11039   return list;
11040 }
11041 
11042 /* OpenACC 2.0, OpenMP 3.0:
11043    collapse ( constant-expression ) */
11044 
11045 static tree
11046 c_parser_omp_clause_collapse (c_parser *parser, tree list)
11047 {
11048   tree c, num = error_mark_node;
11049   HOST_WIDE_INT n;
11050   location_t loc;
11051 
11052   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
11053   check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
11054 
11055   loc = c_parser_peek_token (parser)->location;
11056   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11057     {
11058       num = c_parser_expr_no_commas (parser, NULL).value;
11059       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11060     }
11061   if (num == error_mark_node)
11062     return list;
11063   mark_exp_read (num);
11064   num = c_fully_fold (num, false, NULL);
11065   if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
11066       || !tree_fits_shwi_p (num)
11067       || (n = tree_to_shwi (num)) <= 0
11068       || (int) n != n)
11069     {
11070       error_at (loc,
11071 		"collapse argument needs positive constant integer expression");
11072       return list;
11073     }
11074   c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
11075   OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
11076   OMP_CLAUSE_CHAIN (c) = list;
11077   return c;
11078 }
11079 
11080 /* OpenMP 2.5:
11081    copyin ( variable-list ) */
11082 
11083 static tree
11084 c_parser_omp_clause_copyin (c_parser *parser, tree list)
11085 {
11086   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
11087 }
11088 
11089 /* OpenMP 2.5:
11090    copyprivate ( variable-list ) */
11091 
11092 static tree
11093 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
11094 {
11095   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
11096 }
11097 
11098 /* OpenMP 2.5:
11099    default ( shared | none )
11100 
11101    OpenACC 2.0:
11102    default (none) */
11103 
11104 static tree
11105 c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc)
11106 {
11107   enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
11108   location_t loc = c_parser_peek_token (parser)->location;
11109   tree c;
11110 
11111   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11112     return list;
11113   if (c_parser_next_token_is (parser, CPP_NAME))
11114     {
11115       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11116 
11117       switch (p[0])
11118 	{
11119 	case 'n':
11120 	  if (strcmp ("none", p) != 0)
11121 	    goto invalid_kind;
11122 	  kind = OMP_CLAUSE_DEFAULT_NONE;
11123 	  break;
11124 
11125 	case 's':
11126 	  if (strcmp ("shared", p) != 0 || is_oacc)
11127 	    goto invalid_kind;
11128 	  kind = OMP_CLAUSE_DEFAULT_SHARED;
11129 	  break;
11130 
11131 	default:
11132 	  goto invalid_kind;
11133 	}
11134 
11135       c_parser_consume_token (parser);
11136     }
11137   else
11138     {
11139     invalid_kind:
11140       if (is_oacc)
11141 	c_parser_error (parser, "expected %<none%>");
11142       else
11143 	c_parser_error (parser, "expected %<none%> or %<shared%>");
11144     }
11145   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11146 
11147   if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
11148     return list;
11149 
11150   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
11151   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
11152   OMP_CLAUSE_CHAIN (c) = list;
11153   OMP_CLAUSE_DEFAULT_KIND (c) = kind;
11154 
11155   return c;
11156 }
11157 
11158 /* OpenMP 2.5:
11159    firstprivate ( variable-list ) */
11160 
11161 static tree
11162 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
11163 {
11164   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
11165 }
11166 
11167 /* OpenMP 3.1:
11168    final ( expression ) */
11169 
11170 static tree
11171 c_parser_omp_clause_final (c_parser *parser, tree list)
11172 {
11173   location_t loc = c_parser_peek_token (parser)->location;
11174   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11175     {
11176       tree t = c_parser_paren_condition (parser);
11177       tree c;
11178 
11179       check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
11180 
11181       c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
11182       OMP_CLAUSE_FINAL_EXPR (c) = t;
11183       OMP_CLAUSE_CHAIN (c) = list;
11184       list = c;
11185     }
11186   else
11187     c_parser_error (parser, "expected %<(%>");
11188 
11189   return list;
11190 }
11191 
11192 /* OpenACC, OpenMP 2.5:
11193    if ( expression )
11194 
11195    OpenMP 4.5:
11196    if ( directive-name-modifier : expression )
11197 
11198    directive-name-modifier:
11199      parallel | task | taskloop | target data | target | target update
11200      | target enter data | target exit data  */
11201 
11202 static tree
11203 c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp)
11204 {
11205   location_t location = c_parser_peek_token (parser)->location;
11206   enum tree_code if_modifier = ERROR_MARK;
11207 
11208   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11209     return list;
11210 
11211   if (is_omp && c_parser_next_token_is (parser, CPP_NAME))
11212     {
11213       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11214       int n = 2;
11215       if (strcmp (p, "parallel") == 0)
11216 	if_modifier = OMP_PARALLEL;
11217       else if (strcmp (p, "task") == 0)
11218 	if_modifier = OMP_TASK;
11219       else if (strcmp (p, "taskloop") == 0)
11220 	if_modifier = OMP_TASKLOOP;
11221       else if (strcmp (p, "target") == 0)
11222 	{
11223 	  if_modifier = OMP_TARGET;
11224 	  if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11225 	    {
11226 	      p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value);
11227 	      if (strcmp ("data", p) == 0)
11228 		if_modifier = OMP_TARGET_DATA;
11229 	      else if (strcmp ("update", p) == 0)
11230 		if_modifier = OMP_TARGET_UPDATE;
11231 	      else if (strcmp ("enter", p) == 0)
11232 		if_modifier = OMP_TARGET_ENTER_DATA;
11233 	      else if (strcmp ("exit", p) == 0)
11234 		if_modifier = OMP_TARGET_EXIT_DATA;
11235 	      if (if_modifier != OMP_TARGET)
11236 		{
11237 		  n = 3;
11238 		  c_parser_consume_token (parser);
11239 		}
11240 	      else
11241 		{
11242 		  location_t loc = c_parser_peek_2nd_token (parser)->location;
11243 		  error_at (loc, "expected %<data%>, %<update%>, %<enter%> "
11244 				 "or %<exit%>");
11245 		  if_modifier = ERROR_MARK;
11246 		}
11247 	      if (if_modifier == OMP_TARGET_ENTER_DATA
11248 		  || if_modifier == OMP_TARGET_EXIT_DATA)
11249 		{
11250 		  if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11251 		    {
11252 		      p = IDENTIFIER_POINTER
11253 				(c_parser_peek_2nd_token (parser)->value);
11254 		      if (strcmp ("data", p) == 0)
11255 			n = 4;
11256 		    }
11257 		  if (n == 4)
11258 		    c_parser_consume_token (parser);
11259 		  else
11260 		    {
11261 		      location_t loc
11262 			= c_parser_peek_2nd_token (parser)->location;
11263 		      error_at (loc, "expected %<data%>");
11264 		      if_modifier = ERROR_MARK;
11265 		    }
11266 		}
11267 	    }
11268 	}
11269       if (if_modifier != ERROR_MARK)
11270 	{
11271 	  if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11272 	    {
11273 	      c_parser_consume_token (parser);
11274 	      c_parser_consume_token (parser);
11275 	    }
11276 	  else
11277 	    {
11278 	      if (n > 2)
11279 		{
11280 		  location_t loc = c_parser_peek_2nd_token (parser)->location;
11281 		  error_at (loc, "expected %<:%>");
11282 		}
11283 	      if_modifier = ERROR_MARK;
11284 	    }
11285 	}
11286     }
11287 
11288   tree t = c_parser_condition (parser), c;
11289   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11290 
11291   for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
11292     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF)
11293       {
11294 	if (if_modifier != ERROR_MARK
11295 	    && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
11296 	  {
11297 	    const char *p = NULL;
11298 	    switch (if_modifier)
11299 	      {
11300 	      case OMP_PARALLEL: p = "parallel"; break;
11301 	      case OMP_TASK: p = "task"; break;
11302 	      case OMP_TASKLOOP: p = "taskloop"; break;
11303 	      case OMP_TARGET_DATA: p = "target data"; break;
11304 	      case OMP_TARGET: p = "target"; break;
11305 	      case OMP_TARGET_UPDATE: p = "target update"; break;
11306 	      case OMP_TARGET_ENTER_DATA: p = "enter data"; break;
11307 	      case OMP_TARGET_EXIT_DATA: p = "exit data"; break;
11308 	      default: gcc_unreachable ();
11309 	      }
11310 	    error_at (location, "too many %<if%> clauses with %qs modifier",
11311 		      p);
11312 	    return list;
11313 	  }
11314 	else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
11315 	  {
11316 	    if (!is_omp)
11317 	      error_at (location, "too many %<if%> clauses");
11318 	    else
11319 	      error_at (location, "too many %<if%> clauses without modifier");
11320 	    return list;
11321 	  }
11322 	else if (if_modifier == ERROR_MARK
11323 		 || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK)
11324 	  {
11325 	    error_at (location, "if any %<if%> clause has modifier, then all "
11326 				"%<if%> clauses have to use modifier");
11327 	    return list;
11328 	  }
11329       }
11330 
11331   c = build_omp_clause (location, OMP_CLAUSE_IF);
11332   OMP_CLAUSE_IF_MODIFIER (c) = if_modifier;
11333   OMP_CLAUSE_IF_EXPR (c) = t;
11334   OMP_CLAUSE_CHAIN (c) = list;
11335   return c;
11336 }
11337 
11338 /* OpenMP 2.5:
11339    lastprivate ( variable-list ) */
11340 
11341 static tree
11342 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
11343 {
11344   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
11345 }
11346 
11347 /* OpenMP 3.1:
11348    mergeable */
11349 
11350 static tree
11351 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
11352 {
11353   tree c;
11354 
11355   /* FIXME: Should we allow duplicates?  */
11356   check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
11357 
11358   c = build_omp_clause (c_parser_peek_token (parser)->location,
11359 			OMP_CLAUSE_MERGEABLE);
11360   OMP_CLAUSE_CHAIN (c) = list;
11361 
11362   return c;
11363 }
11364 
11365 /* OpenMP 2.5:
11366    nowait */
11367 
11368 static tree
11369 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
11370 {
11371   tree c;
11372   location_t loc = c_parser_peek_token (parser)->location;
11373 
11374   check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
11375 
11376   c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
11377   OMP_CLAUSE_CHAIN (c) = list;
11378   return c;
11379 }
11380 
11381 /* OpenACC:
11382    num_gangs ( expression ) */
11383 
11384 static tree
11385 c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
11386 {
11387   location_t num_gangs_loc = c_parser_peek_token (parser)->location;
11388   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11389     {
11390       location_t expr_loc = c_parser_peek_token (parser)->location;
11391       c_expr expr = c_parser_expression (parser);
11392       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
11393       tree c, t = expr.value;
11394       t = c_fully_fold (t, false, NULL);
11395 
11396       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11397 
11398       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11399 	{
11400 	  c_parser_error (parser, "expected integer expression");
11401 	  return list;
11402 	}
11403 
11404       /* Attempt to statically determine when the number isn't positive.  */
11405       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11406 		       build_int_cst (TREE_TYPE (t), 0));
11407       protected_set_expr_location (c, expr_loc);
11408       if (c == boolean_true_node)
11409 	{
11410 	  warning_at (expr_loc, 0,
11411 		      "%<num_gangs%> value must be positive");
11412 	  t = integer_one_node;
11413 	}
11414 
11415       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
11416 
11417       c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
11418       OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
11419       OMP_CLAUSE_CHAIN (c) = list;
11420       list = c;
11421     }
11422 
11423   return list;
11424 }
11425 
11426 /* OpenMP 2.5:
11427    num_threads ( expression ) */
11428 
11429 static tree
11430 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
11431 {
11432   location_t num_threads_loc = c_parser_peek_token (parser)->location;
11433   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11434     {
11435       location_t expr_loc = c_parser_peek_token (parser)->location;
11436       c_expr expr = c_parser_expression (parser);
11437       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
11438       tree c, t = expr.value;
11439       t = c_fully_fold (t, false, NULL);
11440 
11441       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11442 
11443       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11444 	{
11445 	  c_parser_error (parser, "expected integer expression");
11446 	  return list;
11447 	}
11448 
11449       /* Attempt to statically determine when the number isn't positive.  */
11450       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11451 		       build_int_cst (TREE_TYPE (t), 0));
11452       protected_set_expr_location (c, expr_loc);
11453       if (c == boolean_true_node)
11454 	{
11455 	  warning_at (expr_loc, 0,
11456 		      "%<num_threads%> value must be positive");
11457 	  t = integer_one_node;
11458 	}
11459 
11460       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
11461 
11462       c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
11463       OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
11464       OMP_CLAUSE_CHAIN (c) = list;
11465       list = c;
11466     }
11467 
11468   return list;
11469 }
11470 
11471 /* OpenMP 4.5:
11472    num_tasks ( expression ) */
11473 
11474 static tree
11475 c_parser_omp_clause_num_tasks (c_parser *parser, tree list)
11476 {
11477   location_t num_tasks_loc = c_parser_peek_token (parser)->location;
11478   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11479     {
11480       location_t expr_loc = c_parser_peek_token (parser)->location;
11481       c_expr expr = c_parser_expression (parser);
11482       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
11483       tree c, t = expr.value;
11484       t = c_fully_fold (t, false, NULL);
11485 
11486       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11487 
11488       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11489 	{
11490 	  c_parser_error (parser, "expected integer expression");
11491 	  return list;
11492 	}
11493 
11494       /* Attempt to statically determine when the number isn't positive.  */
11495       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11496 			   build_int_cst (TREE_TYPE (t), 0));
11497       if (CAN_HAVE_LOCATION_P (c))
11498 	SET_EXPR_LOCATION (c, expr_loc);
11499       if (c == boolean_true_node)
11500 	{
11501 	  warning_at (expr_loc, 0, "%<num_tasks%> value must be positive");
11502 	  t = integer_one_node;
11503 	}
11504 
11505       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks");
11506 
11507       c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS);
11508       OMP_CLAUSE_NUM_TASKS_EXPR (c) = t;
11509       OMP_CLAUSE_CHAIN (c) = list;
11510       list = c;
11511     }
11512 
11513   return list;
11514 }
11515 
11516 /* OpenMP 4.5:
11517    grainsize ( expression ) */
11518 
11519 static tree
11520 c_parser_omp_clause_grainsize (c_parser *parser, tree list)
11521 {
11522   location_t grainsize_loc = c_parser_peek_token (parser)->location;
11523   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11524     {
11525       location_t expr_loc = c_parser_peek_token (parser)->location;
11526       c_expr expr = c_parser_expression (parser);
11527       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
11528       tree c, t = expr.value;
11529       t = c_fully_fold (t, false, NULL);
11530 
11531       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11532 
11533       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11534 	{
11535 	  c_parser_error (parser, "expected integer expression");
11536 	  return list;
11537 	}
11538 
11539       /* Attempt to statically determine when the number isn't positive.  */
11540       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11541 			   build_int_cst (TREE_TYPE (t), 0));
11542       if (CAN_HAVE_LOCATION_P (c))
11543 	SET_EXPR_LOCATION (c, expr_loc);
11544       if (c == boolean_true_node)
11545 	{
11546 	  warning_at (expr_loc, 0, "%<grainsize%> value must be positive");
11547 	  t = integer_one_node;
11548 	}
11549 
11550       check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize");
11551 
11552       c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE);
11553       OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
11554       OMP_CLAUSE_CHAIN (c) = list;
11555       list = c;
11556     }
11557 
11558   return list;
11559 }
11560 
11561 /* OpenMP 4.5:
11562    priority ( expression ) */
11563 
11564 static tree
11565 c_parser_omp_clause_priority (c_parser *parser, tree list)
11566 {
11567   location_t priority_loc = c_parser_peek_token (parser)->location;
11568   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11569     {
11570       location_t expr_loc = c_parser_peek_token (parser)->location;
11571       c_expr expr = c_parser_expression (parser);
11572       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
11573       tree c, t = expr.value;
11574       t = c_fully_fold (t, false, NULL);
11575 
11576       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11577 
11578       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11579 	{
11580 	  c_parser_error (parser, "expected integer expression");
11581 	  return list;
11582 	}
11583 
11584       /* Attempt to statically determine when the number isn't
11585 	 non-negative.  */
11586       c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t,
11587 			   build_int_cst (TREE_TYPE (t), 0));
11588       if (CAN_HAVE_LOCATION_P (c))
11589 	SET_EXPR_LOCATION (c, expr_loc);
11590       if (c == boolean_true_node)
11591 	{
11592 	  warning_at (expr_loc, 0, "%<priority%> value must be non-negative");
11593 	  t = integer_one_node;
11594 	}
11595 
11596       check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority");
11597 
11598       c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY);
11599       OMP_CLAUSE_PRIORITY_EXPR (c) = t;
11600       OMP_CLAUSE_CHAIN (c) = list;
11601       list = c;
11602     }
11603 
11604   return list;
11605 }
11606 
11607 /* OpenMP 4.5:
11608    hint ( expression ) */
11609 
11610 static tree
11611 c_parser_omp_clause_hint (c_parser *parser, tree list)
11612 {
11613   location_t hint_loc = c_parser_peek_token (parser)->location;
11614   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11615     {
11616       location_t expr_loc = c_parser_peek_token (parser)->location;
11617       c_expr expr = c_parser_expression (parser);
11618       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
11619       tree c, t = expr.value;
11620       t = c_fully_fold (t, false, NULL);
11621 
11622       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11623 
11624       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11625 	{
11626 	  c_parser_error (parser, "expected integer expression");
11627 	  return list;
11628 	}
11629 
11630       check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint");
11631 
11632       c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT);
11633       OMP_CLAUSE_HINT_EXPR (c) = t;
11634       OMP_CLAUSE_CHAIN (c) = list;
11635       list = c;
11636     }
11637 
11638   return list;
11639 }
11640 
11641 /* OpenMP 4.5:
11642    defaultmap ( tofrom : scalar ) */
11643 
11644 static tree
11645 c_parser_omp_clause_defaultmap (c_parser *parser, tree list)
11646 {
11647   location_t loc = c_parser_peek_token (parser)->location;
11648   tree c;
11649   const char *p;
11650 
11651   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11652     return list;
11653   if (!c_parser_next_token_is (parser, CPP_NAME))
11654     {
11655       c_parser_error (parser, "expected %<tofrom%>");
11656       goto out_err;
11657     }
11658   p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11659   if (strcmp (p, "tofrom") != 0)
11660     {
11661       c_parser_error (parser, "expected %<tofrom%>");
11662       goto out_err;
11663     }
11664   c_parser_consume_token (parser);
11665   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11666     goto out_err;
11667   if (!c_parser_next_token_is (parser, CPP_NAME))
11668     {
11669       c_parser_error (parser, "expected %<scalar%>");
11670       goto out_err;
11671     }
11672   p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11673   if (strcmp (p, "scalar") != 0)
11674     {
11675       c_parser_error (parser, "expected %<scalar%>");
11676       goto out_err;
11677     }
11678   c_parser_consume_token (parser);
11679   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11680   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap");
11681   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP);
11682   OMP_CLAUSE_CHAIN (c) = list;
11683   return c;
11684 
11685  out_err:
11686   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11687   return list;
11688 }
11689 
11690 /* OpenACC 2.0:
11691    use_device ( variable-list )
11692 
11693    OpenMP 4.5:
11694    use_device_ptr ( variable-list ) */
11695 
11696 static tree
11697 c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list)
11698 {
11699   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR,
11700 				       list);
11701 }
11702 
11703 /* OpenMP 4.5:
11704    is_device_ptr ( variable-list ) */
11705 
11706 static tree
11707 c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list)
11708 {
11709   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list);
11710 }
11711 
11712 /* OpenACC:
11713    num_workers ( expression ) */
11714 
11715 static tree
11716 c_parser_omp_clause_num_workers (c_parser *parser, tree list)
11717 {
11718   location_t num_workers_loc = c_parser_peek_token (parser)->location;
11719   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11720     {
11721       location_t expr_loc = c_parser_peek_token (parser)->location;
11722       c_expr expr = c_parser_expression (parser);
11723       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
11724       tree c, t = expr.value;
11725       t = c_fully_fold (t, false, NULL);
11726 
11727       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11728 
11729       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11730 	{
11731 	  c_parser_error (parser, "expected integer expression");
11732 	  return list;
11733 	}
11734 
11735       /* Attempt to statically determine when the number isn't positive.  */
11736       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11737 		       build_int_cst (TREE_TYPE (t), 0));
11738       protected_set_expr_location (c, expr_loc);
11739       if (c == boolean_true_node)
11740 	{
11741 	  warning_at (expr_loc, 0,
11742 		      "%<num_workers%> value must be positive");
11743 	  t = integer_one_node;
11744 	}
11745 
11746       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
11747 
11748       c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
11749       OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
11750       OMP_CLAUSE_CHAIN (c) = list;
11751       list = c;
11752     }
11753 
11754   return list;
11755 }
11756 
11757 /* OpenACC:
11758 
11759     gang [( gang-arg-list )]
11760     worker [( [num:] int-expr )]
11761     vector [( [length:] int-expr )]
11762 
11763   where gang-arg is one of:
11764 
11765     [num:] int-expr
11766     static: size-expr
11767 
11768   and size-expr may be:
11769 
11770     *
11771     int-expr
11772 */
11773 
11774 static tree
11775 c_parser_oacc_shape_clause (c_parser *parser, omp_clause_code kind,
11776 			    const char *str, tree list)
11777 {
11778   const char *id = "num";
11779   tree ops[2] = { NULL_TREE, NULL_TREE }, c;
11780   location_t loc = c_parser_peek_token (parser)->location;
11781 
11782   if (kind == OMP_CLAUSE_VECTOR)
11783     id = "length";
11784 
11785   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11786     {
11787       c_parser_consume_token (parser);
11788 
11789       do
11790 	{
11791 	  c_token *next = c_parser_peek_token (parser);
11792 	  int idx = 0;
11793 
11794 	  /* Gang static argument.  */
11795 	  if (kind == OMP_CLAUSE_GANG
11796 	      && c_parser_next_token_is_keyword (parser, RID_STATIC))
11797 	    {
11798 	      c_parser_consume_token (parser);
11799 
11800 	      if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11801 		goto cleanup_error;
11802 
11803 	      idx = 1;
11804 	      if (ops[idx] != NULL_TREE)
11805 		{
11806 		  c_parser_error (parser, "too many %<static%> arguments");
11807 		  goto cleanup_error;
11808 		}
11809 
11810 	      /* Check for the '*' argument.  */
11811 	      if (c_parser_next_token_is (parser, CPP_MULT)
11812 		  && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
11813 		      || c_parser_peek_2nd_token (parser)->type
11814 		         == CPP_CLOSE_PAREN))
11815 		{
11816 		  c_parser_consume_token (parser);
11817 		  ops[idx] = integer_minus_one_node;
11818 
11819 		  if (c_parser_next_token_is (parser, CPP_COMMA))
11820 		    {
11821 		      c_parser_consume_token (parser);
11822 		      continue;
11823 		    }
11824 		  else
11825 		    break;
11826 		}
11827 	    }
11828 	  /* Worker num: argument and vector length: arguments.  */
11829 	  else if (c_parser_next_token_is (parser, CPP_NAME)
11830 		   && strcmp (id, IDENTIFIER_POINTER (next->value)) == 0
11831 		   && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11832 	    {
11833 	      c_parser_consume_token (parser);  /* id  */
11834 	      c_parser_consume_token (parser);  /* ':'  */
11835 	    }
11836 
11837 	  /* Now collect the actual argument.  */
11838 	  if (ops[idx] != NULL_TREE)
11839 	    {
11840 	      c_parser_error (parser, "unexpected argument");
11841 	      goto cleanup_error;
11842 	    }
11843 
11844 	  location_t expr_loc = c_parser_peek_token (parser)->location;
11845 	  c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
11846 	  cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
11847 	  tree expr = cexpr.value;
11848 	  if (expr == error_mark_node)
11849 	    goto cleanup_error;
11850 
11851 	  expr = c_fully_fold (expr, false, NULL);
11852 
11853 	  /* Attempt to statically determine when the number isn't a
11854 	     positive integer.  */
11855 
11856 	  if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)))
11857 	    {
11858 	      c_parser_error (parser, "expected integer expression");
11859 	      return list;
11860 	    }
11861 
11862 	  tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr,
11863 				    build_int_cst (TREE_TYPE (expr), 0));
11864 	  if (c == boolean_true_node)
11865 	    {
11866 	      warning_at (loc, 0,
11867 			  "%qs value must be positive", str);
11868 	      expr = integer_one_node;
11869 	    }
11870 
11871 	  ops[idx] = expr;
11872 
11873 	  if (kind == OMP_CLAUSE_GANG
11874 	      && c_parser_next_token_is (parser, CPP_COMMA))
11875 	    {
11876 	      c_parser_consume_token (parser);
11877 	      continue;
11878 	    }
11879 	  break;
11880 	}
11881       while (1);
11882 
11883       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
11884 	goto cleanup_error;
11885     }
11886 
11887   check_no_duplicate_clause (list, kind, str);
11888 
11889   c = build_omp_clause (loc, kind);
11890 
11891   if (ops[1])
11892     OMP_CLAUSE_OPERAND (c, 1) = ops[1];
11893 
11894   OMP_CLAUSE_OPERAND (c, 0) = ops[0];
11895   OMP_CLAUSE_CHAIN (c) = list;
11896 
11897   return c;
11898 
11899  cleanup_error:
11900   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
11901   return list;
11902 }
11903 
11904 /* OpenACC:
11905    auto
11906    independent
11907    nohost
11908    seq */
11909 
11910 static tree
11911 c_parser_oacc_simple_clause (c_parser *parser, enum omp_clause_code code,
11912 			     tree list)
11913 {
11914   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11915 
11916   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11917   OMP_CLAUSE_CHAIN (c) = list;
11918 
11919   return c;
11920 }
11921 
11922 /* OpenACC:
11923    async [( int-expr )] */
11924 
11925 static tree
11926 c_parser_oacc_clause_async (c_parser *parser, tree list)
11927 {
11928   tree c, t;
11929   location_t loc = c_parser_peek_token (parser)->location;
11930 
11931   t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
11932 
11933   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
11934     {
11935       c_parser_consume_token (parser);
11936 
11937       t = c_parser_expression (parser).value;
11938       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11939 	c_parser_error (parser, "expected integer expression");
11940       else if (t == error_mark_node
11941 	  || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
11942 	return list;
11943     }
11944   else
11945     t = c_fully_fold (t, false, NULL);
11946 
11947   check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
11948 
11949   c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
11950   OMP_CLAUSE_ASYNC_EXPR (c) = t;
11951   OMP_CLAUSE_CHAIN (c) = list;
11952   list = c;
11953 
11954   return list;
11955 }
11956 
11957 /* OpenACC 2.0:
11958    tile ( size-expr-list ) */
11959 
11960 static tree
11961 c_parser_oacc_clause_tile (c_parser *parser, tree list)
11962 {
11963   tree c, expr = error_mark_node;
11964   location_t loc;
11965   tree tile = NULL_TREE;
11966 
11967   check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
11968   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
11969 
11970   loc = c_parser_peek_token (parser)->location;
11971   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11972     return list;
11973 
11974   do
11975     {
11976       if (tile && !c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
11977 	return list;
11978 
11979       if (c_parser_next_token_is (parser, CPP_MULT)
11980 	  && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
11981 	      || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
11982 	{
11983 	  c_parser_consume_token (parser);
11984 	  expr = integer_zero_node;
11985 	}
11986       else
11987 	{
11988 	  location_t expr_loc = c_parser_peek_token (parser)->location;
11989 	  c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
11990 	  cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
11991 	  expr = cexpr.value;
11992 
11993 	  if (expr == error_mark_node)
11994 	    {
11995 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11996 					 "expected %<)%>");
11997 	      return list;
11998 	    }
11999 
12000 	  expr = c_fully_fold (expr, false, NULL);
12001 
12002 	  if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
12003 	      || !tree_fits_shwi_p (expr)
12004 	      || tree_to_shwi (expr) <= 0)
12005 	    {
12006 	      error_at (expr_loc, "%<tile%> argument needs positive"
12007 			" integral constant");
12008 	      expr = integer_zero_node;
12009 	    }
12010 	}
12011 
12012       tile = tree_cons (NULL_TREE, expr, tile);
12013     }
12014   while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN));
12015 
12016   /* Consume the trailing ')'.  */
12017   c_parser_consume_token (parser);
12018 
12019   c = build_omp_clause (loc, OMP_CLAUSE_TILE);
12020   tile = nreverse (tile);
12021   OMP_CLAUSE_TILE_LIST (c) = tile;
12022   OMP_CLAUSE_CHAIN (c) = list;
12023   return c;
12024 }
12025 
12026 /* OpenACC:
12027    wait ( int-expr-list ) */
12028 
12029 static tree
12030 c_parser_oacc_clause_wait (c_parser *parser, tree list)
12031 {
12032   location_t clause_loc = c_parser_peek_token (parser)->location;
12033 
12034   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12035     list = c_parser_oacc_wait_list (parser, clause_loc, list);
12036 
12037   return list;
12038 }
12039 
12040 /* OpenMP 2.5:
12041    ordered
12042 
12043    OpenMP 4.5:
12044    ordered ( constant-expression ) */
12045 
12046 static tree
12047 c_parser_omp_clause_ordered (c_parser *parser, tree list)
12048 {
12049   check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
12050 
12051   tree c, num = NULL_TREE;
12052   HOST_WIDE_INT n;
12053   location_t loc = c_parser_peek_token (parser)->location;
12054   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12055     {
12056       c_parser_consume_token (parser);
12057       num = c_parser_expr_no_commas (parser, NULL).value;
12058       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12059     }
12060   if (num == error_mark_node)
12061     return list;
12062   if (num)
12063     {
12064       mark_exp_read (num);
12065       num = c_fully_fold (num, false, NULL);
12066       if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
12067 	  || !tree_fits_shwi_p (num)
12068 	  || (n = tree_to_shwi (num)) <= 0
12069 	  || (int) n != n)
12070 	{
12071 	  error_at (loc, "ordered argument needs positive "
12072 			 "constant integer expression");
12073 	  return list;
12074 	}
12075     }
12076   c = build_omp_clause (loc, OMP_CLAUSE_ORDERED);
12077   OMP_CLAUSE_ORDERED_EXPR (c) = num;
12078   OMP_CLAUSE_CHAIN (c) = list;
12079   return c;
12080 }
12081 
12082 /* OpenMP 2.5:
12083    private ( variable-list ) */
12084 
12085 static tree
12086 c_parser_omp_clause_private (c_parser *parser, tree list)
12087 {
12088   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
12089 }
12090 
12091 /* OpenMP 2.5:
12092    reduction ( reduction-operator : variable-list )
12093 
12094    reduction-operator:
12095      One of: + * - & ^ | && ||
12096 
12097    OpenMP 3.1:
12098 
12099    reduction-operator:
12100      One of: + * - & ^ | && || max min
12101 
12102    OpenMP 4.0:
12103 
12104    reduction-operator:
12105      One of: + * - & ^ | && ||
12106      identifier  */
12107 
12108 static tree
12109 c_parser_omp_clause_reduction (c_parser *parser, tree list)
12110 {
12111   location_t clause_loc = c_parser_peek_token (parser)->location;
12112   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12113     {
12114       enum tree_code code = ERROR_MARK;
12115       tree reduc_id = NULL_TREE;
12116 
12117       switch (c_parser_peek_token (parser)->type)
12118 	{
12119 	case CPP_PLUS:
12120 	  code = PLUS_EXPR;
12121 	  break;
12122 	case CPP_MULT:
12123 	  code = MULT_EXPR;
12124 	  break;
12125 	case CPP_MINUS:
12126 	  code = MINUS_EXPR;
12127 	  break;
12128 	case CPP_AND:
12129 	  code = BIT_AND_EXPR;
12130 	  break;
12131 	case CPP_XOR:
12132 	  code = BIT_XOR_EXPR;
12133 	  break;
12134 	case CPP_OR:
12135 	  code = BIT_IOR_EXPR;
12136 	  break;
12137 	case CPP_AND_AND:
12138 	  code = TRUTH_ANDIF_EXPR;
12139 	  break;
12140 	case CPP_OR_OR:
12141 	  code = TRUTH_ORIF_EXPR;
12142 	  break;
12143         case CPP_NAME:
12144 	  {
12145 	    const char *p
12146 	      = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12147 	    if (strcmp (p, "min") == 0)
12148 	      {
12149 		code = MIN_EXPR;
12150 		break;
12151 	      }
12152 	    if (strcmp (p, "max") == 0)
12153 	      {
12154 		code = MAX_EXPR;
12155 		break;
12156 	      }
12157 	    reduc_id = c_parser_peek_token (parser)->value;
12158 	    break;
12159 	  }
12160 	default:
12161 	  c_parser_error (parser,
12162 			  "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12163 			  "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12164 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
12165 	  return list;
12166 	}
12167       c_parser_consume_token (parser);
12168       reduc_id = c_omp_reduction_id (code, reduc_id);
12169       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12170 	{
12171 	  tree nl, c;
12172 
12173 	  nl = c_parser_omp_variable_list (parser, clause_loc,
12174 					   OMP_CLAUSE_REDUCTION, list);
12175 	  for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12176 	    {
12177 	      tree d = OMP_CLAUSE_DECL (c), type;
12178 	      if (TREE_CODE (d) != TREE_LIST)
12179 		type = TREE_TYPE (d);
12180 	      else
12181 		{
12182 		  int cnt = 0;
12183 		  tree t;
12184 		  for (t = d; TREE_CODE (t) == TREE_LIST; t = TREE_CHAIN (t))
12185 		    cnt++;
12186 		  type = TREE_TYPE (t);
12187 		  while (cnt > 0)
12188 		    {
12189 		      if (TREE_CODE (type) != POINTER_TYPE
12190 			  && TREE_CODE (type) != ARRAY_TYPE)
12191 			break;
12192 		      type = TREE_TYPE (type);
12193 		      cnt--;
12194 		    }
12195 		}
12196 	      while (TREE_CODE (type) == ARRAY_TYPE)
12197 		type = TREE_TYPE (type);
12198 	      OMP_CLAUSE_REDUCTION_CODE (c) = code;
12199 	      if (code == ERROR_MARK
12200 		  || !(INTEGRAL_TYPE_P (type)
12201 		       || TREE_CODE (type) == REAL_TYPE
12202 		       || TREE_CODE (type) == COMPLEX_TYPE))
12203 		OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
12204 		  = c_omp_reduction_lookup (reduc_id,
12205 					    TYPE_MAIN_VARIANT (type));
12206 	    }
12207 
12208 	  list = nl;
12209 	}
12210       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12211     }
12212   return list;
12213 }
12214 
12215 /* OpenMP 2.5:
12216    schedule ( schedule-kind )
12217    schedule ( schedule-kind , expression )
12218 
12219    schedule-kind:
12220      static | dynamic | guided | runtime | auto
12221 
12222    OpenMP 4.5:
12223    schedule ( schedule-modifier : schedule-kind )
12224    schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12225 
12226    schedule-modifier:
12227      simd
12228      monotonic
12229      nonmonotonic  */
12230 
12231 static tree
12232 c_parser_omp_clause_schedule (c_parser *parser, tree list)
12233 {
12234   tree c, t;
12235   location_t loc = c_parser_peek_token (parser)->location;
12236   int modifiers = 0, nmodifiers = 0;
12237 
12238   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12239     return list;
12240 
12241   c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
12242 
12243   while (c_parser_next_token_is (parser, CPP_NAME))
12244     {
12245       tree kind = c_parser_peek_token (parser)->value;
12246       const char *p = IDENTIFIER_POINTER (kind);
12247       if (strcmp ("simd", p) == 0)
12248 	OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
12249       else if (strcmp ("monotonic", p) == 0)
12250 	modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC;
12251       else if (strcmp ("nonmonotonic", p) == 0)
12252 	modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC;
12253       else
12254 	break;
12255       c_parser_consume_token (parser);
12256       if (nmodifiers++ == 0
12257 	  && c_parser_next_token_is (parser, CPP_COMMA))
12258 	c_parser_consume_token (parser);
12259       else
12260 	{
12261 	  c_parser_require (parser, CPP_COLON, "expected %<:%>");
12262 	  break;
12263 	}
12264     }
12265 
12266   if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC
12267 		    | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
12268       == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12269 	  | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
12270     {
12271       error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12272 		     "specified");
12273       modifiers = 0;
12274     }
12275 
12276   if (c_parser_next_token_is (parser, CPP_NAME))
12277     {
12278       tree kind = c_parser_peek_token (parser)->value;
12279       const char *p = IDENTIFIER_POINTER (kind);
12280 
12281       switch (p[0])
12282 	{
12283 	case 'd':
12284 	  if (strcmp ("dynamic", p) != 0)
12285 	    goto invalid_kind;
12286 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
12287 	  break;
12288 
12289         case 'g':
12290 	  if (strcmp ("guided", p) != 0)
12291 	    goto invalid_kind;
12292 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
12293 	  break;
12294 
12295 	case 'r':
12296 	  if (strcmp ("runtime", p) != 0)
12297 	    goto invalid_kind;
12298 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
12299 	  break;
12300 
12301 	default:
12302 	  goto invalid_kind;
12303 	}
12304     }
12305   else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
12306     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
12307   else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
12308     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
12309   else
12310     goto invalid_kind;
12311 
12312   c_parser_consume_token (parser);
12313   if (c_parser_next_token_is (parser, CPP_COMMA))
12314     {
12315       location_t here;
12316       c_parser_consume_token (parser);
12317 
12318       here = c_parser_peek_token (parser)->location;
12319       c_expr expr = c_parser_expr_no_commas (parser, NULL);
12320       expr = convert_lvalue_to_rvalue (here, expr, false, true);
12321       t = expr.value;
12322       t = c_fully_fold (t, false, NULL);
12323 
12324       if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
12325 	error_at (here, "schedule %<runtime%> does not take "
12326 		  "a %<chunk_size%> parameter");
12327       else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
12328 	error_at (here,
12329 		  "schedule %<auto%> does not take "
12330 		  "a %<chunk_size%> parameter");
12331       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
12332 	{
12333 	  /* Attempt to statically determine when the number isn't
12334 	     positive.  */
12335 	  tree s = fold_build2_loc (loc, LE_EXPR, boolean_type_node, t,
12336 				    build_int_cst (TREE_TYPE (t), 0));
12337 	  protected_set_expr_location (s, loc);
12338 	  if (s == boolean_true_node)
12339 	    {
12340 	      warning_at (loc, 0,
12341 			  "chunk size value must be positive");
12342 	      t = integer_one_node;
12343 	    }
12344 	  OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
12345 	}
12346       else
12347 	c_parser_error (parser, "expected integer expression");
12348 
12349       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12350     }
12351   else
12352     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12353 			       "expected %<,%> or %<)%>");
12354 
12355   OMP_CLAUSE_SCHEDULE_KIND (c)
12356     = (enum omp_clause_schedule_kind)
12357       (OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers);
12358 
12359   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
12360   OMP_CLAUSE_CHAIN (c) = list;
12361   return c;
12362 
12363  invalid_kind:
12364   c_parser_error (parser, "invalid schedule kind");
12365   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
12366   return list;
12367 }
12368 
12369 /* OpenMP 2.5:
12370    shared ( variable-list ) */
12371 
12372 static tree
12373 c_parser_omp_clause_shared (c_parser *parser, tree list)
12374 {
12375   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
12376 }
12377 
12378 /* OpenMP 3.0:
12379    untied */
12380 
12381 static tree
12382 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
12383 {
12384   tree c;
12385 
12386   /* FIXME: Should we allow duplicates?  */
12387   check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
12388 
12389   c = build_omp_clause (c_parser_peek_token (parser)->location,
12390 			OMP_CLAUSE_UNTIED);
12391   OMP_CLAUSE_CHAIN (c) = list;
12392 
12393   return c;
12394 }
12395 
12396 /* OpenACC:
12397    vector_length ( expression ) */
12398 
12399 static tree
12400 c_parser_omp_clause_vector_length (c_parser *parser, tree list)
12401 {
12402   location_t vector_length_loc = c_parser_peek_token (parser)->location;
12403   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12404     {
12405       location_t expr_loc = c_parser_peek_token (parser)->location;
12406       c_expr expr = c_parser_expression (parser);
12407       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12408       tree c, t = expr.value;
12409       t = c_fully_fold (t, false, NULL);
12410 
12411       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12412 
12413       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12414 	{
12415 	  c_parser_error (parser, "expected integer expression");
12416 	  return list;
12417 	}
12418 
12419       /* Attempt to statically determine when the number isn't positive.  */
12420       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12421 		       build_int_cst (TREE_TYPE (t), 0));
12422       protected_set_expr_location (c, expr_loc);
12423       if (c == boolean_true_node)
12424 	{
12425 	  warning_at (expr_loc, 0,
12426 		      "%<vector_length%> value must be positive");
12427 	  t = integer_one_node;
12428 	}
12429 
12430       check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
12431 
12432       c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
12433       OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
12434       OMP_CLAUSE_CHAIN (c) = list;
12435       list = c;
12436     }
12437 
12438   return list;
12439 }
12440 
12441 /* OpenMP 4.0:
12442    inbranch
12443    notinbranch */
12444 
12445 static tree
12446 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
12447 			    enum omp_clause_code code, tree list)
12448 {
12449   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
12450 
12451   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
12452   OMP_CLAUSE_CHAIN (c) = list;
12453 
12454   return c;
12455 }
12456 
12457 /* OpenMP 4.0:
12458    parallel
12459    for
12460    sections
12461    taskgroup */
12462 
12463 static tree
12464 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
12465 				enum omp_clause_code code, tree list)
12466 {
12467   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
12468   OMP_CLAUSE_CHAIN (c) = list;
12469 
12470   return c;
12471 }
12472 
12473 /* OpenMP 4.5:
12474    nogroup */
12475 
12476 static tree
12477 c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list)
12478 {
12479   check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup");
12480   tree c = build_omp_clause (c_parser_peek_token (parser)->location,
12481 			     OMP_CLAUSE_NOGROUP);
12482   OMP_CLAUSE_CHAIN (c) = list;
12483   return c;
12484 }
12485 
12486 /* OpenMP 4.5:
12487    simd
12488    threads */
12489 
12490 static tree
12491 c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED,
12492 				 enum omp_clause_code code, tree list)
12493 {
12494   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
12495   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
12496   OMP_CLAUSE_CHAIN (c) = list;
12497   return c;
12498 }
12499 
12500 /* OpenMP 4.0:
12501    num_teams ( expression ) */
12502 
12503 static tree
12504 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
12505 {
12506   location_t num_teams_loc = c_parser_peek_token (parser)->location;
12507   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12508     {
12509       location_t expr_loc = c_parser_peek_token (parser)->location;
12510       c_expr expr = c_parser_expression (parser);
12511       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12512       tree c, t = expr.value;
12513       t = c_fully_fold (t, false, NULL);
12514 
12515       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12516 
12517       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12518 	{
12519 	  c_parser_error (parser, "expected integer expression");
12520 	  return list;
12521 	}
12522 
12523       /* Attempt to statically determine when the number isn't positive.  */
12524       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12525 			   build_int_cst (TREE_TYPE (t), 0));
12526       protected_set_expr_location (c, expr_loc);
12527       if (c == boolean_true_node)
12528 	{
12529 	  warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
12530 	  t = integer_one_node;
12531 	}
12532 
12533       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
12534 
12535       c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
12536       OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
12537       OMP_CLAUSE_CHAIN (c) = list;
12538       list = c;
12539     }
12540 
12541   return list;
12542 }
12543 
12544 /* OpenMP 4.0:
12545    thread_limit ( expression ) */
12546 
12547 static tree
12548 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
12549 {
12550   location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
12551   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12552     {
12553       location_t expr_loc = c_parser_peek_token (parser)->location;
12554       c_expr expr = c_parser_expression (parser);
12555       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12556       tree c, t = expr.value;
12557       t = c_fully_fold (t, false, NULL);
12558 
12559       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12560 
12561       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12562 	{
12563 	  c_parser_error (parser, "expected integer expression");
12564 	  return list;
12565 	}
12566 
12567       /* Attempt to statically determine when the number isn't positive.  */
12568       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12569 			   build_int_cst (TREE_TYPE (t), 0));
12570       protected_set_expr_location (c, expr_loc);
12571       if (c == boolean_true_node)
12572 	{
12573 	  warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
12574 	  t = integer_one_node;
12575 	}
12576 
12577       check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
12578 				 "thread_limit");
12579 
12580       c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
12581       OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
12582       OMP_CLAUSE_CHAIN (c) = list;
12583       list = c;
12584     }
12585 
12586   return list;
12587 }
12588 
12589 /* OpenMP 4.0:
12590    aligned ( variable-list )
12591    aligned ( variable-list : constant-expression ) */
12592 
12593 static tree
12594 c_parser_omp_clause_aligned (c_parser *parser, tree list)
12595 {
12596   location_t clause_loc = c_parser_peek_token (parser)->location;
12597   tree nl, c;
12598 
12599   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12600     return list;
12601 
12602   nl = c_parser_omp_variable_list (parser, clause_loc,
12603 				   OMP_CLAUSE_ALIGNED, list);
12604 
12605   if (c_parser_next_token_is (parser, CPP_COLON))
12606     {
12607       c_parser_consume_token (parser);
12608       location_t expr_loc = c_parser_peek_token (parser)->location;
12609       c_expr expr = c_parser_expr_no_commas (parser, NULL);
12610       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12611       tree alignment = expr.value;
12612       alignment = c_fully_fold (alignment, false, NULL);
12613       if (TREE_CODE (alignment) != INTEGER_CST
12614 	  || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
12615 	  || tree_int_cst_sgn (alignment) != 1)
12616 	{
12617 	  error_at (clause_loc, "%<aligned%> clause alignment expression must "
12618 				"be positive constant integer expression");
12619 	  alignment = NULL_TREE;
12620 	}
12621 
12622       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12623 	OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
12624     }
12625 
12626   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12627   return nl;
12628 }
12629 
12630 /* OpenMP 4.0:
12631    linear ( variable-list )
12632    linear ( variable-list : expression )
12633 
12634    OpenMP 4.5:
12635    linear ( modifier ( variable-list ) )
12636    linear ( modifier ( variable-list ) : expression ) */
12637 
12638 static tree
12639 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn)
12640 {
12641   location_t clause_loc = c_parser_peek_token (parser)->location;
12642   tree nl, c, step;
12643   enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT;
12644 
12645   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12646     return list;
12647 
12648   if (!is_cilk_simd_fn
12649       && c_parser_next_token_is (parser, CPP_NAME))
12650     {
12651       c_token *tok = c_parser_peek_token (parser);
12652       const char *p = IDENTIFIER_POINTER (tok->value);
12653       if (strcmp ("val", p) == 0)
12654 	kind = OMP_CLAUSE_LINEAR_VAL;
12655       if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN)
12656 	kind = OMP_CLAUSE_LINEAR_DEFAULT;
12657       if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
12658 	{
12659 	  c_parser_consume_token (parser);
12660 	  c_parser_consume_token (parser);
12661 	}
12662     }
12663 
12664   nl = c_parser_omp_variable_list (parser, clause_loc,
12665 				   OMP_CLAUSE_LINEAR, list);
12666 
12667   if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
12668     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12669 
12670   if (c_parser_next_token_is (parser, CPP_COLON))
12671     {
12672       c_parser_consume_token (parser);
12673       location_t expr_loc = c_parser_peek_token (parser)->location;
12674       c_expr expr = c_parser_expression (parser);
12675       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12676       step = expr.value;
12677       step = c_fully_fold (step, false, NULL);
12678       if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL)
12679 	{
12680 	  sorry ("using parameters for %<linear%> step is not supported yet");
12681 	  step = integer_one_node;
12682 	}
12683       if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
12684 	{
12685 	  error_at (clause_loc, "%<linear%> clause step expression must "
12686 				"be integral");
12687 	  step = integer_one_node;
12688 	}
12689 
12690     }
12691   else
12692     step = integer_one_node;
12693 
12694   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12695     {
12696       OMP_CLAUSE_LINEAR_STEP (c) = step;
12697       OMP_CLAUSE_LINEAR_KIND (c) = kind;
12698     }
12699 
12700   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12701   return nl;
12702 }
12703 
12704 /* OpenMP 4.0:
12705    safelen ( constant-expression ) */
12706 
12707 static tree
12708 c_parser_omp_clause_safelen (c_parser *parser, tree list)
12709 {
12710   location_t clause_loc = c_parser_peek_token (parser)->location;
12711   tree c, t;
12712 
12713   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12714     return list;
12715 
12716   location_t expr_loc = c_parser_peek_token (parser)->location;
12717   c_expr expr = c_parser_expr_no_commas (parser, NULL);
12718   expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12719   t = expr.value;
12720   t = c_fully_fold (t, false, NULL);
12721   if (TREE_CODE (t) != INTEGER_CST
12722       || !INTEGRAL_TYPE_P (TREE_TYPE (t))
12723       || tree_int_cst_sgn (t) != 1)
12724     {
12725       error_at (clause_loc, "%<safelen%> clause expression must "
12726 			    "be positive constant integer expression");
12727       t = NULL_TREE;
12728     }
12729 
12730   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12731   if (t == NULL_TREE || t == error_mark_node)
12732     return list;
12733 
12734   check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
12735 
12736   c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
12737   OMP_CLAUSE_SAFELEN_EXPR (c) = t;
12738   OMP_CLAUSE_CHAIN (c) = list;
12739   return c;
12740 }
12741 
12742 /* OpenMP 4.0:
12743    simdlen ( constant-expression ) */
12744 
12745 static tree
12746 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
12747 {
12748   location_t clause_loc = c_parser_peek_token (parser)->location;
12749   tree c, t;
12750 
12751   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12752     return list;
12753 
12754   location_t expr_loc = c_parser_peek_token (parser)->location;
12755   c_expr expr = c_parser_expr_no_commas (parser, NULL);
12756   expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12757   t = expr.value;
12758   t = c_fully_fold (t, false, NULL);
12759   if (TREE_CODE (t) != INTEGER_CST
12760       || !INTEGRAL_TYPE_P (TREE_TYPE (t))
12761       || tree_int_cst_sgn (t) != 1)
12762     {
12763       error_at (clause_loc, "%<simdlen%> clause expression must "
12764 			    "be positive constant integer expression");
12765       t = NULL_TREE;
12766     }
12767 
12768   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12769   if (t == NULL_TREE || t == error_mark_node)
12770     return list;
12771 
12772   check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
12773 
12774   c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
12775   OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
12776   OMP_CLAUSE_CHAIN (c) = list;
12777   return c;
12778 }
12779 
12780 /* OpenMP 4.5:
12781    vec:
12782      identifier [+/- integer]
12783      vec , identifier [+/- integer]
12784 */
12785 
12786 static tree
12787 c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc,
12788 				 tree list)
12789 {
12790   tree vec = NULL;
12791   if (c_parser_next_token_is_not (parser, CPP_NAME)
12792       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
12793     {
12794       c_parser_error (parser, "expected identifier");
12795       return list;
12796     }
12797 
12798   while (c_parser_next_token_is (parser, CPP_NAME)
12799 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
12800     {
12801       tree t = lookup_name (c_parser_peek_token (parser)->value);
12802       tree addend = NULL;
12803 
12804       if (t == NULL_TREE)
12805 	{
12806 	  undeclared_variable (c_parser_peek_token (parser)->location,
12807 			       c_parser_peek_token (parser)->value);
12808 	  t = error_mark_node;
12809 	}
12810 
12811       c_parser_consume_token (parser);
12812 
12813       bool neg = false;
12814       if (c_parser_next_token_is (parser, CPP_MINUS))
12815 	neg = true;
12816       else if (!c_parser_next_token_is (parser, CPP_PLUS))
12817 	{
12818 	  addend = integer_zero_node;
12819 	  neg = false;
12820 	  goto add_to_vector;
12821 	}
12822       c_parser_consume_token (parser);
12823 
12824       if (c_parser_next_token_is_not (parser, CPP_NUMBER))
12825 	{
12826 	  c_parser_error (parser, "expected integer");
12827 	  return list;
12828 	}
12829 
12830       addend = c_parser_peek_token (parser)->value;
12831       if (TREE_CODE (addend) != INTEGER_CST)
12832 	{
12833 	  c_parser_error (parser, "expected integer");
12834 	  return list;
12835 	}
12836       c_parser_consume_token (parser);
12837 
12838     add_to_vector:
12839       if (t != error_mark_node)
12840 	{
12841 	  vec = tree_cons (addend, t, vec);
12842 	  if (neg)
12843 	    OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1;
12844 	}
12845 
12846       if (c_parser_next_token_is_not (parser, CPP_COMMA))
12847 	break;
12848 
12849       c_parser_consume_token (parser);
12850     }
12851 
12852   if (vec == NULL_TREE)
12853     return list;
12854 
12855   tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
12856   OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK;
12857   OMP_CLAUSE_DECL (u) = nreverse (vec);
12858   OMP_CLAUSE_CHAIN (u) = list;
12859   return u;
12860 }
12861 
12862 /* OpenMP 4.0:
12863    depend ( depend-kind: variable-list )
12864 
12865    depend-kind:
12866      in | out | inout
12867 
12868    OpenMP 4.5:
12869    depend ( source )
12870 
12871    depend ( sink  : vec )  */
12872 
12873 static tree
12874 c_parser_omp_clause_depend (c_parser *parser, tree list)
12875 {
12876   location_t clause_loc = c_parser_peek_token (parser)->location;
12877   enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
12878   tree nl, c;
12879 
12880   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12881     return list;
12882 
12883   if (c_parser_next_token_is (parser, CPP_NAME))
12884     {
12885       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12886       if (strcmp ("in", p) == 0)
12887 	kind = OMP_CLAUSE_DEPEND_IN;
12888       else if (strcmp ("inout", p) == 0)
12889 	kind = OMP_CLAUSE_DEPEND_INOUT;
12890       else if (strcmp ("out", p) == 0)
12891 	kind = OMP_CLAUSE_DEPEND_OUT;
12892       else if (strcmp ("source", p) == 0)
12893 	kind = OMP_CLAUSE_DEPEND_SOURCE;
12894       else if (strcmp ("sink", p) == 0)
12895 	kind = OMP_CLAUSE_DEPEND_SINK;
12896       else
12897 	goto invalid_kind;
12898     }
12899   else
12900     goto invalid_kind;
12901 
12902   c_parser_consume_token (parser);
12903 
12904   if (kind == OMP_CLAUSE_DEPEND_SOURCE)
12905     {
12906       c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
12907       OMP_CLAUSE_DEPEND_KIND (c) = kind;
12908       OMP_CLAUSE_DECL (c) = NULL_TREE;
12909       OMP_CLAUSE_CHAIN (c) = list;
12910       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12911       return c;
12912     }
12913 
12914   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12915     goto resync_fail;
12916 
12917   if (kind == OMP_CLAUSE_DEPEND_SINK)
12918     nl = c_parser_omp_clause_depend_sink (parser, clause_loc, list);
12919   else
12920     {
12921       nl = c_parser_omp_variable_list (parser, clause_loc,
12922 				       OMP_CLAUSE_DEPEND, list);
12923 
12924       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12925 	OMP_CLAUSE_DEPEND_KIND (c) = kind;
12926     }
12927 
12928   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12929   return nl;
12930 
12931  invalid_kind:
12932   c_parser_error (parser, "invalid depend kind");
12933  resync_fail:
12934   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12935   return list;
12936 }
12937 
12938 /* OpenMP 4.0:
12939    map ( map-kind: variable-list )
12940    map ( variable-list )
12941 
12942    map-kind:
12943      alloc | to | from | tofrom
12944 
12945    OpenMP 4.5:
12946    map-kind:
12947      alloc | to | from | tofrom | release | delete
12948 
12949    map ( always [,] map-kind: variable-list ) */
12950 
12951 static tree
12952 c_parser_omp_clause_map (c_parser *parser, tree list)
12953 {
12954   location_t clause_loc = c_parser_peek_token (parser)->location;
12955   enum gomp_map_kind kind = GOMP_MAP_TOFROM;
12956   int always = 0;
12957   enum c_id_kind always_id_kind = C_ID_NONE;
12958   location_t always_loc = UNKNOWN_LOCATION;
12959   tree always_id = NULL_TREE;
12960   tree nl, c;
12961 
12962   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12963     return list;
12964 
12965   if (c_parser_next_token_is (parser, CPP_NAME))
12966     {
12967       c_token *tok = c_parser_peek_token (parser);
12968       const char *p = IDENTIFIER_POINTER (tok->value);
12969       always_id_kind = tok->id_kind;
12970       always_loc = tok->location;
12971       always_id = tok->value;
12972       if (strcmp ("always", p) == 0)
12973 	{
12974 	  c_token *sectok = c_parser_peek_2nd_token (parser);
12975 	  if (sectok->type == CPP_COMMA)
12976 	    {
12977 	      c_parser_consume_token (parser);
12978 	      c_parser_consume_token (parser);
12979 	      always = 2;
12980 	    }
12981 	  else if (sectok->type == CPP_NAME)
12982 	    {
12983 	      p = IDENTIFIER_POINTER (sectok->value);
12984 	      if (strcmp ("alloc", p) == 0
12985 		  || strcmp ("to", p) == 0
12986 		  || strcmp ("from", p) == 0
12987 		  || strcmp ("tofrom", p) == 0
12988 		  || strcmp ("release", p) == 0
12989 		  || strcmp ("delete", p) == 0)
12990 		{
12991 		  c_parser_consume_token (parser);
12992 		  always = 1;
12993 		}
12994 	    }
12995 	}
12996     }
12997 
12998   if (c_parser_next_token_is (parser, CPP_NAME)
12999       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
13000     {
13001       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13002       if (strcmp ("alloc", p) == 0)
13003 	kind = GOMP_MAP_ALLOC;
13004       else if (strcmp ("to", p) == 0)
13005 	kind = always ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO;
13006       else if (strcmp ("from", p) == 0)
13007 	kind = always ? GOMP_MAP_ALWAYS_FROM : GOMP_MAP_FROM;
13008       else if (strcmp ("tofrom", p) == 0)
13009 	kind = always ? GOMP_MAP_ALWAYS_TOFROM : GOMP_MAP_TOFROM;
13010       else if (strcmp ("release", p) == 0)
13011 	kind = GOMP_MAP_RELEASE;
13012       else if (strcmp ("delete", p) == 0)
13013 	kind = GOMP_MAP_DELETE;
13014       else
13015 	{
13016 	  c_parser_error (parser, "invalid map kind");
13017 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13018 				     "expected %<)%>");
13019 	  return list;
13020 	}
13021       c_parser_consume_token (parser);
13022       c_parser_consume_token (parser);
13023     }
13024   else if (always)
13025     {
13026       if (always_id_kind != C_ID_ID)
13027 	{
13028 	  c_parser_error (parser, "expected identifier");
13029 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13030 	  return list;
13031 	}
13032 
13033       tree t = lookup_name (always_id);
13034       if (t == NULL_TREE)
13035 	{
13036 	  undeclared_variable (always_loc, always_id);
13037 	  t = error_mark_node;
13038 	}
13039       if (t != error_mark_node)
13040 	{
13041 	  tree u = build_omp_clause (clause_loc, OMP_CLAUSE_MAP);
13042 	  OMP_CLAUSE_DECL (u) = t;
13043 	  OMP_CLAUSE_CHAIN (u) = list;
13044 	  OMP_CLAUSE_SET_MAP_KIND (u, kind);
13045 	  list = u;
13046 	}
13047       if (always == 1)
13048 	{
13049 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13050 	  return list;
13051 	}
13052     }
13053 
13054   nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
13055 
13056   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13057     OMP_CLAUSE_SET_MAP_KIND (c, kind);
13058 
13059   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13060   return nl;
13061 }
13062 
13063 /* OpenMP 4.0:
13064    device ( expression ) */
13065 
13066 static tree
13067 c_parser_omp_clause_device (c_parser *parser, tree list)
13068 {
13069   location_t clause_loc = c_parser_peek_token (parser)->location;
13070   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
13071     {
13072       location_t expr_loc = c_parser_peek_token (parser)->location;
13073       c_expr expr = c_parser_expr_no_commas (parser, NULL);
13074       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13075       tree c, t = expr.value;
13076       t = c_fully_fold (t, false, NULL);
13077 
13078       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13079 
13080       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
13081 	{
13082 	  c_parser_error (parser, "expected integer expression");
13083 	  return list;
13084 	}
13085 
13086       check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
13087 
13088       c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
13089       OMP_CLAUSE_DEVICE_ID (c) = t;
13090       OMP_CLAUSE_CHAIN (c) = list;
13091       list = c;
13092     }
13093 
13094   return list;
13095 }
13096 
13097 /* OpenMP 4.0:
13098    dist_schedule ( static )
13099    dist_schedule ( static , expression ) */
13100 
13101 static tree
13102 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
13103 {
13104   tree c, t = NULL_TREE;
13105   location_t loc = c_parser_peek_token (parser)->location;
13106 
13107   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
13108     return list;
13109 
13110   if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
13111     {
13112       c_parser_error (parser, "invalid dist_schedule kind");
13113       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13114 				 "expected %<)%>");
13115       return list;
13116     }
13117 
13118   c_parser_consume_token (parser);
13119   if (c_parser_next_token_is (parser, CPP_COMMA))
13120     {
13121       c_parser_consume_token (parser);
13122 
13123       location_t expr_loc = c_parser_peek_token (parser)->location;
13124       c_expr expr = c_parser_expr_no_commas (parser, NULL);
13125       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13126       t = expr.value;
13127       t = c_fully_fold (t, false, NULL);
13128       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13129     }
13130   else
13131     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13132 			       "expected %<,%> or %<)%>");
13133 
13134   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
13135   if (t == error_mark_node)
13136     return list;
13137 
13138   c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
13139   OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
13140   OMP_CLAUSE_CHAIN (c) = list;
13141   return c;
13142 }
13143 
13144 /* OpenMP 4.0:
13145    proc_bind ( proc-bind-kind )
13146 
13147    proc-bind-kind:
13148      master | close | spread  */
13149 
13150 static tree
13151 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
13152 {
13153   location_t clause_loc = c_parser_peek_token (parser)->location;
13154   enum omp_clause_proc_bind_kind kind;
13155   tree c;
13156 
13157   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
13158     return list;
13159 
13160   if (c_parser_next_token_is (parser, CPP_NAME))
13161     {
13162       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13163       if (strcmp ("master", p) == 0)
13164 	kind = OMP_CLAUSE_PROC_BIND_MASTER;
13165       else if (strcmp ("close", p) == 0)
13166 	kind = OMP_CLAUSE_PROC_BIND_CLOSE;
13167       else if (strcmp ("spread", p) == 0)
13168 	kind = OMP_CLAUSE_PROC_BIND_SPREAD;
13169       else
13170 	goto invalid_kind;
13171     }
13172   else
13173     goto invalid_kind;
13174 
13175   c_parser_consume_token (parser);
13176   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13177   c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
13178   OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
13179   OMP_CLAUSE_CHAIN (c) = list;
13180   return c;
13181 
13182  invalid_kind:
13183   c_parser_error (parser, "invalid proc_bind kind");
13184   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13185   return list;
13186 }
13187 
13188 /* OpenMP 4.0:
13189    to ( variable-list ) */
13190 
13191 static tree
13192 c_parser_omp_clause_to (c_parser *parser, tree list)
13193 {
13194   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
13195 }
13196 
13197 /* OpenMP 4.0:
13198    from ( variable-list ) */
13199 
13200 static tree
13201 c_parser_omp_clause_from (c_parser *parser, tree list)
13202 {
13203   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
13204 }
13205 
13206 /* OpenMP 4.0:
13207    uniform ( variable-list ) */
13208 
13209 static tree
13210 c_parser_omp_clause_uniform (c_parser *parser, tree list)
13211 {
13212   /* The clauses location.  */
13213   location_t loc = c_parser_peek_token (parser)->location;
13214 
13215   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
13216     {
13217       list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
13218 					 list);
13219       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
13220     }
13221   return list;
13222 }
13223 
13224 /* Parse all OpenACC clauses.  The set clauses allowed by the directive
13225    is a bitmask in MASK.  Return the list of clauses found.  */
13226 
13227 static tree
13228 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
13229 			   const char *where, bool finish_p = true)
13230 {
13231   tree clauses = NULL;
13232   bool first = true;
13233 
13234   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13235     {
13236       location_t here;
13237       pragma_omp_clause c_kind;
13238       const char *c_name;
13239       tree prev = clauses;
13240 
13241       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
13242 	c_parser_consume_token (parser);
13243 
13244       here = c_parser_peek_token (parser)->location;
13245       c_kind = c_parser_omp_clause_name (parser);
13246 
13247       switch (c_kind)
13248 	{
13249 	case PRAGMA_OACC_CLAUSE_ASYNC:
13250 	  clauses = c_parser_oacc_clause_async (parser, clauses);
13251 	  c_name = "async";
13252 	  break;
13253 	case PRAGMA_OACC_CLAUSE_AUTO:
13254 	  clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_AUTO,
13255 						clauses);
13256 	  c_name = "auto";
13257 	  break;
13258 	case PRAGMA_OACC_CLAUSE_COLLAPSE:
13259 	  clauses = c_parser_omp_clause_collapse (parser, clauses);
13260 	  c_name = "collapse";
13261 	  break;
13262 	case PRAGMA_OACC_CLAUSE_COPY:
13263 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13264 	  c_name = "copy";
13265 	  break;
13266 	case PRAGMA_OACC_CLAUSE_COPYIN:
13267 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13268 	  c_name = "copyin";
13269 	  break;
13270 	case PRAGMA_OACC_CLAUSE_COPYOUT:
13271 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13272 	  c_name = "copyout";
13273 	  break;
13274 	case PRAGMA_OACC_CLAUSE_CREATE:
13275 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13276 	  c_name = "create";
13277 	  break;
13278 	case PRAGMA_OACC_CLAUSE_DELETE:
13279 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13280 	  c_name = "delete";
13281 	  break;
13282 	case PRAGMA_OMP_CLAUSE_DEFAULT:
13283 	  clauses = c_parser_omp_clause_default (parser, clauses, true);
13284 	  c_name = "default";
13285 	  break;
13286 	case PRAGMA_OACC_CLAUSE_DEVICE:
13287 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13288 	  c_name = "device";
13289 	  break;
13290 	case PRAGMA_OACC_CLAUSE_DEVICEPTR:
13291 	  clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
13292 	  c_name = "deviceptr";
13293 	  break;
13294 	case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
13295 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13296 	  c_name = "device_resident";
13297 	  break;
13298 	case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
13299 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
13300 	  c_name = "firstprivate";
13301 	  break;
13302 	case PRAGMA_OACC_CLAUSE_GANG:
13303 	  c_name = "gang";
13304 	  clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_GANG,
13305 						c_name, clauses);
13306 	  break;
13307 	case PRAGMA_OACC_CLAUSE_HOST:
13308 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13309 	  c_name = "host";
13310 	  break;
13311 	case PRAGMA_OACC_CLAUSE_IF:
13312 	  clauses = c_parser_omp_clause_if (parser, clauses, false);
13313 	  c_name = "if";
13314 	  break;
13315 	case PRAGMA_OACC_CLAUSE_INDEPENDENT:
13316 	  clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_INDEPENDENT,
13317 						clauses);
13318 	  c_name = "independent";
13319 	  break;
13320 	case PRAGMA_OACC_CLAUSE_LINK:
13321 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13322 	  c_name = "link";
13323 	  break;
13324 	case PRAGMA_OACC_CLAUSE_NUM_GANGS:
13325 	  clauses = c_parser_omp_clause_num_gangs (parser, clauses);
13326 	  c_name = "num_gangs";
13327 	  break;
13328 	case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
13329 	  clauses = c_parser_omp_clause_num_workers (parser, clauses);
13330 	  c_name = "num_workers";
13331 	  break;
13332 	case PRAGMA_OACC_CLAUSE_PRESENT:
13333 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13334 	  c_name = "present";
13335 	  break;
13336 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
13337 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13338 	  c_name = "present_or_copy";
13339 	  break;
13340 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
13341 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13342 	  c_name = "present_or_copyin";
13343 	  break;
13344 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
13345 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13346 	  c_name = "present_or_copyout";
13347 	  break;
13348 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
13349 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13350 	  c_name = "present_or_create";
13351 	  break;
13352 	case PRAGMA_OACC_CLAUSE_PRIVATE:
13353 	  clauses = c_parser_omp_clause_private (parser, clauses);
13354 	  c_name = "private";
13355 	  break;
13356 	case PRAGMA_OACC_CLAUSE_REDUCTION:
13357 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
13358 	  c_name = "reduction";
13359 	  break;
13360 	case PRAGMA_OACC_CLAUSE_SELF:
13361 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13362 	  c_name = "self";
13363 	  break;
13364 	case PRAGMA_OACC_CLAUSE_SEQ:
13365 	  clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ,
13366 						clauses);
13367 	  c_name = "seq";
13368 	  break;
13369 	case PRAGMA_OACC_CLAUSE_TILE:
13370 	  clauses = c_parser_oacc_clause_tile (parser, clauses);
13371 	  c_name = "tile";
13372 	  break;
13373 	case PRAGMA_OACC_CLAUSE_USE_DEVICE:
13374 	  clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
13375 	  c_name = "use_device";
13376 	  break;
13377 	case PRAGMA_OACC_CLAUSE_VECTOR:
13378 	  c_name = "vector";
13379 	  clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_VECTOR,
13380 						c_name,	clauses);
13381 	  break;
13382 	case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
13383 	  clauses = c_parser_omp_clause_vector_length (parser, clauses);
13384 	  c_name = "vector_length";
13385 	  break;
13386 	case PRAGMA_OACC_CLAUSE_WAIT:
13387 	  clauses = c_parser_oacc_clause_wait (parser, clauses);
13388 	  c_name = "wait";
13389 	  break;
13390 	case PRAGMA_OACC_CLAUSE_WORKER:
13391 	  c_name = "worker";
13392 	  clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_WORKER,
13393 						c_name, clauses);
13394 	  break;
13395 	default:
13396 	  c_parser_error (parser, "expected %<#pragma acc%> clause");
13397 	  goto saw_error;
13398 	}
13399 
13400       first = false;
13401 
13402       if (((mask >> c_kind) & 1) == 0)
13403 	{
13404 	  /* Remove the invalid clause(s) from the list to avoid
13405 	     confusing the rest of the compiler.  */
13406 	  clauses = prev;
13407 	  error_at (here, "%qs is not valid for %qs", c_name, where);
13408 	}
13409     }
13410 
13411  saw_error:
13412   c_parser_skip_to_pragma_eol (parser);
13413 
13414   if (finish_p)
13415     return c_finish_omp_clauses (clauses, C_ORT_ACC);
13416 
13417   return clauses;
13418 }
13419 
13420 /* Parse all OpenMP clauses.  The set clauses allowed by the directive
13421    is a bitmask in MASK.  Return the list of clauses found.  */
13422 
13423 static tree
13424 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
13425 			  const char *where, bool finish_p = true)
13426 {
13427   tree clauses = NULL;
13428   bool first = true, cilk_simd_fn = false;
13429 
13430   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13431     {
13432       location_t here;
13433       pragma_omp_clause c_kind;
13434       const char *c_name;
13435       tree prev = clauses;
13436 
13437       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
13438 	c_parser_consume_token (parser);
13439 
13440       here = c_parser_peek_token (parser)->location;
13441       c_kind = c_parser_omp_clause_name (parser);
13442 
13443       switch (c_kind)
13444 	{
13445 	case PRAGMA_OMP_CLAUSE_COLLAPSE:
13446 	  clauses = c_parser_omp_clause_collapse (parser, clauses);
13447 	  c_name = "collapse";
13448 	  break;
13449 	case PRAGMA_OMP_CLAUSE_COPYIN:
13450 	  clauses = c_parser_omp_clause_copyin (parser, clauses);
13451 	  c_name = "copyin";
13452 	  break;
13453 	case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
13454 	  clauses = c_parser_omp_clause_copyprivate (parser, clauses);
13455 	  c_name = "copyprivate";
13456 	  break;
13457 	case PRAGMA_OMP_CLAUSE_DEFAULT:
13458 	  clauses = c_parser_omp_clause_default (parser, clauses, false);
13459 	  c_name = "default";
13460 	  break;
13461 	case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
13462 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
13463 	  c_name = "firstprivate";
13464 	  break;
13465 	case PRAGMA_OMP_CLAUSE_FINAL:
13466 	  clauses = c_parser_omp_clause_final (parser, clauses);
13467 	  c_name = "final";
13468 	  break;
13469 	case PRAGMA_OMP_CLAUSE_GRAINSIZE:
13470 	  clauses = c_parser_omp_clause_grainsize (parser, clauses);
13471 	  c_name = "grainsize";
13472 	  break;
13473 	case PRAGMA_OMP_CLAUSE_HINT:
13474 	  clauses = c_parser_omp_clause_hint (parser, clauses);
13475 	  c_name = "hint";
13476 	  break;
13477 	case PRAGMA_OMP_CLAUSE_DEFAULTMAP:
13478 	  clauses = c_parser_omp_clause_defaultmap (parser, clauses);
13479 	  c_name = "defaultmap";
13480 	  break;
13481 	case PRAGMA_OMP_CLAUSE_IF:
13482 	  clauses = c_parser_omp_clause_if (parser, clauses, true);
13483 	  c_name = "if";
13484 	  break;
13485 	case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
13486 	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
13487 	  c_name = "lastprivate";
13488 	  break;
13489 	case PRAGMA_OMP_CLAUSE_MERGEABLE:
13490 	  clauses = c_parser_omp_clause_mergeable (parser, clauses);
13491 	  c_name = "mergeable";
13492 	  break;
13493 	case PRAGMA_OMP_CLAUSE_NOWAIT:
13494 	  clauses = c_parser_omp_clause_nowait (parser, clauses);
13495 	  c_name = "nowait";
13496 	  break;
13497 	case PRAGMA_OMP_CLAUSE_NUM_TASKS:
13498 	  clauses = c_parser_omp_clause_num_tasks (parser, clauses);
13499 	  c_name = "num_tasks";
13500 	  break;
13501 	case PRAGMA_OMP_CLAUSE_NUM_THREADS:
13502 	  clauses = c_parser_omp_clause_num_threads (parser, clauses);
13503 	  c_name = "num_threads";
13504 	  break;
13505 	case PRAGMA_OMP_CLAUSE_ORDERED:
13506 	  clauses = c_parser_omp_clause_ordered (parser, clauses);
13507 	  c_name = "ordered";
13508 	  break;
13509 	case PRAGMA_OMP_CLAUSE_PRIORITY:
13510 	  clauses = c_parser_omp_clause_priority (parser, clauses);
13511 	  c_name = "priority";
13512 	  break;
13513 	case PRAGMA_OMP_CLAUSE_PRIVATE:
13514 	  clauses = c_parser_omp_clause_private (parser, clauses);
13515 	  c_name = "private";
13516 	  break;
13517 	case PRAGMA_OMP_CLAUSE_REDUCTION:
13518 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
13519 	  c_name = "reduction";
13520 	  break;
13521 	case PRAGMA_OMP_CLAUSE_SCHEDULE:
13522 	  clauses = c_parser_omp_clause_schedule (parser, clauses);
13523 	  c_name = "schedule";
13524 	  break;
13525 	case PRAGMA_OMP_CLAUSE_SHARED:
13526 	  clauses = c_parser_omp_clause_shared (parser, clauses);
13527 	  c_name = "shared";
13528 	  break;
13529 	case PRAGMA_OMP_CLAUSE_UNTIED:
13530 	  clauses = c_parser_omp_clause_untied (parser, clauses);
13531 	  c_name = "untied";
13532 	  break;
13533 	case PRAGMA_OMP_CLAUSE_INBRANCH:
13534 	case PRAGMA_CILK_CLAUSE_MASK:
13535 	  clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
13536 						clauses);
13537 	  c_name = "inbranch";
13538 	  break;
13539 	case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
13540 	case PRAGMA_CILK_CLAUSE_NOMASK:
13541 	  clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
13542 						clauses);
13543 	  c_name = "notinbranch";
13544 	  break;
13545 	case PRAGMA_OMP_CLAUSE_PARALLEL:
13546 	  clauses
13547 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
13548 					      clauses);
13549 	  c_name = "parallel";
13550 	  if (!first)
13551 	    {
13552 	     clause_not_first:
13553 	      error_at (here, "%qs must be the first clause of %qs",
13554 			c_name, where);
13555 	      clauses = prev;
13556 	    }
13557 	  break;
13558 	case PRAGMA_OMP_CLAUSE_FOR:
13559 	  clauses
13560 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
13561 					      clauses);
13562 	  c_name = "for";
13563 	  if (!first)
13564 	    goto clause_not_first;
13565 	  break;
13566 	case PRAGMA_OMP_CLAUSE_SECTIONS:
13567 	  clauses
13568 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
13569 					      clauses);
13570 	  c_name = "sections";
13571 	  if (!first)
13572 	    goto clause_not_first;
13573 	  break;
13574 	case PRAGMA_OMP_CLAUSE_TASKGROUP:
13575 	  clauses
13576 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
13577 					      clauses);
13578 	  c_name = "taskgroup";
13579 	  if (!first)
13580 	    goto clause_not_first;
13581 	  break;
13582 	case PRAGMA_OMP_CLAUSE_LINK:
13583 	  clauses
13584 	    = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses);
13585 	  c_name = "link";
13586 	  break;
13587 	case PRAGMA_OMP_CLAUSE_TO:
13588 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0)
13589 	    clauses
13590 	      = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
13591 					      clauses);
13592 	  else
13593 	    clauses = c_parser_omp_clause_to (parser, clauses);
13594 	  c_name = "to";
13595 	  break;
13596 	case PRAGMA_OMP_CLAUSE_FROM:
13597 	  clauses = c_parser_omp_clause_from (parser, clauses);
13598 	  c_name = "from";
13599 	  break;
13600 	case PRAGMA_OMP_CLAUSE_UNIFORM:
13601 	  clauses = c_parser_omp_clause_uniform (parser, clauses);
13602 	  c_name = "uniform";
13603 	  break;
13604 	case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
13605 	  clauses = c_parser_omp_clause_num_teams (parser, clauses);
13606 	  c_name = "num_teams";
13607 	  break;
13608 	case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
13609 	  clauses = c_parser_omp_clause_thread_limit (parser, clauses);
13610 	  c_name = "thread_limit";
13611 	  break;
13612 	case PRAGMA_OMP_CLAUSE_ALIGNED:
13613 	  clauses = c_parser_omp_clause_aligned (parser, clauses);
13614 	  c_name = "aligned";
13615 	  break;
13616 	case PRAGMA_OMP_CLAUSE_LINEAR:
13617 	  if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0)
13618 	   cilk_simd_fn = true;
13619 	  clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn);
13620 	  c_name = "linear";
13621 	  break;
13622 	case PRAGMA_OMP_CLAUSE_DEPEND:
13623 	  clauses = c_parser_omp_clause_depend (parser, clauses);
13624 	  c_name = "depend";
13625 	  break;
13626 	case PRAGMA_OMP_CLAUSE_MAP:
13627 	  clauses = c_parser_omp_clause_map (parser, clauses);
13628 	  c_name = "map";
13629 	  break;
13630 	case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR:
13631 	  clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
13632 	  c_name = "use_device_ptr";
13633 	  break;
13634 	case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR:
13635 	  clauses = c_parser_omp_clause_is_device_ptr (parser, clauses);
13636 	  c_name = "is_device_ptr";
13637 	  break;
13638 	case PRAGMA_OMP_CLAUSE_DEVICE:
13639 	  clauses = c_parser_omp_clause_device (parser, clauses);
13640 	  c_name = "device";
13641 	  break;
13642 	case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
13643 	  clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
13644 	  c_name = "dist_schedule";
13645 	  break;
13646 	case PRAGMA_OMP_CLAUSE_PROC_BIND:
13647 	  clauses = c_parser_omp_clause_proc_bind (parser, clauses);
13648 	  c_name = "proc_bind";
13649 	  break;
13650 	case PRAGMA_OMP_CLAUSE_SAFELEN:
13651 	  clauses = c_parser_omp_clause_safelen (parser, clauses);
13652 	  c_name = "safelen";
13653 	  break;
13654 	case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
13655 	  clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true);
13656 	  c_name = "simdlen";
13657 	  break;
13658 	case PRAGMA_OMP_CLAUSE_SIMDLEN:
13659 	  clauses = c_parser_omp_clause_simdlen (parser, clauses);
13660 	  c_name = "simdlen";
13661 	  break;
13662 	case PRAGMA_OMP_CLAUSE_NOGROUP:
13663 	  clauses = c_parser_omp_clause_nogroup (parser, clauses);
13664 	  c_name = "nogroup";
13665 	  break;
13666 	case PRAGMA_OMP_CLAUSE_THREADS:
13667 	  clauses
13668 	    = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS,
13669 					       clauses);
13670 	  c_name = "threads";
13671 	  break;
13672 	case PRAGMA_OMP_CLAUSE_SIMD:
13673 	  clauses
13674 	    = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD,
13675 					       clauses);
13676 	  c_name = "simd";
13677 	  break;
13678 	default:
13679 	  c_parser_error (parser, "expected %<#pragma omp%> clause");
13680 	  goto saw_error;
13681 	}
13682 
13683       first = false;
13684 
13685       if (((mask >> c_kind) & 1) == 0)
13686 	{
13687 	  /* Remove the invalid clause(s) from the list to avoid
13688 	     confusing the rest of the compiler.  */
13689 	  clauses = prev;
13690 	  error_at (here, "%qs is not valid for %qs", c_name, where);
13691 	}
13692     }
13693 
13694  saw_error:
13695   c_parser_skip_to_pragma_eol (parser);
13696 
13697   if (finish_p)
13698     {
13699       if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0)
13700 	return c_finish_omp_clauses (clauses, C_ORT_OMP_DECLARE_SIMD);
13701       return c_finish_omp_clauses (clauses, C_ORT_OMP);
13702     }
13703 
13704   return clauses;
13705 }
13706 
13707 /* OpenACC 2.0, OpenMP 2.5:
13708    structured-block:
13709      statement
13710 
13711    In practice, we're also interested in adding the statement to an
13712    outer node.  So it is convenient if we work around the fact that
13713    c_parser_statement calls add_stmt.  */
13714 
13715 static tree
13716 c_parser_omp_structured_block (c_parser *parser, bool *if_p)
13717 {
13718   tree stmt = push_stmt_list ();
13719   c_parser_statement (parser, if_p);
13720   return pop_stmt_list (stmt);
13721 }
13722 
13723 /* OpenACC 2.0:
13724    # pragma acc cache (variable-list) new-line
13725 
13726    LOC is the location of the #pragma token.
13727 */
13728 
13729 static tree
13730 c_parser_oacc_cache (location_t loc, c_parser *parser)
13731 {
13732   tree stmt, clauses;
13733 
13734   clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
13735   clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
13736 
13737   c_parser_skip_to_pragma_eol (parser);
13738 
13739   stmt = make_node (OACC_CACHE);
13740   TREE_TYPE (stmt) = void_type_node;
13741   OACC_CACHE_CLAUSES (stmt) = clauses;
13742   SET_EXPR_LOCATION (stmt, loc);
13743   add_stmt (stmt);
13744 
13745   return stmt;
13746 }
13747 
13748 /* OpenACC 2.0:
13749    # pragma acc data oacc-data-clause[optseq] new-line
13750      structured-block
13751 
13752    LOC is the location of the #pragma token.
13753 */
13754 
13755 #define OACC_DATA_CLAUSE_MASK						\
13756 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
13757 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
13758 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
13759 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
13760 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
13761 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
13762 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
13763 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
13764 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
13765 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
13766 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13767 
13768 static tree
13769 c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p)
13770 {
13771   tree stmt, clauses, block;
13772 
13773   clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
13774 				       "#pragma acc data");
13775 
13776   block = c_begin_omp_parallel ();
13777   add_stmt (c_parser_omp_structured_block (parser, if_p));
13778 
13779   stmt = c_finish_oacc_data (loc, clauses, block);
13780 
13781   return stmt;
13782 }
13783 
13784 /* OpenACC 2.0:
13785    # pragma acc declare oacc-data-clause[optseq] new-line
13786 */
13787 
13788 #define OACC_DECLARE_CLAUSE_MASK					\
13789 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
13790 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
13791 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
13792 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
13793 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
13794 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT)	\
13795 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK)		\
13796 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
13797 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
13798 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
13799 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
13800 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13801 
13802 static void
13803 c_parser_oacc_declare (c_parser *parser)
13804 {
13805   location_t pragma_loc = c_parser_peek_token (parser)->location;
13806   tree clauses, stmt, t, decl;
13807 
13808   bool error = false;
13809 
13810   c_parser_consume_pragma (parser);
13811 
13812   clauses = c_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK,
13813 				       "#pragma acc declare");
13814   if (!clauses)
13815     {
13816       error_at (pragma_loc,
13817 		"no valid clauses specified in %<#pragma acc declare%>");
13818       return;
13819     }
13820 
13821   for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t))
13822     {
13823       location_t loc = OMP_CLAUSE_LOCATION (t);
13824       decl = OMP_CLAUSE_DECL (t);
13825       if (!DECL_P (decl))
13826 	{
13827 	  error_at (loc, "array section in %<#pragma acc declare%>");
13828 	  error = true;
13829 	  continue;
13830 	}
13831 
13832       switch (OMP_CLAUSE_MAP_KIND (t))
13833 	{
13834 	case GOMP_MAP_FIRSTPRIVATE_POINTER:
13835 	case GOMP_MAP_FORCE_ALLOC:
13836 	case GOMP_MAP_FORCE_TO:
13837 	case GOMP_MAP_FORCE_DEVICEPTR:
13838 	case GOMP_MAP_DEVICE_RESIDENT:
13839 	  break;
13840 
13841 	case GOMP_MAP_LINK:
13842 	  if (!global_bindings_p ()
13843 	      && (TREE_STATIC (decl)
13844 	       || !DECL_EXTERNAL (decl)))
13845 	    {
13846 	      error_at (loc,
13847 			"%qD must be a global variable in "
13848 			"%<#pragma acc declare link%>",
13849 			decl);
13850 	      error = true;
13851 	      continue;
13852 	    }
13853 	  break;
13854 
13855 	default:
13856 	  if (global_bindings_p ())
13857 	    {
13858 	      error_at (loc, "invalid OpenACC clause at file scope");
13859 	      error = true;
13860 	      continue;
13861 	    }
13862 	  if (DECL_EXTERNAL (decl))
13863 	    {
13864 	      error_at (loc,
13865 			"invalid use of %<extern%> variable %qD "
13866 			"in %<#pragma acc declare%>", decl);
13867 	      error = true;
13868 	      continue;
13869 	    }
13870 	  else if (TREE_PUBLIC (decl))
13871 	    {
13872 	      error_at (loc,
13873 			"invalid use of %<global%> variable %qD "
13874 			"in %<#pragma acc declare%>", decl);
13875 	      error = true;
13876 	      continue;
13877 	    }
13878 	  break;
13879 	}
13880 
13881       if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))
13882 	  || lookup_attribute ("omp declare target link",
13883 			       DECL_ATTRIBUTES (decl)))
13884 	{
13885 	  error_at (loc, "variable %qD used more than once with "
13886 		    "%<#pragma acc declare%>", decl);
13887 	  error = true;
13888 	  continue;
13889 	}
13890 
13891       if (!error)
13892 	{
13893 	  tree id;
13894 
13895 	  if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK)
13896 	    id = get_identifier ("omp declare target link");
13897 	  else
13898 	    id = get_identifier ("omp declare target");
13899 
13900 	  DECL_ATTRIBUTES (decl)
13901 			   = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
13902 
13903 	  if (global_bindings_p ())
13904 	    {
13905 	      symtab_node *node = symtab_node::get (decl);
13906 	      if (node != NULL)
13907 		{
13908 		  node->offloadable = 1;
13909 		  if (ENABLE_OFFLOADING)
13910 		    {
13911 		      g->have_offload = true;
13912 		      if (is_a <varpool_node *> (node))
13913 			vec_safe_push (offload_vars, decl);
13914 		    }
13915 		}
13916 	    }
13917 	}
13918     }
13919 
13920   if (error || global_bindings_p ())
13921     return;
13922 
13923   stmt = make_node (OACC_DECLARE);
13924   TREE_TYPE (stmt) = void_type_node;
13925   OACC_DECLARE_CLAUSES (stmt) = clauses;
13926   SET_EXPR_LOCATION (stmt, pragma_loc);
13927 
13928   add_stmt (stmt);
13929 
13930   return;
13931 }
13932 
13933 /* OpenACC 2.0:
13934    # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13935 
13936    or
13937 
13938    # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13939 
13940 
13941    LOC is the location of the #pragma token.
13942 */
13943 
13944 #define OACC_ENTER_DATA_CLAUSE_MASK					\
13945 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
13946 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
13947 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
13948 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
13949 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
13950 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
13951 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13952 
13953 #define OACC_EXIT_DATA_CLAUSE_MASK					\
13954 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
13955 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
13956 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
13957 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) 		\
13958 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13959 
13960 static void
13961 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
13962 {
13963   location_t loc = c_parser_peek_token (parser)->location;
13964   tree clauses, stmt;
13965   const char *p = "";
13966 
13967   c_parser_consume_pragma (parser);
13968 
13969   if (c_parser_next_token_is (parser, CPP_NAME))
13970     {
13971       p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13972       c_parser_consume_token (parser);
13973     }
13974 
13975   if (strcmp (p, "data") != 0)
13976     {
13977       error_at (loc, "expected %<data%> after %<#pragma acc %s%>",
13978 		enter ? "enter" : "exit");
13979       parser->error = true;
13980       c_parser_skip_to_pragma_eol (parser);
13981       return;
13982     }
13983 
13984   if (enter)
13985     clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
13986 					 "#pragma acc enter data");
13987   else
13988     clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
13989 					 "#pragma acc exit data");
13990 
13991   if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
13992     {
13993       error_at (loc, "%<#pragma acc %s data%> has no data movement clause",
13994 		enter ? "enter" : "exit");
13995       return;
13996     }
13997 
13998   stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);
13999   TREE_TYPE (stmt) = void_type_node;
14000   OMP_STANDALONE_CLAUSES (stmt) = clauses;
14001   SET_EXPR_LOCATION (stmt, loc);
14002   add_stmt (stmt);
14003 }
14004 
14005 
14006 /* OpenACC 2.0:
14007    # pragma acc host_data oacc-data-clause[optseq] new-line
14008      structured-block
14009 */
14010 
14011 #define OACC_HOST_DATA_CLAUSE_MASK					\
14012 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14013 
14014 static tree
14015 c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p)
14016 {
14017   tree stmt, clauses, block;
14018 
14019   clauses = c_parser_oacc_all_clauses (parser, OACC_HOST_DATA_CLAUSE_MASK,
14020 				       "#pragma acc host_data");
14021 
14022   block = c_begin_omp_parallel ();
14023   add_stmt (c_parser_omp_structured_block (parser, if_p));
14024   stmt = c_finish_oacc_host_data (loc, clauses, block);
14025   return stmt;
14026 }
14027 
14028 
14029 /* OpenACC 2.0:
14030 
14031    # pragma acc loop oacc-loop-clause[optseq] new-line
14032      structured-block
14033 
14034    LOC is the location of the #pragma token.
14035 */
14036 
14037 #define OACC_LOOP_CLAUSE_MASK						\
14038 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE)		\
14039 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE)		\
14040 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION)		\
14041 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG)		\
14042 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER)		\
14043 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR)		\
14044 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO)		\
14045 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) 	\
14046 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ)			\
14047 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14048 static tree
14049 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name,
14050 		    omp_clause_mask mask, tree *cclauses, bool *if_p)
14051 {
14052   bool is_parallel = ((mask >> PRAGMA_OACC_CLAUSE_REDUCTION) & 1) == 1;
14053 
14054   strcat (p_name, " loop");
14055   mask |= OACC_LOOP_CLAUSE_MASK;
14056 
14057   tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name,
14058 					    cclauses == NULL);
14059   if (cclauses)
14060     {
14061       clauses = c_oacc_split_loop_clauses (clauses, cclauses, is_parallel);
14062       if (*cclauses)
14063 	*cclauses = c_finish_omp_clauses (*cclauses, C_ORT_ACC);
14064       if (clauses)
14065 	clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
14066     }
14067 
14068   tree block = c_begin_compound_stmt (true);
14069   tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL,
14070 				     if_p);
14071   block = c_end_compound_stmt (loc, block, true);
14072   add_stmt (block);
14073 
14074   return stmt;
14075 }
14076 
14077 /* OpenACC 2.0:
14078    # pragma acc kernels oacc-kernels-clause[optseq] new-line
14079      structured-block
14080 
14081    or
14082 
14083    # pragma acc parallel oacc-parallel-clause[optseq] new-line
14084      structured-block
14085 
14086    LOC is the location of the #pragma token.
14087 */
14088 
14089 #define OACC_KERNELS_CLAUSE_MASK					\
14090 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
14091 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
14092 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
14093 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
14094 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
14095 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT)		\
14096 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
14097 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14098 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
14099 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
14100 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
14101 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
14102 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
14103 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14104 
14105 #define OACC_PARALLEL_CLAUSE_MASK					\
14106 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
14107 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
14108 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
14109 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
14110 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
14111 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT)		\
14112 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
14113 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14114 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE)		\
14115 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE)	\
14116 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS)		\
14117 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS)		\
14118 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
14119 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
14120 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
14121 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
14122 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
14123 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION)		\
14124 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH)	\
14125 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14126 
14127 static tree
14128 c_parser_oacc_kernels_parallel (location_t loc, c_parser *parser,
14129 				enum pragma_kind p_kind, char *p_name,
14130 				bool *if_p)
14131 {
14132   omp_clause_mask mask;
14133   enum tree_code code;
14134   switch (p_kind)
14135     {
14136     case PRAGMA_OACC_KERNELS:
14137       strcat (p_name, " kernels");
14138       mask = OACC_KERNELS_CLAUSE_MASK;
14139       code = OACC_KERNELS;
14140       break;
14141     case PRAGMA_OACC_PARALLEL:
14142       strcat (p_name, " parallel");
14143       mask = OACC_PARALLEL_CLAUSE_MASK;
14144       code = OACC_PARALLEL;
14145       break;
14146     default:
14147       gcc_unreachable ();
14148     }
14149 
14150   if (c_parser_next_token_is (parser, CPP_NAME))
14151     {
14152       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14153       if (strcmp (p, "loop") == 0)
14154 	{
14155 	  c_parser_consume_token (parser);
14156 	  tree block = c_begin_omp_parallel ();
14157 	  tree clauses;
14158 	  c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p);
14159 	  return c_finish_omp_construct (loc, code, block, clauses);
14160 	}
14161     }
14162 
14163   tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name);
14164 
14165   tree block = c_begin_omp_parallel ();
14166   add_stmt (c_parser_omp_structured_block (parser, if_p));
14167 
14168   return c_finish_omp_construct (loc, code, block, clauses);
14169 }
14170 
14171 /* OpenACC 2.0:
14172    # pragma acc routine oacc-routine-clause[optseq] new-line
14173      function-definition
14174 
14175    # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14176 */
14177 
14178 #define OACC_ROUTINE_CLAUSE_MASK					\
14179 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG)		\
14180 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER)		\
14181 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR)		\
14182 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14183 
14184 /* Parse an OpenACC routine directive.  For named directives, we apply
14185    immediately to the named function.  For unnamed ones we then parse
14186    a declaration or definition, which must be for a function.  */
14187 
14188 static void
14189 c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
14190 {
14191   gcc_checking_assert (context == pragma_external);
14192 
14193   oacc_routine_data data;
14194   data.error_seen = false;
14195   data.fndecl_seen = false;
14196   data.clauses = NULL_TREE;
14197   data.loc = c_parser_peek_token (parser)->location;
14198 
14199   c_parser_consume_pragma (parser);
14200 
14201   /* Look for optional '( name )'.  */
14202   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14203     {
14204       c_parser_consume_token (parser); /* '(' */
14205 
14206       tree decl = NULL_TREE;
14207       c_token *name_token = c_parser_peek_token (parser);
14208       location_t name_loc = name_token->location;
14209       if (name_token->type == CPP_NAME
14210 	  && (name_token->id_kind == C_ID_ID
14211 	      || name_token->id_kind == C_ID_TYPENAME))
14212 	{
14213 	  decl = lookup_name (name_token->value);
14214 	  if (!decl)
14215 	    error_at (name_loc,
14216 		      "%qE has not been declared", name_token->value);
14217 	  c_parser_consume_token (parser);
14218 	}
14219       else
14220 	c_parser_error (parser, "expected function name");
14221 
14222       if (!decl
14223 	  || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14224 	{
14225 	  c_parser_skip_to_pragma_eol (parser, false);
14226 	  return;
14227 	}
14228 
14229       data.clauses
14230 	= c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
14231 				     "#pragma acc routine");
14232 
14233       if (TREE_CODE (decl) != FUNCTION_DECL)
14234 	{
14235 	  error_at (name_loc, "%qD does not refer to a function", decl);
14236 	  return;
14237 	}
14238 
14239       c_finish_oacc_routine (&data, decl, false);
14240     }
14241   else /* No optional '( name )'.  */
14242     {
14243       data.clauses
14244 	= c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
14245 				     "#pragma acc routine");
14246 
14247       /* Emit a helpful diagnostic if there's another pragma following this
14248 	 one.  Also don't allow a static assertion declaration, as in the
14249 	 following we'll just parse a *single* "declaration or function
14250 	 definition", and the static assertion counts an one.  */
14251       if (c_parser_next_token_is (parser, CPP_PRAGMA)
14252 	  || c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
14253 	{
14254 	  error_at (data.loc,
14255 		    "%<#pragma acc routine%> not immediately followed by"
14256 		    " function declaration or definition");
14257 	  /* ..., and then just keep going.  */
14258 	  return;
14259 	}
14260 
14261       /* We only have to consider the pragma_external case here.  */
14262       if (c_parser_next_token_is (parser, CPP_KEYWORD)
14263 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14264 	{
14265 	  int ext = disable_extension_diagnostics ();
14266 	  do
14267 	    c_parser_consume_token (parser);
14268 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
14269 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14270 	  c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14271 					 NULL, vNULL, &data);
14272 	  restore_extension_diagnostics (ext);
14273 	}
14274       else
14275 	c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14276 				       NULL, vNULL, &data);
14277     }
14278 }
14279 
14280 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14281    IS_DEFN is true if we're applying it to the definition.  */
14282 
14283 static void
14284 c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl,
14285 		       bool is_defn)
14286 {
14287   /* Keep going if we're in error reporting mode.  */
14288   if (data->error_seen
14289       || fndecl == error_mark_node)
14290     return;
14291 
14292   if (data->fndecl_seen)
14293     {
14294       error_at (data->loc,
14295 		"%<#pragma acc routine%> not immediately followed by"
14296 		" a single function declaration or definition");
14297       data->error_seen = true;
14298       return;
14299     }
14300   if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
14301     {
14302       error_at (data->loc,
14303 		"%<#pragma acc routine%> not immediately followed by"
14304 		" function declaration or definition");
14305       data->error_seen = true;
14306       return;
14307     }
14308 
14309   if (oacc_get_fn_attrib (fndecl))
14310     {
14311       error_at (data->loc,
14312 		"%<#pragma acc routine%> already applied to %qD", fndecl);
14313       data->error_seen = true;
14314       return;
14315     }
14316 
14317   if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
14318     {
14319       error_at (data->loc,
14320 		TREE_USED (fndecl)
14321 		? G_("%<#pragma acc routine%> must be applied before use")
14322 		: G_("%<#pragma acc routine%> must be applied before "
14323 		     "definition"));
14324       data->error_seen = true;
14325       return;
14326     }
14327 
14328   /* Process the routine's dimension clauses.  */
14329   tree dims = oacc_build_routine_dims (data->clauses);
14330   oacc_replace_fn_attrib (fndecl, dims);
14331 
14332   /* Add an "omp declare target" attribute.  */
14333   DECL_ATTRIBUTES (fndecl)
14334     = tree_cons (get_identifier ("omp declare target"),
14335 		 NULL_TREE, DECL_ATTRIBUTES (fndecl));
14336 
14337   /* Remember that we've used this "#pragma acc routine".  */
14338   data->fndecl_seen = true;
14339 }
14340 
14341 /* OpenACC 2.0:
14342    # pragma acc update oacc-update-clause[optseq] new-line
14343 */
14344 
14345 #define OACC_UPDATE_CLAUSE_MASK						\
14346 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
14347 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE)		\
14348 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)		\
14349 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14350 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF)		\
14351 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14352 
14353 static void
14354 c_parser_oacc_update (c_parser *parser)
14355 {
14356   location_t loc = c_parser_peek_token (parser)->location;
14357 
14358   c_parser_consume_pragma (parser);
14359 
14360   tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
14361 					    "#pragma acc update");
14362   if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
14363     {
14364       error_at (loc,
14365 		"%<#pragma acc update%> must contain at least one "
14366 		"%<device%> or %<host%> or %<self%> clause");
14367       return;
14368     }
14369 
14370   if (parser->error)
14371     return;
14372 
14373   tree stmt = make_node (OACC_UPDATE);
14374   TREE_TYPE (stmt) = void_type_node;
14375   OACC_UPDATE_CLAUSES (stmt) = clauses;
14376   SET_EXPR_LOCATION (stmt, loc);
14377   add_stmt (stmt);
14378 }
14379 
14380 /* OpenACC 2.0:
14381    # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14382 
14383    LOC is the location of the #pragma token.
14384 */
14385 
14386 #define OACC_WAIT_CLAUSE_MASK						\
14387 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14388 
14389 static tree
14390 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
14391 {
14392   tree clauses, list = NULL_TREE, stmt = NULL_TREE;
14393 
14394   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
14395     list = c_parser_oacc_wait_list (parser, loc, list);
14396 
14397   strcpy (p_name, " wait");
14398   clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
14399   stmt = c_finish_oacc_wait (loc, list, clauses);
14400   add_stmt (stmt);
14401 
14402   return stmt;
14403 }
14404 
14405 /* OpenMP 2.5:
14406    # pragma omp atomic new-line
14407      expression-stmt
14408 
14409    expression-stmt:
14410      x binop= expr | x++ | ++x | x-- | --x
14411    binop:
14412      +, *, -, /, &, ^, |, <<, >>
14413 
14414   where x is an lvalue expression with scalar type.
14415 
14416    OpenMP 3.1:
14417    # pragma omp atomic new-line
14418      update-stmt
14419 
14420    # pragma omp atomic read new-line
14421      read-stmt
14422 
14423    # pragma omp atomic write new-line
14424      write-stmt
14425 
14426    # pragma omp atomic update new-line
14427      update-stmt
14428 
14429    # pragma omp atomic capture new-line
14430      capture-stmt
14431 
14432    # pragma omp atomic capture new-line
14433      capture-block
14434 
14435    read-stmt:
14436      v = x
14437    write-stmt:
14438      x = expr
14439    update-stmt:
14440      expression-stmt | x = x binop expr
14441    capture-stmt:
14442      v = expression-stmt
14443    capture-block:
14444      { v = x; update-stmt; } | { update-stmt; v = x; }
14445 
14446    OpenMP 4.0:
14447    update-stmt:
14448      expression-stmt | x = x binop expr | x = expr binop x
14449    capture-stmt:
14450      v = update-stmt
14451    capture-block:
14452      { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14453 
14454   where x and v are lvalue expressions with scalar type.
14455 
14456   LOC is the location of the #pragma token.  */
14457 
14458 static void
14459 c_parser_omp_atomic (location_t loc, c_parser *parser)
14460 {
14461   tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
14462   tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
14463   tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
14464   enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
14465   struct c_expr expr;
14466   location_t eloc;
14467   bool structured_block = false;
14468   bool swapped = false;
14469   bool seq_cst = false;
14470   bool non_lvalue_p;
14471 
14472   if (c_parser_next_token_is (parser, CPP_NAME))
14473     {
14474       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14475       if (!strcmp (p, "seq_cst"))
14476 	{
14477 	  seq_cst = true;
14478 	  c_parser_consume_token (parser);
14479 	  if (c_parser_next_token_is (parser, CPP_COMMA)
14480 	      && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
14481 	    c_parser_consume_token (parser);
14482 	}
14483     }
14484   if (c_parser_next_token_is (parser, CPP_NAME))
14485     {
14486       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14487 
14488       if (!strcmp (p, "read"))
14489 	code = OMP_ATOMIC_READ;
14490       else if (!strcmp (p, "write"))
14491 	code = NOP_EXPR;
14492       else if (!strcmp (p, "update"))
14493 	code = OMP_ATOMIC;
14494       else if (!strcmp (p, "capture"))
14495 	code = OMP_ATOMIC_CAPTURE_NEW;
14496       else
14497 	p = NULL;
14498       if (p)
14499 	c_parser_consume_token (parser);
14500     }
14501   if (!seq_cst)
14502     {
14503       if (c_parser_next_token_is (parser, CPP_COMMA)
14504 	  && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
14505 	c_parser_consume_token (parser);
14506 
14507       if (c_parser_next_token_is (parser, CPP_NAME))
14508 	{
14509 	  const char *p
14510 	    = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14511 	  if (!strcmp (p, "seq_cst"))
14512 	    {
14513 	      seq_cst = true;
14514 	      c_parser_consume_token (parser);
14515 	    }
14516 	}
14517     }
14518   c_parser_skip_to_pragma_eol (parser);
14519 
14520   switch (code)
14521     {
14522     case OMP_ATOMIC_READ:
14523     case NOP_EXPR: /* atomic write */
14524       v = c_parser_cast_expression (parser, NULL).value;
14525       non_lvalue_p = !lvalue_p (v);
14526       v = c_fully_fold (v, false, NULL);
14527       if (v == error_mark_node)
14528 	goto saw_error;
14529       if (non_lvalue_p)
14530 	v = non_lvalue (v);
14531       loc = c_parser_peek_token (parser)->location;
14532       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
14533 	goto saw_error;
14534       if (code == NOP_EXPR)
14535 	{
14536 	  lhs = c_parser_expression (parser).value;
14537 	  lhs = c_fully_fold (lhs, false, NULL);
14538 	  if (lhs == error_mark_node)
14539 	    goto saw_error;
14540 	}
14541       else
14542 	{
14543 	  lhs = c_parser_cast_expression (parser, NULL).value;
14544 	  non_lvalue_p = !lvalue_p (lhs);
14545 	  lhs = c_fully_fold (lhs, false, NULL);
14546 	  if (lhs == error_mark_node)
14547 	    goto saw_error;
14548 	  if (non_lvalue_p)
14549 	    lhs = non_lvalue (lhs);
14550 	}
14551       if (code == NOP_EXPR)
14552 	{
14553 	  /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14554 	     opcode.  */
14555 	  code = OMP_ATOMIC;
14556 	  rhs = lhs;
14557 	  lhs = v;
14558 	  v = NULL_TREE;
14559 	}
14560       goto done;
14561     case OMP_ATOMIC_CAPTURE_NEW:
14562       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
14563 	{
14564 	  c_parser_consume_token (parser);
14565 	  structured_block = true;
14566 	}
14567       else
14568 	{
14569 	  v = c_parser_cast_expression (parser, NULL).value;
14570 	  non_lvalue_p = !lvalue_p (v);
14571 	  v = c_fully_fold (v, false, NULL);
14572 	  if (v == error_mark_node)
14573 	    goto saw_error;
14574 	  if (non_lvalue_p)
14575 	    v = non_lvalue (v);
14576 	  if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
14577 	    goto saw_error;
14578 	}
14579       break;
14580     default:
14581       break;
14582     }
14583 
14584   /* For structured_block case we don't know yet whether
14585      old or new x should be captured.  */
14586 restart:
14587   eloc = c_parser_peek_token (parser)->location;
14588   expr = c_parser_cast_expression (parser, NULL);
14589   lhs = expr.value;
14590   expr = default_function_array_conversion (eloc, expr);
14591   unfolded_lhs = expr.value;
14592   lhs = c_fully_fold (lhs, false, NULL);
14593   orig_lhs = lhs;
14594   switch (TREE_CODE (lhs))
14595     {
14596     case ERROR_MARK:
14597     saw_error:
14598       c_parser_skip_to_end_of_block_or_statement (parser);
14599       if (structured_block)
14600 	{
14601 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
14602 	    c_parser_consume_token (parser);
14603 	  else if (code == OMP_ATOMIC_CAPTURE_NEW)
14604 	    {
14605 	      c_parser_skip_to_end_of_block_or_statement (parser);
14606 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
14607 		c_parser_consume_token (parser);
14608 	    }
14609 	}
14610       return;
14611 
14612     case POSTINCREMENT_EXPR:
14613       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
14614 	code = OMP_ATOMIC_CAPTURE_OLD;
14615       /* FALLTHROUGH */
14616     case PREINCREMENT_EXPR:
14617       lhs = TREE_OPERAND (lhs, 0);
14618       unfolded_lhs = NULL_TREE;
14619       opcode = PLUS_EXPR;
14620       rhs = integer_one_node;
14621       break;
14622 
14623     case POSTDECREMENT_EXPR:
14624       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
14625 	code = OMP_ATOMIC_CAPTURE_OLD;
14626       /* FALLTHROUGH */
14627     case PREDECREMENT_EXPR:
14628       lhs = TREE_OPERAND (lhs, 0);
14629       unfolded_lhs = NULL_TREE;
14630       opcode = MINUS_EXPR;
14631       rhs = integer_one_node;
14632       break;
14633 
14634     case COMPOUND_EXPR:
14635       if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
14636 	  && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
14637 	  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
14638 	  && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
14639 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14640 					      (TREE_OPERAND (lhs, 1), 0), 0)))
14641 	     == BOOLEAN_TYPE)
14642 	/* Undo effects of boolean_increment for post {in,de}crement.  */
14643 	lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
14644       /* FALLTHRU */
14645     case MODIFY_EXPR:
14646       if (TREE_CODE (lhs) == MODIFY_EXPR
14647 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
14648 	{
14649 	  /* Undo effects of boolean_increment.  */
14650 	  if (integer_onep (TREE_OPERAND (lhs, 1)))
14651 	    {
14652 	      /* This is pre or post increment.  */
14653 	      rhs = TREE_OPERAND (lhs, 1);
14654 	      lhs = TREE_OPERAND (lhs, 0);
14655 	      unfolded_lhs = NULL_TREE;
14656 	      opcode = NOP_EXPR;
14657 	      if (code == OMP_ATOMIC_CAPTURE_NEW
14658 		  && !structured_block
14659 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
14660 		code = OMP_ATOMIC_CAPTURE_OLD;
14661 	      break;
14662 	    }
14663 	  if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
14664 	      && TREE_OPERAND (lhs, 0)
14665 		 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
14666 	    {
14667 	      /* This is pre or post decrement.  */
14668 	      rhs = TREE_OPERAND (lhs, 1);
14669 	      lhs = TREE_OPERAND (lhs, 0);
14670 	      unfolded_lhs = NULL_TREE;
14671 	      opcode = NOP_EXPR;
14672 	      if (code == OMP_ATOMIC_CAPTURE_NEW
14673 		  && !structured_block
14674 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
14675 		code = OMP_ATOMIC_CAPTURE_OLD;
14676 	      break;
14677 	    }
14678 	}
14679       /* FALLTHRU */
14680     default:
14681       if (!lvalue_p (unfolded_lhs))
14682 	lhs = non_lvalue (lhs);
14683       switch (c_parser_peek_token (parser)->type)
14684 	{
14685 	case CPP_MULT_EQ:
14686 	  opcode = MULT_EXPR;
14687 	  break;
14688 	case CPP_DIV_EQ:
14689 	  opcode = TRUNC_DIV_EXPR;
14690 	  break;
14691 	case CPP_PLUS_EQ:
14692 	  opcode = PLUS_EXPR;
14693 	  break;
14694 	case CPP_MINUS_EQ:
14695 	  opcode = MINUS_EXPR;
14696 	  break;
14697 	case CPP_LSHIFT_EQ:
14698 	  opcode = LSHIFT_EXPR;
14699 	  break;
14700 	case CPP_RSHIFT_EQ:
14701 	  opcode = RSHIFT_EXPR;
14702 	  break;
14703 	case CPP_AND_EQ:
14704 	  opcode = BIT_AND_EXPR;
14705 	  break;
14706 	case CPP_OR_EQ:
14707 	  opcode = BIT_IOR_EXPR;
14708 	  break;
14709 	case CPP_XOR_EQ:
14710 	  opcode = BIT_XOR_EXPR;
14711 	  break;
14712 	case CPP_EQ:
14713 	  c_parser_consume_token (parser);
14714 	  eloc = c_parser_peek_token (parser)->location;
14715 	  expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
14716 	  rhs1 = expr.value;
14717 	  switch (TREE_CODE (rhs1))
14718 	    {
14719 	    case MULT_EXPR:
14720 	    case TRUNC_DIV_EXPR:
14721 	    case RDIV_EXPR:
14722 	    case PLUS_EXPR:
14723 	    case MINUS_EXPR:
14724 	    case LSHIFT_EXPR:
14725 	    case RSHIFT_EXPR:
14726 	    case BIT_AND_EXPR:
14727 	    case BIT_IOR_EXPR:
14728 	    case BIT_XOR_EXPR:
14729 	      if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
14730 		{
14731 		  opcode = TREE_CODE (rhs1);
14732 		  rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
14733 		  rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
14734 		  goto stmt_done;
14735 		}
14736 	      if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
14737 		{
14738 		  opcode = TREE_CODE (rhs1);
14739 		  rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
14740 		  rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
14741 		  swapped = !commutative_tree_code (opcode);
14742 		  goto stmt_done;
14743 		}
14744 	      break;
14745 	    case ERROR_MARK:
14746 	      goto saw_error;
14747 	    default:
14748 	      break;
14749 	    }
14750 	  if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
14751 	    {
14752 	      if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
14753 		{
14754 		  code = OMP_ATOMIC_CAPTURE_OLD;
14755 		  v = lhs;
14756 		  lhs = NULL_TREE;
14757 		  expr = default_function_array_read_conversion (eloc, expr);
14758 		  unfolded_lhs1 = expr.value;
14759 		  lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
14760 		  rhs1 = NULL_TREE;
14761 		  c_parser_consume_token (parser);
14762 		  goto restart;
14763 		}
14764 	      if (structured_block)
14765 		{
14766 		  opcode = NOP_EXPR;
14767 		  expr = default_function_array_read_conversion (eloc, expr);
14768 		  rhs = c_fully_fold (expr.value, false, NULL);
14769 		  rhs1 = NULL_TREE;
14770 		  goto stmt_done;
14771 		}
14772 	    }
14773 	  c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
14774 	  goto saw_error;
14775 	default:
14776 	  c_parser_error (parser,
14777 			  "invalid operator for %<#pragma omp atomic%>");
14778 	  goto saw_error;
14779 	}
14780 
14781       /* Arrange to pass the location of the assignment operator to
14782 	 c_finish_omp_atomic.  */
14783       loc = c_parser_peek_token (parser)->location;
14784       c_parser_consume_token (parser);
14785       eloc = c_parser_peek_token (parser)->location;
14786       expr = c_parser_expression (parser);
14787       expr = default_function_array_read_conversion (eloc, expr);
14788       rhs = expr.value;
14789       rhs = c_fully_fold (rhs, false, NULL);
14790       break;
14791     }
14792 stmt_done:
14793   if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
14794     {
14795       if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
14796 	goto saw_error;
14797       v = c_parser_cast_expression (parser, NULL).value;
14798       non_lvalue_p = !lvalue_p (v);
14799       v = c_fully_fold (v, false, NULL);
14800       if (v == error_mark_node)
14801 	goto saw_error;
14802       if (non_lvalue_p)
14803 	v = non_lvalue (v);
14804       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
14805 	goto saw_error;
14806       eloc = c_parser_peek_token (parser)->location;
14807       expr = c_parser_cast_expression (parser, NULL);
14808       lhs1 = expr.value;
14809       expr = default_function_array_read_conversion (eloc, expr);
14810       unfolded_lhs1 = expr.value;
14811       lhs1 = c_fully_fold (lhs1, false, NULL);
14812       if (lhs1 == error_mark_node)
14813 	goto saw_error;
14814       if (!lvalue_p (unfolded_lhs1))
14815 	lhs1 = non_lvalue (lhs1);
14816     }
14817   if (structured_block)
14818     {
14819       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14820       c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
14821     }
14822 done:
14823   if (unfolded_lhs && unfolded_lhs1
14824       && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
14825     {
14826       error ("%<#pragma omp atomic capture%> uses two different "
14827 	     "expressions for memory");
14828       stmt = error_mark_node;
14829     }
14830   else
14831     stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
14832 				swapped, seq_cst);
14833   if (stmt != error_mark_node)
14834     add_stmt (stmt);
14835 
14836   if (!structured_block)
14837     c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
14838 }
14839 
14840 
14841 /* OpenMP 2.5:
14842    # pragma omp barrier new-line
14843 */
14844 
14845 static void
14846 c_parser_omp_barrier (c_parser *parser)
14847 {
14848   location_t loc = c_parser_peek_token (parser)->location;
14849   c_parser_consume_pragma (parser);
14850   c_parser_skip_to_pragma_eol (parser);
14851 
14852   c_finish_omp_barrier (loc);
14853 }
14854 
14855 /* OpenMP 2.5:
14856    # pragma omp critical [(name)] new-line
14857      structured-block
14858 
14859    OpenMP 4.5:
14860    # pragma omp critical [(name) [hint(expression)]] new-line
14861 
14862   LOC is the location of the #pragma itself.  */
14863 
14864 #define OMP_CRITICAL_CLAUSE_MASK		\
14865 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14866 
14867 static tree
14868 c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p)
14869 {
14870   tree stmt, name = NULL_TREE, clauses = NULL_TREE;
14871 
14872   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14873     {
14874       c_parser_consume_token (parser);
14875       if (c_parser_next_token_is (parser, CPP_NAME))
14876 	{
14877 	  name = c_parser_peek_token (parser)->value;
14878 	  c_parser_consume_token (parser);
14879 	  c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14880 	}
14881       else
14882 	c_parser_error (parser, "expected identifier");
14883 
14884       clauses = c_parser_omp_all_clauses (parser,
14885 					  OMP_CRITICAL_CLAUSE_MASK,
14886 					  "#pragma omp critical");
14887     }
14888   else
14889     {
14890       if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14891 	c_parser_error (parser, "expected %<(%> or end of line");
14892       c_parser_skip_to_pragma_eol (parser);
14893     }
14894 
14895   stmt = c_parser_omp_structured_block (parser, if_p);
14896   return c_finish_omp_critical (loc, stmt, name, clauses);
14897 }
14898 
14899 /* OpenMP 2.5:
14900    # pragma omp flush flush-vars[opt] new-line
14901 
14902    flush-vars:
14903      ( variable-list ) */
14904 
14905 static void
14906 c_parser_omp_flush (c_parser *parser)
14907 {
14908   location_t loc = c_parser_peek_token (parser)->location;
14909   c_parser_consume_pragma (parser);
14910   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14911     c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
14912   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14913     c_parser_error (parser, "expected %<(%> or end of line");
14914   c_parser_skip_to_pragma_eol (parser);
14915 
14916   c_finish_omp_flush (loc);
14917 }
14918 
14919 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14920    The real trick here is to determine the loop control variable early
14921    so that we can push a new decl if necessary to make it private.
14922    LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14923    respectively.  */
14924 
14925 static tree
14926 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
14927 		       tree clauses, tree *cclauses, bool *if_p)
14928 {
14929   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
14930   tree declv, condv, incrv, initv, ret = NULL_TREE;
14931   tree pre_body = NULL_TREE, this_pre_body;
14932   tree ordered_cl = NULL_TREE;
14933   bool fail = false, open_brace_parsed = false;
14934   int i, collapse = 1, ordered = 0, count, nbraces = 0;
14935   location_t for_loc;
14936   bool tiling = false;
14937   vec<tree, va_gc> *for_block = make_tree_vector ();
14938 
14939   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
14940     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
14941       collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
14942     else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
14943       {
14944 	tiling = true;
14945 	collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
14946       }
14947     else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
14948 	     && OMP_CLAUSE_ORDERED_EXPR (cl))
14949       {
14950 	ordered_cl = cl;
14951 	ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl));
14952       }
14953 
14954   if (ordered && ordered < collapse)
14955     {
14956       error_at (OMP_CLAUSE_LOCATION (ordered_cl),
14957 		"%<ordered%> clause parameter is less than %<collapse%>");
14958       OMP_CLAUSE_ORDERED_EXPR (ordered_cl)
14959 	= build_int_cst (NULL_TREE, collapse);
14960       ordered = collapse;
14961     }
14962   if (ordered)
14963     {
14964       for (tree *pc = &clauses; *pc; )
14965 	if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR)
14966 	  {
14967 	    error_at (OMP_CLAUSE_LOCATION (*pc),
14968 		      "%<linear%> clause may not be specified together "
14969 		      "with %<ordered%> clause with a parameter");
14970 	    *pc = OMP_CLAUSE_CHAIN (*pc);
14971 	  }
14972 	else
14973 	  pc = &OMP_CLAUSE_CHAIN (*pc);
14974     }
14975 
14976   gcc_assert (tiling || (collapse >= 1 && ordered >= 0));
14977   count = ordered ? ordered : collapse;
14978 
14979   declv = make_tree_vec (count);
14980   initv = make_tree_vec (count);
14981   condv = make_tree_vec (count);
14982   incrv = make_tree_vec (count);
14983 
14984   if (code != CILK_FOR
14985       && !c_parser_next_token_is_keyword (parser, RID_FOR))
14986     {
14987       c_parser_error (parser, "for statement expected");
14988       return NULL;
14989     }
14990   if (code == CILK_FOR
14991       && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR))
14992     {
14993       c_parser_error (parser, "_Cilk_for statement expected");
14994       return NULL;
14995     }
14996   for_loc = c_parser_peek_token (parser)->location;
14997   c_parser_consume_token (parser);
14998 
14999   for (i = 0; i < count; i++)
15000     {
15001       int bracecount = 0;
15002 
15003       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15004 	goto pop_scopes;
15005 
15006       /* Parse the initialization declaration or expression.  */
15007       if (c_parser_next_tokens_start_declaration (parser))
15008 	{
15009 	  if (i > 0)
15010 	    vec_safe_push (for_block, c_begin_compound_stmt (true));
15011 	  this_pre_body = push_stmt_list ();
15012 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
15013 					 NULL, vNULL);
15014 	  if (this_pre_body)
15015 	    {
15016 	      this_pre_body = pop_stmt_list (this_pre_body);
15017 	      if (pre_body)
15018 		{
15019 		  tree t = pre_body;
15020 		  pre_body = push_stmt_list ();
15021 		  add_stmt (t);
15022 		  add_stmt (this_pre_body);
15023 		  pre_body = pop_stmt_list (pre_body);
15024 		}
15025 	      else
15026 		pre_body = this_pre_body;
15027 	    }
15028 	  decl = check_for_loop_decls (for_loc, flag_isoc99);
15029 	  if (decl == NULL)
15030 	    goto error_init;
15031 	  if (DECL_INITIAL (decl) == error_mark_node)
15032 	    decl = error_mark_node;
15033 	  init = decl;
15034 	}
15035       else if (c_parser_next_token_is (parser, CPP_NAME)
15036 	       && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
15037 	{
15038 	  struct c_expr decl_exp;
15039 	  struct c_expr init_exp;
15040 	  location_t init_loc;
15041 
15042 	  decl_exp = c_parser_postfix_expression (parser);
15043 	  decl = decl_exp.value;
15044 
15045 	  c_parser_require (parser, CPP_EQ, "expected %<=%>");
15046 
15047 	  init_loc = c_parser_peek_token (parser)->location;
15048 	  init_exp = c_parser_expr_no_commas (parser, NULL);
15049 	  init_exp = default_function_array_read_conversion (init_loc,
15050 							     init_exp);
15051 	  init = build_modify_expr (init_loc, decl, decl_exp.original_type,
15052 				    NOP_EXPR, init_loc, init_exp.value,
15053 				    init_exp.original_type);
15054 	  init = c_process_expr_stmt (init_loc, init);
15055 
15056 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15057 	}
15058       else
15059 	{
15060 	error_init:
15061 	  c_parser_error (parser,
15062 			  "expected iteration declaration or initialization");
15063 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
15064 				     "expected %<)%>");
15065 	  fail = true;
15066 	  goto parse_next;
15067 	}
15068 
15069       /* Parse the loop condition.  */
15070       cond = NULL_TREE;
15071       if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
15072 	{
15073 	  location_t cond_loc = c_parser_peek_token (parser)->location;
15074 	  struct c_expr cond_expr
15075 	    = c_parser_binary_expression (parser, NULL, NULL_TREE);
15076 
15077 	  cond = cond_expr.value;
15078 	  cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
15079 	  if (COMPARISON_CLASS_P (cond))
15080 	    {
15081 	      tree op0 = TREE_OPERAND (cond, 0), op1 = TREE_OPERAND (cond, 1);
15082 	      op0 = c_fully_fold (op0, false, NULL);
15083 	      op1 = c_fully_fold (op1, false, NULL);
15084 	      TREE_OPERAND (cond, 0) = op0;
15085 	      TREE_OPERAND (cond, 1) = op1;
15086 	    }
15087 	  switch (cond_expr.original_code)
15088 	    {
15089 	    case GT_EXPR:
15090 	    case GE_EXPR:
15091 	    case LT_EXPR:
15092 	    case LE_EXPR:
15093 	      break;
15094 	    case NE_EXPR:
15095 	      if (code == CILK_SIMD || code == CILK_FOR)
15096 		break;
15097 	      /* FALLTHRU.  */
15098 	    default:
15099 	      /* Can't be cond = error_mark_node, because we want to preserve
15100 		 the location until c_finish_omp_for.  */
15101 	      cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
15102 	      break;
15103 	    }
15104 	  protected_set_expr_location (cond, cond_loc);
15105 	}
15106       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15107 
15108       /* Parse the increment expression.  */
15109       incr = NULL_TREE;
15110       if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
15111 	{
15112 	  location_t incr_loc = c_parser_peek_token (parser)->location;
15113 
15114 	  incr = c_process_expr_stmt (incr_loc,
15115 				      c_parser_expression (parser).value);
15116 	}
15117       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
15118 
15119       if (decl == NULL || decl == error_mark_node || init == error_mark_node)
15120 	fail = true;
15121       else
15122 	{
15123 	  TREE_VEC_ELT (declv, i) = decl;
15124 	  TREE_VEC_ELT (initv, i) = init;
15125 	  TREE_VEC_ELT (condv, i) = cond;
15126 	  TREE_VEC_ELT (incrv, i) = incr;
15127 	}
15128 
15129     parse_next:
15130       if (i == count - 1)
15131 	break;
15132 
15133       /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15134 	 in between the collapsed for loops to be still considered perfectly
15135 	 nested.  Hopefully the final version clarifies this.
15136 	 For now handle (multiple) {'s and empty statements.  */
15137       do
15138 	{
15139 	  if (c_parser_next_token_is_keyword (parser, RID_FOR))
15140 	    {
15141 	      c_parser_consume_token (parser);
15142 	      break;
15143 	    }
15144 	  else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
15145 	    {
15146 	      c_parser_consume_token (parser);
15147 	      bracecount++;
15148 	    }
15149 	  else if (bracecount
15150 		   && c_parser_next_token_is (parser, CPP_SEMICOLON))
15151 	    c_parser_consume_token (parser);
15152 	  else
15153 	    {
15154 	      c_parser_error (parser, "not enough perfectly nested loops");
15155 	      if (bracecount)
15156 		{
15157 		  open_brace_parsed = true;
15158 		  bracecount--;
15159 		}
15160 	      fail = true;
15161 	      count = 0;
15162 	      break;
15163 	    }
15164 	}
15165       while (1);
15166 
15167       nbraces += bracecount;
15168     }
15169 
15170   if (nbraces)
15171     if_p = NULL;
15172 
15173   save_break = c_break_label;
15174   if (code == CILK_SIMD)
15175     c_break_label = build_int_cst (size_type_node, 2);
15176   else
15177     c_break_label = size_one_node;
15178   save_cont = c_cont_label;
15179   c_cont_label = NULL_TREE;
15180   body = push_stmt_list ();
15181 
15182   if (open_brace_parsed)
15183     {
15184       location_t here = c_parser_peek_token (parser)->location;
15185       stmt = c_begin_compound_stmt (true);
15186       c_parser_compound_statement_nostart (parser);
15187       add_stmt (c_end_compound_stmt (here, stmt, true));
15188     }
15189   else
15190     add_stmt (c_parser_c99_block_statement (parser, if_p));
15191   if (c_cont_label)
15192     {
15193       tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
15194       SET_EXPR_LOCATION (t, loc);
15195       add_stmt (t);
15196     }
15197 
15198   body = pop_stmt_list (body);
15199   c_break_label = save_break;
15200   c_cont_label = save_cont;
15201 
15202   while (nbraces)
15203     {
15204       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15205 	{
15206 	  c_parser_consume_token (parser);
15207 	  nbraces--;
15208 	}
15209       else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
15210 	c_parser_consume_token (parser);
15211       else
15212 	{
15213 	  c_parser_error (parser, "collapsed loops not perfectly nested");
15214 	  while (nbraces)
15215 	    {
15216 	      location_t here = c_parser_peek_token (parser)->location;
15217 	      stmt = c_begin_compound_stmt (true);
15218 	      add_stmt (body);
15219 	      c_parser_compound_statement_nostart (parser);
15220 	      body = c_end_compound_stmt (here, stmt, true);
15221 	      nbraces--;
15222 	    }
15223 	  goto pop_scopes;
15224 	}
15225     }
15226 
15227   /* Only bother calling c_finish_omp_for if we haven't already generated
15228      an error from the initialization parsing.  */
15229   if (!fail)
15230     {
15231       stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv,
15232 			       incrv, body, pre_body);
15233 
15234       /* Check for iterators appearing in lb, b or incr expressions.  */
15235       if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL))
15236 	stmt = NULL_TREE;
15237 
15238       if (stmt)
15239 	{
15240 	  add_stmt (stmt);
15241 
15242 	  if (cclauses != NULL
15243 	      && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
15244 	    {
15245 	      tree *c;
15246 	      for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
15247 		if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
15248 		    && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
15249 		  c = &OMP_CLAUSE_CHAIN (*c);
15250 		else
15251 		  {
15252 		    for (i = 0; i < count; i++)
15253 		      if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
15254 			break;
15255 		    if (i == count)
15256 		      c = &OMP_CLAUSE_CHAIN (*c);
15257 		    else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
15258 		      {
15259 			error_at (loc,
15260 				  "iteration variable %qD should not be firstprivate",
15261 				  OMP_CLAUSE_DECL (*c));
15262 			*c = OMP_CLAUSE_CHAIN (*c);
15263 		      }
15264 		    else
15265 		      {
15266 			/* Move lastprivate (decl) clause to OMP_FOR_CLAUSES.  */
15267 			tree l = *c;
15268 			*c = OMP_CLAUSE_CHAIN (*c);
15269 			if (code == OMP_SIMD)
15270 			  {
15271 			    OMP_CLAUSE_CHAIN (l)
15272 			      = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
15273 			    cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
15274 			  }
15275 			else
15276 			  {
15277 			    OMP_CLAUSE_CHAIN (l) = clauses;
15278 			    clauses = l;
15279 			  }
15280 		      }
15281 		  }
15282 	    }
15283 	  OMP_FOR_CLAUSES (stmt) = clauses;
15284 	}
15285       ret = stmt;
15286     }
15287 pop_scopes:
15288   while (!for_block->is_empty ())
15289     {
15290       /* FIXME diagnostics: LOC below should be the actual location of
15291 	 this particular for block.  We need to build a list of
15292 	 locations to go along with FOR_BLOCK.  */
15293       stmt = c_end_compound_stmt (loc, for_block->pop (), true);
15294       add_stmt (stmt);
15295     }
15296   release_tree_vector (for_block);
15297   return ret;
15298 }
15299 
15300 /* Helper function for OpenMP parsing, split clauses and call
15301    finish_omp_clauses on each of the set of clauses afterwards.  */
15302 
15303 static void
15304 omp_split_clauses (location_t loc, enum tree_code code,
15305 		   omp_clause_mask mask, tree clauses, tree *cclauses)
15306 {
15307   int i;
15308   c_omp_split_clauses (loc, code, mask, clauses, cclauses);
15309   for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
15310     if (cclauses[i])
15311       cclauses[i] = c_finish_omp_clauses (cclauses[i], C_ORT_OMP);
15312 }
15313 
15314 /* OpenMP 4.0:
15315    #pragma omp simd simd-clause[optseq] new-line
15316      for-loop
15317 
15318    LOC is the location of the #pragma token.
15319 */
15320 
15321 #define OMP_SIMD_CLAUSE_MASK					\
15322 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN)	\
15323 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN)	\
15324 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
15325 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)	\
15326 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15327 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
15328 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
15329 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15330 
15331 static tree
15332 c_parser_omp_simd (location_t loc, c_parser *parser,
15333 		   char *p_name, omp_clause_mask mask, tree *cclauses,
15334 		   bool *if_p)
15335 {
15336   tree block, clauses, ret;
15337 
15338   strcat (p_name, " simd");
15339   mask |= OMP_SIMD_CLAUSE_MASK;
15340 
15341   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15342   if (cclauses)
15343     {
15344       omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
15345       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
15346       tree c = omp_find_clause (cclauses[C_OMP_CLAUSE_SPLIT_FOR],
15347 				OMP_CLAUSE_ORDERED);
15348       if (c && OMP_CLAUSE_ORDERED_EXPR (c))
15349 	{
15350 	  error_at (OMP_CLAUSE_LOCATION (c),
15351 		    "%<ordered%> clause with parameter may not be specified "
15352 		    "on %qs construct", p_name);
15353 	  OMP_CLAUSE_ORDERED_EXPR (c) = NULL_TREE;
15354 	}
15355     }
15356 
15357   block = c_begin_compound_stmt (true);
15358   ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p);
15359   block = c_end_compound_stmt (loc, block, true);
15360   add_stmt (block);
15361 
15362   return ret;
15363 }
15364 
15365 /* OpenMP 2.5:
15366    #pragma omp for for-clause[optseq] new-line
15367      for-loop
15368 
15369    OpenMP 4.0:
15370    #pragma omp for simd for-simd-clause[optseq] new-line
15371      for-loop
15372 
15373    LOC is the location of the #pragma token.
15374 */
15375 
15376 #define OMP_FOR_CLAUSE_MASK					\
15377 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15378 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
15379 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
15380 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
15381 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
15382 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED)	\
15383 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)	\
15384 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)	\
15385 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15386 
15387 static tree
15388 c_parser_omp_for (location_t loc, c_parser *parser,
15389 		  char *p_name, omp_clause_mask mask, tree *cclauses,
15390 		  bool *if_p)
15391 {
15392   tree block, clauses, ret;
15393 
15394   strcat (p_name, " for");
15395   mask |= OMP_FOR_CLAUSE_MASK;
15396   /* parallel for{, simd} disallows nowait clause, but for
15397      target {teams distribute ,}parallel for{, simd} it should be accepted.  */
15398   if (cclauses && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0)
15399     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
15400   /* Composite distribute parallel for{, simd} disallows ordered clause.  */
15401   if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
15402     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
15403 
15404   if (c_parser_next_token_is (parser, CPP_NAME))
15405     {
15406       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15407 
15408       if (strcmp (p, "simd") == 0)
15409 	{
15410 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
15411 	  if (cclauses == NULL)
15412 	    cclauses = cclauses_buf;
15413 
15414 	  c_parser_consume_token (parser);
15415 	  if (!flag_openmp)  /* flag_openmp_simd  */
15416 	    return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
15417 				      if_p);
15418 	  block = c_begin_compound_stmt (true);
15419 	  ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
15420 	  block = c_end_compound_stmt (loc, block, true);
15421 	  if (ret == NULL_TREE)
15422 	    return ret;
15423 	  ret = make_node (OMP_FOR);
15424 	  TREE_TYPE (ret) = void_type_node;
15425 	  OMP_FOR_BODY (ret) = block;
15426 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
15427 	  SET_EXPR_LOCATION (ret, loc);
15428 	  add_stmt (ret);
15429 	  return ret;
15430 	}
15431     }
15432   if (!flag_openmp)  /* flag_openmp_simd  */
15433     {
15434       c_parser_skip_to_pragma_eol (parser, false);
15435       return NULL_TREE;
15436     }
15437 
15438   /* Composite distribute parallel for disallows linear clause.  */
15439   if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
15440     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR);
15441 
15442   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15443   if (cclauses)
15444     {
15445       omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
15446       clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
15447     }
15448 
15449   block = c_begin_compound_stmt (true);
15450   ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p);
15451   block = c_end_compound_stmt (loc, block, true);
15452   add_stmt (block);
15453 
15454   return ret;
15455 }
15456 
15457 /* OpenMP 2.5:
15458    # pragma omp master new-line
15459      structured-block
15460 
15461    LOC is the location of the #pragma token.
15462 */
15463 
15464 static tree
15465 c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p)
15466 {
15467   c_parser_skip_to_pragma_eol (parser);
15468   return c_finish_omp_master (loc, c_parser_omp_structured_block (parser,
15469 								  if_p));
15470 }
15471 
15472 /* OpenMP 2.5:
15473    # pragma omp ordered new-line
15474      structured-block
15475 
15476    OpenMP 4.5:
15477    # pragma omp ordered ordered-clauses new-line
15478      structured-block
15479 
15480    # pragma omp ordered depend-clauses new-line  */
15481 
15482 #define OMP_ORDERED_CLAUSE_MASK					\
15483 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS)	\
15484 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15485 
15486 #define OMP_ORDERED_DEPEND_CLAUSE_MASK				\
15487 	(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15488 
15489 static bool
15490 c_parser_omp_ordered (c_parser *parser, enum pragma_context context,
15491 		      bool *if_p)
15492 {
15493   location_t loc = c_parser_peek_token (parser)->location;
15494   c_parser_consume_pragma (parser);
15495 
15496   if (context != pragma_stmt && context != pragma_compound)
15497     {
15498       c_parser_error (parser, "expected declaration specifiers");
15499       c_parser_skip_to_pragma_eol (parser, false);
15500       return false;
15501     }
15502 
15503   if (c_parser_next_token_is (parser, CPP_NAME))
15504     {
15505       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15506 
15507       if (!strcmp ("depend", p))
15508 	{
15509 	  if (context == pragma_stmt)
15510 	    {
15511 	      error_at (loc,
15512 			"%<#pragma omp ordered%> with %<depend%> clause may "
15513 			"only be used in compound statements");
15514 	      c_parser_skip_to_pragma_eol (parser, false);
15515 	      return false;
15516 	    }
15517 
15518 	  tree clauses
15519 	    = c_parser_omp_all_clauses (parser,
15520 					OMP_ORDERED_DEPEND_CLAUSE_MASK,
15521 					"#pragma omp ordered");
15522 	  c_finish_omp_ordered (loc, clauses, NULL_TREE);
15523 	  return false;
15524 	}
15525     }
15526 
15527   tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK,
15528 					   "#pragma omp ordered");
15529   c_finish_omp_ordered (loc, clauses,
15530 			c_parser_omp_structured_block (parser, if_p));
15531   return true;
15532 }
15533 
15534 /* OpenMP 2.5:
15535 
15536    section-scope:
15537      { section-sequence }
15538 
15539    section-sequence:
15540      section-directive[opt] structured-block
15541      section-sequence section-directive structured-block
15542 
15543     SECTIONS_LOC is the location of the #pragma omp sections.  */
15544 
15545 static tree
15546 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
15547 {
15548   tree stmt, substmt;
15549   bool error_suppress = false;
15550   location_t loc;
15551 
15552   loc = c_parser_peek_token (parser)->location;
15553   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
15554     {
15555       /* Avoid skipping until the end of the block.  */
15556       parser->error = false;
15557       return NULL_TREE;
15558     }
15559 
15560   stmt = push_stmt_list ();
15561 
15562   if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
15563     {
15564       substmt = c_parser_omp_structured_block (parser, NULL);
15565       substmt = build1 (OMP_SECTION, void_type_node, substmt);
15566       SET_EXPR_LOCATION (substmt, loc);
15567       add_stmt (substmt);
15568     }
15569 
15570   while (1)
15571     {
15572       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15573 	break;
15574       if (c_parser_next_token_is (parser, CPP_EOF))
15575 	break;
15576 
15577       loc = c_parser_peek_token (parser)->location;
15578       if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
15579 	{
15580 	  c_parser_consume_pragma (parser);
15581 	  c_parser_skip_to_pragma_eol (parser);
15582 	  error_suppress = false;
15583 	}
15584       else if (!error_suppress)
15585 	{
15586 	  error_at (loc, "expected %<#pragma omp section%> or %<}%>");
15587 	  error_suppress = true;
15588 	}
15589 
15590       substmt = c_parser_omp_structured_block (parser, NULL);
15591       substmt = build1 (OMP_SECTION, void_type_node, substmt);
15592       SET_EXPR_LOCATION (substmt, loc);
15593       add_stmt (substmt);
15594     }
15595   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
15596 			     "expected %<#pragma omp section%> or %<}%>");
15597 
15598   substmt = pop_stmt_list (stmt);
15599 
15600   stmt = make_node (OMP_SECTIONS);
15601   SET_EXPR_LOCATION (stmt, sections_loc);
15602   TREE_TYPE (stmt) = void_type_node;
15603   OMP_SECTIONS_BODY (stmt) = substmt;
15604 
15605   return add_stmt (stmt);
15606 }
15607 
15608 /* OpenMP 2.5:
15609    # pragma omp sections sections-clause[optseq] newline
15610      sections-scope
15611 
15612    LOC is the location of the #pragma token.
15613 */
15614 
15615 #define OMP_SECTIONS_CLAUSE_MASK				\
15616 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15617 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
15618 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
15619 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
15620 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15621 
15622 static tree
15623 c_parser_omp_sections (location_t loc, c_parser *parser,
15624 		       char *p_name, omp_clause_mask mask, tree *cclauses)
15625 {
15626   tree block, clauses, ret;
15627 
15628   strcat (p_name, " sections");
15629   mask |= OMP_SECTIONS_CLAUSE_MASK;
15630   if (cclauses)
15631     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
15632 
15633   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15634   if (cclauses)
15635     {
15636       omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
15637       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
15638     }
15639 
15640   block = c_begin_compound_stmt (true);
15641   ret = c_parser_omp_sections_scope (loc, parser);
15642   if (ret)
15643     OMP_SECTIONS_CLAUSES (ret) = clauses;
15644   block = c_end_compound_stmt (loc, block, true);
15645   add_stmt (block);
15646 
15647   return ret;
15648 }
15649 
15650 /* OpenMP 2.5:
15651    # pragma omp parallel parallel-clause[optseq] new-line
15652      structured-block
15653    # pragma omp parallel for parallel-for-clause[optseq] new-line
15654      structured-block
15655    # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15656      structured-block
15657 
15658    OpenMP 4.0:
15659    # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15660      structured-block
15661 
15662    LOC is the location of the #pragma token.
15663 */
15664 
15665 #define OMP_PARALLEL_CLAUSE_MASK				\
15666 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
15667 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15668 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
15669 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
15670 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
15671 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN)	\
15672 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
15673 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)	\
15674 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15675 
15676 static tree
15677 c_parser_omp_parallel (location_t loc, c_parser *parser,
15678 		       char *p_name, omp_clause_mask mask, tree *cclauses,
15679 		       bool *if_p)
15680 {
15681   tree stmt, clauses, block;
15682 
15683   strcat (p_name, " parallel");
15684   mask |= OMP_PARALLEL_CLAUSE_MASK;
15685   /* #pragma omp target parallel{, for, for simd} disallow copyin clause.  */
15686   if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0
15687       && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0)
15688     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN);
15689 
15690   if (c_parser_next_token_is_keyword (parser, RID_FOR))
15691     {
15692       tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
15693       if (cclauses == NULL)
15694 	cclauses = cclauses_buf;
15695 
15696       c_parser_consume_token (parser);
15697       if (!flag_openmp)  /* flag_openmp_simd  */
15698 	return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
15699       block = c_begin_omp_parallel ();
15700       tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
15701       stmt
15702 	= c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
15703 				 block);
15704       if (ret == NULL_TREE)
15705 	return ret;
15706       OMP_PARALLEL_COMBINED (stmt) = 1;
15707       return stmt;
15708     }
15709   /* When combined with distribute, parallel has to be followed by for.
15710      #pragma omp target parallel is allowed though.  */
15711   else if (cclauses
15712 	   && (mask & (OMP_CLAUSE_MASK_1
15713 		       << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
15714     {
15715       error_at (loc, "expected %<for%> after %qs", p_name);
15716       c_parser_skip_to_pragma_eol (parser);
15717       return NULL_TREE;
15718     }
15719   else if (!flag_openmp)  /* flag_openmp_simd  */
15720     {
15721       c_parser_skip_to_pragma_eol (parser, false);
15722       return NULL_TREE;
15723     }
15724   else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME))
15725     {
15726       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15727       if (strcmp (p, "sections") == 0)
15728 	{
15729 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
15730 	  if (cclauses == NULL)
15731 	    cclauses = cclauses_buf;
15732 
15733 	  c_parser_consume_token (parser);
15734 	  block = c_begin_omp_parallel ();
15735 	  c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
15736 	  stmt = c_finish_omp_parallel (loc,
15737 					cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
15738 					block);
15739 	  OMP_PARALLEL_COMBINED (stmt) = 1;
15740 	  return stmt;
15741 	}
15742     }
15743 
15744   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15745   if (cclauses)
15746     {
15747       omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses);
15748       clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
15749     }
15750 
15751   block = c_begin_omp_parallel ();
15752   c_parser_statement (parser, if_p);
15753   stmt = c_finish_omp_parallel (loc, clauses, block);
15754 
15755   return stmt;
15756 }
15757 
15758 /* OpenMP 2.5:
15759    # pragma omp single single-clause[optseq] new-line
15760      structured-block
15761 
15762    LOC is the location of the #pragma.
15763 */
15764 
15765 #define OMP_SINGLE_CLAUSE_MASK					\
15766 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15767 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
15768 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE)	\
15769 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15770 
15771 static tree
15772 c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p)
15773 {
15774   tree stmt = make_node (OMP_SINGLE);
15775   SET_EXPR_LOCATION (stmt, loc);
15776   TREE_TYPE (stmt) = void_type_node;
15777 
15778   OMP_SINGLE_CLAUSES (stmt)
15779     = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
15780 				"#pragma omp single");
15781   OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
15782 
15783   return add_stmt (stmt);
15784 }
15785 
15786 /* OpenMP 3.0:
15787    # pragma omp task task-clause[optseq] new-line
15788 
15789    LOC is the location of the #pragma.
15790 */
15791 
15792 #define OMP_TASK_CLAUSE_MASK					\
15793 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
15794 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED)	\
15795 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
15796 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15797 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
15798 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
15799 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
15800 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
15801 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
15802 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15803 
15804 static tree
15805 c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p)
15806 {
15807   tree clauses, block;
15808 
15809   clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
15810 				      "#pragma omp task");
15811 
15812   block = c_begin_omp_task ();
15813   c_parser_statement (parser, if_p);
15814   return c_finish_omp_task (loc, clauses, block);
15815 }
15816 
15817 /* OpenMP 3.0:
15818    # pragma omp taskwait new-line
15819 */
15820 
15821 static void
15822 c_parser_omp_taskwait (c_parser *parser)
15823 {
15824   location_t loc = c_parser_peek_token (parser)->location;
15825   c_parser_consume_pragma (parser);
15826   c_parser_skip_to_pragma_eol (parser);
15827 
15828   c_finish_omp_taskwait (loc);
15829 }
15830 
15831 /* OpenMP 3.1:
15832    # pragma omp taskyield new-line
15833 */
15834 
15835 static void
15836 c_parser_omp_taskyield (c_parser *parser)
15837 {
15838   location_t loc = c_parser_peek_token (parser)->location;
15839   c_parser_consume_pragma (parser);
15840   c_parser_skip_to_pragma_eol (parser);
15841 
15842   c_finish_omp_taskyield (loc);
15843 }
15844 
15845 /* OpenMP 4.0:
15846    # pragma omp taskgroup new-line
15847 */
15848 
15849 static tree
15850 c_parser_omp_taskgroup (c_parser *parser, bool *if_p)
15851 {
15852   location_t loc = c_parser_peek_token (parser)->location;
15853   c_parser_skip_to_pragma_eol (parser);
15854   return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser,
15855 								     if_p));
15856 }
15857 
15858 /* OpenMP 4.0:
15859    # pragma omp cancel cancel-clause[optseq] new-line
15860 
15861    LOC is the location of the #pragma.
15862 */
15863 
15864 #define OMP_CANCEL_CLAUSE_MASK					\
15865 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)	\
15866 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)		\
15867 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
15868 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)	\
15869 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15870 
15871 static void
15872 c_parser_omp_cancel (c_parser *parser)
15873 {
15874   location_t loc = c_parser_peek_token (parser)->location;
15875 
15876   c_parser_consume_pragma (parser);
15877   tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
15878 					   "#pragma omp cancel");
15879 
15880   c_finish_omp_cancel (loc, clauses);
15881 }
15882 
15883 /* OpenMP 4.0:
15884    # pragma omp cancellation point cancelpt-clause[optseq] new-line
15885 
15886    LOC is the location of the #pragma.
15887 */
15888 
15889 #define OMP_CANCELLATION_POINT_CLAUSE_MASK			\
15890 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)	\
15891 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)		\
15892 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
15893 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15894 
15895 static void
15896 c_parser_omp_cancellation_point (c_parser *parser, enum pragma_context context)
15897 {
15898   location_t loc = c_parser_peek_token (parser)->location;
15899   tree clauses;
15900   bool point_seen = false;
15901 
15902   c_parser_consume_pragma (parser);
15903   if (c_parser_next_token_is (parser, CPP_NAME))
15904     {
15905       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15906       if (strcmp (p, "point") == 0)
15907 	{
15908 	  c_parser_consume_token (parser);
15909 	  point_seen = true;
15910 	}
15911     }
15912   if (!point_seen)
15913     {
15914       c_parser_error (parser, "expected %<point%>");
15915       c_parser_skip_to_pragma_eol (parser);
15916       return;
15917     }
15918 
15919   if (context != pragma_compound)
15920     {
15921       if (context == pragma_stmt)
15922 	error_at (loc,
15923 		  "%<#pragma %s%> may only be used in compound statements",
15924 		  "omp cancellation point");
15925       else
15926 	c_parser_error (parser, "expected declaration specifiers");
15927       c_parser_skip_to_pragma_eol (parser, false);
15928       return;
15929     }
15930 
15931   clauses
15932     = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
15933 				"#pragma omp cancellation point");
15934 
15935   c_finish_omp_cancellation_point (loc, clauses);
15936 }
15937 
15938 /* OpenMP 4.0:
15939    #pragma omp distribute distribute-clause[optseq] new-line
15940      for-loop  */
15941 
15942 #define OMP_DISTRIBUTE_CLAUSE_MASK				\
15943 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15944 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
15945 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
15946 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15947 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15948 
15949 static tree
15950 c_parser_omp_distribute (location_t loc, c_parser *parser,
15951 			 char *p_name, omp_clause_mask mask, tree *cclauses,
15952 			 bool *if_p)
15953 {
15954   tree clauses, block, ret;
15955 
15956   strcat (p_name, " distribute");
15957   mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
15958 
15959   if (c_parser_next_token_is (parser, CPP_NAME))
15960     {
15961       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15962       bool simd = false;
15963       bool parallel = false;
15964 
15965       if (strcmp (p, "simd") == 0)
15966 	simd = true;
15967       else
15968 	parallel = strcmp (p, "parallel") == 0;
15969       if (parallel || simd)
15970 	{
15971 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
15972 	  if (cclauses == NULL)
15973 	    cclauses = cclauses_buf;
15974 	  c_parser_consume_token (parser);
15975 	  if (!flag_openmp)  /* flag_openmp_simd  */
15976 	    {
15977 	      if (simd)
15978 		return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
15979 					  if_p);
15980 	      else
15981 		return c_parser_omp_parallel (loc, parser, p_name, mask,
15982 					      cclauses, if_p);
15983 	    }
15984 	  block = c_begin_compound_stmt (true);
15985 	  if (simd)
15986 	    ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
15987 				     if_p);
15988 	  else
15989 	    ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses,
15990 					 if_p);
15991 	  block = c_end_compound_stmt (loc, block, true);
15992 	  if (ret == NULL)
15993 	    return ret;
15994 	  ret = make_node (OMP_DISTRIBUTE);
15995 	  TREE_TYPE (ret) = void_type_node;
15996 	  OMP_FOR_BODY (ret) = block;
15997 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
15998 	  SET_EXPR_LOCATION (ret, loc);
15999 	  add_stmt (ret);
16000 	  return ret;
16001 	}
16002     }
16003   if (!flag_openmp)  /* flag_openmp_simd  */
16004     {
16005       c_parser_skip_to_pragma_eol (parser, false);
16006       return NULL_TREE;
16007     }
16008 
16009   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16010   if (cclauses)
16011     {
16012       omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
16013       clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
16014     }
16015 
16016   block = c_begin_compound_stmt (true);
16017   ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL,
16018 			       if_p);
16019   block = c_end_compound_stmt (loc, block, true);
16020   add_stmt (block);
16021 
16022   return ret;
16023 }
16024 
16025 /* OpenMP 4.0:
16026    # pragma omp teams teams-clause[optseq] new-line
16027      structured-block  */
16028 
16029 #define OMP_TEAMS_CLAUSE_MASK					\
16030 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16031 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16032 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
16033 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
16034 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS)	\
16035 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT)	\
16036 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16037 
16038 static tree
16039 c_parser_omp_teams (location_t loc, c_parser *parser,
16040 		    char *p_name, omp_clause_mask mask, tree *cclauses,
16041 		    bool *if_p)
16042 {
16043   tree clauses, block, ret;
16044 
16045   strcat (p_name, " teams");
16046   mask |= OMP_TEAMS_CLAUSE_MASK;
16047 
16048   if (c_parser_next_token_is (parser, CPP_NAME))
16049     {
16050       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16051       if (strcmp (p, "distribute") == 0)
16052 	{
16053 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16054 	  if (cclauses == NULL)
16055 	    cclauses = cclauses_buf;
16056 
16057 	  c_parser_consume_token (parser);
16058 	  if (!flag_openmp)  /* flag_openmp_simd  */
16059 	    return c_parser_omp_distribute (loc, parser, p_name, mask,
16060 					    cclauses, if_p);
16061 	  block = c_begin_compound_stmt (true);
16062 	  ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses,
16063 					 if_p);
16064 	  block = c_end_compound_stmt (loc, block, true);
16065 	  if (ret == NULL)
16066 	    return ret;
16067 	  clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
16068 	  ret = make_node (OMP_TEAMS);
16069 	  TREE_TYPE (ret) = void_type_node;
16070 	  OMP_TEAMS_CLAUSES (ret) = clauses;
16071 	  OMP_TEAMS_BODY (ret) = block;
16072 	  OMP_TEAMS_COMBINED (ret) = 1;
16073 	  return add_stmt (ret);
16074 	}
16075     }
16076   if (!flag_openmp)  /* flag_openmp_simd  */
16077     {
16078       c_parser_skip_to_pragma_eol (parser, false);
16079       return NULL_TREE;
16080     }
16081 
16082   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16083   if (cclauses)
16084     {
16085       omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
16086       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
16087     }
16088 
16089   tree stmt = make_node (OMP_TEAMS);
16090   TREE_TYPE (stmt) = void_type_node;
16091   OMP_TEAMS_CLAUSES (stmt) = clauses;
16092   OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
16093 
16094   return add_stmt (stmt);
16095 }
16096 
16097 /* OpenMP 4.0:
16098    # pragma omp target data target-data-clause[optseq] new-line
16099      structured-block  */
16100 
16101 #define OMP_TARGET_DATA_CLAUSE_MASK				\
16102 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16103 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
16104 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16105 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16106 
16107 static tree
16108 c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p)
16109 {
16110   tree clauses
16111     = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
16112 				"#pragma omp target data");
16113   int map_seen = 0;
16114   for (tree *pc = &clauses; *pc;)
16115     {
16116       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16117 	switch (OMP_CLAUSE_MAP_KIND (*pc))
16118 	  {
16119 	  case GOMP_MAP_TO:
16120 	  case GOMP_MAP_ALWAYS_TO:
16121 	  case GOMP_MAP_FROM:
16122 	  case GOMP_MAP_ALWAYS_FROM:
16123 	  case GOMP_MAP_TOFROM:
16124 	  case GOMP_MAP_ALWAYS_TOFROM:
16125 	  case GOMP_MAP_ALLOC:
16126 	    map_seen = 3;
16127 	    break;
16128 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
16129 	  case GOMP_MAP_ALWAYS_POINTER:
16130 	    break;
16131 	  default:
16132 	    map_seen |= 1;
16133 	    error_at (OMP_CLAUSE_LOCATION (*pc),
16134 		      "%<#pragma omp target data%> with map-type other "
16135 		      "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16136 		      "on %<map%> clause");
16137 	    *pc = OMP_CLAUSE_CHAIN (*pc);
16138 	    continue;
16139 	  }
16140       pc = &OMP_CLAUSE_CHAIN (*pc);
16141     }
16142 
16143   if (map_seen != 3)
16144     {
16145       if (map_seen == 0)
16146 	error_at (loc,
16147 		  "%<#pragma omp target data%> must contain at least "
16148 		  "one %<map%> clause");
16149       return NULL_TREE;
16150     }
16151 
16152   tree stmt = make_node (OMP_TARGET_DATA);
16153   TREE_TYPE (stmt) = void_type_node;
16154   OMP_TARGET_DATA_CLAUSES (stmt) = clauses;
16155   keep_next_level ();
16156   tree block = c_begin_compound_stmt (true);
16157   add_stmt (c_parser_omp_structured_block (parser, if_p));
16158   OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
16159 
16160   SET_EXPR_LOCATION (stmt, loc);
16161   return add_stmt (stmt);
16162 }
16163 
16164 /* OpenMP 4.0:
16165    # pragma omp target update target-update-clause[optseq] new-line */
16166 
16167 #define OMP_TARGET_UPDATE_CLAUSE_MASK				\
16168 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM)		\
16169 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)		\
16170 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16171 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16172 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16173 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16174 
16175 static bool
16176 c_parser_omp_target_update (location_t loc, c_parser *parser,
16177 			    enum pragma_context context)
16178 {
16179   if (context == pragma_stmt)
16180     {
16181       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16182 		"omp target update");
16183       c_parser_skip_to_pragma_eol (parser, false);
16184       return false;
16185     }
16186 
16187   tree clauses
16188     = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
16189 				"#pragma omp target update");
16190   if (omp_find_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
16191       && omp_find_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
16192     {
16193       error_at (loc,
16194 		"%<#pragma omp target update%> must contain at least one "
16195 		"%<from%> or %<to%> clauses");
16196       return false;
16197     }
16198 
16199   tree stmt = make_node (OMP_TARGET_UPDATE);
16200   TREE_TYPE (stmt) = void_type_node;
16201   OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
16202   SET_EXPR_LOCATION (stmt, loc);
16203   add_stmt (stmt);
16204   return false;
16205 }
16206 
16207 /* OpenMP 4.5:
16208    # pragma omp target enter data target-data-clause[optseq] new-line  */
16209 
16210 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK			\
16211 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16212 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
16213 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16214 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16215 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16216 
16217 static tree
16218 c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
16219 				enum pragma_context context)
16220 {
16221   bool data_seen = false;
16222   if (c_parser_next_token_is (parser, CPP_NAME))
16223     {
16224       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16225       if (strcmp (p, "data") == 0)
16226 	{
16227 	  c_parser_consume_token (parser);
16228 	  data_seen = true;
16229 	}
16230     }
16231   if (!data_seen)
16232     {
16233       c_parser_error (parser, "expected %<data%>");
16234       c_parser_skip_to_pragma_eol (parser);
16235       return NULL_TREE;
16236     }
16237 
16238   if (context == pragma_stmt)
16239     {
16240       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16241 		"omp target enter data");
16242       c_parser_skip_to_pragma_eol (parser, false);
16243       return NULL_TREE;
16244     }
16245 
16246   tree clauses
16247     = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK,
16248 				"#pragma omp target enter data");
16249   int map_seen = 0;
16250   for (tree *pc = &clauses; *pc;)
16251     {
16252       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16253 	switch (OMP_CLAUSE_MAP_KIND (*pc))
16254 	  {
16255 	  case GOMP_MAP_TO:
16256 	  case GOMP_MAP_ALWAYS_TO:
16257 	  case GOMP_MAP_ALLOC:
16258 	    map_seen = 3;
16259 	    break;
16260 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
16261 	  case GOMP_MAP_ALWAYS_POINTER:
16262 	    break;
16263 	  default:
16264 	    map_seen |= 1;
16265 	    error_at (OMP_CLAUSE_LOCATION (*pc),
16266 		      "%<#pragma omp target enter data%> with map-type other "
16267 		      "than %<to%> or %<alloc%> on %<map%> clause");
16268 	    *pc = OMP_CLAUSE_CHAIN (*pc);
16269 	    continue;
16270 	  }
16271       pc = &OMP_CLAUSE_CHAIN (*pc);
16272     }
16273 
16274   if (map_seen != 3)
16275     {
16276       if (map_seen == 0)
16277 	error_at (loc,
16278 		  "%<#pragma omp target enter data%> must contain at least "
16279 		  "one %<map%> clause");
16280       return NULL_TREE;
16281     }
16282 
16283   tree stmt = make_node (OMP_TARGET_ENTER_DATA);
16284   TREE_TYPE (stmt) = void_type_node;
16285   OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses;
16286   SET_EXPR_LOCATION (stmt, loc);
16287   add_stmt (stmt);
16288   return stmt;
16289 }
16290 
16291 /* OpenMP 4.5:
16292    # pragma omp target exit data target-data-clause[optseq] new-line  */
16293 
16294 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK			\
16295 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16296 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
16297 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16298 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16299 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16300 
16301 static tree
16302 c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
16303 			       enum pragma_context context)
16304 {
16305   bool data_seen = false;
16306   if (c_parser_next_token_is (parser, CPP_NAME))
16307     {
16308       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16309       if (strcmp (p, "data") == 0)
16310 	{
16311 	  c_parser_consume_token (parser);
16312 	  data_seen = true;
16313 	}
16314     }
16315   if (!data_seen)
16316     {
16317       c_parser_error (parser, "expected %<data%>");
16318       c_parser_skip_to_pragma_eol (parser);
16319       return NULL_TREE;
16320     }
16321 
16322   if (context == pragma_stmt)
16323     {
16324       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16325 		"omp target exit data");
16326       c_parser_skip_to_pragma_eol (parser, false);
16327       return NULL_TREE;
16328     }
16329 
16330   tree clauses
16331     = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK,
16332 				"#pragma omp target exit data");
16333 
16334   int map_seen = 0;
16335   for (tree *pc = &clauses; *pc;)
16336     {
16337       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16338 	switch (OMP_CLAUSE_MAP_KIND (*pc))
16339 	  {
16340 	  case GOMP_MAP_FROM:
16341 	  case GOMP_MAP_ALWAYS_FROM:
16342 	  case GOMP_MAP_RELEASE:
16343 	  case GOMP_MAP_DELETE:
16344 	    map_seen = 3;
16345 	    break;
16346 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
16347 	  case GOMP_MAP_ALWAYS_POINTER:
16348 	    break;
16349 	  default:
16350 	    map_seen |= 1;
16351 	    error_at (OMP_CLAUSE_LOCATION (*pc),
16352 		      "%<#pragma omp target exit data%> with map-type other "
16353 		      "than %<from%>, %<release%> or %<delete%> on %<map%>"
16354 		      " clause");
16355 	    *pc = OMP_CLAUSE_CHAIN (*pc);
16356 	    continue;
16357 	  }
16358       pc = &OMP_CLAUSE_CHAIN (*pc);
16359     }
16360 
16361   if (map_seen != 3)
16362     {
16363       if (map_seen == 0)
16364 	error_at (loc,
16365 		  "%<#pragma omp target exit data%> must contain at least one "
16366 		  "%<map%> clause");
16367       return NULL_TREE;
16368     }
16369 
16370   tree stmt = make_node (OMP_TARGET_EXIT_DATA);
16371   TREE_TYPE (stmt) = void_type_node;
16372   OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses;
16373   SET_EXPR_LOCATION (stmt, loc);
16374   add_stmt (stmt);
16375   return stmt;
16376 }
16377 
16378 /* OpenMP 4.0:
16379    # pragma omp target target-clause[optseq] new-line
16380      structured-block  */
16381 
16382 #define OMP_TARGET_CLAUSE_MASK					\
16383 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16384 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
16385 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16386 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16387 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)	\
16388 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16389 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16390 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP)	\
16391 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16392 
16393 static bool
16394 c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p)
16395 {
16396   location_t loc = c_parser_peek_token (parser)->location;
16397   c_parser_consume_pragma (parser);
16398   tree *pc = NULL, stmt, block;
16399 
16400   if (context != pragma_stmt && context != pragma_compound)
16401     {
16402       c_parser_error (parser, "expected declaration specifiers");
16403       c_parser_skip_to_pragma_eol (parser);
16404       return false;
16405     }
16406 
16407   if (c_parser_next_token_is (parser, CPP_NAME))
16408     {
16409       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16410       enum tree_code ccode = ERROR_MARK;
16411 
16412       if (strcmp (p, "teams") == 0)
16413 	ccode = OMP_TEAMS;
16414       else if (strcmp (p, "parallel") == 0)
16415 	ccode = OMP_PARALLEL;
16416       else if (strcmp (p, "simd") == 0)
16417 	ccode = OMP_SIMD;
16418       if (ccode != ERROR_MARK)
16419 	{
16420 	  tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
16421 	  char p_name[sizeof ("#pragma omp target teams distribute "
16422 			      "parallel for simd")];
16423 
16424 	  c_parser_consume_token (parser);
16425 	  strcpy (p_name, "#pragma omp target");
16426 	  if (!flag_openmp)  /* flag_openmp_simd  */
16427 	    {
16428 	      tree stmt;
16429 	      switch (ccode)
16430 		{
16431 		case OMP_TEAMS:
16432 		  stmt = c_parser_omp_teams (loc, parser, p_name,
16433 					     OMP_TARGET_CLAUSE_MASK,
16434 					     cclauses, if_p);
16435 		  break;
16436 		case OMP_PARALLEL:
16437 		  stmt = c_parser_omp_parallel (loc, parser, p_name,
16438 						OMP_TARGET_CLAUSE_MASK,
16439 						cclauses, if_p);
16440 		  break;
16441 		case OMP_SIMD:
16442 		  stmt = c_parser_omp_simd (loc, parser, p_name,
16443 					    OMP_TARGET_CLAUSE_MASK,
16444 					    cclauses, if_p);
16445 		  break;
16446 		default:
16447 		  gcc_unreachable ();
16448 		}
16449 	      return stmt != NULL_TREE;
16450 	    }
16451 	  keep_next_level ();
16452 	  tree block = c_begin_compound_stmt (true), ret;
16453 	  switch (ccode)
16454 	    {
16455 	    case OMP_TEAMS:
16456 	      ret = c_parser_omp_teams (loc, parser, p_name,
16457 					OMP_TARGET_CLAUSE_MASK, cclauses,
16458 					if_p);
16459 	      break;
16460 	    case OMP_PARALLEL:
16461 	      ret = c_parser_omp_parallel (loc, parser, p_name,
16462 					   OMP_TARGET_CLAUSE_MASK, cclauses,
16463 					   if_p);
16464 	      break;
16465 	    case OMP_SIMD:
16466 	      ret = c_parser_omp_simd (loc, parser, p_name,
16467 				       OMP_TARGET_CLAUSE_MASK, cclauses,
16468 				       if_p);
16469 	      break;
16470 	    default:
16471 	      gcc_unreachable ();
16472 	    }
16473 	  block = c_end_compound_stmt (loc, block, true);
16474 	  if (ret == NULL_TREE)
16475 	    return false;
16476 	  if (ccode == OMP_TEAMS)
16477 	    {
16478 	      /* For combined target teams, ensure the num_teams and
16479 		 thread_limit clause expressions are evaluated on the host,
16480 		 before entering the target construct.  */
16481 	      tree c;
16482 	      for (c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
16483 		   c; c = OMP_CLAUSE_CHAIN (c))
16484 		if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
16485 		     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT)
16486 		    && TREE_CODE (OMP_CLAUSE_OPERAND (c, 0)) != INTEGER_CST)
16487 		  {
16488 		    tree expr = OMP_CLAUSE_OPERAND (c, 0);
16489 		    tree tmp = create_tmp_var_raw (TREE_TYPE (expr));
16490 		    expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp,
16491 				   expr, NULL_TREE, NULL_TREE);
16492 		    add_stmt (expr);
16493 		    OMP_CLAUSE_OPERAND (c, 0) = expr;
16494 		    tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c),
16495 						OMP_CLAUSE_FIRSTPRIVATE);
16496 		    OMP_CLAUSE_DECL (tc) = tmp;
16497 		    OMP_CLAUSE_CHAIN (tc)
16498 		      = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
16499 		    cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc;
16500 		  }
16501 	    }
16502 	  tree stmt = make_node (OMP_TARGET);
16503 	  TREE_TYPE (stmt) = void_type_node;
16504 	  OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
16505 	  OMP_TARGET_BODY (stmt) = block;
16506 	  OMP_TARGET_COMBINED (stmt) = 1;
16507 	  add_stmt (stmt);
16508 	  pc = &OMP_TARGET_CLAUSES (stmt);
16509 	  goto check_clauses;
16510 	}
16511       else if (!flag_openmp)  /* flag_openmp_simd  */
16512 	{
16513 	  c_parser_skip_to_pragma_eol (parser, false);
16514 	  return false;
16515 	}
16516       else if (strcmp (p, "data") == 0)
16517 	{
16518 	  c_parser_consume_token (parser);
16519 	  c_parser_omp_target_data (loc, parser, if_p);
16520 	  return true;
16521 	}
16522       else if (strcmp (p, "enter") == 0)
16523 	{
16524 	  c_parser_consume_token (parser);
16525 	  c_parser_omp_target_enter_data (loc, parser, context);
16526 	  return false;
16527 	}
16528       else if (strcmp (p, "exit") == 0)
16529 	{
16530 	  c_parser_consume_token (parser);
16531 	  c_parser_omp_target_exit_data (loc, parser, context);
16532 	  return false;
16533 	}
16534       else if (strcmp (p, "update") == 0)
16535 	{
16536 	  c_parser_consume_token (parser);
16537 	  return c_parser_omp_target_update (loc, parser, context);
16538 	}
16539     }
16540   if (!flag_openmp) /* flag_openmp_simd  */
16541     {
16542       c_parser_skip_to_pragma_eol (parser, false);
16543       return false;
16544     }
16545 
16546   stmt = make_node (OMP_TARGET);
16547   TREE_TYPE (stmt) = void_type_node;
16548 
16549   OMP_TARGET_CLAUSES (stmt)
16550     = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
16551 				"#pragma omp target");
16552   pc = &OMP_TARGET_CLAUSES (stmt);
16553   keep_next_level ();
16554   block = c_begin_compound_stmt (true);
16555   add_stmt (c_parser_omp_structured_block (parser, if_p));
16556   OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
16557 
16558   SET_EXPR_LOCATION (stmt, loc);
16559   add_stmt (stmt);
16560 
16561 check_clauses:
16562   while (*pc)
16563     {
16564       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16565 	switch (OMP_CLAUSE_MAP_KIND (*pc))
16566 	  {
16567 	  case GOMP_MAP_TO:
16568 	  case GOMP_MAP_ALWAYS_TO:
16569 	  case GOMP_MAP_FROM:
16570 	  case GOMP_MAP_ALWAYS_FROM:
16571 	  case GOMP_MAP_TOFROM:
16572 	  case GOMP_MAP_ALWAYS_TOFROM:
16573 	  case GOMP_MAP_ALLOC:
16574 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
16575 	  case GOMP_MAP_ALWAYS_POINTER:
16576 	    break;
16577 	  default:
16578 	    error_at (OMP_CLAUSE_LOCATION (*pc),
16579 		      "%<#pragma omp target%> with map-type other "
16580 		      "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16581 		      "on %<map%> clause");
16582 	    *pc = OMP_CLAUSE_CHAIN (*pc);
16583 	    continue;
16584 	  }
16585       pc = &OMP_CLAUSE_CHAIN (*pc);
16586     }
16587   return true;
16588 }
16589 
16590 /* OpenMP 4.0:
16591    # pragma omp declare simd declare-simd-clauses[optseq] new-line  */
16592 
16593 #define OMP_DECLARE_SIMD_CLAUSE_MASK				\
16594 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN)	\
16595 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
16596 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)	\
16597 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)	\
16598 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH)	\
16599 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16600 
16601 static void
16602 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
16603 {
16604   auto_vec<c_token> clauses;
16605   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
16606     {
16607       c_token *token = c_parser_peek_token (parser);
16608       if (token->type == CPP_EOF)
16609 	{
16610 	  c_parser_skip_to_pragma_eol (parser);
16611 	  return;
16612 	}
16613       clauses.safe_push (*token);
16614       c_parser_consume_token (parser);
16615     }
16616   clauses.safe_push (*c_parser_peek_token (parser));
16617   c_parser_skip_to_pragma_eol (parser);
16618 
16619   while (c_parser_next_token_is (parser, CPP_PRAGMA))
16620     {
16621       if (c_parser_peek_token (parser)->pragma_kind
16622 	  != PRAGMA_OMP_DECLARE
16623 	  || c_parser_peek_2nd_token (parser)->type != CPP_NAME
16624 	  || strcmp (IDENTIFIER_POINTER
16625 				(c_parser_peek_2nd_token (parser)->value),
16626 		     "simd") != 0)
16627 	{
16628 	  c_parser_error (parser,
16629 			  "%<#pragma omp declare simd%> must be followed by "
16630 			  "function declaration or definition or another "
16631 			  "%<#pragma omp declare simd%>");
16632 	  return;
16633 	}
16634       c_parser_consume_pragma (parser);
16635       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
16636 	{
16637 	  c_token *token = c_parser_peek_token (parser);
16638 	  if (token->type == CPP_EOF)
16639 	    {
16640 	      c_parser_skip_to_pragma_eol (parser);
16641 	      return;
16642 	    }
16643 	  clauses.safe_push (*token);
16644 	  c_parser_consume_token (parser);
16645 	}
16646       clauses.safe_push (*c_parser_peek_token (parser));
16647       c_parser_skip_to_pragma_eol (parser);
16648     }
16649 
16650   /* Make sure nothing tries to read past the end of the tokens.  */
16651   c_token eof_token;
16652   memset (&eof_token, 0, sizeof (eof_token));
16653   eof_token.type = CPP_EOF;
16654   clauses.safe_push (eof_token);
16655   clauses.safe_push (eof_token);
16656 
16657   switch (context)
16658     {
16659     case pragma_external:
16660       if (c_parser_next_token_is (parser, CPP_KEYWORD)
16661 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
16662 	{
16663 	  int ext = disable_extension_diagnostics ();
16664 	  do
16665 	    c_parser_consume_token (parser);
16666 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
16667 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
16668 	  c_parser_declaration_or_fndef (parser, true, true, true, false, true,
16669 					 NULL, clauses);
16670 	  restore_extension_diagnostics (ext);
16671 	}
16672       else
16673 	c_parser_declaration_or_fndef (parser, true, true, true, false, true,
16674 				       NULL, clauses);
16675       break;
16676     case pragma_struct:
16677     case pragma_param:
16678       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
16679 			      "function declaration or definition");
16680       break;
16681     case pragma_compound:
16682     case pragma_stmt:
16683       if (c_parser_next_token_is (parser, CPP_KEYWORD)
16684 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
16685 	{
16686 	  int ext = disable_extension_diagnostics ();
16687 	  do
16688 	    c_parser_consume_token (parser);
16689 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
16690 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
16691 	  if (c_parser_next_tokens_start_declaration (parser))
16692 	    {
16693 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
16694 					     true, NULL, clauses);
16695 	      restore_extension_diagnostics (ext);
16696 	      break;
16697 	    }
16698 	  restore_extension_diagnostics (ext);
16699 	}
16700       else if (c_parser_next_tokens_start_declaration (parser))
16701 	{
16702 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
16703 					 NULL, clauses);
16704 	  break;
16705 	}
16706       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
16707 			      "function declaration or definition");
16708       break;
16709     default:
16710       gcc_unreachable ();
16711     }
16712 }
16713 
16714 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16715    and put that into "omp declare simd" attribute.  */
16716 
16717 static void
16718 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
16719 			   vec<c_token> clauses)
16720 {
16721   if (flag_cilkplus
16722       && (clauses.exists ()
16723 	  || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl)))
16724       && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
16725     {
16726       error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16727 	     "used in the same function marked as a Cilk Plus SIMD-enabled "
16728 	     "function");
16729       vec_free (parser->cilk_simd_fn_tokens);
16730       return;
16731     }
16732 
16733   /* Normally first token is CPP_NAME "simd".  CPP_EOF there indicates
16734      error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16735      has already processed the tokens.  */
16736   if (clauses.exists () && clauses[0].type == CPP_EOF)
16737     return;
16738   if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
16739     {
16740       error ("%<#pragma omp declare simd%> not immediately followed by "
16741 	     "a function declaration or definition");
16742       clauses[0].type = CPP_EOF;
16743       return;
16744     }
16745   if (clauses.exists () && clauses[0].type != CPP_NAME)
16746     {
16747       error_at (DECL_SOURCE_LOCATION (fndecl),
16748 		"%<#pragma omp declare simd%> not immediately followed by "
16749 		"a single function declaration or definition");
16750       clauses[0].type = CPP_EOF;
16751       return;
16752     }
16753 
16754   if (parms == NULL_TREE)
16755     parms = DECL_ARGUMENTS (fndecl);
16756 
16757   unsigned int tokens_avail = parser->tokens_avail;
16758   gcc_assert (parser->tokens == &parser->tokens_buf[0]);
16759   bool is_cilkplus_cilk_simd_fn = false;
16760 
16761   if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
16762     {
16763       parser->tokens = parser->cilk_simd_fn_tokens->address ();
16764       parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens);
16765       is_cilkplus_cilk_simd_fn = true;
16766 
16767       if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl)) != NULL)
16768 	{
16769 	  error_at (DECL_SOURCE_LOCATION (fndecl),
16770 		    "%<__simd__%> attribute cannot be used in the same "
16771 		    "function marked as a Cilk Plus SIMD-enabled function");
16772 	  vec_free (parser->cilk_simd_fn_tokens);
16773 	  return;
16774 	}
16775 
16776     }
16777   else
16778     {
16779       parser->tokens = clauses.address ();
16780       parser->tokens_avail = clauses.length ();
16781     }
16782 
16783   /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end.  */
16784   while (parser->tokens_avail > 3)
16785     {
16786       c_token *token = c_parser_peek_token (parser);
16787       if (!is_cilkplus_cilk_simd_fn)
16788 	gcc_assert (token->type == CPP_NAME
16789 		    && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
16790       else
16791 	gcc_assert (token->type == CPP_NAME
16792 		    && is_cilkplus_vector_p (token->value));
16793       c_parser_consume_token (parser);
16794       parser->in_pragma = true;
16795 
16796       tree c = NULL_TREE;
16797       if (is_cilkplus_cilk_simd_fn)
16798 	c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
16799 				      "SIMD-enabled functions attribute");
16800       else
16801 	c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
16802 				      "#pragma omp declare simd");
16803       c = c_omp_declare_simd_clauses_to_numbers (parms, c);
16804       if (c != NULL_TREE)
16805 	c = tree_cons (NULL_TREE, c, NULL_TREE);
16806       if (is_cilkplus_cilk_simd_fn)
16807 	{
16808 	  tree k = build_tree_list (get_identifier ("cilk simd function"),
16809 				    NULL_TREE);
16810 	  TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
16811 	  DECL_ATTRIBUTES (fndecl) = k;
16812 	}
16813       c = build_tree_list (get_identifier ("omp declare simd"), c);
16814       TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
16815       DECL_ATTRIBUTES (fndecl) = c;
16816     }
16817 
16818   parser->tokens = &parser->tokens_buf[0];
16819   parser->tokens_avail = tokens_avail;
16820   if (clauses.exists ())
16821     clauses[0].type = CPP_PRAGMA;
16822 
16823   if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens))
16824     vec_free (parser->cilk_simd_fn_tokens);
16825 }
16826 
16827 
16828 /* OpenMP 4.0:
16829    # pragma omp declare target new-line
16830    declarations and definitions
16831    # pragma omp end declare target new-line
16832 
16833    OpenMP 4.5:
16834    # pragma omp declare target ( extended-list ) new-line
16835 
16836    # pragma omp declare target declare-target-clauses[seq] new-line  */
16837 
16838 #define OMP_DECLARE_TARGET_CLAUSE_MASK				\
16839 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)		\
16840 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16841 
16842 static void
16843 c_parser_omp_declare_target (c_parser *parser)
16844 {
16845   location_t loc = c_parser_peek_token (parser)->location;
16846   tree clauses = NULL_TREE;
16847   if (c_parser_next_token_is (parser, CPP_NAME))
16848     clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK,
16849 					"#pragma omp declare target");
16850   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
16851     {
16852       clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
16853 					      clauses);
16854       clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
16855       c_parser_skip_to_pragma_eol (parser);
16856     }
16857   else
16858     {
16859       c_parser_skip_to_pragma_eol (parser);
16860       current_omp_declare_target_attribute++;
16861       return;
16862     }
16863   if (current_omp_declare_target_attribute)
16864     error_at (loc, "%<#pragma omp declare target%> with clauses in between "
16865 		   "%<#pragma omp declare target%> without clauses and "
16866 		   "%<#pragma omp end declare target%>");
16867   for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
16868     {
16869       tree t = OMP_CLAUSE_DECL (c), id;
16870       tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
16871       tree at2 = lookup_attribute ("omp declare target link",
16872 				   DECL_ATTRIBUTES (t));
16873       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
16874 	{
16875 	  id = get_identifier ("omp declare target link");
16876 	  std::swap (at1, at2);
16877 	}
16878       else
16879 	id = get_identifier ("omp declare target");
16880       if (at2)
16881 	{
16882 	  error_at (OMP_CLAUSE_LOCATION (c),
16883 		    "%qD specified both in declare target %<link%> and %<to%>"
16884 		    " clauses", t);
16885 	  continue;
16886 	}
16887       if (!at1)
16888 	{
16889 	  DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
16890 	  if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
16891 	    continue;
16892 
16893 	  symtab_node *node = symtab_node::get (t);
16894 	  if (node != NULL)
16895 	    {
16896 	      node->offloadable = 1;
16897 	      if (ENABLE_OFFLOADING)
16898 		{
16899 		  g->have_offload = true;
16900 		  if (is_a <varpool_node *> (node))
16901 		    vec_safe_push (offload_vars, t);
16902 		}
16903 	    }
16904 	}
16905     }
16906 }
16907 
16908 static void
16909 c_parser_omp_end_declare_target (c_parser *parser)
16910 {
16911   location_t loc = c_parser_peek_token (parser)->location;
16912   c_parser_consume_pragma (parser);
16913   if (c_parser_next_token_is (parser, CPP_NAME)
16914       && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
16915 		 "declare") == 0)
16916     {
16917       c_parser_consume_token (parser);
16918       if (c_parser_next_token_is (parser, CPP_NAME)
16919 	  && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
16920 		     "target") == 0)
16921 	c_parser_consume_token (parser);
16922       else
16923 	{
16924 	  c_parser_error (parser, "expected %<target%>");
16925 	  c_parser_skip_to_pragma_eol (parser);
16926 	  return;
16927 	}
16928     }
16929   else
16930     {
16931       c_parser_error (parser, "expected %<declare%>");
16932       c_parser_skip_to_pragma_eol (parser);
16933       return;
16934     }
16935   c_parser_skip_to_pragma_eol (parser);
16936   if (!current_omp_declare_target_attribute)
16937     error_at (loc, "%<#pragma omp end declare target%> without corresponding "
16938 		   "%<#pragma omp declare target%>");
16939   else
16940     current_omp_declare_target_attribute--;
16941 }
16942 
16943 
16944 /* OpenMP 4.0
16945    #pragma omp declare reduction (reduction-id : typename-list : expression) \
16946       initializer-clause[opt] new-line
16947 
16948    initializer-clause:
16949       initializer (omp_priv = initializer)
16950       initializer (function-name (argument-list))  */
16951 
16952 static void
16953 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
16954 {
16955   unsigned int tokens_avail = 0, i;
16956   vec<tree> types = vNULL;
16957   vec<c_token> clauses = vNULL;
16958   enum tree_code reduc_code = ERROR_MARK;
16959   tree reduc_id = NULL_TREE;
16960   tree type;
16961   location_t rloc = c_parser_peek_token (parser)->location;
16962 
16963   if (context == pragma_struct || context == pragma_param)
16964     {
16965       error ("%<#pragma omp declare reduction%> not at file or block scope");
16966       goto fail;
16967     }
16968 
16969   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
16970     goto fail;
16971 
16972   switch (c_parser_peek_token (parser)->type)
16973     {
16974     case CPP_PLUS:
16975       reduc_code = PLUS_EXPR;
16976       break;
16977     case CPP_MULT:
16978       reduc_code = MULT_EXPR;
16979       break;
16980     case CPP_MINUS:
16981       reduc_code = MINUS_EXPR;
16982       break;
16983     case CPP_AND:
16984       reduc_code = BIT_AND_EXPR;
16985       break;
16986     case CPP_XOR:
16987       reduc_code = BIT_XOR_EXPR;
16988       break;
16989     case CPP_OR:
16990       reduc_code = BIT_IOR_EXPR;
16991       break;
16992     case CPP_AND_AND:
16993       reduc_code = TRUTH_ANDIF_EXPR;
16994       break;
16995     case CPP_OR_OR:
16996       reduc_code = TRUTH_ORIF_EXPR;
16997       break;
16998     case CPP_NAME:
16999       const char *p;
17000       p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17001       if (strcmp (p, "min") == 0)
17002 	{
17003 	  reduc_code = MIN_EXPR;
17004 	  break;
17005 	}
17006       if (strcmp (p, "max") == 0)
17007 	{
17008 	  reduc_code = MAX_EXPR;
17009 	  break;
17010 	}
17011       reduc_id = c_parser_peek_token (parser)->value;
17012       break;
17013     default:
17014       c_parser_error (parser,
17015 		      "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17016 		      "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17017       goto fail;
17018     }
17019 
17020   tree orig_reduc_id, reduc_decl;
17021   orig_reduc_id = reduc_id;
17022   reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
17023   reduc_decl = c_omp_reduction_decl (reduc_id);
17024   c_parser_consume_token (parser);
17025 
17026   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
17027     goto fail;
17028 
17029   while (true)
17030     {
17031       location_t loc = c_parser_peek_token (parser)->location;
17032       struct c_type_name *ctype = c_parser_type_name (parser);
17033       if (ctype != NULL)
17034 	{
17035 	  type = groktypename (ctype, NULL, NULL);
17036 	  if (type == error_mark_node)
17037 	    ;
17038 	  else if ((INTEGRAL_TYPE_P (type)
17039 		    || TREE_CODE (type) == REAL_TYPE
17040 		    || TREE_CODE (type) == COMPLEX_TYPE)
17041 		   && orig_reduc_id == NULL_TREE)
17042 	    error_at (loc, "predeclared arithmetic type in "
17043 			   "%<#pragma omp declare reduction%>");
17044 	  else if (TREE_CODE (type) == FUNCTION_TYPE
17045 		   || TREE_CODE (type) == ARRAY_TYPE)
17046 	    error_at (loc, "function or array type in "
17047 		      "%<#pragma omp declare reduction%>");
17048 	  else if (TYPE_ATOMIC (type))
17049 	    error_at (loc, "%<_Atomic%> qualified type in "
17050 			   "%<#pragma omp declare reduction%>");
17051 	  else if (TYPE_QUALS_NO_ADDR_SPACE (type))
17052 	    error_at (loc, "const, volatile or restrict qualified type in "
17053 			   "%<#pragma omp declare reduction%>");
17054 	  else
17055 	    {
17056 	      tree t;
17057 	      for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
17058 		if (comptypes (TREE_PURPOSE (t), type))
17059 		  {
17060 		    error_at (loc, "redeclaration of %qs "
17061 				   "%<#pragma omp declare reduction%> for "
17062 				   "type %qT",
17063 				   IDENTIFIER_POINTER (reduc_id)
17064 				   + sizeof ("omp declare reduction ") - 1,
17065 				   type);
17066 		    location_t ploc
17067 		      = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
17068 							    0));
17069 		    error_at (ploc, "previous %<#pragma omp declare "
17070 				    "reduction%>");
17071 		    break;
17072 		  }
17073 	      if (t == NULL_TREE)
17074 		types.safe_push (type);
17075 	    }
17076 	  if (c_parser_next_token_is (parser, CPP_COMMA))
17077 	    c_parser_consume_token (parser);
17078 	  else
17079 	    break;
17080 	}
17081       else
17082 	break;
17083     }
17084 
17085   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
17086       || types.is_empty ())
17087     {
17088      fail:
17089       clauses.release ();
17090       types.release ();
17091       while (true)
17092 	{
17093 	  c_token *token = c_parser_peek_token (parser);
17094 	  if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
17095 	    break;
17096 	  c_parser_consume_token (parser);
17097 	}
17098       c_parser_skip_to_pragma_eol (parser);
17099       return;
17100     }
17101 
17102   if (types.length () > 1)
17103     {
17104       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17105 	{
17106 	  c_token *token = c_parser_peek_token (parser);
17107 	  if (token->type == CPP_EOF)
17108 	    goto fail;
17109 	  clauses.safe_push (*token);
17110 	  c_parser_consume_token (parser);
17111 	}
17112       clauses.safe_push (*c_parser_peek_token (parser));
17113       c_parser_skip_to_pragma_eol (parser);
17114 
17115       /* Make sure nothing tries to read past the end of the tokens.  */
17116       c_token eof_token;
17117       memset (&eof_token, 0, sizeof (eof_token));
17118       eof_token.type = CPP_EOF;
17119       clauses.safe_push (eof_token);
17120       clauses.safe_push (eof_token);
17121     }
17122 
17123   int errs = errorcount;
17124   FOR_EACH_VEC_ELT (types, i, type)
17125     {
17126       tokens_avail = parser->tokens_avail;
17127       gcc_assert (parser->tokens == &parser->tokens_buf[0]);
17128       if (!clauses.is_empty ())
17129 	{
17130 	  parser->tokens = clauses.address ();
17131 	  parser->tokens_avail = clauses.length ();
17132 	  parser->in_pragma = true;
17133 	}
17134 
17135       bool nested = current_function_decl != NULL_TREE;
17136       if (nested)
17137 	c_push_function_context ();
17138       tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
17139 				reduc_id, default_function_type);
17140       current_function_decl = fndecl;
17141       allocate_struct_function (fndecl, true);
17142       push_scope ();
17143       tree stmt = push_stmt_list ();
17144       /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17145 	 warn about these.  */
17146       tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
17147 				 get_identifier ("omp_out"), type);
17148       DECL_ARTIFICIAL (omp_out) = 1;
17149       DECL_CONTEXT (omp_out) = fndecl;
17150       pushdecl (omp_out);
17151       tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
17152 				get_identifier ("omp_in"), type);
17153       DECL_ARTIFICIAL (omp_in) = 1;
17154       DECL_CONTEXT (omp_in) = fndecl;
17155       pushdecl (omp_in);
17156       struct c_expr combiner = c_parser_expression (parser);
17157       struct c_expr initializer;
17158       tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
17159       bool bad = false;
17160       initializer.value = error_mark_node;
17161       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
17162 	bad = true;
17163       else if (c_parser_next_token_is (parser, CPP_NAME)
17164 	       && strcmp (IDENTIFIER_POINTER
17165 				(c_parser_peek_token (parser)->value),
17166 			  "initializer") == 0)
17167 	{
17168 	  c_parser_consume_token (parser);
17169 	  pop_scope ();
17170 	  push_scope ();
17171 	  omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
17172 				 get_identifier ("omp_priv"), type);
17173 	  DECL_ARTIFICIAL (omp_priv) = 1;
17174 	  DECL_INITIAL (omp_priv) = error_mark_node;
17175 	  DECL_CONTEXT (omp_priv) = fndecl;
17176 	  pushdecl (omp_priv);
17177 	  omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
17178 				 get_identifier ("omp_orig"), type);
17179 	  DECL_ARTIFICIAL (omp_orig) = 1;
17180 	  DECL_CONTEXT (omp_orig) = fndecl;
17181 	  pushdecl (omp_orig);
17182 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17183 	    bad = true;
17184 	  else if (!c_parser_next_token_is (parser, CPP_NAME))
17185 	    {
17186 	      c_parser_error (parser, "expected %<omp_priv%> or "
17187 				      "function-name");
17188 	      bad = true;
17189 	    }
17190 	  else if (strcmp (IDENTIFIER_POINTER
17191 				(c_parser_peek_token (parser)->value),
17192 			   "omp_priv") != 0)
17193 	    {
17194 	      if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
17195 		  || c_parser_peek_token (parser)->id_kind != C_ID_ID)
17196 		{
17197 		  c_parser_error (parser, "expected function-name %<(%>");
17198 		  bad = true;
17199 		}
17200 	      else
17201 		initializer = c_parser_postfix_expression (parser);
17202 	      if (initializer.value
17203 		  && TREE_CODE (initializer.value) == CALL_EXPR)
17204 		{
17205 		  int j;
17206 		  tree c = initializer.value;
17207 		  for (j = 0; j < call_expr_nargs (c); j++)
17208 		    {
17209 		      tree a = CALL_EXPR_ARG (c, j);
17210 		      STRIP_NOPS (a);
17211 		      if (TREE_CODE (a) == ADDR_EXPR
17212 			  && TREE_OPERAND (a, 0) == omp_priv)
17213 			break;
17214 		    }
17215 		  if (j == call_expr_nargs (c))
17216 		    error ("one of the initializer call arguments should be "
17217 			   "%<&omp_priv%>");
17218 		}
17219 	    }
17220 	  else
17221 	    {
17222 	      c_parser_consume_token (parser);
17223 	      if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
17224 		bad = true;
17225 	      else
17226 		{
17227 		  tree st = push_stmt_list ();
17228 		  location_t loc = c_parser_peek_token (parser)->location;
17229 		  rich_location richloc (line_table, loc);
17230 		  start_init (omp_priv, NULL_TREE, 0, &richloc);
17231 		  struct c_expr init = c_parser_initializer (parser);
17232 		  finish_init ();
17233 		  finish_decl (omp_priv, loc, init.value,
17234 		      	       init.original_type, NULL_TREE);
17235 		  pop_stmt_list (st);
17236 		}
17237 	    }
17238 	  if (!bad
17239 	      && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
17240 	    bad = true;
17241 	}
17242 
17243       if (!bad)
17244 	{
17245 	  c_parser_skip_to_pragma_eol (parser);
17246 
17247 	  tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
17248 			      DECL_INITIAL (reduc_decl));
17249 	  DECL_INITIAL (reduc_decl) = t;
17250 	  DECL_SOURCE_LOCATION (omp_out) = rloc;
17251 	  TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
17252 	  TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
17253 	  TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
17254 	  walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
17255 		     &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
17256 	  if (omp_priv)
17257 	    {
17258 	      DECL_SOURCE_LOCATION (omp_priv) = rloc;
17259 	      TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
17260 	      TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
17261 	      TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
17262 	      walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
17263 			 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
17264 	      walk_tree (&DECL_INITIAL (omp_priv),
17265 			 c_check_omp_declare_reduction_r,
17266 			 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
17267 	    }
17268 	}
17269 
17270       pop_stmt_list (stmt);
17271       pop_scope ();
17272       if (cfun->language != NULL)
17273 	{
17274 	  ggc_free (cfun->language);
17275 	  cfun->language = NULL;
17276 	}
17277       set_cfun (NULL);
17278       current_function_decl = NULL_TREE;
17279       if (nested)
17280 	c_pop_function_context ();
17281 
17282       if (!clauses.is_empty ())
17283 	{
17284 	  parser->tokens = &parser->tokens_buf[0];
17285 	  parser->tokens_avail = tokens_avail;
17286 	}
17287       if (bad)
17288 	goto fail;
17289       if (errs != errorcount)
17290 	break;
17291     }
17292 
17293   clauses.release ();
17294   types.release ();
17295 }
17296 
17297 
17298 /* OpenMP 4.0
17299    #pragma omp declare simd declare-simd-clauses[optseq] new-line
17300    #pragma omp declare reduction (reduction-id : typename-list : expression) \
17301       initializer-clause[opt] new-line
17302    #pragma omp declare target new-line  */
17303 
17304 static void
17305 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
17306 {
17307   c_parser_consume_pragma (parser);
17308   if (c_parser_next_token_is (parser, CPP_NAME))
17309     {
17310       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17311       if (strcmp (p, "simd") == 0)
17312 	{
17313 	  /* c_parser_consume_token (parser); done in
17314 	     c_parser_omp_declare_simd.  */
17315 	  c_parser_omp_declare_simd (parser, context);
17316 	  return;
17317 	}
17318       if (strcmp (p, "reduction") == 0)
17319 	{
17320 	  c_parser_consume_token (parser);
17321 	  c_parser_omp_declare_reduction (parser, context);
17322 	  return;
17323 	}
17324       if (!flag_openmp)  /* flag_openmp_simd  */
17325 	{
17326 	  c_parser_skip_to_pragma_eol (parser, false);
17327 	  return;
17328 	}
17329       if (strcmp (p, "target") == 0)
17330 	{
17331 	  c_parser_consume_token (parser);
17332 	  c_parser_omp_declare_target (parser);
17333 	  return;
17334 	}
17335     }
17336 
17337   c_parser_error (parser, "expected %<simd%> or %<reduction%> "
17338 			  "or %<target%>");
17339   c_parser_skip_to_pragma_eol (parser);
17340 }
17341 
17342 /* OpenMP 4.5:
17343    #pragma omp taskloop taskloop-clause[optseq] new-line
17344      for-loop
17345 
17346    #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17347      for-loop  */
17348 
17349 #define OMP_TASKLOOP_CLAUSE_MASK				\
17350 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
17351 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
17352 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
17353 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
17354 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
17355 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE)	\
17356 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS)	\
17357 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)	\
17358 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED)	\
17359 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
17360 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
17361 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
17362 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)	\
17363 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17364 
17365 static tree
17366 c_parser_omp_taskloop (location_t loc, c_parser *parser,
17367 		       char *p_name, omp_clause_mask mask, tree *cclauses,
17368 		       bool *if_p)
17369 {
17370   tree clauses, block, ret;
17371 
17372   strcat (p_name, " taskloop");
17373   mask |= OMP_TASKLOOP_CLAUSE_MASK;
17374 
17375   if (c_parser_next_token_is (parser, CPP_NAME))
17376     {
17377       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17378 
17379       if (strcmp (p, "simd") == 0)
17380 	{
17381 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
17382 	  if (cclauses == NULL)
17383 	    cclauses = cclauses_buf;
17384 	  mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION);
17385 	  c_parser_consume_token (parser);
17386 	  if (!flag_openmp)  /* flag_openmp_simd  */
17387 	    return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
17388 				      if_p);
17389 	  block = c_begin_compound_stmt (true);
17390 	  ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
17391 	  block = c_end_compound_stmt (loc, block, true);
17392 	  if (ret == NULL)
17393 	    return ret;
17394 	  ret = make_node (OMP_TASKLOOP);
17395 	  TREE_TYPE (ret) = void_type_node;
17396 	  OMP_FOR_BODY (ret) = block;
17397 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
17398 	  SET_EXPR_LOCATION (ret, loc);
17399 	  add_stmt (ret);
17400 	  return ret;
17401 	}
17402     }
17403   if (!flag_openmp)  /* flag_openmp_simd  */
17404     {
17405       c_parser_skip_to_pragma_eol (parser, false);
17406       return NULL_TREE;
17407     }
17408 
17409   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
17410   if (cclauses)
17411     {
17412       omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses);
17413       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
17414     }
17415 
17416   block = c_begin_compound_stmt (true);
17417   ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p);
17418   block = c_end_compound_stmt (loc, block, true);
17419   add_stmt (block);
17420 
17421   return ret;
17422 }
17423 
17424 /* Main entry point to parsing most OpenMP pragmas.  */
17425 
17426 static void
17427 c_parser_omp_construct (c_parser *parser, bool *if_p)
17428 {
17429   enum pragma_kind p_kind;
17430   location_t loc;
17431   tree stmt;
17432   char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
17433   omp_clause_mask mask (0);
17434 
17435   loc = c_parser_peek_token (parser)->location;
17436   p_kind = c_parser_peek_token (parser)->pragma_kind;
17437   c_parser_consume_pragma (parser);
17438 
17439   switch (p_kind)
17440     {
17441     case PRAGMA_OACC_ATOMIC:
17442       c_parser_omp_atomic (loc, parser);
17443       return;
17444     case PRAGMA_OACC_CACHE:
17445       strcpy (p_name, "#pragma acc");
17446       stmt = c_parser_oacc_cache (loc, parser);
17447       break;
17448     case PRAGMA_OACC_DATA:
17449       stmt = c_parser_oacc_data (loc, parser, if_p);
17450       break;
17451     case PRAGMA_OACC_HOST_DATA:
17452       stmt = c_parser_oacc_host_data (loc, parser, if_p);
17453       break;
17454     case PRAGMA_OACC_KERNELS:
17455     case PRAGMA_OACC_PARALLEL:
17456       strcpy (p_name, "#pragma acc");
17457       stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name,
17458 					     if_p);
17459       break;
17460     case PRAGMA_OACC_LOOP:
17461       strcpy (p_name, "#pragma acc");
17462       stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p);
17463       break;
17464     case PRAGMA_OACC_WAIT:
17465       strcpy (p_name, "#pragma wait");
17466       stmt = c_parser_oacc_wait (loc, parser, p_name);
17467       break;
17468     case PRAGMA_OMP_ATOMIC:
17469       c_parser_omp_atomic (loc, parser);
17470       return;
17471     case PRAGMA_OMP_CRITICAL:
17472       stmt = c_parser_omp_critical (loc, parser, if_p);
17473       break;
17474     case PRAGMA_OMP_DISTRIBUTE:
17475       strcpy (p_name, "#pragma omp");
17476       stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p);
17477       break;
17478     case PRAGMA_OMP_FOR:
17479       strcpy (p_name, "#pragma omp");
17480       stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p);
17481       break;
17482     case PRAGMA_OMP_MASTER:
17483       stmt = c_parser_omp_master (loc, parser, if_p);
17484       break;
17485     case PRAGMA_OMP_PARALLEL:
17486       strcpy (p_name, "#pragma omp");
17487       stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p);
17488       break;
17489     case PRAGMA_OMP_SECTIONS:
17490       strcpy (p_name, "#pragma omp");
17491       stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
17492       break;
17493     case PRAGMA_OMP_SIMD:
17494       strcpy (p_name, "#pragma omp");
17495       stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p);
17496       break;
17497     case PRAGMA_OMP_SINGLE:
17498       stmt = c_parser_omp_single (loc, parser, if_p);
17499       break;
17500     case PRAGMA_OMP_TASK:
17501       stmt = c_parser_omp_task (loc, parser, if_p);
17502       break;
17503     case PRAGMA_OMP_TASKGROUP:
17504       stmt = c_parser_omp_taskgroup (parser, if_p);
17505       break;
17506     case PRAGMA_OMP_TASKLOOP:
17507       strcpy (p_name, "#pragma omp");
17508       stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p);
17509       break;
17510     case PRAGMA_OMP_TEAMS:
17511       strcpy (p_name, "#pragma omp");
17512       stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p);
17513       break;
17514     default:
17515       gcc_unreachable ();
17516     }
17517 
17518   if (stmt)
17519     gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
17520 }
17521 
17522 
17523 /* OpenMP 2.5:
17524    # pragma omp threadprivate (variable-list) */
17525 
17526 static void
17527 c_parser_omp_threadprivate (c_parser *parser)
17528 {
17529   tree vars, t;
17530   location_t loc;
17531 
17532   c_parser_consume_pragma (parser);
17533   loc = c_parser_peek_token (parser)->location;
17534   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
17535 
17536   /* Mark every variable in VARS to be assigned thread local storage.  */
17537   for (t = vars; t; t = TREE_CHAIN (t))
17538     {
17539       tree v = TREE_PURPOSE (t);
17540 
17541       /* FIXME diagnostics: Ideally we should keep individual
17542 	 locations for all the variables in the var list to make the
17543 	 following errors more precise.  Perhaps
17544 	 c_parser_omp_var_list_parens() should construct a list of
17545 	 locations to go along with the var list.  */
17546 
17547       /* If V had already been marked threadprivate, it doesn't matter
17548 	 whether it had been used prior to this point.  */
17549       if (!VAR_P (v))
17550 	error_at (loc, "%qD is not a variable", v);
17551       else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
17552 	error_at (loc, "%qE declared %<threadprivate%> after first use", v);
17553       else if (! is_global_var (v))
17554 	error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
17555       else if (TREE_TYPE (v) == error_mark_node)
17556 	;
17557       else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
17558 	error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
17559       else
17560 	{
17561 	  if (! DECL_THREAD_LOCAL_P (v))
17562 	    {
17563 	      set_decl_tls_model (v, decl_default_tls_model (v));
17564 	      /* If rtl has been already set for this var, call
17565 		 make_decl_rtl once again, so that encode_section_info
17566 		 has a chance to look at the new decl flags.  */
17567 	      if (DECL_RTL_SET_P (v))
17568 		make_decl_rtl (v);
17569 	    }
17570 	  C_DECL_THREADPRIVATE_P (v) = 1;
17571 	}
17572     }
17573 
17574   c_parser_skip_to_pragma_eol (parser);
17575 }
17576 
17577 /* Cilk Plus <#pragma simd> parsing routines.  */
17578 
17579 /* Helper function for c_parser_pragma.  Perform some sanity checking
17580    for <#pragma simd> constructs.  Returns FALSE if there was a
17581    problem.  */
17582 
17583 static bool
17584 c_parser_cilk_verify_simd (c_parser *parser,
17585 				  enum pragma_context context)
17586 {
17587   if (!flag_cilkplus)
17588     {
17589       warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17590       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
17591       return false;
17592     }
17593   if (context == pragma_external)
17594     {
17595       c_parser_error (parser,"pragma simd must be inside a function");
17596       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
17597       return false;
17598     }
17599   return true;
17600 }
17601 
17602 /* Cilk Plus:
17603    This function is shared by SIMD-enabled functions and #pragma simd.
17604    If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17605    CLAUSES is unused.  The main purpose of this function is to parse a
17606    vectorlength attribute or clause and check for parse errors.
17607    When IS_SIMD_FN is true then the function is merely caching the tokens
17608    in PARSER->CILK_SIMD_FN_TOKENS.  If errors are found then the token
17609    cache is cleared since there is no reason to continue.
17610    Syntax:
17611    vectorlength ( constant-expression )  */
17612 
17613 static tree
17614 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses,
17615 				   bool is_simd_fn)
17616 {
17617   if (is_simd_fn)
17618     check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength");
17619   else
17620   /* The vectorlength clause behaves exactly like OpenMP's safelen
17621      clause.  Represent it in OpenMP terms.  */
17622     check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
17623 
17624   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17625     return clauses;
17626 
17627   location_t loc = c_parser_peek_token (parser)->location;
17628   tree expr = c_parser_expr_no_commas (parser, NULL).value;
17629   expr = c_fully_fold (expr, false, NULL);
17630 
17631   /* If expr is an error_mark_node then the above function would have
17632      emitted an error.  No reason to do it twice.  */
17633   if (expr == error_mark_node)
17634     ;
17635   else if (!TREE_TYPE (expr)
17636 	   || !TREE_CONSTANT (expr)
17637 	   || !INTEGRAL_TYPE_P (TREE_TYPE (expr)))
17638 
17639     error_at (loc, "vectorlength must be an integer constant");
17640   else if (wi::exact_log2 (expr) == -1)
17641     error_at (loc, "vectorlength must be a power of 2");
17642   else
17643     {
17644       if (is_simd_fn)
17645 	{
17646 	  tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN);
17647 	  OMP_CLAUSE_SIMDLEN_EXPR (u) = expr;
17648 	  OMP_CLAUSE_CHAIN (u) = clauses;
17649 	  clauses = u;
17650 	}
17651       else
17652 	{
17653 	  tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN);
17654 	  OMP_CLAUSE_SAFELEN_EXPR (u) = expr;
17655 	  OMP_CLAUSE_CHAIN (u) = clauses;
17656 	  clauses = u;
17657 	}
17658     }
17659 
17660   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
17661 
17662   return clauses;
17663 }
17664 
17665 /* Cilk Plus:
17666    linear ( simd-linear-variable-list )
17667 
17668    simd-linear-variable-list:
17669      simd-linear-variable
17670      simd-linear-variable-list , simd-linear-variable
17671 
17672    simd-linear-variable:
17673      id-expression
17674      id-expression : simd-linear-step
17675 
17676    simd-linear-step:
17677    conditional-expression */
17678 
17679 static tree
17680 c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
17681 {
17682   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17683     return clauses;
17684 
17685   location_t loc = c_parser_peek_token (parser)->location;
17686 
17687   if (c_parser_next_token_is_not (parser, CPP_NAME)
17688       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
17689     c_parser_error (parser, "expected identifier");
17690 
17691   while (c_parser_next_token_is (parser, CPP_NAME)
17692 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
17693     {
17694       tree var = lookup_name (c_parser_peek_token (parser)->value);
17695 
17696       if (var == NULL)
17697 	{
17698 	  undeclared_variable (c_parser_peek_token (parser)->location,
17699 			       c_parser_peek_token (parser)->value);
17700 	c_parser_consume_token (parser);
17701 	}
17702       else if (var == error_mark_node)
17703 	c_parser_consume_token (parser);
17704       else
17705 	{
17706 	  tree step = integer_one_node;
17707 
17708 	  /* Parse the linear step if present.  */
17709 	  if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
17710 	    {
17711 	      c_parser_consume_token (parser);
17712 	      c_parser_consume_token (parser);
17713 
17714 	      tree expr = c_parser_expr_no_commas (parser, NULL).value;
17715 	      expr = c_fully_fold (expr, false, NULL);
17716 
17717 	      if (TREE_TYPE (expr)
17718 		  && INTEGRAL_TYPE_P (TREE_TYPE (expr))
17719 		  && (TREE_CONSTANT (expr)
17720 		      || DECL_P (expr)))
17721 		step = expr;
17722 	      else
17723 		c_parser_error (parser,
17724 				"step size must be an integer constant "
17725 				"expression or an integer variable");
17726 	    }
17727 	  else
17728 	    c_parser_consume_token (parser);
17729 
17730 	  /* Use OMP_CLAUSE_LINEAR, which has the same semantics.  */
17731 	  tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR);
17732 	  OMP_CLAUSE_DECL (u) = var;
17733 	  OMP_CLAUSE_LINEAR_STEP (u) = step;
17734 	  OMP_CLAUSE_CHAIN (u) = clauses;
17735 	  clauses = u;
17736 	}
17737 
17738       if (c_parser_next_token_is_not (parser, CPP_COMMA))
17739 	break;
17740 
17741       c_parser_consume_token (parser);
17742     }
17743 
17744   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
17745 
17746   return clauses;
17747 }
17748 
17749 /* Returns the name of the next clause.  If the clause is not
17750    recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17751    not consumed.  Otherwise, the appropriate pragma_simd_clause is
17752    returned and the token is consumed.  */
17753 
17754 static pragma_omp_clause
17755 c_parser_cilk_clause_name (c_parser *parser)
17756 {
17757   pragma_omp_clause result;
17758   c_token *token = c_parser_peek_token (parser);
17759 
17760   if (!token->value || token->type != CPP_NAME)
17761     return PRAGMA_CILK_CLAUSE_NONE;
17762 
17763   const char *p = IDENTIFIER_POINTER (token->value);
17764 
17765   if (!strcmp (p, "vectorlength"))
17766     result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
17767   else if (!strcmp (p, "linear"))
17768     result = PRAGMA_CILK_CLAUSE_LINEAR;
17769   else if (!strcmp (p, "private"))
17770     result = PRAGMA_CILK_CLAUSE_PRIVATE;
17771   else if (!strcmp (p, "firstprivate"))
17772     result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
17773   else if (!strcmp (p, "lastprivate"))
17774     result = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
17775   else if (!strcmp (p, "reduction"))
17776     result = PRAGMA_CILK_CLAUSE_REDUCTION;
17777   else
17778     return PRAGMA_CILK_CLAUSE_NONE;
17779 
17780   c_parser_consume_token (parser);
17781   return result;
17782 }
17783 
17784 /* Parse all #<pragma simd> clauses.  Return the list of clauses
17785    found.  */
17786 
17787 static tree
17788 c_parser_cilk_all_clauses (c_parser *parser)
17789 {
17790   tree clauses = NULL;
17791 
17792   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17793     {
17794       pragma_omp_clause c_kind;
17795 
17796       c_kind = c_parser_cilk_clause_name (parser);
17797 
17798       switch (c_kind)
17799 	{
17800 	case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
17801 	  clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false);
17802 	  break;
17803 	case PRAGMA_CILK_CLAUSE_LINEAR:
17804 	  clauses = c_parser_cilk_clause_linear (parser, clauses);
17805 	  break;
17806 	case PRAGMA_CILK_CLAUSE_PRIVATE:
17807 	  /* Use the OpenMP counterpart.  */
17808 	  clauses = c_parser_omp_clause_private (parser, clauses);
17809 	  break;
17810 	case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE:
17811 	  /* Use the OpenMP counterpart.  */
17812 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
17813 	  break;
17814 	case PRAGMA_CILK_CLAUSE_LASTPRIVATE:
17815 	  /* Use the OpenMP counterpart.  */
17816 	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
17817 	  break;
17818 	case PRAGMA_CILK_CLAUSE_REDUCTION:
17819 	  /* Use the OpenMP counterpart.  */
17820 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
17821 	  break;
17822 	default:
17823 	  c_parser_error (parser, "expected %<#pragma simd%> clause");
17824 	  goto saw_error;
17825 	}
17826     }
17827 
17828  saw_error:
17829   c_parser_skip_to_pragma_eol (parser);
17830   return c_finish_omp_clauses (clauses, C_ORT_CILK);
17831 }
17832 
17833 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17834    Here is the correct syntax of this pragma:
17835 	    #pragma cilk grainsize = <EXP>
17836  */
17837 
17838 static void
17839 c_parser_cilk_grainsize (c_parser *parser, bool *if_p)
17840 {
17841   extern tree convert_to_integer (tree, tree);
17842 
17843   /* consume the 'grainsize' keyword.  */
17844   c_parser_consume_pragma (parser);
17845 
17846   if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0)
17847     {
17848       struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL);
17849       if (g_expr.value == error_mark_node)
17850 	{
17851 	  c_parser_skip_to_pragma_eol (parser);
17852 	  return;
17853 	}
17854       tree grain = convert_to_integer (long_integer_type_node,
17855 				       c_fully_fold (g_expr.value, false,
17856 						     NULL));
17857       c_parser_skip_to_pragma_eol (parser);
17858       c_token *token = c_parser_peek_token (parser);
17859       if (token && token->type == CPP_KEYWORD
17860 	  && token->keyword == RID_CILK_FOR)
17861 	{
17862 	  if (grain == NULL_TREE || grain == error_mark_node)
17863 	    grain = integer_zero_node;
17864 	  c_parser_cilk_for (parser, grain, if_p);
17865 	}
17866       else
17867 	warning (0, "%<#pragma cilk grainsize%> is not followed by "
17868 		    "%<_Cilk_for%>");
17869     }
17870   else
17871     c_parser_skip_to_pragma_eol (parser);
17872 }
17873 
17874 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops.  */
17875 
17876 static void
17877 c_parser_cilk_simd (c_parser *parser, bool *if_p)
17878 {
17879   tree clauses = c_parser_cilk_all_clauses (parser);
17880   tree block = c_begin_compound_stmt (true);
17881   location_t loc = c_parser_peek_token (parser)->location;
17882   c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL, if_p);
17883   block = c_end_compound_stmt (loc, block, true);
17884   add_stmt (block);
17885 }
17886 
17887 /* Create an artificial decl with TYPE and emit initialization of it with
17888    INIT.  */
17889 
17890 static tree
17891 c_get_temp_regvar (tree type, tree init)
17892 {
17893   location_t loc = EXPR_LOCATION (init);
17894   tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
17895   DECL_ARTIFICIAL (decl) = 1;
17896   DECL_IGNORED_P (decl) = 1;
17897   pushdecl (decl);
17898   tree t = build2 (INIT_EXPR, type, decl, init);
17899   add_stmt (t);
17900   return decl;
17901 }
17902 
17903 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17904   GRAIN is the grain value passed in through pragma or 0.  */
17905 
17906 static void
17907 c_parser_cilk_for (c_parser *parser, tree grain, bool *if_p)
17908 {
17909   tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE);
17910   OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR;
17911   OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain;
17912   clauses = c_finish_omp_clauses (clauses, C_ORT_CILK);
17913 
17914   tree block = c_begin_compound_stmt (true);
17915   tree sb = push_stmt_list ();
17916   location_t loc = c_parser_peek_token (parser)->location;
17917   tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL,
17918 					if_p);
17919   sb = pop_stmt_list (sb);
17920 
17921   if (omp_for)
17922     {
17923       tree omp_par = make_node (OMP_PARALLEL);
17924       TREE_TYPE (omp_par) = void_type_node;
17925       OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE;
17926       tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
17927       TREE_SIDE_EFFECTS (bind) = 1;
17928       BIND_EXPR_BODY (bind) = sb;
17929       OMP_PARALLEL_BODY (omp_par) = bind;
17930       if (OMP_FOR_PRE_BODY (omp_for))
17931 	{
17932 	  add_stmt (OMP_FOR_PRE_BODY (omp_for));
17933 	  OMP_FOR_PRE_BODY (omp_for) = NULL_TREE;
17934 	}
17935       tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0);
17936       tree decl = TREE_OPERAND (init, 0);
17937       tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0);
17938       tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
17939       tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE;
17940       if (TREE_CODE (t) != INTEGER_CST)
17941 	{
17942 	  TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
17943 	  c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
17944 	  OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1);
17945 	  OMP_CLAUSE_CHAIN (c) = clauses;
17946 	  clauses = c;
17947 	}
17948       if (TREE_CODE (incr) == MODIFY_EXPR)
17949 	{
17950 	  t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
17951 	  if (TREE_CODE (t) != INTEGER_CST)
17952 	    {
17953 	      TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
17954 		= c_get_temp_regvar (TREE_TYPE (t), t);
17955 	      c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
17956 	      OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
17957 	      OMP_CLAUSE_CHAIN (c) = clauses;
17958 	      clauses = c;
17959 	    }
17960 	}
17961       t = TREE_OPERAND (init, 1);
17962       if (TREE_CODE (t) != INTEGER_CST)
17963 	{
17964 	  TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
17965 	  c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
17966 	  OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1);
17967 	  OMP_CLAUSE_CHAIN (c) = clauses;
17968 	  clauses = c;
17969 	}
17970       c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
17971       OMP_CLAUSE_DECL (c) = decl;
17972       OMP_CLAUSE_CHAIN (c) = clauses;
17973       clauses = c;
17974       c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_);
17975       OMP_CLAUSE_OPERAND (c, 0)
17976 	= cilk_for_number_of_iterations (omp_for);
17977       OMP_CLAUSE_CHAIN (c) = clauses;
17978       OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c, C_ORT_CILK);
17979       add_stmt (omp_par);
17980     }
17981 
17982   block = c_end_compound_stmt (loc, block, true);
17983   add_stmt (block);
17984 }
17985 
17986 
17987 /* Parse a transaction attribute (GCC Extension).
17988 
17989    transaction-attribute:
17990      attributes
17991      [ [ any-word ] ]
17992 
17993    The transactional memory language description is written for C++,
17994    and uses the C++0x attribute syntax.  For compatibility, allow the
17995    bracket style for transactions in C as well.  */
17996 
17997 static tree
17998 c_parser_transaction_attributes (c_parser *parser)
17999 {
18000   tree attr_name, attr = NULL;
18001 
18002   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
18003     return c_parser_attributes (parser);
18004 
18005   if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
18006     return NULL_TREE;
18007   c_parser_consume_token (parser);
18008   if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
18009     goto error1;
18010 
18011   attr_name = c_parser_attribute_any_word (parser);
18012   if (attr_name)
18013     {
18014       c_parser_consume_token (parser);
18015       attr = build_tree_list (attr_name, NULL_TREE);
18016     }
18017   else
18018     c_parser_error (parser, "expected identifier");
18019 
18020   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
18021  error1:
18022   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
18023   return attr;
18024 }
18025 
18026 /* Parse a __transaction_atomic or __transaction_relaxed statement
18027    (GCC Extension).
18028 
18029    transaction-statement:
18030      __transaction_atomic transaction-attribute[opt] compound-statement
18031      __transaction_relaxed compound-statement
18032 
18033    Note that the only valid attribute is: "outer".
18034 */
18035 
18036 static tree
18037 c_parser_transaction (c_parser *parser, enum rid keyword)
18038 {
18039   unsigned int old_in = parser->in_transaction;
18040   unsigned int this_in = 1, new_in;
18041   location_t loc = c_parser_peek_token (parser)->location;
18042   tree stmt, attrs;
18043 
18044   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
18045       || keyword == RID_TRANSACTION_RELAXED)
18046       && c_parser_next_token_is_keyword (parser, keyword));
18047   c_parser_consume_token (parser);
18048 
18049   if (keyword == RID_TRANSACTION_RELAXED)
18050     this_in |= TM_STMT_ATTR_RELAXED;
18051   else
18052     {
18053       attrs = c_parser_transaction_attributes (parser);
18054       if (attrs)
18055 	this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
18056     }
18057 
18058   /* Keep track if we're in the lexical scope of an outer transaction.  */
18059   new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
18060 
18061   parser->in_transaction = new_in;
18062   stmt = c_parser_compound_statement (parser);
18063   parser->in_transaction = old_in;
18064 
18065   if (flag_tm)
18066     stmt = c_finish_transaction (loc, stmt, this_in);
18067   else
18068     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
18069 	"%<__transaction_atomic%> without transactional memory support enabled"
18070 	: "%<__transaction_relaxed %> "
18071 	"without transactional memory support enabled"));
18072 
18073   return stmt;
18074 }
18075 
18076 /* Parse a __transaction_atomic or __transaction_relaxed expression
18077    (GCC Extension).
18078 
18079    transaction-expression:
18080      __transaction_atomic ( expression )
18081      __transaction_relaxed ( expression )
18082 */
18083 
18084 static struct c_expr
18085 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
18086 {
18087   struct c_expr ret;
18088   unsigned int old_in = parser->in_transaction;
18089   unsigned int this_in = 1;
18090   location_t loc = c_parser_peek_token (parser)->location;
18091   tree attrs;
18092 
18093   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
18094       || keyword == RID_TRANSACTION_RELAXED)
18095       && c_parser_next_token_is_keyword (parser, keyword));
18096   c_parser_consume_token (parser);
18097 
18098   if (keyword == RID_TRANSACTION_RELAXED)
18099     this_in |= TM_STMT_ATTR_RELAXED;
18100   else
18101     {
18102       attrs = c_parser_transaction_attributes (parser);
18103       if (attrs)
18104 	this_in |= parse_tm_stmt_attr (attrs, 0);
18105     }
18106 
18107   parser->in_transaction = this_in;
18108   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
18109     {
18110       tree expr = c_parser_expression (parser).value;
18111       ret.original_type = TREE_TYPE (expr);
18112       ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
18113       if (this_in & TM_STMT_ATTR_RELAXED)
18114 	TRANSACTION_EXPR_RELAXED (ret.value) = 1;
18115       SET_EXPR_LOCATION (ret.value, loc);
18116       ret.original_code = TRANSACTION_EXPR;
18117       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
18118 	{
18119 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
18120 	  goto error;
18121 	}
18122     }
18123   else
18124     {
18125      error:
18126       ret.value = error_mark_node;
18127       ret.original_code = ERROR_MARK;
18128       ret.original_type = NULL;
18129     }
18130   parser->in_transaction = old_in;
18131 
18132   if (!flag_tm)
18133     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
18134 	"%<__transaction_atomic%> without transactional memory support enabled"
18135 	: "%<__transaction_relaxed %> "
18136 	"without transactional memory support enabled"));
18137 
18138   set_c_expr_source_range (&ret, loc, loc);
18139 
18140   return ret;
18141 }
18142 
18143 /* Parse a __transaction_cancel statement (GCC Extension).
18144 
18145    transaction-cancel-statement:
18146      __transaction_cancel transaction-attribute[opt] ;
18147 
18148    Note that the only valid attribute is "outer".
18149 */
18150 
18151 static tree
18152 c_parser_transaction_cancel (c_parser *parser)
18153 {
18154   location_t loc = c_parser_peek_token (parser)->location;
18155   tree attrs;
18156   bool is_outer = false;
18157 
18158   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
18159   c_parser_consume_token (parser);
18160 
18161   attrs = c_parser_transaction_attributes (parser);
18162   if (attrs)
18163     is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
18164 
18165   if (!flag_tm)
18166     {
18167       error_at (loc, "%<__transaction_cancel%> without "
18168 		"transactional memory support enabled");
18169       goto ret_error;
18170     }
18171   else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
18172     {
18173       error_at (loc, "%<__transaction_cancel%> within a "
18174 		"%<__transaction_relaxed%>");
18175       goto ret_error;
18176     }
18177   else if (is_outer)
18178     {
18179       if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
18180 	  && !is_tm_may_cancel_outer (current_function_decl))
18181 	{
18182 	  error_at (loc, "outer %<__transaction_cancel%> not "
18183 		    "within outer %<__transaction_atomic%>");
18184 	  error_at (loc, "  or a %<transaction_may_cancel_outer%> function");
18185 	  goto ret_error;
18186 	}
18187     }
18188   else if (parser->in_transaction == 0)
18189     {
18190       error_at (loc, "%<__transaction_cancel%> not within "
18191 		"%<__transaction_atomic%>");
18192       goto ret_error;
18193     }
18194 
18195   return add_stmt (build_tm_abort_call (loc, is_outer));
18196 
18197  ret_error:
18198   return build1 (NOP_EXPR, void_type_node, error_mark_node);
18199 }
18200 
18201 /* Parse a single source file.  */
18202 
18203 void
18204 c_parse_file (void)
18205 {
18206   /* Use local storage to begin.  If the first token is a pragma, parse it.
18207      If it is #pragma GCC pch_preprocess, then this will load a PCH file
18208      which will cause garbage collection.  */
18209   c_parser tparser;
18210 
18211   memset (&tparser, 0, sizeof tparser);
18212   tparser.tokens = &tparser.tokens_buf[0];
18213   the_parser = &tparser;
18214 
18215   if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
18216     c_parser_pragma_pch_preprocess (&tparser);
18217   else
18218     c_common_no_more_pch ();
18219 
18220   the_parser = ggc_alloc<c_parser> ();
18221   *the_parser = tparser;
18222   if (tparser.tokens == &tparser.tokens_buf[0])
18223     the_parser->tokens = &the_parser->tokens_buf[0];
18224 
18225   /* Initialize EH, if we've been told to do so.  */
18226   if (flag_exceptions)
18227     using_eh_for_cleanups ();
18228 
18229   c_parser_translation_unit (the_parser);
18230   the_parser = NULL;
18231 }
18232 
18233 /* This function parses Cilk Plus array notation.  The starting index is
18234    passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE.  The
18235    return value of this function is a tree_node called VALUE_TREE of type
18236    ARRAY_NOTATION_REF.  */
18237 
18238 static tree
18239 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
18240 			 tree array_value)
18241 {
18242   c_token *token = NULL;
18243   tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE;
18244   tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE;
18245   tree array_type_domain = NULL_TREE;
18246 
18247   if (array_value == error_mark_node || initial_index == error_mark_node)
18248     {
18249       /* No need to continue.  If either of these 2 were true, then an error
18250 	 must be emitted already.  Thus, no need to emit them twice.  */
18251       c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
18252       return error_mark_node;
18253     }
18254 
18255   array_type = TREE_TYPE (array_value);
18256   gcc_assert (array_type);
18257   if (TREE_CODE (array_type) != ARRAY_TYPE
18258       && TREE_CODE (array_type) != POINTER_TYPE)
18259     {
18260       error_at (loc, "base of array section must be pointer or array type");
18261       c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
18262       return error_mark_node;
18263     }
18264   type = TREE_TYPE (array_type);
18265   token = c_parser_peek_token (parser);
18266 
18267   if (token->type == CPP_EOF)
18268     {
18269       c_parser_error (parser, "expected %<:%> or numeral");
18270       return value_tree;
18271     }
18272   else if (token->type == CPP_COLON)
18273     {
18274       if (!initial_index)
18275 	{
18276 	  /* If we are here, then we have a case like this A[:].  */
18277 	  c_parser_consume_token (parser);
18278 	  if (TREE_CODE (array_type) == POINTER_TYPE)
18279 	    {
18280 	      error_at (loc, "start-index and length fields necessary for "
18281 			"using array notations in pointers");
18282 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
18283 	      return error_mark_node;
18284 	    }
18285 	  if (TREE_CODE (array_type) == FUNCTION_TYPE)
18286 	    {
18287 	      error_at (loc, "array notations cannot be used with function "
18288 			"type");
18289 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
18290 	      return error_mark_node;
18291 	    }
18292 	  array_type_domain = TYPE_DOMAIN (array_type);
18293 
18294 	  if (!array_type_domain)
18295 	    {
18296 	      error_at (loc, "start-index and length fields necessary for "
18297 			"using array notations in dimensionless arrays");
18298 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
18299 	      return error_mark_node;
18300 	    }
18301 
18302 	  start_index = TYPE_MINVAL (array_type_domain);
18303 	  start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node,
18304 				     start_index);
18305 	  if (!TYPE_MAXVAL (array_type_domain)
18306 	      || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain)))
18307 	    {
18308 	      error_at (loc, "start-index and length fields necessary for "
18309 			"using array notations in variable-length arrays");
18310 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
18311 	      return error_mark_node;
18312 	    }
18313 	  end_index = TYPE_MAXVAL (array_type_domain);
18314 	  end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index),
18315 				   end_index, integer_one_node);
18316 	  end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index);
18317 	  stride = build_int_cst (integer_type_node, 1);
18318 	  stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride);
18319 	}
18320       else if (initial_index != error_mark_node)
18321 	{
18322 	  /* If we are here, then there should be 2 possibilities:
18323 	     1. Array [EXPR : EXPR]
18324 	     2. Array [EXPR : EXPR : EXPR]
18325 	  */
18326 	  start_index = initial_index;
18327 
18328 	  if (TREE_CODE (array_type) == FUNCTION_TYPE)
18329 	    {
18330 	      error_at (loc, "array notations cannot be used with function "
18331 			"type");
18332 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
18333 	      return error_mark_node;
18334 	    }
18335 	  c_parser_consume_token (parser); /* consume the ':' */
18336 	  struct c_expr ce = c_parser_expression (parser);
18337 	  ce = convert_lvalue_to_rvalue (loc, ce, false, false);
18338 	  end_index = ce.value;
18339 	  if (!end_index || end_index == error_mark_node)
18340 	    {
18341 	      c_parser_skip_to_end_of_block_or_statement (parser);
18342 	      return error_mark_node;
18343 	    }
18344 	  if (c_parser_peek_token (parser)->type == CPP_COLON)
18345 	    {
18346 	      c_parser_consume_token (parser);
18347 	      ce = c_parser_expression (parser);
18348 	      ce = convert_lvalue_to_rvalue (loc, ce, false, false);
18349 	      stride = ce.value;
18350 	      if (!stride || stride == error_mark_node)
18351 		{
18352 		  c_parser_skip_to_end_of_block_or_statement (parser);
18353 		  return error_mark_node;
18354 		}
18355 	    }
18356 	}
18357       else
18358 	c_parser_error (parser, "expected array notation expression");
18359     }
18360   else
18361     c_parser_error (parser, "expected array notation expression");
18362 
18363   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
18364 
18365   value_tree = build_array_notation_ref (loc, array_value, start_index,
18366 					 end_index, stride, type);
18367   if (value_tree != error_mark_node)
18368     SET_EXPR_LOCATION (value_tree, loc);
18369   return value_tree;
18370 }
18371 
18372 /* Parse the body of a function declaration marked with "__RTL".
18373 
18374    The RTL parser works on the level of characters read from a
18375    FILE *, whereas c_parser works at the level of tokens.
18376    Square this circle by consuming all of the tokens up to and
18377    including the closing brace, recording the start/end of the RTL
18378    fragment, and reopening the file and re-reading the relevant
18379    lines within the RTL parser.
18380 
18381    This requires the opening and closing braces of the C function
18382    to be on separate lines from the RTL they wrap.
18383 
18384    Take ownership of START_WITH_PASS, if non-NULL.  */
18385 
18386 void
18387 c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass)
18388 {
18389   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
18390     {
18391       free (start_with_pass);
18392       return;
18393     }
18394 
18395   location_t start_loc = c_parser_peek_token (parser)->location;
18396 
18397   /* Consume all tokens, up to the closing brace, handling
18398      matching pairs of braces in the rtl dump.  */
18399   int num_open_braces = 1;
18400   while (1)
18401     {
18402       switch (c_parser_peek_token (parser)->type)
18403 	{
18404 	case CPP_OPEN_BRACE:
18405 	  num_open_braces++;
18406 	  break;
18407 	case CPP_CLOSE_BRACE:
18408 	  if (--num_open_braces == 0)
18409 	    goto found_closing_brace;
18410 	  break;
18411 	case CPP_EOF:
18412 	  error_at (start_loc, "no closing brace");
18413 	  free (start_with_pass);
18414 	  return;
18415 	default:
18416 	  break;
18417 	}
18418       c_parser_consume_token (parser);
18419     }
18420 
18421  found_closing_brace:
18422   /* At the closing brace; record its location.  */
18423   location_t end_loc = c_parser_peek_token (parser)->location;
18424 
18425   /* Consume the closing brace.  */
18426   c_parser_consume_token (parser);
18427 
18428   /* Invoke the RTL parser.  */
18429   if (!read_rtl_function_body_from_file_range (start_loc, end_loc))
18430     {
18431       free (start_with_pass);
18432       return;
18433     }
18434 
18435  /*  If a pass name was provided for START_WITH_PASS, run the backend
18436      accordingly now, on the cfun created above, transferring
18437      ownership of START_WITH_PASS.  */
18438   if (start_with_pass)
18439     run_rtl_passes (start_with_pass);
18440 }
18441 
18442 #include "gt-c-c-parser.h"
18443