xref: /dragonfly/contrib/gcc-8.0/gcc/c/c-parser.c (revision dcb5d66b)
1 /* Parser for C and Objective-C.
2    Copyright (C) 1987-2018 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 #define INCLUDE_UNIQUE_PTR
40 #include "system.h"
41 #include "coretypes.h"
42 #include "target.h"
43 #include "function.h"
44 #include "c-tree.h"
45 #include "timevar.h"
46 #include "stringpool.h"
47 #include "cgraph.h"
48 #include "attribs.h"
49 #include "stor-layout.h"
50 #include "varasm.h"
51 #include "trans-mem.h"
52 #include "c-family/c-pragma.h"
53 #include "c-lang.h"
54 #include "c-family/c-objc.h"
55 #include "plugin.h"
56 #include "omp-general.h"
57 #include "omp-offload.h"
58 #include "builtins.h"
59 #include "gomp-constants.h"
60 #include "c-family/c-indentation.h"
61 #include "gimple-expr.h"
62 #include "context.h"
63 #include "gcc-rich-location.h"
64 #include "c-parser.h"
65 #include "gimple-parser.h"
66 #include "read-rtl-function.h"
67 #include "run-rtl-passes.h"
68 #include "intl.h"
69 #include "c-family/name-hint.h"
70 #include "tree-iterator.h"
71 
72 /* We need to walk over decls with incomplete struct/union/enum types
73    after parsing the whole translation unit.
74    In finish_decl(), if the decl is static, has incomplete
75    struct/union/enum type, it is appeneded to incomplete_record_decls.
76    In c_parser_translation_unit(), we iterate over incomplete_record_decls
77    and report error if any of the decls are still incomplete.  */
78 
79 vec<tree> incomplete_record_decls;
80 
81 void
82 set_c_expr_source_range (c_expr *expr,
83 			 location_t start, location_t finish)
84 {
85   expr->src_range.m_start = start;
86   expr->src_range.m_finish = finish;
87   if (expr->value)
88     set_source_range (expr->value, start, finish);
89 }
90 
91 void
92 set_c_expr_source_range (c_expr *expr,
93 			 source_range src_range)
94 {
95   expr->src_range = src_range;
96   if (expr->value)
97     set_source_range (expr->value, src_range);
98 }
99 
100 
101 /* Initialization routine for this file.  */
102 
103 void
104 c_parse_init (void)
105 {
106   /* The only initialization required is of the reserved word
107      identifiers.  */
108   unsigned int i;
109   tree id;
110   int mask = 0;
111 
112   /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
113      the c_token structure.  */
114   gcc_assert (RID_MAX <= 255);
115 
116   mask |= D_CXXONLY;
117   if (!flag_isoc99)
118     mask |= D_C99;
119   if (flag_no_asm)
120     {
121       mask |= D_ASM | D_EXT;
122       if (!flag_isoc99)
123 	mask |= D_EXT89;
124     }
125   if (!c_dialect_objc ())
126     mask |= D_OBJC | D_CXX_OBJC;
127 
128   ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
129   for (i = 0; i < num_c_common_reswords; i++)
130     {
131       /* If a keyword is disabled, do not enter it into the table
132 	 and so create a canonical spelling that isn't a keyword.  */
133       if (c_common_reswords[i].disable & mask)
134 	{
135 	  if (warn_cxx_compat
136 	      && (c_common_reswords[i].disable & D_CXXWARN))
137 	    {
138 	      id = get_identifier (c_common_reswords[i].word);
139 	      C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
140 	      C_IS_RESERVED_WORD (id) = 1;
141 	    }
142 	  continue;
143 	}
144 
145       id = get_identifier (c_common_reswords[i].word);
146       C_SET_RID_CODE (id, c_common_reswords[i].rid);
147       C_IS_RESERVED_WORD (id) = 1;
148       ridpointers [(int) c_common_reswords[i].rid] = id;
149     }
150 
151   for (i = 0; i < NUM_INT_N_ENTS; i++)
152     {
153       /* We always create the symbols but they aren't always supported.  */
154       char name[50];
155       sprintf (name, "__int%d", int_n_data[i].bitsize);
156       id = get_identifier (name);
157       C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
158       C_IS_RESERVED_WORD (id) = 1;
159     }
160 }
161 
162 /* A parser structure recording information about the state and
163    context of parsing.  Includes lexer information with up to two
164    tokens of look-ahead; more are not needed for C.  */
165 struct GTY(()) c_parser {
166   /* The look-ahead tokens.  */
167   c_token * GTY((skip)) tokens;
168   /* Buffer for look-ahead tokens.  */
169   c_token tokens_buf[4];
170   /* How many look-ahead tokens are available (0 - 4, or
171      more if parsing from pre-lexed tokens).  */
172   unsigned int tokens_avail;
173   /* True if a syntax error is being recovered from; false otherwise.
174      c_parser_error sets this flag.  It should clear this flag when
175      enough tokens have been consumed to recover from the error.  */
176   BOOL_BITFIELD error : 1;
177   /* True if we're processing a pragma, and shouldn't automatically
178      consume CPP_PRAGMA_EOL.  */
179   BOOL_BITFIELD in_pragma : 1;
180   /* True if we're parsing the outermost block of an if statement.  */
181   BOOL_BITFIELD in_if_block : 1;
182   /* True if we want to lex an untranslated string.  */
183   BOOL_BITFIELD lex_untranslated_string : 1;
184 
185   /* Objective-C specific parser/lexer information.  */
186 
187   /* True if we are in a context where the Objective-C "PQ" keywords
188      are considered keywords.  */
189   BOOL_BITFIELD objc_pq_context : 1;
190   /* True if we are parsing a (potential) Objective-C foreach
191      statement.  This is set to true after we parsed 'for (' and while
192      we wait for 'in' or ';' to decide if it's a standard C for loop or an
193      Objective-C foreach loop.  */
194   BOOL_BITFIELD objc_could_be_foreach_context : 1;
195   /* The following flag is needed to contextualize Objective-C lexical
196      analysis.  In some cases (e.g., 'int NSObject;'), it is
197      undesirable to bind an identifier to an Objective-C class, even
198      if a class with that name exists.  */
199   BOOL_BITFIELD objc_need_raw_identifier : 1;
200   /* Nonzero if we're processing a __transaction statement.  The value
201      is 1 | TM_STMT_ATTR_*.  */
202   unsigned int in_transaction : 4;
203   /* True if we are in a context where the Objective-C "Property attribute"
204      keywords are valid.  */
205   BOOL_BITFIELD objc_property_attr_context : 1;
206 
207   /* Location of the last consumed token.  */
208   location_t last_token_location;
209 };
210 
211 /* Return a pointer to the Nth token in PARSERs tokens_buf.  */
212 
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     case RID_ALIGNAS:
508       return true;
509     default:
510       if (keyword >= RID_FIRST_INT_N
511 	  && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
512 	  && int_n_enabled_p[keyword - RID_FIRST_INT_N])
513 	return true;
514       return false;
515     }
516 }
517 
518 /* Return true if TOKEN can start a type name,
519    false otherwise.  */
520 bool
521 c_token_starts_typename (c_token *token)
522 {
523   switch (token->type)
524     {
525     case CPP_NAME:
526       switch (token->id_kind)
527 	{
528 	case C_ID_ID:
529 	  return false;
530 	case C_ID_ADDRSPACE:
531 	  return true;
532 	case C_ID_TYPENAME:
533 	  return true;
534 	case C_ID_CLASSNAME:
535 	  gcc_assert (c_dialect_objc ());
536 	  return true;
537 	default:
538 	  gcc_unreachable ();
539 	}
540     case CPP_KEYWORD:
541       return c_keyword_starts_typename (token->keyword);
542     case CPP_LESS:
543       if (c_dialect_objc ())
544 	return true;
545       return false;
546     default:
547       return false;
548     }
549 }
550 
551 /* Return true if the next token from PARSER can start a type name,
552    false otherwise.  LA specifies how to do lookahead in order to
553    detect unknown type names.  If unsure, pick CLA_PREFER_ID.  */
554 
555 static inline bool
556 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
557 {
558   c_token *token = c_parser_peek_token (parser);
559   if (c_token_starts_typename (token))
560     return true;
561 
562   /* Try a bit harder to detect an unknown typename.  */
563   if (la != cla_prefer_id
564       && token->type == CPP_NAME
565       && token->id_kind == C_ID_ID
566 
567       /* Do not try too hard when we could have "object in array".  */
568       && !parser->objc_could_be_foreach_context
569 
570       && (la == cla_prefer_type
571 	  || c_parser_peek_2nd_token (parser)->type == CPP_NAME
572 	  || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
573 
574       /* Only unknown identifiers.  */
575       && !lookup_name (token->value))
576     return true;
577 
578   return false;
579 }
580 
581 /* Return true if TOKEN is a type qualifier, false otherwise.  */
582 static bool
583 c_token_is_qualifier (c_token *token)
584 {
585   switch (token->type)
586     {
587     case CPP_NAME:
588       switch (token->id_kind)
589 	{
590 	case C_ID_ADDRSPACE:
591 	  return true;
592 	default:
593 	  return false;
594 	}
595     case CPP_KEYWORD:
596       switch (token->keyword)
597 	{
598 	case RID_CONST:
599 	case RID_VOLATILE:
600 	case RID_RESTRICT:
601 	case RID_ATTRIBUTE:
602 	case RID_ATOMIC:
603 	  return true;
604 	default:
605 	  return false;
606 	}
607     case CPP_LESS:
608       return false;
609     default:
610       gcc_unreachable ();
611     }
612 }
613 
614 /* Return true if the next token from PARSER is a type qualifier,
615    false otherwise.  */
616 static inline bool
617 c_parser_next_token_is_qualifier (c_parser *parser)
618 {
619   c_token *token = c_parser_peek_token (parser);
620   return c_token_is_qualifier (token);
621 }
622 
623 /* Return true if TOKEN can start declaration specifiers, false
624    otherwise.  */
625 static bool
626 c_token_starts_declspecs (c_token *token)
627 {
628   switch (token->type)
629     {
630     case CPP_NAME:
631       switch (token->id_kind)
632 	{
633 	case C_ID_ID:
634 	  return false;
635 	case C_ID_ADDRSPACE:
636 	  return true;
637 	case C_ID_TYPENAME:
638 	  return true;
639 	case C_ID_CLASSNAME:
640 	  gcc_assert (c_dialect_objc ());
641 	  return true;
642 	default:
643 	  gcc_unreachable ();
644 	}
645     case CPP_KEYWORD:
646       switch (token->keyword)
647 	{
648 	case RID_STATIC:
649 	case RID_EXTERN:
650 	case RID_REGISTER:
651 	case RID_TYPEDEF:
652 	case RID_INLINE:
653 	case RID_NORETURN:
654 	case RID_AUTO:
655 	case RID_THREAD:
656 	case RID_UNSIGNED:
657 	case RID_LONG:
658 	case RID_SHORT:
659 	case RID_SIGNED:
660 	case RID_COMPLEX:
661 	case RID_INT:
662 	case RID_CHAR:
663 	case RID_FLOAT:
664 	case RID_DOUBLE:
665 	case RID_VOID:
666 	case RID_DFLOAT32:
667 	case RID_DFLOAT64:
668 	case RID_DFLOAT128:
669 	CASE_RID_FLOATN_NX:
670 	case RID_BOOL:
671 	case RID_ENUM:
672 	case RID_STRUCT:
673 	case RID_UNION:
674 	case RID_TYPEOF:
675 	case RID_CONST:
676 	case RID_VOLATILE:
677 	case RID_RESTRICT:
678 	case RID_ATTRIBUTE:
679 	case RID_FRACT:
680 	case RID_ACCUM:
681 	case RID_SAT:
682 	case RID_ALIGNAS:
683 	case RID_ATOMIC:
684 	case RID_AUTO_TYPE:
685 	  return true;
686 	default:
687 	  if (token->keyword >= RID_FIRST_INT_N
688 	      && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
689 	      && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
690 	    return true;
691 	  return false;
692 	}
693     case CPP_LESS:
694       if (c_dialect_objc ())
695 	return true;
696       return false;
697     default:
698       return false;
699     }
700 }
701 
702 
703 /* Return true if TOKEN can start declaration specifiers or a static
704    assertion, false otherwise.  */
705 static bool
706 c_token_starts_declaration (c_token *token)
707 {
708   if (c_token_starts_declspecs (token)
709       || token->keyword == RID_STATIC_ASSERT)
710     return true;
711   else
712     return false;
713 }
714 
715 /* Return true if the next token from PARSER can start declaration
716    specifiers, false otherwise.  */
717 bool
718 c_parser_next_token_starts_declspecs (c_parser *parser)
719 {
720   c_token *token = c_parser_peek_token (parser);
721 
722   /* In Objective-C, a classname normally starts a declspecs unless it
723      is immediately followed by a dot.  In that case, it is the
724      Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
725      setter/getter on the class.  c_token_starts_declspecs() can't
726      differentiate between the two cases because it only checks the
727      current token, so we have a special check here.  */
728   if (c_dialect_objc ()
729       && token->type == CPP_NAME
730       && token->id_kind == C_ID_CLASSNAME
731       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
732     return false;
733 
734   return c_token_starts_declspecs (token);
735 }
736 
737 /* Return true if the next tokens from PARSER can start declaration
738    specifiers or a static assertion, false otherwise.  */
739 bool
740 c_parser_next_tokens_start_declaration (c_parser *parser)
741 {
742   c_token *token = c_parser_peek_token (parser);
743 
744   /* Same as above.  */
745   if (c_dialect_objc ()
746       && token->type == CPP_NAME
747       && token->id_kind == C_ID_CLASSNAME
748       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
749     return false;
750 
751   /* Labels do not start declarations.  */
752   if (token->type == CPP_NAME
753       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
754     return false;
755 
756   if (c_token_starts_declaration (token))
757     return true;
758 
759   if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
760     return true;
761 
762   return false;
763 }
764 
765 /* Consume the next token from PARSER.  */
766 
767 void
768 c_parser_consume_token (c_parser *parser)
769 {
770   gcc_assert (parser->tokens_avail >= 1);
771   gcc_assert (parser->tokens[0].type != CPP_EOF);
772   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
773   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
774   parser->last_token_location = parser->tokens[0].location;
775   if (parser->tokens != &parser->tokens_buf[0])
776     parser->tokens++;
777   else if (parser->tokens_avail == 2)
778     parser->tokens[0] = parser->tokens[1];
779   parser->tokens_avail--;
780 }
781 
782 /* Expect the current token to be a #pragma.  Consume it and remember
783    that we've begun parsing a pragma.  */
784 
785 static void
786 c_parser_consume_pragma (c_parser *parser)
787 {
788   gcc_assert (!parser->in_pragma);
789   gcc_assert (parser->tokens_avail >= 1);
790   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
791   if (parser->tokens != &parser->tokens_buf[0])
792     parser->tokens++;
793   else if (parser->tokens_avail == 2)
794     parser->tokens[0] = parser->tokens[1];
795   parser->tokens_avail--;
796   parser->in_pragma = true;
797 }
798 
799 /* Update the global input_location from TOKEN.  */
800 static inline void
801 c_parser_set_source_position_from_token (c_token *token)
802 {
803   if (token->type != CPP_EOF)
804     {
805       input_location = token->location;
806     }
807 }
808 
809 /* Helper function for c_parser_error.
810    Having peeked a token of kind TOK1_KIND that might signify
811    a conflict marker, peek successor tokens to determine
812    if we actually do have a conflict marker.
813    Specifically, we consider a run of 7 '<', '=' or '>' characters
814    at the start of a line as a conflict marker.
815    These come through the lexer as three pairs and a single,
816    e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
817    If it returns true, *OUT_LOC is written to with the location/range
818    of the marker.  */
819 
820 static bool
821 c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind,
822 			       location_t *out_loc)
823 {
824   c_token *token2 = c_parser_peek_2nd_token (parser);
825   if (token2->type != tok1_kind)
826     return false;
827   c_token *token3 = c_parser_peek_nth_token (parser, 3);
828   if (token3->type != tok1_kind)
829     return false;
830   c_token *token4 = c_parser_peek_nth_token (parser, 4);
831   if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind))
832     return false;
833 
834   /* It must be at the start of the line.  */
835   location_t start_loc = c_parser_peek_token (parser)->location;
836   if (LOCATION_COLUMN (start_loc) != 1)
837     return false;
838 
839   /* We have a conflict marker.  Construct a location of the form:
840        <<<<<<<
841        ^~~~~~~
842      with start == caret, finishing at the end of the marker.  */
843   location_t finish_loc = get_finish (token4->location);
844   *out_loc = make_location (start_loc, start_loc, finish_loc);
845 
846   return true;
847 }
848 
849 /* Issue a diagnostic of the form
850       FILE:LINE: MESSAGE before TOKEN
851    where TOKEN is the next token in the input stream of PARSER.
852    MESSAGE (specified by the caller) is usually of the form "expected
853    OTHER-TOKEN".
854 
855    Use RICHLOC as the location of the diagnostic.
856 
857    Do not issue a diagnostic if still recovering from an error.
858 
859    Return true iff an error was actually emitted.
860 
861    ??? This is taken from the C++ parser, but building up messages in
862    this way is not i18n-friendly and some other approach should be
863    used.  */
864 
865 static bool
866 c_parser_error_richloc (c_parser *parser, const char *gmsgid,
867 			rich_location *richloc)
868 {
869   c_token *token = c_parser_peek_token (parser);
870   if (parser->error)
871     return false;
872   parser->error = true;
873   if (!gmsgid)
874     return false;
875 
876   /* If this is actually a conflict marker, report it as such.  */
877   if (token->type == CPP_LSHIFT
878       || token->type == CPP_RSHIFT
879       || token->type == CPP_EQ_EQ)
880     {
881       location_t loc;
882       if (c_parser_peek_conflict_marker (parser, token->type, &loc))
883 	{
884 	  error_at (loc, "version control conflict marker in file");
885 	  return true;
886 	}
887     }
888 
889   c_parse_error (gmsgid,
890 		 /* Because c_parse_error does not understand
891 		    CPP_KEYWORD, keywords are treated like
892 		    identifiers.  */
893 		 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
894 		 /* ??? The C parser does not save the cpp flags of a
895 		    token, we need to pass 0 here and we will not get
896 		    the source spelling of some tokens but rather the
897 		    canonical spelling.  */
898 		 token->value, /*flags=*/0, richloc);
899   return true;
900 }
901 
902 /* As c_parser_error_richloc, but issue the message at the
903    location of PARSER's next token, or at input_location
904    if the next token is EOF.  */
905 
906 bool
907 c_parser_error (c_parser *parser, const char *gmsgid)
908 {
909   c_token *token = c_parser_peek_token (parser);
910   c_parser_set_source_position_from_token (token);
911   rich_location richloc (line_table, input_location);
912   return c_parser_error_richloc (parser, gmsgid, &richloc);
913 }
914 
915 /* Some tokens naturally come in pairs e.g.'(' and ')'.
916    This class is for tracking such a matching pair of symbols.
917    In particular, it tracks the location of the first token,
918    so that if the second token is missing, we can highlight the
919    location of the first token when notifying the user about the
920    problem.  */
921 
922 template <typename traits_t>
923 class token_pair
924 {
925  public:
926   /* token_pair's ctor.  */
927   token_pair () : m_open_loc (UNKNOWN_LOCATION) {}
928 
929   /* If the next token is the opening symbol for this pair, consume it and
930      return true.
931      Otherwise, issue an error and return false.
932      In either case, record the location of the opening token.  */
933 
934   bool require_open (c_parser *parser)
935   {
936     c_token *token = c_parser_peek_token (parser);
937     if (token)
938       m_open_loc = token->location;
939 
940     return c_parser_require (parser, traits_t::open_token_type,
941 			     traits_t::open_gmsgid);
942   }
943 
944   /* Consume the next token from PARSER, recording its location as
945      that of the opening token within the pair.  */
946 
947   void consume_open (c_parser *parser)
948   {
949     c_token *token = c_parser_peek_token (parser);
950     gcc_assert (token->type == traits_t::open_token_type);
951     m_open_loc = token->location;
952     c_parser_consume_token (parser);
953   }
954 
955   /* If the next token is the closing symbol for this pair, consume it
956      and return true.
957      Otherwise, issue an error, highlighting the location of the
958      corresponding opening token, and return false.  */
959 
960   bool require_close (c_parser *parser) const
961   {
962     return c_parser_require (parser, traits_t::close_token_type,
963 			     traits_t::close_gmsgid, m_open_loc);
964   }
965 
966   /* Like token_pair::require_close, except that tokens will be skipped
967      until the desired token is found.  An error message is still produced
968      if the next token is not as expected.  */
969 
970   void skip_until_found_close (c_parser *parser) const
971   {
972     c_parser_skip_until_found (parser, traits_t::close_token_type,
973 			       traits_t::close_gmsgid, m_open_loc);
974   }
975 
976  private:
977   location_t m_open_loc;
978 };
979 
980 /* Traits for token_pair<T> for tracking matching pairs of parentheses.  */
981 
982 struct matching_paren_traits
983 {
984   static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN;
985   static const char * const open_gmsgid;
986   static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN;
987   static const char * const close_gmsgid;
988 };
989 
990 const char * const matching_paren_traits::open_gmsgid = "expected %<(%>";
991 const char * const matching_paren_traits::close_gmsgid = "expected %<)%>";
992 
993 /* "matching_parens" is a token_pair<T> class for tracking matching
994    pairs of parentheses.  */
995 
996 typedef token_pair<matching_paren_traits> matching_parens;
997 
998 /* Traits for token_pair<T> for tracking matching pairs of braces.  */
999 
1000 struct matching_brace_traits
1001 {
1002   static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE;
1003   static const char * const open_gmsgid;
1004   static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE;
1005   static const char * const close_gmsgid;
1006 };
1007 
1008 const char * const matching_brace_traits::open_gmsgid = "expected %<{%>";
1009 const char * const matching_brace_traits::close_gmsgid = "expected %<}%>";
1010 
1011 /* "matching_braces" is a token_pair<T> class for tracking matching
1012    pairs of braces.  */
1013 
1014 typedef token_pair<matching_brace_traits> matching_braces;
1015 
1016 /* Get a description of the matching symbol to TYPE e.g. "(" for
1017    CPP_CLOSE_PAREN.  */
1018 
1019 static const char *
1020 get_matching_symbol (enum cpp_ttype type)
1021 {
1022   switch (type)
1023     {
1024     default:
1025       gcc_unreachable ();
1026       return "";
1027     case CPP_CLOSE_PAREN:
1028       return "(";
1029     case CPP_CLOSE_BRACE:
1030       return "{";
1031     }
1032 }
1033 
1034 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
1035    issue the error MSGID.  If MSGID is NULL then a message has already
1036    been produced and no message will be produced this time.  Returns
1037    true if found, false otherwise.
1038 
1039    If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1040    within any error as the location of an "opening" token matching
1041    the close token TYPE (e.g. the location of the '(' when TYPE is
1042    CPP_CLOSE_PAREN).
1043 
1044    If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1045    one type (e.g. "expected %<)%>") and thus it may be reasonable to
1046    attempt to generate a fix-it hint for the problem.
1047    Otherwise msgid describes multiple token types (e.g.
1048    "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1049    generate a fix-it hint.  */
1050 
1051 bool
1052 c_parser_require (c_parser *parser,
1053 		  enum cpp_ttype type,
1054 		  const char *msgid,
1055 		  location_t matching_location,
1056 		  bool type_is_unique)
1057 {
1058   if (c_parser_next_token_is (parser, type))
1059     {
1060       c_parser_consume_token (parser);
1061       return true;
1062     }
1063   else
1064     {
1065       location_t next_token_loc = c_parser_peek_token (parser)->location;
1066       gcc_rich_location richloc (next_token_loc);
1067 
1068       /* Potentially supply a fix-it hint, suggesting to add the
1069 	 missing token immediately after the *previous* token.
1070 	 This may move the primary location within richloc.  */
1071       if (!parser->error && type_is_unique)
1072 	maybe_suggest_missing_token_insertion (&richloc, type,
1073 					       parser->last_token_location);
1074 
1075       /* If matching_location != UNKNOWN_LOCATION, highlight it.
1076 	 Attempt to consolidate diagnostics by printing it as a
1077 	 secondary range within the main diagnostic.  */
1078       bool added_matching_location = false;
1079       if (matching_location != UNKNOWN_LOCATION)
1080 	added_matching_location
1081 	  = richloc.add_location_if_nearby (matching_location);
1082 
1083       if (c_parser_error_richloc (parser, msgid, &richloc))
1084 	/* If we weren't able to consolidate matching_location, then
1085 	   print it as a secondary diagnostic.  */
1086 	if (matching_location != UNKNOWN_LOCATION && !added_matching_location)
1087 	  inform (matching_location, "to match this %qs",
1088 		  get_matching_symbol (type));
1089 
1090       return false;
1091     }
1092 }
1093 
1094 /* If the next token is the indicated keyword, consume it.  Otherwise,
1095    issue the error MSGID.  Returns true if found, false otherwise.  */
1096 
1097 static bool
1098 c_parser_require_keyword (c_parser *parser,
1099 			  enum rid keyword,
1100 			  const char *msgid)
1101 {
1102   if (c_parser_next_token_is_keyword (parser, keyword))
1103     {
1104       c_parser_consume_token (parser);
1105       return true;
1106     }
1107   else
1108     {
1109       c_parser_error (parser, msgid);
1110       return false;
1111     }
1112 }
1113 
1114 /* Like c_parser_require, except that tokens will be skipped until the
1115    desired token is found.  An error message is still produced if the
1116    next token is not as expected.  If MSGID is NULL then a message has
1117    already been produced and no message will be produced this
1118    time.
1119 
1120    If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1121    within any error as the location of an "opening" token matching
1122    the close token TYPE (e.g. the location of the '(' when TYPE is
1123    CPP_CLOSE_PAREN).  */
1124 
1125 void
1126 c_parser_skip_until_found (c_parser *parser,
1127 			   enum cpp_ttype type,
1128 			   const char *msgid,
1129 			   location_t matching_location)
1130 {
1131   unsigned nesting_depth = 0;
1132 
1133   if (c_parser_require (parser, type, msgid, matching_location))
1134     return;
1135 
1136   /* Skip tokens until the desired token is found.  */
1137   while (true)
1138     {
1139       /* Peek at the next token.  */
1140       c_token *token = c_parser_peek_token (parser);
1141       /* If we've reached the token we want, consume it and stop.  */
1142       if (token->type == type && !nesting_depth)
1143 	{
1144 	  c_parser_consume_token (parser);
1145 	  break;
1146 	}
1147 
1148       /* If we've run out of tokens, stop.  */
1149       if (token->type == CPP_EOF)
1150 	return;
1151       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1152 	return;
1153       if (token->type == CPP_OPEN_BRACE
1154 	  || token->type == CPP_OPEN_PAREN
1155 	  || token->type == CPP_OPEN_SQUARE)
1156 	++nesting_depth;
1157       else if (token->type == CPP_CLOSE_BRACE
1158 	       || token->type == CPP_CLOSE_PAREN
1159 	       || token->type == CPP_CLOSE_SQUARE)
1160 	{
1161 	  if (nesting_depth-- == 0)
1162 	    break;
1163 	}
1164       /* Consume this token.  */
1165       c_parser_consume_token (parser);
1166     }
1167   parser->error = false;
1168 }
1169 
1170 /* Skip tokens until the end of a parameter is found, but do not
1171    consume the comma, semicolon or closing delimiter.  */
1172 
1173 static void
1174 c_parser_skip_to_end_of_parameter (c_parser *parser)
1175 {
1176   unsigned nesting_depth = 0;
1177 
1178   while (true)
1179     {
1180       c_token *token = c_parser_peek_token (parser);
1181       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
1182 	  && !nesting_depth)
1183 	break;
1184       /* If we've run out of tokens, stop.  */
1185       if (token->type == CPP_EOF)
1186 	return;
1187       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1188 	return;
1189       if (token->type == CPP_OPEN_BRACE
1190 	  || token->type == CPP_OPEN_PAREN
1191 	  || token->type == CPP_OPEN_SQUARE)
1192 	++nesting_depth;
1193       else if (token->type == CPP_CLOSE_BRACE
1194 	       || token->type == CPP_CLOSE_PAREN
1195 	       || token->type == CPP_CLOSE_SQUARE)
1196 	{
1197 	  if (nesting_depth-- == 0)
1198 	    break;
1199 	}
1200       /* Consume this token.  */
1201       c_parser_consume_token (parser);
1202     }
1203   parser->error = false;
1204 }
1205 
1206 /* Expect to be at the end of the pragma directive and consume an
1207    end of line marker.  */
1208 
1209 static void
1210 c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
1211 {
1212   gcc_assert (parser->in_pragma);
1213   parser->in_pragma = false;
1214 
1215   if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
1216     c_parser_error (parser, "expected end of line");
1217 
1218   cpp_ttype token_type;
1219   do
1220     {
1221       c_token *token = c_parser_peek_token (parser);
1222       token_type = token->type;
1223       if (token_type == CPP_EOF)
1224 	break;
1225       c_parser_consume_token (parser);
1226     }
1227   while (token_type != CPP_PRAGMA_EOL);
1228 
1229   parser->error = false;
1230 }
1231 
1232 /* Skip tokens until we have consumed an entire block, or until we
1233    have consumed a non-nested ';'.  */
1234 
1235 static void
1236 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1237 {
1238   unsigned nesting_depth = 0;
1239   bool save_error = parser->error;
1240 
1241   while (true)
1242     {
1243       c_token *token;
1244 
1245       /* Peek at the next token.  */
1246       token = c_parser_peek_token (parser);
1247 
1248       switch (token->type)
1249 	{
1250 	case CPP_EOF:
1251 	  return;
1252 
1253 	case CPP_PRAGMA_EOL:
1254 	  if (parser->in_pragma)
1255 	    return;
1256 	  break;
1257 
1258 	case CPP_SEMICOLON:
1259 	  /* If the next token is a ';', we have reached the
1260 	     end of the statement.  */
1261 	  if (!nesting_depth)
1262 	    {
1263 	      /* Consume the ';'.  */
1264 	      c_parser_consume_token (parser);
1265 	      goto finished;
1266 	    }
1267 	  break;
1268 
1269 	case CPP_CLOSE_BRACE:
1270 	  /* If the next token is a non-nested '}', then we have
1271 	     reached the end of the current block.  */
1272 	  if (nesting_depth == 0 || --nesting_depth == 0)
1273 	    {
1274 	      c_parser_consume_token (parser);
1275 	      goto finished;
1276 	    }
1277 	  break;
1278 
1279 	case CPP_OPEN_BRACE:
1280 	  /* If it the next token is a '{', then we are entering a new
1281 	     block.  Consume the entire block.  */
1282 	  ++nesting_depth;
1283 	  break;
1284 
1285 	case CPP_PRAGMA:
1286 	  /* If we see a pragma, consume the whole thing at once.  We
1287 	     have some safeguards against consuming pragmas willy-nilly.
1288 	     Normally, we'd expect to be here with parser->error set,
1289 	     which disables these safeguards.  But it's possible to get
1290 	     here for secondary error recovery, after parser->error has
1291 	     been cleared.  */
1292 	  c_parser_consume_pragma (parser);
1293 	  c_parser_skip_to_pragma_eol (parser);
1294 	  parser->error = save_error;
1295 	  continue;
1296 
1297 	default:
1298 	  break;
1299 	}
1300 
1301       c_parser_consume_token (parser);
1302     }
1303 
1304  finished:
1305   parser->error = false;
1306 }
1307 
1308 /* CPP's options (initialized by c-opts.c).  */
1309 extern cpp_options *cpp_opts;
1310 
1311 /* Save the warning flags which are controlled by __extension__.  */
1312 
1313 static inline int
1314 disable_extension_diagnostics (void)
1315 {
1316   int ret = (pedantic
1317 	     | (warn_pointer_arith << 1)
1318 	     | (warn_traditional << 2)
1319 	     | (flag_iso << 3)
1320 	     | (warn_long_long << 4)
1321 	     | (warn_cxx_compat << 5)
1322 	     | (warn_overlength_strings << 6)
1323 	     /* warn_c90_c99_compat has three states: -1/0/1, so we must
1324 		play tricks to properly restore it.  */
1325 	     | ((warn_c90_c99_compat == 1) << 7)
1326 	     | ((warn_c90_c99_compat == -1) << 8)
1327 	     /* Similarly for warn_c99_c11_compat.  */
1328 	     | ((warn_c99_c11_compat == 1) << 9)
1329 	     | ((warn_c99_c11_compat == -1) << 10)
1330 	     );
1331   cpp_opts->cpp_pedantic = pedantic = 0;
1332   warn_pointer_arith = 0;
1333   cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1334   flag_iso = 0;
1335   cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1336   warn_cxx_compat = 0;
1337   warn_overlength_strings = 0;
1338   warn_c90_c99_compat = 0;
1339   warn_c99_c11_compat = 0;
1340   return ret;
1341 }
1342 
1343 /* Restore the warning flags which are controlled by __extension__.
1344    FLAGS is the return value from disable_extension_diagnostics.  */
1345 
1346 static inline void
1347 restore_extension_diagnostics (int flags)
1348 {
1349   cpp_opts->cpp_pedantic = pedantic = flags & 1;
1350   warn_pointer_arith = (flags >> 1) & 1;
1351   cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1352   flag_iso = (flags >> 3) & 1;
1353   cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1354   warn_cxx_compat = (flags >> 5) & 1;
1355   warn_overlength_strings = (flags >> 6) & 1;
1356   /* See above for why is this needed.  */
1357   warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1358   warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1359 }
1360 
1361 /* Helper data structure for parsing #pragma acc routine.  */
1362 struct oacc_routine_data {
1363   bool error_seen; /* Set if error has been reported.  */
1364   bool fndecl_seen; /* Set if one fn decl/definition has been seen already.  */
1365   tree clauses;
1366   location_t loc;
1367 };
1368 
1369 static void c_parser_external_declaration (c_parser *);
1370 static void c_parser_asm_definition (c_parser *);
1371 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1372 					   bool, bool, tree *, vec<c_token>,
1373 					   struct oacc_routine_data * = NULL,
1374 					   bool * = NULL);
1375 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1376 static void c_parser_static_assert_declaration (c_parser *);
1377 static struct c_typespec c_parser_enum_specifier (c_parser *);
1378 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1379 static tree c_parser_struct_declaration (c_parser *);
1380 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1381 static tree c_parser_alignas_specifier (c_parser *);
1382 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1383 							c_dtr_syn, bool *);
1384 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1385 							      bool,
1386 							      struct c_declarator *);
1387 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1388 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1389 							  tree);
1390 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1391 static tree c_parser_simple_asm_expr (c_parser *);
1392 static tree c_parser_attributes (c_parser *);
1393 static struct c_expr c_parser_initializer (c_parser *);
1394 static struct c_expr c_parser_braced_init (c_parser *, tree, bool,
1395 					   struct obstack *);
1396 static void c_parser_initelt (c_parser *, struct obstack *);
1397 static void c_parser_initval (c_parser *, struct c_expr *,
1398 			      struct obstack *);
1399 static tree c_parser_compound_statement (c_parser *);
1400 static void c_parser_compound_statement_nostart (c_parser *);
1401 static void c_parser_label (c_parser *);
1402 static void c_parser_statement (c_parser *, bool *, location_t * = NULL);
1403 static void c_parser_statement_after_labels (c_parser *, bool *,
1404 					     vec<tree> * = NULL);
1405 static tree c_parser_c99_block_statement (c_parser *, bool *,
1406 					  location_t * = NULL);
1407 static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
1408 static void c_parser_switch_statement (c_parser *, bool *);
1409 static void c_parser_while_statement (c_parser *, bool, unsigned short, bool *);
1410 static void c_parser_do_statement (c_parser *, bool, unsigned short);
1411 static void c_parser_for_statement (c_parser *, bool, unsigned short, bool *);
1412 static tree c_parser_asm_statement (c_parser *);
1413 static tree c_parser_asm_operands (c_parser *);
1414 static tree c_parser_asm_goto_operands (c_parser *);
1415 static tree c_parser_asm_clobbers (c_parser *);
1416 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1417 					      tree = NULL_TREE);
1418 static struct c_expr c_parser_conditional_expression (c_parser *,
1419 						      struct c_expr *, tree);
1420 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1421 						 tree);
1422 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1423 static struct c_expr c_parser_unary_expression (c_parser *);
1424 static struct c_expr c_parser_sizeof_expression (c_parser *);
1425 static struct c_expr c_parser_alignof_expression (c_parser *);
1426 static struct c_expr c_parser_postfix_expression (c_parser *);
1427 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1428 								   struct c_type_name *,
1429 								   location_t);
1430 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1431 								location_t loc,
1432 								struct c_expr);
1433 static tree c_parser_transaction (c_parser *, enum rid);
1434 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1435 static tree c_parser_transaction_cancel (c_parser *);
1436 static struct c_expr c_parser_expression (c_parser *);
1437 static struct c_expr c_parser_expression_conv (c_parser *);
1438 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1439 					     vec<tree, va_gc> **, location_t *,
1440 					     tree *, vec<location_t> *,
1441 					     unsigned int * = NULL);
1442 static void c_parser_oacc_declare (c_parser *);
1443 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1444 static void c_parser_oacc_update (c_parser *);
1445 static void c_parser_omp_construct (c_parser *, bool *);
1446 static void c_parser_omp_threadprivate (c_parser *);
1447 static void c_parser_omp_barrier (c_parser *);
1448 static void c_parser_omp_flush (c_parser *);
1449 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1450 				   tree, tree *, bool *);
1451 static void c_parser_omp_taskwait (c_parser *);
1452 static void c_parser_omp_taskyield (c_parser *);
1453 static void c_parser_omp_cancel (c_parser *);
1454 
1455 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1456 		      pragma_stmt, pragma_compound };
1457 static bool c_parser_pragma (c_parser *, enum pragma_context, bool *);
1458 static void c_parser_omp_cancellation_point (c_parser *, enum pragma_context);
1459 static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
1460 static void c_parser_omp_end_declare_target (c_parser *);
1461 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1462 static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
1463 static void c_parser_oacc_routine (c_parser *, enum pragma_context);
1464 
1465 /* These Objective-C parser functions are only ever called when
1466    compiling Objective-C.  */
1467 static void c_parser_objc_class_definition (c_parser *, tree);
1468 static void c_parser_objc_class_instance_variables (c_parser *);
1469 static void c_parser_objc_class_declaration (c_parser *);
1470 static void c_parser_objc_alias_declaration (c_parser *);
1471 static void c_parser_objc_protocol_definition (c_parser *, tree);
1472 static bool c_parser_objc_method_type (c_parser *);
1473 static void c_parser_objc_method_definition (c_parser *);
1474 static void c_parser_objc_methodprotolist (c_parser *);
1475 static void c_parser_objc_methodproto (c_parser *);
1476 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1477 static tree c_parser_objc_type_name (c_parser *);
1478 static tree c_parser_objc_protocol_refs (c_parser *);
1479 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1480 static void c_parser_objc_synchronized_statement (c_parser *);
1481 static tree c_parser_objc_selector (c_parser *);
1482 static tree c_parser_objc_selector_arg (c_parser *);
1483 static tree c_parser_objc_receiver (c_parser *);
1484 static tree c_parser_objc_message_args (c_parser *);
1485 static tree c_parser_objc_keywordexpr (c_parser *);
1486 static void c_parser_objc_at_property_declaration (c_parser *);
1487 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1488 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1489 static bool c_parser_objc_diagnose_bad_element_prefix
1490   (c_parser *, struct c_declspecs *);
1491 
1492 static void c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass);
1493 
1494 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1495 
1496    translation-unit:
1497      external-declarations
1498 
1499    external-declarations:
1500      external-declaration
1501      external-declarations external-declaration
1502 
1503    GNU extensions:
1504 
1505    translation-unit:
1506      empty
1507 */
1508 
1509 static void
1510 c_parser_translation_unit (c_parser *parser)
1511 {
1512   if (c_parser_next_token_is (parser, CPP_EOF))
1513     {
1514       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1515 	       "ISO C forbids an empty translation unit");
1516     }
1517   else
1518     {
1519       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1520       mark_valid_location_for_stdc_pragma (false);
1521       do
1522 	{
1523 	  ggc_collect ();
1524 	  c_parser_external_declaration (parser);
1525 	  obstack_free (&parser_obstack, obstack_position);
1526 	}
1527       while (c_parser_next_token_is_not (parser, CPP_EOF));
1528     }
1529 
1530   unsigned int i;
1531   tree decl;
1532   FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl)
1533     if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node)
1534       error ("storage size of %q+D isn%'t known", decl);
1535 }
1536 
1537 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1538 
1539    external-declaration:
1540      function-definition
1541      declaration
1542 
1543    GNU extensions:
1544 
1545    external-declaration:
1546      asm-definition
1547      ;
1548      __extension__ external-declaration
1549 
1550    Objective-C:
1551 
1552    external-declaration:
1553      objc-class-definition
1554      objc-class-declaration
1555      objc-alias-declaration
1556      objc-protocol-definition
1557      objc-method-definition
1558      @end
1559 */
1560 
1561 static void
1562 c_parser_external_declaration (c_parser *parser)
1563 {
1564   int ext;
1565   switch (c_parser_peek_token (parser)->type)
1566     {
1567     case CPP_KEYWORD:
1568       switch (c_parser_peek_token (parser)->keyword)
1569 	{
1570 	case RID_EXTENSION:
1571 	  ext = disable_extension_diagnostics ();
1572 	  c_parser_consume_token (parser);
1573 	  c_parser_external_declaration (parser);
1574 	  restore_extension_diagnostics (ext);
1575 	  break;
1576 	case RID_ASM:
1577 	  c_parser_asm_definition (parser);
1578 	  break;
1579 	case RID_AT_INTERFACE:
1580 	case RID_AT_IMPLEMENTATION:
1581 	  gcc_assert (c_dialect_objc ());
1582 	  c_parser_objc_class_definition (parser, NULL_TREE);
1583 	  break;
1584 	case RID_AT_CLASS:
1585 	  gcc_assert (c_dialect_objc ());
1586 	  c_parser_objc_class_declaration (parser);
1587 	  break;
1588 	case RID_AT_ALIAS:
1589 	  gcc_assert (c_dialect_objc ());
1590 	  c_parser_objc_alias_declaration (parser);
1591 	  break;
1592 	case RID_AT_PROTOCOL:
1593 	  gcc_assert (c_dialect_objc ());
1594 	  c_parser_objc_protocol_definition (parser, NULL_TREE);
1595 	  break;
1596 	case RID_AT_PROPERTY:
1597 	  gcc_assert (c_dialect_objc ());
1598 	  c_parser_objc_at_property_declaration (parser);
1599 	  break;
1600 	case RID_AT_SYNTHESIZE:
1601 	  gcc_assert (c_dialect_objc ());
1602 	  c_parser_objc_at_synthesize_declaration (parser);
1603 	  break;
1604 	case RID_AT_DYNAMIC:
1605 	  gcc_assert (c_dialect_objc ());
1606 	  c_parser_objc_at_dynamic_declaration (parser);
1607 	  break;
1608 	case RID_AT_END:
1609 	  gcc_assert (c_dialect_objc ());
1610 	  c_parser_consume_token (parser);
1611 	  objc_finish_implementation ();
1612 	  break;
1613 	default:
1614 	  goto decl_or_fndef;
1615 	}
1616       break;
1617     case CPP_SEMICOLON:
1618       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1619 	       "ISO C does not allow extra %<;%> outside of a function");
1620       c_parser_consume_token (parser);
1621       break;
1622     case CPP_PRAGMA:
1623       mark_valid_location_for_stdc_pragma (true);
1624       c_parser_pragma (parser, pragma_external, NULL);
1625       mark_valid_location_for_stdc_pragma (false);
1626       break;
1627     case CPP_PLUS:
1628     case CPP_MINUS:
1629       if (c_dialect_objc ())
1630 	{
1631 	  c_parser_objc_method_definition (parser);
1632 	  break;
1633 	}
1634       /* Else fall through, and yield a syntax error trying to parse
1635 	 as a declaration or function definition.  */
1636       /* FALLTHRU */
1637     default:
1638     decl_or_fndef:
1639       /* A declaration or a function definition (or, in Objective-C,
1640 	 an @interface or @protocol with prefix attributes).  We can
1641 	 only tell which after parsing the declaration specifiers, if
1642 	 any, and the first declarator.  */
1643       c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1644 				     NULL, vNULL);
1645       break;
1646     }
1647 }
1648 
1649 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1650 static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool);
1651 
1652 /* Build and add a DEBUG_BEGIN_STMT statement with location LOC.  */
1653 
1654 static void
1655 add_debug_begin_stmt (location_t loc)
1656 {
1657   /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721.  */
1658   if (!MAY_HAVE_DEBUG_MARKER_STMTS || !building_stmt_list_p ())
1659     return;
1660 
1661   tree stmt = build0 (DEBUG_BEGIN_STMT, void_type_node);
1662   SET_EXPR_LOCATION (stmt, loc);
1663   add_stmt (stmt);
1664 }
1665 
1666 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1667    6.7, 6.9.1, C11 6.7, 6.9.1).  If FNDEF_OK is true, a function definition
1668    is accepted; otherwise (old-style parameter declarations) only other
1669    declarations are accepted.  If STATIC_ASSERT_OK is true, a static
1670    assertion is accepted; otherwise (old-style parameter declarations)
1671    it is not.  If NESTED is true, we are inside a function or parsing
1672    old-style parameter declarations; any functions encountered are
1673    nested functions and declaration specifiers are required; otherwise
1674    we are at top level and functions are normal functions and
1675    declaration specifiers may be optional.  If EMPTY_OK is true, empty
1676    declarations are OK (subject to all other constraints); otherwise
1677    (old-style parameter declarations) they are diagnosed.  If
1678    START_ATTR_OK is true, the declaration specifiers may start with
1679    attributes; otherwise they may not.
1680    OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1681    declaration when parsing an Objective-C foreach statement.
1682    FALLTHRU_ATTR_P is used to signal whether this function parsed
1683    "__attribute__((fallthrough));".
1684 
1685    declaration:
1686      declaration-specifiers init-declarator-list[opt] ;
1687      static_assert-declaration
1688 
1689    function-definition:
1690      declaration-specifiers[opt] declarator declaration-list[opt]
1691        compound-statement
1692 
1693    declaration-list:
1694      declaration
1695      declaration-list declaration
1696 
1697    init-declarator-list:
1698      init-declarator
1699      init-declarator-list , init-declarator
1700 
1701    init-declarator:
1702      declarator simple-asm-expr[opt] attributes[opt]
1703      declarator simple-asm-expr[opt] attributes[opt] = initializer
1704 
1705    GNU extensions:
1706 
1707    nested-function-definition:
1708      declaration-specifiers declarator declaration-list[opt]
1709        compound-statement
1710 
1711    attribute ;
1712 
1713    Objective-C:
1714      attributes objc-class-definition
1715      attributes objc-category-definition
1716      attributes objc-protocol-definition
1717 
1718    The simple-asm-expr and attributes are GNU extensions.
1719 
1720    This function does not handle __extension__; that is handled in its
1721    callers.  ??? Following the old parser, __extension__ may start
1722    external declarations, declarations in functions and declarations
1723    at the start of "for" loops, but not old-style parameter
1724    declarations.
1725 
1726    C99 requires declaration specifiers in a function definition; the
1727    absence is diagnosed through the diagnosis of implicit int.  In GNU
1728    C we also allow but diagnose declarations without declaration
1729    specifiers, but only at top level (elsewhere they conflict with
1730    other syntax).
1731 
1732    In Objective-C, declarations of the looping variable in a foreach
1733    statement are exceptionally terminated by 'in' (for example, 'for
1734    (NSObject *object in array) { ... }').
1735 
1736    OpenMP:
1737 
1738    declaration:
1739      threadprivate-directive
1740 
1741    GIMPLE:
1742 
1743    gimple-function-definition:
1744      declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1745        declaration-list[opt] compound-statement
1746 
1747    rtl-function-definition:
1748      declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1749        declaration-list[opt] compound-statement  */
1750 
1751 static void
1752 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1753 			       bool static_assert_ok, bool empty_ok,
1754 			       bool nested, bool start_attr_ok,
1755 			       tree *objc_foreach_object_declaration,
1756 			       vec<c_token> omp_declare_simd_clauses,
1757 			       struct oacc_routine_data *oacc_routine_data,
1758 			       bool *fallthru_attr_p)
1759 {
1760   struct c_declspecs *specs;
1761   tree prefix_attrs;
1762   tree all_prefix_attrs;
1763   bool diagnosed_no_specs = false;
1764   location_t here = c_parser_peek_token (parser)->location;
1765 
1766   add_debug_begin_stmt (c_parser_peek_token (parser)->location);
1767 
1768   if (static_assert_ok
1769       && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1770     {
1771       c_parser_static_assert_declaration (parser);
1772       return;
1773     }
1774   specs = build_null_declspecs ();
1775 
1776   /* Try to detect an unknown type name when we have "A B" or "A *B".  */
1777   if (c_parser_peek_token (parser)->type == CPP_NAME
1778       && c_parser_peek_token (parser)->id_kind == C_ID_ID
1779       && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1780           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1781       && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1782     {
1783       tree name = c_parser_peek_token (parser)->value;
1784 
1785       /* Issue a warning about NAME being an unknown type name, perhaps
1786 	 with some kind of hint.
1787 	 If the user forgot a "struct" etc, suggest inserting
1788 	 it.  Otherwise, attempt to look for misspellings.  */
1789       gcc_rich_location richloc (here);
1790       if (tag_exists_p (RECORD_TYPE, name))
1791 	{
1792 	  /* This is not C++ with its implicit typedef.  */
1793 	  richloc.add_fixit_insert_before ("struct ");
1794 	  error_at (&richloc,
1795 		    "unknown type name %qE;"
1796 		    " use %<struct%> keyword to refer to the type",
1797 		    name);
1798 	}
1799       else if (tag_exists_p (UNION_TYPE, name))
1800 	{
1801 	  richloc.add_fixit_insert_before ("union ");
1802 	  error_at (&richloc,
1803 		    "unknown type name %qE;"
1804 		    " use %<union%> keyword to refer to the type",
1805 		    name);
1806 	}
1807       else if (tag_exists_p (ENUMERAL_TYPE, name))
1808 	{
1809 	  richloc.add_fixit_insert_before ("enum ");
1810 	  error_at (&richloc,
1811 		    "unknown type name %qE;"
1812 		    " use %<enum%> keyword to refer to the type",
1813 		    name);
1814 	}
1815       else
1816 	{
1817 	  name_hint hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME,
1818 					      here);
1819 	  if (hint)
1820 	    {
1821 	      richloc.add_fixit_replace (hint.suggestion ());
1822 	      error_at (&richloc,
1823 			"unknown type name %qE; did you mean %qs?",
1824 			name, hint.suggestion ());
1825 	    }
1826 	  else
1827 	    error_at (here, "unknown type name %qE", name);
1828 	}
1829 
1830       /* Parse declspecs normally to get a correct pointer type, but avoid
1831          a further "fails to be a type name" error.  Refuse nested functions
1832          since it is not how the user likely wants us to recover.  */
1833       c_parser_peek_token (parser)->type = CPP_KEYWORD;
1834       c_parser_peek_token (parser)->keyword = RID_VOID;
1835       c_parser_peek_token (parser)->value = error_mark_node;
1836       fndef_ok = !nested;
1837     }
1838 
1839   c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1840 		      true, true, cla_nonabstract_decl);
1841   if (parser->error)
1842     {
1843       c_parser_skip_to_end_of_block_or_statement (parser);
1844       return;
1845     }
1846   if (nested && !specs->declspecs_seen_p)
1847     {
1848       c_parser_error (parser, "expected declaration specifiers");
1849       c_parser_skip_to_end_of_block_or_statement (parser);
1850       return;
1851     }
1852 
1853   finish_declspecs (specs);
1854   bool auto_type_p = specs->typespec_word == cts_auto_type;
1855   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1856     {
1857       if (auto_type_p)
1858 	error_at (here, "%<__auto_type%> in empty declaration");
1859       else if (specs->typespec_kind == ctsk_none
1860 	       && attribute_fallthrough_p (specs->attrs))
1861 	{
1862 	  if (fallthru_attr_p != NULL)
1863 	    *fallthru_attr_p = true;
1864 	  tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH,
1865 						  void_type_node, 0);
1866 	  add_stmt (fn);
1867 	}
1868       else if (empty_ok)
1869 	shadow_tag (specs);
1870       else
1871 	{
1872 	  shadow_tag_warned (specs, 1);
1873 	  pedwarn (here, 0, "empty declaration");
1874 	}
1875       c_parser_consume_token (parser);
1876       if (oacc_routine_data)
1877 	c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1878       return;
1879     }
1880 
1881   /* Provide better error recovery.  Note that a type name here is usually
1882      better diagnosed as a redeclaration.  */
1883   if (empty_ok
1884       && specs->typespec_kind == ctsk_tagdef
1885       && c_parser_next_token_starts_declspecs (parser)
1886       && !c_parser_next_token_is (parser, CPP_NAME))
1887     {
1888       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1889       parser->error = false;
1890       shadow_tag_warned (specs, 1);
1891       return;
1892     }
1893   else if (c_dialect_objc () && !auto_type_p)
1894     {
1895       /* Prefix attributes are an error on method decls.  */
1896       switch (c_parser_peek_token (parser)->type)
1897 	{
1898 	  case CPP_PLUS:
1899 	  case CPP_MINUS:
1900 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1901 	      return;
1902 	    if (specs->attrs)
1903 	      {
1904 		warning_at (c_parser_peek_token (parser)->location,
1905 			    OPT_Wattributes,
1906 	       		    "prefix attributes are ignored for methods");
1907 		specs->attrs = NULL_TREE;
1908 	      }
1909 	    if (fndef_ok)
1910 	      c_parser_objc_method_definition (parser);
1911 	    else
1912 	      c_parser_objc_methodproto (parser);
1913 	    return;
1914 	    break;
1915 	  default:
1916 	    break;
1917 	}
1918       /* This is where we parse 'attributes @interface ...',
1919 	 'attributes @implementation ...', 'attributes @protocol ...'
1920 	 (where attributes could be, for example, __attribute__
1921 	 ((deprecated)).
1922       */
1923       switch (c_parser_peek_token (parser)->keyword)
1924 	{
1925 	case RID_AT_INTERFACE:
1926 	  {
1927 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1928 	      return;
1929 	    c_parser_objc_class_definition (parser, specs->attrs);
1930 	    return;
1931 	  }
1932 	  break;
1933 	case RID_AT_IMPLEMENTATION:
1934 	  {
1935 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1936 	      return;
1937 	    if (specs->attrs)
1938 	      {
1939 		warning_at (c_parser_peek_token (parser)->location,
1940 			OPT_Wattributes,
1941 			"prefix attributes are ignored for implementations");
1942 		specs->attrs = NULL_TREE;
1943 	      }
1944 	    c_parser_objc_class_definition (parser, NULL_TREE);
1945 	    return;
1946 	  }
1947 	  break;
1948 	case RID_AT_PROTOCOL:
1949 	  {
1950 	    if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1951 	      return;
1952 	    c_parser_objc_protocol_definition (parser, specs->attrs);
1953 	    return;
1954 	  }
1955 	  break;
1956 	case RID_AT_ALIAS:
1957 	case RID_AT_CLASS:
1958 	case RID_AT_END:
1959 	case RID_AT_PROPERTY:
1960 	  if (specs->attrs)
1961 	    {
1962 	      c_parser_error (parser, "unexpected attribute");
1963 	      specs->attrs = NULL;
1964 	    }
1965 	  break;
1966 	default:
1967 	  break;
1968 	}
1969     }
1970   else if (attribute_fallthrough_p (specs->attrs))
1971     warning_at (here, OPT_Wattributes,
1972 		"%<fallthrough%> attribute not followed by %<;%>");
1973 
1974   pending_xref_error ();
1975   prefix_attrs = specs->attrs;
1976   all_prefix_attrs = prefix_attrs;
1977   specs->attrs = NULL_TREE;
1978   while (true)
1979     {
1980       struct c_declarator *declarator;
1981       bool dummy = false;
1982       timevar_id_t tv;
1983       tree fnbody = NULL_TREE;
1984       /* Declaring either one or more declarators (in which case we
1985 	 should diagnose if there were no declaration specifiers) or a
1986 	 function definition (in which case the diagnostic for
1987 	 implicit int suffices).  */
1988       declarator = c_parser_declarator (parser,
1989 					specs->typespec_kind != ctsk_none,
1990 					C_DTR_NORMAL, &dummy);
1991       if (declarator == NULL)
1992 	{
1993 	  if (omp_declare_simd_clauses.exists ())
1994 	    c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1995 				       omp_declare_simd_clauses);
1996 	  if (oacc_routine_data)
1997 	    c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1998 	  c_parser_skip_to_end_of_block_or_statement (parser);
1999 	  return;
2000 	}
2001       if (auto_type_p && declarator->kind != cdk_id)
2002 	{
2003 	  error_at (here,
2004 		    "%<__auto_type%> requires a plain identifier"
2005 		    " as declarator");
2006 	  c_parser_skip_to_end_of_block_or_statement (parser);
2007 	  return;
2008 	}
2009       if (c_parser_next_token_is (parser, CPP_EQ)
2010 	  || c_parser_next_token_is (parser, CPP_COMMA)
2011 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
2012 	  || c_parser_next_token_is_keyword (parser, RID_ASM)
2013 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
2014 	  || c_parser_next_token_is_keyword (parser, RID_IN))
2015 	{
2016 	  tree asm_name = NULL_TREE;
2017 	  tree postfix_attrs = NULL_TREE;
2018 	  if (!diagnosed_no_specs && !specs->declspecs_seen_p)
2019 	    {
2020 	      diagnosed_no_specs = true;
2021 	      pedwarn (here, 0, "data definition has no type or storage class");
2022 	    }
2023 	  /* Having seen a data definition, there cannot now be a
2024 	     function definition.  */
2025 	  fndef_ok = false;
2026 	  if (c_parser_next_token_is_keyword (parser, RID_ASM))
2027 	    asm_name = c_parser_simple_asm_expr (parser);
2028 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2029 	    {
2030 	      postfix_attrs = c_parser_attributes (parser);
2031 	      if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2032 		{
2033 		  /* This means there is an attribute specifier after
2034 		     the declarator in a function definition.  Provide
2035 		     some more information for the user.  */
2036 		  error_at (here, "attributes should be specified before the "
2037 			    "declarator in a function definition");
2038 		  c_parser_skip_to_end_of_block_or_statement (parser);
2039 		  return;
2040 		}
2041 	    }
2042 	  if (c_parser_next_token_is (parser, CPP_EQ))
2043 	    {
2044 	      tree d;
2045 	      struct c_expr init;
2046 	      location_t init_loc;
2047 	      c_parser_consume_token (parser);
2048 	      if (auto_type_p)
2049 		{
2050 		  init_loc = c_parser_peek_token (parser)->location;
2051 		  rich_location richloc (line_table, init_loc);
2052 		  start_init (NULL_TREE, asm_name, global_bindings_p (), &richloc);
2053 		  /* A parameter is initialized, which is invalid.  Don't
2054 		     attempt to instrument the initializer.  */
2055 		  int flag_sanitize_save = flag_sanitize;
2056 		  if (nested && !empty_ok)
2057 		    flag_sanitize = 0;
2058 		  init = c_parser_expr_no_commas (parser, NULL);
2059 		  flag_sanitize = flag_sanitize_save;
2060 		  if (TREE_CODE (init.value) == COMPONENT_REF
2061 		      && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
2062 		    error_at (here,
2063 			      "%<__auto_type%> used with a bit-field"
2064 			      " initializer");
2065 		  init = convert_lvalue_to_rvalue (init_loc, init, true, true);
2066 		  tree init_type = TREE_TYPE (init.value);
2067 		  /* As with typeof, remove all qualifiers from atomic types.  */
2068 		  if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
2069 		    init_type
2070 		      = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
2071 		  bool vm_type = variably_modified_type_p (init_type,
2072 							   NULL_TREE);
2073 		  if (vm_type)
2074 		    init.value = save_expr (init.value);
2075 		  finish_init ();
2076 		  specs->typespec_kind = ctsk_typeof;
2077 		  specs->locations[cdw_typedef] = init_loc;
2078 		  specs->typedef_p = true;
2079 		  specs->type = init_type;
2080 		  if (vm_type)
2081 		    {
2082 		      bool maybe_const = true;
2083 		      tree type_expr = c_fully_fold (init.value, false,
2084 						     &maybe_const);
2085 		      specs->expr_const_operands &= maybe_const;
2086 		      if (specs->expr)
2087 			specs->expr = build2 (COMPOUND_EXPR,
2088 					      TREE_TYPE (type_expr),
2089 					      specs->expr, type_expr);
2090 		      else
2091 			specs->expr = type_expr;
2092 		    }
2093 		  d = start_decl (declarator, specs, true,
2094 				  chainon (postfix_attrs, all_prefix_attrs));
2095 		  if (!d)
2096 		    d = error_mark_node;
2097 		  if (omp_declare_simd_clauses.exists ())
2098 		    c_finish_omp_declare_simd (parser, d, NULL_TREE,
2099 					       omp_declare_simd_clauses);
2100 		}
2101 	      else
2102 		{
2103 		  /* The declaration of the variable is in effect while
2104 		     its initializer is parsed.  */
2105 		  d = start_decl (declarator, specs, true,
2106 				  chainon (postfix_attrs, all_prefix_attrs));
2107 		  if (!d)
2108 		    d = error_mark_node;
2109 		  if (omp_declare_simd_clauses.exists ())
2110 		    c_finish_omp_declare_simd (parser, d, NULL_TREE,
2111 					       omp_declare_simd_clauses);
2112 		  init_loc = c_parser_peek_token (parser)->location;
2113 		  rich_location richloc (line_table, init_loc);
2114 		  start_init (d, asm_name, global_bindings_p (), &richloc);
2115 		  /* A parameter is initialized, which is invalid.  Don't
2116 		     attempt to instrument the initializer.  */
2117 		  int flag_sanitize_save = flag_sanitize;
2118 		  if (TREE_CODE (d) == PARM_DECL)
2119 		    flag_sanitize = 0;
2120 		  init = c_parser_initializer (parser);
2121 		  flag_sanitize = flag_sanitize_save;
2122 		  finish_init ();
2123 		}
2124 	      if (oacc_routine_data)
2125 		c_finish_oacc_routine (oacc_routine_data, d, false);
2126 	      if (d != error_mark_node)
2127 		{
2128 		  maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
2129 		  finish_decl (d, init_loc, init.value,
2130 			       init.original_type, asm_name);
2131 		}
2132 	    }
2133 	  else
2134 	    {
2135 	      if (auto_type_p)
2136 		{
2137 		  error_at (here,
2138 			    "%<__auto_type%> requires an initialized "
2139 			    "data declaration");
2140 		  c_parser_skip_to_end_of_block_or_statement (parser);
2141 		  return;
2142 		}
2143 	      tree d = start_decl (declarator, specs, false,
2144 				   chainon (postfix_attrs,
2145 					    all_prefix_attrs));
2146 	      if (d && TREE_CODE (d) == FUNCTION_DECL)
2147 		if (declarator->kind == cdk_function)
2148 		  if (DECL_ARGUMENTS (d) == NULL_TREE)
2149 		    DECL_ARGUMENTS (d) = declarator->u.arg_info->parms;
2150 	      if (omp_declare_simd_clauses.exists ())
2151 		{
2152 		  tree parms = NULL_TREE;
2153 		  if (d && TREE_CODE (d) == FUNCTION_DECL)
2154 		    {
2155 		      struct c_declarator *ce = declarator;
2156 		      while (ce != NULL)
2157 			if (ce->kind == cdk_function)
2158 			  {
2159 			    parms = ce->u.arg_info->parms;
2160 			    break;
2161 			  }
2162 			else
2163 			  ce = ce->declarator;
2164 		    }
2165 		  if (parms)
2166 		    temp_store_parm_decls (d, parms);
2167 		  c_finish_omp_declare_simd (parser, d, parms,
2168 					     omp_declare_simd_clauses);
2169 		  if (parms)
2170 		    temp_pop_parm_decls ();
2171 		}
2172 	      if (oacc_routine_data)
2173 		c_finish_oacc_routine (oacc_routine_data, d, false);
2174 	      if (d)
2175 		finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
2176 			     NULL_TREE, asm_name);
2177 
2178 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
2179 		{
2180 		  if (d)
2181 		    *objc_foreach_object_declaration = d;
2182 		  else
2183 		    *objc_foreach_object_declaration = error_mark_node;
2184 		}
2185 	    }
2186 	  if (c_parser_next_token_is (parser, CPP_COMMA))
2187 	    {
2188 	      if (auto_type_p)
2189 		{
2190 		  error_at (here,
2191 			    "%<__auto_type%> may only be used with"
2192 			    " a single declarator");
2193 		  c_parser_skip_to_end_of_block_or_statement (parser);
2194 		  return;
2195 		}
2196 	      c_parser_consume_token (parser);
2197 	      if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2198 		all_prefix_attrs = chainon (c_parser_attributes (parser),
2199 					    prefix_attrs);
2200 	      else
2201 		all_prefix_attrs = prefix_attrs;
2202 	      continue;
2203 	    }
2204 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2205 	    {
2206 	      c_parser_consume_token (parser);
2207 	      return;
2208 	    }
2209 	  else if (c_parser_next_token_is_keyword (parser, RID_IN))
2210 	    {
2211 	      /* This can only happen in Objective-C: we found the
2212 		 'in' that terminates the declaration inside an
2213 		 Objective-C foreach statement.  Do not consume the
2214 		 token, so that the caller can use it to determine
2215 		 that this indeed is a foreach context.  */
2216 	      return;
2217 	    }
2218 	  else
2219 	    {
2220 	      c_parser_error (parser, "expected %<,%> or %<;%>");
2221 	      c_parser_skip_to_end_of_block_or_statement (parser);
2222 	      return;
2223 	    }
2224 	}
2225       else if (auto_type_p)
2226 	{
2227 	  error_at (here,
2228 		    "%<__auto_type%> requires an initialized data declaration");
2229 	  c_parser_skip_to_end_of_block_or_statement (parser);
2230 	  return;
2231 	}
2232       else if (!fndef_ok)
2233 	{
2234 	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
2235 			  "%<asm%> or %<__attribute__%>");
2236 	  c_parser_skip_to_end_of_block_or_statement (parser);
2237 	  return;
2238 	}
2239       /* Function definition (nested or otherwise).  */
2240       if (nested)
2241 	{
2242 	  pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
2243 	  c_push_function_context ();
2244 	}
2245       if (!start_function (specs, declarator, all_prefix_attrs))
2246 	{
2247 	  /* At this point we've consumed:
2248 	       declaration-specifiers declarator
2249 	     and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2250 	     RID_ASM, RID_ATTRIBUTE, or RID_IN,
2251 	     but the
2252 	       declaration-specifiers declarator
2253 	     aren't grokkable as a function definition, so we have
2254 	     an error.  */
2255 	  gcc_assert (!c_parser_next_token_is (parser, CPP_SEMICOLON));
2256 	  if (c_parser_next_token_starts_declspecs (parser))
2257 	    {
2258 	      /* If we have
2259 		   declaration-specifiers declarator decl-specs
2260 		 then assume we have a missing semicolon, which would
2261 		 give us:
2262 		   declaration-specifiers declarator  decl-specs
2263 						    ^
2264 						    ;
2265 		   <~~~~~~~~~ declaration ~~~~~~~~~~>
2266 		 Use c_parser_require to get an error with a fix-it hint.  */
2267 	      c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>");
2268 	      parser->error = false;
2269 	    }
2270 	  else
2271 	    {
2272 	      /* This can appear in many cases looking nothing like a
2273 		 function definition, so we don't give a more specific
2274 		 error suggesting there was one.  */
2275 	      c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2276 			      "or %<__attribute__%>");
2277 	    }
2278 	  if (nested)
2279 	    c_pop_function_context ();
2280 	  break;
2281 	}
2282 
2283       if (DECL_DECLARED_INLINE_P (current_function_decl))
2284         tv = TV_PARSE_INLINE;
2285       else
2286         tv = TV_PARSE_FUNC;
2287       auto_timevar at (g_timer, tv);
2288 
2289       /* Parse old-style parameter declarations.  ??? Attributes are
2290 	 not allowed to start declaration specifiers here because of a
2291 	 syntax conflict between a function declaration with attribute
2292 	 suffix and a function definition with an attribute prefix on
2293 	 first old-style parameter declaration.  Following the old
2294 	 parser, they are not accepted on subsequent old-style
2295 	 parameter declarations either.  However, there is no
2296 	 ambiguity after the first declaration, nor indeed on the
2297 	 first as long as we don't allow postfix attributes after a
2298 	 declarator with a nonempty identifier list in a definition;
2299 	 and postfix attributes have never been accepted here in
2300 	 function definitions either.  */
2301       while (c_parser_next_token_is_not (parser, CPP_EOF)
2302 	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
2303 	c_parser_declaration_or_fndef (parser, false, false, false,
2304 				       true, false, NULL, vNULL);
2305       store_parm_decls ();
2306       if (omp_declare_simd_clauses.exists ())
2307 	c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
2308 				   omp_declare_simd_clauses);
2309       if (oacc_routine_data)
2310 	c_finish_oacc_routine (oacc_routine_data, current_function_decl, true);
2311       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
2312 	= c_parser_peek_token (parser)->location;
2313 
2314       /* If the definition was marked with __GIMPLE then parse the
2315          function body as GIMPLE.  */
2316       if (specs->gimple_p)
2317 	{
2318 	  cfun->pass_startwith = specs->gimple_or_rtl_pass;
2319 	  bool saved = in_late_binary_op;
2320 	  in_late_binary_op = true;
2321 	  c_parser_parse_gimple_body (parser);
2322 	  in_late_binary_op = saved;
2323 	}
2324       /* Similarly, if it was marked with __RTL, use the RTL parser now,
2325 	 consuming the function body.  */
2326       else if (specs->rtl_p)
2327 	{
2328 	  c_parser_parse_rtl_body (parser, specs->gimple_or_rtl_pass);
2329 
2330 	  /* Normally, store_parm_decls sets next_is_function_body,
2331 	     anticipating a function body.  We need a push_scope/pop_scope
2332 	     pair to flush out this state, or subsequent function parsing
2333 	     will go wrong.  */
2334 	  push_scope ();
2335 	  pop_scope ();
2336 
2337 	  finish_function ();
2338 	  return;
2339 	}
2340       else
2341 	fnbody = c_parser_compound_statement (parser);
2342       tree fndecl = current_function_decl;
2343       if (nested)
2344 	{
2345 	  tree decl = current_function_decl;
2346 	  /* Mark nested functions as needing static-chain initially.
2347 	     lower_nested_functions will recompute it but the
2348 	     DECL_STATIC_CHAIN flag is also used before that happens,
2349 	     by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
2350 	  DECL_STATIC_CHAIN (decl) = 1;
2351 	  add_stmt (fnbody);
2352 	  finish_function ();
2353 	  c_pop_function_context ();
2354 	  add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
2355 	}
2356       else
2357 	{
2358 	  if (fnbody)
2359 	    add_stmt (fnbody);
2360 	  finish_function ();
2361 	}
2362       /* Get rid of the empty stmt list for GIMPLE.  */
2363       if (specs->gimple_p)
2364 	DECL_SAVED_TREE (fndecl) = NULL_TREE;
2365 
2366       break;
2367     }
2368 }
2369 
2370 /* Parse an asm-definition (asm() outside a function body).  This is a
2371    GNU extension.
2372 
2373    asm-definition:
2374      simple-asm-expr ;
2375 */
2376 
2377 static void
2378 c_parser_asm_definition (c_parser *parser)
2379 {
2380   tree asm_str = c_parser_simple_asm_expr (parser);
2381   if (asm_str)
2382     symtab->finalize_toplevel_asm (asm_str);
2383   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2384 }
2385 
2386 /* Parse a static assertion (C11 6.7.10).
2387 
2388    static_assert-declaration:
2389      static_assert-declaration-no-semi ;
2390 */
2391 
2392 static void
2393 c_parser_static_assert_declaration (c_parser *parser)
2394 {
2395   c_parser_static_assert_declaration_no_semi (parser);
2396   if (parser->error
2397       || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2398     c_parser_skip_to_end_of_block_or_statement (parser);
2399 }
2400 
2401 /* Parse a static assertion (C11 6.7.10), without the trailing
2402    semicolon.
2403 
2404    static_assert-declaration-no-semi:
2405      _Static_assert ( constant-expression , string-literal )
2406 */
2407 
2408 static void
2409 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2410 {
2411   location_t assert_loc, value_loc;
2412   tree value;
2413   tree string;
2414 
2415   gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2416   assert_loc = c_parser_peek_token (parser)->location;
2417   if (flag_isoc99)
2418     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2419 		 "ISO C99 does not support %<_Static_assert%>");
2420   else
2421     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2422 		 "ISO C90 does not support %<_Static_assert%>");
2423   c_parser_consume_token (parser);
2424   matching_parens parens;
2425   if (!parens.require_open (parser))
2426     return;
2427   location_t value_tok_loc = c_parser_peek_token (parser)->location;
2428   value = c_parser_expr_no_commas (parser, NULL).value;
2429   value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc);
2430   parser->lex_untranslated_string = true;
2431   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2432     {
2433       parser->lex_untranslated_string = false;
2434       return;
2435     }
2436   switch (c_parser_peek_token (parser)->type)
2437     {
2438     case CPP_STRING:
2439     case CPP_STRING16:
2440     case CPP_STRING32:
2441     case CPP_WSTRING:
2442     case CPP_UTF8STRING:
2443       string = c_parser_peek_token (parser)->value;
2444       c_parser_consume_token (parser);
2445       parser->lex_untranslated_string = false;
2446       break;
2447     default:
2448       c_parser_error (parser, "expected string literal");
2449       parser->lex_untranslated_string = false;
2450       return;
2451     }
2452   parens.require_close (parser);
2453 
2454   if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2455     {
2456       error_at (value_loc, "expression in static assertion is not an integer");
2457       return;
2458     }
2459   if (TREE_CODE (value) != INTEGER_CST)
2460     {
2461       value = c_fully_fold (value, false, NULL);
2462       /* Strip no-op conversions.  */
2463       STRIP_TYPE_NOPS (value);
2464       if (TREE_CODE (value) == INTEGER_CST)
2465 	pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2466 		 "is not an integer constant expression");
2467     }
2468   if (TREE_CODE (value) != INTEGER_CST)
2469     {
2470       error_at (value_loc, "expression in static assertion is not constant");
2471       return;
2472     }
2473   constant_expression_warning (value);
2474   if (integer_zerop (value))
2475     error_at (assert_loc, "static assertion failed: %E", string);
2476 }
2477 
2478 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2479    6.7, C11 6.7), adding them to SPECS (which may already include some).
2480    Storage class specifiers are accepted iff SCSPEC_OK; type
2481    specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2482    accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2483    iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2484 
2485    declaration-specifiers:
2486      storage-class-specifier declaration-specifiers[opt]
2487      type-specifier declaration-specifiers[opt]
2488      type-qualifier declaration-specifiers[opt]
2489      function-specifier declaration-specifiers[opt]
2490      alignment-specifier declaration-specifiers[opt]
2491 
2492    Function specifiers (inline) are from C99, and are currently
2493    handled as storage class specifiers, as is __thread.  Alignment
2494    specifiers are from C11.
2495 
2496    C90 6.5.1, C99 6.7.1, C11 6.7.1:
2497    storage-class-specifier:
2498      typedef
2499      extern
2500      static
2501      auto
2502      register
2503      _Thread_local
2504 
2505    (_Thread_local is new in C11.)
2506 
2507    C99 6.7.4, C11 6.7.4:
2508    function-specifier:
2509      inline
2510      _Noreturn
2511 
2512    (_Noreturn is new in C11.)
2513 
2514    C90 6.5.2, C99 6.7.2, C11 6.7.2:
2515    type-specifier:
2516      void
2517      char
2518      short
2519      int
2520      long
2521      float
2522      double
2523      signed
2524      unsigned
2525      _Bool
2526      _Complex
2527      [_Imaginary removed in C99 TC2]
2528      struct-or-union-specifier
2529      enum-specifier
2530      typedef-name
2531      atomic-type-specifier
2532 
2533    (_Bool and _Complex are new in C99.)
2534    (atomic-type-specifier is new in C11.)
2535 
2536    C90 6.5.3, C99 6.7.3, C11 6.7.3:
2537 
2538    type-qualifier:
2539      const
2540      restrict
2541      volatile
2542      address-space-qualifier
2543      _Atomic
2544 
2545    (restrict is new in C99.)
2546    (_Atomic is new in C11.)
2547 
2548    GNU extensions:
2549 
2550    declaration-specifiers:
2551      attributes declaration-specifiers[opt]
2552 
2553    type-qualifier:
2554      address-space
2555 
2556    address-space:
2557      identifier recognized by the target
2558 
2559    storage-class-specifier:
2560      __thread
2561 
2562    type-specifier:
2563      typeof-specifier
2564      __auto_type
2565      __intN
2566      _Decimal32
2567      _Decimal64
2568      _Decimal128
2569      _Fract
2570      _Accum
2571      _Sat
2572 
2573   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2574    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2575 
2576    atomic-type-specifier
2577     _Atomic ( type-name )
2578 
2579    Objective-C:
2580 
2581    type-specifier:
2582      class-name objc-protocol-refs[opt]
2583      typedef-name objc-protocol-refs
2584      objc-protocol-refs
2585 */
2586 
2587 void
2588 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2589 		    bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2590 		    bool alignspec_ok, bool auto_type_ok,
2591 		    enum c_lookahead_kind la)
2592 {
2593   bool attrs_ok = start_attr_ok;
2594   bool seen_type = specs->typespec_kind != ctsk_none;
2595 
2596   if (!typespec_ok)
2597     gcc_assert (la == cla_prefer_id);
2598 
2599   while (c_parser_next_token_is (parser, CPP_NAME)
2600 	 || c_parser_next_token_is (parser, CPP_KEYWORD)
2601 	 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2602     {
2603       struct c_typespec t;
2604       tree attrs;
2605       tree align;
2606       location_t loc = c_parser_peek_token (parser)->location;
2607 
2608       /* If we cannot accept a type, exit if the next token must start
2609 	 one.  Also, if we already have seen a tagged definition,
2610 	 a typename would be an error anyway and likely the user
2611 	 has simply forgotten a semicolon, so we exit.  */
2612       if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2613 	  && c_parser_next_tokens_start_typename (parser, la)
2614 	  && !c_parser_next_token_is_qualifier (parser)
2615 	  && !c_parser_next_token_is_keyword (parser, RID_ALIGNAS))
2616 	break;
2617 
2618       if (c_parser_next_token_is (parser, CPP_NAME))
2619 	{
2620 	  c_token *name_token = c_parser_peek_token (parser);
2621 	  tree value = name_token->value;
2622 	  c_id_kind kind = name_token->id_kind;
2623 
2624 	  if (kind == C_ID_ADDRSPACE)
2625 	    {
2626 	      addr_space_t as
2627 		= name_token->keyword - RID_FIRST_ADDR_SPACE;
2628 	      declspecs_add_addrspace (name_token->location, specs, as);
2629 	      c_parser_consume_token (parser);
2630 	      attrs_ok = true;
2631 	      continue;
2632 	    }
2633 
2634 	  gcc_assert (!c_parser_next_token_is_qualifier (parser));
2635 
2636 	  /* If we cannot accept a type, and the next token must start one,
2637 	     exit.  Do the same if we already have seen a tagged definition,
2638 	     since it would be an error anyway and likely the user has simply
2639 	     forgotten a semicolon.  */
2640 	  if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2641 	    break;
2642 
2643 	  /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2644 	     a C_ID_CLASSNAME.  */
2645 	  c_parser_consume_token (parser);
2646 	  seen_type = true;
2647 	  attrs_ok = true;
2648 	  if (kind == C_ID_ID)
2649 	    {
2650 	      error_at (loc, "unknown type name %qE", value);
2651 	      t.kind = ctsk_typedef;
2652 	      t.spec = error_mark_node;
2653 	    }
2654 	  else if (kind == C_ID_TYPENAME
2655 	           && (!c_dialect_objc ()
2656 	               || c_parser_next_token_is_not (parser, CPP_LESS)))
2657 	    {
2658 	      t.kind = ctsk_typedef;
2659 	      /* For a typedef name, record the meaning, not the name.
2660 		 In case of 'foo foo, bar;'.  */
2661 	      t.spec = lookup_name (value);
2662 	    }
2663 	  else
2664 	    {
2665 	      tree proto = NULL_TREE;
2666 	      gcc_assert (c_dialect_objc ());
2667 	      t.kind = ctsk_objc;
2668 	      if (c_parser_next_token_is (parser, CPP_LESS))
2669 		proto = c_parser_objc_protocol_refs (parser);
2670 	      t.spec = objc_get_protocol_qualified_type (value, proto);
2671 	    }
2672 	  t.expr = NULL_TREE;
2673 	  t.expr_const_operands = true;
2674 	  declspecs_add_type (name_token->location, specs, t);
2675 	  continue;
2676 	}
2677       if (c_parser_next_token_is (parser, CPP_LESS))
2678 	{
2679 	  /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2680 	     nisse@lysator.liu.se.  */
2681 	  tree proto;
2682 	  gcc_assert (c_dialect_objc ());
2683 	  if (!typespec_ok || seen_type)
2684 	    break;
2685 	  proto = c_parser_objc_protocol_refs (parser);
2686 	  t.kind = ctsk_objc;
2687 	  t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2688 	  t.expr = NULL_TREE;
2689 	  t.expr_const_operands = true;
2690 	  declspecs_add_type (loc, specs, t);
2691 	  continue;
2692 	}
2693       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2694       switch (c_parser_peek_token (parser)->keyword)
2695 	{
2696 	case RID_STATIC:
2697 	case RID_EXTERN:
2698 	case RID_REGISTER:
2699 	case RID_TYPEDEF:
2700 	case RID_INLINE:
2701 	case RID_NORETURN:
2702 	case RID_AUTO:
2703 	case RID_THREAD:
2704 	  if (!scspec_ok)
2705 	    goto out;
2706 	  attrs_ok = true;
2707 	  /* TODO: Distinguish between function specifiers (inline, noreturn)
2708 	     and storage class specifiers, either here or in
2709 	     declspecs_add_scspec.  */
2710 	  declspecs_add_scspec (loc, specs,
2711 				c_parser_peek_token (parser)->value);
2712 	  c_parser_consume_token (parser);
2713 	  break;
2714 	case RID_AUTO_TYPE:
2715 	  if (!auto_type_ok)
2716 	    goto out;
2717 	  /* Fall through.  */
2718 	case RID_UNSIGNED:
2719 	case RID_LONG:
2720 	case RID_SHORT:
2721 	case RID_SIGNED:
2722 	case RID_COMPLEX:
2723 	case RID_INT:
2724 	case RID_CHAR:
2725 	case RID_FLOAT:
2726 	case RID_DOUBLE:
2727 	case RID_VOID:
2728 	case RID_DFLOAT32:
2729 	case RID_DFLOAT64:
2730 	case RID_DFLOAT128:
2731 	CASE_RID_FLOATN_NX:
2732 	case RID_BOOL:
2733 	case RID_FRACT:
2734 	case RID_ACCUM:
2735 	case RID_SAT:
2736 	case RID_INT_N_0:
2737 	case RID_INT_N_1:
2738 	case RID_INT_N_2:
2739 	case RID_INT_N_3:
2740 	  if (!typespec_ok)
2741 	    goto out;
2742 	  attrs_ok = true;
2743 	  seen_type = true;
2744 	  if (c_dialect_objc ())
2745 	    parser->objc_need_raw_identifier = true;
2746 	  t.kind = ctsk_resword;
2747 	  t.spec = c_parser_peek_token (parser)->value;
2748 	  t.expr = NULL_TREE;
2749 	  t.expr_const_operands = true;
2750 	  declspecs_add_type (loc, specs, t);
2751 	  c_parser_consume_token (parser);
2752 	  break;
2753 	case RID_ENUM:
2754 	  if (!typespec_ok)
2755 	    goto out;
2756 	  attrs_ok = true;
2757 	  seen_type = true;
2758 	  t = c_parser_enum_specifier (parser);
2759           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2760 	  declspecs_add_type (loc, specs, t);
2761 	  break;
2762 	case RID_STRUCT:
2763 	case RID_UNION:
2764 	  if (!typespec_ok)
2765 	    goto out;
2766 	  attrs_ok = true;
2767 	  seen_type = true;
2768 	  t = c_parser_struct_or_union_specifier (parser);
2769           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2770 	  declspecs_add_type (loc, specs, t);
2771 	  break;
2772 	case RID_TYPEOF:
2773 	  /* ??? The old parser rejected typeof after other type
2774 	     specifiers, but is a syntax error the best way of
2775 	     handling this?  */
2776 	  if (!typespec_ok || seen_type)
2777 	    goto out;
2778 	  attrs_ok = true;
2779 	  seen_type = true;
2780 	  t = c_parser_typeof_specifier (parser);
2781 	  declspecs_add_type (loc, specs, t);
2782 	  break;
2783 	case RID_ATOMIC:
2784 	  /* C parser handling of Objective-C constructs needs
2785 	     checking for correct lvalue-to-rvalue conversions, and
2786 	     the code in build_modify_expr handling various
2787 	     Objective-C cases, and that in build_unary_op handling
2788 	     Objective-C cases for increment / decrement, also needs
2789 	     updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2790 	     and objc_types_are_equivalent may also need updates.  */
2791 	  if (c_dialect_objc ())
2792 	    sorry ("%<_Atomic%> in Objective-C");
2793 	  if (flag_isoc99)
2794 	    pedwarn_c99 (loc, OPT_Wpedantic,
2795 			 "ISO C99 does not support the %<_Atomic%> qualifier");
2796 	  else
2797 	    pedwarn_c99 (loc, OPT_Wpedantic,
2798 			 "ISO C90 does not support the %<_Atomic%> qualifier");
2799 	  attrs_ok = true;
2800 	  tree value;
2801 	  value = c_parser_peek_token (parser)->value;
2802 	  c_parser_consume_token (parser);
2803 	  if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2804 	    {
2805 	      /* _Atomic ( type-name ).  */
2806 	      seen_type = true;
2807 	      c_parser_consume_token (parser);
2808 	      struct c_type_name *type = c_parser_type_name (parser);
2809 	      t.kind = ctsk_typeof;
2810 	      t.spec = error_mark_node;
2811 	      t.expr = NULL_TREE;
2812 	      t.expr_const_operands = true;
2813 	      if (type != NULL)
2814 		t.spec = groktypename (type, &t.expr,
2815 				       &t.expr_const_operands);
2816 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2817 					 "expected %<)%>");
2818 	      if (t.spec != error_mark_node)
2819 		{
2820 		  if (TREE_CODE (t.spec) == ARRAY_TYPE)
2821 		    error_at (loc, "%<_Atomic%>-qualified array type");
2822 		  else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2823 		    error_at (loc, "%<_Atomic%>-qualified function type");
2824 		  else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2825 		    error_at (loc, "%<_Atomic%> applied to a qualified type");
2826 		  else
2827 		    t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2828 		}
2829 	      declspecs_add_type (loc, specs, t);
2830 	    }
2831 	  else
2832 	    declspecs_add_qual (loc, specs, value);
2833 	  break;
2834 	case RID_CONST:
2835 	case RID_VOLATILE:
2836 	case RID_RESTRICT:
2837 	  attrs_ok = true;
2838 	  declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2839 	  c_parser_consume_token (parser);
2840 	  break;
2841 	case RID_ATTRIBUTE:
2842 	  if (!attrs_ok)
2843 	    goto out;
2844 	  attrs = c_parser_attributes (parser);
2845 	  declspecs_add_attrs (loc, specs, attrs);
2846 	  break;
2847 	case RID_ALIGNAS:
2848 	  if (!alignspec_ok)
2849 	    goto out;
2850 	  align = c_parser_alignas_specifier (parser);
2851 	  declspecs_add_alignas (loc, specs, align);
2852 	  break;
2853 	case RID_GIMPLE:
2854 	  if (! flag_gimple)
2855 	    error_at (loc, "%<__GIMPLE%> only valid with -fgimple");
2856 	  c_parser_consume_token (parser);
2857 	  specs->gimple_p = true;
2858 	  specs->locations[cdw_gimple] = loc;
2859 	  specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2860 	  break;
2861 	case RID_RTL:
2862 	  c_parser_consume_token (parser);
2863 	  specs->rtl_p = true;
2864 	  specs->locations[cdw_rtl] = loc;
2865 	  specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2866 	  break;
2867 	default:
2868 	  goto out;
2869 	}
2870     }
2871  out: ;
2872 }
2873 
2874 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2875 
2876    enum-specifier:
2877      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2878      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2879      enum attributes[opt] identifier
2880 
2881    The form with trailing comma is new in C99.  The forms with
2882    attributes are GNU extensions.  In GNU C, we accept any expression
2883    without commas in the syntax (assignment expressions, not just
2884    conditional expressions); assignment expressions will be diagnosed
2885    as non-constant.
2886 
2887    enumerator-list:
2888      enumerator
2889      enumerator-list , enumerator
2890 
2891    enumerator:
2892      enumeration-constant
2893      enumeration-constant = constant-expression
2894 
2895    GNU Extensions:
2896 
2897    enumerator:
2898      enumeration-constant attributes[opt]
2899      enumeration-constant attributes[opt] = constant-expression
2900 
2901 */
2902 
2903 static struct c_typespec
2904 c_parser_enum_specifier (c_parser *parser)
2905 {
2906   struct c_typespec ret;
2907   tree attrs;
2908   tree ident = NULL_TREE;
2909   location_t enum_loc;
2910   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2911   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2912   c_parser_consume_token (parser);
2913   attrs = c_parser_attributes (parser);
2914   enum_loc = c_parser_peek_token (parser)->location;
2915   /* Set the location in case we create a decl now.  */
2916   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2917   if (c_parser_next_token_is (parser, CPP_NAME))
2918     {
2919       ident = c_parser_peek_token (parser)->value;
2920       ident_loc = c_parser_peek_token (parser)->location;
2921       enum_loc = ident_loc;
2922       c_parser_consume_token (parser);
2923     }
2924   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2925     {
2926       /* Parse an enum definition.  */
2927       struct c_enum_contents the_enum;
2928       tree type;
2929       tree postfix_attrs;
2930       /* We chain the enumerators in reverse order, then put them in
2931 	 forward order at the end.  */
2932       tree values;
2933       timevar_push (TV_PARSE_ENUM);
2934       type = start_enum (enum_loc, &the_enum, ident);
2935       values = NULL_TREE;
2936       c_parser_consume_token (parser);
2937       while (true)
2938 	{
2939 	  tree enum_id;
2940 	  tree enum_value;
2941 	  tree enum_decl;
2942 	  bool seen_comma;
2943 	  c_token *token;
2944 	  location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2945 	  location_t decl_loc, value_loc;
2946 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
2947 	    {
2948 	      /* Give a nicer error for "enum {}".  */
2949 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2950 		  && !parser->error)
2951 		{
2952 		  error_at (c_parser_peek_token (parser)->location,
2953 			    "empty enum is invalid");
2954 		  parser->error = true;
2955 		}
2956 	      else
2957 		c_parser_error (parser, "expected identifier");
2958 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2959 	      values = error_mark_node;
2960 	      break;
2961 	    }
2962 	  token = c_parser_peek_token (parser);
2963 	  enum_id = token->value;
2964 	  /* Set the location in case we create a decl now.  */
2965 	  c_parser_set_source_position_from_token (token);
2966 	  decl_loc = value_loc = token->location;
2967 	  c_parser_consume_token (parser);
2968 	  /* Parse any specified attributes.  */
2969 	  tree enum_attrs = c_parser_attributes (parser);
2970 	  if (c_parser_next_token_is (parser, CPP_EQ))
2971 	    {
2972 	      c_parser_consume_token (parser);
2973 	      value_loc = c_parser_peek_token (parser)->location;
2974 	      enum_value = c_parser_expr_no_commas (parser, NULL).value;
2975 	    }
2976 	  else
2977 	    enum_value = NULL_TREE;
2978 	  enum_decl = build_enumerator (decl_loc, value_loc,
2979 					&the_enum, enum_id, enum_value);
2980 	  if (enum_attrs)
2981 	    decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0);
2982 	  TREE_CHAIN (enum_decl) = values;
2983 	  values = enum_decl;
2984 	  seen_comma = false;
2985 	  if (c_parser_next_token_is (parser, CPP_COMMA))
2986 	    {
2987 	      comma_loc = c_parser_peek_token (parser)->location;
2988 	      seen_comma = true;
2989 	      c_parser_consume_token (parser);
2990 	    }
2991 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2992 	    {
2993 	      if (seen_comma)
2994 		pedwarn_c90 (comma_loc, OPT_Wpedantic,
2995 			     "comma at end of enumerator list");
2996 	      c_parser_consume_token (parser);
2997 	      break;
2998 	    }
2999 	  if (!seen_comma)
3000 	    {
3001 	      c_parser_error (parser, "expected %<,%> or %<}%>");
3002 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
3003 	      values = error_mark_node;
3004 	      break;
3005 	    }
3006 	}
3007       postfix_attrs = c_parser_attributes (parser);
3008       ret.spec = finish_enum (type, nreverse (values),
3009 			      chainon (attrs, postfix_attrs));
3010       ret.kind = ctsk_tagdef;
3011       ret.expr = NULL_TREE;
3012       ret.expr_const_operands = true;
3013       timevar_pop (TV_PARSE_ENUM);
3014       return ret;
3015     }
3016   else if (!ident)
3017     {
3018       c_parser_error (parser, "expected %<{%>");
3019       ret.spec = error_mark_node;
3020       ret.kind = ctsk_tagref;
3021       ret.expr = NULL_TREE;
3022       ret.expr_const_operands = true;
3023       return ret;
3024     }
3025   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
3026   /* In ISO C, enumerated types can be referred to only if already
3027      defined.  */
3028   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
3029     {
3030       gcc_assert (ident);
3031       pedwarn (enum_loc, OPT_Wpedantic,
3032 	       "ISO C forbids forward references to %<enum%> types");
3033     }
3034   return ret;
3035 }
3036 
3037 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3038 
3039    struct-or-union-specifier:
3040      struct-or-union attributes[opt] identifier[opt]
3041        { struct-contents } attributes[opt]
3042      struct-or-union attributes[opt] identifier
3043 
3044    struct-contents:
3045      struct-declaration-list
3046 
3047    struct-declaration-list:
3048      struct-declaration ;
3049      struct-declaration-list struct-declaration ;
3050 
3051    GNU extensions:
3052 
3053    struct-contents:
3054      empty
3055      struct-declaration
3056      struct-declaration-list struct-declaration
3057 
3058    struct-declaration-list:
3059      struct-declaration-list ;
3060      ;
3061 
3062    (Note that in the syntax here, unlike that in ISO C, the semicolons
3063    are included here rather than in struct-declaration, in order to
3064    describe the syntax with extra semicolons and missing semicolon at
3065    end.)
3066 
3067    Objective-C:
3068 
3069    struct-declaration-list:
3070      @defs ( class-name )
3071 
3072    (Note this does not include a trailing semicolon, but can be
3073    followed by further declarations, and gets a pedwarn-if-pedantic
3074    when followed by a semicolon.)  */
3075 
3076 static struct c_typespec
3077 c_parser_struct_or_union_specifier (c_parser *parser)
3078 {
3079   struct c_typespec ret;
3080   tree attrs;
3081   tree ident = NULL_TREE;
3082   location_t struct_loc;
3083   location_t ident_loc = UNKNOWN_LOCATION;
3084   enum tree_code code;
3085   switch (c_parser_peek_token (parser)->keyword)
3086     {
3087     case RID_STRUCT:
3088       code = RECORD_TYPE;
3089       break;
3090     case RID_UNION:
3091       code = UNION_TYPE;
3092       break;
3093     default:
3094       gcc_unreachable ();
3095     }
3096   struct_loc = c_parser_peek_token (parser)->location;
3097   c_parser_consume_token (parser);
3098   attrs = c_parser_attributes (parser);
3099 
3100   /* Set the location in case we create a decl now.  */
3101   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
3102 
3103   if (c_parser_next_token_is (parser, CPP_NAME))
3104     {
3105       ident = c_parser_peek_token (parser)->value;
3106       ident_loc = c_parser_peek_token (parser)->location;
3107       struct_loc = ident_loc;
3108       c_parser_consume_token (parser);
3109     }
3110   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3111     {
3112       /* Parse a struct or union definition.  Start the scope of the
3113 	 tag before parsing components.  */
3114       struct c_struct_parse_info *struct_info;
3115       tree type = start_struct (struct_loc, code, ident, &struct_info);
3116       tree postfix_attrs;
3117       /* We chain the components in reverse order, then put them in
3118 	 forward order at the end.  Each struct-declaration may
3119 	 declare multiple components (comma-separated), so we must use
3120 	 chainon to join them, although when parsing each
3121 	 struct-declaration we can use TREE_CHAIN directly.
3122 
3123 	 The theory behind all this is that there will be more
3124 	 semicolon separated fields than comma separated fields, and
3125 	 so we'll be minimizing the number of node traversals required
3126 	 by chainon.  */
3127       tree contents;
3128       timevar_push (TV_PARSE_STRUCT);
3129       contents = NULL_TREE;
3130       c_parser_consume_token (parser);
3131       /* Handle the Objective-C @defs construct,
3132 	 e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
3133       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
3134 	{
3135 	  tree name;
3136 	  gcc_assert (c_dialect_objc ());
3137 	  c_parser_consume_token (parser);
3138 	  matching_parens parens;
3139 	  if (!parens.require_open (parser))
3140 	    goto end_at_defs;
3141 	  if (c_parser_next_token_is (parser, CPP_NAME)
3142 	      && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
3143 	    {
3144 	      name = c_parser_peek_token (parser)->value;
3145 	      c_parser_consume_token (parser);
3146 	    }
3147 	  else
3148 	    {
3149 	      c_parser_error (parser, "expected class name");
3150 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3151 	      goto end_at_defs;
3152 	    }
3153 	  parens.skip_until_found_close (parser);
3154 	  contents = nreverse (objc_get_class_ivars (name));
3155 	}
3156     end_at_defs:
3157       /* Parse the struct-declarations and semicolons.  Problems with
3158 	 semicolons are diagnosed here; empty structures are diagnosed
3159 	 elsewhere.  */
3160       while (true)
3161 	{
3162 	  tree decls;
3163 	  /* Parse any stray semicolon.  */
3164 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3165 	    {
3166 	      location_t semicolon_loc
3167 		= c_parser_peek_token (parser)->location;
3168 	      gcc_rich_location richloc (semicolon_loc);
3169 	      richloc.add_fixit_remove ();
3170 	      pedwarn (&richloc, OPT_Wpedantic,
3171 		       "extra semicolon in struct or union specified");
3172 	      c_parser_consume_token (parser);
3173 	      continue;
3174 	    }
3175 	  /* Stop if at the end of the struct or union contents.  */
3176 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3177 	    {
3178 	      c_parser_consume_token (parser);
3179 	      break;
3180 	    }
3181 	  /* Accept #pragmas at struct scope.  */
3182 	  if (c_parser_next_token_is (parser, CPP_PRAGMA))
3183 	    {
3184 	      c_parser_pragma (parser, pragma_struct, NULL);
3185 	      continue;
3186 	    }
3187 	  /* Parse some comma-separated declarations, but not the
3188 	     trailing semicolon if any.  */
3189 	  decls = c_parser_struct_declaration (parser);
3190 	  contents = chainon (decls, contents);
3191 	  /* If no semicolon follows, either we have a parse error or
3192 	     are at the end of the struct or union and should
3193 	     pedwarn.  */
3194 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3195 	    c_parser_consume_token (parser);
3196 	  else
3197 	    {
3198 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3199 		pedwarn (c_parser_peek_token (parser)->location, 0,
3200 			 "no semicolon at end of struct or union");
3201 	      else if (parser->error
3202 		       || !c_parser_next_token_starts_declspecs (parser))
3203 		{
3204 		  c_parser_error (parser, "expected %<;%>");
3205 		  c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
3206 		  break;
3207 		}
3208 
3209 	      /* If we come here, we have already emitted an error
3210 		 for an expected `;', identifier or `(', and we also
3211 	         recovered already.  Go on with the next field. */
3212 	    }
3213 	}
3214       postfix_attrs = c_parser_attributes (parser);
3215       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
3216 				chainon (attrs, postfix_attrs), struct_info);
3217       ret.kind = ctsk_tagdef;
3218       ret.expr = NULL_TREE;
3219       ret.expr_const_operands = true;
3220       timevar_pop (TV_PARSE_STRUCT);
3221       return ret;
3222     }
3223   else if (!ident)
3224     {
3225       c_parser_error (parser, "expected %<{%>");
3226       ret.spec = error_mark_node;
3227       ret.kind = ctsk_tagref;
3228       ret.expr = NULL_TREE;
3229       ret.expr_const_operands = true;
3230       return ret;
3231     }
3232   ret = parser_xref_tag (ident_loc, code, ident);
3233   return ret;
3234 }
3235 
3236 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3237    *without* the trailing semicolon.
3238 
3239    struct-declaration:
3240      specifier-qualifier-list struct-declarator-list
3241      static_assert-declaration-no-semi
3242 
3243    specifier-qualifier-list:
3244      type-specifier specifier-qualifier-list[opt]
3245      type-qualifier specifier-qualifier-list[opt]
3246      alignment-specifier specifier-qualifier-list[opt]
3247      attributes specifier-qualifier-list[opt]
3248 
3249    struct-declarator-list:
3250      struct-declarator
3251      struct-declarator-list , attributes[opt] struct-declarator
3252 
3253    struct-declarator:
3254      declarator attributes[opt]
3255      declarator[opt] : constant-expression attributes[opt]
3256 
3257    GNU extensions:
3258 
3259    struct-declaration:
3260      __extension__ struct-declaration
3261      specifier-qualifier-list
3262 
3263    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
3264    of attributes where shown is a GNU extension.  In GNU C, we accept
3265    any expression without commas in the syntax (assignment
3266    expressions, not just conditional expressions); assignment
3267    expressions will be diagnosed as non-constant.  */
3268 
3269 static tree
3270 c_parser_struct_declaration (c_parser *parser)
3271 {
3272   struct c_declspecs *specs;
3273   tree prefix_attrs;
3274   tree all_prefix_attrs;
3275   tree decls;
3276   location_t decl_loc;
3277   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3278     {
3279       int ext;
3280       tree decl;
3281       ext = disable_extension_diagnostics ();
3282       c_parser_consume_token (parser);
3283       decl = c_parser_struct_declaration (parser);
3284       restore_extension_diagnostics (ext);
3285       return decl;
3286     }
3287   if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
3288     {
3289       c_parser_static_assert_declaration_no_semi (parser);
3290       return NULL_TREE;
3291     }
3292   specs = build_null_declspecs ();
3293   decl_loc = c_parser_peek_token (parser)->location;
3294   /* Strictly by the standard, we shouldn't allow _Alignas here,
3295      but it appears to have been intended to allow it there, so
3296      we're keeping it as it is until WG14 reaches a conclusion
3297      of N1731.
3298      <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf>  */
3299   c_parser_declspecs (parser, specs, false, true, true,
3300 		      true, false, cla_nonabstract_decl);
3301   if (parser->error)
3302     return NULL_TREE;
3303   if (!specs->declspecs_seen_p)
3304     {
3305       c_parser_error (parser, "expected specifier-qualifier-list");
3306       return NULL_TREE;
3307     }
3308   finish_declspecs (specs);
3309   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3310       || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3311     {
3312       tree ret;
3313       if (specs->typespec_kind == ctsk_none)
3314 	{
3315 	  pedwarn (decl_loc, OPT_Wpedantic,
3316 		   "ISO C forbids member declarations with no members");
3317 	  shadow_tag_warned (specs, pedantic);
3318 	  ret = NULL_TREE;
3319 	}
3320       else
3321 	{
3322 	  /* Support for unnamed structs or unions as members of
3323 	     structs or unions (which is [a] useful and [b] supports
3324 	     MS P-SDK).  */
3325 	  tree attrs = NULL;
3326 
3327 	  ret = grokfield (c_parser_peek_token (parser)->location,
3328 			   build_id_declarator (NULL_TREE), specs,
3329 			   NULL_TREE, &attrs);
3330 	  if (ret)
3331 	    decl_attributes (&ret, attrs, 0);
3332 	}
3333       return ret;
3334     }
3335 
3336   /* Provide better error recovery.  Note that a type name here is valid,
3337      and will be treated as a field name.  */
3338   if (specs->typespec_kind == ctsk_tagdef
3339       && TREE_CODE (specs->type) != ENUMERAL_TYPE
3340       && c_parser_next_token_starts_declspecs (parser)
3341       && !c_parser_next_token_is (parser, CPP_NAME))
3342     {
3343       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
3344       parser->error = false;
3345       return NULL_TREE;
3346     }
3347 
3348   pending_xref_error ();
3349   prefix_attrs = specs->attrs;
3350   all_prefix_attrs = prefix_attrs;
3351   specs->attrs = NULL_TREE;
3352   decls = NULL_TREE;
3353   while (true)
3354     {
3355       /* Declaring one or more declarators or un-named bit-fields.  */
3356       struct c_declarator *declarator;
3357       bool dummy = false;
3358       if (c_parser_next_token_is (parser, CPP_COLON))
3359 	declarator = build_id_declarator (NULL_TREE);
3360       else
3361 	declarator = c_parser_declarator (parser,
3362 					  specs->typespec_kind != ctsk_none,
3363 					  C_DTR_NORMAL, &dummy);
3364       if (declarator == NULL)
3365 	{
3366 	  c_parser_skip_to_end_of_block_or_statement (parser);
3367 	  break;
3368 	}
3369       if (c_parser_next_token_is (parser, CPP_COLON)
3370 	  || c_parser_next_token_is (parser, CPP_COMMA)
3371 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
3372 	  || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
3373 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3374 	{
3375 	  tree postfix_attrs = NULL_TREE;
3376 	  tree width = NULL_TREE;
3377 	  tree d;
3378 	  if (c_parser_next_token_is (parser, CPP_COLON))
3379 	    {
3380 	      c_parser_consume_token (parser);
3381 	      width = c_parser_expr_no_commas (parser, NULL).value;
3382 	    }
3383 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3384 	    postfix_attrs = c_parser_attributes (parser);
3385 	  d = grokfield (c_parser_peek_token (parser)->location,
3386 			 declarator, specs, width, &all_prefix_attrs);
3387 	  decl_attributes (&d, chainon (postfix_attrs,
3388 					all_prefix_attrs), 0);
3389 	  DECL_CHAIN (d) = decls;
3390 	  decls = d;
3391 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3392 	    all_prefix_attrs = chainon (c_parser_attributes (parser),
3393 					prefix_attrs);
3394 	  else
3395 	    all_prefix_attrs = prefix_attrs;
3396 	  if (c_parser_next_token_is (parser, CPP_COMMA))
3397 	    c_parser_consume_token (parser);
3398 	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3399 		   || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3400 	    {
3401 	      /* Semicolon consumed in caller.  */
3402 	      break;
3403 	    }
3404 	  else
3405 	    {
3406 	      c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3407 	      break;
3408 	    }
3409 	}
3410       else
3411 	{
3412 	  c_parser_error (parser,
3413 			  "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3414 			  "%<__attribute__%>");
3415 	  break;
3416 	}
3417     }
3418   return decls;
3419 }
3420 
3421 /* Parse a typeof specifier (a GNU extension).
3422 
3423    typeof-specifier:
3424      typeof ( expression )
3425      typeof ( type-name )
3426 */
3427 
3428 static struct c_typespec
3429 c_parser_typeof_specifier (c_parser *parser)
3430 {
3431   struct c_typespec ret;
3432   ret.kind = ctsk_typeof;
3433   ret.spec = error_mark_node;
3434   ret.expr = NULL_TREE;
3435   ret.expr_const_operands = true;
3436   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3437   c_parser_consume_token (parser);
3438   c_inhibit_evaluation_warnings++;
3439   in_typeof++;
3440   matching_parens parens;
3441   if (!parens.require_open (parser))
3442     {
3443       c_inhibit_evaluation_warnings--;
3444       in_typeof--;
3445       return ret;
3446     }
3447   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3448     {
3449       struct c_type_name *type = c_parser_type_name (parser);
3450       c_inhibit_evaluation_warnings--;
3451       in_typeof--;
3452       if (type != NULL)
3453 	{
3454 	  ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3455 	  pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3456 	}
3457     }
3458   else
3459     {
3460       bool was_vm;
3461       location_t here = c_parser_peek_token (parser)->location;
3462       struct c_expr expr = c_parser_expression (parser);
3463       c_inhibit_evaluation_warnings--;
3464       in_typeof--;
3465       if (TREE_CODE (expr.value) == COMPONENT_REF
3466 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3467 	error_at (here, "%<typeof%> applied to a bit-field");
3468       mark_exp_read (expr.value);
3469       ret.spec = TREE_TYPE (expr.value);
3470       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3471       /* This is returned with the type so that when the type is
3472 	 evaluated, this can be evaluated.  */
3473       if (was_vm)
3474 	ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3475       pop_maybe_used (was_vm);
3476       /* For use in macros such as those in <stdatomic.h>, remove all
3477 	 qualifiers from atomic types.  (const can be an issue for more macros
3478 	 using typeof than just the <stdatomic.h> ones.)  */
3479       if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3480 	ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3481     }
3482   parens.skip_until_found_close (parser);
3483   return ret;
3484 }
3485 
3486 /* Parse an alignment-specifier.
3487 
3488    C11 6.7.5:
3489 
3490    alignment-specifier:
3491      _Alignas ( type-name )
3492      _Alignas ( constant-expression )
3493 */
3494 
3495 static tree
3496 c_parser_alignas_specifier (c_parser * parser)
3497 {
3498   tree ret = error_mark_node;
3499   location_t loc = c_parser_peek_token (parser)->location;
3500   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3501   c_parser_consume_token (parser);
3502   if (flag_isoc99)
3503     pedwarn_c99 (loc, OPT_Wpedantic,
3504 		 "ISO C99 does not support %<_Alignas%>");
3505   else
3506     pedwarn_c99 (loc, OPT_Wpedantic,
3507 		 "ISO C90 does not support %<_Alignas%>");
3508   matching_parens parens;
3509   if (!parens.require_open (parser))
3510     return ret;
3511   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3512     {
3513       struct c_type_name *type = c_parser_type_name (parser);
3514       if (type != NULL)
3515 	ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3516 					false, true, 1);
3517     }
3518   else
3519     ret = c_parser_expr_no_commas (parser, NULL).value;
3520   parens.skip_until_found_close (parser);
3521   return ret;
3522 }
3523 
3524 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3525    6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7).  If TYPE_SEEN_P then
3526    a typedef name may be redeclared; otherwise it may not.  KIND
3527    indicates which kind of declarator is wanted.  Returns a valid
3528    declarator except in the case of a syntax error in which case NULL is
3529    returned.  *SEEN_ID is set to true if an identifier being declared is
3530    seen; this is used to diagnose bad forms of abstract array declarators
3531    and to determine whether an identifier list is syntactically permitted.
3532 
3533    declarator:
3534      pointer[opt] direct-declarator
3535 
3536    direct-declarator:
3537      identifier
3538      ( attributes[opt] declarator )
3539      direct-declarator array-declarator
3540      direct-declarator ( parameter-type-list )
3541      direct-declarator ( identifier-list[opt] )
3542 
3543    pointer:
3544      * type-qualifier-list[opt]
3545      * type-qualifier-list[opt] pointer
3546 
3547    type-qualifier-list:
3548      type-qualifier
3549      attributes
3550      type-qualifier-list type-qualifier
3551      type-qualifier-list attributes
3552 
3553    array-declarator:
3554      [ type-qualifier-list[opt] assignment-expression[opt] ]
3555      [ static type-qualifier-list[opt] assignment-expression ]
3556      [ type-qualifier-list static assignment-expression ]
3557      [ type-qualifier-list[opt] * ]
3558 
3559    parameter-type-list:
3560      parameter-list
3561      parameter-list , ...
3562 
3563    parameter-list:
3564      parameter-declaration
3565      parameter-list , parameter-declaration
3566 
3567    parameter-declaration:
3568      declaration-specifiers declarator attributes[opt]
3569      declaration-specifiers abstract-declarator[opt] attributes[opt]
3570 
3571    identifier-list:
3572      identifier
3573      identifier-list , identifier
3574 
3575    abstract-declarator:
3576      pointer
3577      pointer[opt] direct-abstract-declarator
3578 
3579    direct-abstract-declarator:
3580      ( attributes[opt] abstract-declarator )
3581      direct-abstract-declarator[opt] array-declarator
3582      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3583 
3584    GNU extensions:
3585 
3586    direct-declarator:
3587      direct-declarator ( parameter-forward-declarations
3588 			 parameter-type-list[opt] )
3589 
3590    direct-abstract-declarator:
3591      direct-abstract-declarator[opt] ( parameter-forward-declarations
3592 				       parameter-type-list[opt] )
3593 
3594    parameter-forward-declarations:
3595      parameter-list ;
3596      parameter-forward-declarations parameter-list ;
3597 
3598    The uses of attributes shown above are GNU extensions.
3599 
3600    Some forms of array declarator are not included in C99 in the
3601    syntax for abstract declarators; these are disallowed elsewhere.
3602    This may be a defect (DR#289).
3603 
3604    This function also accepts an omitted abstract declarator as being
3605    an abstract declarator, although not part of the formal syntax.  */
3606 
3607 struct c_declarator *
3608 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3609 		     bool *seen_id)
3610 {
3611   /* Parse any initial pointer part.  */
3612   if (c_parser_next_token_is (parser, CPP_MULT))
3613     {
3614       struct c_declspecs *quals_attrs = build_null_declspecs ();
3615       struct c_declarator *inner;
3616       c_parser_consume_token (parser);
3617       c_parser_declspecs (parser, quals_attrs, false, false, true,
3618 			  false, false, cla_prefer_id);
3619       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3620       if (inner == NULL)
3621 	return NULL;
3622       else
3623 	return make_pointer_declarator (quals_attrs, inner);
3624     }
3625   /* Now we have a direct declarator, direct abstract declarator or
3626      nothing (which counts as a direct abstract declarator here).  */
3627   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3628 }
3629 
3630 /* Parse a direct declarator or direct abstract declarator; arguments
3631    as c_parser_declarator.  */
3632 
3633 static struct c_declarator *
3634 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3635 			    bool *seen_id)
3636 {
3637   /* The direct declarator must start with an identifier (possibly
3638      omitted) or a parenthesized declarator (possibly abstract).  In
3639      an ordinary declarator, initial parentheses must start a
3640      parenthesized declarator.  In an abstract declarator or parameter
3641      declarator, they could start a parenthesized declarator or a
3642      parameter list.  To tell which, the open parenthesis and any
3643      following attributes must be read.  If a declaration specifier
3644      follows, then it is a parameter list; if the specifier is a
3645      typedef name, there might be an ambiguity about redeclaring it,
3646      which is resolved in the direction of treating it as a typedef
3647      name.  If a close parenthesis follows, it is also an empty
3648      parameter list, as the syntax does not permit empty abstract
3649      declarators.  Otherwise, it is a parenthesized declarator (in
3650      which case the analysis may be repeated inside it, recursively).
3651 
3652      ??? There is an ambiguity in a parameter declaration "int
3653      (__attribute__((foo)) x)", where x is not a typedef name: it
3654      could be an abstract declarator for a function, or declare x with
3655      parentheses.  The proper resolution of this ambiguity needs
3656      documenting.  At present we follow an accident of the old
3657      parser's implementation, whereby the first parameter must have
3658      some declaration specifiers other than just attributes.  Thus as
3659      a parameter declaration it is treated as a parenthesized
3660      parameter named x, and as an abstract declarator it is
3661      rejected.
3662 
3663      ??? Also following the old parser, attributes inside an empty
3664      parameter list are ignored, making it a list not yielding a
3665      prototype, rather than giving an error or making it have one
3666      parameter with implicit type int.
3667 
3668      ??? Also following the old parser, typedef names may be
3669      redeclared in declarators, but not Objective-C class names.  */
3670 
3671   if (kind != C_DTR_ABSTRACT
3672       && c_parser_next_token_is (parser, CPP_NAME)
3673       && ((type_seen_p
3674 	   && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3675 	       || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3676 	  || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3677     {
3678       struct c_declarator *inner
3679 	= build_id_declarator (c_parser_peek_token (parser)->value);
3680       *seen_id = true;
3681       inner->id_loc = c_parser_peek_token (parser)->location;
3682       c_parser_consume_token (parser);
3683       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3684     }
3685 
3686   if (kind != C_DTR_NORMAL
3687       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3688     {
3689       struct c_declarator *inner = build_id_declarator (NULL_TREE);
3690       inner->id_loc = c_parser_peek_token (parser)->location;
3691       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3692     }
3693 
3694   /* Either we are at the end of an abstract declarator, or we have
3695      parentheses.  */
3696 
3697   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3698     {
3699       tree attrs;
3700       struct c_declarator *inner;
3701       c_parser_consume_token (parser);
3702       attrs = c_parser_attributes (parser);
3703       if (kind != C_DTR_NORMAL
3704 	  && (c_parser_next_token_starts_declspecs (parser)
3705 	      || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3706 	{
3707 	  struct c_arg_info *args
3708 	    = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3709 					 attrs);
3710 	  if (args == NULL)
3711 	    return NULL;
3712 	  else
3713 	    {
3714 	      inner
3715 		= build_function_declarator (args,
3716 					     build_id_declarator (NULL_TREE));
3717 	      return c_parser_direct_declarator_inner (parser, *seen_id,
3718 						       inner);
3719 	    }
3720 	}
3721       /* A parenthesized declarator.  */
3722       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3723       if (inner != NULL && attrs != NULL)
3724 	inner = build_attrs_declarator (attrs, inner);
3725       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3726 	{
3727 	  c_parser_consume_token (parser);
3728 	  if (inner == NULL)
3729 	    return NULL;
3730 	  else
3731 	    return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3732 	}
3733       else
3734 	{
3735 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3736 				     "expected %<)%>");
3737 	  return NULL;
3738 	}
3739     }
3740   else
3741     {
3742       if (kind == C_DTR_NORMAL)
3743 	{
3744 	  c_parser_error (parser, "expected identifier or %<(%>");
3745 	  return NULL;
3746 	}
3747       else
3748 	return build_id_declarator (NULL_TREE);
3749     }
3750 }
3751 
3752 /* Parse part of a direct declarator or direct abstract declarator,
3753    given that some (in INNER) has already been parsed; ID_PRESENT is
3754    true if an identifier is present, false for an abstract
3755    declarator.  */
3756 
3757 static struct c_declarator *
3758 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3759 				  struct c_declarator *inner)
3760 {
3761   /* Parse a sequence of array declarators and parameter lists.  */
3762   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3763     {
3764       location_t brace_loc = c_parser_peek_token (parser)->location;
3765       struct c_declarator *declarator;
3766       struct c_declspecs *quals_attrs = build_null_declspecs ();
3767       bool static_seen;
3768       bool star_seen;
3769       struct c_expr dimen;
3770       dimen.value = NULL_TREE;
3771       dimen.original_code = ERROR_MARK;
3772       dimen.original_type = NULL_TREE;
3773       c_parser_consume_token (parser);
3774       c_parser_declspecs (parser, quals_attrs, false, false, true,
3775 			  false, false, cla_prefer_id);
3776       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3777       if (static_seen)
3778 	c_parser_consume_token (parser);
3779       if (static_seen && !quals_attrs->declspecs_seen_p)
3780 	c_parser_declspecs (parser, quals_attrs, false, false, true,
3781 			    false, false, cla_prefer_id);
3782       if (!quals_attrs->declspecs_seen_p)
3783 	quals_attrs = NULL;
3784       /* If "static" is present, there must be an array dimension.
3785 	 Otherwise, there may be a dimension, "*", or no
3786 	 dimension.  */
3787       if (static_seen)
3788 	{
3789 	  star_seen = false;
3790 	  dimen = c_parser_expr_no_commas (parser, NULL);
3791 	}
3792       else
3793 	{
3794 	  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3795 	    {
3796 	      dimen.value = NULL_TREE;
3797 	      star_seen = false;
3798 	    }
3799 	  else if (c_parser_next_token_is (parser, CPP_MULT))
3800 	    {
3801 	      if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3802 		{
3803 		  dimen.value = NULL_TREE;
3804 		  star_seen = true;
3805 		  c_parser_consume_token (parser);
3806 		}
3807 	      else
3808 		{
3809 		  star_seen = false;
3810 		  dimen = c_parser_expr_no_commas (parser, NULL);
3811 		}
3812 	    }
3813 	  else
3814 	    {
3815 	      star_seen = false;
3816 	      dimen = c_parser_expr_no_commas (parser, NULL);
3817 	    }
3818 	}
3819       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3820 	c_parser_consume_token (parser);
3821       else
3822 	{
3823 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3824 				     "expected %<]%>");
3825 	  return NULL;
3826 	}
3827       if (dimen.value)
3828 	dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3829       declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3830 					   static_seen, star_seen);
3831       if (declarator == NULL)
3832 	return NULL;
3833       inner = set_array_declarator_inner (declarator, inner);
3834       return c_parser_direct_declarator_inner (parser, id_present, inner);
3835     }
3836   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3837     {
3838       tree attrs;
3839       struct c_arg_info *args;
3840       c_parser_consume_token (parser);
3841       attrs = c_parser_attributes (parser);
3842       args = c_parser_parms_declarator (parser, id_present, attrs);
3843       if (args == NULL)
3844 	return NULL;
3845       else
3846 	{
3847 	  inner = build_function_declarator (args, inner);
3848 	  return c_parser_direct_declarator_inner (parser, id_present, inner);
3849 	}
3850     }
3851   return inner;
3852 }
3853 
3854 /* Parse a parameter list or identifier list, including the closing
3855    parenthesis but not the opening one.  ATTRS are the attributes at
3856    the start of the list.  ID_LIST_OK is true if an identifier list is
3857    acceptable; such a list must not have attributes at the start.  */
3858 
3859 static struct c_arg_info *
3860 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3861 {
3862   push_scope ();
3863   declare_parm_level ();
3864   /* If the list starts with an identifier, it is an identifier list.
3865      Otherwise, it is either a prototype list or an empty list.  */
3866   if (id_list_ok
3867       && !attrs
3868       && c_parser_next_token_is (parser, CPP_NAME)
3869       && c_parser_peek_token (parser)->id_kind == C_ID_ID
3870 
3871       /* Look ahead to detect typos in type names.  */
3872       && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3873       && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3874       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3875       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE
3876       && c_parser_peek_2nd_token (parser)->type != CPP_KEYWORD)
3877     {
3878       tree list = NULL_TREE, *nextp = &list;
3879       while (c_parser_next_token_is (parser, CPP_NAME)
3880 	     && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3881 	{
3882 	  *nextp = build_tree_list (NULL_TREE,
3883 				    c_parser_peek_token (parser)->value);
3884 	  nextp = & TREE_CHAIN (*nextp);
3885 	  c_parser_consume_token (parser);
3886 	  if (c_parser_next_token_is_not (parser, CPP_COMMA))
3887 	    break;
3888 	  c_parser_consume_token (parser);
3889 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3890 	    {
3891 	      c_parser_error (parser, "expected identifier");
3892 	      break;
3893 	    }
3894 	}
3895       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3896 	{
3897 	  struct c_arg_info *ret = build_arg_info ();
3898 	  ret->types = list;
3899 	  c_parser_consume_token (parser);
3900 	  pop_scope ();
3901 	  return ret;
3902 	}
3903       else
3904 	{
3905 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3906 				     "expected %<)%>");
3907 	  pop_scope ();
3908 	  return NULL;
3909 	}
3910     }
3911   else
3912     {
3913       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3914 							       NULL);
3915       pop_scope ();
3916       return ret;
3917     }
3918 }
3919 
3920 /* Parse a parameter list (possibly empty), including the closing
3921    parenthesis but not the opening one.  ATTRS are the attributes at
3922    the start of the list.  EXPR is NULL or an expression that needs to
3923    be evaluated for the side effects of array size expressions in the
3924    parameters.  */
3925 
3926 static struct c_arg_info *
3927 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3928 {
3929   bool bad_parm = false;
3930 
3931   /* ??? Following the old parser, forward parameter declarations may
3932      use abstract declarators, and if no real parameter declarations
3933      follow the forward declarations then this is not diagnosed.  Also
3934      note as above that attributes are ignored as the only contents of
3935      the parentheses, or as the only contents after forward
3936      declarations.  */
3937   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3938     {
3939       struct c_arg_info *ret = build_arg_info ();
3940       c_parser_consume_token (parser);
3941       return ret;
3942     }
3943   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3944     {
3945       struct c_arg_info *ret = build_arg_info ();
3946 
3947       if (flag_allow_parameterless_variadic_functions)
3948         {
3949           /* F (...) is allowed.  */
3950           ret->types = NULL_TREE;
3951         }
3952       else
3953         {
3954           /* Suppress -Wold-style-definition for this case.  */
3955           ret->types = error_mark_node;
3956           error_at (c_parser_peek_token (parser)->location,
3957                     "ISO C requires a named argument before %<...%>");
3958         }
3959       c_parser_consume_token (parser);
3960       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3961 	{
3962 	  c_parser_consume_token (parser);
3963 	  return ret;
3964 	}
3965       else
3966 	{
3967 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3968 				     "expected %<)%>");
3969 	  return NULL;
3970 	}
3971     }
3972   /* Nonempty list of parameters, either terminated with semicolon
3973      (forward declarations; recurse) or with close parenthesis (normal
3974      function) or with ", ... )" (variadic function).  */
3975   while (true)
3976     {
3977       /* Parse a parameter.  */
3978       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3979       attrs = NULL_TREE;
3980       if (parm == NULL)
3981 	bad_parm = true;
3982       else
3983 	push_parm_decl (parm, &expr);
3984       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3985 	{
3986 	  tree new_attrs;
3987 	  c_parser_consume_token (parser);
3988 	  mark_forward_parm_decls ();
3989 	  new_attrs = c_parser_attributes (parser);
3990 	  return c_parser_parms_list_declarator (parser, new_attrs, expr);
3991 	}
3992       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3993 	{
3994 	  c_parser_consume_token (parser);
3995 	  if (bad_parm)
3996 	    return NULL;
3997 	  else
3998 	    return get_parm_info (false, expr);
3999 	}
4000       if (!c_parser_require (parser, CPP_COMMA,
4001 			     "expected %<;%>, %<,%> or %<)%>",
4002 			     UNKNOWN_LOCATION, false))
4003 	{
4004 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4005 	  return NULL;
4006 	}
4007       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4008 	{
4009 	  c_parser_consume_token (parser);
4010 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4011 	    {
4012 	      c_parser_consume_token (parser);
4013 	      if (bad_parm)
4014 		return NULL;
4015 	      else
4016 		return get_parm_info (true, expr);
4017 	    }
4018 	  else
4019 	    {
4020 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4021 					 "expected %<)%>");
4022 	      return NULL;
4023 	    }
4024 	}
4025     }
4026 }
4027 
4028 /* Parse a parameter declaration.  ATTRS are the attributes at the
4029    start of the declaration if it is the first parameter.  */
4030 
4031 static struct c_parm *
4032 c_parser_parameter_declaration (c_parser *parser, tree attrs)
4033 {
4034   struct c_declspecs *specs;
4035   struct c_declarator *declarator;
4036   tree prefix_attrs;
4037   tree postfix_attrs = NULL_TREE;
4038   bool dummy = false;
4039 
4040   /* Accept #pragmas between parameter declarations.  */
4041   while (c_parser_next_token_is (parser, CPP_PRAGMA))
4042     c_parser_pragma (parser, pragma_param, NULL);
4043 
4044   if (!c_parser_next_token_starts_declspecs (parser))
4045     {
4046       c_token *token = c_parser_peek_token (parser);
4047       if (parser->error)
4048 	return NULL;
4049       c_parser_set_source_position_from_token (token);
4050       if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
4051 	{
4052 	  name_hint hint = lookup_name_fuzzy (token->value,
4053 					      FUZZY_LOOKUP_TYPENAME,
4054 					      token->location);
4055 	  if (hint)
4056 	    {
4057 	      gcc_rich_location richloc (token->location);
4058 	      richloc.add_fixit_replace (hint.suggestion ());
4059 	      error_at (&richloc,
4060 			"unknown type name %qE; did you mean %qs?",
4061 			token->value, hint.suggestion ());
4062 	    }
4063 	  else
4064 	    error_at (token->location, "unknown type name %qE", token->value);
4065 	  parser->error = true;
4066 	}
4067       /* ??? In some Objective-C cases '...' isn't applicable so there
4068 	 should be a different message.  */
4069       else
4070 	c_parser_error (parser,
4071 			"expected declaration specifiers or %<...%>");
4072       c_parser_skip_to_end_of_parameter (parser);
4073       return NULL;
4074     }
4075 
4076   location_t start_loc = c_parser_peek_token (parser)->location;
4077 
4078   specs = build_null_declspecs ();
4079   if (attrs)
4080     {
4081       declspecs_add_attrs (input_location, specs, attrs);
4082       attrs = NULL_TREE;
4083     }
4084   c_parser_declspecs (parser, specs, true, true, true, true, false,
4085 		      cla_nonabstract_decl);
4086   finish_declspecs (specs);
4087   pending_xref_error ();
4088   prefix_attrs = specs->attrs;
4089   specs->attrs = NULL_TREE;
4090   declarator = c_parser_declarator (parser,
4091 				    specs->typespec_kind != ctsk_none,
4092 				    C_DTR_PARM, &dummy);
4093   if (declarator == NULL)
4094     {
4095       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4096       return NULL;
4097     }
4098   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4099     postfix_attrs = c_parser_attributes (parser);
4100 
4101   /* Generate a location for the parameter, ranging from the start of the
4102      initial token to the end of the final token.
4103 
4104      If we have a identifier, then use it for the caret location, e.g.
4105 
4106        extern int callee (int one, int (*two)(int, int), float three);
4107                                    ~~~~~~^~~~~~~~~~~~~~
4108 
4109      otherwise, reuse the start location for the caret location e.g.:
4110 
4111        extern int callee (int one, int (*)(int, int), float three);
4112                                    ^~~~~~~~~~~~~~~~~
4113   */
4114   location_t end_loc = parser->last_token_location;
4115 
4116   /* Find any cdk_id declarator; determine if we have an identifier.  */
4117   c_declarator *id_declarator = declarator;
4118   while (id_declarator && id_declarator->kind != cdk_id)
4119     id_declarator = id_declarator->declarator;
4120   location_t caret_loc = (id_declarator->u.id
4121 			  ? id_declarator->id_loc
4122 			  : start_loc);
4123   location_t param_loc = make_location (caret_loc, start_loc, end_loc);
4124 
4125   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
4126 		       declarator, param_loc);
4127 }
4128 
4129 /* Parse a string literal in an asm expression.  It should not be
4130    translated, and wide string literals are an error although
4131    permitted by the syntax.  This is a GNU extension.
4132 
4133    asm-string-literal:
4134      string-literal
4135 
4136    ??? At present, following the old parser, the caller needs to have
4137    set lex_untranslated_string to 1.  It would be better to follow the
4138    C++ parser rather than using this kludge.  */
4139 
4140 static tree
4141 c_parser_asm_string_literal (c_parser *parser)
4142 {
4143   tree str;
4144   int save_flag = warn_overlength_strings;
4145   warn_overlength_strings = 0;
4146   if (c_parser_next_token_is (parser, CPP_STRING))
4147     {
4148       str = c_parser_peek_token (parser)->value;
4149       c_parser_consume_token (parser);
4150     }
4151   else if (c_parser_next_token_is (parser, CPP_WSTRING))
4152     {
4153       error_at (c_parser_peek_token (parser)->location,
4154 		"wide string literal in %<asm%>");
4155       str = build_string (1, "");
4156       c_parser_consume_token (parser);
4157     }
4158   else
4159     {
4160       c_parser_error (parser, "expected string literal");
4161       str = NULL_TREE;
4162     }
4163   warn_overlength_strings = save_flag;
4164   return str;
4165 }
4166 
4167 /* Parse a simple asm expression.  This is used in restricted
4168    contexts, where a full expression with inputs and outputs does not
4169    make sense.  This is a GNU extension.
4170 
4171    simple-asm-expr:
4172      asm ( asm-string-literal )
4173 */
4174 
4175 static tree
4176 c_parser_simple_asm_expr (c_parser *parser)
4177 {
4178   tree str;
4179   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4180   /* ??? Follow the C++ parser rather than using the
4181      lex_untranslated_string kludge.  */
4182   parser->lex_untranslated_string = true;
4183   c_parser_consume_token (parser);
4184   matching_parens parens;
4185   if (!parens.require_open (parser))
4186     {
4187       parser->lex_untranslated_string = false;
4188       return NULL_TREE;
4189     }
4190   str = c_parser_asm_string_literal (parser);
4191   parser->lex_untranslated_string = false;
4192   if (!parens.require_close (parser))
4193     {
4194       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4195       return NULL_TREE;
4196     }
4197   return str;
4198 }
4199 
4200 static tree
4201 c_parser_attribute_any_word (c_parser *parser)
4202 {
4203   tree attr_name = NULL_TREE;
4204 
4205   if (c_parser_next_token_is (parser, CPP_KEYWORD))
4206     {
4207       /* ??? See comment above about what keywords are accepted here.  */
4208       bool ok;
4209       switch (c_parser_peek_token (parser)->keyword)
4210 	{
4211 	case RID_STATIC:
4212 	case RID_UNSIGNED:
4213 	case RID_LONG:
4214 	case RID_CONST:
4215 	case RID_EXTERN:
4216 	case RID_REGISTER:
4217 	case RID_TYPEDEF:
4218 	case RID_SHORT:
4219 	case RID_INLINE:
4220 	case RID_NORETURN:
4221 	case RID_VOLATILE:
4222 	case RID_SIGNED:
4223 	case RID_AUTO:
4224 	case RID_RESTRICT:
4225 	case RID_COMPLEX:
4226 	case RID_THREAD:
4227 	case RID_INT:
4228 	case RID_CHAR:
4229 	case RID_FLOAT:
4230 	case RID_DOUBLE:
4231 	case RID_VOID:
4232 	case RID_DFLOAT32:
4233 	case RID_DFLOAT64:
4234 	case RID_DFLOAT128:
4235 	CASE_RID_FLOATN_NX:
4236 	case RID_BOOL:
4237 	case RID_FRACT:
4238 	case RID_ACCUM:
4239 	case RID_SAT:
4240 	case RID_TRANSACTION_ATOMIC:
4241 	case RID_TRANSACTION_CANCEL:
4242 	case RID_ATOMIC:
4243 	case RID_AUTO_TYPE:
4244 	case RID_INT_N_0:
4245 	case RID_INT_N_1:
4246 	case RID_INT_N_2:
4247 	case RID_INT_N_3:
4248 	  ok = true;
4249 	  break;
4250 	default:
4251 	  ok = false;
4252 	  break;
4253 	}
4254       if (!ok)
4255 	return NULL_TREE;
4256 
4257       /* Accept __attribute__((__const)) as __attribute__((const)) etc.  */
4258       attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
4259     }
4260   else if (c_parser_next_token_is (parser, CPP_NAME))
4261     attr_name = c_parser_peek_token (parser)->value;
4262 
4263   return attr_name;
4264 }
4265 
4266 /* Parse (possibly empty) attributes.  This is a GNU extension.
4267 
4268    attributes:
4269      empty
4270      attributes attribute
4271 
4272    attribute:
4273      __attribute__ ( ( attribute-list ) )
4274 
4275    attribute-list:
4276      attrib
4277      attribute_list , attrib
4278 
4279    attrib:
4280      empty
4281      any-word
4282      any-word ( identifier )
4283      any-word ( identifier , nonempty-expr-list )
4284      any-word ( expr-list )
4285 
4286    where the "identifier" must not be declared as a type, and
4287    "any-word" may be any identifier (including one declared as a
4288    type), a reserved word storage class specifier, type specifier or
4289    type qualifier.  ??? This still leaves out most reserved keywords
4290    (following the old parser), shouldn't we include them, and why not
4291    allow identifiers declared as types to start the arguments?  */
4292 
4293 static tree
4294 c_parser_attributes (c_parser *parser)
4295 {
4296   tree attrs = NULL_TREE;
4297   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4298     {
4299       /* ??? Follow the C++ parser rather than using the
4300 	 lex_untranslated_string kludge.  */
4301       parser->lex_untranslated_string = true;
4302       /* Consume the `__attribute__' keyword.  */
4303       c_parser_consume_token (parser);
4304       /* Look for the two `(' tokens.  */
4305       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4306 	{
4307 	  parser->lex_untranslated_string = false;
4308 	  return attrs;
4309 	}
4310       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4311 	{
4312 	  parser->lex_untranslated_string = false;
4313 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4314 	  return attrs;
4315 	}
4316       /* Parse the attribute list.  */
4317       while (c_parser_next_token_is (parser, CPP_COMMA)
4318 	     || c_parser_next_token_is (parser, CPP_NAME)
4319 	     || c_parser_next_token_is (parser, CPP_KEYWORD))
4320 	{
4321 	  tree attr, attr_name, attr_args;
4322 	  vec<tree, va_gc> *expr_list;
4323 	  if (c_parser_next_token_is (parser, CPP_COMMA))
4324 	    {
4325 	      c_parser_consume_token (parser);
4326 	      continue;
4327 	    }
4328 
4329 	  attr_name = c_parser_attribute_any_word (parser);
4330 	  if (attr_name == NULL)
4331 	    break;
4332 	  attr_name = canonicalize_attr_name (attr_name);
4333 	  c_parser_consume_token (parser);
4334 	  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
4335 	    {
4336 	      attr = build_tree_list (attr_name, NULL_TREE);
4337 	      /* Add this attribute to the list.  */
4338 	      attrs = chainon (attrs, attr);
4339 	      /* If the next token isn't a comma, we're done.  */
4340 	      if (!c_parser_next_token_is (parser, CPP_COMMA))
4341 		break;
4342 	      continue;
4343 	    }
4344 	  c_parser_consume_token (parser);
4345 	  /* Parse the attribute contents.  If they start with an
4346 	     identifier which is followed by a comma or close
4347 	     parenthesis, then the arguments start with that
4348 	     identifier; otherwise they are an expression list.
4349 	     In objective-c the identifier may be a classname.  */
4350 	  if (c_parser_next_token_is (parser, CPP_NAME)
4351 	      && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4352 		  || (c_dialect_objc ()
4353 		      && c_parser_peek_token (parser)->id_kind
4354 			 == C_ID_CLASSNAME))
4355 	      && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4356 		  || (c_parser_peek_2nd_token (parser)->type
4357 		      == CPP_CLOSE_PAREN))
4358 	      && (attribute_takes_identifier_p (attr_name)
4359 		  || (c_dialect_objc ()
4360 		      && c_parser_peek_token (parser)->id_kind
4361 			 == C_ID_CLASSNAME)))
4362 	    {
4363 	      tree arg1 = c_parser_peek_token (parser)->value;
4364 	      c_parser_consume_token (parser);
4365 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4366 		attr_args = build_tree_list (NULL_TREE, arg1);
4367 	      else
4368 		{
4369 		  tree tree_list;
4370 		  c_parser_consume_token (parser);
4371 		  expr_list = c_parser_expr_list (parser, false, true,
4372 						  NULL, NULL, NULL, NULL);
4373 		  tree_list = build_tree_list_vec (expr_list);
4374 		  attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4375 		  release_tree_vector (expr_list);
4376 		}
4377 	    }
4378 	  else
4379 	    {
4380 	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4381 		attr_args = NULL_TREE;
4382 	      else
4383 		{
4384 		  expr_list = c_parser_expr_list (parser, false, true,
4385 						  NULL, NULL, NULL, NULL);
4386 		  attr_args = build_tree_list_vec (expr_list);
4387 		  release_tree_vector (expr_list);
4388 		}
4389 	    }
4390 
4391 	  attr = build_tree_list (attr_name, attr_args);
4392 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4393 	    c_parser_consume_token (parser);
4394 	  else
4395 	    {
4396 	      parser->lex_untranslated_string = false;
4397 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4398 					 "expected %<)%>");
4399 	      return attrs;
4400 	    }
4401 	  /* Add this attribute to the list.  */
4402 	  attrs = chainon (attrs, attr);
4403 	  /* If the next token isn't a comma, we're done.  */
4404 	  if (!c_parser_next_token_is (parser, CPP_COMMA))
4405 	    break;
4406 	}
4407       /* Look for the two `)' tokens.  */
4408       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4409 	c_parser_consume_token (parser);
4410       else
4411 	{
4412 	  parser->lex_untranslated_string = false;
4413 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4414 				     "expected %<)%>");
4415 	  return attrs;
4416 	}
4417       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4418 	c_parser_consume_token (parser);
4419       else
4420 	{
4421 	  parser->lex_untranslated_string = false;
4422 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4423 				     "expected %<)%>");
4424 	  return attrs;
4425 	}
4426       parser->lex_untranslated_string = false;
4427     }
4428 
4429   return attrs;
4430 }
4431 
4432 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7).  ALIGNAS_OK
4433    says whether alignment specifiers are OK (only in cases that might
4434    be the type name of a compound literal).
4435 
4436    type-name:
4437      specifier-qualifier-list abstract-declarator[opt]
4438 */
4439 
4440 struct c_type_name *
4441 c_parser_type_name (c_parser *parser, bool alignas_ok)
4442 {
4443   struct c_declspecs *specs = build_null_declspecs ();
4444   struct c_declarator *declarator;
4445   struct c_type_name *ret;
4446   bool dummy = false;
4447   c_parser_declspecs (parser, specs, false, true, true, alignas_ok, false,
4448 		      cla_prefer_type);
4449   if (!specs->declspecs_seen_p)
4450     {
4451       c_parser_error (parser, "expected specifier-qualifier-list");
4452       return NULL;
4453     }
4454   if (specs->type != error_mark_node)
4455     {
4456       pending_xref_error ();
4457       finish_declspecs (specs);
4458     }
4459   declarator = c_parser_declarator (parser,
4460 				    specs->typespec_kind != ctsk_none,
4461 				    C_DTR_ABSTRACT, &dummy);
4462   if (declarator == NULL)
4463     return NULL;
4464   ret = XOBNEW (&parser_obstack, struct c_type_name);
4465   ret->specs = specs;
4466   ret->declarator = declarator;
4467   return ret;
4468 }
4469 
4470 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4471 
4472    initializer:
4473      assignment-expression
4474      { initializer-list }
4475      { initializer-list , }
4476 
4477    initializer-list:
4478      designation[opt] initializer
4479      initializer-list , designation[opt] initializer
4480 
4481    designation:
4482      designator-list =
4483 
4484    designator-list:
4485      designator
4486      designator-list designator
4487 
4488    designator:
4489      array-designator
4490      . identifier
4491 
4492    array-designator:
4493      [ constant-expression ]
4494 
4495    GNU extensions:
4496 
4497    initializer:
4498      { }
4499 
4500    designation:
4501      array-designator
4502      identifier :
4503 
4504    array-designator:
4505      [ constant-expression ... constant-expression ]
4506 
4507    Any expression without commas is accepted in the syntax for the
4508    constant-expressions, with non-constant expressions rejected later.
4509 
4510    This function is only used for top-level initializers; for nested
4511    ones, see c_parser_initval.  */
4512 
4513 static struct c_expr
4514 c_parser_initializer (c_parser *parser)
4515 {
4516   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4517     return c_parser_braced_init (parser, NULL_TREE, false, NULL);
4518   else
4519     {
4520       struct c_expr ret;
4521       location_t loc = c_parser_peek_token (parser)->location;
4522       ret = c_parser_expr_no_commas (parser, NULL);
4523       if (TREE_CODE (ret.value) != STRING_CST
4524 	  && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4525 	ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4526       return ret;
4527     }
4528 }
4529 
4530 /* The location of the last comma within the current initializer list,
4531    or UNKNOWN_LOCATION if not within one.  */
4532 
4533 location_t last_init_list_comma;
4534 
4535 /* Parse a braced initializer list.  TYPE is the type specified for a
4536    compound literal, and NULL_TREE for other initializers and for
4537    nested braced lists.  NESTED_P is true for nested braced lists,
4538    false for the list of a compound literal or the list that is the
4539    top-level initializer in a declaration.  */
4540 
4541 static struct c_expr
4542 c_parser_braced_init (c_parser *parser, tree type, bool nested_p,
4543 		      struct obstack *outer_obstack)
4544 {
4545   struct c_expr ret;
4546   struct obstack braced_init_obstack;
4547   location_t brace_loc = c_parser_peek_token (parser)->location;
4548   gcc_obstack_init (&braced_init_obstack);
4549   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4550   matching_braces braces;
4551   braces.consume_open (parser);
4552   if (nested_p)
4553     {
4554       finish_implicit_inits (brace_loc, outer_obstack);
4555       push_init_level (brace_loc, 0, &braced_init_obstack);
4556     }
4557   else
4558     really_start_incremental_init (type);
4559   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4560     {
4561       pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4562     }
4563   else
4564     {
4565       /* Parse a non-empty initializer list, possibly with a trailing
4566 	 comma.  */
4567       while (true)
4568 	{
4569 	  c_parser_initelt (parser, &braced_init_obstack);
4570 	  if (parser->error)
4571 	    break;
4572 	  if (c_parser_next_token_is (parser, CPP_COMMA))
4573 	    {
4574 	      last_init_list_comma = c_parser_peek_token (parser)->location;
4575 	      c_parser_consume_token (parser);
4576 	    }
4577 	  else
4578 	    break;
4579 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4580 	    break;
4581 	}
4582     }
4583   c_token *next_tok = c_parser_peek_token (parser);
4584   if (next_tok->type != CPP_CLOSE_BRACE)
4585     {
4586       ret.set_error ();
4587       ret.original_code = ERROR_MARK;
4588       ret.original_type = NULL;
4589       braces.skip_until_found_close (parser);
4590       pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma);
4591       obstack_free (&braced_init_obstack, NULL);
4592       return ret;
4593     }
4594   location_t close_loc = next_tok->location;
4595   c_parser_consume_token (parser);
4596   ret = pop_init_level (brace_loc, 0, &braced_init_obstack, close_loc);
4597   obstack_free (&braced_init_obstack, NULL);
4598   set_c_expr_source_range (&ret, brace_loc, close_loc);
4599   return ret;
4600 }
4601 
4602 /* Parse a nested initializer, including designators.  */
4603 
4604 static void
4605 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4606 {
4607   /* Parse any designator or designator list.  A single array
4608      designator may have the subsequent "=" omitted in GNU C, but a
4609      longer list or a structure member designator may not.  */
4610   if (c_parser_next_token_is (parser, CPP_NAME)
4611       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4612     {
4613       /* Old-style structure member designator.  */
4614       set_init_label (c_parser_peek_token (parser)->location,
4615 		      c_parser_peek_token (parser)->value,
4616 		      c_parser_peek_token (parser)->location,
4617 		      braced_init_obstack);
4618       /* Use the colon as the error location.  */
4619       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4620 	       "obsolete use of designated initializer with %<:%>");
4621       c_parser_consume_token (parser);
4622       c_parser_consume_token (parser);
4623     }
4624   else
4625     {
4626       /* des_seen is 0 if there have been no designators, 1 if there
4627 	 has been a single array designator and 2 otherwise.  */
4628       int des_seen = 0;
4629       /* Location of a designator.  */
4630       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4631       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4632 	     || c_parser_next_token_is (parser, CPP_DOT))
4633 	{
4634 	  int des_prev = des_seen;
4635 	  if (!des_seen)
4636 	    des_loc = c_parser_peek_token (parser)->location;
4637 	  if (des_seen < 2)
4638 	    des_seen++;
4639 	  if (c_parser_next_token_is (parser, CPP_DOT))
4640 	    {
4641 	      des_seen = 2;
4642 	      c_parser_consume_token (parser);
4643 	      if (c_parser_next_token_is (parser, CPP_NAME))
4644 		{
4645 		  set_init_label (des_loc, c_parser_peek_token (parser)->value,
4646 				  c_parser_peek_token (parser)->location,
4647 				  braced_init_obstack);
4648 		  c_parser_consume_token (parser);
4649 		}
4650 	      else
4651 		{
4652 		  struct c_expr init;
4653 		  init.set_error ();
4654 		  init.original_code = ERROR_MARK;
4655 		  init.original_type = NULL;
4656 		  c_parser_error (parser, "expected identifier");
4657 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4658 		  process_init_element (input_location, init, false,
4659 					braced_init_obstack);
4660 		  return;
4661 		}
4662 	    }
4663 	  else
4664 	    {
4665 	      tree first, second;
4666 	      location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4667 	      location_t array_index_loc = UNKNOWN_LOCATION;
4668 	      /* ??? Following the old parser, [ objc-receiver
4669 		 objc-message-args ] is accepted as an initializer,
4670 		 being distinguished from a designator by what follows
4671 		 the first assignment expression inside the square
4672 		 brackets, but after a first array designator a
4673 		 subsequent square bracket is for Objective-C taken to
4674 		 start an expression, using the obsolete form of
4675 		 designated initializer without '=', rather than
4676 		 possibly being a second level of designation: in LALR
4677 		 terms, the '[' is shifted rather than reducing
4678 		 designator to designator-list.  */
4679 	      if (des_prev == 1 && c_dialect_objc ())
4680 		{
4681 		  des_seen = des_prev;
4682 		  break;
4683 		}
4684 	      if (des_prev == 0 && c_dialect_objc ())
4685 		{
4686 		  /* This might be an array designator or an
4687 		     Objective-C message expression.  If the former,
4688 		     continue parsing here; if the latter, parse the
4689 		     remainder of the initializer given the starting
4690 		     primary-expression.  ??? It might make sense to
4691 		     distinguish when des_prev == 1 as well; see
4692 		     previous comment.  */
4693 		  tree rec, args;
4694 		  struct c_expr mexpr;
4695 		  c_parser_consume_token (parser);
4696 		  if (c_parser_peek_token (parser)->type == CPP_NAME
4697 		      && ((c_parser_peek_token (parser)->id_kind
4698 			   == C_ID_TYPENAME)
4699 			  || (c_parser_peek_token (parser)->id_kind
4700 			      == C_ID_CLASSNAME)))
4701 		    {
4702 		      /* Type name receiver.  */
4703 		      tree id = c_parser_peek_token (parser)->value;
4704 		      c_parser_consume_token (parser);
4705 		      rec = objc_get_class_reference (id);
4706 		      goto parse_message_args;
4707 		    }
4708 		  first = c_parser_expr_no_commas (parser, NULL).value;
4709 		  mark_exp_read (first);
4710 		  if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4711 		      || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4712 		    goto array_desig_after_first;
4713 		  /* Expression receiver.  So far only one part
4714 		     without commas has been parsed; there might be
4715 		     more of the expression.  */
4716 		  rec = first;
4717 		  while (c_parser_next_token_is (parser, CPP_COMMA))
4718 		    {
4719 		      struct c_expr next;
4720 		      location_t comma_loc, exp_loc;
4721 		      comma_loc = c_parser_peek_token (parser)->location;
4722 		      c_parser_consume_token (parser);
4723 		      exp_loc = c_parser_peek_token (parser)->location;
4724 		      next = c_parser_expr_no_commas (parser, NULL);
4725 		      next = convert_lvalue_to_rvalue (exp_loc, next,
4726 						       true, true);
4727 		      rec = build_compound_expr (comma_loc, rec, next.value);
4728 		    }
4729 		parse_message_args:
4730 		  /* Now parse the objc-message-args.  */
4731 		  args = c_parser_objc_message_args (parser);
4732 		  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4733 					     "expected %<]%>");
4734 		  mexpr.value
4735 		    = objc_build_message_expr (rec, args);
4736 		  mexpr.original_code = ERROR_MARK;
4737 		  mexpr.original_type = NULL;
4738 		  /* Now parse and process the remainder of the
4739 		     initializer, starting with this message
4740 		     expression as a primary-expression.  */
4741 		  c_parser_initval (parser, &mexpr, braced_init_obstack);
4742 		  return;
4743 		}
4744 	      c_parser_consume_token (parser);
4745 	      array_index_loc = c_parser_peek_token (parser)->location;
4746 	      first = c_parser_expr_no_commas (parser, NULL).value;
4747 	      mark_exp_read (first);
4748 	    array_desig_after_first:
4749 	      if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4750 		{
4751 		  ellipsis_loc = c_parser_peek_token (parser)->location;
4752 		  c_parser_consume_token (parser);
4753 		  second = c_parser_expr_no_commas (parser, NULL).value;
4754 		  mark_exp_read (second);
4755 		}
4756 	      else
4757 		second = NULL_TREE;
4758 	      if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4759 		{
4760 		  c_parser_consume_token (parser);
4761 		  set_init_index (array_index_loc, first, second,
4762 				  braced_init_obstack);
4763 		  if (second)
4764 		    pedwarn (ellipsis_loc, OPT_Wpedantic,
4765 			     "ISO C forbids specifying range of elements to initialize");
4766 		}
4767 	      else
4768 		c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4769 					   "expected %<]%>");
4770 	    }
4771 	}
4772       if (des_seen >= 1)
4773 	{
4774 	  if (c_parser_next_token_is (parser, CPP_EQ))
4775 	    {
4776 	      pedwarn_c90 (des_loc, OPT_Wpedantic,
4777 			   "ISO C90 forbids specifying subobject "
4778 			   "to initialize");
4779 	      c_parser_consume_token (parser);
4780 	    }
4781 	  else
4782 	    {
4783 	      if (des_seen == 1)
4784 		pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4785 			 "obsolete use of designated initializer without %<=%>");
4786 	      else
4787 		{
4788 		  struct c_expr init;
4789 		  init.set_error ();
4790 		  init.original_code = ERROR_MARK;
4791 		  init.original_type = NULL;
4792 		  c_parser_error (parser, "expected %<=%>");
4793 		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4794 		  process_init_element (input_location, init, false,
4795 					braced_init_obstack);
4796 		  return;
4797 		}
4798 	    }
4799 	}
4800     }
4801   c_parser_initval (parser, NULL, braced_init_obstack);
4802 }
4803 
4804 /* Parse a nested initializer; as c_parser_initializer but parses
4805    initializers within braced lists, after any designators have been
4806    applied.  If AFTER is not NULL then it is an Objective-C message
4807    expression which is the primary-expression starting the
4808    initializer.  */
4809 
4810 static void
4811 c_parser_initval (c_parser *parser, struct c_expr *after,
4812 		  struct obstack * braced_init_obstack)
4813 {
4814   struct c_expr init;
4815   gcc_assert (!after || c_dialect_objc ());
4816   location_t loc = c_parser_peek_token (parser)->location;
4817 
4818   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4819     init = c_parser_braced_init (parser, NULL_TREE, true,
4820 				 braced_init_obstack);
4821   else
4822     {
4823       init = c_parser_expr_no_commas (parser, after);
4824       if (init.value != NULL_TREE
4825 	  && TREE_CODE (init.value) != STRING_CST
4826 	  && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4827 	init = convert_lvalue_to_rvalue (loc, init, true, true);
4828     }
4829   process_init_element (loc, init, false, braced_init_obstack);
4830 }
4831 
4832 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4833    C99 6.8.2, C11 6.8.2).
4834 
4835    compound-statement:
4836      { block-item-list[opt] }
4837      { label-declarations block-item-list }
4838 
4839    block-item-list:
4840      block-item
4841      block-item-list block-item
4842 
4843    block-item:
4844      nested-declaration
4845      statement
4846 
4847    nested-declaration:
4848      declaration
4849 
4850    GNU extensions:
4851 
4852    compound-statement:
4853      { label-declarations block-item-list }
4854 
4855    nested-declaration:
4856      __extension__ nested-declaration
4857      nested-function-definition
4858 
4859    label-declarations:
4860      label-declaration
4861      label-declarations label-declaration
4862 
4863    label-declaration:
4864      __label__ identifier-list ;
4865 
4866    Allowing the mixing of declarations and code is new in C99.  The
4867    GNU syntax also permits (not shown above) labels at the end of
4868    compound statements, which yield an error.  We don't allow labels
4869    on declarations; this might seem like a natural extension, but
4870    there would be a conflict between attributes on the label and
4871    prefix attributes on the declaration.  ??? The syntax follows the
4872    old parser in requiring something after label declarations.
4873    Although they are erroneous if the labels declared aren't defined,
4874    is it useful for the syntax to be this way?
4875 
4876    OpenACC:
4877 
4878    block-item:
4879      openacc-directive
4880 
4881    openacc-directive:
4882      update-directive
4883 
4884    OpenMP:
4885 
4886    block-item:
4887      openmp-directive
4888 
4889    openmp-directive:
4890      barrier-directive
4891      flush-directive
4892      taskwait-directive
4893      taskyield-directive
4894      cancel-directive
4895      cancellation-point-directive  */
4896 
4897 static tree
4898 c_parser_compound_statement (c_parser *parser)
4899 {
4900   tree stmt;
4901   location_t brace_loc;
4902   brace_loc = c_parser_peek_token (parser)->location;
4903   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4904     {
4905       /* Ensure a scope is entered and left anyway to avoid confusion
4906 	 if we have just prepared to enter a function body.  */
4907       stmt = c_begin_compound_stmt (true);
4908       c_end_compound_stmt (brace_loc, stmt, true);
4909       return error_mark_node;
4910     }
4911   stmt = c_begin_compound_stmt (true);
4912   c_parser_compound_statement_nostart (parser);
4913 
4914   return c_end_compound_stmt (brace_loc, stmt, true);
4915 }
4916 
4917 /* Parse a compound statement except for the opening brace.  This is
4918    used for parsing both compound statements and statement expressions
4919    (which follow different paths to handling the opening).  */
4920 
4921 static void
4922 c_parser_compound_statement_nostart (c_parser *parser)
4923 {
4924   bool last_stmt = false;
4925   bool last_label = false;
4926   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4927   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4928   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4929     {
4930       add_debug_begin_stmt (c_parser_peek_token (parser)->location);
4931       c_parser_consume_token (parser);
4932       return;
4933     }
4934   mark_valid_location_for_stdc_pragma (true);
4935   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4936     {
4937       /* Read zero or more forward-declarations for labels that nested
4938 	 functions can jump to.  */
4939       mark_valid_location_for_stdc_pragma (false);
4940       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4941 	{
4942 	  label_loc = c_parser_peek_token (parser)->location;
4943 	  c_parser_consume_token (parser);
4944 	  /* Any identifiers, including those declared as type names,
4945 	     are OK here.  */
4946 	  while (true)
4947 	    {
4948 	      tree label;
4949 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
4950 		{
4951 		  c_parser_error (parser, "expected identifier");
4952 		  break;
4953 		}
4954 	      label
4955 		= declare_label (c_parser_peek_token (parser)->value);
4956 	      C_DECLARED_LABEL_FLAG (label) = 1;
4957 	      add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4958 	      c_parser_consume_token (parser);
4959 	      if (c_parser_next_token_is (parser, CPP_COMMA))
4960 		c_parser_consume_token (parser);
4961 	      else
4962 		break;
4963 	    }
4964 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4965 	}
4966       pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4967     }
4968   /* We must now have at least one statement, label or declaration.  */
4969   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4970     {
4971       mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4972       c_parser_error (parser, "expected declaration or statement");
4973       c_parser_consume_token (parser);
4974       return;
4975     }
4976   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4977     {
4978       location_t loc = c_parser_peek_token (parser)->location;
4979       loc = expansion_point_location_if_in_system_header (loc);
4980       if (c_parser_next_token_is_keyword (parser, RID_CASE)
4981 	  || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4982 	  || (c_parser_next_token_is (parser, CPP_NAME)
4983 	      && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4984 	{
4985 	  if (c_parser_next_token_is_keyword (parser, RID_CASE))
4986 	    label_loc = c_parser_peek_2nd_token (parser)->location;
4987 	  else
4988 	    label_loc = c_parser_peek_token (parser)->location;
4989 	  last_label = true;
4990 	  last_stmt = false;
4991 	  mark_valid_location_for_stdc_pragma (false);
4992 	  c_parser_label (parser);
4993 	}
4994       else if (!last_label
4995 	       && c_parser_next_tokens_start_declaration (parser))
4996 	{
4997 	  last_label = false;
4998 	  mark_valid_location_for_stdc_pragma (false);
4999 	  bool fallthru_attr_p = false;
5000 	  c_parser_declaration_or_fndef (parser, true, true, true, true,
5001 					 true, NULL, vNULL, NULL,
5002 					 &fallthru_attr_p);
5003 	  if (last_stmt && !fallthru_attr_p)
5004 	    pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
5005 			 "ISO C90 forbids mixed declarations and code");
5006 	  last_stmt = fallthru_attr_p;
5007 	}
5008       else if (!last_label
5009 	       && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5010 	{
5011 	  /* __extension__ can start a declaration, but is also an
5012 	     unary operator that can start an expression.  Consume all
5013 	     but the last of a possible series of __extension__ to
5014 	     determine which.  */
5015 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5016 		 && (c_parser_peek_2nd_token (parser)->keyword
5017 		     == RID_EXTENSION))
5018 	    c_parser_consume_token (parser);
5019 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5020 	    {
5021 	      int ext;
5022 	      ext = disable_extension_diagnostics ();
5023 	      c_parser_consume_token (parser);
5024 	      last_label = false;
5025 	      mark_valid_location_for_stdc_pragma (false);
5026 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
5027 					     true, NULL, vNULL);
5028 	      /* Following the old parser, __extension__ does not
5029 		 disable this diagnostic.  */
5030 	      restore_extension_diagnostics (ext);
5031 	      if (last_stmt)
5032 		pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
5033 			     "ISO C90 forbids mixed declarations and code");
5034 	      last_stmt = false;
5035 	    }
5036 	  else
5037 	    goto statement;
5038 	}
5039       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5040 	{
5041 	  /* External pragmas, and some omp pragmas, are not associated
5042 	     with regular c code, and so are not to be considered statements
5043 	     syntactically.  This ensures that the user doesn't put them
5044 	     places that would turn into syntax errors if the directive
5045 	     were ignored.  */
5046 	  if (c_parser_pragma (parser,
5047 			       last_label ? pragma_stmt : pragma_compound,
5048 			       NULL))
5049 	    last_label = false, last_stmt = true;
5050 	}
5051       else if (c_parser_next_token_is (parser, CPP_EOF))
5052 	{
5053 	  mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
5054 	  c_parser_error (parser, "expected declaration or statement");
5055 	  return;
5056 	}
5057       else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5058         {
5059           if (parser->in_if_block)
5060             {
5061 	      mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
5062 	      error_at (loc, "expected %<}%> before %<else%>");
5063               return;
5064             }
5065           else
5066             {
5067               error_at (loc, "%<else%> without a previous %<if%>");
5068               c_parser_consume_token (parser);
5069               continue;
5070             }
5071         }
5072       else
5073 	{
5074 	statement:
5075 	  last_label = false;
5076 	  last_stmt = true;
5077 	  mark_valid_location_for_stdc_pragma (false);
5078 	  c_parser_statement_after_labels (parser, NULL);
5079 	}
5080 
5081       parser->error = false;
5082     }
5083   if (last_label)
5084     error_at (label_loc, "label at end of compound statement");
5085   c_parser_consume_token (parser);
5086   /* Restore the value we started with.  */
5087   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
5088 }
5089 
5090 /* Parse all consecutive labels. */
5091 
5092 static void
5093 c_parser_all_labels (c_parser *parser)
5094 {
5095   while (c_parser_next_token_is_keyword (parser, RID_CASE)
5096 	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
5097 	 || (c_parser_next_token_is (parser, CPP_NAME)
5098 	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
5099     c_parser_label (parser);
5100 }
5101 
5102 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5103 
5104    label:
5105      identifier : attributes[opt]
5106      case constant-expression :
5107      default :
5108 
5109    GNU extensions:
5110 
5111    label:
5112      case constant-expression ... constant-expression :
5113 
5114    The use of attributes on labels is a GNU extension.  The syntax in
5115    GNU C accepts any expressions without commas, non-constant
5116    expressions being rejected later.  */
5117 
5118 static void
5119 c_parser_label (c_parser *parser)
5120 {
5121   location_t loc1 = c_parser_peek_token (parser)->location;
5122   tree label = NULL_TREE;
5123 
5124   /* Remember whether this case or a user-defined label is allowed to fall
5125      through to.  */
5126   bool fallthrough_p = c_parser_peek_token (parser)->flags & PREV_FALLTHROUGH;
5127 
5128   if (c_parser_next_token_is_keyword (parser, RID_CASE))
5129     {
5130       tree exp1, exp2;
5131       c_parser_consume_token (parser);
5132       exp1 = c_parser_expr_no_commas (parser, NULL).value;
5133       if (c_parser_next_token_is (parser, CPP_COLON))
5134 	{
5135 	  c_parser_consume_token (parser);
5136 	  label = do_case (loc1, exp1, NULL_TREE);
5137 	}
5138       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
5139 	{
5140 	  c_parser_consume_token (parser);
5141 	  exp2 = c_parser_expr_no_commas (parser, NULL).value;
5142 	  if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5143 	    label = do_case (loc1, exp1, exp2);
5144 	}
5145       else
5146 	c_parser_error (parser, "expected %<:%> or %<...%>");
5147     }
5148   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
5149     {
5150       c_parser_consume_token (parser);
5151       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5152 	label = do_case (loc1, NULL_TREE, NULL_TREE);
5153     }
5154   else
5155     {
5156       tree name = c_parser_peek_token (parser)->value;
5157       tree tlab;
5158       tree attrs;
5159       location_t loc2 = c_parser_peek_token (parser)->location;
5160       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
5161       c_parser_consume_token (parser);
5162       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
5163       c_parser_consume_token (parser);
5164       attrs = c_parser_attributes (parser);
5165       tlab = define_label (loc2, name);
5166       if (tlab)
5167 	{
5168 	  decl_attributes (&tlab, attrs, 0);
5169 	  label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
5170 	}
5171     }
5172   if (label)
5173     {
5174       if (TREE_CODE (label) == LABEL_EXPR)
5175 	FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label)) = fallthrough_p;
5176       else
5177 	FALLTHROUGH_LABEL_P (CASE_LABEL (label)) = fallthrough_p;
5178 
5179       /* Allow '__attribute__((fallthrough));'.  */
5180       if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
5181 	{
5182 	  location_t loc = c_parser_peek_token (parser)->location;
5183 	  tree attrs = c_parser_attributes (parser);
5184 	  if (attribute_fallthrough_p (attrs))
5185 	    {
5186 	      if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5187 		{
5188 		  tree fn = build_call_expr_internal_loc (loc,
5189 							  IFN_FALLTHROUGH,
5190 							  void_type_node, 0);
5191 		  add_stmt (fn);
5192 		}
5193 	      else
5194 		warning_at (loc, OPT_Wattributes, "%<fallthrough%> attribute "
5195 			    "not followed by %<;%>");
5196 	    }
5197 	  else if (attrs != NULL_TREE)
5198 	    warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>"
5199 			" can be applied to a null statement");
5200 	}
5201       if (c_parser_next_tokens_start_declaration (parser))
5202 	{
5203 	  error_at (c_parser_peek_token (parser)->location,
5204 		    "a label can only be part of a statement and "
5205 		    "a declaration is not a statement");
5206 	  c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
5207 					 /*static_assert_ok*/ true,
5208 					 /*empty_ok*/ true, /*nested*/ true,
5209 					 /*start_attr_ok*/ true, NULL,
5210 					 vNULL);
5211 	}
5212     }
5213 }
5214 
5215 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5216 
5217    statement:
5218      labeled-statement
5219      compound-statement
5220      expression-statement
5221      selection-statement
5222      iteration-statement
5223      jump-statement
5224 
5225    labeled-statement:
5226      label statement
5227 
5228    expression-statement:
5229      expression[opt] ;
5230 
5231    selection-statement:
5232      if-statement
5233      switch-statement
5234 
5235    iteration-statement:
5236      while-statement
5237      do-statement
5238      for-statement
5239 
5240    jump-statement:
5241      goto identifier ;
5242      continue ;
5243      break ;
5244      return expression[opt] ;
5245 
5246    GNU extensions:
5247 
5248    statement:
5249      asm-statement
5250 
5251    jump-statement:
5252      goto * expression ;
5253 
5254    expression-statement:
5255      attributes ;
5256 
5257    Objective-C:
5258 
5259    statement:
5260      objc-throw-statement
5261      objc-try-catch-statement
5262      objc-synchronized-statement
5263 
5264    objc-throw-statement:
5265      @throw expression ;
5266      @throw ;
5267 
5268    OpenACC:
5269 
5270    statement:
5271      openacc-construct
5272 
5273    openacc-construct:
5274      parallel-construct
5275      kernels-construct
5276      data-construct
5277      loop-construct
5278 
5279    parallel-construct:
5280      parallel-directive structured-block
5281 
5282    kernels-construct:
5283      kernels-directive structured-block
5284 
5285    data-construct:
5286      data-directive structured-block
5287 
5288    loop-construct:
5289      loop-directive structured-block
5290 
5291    OpenMP:
5292 
5293    statement:
5294      openmp-construct
5295 
5296    openmp-construct:
5297      parallel-construct
5298      for-construct
5299      simd-construct
5300      for-simd-construct
5301      sections-construct
5302      single-construct
5303      parallel-for-construct
5304      parallel-for-simd-construct
5305      parallel-sections-construct
5306      master-construct
5307      critical-construct
5308      atomic-construct
5309      ordered-construct
5310 
5311    parallel-construct:
5312      parallel-directive structured-block
5313 
5314    for-construct:
5315      for-directive iteration-statement
5316 
5317    simd-construct:
5318      simd-directive iteration-statements
5319 
5320    for-simd-construct:
5321      for-simd-directive iteration-statements
5322 
5323    sections-construct:
5324      sections-directive section-scope
5325 
5326    single-construct:
5327      single-directive structured-block
5328 
5329    parallel-for-construct:
5330      parallel-for-directive iteration-statement
5331 
5332    parallel-for-simd-construct:
5333      parallel-for-simd-directive iteration-statement
5334 
5335    parallel-sections-construct:
5336      parallel-sections-directive section-scope
5337 
5338    master-construct:
5339      master-directive structured-block
5340 
5341    critical-construct:
5342      critical-directive structured-block
5343 
5344    atomic-construct:
5345      atomic-directive expression-statement
5346 
5347    ordered-construct:
5348      ordered-directive structured-block
5349 
5350    Transactional Memory:
5351 
5352    statement:
5353      transaction-statement
5354      transaction-cancel-statement
5355 
5356    IF_P is used to track whether there's a (possibly labeled) if statement
5357    which is not enclosed in braces and has an else clause.  This is used to
5358    implement -Wparentheses.  */
5359 
5360 static void
5361 c_parser_statement (c_parser *parser, bool *if_p, location_t *loc_after_labels)
5362 {
5363   c_parser_all_labels (parser);
5364   if (loc_after_labels)
5365     *loc_after_labels = c_parser_peek_token (parser)->location;
5366   c_parser_statement_after_labels (parser, if_p, NULL);
5367 }
5368 
5369 /* Parse a statement, other than a labeled statement.  CHAIN is a vector
5370    of if-else-if conditions.
5371 
5372    IF_P is used to track whether there's a (possibly labeled) if statement
5373    which is not enclosed in braces and has an else clause.  This is used to
5374    implement -Wparentheses.  */
5375 
5376 static void
5377 c_parser_statement_after_labels (c_parser *parser, bool *if_p,
5378 				 vec<tree> *chain)
5379 {
5380   location_t loc = c_parser_peek_token (parser)->location;
5381   tree stmt = NULL_TREE;
5382   bool in_if_block = parser->in_if_block;
5383   parser->in_if_block = false;
5384   if (if_p != NULL)
5385     *if_p = false;
5386 
5387   if (c_parser_peek_token (parser)->type != CPP_OPEN_BRACE)
5388     add_debug_begin_stmt (loc);
5389 
5390   switch (c_parser_peek_token (parser)->type)
5391     {
5392     case CPP_OPEN_BRACE:
5393       add_stmt (c_parser_compound_statement (parser));
5394       break;
5395     case CPP_KEYWORD:
5396       switch (c_parser_peek_token (parser)->keyword)
5397 	{
5398 	case RID_IF:
5399 	  c_parser_if_statement (parser, if_p, chain);
5400 	  break;
5401 	case RID_SWITCH:
5402 	  c_parser_switch_statement (parser, if_p);
5403 	  break;
5404 	case RID_WHILE:
5405 	  c_parser_while_statement (parser, false, 0, if_p);
5406 	  break;
5407 	case RID_DO:
5408 	  c_parser_do_statement (parser, 0, false);
5409 	  break;
5410 	case RID_FOR:
5411 	  c_parser_for_statement (parser, false, 0, if_p);
5412 	  break;
5413 	case RID_GOTO:
5414 	  c_parser_consume_token (parser);
5415 	  if (c_parser_next_token_is (parser, CPP_NAME))
5416 	    {
5417 	      stmt = c_finish_goto_label (loc,
5418 					  c_parser_peek_token (parser)->value);
5419 	      c_parser_consume_token (parser);
5420 	    }
5421 	  else if (c_parser_next_token_is (parser, CPP_MULT))
5422 	    {
5423 	      struct c_expr val;
5424 
5425 	      c_parser_consume_token (parser);
5426 	      val = c_parser_expression (parser);
5427 	      val = convert_lvalue_to_rvalue (loc, val, false, true);
5428 	      stmt = c_finish_goto_ptr (loc, val.value);
5429 	    }
5430 	  else
5431 	    c_parser_error (parser, "expected identifier or %<*%>");
5432 	  goto expect_semicolon;
5433 	case RID_CONTINUE:
5434 	  c_parser_consume_token (parser);
5435 	  stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5436 	  goto expect_semicolon;
5437 	case RID_BREAK:
5438 	  c_parser_consume_token (parser);
5439 	  stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5440 	  goto expect_semicolon;
5441 	case RID_RETURN:
5442 	  c_parser_consume_token (parser);
5443 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5444 	    {
5445 	      stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5446 	      c_parser_consume_token (parser);
5447 	    }
5448 	  else
5449 	    {
5450 	      location_t xloc = c_parser_peek_token (parser)->location;
5451 	      struct c_expr expr = c_parser_expression_conv (parser);
5452 	      mark_exp_read (expr.value);
5453 	      stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc),
5454 				      expr.value, expr.original_type);
5455 	      goto expect_semicolon;
5456 	    }
5457 	  break;
5458 	case RID_ASM:
5459 	  stmt = c_parser_asm_statement (parser);
5460 	  break;
5461 	case RID_TRANSACTION_ATOMIC:
5462 	case RID_TRANSACTION_RELAXED:
5463 	  stmt = c_parser_transaction (parser,
5464 	      c_parser_peek_token (parser)->keyword);
5465 	  break;
5466 	case RID_TRANSACTION_CANCEL:
5467 	  stmt = c_parser_transaction_cancel (parser);
5468 	  goto expect_semicolon;
5469 	case RID_AT_THROW:
5470 	  gcc_assert (c_dialect_objc ());
5471 	  c_parser_consume_token (parser);
5472 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5473 	    {
5474 	      stmt = objc_build_throw_stmt (loc, NULL_TREE);
5475 	      c_parser_consume_token (parser);
5476 	    }
5477 	  else
5478 	    {
5479 	      struct c_expr expr = c_parser_expression (parser);
5480 	      expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5481 	      expr.value = c_fully_fold (expr.value, false, NULL);
5482 	      stmt = objc_build_throw_stmt (loc, expr.value);
5483 	      goto expect_semicolon;
5484 	    }
5485 	  break;
5486 	case RID_AT_TRY:
5487 	  gcc_assert (c_dialect_objc ());
5488 	  c_parser_objc_try_catch_finally_statement (parser);
5489 	  break;
5490 	case RID_AT_SYNCHRONIZED:
5491 	  gcc_assert (c_dialect_objc ());
5492 	  c_parser_objc_synchronized_statement (parser);
5493 	  break;
5494 	case RID_ATTRIBUTE:
5495 	  {
5496 	    /* Allow '__attribute__((fallthrough));'.  */
5497 	    tree attrs = c_parser_attributes (parser);
5498 	    if (attribute_fallthrough_p (attrs))
5499 	      {
5500 		if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5501 		  {
5502 		    tree fn = build_call_expr_internal_loc (loc,
5503 							    IFN_FALLTHROUGH,
5504 							    void_type_node, 0);
5505 		    add_stmt (fn);
5506 		    /* Eat the ';'.  */
5507 		    c_parser_consume_token (parser);
5508 		  }
5509 		else
5510 		  warning_at (loc, OPT_Wattributes,
5511 			      "%<fallthrough%> attribute not followed "
5512 			      "by %<;%>");
5513 	      }
5514 	    else if (attrs != NULL_TREE)
5515 	      warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>"
5516 			  " can be applied to a null statement");
5517 	    break;
5518 	  }
5519 	default:
5520 	  goto expr_stmt;
5521 	}
5522       break;
5523     case CPP_SEMICOLON:
5524       c_parser_consume_token (parser);
5525       break;
5526     case CPP_CLOSE_PAREN:
5527     case CPP_CLOSE_SQUARE:
5528       /* Avoid infinite loop in error recovery:
5529 	 c_parser_skip_until_found stops at a closing nesting
5530 	 delimiter without consuming it, but here we need to consume
5531 	 it to proceed further.  */
5532       c_parser_error (parser, "expected statement");
5533       c_parser_consume_token (parser);
5534       break;
5535     case CPP_PRAGMA:
5536       c_parser_pragma (parser, pragma_stmt, if_p);
5537       break;
5538     default:
5539     expr_stmt:
5540       stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5541     expect_semicolon:
5542       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5543       break;
5544     }
5545   /* Two cases cannot and do not have line numbers associated: If stmt
5546      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5547      cannot hold line numbers.  But that's OK because the statement
5548      will either be changed to a MODIFY_EXPR during gimplification of
5549      the statement expr, or discarded.  If stmt was compound, but
5550      without new variables, we will have skipped the creation of a
5551      BIND and will have a bare STATEMENT_LIST.  But that's OK because
5552      (recursively) all of the component statements should already have
5553      line numbers assigned.  ??? Can we discard no-op statements
5554      earlier?  */
5555   if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5556     protected_set_expr_location (stmt, loc);
5557 
5558   parser->in_if_block = in_if_block;
5559 }
5560 
5561 /* Parse the condition from an if, do, while or for statements.  */
5562 
5563 static tree
5564 c_parser_condition (c_parser *parser)
5565 {
5566   location_t loc = c_parser_peek_token (parser)->location;
5567   tree cond;
5568   cond = c_parser_expression_conv (parser).value;
5569   cond = c_objc_common_truthvalue_conversion (loc, cond);
5570   cond = c_fully_fold (cond, false, NULL);
5571   if (warn_sequence_point)
5572     verify_sequence_points (cond);
5573   return cond;
5574 }
5575 
5576 /* Parse a parenthesized condition from an if, do or while statement.
5577 
5578    condition:
5579      ( expression )
5580 */
5581 static tree
5582 c_parser_paren_condition (c_parser *parser)
5583 {
5584   tree cond;
5585   matching_parens parens;
5586   if (!parens.require_open (parser))
5587     return error_mark_node;
5588   cond = c_parser_condition (parser);
5589   parens.skip_until_found_close (parser);
5590   return cond;
5591 }
5592 
5593 /* Parse a statement which is a block in C99.
5594 
5595    IF_P is used to track whether there's a (possibly labeled) if statement
5596    which is not enclosed in braces and has an else clause.  This is used to
5597    implement -Wparentheses.  */
5598 
5599 static tree
5600 c_parser_c99_block_statement (c_parser *parser, bool *if_p,
5601 			      location_t *loc_after_labels)
5602 {
5603   tree block = c_begin_compound_stmt (flag_isoc99);
5604   location_t loc = c_parser_peek_token (parser)->location;
5605   c_parser_statement (parser, if_p, loc_after_labels);
5606   return c_end_compound_stmt (loc, block, flag_isoc99);
5607 }
5608 
5609 /* Parse the body of an if statement.  This is just parsing a
5610    statement but (a) it is a block in C99, (b) we track whether the
5611    body is an if statement for the sake of -Wparentheses warnings, (c)
5612    we handle an empty body specially for the sake of -Wempty-body
5613    warnings, and (d) we call parser_compound_statement directly
5614    because c_parser_statement_after_labels resets
5615    parser->in_if_block.
5616 
5617    IF_P is used to track whether there's a (possibly labeled) if statement
5618    which is not enclosed in braces and has an else clause.  This is used to
5619    implement -Wparentheses.  */
5620 
5621 static tree
5622 c_parser_if_body (c_parser *parser, bool *if_p,
5623 		  const token_indent_info &if_tinfo)
5624 {
5625   tree block = c_begin_compound_stmt (flag_isoc99);
5626   location_t body_loc = c_parser_peek_token (parser)->location;
5627   location_t body_loc_after_labels = UNKNOWN_LOCATION;
5628   token_indent_info body_tinfo
5629     = get_token_indent_info (c_parser_peek_token (parser));
5630 
5631   c_parser_all_labels (parser);
5632   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5633     {
5634       location_t loc = c_parser_peek_token (parser)->location;
5635       add_stmt (build_empty_stmt (loc));
5636       c_parser_consume_token (parser);
5637       if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5638 	warning_at (loc, OPT_Wempty_body,
5639 		    "suggest braces around empty body in an %<if%> statement");
5640     }
5641   else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5642     add_stmt (c_parser_compound_statement (parser));
5643   else
5644     {
5645       body_loc_after_labels = c_parser_peek_token (parser)->location;
5646       c_parser_statement_after_labels (parser, if_p);
5647     }
5648 
5649   token_indent_info next_tinfo
5650     = get_token_indent_info (c_parser_peek_token (parser));
5651   warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo);
5652   if (body_loc_after_labels != UNKNOWN_LOCATION
5653       && next_tinfo.type != CPP_SEMICOLON)
5654     warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location,
5655 				    if_tinfo.location, RID_IF);
5656 
5657   return c_end_compound_stmt (body_loc, block, flag_isoc99);
5658 }
5659 
5660 /* Parse the else body of an if statement.  This is just parsing a
5661    statement but (a) it is a block in C99, (b) we handle an empty body
5662    specially for the sake of -Wempty-body warnings.  CHAIN is a vector
5663    of if-else-if conditions.  */
5664 
5665 static tree
5666 c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
5667 		    vec<tree> *chain)
5668 {
5669   location_t body_loc = c_parser_peek_token (parser)->location;
5670   tree block = c_begin_compound_stmt (flag_isoc99);
5671   token_indent_info body_tinfo
5672     = get_token_indent_info (c_parser_peek_token (parser));
5673   location_t body_loc_after_labels = UNKNOWN_LOCATION;
5674 
5675   c_parser_all_labels (parser);
5676   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5677     {
5678       location_t loc = c_parser_peek_token (parser)->location;
5679       warning_at (loc,
5680 		  OPT_Wempty_body,
5681 	         "suggest braces around empty body in an %<else%> statement");
5682       add_stmt (build_empty_stmt (loc));
5683       c_parser_consume_token (parser);
5684     }
5685   else
5686     {
5687       if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5688 	body_loc_after_labels = c_parser_peek_token (parser)->location;
5689       c_parser_statement_after_labels (parser, NULL, chain);
5690     }
5691 
5692   token_indent_info next_tinfo
5693     = get_token_indent_info (c_parser_peek_token (parser));
5694   warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo);
5695   if (body_loc_after_labels != UNKNOWN_LOCATION
5696       && next_tinfo.type != CPP_SEMICOLON)
5697     warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location,
5698 				    else_tinfo.location, RID_ELSE);
5699 
5700   return c_end_compound_stmt (body_loc, block, flag_isoc99);
5701 }
5702 
5703 /* We might need to reclassify any previously-lexed identifier, e.g.
5704    when we've left a for loop with an if-statement without else in the
5705    body - we might have used a wrong scope for the token.  See PR67784.  */
5706 
5707 static void
5708 c_parser_maybe_reclassify_token (c_parser *parser)
5709 {
5710   if (c_parser_next_token_is (parser, CPP_NAME))
5711     {
5712       c_token *token = c_parser_peek_token (parser);
5713 
5714       if (token->id_kind != C_ID_CLASSNAME)
5715 	{
5716 	  tree decl = lookup_name (token->value);
5717 
5718 	  token->id_kind = C_ID_ID;
5719 	  if (decl)
5720 	    {
5721 	      if (TREE_CODE (decl) == TYPE_DECL)
5722 		token->id_kind = C_ID_TYPENAME;
5723 	    }
5724 	  else if (c_dialect_objc ())
5725 	    {
5726 	      tree objc_interface_decl = objc_is_class_name (token->value);
5727 	      /* Objective-C class names are in the same namespace as
5728 		 variables and typedefs, and hence are shadowed by local
5729 		 declarations.  */
5730 	      if (objc_interface_decl)
5731 		{
5732 		  token->value = objc_interface_decl;
5733 		  token->id_kind = C_ID_CLASSNAME;
5734 		}
5735 	    }
5736 	}
5737     }
5738 }
5739 
5740 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5741 
5742    if-statement:
5743      if ( expression ) statement
5744      if ( expression ) statement else statement
5745 
5746    CHAIN is a vector of if-else-if conditions.
5747    IF_P is used to track whether there's a (possibly labeled) if statement
5748    which is not enclosed in braces and has an else clause.  This is used to
5749    implement -Wparentheses.  */
5750 
5751 static void
5752 c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
5753 {
5754   tree block;
5755   location_t loc;
5756   tree cond;
5757   bool nested_if = false;
5758   tree first_body, second_body;
5759   bool in_if_block;
5760 
5761   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5762   token_indent_info if_tinfo
5763     = get_token_indent_info (c_parser_peek_token (parser));
5764   c_parser_consume_token (parser);
5765   block = c_begin_compound_stmt (flag_isoc99);
5766   loc = c_parser_peek_token (parser)->location;
5767   cond = c_parser_paren_condition (parser);
5768   in_if_block = parser->in_if_block;
5769   parser->in_if_block = true;
5770   first_body = c_parser_if_body (parser, &nested_if, if_tinfo);
5771   parser->in_if_block = in_if_block;
5772 
5773   if (warn_duplicated_cond)
5774     warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain);
5775 
5776   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5777     {
5778       token_indent_info else_tinfo
5779 	= get_token_indent_info (c_parser_peek_token (parser));
5780       c_parser_consume_token (parser);
5781       if (warn_duplicated_cond)
5782 	{
5783 	  if (c_parser_next_token_is_keyword (parser, RID_IF)
5784 	      && chain == NULL)
5785 	    {
5786 	      /* We've got "if (COND) else if (COND2)".  Start the
5787 		 condition chain and add COND as the first element.  */
5788 	      chain = new vec<tree> ();
5789 	      if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond))
5790 		chain->safe_push (cond);
5791 	    }
5792 	  else if (!c_parser_next_token_is_keyword (parser, RID_IF))
5793 	    {
5794 	      /* This is if-else without subsequent if.  Zap the condition
5795 		 chain; we would have already warned at this point.  */
5796 	      delete chain;
5797 	      chain = NULL;
5798 	    }
5799 	}
5800       second_body = c_parser_else_body (parser, else_tinfo, chain);
5801       /* Set IF_P to true to indicate that this if statement has an
5802 	 else clause.  This may trigger the Wparentheses warning
5803 	 below when we get back up to the parent if statement.  */
5804       if (if_p != NULL)
5805 	*if_p = true;
5806     }
5807   else
5808     {
5809       second_body = NULL_TREE;
5810 
5811       /* Diagnose an ambiguous else if if-then-else is nested inside
5812 	 if-then.  */
5813       if (nested_if)
5814 	warning_at (loc, OPT_Wdangling_else,
5815 		    "suggest explicit braces to avoid ambiguous %<else%>");
5816 
5817       if (warn_duplicated_cond)
5818 	{
5819 	  /* This if statement does not have an else clause.  We don't
5820 	     need the condition chain anymore.  */
5821 	  delete chain;
5822 	  chain = NULL;
5823 	}
5824     }
5825   c_finish_if_stmt (loc, cond, first_body, second_body);
5826   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5827 
5828   c_parser_maybe_reclassify_token (parser);
5829 }
5830 
5831 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5832 
5833    switch-statement:
5834      switch (expression) statement
5835 */
5836 
5837 static void
5838 c_parser_switch_statement (c_parser *parser, bool *if_p)
5839 {
5840   struct c_expr ce;
5841   tree block, expr, body, save_break;
5842   location_t switch_loc = c_parser_peek_token (parser)->location;
5843   location_t switch_cond_loc;
5844   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5845   c_parser_consume_token (parser);
5846   block = c_begin_compound_stmt (flag_isoc99);
5847   bool explicit_cast_p = false;
5848   matching_parens parens;
5849   if (parens.require_open (parser))
5850     {
5851       switch_cond_loc = c_parser_peek_token (parser)->location;
5852       if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5853 	  && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5854 	explicit_cast_p = true;
5855       ce = c_parser_expression (parser);
5856       ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5857       expr = ce.value;
5858       /* ??? expr has no valid location?  */
5859       parens.skip_until_found_close (parser);
5860     }
5861   else
5862     {
5863       switch_cond_loc = UNKNOWN_LOCATION;
5864       expr = error_mark_node;
5865       ce.original_type = error_mark_node;
5866     }
5867   c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5868   save_break = c_break_label;
5869   c_break_label = NULL_TREE;
5870   location_t loc_after_labels;
5871   bool open_brace_p = c_parser_peek_token (parser)->type == CPP_OPEN_BRACE;
5872   body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
5873   location_t next_loc = c_parser_peek_token (parser)->location;
5874   if (!open_brace_p && c_parser_peek_token (parser)->type != CPP_SEMICOLON)
5875     warn_for_multistatement_macros (loc_after_labels, next_loc, switch_loc,
5876 				    RID_SWITCH);
5877   if (c_break_label)
5878     {
5879       location_t here = c_parser_peek_token (parser)->location;
5880       tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5881       SET_EXPR_LOCATION (t, here);
5882       SWITCH_BREAK_LABEL_P (c_break_label) = 1;
5883       append_to_statement_list_force (t, &body);
5884     }
5885   c_finish_case (body, ce.original_type);
5886   c_break_label = save_break;
5887   add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5888   c_parser_maybe_reclassify_token (parser);
5889 }
5890 
5891 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5892 
5893    while-statement:
5894       while (expression) statement
5895 
5896    IF_P is used to track whether there's a (possibly labeled) if statement
5897    which is not enclosed in braces and has an else clause.  This is used to
5898    implement -Wparentheses.  */
5899 
5900 static void
5901 c_parser_while_statement (c_parser *parser, bool ivdep, unsigned short unroll,
5902 			  bool *if_p)
5903 {
5904   tree block, cond, body, save_break, save_cont;
5905   location_t loc;
5906   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5907   token_indent_info while_tinfo
5908     = get_token_indent_info (c_parser_peek_token (parser));
5909   c_parser_consume_token (parser);
5910   block = c_begin_compound_stmt (flag_isoc99);
5911   loc = c_parser_peek_token (parser)->location;
5912   cond = c_parser_paren_condition (parser);
5913   if (ivdep && cond != error_mark_node)
5914     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5915 		   build_int_cst (integer_type_node,
5916 				  annot_expr_ivdep_kind),
5917 		   integer_zero_node);
5918   if (unroll && cond != error_mark_node)
5919     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5920 		   build_int_cst (integer_type_node,
5921 				  annot_expr_unroll_kind),
5922 		   build_int_cst (integer_type_node, unroll));
5923   save_break = c_break_label;
5924   c_break_label = NULL_TREE;
5925   save_cont = c_cont_label;
5926   c_cont_label = NULL_TREE;
5927 
5928   token_indent_info body_tinfo
5929     = get_token_indent_info (c_parser_peek_token (parser));
5930 
5931   location_t loc_after_labels;
5932   bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE);
5933   body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
5934   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5935   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5936   c_parser_maybe_reclassify_token (parser);
5937 
5938   token_indent_info next_tinfo
5939     = get_token_indent_info (c_parser_peek_token (parser));
5940   warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo);
5941 
5942   if (next_tinfo.type != CPP_SEMICOLON && !open_brace)
5943     warn_for_multistatement_macros (loc_after_labels, next_tinfo.location,
5944 				    while_tinfo.location, RID_WHILE);
5945 
5946   c_break_label = save_break;
5947   c_cont_label = save_cont;
5948 }
5949 
5950 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5951 
5952    do-statement:
5953      do statement while ( expression ) ;
5954 */
5955 
5956 static void
5957 c_parser_do_statement (c_parser *parser, bool ivdep, unsigned short unroll)
5958 {
5959   tree block, cond, body, save_break, save_cont, new_break, new_cont;
5960   location_t loc;
5961   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5962   c_parser_consume_token (parser);
5963   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5964     warning_at (c_parser_peek_token (parser)->location,
5965 		OPT_Wempty_body,
5966 		"suggest braces around empty body in %<do%> statement");
5967   block = c_begin_compound_stmt (flag_isoc99);
5968   loc = c_parser_peek_token (parser)->location;
5969   save_break = c_break_label;
5970   c_break_label = NULL_TREE;
5971   save_cont = c_cont_label;
5972   c_cont_label = NULL_TREE;
5973   body = c_parser_c99_block_statement (parser, NULL);
5974   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5975   new_break = c_break_label;
5976   c_break_label = save_break;
5977   new_cont = c_cont_label;
5978   c_cont_label = save_cont;
5979   cond = c_parser_paren_condition (parser);
5980   if (ivdep && cond != error_mark_node)
5981     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5982 		   build_int_cst (integer_type_node,
5983 				  annot_expr_ivdep_kind),
5984 		   integer_zero_node);
5985   if (unroll && cond != error_mark_node)
5986     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5987 		   build_int_cst (integer_type_node,
5988 				  annot_expr_unroll_kind),
5989  		   build_int_cst (integer_type_node, unroll));
5990   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5991     c_parser_skip_to_end_of_block_or_statement (parser);
5992   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5993   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5994 }
5995 
5996 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5997 
5998    for-statement:
5999      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6000      for ( nested-declaration expression[opt] ; expression[opt] ) statement
6001 
6002    The form with a declaration is new in C99.
6003 
6004    ??? In accordance with the old parser, the declaration may be a
6005    nested function, which is then rejected in check_for_loop_decls,
6006    but does it make any sense for this to be included in the grammar?
6007    Note in particular that the nested function does not include a
6008    trailing ';', whereas the "declaration" production includes one.
6009    Also, can we reject bad declarations earlier and cheaper than
6010    check_for_loop_decls?
6011 
6012    In Objective-C, there are two additional variants:
6013 
6014    foreach-statement:
6015      for ( expression in expresssion ) statement
6016      for ( declaration in expression ) statement
6017 
6018    This is inconsistent with C, because the second variant is allowed
6019    even if c99 is not enabled.
6020 
6021    The rest of the comment documents these Objective-C foreach-statement.
6022 
6023    Here is the canonical example of the first variant:
6024     for (object in array)    { do something with object }
6025    we call the first expression ("object") the "object_expression" and
6026    the second expression ("array") the "collection_expression".
6027    object_expression must be an lvalue of type "id" (a generic Objective-C
6028    object) because the loop works by assigning to object_expression the
6029    various objects from the collection_expression.  collection_expression
6030    must evaluate to something of type "id" which responds to the method
6031    countByEnumeratingWithState:objects:count:.
6032 
6033    The canonical example of the second variant is:
6034     for (id object in array)    { do something with object }
6035    which is completely equivalent to
6036     {
6037       id object;
6038       for (object in array) { do something with object }
6039     }
6040    Note that initizializing 'object' in some way (eg, "for ((object =
6041    xxx) in array) { do something with object }") is possibly
6042    technically valid, but completely pointless as 'object' will be
6043    assigned to something else as soon as the loop starts.  We should
6044    most likely reject it (TODO).
6045 
6046    The beginning of the Objective-C foreach-statement looks exactly
6047    like the beginning of the for-statement, and we can tell it is a
6048    foreach-statement only because the initial declaration or
6049    expression is terminated by 'in' instead of ';'.
6050 
6051    IF_P is used to track whether there's a (possibly labeled) if statement
6052    which is not enclosed in braces and has an else clause.  This is used to
6053    implement -Wparentheses.  */
6054 
6055 static void
6056 c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll,
6057 			bool *if_p)
6058 {
6059   tree block, cond, incr, save_break, save_cont, body;
6060   /* The following are only used when parsing an ObjC foreach statement.  */
6061   tree object_expression;
6062   /* Silence the bogus uninitialized warning.  */
6063   tree collection_expression = NULL;
6064   location_t loc = c_parser_peek_token (parser)->location;
6065   location_t for_loc = c_parser_peek_token (parser)->location;
6066   bool is_foreach_statement = false;
6067   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
6068   token_indent_info for_tinfo
6069     = get_token_indent_info (c_parser_peek_token (parser));
6070   c_parser_consume_token (parser);
6071   /* Open a compound statement in Objective-C as well, just in case this is
6072      as foreach expression.  */
6073   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
6074   cond = error_mark_node;
6075   incr = error_mark_node;
6076   matching_parens parens;
6077   if (parens.require_open (parser))
6078     {
6079       /* Parse the initialization declaration or expression.  */
6080       object_expression = error_mark_node;
6081       parser->objc_could_be_foreach_context = c_dialect_objc ();
6082       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6083 	{
6084 	  parser->objc_could_be_foreach_context = false;
6085 	  c_parser_consume_token (parser);
6086 	  c_finish_expr_stmt (loc, NULL_TREE);
6087 	}
6088       else if (c_parser_next_tokens_start_declaration (parser))
6089 	{
6090 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
6091 					 &object_expression, vNULL);
6092 	  parser->objc_could_be_foreach_context = false;
6093 
6094 	  if (c_parser_next_token_is_keyword (parser, RID_IN))
6095 	    {
6096 	      c_parser_consume_token (parser);
6097 	      is_foreach_statement = true;
6098 	      if (check_for_loop_decls (for_loc, true) == NULL_TREE)
6099 		c_parser_error (parser, "multiple iterating variables in fast enumeration");
6100 	    }
6101 	  else
6102 	    check_for_loop_decls (for_loc, flag_isoc99);
6103 	}
6104       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
6105 	{
6106 	  /* __extension__ can start a declaration, but is also an
6107 	     unary operator that can start an expression.  Consume all
6108 	     but the last of a possible series of __extension__ to
6109 	     determine which.  */
6110 	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
6111 		 && (c_parser_peek_2nd_token (parser)->keyword
6112 		     == RID_EXTENSION))
6113 	    c_parser_consume_token (parser);
6114 	  if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
6115 	    {
6116 	      int ext;
6117 	      ext = disable_extension_diagnostics ();
6118 	      c_parser_consume_token (parser);
6119 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
6120 					     true, &object_expression, vNULL);
6121 	      parser->objc_could_be_foreach_context = false;
6122 
6123 	      restore_extension_diagnostics (ext);
6124 	      if (c_parser_next_token_is_keyword (parser, RID_IN))
6125 		{
6126 		  c_parser_consume_token (parser);
6127 		  is_foreach_statement = true;
6128 		  if (check_for_loop_decls (for_loc, true) == NULL_TREE)
6129 		    c_parser_error (parser, "multiple iterating variables in fast enumeration");
6130 		}
6131 	      else
6132 		check_for_loop_decls (for_loc, flag_isoc99);
6133 	    }
6134 	  else
6135 	    goto init_expr;
6136 	}
6137       else
6138 	{
6139 	init_expr:
6140 	  {
6141 	    struct c_expr ce;
6142 	    tree init_expression;
6143 	    ce = c_parser_expression (parser);
6144 	    init_expression = ce.value;
6145 	    parser->objc_could_be_foreach_context = false;
6146 	    if (c_parser_next_token_is_keyword (parser, RID_IN))
6147 	      {
6148 		c_parser_consume_token (parser);
6149 		is_foreach_statement = true;
6150 		if (! lvalue_p (init_expression))
6151 		  c_parser_error (parser, "invalid iterating variable in fast enumeration");
6152 		object_expression = c_fully_fold (init_expression, false, NULL);
6153 	      }
6154 	    else
6155 	      {
6156 		ce = convert_lvalue_to_rvalue (loc, ce, true, false);
6157 		init_expression = ce.value;
6158 		c_finish_expr_stmt (loc, init_expression);
6159 		c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6160 	      }
6161 	  }
6162 	}
6163       /* Parse the loop condition.  In the case of a foreach
6164 	 statement, there is no loop condition.  */
6165       gcc_assert (!parser->objc_could_be_foreach_context);
6166       if (!is_foreach_statement)
6167 	{
6168 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6169 	    {
6170 	      if (ivdep)
6171 		{
6172 		  c_parser_error (parser, "missing loop condition in loop with "
6173 				  "%<GCC ivdep%> pragma");
6174 		  cond = error_mark_node;
6175 		}
6176 	      else if (unroll)
6177 		{
6178 		  c_parser_error (parser, "missing loop condition in loop with "
6179 				  "%<GCC unroll%> pragma");
6180 		  cond = error_mark_node;
6181 		}
6182 	      else
6183 		{
6184 		  c_parser_consume_token (parser);
6185 		  cond = NULL_TREE;
6186 		}
6187 	    }
6188 	  else
6189 	    {
6190 	      cond = c_parser_condition (parser);
6191 	      c_parser_skip_until_found (parser, CPP_SEMICOLON,
6192 					 "expected %<;%>");
6193 	    }
6194 	  if (ivdep && cond != error_mark_node)
6195 	    cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
6196 			   build_int_cst (integer_type_node,
6197 					  annot_expr_ivdep_kind),
6198 			   integer_zero_node);
6199 	  if (unroll && cond != error_mark_node)
6200 	    cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
6201  			   build_int_cst (integer_type_node,
6202 					  annot_expr_unroll_kind),
6203 			   build_int_cst (integer_type_node, unroll));
6204 	}
6205       /* Parse the increment expression (the third expression in a
6206 	 for-statement).  In the case of a foreach-statement, this is
6207 	 the expression that follows the 'in'.  */
6208       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6209 	{
6210 	  if (is_foreach_statement)
6211 	    {
6212 	      c_parser_error (parser, "missing collection in fast enumeration");
6213 	      collection_expression = error_mark_node;
6214 	    }
6215 	  else
6216 	    incr = c_process_expr_stmt (loc, NULL_TREE);
6217 	}
6218       else
6219 	{
6220 	  if (is_foreach_statement)
6221 	    collection_expression = c_fully_fold (c_parser_expression (parser).value,
6222 						  false, NULL);
6223 	  else
6224 	    {
6225 	      struct c_expr ce = c_parser_expression (parser);
6226 	      ce = convert_lvalue_to_rvalue (loc, ce, true, false);
6227 	      incr = c_process_expr_stmt (loc, ce.value);
6228 	    }
6229 	}
6230       parens.skip_until_found_close (parser);
6231     }
6232   save_break = c_break_label;
6233   c_break_label = NULL_TREE;
6234   save_cont = c_cont_label;
6235   c_cont_label = NULL_TREE;
6236 
6237   token_indent_info body_tinfo
6238     = get_token_indent_info (c_parser_peek_token (parser));
6239 
6240   location_t loc_after_labels;
6241   bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE);
6242   body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
6243 
6244   if (is_foreach_statement)
6245     objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
6246   else
6247     c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
6248   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
6249   c_parser_maybe_reclassify_token (parser);
6250 
6251   token_indent_info next_tinfo
6252     = get_token_indent_info (c_parser_peek_token (parser));
6253   warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo);
6254 
6255   if (next_tinfo.type != CPP_SEMICOLON && !open_brace)
6256     warn_for_multistatement_macros (loc_after_labels, next_tinfo.location,
6257 				    for_tinfo.location, RID_FOR);
6258 
6259   c_break_label = save_break;
6260   c_cont_label = save_cont;
6261 }
6262 
6263 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
6264    statement with inputs, outputs, clobbers, and volatile tag
6265    allowed.
6266 
6267    asm-statement:
6268      asm type-qualifier[opt] ( asm-argument ) ;
6269      asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6270 
6271    asm-argument:
6272      asm-string-literal
6273      asm-string-literal : asm-operands[opt]
6274      asm-string-literal : asm-operands[opt] : asm-operands[opt]
6275      asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6276 
6277    asm-goto-argument:
6278      asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6279        : asm-goto-operands
6280 
6281    Qualifiers other than volatile are accepted in the syntax but
6282    warned for.  */
6283 
6284 static tree
6285 c_parser_asm_statement (c_parser *parser)
6286 {
6287   tree quals, str, outputs, inputs, clobbers, labels, ret;
6288   bool simple, is_goto;
6289   location_t asm_loc = c_parser_peek_token (parser)->location;
6290   int section, nsections;
6291 
6292   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
6293   c_parser_consume_token (parser);
6294   if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
6295     {
6296       quals = c_parser_peek_token (parser)->value;
6297       c_parser_consume_token (parser);
6298     }
6299   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
6300 	   || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
6301     {
6302       warning_at (c_parser_peek_token (parser)->location,
6303 		  0,
6304 		  "%E qualifier ignored on asm",
6305 		  c_parser_peek_token (parser)->value);
6306       quals = NULL_TREE;
6307       c_parser_consume_token (parser);
6308     }
6309   else
6310     quals = NULL_TREE;
6311 
6312   is_goto = false;
6313   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
6314     {
6315       c_parser_consume_token (parser);
6316       is_goto = true;
6317     }
6318 
6319   /* ??? Follow the C++ parser rather than using the
6320      lex_untranslated_string kludge.  */
6321   parser->lex_untranslated_string = true;
6322   ret = NULL;
6323 
6324   matching_parens parens;
6325   if (!parens.require_open (parser))
6326     goto error;
6327 
6328   str = c_parser_asm_string_literal (parser);
6329   if (str == NULL_TREE)
6330     goto error_close_paren;
6331 
6332   simple = true;
6333   outputs = NULL_TREE;
6334   inputs = NULL_TREE;
6335   clobbers = NULL_TREE;
6336   labels = NULL_TREE;
6337 
6338   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
6339     goto done_asm;
6340 
6341   /* Parse each colon-delimited section of operands.  */
6342   nsections = 3 + is_goto;
6343   for (section = 0; section < nsections; ++section)
6344     {
6345       if (!c_parser_require (parser, CPP_COLON,
6346 			     is_goto
6347 			     ? G_("expected %<:%>")
6348 			     : G_("expected %<:%> or %<)%>"),
6349 			     UNKNOWN_LOCATION, is_goto))
6350 	goto error_close_paren;
6351 
6352       /* Once past any colon, we're no longer a simple asm.  */
6353       simple = false;
6354 
6355       if ((!c_parser_next_token_is (parser, CPP_COLON)
6356 	   && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6357 	  || section == 3)
6358 	switch (section)
6359 	  {
6360 	  case 0:
6361 	    /* For asm goto, we don't allow output operands, but reserve
6362 	       the slot for a future extension that does allow them.  */
6363 	    if (!is_goto)
6364 	      outputs = c_parser_asm_operands (parser);
6365 	    break;
6366 	  case 1:
6367 	    inputs = c_parser_asm_operands (parser);
6368 	    break;
6369 	  case 2:
6370 	    clobbers = c_parser_asm_clobbers (parser);
6371 	    break;
6372 	  case 3:
6373 	    labels = c_parser_asm_goto_operands (parser);
6374 	    break;
6375 	  default:
6376 	    gcc_unreachable ();
6377 	  }
6378 
6379       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
6380 	goto done_asm;
6381     }
6382 
6383  done_asm:
6384   if (!parens.require_close (parser))
6385     {
6386       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6387       goto error;
6388     }
6389 
6390   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
6391     c_parser_skip_to_end_of_block_or_statement (parser);
6392 
6393   ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
6394 					       clobbers, labels, simple));
6395 
6396  error:
6397   parser->lex_untranslated_string = false;
6398   return ret;
6399 
6400  error_close_paren:
6401   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6402   goto error;
6403 }
6404 
6405 /* Parse asm operands, a GNU extension.
6406 
6407    asm-operands:
6408      asm-operand
6409      asm-operands , asm-operand
6410 
6411    asm-operand:
6412      asm-string-literal ( expression )
6413      [ identifier ] asm-string-literal ( expression )
6414 */
6415 
6416 static tree
6417 c_parser_asm_operands (c_parser *parser)
6418 {
6419   tree list = NULL_TREE;
6420   while (true)
6421     {
6422       tree name, str;
6423       struct c_expr expr;
6424       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
6425 	{
6426 	  c_parser_consume_token (parser);
6427 	  if (c_parser_next_token_is (parser, CPP_NAME))
6428 	    {
6429 	      tree id = c_parser_peek_token (parser)->value;
6430 	      c_parser_consume_token (parser);
6431 	      name = build_string (IDENTIFIER_LENGTH (id),
6432 				   IDENTIFIER_POINTER (id));
6433 	    }
6434 	  else
6435 	    {
6436 	      c_parser_error (parser, "expected identifier");
6437 	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
6438 	      return NULL_TREE;
6439 	    }
6440 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6441 				     "expected %<]%>");
6442 	}
6443       else
6444 	name = NULL_TREE;
6445       str = c_parser_asm_string_literal (parser);
6446       if (str == NULL_TREE)
6447 	return NULL_TREE;
6448       parser->lex_untranslated_string = false;
6449       matching_parens parens;
6450       if (!parens.require_open (parser))
6451 	{
6452 	  parser->lex_untranslated_string = true;
6453 	  return NULL_TREE;
6454 	}
6455       expr = c_parser_expression (parser);
6456       mark_exp_read (expr.value);
6457       parser->lex_untranslated_string = true;
6458       if (!parens.require_close (parser))
6459 	{
6460 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6461 	  return NULL_TREE;
6462 	}
6463       list = chainon (list, build_tree_list (build_tree_list (name, str),
6464 					     expr.value));
6465       if (c_parser_next_token_is (parser, CPP_COMMA))
6466 	c_parser_consume_token (parser);
6467       else
6468 	break;
6469     }
6470   return list;
6471 }
6472 
6473 /* Parse asm clobbers, a GNU extension.
6474 
6475    asm-clobbers:
6476      asm-string-literal
6477      asm-clobbers , asm-string-literal
6478 */
6479 
6480 static tree
6481 c_parser_asm_clobbers (c_parser *parser)
6482 {
6483   tree list = NULL_TREE;
6484   while (true)
6485     {
6486       tree str = c_parser_asm_string_literal (parser);
6487       if (str)
6488 	list = tree_cons (NULL_TREE, str, list);
6489       else
6490 	return NULL_TREE;
6491       if (c_parser_next_token_is (parser, CPP_COMMA))
6492 	c_parser_consume_token (parser);
6493       else
6494 	break;
6495     }
6496   return list;
6497 }
6498 
6499 /* Parse asm goto labels, a GNU extension.
6500 
6501    asm-goto-operands:
6502      identifier
6503      asm-goto-operands , identifier
6504 */
6505 
6506 static tree
6507 c_parser_asm_goto_operands (c_parser *parser)
6508 {
6509   tree list = NULL_TREE;
6510   while (true)
6511     {
6512       tree name, label;
6513 
6514       if (c_parser_next_token_is (parser, CPP_NAME))
6515 	{
6516 	  c_token *tok = c_parser_peek_token (parser);
6517 	  name = tok->value;
6518 	  label = lookup_label_for_goto (tok->location, name);
6519 	  c_parser_consume_token (parser);
6520 	  TREE_USED (label) = 1;
6521 	}
6522       else
6523 	{
6524 	  c_parser_error (parser, "expected identifier");
6525 	  return NULL_TREE;
6526 	}
6527 
6528       name = build_string (IDENTIFIER_LENGTH (name),
6529 			   IDENTIFIER_POINTER (name));
6530       list = tree_cons (name, label, list);
6531       if (c_parser_next_token_is (parser, CPP_COMMA))
6532 	c_parser_consume_token (parser);
6533       else
6534 	return nreverse (list);
6535     }
6536 }
6537 
6538 /* Parse an expression other than a compound expression; that is, an
6539    assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16).  If
6540    AFTER is not NULL then it is an Objective-C message expression which
6541    is the primary-expression starting the expression as an initializer.
6542 
6543    assignment-expression:
6544      conditional-expression
6545      unary-expression assignment-operator assignment-expression
6546 
6547    assignment-operator: one of
6548      = *= /= %= += -= <<= >>= &= ^= |=
6549 
6550    In GNU C we accept any conditional expression on the LHS and
6551    diagnose the invalid lvalue rather than producing a syntax
6552    error.  */
6553 
6554 static struct c_expr
6555 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
6556 			 tree omp_atomic_lhs)
6557 {
6558   struct c_expr lhs, rhs, ret;
6559   enum tree_code code;
6560   location_t op_location, exp_location;
6561   gcc_assert (!after || c_dialect_objc ());
6562   lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
6563   op_location = c_parser_peek_token (parser)->location;
6564   switch (c_parser_peek_token (parser)->type)
6565     {
6566     case CPP_EQ:
6567       code = NOP_EXPR;
6568       break;
6569     case CPP_MULT_EQ:
6570       code = MULT_EXPR;
6571       break;
6572     case CPP_DIV_EQ:
6573       code = TRUNC_DIV_EXPR;
6574       break;
6575     case CPP_MOD_EQ:
6576       code = TRUNC_MOD_EXPR;
6577       break;
6578     case CPP_PLUS_EQ:
6579       code = PLUS_EXPR;
6580       break;
6581     case CPP_MINUS_EQ:
6582       code = MINUS_EXPR;
6583       break;
6584     case CPP_LSHIFT_EQ:
6585       code = LSHIFT_EXPR;
6586       break;
6587     case CPP_RSHIFT_EQ:
6588       code = RSHIFT_EXPR;
6589       break;
6590     case CPP_AND_EQ:
6591       code = BIT_AND_EXPR;
6592       break;
6593     case CPP_XOR_EQ:
6594       code = BIT_XOR_EXPR;
6595       break;
6596     case CPP_OR_EQ:
6597       code = BIT_IOR_EXPR;
6598       break;
6599     default:
6600       return lhs;
6601     }
6602   c_parser_consume_token (parser);
6603   exp_location = c_parser_peek_token (parser)->location;
6604   rhs = c_parser_expr_no_commas (parser, NULL);
6605   rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
6606 
6607   ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
6608 				 code, exp_location, rhs.value,
6609 				 rhs.original_type);
6610   set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ());
6611   if (code == NOP_EXPR)
6612     ret.original_code = MODIFY_EXPR;
6613   else
6614     {
6615       TREE_NO_WARNING (ret.value) = 1;
6616       ret.original_code = ERROR_MARK;
6617     }
6618   ret.original_type = NULL;
6619   return ret;
6620 }
6621 
6622 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15).  If
6623    AFTER is not NULL then it is an Objective-C message expression which is
6624    the primary-expression starting the expression as an initializer.
6625 
6626    conditional-expression:
6627      logical-OR-expression
6628      logical-OR-expression ? expression : conditional-expression
6629 
6630    GNU extensions:
6631 
6632    conditional-expression:
6633      logical-OR-expression ? : conditional-expression
6634 */
6635 
6636 static struct c_expr
6637 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6638 				 tree omp_atomic_lhs)
6639 {
6640   struct c_expr cond, exp1, exp2, ret;
6641   location_t start, cond_loc, colon_loc;
6642 
6643   gcc_assert (!after || c_dialect_objc ());
6644 
6645   cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6646 
6647   if (c_parser_next_token_is_not (parser, CPP_QUERY))
6648     return cond;
6649   if (cond.value != error_mark_node)
6650     start = cond.get_start ();
6651   else
6652     start = UNKNOWN_LOCATION;
6653   cond_loc = c_parser_peek_token (parser)->location;
6654   cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6655   c_parser_consume_token (parser);
6656   if (c_parser_next_token_is (parser, CPP_COLON))
6657     {
6658       tree eptype = NULL_TREE;
6659 
6660       location_t middle_loc = c_parser_peek_token (parser)->location;
6661       pedwarn (middle_loc, OPT_Wpedantic,
6662 	       "ISO C forbids omitting the middle term of a ?: expression");
6663       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6664 	{
6665 	  eptype = TREE_TYPE (cond.value);
6666 	  cond.value = TREE_OPERAND (cond.value, 0);
6667 	}
6668       tree e = cond.value;
6669       while (TREE_CODE (e) == COMPOUND_EXPR)
6670 	e = TREE_OPERAND (e, 1);
6671       warn_for_omitted_condop (middle_loc, e);
6672       /* Make sure first operand is calculated only once.  */
6673       exp1.value = save_expr (default_conversion (cond.value));
6674       if (eptype)
6675 	exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6676       exp1.original_type = NULL;
6677       exp1.src_range = cond.src_range;
6678       cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6679       c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6680     }
6681   else
6682     {
6683       cond.value
6684 	= c_objc_common_truthvalue_conversion
6685 	(cond_loc, default_conversion (cond.value));
6686       c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6687       exp1 = c_parser_expression_conv (parser);
6688       mark_exp_read (exp1.value);
6689       c_inhibit_evaluation_warnings +=
6690 	((cond.value == truthvalue_true_node)
6691 	 - (cond.value == truthvalue_false_node));
6692     }
6693 
6694   colon_loc = c_parser_peek_token (parser)->location;
6695   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6696     {
6697       c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6698       ret.set_error ();
6699       ret.original_code = ERROR_MARK;
6700       ret.original_type = NULL;
6701       return ret;
6702     }
6703   {
6704     location_t exp2_loc = c_parser_peek_token (parser)->location;
6705     exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6706     exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6707   }
6708   c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6709   location_t loc1 = make_location (exp1.get_start (), exp1.src_range);
6710   location_t loc2 = make_location (exp2.get_start (), exp2.src_range);
6711   ret.value = build_conditional_expr (colon_loc, cond.value,
6712 				      cond.original_code == C_MAYBE_CONST_EXPR,
6713 				      exp1.value, exp1.original_type, loc1,
6714 				      exp2.value, exp2.original_type, loc2);
6715   ret.original_code = ERROR_MARK;
6716   if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6717     ret.original_type = NULL;
6718   else
6719     {
6720       tree t1, t2;
6721 
6722       /* If both sides are enum type, the default conversion will have
6723 	 made the type of the result be an integer type.  We want to
6724 	 remember the enum types we started with.  */
6725       t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6726       t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6727       ret.original_type = ((t1 != error_mark_node
6728 			    && t2 != error_mark_node
6729 			    && (TYPE_MAIN_VARIANT (t1)
6730 				== TYPE_MAIN_VARIANT (t2)))
6731 			   ? t1
6732 			   : NULL);
6733     }
6734   set_c_expr_source_range (&ret, start, exp2.get_finish ());
6735   return ret;
6736 }
6737 
6738 /* Parse a binary expression; that is, a logical-OR-expression (C90
6739    6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14).  If AFTER is not
6740    NULL then it is an Objective-C message expression which is the
6741    primary-expression starting the expression as an initializer.
6742 
6743    OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6744    when it should be the unfolded lhs.  In a valid OpenMP source,
6745    one of the operands of the toplevel binary expression must be equal
6746    to it.  In that case, just return a build2 created binary operation
6747    rather than result of parser_build_binary_op.
6748 
6749    multiplicative-expression:
6750      cast-expression
6751      multiplicative-expression * cast-expression
6752      multiplicative-expression / cast-expression
6753      multiplicative-expression % cast-expression
6754 
6755    additive-expression:
6756      multiplicative-expression
6757      additive-expression + multiplicative-expression
6758      additive-expression - multiplicative-expression
6759 
6760    shift-expression:
6761      additive-expression
6762      shift-expression << additive-expression
6763      shift-expression >> additive-expression
6764 
6765    relational-expression:
6766      shift-expression
6767      relational-expression < shift-expression
6768      relational-expression > shift-expression
6769      relational-expression <= shift-expression
6770      relational-expression >= shift-expression
6771 
6772    equality-expression:
6773      relational-expression
6774      equality-expression == relational-expression
6775      equality-expression != relational-expression
6776 
6777    AND-expression:
6778      equality-expression
6779      AND-expression & equality-expression
6780 
6781    exclusive-OR-expression:
6782      AND-expression
6783      exclusive-OR-expression ^ AND-expression
6784 
6785    inclusive-OR-expression:
6786      exclusive-OR-expression
6787      inclusive-OR-expression | exclusive-OR-expression
6788 
6789    logical-AND-expression:
6790      inclusive-OR-expression
6791      logical-AND-expression && inclusive-OR-expression
6792 
6793    logical-OR-expression:
6794      logical-AND-expression
6795      logical-OR-expression || logical-AND-expression
6796 */
6797 
6798 static struct c_expr
6799 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6800 			    tree omp_atomic_lhs)
6801 {
6802   /* A binary expression is parsed using operator-precedence parsing,
6803      with the operands being cast expressions.  All the binary
6804      operators are left-associative.  Thus a binary expression is of
6805      form:
6806 
6807      E0 op1 E1 op2 E2 ...
6808 
6809      which we represent on a stack.  On the stack, the precedence
6810      levels are strictly increasing.  When a new operator is
6811      encountered of higher precedence than that at the top of the
6812      stack, it is pushed; its LHS is the top expression, and its RHS
6813      is everything parsed until it is popped.  When a new operator is
6814      encountered with precedence less than or equal to that at the top
6815      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6816      by the result of the operation until the operator at the top of
6817      the stack has lower precedence than the new operator or there is
6818      only one element on the stack; then the top expression is the LHS
6819      of the new operator.  In the case of logical AND and OR
6820      expressions, we also need to adjust c_inhibit_evaluation_warnings
6821      as appropriate when the operators are pushed and popped.  */
6822 
6823   struct {
6824     /* The expression at this stack level.  */
6825     struct c_expr expr;
6826     /* The precedence of the operator on its left, PREC_NONE at the
6827        bottom of the stack.  */
6828     enum c_parser_prec prec;
6829     /* The operation on its left.  */
6830     enum tree_code op;
6831     /* The source location of this operation.  */
6832     location_t loc;
6833     /* The sizeof argument if expr.original_code == SIZEOF_EXPR.  */
6834     tree sizeof_arg;
6835   } stack[NUM_PRECS];
6836   int sp;
6837   /* Location of the binary operator.  */
6838   location_t binary_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
6839 #define POP								      \
6840   do {									      \
6841     switch (stack[sp].op)						      \
6842       {									      \
6843       case TRUTH_ANDIF_EXPR:						      \
6844 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
6845 					  == truthvalue_false_node);	      \
6846 	break;								      \
6847       case TRUTH_ORIF_EXPR:						      \
6848 	c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value	      \
6849 					  == truthvalue_true_node);	      \
6850 	break;								      \
6851       case TRUNC_DIV_EXPR: 						      \
6852 	if (stack[sp - 1].expr.original_code == SIZEOF_EXPR		      \
6853 	    && stack[sp].expr.original_code == SIZEOF_EXPR)		      \
6854 	  {								      \
6855 	    tree type0 = stack[sp - 1].sizeof_arg;			      \
6856 	    tree type1 = stack[sp].sizeof_arg;				      \
6857 	    tree first_arg = type0;					      \
6858 	    if (!TYPE_P (type0))					      \
6859 	      type0 = TREE_TYPE (type0);				      \
6860 	    if (!TYPE_P (type1))					      \
6861 	      type1 = TREE_TYPE (type1);				      \
6862 	    if (POINTER_TYPE_P (type0)					      \
6863 		&& comptypes (TREE_TYPE (type0), type1)			      \
6864 		&& !(TREE_CODE (first_arg) == PARM_DECL			      \
6865 		     && C_ARRAY_PARAMETER (first_arg)			      \
6866 		     && warn_sizeof_array_argument))			      \
6867 	      if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div,	      \
6868 			      "division %<sizeof (%T) / sizeof (%T)%> does "  \
6869 			      "not compute the number of array elements",     \
6870 			      type0, type1))				      \
6871 		if (DECL_P (first_arg))					      \
6872 		  inform (DECL_SOURCE_LOCATION (first_arg),		      \
6873 			  "first %<sizeof%> operand was declared here");      \
6874 	  }								      \
6875 	break;								      \
6876       default:								      \
6877 	break;								      \
6878       }									      \
6879     stack[sp - 1].expr							      \
6880       = convert_lvalue_to_rvalue (stack[sp - 1].loc,			      \
6881 				  stack[sp - 1].expr, true, true);	      \
6882     stack[sp].expr							      \
6883       = convert_lvalue_to_rvalue (stack[sp].loc,			      \
6884 				  stack[sp].expr, true, true);		      \
6885     if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1	      \
6886 	&& c_parser_peek_token (parser)->type == CPP_SEMICOLON		      \
6887 	&& ((1 << stack[sp].prec)					      \
6888 	    & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND)    \
6889 	       | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT)))     \
6890 	&& stack[sp].op != TRUNC_MOD_EXPR				      \
6891 	&& stack[0].expr.value != error_mark_node			      \
6892 	&& stack[1].expr.value != error_mark_node			      \
6893 	&& (c_tree_equal (stack[0].expr.value, omp_atomic_lhs)		      \
6894 	    || c_tree_equal (stack[1].expr.value, omp_atomic_lhs)))	      \
6895       stack[0].expr.value						      \
6896 	= build2 (stack[1].op, TREE_TYPE (stack[0].expr.value),		      \
6897 		  stack[0].expr.value, stack[1].expr.value);		      \
6898     else								      \
6899       stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc,	      \
6900 						   stack[sp].op,	      \
6901 						   stack[sp - 1].expr,	      \
6902 						   stack[sp].expr);	      \
6903     sp--;								      \
6904   } while (0)
6905   gcc_assert (!after || c_dialect_objc ());
6906   stack[0].loc = c_parser_peek_token (parser)->location;
6907   stack[0].expr = c_parser_cast_expression (parser, after);
6908   stack[0].prec = PREC_NONE;
6909   stack[0].sizeof_arg = c_last_sizeof_arg;
6910   sp = 0;
6911   while (true)
6912     {
6913       enum c_parser_prec oprec;
6914       enum tree_code ocode;
6915       source_range src_range;
6916       if (parser->error)
6917 	goto out;
6918       switch (c_parser_peek_token (parser)->type)
6919 	{
6920 	case CPP_MULT:
6921 	  oprec = PREC_MULT;
6922 	  ocode = MULT_EXPR;
6923 	  break;
6924 	case CPP_DIV:
6925 	  oprec = PREC_MULT;
6926 	  ocode = TRUNC_DIV_EXPR;
6927 	  break;
6928 	case CPP_MOD:
6929 	  oprec = PREC_MULT;
6930 	  ocode = TRUNC_MOD_EXPR;
6931 	  break;
6932 	case CPP_PLUS:
6933 	  oprec = PREC_ADD;
6934 	  ocode = PLUS_EXPR;
6935 	  break;
6936 	case CPP_MINUS:
6937 	  oprec = PREC_ADD;
6938 	  ocode = MINUS_EXPR;
6939 	  break;
6940 	case CPP_LSHIFT:
6941 	  oprec = PREC_SHIFT;
6942 	  ocode = LSHIFT_EXPR;
6943 	  break;
6944 	case CPP_RSHIFT:
6945 	  oprec = PREC_SHIFT;
6946 	  ocode = RSHIFT_EXPR;
6947 	  break;
6948 	case CPP_LESS:
6949 	  oprec = PREC_REL;
6950 	  ocode = LT_EXPR;
6951 	  break;
6952 	case CPP_GREATER:
6953 	  oprec = PREC_REL;
6954 	  ocode = GT_EXPR;
6955 	  break;
6956 	case CPP_LESS_EQ:
6957 	  oprec = PREC_REL;
6958 	  ocode = LE_EXPR;
6959 	  break;
6960 	case CPP_GREATER_EQ:
6961 	  oprec = PREC_REL;
6962 	  ocode = GE_EXPR;
6963 	  break;
6964 	case CPP_EQ_EQ:
6965 	  oprec = PREC_EQ;
6966 	  ocode = EQ_EXPR;
6967 	  break;
6968 	case CPP_NOT_EQ:
6969 	  oprec = PREC_EQ;
6970 	  ocode = NE_EXPR;
6971 	  break;
6972 	case CPP_AND:
6973 	  oprec = PREC_BITAND;
6974 	  ocode = BIT_AND_EXPR;
6975 	  break;
6976 	case CPP_XOR:
6977 	  oprec = PREC_BITXOR;
6978 	  ocode = BIT_XOR_EXPR;
6979 	  break;
6980 	case CPP_OR:
6981 	  oprec = PREC_BITOR;
6982 	  ocode = BIT_IOR_EXPR;
6983 	  break;
6984 	case CPP_AND_AND:
6985 	  oprec = PREC_LOGAND;
6986 	  ocode = TRUTH_ANDIF_EXPR;
6987 	  break;
6988 	case CPP_OR_OR:
6989 	  oprec = PREC_LOGOR;
6990 	  ocode = TRUTH_ORIF_EXPR;
6991 	  break;
6992 	default:
6993 	  /* Not a binary operator, so end of the binary
6994 	     expression.  */
6995 	  goto out;
6996 	}
6997       binary_loc = c_parser_peek_token (parser)->location;
6998       while (oprec <= stack[sp].prec)
6999 	POP;
7000       c_parser_consume_token (parser);
7001       switch (ocode)
7002 	{
7003 	case TRUTH_ANDIF_EXPR:
7004 	  src_range = stack[sp].expr.src_range;
7005 	  stack[sp].expr
7006 	    = convert_lvalue_to_rvalue (stack[sp].loc,
7007 					stack[sp].expr, true, true);
7008 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
7009 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
7010 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
7011 					    == truthvalue_false_node);
7012 	  set_c_expr_source_range (&stack[sp].expr, src_range);
7013 	  break;
7014 	case TRUTH_ORIF_EXPR:
7015 	  src_range = stack[sp].expr.src_range;
7016 	  stack[sp].expr
7017 	    = convert_lvalue_to_rvalue (stack[sp].loc,
7018 					stack[sp].expr, true, true);
7019 	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
7020 	    (stack[sp].loc, default_conversion (stack[sp].expr.value));
7021 	  c_inhibit_evaluation_warnings += (stack[sp].expr.value
7022 					    == truthvalue_true_node);
7023 	  set_c_expr_source_range (&stack[sp].expr, src_range);
7024 	  break;
7025 	default:
7026 	  break;
7027 	}
7028       sp++;
7029       stack[sp].loc = binary_loc;
7030       stack[sp].expr = c_parser_cast_expression (parser, NULL);
7031       stack[sp].prec = oprec;
7032       stack[sp].op = ocode;
7033       stack[sp].sizeof_arg = c_last_sizeof_arg;
7034     }
7035  out:
7036   while (sp > 0)
7037     POP;
7038   return stack[0].expr;
7039 #undef POP
7040 }
7041 
7042 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4).  If AFTER
7043    is not NULL then it is an Objective-C message expression which is the
7044    primary-expression starting the expression as an initializer.
7045 
7046    cast-expression:
7047      unary-expression
7048      ( type-name ) unary-expression
7049 */
7050 
7051 static struct c_expr
7052 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
7053 {
7054   location_t cast_loc = c_parser_peek_token (parser)->location;
7055   gcc_assert (!after || c_dialect_objc ());
7056   if (after)
7057     return c_parser_postfix_expression_after_primary (parser,
7058 						      cast_loc, *after);
7059   /* If the expression begins with a parenthesized type name, it may
7060      be either a cast or a compound literal; we need to see whether
7061      the next character is '{' to tell the difference.  If not, it is
7062      an unary expression.  Full detection of unknown typenames here
7063      would require a 3-token lookahead.  */
7064   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7065       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7066     {
7067       struct c_type_name *type_name;
7068       struct c_expr ret;
7069       struct c_expr expr;
7070       matching_parens parens;
7071       parens.consume_open (parser);
7072       type_name = c_parser_type_name (parser, true);
7073       parens.skip_until_found_close (parser);
7074       if (type_name == NULL)
7075 	{
7076 	  ret.set_error ();
7077 	  ret.original_code = ERROR_MARK;
7078 	  ret.original_type = NULL;
7079 	  return ret;
7080 	}
7081 
7082       /* Save casted types in the function's used types hash table.  */
7083       used_types_insert (type_name->specs->type);
7084 
7085       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7086 	return c_parser_postfix_expression_after_paren_type (parser, type_name,
7087 							     cast_loc);
7088       if (type_name->specs->alignas_p)
7089 	error_at (type_name->specs->locations[cdw_alignas],
7090 		  "alignment specified for type name in cast");
7091       {
7092 	location_t expr_loc = c_parser_peek_token (parser)->location;
7093 	expr = c_parser_cast_expression (parser, NULL);
7094 	expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
7095       }
7096       ret.value = c_cast_expr (cast_loc, type_name, expr.value);
7097       if (ret.value && expr.value)
7098 	set_c_expr_source_range (&ret, cast_loc, expr.get_finish ());
7099       ret.original_code = ERROR_MARK;
7100       ret.original_type = NULL;
7101       return ret;
7102     }
7103   else
7104     return c_parser_unary_expression (parser);
7105 }
7106 
7107 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7108 
7109    unary-expression:
7110      postfix-expression
7111      ++ unary-expression
7112      -- unary-expression
7113      unary-operator cast-expression
7114      sizeof unary-expression
7115      sizeof ( type-name )
7116 
7117    unary-operator: one of
7118      & * + - ~ !
7119 
7120    GNU extensions:
7121 
7122    unary-expression:
7123      __alignof__ unary-expression
7124      __alignof__ ( type-name )
7125      && identifier
7126 
7127    (C11 permits _Alignof with type names only.)
7128 
7129    unary-operator: one of
7130      __extension__ __real__ __imag__
7131 
7132    Transactional Memory:
7133 
7134    unary-expression:
7135      transaction-expression
7136 
7137    In addition, the GNU syntax treats ++ and -- as unary operators, so
7138    they may be applied to cast expressions with errors for non-lvalues
7139    given later.  */
7140 
7141 static struct c_expr
7142 c_parser_unary_expression (c_parser *parser)
7143 {
7144   int ext;
7145   struct c_expr ret, op;
7146   location_t op_loc = c_parser_peek_token (parser)->location;
7147   location_t exp_loc;
7148   location_t finish;
7149   ret.original_code = ERROR_MARK;
7150   ret.original_type = NULL;
7151   switch (c_parser_peek_token (parser)->type)
7152     {
7153     case CPP_PLUS_PLUS:
7154       c_parser_consume_token (parser);
7155       exp_loc = c_parser_peek_token (parser)->location;
7156       op = c_parser_cast_expression (parser, NULL);
7157 
7158       op = default_function_array_read_conversion (exp_loc, op);
7159       return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
7160     case CPP_MINUS_MINUS:
7161       c_parser_consume_token (parser);
7162       exp_loc = c_parser_peek_token (parser)->location;
7163       op = c_parser_cast_expression (parser, NULL);
7164 
7165       op = default_function_array_read_conversion (exp_loc, op);
7166       return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
7167     case CPP_AND:
7168       c_parser_consume_token (parser);
7169       op = c_parser_cast_expression (parser, NULL);
7170       mark_exp_read (op.value);
7171       return parser_build_unary_op (op_loc, ADDR_EXPR, op);
7172     case CPP_MULT:
7173       {
7174 	c_parser_consume_token (parser);
7175 	exp_loc = c_parser_peek_token (parser)->location;
7176 	op = c_parser_cast_expression (parser, NULL);
7177 	finish = op.get_finish ();
7178 	op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7179 	location_t combined_loc = make_location (op_loc, op_loc, finish);
7180 	ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR);
7181 	ret.src_range.m_start = op_loc;
7182 	ret.src_range.m_finish = finish;
7183 	return ret;
7184       }
7185     case CPP_PLUS:
7186       if (!c_dialect_objc () && !in_system_header_at (input_location))
7187 	warning_at (op_loc,
7188 		    OPT_Wtraditional,
7189 		    "traditional C rejects the unary plus operator");
7190       c_parser_consume_token (parser);
7191       exp_loc = c_parser_peek_token (parser)->location;
7192       op = c_parser_cast_expression (parser, NULL);
7193       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7194       return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
7195     case CPP_MINUS:
7196       c_parser_consume_token (parser);
7197       exp_loc = c_parser_peek_token (parser)->location;
7198       op = c_parser_cast_expression (parser, NULL);
7199       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7200       return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
7201     case CPP_COMPL:
7202       c_parser_consume_token (parser);
7203       exp_loc = c_parser_peek_token (parser)->location;
7204       op = c_parser_cast_expression (parser, NULL);
7205       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7206       return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
7207     case CPP_NOT:
7208       c_parser_consume_token (parser);
7209       exp_loc = c_parser_peek_token (parser)->location;
7210       op = c_parser_cast_expression (parser, NULL);
7211       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7212       return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
7213     case CPP_AND_AND:
7214       /* Refer to the address of a label as a pointer.  */
7215       c_parser_consume_token (parser);
7216       if (c_parser_next_token_is (parser, CPP_NAME))
7217 	{
7218 	  ret.value = finish_label_address_expr
7219 	    (c_parser_peek_token (parser)->value, op_loc);
7220 	  set_c_expr_source_range (&ret, op_loc,
7221 				   c_parser_peek_token (parser)->get_finish ());
7222 	  c_parser_consume_token (parser);
7223 	}
7224       else
7225 	{
7226 	  c_parser_error (parser, "expected identifier");
7227 	  ret.set_error ();
7228 	}
7229       return ret;
7230     case CPP_KEYWORD:
7231       switch (c_parser_peek_token (parser)->keyword)
7232 	{
7233 	case RID_SIZEOF:
7234 	  return c_parser_sizeof_expression (parser);
7235 	case RID_ALIGNOF:
7236 	  return c_parser_alignof_expression (parser);
7237 	case RID_EXTENSION:
7238 	  c_parser_consume_token (parser);
7239 	  ext = disable_extension_diagnostics ();
7240 	  ret = c_parser_cast_expression (parser, NULL);
7241 	  restore_extension_diagnostics (ext);
7242 	  return ret;
7243 	case RID_REALPART:
7244 	  c_parser_consume_token (parser);
7245 	  exp_loc = c_parser_peek_token (parser)->location;
7246 	  op = c_parser_cast_expression (parser, NULL);
7247 	  op = default_function_array_conversion (exp_loc, op);
7248 	  return parser_build_unary_op (op_loc, REALPART_EXPR, op);
7249 	case RID_IMAGPART:
7250 	  c_parser_consume_token (parser);
7251 	  exp_loc = c_parser_peek_token (parser)->location;
7252 	  op = c_parser_cast_expression (parser, NULL);
7253 	  op = default_function_array_conversion (exp_loc, op);
7254 	  return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
7255 	case RID_TRANSACTION_ATOMIC:
7256 	case RID_TRANSACTION_RELAXED:
7257 	  return c_parser_transaction_expression (parser,
7258 	      c_parser_peek_token (parser)->keyword);
7259 	default:
7260 	  return c_parser_postfix_expression (parser);
7261 	}
7262     default:
7263       return c_parser_postfix_expression (parser);
7264     }
7265 }
7266 
7267 /* Parse a sizeof expression.  */
7268 
7269 static struct c_expr
7270 c_parser_sizeof_expression (c_parser *parser)
7271 {
7272   struct c_expr expr;
7273   struct c_expr result;
7274   location_t expr_loc;
7275   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
7276 
7277   location_t start;
7278   location_t finish = UNKNOWN_LOCATION;
7279 
7280   start = c_parser_peek_token (parser)->location;
7281 
7282   c_parser_consume_token (parser);
7283   c_inhibit_evaluation_warnings++;
7284   in_sizeof++;
7285   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7286       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7287     {
7288       /* Either sizeof ( type-name ) or sizeof unary-expression
7289 	 starting with a compound literal.  */
7290       struct c_type_name *type_name;
7291       matching_parens parens;
7292       parens.consume_open (parser);
7293       expr_loc = c_parser_peek_token (parser)->location;
7294       type_name = c_parser_type_name (parser, true);
7295       parens.skip_until_found_close (parser);
7296       finish = parser->tokens_buf[0].location;
7297       if (type_name == NULL)
7298 	{
7299 	  struct c_expr ret;
7300 	  c_inhibit_evaluation_warnings--;
7301 	  in_sizeof--;
7302 	  ret.set_error ();
7303 	  ret.original_code = ERROR_MARK;
7304 	  ret.original_type = NULL;
7305 	  return ret;
7306 	}
7307       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7308 	{
7309 	  expr = c_parser_postfix_expression_after_paren_type (parser,
7310 							       type_name,
7311 							       expr_loc);
7312 	  finish = expr.get_finish ();
7313 	  goto sizeof_expr;
7314 	}
7315       /* sizeof ( type-name ).  */
7316       if (type_name->specs->alignas_p)
7317 	error_at (type_name->specs->locations[cdw_alignas],
7318 		  "alignment specified for type name in %<sizeof%>");
7319       c_inhibit_evaluation_warnings--;
7320       in_sizeof--;
7321       result = c_expr_sizeof_type (expr_loc, type_name);
7322     }
7323   else
7324     {
7325       expr_loc = c_parser_peek_token (parser)->location;
7326       expr = c_parser_unary_expression (parser);
7327       finish = expr.get_finish ();
7328     sizeof_expr:
7329       c_inhibit_evaluation_warnings--;
7330       in_sizeof--;
7331       mark_exp_read (expr.value);
7332       if (TREE_CODE (expr.value) == COMPONENT_REF
7333 	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
7334 	error_at (expr_loc, "%<sizeof%> applied to a bit-field");
7335       result = c_expr_sizeof_expr (expr_loc, expr);
7336     }
7337   if (finish != UNKNOWN_LOCATION)
7338     set_c_expr_source_range (&result, start, finish);
7339   return result;
7340 }
7341 
7342 /* Parse an alignof expression.  */
7343 
7344 static struct c_expr
7345 c_parser_alignof_expression (c_parser *parser)
7346 {
7347   struct c_expr expr;
7348   location_t start_loc = c_parser_peek_token (parser)->location;
7349   location_t end_loc;
7350   tree alignof_spelling = c_parser_peek_token (parser)->value;
7351   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
7352   bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
7353 				"_Alignof") == 0;
7354   /* A diagnostic is not required for the use of this identifier in
7355      the implementation namespace; only diagnose it for the C11
7356      spelling because of existing code using the other spellings.  */
7357   if (is_c11_alignof)
7358     {
7359       if (flag_isoc99)
7360 	pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE",
7361 		     alignof_spelling);
7362       else
7363 	pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE",
7364 		     alignof_spelling);
7365     }
7366   c_parser_consume_token (parser);
7367   c_inhibit_evaluation_warnings++;
7368   in_alignof++;
7369   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7370       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7371     {
7372       /* Either __alignof__ ( type-name ) or __alignof__
7373 	 unary-expression starting with a compound literal.  */
7374       location_t loc;
7375       struct c_type_name *type_name;
7376       struct c_expr ret;
7377       matching_parens parens;
7378       parens.consume_open (parser);
7379       loc = c_parser_peek_token (parser)->location;
7380       type_name = c_parser_type_name (parser, true);
7381       end_loc = c_parser_peek_token (parser)->location;
7382       parens.skip_until_found_close (parser);
7383       if (type_name == NULL)
7384 	{
7385 	  struct c_expr ret;
7386 	  c_inhibit_evaluation_warnings--;
7387 	  in_alignof--;
7388 	  ret.set_error ();
7389 	  ret.original_code = ERROR_MARK;
7390 	  ret.original_type = NULL;
7391 	  return ret;
7392 	}
7393       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7394 	{
7395 	  expr = c_parser_postfix_expression_after_paren_type (parser,
7396 							       type_name,
7397 							       loc);
7398 	  goto alignof_expr;
7399 	}
7400       /* alignof ( type-name ).  */
7401       if (type_name->specs->alignas_p)
7402 	error_at (type_name->specs->locations[cdw_alignas],
7403 		  "alignment specified for type name in %qE",
7404 		  alignof_spelling);
7405       c_inhibit_evaluation_warnings--;
7406       in_alignof--;
7407       ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
7408 							       NULL, NULL),
7409 					    false, is_c11_alignof, 1);
7410       ret.original_code = ERROR_MARK;
7411       ret.original_type = NULL;
7412       set_c_expr_source_range (&ret, start_loc, end_loc);
7413       return ret;
7414     }
7415   else
7416     {
7417       struct c_expr ret;
7418       expr = c_parser_unary_expression (parser);
7419       end_loc = expr.src_range.m_finish;
7420     alignof_expr:
7421       mark_exp_read (expr.value);
7422       c_inhibit_evaluation_warnings--;
7423       in_alignof--;
7424       if (is_c11_alignof)
7425 	pedwarn (start_loc,
7426 		 OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
7427 		 alignof_spelling);
7428       ret.value = c_alignof_expr (start_loc, expr.value);
7429       ret.original_code = ERROR_MARK;
7430       ret.original_type = NULL;
7431       set_c_expr_source_range (&ret, start_loc, end_loc);
7432       return ret;
7433     }
7434 }
7435 
7436 /* Helper function to read arguments of builtins which are interfaces
7437    for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7438    others.  The name of the builtin is passed using BNAME parameter.
7439    Function returns true if there were no errors while parsing and
7440    stores the arguments in CEXPR_LIST.  If it returns true,
7441    *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7442    parenthesis.  */
7443 static bool
7444 c_parser_get_builtin_args (c_parser *parser, const char *bname,
7445 			   vec<c_expr_t, va_gc> **ret_cexpr_list,
7446 			   bool choose_expr_p,
7447 			   location_t *out_close_paren_loc)
7448 {
7449   location_t loc = c_parser_peek_token (parser)->location;
7450   vec<c_expr_t, va_gc> *cexpr_list;
7451   c_expr_t expr;
7452   bool saved_force_folding_builtin_constant_p;
7453 
7454   *ret_cexpr_list = NULL;
7455   if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
7456     {
7457       error_at (loc, "cannot take address of %qs", bname);
7458       return false;
7459     }
7460 
7461   c_parser_consume_token (parser);
7462 
7463   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7464     {
7465       *out_close_paren_loc = c_parser_peek_token (parser)->location;
7466       c_parser_consume_token (parser);
7467       return true;
7468     }
7469 
7470   saved_force_folding_builtin_constant_p
7471     = force_folding_builtin_constant_p;
7472   force_folding_builtin_constant_p |= choose_expr_p;
7473   expr = c_parser_expr_no_commas (parser, NULL);
7474   force_folding_builtin_constant_p
7475     = saved_force_folding_builtin_constant_p;
7476   vec_alloc (cexpr_list, 1);
7477   vec_safe_push (cexpr_list, expr);
7478   while (c_parser_next_token_is (parser, CPP_COMMA))
7479     {
7480       c_parser_consume_token (parser);
7481       expr = c_parser_expr_no_commas (parser, NULL);
7482       vec_safe_push (cexpr_list, expr);
7483     }
7484 
7485   *out_close_paren_loc = c_parser_peek_token (parser)->location;
7486   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7487     return false;
7488 
7489   *ret_cexpr_list = cexpr_list;
7490   return true;
7491 }
7492 
7493 /* This represents a single generic-association.  */
7494 
7495 struct c_generic_association
7496 {
7497   /* The location of the starting token of the type.  */
7498   location_t type_location;
7499   /* The association's type, or NULL_TREE for 'default'.  */
7500   tree type;
7501   /* The association's expression.  */
7502   struct c_expr expression;
7503 };
7504 
7505 /* Parse a generic-selection.  (C11 6.5.1.1).
7506 
7507    generic-selection:
7508      _Generic ( assignment-expression , generic-assoc-list )
7509 
7510    generic-assoc-list:
7511      generic-association
7512      generic-assoc-list , generic-association
7513 
7514    generic-association:
7515      type-name : assignment-expression
7516      default : assignment-expression
7517 */
7518 
7519 static struct c_expr
7520 c_parser_generic_selection (c_parser *parser)
7521 {
7522   struct c_expr selector, error_expr;
7523   tree selector_type;
7524   struct c_generic_association matched_assoc;
7525   bool match_found = false;
7526   location_t generic_loc, selector_loc;
7527 
7528   error_expr.original_code = ERROR_MARK;
7529   error_expr.original_type = NULL;
7530   error_expr.set_error ();
7531   matched_assoc.type_location = UNKNOWN_LOCATION;
7532   matched_assoc.type = NULL_TREE;
7533   matched_assoc.expression = error_expr;
7534 
7535   gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
7536   generic_loc = c_parser_peek_token (parser)->location;
7537   c_parser_consume_token (parser);
7538   if (flag_isoc99)
7539     pedwarn_c99 (generic_loc, OPT_Wpedantic,
7540 		 "ISO C99 does not support %<_Generic%>");
7541   else
7542     pedwarn_c99 (generic_loc, OPT_Wpedantic,
7543 		 "ISO C90 does not support %<_Generic%>");
7544 
7545   matching_parens parens;
7546   if (!parens.require_open (parser))
7547     return error_expr;
7548 
7549   c_inhibit_evaluation_warnings++;
7550   selector_loc = c_parser_peek_token (parser)->location;
7551   selector = c_parser_expr_no_commas (parser, NULL);
7552   selector = default_function_array_conversion (selector_loc, selector);
7553   c_inhibit_evaluation_warnings--;
7554 
7555   if (selector.value == error_mark_node)
7556     {
7557       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7558       return selector;
7559     }
7560   selector_type = TREE_TYPE (selector.value);
7561   /* In ISO C terms, rvalues (including the controlling expression of
7562      _Generic) do not have qualified types.  */
7563   if (TREE_CODE (selector_type) != ARRAY_TYPE)
7564     selector_type = TYPE_MAIN_VARIANT (selector_type);
7565   /* In ISO C terms, _Noreturn is not part of the type of expressions
7566      such as &abort, but in GCC it is represented internally as a type
7567      qualifier.  */
7568   if (FUNCTION_POINTER_TYPE_P (selector_type)
7569       && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
7570     selector_type
7571       = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
7572 
7573   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7574     {
7575       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7576       return error_expr;
7577     }
7578 
7579   auto_vec<c_generic_association> associations;
7580   while (1)
7581     {
7582       struct c_generic_association assoc, *iter;
7583       unsigned int ix;
7584       c_token *token = c_parser_peek_token (parser);
7585 
7586       assoc.type_location = token->location;
7587       if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
7588 	{
7589 	  c_parser_consume_token (parser);
7590 	  assoc.type = NULL_TREE;
7591 	}
7592       else
7593 	{
7594 	  struct c_type_name *type_name;
7595 
7596 	  type_name = c_parser_type_name (parser);
7597 	  if (type_name == NULL)
7598 	    {
7599 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7600 	      return error_expr;
7601 	    }
7602 	  assoc.type = groktypename (type_name, NULL, NULL);
7603 	  if (assoc.type == error_mark_node)
7604 	    {
7605 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7606 	      return error_expr;
7607 	    }
7608 
7609 	  if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
7610 	    error_at (assoc.type_location,
7611 		      "%<_Generic%> association has function type");
7612 	  else if (!COMPLETE_TYPE_P (assoc.type))
7613 	    error_at (assoc.type_location,
7614 		      "%<_Generic%> association has incomplete type");
7615 
7616 	  if (variably_modified_type_p (assoc.type, NULL_TREE))
7617 	    error_at (assoc.type_location,
7618 		      "%<_Generic%> association has "
7619 		      "variable length type");
7620 	}
7621 
7622       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7623 	{
7624 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7625 	  return error_expr;
7626 	}
7627 
7628       assoc.expression = c_parser_expr_no_commas (parser, NULL);
7629       if (assoc.expression.value == error_mark_node)
7630 	{
7631 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7632 	  return error_expr;
7633 	}
7634 
7635       for (ix = 0; associations.iterate (ix, &iter); ++ix)
7636 	{
7637 	  if (assoc.type == NULL_TREE)
7638 	    {
7639 	      if (iter->type == NULL_TREE)
7640 		{
7641 		  error_at (assoc.type_location,
7642 			    "duplicate %<default%> case in %<_Generic%>");
7643 		  inform (iter->type_location, "original %<default%> is here");
7644 		}
7645 	    }
7646 	  else if (iter->type != NULL_TREE)
7647 	    {
7648 	      if (comptypes (assoc.type, iter->type))
7649 		{
7650 		  error_at (assoc.type_location,
7651 			    "%<_Generic%> specifies two compatible types");
7652 		  inform (iter->type_location, "compatible type is here");
7653 		}
7654 	    }
7655 	}
7656 
7657       if (assoc.type == NULL_TREE)
7658 	{
7659 	  if (!match_found)
7660 	    {
7661 	      matched_assoc = assoc;
7662 	      match_found = true;
7663 	    }
7664 	}
7665       else if (comptypes (assoc.type, selector_type))
7666 	{
7667 	  if (!match_found || matched_assoc.type == NULL_TREE)
7668 	    {
7669 	      matched_assoc = assoc;
7670 	      match_found = true;
7671 	    }
7672 	  else
7673 	    {
7674 	      error_at (assoc.type_location,
7675 			"%<_Generic%> selector matches multiple associations");
7676 	      inform (matched_assoc.type_location,
7677 		      "other match is here");
7678 	    }
7679 	}
7680 
7681       associations.safe_push (assoc);
7682 
7683       if (c_parser_peek_token (parser)->type != CPP_COMMA)
7684 	break;
7685       c_parser_consume_token (parser);
7686     }
7687 
7688   if (!parens.require_close (parser))
7689     {
7690       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7691       return error_expr;
7692     }
7693 
7694   if (!match_found)
7695     {
7696       error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7697 		"compatible with any association",
7698 		selector_type);
7699       return error_expr;
7700     }
7701 
7702   return matched_assoc.expression;
7703 }
7704 
7705 /* Check the validity of a function pointer argument *EXPR (argument
7706    position POS) to __builtin_tgmath.  Return the number of function
7707    arguments if possibly valid; return 0 having reported an error if
7708    not valid.  */
7709 
7710 static unsigned int
7711 check_tgmath_function (c_expr *expr, unsigned int pos)
7712 {
7713   tree type = TREE_TYPE (expr->value);
7714   if (!FUNCTION_POINTER_TYPE_P (type))
7715     {
7716       error_at (expr->get_location (),
7717 		"argument %u of %<__builtin_tgmath%> is not a function pointer",
7718 		pos);
7719       return 0;
7720     }
7721   type = TREE_TYPE (type);
7722   if (!prototype_p (type))
7723     {
7724       error_at (expr->get_location (),
7725 		"argument %u of %<__builtin_tgmath%> is unprototyped", pos);
7726       return 0;
7727     }
7728   if (stdarg_p (type))
7729     {
7730       error_at (expr->get_location (),
7731 		"argument %u of %<__builtin_tgmath%> has variable arguments",
7732 		pos);
7733       return 0;
7734     }
7735   unsigned int nargs = 0;
7736   function_args_iterator iter;
7737   tree t;
7738   FOREACH_FUNCTION_ARGS (type, t, iter)
7739     {
7740       if (t == void_type_node)
7741 	break;
7742       nargs++;
7743     }
7744   if (nargs == 0)
7745     {
7746       error_at (expr->get_location (),
7747 		"argument %u of %<__builtin_tgmath%> has no arguments", pos);
7748       return 0;
7749     }
7750   return nargs;
7751 }
7752 
7753 /* Ways in which a parameter or return value of a type-generic macro
7754    may vary between the different functions the macro may call.  */
7755 enum tgmath_parm_kind
7756   {
7757     tgmath_fixed, tgmath_real, tgmath_complex
7758   };
7759 
7760 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7761    C11 6.5.1-6.5.2).  Compound literals aren't handled here; callers have to
7762    call c_parser_postfix_expression_after_paren_type on encountering them.
7763 
7764    postfix-expression:
7765      primary-expression
7766      postfix-expression [ expression ]
7767      postfix-expression ( argument-expression-list[opt] )
7768      postfix-expression . identifier
7769      postfix-expression -> identifier
7770      postfix-expression ++
7771      postfix-expression --
7772      ( type-name ) { initializer-list }
7773      ( type-name ) { initializer-list , }
7774 
7775    argument-expression-list:
7776      argument-expression
7777      argument-expression-list , argument-expression
7778 
7779    primary-expression:
7780      identifier
7781      constant
7782      string-literal
7783      ( expression )
7784      generic-selection
7785 
7786    GNU extensions:
7787 
7788    primary-expression:
7789      __func__
7790        (treated as a keyword in GNU C)
7791      __FUNCTION__
7792      __PRETTY_FUNCTION__
7793      ( compound-statement )
7794      __builtin_va_arg ( assignment-expression , type-name )
7795      __builtin_offsetof ( type-name , offsetof-member-designator )
7796      __builtin_choose_expr ( assignment-expression ,
7797 			     assignment-expression ,
7798 			     assignment-expression )
7799      __builtin_types_compatible_p ( type-name , type-name )
7800      __builtin_tgmath ( expr-list )
7801      __builtin_complex ( assignment-expression , assignment-expression )
7802      __builtin_shuffle ( assignment-expression , assignment-expression )
7803      __builtin_shuffle ( assignment-expression ,
7804 			 assignment-expression ,
7805 			 assignment-expression, )
7806 
7807    offsetof-member-designator:
7808      identifier
7809      offsetof-member-designator . identifier
7810      offsetof-member-designator [ expression ]
7811 
7812    Objective-C:
7813 
7814    primary-expression:
7815      [ objc-receiver objc-message-args ]
7816      @selector ( objc-selector-arg )
7817      @protocol ( identifier )
7818      @encode ( type-name )
7819      objc-string-literal
7820      Classname . identifier
7821 */
7822 
7823 static struct c_expr
7824 c_parser_postfix_expression (c_parser *parser)
7825 {
7826   struct c_expr expr, e1;
7827   struct c_type_name *t1, *t2;
7828   location_t loc = c_parser_peek_token (parser)->location;
7829   source_range tok_range = c_parser_peek_token (parser)->get_range ();
7830   expr.original_code = ERROR_MARK;
7831   expr.original_type = NULL;
7832   switch (c_parser_peek_token (parser)->type)
7833     {
7834     case CPP_NUMBER:
7835       expr.value = c_parser_peek_token (parser)->value;
7836       set_c_expr_source_range (&expr, tok_range);
7837       loc = c_parser_peek_token (parser)->location;
7838       c_parser_consume_token (parser);
7839       if (TREE_CODE (expr.value) == FIXED_CST
7840 	  && !targetm.fixed_point_supported_p ())
7841 	{
7842 	  error_at (loc, "fixed-point types not supported for this target");
7843 	  expr.set_error ();
7844 	}
7845       break;
7846     case CPP_CHAR:
7847     case CPP_CHAR16:
7848     case CPP_CHAR32:
7849     case CPP_WCHAR:
7850       expr.value = c_parser_peek_token (parser)->value;
7851       /* For the purpose of warning when a pointer is compared with
7852 	 a zero character constant.  */
7853       expr.original_type = char_type_node;
7854       set_c_expr_source_range (&expr, tok_range);
7855       c_parser_consume_token (parser);
7856       break;
7857     case CPP_STRING:
7858     case CPP_STRING16:
7859     case CPP_STRING32:
7860     case CPP_WSTRING:
7861     case CPP_UTF8STRING:
7862       expr.value = c_parser_peek_token (parser)->value;
7863       set_c_expr_source_range (&expr, tok_range);
7864       expr.original_code = STRING_CST;
7865       c_parser_consume_token (parser);
7866       break;
7867     case CPP_OBJC_STRING:
7868       gcc_assert (c_dialect_objc ());
7869       expr.value
7870 	= objc_build_string_object (c_parser_peek_token (parser)->value);
7871       set_c_expr_source_range (&expr, tok_range);
7872       c_parser_consume_token (parser);
7873       break;
7874     case CPP_NAME:
7875       switch (c_parser_peek_token (parser)->id_kind)
7876 	{
7877 	case C_ID_ID:
7878 	  {
7879 	    tree id = c_parser_peek_token (parser)->value;
7880 	    c_parser_consume_token (parser);
7881 	    expr.value = build_external_ref (loc, id,
7882 					     (c_parser_peek_token (parser)->type
7883 					      == CPP_OPEN_PAREN),
7884 					     &expr.original_type);
7885 	    set_c_expr_source_range (&expr, tok_range);
7886 	    break;
7887 	  }
7888 	case C_ID_CLASSNAME:
7889 	  {
7890 	    /* Here we parse the Objective-C 2.0 Class.name dot
7891 	       syntax.  */
7892 	    tree class_name = c_parser_peek_token (parser)->value;
7893 	    tree component;
7894 	    c_parser_consume_token (parser);
7895 	    gcc_assert (c_dialect_objc ());
7896 	    if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7897 	      {
7898 		expr.set_error ();
7899 		break;
7900 	      }
7901 	    if (c_parser_next_token_is_not (parser, CPP_NAME))
7902 	      {
7903 		c_parser_error (parser, "expected identifier");
7904 		expr.set_error ();
7905 		break;
7906 	      }
7907 	    c_token *component_tok = c_parser_peek_token (parser);
7908 	    component = component_tok->value;
7909 	    location_t end_loc = component_tok->get_finish ();
7910 	    c_parser_consume_token (parser);
7911 	    expr.value = objc_build_class_component_ref (class_name,
7912 							 component);
7913 	    set_c_expr_source_range (&expr, loc, end_loc);
7914 	    break;
7915 	  }
7916 	default:
7917 	  c_parser_error (parser, "expected expression");
7918 	  expr.set_error ();
7919 	  break;
7920 	}
7921       break;
7922     case CPP_OPEN_PAREN:
7923       /* A parenthesized expression, statement expression or compound
7924 	 literal.  */
7925       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7926 	{
7927 	  /* A statement expression.  */
7928 	  tree stmt;
7929 	  location_t brace_loc;
7930 	  c_parser_consume_token (parser);
7931 	  brace_loc = c_parser_peek_token (parser)->location;
7932 	  c_parser_consume_token (parser);
7933 	  if (!building_stmt_list_p ())
7934 	    {
7935 	      error_at (loc, "braced-group within expression allowed "
7936 			"only inside a function");
7937 	      parser->error = true;
7938 	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7939 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7940 	      expr.set_error ();
7941 	      break;
7942 	    }
7943 	  stmt = c_begin_stmt_expr ();
7944 	  c_parser_compound_statement_nostart (parser);
7945 	  location_t close_loc = c_parser_peek_token (parser)->location;
7946 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7947 				     "expected %<)%>");
7948 	  pedwarn (loc, OPT_Wpedantic,
7949 		   "ISO C forbids braced-groups within expressions");
7950 	  expr.value = c_finish_stmt_expr (brace_loc, stmt);
7951 	  set_c_expr_source_range (&expr, loc, close_loc);
7952 	  mark_exp_read (expr.value);
7953 	}
7954       else
7955 	{
7956 	  /* A parenthesized expression.  */
7957 	  location_t loc_open_paren = c_parser_peek_token (parser)->location;
7958 	  c_parser_consume_token (parser);
7959 	  expr = c_parser_expression (parser);
7960 	  if (TREE_CODE (expr.value) == MODIFY_EXPR)
7961 	    TREE_NO_WARNING (expr.value) = 1;
7962 	  if (expr.original_code != C_MAYBE_CONST_EXPR
7963 	      && expr.original_code != SIZEOF_EXPR)
7964 	    expr.original_code = ERROR_MARK;
7965 	  /* Don't change EXPR.ORIGINAL_TYPE.  */
7966 	  location_t loc_close_paren = c_parser_peek_token (parser)->location;
7967 	  set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren);
7968 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7969 				     "expected %<)%>", loc_open_paren);
7970 	}
7971       break;
7972     case CPP_KEYWORD:
7973       switch (c_parser_peek_token (parser)->keyword)
7974 	{
7975 	case RID_FUNCTION_NAME:
7976 	  pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7977 		   "%<__FUNCTION__%> predefined identifier");
7978 	  expr.value = fname_decl (loc,
7979 				   c_parser_peek_token (parser)->keyword,
7980 				   c_parser_peek_token (parser)->value);
7981 	  set_c_expr_source_range (&expr, loc, loc);
7982 	  c_parser_consume_token (parser);
7983 	  break;
7984 	case RID_PRETTY_FUNCTION_NAME:
7985 	  pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7986 		   "%<__PRETTY_FUNCTION__%> predefined identifier");
7987 	  expr.value = fname_decl (loc,
7988 				   c_parser_peek_token (parser)->keyword,
7989 				   c_parser_peek_token (parser)->value);
7990 	  set_c_expr_source_range (&expr, loc, loc);
7991 	  c_parser_consume_token (parser);
7992 	  break;
7993 	case RID_C99_FUNCTION_NAME:
7994 	  pedwarn_c90 (loc, OPT_Wpedantic,  "ISO C90 does not support "
7995 		   "%<__func__%> predefined identifier");
7996 	  expr.value = fname_decl (loc,
7997 				   c_parser_peek_token (parser)->keyword,
7998 				   c_parser_peek_token (parser)->value);
7999 	  set_c_expr_source_range (&expr, loc, loc);
8000 	  c_parser_consume_token (parser);
8001 	  break;
8002 	case RID_VA_ARG:
8003 	  {
8004 	    location_t start_loc = loc;
8005 	    c_parser_consume_token (parser);
8006 	    matching_parens parens;
8007 	    if (!parens.require_open (parser))
8008 	      {
8009 		expr.set_error ();
8010 		break;
8011 	      }
8012 	    e1 = c_parser_expr_no_commas (parser, NULL);
8013 	    mark_exp_read (e1.value);
8014 	    e1.value = c_fully_fold (e1.value, false, NULL);
8015 	    if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
8016 	      {
8017 		c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8018 		expr.set_error ();
8019 		break;
8020 	      }
8021 	    loc = c_parser_peek_token (parser)->location;
8022 	    t1 = c_parser_type_name (parser);
8023 	    location_t end_loc = c_parser_peek_token (parser)->get_finish ();
8024 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8025 				       "expected %<)%>");
8026 	    if (t1 == NULL)
8027 	      {
8028 		expr.set_error ();
8029 	      }
8030 	    else
8031 	      {
8032 		tree type_expr = NULL_TREE;
8033 		expr.value = c_build_va_arg (start_loc, e1.value, loc,
8034 					     groktypename (t1, &type_expr, NULL));
8035 		if (type_expr)
8036 		  {
8037 		    expr.value = build2 (C_MAYBE_CONST_EXPR,
8038 					 TREE_TYPE (expr.value), type_expr,
8039 					 expr.value);
8040 		    C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
8041 		  }
8042 		set_c_expr_source_range (&expr, start_loc, end_loc);
8043 	      }
8044 	  }
8045 	  break;
8046 	case RID_OFFSETOF:
8047 	  {
8048 	    c_parser_consume_token (parser);
8049 	    matching_parens parens;
8050 	    if (!parens.require_open (parser))
8051 	      {
8052 		expr.set_error ();
8053 		break;
8054 	      }
8055 	    t1 = c_parser_type_name (parser);
8056 	    if (t1 == NULL)
8057 	      parser->error = true;
8058 	    if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
8059 	      gcc_assert (parser->error);
8060 	    if (parser->error)
8061 	      {
8062 		c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8063 		expr.set_error ();
8064 		break;
8065 	      }
8066 	    tree type = groktypename (t1, NULL, NULL);
8067 	    tree offsetof_ref;
8068 	    if (type == error_mark_node)
8069 	      offsetof_ref = error_mark_node;
8070 	    else
8071 	      {
8072 		offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
8073 		SET_EXPR_LOCATION (offsetof_ref, loc);
8074 	      }
8075 	    /* Parse the second argument to __builtin_offsetof.  We
8076 	       must have one identifier, and beyond that we want to
8077 	       accept sub structure and sub array references.  */
8078 	    if (c_parser_next_token_is (parser, CPP_NAME))
8079 	      {
8080 		c_token *comp_tok = c_parser_peek_token (parser);
8081 		offsetof_ref = build_component_ref
8082 		  (loc, offsetof_ref, comp_tok->value, comp_tok->location);
8083 		c_parser_consume_token (parser);
8084 		while (c_parser_next_token_is (parser, CPP_DOT)
8085 		       || c_parser_next_token_is (parser,
8086 						  CPP_OPEN_SQUARE)
8087 		       || c_parser_next_token_is (parser,
8088 						  CPP_DEREF))
8089 		  {
8090 		    if (c_parser_next_token_is (parser, CPP_DEREF))
8091 		      {
8092 			loc = c_parser_peek_token (parser)->location;
8093 			offsetof_ref = build_array_ref (loc,
8094 							offsetof_ref,
8095 							integer_zero_node);
8096 			goto do_dot;
8097 		      }
8098 		    else if (c_parser_next_token_is (parser, CPP_DOT))
8099 		      {
8100 		      do_dot:
8101 			c_parser_consume_token (parser);
8102 			if (c_parser_next_token_is_not (parser,
8103 							CPP_NAME))
8104 			  {
8105 			    c_parser_error (parser, "expected identifier");
8106 			    break;
8107 			  }
8108 			c_token *comp_tok = c_parser_peek_token (parser);
8109 			offsetof_ref = build_component_ref
8110 			  (loc, offsetof_ref, comp_tok->value,
8111 			   comp_tok->location);
8112 			c_parser_consume_token (parser);
8113 		      }
8114 		    else
8115 		      {
8116 			struct c_expr ce;
8117 			tree idx;
8118 			loc = c_parser_peek_token (parser)->location;
8119 			c_parser_consume_token (parser);
8120 			ce = c_parser_expression (parser);
8121 			ce = convert_lvalue_to_rvalue (loc, ce, false, false);
8122 			idx = ce.value;
8123 			idx = c_fully_fold (idx, false, NULL);
8124 			c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
8125 						   "expected %<]%>");
8126 			offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
8127 		      }
8128 		  }
8129 	      }
8130 	    else
8131 	      c_parser_error (parser, "expected identifier");
8132 	    location_t end_loc = c_parser_peek_token (parser)->get_finish ();
8133 	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8134 				       "expected %<)%>");
8135 	    expr.value = fold_offsetof (offsetof_ref);
8136 	    set_c_expr_source_range (&expr, loc, end_loc);
8137 	  }
8138 	  break;
8139 	case RID_CHOOSE_EXPR:
8140 	  {
8141 	    vec<c_expr_t, va_gc> *cexpr_list;
8142 	    c_expr_t *e1_p, *e2_p, *e3_p;
8143 	    tree c;
8144 	    location_t close_paren_loc;
8145 
8146 	    c_parser_consume_token (parser);
8147 	    if (!c_parser_get_builtin_args (parser,
8148 					    "__builtin_choose_expr",
8149 					    &cexpr_list, true,
8150 					    &close_paren_loc))
8151 	      {
8152 		expr.set_error ();
8153 		break;
8154 	      }
8155 
8156 	    if (vec_safe_length (cexpr_list) != 3)
8157 	      {
8158 		error_at (loc, "wrong number of arguments to "
8159 			       "%<__builtin_choose_expr%>");
8160 		expr.set_error ();
8161 		break;
8162 	      }
8163 
8164 	    e1_p = &(*cexpr_list)[0];
8165 	    e2_p = &(*cexpr_list)[1];
8166 	    e3_p = &(*cexpr_list)[2];
8167 
8168 	    c = e1_p->value;
8169 	    mark_exp_read (e2_p->value);
8170 	    mark_exp_read (e3_p->value);
8171 	    if (TREE_CODE (c) != INTEGER_CST
8172 		|| !INTEGRAL_TYPE_P (TREE_TYPE (c)))
8173 	      error_at (loc,
8174 			"first argument to %<__builtin_choose_expr%> not"
8175 			" a constant");
8176 	    constant_expression_warning (c);
8177 	    expr = integer_zerop (c) ? *e3_p : *e2_p;
8178 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8179 	    break;
8180 	  }
8181 	case RID_TYPES_COMPATIBLE_P:
8182 	  {
8183 	    c_parser_consume_token (parser);
8184 	    matching_parens parens;
8185 	    if (!parens.require_open (parser))
8186 	      {
8187 		expr.set_error ();
8188 		break;
8189 	      }
8190 	    t1 = c_parser_type_name (parser);
8191 	    if (t1 == NULL)
8192 	      {
8193 		expr.set_error ();
8194 		break;
8195 	      }
8196 	    if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
8197 	      {
8198 		c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8199 		expr.set_error ();
8200 		break;
8201 	      }
8202 	    t2 = c_parser_type_name (parser);
8203 	    if (t2 == NULL)
8204 	      {
8205 		expr.set_error ();
8206 		break;
8207 	      }
8208 	    location_t close_paren_loc = c_parser_peek_token (parser)->location;
8209 	    parens.skip_until_found_close (parser);
8210 	    tree e1, e2;
8211 	    e1 = groktypename (t1, NULL, NULL);
8212 	    e2 = groktypename (t2, NULL, NULL);
8213 	    if (e1 == error_mark_node || e2 == error_mark_node)
8214 	      {
8215 		expr.set_error ();
8216 		break;
8217 	      }
8218 
8219 	    e1 = TYPE_MAIN_VARIANT (e1);
8220 	    e2 = TYPE_MAIN_VARIANT (e2);
8221 
8222 	    expr.value
8223 	      = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
8224 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8225 	  }
8226 	  break;
8227 	case RID_BUILTIN_TGMATH:
8228 	  {
8229 	    vec<c_expr_t, va_gc> *cexpr_list;
8230 	    location_t close_paren_loc;
8231 
8232 	    c_parser_consume_token (parser);
8233 	    if (!c_parser_get_builtin_args (parser,
8234 					    "__builtin_tgmath",
8235 					    &cexpr_list, false,
8236 					    &close_paren_loc))
8237 	      {
8238 		expr.set_error ();
8239 		break;
8240 	      }
8241 
8242 	    if (vec_safe_length (cexpr_list) < 3)
8243 	      {
8244 		error_at (loc, "too few arguments to %<__builtin_tgmath%>");
8245 		expr.set_error ();
8246 		break;
8247 	      }
8248 
8249 	    unsigned int i;
8250 	    c_expr_t *p;
8251 	    FOR_EACH_VEC_ELT (*cexpr_list, i, p)
8252 	      *p = convert_lvalue_to_rvalue (loc, *p, true, true);
8253 	    unsigned int nargs = check_tgmath_function (&(*cexpr_list)[0], 1);
8254 	    if (nargs == 0)
8255 	      {
8256 		expr.set_error ();
8257 		break;
8258 	      }
8259 	    if (vec_safe_length (cexpr_list) < nargs)
8260 	      {
8261 		error_at (loc, "too few arguments to %<__builtin_tgmath%>");
8262 		expr.set_error ();
8263 		break;
8264 	      }
8265 	    unsigned int num_functions = vec_safe_length (cexpr_list) - nargs;
8266 	    if (num_functions < 2)
8267 	      {
8268 		error_at (loc, "too few arguments to %<__builtin_tgmath%>");
8269 		expr.set_error ();
8270 		break;
8271 	      }
8272 
8273 	    /* The first NUM_FUNCTIONS expressions are the function
8274 	       pointers.  The remaining NARGS expressions are the
8275 	       arguments that are to be passed to one of those
8276 	       functions, chosen following <tgmath.h> rules.  */
8277 	    for (unsigned int j = 1; j < num_functions; j++)
8278 	      {
8279 		unsigned int this_nargs
8280 		  = check_tgmath_function (&(*cexpr_list)[j], j + 1);
8281 		if (this_nargs == 0)
8282 		  {
8283 		    expr.set_error ();
8284 		    goto out;
8285 		  }
8286 		if (this_nargs != nargs)
8287 		  {
8288 		    error_at ((*cexpr_list)[j].get_location (),
8289 			      "argument %u of %<__builtin_tgmath%> has "
8290 			      "wrong number of arguments", j + 1);
8291 		    expr.set_error ();
8292 		    goto out;
8293 		  }
8294 	      }
8295 
8296 	    /* The functions all have the same number of arguments.
8297 	       Determine whether arguments and return types vary in
8298 	       ways permitted for <tgmath.h> functions.  */
8299 	    /* The first entry in each of these vectors is for the
8300 	       return type, subsequent entries for parameter
8301 	       types.  */
8302 	    auto_vec<enum tgmath_parm_kind> parm_kind (nargs + 1);
8303 	    auto_vec<tree> parm_first (nargs + 1);
8304 	    auto_vec<bool> parm_complex (nargs + 1);
8305 	    auto_vec<bool> parm_varies (nargs + 1);
8306 	    tree first_type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[0].value));
8307 	    tree first_ret = TYPE_MAIN_VARIANT (TREE_TYPE (first_type));
8308 	    parm_first.quick_push (first_ret);
8309 	    parm_complex.quick_push (TREE_CODE (first_ret) == COMPLEX_TYPE);
8310 	    parm_varies.quick_push (false);
8311 	    function_args_iterator iter;
8312 	    tree t;
8313 	    unsigned int argpos;
8314 	    FOREACH_FUNCTION_ARGS (first_type, t, iter)
8315 	      {
8316 		if (t == void_type_node)
8317 		  break;
8318 		parm_first.quick_push (TYPE_MAIN_VARIANT (t));
8319 		parm_complex.quick_push (TREE_CODE (t) == COMPLEX_TYPE);
8320 		parm_varies.quick_push (false);
8321 	      }
8322 	    for (unsigned int j = 1; j < num_functions; j++)
8323 	      {
8324 		tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
8325 		tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type));
8326 		if (ret != parm_first[0])
8327 		  {
8328 		    parm_varies[0] = true;
8329 		    if (!SCALAR_FLOAT_TYPE_P (parm_first[0])
8330 			&& !COMPLEX_FLOAT_TYPE_P (parm_first[0]))
8331 		      {
8332 			error_at ((*cexpr_list)[0].get_location (),
8333 				  "invalid type-generic return type for "
8334 				  "argument %u of %<__builtin_tgmath%>",
8335 				  1);
8336 			expr.set_error ();
8337 			goto out;
8338 		      }
8339 		    if (!SCALAR_FLOAT_TYPE_P (ret)
8340 			&& !COMPLEX_FLOAT_TYPE_P (ret))
8341 		      {
8342 			error_at ((*cexpr_list)[j].get_location (),
8343 				  "invalid type-generic return type for "
8344 				  "argument %u of %<__builtin_tgmath%>",
8345 				  j + 1);
8346 			expr.set_error ();
8347 			goto out;
8348 		      }
8349 		  }
8350 		if (TREE_CODE (ret) == COMPLEX_TYPE)
8351 		  parm_complex[0] = true;
8352 		argpos = 1;
8353 		FOREACH_FUNCTION_ARGS (type, t, iter)
8354 		  {
8355 		    if (t == void_type_node)
8356 		      break;
8357 		    t = TYPE_MAIN_VARIANT (t);
8358 		    if (t != parm_first[argpos])
8359 		      {
8360 			parm_varies[argpos] = true;
8361 			if (!SCALAR_FLOAT_TYPE_P (parm_first[argpos])
8362 			    && !COMPLEX_FLOAT_TYPE_P (parm_first[argpos]))
8363 			  {
8364 			    error_at ((*cexpr_list)[0].get_location (),
8365 				      "invalid type-generic type for "
8366 				      "argument %u of argument %u of "
8367 				      "%<__builtin_tgmath%>", argpos, 1);
8368 			    expr.set_error ();
8369 			    goto out;
8370 			  }
8371 			if (!SCALAR_FLOAT_TYPE_P (t)
8372 			    && !COMPLEX_FLOAT_TYPE_P (t))
8373 			  {
8374 			    error_at ((*cexpr_list)[j].get_location (),
8375 				      "invalid type-generic type for "
8376 				      "argument %u of argument %u of "
8377 				      "%<__builtin_tgmath%>", argpos, j + 1);
8378 			    expr.set_error ();
8379 			    goto out;
8380 			  }
8381 		      }
8382 		    if (TREE_CODE (t) == COMPLEX_TYPE)
8383 		      parm_complex[argpos] = true;
8384 		    argpos++;
8385 		  }
8386 	      }
8387 	    enum tgmath_parm_kind max_variation = tgmath_fixed;
8388 	    for (unsigned int j = 0; j <= nargs; j++)
8389 	      {
8390 		enum tgmath_parm_kind this_kind;
8391 		if (parm_varies[j])
8392 		  {
8393 		    if (parm_complex[j])
8394 		      max_variation = this_kind = tgmath_complex;
8395 		    else
8396 		      {
8397 			this_kind = tgmath_real;
8398 			if (max_variation != tgmath_complex)
8399 			  max_variation = tgmath_real;
8400 		      }
8401 		  }
8402 		else
8403 		  this_kind = tgmath_fixed;
8404 		parm_kind.quick_push (this_kind);
8405 	      }
8406 	    if (max_variation == tgmath_fixed)
8407 	      {
8408 		error_at (loc, "function arguments of %<__builtin_tgmath%> "
8409 			  "all have the same type");
8410 		expr.set_error ();
8411 		break;
8412 	      }
8413 
8414 	    /* Identify a parameter (not the return type) that varies,
8415 	       including with complex types if any variation includes
8416 	       complex types; there must be at least one such
8417 	       parameter.  */
8418 	    unsigned int tgarg = 0;
8419 	    for (unsigned int j = 1; j <= nargs; j++)
8420 	      if (parm_kind[j] == max_variation)
8421 		{
8422 		  tgarg = j;
8423 		  break;
8424 		}
8425 	    if (tgarg == 0)
8426 	      {
8427 		error_at (loc, "function arguments of %<__builtin_tgmath%> "
8428 			  "lack type-generic parameter");
8429 		expr.set_error ();
8430 		break;
8431 	      }
8432 
8433 	    /* Determine the type of the relevant parameter for each
8434 	       function.  */
8435 	    auto_vec<tree> tg_type (num_functions);
8436 	    for (unsigned int j = 0; j < num_functions; j++)
8437 	      {
8438 		tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
8439 		argpos = 1;
8440 		FOREACH_FUNCTION_ARGS (type, t, iter)
8441 		  {
8442 		    if (argpos == tgarg)
8443 		      {
8444 			tg_type.quick_push (TYPE_MAIN_VARIANT (t));
8445 			break;
8446 		      }
8447 		    argpos++;
8448 		  }
8449 	      }
8450 
8451 	    /* Verify that the corresponding types are different for
8452 	       all the listed functions.  Also determine whether all
8453 	       the types are complex, whether all the types are
8454 	       standard or binary, and whether all the types are
8455 	       decimal.  */
8456 	    bool all_complex = true;
8457 	    bool all_binary = true;
8458 	    bool all_decimal = true;
8459 	    hash_set<tree> tg_types;
8460 	    FOR_EACH_VEC_ELT (tg_type, i, t)
8461 	      {
8462 		if (TREE_CODE (t) == COMPLEX_TYPE)
8463 		  all_decimal = false;
8464 		else
8465 		  {
8466 		    all_complex = false;
8467 		    if (DECIMAL_FLOAT_TYPE_P (t))
8468 		      all_binary = false;
8469 		    else
8470 		      all_decimal = false;
8471 		  }
8472 		if (tg_types.add (t))
8473 		  {
8474 		    error_at ((*cexpr_list)[i].get_location (),
8475 			      "duplicate type-generic parameter type for "
8476 			      "function argument %u of %<__builtin_tgmath%>",
8477 			      i + 1);
8478 		    expr.set_error ();
8479 		    goto out;
8480 		  }
8481 	      }
8482 
8483 	    /* Verify that other parameters and the return type whose
8484 	       types vary have their types varying in the correct
8485 	       way.  */
8486 	    for (unsigned int j = 0; j < num_functions; j++)
8487 	      {
8488 		tree exp_type = tg_type[j];
8489 		tree exp_real_type = exp_type;
8490 		if (TREE_CODE (exp_type) == COMPLEX_TYPE)
8491 		  exp_real_type = TREE_TYPE (exp_type);
8492 		tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
8493 		tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type));
8494 		if ((parm_kind[0] == tgmath_complex && ret != exp_type)
8495 		    || (parm_kind[0] == tgmath_real && ret != exp_real_type))
8496 		  {
8497 		    error_at ((*cexpr_list)[j].get_location (),
8498 			      "bad return type for function argument %u "
8499 			      "of %<__builtin_tgmath%>", j + 1);
8500 		    expr.set_error ();
8501 		    goto out;
8502 		  }
8503 		argpos = 1;
8504 		FOREACH_FUNCTION_ARGS (type, t, iter)
8505 		  {
8506 		    if (t == void_type_node)
8507 		      break;
8508 		    t = TYPE_MAIN_VARIANT (t);
8509 		    if ((parm_kind[argpos] == tgmath_complex
8510 			 && t != exp_type)
8511 			|| (parm_kind[argpos] == tgmath_real
8512 			    && t != exp_real_type))
8513 		      {
8514 			error_at ((*cexpr_list)[j].get_location (),
8515 				  "bad type for argument %u of "
8516 				  "function argument %u of "
8517 				  "%<__builtin_tgmath%>", argpos, j + 1);
8518 			expr.set_error ();
8519 			goto out;
8520 		      }
8521 		    argpos++;
8522 		  }
8523 	      }
8524 
8525 	    /* The functions listed are a valid set of functions for a
8526 	       <tgmath.h> macro to select between.  Identify the
8527 	       matching function, if any.  First, the argument types
8528 	       must be combined following <tgmath.h> rules.  Integer
8529 	       types are treated as _Decimal64 if any type-generic
8530 	       argument is decimal, or if the only alternatives for
8531 	       type-generic arguments are of decimal types, and are
8532 	       otherwise treated as double (or _Complex double for
8533 	       complex integer types, or _Float64 or _Complex _Float64
8534 	       if all the return types are the same _FloatN or
8535 	       _FloatNx type).  After that adjustment, types are
8536 	       combined following the usual arithmetic conversions.
8537 	       If the function only accepts complex arguments, a
8538 	       complex type is produced.  */
8539 	    bool arg_complex = all_complex;
8540 	    bool arg_binary = all_binary;
8541 	    bool arg_int_decimal = all_decimal;
8542 	    for (unsigned int j = 1; j <= nargs; j++)
8543 	      {
8544 		if (parm_kind[j] == tgmath_fixed)
8545 		  continue;
8546 		c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1];
8547 		tree type = TREE_TYPE (ce->value);
8548 		if (!INTEGRAL_TYPE_P (type)
8549 		    && !SCALAR_FLOAT_TYPE_P (type)
8550 		    && TREE_CODE (type) != COMPLEX_TYPE)
8551 		  {
8552 		    error_at (ce->get_location (),
8553 			      "invalid type of argument %u of type-generic "
8554 			      "function", j);
8555 		    expr.set_error ();
8556 		    goto out;
8557 		  }
8558 		if (DECIMAL_FLOAT_TYPE_P (type))
8559 		  {
8560 		    arg_int_decimal = true;
8561 		    if (all_complex)
8562 		      {
8563 			error_at (ce->get_location (),
8564 				  "decimal floating-point argument %u to "
8565 				  "complex-only type-generic function", j);
8566 			expr.set_error ();
8567 			goto out;
8568 		      }
8569 		    else if (all_binary)
8570 		      {
8571 			error_at (ce->get_location (),
8572 				  "decimal floating-point argument %u to "
8573 				  "binary-only type-generic function", j);
8574 			expr.set_error ();
8575 			goto out;
8576 		      }
8577 		    else if (arg_complex)
8578 		      {
8579 			error_at (ce->get_location (),
8580 				  "both complex and decimal floating-point "
8581 				  "arguments to type-generic function");
8582 			expr.set_error ();
8583 			goto out;
8584 		      }
8585 		    else if (arg_binary)
8586 		      {
8587 			error_at (ce->get_location (),
8588 				  "both binary and decimal floating-point "
8589 				  "arguments to type-generic function");
8590 			expr.set_error ();
8591 			goto out;
8592 		      }
8593 		  }
8594 		else if (TREE_CODE (type) == COMPLEX_TYPE)
8595 		  {
8596 		    arg_complex = true;
8597 		    if (COMPLEX_FLOAT_TYPE_P (type))
8598 		      arg_binary = true;
8599 		    if (all_decimal)
8600 		      {
8601 			error_at (ce->get_location (),
8602 				  "complex argument %u to "
8603 				  "decimal-only type-generic function", j);
8604 			expr.set_error ();
8605 			goto out;
8606 		      }
8607 		    else if (arg_int_decimal)
8608 		      {
8609 			error_at (ce->get_location (),
8610 				  "both complex and decimal floating-point "
8611 				  "arguments to type-generic function");
8612 			expr.set_error ();
8613 			goto out;
8614 		      }
8615 		  }
8616 		else if (SCALAR_FLOAT_TYPE_P (type))
8617 		  {
8618 		    arg_binary = true;
8619 		    if (all_decimal)
8620 		      {
8621 			error_at (ce->get_location (),
8622 				  "binary argument %u to "
8623 				  "decimal-only type-generic function", j);
8624 			expr.set_error ();
8625 			goto out;
8626 		      }
8627 		    else if (arg_int_decimal)
8628 		      {
8629 			error_at (ce->get_location (),
8630 				  "both binary and decimal floating-point "
8631 				  "arguments to type-generic function");
8632 			expr.set_error ();
8633 			goto out;
8634 		      }
8635 		  }
8636 	      }
8637 	    /* For a macro rounding its result to a narrower type, map
8638 	       integer types to _Float64 not double if the return type
8639 	       is a _FloatN or _FloatNx type.  */
8640 	    bool arg_int_float64 = false;
8641 	    if (parm_kind[0] == tgmath_fixed
8642 		&& SCALAR_FLOAT_TYPE_P (parm_first[0])
8643 		&& float64_type_node != NULL_TREE)
8644 	      for (unsigned int j = 0; j < NUM_FLOATN_NX_TYPES; j++)
8645 		if (parm_first[0] == FLOATN_TYPE_NODE (j))
8646 		  {
8647 		    arg_int_float64 = true;
8648 		    break;
8649 		  }
8650 	    tree arg_real = NULL_TREE;
8651 	    for (unsigned int j = 1; j <= nargs; j++)
8652 	      {
8653 		if (parm_kind[j] == tgmath_fixed)
8654 		  continue;
8655 		c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1];
8656 		tree type = TYPE_MAIN_VARIANT (TREE_TYPE (ce->value));
8657 		if (TREE_CODE (type) == COMPLEX_TYPE)
8658 		  type = TREE_TYPE (type);
8659 		if (INTEGRAL_TYPE_P (type))
8660 		  type = (arg_int_decimal
8661 			  ? dfloat64_type_node
8662 			  : arg_int_float64
8663 			  ? float64_type_node
8664 			  : double_type_node);
8665 		if (arg_real == NULL_TREE)
8666 		  arg_real = type;
8667 		else
8668 		  arg_real = common_type (arg_real, type);
8669 		if (arg_real == error_mark_node)
8670 		  {
8671 		    expr.set_error ();
8672 		    goto out;
8673 		  }
8674 	      }
8675 	    tree arg_type = (arg_complex
8676 			     ? build_complex_type (arg_real)
8677 			     : arg_real);
8678 
8679 	    /* Look for a function to call with type-generic parameter
8680 	       type ARG_TYPE.  */
8681 	    c_expr_t *fn = NULL;
8682 	    for (unsigned int j = 0; j < num_functions; j++)
8683 	      {
8684 		if (tg_type[j] == arg_type)
8685 		  {
8686 		    fn = &(*cexpr_list)[j];
8687 		    break;
8688 		  }
8689 	      }
8690 	    if (fn == NULL
8691 		&& parm_kind[0] == tgmath_fixed
8692 		&& SCALAR_FLOAT_TYPE_P (parm_first[0]))
8693 	      {
8694 		/* Presume this is a macro that rounds its result to a
8695 		   narrower type, and look for the first function with
8696 		   at least the range and precision of the argument
8697 		   type.  */
8698 		for (unsigned int j = 0; j < num_functions; j++)
8699 		  {
8700 		    if (arg_complex
8701 			!= (TREE_CODE (tg_type[j]) == COMPLEX_TYPE))
8702 		      continue;
8703 		    tree real_tg_type = (arg_complex
8704 					 ? TREE_TYPE (tg_type[j])
8705 					 : tg_type[j]);
8706 		    if (DECIMAL_FLOAT_TYPE_P (arg_real)
8707 			!= DECIMAL_FLOAT_TYPE_P (real_tg_type))
8708 		      continue;
8709 		    scalar_float_mode arg_mode
8710 		      = SCALAR_FLOAT_TYPE_MODE (arg_real);
8711 		    scalar_float_mode tg_mode
8712 		      = SCALAR_FLOAT_TYPE_MODE (real_tg_type);
8713 		    const real_format *arg_fmt = REAL_MODE_FORMAT (arg_mode);
8714 		    const real_format *tg_fmt = REAL_MODE_FORMAT (tg_mode);
8715 		    if (arg_fmt->b == tg_fmt->b
8716 			&& arg_fmt->p <= tg_fmt->p
8717 			&& arg_fmt->emax <= tg_fmt->emax
8718 			&& (arg_fmt->emin - arg_fmt->p
8719 			    >= tg_fmt->emin - tg_fmt->p))
8720 		      {
8721 			fn = &(*cexpr_list)[j];
8722 			break;
8723 		      }
8724 		  }
8725 	      }
8726 	    if (fn == NULL)
8727 	      {
8728 		error_at (loc, "no matching function for type-generic call");
8729 		expr.set_error ();
8730 		break;
8731 	      }
8732 
8733 	    /* Construct a call to FN.  */
8734 	    vec<tree, va_gc> *args;
8735 	    vec_alloc (args, nargs);
8736 	    vec<tree, va_gc> *origtypes;
8737 	    vec_alloc (origtypes, nargs);
8738 	    auto_vec<location_t> arg_loc (nargs);
8739 	    for (unsigned int j = 0; j < nargs; j++)
8740 	      {
8741 		c_expr_t *ce = &(*cexpr_list)[num_functions + j];
8742 		args->quick_push (ce->value);
8743 		arg_loc.quick_push (ce->get_location ());
8744 		origtypes->quick_push (ce->original_type);
8745 	      }
8746 	    expr.value = c_build_function_call_vec (loc, arg_loc, fn->value,
8747 						    args, origtypes);
8748 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8749 	    break;
8750 	  }
8751 	case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
8752 	  {
8753 	    vec<c_expr_t, va_gc> *cexpr_list;
8754 	    c_expr_t *e2_p;
8755 	    tree chain_value;
8756 	    location_t close_paren_loc;
8757 
8758 	    c_parser_consume_token (parser);
8759 	    if (!c_parser_get_builtin_args (parser,
8760 					    "__builtin_call_with_static_chain",
8761 					    &cexpr_list, false,
8762 					    &close_paren_loc))
8763 	      {
8764 		expr.set_error ();
8765 		break;
8766 	      }
8767 	    if (vec_safe_length (cexpr_list) != 2)
8768 	      {
8769 		error_at (loc, "wrong number of arguments to "
8770 			       "%<__builtin_call_with_static_chain%>");
8771 		expr.set_error ();
8772 		break;
8773 	      }
8774 
8775 	    expr = (*cexpr_list)[0];
8776 	    e2_p = &(*cexpr_list)[1];
8777 	    *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
8778 	    chain_value = e2_p->value;
8779 	    mark_exp_read (chain_value);
8780 
8781 	    if (TREE_CODE (expr.value) != CALL_EXPR)
8782 	      error_at (loc, "first argument to "
8783 			"%<__builtin_call_with_static_chain%> "
8784 			"must be a call expression");
8785 	    else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
8786 	      error_at (loc, "second argument to "
8787 			"%<__builtin_call_with_static_chain%> "
8788 			"must be a pointer type");
8789 	    else
8790 	      CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
8791 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8792 	    break;
8793 	  }
8794 	case RID_BUILTIN_COMPLEX:
8795 	  {
8796 	    vec<c_expr_t, va_gc> *cexpr_list;
8797 	    c_expr_t *e1_p, *e2_p;
8798 	    location_t close_paren_loc;
8799 
8800 	    c_parser_consume_token (parser);
8801 	    if (!c_parser_get_builtin_args (parser,
8802 					    "__builtin_complex",
8803 					    &cexpr_list, false,
8804 					    &close_paren_loc))
8805 	      {
8806 		expr.set_error ();
8807 		break;
8808 	      }
8809 
8810 	    if (vec_safe_length (cexpr_list) != 2)
8811 	      {
8812 		error_at (loc, "wrong number of arguments to "
8813 			       "%<__builtin_complex%>");
8814 		expr.set_error ();
8815 		break;
8816 	      }
8817 
8818 	    e1_p = &(*cexpr_list)[0];
8819 	    e2_p = &(*cexpr_list)[1];
8820 
8821 	    *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
8822 	    if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
8823 	      e1_p->value = convert (TREE_TYPE (e1_p->value),
8824 				     TREE_OPERAND (e1_p->value, 0));
8825 	    *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
8826 	    if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
8827 	      e2_p->value = convert (TREE_TYPE (e2_p->value),
8828 				     TREE_OPERAND (e2_p->value, 0));
8829 	    if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
8830 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
8831 		|| !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
8832 		|| DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
8833 	      {
8834 		error_at (loc, "%<__builtin_complex%> operand "
8835 			  "not of real binary floating-point type");
8836 		expr.set_error ();
8837 		break;
8838 	      }
8839 	    if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
8840 		!= TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
8841 	      {
8842 		error_at (loc,
8843 			  "%<__builtin_complex%> operands of different types");
8844 		expr.set_error ();
8845 		break;
8846 	      }
8847 	    pedwarn_c90 (loc, OPT_Wpedantic,
8848 			 "ISO C90 does not support complex types");
8849 	    expr.value = build2_loc (loc, COMPLEX_EXPR,
8850 				     build_complex_type
8851 				     (TYPE_MAIN_VARIANT
8852 				      (TREE_TYPE (e1_p->value))),
8853 				     e1_p->value, e2_p->value);
8854 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8855 	    break;
8856 	  }
8857 	case RID_BUILTIN_SHUFFLE:
8858 	  {
8859 	    vec<c_expr_t, va_gc> *cexpr_list;
8860 	    unsigned int i;
8861 	    c_expr_t *p;
8862 	    location_t close_paren_loc;
8863 
8864 	    c_parser_consume_token (parser);
8865 	    if (!c_parser_get_builtin_args (parser,
8866 					    "__builtin_shuffle",
8867 					    &cexpr_list, false,
8868 					    &close_paren_loc))
8869 	      {
8870 		expr.set_error ();
8871 		break;
8872 	      }
8873 
8874 	    FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
8875 	      *p = convert_lvalue_to_rvalue (loc, *p, true, true);
8876 
8877 	    if (vec_safe_length (cexpr_list) == 2)
8878 	      expr.value =
8879 		c_build_vec_perm_expr
8880 		  (loc, (*cexpr_list)[0].value,
8881 		   NULL_TREE, (*cexpr_list)[1].value);
8882 
8883 	    else if (vec_safe_length (cexpr_list) == 3)
8884 	      expr.value =
8885 		c_build_vec_perm_expr
8886 		  (loc, (*cexpr_list)[0].value,
8887 		   (*cexpr_list)[1].value,
8888 		   (*cexpr_list)[2].value);
8889 	    else
8890 	      {
8891 		error_at (loc, "wrong number of arguments to "
8892 			       "%<__builtin_shuffle%>");
8893 		expr.set_error ();
8894 	      }
8895 	    set_c_expr_source_range (&expr, loc, close_paren_loc);
8896 	    break;
8897 	  }
8898 	case RID_AT_SELECTOR:
8899 	  {
8900 	    gcc_assert (c_dialect_objc ());
8901 	    c_parser_consume_token (parser);
8902 	    matching_parens parens;
8903 	    if (!parens.require_open (parser))
8904 	      {
8905 		expr.set_error ();
8906 		break;
8907 	      }
8908 	    tree sel = c_parser_objc_selector_arg (parser);
8909 	    location_t close_loc = c_parser_peek_token (parser)->location;
8910 	    parens.skip_until_found_close (parser);
8911 	    expr.value = objc_build_selector_expr (loc, sel);
8912 	    set_c_expr_source_range (&expr, loc, close_loc);
8913 	  }
8914 	  break;
8915 	case RID_AT_PROTOCOL:
8916 	  {
8917 	    gcc_assert (c_dialect_objc ());
8918 	    c_parser_consume_token (parser);
8919 	    matching_parens parens;
8920 	    if (!parens.require_open (parser))
8921 	      {
8922 		expr.set_error ();
8923 		break;
8924 	      }
8925 	    if (c_parser_next_token_is_not (parser, CPP_NAME))
8926 	      {
8927 		c_parser_error (parser, "expected identifier");
8928 		c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8929 		expr.set_error ();
8930 		break;
8931 	      }
8932 	    tree id = c_parser_peek_token (parser)->value;
8933 	    c_parser_consume_token (parser);
8934 	    location_t close_loc = c_parser_peek_token (parser)->location;
8935 	    parens.skip_until_found_close (parser);
8936 	    expr.value = objc_build_protocol_expr (id);
8937 	    set_c_expr_source_range (&expr, loc, close_loc);
8938 	  }
8939 	  break;
8940 	case RID_AT_ENCODE:
8941 	  {
8942 	    /* Extension to support C-structures in the archiver.  */
8943 	    gcc_assert (c_dialect_objc ());
8944 	    c_parser_consume_token (parser);
8945 	    matching_parens parens;
8946 	    if (!parens.require_open (parser))
8947 	      {
8948 		expr.set_error ();
8949 		break;
8950 	      }
8951 	    t1 = c_parser_type_name (parser);
8952 	    if (t1 == NULL)
8953 	      {
8954 		expr.set_error ();
8955 		c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8956 		break;
8957 	      }
8958 	    location_t close_loc = c_parser_peek_token (parser)->location;
8959 	    parens.skip_until_found_close (parser);
8960 	    tree type = groktypename (t1, NULL, NULL);
8961 	    expr.value = objc_build_encode_expr (type);
8962 	    set_c_expr_source_range (&expr, loc, close_loc);
8963 	  }
8964 	  break;
8965 	case RID_GENERIC:
8966 	  expr = c_parser_generic_selection (parser);
8967 	  break;
8968 	default:
8969 	  c_parser_error (parser, "expected expression");
8970 	  expr.set_error ();
8971 	  break;
8972 	}
8973       break;
8974     case CPP_OPEN_SQUARE:
8975       if (c_dialect_objc ())
8976 	{
8977 	  tree receiver, args;
8978 	  c_parser_consume_token (parser);
8979 	  receiver = c_parser_objc_receiver (parser);
8980 	  args = c_parser_objc_message_args (parser);
8981 	  location_t close_loc = c_parser_peek_token (parser)->location;
8982 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
8983 				     "expected %<]%>");
8984 	  expr.value = objc_build_message_expr (receiver, args);
8985 	  set_c_expr_source_range (&expr, loc, close_loc);
8986 	  break;
8987 	}
8988       /* Else fall through to report error.  */
8989       /* FALLTHRU */
8990     default:
8991       c_parser_error (parser, "expected expression");
8992       expr.set_error ();
8993       break;
8994     }
8995  out:
8996   return c_parser_postfix_expression_after_primary
8997     (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr);
8998 }
8999 
9000 /* Parse a postfix expression after a parenthesized type name: the
9001    brace-enclosed initializer of a compound literal, possibly followed
9002    by some postfix operators.  This is separate because it is not
9003    possible to tell until after the type name whether a cast
9004    expression has a cast or a compound literal, or whether the operand
9005    of sizeof is a parenthesized type name or starts with a compound
9006    literal.  TYPE_LOC is the location where TYPE_NAME starts--the
9007    location of the first token after the parentheses around the type
9008    name.  */
9009 
9010 static struct c_expr
9011 c_parser_postfix_expression_after_paren_type (c_parser *parser,
9012 					      struct c_type_name *type_name,
9013 					      location_t type_loc)
9014 {
9015   tree type;
9016   struct c_expr init;
9017   bool non_const;
9018   struct c_expr expr;
9019   location_t start_loc;
9020   tree type_expr = NULL_TREE;
9021   bool type_expr_const = true;
9022   check_compound_literal_type (type_loc, type_name);
9023   rich_location richloc (line_table, type_loc);
9024   start_init (NULL_TREE, NULL, 0, &richloc);
9025   type = groktypename (type_name, &type_expr, &type_expr_const);
9026   start_loc = c_parser_peek_token (parser)->location;
9027   if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
9028     {
9029       error_at (type_loc, "compound literal has variable size");
9030       type = error_mark_node;
9031     }
9032   init = c_parser_braced_init (parser, type, false, NULL);
9033   finish_init ();
9034   maybe_warn_string_init (type_loc, type, init);
9035 
9036   if (type != error_mark_node
9037       && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
9038       && current_function_decl)
9039     {
9040       error ("compound literal qualified by address-space qualifier");
9041       type = error_mark_node;
9042     }
9043 
9044   pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
9045   non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
9046 	       ? CONSTRUCTOR_NON_CONST (init.value)
9047 	       : init.original_code == C_MAYBE_CONST_EXPR);
9048   non_const |= !type_expr_const;
9049   unsigned int alignas_align = 0;
9050   if (type != error_mark_node
9051       && type_name->specs->align_log != -1)
9052     {
9053       alignas_align = 1U << type_name->specs->align_log;
9054       if (alignas_align < min_align_of_type (type))
9055 	{
9056 	  error_at (type_name->specs->locations[cdw_alignas],
9057 		    "%<_Alignas%> specifiers cannot reduce "
9058 		    "alignment of compound literal");
9059 	  alignas_align = 0;
9060 	}
9061     }
9062   expr.value = build_compound_literal (start_loc, type, init.value, non_const,
9063 				       alignas_align);
9064   set_c_expr_source_range (&expr, init.src_range);
9065   expr.original_code = ERROR_MARK;
9066   expr.original_type = NULL;
9067   if (type != error_mark_node
9068       && expr.value != error_mark_node
9069       && type_expr)
9070     {
9071       if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
9072 	{
9073 	  gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
9074 	  C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
9075 	}
9076       else
9077 	{
9078 	  gcc_assert (!non_const);
9079 	  expr.value = build2 (C_MAYBE_CONST_EXPR, type,
9080 			       type_expr, expr.value);
9081 	}
9082     }
9083   return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
9084 }
9085 
9086 /* Callback function for sizeof_pointer_memaccess_warning to compare
9087    types.  */
9088 
9089 static bool
9090 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
9091 {
9092   return comptypes (type1, type2) == 1;
9093 }
9094 
9095 /* Parse a postfix expression after the initial primary or compound
9096    literal; that is, parse a series of postfix operators.
9097 
9098    EXPR_LOC is the location of the primary expression.  */
9099 
9100 static struct c_expr
9101 c_parser_postfix_expression_after_primary (c_parser *parser,
9102 					   location_t expr_loc,
9103 					   struct c_expr expr)
9104 {
9105   struct c_expr orig_expr;
9106   tree ident, idx;
9107   location_t sizeof_arg_loc[3], comp_loc;
9108   tree sizeof_arg[3];
9109   unsigned int literal_zero_mask;
9110   unsigned int i;
9111   vec<tree, va_gc> *exprlist;
9112   vec<tree, va_gc> *origtypes = NULL;
9113   vec<location_t> arg_loc = vNULL;
9114   location_t start;
9115   location_t finish;
9116 
9117   while (true)
9118     {
9119       location_t op_loc = c_parser_peek_token (parser)->location;
9120       switch (c_parser_peek_token (parser)->type)
9121 	{
9122 	case CPP_OPEN_SQUARE:
9123 	  /* Array reference.  */
9124 	  c_parser_consume_token (parser);
9125 	  idx = c_parser_expression (parser).value;
9126 	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
9127 				     "expected %<]%>");
9128 	  start = expr.get_start ();
9129 	  finish = parser->tokens_buf[0].location;
9130 	  expr.value = build_array_ref (op_loc, expr.value, idx);
9131 	  set_c_expr_source_range (&expr, start, finish);
9132 	  expr.original_code = ERROR_MARK;
9133 	  expr.original_type = NULL;
9134 	  break;
9135 	case CPP_OPEN_PAREN:
9136 	  /* Function call.  */
9137 	  c_parser_consume_token (parser);
9138 	  for (i = 0; i < 3; i++)
9139 	    {
9140 	      sizeof_arg[i] = NULL_TREE;
9141 	      sizeof_arg_loc[i] = UNKNOWN_LOCATION;
9142 	    }
9143 	  literal_zero_mask = 0;
9144 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9145 	    exprlist = NULL;
9146 	  else
9147 	    exprlist = c_parser_expr_list (parser, true, false, &origtypes,
9148 					   sizeof_arg_loc, sizeof_arg,
9149 					   &arg_loc, &literal_zero_mask);
9150 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9151 				     "expected %<)%>");
9152 	  orig_expr = expr;
9153 	  mark_exp_read (expr.value);
9154 	  if (warn_sizeof_pointer_memaccess)
9155 	    sizeof_pointer_memaccess_warning (sizeof_arg_loc,
9156 					      expr.value, exprlist,
9157 					      sizeof_arg,
9158 					      sizeof_ptr_memacc_comptypes);
9159 	  if (TREE_CODE (expr.value) == FUNCTION_DECL
9160 	      && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
9161 	      && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
9162 	      && vec_safe_length (exprlist) == 3)
9163 	    {
9164 	      tree arg0 = (*exprlist)[0];
9165 	      tree arg2 = (*exprlist)[2];
9166 	      warn_for_memset (expr_loc, arg0, arg2, literal_zero_mask);
9167 	    }
9168 
9169 	  start = expr.get_start ();
9170 	  finish = parser->tokens_buf[0].get_finish ();
9171 	  expr.value
9172 	    = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
9173 					 exprlist, origtypes);
9174 	  set_c_expr_source_range (&expr, start, finish);
9175 
9176 	  expr.original_code = ERROR_MARK;
9177 	  if (TREE_CODE (expr.value) == INTEGER_CST
9178 	      && TREE_CODE (orig_expr.value) == FUNCTION_DECL
9179 	      && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
9180 	      && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
9181 	    expr.original_code = C_MAYBE_CONST_EXPR;
9182 	  expr.original_type = NULL;
9183 	  if (exprlist)
9184 	    {
9185 	      release_tree_vector (exprlist);
9186 	      release_tree_vector (origtypes);
9187 	    }
9188 	  arg_loc.release ();
9189 	  break;
9190 	case CPP_DOT:
9191 	  /* Structure element reference.  */
9192 	  c_parser_consume_token (parser);
9193 	  expr = default_function_array_conversion (expr_loc, expr);
9194 	  if (c_parser_next_token_is (parser, CPP_NAME))
9195 	    {
9196 	      c_token *comp_tok = c_parser_peek_token (parser);
9197 	      ident = comp_tok->value;
9198 	      comp_loc = comp_tok->location;
9199 	    }
9200 	  else
9201 	    {
9202 	      c_parser_error (parser, "expected identifier");
9203 	      expr.set_error ();
9204 	      expr.original_code = ERROR_MARK;
9205               expr.original_type = NULL;
9206 	      return expr;
9207 	    }
9208 	  start = expr.get_start ();
9209 	  finish = c_parser_peek_token (parser)->get_finish ();
9210 	  c_parser_consume_token (parser);
9211 	  expr.value = build_component_ref (op_loc, expr.value, ident,
9212 					    comp_loc);
9213 	  set_c_expr_source_range (&expr, start, finish);
9214 	  expr.original_code = ERROR_MARK;
9215 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
9216 	    expr.original_type = NULL;
9217 	  else
9218 	    {
9219 	      /* Remember the original type of a bitfield.  */
9220 	      tree field = TREE_OPERAND (expr.value, 1);
9221 	      if (TREE_CODE (field) != FIELD_DECL)
9222 		expr.original_type = NULL;
9223 	      else
9224 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
9225 	    }
9226 	  break;
9227 	case CPP_DEREF:
9228 	  /* Structure element reference.  */
9229 	  c_parser_consume_token (parser);
9230 	  expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
9231 	  if (c_parser_next_token_is (parser, CPP_NAME))
9232 	    {
9233 	      c_token *comp_tok = c_parser_peek_token (parser);
9234 	      ident = comp_tok->value;
9235 	      comp_loc = comp_tok->location;
9236 	    }
9237 	  else
9238 	    {
9239 	      c_parser_error (parser, "expected identifier");
9240 	      expr.set_error ();
9241 	      expr.original_code = ERROR_MARK;
9242 	      expr.original_type = NULL;
9243 	      return expr;
9244 	    }
9245 	  start = expr.get_start ();
9246 	  finish = c_parser_peek_token (parser)->get_finish ();
9247 	  c_parser_consume_token (parser);
9248 	  expr.value = build_component_ref (op_loc,
9249 					    build_indirect_ref (op_loc,
9250 								expr.value,
9251 								RO_ARROW),
9252 					    ident, comp_loc);
9253 	  set_c_expr_source_range (&expr, start, finish);
9254 	  expr.original_code = ERROR_MARK;
9255 	  if (TREE_CODE (expr.value) != COMPONENT_REF)
9256 	    expr.original_type = NULL;
9257 	  else
9258 	    {
9259 	      /* Remember the original type of a bitfield.  */
9260 	      tree field = TREE_OPERAND (expr.value, 1);
9261 	      if (TREE_CODE (field) != FIELD_DECL)
9262 		expr.original_type = NULL;
9263 	      else
9264 		expr.original_type = DECL_BIT_FIELD_TYPE (field);
9265 	    }
9266 	  break;
9267 	case CPP_PLUS_PLUS:
9268 	  /* Postincrement.  */
9269 	  start = expr.get_start ();
9270 	  finish = c_parser_peek_token (parser)->get_finish ();
9271 	  c_parser_consume_token (parser);
9272 	  expr = default_function_array_read_conversion (expr_loc, expr);
9273 	  expr.value = build_unary_op (op_loc, POSTINCREMENT_EXPR,
9274 				       expr.value, false);
9275 	  set_c_expr_source_range (&expr, start, finish);
9276 	  expr.original_code = ERROR_MARK;
9277 	  expr.original_type = NULL;
9278 	  break;
9279 	case CPP_MINUS_MINUS:
9280 	  /* Postdecrement.  */
9281 	  start = expr.get_start ();
9282 	  finish = c_parser_peek_token (parser)->get_finish ();
9283 	  c_parser_consume_token (parser);
9284 	  expr = default_function_array_read_conversion (expr_loc, expr);
9285 	  expr.value = build_unary_op (op_loc, POSTDECREMENT_EXPR,
9286 				       expr.value, false);
9287 	  set_c_expr_source_range (&expr, start, finish);
9288 	  expr.original_code = ERROR_MARK;
9289 	  expr.original_type = NULL;
9290 	  break;
9291 	default:
9292 	  return expr;
9293 	}
9294     }
9295 }
9296 
9297 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9298 
9299    expression:
9300      assignment-expression
9301      expression , assignment-expression
9302 */
9303 
9304 static struct c_expr
9305 c_parser_expression (c_parser *parser)
9306 {
9307   location_t tloc = c_parser_peek_token (parser)->location;
9308   struct c_expr expr;
9309   expr = c_parser_expr_no_commas (parser, NULL);
9310   if (c_parser_next_token_is (parser, CPP_COMMA))
9311     expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
9312   while (c_parser_next_token_is (parser, CPP_COMMA))
9313     {
9314       struct c_expr next;
9315       tree lhsval;
9316       location_t loc = c_parser_peek_token (parser)->location;
9317       location_t expr_loc;
9318       c_parser_consume_token (parser);
9319       expr_loc = c_parser_peek_token (parser)->location;
9320       lhsval = expr.value;
9321       while (TREE_CODE (lhsval) == COMPOUND_EXPR)
9322 	lhsval = TREE_OPERAND (lhsval, 1);
9323       if (DECL_P (lhsval) || handled_component_p (lhsval))
9324 	mark_exp_read (lhsval);
9325       next = c_parser_expr_no_commas (parser, NULL);
9326       next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
9327       expr.value = build_compound_expr (loc, expr.value, next.value);
9328       expr.original_code = COMPOUND_EXPR;
9329       expr.original_type = next.original_type;
9330     }
9331   return expr;
9332 }
9333 
9334 /* Parse an expression and convert functions or arrays to pointers and
9335    lvalues to rvalues.  */
9336 
9337 static struct c_expr
9338 c_parser_expression_conv (c_parser *parser)
9339 {
9340   struct c_expr expr;
9341   location_t loc = c_parser_peek_token (parser)->location;
9342   expr = c_parser_expression (parser);
9343   expr = convert_lvalue_to_rvalue (loc, expr, true, false);
9344   return expr;
9345 }
9346 
9347 /* Helper function of c_parser_expr_list.  Check if IDXth (0 based)
9348    argument is a literal zero alone and if so, set it in literal_zero_mask.  */
9349 
9350 static inline void
9351 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
9352 			     unsigned int idx)
9353 {
9354   if (idx >= HOST_BITS_PER_INT)
9355     return;
9356 
9357   c_token *tok = c_parser_peek_token (parser);
9358   switch (tok->type)
9359     {
9360     case CPP_NUMBER:
9361     case CPP_CHAR:
9362     case CPP_WCHAR:
9363     case CPP_CHAR16:
9364     case CPP_CHAR32:
9365       /* If a parameter is literal zero alone, remember it
9366 	 for -Wmemset-transposed-args warning.  */
9367       if (integer_zerop (tok->value)
9368 	  && !TREE_OVERFLOW (tok->value)
9369 	  && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
9370 	      || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
9371 	*literal_zero_mask |= 1U << idx;
9372     default:
9373       break;
9374     }
9375 }
9376 
9377 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
9378    functions and arrays to pointers and lvalues to rvalues.  If
9379    FOLD_P, fold the expressions.  If LOCATIONS is non-NULL, save the
9380    locations of function arguments into this vector.
9381 
9382    nonempty-expr-list:
9383      assignment-expression
9384      nonempty-expr-list , assignment-expression
9385 */
9386 
9387 static vec<tree, va_gc> *
9388 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
9389 		    vec<tree, va_gc> **p_orig_types,
9390 		    location_t *sizeof_arg_loc, tree *sizeof_arg,
9391 		    vec<location_t> *locations,
9392 		    unsigned int *literal_zero_mask)
9393 {
9394   vec<tree, va_gc> *ret;
9395   vec<tree, va_gc> *orig_types;
9396   struct c_expr expr;
9397   unsigned int idx = 0;
9398 
9399   ret = make_tree_vector ();
9400   if (p_orig_types == NULL)
9401     orig_types = NULL;
9402   else
9403     orig_types = make_tree_vector ();
9404 
9405   if (literal_zero_mask)
9406     c_parser_check_literal_zero (parser, literal_zero_mask, 0);
9407   expr = c_parser_expr_no_commas (parser, NULL);
9408   if (convert_p)
9409     expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true, true);
9410   if (fold_p)
9411     expr.value = c_fully_fold (expr.value, false, NULL);
9412   ret->quick_push (expr.value);
9413   if (orig_types)
9414     orig_types->quick_push (expr.original_type);
9415   if (locations)
9416     locations->safe_push (expr.get_location ());
9417   if (sizeof_arg != NULL
9418       && expr.original_code == SIZEOF_EXPR)
9419     {
9420       sizeof_arg[0] = c_last_sizeof_arg;
9421       sizeof_arg_loc[0] = c_last_sizeof_loc;
9422     }
9423   while (c_parser_next_token_is (parser, CPP_COMMA))
9424     {
9425       c_parser_consume_token (parser);
9426       if (literal_zero_mask)
9427 	c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
9428       expr = c_parser_expr_no_commas (parser, NULL);
9429       if (convert_p)
9430 	expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true,
9431 					 true);
9432       if (fold_p)
9433 	expr.value = c_fully_fold (expr.value, false, NULL);
9434       vec_safe_push (ret, expr.value);
9435       if (orig_types)
9436 	vec_safe_push (orig_types, expr.original_type);
9437       if (locations)
9438 	locations->safe_push (expr.get_location ());
9439       if (++idx < 3
9440 	  && sizeof_arg != NULL
9441 	  && expr.original_code == SIZEOF_EXPR)
9442 	{
9443 	  sizeof_arg[idx] = c_last_sizeof_arg;
9444 	  sizeof_arg_loc[idx] = c_last_sizeof_loc;
9445 	}
9446     }
9447   if (orig_types)
9448     *p_orig_types = orig_types;
9449   return ret;
9450 }
9451 
9452 /* Parse Objective-C-specific constructs.  */
9453 
9454 /* Parse an objc-class-definition.
9455 
9456    objc-class-definition:
9457      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9458        objc-class-instance-variables[opt] objc-methodprotolist @end
9459      @implementation identifier objc-superclass[opt]
9460        objc-class-instance-variables[opt]
9461      @interface identifier ( identifier ) objc-protocol-refs[opt]
9462        objc-methodprotolist @end
9463      @interface identifier ( ) objc-protocol-refs[opt]
9464        objc-methodprotolist @end
9465      @implementation identifier ( identifier )
9466 
9467    objc-superclass:
9468      : identifier
9469 
9470    "@interface identifier (" must start "@interface identifier (
9471    identifier ) ...": objc-methodprotolist in the first production may
9472    not start with a parenthesized identifier as a declarator of a data
9473    definition with no declaration specifiers if the objc-superclass,
9474    objc-protocol-refs and objc-class-instance-variables are omitted.  */
9475 
9476 static void
9477 c_parser_objc_class_definition (c_parser *parser, tree attributes)
9478 {
9479   bool iface_p;
9480   tree id1;
9481   tree superclass;
9482   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
9483     iface_p = true;
9484   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
9485     iface_p = false;
9486   else
9487     gcc_unreachable ();
9488 
9489   c_parser_consume_token (parser);
9490   if (c_parser_next_token_is_not (parser, CPP_NAME))
9491     {
9492       c_parser_error (parser, "expected identifier");
9493       return;
9494     }
9495   id1 = c_parser_peek_token (parser)->value;
9496   c_parser_consume_token (parser);
9497   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9498     {
9499       /* We have a category or class extension.  */
9500       tree id2;
9501       tree proto = NULL_TREE;
9502       matching_parens parens;
9503       parens.consume_open (parser);
9504       if (c_parser_next_token_is_not (parser, CPP_NAME))
9505 	{
9506 	  if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9507 	    {
9508 	      /* We have a class extension.  */
9509 	      id2 = NULL_TREE;
9510 	    }
9511 	  else
9512 	    {
9513 	      c_parser_error (parser, "expected identifier or %<)%>");
9514 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
9515 	      return;
9516 	    }
9517 	}
9518       else
9519 	{
9520 	  id2 = c_parser_peek_token (parser)->value;
9521 	  c_parser_consume_token (parser);
9522 	}
9523       parens.skip_until_found_close (parser);
9524       if (!iface_p)
9525 	{
9526 	  objc_start_category_implementation (id1, id2);
9527 	  return;
9528 	}
9529       if (c_parser_next_token_is (parser, CPP_LESS))
9530 	proto = c_parser_objc_protocol_refs (parser);
9531       objc_start_category_interface (id1, id2, proto, attributes);
9532       c_parser_objc_methodprotolist (parser);
9533       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
9534       objc_finish_interface ();
9535       return;
9536     }
9537   if (c_parser_next_token_is (parser, CPP_COLON))
9538     {
9539       c_parser_consume_token (parser);
9540       if (c_parser_next_token_is_not (parser, CPP_NAME))
9541 	{
9542 	  c_parser_error (parser, "expected identifier");
9543 	  return;
9544 	}
9545       superclass = c_parser_peek_token (parser)->value;
9546       c_parser_consume_token (parser);
9547     }
9548   else
9549     superclass = NULL_TREE;
9550   if (iface_p)
9551     {
9552       tree proto = NULL_TREE;
9553       if (c_parser_next_token_is (parser, CPP_LESS))
9554 	proto = c_parser_objc_protocol_refs (parser);
9555       objc_start_class_interface (id1, superclass, proto, attributes);
9556     }
9557   else
9558     objc_start_class_implementation (id1, superclass);
9559   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9560     c_parser_objc_class_instance_variables (parser);
9561   if (iface_p)
9562     {
9563       objc_continue_interface ();
9564       c_parser_objc_methodprotolist (parser);
9565       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
9566       objc_finish_interface ();
9567     }
9568   else
9569     {
9570       objc_continue_implementation ();
9571       return;
9572     }
9573 }
9574 
9575 /* Parse objc-class-instance-variables.
9576 
9577    objc-class-instance-variables:
9578      { objc-instance-variable-decl-list[opt] }
9579 
9580    objc-instance-variable-decl-list:
9581      objc-visibility-spec
9582      objc-instance-variable-decl ;
9583      ;
9584      objc-instance-variable-decl-list objc-visibility-spec
9585      objc-instance-variable-decl-list objc-instance-variable-decl ;
9586      objc-instance-variable-decl-list ;
9587 
9588    objc-visibility-spec:
9589      @private
9590      @protected
9591      @public
9592 
9593    objc-instance-variable-decl:
9594      struct-declaration
9595 */
9596 
9597 static void
9598 c_parser_objc_class_instance_variables (c_parser *parser)
9599 {
9600   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
9601   c_parser_consume_token (parser);
9602   while (c_parser_next_token_is_not (parser, CPP_EOF))
9603     {
9604       tree decls;
9605       /* Parse any stray semicolon.  */
9606       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9607 	{
9608 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9609 		   "extra semicolon");
9610 	  c_parser_consume_token (parser);
9611 	  continue;
9612 	}
9613       /* Stop if at the end of the instance variables.  */
9614       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9615 	{
9616 	  c_parser_consume_token (parser);
9617 	  break;
9618 	}
9619       /* Parse any objc-visibility-spec.  */
9620       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
9621 	{
9622 	  c_parser_consume_token (parser);
9623 	  objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
9624 	  continue;
9625 	}
9626       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
9627 	{
9628 	  c_parser_consume_token (parser);
9629 	  objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
9630 	  continue;
9631 	}
9632       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
9633 	{
9634 	  c_parser_consume_token (parser);
9635 	  objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
9636 	  continue;
9637 	}
9638       else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
9639 	{
9640 	  c_parser_consume_token (parser);
9641 	  objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
9642 	  continue;
9643 	}
9644       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
9645 	{
9646 	  c_parser_pragma (parser, pragma_external, NULL);
9647 	  continue;
9648 	}
9649 
9650       /* Parse some comma-separated declarations.  */
9651       decls = c_parser_struct_declaration (parser);
9652       if (decls == NULL)
9653 	{
9654 	  /* There is a syntax error.  We want to skip the offending
9655 	     tokens up to the next ';' (included) or '}'
9656 	     (excluded).  */
9657 
9658 	  /* First, skip manually a ')' or ']'.  This is because they
9659 	     reduce the nesting level, so c_parser_skip_until_found()
9660 	     wouldn't be able to skip past them.  */
9661 	  c_token *token = c_parser_peek_token (parser);
9662 	  if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
9663 	    c_parser_consume_token (parser);
9664 
9665 	  /* Then, do the standard skipping.  */
9666 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9667 
9668 	  /* We hopefully recovered.  Start normal parsing again.  */
9669 	  parser->error = false;
9670 	  continue;
9671 	}
9672       else
9673 	{
9674 	  /* Comma-separated instance variables are chained together
9675 	     in reverse order; add them one by one.  */
9676 	  tree ivar = nreverse (decls);
9677 	  for (; ivar; ivar = DECL_CHAIN (ivar))
9678 	    objc_add_instance_variable (copy_node (ivar));
9679 	}
9680       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9681     }
9682 }
9683 
9684 /* Parse an objc-class-declaration.
9685 
9686    objc-class-declaration:
9687      @class identifier-list ;
9688 */
9689 
9690 static void
9691 c_parser_objc_class_declaration (c_parser *parser)
9692 {
9693   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
9694   c_parser_consume_token (parser);
9695   /* Any identifiers, including those declared as type names, are OK
9696      here.  */
9697   while (true)
9698     {
9699       tree id;
9700       if (c_parser_next_token_is_not (parser, CPP_NAME))
9701 	{
9702 	  c_parser_error (parser, "expected identifier");
9703 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9704 	  parser->error = false;
9705 	  return;
9706 	}
9707       id = c_parser_peek_token (parser)->value;
9708       objc_declare_class (id);
9709       c_parser_consume_token (parser);
9710       if (c_parser_next_token_is (parser, CPP_COMMA))
9711 	c_parser_consume_token (parser);
9712       else
9713 	break;
9714     }
9715   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9716 }
9717 
9718 /* Parse an objc-alias-declaration.
9719 
9720    objc-alias-declaration:
9721      @compatibility_alias identifier identifier ;
9722 */
9723 
9724 static void
9725 c_parser_objc_alias_declaration (c_parser *parser)
9726 {
9727   tree id1, id2;
9728   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
9729   c_parser_consume_token (parser);
9730   if (c_parser_next_token_is_not (parser, CPP_NAME))
9731     {
9732       c_parser_error (parser, "expected identifier");
9733       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9734       return;
9735     }
9736   id1 = c_parser_peek_token (parser)->value;
9737   c_parser_consume_token (parser);
9738   if (c_parser_next_token_is_not (parser, CPP_NAME))
9739     {
9740       c_parser_error (parser, "expected identifier");
9741       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9742       return;
9743     }
9744   id2 = c_parser_peek_token (parser)->value;
9745   c_parser_consume_token (parser);
9746   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9747   objc_declare_alias (id1, id2);
9748 }
9749 
9750 /* Parse an objc-protocol-definition.
9751 
9752    objc-protocol-definition:
9753      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9754      @protocol identifier-list ;
9755 
9756    "@protocol identifier ;" should be resolved as "@protocol
9757    identifier-list ;": objc-methodprotolist may not start with a
9758    semicolon in the first alternative if objc-protocol-refs are
9759    omitted.  */
9760 
9761 static void
9762 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
9763 {
9764   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
9765 
9766   c_parser_consume_token (parser);
9767   if (c_parser_next_token_is_not (parser, CPP_NAME))
9768     {
9769       c_parser_error (parser, "expected identifier");
9770       return;
9771     }
9772   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
9773       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
9774     {
9775       /* Any identifiers, including those declared as type names, are
9776 	 OK here.  */
9777       while (true)
9778 	{
9779 	  tree id;
9780 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
9781 	    {
9782 	      c_parser_error (parser, "expected identifier");
9783 	      break;
9784 	    }
9785 	  id = c_parser_peek_token (parser)->value;
9786 	  objc_declare_protocol (id, attributes);
9787 	  c_parser_consume_token (parser);
9788 	  if (c_parser_next_token_is (parser, CPP_COMMA))
9789 	    c_parser_consume_token (parser);
9790 	  else
9791 	    break;
9792 	}
9793       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9794     }
9795   else
9796     {
9797       tree id = c_parser_peek_token (parser)->value;
9798       tree proto = NULL_TREE;
9799       c_parser_consume_token (parser);
9800       if (c_parser_next_token_is (parser, CPP_LESS))
9801 	proto = c_parser_objc_protocol_refs (parser);
9802       parser->objc_pq_context = true;
9803       objc_start_protocol (id, proto, attributes);
9804       c_parser_objc_methodprotolist (parser);
9805       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
9806       parser->objc_pq_context = false;
9807       objc_finish_interface ();
9808     }
9809 }
9810 
9811 /* Parse an objc-method-type.
9812 
9813    objc-method-type:
9814      +
9815      -
9816 
9817    Return true if it is a class method (+) and false if it is
9818    an instance method (-).
9819 */
9820 static inline bool
9821 c_parser_objc_method_type (c_parser *parser)
9822 {
9823   switch (c_parser_peek_token (parser)->type)
9824     {
9825     case CPP_PLUS:
9826       c_parser_consume_token (parser);
9827       return true;
9828     case CPP_MINUS:
9829       c_parser_consume_token (parser);
9830       return false;
9831     default:
9832       gcc_unreachable ();
9833     }
9834 }
9835 
9836 /* Parse an objc-method-definition.
9837 
9838    objc-method-definition:
9839      objc-method-type objc-method-decl ;[opt] compound-statement
9840 */
9841 
9842 static void
9843 c_parser_objc_method_definition (c_parser *parser)
9844 {
9845   bool is_class_method = c_parser_objc_method_type (parser);
9846   tree decl, attributes = NULL_TREE, expr = NULL_TREE;
9847   parser->objc_pq_context = true;
9848   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
9849 				    &expr);
9850   if (decl == error_mark_node)
9851     return;  /* Bail here. */
9852 
9853   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9854     {
9855       c_parser_consume_token (parser);
9856       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9857 	       "extra semicolon in method definition specified");
9858     }
9859 
9860   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9861     {
9862       c_parser_error (parser, "expected %<{%>");
9863       return;
9864     }
9865 
9866   parser->objc_pq_context = false;
9867   if (objc_start_method_definition (is_class_method, decl, attributes, expr))
9868     {
9869       add_stmt (c_parser_compound_statement (parser));
9870       objc_finish_method_definition (current_function_decl);
9871     }
9872   else
9873     {
9874       /* This code is executed when we find a method definition
9875 	 outside of an @implementation context (or invalid for other
9876 	 reasons).  Parse the method (to keep going) but do not emit
9877 	 any code.
9878       */
9879       c_parser_compound_statement (parser);
9880     }
9881 }
9882 
9883 /* Parse an objc-methodprotolist.
9884 
9885    objc-methodprotolist:
9886      empty
9887      objc-methodprotolist objc-methodproto
9888      objc-methodprotolist declaration
9889      objc-methodprotolist ;
9890      @optional
9891      @required
9892 
9893    The declaration is a data definition, which may be missing
9894    declaration specifiers under the same rules and diagnostics as
9895    other data definitions outside functions, and the stray semicolon
9896    is diagnosed the same way as a stray semicolon outside a
9897    function.  */
9898 
9899 static void
9900 c_parser_objc_methodprotolist (c_parser *parser)
9901 {
9902   while (true)
9903     {
9904       /* The list is terminated by @end.  */
9905       switch (c_parser_peek_token (parser)->type)
9906 	{
9907 	case CPP_SEMICOLON:
9908 	  pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9909 		   "ISO C does not allow extra %<;%> outside of a function");
9910 	  c_parser_consume_token (parser);
9911 	  break;
9912 	case CPP_PLUS:
9913 	case CPP_MINUS:
9914 	  c_parser_objc_methodproto (parser);
9915 	  break;
9916 	case CPP_PRAGMA:
9917 	  c_parser_pragma (parser, pragma_external, NULL);
9918 	  break;
9919 	case CPP_EOF:
9920 	  return;
9921 	default:
9922 	  if (c_parser_next_token_is_keyword (parser, RID_AT_END))
9923 	    return;
9924 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
9925 	    c_parser_objc_at_property_declaration (parser);
9926 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
9927 	    {
9928 	      objc_set_method_opt (true);
9929 	      c_parser_consume_token (parser);
9930 	    }
9931 	  else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
9932 	    {
9933 	      objc_set_method_opt (false);
9934 	      c_parser_consume_token (parser);
9935 	    }
9936 	  else
9937 	    c_parser_declaration_or_fndef (parser, false, false, true,
9938 					   false, true, NULL, vNULL);
9939 	  break;
9940 	}
9941     }
9942 }
9943 
9944 /* Parse an objc-methodproto.
9945 
9946    objc-methodproto:
9947      objc-method-type objc-method-decl ;
9948 */
9949 
9950 static void
9951 c_parser_objc_methodproto (c_parser *parser)
9952 {
9953   bool is_class_method = c_parser_objc_method_type (parser);
9954   tree decl, attributes = NULL_TREE;
9955 
9956   /* Remember protocol qualifiers in prototypes.  */
9957   parser->objc_pq_context = true;
9958   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
9959 				    NULL);
9960   /* Forget protocol qualifiers now.  */
9961   parser->objc_pq_context = false;
9962 
9963   /* Do not allow the presence of attributes to hide an erroneous
9964      method implementation in the interface section.  */
9965   if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
9966     {
9967       c_parser_error (parser, "expected %<;%>");
9968       return;
9969     }
9970 
9971   if (decl != error_mark_node)
9972     objc_add_method_declaration (is_class_method, decl, attributes);
9973 
9974   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9975 }
9976 
9977 /* If we are at a position that method attributes may be present, check that
9978    there are not any parsed already (a syntax error) and then collect any
9979    specified at the current location.  Finally, if new attributes were present,
9980    check that the next token is legal ( ';' for decls and '{' for defs).  */
9981 
9982 static bool
9983 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
9984 {
9985   bool bad = false;
9986   if (*attributes)
9987     {
9988       c_parser_error (parser,
9989 		    "method attributes must be specified at the end only");
9990       *attributes = NULL_TREE;
9991       bad = true;
9992     }
9993 
9994   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
9995     *attributes = c_parser_attributes (parser);
9996 
9997   /* If there were no attributes here, just report any earlier error.  */
9998   if (*attributes == NULL_TREE || bad)
9999     return bad;
10000 
10001   /* If the attributes are followed by a ; or {, then just report any earlier
10002      error.  */
10003   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
10004       || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
10005     return bad;
10006 
10007   /* We've got attributes, but not at the end.  */
10008   c_parser_error (parser,
10009 		  "expected %<;%> or %<{%> after method attribute definition");
10010   return true;
10011 }
10012 
10013 /* Parse an objc-method-decl.
10014 
10015    objc-method-decl:
10016      ( objc-type-name ) objc-selector
10017      objc-selector
10018      ( objc-type-name ) objc-keyword-selector objc-optparmlist
10019      objc-keyword-selector objc-optparmlist
10020      attributes
10021 
10022    objc-keyword-selector:
10023      objc-keyword-decl
10024      objc-keyword-selector objc-keyword-decl
10025 
10026    objc-keyword-decl:
10027      objc-selector : ( objc-type-name ) identifier
10028      objc-selector : identifier
10029      : ( objc-type-name ) identifier
10030      : identifier
10031 
10032    objc-optparmlist:
10033      objc-optparms objc-optellipsis
10034 
10035    objc-optparms:
10036      empty
10037      objc-opt-parms , parameter-declaration
10038 
10039    objc-optellipsis:
10040      empty
10041      , ...
10042 */
10043 
10044 static tree
10045 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
10046 			   tree *attributes, tree *expr)
10047 {
10048   tree type = NULL_TREE;
10049   tree sel;
10050   tree parms = NULL_TREE;
10051   bool ellipsis = false;
10052   bool attr_err = false;
10053 
10054   *attributes = NULL_TREE;
10055   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10056     {
10057       matching_parens parens;
10058       parens.consume_open (parser);
10059       type = c_parser_objc_type_name (parser);
10060       parens.skip_until_found_close (parser);
10061     }
10062   sel = c_parser_objc_selector (parser);
10063   /* If there is no selector, or a colon follows, we have an
10064      objc-keyword-selector.  If there is a selector, and a colon does
10065      not follow, that selector ends the objc-method-decl.  */
10066   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
10067     {
10068       tree tsel = sel;
10069       tree list = NULL_TREE;
10070       while (true)
10071 	{
10072 	  tree atype = NULL_TREE, id, keyworddecl;
10073 	  tree param_attr = NULL_TREE;
10074 	  if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10075 	    break;
10076 	  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10077 	    {
10078 	      c_parser_consume_token (parser);
10079 	      atype = c_parser_objc_type_name (parser);
10080 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
10081 					 "expected %<)%>");
10082 	    }
10083 	  /* New ObjC allows attributes on method parameters.  */
10084 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
10085 	    param_attr = c_parser_attributes (parser);
10086 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
10087 	    {
10088 	      c_parser_error (parser, "expected identifier");
10089 	      return error_mark_node;
10090 	    }
10091 	  id = c_parser_peek_token (parser)->value;
10092 	  c_parser_consume_token (parser);
10093 	  keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
10094 	  list = chainon (list, keyworddecl);
10095 	  tsel = c_parser_objc_selector (parser);
10096 	  if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
10097 	    break;
10098 	}
10099 
10100       attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
10101 
10102       /* Parse the optional parameter list.  Optional Objective-C
10103 	 method parameters follow the C syntax, and may include '...'
10104 	 to denote a variable number of arguments.  */
10105       parms = make_node (TREE_LIST);
10106       while (c_parser_next_token_is (parser, CPP_COMMA))
10107 	{
10108 	  struct c_parm *parm;
10109 	  c_parser_consume_token (parser);
10110 	  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
10111 	    {
10112 	      ellipsis = true;
10113 	      c_parser_consume_token (parser);
10114 	      attr_err |= c_parser_objc_maybe_method_attributes
10115 						(parser, attributes) ;
10116 	      break;
10117 	    }
10118 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
10119 	  if (parm == NULL)
10120 	    break;
10121 	  parms = chainon (parms,
10122 			   build_tree_list (NULL_TREE, grokparm (parm, expr)));
10123 	}
10124       sel = list;
10125     }
10126   else
10127     attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
10128 
10129   if (sel == NULL)
10130     {
10131       c_parser_error (parser, "objective-c method declaration is expected");
10132       return error_mark_node;
10133     }
10134 
10135   if (attr_err)
10136     return error_mark_node;
10137 
10138   return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
10139 }
10140 
10141 /* Parse an objc-type-name.
10142 
10143    objc-type-name:
10144      objc-type-qualifiers[opt] type-name
10145      objc-type-qualifiers[opt]
10146 
10147    objc-type-qualifiers:
10148      objc-type-qualifier
10149      objc-type-qualifiers objc-type-qualifier
10150 
10151    objc-type-qualifier: one of
10152      in out inout bycopy byref oneway
10153 */
10154 
10155 static tree
10156 c_parser_objc_type_name (c_parser *parser)
10157 {
10158   tree quals = NULL_TREE;
10159   struct c_type_name *type_name = NULL;
10160   tree type = NULL_TREE;
10161   while (true)
10162     {
10163       c_token *token = c_parser_peek_token (parser);
10164       if (token->type == CPP_KEYWORD
10165 	  && (token->keyword == RID_IN
10166 	      || token->keyword == RID_OUT
10167 	      || token->keyword == RID_INOUT
10168 	      || token->keyword == RID_BYCOPY
10169 	      || token->keyword == RID_BYREF
10170 	      || token->keyword == RID_ONEWAY))
10171 	{
10172 	  quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
10173 	  c_parser_consume_token (parser);
10174 	}
10175       else
10176 	break;
10177     }
10178   if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
10179     type_name = c_parser_type_name (parser);
10180   if (type_name)
10181     type = groktypename (type_name, NULL, NULL);
10182 
10183   /* If the type is unknown, and error has already been produced and
10184      we need to recover from the error.  In that case, use NULL_TREE
10185      for the type, as if no type had been specified; this will use the
10186      default type ('id') which is good for error recovery.  */
10187   if (type == error_mark_node)
10188     type = NULL_TREE;
10189 
10190   return build_tree_list (quals, type);
10191 }
10192 
10193 /* Parse objc-protocol-refs.
10194 
10195    objc-protocol-refs:
10196      < identifier-list >
10197 */
10198 
10199 static tree
10200 c_parser_objc_protocol_refs (c_parser *parser)
10201 {
10202   tree list = NULL_TREE;
10203   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
10204   c_parser_consume_token (parser);
10205   /* Any identifiers, including those declared as type names, are OK
10206      here.  */
10207   while (true)
10208     {
10209       tree id;
10210       if (c_parser_next_token_is_not (parser, CPP_NAME))
10211 	{
10212 	  c_parser_error (parser, "expected identifier");
10213 	  break;
10214 	}
10215       id = c_parser_peek_token (parser)->value;
10216       list = chainon (list, build_tree_list (NULL_TREE, id));
10217       c_parser_consume_token (parser);
10218       if (c_parser_next_token_is (parser, CPP_COMMA))
10219 	c_parser_consume_token (parser);
10220       else
10221 	break;
10222     }
10223   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
10224   return list;
10225 }
10226 
10227 /* Parse an objc-try-catch-finally-statement.
10228 
10229    objc-try-catch-finally-statement:
10230      @try compound-statement objc-catch-list[opt]
10231      @try compound-statement objc-catch-list[opt] @finally compound-statement
10232 
10233    objc-catch-list:
10234      @catch ( objc-catch-parameter-declaration ) compound-statement
10235      objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10236 
10237    objc-catch-parameter-declaration:
10238      parameter-declaration
10239      '...'
10240 
10241    where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10242 
10243    PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10244    for C++.  Keep them in sync.  */
10245 
10246 static void
10247 c_parser_objc_try_catch_finally_statement (c_parser *parser)
10248 {
10249   location_t location;
10250   tree stmt;
10251 
10252   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
10253   c_parser_consume_token (parser);
10254   location = c_parser_peek_token (parser)->location;
10255   objc_maybe_warn_exceptions (location);
10256   stmt = c_parser_compound_statement (parser);
10257   objc_begin_try_stmt (location, stmt);
10258 
10259   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
10260     {
10261       struct c_parm *parm;
10262       tree parameter_declaration = error_mark_node;
10263       bool seen_open_paren = false;
10264 
10265       c_parser_consume_token (parser);
10266       matching_parens parens;
10267       if (!parens.require_open (parser))
10268 	seen_open_paren = true;
10269       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
10270 	{
10271 	  /* We have "@catch (...)" (where the '...' are literally
10272 	     what is in the code).  Skip the '...'.
10273 	     parameter_declaration is set to NULL_TREE, and
10274 	     objc_being_catch_clauses() knows that that means
10275 	     '...'.  */
10276 	  c_parser_consume_token (parser);
10277 	  parameter_declaration = NULL_TREE;
10278 	}
10279       else
10280 	{
10281 	  /* We have "@catch (NSException *exception)" or something
10282 	     like that.  Parse the parameter declaration.  */
10283 	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
10284 	  if (parm == NULL)
10285 	    parameter_declaration = error_mark_node;
10286 	  else
10287 	    parameter_declaration = grokparm (parm, NULL);
10288 	}
10289       if (seen_open_paren)
10290 	parens.require_close (parser);
10291       else
10292 	{
10293 	  /* If there was no open parenthesis, we are recovering from
10294 	     an error, and we are trying to figure out what mistake
10295 	     the user has made.  */
10296 
10297 	  /* If there is an immediate closing parenthesis, the user
10298 	     probably forgot the opening one (ie, they typed "@catch
10299 	     NSException *e)".  Parse the closing parenthesis and keep
10300 	     going.  */
10301 	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
10302 	    c_parser_consume_token (parser);
10303 
10304 	  /* If these is no immediate closing parenthesis, the user
10305 	     probably doesn't know that parenthesis are required at
10306 	     all (ie, they typed "@catch NSException *e").  So, just
10307 	     forget about the closing parenthesis and keep going.  */
10308 	}
10309       objc_begin_catch_clause (parameter_declaration);
10310       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
10311 	c_parser_compound_statement_nostart (parser);
10312       objc_finish_catch_clause ();
10313     }
10314   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
10315     {
10316       c_parser_consume_token (parser);
10317       location = c_parser_peek_token (parser)->location;
10318       stmt = c_parser_compound_statement (parser);
10319       objc_build_finally_clause (location, stmt);
10320     }
10321   objc_finish_try_stmt ();
10322 }
10323 
10324 /* Parse an objc-synchronized-statement.
10325 
10326    objc-synchronized-statement:
10327      @synchronized ( expression ) compound-statement
10328 */
10329 
10330 static void
10331 c_parser_objc_synchronized_statement (c_parser *parser)
10332 {
10333   location_t loc;
10334   tree expr, stmt;
10335   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
10336   c_parser_consume_token (parser);
10337   loc = c_parser_peek_token (parser)->location;
10338   objc_maybe_warn_exceptions (loc);
10339   matching_parens parens;
10340   if (parens.require_open (parser))
10341     {
10342       struct c_expr ce = c_parser_expression (parser);
10343       ce = convert_lvalue_to_rvalue (loc, ce, false, false);
10344       expr = ce.value;
10345       expr = c_fully_fold (expr, false, NULL);
10346       parens.skip_until_found_close (parser);
10347     }
10348   else
10349     expr = error_mark_node;
10350   stmt = c_parser_compound_statement (parser);
10351   objc_build_synchronized (loc, expr, stmt);
10352 }
10353 
10354 /* Parse an objc-selector; return NULL_TREE without an error if the
10355    next token is not an objc-selector.
10356 
10357    objc-selector:
10358      identifier
10359      one of
10360        enum struct union if else while do for switch case default
10361        break continue return goto asm sizeof typeof __alignof
10362        unsigned long const short volatile signed restrict _Complex
10363        in out inout bycopy byref oneway int char float double void _Bool
10364        _Atomic
10365 
10366    ??? Why this selection of keywords but not, for example, storage
10367    class specifiers?  */
10368 
10369 static tree
10370 c_parser_objc_selector (c_parser *parser)
10371 {
10372   c_token *token = c_parser_peek_token (parser);
10373   tree value = token->value;
10374   if (token->type == CPP_NAME)
10375     {
10376       c_parser_consume_token (parser);
10377       return value;
10378     }
10379   if (token->type != CPP_KEYWORD)
10380     return NULL_TREE;
10381   switch (token->keyword)
10382     {
10383     case RID_ENUM:
10384     case RID_STRUCT:
10385     case RID_UNION:
10386     case RID_IF:
10387     case RID_ELSE:
10388     case RID_WHILE:
10389     case RID_DO:
10390     case RID_FOR:
10391     case RID_SWITCH:
10392     case RID_CASE:
10393     case RID_DEFAULT:
10394     case RID_BREAK:
10395     case RID_CONTINUE:
10396     case RID_RETURN:
10397     case RID_GOTO:
10398     case RID_ASM:
10399     case RID_SIZEOF:
10400     case RID_TYPEOF:
10401     case RID_ALIGNOF:
10402     case RID_UNSIGNED:
10403     case RID_LONG:
10404     case RID_CONST:
10405     case RID_SHORT:
10406     case RID_VOLATILE:
10407     case RID_SIGNED:
10408     case RID_RESTRICT:
10409     case RID_COMPLEX:
10410     case RID_IN:
10411     case RID_OUT:
10412     case RID_INOUT:
10413     case RID_BYCOPY:
10414     case RID_BYREF:
10415     case RID_ONEWAY:
10416     case RID_INT:
10417     case RID_CHAR:
10418     case RID_FLOAT:
10419     case RID_DOUBLE:
10420     CASE_RID_FLOATN_NX:
10421     case RID_VOID:
10422     case RID_BOOL:
10423     case RID_ATOMIC:
10424     case RID_AUTO_TYPE:
10425     case RID_INT_N_0:
10426     case RID_INT_N_1:
10427     case RID_INT_N_2:
10428     case RID_INT_N_3:
10429       c_parser_consume_token (parser);
10430       return value;
10431     default:
10432       return NULL_TREE;
10433     }
10434 }
10435 
10436 /* Parse an objc-selector-arg.
10437 
10438    objc-selector-arg:
10439      objc-selector
10440      objc-keywordname-list
10441 
10442    objc-keywordname-list:
10443      objc-keywordname
10444      objc-keywordname-list objc-keywordname
10445 
10446    objc-keywordname:
10447      objc-selector :
10448      :
10449 */
10450 
10451 static tree
10452 c_parser_objc_selector_arg (c_parser *parser)
10453 {
10454   tree sel = c_parser_objc_selector (parser);
10455   tree list = NULL_TREE;
10456   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
10457     return sel;
10458   while (true)
10459     {
10460       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10461 	return list;
10462       list = chainon (list, build_tree_list (sel, NULL_TREE));
10463       sel = c_parser_objc_selector (parser);
10464       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
10465 	break;
10466     }
10467   return list;
10468 }
10469 
10470 /* Parse an objc-receiver.
10471 
10472    objc-receiver:
10473      expression
10474      class-name
10475      type-name
10476 */
10477 
10478 static tree
10479 c_parser_objc_receiver (c_parser *parser)
10480 {
10481   location_t loc = c_parser_peek_token (parser)->location;
10482 
10483   if (c_parser_peek_token (parser)->type == CPP_NAME
10484       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
10485 	  || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
10486     {
10487       tree id = c_parser_peek_token (parser)->value;
10488       c_parser_consume_token (parser);
10489       return objc_get_class_reference (id);
10490     }
10491   struct c_expr ce = c_parser_expression (parser);
10492   ce = convert_lvalue_to_rvalue (loc, ce, false, false);
10493   return c_fully_fold (ce.value, false, NULL);
10494 }
10495 
10496 /* Parse objc-message-args.
10497 
10498    objc-message-args:
10499      objc-selector
10500      objc-keywordarg-list
10501 
10502    objc-keywordarg-list:
10503      objc-keywordarg
10504      objc-keywordarg-list objc-keywordarg
10505 
10506    objc-keywordarg:
10507      objc-selector : objc-keywordexpr
10508      : objc-keywordexpr
10509 */
10510 
10511 static tree
10512 c_parser_objc_message_args (c_parser *parser)
10513 {
10514   tree sel = c_parser_objc_selector (parser);
10515   tree list = NULL_TREE;
10516   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
10517     return sel;
10518   while (true)
10519     {
10520       tree keywordexpr;
10521       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10522 	return error_mark_node;
10523       keywordexpr = c_parser_objc_keywordexpr (parser);
10524       list = chainon (list, build_tree_list (sel, keywordexpr));
10525       sel = c_parser_objc_selector (parser);
10526       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
10527 	break;
10528     }
10529   return list;
10530 }
10531 
10532 /* Parse an objc-keywordexpr.
10533 
10534    objc-keywordexpr:
10535      nonempty-expr-list
10536 */
10537 
10538 static tree
10539 c_parser_objc_keywordexpr (c_parser *parser)
10540 {
10541   tree ret;
10542   vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
10543 						NULL, NULL, NULL, NULL);
10544   if (vec_safe_length (expr_list) == 1)
10545     {
10546       /* Just return the expression, remove a level of
10547 	 indirection.  */
10548       ret = (*expr_list)[0];
10549     }
10550   else
10551     {
10552       /* We have a comma expression, we will collapse later.  */
10553       ret = build_tree_list_vec (expr_list);
10554     }
10555   release_tree_vector (expr_list);
10556   return ret;
10557 }
10558 
10559 /* A check, needed in several places, that ObjC interface, implementation or
10560    method definitions are not prefixed by incorrect items.  */
10561 static bool
10562 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
10563 					   struct c_declspecs *specs)
10564 {
10565   if (!specs->declspecs_seen_p || specs->non_sc_seen_p
10566       || specs->typespec_kind != ctsk_none)
10567     {
10568       c_parser_error (parser,
10569       		      "no type or storage class may be specified here,");
10570       c_parser_skip_to_end_of_block_or_statement (parser);
10571       return true;
10572     }
10573   return false;
10574 }
10575 
10576 /* Parse an Objective-C @property declaration.  The syntax is:
10577 
10578    objc-property-declaration:
10579      '@property' objc-property-attributes[opt] struct-declaration ;
10580 
10581    objc-property-attributes:
10582     '(' objc-property-attribute-list ')'
10583 
10584    objc-property-attribute-list:
10585      objc-property-attribute
10586      objc-property-attribute-list, objc-property-attribute
10587 
10588    objc-property-attribute
10589      'getter' = identifier
10590      'setter' = identifier
10591      'readonly'
10592      'readwrite'
10593      'assign'
10594      'retain'
10595      'copy'
10596      'nonatomic'
10597 
10598   For example:
10599     @property NSString *name;
10600     @property (readonly) id object;
10601     @property (retain, nonatomic, getter=getTheName) id name;
10602     @property int a, b, c;
10603 
10604   PS: This function is identical to cp_parser_objc_at_propery_declaration
10605   for C++.  Keep them in sync.  */
10606 static void
10607 c_parser_objc_at_property_declaration (c_parser *parser)
10608 {
10609   /* The following variables hold the attributes of the properties as
10610      parsed.  They are 'false' or 'NULL_TREE' if the attribute was not
10611      seen.  When we see an attribute, we set them to 'true' (if they
10612      are boolean properties) or to the identifier (if they have an
10613      argument, ie, for getter and setter).  Note that here we only
10614      parse the list of attributes, check the syntax and accumulate the
10615      attributes that we find.  objc_add_property_declaration() will
10616      then process the information.  */
10617   bool property_assign = false;
10618   bool property_copy = false;
10619   tree property_getter_ident = NULL_TREE;
10620   bool property_nonatomic = false;
10621   bool property_readonly = false;
10622   bool property_readwrite = false;
10623   bool property_retain = false;
10624   tree property_setter_ident = NULL_TREE;
10625 
10626   /* 'properties' is the list of properties that we read.  Usually a
10627      single one, but maybe more (eg, in "@property int a, b, c;" there
10628      are three).  */
10629   tree properties;
10630   location_t loc;
10631 
10632   loc = c_parser_peek_token (parser)->location;
10633   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
10634 
10635   c_parser_consume_token (parser);  /* Eat '@property'.  */
10636 
10637   /* Parse the optional attribute list...  */
10638   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10639     {
10640       matching_parens parens;
10641 
10642       /* Eat the '(' */
10643       parens.consume_open (parser);
10644 
10645       /* Property attribute keywords are valid now.  */
10646       parser->objc_property_attr_context = true;
10647 
10648       while (true)
10649 	{
10650 	  bool syntax_error = false;
10651 	  c_token *token = c_parser_peek_token (parser);
10652 	  enum rid keyword;
10653 
10654 	  if (token->type != CPP_KEYWORD)
10655 	    {
10656 	      if (token->type == CPP_CLOSE_PAREN)
10657 		c_parser_error (parser, "expected identifier");
10658 	      else
10659 		{
10660 		  c_parser_consume_token (parser);
10661 		  c_parser_error (parser, "unknown property attribute");
10662 		}
10663 	      break;
10664 	    }
10665 	  keyword = token->keyword;
10666 	  c_parser_consume_token (parser);
10667 	  switch (keyword)
10668 	    {
10669 	    case RID_ASSIGN:    property_assign = true;    break;
10670 	    case RID_COPY:      property_copy = true;      break;
10671 	    case RID_NONATOMIC: property_nonatomic = true; break;
10672 	    case RID_READONLY:  property_readonly = true;  break;
10673 	    case RID_READWRITE: property_readwrite = true; break;
10674 	    case RID_RETAIN:    property_retain = true;    break;
10675 
10676 	    case RID_GETTER:
10677 	    case RID_SETTER:
10678 	      if (c_parser_next_token_is_not (parser, CPP_EQ))
10679 		{
10680 		  if (keyword == RID_GETTER)
10681 		    c_parser_error (parser,
10682 				    "missing %<=%> (after %<getter%> attribute)");
10683 		  else
10684 		    c_parser_error (parser,
10685 				    "missing %<=%> (after %<setter%> attribute)");
10686 		  syntax_error = true;
10687 		  break;
10688 		}
10689 	      c_parser_consume_token (parser); /* eat the = */
10690 	      if (c_parser_next_token_is_not (parser, CPP_NAME))
10691 		{
10692 		  c_parser_error (parser, "expected identifier");
10693 		  syntax_error = true;
10694 		  break;
10695 		}
10696 	      if (keyword == RID_SETTER)
10697 		{
10698 		  if (property_setter_ident != NULL_TREE)
10699 		    c_parser_error (parser, "the %<setter%> attribute may only be specified once");
10700 		  else
10701 		    property_setter_ident = c_parser_peek_token (parser)->value;
10702 		  c_parser_consume_token (parser);
10703 		  if (c_parser_next_token_is_not (parser, CPP_COLON))
10704 		    c_parser_error (parser, "setter name must terminate with %<:%>");
10705 		  else
10706 		    c_parser_consume_token (parser);
10707 		}
10708 	      else
10709 		{
10710 		  if (property_getter_ident != NULL_TREE)
10711 		    c_parser_error (parser, "the %<getter%> attribute may only be specified once");
10712 		  else
10713 		    property_getter_ident = c_parser_peek_token (parser)->value;
10714 		  c_parser_consume_token (parser);
10715 		}
10716 	      break;
10717 	    default:
10718 	      c_parser_error (parser, "unknown property attribute");
10719 	      syntax_error = true;
10720 	      break;
10721 	    }
10722 
10723 	  if (syntax_error)
10724 	    break;
10725 
10726 	  if (c_parser_next_token_is (parser, CPP_COMMA))
10727 	    c_parser_consume_token (parser);
10728 	  else
10729 	    break;
10730 	}
10731       parser->objc_property_attr_context = false;
10732       parens.skip_until_found_close (parser);
10733     }
10734   /* ... and the property declaration(s).  */
10735   properties = c_parser_struct_declaration (parser);
10736 
10737   if (properties == error_mark_node)
10738     {
10739       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10740       parser->error = false;
10741       return;
10742     }
10743 
10744   if (properties == NULL_TREE)
10745     c_parser_error (parser, "expected identifier");
10746   else
10747     {
10748       /* Comma-separated properties are chained together in
10749 	 reverse order; add them one by one.  */
10750       properties = nreverse (properties);
10751 
10752       for (; properties; properties = TREE_CHAIN (properties))
10753 	objc_add_property_declaration (loc, copy_node (properties),
10754 				       property_readonly, property_readwrite,
10755 				       property_assign, property_retain,
10756 				       property_copy, property_nonatomic,
10757 				       property_getter_ident, property_setter_ident);
10758     }
10759 
10760   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10761   parser->error = false;
10762 }
10763 
10764 /* Parse an Objective-C @synthesize declaration.  The syntax is:
10765 
10766    objc-synthesize-declaration:
10767      @synthesize objc-synthesize-identifier-list ;
10768 
10769    objc-synthesize-identifier-list:
10770      objc-synthesize-identifier
10771      objc-synthesize-identifier-list, objc-synthesize-identifier
10772 
10773    objc-synthesize-identifier
10774      identifier
10775      identifier = identifier
10776 
10777   For example:
10778     @synthesize MyProperty;
10779     @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10780 
10781   PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10782   for C++.  Keep them in sync.
10783 */
10784 static void
10785 c_parser_objc_at_synthesize_declaration (c_parser *parser)
10786 {
10787   tree list = NULL_TREE;
10788   location_t loc;
10789   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
10790   loc = c_parser_peek_token (parser)->location;
10791 
10792   c_parser_consume_token (parser);
10793   while (true)
10794     {
10795       tree property, ivar;
10796       if (c_parser_next_token_is_not (parser, CPP_NAME))
10797 	{
10798 	  c_parser_error (parser, "expected identifier");
10799 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10800 	  /* Once we find the semicolon, we can resume normal parsing.
10801 	     We have to reset parser->error manually because
10802 	     c_parser_skip_until_found() won't reset it for us if the
10803 	     next token is precisely a semicolon.  */
10804 	  parser->error = false;
10805 	  return;
10806 	}
10807       property = c_parser_peek_token (parser)->value;
10808       c_parser_consume_token (parser);
10809       if (c_parser_next_token_is (parser, CPP_EQ))
10810 	{
10811 	  c_parser_consume_token (parser);
10812 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
10813 	    {
10814 	      c_parser_error (parser, "expected identifier");
10815 	      c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10816 	      parser->error = false;
10817 	      return;
10818 	    }
10819 	  ivar = c_parser_peek_token (parser)->value;
10820 	  c_parser_consume_token (parser);
10821 	}
10822       else
10823 	ivar = NULL_TREE;
10824       list = chainon (list, build_tree_list (ivar, property));
10825       if (c_parser_next_token_is (parser, CPP_COMMA))
10826 	c_parser_consume_token (parser);
10827       else
10828 	break;
10829     }
10830   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10831   objc_add_synthesize_declaration (loc, list);
10832 }
10833 
10834 /* Parse an Objective-C @dynamic declaration.  The syntax is:
10835 
10836    objc-dynamic-declaration:
10837      @dynamic identifier-list ;
10838 
10839    For example:
10840      @dynamic MyProperty;
10841      @dynamic MyProperty, AnotherProperty;
10842 
10843   PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10844   for C++.  Keep them in sync.
10845 */
10846 static void
10847 c_parser_objc_at_dynamic_declaration (c_parser *parser)
10848 {
10849   tree list = NULL_TREE;
10850   location_t loc;
10851   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
10852   loc = c_parser_peek_token (parser)->location;
10853 
10854   c_parser_consume_token (parser);
10855   while (true)
10856     {
10857       tree property;
10858       if (c_parser_next_token_is_not (parser, CPP_NAME))
10859 	{
10860 	  c_parser_error (parser, "expected identifier");
10861 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10862 	  parser->error = false;
10863 	  return;
10864 	}
10865       property = c_parser_peek_token (parser)->value;
10866       list = chainon (list, build_tree_list (NULL_TREE, property));
10867       c_parser_consume_token (parser);
10868       if (c_parser_next_token_is (parser, CPP_COMMA))
10869 	c_parser_consume_token (parser);
10870       else
10871 	break;
10872     }
10873   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10874   objc_add_dynamic_declaration (loc, list);
10875 }
10876 
10877 
10878 /* Parse a pragma GCC ivdep.  */
10879 
10880 static bool
10881 c_parse_pragma_ivdep (c_parser *parser)
10882 {
10883   c_parser_consume_pragma (parser);
10884   c_parser_skip_to_pragma_eol (parser);
10885   return true;
10886 }
10887 
10888 /* Parse a pragma GCC unroll.  */
10889 
10890 static unsigned short
10891 c_parser_pragma_unroll (c_parser *parser)
10892 {
10893   unsigned short unroll;
10894   c_parser_consume_pragma (parser);
10895   location_t location = c_parser_peek_token (parser)->location;
10896   tree expr = c_parser_expr_no_commas (parser, NULL).value;
10897   mark_exp_read (expr);
10898   expr = c_fully_fold (expr, false, NULL);
10899   HOST_WIDE_INT lunroll = 0;
10900   if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
10901       || TREE_CODE (expr) != INTEGER_CST
10902       || (lunroll = tree_to_shwi (expr)) < 0
10903       || lunroll >= USHRT_MAX)
10904     {
10905       error_at (location, "%<#pragma GCC unroll%> requires an"
10906 		" assignment-expression that evaluates to a non-negative"
10907 		" integral constant less than %u", USHRT_MAX);
10908       unroll = 0;
10909     }
10910   else
10911     {
10912       unroll = (unsigned short)lunroll;
10913       if (unroll == 0)
10914 	unroll = 1;
10915     }
10916 
10917   c_parser_skip_to_pragma_eol (parser);
10918   return unroll;
10919 }
10920 
10921 /* Handle pragmas.  Some OpenMP pragmas are associated with, and therefore
10922    should be considered, statements.  ALLOW_STMT is true if we're within
10923    the context of a function and such pragmas are to be allowed.  Returns
10924    true if we actually parsed such a pragma.  */
10925 
10926 static bool
10927 c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p)
10928 {
10929   unsigned int id;
10930   const char *construct = NULL;
10931 
10932   id = c_parser_peek_token (parser)->pragma_kind;
10933   gcc_assert (id != PRAGMA_NONE);
10934 
10935   switch (id)
10936     {
10937     case PRAGMA_OACC_DECLARE:
10938       c_parser_oacc_declare (parser);
10939       return false;
10940 
10941     case PRAGMA_OACC_ENTER_DATA:
10942       if (context != pragma_compound)
10943 	{
10944 	  construct = "acc enter data";
10945 	in_compound:
10946 	  if (context == pragma_stmt)
10947 	    {
10948 	      error_at (c_parser_peek_token (parser)->location,
10949 			"%<#pragma %s%> may only be used in compound "
10950 			"statements", construct);
10951 	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10952 	      return false;
10953 	    }
10954 	  goto bad_stmt;
10955 	}
10956       c_parser_oacc_enter_exit_data (parser, true);
10957       return false;
10958 
10959     case PRAGMA_OACC_EXIT_DATA:
10960       if (context != pragma_compound)
10961 	{
10962 	  construct = "acc exit data";
10963 	  goto in_compound;
10964 	}
10965       c_parser_oacc_enter_exit_data (parser, false);
10966       return false;
10967 
10968     case PRAGMA_OACC_ROUTINE:
10969       if (context != pragma_external)
10970 	{
10971 	  error_at (c_parser_peek_token (parser)->location,
10972 		    "%<#pragma acc routine%> must be at file scope");
10973 	  c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10974 	  return false;
10975 	}
10976       c_parser_oacc_routine (parser, context);
10977       return false;
10978 
10979     case PRAGMA_OACC_UPDATE:
10980       if (context != pragma_compound)
10981 	{
10982 	  construct = "acc update";
10983 	  goto in_compound;
10984 	}
10985       c_parser_oacc_update (parser);
10986       return false;
10987 
10988     case PRAGMA_OMP_BARRIER:
10989       if (context != pragma_compound)
10990 	{
10991 	  construct = "omp barrier";
10992 	  goto in_compound;
10993 	}
10994       c_parser_omp_barrier (parser);
10995       return false;
10996 
10997     case PRAGMA_OMP_FLUSH:
10998       if (context != pragma_compound)
10999 	{
11000 	  construct = "omp flush";
11001 	  goto in_compound;
11002 	}
11003       c_parser_omp_flush (parser);
11004       return false;
11005 
11006     case PRAGMA_OMP_TASKWAIT:
11007       if (context != pragma_compound)
11008 	{
11009 	  construct = "omp taskwait";
11010 	  goto in_compound;
11011 	}
11012       c_parser_omp_taskwait (parser);
11013       return false;
11014 
11015     case PRAGMA_OMP_TASKYIELD:
11016       if (context != pragma_compound)
11017 	{
11018 	  construct = "omp taskyield";
11019 	  goto in_compound;
11020 	}
11021       c_parser_omp_taskyield (parser);
11022       return false;
11023 
11024     case PRAGMA_OMP_CANCEL:
11025       if (context != pragma_compound)
11026 	{
11027 	  construct = "omp cancel";
11028 	  goto in_compound;
11029 	}
11030       c_parser_omp_cancel (parser);
11031       return false;
11032 
11033     case PRAGMA_OMP_CANCELLATION_POINT:
11034       c_parser_omp_cancellation_point (parser, context);
11035       return false;
11036 
11037     case PRAGMA_OMP_THREADPRIVATE:
11038       c_parser_omp_threadprivate (parser);
11039       return false;
11040 
11041     case PRAGMA_OMP_TARGET:
11042       return c_parser_omp_target (parser, context, if_p);
11043 
11044     case PRAGMA_OMP_END_DECLARE_TARGET:
11045       c_parser_omp_end_declare_target (parser);
11046       return false;
11047 
11048     case PRAGMA_OMP_SECTION:
11049       error_at (c_parser_peek_token (parser)->location,
11050 		"%<#pragma omp section%> may only be used in "
11051 		"%<#pragma omp sections%> construct");
11052       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
11053       return false;
11054 
11055     case PRAGMA_OMP_DECLARE:
11056       c_parser_omp_declare (parser, context);
11057       return false;
11058 
11059     case PRAGMA_OMP_ORDERED:
11060       return c_parser_omp_ordered (parser, context, if_p);
11061 
11062     case PRAGMA_IVDEP:
11063       {
11064 	const bool ivdep = c_parse_pragma_ivdep (parser);
11065 	unsigned short unroll;
11066 	if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_UNROLL)
11067 	  unroll = c_parser_pragma_unroll (parser);
11068 	else
11069 	  unroll = 0;
11070 	if (!c_parser_next_token_is_keyword (parser, RID_FOR)
11071 	    && !c_parser_next_token_is_keyword (parser, RID_WHILE)
11072 	    && !c_parser_next_token_is_keyword (parser, RID_DO))
11073 	  {
11074 	    c_parser_error (parser, "for, while or do statement expected");
11075 	    return false;
11076 	  }
11077 	if (c_parser_next_token_is_keyword (parser, RID_FOR))
11078 	  c_parser_for_statement (parser, ivdep, unroll, if_p);
11079 	else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
11080 	  c_parser_while_statement (parser, ivdep, unroll, if_p);
11081 	else
11082 	  c_parser_do_statement (parser, ivdep, unroll);
11083       }
11084       return false;
11085 
11086     case PRAGMA_UNROLL:
11087       {
11088 	unsigned short unroll = c_parser_pragma_unroll (parser);
11089 	bool ivdep;
11090 	if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_IVDEP)
11091 	  ivdep = c_parse_pragma_ivdep (parser);
11092 	else
11093 	  ivdep = false;
11094 	if (!c_parser_next_token_is_keyword (parser, RID_FOR)
11095 	    && !c_parser_next_token_is_keyword (parser, RID_WHILE)
11096 	    && !c_parser_next_token_is_keyword (parser, RID_DO))
11097 	  {
11098 	    c_parser_error (parser, "for, while or do statement expected");
11099 	    return false;
11100 	  }
11101 	if (c_parser_next_token_is_keyword (parser, RID_FOR))
11102 	  c_parser_for_statement (parser, ivdep, unroll, if_p);
11103 	else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
11104 	  c_parser_while_statement (parser, ivdep, unroll, if_p);
11105 	else
11106 	  c_parser_do_statement (parser, ivdep, unroll);
11107       }
11108       return false;
11109 
11110     case PRAGMA_GCC_PCH_PREPROCESS:
11111       c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
11112       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
11113       return false;
11114 
11115     case PRAGMA_OACC_WAIT:
11116       if (context != pragma_compound)
11117 	{
11118 	  construct = "acc wait";
11119 	  goto in_compound;
11120 	}
11121 	/* FALL THROUGH.  */
11122 
11123     default:
11124       if (id < PRAGMA_FIRST_EXTERNAL)
11125 	{
11126 	  if (context != pragma_stmt && context != pragma_compound)
11127 	    {
11128 	    bad_stmt:
11129 	      c_parser_error (parser, "expected declaration specifiers");
11130 	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
11131 	      return false;
11132 	    }
11133 	  c_parser_omp_construct (parser, if_p);
11134 	  return true;
11135 	}
11136       break;
11137     }
11138 
11139   c_parser_consume_pragma (parser);
11140   c_invoke_pragma_handler (id);
11141 
11142   /* Skip to EOL, but suppress any error message.  Those will have been
11143      generated by the handler routine through calling error, as opposed
11144      to calling c_parser_error.  */
11145   parser->error = true;
11146   c_parser_skip_to_pragma_eol (parser);
11147 
11148   return false;
11149 }
11150 
11151 /* The interface the pragma parsers have to the lexer.  */
11152 
11153 enum cpp_ttype
11154 pragma_lex (tree *value, location_t *loc)
11155 {
11156   c_token *tok = c_parser_peek_token (the_parser);
11157   enum cpp_ttype ret = tok->type;
11158 
11159   *value = tok->value;
11160   if (loc)
11161     *loc = tok->location;
11162 
11163   if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
11164     ret = CPP_EOF;
11165   else
11166     {
11167       if (ret == CPP_KEYWORD)
11168 	ret = CPP_NAME;
11169       c_parser_consume_token (the_parser);
11170     }
11171 
11172   return ret;
11173 }
11174 
11175 static void
11176 c_parser_pragma_pch_preprocess (c_parser *parser)
11177 {
11178   tree name = NULL;
11179 
11180   c_parser_consume_pragma (parser);
11181   if (c_parser_next_token_is (parser, CPP_STRING))
11182     {
11183       name = c_parser_peek_token (parser)->value;
11184       c_parser_consume_token (parser);
11185     }
11186   else
11187     c_parser_error (parser, "expected string literal");
11188   c_parser_skip_to_pragma_eol (parser);
11189 
11190   if (name)
11191     c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
11192 }
11193 
11194 /* OpenACC and OpenMP parsing routines.  */
11195 
11196 /* Returns name of the next clause.
11197    If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11198    the token is not consumed.  Otherwise appropriate pragma_omp_clause is
11199    returned and the token is consumed.  */
11200 
11201 static pragma_omp_clause
11202 c_parser_omp_clause_name (c_parser *parser)
11203 {
11204   pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
11205 
11206   if (c_parser_next_token_is_keyword (parser, RID_AUTO))
11207     result = PRAGMA_OACC_CLAUSE_AUTO;
11208   else if (c_parser_next_token_is_keyword (parser, RID_IF))
11209     result = PRAGMA_OMP_CLAUSE_IF;
11210   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
11211     result = PRAGMA_OMP_CLAUSE_DEFAULT;
11212   else if (c_parser_next_token_is_keyword (parser, RID_FOR))
11213     result = PRAGMA_OMP_CLAUSE_FOR;
11214   else if (c_parser_next_token_is (parser, CPP_NAME))
11215     {
11216       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11217 
11218       switch (p[0])
11219 	{
11220 	case 'a':
11221 	  if (!strcmp ("aligned", p))
11222 	    result = PRAGMA_OMP_CLAUSE_ALIGNED;
11223 	  else if (!strcmp ("async", p))
11224 	    result = PRAGMA_OACC_CLAUSE_ASYNC;
11225 	  break;
11226 	case 'c':
11227 	  if (!strcmp ("collapse", p))
11228 	    result = PRAGMA_OMP_CLAUSE_COLLAPSE;
11229 	  else if (!strcmp ("copy", p))
11230 	    result = PRAGMA_OACC_CLAUSE_COPY;
11231 	  else if (!strcmp ("copyin", p))
11232 	    result = PRAGMA_OMP_CLAUSE_COPYIN;
11233 	  else if (!strcmp ("copyout", p))
11234 	    result = PRAGMA_OACC_CLAUSE_COPYOUT;
11235           else if (!strcmp ("copyprivate", p))
11236 	    result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
11237 	  else if (!strcmp ("create", p))
11238 	    result = PRAGMA_OACC_CLAUSE_CREATE;
11239 	  break;
11240 	case 'd':
11241 	  if (!strcmp ("defaultmap", p))
11242 	    result = PRAGMA_OMP_CLAUSE_DEFAULTMAP;
11243 	  else if (!strcmp ("delete", p))
11244 	    result = PRAGMA_OACC_CLAUSE_DELETE;
11245 	  else if (!strcmp ("depend", p))
11246 	    result = PRAGMA_OMP_CLAUSE_DEPEND;
11247 	  else if (!strcmp ("device", p))
11248 	    result = PRAGMA_OMP_CLAUSE_DEVICE;
11249 	  else if (!strcmp ("deviceptr", p))
11250 	    result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
11251 	  else if (!strcmp ("device_resident", p))
11252 	    result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT;
11253 	  else if (!strcmp ("dist_schedule", p))
11254 	    result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
11255 	  break;
11256 	case 'f':
11257 	  if (!strcmp ("final", p))
11258 	    result = PRAGMA_OMP_CLAUSE_FINAL;
11259 	  else if (!strcmp ("firstprivate", p))
11260 	    result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
11261 	  else if (!strcmp ("from", p))
11262 	    result = PRAGMA_OMP_CLAUSE_FROM;
11263 	  break;
11264 	case 'g':
11265 	  if (!strcmp ("gang", p))
11266 	    result = PRAGMA_OACC_CLAUSE_GANG;
11267 	  else if (!strcmp ("grainsize", p))
11268 	    result = PRAGMA_OMP_CLAUSE_GRAINSIZE;
11269 	  break;
11270 	case 'h':
11271 	  if (!strcmp ("hint", p))
11272 	    result = PRAGMA_OMP_CLAUSE_HINT;
11273 	  else if (!strcmp ("host", p))
11274 	    result = PRAGMA_OACC_CLAUSE_HOST;
11275 	  break;
11276 	case 'i':
11277 	  if (!strcmp ("inbranch", p))
11278 	    result = PRAGMA_OMP_CLAUSE_INBRANCH;
11279 	  else if (!strcmp ("independent", p))
11280 	    result = PRAGMA_OACC_CLAUSE_INDEPENDENT;
11281 	  else if (!strcmp ("is_device_ptr", p))
11282 	    result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR;
11283 	  break;
11284 	case 'l':
11285 	  if (!strcmp ("lastprivate", p))
11286 	    result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
11287 	  else if (!strcmp ("linear", p))
11288 	    result = PRAGMA_OMP_CLAUSE_LINEAR;
11289 	  else if (!strcmp ("link", p))
11290 	    result = PRAGMA_OMP_CLAUSE_LINK;
11291 	  break;
11292 	case 'm':
11293 	  if (!strcmp ("map", p))
11294 	    result = PRAGMA_OMP_CLAUSE_MAP;
11295 	  else if (!strcmp ("mergeable", p))
11296 	    result = PRAGMA_OMP_CLAUSE_MERGEABLE;
11297 	  break;
11298 	case 'n':
11299 	  if (!strcmp ("nogroup", p))
11300 	    result = PRAGMA_OMP_CLAUSE_NOGROUP;
11301 	  else if (!strcmp ("notinbranch", p))
11302 	    result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
11303 	  else if (!strcmp ("nowait", p))
11304 	    result = PRAGMA_OMP_CLAUSE_NOWAIT;
11305 	  else if (!strcmp ("num_gangs", p))
11306 	    result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
11307 	  else if (!strcmp ("num_tasks", p))
11308 	    result = PRAGMA_OMP_CLAUSE_NUM_TASKS;
11309 	  else if (!strcmp ("num_teams", p))
11310 	    result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
11311 	  else if (!strcmp ("num_threads", p))
11312 	    result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
11313 	  else if (!strcmp ("num_workers", p))
11314 	    result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
11315 	  break;
11316 	case 'o':
11317 	  if (!strcmp ("ordered", p))
11318 	    result = PRAGMA_OMP_CLAUSE_ORDERED;
11319 	  break;
11320 	case 'p':
11321 	  if (!strcmp ("parallel", p))
11322 	    result = PRAGMA_OMP_CLAUSE_PARALLEL;
11323 	  else if (!strcmp ("present", p))
11324 	    result = PRAGMA_OACC_CLAUSE_PRESENT;
11325 	  else if (!strcmp ("present_or_copy", p)
11326 		   || !strcmp ("pcopy", p))
11327 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
11328 	  else if (!strcmp ("present_or_copyin", p)
11329 		   || !strcmp ("pcopyin", p))
11330 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
11331 	  else if (!strcmp ("present_or_copyout", p)
11332 		   || !strcmp ("pcopyout", p))
11333 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
11334 	  else if (!strcmp ("present_or_create", p)
11335 		   || !strcmp ("pcreate", p))
11336 	    result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
11337 	  else if (!strcmp ("priority", p))
11338 	    result = PRAGMA_OMP_CLAUSE_PRIORITY;
11339 	  else if (!strcmp ("private", p))
11340 	    result = PRAGMA_OMP_CLAUSE_PRIVATE;
11341 	  else if (!strcmp ("proc_bind", p))
11342 	    result = PRAGMA_OMP_CLAUSE_PROC_BIND;
11343 	  break;
11344 	case 'r':
11345 	  if (!strcmp ("reduction", p))
11346 	    result = PRAGMA_OMP_CLAUSE_REDUCTION;
11347 	  break;
11348 	case 's':
11349 	  if (!strcmp ("safelen", p))
11350 	    result = PRAGMA_OMP_CLAUSE_SAFELEN;
11351 	  else if (!strcmp ("schedule", p))
11352 	    result = PRAGMA_OMP_CLAUSE_SCHEDULE;
11353 	  else if (!strcmp ("sections", p))
11354 	    result = PRAGMA_OMP_CLAUSE_SECTIONS;
11355 	  else if (!strcmp ("seq", p))
11356 	    result = PRAGMA_OACC_CLAUSE_SEQ;
11357 	  else if (!strcmp ("shared", p))
11358 	    result = PRAGMA_OMP_CLAUSE_SHARED;
11359 	  else if (!strcmp ("simd", p))
11360 	    result = PRAGMA_OMP_CLAUSE_SIMD;
11361 	  else if (!strcmp ("simdlen", p))
11362 	    result = PRAGMA_OMP_CLAUSE_SIMDLEN;
11363 	  else if (!strcmp ("self", p))
11364 	    result = PRAGMA_OACC_CLAUSE_SELF;
11365 	  break;
11366 	case 't':
11367 	  if (!strcmp ("taskgroup", p))
11368 	    result = PRAGMA_OMP_CLAUSE_TASKGROUP;
11369 	  else if (!strcmp ("thread_limit", p))
11370 	    result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
11371 	  else if (!strcmp ("threads", p))
11372 	    result = PRAGMA_OMP_CLAUSE_THREADS;
11373 	  else if (!strcmp ("tile", p))
11374 	    result = PRAGMA_OACC_CLAUSE_TILE;
11375 	  else if (!strcmp ("to", p))
11376 	    result = PRAGMA_OMP_CLAUSE_TO;
11377 	  break;
11378 	case 'u':
11379 	  if (!strcmp ("uniform", p))
11380 	    result = PRAGMA_OMP_CLAUSE_UNIFORM;
11381 	  else if (!strcmp ("untied", p))
11382 	    result = PRAGMA_OMP_CLAUSE_UNTIED;
11383 	  else if (!strcmp ("use_device", p))
11384 	    result = PRAGMA_OACC_CLAUSE_USE_DEVICE;
11385 	  else if (!strcmp ("use_device_ptr", p))
11386 	    result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR;
11387 	  break;
11388 	case 'v':
11389 	  if (!strcmp ("vector", p))
11390 	    result = PRAGMA_OACC_CLAUSE_VECTOR;
11391 	  else if (!strcmp ("vector_length", p))
11392 	    result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
11393 	  break;
11394 	case 'w':
11395 	  if (!strcmp ("wait", p))
11396 	    result = PRAGMA_OACC_CLAUSE_WAIT;
11397 	  else if (!strcmp ("worker", p))
11398 	    result = PRAGMA_OACC_CLAUSE_WORKER;
11399 	  break;
11400 	}
11401     }
11402 
11403   if (result != PRAGMA_OMP_CLAUSE_NONE)
11404     c_parser_consume_token (parser);
11405 
11406   return result;
11407 }
11408 
11409 /* Validate that a clause of the given type does not already exist.  */
11410 
11411 static void
11412 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
11413 			   const char *name)
11414 {
11415   tree c;
11416 
11417   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11418     if (OMP_CLAUSE_CODE (c) == code)
11419       {
11420 	location_t loc = OMP_CLAUSE_LOCATION (c);
11421 	error_at (loc, "too many %qs clauses", name);
11422 	break;
11423       }
11424 }
11425 
11426 /* OpenACC 2.0
11427    Parse wait clause or wait directive parameters.  */
11428 
11429 static tree
11430 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
11431 {
11432   vec<tree, va_gc> *args;
11433   tree t, args_tree;
11434 
11435   matching_parens parens;
11436   if (!parens.require_open (parser))
11437     return list;
11438 
11439   args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
11440 
11441   if (args->length () == 0)
11442     {
11443       c_parser_error (parser, "expected integer expression before ')'");
11444       release_tree_vector (args);
11445       return list;
11446     }
11447 
11448   args_tree = build_tree_list_vec (args);
11449 
11450   for (t = args_tree; t; t = TREE_CHAIN (t))
11451     {
11452       tree targ = TREE_VALUE (t);
11453 
11454       if (targ != error_mark_node)
11455 	{
11456 	  if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
11457 	    {
11458 	      c_parser_error (parser, "expression must be integral");
11459 	      targ = error_mark_node;
11460 	    }
11461 	  else
11462 	    {
11463 	      tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
11464 
11465 	      OMP_CLAUSE_DECL (c) = targ;
11466 	      OMP_CLAUSE_CHAIN (c) = list;
11467 	      list = c;
11468 	    }
11469 	}
11470     }
11471 
11472   release_tree_vector (args);
11473   parens.require_close (parser);
11474   return list;
11475 }
11476 
11477 /* OpenACC 2.0, OpenMP 2.5:
11478    variable-list:
11479      identifier
11480      variable-list , identifier
11481 
11482    If KIND is nonzero, create the appropriate node and install the
11483    decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11484    If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11485 
11486    If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11487    return the list created.  */
11488 
11489 static tree
11490 c_parser_omp_variable_list (c_parser *parser,
11491 			    location_t clause_loc,
11492 			    enum omp_clause_code kind, tree list)
11493 {
11494   if (c_parser_next_token_is_not (parser, CPP_NAME)
11495       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
11496     c_parser_error (parser, "expected identifier");
11497 
11498   while (c_parser_next_token_is (parser, CPP_NAME)
11499 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
11500     {
11501       tree t = lookup_name (c_parser_peek_token (parser)->value);
11502 
11503       if (t == NULL_TREE)
11504 	{
11505 	  undeclared_variable (c_parser_peek_token (parser)->location,
11506 			       c_parser_peek_token (parser)->value);
11507 	  t = error_mark_node;
11508 	}
11509 
11510       c_parser_consume_token (parser);
11511 
11512       if (t == error_mark_node)
11513 	;
11514       else if (kind != 0)
11515 	{
11516 	  switch (kind)
11517 	    {
11518 	    case OMP_CLAUSE__CACHE_:
11519 	      /* The OpenACC cache directive explicitly only allows "array
11520 		 elements or subarrays".  */
11521 	      if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
11522 		{
11523 		  c_parser_error (parser, "expected %<[%>");
11524 		  t = error_mark_node;
11525 		  break;
11526 		}
11527 	      /* FALLTHROUGH  */
11528 	    case OMP_CLAUSE_MAP:
11529 	    case OMP_CLAUSE_FROM:
11530 	    case OMP_CLAUSE_TO:
11531 	      while (c_parser_next_token_is (parser, CPP_DOT))
11532 		{
11533 		  location_t op_loc = c_parser_peek_token (parser)->location;
11534 		  c_parser_consume_token (parser);
11535 		  if (!c_parser_next_token_is (parser, CPP_NAME))
11536 		    {
11537 		      c_parser_error (parser, "expected identifier");
11538 		      t = error_mark_node;
11539 		      break;
11540 		    }
11541 
11542 		  c_token *comp_tok = c_parser_peek_token (parser);
11543 		  tree ident = comp_tok->value;
11544 		  location_t comp_loc = comp_tok->location;
11545 		  c_parser_consume_token (parser);
11546 		  t = build_component_ref (op_loc, t, ident, comp_loc);
11547 		}
11548 	      /* FALLTHROUGH  */
11549 	    case OMP_CLAUSE_DEPEND:
11550 	    case OMP_CLAUSE_REDUCTION:
11551 	      while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
11552 		{
11553 		  tree low_bound = NULL_TREE, length = NULL_TREE;
11554 
11555 		  c_parser_consume_token (parser);
11556 		  if (!c_parser_next_token_is (parser, CPP_COLON))
11557 		    {
11558 		      location_t expr_loc
11559 			= c_parser_peek_token (parser)->location;
11560 		      c_expr expr = c_parser_expression (parser);
11561 		      expr = convert_lvalue_to_rvalue (expr_loc, expr,
11562 						       false, true);
11563 		      low_bound = expr.value;
11564 		    }
11565 		  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
11566 		    length = integer_one_node;
11567 		  else
11568 		    {
11569 		      /* Look for `:'.  */
11570 		      if (!c_parser_require (parser, CPP_COLON,
11571 					     "expected %<:%>"))
11572 			{
11573 			  t = error_mark_node;
11574 			  break;
11575 			}
11576 		      if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
11577 			{
11578 			  location_t expr_loc
11579 			    = c_parser_peek_token (parser)->location;
11580 			  c_expr expr = c_parser_expression (parser);
11581 			  expr = convert_lvalue_to_rvalue (expr_loc, expr,
11582 							   false, true);
11583 			  length = expr.value;
11584 			}
11585 		    }
11586 		  /* Look for the closing `]'.  */
11587 		  if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
11588 					 "expected %<]%>"))
11589 		    {
11590 		      t = error_mark_node;
11591 		      break;
11592 		    }
11593 
11594 		  t = tree_cons (low_bound, length, t);
11595 		}
11596 	      break;
11597 	    default:
11598 	      break;
11599 	    }
11600 
11601 	  if (t != error_mark_node)
11602 	    {
11603 	      tree u = build_omp_clause (clause_loc, kind);
11604 	      OMP_CLAUSE_DECL (u) = t;
11605 	      OMP_CLAUSE_CHAIN (u) = list;
11606 	      list = u;
11607 	    }
11608 	}
11609       else
11610 	list = tree_cons (t, NULL_TREE, list);
11611 
11612       if (c_parser_next_token_is_not (parser, CPP_COMMA))
11613 	break;
11614 
11615       c_parser_consume_token (parser);
11616     }
11617 
11618   return list;
11619 }
11620 
11621 /* Similarly, but expect leading and trailing parenthesis.  This is a very
11622    common case for OpenACC and OpenMP clauses.  */
11623 
11624 static tree
11625 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
11626 			      tree list)
11627 {
11628   /* The clauses location.  */
11629   location_t loc = c_parser_peek_token (parser)->location;
11630 
11631   matching_parens parens;
11632   if (parens.require_open (parser))
11633     {
11634       list = c_parser_omp_variable_list (parser, loc, kind, list);
11635       parens.skip_until_found_close (parser);
11636     }
11637   return list;
11638 }
11639 
11640 /* OpenACC 2.0:
11641    copy ( variable-list )
11642    copyin ( variable-list )
11643    copyout ( variable-list )
11644    create ( variable-list )
11645    delete ( variable-list )
11646    present ( variable-list )
11647    present_or_copy ( variable-list )
11648      pcopy ( variable-list )
11649    present_or_copyin ( variable-list )
11650      pcopyin ( variable-list )
11651    present_or_copyout ( variable-list )
11652      pcopyout ( variable-list )
11653    present_or_create ( variable-list )
11654      pcreate ( variable-list ) */
11655 
11656 static tree
11657 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
11658 			   tree list)
11659 {
11660   enum gomp_map_kind kind;
11661   switch (c_kind)
11662     {
11663     case PRAGMA_OACC_CLAUSE_COPY:
11664       kind = GOMP_MAP_FORCE_TOFROM;
11665       break;
11666     case PRAGMA_OACC_CLAUSE_COPYIN:
11667       kind = GOMP_MAP_FORCE_TO;
11668       break;
11669     case PRAGMA_OACC_CLAUSE_COPYOUT:
11670       kind = GOMP_MAP_FORCE_FROM;
11671       break;
11672     case PRAGMA_OACC_CLAUSE_CREATE:
11673       kind = GOMP_MAP_FORCE_ALLOC;
11674       break;
11675     case PRAGMA_OACC_CLAUSE_DELETE:
11676       kind = GOMP_MAP_DELETE;
11677       break;
11678     case PRAGMA_OACC_CLAUSE_DEVICE:
11679       kind = GOMP_MAP_FORCE_TO;
11680       break;
11681     case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
11682       kind = GOMP_MAP_DEVICE_RESIDENT;
11683       break;
11684     case PRAGMA_OACC_CLAUSE_HOST:
11685     case PRAGMA_OACC_CLAUSE_SELF:
11686       kind = GOMP_MAP_FORCE_FROM;
11687       break;
11688     case PRAGMA_OACC_CLAUSE_LINK:
11689       kind = GOMP_MAP_LINK;
11690       break;
11691     case PRAGMA_OACC_CLAUSE_PRESENT:
11692       kind = GOMP_MAP_FORCE_PRESENT;
11693       break;
11694     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
11695       kind = GOMP_MAP_TOFROM;
11696       break;
11697     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
11698       kind = GOMP_MAP_TO;
11699       break;
11700     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
11701       kind = GOMP_MAP_FROM;
11702       break;
11703     case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
11704       kind = GOMP_MAP_ALLOC;
11705       break;
11706     default:
11707       gcc_unreachable ();
11708     }
11709   tree nl, c;
11710   nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
11711 
11712   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11713     OMP_CLAUSE_SET_MAP_KIND (c, kind);
11714 
11715   return nl;
11716 }
11717 
11718 /* OpenACC 2.0:
11719    deviceptr ( variable-list ) */
11720 
11721 static tree
11722 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
11723 {
11724   location_t loc = c_parser_peek_token (parser)->location;
11725   tree vars, t;
11726 
11727   /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11728      c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11729      variable-list must only allow for pointer variables.  */
11730   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
11731   for (t = vars; t && t; t = TREE_CHAIN (t))
11732     {
11733       tree v = TREE_PURPOSE (t);
11734 
11735       /* FIXME diagnostics: Ideally we should keep individual
11736 	 locations for all the variables in the var list to make the
11737 	 following errors more precise.  Perhaps
11738 	 c_parser_omp_var_list_parens() should construct a list of
11739 	 locations to go along with the var list.  */
11740 
11741       if (!VAR_P (v) && TREE_CODE (v) != PARM_DECL)
11742 	error_at (loc, "%qD is not a variable", v);
11743       else if (TREE_TYPE (v) == error_mark_node)
11744 	;
11745       else if (!POINTER_TYPE_P (TREE_TYPE (v)))
11746 	error_at (loc, "%qD is not a pointer variable", v);
11747 
11748       tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
11749       OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
11750       OMP_CLAUSE_DECL (u) = v;
11751       OMP_CLAUSE_CHAIN (u) = list;
11752       list = u;
11753     }
11754 
11755   return list;
11756 }
11757 
11758 /* OpenACC 2.0, OpenMP 3.0:
11759    collapse ( constant-expression ) */
11760 
11761 static tree
11762 c_parser_omp_clause_collapse (c_parser *parser, tree list)
11763 {
11764   tree c, num = error_mark_node;
11765   HOST_WIDE_INT n;
11766   location_t loc;
11767 
11768   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
11769   check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
11770 
11771   loc = c_parser_peek_token (parser)->location;
11772   matching_parens parens;
11773   if (parens.require_open (parser))
11774     {
11775       num = c_parser_expr_no_commas (parser, NULL).value;
11776       parens.skip_until_found_close (parser);
11777     }
11778   if (num == error_mark_node)
11779     return list;
11780   mark_exp_read (num);
11781   num = c_fully_fold (num, false, NULL);
11782   if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
11783       || !tree_fits_shwi_p (num)
11784       || (n = tree_to_shwi (num)) <= 0
11785       || (int) n != n)
11786     {
11787       error_at (loc,
11788 		"collapse argument needs positive constant integer expression");
11789       return list;
11790     }
11791   c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
11792   OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
11793   OMP_CLAUSE_CHAIN (c) = list;
11794   return c;
11795 }
11796 
11797 /* OpenMP 2.5:
11798    copyin ( variable-list ) */
11799 
11800 static tree
11801 c_parser_omp_clause_copyin (c_parser *parser, tree list)
11802 {
11803   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
11804 }
11805 
11806 /* OpenMP 2.5:
11807    copyprivate ( variable-list ) */
11808 
11809 static tree
11810 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
11811 {
11812   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
11813 }
11814 
11815 /* OpenMP 2.5:
11816    default ( none | shared )
11817 
11818    OpenACC:
11819    default ( none | present ) */
11820 
11821 static tree
11822 c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc)
11823 {
11824   enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
11825   location_t loc = c_parser_peek_token (parser)->location;
11826   tree c;
11827 
11828   matching_parens parens;
11829   if (!parens.require_open (parser))
11830     return list;
11831   if (c_parser_next_token_is (parser, CPP_NAME))
11832     {
11833       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11834 
11835       switch (p[0])
11836 	{
11837 	case 'n':
11838 	  if (strcmp ("none", p) != 0)
11839 	    goto invalid_kind;
11840 	  kind = OMP_CLAUSE_DEFAULT_NONE;
11841 	  break;
11842 
11843 	case 'p':
11844 	  if (strcmp ("present", p) != 0 || !is_oacc)
11845 	    goto invalid_kind;
11846 	  kind = OMP_CLAUSE_DEFAULT_PRESENT;
11847 	  break;
11848 
11849 	case 's':
11850 	  if (strcmp ("shared", p) != 0 || is_oacc)
11851 	    goto invalid_kind;
11852 	  kind = OMP_CLAUSE_DEFAULT_SHARED;
11853 	  break;
11854 
11855 	default:
11856 	  goto invalid_kind;
11857 	}
11858 
11859       c_parser_consume_token (parser);
11860     }
11861   else
11862     {
11863     invalid_kind:
11864       if (is_oacc)
11865 	c_parser_error (parser, "expected %<none%> or %<present%>");
11866       else
11867 	c_parser_error (parser, "expected %<none%> or %<shared%>");
11868     }
11869   parens.skip_until_found_close (parser);
11870 
11871   if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
11872     return list;
11873 
11874   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
11875   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
11876   OMP_CLAUSE_CHAIN (c) = list;
11877   OMP_CLAUSE_DEFAULT_KIND (c) = kind;
11878 
11879   return c;
11880 }
11881 
11882 /* OpenMP 2.5:
11883    firstprivate ( variable-list ) */
11884 
11885 static tree
11886 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
11887 {
11888   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
11889 }
11890 
11891 /* OpenMP 3.1:
11892    final ( expression ) */
11893 
11894 static tree
11895 c_parser_omp_clause_final (c_parser *parser, tree list)
11896 {
11897   location_t loc = c_parser_peek_token (parser)->location;
11898   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11899     {
11900       tree t = c_parser_paren_condition (parser);
11901       tree c;
11902 
11903       check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
11904 
11905       c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
11906       OMP_CLAUSE_FINAL_EXPR (c) = t;
11907       OMP_CLAUSE_CHAIN (c) = list;
11908       list = c;
11909     }
11910   else
11911     c_parser_error (parser, "expected %<(%>");
11912 
11913   return list;
11914 }
11915 
11916 /* OpenACC, OpenMP 2.5:
11917    if ( expression )
11918 
11919    OpenMP 4.5:
11920    if ( directive-name-modifier : expression )
11921 
11922    directive-name-modifier:
11923      parallel | task | taskloop | target data | target | target update
11924      | target enter data | target exit data  */
11925 
11926 static tree
11927 c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp)
11928 {
11929   location_t location = c_parser_peek_token (parser)->location;
11930   enum tree_code if_modifier = ERROR_MARK;
11931 
11932   matching_parens parens;
11933   if (!parens.require_open (parser))
11934     return list;
11935 
11936   if (is_omp && c_parser_next_token_is (parser, CPP_NAME))
11937     {
11938       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11939       int n = 2;
11940       if (strcmp (p, "parallel") == 0)
11941 	if_modifier = OMP_PARALLEL;
11942       else if (strcmp (p, "task") == 0)
11943 	if_modifier = OMP_TASK;
11944       else if (strcmp (p, "taskloop") == 0)
11945 	if_modifier = OMP_TASKLOOP;
11946       else if (strcmp (p, "target") == 0)
11947 	{
11948 	  if_modifier = OMP_TARGET;
11949 	  if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11950 	    {
11951 	      p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value);
11952 	      if (strcmp ("data", p) == 0)
11953 		if_modifier = OMP_TARGET_DATA;
11954 	      else if (strcmp ("update", p) == 0)
11955 		if_modifier = OMP_TARGET_UPDATE;
11956 	      else if (strcmp ("enter", p) == 0)
11957 		if_modifier = OMP_TARGET_ENTER_DATA;
11958 	      else if (strcmp ("exit", p) == 0)
11959 		if_modifier = OMP_TARGET_EXIT_DATA;
11960 	      if (if_modifier != OMP_TARGET)
11961 		{
11962 		  n = 3;
11963 		  c_parser_consume_token (parser);
11964 		}
11965 	      else
11966 		{
11967 		  location_t loc = c_parser_peek_2nd_token (parser)->location;
11968 		  error_at (loc, "expected %<data%>, %<update%>, %<enter%> "
11969 				 "or %<exit%>");
11970 		  if_modifier = ERROR_MARK;
11971 		}
11972 	      if (if_modifier == OMP_TARGET_ENTER_DATA
11973 		  || if_modifier == OMP_TARGET_EXIT_DATA)
11974 		{
11975 		  if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11976 		    {
11977 		      p = IDENTIFIER_POINTER
11978 				(c_parser_peek_2nd_token (parser)->value);
11979 		      if (strcmp ("data", p) == 0)
11980 			n = 4;
11981 		    }
11982 		  if (n == 4)
11983 		    c_parser_consume_token (parser);
11984 		  else
11985 		    {
11986 		      location_t loc
11987 			= c_parser_peek_2nd_token (parser)->location;
11988 		      error_at (loc, "expected %<data%>");
11989 		      if_modifier = ERROR_MARK;
11990 		    }
11991 		}
11992 	    }
11993 	}
11994       if (if_modifier != ERROR_MARK)
11995 	{
11996 	  if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11997 	    {
11998 	      c_parser_consume_token (parser);
11999 	      c_parser_consume_token (parser);
12000 	    }
12001 	  else
12002 	    {
12003 	      if (n > 2)
12004 		{
12005 		  location_t loc = c_parser_peek_2nd_token (parser)->location;
12006 		  error_at (loc, "expected %<:%>");
12007 		}
12008 	      if_modifier = ERROR_MARK;
12009 	    }
12010 	}
12011     }
12012 
12013   tree t = c_parser_condition (parser), c;
12014   parens.skip_until_found_close (parser);
12015 
12016   for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
12017     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF)
12018       {
12019 	if (if_modifier != ERROR_MARK
12020 	    && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
12021 	  {
12022 	    const char *p = NULL;
12023 	    switch (if_modifier)
12024 	      {
12025 	      case OMP_PARALLEL: p = "parallel"; break;
12026 	      case OMP_TASK: p = "task"; break;
12027 	      case OMP_TASKLOOP: p = "taskloop"; break;
12028 	      case OMP_TARGET_DATA: p = "target data"; break;
12029 	      case OMP_TARGET: p = "target"; break;
12030 	      case OMP_TARGET_UPDATE: p = "target update"; break;
12031 	      case OMP_TARGET_ENTER_DATA: p = "enter data"; break;
12032 	      case OMP_TARGET_EXIT_DATA: p = "exit data"; break;
12033 	      default: gcc_unreachable ();
12034 	      }
12035 	    error_at (location, "too many %<if%> clauses with %qs modifier",
12036 		      p);
12037 	    return list;
12038 	  }
12039 	else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
12040 	  {
12041 	    if (!is_omp)
12042 	      error_at (location, "too many %<if%> clauses");
12043 	    else
12044 	      error_at (location, "too many %<if%> clauses without modifier");
12045 	    return list;
12046 	  }
12047 	else if (if_modifier == ERROR_MARK
12048 		 || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK)
12049 	  {
12050 	    error_at (location, "if any %<if%> clause has modifier, then all "
12051 				"%<if%> clauses have to use modifier");
12052 	    return list;
12053 	  }
12054       }
12055 
12056   c = build_omp_clause (location, OMP_CLAUSE_IF);
12057   OMP_CLAUSE_IF_MODIFIER (c) = if_modifier;
12058   OMP_CLAUSE_IF_EXPR (c) = t;
12059   OMP_CLAUSE_CHAIN (c) = list;
12060   return c;
12061 }
12062 
12063 /* OpenMP 2.5:
12064    lastprivate ( variable-list ) */
12065 
12066 static tree
12067 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
12068 {
12069   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
12070 }
12071 
12072 /* OpenMP 3.1:
12073    mergeable */
12074 
12075 static tree
12076 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
12077 {
12078   tree c;
12079 
12080   /* FIXME: Should we allow duplicates?  */
12081   check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
12082 
12083   c = build_omp_clause (c_parser_peek_token (parser)->location,
12084 			OMP_CLAUSE_MERGEABLE);
12085   OMP_CLAUSE_CHAIN (c) = list;
12086 
12087   return c;
12088 }
12089 
12090 /* OpenMP 2.5:
12091    nowait */
12092 
12093 static tree
12094 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
12095 {
12096   tree c;
12097   location_t loc = c_parser_peek_token (parser)->location;
12098 
12099   check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
12100 
12101   c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
12102   OMP_CLAUSE_CHAIN (c) = list;
12103   return c;
12104 }
12105 
12106 /* OpenMP 2.5:
12107    num_threads ( expression ) */
12108 
12109 static tree
12110 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
12111 {
12112   location_t num_threads_loc = c_parser_peek_token (parser)->location;
12113   matching_parens parens;
12114   if (parens.require_open (parser))
12115     {
12116       location_t expr_loc = c_parser_peek_token (parser)->location;
12117       c_expr expr = c_parser_expression (parser);
12118       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12119       tree c, t = expr.value;
12120       t = c_fully_fold (t, false, NULL);
12121 
12122       parens.skip_until_found_close (parser);
12123 
12124       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12125 	{
12126 	  c_parser_error (parser, "expected integer expression");
12127 	  return list;
12128 	}
12129 
12130       /* Attempt to statically determine when the number isn't positive.  */
12131       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12132 		       build_int_cst (TREE_TYPE (t), 0));
12133       protected_set_expr_location (c, expr_loc);
12134       if (c == boolean_true_node)
12135 	{
12136 	  warning_at (expr_loc, 0,
12137 		      "%<num_threads%> value must be positive");
12138 	  t = integer_one_node;
12139 	}
12140 
12141       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
12142 
12143       c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
12144       OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
12145       OMP_CLAUSE_CHAIN (c) = list;
12146       list = c;
12147     }
12148 
12149   return list;
12150 }
12151 
12152 /* OpenMP 4.5:
12153    num_tasks ( expression ) */
12154 
12155 static tree
12156 c_parser_omp_clause_num_tasks (c_parser *parser, tree list)
12157 {
12158   location_t num_tasks_loc = c_parser_peek_token (parser)->location;
12159   matching_parens parens;
12160   if (parens.require_open (parser))
12161     {
12162       location_t expr_loc = c_parser_peek_token (parser)->location;
12163       c_expr expr = c_parser_expression (parser);
12164       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12165       tree c, t = expr.value;
12166       t = c_fully_fold (t, false, NULL);
12167 
12168       parens.skip_until_found_close (parser);
12169 
12170       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12171 	{
12172 	  c_parser_error (parser, "expected integer expression");
12173 	  return list;
12174 	}
12175 
12176       /* Attempt to statically determine when the number isn't positive.  */
12177       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12178 			   build_int_cst (TREE_TYPE (t), 0));
12179       if (CAN_HAVE_LOCATION_P (c))
12180 	SET_EXPR_LOCATION (c, expr_loc);
12181       if (c == boolean_true_node)
12182 	{
12183 	  warning_at (expr_loc, 0, "%<num_tasks%> value must be positive");
12184 	  t = integer_one_node;
12185 	}
12186 
12187       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks");
12188 
12189       c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS);
12190       OMP_CLAUSE_NUM_TASKS_EXPR (c) = t;
12191       OMP_CLAUSE_CHAIN (c) = list;
12192       list = c;
12193     }
12194 
12195   return list;
12196 }
12197 
12198 /* OpenMP 4.5:
12199    grainsize ( expression ) */
12200 
12201 static tree
12202 c_parser_omp_clause_grainsize (c_parser *parser, tree list)
12203 {
12204   location_t grainsize_loc = c_parser_peek_token (parser)->location;
12205   matching_parens parens;
12206   if (parens.require_open (parser))
12207     {
12208       location_t expr_loc = c_parser_peek_token (parser)->location;
12209       c_expr expr = c_parser_expression (parser);
12210       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12211       tree c, t = expr.value;
12212       t = c_fully_fold (t, false, NULL);
12213 
12214       parens.skip_until_found_close (parser);
12215 
12216       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12217 	{
12218 	  c_parser_error (parser, "expected integer expression");
12219 	  return list;
12220 	}
12221 
12222       /* Attempt to statically determine when the number isn't positive.  */
12223       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12224 			   build_int_cst (TREE_TYPE (t), 0));
12225       if (CAN_HAVE_LOCATION_P (c))
12226 	SET_EXPR_LOCATION (c, expr_loc);
12227       if (c == boolean_true_node)
12228 	{
12229 	  warning_at (expr_loc, 0, "%<grainsize%> value must be positive");
12230 	  t = integer_one_node;
12231 	}
12232 
12233       check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize");
12234 
12235       c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE);
12236       OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
12237       OMP_CLAUSE_CHAIN (c) = list;
12238       list = c;
12239     }
12240 
12241   return list;
12242 }
12243 
12244 /* OpenMP 4.5:
12245    priority ( expression ) */
12246 
12247 static tree
12248 c_parser_omp_clause_priority (c_parser *parser, tree list)
12249 {
12250   location_t priority_loc = c_parser_peek_token (parser)->location;
12251   matching_parens parens;
12252   if (parens.require_open (parser))
12253     {
12254       location_t expr_loc = c_parser_peek_token (parser)->location;
12255       c_expr expr = c_parser_expression (parser);
12256       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12257       tree c, t = expr.value;
12258       t = c_fully_fold (t, false, NULL);
12259 
12260       parens.skip_until_found_close (parser);
12261 
12262       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12263 	{
12264 	  c_parser_error (parser, "expected integer expression");
12265 	  return list;
12266 	}
12267 
12268       /* Attempt to statically determine when the number isn't
12269 	 non-negative.  */
12270       c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t,
12271 			   build_int_cst (TREE_TYPE (t), 0));
12272       if (CAN_HAVE_LOCATION_P (c))
12273 	SET_EXPR_LOCATION (c, expr_loc);
12274       if (c == boolean_true_node)
12275 	{
12276 	  warning_at (expr_loc, 0, "%<priority%> value must be non-negative");
12277 	  t = integer_one_node;
12278 	}
12279 
12280       check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority");
12281 
12282       c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY);
12283       OMP_CLAUSE_PRIORITY_EXPR (c) = t;
12284       OMP_CLAUSE_CHAIN (c) = list;
12285       list = c;
12286     }
12287 
12288   return list;
12289 }
12290 
12291 /* OpenMP 4.5:
12292    hint ( expression ) */
12293 
12294 static tree
12295 c_parser_omp_clause_hint (c_parser *parser, tree list)
12296 {
12297   location_t hint_loc = c_parser_peek_token (parser)->location;
12298   matching_parens parens;
12299   if (parens.require_open (parser))
12300     {
12301       location_t expr_loc = c_parser_peek_token (parser)->location;
12302       c_expr expr = c_parser_expression (parser);
12303       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12304       tree c, t = expr.value;
12305       t = c_fully_fold (t, false, NULL);
12306 
12307       parens.skip_until_found_close (parser);
12308 
12309       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12310 	{
12311 	  c_parser_error (parser, "expected integer expression");
12312 	  return list;
12313 	}
12314 
12315       check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint");
12316 
12317       c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT);
12318       OMP_CLAUSE_HINT_EXPR (c) = t;
12319       OMP_CLAUSE_CHAIN (c) = list;
12320       list = c;
12321     }
12322 
12323   return list;
12324 }
12325 
12326 /* OpenMP 4.5:
12327    defaultmap ( tofrom : scalar ) */
12328 
12329 static tree
12330 c_parser_omp_clause_defaultmap (c_parser *parser, tree list)
12331 {
12332   location_t loc = c_parser_peek_token (parser)->location;
12333   tree c;
12334   const char *p;
12335 
12336   matching_parens parens;
12337   if (!parens.require_open (parser))
12338     return list;
12339   if (!c_parser_next_token_is (parser, CPP_NAME))
12340     {
12341       c_parser_error (parser, "expected %<tofrom%>");
12342       goto out_err;
12343     }
12344   p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12345   if (strcmp (p, "tofrom") != 0)
12346     {
12347       c_parser_error (parser, "expected %<tofrom%>");
12348       goto out_err;
12349     }
12350   c_parser_consume_token (parser);
12351   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12352     goto out_err;
12353   if (!c_parser_next_token_is (parser, CPP_NAME))
12354     {
12355       c_parser_error (parser, "expected %<scalar%>");
12356       goto out_err;
12357     }
12358   p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12359   if (strcmp (p, "scalar") != 0)
12360     {
12361       c_parser_error (parser, "expected %<scalar%>");
12362       goto out_err;
12363     }
12364   c_parser_consume_token (parser);
12365   parens.skip_until_found_close (parser);
12366   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap");
12367   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP);
12368   OMP_CLAUSE_CHAIN (c) = list;
12369   return c;
12370 
12371  out_err:
12372   parens.skip_until_found_close (parser);
12373   return list;
12374 }
12375 
12376 /* OpenACC 2.0:
12377    use_device ( variable-list )
12378 
12379    OpenMP 4.5:
12380    use_device_ptr ( variable-list ) */
12381 
12382 static tree
12383 c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list)
12384 {
12385   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR,
12386 				       list);
12387 }
12388 
12389 /* OpenMP 4.5:
12390    is_device_ptr ( variable-list ) */
12391 
12392 static tree
12393 c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list)
12394 {
12395   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list);
12396 }
12397 
12398 /* OpenACC:
12399    num_gangs ( expression )
12400    num_workers ( expression )
12401    vector_length ( expression )  */
12402 
12403 static tree
12404 c_parser_oacc_single_int_clause (c_parser *parser, omp_clause_code code,
12405 				 tree list)
12406 {
12407   location_t loc = c_parser_peek_token (parser)->location;
12408 
12409   matching_parens parens;
12410   if (!parens.require_open (parser))
12411     return list;
12412 
12413   location_t expr_loc = c_parser_peek_token (parser)->location;
12414   c_expr expr = c_parser_expression (parser);
12415   expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12416   tree c, t = expr.value;
12417   t = c_fully_fold (t, false, NULL);
12418 
12419   parens.skip_until_found_close (parser);
12420 
12421   if (t == error_mark_node)
12422     return list;
12423   else if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12424     {
12425       error_at (expr_loc, "%qs expression must be integral",
12426 		omp_clause_code_name[code]);
12427       return list;
12428     }
12429 
12430   /* Attempt to statically determine when the number isn't positive.  */
12431   c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12432 		       build_int_cst (TREE_TYPE (t), 0));
12433   protected_set_expr_location (c, expr_loc);
12434   if (c == boolean_true_node)
12435     {
12436       warning_at (expr_loc, 0,
12437 		  "%qs value must be positive",
12438 		  omp_clause_code_name[code]);
12439       t = integer_one_node;
12440     }
12441 
12442   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
12443 
12444   c = build_omp_clause (loc, code);
12445   OMP_CLAUSE_OPERAND (c, 0) = t;
12446   OMP_CLAUSE_CHAIN (c) = list;
12447   return c;
12448 }
12449 
12450 /* OpenACC:
12451 
12452     gang [( gang-arg-list )]
12453     worker [( [num:] int-expr )]
12454     vector [( [length:] int-expr )]
12455 
12456   where gang-arg is one of:
12457 
12458     [num:] int-expr
12459     static: size-expr
12460 
12461   and size-expr may be:
12462 
12463     *
12464     int-expr
12465 */
12466 
12467 static tree
12468 c_parser_oacc_shape_clause (c_parser *parser, omp_clause_code kind,
12469 			    const char *str, tree list)
12470 {
12471   const char *id = "num";
12472   tree ops[2] = { NULL_TREE, NULL_TREE }, c;
12473   location_t loc = c_parser_peek_token (parser)->location;
12474 
12475   if (kind == OMP_CLAUSE_VECTOR)
12476     id = "length";
12477 
12478   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12479     {
12480       c_parser_consume_token (parser);
12481 
12482       do
12483 	{
12484 	  c_token *next = c_parser_peek_token (parser);
12485 	  int idx = 0;
12486 
12487 	  /* Gang static argument.  */
12488 	  if (kind == OMP_CLAUSE_GANG
12489 	      && c_parser_next_token_is_keyword (parser, RID_STATIC))
12490 	    {
12491 	      c_parser_consume_token (parser);
12492 
12493 	      if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12494 		goto cleanup_error;
12495 
12496 	      idx = 1;
12497 	      if (ops[idx] != NULL_TREE)
12498 		{
12499 		  c_parser_error (parser, "too many %<static%> arguments");
12500 		  goto cleanup_error;
12501 		}
12502 
12503 	      /* Check for the '*' argument.  */
12504 	      if (c_parser_next_token_is (parser, CPP_MULT)
12505 		  && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
12506 		      || c_parser_peek_2nd_token (parser)->type
12507 		         == CPP_CLOSE_PAREN))
12508 		{
12509 		  c_parser_consume_token (parser);
12510 		  ops[idx] = integer_minus_one_node;
12511 
12512 		  if (c_parser_next_token_is (parser, CPP_COMMA))
12513 		    {
12514 		      c_parser_consume_token (parser);
12515 		      continue;
12516 		    }
12517 		  else
12518 		    break;
12519 		}
12520 	    }
12521 	  /* Worker num: argument and vector length: arguments.  */
12522 	  else if (c_parser_next_token_is (parser, CPP_NAME)
12523 		   && strcmp (id, IDENTIFIER_POINTER (next->value)) == 0
12524 		   && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
12525 	    {
12526 	      c_parser_consume_token (parser);  /* id  */
12527 	      c_parser_consume_token (parser);  /* ':'  */
12528 	    }
12529 
12530 	  /* Now collect the actual argument.  */
12531 	  if (ops[idx] != NULL_TREE)
12532 	    {
12533 	      c_parser_error (parser, "unexpected argument");
12534 	      goto cleanup_error;
12535 	    }
12536 
12537 	  location_t expr_loc = c_parser_peek_token (parser)->location;
12538 	  c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
12539 	  cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
12540 	  tree expr = cexpr.value;
12541 	  if (expr == error_mark_node)
12542 	    goto cleanup_error;
12543 
12544 	  expr = c_fully_fold (expr, false, NULL);
12545 
12546 	  /* Attempt to statically determine when the number isn't a
12547 	     positive integer.  */
12548 
12549 	  if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)))
12550 	    {
12551 	      c_parser_error (parser, "expected integer expression");
12552 	      return list;
12553 	    }
12554 
12555 	  tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr,
12556 				    build_int_cst (TREE_TYPE (expr), 0));
12557 	  if (c == boolean_true_node)
12558 	    {
12559 	      warning_at (loc, 0,
12560 			  "%qs value must be positive", str);
12561 	      expr = integer_one_node;
12562 	    }
12563 
12564 	  ops[idx] = expr;
12565 
12566 	  if (kind == OMP_CLAUSE_GANG
12567 	      && c_parser_next_token_is (parser, CPP_COMMA))
12568 	    {
12569 	      c_parser_consume_token (parser);
12570 	      continue;
12571 	    }
12572 	  break;
12573 	}
12574       while (1);
12575 
12576       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
12577 	goto cleanup_error;
12578     }
12579 
12580   check_no_duplicate_clause (list, kind, str);
12581 
12582   c = build_omp_clause (loc, kind);
12583 
12584   if (ops[1])
12585     OMP_CLAUSE_OPERAND (c, 1) = ops[1];
12586 
12587   OMP_CLAUSE_OPERAND (c, 0) = ops[0];
12588   OMP_CLAUSE_CHAIN (c) = list;
12589 
12590   return c;
12591 
12592  cleanup_error:
12593   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
12594   return list;
12595 }
12596 
12597 /* OpenACC:
12598    auto
12599    independent
12600    nohost
12601    seq */
12602 
12603 static tree
12604 c_parser_oacc_simple_clause (c_parser *parser, enum omp_clause_code code,
12605 			     tree list)
12606 {
12607   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
12608 
12609   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
12610   OMP_CLAUSE_CHAIN (c) = list;
12611 
12612   return c;
12613 }
12614 
12615 /* OpenACC:
12616    async [( int-expr )] */
12617 
12618 static tree
12619 c_parser_oacc_clause_async (c_parser *parser, tree list)
12620 {
12621   tree c, t;
12622   location_t loc = c_parser_peek_token (parser)->location;
12623 
12624   t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
12625 
12626   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12627     {
12628       c_parser_consume_token (parser);
12629 
12630       t = c_parser_expression (parser).value;
12631       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12632 	c_parser_error (parser, "expected integer expression");
12633       else if (t == error_mark_node
12634 	  || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
12635 	return list;
12636     }
12637   else
12638     t = c_fully_fold (t, false, NULL);
12639 
12640   check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
12641 
12642   c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
12643   OMP_CLAUSE_ASYNC_EXPR (c) = t;
12644   OMP_CLAUSE_CHAIN (c) = list;
12645   list = c;
12646 
12647   return list;
12648 }
12649 
12650 /* OpenACC 2.0:
12651    tile ( size-expr-list ) */
12652 
12653 static tree
12654 c_parser_oacc_clause_tile (c_parser *parser, tree list)
12655 {
12656   tree c, expr = error_mark_node;
12657   location_t loc;
12658   tree tile = NULL_TREE;
12659 
12660   check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
12661   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
12662 
12663   loc = c_parser_peek_token (parser)->location;
12664   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12665     return list;
12666 
12667   do
12668     {
12669       if (tile && !c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
12670 	return list;
12671 
12672       if (c_parser_next_token_is (parser, CPP_MULT)
12673 	  && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
12674 	      || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
12675 	{
12676 	  c_parser_consume_token (parser);
12677 	  expr = integer_zero_node;
12678 	}
12679       else
12680 	{
12681 	  location_t expr_loc = c_parser_peek_token (parser)->location;
12682 	  c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
12683 	  cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
12684 	  expr = cexpr.value;
12685 
12686 	  if (expr == error_mark_node)
12687 	    {
12688 	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12689 					 "expected %<)%>");
12690 	      return list;
12691 	    }
12692 
12693 	  expr = c_fully_fold (expr, false, NULL);
12694 
12695 	  if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
12696 	      || !tree_fits_shwi_p (expr)
12697 	      || tree_to_shwi (expr) <= 0)
12698 	    {
12699 	      error_at (expr_loc, "%<tile%> argument needs positive"
12700 			" integral constant");
12701 	      expr = integer_zero_node;
12702 	    }
12703 	}
12704 
12705       tile = tree_cons (NULL_TREE, expr, tile);
12706     }
12707   while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN));
12708 
12709   /* Consume the trailing ')'.  */
12710   c_parser_consume_token (parser);
12711 
12712   c = build_omp_clause (loc, OMP_CLAUSE_TILE);
12713   tile = nreverse (tile);
12714   OMP_CLAUSE_TILE_LIST (c) = tile;
12715   OMP_CLAUSE_CHAIN (c) = list;
12716   return c;
12717 }
12718 
12719 /* OpenACC:
12720    wait ( int-expr-list ) */
12721 
12722 static tree
12723 c_parser_oacc_clause_wait (c_parser *parser, tree list)
12724 {
12725   location_t clause_loc = c_parser_peek_token (parser)->location;
12726 
12727   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12728     list = c_parser_oacc_wait_list (parser, clause_loc, list);
12729 
12730   return list;
12731 }
12732 
12733 /* OpenMP 2.5:
12734    ordered
12735 
12736    OpenMP 4.5:
12737    ordered ( constant-expression ) */
12738 
12739 static tree
12740 c_parser_omp_clause_ordered (c_parser *parser, tree list)
12741 {
12742   check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
12743 
12744   tree c, num = NULL_TREE;
12745   HOST_WIDE_INT n;
12746   location_t loc = c_parser_peek_token (parser)->location;
12747   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12748     {
12749       matching_parens parens;
12750       parens.consume_open (parser);
12751       num = c_parser_expr_no_commas (parser, NULL).value;
12752       parens.skip_until_found_close (parser);
12753     }
12754   if (num == error_mark_node)
12755     return list;
12756   if (num)
12757     {
12758       mark_exp_read (num);
12759       num = c_fully_fold (num, false, NULL);
12760       if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
12761 	  || !tree_fits_shwi_p (num)
12762 	  || (n = tree_to_shwi (num)) <= 0
12763 	  || (int) n != n)
12764 	{
12765 	  error_at (loc, "ordered argument needs positive "
12766 			 "constant integer expression");
12767 	  return list;
12768 	}
12769     }
12770   c = build_omp_clause (loc, OMP_CLAUSE_ORDERED);
12771   OMP_CLAUSE_ORDERED_EXPR (c) = num;
12772   OMP_CLAUSE_CHAIN (c) = list;
12773   return c;
12774 }
12775 
12776 /* OpenMP 2.5:
12777    private ( variable-list ) */
12778 
12779 static tree
12780 c_parser_omp_clause_private (c_parser *parser, tree list)
12781 {
12782   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
12783 }
12784 
12785 /* OpenMP 2.5:
12786    reduction ( reduction-operator : variable-list )
12787 
12788    reduction-operator:
12789      One of: + * - & ^ | && ||
12790 
12791    OpenMP 3.1:
12792 
12793    reduction-operator:
12794      One of: + * - & ^ | && || max min
12795 
12796    OpenMP 4.0:
12797 
12798    reduction-operator:
12799      One of: + * - & ^ | && ||
12800      identifier  */
12801 
12802 static tree
12803 c_parser_omp_clause_reduction (c_parser *parser, tree list)
12804 {
12805   location_t clause_loc = c_parser_peek_token (parser)->location;
12806   matching_parens parens;
12807   if (parens.require_open (parser))
12808     {
12809       enum tree_code code = ERROR_MARK;
12810       tree reduc_id = NULL_TREE;
12811 
12812       switch (c_parser_peek_token (parser)->type)
12813 	{
12814 	case CPP_PLUS:
12815 	  code = PLUS_EXPR;
12816 	  break;
12817 	case CPP_MULT:
12818 	  code = MULT_EXPR;
12819 	  break;
12820 	case CPP_MINUS:
12821 	  code = MINUS_EXPR;
12822 	  break;
12823 	case CPP_AND:
12824 	  code = BIT_AND_EXPR;
12825 	  break;
12826 	case CPP_XOR:
12827 	  code = BIT_XOR_EXPR;
12828 	  break;
12829 	case CPP_OR:
12830 	  code = BIT_IOR_EXPR;
12831 	  break;
12832 	case CPP_AND_AND:
12833 	  code = TRUTH_ANDIF_EXPR;
12834 	  break;
12835 	case CPP_OR_OR:
12836 	  code = TRUTH_ORIF_EXPR;
12837 	  break;
12838         case CPP_NAME:
12839 	  {
12840 	    const char *p
12841 	      = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12842 	    if (strcmp (p, "min") == 0)
12843 	      {
12844 		code = MIN_EXPR;
12845 		break;
12846 	      }
12847 	    if (strcmp (p, "max") == 0)
12848 	      {
12849 		code = MAX_EXPR;
12850 		break;
12851 	      }
12852 	    reduc_id = c_parser_peek_token (parser)->value;
12853 	    break;
12854 	  }
12855 	default:
12856 	  c_parser_error (parser,
12857 			  "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12858 			  "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12859 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
12860 	  return list;
12861 	}
12862       c_parser_consume_token (parser);
12863       reduc_id = c_omp_reduction_id (code, reduc_id);
12864       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12865 	{
12866 	  tree nl, c;
12867 
12868 	  nl = c_parser_omp_variable_list (parser, clause_loc,
12869 					   OMP_CLAUSE_REDUCTION, list);
12870 	  for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12871 	    {
12872 	      tree d = OMP_CLAUSE_DECL (c), type;
12873 	      if (TREE_CODE (d) != TREE_LIST)
12874 		type = TREE_TYPE (d);
12875 	      else
12876 		{
12877 		  int cnt = 0;
12878 		  tree t;
12879 		  for (t = d; TREE_CODE (t) == TREE_LIST; t = TREE_CHAIN (t))
12880 		    cnt++;
12881 		  type = TREE_TYPE (t);
12882 		  while (cnt > 0)
12883 		    {
12884 		      if (TREE_CODE (type) != POINTER_TYPE
12885 			  && TREE_CODE (type) != ARRAY_TYPE)
12886 			break;
12887 		      type = TREE_TYPE (type);
12888 		      cnt--;
12889 		    }
12890 		}
12891 	      while (TREE_CODE (type) == ARRAY_TYPE)
12892 		type = TREE_TYPE (type);
12893 	      OMP_CLAUSE_REDUCTION_CODE (c) = code;
12894 	      if (code == ERROR_MARK
12895 		  || !(INTEGRAL_TYPE_P (type)
12896 		       || TREE_CODE (type) == REAL_TYPE
12897 		       || TREE_CODE (type) == COMPLEX_TYPE))
12898 		OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
12899 		  = c_omp_reduction_lookup (reduc_id,
12900 					    TYPE_MAIN_VARIANT (type));
12901 	    }
12902 
12903 	  list = nl;
12904 	}
12905       parens.skip_until_found_close (parser);
12906     }
12907   return list;
12908 }
12909 
12910 /* OpenMP 2.5:
12911    schedule ( schedule-kind )
12912    schedule ( schedule-kind , expression )
12913 
12914    schedule-kind:
12915      static | dynamic | guided | runtime | auto
12916 
12917    OpenMP 4.5:
12918    schedule ( schedule-modifier : schedule-kind )
12919    schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12920 
12921    schedule-modifier:
12922      simd
12923      monotonic
12924      nonmonotonic  */
12925 
12926 static tree
12927 c_parser_omp_clause_schedule (c_parser *parser, tree list)
12928 {
12929   tree c, t;
12930   location_t loc = c_parser_peek_token (parser)->location;
12931   int modifiers = 0, nmodifiers = 0;
12932 
12933   matching_parens parens;
12934   if (!parens.require_open (parser))
12935     return list;
12936 
12937   c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
12938 
12939   while (c_parser_next_token_is (parser, CPP_NAME))
12940     {
12941       tree kind = c_parser_peek_token (parser)->value;
12942       const char *p = IDENTIFIER_POINTER (kind);
12943       if (strcmp ("simd", p) == 0)
12944 	OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
12945       else if (strcmp ("monotonic", p) == 0)
12946 	modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC;
12947       else if (strcmp ("nonmonotonic", p) == 0)
12948 	modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC;
12949       else
12950 	break;
12951       c_parser_consume_token (parser);
12952       if (nmodifiers++ == 0
12953 	  && c_parser_next_token_is (parser, CPP_COMMA))
12954 	c_parser_consume_token (parser);
12955       else
12956 	{
12957 	  c_parser_require (parser, CPP_COLON, "expected %<:%>");
12958 	  break;
12959 	}
12960     }
12961 
12962   if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC
12963 		    | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
12964       == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12965 	  | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
12966     {
12967       error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12968 		     "specified");
12969       modifiers = 0;
12970     }
12971 
12972   if (c_parser_next_token_is (parser, CPP_NAME))
12973     {
12974       tree kind = c_parser_peek_token (parser)->value;
12975       const char *p = IDENTIFIER_POINTER (kind);
12976 
12977       switch (p[0])
12978 	{
12979 	case 'd':
12980 	  if (strcmp ("dynamic", p) != 0)
12981 	    goto invalid_kind;
12982 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
12983 	  break;
12984 
12985         case 'g':
12986 	  if (strcmp ("guided", p) != 0)
12987 	    goto invalid_kind;
12988 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
12989 	  break;
12990 
12991 	case 'r':
12992 	  if (strcmp ("runtime", p) != 0)
12993 	    goto invalid_kind;
12994 	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
12995 	  break;
12996 
12997 	default:
12998 	  goto invalid_kind;
12999 	}
13000     }
13001   else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
13002     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
13003   else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
13004     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
13005   else
13006     goto invalid_kind;
13007 
13008   c_parser_consume_token (parser);
13009   if (c_parser_next_token_is (parser, CPP_COMMA))
13010     {
13011       location_t here;
13012       c_parser_consume_token (parser);
13013 
13014       here = c_parser_peek_token (parser)->location;
13015       c_expr expr = c_parser_expr_no_commas (parser, NULL);
13016       expr = convert_lvalue_to_rvalue (here, expr, false, true);
13017       t = expr.value;
13018       t = c_fully_fold (t, false, NULL);
13019 
13020       if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
13021 	error_at (here, "schedule %<runtime%> does not take "
13022 		  "a %<chunk_size%> parameter");
13023       else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
13024 	error_at (here,
13025 		  "schedule %<auto%> does not take "
13026 		  "a %<chunk_size%> parameter");
13027       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
13028 	{
13029 	  /* Attempt to statically determine when the number isn't
13030 	     positive.  */
13031 	  tree s = fold_build2_loc (loc, LE_EXPR, boolean_type_node, t,
13032 				    build_int_cst (TREE_TYPE (t), 0));
13033 	  protected_set_expr_location (s, loc);
13034 	  if (s == boolean_true_node)
13035 	    {
13036 	      warning_at (loc, 0,
13037 			  "chunk size value must be positive");
13038 	      t = integer_one_node;
13039 	    }
13040 	  OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
13041 	}
13042       else
13043 	c_parser_error (parser, "expected integer expression");
13044 
13045       parens.skip_until_found_close (parser);
13046     }
13047   else
13048     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13049 			       "expected %<,%> or %<)%>");
13050 
13051   OMP_CLAUSE_SCHEDULE_KIND (c)
13052     = (enum omp_clause_schedule_kind)
13053       (OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers);
13054 
13055   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
13056   OMP_CLAUSE_CHAIN (c) = list;
13057   return c;
13058 
13059  invalid_kind:
13060   c_parser_error (parser, "invalid schedule kind");
13061   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
13062   return list;
13063 }
13064 
13065 /* OpenMP 2.5:
13066    shared ( variable-list ) */
13067 
13068 static tree
13069 c_parser_omp_clause_shared (c_parser *parser, tree list)
13070 {
13071   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
13072 }
13073 
13074 /* OpenMP 3.0:
13075    untied */
13076 
13077 static tree
13078 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
13079 {
13080   tree c;
13081 
13082   /* FIXME: Should we allow duplicates?  */
13083   check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
13084 
13085   c = build_omp_clause (c_parser_peek_token (parser)->location,
13086 			OMP_CLAUSE_UNTIED);
13087   OMP_CLAUSE_CHAIN (c) = list;
13088 
13089   return c;
13090 }
13091 
13092 /* OpenMP 4.0:
13093    inbranch
13094    notinbranch */
13095 
13096 static tree
13097 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
13098 			    enum omp_clause_code code, tree list)
13099 {
13100   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
13101 
13102   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
13103   OMP_CLAUSE_CHAIN (c) = list;
13104 
13105   return c;
13106 }
13107 
13108 /* OpenMP 4.0:
13109    parallel
13110    for
13111    sections
13112    taskgroup */
13113 
13114 static tree
13115 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
13116 				enum omp_clause_code code, tree list)
13117 {
13118   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
13119   OMP_CLAUSE_CHAIN (c) = list;
13120 
13121   return c;
13122 }
13123 
13124 /* OpenMP 4.5:
13125    nogroup */
13126 
13127 static tree
13128 c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list)
13129 {
13130   check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup");
13131   tree c = build_omp_clause (c_parser_peek_token (parser)->location,
13132 			     OMP_CLAUSE_NOGROUP);
13133   OMP_CLAUSE_CHAIN (c) = list;
13134   return c;
13135 }
13136 
13137 /* OpenMP 4.5:
13138    simd
13139    threads */
13140 
13141 static tree
13142 c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED,
13143 				 enum omp_clause_code code, tree list)
13144 {
13145   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
13146   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
13147   OMP_CLAUSE_CHAIN (c) = list;
13148   return c;
13149 }
13150 
13151 /* OpenMP 4.0:
13152    num_teams ( expression ) */
13153 
13154 static tree
13155 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
13156 {
13157   location_t num_teams_loc = c_parser_peek_token (parser)->location;
13158   matching_parens parens;
13159   if (parens.require_open (parser))
13160     {
13161       location_t expr_loc = c_parser_peek_token (parser)->location;
13162       c_expr expr = c_parser_expression (parser);
13163       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13164       tree c, t = expr.value;
13165       t = c_fully_fold (t, false, NULL);
13166 
13167       parens.skip_until_found_close (parser);
13168 
13169       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
13170 	{
13171 	  c_parser_error (parser, "expected integer expression");
13172 	  return list;
13173 	}
13174 
13175       /* Attempt to statically determine when the number isn't positive.  */
13176       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
13177 			   build_int_cst (TREE_TYPE (t), 0));
13178       protected_set_expr_location (c, expr_loc);
13179       if (c == boolean_true_node)
13180 	{
13181 	  warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
13182 	  t = integer_one_node;
13183 	}
13184 
13185       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
13186 
13187       c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
13188       OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
13189       OMP_CLAUSE_CHAIN (c) = list;
13190       list = c;
13191     }
13192 
13193   return list;
13194 }
13195 
13196 /* OpenMP 4.0:
13197    thread_limit ( expression ) */
13198 
13199 static tree
13200 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
13201 {
13202   location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
13203   matching_parens parens;
13204   if (parens.require_open (parser))
13205     {
13206       location_t expr_loc = c_parser_peek_token (parser)->location;
13207       c_expr expr = c_parser_expression (parser);
13208       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13209       tree c, t = expr.value;
13210       t = c_fully_fold (t, false, NULL);
13211 
13212       parens.skip_until_found_close (parser);
13213 
13214       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
13215 	{
13216 	  c_parser_error (parser, "expected integer expression");
13217 	  return list;
13218 	}
13219 
13220       /* Attempt to statically determine when the number isn't positive.  */
13221       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
13222 			   build_int_cst (TREE_TYPE (t), 0));
13223       protected_set_expr_location (c, expr_loc);
13224       if (c == boolean_true_node)
13225 	{
13226 	  warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
13227 	  t = integer_one_node;
13228 	}
13229 
13230       check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
13231 				 "thread_limit");
13232 
13233       c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
13234       OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
13235       OMP_CLAUSE_CHAIN (c) = list;
13236       list = c;
13237     }
13238 
13239   return list;
13240 }
13241 
13242 /* OpenMP 4.0:
13243    aligned ( variable-list )
13244    aligned ( variable-list : constant-expression ) */
13245 
13246 static tree
13247 c_parser_omp_clause_aligned (c_parser *parser, tree list)
13248 {
13249   location_t clause_loc = c_parser_peek_token (parser)->location;
13250   tree nl, c;
13251 
13252   matching_parens parens;
13253   if (!parens.require_open (parser))
13254     return list;
13255 
13256   nl = c_parser_omp_variable_list (parser, clause_loc,
13257 				   OMP_CLAUSE_ALIGNED, list);
13258 
13259   if (c_parser_next_token_is (parser, CPP_COLON))
13260     {
13261       c_parser_consume_token (parser);
13262       location_t expr_loc = c_parser_peek_token (parser)->location;
13263       c_expr expr = c_parser_expr_no_commas (parser, NULL);
13264       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13265       tree alignment = expr.value;
13266       alignment = c_fully_fold (alignment, false, NULL);
13267       if (TREE_CODE (alignment) != INTEGER_CST
13268 	  || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
13269 	  || tree_int_cst_sgn (alignment) != 1)
13270 	{
13271 	  error_at (clause_loc, "%<aligned%> clause alignment expression must "
13272 				"be positive constant integer expression");
13273 	  alignment = NULL_TREE;
13274 	}
13275 
13276       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13277 	OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
13278     }
13279 
13280   parens.skip_until_found_close (parser);
13281   return nl;
13282 }
13283 
13284 /* OpenMP 4.0:
13285    linear ( variable-list )
13286    linear ( variable-list : expression )
13287 
13288    OpenMP 4.5:
13289    linear ( modifier ( variable-list ) )
13290    linear ( modifier ( variable-list ) : expression ) */
13291 
13292 static tree
13293 c_parser_omp_clause_linear (c_parser *parser, tree list)
13294 {
13295   location_t clause_loc = c_parser_peek_token (parser)->location;
13296   tree nl, c, step;
13297   enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT;
13298 
13299   matching_parens parens;
13300   if (!parens.require_open (parser))
13301     return list;
13302 
13303   if (c_parser_next_token_is (parser, CPP_NAME))
13304     {
13305       c_token *tok = c_parser_peek_token (parser);
13306       const char *p = IDENTIFIER_POINTER (tok->value);
13307       if (strcmp ("val", p) == 0)
13308 	kind = OMP_CLAUSE_LINEAR_VAL;
13309       if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN)
13310 	kind = OMP_CLAUSE_LINEAR_DEFAULT;
13311       if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
13312 	{
13313 	  c_parser_consume_token (parser);
13314 	  c_parser_consume_token (parser);
13315 	}
13316     }
13317 
13318   nl = c_parser_omp_variable_list (parser, clause_loc,
13319 				   OMP_CLAUSE_LINEAR, list);
13320 
13321   if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
13322     parens.skip_until_found_close (parser);
13323 
13324   if (c_parser_next_token_is (parser, CPP_COLON))
13325     {
13326       c_parser_consume_token (parser);
13327       location_t expr_loc = c_parser_peek_token (parser)->location;
13328       c_expr expr = c_parser_expression (parser);
13329       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13330       step = expr.value;
13331       step = c_fully_fold (step, false, NULL);
13332       if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
13333 	{
13334 	  error_at (clause_loc, "%<linear%> clause step expression must "
13335 				"be integral");
13336 	  step = integer_one_node;
13337 	}
13338 
13339     }
13340   else
13341     step = integer_one_node;
13342 
13343   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13344     {
13345       OMP_CLAUSE_LINEAR_STEP (c) = step;
13346       OMP_CLAUSE_LINEAR_KIND (c) = kind;
13347     }
13348 
13349   parens.skip_until_found_close (parser);
13350   return nl;
13351 }
13352 
13353 /* OpenMP 4.0:
13354    safelen ( constant-expression ) */
13355 
13356 static tree
13357 c_parser_omp_clause_safelen (c_parser *parser, tree list)
13358 {
13359   location_t clause_loc = c_parser_peek_token (parser)->location;
13360   tree c, t;
13361 
13362   matching_parens parens;
13363   if (!parens.require_open (parser))
13364     return list;
13365 
13366   location_t expr_loc = c_parser_peek_token (parser)->location;
13367   c_expr expr = c_parser_expr_no_commas (parser, NULL);
13368   expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13369   t = expr.value;
13370   t = c_fully_fold (t, false, NULL);
13371   if (TREE_CODE (t) != INTEGER_CST
13372       || !INTEGRAL_TYPE_P (TREE_TYPE (t))
13373       || tree_int_cst_sgn (t) != 1)
13374     {
13375       error_at (clause_loc, "%<safelen%> clause expression must "
13376 			    "be positive constant integer expression");
13377       t = NULL_TREE;
13378     }
13379 
13380   parens.skip_until_found_close (parser);
13381   if (t == NULL_TREE || t == error_mark_node)
13382     return list;
13383 
13384   check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
13385 
13386   c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
13387   OMP_CLAUSE_SAFELEN_EXPR (c) = t;
13388   OMP_CLAUSE_CHAIN (c) = list;
13389   return c;
13390 }
13391 
13392 /* OpenMP 4.0:
13393    simdlen ( constant-expression ) */
13394 
13395 static tree
13396 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
13397 {
13398   location_t clause_loc = c_parser_peek_token (parser)->location;
13399   tree c, t;
13400 
13401   matching_parens parens;
13402   if (!parens.require_open (parser))
13403     return list;
13404 
13405   location_t expr_loc = c_parser_peek_token (parser)->location;
13406   c_expr expr = c_parser_expr_no_commas (parser, NULL);
13407   expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13408   t = expr.value;
13409   t = c_fully_fold (t, false, NULL);
13410   if (TREE_CODE (t) != INTEGER_CST
13411       || !INTEGRAL_TYPE_P (TREE_TYPE (t))
13412       || tree_int_cst_sgn (t) != 1)
13413     {
13414       error_at (clause_loc, "%<simdlen%> clause expression must "
13415 			    "be positive constant integer expression");
13416       t = NULL_TREE;
13417     }
13418 
13419   parens.skip_until_found_close (parser);
13420   if (t == NULL_TREE || t == error_mark_node)
13421     return list;
13422 
13423   check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
13424 
13425   c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
13426   OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
13427   OMP_CLAUSE_CHAIN (c) = list;
13428   return c;
13429 }
13430 
13431 /* OpenMP 4.5:
13432    vec:
13433      identifier [+/- integer]
13434      vec , identifier [+/- integer]
13435 */
13436 
13437 static tree
13438 c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc,
13439 				 tree list)
13440 {
13441   tree vec = NULL;
13442   if (c_parser_next_token_is_not (parser, CPP_NAME)
13443       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
13444     {
13445       c_parser_error (parser, "expected identifier");
13446       return list;
13447     }
13448 
13449   while (c_parser_next_token_is (parser, CPP_NAME)
13450 	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
13451     {
13452       tree t = lookup_name (c_parser_peek_token (parser)->value);
13453       tree addend = NULL;
13454 
13455       if (t == NULL_TREE)
13456 	{
13457 	  undeclared_variable (c_parser_peek_token (parser)->location,
13458 			       c_parser_peek_token (parser)->value);
13459 	  t = error_mark_node;
13460 	}
13461 
13462       c_parser_consume_token (parser);
13463 
13464       bool neg = false;
13465       if (c_parser_next_token_is (parser, CPP_MINUS))
13466 	neg = true;
13467       else if (!c_parser_next_token_is (parser, CPP_PLUS))
13468 	{
13469 	  addend = integer_zero_node;
13470 	  neg = false;
13471 	  goto add_to_vector;
13472 	}
13473       c_parser_consume_token (parser);
13474 
13475       if (c_parser_next_token_is_not (parser, CPP_NUMBER))
13476 	{
13477 	  c_parser_error (parser, "expected integer");
13478 	  return list;
13479 	}
13480 
13481       addend = c_parser_peek_token (parser)->value;
13482       if (TREE_CODE (addend) != INTEGER_CST)
13483 	{
13484 	  c_parser_error (parser, "expected integer");
13485 	  return list;
13486 	}
13487       c_parser_consume_token (parser);
13488 
13489     add_to_vector:
13490       if (t != error_mark_node)
13491 	{
13492 	  vec = tree_cons (addend, t, vec);
13493 	  if (neg)
13494 	    OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1;
13495 	}
13496 
13497       if (c_parser_next_token_is_not (parser, CPP_COMMA))
13498 	break;
13499 
13500       c_parser_consume_token (parser);
13501     }
13502 
13503   if (vec == NULL_TREE)
13504     return list;
13505 
13506   tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
13507   OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK;
13508   OMP_CLAUSE_DECL (u) = nreverse (vec);
13509   OMP_CLAUSE_CHAIN (u) = list;
13510   return u;
13511 }
13512 
13513 /* OpenMP 4.0:
13514    depend ( depend-kind: variable-list )
13515 
13516    depend-kind:
13517      in | out | inout
13518 
13519    OpenMP 4.5:
13520    depend ( source )
13521 
13522    depend ( sink  : vec )  */
13523 
13524 static tree
13525 c_parser_omp_clause_depend (c_parser *parser, tree list)
13526 {
13527   location_t clause_loc = c_parser_peek_token (parser)->location;
13528   enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
13529   tree nl, c;
13530 
13531   matching_parens parens;
13532   if (!parens.require_open (parser))
13533     return list;
13534 
13535   if (c_parser_next_token_is (parser, CPP_NAME))
13536     {
13537       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13538       if (strcmp ("in", p) == 0)
13539 	kind = OMP_CLAUSE_DEPEND_IN;
13540       else if (strcmp ("inout", p) == 0)
13541 	kind = OMP_CLAUSE_DEPEND_INOUT;
13542       else if (strcmp ("out", p) == 0)
13543 	kind = OMP_CLAUSE_DEPEND_OUT;
13544       else if (strcmp ("source", p) == 0)
13545 	kind = OMP_CLAUSE_DEPEND_SOURCE;
13546       else if (strcmp ("sink", p) == 0)
13547 	kind = OMP_CLAUSE_DEPEND_SINK;
13548       else
13549 	goto invalid_kind;
13550     }
13551   else
13552     goto invalid_kind;
13553 
13554   c_parser_consume_token (parser);
13555 
13556   if (kind == OMP_CLAUSE_DEPEND_SOURCE)
13557     {
13558       c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
13559       OMP_CLAUSE_DEPEND_KIND (c) = kind;
13560       OMP_CLAUSE_DECL (c) = NULL_TREE;
13561       OMP_CLAUSE_CHAIN (c) = list;
13562       parens.skip_until_found_close (parser);
13563       return c;
13564     }
13565 
13566   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
13567     goto resync_fail;
13568 
13569   if (kind == OMP_CLAUSE_DEPEND_SINK)
13570     nl = c_parser_omp_clause_depend_sink (parser, clause_loc, list);
13571   else
13572     {
13573       nl = c_parser_omp_variable_list (parser, clause_loc,
13574 				       OMP_CLAUSE_DEPEND, list);
13575 
13576       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13577 	OMP_CLAUSE_DEPEND_KIND (c) = kind;
13578     }
13579 
13580   parens.skip_until_found_close (parser);
13581   return nl;
13582 
13583  invalid_kind:
13584   c_parser_error (parser, "invalid depend kind");
13585  resync_fail:
13586   parens.skip_until_found_close (parser);
13587   return list;
13588 }
13589 
13590 /* OpenMP 4.0:
13591    map ( map-kind: variable-list )
13592    map ( variable-list )
13593 
13594    map-kind:
13595      alloc | to | from | tofrom
13596 
13597    OpenMP 4.5:
13598    map-kind:
13599      alloc | to | from | tofrom | release | delete
13600 
13601    map ( always [,] map-kind: variable-list ) */
13602 
13603 static tree
13604 c_parser_omp_clause_map (c_parser *parser, tree list)
13605 {
13606   location_t clause_loc = c_parser_peek_token (parser)->location;
13607   enum gomp_map_kind kind = GOMP_MAP_TOFROM;
13608   int always = 0;
13609   enum c_id_kind always_id_kind = C_ID_NONE;
13610   location_t always_loc = UNKNOWN_LOCATION;
13611   tree always_id = NULL_TREE;
13612   tree nl, c;
13613 
13614   matching_parens parens;
13615   if (!parens.require_open (parser))
13616     return list;
13617 
13618   if (c_parser_next_token_is (parser, CPP_NAME))
13619     {
13620       c_token *tok = c_parser_peek_token (parser);
13621       const char *p = IDENTIFIER_POINTER (tok->value);
13622       always_id_kind = tok->id_kind;
13623       always_loc = tok->location;
13624       always_id = tok->value;
13625       if (strcmp ("always", p) == 0)
13626 	{
13627 	  c_token *sectok = c_parser_peek_2nd_token (parser);
13628 	  if (sectok->type == CPP_COMMA)
13629 	    {
13630 	      c_parser_consume_token (parser);
13631 	      c_parser_consume_token (parser);
13632 	      always = 2;
13633 	    }
13634 	  else if (sectok->type == CPP_NAME)
13635 	    {
13636 	      p = IDENTIFIER_POINTER (sectok->value);
13637 	      if (strcmp ("alloc", p) == 0
13638 		  || strcmp ("to", p) == 0
13639 		  || strcmp ("from", p) == 0
13640 		  || strcmp ("tofrom", p) == 0
13641 		  || strcmp ("release", p) == 0
13642 		  || strcmp ("delete", p) == 0)
13643 		{
13644 		  c_parser_consume_token (parser);
13645 		  always = 1;
13646 		}
13647 	    }
13648 	}
13649     }
13650 
13651   if (c_parser_next_token_is (parser, CPP_NAME)
13652       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
13653     {
13654       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13655       if (strcmp ("alloc", p) == 0)
13656 	kind = GOMP_MAP_ALLOC;
13657       else if (strcmp ("to", p) == 0)
13658 	kind = always ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO;
13659       else if (strcmp ("from", p) == 0)
13660 	kind = always ? GOMP_MAP_ALWAYS_FROM : GOMP_MAP_FROM;
13661       else if (strcmp ("tofrom", p) == 0)
13662 	kind = always ? GOMP_MAP_ALWAYS_TOFROM : GOMP_MAP_TOFROM;
13663       else if (strcmp ("release", p) == 0)
13664 	kind = GOMP_MAP_RELEASE;
13665       else if (strcmp ("delete", p) == 0)
13666 	kind = GOMP_MAP_DELETE;
13667       else
13668 	{
13669 	  c_parser_error (parser, "invalid map kind");
13670 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13671 				     "expected %<)%>");
13672 	  return list;
13673 	}
13674       c_parser_consume_token (parser);
13675       c_parser_consume_token (parser);
13676     }
13677   else if (always)
13678     {
13679       if (always_id_kind != C_ID_ID)
13680 	{
13681 	  c_parser_error (parser, "expected identifier");
13682 	  parens.skip_until_found_close (parser);
13683 	  return list;
13684 	}
13685 
13686       tree t = lookup_name (always_id);
13687       if (t == NULL_TREE)
13688 	{
13689 	  undeclared_variable (always_loc, always_id);
13690 	  t = error_mark_node;
13691 	}
13692       if (t != error_mark_node)
13693 	{
13694 	  tree u = build_omp_clause (clause_loc, OMP_CLAUSE_MAP);
13695 	  OMP_CLAUSE_DECL (u) = t;
13696 	  OMP_CLAUSE_CHAIN (u) = list;
13697 	  OMP_CLAUSE_SET_MAP_KIND (u, kind);
13698 	  list = u;
13699 	}
13700       if (always == 1)
13701 	{
13702 	  parens.skip_until_found_close (parser);
13703 	  return list;
13704 	}
13705     }
13706 
13707   nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
13708 
13709   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13710     OMP_CLAUSE_SET_MAP_KIND (c, kind);
13711 
13712   parens.skip_until_found_close (parser);
13713   return nl;
13714 }
13715 
13716 /* OpenMP 4.0:
13717    device ( expression ) */
13718 
13719 static tree
13720 c_parser_omp_clause_device (c_parser *parser, tree list)
13721 {
13722   location_t clause_loc = c_parser_peek_token (parser)->location;
13723   matching_parens parens;
13724   if (parens.require_open (parser))
13725     {
13726       location_t expr_loc = c_parser_peek_token (parser)->location;
13727       c_expr expr = c_parser_expr_no_commas (parser, NULL);
13728       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13729       tree c, t = expr.value;
13730       t = c_fully_fold (t, false, NULL);
13731 
13732       parens.skip_until_found_close (parser);
13733 
13734       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
13735 	{
13736 	  c_parser_error (parser, "expected integer expression");
13737 	  return list;
13738 	}
13739 
13740       check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
13741 
13742       c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
13743       OMP_CLAUSE_DEVICE_ID (c) = t;
13744       OMP_CLAUSE_CHAIN (c) = list;
13745       list = c;
13746     }
13747 
13748   return list;
13749 }
13750 
13751 /* OpenMP 4.0:
13752    dist_schedule ( static )
13753    dist_schedule ( static , expression ) */
13754 
13755 static tree
13756 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
13757 {
13758   tree c, t = NULL_TREE;
13759   location_t loc = c_parser_peek_token (parser)->location;
13760 
13761   matching_parens parens;
13762   if (!parens.require_open (parser))
13763     return list;
13764 
13765   if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
13766     {
13767       c_parser_error (parser, "invalid dist_schedule kind");
13768       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13769 				 "expected %<)%>");
13770       return list;
13771     }
13772 
13773   c_parser_consume_token (parser);
13774   if (c_parser_next_token_is (parser, CPP_COMMA))
13775     {
13776       c_parser_consume_token (parser);
13777 
13778       location_t expr_loc = c_parser_peek_token (parser)->location;
13779       c_expr expr = c_parser_expr_no_commas (parser, NULL);
13780       expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13781       t = expr.value;
13782       t = c_fully_fold (t, false, NULL);
13783       parens.skip_until_found_close (parser);
13784     }
13785   else
13786     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13787 			       "expected %<,%> or %<)%>");
13788 
13789   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
13790   if (t == error_mark_node)
13791     return list;
13792 
13793   c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
13794   OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
13795   OMP_CLAUSE_CHAIN (c) = list;
13796   return c;
13797 }
13798 
13799 /* OpenMP 4.0:
13800    proc_bind ( proc-bind-kind )
13801 
13802    proc-bind-kind:
13803      master | close | spread  */
13804 
13805 static tree
13806 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
13807 {
13808   location_t clause_loc = c_parser_peek_token (parser)->location;
13809   enum omp_clause_proc_bind_kind kind;
13810   tree c;
13811 
13812   matching_parens parens;
13813   if (!parens.require_open (parser))
13814     return list;
13815 
13816   if (c_parser_next_token_is (parser, CPP_NAME))
13817     {
13818       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13819       if (strcmp ("master", p) == 0)
13820 	kind = OMP_CLAUSE_PROC_BIND_MASTER;
13821       else if (strcmp ("close", p) == 0)
13822 	kind = OMP_CLAUSE_PROC_BIND_CLOSE;
13823       else if (strcmp ("spread", p) == 0)
13824 	kind = OMP_CLAUSE_PROC_BIND_SPREAD;
13825       else
13826 	goto invalid_kind;
13827     }
13828   else
13829     goto invalid_kind;
13830 
13831   c_parser_consume_token (parser);
13832   parens.skip_until_found_close (parser);
13833   c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
13834   OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
13835   OMP_CLAUSE_CHAIN (c) = list;
13836   return c;
13837 
13838  invalid_kind:
13839   c_parser_error (parser, "invalid proc_bind kind");
13840   parens.skip_until_found_close (parser);
13841   return list;
13842 }
13843 
13844 /* OpenMP 4.0:
13845    to ( variable-list ) */
13846 
13847 static tree
13848 c_parser_omp_clause_to (c_parser *parser, tree list)
13849 {
13850   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
13851 }
13852 
13853 /* OpenMP 4.0:
13854    from ( variable-list ) */
13855 
13856 static tree
13857 c_parser_omp_clause_from (c_parser *parser, tree list)
13858 {
13859   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
13860 }
13861 
13862 /* OpenMP 4.0:
13863    uniform ( variable-list ) */
13864 
13865 static tree
13866 c_parser_omp_clause_uniform (c_parser *parser, tree list)
13867 {
13868   /* The clauses location.  */
13869   location_t loc = c_parser_peek_token (parser)->location;
13870 
13871   matching_parens parens;
13872   if (parens.require_open (parser))
13873     {
13874       list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
13875 					 list);
13876       parens.skip_until_found_close (parser);
13877     }
13878   return list;
13879 }
13880 
13881 /* Parse all OpenACC clauses.  The set clauses allowed by the directive
13882    is a bitmask in MASK.  Return the list of clauses found.  */
13883 
13884 static tree
13885 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
13886 			   const char *where, bool finish_p = true)
13887 {
13888   tree clauses = NULL;
13889   bool first = true;
13890 
13891   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13892     {
13893       location_t here;
13894       pragma_omp_clause c_kind;
13895       const char *c_name;
13896       tree prev = clauses;
13897 
13898       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
13899 	c_parser_consume_token (parser);
13900 
13901       here = c_parser_peek_token (parser)->location;
13902       c_kind = c_parser_omp_clause_name (parser);
13903 
13904       switch (c_kind)
13905 	{
13906 	case PRAGMA_OACC_CLAUSE_ASYNC:
13907 	  clauses = c_parser_oacc_clause_async (parser, clauses);
13908 	  c_name = "async";
13909 	  break;
13910 	case PRAGMA_OACC_CLAUSE_AUTO:
13911 	  clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_AUTO,
13912 						clauses);
13913 	  c_name = "auto";
13914 	  break;
13915 	case PRAGMA_OACC_CLAUSE_COLLAPSE:
13916 	  clauses = c_parser_omp_clause_collapse (parser, clauses);
13917 	  c_name = "collapse";
13918 	  break;
13919 	case PRAGMA_OACC_CLAUSE_COPY:
13920 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13921 	  c_name = "copy";
13922 	  break;
13923 	case PRAGMA_OACC_CLAUSE_COPYIN:
13924 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13925 	  c_name = "copyin";
13926 	  break;
13927 	case PRAGMA_OACC_CLAUSE_COPYOUT:
13928 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13929 	  c_name = "copyout";
13930 	  break;
13931 	case PRAGMA_OACC_CLAUSE_CREATE:
13932 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13933 	  c_name = "create";
13934 	  break;
13935 	case PRAGMA_OACC_CLAUSE_DELETE:
13936 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13937 	  c_name = "delete";
13938 	  break;
13939 	case PRAGMA_OMP_CLAUSE_DEFAULT:
13940 	  clauses = c_parser_omp_clause_default (parser, clauses, true);
13941 	  c_name = "default";
13942 	  break;
13943 	case PRAGMA_OACC_CLAUSE_DEVICE:
13944 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13945 	  c_name = "device";
13946 	  break;
13947 	case PRAGMA_OACC_CLAUSE_DEVICEPTR:
13948 	  clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
13949 	  c_name = "deviceptr";
13950 	  break;
13951 	case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
13952 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13953 	  c_name = "device_resident";
13954 	  break;
13955 	case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
13956 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
13957 	  c_name = "firstprivate";
13958 	  break;
13959 	case PRAGMA_OACC_CLAUSE_GANG:
13960 	  c_name = "gang";
13961 	  clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_GANG,
13962 						c_name, clauses);
13963 	  break;
13964 	case PRAGMA_OACC_CLAUSE_HOST:
13965 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13966 	  c_name = "host";
13967 	  break;
13968 	case PRAGMA_OACC_CLAUSE_IF:
13969 	  clauses = c_parser_omp_clause_if (parser, clauses, false);
13970 	  c_name = "if";
13971 	  break;
13972 	case PRAGMA_OACC_CLAUSE_INDEPENDENT:
13973 	  clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_INDEPENDENT,
13974 						clauses);
13975 	  c_name = "independent";
13976 	  break;
13977 	case PRAGMA_OACC_CLAUSE_LINK:
13978 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13979 	  c_name = "link";
13980 	  break;
13981 	case PRAGMA_OACC_CLAUSE_NUM_GANGS:
13982 	  clauses = c_parser_oacc_single_int_clause (parser,
13983 						     OMP_CLAUSE_NUM_GANGS,
13984 						     clauses);
13985 	  c_name = "num_gangs";
13986 	  break;
13987 	case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
13988 	  clauses = c_parser_oacc_single_int_clause (parser,
13989 						     OMP_CLAUSE_NUM_WORKERS,
13990 						     clauses);
13991 	  c_name = "num_workers";
13992 	  break;
13993 	case PRAGMA_OACC_CLAUSE_PRESENT:
13994 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13995 	  c_name = "present";
13996 	  break;
13997 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
13998 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13999 	  c_name = "present_or_copy";
14000 	  break;
14001 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
14002 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14003 	  c_name = "present_or_copyin";
14004 	  break;
14005 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
14006 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14007 	  c_name = "present_or_copyout";
14008 	  break;
14009 	case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
14010 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14011 	  c_name = "present_or_create";
14012 	  break;
14013 	case PRAGMA_OACC_CLAUSE_PRIVATE:
14014 	  clauses = c_parser_omp_clause_private (parser, clauses);
14015 	  c_name = "private";
14016 	  break;
14017 	case PRAGMA_OACC_CLAUSE_REDUCTION:
14018 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
14019 	  c_name = "reduction";
14020 	  break;
14021 	case PRAGMA_OACC_CLAUSE_SELF:
14022 	  clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14023 	  c_name = "self";
14024 	  break;
14025 	case PRAGMA_OACC_CLAUSE_SEQ:
14026 	  clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ,
14027 						clauses);
14028 	  c_name = "seq";
14029 	  break;
14030 	case PRAGMA_OACC_CLAUSE_TILE:
14031 	  clauses = c_parser_oacc_clause_tile (parser, clauses);
14032 	  c_name = "tile";
14033 	  break;
14034 	case PRAGMA_OACC_CLAUSE_USE_DEVICE:
14035 	  clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
14036 	  c_name = "use_device";
14037 	  break;
14038 	case PRAGMA_OACC_CLAUSE_VECTOR:
14039 	  c_name = "vector";
14040 	  clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_VECTOR,
14041 						c_name,	clauses);
14042 	  break;
14043 	case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
14044 	  clauses = c_parser_oacc_single_int_clause (parser,
14045 						     OMP_CLAUSE_VECTOR_LENGTH,
14046 						     clauses);
14047 	  c_name = "vector_length";
14048 	  break;
14049 	case PRAGMA_OACC_CLAUSE_WAIT:
14050 	  clauses = c_parser_oacc_clause_wait (parser, clauses);
14051 	  c_name = "wait";
14052 	  break;
14053 	case PRAGMA_OACC_CLAUSE_WORKER:
14054 	  c_name = "worker";
14055 	  clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_WORKER,
14056 						c_name, clauses);
14057 	  break;
14058 	default:
14059 	  c_parser_error (parser, "expected %<#pragma acc%> clause");
14060 	  goto saw_error;
14061 	}
14062 
14063       first = false;
14064 
14065       if (((mask >> c_kind) & 1) == 0)
14066 	{
14067 	  /* Remove the invalid clause(s) from the list to avoid
14068 	     confusing the rest of the compiler.  */
14069 	  clauses = prev;
14070 	  error_at (here, "%qs is not valid for %qs", c_name, where);
14071 	}
14072     }
14073 
14074  saw_error:
14075   c_parser_skip_to_pragma_eol (parser);
14076 
14077   if (finish_p)
14078     return c_finish_omp_clauses (clauses, C_ORT_ACC);
14079 
14080   return clauses;
14081 }
14082 
14083 /* Parse all OpenMP clauses.  The set clauses allowed by the directive
14084    is a bitmask in MASK.  Return the list of clauses found.  */
14085 
14086 static tree
14087 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
14088 			  const char *where, bool finish_p = true)
14089 {
14090   tree clauses = NULL;
14091   bool first = true;
14092 
14093   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14094     {
14095       location_t here;
14096       pragma_omp_clause c_kind;
14097       const char *c_name;
14098       tree prev = clauses;
14099 
14100       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
14101 	c_parser_consume_token (parser);
14102 
14103       here = c_parser_peek_token (parser)->location;
14104       c_kind = c_parser_omp_clause_name (parser);
14105 
14106       switch (c_kind)
14107 	{
14108 	case PRAGMA_OMP_CLAUSE_COLLAPSE:
14109 	  clauses = c_parser_omp_clause_collapse (parser, clauses);
14110 	  c_name = "collapse";
14111 	  break;
14112 	case PRAGMA_OMP_CLAUSE_COPYIN:
14113 	  clauses = c_parser_omp_clause_copyin (parser, clauses);
14114 	  c_name = "copyin";
14115 	  break;
14116 	case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
14117 	  clauses = c_parser_omp_clause_copyprivate (parser, clauses);
14118 	  c_name = "copyprivate";
14119 	  break;
14120 	case PRAGMA_OMP_CLAUSE_DEFAULT:
14121 	  clauses = c_parser_omp_clause_default (parser, clauses, false);
14122 	  c_name = "default";
14123 	  break;
14124 	case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
14125 	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
14126 	  c_name = "firstprivate";
14127 	  break;
14128 	case PRAGMA_OMP_CLAUSE_FINAL:
14129 	  clauses = c_parser_omp_clause_final (parser, clauses);
14130 	  c_name = "final";
14131 	  break;
14132 	case PRAGMA_OMP_CLAUSE_GRAINSIZE:
14133 	  clauses = c_parser_omp_clause_grainsize (parser, clauses);
14134 	  c_name = "grainsize";
14135 	  break;
14136 	case PRAGMA_OMP_CLAUSE_HINT:
14137 	  clauses = c_parser_omp_clause_hint (parser, clauses);
14138 	  c_name = "hint";
14139 	  break;
14140 	case PRAGMA_OMP_CLAUSE_DEFAULTMAP:
14141 	  clauses = c_parser_omp_clause_defaultmap (parser, clauses);
14142 	  c_name = "defaultmap";
14143 	  break;
14144 	case PRAGMA_OMP_CLAUSE_IF:
14145 	  clauses = c_parser_omp_clause_if (parser, clauses, true);
14146 	  c_name = "if";
14147 	  break;
14148 	case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
14149 	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
14150 	  c_name = "lastprivate";
14151 	  break;
14152 	case PRAGMA_OMP_CLAUSE_MERGEABLE:
14153 	  clauses = c_parser_omp_clause_mergeable (parser, clauses);
14154 	  c_name = "mergeable";
14155 	  break;
14156 	case PRAGMA_OMP_CLAUSE_NOWAIT:
14157 	  clauses = c_parser_omp_clause_nowait (parser, clauses);
14158 	  c_name = "nowait";
14159 	  break;
14160 	case PRAGMA_OMP_CLAUSE_NUM_TASKS:
14161 	  clauses = c_parser_omp_clause_num_tasks (parser, clauses);
14162 	  c_name = "num_tasks";
14163 	  break;
14164 	case PRAGMA_OMP_CLAUSE_NUM_THREADS:
14165 	  clauses = c_parser_omp_clause_num_threads (parser, clauses);
14166 	  c_name = "num_threads";
14167 	  break;
14168 	case PRAGMA_OMP_CLAUSE_ORDERED:
14169 	  clauses = c_parser_omp_clause_ordered (parser, clauses);
14170 	  c_name = "ordered";
14171 	  break;
14172 	case PRAGMA_OMP_CLAUSE_PRIORITY:
14173 	  clauses = c_parser_omp_clause_priority (parser, clauses);
14174 	  c_name = "priority";
14175 	  break;
14176 	case PRAGMA_OMP_CLAUSE_PRIVATE:
14177 	  clauses = c_parser_omp_clause_private (parser, clauses);
14178 	  c_name = "private";
14179 	  break;
14180 	case PRAGMA_OMP_CLAUSE_REDUCTION:
14181 	  clauses = c_parser_omp_clause_reduction (parser, clauses);
14182 	  c_name = "reduction";
14183 	  break;
14184 	case PRAGMA_OMP_CLAUSE_SCHEDULE:
14185 	  clauses = c_parser_omp_clause_schedule (parser, clauses);
14186 	  c_name = "schedule";
14187 	  break;
14188 	case PRAGMA_OMP_CLAUSE_SHARED:
14189 	  clauses = c_parser_omp_clause_shared (parser, clauses);
14190 	  c_name = "shared";
14191 	  break;
14192 	case PRAGMA_OMP_CLAUSE_UNTIED:
14193 	  clauses = c_parser_omp_clause_untied (parser, clauses);
14194 	  c_name = "untied";
14195 	  break;
14196 	case PRAGMA_OMP_CLAUSE_INBRANCH:
14197 	  clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
14198 						clauses);
14199 	  c_name = "inbranch";
14200 	  break;
14201 	case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
14202 	  clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
14203 						clauses);
14204 	  c_name = "notinbranch";
14205 	  break;
14206 	case PRAGMA_OMP_CLAUSE_PARALLEL:
14207 	  clauses
14208 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
14209 					      clauses);
14210 	  c_name = "parallel";
14211 	  if (!first)
14212 	    {
14213 	     clause_not_first:
14214 	      error_at (here, "%qs must be the first clause of %qs",
14215 			c_name, where);
14216 	      clauses = prev;
14217 	    }
14218 	  break;
14219 	case PRAGMA_OMP_CLAUSE_FOR:
14220 	  clauses
14221 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
14222 					      clauses);
14223 	  c_name = "for";
14224 	  if (!first)
14225 	    goto clause_not_first;
14226 	  break;
14227 	case PRAGMA_OMP_CLAUSE_SECTIONS:
14228 	  clauses
14229 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
14230 					      clauses);
14231 	  c_name = "sections";
14232 	  if (!first)
14233 	    goto clause_not_first;
14234 	  break;
14235 	case PRAGMA_OMP_CLAUSE_TASKGROUP:
14236 	  clauses
14237 	    = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
14238 					      clauses);
14239 	  c_name = "taskgroup";
14240 	  if (!first)
14241 	    goto clause_not_first;
14242 	  break;
14243 	case PRAGMA_OMP_CLAUSE_LINK:
14244 	  clauses
14245 	    = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses);
14246 	  c_name = "link";
14247 	  break;
14248 	case PRAGMA_OMP_CLAUSE_TO:
14249 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0)
14250 	    clauses
14251 	      = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
14252 					      clauses);
14253 	  else
14254 	    clauses = c_parser_omp_clause_to (parser, clauses);
14255 	  c_name = "to";
14256 	  break;
14257 	case PRAGMA_OMP_CLAUSE_FROM:
14258 	  clauses = c_parser_omp_clause_from (parser, clauses);
14259 	  c_name = "from";
14260 	  break;
14261 	case PRAGMA_OMP_CLAUSE_UNIFORM:
14262 	  clauses = c_parser_omp_clause_uniform (parser, clauses);
14263 	  c_name = "uniform";
14264 	  break;
14265 	case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
14266 	  clauses = c_parser_omp_clause_num_teams (parser, clauses);
14267 	  c_name = "num_teams";
14268 	  break;
14269 	case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
14270 	  clauses = c_parser_omp_clause_thread_limit (parser, clauses);
14271 	  c_name = "thread_limit";
14272 	  break;
14273 	case PRAGMA_OMP_CLAUSE_ALIGNED:
14274 	  clauses = c_parser_omp_clause_aligned (parser, clauses);
14275 	  c_name = "aligned";
14276 	  break;
14277 	case PRAGMA_OMP_CLAUSE_LINEAR:
14278 	  clauses = c_parser_omp_clause_linear (parser, clauses);
14279 	  c_name = "linear";
14280 	  break;
14281 	case PRAGMA_OMP_CLAUSE_DEPEND:
14282 	  clauses = c_parser_omp_clause_depend (parser, clauses);
14283 	  c_name = "depend";
14284 	  break;
14285 	case PRAGMA_OMP_CLAUSE_MAP:
14286 	  clauses = c_parser_omp_clause_map (parser, clauses);
14287 	  c_name = "map";
14288 	  break;
14289 	case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR:
14290 	  clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
14291 	  c_name = "use_device_ptr";
14292 	  break;
14293 	case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR:
14294 	  clauses = c_parser_omp_clause_is_device_ptr (parser, clauses);
14295 	  c_name = "is_device_ptr";
14296 	  break;
14297 	case PRAGMA_OMP_CLAUSE_DEVICE:
14298 	  clauses = c_parser_omp_clause_device (parser, clauses);
14299 	  c_name = "device";
14300 	  break;
14301 	case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
14302 	  clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
14303 	  c_name = "dist_schedule";
14304 	  break;
14305 	case PRAGMA_OMP_CLAUSE_PROC_BIND:
14306 	  clauses = c_parser_omp_clause_proc_bind (parser, clauses);
14307 	  c_name = "proc_bind";
14308 	  break;
14309 	case PRAGMA_OMP_CLAUSE_SAFELEN:
14310 	  clauses = c_parser_omp_clause_safelen (parser, clauses);
14311 	  c_name = "safelen";
14312 	  break;
14313 	case PRAGMA_OMP_CLAUSE_SIMDLEN:
14314 	  clauses = c_parser_omp_clause_simdlen (parser, clauses);
14315 	  c_name = "simdlen";
14316 	  break;
14317 	case PRAGMA_OMP_CLAUSE_NOGROUP:
14318 	  clauses = c_parser_omp_clause_nogroup (parser, clauses);
14319 	  c_name = "nogroup";
14320 	  break;
14321 	case PRAGMA_OMP_CLAUSE_THREADS:
14322 	  clauses
14323 	    = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS,
14324 					       clauses);
14325 	  c_name = "threads";
14326 	  break;
14327 	case PRAGMA_OMP_CLAUSE_SIMD:
14328 	  clauses
14329 	    = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD,
14330 					       clauses);
14331 	  c_name = "simd";
14332 	  break;
14333 	default:
14334 	  c_parser_error (parser, "expected %<#pragma omp%> clause");
14335 	  goto saw_error;
14336 	}
14337 
14338       first = false;
14339 
14340       if (((mask >> c_kind) & 1) == 0)
14341 	{
14342 	  /* Remove the invalid clause(s) from the list to avoid
14343 	     confusing the rest of the compiler.  */
14344 	  clauses = prev;
14345 	  error_at (here, "%qs is not valid for %qs", c_name, where);
14346 	}
14347     }
14348 
14349  saw_error:
14350   c_parser_skip_to_pragma_eol (parser);
14351 
14352   if (finish_p)
14353     {
14354       if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0)
14355 	return c_finish_omp_clauses (clauses, C_ORT_OMP_DECLARE_SIMD);
14356       return c_finish_omp_clauses (clauses, C_ORT_OMP);
14357     }
14358 
14359   return clauses;
14360 }
14361 
14362 /* OpenACC 2.0, OpenMP 2.5:
14363    structured-block:
14364      statement
14365 
14366    In practice, we're also interested in adding the statement to an
14367    outer node.  So it is convenient if we work around the fact that
14368    c_parser_statement calls add_stmt.  */
14369 
14370 static tree
14371 c_parser_omp_structured_block (c_parser *parser, bool *if_p)
14372 {
14373   tree stmt = push_stmt_list ();
14374   c_parser_statement (parser, if_p);
14375   return pop_stmt_list (stmt);
14376 }
14377 
14378 /* OpenACC 2.0:
14379    # pragma acc cache (variable-list) new-line
14380 
14381    LOC is the location of the #pragma token.
14382 */
14383 
14384 static tree
14385 c_parser_oacc_cache (location_t loc, c_parser *parser)
14386 {
14387   tree stmt, clauses;
14388 
14389   clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
14390   clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
14391 
14392   c_parser_skip_to_pragma_eol (parser);
14393 
14394   stmt = make_node (OACC_CACHE);
14395   TREE_TYPE (stmt) = void_type_node;
14396   OACC_CACHE_CLAUSES (stmt) = clauses;
14397   SET_EXPR_LOCATION (stmt, loc);
14398   add_stmt (stmt);
14399 
14400   return stmt;
14401 }
14402 
14403 /* OpenACC 2.0:
14404    # pragma acc data oacc-data-clause[optseq] new-line
14405      structured-block
14406 
14407    LOC is the location of the #pragma token.
14408 */
14409 
14410 #define OACC_DATA_CLAUSE_MASK						\
14411 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
14412 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
14413 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
14414 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
14415 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
14416 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14417 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
14418 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
14419 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
14420 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
14421 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14422 
14423 static tree
14424 c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p)
14425 {
14426   tree stmt, clauses, block;
14427 
14428   clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
14429 				       "#pragma acc data");
14430 
14431   block = c_begin_omp_parallel ();
14432   add_stmt (c_parser_omp_structured_block (parser, if_p));
14433 
14434   stmt = c_finish_oacc_data (loc, clauses, block);
14435 
14436   return stmt;
14437 }
14438 
14439 /* OpenACC 2.0:
14440    # pragma acc declare oacc-data-clause[optseq] new-line
14441 */
14442 
14443 #define OACC_DECLARE_CLAUSE_MASK					\
14444 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
14445 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
14446 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
14447 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
14448 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
14449 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT)	\
14450 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK)		\
14451 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
14452 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
14453 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
14454 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
14455 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14456 
14457 static void
14458 c_parser_oacc_declare (c_parser *parser)
14459 {
14460   location_t pragma_loc = c_parser_peek_token (parser)->location;
14461   tree clauses, stmt, t, decl;
14462 
14463   bool error = false;
14464 
14465   c_parser_consume_pragma (parser);
14466 
14467   clauses = c_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK,
14468 				       "#pragma acc declare");
14469   if (!clauses)
14470     {
14471       error_at (pragma_loc,
14472 		"no valid clauses specified in %<#pragma acc declare%>");
14473       return;
14474     }
14475 
14476   for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t))
14477     {
14478       location_t loc = OMP_CLAUSE_LOCATION (t);
14479       decl = OMP_CLAUSE_DECL (t);
14480       if (!DECL_P (decl))
14481 	{
14482 	  error_at (loc, "array section in %<#pragma acc declare%>");
14483 	  error = true;
14484 	  continue;
14485 	}
14486 
14487       switch (OMP_CLAUSE_MAP_KIND (t))
14488 	{
14489 	case GOMP_MAP_FIRSTPRIVATE_POINTER:
14490 	case GOMP_MAP_FORCE_ALLOC:
14491 	case GOMP_MAP_FORCE_TO:
14492 	case GOMP_MAP_FORCE_DEVICEPTR:
14493 	case GOMP_MAP_DEVICE_RESIDENT:
14494 	  break;
14495 
14496 	case GOMP_MAP_LINK:
14497 	  if (!global_bindings_p ()
14498 	      && (TREE_STATIC (decl)
14499 	       || !DECL_EXTERNAL (decl)))
14500 	    {
14501 	      error_at (loc,
14502 			"%qD must be a global variable in "
14503 			"%<#pragma acc declare link%>",
14504 			decl);
14505 	      error = true;
14506 	      continue;
14507 	    }
14508 	  break;
14509 
14510 	default:
14511 	  if (global_bindings_p ())
14512 	    {
14513 	      error_at (loc, "invalid OpenACC clause at file scope");
14514 	      error = true;
14515 	      continue;
14516 	    }
14517 	  if (DECL_EXTERNAL (decl))
14518 	    {
14519 	      error_at (loc,
14520 			"invalid use of %<extern%> variable %qD "
14521 			"in %<#pragma acc declare%>", decl);
14522 	      error = true;
14523 	      continue;
14524 	    }
14525 	  else if (TREE_PUBLIC (decl))
14526 	    {
14527 	      error_at (loc,
14528 			"invalid use of %<global%> variable %qD "
14529 			"in %<#pragma acc declare%>", decl);
14530 	      error = true;
14531 	      continue;
14532 	    }
14533 	  break;
14534 	}
14535 
14536       if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))
14537 	  || lookup_attribute ("omp declare target link",
14538 			       DECL_ATTRIBUTES (decl)))
14539 	{
14540 	  error_at (loc, "variable %qD used more than once with "
14541 		    "%<#pragma acc declare%>", decl);
14542 	  error = true;
14543 	  continue;
14544 	}
14545 
14546       if (!error)
14547 	{
14548 	  tree id;
14549 
14550 	  if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK)
14551 	    id = get_identifier ("omp declare target link");
14552 	  else
14553 	    id = get_identifier ("omp declare target");
14554 
14555 	  DECL_ATTRIBUTES (decl)
14556 			   = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
14557 
14558 	  if (global_bindings_p ())
14559 	    {
14560 	      symtab_node *node = symtab_node::get (decl);
14561 	      if (node != NULL)
14562 		{
14563 		  node->offloadable = 1;
14564 		  if (ENABLE_OFFLOADING)
14565 		    {
14566 		      g->have_offload = true;
14567 		      if (is_a <varpool_node *> (node))
14568 			vec_safe_push (offload_vars, decl);
14569 		    }
14570 		}
14571 	    }
14572 	}
14573     }
14574 
14575   if (error || global_bindings_p ())
14576     return;
14577 
14578   stmt = make_node (OACC_DECLARE);
14579   TREE_TYPE (stmt) = void_type_node;
14580   OACC_DECLARE_CLAUSES (stmt) = clauses;
14581   SET_EXPR_LOCATION (stmt, pragma_loc);
14582 
14583   add_stmt (stmt);
14584 
14585   return;
14586 }
14587 
14588 /* OpenACC 2.0:
14589    # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14590 
14591    or
14592 
14593    # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14594 
14595 
14596    LOC is the location of the #pragma token.
14597 */
14598 
14599 #define OACC_ENTER_DATA_CLAUSE_MASK					\
14600 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14601 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
14602 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
14603 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
14604 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
14605 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
14606 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14607 
14608 #define OACC_EXIT_DATA_CLAUSE_MASK					\
14609 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14610 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
14611 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
14612 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) 		\
14613 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14614 
14615 static void
14616 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
14617 {
14618   location_t loc = c_parser_peek_token (parser)->location;
14619   tree clauses, stmt;
14620   const char *p = "";
14621 
14622   c_parser_consume_pragma (parser);
14623 
14624   if (c_parser_next_token_is (parser, CPP_NAME))
14625     {
14626       p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14627       c_parser_consume_token (parser);
14628     }
14629 
14630   if (strcmp (p, "data") != 0)
14631     {
14632       error_at (loc, "expected %<data%> after %<#pragma acc %s%>",
14633 		enter ? "enter" : "exit");
14634       parser->error = true;
14635       c_parser_skip_to_pragma_eol (parser);
14636       return;
14637     }
14638 
14639   if (enter)
14640     clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
14641 					 "#pragma acc enter data");
14642   else
14643     clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
14644 					 "#pragma acc exit data");
14645 
14646   if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
14647     {
14648       error_at (loc, "%<#pragma acc %s data%> has no data movement clause",
14649 		enter ? "enter" : "exit");
14650       return;
14651     }
14652 
14653   stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);
14654   TREE_TYPE (stmt) = void_type_node;
14655   OMP_STANDALONE_CLAUSES (stmt) = clauses;
14656   SET_EXPR_LOCATION (stmt, loc);
14657   add_stmt (stmt);
14658 }
14659 
14660 
14661 /* OpenACC 2.0:
14662    # pragma acc host_data oacc-data-clause[optseq] new-line
14663      structured-block
14664 */
14665 
14666 #define OACC_HOST_DATA_CLAUSE_MASK					\
14667 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14668 
14669 static tree
14670 c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p)
14671 {
14672   tree stmt, clauses, block;
14673 
14674   clauses = c_parser_oacc_all_clauses (parser, OACC_HOST_DATA_CLAUSE_MASK,
14675 				       "#pragma acc host_data");
14676 
14677   block = c_begin_omp_parallel ();
14678   add_stmt (c_parser_omp_structured_block (parser, if_p));
14679   stmt = c_finish_oacc_host_data (loc, clauses, block);
14680   return stmt;
14681 }
14682 
14683 
14684 /* OpenACC 2.0:
14685 
14686    # pragma acc loop oacc-loop-clause[optseq] new-line
14687      structured-block
14688 
14689    LOC is the location of the #pragma token.
14690 */
14691 
14692 #define OACC_LOOP_CLAUSE_MASK						\
14693 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE)		\
14694 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE)		\
14695 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION)		\
14696 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG)		\
14697 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER)		\
14698 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR)		\
14699 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO)		\
14700 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) 	\
14701 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ)			\
14702 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14703 static tree
14704 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name,
14705 		    omp_clause_mask mask, tree *cclauses, bool *if_p)
14706 {
14707   bool is_parallel = ((mask >> PRAGMA_OACC_CLAUSE_REDUCTION) & 1) == 1;
14708 
14709   strcat (p_name, " loop");
14710   mask |= OACC_LOOP_CLAUSE_MASK;
14711 
14712   tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name,
14713 					    cclauses == NULL);
14714   if (cclauses)
14715     {
14716       clauses = c_oacc_split_loop_clauses (clauses, cclauses, is_parallel);
14717       if (*cclauses)
14718 	*cclauses = c_finish_omp_clauses (*cclauses, C_ORT_ACC);
14719       if (clauses)
14720 	clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
14721     }
14722 
14723   tree block = c_begin_compound_stmt (true);
14724   tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL,
14725 				     if_p);
14726   block = c_end_compound_stmt (loc, block, true);
14727   add_stmt (block);
14728 
14729   return stmt;
14730 }
14731 
14732 /* OpenACC 2.0:
14733    # pragma acc kernels oacc-kernels-clause[optseq] new-line
14734      structured-block
14735 
14736    or
14737 
14738    # pragma acc parallel oacc-parallel-clause[optseq] new-line
14739      structured-block
14740 
14741    LOC is the location of the #pragma token.
14742 */
14743 
14744 #define OACC_KERNELS_CLAUSE_MASK					\
14745 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
14746 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
14747 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
14748 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
14749 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
14750 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT)		\
14751 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
14752 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14753 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS)		\
14754 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS)		\
14755 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
14756 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
14757 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
14758 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
14759 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
14760 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH)	\
14761 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14762 
14763 #define OACC_PARALLEL_CLAUSE_MASK					\
14764 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
14765 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)		\
14766 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)		\
14767 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)		\
14768 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)		\
14769 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT)		\
14770 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)		\
14771 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
14772 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE)		\
14773 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE)	\
14774 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS)		\
14775 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS)		\
14776 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)		\
14777 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)	\
14778 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)	\
14779 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)	\
14780 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)	\
14781 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION)		\
14782 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH)	\
14783 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14784 
14785 static tree
14786 c_parser_oacc_kernels_parallel (location_t loc, c_parser *parser,
14787 				enum pragma_kind p_kind, char *p_name,
14788 				bool *if_p)
14789 {
14790   omp_clause_mask mask;
14791   enum tree_code code;
14792   switch (p_kind)
14793     {
14794     case PRAGMA_OACC_KERNELS:
14795       strcat (p_name, " kernels");
14796       mask = OACC_KERNELS_CLAUSE_MASK;
14797       code = OACC_KERNELS;
14798       break;
14799     case PRAGMA_OACC_PARALLEL:
14800       strcat (p_name, " parallel");
14801       mask = OACC_PARALLEL_CLAUSE_MASK;
14802       code = OACC_PARALLEL;
14803       break;
14804     default:
14805       gcc_unreachable ();
14806     }
14807 
14808   if (c_parser_next_token_is (parser, CPP_NAME))
14809     {
14810       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14811       if (strcmp (p, "loop") == 0)
14812 	{
14813 	  c_parser_consume_token (parser);
14814 	  tree block = c_begin_omp_parallel ();
14815 	  tree clauses;
14816 	  c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p);
14817 	  return c_finish_omp_construct (loc, code, block, clauses);
14818 	}
14819     }
14820 
14821   tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name);
14822 
14823   tree block = c_begin_omp_parallel ();
14824   add_stmt (c_parser_omp_structured_block (parser, if_p));
14825 
14826   return c_finish_omp_construct (loc, code, block, clauses);
14827 }
14828 
14829 /* OpenACC 2.0:
14830    # pragma acc routine oacc-routine-clause[optseq] new-line
14831      function-definition
14832 
14833    # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14834 */
14835 
14836 #define OACC_ROUTINE_CLAUSE_MASK					\
14837 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG)		\
14838 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER)		\
14839 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR)		\
14840 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14841 
14842 /* Parse an OpenACC routine directive.  For named directives, we apply
14843    immediately to the named function.  For unnamed ones we then parse
14844    a declaration or definition, which must be for a function.  */
14845 
14846 static void
14847 c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
14848 {
14849   gcc_checking_assert (context == pragma_external);
14850 
14851   oacc_routine_data data;
14852   data.error_seen = false;
14853   data.fndecl_seen = false;
14854   data.clauses = NULL_TREE;
14855   data.loc = c_parser_peek_token (parser)->location;
14856 
14857   c_parser_consume_pragma (parser);
14858 
14859   /* Look for optional '( name )'.  */
14860   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14861     {
14862       c_parser_consume_token (parser); /* '(' */
14863 
14864       tree decl = NULL_TREE;
14865       c_token *name_token = c_parser_peek_token (parser);
14866       location_t name_loc = name_token->location;
14867       if (name_token->type == CPP_NAME
14868 	  && (name_token->id_kind == C_ID_ID
14869 	      || name_token->id_kind == C_ID_TYPENAME))
14870 	{
14871 	  decl = lookup_name (name_token->value);
14872 	  if (!decl)
14873 	    error_at (name_loc,
14874 		      "%qE has not been declared", name_token->value);
14875 	  c_parser_consume_token (parser);
14876 	}
14877       else
14878 	c_parser_error (parser, "expected function name");
14879 
14880       if (!decl
14881 	  || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14882 	{
14883 	  c_parser_skip_to_pragma_eol (parser, false);
14884 	  return;
14885 	}
14886 
14887       data.clauses
14888 	= c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
14889 				     "#pragma acc routine");
14890 
14891       if (TREE_CODE (decl) != FUNCTION_DECL)
14892 	{
14893 	  error_at (name_loc, "%qD does not refer to a function", decl);
14894 	  return;
14895 	}
14896 
14897       c_finish_oacc_routine (&data, decl, false);
14898     }
14899   else /* No optional '( name )'.  */
14900     {
14901       data.clauses
14902 	= c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
14903 				     "#pragma acc routine");
14904 
14905       /* Emit a helpful diagnostic if there's another pragma following this
14906 	 one.  Also don't allow a static assertion declaration, as in the
14907 	 following we'll just parse a *single* "declaration or function
14908 	 definition", and the static assertion counts an one.  */
14909       if (c_parser_next_token_is (parser, CPP_PRAGMA)
14910 	  || c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
14911 	{
14912 	  error_at (data.loc,
14913 		    "%<#pragma acc routine%> not immediately followed by"
14914 		    " function declaration or definition");
14915 	  /* ..., and then just keep going.  */
14916 	  return;
14917 	}
14918 
14919       /* We only have to consider the pragma_external case here.  */
14920       if (c_parser_next_token_is (parser, CPP_KEYWORD)
14921 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14922 	{
14923 	  int ext = disable_extension_diagnostics ();
14924 	  do
14925 	    c_parser_consume_token (parser);
14926 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
14927 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14928 	  c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14929 					 NULL, vNULL, &data);
14930 	  restore_extension_diagnostics (ext);
14931 	}
14932       else
14933 	c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14934 				       NULL, vNULL, &data);
14935     }
14936 }
14937 
14938 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14939    IS_DEFN is true if we're applying it to the definition.  */
14940 
14941 static void
14942 c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl,
14943 		       bool is_defn)
14944 {
14945   /* Keep going if we're in error reporting mode.  */
14946   if (data->error_seen
14947       || fndecl == error_mark_node)
14948     return;
14949 
14950   if (data->fndecl_seen)
14951     {
14952       error_at (data->loc,
14953 		"%<#pragma acc routine%> not immediately followed by"
14954 		" a single function declaration or definition");
14955       data->error_seen = true;
14956       return;
14957     }
14958   if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
14959     {
14960       error_at (data->loc,
14961 		"%<#pragma acc routine%> not immediately followed by"
14962 		" function declaration or definition");
14963       data->error_seen = true;
14964       return;
14965     }
14966 
14967   if (oacc_get_fn_attrib (fndecl))
14968     {
14969       error_at (data->loc,
14970 		"%<#pragma acc routine%> already applied to %qD", fndecl);
14971       data->error_seen = true;
14972       return;
14973     }
14974 
14975   if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
14976     {
14977       error_at (data->loc,
14978 		TREE_USED (fndecl)
14979 		? G_("%<#pragma acc routine%> must be applied before use")
14980 		: G_("%<#pragma acc routine%> must be applied before "
14981 		     "definition"));
14982       data->error_seen = true;
14983       return;
14984     }
14985 
14986   /* Process the routine's dimension clauses.  */
14987   tree dims = oacc_build_routine_dims (data->clauses);
14988   oacc_replace_fn_attrib (fndecl, dims);
14989 
14990   /* Add an "omp declare target" attribute.  */
14991   DECL_ATTRIBUTES (fndecl)
14992     = tree_cons (get_identifier ("omp declare target"),
14993 		 NULL_TREE, DECL_ATTRIBUTES (fndecl));
14994 
14995   /* Remember that we've used this "#pragma acc routine".  */
14996   data->fndecl_seen = true;
14997 }
14998 
14999 /* OpenACC 2.0:
15000    # pragma acc update oacc-update-clause[optseq] new-line
15001 */
15002 
15003 #define OACC_UPDATE_CLAUSE_MASK						\
15004 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)		\
15005 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE)		\
15006 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)		\
15007 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
15008 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF)		\
15009 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15010 
15011 static void
15012 c_parser_oacc_update (c_parser *parser)
15013 {
15014   location_t loc = c_parser_peek_token (parser)->location;
15015 
15016   c_parser_consume_pragma (parser);
15017 
15018   tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
15019 					    "#pragma acc update");
15020   if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
15021     {
15022       error_at (loc,
15023 		"%<#pragma acc update%> must contain at least one "
15024 		"%<device%> or %<host%> or %<self%> clause");
15025       return;
15026     }
15027 
15028   if (parser->error)
15029     return;
15030 
15031   tree stmt = make_node (OACC_UPDATE);
15032   TREE_TYPE (stmt) = void_type_node;
15033   OACC_UPDATE_CLAUSES (stmt) = clauses;
15034   SET_EXPR_LOCATION (stmt, loc);
15035   add_stmt (stmt);
15036 }
15037 
15038 /* OpenACC 2.0:
15039    # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15040 
15041    LOC is the location of the #pragma token.
15042 */
15043 
15044 #define OACC_WAIT_CLAUSE_MASK						\
15045 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15046 
15047 static tree
15048 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
15049 {
15050   tree clauses, list = NULL_TREE, stmt = NULL_TREE;
15051 
15052   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
15053     list = c_parser_oacc_wait_list (parser, loc, list);
15054 
15055   strcpy (p_name, " wait");
15056   clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
15057   stmt = c_finish_oacc_wait (loc, list, clauses);
15058   add_stmt (stmt);
15059 
15060   return stmt;
15061 }
15062 
15063 /* OpenMP 2.5:
15064    # pragma omp atomic new-line
15065      expression-stmt
15066 
15067    expression-stmt:
15068      x binop= expr | x++ | ++x | x-- | --x
15069    binop:
15070      +, *, -, /, &, ^, |, <<, >>
15071 
15072   where x is an lvalue expression with scalar type.
15073 
15074    OpenMP 3.1:
15075    # pragma omp atomic new-line
15076      update-stmt
15077 
15078    # pragma omp atomic read new-line
15079      read-stmt
15080 
15081    # pragma omp atomic write new-line
15082      write-stmt
15083 
15084    # pragma omp atomic update new-line
15085      update-stmt
15086 
15087    # pragma omp atomic capture new-line
15088      capture-stmt
15089 
15090    # pragma omp atomic capture new-line
15091      capture-block
15092 
15093    read-stmt:
15094      v = x
15095    write-stmt:
15096      x = expr
15097    update-stmt:
15098      expression-stmt | x = x binop expr
15099    capture-stmt:
15100      v = expression-stmt
15101    capture-block:
15102      { v = x; update-stmt; } | { update-stmt; v = x; }
15103 
15104    OpenMP 4.0:
15105    update-stmt:
15106      expression-stmt | x = x binop expr | x = expr binop x
15107    capture-stmt:
15108      v = update-stmt
15109    capture-block:
15110      { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15111 
15112   where x and v are lvalue expressions with scalar type.
15113 
15114   LOC is the location of the #pragma token.  */
15115 
15116 static void
15117 c_parser_omp_atomic (location_t loc, c_parser *parser)
15118 {
15119   tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
15120   tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
15121   tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
15122   enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
15123   struct c_expr expr;
15124   location_t eloc;
15125   bool structured_block = false;
15126   bool swapped = false;
15127   bool seq_cst = false;
15128   bool non_lvalue_p;
15129 
15130   if (c_parser_next_token_is (parser, CPP_NAME))
15131     {
15132       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15133       if (!strcmp (p, "seq_cst"))
15134 	{
15135 	  seq_cst = true;
15136 	  c_parser_consume_token (parser);
15137 	  if (c_parser_next_token_is (parser, CPP_COMMA)
15138 	      && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
15139 	    c_parser_consume_token (parser);
15140 	}
15141     }
15142   if (c_parser_next_token_is (parser, CPP_NAME))
15143     {
15144       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15145 
15146       if (!strcmp (p, "read"))
15147 	code = OMP_ATOMIC_READ;
15148       else if (!strcmp (p, "write"))
15149 	code = NOP_EXPR;
15150       else if (!strcmp (p, "update"))
15151 	code = OMP_ATOMIC;
15152       else if (!strcmp (p, "capture"))
15153 	code = OMP_ATOMIC_CAPTURE_NEW;
15154       else
15155 	p = NULL;
15156       if (p)
15157 	c_parser_consume_token (parser);
15158     }
15159   if (!seq_cst)
15160     {
15161       if (c_parser_next_token_is (parser, CPP_COMMA)
15162 	  && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
15163 	c_parser_consume_token (parser);
15164 
15165       if (c_parser_next_token_is (parser, CPP_NAME))
15166 	{
15167 	  const char *p
15168 	    = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15169 	  if (!strcmp (p, "seq_cst"))
15170 	    {
15171 	      seq_cst = true;
15172 	      c_parser_consume_token (parser);
15173 	    }
15174 	}
15175     }
15176   c_parser_skip_to_pragma_eol (parser);
15177 
15178   switch (code)
15179     {
15180     case OMP_ATOMIC_READ:
15181     case NOP_EXPR: /* atomic write */
15182       v = c_parser_cast_expression (parser, NULL).value;
15183       non_lvalue_p = !lvalue_p (v);
15184       v = c_fully_fold (v, false, NULL, true);
15185       if (v == error_mark_node)
15186 	goto saw_error;
15187       if (non_lvalue_p)
15188 	v = non_lvalue (v);
15189       loc = c_parser_peek_token (parser)->location;
15190       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
15191 	goto saw_error;
15192       if (code == NOP_EXPR)
15193 	{
15194 	  lhs = c_parser_expression (parser).value;
15195 	  lhs = c_fully_fold (lhs, false, NULL);
15196 	  if (lhs == error_mark_node)
15197 	    goto saw_error;
15198 	}
15199       else
15200 	{
15201 	  lhs = c_parser_cast_expression (parser, NULL).value;
15202 	  non_lvalue_p = !lvalue_p (lhs);
15203 	  lhs = c_fully_fold (lhs, false, NULL, true);
15204 	  if (lhs == error_mark_node)
15205 	    goto saw_error;
15206 	  if (non_lvalue_p)
15207 	    lhs = non_lvalue (lhs);
15208 	}
15209       if (code == NOP_EXPR)
15210 	{
15211 	  /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15212 	     opcode.  */
15213 	  code = OMP_ATOMIC;
15214 	  rhs = lhs;
15215 	  lhs = v;
15216 	  v = NULL_TREE;
15217 	}
15218       goto done;
15219     case OMP_ATOMIC_CAPTURE_NEW:
15220       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
15221 	{
15222 	  c_parser_consume_token (parser);
15223 	  structured_block = true;
15224 	}
15225       else
15226 	{
15227 	  v = c_parser_cast_expression (parser, NULL).value;
15228 	  non_lvalue_p = !lvalue_p (v);
15229 	  v = c_fully_fold (v, false, NULL, true);
15230 	  if (v == error_mark_node)
15231 	    goto saw_error;
15232 	  if (non_lvalue_p)
15233 	    v = non_lvalue (v);
15234 	  if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
15235 	    goto saw_error;
15236 	}
15237       break;
15238     default:
15239       break;
15240     }
15241 
15242   /* For structured_block case we don't know yet whether
15243      old or new x should be captured.  */
15244 restart:
15245   eloc = c_parser_peek_token (parser)->location;
15246   expr = c_parser_cast_expression (parser, NULL);
15247   lhs = expr.value;
15248   expr = default_function_array_conversion (eloc, expr);
15249   unfolded_lhs = expr.value;
15250   lhs = c_fully_fold (lhs, false, NULL, true);
15251   orig_lhs = lhs;
15252   switch (TREE_CODE (lhs))
15253     {
15254     case ERROR_MARK:
15255     saw_error:
15256       c_parser_skip_to_end_of_block_or_statement (parser);
15257       if (structured_block)
15258 	{
15259 	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15260 	    c_parser_consume_token (parser);
15261 	  else if (code == OMP_ATOMIC_CAPTURE_NEW)
15262 	    {
15263 	      c_parser_skip_to_end_of_block_or_statement (parser);
15264 	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15265 		c_parser_consume_token (parser);
15266 	    }
15267 	}
15268       return;
15269 
15270     case POSTINCREMENT_EXPR:
15271       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
15272 	code = OMP_ATOMIC_CAPTURE_OLD;
15273       /* FALLTHROUGH */
15274     case PREINCREMENT_EXPR:
15275       lhs = TREE_OPERAND (lhs, 0);
15276       unfolded_lhs = NULL_TREE;
15277       opcode = PLUS_EXPR;
15278       rhs = integer_one_node;
15279       break;
15280 
15281     case POSTDECREMENT_EXPR:
15282       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
15283 	code = OMP_ATOMIC_CAPTURE_OLD;
15284       /* FALLTHROUGH */
15285     case PREDECREMENT_EXPR:
15286       lhs = TREE_OPERAND (lhs, 0);
15287       unfolded_lhs = NULL_TREE;
15288       opcode = MINUS_EXPR;
15289       rhs = integer_one_node;
15290       break;
15291 
15292     case COMPOUND_EXPR:
15293       if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
15294 	  && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
15295 	  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
15296 	  && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
15297 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15298 					      (TREE_OPERAND (lhs, 1), 0), 0)))
15299 	     == BOOLEAN_TYPE)
15300 	/* Undo effects of boolean_increment for post {in,de}crement.  */
15301 	lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
15302       /* FALLTHRU */
15303     case MODIFY_EXPR:
15304       if (TREE_CODE (lhs) == MODIFY_EXPR
15305 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
15306 	{
15307 	  /* Undo effects of boolean_increment.  */
15308 	  if (integer_onep (TREE_OPERAND (lhs, 1)))
15309 	    {
15310 	      /* This is pre or post increment.  */
15311 	      rhs = TREE_OPERAND (lhs, 1);
15312 	      lhs = TREE_OPERAND (lhs, 0);
15313 	      unfolded_lhs = NULL_TREE;
15314 	      opcode = NOP_EXPR;
15315 	      if (code == OMP_ATOMIC_CAPTURE_NEW
15316 		  && !structured_block
15317 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
15318 		code = OMP_ATOMIC_CAPTURE_OLD;
15319 	      break;
15320 	    }
15321 	  if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
15322 	      && TREE_OPERAND (lhs, 0)
15323 		 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
15324 	    {
15325 	      /* This is pre or post decrement.  */
15326 	      rhs = TREE_OPERAND (lhs, 1);
15327 	      lhs = TREE_OPERAND (lhs, 0);
15328 	      unfolded_lhs = NULL_TREE;
15329 	      opcode = NOP_EXPR;
15330 	      if (code == OMP_ATOMIC_CAPTURE_NEW
15331 		  && !structured_block
15332 		  && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
15333 		code = OMP_ATOMIC_CAPTURE_OLD;
15334 	      break;
15335 	    }
15336 	}
15337       /* FALLTHRU */
15338     default:
15339       if (!lvalue_p (unfolded_lhs))
15340 	lhs = non_lvalue (lhs);
15341       switch (c_parser_peek_token (parser)->type)
15342 	{
15343 	case CPP_MULT_EQ:
15344 	  opcode = MULT_EXPR;
15345 	  break;
15346 	case CPP_DIV_EQ:
15347 	  opcode = TRUNC_DIV_EXPR;
15348 	  break;
15349 	case CPP_PLUS_EQ:
15350 	  opcode = PLUS_EXPR;
15351 	  break;
15352 	case CPP_MINUS_EQ:
15353 	  opcode = MINUS_EXPR;
15354 	  break;
15355 	case CPP_LSHIFT_EQ:
15356 	  opcode = LSHIFT_EXPR;
15357 	  break;
15358 	case CPP_RSHIFT_EQ:
15359 	  opcode = RSHIFT_EXPR;
15360 	  break;
15361 	case CPP_AND_EQ:
15362 	  opcode = BIT_AND_EXPR;
15363 	  break;
15364 	case CPP_OR_EQ:
15365 	  opcode = BIT_IOR_EXPR;
15366 	  break;
15367 	case CPP_XOR_EQ:
15368 	  opcode = BIT_XOR_EXPR;
15369 	  break;
15370 	case CPP_EQ:
15371 	  c_parser_consume_token (parser);
15372 	  eloc = c_parser_peek_token (parser)->location;
15373 	  expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
15374 	  rhs1 = expr.value;
15375 	  switch (TREE_CODE (rhs1))
15376 	    {
15377 	    case MULT_EXPR:
15378 	    case TRUNC_DIV_EXPR:
15379 	    case RDIV_EXPR:
15380 	    case PLUS_EXPR:
15381 	    case MINUS_EXPR:
15382 	    case LSHIFT_EXPR:
15383 	    case RSHIFT_EXPR:
15384 	    case BIT_AND_EXPR:
15385 	    case BIT_IOR_EXPR:
15386 	    case BIT_XOR_EXPR:
15387 	      if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
15388 		{
15389 		  opcode = TREE_CODE (rhs1);
15390 		  rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
15391 				      true);
15392 		  rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
15393 				       true);
15394 		  goto stmt_done;
15395 		}
15396 	      if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
15397 		{
15398 		  opcode = TREE_CODE (rhs1);
15399 		  rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
15400 				      true);
15401 		  rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
15402 				       true);
15403 		  swapped = !commutative_tree_code (opcode);
15404 		  goto stmt_done;
15405 		}
15406 	      break;
15407 	    case ERROR_MARK:
15408 	      goto saw_error;
15409 	    default:
15410 	      break;
15411 	    }
15412 	  if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
15413 	    {
15414 	      if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
15415 		{
15416 		  code = OMP_ATOMIC_CAPTURE_OLD;
15417 		  v = lhs;
15418 		  lhs = NULL_TREE;
15419 		  expr = default_function_array_read_conversion (eloc, expr);
15420 		  unfolded_lhs1 = expr.value;
15421 		  lhs1 = c_fully_fold (unfolded_lhs1, false, NULL, true);
15422 		  rhs1 = NULL_TREE;
15423 		  c_parser_consume_token (parser);
15424 		  goto restart;
15425 		}
15426 	      if (structured_block)
15427 		{
15428 		  opcode = NOP_EXPR;
15429 		  expr = default_function_array_read_conversion (eloc, expr);
15430 		  rhs = c_fully_fold (expr.value, false, NULL, true);
15431 		  rhs1 = NULL_TREE;
15432 		  goto stmt_done;
15433 		}
15434 	    }
15435 	  c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
15436 	  goto saw_error;
15437 	default:
15438 	  c_parser_error (parser,
15439 			  "invalid operator for %<#pragma omp atomic%>");
15440 	  goto saw_error;
15441 	}
15442 
15443       /* Arrange to pass the location of the assignment operator to
15444 	 c_finish_omp_atomic.  */
15445       loc = c_parser_peek_token (parser)->location;
15446       c_parser_consume_token (parser);
15447       eloc = c_parser_peek_token (parser)->location;
15448       expr = c_parser_expression (parser);
15449       expr = default_function_array_read_conversion (eloc, expr);
15450       rhs = expr.value;
15451       rhs = c_fully_fold (rhs, false, NULL, true);
15452       break;
15453     }
15454 stmt_done:
15455   if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
15456     {
15457       if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
15458 	goto saw_error;
15459       v = c_parser_cast_expression (parser, NULL).value;
15460       non_lvalue_p = !lvalue_p (v);
15461       v = c_fully_fold (v, false, NULL, true);
15462       if (v == error_mark_node)
15463 	goto saw_error;
15464       if (non_lvalue_p)
15465 	v = non_lvalue (v);
15466       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
15467 	goto saw_error;
15468       eloc = c_parser_peek_token (parser)->location;
15469       expr = c_parser_cast_expression (parser, NULL);
15470       lhs1 = expr.value;
15471       expr = default_function_array_read_conversion (eloc, expr);
15472       unfolded_lhs1 = expr.value;
15473       lhs1 = c_fully_fold (lhs1, false, NULL, true);
15474       if (lhs1 == error_mark_node)
15475 	goto saw_error;
15476       if (!lvalue_p (unfolded_lhs1))
15477 	lhs1 = non_lvalue (lhs1);
15478     }
15479   if (structured_block)
15480     {
15481       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15482       c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
15483     }
15484 done:
15485   if (unfolded_lhs && unfolded_lhs1
15486       && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
15487     {
15488       error ("%<#pragma omp atomic capture%> uses two different "
15489 	     "expressions for memory");
15490       stmt = error_mark_node;
15491     }
15492   else
15493     stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
15494 				swapped, seq_cst);
15495   if (stmt != error_mark_node)
15496     add_stmt (stmt);
15497 
15498   if (!structured_block)
15499     c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15500 }
15501 
15502 
15503 /* OpenMP 2.5:
15504    # pragma omp barrier new-line
15505 */
15506 
15507 static void
15508 c_parser_omp_barrier (c_parser *parser)
15509 {
15510   location_t loc = c_parser_peek_token (parser)->location;
15511   c_parser_consume_pragma (parser);
15512   c_parser_skip_to_pragma_eol (parser);
15513 
15514   c_finish_omp_barrier (loc);
15515 }
15516 
15517 /* OpenMP 2.5:
15518    # pragma omp critical [(name)] new-line
15519      structured-block
15520 
15521    OpenMP 4.5:
15522    # pragma omp critical [(name) [hint(expression)]] new-line
15523 
15524   LOC is the location of the #pragma itself.  */
15525 
15526 #define OMP_CRITICAL_CLAUSE_MASK		\
15527 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15528 
15529 static tree
15530 c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p)
15531 {
15532   tree stmt, name = NULL_TREE, clauses = NULL_TREE;
15533 
15534   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15535     {
15536       c_parser_consume_token (parser);
15537       if (c_parser_next_token_is (parser, CPP_NAME))
15538 	{
15539 	  name = c_parser_peek_token (parser)->value;
15540 	  c_parser_consume_token (parser);
15541 	  c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
15542 	}
15543       else
15544 	c_parser_error (parser, "expected identifier");
15545 
15546       clauses = c_parser_omp_all_clauses (parser,
15547 					  OMP_CRITICAL_CLAUSE_MASK,
15548 					  "#pragma omp critical");
15549     }
15550   else
15551     {
15552       if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15553 	c_parser_error (parser, "expected %<(%> or end of line");
15554       c_parser_skip_to_pragma_eol (parser);
15555     }
15556 
15557   stmt = c_parser_omp_structured_block (parser, if_p);
15558   return c_finish_omp_critical (loc, stmt, name, clauses);
15559 }
15560 
15561 /* OpenMP 2.5:
15562    # pragma omp flush flush-vars[opt] new-line
15563 
15564    flush-vars:
15565      ( variable-list ) */
15566 
15567 static void
15568 c_parser_omp_flush (c_parser *parser)
15569 {
15570   location_t loc = c_parser_peek_token (parser)->location;
15571   c_parser_consume_pragma (parser);
15572   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15573     c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
15574   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15575     c_parser_error (parser, "expected %<(%> or end of line");
15576   c_parser_skip_to_pragma_eol (parser);
15577 
15578   c_finish_omp_flush (loc);
15579 }
15580 
15581 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15582    The real trick here is to determine the loop control variable early
15583    so that we can push a new decl if necessary to make it private.
15584    LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15585    respectively.  */
15586 
15587 static tree
15588 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
15589 		       tree clauses, tree *cclauses, bool *if_p)
15590 {
15591   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
15592   tree declv, condv, incrv, initv, ret = NULL_TREE;
15593   tree pre_body = NULL_TREE, this_pre_body;
15594   tree ordered_cl = NULL_TREE;
15595   bool fail = false, open_brace_parsed = false;
15596   int i, collapse = 1, ordered = 0, count, nbraces = 0;
15597   location_t for_loc;
15598   bool tiling = false;
15599   vec<tree, va_gc> *for_block = make_tree_vector ();
15600 
15601   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
15602     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
15603       collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
15604     else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
15605       {
15606 	tiling = true;
15607 	collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
15608       }
15609     else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
15610 	     && OMP_CLAUSE_ORDERED_EXPR (cl))
15611       {
15612 	ordered_cl = cl;
15613 	ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl));
15614       }
15615 
15616   if (ordered && ordered < collapse)
15617     {
15618       error_at (OMP_CLAUSE_LOCATION (ordered_cl),
15619 		"%<ordered%> clause parameter is less than %<collapse%>");
15620       OMP_CLAUSE_ORDERED_EXPR (ordered_cl)
15621 	= build_int_cst (NULL_TREE, collapse);
15622       ordered = collapse;
15623     }
15624   if (ordered)
15625     {
15626       for (tree *pc = &clauses; *pc; )
15627 	if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR)
15628 	  {
15629 	    error_at (OMP_CLAUSE_LOCATION (*pc),
15630 		      "%<linear%> clause may not be specified together "
15631 		      "with %<ordered%> clause with a parameter");
15632 	    *pc = OMP_CLAUSE_CHAIN (*pc);
15633 	  }
15634 	else
15635 	  pc = &OMP_CLAUSE_CHAIN (*pc);
15636     }
15637 
15638   gcc_assert (tiling || (collapse >= 1 && ordered >= 0));
15639   count = ordered ? ordered : collapse;
15640 
15641   declv = make_tree_vec (count);
15642   initv = make_tree_vec (count);
15643   condv = make_tree_vec (count);
15644   incrv = make_tree_vec (count);
15645 
15646   if (!c_parser_next_token_is_keyword (parser, RID_FOR))
15647     {
15648       c_parser_error (parser, "for statement expected");
15649       return NULL;
15650     }
15651   for_loc = c_parser_peek_token (parser)->location;
15652   c_parser_consume_token (parser);
15653 
15654   for (i = 0; i < count; i++)
15655     {
15656       int bracecount = 0;
15657 
15658       matching_parens parens;
15659       if (!parens.require_open (parser))
15660 	goto pop_scopes;
15661 
15662       /* Parse the initialization declaration or expression.  */
15663       if (c_parser_next_tokens_start_declaration (parser))
15664 	{
15665 	  if (i > 0)
15666 	    vec_safe_push (for_block, c_begin_compound_stmt (true));
15667 	  this_pre_body = push_stmt_list ();
15668 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
15669 					 NULL, vNULL);
15670 	  if (this_pre_body)
15671 	    {
15672 	      this_pre_body = pop_stmt_list (this_pre_body);
15673 	      if (pre_body)
15674 		{
15675 		  tree t = pre_body;
15676 		  pre_body = push_stmt_list ();
15677 		  add_stmt (t);
15678 		  add_stmt (this_pre_body);
15679 		  pre_body = pop_stmt_list (pre_body);
15680 		}
15681 	      else
15682 		pre_body = this_pre_body;
15683 	    }
15684 	  decl = check_for_loop_decls (for_loc, flag_isoc99);
15685 	  if (decl == NULL)
15686 	    goto error_init;
15687 	  if (DECL_INITIAL (decl) == error_mark_node)
15688 	    decl = error_mark_node;
15689 	  init = decl;
15690 	}
15691       else if (c_parser_next_token_is (parser, CPP_NAME)
15692 	       && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
15693 	{
15694 	  struct c_expr decl_exp;
15695 	  struct c_expr init_exp;
15696 	  location_t init_loc;
15697 
15698 	  decl_exp = c_parser_postfix_expression (parser);
15699 	  decl = decl_exp.value;
15700 
15701 	  c_parser_require (parser, CPP_EQ, "expected %<=%>");
15702 
15703 	  init_loc = c_parser_peek_token (parser)->location;
15704 	  init_exp = c_parser_expr_no_commas (parser, NULL);
15705 	  init_exp = default_function_array_read_conversion (init_loc,
15706 							     init_exp);
15707 	  init = build_modify_expr (init_loc, decl, decl_exp.original_type,
15708 				    NOP_EXPR, init_loc, init_exp.value,
15709 				    init_exp.original_type);
15710 	  init = c_process_expr_stmt (init_loc, init);
15711 
15712 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15713 	}
15714       else
15715 	{
15716 	error_init:
15717 	  c_parser_error (parser,
15718 			  "expected iteration declaration or initialization");
15719 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
15720 				     "expected %<)%>");
15721 	  fail = true;
15722 	  goto parse_next;
15723 	}
15724 
15725       /* Parse the loop condition.  */
15726       cond = NULL_TREE;
15727       if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
15728 	{
15729 	  location_t cond_loc = c_parser_peek_token (parser)->location;
15730 	  struct c_expr cond_expr
15731 	    = c_parser_binary_expression (parser, NULL, NULL_TREE);
15732 
15733 	  cond = cond_expr.value;
15734 	  cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
15735 	  if (COMPARISON_CLASS_P (cond))
15736 	    {
15737 	      tree op0 = TREE_OPERAND (cond, 0), op1 = TREE_OPERAND (cond, 1);
15738 	      op0 = c_fully_fold (op0, false, NULL);
15739 	      op1 = c_fully_fold (op1, false, NULL);
15740 	      TREE_OPERAND (cond, 0) = op0;
15741 	      TREE_OPERAND (cond, 1) = op1;
15742 	    }
15743 	  switch (cond_expr.original_code)
15744 	    {
15745 	    case GT_EXPR:
15746 	    case GE_EXPR:
15747 	    case LT_EXPR:
15748 	    case LE_EXPR:
15749 	      break;
15750 	    default:
15751 	      /* Can't be cond = error_mark_node, because we want to preserve
15752 		 the location until c_finish_omp_for.  */
15753 	      cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
15754 	      break;
15755 	    }
15756 	  protected_set_expr_location (cond, cond_loc);
15757 	}
15758       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15759 
15760       /* Parse the increment expression.  */
15761       incr = NULL_TREE;
15762       if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
15763 	{
15764 	  location_t incr_loc = c_parser_peek_token (parser)->location;
15765 
15766 	  incr = c_process_expr_stmt (incr_loc,
15767 				      c_parser_expression (parser).value);
15768 	}
15769       parens.skip_until_found_close (parser);
15770 
15771       if (decl == NULL || decl == error_mark_node || init == error_mark_node)
15772 	fail = true;
15773       else
15774 	{
15775 	  TREE_VEC_ELT (declv, i) = decl;
15776 	  TREE_VEC_ELT (initv, i) = init;
15777 	  TREE_VEC_ELT (condv, i) = cond;
15778 	  TREE_VEC_ELT (incrv, i) = incr;
15779 	}
15780 
15781     parse_next:
15782       if (i == count - 1)
15783 	break;
15784 
15785       /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15786 	 in between the collapsed for loops to be still considered perfectly
15787 	 nested.  Hopefully the final version clarifies this.
15788 	 For now handle (multiple) {'s and empty statements.  */
15789       do
15790 	{
15791 	  if (c_parser_next_token_is_keyword (parser, RID_FOR))
15792 	    {
15793 	      c_parser_consume_token (parser);
15794 	      break;
15795 	    }
15796 	  else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
15797 	    {
15798 	      c_parser_consume_token (parser);
15799 	      bracecount++;
15800 	    }
15801 	  else if (bracecount
15802 		   && c_parser_next_token_is (parser, CPP_SEMICOLON))
15803 	    c_parser_consume_token (parser);
15804 	  else
15805 	    {
15806 	      c_parser_error (parser, "not enough perfectly nested loops");
15807 	      if (bracecount)
15808 		{
15809 		  open_brace_parsed = true;
15810 		  bracecount--;
15811 		}
15812 	      fail = true;
15813 	      count = 0;
15814 	      break;
15815 	    }
15816 	}
15817       while (1);
15818 
15819       nbraces += bracecount;
15820     }
15821 
15822   if (nbraces)
15823     if_p = NULL;
15824 
15825   save_break = c_break_label;
15826   c_break_label = size_one_node;
15827   save_cont = c_cont_label;
15828   c_cont_label = NULL_TREE;
15829   body = push_stmt_list ();
15830 
15831   if (open_brace_parsed)
15832     {
15833       location_t here = c_parser_peek_token (parser)->location;
15834       stmt = c_begin_compound_stmt (true);
15835       c_parser_compound_statement_nostart (parser);
15836       add_stmt (c_end_compound_stmt (here, stmt, true));
15837     }
15838   else
15839     add_stmt (c_parser_c99_block_statement (parser, if_p));
15840   if (c_cont_label)
15841     {
15842       tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
15843       SET_EXPR_LOCATION (t, loc);
15844       add_stmt (t);
15845     }
15846 
15847   body = pop_stmt_list (body);
15848   c_break_label = save_break;
15849   c_cont_label = save_cont;
15850 
15851   while (nbraces)
15852     {
15853       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15854 	{
15855 	  c_parser_consume_token (parser);
15856 	  nbraces--;
15857 	}
15858       else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
15859 	c_parser_consume_token (parser);
15860       else
15861 	{
15862 	  c_parser_error (parser, "collapsed loops not perfectly nested");
15863 	  while (nbraces)
15864 	    {
15865 	      location_t here = c_parser_peek_token (parser)->location;
15866 	      stmt = c_begin_compound_stmt (true);
15867 	      add_stmt (body);
15868 	      c_parser_compound_statement_nostart (parser);
15869 	      body = c_end_compound_stmt (here, stmt, true);
15870 	      nbraces--;
15871 	    }
15872 	  goto pop_scopes;
15873 	}
15874     }
15875 
15876   /* Only bother calling c_finish_omp_for if we haven't already generated
15877      an error from the initialization parsing.  */
15878   if (!fail)
15879     {
15880       stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv,
15881 			       incrv, body, pre_body);
15882 
15883       /* Check for iterators appearing in lb, b or incr expressions.  */
15884       if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL))
15885 	stmt = NULL_TREE;
15886 
15887       if (stmt)
15888 	{
15889 	  add_stmt (stmt);
15890 
15891 	  if (cclauses != NULL
15892 	      && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
15893 	    {
15894 	      tree *c;
15895 	      for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
15896 		if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
15897 		    && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
15898 		  c = &OMP_CLAUSE_CHAIN (*c);
15899 		else
15900 		  {
15901 		    for (i = 0; i < count; i++)
15902 		      if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
15903 			break;
15904 		    if (i == count)
15905 		      c = &OMP_CLAUSE_CHAIN (*c);
15906 		    else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
15907 		      {
15908 			error_at (loc,
15909 				  "iteration variable %qD should not be firstprivate",
15910 				  OMP_CLAUSE_DECL (*c));
15911 			*c = OMP_CLAUSE_CHAIN (*c);
15912 		      }
15913 		    else
15914 		      {
15915 			/* Move lastprivate (decl) clause to OMP_FOR_CLAUSES.  */
15916 			tree l = *c;
15917 			*c = OMP_CLAUSE_CHAIN (*c);
15918 			if (code == OMP_SIMD)
15919 			  {
15920 			    OMP_CLAUSE_CHAIN (l)
15921 			      = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
15922 			    cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
15923 			  }
15924 			else
15925 			  {
15926 			    OMP_CLAUSE_CHAIN (l) = clauses;
15927 			    clauses = l;
15928 			  }
15929 		      }
15930 		  }
15931 	    }
15932 	  OMP_FOR_CLAUSES (stmt) = clauses;
15933 	}
15934       ret = stmt;
15935     }
15936 pop_scopes:
15937   while (!for_block->is_empty ())
15938     {
15939       /* FIXME diagnostics: LOC below should be the actual location of
15940 	 this particular for block.  We need to build a list of
15941 	 locations to go along with FOR_BLOCK.  */
15942       stmt = c_end_compound_stmt (loc, for_block->pop (), true);
15943       add_stmt (stmt);
15944     }
15945   release_tree_vector (for_block);
15946   return ret;
15947 }
15948 
15949 /* Helper function for OpenMP parsing, split clauses and call
15950    finish_omp_clauses on each of the set of clauses afterwards.  */
15951 
15952 static void
15953 omp_split_clauses (location_t loc, enum tree_code code,
15954 		   omp_clause_mask mask, tree clauses, tree *cclauses)
15955 {
15956   int i;
15957   c_omp_split_clauses (loc, code, mask, clauses, cclauses);
15958   for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
15959     if (cclauses[i])
15960       cclauses[i] = c_finish_omp_clauses (cclauses[i], C_ORT_OMP);
15961 }
15962 
15963 /* OpenMP 4.0:
15964    #pragma omp simd simd-clause[optseq] new-line
15965      for-loop
15966 
15967    LOC is the location of the #pragma token.
15968 */
15969 
15970 #define OMP_SIMD_CLAUSE_MASK					\
15971 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN)	\
15972 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN)	\
15973 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
15974 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)	\
15975 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
15976 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
15977 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
15978 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15979 
15980 static tree
15981 c_parser_omp_simd (location_t loc, c_parser *parser,
15982 		   char *p_name, omp_clause_mask mask, tree *cclauses,
15983 		   bool *if_p)
15984 {
15985   tree block, clauses, ret;
15986 
15987   strcat (p_name, " simd");
15988   mask |= OMP_SIMD_CLAUSE_MASK;
15989 
15990   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15991   if (cclauses)
15992     {
15993       omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
15994       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
15995       tree c = omp_find_clause (cclauses[C_OMP_CLAUSE_SPLIT_FOR],
15996 				OMP_CLAUSE_ORDERED);
15997       if (c && OMP_CLAUSE_ORDERED_EXPR (c))
15998 	{
15999 	  error_at (OMP_CLAUSE_LOCATION (c),
16000 		    "%<ordered%> clause with parameter may not be specified "
16001 		    "on %qs construct", p_name);
16002 	  OMP_CLAUSE_ORDERED_EXPR (c) = NULL_TREE;
16003 	}
16004     }
16005 
16006   block = c_begin_compound_stmt (true);
16007   ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p);
16008   block = c_end_compound_stmt (loc, block, true);
16009   add_stmt (block);
16010 
16011   return ret;
16012 }
16013 
16014 /* OpenMP 2.5:
16015    #pragma omp for for-clause[optseq] new-line
16016      for-loop
16017 
16018    OpenMP 4.0:
16019    #pragma omp for simd for-simd-clause[optseq] new-line
16020      for-loop
16021 
16022    LOC is the location of the #pragma token.
16023 */
16024 
16025 #define OMP_FOR_CLAUSE_MASK					\
16026 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16027 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16028 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
16029 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
16030 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
16031 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED)	\
16032 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)	\
16033 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)	\
16034 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16035 
16036 static tree
16037 c_parser_omp_for (location_t loc, c_parser *parser,
16038 		  char *p_name, omp_clause_mask mask, tree *cclauses,
16039 		  bool *if_p)
16040 {
16041   tree block, clauses, ret;
16042 
16043   strcat (p_name, " for");
16044   mask |= OMP_FOR_CLAUSE_MASK;
16045   /* parallel for{, simd} disallows nowait clause, but for
16046      target {teams distribute ,}parallel for{, simd} it should be accepted.  */
16047   if (cclauses && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0)
16048     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
16049   /* Composite distribute parallel for{, simd} disallows ordered clause.  */
16050   if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
16051     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
16052 
16053   if (c_parser_next_token_is (parser, CPP_NAME))
16054     {
16055       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16056 
16057       if (strcmp (p, "simd") == 0)
16058 	{
16059 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16060 	  if (cclauses == NULL)
16061 	    cclauses = cclauses_buf;
16062 
16063 	  c_parser_consume_token (parser);
16064 	  if (!flag_openmp)  /* flag_openmp_simd  */
16065 	    return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
16066 				      if_p);
16067 	  block = c_begin_compound_stmt (true);
16068 	  ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
16069 	  block = c_end_compound_stmt (loc, block, true);
16070 	  if (ret == NULL_TREE)
16071 	    return ret;
16072 	  ret = make_node (OMP_FOR);
16073 	  TREE_TYPE (ret) = void_type_node;
16074 	  OMP_FOR_BODY (ret) = block;
16075 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
16076 	  SET_EXPR_LOCATION (ret, loc);
16077 	  add_stmt (ret);
16078 	  return ret;
16079 	}
16080     }
16081   if (!flag_openmp)  /* flag_openmp_simd  */
16082     {
16083       c_parser_skip_to_pragma_eol (parser, false);
16084       return NULL_TREE;
16085     }
16086 
16087   /* Composite distribute parallel for disallows linear clause.  */
16088   if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
16089     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR);
16090 
16091   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16092   if (cclauses)
16093     {
16094       omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
16095       clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
16096     }
16097 
16098   block = c_begin_compound_stmt (true);
16099   ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p);
16100   block = c_end_compound_stmt (loc, block, true);
16101   add_stmt (block);
16102 
16103   return ret;
16104 }
16105 
16106 /* OpenMP 2.5:
16107    # pragma omp master new-line
16108      structured-block
16109 
16110    LOC is the location of the #pragma token.
16111 */
16112 
16113 static tree
16114 c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p)
16115 {
16116   c_parser_skip_to_pragma_eol (parser);
16117   return c_finish_omp_master (loc, c_parser_omp_structured_block (parser,
16118 								  if_p));
16119 }
16120 
16121 /* OpenMP 2.5:
16122    # pragma omp ordered new-line
16123      structured-block
16124 
16125    OpenMP 4.5:
16126    # pragma omp ordered ordered-clauses new-line
16127      structured-block
16128 
16129    # pragma omp ordered depend-clauses new-line  */
16130 
16131 #define OMP_ORDERED_CLAUSE_MASK					\
16132 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS)	\
16133 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16134 
16135 #define OMP_ORDERED_DEPEND_CLAUSE_MASK				\
16136 	(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16137 
16138 static bool
16139 c_parser_omp_ordered (c_parser *parser, enum pragma_context context,
16140 		      bool *if_p)
16141 {
16142   location_t loc = c_parser_peek_token (parser)->location;
16143   c_parser_consume_pragma (parser);
16144 
16145   if (context != pragma_stmt && context != pragma_compound)
16146     {
16147       c_parser_error (parser, "expected declaration specifiers");
16148       c_parser_skip_to_pragma_eol (parser, false);
16149       return false;
16150     }
16151 
16152   if (c_parser_next_token_is (parser, CPP_NAME))
16153     {
16154       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16155 
16156       if (!strcmp ("depend", p))
16157 	{
16158 	  if (!flag_openmp)	/* flag_openmp_simd  */
16159 	    {
16160 	      c_parser_skip_to_pragma_eol (parser, false);
16161 	      return false;
16162 	    }
16163 	  if (context == pragma_stmt)
16164 	    {
16165 	      error_at (loc,
16166 			"%<#pragma omp ordered%> with %<depend%> clause may "
16167 			"only be used in compound statements");
16168 	      c_parser_skip_to_pragma_eol (parser, false);
16169 	      return false;
16170 	    }
16171 
16172 	  tree clauses
16173 	    = c_parser_omp_all_clauses (parser,
16174 					OMP_ORDERED_DEPEND_CLAUSE_MASK,
16175 					"#pragma omp ordered");
16176 	  c_finish_omp_ordered (loc, clauses, NULL_TREE);
16177 	  return false;
16178 	}
16179     }
16180 
16181   tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK,
16182 					   "#pragma omp ordered");
16183 
16184   if (!flag_openmp	/* flag_openmp_simd  */
16185       && omp_find_clause (clauses, OMP_CLAUSE_SIMD) == NULL_TREE)
16186     return false;
16187 
16188   c_finish_omp_ordered (loc, clauses,
16189 			c_parser_omp_structured_block (parser, if_p));
16190   return true;
16191 }
16192 
16193 /* OpenMP 2.5:
16194 
16195    section-scope:
16196      { section-sequence }
16197 
16198    section-sequence:
16199      section-directive[opt] structured-block
16200      section-sequence section-directive structured-block
16201 
16202     SECTIONS_LOC is the location of the #pragma omp sections.  */
16203 
16204 static tree
16205 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
16206 {
16207   tree stmt, substmt;
16208   bool error_suppress = false;
16209   location_t loc;
16210 
16211   loc = c_parser_peek_token (parser)->location;
16212   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
16213     {
16214       /* Avoid skipping until the end of the block.  */
16215       parser->error = false;
16216       return NULL_TREE;
16217     }
16218 
16219   stmt = push_stmt_list ();
16220 
16221   if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
16222     {
16223       substmt = c_parser_omp_structured_block (parser, NULL);
16224       substmt = build1 (OMP_SECTION, void_type_node, substmt);
16225       SET_EXPR_LOCATION (substmt, loc);
16226       add_stmt (substmt);
16227     }
16228 
16229   while (1)
16230     {
16231       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
16232 	break;
16233       if (c_parser_next_token_is (parser, CPP_EOF))
16234 	break;
16235 
16236       loc = c_parser_peek_token (parser)->location;
16237       if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
16238 	{
16239 	  c_parser_consume_pragma (parser);
16240 	  c_parser_skip_to_pragma_eol (parser);
16241 	  error_suppress = false;
16242 	}
16243       else if (!error_suppress)
16244 	{
16245 	  error_at (loc, "expected %<#pragma omp section%> or %<}%>");
16246 	  error_suppress = true;
16247 	}
16248 
16249       substmt = c_parser_omp_structured_block (parser, NULL);
16250       substmt = build1 (OMP_SECTION, void_type_node, substmt);
16251       SET_EXPR_LOCATION (substmt, loc);
16252       add_stmt (substmt);
16253     }
16254   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
16255 			     "expected %<#pragma omp section%> or %<}%>");
16256 
16257   substmt = pop_stmt_list (stmt);
16258 
16259   stmt = make_node (OMP_SECTIONS);
16260   SET_EXPR_LOCATION (stmt, sections_loc);
16261   TREE_TYPE (stmt) = void_type_node;
16262   OMP_SECTIONS_BODY (stmt) = substmt;
16263 
16264   return add_stmt (stmt);
16265 }
16266 
16267 /* OpenMP 2.5:
16268    # pragma omp sections sections-clause[optseq] newline
16269      sections-scope
16270 
16271    LOC is the location of the #pragma token.
16272 */
16273 
16274 #define OMP_SECTIONS_CLAUSE_MASK				\
16275 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16276 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16277 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
16278 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
16279 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16280 
16281 static tree
16282 c_parser_omp_sections (location_t loc, c_parser *parser,
16283 		       char *p_name, omp_clause_mask mask, tree *cclauses)
16284 {
16285   tree block, clauses, ret;
16286 
16287   strcat (p_name, " sections");
16288   mask |= OMP_SECTIONS_CLAUSE_MASK;
16289   if (cclauses)
16290     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
16291 
16292   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16293   if (cclauses)
16294     {
16295       omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
16296       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
16297     }
16298 
16299   block = c_begin_compound_stmt (true);
16300   ret = c_parser_omp_sections_scope (loc, parser);
16301   if (ret)
16302     OMP_SECTIONS_CLAUSES (ret) = clauses;
16303   block = c_end_compound_stmt (loc, block, true);
16304   add_stmt (block);
16305 
16306   return ret;
16307 }
16308 
16309 /* OpenMP 2.5:
16310    # pragma omp parallel parallel-clause[optseq] new-line
16311      structured-block
16312    # pragma omp parallel for parallel-for-clause[optseq] new-line
16313      structured-block
16314    # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16315      structured-block
16316 
16317    OpenMP 4.0:
16318    # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16319      structured-block
16320 
16321    LOC is the location of the #pragma token.
16322 */
16323 
16324 #define OMP_PARALLEL_CLAUSE_MASK				\
16325 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16326 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16327 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16328 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
16329 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
16330 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN)	\
16331 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
16332 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)	\
16333 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16334 
16335 static tree
16336 c_parser_omp_parallel (location_t loc, c_parser *parser,
16337 		       char *p_name, omp_clause_mask mask, tree *cclauses,
16338 		       bool *if_p)
16339 {
16340   tree stmt, clauses, block;
16341 
16342   strcat (p_name, " parallel");
16343   mask |= OMP_PARALLEL_CLAUSE_MASK;
16344   /* #pragma omp target parallel{, for, for simd} disallow copyin clause.  */
16345   if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0
16346       && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0)
16347     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN);
16348 
16349   if (c_parser_next_token_is_keyword (parser, RID_FOR))
16350     {
16351       tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16352       if (cclauses == NULL)
16353 	cclauses = cclauses_buf;
16354 
16355       c_parser_consume_token (parser);
16356       if (!flag_openmp)  /* flag_openmp_simd  */
16357 	return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
16358       block = c_begin_omp_parallel ();
16359       tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
16360       stmt
16361 	= c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
16362 				 block);
16363       if (ret == NULL_TREE)
16364 	return ret;
16365       OMP_PARALLEL_COMBINED (stmt) = 1;
16366       return stmt;
16367     }
16368   /* When combined with distribute, parallel has to be followed by for.
16369      #pragma omp target parallel is allowed though.  */
16370   else if (cclauses
16371 	   && (mask & (OMP_CLAUSE_MASK_1
16372 		       << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
16373     {
16374       error_at (loc, "expected %<for%> after %qs", p_name);
16375       c_parser_skip_to_pragma_eol (parser);
16376       return NULL_TREE;
16377     }
16378   else if (!flag_openmp)  /* flag_openmp_simd  */
16379     {
16380       c_parser_skip_to_pragma_eol (parser, false);
16381       return NULL_TREE;
16382     }
16383   else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME))
16384     {
16385       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16386       if (strcmp (p, "sections") == 0)
16387 	{
16388 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16389 	  if (cclauses == NULL)
16390 	    cclauses = cclauses_buf;
16391 
16392 	  c_parser_consume_token (parser);
16393 	  block = c_begin_omp_parallel ();
16394 	  c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
16395 	  stmt = c_finish_omp_parallel (loc,
16396 					cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
16397 					block);
16398 	  OMP_PARALLEL_COMBINED (stmt) = 1;
16399 	  return stmt;
16400 	}
16401     }
16402 
16403   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16404   if (cclauses)
16405     {
16406       omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses);
16407       clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
16408     }
16409 
16410   block = c_begin_omp_parallel ();
16411   c_parser_statement (parser, if_p);
16412   stmt = c_finish_omp_parallel (loc, clauses, block);
16413 
16414   return stmt;
16415 }
16416 
16417 /* OpenMP 2.5:
16418    # pragma omp single single-clause[optseq] new-line
16419      structured-block
16420 
16421    LOC is the location of the #pragma.
16422 */
16423 
16424 #define OMP_SINGLE_CLAUSE_MASK					\
16425 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16426 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16427 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE)	\
16428 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16429 
16430 static tree
16431 c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p)
16432 {
16433   tree stmt = make_node (OMP_SINGLE);
16434   SET_EXPR_LOCATION (stmt, loc);
16435   TREE_TYPE (stmt) = void_type_node;
16436 
16437   OMP_SINGLE_CLAUSES (stmt)
16438     = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
16439 				"#pragma omp single");
16440   OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
16441 
16442   return add_stmt (stmt);
16443 }
16444 
16445 /* OpenMP 3.0:
16446    # pragma omp task task-clause[optseq] new-line
16447 
16448    LOC is the location of the #pragma.
16449 */
16450 
16451 #define OMP_TASK_CLAUSE_MASK					\
16452 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16453 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED)	\
16454 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
16455 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16456 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16457 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
16458 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
16459 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
16460 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16461 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16462 
16463 static tree
16464 c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p)
16465 {
16466   tree clauses, block;
16467 
16468   clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
16469 				      "#pragma omp task");
16470 
16471   block = c_begin_omp_task ();
16472   c_parser_statement (parser, if_p);
16473   return c_finish_omp_task (loc, clauses, block);
16474 }
16475 
16476 /* OpenMP 3.0:
16477    # pragma omp taskwait new-line
16478 */
16479 
16480 static void
16481 c_parser_omp_taskwait (c_parser *parser)
16482 {
16483   location_t loc = c_parser_peek_token (parser)->location;
16484   c_parser_consume_pragma (parser);
16485   c_parser_skip_to_pragma_eol (parser);
16486 
16487   c_finish_omp_taskwait (loc);
16488 }
16489 
16490 /* OpenMP 3.1:
16491    # pragma omp taskyield new-line
16492 */
16493 
16494 static void
16495 c_parser_omp_taskyield (c_parser *parser)
16496 {
16497   location_t loc = c_parser_peek_token (parser)->location;
16498   c_parser_consume_pragma (parser);
16499   c_parser_skip_to_pragma_eol (parser);
16500 
16501   c_finish_omp_taskyield (loc);
16502 }
16503 
16504 /* OpenMP 4.0:
16505    # pragma omp taskgroup new-line
16506 */
16507 
16508 static tree
16509 c_parser_omp_taskgroup (c_parser *parser, bool *if_p)
16510 {
16511   location_t loc = c_parser_peek_token (parser)->location;
16512   c_parser_skip_to_pragma_eol (parser);
16513   return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser,
16514 								     if_p));
16515 }
16516 
16517 /* OpenMP 4.0:
16518    # pragma omp cancel cancel-clause[optseq] new-line
16519 
16520    LOC is the location of the #pragma.
16521 */
16522 
16523 #define OMP_CANCEL_CLAUSE_MASK					\
16524 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)	\
16525 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)		\
16526 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
16527 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)	\
16528 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16529 
16530 static void
16531 c_parser_omp_cancel (c_parser *parser)
16532 {
16533   location_t loc = c_parser_peek_token (parser)->location;
16534 
16535   c_parser_consume_pragma (parser);
16536   tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
16537 					   "#pragma omp cancel");
16538 
16539   c_finish_omp_cancel (loc, clauses);
16540 }
16541 
16542 /* OpenMP 4.0:
16543    # pragma omp cancellation point cancelpt-clause[optseq] new-line
16544 
16545    LOC is the location of the #pragma.
16546 */
16547 
16548 #define OMP_CANCELLATION_POINT_CLAUSE_MASK			\
16549 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)	\
16550 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)		\
16551 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
16552 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16553 
16554 static void
16555 c_parser_omp_cancellation_point (c_parser *parser, enum pragma_context context)
16556 {
16557   location_t loc = c_parser_peek_token (parser)->location;
16558   tree clauses;
16559   bool point_seen = false;
16560 
16561   c_parser_consume_pragma (parser);
16562   if (c_parser_next_token_is (parser, CPP_NAME))
16563     {
16564       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16565       if (strcmp (p, "point") == 0)
16566 	{
16567 	  c_parser_consume_token (parser);
16568 	  point_seen = true;
16569 	}
16570     }
16571   if (!point_seen)
16572     {
16573       c_parser_error (parser, "expected %<point%>");
16574       c_parser_skip_to_pragma_eol (parser);
16575       return;
16576     }
16577 
16578   if (context != pragma_compound)
16579     {
16580       if (context == pragma_stmt)
16581 	error_at (loc,
16582 		  "%<#pragma %s%> may only be used in compound statements",
16583 		  "omp cancellation point");
16584       else
16585 	c_parser_error (parser, "expected declaration specifiers");
16586       c_parser_skip_to_pragma_eol (parser, false);
16587       return;
16588     }
16589 
16590   clauses
16591     = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
16592 				"#pragma omp cancellation point");
16593 
16594   c_finish_omp_cancellation_point (loc, clauses);
16595 }
16596 
16597 /* OpenMP 4.0:
16598    #pragma omp distribute distribute-clause[optseq] new-line
16599      for-loop  */
16600 
16601 #define OMP_DISTRIBUTE_CLAUSE_MASK				\
16602 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16603 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16604 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
16605 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16606 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16607 
16608 static tree
16609 c_parser_omp_distribute (location_t loc, c_parser *parser,
16610 			 char *p_name, omp_clause_mask mask, tree *cclauses,
16611 			 bool *if_p)
16612 {
16613   tree clauses, block, ret;
16614 
16615   strcat (p_name, " distribute");
16616   mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
16617 
16618   if (c_parser_next_token_is (parser, CPP_NAME))
16619     {
16620       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16621       bool simd = false;
16622       bool parallel = false;
16623 
16624       if (strcmp (p, "simd") == 0)
16625 	simd = true;
16626       else
16627 	parallel = strcmp (p, "parallel") == 0;
16628       if (parallel || simd)
16629 	{
16630 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16631 	  if (cclauses == NULL)
16632 	    cclauses = cclauses_buf;
16633 	  c_parser_consume_token (parser);
16634 	  if (!flag_openmp)  /* flag_openmp_simd  */
16635 	    {
16636 	      if (simd)
16637 		return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
16638 					  if_p);
16639 	      else
16640 		return c_parser_omp_parallel (loc, parser, p_name, mask,
16641 					      cclauses, if_p);
16642 	    }
16643 	  block = c_begin_compound_stmt (true);
16644 	  if (simd)
16645 	    ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
16646 				     if_p);
16647 	  else
16648 	    ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses,
16649 					 if_p);
16650 	  block = c_end_compound_stmt (loc, block, true);
16651 	  if (ret == NULL)
16652 	    return ret;
16653 	  ret = make_node (OMP_DISTRIBUTE);
16654 	  TREE_TYPE (ret) = void_type_node;
16655 	  OMP_FOR_BODY (ret) = block;
16656 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
16657 	  SET_EXPR_LOCATION (ret, loc);
16658 	  add_stmt (ret);
16659 	  return ret;
16660 	}
16661     }
16662   if (!flag_openmp)  /* flag_openmp_simd  */
16663     {
16664       c_parser_skip_to_pragma_eol (parser, false);
16665       return NULL_TREE;
16666     }
16667 
16668   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16669   if (cclauses)
16670     {
16671       omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
16672       clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
16673     }
16674 
16675   block = c_begin_compound_stmt (true);
16676   ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL,
16677 			       if_p);
16678   block = c_end_compound_stmt (loc, block, true);
16679   add_stmt (block);
16680 
16681   return ret;
16682 }
16683 
16684 /* OpenMP 4.0:
16685    # pragma omp teams teams-clause[optseq] new-line
16686      structured-block  */
16687 
16688 #define OMP_TEAMS_CLAUSE_MASK					\
16689 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
16690 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
16691 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
16692 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
16693 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS)	\
16694 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT)	\
16695 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16696 
16697 static tree
16698 c_parser_omp_teams (location_t loc, c_parser *parser,
16699 		    char *p_name, omp_clause_mask mask, tree *cclauses,
16700 		    bool *if_p)
16701 {
16702   tree clauses, block, ret;
16703 
16704   strcat (p_name, " teams");
16705   mask |= OMP_TEAMS_CLAUSE_MASK;
16706 
16707   if (c_parser_next_token_is (parser, CPP_NAME))
16708     {
16709       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16710       if (strcmp (p, "distribute") == 0)
16711 	{
16712 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16713 	  if (cclauses == NULL)
16714 	    cclauses = cclauses_buf;
16715 
16716 	  c_parser_consume_token (parser);
16717 	  if (!flag_openmp)  /* flag_openmp_simd  */
16718 	    return c_parser_omp_distribute (loc, parser, p_name, mask,
16719 					    cclauses, if_p);
16720 	  block = c_begin_compound_stmt (true);
16721 	  ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses,
16722 					 if_p);
16723 	  block = c_end_compound_stmt (loc, block, true);
16724 	  if (ret == NULL)
16725 	    return ret;
16726 	  clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
16727 	  ret = make_node (OMP_TEAMS);
16728 	  TREE_TYPE (ret) = void_type_node;
16729 	  OMP_TEAMS_CLAUSES (ret) = clauses;
16730 	  OMP_TEAMS_BODY (ret) = block;
16731 	  OMP_TEAMS_COMBINED (ret) = 1;
16732 	  return add_stmt (ret);
16733 	}
16734     }
16735   if (!flag_openmp)  /* flag_openmp_simd  */
16736     {
16737       c_parser_skip_to_pragma_eol (parser, false);
16738       return NULL_TREE;
16739     }
16740 
16741   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16742   if (cclauses)
16743     {
16744       omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
16745       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
16746     }
16747 
16748   tree stmt = make_node (OMP_TEAMS);
16749   TREE_TYPE (stmt) = void_type_node;
16750   OMP_TEAMS_CLAUSES (stmt) = clauses;
16751   OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
16752 
16753   return add_stmt (stmt);
16754 }
16755 
16756 /* OpenMP 4.0:
16757    # pragma omp target data target-data-clause[optseq] new-line
16758      structured-block  */
16759 
16760 #define OMP_TARGET_DATA_CLAUSE_MASK				\
16761 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16762 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
16763 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16764 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16765 
16766 static tree
16767 c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p)
16768 {
16769   tree clauses
16770     = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
16771 				"#pragma omp target data");
16772   int map_seen = 0;
16773   for (tree *pc = &clauses; *pc;)
16774     {
16775       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16776 	switch (OMP_CLAUSE_MAP_KIND (*pc))
16777 	  {
16778 	  case GOMP_MAP_TO:
16779 	  case GOMP_MAP_ALWAYS_TO:
16780 	  case GOMP_MAP_FROM:
16781 	  case GOMP_MAP_ALWAYS_FROM:
16782 	  case GOMP_MAP_TOFROM:
16783 	  case GOMP_MAP_ALWAYS_TOFROM:
16784 	  case GOMP_MAP_ALLOC:
16785 	    map_seen = 3;
16786 	    break;
16787 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
16788 	  case GOMP_MAP_ALWAYS_POINTER:
16789 	    break;
16790 	  default:
16791 	    map_seen |= 1;
16792 	    error_at (OMP_CLAUSE_LOCATION (*pc),
16793 		      "%<#pragma omp target data%> with map-type other "
16794 		      "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16795 		      "on %<map%> clause");
16796 	    *pc = OMP_CLAUSE_CHAIN (*pc);
16797 	    continue;
16798 	  }
16799       pc = &OMP_CLAUSE_CHAIN (*pc);
16800     }
16801 
16802   if (map_seen != 3)
16803     {
16804       if (map_seen == 0)
16805 	error_at (loc,
16806 		  "%<#pragma omp target data%> must contain at least "
16807 		  "one %<map%> clause");
16808       return NULL_TREE;
16809     }
16810 
16811   tree stmt = make_node (OMP_TARGET_DATA);
16812   TREE_TYPE (stmt) = void_type_node;
16813   OMP_TARGET_DATA_CLAUSES (stmt) = clauses;
16814   keep_next_level ();
16815   tree block = c_begin_compound_stmt (true);
16816   add_stmt (c_parser_omp_structured_block (parser, if_p));
16817   OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
16818 
16819   SET_EXPR_LOCATION (stmt, loc);
16820   return add_stmt (stmt);
16821 }
16822 
16823 /* OpenMP 4.0:
16824    # pragma omp target update target-update-clause[optseq] new-line */
16825 
16826 #define OMP_TARGET_UPDATE_CLAUSE_MASK				\
16827 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM)		\
16828 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)		\
16829 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16830 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16831 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16832 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16833 
16834 static bool
16835 c_parser_omp_target_update (location_t loc, c_parser *parser,
16836 			    enum pragma_context context)
16837 {
16838   if (context == pragma_stmt)
16839     {
16840       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16841 		"omp target update");
16842       c_parser_skip_to_pragma_eol (parser, false);
16843       return false;
16844     }
16845 
16846   tree clauses
16847     = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
16848 				"#pragma omp target update");
16849   if (omp_find_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
16850       && omp_find_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
16851     {
16852       error_at (loc,
16853 		"%<#pragma omp target update%> must contain at least one "
16854 		"%<from%> or %<to%> clauses");
16855       return false;
16856     }
16857 
16858   tree stmt = make_node (OMP_TARGET_UPDATE);
16859   TREE_TYPE (stmt) = void_type_node;
16860   OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
16861   SET_EXPR_LOCATION (stmt, loc);
16862   add_stmt (stmt);
16863   return false;
16864 }
16865 
16866 /* OpenMP 4.5:
16867    # pragma omp target enter data target-data-clause[optseq] new-line  */
16868 
16869 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK			\
16870 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16871 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
16872 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16873 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16874 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16875 
16876 static tree
16877 c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
16878 				enum pragma_context context)
16879 {
16880   bool data_seen = false;
16881   if (c_parser_next_token_is (parser, CPP_NAME))
16882     {
16883       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16884       if (strcmp (p, "data") == 0)
16885 	{
16886 	  c_parser_consume_token (parser);
16887 	  data_seen = true;
16888 	}
16889     }
16890   if (!data_seen)
16891     {
16892       c_parser_error (parser, "expected %<data%>");
16893       c_parser_skip_to_pragma_eol (parser);
16894       return NULL_TREE;
16895     }
16896 
16897   if (context == pragma_stmt)
16898     {
16899       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16900 		"omp target enter data");
16901       c_parser_skip_to_pragma_eol (parser, false);
16902       return NULL_TREE;
16903     }
16904 
16905   tree clauses
16906     = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK,
16907 				"#pragma omp target enter data");
16908   int map_seen = 0;
16909   for (tree *pc = &clauses; *pc;)
16910     {
16911       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16912 	switch (OMP_CLAUSE_MAP_KIND (*pc))
16913 	  {
16914 	  case GOMP_MAP_TO:
16915 	  case GOMP_MAP_ALWAYS_TO:
16916 	  case GOMP_MAP_ALLOC:
16917 	    map_seen = 3;
16918 	    break;
16919 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
16920 	  case GOMP_MAP_ALWAYS_POINTER:
16921 	    break;
16922 	  default:
16923 	    map_seen |= 1;
16924 	    error_at (OMP_CLAUSE_LOCATION (*pc),
16925 		      "%<#pragma omp target enter data%> with map-type other "
16926 		      "than %<to%> or %<alloc%> on %<map%> clause");
16927 	    *pc = OMP_CLAUSE_CHAIN (*pc);
16928 	    continue;
16929 	  }
16930       pc = &OMP_CLAUSE_CHAIN (*pc);
16931     }
16932 
16933   if (map_seen != 3)
16934     {
16935       if (map_seen == 0)
16936 	error_at (loc,
16937 		  "%<#pragma omp target enter data%> must contain at least "
16938 		  "one %<map%> clause");
16939       return NULL_TREE;
16940     }
16941 
16942   tree stmt = make_node (OMP_TARGET_ENTER_DATA);
16943   TREE_TYPE (stmt) = void_type_node;
16944   OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses;
16945   SET_EXPR_LOCATION (stmt, loc);
16946   add_stmt (stmt);
16947   return stmt;
16948 }
16949 
16950 /* OpenMP 4.5:
16951    # pragma omp target exit data target-data-clause[optseq] new-line  */
16952 
16953 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK			\
16954 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
16955 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
16956 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
16957 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
16958 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16959 
16960 static tree
16961 c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
16962 			       enum pragma_context context)
16963 {
16964   bool data_seen = false;
16965   if (c_parser_next_token_is (parser, CPP_NAME))
16966     {
16967       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16968       if (strcmp (p, "data") == 0)
16969 	{
16970 	  c_parser_consume_token (parser);
16971 	  data_seen = true;
16972 	}
16973     }
16974   if (!data_seen)
16975     {
16976       c_parser_error (parser, "expected %<data%>");
16977       c_parser_skip_to_pragma_eol (parser);
16978       return NULL_TREE;
16979     }
16980 
16981   if (context == pragma_stmt)
16982     {
16983       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16984 		"omp target exit data");
16985       c_parser_skip_to_pragma_eol (parser, false);
16986       return NULL_TREE;
16987     }
16988 
16989   tree clauses
16990     = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK,
16991 				"#pragma omp target exit data");
16992 
16993   int map_seen = 0;
16994   for (tree *pc = &clauses; *pc;)
16995     {
16996       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16997 	switch (OMP_CLAUSE_MAP_KIND (*pc))
16998 	  {
16999 	  case GOMP_MAP_FROM:
17000 	  case GOMP_MAP_ALWAYS_FROM:
17001 	  case GOMP_MAP_RELEASE:
17002 	  case GOMP_MAP_DELETE:
17003 	    map_seen = 3;
17004 	    break;
17005 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
17006 	  case GOMP_MAP_ALWAYS_POINTER:
17007 	    break;
17008 	  default:
17009 	    map_seen |= 1;
17010 	    error_at (OMP_CLAUSE_LOCATION (*pc),
17011 		      "%<#pragma omp target exit data%> with map-type other "
17012 		      "than %<from%>, %<release%> or %<delete%> on %<map%>"
17013 		      " clause");
17014 	    *pc = OMP_CLAUSE_CHAIN (*pc);
17015 	    continue;
17016 	  }
17017       pc = &OMP_CLAUSE_CHAIN (*pc);
17018     }
17019 
17020   if (map_seen != 3)
17021     {
17022       if (map_seen == 0)
17023 	error_at (loc,
17024 		  "%<#pragma omp target exit data%> must contain at least one "
17025 		  "%<map%> clause");
17026       return NULL_TREE;
17027     }
17028 
17029   tree stmt = make_node (OMP_TARGET_EXIT_DATA);
17030   TREE_TYPE (stmt) = void_type_node;
17031   OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses;
17032   SET_EXPR_LOCATION (stmt, loc);
17033   add_stmt (stmt);
17034   return stmt;
17035 }
17036 
17037 /* OpenMP 4.0:
17038    # pragma omp target target-clause[optseq] new-line
17039      structured-block  */
17040 
17041 #define OMP_TARGET_CLAUSE_MASK					\
17042 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)	\
17043 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)		\
17044 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
17045 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
17046 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)	\
17047 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
17048 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
17049 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP)	\
17050 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
17051 
17052 static bool
17053 c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p)
17054 {
17055   location_t loc = c_parser_peek_token (parser)->location;
17056   c_parser_consume_pragma (parser);
17057   tree *pc = NULL, stmt, block;
17058 
17059   if (context != pragma_stmt && context != pragma_compound)
17060     {
17061       c_parser_error (parser, "expected declaration specifiers");
17062       c_parser_skip_to_pragma_eol (parser);
17063       return false;
17064     }
17065 
17066   if (c_parser_next_token_is (parser, CPP_NAME))
17067     {
17068       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17069       enum tree_code ccode = ERROR_MARK;
17070 
17071       if (strcmp (p, "teams") == 0)
17072 	ccode = OMP_TEAMS;
17073       else if (strcmp (p, "parallel") == 0)
17074 	ccode = OMP_PARALLEL;
17075       else if (strcmp (p, "simd") == 0)
17076 	ccode = OMP_SIMD;
17077       if (ccode != ERROR_MARK)
17078 	{
17079 	  tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
17080 	  char p_name[sizeof ("#pragma omp target teams distribute "
17081 			      "parallel for simd")];
17082 
17083 	  c_parser_consume_token (parser);
17084 	  strcpy (p_name, "#pragma omp target");
17085 	  if (!flag_openmp)  /* flag_openmp_simd  */
17086 	    {
17087 	      tree stmt;
17088 	      switch (ccode)
17089 		{
17090 		case OMP_TEAMS:
17091 		  stmt = c_parser_omp_teams (loc, parser, p_name,
17092 					     OMP_TARGET_CLAUSE_MASK,
17093 					     cclauses, if_p);
17094 		  break;
17095 		case OMP_PARALLEL:
17096 		  stmt = c_parser_omp_parallel (loc, parser, p_name,
17097 						OMP_TARGET_CLAUSE_MASK,
17098 						cclauses, if_p);
17099 		  break;
17100 		case OMP_SIMD:
17101 		  stmt = c_parser_omp_simd (loc, parser, p_name,
17102 					    OMP_TARGET_CLAUSE_MASK,
17103 					    cclauses, if_p);
17104 		  break;
17105 		default:
17106 		  gcc_unreachable ();
17107 		}
17108 	      return stmt != NULL_TREE;
17109 	    }
17110 	  keep_next_level ();
17111 	  tree block = c_begin_compound_stmt (true), ret;
17112 	  switch (ccode)
17113 	    {
17114 	    case OMP_TEAMS:
17115 	      ret = c_parser_omp_teams (loc, parser, p_name,
17116 					OMP_TARGET_CLAUSE_MASK, cclauses,
17117 					if_p);
17118 	      break;
17119 	    case OMP_PARALLEL:
17120 	      ret = c_parser_omp_parallel (loc, parser, p_name,
17121 					   OMP_TARGET_CLAUSE_MASK, cclauses,
17122 					   if_p);
17123 	      break;
17124 	    case OMP_SIMD:
17125 	      ret = c_parser_omp_simd (loc, parser, p_name,
17126 				       OMP_TARGET_CLAUSE_MASK, cclauses,
17127 				       if_p);
17128 	      break;
17129 	    default:
17130 	      gcc_unreachable ();
17131 	    }
17132 	  block = c_end_compound_stmt (loc, block, true);
17133 	  if (ret == NULL_TREE)
17134 	    return false;
17135 	  if (ccode == OMP_TEAMS)
17136 	    {
17137 	      /* For combined target teams, ensure the num_teams and
17138 		 thread_limit clause expressions are evaluated on the host,
17139 		 before entering the target construct.  */
17140 	      tree c;
17141 	      for (c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
17142 		   c; c = OMP_CLAUSE_CHAIN (c))
17143 		if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
17144 		     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT)
17145 		    && TREE_CODE (OMP_CLAUSE_OPERAND (c, 0)) != INTEGER_CST)
17146 		  {
17147 		    tree expr = OMP_CLAUSE_OPERAND (c, 0);
17148 		    tree tmp = create_tmp_var_raw (TREE_TYPE (expr));
17149 		    expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp,
17150 				   expr, NULL_TREE, NULL_TREE);
17151 		    add_stmt (expr);
17152 		    OMP_CLAUSE_OPERAND (c, 0) = expr;
17153 		    tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c),
17154 						OMP_CLAUSE_FIRSTPRIVATE);
17155 		    OMP_CLAUSE_DECL (tc) = tmp;
17156 		    OMP_CLAUSE_CHAIN (tc)
17157 		      = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
17158 		    cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc;
17159 		  }
17160 	    }
17161 	  tree stmt = make_node (OMP_TARGET);
17162 	  TREE_TYPE (stmt) = void_type_node;
17163 	  OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
17164 	  OMP_TARGET_BODY (stmt) = block;
17165 	  OMP_TARGET_COMBINED (stmt) = 1;
17166 	  add_stmt (stmt);
17167 	  pc = &OMP_TARGET_CLAUSES (stmt);
17168 	  goto check_clauses;
17169 	}
17170       else if (!flag_openmp)  /* flag_openmp_simd  */
17171 	{
17172 	  c_parser_skip_to_pragma_eol (parser, false);
17173 	  return false;
17174 	}
17175       else if (strcmp (p, "data") == 0)
17176 	{
17177 	  c_parser_consume_token (parser);
17178 	  c_parser_omp_target_data (loc, parser, if_p);
17179 	  return true;
17180 	}
17181       else if (strcmp (p, "enter") == 0)
17182 	{
17183 	  c_parser_consume_token (parser);
17184 	  c_parser_omp_target_enter_data (loc, parser, context);
17185 	  return false;
17186 	}
17187       else if (strcmp (p, "exit") == 0)
17188 	{
17189 	  c_parser_consume_token (parser);
17190 	  c_parser_omp_target_exit_data (loc, parser, context);
17191 	  return false;
17192 	}
17193       else if (strcmp (p, "update") == 0)
17194 	{
17195 	  c_parser_consume_token (parser);
17196 	  return c_parser_omp_target_update (loc, parser, context);
17197 	}
17198     }
17199   if (!flag_openmp) /* flag_openmp_simd  */
17200     {
17201       c_parser_skip_to_pragma_eol (parser, false);
17202       return false;
17203     }
17204 
17205   stmt = make_node (OMP_TARGET);
17206   TREE_TYPE (stmt) = void_type_node;
17207 
17208   OMP_TARGET_CLAUSES (stmt)
17209     = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
17210 				"#pragma omp target");
17211   pc = &OMP_TARGET_CLAUSES (stmt);
17212   keep_next_level ();
17213   block = c_begin_compound_stmt (true);
17214   add_stmt (c_parser_omp_structured_block (parser, if_p));
17215   OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
17216 
17217   SET_EXPR_LOCATION (stmt, loc);
17218   add_stmt (stmt);
17219 
17220 check_clauses:
17221   while (*pc)
17222     {
17223       if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
17224 	switch (OMP_CLAUSE_MAP_KIND (*pc))
17225 	  {
17226 	  case GOMP_MAP_TO:
17227 	  case GOMP_MAP_ALWAYS_TO:
17228 	  case GOMP_MAP_FROM:
17229 	  case GOMP_MAP_ALWAYS_FROM:
17230 	  case GOMP_MAP_TOFROM:
17231 	  case GOMP_MAP_ALWAYS_TOFROM:
17232 	  case GOMP_MAP_ALLOC:
17233 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
17234 	  case GOMP_MAP_ALWAYS_POINTER:
17235 	    break;
17236 	  default:
17237 	    error_at (OMP_CLAUSE_LOCATION (*pc),
17238 		      "%<#pragma omp target%> with map-type other "
17239 		      "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17240 		      "on %<map%> clause");
17241 	    *pc = OMP_CLAUSE_CHAIN (*pc);
17242 	    continue;
17243 	  }
17244       pc = &OMP_CLAUSE_CHAIN (*pc);
17245     }
17246   return true;
17247 }
17248 
17249 /* OpenMP 4.0:
17250    # pragma omp declare simd declare-simd-clauses[optseq] new-line  */
17251 
17252 #define OMP_DECLARE_SIMD_CLAUSE_MASK				\
17253 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN)	\
17254 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)	\
17255 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)	\
17256 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)	\
17257 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH)	\
17258 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17259 
17260 static void
17261 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
17262 {
17263   auto_vec<c_token> clauses;
17264   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17265     {
17266       c_token *token = c_parser_peek_token (parser);
17267       if (token->type == CPP_EOF)
17268 	{
17269 	  c_parser_skip_to_pragma_eol (parser);
17270 	  return;
17271 	}
17272       clauses.safe_push (*token);
17273       c_parser_consume_token (parser);
17274     }
17275   clauses.safe_push (*c_parser_peek_token (parser));
17276   c_parser_skip_to_pragma_eol (parser);
17277 
17278   while (c_parser_next_token_is (parser, CPP_PRAGMA))
17279     {
17280       if (c_parser_peek_token (parser)->pragma_kind
17281 	  != PRAGMA_OMP_DECLARE
17282 	  || c_parser_peek_2nd_token (parser)->type != CPP_NAME
17283 	  || strcmp (IDENTIFIER_POINTER
17284 				(c_parser_peek_2nd_token (parser)->value),
17285 		     "simd") != 0)
17286 	{
17287 	  c_parser_error (parser,
17288 			  "%<#pragma omp declare simd%> must be followed by "
17289 			  "function declaration or definition or another "
17290 			  "%<#pragma omp declare simd%>");
17291 	  return;
17292 	}
17293       c_parser_consume_pragma (parser);
17294       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17295 	{
17296 	  c_token *token = c_parser_peek_token (parser);
17297 	  if (token->type == CPP_EOF)
17298 	    {
17299 	      c_parser_skip_to_pragma_eol (parser);
17300 	      return;
17301 	    }
17302 	  clauses.safe_push (*token);
17303 	  c_parser_consume_token (parser);
17304 	}
17305       clauses.safe_push (*c_parser_peek_token (parser));
17306       c_parser_skip_to_pragma_eol (parser);
17307     }
17308 
17309   /* Make sure nothing tries to read past the end of the tokens.  */
17310   c_token eof_token;
17311   memset (&eof_token, 0, sizeof (eof_token));
17312   eof_token.type = CPP_EOF;
17313   clauses.safe_push (eof_token);
17314   clauses.safe_push (eof_token);
17315 
17316   switch (context)
17317     {
17318     case pragma_external:
17319       if (c_parser_next_token_is (parser, CPP_KEYWORD)
17320 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
17321 	{
17322 	  int ext = disable_extension_diagnostics ();
17323 	  do
17324 	    c_parser_consume_token (parser);
17325 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
17326 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
17327 	  c_parser_declaration_or_fndef (parser, true, true, true, false, true,
17328 					 NULL, clauses);
17329 	  restore_extension_diagnostics (ext);
17330 	}
17331       else
17332 	c_parser_declaration_or_fndef (parser, true, true, true, false, true,
17333 				       NULL, clauses);
17334       break;
17335     case pragma_struct:
17336     case pragma_param:
17337     case pragma_stmt:
17338       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
17339 			      "function declaration or definition");
17340       break;
17341     case pragma_compound:
17342       if (c_parser_next_token_is (parser, CPP_KEYWORD)
17343 	  && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
17344 	{
17345 	  int ext = disable_extension_diagnostics ();
17346 	  do
17347 	    c_parser_consume_token (parser);
17348 	  while (c_parser_next_token_is (parser, CPP_KEYWORD)
17349 		 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
17350 	  if (c_parser_next_tokens_start_declaration (parser))
17351 	    {
17352 	      c_parser_declaration_or_fndef (parser, true, true, true, true,
17353 					     true, NULL, clauses);
17354 	      restore_extension_diagnostics (ext);
17355 	      break;
17356 	    }
17357 	  restore_extension_diagnostics (ext);
17358 	}
17359       else if (c_parser_next_tokens_start_declaration (parser))
17360 	{
17361 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true,
17362 					 NULL, clauses);
17363 	  break;
17364 	}
17365       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
17366 			      "function declaration or definition");
17367       break;
17368     default:
17369       gcc_unreachable ();
17370     }
17371 }
17372 
17373 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17374    and put that into "omp declare simd" attribute.  */
17375 
17376 static void
17377 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
17378 			   vec<c_token> clauses)
17379 {
17380   /* Normally first token is CPP_NAME "simd".  CPP_EOF there indicates
17381      error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17382      has already processed the tokens.  */
17383   if (clauses.exists () && clauses[0].type == CPP_EOF)
17384     return;
17385   if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
17386     {
17387       error ("%<#pragma omp declare simd%> not immediately followed by "
17388 	     "a function declaration or definition");
17389       clauses[0].type = CPP_EOF;
17390       return;
17391     }
17392   if (clauses.exists () && clauses[0].type != CPP_NAME)
17393     {
17394       error_at (DECL_SOURCE_LOCATION (fndecl),
17395 		"%<#pragma omp declare simd%> not immediately followed by "
17396 		"a single function declaration or definition");
17397       clauses[0].type = CPP_EOF;
17398       return;
17399     }
17400 
17401   if (parms == NULL_TREE)
17402     parms = DECL_ARGUMENTS (fndecl);
17403 
17404   unsigned int tokens_avail = parser->tokens_avail;
17405   gcc_assert (parser->tokens == &parser->tokens_buf[0]);
17406 
17407 
17408   parser->tokens = clauses.address ();
17409   parser->tokens_avail = clauses.length ();
17410 
17411   /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end.  */
17412   while (parser->tokens_avail > 3)
17413     {
17414       c_token *token = c_parser_peek_token (parser);
17415       gcc_assert (token->type == CPP_NAME
17416 		  && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
17417       c_parser_consume_token (parser);
17418       parser->in_pragma = true;
17419 
17420       tree c = NULL_TREE;
17421       c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
17422 				      "#pragma omp declare simd");
17423       c = c_omp_declare_simd_clauses_to_numbers (parms, c);
17424       if (c != NULL_TREE)
17425 	c = tree_cons (NULL_TREE, c, NULL_TREE);
17426       c = build_tree_list (get_identifier ("omp declare simd"), c);
17427       TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
17428       DECL_ATTRIBUTES (fndecl) = c;
17429     }
17430 
17431   parser->tokens = &parser->tokens_buf[0];
17432   parser->tokens_avail = tokens_avail;
17433   if (clauses.exists ())
17434     clauses[0].type = CPP_PRAGMA;
17435 }
17436 
17437 
17438 /* OpenMP 4.0:
17439    # pragma omp declare target new-line
17440    declarations and definitions
17441    # pragma omp end declare target new-line
17442 
17443    OpenMP 4.5:
17444    # pragma omp declare target ( extended-list ) new-line
17445 
17446    # pragma omp declare target declare-target-clauses[seq] new-line  */
17447 
17448 #define OMP_DECLARE_TARGET_CLAUSE_MASK				\
17449 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)		\
17450 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17451 
17452 static void
17453 c_parser_omp_declare_target (c_parser *parser)
17454 {
17455   location_t loc = c_parser_peek_token (parser)->location;
17456   tree clauses = NULL_TREE;
17457   if (c_parser_next_token_is (parser, CPP_NAME))
17458     clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK,
17459 					"#pragma omp declare target");
17460   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
17461     {
17462       clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
17463 					      clauses);
17464       clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
17465       c_parser_skip_to_pragma_eol (parser);
17466     }
17467   else
17468     {
17469       c_parser_skip_to_pragma_eol (parser);
17470       current_omp_declare_target_attribute++;
17471       return;
17472     }
17473   if (current_omp_declare_target_attribute)
17474     error_at (loc, "%<#pragma omp declare target%> with clauses in between "
17475 		   "%<#pragma omp declare target%> without clauses and "
17476 		   "%<#pragma omp end declare target%>");
17477   for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
17478     {
17479       tree t = OMP_CLAUSE_DECL (c), id;
17480       tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
17481       tree at2 = lookup_attribute ("omp declare target link",
17482 				   DECL_ATTRIBUTES (t));
17483       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
17484 	{
17485 	  id = get_identifier ("omp declare target link");
17486 	  std::swap (at1, at2);
17487 	}
17488       else
17489 	id = get_identifier ("omp declare target");
17490       if (at2)
17491 	{
17492 	  error_at (OMP_CLAUSE_LOCATION (c),
17493 		    "%qD specified both in declare target %<link%> and %<to%>"
17494 		    " clauses", t);
17495 	  continue;
17496 	}
17497       if (!at1)
17498 	{
17499 	  DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
17500 	  if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
17501 	    continue;
17502 
17503 	  symtab_node *node = symtab_node::get (t);
17504 	  if (node != NULL)
17505 	    {
17506 	      node->offloadable = 1;
17507 	      if (ENABLE_OFFLOADING)
17508 		{
17509 		  g->have_offload = true;
17510 		  if (is_a <varpool_node *> (node))
17511 		    vec_safe_push (offload_vars, t);
17512 		}
17513 	    }
17514 	}
17515     }
17516 }
17517 
17518 static void
17519 c_parser_omp_end_declare_target (c_parser *parser)
17520 {
17521   location_t loc = c_parser_peek_token (parser)->location;
17522   c_parser_consume_pragma (parser);
17523   if (c_parser_next_token_is (parser, CPP_NAME)
17524       && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
17525 		 "declare") == 0)
17526     {
17527       c_parser_consume_token (parser);
17528       if (c_parser_next_token_is (parser, CPP_NAME)
17529 	  && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
17530 		     "target") == 0)
17531 	c_parser_consume_token (parser);
17532       else
17533 	{
17534 	  c_parser_error (parser, "expected %<target%>");
17535 	  c_parser_skip_to_pragma_eol (parser);
17536 	  return;
17537 	}
17538     }
17539   else
17540     {
17541       c_parser_error (parser, "expected %<declare%>");
17542       c_parser_skip_to_pragma_eol (parser);
17543       return;
17544     }
17545   c_parser_skip_to_pragma_eol (parser);
17546   if (!current_omp_declare_target_attribute)
17547     error_at (loc, "%<#pragma omp end declare target%> without corresponding "
17548 		   "%<#pragma omp declare target%>");
17549   else
17550     current_omp_declare_target_attribute--;
17551 }
17552 
17553 
17554 /* OpenMP 4.0
17555    #pragma omp declare reduction (reduction-id : typename-list : expression) \
17556       initializer-clause[opt] new-line
17557 
17558    initializer-clause:
17559       initializer (omp_priv = initializer)
17560       initializer (function-name (argument-list))  */
17561 
17562 static void
17563 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
17564 {
17565   unsigned int tokens_avail = 0, i;
17566   vec<tree> types = vNULL;
17567   vec<c_token> clauses = vNULL;
17568   enum tree_code reduc_code = ERROR_MARK;
17569   tree reduc_id = NULL_TREE;
17570   tree type;
17571   location_t rloc = c_parser_peek_token (parser)->location;
17572 
17573   if (context == pragma_struct || context == pragma_param)
17574     {
17575       error ("%<#pragma omp declare reduction%> not at file or block scope");
17576       goto fail;
17577     }
17578 
17579   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17580     goto fail;
17581 
17582   switch (c_parser_peek_token (parser)->type)
17583     {
17584     case CPP_PLUS:
17585       reduc_code = PLUS_EXPR;
17586       break;
17587     case CPP_MULT:
17588       reduc_code = MULT_EXPR;
17589       break;
17590     case CPP_MINUS:
17591       reduc_code = MINUS_EXPR;
17592       break;
17593     case CPP_AND:
17594       reduc_code = BIT_AND_EXPR;
17595       break;
17596     case CPP_XOR:
17597       reduc_code = BIT_XOR_EXPR;
17598       break;
17599     case CPP_OR:
17600       reduc_code = BIT_IOR_EXPR;
17601       break;
17602     case CPP_AND_AND:
17603       reduc_code = TRUTH_ANDIF_EXPR;
17604       break;
17605     case CPP_OR_OR:
17606       reduc_code = TRUTH_ORIF_EXPR;
17607       break;
17608     case CPP_NAME:
17609       const char *p;
17610       p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17611       if (strcmp (p, "min") == 0)
17612 	{
17613 	  reduc_code = MIN_EXPR;
17614 	  break;
17615 	}
17616       if (strcmp (p, "max") == 0)
17617 	{
17618 	  reduc_code = MAX_EXPR;
17619 	  break;
17620 	}
17621       reduc_id = c_parser_peek_token (parser)->value;
17622       break;
17623     default:
17624       c_parser_error (parser,
17625 		      "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17626 		      "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17627       goto fail;
17628     }
17629 
17630   tree orig_reduc_id, reduc_decl;
17631   orig_reduc_id = reduc_id;
17632   reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
17633   reduc_decl = c_omp_reduction_decl (reduc_id);
17634   c_parser_consume_token (parser);
17635 
17636   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
17637     goto fail;
17638 
17639   while (true)
17640     {
17641       location_t loc = c_parser_peek_token (parser)->location;
17642       struct c_type_name *ctype = c_parser_type_name (parser);
17643       if (ctype != NULL)
17644 	{
17645 	  type = groktypename (ctype, NULL, NULL);
17646 	  if (type == error_mark_node)
17647 	    ;
17648 	  else if ((INTEGRAL_TYPE_P (type)
17649 		    || TREE_CODE (type) == REAL_TYPE
17650 		    || TREE_CODE (type) == COMPLEX_TYPE)
17651 		   && orig_reduc_id == NULL_TREE)
17652 	    error_at (loc, "predeclared arithmetic type in "
17653 			   "%<#pragma omp declare reduction%>");
17654 	  else if (TREE_CODE (type) == FUNCTION_TYPE
17655 		   || TREE_CODE (type) == ARRAY_TYPE)
17656 	    error_at (loc, "function or array type in "
17657 		      "%<#pragma omp declare reduction%>");
17658 	  else if (TYPE_ATOMIC (type))
17659 	    error_at (loc, "%<_Atomic%> qualified type in "
17660 			   "%<#pragma omp declare reduction%>");
17661 	  else if (TYPE_QUALS_NO_ADDR_SPACE (type))
17662 	    error_at (loc, "const, volatile or restrict qualified type in "
17663 			   "%<#pragma omp declare reduction%>");
17664 	  else
17665 	    {
17666 	      tree t;
17667 	      for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
17668 		if (comptypes (TREE_PURPOSE (t), type))
17669 		  {
17670 		    error_at (loc, "redeclaration of %qs "
17671 				   "%<#pragma omp declare reduction%> for "
17672 				   "type %qT",
17673 				   IDENTIFIER_POINTER (reduc_id)
17674 				   + sizeof ("omp declare reduction ") - 1,
17675 				   type);
17676 		    location_t ploc
17677 		      = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
17678 							    0));
17679 		    error_at (ploc, "previous %<#pragma omp declare "
17680 				    "reduction%>");
17681 		    break;
17682 		  }
17683 	      if (t == NULL_TREE)
17684 		types.safe_push (type);
17685 	    }
17686 	  if (c_parser_next_token_is (parser, CPP_COMMA))
17687 	    c_parser_consume_token (parser);
17688 	  else
17689 	    break;
17690 	}
17691       else
17692 	break;
17693     }
17694 
17695   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
17696       || types.is_empty ())
17697     {
17698      fail:
17699       clauses.release ();
17700       types.release ();
17701       while (true)
17702 	{
17703 	  c_token *token = c_parser_peek_token (parser);
17704 	  if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
17705 	    break;
17706 	  c_parser_consume_token (parser);
17707 	}
17708       c_parser_skip_to_pragma_eol (parser);
17709       return;
17710     }
17711 
17712   if (types.length () > 1)
17713     {
17714       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17715 	{
17716 	  c_token *token = c_parser_peek_token (parser);
17717 	  if (token->type == CPP_EOF)
17718 	    goto fail;
17719 	  clauses.safe_push (*token);
17720 	  c_parser_consume_token (parser);
17721 	}
17722       clauses.safe_push (*c_parser_peek_token (parser));
17723       c_parser_skip_to_pragma_eol (parser);
17724 
17725       /* Make sure nothing tries to read past the end of the tokens.  */
17726       c_token eof_token;
17727       memset (&eof_token, 0, sizeof (eof_token));
17728       eof_token.type = CPP_EOF;
17729       clauses.safe_push (eof_token);
17730       clauses.safe_push (eof_token);
17731     }
17732 
17733   int errs = errorcount;
17734   FOR_EACH_VEC_ELT (types, i, type)
17735     {
17736       tokens_avail = parser->tokens_avail;
17737       gcc_assert (parser->tokens == &parser->tokens_buf[0]);
17738       if (!clauses.is_empty ())
17739 	{
17740 	  parser->tokens = clauses.address ();
17741 	  parser->tokens_avail = clauses.length ();
17742 	  parser->in_pragma = true;
17743 	}
17744 
17745       bool nested = current_function_decl != NULL_TREE;
17746       if (nested)
17747 	c_push_function_context ();
17748       tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
17749 				reduc_id, default_function_type);
17750       current_function_decl = fndecl;
17751       allocate_struct_function (fndecl, true);
17752       push_scope ();
17753       tree stmt = push_stmt_list ();
17754       /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17755 	 warn about these.  */
17756       tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
17757 				 get_identifier ("omp_out"), type);
17758       DECL_ARTIFICIAL (omp_out) = 1;
17759       DECL_CONTEXT (omp_out) = fndecl;
17760       pushdecl (omp_out);
17761       tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
17762 				get_identifier ("omp_in"), type);
17763       DECL_ARTIFICIAL (omp_in) = 1;
17764       DECL_CONTEXT (omp_in) = fndecl;
17765       pushdecl (omp_in);
17766       struct c_expr combiner = c_parser_expression (parser);
17767       struct c_expr initializer;
17768       tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
17769       bool bad = false;
17770       initializer.set_error ();
17771       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
17772 	bad = true;
17773       else if (c_parser_next_token_is (parser, CPP_NAME)
17774 	       && strcmp (IDENTIFIER_POINTER
17775 				(c_parser_peek_token (parser)->value),
17776 			  "initializer") == 0)
17777 	{
17778 	  c_parser_consume_token (parser);
17779 	  pop_scope ();
17780 	  push_scope ();
17781 	  omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
17782 				 get_identifier ("omp_priv"), type);
17783 	  DECL_ARTIFICIAL (omp_priv) = 1;
17784 	  DECL_INITIAL (omp_priv) = error_mark_node;
17785 	  DECL_CONTEXT (omp_priv) = fndecl;
17786 	  pushdecl (omp_priv);
17787 	  omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
17788 				 get_identifier ("omp_orig"), type);
17789 	  DECL_ARTIFICIAL (omp_orig) = 1;
17790 	  DECL_CONTEXT (omp_orig) = fndecl;
17791 	  pushdecl (omp_orig);
17792 	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17793 	    bad = true;
17794 	  else if (!c_parser_next_token_is (parser, CPP_NAME))
17795 	    {
17796 	      c_parser_error (parser, "expected %<omp_priv%> or "
17797 				      "function-name");
17798 	      bad = true;
17799 	    }
17800 	  else if (strcmp (IDENTIFIER_POINTER
17801 				(c_parser_peek_token (parser)->value),
17802 			   "omp_priv") != 0)
17803 	    {
17804 	      if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
17805 		  || c_parser_peek_token (parser)->id_kind != C_ID_ID)
17806 		{
17807 		  c_parser_error (parser, "expected function-name %<(%>");
17808 		  bad = true;
17809 		}
17810 	      else
17811 		initializer = c_parser_postfix_expression (parser);
17812 	      if (initializer.value
17813 		  && TREE_CODE (initializer.value) == CALL_EXPR)
17814 		{
17815 		  int j;
17816 		  tree c = initializer.value;
17817 		  for (j = 0; j < call_expr_nargs (c); j++)
17818 		    {
17819 		      tree a = CALL_EXPR_ARG (c, j);
17820 		      STRIP_NOPS (a);
17821 		      if (TREE_CODE (a) == ADDR_EXPR
17822 			  && TREE_OPERAND (a, 0) == omp_priv)
17823 			break;
17824 		    }
17825 		  if (j == call_expr_nargs (c))
17826 		    error ("one of the initializer call arguments should be "
17827 			   "%<&omp_priv%>");
17828 		}
17829 	    }
17830 	  else
17831 	    {
17832 	      c_parser_consume_token (parser);
17833 	      if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
17834 		bad = true;
17835 	      else
17836 		{
17837 		  tree st = push_stmt_list ();
17838 		  location_t loc = c_parser_peek_token (parser)->location;
17839 		  rich_location richloc (line_table, loc);
17840 		  start_init (omp_priv, NULL_TREE, 0, &richloc);
17841 		  struct c_expr init = c_parser_initializer (parser);
17842 		  finish_init ();
17843 		  finish_decl (omp_priv, loc, init.value,
17844 		      	       init.original_type, NULL_TREE);
17845 		  pop_stmt_list (st);
17846 		}
17847 	    }
17848 	  if (!bad
17849 	      && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
17850 	    bad = true;
17851 	}
17852 
17853       if (!bad)
17854 	{
17855 	  c_parser_skip_to_pragma_eol (parser);
17856 
17857 	  tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
17858 			      DECL_INITIAL (reduc_decl));
17859 	  DECL_INITIAL (reduc_decl) = t;
17860 	  DECL_SOURCE_LOCATION (omp_out) = rloc;
17861 	  TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
17862 	  TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
17863 	  TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
17864 	  walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
17865 		     &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
17866 	  if (omp_priv)
17867 	    {
17868 	      DECL_SOURCE_LOCATION (omp_priv) = rloc;
17869 	      TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
17870 	      TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
17871 	      TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
17872 	      walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
17873 			 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
17874 	      walk_tree (&DECL_INITIAL (omp_priv),
17875 			 c_check_omp_declare_reduction_r,
17876 			 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
17877 	    }
17878 	}
17879 
17880       pop_stmt_list (stmt);
17881       pop_scope ();
17882       if (cfun->language != NULL)
17883 	{
17884 	  ggc_free (cfun->language);
17885 	  cfun->language = NULL;
17886 	}
17887       set_cfun (NULL);
17888       current_function_decl = NULL_TREE;
17889       if (nested)
17890 	c_pop_function_context ();
17891 
17892       if (!clauses.is_empty ())
17893 	{
17894 	  parser->tokens = &parser->tokens_buf[0];
17895 	  parser->tokens_avail = tokens_avail;
17896 	}
17897       if (bad)
17898 	goto fail;
17899       if (errs != errorcount)
17900 	break;
17901     }
17902 
17903   clauses.release ();
17904   types.release ();
17905 }
17906 
17907 
17908 /* OpenMP 4.0
17909    #pragma omp declare simd declare-simd-clauses[optseq] new-line
17910    #pragma omp declare reduction (reduction-id : typename-list : expression) \
17911       initializer-clause[opt] new-line
17912    #pragma omp declare target new-line  */
17913 
17914 static void
17915 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
17916 {
17917   c_parser_consume_pragma (parser);
17918   if (c_parser_next_token_is (parser, CPP_NAME))
17919     {
17920       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17921       if (strcmp (p, "simd") == 0)
17922 	{
17923 	  /* c_parser_consume_token (parser); done in
17924 	     c_parser_omp_declare_simd.  */
17925 	  c_parser_omp_declare_simd (parser, context);
17926 	  return;
17927 	}
17928       if (strcmp (p, "reduction") == 0)
17929 	{
17930 	  c_parser_consume_token (parser);
17931 	  c_parser_omp_declare_reduction (parser, context);
17932 	  return;
17933 	}
17934       if (!flag_openmp)  /* flag_openmp_simd  */
17935 	{
17936 	  c_parser_skip_to_pragma_eol (parser, false);
17937 	  return;
17938 	}
17939       if (strcmp (p, "target") == 0)
17940 	{
17941 	  c_parser_consume_token (parser);
17942 	  c_parser_omp_declare_target (parser);
17943 	  return;
17944 	}
17945     }
17946 
17947   c_parser_error (parser, "expected %<simd%> or %<reduction%> "
17948 			  "or %<target%>");
17949   c_parser_skip_to_pragma_eol (parser);
17950 }
17951 
17952 /* OpenMP 4.5:
17953    #pragma omp taskloop taskloop-clause[optseq] new-line
17954      for-loop
17955 
17956    #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17957      for-loop  */
17958 
17959 #define OMP_TASKLOOP_CLAUSE_MASK				\
17960 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)	\
17961 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
17962 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
17963 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
17964 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)	\
17965 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE)	\
17966 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS)	\
17967 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)	\
17968 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED)	\
17969 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
17970 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
17971 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
17972 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)	\
17973 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17974 
17975 static tree
17976 c_parser_omp_taskloop (location_t loc, c_parser *parser,
17977 		       char *p_name, omp_clause_mask mask, tree *cclauses,
17978 		       bool *if_p)
17979 {
17980   tree clauses, block, ret;
17981 
17982   strcat (p_name, " taskloop");
17983   mask |= OMP_TASKLOOP_CLAUSE_MASK;
17984 
17985   if (c_parser_next_token_is (parser, CPP_NAME))
17986     {
17987       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17988 
17989       if (strcmp (p, "simd") == 0)
17990 	{
17991 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
17992 	  if (cclauses == NULL)
17993 	    cclauses = cclauses_buf;
17994 	  mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION);
17995 	  c_parser_consume_token (parser);
17996 	  if (!flag_openmp)  /* flag_openmp_simd  */
17997 	    return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
17998 				      if_p);
17999 	  block = c_begin_compound_stmt (true);
18000 	  ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
18001 	  block = c_end_compound_stmt (loc, block, true);
18002 	  if (ret == NULL)
18003 	    return ret;
18004 	  ret = make_node (OMP_TASKLOOP);
18005 	  TREE_TYPE (ret) = void_type_node;
18006 	  OMP_FOR_BODY (ret) = block;
18007 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
18008 	  SET_EXPR_LOCATION (ret, loc);
18009 	  add_stmt (ret);
18010 	  return ret;
18011 	}
18012     }
18013   if (!flag_openmp)  /* flag_openmp_simd  */
18014     {
18015       c_parser_skip_to_pragma_eol (parser, false);
18016       return NULL_TREE;
18017     }
18018 
18019   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
18020   if (cclauses)
18021     {
18022       omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses);
18023       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
18024     }
18025 
18026   block = c_begin_compound_stmt (true);
18027   ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p);
18028   block = c_end_compound_stmt (loc, block, true);
18029   add_stmt (block);
18030 
18031   return ret;
18032 }
18033 
18034 /* Main entry point to parsing most OpenMP pragmas.  */
18035 
18036 static void
18037 c_parser_omp_construct (c_parser *parser, bool *if_p)
18038 {
18039   enum pragma_kind p_kind;
18040   location_t loc;
18041   tree stmt;
18042   char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
18043   omp_clause_mask mask (0);
18044 
18045   loc = c_parser_peek_token (parser)->location;
18046   p_kind = c_parser_peek_token (parser)->pragma_kind;
18047   c_parser_consume_pragma (parser);
18048 
18049   switch (p_kind)
18050     {
18051     case PRAGMA_OACC_ATOMIC:
18052       c_parser_omp_atomic (loc, parser);
18053       return;
18054     case PRAGMA_OACC_CACHE:
18055       strcpy (p_name, "#pragma acc");
18056       stmt = c_parser_oacc_cache (loc, parser);
18057       break;
18058     case PRAGMA_OACC_DATA:
18059       stmt = c_parser_oacc_data (loc, parser, if_p);
18060       break;
18061     case PRAGMA_OACC_HOST_DATA:
18062       stmt = c_parser_oacc_host_data (loc, parser, if_p);
18063       break;
18064     case PRAGMA_OACC_KERNELS:
18065     case PRAGMA_OACC_PARALLEL:
18066       strcpy (p_name, "#pragma acc");
18067       stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name,
18068 					     if_p);
18069       break;
18070     case PRAGMA_OACC_LOOP:
18071       strcpy (p_name, "#pragma acc");
18072       stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p);
18073       break;
18074     case PRAGMA_OACC_WAIT:
18075       strcpy (p_name, "#pragma wait");
18076       stmt = c_parser_oacc_wait (loc, parser, p_name);
18077       break;
18078     case PRAGMA_OMP_ATOMIC:
18079       c_parser_omp_atomic (loc, parser);
18080       return;
18081     case PRAGMA_OMP_CRITICAL:
18082       stmt = c_parser_omp_critical (loc, parser, if_p);
18083       break;
18084     case PRAGMA_OMP_DISTRIBUTE:
18085       strcpy (p_name, "#pragma omp");
18086       stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p);
18087       break;
18088     case PRAGMA_OMP_FOR:
18089       strcpy (p_name, "#pragma omp");
18090       stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p);
18091       break;
18092     case PRAGMA_OMP_MASTER:
18093       stmt = c_parser_omp_master (loc, parser, if_p);
18094       break;
18095     case PRAGMA_OMP_PARALLEL:
18096       strcpy (p_name, "#pragma omp");
18097       stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p);
18098       break;
18099     case PRAGMA_OMP_SECTIONS:
18100       strcpy (p_name, "#pragma omp");
18101       stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
18102       break;
18103     case PRAGMA_OMP_SIMD:
18104       strcpy (p_name, "#pragma omp");
18105       stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p);
18106       break;
18107     case PRAGMA_OMP_SINGLE:
18108       stmt = c_parser_omp_single (loc, parser, if_p);
18109       break;
18110     case PRAGMA_OMP_TASK:
18111       stmt = c_parser_omp_task (loc, parser, if_p);
18112       break;
18113     case PRAGMA_OMP_TASKGROUP:
18114       stmt = c_parser_omp_taskgroup (parser, if_p);
18115       break;
18116     case PRAGMA_OMP_TASKLOOP:
18117       strcpy (p_name, "#pragma omp");
18118       stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p);
18119       break;
18120     case PRAGMA_OMP_TEAMS:
18121       strcpy (p_name, "#pragma omp");
18122       stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p);
18123       break;
18124     default:
18125       gcc_unreachable ();
18126     }
18127 
18128   if (stmt)
18129     gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
18130 }
18131 
18132 
18133 /* OpenMP 2.5:
18134    # pragma omp threadprivate (variable-list) */
18135 
18136 static void
18137 c_parser_omp_threadprivate (c_parser *parser)
18138 {
18139   tree vars, t;
18140   location_t loc;
18141 
18142   c_parser_consume_pragma (parser);
18143   loc = c_parser_peek_token (parser)->location;
18144   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
18145 
18146   /* Mark every variable in VARS to be assigned thread local storage.  */
18147   for (t = vars; t; t = TREE_CHAIN (t))
18148     {
18149       tree v = TREE_PURPOSE (t);
18150 
18151       /* FIXME diagnostics: Ideally we should keep individual
18152 	 locations for all the variables in the var list to make the
18153 	 following errors more precise.  Perhaps
18154 	 c_parser_omp_var_list_parens() should construct a list of
18155 	 locations to go along with the var list.  */
18156 
18157       /* If V had already been marked threadprivate, it doesn't matter
18158 	 whether it had been used prior to this point.  */
18159       if (!VAR_P (v))
18160 	error_at (loc, "%qD is not a variable", v);
18161       else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
18162 	error_at (loc, "%qE declared %<threadprivate%> after first use", v);
18163       else if (! is_global_var (v))
18164 	error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
18165       else if (TREE_TYPE (v) == error_mark_node)
18166 	;
18167       else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
18168 	error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
18169       else
18170 	{
18171 	  if (! DECL_THREAD_LOCAL_P (v))
18172 	    {
18173 	      set_decl_tls_model (v, decl_default_tls_model (v));
18174 	      /* If rtl has been already set for this var, call
18175 		 make_decl_rtl once again, so that encode_section_info
18176 		 has a chance to look at the new decl flags.  */
18177 	      if (DECL_RTL_SET_P (v))
18178 		make_decl_rtl (v);
18179 	    }
18180 	  C_DECL_THREADPRIVATE_P (v) = 1;
18181 	}
18182     }
18183 
18184   c_parser_skip_to_pragma_eol (parser);
18185 }
18186 
18187 /* Parse a transaction attribute (GCC Extension).
18188 
18189    transaction-attribute:
18190      attributes
18191      [ [ any-word ] ]
18192 
18193    The transactional memory language description is written for C++,
18194    and uses the C++0x attribute syntax.  For compatibility, allow the
18195    bracket style for transactions in C as well.  */
18196 
18197 static tree
18198 c_parser_transaction_attributes (c_parser *parser)
18199 {
18200   tree attr_name, attr = NULL;
18201 
18202   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
18203     return c_parser_attributes (parser);
18204 
18205   if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
18206     return NULL_TREE;
18207   c_parser_consume_token (parser);
18208   if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
18209     goto error1;
18210 
18211   attr_name = c_parser_attribute_any_word (parser);
18212   if (attr_name)
18213     {
18214       c_parser_consume_token (parser);
18215       attr = build_tree_list (attr_name, NULL_TREE);
18216     }
18217   else
18218     c_parser_error (parser, "expected identifier");
18219 
18220   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
18221  error1:
18222   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
18223   return attr;
18224 }
18225 
18226 /* Parse a __transaction_atomic or __transaction_relaxed statement
18227    (GCC Extension).
18228 
18229    transaction-statement:
18230      __transaction_atomic transaction-attribute[opt] compound-statement
18231      __transaction_relaxed compound-statement
18232 
18233    Note that the only valid attribute is: "outer".
18234 */
18235 
18236 static tree
18237 c_parser_transaction (c_parser *parser, enum rid keyword)
18238 {
18239   unsigned int old_in = parser->in_transaction;
18240   unsigned int this_in = 1, new_in;
18241   location_t loc = c_parser_peek_token (parser)->location;
18242   tree stmt, attrs;
18243 
18244   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
18245       || keyword == RID_TRANSACTION_RELAXED)
18246       && c_parser_next_token_is_keyword (parser, keyword));
18247   c_parser_consume_token (parser);
18248 
18249   if (keyword == RID_TRANSACTION_RELAXED)
18250     this_in |= TM_STMT_ATTR_RELAXED;
18251   else
18252     {
18253       attrs = c_parser_transaction_attributes (parser);
18254       if (attrs)
18255 	this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
18256     }
18257 
18258   /* Keep track if we're in the lexical scope of an outer transaction.  */
18259   new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
18260 
18261   parser->in_transaction = new_in;
18262   stmt = c_parser_compound_statement (parser);
18263   parser->in_transaction = old_in;
18264 
18265   if (flag_tm)
18266     stmt = c_finish_transaction (loc, stmt, this_in);
18267   else
18268     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
18269 	"%<__transaction_atomic%> without transactional memory support enabled"
18270 	: "%<__transaction_relaxed %> "
18271 	"without transactional memory support enabled"));
18272 
18273   return stmt;
18274 }
18275 
18276 /* Parse a __transaction_atomic or __transaction_relaxed expression
18277    (GCC Extension).
18278 
18279    transaction-expression:
18280      __transaction_atomic ( expression )
18281      __transaction_relaxed ( expression )
18282 */
18283 
18284 static struct c_expr
18285 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
18286 {
18287   struct c_expr ret;
18288   unsigned int old_in = parser->in_transaction;
18289   unsigned int this_in = 1;
18290   location_t loc = c_parser_peek_token (parser)->location;
18291   tree attrs;
18292 
18293   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
18294       || keyword == RID_TRANSACTION_RELAXED)
18295       && c_parser_next_token_is_keyword (parser, keyword));
18296   c_parser_consume_token (parser);
18297 
18298   if (keyword == RID_TRANSACTION_RELAXED)
18299     this_in |= TM_STMT_ATTR_RELAXED;
18300   else
18301     {
18302       attrs = c_parser_transaction_attributes (parser);
18303       if (attrs)
18304 	this_in |= parse_tm_stmt_attr (attrs, 0);
18305     }
18306 
18307   parser->in_transaction = this_in;
18308   matching_parens parens;
18309   if (parens.require_open (parser))
18310     {
18311       tree expr = c_parser_expression (parser).value;
18312       ret.original_type = TREE_TYPE (expr);
18313       ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
18314       if (this_in & TM_STMT_ATTR_RELAXED)
18315 	TRANSACTION_EXPR_RELAXED (ret.value) = 1;
18316       SET_EXPR_LOCATION (ret.value, loc);
18317       ret.original_code = TRANSACTION_EXPR;
18318       if (!parens.require_close (parser))
18319 	{
18320 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
18321 	  goto error;
18322 	}
18323     }
18324   else
18325     {
18326      error:
18327       ret.set_error ();
18328       ret.original_code = ERROR_MARK;
18329       ret.original_type = NULL;
18330     }
18331   parser->in_transaction = old_in;
18332 
18333   if (!flag_tm)
18334     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
18335 	"%<__transaction_atomic%> without transactional memory support enabled"
18336 	: "%<__transaction_relaxed %> "
18337 	"without transactional memory support enabled"));
18338 
18339   set_c_expr_source_range (&ret, loc, loc);
18340 
18341   return ret;
18342 }
18343 
18344 /* Parse a __transaction_cancel statement (GCC Extension).
18345 
18346    transaction-cancel-statement:
18347      __transaction_cancel transaction-attribute[opt] ;
18348 
18349    Note that the only valid attribute is "outer".
18350 */
18351 
18352 static tree
18353 c_parser_transaction_cancel (c_parser *parser)
18354 {
18355   location_t loc = c_parser_peek_token (parser)->location;
18356   tree attrs;
18357   bool is_outer = false;
18358 
18359   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
18360   c_parser_consume_token (parser);
18361 
18362   attrs = c_parser_transaction_attributes (parser);
18363   if (attrs)
18364     is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
18365 
18366   if (!flag_tm)
18367     {
18368       error_at (loc, "%<__transaction_cancel%> without "
18369 		"transactional memory support enabled");
18370       goto ret_error;
18371     }
18372   else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
18373     {
18374       error_at (loc, "%<__transaction_cancel%> within a "
18375 		"%<__transaction_relaxed%>");
18376       goto ret_error;
18377     }
18378   else if (is_outer)
18379     {
18380       if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
18381 	  && !is_tm_may_cancel_outer (current_function_decl))
18382 	{
18383 	  error_at (loc, "outer %<__transaction_cancel%> not "
18384 		    "within outer %<__transaction_atomic%>");
18385 	  error_at (loc, "  or a %<transaction_may_cancel_outer%> function");
18386 	  goto ret_error;
18387 	}
18388     }
18389   else if (parser->in_transaction == 0)
18390     {
18391       error_at (loc, "%<__transaction_cancel%> not within "
18392 		"%<__transaction_atomic%>");
18393       goto ret_error;
18394     }
18395 
18396   return add_stmt (build_tm_abort_call (loc, is_outer));
18397 
18398  ret_error:
18399   return build1 (NOP_EXPR, void_type_node, error_mark_node);
18400 }
18401 
18402 /* Parse a single source file.  */
18403 
18404 void
18405 c_parse_file (void)
18406 {
18407   /* Use local storage to begin.  If the first token is a pragma, parse it.
18408      If it is #pragma GCC pch_preprocess, then this will load a PCH file
18409      which will cause garbage collection.  */
18410   c_parser tparser;
18411 
18412   memset (&tparser, 0, sizeof tparser);
18413   tparser.tokens = &tparser.tokens_buf[0];
18414   the_parser = &tparser;
18415 
18416   if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
18417     c_parser_pragma_pch_preprocess (&tparser);
18418 
18419   the_parser = ggc_alloc<c_parser> ();
18420   *the_parser = tparser;
18421   if (tparser.tokens == &tparser.tokens_buf[0])
18422     the_parser->tokens = &the_parser->tokens_buf[0];
18423 
18424   /* Initialize EH, if we've been told to do so.  */
18425   if (flag_exceptions)
18426     using_eh_for_cleanups ();
18427 
18428   c_parser_translation_unit (the_parser);
18429   the_parser = NULL;
18430 }
18431 
18432 /* Parse the body of a function declaration marked with "__RTL".
18433 
18434    The RTL parser works on the level of characters read from a
18435    FILE *, whereas c_parser works at the level of tokens.
18436    Square this circle by consuming all of the tokens up to and
18437    including the closing brace, recording the start/end of the RTL
18438    fragment, and reopening the file and re-reading the relevant
18439    lines within the RTL parser.
18440 
18441    This requires the opening and closing braces of the C function
18442    to be on separate lines from the RTL they wrap.
18443 
18444    Take ownership of START_WITH_PASS, if non-NULL.  */
18445 
18446 void
18447 c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass)
18448 {
18449   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
18450     {
18451       free (start_with_pass);
18452       return;
18453     }
18454 
18455   location_t start_loc = c_parser_peek_token (parser)->location;
18456 
18457   /* Consume all tokens, up to the closing brace, handling
18458      matching pairs of braces in the rtl dump.  */
18459   int num_open_braces = 1;
18460   while (1)
18461     {
18462       switch (c_parser_peek_token (parser)->type)
18463 	{
18464 	case CPP_OPEN_BRACE:
18465 	  num_open_braces++;
18466 	  break;
18467 	case CPP_CLOSE_BRACE:
18468 	  if (--num_open_braces == 0)
18469 	    goto found_closing_brace;
18470 	  break;
18471 	case CPP_EOF:
18472 	  error_at (start_loc, "no closing brace");
18473 	  free (start_with_pass);
18474 	  return;
18475 	default:
18476 	  break;
18477 	}
18478       c_parser_consume_token (parser);
18479     }
18480 
18481  found_closing_brace:
18482   /* At the closing brace; record its location.  */
18483   location_t end_loc = c_parser_peek_token (parser)->location;
18484 
18485   /* Consume the closing brace.  */
18486   c_parser_consume_token (parser);
18487 
18488   /* Invoke the RTL parser.  */
18489   if (!read_rtl_function_body_from_file_range (start_loc, end_loc))
18490     {
18491       free (start_with_pass);
18492       return;
18493     }
18494 
18495  /*  If a pass name was provided for START_WITH_PASS, run the backend
18496      accordingly now, on the cfun created above, transferring
18497      ownership of START_WITH_PASS.  */
18498   if (start_with_pass)
18499     run_rtl_passes (start_with_pass);
18500 }
18501 
18502 #include "gt-c-c-parser.h"
18503