OSDN Git Service

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