Merge branch 'vendor/GCC50' - gcc 5.0 snapshot 1 FEB 2015
[dragonfly.git] / contrib / gcc-5.0 / gcc / c / c-parser.c
1 /* Parser for C and Objective-C.
2    Copyright (C) 1987-2015 Free Software Foundation, Inc.
3
4    Parser actions based on the old Bison parser; structure somewhat
5    influenced by and fragments based on the C++ parser.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22
23 /* TODO:
24
25    Make sure all relevant comments, and all relevant code from all
26    actions, brought over from old parser.  Verify exact correspondence
27    of syntax accepted.
28
29    Add testcases covering every input symbol in every state in old and
30    new parsers.
31
32    Include full syntax for GNU C, including erroneous cases accepted
33    with error messages, in syntax productions in comments.
34
35    Make more diagnostics in the front end generally take an explicit
36    location rather than implicitly using input_location.  */
37
38 #include "config.h"
39 #include "system.h"
40 #include "coretypes.h"
41 #include "tm.h"                 /* For rtl.h: needs enum reg_class.  */
42 #include "hash-set.h"
43 #include "vec.h"
44 #include "symtab.h"
45 #include "input.h"
46 #include "alias.h"
47 #include "double-int.h"
48 #include "machmode.h"
49 #include "flags.h"
50 #include "inchash.h"
51 #include "tree.h"
52 #include "fold-const.h"
53 #include "stringpool.h"
54 #include "attribs.h"
55 #include "stor-layout.h"
56 #include "varasm.h"
57 #include "trans-mem.h"
58 #include "langhooks.h"
59 #include "input.h"
60 #include "cpplib.h"
61 #include "timevar.h"
62 #include "c-family/c-pragma.h"
63 #include "c-tree.h"
64 #include "c-lang.h"
65 #include "flags.h"
66 #include "ggc.h"
67 #include "c-family/c-common.h"
68 #include "c-family/c-objc.h"
69 #include "vec.h"
70 #include "target.h"
71 #include "hash-map.h"
72 #include "is-a.h"
73 #include "plugin-api.h"
74 #include "hashtab.h"
75 #include "hash-set.h"
76 #include "machmode.h"
77 #include "hard-reg-set.h"
78 #include "function.h"
79 #include "ipa-ref.h"
80 #include "cgraph.h"
81 #include "plugin.h"
82 #include "omp-low.h"
83 #include "builtins.h"
84 #include "gomp-constants.h"
85
86 \f
87 /* Initialization routine for this file.  */
88
89 void
90 c_parse_init (void)
91 {
92   /* The only initialization required is of the reserved word
93      identifiers.  */
94   unsigned int i;
95   tree id;
96   int mask = 0;
97
98   /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
99      the c_token structure.  */
100   gcc_assert (RID_MAX <= 255);
101
102   mask |= D_CXXONLY;
103   if (!flag_isoc99)
104     mask |= D_C99;
105   if (flag_no_asm)
106     {
107       mask |= D_ASM | D_EXT;
108       if (!flag_isoc99)
109         mask |= D_EXT89;
110     }
111   if (!c_dialect_objc ())
112     mask |= D_OBJC | D_CXX_OBJC;
113
114   ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
115   for (i = 0; i < num_c_common_reswords; i++)
116     {
117       /* If a keyword is disabled, do not enter it into the table
118          and so create a canonical spelling that isn't a keyword.  */
119       if (c_common_reswords[i].disable & mask)
120         {
121           if (warn_cxx_compat
122               && (c_common_reswords[i].disable & D_CXXWARN))
123             {
124               id = get_identifier (c_common_reswords[i].word);
125               C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
126               C_IS_RESERVED_WORD (id) = 1;
127             }
128           continue;
129         }
130
131       id = get_identifier (c_common_reswords[i].word);
132       C_SET_RID_CODE (id, c_common_reswords[i].rid);
133       C_IS_RESERVED_WORD (id) = 1;
134       ridpointers [(int) c_common_reswords[i].rid] = id;
135     }
136
137   for (i = 0; i < NUM_INT_N_ENTS; i++)
138     {
139       /* We always create the symbols but they aren't always supported.  */
140       char name[50];
141       sprintf (name, "__int%d", int_n_data[i].bitsize);
142       id = get_identifier (xstrdup (name));
143       C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
144       C_IS_RESERVED_WORD (id) = 1;
145     }
146 }
147 \f
148 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
149    and the C parser.  Unlike the C++ lexer, the parser structure
150    stores the lexer information instead of using a separate structure.
151    Identifiers are separated into ordinary identifiers, type names,
152    keywords and some other Objective-C types of identifiers, and some
153    look-ahead is maintained.
154
155    ??? It might be a good idea to lex the whole file up front (as for
156    C++).  It would then be possible to share more of the C and C++
157    lexer code, if desired.  */
158
159 /* More information about the type of a CPP_NAME token.  */
160 typedef enum c_id_kind {
161   /* An ordinary identifier.  */
162   C_ID_ID,
163   /* An identifier declared as a typedef name.  */
164   C_ID_TYPENAME,
165   /* An identifier declared as an Objective-C class name.  */
166   C_ID_CLASSNAME,
167   /* An address space identifier.  */
168   C_ID_ADDRSPACE,
169   /* Not an identifier.  */
170   C_ID_NONE
171 } c_id_kind;
172
173 /* A single C token after string literal concatenation and conversion
174    of preprocessing tokens to tokens.  */
175 typedef struct GTY (()) c_token {
176   /* The kind of token.  */
177   ENUM_BITFIELD (cpp_ttype) type : 8;
178   /* If this token is a CPP_NAME, this value indicates whether also
179      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
180   ENUM_BITFIELD (c_id_kind) id_kind : 8;
181   /* If this token is a keyword, this value indicates which keyword.
182      Otherwise, this value is RID_MAX.  */
183   ENUM_BITFIELD (rid) keyword : 8;
184   /* If this token is a CPP_PRAGMA, this indicates the pragma that
185      was seen.  Otherwise it is PRAGMA_NONE.  */
186   ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
187   /* The location at which this token was found.  */
188   location_t location;
189   /* The value associated with this token, if any.  */
190   tree value;
191 } c_token;
192
193 /* A parser structure recording information about the state and
194    context of parsing.  Includes lexer information with up to two
195    tokens of look-ahead; more are not needed for C.  */
196 typedef struct GTY(()) c_parser {
197   /* The look-ahead tokens.  */
198   c_token * GTY((skip)) tokens;
199   /* Buffer for look-ahead tokens.  */
200   c_token tokens_buf[2];
201   /* How many look-ahead tokens are available (0, 1 or 2, or
202      more if parsing from pre-lexed tokens).  */
203   unsigned int tokens_avail;
204   /* True if a syntax error is being recovered from; false otherwise.
205      c_parser_error sets this flag.  It should clear this flag when
206      enough tokens have been consumed to recover from the error.  */
207   BOOL_BITFIELD error : 1;
208   /* True if we're processing a pragma, and shouldn't automatically
209      consume CPP_PRAGMA_EOL.  */
210   BOOL_BITFIELD in_pragma : 1;
211   /* True if we're parsing the outermost block of an if statement.  */
212   BOOL_BITFIELD in_if_block : 1;
213   /* True if we want to lex an untranslated string.  */
214   BOOL_BITFIELD lex_untranslated_string : 1;
215
216   /* Objective-C specific parser/lexer information.  */
217
218   /* True if we are in a context where the Objective-C "PQ" keywords
219      are considered keywords.  */
220   BOOL_BITFIELD objc_pq_context : 1;
221   /* True if we are parsing a (potential) Objective-C foreach
222      statement.  This is set to true after we parsed 'for (' and while
223      we wait for 'in' or ';' to decide if it's a standard C for loop or an
224      Objective-C foreach loop.  */
225   BOOL_BITFIELD objc_could_be_foreach_context : 1;
226   /* The following flag is needed to contextualize Objective-C lexical
227      analysis.  In some cases (e.g., 'int NSObject;'), it is
228      undesirable to bind an identifier to an Objective-C class, even
229      if a class with that name exists.  */
230   BOOL_BITFIELD objc_need_raw_identifier : 1;
231   /* Nonzero if we're processing a __transaction statement.  The value
232      is 1 | TM_STMT_ATTR_*.  */
233   unsigned int in_transaction : 4;
234   /* True if we are in a context where the Objective-C "Property attribute"
235      keywords are valid.  */
236   BOOL_BITFIELD objc_property_attr_context : 1;
237
238   /* Cilk Plus specific parser/lexer information.  */
239
240   /* Buffer to hold all the tokens from parsing the vector attribute for the
241      SIMD-enabled functions (formerly known as elemental functions).  */
242   vec <c_token, va_gc> *cilk_simd_fn_tokens;
243 } c_parser;
244
245
246 /* The actual parser and external interface.  ??? Does this need to be
247    garbage-collected?  */
248
249 static GTY (()) c_parser *the_parser;
250
251 /* Read in and lex a single token, storing it in *TOKEN.  */
252
253 static void
254 c_lex_one_token (c_parser *parser, c_token *token)
255 {
256   timevar_push (TV_LEX);
257
258   token->type = c_lex_with_flags (&token->value, &token->location, NULL,
259                                   (parser->lex_untranslated_string
260                                    ? C_LEX_STRING_NO_TRANSLATE : 0));
261   token->id_kind = C_ID_NONE;
262   token->keyword = RID_MAX;
263   token->pragma_kind = PRAGMA_NONE;
264
265   switch (token->type)
266     {
267     case CPP_NAME:
268       {
269         tree decl;
270
271         bool objc_force_identifier = parser->objc_need_raw_identifier;
272         if (c_dialect_objc ())
273           parser->objc_need_raw_identifier = false;
274
275         if (C_IS_RESERVED_WORD (token->value))
276           {
277             enum rid rid_code = C_RID_CODE (token->value);
278
279             if (rid_code == RID_CXX_COMPAT_WARN)
280               {
281                 warning_at (token->location,
282                             OPT_Wc___compat,
283                             "identifier %qE conflicts with C++ keyword",
284                             token->value);
285               }
286             else if (rid_code >= RID_FIRST_ADDR_SPACE
287                      && rid_code <= RID_LAST_ADDR_SPACE)
288               {
289                 token->id_kind = C_ID_ADDRSPACE;
290                 token->keyword = rid_code;
291                 break;
292               }
293             else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
294               {
295                 /* We found an Objective-C "pq" keyword (in, out,
296                    inout, bycopy, byref, oneway).  They need special
297                    care because the interpretation depends on the
298                    context.  */
299                 if (parser->objc_pq_context)
300                   {
301                     token->type = CPP_KEYWORD;
302                     token->keyword = rid_code;
303                     break;
304                   }
305                 else if (parser->objc_could_be_foreach_context
306                          && rid_code == RID_IN)
307                   {
308                     /* We are in Objective-C, inside a (potential)
309                        foreach context (which means after having
310                        parsed 'for (', but before having parsed ';'),
311                        and we found 'in'.  We consider it the keyword
312                        which terminates the declaration at the
313                        beginning of a foreach-statement.  Note that
314                        this means you can't use 'in' for anything else
315                        in that context; in particular, in Objective-C
316                        you can't use 'in' as the name of the running
317                        variable in a C for loop.  We could potentially
318                        try to add code here to disambiguate, but it
319                        seems a reasonable limitation.  */
320                     token->type = CPP_KEYWORD;
321                     token->keyword = rid_code;
322                     break;
323                   }
324                 /* Else, "pq" keywords outside of the "pq" context are
325                    not keywords, and we fall through to the code for
326                    normal tokens.  */
327               }
328             else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
329               {
330                 /* We found an Objective-C "property attribute"
331                    keyword (getter, setter, readonly, etc). These are
332                    only valid in the property context.  */
333                 if (parser->objc_property_attr_context)
334                   {
335                     token->type = CPP_KEYWORD;
336                     token->keyword = rid_code;
337                     break;
338                   }
339                 /* Else they are not special keywords.
340                 */
341               }
342             else if (c_dialect_objc () 
343                      && (OBJC_IS_AT_KEYWORD (rid_code)
344                          || OBJC_IS_CXX_KEYWORD (rid_code)))
345               {
346                 /* We found one of the Objective-C "@" keywords (defs,
347                    selector, synchronized, etc) or one of the
348                    Objective-C "cxx" keywords (class, private,
349                    protected, public, try, catch, throw) without a
350                    preceding '@' sign.  Do nothing and fall through to
351                    the code for normal tokens (in C++ we would still
352                    consider the CXX ones keywords, but not in C).  */
353                 ;
354               }
355             else
356               {
357                 token->type = CPP_KEYWORD;
358                 token->keyword = rid_code;
359                 break;
360               }
361           }
362
363         decl = lookup_name (token->value);
364         if (decl)
365           {
366             if (TREE_CODE (decl) == TYPE_DECL)
367               {
368                 token->id_kind = C_ID_TYPENAME;
369                 break;
370               }
371           }
372         else if (c_dialect_objc ())
373           {
374             tree objc_interface_decl = objc_is_class_name (token->value);
375             /* Objective-C class names are in the same namespace as
376                variables and typedefs, and hence are shadowed by local
377                declarations.  */
378             if (objc_interface_decl
379                 && (!objc_force_identifier || global_bindings_p ()))
380               {
381                 token->value = objc_interface_decl;
382                 token->id_kind = C_ID_CLASSNAME;
383                 break;
384               }
385           }
386         token->id_kind = C_ID_ID;
387       }
388       break;
389     case CPP_AT_NAME:
390       /* This only happens in Objective-C; it must be a keyword.  */
391       token->type = CPP_KEYWORD;
392       switch (C_RID_CODE (token->value))
393         {
394           /* Replace 'class' with '@class', 'private' with '@private',
395              etc.  This prevents confusion with the C++ keyword
396              'class', and makes the tokens consistent with other
397              Objective-C 'AT' keywords.  For example '@class' is
398              reported as RID_AT_CLASS which is consistent with
399              '@synchronized', which is reported as
400              RID_AT_SYNCHRONIZED.
401           */
402         case RID_CLASS:     token->keyword = RID_AT_CLASS; break;
403         case RID_PRIVATE:   token->keyword = RID_AT_PRIVATE; break;
404         case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
405         case RID_PUBLIC:    token->keyword = RID_AT_PUBLIC; break;
406         case RID_THROW:     token->keyword = RID_AT_THROW; break;
407         case RID_TRY:       token->keyword = RID_AT_TRY; break;
408         case RID_CATCH:     token->keyword = RID_AT_CATCH; break;
409         default:            token->keyword = C_RID_CODE (token->value);
410         }
411       break;
412     case CPP_COLON:
413     case CPP_COMMA:
414     case CPP_CLOSE_PAREN:
415     case CPP_SEMICOLON:
416       /* These tokens may affect the interpretation of any identifiers
417          following, if doing Objective-C.  */
418       if (c_dialect_objc ())
419         parser->objc_need_raw_identifier = false;
420       break;
421     case CPP_PRAGMA:
422       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
423       token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
424       token->value = NULL;
425       break;
426     default:
427       break;
428     }
429   timevar_pop (TV_LEX);
430 }
431
432 /* Return a pointer to the next token from PARSER, reading it in if
433    necessary.  */
434
435 static inline c_token *
436 c_parser_peek_token (c_parser *parser)
437 {
438   if (parser->tokens_avail == 0)
439     {
440       c_lex_one_token (parser, &parser->tokens[0]);
441       parser->tokens_avail = 1;
442     }
443   return &parser->tokens[0];
444 }
445
446 /* Return true if the next token from PARSER has the indicated
447    TYPE.  */
448
449 static inline bool
450 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
451 {
452   return c_parser_peek_token (parser)->type == type;
453 }
454
455 /* Return true if the next token from PARSER does not have the
456    indicated TYPE.  */
457
458 static inline bool
459 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
460 {
461   return !c_parser_next_token_is (parser, type);
462 }
463
464 /* Return true if the next token from PARSER is the indicated
465    KEYWORD.  */
466
467 static inline bool
468 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
469 {
470   return c_parser_peek_token (parser)->keyword == keyword;
471 }
472
473 /* Return a pointer to the next-but-one token from PARSER, reading it
474    in if necessary.  The next token is already read in.  */
475
476 static c_token *
477 c_parser_peek_2nd_token (c_parser *parser)
478 {
479   if (parser->tokens_avail >= 2)
480     return &parser->tokens[1];
481   gcc_assert (parser->tokens_avail == 1);
482   gcc_assert (parser->tokens[0].type != CPP_EOF);
483   gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
484   c_lex_one_token (parser, &parser->tokens[1]);
485   parser->tokens_avail = 2;
486   return &parser->tokens[1];
487 }
488
489 /* Return true if TOKEN can start a type name,
490    false otherwise.  */
491 static bool
492 c_token_starts_typename (c_token *token)
493 {
494   switch (token->type)
495     {
496     case CPP_NAME:
497       switch (token->id_kind)
498         {
499         case C_ID_ID:
500           return false;
501         case C_ID_ADDRSPACE:
502           return true;
503         case C_ID_TYPENAME:
504           return true;
505         case C_ID_CLASSNAME:
506           gcc_assert (c_dialect_objc ());
507           return true;
508         default:
509           gcc_unreachable ();
510         }
511     case CPP_KEYWORD:
512       switch (token->keyword)
513         {
514         case RID_UNSIGNED:
515         case RID_LONG:
516         case RID_SHORT:
517         case RID_SIGNED:
518         case RID_COMPLEX:
519         case RID_INT:
520         case RID_CHAR:
521         case RID_FLOAT:
522         case RID_DOUBLE:
523         case RID_VOID:
524         case RID_DFLOAT32:
525         case RID_DFLOAT64:
526         case RID_DFLOAT128:
527         case RID_BOOL:
528         case RID_ENUM:
529         case RID_STRUCT:
530         case RID_UNION:
531         case RID_TYPEOF:
532         case RID_CONST:
533         case RID_ATOMIC:
534         case RID_VOLATILE:
535         case RID_RESTRICT:
536         case RID_ATTRIBUTE:
537         case RID_FRACT:
538         case RID_ACCUM:
539         case RID_SAT:
540         case RID_AUTO_TYPE:
541           return true;
542         default:
543           if (token->keyword >= RID_FIRST_INT_N
544               && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
545               && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
546             return true;
547           return false;
548         }
549     case CPP_LESS:
550       if (c_dialect_objc ())
551         return true;
552       return false;
553     default:
554       return false;
555     }
556 }
557
558 enum c_lookahead_kind {
559   /* Always treat unknown identifiers as typenames.  */
560   cla_prefer_type,
561
562   /* Could be parsing a nonabstract declarator.  Only treat an identifier
563      as a typename if followed by another identifier or a star.  */
564   cla_nonabstract_decl,
565
566   /* Never treat identifiers as typenames.  */
567   cla_prefer_id
568 };
569
570 /* Return true if the next token from PARSER can start a type name,
571    false otherwise.  LA specifies how to do lookahead in order to
572    detect unknown type names.  If unsure, pick CLA_PREFER_ID.  */
573
574 static inline bool
575 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
576 {
577   c_token *token = c_parser_peek_token (parser);
578   if (c_token_starts_typename (token))
579     return true;
580
581   /* Try a bit harder to detect an unknown typename.  */
582   if (la != cla_prefer_id
583       && token->type == CPP_NAME
584       && token->id_kind == C_ID_ID
585
586       /* Do not try too hard when we could have "object in array".  */
587       && !parser->objc_could_be_foreach_context
588
589       && (la == cla_prefer_type
590           || c_parser_peek_2nd_token (parser)->type == CPP_NAME
591           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
592
593       /* Only unknown identifiers.  */
594       && !lookup_name (token->value))
595     return true;
596
597   return false;
598 }
599
600 /* Return true if TOKEN is a type qualifier, false otherwise.  */
601 static bool
602 c_token_is_qualifier (c_token *token)
603 {
604   switch (token->type)
605     {
606     case CPP_NAME:
607       switch (token->id_kind)
608         {
609         case C_ID_ADDRSPACE:
610           return true;
611         default:
612           return false;
613         }
614     case CPP_KEYWORD:
615       switch (token->keyword)
616         {
617         case RID_CONST:
618         case RID_VOLATILE:
619         case RID_RESTRICT:
620         case RID_ATTRIBUTE:
621         case RID_ATOMIC:
622           return true;
623         default:
624           return false;
625         }
626     case CPP_LESS:
627       return false;
628     default:
629       gcc_unreachable ();
630     }
631 }
632
633 /* Return true if the next token from PARSER is a type qualifier,
634    false otherwise.  */
635 static inline bool
636 c_parser_next_token_is_qualifier (c_parser *parser)
637 {
638   c_token *token = c_parser_peek_token (parser);
639   return c_token_is_qualifier (token);
640 }
641
642 /* Return true if TOKEN can start declaration specifiers, false
643    otherwise.  */
644 static bool
645 c_token_starts_declspecs (c_token *token)
646 {
647   switch (token->type)
648     {
649     case CPP_NAME:
650       switch (token->id_kind)
651         {
652         case C_ID_ID:
653           return false;
654         case C_ID_ADDRSPACE:
655           return true;
656         case C_ID_TYPENAME:
657           return true;
658         case C_ID_CLASSNAME:
659           gcc_assert (c_dialect_objc ());
660           return true;
661         default:
662           gcc_unreachable ();
663         }
664     case CPP_KEYWORD:
665       switch (token->keyword)
666         {
667         case RID_STATIC:
668         case RID_EXTERN:
669         case RID_REGISTER:
670         case RID_TYPEDEF:
671         case RID_INLINE:
672         case RID_NORETURN:
673         case RID_AUTO:
674         case RID_THREAD:
675         case RID_UNSIGNED:
676         case RID_LONG:
677         case RID_SHORT:
678         case RID_SIGNED:
679         case RID_COMPLEX:
680         case RID_INT:
681         case RID_CHAR:
682         case RID_FLOAT:
683         case RID_DOUBLE:
684         case RID_VOID:
685         case RID_DFLOAT32:
686         case RID_DFLOAT64:
687         case RID_DFLOAT128:
688         case RID_BOOL:
689         case RID_ENUM:
690         case RID_STRUCT:
691         case RID_UNION:
692         case RID_TYPEOF:
693         case RID_CONST:
694         case RID_VOLATILE:
695         case RID_RESTRICT:
696         case RID_ATTRIBUTE:
697         case RID_FRACT:
698         case RID_ACCUM:
699         case RID_SAT:
700         case RID_ALIGNAS:
701         case RID_ATOMIC:
702         case RID_AUTO_TYPE:
703           return true;
704         default:
705           if (token->keyword >= RID_FIRST_INT_N
706               && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
707               && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
708             return true;
709           return false;
710         }
711     case CPP_LESS:
712       if (c_dialect_objc ())
713         return true;
714       return false;
715     default:
716       return false;
717     }
718 }
719
720
721 /* Return true if TOKEN can start declaration specifiers or a static
722    assertion, false otherwise.  */
723 static bool
724 c_token_starts_declaration (c_token *token)
725 {
726   if (c_token_starts_declspecs (token)
727       || token->keyword == RID_STATIC_ASSERT)
728     return true;
729   else
730     return false;
731 }
732
733 /* Return true if the next token from PARSER can start declaration
734    specifiers, false otherwise.  */
735 static inline bool
736 c_parser_next_token_starts_declspecs (c_parser *parser)
737 {
738   c_token *token = c_parser_peek_token (parser);
739
740   /* In Objective-C, a classname normally starts a declspecs unless it
741      is immediately followed by a dot.  In that case, it is the
742      Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
743      setter/getter on the class.  c_token_starts_declspecs() can't
744      differentiate between the two cases because it only checks the
745      current token, so we have a special check here.  */
746   if (c_dialect_objc () 
747       && token->type == CPP_NAME
748       && token->id_kind == C_ID_CLASSNAME 
749       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
750     return false;
751
752   return c_token_starts_declspecs (token);
753 }
754
755 /* Return true if the next tokens from PARSER can start declaration
756    specifiers or a static assertion, false otherwise.  */
757 static inline bool
758 c_parser_next_tokens_start_declaration (c_parser *parser)
759 {
760   c_token *token = c_parser_peek_token (parser);
761
762   /* Same as above.  */
763   if (c_dialect_objc () 
764       && token->type == CPP_NAME
765       && token->id_kind == C_ID_CLASSNAME 
766       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
767     return false;
768
769   /* Labels do not start declarations.  */
770   if (token->type == CPP_NAME
771       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
772     return false;
773
774   if (c_token_starts_declaration (token))
775     return true;
776
777   if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
778     return true;
779
780   return false;
781 }
782
783 /* Consume the next token from PARSER.  */
784
785 static void
786 c_parser_consume_token (c_parser *parser)
787 {
788   gcc_assert (parser->tokens_avail >= 1);
789   gcc_assert (parser->tokens[0].type != CPP_EOF);
790   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
791   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
792   if (parser->tokens != &parser->tokens_buf[0])
793     parser->tokens++;
794   else if (parser->tokens_avail == 2)
795     parser->tokens[0] = parser->tokens[1];
796   parser->tokens_avail--;
797 }
798
799 /* Expect the current token to be a #pragma.  Consume it and remember
800    that we've begun parsing a pragma.  */
801
802 static void
803 c_parser_consume_pragma (c_parser *parser)
804 {
805   gcc_assert (!parser->in_pragma);
806   gcc_assert (parser->tokens_avail >= 1);
807   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
808   if (parser->tokens != &parser->tokens_buf[0])
809     parser->tokens++;
810   else if (parser->tokens_avail == 2)
811     parser->tokens[0] = parser->tokens[1];
812   parser->tokens_avail--;
813   parser->in_pragma = true;
814 }
815
816 /* Update the global input_location from TOKEN.  */
817 static inline void
818 c_parser_set_source_position_from_token (c_token *token)
819 {
820   if (token->type != CPP_EOF)
821     {
822       input_location = token->location;
823     }
824 }
825
826 /* Issue a diagnostic of the form
827       FILE:LINE: MESSAGE before TOKEN
828    where TOKEN is the next token in the input stream of PARSER.
829    MESSAGE (specified by the caller) is usually of the form "expected
830    OTHER-TOKEN".
831
832    Do not issue a diagnostic if still recovering from an error.
833
834    ??? This is taken from the C++ parser, but building up messages in
835    this way is not i18n-friendly and some other approach should be
836    used.  */
837
838 static void
839 c_parser_error (c_parser *parser, const char *gmsgid)
840 {
841   c_token *token = c_parser_peek_token (parser);
842   if (parser->error)
843     return;
844   parser->error = true;
845   if (!gmsgid)
846     return;
847   /* This diagnostic makes more sense if it is tagged to the line of
848      the token we just peeked at.  */
849   c_parser_set_source_position_from_token (token);
850   c_parse_error (gmsgid,
851                  /* Because c_parse_error does not understand
852                     CPP_KEYWORD, keywords are treated like
853                     identifiers.  */
854                  (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
855                  /* ??? The C parser does not save the cpp flags of a
856                     token, we need to pass 0 here and we will not get
857                     the source spelling of some tokens but rather the
858                     canonical spelling.  */
859                  token->value, /*flags=*/0);
860 }
861
862 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
863    issue the error MSGID.  If MSGID is NULL then a message has already
864    been produced and no message will be produced this time.  Returns
865    true if found, false otherwise.  */
866
867 static bool
868 c_parser_require (c_parser *parser,
869                   enum cpp_ttype type,
870                   const char *msgid)
871 {
872   if (c_parser_next_token_is (parser, type))
873     {
874       c_parser_consume_token (parser);
875       return true;
876     }
877   else
878     {
879       c_parser_error (parser, msgid);
880       return false;
881     }
882 }
883
884 /* If the next token is the indicated keyword, consume it.  Otherwise,
885    issue the error MSGID.  Returns true if found, false otherwise.  */
886
887 static bool
888 c_parser_require_keyword (c_parser *parser,
889                           enum rid keyword,
890                           const char *msgid)
891 {
892   if (c_parser_next_token_is_keyword (parser, keyword))
893     {
894       c_parser_consume_token (parser);
895       return true;
896     }
897   else
898     {
899       c_parser_error (parser, msgid);
900       return false;
901     }
902 }
903
904 /* Like c_parser_require, except that tokens will be skipped until the
905    desired token is found.  An error message is still produced if the
906    next token is not as expected.  If MSGID is NULL then a message has
907    already been produced and no message will be produced this
908    time.  */
909
910 static void
911 c_parser_skip_until_found (c_parser *parser,
912                            enum cpp_ttype type,
913                            const char *msgid)
914 {
915   unsigned nesting_depth = 0;
916
917   if (c_parser_require (parser, type, msgid))
918     return;
919
920   /* Skip tokens until the desired token is found.  */
921   while (true)
922     {
923       /* Peek at the next token.  */
924       c_token *token = c_parser_peek_token (parser);
925       /* If we've reached the token we want, consume it and stop.  */
926       if (token->type == type && !nesting_depth)
927         {
928           c_parser_consume_token (parser);
929           break;
930         }
931
932       /* If we've run out of tokens, stop.  */
933       if (token->type == CPP_EOF)
934         return;
935       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
936         return;
937       if (token->type == CPP_OPEN_BRACE
938           || token->type == CPP_OPEN_PAREN
939           || token->type == CPP_OPEN_SQUARE)
940         ++nesting_depth;
941       else if (token->type == CPP_CLOSE_BRACE
942                || token->type == CPP_CLOSE_PAREN
943                || token->type == CPP_CLOSE_SQUARE)
944         {
945           if (nesting_depth-- == 0)
946             break;
947         }
948       /* Consume this token.  */
949       c_parser_consume_token (parser);
950     }
951   parser->error = false;
952 }
953
954 /* Skip tokens until the end of a parameter is found, but do not
955    consume the comma, semicolon or closing delimiter.  */
956
957 static void
958 c_parser_skip_to_end_of_parameter (c_parser *parser)
959 {
960   unsigned nesting_depth = 0;
961
962   while (true)
963     {
964       c_token *token = c_parser_peek_token (parser);
965       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
966           && !nesting_depth)
967         break;
968       /* If we've run out of tokens, stop.  */
969       if (token->type == CPP_EOF)
970         return;
971       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
972         return;
973       if (token->type == CPP_OPEN_BRACE
974           || token->type == CPP_OPEN_PAREN
975           || token->type == CPP_OPEN_SQUARE)
976         ++nesting_depth;
977       else if (token->type == CPP_CLOSE_BRACE
978                || token->type == CPP_CLOSE_PAREN
979                || token->type == CPP_CLOSE_SQUARE)
980         {
981           if (nesting_depth-- == 0)
982             break;
983         }
984       /* Consume this token.  */
985       c_parser_consume_token (parser);
986     }
987   parser->error = false;
988 }
989
990 /* Expect to be at the end of the pragma directive and consume an
991    end of line marker.  */
992
993 static void
994 c_parser_skip_to_pragma_eol (c_parser *parser)
995 {
996   gcc_assert (parser->in_pragma);
997   parser->in_pragma = false;
998
999   if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
1000     while (true)
1001       {
1002         c_token *token = c_parser_peek_token (parser);
1003         if (token->type == CPP_EOF)
1004           break;
1005         if (token->type == CPP_PRAGMA_EOL)
1006           {
1007             c_parser_consume_token (parser);
1008             break;
1009           }
1010         c_parser_consume_token (parser);
1011       }
1012
1013   parser->error = false;
1014 }
1015
1016 /* Skip tokens until we have consumed an entire block, or until we
1017    have consumed a non-nested ';'.  */
1018
1019 static void
1020 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1021 {
1022   unsigned nesting_depth = 0;
1023   bool save_error = parser->error;
1024
1025   while (true)
1026     {
1027       c_token *token;
1028
1029       /* Peek at the next token.  */
1030       token = c_parser_peek_token (parser);
1031
1032       switch (token->type)
1033         {
1034         case CPP_EOF:
1035           return;
1036
1037         case CPP_PRAGMA_EOL:
1038           if (parser->in_pragma)
1039             return;
1040           break;
1041
1042         case CPP_SEMICOLON:
1043           /* If the next token is a ';', we have reached the
1044              end of the statement.  */
1045           if (!nesting_depth)
1046             {
1047               /* Consume the ';'.  */
1048               c_parser_consume_token (parser);
1049               goto finished;
1050             }
1051           break;
1052
1053         case CPP_CLOSE_BRACE:
1054           /* If the next token is a non-nested '}', then we have
1055              reached the end of the current block.  */
1056           if (nesting_depth == 0 || --nesting_depth == 0)
1057             {
1058               c_parser_consume_token (parser);
1059               goto finished;
1060             }
1061           break;
1062
1063         case CPP_OPEN_BRACE:
1064           /* If it the next token is a '{', then we are entering a new
1065              block.  Consume the entire block.  */
1066           ++nesting_depth;
1067           break;
1068
1069         case CPP_PRAGMA:
1070           /* If we see a pragma, consume the whole thing at once.  We
1071              have some safeguards against consuming pragmas willy-nilly.
1072              Normally, we'd expect to be here with parser->error set,
1073              which disables these safeguards.  But it's possible to get
1074              here for secondary error recovery, after parser->error has
1075              been cleared.  */
1076           c_parser_consume_pragma (parser);
1077           c_parser_skip_to_pragma_eol (parser);
1078           parser->error = save_error;
1079           continue;
1080
1081         default:
1082           break;
1083         }
1084
1085       c_parser_consume_token (parser);
1086     }
1087
1088  finished:
1089   parser->error = false;
1090 }
1091
1092 /* CPP's options (initialized by c-opts.c).  */
1093 extern cpp_options *cpp_opts;
1094
1095 /* Save the warning flags which are controlled by __extension__.  */
1096
1097 static inline int
1098 disable_extension_diagnostics (void)
1099 {
1100   int ret = (pedantic
1101              | (warn_pointer_arith << 1)
1102              | (warn_traditional << 2)
1103              | (flag_iso << 3)
1104              | (warn_long_long << 4)
1105              | (warn_cxx_compat << 5)
1106              | (warn_overlength_strings << 6)
1107              /* warn_c90_c99_compat has three states: -1/0/1, so we must
1108                 play tricks to properly restore it.  */
1109              | ((warn_c90_c99_compat == 1) << 7)
1110              | ((warn_c90_c99_compat == -1) << 8)
1111              /* Similarly for warn_c99_c11_compat.  */
1112              | ((warn_c99_c11_compat == 1) << 9)
1113              | ((warn_c99_c11_compat == -1) << 10)
1114              );
1115   cpp_opts->cpp_pedantic = pedantic = 0;
1116   warn_pointer_arith = 0;
1117   cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1118   flag_iso = 0;
1119   cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1120   warn_cxx_compat = 0;
1121   warn_overlength_strings = 0;
1122   warn_c90_c99_compat = 0;
1123   warn_c99_c11_compat = 0;
1124   return ret;
1125 }
1126
1127 /* Restore the warning flags which are controlled by __extension__.
1128    FLAGS is the return value from disable_extension_diagnostics.  */
1129
1130 static inline void
1131 restore_extension_diagnostics (int flags)
1132 {
1133   cpp_opts->cpp_pedantic = pedantic = flags & 1;
1134   warn_pointer_arith = (flags >> 1) & 1;
1135   cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1136   flag_iso = (flags >> 3) & 1;
1137   cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1138   warn_cxx_compat = (flags >> 5) & 1;
1139   warn_overlength_strings = (flags >> 6) & 1;
1140   /* See above for why is this needed.  */
1141   warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1142   warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1143 }
1144
1145 /* Possibly kinds of declarator to parse.  */
1146 typedef enum c_dtr_syn {
1147   /* A normal declarator with an identifier.  */
1148   C_DTR_NORMAL,
1149   /* An abstract declarator (maybe empty).  */
1150   C_DTR_ABSTRACT,
1151   /* A parameter declarator: may be either, but after a type name does
1152      not redeclare a typedef name as an identifier if it can
1153      alternatively be interpreted as a typedef name; see DR#009,
1154      applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1155      following DR#249.  For example, given a typedef T, "int T" and
1156      "int *T" are valid parameter declarations redeclaring T, while
1157      "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1158      abstract declarators rather than involving redundant parentheses;
1159      the same applies with attributes inside the parentheses before
1160      "T".  */
1161   C_DTR_PARM
1162 } c_dtr_syn;
1163
1164 /* The binary operation precedence levels, where 0 is a dummy lowest level
1165    used for the bottom of the stack.  */
1166 enum c_parser_prec {
1167   PREC_NONE,
1168   PREC_LOGOR,
1169   PREC_LOGAND,
1170   PREC_BITOR,
1171   PREC_BITXOR,
1172   PREC_BITAND,
1173   PREC_EQ,
1174   PREC_REL,
1175   PREC_SHIFT,
1176   PREC_ADD,
1177   PREC_MULT,
1178   NUM_PRECS
1179 };
1180
1181 static void c_parser_external_declaration (c_parser *);
1182 static void c_parser_asm_definition (c_parser *);
1183 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1184                                            bool, bool, tree *, vec<c_token>);
1185 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1186 static void c_parser_static_assert_declaration (c_parser *);
1187 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1188                                 bool, bool, bool, enum c_lookahead_kind);
1189 static struct c_typespec c_parser_enum_specifier (c_parser *);
1190 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1191 static tree c_parser_struct_declaration (c_parser *);
1192 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1193 static tree c_parser_alignas_specifier (c_parser *);
1194 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1195                                                  bool *);
1196 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1197                                                         c_dtr_syn, bool *);
1198 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1199                                                               bool,
1200                                                               struct c_declarator *);
1201 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1202 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1203                                                           tree);
1204 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1205 static tree c_parser_simple_asm_expr (c_parser *);
1206 static tree c_parser_attributes (c_parser *);
1207 static struct c_type_name *c_parser_type_name (c_parser *);
1208 static struct c_expr c_parser_initializer (c_parser *);
1209 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1210 static void c_parser_initelt (c_parser *, struct obstack *);
1211 static void c_parser_initval (c_parser *, struct c_expr *,
1212                               struct obstack *);
1213 static tree c_parser_compound_statement (c_parser *);
1214 static void c_parser_compound_statement_nostart (c_parser *);
1215 static void c_parser_label (c_parser *);
1216 static void c_parser_statement (c_parser *);
1217 static void c_parser_statement_after_labels (c_parser *);
1218 static void c_parser_if_statement (c_parser *);
1219 static void c_parser_switch_statement (c_parser *);
1220 static void c_parser_while_statement (c_parser *, bool);
1221 static void c_parser_do_statement (c_parser *, bool);
1222 static void c_parser_for_statement (c_parser *, bool);
1223 static tree c_parser_asm_statement (c_parser *);
1224 static tree c_parser_asm_operands (c_parser *);
1225 static tree c_parser_asm_goto_operands (c_parser *);
1226 static tree c_parser_asm_clobbers (c_parser *);
1227 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1228                                               tree = NULL_TREE);
1229 static struct c_expr c_parser_conditional_expression (c_parser *,
1230                                                       struct c_expr *, tree);
1231 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1232                                                  tree);
1233 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1234 static struct c_expr c_parser_unary_expression (c_parser *);
1235 static struct c_expr c_parser_sizeof_expression (c_parser *);
1236 static struct c_expr c_parser_alignof_expression (c_parser *);
1237 static struct c_expr c_parser_postfix_expression (c_parser *);
1238 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1239                                                                    struct c_type_name *,
1240                                                                    location_t);
1241 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1242                                                                 location_t loc,
1243                                                                 struct c_expr);
1244 static tree c_parser_transaction (c_parser *, enum rid);
1245 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1246 static tree c_parser_transaction_cancel (c_parser *);
1247 static struct c_expr c_parser_expression (c_parser *);
1248 static struct c_expr c_parser_expression_conv (c_parser *);
1249 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1250                                              vec<tree, va_gc> **, location_t *,
1251                                              tree *, vec<location_t> *,
1252                                              unsigned int * = NULL);
1253 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1254 static void c_parser_oacc_update (c_parser *);
1255 static tree c_parser_oacc_loop (location_t, c_parser *, char *);
1256 static void c_parser_omp_construct (c_parser *);
1257 static void c_parser_omp_threadprivate (c_parser *);
1258 static void c_parser_omp_barrier (c_parser *);
1259 static void c_parser_omp_flush (c_parser *);
1260 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1261                                    tree, tree *);
1262 static void c_parser_omp_taskwait (c_parser *);
1263 static void c_parser_omp_taskyield (c_parser *);
1264 static void c_parser_omp_cancel (c_parser *);
1265 static void c_parser_omp_cancellation_point (c_parser *);
1266
1267 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1268                       pragma_stmt, pragma_compound };
1269 static bool c_parser_pragma (c_parser *, enum pragma_context);
1270 static bool c_parser_omp_target (c_parser *, enum pragma_context);
1271 static void c_parser_omp_end_declare_target (c_parser *);
1272 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1273
1274 /* These Objective-C parser functions are only ever called when
1275    compiling Objective-C.  */
1276 static void c_parser_objc_class_definition (c_parser *, tree);
1277 static void c_parser_objc_class_instance_variables (c_parser *);
1278 static void c_parser_objc_class_declaration (c_parser *);
1279 static void c_parser_objc_alias_declaration (c_parser *);
1280 static void c_parser_objc_protocol_definition (c_parser *, tree);
1281 static bool c_parser_objc_method_type (c_parser *);
1282 static void c_parser_objc_method_definition (c_parser *);
1283 static void c_parser_objc_methodprotolist (c_parser *);
1284 static void c_parser_objc_methodproto (c_parser *);
1285 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1286 static tree c_parser_objc_type_name (c_parser *);
1287 static tree c_parser_objc_protocol_refs (c_parser *);
1288 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1289 static void c_parser_objc_synchronized_statement (c_parser *);
1290 static tree c_parser_objc_selector (c_parser *);
1291 static tree c_parser_objc_selector_arg (c_parser *);
1292 static tree c_parser_objc_receiver (c_parser *);
1293 static tree c_parser_objc_message_args (c_parser *);
1294 static tree c_parser_objc_keywordexpr (c_parser *);
1295 static void c_parser_objc_at_property_declaration (c_parser *);
1296 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1297 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1298 static bool c_parser_objc_diagnose_bad_element_prefix
1299   (c_parser *, struct c_declspecs *);
1300
1301 /* Cilk Plus supporting routines.  */
1302 static void c_parser_cilk_simd (c_parser *);
1303 static void c_parser_cilk_for (c_parser *, tree);
1304 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
1305 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
1306 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
1307 static void c_parser_cilk_grainsize (c_parser *);
1308
1309 /* Parse a translation unit (C90 6.7, C99 6.9).
1310
1311    translation-unit:
1312      external-declarations
1313
1314    external-declarations:
1315      external-declaration
1316      external-declarations external-declaration
1317
1318    GNU extensions:
1319
1320    translation-unit:
1321      empty
1322 */
1323
1324 static void
1325 c_parser_translation_unit (c_parser *parser)
1326 {
1327   if (c_parser_next_token_is (parser, CPP_EOF))
1328     {
1329       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1330                "ISO C forbids an empty translation unit");
1331     }
1332   else
1333     {
1334       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1335       mark_valid_location_for_stdc_pragma (false);
1336       do
1337         {
1338           ggc_collect ();
1339           c_parser_external_declaration (parser);
1340           obstack_free (&parser_obstack, obstack_position);
1341         }
1342       while (c_parser_next_token_is_not (parser, CPP_EOF));
1343     }
1344 }
1345
1346 /* Parse an external declaration (C90 6.7, C99 6.9).
1347
1348    external-declaration:
1349      function-definition
1350      declaration
1351
1352    GNU extensions:
1353
1354    external-declaration:
1355      asm-definition
1356      ;
1357      __extension__ external-declaration
1358
1359    Objective-C:
1360
1361    external-declaration:
1362      objc-class-definition
1363      objc-class-declaration
1364      objc-alias-declaration
1365      objc-protocol-definition
1366      objc-method-definition
1367      @end
1368 */
1369
1370 static void
1371 c_parser_external_declaration (c_parser *parser)
1372 {
1373   int ext;
1374   switch (c_parser_peek_token (parser)->type)
1375     {
1376     case CPP_KEYWORD:
1377       switch (c_parser_peek_token (parser)->keyword)
1378         {
1379         case RID_EXTENSION:
1380           ext = disable_extension_diagnostics ();
1381           c_parser_consume_token (parser);
1382           c_parser_external_declaration (parser);
1383           restore_extension_diagnostics (ext);
1384           break;
1385         case RID_ASM:
1386           c_parser_asm_definition (parser);
1387           break;
1388         case RID_AT_INTERFACE:
1389         case RID_AT_IMPLEMENTATION:
1390           gcc_assert (c_dialect_objc ());
1391           c_parser_objc_class_definition (parser, NULL_TREE);
1392           break;
1393         case RID_AT_CLASS:
1394           gcc_assert (c_dialect_objc ());
1395           c_parser_objc_class_declaration (parser);
1396           break;
1397         case RID_AT_ALIAS:
1398           gcc_assert (c_dialect_objc ());
1399           c_parser_objc_alias_declaration (parser);
1400           break;
1401         case RID_AT_PROTOCOL:
1402           gcc_assert (c_dialect_objc ());
1403           c_parser_objc_protocol_definition (parser, NULL_TREE);
1404           break;
1405         case RID_AT_PROPERTY:
1406           gcc_assert (c_dialect_objc ());
1407           c_parser_objc_at_property_declaration (parser);
1408           break;
1409         case RID_AT_SYNTHESIZE:
1410           gcc_assert (c_dialect_objc ());
1411           c_parser_objc_at_synthesize_declaration (parser);
1412           break;
1413         case RID_AT_DYNAMIC:
1414           gcc_assert (c_dialect_objc ());
1415           c_parser_objc_at_dynamic_declaration (parser);
1416           break;
1417         case RID_AT_END:
1418           gcc_assert (c_dialect_objc ());
1419           c_parser_consume_token (parser);
1420           objc_finish_implementation ();
1421           break;
1422         default:
1423           goto decl_or_fndef;
1424         }
1425       break;
1426     case CPP_SEMICOLON:
1427       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1428                "ISO C does not allow extra %<;%> outside of a function");
1429       c_parser_consume_token (parser);
1430       break;
1431     case CPP_PRAGMA:
1432       mark_valid_location_for_stdc_pragma (true);
1433       c_parser_pragma (parser, pragma_external);
1434       mark_valid_location_for_stdc_pragma (false);
1435       break;
1436     case CPP_PLUS:
1437     case CPP_MINUS:
1438       if (c_dialect_objc ())
1439         {
1440           c_parser_objc_method_definition (parser);
1441           break;
1442         }
1443       /* Else fall through, and yield a syntax error trying to parse
1444          as a declaration or function definition.  */
1445     default:
1446     decl_or_fndef:
1447       /* A declaration or a function definition (or, in Objective-C,
1448          an @interface or @protocol with prefix attributes).  We can
1449          only tell which after parsing the declaration specifiers, if
1450          any, and the first declarator.  */
1451       c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1452                                      NULL, vNULL);
1453       break;
1454     }
1455 }
1456
1457 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1458
1459 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1460    6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
1461    accepted; otherwise (old-style parameter declarations) only other
1462    declarations are accepted.  If STATIC_ASSERT_OK is true, a static
1463    assertion is accepted; otherwise (old-style parameter declarations)
1464    it is not.  If NESTED is true, we are inside a function or parsing
1465    old-style parameter declarations; any functions encountered are
1466    nested functions and declaration specifiers are required; otherwise
1467    we are at top level and functions are normal functions and
1468    declaration specifiers may be optional.  If EMPTY_OK is true, empty
1469    declarations are OK (subject to all other constraints); otherwise
1470    (old-style parameter declarations) they are diagnosed.  If
1471    START_ATTR_OK is true, the declaration specifiers may start with
1472    attributes; otherwise they may not.
1473    OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1474    declaration when parsing an Objective-C foreach statement.
1475
1476    declaration:
1477      declaration-specifiers init-declarator-list[opt] ;
1478      static_assert-declaration
1479
1480    function-definition:
1481      declaration-specifiers[opt] declarator declaration-list[opt]
1482        compound-statement
1483
1484    declaration-list:
1485      declaration
1486      declaration-list declaration
1487
1488    init-declarator-list:
1489      init-declarator
1490      init-declarator-list , init-declarator
1491
1492    init-declarator:
1493      declarator simple-asm-expr[opt] attributes[opt]
1494      declarator simple-asm-expr[opt] attributes[opt] = initializer
1495
1496    GNU extensions:
1497
1498    nested-function-definition:
1499      declaration-specifiers declarator declaration-list[opt]
1500        compound-statement
1501
1502    Objective-C:
1503      attributes objc-class-definition
1504      attributes objc-category-definition
1505      attributes objc-protocol-definition
1506
1507    The simple-asm-expr and attributes are GNU extensions.
1508
1509    This function does not handle __extension__; that is handled in its
1510    callers.  ??? Following the old parser, __extension__ may start
1511    external declarations, declarations in functions and declarations
1512    at the start of "for" loops, but not old-style parameter
1513    declarations.
1514
1515    C99 requires declaration specifiers in a function definition; the
1516    absence is diagnosed through the diagnosis of implicit int.  In GNU
1517    C we also allow but diagnose declarations without declaration
1518    specifiers, but only at top level (elsewhere they conflict with
1519    other syntax).
1520
1521    In Objective-C, declarations of the looping variable in a foreach
1522    statement are exceptionally terminated by 'in' (for example, 'for
1523    (NSObject *object in array) { ... }').
1524
1525    OpenMP:
1526
1527    declaration:
1528      threadprivate-directive  */
1529
1530 static void
1531 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1532                                bool static_assert_ok, bool empty_ok,
1533                                bool nested, bool start_attr_ok,
1534                                tree *objc_foreach_object_declaration,
1535                                vec<c_token> omp_declare_simd_clauses)
1536 {
1537   struct c_declspecs *specs;
1538   tree prefix_attrs;
1539   tree all_prefix_attrs;
1540   bool diagnosed_no_specs = false;
1541   location_t here = c_parser_peek_token (parser)->location;
1542
1543   if (static_assert_ok
1544       && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1545     {
1546       c_parser_static_assert_declaration (parser);
1547       return;
1548     }
1549   specs = build_null_declspecs ();
1550
1551   /* Try to detect an unknown type name when we have "A B" or "A *B".  */
1552   if (c_parser_peek_token (parser)->type == CPP_NAME
1553       && c_parser_peek_token (parser)->id_kind == C_ID_ID
1554       && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1555           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1556       && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1557     {
1558       error_at (here, "unknown type name %qE",
1559                 c_parser_peek_token (parser)->value);
1560
1561       /* Parse declspecs normally to get a correct pointer type, but avoid
1562          a further "fails to be a type name" error.  Refuse nested functions
1563          since it is not how the user likely wants us to recover.  */
1564       c_parser_peek_token (parser)->type = CPP_KEYWORD;
1565       c_parser_peek_token (parser)->keyword = RID_VOID;
1566       c_parser_peek_token (parser)->value = error_mark_node;
1567       fndef_ok = !nested;
1568     }
1569
1570   c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1571                       true, true, cla_nonabstract_decl);
1572   if (parser->error)
1573     {
1574       c_parser_skip_to_end_of_block_or_statement (parser);
1575       return;
1576     }
1577   if (nested && !specs->declspecs_seen_p)
1578     {
1579       c_parser_error (parser, "expected declaration specifiers");
1580       c_parser_skip_to_end_of_block_or_statement (parser);
1581       return;
1582     }
1583   finish_declspecs (specs);
1584   bool auto_type_p = specs->typespec_word == cts_auto_type;
1585   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1586     {
1587       if (auto_type_p)
1588         error_at (here, "%<__auto_type%> in empty declaration");
1589       else if (empty_ok)
1590         shadow_tag (specs);
1591       else
1592         {
1593           shadow_tag_warned (specs, 1);
1594           pedwarn (here, 0, "empty declaration");
1595         }
1596       c_parser_consume_token (parser);
1597       return;
1598     }
1599
1600   /* Provide better error recovery.  Note that a type name here is usually
1601      better diagnosed as a redeclaration.  */
1602   if (empty_ok
1603       && specs->typespec_kind == ctsk_tagdef
1604       && c_parser_next_token_starts_declspecs (parser)
1605       && !c_parser_next_token_is (parser, CPP_NAME))
1606     {
1607       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1608       parser->error = false;
1609       shadow_tag_warned (specs, 1);
1610       return;
1611     }
1612   else if (c_dialect_objc () && !auto_type_p)
1613     {
1614       /* Prefix attributes are an error on method decls.  */
1615       switch (c_parser_peek_token (parser)->type)
1616         {
1617           case CPP_PLUS:
1618           case CPP_MINUS:
1619             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1620               return;
1621             if (specs->attrs)
1622               {
1623                 warning_at (c_parser_peek_token (parser)->location, 
1624                             OPT_Wattributes,
1625                             "prefix attributes are ignored for methods");
1626                 specs->attrs = NULL_TREE;
1627               }
1628             if (fndef_ok)
1629               c_parser_objc_method_definition (parser);
1630             else
1631               c_parser_objc_methodproto (parser);
1632             return;
1633             break;
1634           default:
1635             break;
1636         }
1637       /* This is where we parse 'attributes @interface ...',
1638          'attributes @implementation ...', 'attributes @protocol ...'
1639          (where attributes could be, for example, __attribute__
1640          ((deprecated)).
1641       */
1642       switch (c_parser_peek_token (parser)->keyword)
1643         {
1644         case RID_AT_INTERFACE:
1645           {
1646             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1647               return;
1648             c_parser_objc_class_definition (parser, specs->attrs);
1649             return;
1650           }
1651           break;
1652         case RID_AT_IMPLEMENTATION:
1653           {
1654             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1655               return;
1656             if (specs->attrs)
1657               {
1658                 warning_at (c_parser_peek_token (parser)->location, 
1659                         OPT_Wattributes,
1660                         "prefix attributes are ignored for implementations");
1661                 specs->attrs = NULL_TREE;
1662               }
1663             c_parser_objc_class_definition (parser, NULL_TREE);     
1664             return;
1665           }
1666           break;
1667         case RID_AT_PROTOCOL:
1668           {
1669             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1670               return;
1671             c_parser_objc_protocol_definition (parser, specs->attrs);
1672             return;
1673           }
1674           break;
1675         case RID_AT_ALIAS:
1676         case RID_AT_CLASS:
1677         case RID_AT_END:
1678         case RID_AT_PROPERTY:
1679           if (specs->attrs)
1680             {
1681               c_parser_error (parser, "unexpected attribute");
1682               specs->attrs = NULL;
1683             }
1684           break;
1685         default:
1686           break;
1687         }
1688     }
1689   
1690   pending_xref_error ();
1691   prefix_attrs = specs->attrs;
1692   all_prefix_attrs = prefix_attrs;
1693   specs->attrs = NULL_TREE;
1694   while (true)
1695     {
1696       struct c_declarator *declarator;
1697       bool dummy = false;
1698       timevar_id_t tv;
1699       tree fnbody;
1700       /* Declaring either one or more declarators (in which case we
1701          should diagnose if there were no declaration specifiers) or a
1702          function definition (in which case the diagnostic for
1703          implicit int suffices).  */
1704       declarator = c_parser_declarator (parser, 
1705                                         specs->typespec_kind != ctsk_none,
1706                                         C_DTR_NORMAL, &dummy);
1707       if (declarator == NULL)
1708         {
1709           if (omp_declare_simd_clauses.exists ()
1710               || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1711             c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1712                                        omp_declare_simd_clauses);
1713           c_parser_skip_to_end_of_block_or_statement (parser);
1714           return;
1715         }
1716       if (auto_type_p && declarator->kind != cdk_id)
1717         {
1718           error_at (here,
1719                     "%<__auto_type%> requires a plain identifier"
1720                     " as declarator");
1721           c_parser_skip_to_end_of_block_or_statement (parser);
1722           return;
1723         }
1724       if (c_parser_next_token_is (parser, CPP_EQ)
1725           || c_parser_next_token_is (parser, CPP_COMMA)
1726           || c_parser_next_token_is (parser, CPP_SEMICOLON)
1727           || c_parser_next_token_is_keyword (parser, RID_ASM)
1728           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1729           || c_parser_next_token_is_keyword (parser, RID_IN))
1730         {
1731           tree asm_name = NULL_TREE;
1732           tree postfix_attrs = NULL_TREE;
1733           if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1734             {
1735               diagnosed_no_specs = true;
1736               pedwarn (here, 0, "data definition has no type or storage class");
1737             }
1738           /* Having seen a data definition, there cannot now be a
1739              function definition.  */
1740           fndef_ok = false;
1741           if (c_parser_next_token_is_keyword (parser, RID_ASM))
1742             asm_name = c_parser_simple_asm_expr (parser);
1743           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1744             {
1745               postfix_attrs = c_parser_attributes (parser);
1746               if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1747                 {
1748                   /* This means there is an attribute specifier after
1749                      the declarator in a function definition.  Provide
1750                      some more information for the user.  */
1751                   error_at (here, "attributes should be specified before the "
1752                             "declarator in a function definition");
1753                   c_parser_skip_to_end_of_block_or_statement (parser);
1754                   return;
1755                 }
1756             }
1757           if (c_parser_next_token_is (parser, CPP_EQ))
1758             {
1759               tree d;
1760               struct c_expr init;
1761               location_t init_loc;
1762               c_parser_consume_token (parser);
1763               if (auto_type_p)
1764                 {
1765                   start_init (NULL_TREE, asm_name, global_bindings_p ());
1766                   init_loc = c_parser_peek_token (parser)->location;
1767                   init = c_parser_expr_no_commas (parser, NULL);
1768                   if (TREE_CODE (init.value) == COMPONENT_REF
1769                       && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
1770                     error_at (here,
1771                               "%<__auto_type%> used with a bit-field"
1772                               " initializer");
1773                   init = convert_lvalue_to_rvalue (init_loc, init, true, true);
1774                   tree init_type = TREE_TYPE (init.value);
1775                   /* As with typeof, remove all qualifiers from atomic types.  */
1776                   if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
1777                     init_type
1778                       = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
1779                   bool vm_type = variably_modified_type_p (init_type,
1780                                                            NULL_TREE);
1781                   if (vm_type)
1782                     init.value = c_save_expr (init.value);
1783                   finish_init ();
1784                   specs->typespec_kind = ctsk_typeof;
1785                   specs->locations[cdw_typedef] = init_loc;
1786                   specs->typedef_p = true;
1787                   specs->type = init_type;
1788                   if (vm_type)
1789                     {
1790                       bool maybe_const = true;
1791                       tree type_expr = c_fully_fold (init.value, false,
1792                                                      &maybe_const);
1793                       specs->expr_const_operands &= maybe_const;
1794                       if (specs->expr)
1795                         specs->expr = build2 (COMPOUND_EXPR,
1796                                               TREE_TYPE (type_expr),
1797                                               specs->expr, type_expr);
1798                       else
1799                         specs->expr = type_expr;
1800                     }
1801                   d = start_decl (declarator, specs, true,
1802                                   chainon (postfix_attrs, all_prefix_attrs));
1803                   if (!d)
1804                     d = error_mark_node;
1805                   if (omp_declare_simd_clauses.exists ()
1806                       || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1807                     c_finish_omp_declare_simd (parser, d, NULL_TREE,
1808                                                omp_declare_simd_clauses);
1809                 }
1810               else
1811                 {
1812                   /* The declaration of the variable is in effect while
1813                      its initializer is parsed.  */
1814                   d = start_decl (declarator, specs, true,
1815                                   chainon (postfix_attrs, all_prefix_attrs));
1816                   if (!d)
1817                     d = error_mark_node;
1818                   if (omp_declare_simd_clauses.exists ()
1819                       || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1820                     c_finish_omp_declare_simd (parser, d, NULL_TREE,
1821                                                omp_declare_simd_clauses);
1822                   start_init (d, asm_name, global_bindings_p ());
1823                   init_loc = c_parser_peek_token (parser)->location;
1824                   init = c_parser_initializer (parser);
1825                   finish_init ();
1826                 }
1827               if (d != error_mark_node)
1828                 {
1829                   maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
1830                   finish_decl (d, init_loc, init.value,
1831                                init.original_type, asm_name);
1832                 }
1833             }
1834           else
1835             {
1836               if (auto_type_p)
1837                 {
1838                   error_at (here,
1839                             "%<__auto_type%> requires an initialized "
1840                             "data declaration");
1841                   c_parser_skip_to_end_of_block_or_statement (parser);
1842                   return;
1843                 }
1844               tree d = start_decl (declarator, specs, false,
1845                                    chainon (postfix_attrs,
1846                                             all_prefix_attrs));
1847               if (omp_declare_simd_clauses.exists ()
1848                   || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1849                 {
1850                   tree parms = NULL_TREE;
1851                   if (d && TREE_CODE (d) == FUNCTION_DECL)
1852                     {
1853                       struct c_declarator *ce = declarator;
1854                       while (ce != NULL)
1855                         if (ce->kind == cdk_function)
1856                           {
1857                             parms = ce->u.arg_info->parms;
1858                             break;
1859                           }
1860                         else
1861                           ce = ce->declarator;
1862                     }
1863                   if (parms)
1864                     temp_store_parm_decls (d, parms);
1865                   c_finish_omp_declare_simd (parser, d, parms,
1866                                              omp_declare_simd_clauses);
1867                   if (parms)
1868                     temp_pop_parm_decls ();
1869                 }
1870               if (d)
1871                 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1872                              NULL_TREE, asm_name);
1873               
1874               if (c_parser_next_token_is_keyword (parser, RID_IN))
1875                 {
1876                   if (d)
1877                     *objc_foreach_object_declaration = d;
1878                   else
1879                     *objc_foreach_object_declaration = error_mark_node;             
1880                 }
1881             }
1882           if (c_parser_next_token_is (parser, CPP_COMMA))
1883             {
1884               if (auto_type_p)
1885                 {
1886                   error_at (here,
1887                             "%<__auto_type%> may only be used with"
1888                             " a single declarator");
1889                   c_parser_skip_to_end_of_block_or_statement (parser);
1890                   return;
1891                 }
1892               c_parser_consume_token (parser);
1893               if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1894                 all_prefix_attrs = chainon (c_parser_attributes (parser),
1895                                             prefix_attrs);
1896               else
1897                 all_prefix_attrs = prefix_attrs;
1898               continue;
1899             }
1900           else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1901             {
1902               c_parser_consume_token (parser);
1903               return;
1904             }
1905           else if (c_parser_next_token_is_keyword (parser, RID_IN))
1906             {
1907               /* This can only happen in Objective-C: we found the
1908                  'in' that terminates the declaration inside an
1909                  Objective-C foreach statement.  Do not consume the
1910                  token, so that the caller can use it to determine
1911                  that this indeed is a foreach context.  */
1912               return;
1913             }
1914           else
1915             {
1916               c_parser_error (parser, "expected %<,%> or %<;%>");
1917               c_parser_skip_to_end_of_block_or_statement (parser);
1918               return;
1919             }
1920         }
1921       else if (auto_type_p)
1922         {
1923           error_at (here,
1924                     "%<__auto_type%> requires an initialized data declaration");
1925           c_parser_skip_to_end_of_block_or_statement (parser);
1926           return;
1927         }
1928       else if (!fndef_ok)
1929         {
1930           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1931                           "%<asm%> or %<__attribute__%>");
1932           c_parser_skip_to_end_of_block_or_statement (parser);
1933           return;
1934         }
1935       /* Function definition (nested or otherwise).  */
1936       if (nested)
1937         {
1938           pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
1939           c_push_function_context ();
1940         }
1941       if (!start_function (specs, declarator, all_prefix_attrs))
1942         {
1943           /* This can appear in many cases looking nothing like a
1944              function definition, so we don't give a more specific
1945              error suggesting there was one.  */
1946           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1947                           "or %<__attribute__%>");
1948           if (nested)
1949             c_pop_function_context ();
1950           break;
1951         }
1952
1953       if (DECL_DECLARED_INLINE_P (current_function_decl))
1954         tv = TV_PARSE_INLINE;
1955       else
1956         tv = TV_PARSE_FUNC;
1957       timevar_push (tv);
1958
1959       /* Parse old-style parameter declarations.  ??? Attributes are
1960          not allowed to start declaration specifiers here because of a
1961          syntax conflict between a function declaration with attribute
1962          suffix and a function definition with an attribute prefix on
1963          first old-style parameter declaration.  Following the old
1964          parser, they are not accepted on subsequent old-style
1965          parameter declarations either.  However, there is no
1966          ambiguity after the first declaration, nor indeed on the
1967          first as long as we don't allow postfix attributes after a
1968          declarator with a nonempty identifier list in a definition;
1969          and postfix attributes have never been accepted here in
1970          function definitions either.  */
1971       while (c_parser_next_token_is_not (parser, CPP_EOF)
1972              && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1973         c_parser_declaration_or_fndef (parser, false, false, false,
1974                                        true, false, NULL, vNULL);
1975       store_parm_decls ();
1976       if (omp_declare_simd_clauses.exists ()
1977           || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1978         c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
1979                                    omp_declare_simd_clauses);
1980       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1981         = c_parser_peek_token (parser)->location;
1982       fnbody = c_parser_compound_statement (parser);
1983       if (flag_cilkplus && contains_array_notation_expr (fnbody))
1984         fnbody = expand_array_notation_exprs (fnbody);
1985       if (nested)
1986         {
1987           tree decl = current_function_decl;
1988           /* Mark nested functions as needing static-chain initially.
1989              lower_nested_functions will recompute it but the
1990              DECL_STATIC_CHAIN flag is also used before that happens,
1991              by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
1992           DECL_STATIC_CHAIN (decl) = 1;
1993           add_stmt (fnbody);
1994           finish_function ();
1995           c_pop_function_context ();
1996           add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1997         }
1998       else
1999         {
2000           add_stmt (fnbody);
2001           finish_function ();
2002         }
2003
2004       timevar_pop (tv);
2005       break;
2006     }
2007 }
2008
2009 /* Parse an asm-definition (asm() outside a function body).  This is a
2010    GNU extension.
2011
2012    asm-definition:
2013      simple-asm-expr ;
2014 */
2015
2016 static void
2017 c_parser_asm_definition (c_parser *parser)
2018 {
2019   tree asm_str = c_parser_simple_asm_expr (parser);
2020   if (asm_str)
2021     symtab->finalize_toplevel_asm (asm_str);
2022   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2023 }
2024
2025 /* Parse a static assertion (C11 6.7.10).
2026
2027    static_assert-declaration:
2028      static_assert-declaration-no-semi ;
2029 */
2030
2031 static void
2032 c_parser_static_assert_declaration (c_parser *parser)
2033 {
2034   c_parser_static_assert_declaration_no_semi (parser);
2035   if (parser->error
2036       || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2037     c_parser_skip_to_end_of_block_or_statement (parser);
2038 }
2039
2040 /* Parse a static assertion (C11 6.7.10), without the trailing
2041    semicolon.
2042
2043    static_assert-declaration-no-semi:
2044      _Static_assert ( constant-expression , string-literal )
2045 */
2046
2047 static void
2048 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2049 {
2050   location_t assert_loc, value_loc;
2051   tree value;
2052   tree string;
2053
2054   gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2055   assert_loc = c_parser_peek_token (parser)->location;
2056   if (flag_isoc99)
2057     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2058                  "ISO C99 does not support %<_Static_assert%>");
2059   else
2060     pedwarn_c99 (assert_loc, OPT_Wpedantic,
2061                  "ISO C90 does not support %<_Static_assert%>");
2062   c_parser_consume_token (parser);
2063   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2064     return;
2065   value_loc = c_parser_peek_token (parser)->location;
2066   value = c_parser_expr_no_commas (parser, NULL).value;
2067   parser->lex_untranslated_string = true;
2068   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2069     {
2070       parser->lex_untranslated_string = false;
2071       return;
2072     }
2073   switch (c_parser_peek_token (parser)->type)
2074     {
2075     case CPP_STRING:
2076     case CPP_STRING16:
2077     case CPP_STRING32:
2078     case CPP_WSTRING:
2079     case CPP_UTF8STRING:
2080       string = c_parser_peek_token (parser)->value;
2081       c_parser_consume_token (parser);
2082       parser->lex_untranslated_string = false;
2083       break;
2084     default:
2085       c_parser_error (parser, "expected string literal");
2086       parser->lex_untranslated_string = false;
2087       return;
2088     }
2089   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2090
2091   if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2092     {
2093       error_at (value_loc, "expression in static assertion is not an integer");
2094       return;
2095     }
2096   if (TREE_CODE (value) != INTEGER_CST)
2097     {
2098       value = c_fully_fold (value, false, NULL);
2099       /* Strip no-op conversions.  */
2100       STRIP_TYPE_NOPS (value);
2101       if (TREE_CODE (value) == INTEGER_CST)
2102         pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2103                  "is not an integer constant expression");
2104     }
2105   if (TREE_CODE (value) != INTEGER_CST)
2106     {
2107       error_at (value_loc, "expression in static assertion is not constant");
2108       return;
2109     }
2110   constant_expression_warning (value);
2111   if (integer_zerop (value))
2112     error_at (assert_loc, "static assertion failed: %E", string);
2113 }
2114
2115 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2116    6.7), adding them to SPECS (which may already include some).
2117    Storage class specifiers are accepted iff SCSPEC_OK; type
2118    specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2119    accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2120    iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2121
2122    declaration-specifiers:
2123      storage-class-specifier declaration-specifiers[opt]
2124      type-specifier declaration-specifiers[opt]
2125      type-qualifier declaration-specifiers[opt]
2126      function-specifier declaration-specifiers[opt]
2127      alignment-specifier declaration-specifiers[opt]
2128
2129    Function specifiers (inline) are from C99, and are currently
2130    handled as storage class specifiers, as is __thread.  Alignment
2131    specifiers are from C11.
2132
2133    C90 6.5.1, C99 6.7.1:
2134    storage-class-specifier:
2135      typedef
2136      extern
2137      static
2138      auto
2139      register
2140      _Thread_local
2141
2142    (_Thread_local is new in C11.)
2143
2144    C99 6.7.4:
2145    function-specifier:
2146      inline
2147      _Noreturn
2148
2149    (_Noreturn is new in C11.)
2150
2151    C90 6.5.2, C99 6.7.2:
2152    type-specifier:
2153      void
2154      char
2155      short
2156      int
2157      long
2158      float
2159      double
2160      signed
2161      unsigned
2162      _Bool
2163      _Complex
2164      [_Imaginary removed in C99 TC2]
2165      struct-or-union-specifier
2166      enum-specifier
2167      typedef-name
2168      atomic-type-specifier
2169
2170    (_Bool and _Complex are new in C99.)
2171    (atomic-type-specifier is new in C11.)
2172
2173    C90 6.5.3, C99 6.7.3:
2174
2175    type-qualifier:
2176      const
2177      restrict
2178      volatile
2179      address-space-qualifier
2180      _Atomic
2181
2182    (restrict is new in C99.)
2183    (_Atomic is new in C11.)
2184
2185    GNU extensions:
2186
2187    declaration-specifiers:
2188      attributes declaration-specifiers[opt]
2189
2190    type-qualifier:
2191      address-space
2192
2193    address-space:
2194      identifier recognized by the target
2195
2196    storage-class-specifier:
2197      __thread
2198
2199    type-specifier:
2200      typeof-specifier
2201      __auto_type
2202      __intN
2203      _Decimal32
2204      _Decimal64
2205      _Decimal128
2206      _Fract
2207      _Accum
2208      _Sat
2209
2210   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2211    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2212
2213    atomic-type-specifier
2214     _Atomic ( type-name )
2215
2216    Objective-C:
2217
2218    type-specifier:
2219      class-name objc-protocol-refs[opt]
2220      typedef-name objc-protocol-refs
2221      objc-protocol-refs
2222 */
2223
2224 static void
2225 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2226                     bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2227                     bool alignspec_ok, bool auto_type_ok,
2228                     enum c_lookahead_kind la)
2229 {
2230   bool attrs_ok = start_attr_ok;
2231   bool seen_type = specs->typespec_kind != ctsk_none;
2232
2233   if (!typespec_ok)
2234     gcc_assert (la == cla_prefer_id);
2235
2236   while (c_parser_next_token_is (parser, CPP_NAME)
2237          || c_parser_next_token_is (parser, CPP_KEYWORD)
2238          || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2239     {
2240       struct c_typespec t;
2241       tree attrs;
2242       tree align;
2243       location_t loc = c_parser_peek_token (parser)->location;
2244
2245       /* If we cannot accept a type, exit if the next token must start
2246          one.  Also, if we already have seen a tagged definition,
2247          a typename would be an error anyway and likely the user
2248          has simply forgotten a semicolon, so we exit.  */
2249       if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2250           && c_parser_next_tokens_start_typename (parser, la)
2251           && !c_parser_next_token_is_qualifier (parser))
2252         break;
2253
2254       if (c_parser_next_token_is (parser, CPP_NAME))
2255         {
2256           c_token *name_token = c_parser_peek_token (parser);
2257           tree value = name_token->value;
2258           c_id_kind kind = name_token->id_kind;
2259
2260           if (kind == C_ID_ADDRSPACE)
2261             {
2262               addr_space_t as
2263                 = name_token->keyword - RID_FIRST_ADDR_SPACE;
2264               declspecs_add_addrspace (name_token->location, specs, as);
2265               c_parser_consume_token (parser);
2266               attrs_ok = true;
2267               continue;
2268             }
2269
2270           gcc_assert (!c_parser_next_token_is_qualifier (parser));
2271
2272           /* If we cannot accept a type, and the next token must start one,
2273              exit.  Do the same if we already have seen a tagged definition,
2274              since it would be an error anyway and likely the user has simply
2275              forgotten a semicolon.  */
2276           if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2277             break;
2278
2279           /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2280              a C_ID_CLASSNAME.  */
2281           c_parser_consume_token (parser);
2282           seen_type = true;
2283           attrs_ok = true;
2284           if (kind == C_ID_ID)
2285             {
2286               error_at (loc, "unknown type name %qE", value);
2287               t.kind = ctsk_typedef;
2288               t.spec = error_mark_node;
2289             }
2290           else if (kind == C_ID_TYPENAME
2291                    && (!c_dialect_objc ()
2292                        || c_parser_next_token_is_not (parser, CPP_LESS)))
2293             {
2294               t.kind = ctsk_typedef;
2295               /* For a typedef name, record the meaning, not the name.
2296                  In case of 'foo foo, bar;'.  */
2297               t.spec = lookup_name (value);
2298             }
2299           else
2300             {
2301               tree proto = NULL_TREE;
2302               gcc_assert (c_dialect_objc ());
2303               t.kind = ctsk_objc;
2304               if (c_parser_next_token_is (parser, CPP_LESS))
2305                 proto = c_parser_objc_protocol_refs (parser);
2306               t.spec = objc_get_protocol_qualified_type (value, proto);
2307             }
2308           t.expr = NULL_TREE;
2309           t.expr_const_operands = true;
2310           declspecs_add_type (name_token->location, specs, t);
2311           continue;
2312         }
2313       if (c_parser_next_token_is (parser, CPP_LESS))
2314         {
2315           /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2316              nisse@lysator.liu.se.  */
2317           tree proto;
2318           gcc_assert (c_dialect_objc ());
2319           if (!typespec_ok || seen_type)
2320             break;
2321           proto = c_parser_objc_protocol_refs (parser);
2322           t.kind = ctsk_objc;
2323           t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2324           t.expr = NULL_TREE;
2325           t.expr_const_operands = true;
2326           declspecs_add_type (loc, specs, t);
2327           continue;
2328         }
2329       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2330       switch (c_parser_peek_token (parser)->keyword)
2331         {
2332         case RID_STATIC:
2333         case RID_EXTERN:
2334         case RID_REGISTER:
2335         case RID_TYPEDEF:
2336         case RID_INLINE:
2337         case RID_NORETURN:
2338         case RID_AUTO:
2339         case RID_THREAD:
2340           if (!scspec_ok)
2341             goto out;
2342           attrs_ok = true;
2343           /* TODO: Distinguish between function specifiers (inline, noreturn)
2344              and storage class specifiers, either here or in
2345              declspecs_add_scspec.  */
2346           declspecs_add_scspec (loc, specs,
2347                                 c_parser_peek_token (parser)->value);
2348           c_parser_consume_token (parser);
2349           break;
2350         case RID_AUTO_TYPE:
2351           if (!auto_type_ok)
2352             goto out;
2353           /* Fall through.  */
2354         case RID_UNSIGNED:
2355         case RID_LONG:
2356         case RID_SHORT:
2357         case RID_SIGNED:
2358         case RID_COMPLEX:
2359         case RID_INT:
2360         case RID_CHAR:
2361         case RID_FLOAT:
2362         case RID_DOUBLE:
2363         case RID_VOID:
2364         case RID_DFLOAT32:
2365         case RID_DFLOAT64:
2366         case RID_DFLOAT128:
2367         case RID_BOOL:
2368         case RID_FRACT:
2369         case RID_ACCUM:
2370         case RID_SAT:
2371         case RID_INT_N_0:
2372         case RID_INT_N_1:
2373         case RID_INT_N_2:
2374         case RID_INT_N_3:
2375           if (!typespec_ok)
2376             goto out;
2377           attrs_ok = true;
2378           seen_type = true;
2379           if (c_dialect_objc ())
2380             parser->objc_need_raw_identifier = true;
2381           t.kind = ctsk_resword;
2382           t.spec = c_parser_peek_token (parser)->value;
2383           t.expr = NULL_TREE;
2384           t.expr_const_operands = true;
2385           declspecs_add_type (loc, specs, t);
2386           c_parser_consume_token (parser);
2387           break;
2388         case RID_ENUM:
2389           if (!typespec_ok)
2390             goto out;
2391           attrs_ok = true;
2392           seen_type = true;
2393           t = c_parser_enum_specifier (parser);
2394           declspecs_add_type (loc, specs, t);
2395           break;
2396         case RID_STRUCT:
2397         case RID_UNION:
2398           if (!typespec_ok)
2399             goto out;
2400           attrs_ok = true;
2401           seen_type = true;
2402           t = c_parser_struct_or_union_specifier (parser);
2403           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2404           declspecs_add_type (loc, specs, t);
2405           break;
2406         case RID_TYPEOF:
2407           /* ??? The old parser rejected typeof after other type
2408              specifiers, but is a syntax error the best way of
2409              handling this?  */
2410           if (!typespec_ok || seen_type)
2411             goto out;
2412           attrs_ok = true;
2413           seen_type = true;
2414           t = c_parser_typeof_specifier (parser);
2415           declspecs_add_type (loc, specs, t);
2416           break;
2417         case RID_ATOMIC:
2418           /* C parser handling of Objective-C constructs needs
2419              checking for correct lvalue-to-rvalue conversions, and
2420              the code in build_modify_expr handling various
2421              Objective-C cases, and that in build_unary_op handling
2422              Objective-C cases for increment / decrement, also needs
2423              updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2424              and objc_types_are_equivalent may also need updates.  */
2425           if (c_dialect_objc ())
2426             sorry ("%<_Atomic%> in Objective-C");
2427           /* C parser handling of OpenMP constructs needs checking for
2428              correct lvalue-to-rvalue conversions.  */
2429           if (flag_openmp)
2430             sorry ("%<_Atomic%> with OpenMP");
2431           if (flag_isoc99)
2432             pedwarn_c99 (loc, OPT_Wpedantic,
2433                          "ISO C99 does not support the %<_Atomic%> qualifier");
2434           else
2435             pedwarn_c99 (loc, OPT_Wpedantic,
2436                          "ISO C90 does not support the %<_Atomic%> qualifier");
2437           attrs_ok = true;
2438           tree value;
2439           value = c_parser_peek_token (parser)->value;
2440           c_parser_consume_token (parser);
2441           if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2442             {
2443               /* _Atomic ( type-name ).  */
2444               seen_type = true;
2445               c_parser_consume_token (parser);
2446               struct c_type_name *type = c_parser_type_name (parser);
2447               t.kind = ctsk_typeof;
2448               t.spec = error_mark_node;
2449               t.expr = NULL_TREE;
2450               t.expr_const_operands = true;
2451               if (type != NULL)
2452                 t.spec = groktypename (type, &t.expr,
2453                                        &t.expr_const_operands);
2454               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2455                                          "expected %<)%>");
2456               if (t.spec != error_mark_node)
2457                 {
2458                   if (TREE_CODE (t.spec) == ARRAY_TYPE)
2459                     error_at (loc, "%<_Atomic%>-qualified array type");
2460                   else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2461                     error_at (loc, "%<_Atomic%>-qualified function type");
2462                   else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2463                     error_at (loc, "%<_Atomic%> applied to a qualified type");
2464                   else
2465                     t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2466                 }
2467               declspecs_add_type (loc, specs, t);
2468             }
2469           else
2470             declspecs_add_qual (loc, specs, value);
2471           break;
2472         case RID_CONST:
2473         case RID_VOLATILE:
2474         case RID_RESTRICT:
2475           attrs_ok = true;
2476           declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2477           c_parser_consume_token (parser);
2478           break;
2479         case RID_ATTRIBUTE:
2480           if (!attrs_ok)
2481             goto out;
2482           attrs = c_parser_attributes (parser);
2483           declspecs_add_attrs (loc, specs, attrs);
2484           break;
2485         case RID_ALIGNAS:
2486           if (!alignspec_ok)
2487             goto out;
2488           align = c_parser_alignas_specifier (parser);
2489           declspecs_add_alignas (loc, specs, align);
2490           break;
2491         default:
2492           goto out;
2493         }
2494     }
2495  out: ;
2496 }
2497
2498 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2499
2500    enum-specifier:
2501      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2502      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2503      enum attributes[opt] identifier
2504
2505    The form with trailing comma is new in C99.  The forms with
2506    attributes are GNU extensions.  In GNU C, we accept any expression
2507    without commas in the syntax (assignment expressions, not just
2508    conditional expressions); assignment expressions will be diagnosed
2509    as non-constant.
2510
2511    enumerator-list:
2512      enumerator
2513      enumerator-list , enumerator
2514
2515    enumerator:
2516      enumeration-constant
2517      enumeration-constant = constant-expression
2518 */
2519
2520 static struct c_typespec
2521 c_parser_enum_specifier (c_parser *parser)
2522 {
2523   struct c_typespec ret;
2524   tree attrs;
2525   tree ident = NULL_TREE;
2526   location_t enum_loc;
2527   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2528   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2529   enum_loc = c_parser_peek_token (parser)->location;
2530   c_parser_consume_token (parser);
2531   attrs = c_parser_attributes (parser);
2532   enum_loc = c_parser_peek_token (parser)->location;
2533   /* Set the location in case we create a decl now.  */
2534   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2535   if (c_parser_next_token_is (parser, CPP_NAME))
2536     {
2537       ident = c_parser_peek_token (parser)->value;
2538       ident_loc = c_parser_peek_token (parser)->location;
2539       enum_loc = ident_loc;
2540       c_parser_consume_token (parser);
2541     }
2542   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2543     {
2544       /* Parse an enum definition.  */
2545       struct c_enum_contents the_enum;
2546       tree type;
2547       tree postfix_attrs;
2548       /* We chain the enumerators in reverse order, then put them in
2549          forward order at the end.  */
2550       tree values;
2551       timevar_push (TV_PARSE_ENUM);
2552       type = start_enum (enum_loc, &the_enum, ident);
2553       values = NULL_TREE;
2554       c_parser_consume_token (parser);
2555       while (true)
2556         {
2557           tree enum_id;
2558           tree enum_value;
2559           tree enum_decl;
2560           bool seen_comma;
2561           c_token *token;
2562           location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2563           location_t decl_loc, value_loc;
2564           if (c_parser_next_token_is_not (parser, CPP_NAME))
2565             {
2566               c_parser_error (parser, "expected identifier");
2567               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2568               values = error_mark_node;
2569               break;
2570             }
2571           token = c_parser_peek_token (parser);
2572           enum_id = token->value;
2573           /* Set the location in case we create a decl now.  */
2574           c_parser_set_source_position_from_token (token);
2575           decl_loc = value_loc = token->location;
2576           c_parser_consume_token (parser);
2577           if (c_parser_next_token_is (parser, CPP_EQ))
2578             {
2579               c_parser_consume_token (parser);
2580               value_loc = c_parser_peek_token (parser)->location;
2581               enum_value = c_parser_expr_no_commas (parser, NULL).value;
2582             }
2583           else
2584             enum_value = NULL_TREE;
2585           enum_decl = build_enumerator (decl_loc, value_loc,
2586                                         &the_enum, enum_id, enum_value);
2587           TREE_CHAIN (enum_decl) = values;
2588           values = enum_decl;
2589           seen_comma = false;
2590           if (c_parser_next_token_is (parser, CPP_COMMA))
2591             {
2592               comma_loc = c_parser_peek_token (parser)->location;
2593               seen_comma = true;
2594               c_parser_consume_token (parser);
2595             }
2596           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2597             {
2598               if (seen_comma)
2599                 pedwarn_c90 (comma_loc, OPT_Wpedantic,
2600                              "comma at end of enumerator list");
2601               c_parser_consume_token (parser);
2602               break;
2603             }
2604           if (!seen_comma)
2605             {
2606               c_parser_error (parser, "expected %<,%> or %<}%>");
2607               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2608               values = error_mark_node;
2609               break;
2610             }
2611         }
2612       postfix_attrs = c_parser_attributes (parser);
2613       ret.spec = finish_enum (type, nreverse (values),
2614                               chainon (attrs, postfix_attrs));
2615       ret.kind = ctsk_tagdef;
2616       ret.expr = NULL_TREE;
2617       ret.expr_const_operands = true;
2618       timevar_pop (TV_PARSE_ENUM);
2619       return ret;
2620     }
2621   else if (!ident)
2622     {
2623       c_parser_error (parser, "expected %<{%>");
2624       ret.spec = error_mark_node;
2625       ret.kind = ctsk_tagref;
2626       ret.expr = NULL_TREE;
2627       ret.expr_const_operands = true;
2628       return ret;
2629     }
2630   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2631   /* In ISO C, enumerated types can be referred to only if already
2632      defined.  */
2633   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2634     {
2635       gcc_assert (ident);
2636       pedwarn (enum_loc, OPT_Wpedantic,
2637                "ISO C forbids forward references to %<enum%> types");
2638     }
2639   return ret;
2640 }
2641
2642 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2643
2644    struct-or-union-specifier:
2645      struct-or-union attributes[opt] identifier[opt]
2646        { struct-contents } attributes[opt]
2647      struct-or-union attributes[opt] identifier
2648
2649    struct-contents:
2650      struct-declaration-list
2651
2652    struct-declaration-list:
2653      struct-declaration ;
2654      struct-declaration-list struct-declaration ;
2655
2656    GNU extensions:
2657
2658    struct-contents:
2659      empty
2660      struct-declaration
2661      struct-declaration-list struct-declaration
2662
2663    struct-declaration-list:
2664      struct-declaration-list ;
2665      ;
2666
2667    (Note that in the syntax here, unlike that in ISO C, the semicolons
2668    are included here rather than in struct-declaration, in order to
2669    describe the syntax with extra semicolons and missing semicolon at
2670    end.)
2671
2672    Objective-C:
2673
2674    struct-declaration-list:
2675      @defs ( class-name )
2676
2677    (Note this does not include a trailing semicolon, but can be
2678    followed by further declarations, and gets a pedwarn-if-pedantic
2679    when followed by a semicolon.)  */
2680
2681 static struct c_typespec
2682 c_parser_struct_or_union_specifier (c_parser *parser)
2683 {
2684   struct c_typespec ret;
2685   tree attrs;
2686   tree ident = NULL_TREE;
2687   location_t struct_loc;
2688   location_t ident_loc = UNKNOWN_LOCATION;
2689   enum tree_code code;
2690   switch (c_parser_peek_token (parser)->keyword)
2691     {
2692     case RID_STRUCT:
2693       code = RECORD_TYPE;
2694       break;
2695     case RID_UNION:
2696       code = UNION_TYPE;
2697       break;
2698     default:
2699       gcc_unreachable ();
2700     }
2701   struct_loc = c_parser_peek_token (parser)->location;
2702   c_parser_consume_token (parser);
2703   attrs = c_parser_attributes (parser);
2704
2705   /* Set the location in case we create a decl now.  */
2706   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2707
2708   if (c_parser_next_token_is (parser, CPP_NAME))
2709     {
2710       ident = c_parser_peek_token (parser)->value;
2711       ident_loc = c_parser_peek_token (parser)->location;
2712       struct_loc = ident_loc;
2713       c_parser_consume_token (parser);
2714     }
2715   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2716     {
2717       /* Parse a struct or union definition.  Start the scope of the
2718          tag before parsing components.  */
2719       struct c_struct_parse_info *struct_info;
2720       tree type = start_struct (struct_loc, code, ident, &struct_info);
2721       tree postfix_attrs;
2722       /* We chain the components in reverse order, then put them in
2723          forward order at the end.  Each struct-declaration may
2724          declare multiple components (comma-separated), so we must use
2725          chainon to join them, although when parsing each
2726          struct-declaration we can use TREE_CHAIN directly.
2727
2728          The theory behind all this is that there will be more
2729          semicolon separated fields than comma separated fields, and
2730          so we'll be minimizing the number of node traversals required
2731          by chainon.  */
2732       tree contents;
2733       timevar_push (TV_PARSE_STRUCT);
2734       contents = NULL_TREE;
2735       c_parser_consume_token (parser);
2736       /* Handle the Objective-C @defs construct,
2737          e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
2738       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2739         {
2740           tree name;
2741           gcc_assert (c_dialect_objc ());
2742           c_parser_consume_token (parser);
2743           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2744             goto end_at_defs;
2745           if (c_parser_next_token_is (parser, CPP_NAME)
2746               && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2747             {
2748               name = c_parser_peek_token (parser)->value;
2749               c_parser_consume_token (parser);
2750             }
2751           else
2752             {
2753               c_parser_error (parser, "expected class name");
2754               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2755               goto end_at_defs;
2756             }
2757           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2758                                      "expected %<)%>");
2759           contents = nreverse (objc_get_class_ivars (name));
2760         }
2761     end_at_defs:
2762       /* Parse the struct-declarations and semicolons.  Problems with
2763          semicolons are diagnosed here; empty structures are diagnosed
2764          elsewhere.  */
2765       while (true)
2766         {
2767           tree decls;
2768           /* Parse any stray semicolon.  */
2769           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2770             {
2771               pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2772                        "extra semicolon in struct or union specified");
2773               c_parser_consume_token (parser);
2774               continue;
2775             }
2776           /* Stop if at the end of the struct or union contents.  */
2777           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2778             {
2779               c_parser_consume_token (parser);
2780               break;
2781             }
2782           /* Accept #pragmas at struct scope.  */
2783           if (c_parser_next_token_is (parser, CPP_PRAGMA))
2784             {
2785               c_parser_pragma (parser, pragma_struct);
2786               continue;
2787             }
2788           /* Parse some comma-separated declarations, but not the
2789              trailing semicolon if any.  */
2790           decls = c_parser_struct_declaration (parser);
2791           contents = chainon (decls, contents);
2792           /* If no semicolon follows, either we have a parse error or
2793              are at the end of the struct or union and should
2794              pedwarn.  */
2795           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2796             c_parser_consume_token (parser);
2797           else
2798             {
2799               if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2800                 pedwarn (c_parser_peek_token (parser)->location, 0,
2801                          "no semicolon at end of struct or union");
2802               else if (parser->error
2803                        || !c_parser_next_token_starts_declspecs (parser))
2804                 {
2805                   c_parser_error (parser, "expected %<;%>");
2806                   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2807                   break;
2808                 }
2809
2810               /* If we come here, we have already emitted an error
2811                  for an expected `;', identifier or `(', and we also
2812                  recovered already.  Go on with the next field. */
2813             }
2814         }
2815       postfix_attrs = c_parser_attributes (parser);
2816       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2817                                 chainon (attrs, postfix_attrs), struct_info);
2818       ret.kind = ctsk_tagdef;
2819       ret.expr = NULL_TREE;
2820       ret.expr_const_operands = true;
2821       timevar_pop (TV_PARSE_STRUCT);
2822       return ret;
2823     }
2824   else if (!ident)
2825     {
2826       c_parser_error (parser, "expected %<{%>");
2827       ret.spec = error_mark_node;
2828       ret.kind = ctsk_tagref;
2829       ret.expr = NULL_TREE;
2830       ret.expr_const_operands = true;
2831       return ret;
2832     }
2833   ret = parser_xref_tag (ident_loc, code, ident);
2834   return ret;
2835 }
2836
2837 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2838    the trailing semicolon.
2839
2840    struct-declaration:
2841      specifier-qualifier-list struct-declarator-list
2842      static_assert-declaration-no-semi
2843
2844    specifier-qualifier-list:
2845      type-specifier specifier-qualifier-list[opt]
2846      type-qualifier specifier-qualifier-list[opt]
2847      attributes specifier-qualifier-list[opt]
2848
2849    struct-declarator-list:
2850      struct-declarator
2851      struct-declarator-list , attributes[opt] struct-declarator
2852
2853    struct-declarator:
2854      declarator attributes[opt]
2855      declarator[opt] : constant-expression attributes[opt]
2856
2857    GNU extensions:
2858
2859    struct-declaration:
2860      __extension__ struct-declaration
2861      specifier-qualifier-list
2862
2863    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
2864    of attributes where shown is a GNU extension.  In GNU C, we accept
2865    any expression without commas in the syntax (assignment
2866    expressions, not just conditional expressions); assignment
2867    expressions will be diagnosed as non-constant.  */
2868
2869 static tree
2870 c_parser_struct_declaration (c_parser *parser)
2871 {
2872   struct c_declspecs *specs;
2873   tree prefix_attrs;
2874   tree all_prefix_attrs;
2875   tree decls;
2876   location_t decl_loc;
2877   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2878     {
2879       int ext;
2880       tree decl;
2881       ext = disable_extension_diagnostics ();
2882       c_parser_consume_token (parser);
2883       decl = c_parser_struct_declaration (parser);
2884       restore_extension_diagnostics (ext);
2885       return decl;
2886     }
2887   if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2888     {
2889       c_parser_static_assert_declaration_no_semi (parser);
2890       return NULL_TREE;
2891     }
2892   specs = build_null_declspecs ();
2893   decl_loc = c_parser_peek_token (parser)->location;
2894   /* Strictly by the standard, we shouldn't allow _Alignas here,
2895      but it appears to have been intended to allow it there, so
2896      we're keeping it as it is until WG14 reaches a conclusion
2897      of N1731.
2898      <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf>  */
2899   c_parser_declspecs (parser, specs, false, true, true,
2900                       true, false, cla_nonabstract_decl);
2901   if (parser->error)
2902     return NULL_TREE;
2903   if (!specs->declspecs_seen_p)
2904     {
2905       c_parser_error (parser, "expected specifier-qualifier-list");
2906       return NULL_TREE;
2907     }
2908   finish_declspecs (specs);
2909   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2910       || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2911     {
2912       tree ret;
2913       if (specs->typespec_kind == ctsk_none)
2914         {
2915           pedwarn (decl_loc, OPT_Wpedantic,
2916                    "ISO C forbids member declarations with no members");
2917           shadow_tag_warned (specs, pedantic);
2918           ret = NULL_TREE;
2919         }
2920       else
2921         {
2922           /* Support for unnamed structs or unions as members of
2923              structs or unions (which is [a] useful and [b] supports
2924              MS P-SDK).  */
2925           tree attrs = NULL;
2926
2927           ret = grokfield (c_parser_peek_token (parser)->location,
2928                            build_id_declarator (NULL_TREE), specs,
2929                            NULL_TREE, &attrs);
2930           if (ret)
2931             decl_attributes (&ret, attrs, 0);
2932         }
2933       return ret;
2934     }
2935
2936   /* Provide better error recovery.  Note that a type name here is valid,
2937      and will be treated as a field name.  */
2938   if (specs->typespec_kind == ctsk_tagdef
2939       && TREE_CODE (specs->type) != ENUMERAL_TYPE
2940       && c_parser_next_token_starts_declspecs (parser)
2941       && !c_parser_next_token_is (parser, CPP_NAME))
2942     {
2943       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2944       parser->error = false;
2945       return NULL_TREE;
2946     }
2947
2948   pending_xref_error ();
2949   prefix_attrs = specs->attrs;
2950   all_prefix_attrs = prefix_attrs;
2951   specs->attrs = NULL_TREE;
2952   decls = NULL_TREE;
2953   while (true)
2954     {
2955       /* Declaring one or more declarators or un-named bit-fields.  */
2956       struct c_declarator *declarator;
2957       bool dummy = false;
2958       if (c_parser_next_token_is (parser, CPP_COLON))
2959         declarator = build_id_declarator (NULL_TREE);
2960       else
2961         declarator = c_parser_declarator (parser,
2962                                           specs->typespec_kind != ctsk_none,
2963                                           C_DTR_NORMAL, &dummy);
2964       if (declarator == NULL)
2965         {
2966           c_parser_skip_to_end_of_block_or_statement (parser);
2967           break;
2968         }
2969       if (c_parser_next_token_is (parser, CPP_COLON)
2970           || c_parser_next_token_is (parser, CPP_COMMA)
2971           || c_parser_next_token_is (parser, CPP_SEMICOLON)
2972           || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2973           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2974         {
2975           tree postfix_attrs = NULL_TREE;
2976           tree width = NULL_TREE;
2977           tree d;
2978           if (c_parser_next_token_is (parser, CPP_COLON))
2979             {
2980               c_parser_consume_token (parser);
2981               width = c_parser_expr_no_commas (parser, NULL).value;
2982             }
2983           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2984             postfix_attrs = c_parser_attributes (parser);
2985           d = grokfield (c_parser_peek_token (parser)->location,
2986                          declarator, specs, width, &all_prefix_attrs);
2987           decl_attributes (&d, chainon (postfix_attrs,
2988                                         all_prefix_attrs), 0);
2989           DECL_CHAIN (d) = decls;
2990           decls = d;
2991           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2992             all_prefix_attrs = chainon (c_parser_attributes (parser),
2993                                         prefix_attrs);
2994           else
2995             all_prefix_attrs = prefix_attrs;
2996           if (c_parser_next_token_is (parser, CPP_COMMA))
2997             c_parser_consume_token (parser);
2998           else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2999                    || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3000             {
3001               /* Semicolon consumed in caller.  */
3002               break;
3003             }
3004           else
3005             {
3006               c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3007               break;
3008             }
3009         }
3010       else
3011         {
3012           c_parser_error (parser,
3013                           "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3014                           "%<__attribute__%>");
3015           break;
3016         }
3017     }
3018   return decls;
3019 }
3020
3021 /* Parse a typeof specifier (a GNU extension).
3022
3023    typeof-specifier:
3024      typeof ( expression )
3025      typeof ( type-name )
3026 */
3027
3028 static struct c_typespec
3029 c_parser_typeof_specifier (c_parser *parser)
3030 {
3031   struct c_typespec ret;
3032   ret.kind = ctsk_typeof;
3033   ret.spec = error_mark_node;
3034   ret.expr = NULL_TREE;
3035   ret.expr_const_operands = true;
3036   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3037   c_parser_consume_token (parser);
3038   c_inhibit_evaluation_warnings++;
3039   in_typeof++;
3040   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3041     {
3042       c_inhibit_evaluation_warnings--;
3043       in_typeof--;
3044       return ret;
3045     }
3046   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3047     {
3048       struct c_type_name *type = c_parser_type_name (parser);
3049       c_inhibit_evaluation_warnings--;
3050       in_typeof--;
3051       if (type != NULL)
3052         {
3053           ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3054           pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3055         }
3056     }
3057   else
3058     {
3059       bool was_vm;
3060       location_t here = c_parser_peek_token (parser)->location;
3061       struct c_expr expr = c_parser_expression (parser);
3062       c_inhibit_evaluation_warnings--;
3063       in_typeof--;
3064       if (TREE_CODE (expr.value) == COMPONENT_REF
3065           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3066         error_at (here, "%<typeof%> applied to a bit-field");
3067       mark_exp_read (expr.value);
3068       ret.spec = TREE_TYPE (expr.value);
3069       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3070       /* This is returned with the type so that when the type is
3071          evaluated, this can be evaluated.  */
3072       if (was_vm)
3073         ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3074       pop_maybe_used (was_vm);
3075       /* For use in macros such as those in <stdatomic.h>, remove all
3076          qualifiers from atomic types.  (const can be an issue for more macros
3077          using typeof than just the <stdatomic.h> ones.)  */
3078       if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3079         ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3080     }
3081   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3082   return ret;
3083 }
3084
3085 /* Parse an alignment-specifier.
3086
3087    C11 6.7.5:
3088
3089    alignment-specifier:
3090      _Alignas ( type-name )
3091      _Alignas ( constant-expression )
3092 */
3093
3094 static tree
3095 c_parser_alignas_specifier (c_parser * parser)
3096 {
3097   tree ret = error_mark_node;
3098   location_t loc = c_parser_peek_token (parser)->location;
3099   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3100   c_parser_consume_token (parser);
3101   if (flag_isoc99)
3102     pedwarn_c99 (loc, OPT_Wpedantic,
3103                  "ISO C99 does not support %<_Alignas%>");
3104   else
3105     pedwarn_c99 (loc, OPT_Wpedantic,
3106                  "ISO C90 does not support %<_Alignas%>");
3107   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3108     return ret;
3109   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3110     {
3111       struct c_type_name *type = c_parser_type_name (parser);
3112       if (type != NULL)
3113         ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3114                                         false, true, 1);
3115     }
3116   else
3117     ret = c_parser_expr_no_commas (parser, NULL).value;
3118   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3119   return ret;
3120 }
3121
3122 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3123    6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
3124    be redeclared; otherwise it may not.  KIND indicates which kind of
3125    declarator is wanted.  Returns a valid declarator except in the
3126    case of a syntax error in which case NULL is returned.  *SEEN_ID is
3127    set to true if an identifier being declared is seen; this is used
3128    to diagnose bad forms of abstract array declarators and to
3129    determine whether an identifier list is syntactically permitted.
3130
3131    declarator:
3132      pointer[opt] direct-declarator
3133
3134    direct-declarator:
3135      identifier
3136      ( attributes[opt] declarator )
3137      direct-declarator array-declarator
3138      direct-declarator ( parameter-type-list )
3139      direct-declarator ( identifier-list[opt] )
3140
3141    pointer:
3142      * type-qualifier-list[opt]
3143      * type-qualifier-list[opt] pointer
3144
3145    type-qualifier-list:
3146      type-qualifier
3147      attributes
3148      type-qualifier-list type-qualifier
3149      type-qualifier-list attributes
3150
3151    array-declarator:
3152      [ type-qualifier-list[opt] assignment-expression[opt] ]
3153      [ static type-qualifier-list[opt] assignment-expression ]
3154      [ type-qualifier-list static assignment-expression ]
3155      [ type-qualifier-list[opt] * ]
3156
3157    parameter-type-list:
3158      parameter-list
3159      parameter-list , ...
3160
3161    parameter-list:
3162      parameter-declaration
3163      parameter-list , parameter-declaration
3164
3165    parameter-declaration:
3166      declaration-specifiers declarator attributes[opt]
3167      declaration-specifiers abstract-declarator[opt] attributes[opt]
3168
3169    identifier-list:
3170      identifier
3171      identifier-list , identifier
3172
3173    abstract-declarator:
3174      pointer
3175      pointer[opt] direct-abstract-declarator
3176
3177    direct-abstract-declarator:
3178      ( attributes[opt] abstract-declarator )
3179      direct-abstract-declarator[opt] array-declarator
3180      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3181
3182    GNU extensions:
3183
3184    direct-declarator:
3185      direct-declarator ( parameter-forward-declarations
3186                          parameter-type-list[opt] )
3187
3188    direct-abstract-declarator:
3189      direct-abstract-declarator[opt] ( parameter-forward-declarations
3190                                        parameter-type-list[opt] )
3191
3192    parameter-forward-declarations:
3193      parameter-list ;
3194      parameter-forward-declarations parameter-list ;
3195
3196    The uses of attributes shown above are GNU extensions.
3197
3198    Some forms of array declarator are not included in C99 in the
3199    syntax for abstract declarators; these are disallowed elsewhere.
3200    This may be a defect (DR#289).
3201
3202    This function also accepts an omitted abstract declarator as being
3203    an abstract declarator, although not part of the formal syntax.  */
3204
3205 static struct c_declarator *
3206 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3207                      bool *seen_id)
3208 {
3209   /* Parse any initial pointer part.  */
3210   if (c_parser_next_token_is (parser, CPP_MULT))
3211     {
3212       struct c_declspecs *quals_attrs = build_null_declspecs ();
3213       struct c_declarator *inner;
3214       c_parser_consume_token (parser);
3215       c_parser_declspecs (parser, quals_attrs, false, false, true,
3216                           false, false, cla_prefer_id);
3217       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3218       if (inner == NULL)
3219         return NULL;
3220       else
3221         return make_pointer_declarator (quals_attrs, inner);
3222     }
3223   /* Now we have a direct declarator, direct abstract declarator or
3224      nothing (which counts as a direct abstract declarator here).  */
3225   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3226 }
3227
3228 /* Parse a direct declarator or direct abstract declarator; arguments
3229    as c_parser_declarator.  */
3230
3231 static struct c_declarator *
3232 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3233                             bool *seen_id)
3234 {
3235   /* The direct declarator must start with an identifier (possibly
3236      omitted) or a parenthesized declarator (possibly abstract).  In
3237      an ordinary declarator, initial parentheses must start a
3238      parenthesized declarator.  In an abstract declarator or parameter
3239      declarator, they could start a parenthesized declarator or a
3240      parameter list.  To tell which, the open parenthesis and any
3241      following attributes must be read.  If a declaration specifier
3242      follows, then it is a parameter list; if the specifier is a
3243      typedef name, there might be an ambiguity about redeclaring it,
3244      which is resolved in the direction of treating it as a typedef
3245      name.  If a close parenthesis follows, it is also an empty
3246      parameter list, as the syntax does not permit empty abstract
3247      declarators.  Otherwise, it is a parenthesized declarator (in
3248      which case the analysis may be repeated inside it, recursively).
3249
3250      ??? There is an ambiguity in a parameter declaration "int
3251      (__attribute__((foo)) x)", where x is not a typedef name: it
3252      could be an abstract declarator for a function, or declare x with
3253      parentheses.  The proper resolution of this ambiguity needs
3254      documenting.  At present we follow an accident of the old
3255      parser's implementation, whereby the first parameter must have
3256      some declaration specifiers other than just attributes.  Thus as
3257      a parameter declaration it is treated as a parenthesized
3258      parameter named x, and as an abstract declarator it is
3259      rejected.
3260
3261      ??? Also following the old parser, attributes inside an empty
3262      parameter list are ignored, making it a list not yielding a
3263      prototype, rather than giving an error or making it have one
3264      parameter with implicit type int.
3265
3266      ??? Also following the old parser, typedef names may be
3267      redeclared in declarators, but not Objective-C class names.  */
3268
3269   if (kind != C_DTR_ABSTRACT
3270       && c_parser_next_token_is (parser, CPP_NAME)
3271       && ((type_seen_p
3272            && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3273                || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3274           || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3275     {
3276       struct c_declarator *inner
3277         = build_id_declarator (c_parser_peek_token (parser)->value);
3278       *seen_id = true;
3279       inner->id_loc = c_parser_peek_token (parser)->location;
3280       c_parser_consume_token (parser);
3281       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3282     }
3283
3284   if (kind != C_DTR_NORMAL
3285       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3286     {
3287       struct c_declarator *inner = build_id_declarator (NULL_TREE);
3288       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3289     }
3290
3291   /* Either we are at the end of an abstract declarator, or we have
3292      parentheses.  */
3293
3294   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3295     {
3296       tree attrs;
3297       struct c_declarator *inner;
3298       c_parser_consume_token (parser);
3299       attrs = c_parser_attributes (parser);
3300       if (kind != C_DTR_NORMAL
3301           && (c_parser_next_token_starts_declspecs (parser)
3302               || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3303         {
3304           struct c_arg_info *args
3305             = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3306                                          attrs);
3307           if (args == NULL)
3308             return NULL;
3309           else
3310             {
3311               inner
3312                 = build_function_declarator (args,
3313                                              build_id_declarator (NULL_TREE));
3314               return c_parser_direct_declarator_inner (parser, *seen_id,
3315                                                        inner);
3316             }
3317         }
3318       /* A parenthesized declarator.  */
3319       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3320       if (inner != NULL && attrs != NULL)
3321         inner = build_attrs_declarator (attrs, inner);
3322       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3323         {
3324           c_parser_consume_token (parser);
3325           if (inner == NULL)
3326             return NULL;
3327           else
3328             return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3329         }
3330       else
3331         {
3332           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3333                                      "expected %<)%>");
3334           return NULL;
3335         }
3336     }
3337   else
3338     {
3339       if (kind == C_DTR_NORMAL)
3340         {
3341           c_parser_error (parser, "expected identifier or %<(%>");
3342           return NULL;
3343         }
3344       else
3345         return build_id_declarator (NULL_TREE);
3346     }
3347 }
3348
3349 /* Parse part of a direct declarator or direct abstract declarator,
3350    given that some (in INNER) has already been parsed; ID_PRESENT is
3351    true if an identifier is present, false for an abstract
3352    declarator.  */
3353
3354 static struct c_declarator *
3355 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3356                                   struct c_declarator *inner)
3357 {
3358   /* Parse a sequence of array declarators and parameter lists.  */
3359   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3360     {
3361       location_t brace_loc = c_parser_peek_token (parser)->location;
3362       struct c_declarator *declarator;
3363       struct c_declspecs *quals_attrs = build_null_declspecs ();
3364       bool static_seen;
3365       bool star_seen;
3366       struct c_expr dimen;
3367       dimen.value = NULL_TREE;
3368       dimen.original_code = ERROR_MARK;
3369       dimen.original_type = NULL_TREE;
3370       c_parser_consume_token (parser);
3371       c_parser_declspecs (parser, quals_attrs, false, false, true,
3372                           false, false, cla_prefer_id);
3373       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3374       if (static_seen)
3375         c_parser_consume_token (parser);
3376       if (static_seen && !quals_attrs->declspecs_seen_p)
3377         c_parser_declspecs (parser, quals_attrs, false, false, true,
3378                             false, false, cla_prefer_id);
3379       if (!quals_attrs->declspecs_seen_p)
3380         quals_attrs = NULL;
3381       /* If "static" is present, there must be an array dimension.
3382          Otherwise, there may be a dimension, "*", or no
3383          dimension.  */
3384       if (static_seen)
3385         {
3386           star_seen = false;
3387           dimen = c_parser_expr_no_commas (parser, NULL);
3388         }
3389       else
3390         {
3391           if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3392             {
3393               dimen.value = NULL_TREE;
3394               star_seen = false;
3395             }
3396           else if (flag_cilkplus
3397                    && c_parser_next_token_is (parser, CPP_COLON))
3398             {
3399               dimen.value = error_mark_node;
3400               star_seen = false;
3401               error_at (c_parser_peek_token (parser)->location,
3402                         "array notations cannot be used in declaration");
3403               c_parser_consume_token (parser);
3404             }   
3405           else if (c_parser_next_token_is (parser, CPP_MULT))
3406             {
3407               if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3408                 {
3409                   dimen.value = NULL_TREE;
3410                   star_seen = true;
3411                   c_parser_consume_token (parser);
3412                 }
3413               else
3414                 {
3415                   star_seen = false;
3416                   dimen = c_parser_expr_no_commas (parser, NULL);
3417                 }
3418             }
3419           else
3420             {
3421               star_seen = false;
3422               dimen = c_parser_expr_no_commas (parser, NULL);
3423             }
3424         }
3425       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3426         c_parser_consume_token (parser);
3427       else if (flag_cilkplus
3428                && c_parser_next_token_is (parser, CPP_COLON))
3429         {
3430           error_at (c_parser_peek_token (parser)->location,
3431                     "array notations cannot be used in declaration");
3432           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
3433           return NULL;
3434         }
3435       else
3436         {
3437           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3438                                      "expected %<]%>");
3439           return NULL;
3440         }
3441       if (dimen.value)
3442         dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3443       declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3444                                            static_seen, star_seen);
3445       if (declarator == NULL)
3446         return NULL;
3447       inner = set_array_declarator_inner (declarator, inner);
3448       return c_parser_direct_declarator_inner (parser, id_present, inner);
3449     }
3450   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3451     {
3452       tree attrs;
3453       struct c_arg_info *args;
3454       c_parser_consume_token (parser);
3455       attrs = c_parser_attributes (parser);
3456       args = c_parser_parms_declarator (parser, id_present, attrs);
3457       if (args == NULL)
3458         return NULL;
3459       else
3460         {
3461           inner = build_function_declarator (args, inner);
3462           return c_parser_direct_declarator_inner (parser, id_present, inner);
3463         }
3464     }
3465   return inner;
3466 }
3467
3468 /* Parse a parameter list or identifier list, including the closing
3469    parenthesis but not the opening one.  ATTRS are the attributes at
3470    the start of the list.  ID_LIST_OK is true if an identifier list is
3471    acceptable; such a list must not have attributes at the start.  */
3472
3473 static struct c_arg_info *
3474 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3475 {
3476   push_scope ();
3477   declare_parm_level ();
3478   /* If the list starts with an identifier, it is an identifier list.
3479      Otherwise, it is either a prototype list or an empty list.  */
3480   if (id_list_ok
3481       && !attrs
3482       && c_parser_next_token_is (parser, CPP_NAME)
3483       && c_parser_peek_token (parser)->id_kind == C_ID_ID
3484       
3485       /* Look ahead to detect typos in type names.  */
3486       && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3487       && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3488       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3489       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3490     {
3491       tree list = NULL_TREE, *nextp = &list;
3492       while (c_parser_next_token_is (parser, CPP_NAME)
3493              && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3494         {
3495           *nextp = build_tree_list (NULL_TREE,
3496                                     c_parser_peek_token (parser)->value);
3497           nextp = & TREE_CHAIN (*nextp);
3498           c_parser_consume_token (parser);
3499           if (c_parser_next_token_is_not (parser, CPP_COMMA))
3500             break;
3501           c_parser_consume_token (parser);
3502           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3503             {
3504               c_parser_error (parser, "expected identifier");
3505               break;
3506             }
3507         }
3508       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3509         {
3510           struct c_arg_info *ret = build_arg_info ();
3511           ret->types = list;
3512           c_parser_consume_token (parser);
3513           pop_scope ();
3514           return ret;
3515         }
3516       else
3517         {
3518           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3519                                      "expected %<)%>");
3520           pop_scope ();
3521           return NULL;
3522         }
3523     }
3524   else
3525     {
3526       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3527                                                                NULL);
3528       pop_scope ();
3529       return ret;
3530     }
3531 }
3532
3533 /* Parse a parameter list (possibly empty), including the closing
3534    parenthesis but not the opening one.  ATTRS are the attributes at
3535    the start of the list.  EXPR is NULL or an expression that needs to
3536    be evaluated for the side effects of array size expressions in the
3537    parameters.  */
3538
3539 static struct c_arg_info *
3540 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3541 {
3542   bool bad_parm = false;
3543
3544   /* ??? Following the old parser, forward parameter declarations may
3545      use abstract declarators, and if no real parameter declarations
3546      follow the forward declarations then this is not diagnosed.  Also
3547      note as above that attributes are ignored as the only contents of
3548      the parentheses, or as the only contents after forward
3549      declarations.  */
3550   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3551     {
3552       struct c_arg_info *ret = build_arg_info ();
3553       c_parser_consume_token (parser);
3554       return ret;
3555     }
3556   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3557     {
3558       struct c_arg_info *ret = build_arg_info ();
3559
3560       if (flag_allow_parameterless_variadic_functions)
3561         {
3562           /* F (...) is allowed.  */
3563           ret->types = NULL_TREE;
3564         }
3565       else
3566         {
3567           /* Suppress -Wold-style-definition for this case.  */
3568           ret->types = error_mark_node;
3569           error_at (c_parser_peek_token (parser)->location,
3570                     "ISO C requires a named argument before %<...%>");
3571         }
3572       c_parser_consume_token (parser);
3573       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3574         {
3575           c_parser_consume_token (parser);
3576           return ret;
3577         }
3578       else
3579         {
3580           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3581                                      "expected %<)%>");
3582           return NULL;
3583         }
3584     }
3585   /* Nonempty list of parameters, either terminated with semicolon
3586      (forward declarations; recurse) or with close parenthesis (normal
3587      function) or with ", ... )" (variadic function).  */
3588   while (true)
3589     {
3590       /* Parse a parameter.  */
3591       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3592       attrs = NULL_TREE;
3593       if (parm == NULL)
3594         bad_parm = true;
3595       else
3596         push_parm_decl (parm, &expr);
3597       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3598         {
3599           tree new_attrs;
3600           c_parser_consume_token (parser);
3601           mark_forward_parm_decls ();
3602           new_attrs = c_parser_attributes (parser);
3603           return c_parser_parms_list_declarator (parser, new_attrs, expr);
3604         }
3605       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3606         {
3607           c_parser_consume_token (parser);
3608           if (bad_parm)
3609             return NULL;
3610           else
3611             return get_parm_info (false, expr);
3612         }
3613       if (!c_parser_require (parser, CPP_COMMA,
3614                              "expected %<;%>, %<,%> or %<)%>"))
3615         {
3616           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3617           return NULL;
3618         }
3619       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3620         {
3621           c_parser_consume_token (parser);
3622           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3623             {
3624               c_parser_consume_token (parser);
3625               if (bad_parm)
3626                 return NULL;
3627               else
3628                 return get_parm_info (true, expr);
3629             }
3630           else
3631             {
3632               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3633                                          "expected %<)%>");
3634               return NULL;
3635             }
3636         }
3637     }
3638 }
3639
3640 /* Parse a parameter declaration.  ATTRS are the attributes at the
3641    start of the declaration if it is the first parameter.  */
3642
3643 static struct c_parm *
3644 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3645 {
3646   struct c_declspecs *specs;
3647   struct c_declarator *declarator;
3648   tree prefix_attrs;
3649   tree postfix_attrs = NULL_TREE;
3650   bool dummy = false;
3651
3652   /* Accept #pragmas between parameter declarations.  */
3653   while (c_parser_next_token_is (parser, CPP_PRAGMA))
3654     c_parser_pragma (parser, pragma_param);
3655
3656   if (!c_parser_next_token_starts_declspecs (parser))
3657     {
3658       c_token *token = c_parser_peek_token (parser);
3659       if (parser->error)
3660         return NULL;
3661       c_parser_set_source_position_from_token (token);
3662       if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3663         {
3664           error_at (token->location, "unknown type name %qE", token->value);
3665           parser->error = true;
3666         }
3667       /* ??? In some Objective-C cases '...' isn't applicable so there
3668          should be a different message.  */
3669       else
3670         c_parser_error (parser,
3671                         "expected declaration specifiers or %<...%>");
3672       c_parser_skip_to_end_of_parameter (parser);
3673       return NULL;
3674     }
3675   specs = build_null_declspecs ();
3676   if (attrs)
3677     {
3678       declspecs_add_attrs (input_location, specs, attrs);
3679       attrs = NULL_TREE;
3680     }
3681   c_parser_declspecs (parser, specs, true, true, true, true, false,
3682                       cla_nonabstract_decl);
3683   finish_declspecs (specs);
3684   pending_xref_error ();
3685   prefix_attrs = specs->attrs;
3686   specs->attrs = NULL_TREE;
3687   declarator = c_parser_declarator (parser,
3688                                     specs->typespec_kind != ctsk_none,
3689                                     C_DTR_PARM, &dummy);
3690   if (declarator == NULL)
3691     {
3692       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3693       return NULL;
3694     }
3695   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3696     postfix_attrs = c_parser_attributes (parser);
3697   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3698                        declarator);
3699 }
3700
3701 /* Parse a string literal in an asm expression.  It should not be
3702    translated, and wide string literals are an error although
3703    permitted by the syntax.  This is a GNU extension.
3704
3705    asm-string-literal:
3706      string-literal
3707
3708    ??? At present, following the old parser, the caller needs to have
3709    set lex_untranslated_string to 1.  It would be better to follow the
3710    C++ parser rather than using this kludge.  */
3711
3712 static tree
3713 c_parser_asm_string_literal (c_parser *parser)
3714 {
3715   tree str;
3716   int save_flag = warn_overlength_strings;
3717   warn_overlength_strings = 0;
3718   if (c_parser_next_token_is (parser, CPP_STRING))
3719     {
3720       str = c_parser_peek_token (parser)->value;
3721       c_parser_consume_token (parser);
3722     }
3723   else if (c_parser_next_token_is (parser, CPP_WSTRING))
3724     {
3725       error_at (c_parser_peek_token (parser)->location,
3726                 "wide string literal in %<asm%>");
3727       str = build_string (1, "");
3728       c_parser_consume_token (parser);
3729     }
3730   else
3731     {
3732       c_parser_error (parser, "expected string literal");
3733       str = NULL_TREE;
3734     }
3735   warn_overlength_strings = save_flag;
3736   return str;
3737 }
3738
3739 /* Parse a simple asm expression.  This is used in restricted
3740    contexts, where a full expression with inputs and outputs does not
3741    make sense.  This is a GNU extension.
3742
3743    simple-asm-expr:
3744      asm ( asm-string-literal )
3745 */
3746
3747 static tree
3748 c_parser_simple_asm_expr (c_parser *parser)
3749 {
3750   tree str;
3751   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3752   /* ??? Follow the C++ parser rather than using the
3753      lex_untranslated_string kludge.  */
3754   parser->lex_untranslated_string = true;
3755   c_parser_consume_token (parser);
3756   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3757     {
3758       parser->lex_untranslated_string = false;
3759       return NULL_TREE;
3760     }
3761   str = c_parser_asm_string_literal (parser);
3762   parser->lex_untranslated_string = false;
3763   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3764     {
3765       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3766       return NULL_TREE;
3767     }
3768   return str;
3769 }
3770
3771 static tree
3772 c_parser_attribute_any_word (c_parser *parser)
3773 {
3774   tree attr_name = NULL_TREE;
3775
3776   if (c_parser_next_token_is (parser, CPP_KEYWORD))
3777     {
3778       /* ??? See comment above about what keywords are accepted here.  */
3779       bool ok;
3780       switch (c_parser_peek_token (parser)->keyword)
3781         {
3782         case RID_STATIC:
3783         case RID_UNSIGNED:
3784         case RID_LONG:
3785         case RID_CONST:
3786         case RID_EXTERN:
3787         case RID_REGISTER:
3788         case RID_TYPEDEF:
3789         case RID_SHORT:
3790         case RID_INLINE:
3791         case RID_NORETURN:
3792         case RID_VOLATILE:
3793         case RID_SIGNED:
3794         case RID_AUTO:
3795         case RID_RESTRICT:
3796         case RID_COMPLEX:
3797         case RID_THREAD:
3798         case RID_INT:
3799         case RID_CHAR:
3800         case RID_FLOAT:
3801         case RID_DOUBLE:
3802         case RID_VOID:
3803         case RID_DFLOAT32:
3804         case RID_DFLOAT64:
3805         case RID_DFLOAT128:
3806         case RID_BOOL:
3807         case RID_FRACT:
3808         case RID_ACCUM:
3809         case RID_SAT:
3810         case RID_TRANSACTION_ATOMIC:
3811         case RID_TRANSACTION_CANCEL:
3812         case RID_ATOMIC:
3813         case RID_AUTO_TYPE:
3814         case RID_INT_N_0:
3815         case RID_INT_N_1:
3816         case RID_INT_N_2:
3817         case RID_INT_N_3:
3818           ok = true;
3819           break;
3820         default:
3821           ok = false;
3822           break;
3823         }
3824       if (!ok)
3825         return NULL_TREE;
3826
3827       /* Accept __attribute__((__const)) as __attribute__((const)) etc.  */
3828       attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3829     }
3830   else if (c_parser_next_token_is (parser, CPP_NAME))
3831     attr_name = c_parser_peek_token (parser)->value;
3832
3833   return attr_name;
3834 }
3835
3836 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3837    "__vector" or "__vector__."  */
3838
3839 static inline bool
3840 is_cilkplus_vector_p (tree name)
3841
3842   if (flag_cilkplus && is_attribute_p ("vector", name)) 
3843     return true;
3844   return false;
3845 }
3846
3847 #define CILK_SIMD_FN_CLAUSE_MASK                                  \
3848         ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH)   \
3849          | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR)       \
3850          | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM)      \
3851          | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK)         \
3852          | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3853
3854 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3855    VEC_TOKEN is the "vector" token that is replaced with "simd" and
3856    pushed into the token list. 
3857    Syntax:
3858    vector
3859    vector (<vector attributes>).  */
3860
3861 static void
3862 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token)
3863 {
3864   gcc_assert (is_cilkplus_vector_p (vec_token.value));
3865   
3866   int paren_scope = 0;
3867   vec_safe_push (parser->cilk_simd_fn_tokens, vec_token);
3868   /* Consume the "vector" token.  */
3869   c_parser_consume_token (parser);
3870
3871   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3872     {
3873       c_parser_consume_token (parser);
3874       paren_scope++;
3875     }
3876   while (paren_scope > 0)
3877     {
3878       c_token *token = c_parser_peek_token (parser);
3879       if (token->type == CPP_OPEN_PAREN)
3880         paren_scope++;
3881       else if (token->type == CPP_CLOSE_PAREN)
3882         paren_scope--;
3883       /* Do not push the last ')' since we are not pushing the '('.  */
3884       if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0))
3885         vec_safe_push (parser->cilk_simd_fn_tokens, *token);
3886       c_parser_consume_token (parser);
3887     }
3888   
3889   /* Since we are converting an attribute to a pragma, we need to end the
3890      attribute with PRAGMA_EOL.  */
3891   c_token eol_token;
3892   memset (&eol_token, 0, sizeof (eol_token));
3893   eol_token.type = CPP_PRAGMA_EOL;
3894   vec_safe_push (parser->cilk_simd_fn_tokens, eol_token);
3895 }
3896
3897 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector.  */
3898
3899 static void
3900 c_finish_cilk_simd_fn_tokens (c_parser *parser)
3901 {
3902   c_token last_token = parser->cilk_simd_fn_tokens->last ();
3903
3904   /* c_parser_attributes is called in several places, so if these EOF
3905      tokens are already inserted, then don't do them again.  */
3906   if (last_token.type == CPP_EOF)
3907     return;
3908   
3909   /* Two CPP_EOF token are added as a safety net since the normal C
3910      front-end has two token look-ahead.  */
3911   c_token eof_token;
3912   eof_token.type = CPP_EOF;
3913   vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3914   vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3915 }
3916
3917 /* Parse (possibly empty) attributes.  This is a GNU extension.
3918
3919    attributes:
3920      empty
3921      attributes attribute
3922
3923    attribute:
3924      __attribute__ ( ( attribute-list ) )
3925
3926    attribute-list:
3927      attrib
3928      attribute_list , attrib
3929
3930    attrib:
3931      empty
3932      any-word
3933      any-word ( identifier )
3934      any-word ( identifier , nonempty-expr-list )
3935      any-word ( expr-list )
3936
3937    where the "identifier" must not be declared as a type, and
3938    "any-word" may be any identifier (including one declared as a
3939    type), a reserved word storage class specifier, type specifier or
3940    type qualifier.  ??? This still leaves out most reserved keywords
3941    (following the old parser), shouldn't we include them, and why not
3942    allow identifiers declared as types to start the arguments?  */
3943
3944 static tree
3945 c_parser_attributes (c_parser *parser)
3946 {
3947   tree attrs = NULL_TREE;
3948   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3949     {
3950       /* ??? Follow the C++ parser rather than using the
3951          lex_untranslated_string kludge.  */
3952       parser->lex_untranslated_string = true;
3953       c_parser_consume_token (parser);
3954       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3955         {
3956           parser->lex_untranslated_string = false;
3957           return attrs;
3958         }
3959       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3960         {
3961           parser->lex_untranslated_string = false;
3962           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3963           return attrs;
3964         }
3965       /* Parse the attribute list.  */
3966       while (c_parser_next_token_is (parser, CPP_COMMA)
3967              || c_parser_next_token_is (parser, CPP_NAME)
3968              || c_parser_next_token_is (parser, CPP_KEYWORD))
3969         {
3970           tree attr, attr_name, attr_args;
3971           vec<tree, va_gc> *expr_list;
3972           if (c_parser_next_token_is (parser, CPP_COMMA))
3973             {
3974               c_parser_consume_token (parser);
3975               continue;
3976             }
3977
3978           attr_name = c_parser_attribute_any_word (parser);
3979           if (attr_name == NULL)
3980             break;
3981           if (is_cilkplus_vector_p (attr_name))           
3982             {
3983               c_token *v_token = c_parser_peek_token (parser);
3984               c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
3985               continue;
3986             }
3987           c_parser_consume_token (parser);
3988           if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3989             {
3990               attr = build_tree_list (attr_name, NULL_TREE);
3991               attrs = chainon (attrs, attr);
3992               continue;
3993             }
3994           c_parser_consume_token (parser);
3995           /* Parse the attribute contents.  If they start with an
3996              identifier which is followed by a comma or close
3997              parenthesis, then the arguments start with that
3998              identifier; otherwise they are an expression list.  
3999              In objective-c the identifier may be a classname.  */
4000           if (c_parser_next_token_is (parser, CPP_NAME)
4001               && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4002                   || (c_dialect_objc ()
4003                       && c_parser_peek_token (parser)->id_kind
4004                          == C_ID_CLASSNAME))
4005               && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4006                   || (c_parser_peek_2nd_token (parser)->type
4007                       == CPP_CLOSE_PAREN))
4008               && (attribute_takes_identifier_p (attr_name)
4009                   || (c_dialect_objc ()
4010                       && c_parser_peek_token (parser)->id_kind
4011                          == C_ID_CLASSNAME)))
4012             {
4013               tree arg1 = c_parser_peek_token (parser)->value;
4014               c_parser_consume_token (parser);
4015               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4016                 attr_args = build_tree_list (NULL_TREE, arg1);
4017               else
4018                 {
4019                   tree tree_list;
4020                   c_parser_consume_token (parser);
4021                   expr_list = c_parser_expr_list (parser, false, true,
4022                                                   NULL, NULL, NULL, NULL);
4023                   tree_list = build_tree_list_vec (expr_list);
4024                   attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4025                   release_tree_vector (expr_list);
4026                 }
4027             }
4028           else
4029             {
4030               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4031                 attr_args = NULL_TREE;
4032               else
4033                 {
4034                   expr_list = c_parser_expr_list (parser, false, true,
4035                                                   NULL, NULL, NULL, NULL);
4036                   attr_args = build_tree_list_vec (expr_list);
4037                   release_tree_vector (expr_list);
4038                 }
4039             }
4040           attr = build_tree_list (attr_name, attr_args);
4041           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4042             c_parser_consume_token (parser);
4043           else
4044             {
4045               parser->lex_untranslated_string = false;
4046               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4047                                          "expected %<)%>");
4048               return attrs;
4049             }
4050           attrs = chainon (attrs, attr);
4051         }
4052       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4053         c_parser_consume_token (parser);
4054       else
4055         {
4056           parser->lex_untranslated_string = false;
4057           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4058                                      "expected %<)%>");
4059           return attrs;
4060         }
4061       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4062         c_parser_consume_token (parser);
4063       else
4064         {
4065           parser->lex_untranslated_string = false;
4066           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4067                                      "expected %<)%>");
4068           return attrs;
4069         }
4070       parser->lex_untranslated_string = false;
4071     }
4072
4073   if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
4074     c_finish_cilk_simd_fn_tokens (parser);
4075   return attrs;
4076 }
4077
4078 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4079
4080    type-name:
4081      specifier-qualifier-list abstract-declarator[opt]
4082 */
4083
4084 static struct c_type_name *
4085 c_parser_type_name (c_parser *parser)
4086 {
4087   struct c_declspecs *specs = build_null_declspecs ();
4088   struct c_declarator *declarator;
4089   struct c_type_name *ret;
4090   bool dummy = false;
4091   c_parser_declspecs (parser, specs, false, true, true, false, false,
4092                       cla_prefer_type);
4093   if (!specs->declspecs_seen_p)
4094     {
4095       c_parser_error (parser, "expected specifier-qualifier-list");
4096       return NULL;
4097     }
4098   if (specs->type != error_mark_node)
4099     {
4100       pending_xref_error ();
4101       finish_declspecs (specs);
4102     }
4103   declarator = c_parser_declarator (parser,
4104                                     specs->typespec_kind != ctsk_none,
4105                                     C_DTR_ABSTRACT, &dummy);
4106   if (declarator == NULL)
4107     return NULL;
4108   ret = XOBNEW (&parser_obstack, struct c_type_name);
4109   ret->specs = specs;
4110   ret->declarator = declarator;
4111   return ret;
4112 }
4113
4114 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4115
4116    initializer:
4117      assignment-expression
4118      { initializer-list }
4119      { initializer-list , }
4120
4121    initializer-list:
4122      designation[opt] initializer
4123      initializer-list , designation[opt] initializer
4124
4125    designation:
4126      designator-list =
4127
4128    designator-list:
4129      designator
4130      designator-list designator
4131
4132    designator:
4133      array-designator
4134      . identifier
4135
4136    array-designator:
4137      [ constant-expression ]
4138
4139    GNU extensions:
4140
4141    initializer:
4142      { }
4143
4144    designation:
4145      array-designator
4146      identifier :
4147
4148    array-designator:
4149      [ constant-expression ... constant-expression ]
4150
4151    Any expression without commas is accepted in the syntax for the
4152    constant-expressions, with non-constant expressions rejected later.
4153
4154    This function is only used for top-level initializers; for nested
4155    ones, see c_parser_initval.  */
4156
4157 static struct c_expr
4158 c_parser_initializer (c_parser *parser)
4159 {
4160   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4161     return c_parser_braced_init (parser, NULL_TREE, false);
4162   else
4163     {
4164       struct c_expr ret;
4165       location_t loc = c_parser_peek_token (parser)->location;
4166       ret = c_parser_expr_no_commas (parser, NULL);
4167       if (TREE_CODE (ret.value) != STRING_CST
4168           && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4169         ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4170       return ret;
4171     }
4172 }
4173
4174 /* Parse a braced initializer list.  TYPE is the type specified for a
4175    compound literal, and NULL_TREE for other initializers and for
4176    nested braced lists.  NESTED_P is true for nested braced lists,
4177    false for the list of a compound literal or the list that is the
4178    top-level initializer in a declaration.  */
4179
4180 static struct c_expr
4181 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
4182 {
4183   struct c_expr ret;
4184   struct obstack braced_init_obstack;
4185   location_t brace_loc = c_parser_peek_token (parser)->location;
4186   gcc_obstack_init (&braced_init_obstack);
4187   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4188   c_parser_consume_token (parser);
4189   if (nested_p)
4190     push_init_level (brace_loc, 0, &braced_init_obstack);
4191   else
4192     really_start_incremental_init (type);
4193   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4194     {
4195       pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4196     }
4197   else
4198     {
4199       /* Parse a non-empty initializer list, possibly with a trailing
4200          comma.  */
4201       while (true)
4202         {
4203           c_parser_initelt (parser, &braced_init_obstack);
4204           if (parser->error)
4205             break;
4206           if (c_parser_next_token_is (parser, CPP_COMMA))
4207             c_parser_consume_token (parser);
4208           else
4209             break;
4210           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4211             break;
4212         }
4213     }
4214   if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4215     {
4216       ret.value = error_mark_node;
4217       ret.original_code = ERROR_MARK;
4218       ret.original_type = NULL;
4219       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
4220       pop_init_level (brace_loc, 0, &braced_init_obstack);
4221       obstack_free (&braced_init_obstack, NULL);
4222       return ret;
4223     }
4224   c_parser_consume_token (parser);
4225   ret = pop_init_level (brace_loc, 0, &braced_init_obstack);
4226   obstack_free (&braced_init_obstack, NULL);
4227   return ret;
4228 }
4229
4230 /* Parse a nested initializer, including designators.  */
4231
4232 static void
4233 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4234 {
4235   /* Parse any designator or designator list.  A single array
4236      designator may have the subsequent "=" omitted in GNU C, but a
4237      longer list or a structure member designator may not.  */
4238   if (c_parser_next_token_is (parser, CPP_NAME)
4239       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4240     {
4241       /* Old-style structure member designator.  */
4242       set_init_label (c_parser_peek_token (parser)->location,
4243                       c_parser_peek_token (parser)->value,
4244                       braced_init_obstack);
4245       /* Use the colon as the error location.  */
4246       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4247                "obsolete use of designated initializer with %<:%>");
4248       c_parser_consume_token (parser);
4249       c_parser_consume_token (parser);
4250     }
4251   else
4252     {
4253       /* des_seen is 0 if there have been no designators, 1 if there
4254          has been a single array designator and 2 otherwise.  */
4255       int des_seen = 0;
4256       /* Location of a designator.  */
4257       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4258       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4259              || c_parser_next_token_is (parser, CPP_DOT))
4260         {
4261           int des_prev = des_seen;
4262           if (!des_seen)
4263             des_loc = c_parser_peek_token (parser)->location;
4264           if (des_seen < 2)
4265             des_seen++;
4266           if (c_parser_next_token_is (parser, CPP_DOT))
4267             {
4268               des_seen = 2;
4269               c_parser_consume_token (parser);
4270               if (c_parser_next_token_is (parser, CPP_NAME))
4271                 {
4272                   set_init_label (des_loc, c_parser_peek_token (parser)->value,
4273                                   braced_init_obstack);
4274                   c_parser_consume_token (parser);
4275                 }
4276               else
4277                 {
4278                   struct c_expr init;
4279                   init.value = error_mark_node;
4280                   init.original_code = ERROR_MARK;
4281                   init.original_type = NULL;
4282                   c_parser_error (parser, "expected identifier");
4283                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4284                   process_init_element (input_location, init, false,
4285                                         braced_init_obstack);
4286                   return;
4287                 }
4288             }
4289           else
4290             {
4291               tree first, second;
4292               location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4293               location_t array_index_loc = UNKNOWN_LOCATION;
4294               /* ??? Following the old parser, [ objc-receiver
4295                  objc-message-args ] is accepted as an initializer,
4296                  being distinguished from a designator by what follows
4297                  the first assignment expression inside the square
4298                  brackets, but after a first array designator a
4299                  subsequent square bracket is for Objective-C taken to
4300                  start an expression, using the obsolete form of
4301                  designated initializer without '=', rather than
4302                  possibly being a second level of designation: in LALR
4303                  terms, the '[' is shifted rather than reducing
4304                  designator to designator-list.  */
4305               if (des_prev == 1 && c_dialect_objc ())
4306                 {
4307                   des_seen = des_prev;
4308                   break;
4309                 }
4310               if (des_prev == 0 && c_dialect_objc ())
4311                 {
4312                   /* This might be an array designator or an
4313                      Objective-C message expression.  If the former,
4314                      continue parsing here; if the latter, parse the
4315                      remainder of the initializer given the starting
4316                      primary-expression.  ??? It might make sense to
4317                      distinguish when des_prev == 1 as well; see
4318                      previous comment.  */
4319                   tree rec, args;
4320                   struct c_expr mexpr;
4321                   c_parser_consume_token (parser);
4322                   if (c_parser_peek_token (parser)->type == CPP_NAME
4323                       && ((c_parser_peek_token (parser)->id_kind
4324                            == C_ID_TYPENAME)
4325                           || (c_parser_peek_token (parser)->id_kind
4326                               == C_ID_CLASSNAME)))
4327                     {
4328                       /* Type name receiver.  */
4329                       tree id = c_parser_peek_token (parser)->value;
4330                       c_parser_consume_token (parser);
4331                       rec = objc_get_class_reference (id);
4332                       goto parse_message_args;
4333                     }
4334                   first = c_parser_expr_no_commas (parser, NULL).value;
4335                   mark_exp_read (first);
4336                   if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4337                       || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4338                     goto array_desig_after_first;
4339                   /* Expression receiver.  So far only one part
4340                      without commas has been parsed; there might be
4341                      more of the expression.  */
4342                   rec = first;
4343                   while (c_parser_next_token_is (parser, CPP_COMMA))
4344                     {
4345                       struct c_expr next;
4346                       location_t comma_loc, exp_loc;
4347                       comma_loc = c_parser_peek_token (parser)->location;
4348                       c_parser_consume_token (parser);
4349                       exp_loc = c_parser_peek_token (parser)->location;
4350                       next = c_parser_expr_no_commas (parser, NULL);
4351                       next = convert_lvalue_to_rvalue (exp_loc, next,
4352                                                        true, true);
4353                       rec = build_compound_expr (comma_loc, rec, next.value);
4354                     }
4355                 parse_message_args:
4356                   /* Now parse the objc-message-args.  */
4357                   args = c_parser_objc_message_args (parser);
4358                   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4359                                              "expected %<]%>");
4360                   mexpr.value
4361                     = objc_build_message_expr (rec, args);
4362                   mexpr.original_code = ERROR_MARK;
4363                   mexpr.original_type = NULL;
4364                   /* Now parse and process the remainder of the
4365                      initializer, starting with this message
4366                      expression as a primary-expression.  */
4367                   c_parser_initval (parser, &mexpr, braced_init_obstack);
4368                   return;
4369                 }
4370               c_parser_consume_token (parser);
4371               array_index_loc = c_parser_peek_token (parser)->location;
4372               first = c_parser_expr_no_commas (parser, NULL).value;
4373               mark_exp_read (first);
4374             array_desig_after_first:
4375               if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4376                 {
4377                   ellipsis_loc = c_parser_peek_token (parser)->location;
4378                   c_parser_consume_token (parser);
4379                   second = c_parser_expr_no_commas (parser, NULL).value;
4380                   mark_exp_read (second);
4381                 }
4382               else
4383                 second = NULL_TREE;
4384               if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4385                 {
4386                   c_parser_consume_token (parser);
4387                   set_init_index (array_index_loc, first, second,
4388                                   braced_init_obstack);
4389                   if (second)
4390                     pedwarn (ellipsis_loc, OPT_Wpedantic,
4391                              "ISO C forbids specifying range of elements to initialize");
4392                 }
4393               else
4394                 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4395                                            "expected %<]%>");
4396             }
4397         }
4398       if (des_seen >= 1)
4399         {
4400           if (c_parser_next_token_is (parser, CPP_EQ))
4401             {
4402               pedwarn_c90 (des_loc, OPT_Wpedantic,
4403                            "ISO C90 forbids specifying subobject "
4404                            "to initialize");
4405               c_parser_consume_token (parser);
4406             }
4407           else
4408             {
4409               if (des_seen == 1)
4410                 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4411                          "obsolete use of designated initializer without %<=%>");
4412               else
4413                 {
4414                   struct c_expr init;
4415                   init.value = error_mark_node;
4416                   init.original_code = ERROR_MARK;
4417                   init.original_type = NULL;
4418                   c_parser_error (parser, "expected %<=%>");
4419                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4420                   process_init_element (input_location, init, false,
4421                                         braced_init_obstack);
4422                   return;
4423                 }
4424             }
4425         }
4426     }
4427   c_parser_initval (parser, NULL, braced_init_obstack);
4428 }
4429
4430 /* Parse a nested initializer; as c_parser_initializer but parses
4431    initializers within braced lists, after any designators have been
4432    applied.  If AFTER is not NULL then it is an Objective-C message
4433    expression which is the primary-expression starting the
4434    initializer.  */
4435
4436 static void
4437 c_parser_initval (c_parser *parser, struct c_expr *after,
4438                   struct obstack * braced_init_obstack)
4439 {
4440   struct c_expr init;
4441   gcc_assert (!after || c_dialect_objc ());
4442   location_t loc = c_parser_peek_token (parser)->location;
4443
4444   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4445     init = c_parser_braced_init (parser, NULL_TREE, true);
4446   else
4447     {
4448       init = c_parser_expr_no_commas (parser, after);
4449       if (init.value != NULL_TREE
4450           && TREE_CODE (init.value) != STRING_CST
4451           && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4452         init = convert_lvalue_to_rvalue (loc, init, true, true);
4453     }
4454   process_init_element (loc, init, false, braced_init_obstack);
4455 }
4456
4457 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4458    C99 6.8.2).
4459
4460    compound-statement:
4461      { block-item-list[opt] }
4462      { label-declarations block-item-list }
4463
4464    block-item-list:
4465      block-item
4466      block-item-list block-item
4467
4468    block-item:
4469      nested-declaration
4470      statement
4471
4472    nested-declaration:
4473      declaration
4474
4475    GNU extensions:
4476
4477    compound-statement:
4478      { label-declarations block-item-list }
4479
4480    nested-declaration:
4481      __extension__ nested-declaration
4482      nested-function-definition
4483
4484    label-declarations:
4485      label-declaration
4486      label-declarations label-declaration
4487
4488    label-declaration:
4489      __label__ identifier-list ;
4490
4491    Allowing the mixing of declarations and code is new in C99.  The
4492    GNU syntax also permits (not shown above) labels at the end of
4493    compound statements, which yield an error.  We don't allow labels
4494    on declarations; this might seem like a natural extension, but
4495    there would be a conflict between attributes on the label and
4496    prefix attributes on the declaration.  ??? The syntax follows the
4497    old parser in requiring something after label declarations.
4498    Although they are erroneous if the labels declared aren't defined,
4499    is it useful for the syntax to be this way?
4500
4501    OpenACC:
4502
4503    block-item:
4504      openacc-directive
4505
4506    openacc-directive:
4507      update-directive
4508
4509    OpenMP:
4510
4511    block-item:
4512      openmp-directive
4513
4514    openmp-directive:
4515      barrier-directive
4516      flush-directive
4517      taskwait-directive
4518      taskyield-directive
4519      cancel-directive
4520      cancellation-point-directive  */
4521
4522 static tree
4523 c_parser_compound_statement (c_parser *parser)
4524 {
4525   tree stmt;
4526   location_t brace_loc;
4527   brace_loc = c_parser_peek_token (parser)->location;
4528   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4529     {
4530       /* Ensure a scope is entered and left anyway to avoid confusion
4531          if we have just prepared to enter a function body.  */
4532       stmt = c_begin_compound_stmt (true);
4533       c_end_compound_stmt (brace_loc, stmt, true);
4534       return error_mark_node;
4535     }
4536   stmt = c_begin_compound_stmt (true);
4537   c_parser_compound_statement_nostart (parser);
4538
4539   /* If the compound stmt contains array notations, then we expand them.  */
4540   if (flag_cilkplus && contains_array_notation_expr (stmt))
4541     stmt = expand_array_notation_exprs (stmt);
4542   return c_end_compound_stmt (brace_loc, stmt, true);
4543 }
4544
4545 /* Parse a compound statement except for the opening brace.  This is
4546    used for parsing both compound statements and statement expressions
4547    (which follow different paths to handling the opening).  */
4548
4549 static void
4550 c_parser_compound_statement_nostart (c_parser *parser)
4551 {
4552   bool last_stmt = false;
4553   bool last_label = false;
4554   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4555   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
4556   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4557     {
4558       c_parser_consume_token (parser);
4559       return;
4560     }
4561   mark_valid_location_for_stdc_pragma (true);
4562   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4563     {
4564       /* Read zero or more forward-declarations for labels that nested
4565          functions can jump to.  */
4566       mark_valid_location_for_stdc_pragma (false);
4567       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4568         {
4569           label_loc = c_parser_peek_token (parser)->location;
4570           c_parser_consume_token (parser);
4571           /* Any identifiers, including those declared as type names,
4572              are OK here.  */
4573           while (true)
4574             {
4575               tree label;
4576               if (c_parser_next_token_is_not (parser, CPP_NAME))
4577                 {
4578                   c_parser_error (parser, "expected identifier");
4579                   break;
4580                 }
4581               label
4582                 = declare_label (c_parser_peek_token (parser)->value);
4583               C_DECLARED_LABEL_FLAG (label) = 1;
4584               add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4585               c_parser_consume_token (parser);
4586               if (c_parser_next_token_is (parser, CPP_COMMA))
4587                 c_parser_consume_token (parser);
4588               else
4589                 break;
4590             }
4591           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4592         }
4593       pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4594     }
4595   /* We must now have at least one statement, label or declaration.  */
4596   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4597     {
4598       mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4599       c_parser_error (parser, "expected declaration or statement");
4600       c_parser_consume_token (parser);
4601       return;
4602     }
4603   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4604     {
4605       location_t loc = c_parser_peek_token (parser)->location;
4606       if (c_parser_next_token_is_keyword (parser, RID_CASE)
4607           || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4608           || (c_parser_next_token_is (parser, CPP_NAME)
4609               && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4610         {
4611           if (c_parser_next_token_is_keyword (parser, RID_CASE))
4612             label_loc = c_parser_peek_2nd_token (parser)->location;
4613           else
4614             label_loc = c_parser_peek_token (parser)->location;
4615           last_label = true;
4616           last_stmt = false;
4617           mark_valid_location_for_stdc_pragma (false);
4618           c_parser_label (parser);
4619         }
4620       else if (!last_label
4621                && c_parser_next_tokens_start_declaration (parser))
4622         {
4623           last_label = false;
4624           mark_valid_location_for_stdc_pragma (false);
4625           c_parser_declaration_or_fndef (parser, true, true, true, true,
4626                                          true, NULL, vNULL);
4627           if (last_stmt)
4628             pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4629                          "ISO C90 forbids mixed declarations and code");
4630           last_stmt = false;
4631         }
4632       else if (!last_label
4633                && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4634         {
4635           /* __extension__ can start a declaration, but is also an
4636              unary operator that can start an expression.  Consume all
4637              but the last of a possible series of __extension__ to
4638              determine which.  */
4639           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4640                  && (c_parser_peek_2nd_token (parser)->keyword
4641                      == RID_EXTENSION))
4642             c_parser_consume_token (parser);
4643           if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4644             {
4645               int ext;
4646               ext = disable_extension_diagnostics ();
4647               c_parser_consume_token (parser);
4648               last_label = false;
4649               mark_valid_location_for_stdc_pragma (false);
4650               c_parser_declaration_or_fndef (parser, true, true, true, true,
4651                                              true, NULL, vNULL);
4652               /* Following the old parser, __extension__ does not
4653                  disable this diagnostic.  */
4654               restore_extension_diagnostics (ext);
4655               if (last_stmt)
4656                 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4657                              "ISO C90 forbids mixed declarations and code");
4658               last_stmt = false;
4659             }
4660           else
4661             goto statement;
4662         }
4663       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4664         {
4665           /* External pragmas, and some omp pragmas, are not associated
4666              with regular c code, and so are not to be considered statements
4667              syntactically.  This ensures that the user doesn't put them
4668              places that would turn into syntax errors if the directive
4669              were ignored.  */
4670           if (c_parser_pragma (parser, pragma_compound))
4671             last_label = false, last_stmt = true;
4672         }
4673       else if (c_parser_next_token_is (parser, CPP_EOF))
4674         {
4675           mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4676           c_parser_error (parser, "expected declaration or statement");
4677           return;
4678         }
4679       else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4680         {
4681           if (parser->in_if_block)
4682             {
4683               mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4684               error_at (loc, """expected %<}%> before %<else%>");
4685               return;
4686             }
4687           else
4688             {
4689               error_at (loc, "%<else%> without a previous %<if%>");
4690               c_parser_consume_token (parser);
4691               continue;
4692             }
4693         }
4694       else
4695         {
4696         statement:
4697           last_label = false;
4698           last_stmt = true;
4699           mark_valid_location_for_stdc_pragma (false);
4700           c_parser_statement_after_labels (parser);
4701         }
4702
4703       parser->error = false;
4704     }
4705   if (last_label)
4706     error_at (label_loc, "label at end of compound statement");
4707   c_parser_consume_token (parser);
4708   /* Restore the value we started with.  */
4709   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4710 }
4711
4712 /* Parse all consecutive labels. */
4713
4714 static void
4715 c_parser_all_labels (c_parser *parser)
4716 {
4717   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4718          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4719          || (c_parser_next_token_is (parser, CPP_NAME)
4720              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4721     c_parser_label (parser);
4722 }
4723
4724 /* Parse a label (C90 6.6.1, C99 6.8.1).
4725
4726    label:
4727      identifier : attributes[opt]
4728      case constant-expression :
4729      default :
4730
4731    GNU extensions:
4732
4733    label:
4734      case constant-expression ... constant-expression :
4735
4736    The use of attributes on labels is a GNU extension.  The syntax in
4737    GNU C accepts any expressions without commas, non-constant
4738    expressions being rejected later.  */
4739
4740 static void
4741 c_parser_label (c_parser *parser)
4742 {
4743   location_t loc1 = c_parser_peek_token (parser)->location;
4744   tree label = NULL_TREE;
4745   if (c_parser_next_token_is_keyword (parser, RID_CASE))
4746     {
4747       tree exp1, exp2;
4748       c_parser_consume_token (parser);
4749       exp1 = c_parser_expr_no_commas (parser, NULL).value;
4750       if (c_parser_next_token_is (parser, CPP_COLON))
4751         {
4752           c_parser_consume_token (parser);
4753           label = do_case (loc1, exp1, NULL_TREE);
4754         }
4755       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4756         {
4757           c_parser_consume_token (parser);
4758           exp2 = c_parser_expr_no_commas (parser, NULL).value;
4759           if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4760             label = do_case (loc1, exp1, exp2);
4761         }
4762       else
4763         c_parser_error (parser, "expected %<:%> or %<...%>");
4764     }
4765   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4766     {
4767       c_parser_consume_token (parser);
4768       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4769         label = do_case (loc1, NULL_TREE, NULL_TREE);
4770     }
4771   else
4772     {
4773       tree name = c_parser_peek_token (parser)->value;
4774       tree tlab;
4775       tree attrs;
4776       location_t loc2 = c_parser_peek_token (parser)->location;
4777       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4778       c_parser_consume_token (parser);
4779       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4780       c_parser_consume_token (parser);
4781       attrs = c_parser_attributes (parser);
4782       tlab = define_label (loc2, name);
4783       if (tlab)
4784         {
4785           decl_attributes (&tlab, attrs, 0);
4786           label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4787         }
4788     }
4789   if (label)
4790     {
4791       if (c_parser_next_tokens_start_declaration (parser))
4792         {
4793           error_at (c_parser_peek_token (parser)->location,
4794                     "a label can only be part of a statement and "
4795                     "a declaration is not a statement");
4796           c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4797                                          /*static_assert_ok*/ true,
4798                                          /*empty_ok*/ true, /*nested*/ true,
4799                                          /*start_attr_ok*/ true, NULL,
4800                                          vNULL);
4801         }
4802     }
4803 }
4804
4805 /* Parse a statement (C90 6.6, C99 6.8).
4806
4807    statement:
4808      labeled-statement
4809      compound-statement
4810      expression-statement
4811      selection-statement
4812      iteration-statement
4813      jump-statement
4814
4815    labeled-statement:
4816      label statement
4817
4818    expression-statement:
4819      expression[opt] ;
4820
4821    selection-statement:
4822      if-statement
4823      switch-statement
4824
4825    iteration-statement:
4826      while-statement
4827      do-statement
4828      for-statement
4829
4830    jump-statement:
4831      goto identifier ;
4832      continue ;
4833      break ;
4834      return expression[opt] ;
4835
4836    GNU extensions:
4837
4838    statement:
4839      asm-statement
4840
4841    jump-statement:
4842      goto * expression ;
4843
4844    Objective-C:
4845
4846    statement:
4847      objc-throw-statement
4848      objc-try-catch-statement
4849      objc-synchronized-statement
4850
4851    objc-throw-statement:
4852      @throw expression ;
4853      @throw ;
4854
4855    OpenACC:
4856
4857    statement:
4858      openacc-construct
4859
4860    openacc-construct:
4861      parallel-construct
4862      kernels-construct
4863      data-construct
4864      loop-construct
4865
4866    parallel-construct:
4867      parallel-directive structured-block
4868
4869    kernels-construct:
4870      kernels-directive structured-block
4871
4872    data-construct:
4873      data-directive structured-block
4874
4875    loop-construct:
4876      loop-directive structured-block
4877
4878    OpenMP:
4879
4880    statement:
4881      openmp-construct
4882
4883    openmp-construct:
4884      parallel-construct
4885      for-construct
4886      simd-construct
4887      for-simd-construct
4888      sections-construct
4889      single-construct
4890      parallel-for-construct
4891      parallel-for-simd-construct
4892      parallel-sections-construct
4893      master-construct
4894      critical-construct
4895      atomic-construct
4896      ordered-construct
4897
4898    parallel-construct:
4899      parallel-directive structured-block
4900
4901    for-construct:
4902      for-directive iteration-statement
4903
4904    simd-construct:
4905      simd-directive iteration-statements
4906
4907    for-simd-construct:
4908      for-simd-directive iteration-statements
4909
4910    sections-construct:
4911      sections-directive section-scope
4912
4913    single-construct:
4914      single-directive structured-block
4915
4916    parallel-for-construct:
4917      parallel-for-directive iteration-statement
4918
4919    parallel-for-simd-construct:
4920      parallel-for-simd-directive iteration-statement
4921
4922    parallel-sections-construct:
4923      parallel-sections-directive section-scope
4924
4925    master-construct:
4926      master-directive structured-block
4927
4928    critical-construct:
4929      critical-directive structured-block
4930
4931    atomic-construct:
4932      atomic-directive expression-statement
4933
4934    ordered-construct:
4935      ordered-directive structured-block
4936
4937    Transactional Memory:
4938
4939    statement:
4940      transaction-statement
4941      transaction-cancel-statement
4942 */
4943
4944 static void
4945 c_parser_statement (c_parser *parser)
4946 {
4947   c_parser_all_labels (parser);
4948   c_parser_statement_after_labels (parser);
4949 }
4950
4951 /* Parse a statement, other than a labeled statement.  */
4952
4953 static void
4954 c_parser_statement_after_labels (c_parser *parser)
4955 {
4956   location_t loc = c_parser_peek_token (parser)->location;
4957   tree stmt = NULL_TREE;
4958   bool in_if_block = parser->in_if_block;
4959   parser->in_if_block = false;
4960   switch (c_parser_peek_token (parser)->type)
4961     {
4962     case CPP_OPEN_BRACE:
4963       add_stmt (c_parser_compound_statement (parser));
4964       break;
4965     case CPP_KEYWORD:
4966       switch (c_parser_peek_token (parser)->keyword)
4967         {
4968         case RID_IF:
4969           c_parser_if_statement (parser);
4970           break;
4971         case RID_SWITCH:
4972           c_parser_switch_statement (parser);
4973           break;
4974         case RID_WHILE:
4975           c_parser_while_statement (parser, false);
4976           break;
4977         case RID_DO:
4978           c_parser_do_statement (parser, false);
4979           break;
4980         case RID_FOR:
4981           c_parser_for_statement (parser, false);
4982           break;
4983         case RID_CILK_FOR:
4984           if (!flag_cilkplus)
4985             {
4986               error_at (c_parser_peek_token (parser)->location,
4987                         "-fcilkplus must be enabled to use %<_Cilk_for%>");
4988               c_parser_skip_to_end_of_block_or_statement (parser);
4989             }
4990           else
4991             c_parser_cilk_for (parser, integer_zero_node);
4992           break;
4993         case RID_CILK_SYNC:
4994           c_parser_consume_token (parser);
4995           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4996           if (!flag_cilkplus) 
4997             error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4998           else 
4999             add_stmt (build_cilk_sync ());
5000           break;
5001         case RID_GOTO:
5002           c_parser_consume_token (parser);
5003           if (c_parser_next_token_is (parser, CPP_NAME))
5004             {
5005               stmt = c_finish_goto_label (loc,
5006                                           c_parser_peek_token (parser)->value);
5007               c_parser_consume_token (parser);
5008             }
5009           else if (c_parser_next_token_is (parser, CPP_MULT))
5010             {
5011               struct c_expr val;
5012
5013               c_parser_consume_token (parser);
5014               val = c_parser_expression (parser);
5015               if (check_no_cilk (val.value,
5016                                  "Cilk array notation cannot be used as a computed goto expression",
5017                                  "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5018                                  loc))
5019                 val.value = error_mark_node;
5020               val = convert_lvalue_to_rvalue (loc, val, false, true);
5021               stmt = c_finish_goto_ptr (loc, val.value);
5022             }
5023           else
5024             c_parser_error (parser, "expected identifier or %<*%>");
5025           goto expect_semicolon;
5026         case RID_CONTINUE:
5027           c_parser_consume_token (parser);
5028           stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5029           goto expect_semicolon;
5030         case RID_BREAK:
5031           c_parser_consume_token (parser);
5032           stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5033           goto expect_semicolon;
5034         case RID_RETURN:
5035           c_parser_consume_token (parser);
5036           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5037             {
5038               stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5039               c_parser_consume_token (parser);
5040             }
5041           else
5042             {
5043               location_t xloc = c_parser_peek_token (parser)->location;
5044               struct c_expr expr = c_parser_expression_conv (parser);
5045               mark_exp_read (expr.value);
5046               stmt = c_finish_return (xloc, expr.value, expr.original_type);
5047               goto expect_semicolon;
5048             }
5049           break;
5050         case RID_ASM:
5051           stmt = c_parser_asm_statement (parser);
5052           break;
5053         case RID_TRANSACTION_ATOMIC:
5054         case RID_TRANSACTION_RELAXED:
5055           stmt = c_parser_transaction (parser,
5056               c_parser_peek_token (parser)->keyword);
5057           break;
5058         case RID_TRANSACTION_CANCEL:
5059           stmt = c_parser_transaction_cancel (parser);
5060           goto expect_semicolon;
5061         case RID_AT_THROW:
5062           gcc_assert (c_dialect_objc ());
5063           c_parser_consume_token (parser);
5064           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5065             {
5066               stmt = objc_build_throw_stmt (loc, NULL_TREE);
5067               c_parser_consume_token (parser);
5068             }
5069           else
5070             {
5071               struct c_expr expr = c_parser_expression (parser);
5072               expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5073               if (check_no_cilk (expr.value,
5074                  "Cilk array notation cannot be used for a throw expression",
5075                  "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5076                 expr.value = error_mark_node;
5077               else
5078                 {
5079                   expr.value = c_fully_fold (expr.value, false, NULL);
5080                   stmt = objc_build_throw_stmt (loc, expr.value);
5081                 }
5082               goto expect_semicolon;
5083             }
5084           break;
5085         case RID_AT_TRY:
5086           gcc_assert (c_dialect_objc ());
5087           c_parser_objc_try_catch_finally_statement (parser);
5088           break;
5089         case RID_AT_SYNCHRONIZED:
5090           gcc_assert (c_dialect_objc ());
5091           c_parser_objc_synchronized_statement (parser);
5092           break;
5093         default:
5094           goto expr_stmt;
5095         }
5096       break;
5097     case CPP_SEMICOLON:
5098       c_parser_consume_token (parser);
5099       break;
5100     case CPP_CLOSE_PAREN:
5101     case CPP_CLOSE_SQUARE:
5102       /* Avoid infinite loop in error recovery:
5103          c_parser_skip_until_found stops at a closing nesting
5104          delimiter without consuming it, but here we need to consume
5105          it to proceed further.  */
5106       c_parser_error (parser, "expected statement");
5107       c_parser_consume_token (parser);
5108       break;
5109     case CPP_PRAGMA:
5110       c_parser_pragma (parser, pragma_stmt);
5111       break;
5112     default:
5113     expr_stmt:
5114       stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5115     expect_semicolon:
5116       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5117       break;
5118     }
5119   /* Two cases cannot and do not have line numbers associated: If stmt
5120      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5121      cannot hold line numbers.  But that's OK because the statement
5122      will either be changed to a MODIFY_EXPR during gimplification of
5123      the statement expr, or discarded.  If stmt was compound, but
5124      without new variables, we will have skipped the creation of a
5125      BIND and will have a bare STATEMENT_LIST.  But that's OK because
5126      (recursively) all of the component statements should already have
5127      line numbers assigned.  ??? Can we discard no-op statements
5128      earlier?  */
5129   if (CAN_HAVE_LOCATION_P (stmt)
5130       && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5131     SET_EXPR_LOCATION (stmt, loc);
5132
5133   parser->in_if_block = in_if_block;
5134 }
5135
5136 /* Parse the condition from an if, do, while or for statements.  */
5137
5138 static tree
5139 c_parser_condition (c_parser *parser)
5140 {
5141   location_t loc = c_parser_peek_token (parser)->location;
5142   tree cond;
5143   cond = c_parser_expression_conv (parser).value;
5144   cond = c_objc_common_truthvalue_conversion (loc, cond);
5145   cond = c_fully_fold (cond, false, NULL);
5146   if (warn_sequence_point)
5147     verify_sequence_points (cond);
5148   return cond;
5149 }
5150
5151 /* Parse a parenthesized condition from an if, do or while statement.
5152
5153    condition:
5154      ( expression )
5155 */
5156 static tree
5157 c_parser_paren_condition (c_parser *parser)
5158 {
5159   tree cond;
5160   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5161     return error_mark_node;
5162   cond = c_parser_condition (parser);
5163   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5164   return cond;
5165 }
5166
5167 /* Parse a statement which is a block in C99.  */
5168
5169 static tree
5170 c_parser_c99_block_statement (c_parser *parser)
5171 {
5172   tree block = c_begin_compound_stmt (flag_isoc99);
5173   location_t loc = c_parser_peek_token (parser)->location;
5174   c_parser_statement (parser);
5175   return c_end_compound_stmt (loc, block, flag_isoc99);
5176 }
5177
5178 /* Parse the body of an if statement.  This is just parsing a
5179    statement but (a) it is a block in C99, (b) we track whether the
5180    body is an if statement for the sake of -Wparentheses warnings, (c)
5181    we handle an empty body specially for the sake of -Wempty-body
5182    warnings, and (d) we call parser_compound_statement directly
5183    because c_parser_statement_after_labels resets
5184    parser->in_if_block.  */
5185
5186 static tree
5187 c_parser_if_body (c_parser *parser, bool *if_p)
5188 {
5189   tree block = c_begin_compound_stmt (flag_isoc99);
5190   location_t body_loc = c_parser_peek_token (parser)->location;
5191   c_parser_all_labels (parser);
5192   *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
5193   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5194     {
5195       location_t loc = c_parser_peek_token (parser)->location;
5196       add_stmt (build_empty_stmt (loc));
5197       c_parser_consume_token (parser);
5198       if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5199         warning_at (loc, OPT_Wempty_body,
5200                     "suggest braces around empty body in an %<if%> statement");
5201     }
5202   else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5203     add_stmt (c_parser_compound_statement (parser));
5204   else
5205     c_parser_statement_after_labels (parser);
5206   return c_end_compound_stmt (body_loc, block, flag_isoc99);
5207 }
5208
5209 /* Parse the else body of an if statement.  This is just parsing a
5210    statement but (a) it is a block in C99, (b) we handle an empty body
5211    specially for the sake of -Wempty-body warnings.  */
5212
5213 static tree
5214 c_parser_else_body (c_parser *parser)
5215 {
5216   location_t else_loc = c_parser_peek_token (parser)->location;
5217   tree block = c_begin_compound_stmt (flag_isoc99);
5218   c_parser_all_labels (parser);
5219   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5220     {
5221       location_t loc = c_parser_peek_token (parser)->location;
5222       warning_at (loc,
5223                   OPT_Wempty_body,
5224                  "suggest braces around empty body in an %<else%> statement");
5225       add_stmt (build_empty_stmt (loc));
5226       c_parser_consume_token (parser);
5227     }
5228   else
5229     c_parser_statement_after_labels (parser);
5230   return c_end_compound_stmt (else_loc, block, flag_isoc99);
5231 }
5232
5233 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5234
5235    if-statement:
5236      if ( expression ) statement
5237      if ( expression ) statement else statement
5238 */
5239
5240 static void
5241 c_parser_if_statement (c_parser *parser)
5242 {
5243   tree block;
5244   location_t loc;
5245   tree cond;
5246   bool first_if = false;
5247   tree first_body, second_body;
5248   bool in_if_block;
5249   tree if_stmt;
5250
5251   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5252   c_parser_consume_token (parser);
5253   block = c_begin_compound_stmt (flag_isoc99);
5254   loc = c_parser_peek_token (parser)->location;
5255   cond = c_parser_paren_condition (parser);
5256   if (flag_cilkplus && contains_cilk_spawn_stmt (cond))
5257     {
5258       error_at (loc, "if statement cannot contain %<Cilk_spawn%>");
5259       cond = error_mark_node;
5260     }
5261   in_if_block = parser->in_if_block;
5262   parser->in_if_block = true;
5263   first_body = c_parser_if_body (parser, &first_if);
5264   parser->in_if_block = in_if_block;
5265   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5266     {
5267       c_parser_consume_token (parser);
5268       second_body = c_parser_else_body (parser);
5269     }
5270   else
5271     second_body = NULL_TREE;
5272   c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
5273   if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
5274
5275   /* If the if statement contains array notations, then we expand them.  */
5276   if (flag_cilkplus && contains_array_notation_expr (if_stmt))
5277     if_stmt = fix_conditional_array_notations (if_stmt);
5278   add_stmt (if_stmt);
5279 }
5280
5281 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5282
5283    switch-statement:
5284      switch (expression) statement
5285 */
5286
5287 static void
5288 c_parser_switch_statement (c_parser *parser)
5289 {
5290   struct c_expr ce;
5291   tree block, expr, body, save_break;
5292   location_t switch_loc = c_parser_peek_token (parser)->location;
5293   location_t switch_cond_loc;
5294   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5295   c_parser_consume_token (parser);
5296   block = c_begin_compound_stmt (flag_isoc99);
5297   bool explicit_cast_p = false;
5298   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5299     {
5300       switch_cond_loc = c_parser_peek_token (parser)->location;
5301       if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5302           && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5303         explicit_cast_p = true;
5304       ce = c_parser_expression (parser);
5305       ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5306       expr = ce.value;
5307       /* ??? expr has no valid location?  */
5308       if (check_no_cilk (expr,
5309          "Cilk array notation cannot be used as a condition for switch statement",
5310          "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5311                          switch_cond_loc))
5312         expr = error_mark_node;
5313       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5314     }
5315   else
5316     {
5317       switch_cond_loc = UNKNOWN_LOCATION;
5318       expr = error_mark_node;
5319     }
5320   c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5321   save_break = c_break_label;
5322   c_break_label = NULL_TREE;
5323   body = c_parser_c99_block_statement (parser);
5324   c_finish_case (body, ce.original_type);
5325   if (c_break_label)
5326     {
5327       location_t here = c_parser_peek_token (parser)->location;
5328       tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5329       SET_EXPR_LOCATION (t, here);
5330       add_stmt (t);
5331     }
5332   c_break_label = save_break;
5333   add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5334 }
5335
5336 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5337
5338    while-statement:
5339       while (expression) statement
5340 */
5341
5342 static void
5343 c_parser_while_statement (c_parser *parser, bool ivdep)
5344 {
5345   tree block, cond, body, save_break, save_cont;
5346   location_t loc;
5347   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5348   c_parser_consume_token (parser);
5349   block = c_begin_compound_stmt (flag_isoc99);
5350   loc = c_parser_peek_token (parser)->location;
5351   cond = c_parser_paren_condition (parser);
5352   if (check_no_cilk (cond,
5353          "Cilk array notation cannot be used as a condition for while statement",
5354          "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5355     cond = error_mark_node;
5356   if (ivdep && cond != error_mark_node)
5357     cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5358                    build_int_cst (integer_type_node,
5359                    annot_expr_ivdep_kind));
5360   save_break = c_break_label;
5361   c_break_label = NULL_TREE;
5362   save_cont = c_cont_label;
5363   c_cont_label = NULL_TREE;
5364   body = c_parser_c99_block_statement (parser);
5365   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5366   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5367   c_break_label = save_break;
5368   c_cont_label = save_cont;
5369 }
5370
5371 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5372
5373    do-statement:
5374      do statement while ( expression ) ;
5375 */
5376
5377 static void
5378 c_parser_do_statement (c_parser *parser, bool ivdep)
5379 {
5380   tree block, cond, body, save_break, save_cont, new_break, new_cont;
5381   location_t loc;
5382   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5383   c_parser_consume_token (parser);
5384   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5385     warning_at (c_parser_peek_token (parser)->location,
5386                 OPT_Wempty_body,
5387                 "suggest braces around empty body in %<do%> statement");
5388   block = c_begin_compound_stmt (flag_isoc99);
5389   loc = c_parser_peek_token (parser)->location;
5390   save_break = c_break_label;
5391   c_break_label = NULL_TREE;
5392   save_cont = c_cont_label;
5393   c_cont_label = NULL_TREE;
5394   body = c_parser_c99_block_statement (parser);
5395   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5396   new_break = c_break_label;
5397   c_break_label = save_break;
5398   new_cont = c_cont_label;
5399   c_cont_label = save_cont;
5400   cond = c_parser_paren_condition (parser);
5401   if (check_no_cilk (cond,
5402          "Cilk array notation cannot be used as a condition for a do-while statement",
5403          "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5404     cond = error_mark_node;
5405   if (ivdep && cond != error_mark_node)
5406     cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5407                    build_int_cst (integer_type_node,
5408                    annot_expr_ivdep_kind));
5409   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5410     c_parser_skip_to_end_of_block_or_statement (parser);
5411   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5412   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5413 }
5414
5415 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5416
5417    for-statement:
5418      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5419      for ( nested-declaration expression[opt] ; expression[opt] ) statement
5420
5421    The form with a declaration is new in C99.
5422
5423    ??? In accordance with the old parser, the declaration may be a
5424    nested function, which is then rejected in check_for_loop_decls,
5425    but does it make any sense for this to be included in the grammar?
5426    Note in particular that the nested function does not include a
5427    trailing ';', whereas the "declaration" production includes one.
5428    Also, can we reject bad declarations earlier and cheaper than
5429    check_for_loop_decls?
5430
5431    In Objective-C, there are two additional variants:
5432
5433    foreach-statement:
5434      for ( expression in expresssion ) statement
5435      for ( declaration in expression ) statement
5436
5437    This is inconsistent with C, because the second variant is allowed
5438    even if c99 is not enabled.
5439
5440    The rest of the comment documents these Objective-C foreach-statement.
5441
5442    Here is the canonical example of the first variant:
5443     for (object in array)    { do something with object }
5444    we call the first expression ("object") the "object_expression" and 
5445    the second expression ("array") the "collection_expression".
5446    object_expression must be an lvalue of type "id" (a generic Objective-C
5447    object) because the loop works by assigning to object_expression the
5448    various objects from the collection_expression.  collection_expression
5449    must evaluate to something of type "id" which responds to the method
5450    countByEnumeratingWithState:objects:count:.
5451
5452    The canonical example of the second variant is:
5453     for (id object in array)    { do something with object }
5454    which is completely equivalent to
5455     {
5456       id object;
5457       for (object in array) { do something with object }
5458     }
5459    Note that initizializing 'object' in some way (eg, "for ((object =
5460    xxx) in array) { do something with object }") is possibly
5461    technically valid, but completely pointless as 'object' will be
5462    assigned to something else as soon as the loop starts.  We should
5463    most likely reject it (TODO).
5464
5465    The beginning of the Objective-C foreach-statement looks exactly
5466    like the beginning of the for-statement, and we can tell it is a
5467    foreach-statement only because the initial declaration or
5468    expression is terminated by 'in' instead of ';'.
5469 */
5470
5471 static void
5472 c_parser_for_statement (c_parser *parser, bool ivdep)
5473 {
5474   tree block, cond, incr, save_break, save_cont, body;
5475   /* The following are only used when parsing an ObjC foreach statement.  */
5476   tree object_expression;
5477   /* Silence the bogus uninitialized warning.  */
5478   tree collection_expression = NULL;
5479   location_t loc = c_parser_peek_token (parser)->location;
5480   location_t for_loc = c_parser_peek_token (parser)->location;
5481   bool is_foreach_statement = false;
5482   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
5483   c_parser_consume_token (parser);
5484   /* Open a compound statement in Objective-C as well, just in case this is
5485      as foreach expression.  */
5486   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
5487   cond = error_mark_node;
5488   incr = error_mark_node;
5489   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5490     {
5491       /* Parse the initialization declaration or expression.  */
5492       object_expression = error_mark_node;
5493       parser->objc_could_be_foreach_context = c_dialect_objc ();
5494       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5495         {
5496           parser->objc_could_be_foreach_context = false;
5497           c_parser_consume_token (parser);
5498           c_finish_expr_stmt (loc, NULL_TREE);
5499         }
5500       else if (c_parser_next_tokens_start_declaration (parser))
5501         {
5502           c_parser_declaration_or_fndef (parser, true, true, true, true, true, 
5503                                          &object_expression, vNULL);
5504           parser->objc_could_be_foreach_context = false;
5505           
5506           if (c_parser_next_token_is_keyword (parser, RID_IN))
5507             {
5508               c_parser_consume_token (parser);
5509               is_foreach_statement = true;
5510               if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5511                 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5512             }
5513           else
5514             check_for_loop_decls (for_loc, flag_isoc99);
5515         }
5516       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5517         {
5518           /* __extension__ can start a declaration, but is also an
5519              unary operator that can start an expression.  Consume all
5520              but the last of a possible series of __extension__ to
5521              determine which.  */
5522           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5523                  && (c_parser_peek_2nd_token (parser)->keyword
5524                      == RID_EXTENSION))
5525             c_parser_consume_token (parser);
5526           if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5527             {
5528               int ext;
5529               ext = disable_extension_diagnostics ();
5530               c_parser_consume_token (parser);
5531               c_parser_declaration_or_fndef (parser, true, true, true, true,
5532                                              true, &object_expression, vNULL);
5533               parser->objc_could_be_foreach_context = false;
5534               
5535               restore_extension_diagnostics (ext);
5536               if (c_parser_next_token_is_keyword (parser, RID_IN))
5537                 {
5538                   c_parser_consume_token (parser);
5539                   is_foreach_statement = true;
5540                   if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5541                     c_parser_error (parser, "multiple iterating variables in fast enumeration");
5542                 }
5543               else
5544                 check_for_loop_decls (for_loc, flag_isoc99);
5545             }
5546           else
5547             goto init_expr;
5548         }
5549       else
5550         {
5551         init_expr:
5552           {
5553             struct c_expr ce;
5554             tree init_expression;
5555             ce = c_parser_expression (parser);
5556             /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5557                level statement", but it works just fine, so allow it.  */
5558             init_expression = ce.value;
5559             parser->objc_could_be_foreach_context = false;
5560             if (c_parser_next_token_is_keyword (parser, RID_IN))
5561               {
5562                 c_parser_consume_token (parser);
5563                 is_foreach_statement = true;
5564                 if (! lvalue_p (init_expression))
5565                   c_parser_error (parser, "invalid iterating variable in fast enumeration");
5566                 object_expression = c_fully_fold (init_expression, false, NULL);
5567               }
5568             else
5569               {
5570                 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5571                 init_expression = ce.value;
5572                 c_finish_expr_stmt (loc, init_expression);
5573                 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5574               }
5575           }
5576         }
5577       /* Parse the loop condition.  In the case of a foreach
5578          statement, there is no loop condition.  */
5579       gcc_assert (!parser->objc_could_be_foreach_context);
5580       if (!is_foreach_statement)
5581         {
5582           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5583             {
5584               if (ivdep)
5585                 {
5586                   c_parser_error (parser, "missing loop condition in loop with "
5587                                   "%<GCC ivdep%> pragma");
5588                   cond = error_mark_node;
5589                 }
5590               else
5591                 {
5592                   c_parser_consume_token (parser);
5593                   cond = NULL_TREE;
5594                 }
5595             }
5596           else
5597             {
5598               cond = c_parser_condition (parser);
5599               if (check_no_cilk (cond,
5600                  "Cilk array notation cannot be used in a condition for a for-loop",
5601                  "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5602                 cond = error_mark_node;
5603               c_parser_skip_until_found (parser, CPP_SEMICOLON,
5604                                          "expected %<;%>");
5605             }
5606           if (ivdep && cond != error_mark_node)
5607             cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5608                            build_int_cst (integer_type_node,
5609                            annot_expr_ivdep_kind));
5610         }
5611       /* Parse the increment expression (the third expression in a
5612          for-statement).  In the case of a foreach-statement, this is
5613          the expression that follows the 'in'.  */
5614       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5615         {
5616           if (is_foreach_statement)
5617             {
5618               c_parser_error (parser, "missing collection in fast enumeration");
5619               collection_expression = error_mark_node;
5620             }
5621           else
5622             incr = c_process_expr_stmt (loc, NULL_TREE);
5623         }
5624       else
5625         {
5626           if (is_foreach_statement)
5627             collection_expression = c_fully_fold (c_parser_expression (parser).value,
5628                                                   false, NULL);
5629           else
5630             {
5631               struct c_expr ce = c_parser_expression (parser);
5632               ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5633               incr = c_process_expr_stmt (loc, ce.value);
5634             }
5635         }
5636       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5637     }
5638   save_break = c_break_label;
5639   c_break_label = NULL_TREE;
5640   save_cont = c_cont_label;
5641   c_cont_label = NULL_TREE;
5642   body = c_parser_c99_block_statement (parser);
5643   if (is_foreach_statement)
5644     objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5645   else
5646     c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5647   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5648   c_break_label = save_break;
5649   c_cont_label = save_cont;
5650 }
5651
5652 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
5653    statement with inputs, outputs, clobbers, and volatile tag
5654    allowed.
5655
5656    asm-statement:
5657      asm type-qualifier[opt] ( asm-argument ) ;
5658      asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5659
5660    asm-argument:
5661      asm-string-literal
5662      asm-string-literal : asm-operands[opt]
5663      asm-string-literal : asm-operands[opt] : asm-operands[opt]
5664      asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5665
5666    asm-goto-argument:
5667      asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5668        : asm-goto-operands
5669
5670    Qualifiers other than volatile are accepted in the syntax but
5671    warned for.  */
5672
5673 static tree
5674 c_parser_asm_statement (c_parser *parser)
5675 {
5676   tree quals, str, outputs, inputs, clobbers, labels, ret;
5677   bool simple, is_goto;
5678   location_t asm_loc = c_parser_peek_token (parser)->location;
5679   int section, nsections;
5680
5681   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5682   c_parser_consume_token (parser);
5683   if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5684     {
5685       quals = c_parser_peek_token (parser)->value;
5686       c_parser_consume_token (parser);
5687     }
5688   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5689            || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5690     {
5691       warning_at (c_parser_peek_token (parser)->location,
5692                   0,
5693                   "%E qualifier ignored on asm",
5694                   c_parser_peek_token (parser)->value);
5695       quals = NULL_TREE;
5696       c_parser_consume_token (parser);
5697     }
5698   else
5699     quals = NULL_TREE;
5700
5701   is_goto = false;
5702   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5703     {
5704       c_parser_consume_token (parser);
5705       is_goto = true;
5706     }
5707
5708   /* ??? Follow the C++ parser rather than using the
5709      lex_untranslated_string kludge.  */
5710   parser->lex_untranslated_string = true;
5711   ret = NULL;
5712
5713   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5714     goto error;
5715
5716   str = c_parser_asm_string_literal (parser);
5717   if (str == NULL_TREE)
5718     goto error_close_paren;
5719
5720   simple = true;
5721   outputs = NULL_TREE;
5722   inputs = NULL_TREE;
5723   clobbers = NULL_TREE;
5724   labels = NULL_TREE;
5725
5726   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5727     goto done_asm;
5728
5729   /* Parse each colon-delimited section of operands.  */
5730   nsections = 3 + is_goto;
5731   for (section = 0; section < nsections; ++section)
5732     {
5733       if (!c_parser_require (parser, CPP_COLON,
5734                              is_goto
5735                              ? "expected %<:%>"
5736                              : "expected %<:%> or %<)%>"))
5737         goto error_close_paren;
5738
5739       /* Once past any colon, we're no longer a simple asm.  */
5740       simple = false;
5741
5742       if ((!c_parser_next_token_is (parser, CPP_COLON)
5743            && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5744           || section == 3)
5745         switch (section)
5746           {
5747           case 0:
5748             /* For asm goto, we don't allow output operands, but reserve
5749                the slot for a future extension that does allow them.  */
5750             if (!is_goto)
5751               outputs = c_parser_asm_operands (parser);
5752             break;
5753           case 1:
5754             inputs = c_parser_asm_operands (parser);
5755             break;
5756           case 2:
5757             clobbers = c_parser_asm_clobbers (parser);
5758             break;
5759           case 3:
5760             labels = c_parser_asm_goto_operands (parser);
5761             break;
5762           default:
5763             gcc_unreachable ();
5764           }
5765
5766       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5767         goto done_asm;
5768     }
5769
5770  done_asm:
5771   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5772     {
5773       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5774       goto error;
5775     }
5776
5777   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5778     c_parser_skip_to_end_of_block_or_statement (parser);
5779
5780   ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5781                                                clobbers, labels, simple));
5782
5783  error:
5784   parser->lex_untranslated_string = false;
5785   return ret;
5786
5787  error_close_paren:
5788   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5789   goto error;
5790 }
5791
5792 /* Parse asm operands, a GNU extension.
5793
5794    asm-operands:
5795      asm-operand
5796      asm-operands , asm-operand
5797
5798    asm-operand:
5799      asm-string-literal ( expression )
5800      [ identifier ] asm-string-literal ( expression )
5801 */
5802
5803 static tree
5804 c_parser_asm_operands (c_parser *parser)
5805 {
5806   tree list = NULL_TREE;
5807   while (true)
5808     {
5809       tree name, str;
5810       struct c_expr expr;
5811       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5812         {
5813           c_parser_consume_token (parser);
5814           if (c_parser_next_token_is (parser, CPP_NAME))
5815             {
5816               tree id = c_parser_peek_token (parser)->value;
5817               c_parser_consume_token (parser);
5818               name = build_string (IDENTIFIER_LENGTH (id),
5819                                    IDENTIFIER_POINTER (id));
5820             }
5821           else
5822             {
5823               c_parser_error (parser, "expected identifier");
5824               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5825               return NULL_TREE;
5826             }
5827           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5828                                      "expected %<]%>");
5829         }
5830       else
5831         name = NULL_TREE;
5832       str = c_parser_asm_string_literal (parser);
5833       if (str == NULL_TREE)
5834         return NULL_TREE;
5835       parser->lex_untranslated_string = false;
5836       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5837         {
5838           parser->lex_untranslated_string = true;
5839           return NULL_TREE;
5840         }
5841       expr = c_parser_expression (parser);
5842       mark_exp_read (expr.value);
5843       parser->lex_untranslated_string = true;
5844       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5845         {
5846           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5847           return NULL_TREE;
5848         }
5849       list = chainon (list, build_tree_list (build_tree_list (name, str),
5850                                              expr.value));
5851       if (c_parser_next_token_is (parser, CPP_COMMA))
5852         c_parser_consume_token (parser);
5853       else
5854         break;
5855     }
5856   return list;
5857 }
5858
5859 /* Parse asm clobbers, a GNU extension.
5860
5861    asm-clobbers:
5862      asm-string-literal
5863      asm-clobbers , asm-string-literal
5864 */
5865
5866 static tree
5867 c_parser_asm_clobbers (c_parser *parser)
5868 {
5869   tree list = NULL_TREE;
5870   while (true)
5871     {
5872       tree str = c_parser_asm_string_literal (parser);
5873       if (str)
5874         list = tree_cons (NULL_TREE, str, list);
5875       else
5876         return NULL_TREE;
5877       if (c_parser_next_token_is (parser, CPP_COMMA))
5878         c_parser_consume_token (parser);
5879       else
5880         break;
5881     }
5882   return list;
5883 }
5884
5885 /* Parse asm goto labels, a GNU extension.
5886
5887    asm-goto-operands:
5888      identifier
5889      asm-goto-operands , identifier
5890 */
5891
5892 static tree
5893 c_parser_asm_goto_operands (c_parser *parser)
5894 {
5895   tree list = NULL_TREE;
5896   while (true)
5897     {
5898       tree name, label;
5899
5900       if (c_parser_next_token_is (parser, CPP_NAME))
5901         {
5902           c_token *tok = c_parser_peek_token (parser);
5903           name = tok->value;
5904           label = lookup_label_for_goto (tok->location, name);
5905           c_parser_consume_token (parser);
5906           TREE_USED (label) = 1;
5907         }
5908       else
5909         {
5910           c_parser_error (parser, "expected identifier");
5911           return NULL_TREE;
5912         }
5913
5914       name = build_string (IDENTIFIER_LENGTH (name),
5915                            IDENTIFIER_POINTER (name));
5916       list = tree_cons (name, label, list);
5917       if (c_parser_next_token_is (parser, CPP_COMMA))
5918         c_parser_consume_token (parser);
5919       else
5920         return nreverse (list);
5921     }
5922 }
5923
5924 /* Parse an expression other than a compound expression; that is, an
5925    assignment expression (C90 6.3.16, C99 6.5.16).  If AFTER is not
5926    NULL then it is an Objective-C message expression which is the
5927    primary-expression starting the expression as an initializer.
5928
5929    assignment-expression:
5930      conditional-expression
5931      unary-expression assignment-operator assignment-expression
5932
5933    assignment-operator: one of
5934      = *= /= %= += -= <<= >>= &= ^= |=
5935
5936    In GNU C we accept any conditional expression on the LHS and
5937    diagnose the invalid lvalue rather than producing a syntax
5938    error.  */
5939
5940 static struct c_expr
5941 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
5942                          tree omp_atomic_lhs)
5943 {
5944   struct c_expr lhs, rhs, ret;
5945   enum tree_code code;
5946   location_t op_location, exp_location;
5947   gcc_assert (!after || c_dialect_objc ());
5948   lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
5949   op_location = c_parser_peek_token (parser)->location;
5950   switch (c_parser_peek_token (parser)->type)
5951     {
5952     case CPP_EQ:
5953       code = NOP_EXPR;
5954       break;
5955     case CPP_MULT_EQ:
5956       code = MULT_EXPR;
5957       break;
5958     case CPP_DIV_EQ:
5959       code = TRUNC_DIV_EXPR;
5960       break;
5961     case CPP_MOD_EQ:
5962       code = TRUNC_MOD_EXPR;
5963       break;
5964     case CPP_PLUS_EQ:
5965       code = PLUS_EXPR;
5966       break;
5967     case CPP_MINUS_EQ:
5968       code = MINUS_EXPR;
5969       break;
5970     case CPP_LSHIFT_EQ:
5971       code = LSHIFT_EXPR;
5972       break;
5973     case CPP_RSHIFT_EQ:
5974       code = RSHIFT_EXPR;
5975       break;
5976     case CPP_AND_EQ:
5977       code = BIT_AND_EXPR;
5978       break;
5979     case CPP_XOR_EQ:
5980       code = BIT_XOR_EXPR;
5981       break;
5982     case CPP_OR_EQ:
5983       code = BIT_IOR_EXPR;
5984       break;
5985     default:
5986       return lhs;
5987     }
5988   c_parser_consume_token (parser);
5989   exp_location = c_parser_peek_token (parser)->location;
5990   rhs = c_parser_expr_no_commas (parser, NULL);
5991   rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
5992   
5993   ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5994                                  code, exp_location, rhs.value,
5995                                  rhs.original_type);
5996   if (code == NOP_EXPR)
5997     ret.original_code = MODIFY_EXPR;
5998   else
5999     {
6000       TREE_NO_WARNING (ret.value) = 1;
6001       ret.original_code = ERROR_MARK;
6002     }
6003   ret.original_type = NULL;
6004   return ret;
6005 }
6006
6007 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15).  If AFTER
6008    is not NULL then it is an Objective-C message expression which is
6009    the primary-expression starting the expression as an initializer.
6010
6011    conditional-expression:
6012      logical-OR-expression
6013      logical-OR-expression ? expression : conditional-expression
6014
6015    GNU extensions:
6016
6017    conditional-expression:
6018      logical-OR-expression ? : conditional-expression
6019 */
6020
6021 static struct c_expr
6022 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6023                                  tree omp_atomic_lhs)
6024 {
6025   struct c_expr cond, exp1, exp2, ret;
6026   location_t cond_loc, colon_loc, middle_loc;
6027
6028   gcc_assert (!after || c_dialect_objc ());
6029
6030   cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6031
6032   if (c_parser_next_token_is_not (parser, CPP_QUERY))
6033     return cond;
6034   cond_loc = c_parser_peek_token (parser)->location;
6035   cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6036   c_parser_consume_token (parser);
6037   if (c_parser_next_token_is (parser, CPP_COLON))
6038     {
6039       tree eptype = NULL_TREE;
6040
6041       middle_loc = c_parser_peek_token (parser)->location;
6042       pedwarn (middle_loc, OPT_Wpedantic, 
6043                "ISO C forbids omitting the middle term of a ?: expression");
6044       warn_for_omitted_condop (middle_loc, cond.value);
6045       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6046         {
6047           eptype = TREE_TYPE (cond.value);
6048           cond.value = TREE_OPERAND (cond.value, 0);
6049         }
6050       /* Make sure first operand is calculated only once.  */
6051       exp1.value = c_save_expr (default_conversion (cond.value));
6052       if (eptype)
6053         exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6054       exp1.original_type = NULL;
6055       cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6056       c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6057     }
6058   else
6059     {
6060       cond.value
6061         = c_objc_common_truthvalue_conversion
6062         (cond_loc, default_conversion (cond.value));
6063       c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6064       exp1 = c_parser_expression_conv (parser);
6065       mark_exp_read (exp1.value);
6066       c_inhibit_evaluation_warnings +=
6067         ((cond.value == truthvalue_true_node)
6068          - (cond.value == truthvalue_false_node));
6069     }
6070
6071   colon_loc = c_parser_peek_token (parser)->location;
6072   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6073     {
6074       c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6075       ret.value = error_mark_node;
6076       ret.original_code = ERROR_MARK;
6077       ret.original_type = NULL;
6078       return ret;
6079     }
6080   {
6081     location_t exp2_loc = c_parser_peek_token (parser)->location;
6082     exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6083     exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6084   }
6085   c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6086   ret.value = build_conditional_expr (colon_loc, cond.value,
6087                                       cond.original_code == C_MAYBE_CONST_EXPR,
6088                                       exp1.value, exp1.original_type,
6089                                       exp2.value, exp2.original_type);
6090   ret.original_code = ERROR_MARK;
6091   if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6092     ret.original_type = NULL;
6093   else
6094     {
6095       tree t1, t2;
6096
6097       /* If both sides are enum type, the default conversion will have
6098          made the type of the result be an integer type.  We want to
6099          remember the enum types we started with.  */
6100       t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6101       t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6102       ret.original_type = ((t1 != error_mark_node
6103                             && t2 != error_mark_node
6104                             && (TYPE_MAIN_VARIANT (t1)
6105                                 == TYPE_MAIN_VARIANT (t2)))
6106                            ? t1
6107                            : NULL);
6108     }
6109   return ret;
6110 }
6111
6112 /* Parse a binary expression; that is, a logical-OR-expression (C90
6113    6.3.5-6.3.14, C99 6.5.5-6.5.14).  If AFTER is not NULL then it is
6114    an Objective-C message expression which is the primary-expression
6115    starting the expression as an initializer.
6116
6117    OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6118    when it should be the unfolded lhs.  In a valid OpenMP source,
6119    one of the operands of the toplevel binary expression must be equal
6120    to it.  In that case, just return a build2 created binary operation
6121    rather than result of parser_build_binary_op.
6122
6123    multiplicative-expression:
6124      cast-expression
6125      multiplicative-expression * cast-expression
6126      multiplicative-expression / cast-expression
6127      multiplicative-expression % cast-expression
6128
6129    additive-expression:
6130      multiplicative-expression
6131      additive-expression + multiplicative-expression
6132      additive-expression - multiplicative-expression
6133
6134    shift-expression:
6135      additive-expression
6136      shift-expression << additive-expression
6137      shift-expression >> additive-expression
6138
6139    relational-expression:
6140      shift-expression
6141      relational-expression < shift-expression
6142      relational-expression > shift-expression
6143      relational-expression <= shift-expression
6144      relational-expression >= shift-expression
6145
6146    equality-expression:
6147      relational-expression
6148      equality-expression == relational-expression
6149      equality-expression != relational-expression
6150
6151    AND-expression:
6152      equality-expression
6153      AND-expression & equality-expression
6154
6155    exclusive-OR-expression:
6156      AND-expression
6157      exclusive-OR-expression ^ AND-expression
6158
6159    inclusive-OR-expression:
6160      exclusive-OR-expression
6161      inclusive-OR-expression | exclusive-OR-expression
6162
6163    logical-AND-expression:
6164      inclusive-OR-expression
6165      logical-AND-expression && inclusive-OR-expression
6166
6167    logical-OR-expression:
6168      logical-AND-expression
6169      logical-OR-expression || logical-AND-expression
6170 */
6171
6172 static struct c_expr
6173 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6174                             tree omp_atomic_lhs)
6175 {
6176   /* A binary expression is parsed using operator-precedence parsing,
6177      with the operands being cast expressions.  All the binary
6178      operators are left-associative.  Thus a binary expression is of
6179      form:
6180
6181      E0 op1 E1 op2 E2 ...
6182
6183      which we represent on a stack.  On the stack, the precedence
6184      levels are strictly increasing.  When a new operator is
6185      encountered of higher precedence than that at the top of the
6186      stack, it is pushed; its LHS is the top expression, and its RHS
6187      is everything parsed until it is popped.  When a new operator is
6188      encountered with precedence less than or equal to that at the top
6189      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6190      by the result of the operation until the operator at the top of
6191      the stack has lower precedence than the new operator or there is
6192      only one element on the stack; then the top expression is the LHS
6193      of the new operator.  In the case of logical AND and OR
6194      expressions, we also need to adjust c_inhibit_evaluation_warnings
6195      as appropriate when the operators are pushed and popped.  */
6196
6197   struct {
6198     /* The expression at this stack level.  */
6199     struct c_expr expr;
6200     /* The precedence of the operator on its left, PREC_NONE at the
6201        bottom of the stack.  */
6202     enum c_parser_prec prec;
6203     /* The operation on its left.  */
6204     enum tree_code op;
6205     /* The source location of this operation.  */
6206     location_t loc;
6207   } stack[NUM_PRECS];
6208   int sp;
6209   /* Location of the binary operator.  */
6210   location_t binary_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
6211 #define POP                                                                   \
6212   do {                                                                        \
6213     switch (stack[sp].op)                                                     \
6214       {                                                                       \
6215       case TRUTH_ANDIF_EXPR:                                                  \
6216         c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value            \
6217                                           == truthvalue_false_node);          \
6218         break;                                                                \
6219       case TRUTH_ORIF_EXPR:                                                   \
6220         c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value            \
6221                                           == truthvalue_true_node);           \
6222         break;                                                                \
6223       default:                                                                \
6224         break;                                                                \
6225       }                                                                       \
6226     stack[sp - 1].expr                                                        \
6227       = convert_lvalue_to_rvalue (stack[sp - 1].loc,                          \
6228                                   stack[sp - 1].expr, true, true);            \
6229     stack[sp].expr                                                            \
6230       = convert_lvalue_to_rvalue (stack[sp].loc,                              \
6231                                   stack[sp].expr, true, true);                \
6232     if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1          \
6233         && c_parser_peek_token (parser)->type == CPP_SEMICOLON                \
6234         && ((1 << stack[sp].prec)                                             \
6235             & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT      \
6236                      | PREC_ADD | PREC_MULT)))                                \
6237         && stack[sp].op != TRUNC_MOD_EXPR                                     \
6238         && stack[0].expr.value != error_mark_node                             \
6239         && stack[1].expr.value != error_mark_node                             \
6240         && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs)                \
6241             || c_tree_equal (stack[1].expr.value, omp_atomic_lhs)))           \
6242       stack[0].expr.value                                                     \
6243         = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value),               \
6244                   stack[0].expr.value, stack[1].expr.value);                  \
6245     else                                                                      \
6246       stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc,             \
6247                                                    stack[sp].op,              \
6248                                                    stack[sp - 1].expr,        \
6249                                                    stack[sp].expr);           \
6250     sp--;                                                                     \
6251   } while (0)
6252   gcc_assert (!after || c_dialect_objc ());
6253   stack[0].loc = c_parser_peek_token (parser)->location;
6254   stack[0].expr = c_parser_cast_expression (parser, after);
6255   stack[0].prec = PREC_NONE;
6256   sp = 0;
6257   while (true)
6258     {
6259       enum c_parser_prec oprec;
6260       enum tree_code ocode;
6261       if (parser->error)
6262         goto out;
6263       switch (c_parser_peek_token (parser)->type)
6264         {
6265         case CPP_MULT:
6266           oprec = PREC_MULT;
6267           ocode = MULT_EXPR;
6268           break;
6269         case CPP_DIV:
6270           oprec = PREC_MULT;
6271           ocode = TRUNC_DIV_EXPR;
6272           break;
6273         case CPP_MOD:
6274           oprec = PREC_MULT;
6275           ocode = TRUNC_MOD_EXPR;
6276           break;
6277         case CPP_PLUS:
6278           oprec = PREC_ADD;
6279           ocode = PLUS_EXPR;
6280           break;
6281         case CPP_MINUS:
6282           oprec = PREC_ADD;
6283           ocode = MINUS_EXPR;
6284           break;
6285         case CPP_LSHIFT:
6286           oprec = PREC_SHIFT;
6287           ocode = LSHIFT_EXPR;
6288           break;
6289         case CPP_RSHIFT:
6290           oprec = PREC_SHIFT;
6291           ocode = RSHIFT_EXPR;
6292           break;
6293         case CPP_LESS:
6294           oprec = PREC_REL;
6295           ocode = LT_EXPR;
6296           break;
6297         case CPP_GREATER:
6298           oprec = PREC_REL;
6299           ocode = GT_EXPR;
6300           break;
6301         case CPP_LESS_EQ:
6302           oprec = PREC_REL;
6303           ocode = LE_EXPR;
6304           break;
6305         case CPP_GREATER_EQ:
6306           oprec = PREC_REL;
6307           ocode = GE_EXPR;
6308           break;
6309         case CPP_EQ_EQ:
6310           oprec = PREC_EQ;
6311           ocode = EQ_EXPR;
6312           break;
6313         case CPP_NOT_EQ:
6314           oprec = PREC_EQ;
6315           ocode = NE_EXPR;
6316           break;
6317         case CPP_AND:
6318           oprec = PREC_BITAND;
6319           ocode = BIT_AND_EXPR;
6320           break;
6321         case CPP_XOR:
6322           oprec = PREC_BITXOR;
6323           ocode = BIT_XOR_EXPR;
6324           break;
6325         case CPP_OR:
6326           oprec = PREC_BITOR;
6327           ocode = BIT_IOR_EXPR;
6328           break;
6329         case CPP_AND_AND:
6330           oprec = PREC_LOGAND;
6331           ocode = TRUTH_ANDIF_EXPR;
6332           break;
6333         case CPP_OR_OR:
6334           oprec = PREC_LOGOR;
6335           ocode = TRUTH_ORIF_EXPR;
6336           break;
6337         default:
6338           /* Not a binary operator, so end of the binary
6339              expression.  */
6340           goto out;
6341         }
6342       binary_loc = c_parser_peek_token (parser)->location;
6343       while (oprec <= stack[sp].prec)
6344         POP;
6345       c_parser_consume_token (parser);
6346       switch (ocode)
6347         {
6348         case TRUTH_ANDIF_EXPR:
6349           stack[sp].expr
6350             = convert_lvalue_to_rvalue (stack[sp].loc,
6351                                         stack[sp].expr, true, true);
6352           stack[sp].expr.value = c_objc_common_truthvalue_conversion
6353             (stack[sp].loc, default_conversion (stack[sp].expr.value));
6354           c_inhibit_evaluation_warnings += (stack[sp].expr.value
6355                                             == truthvalue_false_node);
6356           break;
6357         case TRUTH_ORIF_EXPR:
6358           stack[sp].expr
6359             = convert_lvalue_to_rvalue (stack[sp].loc,
6360                                         stack[sp].expr, true, true);
6361           stack[sp].expr.value = c_objc_common_truthvalue_conversion
6362             (stack[sp].loc, default_conversion (stack[sp].expr.value));
6363           c_inhibit_evaluation_warnings += (stack[sp].expr.value
6364                                             == truthvalue_true_node);
6365           break;
6366         default:
6367           break;
6368         }
6369       sp++;
6370       stack[sp].loc = binary_loc;
6371       stack[sp].expr = c_parser_cast_expression (parser, NULL);
6372       stack[sp].prec = oprec;
6373       stack[sp].op = ocode;
6374       stack[sp].loc = binary_loc;
6375     }
6376  out:
6377   while (sp > 0)
6378     POP;
6379   return stack[0].expr;
6380 #undef POP
6381 }
6382
6383 /* Parse a cast expression (C90 6.3.4, C99 6.5.4).  If AFTER is not
6384    NULL then it is an Objective-C message expression which is the
6385    primary-expression starting the expression as an initializer.
6386
6387    cast-expression:
6388      unary-expression
6389      ( type-name ) unary-expression
6390 */
6391
6392 static struct c_expr
6393 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
6394 {
6395   location_t cast_loc = c_parser_peek_token (parser)->location;
6396   gcc_assert (!after || c_dialect_objc ());
6397   if (after)
6398     return c_parser_postfix_expression_after_primary (parser,
6399                                                       cast_loc, *after);
6400   /* If the expression begins with a parenthesized type name, it may
6401      be either a cast or a compound literal; we need to see whether
6402      the next character is '{' to tell the difference.  If not, it is
6403      an unary expression.  Full detection of unknown typenames here
6404      would require a 3-token lookahead.  */
6405   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6406       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6407     {
6408       struct c_type_name *type_name;
6409       struct c_expr ret;
6410       struct c_expr expr;
6411       c_parser_consume_token (parser);
6412       type_name = c_parser_type_name (parser);
6413       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6414       if (type_name == NULL)
6415         {
6416           ret.value = error_mark_node;
6417           ret.original_code = ERROR_MARK;
6418           ret.original_type = NULL;
6419           return ret;
6420         }
6421
6422       /* Save casted types in the function's used types hash table.  */
6423       used_types_insert (type_name->specs->type);
6424
6425       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6426         return c_parser_postfix_expression_after_paren_type (parser, type_name,
6427                                                              cast_loc);
6428       {
6429         location_t expr_loc = c_parser_peek_token (parser)->location;
6430         expr = c_parser_cast_expression (parser, NULL);
6431         expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
6432       }
6433       ret.value = c_cast_expr (cast_loc, type_name, expr.value);
6434       ret.original_code = ERROR_MARK;
6435       ret.original_type = NULL;
6436       return ret;
6437     }
6438   else
6439     return c_parser_unary_expression (parser);
6440 }
6441
6442 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6443
6444    unary-expression:
6445      postfix-expression
6446      ++ unary-expression
6447      -- unary-expression
6448      unary-operator cast-expression
6449      sizeof unary-expression
6450      sizeof ( type-name )
6451
6452    unary-operator: one of
6453      & * + - ~ !
6454
6455    GNU extensions:
6456
6457    unary-expression:
6458      __alignof__ unary-expression
6459      __alignof__ ( type-name )
6460      && identifier
6461
6462    (C11 permits _Alignof with type names only.)
6463
6464    unary-operator: one of
6465      __extension__ __real__ __imag__
6466
6467    Transactional Memory:
6468
6469    unary-expression:
6470      transaction-expression
6471
6472    In addition, the GNU syntax treats ++ and -- as unary operators, so
6473    they may be applied to cast expressions with errors for non-lvalues
6474    given later.  */
6475
6476 static struct c_expr
6477 c_parser_unary_expression (c_parser *parser)
6478 {
6479   int ext;
6480   struct c_expr ret, op;
6481   location_t op_loc = c_parser_peek_token (parser)->location;
6482   location_t exp_loc;
6483   ret.original_code = ERROR_MARK;
6484   ret.original_type = NULL;
6485   switch (c_parser_peek_token (parser)->type)
6486     {
6487     case CPP_PLUS_PLUS:
6488       c_parser_consume_token (parser);
6489       exp_loc = c_parser_peek_token (parser)->location;
6490       op = c_parser_cast_expression (parser, NULL);
6491
6492       /* If there is array notations in op, we expand them.  */
6493       if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6494         return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op);
6495       else
6496         {
6497           op = default_function_array_read_conversion (exp_loc, op);
6498           return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
6499         }
6500     case CPP_MINUS_MINUS:
6501       c_parser_consume_token (parser);
6502       exp_loc = c_parser_peek_token (parser)->location;
6503       op = c_parser_cast_expression (parser, NULL);
6504       
6505       /* If there is array notations in op, we expand them.  */
6506       if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6507         return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op);
6508       else
6509         {
6510           op = default_function_array_read_conversion (exp_loc, op);
6511           return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
6512         }
6513     case CPP_AND:
6514       c_parser_consume_token (parser);
6515       op = c_parser_cast_expression (parser, NULL);
6516       mark_exp_read (op.value);
6517       return parser_build_unary_op (op_loc, ADDR_EXPR, op);
6518     case CPP_MULT:
6519       c_parser_consume_token (parser);
6520       exp_loc = c_parser_peek_token (parser)->location;
6521       op = c_parser_cast_expression (parser, NULL);
6522       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6523       ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
6524       return ret;
6525     case CPP_PLUS:
6526       if (!c_dialect_objc () && !in_system_header_at (input_location))
6527         warning_at (op_loc,
6528                     OPT_Wtraditional,
6529                     "traditional C rejects the unary plus operator");
6530       c_parser_consume_token (parser);
6531       exp_loc = c_parser_peek_token (parser)->location;
6532       op = c_parser_cast_expression (parser, NULL);
6533       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6534       return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
6535     case CPP_MINUS:
6536       c_parser_consume_token (parser);
6537       exp_loc = c_parser_peek_token (parser)->location;
6538       op = c_parser_cast_expression (parser, NULL);
6539       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6540       return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
6541     case CPP_COMPL:
6542       c_parser_consume_token (parser);
6543       exp_loc = c_parser_peek_token (parser)->location;
6544       op = c_parser_cast_expression (parser, NULL);
6545       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6546       return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
6547     case CPP_NOT:
6548       c_parser_consume_token (parser);
6549       exp_loc = c_parser_peek_token (parser)->location;
6550       op = c_parser_cast_expression (parser, NULL);
6551       op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6552       return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
6553     case CPP_AND_AND:
6554       /* Refer to the address of a label as a pointer.  */
6555       c_parser_consume_token (parser);
6556       if (c_parser_next_token_is (parser, CPP_NAME))
6557         {
6558           ret.value = finish_label_address_expr
6559             (c_parser_peek_token (parser)->value, op_loc);
6560           c_parser_consume_token (parser);
6561         }
6562       else
6563         {
6564           c_parser_error (parser, "expected identifier");
6565           ret.value = error_mark_node;
6566         }
6567         return ret;
6568     case CPP_KEYWORD:
6569       switch (c_parser_peek_token (parser)->keyword)
6570         {
6571         case RID_SIZEOF:
6572           return c_parser_sizeof_expression (parser);
6573         case RID_ALIGNOF:
6574           return c_parser_alignof_expression (parser);
6575         case RID_EXTENSION:
6576           c_parser_consume_token (parser);
6577           ext = disable_extension_diagnostics ();
6578           ret = c_parser_cast_expression (parser, NULL);
6579           restore_extension_diagnostics (ext);
6580           return ret;
6581         case RID_REALPART:
6582           c_parser_consume_token (parser);
6583           exp_loc = c_parser_peek_token (parser)->location;
6584           op = c_parser_cast_expression (parser, NULL);
6585           op = default_function_array_conversion (exp_loc, op);
6586           return parser_build_unary_op (op_loc, REALPART_EXPR, op);
6587         case RID_IMAGPART:
6588           c_parser_consume_token (parser);
6589           exp_loc = c_parser_peek_token (parser)->location;
6590           op = c_parser_cast_expression (parser, NULL);
6591           op = default_function_array_conversion (exp_loc, op);
6592           return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
6593         case RID_TRANSACTION_ATOMIC:
6594         case RID_TRANSACTION_RELAXED:
6595           return c_parser_transaction_expression (parser,
6596               c_parser_peek_token (parser)->keyword);
6597         default:
6598           return c_parser_postfix_expression (parser);
6599         }
6600     default:
6601       return c_parser_postfix_expression (parser);
6602     }
6603 }
6604
6605 /* Parse a sizeof expression.  */
6606
6607 static struct c_expr
6608 c_parser_sizeof_expression (c_parser *parser)
6609 {
6610   struct c_expr expr;
6611   location_t expr_loc;
6612   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
6613   c_parser_consume_token (parser);
6614   c_inhibit_evaluation_warnings++;
6615   in_sizeof++;
6616   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6617       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6618     {
6619       /* Either sizeof ( type-name ) or sizeof unary-expression
6620          starting with a compound literal.  */
6621       struct c_type_name *type_name;
6622       c_parser_consume_token (parser);
6623       expr_loc = c_parser_peek_token (parser)->location;
6624       type_name = c_parser_type_name (parser);
6625       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6626       if (type_name == NULL)
6627         {
6628           struct c_expr ret;
6629           c_inhibit_evaluation_warnings--;
6630           in_sizeof--;
6631           ret.value = error_mark_node;
6632           ret.original_code = ERROR_MARK;
6633           ret.original_type = NULL;
6634           return ret;
6635         }
6636       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6637         {
6638           expr = c_parser_postfix_expression_after_paren_type (parser,
6639                                                                type_name,
6640                                                                expr_loc);
6641           goto sizeof_expr;
6642         }
6643       /* sizeof ( type-name ).  */
6644       c_inhibit_evaluation_warnings--;
6645       in_sizeof--;
6646       return c_expr_sizeof_type (expr_loc, type_name);
6647     }
6648   else
6649     {
6650       expr_loc = c_parser_peek_token (parser)->location;
6651       expr = c_parser_unary_expression (parser);
6652     sizeof_expr:
6653       c_inhibit_evaluation_warnings--;
6654       in_sizeof--;
6655       mark_exp_read (expr.value);
6656       if (TREE_CODE (expr.value) == COMPONENT_REF
6657           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
6658         error_at (expr_loc, "%<sizeof%> applied to a bit-field");
6659       return c_expr_sizeof_expr (expr_loc, expr);
6660     }
6661 }
6662
6663 /* Parse an alignof expression.  */
6664
6665 static struct c_expr
6666 c_parser_alignof_expression (c_parser *parser)
6667 {
6668   struct c_expr expr;
6669   location_t loc = c_parser_peek_token (parser)->location;
6670   tree alignof_spelling = c_parser_peek_token (parser)->value;
6671   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
6672   bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
6673                                 "_Alignof") == 0;
6674   /* A diagnostic is not required for the use of this identifier in
6675      the implementation namespace; only diagnose it for the C11
6676      spelling because of existing code using the other spellings.  */
6677   if (is_c11_alignof)
6678     {
6679       if (flag_isoc99)
6680         pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
6681                      alignof_spelling);
6682       else
6683         pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
6684                      alignof_spelling);
6685     }
6686   c_parser_consume_token (parser);
6687   c_inhibit_evaluation_warnings++;
6688   in_alignof++;
6689   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6690       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6691     {
6692       /* Either __alignof__ ( type-name ) or __alignof__
6693          unary-expression starting with a compound literal.  */
6694       location_t loc;
6695       struct c_type_name *type_name;
6696       struct c_expr ret;
6697       c_parser_consume_token (parser);
6698       loc = c_parser_peek_token (parser)->location;
6699       type_name = c_parser_type_name (parser);
6700       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6701       if (type_name == NULL)
6702         {
6703           struct c_expr ret;
6704           c_inhibit_evaluation_warnings--;
6705           in_alignof--;
6706           ret.value = error_mark_node;
6707           ret.original_code = ERROR_MARK;
6708           ret.original_type = NULL;
6709           return ret;
6710         }
6711       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6712         {
6713           expr = c_parser_postfix_expression_after_paren_type (parser,
6714                                                                type_name,
6715                                                                loc);
6716           goto alignof_expr;
6717         }
6718       /* alignof ( type-name ).  */
6719       c_inhibit_evaluation_warnings--;
6720       in_alignof--;
6721       ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
6722                                                                NULL, NULL),
6723                                             false, is_c11_alignof, 1);
6724       ret.original_code = ERROR_MARK;
6725       ret.original_type = NULL;
6726       return ret;
6727     }
6728   else
6729     {
6730       struct c_expr ret;
6731       expr = c_parser_unary_expression (parser);
6732     alignof_expr:
6733       mark_exp_read (expr.value);
6734       c_inhibit_evaluation_warnings--;
6735       in_alignof--;
6736       pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
6737                alignof_spelling);
6738       ret.value = c_alignof_expr (loc, expr.value);
6739       ret.original_code = ERROR_MARK;
6740       ret.original_type = NULL;
6741       return ret;
6742     }
6743 }
6744
6745 /* Helper function to read arguments of builtins which are interfaces
6746    for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6747    others.  The name of the builtin is passed using BNAME parameter.
6748    Function returns true if there were no errors while parsing and
6749    stores the arguments in CEXPR_LIST.  */
6750 static bool
6751 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6752                            vec<c_expr_t, va_gc> **ret_cexpr_list,
6753                            bool choose_expr_p)
6754 {
6755   location_t loc = c_parser_peek_token (parser)->location;
6756   vec<c_expr_t, va_gc> *cexpr_list;
6757   c_expr_t expr;
6758   bool saved_force_folding_builtin_constant_p;
6759
6760   *ret_cexpr_list = NULL;
6761   if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6762     {
6763       error_at (loc, "cannot take address of %qs", bname);
6764       return false;
6765     }
6766
6767   c_parser_consume_token (parser);
6768
6769   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6770     {
6771       c_parser_consume_token (parser);
6772       return true;
6773     }
6774
6775   saved_force_folding_builtin_constant_p
6776     = force_folding_builtin_constant_p;
6777   force_folding_builtin_constant_p |= choose_expr_p;
6778   expr = c_parser_expr_no_commas (parser, NULL);
6779   force_folding_builtin_constant_p
6780     = saved_force_folding_builtin_constant_p;
6781   vec_alloc (cexpr_list, 1);
6782   vec_safe_push (cexpr_list, expr);
6783   while (c_parser_next_token_is (parser, CPP_COMMA))
6784     {
6785       c_parser_consume_token (parser);
6786       expr = c_parser_expr_no_commas (parser, NULL);
6787       vec_safe_push (cexpr_list, expr);
6788     }
6789
6790   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6791     return false;
6792
6793   *ret_cexpr_list = cexpr_list;
6794   return true;
6795 }
6796
6797 /* This represents a single generic-association.  */
6798
6799 struct c_generic_association
6800 {
6801   /* The location of the starting token of the type.  */
6802   location_t type_location;
6803   /* The association's type, or NULL_TREE for 'default'.  */
6804   tree type;
6805   /* The association's expression.  */
6806   struct c_expr expression;
6807 };
6808
6809 /* Parse a generic-selection.  (C11 6.5.1.1).
6810    
6811    generic-selection:
6812      _Generic ( assignment-expression , generic-assoc-list )
6813      
6814    generic-assoc-list:
6815      generic-association
6816      generic-assoc-list , generic-association
6817    
6818    generic-association:
6819      type-name : assignment-expression
6820      default : assignment-expression
6821 */
6822
6823 static struct c_expr
6824 c_parser_generic_selection (c_parser *parser)
6825 {
6826   vec<c_generic_association> associations = vNULL;
6827   struct c_expr selector, error_expr;
6828   tree selector_type;
6829   struct c_generic_association matched_assoc;
6830   bool match_found = false;
6831   location_t generic_loc, selector_loc;
6832
6833   error_expr.original_code = ERROR_MARK;
6834   error_expr.original_type = NULL;
6835   error_expr.value = error_mark_node;
6836   matched_assoc.type_location = UNKNOWN_LOCATION;
6837   matched_assoc.type = NULL_TREE;
6838   matched_assoc.expression = error_expr;
6839
6840   gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
6841   generic_loc = c_parser_peek_token (parser)->location;
6842   c_parser_consume_token (parser);
6843   if (flag_isoc99)
6844     pedwarn_c99 (generic_loc, OPT_Wpedantic,
6845                  "ISO C99 does not support %<_Generic%>");
6846   else
6847     pedwarn_c99 (generic_loc, OPT_Wpedantic,
6848                  "ISO C90 does not support %<_Generic%>");
6849
6850   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6851     return error_expr;
6852
6853   c_inhibit_evaluation_warnings++;
6854   selector_loc = c_parser_peek_token (parser)->location;
6855   selector = c_parser_expr_no_commas (parser, NULL);
6856   selector = default_function_array_conversion (selector_loc, selector);
6857   c_inhibit_evaluation_warnings--;
6858
6859   if (selector.value == error_mark_node)
6860     {
6861       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6862       return selector;
6863     }
6864   selector_type = TREE_TYPE (selector.value);
6865   /* In ISO C terms, rvalues (including the controlling expression of
6866      _Generic) do not have qualified types.  */
6867   if (TREE_CODE (selector_type) != ARRAY_TYPE)
6868     selector_type = TYPE_MAIN_VARIANT (selector_type);
6869   /* In ISO C terms, _Noreturn is not part of the type of expressions
6870      such as &abort, but in GCC it is represented internally as a type
6871      qualifier.  */
6872   if (FUNCTION_POINTER_TYPE_P (selector_type)
6873       && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
6874     selector_type
6875       = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
6876
6877   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6878     {
6879       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6880       return error_expr;
6881     }
6882
6883   while (1)
6884     {
6885       struct c_generic_association assoc, *iter;
6886       unsigned int ix;
6887       c_token *token = c_parser_peek_token (parser);
6888
6889       assoc.type_location = token->location;
6890       if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
6891         {
6892           c_parser_consume_token (parser);
6893           assoc.type = NULL_TREE;
6894         }
6895       else
6896         {
6897           struct c_type_name *type_name;
6898
6899           type_name = c_parser_type_name (parser);
6900           if (type_name == NULL)
6901             {
6902               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6903               goto error_exit;
6904             }
6905           assoc.type = groktypename (type_name, NULL, NULL);
6906           if (assoc.type == error_mark_node)
6907             {
6908               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6909               goto error_exit;
6910             }
6911
6912           if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
6913             error_at (assoc.type_location,
6914                       "%<_Generic%> association has function type");
6915           else if (!COMPLETE_TYPE_P (assoc.type))
6916             error_at (assoc.type_location,
6917                       "%<_Generic%> association has incomplete type");
6918
6919           if (variably_modified_type_p (assoc.type, NULL_TREE))
6920             error_at (assoc.type_location,
6921                       "%<_Generic%> association has "
6922                       "variable length type");
6923         }
6924
6925       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6926         {
6927           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6928           goto error_exit;
6929         }
6930
6931       assoc.expression = c_parser_expr_no_commas (parser, NULL);
6932       if (assoc.expression.value == error_mark_node)
6933         {
6934           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6935           goto error_exit;
6936         }
6937
6938       for (ix = 0; associations.iterate (ix, &iter); ++ix)
6939         {
6940           if (assoc.type == NULL_TREE)
6941             {
6942               if (iter->type == NULL_TREE)
6943                 {
6944                   error_at (assoc.type_location,
6945                             "duplicate %<default%> case in %<_Generic%>");
6946                   inform (iter->type_location, "original %<default%> is here");
6947                 }
6948             }
6949           else if (iter->type != NULL_TREE)
6950             {
6951               if (comptypes (assoc.type, iter->type))
6952                 {
6953                   error_at (assoc.type_location,
6954                             "%<_Generic%> specifies two compatible types");
6955                   inform (iter->type_location, "compatible type is here");
6956                 }
6957             }
6958         }
6959
6960       if (assoc.type == NULL_TREE)
6961         {
6962           if (!match_found)
6963             {
6964               matched_assoc = assoc;
6965               match_found = true;
6966             }
6967         }
6968       else if (comptypes (assoc.type, selector_type))
6969         {
6970           if (!match_found || matched_assoc.type == NULL_TREE)
6971             {
6972               matched_assoc = assoc;
6973               match_found = true;
6974             }
6975           else
6976             {
6977               error_at (assoc.type_location,
6978                         "%<_Generic> selector matches multiple associations");
6979               inform (matched_assoc.type_location,
6980                       "other match is here");
6981             }
6982         }
6983
6984       associations.safe_push (assoc);
6985
6986       if (c_parser_peek_token (parser)->type != CPP_COMMA)
6987         break;
6988       c_parser_consume_token (parser);
6989     }
6990
6991   associations.release ();
6992
6993   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6994     {
6995       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6996       return error_expr;
6997     }
6998
6999   if (!match_found)
7000     {
7001       error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7002                 "compatible with any association",
7003                 selector_type);
7004       return error_expr;
7005     }
7006
7007   return matched_assoc.expression;
7008
7009  error_exit:
7010   associations.release ();
7011   return error_expr;
7012 }
7013
7014 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7015
7016    postfix-expression:
7017      primary-expression
7018      postfix-expression [ expression ]
7019      postfix-expression ( argument-expression-list[opt] )
7020      postfix-expression . identifier
7021      postfix-expression -> identifier
7022      postfix-expression ++
7023      postfix-expression --
7024      ( type-name ) { initializer-list }
7025      ( type-name ) { initializer-list , }
7026
7027    argument-expression-list:
7028      argument-expression
7029      argument-expression-list , argument-expression
7030
7031    primary-expression:
7032      identifier
7033      constant
7034      string-literal
7035      ( expression )
7036      generic-selection
7037
7038    GNU extensions:
7039
7040    primary-expression:
7041      __func__
7042        (treated as a keyword in GNU C)
7043      __FUNCTION__
7044      __PRETTY_FUNCTION__
7045      ( compound-statement )
7046      __builtin_va_arg ( assignment-expression , type-name )
7047      __builtin_offsetof ( type-name , offsetof-member-designator )
7048      __builtin_choose_expr ( assignment-expression ,
7049                              assignment-expression ,
7050                              assignment-expression )
7051      __builtin_types_compatible_p ( type-name , type-name )
7052      __builtin_complex ( assignment-expression , assignment-expression )
7053      __builtin_shuffle ( assignment-expression , assignment-expression )
7054      __builtin_shuffle ( assignment-expression , 
7055                          assignment-expression ,
7056                          assignment-expression, )
7057
7058    offsetof-member-designator:
7059      identifier
7060      offsetof-member-designator . identifier
7061      offsetof-member-designator [ expression ]
7062
7063    Objective-C:
7064
7065    primary-expression:
7066      [ objc-receiver objc-message-args ]
7067      @selector ( objc-selector-arg )
7068      @protocol ( identifier )
7069      @encode ( type-name )
7070      objc-string-literal
7071      Classname . identifier
7072 */
7073
7074 static struct c_expr
7075 c_parser_postfix_expression (c_parser *parser)
7076 {
7077   struct c_expr expr, e1;
7078   struct c_type_name *t1, *t2;
7079   location_t loc = c_parser_peek_token (parser)->location;;
7080   expr.original_code = ERROR_MARK;
7081   expr.original_type = NULL;
7082   switch (c_parser_peek_token (parser)->type)
7083     {
7084     case CPP_NUMBER:
7085       expr.value = c_parser_peek_token (parser)->value;
7086       loc = c_parser_peek_token (parser)->location;
7087       c_parser_consume_token (parser);
7088       if (TREE_CODE (expr.value) == FIXED_CST
7089           && !targetm.fixed_point_supported_p ())
7090         {
7091           error_at (loc, "fixed-point types not supported for this target");
7092           expr.value = error_mark_node;
7093         }
7094       break;
7095     case CPP_CHAR:
7096     case CPP_CHAR16:
7097     case CPP_CHAR32:
7098     case CPP_WCHAR:
7099       expr.value = c_parser_peek_token (parser)->value;
7100       c_parser_consume_token (parser);
7101       break;
7102     case CPP_STRING:
7103     case CPP_STRING16:
7104     case CPP_STRING32:
7105     case CPP_WSTRING:
7106     case CPP_UTF8STRING:
7107       expr.value = c_parser_peek_token (parser)->value;
7108       expr.original_code = STRING_CST;
7109       c_parser_consume_token (parser);
7110       break;
7111     case CPP_OBJC_STRING:
7112       gcc_assert (c_dialect_objc ());
7113       expr.value
7114         = objc_build_string_object (c_parser_peek_token (parser)->value);
7115       c_parser_consume_token (parser);
7116       break;
7117     case CPP_NAME:
7118       switch (c_parser_peek_token (parser)->id_kind)
7119         {
7120         case C_ID_ID:
7121           {
7122             tree id = c_parser_peek_token (parser)->value;
7123             c_parser_consume_token (parser);
7124             expr.value = build_external_ref (loc, id,
7125                                              (c_parser_peek_token (parser)->type
7126                                               == CPP_OPEN_PAREN),
7127                                              &expr.original_type);
7128             break;
7129           }
7130         case C_ID_CLASSNAME:
7131           {
7132             /* Here we parse the Objective-C 2.0 Class.name dot
7133                syntax.  */
7134             tree class_name = c_parser_peek_token (parser)->value;
7135             tree component;
7136             c_parser_consume_token (parser);
7137             gcc_assert (c_dialect_objc ());
7138             if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7139               {
7140                 expr.value = error_mark_node;
7141                 break;
7142               }
7143             if (c_parser_next_token_is_not (parser, CPP_NAME))
7144               {
7145                 c_parser_error (parser, "expected identifier");
7146                 expr.value = error_mark_node;
7147                 break;
7148               }
7149             component = c_parser_peek_token (parser)->value;
7150             c_parser_consume_token (parser);
7151             expr.value = objc_build_class_component_ref (class_name, 
7152                                                          component);
7153             break;
7154           }
7155         default:
7156           c_parser_error (parser, "expected expression");
7157           expr.value = error_mark_node;
7158           break;
7159         }
7160       break;
7161     case CPP_OPEN_PAREN:
7162       /* A parenthesized expression, statement expression or compound
7163          literal.  */
7164       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7165         {
7166           /* A statement expression.  */
7167           tree stmt;
7168           location_t brace_loc;
7169           c_parser_consume_token (parser);
7170           brace_loc = c_parser_peek_token (parser)->location;
7171           c_parser_consume_token (parser);
7172           if (!building_stmt_list_p ())
7173             {
7174               error_at (loc, "braced-group within expression allowed "
7175                         "only inside a function");
7176               parser->error = true;
7177               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7178               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7179               expr.value = error_mark_node;
7180               break;
7181             }
7182           stmt = c_begin_stmt_expr ();
7183           c_parser_compound_statement_nostart (parser);
7184           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7185                                      "expected %<)%>");
7186           pedwarn (loc, OPT_Wpedantic,
7187                    "ISO C forbids braced-groups within expressions");
7188           expr.value = c_finish_stmt_expr (brace_loc, stmt);
7189           mark_exp_read (expr.value);
7190         }
7191       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7192         {
7193           /* A compound literal.  ??? Can we actually get here rather
7194              than going directly to
7195              c_parser_postfix_expression_after_paren_type from
7196              elsewhere?  */
7197           location_t loc;
7198           struct c_type_name *type_name;
7199           c_parser_consume_token (parser);
7200           loc = c_parser_peek_token (parser)->location;
7201           type_name = c_parser_type_name (parser);
7202           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7203                                      "expected %<)%>");
7204           if (type_name == NULL)
7205             {
7206               expr.value = error_mark_node;
7207             }
7208           else
7209             expr = c_parser_postfix_expression_after_paren_type (parser,
7210                                                                  type_name,
7211                                                                  loc);
7212         }
7213       else
7214         {
7215           /* A parenthesized expression.  */
7216           c_parser_consume_token (parser);
7217           expr = c_parser_expression (parser);
7218           if (TREE_CODE (expr.value) == MODIFY_EXPR)
7219             TREE_NO_WARNING (expr.value) = 1;
7220           if (expr.original_code != C_MAYBE_CONST_EXPR)
7221             expr.original_code = ERROR_MARK;
7222           /* Don't change EXPR.ORIGINAL_TYPE.  */
7223           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7224                                      "expected %<)%>");
7225         }
7226       break;
7227     case CPP_KEYWORD:
7228       switch (c_parser_peek_token (parser)->keyword)
7229         {
7230         case RID_FUNCTION_NAME:
7231           pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7232                    "%<__FUNCTION__%> predefined identifier");
7233           expr.value = fname_decl (loc,
7234                                    c_parser_peek_token (parser)->keyword,
7235                                    c_parser_peek_token (parser)->value);
7236           c_parser_consume_token (parser);
7237           break;
7238         case RID_PRETTY_FUNCTION_NAME:
7239           pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
7240                    "%<__PRETTY_FUNCTION__%> predefined identifier");
7241           expr.value = fname_decl (loc,
7242                                    c_parser_peek_token (parser)->keyword,
7243                                    c_parser_peek_token (parser)->value);
7244           c_parser_consume_token (parser);
7245           break;
7246         case RID_C99_FUNCTION_NAME:
7247           pedwarn_c90 (loc, OPT_Wpedantic,  "ISO C90 does not support "
7248                    "%<__func__%> predefined identifier");
7249           expr.value = fname_decl (loc,
7250                                    c_parser_peek_token (parser)->keyword,
7251                                    c_parser_peek_token (parser)->value);
7252           c_parser_consume_token (parser);
7253           break;
7254         case RID_VA_ARG:
7255           c_parser_consume_token (parser);
7256           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7257             {
7258               expr.value = error_mark_node;
7259               break;
7260             }
7261           e1 = c_parser_expr_no_commas (parser, NULL);
7262           mark_exp_read (e1.value);
7263           e1.value = c_fully_fold (e1.value, false, NULL);
7264           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7265             {
7266               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7267               expr.value = error_mark_node;
7268               break;
7269             }
7270           loc = c_parser_peek_token (parser)->location;
7271           t1 = c_parser_type_name (parser);
7272           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7273                                      "expected %<)%>");
7274           if (t1 == NULL)
7275             {
7276               expr.value = error_mark_node;
7277             }
7278           else
7279             {
7280               tree type_expr = NULL_TREE;
7281               expr.value = c_build_va_arg (loc, e1.value,
7282                                            groktypename (t1, &type_expr, NULL));
7283               if (type_expr)
7284                 {
7285                   expr.value = build2 (C_MAYBE_CONST_EXPR,
7286                                        TREE_TYPE (expr.value), type_expr,
7287                                        expr.value);
7288                   C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
7289                 }
7290             }
7291           break;
7292         case RID_OFFSETOF:
7293           c_parser_consume_token (parser);
7294           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7295             {
7296               expr.value = error_mark_node;
7297               break;
7298             }
7299           t1 = c_parser_type_name (parser);
7300           if (t1 == NULL)
7301             parser->error = true;
7302           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7303             gcc_assert (parser->error);
7304           if (parser->error)
7305             {
7306               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7307               expr.value = error_mark_node;
7308               break;
7309             }
7310
7311           {
7312             tree type = groktypename (t1, NULL, NULL);
7313             tree offsetof_ref;
7314             if (type == error_mark_node)
7315               offsetof_ref = error_mark_node;
7316             else
7317               {
7318                 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
7319                 SET_EXPR_LOCATION (offsetof_ref, loc);
7320               }
7321             /* Parse the second argument to __builtin_offsetof.  We
7322                must have one identifier, and beyond that we want to
7323                accept sub structure and sub array references.  */
7324             if (c_parser_next_token_is (parser, CPP_NAME))
7325               {
7326                 offsetof_ref = build_component_ref
7327                   (loc, offsetof_ref, c_parser_peek_token (parser)->value);
7328                 c_parser_consume_token (parser);
7329                 while (c_parser_next_token_is (parser, CPP_DOT)
7330                        || c_parser_next_token_is (parser,
7331                                                   CPP_OPEN_SQUARE)
7332                        || c_parser_next_token_is (parser,
7333                                                   CPP_DEREF))
7334                   {
7335                     if (c_parser_next_token_is (parser, CPP_DEREF))
7336                       {
7337                         loc = c_parser_peek_token (parser)->location;
7338                         offsetof_ref = build_array_ref (loc,
7339                                                         offsetof_ref,
7340                                                         integer_zero_node);
7341                         goto do_dot;
7342                       }
7343                     else if (c_parser_next_token_is (parser, CPP_DOT))
7344                       {
7345                       do_dot:
7346                         c_parser_consume_token (parser);
7347                         if (c_parser_next_token_is_not (parser,
7348                                                         CPP_NAME))
7349                           {
7350                             c_parser_error (parser, "expected identifier");
7351                             break;
7352                           }
7353                         offsetof_ref = build_component_ref
7354                           (loc, offsetof_ref,
7355                            c_parser_peek_token (parser)->value);
7356                         c_parser_consume_token (parser);
7357                       }
7358                     else
7359                       {
7360                         struct c_expr ce;
7361                         tree idx;
7362                         loc = c_parser_peek_token (parser)->location;
7363                         c_parser_consume_token (parser);
7364                         ce = c_parser_expression (parser);
7365                         ce = convert_lvalue_to_rvalue (loc, ce, false, false);
7366                         idx = ce.value;
7367                         idx = c_fully_fold (idx, false, NULL);
7368                         c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7369                                                    "expected %<]%>");
7370                         offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
7371                       }
7372                   }
7373               }
7374             else
7375               c_parser_error (parser, "expected identifier");
7376             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7377                                        "expected %<)%>");
7378             expr.value = fold_offsetof (offsetof_ref);
7379           }
7380           break;
7381         case RID_CHOOSE_EXPR:
7382           {
7383             vec<c_expr_t, va_gc> *cexpr_list;
7384             c_expr_t *e1_p, *e2_p, *e3_p;
7385             tree c;
7386
7387             c_parser_consume_token (parser);
7388             if (!c_parser_get_builtin_args (parser,
7389                                             "__builtin_choose_expr",
7390                                             &cexpr_list, true))
7391               {
7392                 expr.value = error_mark_node;
7393                 break;
7394               }
7395
7396             if (vec_safe_length (cexpr_list) != 3)
7397               {
7398                 error_at (loc, "wrong number of arguments to "
7399                                "%<__builtin_choose_expr%>");
7400                 expr.value = error_mark_node;
7401                 break;
7402               }
7403
7404             e1_p = &(*cexpr_list)[0];
7405             e2_p = &(*cexpr_list)[1];
7406             e3_p = &(*cexpr_list)[2];
7407
7408             c = e1_p->value;
7409             mark_exp_read (e2_p->value);
7410             mark_exp_read (e3_p->value);
7411             if (TREE_CODE (c) != INTEGER_CST
7412                 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
7413               error_at (loc,
7414                         "first argument to %<__builtin_choose_expr%> not"
7415                         " a constant");
7416             constant_expression_warning (c);
7417             expr = integer_zerop (c) ? *e3_p : *e2_p;
7418             break;
7419           }
7420         case RID_TYPES_COMPATIBLE_P:
7421           c_parser_consume_token (parser);
7422           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7423             {
7424               expr.value = error_mark_node;
7425               break;
7426             }
7427           t1 = c_parser_type_name (parser);
7428           if (t1 == NULL)
7429             {
7430               expr.value = error_mark_node;
7431               break;
7432             }
7433           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7434             {
7435               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7436               expr.value = error_mark_node;
7437               break;
7438             }
7439           t2 = c_parser_type_name (parser);
7440           if (t2 == NULL)
7441             {
7442               expr.value = error_mark_node;
7443               break;
7444             }
7445           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7446                                      "expected %<)%>");
7447           {
7448             tree e1, e2;
7449             e1 = groktypename (t1, NULL, NULL);
7450             e2 = groktypename (t2, NULL, NULL);
7451             if (e1 == error_mark_node || e2 == error_mark_node)
7452               {
7453                 expr.value = error_mark_node;
7454                 break;
7455               }
7456
7457             e1 = TYPE_MAIN_VARIANT (e1);
7458             e2 = TYPE_MAIN_VARIANT (e2);
7459
7460             expr.value
7461               = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
7462           }
7463           break;
7464         case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
7465           {
7466             vec<c_expr_t, va_gc> *cexpr_list;
7467             c_expr_t *e2_p;
7468             tree chain_value;
7469
7470             c_parser_consume_token (parser);
7471             if (!c_parser_get_builtin_args (parser,
7472                                             "__builtin_call_with_static_chain",
7473                                             &cexpr_list, false))
7474               {
7475                 expr.value = error_mark_node;
7476                 break;
7477               }
7478             if (vec_safe_length (cexpr_list) != 2)
7479               {
7480                 error_at (loc, "wrong number of arguments to "
7481                                "%<__builtin_call_with_static_chain%>");
7482                 expr.value = error_mark_node;
7483                 break;
7484               }
7485
7486             expr = (*cexpr_list)[0];
7487             e2_p = &(*cexpr_list)[1];
7488             *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7489             chain_value = e2_p->value;
7490             mark_exp_read (chain_value);
7491
7492             if (TREE_CODE (expr.value) != CALL_EXPR)
7493               error_at (loc, "first argument to "
7494                         "%<__builtin_call_with_static_chain%> "
7495                         "must be a call expression");
7496             else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
7497               error_at (loc, "second argument to "
7498                         "%<__builtin_call_with_static_chain%> "
7499                         "must be a pointer type");
7500             else
7501               CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
7502             break;
7503           }
7504         case RID_BUILTIN_COMPLEX:
7505           {
7506             vec<c_expr_t, va_gc> *cexpr_list;
7507             c_expr_t *e1_p, *e2_p;
7508
7509             c_parser_consume_token (parser);
7510             if (!c_parser_get_builtin_args (parser,
7511                                             "__builtin_complex",
7512                                             &cexpr_list, false))
7513               {
7514                 expr.value = error_mark_node;
7515                 break;
7516               }
7517
7518             if (vec_safe_length (cexpr_list) != 2)
7519               {
7520                 error_at (loc, "wrong number of arguments to "
7521                                "%<__builtin_complex%>");
7522                 expr.value = error_mark_node;
7523                 break;
7524               }
7525
7526             e1_p = &(*cexpr_list)[0];
7527             e2_p = &(*cexpr_list)[1];
7528
7529             *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
7530             if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
7531               e1_p->value = convert (TREE_TYPE (e1_p->value),
7532                                      TREE_OPERAND (e1_p->value, 0));
7533             *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7534             if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
7535               e2_p->value = convert (TREE_TYPE (e2_p->value),
7536                                      TREE_OPERAND (e2_p->value, 0));
7537             if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7538                 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7539                 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
7540                 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
7541               {
7542                 error_at (loc, "%<__builtin_complex%> operand "
7543                           "not of real binary floating-point type");
7544                 expr.value = error_mark_node;
7545                 break;
7546               }
7547             if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
7548                 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
7549               {
7550                 error_at (loc,
7551                           "%<__builtin_complex%> operands of different types");
7552                 expr.value = error_mark_node;
7553                 break;
7554               }
7555             pedwarn_c90 (loc, OPT_Wpedantic,
7556                          "ISO C90 does not support complex types");
7557             expr.value = build2 (COMPLEX_EXPR,
7558                                  build_complex_type
7559                                    (TYPE_MAIN_VARIANT
7560                                      (TREE_TYPE (e1_p->value))),
7561                                  e1_p->value, e2_p->value);
7562             break;
7563           }
7564         case RID_BUILTIN_SHUFFLE:
7565           {
7566             vec<c_expr_t, va_gc> *cexpr_list;
7567             unsigned int i;
7568             c_expr_t *p;
7569
7570             c_parser_consume_token (parser);
7571             if (!c_parser_get_builtin_args (parser,
7572                                             "__builtin_shuffle",
7573                                             &cexpr_list, false))
7574               {
7575                 expr.value = error_mark_node;
7576                 break;
7577               }
7578
7579             FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
7580               *p = convert_lvalue_to_rvalue (loc, *p, true, true);
7581
7582             if (vec_safe_length (cexpr_list) == 2)
7583               expr.value =
7584                 c_build_vec_perm_expr
7585                   (loc, (*cexpr_list)[0].value,
7586                    NULL_TREE, (*cexpr_list)[1].value);
7587
7588             else if (vec_safe_length (cexpr_list) == 3)
7589               expr.value =
7590                 c_build_vec_perm_expr
7591                   (loc, (*cexpr_list)[0].value,
7592                    (*cexpr_list)[1].value,
7593                    (*cexpr_list)[2].value);
7594             else
7595               {
7596                 error_at (loc, "wrong number of arguments to "
7597                                "%<__builtin_shuffle%>");
7598                 expr.value = error_mark_node;
7599               }
7600             break;
7601           }
7602         case RID_AT_SELECTOR:
7603           gcc_assert (c_dialect_objc ());
7604           c_parser_consume_token (parser);
7605           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7606             {
7607               expr.value = error_mark_node;
7608               break;
7609             }
7610           {
7611             tree sel = c_parser_objc_selector_arg (parser);
7612             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7613                                        "expected %<)%>");
7614             expr.value = objc_build_selector_expr (loc, sel);
7615           }
7616           break;
7617         case RID_AT_PROTOCOL:
7618           gcc_assert (c_dialect_objc ());
7619           c_parser_consume_token (parser);
7620           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7621             {
7622               expr.value = error_mark_node;
7623               break;
7624             }
7625           if (c_parser_next_token_is_not (parser, CPP_NAME))
7626             {
7627               c_parser_error (parser, "expected identifier");
7628               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7629               expr.value = error_mark_node;
7630               break;
7631             }
7632           {
7633             tree id = c_parser_peek_token (parser)->value;
7634             c_parser_consume_token (parser);
7635             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7636                                        "expected %<)%>");
7637             expr.value = objc_build_protocol_expr (id);
7638           }
7639           break;
7640         case RID_AT_ENCODE:
7641           /* Extension to support C-structures in the archiver.  */
7642           gcc_assert (c_dialect_objc ());
7643           c_parser_consume_token (parser);
7644           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7645             {
7646               expr.value = error_mark_node;
7647               break;
7648             }
7649           t1 = c_parser_type_name (parser);
7650           if (t1 == NULL)
7651             {
7652               expr.value = error_mark_node;
7653               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7654               break;
7655             }
7656           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7657                                      "expected %<)%>");
7658           {
7659             tree type = groktypename (t1, NULL, NULL);
7660             expr.value = objc_build_encode_expr (type);
7661           }
7662           break;
7663         case RID_GENERIC:
7664           expr = c_parser_generic_selection (parser);
7665           break;
7666         case RID_CILK_SPAWN:
7667           c_parser_consume_token (parser);
7668           if (!flag_cilkplus)
7669             {
7670               error_at (loc, "-fcilkplus must be enabled to use "
7671                         "%<_Cilk_spawn%>");
7672               expr = c_parser_postfix_expression (parser);
7673               expr.value = error_mark_node;           
7674             }
7675           else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7676             {
7677               error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
7678                         "are not permitted");
7679               /* Now flush out all the _Cilk_spawns.  */
7680               while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7681                 c_parser_consume_token (parser);
7682               expr = c_parser_postfix_expression (parser);
7683             }
7684           else
7685             {
7686               expr = c_parser_postfix_expression (parser);
7687               expr.value = build_cilk_spawn (loc, expr.value);
7688             }
7689           break; 
7690         default:
7691           c_parser_error (parser, "expected expression");
7692           expr.value = error_mark_node;
7693           break;
7694         }
7695       break;
7696     case CPP_OPEN_SQUARE:
7697       if (c_dialect_objc ())
7698         {
7699           tree receiver, args;
7700           c_parser_consume_token (parser);
7701           receiver = c_parser_objc_receiver (parser);
7702           args = c_parser_objc_message_args (parser);
7703           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7704                                      "expected %<]%>");
7705           expr.value = objc_build_message_expr (receiver, args);
7706           break;
7707         }
7708       /* Else fall through to report error.  */
7709     default:
7710       c_parser_error (parser, "expected expression");
7711       expr.value = error_mark_node;
7712       break;
7713     }
7714   return c_parser_postfix_expression_after_primary (parser, loc, expr);
7715 }
7716
7717 /* Parse a postfix expression after a parenthesized type name: the
7718    brace-enclosed initializer of a compound literal, possibly followed
7719    by some postfix operators.  This is separate because it is not
7720    possible to tell until after the type name whether a cast
7721    expression has a cast or a compound literal, or whether the operand
7722    of sizeof is a parenthesized type name or starts with a compound
7723    literal.  TYPE_LOC is the location where TYPE_NAME starts--the
7724    location of the first token after the parentheses around the type
7725    name.  */
7726
7727 static struct c_expr
7728 c_parser_postfix_expression_after_paren_type (c_parser *parser,
7729                                               struct c_type_name *type_name,
7730                                               location_t type_loc)
7731 {
7732   tree type;
7733   struct c_expr init;
7734   bool non_const;
7735   struct c_expr expr;
7736   location_t start_loc;
7737   tree type_expr = NULL_TREE;
7738   bool type_expr_const = true;
7739   check_compound_literal_type (type_loc, type_name);
7740   start_init (NULL_TREE, NULL, 0);
7741   type = groktypename (type_name, &type_expr, &type_expr_const);
7742   start_loc = c_parser_peek_token (parser)->location;
7743   if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
7744     {
7745       error_at (type_loc, "compound literal has variable size");
7746       type = error_mark_node;
7747     }
7748   init = c_parser_braced_init (parser, type, false);
7749   finish_init ();
7750   maybe_warn_string_init (type_loc, type, init);
7751
7752   if (type != error_mark_node
7753       && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
7754       && current_function_decl)
7755     {
7756       error ("compound literal qualified by address-space qualifier");
7757       type = error_mark_node;
7758     }
7759
7760   pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
7761   non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
7762                ? CONSTRUCTOR_NON_CONST (init.value)
7763                : init.original_code == C_MAYBE_CONST_EXPR);
7764   non_const |= !type_expr_const;
7765   expr.value = build_compound_literal (start_loc, type, init.value, non_const);
7766   expr.original_code = ERROR_MARK;
7767   expr.original_type = NULL;
7768   if (type_expr)
7769     {
7770       if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
7771         {
7772           gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
7773           C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
7774         }
7775       else
7776         {
7777           gcc_assert (!non_const);
7778           expr.value = build2 (C_MAYBE_CONST_EXPR, type,
7779                                type_expr, expr.value);
7780         }
7781     }
7782   return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
7783 }
7784
7785 /* Callback function for sizeof_pointer_memaccess_warning to compare
7786    types.  */
7787
7788 static bool
7789 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
7790 {
7791   return comptypes (type1, type2) == 1;
7792 }
7793
7794 /* Parse a postfix expression after the initial primary or compound
7795    literal; that is, parse a series of postfix operators.
7796
7797    EXPR_LOC is the location of the primary expression.  */
7798
7799 static struct c_expr
7800 c_parser_postfix_expression_after_primary (c_parser *parser,
7801                                            location_t expr_loc,
7802                                            struct c_expr expr)
7803 {
7804   struct c_expr orig_expr;
7805   tree ident, idx;
7806   location_t sizeof_arg_loc[3];
7807   tree sizeof_arg[3];
7808   unsigned int literal_zero_mask;
7809   unsigned int i;
7810   vec<tree, va_gc> *exprlist;
7811   vec<tree, va_gc> *origtypes = NULL;
7812   vec<location_t> arg_loc = vNULL;
7813
7814   while (true)
7815     {
7816       location_t op_loc = c_parser_peek_token (parser)->location;
7817       switch (c_parser_peek_token (parser)->type)
7818         {
7819         case CPP_OPEN_SQUARE:
7820           /* Array reference.  */
7821           c_parser_consume_token (parser);
7822           if (flag_cilkplus
7823               && c_parser_peek_token (parser)->type == CPP_COLON)
7824             /* If we are here, then we have something like this:
7825                Array [ : ]
7826             */
7827             expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE,
7828                                                   expr.value);
7829           else
7830             {         
7831               idx = c_parser_expression (parser).value;
7832               /* Here we have 3 options:
7833                  1. Array [EXPR] -- Normal Array call.
7834                  2. Array [EXPR : EXPR] -- Array notation without stride.
7835                  3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7836
7837                  For 1, we just handle it just like a normal array expression.
7838                  For 2 and 3 we handle it like we handle array notations.  The
7839                  idx value we have above becomes the initial/start index.
7840               */
7841               if (flag_cilkplus
7842                   && c_parser_peek_token (parser)->type == CPP_COLON)
7843                 expr.value = c_parser_array_notation (expr_loc, parser, idx, 
7844                                                       expr.value);
7845               else
7846                 {
7847                   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7848                                              "expected %<]%>");
7849                   expr.value = build_array_ref (op_loc, expr.value, idx);
7850                 }
7851             }
7852           expr.original_code = ERROR_MARK;
7853           expr.original_type = NULL;
7854           break;
7855         case CPP_OPEN_PAREN:
7856           /* Function call.  */
7857           c_parser_consume_token (parser);
7858           for (i = 0; i < 3; i++)
7859             {
7860               sizeof_arg[i] = NULL_TREE;
7861               sizeof_arg_loc[i] = UNKNOWN_LOCATION;
7862             }
7863           literal_zero_mask = 0;
7864           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7865             exprlist = NULL;
7866           else
7867             exprlist = c_parser_expr_list (parser, true, false, &origtypes,
7868                                            sizeof_arg_loc, sizeof_arg,
7869                                            &arg_loc, &literal_zero_mask);
7870           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7871                                      "expected %<)%>");
7872           orig_expr = expr;
7873           mark_exp_read (expr.value);
7874           if (warn_sizeof_pointer_memaccess)
7875             sizeof_pointer_memaccess_warning (sizeof_arg_loc,
7876                                               expr.value, exprlist,
7877                                               sizeof_arg,
7878                                               sizeof_ptr_memacc_comptypes);
7879           if (warn_memset_transposed_args
7880               && TREE_CODE (expr.value) == FUNCTION_DECL
7881               && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
7882               && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
7883               && vec_safe_length (exprlist) == 3
7884               && integer_zerop ((*exprlist)[2])
7885               && (literal_zero_mask & (1 << 2)) != 0
7886               && (!integer_zerop ((*exprlist)[1])
7887                   || (literal_zero_mask & (1 << 1)) == 0))
7888             warning_at (expr_loc, OPT_Wmemset_transposed_args,
7889                         "%<memset%> used with constant zero length parameter; "
7890                         "this could be due to transposed parameters");
7891
7892           expr.value
7893             = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
7894                                          exprlist, origtypes);
7895           expr.original_code = ERROR_MARK;
7896           if (TREE_CODE (expr.value) == INTEGER_CST
7897               && TREE_CODE (orig_expr.value) == FUNCTION_DECL
7898               && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
7899               && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
7900             expr.original_code = C_MAYBE_CONST_EXPR;
7901           expr.original_type = NULL;
7902           if (exprlist)
7903             {
7904               release_tree_vector (exprlist);
7905               release_tree_vector (origtypes);
7906             }
7907           arg_loc.release ();
7908           break;
7909         case CPP_DOT:
7910           /* Structure element reference.  */
7911           c_parser_consume_token (parser);
7912           expr = default_function_array_conversion (expr_loc, expr);
7913           if (c_parser_next_token_is (parser, CPP_NAME))
7914             ident = c_parser_peek_token (parser)->value;
7915           else
7916             {
7917               c_parser_error (parser, "expected identifier");
7918               expr.value = error_mark_node;
7919               expr.original_code = ERROR_MARK;
7920               expr.original_type = NULL;
7921               return expr;
7922             }
7923           c_parser_consume_token (parser);
7924           expr.value = build_component_ref (op_loc, expr.value, ident);
7925           expr.original_code = ERROR_MARK;
7926           if (TREE_CODE (expr.value) != COMPONENT_REF)
7927             expr.original_type = NULL;
7928           else
7929             {
7930               /* Remember the original type of a bitfield.  */
7931               tree field = TREE_OPERAND (expr.value, 1);
7932               if (TREE_CODE (field) != FIELD_DECL)
7933                 expr.original_type = NULL;
7934               else
7935                 expr.original_type = DECL_BIT_FIELD_TYPE (field);
7936             }
7937           break;
7938         case CPP_DEREF:
7939           /* Structure element reference.  */
7940           c_parser_consume_token (parser);
7941           expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
7942           if (c_parser_next_token_is (parser, CPP_NAME))
7943             ident = c_parser_peek_token (parser)->value;
7944           else
7945             {
7946               c_parser_error (parser, "expected identifier");
7947               expr.value = error_mark_node;
7948               expr.original_code = ERROR_MARK;
7949               expr.original_type = NULL;
7950               return expr;
7951             }
7952           c_parser_consume_token (parser);
7953           expr.value = build_component_ref (op_loc,
7954                                             build_indirect_ref (op_loc,
7955                                                                 expr.value,
7956                                                                 RO_ARROW),
7957                                             ident);
7958           expr.original_code = ERROR_MARK;
7959           if (TREE_CODE (expr.value) != COMPONENT_REF)
7960             expr.original_type = NULL;
7961           else
7962             {
7963               /* Remember the original type of a bitfield.  */
7964               tree field = TREE_OPERAND (expr.value, 1);
7965               if (TREE_CODE (field) != FIELD_DECL)
7966                 expr.original_type = NULL;
7967               else
7968                 expr.original_type = DECL_BIT_FIELD_TYPE (field);
7969             }
7970           break;
7971         case CPP_PLUS_PLUS:
7972           /* Postincrement.  */
7973           c_parser_consume_token (parser);
7974           /* If the expressions have array notations, we expand them.  */
7975           if (flag_cilkplus
7976               && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
7977             expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr);
7978           else
7979             {
7980               expr = default_function_array_read_conversion (expr_loc, expr);
7981               expr.value = build_unary_op (op_loc,
7982                                            POSTINCREMENT_EXPR, expr.value, 0);
7983             }
7984           expr.original_code = ERROR_MARK;
7985           expr.original_type = NULL;
7986           break;
7987         case CPP_MINUS_MINUS:
7988           /* Postdecrement.  */
7989           c_parser_consume_token (parser);
7990           /* If the expressions have array notations, we expand them.  */
7991           if (flag_cilkplus
7992               && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
7993             expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr);
7994           else
7995             {
7996               expr = default_function_array_read_conversion (expr_loc, expr);
7997               expr.value = build_unary_op (op_loc,
7998                                            POSTDECREMENT_EXPR, expr.value, 0);
7999             }
8000           expr.original_code = ERROR_MARK;
8001           expr.original_type = NULL;
8002           break;
8003         default:
8004           return expr;
8005         }
8006     }
8007 }
8008
8009 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8010
8011    expression:
8012      assignment-expression
8013      expression , assignment-expression
8014 */
8015
8016 static struct c_expr
8017 c_parser_expression (c_parser *parser)
8018 {
8019   location_t tloc = c_parser_peek_token (parser)->location;
8020   struct c_expr expr;
8021   expr = c_parser_expr_no_commas (parser, NULL);
8022   if (c_parser_next_token_is (parser, CPP_COMMA))
8023     expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
8024   while (c_parser_next_token_is (parser, CPP_COMMA))
8025     {
8026       struct c_expr next;
8027       tree lhsval;
8028       location_t loc = c_parser_peek_token (parser)->location;
8029       location_t expr_loc;
8030       c_parser_consume_token (parser);
8031       expr_loc = c_parser_peek_token (parser)->location;
8032       lhsval = expr.value;
8033       while (TREE_CODE (lhsval) == COMPOUND_EXPR)
8034         lhsval = TREE_OPERAND (lhsval, 1);
8035       if (DECL_P (lhsval) || handled_component_p (lhsval))
8036         mark_exp_read (lhsval);
8037       next = c_parser_expr_no_commas (parser, NULL);
8038       next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
8039       expr.value = build_compound_expr (loc, expr.value, next.value);
8040       expr.original_code = COMPOUND_EXPR;
8041       expr.original_type = next.original_type;
8042     }
8043   return expr;
8044 }
8045
8046 /* Parse an expression and convert functions or arrays to pointers and
8047    lvalues to rvalues.  */
8048
8049 static struct c_expr
8050 c_parser_expression_conv (c_parser *parser)
8051 {
8052   struct c_expr expr;
8053   location_t loc = c_parser_peek_token (parser)->location;
8054   expr = c_parser_expression (parser);
8055   expr = convert_lvalue_to_rvalue (loc, expr, true, false);
8056   return expr;
8057 }
8058
8059 /* Helper function of c_parser_expr_list.  Check if IDXth (0 based)
8060    argument is a literal zero alone and if so, set it in literal_zero_mask.  */
8061
8062 static inline void
8063 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
8064                              unsigned int idx)
8065 {
8066   if (idx >= HOST_BITS_PER_INT)
8067     return;
8068
8069   c_token *tok = c_parser_peek_token (parser);
8070   switch (tok->type)
8071     {
8072     case CPP_NUMBER:
8073     case CPP_CHAR:
8074     case CPP_WCHAR:
8075     case CPP_CHAR16:
8076     case CPP_CHAR32:
8077       /* If a parameter is literal zero alone, remember it
8078          for -Wmemset-transposed-args warning.  */
8079       if (integer_zerop (tok->value)
8080           && !TREE_OVERFLOW (tok->value)
8081           && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8082               || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
8083         *literal_zero_mask |= 1U << idx;
8084     default:
8085       break;
8086     }
8087 }
8088
8089 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
8090    functions and arrays to pointers and lvalues to rvalues.  If
8091    FOLD_P, fold the expressions.  If LOCATIONS is non-NULL, save the
8092    locations of function arguments into this vector.
8093
8094    nonempty-expr-list:
8095      assignment-expression
8096      nonempty-expr-list , assignment-expression
8097 */
8098
8099 static vec<tree, va_gc> *
8100 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
8101                     vec<tree, va_gc> **p_orig_types,
8102                     location_t *sizeof_arg_loc, tree *sizeof_arg,
8103                     vec<location_t> *locations,
8104                     unsigned int *literal_zero_mask)
8105 {
8106   vec<tree, va_gc> *ret;
8107   vec<tree, va_gc> *orig_types;
8108   struct c_expr expr;
8109   location_t loc = c_parser_peek_token (parser)->location;
8110   location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8111   unsigned int idx = 0;
8112
8113   ret = make_tree_vector ();
8114   if (p_orig_types == NULL)
8115     orig_types = NULL;
8116   else
8117     orig_types = make_tree_vector ();
8118
8119   if (sizeof_arg != NULL
8120       && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8121     cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8122   if (literal_zero_mask)
8123     c_parser_check_literal_zero (parser, literal_zero_mask, 0);
8124   expr = c_parser_expr_no_commas (parser, NULL);
8125   if (convert_p)
8126     expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8127   if (fold_p)
8128     expr.value = c_fully_fold (expr.value, false, NULL);
8129   ret->quick_push (expr.value);
8130   if (orig_types)
8131     orig_types->quick_push (expr.original_type);
8132   if (locations)
8133     locations->safe_push (loc);
8134   if (sizeof_arg != NULL
8135       && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8136       && expr.original_code == SIZEOF_EXPR)
8137     {
8138       sizeof_arg[0] = c_last_sizeof_arg;
8139       sizeof_arg_loc[0] = cur_sizeof_arg_loc;
8140     }
8141   while (c_parser_next_token_is (parser, CPP_COMMA))
8142     {
8143       c_parser_consume_token (parser);
8144       loc = c_parser_peek_token (parser)->location;
8145       if (sizeof_arg != NULL
8146           && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8147         cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8148       else
8149         cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8150       if (literal_zero_mask)
8151         c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
8152       expr = c_parser_expr_no_commas (parser, NULL);
8153       if (convert_p)
8154         expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8155       if (fold_p)
8156         expr.value = c_fully_fold (expr.value, false, NULL);
8157       vec_safe_push (ret, expr.value);
8158       if (orig_types)
8159         vec_safe_push (orig_types, expr.original_type);
8160       if (locations)
8161         locations->safe_push (loc);
8162       if (++idx < 3
8163           && sizeof_arg != NULL
8164           && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8165           && expr.original_code == SIZEOF_EXPR)
8166         {
8167           sizeof_arg[idx] = c_last_sizeof_arg;
8168           sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
8169         }
8170     }
8171   if (orig_types)
8172     *p_orig_types = orig_types;
8173   return ret;
8174 }
8175 \f
8176 /* Parse Objective-C-specific constructs.  */
8177
8178 /* Parse an objc-class-definition.
8179
8180    objc-class-definition:
8181      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8182        objc-class-instance-variables[opt] objc-methodprotolist @end
8183      @implementation identifier objc-superclass[opt]
8184        objc-class-instance-variables[opt]
8185      @interface identifier ( identifier ) objc-protocol-refs[opt]
8186        objc-methodprotolist @end
8187      @interface identifier ( ) objc-protocol-refs[opt]
8188        objc-methodprotolist @end
8189      @implementation identifier ( identifier )
8190
8191    objc-superclass:
8192      : identifier
8193
8194    "@interface identifier (" must start "@interface identifier (
8195    identifier ) ...": objc-methodprotolist in the first production may
8196    not start with a parenthesized identifier as a declarator of a data
8197    definition with no declaration specifiers if the objc-superclass,
8198    objc-protocol-refs and objc-class-instance-variables are omitted.  */
8199
8200 static void
8201 c_parser_objc_class_definition (c_parser *parser, tree attributes)
8202 {
8203   bool iface_p;
8204   tree id1;
8205   tree superclass;
8206   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
8207     iface_p = true;
8208   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
8209     iface_p = false;
8210   else
8211     gcc_unreachable ();
8212
8213   c_parser_consume_token (parser);
8214   if (c_parser_next_token_is_not (parser, CPP_NAME))
8215     {
8216       c_parser_error (parser, "expected identifier");
8217       return;
8218     }
8219   id1 = c_parser_peek_token (parser)->value;
8220   c_parser_consume_token (parser);
8221   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8222     {
8223       /* We have a category or class extension.  */
8224       tree id2;
8225       tree proto = NULL_TREE;
8226       c_parser_consume_token (parser);
8227       if (c_parser_next_token_is_not (parser, CPP_NAME))
8228         {
8229           if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8230             {
8231               /* We have a class extension.  */
8232               id2 = NULL_TREE;
8233             }
8234           else
8235             {
8236               c_parser_error (parser, "expected identifier or %<)%>");
8237               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8238               return;
8239             }
8240         }
8241       else
8242         {
8243           id2 = c_parser_peek_token (parser)->value;
8244           c_parser_consume_token (parser);
8245         }
8246       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8247       if (!iface_p)
8248         {
8249           objc_start_category_implementation (id1, id2);
8250           return;
8251         }
8252       if (c_parser_next_token_is (parser, CPP_LESS))
8253         proto = c_parser_objc_protocol_refs (parser);
8254       objc_start_category_interface (id1, id2, proto, attributes);
8255       c_parser_objc_methodprotolist (parser);
8256       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8257       objc_finish_interface ();
8258       return;
8259     }
8260   if (c_parser_next_token_is (parser, CPP_COLON))
8261     {
8262       c_parser_consume_token (parser);
8263       if (c_parser_next_token_is_not (parser, CPP_NAME))
8264         {
8265           c_parser_error (parser, "expected identifier");
8266           return;
8267         }
8268       superclass = c_parser_peek_token (parser)->value;
8269       c_parser_consume_token (parser);
8270     }
8271   else
8272     superclass = NULL_TREE;
8273   if (iface_p)
8274     {
8275       tree proto = NULL_TREE;
8276       if (c_parser_next_token_is (parser, CPP_LESS))
8277         proto = c_parser_objc_protocol_refs (parser);
8278       objc_start_class_interface (id1, superclass, proto, attributes);
8279     }
8280   else
8281     objc_start_class_implementation (id1, superclass);
8282   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8283     c_parser_objc_class_instance_variables (parser);
8284   if (iface_p)
8285     {
8286       objc_continue_interface ();
8287       c_parser_objc_methodprotolist (parser);
8288       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8289       objc_finish_interface ();
8290     }
8291   else
8292     {
8293       objc_continue_implementation ();
8294       return;
8295     }
8296 }
8297
8298 /* Parse objc-class-instance-variables.
8299
8300    objc-class-instance-variables:
8301      { objc-instance-variable-decl-list[opt] }
8302
8303    objc-instance-variable-decl-list:
8304      objc-visibility-spec
8305      objc-instance-variable-decl ;
8306      ;
8307      objc-instance-variable-decl-list objc-visibility-spec
8308      objc-instance-variable-decl-list objc-instance-variable-decl ;
8309      objc-instance-variable-decl-list ;
8310
8311    objc-visibility-spec:
8312      @private
8313      @protected
8314      @public
8315
8316    objc-instance-variable-decl:
8317      struct-declaration
8318 */
8319
8320 static void
8321 c_parser_objc_class_instance_variables (c_parser *parser)
8322 {
8323   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
8324   c_parser_consume_token (parser);
8325   while (c_parser_next_token_is_not (parser, CPP_EOF))
8326     {
8327       tree decls;
8328       /* Parse any stray semicolon.  */
8329       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8330         {
8331           pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8332                    "extra semicolon");
8333           c_parser_consume_token (parser);
8334           continue;
8335         }
8336       /* Stop if at the end of the instance variables.  */
8337       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8338         {
8339           c_parser_consume_token (parser);
8340           break;
8341         }
8342       /* Parse any objc-visibility-spec.  */
8343       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
8344         {
8345           c_parser_consume_token (parser);
8346           objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
8347           continue;
8348         }
8349       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
8350         {
8351           c_parser_consume_token (parser);
8352           objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
8353           continue;
8354         }
8355       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
8356         {
8357           c_parser_consume_token (parser);
8358           objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
8359           continue;
8360         }
8361       else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
8362         {
8363           c_parser_consume_token (parser);
8364           objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
8365           continue;
8366         }
8367       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
8368         {
8369           c_parser_pragma (parser, pragma_external);
8370           continue;
8371         }
8372
8373       /* Parse some comma-separated declarations.  */
8374       decls = c_parser_struct_declaration (parser);
8375       if (decls == NULL)
8376         {
8377           /* There is a syntax error.  We want to skip the offending
8378              tokens up to the next ';' (included) or '}'
8379              (excluded).  */
8380           
8381           /* First, skip manually a ')' or ']'.  This is because they
8382              reduce the nesting level, so c_parser_skip_until_found()
8383              wouldn't be able to skip past them.  */
8384           c_token *token = c_parser_peek_token (parser);
8385           if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
8386             c_parser_consume_token (parser);
8387
8388           /* Then, do the standard skipping.  */
8389           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8390
8391           /* We hopefully recovered.  Start normal parsing again.  */
8392           parser->error = false;
8393           continue;
8394         }
8395       else
8396         {
8397           /* Comma-separated instance variables are chained together
8398              in reverse order; add them one by one.  */
8399           tree ivar = nreverse (decls);
8400           for (; ivar; ivar = DECL_CHAIN (ivar))
8401             objc_add_instance_variable (copy_node (ivar));
8402         }
8403       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8404     }
8405 }
8406
8407 /* Parse an objc-class-declaration.
8408
8409    objc-class-declaration:
8410      @class identifier-list ;
8411 */
8412
8413 static void
8414 c_parser_objc_class_declaration (c_parser *parser)
8415 {
8416   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
8417   c_parser_consume_token (parser);
8418   /* Any identifiers, including those declared as type names, are OK
8419      here.  */
8420   while (true)
8421     {
8422       tree id;
8423       if (c_parser_next_token_is_not (parser, CPP_NAME))
8424         {
8425           c_parser_error (parser, "expected identifier");
8426           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8427           parser->error = false;
8428           return;
8429         }
8430       id = c_parser_peek_token (parser)->value;
8431       objc_declare_class (id);
8432       c_parser_consume_token (parser);
8433       if (c_parser_next_token_is (parser, CPP_COMMA))
8434         c_parser_consume_token (parser);
8435       else
8436         break;
8437     }
8438   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8439 }
8440
8441 /* Parse an objc-alias-declaration.
8442
8443    objc-alias-declaration:
8444      @compatibility_alias identifier identifier ;
8445 */
8446
8447 static void
8448 c_parser_objc_alias_declaration (c_parser *parser)
8449 {
8450   tree id1, id2;
8451   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
8452   c_parser_consume_token (parser);
8453   if (c_parser_next_token_is_not (parser, CPP_NAME))
8454     {
8455       c_parser_error (parser, "expected identifier");
8456       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8457       return;
8458     }
8459   id1 = c_parser_peek_token (parser)->value;
8460   c_parser_consume_token (parser);
8461   if (c_parser_next_token_is_not (parser, CPP_NAME))
8462     {
8463       c_parser_error (parser, "expected identifier");
8464       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8465       return;
8466     }
8467   id2 = c_parser_peek_token (parser)->value;
8468   c_parser_consume_token (parser);
8469   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8470   objc_declare_alias (id1, id2);
8471 }
8472
8473 /* Parse an objc-protocol-definition.
8474
8475    objc-protocol-definition:
8476      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8477      @protocol identifier-list ;
8478
8479    "@protocol identifier ;" should be resolved as "@protocol
8480    identifier-list ;": objc-methodprotolist may not start with a
8481    semicolon in the first alternative if objc-protocol-refs are
8482    omitted.  */
8483
8484 static void
8485 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
8486 {
8487   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
8488
8489   c_parser_consume_token (parser);
8490   if (c_parser_next_token_is_not (parser, CPP_NAME))
8491     {
8492       c_parser_error (parser, "expected identifier");
8493       return;
8494     }
8495   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8496       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
8497     {
8498       /* Any identifiers, including those declared as type names, are
8499          OK here.  */
8500       while (true)
8501         {
8502           tree id;
8503           if (c_parser_next_token_is_not (parser, CPP_NAME))
8504             {
8505               c_parser_error (parser, "expected identifier");
8506               break;
8507             }
8508           id = c_parser_peek_token (parser)->value;
8509           objc_declare_protocol (id, attributes);
8510           c_parser_consume_token (parser);
8511           if (c_parser_next_token_is (parser, CPP_COMMA))
8512             c_parser_consume_token (parser);
8513           else
8514             break;
8515         }
8516       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8517     }
8518   else
8519     {
8520       tree id = c_parser_peek_token (parser)->value;
8521       tree proto = NULL_TREE;
8522       c_parser_consume_token (parser);
8523       if (c_parser_next_token_is (parser, CPP_LESS))
8524         proto = c_parser_objc_protocol_refs (parser);
8525       parser->objc_pq_context = true;
8526       objc_start_protocol (id, proto, attributes);
8527       c_parser_objc_methodprotolist (parser);
8528       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8529       parser->objc_pq_context = false;
8530       objc_finish_interface ();
8531     }
8532 }
8533
8534 /* Parse an objc-method-type.
8535
8536    objc-method-type:
8537      +
8538      -
8539
8540    Return true if it is a class method (+) and false if it is
8541    an instance method (-).
8542 */
8543 static inline bool
8544 c_parser_objc_method_type (c_parser *parser)
8545 {
8546   switch (c_parser_peek_token (parser)->type)
8547     {
8548     case CPP_PLUS:
8549       c_parser_consume_token (parser);
8550       return true;
8551     case CPP_MINUS:
8552       c_parser_consume_token (parser);
8553       return false;
8554     default:
8555       gcc_unreachable ();
8556     }
8557 }
8558
8559 /* Parse an objc-method-definition.
8560
8561    objc-method-definition:
8562      objc-method-type objc-method-decl ;[opt] compound-statement
8563 */
8564
8565 static void
8566 c_parser_objc_method_definition (c_parser *parser)
8567 {
8568   bool is_class_method = c_parser_objc_method_type (parser);
8569   tree decl, attributes = NULL_TREE, expr = NULL_TREE;
8570   parser->objc_pq_context = true;
8571   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8572                                     &expr);
8573   if (decl == error_mark_node)
8574     return;  /* Bail here. */
8575
8576   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8577     {
8578       c_parser_consume_token (parser);
8579       pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8580                "extra semicolon in method definition specified");
8581     }
8582
8583   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8584     {
8585       c_parser_error (parser, "expected %<{%>");
8586       return;
8587     }
8588
8589   parser->objc_pq_context = false;
8590   if (objc_start_method_definition (is_class_method, decl, attributes, expr))
8591     {
8592       add_stmt (c_parser_compound_statement (parser));
8593       objc_finish_method_definition (current_function_decl);
8594     }
8595   else
8596     {
8597       /* This code is executed when we find a method definition
8598          outside of an @implementation context (or invalid for other
8599          reasons).  Parse the method (to keep going) but do not emit
8600          any code.
8601       */
8602       c_parser_compound_statement (parser);
8603     }
8604 }
8605
8606 /* Parse an objc-methodprotolist.
8607
8608    objc-methodprotolist:
8609      empty
8610      objc-methodprotolist objc-methodproto
8611      objc-methodprotolist declaration
8612      objc-methodprotolist ;
8613      @optional
8614      @required
8615
8616    The declaration is a data definition, which may be missing
8617    declaration specifiers under the same rules and diagnostics as
8618    other data definitions outside functions, and the stray semicolon
8619    is diagnosed the same way as a stray semicolon outside a
8620    function.  */
8621
8622 static void
8623 c_parser_objc_methodprotolist (c_parser *parser)
8624 {
8625   while (true)
8626     {
8627       /* The list is terminated by @end.  */
8628       switch (c_parser_peek_token (parser)->type)
8629         {
8630         case CPP_SEMICOLON:
8631           pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8632                    "ISO C does not allow extra %<;%> outside of a function");
8633           c_parser_consume_token (parser);
8634           break;
8635         case CPP_PLUS:
8636         case CPP_MINUS:
8637           c_parser_objc_methodproto (parser);
8638           break;
8639         case CPP_PRAGMA:
8640           c_parser_pragma (parser, pragma_external);
8641           break;
8642         case CPP_EOF:
8643           return;
8644         default:
8645           if (c_parser_next_token_is_keyword (parser, RID_AT_END))
8646             return;
8647           else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
8648             c_parser_objc_at_property_declaration (parser);
8649           else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
8650             {
8651               objc_set_method_opt (true);
8652               c_parser_consume_token (parser);
8653             }
8654           else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
8655             {
8656               objc_set_method_opt (false);
8657               c_parser_consume_token (parser);
8658             }
8659           else
8660             c_parser_declaration_or_fndef (parser, false, false, true,
8661                                            false, true, NULL, vNULL);
8662           break;
8663         }
8664     }
8665 }
8666
8667 /* Parse an objc-methodproto.
8668
8669    objc-methodproto:
8670      objc-method-type objc-method-decl ;
8671 */
8672
8673 static void
8674 c_parser_objc_methodproto (c_parser *parser)
8675 {
8676   bool is_class_method = c_parser_objc_method_type (parser);
8677   tree decl, attributes = NULL_TREE;
8678
8679   /* Remember protocol qualifiers in prototypes.  */
8680   parser->objc_pq_context = true;
8681   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8682                                     NULL);
8683   /* Forget protocol qualifiers now.  */
8684   parser->objc_pq_context = false;
8685
8686   /* Do not allow the presence of attributes to hide an erroneous 
8687      method implementation in the interface section.  */
8688   if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
8689     {
8690       c_parser_error (parser, "expected %<;%>");
8691       return;
8692     }
8693   
8694   if (decl != error_mark_node)
8695     objc_add_method_declaration (is_class_method, decl, attributes);
8696
8697   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8698 }
8699
8700 /* If we are at a position that method attributes may be present, check that 
8701    there are not any parsed already (a syntax error) and then collect any 
8702    specified at the current location.  Finally, if new attributes were present,
8703    check that the next token is legal ( ';' for decls and '{' for defs).  */
8704    
8705 static bool 
8706 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
8707 {
8708   bool bad = false;
8709   if (*attributes)
8710     {
8711       c_parser_error (parser, 
8712                     "method attributes must be specified at the end only");
8713       *attributes = NULL_TREE;
8714       bad = true;
8715     }
8716
8717   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8718     *attributes = c_parser_attributes (parser);
8719
8720   /* If there were no attributes here, just report any earlier error.  */
8721   if (*attributes == NULL_TREE || bad)
8722     return bad;
8723
8724   /* If the attributes are followed by a ; or {, then just report any earlier
8725      error.  */
8726   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
8727       || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8728     return bad;
8729
8730   /* We've got attributes, but not at the end.  */
8731   c_parser_error (parser, 
8732                   "expected %<;%> or %<{%> after method attribute definition");
8733   return true;
8734 }
8735
8736 /* Parse an objc-method-decl.
8737
8738    objc-method-decl:
8739      ( objc-type-name ) objc-selector
8740      objc-selector
8741      ( objc-type-name ) objc-keyword-selector objc-optparmlist
8742      objc-keyword-selector objc-optparmlist
8743      attributes
8744
8745    objc-keyword-selector:
8746      objc-keyword-decl
8747      objc-keyword-selector objc-keyword-decl
8748
8749    objc-keyword-decl:
8750      objc-selector : ( objc-type-name ) identifier
8751      objc-selector : identifier
8752      : ( objc-type-name ) identifier
8753      : identifier
8754
8755    objc-optparmlist:
8756      objc-optparms objc-optellipsis
8757
8758    objc-optparms:
8759      empty
8760      objc-opt-parms , parameter-declaration
8761
8762    objc-optellipsis:
8763      empty
8764      , ...
8765 */
8766
8767 static tree
8768 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
8769                            tree *attributes, tree *expr)
8770 {
8771   tree type = NULL_TREE;
8772   tree sel;
8773   tree parms = NULL_TREE;
8774   bool ellipsis = false;
8775   bool attr_err = false;
8776
8777   *attributes = NULL_TREE;
8778   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8779     {
8780       c_parser_consume_token (parser);
8781       type = c_parser_objc_type_name (parser);
8782       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8783     }
8784   sel = c_parser_objc_selector (parser);
8785   /* If there is no selector, or a colon follows, we have an
8786      objc-keyword-selector.  If there is a selector, and a colon does
8787      not follow, that selector ends the objc-method-decl.  */
8788   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
8789     {
8790       tree tsel = sel;
8791       tree list = NULL_TREE;
8792       while (true)
8793         {
8794           tree atype = NULL_TREE, id, keyworddecl;
8795           tree param_attr = NULL_TREE;
8796           if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8797             break;
8798           if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8799             {
8800               c_parser_consume_token (parser);
8801               atype = c_parser_objc_type_name (parser);
8802               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8803                                          "expected %<)%>");
8804             }
8805           /* New ObjC allows attributes on method parameters.  */
8806           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8807             param_attr = c_parser_attributes (parser);
8808           if (c_parser_next_token_is_not (parser, CPP_NAME))
8809             {
8810               c_parser_error (parser, "expected identifier");
8811               return error_mark_node;
8812             }
8813           id = c_parser_peek_token (parser)->value;
8814           c_parser_consume_token (parser);
8815           keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
8816           list = chainon (list, keyworddecl);
8817           tsel = c_parser_objc_selector (parser);
8818           if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
8819             break;
8820         }
8821
8822       attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8823
8824       /* Parse the optional parameter list.  Optional Objective-C
8825          method parameters follow the C syntax, and may include '...'
8826          to denote a variable number of arguments.  */
8827       parms = make_node (TREE_LIST);
8828       while (c_parser_next_token_is (parser, CPP_COMMA))
8829         {
8830           struct c_parm *parm;
8831           c_parser_consume_token (parser);
8832           if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8833             {
8834               ellipsis = true;
8835               c_parser_consume_token (parser);
8836               attr_err |= c_parser_objc_maybe_method_attributes 
8837                                                 (parser, attributes) ;
8838               break;
8839             }
8840           parm = c_parser_parameter_declaration (parser, NULL_TREE);
8841           if (parm == NULL)
8842             break;
8843           parms = chainon (parms,
8844                            build_tree_list (NULL_TREE, grokparm (parm, expr)));
8845         }
8846       sel = list;
8847     }
8848   else
8849     attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8850
8851   if (sel == NULL)
8852     {
8853       c_parser_error (parser, "objective-c method declaration is expected");
8854       return error_mark_node;
8855     }
8856
8857   if (attr_err)
8858     return error_mark_node;
8859
8860   return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
8861 }
8862
8863 /* Parse an objc-type-name.
8864
8865    objc-type-name:
8866      objc-type-qualifiers[opt] type-name
8867      objc-type-qualifiers[opt]
8868
8869    objc-type-qualifiers:
8870      objc-type-qualifier
8871      objc-type-qualifiers objc-type-qualifier
8872
8873    objc-type-qualifier: one of
8874      in out inout bycopy byref oneway
8875 */
8876
8877 static tree
8878 c_parser_objc_type_name (c_parser *parser)
8879 {
8880   tree quals = NULL_TREE;
8881   struct c_type_name *type_name = NULL;
8882   tree type = NULL_TREE;
8883   while (true)
8884     {
8885       c_token *token = c_parser_peek_token (parser);
8886       if (token->type == CPP_KEYWORD
8887           && (token->keyword == RID_IN
8888               || token->keyword == RID_OUT
8889               || token->keyword == RID_INOUT
8890               || token->keyword == RID_BYCOPY
8891               || token->keyword == RID_BYREF
8892               || token->keyword == RID_ONEWAY))
8893         {
8894           quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
8895           c_parser_consume_token (parser);
8896         }
8897       else
8898         break;
8899     }
8900   if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
8901     type_name = c_parser_type_name (parser);
8902   if (type_name)
8903     type = groktypename (type_name, NULL, NULL);
8904
8905   /* If the type is unknown, and error has already been produced and
8906      we need to recover from the error.  In that case, use NULL_TREE
8907      for the type, as if no type had been specified; this will use the
8908      default type ('id') which is good for error recovery.  */
8909   if (type == error_mark_node)
8910     type = NULL_TREE;
8911
8912   return build_tree_list (quals, type);
8913 }
8914
8915 /* Parse objc-protocol-refs.
8916
8917    objc-protocol-refs:
8918      < identifier-list >
8919 */
8920
8921 static tree
8922 c_parser_objc_protocol_refs (c_parser *parser)
8923 {
8924   tree list = NULL_TREE;
8925   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
8926   c_parser_consume_token (parser);
8927   /* Any identifiers, including those declared as type names, are OK
8928      here.  */
8929   while (true)
8930     {
8931       tree id;
8932       if (c_parser_next_token_is_not (parser, CPP_NAME))
8933         {
8934           c_parser_error (parser, "expected identifier");
8935           break;
8936         }
8937       id = c_parser_peek_token (parser)->value;
8938       list = chainon (list, build_tree_list (NULL_TREE, id));
8939       c_parser_consume_token (parser);
8940       if (c_parser_next_token_is (parser, CPP_COMMA))
8941         c_parser_consume_token (parser);
8942       else
8943         break;
8944     }
8945   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
8946   return list;
8947 }
8948
8949 /* Parse an objc-try-catch-finally-statement.
8950
8951    objc-try-catch-finally-statement:
8952      @try compound-statement objc-catch-list[opt]
8953      @try compound-statement objc-catch-list[opt] @finally compound-statement
8954
8955    objc-catch-list:
8956      @catch ( objc-catch-parameter-declaration ) compound-statement
8957      objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8958
8959    objc-catch-parameter-declaration:
8960      parameter-declaration
8961      '...'
8962
8963    where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8964
8965    PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8966    for C++.  Keep them in sync.  */   
8967
8968 static void
8969 c_parser_objc_try_catch_finally_statement (c_parser *parser)
8970 {
8971   location_t location;
8972   tree stmt;
8973
8974   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
8975   c_parser_consume_token (parser);
8976   location = c_parser_peek_token (parser)->location;
8977   objc_maybe_warn_exceptions (location);
8978   stmt = c_parser_compound_statement (parser);
8979   objc_begin_try_stmt (location, stmt);
8980
8981   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
8982     {
8983       struct c_parm *parm;
8984       tree parameter_declaration = error_mark_node;
8985       bool seen_open_paren = false;
8986
8987       c_parser_consume_token (parser);
8988       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8989         seen_open_paren = true;
8990       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8991         {
8992           /* We have "@catch (...)" (where the '...' are literally
8993              what is in the code).  Skip the '...'.
8994              parameter_declaration is set to NULL_TREE, and
8995              objc_being_catch_clauses() knows that that means
8996              '...'.  */
8997           c_parser_consume_token (parser);
8998           parameter_declaration = NULL_TREE;
8999         }
9000       else
9001         {
9002           /* We have "@catch (NSException *exception)" or something
9003              like that.  Parse the parameter declaration.  */
9004           parm = c_parser_parameter_declaration (parser, NULL_TREE);
9005           if (parm == NULL)
9006             parameter_declaration = error_mark_node;
9007           else
9008             parameter_declaration = grokparm (parm, NULL);
9009         }
9010       if (seen_open_paren)
9011         c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9012       else
9013         {
9014           /* If there was no open parenthesis, we are recovering from
9015              an error, and we are trying to figure out what mistake
9016              the user has made.  */
9017
9018           /* If there is an immediate closing parenthesis, the user
9019              probably forgot the opening one (ie, they typed "@catch
9020              NSException *e)".  Parse the closing parenthesis and keep
9021              going.  */
9022           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9023             c_parser_consume_token (parser);
9024           
9025           /* If these is no immediate closing parenthesis, the user
9026              probably doesn't know that parenthesis are required at
9027              all (ie, they typed "@catch NSException *e").  So, just
9028              forget about the closing parenthesis and keep going.  */
9029         }
9030       objc_begin_catch_clause (parameter_declaration);
9031       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9032         c_parser_compound_statement_nostart (parser);
9033       objc_finish_catch_clause ();
9034     }
9035   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
9036     {
9037       c_parser_consume_token (parser);
9038       location = c_parser_peek_token (parser)->location;
9039       stmt = c_parser_compound_statement (parser);
9040       objc_build_finally_clause (location, stmt);
9041     }
9042   objc_finish_try_stmt ();
9043 }
9044
9045 /* Parse an objc-synchronized-statement.
9046
9047    objc-synchronized-statement:
9048      @synchronized ( expression ) compound-statement
9049 */
9050
9051 static void
9052 c_parser_objc_synchronized_statement (c_parser *parser)
9053 {
9054   location_t loc;
9055   tree expr, stmt;
9056   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
9057   c_parser_consume_token (parser);
9058   loc = c_parser_peek_token (parser)->location;
9059   objc_maybe_warn_exceptions (loc);
9060   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9061     {
9062       struct c_expr ce = c_parser_expression (parser);
9063       ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9064       expr = ce.value;
9065       expr = c_fully_fold (expr, false, NULL);
9066       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9067     }
9068   else
9069     expr = error_mark_node;
9070   stmt = c_parser_compound_statement (parser);
9071   objc_build_synchronized (loc, expr, stmt);
9072 }
9073
9074 /* Parse an objc-selector; return NULL_TREE without an error if the
9075    next token is not an objc-selector.
9076
9077    objc-selector:
9078      identifier
9079      one of
9080        enum struct union if else while do for switch case default
9081        break continue return goto asm sizeof typeof __alignof
9082        unsigned long const short volatile signed restrict _Complex
9083        in out inout bycopy byref oneway int char float double void _Bool
9084        _Atomic
9085
9086    ??? Why this selection of keywords but not, for example, storage
9087    class specifiers?  */
9088
9089 static tree
9090 c_parser_objc_selector (c_parser *parser)
9091 {
9092   c_token *token = c_parser_peek_token (parser);
9093   tree value = token->value;
9094   if (token->type == CPP_NAME)
9095     {
9096       c_parser_consume_token (parser);
9097       return value;
9098     }
9099   if (token->type != CPP_KEYWORD)
9100     return NULL_TREE;
9101   switch (token->keyword)
9102     {
9103     case RID_ENUM:
9104     case RID_STRUCT:
9105     case RID_UNION:
9106     case RID_IF:
9107     case RID_ELSE:
9108     case RID_WHILE:
9109     case RID_DO:
9110     case RID_FOR:
9111     case RID_SWITCH:
9112     case RID_CASE:
9113     case RID_DEFAULT:
9114     case RID_BREAK:
9115     case RID_CONTINUE:
9116     case RID_RETURN:
9117     case RID_GOTO:
9118     case RID_ASM:
9119     case RID_SIZEOF:
9120     case RID_TYPEOF:
9121     case RID_ALIGNOF:
9122     case RID_UNSIGNED:
9123     case RID_LONG:
9124     case RID_CONST:
9125     case RID_SHORT:
9126     case RID_VOLATILE:
9127     case RID_SIGNED:
9128     case RID_RESTRICT:
9129     case RID_COMPLEX:
9130     case RID_IN:
9131     case RID_OUT:
9132     case RID_INOUT:
9133     case RID_BYCOPY:
9134     case RID_BYREF:
9135     case RID_ONEWAY:
9136     case RID_INT:
9137     case RID_CHAR:
9138     case RID_FLOAT:
9139     case RID_DOUBLE:
9140     case RID_VOID:
9141     case RID_BOOL:
9142     case RID_ATOMIC:
9143     case RID_AUTO_TYPE:
9144     case RID_INT_N_0:
9145     case RID_INT_N_1:
9146     case RID_INT_N_2:
9147     case RID_INT_N_3:
9148       c_parser_consume_token (parser);
9149       return value;
9150     default:
9151       return NULL_TREE;
9152     }
9153 }
9154
9155 /* Parse an objc-selector-arg.
9156
9157    objc-selector-arg:
9158      objc-selector
9159      objc-keywordname-list
9160
9161    objc-keywordname-list:
9162      objc-keywordname
9163      objc-keywordname-list objc-keywordname
9164
9165    objc-keywordname:
9166      objc-selector :
9167      :
9168 */
9169
9170 static tree
9171 c_parser_objc_selector_arg (c_parser *parser)
9172 {
9173   tree sel = c_parser_objc_selector (parser);
9174   tree list = NULL_TREE;
9175   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9176     return sel;
9177   while (true)
9178     {
9179       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9180         return list;
9181       list = chainon (list, build_tree_list (sel, NULL_TREE));
9182       sel = c_parser_objc_selector (parser);
9183       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9184         break;
9185     }
9186   return list;
9187 }
9188
9189 /* Parse an objc-receiver.
9190
9191    objc-receiver:
9192      expression
9193      class-name
9194      type-name
9195 */
9196
9197 static tree
9198 c_parser_objc_receiver (c_parser *parser)
9199 {
9200   location_t loc = c_parser_peek_token (parser)->location;
9201
9202   if (c_parser_peek_token (parser)->type == CPP_NAME
9203       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
9204           || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
9205     {
9206       tree id = c_parser_peek_token (parser)->value;
9207       c_parser_consume_token (parser);
9208       return objc_get_class_reference (id);
9209     }
9210   struct c_expr ce = c_parser_expression (parser);
9211   ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9212   return c_fully_fold (ce.value, false, NULL);
9213 }
9214
9215 /* Parse objc-message-args.
9216
9217    objc-message-args:
9218      objc-selector
9219      objc-keywordarg-list
9220
9221    objc-keywordarg-list:
9222      objc-keywordarg
9223      objc-keywordarg-list objc-keywordarg
9224
9225    objc-keywordarg:
9226      objc-selector : objc-keywordexpr
9227      : objc-keywordexpr
9228 */
9229
9230 static tree
9231 c_parser_objc_message_args (c_parser *parser)
9232 {
9233   tree sel = c_parser_objc_selector (parser);
9234   tree list = NULL_TREE;
9235   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9236     return sel;
9237   while (true)
9238     {
9239       tree keywordexpr;
9240       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9241         return error_mark_node;
9242       keywordexpr = c_parser_objc_keywordexpr (parser);
9243       list = chainon (list, build_tree_list (sel, keywordexpr));
9244       sel = c_parser_objc_selector (parser);
9245       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9246         break;
9247     }
9248   return list;
9249 }
9250
9251 /* Parse an objc-keywordexpr.
9252
9253    objc-keywordexpr:
9254      nonempty-expr-list
9255 */
9256
9257 static tree
9258 c_parser_objc_keywordexpr (c_parser *parser)
9259 {
9260   tree ret;
9261   vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
9262                                                 NULL, NULL, NULL, NULL);
9263   if (vec_safe_length (expr_list) == 1)
9264     {
9265       /* Just return the expression, remove a level of
9266          indirection.  */
9267       ret = (*expr_list)[0];
9268     }
9269   else
9270     {
9271       /* We have a comma expression, we will collapse later.  */
9272       ret = build_tree_list_vec (expr_list);
9273     }
9274   release_tree_vector (expr_list);
9275   return ret;
9276 }
9277
9278 /* A check, needed in several places, that ObjC interface, implementation or
9279    method definitions are not prefixed by incorrect items.  */
9280 static bool
9281 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, 
9282                                            struct c_declspecs *specs)
9283 {
9284   if (!specs->declspecs_seen_p || specs->non_sc_seen_p
9285       || specs->typespec_kind != ctsk_none)
9286     {
9287       c_parser_error (parser, 
9288                       "no type or storage class may be specified here,");
9289       c_parser_skip_to_end_of_block_or_statement (parser);
9290       return true;
9291     }
9292   return false;
9293 }
9294
9295 /* Parse an Objective-C @property declaration.  The syntax is:
9296
9297    objc-property-declaration:
9298      '@property' objc-property-attributes[opt] struct-declaration ;
9299
9300    objc-property-attributes:
9301     '(' objc-property-attribute-list ')'
9302
9303    objc-property-attribute-list:
9304      objc-property-attribute
9305      objc-property-attribute-list, objc-property-attribute
9306
9307    objc-property-attribute
9308      'getter' = identifier
9309      'setter' = identifier
9310      'readonly'
9311      'readwrite'
9312      'assign'
9313      'retain'
9314      'copy'
9315      'nonatomic'
9316
9317   For example:
9318     @property NSString *name;
9319     @property (readonly) id object;
9320     @property (retain, nonatomic, getter=getTheName) id name;
9321     @property int a, b, c;
9322
9323   PS: This function is identical to cp_parser_objc_at_propery_declaration
9324   for C++.  Keep them in sync.  */
9325 static void
9326 c_parser_objc_at_property_declaration (c_parser *parser)
9327 {
9328   /* The following variables hold the attributes of the properties as
9329      parsed.  They are 'false' or 'NULL_TREE' if the attribute was not
9330      seen.  When we see an attribute, we set them to 'true' (if they
9331      are boolean properties) or to the identifier (if they have an
9332      argument, ie, for getter and setter).  Note that here we only
9333      parse the list of attributes, check the syntax and accumulate the
9334      attributes that we find.  objc_add_property_declaration() will
9335      then process the information.  */
9336   bool property_assign = false;
9337   bool property_copy = false;
9338   tree property_getter_ident = NULL_TREE;
9339   bool property_nonatomic = false;
9340   bool property_readonly = false;
9341   bool property_readwrite = false;
9342   bool property_retain = false;
9343   tree property_setter_ident = NULL_TREE;
9344
9345   /* 'properties' is the list of properties that we read.  Usually a
9346      single one, but maybe more (eg, in "@property int a, b, c;" there
9347      are three).  */
9348   tree properties;
9349   location_t loc;
9350
9351   loc = c_parser_peek_token (parser)->location;
9352   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
9353
9354   c_parser_consume_token (parser);  /* Eat '@property'.  */
9355
9356   /* Parse the optional attribute list...  */
9357   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9358     {
9359       /* Eat the '(' */
9360       c_parser_consume_token (parser);
9361       
9362       /* Property attribute keywords are valid now.  */
9363       parser->objc_property_attr_context = true;
9364
9365       while (true)
9366         {
9367           bool syntax_error = false;
9368           c_token *token = c_parser_peek_token (parser);
9369           enum rid keyword;
9370
9371           if (token->type != CPP_KEYWORD)
9372             {
9373               if (token->type == CPP_CLOSE_PAREN)
9374                 c_parser_error (parser, "expected identifier");
9375               else
9376                 {
9377                   c_parser_consume_token (parser);
9378                   c_parser_error (parser, "unknown property attribute");
9379                 }
9380               break;
9381             }
9382           keyword = token->keyword;
9383           c_parser_consume_token (parser);
9384           switch (keyword)
9385             {
9386             case RID_ASSIGN:    property_assign = true;    break;
9387             case RID_COPY:      property_copy = true;      break;
9388             case RID_NONATOMIC: property_nonatomic = true; break;
9389             case RID_READONLY:  property_readonly = true;  break;
9390             case RID_READWRITE: property_readwrite = true; break;
9391             case RID_RETAIN:    property_retain = true;    break;
9392
9393             case RID_GETTER:
9394             case RID_SETTER:
9395               if (c_parser_next_token_is_not (parser, CPP_EQ))
9396                 {
9397                   if (keyword == RID_GETTER)
9398                     c_parser_error (parser,
9399                                     "missing %<=%> (after %<getter%> attribute)");
9400                   else
9401                     c_parser_error (parser,
9402                                     "missing %<=%> (after %<setter%> attribute)");
9403                   syntax_error = true;
9404                   break;
9405                 }
9406               c_parser_consume_token (parser); /* eat the = */
9407               if (c_parser_next_token_is_not (parser, CPP_NAME))
9408                 {
9409                   c_parser_error (parser, "expected identifier");
9410                   syntax_error = true;
9411                   break;
9412                 }
9413               if (keyword == RID_SETTER)
9414                 {
9415                   if (property_setter_ident != NULL_TREE)
9416                     c_parser_error (parser, "the %<setter%> attribute may only be specified once");
9417                   else
9418                     property_setter_ident = c_parser_peek_token (parser)->value;
9419                   c_parser_consume_token (parser);
9420                   if (c_parser_next_token_is_not (parser, CPP_COLON))
9421                     c_parser_error (parser, "setter name must terminate with %<:%>");
9422                   else
9423                     c_parser_consume_token (parser);
9424                 }
9425               else
9426                 {
9427                   if (property_getter_ident != NULL_TREE)
9428                     c_parser_error (parser, "the %<getter%> attribute may only be specified once");
9429                   else
9430                     property_getter_ident = c_parser_peek_token (parser)->value;
9431                   c_parser_consume_token (parser);
9432                 }
9433               break;
9434             default:
9435               c_parser_error (parser, "unknown property attribute");
9436               syntax_error = true;
9437               break;
9438             }
9439
9440           if (syntax_error)
9441             break;
9442           
9443           if (c_parser_next_token_is (parser, CPP_COMMA))
9444             c_parser_consume_token (parser);
9445           else
9446             break;
9447         }
9448       parser->objc_property_attr_context = false;
9449       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9450     }
9451   /* ... and the property declaration(s).  */
9452   properties = c_parser_struct_declaration (parser);
9453
9454   if (properties == error_mark_node)
9455     {
9456       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9457       parser->error = false;
9458       return;
9459     }
9460
9461   if (properties == NULL_TREE)
9462     c_parser_error (parser, "expected identifier");
9463   else
9464     {
9465       /* Comma-separated properties are chained together in
9466          reverse order; add them one by one.  */
9467       properties = nreverse (properties);
9468       
9469       for (; properties; properties = TREE_CHAIN (properties))
9470         objc_add_property_declaration (loc, copy_node (properties),
9471                                        property_readonly, property_readwrite,
9472                                        property_assign, property_retain,
9473                                        property_copy, property_nonatomic,
9474                                        property_getter_ident, property_setter_ident);
9475     }
9476
9477   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9478   parser->error = false;
9479 }
9480
9481 /* Parse an Objective-C @synthesize declaration.  The syntax is:
9482
9483    objc-synthesize-declaration:
9484      @synthesize objc-synthesize-identifier-list ;
9485
9486    objc-synthesize-identifier-list:
9487      objc-synthesize-identifier
9488      objc-synthesize-identifier-list, objc-synthesize-identifier
9489
9490    objc-synthesize-identifier
9491      identifier
9492      identifier = identifier
9493
9494   For example:
9495     @synthesize MyProperty;
9496     @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9497
9498   PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9499   for C++.  Keep them in sync.
9500 */
9501 static void
9502 c_parser_objc_at_synthesize_declaration (c_parser *parser)
9503 {
9504   tree list = NULL_TREE;
9505   location_t loc;
9506   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
9507   loc = c_parser_peek_token (parser)->location;
9508
9509   c_parser_consume_token (parser);
9510   while (true)
9511     {
9512       tree property, ivar;
9513       if (c_parser_next_token_is_not (parser, CPP_NAME))
9514         {
9515           c_parser_error (parser, "expected identifier");
9516           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9517           /* Once we find the semicolon, we can resume normal parsing.
9518              We have to reset parser->error manually because
9519              c_parser_skip_until_found() won't reset it for us if the
9520              next token is precisely a semicolon.  */
9521           parser->error = false;
9522           return;
9523         }
9524       property = c_parser_peek_token (parser)->value;
9525       c_parser_consume_token (parser);
9526       if (c_parser_next_token_is (parser, CPP_EQ))
9527         {
9528           c_parser_consume_token (parser);
9529           if (c_parser_next_token_is_not (parser, CPP_NAME))
9530             {
9531               c_parser_error (parser, "expected identifier");
9532               c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9533               parser->error = false;
9534               return;
9535             }
9536           ivar = c_parser_peek_token (parser)->value;
9537           c_parser_consume_token (parser);
9538         }
9539       else
9540         ivar = NULL_TREE;
9541       list = chainon (list, build_tree_list (ivar, property));
9542       if (c_parser_next_token_is (parser, CPP_COMMA))
9543         c_parser_consume_token (parser);
9544       else
9545         break;
9546     }
9547   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9548   objc_add_synthesize_declaration (loc, list);
9549 }
9550
9551 /* Parse an Objective-C @dynamic declaration.  The syntax is:
9552
9553    objc-dynamic-declaration:
9554      @dynamic identifier-list ;
9555
9556    For example:
9557      @dynamic MyProperty;
9558      @dynamic MyProperty, AnotherProperty;
9559
9560   PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9561   for C++.  Keep them in sync.
9562 */
9563 static void
9564 c_parser_objc_at_dynamic_declaration (c_parser *parser)
9565 {
9566   tree list = NULL_TREE;
9567   location_t loc;
9568   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
9569   loc = c_parser_peek_token (parser)->location;
9570
9571   c_parser_consume_token (parser);
9572   while (true)
9573     {
9574       tree property;
9575       if (c_parser_next_token_is_not (parser, CPP_NAME))
9576         {
9577           c_parser_error (parser, "expected identifier");
9578           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9579           parser->error = false;
9580           return;
9581         }
9582       property = c_parser_peek_token (parser)->value;
9583       list = chainon (list, build_tree_list (NULL_TREE, property));
9584       c_parser_consume_token (parser);
9585       if (c_parser_next_token_is (parser, CPP_COMMA))
9586         c_parser_consume_token (parser);
9587       else
9588         break;
9589     }
9590   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9591   objc_add_dynamic_declaration (loc, list);
9592 }
9593
9594 \f
9595 /* Handle pragmas.  Some OpenMP pragmas are associated with, and therefore
9596    should be considered, statements.  ALLOW_STMT is true if we're within
9597    the context of a function and such pragmas are to be allowed.  Returns
9598    true if we actually parsed such a pragma.  */
9599
9600 static bool
9601 c_parser_pragma (c_parser *parser, enum pragma_context context)
9602 {
9603   unsigned int id;
9604
9605   id = c_parser_peek_token (parser)->pragma_kind;
9606   gcc_assert (id != PRAGMA_NONE);
9607
9608   switch (id)
9609     {
9610     case PRAGMA_OACC_ENTER_DATA:
9611       c_parser_oacc_enter_exit_data (parser, true);
9612       return false;
9613
9614     case PRAGMA_OACC_EXIT_DATA:
9615       c_parser_oacc_enter_exit_data (parser, false);
9616       return false;
9617
9618     case PRAGMA_OACC_UPDATE:
9619       if (context != pragma_compound)
9620         {
9621           if (context == pragma_stmt)
9622             c_parser_error (parser, "%<#pragma acc update%> may only be "
9623                             "used in compound statements");
9624           goto bad_stmt;
9625         }
9626       c_parser_oacc_update (parser);
9627       return false;
9628
9629     case PRAGMA_OMP_BARRIER:
9630       if (context != pragma_compound)
9631         {
9632           if (context == pragma_stmt)
9633             c_parser_error (parser, "%<#pragma omp barrier%> may only be "
9634                             "used in compound statements");
9635           goto bad_stmt;
9636         }
9637       c_parser_omp_barrier (parser);
9638       return false;
9639
9640     case PRAGMA_OMP_FLUSH:
9641       if (context != pragma_compound)
9642         {
9643           if (context == pragma_stmt)
9644             c_parser_error (parser, "%<#pragma omp flush%> may only be "
9645                             "used in compound statements");
9646           goto bad_stmt;
9647         }
9648       c_parser_omp_flush (parser);
9649       return false;
9650
9651     case PRAGMA_OMP_TASKWAIT:
9652       if (context != pragma_compound)
9653         {
9654           if (context == pragma_stmt)
9655             c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
9656                             "used in compound statements");
9657           goto bad_stmt;
9658         }
9659       c_parser_omp_taskwait (parser);
9660       return false;
9661
9662     case PRAGMA_OMP_TASKYIELD:
9663       if (context != pragma_compound)
9664         {
9665           if (context == pragma_stmt)
9666             c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
9667                             "used in compound statements");
9668           goto bad_stmt;
9669         }
9670       c_parser_omp_taskyield (parser);
9671       return false;
9672
9673     case PRAGMA_OMP_CANCEL:
9674       if (context != pragma_compound)
9675         {
9676           if (context == pragma_stmt)
9677             c_parser_error (parser, "%<#pragma omp cancel%> may only be "
9678                             "used in compound statements");
9679           goto bad_stmt;
9680         }
9681       c_parser_omp_cancel (parser);
9682       return false;
9683
9684     case PRAGMA_OMP_CANCELLATION_POINT:
9685       if (context != pragma_compound)
9686         {
9687           if (context == pragma_stmt)
9688             c_parser_error (parser, "%<#pragma omp cancellation point%> may "
9689                                     "only be used in compound statements");
9690           goto bad_stmt;
9691         }
9692       c_parser_omp_cancellation_point (parser);
9693       return false;
9694
9695     case PRAGMA_OMP_THREADPRIVATE:
9696       c_parser_omp_threadprivate (parser);
9697       return false;
9698
9699     case PRAGMA_OMP_TARGET:
9700       return c_parser_omp_target (parser, context);
9701
9702     case PRAGMA_OMP_END_DECLARE_TARGET:
9703       c_parser_omp_end_declare_target (parser);
9704       return false;
9705
9706     case PRAGMA_OMP_SECTION:
9707       error_at (c_parser_peek_token (parser)->location,
9708                 "%<#pragma omp section%> may only be used in "
9709                 "%<#pragma omp sections%> construct");
9710       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9711       return false;
9712
9713     case PRAGMA_OMP_DECLARE_REDUCTION:
9714       c_parser_omp_declare (parser, context);
9715       return false;
9716     case PRAGMA_IVDEP:
9717       c_parser_consume_pragma (parser);
9718       c_parser_skip_to_pragma_eol (parser);
9719       if (!c_parser_next_token_is_keyword (parser, RID_FOR)
9720           && !c_parser_next_token_is_keyword (parser, RID_WHILE)
9721           && !c_parser_next_token_is_keyword (parser, RID_DO))
9722         {
9723           c_parser_error (parser, "for, while or do statement expected");
9724           return false;
9725         }
9726       if (c_parser_next_token_is_keyword (parser, RID_FOR))
9727         c_parser_for_statement (parser, true);
9728       else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
9729         c_parser_while_statement (parser, true);
9730       else
9731         c_parser_do_statement (parser, true);
9732       return false;
9733
9734     case PRAGMA_GCC_PCH_PREPROCESS:
9735       c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
9736       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9737       return false;
9738
9739     case PRAGMA_CILK_SIMD:
9740       if (!c_parser_cilk_verify_simd (parser, context))
9741         return false;
9742       c_parser_consume_pragma (parser);
9743       c_parser_cilk_simd (parser);
9744       return false;
9745     case PRAGMA_CILK_GRAINSIZE:
9746       if (!flag_cilkplus)
9747         {
9748           warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9749                    " enabled");
9750           c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9751           return false;
9752         }
9753       if (context == pragma_external)
9754         {
9755           error_at (c_parser_peek_token (parser)->location,
9756                     "%<#pragma grainsize%> must be inside a function");
9757           c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9758           return false;
9759         }
9760       c_parser_cilk_grainsize (parser);
9761       return false;
9762
9763     default:
9764       if (id < PRAGMA_FIRST_EXTERNAL)
9765         {
9766           if (context != pragma_stmt && context != pragma_compound)
9767             {
9768             bad_stmt:
9769               c_parser_error (parser, "expected declaration specifiers");
9770               c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9771               return false;
9772             }
9773           c_parser_omp_construct (parser);
9774           return true;
9775         }
9776       break;
9777     }
9778
9779   c_parser_consume_pragma (parser);
9780   c_invoke_pragma_handler (id);
9781
9782   /* Skip to EOL, but suppress any error message.  Those will have been
9783      generated by the handler routine through calling error, as opposed
9784      to calling c_parser_error.  */
9785   parser->error = true;
9786   c_parser_skip_to_pragma_eol (parser);
9787
9788   return false;
9789 }
9790
9791 /* The interface the pragma parsers have to the lexer.  */
9792
9793 enum cpp_ttype
9794 pragma_lex (tree *value)
9795 {
9796   c_token *tok = c_parser_peek_token (the_parser);
9797   enum cpp_ttype ret = tok->type;
9798
9799   *value = tok->value;
9800   if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
9801     ret = CPP_EOF;
9802   else
9803     {
9804       if (ret == CPP_KEYWORD)
9805         ret = CPP_NAME;
9806       c_parser_consume_token (the_parser);
9807     }
9808
9809   return ret;
9810 }
9811
9812 static void
9813 c_parser_pragma_pch_preprocess (c_parser *parser)
9814 {
9815   tree name = NULL;
9816
9817   c_parser_consume_pragma (parser);
9818   if (c_parser_next_token_is (parser, CPP_STRING))
9819     {
9820       name = c_parser_peek_token (parser)->value;
9821       c_parser_consume_token (parser);
9822     }
9823   else
9824     c_parser_error (parser, "expected string literal");
9825   c_parser_skip_to_pragma_eol (parser);
9826
9827   if (name)
9828     c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
9829 }
9830 \f
9831 /* OpenACC and OpenMP parsing routines.  */
9832
9833 /* Returns name of the next clause.
9834    If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9835    the token is not consumed.  Otherwise appropriate pragma_omp_clause is
9836    returned and the token is consumed.  */
9837
9838 static pragma_omp_clause
9839 c_parser_omp_clause_name (c_parser *parser)
9840 {
9841   pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
9842
9843   if (c_parser_next_token_is_keyword (parser, RID_AUTO))
9844     result = PRAGMA_OACC_CLAUSE_AUTO;
9845   else if (c_parser_next_token_is_keyword (parser, RID_IF))
9846     result = PRAGMA_OMP_CLAUSE_IF;
9847   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
9848     result = PRAGMA_OMP_CLAUSE_DEFAULT;
9849   else if (c_parser_next_token_is_keyword (parser, RID_FOR))
9850     result = PRAGMA_OMP_CLAUSE_FOR;
9851   else if (c_parser_next_token_is (parser, CPP_NAME))
9852     {
9853       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9854
9855       switch (p[0])
9856         {
9857         case 'a':
9858           if (!strcmp ("aligned", p))
9859             result = PRAGMA_OMP_CLAUSE_ALIGNED;
9860           else if (!strcmp ("async", p))
9861             result = PRAGMA_OACC_CLAUSE_ASYNC;
9862           break;
9863         case 'c':
9864           if (!strcmp ("collapse", p))
9865             result = PRAGMA_OMP_CLAUSE_COLLAPSE;
9866           else if (!strcmp ("copy", p))
9867             result = PRAGMA_OACC_CLAUSE_COPY;
9868           else if (!strcmp ("copyin", p))
9869             result = PRAGMA_OMP_CLAUSE_COPYIN;
9870           else if (!strcmp ("copyout", p))
9871             result = PRAGMA_OACC_CLAUSE_COPYOUT;
9872           else if (!strcmp ("copyprivate", p))
9873             result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
9874           else if (!strcmp ("create", p))
9875             result = PRAGMA_OACC_CLAUSE_CREATE;
9876           break;
9877         case 'd':
9878           if (!strcmp ("delete", p))
9879             result = PRAGMA_OACC_CLAUSE_DELETE;
9880           else if (!strcmp ("depend", p))
9881             result = PRAGMA_OMP_CLAUSE_DEPEND;
9882           else if (!strcmp ("device", p))
9883             result = PRAGMA_OMP_CLAUSE_DEVICE;
9884           else if (!strcmp ("deviceptr", p))
9885             result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
9886           else if (!strcmp ("dist_schedule", p))
9887             result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
9888           break;
9889         case 'f':
9890           if (!strcmp ("final", p))
9891             result = PRAGMA_OMP_CLAUSE_FINAL;
9892           else if (!strcmp ("firstprivate", p))
9893             result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
9894           else if (!strcmp ("from", p))
9895             result = PRAGMA_OMP_CLAUSE_FROM;
9896           break;
9897         case 'g':
9898           if (!strcmp ("gang", p))
9899             result = PRAGMA_OACC_CLAUSE_GANG;
9900           break;
9901         case 'h':
9902           if (!strcmp ("host", p))
9903             result = PRAGMA_OACC_CLAUSE_HOST;
9904           break;
9905         case 'i':
9906           if (!strcmp ("inbranch", p))
9907             result = PRAGMA_OMP_CLAUSE_INBRANCH;
9908           break;
9909         case 'l':
9910           if (!strcmp ("lastprivate", p))
9911             result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
9912           else if (!strcmp ("linear", p))
9913             result = PRAGMA_OMP_CLAUSE_LINEAR;
9914           break;
9915         case 'm':
9916           if (!strcmp ("map", p))
9917             result = PRAGMA_OMP_CLAUSE_MAP;
9918           else if (!strcmp ("mergeable", p))
9919             result = PRAGMA_OMP_CLAUSE_MERGEABLE;
9920           else if (flag_cilkplus && !strcmp ("mask", p))
9921             result = PRAGMA_CILK_CLAUSE_MASK;
9922           break;
9923         case 'n':
9924           if (!strcmp ("notinbranch", p))
9925             result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
9926           else if (!strcmp ("nowait", p))
9927             result = PRAGMA_OMP_CLAUSE_NOWAIT;
9928           else if (!strcmp ("num_gangs", p))
9929             result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
9930           else if (!strcmp ("num_teams", p))
9931             result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
9932           else if (!strcmp ("num_threads", p))
9933             result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
9934           else if (!strcmp ("num_workers", p))
9935             result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
9936           else if (flag_cilkplus && !strcmp ("nomask", p))
9937             result = PRAGMA_CILK_CLAUSE_NOMASK;
9938           break;
9939         case 'o':
9940           if (!strcmp ("ordered", p))
9941             result = PRAGMA_OMP_CLAUSE_ORDERED;
9942           break;
9943         case 'p':
9944           if (!strcmp ("parallel", p))
9945             result = PRAGMA_OMP_CLAUSE_PARALLEL;
9946           else if (!strcmp ("present", p))
9947             result = PRAGMA_OACC_CLAUSE_PRESENT;
9948           else if (!strcmp ("present_or_copy", p)
9949                    || !strcmp ("pcopy", p))
9950             result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
9951           else if (!strcmp ("present_or_copyin", p)
9952                    || !strcmp ("pcopyin", p))
9953             result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
9954           else if (!strcmp ("present_or_copyout", p)
9955                    || !strcmp ("pcopyout", p))
9956             result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
9957           else if (!strcmp ("present_or_create", p)
9958                    || !strcmp ("pcreate", p))
9959             result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
9960           else if (!strcmp ("private", p))
9961             result = PRAGMA_OMP_CLAUSE_PRIVATE;
9962           else if (!strcmp ("proc_bind", p))
9963             result = PRAGMA_OMP_CLAUSE_PROC_BIND;
9964           break;
9965         case 'r':
9966           if (!strcmp ("reduction", p))
9967             result = PRAGMA_OMP_CLAUSE_REDUCTION;
9968           break;
9969         case 's':
9970           if (!strcmp ("safelen", p))
9971             result = PRAGMA_OMP_CLAUSE_SAFELEN;
9972           else if (!strcmp ("schedule", p))
9973             result = PRAGMA_OMP_CLAUSE_SCHEDULE;
9974           else if (!strcmp ("sections", p))
9975             result = PRAGMA_OMP_CLAUSE_SECTIONS;
9976           else if (!strcmp ("seq", p))
9977             result = PRAGMA_OACC_CLAUSE_SEQ;
9978           else if (!strcmp ("shared", p))
9979             result = PRAGMA_OMP_CLAUSE_SHARED;
9980           else if (!strcmp ("simdlen", p))
9981             result = PRAGMA_OMP_CLAUSE_SIMDLEN;
9982           else if (!strcmp ("self", p))
9983             result = PRAGMA_OACC_CLAUSE_SELF;
9984           break;
9985         case 't':
9986           if (!strcmp ("taskgroup", p))
9987             result = PRAGMA_OMP_CLAUSE_TASKGROUP;
9988           else if (!strcmp ("thread_limit", p))
9989             result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
9990           else if (!strcmp ("to", p))
9991             result = PRAGMA_OMP_CLAUSE_TO;
9992           break;
9993         case 'u':
9994           if (!strcmp ("uniform", p))
9995             result = PRAGMA_OMP_CLAUSE_UNIFORM;
9996           else if (!strcmp ("untied", p))
9997             result = PRAGMA_OMP_CLAUSE_UNTIED;
9998           break;
9999         case 'v':
10000           if (!strcmp ("vector", p))
10001             result = PRAGMA_OACC_CLAUSE_VECTOR;
10002           else if (!strcmp ("vector_length", p))
10003             result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
10004           else if (flag_cilkplus && !strcmp ("vectorlength", p))
10005             result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
10006           break;
10007         case 'w':
10008           if (!strcmp ("wait", p))
10009             result = PRAGMA_OACC_CLAUSE_WAIT;
10010           else if (!strcmp ("worker", p))
10011             result = PRAGMA_OACC_CLAUSE_WORKER;
10012           break;
10013         }
10014     }
10015
10016   if (result != PRAGMA_OMP_CLAUSE_NONE)
10017     c_parser_consume_token (parser);
10018
10019   return result;
10020 }
10021
10022 /* Validate that a clause of the given type does not already exist.  */
10023
10024 static void
10025 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
10026                            const char *name)
10027 {
10028   tree c;
10029
10030   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
10031     if (OMP_CLAUSE_CODE (c) == code)
10032       {
10033         location_t loc = OMP_CLAUSE_LOCATION (c);
10034         error_at (loc, "too many %qs clauses", name);
10035         break;
10036       }
10037 }
10038
10039 /* OpenACC 2.0
10040    Parse wait clause or wait directive parameters.  */
10041
10042 static tree
10043 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
10044 {
10045   vec<tree, va_gc> *args;
10046   tree t, args_tree;
10047
10048   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10049     return list;
10050
10051   args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
10052
10053   if (args->length () == 0)
10054     {
10055       c_parser_error (parser, "expected integer expression before ')'");
10056       release_tree_vector (args);
10057       return list;
10058     }
10059
10060   args_tree = build_tree_list_vec (args);
10061
10062   for (t = args_tree; t; t = TREE_CHAIN (t))
10063     {
10064       tree targ = TREE_VALUE (t);
10065
10066       if (targ != error_mark_node)
10067         {
10068           if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
10069             {
10070               c_parser_error (parser, "expression must be integral");
10071               targ = error_mark_node;
10072             }
10073           else
10074             {
10075               tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
10076
10077               OMP_CLAUSE_DECL (c) = targ;
10078               OMP_CLAUSE_CHAIN (c) = list;
10079               list = c;
10080             }
10081         }
10082     }
10083
10084   release_tree_vector (args);
10085   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10086   return list;
10087 }
10088
10089 /* OpenACC 2.0, OpenMP 2.5:
10090    variable-list:
10091      identifier
10092      variable-list , identifier
10093
10094    If KIND is nonzero, create the appropriate node and install the
10095    decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10096    If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10097
10098    If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10099    return the list created.  */
10100
10101 static tree
10102 c_parser_omp_variable_list (c_parser *parser,
10103                             location_t clause_loc,
10104                             enum omp_clause_code kind, tree list)
10105 {
10106   if (c_parser_next_token_is_not (parser, CPP_NAME)
10107       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
10108     c_parser_error (parser, "expected identifier");
10109
10110   while (c_parser_next_token_is (parser, CPP_NAME)
10111          && c_parser_peek_token (parser)->id_kind == C_ID_ID)
10112     {
10113       tree t = lookup_name (c_parser_peek_token (parser)->value);
10114
10115       if (t == NULL_TREE)
10116         {
10117           undeclared_variable (c_parser_peek_token (parser)->location,
10118                                c_parser_peek_token (parser)->value);
10119           t = error_mark_node;
10120         }
10121
10122       c_parser_consume_token (parser);
10123
10124       if (t == error_mark_node)
10125         ;
10126       else if (kind != 0)
10127         {
10128           switch (kind)
10129             {
10130             case OMP_CLAUSE__CACHE_:
10131               if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
10132                 {
10133                   c_parser_error (parser, "expected %<[%>");
10134                   t = error_mark_node;
10135                   break;
10136                 }
10137               /* FALL THROUGH.  */
10138             case OMP_CLAUSE_MAP:
10139             case OMP_CLAUSE_FROM:
10140             case OMP_CLAUSE_TO:
10141             case OMP_CLAUSE_DEPEND:
10142               while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
10143                 {
10144                   tree low_bound = NULL_TREE, length = NULL_TREE;
10145
10146                   c_parser_consume_token (parser);
10147                   if (!c_parser_next_token_is (parser, CPP_COLON))
10148                     {
10149                       low_bound = c_parser_expression (parser).value;
10150                       mark_exp_read (low_bound);
10151                     }
10152                   if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10153                     length = integer_one_node;
10154                   else
10155                     {
10156                       /* Look for `:'.  */
10157                       if (!c_parser_require (parser, CPP_COLON,
10158                                              "expected %<:%>"))
10159                         {
10160                           t = error_mark_node;
10161                           break;
10162                         }
10163                       if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10164                         {
10165                           length = c_parser_expression (parser).value;
10166                           mark_exp_read (length);
10167                         }
10168                     }
10169                   /* Look for the closing `]'.  */
10170                   if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
10171                                          "expected %<]%>"))
10172                     {
10173                       t = error_mark_node;
10174                       break;
10175                     }
10176
10177                   if (kind == OMP_CLAUSE__CACHE_)
10178                     {
10179                       if (TREE_CODE (low_bound) != INTEGER_CST
10180                           && !TREE_READONLY (low_bound))
10181                         {
10182                           error_at (clause_loc,
10183                                         "%qD is not a constant", low_bound);
10184                           t = error_mark_node;
10185                         }
10186
10187                       if (TREE_CODE (length) != INTEGER_CST
10188                           && !TREE_READONLY (length))
10189                         {
10190                           error_at (clause_loc,
10191                                         "%qD is not a constant", length);
10192                           t = error_mark_node;
10193                         }
10194                     }
10195
10196                   t = tree_cons (low_bound, length, t);
10197                 }
10198               break;
10199             default:
10200               break;
10201             }
10202
10203           if (t != error_mark_node)
10204             {
10205               tree u = build_omp_clause (clause_loc, kind);
10206               OMP_CLAUSE_DECL (u) = t;
10207               OMP_CLAUSE_CHAIN (u) = list;
10208               list = u;
10209             }
10210         }
10211       else
10212         list = tree_cons (t, NULL_TREE, list);
10213
10214       if (c_parser_next_token_is_not (parser, CPP_COMMA))
10215         break;
10216
10217       c_parser_consume_token (parser);
10218     }
10219
10220   return list;
10221 }
10222
10223 /* Similarly, but expect leading and trailing parenthesis.  This is a very
10224    common case for OpenACC and OpenMP clauses.  */
10225
10226 static tree
10227 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
10228                               tree list)
10229 {
10230   /* The clauses location.  */
10231   location_t loc = c_parser_peek_token (parser)->location;
10232
10233   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10234     {
10235       list = c_parser_omp_variable_list (parser, loc, kind, list);
10236       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10237     }
10238   return list;
10239 }
10240
10241 /* OpenACC 2.0:
10242    copy ( variable-list )
10243    copyin ( variable-list )
10244    copyout ( variable-list )
10245    create ( variable-list )
10246    delete ( variable-list )
10247    present ( variable-list )
10248    present_or_copy ( variable-list )
10249      pcopy ( variable-list )
10250    present_or_copyin ( variable-list )
10251      pcopyin ( variable-list )
10252    present_or_copyout ( variable-list )
10253      pcopyout ( variable-list )
10254    present_or_create ( variable-list )
10255      pcreate ( variable-list ) */
10256
10257 static tree
10258 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
10259                            tree list)
10260 {
10261   enum gomp_map_kind kind;
10262   switch (c_kind)
10263     {
10264     case PRAGMA_OACC_CLAUSE_COPY:
10265       kind = GOMP_MAP_FORCE_TOFROM;
10266       break;
10267     case PRAGMA_OACC_CLAUSE_COPYIN:
10268       kind = GOMP_MAP_FORCE_TO;
10269       break;
10270     case PRAGMA_OACC_CLAUSE_COPYOUT:
10271       kind = GOMP_MAP_FORCE_FROM;
10272       break;
10273     case PRAGMA_OACC_CLAUSE_CREATE:
10274       kind = GOMP_MAP_FORCE_ALLOC;
10275       break;
10276     case PRAGMA_OACC_CLAUSE_DELETE:
10277       kind = GOMP_MAP_FORCE_DEALLOC;
10278       break;
10279     case PRAGMA_OACC_CLAUSE_DEVICE:
10280       kind = GOMP_MAP_FORCE_TO;
10281       break;
10282     case PRAGMA_OACC_CLAUSE_HOST:
10283     case PRAGMA_OACC_CLAUSE_SELF:
10284       kind = GOMP_MAP_FORCE_FROM;
10285       break;
10286     case PRAGMA_OACC_CLAUSE_PRESENT:
10287       kind = GOMP_MAP_FORCE_PRESENT;
10288       break;
10289     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
10290       kind = GOMP_MAP_TOFROM;
10291       break;
10292     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
10293       kind = GOMP_MAP_TO;
10294       break;
10295     case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
10296       kind = GOMP_MAP_FROM;
10297       break;
10298     case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
10299       kind = GOMP_MAP_ALLOC;
10300       break;
10301     default:
10302       gcc_unreachable ();
10303     }
10304   tree nl, c;
10305   nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
10306
10307   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10308     OMP_CLAUSE_SET_MAP_KIND (c, kind);
10309
10310   return nl;
10311 }
10312
10313 /* OpenACC 2.0:
10314    deviceptr ( variable-list ) */
10315
10316 static tree
10317 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
10318 {
10319   location_t loc = c_parser_peek_token (parser)->location;
10320   tree vars, t;
10321
10322   /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10323      c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10324      variable-list must only allow for pointer variables.  */
10325   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10326   for (t = vars; t && t; t = TREE_CHAIN (t))
10327     {
10328       tree v = TREE_PURPOSE (t);
10329
10330       /* FIXME diagnostics: Ideally we should keep individual
10331          locations for all the variables in the var list to make the
10332          following errors more precise.  Perhaps
10333          c_parser_omp_var_list_parens() should construct a list of
10334          locations to go along with the var list.  */
10335
10336       if (TREE_CODE (v) != VAR_DECL)
10337         error_at (loc, "%qD is not a variable", v);
10338       else if (TREE_TYPE (v) == error_mark_node)
10339         ;
10340       else if (!POINTER_TYPE_P (TREE_TYPE (v)))
10341         error_at (loc, "%qD is not a pointer variable", v);
10342
10343       tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
10344       OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
10345       OMP_CLAUSE_DECL (u) = v;
10346       OMP_CLAUSE_CHAIN (u) = list;
10347       list = u;
10348     }
10349
10350   return list;
10351 }
10352
10353 /* OpenACC 2.0, OpenMP 3.0:
10354    collapse ( constant-expression ) */
10355
10356 static tree
10357 c_parser_omp_clause_collapse (c_parser *parser, tree list)
10358 {
10359   tree c, num = error_mark_node;
10360   HOST_WIDE_INT n;
10361   location_t loc;
10362
10363   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
10364
10365   loc = c_parser_peek_token (parser)->location;
10366   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10367     {
10368       num = c_parser_expr_no_commas (parser, NULL).value;
10369       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10370     }
10371   if (num == error_mark_node)
10372     return list;
10373   mark_exp_read (num);
10374   num = c_fully_fold (num, false, NULL);
10375   if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
10376       || !tree_fits_shwi_p (num)
10377       || (n = tree_to_shwi (num)) <= 0
10378       || (int) n != n)
10379     {
10380       error_at (loc,
10381                 "collapse argument needs positive constant integer expression");
10382       return list;
10383     }
10384   c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
10385   OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
10386   OMP_CLAUSE_CHAIN (c) = list;
10387   return c;
10388 }
10389
10390 /* OpenMP 2.5:
10391    copyin ( variable-list ) */
10392
10393 static tree
10394 c_parser_omp_clause_copyin (c_parser *parser, tree list)
10395 {
10396   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
10397 }
10398
10399 /* OpenMP 2.5:
10400    copyprivate ( variable-list ) */
10401
10402 static tree
10403 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
10404 {
10405   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
10406 }
10407
10408 /* OpenMP 2.5:
10409    default ( shared | none ) */
10410
10411 static tree
10412 c_parser_omp_clause_default (c_parser *parser, tree list)
10413 {
10414   enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
10415   location_t loc = c_parser_peek_token (parser)->location;
10416   tree c;
10417
10418   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10419     return list;
10420   if (c_parser_next_token_is (parser, CPP_NAME))
10421     {
10422       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10423
10424       switch (p[0])
10425         {
10426         case 'n':
10427           if (strcmp ("none", p) != 0)
10428             goto invalid_kind;
10429           kind = OMP_CLAUSE_DEFAULT_NONE;
10430           break;
10431
10432         case 's':
10433           if (strcmp ("shared", p) != 0)
10434             goto invalid_kind;
10435           kind = OMP_CLAUSE_DEFAULT_SHARED;
10436           break;
10437
10438         default:
10439           goto invalid_kind;
10440         }
10441
10442       c_parser_consume_token (parser);
10443     }
10444   else
10445     {
10446     invalid_kind:
10447       c_parser_error (parser, "expected %<none%> or %<shared%>");
10448     }
10449   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10450
10451   if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
10452     return list;
10453
10454   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
10455   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
10456   OMP_CLAUSE_CHAIN (c) = list;
10457   OMP_CLAUSE_DEFAULT_KIND (c) = kind;
10458
10459   return c;
10460 }
10461
10462 /* OpenMP 2.5:
10463    firstprivate ( variable-list ) */
10464
10465 static tree
10466 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
10467 {
10468   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
10469 }
10470
10471 /* OpenMP 3.1:
10472    final ( expression ) */
10473
10474 static tree
10475 c_parser_omp_clause_final (c_parser *parser, tree list)
10476 {
10477   location_t loc = c_parser_peek_token (parser)->location;
10478   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10479     {
10480       tree t = c_parser_paren_condition (parser);
10481       tree c;
10482
10483       check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
10484
10485       c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
10486       OMP_CLAUSE_FINAL_EXPR (c) = t;
10487       OMP_CLAUSE_CHAIN (c) = list;
10488       list = c;
10489     }
10490   else
10491     c_parser_error (parser, "expected %<(%>");
10492
10493   return list;
10494 }
10495
10496 /* OpenACC, OpenMP 2.5:
10497    if ( expression ) */
10498
10499 static tree
10500 c_parser_omp_clause_if (c_parser *parser, tree list)
10501 {
10502   location_t loc = c_parser_peek_token (parser)->location;
10503   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10504     {
10505       tree t = c_parser_paren_condition (parser);
10506       tree c;
10507
10508       check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
10509
10510       c = build_omp_clause (loc, OMP_CLAUSE_IF);
10511       OMP_CLAUSE_IF_EXPR (c) = t;
10512       OMP_CLAUSE_CHAIN (c) = list;
10513       list = c;
10514     }
10515   else
10516     c_parser_error (parser, "expected %<(%>");
10517
10518   return list;
10519 }
10520
10521 /* OpenMP 2.5:
10522    lastprivate ( variable-list ) */
10523
10524 static tree
10525 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
10526 {
10527   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
10528 }
10529
10530 /* OpenMP 3.1:
10531    mergeable */
10532
10533 static tree
10534 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10535 {
10536   tree c;
10537
10538   /* FIXME: Should we allow duplicates?  */
10539   check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
10540
10541   c = build_omp_clause (c_parser_peek_token (parser)->location,
10542                         OMP_CLAUSE_MERGEABLE);
10543   OMP_CLAUSE_CHAIN (c) = list;
10544
10545   return c;
10546 }
10547
10548 /* OpenMP 2.5:
10549    nowait */
10550
10551 static tree
10552 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10553 {
10554   tree c;
10555   location_t loc = c_parser_peek_token (parser)->location;
10556
10557   check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
10558
10559   c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
10560   OMP_CLAUSE_CHAIN (c) = list;
10561   return c;
10562 }
10563
10564 /* OpenACC:
10565    num_gangs ( expression ) */
10566
10567 static tree
10568 c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
10569 {
10570   location_t num_gangs_loc = c_parser_peek_token (parser)->location;
10571   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10572     {
10573       location_t expr_loc = c_parser_peek_token (parser)->location;
10574       tree c, t = c_parser_expression (parser).value;
10575       mark_exp_read (t);
10576       t = c_fully_fold (t, false, NULL);
10577
10578       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10579
10580       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10581         {
10582           c_parser_error (parser, "expected integer expression");
10583           return list;
10584         }
10585
10586       /* Attempt to statically determine when the number isn't positive.  */
10587       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10588                        build_int_cst (TREE_TYPE (t), 0));
10589       if (CAN_HAVE_LOCATION_P (c))
10590         SET_EXPR_LOCATION (c, expr_loc);
10591       if (c == boolean_true_node)
10592         {
10593           warning_at (expr_loc, 0,
10594                       "%<num_gangs%> value must be positive");
10595           t = integer_one_node;
10596         }
10597
10598       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
10599
10600       c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
10601       OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
10602       OMP_CLAUSE_CHAIN (c) = list;
10603       list = c;
10604     }
10605
10606   return list;
10607 }
10608
10609 /* OpenMP 2.5:
10610    num_threads ( expression ) */
10611
10612 static tree
10613 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
10614 {
10615   location_t num_threads_loc = c_parser_peek_token (parser)->location;
10616   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10617     {
10618       location_t expr_loc = c_parser_peek_token (parser)->location;
10619       tree c, t = c_parser_expression (parser).value;
10620       mark_exp_read (t);
10621       t = c_fully_fold (t, false, NULL);
10622
10623       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10624
10625       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10626         {
10627           c_parser_error (parser, "expected integer expression");
10628           return list;
10629         }
10630
10631       /* Attempt to statically determine when the number isn't positive.  */
10632       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10633                        build_int_cst (TREE_TYPE (t), 0));
10634       if (CAN_HAVE_LOCATION_P (c))
10635         SET_EXPR_LOCATION (c, expr_loc);
10636       if (c == boolean_true_node)
10637         {
10638           warning_at (expr_loc, 0,
10639                       "%<num_threads%> value must be positive");
10640           t = integer_one_node;
10641         }
10642
10643       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
10644
10645       c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
10646       OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
10647       OMP_CLAUSE_CHAIN (c) = list;
10648       list = c;
10649     }
10650
10651   return list;
10652 }
10653
10654 /* OpenACC:
10655    num_workers ( expression ) */
10656
10657 static tree
10658 c_parser_omp_clause_num_workers (c_parser *parser, tree list)
10659 {
10660   location_t num_workers_loc = c_parser_peek_token (parser)->location;
10661   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10662     {
10663       location_t expr_loc = c_parser_peek_token (parser)->location;
10664       tree c, t = c_parser_expression (parser).value;
10665       mark_exp_read (t);
10666       t = c_fully_fold (t, false, NULL);
10667
10668       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10669
10670       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10671         {
10672           c_parser_error (parser, "expected integer expression");
10673           return list;
10674         }
10675
10676       /* Attempt to statically determine when the number isn't positive.  */
10677       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10678                        build_int_cst (TREE_TYPE (t), 0));
10679       if (CAN_HAVE_LOCATION_P (c))
10680         SET_EXPR_LOCATION (c, expr_loc);
10681       if (c == boolean_true_node)
10682         {
10683           warning_at (expr_loc, 0,
10684                       "%<num_workers%> value must be positive");
10685           t = integer_one_node;
10686         }
10687
10688       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
10689
10690       c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
10691       OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
10692       OMP_CLAUSE_CHAIN (c) = list;
10693       list = c;
10694     }
10695
10696   return list;
10697 }
10698
10699 /* OpenACC:
10700    async [( int-expr )] */
10701
10702 static tree
10703 c_parser_oacc_clause_async (c_parser *parser, tree list)
10704 {
10705   tree c, t;
10706   location_t loc = c_parser_peek_token (parser)->location;
10707
10708   t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
10709
10710   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
10711     {
10712       c_parser_consume_token (parser);
10713
10714       t = c_parser_expression (parser).value;
10715       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10716         c_parser_error (parser, "expected integer expression");
10717       else if (t == error_mark_node
10718           || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
10719         return list;
10720     }
10721   else
10722     t = c_fully_fold (t, false, NULL);
10723
10724   check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
10725
10726   c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
10727   OMP_CLAUSE_ASYNC_EXPR (c) = t;
10728   OMP_CLAUSE_CHAIN (c) = list;
10729   list = c;
10730
10731   return list;
10732 }
10733
10734 /* OpenACC:
10735    wait ( int-expr-list ) */
10736
10737 static tree
10738 c_parser_oacc_clause_wait (c_parser *parser, tree list)
10739 {
10740   location_t clause_loc = c_parser_peek_token (parser)->location;
10741
10742   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
10743     list = c_parser_oacc_wait_list (parser, clause_loc, list);
10744
10745   return list;
10746 }
10747
10748 /* OpenMP 2.5:
10749    ordered */
10750
10751 static tree
10752 c_parser_omp_clause_ordered (c_parser *parser, tree list)
10753 {
10754   tree c;
10755
10756   check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
10757
10758   c = build_omp_clause (c_parser_peek_token (parser)->location,
10759                         OMP_CLAUSE_ORDERED);
10760   OMP_CLAUSE_CHAIN (c) = list;
10761
10762   return c;
10763 }
10764
10765 /* OpenMP 2.5:
10766    private ( variable-list ) */
10767
10768 static tree
10769 c_parser_omp_clause_private (c_parser *parser, tree list)
10770 {
10771   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
10772 }
10773
10774 /* OpenMP 2.5:
10775    reduction ( reduction-operator : variable-list )
10776
10777    reduction-operator:
10778      One of: + * - & ^ | && ||
10779
10780    OpenMP 3.1:
10781    
10782    reduction-operator:
10783      One of: + * - & ^ | && || max min
10784
10785    OpenMP 4.0:
10786
10787    reduction-operator:
10788      One of: + * - & ^ | && ||
10789      identifier  */
10790
10791 static tree
10792 c_parser_omp_clause_reduction (c_parser *parser, tree list)
10793 {
10794   location_t clause_loc = c_parser_peek_token (parser)->location;
10795   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10796     {
10797       enum tree_code code = ERROR_MARK;
10798       tree reduc_id = NULL_TREE;
10799
10800       switch (c_parser_peek_token (parser)->type)
10801         {
10802         case CPP_PLUS:
10803           code = PLUS_EXPR;
10804           break;
10805         case CPP_MULT:
10806           code = MULT_EXPR;
10807           break;
10808         case CPP_MINUS:
10809           code = MINUS_EXPR;
10810           break;
10811         case CPP_AND:
10812           code = BIT_AND_EXPR;
10813           break;
10814         case CPP_XOR:
10815           code = BIT_XOR_EXPR;
10816           break;
10817         case CPP_OR:
10818           code = BIT_IOR_EXPR;
10819           break;
10820         case CPP_AND_AND:
10821           code = TRUTH_ANDIF_EXPR;
10822           break;
10823         case CPP_OR_OR:
10824           code = TRUTH_ORIF_EXPR;
10825           break;
10826         case CPP_NAME:
10827           {
10828             const char *p
10829               = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10830             if (strcmp (p, "min") == 0)
10831               {
10832                 code = MIN_EXPR;
10833                 break;
10834               }
10835             if (strcmp (p, "max") == 0)
10836               {
10837                 code = MAX_EXPR;
10838                 break;
10839               }
10840             reduc_id = c_parser_peek_token (parser)->value;
10841             break;
10842           }
10843         default:
10844           c_parser_error (parser,
10845                           "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10846                           "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10847           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10848           return list;
10849         }
10850       c_parser_consume_token (parser);
10851       reduc_id = c_omp_reduction_id (code, reduc_id);
10852       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10853         {
10854           tree nl, c;
10855
10856           nl = c_parser_omp_variable_list (parser, clause_loc,
10857                                            OMP_CLAUSE_REDUCTION, list);
10858           for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10859             {
10860               tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
10861               OMP_CLAUSE_REDUCTION_CODE (c) = code;
10862               if (code == ERROR_MARK
10863                   || !(INTEGRAL_TYPE_P (type)
10864                        || TREE_CODE (type) == REAL_TYPE
10865                        || TREE_CODE (type) == COMPLEX_TYPE))
10866                 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
10867                   = c_omp_reduction_lookup (reduc_id,
10868                                             TYPE_MAIN_VARIANT (type));
10869             }
10870
10871           list = nl;
10872         }
10873       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10874     }
10875   return list;
10876 }
10877
10878 /* OpenMP 2.5:
10879    schedule ( schedule-kind )
10880    schedule ( schedule-kind , expression )
10881
10882    schedule-kind:
10883      static | dynamic | guided | runtime | auto
10884 */
10885
10886 static tree
10887 c_parser_omp_clause_schedule (c_parser *parser, tree list)
10888 {
10889   tree c, t;
10890   location_t loc = c_parser_peek_token (parser)->location;
10891
10892   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10893     return list;
10894
10895   c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
10896
10897   if (c_parser_next_token_is (parser, CPP_NAME))
10898     {
10899       tree kind = c_parser_peek_token (parser)->value;
10900       const char *p = IDENTIFIER_POINTER (kind);
10901
10902       switch (p[0])
10903         {
10904         case 'd':
10905           if (strcmp ("dynamic", p) != 0)
10906             goto invalid_kind;
10907           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
10908           break;
10909
10910         case 'g':
10911           if (strcmp ("guided", p) != 0)
10912             goto invalid_kind;
10913           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
10914           break;
10915
10916         case 'r':
10917           if (strcmp ("runtime", p) != 0)
10918             goto invalid_kind;
10919           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
10920           break;
10921
10922         default:
10923           goto invalid_kind;
10924         }
10925     }
10926   else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
10927     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
10928   else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
10929     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
10930   else
10931     goto invalid_kind;
10932
10933   c_parser_consume_token (parser);
10934   if (c_parser_next_token_is (parser, CPP_COMMA))
10935     {
10936       location_t here;
10937       c_parser_consume_token (parser);
10938
10939       here = c_parser_peek_token (parser)->location;
10940       t = c_parser_expr_no_commas (parser, NULL).value;
10941       mark_exp_read (t);
10942       t = c_fully_fold (t, false, NULL);
10943
10944       if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
10945         error_at (here, "schedule %<runtime%> does not take "
10946                   "a %<chunk_size%> parameter");
10947       else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
10948         error_at (here,
10949                   "schedule %<auto%> does not take "
10950                   "a %<chunk_size%> parameter");
10951       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
10952         OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
10953       else
10954         c_parser_error (parser, "expected integer expression");
10955
10956       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10957     }
10958   else
10959     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
10960                                "expected %<,%> or %<)%>");
10961
10962   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
10963   OMP_CLAUSE_CHAIN (c) = list;
10964   return c;
10965
10966  invalid_kind:
10967   c_parser_error (parser, "invalid schedule kind");
10968   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10969   return list;
10970 }
10971
10972 /* OpenMP 2.5:
10973    shared ( variable-list ) */
10974
10975 static tree
10976 c_parser_omp_clause_shared (c_parser *parser, tree list)
10977 {
10978   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
10979 }
10980
10981 /* OpenMP 3.0:
10982    untied */
10983
10984 static tree
10985 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10986 {
10987   tree c;
10988
10989   /* FIXME: Should we allow duplicates?  */
10990   check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
10991
10992   c = build_omp_clause (c_parser_peek_token (parser)->location,
10993                         OMP_CLAUSE_UNTIED);
10994   OMP_CLAUSE_CHAIN (c) = list;
10995
10996   return c;
10997 }
10998
10999 /* OpenACC:
11000    vector_length ( expression ) */
11001
11002 static tree
11003 c_parser_omp_clause_vector_length (c_parser *parser, tree list)
11004 {
11005   location_t vector_length_loc = c_parser_peek_token (parser)->location;
11006   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11007     {
11008       location_t expr_loc = c_parser_peek_token (parser)->location;
11009       tree c, t = c_parser_expression (parser).value;
11010       mark_exp_read (t);
11011       t = c_fully_fold (t, false, NULL);
11012
11013       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11014
11015       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11016         {
11017           c_parser_error (parser, "expected integer expression");
11018           return list;
11019         }
11020
11021       /* Attempt to statically determine when the number isn't positive.  */
11022       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11023                        build_int_cst (TREE_TYPE (t), 0));
11024       if (CAN_HAVE_LOCATION_P (c))
11025         SET_EXPR_LOCATION (c, expr_loc);
11026       if (c == boolean_true_node)
11027         {
11028           warning_at (expr_loc, 0,
11029                       "%<vector_length%> value must be positive");
11030           t = integer_one_node;
11031         }
11032
11033       check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
11034
11035       c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
11036       OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
11037       OMP_CLAUSE_CHAIN (c) = list;
11038       list = c;
11039     }
11040
11041   return list;
11042 }
11043
11044 /* OpenMP 4.0:
11045    inbranch
11046    notinbranch */
11047
11048 static tree
11049 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
11050                             enum omp_clause_code code, tree list)
11051 {
11052   check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11053
11054   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11055   OMP_CLAUSE_CHAIN (c) = list;
11056
11057   return c;
11058 }
11059
11060 /* OpenMP 4.0:
11061    parallel
11062    for
11063    sections
11064    taskgroup */
11065
11066 static tree
11067 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
11068                                 enum omp_clause_code code, tree list)
11069 {
11070   tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11071   OMP_CLAUSE_CHAIN (c) = list;
11072
11073   return c;
11074 }
11075
11076 /* OpenMP 4.0:
11077    num_teams ( expression ) */
11078
11079 static tree
11080 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
11081 {
11082   location_t num_teams_loc = c_parser_peek_token (parser)->location;
11083   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11084     {
11085       location_t expr_loc = c_parser_peek_token (parser)->location;
11086       tree c, t = c_parser_expression (parser).value;
11087       mark_exp_read (t);
11088       t = c_fully_fold (t, false, NULL);
11089
11090       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11091
11092       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11093         {
11094           c_parser_error (parser, "expected integer expression");
11095           return list;
11096         }
11097
11098       /* Attempt to statically determine when the number isn't positive.  */
11099       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11100                            build_int_cst (TREE_TYPE (t), 0));
11101       if (CAN_HAVE_LOCATION_P (c))
11102         SET_EXPR_LOCATION (c, expr_loc);
11103       if (c == boolean_true_node)
11104         {
11105           warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
11106           t = integer_one_node;
11107         }
11108
11109       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
11110
11111       c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
11112       OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
11113       OMP_CLAUSE_CHAIN (c) = list;
11114       list = c;
11115     }
11116
11117   return list;
11118 }
11119
11120 /* OpenMP 4.0:
11121    thread_limit ( expression ) */
11122
11123 static tree
11124 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
11125 {
11126   location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
11127   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11128     {
11129       location_t expr_loc = c_parser_peek_token (parser)->location;
11130       tree c, t = c_parser_expression (parser).value;
11131       mark_exp_read (t);
11132       t = c_fully_fold (t, false, NULL);
11133
11134       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11135
11136       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11137         {
11138           c_parser_error (parser, "expected integer expression");
11139           return list;
11140         }
11141
11142       /* Attempt to statically determine when the number isn't positive.  */
11143       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11144                            build_int_cst (TREE_TYPE (t), 0));
11145       if (CAN_HAVE_LOCATION_P (c))
11146         SET_EXPR_LOCATION (c, expr_loc);
11147       if (c == boolean_true_node)
11148         {
11149           warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
11150           t = integer_one_node;
11151         }
11152
11153       check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
11154                                  "thread_limit");
11155
11156       c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
11157       OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
11158       OMP_CLAUSE_CHAIN (c) = list;
11159       list = c;
11160     }
11161
11162   return list;
11163 }
11164
11165 /* OpenMP 4.0:
11166    aligned ( variable-list )
11167    aligned ( variable-list : constant-expression ) */
11168
11169 static tree
11170 c_parser_omp_clause_aligned (c_parser *parser, tree list)
11171 {
11172   location_t clause_loc = c_parser_peek_token (parser)->location;
11173   tree nl, c;
11174
11175   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11176     return list;
11177
11178   nl = c_parser_omp_variable_list (parser, clause_loc,
11179                                    OMP_CLAUSE_ALIGNED, list);
11180
11181   if (c_parser_next_token_is (parser, CPP_COLON))
11182     {
11183       c_parser_consume_token (parser);
11184       tree alignment = c_parser_expr_no_commas (parser, NULL).value;
11185       mark_exp_read (alignment);
11186       alignment = c_fully_fold (alignment, false, NULL);
11187       if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment))
11188           && TREE_CODE (alignment) != INTEGER_CST
11189           && tree_int_cst_sgn (alignment) != 1)
11190         {
11191           error_at (clause_loc, "%<aligned%> clause alignment expression must "
11192                                 "be positive constant integer expression");
11193           alignment = NULL_TREE;
11194         }
11195
11196       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11197         OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
11198     }
11199
11200   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11201   return nl;
11202 }
11203
11204 /* OpenMP 4.0:
11205    linear ( variable-list )
11206    linear ( variable-list : expression ) */
11207
11208 static tree
11209 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn)
11210 {
11211   location_t clause_loc = c_parser_peek_token (parser)->location;
11212   tree nl, c, step;
11213
11214   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11215     return list;
11216
11217   nl = c_parser_omp_variable_list (parser, clause_loc,
11218                                    OMP_CLAUSE_LINEAR, list);
11219
11220   if (c_parser_next_token_is (parser, CPP_COLON))
11221     {
11222       c_parser_consume_token (parser);
11223       step = c_parser_expression (parser).value;
11224       mark_exp_read (step);
11225       step = c_fully_fold (step, false, NULL);
11226       if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL)
11227         {
11228           sorry ("using parameters for %<linear%> step is not supported yet");
11229           step = integer_one_node;
11230         }
11231       if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
11232         {
11233           error_at (clause_loc, "%<linear%> clause step expression must "
11234                                 "be integral");
11235           step = integer_one_node;
11236         }
11237
11238     }
11239   else
11240     step = integer_one_node;
11241
11242   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11243     {
11244       OMP_CLAUSE_LINEAR_STEP (c) = step;
11245     }
11246
11247   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11248   return nl;
11249 }
11250
11251 /* OpenMP 4.0:
11252    safelen ( constant-expression ) */
11253
11254 static tree
11255 c_parser_omp_clause_safelen (c_parser *parser, tree list)
11256 {
11257   location_t clause_loc = c_parser_peek_token (parser)->location;
11258   tree c, t;
11259
11260   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11261     return list;
11262
11263   t = c_parser_expr_no_commas (parser, NULL).value;
11264   mark_exp_read (t);
11265   t = c_fully_fold (t, false, NULL);
11266   if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
11267       && TREE_CODE (t) != INTEGER_CST
11268       && tree_int_cst_sgn (t) != 1)
11269     {
11270       error_at (clause_loc, "%<safelen%> clause expression must "
11271                             "be positive constant integer expression");
11272       t = NULL_TREE;
11273     }
11274
11275   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11276   if (t == NULL_TREE || t == error_mark_node)
11277     return list;
11278
11279   check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
11280
11281   c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
11282   OMP_CLAUSE_SAFELEN_EXPR (c) = t;
11283   OMP_CLAUSE_CHAIN (c) = list;
11284   return c;
11285 }
11286
11287 /* OpenMP 4.0:
11288    simdlen ( constant-expression ) */
11289
11290 static tree
11291 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
11292 {
11293   location_t clause_loc = c_parser_peek_token (parser)->location;
11294   tree c, t;
11295
11296   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11297     return list;
11298
11299   t = c_parser_expr_no_commas (parser, NULL).value;
11300   mark_exp_read (t);
11301   t = c_fully_fold (t, false, NULL);
11302   if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
11303       && TREE_CODE (t) != INTEGER_CST
11304       && tree_int_cst_sgn (t) != 1)
11305     {
11306       error_at (clause_loc, "%<simdlen%> clause expression must "
11307                             "be positive constant integer expression");
11308       t = NULL_TREE;
11309     }
11310
11311   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11312   if (t == NULL_TREE || t == error_mark_node)
11313     return list;
11314
11315   check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
11316
11317   c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
11318   OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
11319   OMP_CLAUSE_CHAIN (c) = list;
11320   return c;
11321 }
11322
11323 /* OpenMP 4.0:
11324    depend ( depend-kind: variable-list )
11325
11326    depend-kind:
11327      in | out | inout  */
11328
11329 static tree
11330 c_parser_omp_clause_depend (c_parser *parser, tree list)
11331 {
11332   location_t clause_loc = c_parser_peek_token (parser)->location;
11333   enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
11334   tree nl, c;
11335
11336   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11337     return list;
11338
11339   if (c_parser_next_token_is (parser, CPP_NAME))
11340     {
11341       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11342       if (strcmp ("in", p) == 0)
11343         kind = OMP_CLAUSE_DEPEND_IN;
11344       else if (strcmp ("inout", p) == 0)
11345         kind = OMP_CLAUSE_DEPEND_INOUT;
11346       else if (strcmp ("out", p) == 0)
11347         kind = OMP_CLAUSE_DEPEND_OUT;
11348       else
11349         goto invalid_kind;
11350     }
11351   else
11352     goto invalid_kind;
11353
11354   c_parser_consume_token (parser);
11355   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11356     goto resync_fail;
11357
11358   nl = c_parser_omp_variable_list (parser, clause_loc,
11359                                    OMP_CLAUSE_DEPEND, list);
11360
11361   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11362     OMP_CLAUSE_DEPEND_KIND (c) = kind;
11363
11364   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11365   return nl;
11366
11367  invalid_kind:
11368   c_parser_error (parser, "invalid depend kind");
11369  resync_fail:
11370   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11371   return list;
11372 }
11373
11374 /* OpenMP 4.0:
11375    map ( map-kind: variable-list )
11376    map ( variable-list )
11377
11378    map-kind:
11379      alloc | to | from | tofrom  */
11380
11381 static tree
11382 c_parser_omp_clause_map (c_parser *parser, tree list)
11383 {
11384   location_t clause_loc = c_parser_peek_token (parser)->location;
11385   enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11386   tree nl, c;
11387
11388   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11389     return list;
11390
11391   if (c_parser_next_token_is (parser, CPP_NAME)
11392       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11393     {
11394       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11395       if (strcmp ("alloc", p) == 0)
11396         kind = GOMP_MAP_ALLOC;
11397       else if (strcmp ("to", p) == 0)
11398         kind = GOMP_MAP_TO;
11399       else if (strcmp ("from", p) == 0)
11400         kind = GOMP_MAP_FROM;
11401       else if (strcmp ("tofrom", p) == 0)
11402         kind = GOMP_MAP_TOFROM;
11403       else
11404         {
11405           c_parser_error (parser, "invalid map kind");
11406           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11407                                      "expected %<)%>");
11408           return list;
11409         }
11410       c_parser_consume_token (parser);
11411       c_parser_consume_token (parser);
11412     }
11413
11414   nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
11415
11416   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11417     OMP_CLAUSE_SET_MAP_KIND (c, kind);
11418
11419   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11420   return nl;
11421 }
11422
11423 /* OpenMP 4.0:
11424    device ( expression ) */
11425
11426 static tree
11427 c_parser_omp_clause_device (c_parser *parser, tree list)
11428 {
11429   location_t clause_loc = c_parser_peek_token (parser)->location;
11430   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11431     {
11432       tree c, t = c_parser_expr_no_commas (parser, NULL).value;
11433       mark_exp_read (t);
11434       t = c_fully_fold (t, false, NULL);
11435
11436       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11437
11438       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11439         {
11440           c_parser_error (parser, "expected integer expression");
11441           return list;
11442         }
11443
11444       check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
11445
11446       c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
11447       OMP_CLAUSE_DEVICE_ID (c) = t;
11448       OMP_CLAUSE_CHAIN (c) = list;
11449       list = c;
11450     }
11451
11452   return list;
11453 }
11454
11455 /* OpenMP 4.0:
11456    dist_schedule ( static )
11457    dist_schedule ( static , expression ) */
11458
11459 static tree
11460 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
11461 {
11462   tree c, t = NULL_TREE;
11463   location_t loc = c_parser_peek_token (parser)->location;
11464
11465   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11466     return list;
11467
11468   if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
11469     {
11470       c_parser_error (parser, "invalid dist_schedule kind");
11471       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11472                                  "expected %<)%>");
11473       return list;
11474     }
11475
11476   c_parser_consume_token (parser);
11477   if (c_parser_next_token_is (parser, CPP_COMMA))
11478     {
11479       c_parser_consume_token (parser);
11480
11481       t = c_parser_expr_no_commas (parser, NULL).value;
11482       mark_exp_read (t);
11483       t = c_fully_fold (t, false, NULL);
11484       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11485     }
11486   else
11487     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11488                                "expected %<,%> or %<)%>");
11489
11490   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
11491   if (t == error_mark_node)
11492     return list;
11493
11494   c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
11495   OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
11496   OMP_CLAUSE_CHAIN (c) = list;
11497   return c;
11498 }
11499
11500 /* OpenMP 4.0:
11501    proc_bind ( proc-bind-kind )
11502
11503    proc-bind-kind:
11504      master | close | spread  */
11505
11506 static tree
11507 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
11508 {
11509   location_t clause_loc = c_parser_peek_token (parser)->location;
11510   enum omp_clause_proc_bind_kind kind;
11511   tree c;
11512
11513   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11514     return list;
11515
11516   if (c_parser_next_token_is (parser, CPP_NAME))
11517     {
11518       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11519       if (strcmp ("master", p) == 0)
11520         kind = OMP_CLAUSE_PROC_BIND_MASTER;
11521       else if (strcmp ("close", p) == 0)
11522         kind = OMP_CLAUSE_PROC_BIND_CLOSE;
11523       else if (strcmp ("spread", p) == 0)
11524         kind = OMP_CLAUSE_PROC_BIND_SPREAD;
11525       else
11526         goto invalid_kind;
11527     }
11528   else
11529     goto invalid_kind;
11530
11531   c_parser_consume_token (parser);
11532   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11533   c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
11534   OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
11535   OMP_CLAUSE_CHAIN (c) = list;
11536   return c;
11537
11538  invalid_kind:
11539   c_parser_error (parser, "invalid proc_bind kind");
11540   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11541   return list;
11542 }
11543
11544 /* OpenMP 4.0:
11545    to ( variable-list ) */
11546
11547 static tree
11548 c_parser_omp_clause_to (c_parser *parser, tree list)
11549 {
11550   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
11551 }
11552
11553 /* OpenMP 4.0:
11554    from ( variable-list ) */
11555
11556 static tree
11557 c_parser_omp_clause_from (c_parser *parser, tree list)
11558 {
11559   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
11560 }
11561
11562 /* OpenMP 4.0:
11563    uniform ( variable-list ) */
11564
11565 static tree
11566 c_parser_omp_clause_uniform (c_parser *parser, tree list)
11567 {
11568   /* The clauses location.  */
11569   location_t loc = c_parser_peek_token (parser)->location;
11570
11571   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11572     {
11573       list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
11574                                          list);
11575       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11576     }
11577   return list;
11578 }
11579
11580 /* Parse all OpenACC clauses.  The set clauses allowed by the directive
11581    is a bitmask in MASK.  Return the list of clauses found.  */
11582
11583 static tree
11584 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
11585                            const char *where, bool finish_p = true)
11586 {
11587   tree clauses = NULL;
11588   bool first = true;
11589
11590   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11591     {
11592       location_t here;
11593       pragma_omp_clause c_kind;
11594       const char *c_name;
11595       tree prev = clauses;
11596
11597       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11598         c_parser_consume_token (parser);
11599
11600       here = c_parser_peek_token (parser)->location;
11601       c_kind = c_parser_omp_clause_name (parser);
11602
11603       switch (c_kind)
11604         {
11605         case PRAGMA_OACC_CLAUSE_ASYNC:
11606           clauses = c_parser_oacc_clause_async (parser, clauses);
11607           c_name = "async";
11608           break;
11609         case PRAGMA_OACC_CLAUSE_COLLAPSE:
11610           clauses = c_parser_omp_clause_collapse (parser, clauses);
11611           c_name = "collapse";
11612           break;
11613         case PRAGMA_OACC_CLAUSE_COPY:
11614           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11615           c_name = "copy";
11616           break;
11617         case PRAGMA_OACC_CLAUSE_COPYIN:
11618           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11619           c_name = "copyin";
11620           break;
11621         case PRAGMA_OACC_CLAUSE_COPYOUT:
11622           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11623           c_name = "copyout";
11624           break;
11625         case PRAGMA_OACC_CLAUSE_CREATE:
11626           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11627           c_name = "create";
11628           break;
11629         case PRAGMA_OACC_CLAUSE_DELETE:
11630           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11631           c_name = "delete";
11632           break;
11633         case PRAGMA_OACC_CLAUSE_DEVICE:
11634           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11635           c_name = "device";
11636           break;
11637         case PRAGMA_OACC_CLAUSE_DEVICEPTR:
11638           clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
11639           c_name = "deviceptr";
11640           break;
11641         case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
11642           clauses = c_parser_omp_clause_firstprivate (parser, clauses);
11643           c_name = "firstprivate";
11644           break;
11645         case PRAGMA_OACC_CLAUSE_HOST:
11646           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11647           c_name = "host";
11648           break;
11649         case PRAGMA_OACC_CLAUSE_IF:
11650           clauses = c_parser_omp_clause_if (parser, clauses);
11651           c_name = "if";
11652           break;
11653         case PRAGMA_OACC_CLAUSE_NUM_GANGS:
11654           clauses = c_parser_omp_clause_num_gangs (parser, clauses);
11655           c_name = "num_gangs";
11656           break;
11657         case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
11658           clauses = c_parser_omp_clause_num_workers (parser, clauses);
11659           c_name = "num_workers";
11660           break;
11661         case PRAGMA_OACC_CLAUSE_PRESENT:
11662           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11663           c_name = "present";
11664           break;
11665         case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
11666           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11667           c_name = "present_or_copy";
11668           break;
11669         case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
11670           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11671           c_name = "present_or_copyin";
11672           break;
11673         case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
11674           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11675           c_name = "present_or_copyout";
11676           break;
11677         case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
11678           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11679           c_name = "present_or_create";
11680           break;
11681         case PRAGMA_OACC_CLAUSE_PRIVATE:
11682           clauses = c_parser_omp_clause_private (parser, clauses);
11683           c_name = "private";
11684           break;
11685         case PRAGMA_OACC_CLAUSE_REDUCTION:
11686           clauses = c_parser_omp_clause_reduction (parser, clauses);
11687           c_name = "reduction";
11688           break;
11689         case PRAGMA_OACC_CLAUSE_SELF:
11690           clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11691           c_name = "self";
11692           break;
11693         case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
11694           clauses = c_parser_omp_clause_vector_length (parser, clauses);
11695           c_name = "vector_length";
11696           break;
11697         case PRAGMA_OACC_CLAUSE_WAIT:
11698           clauses = c_parser_oacc_clause_wait (parser, clauses);
11699           c_name = "wait";
11700           break;
11701         default:
11702           c_parser_error (parser, "expected %<#pragma acc%> clause");
11703           goto saw_error;
11704         }
11705
11706       first = false;
11707
11708       if (((mask >> c_kind) & 1) == 0 && !parser->error)
11709         {
11710           /* Remove the invalid clause(s) from the list to avoid
11711              confusing the rest of the compiler.  */
11712           clauses = prev;
11713           error_at (here, "%qs is not valid for %qs", c_name, where);
11714         }
11715     }
11716
11717  saw_error:
11718   c_parser_skip_to_pragma_eol (parser);
11719
11720   if (finish_p)
11721     return c_finish_omp_clauses (clauses);
11722
11723   return clauses;
11724 }
11725
11726 /* Parse all OpenMP clauses.  The set clauses allowed by the directive
11727    is a bitmask in MASK.  Return the list of clauses found.  */
11728
11729 static tree
11730 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
11731                           const char *where, bool finish_p = true)
11732 {
11733   tree clauses = NULL;
11734   bool first = true, cilk_simd_fn = false;
11735
11736   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11737     {
11738       location_t here;
11739       pragma_omp_clause c_kind;
11740       const char *c_name;
11741       tree prev = clauses;
11742
11743       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11744         c_parser_consume_token (parser);
11745
11746       here = c_parser_peek_token (parser)->location;
11747       c_kind = c_parser_omp_clause_name (parser);
11748
11749       switch (c_kind)
11750         {
11751         case PRAGMA_OMP_CLAUSE_COLLAPSE:
11752           clauses = c_parser_omp_clause_collapse (parser, clauses);
11753           c_name = "collapse";
11754           break;
11755         case PRAGMA_OMP_CLAUSE_COPYIN:
11756           clauses = c_parser_omp_clause_copyin (parser, clauses);
11757           c_name = "copyin";
11758           break;
11759         case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
11760           clauses = c_parser_omp_clause_copyprivate (parser, clauses);
11761           c_name = "copyprivate";
11762           break;
11763         case PRAGMA_OMP_CLAUSE_DEFAULT:
11764           clauses = c_parser_omp_clause_default (parser, clauses);
11765           c_name = "default";
11766           break;
11767         case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
11768           clauses = c_parser_omp_clause_firstprivate (parser, clauses);
11769           c_name = "firstprivate";
11770           break;
11771         case PRAGMA_OMP_CLAUSE_FINAL:
11772           clauses = c_parser_omp_clause_final (parser, clauses);
11773           c_name = "final";
11774           break;
11775         case PRAGMA_OMP_CLAUSE_IF:
11776           clauses = c_parser_omp_clause_if (parser, clauses);
11777           c_name = "if";
11778           break;
11779         case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
11780           clauses = c_parser_omp_clause_lastprivate (parser, clauses);
11781           c_name = "lastprivate";
11782           break;
11783         case PRAGMA_OMP_CLAUSE_MERGEABLE:
11784           clauses = c_parser_omp_clause_mergeable (parser, clauses);
11785           c_name = "mergeable";
11786           break;
11787         case PRAGMA_OMP_CLAUSE_NOWAIT:
11788           clauses = c_parser_omp_clause_nowait (parser, clauses);
11789           c_name = "nowait";
11790           break;
11791         case PRAGMA_OMP_CLAUSE_NUM_THREADS:
11792           clauses = c_parser_omp_clause_num_threads (parser, clauses);
11793           c_name = "num_threads";
11794           break;
11795         case PRAGMA_OMP_CLAUSE_ORDERED:
11796           clauses = c_parser_omp_clause_ordered (parser, clauses);
11797           c_name = "ordered";
11798           break;
11799         case PRAGMA_OMP_CLAUSE_PRIVATE:
11800           clauses = c_parser_omp_clause_private (parser, clauses);
11801           c_name = "private";
11802           break;
11803         case PRAGMA_OMP_CLAUSE_REDUCTION:
11804           clauses = c_parser_omp_clause_reduction (parser, clauses);
11805           c_name = "reduction";
11806           break;
11807         case PRAGMA_OMP_CLAUSE_SCHEDULE:
11808           clauses = c_parser_omp_clause_schedule (parser, clauses);
11809           c_name = "schedule";
11810           break;
11811         case PRAGMA_OMP_CLAUSE_SHARED:
11812           clauses = c_parser_omp_clause_shared (parser, clauses);
11813           c_name = "shared";
11814           break;
11815         case PRAGMA_OMP_CLAUSE_UNTIED:
11816           clauses = c_parser_omp_clause_untied (parser, clauses);
11817           c_name = "untied";
11818           break;
11819         case PRAGMA_OMP_CLAUSE_INBRANCH:
11820         case PRAGMA_CILK_CLAUSE_MASK:
11821           clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
11822                                                 clauses);
11823           c_name = "inbranch";
11824           break;
11825         case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
11826         case PRAGMA_CILK_CLAUSE_NOMASK:
11827           clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
11828                                                 clauses);
11829           c_name = "notinbranch";
11830           break;
11831         case PRAGMA_OMP_CLAUSE_PARALLEL:
11832           clauses
11833             = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
11834                                               clauses);
11835           c_name = "parallel";
11836           if (!first)
11837             {
11838              clause_not_first:
11839               error_at (here, "%qs must be the first clause of %qs",
11840                         c_name, where);
11841               clauses = prev;
11842             }
11843           break;
11844         case PRAGMA_OMP_CLAUSE_FOR:
11845           clauses
11846             = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
11847                                               clauses);
11848           c_name = "for";
11849           if (!first)
11850             goto clause_not_first;
11851           break;
11852         case PRAGMA_OMP_CLAUSE_SECTIONS:
11853           clauses
11854             = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
11855                                               clauses);
11856           c_name = "sections";
11857           if (!first)
11858             goto clause_not_first;
11859           break;
11860         case PRAGMA_OMP_CLAUSE_TASKGROUP:
11861           clauses
11862             = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
11863                                               clauses);
11864           c_name = "taskgroup";
11865           if (!first)
11866             goto clause_not_first;
11867           break;
11868         case PRAGMA_OMP_CLAUSE_TO:
11869           clauses = c_parser_omp_clause_to (parser, clauses);
11870           c_name = "to";
11871           break;
11872         case PRAGMA_OMP_CLAUSE_FROM:
11873           clauses = c_parser_omp_clause_from (parser, clauses);
11874           c_name = "from";
11875           break;
11876         case PRAGMA_OMP_CLAUSE_UNIFORM:
11877           clauses = c_parser_omp_clause_uniform (parser, clauses);
11878           c_name = "uniform";
11879           break;
11880         case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
11881           clauses = c_parser_omp_clause_num_teams (parser, clauses);
11882           c_name = "num_teams";
11883           break;
11884         case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
11885           clauses = c_parser_omp_clause_thread_limit (parser, clauses);
11886           c_name = "thread_limit";
11887           break;
11888         case PRAGMA_OMP_CLAUSE_ALIGNED:
11889           clauses = c_parser_omp_clause_aligned (parser, clauses);
11890           c_name = "aligned";
11891           break;
11892         case PRAGMA_OMP_CLAUSE_LINEAR: 
11893           if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0)
11894            cilk_simd_fn = true; 
11895           clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn); 
11896           c_name = "linear";
11897           break;
11898         case PRAGMA_OMP_CLAUSE_DEPEND:
11899           clauses = c_parser_omp_clause_depend (parser, clauses);
11900           c_name = "depend";
11901           break;
11902         case PRAGMA_OMP_CLAUSE_MAP:
11903           clauses = c_parser_omp_clause_map (parser, clauses);
11904           c_name = "map";
11905           break;
11906         case PRAGMA_OMP_CLAUSE_DEVICE:
11907           clauses = c_parser_omp_clause_device (parser, clauses);
11908           c_name = "device";
11909           break;
11910         case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
11911           clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
11912           c_name = "dist_schedule";
11913           break;
11914         case PRAGMA_OMP_CLAUSE_PROC_BIND:
11915           clauses = c_parser_omp_clause_proc_bind (parser, clauses);
11916           c_name = "proc_bind";
11917           break;
11918         case PRAGMA_OMP_CLAUSE_SAFELEN:
11919           clauses = c_parser_omp_clause_safelen (parser, clauses);
11920           c_name = "safelen";
11921           break;
11922         case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
11923           clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true);
11924           c_name = "simdlen";
11925           break;
11926         case PRAGMA_OMP_CLAUSE_SIMDLEN:
11927           clauses = c_parser_omp_clause_simdlen (parser, clauses);
11928           c_name = "simdlen";
11929           break;
11930         default:
11931           c_parser_error (parser, "expected %<#pragma omp%> clause");
11932           goto saw_error;
11933         }
11934
11935       first = false;
11936
11937       if (((mask >> c_kind) & 1) == 0 && !parser->error)
11938         {
11939           /* Remove the invalid clause(s) from the list to avoid
11940              confusing the rest of the compiler.  */
11941           clauses = prev;
11942           error_at (here, "%qs is not valid for %qs", c_name, where);
11943         }
11944     }
11945
11946  saw_error:
11947   c_parser_skip_to_pragma_eol (parser);
11948
11949   if (finish_p)
11950     return c_finish_omp_clauses (clauses);
11951
11952   return clauses;
11953 }
11954
11955 /* OpenACC 2.0, OpenMP 2.5:
11956    structured-block:
11957      statement
11958
11959    In practice, we're also interested in adding the statement to an
11960    outer node.  So it is convenient if we work around the fact that
11961    c_parser_statement calls add_stmt.  */
11962
11963 static tree
11964 c_parser_omp_structured_block (c_parser *parser)
11965 {
11966   tree stmt = push_stmt_list ();
11967   c_parser_statement (parser);
11968   return pop_stmt_list (stmt);
11969 }
11970
11971 /* OpenACC 2.0:
11972    # pragma acc cache (variable-list) new-line
11973
11974    LOC is the location of the #pragma token.
11975 */
11976
11977 static tree
11978 c_parser_oacc_cache (location_t loc, c_parser *parser)
11979 {
11980   tree stmt, clauses;
11981
11982   clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
11983   clauses = c_finish_omp_clauses (clauses);
11984
11985   c_parser_skip_to_pragma_eol (parser);
11986
11987   stmt = make_node (OACC_CACHE);
11988   TREE_TYPE (stmt) = void_type_node;
11989   OACC_CACHE_CLAUSES (stmt) = clauses;
11990   SET_EXPR_LOCATION (stmt, loc);
11991   add_stmt (stmt);
11992
11993   return stmt;
11994 }
11995
11996 /* OpenACC 2.0:
11997    # pragma acc data oacc-data-clause[optseq] new-line
11998      structured-block
11999
12000    LOC is the location of the #pragma token.
12001 */
12002
12003 #define OACC_DATA_CLAUSE_MASK                                           \
12004         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)                \
12005         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)              \
12006         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)             \
12007         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)              \
12008         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)           \
12009         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)                  \
12010         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)             \
12011         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)     \
12012         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)   \
12013         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)  \
12014         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12015
12016 static tree
12017 c_parser_oacc_data (location_t loc, c_parser *parser)
12018 {
12019   tree stmt, clauses, block;
12020
12021   clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
12022                                        "#pragma acc data");
12023
12024   block = c_begin_omp_parallel ();
12025   add_stmt (c_parser_omp_structured_block (parser));
12026
12027   stmt = c_finish_oacc_data (loc, clauses, block);
12028
12029   return stmt;
12030 }
12031
12032 /* OpenACC 2.0:
12033    # pragma acc kernels oacc-kernels-clause[optseq] new-line
12034      structured-block
12035
12036    LOC is the location of the #pragma token.
12037 */
12038
12039 #define OACC_KERNELS_CLAUSE_MASK                                        \
12040         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)               \
12041         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)                \
12042         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)              \
12043         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)             \
12044         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)              \
12045         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)           \
12046         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)                  \
12047         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)             \
12048         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)     \
12049         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)   \
12050         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)  \
12051         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)   \
12052         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12053
12054 static tree
12055 c_parser_oacc_kernels (location_t loc, c_parser *parser, char *p_name)
12056 {
12057   tree stmt, clauses = NULL_TREE, block;
12058
12059   strcat (p_name, " kernels");
12060
12061   if (c_parser_next_token_is (parser, CPP_NAME))
12062     {
12063       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12064       if (strcmp (p, "loop") == 0)
12065         {
12066           c_parser_consume_token (parser);
12067           block = c_begin_omp_parallel ();
12068           c_parser_oacc_loop (loc, parser, p_name);
12069           stmt = c_finish_oacc_kernels (loc, clauses, block);
12070           OACC_KERNELS_COMBINED (stmt) = 1;
12071           return stmt;
12072         }
12073     }
12074
12075   clauses =  c_parser_oacc_all_clauses (parser, OACC_KERNELS_CLAUSE_MASK,
12076                                         p_name);
12077
12078   block = c_begin_omp_parallel ();
12079   add_stmt (c_parser_omp_structured_block (parser));
12080
12081   stmt = c_finish_oacc_kernels (loc, clauses, block);
12082
12083   return stmt;
12084 }
12085
12086 /* OpenACC 2.0:
12087    # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12088
12089    or
12090
12091    # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12092
12093
12094    LOC is the location of the #pragma token.
12095 */
12096
12097 #define OACC_ENTER_DATA_CLAUSE_MASK                                     \
12098         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)                  \
12099         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)               \
12100         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)              \
12101         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)              \
12102         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)   \
12103         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)   \
12104         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12105
12106 #define OACC_EXIT_DATA_CLAUSE_MASK                                      \
12107         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)                  \
12108         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)               \
12109         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)             \
12110         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE)              \
12111         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12112
12113 static void
12114 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
12115 {
12116   location_t loc = c_parser_peek_token (parser)->location;
12117   tree clauses, stmt;
12118
12119   c_parser_consume_pragma (parser);
12120
12121   if (!c_parser_next_token_is (parser, CPP_NAME))
12122     {
12123       c_parser_error (parser, enter
12124                       ? "expected %<data%> in %<#pragma acc enter data%>"
12125                       : "expected %<data%> in %<#pragma acc exit data%>");
12126       c_parser_skip_to_pragma_eol (parser);
12127       return;
12128     }
12129
12130   const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12131   if (strcmp (p, "data") != 0)
12132     {
12133       c_parser_error (parser, "invalid pragma");
12134       c_parser_skip_to_pragma_eol (parser);
12135       return;
12136     }
12137
12138   c_parser_consume_token (parser);
12139
12140   if (enter)
12141     clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
12142                                          "#pragma acc enter data");
12143   else
12144     clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
12145                                          "#pragma acc exit data");
12146
12147   if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12148     {
12149       error_at (loc, enter
12150                 ? "%<#pragma acc enter data%> has no data movement clause"
12151                 : "%<#pragma acc exit data%> has no data movement clause");
12152       return;
12153     }
12154
12155   stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);;
12156   TREE_TYPE (stmt) = void_type_node;
12157   if (enter)
12158     OACC_ENTER_DATA_CLAUSES (stmt) = clauses;
12159   else
12160     OACC_EXIT_DATA_CLAUSES (stmt) = clauses;
12161   SET_EXPR_LOCATION (stmt, loc);
12162   add_stmt (stmt);
12163 }
12164
12165
12166 /* OpenACC 2.0:
12167
12168    # pragma acc loop oacc-loop-clause[optseq] new-line
12169      structured-block
12170
12171    LOC is the location of the #pragma token.
12172 */
12173
12174 #define OACC_LOOP_CLAUSE_MASK                                           \
12175         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE)            \
12176         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12177
12178 static tree
12179 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name)
12180 {
12181   tree stmt, clauses, block;
12182
12183   strcat (p_name, " loop");
12184
12185   clauses = c_parser_oacc_all_clauses (parser, OACC_LOOP_CLAUSE_MASK, p_name);
12186
12187   block = c_begin_compound_stmt (true);
12188   stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL);
12189   block = c_end_compound_stmt (loc, block, true);
12190   add_stmt (block);
12191
12192   return stmt;
12193 }
12194
12195 /* OpenACC 2.0:
12196    # pragma acc parallel oacc-parallel-clause[optseq] new-line
12197      structured-block
12198
12199    LOC is the location of the #pragma token.
12200 */
12201
12202 #define OACC_PARALLEL_CLAUSE_MASK                                       \
12203         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)               \
12204         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY)                \
12205         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN)              \
12206         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT)             \
12207         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE)              \
12208         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)           \
12209         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)                  \
12210         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS)           \
12211         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS)         \
12212         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT)             \
12213         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY)     \
12214         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)   \
12215         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)  \
12216         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)   \
12217         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION)           \
12218         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH)       \
12219         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12220
12221 static tree
12222 c_parser_oacc_parallel (location_t loc, c_parser *parser, char *p_name)
12223 {
12224   tree stmt, clauses = NULL_TREE, block;
12225
12226   strcat (p_name, " parallel");
12227
12228   if (c_parser_next_token_is (parser, CPP_NAME))
12229     {
12230       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12231       if (strcmp (p, "loop") == 0)
12232         {
12233           c_parser_consume_token (parser);
12234           block = c_begin_omp_parallel ();
12235           c_parser_oacc_loop (loc, parser, p_name);
12236           stmt = c_finish_oacc_parallel (loc, clauses, block);
12237           OACC_PARALLEL_COMBINED (stmt) = 1;
12238           return stmt;
12239         }
12240     }
12241
12242   clauses =  c_parser_oacc_all_clauses (parser, OACC_PARALLEL_CLAUSE_MASK,
12243                                         p_name);
12244
12245   block = c_begin_omp_parallel ();
12246   add_stmt (c_parser_omp_structured_block (parser));
12247
12248   stmt = c_finish_oacc_parallel (loc, clauses, block);
12249
12250   return stmt;
12251 }
12252
12253 /* OpenACC 2.0:
12254    # pragma acc update oacc-update-clause[optseq] new-line
12255 */
12256
12257 #define OACC_UPDATE_CLAUSE_MASK                                         \
12258         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC)               \
12259         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE)              \
12260         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)                \
12261         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)                  \
12262         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF)                \
12263         | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12264
12265 static void
12266 c_parser_oacc_update (c_parser *parser)
12267 {
12268   location_t loc = c_parser_peek_token (parser)->location;
12269
12270   c_parser_consume_pragma (parser);
12271
12272   tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
12273                                             "#pragma acc update");
12274   if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12275     {
12276       error_at (loc,
12277                 "%<#pragma acc update%> must contain at least one "
12278                 "%<device%> or %<host/self%> clause");
12279       return;
12280     }
12281
12282   if (parser->error)
12283     return;
12284
12285   tree stmt = make_node (OACC_UPDATE);
12286   TREE_TYPE (stmt) = void_type_node;
12287   OACC_UPDATE_CLAUSES (stmt) = clauses;
12288   SET_EXPR_LOCATION (stmt, loc);
12289   add_stmt (stmt);
12290 }
12291
12292 /* OpenACC 2.0:
12293    # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12294
12295    LOC is the location of the #pragma token.
12296 */
12297
12298 #define OACC_WAIT_CLAUSE_MASK                                           \
12299         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12300
12301 static tree
12302 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
12303 {
12304   tree clauses, list = NULL_TREE, stmt = NULL_TREE;
12305
12306   if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12307     list = c_parser_oacc_wait_list (parser, loc, list);
12308
12309   strcpy (p_name, " wait");
12310   clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
12311   stmt = c_finish_oacc_wait (loc, list, clauses);
12312
12313   return stmt;
12314 }
12315
12316 /* OpenMP 2.5:
12317    # pragma omp atomic new-line
12318      expression-stmt
12319
12320    expression-stmt:
12321      x binop= expr | x++ | ++x | x-- | --x
12322    binop:
12323      +, *, -, /, &, ^, |, <<, >>
12324
12325   where x is an lvalue expression with scalar type.
12326
12327    OpenMP 3.1:
12328    # pragma omp atomic new-line
12329      update-stmt
12330
12331    # pragma omp atomic read new-line
12332      read-stmt
12333
12334    # pragma omp atomic write new-line
12335      write-stmt
12336
12337    # pragma omp atomic update new-line
12338      update-stmt
12339
12340    # pragma omp atomic capture new-line
12341      capture-stmt
12342
12343    # pragma omp atomic capture new-line
12344      capture-block
12345
12346    read-stmt:
12347      v = x
12348    write-stmt:
12349      x = expr
12350    update-stmt:
12351      expression-stmt | x = x binop expr
12352    capture-stmt:
12353      v = expression-stmt
12354    capture-block:
12355      { v = x; update-stmt; } | { update-stmt; v = x; }
12356
12357    OpenMP 4.0:
12358    update-stmt:
12359      expression-stmt | x = x binop expr | x = expr binop x
12360    capture-stmt:
12361      v = update-stmt
12362    capture-block:
12363      { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12364
12365   where x and v are lvalue expressions with scalar type.
12366
12367   LOC is the location of the #pragma token.  */
12368
12369 static void
12370 c_parser_omp_atomic (location_t loc, c_parser *parser)
12371 {
12372   tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
12373   tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
12374   tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
12375   enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
12376   struct c_expr expr;
12377   location_t eloc;
12378   bool structured_block = false;
12379   bool swapped = false;
12380   bool seq_cst = false;
12381
12382   if (c_parser_next_token_is (parser, CPP_NAME))
12383     {
12384       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12385       if (!strcmp (p, "seq_cst"))
12386         {
12387           seq_cst = true;
12388           c_parser_consume_token (parser);
12389           if (c_parser_next_token_is (parser, CPP_COMMA)
12390               && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12391             c_parser_consume_token (parser);
12392         }
12393     }
12394   if (c_parser_next_token_is (parser, CPP_NAME))
12395     {
12396       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12397
12398       if (!strcmp (p, "read"))
12399         code = OMP_ATOMIC_READ;
12400       else if (!strcmp (p, "write"))
12401         code = NOP_EXPR;
12402       else if (!strcmp (p, "update"))
12403         code = OMP_ATOMIC;
12404       else if (!strcmp (p, "capture"))
12405         code = OMP_ATOMIC_CAPTURE_NEW;
12406       else
12407         p = NULL;
12408       if (p)
12409         c_parser_consume_token (parser);
12410     }
12411   if (!seq_cst)
12412     {
12413       if (c_parser_next_token_is (parser, CPP_COMMA)
12414           && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12415         c_parser_consume_token (parser);
12416
12417       if (c_parser_next_token_is (parser, CPP_NAME))
12418         {
12419           const char *p
12420             = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12421           if (!strcmp (p, "seq_cst"))
12422             {
12423               seq_cst = true;
12424               c_parser_consume_token (parser);
12425             }
12426         }
12427     }
12428   c_parser_skip_to_pragma_eol (parser);
12429
12430   switch (code)
12431     {
12432     case OMP_ATOMIC_READ:
12433     case NOP_EXPR: /* atomic write */
12434       v = c_parser_unary_expression (parser).value;
12435       v = c_fully_fold (v, false, NULL);
12436       if (v == error_mark_node)
12437         goto saw_error;
12438       loc = c_parser_peek_token (parser)->location;
12439       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12440         goto saw_error;
12441       if (code == NOP_EXPR)
12442         lhs = c_parser_expression (parser).value;
12443       else
12444         lhs = c_parser_unary_expression (parser).value;
12445       lhs = c_fully_fold (lhs, false, NULL);
12446       if (lhs == error_mark_node)
12447         goto saw_error;
12448       if (code == NOP_EXPR)
12449         {
12450           /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12451              opcode.  */
12452           code = OMP_ATOMIC;
12453           rhs = lhs;
12454           lhs = v;
12455           v = NULL_TREE;
12456         }
12457       goto done;
12458     case OMP_ATOMIC_CAPTURE_NEW:
12459       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
12460         {
12461           c_parser_consume_token (parser);
12462           structured_block = true;
12463         }
12464       else
12465         {
12466           v = c_parser_unary_expression (parser).value;
12467           v = c_fully_fold (v, false, NULL);
12468           if (v == error_mark_node)
12469             goto saw_error;
12470           if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12471             goto saw_error;
12472         }
12473       break;
12474     default:
12475       break;
12476     }
12477
12478   /* For structured_block case we don't know yet whether
12479      old or new x should be captured.  */
12480 restart:
12481   eloc = c_parser_peek_token (parser)->location;
12482   expr = c_parser_unary_expression (parser);
12483   lhs = expr.value;
12484   expr = default_function_array_conversion (eloc, expr);
12485   unfolded_lhs = expr.value;
12486   lhs = c_fully_fold (lhs, false, NULL);
12487   orig_lhs = lhs;
12488   switch (TREE_CODE (lhs))
12489     {
12490     case ERROR_MARK:
12491     saw_error:
12492       c_parser_skip_to_end_of_block_or_statement (parser);
12493       if (structured_block)
12494         {
12495           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12496             c_parser_consume_token (parser);
12497           else if (code == OMP_ATOMIC_CAPTURE_NEW)
12498             {
12499               c_parser_skip_to_end_of_block_or_statement (parser);
12500               if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12501                 c_parser_consume_token (parser);
12502             }
12503         }
12504       return;
12505
12506     case POSTINCREMENT_EXPR:
12507       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12508         code = OMP_ATOMIC_CAPTURE_OLD;
12509       /* FALLTHROUGH */
12510     case PREINCREMENT_EXPR:
12511       lhs = TREE_OPERAND (lhs, 0);
12512       unfolded_lhs = NULL_TREE;
12513       opcode = PLUS_EXPR;
12514       rhs = integer_one_node;
12515       break;
12516
12517     case POSTDECREMENT_EXPR:
12518       if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12519         code = OMP_ATOMIC_CAPTURE_OLD;
12520       /* FALLTHROUGH */
12521     case PREDECREMENT_EXPR:
12522       lhs = TREE_OPERAND (lhs, 0);
12523       unfolded_lhs = NULL_TREE;
12524       opcode = MINUS_EXPR;
12525       rhs = integer_one_node;
12526       break;
12527
12528     case COMPOUND_EXPR:
12529       if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
12530           && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
12531           && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
12532           && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
12533           && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12534                                               (TREE_OPERAND (lhs, 1), 0), 0)))
12535              == BOOLEAN_TYPE)
12536         /* Undo effects of boolean_increment for post {in,de}crement.  */
12537         lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
12538       /* FALLTHRU */
12539     case MODIFY_EXPR:
12540       if (TREE_CODE (lhs) == MODIFY_EXPR
12541           && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
12542         {
12543           /* Undo effects of boolean_increment.  */
12544           if (integer_onep (TREE_OPERAND (lhs, 1)))
12545             {
12546               /* This is pre or post increment.  */
12547               rhs = TREE_OPERAND (lhs, 1);
12548               lhs = TREE_OPERAND (lhs, 0);
12549               unfolded_lhs = NULL_TREE;
12550               opcode = NOP_EXPR;
12551               if (code == OMP_ATOMIC_CAPTURE_NEW
12552                   && !structured_block
12553                   && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12554                 code = OMP_ATOMIC_CAPTURE_OLD;
12555               break;
12556             }
12557           if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
12558               && TREE_OPERAND (lhs, 0)
12559                  == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
12560             {
12561               /* This is pre or post decrement.  */
12562               rhs = TREE_OPERAND (lhs, 1);
12563               lhs = TREE_OPERAND (lhs, 0);
12564               unfolded_lhs = NULL_TREE;
12565               opcode = NOP_EXPR;
12566               if (code == OMP_ATOMIC_CAPTURE_NEW
12567                   && !structured_block
12568                   && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12569                 code = OMP_ATOMIC_CAPTURE_OLD;
12570               break;
12571             }
12572         }
12573       /* FALLTHRU */
12574     default:
12575       switch (c_parser_peek_token (parser)->type)
12576         {
12577         case CPP_MULT_EQ:
12578           opcode = MULT_EXPR;
12579           break;
12580         case CPP_DIV_EQ:
12581           opcode = TRUNC_DIV_EXPR;
12582           break;
12583         case CPP_PLUS_EQ:
12584           opcode = PLUS_EXPR;
12585           break;
12586         case CPP_MINUS_EQ:
12587           opcode = MINUS_EXPR;
12588           break;
12589         case CPP_LSHIFT_EQ:
12590           opcode = LSHIFT_EXPR;
12591           break;
12592         case CPP_RSHIFT_EQ:
12593           opcode = RSHIFT_EXPR;
12594           break;
12595         case CPP_AND_EQ:
12596           opcode = BIT_AND_EXPR;
12597           break;
12598         case CPP_OR_EQ:
12599           opcode = BIT_IOR_EXPR;
12600           break;
12601         case CPP_XOR_EQ:
12602           opcode = BIT_XOR_EXPR;
12603           break;
12604         case CPP_EQ:
12605           c_parser_consume_token (parser);
12606           eloc = c_parser_peek_token (parser)->location;
12607           expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
12608           rhs1 = expr.value;
12609           switch (TREE_CODE (rhs1))
12610             {
12611             case MULT_EXPR:
12612             case TRUNC_DIV_EXPR:
12613             case PLUS_EXPR:
12614             case MINUS_EXPR:
12615             case LSHIFT_EXPR:
12616             case RSHIFT_EXPR:
12617             case BIT_AND_EXPR:
12618             case BIT_IOR_EXPR:
12619             case BIT_XOR_EXPR:
12620               if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
12621                 {
12622                   opcode = TREE_CODE (rhs1);
12623                   rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12624                   rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12625                   goto stmt_done;
12626                 }
12627               if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
12628                 {
12629                   opcode = TREE_CODE (rhs1);
12630                   rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12631                   rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12632                   swapped = !commutative_tree_code (opcode);
12633                   goto stmt_done;
12634                 }
12635               break;
12636             case ERROR_MARK:
12637               goto saw_error;
12638             default:
12639               break;
12640             }
12641           if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
12642             {
12643               if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12644                 {
12645                   code = OMP_ATOMIC_CAPTURE_OLD;
12646                   v = lhs;
12647                   lhs = NULL_TREE;
12648                   expr = default_function_array_read_conversion (eloc, expr);
12649                   unfolded_lhs1 = expr.value;
12650                   lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
12651                   rhs1 = NULL_TREE;
12652                   c_parser_consume_token (parser);
12653                   goto restart;
12654                 }
12655               if (structured_block)
12656                 {
12657                   opcode = NOP_EXPR;
12658                   expr = default_function_array_read_conversion (eloc, expr);
12659                   rhs = c_fully_fold (expr.value, false, NULL);
12660                   rhs1 = NULL_TREE;
12661                   goto stmt_done;
12662                 }
12663             }
12664           c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
12665           goto saw_error;
12666         default:
12667           c_parser_error (parser,
12668                           "invalid operator for %<#pragma omp atomic%>");
12669           goto saw_error;
12670         }
12671
12672       /* Arrange to pass the location of the assignment operator to
12673          c_finish_omp_atomic.  */
12674       loc = c_parser_peek_token (parser)->location;
12675       c_parser_consume_token (parser);
12676       eloc = c_parser_peek_token (parser)->location;
12677       expr = c_parser_expression (parser);
12678       expr = default_function_array_read_conversion (eloc, expr);
12679       rhs = expr.value;
12680       rhs = c_fully_fold (rhs, false, NULL);
12681       break;
12682     }
12683 stmt_done:
12684   if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12685     {
12686       if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
12687         goto saw_error;
12688       v = c_parser_unary_expression (parser).value;
12689       v = c_fully_fold (v, false, NULL);
12690       if (v == error_mark_node)
12691         goto saw_error;
12692       if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12693         goto saw_error;
12694       eloc = c_parser_peek_token (parser)->location;
12695       expr = c_parser_unary_expression (parser);
12696       lhs1 = expr.value;
12697       expr = default_function_array_read_conversion (eloc, expr);
12698       unfolded_lhs1 = expr.value;
12699       lhs1 = c_fully_fold (lhs1, false, NULL);
12700       if (lhs1 == error_mark_node)
12701         goto saw_error;
12702     }
12703   if (structured_block)
12704     {
12705       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12706       c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
12707     }
12708 done:
12709   if (unfolded_lhs && unfolded_lhs1
12710       && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
12711     {
12712       error ("%<#pragma omp atomic capture%> uses two different "
12713              "expressions for memory");
12714       stmt = error_mark_node;
12715     }
12716   else
12717     stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
12718                                 swapped, seq_cst);
12719   if (stmt != error_mark_node)
12720     add_stmt (stmt);
12721
12722   if (!structured_block)
12723     c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12724 }
12725
12726
12727 /* OpenMP 2.5:
12728    # pragma omp barrier new-line
12729 */
12730
12731 static void
12732 c_parser_omp_barrier (c_parser *parser)
12733 {
12734   location_t loc = c_parser_peek_token (parser)->location;
12735   c_parser_consume_pragma (parser);
12736   c_parser_skip_to_pragma_eol (parser);
12737
12738   c_finish_omp_barrier (loc);
12739 }
12740
12741 /* OpenMP 2.5:
12742    # pragma omp critical [(name)] new-line
12743      structured-block
12744
12745   LOC is the location of the #pragma itself.  */
12746
12747 static tree
12748 c_parser_omp_critical (location_t loc, c_parser *parser)
12749 {
12750   tree stmt, name = NULL;
12751
12752   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12753     {
12754       c_parser_consume_token (parser);
12755       if (c_parser_next_token_is (parser, CPP_NAME))
12756         {
12757           name = c_parser_peek_token (parser)->value;
12758           c_parser_consume_token (parser);
12759           c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12760         }
12761       else
12762         c_parser_error (parser, "expected identifier");
12763     }
12764   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12765     c_parser_error (parser, "expected %<(%> or end of line");
12766   c_parser_skip_to_pragma_eol (parser);
12767
12768   stmt = c_parser_omp_structured_block (parser);
12769   return c_finish_omp_critical (loc, stmt, name);
12770 }
12771
12772 /* OpenMP 2.5:
12773    # pragma omp flush flush-vars[opt] new-line
12774
12775    flush-vars:
12776      ( variable-list ) */
12777
12778 static void
12779 c_parser_omp_flush (c_parser *parser)
12780 {
12781   location_t loc = c_parser_peek_token (parser)->location;
12782   c_parser_consume_pragma (parser);
12783   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12784     c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
12785   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12786     c_parser_error (parser, "expected %<(%> or end of line");
12787   c_parser_skip_to_pragma_eol (parser);
12788
12789   c_finish_omp_flush (loc);
12790 }
12791
12792 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12793    The real trick here is to determine the loop control variable early
12794    so that we can push a new decl if necessary to make it private.
12795    LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12796    respectively.  */
12797
12798 static tree
12799 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
12800                        tree clauses, tree *cclauses)
12801 {
12802   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
12803   tree declv, condv, incrv, initv, ret = NULL;
12804   bool fail = false, open_brace_parsed = false;
12805   int i, collapse = 1, nbraces = 0;
12806   location_t for_loc;
12807   vec<tree, va_gc> *for_block = make_tree_vector ();
12808
12809   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
12810     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
12811       collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
12812
12813   gcc_assert (collapse >= 1);
12814
12815   declv = make_tree_vec (collapse);
12816   initv = make_tree_vec (collapse);
12817   condv = make_tree_vec (collapse);
12818   incrv = make_tree_vec (collapse);
12819
12820   if (code != CILK_FOR
12821       && !c_parser_next_token_is_keyword (parser, RID_FOR))
12822     {
12823       c_parser_error (parser, "for statement expected");
12824       return NULL;
12825     }
12826   if (code == CILK_FOR
12827       && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR))
12828     {
12829       c_parser_error (parser, "_Cilk_for statement expected");
12830       return NULL;
12831     }
12832   for_loc = c_parser_peek_token (parser)->location;
12833   c_parser_consume_token (parser);
12834
12835   for (i = 0; i < collapse; i++)
12836     {
12837       int bracecount = 0;
12838
12839       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12840         goto pop_scopes;
12841
12842       /* Parse the initialization declaration or expression.  */
12843       if (c_parser_next_tokens_start_declaration (parser))
12844         {
12845           if (i > 0)
12846             vec_safe_push (for_block, c_begin_compound_stmt (true));
12847           c_parser_declaration_or_fndef (parser, true, true, true, true, true,
12848                                          NULL, vNULL);
12849           decl = check_for_loop_decls (for_loc, flag_isoc99);
12850           if (decl == NULL)
12851             goto error_init;
12852           if (DECL_INITIAL (decl) == error_mark_node)
12853             decl = error_mark_node;
12854           init = decl;
12855         }
12856       else if (c_parser_next_token_is (parser, CPP_NAME)
12857                && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
12858         {
12859           struct c_expr decl_exp;
12860           struct c_expr init_exp;
12861           location_t init_loc;
12862
12863           decl_exp = c_parser_postfix_expression (parser);
12864           decl = decl_exp.value;
12865
12866           c_parser_require (parser, CPP_EQ, "expected %<=%>");
12867
12868           init_loc = c_parser_peek_token (parser)->location;
12869           init_exp = c_parser_expr_no_commas (parser, NULL);
12870           init_exp = default_function_array_read_conversion (init_loc,
12871                                                              init_exp);
12872           init = build_modify_expr (init_loc, decl, decl_exp.original_type,
12873                                     NOP_EXPR, init_loc, init_exp.value,
12874                                     init_exp.original_type);
12875           init = c_process_expr_stmt (init_loc, init);
12876
12877           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12878         }
12879       else
12880         {
12881         error_init:
12882           c_parser_error (parser,
12883                           "expected iteration declaration or initialization");
12884           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12885                                      "expected %<)%>");
12886           fail = true;
12887           goto parse_next;
12888         }
12889
12890       /* Parse the loop condition.  */
12891       cond = NULL_TREE;
12892       if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
12893         {
12894           location_t cond_loc = c_parser_peek_token (parser)->location;
12895           struct c_expr cond_expr
12896             = c_parser_binary_expression (parser, NULL, NULL_TREE);
12897
12898           cond = cond_expr.value;
12899           cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
12900           cond = c_fully_fold (cond, false, NULL);
12901           switch (cond_expr.original_code)
12902             {
12903             case GT_EXPR:
12904             case GE_EXPR:
12905             case LT_EXPR:
12906             case LE_EXPR:
12907               break;
12908             case NE_EXPR:
12909               if (code == CILK_SIMD || code == CILK_FOR)
12910                 break;
12911               /* FALLTHRU.  */
12912             default:
12913               /* Can't be cond = error_mark_node, because we want to preserve
12914                  the location until c_finish_omp_for.  */
12915               cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
12916               break;
12917             }
12918           protected_set_expr_location (cond, cond_loc);
12919         }
12920       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12921
12922       /* Parse the increment expression.  */
12923       incr = NULL_TREE;
12924       if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
12925         {
12926           location_t incr_loc = c_parser_peek_token (parser)->location;
12927
12928           incr = c_process_expr_stmt (incr_loc,
12929                                       c_parser_expression (parser).value);
12930         }
12931       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12932
12933       if (decl == NULL || decl == error_mark_node || init == error_mark_node)
12934         fail = true;
12935       else
12936         {
12937           TREE_VEC_ELT (declv, i) = decl;
12938           TREE_VEC_ELT (initv, i) = init;
12939           TREE_VEC_ELT (condv, i) = cond;
12940           TREE_VEC_ELT (incrv, i) = incr;
12941         }
12942
12943     parse_next:
12944       if (i == collapse - 1)
12945         break;
12946
12947       /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12948          in between the collapsed for loops to be still considered perfectly
12949          nested.  Hopefully the final version clarifies this.
12950          For now handle (multiple) {'s and empty statements.  */
12951       do
12952         {
12953           if (c_parser_next_token_is_keyword (parser, RID_FOR))
12954             {
12955               c_parser_consume_token (parser);
12956               break;
12957             }
12958           else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
12959             {
12960               c_parser_consume_token (parser);
12961               bracecount++;
12962             }
12963           else if (bracecount
12964                    && c_parser_next_token_is (parser, CPP_SEMICOLON))
12965             c_parser_consume_token (parser);
12966           else
12967             {
12968               c_parser_error (parser, "not enough perfectly nested loops");
12969               if (bracecount)
12970                 {
12971                   open_brace_parsed = true;
12972                   bracecount--;
12973                 }
12974               fail = true;
12975               collapse = 0;
12976               break;
12977             }
12978         }
12979       while (1);
12980
12981       nbraces += bracecount;
12982     }
12983
12984   save_break = c_break_label;
12985   if (code == CILK_SIMD)
12986     c_break_label = build_int_cst (size_type_node, 2);
12987   else
12988     c_break_label = size_one_node;
12989   save_cont = c_cont_label;
12990   c_cont_label = NULL_TREE;
12991   body = push_stmt_list ();
12992
12993   if (open_brace_parsed)
12994     {
12995       location_t here = c_parser_peek_token (parser)->location;
12996       stmt = c_begin_compound_stmt (true);
12997       c_parser_compound_statement_nostart (parser);
12998       add_stmt (c_end_compound_stmt (here, stmt, true));
12999     }
13000   else
13001     add_stmt (c_parser_c99_block_statement (parser));
13002   if (c_cont_label)
13003     {
13004       tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
13005       SET_EXPR_LOCATION (t, loc);
13006       add_stmt (t);
13007     }
13008
13009   body = pop_stmt_list (body);
13010   c_break_label = save_break;
13011   c_cont_label = save_cont;
13012
13013   while (nbraces)
13014     {
13015       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13016         {
13017           c_parser_consume_token (parser);
13018           nbraces--;
13019         }
13020       else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
13021         c_parser_consume_token (parser);
13022       else
13023         {
13024           c_parser_error (parser, "collapsed loops not perfectly nested");
13025           while (nbraces)
13026             {
13027               location_t here = c_parser_peek_token (parser)->location;
13028               stmt = c_begin_compound_stmt (true);
13029               add_stmt (body);
13030               c_parser_compound_statement_nostart (parser);
13031               body = c_end_compound_stmt (here, stmt, true);
13032               nbraces--;
13033             }
13034           goto pop_scopes;
13035         }
13036     }
13037
13038   /* Only bother calling c_finish_omp_for if we haven't already generated
13039      an error from the initialization parsing.  */
13040   if (!fail)
13041     {
13042       stmt = c_finish_omp_for (loc, code, declv, initv, condv,
13043                                incrv, body, NULL);
13044       if (stmt)
13045         {
13046           if (cclauses != NULL
13047               && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
13048             {
13049               tree *c;
13050               for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
13051                 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
13052                     && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
13053                   c = &OMP_CLAUSE_CHAIN (*c);
13054                 else
13055                   {
13056                     for (i = 0; i < collapse; i++)
13057                       if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
13058                         break;
13059                     if (i == collapse)
13060                       c = &OMP_CLAUSE_CHAIN (*c);
13061                     else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
13062                       {
13063                         error_at (loc,
13064                                   "iteration variable %qD should not be firstprivate",
13065                                   OMP_CLAUSE_DECL (*c));
13066                         *c = OMP_CLAUSE_CHAIN (*c);
13067                       }
13068                     else
13069                       {
13070                         /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
13071                            change it to shared (decl) in
13072                            OMP_PARALLEL_CLAUSES.  */
13073                         tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
13074                                                    OMP_CLAUSE_LASTPRIVATE);
13075                         OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
13076                         if (code == OMP_SIMD)
13077                           {
13078                             OMP_CLAUSE_CHAIN (l)
13079                               = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13080                             cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
13081                           }
13082                         else
13083                           {
13084                             OMP_CLAUSE_CHAIN (l) = clauses;
13085                             clauses = l;
13086                           }
13087                         OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
13088                       }
13089                   }
13090             }
13091           OMP_FOR_CLAUSES (stmt) = clauses;
13092         }
13093       ret = stmt;
13094     }
13095 pop_scopes:
13096   while (!for_block->is_empty ())
13097     {
13098       /* FIXME diagnostics: LOC below should be the actual location of
13099          this particular for block.  We need to build a list of
13100          locations to go along with FOR_BLOCK.  */
13101       stmt = c_end_compound_stmt (loc, for_block->pop (), true);
13102       add_stmt (stmt);
13103     }
13104   release_tree_vector (for_block);
13105   return ret;
13106 }
13107
13108 /* Helper function for OpenMP parsing, split clauses and call
13109    finish_omp_clauses on each of the set of clauses afterwards.  */
13110
13111 static void
13112 omp_split_clauses (location_t loc, enum tree_code code,
13113                    omp_clause_mask mask, tree clauses, tree *cclauses)
13114 {
13115   int i;
13116   c_omp_split_clauses (loc, code, mask, clauses, cclauses);
13117   for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
13118     if (cclauses[i])
13119       cclauses[i] = c_finish_omp_clauses (cclauses[i]);
13120 }
13121
13122 /* OpenMP 4.0:
13123    #pragma omp simd simd-clause[optseq] new-line
13124      for-loop
13125
13126    LOC is the location of the #pragma token.
13127 */
13128
13129 #define OMP_SIMD_CLAUSE_MASK                                    \
13130         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN)      \
13131         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)       \
13132         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)      \
13133         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13134         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)  \
13135         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)    \
13136         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13137
13138 static tree
13139 c_parser_omp_simd (location_t loc, c_parser *parser,
13140                    char *p_name, omp_clause_mask mask, tree *cclauses)
13141 {
13142   tree block, clauses, ret;
13143
13144   strcat (p_name, " simd");
13145   mask |= OMP_SIMD_CLAUSE_MASK;
13146   mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
13147
13148   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13149   if (cclauses)
13150     {
13151       omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
13152       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
13153     }
13154
13155   block = c_begin_compound_stmt (true);
13156   ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses);
13157   block = c_end_compound_stmt (loc, block, true);
13158   add_stmt (block);
13159
13160   return ret;
13161 }
13162
13163 /* OpenMP 2.5:
13164    #pragma omp for for-clause[optseq] new-line
13165      for-loop
13166
13167    OpenMP 4.0:
13168    #pragma omp for simd for-simd-clause[optseq] new-line
13169      for-loop
13170
13171    LOC is the location of the #pragma token.
13172 */
13173
13174 #define OMP_FOR_CLAUSE_MASK                                     \
13175         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13176         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13177         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)  \
13178         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)    \
13179         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED)      \
13180         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)     \
13181         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)     \
13182         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13183
13184 static tree
13185 c_parser_omp_for (location_t loc, c_parser *parser,
13186                   char *p_name, omp_clause_mask mask, tree *cclauses)
13187 {
13188   tree block, clauses, ret;
13189
13190   strcat (p_name, " for");
13191   mask |= OMP_FOR_CLAUSE_MASK;
13192   if (cclauses)
13193     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13194
13195   if (c_parser_next_token_is (parser, CPP_NAME))
13196     {
13197       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13198
13199       if (strcmp (p, "simd") == 0)
13200         {
13201           tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13202           if (cclauses == NULL)
13203             cclauses = cclauses_buf;
13204
13205           c_parser_consume_token (parser);
13206           if (!flag_openmp)  /* flag_openmp_simd  */
13207             return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13208           block = c_begin_compound_stmt (true);
13209           ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13210           block = c_end_compound_stmt (loc, block, true);
13211           if (ret == NULL_TREE)
13212             return ret;
13213           ret = make_node (OMP_FOR);
13214           TREE_TYPE (ret) = void_type_node;
13215           OMP_FOR_BODY (ret) = block;
13216           OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13217           SET_EXPR_LOCATION (ret, loc);
13218           add_stmt (ret);
13219           return ret;
13220         }
13221     }
13222   if (!flag_openmp)  /* flag_openmp_simd  */
13223     {
13224       c_parser_skip_to_pragma_eol (parser);
13225       return NULL_TREE;
13226     }
13227
13228   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13229   if (cclauses)
13230     {
13231       omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
13232       clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13233     }
13234
13235   block = c_begin_compound_stmt (true);
13236   ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses);
13237   block = c_end_compound_stmt (loc, block, true);
13238   add_stmt (block);
13239
13240   return ret;
13241 }
13242
13243 /* OpenMP 2.5:
13244    # pragma omp master new-line
13245      structured-block
13246
13247    LOC is the location of the #pragma token.
13248 */
13249
13250 static tree
13251 c_parser_omp_master (location_t loc, c_parser *parser)
13252 {
13253   c_parser_skip_to_pragma_eol (parser);
13254   return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
13255 }
13256
13257 /* OpenMP 2.5:
13258    # pragma omp ordered new-line
13259      structured-block
13260
13261    LOC is the location of the #pragma itself.
13262 */
13263
13264 static tree
13265 c_parser_omp_ordered (location_t loc, c_parser *parser)
13266 {
13267   c_parser_skip_to_pragma_eol (parser);
13268   return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
13269 }
13270
13271 /* OpenMP 2.5:
13272
13273    section-scope:
13274      { section-sequence }
13275
13276    section-sequence:
13277      section-directive[opt] structured-block
13278      section-sequence section-directive structured-block
13279
13280     SECTIONS_LOC is the location of the #pragma omp sections.  */
13281
13282 static tree
13283 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
13284 {
13285   tree stmt, substmt;
13286   bool error_suppress = false;
13287   location_t loc;
13288
13289   loc = c_parser_peek_token (parser)->location;
13290   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
13291     {
13292       /* Avoid skipping until the end of the block.  */
13293       parser->error = false;
13294       return NULL_TREE;
13295     }
13296
13297   stmt = push_stmt_list ();
13298
13299   if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
13300     {
13301       substmt = c_parser_omp_structured_block (parser);
13302       substmt = build1 (OMP_SECTION, void_type_node, substmt);
13303       SET_EXPR_LOCATION (substmt, loc);
13304       add_stmt (substmt);
13305     }
13306
13307   while (1)
13308     {
13309       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13310         break;
13311       if (c_parser_next_token_is (parser, CPP_EOF))
13312         break;
13313
13314       loc = c_parser_peek_token (parser)->location;
13315       if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
13316         {
13317           c_parser_consume_pragma (parser);
13318           c_parser_skip_to_pragma_eol (parser);
13319           error_suppress = false;
13320         }
13321       else if (!error_suppress)
13322         {
13323           error_at (loc, "expected %<#pragma omp section%> or %<}%>");
13324           error_suppress = true;
13325         }
13326
13327       substmt = c_parser_omp_structured_block (parser);
13328       substmt = build1 (OMP_SECTION, void_type_node, substmt);
13329       SET_EXPR_LOCATION (substmt, loc);
13330       add_stmt (substmt);
13331     }
13332   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
13333                              "expected %<#pragma omp section%> or %<}%>");
13334
13335   substmt = pop_stmt_list (stmt);
13336
13337   stmt = make_node (OMP_SECTIONS);
13338   SET_EXPR_LOCATION (stmt, sections_loc);
13339   TREE_TYPE (stmt) = void_type_node;
13340   OMP_SECTIONS_BODY (stmt) = substmt;
13341
13342   return add_stmt (stmt);
13343 }
13344
13345 /* OpenMP 2.5:
13346    # pragma omp sections sections-clause[optseq] newline
13347      sections-scope
13348
13349    LOC is the location of the #pragma token.
13350 */
13351
13352 #define OMP_SECTIONS_CLAUSE_MASK                                \
13353         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13354         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13355         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)  \
13356         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)    \
13357         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13358
13359 static tree
13360 c_parser_omp_sections (location_t loc, c_parser *parser,
13361                        char *p_name, omp_clause_mask mask, tree *cclauses)
13362 {
13363   tree block, clauses, ret;
13364
13365   strcat (p_name, " sections");
13366   mask |= OMP_SECTIONS_CLAUSE_MASK;
13367   if (cclauses)
13368     mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13369
13370   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13371   if (cclauses)
13372     {
13373       omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
13374       clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
13375     }
13376
13377   block = c_begin_compound_stmt (true);
13378   ret = c_parser_omp_sections_scope (loc, parser);
13379   if (ret)
13380     OMP_SECTIONS_CLAUSES (ret) = clauses;
13381   block = c_end_compound_stmt (loc, block, true);
13382   add_stmt (block);
13383
13384   return ret;
13385 }
13386
13387 /* OpenMP 2.5:
13388    # pragma omp parallel parallel-clause[optseq] new-line
13389      structured-block
13390    # pragma omp parallel for parallel-for-clause[optseq] new-line
13391      structured-block
13392    # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13393      structured-block
13394
13395    OpenMP 4.0:
13396    # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13397      structured-block
13398
13399    LOC is the location of the #pragma token.
13400 */
13401
13402 #define OMP_PARALLEL_CLAUSE_MASK                                \
13403         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)           \
13404         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13405         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13406         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)      \
13407         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)       \
13408         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN)       \
13409         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)    \
13410         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)  \
13411         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13412
13413 static tree
13414 c_parser_omp_parallel (location_t loc, c_parser *parser,
13415                        char *p_name, omp_clause_mask mask, tree *cclauses)
13416 {
13417   tree stmt, clauses, block;
13418
13419   strcat (p_name, " parallel");
13420   mask |= OMP_PARALLEL_CLAUSE_MASK;
13421
13422   if (c_parser_next_token_is_keyword (parser, RID_FOR))
13423     {
13424       tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13425       if (cclauses == NULL)
13426         cclauses = cclauses_buf;
13427
13428       c_parser_consume_token (parser);
13429       if (!flag_openmp)  /* flag_openmp_simd  */
13430         return c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13431       block = c_begin_omp_parallel ();
13432       tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13433       stmt
13434         = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
13435                                  block);
13436       if (ret == NULL_TREE)
13437         return ret;
13438       OMP_PARALLEL_COMBINED (stmt) = 1;
13439       return stmt;
13440     }
13441   else if (cclauses)
13442     {
13443       error_at (loc, "expected %<for%> after %qs", p_name);
13444       c_parser_skip_to_pragma_eol (parser);
13445       return NULL_TREE;
13446     }
13447   else if (!flag_openmp)  /* flag_openmp_simd  */
13448     {
13449       c_parser_skip_to_pragma_eol (parser);
13450       return NULL_TREE;
13451     }
13452   else if (c_parser_next_token_is (parser, CPP_NAME))
13453     {
13454       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13455       if (strcmp (p, "sections") == 0)
13456         {
13457           tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13458           if (cclauses == NULL)
13459             cclauses = cclauses_buf;
13460
13461           c_parser_consume_token (parser);
13462           block = c_begin_omp_parallel ();
13463           c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
13464           stmt = c_finish_omp_parallel (loc,
13465                                         cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
13466                                         block);
13467           OMP_PARALLEL_COMBINED (stmt) = 1;
13468           return stmt;
13469         }
13470     }
13471
13472   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13473
13474   block = c_begin_omp_parallel ();
13475   c_parser_statement (parser);
13476   stmt = c_finish_omp_parallel (loc, clauses, block);
13477
13478   return stmt;
13479 }
13480
13481 /* OpenMP 2.5:
13482    # pragma omp single single-clause[optseq] new-line
13483      structured-block
13484
13485    LOC is the location of the #pragma.
13486 */
13487
13488 #define OMP_SINGLE_CLAUSE_MASK                                  \
13489         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13490         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13491         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE)  \
13492         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13493
13494 static tree
13495 c_parser_omp_single (location_t loc, c_parser *parser)
13496 {
13497   tree stmt = make_node (OMP_SINGLE);
13498   SET_EXPR_LOCATION (stmt, loc);
13499   TREE_TYPE (stmt) = void_type_node;
13500
13501   OMP_SINGLE_CLAUSES (stmt)
13502     = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
13503                                 "#pragma omp single");
13504   OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
13505
13506   return add_stmt (stmt);
13507 }
13508
13509 /* OpenMP 3.0:
13510    # pragma omp task task-clause[optseq] new-line
13511
13512    LOC is the location of the #pragma.
13513 */
13514
13515 #define OMP_TASK_CLAUSE_MASK                                    \
13516         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)           \
13517         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED)       \
13518         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)      \
13519         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13520         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13521         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)       \
13522         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)        \
13523         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)    \
13524         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13525
13526 static tree
13527 c_parser_omp_task (location_t loc, c_parser *parser)
13528 {
13529   tree clauses, block;
13530
13531   clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
13532                                       "#pragma omp task");
13533
13534   block = c_begin_omp_task ();
13535   c_parser_statement (parser);
13536   return c_finish_omp_task (loc, clauses, block);
13537 }
13538
13539 /* OpenMP 3.0:
13540    # pragma omp taskwait new-line
13541 */
13542
13543 static void
13544 c_parser_omp_taskwait (c_parser *parser)
13545 {
13546   location_t loc = c_parser_peek_token (parser)->location;
13547   c_parser_consume_pragma (parser);
13548   c_parser_skip_to_pragma_eol (parser);
13549
13550   c_finish_omp_taskwait (loc);
13551 }
13552
13553 /* OpenMP 3.1:
13554    # pragma omp taskyield new-line
13555 */
13556
13557 static void
13558 c_parser_omp_taskyield (c_parser *parser)
13559 {
13560   location_t loc = c_parser_peek_token (parser)->location;
13561   c_parser_consume_pragma (parser);
13562   c_parser_skip_to_pragma_eol (parser);
13563
13564   c_finish_omp_taskyield (loc);
13565 }
13566
13567 /* OpenMP 4.0:
13568    # pragma omp taskgroup new-line
13569 */
13570
13571 static tree
13572 c_parser_omp_taskgroup (c_parser *parser)
13573 {
13574   location_t loc = c_parser_peek_token (parser)->location;
13575   c_parser_skip_to_pragma_eol (parser);
13576   return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser));
13577 }
13578
13579 /* OpenMP 4.0:
13580    # pragma omp cancel cancel-clause[optseq] new-line
13581
13582    LOC is the location of the #pragma.
13583 */
13584
13585 #define OMP_CANCEL_CLAUSE_MASK                                  \
13586         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)     \
13587         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)          \
13588         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)     \
13589         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)    \
13590         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13591
13592 static void
13593 c_parser_omp_cancel (c_parser *parser)
13594 {
13595   location_t loc = c_parser_peek_token (parser)->location;
13596
13597   c_parser_consume_pragma (parser);
13598   tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
13599                                            "#pragma omp cancel");
13600
13601   c_finish_omp_cancel (loc, clauses);
13602 }
13603
13604 /* OpenMP 4.0:
13605    # pragma omp cancellation point cancelpt-clause[optseq] new-line
13606
13607    LOC is the location of the #pragma.
13608 */
13609
13610 #define OMP_CANCELLATION_POINT_CLAUSE_MASK                      \
13611         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL)     \
13612         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR)          \
13613         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)     \
13614         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13615
13616 static void
13617 c_parser_omp_cancellation_point (c_parser *parser)
13618 {
13619   location_t loc = c_parser_peek_token (parser)->location;
13620   tree clauses;
13621   bool point_seen = false;
13622
13623   c_parser_consume_pragma (parser);
13624   if (c_parser_next_token_is (parser, CPP_NAME))
13625     {
13626       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13627       if (strcmp (p, "point") == 0)
13628         {
13629           c_parser_consume_token (parser);
13630           point_seen = true;
13631         }
13632     }
13633   if (!point_seen)
13634     {
13635       c_parser_error (parser, "expected %<point%>");
13636       c_parser_skip_to_pragma_eol (parser);
13637       return;
13638     }
13639
13640   clauses
13641     = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
13642                                 "#pragma omp cancellation point");
13643
13644   c_finish_omp_cancellation_point (loc, clauses);
13645 }
13646
13647 /* OpenMP 4.0:
13648    #pragma omp distribute distribute-clause[optseq] new-line
13649      for-loop  */
13650
13651 #define OMP_DISTRIBUTE_CLAUSE_MASK                              \
13652         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13653         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13654         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13655         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13656
13657 static tree
13658 c_parser_omp_distribute (location_t loc, c_parser *parser,
13659                          char *p_name, omp_clause_mask mask, tree *cclauses)
13660 {
13661   tree clauses, block, ret;
13662
13663   strcat (p_name, " distribute");
13664   mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
13665
13666   if (c_parser_next_token_is (parser, CPP_NAME))
13667     {
13668       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13669       bool simd = false;
13670       bool parallel = false;
13671
13672       if (strcmp (p, "simd") == 0)
13673         simd = true;
13674       else
13675         parallel = strcmp (p, "parallel") == 0;
13676       if (parallel || simd)
13677         {
13678           tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13679           if (cclauses == NULL)
13680             cclauses = cclauses_buf;
13681           c_parser_consume_token (parser);
13682           if (!flag_openmp)  /* flag_openmp_simd  */
13683             {
13684               if (simd)
13685                 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13686               else
13687                 return c_parser_omp_parallel (loc, parser, p_name, mask,
13688                                               cclauses);
13689             }
13690           block = c_begin_compound_stmt (true);
13691           if (simd)
13692             ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13693           else
13694             ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses);
13695           block = c_end_compound_stmt (loc, block, true);
13696           if (ret == NULL)
13697             return ret;
13698           ret = make_node (OMP_DISTRIBUTE);
13699           TREE_TYPE (ret) = void_type_node;
13700           OMP_FOR_BODY (ret) = block;
13701           OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13702           SET_EXPR_LOCATION (ret, loc);
13703           add_stmt (ret);
13704           return ret;
13705         }
13706     }
13707   if (!flag_openmp)  /* flag_openmp_simd  */
13708     {
13709       c_parser_skip_to_pragma_eol (parser);
13710       return NULL_TREE;
13711     }
13712
13713   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13714   if (cclauses)
13715     {
13716       omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
13717       clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13718     }
13719
13720   block = c_begin_compound_stmt (true);
13721   ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL);
13722   block = c_end_compound_stmt (loc, block, true);
13723   add_stmt (block);
13724
13725   return ret;
13726 }
13727
13728 /* OpenMP 4.0:
13729    # pragma omp teams teams-clause[optseq] new-line
13730      structured-block  */
13731
13732 #define OMP_TEAMS_CLAUSE_MASK                                   \
13733         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)      \
13734         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13735         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED)       \
13736         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)    \
13737         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS)    \
13738         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13739         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13740
13741 static tree
13742 c_parser_omp_teams (location_t loc, c_parser *parser,
13743                     char *p_name, omp_clause_mask mask, tree *cclauses)
13744 {
13745   tree clauses, block, ret;
13746
13747   strcat (p_name, " teams");
13748   mask |= OMP_TEAMS_CLAUSE_MASK;
13749
13750   if (c_parser_next_token_is (parser, CPP_NAME))
13751     {
13752       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13753       if (strcmp (p, "distribute") == 0)
13754         {
13755           tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13756           if (cclauses == NULL)
13757             cclauses = cclauses_buf;
13758
13759           c_parser_consume_token (parser);
13760           if (!flag_openmp)  /* flag_openmp_simd  */
13761             return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13762           block = c_begin_compound_stmt (true);
13763           ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13764           block = c_end_compound_stmt (loc, block, true);
13765           if (ret == NULL)
13766             return ret;
13767           clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13768           ret = make_node (OMP_TEAMS);
13769           TREE_TYPE (ret) = void_type_node;
13770           OMP_TEAMS_CLAUSES (ret) = clauses;
13771           OMP_TEAMS_BODY (ret) = block;
13772           return add_stmt (ret);
13773         }
13774     }
13775   if (!flag_openmp)  /* flag_openmp_simd  */
13776     {
13777       c_parser_skip_to_pragma_eol (parser);
13778       return NULL_TREE;
13779     }
13780
13781   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13782   if (cclauses)
13783     {
13784       omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
13785       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13786     }
13787
13788   tree stmt = make_node (OMP_TEAMS);
13789   TREE_TYPE (stmt) = void_type_node;
13790   OMP_TEAMS_CLAUSES (stmt) = clauses;
13791   OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser);
13792
13793   return add_stmt (stmt);
13794 }
13795
13796 /* OpenMP 4.0:
13797    # pragma omp target data target-data-clause[optseq] new-line
13798      structured-block  */
13799
13800 #define OMP_TARGET_DATA_CLAUSE_MASK                             \
13801         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)       \
13802         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)          \
13803         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13804
13805 static tree
13806 c_parser_omp_target_data (location_t loc, c_parser *parser)
13807 {
13808   tree stmt = make_node (OMP_TARGET_DATA);
13809   TREE_TYPE (stmt) = void_type_node;
13810
13811   OMP_TARGET_DATA_CLAUSES (stmt)
13812     = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
13813                                 "#pragma omp target data");
13814   keep_next_level ();
13815   tree block = c_begin_compound_stmt (true);
13816   add_stmt (c_parser_omp_structured_block (parser));
13817   OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13818
13819   SET_EXPR_LOCATION (stmt, loc);
13820   return add_stmt (stmt);
13821 }
13822
13823 /* OpenMP 4.0:
13824    # pragma omp target update target-update-clause[optseq] new-line */
13825
13826 #define OMP_TARGET_UPDATE_CLAUSE_MASK                           \
13827         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM)         \
13828         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)           \
13829         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)       \
13830         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13831
13832 static bool
13833 c_parser_omp_target_update (location_t loc, c_parser *parser,
13834                             enum pragma_context context)
13835 {
13836   if (context == pragma_stmt)
13837     {
13838       error_at (loc,
13839                 "%<#pragma omp target update%> may only be "
13840                 "used in compound statements");
13841       c_parser_skip_to_pragma_eol (parser);
13842       return false;
13843     }
13844
13845   tree clauses
13846     = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
13847                                 "#pragma omp target update");
13848   if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
13849       && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
13850     {
13851       error_at (loc,
13852                 "%<#pragma omp target update must contain at least one "
13853                 "%<from%> or %<to%> clauses");
13854       return false;
13855     }
13856
13857   tree stmt = make_node (OMP_TARGET_UPDATE);
13858   TREE_TYPE (stmt) = void_type_node;
13859   OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
13860   SET_EXPR_LOCATION (stmt, loc);
13861   add_stmt (stmt);
13862   return false;
13863 }
13864
13865 /* OpenMP 4.0:
13866    # pragma omp target target-clause[optseq] new-line
13867      structured-block  */
13868
13869 #define OMP_TARGET_CLAUSE_MASK                                  \
13870         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE)       \
13871         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)          \
13872         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13873
13874 static bool
13875 c_parser_omp_target (c_parser *parser, enum pragma_context context)
13876 {
13877   location_t loc = c_parser_peek_token (parser)->location;
13878   c_parser_consume_pragma (parser);
13879
13880   if (context != pragma_stmt && context != pragma_compound)
13881     {
13882       c_parser_error (parser, "expected declaration specifiers");
13883       c_parser_skip_to_pragma_eol (parser);
13884       return false;
13885     }
13886
13887   if (c_parser_next_token_is (parser, CPP_NAME))
13888     {
13889       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13890
13891       if (strcmp (p, "teams") == 0)
13892         {
13893           tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
13894           char p_name[sizeof ("#pragma omp target teams distribute "
13895                               "parallel for simd")];
13896
13897           c_parser_consume_token (parser);
13898           strcpy (p_name, "#pragma omp target");
13899           if (!flag_openmp)  /* flag_openmp_simd  */
13900             {
13901               tree stmt = c_parser_omp_teams (loc, parser, p_name,
13902                                               OMP_TARGET_CLAUSE_MASK,
13903                                               cclauses);
13904               return stmt != NULL_TREE;
13905             }
13906           keep_next_level ();
13907           tree block = c_begin_compound_stmt (true);
13908           tree ret = c_parser_omp_teams (loc, parser, p_name,
13909                                          OMP_TARGET_CLAUSE_MASK, cclauses);
13910           block = c_end_compound_stmt (loc, block, true);
13911           if (ret == NULL_TREE)
13912             return false;
13913           tree stmt = make_node (OMP_TARGET);
13914           TREE_TYPE (stmt) = void_type_node;
13915           OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
13916           OMP_TARGET_BODY (stmt) = block;
13917           add_stmt (stmt);
13918           return true;
13919         }
13920       else if (!flag_openmp)  /* flag_openmp_simd  */
13921         {
13922           c_parser_skip_to_pragma_eol (parser);
13923           return false;
13924         }
13925       else if (strcmp (p, "data") == 0)
13926         {
13927           c_parser_consume_token (parser);
13928           c_parser_omp_target_data (loc, parser);
13929           return true;
13930         }
13931       else if (strcmp (p, "update") == 0)
13932         {
13933           c_parser_consume_token (parser);
13934           return c_parser_omp_target_update (loc, parser, context);
13935         }
13936     }
13937
13938   tree stmt = make_node (OMP_TARGET);
13939   TREE_TYPE (stmt) = void_type_node;
13940
13941   OMP_TARGET_CLAUSES (stmt)
13942     = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
13943                                 "#pragma omp target");
13944   keep_next_level ();
13945   tree block = c_begin_compound_stmt (true);
13946   add_stmt (c_parser_omp_structured_block (parser));
13947   OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13948
13949   SET_EXPR_LOCATION (stmt, loc);
13950   add_stmt (stmt);
13951   return true;
13952 }
13953
13954 /* OpenMP 4.0:
13955    # pragma omp declare simd declare-simd-clauses[optseq] new-line  */
13956
13957 #define OMP_DECLARE_SIMD_CLAUSE_MASK                            \
13958         ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN)      \
13959         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR)       \
13960         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED)      \
13961         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)      \
13962         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH)     \
13963         | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13964
13965 static void
13966 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
13967 {
13968   vec<c_token> clauses = vNULL;
13969   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13970     {
13971       c_token *token = c_parser_peek_token (parser);
13972       if (token->type == CPP_EOF)
13973         {
13974           c_parser_skip_to_pragma_eol (parser);
13975           clauses.release ();
13976           return;
13977         }
13978       clauses.safe_push (*token);
13979       c_parser_consume_token (parser);
13980     }
13981   clauses.safe_push (*c_parser_peek_token (parser));
13982   c_parser_skip_to_pragma_eol (parser);
13983
13984   while (c_parser_next_token_is (parser, CPP_PRAGMA))
13985     {
13986       if (c_parser_peek_token (parser)->pragma_kind
13987           != PRAGMA_OMP_DECLARE_REDUCTION
13988           || c_parser_peek_2nd_token (parser)->type != CPP_NAME
13989           || strcmp (IDENTIFIER_POINTER
13990                                 (c_parser_peek_2nd_token (parser)->value),
13991                      "simd") != 0)
13992         {
13993           c_parser_error (parser,
13994                           "%<#pragma omp declare simd%> must be followed by "
13995                           "function declaration or definition or another "
13996                           "%<#pragma omp declare simd%>");
13997           clauses.release ();
13998           return;
13999         }
14000       c_parser_consume_pragma (parser);
14001       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14002         {
14003           c_token *token = c_parser_peek_token (parser);
14004           if (token->type == CPP_EOF)
14005             {
14006               c_parser_skip_to_pragma_eol (parser);
14007               clauses.release ();
14008               return;
14009             }
14010           clauses.safe_push (*token);
14011           c_parser_consume_token (parser);
14012         }
14013       clauses.safe_push (*c_parser_peek_token (parser));
14014       c_parser_skip_to_pragma_eol (parser);
14015     }
14016
14017   /* Make sure nothing tries to read past the end of the tokens.  */
14018   c_token eof_token;
14019   memset (&eof_token, 0, sizeof (eof_token));
14020   eof_token.type = CPP_EOF;
14021   clauses.safe_push (eof_token);
14022   clauses.safe_push (eof_token);
14023
14024   switch (context)
14025     {
14026     case pragma_external:
14027       if (c_parser_next_token_is (parser, CPP_KEYWORD)
14028           && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14029         {
14030           int ext = disable_extension_diagnostics ();
14031           do
14032             c_parser_consume_token (parser);
14033           while (c_parser_next_token_is (parser, CPP_KEYWORD)
14034                  && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14035           c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14036                                          NULL, clauses);
14037           restore_extension_diagnostics (ext);
14038         }
14039       else
14040         c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14041                                        NULL, clauses);
14042       break;
14043     case pragma_struct:
14044     case pragma_param:
14045       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14046                               "function declaration or definition");
14047       break;
14048     case pragma_compound:
14049     case pragma_stmt:
14050       if (c_parser_next_token_is (parser, CPP_KEYWORD)
14051           && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14052         {
14053           int ext = disable_extension_diagnostics ();
14054           do
14055             c_parser_consume_token (parser);
14056           while (c_parser_next_token_is (parser, CPP_KEYWORD)
14057                  && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14058           if (c_parser_next_tokens_start_declaration (parser))
14059             {
14060               c_parser_declaration_or_fndef (parser, true, true, true, true,
14061                                              true, NULL, clauses);
14062               restore_extension_diagnostics (ext);
14063               break;
14064             }
14065           restore_extension_diagnostics (ext);
14066         }
14067       else if (c_parser_next_tokens_start_declaration (parser))
14068         {
14069           c_parser_declaration_or_fndef (parser, true, true, true, true, true,
14070                                          NULL, clauses);
14071           break;
14072         }
14073       c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14074                               "function declaration or definition");
14075       break;
14076     default:
14077       gcc_unreachable ();
14078     }
14079   clauses.release ();
14080 }
14081
14082 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14083    and put that into "omp declare simd" attribute.  */
14084
14085 static void
14086 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
14087                            vec<c_token> clauses)
14088 {
14089   if (flag_cilkplus
14090       && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14091     {
14092       error ("%<#pragma omp declare simd%> cannot be used in the same "
14093              "function marked as a Cilk Plus SIMD-enabled function");
14094       vec_free (parser->cilk_simd_fn_tokens);
14095       return;
14096     }
14097   
14098   /* Normally first token is CPP_NAME "simd".  CPP_EOF there indicates
14099      error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14100      has already processed the tokens.  */
14101   if (clauses.exists () && clauses[0].type == CPP_EOF)
14102     return;
14103   if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
14104     {
14105       error ("%<#pragma omp declare simd%> not immediately followed by "
14106              "a function declaration or definition");
14107       clauses[0].type = CPP_EOF;
14108       return;
14109     }
14110   if (clauses.exists () && clauses[0].type != CPP_NAME)
14111     {
14112       error_at (DECL_SOURCE_LOCATION (fndecl),
14113                 "%<#pragma omp declare simd%> not immediately followed by "
14114                 "a single function declaration or definition");
14115       clauses[0].type = CPP_EOF;
14116       return;
14117     }
14118
14119   if (parms == NULL_TREE)
14120     parms = DECL_ARGUMENTS (fndecl);
14121
14122   unsigned int tokens_avail = parser->tokens_avail;
14123   gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14124   bool is_cilkplus_cilk_simd_fn = false;
14125   
14126   if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14127     {
14128       parser->tokens = parser->cilk_simd_fn_tokens->address ();
14129       parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens);
14130       is_cilkplus_cilk_simd_fn = true;
14131     }
14132   else
14133     {
14134       parser->tokens = clauses.address ();
14135       parser->tokens_avail = clauses.length ();
14136     }
14137   
14138   /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end.  */
14139   while (parser->tokens_avail > 3)
14140     {
14141       c_token *token = c_parser_peek_token (parser);
14142       if (!is_cilkplus_cilk_simd_fn) 
14143         gcc_assert (token->type == CPP_NAME 
14144                     && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
14145       else
14146         gcc_assert (token->type == CPP_NAME
14147                     && is_cilkplus_vector_p (token->value));
14148       c_parser_consume_token (parser);
14149       parser->in_pragma = true;
14150
14151       tree c = NULL_TREE;
14152       if (is_cilkplus_cilk_simd_fn) 
14153         c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
14154                                       "SIMD-enabled functions attribute");
14155       else 
14156         c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
14157                                       "#pragma omp declare simd");
14158       c = c_omp_declare_simd_clauses_to_numbers (parms, c);
14159       if (c != NULL_TREE)
14160         c = tree_cons (NULL_TREE, c, NULL_TREE);
14161       if (is_cilkplus_cilk_simd_fn) 
14162         { 
14163           tree k = build_tree_list (get_identifier ("cilk simd function"), 
14164                                     NULL_TREE);
14165           TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
14166           DECL_ATTRIBUTES (fndecl) = k;
14167         } 
14168       c = build_tree_list (get_identifier ("omp declare simd"), c);
14169       TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
14170       DECL_ATTRIBUTES (fndecl) = c;
14171     }
14172
14173   parser->tokens = &parser->tokens_buf[0];
14174   parser->tokens_avail = tokens_avail;
14175   if (clauses.exists ())
14176     clauses[0].type = CPP_PRAGMA;
14177
14178   if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14179     vec_free (parser->cilk_simd_fn_tokens);
14180 }
14181
14182
14183 /* OpenMP 4.0:
14184    # pragma omp declare target new-line
14185    declarations and definitions
14186    # pragma omp end declare target new-line  */
14187
14188 static void
14189 c_parser_omp_declare_target (c_parser *parser)
14190 {
14191   c_parser_skip_to_pragma_eol (parser);
14192   current_omp_declare_target_attribute++;
14193 }
14194
14195 static void
14196 c_parser_omp_end_declare_target (c_parser *parser)
14197 {
14198   location_t loc = c_parser_peek_token (parser)->location;
14199   c_parser_consume_pragma (parser);
14200   if (c_parser_next_token_is (parser, CPP_NAME)
14201       && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14202                  "declare") == 0)
14203     {
14204       c_parser_consume_token (parser);
14205       if (c_parser_next_token_is (parser, CPP_NAME)
14206           && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14207                      "target") == 0)
14208         c_parser_consume_token (parser);
14209       else
14210         {
14211           c_parser_error (parser, "expected %<target%>");
14212           c_parser_skip_to_pragma_eol (parser);
14213           return;
14214         }
14215     }
14216   else
14217     {
14218       c_parser_error (parser, "expected %<declare%>");
14219       c_parser_skip_to_pragma_eol (parser);
14220       return;
14221     }
14222   c_parser_skip_to_pragma_eol (parser);
14223   if (!current_omp_declare_target_attribute)
14224     error_at (loc, "%<#pragma omp end declare target%> without corresponding "
14225                    "%<#pragma omp declare target%>");
14226   else
14227     current_omp_declare_target_attribute--;
14228 }
14229
14230
14231 /* OpenMP 4.0
14232    #pragma omp declare reduction (reduction-id : typename-list : expression) \
14233       initializer-clause[opt] new-line
14234
14235    initializer-clause:
14236       initializer (omp_priv = initializer)
14237       initializer (function-name (argument-list))  */
14238
14239 static void
14240 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
14241 {
14242   unsigned int tokens_avail = 0, i;
14243   vec<tree> types = vNULL;
14244   vec<c_token> clauses = vNULL;
14245   enum tree_code reduc_code = ERROR_MARK;
14246   tree reduc_id = NULL_TREE;
14247   tree type;
14248   location_t rloc = c_parser_peek_token (parser)->location;
14249
14250   if (context == pragma_struct || context == pragma_param)
14251     {
14252       error ("%<#pragma omp declare reduction%> not at file or block scope");
14253       goto fail;
14254     }
14255
14256   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14257     goto fail;
14258
14259   switch (c_parser_peek_token (parser)->type)
14260     {
14261     case CPP_PLUS:
14262       reduc_code = PLUS_EXPR;
14263       break;
14264     case CPP_MULT:
14265       reduc_code = MULT_EXPR;
14266       break;
14267     case CPP_MINUS:
14268       reduc_code = MINUS_EXPR;
14269       break;
14270     case CPP_AND:
14271       reduc_code = BIT_AND_EXPR;
14272       break;
14273     case CPP_XOR:
14274       reduc_code = BIT_XOR_EXPR;
14275       break;
14276     case CPP_OR:
14277       reduc_code = BIT_IOR_EXPR;
14278       break;
14279     case CPP_AND_AND:
14280       reduc_code = TRUTH_ANDIF_EXPR;
14281       break;
14282     case CPP_OR_OR:
14283       reduc_code = TRUTH_ORIF_EXPR;
14284       break;
14285     case CPP_NAME:
14286       const char *p;
14287       p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14288       if (strcmp (p, "min") == 0)
14289         {
14290           reduc_code = MIN_EXPR;
14291           break;
14292         }
14293       if (strcmp (p, "max") == 0)
14294         {
14295           reduc_code = MAX_EXPR;
14296           break;
14297         }
14298       reduc_id = c_parser_peek_token (parser)->value;
14299       break;
14300     default:
14301       c_parser_error (parser,
14302                       "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14303                       "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14304       goto fail;
14305     }
14306
14307   tree orig_reduc_id, reduc_decl;
14308   orig_reduc_id = reduc_id;
14309   reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
14310   reduc_decl = c_omp_reduction_decl (reduc_id);
14311   c_parser_consume_token (parser);
14312
14313   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
14314     goto fail;
14315
14316   while (true)
14317     {
14318       location_t loc = c_parser_peek_token (parser)->location;
14319       struct c_type_name *ctype = c_parser_type_name (parser);
14320       if (ctype != NULL)
14321         {
14322           type = groktypename (ctype, NULL, NULL);
14323           if (type == error_mark_node)
14324             ;
14325           else if ((INTEGRAL_TYPE_P (type)
14326                     || TREE_CODE (type) == REAL_TYPE
14327                     || TREE_CODE (type) == COMPLEX_TYPE)
14328                    && orig_reduc_id == NULL_TREE)
14329             error_at (loc, "predeclared arithmetic type in "
14330                            "%<#pragma omp declare reduction%>");
14331           else if (TREE_CODE (type) == FUNCTION_TYPE
14332                    || TREE_CODE (type) == ARRAY_TYPE)
14333             error_at (loc, "function or array type in "
14334                       "%<#pragma omp declare reduction%>");
14335           else if (TYPE_QUALS_NO_ADDR_SPACE (type))
14336             error_at (loc, "const, volatile or restrict qualified type in "
14337                            "%<#pragma omp declare reduction%>");
14338           else
14339             {
14340               tree t;
14341               for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
14342                 if (comptypes (TREE_PURPOSE (t), type))
14343                   {
14344                     error_at (loc, "redeclaration of %qs "
14345                                    "%<#pragma omp declare reduction%> for "
14346                                    "type %qT",
14347                                    IDENTIFIER_POINTER (reduc_id)
14348                                    + sizeof ("omp declare reduction ") - 1,
14349                                    type);
14350                     location_t ploc
14351                       = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
14352                                                             0));
14353                     error_at (ploc, "previous %<#pragma omp declare "
14354                                     "reduction%>");
14355                     break;
14356                   }
14357               if (t == NULL_TREE)
14358                 types.safe_push (type);
14359             }
14360           if (c_parser_next_token_is (parser, CPP_COMMA))
14361             c_parser_consume_token (parser);
14362           else
14363             break;
14364         }
14365       else
14366         break;
14367     }
14368
14369   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
14370       || types.is_empty ())
14371     {
14372      fail:
14373       clauses.release ();
14374       types.release ();
14375       while (true)
14376         {
14377           c_token *token = c_parser_peek_token (parser);
14378           if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
14379             break;
14380           c_parser_consume_token (parser);
14381         }
14382       c_parser_skip_to_pragma_eol (parser);
14383       return;
14384     }
14385
14386   if (types.length () > 1)
14387     {
14388       while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14389         {
14390           c_token *token = c_parser_peek_token (parser);
14391           if (token->type == CPP_EOF)
14392             goto fail;
14393           clauses.safe_push (*token);
14394           c_parser_consume_token (parser);
14395         }
14396       clauses.safe_push (*c_parser_peek_token (parser));
14397       c_parser_skip_to_pragma_eol (parser);
14398
14399       /* Make sure nothing tries to read past the end of the tokens.  */
14400       c_token eof_token;
14401       memset (&eof_token, 0, sizeof (eof_token));
14402       eof_token.type = CPP_EOF;
14403       clauses.safe_push (eof_token);
14404       clauses.safe_push (eof_token);
14405     }
14406
14407   int errs = errorcount;
14408   FOR_EACH_VEC_ELT (types, i, type)
14409     {
14410       tokens_avail = parser->tokens_avail;
14411       gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14412       if (!clauses.is_empty ())
14413         {
14414           parser->tokens = clauses.address ();
14415           parser->tokens_avail = clauses.length ();
14416           parser->in_pragma = true;
14417         }
14418
14419       bool nested = current_function_decl != NULL_TREE;
14420       if (nested)
14421         c_push_function_context ();
14422       tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
14423                                 reduc_id, default_function_type);
14424       current_function_decl = fndecl;
14425       allocate_struct_function (fndecl, true);
14426       push_scope ();
14427       tree stmt = push_stmt_list ();
14428       /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14429          warn about these.  */
14430       tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
14431                                  get_identifier ("omp_out"), type);
14432       DECL_ARTIFICIAL (omp_out) = 1;
14433       DECL_CONTEXT (omp_out) = fndecl;
14434       pushdecl (omp_out);
14435       tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
14436                                 get_identifier ("omp_in"), type);
14437       DECL_ARTIFICIAL (omp_in) = 1;
14438       DECL_CONTEXT (omp_in) = fndecl;
14439       pushdecl (omp_in);
14440       struct c_expr combiner = c_parser_expression (parser);
14441       struct c_expr initializer;
14442       tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
14443       bool bad = false;
14444       initializer.value = error_mark_node;
14445       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14446         bad = true;
14447       else if (c_parser_next_token_is (parser, CPP_NAME)
14448                && strcmp (IDENTIFIER_POINTER
14449                                 (c_parser_peek_token (parser)->value),
14450                           "initializer") == 0)
14451         {
14452           c_parser_consume_token (parser);
14453           pop_scope ();
14454           push_scope ();
14455           omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
14456                                  get_identifier ("omp_priv"), type);
14457           DECL_ARTIFICIAL (omp_priv) = 1;
14458           DECL_INITIAL (omp_priv) = error_mark_node;
14459           DECL_CONTEXT (omp_priv) = fndecl;
14460           pushdecl (omp_priv);
14461           omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
14462                                  get_identifier ("omp_orig"), type);
14463           DECL_ARTIFICIAL (omp_orig) = 1;
14464           DECL_CONTEXT (omp_orig) = fndecl;
14465           pushdecl (omp_orig);
14466           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14467             bad = true;
14468           else if (!c_parser_next_token_is (parser, CPP_NAME))
14469             {
14470               c_parser_error (parser, "expected %<omp_priv%> or "
14471                                       "function-name");
14472               bad = true;
14473             }
14474           else if (strcmp (IDENTIFIER_POINTER
14475                                 (c_parser_peek_token (parser)->value),
14476                            "omp_priv") != 0)
14477             {
14478               if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
14479                   || c_parser_peek_token (parser)->id_kind != C_ID_ID)
14480                 {
14481                   c_parser_error (parser, "expected function-name %<(%>");
14482                   bad = true;
14483                 }
14484               else
14485                 initializer = c_parser_postfix_expression (parser);
14486               if (initializer.value
14487                   && TREE_CODE (initializer.value) == CALL_EXPR)
14488                 {
14489                   int j;
14490                   tree c = initializer.value;
14491                   for (j = 0; j < call_expr_nargs (c); j++)
14492                     if (TREE_CODE (CALL_EXPR_ARG (c, j)) == ADDR_EXPR
14493                         && TREE_OPERAND (CALL_EXPR_ARG (c, j), 0) == omp_priv)
14494                       break;
14495                   if (j == call_expr_nargs (c))
14496                     error ("one of the initializer call arguments should be "
14497                            "%<&omp_priv%>");
14498                 }
14499             }
14500           else
14501             {
14502               c_parser_consume_token (parser);
14503               if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
14504                 bad = true;
14505               else
14506                 {
14507                   tree st = push_stmt_list ();
14508                   start_init (omp_priv, NULL_TREE, 0);
14509                   location_t loc = c_parser_peek_token (parser)->location;
14510                   struct c_expr init = c_parser_initializer (parser);
14511                   finish_init ();
14512                   finish_decl (omp_priv, loc, init.value,
14513                                init.original_type, NULL_TREE);
14514                   pop_stmt_list (st);
14515                 }
14516             }
14517           if (!bad
14518               && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14519             bad = true;
14520         }
14521
14522       if (!bad)
14523         {
14524           c_parser_skip_to_pragma_eol (parser);
14525
14526           tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
14527                               DECL_INITIAL (reduc_decl));
14528           DECL_INITIAL (reduc_decl) = t;
14529           DECL_SOURCE_LOCATION (omp_out) = rloc;
14530           TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
14531           TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
14532           TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
14533           walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
14534                      &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
14535           if (omp_priv)
14536             {
14537               DECL_SOURCE_LOCATION (omp_priv) = rloc;
14538               TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
14539               TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
14540               TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
14541               walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
14542                          &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14543               walk_tree (&DECL_INITIAL (omp_priv),
14544                          c_check_omp_declare_reduction_r,
14545                          &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14546             }
14547         }
14548
14549       pop_stmt_list (stmt);
14550       pop_scope ();
14551       if (cfun->language != NULL)
14552         {
14553           ggc_free (cfun->language);
14554           cfun->language = NULL;
14555         }
14556       set_cfun (NULL);
14557       current_function_decl = NULL_TREE;
14558       if (nested)
14559         c_pop_function_context ();
14560
14561       if (!clauses.is_empty ())
14562         {
14563           parser->tokens = &parser->tokens_buf[0];
14564           parser->tokens_avail = tokens_avail;
14565         }
14566       if (bad)
14567         goto fail;
14568       if (errs != errorcount)
14569         break;
14570     }
14571
14572   clauses.release ();
14573   types.release ();
14574 }
14575
14576
14577 /* OpenMP 4.0
14578    #pragma omp declare simd declare-simd-clauses[optseq] new-line
14579    #pragma omp declare reduction (reduction-id : typename-list : expression) \
14580       initializer-clause[opt] new-line
14581    #pragma omp declare target new-line  */
14582
14583 static void
14584 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
14585 {
14586   c_parser_consume_pragma (parser);
14587   if (c_parser_next_token_is (parser, CPP_NAME))
14588     {
14589       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14590       if (strcmp (p, "simd") == 0)
14591         {
14592           /* c_parser_consume_token (parser); done in
14593              c_parser_omp_declare_simd.  */
14594           c_parser_omp_declare_simd (parser, context);
14595           return;
14596         }
14597       if (strcmp (p, "reduction") == 0)
14598         {
14599           c_parser_consume_token (parser);
14600           c_parser_omp_declare_reduction (parser, context);
14601           return;
14602         }
14603       if (!flag_openmp)  /* flag_openmp_simd  */
14604         {
14605           c_parser_skip_to_pragma_eol (parser);
14606           return;
14607         }
14608       if (strcmp (p, "target") == 0)
14609         {
14610           c_parser_consume_token (parser);
14611           c_parser_omp_declare_target (parser);
14612           return;
14613         }
14614     }
14615
14616   c_parser_error (parser, "expected %<simd%> or %<reduction%> "
14617                           "or %<target%>");
14618   c_parser_skip_to_pragma_eol (parser);
14619 }
14620
14621 /* Main entry point to parsing most OpenMP pragmas.  */
14622
14623 static void
14624 c_parser_omp_construct (c_parser *parser)
14625 {
14626   enum pragma_kind p_kind;
14627   location_t loc;
14628   tree stmt;
14629   char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
14630   omp_clause_mask mask (0);
14631
14632   loc = c_parser_peek_token (parser)->location;
14633   p_kind = c_parser_peek_token (parser)->pragma_kind;
14634   c_parser_consume_pragma (parser);
14635
14636   switch (p_kind)
14637     {
14638     case PRAGMA_OACC_CACHE:
14639       strcpy (p_name, "#pragma acc");
14640       stmt = c_parser_oacc_cache (loc, parser);
14641       break;
14642     case PRAGMA_OACC_DATA:
14643       stmt = c_parser_oacc_data (loc, parser);
14644       break;
14645     case PRAGMA_OACC_KERNELS:
14646       strcpy (p_name, "#pragma acc");
14647       stmt = c_parser_oacc_kernels (loc, parser, p_name);
14648       break;
14649     case PRAGMA_OACC_LOOP:
14650       strcpy (p_name, "#pragma acc");
14651       stmt = c_parser_oacc_loop (loc, parser, p_name);
14652       break;
14653     case PRAGMA_OACC_PARALLEL:
14654       strcpy (p_name, "#pragma acc");
14655       stmt = c_parser_oacc_parallel (loc, parser, p_name);
14656       break;
14657     case PRAGMA_OACC_WAIT:
14658       strcpy (p_name, "#pragma wait");
14659       stmt = c_parser_oacc_wait (loc, parser, p_name);
14660       break;
14661     case PRAGMA_OMP_ATOMIC:
14662       c_parser_omp_atomic (loc, parser);
14663       return;
14664     case PRAGMA_OMP_CRITICAL:
14665       stmt = c_parser_omp_critical (loc, parser);
14666       break;
14667     case PRAGMA_OMP_DISTRIBUTE:
14668       strcpy (p_name, "#pragma omp");
14669       stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL);
14670       break;
14671     case PRAGMA_OMP_FOR:
14672       strcpy (p_name, "#pragma omp");
14673       stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL);
14674       break;
14675     case PRAGMA_OMP_MASTER:
14676       stmt = c_parser_omp_master (loc, parser);
14677       break;
14678     case PRAGMA_OMP_ORDERED:
14679       stmt = c_parser_omp_ordered (loc, parser);
14680       break;
14681     case PRAGMA_OMP_PARALLEL:
14682       strcpy (p_name, "#pragma omp");
14683       stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL);
14684       break;
14685     case PRAGMA_OMP_SECTIONS:
14686       strcpy (p_name, "#pragma omp");
14687       stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
14688       break;
14689     case PRAGMA_OMP_SIMD:
14690       strcpy (p_name, "#pragma omp");
14691       stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL);
14692       break;
14693     case PRAGMA_OMP_SINGLE:
14694       stmt = c_parser_omp_single (loc, parser);
14695       break;
14696     case PRAGMA_OMP_TASK:
14697       stmt = c_parser_omp_task (loc, parser);
14698       break;
14699     case PRAGMA_OMP_TASKGROUP:
14700       stmt = c_parser_omp_taskgroup (parser);
14701       break;
14702     case PRAGMA_OMP_TEAMS:
14703       strcpy (p_name, "#pragma omp");
14704       stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL);
14705       break;
14706     default:
14707       gcc_unreachable ();
14708     }
14709
14710   if (stmt)
14711     gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
14712 }
14713
14714
14715 /* OpenMP 2.5:
14716    # pragma omp threadprivate (variable-list) */
14717
14718 static void
14719 c_parser_omp_threadprivate (c_parser *parser)
14720 {
14721   tree vars, t;
14722   location_t loc;
14723
14724   c_parser_consume_pragma (parser);
14725   loc = c_parser_peek_token (parser)->location;
14726   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
14727
14728   /* Mark every variable in VARS to be assigned thread local storage.  */
14729   for (t = vars; t; t = TREE_CHAIN (t))
14730     {
14731       tree v = TREE_PURPOSE (t);
14732
14733       /* FIXME diagnostics: Ideally we should keep individual
14734          locations for all the variables in the var list to make the
14735          following errors more precise.  Perhaps
14736          c_parser_omp_var_list_parens() should construct a list of
14737          locations to go along with the var list.  */
14738
14739       /* If V had already been marked threadprivate, it doesn't matter
14740          whether it had been used prior to this point.  */
14741       if (TREE_CODE (v) != VAR_DECL)
14742         error_at (loc, "%qD is not a variable", v);
14743       else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
14744         error_at (loc, "%qE declared %<threadprivate%> after first use", v);
14745       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
14746         error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
14747       else if (TREE_TYPE (v) == error_mark_node)
14748         ;
14749       else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
14750         error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
14751       else
14752         {
14753           if (! DECL_THREAD_LOCAL_P (v))
14754             {
14755               set_decl_tls_model (v, decl_default_tls_model (v));
14756               /* If rtl has been already set for this var, call
14757                  make_decl_rtl once again, so that encode_section_info
14758                  has a chance to look at the new decl flags.  */
14759               if (DECL_RTL_SET_P (v))
14760                 make_decl_rtl (v);
14761             }
14762           C_DECL_THREADPRIVATE_P (v) = 1;
14763         }
14764     }
14765
14766   c_parser_skip_to_pragma_eol (parser);
14767 }
14768 \f
14769 /* Cilk Plus <#pragma simd> parsing routines.  */
14770
14771 /* Helper function for c_parser_pragma.  Perform some sanity checking
14772    for <#pragma simd> constructs.  Returns FALSE if there was a
14773    problem.  */
14774
14775 static bool
14776 c_parser_cilk_verify_simd (c_parser *parser,
14777                                   enum pragma_context context)
14778 {
14779   if (!flag_cilkplus)
14780     {
14781       warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14782       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14783       return false;
14784     }
14785   if (context == pragma_external)
14786     {
14787       c_parser_error (parser,"pragma simd must be inside a function");
14788       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14789       return false;
14790     }
14791   return true;
14792 }
14793
14794 /* Cilk Plus:
14795    This function is shared by SIMD-enabled functions and #pragma simd.  
14796    If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and 
14797    CLAUSES is unused.  The main purpose of this function is to parse a
14798    vectorlength attribute or clause and check for parse errors.
14799    When IS_SIMD_FN is true then the function is merely caching the tokens
14800    in PARSER->CILK_SIMD_FN_TOKENS.  If errors are found then the token
14801    cache is cleared since there is no reason to continue.
14802    Syntax:
14803    vectorlength ( constant-expression )  */
14804
14805 static tree
14806 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses, 
14807                                    bool is_simd_fn)
14808 {
14809   if (is_simd_fn)
14810     check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength");
14811   else
14812   /* The vectorlength clause behaves exactly like OpenMP's safelen
14813      clause.  Represent it in OpenMP terms.  */
14814     check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
14815
14816   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14817     return clauses;
14818
14819   location_t loc = c_parser_peek_token (parser)->location;
14820   tree expr = c_parser_expr_no_commas (parser, NULL).value;
14821   expr = c_fully_fold (expr, false, NULL);
14822
14823   /* If expr is an error_mark_node then the above function would have
14824      emitted an error.  No reason to do it twice.  */
14825   if (expr == error_mark_node)
14826     ;
14827   else if (!TREE_TYPE (expr)
14828            || !TREE_CONSTANT (expr)
14829            || !INTEGRAL_TYPE_P (TREE_TYPE (expr)))
14830   
14831     error_at (loc, "vectorlength must be an integer constant");  
14832   else if (wi::exact_log2 (expr) == -1)
14833     error_at (loc, "vectorlength must be a power of 2");
14834   else
14835     {
14836       if (is_simd_fn)
14837         {
14838           tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN);
14839           OMP_CLAUSE_SIMDLEN_EXPR (u) = expr;
14840           OMP_CLAUSE_CHAIN (u) = clauses;
14841           clauses = u;
14842         }
14843       else
14844         {
14845           tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN);
14846           OMP_CLAUSE_SAFELEN_EXPR (u) = expr;
14847           OMP_CLAUSE_CHAIN (u) = clauses;
14848           clauses = u;
14849         }
14850     }
14851
14852   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14853
14854   return clauses;
14855 }
14856
14857 /* Cilk Plus:
14858    linear ( simd-linear-variable-list )
14859
14860    simd-linear-variable-list:
14861      simd-linear-variable
14862      simd-linear-variable-list , simd-linear-variable
14863
14864    simd-linear-variable:
14865      id-expression
14866      id-expression : simd-linear-step
14867
14868    simd-linear-step:
14869    conditional-expression */
14870
14871 static tree
14872 c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
14873 {
14874   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14875     return clauses;
14876
14877   location_t loc = c_parser_peek_token (parser)->location;
14878
14879   if (c_parser_next_token_is_not (parser, CPP_NAME)
14880       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
14881     c_parser_error (parser, "expected identifier");
14882
14883   while (c_parser_next_token_is (parser, CPP_NAME)
14884          && c_parser_peek_token (parser)->id_kind == C_ID_ID)
14885     {
14886       tree var = lookup_name (c_parser_peek_token (parser)->value);
14887
14888       if (var == NULL)
14889         {
14890           undeclared_variable (c_parser_peek_token (parser)->location,
14891                                c_parser_peek_token (parser)->value);
14892         c_parser_consume_token (parser);
14893         }
14894       else if (var == error_mark_node)
14895         c_parser_consume_token (parser);
14896       else
14897         {
14898           tree step = integer_one_node;
14899
14900           /* Parse the linear step if present.  */
14901           if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
14902             {
14903               c_parser_consume_token (parser);
14904               c_parser_consume_token (parser);
14905
14906               tree expr = c_parser_expr_no_commas (parser, NULL).value;
14907               expr = c_fully_fold (expr, false, NULL);
14908
14909               if (TREE_TYPE (expr)
14910                   && INTEGRAL_TYPE_P (TREE_TYPE (expr))
14911                   && (TREE_CONSTANT (expr)
14912                       || DECL_P (expr)))
14913                 step = expr;
14914               else
14915                 c_parser_error (parser,
14916                                 "step size must be an integer constant "
14917                                 "expression or an integer variable");
14918             }
14919           else
14920             c_parser_consume_token (parser);
14921
14922           /* Use OMP_CLAUSE_LINEAR, which has the same semantics.  */
14923           tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR);
14924           OMP_CLAUSE_DECL (u) = var;
14925           OMP_CLAUSE_LINEAR_STEP (u) = step;
14926           OMP_CLAUSE_CHAIN (u) = clauses;
14927           clauses = u;
14928         }
14929
14930       if (c_parser_next_token_is_not (parser, CPP_COMMA))
14931         break;
14932
14933       c_parser_consume_token (parser);
14934     }
14935
14936   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14937
14938   return clauses;
14939 }
14940
14941 /* Returns the name of the next clause.  If the clause is not
14942    recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14943    not consumed.  Otherwise, the appropriate pragma_simd_clause is
14944    returned and the token is consumed.  */
14945
14946 static pragma_omp_clause
14947 c_parser_cilk_clause_name (c_parser *parser)
14948 {
14949   pragma_omp_clause result;
14950   c_token *token = c_parser_peek_token (parser);
14951
14952   if (!token->value || token->type != CPP_NAME)
14953     return PRAGMA_CILK_CLAUSE_NONE;
14954
14955   const char *p = IDENTIFIER_POINTER (token->value);
14956
14957   if (!strcmp (p, "vectorlength"))
14958     result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
14959   else if (!strcmp (p, "linear"))
14960     result = PRAGMA_CILK_CLAUSE_LINEAR;
14961   else if (!strcmp (p, "private"))
14962     result = PRAGMA_CILK_CLAUSE_PRIVATE;
14963   else if (!strcmp (p, "firstprivate"))
14964     result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
14965   else if (!strcmp (p, "lastprivate"))
14966     result = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
14967   else if (!strcmp (p, "reduction"))
14968     result = PRAGMA_CILK_CLAUSE_REDUCTION;
14969   else
14970     return PRAGMA_CILK_CLAUSE_NONE;
14971
14972   c_parser_consume_token (parser);
14973   return result;
14974 }
14975
14976 /* Parse all #<pragma simd> clauses.  Return the list of clauses
14977    found.  */
14978
14979 static tree
14980 c_parser_cilk_all_clauses (c_parser *parser)
14981 {
14982   tree clauses = NULL;
14983
14984   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14985     {
14986       pragma_omp_clause c_kind;
14987
14988       c_kind = c_parser_cilk_clause_name (parser);
14989
14990       switch (c_kind)
14991         {
14992         case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
14993           clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false);
14994           break;
14995         case PRAGMA_CILK_CLAUSE_LINEAR:
14996           clauses = c_parser_cilk_clause_linear (parser, clauses);
14997           break;
14998         case PRAGMA_CILK_CLAUSE_PRIVATE:
14999           /* Use the OpenMP counterpart.  */
15000           clauses = c_parser_omp_clause_private (parser, clauses);
15001           break;
15002         case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE:
15003           /* Use the OpenMP counterpart.  */
15004           clauses = c_parser_omp_clause_firstprivate (parser, clauses);
15005           break;
15006         case PRAGMA_CILK_CLAUSE_LASTPRIVATE:
15007           /* Use the OpenMP counterpart.  */
15008           clauses = c_parser_omp_clause_lastprivate (parser, clauses);
15009           break;
15010         case PRAGMA_CILK_CLAUSE_REDUCTION:
15011           /* Use the OpenMP counterpart.  */
15012           clauses = c_parser_omp_clause_reduction (parser, clauses);
15013           break;
15014         default:
15015           c_parser_error (parser, "expected %<#pragma simd%> clause");
15016           goto saw_error;
15017         }
15018     }
15019
15020  saw_error:
15021   c_parser_skip_to_pragma_eol (parser);
15022   return c_finish_cilk_clauses (clauses);
15023 }
15024
15025 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15026    Here is the correct syntax of this pragma:
15027             #pragma cilk grainsize = <EXP>
15028  */
15029
15030 static void
15031 c_parser_cilk_grainsize (c_parser *parser)
15032 {
15033   extern tree convert_to_integer (tree, tree);
15034
15035   /* consume the 'grainsize' keyword.  */
15036   c_parser_consume_pragma (parser);
15037
15038   if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0)
15039     {
15040       struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL);
15041       if (g_expr.value == error_mark_node)
15042         {
15043           c_parser_skip_to_pragma_eol (parser);
15044           return;
15045         }
15046       tree grain = convert_to_integer (long_integer_type_node,
15047                                        c_fully_fold (g_expr.value, false,
15048                                                      NULL));
15049       c_parser_skip_to_pragma_eol (parser);
15050       c_token *token = c_parser_peek_token (parser);
15051       if (token && token->type == CPP_KEYWORD
15052           && token->keyword == RID_CILK_FOR)
15053         {
15054           if (grain == NULL_TREE || grain == error_mark_node)
15055             grain = integer_zero_node;
15056           c_parser_cilk_for (parser, grain);
15057         }
15058       else
15059         warning (0, "%<#pragma cilk grainsize%> is not followed by "
15060                     "%<_Cilk_for%>");
15061     }
15062   else
15063     c_parser_skip_to_pragma_eol (parser);
15064 }
15065
15066 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops.  */
15067
15068 static void
15069 c_parser_cilk_simd (c_parser *parser)
15070 {
15071   tree clauses = c_parser_cilk_all_clauses (parser);
15072   tree block = c_begin_compound_stmt (true);
15073   location_t loc = c_parser_peek_token (parser)->location;
15074   c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL);
15075   block = c_end_compound_stmt (loc, block, true);
15076   add_stmt (block);
15077 }
15078
15079 /* Create an artificial decl with TYPE and emit initialization of it with
15080    INIT.  */
15081
15082 static tree
15083 c_get_temp_regvar (tree type, tree init)
15084 {
15085   location_t loc = EXPR_LOCATION (init);
15086   tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
15087   DECL_ARTIFICIAL (decl) = 1;
15088   DECL_IGNORED_P (decl) = 1;
15089   pushdecl (decl);
15090   tree t = build2 (INIT_EXPR, type, decl, init);
15091   add_stmt (t);
15092   return decl;
15093 }
15094
15095 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15096   GRAIN is the grain value passed in through pragma or 0.  */
15097
15098 static void
15099 c_parser_cilk_for (c_parser *parser, tree grain)
15100 {
15101   tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE);
15102   OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR;
15103   OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain;
15104   clauses = c_finish_omp_clauses (clauses);
15105
15106   tree block = c_begin_compound_stmt (true);
15107   tree sb = push_stmt_list ();
15108   location_t loc = c_parser_peek_token (parser)->location;
15109   tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL);
15110   sb = pop_stmt_list (sb);
15111
15112   if (omp_for)
15113     {
15114       tree omp_par = make_node (OMP_PARALLEL);
15115       TREE_TYPE (omp_par) = void_type_node;
15116       OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE;
15117       tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
15118       TREE_SIDE_EFFECTS (bind) = 1;
15119       BIND_EXPR_BODY (bind) = sb;
15120       OMP_PARALLEL_BODY (omp_par) = bind;
15121       if (OMP_FOR_PRE_BODY (omp_for))
15122         {
15123           add_stmt (OMP_FOR_PRE_BODY (omp_for));
15124           OMP_FOR_PRE_BODY (omp_for) = NULL_TREE;
15125         }
15126       tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0);
15127       tree decl = TREE_OPERAND (init, 0);
15128       tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0);
15129       tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
15130       tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE;
15131       if (TREE_CODE (t) != INTEGER_CST)
15132         {
15133           TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15134           c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15135           OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1);
15136           OMP_CLAUSE_CHAIN (c) = clauses;
15137           clauses = c;
15138         }
15139       if (TREE_CODE (incr) == MODIFY_EXPR)
15140         {
15141           t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15142           if (TREE_CODE (t) != INTEGER_CST)
15143             {
15144               TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
15145                 = c_get_temp_regvar (TREE_TYPE (t), t);
15146               c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15147               OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15148               OMP_CLAUSE_CHAIN (c) = clauses;
15149               clauses = c;
15150             }
15151         }
15152       t = TREE_OPERAND (init, 1);
15153       if (TREE_CODE (t) != INTEGER_CST)
15154         {
15155           TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15156           c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15157           OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1);
15158           OMP_CLAUSE_CHAIN (c) = clauses;
15159           clauses = c;
15160         }
15161       c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
15162       OMP_CLAUSE_DECL (c) = decl;
15163       OMP_CLAUSE_CHAIN (c) = clauses;
15164       clauses = c;
15165       c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_);
15166       OMP_CLAUSE_OPERAND (c, 0)
15167         = cilk_for_number_of_iterations (omp_for);
15168       OMP_CLAUSE_CHAIN (c) = clauses;
15169       OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c);
15170       add_stmt (omp_par);
15171     }
15172
15173   block = c_end_compound_stmt (loc, block, true);
15174   add_stmt (block);
15175 }
15176
15177 \f
15178 /* Parse a transaction attribute (GCC Extension).
15179
15180    transaction-attribute:
15181      attributes
15182      [ [ any-word ] ]
15183
15184    The transactional memory language description is written for C++,
15185    and uses the C++0x attribute syntax.  For compatibility, allow the
15186    bracket style for transactions in C as well.  */
15187
15188 static tree
15189 c_parser_transaction_attributes (c_parser *parser)
15190 {
15191   tree attr_name, attr = NULL;
15192
15193   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
15194     return c_parser_attributes (parser);
15195
15196   if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
15197     return NULL_TREE;
15198   c_parser_consume_token (parser);
15199   if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
15200     goto error1;
15201
15202   attr_name = c_parser_attribute_any_word (parser);
15203   if (attr_name)
15204     {
15205       c_parser_consume_token (parser);
15206       attr = build_tree_list (attr_name, NULL_TREE);
15207     }
15208   else
15209     c_parser_error (parser, "expected identifier");
15210
15211   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15212  error1:
15213   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15214   return attr;
15215 }
15216
15217 /* Parse a __transaction_atomic or __transaction_relaxed statement
15218    (GCC Extension).
15219
15220    transaction-statement:
15221      __transaction_atomic transaction-attribute[opt] compound-statement
15222      __transaction_relaxed compound-statement
15223
15224    Note that the only valid attribute is: "outer".
15225 */
15226
15227 static tree
15228 c_parser_transaction (c_parser *parser, enum rid keyword)
15229 {
15230   unsigned int old_in = parser->in_transaction;
15231   unsigned int this_in = 1, new_in;
15232   location_t loc = c_parser_peek_token (parser)->location;
15233   tree stmt, attrs;
15234
15235   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15236       || keyword == RID_TRANSACTION_RELAXED)
15237       && c_parser_next_token_is_keyword (parser, keyword));
15238   c_parser_consume_token (parser);
15239
15240   if (keyword == RID_TRANSACTION_RELAXED)
15241     this_in |= TM_STMT_ATTR_RELAXED;
15242   else
15243     {
15244       attrs = c_parser_transaction_attributes (parser);
15245       if (attrs)
15246         this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
15247     }
15248
15249   /* Keep track if we're in the lexical scope of an outer transaction.  */
15250   new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
15251
15252   parser->in_transaction = new_in;
15253   stmt = c_parser_compound_statement (parser);
15254   parser->in_transaction = old_in;
15255
15256   if (flag_tm)
15257     stmt = c_finish_transaction (loc, stmt, this_in);
15258   else
15259     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15260         "%<__transaction_atomic%> without transactional memory support enabled"
15261         : "%<__transaction_relaxed %> "
15262         "without transactional memory support enabled"));
15263
15264   return stmt;
15265 }
15266
15267 /* Parse a __transaction_atomic or __transaction_relaxed expression
15268    (GCC Extension).
15269
15270    transaction-expression:
15271      __transaction_atomic ( expression )
15272      __transaction_relaxed ( expression )
15273 */
15274
15275 static struct c_expr
15276 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
15277 {
15278   struct c_expr ret;
15279   unsigned int old_in = parser->in_transaction;
15280   unsigned int this_in = 1;
15281   location_t loc = c_parser_peek_token (parser)->location;
15282   tree attrs;
15283
15284   gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15285       || keyword == RID_TRANSACTION_RELAXED)
15286       && c_parser_next_token_is_keyword (parser, keyword));
15287   c_parser_consume_token (parser);
15288
15289   if (keyword == RID_TRANSACTION_RELAXED)
15290     this_in |= TM_STMT_ATTR_RELAXED;
15291   else
15292     {
15293       attrs = c_parser_transaction_attributes (parser);
15294       if (attrs)
15295         this_in |= parse_tm_stmt_attr (attrs, 0);
15296     }
15297
15298   parser->in_transaction = this_in;
15299   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15300     {
15301       tree expr = c_parser_expression (parser).value;
15302       ret.original_type = TREE_TYPE (expr);
15303       ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
15304       if (this_in & TM_STMT_ATTR_RELAXED)
15305         TRANSACTION_EXPR_RELAXED (ret.value) = 1;
15306       SET_EXPR_LOCATION (ret.value, loc);
15307       ret.original_code = TRANSACTION_EXPR;
15308       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
15309         {
15310           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
15311           goto error;
15312         }
15313     }
15314   else
15315     {
15316      error:
15317       ret.value = error_mark_node;
15318       ret.original_code = ERROR_MARK;
15319       ret.original_type = NULL;
15320     }
15321   parser->in_transaction = old_in;
15322
15323   if (!flag_tm)
15324     error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15325         "%<__transaction_atomic%> without transactional memory support enabled"
15326         : "%<__transaction_relaxed %> "
15327         "without transactional memory support enabled"));
15328
15329   return ret;
15330 }
15331
15332 /* Parse a __transaction_cancel statement (GCC Extension).
15333
15334    transaction-cancel-statement:
15335      __transaction_cancel transaction-attribute[opt] ;
15336
15337    Note that the only valid attribute is "outer".
15338 */
15339
15340 static tree
15341 c_parser_transaction_cancel (c_parser *parser)
15342 {
15343   location_t loc = c_parser_peek_token (parser)->location;
15344   tree attrs;
15345   bool is_outer = false;
15346
15347   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
15348   c_parser_consume_token (parser);
15349
15350   attrs = c_parser_transaction_attributes (parser);
15351   if (attrs)
15352     is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
15353
15354   if (!flag_tm)
15355     {
15356       error_at (loc, "%<__transaction_cancel%> without "
15357                 "transactional memory support enabled");
15358       goto ret_error;
15359     }
15360   else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
15361     {
15362       error_at (loc, "%<__transaction_cancel%> within a "
15363                 "%<__transaction_relaxed%>");
15364       goto ret_error;
15365     }
15366   else if (is_outer)
15367     {
15368       if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
15369           && !is_tm_may_cancel_outer (current_function_decl))
15370         {
15371           error_at (loc, "outer %<__transaction_cancel%> not "
15372                     "within outer %<__transaction_atomic%>");
15373           error_at (loc, "  or a %<transaction_may_cancel_outer%> function");
15374           goto ret_error;
15375         }
15376     }
15377   else if (parser->in_transaction == 0)
15378     {
15379       error_at (loc, "%<__transaction_cancel%> not within "
15380                 "%<__transaction_atomic%>");
15381       goto ret_error;
15382     }
15383
15384   return add_stmt (build_tm_abort_call (loc, is_outer));
15385
15386  ret_error:
15387   return build1 (NOP_EXPR, void_type_node, error_mark_node);
15388 }
15389 \f
15390 /* Parse a single source file.  */
15391
15392 void
15393 c_parse_file (void)
15394 {
15395   /* Use local storage to begin.  If the first token is a pragma, parse it.
15396      If it is #pragma GCC pch_preprocess, then this will load a PCH file
15397      which will cause garbage collection.  */
15398   c_parser tparser;
15399
15400   memset (&tparser, 0, sizeof tparser);
15401   tparser.tokens = &tparser.tokens_buf[0];
15402   the_parser = &tparser;
15403
15404   if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
15405     c_parser_pragma_pch_preprocess (&tparser);
15406
15407   the_parser = ggc_alloc<c_parser> ();
15408   *the_parser = tparser;
15409   if (tparser.tokens == &tparser.tokens_buf[0])
15410     the_parser->tokens = &the_parser->tokens_buf[0];
15411
15412   /* Initialize EH, if we've been told to do so.  */
15413   if (flag_exceptions)
15414     using_eh_for_cleanups ();
15415
15416   c_parser_translation_unit (the_parser);
15417   the_parser = NULL;
15418 }
15419
15420 /* This function parses Cilk Plus array notation.  The starting index is
15421    passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE.  The
15422    return value of this function is a tree_node called VALUE_TREE of type
15423    ARRAY_NOTATION_REF.  */
15424
15425 static tree 
15426 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index, 
15427                          tree array_value)
15428 {
15429   c_token *token = NULL;
15430   tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE;
15431   tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE;
15432   tree array_type_domain = NULL_TREE; 
15433
15434   if (array_value == error_mark_node || initial_index == error_mark_node)
15435     {
15436       /* No need to continue.  If either of these 2 were true, then an error
15437          must be emitted already.  Thus, no need to emit them twice.  */
15438       c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15439       return error_mark_node;
15440     }
15441   
15442   array_type = TREE_TYPE (array_value);
15443   gcc_assert (array_type);
15444   if (TREE_CODE (array_type) != ARRAY_TYPE
15445       && TREE_CODE (array_type) != POINTER_TYPE)
15446     {
15447       error_at (loc, "base of array section must be pointer or array type");
15448       c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15449       return error_mark_node;
15450     }
15451   type = TREE_TYPE (array_type);
15452   token = c_parser_peek_token (parser);
15453    
15454   if (token->type == CPP_EOF)
15455     {
15456       c_parser_error (parser, "expected %<:%> or numeral");
15457       return value_tree;
15458     }
15459   else if (token->type == CPP_COLON)
15460     {
15461       if (!initial_index)
15462         {
15463           /* If we are here, then we have a case like this A[:].  */
15464           c_parser_consume_token (parser);
15465           if (TREE_CODE (array_type) == POINTER_TYPE)
15466             {
15467               error_at (loc, "start-index and length fields necessary for "
15468                         "using array notations in pointers");
15469               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15470               return error_mark_node;
15471             }
15472           if (TREE_CODE (array_type) == FUNCTION_TYPE)
15473             {
15474               error_at (loc, "array notations cannot be used with function "
15475                         "type");
15476               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15477               return error_mark_node;
15478             }
15479           array_type_domain = TYPE_DOMAIN (array_type);
15480
15481           if (!array_type_domain)
15482             {
15483               error_at (loc, "start-index and length fields necessary for "
15484                         "using array notations in dimensionless arrays");
15485               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15486               return error_mark_node;
15487             }
15488
15489           start_index = TYPE_MINVAL (array_type_domain);
15490           start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node,
15491                                      start_index);
15492           if (!TYPE_MAXVAL (array_type_domain)
15493               || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain)))
15494             {
15495               error_at (loc, "start-index and length fields necessary for "
15496                         "using array notations in variable-length arrays");
15497               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15498               return error_mark_node;
15499             }
15500           end_index = TYPE_MAXVAL (array_type_domain);
15501           end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index),
15502                                    end_index, integer_one_node);
15503           end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index);
15504           stride = build_int_cst (integer_type_node, 1);
15505           stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride);
15506         }
15507       else if (initial_index != error_mark_node)
15508         {
15509           /* If we are here, then there should be 2 possibilities:
15510              1. Array [EXPR : EXPR]
15511              2. Array [EXPR : EXPR : EXPR]
15512           */
15513           start_index = initial_index;
15514
15515           if (TREE_CODE (array_type) == FUNCTION_TYPE)
15516             {
15517               error_at (loc, "array notations cannot be used with function "
15518                         "type");
15519               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15520               return error_mark_node;
15521             }
15522           c_parser_consume_token (parser); /* consume the ':' */
15523           struct c_expr ce = c_parser_expression (parser);
15524           ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15525           end_index = ce.value;
15526           if (!end_index || end_index == error_mark_node)
15527             {
15528               c_parser_skip_to_end_of_block_or_statement (parser);
15529               return error_mark_node;
15530             }
15531           if (c_parser_peek_token (parser)->type == CPP_COLON)
15532             {
15533               c_parser_consume_token (parser);
15534               ce = c_parser_expression (parser);
15535               ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15536               stride = ce.value;
15537               if (!stride || stride == error_mark_node)
15538                 {
15539                   c_parser_skip_to_end_of_block_or_statement (parser);
15540                   return error_mark_node;
15541                 }
15542             }
15543         }
15544       else
15545         c_parser_error (parser, "expected array notation expression");
15546     }
15547   else
15548     c_parser_error (parser, "expected array notation expression");
15549   
15550   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15551
15552   value_tree = build_array_notation_ref (loc, array_value, start_index,
15553                                          end_index, stride, type);
15554   if (value_tree != error_mark_node)
15555     SET_EXPR_LOCATION (value_tree, loc);
15556   return value_tree;
15557 }
15558
15559 #include "gt-c-c-parser.h"