1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
47 #include "double-int.h"
52 #include "fold-const.h"
53 #include "stringpool.h"
55 #include "stor-layout.h"
57 #include "trans-mem.h"
58 #include "langhooks.h"
62 #include "c-family/c-pragma.h"
67 #include "c-family/c-common.h"
68 #include "c-family/c-objc.h"
73 #include "plugin-api.h"
77 #include "hard-reg-set.h"
84 #include "gomp-constants.h"
87 /* Initialization routine for this file. */
92 /* The only initialization required is of the reserved word
98 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
99 the c_token structure. */
100 gcc_assert (RID_MAX <= 255);
107 mask |= D_ASM | D_EXT;
111 if (!c_dialect_objc ())
112 mask |= D_OBJC | D_CXX_OBJC;
114 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
115 for (i = 0; i < num_c_common_reswords; i++)
117 /* If a keyword is disabled, do not enter it into the table
118 and so create a canonical spelling that isn't a keyword. */
119 if (c_common_reswords[i].disable & mask)
122 && (c_common_reswords[i].disable & D_CXXWARN))
124 id = get_identifier (c_common_reswords[i].word);
125 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
126 C_IS_RESERVED_WORD (id) = 1;
131 id = get_identifier (c_common_reswords[i].word);
132 C_SET_RID_CODE (id, c_common_reswords[i].rid);
133 C_IS_RESERVED_WORD (id) = 1;
134 ridpointers [(int) c_common_reswords[i].rid] = id;
137 for (i = 0; i < NUM_INT_N_ENTS; i++)
139 /* We always create the symbols but they aren't always supported. */
141 sprintf (name, "__int%d", int_n_data[i].bitsize);
142 id = get_identifier (name);
143 C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
144 C_IS_RESERVED_WORD (id) = 1;
148 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
149 and the C parser. Unlike the C++ lexer, the parser structure
150 stores the lexer information instead of using a separate structure.
151 Identifiers are separated into ordinary identifiers, type names,
152 keywords and some other Objective-C types of identifiers, and some
153 look-ahead is maintained.
155 ??? It might be a good idea to lex the whole file up front (as for
156 C++). It would then be possible to share more of the C and C++
157 lexer code, if desired. */
159 /* More information about the type of a CPP_NAME token. */
160 typedef enum c_id_kind {
161 /* An ordinary identifier. */
163 /* An identifier declared as a typedef name. */
165 /* An identifier declared as an Objective-C class name. */
167 /* An address space identifier. */
169 /* Not an identifier. */
173 /* A single C token after string literal concatenation and conversion
174 of preprocessing tokens to tokens. */
175 typedef struct GTY (()) c_token {
176 /* The kind of token. */
177 ENUM_BITFIELD (cpp_ttype) type : 8;
178 /* If this token is a CPP_NAME, this value indicates whether also
179 declared as some kind of type. Otherwise, it is C_ID_NONE. */
180 ENUM_BITFIELD (c_id_kind) id_kind : 8;
181 /* If this token is a keyword, this value indicates which keyword.
182 Otherwise, this value is RID_MAX. */
183 ENUM_BITFIELD (rid) keyword : 8;
184 /* If this token is a CPP_PRAGMA, this indicates the pragma that
185 was seen. Otherwise it is PRAGMA_NONE. */
186 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
187 /* The location at which this token was found. */
189 /* The value associated with this token, if any. */
193 /* A parser structure recording information about the state and
194 context of parsing. Includes lexer information with up to two
195 tokens of look-ahead; more are not needed for C. */
196 typedef struct GTY(()) c_parser {
197 /* The look-ahead tokens. */
198 c_token * GTY((skip)) tokens;
199 /* Buffer for look-ahead tokens. */
200 c_token tokens_buf[2];
201 /* How many look-ahead tokens are available (0, 1 or 2, or
202 more if parsing from pre-lexed tokens). */
203 unsigned int tokens_avail;
204 /* True if a syntax error is being recovered from; false otherwise.
205 c_parser_error sets this flag. It should clear this flag when
206 enough tokens have been consumed to recover from the error. */
207 BOOL_BITFIELD error : 1;
208 /* True if we're processing a pragma, and shouldn't automatically
209 consume CPP_PRAGMA_EOL. */
210 BOOL_BITFIELD in_pragma : 1;
211 /* True if we're parsing the outermost block of an if statement. */
212 BOOL_BITFIELD in_if_block : 1;
213 /* True if we want to lex an untranslated string. */
214 BOOL_BITFIELD lex_untranslated_string : 1;
216 /* Objective-C specific parser/lexer information. */
218 /* True if we are in a context where the Objective-C "PQ" keywords
219 are considered keywords. */
220 BOOL_BITFIELD objc_pq_context : 1;
221 /* True if we are parsing a (potential) Objective-C foreach
222 statement. This is set to true after we parsed 'for (' and while
223 we wait for 'in' or ';' to decide if it's a standard C for loop or an
224 Objective-C foreach loop. */
225 BOOL_BITFIELD objc_could_be_foreach_context : 1;
226 /* The following flag is needed to contextualize Objective-C lexical
227 analysis. In some cases (e.g., 'int NSObject;'), it is
228 undesirable to bind an identifier to an Objective-C class, even
229 if a class with that name exists. */
230 BOOL_BITFIELD objc_need_raw_identifier : 1;
231 /* Nonzero if we're processing a __transaction statement. The value
232 is 1 | TM_STMT_ATTR_*. */
233 unsigned int in_transaction : 4;
234 /* True if we are in a context where the Objective-C "Property attribute"
235 keywords are valid. */
236 BOOL_BITFIELD objc_property_attr_context : 1;
238 /* Cilk Plus specific parser/lexer information. */
240 /* Buffer to hold all the tokens from parsing the vector attribute for the
241 SIMD-enabled functions (formerly known as elemental functions). */
242 vec <c_token, va_gc> *cilk_simd_fn_tokens;
246 /* The actual parser and external interface. ??? Does this need to be
247 garbage-collected? */
249 static GTY (()) c_parser *the_parser;
251 /* Read in and lex a single token, storing it in *TOKEN. */
254 c_lex_one_token (c_parser *parser, c_token *token)
256 timevar_push (TV_LEX);
258 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
259 (parser->lex_untranslated_string
260 ? C_LEX_STRING_NO_TRANSLATE : 0));
261 token->id_kind = C_ID_NONE;
262 token->keyword = RID_MAX;
263 token->pragma_kind = PRAGMA_NONE;
271 bool objc_force_identifier = parser->objc_need_raw_identifier;
272 if (c_dialect_objc ())
273 parser->objc_need_raw_identifier = false;
275 if (C_IS_RESERVED_WORD (token->value))
277 enum rid rid_code = C_RID_CODE (token->value);
279 if (rid_code == RID_CXX_COMPAT_WARN)
281 warning_at (token->location,
283 "identifier %qE conflicts with C++ keyword",
286 else if (rid_code >= RID_FIRST_ADDR_SPACE
287 && rid_code <= RID_LAST_ADDR_SPACE)
289 token->id_kind = C_ID_ADDRSPACE;
290 token->keyword = rid_code;
293 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
295 /* We found an Objective-C "pq" keyword (in, out,
296 inout, bycopy, byref, oneway). They need special
297 care because the interpretation depends on the
299 if (parser->objc_pq_context)
301 token->type = CPP_KEYWORD;
302 token->keyword = rid_code;
305 else if (parser->objc_could_be_foreach_context
306 && rid_code == RID_IN)
308 /* We are in Objective-C, inside a (potential)
309 foreach context (which means after having
310 parsed 'for (', but before having parsed ';'),
311 and we found 'in'. We consider it the keyword
312 which terminates the declaration at the
313 beginning of a foreach-statement. Note that
314 this means you can't use 'in' for anything else
315 in that context; in particular, in Objective-C
316 you can't use 'in' as the name of the running
317 variable in a C for loop. We could potentially
318 try to add code here to disambiguate, but it
319 seems a reasonable limitation. */
320 token->type = CPP_KEYWORD;
321 token->keyword = rid_code;
324 /* Else, "pq" keywords outside of the "pq" context are
325 not keywords, and we fall through to the code for
328 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
330 /* We found an Objective-C "property attribute"
331 keyword (getter, setter, readonly, etc). These are
332 only valid in the property context. */
333 if (parser->objc_property_attr_context)
335 token->type = CPP_KEYWORD;
336 token->keyword = rid_code;
339 /* Else they are not special keywords.
342 else if (c_dialect_objc ()
343 && (OBJC_IS_AT_KEYWORD (rid_code)
344 || OBJC_IS_CXX_KEYWORD (rid_code)))
346 /* We found one of the Objective-C "@" keywords (defs,
347 selector, synchronized, etc) or one of the
348 Objective-C "cxx" keywords (class, private,
349 protected, public, try, catch, throw) without a
350 preceding '@' sign. Do nothing and fall through to
351 the code for normal tokens (in C++ we would still
352 consider the CXX ones keywords, but not in C). */
357 token->type = CPP_KEYWORD;
358 token->keyword = rid_code;
363 decl = lookup_name (token->value);
366 if (TREE_CODE (decl) == TYPE_DECL)
368 token->id_kind = C_ID_TYPENAME;
372 else if (c_dialect_objc ())
374 tree objc_interface_decl = objc_is_class_name (token->value);
375 /* Objective-C class names are in the same namespace as
376 variables and typedefs, and hence are shadowed by local
378 if (objc_interface_decl
379 && (!objc_force_identifier || global_bindings_p ()))
381 token->value = objc_interface_decl;
382 token->id_kind = C_ID_CLASSNAME;
386 token->id_kind = C_ID_ID;
390 /* This only happens in Objective-C; it must be a keyword. */
391 token->type = CPP_KEYWORD;
392 switch (C_RID_CODE (token->value))
394 /* Replace 'class' with '@class', 'private' with '@private',
395 etc. This prevents confusion with the C++ keyword
396 'class', and makes the tokens consistent with other
397 Objective-C 'AT' keywords. For example '@class' is
398 reported as RID_AT_CLASS which is consistent with
399 '@synchronized', which is reported as
402 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
403 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
404 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
405 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
406 case RID_THROW: token->keyword = RID_AT_THROW; break;
407 case RID_TRY: token->keyword = RID_AT_TRY; break;
408 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
409 default: token->keyword = C_RID_CODE (token->value);
414 case CPP_CLOSE_PAREN:
416 /* These tokens may affect the interpretation of any identifiers
417 following, if doing Objective-C. */
418 if (c_dialect_objc ())
419 parser->objc_need_raw_identifier = false;
422 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
423 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
429 timevar_pop (TV_LEX);
432 /* Return a pointer to the next token from PARSER, reading it in if
435 static inline c_token *
436 c_parser_peek_token (c_parser *parser)
438 if (parser->tokens_avail == 0)
440 c_lex_one_token (parser, &parser->tokens[0]);
441 parser->tokens_avail = 1;
443 return &parser->tokens[0];
446 /* Return true if the next token from PARSER has the indicated
450 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
452 return c_parser_peek_token (parser)->type == type;
455 /* Return true if the next token from PARSER does not have the
459 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
461 return !c_parser_next_token_is (parser, type);
464 /* Return true if the next token from PARSER is the indicated
468 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
470 return c_parser_peek_token (parser)->keyword == keyword;
473 /* Return a pointer to the next-but-one token from PARSER, reading it
474 in if necessary. The next token is already read in. */
477 c_parser_peek_2nd_token (c_parser *parser)
479 if (parser->tokens_avail >= 2)
480 return &parser->tokens[1];
481 gcc_assert (parser->tokens_avail == 1);
482 gcc_assert (parser->tokens[0].type != CPP_EOF);
483 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
484 c_lex_one_token (parser, &parser->tokens[1]);
485 parser->tokens_avail = 2;
486 return &parser->tokens[1];
489 /* Return true if TOKEN can start a type name,
492 c_token_starts_typename (c_token *token)
497 switch (token->id_kind)
506 gcc_assert (c_dialect_objc ());
512 switch (token->keyword)
543 if (token->keyword >= RID_FIRST_INT_N
544 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
545 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
550 if (c_dialect_objc ())
558 enum c_lookahead_kind {
559 /* Always treat unknown identifiers as typenames. */
562 /* Could be parsing a nonabstract declarator. Only treat an identifier
563 as a typename if followed by another identifier or a star. */
564 cla_nonabstract_decl,
566 /* Never treat identifiers as typenames. */
570 /* Return true if the next token from PARSER can start a type name,
571 false otherwise. LA specifies how to do lookahead in order to
572 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
575 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
577 c_token *token = c_parser_peek_token (parser);
578 if (c_token_starts_typename (token))
581 /* Try a bit harder to detect an unknown typename. */
582 if (la != cla_prefer_id
583 && token->type == CPP_NAME
584 && token->id_kind == C_ID_ID
586 /* Do not try too hard when we could have "object in array". */
587 && !parser->objc_could_be_foreach_context
589 && (la == cla_prefer_type
590 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
591 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
593 /* Only unknown identifiers. */
594 && !lookup_name (token->value))
600 /* Return true if TOKEN is a type qualifier, false otherwise. */
602 c_token_is_qualifier (c_token *token)
607 switch (token->id_kind)
615 switch (token->keyword)
633 /* Return true if the next token from PARSER is a type qualifier,
636 c_parser_next_token_is_qualifier (c_parser *parser)
638 c_token *token = c_parser_peek_token (parser);
639 return c_token_is_qualifier (token);
642 /* Return true if TOKEN can start declaration specifiers, false
645 c_token_starts_declspecs (c_token *token)
650 switch (token->id_kind)
659 gcc_assert (c_dialect_objc ());
665 switch (token->keyword)
705 if (token->keyword >= RID_FIRST_INT_N
706 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
707 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
712 if (c_dialect_objc ())
721 /* Return true if TOKEN can start declaration specifiers or a static
722 assertion, false otherwise. */
724 c_token_starts_declaration (c_token *token)
726 if (c_token_starts_declspecs (token)
727 || token->keyword == RID_STATIC_ASSERT)
733 /* Return true if the next token from PARSER can start declaration
734 specifiers, false otherwise. */
736 c_parser_next_token_starts_declspecs (c_parser *parser)
738 c_token *token = c_parser_peek_token (parser);
740 /* In Objective-C, a classname normally starts a declspecs unless it
741 is immediately followed by a dot. In that case, it is the
742 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
743 setter/getter on the class. c_token_starts_declspecs() can't
744 differentiate between the two cases because it only checks the
745 current token, so we have a special check here. */
746 if (c_dialect_objc ()
747 && token->type == CPP_NAME
748 && token->id_kind == C_ID_CLASSNAME
749 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
752 return c_token_starts_declspecs (token);
755 /* Return true if the next tokens from PARSER can start declaration
756 specifiers or a static assertion, false otherwise. */
758 c_parser_next_tokens_start_declaration (c_parser *parser)
760 c_token *token = c_parser_peek_token (parser);
763 if (c_dialect_objc ()
764 && token->type == CPP_NAME
765 && token->id_kind == C_ID_CLASSNAME
766 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
769 /* Labels do not start declarations. */
770 if (token->type == CPP_NAME
771 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
774 if (c_token_starts_declaration (token))
777 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
783 /* Consume the next token from PARSER. */
786 c_parser_consume_token (c_parser *parser)
788 gcc_assert (parser->tokens_avail >= 1);
789 gcc_assert (parser->tokens[0].type != CPP_EOF);
790 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
791 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
792 if (parser->tokens != &parser->tokens_buf[0])
794 else if (parser->tokens_avail == 2)
795 parser->tokens[0] = parser->tokens[1];
796 parser->tokens_avail--;
799 /* Expect the current token to be a #pragma. Consume it and remember
800 that we've begun parsing a pragma. */
803 c_parser_consume_pragma (c_parser *parser)
805 gcc_assert (!parser->in_pragma);
806 gcc_assert (parser->tokens_avail >= 1);
807 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
808 if (parser->tokens != &parser->tokens_buf[0])
810 else if (parser->tokens_avail == 2)
811 parser->tokens[0] = parser->tokens[1];
812 parser->tokens_avail--;
813 parser->in_pragma = true;
816 /* Update the global input_location from TOKEN. */
818 c_parser_set_source_position_from_token (c_token *token)
820 if (token->type != CPP_EOF)
822 input_location = token->location;
826 /* Issue a diagnostic of the form
827 FILE:LINE: MESSAGE before TOKEN
828 where TOKEN is the next token in the input stream of PARSER.
829 MESSAGE (specified by the caller) is usually of the form "expected
832 Do not issue a diagnostic if still recovering from an error.
834 ??? This is taken from the C++ parser, but building up messages in
835 this way is not i18n-friendly and some other approach should be
839 c_parser_error (c_parser *parser, const char *gmsgid)
841 c_token *token = c_parser_peek_token (parser);
844 parser->error = true;
847 /* This diagnostic makes more sense if it is tagged to the line of
848 the token we just peeked at. */
849 c_parser_set_source_position_from_token (token);
850 c_parse_error (gmsgid,
851 /* Because c_parse_error does not understand
852 CPP_KEYWORD, keywords are treated like
854 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
855 /* ??? The C parser does not save the cpp flags of a
856 token, we need to pass 0 here and we will not get
857 the source spelling of some tokens but rather the
858 canonical spelling. */
859 token->value, /*flags=*/0);
862 /* If the next token is of the indicated TYPE, consume it. Otherwise,
863 issue the error MSGID. If MSGID is NULL then a message has already
864 been produced and no message will be produced this time. Returns
865 true if found, false otherwise. */
868 c_parser_require (c_parser *parser,
872 if (c_parser_next_token_is (parser, type))
874 c_parser_consume_token (parser);
879 c_parser_error (parser, msgid);
884 /* If the next token is the indicated keyword, consume it. Otherwise,
885 issue the error MSGID. Returns true if found, false otherwise. */
888 c_parser_require_keyword (c_parser *parser,
892 if (c_parser_next_token_is_keyword (parser, keyword))
894 c_parser_consume_token (parser);
899 c_parser_error (parser, msgid);
904 /* Like c_parser_require, except that tokens will be skipped until the
905 desired token is found. An error message is still produced if the
906 next token is not as expected. If MSGID is NULL then a message has
907 already been produced and no message will be produced this
911 c_parser_skip_until_found (c_parser *parser,
915 unsigned nesting_depth = 0;
917 if (c_parser_require (parser, type, msgid))
920 /* Skip tokens until the desired token is found. */
923 /* Peek at the next token. */
924 c_token *token = c_parser_peek_token (parser);
925 /* If we've reached the token we want, consume it and stop. */
926 if (token->type == type && !nesting_depth)
928 c_parser_consume_token (parser);
932 /* If we've run out of tokens, stop. */
933 if (token->type == CPP_EOF)
935 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
937 if (token->type == CPP_OPEN_BRACE
938 || token->type == CPP_OPEN_PAREN
939 || token->type == CPP_OPEN_SQUARE)
941 else if (token->type == CPP_CLOSE_BRACE
942 || token->type == CPP_CLOSE_PAREN
943 || token->type == CPP_CLOSE_SQUARE)
945 if (nesting_depth-- == 0)
948 /* Consume this token. */
949 c_parser_consume_token (parser);
951 parser->error = false;
954 /* Skip tokens until the end of a parameter is found, but do not
955 consume the comma, semicolon or closing delimiter. */
958 c_parser_skip_to_end_of_parameter (c_parser *parser)
960 unsigned nesting_depth = 0;
964 c_token *token = c_parser_peek_token (parser);
965 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
968 /* If we've run out of tokens, stop. */
969 if (token->type == CPP_EOF)
971 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
973 if (token->type == CPP_OPEN_BRACE
974 || token->type == CPP_OPEN_PAREN
975 || token->type == CPP_OPEN_SQUARE)
977 else if (token->type == CPP_CLOSE_BRACE
978 || token->type == CPP_CLOSE_PAREN
979 || token->type == CPP_CLOSE_SQUARE)
981 if (nesting_depth-- == 0)
984 /* Consume this token. */
985 c_parser_consume_token (parser);
987 parser->error = false;
990 /* Expect to be at the end of the pragma directive and consume an
991 end of line marker. */
994 c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
996 gcc_assert (parser->in_pragma);
997 parser->in_pragma = false;
999 if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
1000 c_parser_error (parser, "expected end of line");
1002 cpp_ttype token_type;
1005 c_token *token = c_parser_peek_token (parser);
1006 token_type = token->type;
1007 if (token_type == CPP_EOF)
1009 c_parser_consume_token (parser);
1011 while (token_type != CPP_PRAGMA_EOL);
1013 parser->error = false;
1016 /* Skip tokens until we have consumed an entire block, or until we
1017 have consumed a non-nested ';'. */
1020 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1022 unsigned nesting_depth = 0;
1023 bool save_error = parser->error;
1029 /* Peek at the next token. */
1030 token = c_parser_peek_token (parser);
1032 switch (token->type)
1037 case CPP_PRAGMA_EOL:
1038 if (parser->in_pragma)
1043 /* If the next token is a ';', we have reached the
1044 end of the statement. */
1047 /* Consume the ';'. */
1048 c_parser_consume_token (parser);
1053 case CPP_CLOSE_BRACE:
1054 /* If the next token is a non-nested '}', then we have
1055 reached the end of the current block. */
1056 if (nesting_depth == 0 || --nesting_depth == 0)
1058 c_parser_consume_token (parser);
1063 case CPP_OPEN_BRACE:
1064 /* If it the next token is a '{', then we are entering a new
1065 block. Consume the entire block. */
1070 /* If we see a pragma, consume the whole thing at once. We
1071 have some safeguards against consuming pragmas willy-nilly.
1072 Normally, we'd expect to be here with parser->error set,
1073 which disables these safeguards. But it's possible to get
1074 here for secondary error recovery, after parser->error has
1076 c_parser_consume_pragma (parser);
1077 c_parser_skip_to_pragma_eol (parser);
1078 parser->error = save_error;
1085 c_parser_consume_token (parser);
1089 parser->error = false;
1092 /* CPP's options (initialized by c-opts.c). */
1093 extern cpp_options *cpp_opts;
1095 /* Save the warning flags which are controlled by __extension__. */
1098 disable_extension_diagnostics (void)
1101 | (warn_pointer_arith << 1)
1102 | (warn_traditional << 2)
1104 | (warn_long_long << 4)
1105 | (warn_cxx_compat << 5)
1106 | (warn_overlength_strings << 6)
1107 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1108 play tricks to properly restore it. */
1109 | ((warn_c90_c99_compat == 1) << 7)
1110 | ((warn_c90_c99_compat == -1) << 8)
1111 /* Similarly for warn_c99_c11_compat. */
1112 | ((warn_c99_c11_compat == 1) << 9)
1113 | ((warn_c99_c11_compat == -1) << 10)
1115 cpp_opts->cpp_pedantic = pedantic = 0;
1116 warn_pointer_arith = 0;
1117 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1119 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1120 warn_cxx_compat = 0;
1121 warn_overlength_strings = 0;
1122 warn_c90_c99_compat = 0;
1123 warn_c99_c11_compat = 0;
1127 /* Restore the warning flags which are controlled by __extension__.
1128 FLAGS is the return value from disable_extension_diagnostics. */
1131 restore_extension_diagnostics (int flags)
1133 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1134 warn_pointer_arith = (flags >> 1) & 1;
1135 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1136 flag_iso = (flags >> 3) & 1;
1137 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1138 warn_cxx_compat = (flags >> 5) & 1;
1139 warn_overlength_strings = (flags >> 6) & 1;
1140 /* See above for why is this needed. */
1141 warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1142 warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1145 /* Possibly kinds of declarator to parse. */
1146 typedef enum c_dtr_syn {
1147 /* A normal declarator with an identifier. */
1149 /* An abstract declarator (maybe empty). */
1151 /* A parameter declarator: may be either, but after a type name does
1152 not redeclare a typedef name as an identifier if it can
1153 alternatively be interpreted as a typedef name; see DR#009,
1154 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1155 following DR#249. For example, given a typedef T, "int T" and
1156 "int *T" are valid parameter declarations redeclaring T, while
1157 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1158 abstract declarators rather than involving redundant parentheses;
1159 the same applies with attributes inside the parentheses before
1164 /* The binary operation precedence levels, where 0 is a dummy lowest level
1165 used for the bottom of the stack. */
1166 enum c_parser_prec {
1181 static void c_parser_external_declaration (c_parser *);
1182 static void c_parser_asm_definition (c_parser *);
1183 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1184 bool, bool, tree *, vec<c_token>);
1185 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1186 static void c_parser_static_assert_declaration (c_parser *);
1187 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1188 bool, bool, bool, enum c_lookahead_kind);
1189 static struct c_typespec c_parser_enum_specifier (c_parser *);
1190 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1191 static tree c_parser_struct_declaration (c_parser *);
1192 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1193 static tree c_parser_alignas_specifier (c_parser *);
1194 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1196 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1198 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1200 struct c_declarator *);
1201 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1202 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1204 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1205 static tree c_parser_simple_asm_expr (c_parser *);
1206 static tree c_parser_attributes (c_parser *);
1207 static struct c_type_name *c_parser_type_name (c_parser *);
1208 static struct c_expr c_parser_initializer (c_parser *);
1209 static struct c_expr c_parser_braced_init (c_parser *, tree, bool,
1211 static void c_parser_initelt (c_parser *, struct obstack *);
1212 static void c_parser_initval (c_parser *, struct c_expr *,
1214 static tree c_parser_compound_statement (c_parser *);
1215 static void c_parser_compound_statement_nostart (c_parser *);
1216 static void c_parser_label (c_parser *);
1217 static void c_parser_statement (c_parser *);
1218 static void c_parser_statement_after_labels (c_parser *);
1219 static void c_parser_if_statement (c_parser *);
1220 static void c_parser_switch_statement (c_parser *);
1221 static void c_parser_while_statement (c_parser *, bool);
1222 static void c_parser_do_statement (c_parser *, bool);
1223 static void c_parser_for_statement (c_parser *, bool);
1224 static tree c_parser_asm_statement (c_parser *);
1225 static tree c_parser_asm_operands (c_parser *);
1226 static tree c_parser_asm_goto_operands (c_parser *);
1227 static tree c_parser_asm_clobbers (c_parser *);
1228 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1230 static struct c_expr c_parser_conditional_expression (c_parser *,
1231 struct c_expr *, tree);
1232 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1234 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1235 static struct c_expr c_parser_unary_expression (c_parser *);
1236 static struct c_expr c_parser_sizeof_expression (c_parser *);
1237 static struct c_expr c_parser_alignof_expression (c_parser *);
1238 static struct c_expr c_parser_postfix_expression (c_parser *);
1239 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1240 struct c_type_name *,
1242 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1245 static tree c_parser_transaction (c_parser *, enum rid);
1246 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1247 static tree c_parser_transaction_cancel (c_parser *);
1248 static struct c_expr c_parser_expression (c_parser *);
1249 static struct c_expr c_parser_expression_conv (c_parser *);
1250 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1251 vec<tree, va_gc> **, location_t *,
1252 tree *, vec<location_t> *,
1253 unsigned int * = NULL);
1254 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1255 static void c_parser_oacc_update (c_parser *);
1256 static tree c_parser_oacc_loop (location_t, c_parser *, char *);
1257 static void c_parser_omp_construct (c_parser *);
1258 static void c_parser_omp_threadprivate (c_parser *);
1259 static void c_parser_omp_barrier (c_parser *);
1260 static void c_parser_omp_flush (c_parser *);
1261 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1263 static void c_parser_omp_taskwait (c_parser *);
1264 static void c_parser_omp_taskyield (c_parser *);
1265 static void c_parser_omp_cancel (c_parser *);
1266 static void c_parser_omp_cancellation_point (c_parser *);
1268 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1269 pragma_stmt, pragma_compound };
1270 static bool c_parser_pragma (c_parser *, enum pragma_context);
1271 static bool c_parser_omp_target (c_parser *, enum pragma_context);
1272 static void c_parser_omp_end_declare_target (c_parser *);
1273 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1275 /* These Objective-C parser functions are only ever called when
1276 compiling Objective-C. */
1277 static void c_parser_objc_class_definition (c_parser *, tree);
1278 static void c_parser_objc_class_instance_variables (c_parser *);
1279 static void c_parser_objc_class_declaration (c_parser *);
1280 static void c_parser_objc_alias_declaration (c_parser *);
1281 static void c_parser_objc_protocol_definition (c_parser *, tree);
1282 static bool c_parser_objc_method_type (c_parser *);
1283 static void c_parser_objc_method_definition (c_parser *);
1284 static void c_parser_objc_methodprotolist (c_parser *);
1285 static void c_parser_objc_methodproto (c_parser *);
1286 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1287 static tree c_parser_objc_type_name (c_parser *);
1288 static tree c_parser_objc_protocol_refs (c_parser *);
1289 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1290 static void c_parser_objc_synchronized_statement (c_parser *);
1291 static tree c_parser_objc_selector (c_parser *);
1292 static tree c_parser_objc_selector_arg (c_parser *);
1293 static tree c_parser_objc_receiver (c_parser *);
1294 static tree c_parser_objc_message_args (c_parser *);
1295 static tree c_parser_objc_keywordexpr (c_parser *);
1296 static void c_parser_objc_at_property_declaration (c_parser *);
1297 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1298 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1299 static bool c_parser_objc_diagnose_bad_element_prefix
1300 (c_parser *, struct c_declspecs *);
1302 /* Cilk Plus supporting routines. */
1303 static void c_parser_cilk_simd (c_parser *);
1304 static void c_parser_cilk_for (c_parser *, tree);
1305 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
1306 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
1307 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
1308 static void c_parser_cilk_grainsize (c_parser *);
1310 /* Parse a translation unit (C90 6.7, C99 6.9).
1313 external-declarations
1315 external-declarations:
1316 external-declaration
1317 external-declarations external-declaration
1326 c_parser_translation_unit (c_parser *parser)
1328 if (c_parser_next_token_is (parser, CPP_EOF))
1330 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1331 "ISO C forbids an empty translation unit");
1335 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1336 mark_valid_location_for_stdc_pragma (false);
1340 c_parser_external_declaration (parser);
1341 obstack_free (&parser_obstack, obstack_position);
1343 while (c_parser_next_token_is_not (parser, CPP_EOF));
1347 /* Parse an external declaration (C90 6.7, C99 6.9).
1349 external-declaration:
1355 external-declaration:
1358 __extension__ external-declaration
1362 external-declaration:
1363 objc-class-definition
1364 objc-class-declaration
1365 objc-alias-declaration
1366 objc-protocol-definition
1367 objc-method-definition
1372 c_parser_external_declaration (c_parser *parser)
1375 switch (c_parser_peek_token (parser)->type)
1378 switch (c_parser_peek_token (parser)->keyword)
1381 ext = disable_extension_diagnostics ();
1382 c_parser_consume_token (parser);
1383 c_parser_external_declaration (parser);
1384 restore_extension_diagnostics (ext);
1387 c_parser_asm_definition (parser);
1389 case RID_AT_INTERFACE:
1390 case RID_AT_IMPLEMENTATION:
1391 gcc_assert (c_dialect_objc ());
1392 c_parser_objc_class_definition (parser, NULL_TREE);
1395 gcc_assert (c_dialect_objc ());
1396 c_parser_objc_class_declaration (parser);
1399 gcc_assert (c_dialect_objc ());
1400 c_parser_objc_alias_declaration (parser);
1402 case RID_AT_PROTOCOL:
1403 gcc_assert (c_dialect_objc ());
1404 c_parser_objc_protocol_definition (parser, NULL_TREE);
1406 case RID_AT_PROPERTY:
1407 gcc_assert (c_dialect_objc ());
1408 c_parser_objc_at_property_declaration (parser);
1410 case RID_AT_SYNTHESIZE:
1411 gcc_assert (c_dialect_objc ());
1412 c_parser_objc_at_synthesize_declaration (parser);
1414 case RID_AT_DYNAMIC:
1415 gcc_assert (c_dialect_objc ());
1416 c_parser_objc_at_dynamic_declaration (parser);
1419 gcc_assert (c_dialect_objc ());
1420 c_parser_consume_token (parser);
1421 objc_finish_implementation ();
1428 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1429 "ISO C does not allow extra %<;%> outside of a function");
1430 c_parser_consume_token (parser);
1433 mark_valid_location_for_stdc_pragma (true);
1434 c_parser_pragma (parser, pragma_external);
1435 mark_valid_location_for_stdc_pragma (false);
1439 if (c_dialect_objc ())
1441 c_parser_objc_method_definition (parser);
1444 /* Else fall through, and yield a syntax error trying to parse
1445 as a declaration or function definition. */
1448 /* A declaration or a function definition (or, in Objective-C,
1449 an @interface or @protocol with prefix attributes). We can
1450 only tell which after parsing the declaration specifiers, if
1451 any, and the first declarator. */
1452 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1458 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1460 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1461 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1462 accepted; otherwise (old-style parameter declarations) only other
1463 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1464 assertion is accepted; otherwise (old-style parameter declarations)
1465 it is not. If NESTED is true, we are inside a function or parsing
1466 old-style parameter declarations; any functions encountered are
1467 nested functions and declaration specifiers are required; otherwise
1468 we are at top level and functions are normal functions and
1469 declaration specifiers may be optional. If EMPTY_OK is true, empty
1470 declarations are OK (subject to all other constraints); otherwise
1471 (old-style parameter declarations) they are diagnosed. If
1472 START_ATTR_OK is true, the declaration specifiers may start with
1473 attributes; otherwise they may not.
1474 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1475 declaration when parsing an Objective-C foreach statement.
1478 declaration-specifiers init-declarator-list[opt] ;
1479 static_assert-declaration
1481 function-definition:
1482 declaration-specifiers[opt] declarator declaration-list[opt]
1487 declaration-list declaration
1489 init-declarator-list:
1491 init-declarator-list , init-declarator
1494 declarator simple-asm-expr[opt] attributes[opt]
1495 declarator simple-asm-expr[opt] attributes[opt] = initializer
1499 nested-function-definition:
1500 declaration-specifiers declarator declaration-list[opt]
1504 attributes objc-class-definition
1505 attributes objc-category-definition
1506 attributes objc-protocol-definition
1508 The simple-asm-expr and attributes are GNU extensions.
1510 This function does not handle __extension__; that is handled in its
1511 callers. ??? Following the old parser, __extension__ may start
1512 external declarations, declarations in functions and declarations
1513 at the start of "for" loops, but not old-style parameter
1516 C99 requires declaration specifiers in a function definition; the
1517 absence is diagnosed through the diagnosis of implicit int. In GNU
1518 C we also allow but diagnose declarations without declaration
1519 specifiers, but only at top level (elsewhere they conflict with
1522 In Objective-C, declarations of the looping variable in a foreach
1523 statement are exceptionally terminated by 'in' (for example, 'for
1524 (NSObject *object in array) { ... }').
1529 threadprivate-directive */
1532 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1533 bool static_assert_ok, bool empty_ok,
1534 bool nested, bool start_attr_ok,
1535 tree *objc_foreach_object_declaration,
1536 vec<c_token> omp_declare_simd_clauses)
1538 struct c_declspecs *specs;
1540 tree all_prefix_attrs;
1541 bool diagnosed_no_specs = false;
1542 location_t here = c_parser_peek_token (parser)->location;
1544 if (static_assert_ok
1545 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1547 c_parser_static_assert_declaration (parser);
1550 specs = build_null_declspecs ();
1552 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1553 if (c_parser_peek_token (parser)->type == CPP_NAME
1554 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1555 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1556 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1557 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1559 error_at (here, "unknown type name %qE",
1560 c_parser_peek_token (parser)->value);
1562 /* Parse declspecs normally to get a correct pointer type, but avoid
1563 a further "fails to be a type name" error. Refuse nested functions
1564 since it is not how the user likely wants us to recover. */
1565 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1566 c_parser_peek_token (parser)->keyword = RID_VOID;
1567 c_parser_peek_token (parser)->value = error_mark_node;
1571 c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1572 true, true, cla_nonabstract_decl);
1575 c_parser_skip_to_end_of_block_or_statement (parser);
1578 if (nested && !specs->declspecs_seen_p)
1580 c_parser_error (parser, "expected declaration specifiers");
1581 c_parser_skip_to_end_of_block_or_statement (parser);
1584 finish_declspecs (specs);
1585 bool auto_type_p = specs->typespec_word == cts_auto_type;
1586 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1589 error_at (here, "%<__auto_type%> in empty declaration");
1594 shadow_tag_warned (specs, 1);
1595 pedwarn (here, 0, "empty declaration");
1597 c_parser_consume_token (parser);
1601 /* Provide better error recovery. Note that a type name here is usually
1602 better diagnosed as a redeclaration. */
1604 && specs->typespec_kind == ctsk_tagdef
1605 && c_parser_next_token_starts_declspecs (parser)
1606 && !c_parser_next_token_is (parser, CPP_NAME))
1608 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1609 parser->error = false;
1610 shadow_tag_warned (specs, 1);
1613 else if (c_dialect_objc () && !auto_type_p)
1615 /* Prefix attributes are an error on method decls. */
1616 switch (c_parser_peek_token (parser)->type)
1620 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1624 warning_at (c_parser_peek_token (parser)->location,
1626 "prefix attributes are ignored for methods");
1627 specs->attrs = NULL_TREE;
1630 c_parser_objc_method_definition (parser);
1632 c_parser_objc_methodproto (parser);
1638 /* This is where we parse 'attributes @interface ...',
1639 'attributes @implementation ...', 'attributes @protocol ...'
1640 (where attributes could be, for example, __attribute__
1643 switch (c_parser_peek_token (parser)->keyword)
1645 case RID_AT_INTERFACE:
1647 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1649 c_parser_objc_class_definition (parser, specs->attrs);
1653 case RID_AT_IMPLEMENTATION:
1655 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1659 warning_at (c_parser_peek_token (parser)->location,
1661 "prefix attributes are ignored for implementations");
1662 specs->attrs = NULL_TREE;
1664 c_parser_objc_class_definition (parser, NULL_TREE);
1668 case RID_AT_PROTOCOL:
1670 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1672 c_parser_objc_protocol_definition (parser, specs->attrs);
1679 case RID_AT_PROPERTY:
1682 c_parser_error (parser, "unexpected attribute");
1683 specs->attrs = NULL;
1691 pending_xref_error ();
1692 prefix_attrs = specs->attrs;
1693 all_prefix_attrs = prefix_attrs;
1694 specs->attrs = NULL_TREE;
1697 struct c_declarator *declarator;
1701 /* Declaring either one or more declarators (in which case we
1702 should diagnose if there were no declaration specifiers) or a
1703 function definition (in which case the diagnostic for
1704 implicit int suffices). */
1705 declarator = c_parser_declarator (parser,
1706 specs->typespec_kind != ctsk_none,
1707 C_DTR_NORMAL, &dummy);
1708 if (declarator == NULL)
1710 if (omp_declare_simd_clauses.exists ()
1711 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1712 c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1713 omp_declare_simd_clauses);
1714 c_parser_skip_to_end_of_block_or_statement (parser);
1717 if (auto_type_p && declarator->kind != cdk_id)
1720 "%<__auto_type%> requires a plain identifier"
1722 c_parser_skip_to_end_of_block_or_statement (parser);
1725 if (c_parser_next_token_is (parser, CPP_EQ)
1726 || c_parser_next_token_is (parser, CPP_COMMA)
1727 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1728 || c_parser_next_token_is_keyword (parser, RID_ASM)
1729 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1730 || c_parser_next_token_is_keyword (parser, RID_IN))
1732 tree asm_name = NULL_TREE;
1733 tree postfix_attrs = NULL_TREE;
1734 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1736 diagnosed_no_specs = true;
1737 pedwarn (here, 0, "data definition has no type or storage class");
1739 /* Having seen a data definition, there cannot now be a
1740 function definition. */
1742 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1743 asm_name = c_parser_simple_asm_expr (parser);
1744 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1746 postfix_attrs = c_parser_attributes (parser);
1747 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1749 /* This means there is an attribute specifier after
1750 the declarator in a function definition. Provide
1751 some more information for the user. */
1752 error_at (here, "attributes should be specified before the "
1753 "declarator in a function definition");
1754 c_parser_skip_to_end_of_block_or_statement (parser);
1758 if (c_parser_next_token_is (parser, CPP_EQ))
1762 location_t init_loc;
1763 c_parser_consume_token (parser);
1766 start_init (NULL_TREE, asm_name, global_bindings_p ());
1767 init_loc = c_parser_peek_token (parser)->location;
1768 init = c_parser_expr_no_commas (parser, NULL);
1769 if (TREE_CODE (init.value) == COMPONENT_REF
1770 && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
1772 "%<__auto_type%> used with a bit-field"
1774 init = convert_lvalue_to_rvalue (init_loc, init, true, true);
1775 tree init_type = TREE_TYPE (init.value);
1776 /* As with typeof, remove all qualifiers from atomic types. */
1777 if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
1779 = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
1780 bool vm_type = variably_modified_type_p (init_type,
1783 init.value = c_save_expr (init.value);
1785 specs->typespec_kind = ctsk_typeof;
1786 specs->locations[cdw_typedef] = init_loc;
1787 specs->typedef_p = true;
1788 specs->type = init_type;
1791 bool maybe_const = true;
1792 tree type_expr = c_fully_fold (init.value, false,
1794 specs->expr_const_operands &= maybe_const;
1796 specs->expr = build2 (COMPOUND_EXPR,
1797 TREE_TYPE (type_expr),
1798 specs->expr, type_expr);
1800 specs->expr = type_expr;
1802 d = start_decl (declarator, specs, true,
1803 chainon (postfix_attrs, all_prefix_attrs));
1805 d = error_mark_node;
1806 if (omp_declare_simd_clauses.exists ()
1807 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1808 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1809 omp_declare_simd_clauses);
1813 /* The declaration of the variable is in effect while
1814 its initializer is parsed. */
1815 d = start_decl (declarator, specs, true,
1816 chainon (postfix_attrs, all_prefix_attrs));
1818 d = error_mark_node;
1819 if (omp_declare_simd_clauses.exists ()
1820 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1821 c_finish_omp_declare_simd (parser, d, NULL_TREE,
1822 omp_declare_simd_clauses);
1823 start_init (d, asm_name, global_bindings_p ());
1824 init_loc = c_parser_peek_token (parser)->location;
1825 init = c_parser_initializer (parser);
1828 if (d != error_mark_node)
1830 maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
1831 finish_decl (d, init_loc, init.value,
1832 init.original_type, asm_name);
1840 "%<__auto_type%> requires an initialized "
1841 "data declaration");
1842 c_parser_skip_to_end_of_block_or_statement (parser);
1845 tree d = start_decl (declarator, specs, false,
1846 chainon (postfix_attrs,
1848 if (omp_declare_simd_clauses.exists ()
1849 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1851 tree parms = NULL_TREE;
1852 if (d && TREE_CODE (d) == FUNCTION_DECL)
1854 struct c_declarator *ce = declarator;
1856 if (ce->kind == cdk_function)
1858 parms = ce->u.arg_info->parms;
1862 ce = ce->declarator;
1865 temp_store_parm_decls (d, parms);
1866 c_finish_omp_declare_simd (parser, d, parms,
1867 omp_declare_simd_clauses);
1869 temp_pop_parm_decls ();
1872 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1873 NULL_TREE, asm_name);
1875 if (c_parser_next_token_is_keyword (parser, RID_IN))
1878 *objc_foreach_object_declaration = d;
1880 *objc_foreach_object_declaration = error_mark_node;
1883 if (c_parser_next_token_is (parser, CPP_COMMA))
1888 "%<__auto_type%> may only be used with"
1889 " a single declarator");
1890 c_parser_skip_to_end_of_block_or_statement (parser);
1893 c_parser_consume_token (parser);
1894 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1895 all_prefix_attrs = chainon (c_parser_attributes (parser),
1898 all_prefix_attrs = prefix_attrs;
1901 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1903 c_parser_consume_token (parser);
1906 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1908 /* This can only happen in Objective-C: we found the
1909 'in' that terminates the declaration inside an
1910 Objective-C foreach statement. Do not consume the
1911 token, so that the caller can use it to determine
1912 that this indeed is a foreach context. */
1917 c_parser_error (parser, "expected %<,%> or %<;%>");
1918 c_parser_skip_to_end_of_block_or_statement (parser);
1922 else if (auto_type_p)
1925 "%<__auto_type%> requires an initialized data declaration");
1926 c_parser_skip_to_end_of_block_or_statement (parser);
1931 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1932 "%<asm%> or %<__attribute__%>");
1933 c_parser_skip_to_end_of_block_or_statement (parser);
1936 /* Function definition (nested or otherwise). */
1939 pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
1940 c_push_function_context ();
1942 if (!start_function (specs, declarator, all_prefix_attrs))
1944 /* This can appear in many cases looking nothing like a
1945 function definition, so we don't give a more specific
1946 error suggesting there was one. */
1947 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1948 "or %<__attribute__%>");
1950 c_pop_function_context ();
1954 if (DECL_DECLARED_INLINE_P (current_function_decl))
1955 tv = TV_PARSE_INLINE;
1960 /* Parse old-style parameter declarations. ??? Attributes are
1961 not allowed to start declaration specifiers here because of a
1962 syntax conflict between a function declaration with attribute
1963 suffix and a function definition with an attribute prefix on
1964 first old-style parameter declaration. Following the old
1965 parser, they are not accepted on subsequent old-style
1966 parameter declarations either. However, there is no
1967 ambiguity after the first declaration, nor indeed on the
1968 first as long as we don't allow postfix attributes after a
1969 declarator with a nonempty identifier list in a definition;
1970 and postfix attributes have never been accepted here in
1971 function definitions either. */
1972 while (c_parser_next_token_is_not (parser, CPP_EOF)
1973 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1974 c_parser_declaration_or_fndef (parser, false, false, false,
1975 true, false, NULL, vNULL);
1976 store_parm_decls ();
1977 if (omp_declare_simd_clauses.exists ()
1978 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
1979 c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
1980 omp_declare_simd_clauses);
1981 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1982 = c_parser_peek_token (parser)->location;
1983 fnbody = c_parser_compound_statement (parser);
1984 if (flag_cilkplus && contains_array_notation_expr (fnbody))
1985 fnbody = expand_array_notation_exprs (fnbody);
1988 tree decl = current_function_decl;
1989 /* Mark nested functions as needing static-chain initially.
1990 lower_nested_functions will recompute it but the
1991 DECL_STATIC_CHAIN flag is also used before that happens,
1992 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1993 DECL_STATIC_CHAIN (decl) = 1;
1996 c_pop_function_context ();
1997 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
2010 /* Parse an asm-definition (asm() outside a function body). This is a
2018 c_parser_asm_definition (c_parser *parser)
2020 tree asm_str = c_parser_simple_asm_expr (parser);
2022 symtab->finalize_toplevel_asm (asm_str);
2023 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2026 /* Parse a static assertion (C11 6.7.10).
2028 static_assert-declaration:
2029 static_assert-declaration-no-semi ;
2033 c_parser_static_assert_declaration (c_parser *parser)
2035 c_parser_static_assert_declaration_no_semi (parser);
2037 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2038 c_parser_skip_to_end_of_block_or_statement (parser);
2041 /* Parse a static assertion (C11 6.7.10), without the trailing
2044 static_assert-declaration-no-semi:
2045 _Static_assert ( constant-expression , string-literal )
2049 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2051 location_t assert_loc, value_loc;
2055 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2056 assert_loc = c_parser_peek_token (parser)->location;
2058 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2059 "ISO C99 does not support %<_Static_assert%>");
2061 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2062 "ISO C90 does not support %<_Static_assert%>");
2063 c_parser_consume_token (parser);
2064 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2066 value_loc = c_parser_peek_token (parser)->location;
2067 value = c_parser_expr_no_commas (parser, NULL).value;
2068 parser->lex_untranslated_string = true;
2069 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2071 parser->lex_untranslated_string = false;
2074 switch (c_parser_peek_token (parser)->type)
2080 case CPP_UTF8STRING:
2081 string = c_parser_peek_token (parser)->value;
2082 c_parser_consume_token (parser);
2083 parser->lex_untranslated_string = false;
2086 c_parser_error (parser, "expected string literal");
2087 parser->lex_untranslated_string = false;
2090 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2092 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2094 error_at (value_loc, "expression in static assertion is not an integer");
2097 if (TREE_CODE (value) != INTEGER_CST)
2099 value = c_fully_fold (value, false, NULL);
2100 /* Strip no-op conversions. */
2101 STRIP_TYPE_NOPS (value);
2102 if (TREE_CODE (value) == INTEGER_CST)
2103 pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2104 "is not an integer constant expression");
2106 if (TREE_CODE (value) != INTEGER_CST)
2108 error_at (value_loc, "expression in static assertion is not constant");
2111 constant_expression_warning (value);
2112 if (integer_zerop (value))
2113 error_at (assert_loc, "static assertion failed: %E", string);
2116 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2117 6.7), adding them to SPECS (which may already include some).
2118 Storage class specifiers are accepted iff SCSPEC_OK; type
2119 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2120 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2121 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2123 declaration-specifiers:
2124 storage-class-specifier declaration-specifiers[opt]
2125 type-specifier declaration-specifiers[opt]
2126 type-qualifier declaration-specifiers[opt]
2127 function-specifier declaration-specifiers[opt]
2128 alignment-specifier declaration-specifiers[opt]
2130 Function specifiers (inline) are from C99, and are currently
2131 handled as storage class specifiers, as is __thread. Alignment
2132 specifiers are from C11.
2134 C90 6.5.1, C99 6.7.1:
2135 storage-class-specifier:
2143 (_Thread_local is new in C11.)
2150 (_Noreturn is new in C11.)
2152 C90 6.5.2, C99 6.7.2:
2165 [_Imaginary removed in C99 TC2]
2166 struct-or-union-specifier
2169 atomic-type-specifier
2171 (_Bool and _Complex are new in C99.)
2172 (atomic-type-specifier is new in C11.)
2174 C90 6.5.3, C99 6.7.3:
2180 address-space-qualifier
2183 (restrict is new in C99.)
2184 (_Atomic is new in C11.)
2188 declaration-specifiers:
2189 attributes declaration-specifiers[opt]
2195 identifier recognized by the target
2197 storage-class-specifier:
2211 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2212 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2214 atomic-type-specifier
2215 _Atomic ( type-name )
2220 class-name objc-protocol-refs[opt]
2221 typedef-name objc-protocol-refs
2226 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2227 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2228 bool alignspec_ok, bool auto_type_ok,
2229 enum c_lookahead_kind la)
2231 bool attrs_ok = start_attr_ok;
2232 bool seen_type = specs->typespec_kind != ctsk_none;
2235 gcc_assert (la == cla_prefer_id);
2237 while (c_parser_next_token_is (parser, CPP_NAME)
2238 || c_parser_next_token_is (parser, CPP_KEYWORD)
2239 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2241 struct c_typespec t;
2244 location_t loc = c_parser_peek_token (parser)->location;
2246 /* If we cannot accept a type, exit if the next token must start
2247 one. Also, if we already have seen a tagged definition,
2248 a typename would be an error anyway and likely the user
2249 has simply forgotten a semicolon, so we exit. */
2250 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2251 && c_parser_next_tokens_start_typename (parser, la)
2252 && !c_parser_next_token_is_qualifier (parser))
2255 if (c_parser_next_token_is (parser, CPP_NAME))
2257 c_token *name_token = c_parser_peek_token (parser);
2258 tree value = name_token->value;
2259 c_id_kind kind = name_token->id_kind;
2261 if (kind == C_ID_ADDRSPACE)
2264 = name_token->keyword - RID_FIRST_ADDR_SPACE;
2265 declspecs_add_addrspace (name_token->location, specs, as);
2266 c_parser_consume_token (parser);
2271 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2273 /* If we cannot accept a type, and the next token must start one,
2274 exit. Do the same if we already have seen a tagged definition,
2275 since it would be an error anyway and likely the user has simply
2276 forgotten a semicolon. */
2277 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2280 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2281 a C_ID_CLASSNAME. */
2282 c_parser_consume_token (parser);
2285 if (kind == C_ID_ID)
2287 error_at (loc, "unknown type name %qE", value);
2288 t.kind = ctsk_typedef;
2289 t.spec = error_mark_node;
2291 else if (kind == C_ID_TYPENAME
2292 && (!c_dialect_objc ()
2293 || c_parser_next_token_is_not (parser, CPP_LESS)))
2295 t.kind = ctsk_typedef;
2296 /* For a typedef name, record the meaning, not the name.
2297 In case of 'foo foo, bar;'. */
2298 t.spec = lookup_name (value);
2302 tree proto = NULL_TREE;
2303 gcc_assert (c_dialect_objc ());
2305 if (c_parser_next_token_is (parser, CPP_LESS))
2306 proto = c_parser_objc_protocol_refs (parser);
2307 t.spec = objc_get_protocol_qualified_type (value, proto);
2310 t.expr_const_operands = true;
2311 declspecs_add_type (name_token->location, specs, t);
2314 if (c_parser_next_token_is (parser, CPP_LESS))
2316 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2317 nisse@lysator.liu.se. */
2319 gcc_assert (c_dialect_objc ());
2320 if (!typespec_ok || seen_type)
2322 proto = c_parser_objc_protocol_refs (parser);
2324 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2326 t.expr_const_operands = true;
2327 declspecs_add_type (loc, specs, t);
2330 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2331 switch (c_parser_peek_token (parser)->keyword)
2344 /* TODO: Distinguish between function specifiers (inline, noreturn)
2345 and storage class specifiers, either here or in
2346 declspecs_add_scspec. */
2347 declspecs_add_scspec (loc, specs,
2348 c_parser_peek_token (parser)->value);
2349 c_parser_consume_token (parser);
2380 if (c_dialect_objc ())
2381 parser->objc_need_raw_identifier = true;
2382 t.kind = ctsk_resword;
2383 t.spec = c_parser_peek_token (parser)->value;
2385 t.expr_const_operands = true;
2386 declspecs_add_type (loc, specs, t);
2387 c_parser_consume_token (parser);
2394 t = c_parser_enum_specifier (parser);
2395 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2396 declspecs_add_type (loc, specs, t);
2404 t = c_parser_struct_or_union_specifier (parser);
2405 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2406 declspecs_add_type (loc, specs, t);
2409 /* ??? The old parser rejected typeof after other type
2410 specifiers, but is a syntax error the best way of
2412 if (!typespec_ok || seen_type)
2416 t = c_parser_typeof_specifier (parser);
2417 declspecs_add_type (loc, specs, t);
2420 /* C parser handling of Objective-C constructs needs
2421 checking for correct lvalue-to-rvalue conversions, and
2422 the code in build_modify_expr handling various
2423 Objective-C cases, and that in build_unary_op handling
2424 Objective-C cases for increment / decrement, also needs
2425 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2426 and objc_types_are_equivalent may also need updates. */
2427 if (c_dialect_objc ())
2428 sorry ("%<_Atomic%> in Objective-C");
2429 /* C parser handling of OpenMP constructs needs checking for
2430 correct lvalue-to-rvalue conversions. */
2432 sorry ("%<_Atomic%> with OpenMP");
2434 pedwarn_c99 (loc, OPT_Wpedantic,
2435 "ISO C99 does not support the %<_Atomic%> qualifier");
2437 pedwarn_c99 (loc, OPT_Wpedantic,
2438 "ISO C90 does not support the %<_Atomic%> qualifier");
2441 value = c_parser_peek_token (parser)->value;
2442 c_parser_consume_token (parser);
2443 if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2445 /* _Atomic ( type-name ). */
2447 c_parser_consume_token (parser);
2448 struct c_type_name *type = c_parser_type_name (parser);
2449 t.kind = ctsk_typeof;
2450 t.spec = error_mark_node;
2452 t.expr_const_operands = true;
2454 t.spec = groktypename (type, &t.expr,
2455 &t.expr_const_operands);
2456 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2458 if (t.spec != error_mark_node)
2460 if (TREE_CODE (t.spec) == ARRAY_TYPE)
2461 error_at (loc, "%<_Atomic%>-qualified array type");
2462 else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2463 error_at (loc, "%<_Atomic%>-qualified function type");
2464 else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2465 error_at (loc, "%<_Atomic%> applied to a qualified type");
2467 t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2469 declspecs_add_type (loc, specs, t);
2472 declspecs_add_qual (loc, specs, value);
2478 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2479 c_parser_consume_token (parser);
2484 attrs = c_parser_attributes (parser);
2485 declspecs_add_attrs (loc, specs, attrs);
2490 align = c_parser_alignas_specifier (parser);
2491 declspecs_add_alignas (loc, specs, align);
2500 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2503 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2504 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2505 enum attributes[opt] identifier
2507 The form with trailing comma is new in C99. The forms with
2508 attributes are GNU extensions. In GNU C, we accept any expression
2509 without commas in the syntax (assignment expressions, not just
2510 conditional expressions); assignment expressions will be diagnosed
2515 enumerator-list , enumerator
2518 enumeration-constant
2519 enumeration-constant = constant-expression
2522 static struct c_typespec
2523 c_parser_enum_specifier (c_parser *parser)
2525 struct c_typespec ret;
2527 tree ident = NULL_TREE;
2528 location_t enum_loc;
2529 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2530 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2531 enum_loc = c_parser_peek_token (parser)->location;
2532 c_parser_consume_token (parser);
2533 attrs = c_parser_attributes (parser);
2534 enum_loc = c_parser_peek_token (parser)->location;
2535 /* Set the location in case we create a decl now. */
2536 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2537 if (c_parser_next_token_is (parser, CPP_NAME))
2539 ident = c_parser_peek_token (parser)->value;
2540 ident_loc = c_parser_peek_token (parser)->location;
2541 enum_loc = ident_loc;
2542 c_parser_consume_token (parser);
2544 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2546 /* Parse an enum definition. */
2547 struct c_enum_contents the_enum;
2550 /* We chain the enumerators in reverse order, then put them in
2551 forward order at the end. */
2553 timevar_push (TV_PARSE_ENUM);
2554 type = start_enum (enum_loc, &the_enum, ident);
2556 c_parser_consume_token (parser);
2564 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2565 location_t decl_loc, value_loc;
2566 if (c_parser_next_token_is_not (parser, CPP_NAME))
2568 c_parser_error (parser, "expected identifier");
2569 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2570 values = error_mark_node;
2573 token = c_parser_peek_token (parser);
2574 enum_id = token->value;
2575 /* Set the location in case we create a decl now. */
2576 c_parser_set_source_position_from_token (token);
2577 decl_loc = value_loc = token->location;
2578 c_parser_consume_token (parser);
2579 if (c_parser_next_token_is (parser, CPP_EQ))
2581 c_parser_consume_token (parser);
2582 value_loc = c_parser_peek_token (parser)->location;
2583 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2586 enum_value = NULL_TREE;
2587 enum_decl = build_enumerator (decl_loc, value_loc,
2588 &the_enum, enum_id, enum_value);
2589 TREE_CHAIN (enum_decl) = values;
2592 if (c_parser_next_token_is (parser, CPP_COMMA))
2594 comma_loc = c_parser_peek_token (parser)->location;
2596 c_parser_consume_token (parser);
2598 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2601 pedwarn_c90 (comma_loc, OPT_Wpedantic,
2602 "comma at end of enumerator list");
2603 c_parser_consume_token (parser);
2608 c_parser_error (parser, "expected %<,%> or %<}%>");
2609 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2610 values = error_mark_node;
2614 postfix_attrs = c_parser_attributes (parser);
2615 ret.spec = finish_enum (type, nreverse (values),
2616 chainon (attrs, postfix_attrs));
2617 ret.kind = ctsk_tagdef;
2618 ret.expr = NULL_TREE;
2619 ret.expr_const_operands = true;
2620 timevar_pop (TV_PARSE_ENUM);
2625 c_parser_error (parser, "expected %<{%>");
2626 ret.spec = error_mark_node;
2627 ret.kind = ctsk_tagref;
2628 ret.expr = NULL_TREE;
2629 ret.expr_const_operands = true;
2632 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2633 /* In ISO C, enumerated types can be referred to only if already
2635 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2638 pedwarn (enum_loc, OPT_Wpedantic,
2639 "ISO C forbids forward references to %<enum%> types");
2644 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2646 struct-or-union-specifier:
2647 struct-or-union attributes[opt] identifier[opt]
2648 { struct-contents } attributes[opt]
2649 struct-or-union attributes[opt] identifier
2652 struct-declaration-list
2654 struct-declaration-list:
2655 struct-declaration ;
2656 struct-declaration-list struct-declaration ;
2663 struct-declaration-list struct-declaration
2665 struct-declaration-list:
2666 struct-declaration-list ;
2669 (Note that in the syntax here, unlike that in ISO C, the semicolons
2670 are included here rather than in struct-declaration, in order to
2671 describe the syntax with extra semicolons and missing semicolon at
2676 struct-declaration-list:
2677 @defs ( class-name )
2679 (Note this does not include a trailing semicolon, but can be
2680 followed by further declarations, and gets a pedwarn-if-pedantic
2681 when followed by a semicolon.) */
2683 static struct c_typespec
2684 c_parser_struct_or_union_specifier (c_parser *parser)
2686 struct c_typespec ret;
2688 tree ident = NULL_TREE;
2689 location_t struct_loc;
2690 location_t ident_loc = UNKNOWN_LOCATION;
2691 enum tree_code code;
2692 switch (c_parser_peek_token (parser)->keyword)
2703 struct_loc = c_parser_peek_token (parser)->location;
2704 c_parser_consume_token (parser);
2705 attrs = c_parser_attributes (parser);
2707 /* Set the location in case we create a decl now. */
2708 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2710 if (c_parser_next_token_is (parser, CPP_NAME))
2712 ident = c_parser_peek_token (parser)->value;
2713 ident_loc = c_parser_peek_token (parser)->location;
2714 struct_loc = ident_loc;
2715 c_parser_consume_token (parser);
2717 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2719 /* Parse a struct or union definition. Start the scope of the
2720 tag before parsing components. */
2721 struct c_struct_parse_info *struct_info;
2722 tree type = start_struct (struct_loc, code, ident, &struct_info);
2724 /* We chain the components in reverse order, then put them in
2725 forward order at the end. Each struct-declaration may
2726 declare multiple components (comma-separated), so we must use
2727 chainon to join them, although when parsing each
2728 struct-declaration we can use TREE_CHAIN directly.
2730 The theory behind all this is that there will be more
2731 semicolon separated fields than comma separated fields, and
2732 so we'll be minimizing the number of node traversals required
2735 timevar_push (TV_PARSE_STRUCT);
2736 contents = NULL_TREE;
2737 c_parser_consume_token (parser);
2738 /* Handle the Objective-C @defs construct,
2739 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2740 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2743 gcc_assert (c_dialect_objc ());
2744 c_parser_consume_token (parser);
2745 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2747 if (c_parser_next_token_is (parser, CPP_NAME)
2748 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2750 name = c_parser_peek_token (parser)->value;
2751 c_parser_consume_token (parser);
2755 c_parser_error (parser, "expected class name");
2756 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2759 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2761 contents = nreverse (objc_get_class_ivars (name));
2764 /* Parse the struct-declarations and semicolons. Problems with
2765 semicolons are diagnosed here; empty structures are diagnosed
2770 /* Parse any stray semicolon. */
2771 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2773 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
2774 "extra semicolon in struct or union specified");
2775 c_parser_consume_token (parser);
2778 /* Stop if at the end of the struct or union contents. */
2779 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2781 c_parser_consume_token (parser);
2784 /* Accept #pragmas at struct scope. */
2785 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2787 c_parser_pragma (parser, pragma_struct);
2790 /* Parse some comma-separated declarations, but not the
2791 trailing semicolon if any. */
2792 decls = c_parser_struct_declaration (parser);
2793 contents = chainon (decls, contents);
2794 /* If no semicolon follows, either we have a parse error or
2795 are at the end of the struct or union and should
2797 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2798 c_parser_consume_token (parser);
2801 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2802 pedwarn (c_parser_peek_token (parser)->location, 0,
2803 "no semicolon at end of struct or union");
2804 else if (parser->error
2805 || !c_parser_next_token_starts_declspecs (parser))
2807 c_parser_error (parser, "expected %<;%>");
2808 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2812 /* If we come here, we have already emitted an error
2813 for an expected `;', identifier or `(', and we also
2814 recovered already. Go on with the next field. */
2817 postfix_attrs = c_parser_attributes (parser);
2818 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2819 chainon (attrs, postfix_attrs), struct_info);
2820 ret.kind = ctsk_tagdef;
2821 ret.expr = NULL_TREE;
2822 ret.expr_const_operands = true;
2823 timevar_pop (TV_PARSE_STRUCT);
2828 c_parser_error (parser, "expected %<{%>");
2829 ret.spec = error_mark_node;
2830 ret.kind = ctsk_tagref;
2831 ret.expr = NULL_TREE;
2832 ret.expr_const_operands = true;
2835 ret = parser_xref_tag (ident_loc, code, ident);
2839 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2840 the trailing semicolon.
2843 specifier-qualifier-list struct-declarator-list
2844 static_assert-declaration-no-semi
2846 specifier-qualifier-list:
2847 type-specifier specifier-qualifier-list[opt]
2848 type-qualifier specifier-qualifier-list[opt]
2849 attributes specifier-qualifier-list[opt]
2851 struct-declarator-list:
2853 struct-declarator-list , attributes[opt] struct-declarator
2856 declarator attributes[opt]
2857 declarator[opt] : constant-expression attributes[opt]
2862 __extension__ struct-declaration
2863 specifier-qualifier-list
2865 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2866 of attributes where shown is a GNU extension. In GNU C, we accept
2867 any expression without commas in the syntax (assignment
2868 expressions, not just conditional expressions); assignment
2869 expressions will be diagnosed as non-constant. */
2872 c_parser_struct_declaration (c_parser *parser)
2874 struct c_declspecs *specs;
2876 tree all_prefix_attrs;
2878 location_t decl_loc;
2879 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2883 ext = disable_extension_diagnostics ();
2884 c_parser_consume_token (parser);
2885 decl = c_parser_struct_declaration (parser);
2886 restore_extension_diagnostics (ext);
2889 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2891 c_parser_static_assert_declaration_no_semi (parser);
2894 specs = build_null_declspecs ();
2895 decl_loc = c_parser_peek_token (parser)->location;
2896 /* Strictly by the standard, we shouldn't allow _Alignas here,
2897 but it appears to have been intended to allow it there, so
2898 we're keeping it as it is until WG14 reaches a conclusion
2900 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2901 c_parser_declspecs (parser, specs, false, true, true,
2902 true, false, cla_nonabstract_decl);
2905 if (!specs->declspecs_seen_p)
2907 c_parser_error (parser, "expected specifier-qualifier-list");
2910 finish_declspecs (specs);
2911 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2912 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2915 if (specs->typespec_kind == ctsk_none)
2917 pedwarn (decl_loc, OPT_Wpedantic,
2918 "ISO C forbids member declarations with no members");
2919 shadow_tag_warned (specs, pedantic);
2924 /* Support for unnamed structs or unions as members of
2925 structs or unions (which is [a] useful and [b] supports
2929 ret = grokfield (c_parser_peek_token (parser)->location,
2930 build_id_declarator (NULL_TREE), specs,
2933 decl_attributes (&ret, attrs, 0);
2938 /* Provide better error recovery. Note that a type name here is valid,
2939 and will be treated as a field name. */
2940 if (specs->typespec_kind == ctsk_tagdef
2941 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2942 && c_parser_next_token_starts_declspecs (parser)
2943 && !c_parser_next_token_is (parser, CPP_NAME))
2945 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2946 parser->error = false;
2950 pending_xref_error ();
2951 prefix_attrs = specs->attrs;
2952 all_prefix_attrs = prefix_attrs;
2953 specs->attrs = NULL_TREE;
2957 /* Declaring one or more declarators or un-named bit-fields. */
2958 struct c_declarator *declarator;
2960 if (c_parser_next_token_is (parser, CPP_COLON))
2961 declarator = build_id_declarator (NULL_TREE);
2963 declarator = c_parser_declarator (parser,
2964 specs->typespec_kind != ctsk_none,
2965 C_DTR_NORMAL, &dummy);
2966 if (declarator == NULL)
2968 c_parser_skip_to_end_of_block_or_statement (parser);
2971 if (c_parser_next_token_is (parser, CPP_COLON)
2972 || c_parser_next_token_is (parser, CPP_COMMA)
2973 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2974 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2975 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2977 tree postfix_attrs = NULL_TREE;
2978 tree width = NULL_TREE;
2980 if (c_parser_next_token_is (parser, CPP_COLON))
2982 c_parser_consume_token (parser);
2983 width = c_parser_expr_no_commas (parser, NULL).value;
2985 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2986 postfix_attrs = c_parser_attributes (parser);
2987 d = grokfield (c_parser_peek_token (parser)->location,
2988 declarator, specs, width, &all_prefix_attrs);
2989 decl_attributes (&d, chainon (postfix_attrs,
2990 all_prefix_attrs), 0);
2991 DECL_CHAIN (d) = decls;
2993 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2994 all_prefix_attrs = chainon (c_parser_attributes (parser),
2997 all_prefix_attrs = prefix_attrs;
2998 if (c_parser_next_token_is (parser, CPP_COMMA))
2999 c_parser_consume_token (parser);
3000 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3001 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3003 /* Semicolon consumed in caller. */
3008 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3014 c_parser_error (parser,
3015 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3016 "%<__attribute__%>");
3023 /* Parse a typeof specifier (a GNU extension).
3026 typeof ( expression )
3027 typeof ( type-name )
3030 static struct c_typespec
3031 c_parser_typeof_specifier (c_parser *parser)
3033 struct c_typespec ret;
3034 ret.kind = ctsk_typeof;
3035 ret.spec = error_mark_node;
3036 ret.expr = NULL_TREE;
3037 ret.expr_const_operands = true;
3038 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3039 c_parser_consume_token (parser);
3040 c_inhibit_evaluation_warnings++;
3042 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3044 c_inhibit_evaluation_warnings--;
3048 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3050 struct c_type_name *type = c_parser_type_name (parser);
3051 c_inhibit_evaluation_warnings--;
3055 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3056 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3062 location_t here = c_parser_peek_token (parser)->location;
3063 struct c_expr expr = c_parser_expression (parser);
3064 c_inhibit_evaluation_warnings--;
3066 if (TREE_CODE (expr.value) == COMPONENT_REF
3067 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3068 error_at (here, "%<typeof%> applied to a bit-field");
3069 mark_exp_read (expr.value);
3070 ret.spec = TREE_TYPE (expr.value);
3071 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3072 /* This is returned with the type so that when the type is
3073 evaluated, this can be evaluated. */
3075 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3076 pop_maybe_used (was_vm);
3077 /* For use in macros such as those in <stdatomic.h>, remove all
3078 qualifiers from atomic types. (const can be an issue for more macros
3079 using typeof than just the <stdatomic.h> ones.) */
3080 if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3081 ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3083 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3087 /* Parse an alignment-specifier.
3091 alignment-specifier:
3092 _Alignas ( type-name )
3093 _Alignas ( constant-expression )
3097 c_parser_alignas_specifier (c_parser * parser)
3099 tree ret = error_mark_node;
3100 location_t loc = c_parser_peek_token (parser)->location;
3101 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3102 c_parser_consume_token (parser);
3104 pedwarn_c99 (loc, OPT_Wpedantic,
3105 "ISO C99 does not support %<_Alignas%>");
3107 pedwarn_c99 (loc, OPT_Wpedantic,
3108 "ISO C90 does not support %<_Alignas%>");
3109 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3111 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3113 struct c_type_name *type = c_parser_type_name (parser);
3115 ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3119 ret = c_parser_expr_no_commas (parser, NULL).value;
3120 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3124 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3125 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3126 be redeclared; otherwise it may not. KIND indicates which kind of
3127 declarator is wanted. Returns a valid declarator except in the
3128 case of a syntax error in which case NULL is returned. *SEEN_ID is
3129 set to true if an identifier being declared is seen; this is used
3130 to diagnose bad forms of abstract array declarators and to
3131 determine whether an identifier list is syntactically permitted.
3134 pointer[opt] direct-declarator
3138 ( attributes[opt] declarator )
3139 direct-declarator array-declarator
3140 direct-declarator ( parameter-type-list )
3141 direct-declarator ( identifier-list[opt] )
3144 * type-qualifier-list[opt]
3145 * type-qualifier-list[opt] pointer
3147 type-qualifier-list:
3150 type-qualifier-list type-qualifier
3151 type-qualifier-list attributes
3154 [ type-qualifier-list[opt] assignment-expression[opt] ]
3155 [ static type-qualifier-list[opt] assignment-expression ]
3156 [ type-qualifier-list static assignment-expression ]
3157 [ type-qualifier-list[opt] * ]
3159 parameter-type-list:
3161 parameter-list , ...
3164 parameter-declaration
3165 parameter-list , parameter-declaration
3167 parameter-declaration:
3168 declaration-specifiers declarator attributes[opt]
3169 declaration-specifiers abstract-declarator[opt] attributes[opt]
3173 identifier-list , identifier
3175 abstract-declarator:
3177 pointer[opt] direct-abstract-declarator
3179 direct-abstract-declarator:
3180 ( attributes[opt] abstract-declarator )
3181 direct-abstract-declarator[opt] array-declarator
3182 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3187 direct-declarator ( parameter-forward-declarations
3188 parameter-type-list[opt] )
3190 direct-abstract-declarator:
3191 direct-abstract-declarator[opt] ( parameter-forward-declarations
3192 parameter-type-list[opt] )
3194 parameter-forward-declarations:
3196 parameter-forward-declarations parameter-list ;
3198 The uses of attributes shown above are GNU extensions.
3200 Some forms of array declarator are not included in C99 in the
3201 syntax for abstract declarators; these are disallowed elsewhere.
3202 This may be a defect (DR#289).
3204 This function also accepts an omitted abstract declarator as being
3205 an abstract declarator, although not part of the formal syntax. */
3207 static struct c_declarator *
3208 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3211 /* Parse any initial pointer part. */
3212 if (c_parser_next_token_is (parser, CPP_MULT))
3214 struct c_declspecs *quals_attrs = build_null_declspecs ();
3215 struct c_declarator *inner;
3216 c_parser_consume_token (parser);
3217 c_parser_declspecs (parser, quals_attrs, false, false, true,
3218 false, false, cla_prefer_id);
3219 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3223 return make_pointer_declarator (quals_attrs, inner);
3225 /* Now we have a direct declarator, direct abstract declarator or
3226 nothing (which counts as a direct abstract declarator here). */
3227 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3230 /* Parse a direct declarator or direct abstract declarator; arguments
3231 as c_parser_declarator. */
3233 static struct c_declarator *
3234 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3237 /* The direct declarator must start with an identifier (possibly
3238 omitted) or a parenthesized declarator (possibly abstract). In
3239 an ordinary declarator, initial parentheses must start a
3240 parenthesized declarator. In an abstract declarator or parameter
3241 declarator, they could start a parenthesized declarator or a
3242 parameter list. To tell which, the open parenthesis and any
3243 following attributes must be read. If a declaration specifier
3244 follows, then it is a parameter list; if the specifier is a
3245 typedef name, there might be an ambiguity about redeclaring it,
3246 which is resolved in the direction of treating it as a typedef
3247 name. If a close parenthesis follows, it is also an empty
3248 parameter list, as the syntax does not permit empty abstract
3249 declarators. Otherwise, it is a parenthesized declarator (in
3250 which case the analysis may be repeated inside it, recursively).
3252 ??? There is an ambiguity in a parameter declaration "int
3253 (__attribute__((foo)) x)", where x is not a typedef name: it
3254 could be an abstract declarator for a function, or declare x with
3255 parentheses. The proper resolution of this ambiguity needs
3256 documenting. At present we follow an accident of the old
3257 parser's implementation, whereby the first parameter must have
3258 some declaration specifiers other than just attributes. Thus as
3259 a parameter declaration it is treated as a parenthesized
3260 parameter named x, and as an abstract declarator it is
3263 ??? Also following the old parser, attributes inside an empty
3264 parameter list are ignored, making it a list not yielding a
3265 prototype, rather than giving an error or making it have one
3266 parameter with implicit type int.
3268 ??? Also following the old parser, typedef names may be
3269 redeclared in declarators, but not Objective-C class names. */
3271 if (kind != C_DTR_ABSTRACT
3272 && c_parser_next_token_is (parser, CPP_NAME)
3274 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3275 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3276 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3278 struct c_declarator *inner
3279 = build_id_declarator (c_parser_peek_token (parser)->value);
3281 inner->id_loc = c_parser_peek_token (parser)->location;
3282 c_parser_consume_token (parser);
3283 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3286 if (kind != C_DTR_NORMAL
3287 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3289 struct c_declarator *inner = build_id_declarator (NULL_TREE);
3290 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3293 /* Either we are at the end of an abstract declarator, or we have
3296 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3299 struct c_declarator *inner;
3300 c_parser_consume_token (parser);
3301 attrs = c_parser_attributes (parser);
3302 if (kind != C_DTR_NORMAL
3303 && (c_parser_next_token_starts_declspecs (parser)
3304 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3306 struct c_arg_info *args
3307 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3314 = build_function_declarator (args,
3315 build_id_declarator (NULL_TREE));
3316 return c_parser_direct_declarator_inner (parser, *seen_id,
3320 /* A parenthesized declarator. */
3321 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3322 if (inner != NULL && attrs != NULL)
3323 inner = build_attrs_declarator (attrs, inner);
3324 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3326 c_parser_consume_token (parser);
3330 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3334 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3341 if (kind == C_DTR_NORMAL)
3343 c_parser_error (parser, "expected identifier or %<(%>");
3347 return build_id_declarator (NULL_TREE);
3351 /* Parse part of a direct declarator or direct abstract declarator,
3352 given that some (in INNER) has already been parsed; ID_PRESENT is
3353 true if an identifier is present, false for an abstract
3356 static struct c_declarator *
3357 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3358 struct c_declarator *inner)
3360 /* Parse a sequence of array declarators and parameter lists. */
3361 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3363 location_t brace_loc = c_parser_peek_token (parser)->location;
3364 struct c_declarator *declarator;
3365 struct c_declspecs *quals_attrs = build_null_declspecs ();
3368 struct c_expr dimen;
3369 dimen.value = NULL_TREE;
3370 dimen.original_code = ERROR_MARK;
3371 dimen.original_type = NULL_TREE;
3372 c_parser_consume_token (parser);
3373 c_parser_declspecs (parser, quals_attrs, false, false, true,
3374 false, false, cla_prefer_id);
3375 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3377 c_parser_consume_token (parser);
3378 if (static_seen && !quals_attrs->declspecs_seen_p)
3379 c_parser_declspecs (parser, quals_attrs, false, false, true,
3380 false, false, cla_prefer_id);
3381 if (!quals_attrs->declspecs_seen_p)
3383 /* If "static" is present, there must be an array dimension.
3384 Otherwise, there may be a dimension, "*", or no
3389 dimen = c_parser_expr_no_commas (parser, NULL);
3393 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3395 dimen.value = NULL_TREE;
3398 else if (flag_cilkplus
3399 && c_parser_next_token_is (parser, CPP_COLON))
3401 dimen.value = error_mark_node;
3403 error_at (c_parser_peek_token (parser)->location,
3404 "array notations cannot be used in declaration");
3405 c_parser_consume_token (parser);
3407 else if (c_parser_next_token_is (parser, CPP_MULT))
3409 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3411 dimen.value = NULL_TREE;
3413 c_parser_consume_token (parser);
3418 dimen = c_parser_expr_no_commas (parser, NULL);
3424 dimen = c_parser_expr_no_commas (parser, NULL);
3427 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3428 c_parser_consume_token (parser);
3429 else if (flag_cilkplus
3430 && c_parser_next_token_is (parser, CPP_COLON))
3432 error_at (c_parser_peek_token (parser)->location,
3433 "array notations cannot be used in declaration");
3434 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
3439 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3444 dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3445 declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3446 static_seen, star_seen);
3447 if (declarator == NULL)
3449 inner = set_array_declarator_inner (declarator, inner);
3450 return c_parser_direct_declarator_inner (parser, id_present, inner);
3452 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3455 struct c_arg_info *args;
3456 c_parser_consume_token (parser);
3457 attrs = c_parser_attributes (parser);
3458 args = c_parser_parms_declarator (parser, id_present, attrs);
3463 inner = build_function_declarator (args, inner);
3464 return c_parser_direct_declarator_inner (parser, id_present, inner);
3470 /* Parse a parameter list or identifier list, including the closing
3471 parenthesis but not the opening one. ATTRS are the attributes at
3472 the start of the list. ID_LIST_OK is true if an identifier list is
3473 acceptable; such a list must not have attributes at the start. */
3475 static struct c_arg_info *
3476 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3479 declare_parm_level ();
3480 /* If the list starts with an identifier, it is an identifier list.
3481 Otherwise, it is either a prototype list or an empty list. */
3484 && c_parser_next_token_is (parser, CPP_NAME)
3485 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3487 /* Look ahead to detect typos in type names. */
3488 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3489 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3490 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3491 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3493 tree list = NULL_TREE, *nextp = &list;
3494 while (c_parser_next_token_is (parser, CPP_NAME)
3495 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3497 *nextp = build_tree_list (NULL_TREE,
3498 c_parser_peek_token (parser)->value);
3499 nextp = & TREE_CHAIN (*nextp);
3500 c_parser_consume_token (parser);
3501 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3503 c_parser_consume_token (parser);
3504 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3506 c_parser_error (parser, "expected identifier");
3510 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3512 struct c_arg_info *ret = build_arg_info ();
3514 c_parser_consume_token (parser);
3520 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3528 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3535 /* Parse a parameter list (possibly empty), including the closing
3536 parenthesis but not the opening one. ATTRS are the attributes at
3537 the start of the list. EXPR is NULL or an expression that needs to
3538 be evaluated for the side effects of array size expressions in the
3541 static struct c_arg_info *
3542 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3544 bool bad_parm = false;
3546 /* ??? Following the old parser, forward parameter declarations may
3547 use abstract declarators, and if no real parameter declarations
3548 follow the forward declarations then this is not diagnosed. Also
3549 note as above that attributes are ignored as the only contents of
3550 the parentheses, or as the only contents after forward
3552 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3554 struct c_arg_info *ret = build_arg_info ();
3555 c_parser_consume_token (parser);
3558 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3560 struct c_arg_info *ret = build_arg_info ();
3562 if (flag_allow_parameterless_variadic_functions)
3564 /* F (...) is allowed. */
3565 ret->types = NULL_TREE;
3569 /* Suppress -Wold-style-definition for this case. */
3570 ret->types = error_mark_node;
3571 error_at (c_parser_peek_token (parser)->location,
3572 "ISO C requires a named argument before %<...%>");
3574 c_parser_consume_token (parser);
3575 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3577 c_parser_consume_token (parser);
3582 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3587 /* Nonempty list of parameters, either terminated with semicolon
3588 (forward declarations; recurse) or with close parenthesis (normal
3589 function) or with ", ... )" (variadic function). */
3592 /* Parse a parameter. */
3593 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3598 push_parm_decl (parm, &expr);
3599 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3602 c_parser_consume_token (parser);
3603 mark_forward_parm_decls ();
3604 new_attrs = c_parser_attributes (parser);
3605 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3607 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3609 c_parser_consume_token (parser);
3613 return get_parm_info (false, expr);
3615 if (!c_parser_require (parser, CPP_COMMA,
3616 "expected %<;%>, %<,%> or %<)%>"))
3618 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3621 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3623 c_parser_consume_token (parser);
3624 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3626 c_parser_consume_token (parser);
3630 return get_parm_info (true, expr);
3634 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3642 /* Parse a parameter declaration. ATTRS are the attributes at the
3643 start of the declaration if it is the first parameter. */
3645 static struct c_parm *
3646 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3648 struct c_declspecs *specs;
3649 struct c_declarator *declarator;
3651 tree postfix_attrs = NULL_TREE;
3654 /* Accept #pragmas between parameter declarations. */
3655 while (c_parser_next_token_is (parser, CPP_PRAGMA))
3656 c_parser_pragma (parser, pragma_param);
3658 if (!c_parser_next_token_starts_declspecs (parser))
3660 c_token *token = c_parser_peek_token (parser);
3663 c_parser_set_source_position_from_token (token);
3664 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3666 error_at (token->location, "unknown type name %qE", token->value);
3667 parser->error = true;
3669 /* ??? In some Objective-C cases '...' isn't applicable so there
3670 should be a different message. */
3672 c_parser_error (parser,
3673 "expected declaration specifiers or %<...%>");
3674 c_parser_skip_to_end_of_parameter (parser);
3677 specs = build_null_declspecs ();
3680 declspecs_add_attrs (input_location, specs, attrs);
3683 c_parser_declspecs (parser, specs, true, true, true, true, false,
3684 cla_nonabstract_decl);
3685 finish_declspecs (specs);
3686 pending_xref_error ();
3687 prefix_attrs = specs->attrs;
3688 specs->attrs = NULL_TREE;
3689 declarator = c_parser_declarator (parser,
3690 specs->typespec_kind != ctsk_none,
3691 C_DTR_PARM, &dummy);
3692 if (declarator == NULL)
3694 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3697 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3698 postfix_attrs = c_parser_attributes (parser);
3699 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3703 /* Parse a string literal in an asm expression. It should not be
3704 translated, and wide string literals are an error although
3705 permitted by the syntax. This is a GNU extension.
3710 ??? At present, following the old parser, the caller needs to have
3711 set lex_untranslated_string to 1. It would be better to follow the
3712 C++ parser rather than using this kludge. */
3715 c_parser_asm_string_literal (c_parser *parser)
3718 int save_flag = warn_overlength_strings;
3719 warn_overlength_strings = 0;
3720 if (c_parser_next_token_is (parser, CPP_STRING))
3722 str = c_parser_peek_token (parser)->value;
3723 c_parser_consume_token (parser);
3725 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3727 error_at (c_parser_peek_token (parser)->location,
3728 "wide string literal in %<asm%>");
3729 str = build_string (1, "");
3730 c_parser_consume_token (parser);
3734 c_parser_error (parser, "expected string literal");
3737 warn_overlength_strings = save_flag;
3741 /* Parse a simple asm expression. This is used in restricted
3742 contexts, where a full expression with inputs and outputs does not
3743 make sense. This is a GNU extension.
3746 asm ( asm-string-literal )
3750 c_parser_simple_asm_expr (c_parser *parser)
3753 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3754 /* ??? Follow the C++ parser rather than using the
3755 lex_untranslated_string kludge. */
3756 parser->lex_untranslated_string = true;
3757 c_parser_consume_token (parser);
3758 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3760 parser->lex_untranslated_string = false;
3763 str = c_parser_asm_string_literal (parser);
3764 parser->lex_untranslated_string = false;
3765 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3767 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3774 c_parser_attribute_any_word (c_parser *parser)
3776 tree attr_name = NULL_TREE;
3778 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3780 /* ??? See comment above about what keywords are accepted here. */
3782 switch (c_parser_peek_token (parser)->keyword)
3812 case RID_TRANSACTION_ATOMIC:
3813 case RID_TRANSACTION_CANCEL:
3829 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3830 attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3832 else if (c_parser_next_token_is (parser, CPP_NAME))
3833 attr_name = c_parser_peek_token (parser)->value;
3838 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3839 "__vector" or "__vector__." */
3842 is_cilkplus_vector_p (tree name)
3844 if (flag_cilkplus && is_attribute_p ("vector", name))
3849 #define CILK_SIMD_FN_CLAUSE_MASK \
3850 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3851 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3852 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3853 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3854 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3856 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3857 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3858 pushed into the token list.
3861 vector (<vector attributes>). */
3864 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token)
3866 gcc_assert (is_cilkplus_vector_p (vec_token.value));
3868 int paren_scope = 0;
3869 vec_safe_push (parser->cilk_simd_fn_tokens, vec_token);
3870 /* Consume the "vector" token. */
3871 c_parser_consume_token (parser);
3873 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3875 c_parser_consume_token (parser);
3878 while (paren_scope > 0)
3880 c_token *token = c_parser_peek_token (parser);
3881 if (token->type == CPP_OPEN_PAREN)
3883 else if (token->type == CPP_CLOSE_PAREN)
3885 /* Do not push the last ')' since we are not pushing the '('. */
3886 if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0))
3887 vec_safe_push (parser->cilk_simd_fn_tokens, *token);
3888 c_parser_consume_token (parser);
3891 /* Since we are converting an attribute to a pragma, we need to end the
3892 attribute with PRAGMA_EOL. */
3894 memset (&eol_token, 0, sizeof (eol_token));
3895 eol_token.type = CPP_PRAGMA_EOL;
3896 vec_safe_push (parser->cilk_simd_fn_tokens, eol_token);
3899 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3902 c_finish_cilk_simd_fn_tokens (c_parser *parser)
3904 c_token last_token = parser->cilk_simd_fn_tokens->last ();
3906 /* c_parser_attributes is called in several places, so if these EOF
3907 tokens are already inserted, then don't do them again. */
3908 if (last_token.type == CPP_EOF)
3911 /* Two CPP_EOF token are added as a safety net since the normal C
3912 front-end has two token look-ahead. */
3914 eof_token.type = CPP_EOF;
3915 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3916 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token);
3919 /* Parse (possibly empty) attributes. This is a GNU extension.
3923 attributes attribute
3926 __attribute__ ( ( attribute-list ) )
3930 attribute_list , attrib
3935 any-word ( identifier )
3936 any-word ( identifier , nonempty-expr-list )
3937 any-word ( expr-list )
3939 where the "identifier" must not be declared as a type, and
3940 "any-word" may be any identifier (including one declared as a
3941 type), a reserved word storage class specifier, type specifier or
3942 type qualifier. ??? This still leaves out most reserved keywords
3943 (following the old parser), shouldn't we include them, and why not
3944 allow identifiers declared as types to start the arguments? */
3947 c_parser_attributes (c_parser *parser)
3949 tree attrs = NULL_TREE;
3950 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3952 /* ??? Follow the C++ parser rather than using the
3953 lex_untranslated_string kludge. */
3954 parser->lex_untranslated_string = true;
3955 c_parser_consume_token (parser);
3956 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3958 parser->lex_untranslated_string = false;
3961 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3963 parser->lex_untranslated_string = false;
3964 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3967 /* Parse the attribute list. */
3968 while (c_parser_next_token_is (parser, CPP_COMMA)
3969 || c_parser_next_token_is (parser, CPP_NAME)
3970 || c_parser_next_token_is (parser, CPP_KEYWORD))
3972 tree attr, attr_name, attr_args;
3973 vec<tree, va_gc> *expr_list;
3974 if (c_parser_next_token_is (parser, CPP_COMMA))
3976 c_parser_consume_token (parser);
3980 attr_name = c_parser_attribute_any_word (parser);
3981 if (attr_name == NULL)
3983 if (is_cilkplus_vector_p (attr_name))
3985 c_token *v_token = c_parser_peek_token (parser);
3986 c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
3989 c_parser_consume_token (parser);
3990 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3992 attr = build_tree_list (attr_name, NULL_TREE);
3993 attrs = chainon (attrs, attr);
3996 c_parser_consume_token (parser);
3997 /* Parse the attribute contents. If they start with an
3998 identifier which is followed by a comma or close
3999 parenthesis, then the arguments start with that
4000 identifier; otherwise they are an expression list.
4001 In objective-c the identifier may be a classname. */
4002 if (c_parser_next_token_is (parser, CPP_NAME)
4003 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4004 || (c_dialect_objc ()
4005 && c_parser_peek_token (parser)->id_kind
4007 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4008 || (c_parser_peek_2nd_token (parser)->type
4009 == CPP_CLOSE_PAREN))
4010 && (attribute_takes_identifier_p (attr_name)
4011 || (c_dialect_objc ()
4012 && c_parser_peek_token (parser)->id_kind
4013 == C_ID_CLASSNAME)))
4015 tree arg1 = c_parser_peek_token (parser)->value;
4016 c_parser_consume_token (parser);
4017 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4018 attr_args = build_tree_list (NULL_TREE, arg1);
4022 c_parser_consume_token (parser);
4023 expr_list = c_parser_expr_list (parser, false, true,
4024 NULL, NULL, NULL, NULL);
4025 tree_list = build_tree_list_vec (expr_list);
4026 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4027 release_tree_vector (expr_list);
4032 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4033 attr_args = NULL_TREE;
4036 expr_list = c_parser_expr_list (parser, false, true,
4037 NULL, NULL, NULL, NULL);
4038 attr_args = build_tree_list_vec (expr_list);
4039 release_tree_vector (expr_list);
4042 attr = build_tree_list (attr_name, attr_args);
4043 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4044 c_parser_consume_token (parser);
4047 parser->lex_untranslated_string = false;
4048 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4052 attrs = chainon (attrs, attr);
4054 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4055 c_parser_consume_token (parser);
4058 parser->lex_untranslated_string = false;
4059 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4063 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4064 c_parser_consume_token (parser);
4067 parser->lex_untranslated_string = false;
4068 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4072 parser->lex_untranslated_string = false;
4075 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
4076 c_finish_cilk_simd_fn_tokens (parser);
4080 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4083 specifier-qualifier-list abstract-declarator[opt]
4086 static struct c_type_name *
4087 c_parser_type_name (c_parser *parser)
4089 struct c_declspecs *specs = build_null_declspecs ();
4090 struct c_declarator *declarator;
4091 struct c_type_name *ret;
4093 c_parser_declspecs (parser, specs, false, true, true, false, false,
4095 if (!specs->declspecs_seen_p)
4097 c_parser_error (parser, "expected specifier-qualifier-list");
4100 if (specs->type != error_mark_node)
4102 pending_xref_error ();
4103 finish_declspecs (specs);
4105 declarator = c_parser_declarator (parser,
4106 specs->typespec_kind != ctsk_none,
4107 C_DTR_ABSTRACT, &dummy);
4108 if (declarator == NULL)
4110 ret = XOBNEW (&parser_obstack, struct c_type_name);
4112 ret->declarator = declarator;
4116 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4119 assignment-expression
4120 { initializer-list }
4121 { initializer-list , }
4124 designation[opt] initializer
4125 initializer-list , designation[opt] initializer
4132 designator-list designator
4139 [ constant-expression ]
4151 [ constant-expression ... constant-expression ]
4153 Any expression without commas is accepted in the syntax for the
4154 constant-expressions, with non-constant expressions rejected later.
4156 This function is only used for top-level initializers; for nested
4157 ones, see c_parser_initval. */
4159 static struct c_expr
4160 c_parser_initializer (c_parser *parser)
4162 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4163 return c_parser_braced_init (parser, NULL_TREE, false, NULL);
4167 location_t loc = c_parser_peek_token (parser)->location;
4168 ret = c_parser_expr_no_commas (parser, NULL);
4169 if (TREE_CODE (ret.value) != STRING_CST
4170 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4171 ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4176 /* Parse a braced initializer list. TYPE is the type specified for a
4177 compound literal, and NULL_TREE for other initializers and for
4178 nested braced lists. NESTED_P is true for nested braced lists,
4179 false for the list of a compound literal or the list that is the
4180 top-level initializer in a declaration. */
4182 static struct c_expr
4183 c_parser_braced_init (c_parser *parser, tree type, bool nested_p,
4184 struct obstack *outer_obstack)
4187 struct obstack braced_init_obstack;
4188 location_t brace_loc = c_parser_peek_token (parser)->location;
4189 gcc_obstack_init (&braced_init_obstack);
4190 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4191 c_parser_consume_token (parser);
4194 finish_implicit_inits (brace_loc, outer_obstack);
4195 push_init_level (brace_loc, 0, &braced_init_obstack);
4198 really_start_incremental_init (type);
4199 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4201 pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4205 /* Parse a non-empty initializer list, possibly with a trailing
4209 c_parser_initelt (parser, &braced_init_obstack);
4212 if (c_parser_next_token_is (parser, CPP_COMMA))
4213 c_parser_consume_token (parser);
4216 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4220 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4222 ret.value = error_mark_node;
4223 ret.original_code = ERROR_MARK;
4224 ret.original_type = NULL;
4225 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
4226 pop_init_level (brace_loc, 0, &braced_init_obstack);
4227 obstack_free (&braced_init_obstack, NULL);
4230 c_parser_consume_token (parser);
4231 ret = pop_init_level (brace_loc, 0, &braced_init_obstack);
4232 obstack_free (&braced_init_obstack, NULL);
4236 /* Parse a nested initializer, including designators. */
4239 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4241 /* Parse any designator or designator list. A single array
4242 designator may have the subsequent "=" omitted in GNU C, but a
4243 longer list or a structure member designator may not. */
4244 if (c_parser_next_token_is (parser, CPP_NAME)
4245 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4247 /* Old-style structure member designator. */
4248 set_init_label (c_parser_peek_token (parser)->location,
4249 c_parser_peek_token (parser)->value,
4250 braced_init_obstack);
4251 /* Use the colon as the error location. */
4252 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4253 "obsolete use of designated initializer with %<:%>");
4254 c_parser_consume_token (parser);
4255 c_parser_consume_token (parser);
4259 /* des_seen is 0 if there have been no designators, 1 if there
4260 has been a single array designator and 2 otherwise. */
4262 /* Location of a designator. */
4263 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4264 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4265 || c_parser_next_token_is (parser, CPP_DOT))
4267 int des_prev = des_seen;
4269 des_loc = c_parser_peek_token (parser)->location;
4272 if (c_parser_next_token_is (parser, CPP_DOT))
4275 c_parser_consume_token (parser);
4276 if (c_parser_next_token_is (parser, CPP_NAME))
4278 set_init_label (des_loc, c_parser_peek_token (parser)->value,
4279 braced_init_obstack);
4280 c_parser_consume_token (parser);
4285 init.value = error_mark_node;
4286 init.original_code = ERROR_MARK;
4287 init.original_type = NULL;
4288 c_parser_error (parser, "expected identifier");
4289 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4290 process_init_element (input_location, init, false,
4291 braced_init_obstack);
4298 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4299 location_t array_index_loc = UNKNOWN_LOCATION;
4300 /* ??? Following the old parser, [ objc-receiver
4301 objc-message-args ] is accepted as an initializer,
4302 being distinguished from a designator by what follows
4303 the first assignment expression inside the square
4304 brackets, but after a first array designator a
4305 subsequent square bracket is for Objective-C taken to
4306 start an expression, using the obsolete form of
4307 designated initializer without '=', rather than
4308 possibly being a second level of designation: in LALR
4309 terms, the '[' is shifted rather than reducing
4310 designator to designator-list. */
4311 if (des_prev == 1 && c_dialect_objc ())
4313 des_seen = des_prev;
4316 if (des_prev == 0 && c_dialect_objc ())
4318 /* This might be an array designator or an
4319 Objective-C message expression. If the former,
4320 continue parsing here; if the latter, parse the
4321 remainder of the initializer given the starting
4322 primary-expression. ??? It might make sense to
4323 distinguish when des_prev == 1 as well; see
4324 previous comment. */
4326 struct c_expr mexpr;
4327 c_parser_consume_token (parser);
4328 if (c_parser_peek_token (parser)->type == CPP_NAME
4329 && ((c_parser_peek_token (parser)->id_kind
4331 || (c_parser_peek_token (parser)->id_kind
4332 == C_ID_CLASSNAME)))
4334 /* Type name receiver. */
4335 tree id = c_parser_peek_token (parser)->value;
4336 c_parser_consume_token (parser);
4337 rec = objc_get_class_reference (id);
4338 goto parse_message_args;
4340 first = c_parser_expr_no_commas (parser, NULL).value;
4341 mark_exp_read (first);
4342 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4343 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4344 goto array_desig_after_first;
4345 /* Expression receiver. So far only one part
4346 without commas has been parsed; there might be
4347 more of the expression. */
4349 while (c_parser_next_token_is (parser, CPP_COMMA))
4352 location_t comma_loc, exp_loc;
4353 comma_loc = c_parser_peek_token (parser)->location;
4354 c_parser_consume_token (parser);
4355 exp_loc = c_parser_peek_token (parser)->location;
4356 next = c_parser_expr_no_commas (parser, NULL);
4357 next = convert_lvalue_to_rvalue (exp_loc, next,
4359 rec = build_compound_expr (comma_loc, rec, next.value);
4362 /* Now parse the objc-message-args. */
4363 args = c_parser_objc_message_args (parser);
4364 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4367 = objc_build_message_expr (rec, args);
4368 mexpr.original_code = ERROR_MARK;
4369 mexpr.original_type = NULL;
4370 /* Now parse and process the remainder of the
4371 initializer, starting with this message
4372 expression as a primary-expression. */
4373 c_parser_initval (parser, &mexpr, braced_init_obstack);
4376 c_parser_consume_token (parser);
4377 array_index_loc = c_parser_peek_token (parser)->location;
4378 first = c_parser_expr_no_commas (parser, NULL).value;
4379 mark_exp_read (first);
4380 array_desig_after_first:
4381 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4383 ellipsis_loc = c_parser_peek_token (parser)->location;
4384 c_parser_consume_token (parser);
4385 second = c_parser_expr_no_commas (parser, NULL).value;
4386 mark_exp_read (second);
4390 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4392 c_parser_consume_token (parser);
4393 set_init_index (array_index_loc, first, second,
4394 braced_init_obstack);
4396 pedwarn (ellipsis_loc, OPT_Wpedantic,
4397 "ISO C forbids specifying range of elements to initialize");
4400 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4406 if (c_parser_next_token_is (parser, CPP_EQ))
4408 pedwarn_c90 (des_loc, OPT_Wpedantic,
4409 "ISO C90 forbids specifying subobject "
4411 c_parser_consume_token (parser);
4416 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4417 "obsolete use of designated initializer without %<=%>");
4421 init.value = error_mark_node;
4422 init.original_code = ERROR_MARK;
4423 init.original_type = NULL;
4424 c_parser_error (parser, "expected %<=%>");
4425 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4426 process_init_element (input_location, init, false,
4427 braced_init_obstack);
4433 c_parser_initval (parser, NULL, braced_init_obstack);
4436 /* Parse a nested initializer; as c_parser_initializer but parses
4437 initializers within braced lists, after any designators have been
4438 applied. If AFTER is not NULL then it is an Objective-C message
4439 expression which is the primary-expression starting the
4443 c_parser_initval (c_parser *parser, struct c_expr *after,
4444 struct obstack * braced_init_obstack)
4447 gcc_assert (!after || c_dialect_objc ());
4448 location_t loc = c_parser_peek_token (parser)->location;
4450 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4451 init = c_parser_braced_init (parser, NULL_TREE, true,
4452 braced_init_obstack);
4455 init = c_parser_expr_no_commas (parser, after);
4456 if (init.value != NULL_TREE
4457 && TREE_CODE (init.value) != STRING_CST
4458 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4459 init = convert_lvalue_to_rvalue (loc, init, true, true);
4461 process_init_element (loc, init, false, braced_init_obstack);
4464 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4468 { block-item-list[opt] }
4469 { label-declarations block-item-list }
4473 block-item-list block-item
4485 { label-declarations block-item-list }
4488 __extension__ nested-declaration
4489 nested-function-definition
4493 label-declarations label-declaration
4496 __label__ identifier-list ;
4498 Allowing the mixing of declarations and code is new in C99. The
4499 GNU syntax also permits (not shown above) labels at the end of
4500 compound statements, which yield an error. We don't allow labels
4501 on declarations; this might seem like a natural extension, but
4502 there would be a conflict between attributes on the label and
4503 prefix attributes on the declaration. ??? The syntax follows the
4504 old parser in requiring something after label declarations.
4505 Although they are erroneous if the labels declared aren't defined,
4506 is it useful for the syntax to be this way?
4527 cancellation-point-directive */
4530 c_parser_compound_statement (c_parser *parser)
4533 location_t brace_loc;
4534 brace_loc = c_parser_peek_token (parser)->location;
4535 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4537 /* Ensure a scope is entered and left anyway to avoid confusion
4538 if we have just prepared to enter a function body. */
4539 stmt = c_begin_compound_stmt (true);
4540 c_end_compound_stmt (brace_loc, stmt, true);
4541 return error_mark_node;
4543 stmt = c_begin_compound_stmt (true);
4544 c_parser_compound_statement_nostart (parser);
4546 /* If the compound stmt contains array notations, then we expand them. */
4547 if (flag_cilkplus && contains_array_notation_expr (stmt))
4548 stmt = expand_array_notation_exprs (stmt);
4549 return c_end_compound_stmt (brace_loc, stmt, true);
4552 /* Parse a compound statement except for the opening brace. This is
4553 used for parsing both compound statements and statement expressions
4554 (which follow different paths to handling the opening). */
4557 c_parser_compound_statement_nostart (c_parser *parser)
4559 bool last_stmt = false;
4560 bool last_label = false;
4561 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4562 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4563 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4565 c_parser_consume_token (parser);
4568 mark_valid_location_for_stdc_pragma (true);
4569 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4571 /* Read zero or more forward-declarations for labels that nested
4572 functions can jump to. */
4573 mark_valid_location_for_stdc_pragma (false);
4574 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4576 label_loc = c_parser_peek_token (parser)->location;
4577 c_parser_consume_token (parser);
4578 /* Any identifiers, including those declared as type names,
4583 if (c_parser_next_token_is_not (parser, CPP_NAME))
4585 c_parser_error (parser, "expected identifier");
4589 = declare_label (c_parser_peek_token (parser)->value);
4590 C_DECLARED_LABEL_FLAG (label) = 1;
4591 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4592 c_parser_consume_token (parser);
4593 if (c_parser_next_token_is (parser, CPP_COMMA))
4594 c_parser_consume_token (parser);
4598 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4600 pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4602 /* We must now have at least one statement, label or declaration. */
4603 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4605 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4606 c_parser_error (parser, "expected declaration or statement");
4607 c_parser_consume_token (parser);
4610 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4612 location_t loc = c_parser_peek_token (parser)->location;
4613 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4614 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4615 || (c_parser_next_token_is (parser, CPP_NAME)
4616 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4618 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4619 label_loc = c_parser_peek_2nd_token (parser)->location;
4621 label_loc = c_parser_peek_token (parser)->location;
4624 mark_valid_location_for_stdc_pragma (false);
4625 c_parser_label (parser);
4627 else if (!last_label
4628 && c_parser_next_tokens_start_declaration (parser))
4631 mark_valid_location_for_stdc_pragma (false);
4632 c_parser_declaration_or_fndef (parser, true, true, true, true,
4635 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4636 "ISO C90 forbids mixed declarations and code");
4639 else if (!last_label
4640 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4642 /* __extension__ can start a declaration, but is also an
4643 unary operator that can start an expression. Consume all
4644 but the last of a possible series of __extension__ to
4646 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4647 && (c_parser_peek_2nd_token (parser)->keyword
4649 c_parser_consume_token (parser);
4650 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4653 ext = disable_extension_diagnostics ();
4654 c_parser_consume_token (parser);
4656 mark_valid_location_for_stdc_pragma (false);
4657 c_parser_declaration_or_fndef (parser, true, true, true, true,
4659 /* Following the old parser, __extension__ does not
4660 disable this diagnostic. */
4661 restore_extension_diagnostics (ext);
4663 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
4664 "ISO C90 forbids mixed declarations and code");
4670 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4672 /* External pragmas, and some omp pragmas, are not associated
4673 with regular c code, and so are not to be considered statements
4674 syntactically. This ensures that the user doesn't put them
4675 places that would turn into syntax errors if the directive
4677 if (c_parser_pragma (parser, pragma_compound))
4678 last_label = false, last_stmt = true;
4680 else if (c_parser_next_token_is (parser, CPP_EOF))
4682 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4683 c_parser_error (parser, "expected declaration or statement");
4686 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4688 if (parser->in_if_block)
4690 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4691 error_at (loc, """expected %<}%> before %<else%>");
4696 error_at (loc, "%<else%> without a previous %<if%>");
4697 c_parser_consume_token (parser);
4706 mark_valid_location_for_stdc_pragma (false);
4707 c_parser_statement_after_labels (parser);
4710 parser->error = false;
4713 error_at (label_loc, "label at end of compound statement");
4714 c_parser_consume_token (parser);
4715 /* Restore the value we started with. */
4716 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4719 /* Parse all consecutive labels. */
4722 c_parser_all_labels (c_parser *parser)
4724 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4725 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4726 || (c_parser_next_token_is (parser, CPP_NAME)
4727 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4728 c_parser_label (parser);
4731 /* Parse a label (C90 6.6.1, C99 6.8.1).
4734 identifier : attributes[opt]
4735 case constant-expression :
4741 case constant-expression ... constant-expression :
4743 The use of attributes on labels is a GNU extension. The syntax in
4744 GNU C accepts any expressions without commas, non-constant
4745 expressions being rejected later. */
4748 c_parser_label (c_parser *parser)
4750 location_t loc1 = c_parser_peek_token (parser)->location;
4751 tree label = NULL_TREE;
4752 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4755 c_parser_consume_token (parser);
4756 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4757 if (c_parser_next_token_is (parser, CPP_COLON))
4759 c_parser_consume_token (parser);
4760 label = do_case (loc1, exp1, NULL_TREE);
4762 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4764 c_parser_consume_token (parser);
4765 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4766 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4767 label = do_case (loc1, exp1, exp2);
4770 c_parser_error (parser, "expected %<:%> or %<...%>");
4772 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4774 c_parser_consume_token (parser);
4775 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4776 label = do_case (loc1, NULL_TREE, NULL_TREE);
4780 tree name = c_parser_peek_token (parser)->value;
4783 location_t loc2 = c_parser_peek_token (parser)->location;
4784 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4785 c_parser_consume_token (parser);
4786 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4787 c_parser_consume_token (parser);
4788 attrs = c_parser_attributes (parser);
4789 tlab = define_label (loc2, name);
4792 decl_attributes (&tlab, attrs, 0);
4793 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4798 if (c_parser_next_tokens_start_declaration (parser))
4800 error_at (c_parser_peek_token (parser)->location,
4801 "a label can only be part of a statement and "
4802 "a declaration is not a statement");
4803 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4804 /*static_assert_ok*/ true,
4805 /*empty_ok*/ true, /*nested*/ true,
4806 /*start_attr_ok*/ true, NULL,
4812 /* Parse a statement (C90 6.6, C99 6.8).
4817 expression-statement
4825 expression-statement:
4828 selection-statement:
4832 iteration-statement:
4841 return expression[opt] ;
4854 objc-throw-statement
4855 objc-try-catch-statement
4856 objc-synchronized-statement
4858 objc-throw-statement:
4874 parallel-directive structured-block
4877 kernels-directive structured-block
4880 data-directive structured-block
4883 loop-directive structured-block
4897 parallel-for-construct
4898 parallel-for-simd-construct
4899 parallel-sections-construct
4906 parallel-directive structured-block
4909 for-directive iteration-statement
4912 simd-directive iteration-statements
4915 for-simd-directive iteration-statements
4918 sections-directive section-scope
4921 single-directive structured-block
4923 parallel-for-construct:
4924 parallel-for-directive iteration-statement
4926 parallel-for-simd-construct:
4927 parallel-for-simd-directive iteration-statement
4929 parallel-sections-construct:
4930 parallel-sections-directive section-scope
4933 master-directive structured-block
4936 critical-directive structured-block
4939 atomic-directive expression-statement
4942 ordered-directive structured-block
4944 Transactional Memory:
4947 transaction-statement
4948 transaction-cancel-statement
4952 c_parser_statement (c_parser *parser)
4954 c_parser_all_labels (parser);
4955 c_parser_statement_after_labels (parser);
4958 /* Parse a statement, other than a labeled statement. */
4961 c_parser_statement_after_labels (c_parser *parser)
4963 location_t loc = c_parser_peek_token (parser)->location;
4964 tree stmt = NULL_TREE;
4965 bool in_if_block = parser->in_if_block;
4966 parser->in_if_block = false;
4967 switch (c_parser_peek_token (parser)->type)
4969 case CPP_OPEN_BRACE:
4970 add_stmt (c_parser_compound_statement (parser));
4973 switch (c_parser_peek_token (parser)->keyword)
4976 c_parser_if_statement (parser);
4979 c_parser_switch_statement (parser);
4982 c_parser_while_statement (parser, false);
4985 c_parser_do_statement (parser, false);
4988 c_parser_for_statement (parser, false);
4993 error_at (c_parser_peek_token (parser)->location,
4994 "-fcilkplus must be enabled to use %<_Cilk_for%>");
4995 c_parser_skip_to_end_of_block_or_statement (parser);
4998 c_parser_cilk_for (parser, integer_zero_node);
5001 c_parser_consume_token (parser);
5002 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5004 error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5006 add_stmt (build_cilk_sync ());
5009 c_parser_consume_token (parser);
5010 if (c_parser_next_token_is (parser, CPP_NAME))
5012 stmt = c_finish_goto_label (loc,
5013 c_parser_peek_token (parser)->value);
5014 c_parser_consume_token (parser);
5016 else if (c_parser_next_token_is (parser, CPP_MULT))
5020 c_parser_consume_token (parser);
5021 val = c_parser_expression (parser);
5022 if (check_no_cilk (val.value,
5023 "Cilk array notation cannot be used as a computed goto expression",
5024 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5026 val.value = error_mark_node;
5027 val = convert_lvalue_to_rvalue (loc, val, false, true);
5028 stmt = c_finish_goto_ptr (loc, val.value);
5031 c_parser_error (parser, "expected identifier or %<*%>");
5032 goto expect_semicolon;
5034 c_parser_consume_token (parser);
5035 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5036 goto expect_semicolon;
5038 c_parser_consume_token (parser);
5039 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5040 goto expect_semicolon;
5042 c_parser_consume_token (parser);
5043 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5045 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5046 c_parser_consume_token (parser);
5050 location_t xloc = c_parser_peek_token (parser)->location;
5051 struct c_expr expr = c_parser_expression_conv (parser);
5052 mark_exp_read (expr.value);
5053 stmt = c_finish_return (xloc, expr.value, expr.original_type);
5054 goto expect_semicolon;
5058 stmt = c_parser_asm_statement (parser);
5060 case RID_TRANSACTION_ATOMIC:
5061 case RID_TRANSACTION_RELAXED:
5062 stmt = c_parser_transaction (parser,
5063 c_parser_peek_token (parser)->keyword);
5065 case RID_TRANSACTION_CANCEL:
5066 stmt = c_parser_transaction_cancel (parser);
5067 goto expect_semicolon;
5069 gcc_assert (c_dialect_objc ());
5070 c_parser_consume_token (parser);
5071 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5073 stmt = objc_build_throw_stmt (loc, NULL_TREE);
5074 c_parser_consume_token (parser);
5078 struct c_expr expr = c_parser_expression (parser);
5079 expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5080 if (check_no_cilk (expr.value,
5081 "Cilk array notation cannot be used for a throw expression",
5082 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5083 expr.value = error_mark_node;
5086 expr.value = c_fully_fold (expr.value, false, NULL);
5087 stmt = objc_build_throw_stmt (loc, expr.value);
5089 goto expect_semicolon;
5093 gcc_assert (c_dialect_objc ());
5094 c_parser_objc_try_catch_finally_statement (parser);
5096 case RID_AT_SYNCHRONIZED:
5097 gcc_assert (c_dialect_objc ());
5098 c_parser_objc_synchronized_statement (parser);
5105 c_parser_consume_token (parser);
5107 case CPP_CLOSE_PAREN:
5108 case CPP_CLOSE_SQUARE:
5109 /* Avoid infinite loop in error recovery:
5110 c_parser_skip_until_found stops at a closing nesting
5111 delimiter without consuming it, but here we need to consume
5112 it to proceed further. */
5113 c_parser_error (parser, "expected statement");
5114 c_parser_consume_token (parser);
5117 c_parser_pragma (parser, pragma_stmt);
5121 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5123 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5126 /* Two cases cannot and do not have line numbers associated: If stmt
5127 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5128 cannot hold line numbers. But that's OK because the statement
5129 will either be changed to a MODIFY_EXPR during gimplification of
5130 the statement expr, or discarded. If stmt was compound, but
5131 without new variables, we will have skipped the creation of a
5132 BIND and will have a bare STATEMENT_LIST. But that's OK because
5133 (recursively) all of the component statements should already have
5134 line numbers assigned. ??? Can we discard no-op statements
5136 if (CAN_HAVE_LOCATION_P (stmt)
5137 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5138 SET_EXPR_LOCATION (stmt, loc);
5140 parser->in_if_block = in_if_block;
5143 /* Parse the condition from an if, do, while or for statements. */
5146 c_parser_condition (c_parser *parser)
5148 location_t loc = c_parser_peek_token (parser)->location;
5150 cond = c_parser_expression_conv (parser).value;
5151 cond = c_objc_common_truthvalue_conversion (loc, cond);
5152 cond = c_fully_fold (cond, false, NULL);
5153 if (warn_sequence_point)
5154 verify_sequence_points (cond);
5158 /* Parse a parenthesized condition from an if, do or while statement.
5164 c_parser_paren_condition (c_parser *parser)
5167 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5168 return error_mark_node;
5169 cond = c_parser_condition (parser);
5170 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5174 /* Parse a statement which is a block in C99. */
5177 c_parser_c99_block_statement (c_parser *parser)
5179 tree block = c_begin_compound_stmt (flag_isoc99);
5180 location_t loc = c_parser_peek_token (parser)->location;
5181 c_parser_statement (parser);
5182 return c_end_compound_stmt (loc, block, flag_isoc99);
5185 /* Parse the body of an if statement. This is just parsing a
5186 statement but (a) it is a block in C99, (b) we track whether the
5187 body is an if statement for the sake of -Wparentheses warnings, (c)
5188 we handle an empty body specially for the sake of -Wempty-body
5189 warnings, and (d) we call parser_compound_statement directly
5190 because c_parser_statement_after_labels resets
5191 parser->in_if_block. */
5194 c_parser_if_body (c_parser *parser, bool *if_p)
5196 tree block = c_begin_compound_stmt (flag_isoc99);
5197 location_t body_loc = c_parser_peek_token (parser)->location;
5198 c_parser_all_labels (parser);
5199 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
5200 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5202 location_t loc = c_parser_peek_token (parser)->location;
5203 add_stmt (build_empty_stmt (loc));
5204 c_parser_consume_token (parser);
5205 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5206 warning_at (loc, OPT_Wempty_body,
5207 "suggest braces around empty body in an %<if%> statement");
5209 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5210 add_stmt (c_parser_compound_statement (parser));
5212 c_parser_statement_after_labels (parser);
5213 return c_end_compound_stmt (body_loc, block, flag_isoc99);
5216 /* Parse the else body of an if statement. This is just parsing a
5217 statement but (a) it is a block in C99, (b) we handle an empty body
5218 specially for the sake of -Wempty-body warnings. */
5221 c_parser_else_body (c_parser *parser)
5223 location_t else_loc = c_parser_peek_token (parser)->location;
5224 tree block = c_begin_compound_stmt (flag_isoc99);
5225 c_parser_all_labels (parser);
5226 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5228 location_t loc = c_parser_peek_token (parser)->location;
5231 "suggest braces around empty body in an %<else%> statement");
5232 add_stmt (build_empty_stmt (loc));
5233 c_parser_consume_token (parser);
5236 c_parser_statement_after_labels (parser);
5237 return c_end_compound_stmt (else_loc, block, flag_isoc99);
5240 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5243 if ( expression ) statement
5244 if ( expression ) statement else statement
5248 c_parser_if_statement (c_parser *parser)
5253 bool first_if = false;
5254 tree first_body, second_body;
5258 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5259 c_parser_consume_token (parser);
5260 block = c_begin_compound_stmt (flag_isoc99);
5261 loc = c_parser_peek_token (parser)->location;
5262 cond = c_parser_paren_condition (parser);
5263 if (flag_cilkplus && contains_cilk_spawn_stmt (cond))
5265 error_at (loc, "if statement cannot contain %<Cilk_spawn%>");
5266 cond = error_mark_node;
5268 in_if_block = parser->in_if_block;
5269 parser->in_if_block = true;
5270 first_body = c_parser_if_body (parser, &first_if);
5271 parser->in_if_block = in_if_block;
5272 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5274 c_parser_consume_token (parser);
5275 second_body = c_parser_else_body (parser);
5278 second_body = NULL_TREE;
5279 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
5280 if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
5282 /* If the if statement contains array notations, then we expand them. */
5283 if (flag_cilkplus && contains_array_notation_expr (if_stmt))
5284 if_stmt = fix_conditional_array_notations (if_stmt);
5288 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5291 switch (expression) statement
5295 c_parser_switch_statement (c_parser *parser)
5298 tree block, expr, body, save_break;
5299 location_t switch_loc = c_parser_peek_token (parser)->location;
5300 location_t switch_cond_loc;
5301 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5302 c_parser_consume_token (parser);
5303 block = c_begin_compound_stmt (flag_isoc99);
5304 bool explicit_cast_p = false;
5305 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5307 switch_cond_loc = c_parser_peek_token (parser)->location;
5308 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5309 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5310 explicit_cast_p = true;
5311 ce = c_parser_expression (parser);
5312 ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5314 /* ??? expr has no valid location? */
5315 if (check_no_cilk (expr,
5316 "Cilk array notation cannot be used as a condition for switch statement",
5317 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5319 expr = error_mark_node;
5320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5324 switch_cond_loc = UNKNOWN_LOCATION;
5325 expr = error_mark_node;
5327 c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5328 save_break = c_break_label;
5329 c_break_label = NULL_TREE;
5330 body = c_parser_c99_block_statement (parser);
5331 c_finish_case (body, ce.original_type);
5334 location_t here = c_parser_peek_token (parser)->location;
5335 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5336 SET_EXPR_LOCATION (t, here);
5339 c_break_label = save_break;
5340 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5343 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5346 while (expression) statement
5350 c_parser_while_statement (c_parser *parser, bool ivdep)
5352 tree block, cond, body, save_break, save_cont;
5354 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5355 c_parser_consume_token (parser);
5356 block = c_begin_compound_stmt (flag_isoc99);
5357 loc = c_parser_peek_token (parser)->location;
5358 cond = c_parser_paren_condition (parser);
5359 if (check_no_cilk (cond,
5360 "Cilk array notation cannot be used as a condition for while statement",
5361 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5362 cond = error_mark_node;
5363 if (ivdep && cond != error_mark_node)
5364 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5365 build_int_cst (integer_type_node,
5366 annot_expr_ivdep_kind));
5367 save_break = c_break_label;
5368 c_break_label = NULL_TREE;
5369 save_cont = c_cont_label;
5370 c_cont_label = NULL_TREE;
5371 body = c_parser_c99_block_statement (parser);
5372 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5373 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5374 c_break_label = save_break;
5375 c_cont_label = save_cont;
5378 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5381 do statement while ( expression ) ;
5385 c_parser_do_statement (c_parser *parser, bool ivdep)
5387 tree block, cond, body, save_break, save_cont, new_break, new_cont;
5389 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5390 c_parser_consume_token (parser);
5391 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5392 warning_at (c_parser_peek_token (parser)->location,
5394 "suggest braces around empty body in %<do%> statement");
5395 block = c_begin_compound_stmt (flag_isoc99);
5396 loc = c_parser_peek_token (parser)->location;
5397 save_break = c_break_label;
5398 c_break_label = NULL_TREE;
5399 save_cont = c_cont_label;
5400 c_cont_label = NULL_TREE;
5401 body = c_parser_c99_block_statement (parser);
5402 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5403 new_break = c_break_label;
5404 c_break_label = save_break;
5405 new_cont = c_cont_label;
5406 c_cont_label = save_cont;
5407 cond = c_parser_paren_condition (parser);
5408 if (check_no_cilk (cond,
5409 "Cilk array notation cannot be used as a condition for a do-while statement",
5410 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5411 cond = error_mark_node;
5412 if (ivdep && cond != error_mark_node)
5413 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5414 build_int_cst (integer_type_node,
5415 annot_expr_ivdep_kind));
5416 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5417 c_parser_skip_to_end_of_block_or_statement (parser);
5418 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5419 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5422 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5425 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5426 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5428 The form with a declaration is new in C99.
5430 ??? In accordance with the old parser, the declaration may be a
5431 nested function, which is then rejected in check_for_loop_decls,
5432 but does it make any sense for this to be included in the grammar?
5433 Note in particular that the nested function does not include a
5434 trailing ';', whereas the "declaration" production includes one.
5435 Also, can we reject bad declarations earlier and cheaper than
5436 check_for_loop_decls?
5438 In Objective-C, there are two additional variants:
5441 for ( expression in expresssion ) statement
5442 for ( declaration in expression ) statement
5444 This is inconsistent with C, because the second variant is allowed
5445 even if c99 is not enabled.
5447 The rest of the comment documents these Objective-C foreach-statement.
5449 Here is the canonical example of the first variant:
5450 for (object in array) { do something with object }
5451 we call the first expression ("object") the "object_expression" and
5452 the second expression ("array") the "collection_expression".
5453 object_expression must be an lvalue of type "id" (a generic Objective-C
5454 object) because the loop works by assigning to object_expression the
5455 various objects from the collection_expression. collection_expression
5456 must evaluate to something of type "id" which responds to the method
5457 countByEnumeratingWithState:objects:count:.
5459 The canonical example of the second variant is:
5460 for (id object in array) { do something with object }
5461 which is completely equivalent to
5464 for (object in array) { do something with object }
5466 Note that initizializing 'object' in some way (eg, "for ((object =
5467 xxx) in array) { do something with object }") is possibly
5468 technically valid, but completely pointless as 'object' will be
5469 assigned to something else as soon as the loop starts. We should
5470 most likely reject it (TODO).
5472 The beginning of the Objective-C foreach-statement looks exactly
5473 like the beginning of the for-statement, and we can tell it is a
5474 foreach-statement only because the initial declaration or
5475 expression is terminated by 'in' instead of ';'.
5479 c_parser_for_statement (c_parser *parser, bool ivdep)
5481 tree block, cond, incr, save_break, save_cont, body;
5482 /* The following are only used when parsing an ObjC foreach statement. */
5483 tree object_expression;
5484 /* Silence the bogus uninitialized warning. */
5485 tree collection_expression = NULL;
5486 location_t loc = c_parser_peek_token (parser)->location;
5487 location_t for_loc = c_parser_peek_token (parser)->location;
5488 bool is_foreach_statement = false;
5489 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
5490 c_parser_consume_token (parser);
5491 /* Open a compound statement in Objective-C as well, just in case this is
5492 as foreach expression. */
5493 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
5494 cond = error_mark_node;
5495 incr = error_mark_node;
5496 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5498 /* Parse the initialization declaration or expression. */
5499 object_expression = error_mark_node;
5500 parser->objc_could_be_foreach_context = c_dialect_objc ();
5501 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5503 parser->objc_could_be_foreach_context = false;
5504 c_parser_consume_token (parser);
5505 c_finish_expr_stmt (loc, NULL_TREE);
5507 else if (c_parser_next_tokens_start_declaration (parser))
5509 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
5510 &object_expression, vNULL);
5511 parser->objc_could_be_foreach_context = false;
5513 if (c_parser_next_token_is_keyword (parser, RID_IN))
5515 c_parser_consume_token (parser);
5516 is_foreach_statement = true;
5517 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5518 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5521 check_for_loop_decls (for_loc, flag_isoc99);
5523 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5525 /* __extension__ can start a declaration, but is also an
5526 unary operator that can start an expression. Consume all
5527 but the last of a possible series of __extension__ to
5529 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5530 && (c_parser_peek_2nd_token (parser)->keyword
5532 c_parser_consume_token (parser);
5533 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5536 ext = disable_extension_diagnostics ();
5537 c_parser_consume_token (parser);
5538 c_parser_declaration_or_fndef (parser, true, true, true, true,
5539 true, &object_expression, vNULL);
5540 parser->objc_could_be_foreach_context = false;
5542 restore_extension_diagnostics (ext);
5543 if (c_parser_next_token_is_keyword (parser, RID_IN))
5545 c_parser_consume_token (parser);
5546 is_foreach_statement = true;
5547 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
5548 c_parser_error (parser, "multiple iterating variables in fast enumeration");
5551 check_for_loop_decls (for_loc, flag_isoc99);
5561 tree init_expression;
5562 ce = c_parser_expression (parser);
5563 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5564 level statement", but it works just fine, so allow it. */
5565 init_expression = ce.value;
5566 parser->objc_could_be_foreach_context = false;
5567 if (c_parser_next_token_is_keyword (parser, RID_IN))
5569 c_parser_consume_token (parser);
5570 is_foreach_statement = true;
5571 if (! lvalue_p (init_expression))
5572 c_parser_error (parser, "invalid iterating variable in fast enumeration");
5573 object_expression = c_fully_fold (init_expression, false, NULL);
5577 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5578 init_expression = ce.value;
5579 c_finish_expr_stmt (loc, init_expression);
5580 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5584 /* Parse the loop condition. In the case of a foreach
5585 statement, there is no loop condition. */
5586 gcc_assert (!parser->objc_could_be_foreach_context);
5587 if (!is_foreach_statement)
5589 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5593 c_parser_error (parser, "missing loop condition in loop with "
5594 "%<GCC ivdep%> pragma");
5595 cond = error_mark_node;
5599 c_parser_consume_token (parser);
5605 cond = c_parser_condition (parser);
5606 if (check_no_cilk (cond,
5607 "Cilk array notation cannot be used in a condition for a for-loop",
5608 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5609 cond = error_mark_node;
5610 c_parser_skip_until_found (parser, CPP_SEMICOLON,
5613 if (ivdep && cond != error_mark_node)
5614 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5615 build_int_cst (integer_type_node,
5616 annot_expr_ivdep_kind));
5618 /* Parse the increment expression (the third expression in a
5619 for-statement). In the case of a foreach-statement, this is
5620 the expression that follows the 'in'. */
5621 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5623 if (is_foreach_statement)
5625 c_parser_error (parser, "missing collection in fast enumeration");
5626 collection_expression = error_mark_node;
5629 incr = c_process_expr_stmt (loc, NULL_TREE);
5633 if (is_foreach_statement)
5634 collection_expression = c_fully_fold (c_parser_expression (parser).value,
5638 struct c_expr ce = c_parser_expression (parser);
5639 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
5640 incr = c_process_expr_stmt (loc, ce.value);
5643 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5645 save_break = c_break_label;
5646 c_break_label = NULL_TREE;
5647 save_cont = c_cont_label;
5648 c_cont_label = NULL_TREE;
5649 body = c_parser_c99_block_statement (parser);
5650 if (is_foreach_statement)
5651 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5653 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5654 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5655 c_break_label = save_break;
5656 c_cont_label = save_cont;
5659 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5660 statement with inputs, outputs, clobbers, and volatile tag
5664 asm type-qualifier[opt] ( asm-argument ) ;
5665 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5669 asm-string-literal : asm-operands[opt]
5670 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5671 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5674 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5677 Qualifiers other than volatile are accepted in the syntax but
5681 c_parser_asm_statement (c_parser *parser)
5683 tree quals, str, outputs, inputs, clobbers, labels, ret;
5684 bool simple, is_goto;
5685 location_t asm_loc = c_parser_peek_token (parser)->location;
5686 int section, nsections;
5688 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5689 c_parser_consume_token (parser);
5690 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5692 quals = c_parser_peek_token (parser)->value;
5693 c_parser_consume_token (parser);
5695 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5696 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5698 warning_at (c_parser_peek_token (parser)->location,
5700 "%E qualifier ignored on asm",
5701 c_parser_peek_token (parser)->value);
5703 c_parser_consume_token (parser);
5709 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5711 c_parser_consume_token (parser);
5715 /* ??? Follow the C++ parser rather than using the
5716 lex_untranslated_string kludge. */
5717 parser->lex_untranslated_string = true;
5720 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5723 str = c_parser_asm_string_literal (parser);
5724 if (str == NULL_TREE)
5725 goto error_close_paren;
5728 outputs = NULL_TREE;
5730 clobbers = NULL_TREE;
5733 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5736 /* Parse each colon-delimited section of operands. */
5737 nsections = 3 + is_goto;
5738 for (section = 0; section < nsections; ++section)
5740 if (!c_parser_require (parser, CPP_COLON,
5743 : "expected %<:%> or %<)%>"))
5744 goto error_close_paren;
5746 /* Once past any colon, we're no longer a simple asm. */
5749 if ((!c_parser_next_token_is (parser, CPP_COLON)
5750 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5755 /* For asm goto, we don't allow output operands, but reserve
5756 the slot for a future extension that does allow them. */
5758 outputs = c_parser_asm_operands (parser);
5761 inputs = c_parser_asm_operands (parser);
5764 clobbers = c_parser_asm_clobbers (parser);
5767 labels = c_parser_asm_goto_operands (parser);
5773 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5778 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5780 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5784 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5785 c_parser_skip_to_end_of_block_or_statement (parser);
5787 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5788 clobbers, labels, simple));
5791 parser->lex_untranslated_string = false;
5795 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5799 /* Parse asm operands, a GNU extension.
5803 asm-operands , asm-operand
5806 asm-string-literal ( expression )
5807 [ identifier ] asm-string-literal ( expression )
5811 c_parser_asm_operands (c_parser *parser)
5813 tree list = NULL_TREE;
5818 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5820 c_parser_consume_token (parser);
5821 if (c_parser_next_token_is (parser, CPP_NAME))
5823 tree id = c_parser_peek_token (parser)->value;
5824 c_parser_consume_token (parser);
5825 name = build_string (IDENTIFIER_LENGTH (id),
5826 IDENTIFIER_POINTER (id));
5830 c_parser_error (parser, "expected identifier");
5831 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5834 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5839 str = c_parser_asm_string_literal (parser);
5840 if (str == NULL_TREE)
5842 parser->lex_untranslated_string = false;
5843 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5845 parser->lex_untranslated_string = true;
5848 expr = c_parser_expression (parser);
5849 mark_exp_read (expr.value);
5850 parser->lex_untranslated_string = true;
5851 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5853 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5856 list = chainon (list, build_tree_list (build_tree_list (name, str),
5858 if (c_parser_next_token_is (parser, CPP_COMMA))
5859 c_parser_consume_token (parser);
5866 /* Parse asm clobbers, a GNU extension.
5870 asm-clobbers , asm-string-literal
5874 c_parser_asm_clobbers (c_parser *parser)
5876 tree list = NULL_TREE;
5879 tree str = c_parser_asm_string_literal (parser);
5881 list = tree_cons (NULL_TREE, str, list);
5884 if (c_parser_next_token_is (parser, CPP_COMMA))
5885 c_parser_consume_token (parser);
5892 /* Parse asm goto labels, a GNU extension.
5896 asm-goto-operands , identifier
5900 c_parser_asm_goto_operands (c_parser *parser)
5902 tree list = NULL_TREE;
5907 if (c_parser_next_token_is (parser, CPP_NAME))
5909 c_token *tok = c_parser_peek_token (parser);
5911 label = lookup_label_for_goto (tok->location, name);
5912 c_parser_consume_token (parser);
5913 TREE_USED (label) = 1;
5917 c_parser_error (parser, "expected identifier");
5921 name = build_string (IDENTIFIER_LENGTH (name),
5922 IDENTIFIER_POINTER (name));
5923 list = tree_cons (name, label, list);
5924 if (c_parser_next_token_is (parser, CPP_COMMA))
5925 c_parser_consume_token (parser);
5927 return nreverse (list);
5931 /* Parse an expression other than a compound expression; that is, an
5932 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5933 NULL then it is an Objective-C message expression which is the
5934 primary-expression starting the expression as an initializer.
5936 assignment-expression:
5937 conditional-expression
5938 unary-expression assignment-operator assignment-expression
5940 assignment-operator: one of
5941 = *= /= %= += -= <<= >>= &= ^= |=
5943 In GNU C we accept any conditional expression on the LHS and
5944 diagnose the invalid lvalue rather than producing a syntax
5947 static struct c_expr
5948 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
5949 tree omp_atomic_lhs)
5951 struct c_expr lhs, rhs, ret;
5952 enum tree_code code;
5953 location_t op_location, exp_location;
5954 gcc_assert (!after || c_dialect_objc ());
5955 lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
5956 op_location = c_parser_peek_token (parser)->location;
5957 switch (c_parser_peek_token (parser)->type)
5966 code = TRUNC_DIV_EXPR;
5969 code = TRUNC_MOD_EXPR;
5984 code = BIT_AND_EXPR;
5987 code = BIT_XOR_EXPR;
5990 code = BIT_IOR_EXPR;
5995 c_parser_consume_token (parser);
5996 exp_location = c_parser_peek_token (parser)->location;
5997 rhs = c_parser_expr_no_commas (parser, NULL);
5998 rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
6000 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
6001 code, exp_location, rhs.value,
6003 if (code == NOP_EXPR)
6004 ret.original_code = MODIFY_EXPR;
6007 TREE_NO_WARNING (ret.value) = 1;
6008 ret.original_code = ERROR_MARK;
6010 ret.original_type = NULL;
6014 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6015 is not NULL then it is an Objective-C message expression which is
6016 the primary-expression starting the expression as an initializer.
6018 conditional-expression:
6019 logical-OR-expression
6020 logical-OR-expression ? expression : conditional-expression
6024 conditional-expression:
6025 logical-OR-expression ? : conditional-expression
6028 static struct c_expr
6029 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6030 tree omp_atomic_lhs)
6032 struct c_expr cond, exp1, exp2, ret;
6033 location_t cond_loc, colon_loc, middle_loc;
6035 gcc_assert (!after || c_dialect_objc ());
6037 cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6039 if (c_parser_next_token_is_not (parser, CPP_QUERY))
6041 cond_loc = c_parser_peek_token (parser)->location;
6042 cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6043 c_parser_consume_token (parser);
6044 if (c_parser_next_token_is (parser, CPP_COLON))
6046 tree eptype = NULL_TREE;
6048 middle_loc = c_parser_peek_token (parser)->location;
6049 pedwarn (middle_loc, OPT_Wpedantic,
6050 "ISO C forbids omitting the middle term of a ?: expression");
6051 warn_for_omitted_condop (middle_loc, cond.value);
6052 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6054 eptype = TREE_TYPE (cond.value);
6055 cond.value = TREE_OPERAND (cond.value, 0);
6057 /* Make sure first operand is calculated only once. */
6058 exp1.value = c_save_expr (default_conversion (cond.value));
6060 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6061 exp1.original_type = NULL;
6062 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6063 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6068 = c_objc_common_truthvalue_conversion
6069 (cond_loc, default_conversion (cond.value));
6070 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6071 exp1 = c_parser_expression_conv (parser);
6072 mark_exp_read (exp1.value);
6073 c_inhibit_evaluation_warnings +=
6074 ((cond.value == truthvalue_true_node)
6075 - (cond.value == truthvalue_false_node));
6078 colon_loc = c_parser_peek_token (parser)->location;
6079 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6081 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6082 ret.value = error_mark_node;
6083 ret.original_code = ERROR_MARK;
6084 ret.original_type = NULL;
6088 location_t exp2_loc = c_parser_peek_token (parser)->location;
6089 exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6090 exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6092 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6093 ret.value = build_conditional_expr (colon_loc, cond.value,
6094 cond.original_code == C_MAYBE_CONST_EXPR,
6095 exp1.value, exp1.original_type,
6096 exp2.value, exp2.original_type);
6097 ret.original_code = ERROR_MARK;
6098 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6099 ret.original_type = NULL;
6104 /* If both sides are enum type, the default conversion will have
6105 made the type of the result be an integer type. We want to
6106 remember the enum types we started with. */
6107 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6108 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6109 ret.original_type = ((t1 != error_mark_node
6110 && t2 != error_mark_node
6111 && (TYPE_MAIN_VARIANT (t1)
6112 == TYPE_MAIN_VARIANT (t2)))
6119 /* Parse a binary expression; that is, a logical-OR-expression (C90
6120 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6121 an Objective-C message expression which is the primary-expression
6122 starting the expression as an initializer.
6124 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6125 when it should be the unfolded lhs. In a valid OpenMP source,
6126 one of the operands of the toplevel binary expression must be equal
6127 to it. In that case, just return a build2 created binary operation
6128 rather than result of parser_build_binary_op.
6130 multiplicative-expression:
6132 multiplicative-expression * cast-expression
6133 multiplicative-expression / cast-expression
6134 multiplicative-expression % cast-expression
6136 additive-expression:
6137 multiplicative-expression
6138 additive-expression + multiplicative-expression
6139 additive-expression - multiplicative-expression
6143 shift-expression << additive-expression
6144 shift-expression >> additive-expression
6146 relational-expression:
6148 relational-expression < shift-expression
6149 relational-expression > shift-expression
6150 relational-expression <= shift-expression
6151 relational-expression >= shift-expression
6153 equality-expression:
6154 relational-expression
6155 equality-expression == relational-expression
6156 equality-expression != relational-expression
6160 AND-expression & equality-expression
6162 exclusive-OR-expression:
6164 exclusive-OR-expression ^ AND-expression
6166 inclusive-OR-expression:
6167 exclusive-OR-expression
6168 inclusive-OR-expression | exclusive-OR-expression
6170 logical-AND-expression:
6171 inclusive-OR-expression
6172 logical-AND-expression && inclusive-OR-expression
6174 logical-OR-expression:
6175 logical-AND-expression
6176 logical-OR-expression || logical-AND-expression
6179 static struct c_expr
6180 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6181 tree omp_atomic_lhs)
6183 /* A binary expression is parsed using operator-precedence parsing,
6184 with the operands being cast expressions. All the binary
6185 operators are left-associative. Thus a binary expression is of
6188 E0 op1 E1 op2 E2 ...
6190 which we represent on a stack. On the stack, the precedence
6191 levels are strictly increasing. When a new operator is
6192 encountered of higher precedence than that at the top of the
6193 stack, it is pushed; its LHS is the top expression, and its RHS
6194 is everything parsed until it is popped. When a new operator is
6195 encountered with precedence less than or equal to that at the top
6196 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6197 by the result of the operation until the operator at the top of
6198 the stack has lower precedence than the new operator or there is
6199 only one element on the stack; then the top expression is the LHS
6200 of the new operator. In the case of logical AND and OR
6201 expressions, we also need to adjust c_inhibit_evaluation_warnings
6202 as appropriate when the operators are pushed and popped. */
6205 /* The expression at this stack level. */
6207 /* The precedence of the operator on its left, PREC_NONE at the
6208 bottom of the stack. */
6209 enum c_parser_prec prec;
6210 /* The operation on its left. */
6212 /* The source location of this operation. */
6216 /* Location of the binary operator. */
6217 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
6220 switch (stack[sp].op) \
6222 case TRUTH_ANDIF_EXPR: \
6223 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6224 == truthvalue_false_node); \
6226 case TRUTH_ORIF_EXPR: \
6227 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6228 == truthvalue_true_node); \
6233 stack[sp - 1].expr \
6234 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6235 stack[sp - 1].expr, true, true); \
6237 = convert_lvalue_to_rvalue (stack[sp].loc, \
6238 stack[sp].expr, true, true); \
6239 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6240 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6241 && ((1 << stack[sp].prec) \
6242 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6243 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6244 && stack[sp].op != TRUNC_MOD_EXPR \
6245 && stack[0].expr.value != error_mark_node \
6246 && stack[1].expr.value != error_mark_node \
6247 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6248 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6249 stack[0].expr.value \
6250 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6251 stack[0].expr.value, stack[1].expr.value); \
6253 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6255 stack[sp - 1].expr, \
6259 gcc_assert (!after || c_dialect_objc ());
6260 stack[0].loc = c_parser_peek_token (parser)->location;
6261 stack[0].expr = c_parser_cast_expression (parser, after);
6262 stack[0].prec = PREC_NONE;
6266 enum c_parser_prec oprec;
6267 enum tree_code ocode;
6270 switch (c_parser_peek_token (parser)->type)
6278 ocode = TRUNC_DIV_EXPR;
6282 ocode = TRUNC_MOD_EXPR;
6294 ocode = LSHIFT_EXPR;
6298 ocode = RSHIFT_EXPR;
6312 case CPP_GREATER_EQ:
6325 oprec = PREC_BITAND;
6326 ocode = BIT_AND_EXPR;
6329 oprec = PREC_BITXOR;
6330 ocode = BIT_XOR_EXPR;
6334 ocode = BIT_IOR_EXPR;
6337 oprec = PREC_LOGAND;
6338 ocode = TRUTH_ANDIF_EXPR;
6342 ocode = TRUTH_ORIF_EXPR;
6345 /* Not a binary operator, so end of the binary
6349 binary_loc = c_parser_peek_token (parser)->location;
6350 while (oprec <= stack[sp].prec)
6352 c_parser_consume_token (parser);
6355 case TRUTH_ANDIF_EXPR:
6357 = convert_lvalue_to_rvalue (stack[sp].loc,
6358 stack[sp].expr, true, true);
6359 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6360 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6361 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6362 == truthvalue_false_node);
6364 case TRUTH_ORIF_EXPR:
6366 = convert_lvalue_to_rvalue (stack[sp].loc,
6367 stack[sp].expr, true, true);
6368 stack[sp].expr.value = c_objc_common_truthvalue_conversion
6369 (stack[sp].loc, default_conversion (stack[sp].expr.value));
6370 c_inhibit_evaluation_warnings += (stack[sp].expr.value
6371 == truthvalue_true_node);
6377 stack[sp].loc = binary_loc;
6378 stack[sp].expr = c_parser_cast_expression (parser, NULL);
6379 stack[sp].prec = oprec;
6380 stack[sp].op = ocode;
6381 stack[sp].loc = binary_loc;
6386 return stack[0].expr;
6390 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6391 NULL then it is an Objective-C message expression which is the
6392 primary-expression starting the expression as an initializer.
6396 ( type-name ) unary-expression
6399 static struct c_expr
6400 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
6402 location_t cast_loc = c_parser_peek_token (parser)->location;
6403 gcc_assert (!after || c_dialect_objc ());
6405 return c_parser_postfix_expression_after_primary (parser,
6407 /* If the expression begins with a parenthesized type name, it may
6408 be either a cast or a compound literal; we need to see whether
6409 the next character is '{' to tell the difference. If not, it is
6410 an unary expression. Full detection of unknown typenames here
6411 would require a 3-token lookahead. */
6412 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6413 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6415 struct c_type_name *type_name;
6418 c_parser_consume_token (parser);
6419 type_name = c_parser_type_name (parser);
6420 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6421 if (type_name == NULL)
6423 ret.value = error_mark_node;
6424 ret.original_code = ERROR_MARK;
6425 ret.original_type = NULL;
6429 /* Save casted types in the function's used types hash table. */
6430 used_types_insert (type_name->specs->type);
6432 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6433 return c_parser_postfix_expression_after_paren_type (parser, type_name,
6436 location_t expr_loc = c_parser_peek_token (parser)->location;
6437 expr = c_parser_cast_expression (parser, NULL);
6438 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
6440 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
6441 ret.original_code = ERROR_MARK;
6442 ret.original_type = NULL;
6446 return c_parser_unary_expression (parser);
6449 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6455 unary-operator cast-expression
6456 sizeof unary-expression
6457 sizeof ( type-name )
6459 unary-operator: one of
6465 __alignof__ unary-expression
6466 __alignof__ ( type-name )
6469 (C11 permits _Alignof with type names only.)
6471 unary-operator: one of
6472 __extension__ __real__ __imag__
6474 Transactional Memory:
6477 transaction-expression
6479 In addition, the GNU syntax treats ++ and -- as unary operators, so
6480 they may be applied to cast expressions with errors for non-lvalues
6483 static struct c_expr
6484 c_parser_unary_expression (c_parser *parser)
6487 struct c_expr ret, op;
6488 location_t op_loc = c_parser_peek_token (parser)->location;
6490 ret.original_code = ERROR_MARK;
6491 ret.original_type = NULL;
6492 switch (c_parser_peek_token (parser)->type)
6495 c_parser_consume_token (parser);
6496 exp_loc = c_parser_peek_token (parser)->location;
6497 op = c_parser_cast_expression (parser, NULL);
6499 /* If there is array notations in op, we expand them. */
6500 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6501 return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op);
6504 op = default_function_array_read_conversion (exp_loc, op);
6505 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
6507 case CPP_MINUS_MINUS:
6508 c_parser_consume_token (parser);
6509 exp_loc = c_parser_peek_token (parser)->location;
6510 op = c_parser_cast_expression (parser, NULL);
6512 /* If there is array notations in op, we expand them. */
6513 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF)
6514 return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op);
6517 op = default_function_array_read_conversion (exp_loc, op);
6518 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
6521 c_parser_consume_token (parser);
6522 op = c_parser_cast_expression (parser, NULL);
6523 mark_exp_read (op.value);
6524 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
6526 c_parser_consume_token (parser);
6527 exp_loc = c_parser_peek_token (parser)->location;
6528 op = c_parser_cast_expression (parser, NULL);
6529 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6530 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
6533 if (!c_dialect_objc () && !in_system_header_at (input_location))
6536 "traditional C rejects the unary plus operator");
6537 c_parser_consume_token (parser);
6538 exp_loc = c_parser_peek_token (parser)->location;
6539 op = c_parser_cast_expression (parser, NULL);
6540 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6541 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
6543 c_parser_consume_token (parser);
6544 exp_loc = c_parser_peek_token (parser)->location;
6545 op = c_parser_cast_expression (parser, NULL);
6546 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6547 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
6549 c_parser_consume_token (parser);
6550 exp_loc = c_parser_peek_token (parser)->location;
6551 op = c_parser_cast_expression (parser, NULL);
6552 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6553 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
6555 c_parser_consume_token (parser);
6556 exp_loc = c_parser_peek_token (parser)->location;
6557 op = c_parser_cast_expression (parser, NULL);
6558 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
6559 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
6561 /* Refer to the address of a label as a pointer. */
6562 c_parser_consume_token (parser);
6563 if (c_parser_next_token_is (parser, CPP_NAME))
6565 ret.value = finish_label_address_expr
6566 (c_parser_peek_token (parser)->value, op_loc);
6567 c_parser_consume_token (parser);
6571 c_parser_error (parser, "expected identifier");
6572 ret.value = error_mark_node;
6576 switch (c_parser_peek_token (parser)->keyword)
6579 return c_parser_sizeof_expression (parser);
6581 return c_parser_alignof_expression (parser);
6583 c_parser_consume_token (parser);
6584 ext = disable_extension_diagnostics ();
6585 ret = c_parser_cast_expression (parser, NULL);
6586 restore_extension_diagnostics (ext);
6589 c_parser_consume_token (parser);
6590 exp_loc = c_parser_peek_token (parser)->location;
6591 op = c_parser_cast_expression (parser, NULL);
6592 op = default_function_array_conversion (exp_loc, op);
6593 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
6595 c_parser_consume_token (parser);
6596 exp_loc = c_parser_peek_token (parser)->location;
6597 op = c_parser_cast_expression (parser, NULL);
6598 op = default_function_array_conversion (exp_loc, op);
6599 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
6600 case RID_TRANSACTION_ATOMIC:
6601 case RID_TRANSACTION_RELAXED:
6602 return c_parser_transaction_expression (parser,
6603 c_parser_peek_token (parser)->keyword);
6605 return c_parser_postfix_expression (parser);
6608 return c_parser_postfix_expression (parser);
6612 /* Parse a sizeof expression. */
6614 static struct c_expr
6615 c_parser_sizeof_expression (c_parser *parser)
6618 location_t expr_loc;
6619 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
6620 c_parser_consume_token (parser);
6621 c_inhibit_evaluation_warnings++;
6623 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6624 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6626 /* Either sizeof ( type-name ) or sizeof unary-expression
6627 starting with a compound literal. */
6628 struct c_type_name *type_name;
6629 c_parser_consume_token (parser);
6630 expr_loc = c_parser_peek_token (parser)->location;
6631 type_name = c_parser_type_name (parser);
6632 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6633 if (type_name == NULL)
6636 c_inhibit_evaluation_warnings--;
6638 ret.value = error_mark_node;
6639 ret.original_code = ERROR_MARK;
6640 ret.original_type = NULL;
6643 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6645 expr = c_parser_postfix_expression_after_paren_type (parser,
6650 /* sizeof ( type-name ). */
6651 c_inhibit_evaluation_warnings--;
6653 return c_expr_sizeof_type (expr_loc, type_name);
6657 expr_loc = c_parser_peek_token (parser)->location;
6658 expr = c_parser_unary_expression (parser);
6660 c_inhibit_evaluation_warnings--;
6662 mark_exp_read (expr.value);
6663 if (TREE_CODE (expr.value) == COMPONENT_REF
6664 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
6665 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
6666 return c_expr_sizeof_expr (expr_loc, expr);
6670 /* Parse an alignof expression. */
6672 static struct c_expr
6673 c_parser_alignof_expression (c_parser *parser)
6676 location_t loc = c_parser_peek_token (parser)->location;
6677 tree alignof_spelling = c_parser_peek_token (parser)->value;
6678 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
6679 bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
6681 /* A diagnostic is not required for the use of this identifier in
6682 the implementation namespace; only diagnose it for the C11
6683 spelling because of existing code using the other spellings. */
6687 pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
6690 pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
6693 c_parser_consume_token (parser);
6694 c_inhibit_evaluation_warnings++;
6696 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6697 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6699 /* Either __alignof__ ( type-name ) or __alignof__
6700 unary-expression starting with a compound literal. */
6702 struct c_type_name *type_name;
6704 c_parser_consume_token (parser);
6705 loc = c_parser_peek_token (parser)->location;
6706 type_name = c_parser_type_name (parser);
6707 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6708 if (type_name == NULL)
6711 c_inhibit_evaluation_warnings--;
6713 ret.value = error_mark_node;
6714 ret.original_code = ERROR_MARK;
6715 ret.original_type = NULL;
6718 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6720 expr = c_parser_postfix_expression_after_paren_type (parser,
6725 /* alignof ( type-name ). */
6726 c_inhibit_evaluation_warnings--;
6728 ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
6730 false, is_c11_alignof, 1);
6731 ret.original_code = ERROR_MARK;
6732 ret.original_type = NULL;
6738 expr = c_parser_unary_expression (parser);
6740 mark_exp_read (expr.value);
6741 c_inhibit_evaluation_warnings--;
6743 pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
6745 ret.value = c_alignof_expr (loc, expr.value);
6746 ret.original_code = ERROR_MARK;
6747 ret.original_type = NULL;
6752 /* Helper function to read arguments of builtins which are interfaces
6753 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6754 others. The name of the builtin is passed using BNAME parameter.
6755 Function returns true if there were no errors while parsing and
6756 stores the arguments in CEXPR_LIST. */
6758 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6759 vec<c_expr_t, va_gc> **ret_cexpr_list,
6762 location_t loc = c_parser_peek_token (parser)->location;
6763 vec<c_expr_t, va_gc> *cexpr_list;
6765 bool saved_force_folding_builtin_constant_p;
6767 *ret_cexpr_list = NULL;
6768 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6770 error_at (loc, "cannot take address of %qs", bname);
6774 c_parser_consume_token (parser);
6776 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6778 c_parser_consume_token (parser);
6782 saved_force_folding_builtin_constant_p
6783 = force_folding_builtin_constant_p;
6784 force_folding_builtin_constant_p |= choose_expr_p;
6785 expr = c_parser_expr_no_commas (parser, NULL);
6786 force_folding_builtin_constant_p
6787 = saved_force_folding_builtin_constant_p;
6788 vec_alloc (cexpr_list, 1);
6789 vec_safe_push (cexpr_list, expr);
6790 while (c_parser_next_token_is (parser, CPP_COMMA))
6792 c_parser_consume_token (parser);
6793 expr = c_parser_expr_no_commas (parser, NULL);
6794 vec_safe_push (cexpr_list, expr);
6797 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6800 *ret_cexpr_list = cexpr_list;
6804 /* This represents a single generic-association. */
6806 struct c_generic_association
6808 /* The location of the starting token of the type. */
6809 location_t type_location;
6810 /* The association's type, or NULL_TREE for 'default'. */
6812 /* The association's expression. */
6813 struct c_expr expression;
6816 /* Parse a generic-selection. (C11 6.5.1.1).
6819 _Generic ( assignment-expression , generic-assoc-list )
6823 generic-assoc-list , generic-association
6825 generic-association:
6826 type-name : assignment-expression
6827 default : assignment-expression
6830 static struct c_expr
6831 c_parser_generic_selection (c_parser *parser)
6833 vec<c_generic_association> associations = vNULL;
6834 struct c_expr selector, error_expr;
6836 struct c_generic_association matched_assoc;
6837 bool match_found = false;
6838 location_t generic_loc, selector_loc;
6840 error_expr.original_code = ERROR_MARK;
6841 error_expr.original_type = NULL;
6842 error_expr.value = error_mark_node;
6843 matched_assoc.type_location = UNKNOWN_LOCATION;
6844 matched_assoc.type = NULL_TREE;
6845 matched_assoc.expression = error_expr;
6847 gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
6848 generic_loc = c_parser_peek_token (parser)->location;
6849 c_parser_consume_token (parser);
6851 pedwarn_c99 (generic_loc, OPT_Wpedantic,
6852 "ISO C99 does not support %<_Generic%>");
6854 pedwarn_c99 (generic_loc, OPT_Wpedantic,
6855 "ISO C90 does not support %<_Generic%>");
6857 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6860 c_inhibit_evaluation_warnings++;
6861 selector_loc = c_parser_peek_token (parser)->location;
6862 selector = c_parser_expr_no_commas (parser, NULL);
6863 selector = default_function_array_conversion (selector_loc, selector);
6864 c_inhibit_evaluation_warnings--;
6866 if (selector.value == error_mark_node)
6868 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6871 selector_type = TREE_TYPE (selector.value);
6872 /* In ISO C terms, rvalues (including the controlling expression of
6873 _Generic) do not have qualified types. */
6874 if (TREE_CODE (selector_type) != ARRAY_TYPE)
6875 selector_type = TYPE_MAIN_VARIANT (selector_type);
6876 /* In ISO C terms, _Noreturn is not part of the type of expressions
6877 such as &abort, but in GCC it is represented internally as a type
6879 if (FUNCTION_POINTER_TYPE_P (selector_type)
6880 && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
6882 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
6884 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6886 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6892 struct c_generic_association assoc, *iter;
6894 c_token *token = c_parser_peek_token (parser);
6896 assoc.type_location = token->location;
6897 if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
6899 c_parser_consume_token (parser);
6900 assoc.type = NULL_TREE;
6904 struct c_type_name *type_name;
6906 type_name = c_parser_type_name (parser);
6907 if (type_name == NULL)
6909 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6912 assoc.type = groktypename (type_name, NULL, NULL);
6913 if (assoc.type == error_mark_node)
6915 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6919 if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
6920 error_at (assoc.type_location,
6921 "%<_Generic%> association has function type");
6922 else if (!COMPLETE_TYPE_P (assoc.type))
6923 error_at (assoc.type_location,
6924 "%<_Generic%> association has incomplete type");
6926 if (variably_modified_type_p (assoc.type, NULL_TREE))
6927 error_at (assoc.type_location,
6928 "%<_Generic%> association has "
6929 "variable length type");
6932 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6934 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6938 assoc.expression = c_parser_expr_no_commas (parser, NULL);
6939 if (assoc.expression.value == error_mark_node)
6941 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6945 for (ix = 0; associations.iterate (ix, &iter); ++ix)
6947 if (assoc.type == NULL_TREE)
6949 if (iter->type == NULL_TREE)
6951 error_at (assoc.type_location,
6952 "duplicate %<default%> case in %<_Generic%>");
6953 inform (iter->type_location, "original %<default%> is here");
6956 else if (iter->type != NULL_TREE)
6958 if (comptypes (assoc.type, iter->type))
6960 error_at (assoc.type_location,
6961 "%<_Generic%> specifies two compatible types");
6962 inform (iter->type_location, "compatible type is here");
6967 if (assoc.type == NULL_TREE)
6971 matched_assoc = assoc;
6975 else if (comptypes (assoc.type, selector_type))
6977 if (!match_found || matched_assoc.type == NULL_TREE)
6979 matched_assoc = assoc;
6984 error_at (assoc.type_location,
6985 "%<_Generic> selector matches multiple associations");
6986 inform (matched_assoc.type_location,
6987 "other match is here");
6991 associations.safe_push (assoc);
6993 if (c_parser_peek_token (parser)->type != CPP_COMMA)
6995 c_parser_consume_token (parser);
6998 associations.release ();
7000 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7002 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7008 error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7009 "compatible with any association",
7014 return matched_assoc.expression;
7017 associations.release ();
7021 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7025 postfix-expression [ expression ]
7026 postfix-expression ( argument-expression-list[opt] )
7027 postfix-expression . identifier
7028 postfix-expression -> identifier
7029 postfix-expression ++
7030 postfix-expression --
7031 ( type-name ) { initializer-list }
7032 ( type-name ) { initializer-list , }
7034 argument-expression-list:
7036 argument-expression-list , argument-expression
7049 (treated as a keyword in GNU C)
7052 ( compound-statement )
7053 __builtin_va_arg ( assignment-expression , type-name )
7054 __builtin_offsetof ( type-name , offsetof-member-designator )
7055 __builtin_choose_expr ( assignment-expression ,
7056 assignment-expression ,
7057 assignment-expression )
7058 __builtin_types_compatible_p ( type-name , type-name )
7059 __builtin_complex ( assignment-expression , assignment-expression )
7060 __builtin_shuffle ( assignment-expression , assignment-expression )
7061 __builtin_shuffle ( assignment-expression ,
7062 assignment-expression ,
7063 assignment-expression, )
7065 offsetof-member-designator:
7067 offsetof-member-designator . identifier
7068 offsetof-member-designator [ expression ]
7073 [ objc-receiver objc-message-args ]
7074 @selector ( objc-selector-arg )
7075 @protocol ( identifier )
7076 @encode ( type-name )
7078 Classname . identifier
7081 static struct c_expr
7082 c_parser_postfix_expression (c_parser *parser)
7084 struct c_expr expr, e1;
7085 struct c_type_name *t1, *t2;
7086 location_t loc = c_parser_peek_token (parser)->location;;
7087 expr.original_code = ERROR_MARK;
7088 expr.original_type = NULL;
7089 switch (c_parser_peek_token (parser)->type)
7092 expr.value = c_parser_peek_token (parser)->value;
7093 loc = c_parser_peek_token (parser)->location;
7094 c_parser_consume_token (parser);
7095 if (TREE_CODE (expr.value) == FIXED_CST
7096 && !targetm.fixed_point_supported_p ())
7098 error_at (loc, "fixed-point types not supported for this target");
7099 expr.value = error_mark_node;
7106 expr.value = c_parser_peek_token (parser)->value;
7107 c_parser_consume_token (parser);
7113 case CPP_UTF8STRING:
7114 expr.value = c_parser_peek_token (parser)->value;
7115 expr.original_code = STRING_CST;
7116 c_parser_consume_token (parser);
7118 case CPP_OBJC_STRING:
7119 gcc_assert (c_dialect_objc ());
7121 = objc_build_string_object (c_parser_peek_token (parser)->value);
7122 c_parser_consume_token (parser);
7125 switch (c_parser_peek_token (parser)->id_kind)
7129 tree id = c_parser_peek_token (parser)->value;
7130 c_parser_consume_token (parser);
7131 expr.value = build_external_ref (loc, id,
7132 (c_parser_peek_token (parser)->type
7134 &expr.original_type);
7137 case C_ID_CLASSNAME:
7139 /* Here we parse the Objective-C 2.0 Class.name dot
7141 tree class_name = c_parser_peek_token (parser)->value;
7143 c_parser_consume_token (parser);
7144 gcc_assert (c_dialect_objc ());
7145 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7147 expr.value = error_mark_node;
7150 if (c_parser_next_token_is_not (parser, CPP_NAME))
7152 c_parser_error (parser, "expected identifier");
7153 expr.value = error_mark_node;
7156 component = c_parser_peek_token (parser)->value;
7157 c_parser_consume_token (parser);
7158 expr.value = objc_build_class_component_ref (class_name,
7163 c_parser_error (parser, "expected expression");
7164 expr.value = error_mark_node;
7168 case CPP_OPEN_PAREN:
7169 /* A parenthesized expression, statement expression or compound
7171 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7173 /* A statement expression. */
7175 location_t brace_loc;
7176 c_parser_consume_token (parser);
7177 brace_loc = c_parser_peek_token (parser)->location;
7178 c_parser_consume_token (parser);
7179 if (!building_stmt_list_p ())
7181 error_at (loc, "braced-group within expression allowed "
7182 "only inside a function");
7183 parser->error = true;
7184 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7185 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7186 expr.value = error_mark_node;
7189 stmt = c_begin_stmt_expr ();
7190 c_parser_compound_statement_nostart (parser);
7191 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7193 pedwarn (loc, OPT_Wpedantic,
7194 "ISO C forbids braced-groups within expressions");
7195 expr.value = c_finish_stmt_expr (brace_loc, stmt);
7196 mark_exp_read (expr.value);
7198 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7200 /* A compound literal. ??? Can we actually get here rather
7201 than going directly to
7202 c_parser_postfix_expression_after_paren_type from
7205 struct c_type_name *type_name;
7206 c_parser_consume_token (parser);
7207 loc = c_parser_peek_token (parser)->location;
7208 type_name = c_parser_type_name (parser);
7209 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7211 if (type_name == NULL)
7213 expr.value = error_mark_node;
7216 expr = c_parser_postfix_expression_after_paren_type (parser,
7222 /* A parenthesized expression. */
7223 c_parser_consume_token (parser);
7224 expr = c_parser_expression (parser);
7225 if (TREE_CODE (expr.value) == MODIFY_EXPR)
7226 TREE_NO_WARNING (expr.value) = 1;
7227 if (expr.original_code != C_MAYBE_CONST_EXPR)
7228 expr.original_code = ERROR_MARK;
7229 /* Don't change EXPR.ORIGINAL_TYPE. */
7230 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7235 switch (c_parser_peek_token (parser)->keyword)
7237 case RID_FUNCTION_NAME:
7238 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7239 "%<__FUNCTION__%> predefined identifier");
7240 expr.value = fname_decl (loc,
7241 c_parser_peek_token (parser)->keyword,
7242 c_parser_peek_token (parser)->value);
7243 c_parser_consume_token (parser);
7245 case RID_PRETTY_FUNCTION_NAME:
7246 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7247 "%<__PRETTY_FUNCTION__%> predefined identifier");
7248 expr.value = fname_decl (loc,
7249 c_parser_peek_token (parser)->keyword,
7250 c_parser_peek_token (parser)->value);
7251 c_parser_consume_token (parser);
7253 case RID_C99_FUNCTION_NAME:
7254 pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support "
7255 "%<__func__%> predefined identifier");
7256 expr.value = fname_decl (loc,
7257 c_parser_peek_token (parser)->keyword,
7258 c_parser_peek_token (parser)->value);
7259 c_parser_consume_token (parser);
7262 c_parser_consume_token (parser);
7263 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7265 expr.value = error_mark_node;
7268 e1 = c_parser_expr_no_commas (parser, NULL);
7269 mark_exp_read (e1.value);
7270 e1.value = c_fully_fold (e1.value, false, NULL);
7271 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7273 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7274 expr.value = error_mark_node;
7277 loc = c_parser_peek_token (parser)->location;
7278 t1 = c_parser_type_name (parser);
7279 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7283 expr.value = error_mark_node;
7287 tree type_expr = NULL_TREE;
7288 expr.value = c_build_va_arg (loc, e1.value,
7289 groktypename (t1, &type_expr, NULL));
7292 expr.value = build2 (C_MAYBE_CONST_EXPR,
7293 TREE_TYPE (expr.value), type_expr,
7295 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
7300 c_parser_consume_token (parser);
7301 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7303 expr.value = error_mark_node;
7306 t1 = c_parser_type_name (parser);
7308 parser->error = true;
7309 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7310 gcc_assert (parser->error);
7313 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7314 expr.value = error_mark_node;
7319 tree type = groktypename (t1, NULL, NULL);
7321 if (type == error_mark_node)
7322 offsetof_ref = error_mark_node;
7325 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
7326 SET_EXPR_LOCATION (offsetof_ref, loc);
7328 /* Parse the second argument to __builtin_offsetof. We
7329 must have one identifier, and beyond that we want to
7330 accept sub structure and sub array references. */
7331 if (c_parser_next_token_is (parser, CPP_NAME))
7333 offsetof_ref = build_component_ref
7334 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
7335 c_parser_consume_token (parser);
7336 while (c_parser_next_token_is (parser, CPP_DOT)
7337 || c_parser_next_token_is (parser,
7339 || c_parser_next_token_is (parser,
7342 if (c_parser_next_token_is (parser, CPP_DEREF))
7344 loc = c_parser_peek_token (parser)->location;
7345 offsetof_ref = build_array_ref (loc,
7350 else if (c_parser_next_token_is (parser, CPP_DOT))
7353 c_parser_consume_token (parser);
7354 if (c_parser_next_token_is_not (parser,
7357 c_parser_error (parser, "expected identifier");
7360 offsetof_ref = build_component_ref
7362 c_parser_peek_token (parser)->value);
7363 c_parser_consume_token (parser);
7369 loc = c_parser_peek_token (parser)->location;
7370 c_parser_consume_token (parser);
7371 ce = c_parser_expression (parser);
7372 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
7374 idx = c_fully_fold (idx, false, NULL);
7375 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7377 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
7382 c_parser_error (parser, "expected identifier");
7383 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7385 expr.value = fold_offsetof (offsetof_ref);
7388 case RID_CHOOSE_EXPR:
7390 vec<c_expr_t, va_gc> *cexpr_list;
7391 c_expr_t *e1_p, *e2_p, *e3_p;
7394 c_parser_consume_token (parser);
7395 if (!c_parser_get_builtin_args (parser,
7396 "__builtin_choose_expr",
7399 expr.value = error_mark_node;
7403 if (vec_safe_length (cexpr_list) != 3)
7405 error_at (loc, "wrong number of arguments to "
7406 "%<__builtin_choose_expr%>");
7407 expr.value = error_mark_node;
7411 e1_p = &(*cexpr_list)[0];
7412 e2_p = &(*cexpr_list)[1];
7413 e3_p = &(*cexpr_list)[2];
7416 mark_exp_read (e2_p->value);
7417 mark_exp_read (e3_p->value);
7418 if (TREE_CODE (c) != INTEGER_CST
7419 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
7421 "first argument to %<__builtin_choose_expr%> not"
7423 constant_expression_warning (c);
7424 expr = integer_zerop (c) ? *e3_p : *e2_p;
7427 case RID_TYPES_COMPATIBLE_P:
7428 c_parser_consume_token (parser);
7429 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7431 expr.value = error_mark_node;
7434 t1 = c_parser_type_name (parser);
7437 expr.value = error_mark_node;
7440 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7442 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7443 expr.value = error_mark_node;
7446 t2 = c_parser_type_name (parser);
7449 expr.value = error_mark_node;
7452 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7456 e1 = groktypename (t1, NULL, NULL);
7457 e2 = groktypename (t2, NULL, NULL);
7458 if (e1 == error_mark_node || e2 == error_mark_node)
7460 expr.value = error_mark_node;
7464 e1 = TYPE_MAIN_VARIANT (e1);
7465 e2 = TYPE_MAIN_VARIANT (e2);
7468 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
7471 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
7473 vec<c_expr_t, va_gc> *cexpr_list;
7477 c_parser_consume_token (parser);
7478 if (!c_parser_get_builtin_args (parser,
7479 "__builtin_call_with_static_chain",
7480 &cexpr_list, false))
7482 expr.value = error_mark_node;
7485 if (vec_safe_length (cexpr_list) != 2)
7487 error_at (loc, "wrong number of arguments to "
7488 "%<__builtin_call_with_static_chain%>");
7489 expr.value = error_mark_node;
7493 expr = (*cexpr_list)[0];
7494 e2_p = &(*cexpr_list)[1];
7495 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7496 chain_value = e2_p->value;
7497 mark_exp_read (chain_value);
7499 if (TREE_CODE (expr.value) != CALL_EXPR)
7500 error_at (loc, "first argument to "
7501 "%<__builtin_call_with_static_chain%> "
7502 "must be a call expression");
7503 else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
7504 error_at (loc, "second argument to "
7505 "%<__builtin_call_with_static_chain%> "
7506 "must be a pointer type");
7508 CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
7511 case RID_BUILTIN_COMPLEX:
7513 vec<c_expr_t, va_gc> *cexpr_list;
7514 c_expr_t *e1_p, *e2_p;
7516 c_parser_consume_token (parser);
7517 if (!c_parser_get_builtin_args (parser,
7518 "__builtin_complex",
7519 &cexpr_list, false))
7521 expr.value = error_mark_node;
7525 if (vec_safe_length (cexpr_list) != 2)
7527 error_at (loc, "wrong number of arguments to "
7528 "%<__builtin_complex%>");
7529 expr.value = error_mark_node;
7533 e1_p = &(*cexpr_list)[0];
7534 e2_p = &(*cexpr_list)[1];
7536 *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
7537 if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
7538 e1_p->value = convert (TREE_TYPE (e1_p->value),
7539 TREE_OPERAND (e1_p->value, 0));
7540 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
7541 if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
7542 e2_p->value = convert (TREE_TYPE (e2_p->value),
7543 TREE_OPERAND (e2_p->value, 0));
7544 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7545 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
7546 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
7547 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
7549 error_at (loc, "%<__builtin_complex%> operand "
7550 "not of real binary floating-point type");
7551 expr.value = error_mark_node;
7554 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
7555 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
7558 "%<__builtin_complex%> operands of different types");
7559 expr.value = error_mark_node;
7562 pedwarn_c90 (loc, OPT_Wpedantic,
7563 "ISO C90 does not support complex types");
7564 expr.value = build2 (COMPLEX_EXPR,
7567 (TREE_TYPE (e1_p->value))),
7568 e1_p->value, e2_p->value);
7571 case RID_BUILTIN_SHUFFLE:
7573 vec<c_expr_t, va_gc> *cexpr_list;
7577 c_parser_consume_token (parser);
7578 if (!c_parser_get_builtin_args (parser,
7579 "__builtin_shuffle",
7580 &cexpr_list, false))
7582 expr.value = error_mark_node;
7586 FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
7587 *p = convert_lvalue_to_rvalue (loc, *p, true, true);
7589 if (vec_safe_length (cexpr_list) == 2)
7591 c_build_vec_perm_expr
7592 (loc, (*cexpr_list)[0].value,
7593 NULL_TREE, (*cexpr_list)[1].value);
7595 else if (vec_safe_length (cexpr_list) == 3)
7597 c_build_vec_perm_expr
7598 (loc, (*cexpr_list)[0].value,
7599 (*cexpr_list)[1].value,
7600 (*cexpr_list)[2].value);
7603 error_at (loc, "wrong number of arguments to "
7604 "%<__builtin_shuffle%>");
7605 expr.value = error_mark_node;
7609 case RID_AT_SELECTOR:
7610 gcc_assert (c_dialect_objc ());
7611 c_parser_consume_token (parser);
7612 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7614 expr.value = error_mark_node;
7618 tree sel = c_parser_objc_selector_arg (parser);
7619 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7621 expr.value = objc_build_selector_expr (loc, sel);
7624 case RID_AT_PROTOCOL:
7625 gcc_assert (c_dialect_objc ());
7626 c_parser_consume_token (parser);
7627 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7629 expr.value = error_mark_node;
7632 if (c_parser_next_token_is_not (parser, CPP_NAME))
7634 c_parser_error (parser, "expected identifier");
7635 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7636 expr.value = error_mark_node;
7640 tree id = c_parser_peek_token (parser)->value;
7641 c_parser_consume_token (parser);
7642 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7644 expr.value = objc_build_protocol_expr (id);
7648 /* Extension to support C-structures in the archiver. */
7649 gcc_assert (c_dialect_objc ());
7650 c_parser_consume_token (parser);
7651 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7653 expr.value = error_mark_node;
7656 t1 = c_parser_type_name (parser);
7659 expr.value = error_mark_node;
7660 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7663 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7666 tree type = groktypename (t1, NULL, NULL);
7667 expr.value = objc_build_encode_expr (type);
7671 expr = c_parser_generic_selection (parser);
7673 case RID_CILK_SPAWN:
7674 c_parser_consume_token (parser);
7677 error_at (loc, "-fcilkplus must be enabled to use "
7679 expr = c_parser_postfix_expression (parser);
7680 expr.value = error_mark_node;
7682 else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7684 error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
7685 "are not permitted");
7686 /* Now flush out all the _Cilk_spawns. */
7687 while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
7688 c_parser_consume_token (parser);
7689 expr = c_parser_postfix_expression (parser);
7693 expr = c_parser_postfix_expression (parser);
7694 expr.value = build_cilk_spawn (loc, expr.value);
7698 c_parser_error (parser, "expected expression");
7699 expr.value = error_mark_node;
7703 case CPP_OPEN_SQUARE:
7704 if (c_dialect_objc ())
7706 tree receiver, args;
7707 c_parser_consume_token (parser);
7708 receiver = c_parser_objc_receiver (parser);
7709 args = c_parser_objc_message_args (parser);
7710 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7712 expr.value = objc_build_message_expr (receiver, args);
7715 /* Else fall through to report error. */
7717 c_parser_error (parser, "expected expression");
7718 expr.value = error_mark_node;
7721 return c_parser_postfix_expression_after_primary (parser, loc, expr);
7724 /* Parse a postfix expression after a parenthesized type name: the
7725 brace-enclosed initializer of a compound literal, possibly followed
7726 by some postfix operators. This is separate because it is not
7727 possible to tell until after the type name whether a cast
7728 expression has a cast or a compound literal, or whether the operand
7729 of sizeof is a parenthesized type name or starts with a compound
7730 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7731 location of the first token after the parentheses around the type
7734 static struct c_expr
7735 c_parser_postfix_expression_after_paren_type (c_parser *parser,
7736 struct c_type_name *type_name,
7737 location_t type_loc)
7743 location_t start_loc;
7744 tree type_expr = NULL_TREE;
7745 bool type_expr_const = true;
7746 check_compound_literal_type (type_loc, type_name);
7747 start_init (NULL_TREE, NULL, 0);
7748 type = groktypename (type_name, &type_expr, &type_expr_const);
7749 start_loc = c_parser_peek_token (parser)->location;
7750 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
7752 error_at (type_loc, "compound literal has variable size");
7753 type = error_mark_node;
7755 init = c_parser_braced_init (parser, type, false, NULL);
7757 maybe_warn_string_init (type_loc, type, init);
7759 if (type != error_mark_node
7760 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
7761 && current_function_decl)
7763 error ("compound literal qualified by address-space qualifier");
7764 type = error_mark_node;
7767 pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
7768 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
7769 ? CONSTRUCTOR_NON_CONST (init.value)
7770 : init.original_code == C_MAYBE_CONST_EXPR);
7771 non_const |= !type_expr_const;
7772 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
7773 expr.original_code = ERROR_MARK;
7774 expr.original_type = NULL;
7777 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
7779 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
7780 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
7784 gcc_assert (!non_const);
7785 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
7786 type_expr, expr.value);
7789 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
7792 /* Callback function for sizeof_pointer_memaccess_warning to compare
7796 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
7798 return comptypes (type1, type2) == 1;
7801 /* Parse a postfix expression after the initial primary or compound
7802 literal; that is, parse a series of postfix operators.
7804 EXPR_LOC is the location of the primary expression. */
7806 static struct c_expr
7807 c_parser_postfix_expression_after_primary (c_parser *parser,
7808 location_t expr_loc,
7811 struct c_expr orig_expr;
7813 location_t sizeof_arg_loc[3];
7815 unsigned int literal_zero_mask;
7817 vec<tree, va_gc> *exprlist;
7818 vec<tree, va_gc> *origtypes = NULL;
7819 vec<location_t> arg_loc = vNULL;
7823 location_t op_loc = c_parser_peek_token (parser)->location;
7824 switch (c_parser_peek_token (parser)->type)
7826 case CPP_OPEN_SQUARE:
7827 /* Array reference. */
7828 c_parser_consume_token (parser);
7830 && c_parser_peek_token (parser)->type == CPP_COLON)
7831 /* If we are here, then we have something like this:
7834 expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE,
7838 idx = c_parser_expression (parser).value;
7839 /* Here we have 3 options:
7840 1. Array [EXPR] -- Normal Array call.
7841 2. Array [EXPR : EXPR] -- Array notation without stride.
7842 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7844 For 1, we just handle it just like a normal array expression.
7845 For 2 and 3 we handle it like we handle array notations. The
7846 idx value we have above becomes the initial/start index.
7849 && c_parser_peek_token (parser)->type == CPP_COLON)
7850 expr.value = c_parser_array_notation (expr_loc, parser, idx,
7854 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
7856 expr.value = build_array_ref (op_loc, expr.value, idx);
7859 expr.original_code = ERROR_MARK;
7860 expr.original_type = NULL;
7862 case CPP_OPEN_PAREN:
7863 /* Function call. */
7864 c_parser_consume_token (parser);
7865 for (i = 0; i < 3; i++)
7867 sizeof_arg[i] = NULL_TREE;
7868 sizeof_arg_loc[i] = UNKNOWN_LOCATION;
7870 literal_zero_mask = 0;
7871 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7874 exprlist = c_parser_expr_list (parser, true, false, &origtypes,
7875 sizeof_arg_loc, sizeof_arg,
7876 &arg_loc, &literal_zero_mask);
7877 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7880 mark_exp_read (expr.value);
7881 if (warn_sizeof_pointer_memaccess)
7882 sizeof_pointer_memaccess_warning (sizeof_arg_loc,
7883 expr.value, exprlist,
7885 sizeof_ptr_memacc_comptypes);
7886 if (warn_memset_transposed_args
7887 && TREE_CODE (expr.value) == FUNCTION_DECL
7888 && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
7889 && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
7890 && vec_safe_length (exprlist) == 3
7891 && integer_zerop ((*exprlist)[2])
7892 && (literal_zero_mask & (1 << 2)) != 0
7893 && (!integer_zerop ((*exprlist)[1])
7894 || (literal_zero_mask & (1 << 1)) == 0))
7895 warning_at (expr_loc, OPT_Wmemset_transposed_args,
7896 "%<memset%> used with constant zero length parameter; "
7897 "this could be due to transposed parameters");
7900 = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
7901 exprlist, origtypes);
7902 expr.original_code = ERROR_MARK;
7903 if (TREE_CODE (expr.value) == INTEGER_CST
7904 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
7905 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
7906 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
7907 expr.original_code = C_MAYBE_CONST_EXPR;
7908 expr.original_type = NULL;
7911 release_tree_vector (exprlist);
7912 release_tree_vector (origtypes);
7917 /* Structure element reference. */
7918 c_parser_consume_token (parser);
7919 expr = default_function_array_conversion (expr_loc, expr);
7920 if (c_parser_next_token_is (parser, CPP_NAME))
7921 ident = c_parser_peek_token (parser)->value;
7924 c_parser_error (parser, "expected identifier");
7925 expr.value = error_mark_node;
7926 expr.original_code = ERROR_MARK;
7927 expr.original_type = NULL;
7930 c_parser_consume_token (parser);
7931 expr.value = build_component_ref (op_loc, expr.value, ident);
7932 expr.original_code = ERROR_MARK;
7933 if (TREE_CODE (expr.value) != COMPONENT_REF)
7934 expr.original_type = NULL;
7937 /* Remember the original type of a bitfield. */
7938 tree field = TREE_OPERAND (expr.value, 1);
7939 if (TREE_CODE (field) != FIELD_DECL)
7940 expr.original_type = NULL;
7942 expr.original_type = DECL_BIT_FIELD_TYPE (field);
7946 /* Structure element reference. */
7947 c_parser_consume_token (parser);
7948 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
7949 if (c_parser_next_token_is (parser, CPP_NAME))
7950 ident = c_parser_peek_token (parser)->value;
7953 c_parser_error (parser, "expected identifier");
7954 expr.value = error_mark_node;
7955 expr.original_code = ERROR_MARK;
7956 expr.original_type = NULL;
7959 c_parser_consume_token (parser);
7960 expr.value = build_component_ref (op_loc,
7961 build_indirect_ref (op_loc,
7965 expr.original_code = ERROR_MARK;
7966 if (TREE_CODE (expr.value) != COMPONENT_REF)
7967 expr.original_type = NULL;
7970 /* Remember the original type of a bitfield. */
7971 tree field = TREE_OPERAND (expr.value, 1);
7972 if (TREE_CODE (field) != FIELD_DECL)
7973 expr.original_type = NULL;
7975 expr.original_type = DECL_BIT_FIELD_TYPE (field);
7979 /* Postincrement. */
7980 c_parser_consume_token (parser);
7981 /* If the expressions have array notations, we expand them. */
7983 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
7984 expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr);
7987 expr = default_function_array_read_conversion (expr_loc, expr);
7988 expr.value = build_unary_op (op_loc,
7989 POSTINCREMENT_EXPR, expr.value, 0);
7991 expr.original_code = ERROR_MARK;
7992 expr.original_type = NULL;
7994 case CPP_MINUS_MINUS:
7995 /* Postdecrement. */
7996 c_parser_consume_token (parser);
7997 /* If the expressions have array notations, we expand them. */
7999 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF)
8000 expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr);
8003 expr = default_function_array_read_conversion (expr_loc, expr);
8004 expr.value = build_unary_op (op_loc,
8005 POSTDECREMENT_EXPR, expr.value, 0);
8007 expr.original_code = ERROR_MARK;
8008 expr.original_type = NULL;
8016 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8019 assignment-expression
8020 expression , assignment-expression
8023 static struct c_expr
8024 c_parser_expression (c_parser *parser)
8026 location_t tloc = c_parser_peek_token (parser)->location;
8028 expr = c_parser_expr_no_commas (parser, NULL);
8029 if (c_parser_next_token_is (parser, CPP_COMMA))
8030 expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
8031 while (c_parser_next_token_is (parser, CPP_COMMA))
8035 location_t loc = c_parser_peek_token (parser)->location;
8036 location_t expr_loc;
8037 c_parser_consume_token (parser);
8038 expr_loc = c_parser_peek_token (parser)->location;
8039 lhsval = expr.value;
8040 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
8041 lhsval = TREE_OPERAND (lhsval, 1);
8042 if (DECL_P (lhsval) || handled_component_p (lhsval))
8043 mark_exp_read (lhsval);
8044 next = c_parser_expr_no_commas (parser, NULL);
8045 next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
8046 expr.value = build_compound_expr (loc, expr.value, next.value);
8047 expr.original_code = COMPOUND_EXPR;
8048 expr.original_type = next.original_type;
8053 /* Parse an expression and convert functions or arrays to pointers and
8054 lvalues to rvalues. */
8056 static struct c_expr
8057 c_parser_expression_conv (c_parser *parser)
8060 location_t loc = c_parser_peek_token (parser)->location;
8061 expr = c_parser_expression (parser);
8062 expr = convert_lvalue_to_rvalue (loc, expr, true, false);
8066 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8067 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8070 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
8073 if (idx >= HOST_BITS_PER_INT)
8076 c_token *tok = c_parser_peek_token (parser);
8084 /* If a parameter is literal zero alone, remember it
8085 for -Wmemset-transposed-args warning. */
8086 if (integer_zerop (tok->value)
8087 && !TREE_OVERFLOW (tok->value)
8088 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8089 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
8090 *literal_zero_mask |= 1U << idx;
8096 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8097 functions and arrays to pointers and lvalues to rvalues. If
8098 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8099 locations of function arguments into this vector.
8102 assignment-expression
8103 nonempty-expr-list , assignment-expression
8106 static vec<tree, va_gc> *
8107 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
8108 vec<tree, va_gc> **p_orig_types,
8109 location_t *sizeof_arg_loc, tree *sizeof_arg,
8110 vec<location_t> *locations,
8111 unsigned int *literal_zero_mask)
8113 vec<tree, va_gc> *ret;
8114 vec<tree, va_gc> *orig_types;
8116 location_t loc = c_parser_peek_token (parser)->location;
8117 location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8118 unsigned int idx = 0;
8120 ret = make_tree_vector ();
8121 if (p_orig_types == NULL)
8124 orig_types = make_tree_vector ();
8126 if (sizeof_arg != NULL
8127 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8128 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8129 if (literal_zero_mask)
8130 c_parser_check_literal_zero (parser, literal_zero_mask, 0);
8131 expr = c_parser_expr_no_commas (parser, NULL);
8133 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8135 expr.value = c_fully_fold (expr.value, false, NULL);
8136 ret->quick_push (expr.value);
8138 orig_types->quick_push (expr.original_type);
8140 locations->safe_push (loc);
8141 if (sizeof_arg != NULL
8142 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8143 && expr.original_code == SIZEOF_EXPR)
8145 sizeof_arg[0] = c_last_sizeof_arg;
8146 sizeof_arg_loc[0] = cur_sizeof_arg_loc;
8148 while (c_parser_next_token_is (parser, CPP_COMMA))
8150 c_parser_consume_token (parser);
8151 loc = c_parser_peek_token (parser)->location;
8152 if (sizeof_arg != NULL
8153 && c_parser_next_token_is_keyword (parser, RID_SIZEOF))
8154 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
8156 cur_sizeof_arg_loc = UNKNOWN_LOCATION;
8157 if (literal_zero_mask)
8158 c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
8159 expr = c_parser_expr_no_commas (parser, NULL);
8161 expr = convert_lvalue_to_rvalue (loc, expr, true, true);
8163 expr.value = c_fully_fold (expr.value, false, NULL);
8164 vec_safe_push (ret, expr.value);
8166 vec_safe_push (orig_types, expr.original_type);
8168 locations->safe_push (loc);
8170 && sizeof_arg != NULL
8171 && cur_sizeof_arg_loc != UNKNOWN_LOCATION
8172 && expr.original_code == SIZEOF_EXPR)
8174 sizeof_arg[idx] = c_last_sizeof_arg;
8175 sizeof_arg_loc[idx] = cur_sizeof_arg_loc;
8179 *p_orig_types = orig_types;
8183 /* Parse Objective-C-specific constructs. */
8185 /* Parse an objc-class-definition.
8187 objc-class-definition:
8188 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8189 objc-class-instance-variables[opt] objc-methodprotolist @end
8190 @implementation identifier objc-superclass[opt]
8191 objc-class-instance-variables[opt]
8192 @interface identifier ( identifier ) objc-protocol-refs[opt]
8193 objc-methodprotolist @end
8194 @interface identifier ( ) objc-protocol-refs[opt]
8195 objc-methodprotolist @end
8196 @implementation identifier ( identifier )
8201 "@interface identifier (" must start "@interface identifier (
8202 identifier ) ...": objc-methodprotolist in the first production may
8203 not start with a parenthesized identifier as a declarator of a data
8204 definition with no declaration specifiers if the objc-superclass,
8205 objc-protocol-refs and objc-class-instance-variables are omitted. */
8208 c_parser_objc_class_definition (c_parser *parser, tree attributes)
8213 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
8215 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
8220 c_parser_consume_token (parser);
8221 if (c_parser_next_token_is_not (parser, CPP_NAME))
8223 c_parser_error (parser, "expected identifier");
8226 id1 = c_parser_peek_token (parser)->value;
8227 c_parser_consume_token (parser);
8228 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8230 /* We have a category or class extension. */
8232 tree proto = NULL_TREE;
8233 c_parser_consume_token (parser);
8234 if (c_parser_next_token_is_not (parser, CPP_NAME))
8236 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
8238 /* We have a class extension. */
8243 c_parser_error (parser, "expected identifier or %<)%>");
8244 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8250 id2 = c_parser_peek_token (parser)->value;
8251 c_parser_consume_token (parser);
8253 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8256 objc_start_category_implementation (id1, id2);
8259 if (c_parser_next_token_is (parser, CPP_LESS))
8260 proto = c_parser_objc_protocol_refs (parser);
8261 objc_start_category_interface (id1, id2, proto, attributes);
8262 c_parser_objc_methodprotolist (parser);
8263 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8264 objc_finish_interface ();
8267 if (c_parser_next_token_is (parser, CPP_COLON))
8269 c_parser_consume_token (parser);
8270 if (c_parser_next_token_is_not (parser, CPP_NAME))
8272 c_parser_error (parser, "expected identifier");
8275 superclass = c_parser_peek_token (parser)->value;
8276 c_parser_consume_token (parser);
8279 superclass = NULL_TREE;
8282 tree proto = NULL_TREE;
8283 if (c_parser_next_token_is (parser, CPP_LESS))
8284 proto = c_parser_objc_protocol_refs (parser);
8285 objc_start_class_interface (id1, superclass, proto, attributes);
8288 objc_start_class_implementation (id1, superclass);
8289 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8290 c_parser_objc_class_instance_variables (parser);
8293 objc_continue_interface ();
8294 c_parser_objc_methodprotolist (parser);
8295 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8296 objc_finish_interface ();
8300 objc_continue_implementation ();
8305 /* Parse objc-class-instance-variables.
8307 objc-class-instance-variables:
8308 { objc-instance-variable-decl-list[opt] }
8310 objc-instance-variable-decl-list:
8311 objc-visibility-spec
8312 objc-instance-variable-decl ;
8314 objc-instance-variable-decl-list objc-visibility-spec
8315 objc-instance-variable-decl-list objc-instance-variable-decl ;
8316 objc-instance-variable-decl-list ;
8318 objc-visibility-spec:
8323 objc-instance-variable-decl:
8328 c_parser_objc_class_instance_variables (c_parser *parser)
8330 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
8331 c_parser_consume_token (parser);
8332 while (c_parser_next_token_is_not (parser, CPP_EOF))
8335 /* Parse any stray semicolon. */
8336 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8338 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8340 c_parser_consume_token (parser);
8343 /* Stop if at the end of the instance variables. */
8344 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8346 c_parser_consume_token (parser);
8349 /* Parse any objc-visibility-spec. */
8350 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
8352 c_parser_consume_token (parser);
8353 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
8356 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
8358 c_parser_consume_token (parser);
8359 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
8362 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
8364 c_parser_consume_token (parser);
8365 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
8368 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
8370 c_parser_consume_token (parser);
8371 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
8374 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
8376 c_parser_pragma (parser, pragma_external);
8380 /* Parse some comma-separated declarations. */
8381 decls = c_parser_struct_declaration (parser);
8384 /* There is a syntax error. We want to skip the offending
8385 tokens up to the next ';' (included) or '}'
8388 /* First, skip manually a ')' or ']'. This is because they
8389 reduce the nesting level, so c_parser_skip_until_found()
8390 wouldn't be able to skip past them. */
8391 c_token *token = c_parser_peek_token (parser);
8392 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
8393 c_parser_consume_token (parser);
8395 /* Then, do the standard skipping. */
8396 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8398 /* We hopefully recovered. Start normal parsing again. */
8399 parser->error = false;
8404 /* Comma-separated instance variables are chained together
8405 in reverse order; add them one by one. */
8406 tree ivar = nreverse (decls);
8407 for (; ivar; ivar = DECL_CHAIN (ivar))
8408 objc_add_instance_variable (copy_node (ivar));
8410 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8414 /* Parse an objc-class-declaration.
8416 objc-class-declaration:
8417 @class identifier-list ;
8421 c_parser_objc_class_declaration (c_parser *parser)
8423 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
8424 c_parser_consume_token (parser);
8425 /* Any identifiers, including those declared as type names, are OK
8430 if (c_parser_next_token_is_not (parser, CPP_NAME))
8432 c_parser_error (parser, "expected identifier");
8433 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8434 parser->error = false;
8437 id = c_parser_peek_token (parser)->value;
8438 objc_declare_class (id);
8439 c_parser_consume_token (parser);
8440 if (c_parser_next_token_is (parser, CPP_COMMA))
8441 c_parser_consume_token (parser);
8445 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8448 /* Parse an objc-alias-declaration.
8450 objc-alias-declaration:
8451 @compatibility_alias identifier identifier ;
8455 c_parser_objc_alias_declaration (c_parser *parser)
8458 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
8459 c_parser_consume_token (parser);
8460 if (c_parser_next_token_is_not (parser, CPP_NAME))
8462 c_parser_error (parser, "expected identifier");
8463 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8466 id1 = c_parser_peek_token (parser)->value;
8467 c_parser_consume_token (parser);
8468 if (c_parser_next_token_is_not (parser, CPP_NAME))
8470 c_parser_error (parser, "expected identifier");
8471 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8474 id2 = c_parser_peek_token (parser)->value;
8475 c_parser_consume_token (parser);
8476 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8477 objc_declare_alias (id1, id2);
8480 /* Parse an objc-protocol-definition.
8482 objc-protocol-definition:
8483 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8484 @protocol identifier-list ;
8486 "@protocol identifier ;" should be resolved as "@protocol
8487 identifier-list ;": objc-methodprotolist may not start with a
8488 semicolon in the first alternative if objc-protocol-refs are
8492 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
8494 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
8496 c_parser_consume_token (parser);
8497 if (c_parser_next_token_is_not (parser, CPP_NAME))
8499 c_parser_error (parser, "expected identifier");
8502 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
8503 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
8505 /* Any identifiers, including those declared as type names, are
8510 if (c_parser_next_token_is_not (parser, CPP_NAME))
8512 c_parser_error (parser, "expected identifier");
8515 id = c_parser_peek_token (parser)->value;
8516 objc_declare_protocol (id, attributes);
8517 c_parser_consume_token (parser);
8518 if (c_parser_next_token_is (parser, CPP_COMMA))
8519 c_parser_consume_token (parser);
8523 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8527 tree id = c_parser_peek_token (parser)->value;
8528 tree proto = NULL_TREE;
8529 c_parser_consume_token (parser);
8530 if (c_parser_next_token_is (parser, CPP_LESS))
8531 proto = c_parser_objc_protocol_refs (parser);
8532 parser->objc_pq_context = true;
8533 objc_start_protocol (id, proto, attributes);
8534 c_parser_objc_methodprotolist (parser);
8535 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
8536 parser->objc_pq_context = false;
8537 objc_finish_interface ();
8541 /* Parse an objc-method-type.
8547 Return true if it is a class method (+) and false if it is
8548 an instance method (-).
8551 c_parser_objc_method_type (c_parser *parser)
8553 switch (c_parser_peek_token (parser)->type)
8556 c_parser_consume_token (parser);
8559 c_parser_consume_token (parser);
8566 /* Parse an objc-method-definition.
8568 objc-method-definition:
8569 objc-method-type objc-method-decl ;[opt] compound-statement
8573 c_parser_objc_method_definition (c_parser *parser)
8575 bool is_class_method = c_parser_objc_method_type (parser);
8576 tree decl, attributes = NULL_TREE, expr = NULL_TREE;
8577 parser->objc_pq_context = true;
8578 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8580 if (decl == error_mark_node)
8581 return; /* Bail here. */
8583 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8585 c_parser_consume_token (parser);
8586 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8587 "extra semicolon in method definition specified");
8590 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8592 c_parser_error (parser, "expected %<{%>");
8596 parser->objc_pq_context = false;
8597 if (objc_start_method_definition (is_class_method, decl, attributes, expr))
8599 add_stmt (c_parser_compound_statement (parser));
8600 objc_finish_method_definition (current_function_decl);
8604 /* This code is executed when we find a method definition
8605 outside of an @implementation context (or invalid for other
8606 reasons). Parse the method (to keep going) but do not emit
8609 c_parser_compound_statement (parser);
8613 /* Parse an objc-methodprotolist.
8615 objc-methodprotolist:
8617 objc-methodprotolist objc-methodproto
8618 objc-methodprotolist declaration
8619 objc-methodprotolist ;
8623 The declaration is a data definition, which may be missing
8624 declaration specifiers under the same rules and diagnostics as
8625 other data definitions outside functions, and the stray semicolon
8626 is diagnosed the same way as a stray semicolon outside a
8630 c_parser_objc_methodprotolist (c_parser *parser)
8634 /* The list is terminated by @end. */
8635 switch (c_parser_peek_token (parser)->type)
8638 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
8639 "ISO C does not allow extra %<;%> outside of a function");
8640 c_parser_consume_token (parser);
8644 c_parser_objc_methodproto (parser);
8647 c_parser_pragma (parser, pragma_external);
8652 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
8654 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
8655 c_parser_objc_at_property_declaration (parser);
8656 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
8658 objc_set_method_opt (true);
8659 c_parser_consume_token (parser);
8661 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
8663 objc_set_method_opt (false);
8664 c_parser_consume_token (parser);
8667 c_parser_declaration_or_fndef (parser, false, false, true,
8668 false, true, NULL, vNULL);
8674 /* Parse an objc-methodproto.
8677 objc-method-type objc-method-decl ;
8681 c_parser_objc_methodproto (c_parser *parser)
8683 bool is_class_method = c_parser_objc_method_type (parser);
8684 tree decl, attributes = NULL_TREE;
8686 /* Remember protocol qualifiers in prototypes. */
8687 parser->objc_pq_context = true;
8688 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
8690 /* Forget protocol qualifiers now. */
8691 parser->objc_pq_context = false;
8693 /* Do not allow the presence of attributes to hide an erroneous
8694 method implementation in the interface section. */
8695 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
8697 c_parser_error (parser, "expected %<;%>");
8701 if (decl != error_mark_node)
8702 objc_add_method_declaration (is_class_method, decl, attributes);
8704 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8707 /* If we are at a position that method attributes may be present, check that
8708 there are not any parsed already (a syntax error) and then collect any
8709 specified at the current location. Finally, if new attributes were present,
8710 check that the next token is legal ( ';' for decls and '{' for defs). */
8713 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
8718 c_parser_error (parser,
8719 "method attributes must be specified at the end only");
8720 *attributes = NULL_TREE;
8724 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8725 *attributes = c_parser_attributes (parser);
8727 /* If there were no attributes here, just report any earlier error. */
8728 if (*attributes == NULL_TREE || bad)
8731 /* If the attributes are followed by a ; or {, then just report any earlier
8733 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
8734 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8737 /* We've got attributes, but not at the end. */
8738 c_parser_error (parser,
8739 "expected %<;%> or %<{%> after method attribute definition");
8743 /* Parse an objc-method-decl.
8746 ( objc-type-name ) objc-selector
8748 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8749 objc-keyword-selector objc-optparmlist
8752 objc-keyword-selector:
8754 objc-keyword-selector objc-keyword-decl
8757 objc-selector : ( objc-type-name ) identifier
8758 objc-selector : identifier
8759 : ( objc-type-name ) identifier
8763 objc-optparms objc-optellipsis
8767 objc-opt-parms , parameter-declaration
8775 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
8776 tree *attributes, tree *expr)
8778 tree type = NULL_TREE;
8780 tree parms = NULL_TREE;
8781 bool ellipsis = false;
8782 bool attr_err = false;
8784 *attributes = NULL_TREE;
8785 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8787 c_parser_consume_token (parser);
8788 type = c_parser_objc_type_name (parser);
8789 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8791 sel = c_parser_objc_selector (parser);
8792 /* If there is no selector, or a colon follows, we have an
8793 objc-keyword-selector. If there is a selector, and a colon does
8794 not follow, that selector ends the objc-method-decl. */
8795 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
8798 tree list = NULL_TREE;
8801 tree atype = NULL_TREE, id, keyworddecl;
8802 tree param_attr = NULL_TREE;
8803 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8805 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8807 c_parser_consume_token (parser);
8808 atype = c_parser_objc_type_name (parser);
8809 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8812 /* New ObjC allows attributes on method parameters. */
8813 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
8814 param_attr = c_parser_attributes (parser);
8815 if (c_parser_next_token_is_not (parser, CPP_NAME))
8817 c_parser_error (parser, "expected identifier");
8818 return error_mark_node;
8820 id = c_parser_peek_token (parser)->value;
8821 c_parser_consume_token (parser);
8822 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
8823 list = chainon (list, keyworddecl);
8824 tsel = c_parser_objc_selector (parser);
8825 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
8829 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8831 /* Parse the optional parameter list. Optional Objective-C
8832 method parameters follow the C syntax, and may include '...'
8833 to denote a variable number of arguments. */
8834 parms = make_node (TREE_LIST);
8835 while (c_parser_next_token_is (parser, CPP_COMMA))
8837 struct c_parm *parm;
8838 c_parser_consume_token (parser);
8839 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8842 c_parser_consume_token (parser);
8843 attr_err |= c_parser_objc_maybe_method_attributes
8844 (parser, attributes) ;
8847 parm = c_parser_parameter_declaration (parser, NULL_TREE);
8850 parms = chainon (parms,
8851 build_tree_list (NULL_TREE, grokparm (parm, expr)));
8856 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
8860 c_parser_error (parser, "objective-c method declaration is expected");
8861 return error_mark_node;
8865 return error_mark_node;
8867 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
8870 /* Parse an objc-type-name.
8873 objc-type-qualifiers[opt] type-name
8874 objc-type-qualifiers[opt]
8876 objc-type-qualifiers:
8878 objc-type-qualifiers objc-type-qualifier
8880 objc-type-qualifier: one of
8881 in out inout bycopy byref oneway
8885 c_parser_objc_type_name (c_parser *parser)
8887 tree quals = NULL_TREE;
8888 struct c_type_name *type_name = NULL;
8889 tree type = NULL_TREE;
8892 c_token *token = c_parser_peek_token (parser);
8893 if (token->type == CPP_KEYWORD
8894 && (token->keyword == RID_IN
8895 || token->keyword == RID_OUT
8896 || token->keyword == RID_INOUT
8897 || token->keyword == RID_BYCOPY
8898 || token->keyword == RID_BYREF
8899 || token->keyword == RID_ONEWAY))
8901 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
8902 c_parser_consume_token (parser);
8907 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
8908 type_name = c_parser_type_name (parser);
8910 type = groktypename (type_name, NULL, NULL);
8912 /* If the type is unknown, and error has already been produced and
8913 we need to recover from the error. In that case, use NULL_TREE
8914 for the type, as if no type had been specified; this will use the
8915 default type ('id') which is good for error recovery. */
8916 if (type == error_mark_node)
8919 return build_tree_list (quals, type);
8922 /* Parse objc-protocol-refs.
8929 c_parser_objc_protocol_refs (c_parser *parser)
8931 tree list = NULL_TREE;
8932 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
8933 c_parser_consume_token (parser);
8934 /* Any identifiers, including those declared as type names, are OK
8939 if (c_parser_next_token_is_not (parser, CPP_NAME))
8941 c_parser_error (parser, "expected identifier");
8944 id = c_parser_peek_token (parser)->value;
8945 list = chainon (list, build_tree_list (NULL_TREE, id));
8946 c_parser_consume_token (parser);
8947 if (c_parser_next_token_is (parser, CPP_COMMA))
8948 c_parser_consume_token (parser);
8952 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
8956 /* Parse an objc-try-catch-finally-statement.
8958 objc-try-catch-finally-statement:
8959 @try compound-statement objc-catch-list[opt]
8960 @try compound-statement objc-catch-list[opt] @finally compound-statement
8963 @catch ( objc-catch-parameter-declaration ) compound-statement
8964 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8966 objc-catch-parameter-declaration:
8967 parameter-declaration
8970 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8972 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8973 for C++. Keep them in sync. */
8976 c_parser_objc_try_catch_finally_statement (c_parser *parser)
8978 location_t location;
8981 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
8982 c_parser_consume_token (parser);
8983 location = c_parser_peek_token (parser)->location;
8984 objc_maybe_warn_exceptions (location);
8985 stmt = c_parser_compound_statement (parser);
8986 objc_begin_try_stmt (location, stmt);
8988 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
8990 struct c_parm *parm;
8991 tree parameter_declaration = error_mark_node;
8992 bool seen_open_paren = false;
8994 c_parser_consume_token (parser);
8995 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8996 seen_open_paren = true;
8997 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
8999 /* We have "@catch (...)" (where the '...' are literally
9000 what is in the code). Skip the '...'.
9001 parameter_declaration is set to NULL_TREE, and
9002 objc_being_catch_clauses() knows that that means
9004 c_parser_consume_token (parser);
9005 parameter_declaration = NULL_TREE;
9009 /* We have "@catch (NSException *exception)" or something
9010 like that. Parse the parameter declaration. */
9011 parm = c_parser_parameter_declaration (parser, NULL_TREE);
9013 parameter_declaration = error_mark_node;
9015 parameter_declaration = grokparm (parm, NULL);
9017 if (seen_open_paren)
9018 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9021 /* If there was no open parenthesis, we are recovering from
9022 an error, and we are trying to figure out what mistake
9023 the user has made. */
9025 /* If there is an immediate closing parenthesis, the user
9026 probably forgot the opening one (ie, they typed "@catch
9027 NSException *e)". Parse the closing parenthesis and keep
9029 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9030 c_parser_consume_token (parser);
9032 /* If these is no immediate closing parenthesis, the user
9033 probably doesn't know that parenthesis are required at
9034 all (ie, they typed "@catch NSException *e"). So, just
9035 forget about the closing parenthesis and keep going. */
9037 objc_begin_catch_clause (parameter_declaration);
9038 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9039 c_parser_compound_statement_nostart (parser);
9040 objc_finish_catch_clause ();
9042 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
9044 c_parser_consume_token (parser);
9045 location = c_parser_peek_token (parser)->location;
9046 stmt = c_parser_compound_statement (parser);
9047 objc_build_finally_clause (location, stmt);
9049 objc_finish_try_stmt ();
9052 /* Parse an objc-synchronized-statement.
9054 objc-synchronized-statement:
9055 @synchronized ( expression ) compound-statement
9059 c_parser_objc_synchronized_statement (c_parser *parser)
9063 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
9064 c_parser_consume_token (parser);
9065 loc = c_parser_peek_token (parser)->location;
9066 objc_maybe_warn_exceptions (loc);
9067 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9069 struct c_expr ce = c_parser_expression (parser);
9070 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9072 expr = c_fully_fold (expr, false, NULL);
9073 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9076 expr = error_mark_node;
9077 stmt = c_parser_compound_statement (parser);
9078 objc_build_synchronized (loc, expr, stmt);
9081 /* Parse an objc-selector; return NULL_TREE without an error if the
9082 next token is not an objc-selector.
9087 enum struct union if else while do for switch case default
9088 break continue return goto asm sizeof typeof __alignof
9089 unsigned long const short volatile signed restrict _Complex
9090 in out inout bycopy byref oneway int char float double void _Bool
9093 ??? Why this selection of keywords but not, for example, storage
9094 class specifiers? */
9097 c_parser_objc_selector (c_parser *parser)
9099 c_token *token = c_parser_peek_token (parser);
9100 tree value = token->value;
9101 if (token->type == CPP_NAME)
9103 c_parser_consume_token (parser);
9106 if (token->type != CPP_KEYWORD)
9108 switch (token->keyword)
9155 c_parser_consume_token (parser);
9162 /* Parse an objc-selector-arg.
9166 objc-keywordname-list
9168 objc-keywordname-list:
9170 objc-keywordname-list objc-keywordname
9178 c_parser_objc_selector_arg (c_parser *parser)
9180 tree sel = c_parser_objc_selector (parser);
9181 tree list = NULL_TREE;
9182 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9186 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9188 list = chainon (list, build_tree_list (sel, NULL_TREE));
9189 sel = c_parser_objc_selector (parser);
9190 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9196 /* Parse an objc-receiver.
9205 c_parser_objc_receiver (c_parser *parser)
9207 location_t loc = c_parser_peek_token (parser)->location;
9209 if (c_parser_peek_token (parser)->type == CPP_NAME
9210 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
9211 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
9213 tree id = c_parser_peek_token (parser)->value;
9214 c_parser_consume_token (parser);
9215 return objc_get_class_reference (id);
9217 struct c_expr ce = c_parser_expression (parser);
9218 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
9219 return c_fully_fold (ce.value, false, NULL);
9222 /* Parse objc-message-args.
9226 objc-keywordarg-list
9228 objc-keywordarg-list:
9230 objc-keywordarg-list objc-keywordarg
9233 objc-selector : objc-keywordexpr
9238 c_parser_objc_message_args (c_parser *parser)
9240 tree sel = c_parser_objc_selector (parser);
9241 tree list = NULL_TREE;
9242 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
9247 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9248 return error_mark_node;
9249 keywordexpr = c_parser_objc_keywordexpr (parser);
9250 list = chainon (list, build_tree_list (sel, keywordexpr));
9251 sel = c_parser_objc_selector (parser);
9252 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
9258 /* Parse an objc-keywordexpr.
9265 c_parser_objc_keywordexpr (c_parser *parser)
9268 vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
9269 NULL, NULL, NULL, NULL);
9270 if (vec_safe_length (expr_list) == 1)
9272 /* Just return the expression, remove a level of
9274 ret = (*expr_list)[0];
9278 /* We have a comma expression, we will collapse later. */
9279 ret = build_tree_list_vec (expr_list);
9281 release_tree_vector (expr_list);
9285 /* A check, needed in several places, that ObjC interface, implementation or
9286 method definitions are not prefixed by incorrect items. */
9288 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
9289 struct c_declspecs *specs)
9291 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
9292 || specs->typespec_kind != ctsk_none)
9294 c_parser_error (parser,
9295 "no type or storage class may be specified here,");
9296 c_parser_skip_to_end_of_block_or_statement (parser);
9302 /* Parse an Objective-C @property declaration. The syntax is:
9304 objc-property-declaration:
9305 '@property' objc-property-attributes[opt] struct-declaration ;
9307 objc-property-attributes:
9308 '(' objc-property-attribute-list ')'
9310 objc-property-attribute-list:
9311 objc-property-attribute
9312 objc-property-attribute-list, objc-property-attribute
9314 objc-property-attribute
9315 'getter' = identifier
9316 'setter' = identifier
9325 @property NSString *name;
9326 @property (readonly) id object;
9327 @property (retain, nonatomic, getter=getTheName) id name;
9328 @property int a, b, c;
9330 PS: This function is identical to cp_parser_objc_at_propery_declaration
9331 for C++. Keep them in sync. */
9333 c_parser_objc_at_property_declaration (c_parser *parser)
9335 /* The following variables hold the attributes of the properties as
9336 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9337 seen. When we see an attribute, we set them to 'true' (if they
9338 are boolean properties) or to the identifier (if they have an
9339 argument, ie, for getter and setter). Note that here we only
9340 parse the list of attributes, check the syntax and accumulate the
9341 attributes that we find. objc_add_property_declaration() will
9342 then process the information. */
9343 bool property_assign = false;
9344 bool property_copy = false;
9345 tree property_getter_ident = NULL_TREE;
9346 bool property_nonatomic = false;
9347 bool property_readonly = false;
9348 bool property_readwrite = false;
9349 bool property_retain = false;
9350 tree property_setter_ident = NULL_TREE;
9352 /* 'properties' is the list of properties that we read. Usually a
9353 single one, but maybe more (eg, in "@property int a, b, c;" there
9358 loc = c_parser_peek_token (parser)->location;
9359 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
9361 c_parser_consume_token (parser); /* Eat '@property'. */
9363 /* Parse the optional attribute list... */
9364 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9367 c_parser_consume_token (parser);
9369 /* Property attribute keywords are valid now. */
9370 parser->objc_property_attr_context = true;
9374 bool syntax_error = false;
9375 c_token *token = c_parser_peek_token (parser);
9378 if (token->type != CPP_KEYWORD)
9380 if (token->type == CPP_CLOSE_PAREN)
9381 c_parser_error (parser, "expected identifier");
9384 c_parser_consume_token (parser);
9385 c_parser_error (parser, "unknown property attribute");
9389 keyword = token->keyword;
9390 c_parser_consume_token (parser);
9393 case RID_ASSIGN: property_assign = true; break;
9394 case RID_COPY: property_copy = true; break;
9395 case RID_NONATOMIC: property_nonatomic = true; break;
9396 case RID_READONLY: property_readonly = true; break;
9397 case RID_READWRITE: property_readwrite = true; break;
9398 case RID_RETAIN: property_retain = true; break;
9402 if (c_parser_next_token_is_not (parser, CPP_EQ))
9404 if (keyword == RID_GETTER)
9405 c_parser_error (parser,
9406 "missing %<=%> (after %<getter%> attribute)");
9408 c_parser_error (parser,
9409 "missing %<=%> (after %<setter%> attribute)");
9410 syntax_error = true;
9413 c_parser_consume_token (parser); /* eat the = */
9414 if (c_parser_next_token_is_not (parser, CPP_NAME))
9416 c_parser_error (parser, "expected identifier");
9417 syntax_error = true;
9420 if (keyword == RID_SETTER)
9422 if (property_setter_ident != NULL_TREE)
9423 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
9425 property_setter_ident = c_parser_peek_token (parser)->value;
9426 c_parser_consume_token (parser);
9427 if (c_parser_next_token_is_not (parser, CPP_COLON))
9428 c_parser_error (parser, "setter name must terminate with %<:%>");
9430 c_parser_consume_token (parser);
9434 if (property_getter_ident != NULL_TREE)
9435 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
9437 property_getter_ident = c_parser_peek_token (parser)->value;
9438 c_parser_consume_token (parser);
9442 c_parser_error (parser, "unknown property attribute");
9443 syntax_error = true;
9450 if (c_parser_next_token_is (parser, CPP_COMMA))
9451 c_parser_consume_token (parser);
9455 parser->objc_property_attr_context = false;
9456 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9458 /* ... and the property declaration(s). */
9459 properties = c_parser_struct_declaration (parser);
9461 if (properties == error_mark_node)
9463 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9464 parser->error = false;
9468 if (properties == NULL_TREE)
9469 c_parser_error (parser, "expected identifier");
9472 /* Comma-separated properties are chained together in
9473 reverse order; add them one by one. */
9474 properties = nreverse (properties);
9476 for (; properties; properties = TREE_CHAIN (properties))
9477 objc_add_property_declaration (loc, copy_node (properties),
9478 property_readonly, property_readwrite,
9479 property_assign, property_retain,
9480 property_copy, property_nonatomic,
9481 property_getter_ident, property_setter_ident);
9484 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9485 parser->error = false;
9488 /* Parse an Objective-C @synthesize declaration. The syntax is:
9490 objc-synthesize-declaration:
9491 @synthesize objc-synthesize-identifier-list ;
9493 objc-synthesize-identifier-list:
9494 objc-synthesize-identifier
9495 objc-synthesize-identifier-list, objc-synthesize-identifier
9497 objc-synthesize-identifier
9499 identifier = identifier
9502 @synthesize MyProperty;
9503 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9505 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9506 for C++. Keep them in sync.
9509 c_parser_objc_at_synthesize_declaration (c_parser *parser)
9511 tree list = NULL_TREE;
9513 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
9514 loc = c_parser_peek_token (parser)->location;
9516 c_parser_consume_token (parser);
9519 tree property, ivar;
9520 if (c_parser_next_token_is_not (parser, CPP_NAME))
9522 c_parser_error (parser, "expected identifier");
9523 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9524 /* Once we find the semicolon, we can resume normal parsing.
9525 We have to reset parser->error manually because
9526 c_parser_skip_until_found() won't reset it for us if the
9527 next token is precisely a semicolon. */
9528 parser->error = false;
9531 property = c_parser_peek_token (parser)->value;
9532 c_parser_consume_token (parser);
9533 if (c_parser_next_token_is (parser, CPP_EQ))
9535 c_parser_consume_token (parser);
9536 if (c_parser_next_token_is_not (parser, CPP_NAME))
9538 c_parser_error (parser, "expected identifier");
9539 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9540 parser->error = false;
9543 ivar = c_parser_peek_token (parser)->value;
9544 c_parser_consume_token (parser);
9548 list = chainon (list, build_tree_list (ivar, property));
9549 if (c_parser_next_token_is (parser, CPP_COMMA))
9550 c_parser_consume_token (parser);
9554 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9555 objc_add_synthesize_declaration (loc, list);
9558 /* Parse an Objective-C @dynamic declaration. The syntax is:
9560 objc-dynamic-declaration:
9561 @dynamic identifier-list ;
9564 @dynamic MyProperty;
9565 @dynamic MyProperty, AnotherProperty;
9567 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9568 for C++. Keep them in sync.
9571 c_parser_objc_at_dynamic_declaration (c_parser *parser)
9573 tree list = NULL_TREE;
9575 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
9576 loc = c_parser_peek_token (parser)->location;
9578 c_parser_consume_token (parser);
9582 if (c_parser_next_token_is_not (parser, CPP_NAME))
9584 c_parser_error (parser, "expected identifier");
9585 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9586 parser->error = false;
9589 property = c_parser_peek_token (parser)->value;
9590 list = chainon (list, build_tree_list (NULL_TREE, property));
9591 c_parser_consume_token (parser);
9592 if (c_parser_next_token_is (parser, CPP_COMMA))
9593 c_parser_consume_token (parser);
9597 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9598 objc_add_dynamic_declaration (loc, list);
9602 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9603 should be considered, statements. ALLOW_STMT is true if we're within
9604 the context of a function and such pragmas are to be allowed. Returns
9605 true if we actually parsed such a pragma. */
9608 c_parser_pragma (c_parser *parser, enum pragma_context context)
9612 id = c_parser_peek_token (parser)->pragma_kind;
9613 gcc_assert (id != PRAGMA_NONE);
9617 case PRAGMA_OACC_ENTER_DATA:
9618 c_parser_oacc_enter_exit_data (parser, true);
9621 case PRAGMA_OACC_EXIT_DATA:
9622 c_parser_oacc_enter_exit_data (parser, false);
9625 case PRAGMA_OACC_UPDATE:
9626 if (context != pragma_compound)
9628 if (context == pragma_stmt)
9629 c_parser_error (parser, "%<#pragma acc update%> may only be "
9630 "used in compound statements");
9633 c_parser_oacc_update (parser);
9636 case PRAGMA_OMP_BARRIER:
9637 if (context != pragma_compound)
9639 if (context == pragma_stmt)
9640 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
9641 "used in compound statements");
9644 c_parser_omp_barrier (parser);
9647 case PRAGMA_OMP_FLUSH:
9648 if (context != pragma_compound)
9650 if (context == pragma_stmt)
9651 c_parser_error (parser, "%<#pragma omp flush%> may only be "
9652 "used in compound statements");
9655 c_parser_omp_flush (parser);
9658 case PRAGMA_OMP_TASKWAIT:
9659 if (context != pragma_compound)
9661 if (context == pragma_stmt)
9662 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
9663 "used in compound statements");
9666 c_parser_omp_taskwait (parser);
9669 case PRAGMA_OMP_TASKYIELD:
9670 if (context != pragma_compound)
9672 if (context == pragma_stmt)
9673 c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
9674 "used in compound statements");
9677 c_parser_omp_taskyield (parser);
9680 case PRAGMA_OMP_CANCEL:
9681 if (context != pragma_compound)
9683 if (context == pragma_stmt)
9684 c_parser_error (parser, "%<#pragma omp cancel%> may only be "
9685 "used in compound statements");
9688 c_parser_omp_cancel (parser);
9691 case PRAGMA_OMP_CANCELLATION_POINT:
9692 if (context != pragma_compound)
9694 if (context == pragma_stmt)
9695 c_parser_error (parser, "%<#pragma omp cancellation point%> may "
9696 "only be used in compound statements");
9699 c_parser_omp_cancellation_point (parser);
9702 case PRAGMA_OMP_THREADPRIVATE:
9703 c_parser_omp_threadprivate (parser);
9706 case PRAGMA_OMP_TARGET:
9707 return c_parser_omp_target (parser, context);
9709 case PRAGMA_OMP_END_DECLARE_TARGET:
9710 c_parser_omp_end_declare_target (parser);
9713 case PRAGMA_OMP_SECTION:
9714 error_at (c_parser_peek_token (parser)->location,
9715 "%<#pragma omp section%> may only be used in "
9716 "%<#pragma omp sections%> construct");
9717 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9720 case PRAGMA_OMP_DECLARE_REDUCTION:
9721 c_parser_omp_declare (parser, context);
9724 c_parser_consume_pragma (parser);
9725 c_parser_skip_to_pragma_eol (parser);
9726 if (!c_parser_next_token_is_keyword (parser, RID_FOR)
9727 && !c_parser_next_token_is_keyword (parser, RID_WHILE)
9728 && !c_parser_next_token_is_keyword (parser, RID_DO))
9730 c_parser_error (parser, "for, while or do statement expected");
9733 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9734 c_parser_for_statement (parser, true);
9735 else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
9736 c_parser_while_statement (parser, true);
9738 c_parser_do_statement (parser, true);
9741 case PRAGMA_GCC_PCH_PREPROCESS:
9742 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
9743 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9746 case PRAGMA_CILK_SIMD:
9747 if (!c_parser_cilk_verify_simd (parser, context))
9749 c_parser_consume_pragma (parser);
9750 c_parser_cilk_simd (parser);
9752 case PRAGMA_CILK_GRAINSIZE:
9755 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9757 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9760 if (context == pragma_external)
9762 error_at (c_parser_peek_token (parser)->location,
9763 "%<#pragma grainsize%> must be inside a function");
9764 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9767 c_parser_cilk_grainsize (parser);
9771 if (id < PRAGMA_FIRST_EXTERNAL)
9773 if (context != pragma_stmt && context != pragma_compound)
9776 c_parser_error (parser, "expected declaration specifiers");
9777 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
9780 c_parser_omp_construct (parser);
9786 c_parser_consume_pragma (parser);
9787 c_invoke_pragma_handler (id);
9789 /* Skip to EOL, but suppress any error message. Those will have been
9790 generated by the handler routine through calling error, as opposed
9791 to calling c_parser_error. */
9792 parser->error = true;
9793 c_parser_skip_to_pragma_eol (parser);
9798 /* The interface the pragma parsers have to the lexer. */
9801 pragma_lex (tree *value)
9803 c_token *tok = c_parser_peek_token (the_parser);
9804 enum cpp_ttype ret = tok->type;
9806 *value = tok->value;
9807 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
9811 if (ret == CPP_KEYWORD)
9813 c_parser_consume_token (the_parser);
9820 c_parser_pragma_pch_preprocess (c_parser *parser)
9824 c_parser_consume_pragma (parser);
9825 if (c_parser_next_token_is (parser, CPP_STRING))
9827 name = c_parser_peek_token (parser)->value;
9828 c_parser_consume_token (parser);
9831 c_parser_error (parser, "expected string literal");
9832 c_parser_skip_to_pragma_eol (parser);
9835 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
9838 /* OpenACC and OpenMP parsing routines. */
9840 /* Returns name of the next clause.
9841 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9842 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9843 returned and the token is consumed. */
9845 static pragma_omp_clause
9846 c_parser_omp_clause_name (c_parser *parser)
9848 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
9850 if (c_parser_next_token_is_keyword (parser, RID_AUTO))
9851 result = PRAGMA_OACC_CLAUSE_AUTO;
9852 else if (c_parser_next_token_is_keyword (parser, RID_IF))
9853 result = PRAGMA_OMP_CLAUSE_IF;
9854 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
9855 result = PRAGMA_OMP_CLAUSE_DEFAULT;
9856 else if (c_parser_next_token_is_keyword (parser, RID_FOR))
9857 result = PRAGMA_OMP_CLAUSE_FOR;
9858 else if (c_parser_next_token_is (parser, CPP_NAME))
9860 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9865 if (!strcmp ("aligned", p))
9866 result = PRAGMA_OMP_CLAUSE_ALIGNED;
9867 else if (!strcmp ("async", p))
9868 result = PRAGMA_OACC_CLAUSE_ASYNC;
9871 if (!strcmp ("collapse", p))
9872 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
9873 else if (!strcmp ("copy", p))
9874 result = PRAGMA_OACC_CLAUSE_COPY;
9875 else if (!strcmp ("copyin", p))
9876 result = PRAGMA_OMP_CLAUSE_COPYIN;
9877 else if (!strcmp ("copyout", p))
9878 result = PRAGMA_OACC_CLAUSE_COPYOUT;
9879 else if (!strcmp ("copyprivate", p))
9880 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
9881 else if (!strcmp ("create", p))
9882 result = PRAGMA_OACC_CLAUSE_CREATE;
9885 if (!strcmp ("delete", p))
9886 result = PRAGMA_OACC_CLAUSE_DELETE;
9887 else if (!strcmp ("depend", p))
9888 result = PRAGMA_OMP_CLAUSE_DEPEND;
9889 else if (!strcmp ("device", p))
9890 result = PRAGMA_OMP_CLAUSE_DEVICE;
9891 else if (!strcmp ("deviceptr", p))
9892 result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
9893 else if (!strcmp ("dist_schedule", p))
9894 result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
9897 if (!strcmp ("final", p))
9898 result = PRAGMA_OMP_CLAUSE_FINAL;
9899 else if (!strcmp ("firstprivate", p))
9900 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
9901 else if (!strcmp ("from", p))
9902 result = PRAGMA_OMP_CLAUSE_FROM;
9905 if (!strcmp ("gang", p))
9906 result = PRAGMA_OACC_CLAUSE_GANG;
9909 if (!strcmp ("host", p))
9910 result = PRAGMA_OACC_CLAUSE_HOST;
9913 if (!strcmp ("inbranch", p))
9914 result = PRAGMA_OMP_CLAUSE_INBRANCH;
9917 if (!strcmp ("lastprivate", p))
9918 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
9919 else if (!strcmp ("linear", p))
9920 result = PRAGMA_OMP_CLAUSE_LINEAR;
9923 if (!strcmp ("map", p))
9924 result = PRAGMA_OMP_CLAUSE_MAP;
9925 else if (!strcmp ("mergeable", p))
9926 result = PRAGMA_OMP_CLAUSE_MERGEABLE;
9927 else if (flag_cilkplus && !strcmp ("mask", p))
9928 result = PRAGMA_CILK_CLAUSE_MASK;
9931 if (!strcmp ("notinbranch", p))
9932 result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
9933 else if (!strcmp ("nowait", p))
9934 result = PRAGMA_OMP_CLAUSE_NOWAIT;
9935 else if (!strcmp ("num_gangs", p))
9936 result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
9937 else if (!strcmp ("num_teams", p))
9938 result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
9939 else if (!strcmp ("num_threads", p))
9940 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
9941 else if (!strcmp ("num_workers", p))
9942 result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
9943 else if (flag_cilkplus && !strcmp ("nomask", p))
9944 result = PRAGMA_CILK_CLAUSE_NOMASK;
9947 if (!strcmp ("ordered", p))
9948 result = PRAGMA_OMP_CLAUSE_ORDERED;
9951 if (!strcmp ("parallel", p))
9952 result = PRAGMA_OMP_CLAUSE_PARALLEL;
9953 else if (!strcmp ("present", p))
9954 result = PRAGMA_OACC_CLAUSE_PRESENT;
9955 else if (!strcmp ("present_or_copy", p)
9956 || !strcmp ("pcopy", p))
9957 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
9958 else if (!strcmp ("present_or_copyin", p)
9959 || !strcmp ("pcopyin", p))
9960 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
9961 else if (!strcmp ("present_or_copyout", p)
9962 || !strcmp ("pcopyout", p))
9963 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
9964 else if (!strcmp ("present_or_create", p)
9965 || !strcmp ("pcreate", p))
9966 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
9967 else if (!strcmp ("private", p))
9968 result = PRAGMA_OMP_CLAUSE_PRIVATE;
9969 else if (!strcmp ("proc_bind", p))
9970 result = PRAGMA_OMP_CLAUSE_PROC_BIND;
9973 if (!strcmp ("reduction", p))
9974 result = PRAGMA_OMP_CLAUSE_REDUCTION;
9977 if (!strcmp ("safelen", p))
9978 result = PRAGMA_OMP_CLAUSE_SAFELEN;
9979 else if (!strcmp ("schedule", p))
9980 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
9981 else if (!strcmp ("sections", p))
9982 result = PRAGMA_OMP_CLAUSE_SECTIONS;
9983 else if (!strcmp ("seq", p))
9984 result = PRAGMA_OACC_CLAUSE_SEQ;
9985 else if (!strcmp ("shared", p))
9986 result = PRAGMA_OMP_CLAUSE_SHARED;
9987 else if (!strcmp ("simdlen", p))
9988 result = PRAGMA_OMP_CLAUSE_SIMDLEN;
9989 else if (!strcmp ("self", p))
9990 result = PRAGMA_OACC_CLAUSE_SELF;
9993 if (!strcmp ("taskgroup", p))
9994 result = PRAGMA_OMP_CLAUSE_TASKGROUP;
9995 else if (!strcmp ("thread_limit", p))
9996 result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
9997 else if (!strcmp ("to", p))
9998 result = PRAGMA_OMP_CLAUSE_TO;
10001 if (!strcmp ("uniform", p))
10002 result = PRAGMA_OMP_CLAUSE_UNIFORM;
10003 else if (!strcmp ("untied", p))
10004 result = PRAGMA_OMP_CLAUSE_UNTIED;
10007 if (!strcmp ("vector", p))
10008 result = PRAGMA_OACC_CLAUSE_VECTOR;
10009 else if (!strcmp ("vector_length", p))
10010 result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
10011 else if (flag_cilkplus && !strcmp ("vectorlength", p))
10012 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
10015 if (!strcmp ("wait", p))
10016 result = PRAGMA_OACC_CLAUSE_WAIT;
10017 else if (!strcmp ("worker", p))
10018 result = PRAGMA_OACC_CLAUSE_WORKER;
10023 if (result != PRAGMA_OMP_CLAUSE_NONE)
10024 c_parser_consume_token (parser);
10029 /* Validate that a clause of the given type does not already exist. */
10032 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
10037 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
10038 if (OMP_CLAUSE_CODE (c) == code)
10040 location_t loc = OMP_CLAUSE_LOCATION (c);
10041 error_at (loc, "too many %qs clauses", name);
10047 Parse wait clause or wait directive parameters. */
10050 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
10052 vec<tree, va_gc> *args;
10055 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10058 args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
10060 if (args->length () == 0)
10062 c_parser_error (parser, "expected integer expression before ')'");
10063 release_tree_vector (args);
10067 args_tree = build_tree_list_vec (args);
10069 for (t = args_tree; t; t = TREE_CHAIN (t))
10071 tree targ = TREE_VALUE (t);
10073 if (targ != error_mark_node)
10075 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
10077 c_parser_error (parser, "expression must be integral");
10078 targ = error_mark_node;
10082 tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
10084 OMP_CLAUSE_DECL (c) = targ;
10085 OMP_CLAUSE_CHAIN (c) = list;
10091 release_tree_vector (args);
10092 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10096 /* OpenACC 2.0, OpenMP 2.5:
10099 variable-list , identifier
10101 If KIND is nonzero, create the appropriate node and install the
10102 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10103 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10105 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10106 return the list created. */
10109 c_parser_omp_variable_list (c_parser *parser,
10110 location_t clause_loc,
10111 enum omp_clause_code kind, tree list)
10113 if (c_parser_next_token_is_not (parser, CPP_NAME)
10114 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
10115 c_parser_error (parser, "expected identifier");
10117 while (c_parser_next_token_is (parser, CPP_NAME)
10118 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
10120 tree t = lookup_name (c_parser_peek_token (parser)->value);
10122 if (t == NULL_TREE)
10124 undeclared_variable (c_parser_peek_token (parser)->location,
10125 c_parser_peek_token (parser)->value);
10126 t = error_mark_node;
10129 c_parser_consume_token (parser);
10131 if (t == error_mark_node)
10133 else if (kind != 0)
10137 case OMP_CLAUSE__CACHE_:
10138 if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
10140 c_parser_error (parser, "expected %<[%>");
10141 t = error_mark_node;
10144 /* FALL THROUGH. */
10145 case OMP_CLAUSE_MAP:
10146 case OMP_CLAUSE_FROM:
10147 case OMP_CLAUSE_TO:
10148 case OMP_CLAUSE_DEPEND:
10149 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
10151 tree low_bound = NULL_TREE, length = NULL_TREE;
10153 c_parser_consume_token (parser);
10154 if (!c_parser_next_token_is (parser, CPP_COLON))
10156 low_bound = c_parser_expression (parser).value;
10157 mark_exp_read (low_bound);
10159 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10160 length = integer_one_node;
10163 /* Look for `:'. */
10164 if (!c_parser_require (parser, CPP_COLON,
10167 t = error_mark_node;
10170 if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
10172 length = c_parser_expression (parser).value;
10173 mark_exp_read (length);
10176 /* Look for the closing `]'. */
10177 if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
10180 t = error_mark_node;
10184 if (kind == OMP_CLAUSE__CACHE_)
10186 if (TREE_CODE (low_bound) != INTEGER_CST
10187 && !TREE_READONLY (low_bound))
10189 error_at (clause_loc,
10190 "%qD is not a constant", low_bound);
10191 t = error_mark_node;
10194 if (TREE_CODE (length) != INTEGER_CST
10195 && !TREE_READONLY (length))
10197 error_at (clause_loc,
10198 "%qD is not a constant", length);
10199 t = error_mark_node;
10203 t = tree_cons (low_bound, length, t);
10210 if (t != error_mark_node)
10212 tree u = build_omp_clause (clause_loc, kind);
10213 OMP_CLAUSE_DECL (u) = t;
10214 OMP_CLAUSE_CHAIN (u) = list;
10219 list = tree_cons (t, NULL_TREE, list);
10221 if (c_parser_next_token_is_not (parser, CPP_COMMA))
10224 c_parser_consume_token (parser);
10230 /* Similarly, but expect leading and trailing parenthesis. This is a very
10231 common case for OpenACC and OpenMP clauses. */
10234 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
10237 /* The clauses location. */
10238 location_t loc = c_parser_peek_token (parser)->location;
10240 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10242 list = c_parser_omp_variable_list (parser, loc, kind, list);
10243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10249 copy ( variable-list )
10250 copyin ( variable-list )
10251 copyout ( variable-list )
10252 create ( variable-list )
10253 delete ( variable-list )
10254 present ( variable-list )
10255 present_or_copy ( variable-list )
10256 pcopy ( variable-list )
10257 present_or_copyin ( variable-list )
10258 pcopyin ( variable-list )
10259 present_or_copyout ( variable-list )
10260 pcopyout ( variable-list )
10261 present_or_create ( variable-list )
10262 pcreate ( variable-list ) */
10265 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
10268 enum gomp_map_kind kind;
10271 case PRAGMA_OACC_CLAUSE_COPY:
10272 kind = GOMP_MAP_FORCE_TOFROM;
10274 case PRAGMA_OACC_CLAUSE_COPYIN:
10275 kind = GOMP_MAP_FORCE_TO;
10277 case PRAGMA_OACC_CLAUSE_COPYOUT:
10278 kind = GOMP_MAP_FORCE_FROM;
10280 case PRAGMA_OACC_CLAUSE_CREATE:
10281 kind = GOMP_MAP_FORCE_ALLOC;
10283 case PRAGMA_OACC_CLAUSE_DELETE:
10284 kind = GOMP_MAP_FORCE_DEALLOC;
10286 case PRAGMA_OACC_CLAUSE_DEVICE:
10287 kind = GOMP_MAP_FORCE_TO;
10289 case PRAGMA_OACC_CLAUSE_HOST:
10290 case PRAGMA_OACC_CLAUSE_SELF:
10291 kind = GOMP_MAP_FORCE_FROM;
10293 case PRAGMA_OACC_CLAUSE_PRESENT:
10294 kind = GOMP_MAP_FORCE_PRESENT;
10296 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
10297 kind = GOMP_MAP_TOFROM;
10299 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
10300 kind = GOMP_MAP_TO;
10302 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
10303 kind = GOMP_MAP_FROM;
10305 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
10306 kind = GOMP_MAP_ALLOC;
10309 gcc_unreachable ();
10312 nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
10314 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10315 OMP_CLAUSE_SET_MAP_KIND (c, kind);
10321 deviceptr ( variable-list ) */
10324 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
10326 location_t loc = c_parser_peek_token (parser)->location;
10329 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10330 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10331 variable-list must only allow for pointer variables. */
10332 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10333 for (t = vars; t && t; t = TREE_CHAIN (t))
10335 tree v = TREE_PURPOSE (t);
10337 /* FIXME diagnostics: Ideally we should keep individual
10338 locations for all the variables in the var list to make the
10339 following errors more precise. Perhaps
10340 c_parser_omp_var_list_parens() should construct a list of
10341 locations to go along with the var list. */
10343 if (TREE_CODE (v) != VAR_DECL)
10344 error_at (loc, "%qD is not a variable", v);
10345 else if (TREE_TYPE (v) == error_mark_node)
10347 else if (!POINTER_TYPE_P (TREE_TYPE (v)))
10348 error_at (loc, "%qD is not a pointer variable", v);
10350 tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
10351 OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
10352 OMP_CLAUSE_DECL (u) = v;
10353 OMP_CLAUSE_CHAIN (u) = list;
10360 /* OpenACC 2.0, OpenMP 3.0:
10361 collapse ( constant-expression ) */
10364 c_parser_omp_clause_collapse (c_parser *parser, tree list)
10366 tree c, num = error_mark_node;
10370 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
10372 loc = c_parser_peek_token (parser)->location;
10373 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10375 num = c_parser_expr_no_commas (parser, NULL).value;
10376 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10378 if (num == error_mark_node)
10380 mark_exp_read (num);
10381 num = c_fully_fold (num, false, NULL);
10382 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
10383 || !tree_fits_shwi_p (num)
10384 || (n = tree_to_shwi (num)) <= 0
10388 "collapse argument needs positive constant integer expression");
10391 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
10392 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
10393 OMP_CLAUSE_CHAIN (c) = list;
10398 copyin ( variable-list ) */
10401 c_parser_omp_clause_copyin (c_parser *parser, tree list)
10403 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
10407 copyprivate ( variable-list ) */
10410 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
10412 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
10416 default ( shared | none ) */
10419 c_parser_omp_clause_default (c_parser *parser, tree list)
10421 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
10422 location_t loc = c_parser_peek_token (parser)->location;
10425 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10427 if (c_parser_next_token_is (parser, CPP_NAME))
10429 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10434 if (strcmp ("none", p) != 0)
10436 kind = OMP_CLAUSE_DEFAULT_NONE;
10440 if (strcmp ("shared", p) != 0)
10442 kind = OMP_CLAUSE_DEFAULT_SHARED;
10449 c_parser_consume_token (parser);
10454 c_parser_error (parser, "expected %<none%> or %<shared%>");
10456 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10458 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
10461 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
10462 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
10463 OMP_CLAUSE_CHAIN (c) = list;
10464 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
10470 firstprivate ( variable-list ) */
10473 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
10475 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
10479 final ( expression ) */
10482 c_parser_omp_clause_final (c_parser *parser, tree list)
10484 location_t loc = c_parser_peek_token (parser)->location;
10485 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10487 tree t = c_parser_paren_condition (parser);
10490 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
10492 c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
10493 OMP_CLAUSE_FINAL_EXPR (c) = t;
10494 OMP_CLAUSE_CHAIN (c) = list;
10498 c_parser_error (parser, "expected %<(%>");
10503 /* OpenACC, OpenMP 2.5:
10504 if ( expression ) */
10507 c_parser_omp_clause_if (c_parser *parser, tree list)
10509 location_t loc = c_parser_peek_token (parser)->location;
10510 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10512 tree t = c_parser_paren_condition (parser);
10515 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
10517 c = build_omp_clause (loc, OMP_CLAUSE_IF);
10518 OMP_CLAUSE_IF_EXPR (c) = t;
10519 OMP_CLAUSE_CHAIN (c) = list;
10523 c_parser_error (parser, "expected %<(%>");
10529 lastprivate ( variable-list ) */
10532 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
10534 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
10541 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10545 /* FIXME: Should we allow duplicates? */
10546 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
10548 c = build_omp_clause (c_parser_peek_token (parser)->location,
10549 OMP_CLAUSE_MERGEABLE);
10550 OMP_CLAUSE_CHAIN (c) = list;
10559 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10562 location_t loc = c_parser_peek_token (parser)->location;
10564 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
10566 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
10567 OMP_CLAUSE_CHAIN (c) = list;
10572 num_gangs ( expression ) */
10575 c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
10577 location_t num_gangs_loc = c_parser_peek_token (parser)->location;
10578 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10580 location_t expr_loc = c_parser_peek_token (parser)->location;
10581 tree c, t = c_parser_expression (parser).value;
10583 t = c_fully_fold (t, false, NULL);
10585 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10587 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10589 c_parser_error (parser, "expected integer expression");
10593 /* Attempt to statically determine when the number isn't positive. */
10594 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10595 build_int_cst (TREE_TYPE (t), 0));
10596 if (CAN_HAVE_LOCATION_P (c))
10597 SET_EXPR_LOCATION (c, expr_loc);
10598 if (c == boolean_true_node)
10600 warning_at (expr_loc, 0,
10601 "%<num_gangs%> value must be positive");
10602 t = integer_one_node;
10605 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
10607 c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
10608 OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
10609 OMP_CLAUSE_CHAIN (c) = list;
10617 num_threads ( expression ) */
10620 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
10622 location_t num_threads_loc = c_parser_peek_token (parser)->location;
10623 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10625 location_t expr_loc = c_parser_peek_token (parser)->location;
10626 tree c, t = c_parser_expression (parser).value;
10628 t = c_fully_fold (t, false, NULL);
10630 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10632 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10634 c_parser_error (parser, "expected integer expression");
10638 /* Attempt to statically determine when the number isn't positive. */
10639 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10640 build_int_cst (TREE_TYPE (t), 0));
10641 if (CAN_HAVE_LOCATION_P (c))
10642 SET_EXPR_LOCATION (c, expr_loc);
10643 if (c == boolean_true_node)
10645 warning_at (expr_loc, 0,
10646 "%<num_threads%> value must be positive");
10647 t = integer_one_node;
10650 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
10652 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
10653 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
10654 OMP_CLAUSE_CHAIN (c) = list;
10662 num_workers ( expression ) */
10665 c_parser_omp_clause_num_workers (c_parser *parser, tree list)
10667 location_t num_workers_loc = c_parser_peek_token (parser)->location;
10668 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10670 location_t expr_loc = c_parser_peek_token (parser)->location;
10671 tree c, t = c_parser_expression (parser).value;
10673 t = c_fully_fold (t, false, NULL);
10675 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10677 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10679 c_parser_error (parser, "expected integer expression");
10683 /* Attempt to statically determine when the number isn't positive. */
10684 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
10685 build_int_cst (TREE_TYPE (t), 0));
10686 if (CAN_HAVE_LOCATION_P (c))
10687 SET_EXPR_LOCATION (c, expr_loc);
10688 if (c == boolean_true_node)
10690 warning_at (expr_loc, 0,
10691 "%<num_workers%> value must be positive");
10692 t = integer_one_node;
10695 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
10697 c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
10698 OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
10699 OMP_CLAUSE_CHAIN (c) = list;
10707 async [( int-expr )] */
10710 c_parser_oacc_clause_async (c_parser *parser, tree list)
10713 location_t loc = c_parser_peek_token (parser)->location;
10715 t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
10717 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
10719 c_parser_consume_token (parser);
10721 t = c_parser_expression (parser).value;
10722 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
10723 c_parser_error (parser, "expected integer expression");
10724 else if (t == error_mark_node
10725 || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
10729 t = c_fully_fold (t, false, NULL);
10731 check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
10733 c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
10734 OMP_CLAUSE_ASYNC_EXPR (c) = t;
10735 OMP_CLAUSE_CHAIN (c) = list;
10742 wait ( int-expr-list ) */
10745 c_parser_oacc_clause_wait (c_parser *parser, tree list)
10747 location_t clause_loc = c_parser_peek_token (parser)->location;
10749 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
10750 list = c_parser_oacc_wait_list (parser, clause_loc, list);
10759 c_parser_omp_clause_ordered (c_parser *parser, tree list)
10763 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
10765 c = build_omp_clause (c_parser_peek_token (parser)->location,
10766 OMP_CLAUSE_ORDERED);
10767 OMP_CLAUSE_CHAIN (c) = list;
10773 private ( variable-list ) */
10776 c_parser_omp_clause_private (c_parser *parser, tree list)
10778 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
10782 reduction ( reduction-operator : variable-list )
10784 reduction-operator:
10785 One of: + * - & ^ | && ||
10789 reduction-operator:
10790 One of: + * - & ^ | && || max min
10794 reduction-operator:
10795 One of: + * - & ^ | && ||
10799 c_parser_omp_clause_reduction (c_parser *parser, tree list)
10801 location_t clause_loc = c_parser_peek_token (parser)->location;
10802 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10804 enum tree_code code = ERROR_MARK;
10805 tree reduc_id = NULL_TREE;
10807 switch (c_parser_peek_token (parser)->type)
10819 code = BIT_AND_EXPR;
10822 code = BIT_XOR_EXPR;
10825 code = BIT_IOR_EXPR;
10828 code = TRUTH_ANDIF_EXPR;
10831 code = TRUTH_ORIF_EXPR;
10836 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10837 if (strcmp (p, "min") == 0)
10842 if (strcmp (p, "max") == 0)
10847 reduc_id = c_parser_peek_token (parser)->value;
10851 c_parser_error (parser,
10852 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10853 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10854 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10857 c_parser_consume_token (parser);
10858 reduc_id = c_omp_reduction_id (code, reduc_id);
10859 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10863 nl = c_parser_omp_variable_list (parser, clause_loc,
10864 OMP_CLAUSE_REDUCTION, list);
10865 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
10867 tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
10868 OMP_CLAUSE_REDUCTION_CODE (c) = code;
10869 if (code == ERROR_MARK
10870 || !(INTEGRAL_TYPE_P (type)
10871 || TREE_CODE (type) == REAL_TYPE
10872 || TREE_CODE (type) == COMPLEX_TYPE))
10873 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
10874 = c_omp_reduction_lookup (reduc_id,
10875 TYPE_MAIN_VARIANT (type));
10880 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10886 schedule ( schedule-kind )
10887 schedule ( schedule-kind , expression )
10890 static | dynamic | guided | runtime | auto
10894 c_parser_omp_clause_schedule (c_parser *parser, tree list)
10897 location_t loc = c_parser_peek_token (parser)->location;
10899 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
10902 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
10904 if (c_parser_next_token_is (parser, CPP_NAME))
10906 tree kind = c_parser_peek_token (parser)->value;
10907 const char *p = IDENTIFIER_POINTER (kind);
10912 if (strcmp ("dynamic", p) != 0)
10914 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
10918 if (strcmp ("guided", p) != 0)
10920 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
10924 if (strcmp ("runtime", p) != 0)
10926 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
10933 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
10934 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
10935 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
10936 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
10940 c_parser_consume_token (parser);
10941 if (c_parser_next_token_is (parser, CPP_COMMA))
10944 c_parser_consume_token (parser);
10946 here = c_parser_peek_token (parser)->location;
10947 t = c_parser_expr_no_commas (parser, NULL).value;
10949 t = c_fully_fold (t, false, NULL);
10951 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
10952 error_at (here, "schedule %<runtime%> does not take "
10953 "a %<chunk_size%> parameter");
10954 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
10956 "schedule %<auto%> does not take "
10957 "a %<chunk_size%> parameter");
10958 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
10959 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
10961 c_parser_error (parser, "expected integer expression");
10963 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
10966 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
10967 "expected %<,%> or %<)%>");
10969 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
10970 OMP_CLAUSE_CHAIN (c) = list;
10974 c_parser_error (parser, "invalid schedule kind");
10975 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
10980 shared ( variable-list ) */
10983 c_parser_omp_clause_shared (c_parser *parser, tree list)
10985 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
10992 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
10996 /* FIXME: Should we allow duplicates? */
10997 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
10999 c = build_omp_clause (c_parser_peek_token (parser)->location,
11000 OMP_CLAUSE_UNTIED);
11001 OMP_CLAUSE_CHAIN (c) = list;
11007 vector_length ( expression ) */
11010 c_parser_omp_clause_vector_length (c_parser *parser, tree list)
11012 location_t vector_length_loc = c_parser_peek_token (parser)->location;
11013 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11015 location_t expr_loc = c_parser_peek_token (parser)->location;
11016 tree c, t = c_parser_expression (parser).value;
11018 t = c_fully_fold (t, false, NULL);
11020 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11022 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11024 c_parser_error (parser, "expected integer expression");
11028 /* Attempt to statically determine when the number isn't positive. */
11029 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11030 build_int_cst (TREE_TYPE (t), 0));
11031 if (CAN_HAVE_LOCATION_P (c))
11032 SET_EXPR_LOCATION (c, expr_loc);
11033 if (c == boolean_true_node)
11035 warning_at (expr_loc, 0,
11036 "%<vector_length%> value must be positive");
11037 t = integer_one_node;
11040 check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
11042 c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
11043 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
11044 OMP_CLAUSE_CHAIN (c) = list;
11056 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
11057 enum omp_clause_code code, tree list)
11059 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
11061 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11062 OMP_CLAUSE_CHAIN (c) = list;
11074 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
11075 enum omp_clause_code code, tree list)
11077 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
11078 OMP_CLAUSE_CHAIN (c) = list;
11084 num_teams ( expression ) */
11087 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
11089 location_t num_teams_loc = c_parser_peek_token (parser)->location;
11090 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11092 location_t expr_loc = c_parser_peek_token (parser)->location;
11093 tree c, t = c_parser_expression (parser).value;
11095 t = c_fully_fold (t, false, NULL);
11097 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11099 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11101 c_parser_error (parser, "expected integer expression");
11105 /* Attempt to statically determine when the number isn't positive. */
11106 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11107 build_int_cst (TREE_TYPE (t), 0));
11108 if (CAN_HAVE_LOCATION_P (c))
11109 SET_EXPR_LOCATION (c, expr_loc);
11110 if (c == boolean_true_node)
11112 warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
11113 t = integer_one_node;
11116 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
11118 c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
11119 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
11120 OMP_CLAUSE_CHAIN (c) = list;
11128 thread_limit ( expression ) */
11131 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
11133 location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
11134 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11136 location_t expr_loc = c_parser_peek_token (parser)->location;
11137 tree c, t = c_parser_expression (parser).value;
11139 t = c_fully_fold (t, false, NULL);
11141 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11143 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11145 c_parser_error (parser, "expected integer expression");
11149 /* Attempt to statically determine when the number isn't positive. */
11150 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
11151 build_int_cst (TREE_TYPE (t), 0));
11152 if (CAN_HAVE_LOCATION_P (c))
11153 SET_EXPR_LOCATION (c, expr_loc);
11154 if (c == boolean_true_node)
11156 warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
11157 t = integer_one_node;
11160 check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
11163 c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
11164 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
11165 OMP_CLAUSE_CHAIN (c) = list;
11173 aligned ( variable-list )
11174 aligned ( variable-list : constant-expression ) */
11177 c_parser_omp_clause_aligned (c_parser *parser, tree list)
11179 location_t clause_loc = c_parser_peek_token (parser)->location;
11182 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11185 nl = c_parser_omp_variable_list (parser, clause_loc,
11186 OMP_CLAUSE_ALIGNED, list);
11188 if (c_parser_next_token_is (parser, CPP_COLON))
11190 c_parser_consume_token (parser);
11191 tree alignment = c_parser_expr_no_commas (parser, NULL).value;
11192 mark_exp_read (alignment);
11193 alignment = c_fully_fold (alignment, false, NULL);
11194 if (TREE_CODE (alignment) != INTEGER_CST
11195 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
11196 || tree_int_cst_sgn (alignment) != 1)
11198 error_at (clause_loc, "%<aligned%> clause alignment expression must "
11199 "be positive constant integer expression");
11200 alignment = NULL_TREE;
11203 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11204 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
11207 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11212 linear ( variable-list )
11213 linear ( variable-list : expression ) */
11216 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn)
11218 location_t clause_loc = c_parser_peek_token (parser)->location;
11221 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11224 nl = c_parser_omp_variable_list (parser, clause_loc,
11225 OMP_CLAUSE_LINEAR, list);
11227 if (c_parser_next_token_is (parser, CPP_COLON))
11229 c_parser_consume_token (parser);
11230 step = c_parser_expression (parser).value;
11231 mark_exp_read (step);
11232 step = c_fully_fold (step, false, NULL);
11233 if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL)
11235 sorry ("using parameters for %<linear%> step is not supported yet");
11236 step = integer_one_node;
11238 if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
11240 error_at (clause_loc, "%<linear%> clause step expression must "
11242 step = integer_one_node;
11247 step = integer_one_node;
11249 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11251 OMP_CLAUSE_LINEAR_STEP (c) = step;
11254 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11259 safelen ( constant-expression ) */
11262 c_parser_omp_clause_safelen (c_parser *parser, tree list)
11264 location_t clause_loc = c_parser_peek_token (parser)->location;
11267 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11270 t = c_parser_expr_no_commas (parser, NULL).value;
11272 t = c_fully_fold (t, false, NULL);
11273 if (TREE_CODE (t) != INTEGER_CST
11274 || !INTEGRAL_TYPE_P (TREE_TYPE (t))
11275 || tree_int_cst_sgn (t) != 1)
11277 error_at (clause_loc, "%<safelen%> clause expression must "
11278 "be positive constant integer expression");
11282 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11283 if (t == NULL_TREE || t == error_mark_node)
11286 check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
11288 c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
11289 OMP_CLAUSE_SAFELEN_EXPR (c) = t;
11290 OMP_CLAUSE_CHAIN (c) = list;
11295 simdlen ( constant-expression ) */
11298 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
11300 location_t clause_loc = c_parser_peek_token (parser)->location;
11303 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11306 t = c_parser_expr_no_commas (parser, NULL).value;
11308 t = c_fully_fold (t, false, NULL);
11309 if (TREE_CODE (t) != INTEGER_CST
11310 || !INTEGRAL_TYPE_P (TREE_TYPE (t))
11311 || tree_int_cst_sgn (t) != 1)
11313 error_at (clause_loc, "%<simdlen%> clause expression must "
11314 "be positive constant integer expression");
11318 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11319 if (t == NULL_TREE || t == error_mark_node)
11322 check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
11324 c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
11325 OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
11326 OMP_CLAUSE_CHAIN (c) = list;
11331 depend ( depend-kind: variable-list )
11334 in | out | inout */
11337 c_parser_omp_clause_depend (c_parser *parser, tree list)
11339 location_t clause_loc = c_parser_peek_token (parser)->location;
11340 enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
11343 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11346 if (c_parser_next_token_is (parser, CPP_NAME))
11348 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11349 if (strcmp ("in", p) == 0)
11350 kind = OMP_CLAUSE_DEPEND_IN;
11351 else if (strcmp ("inout", p) == 0)
11352 kind = OMP_CLAUSE_DEPEND_INOUT;
11353 else if (strcmp ("out", p) == 0)
11354 kind = OMP_CLAUSE_DEPEND_OUT;
11361 c_parser_consume_token (parser);
11362 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
11365 nl = c_parser_omp_variable_list (parser, clause_loc,
11366 OMP_CLAUSE_DEPEND, list);
11368 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11369 OMP_CLAUSE_DEPEND_KIND (c) = kind;
11371 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11375 c_parser_error (parser, "invalid depend kind");
11377 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11382 map ( map-kind: variable-list )
11383 map ( variable-list )
11386 alloc | to | from | tofrom */
11389 c_parser_omp_clause_map (c_parser *parser, tree list)
11391 location_t clause_loc = c_parser_peek_token (parser)->location;
11392 enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11395 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11398 if (c_parser_next_token_is (parser, CPP_NAME)
11399 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11401 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11402 if (strcmp ("alloc", p) == 0)
11403 kind = GOMP_MAP_ALLOC;
11404 else if (strcmp ("to", p) == 0)
11405 kind = GOMP_MAP_TO;
11406 else if (strcmp ("from", p) == 0)
11407 kind = GOMP_MAP_FROM;
11408 else if (strcmp ("tofrom", p) == 0)
11409 kind = GOMP_MAP_TOFROM;
11412 c_parser_error (parser, "invalid map kind");
11413 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11417 c_parser_consume_token (parser);
11418 c_parser_consume_token (parser);
11421 nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
11423 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11424 OMP_CLAUSE_SET_MAP_KIND (c, kind);
11426 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11431 device ( expression ) */
11434 c_parser_omp_clause_device (c_parser *parser, tree list)
11436 location_t clause_loc = c_parser_peek_token (parser)->location;
11437 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11439 tree c, t = c_parser_expr_no_commas (parser, NULL).value;
11441 t = c_fully_fold (t, false, NULL);
11443 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11445 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
11447 c_parser_error (parser, "expected integer expression");
11451 check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
11453 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
11454 OMP_CLAUSE_DEVICE_ID (c) = t;
11455 OMP_CLAUSE_CHAIN (c) = list;
11463 dist_schedule ( static )
11464 dist_schedule ( static , expression ) */
11467 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
11469 tree c, t = NULL_TREE;
11470 location_t loc = c_parser_peek_token (parser)->location;
11472 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11475 if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
11477 c_parser_error (parser, "invalid dist_schedule kind");
11478 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11483 c_parser_consume_token (parser);
11484 if (c_parser_next_token_is (parser, CPP_COMMA))
11486 c_parser_consume_token (parser);
11488 t = c_parser_expr_no_commas (parser, NULL).value;
11490 t = c_fully_fold (t, false, NULL);
11491 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11494 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
11495 "expected %<,%> or %<)%>");
11497 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
11498 if (t == error_mark_node)
11501 c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
11502 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
11503 OMP_CLAUSE_CHAIN (c) = list;
11508 proc_bind ( proc-bind-kind )
11511 master | close | spread */
11514 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
11516 location_t clause_loc = c_parser_peek_token (parser)->location;
11517 enum omp_clause_proc_bind_kind kind;
11520 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11523 if (c_parser_next_token_is (parser, CPP_NAME))
11525 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11526 if (strcmp ("master", p) == 0)
11527 kind = OMP_CLAUSE_PROC_BIND_MASTER;
11528 else if (strcmp ("close", p) == 0)
11529 kind = OMP_CLAUSE_PROC_BIND_CLOSE;
11530 else if (strcmp ("spread", p) == 0)
11531 kind = OMP_CLAUSE_PROC_BIND_SPREAD;
11538 c_parser_consume_token (parser);
11539 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11540 c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
11541 OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
11542 OMP_CLAUSE_CHAIN (c) = list;
11546 c_parser_error (parser, "invalid proc_bind kind");
11547 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11552 to ( variable-list ) */
11555 c_parser_omp_clause_to (c_parser *parser, tree list)
11557 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
11561 from ( variable-list ) */
11564 c_parser_omp_clause_from (c_parser *parser, tree list)
11566 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
11570 uniform ( variable-list ) */
11573 c_parser_omp_clause_uniform (c_parser *parser, tree list)
11575 /* The clauses location. */
11576 location_t loc = c_parser_peek_token (parser)->location;
11578 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
11580 list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
11582 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
11587 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11588 is a bitmask in MASK. Return the list of clauses found. */
11591 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
11592 const char *where, bool finish_p = true)
11594 tree clauses = NULL;
11597 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11600 pragma_omp_clause c_kind;
11601 const char *c_name;
11602 tree prev = clauses;
11604 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11605 c_parser_consume_token (parser);
11607 here = c_parser_peek_token (parser)->location;
11608 c_kind = c_parser_omp_clause_name (parser);
11612 case PRAGMA_OACC_CLAUSE_ASYNC:
11613 clauses = c_parser_oacc_clause_async (parser, clauses);
11616 case PRAGMA_OACC_CLAUSE_COLLAPSE:
11617 clauses = c_parser_omp_clause_collapse (parser, clauses);
11618 c_name = "collapse";
11620 case PRAGMA_OACC_CLAUSE_COPY:
11621 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11624 case PRAGMA_OACC_CLAUSE_COPYIN:
11625 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11628 case PRAGMA_OACC_CLAUSE_COPYOUT:
11629 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11630 c_name = "copyout";
11632 case PRAGMA_OACC_CLAUSE_CREATE:
11633 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11636 case PRAGMA_OACC_CLAUSE_DELETE:
11637 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11640 case PRAGMA_OACC_CLAUSE_DEVICE:
11641 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11644 case PRAGMA_OACC_CLAUSE_DEVICEPTR:
11645 clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
11646 c_name = "deviceptr";
11648 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
11649 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
11650 c_name = "firstprivate";
11652 case PRAGMA_OACC_CLAUSE_HOST:
11653 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11656 case PRAGMA_OACC_CLAUSE_IF:
11657 clauses = c_parser_omp_clause_if (parser, clauses);
11660 case PRAGMA_OACC_CLAUSE_NUM_GANGS:
11661 clauses = c_parser_omp_clause_num_gangs (parser, clauses);
11662 c_name = "num_gangs";
11664 case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
11665 clauses = c_parser_omp_clause_num_workers (parser, clauses);
11666 c_name = "num_workers";
11668 case PRAGMA_OACC_CLAUSE_PRESENT:
11669 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11670 c_name = "present";
11672 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
11673 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11674 c_name = "present_or_copy";
11676 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
11677 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11678 c_name = "present_or_copyin";
11680 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
11681 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11682 c_name = "present_or_copyout";
11684 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
11685 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11686 c_name = "present_or_create";
11688 case PRAGMA_OACC_CLAUSE_PRIVATE:
11689 clauses = c_parser_omp_clause_private (parser, clauses);
11690 c_name = "private";
11692 case PRAGMA_OACC_CLAUSE_REDUCTION:
11693 clauses = c_parser_omp_clause_reduction (parser, clauses);
11694 c_name = "reduction";
11696 case PRAGMA_OACC_CLAUSE_SELF:
11697 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
11700 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
11701 clauses = c_parser_omp_clause_vector_length (parser, clauses);
11702 c_name = "vector_length";
11704 case PRAGMA_OACC_CLAUSE_WAIT:
11705 clauses = c_parser_oacc_clause_wait (parser, clauses);
11709 c_parser_error (parser, "expected %<#pragma acc%> clause");
11715 if (((mask >> c_kind) & 1) == 0)
11717 /* Remove the invalid clause(s) from the list to avoid
11718 confusing the rest of the compiler. */
11720 error_at (here, "%qs is not valid for %qs", c_name, where);
11725 c_parser_skip_to_pragma_eol (parser);
11728 return c_finish_omp_clauses (clauses);
11733 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11734 is a bitmask in MASK. Return the list of clauses found. */
11737 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
11738 const char *where, bool finish_p = true)
11740 tree clauses = NULL;
11741 bool first = true, cilk_simd_fn = false;
11743 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
11746 pragma_omp_clause c_kind;
11747 const char *c_name;
11748 tree prev = clauses;
11750 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
11751 c_parser_consume_token (parser);
11753 here = c_parser_peek_token (parser)->location;
11754 c_kind = c_parser_omp_clause_name (parser);
11758 case PRAGMA_OMP_CLAUSE_COLLAPSE:
11759 clauses = c_parser_omp_clause_collapse (parser, clauses);
11760 c_name = "collapse";
11762 case PRAGMA_OMP_CLAUSE_COPYIN:
11763 clauses = c_parser_omp_clause_copyin (parser, clauses);
11766 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
11767 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
11768 c_name = "copyprivate";
11770 case PRAGMA_OMP_CLAUSE_DEFAULT:
11771 clauses = c_parser_omp_clause_default (parser, clauses);
11772 c_name = "default";
11774 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
11775 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
11776 c_name = "firstprivate";
11778 case PRAGMA_OMP_CLAUSE_FINAL:
11779 clauses = c_parser_omp_clause_final (parser, clauses);
11782 case PRAGMA_OMP_CLAUSE_IF:
11783 clauses = c_parser_omp_clause_if (parser, clauses);
11786 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
11787 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
11788 c_name = "lastprivate";
11790 case PRAGMA_OMP_CLAUSE_MERGEABLE:
11791 clauses = c_parser_omp_clause_mergeable (parser, clauses);
11792 c_name = "mergeable";
11794 case PRAGMA_OMP_CLAUSE_NOWAIT:
11795 clauses = c_parser_omp_clause_nowait (parser, clauses);
11798 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
11799 clauses = c_parser_omp_clause_num_threads (parser, clauses);
11800 c_name = "num_threads";
11802 case PRAGMA_OMP_CLAUSE_ORDERED:
11803 clauses = c_parser_omp_clause_ordered (parser, clauses);
11804 c_name = "ordered";
11806 case PRAGMA_OMP_CLAUSE_PRIVATE:
11807 clauses = c_parser_omp_clause_private (parser, clauses);
11808 c_name = "private";
11810 case PRAGMA_OMP_CLAUSE_REDUCTION:
11811 clauses = c_parser_omp_clause_reduction (parser, clauses);
11812 c_name = "reduction";
11814 case PRAGMA_OMP_CLAUSE_SCHEDULE:
11815 clauses = c_parser_omp_clause_schedule (parser, clauses);
11816 c_name = "schedule";
11818 case PRAGMA_OMP_CLAUSE_SHARED:
11819 clauses = c_parser_omp_clause_shared (parser, clauses);
11822 case PRAGMA_OMP_CLAUSE_UNTIED:
11823 clauses = c_parser_omp_clause_untied (parser, clauses);
11826 case PRAGMA_OMP_CLAUSE_INBRANCH:
11827 case PRAGMA_CILK_CLAUSE_MASK:
11828 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
11830 c_name = "inbranch";
11832 case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
11833 case PRAGMA_CILK_CLAUSE_NOMASK:
11834 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
11836 c_name = "notinbranch";
11838 case PRAGMA_OMP_CLAUSE_PARALLEL:
11840 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
11842 c_name = "parallel";
11846 error_at (here, "%qs must be the first clause of %qs",
11851 case PRAGMA_OMP_CLAUSE_FOR:
11853 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
11857 goto clause_not_first;
11859 case PRAGMA_OMP_CLAUSE_SECTIONS:
11861 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
11863 c_name = "sections";
11865 goto clause_not_first;
11867 case PRAGMA_OMP_CLAUSE_TASKGROUP:
11869 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
11871 c_name = "taskgroup";
11873 goto clause_not_first;
11875 case PRAGMA_OMP_CLAUSE_TO:
11876 clauses = c_parser_omp_clause_to (parser, clauses);
11879 case PRAGMA_OMP_CLAUSE_FROM:
11880 clauses = c_parser_omp_clause_from (parser, clauses);
11883 case PRAGMA_OMP_CLAUSE_UNIFORM:
11884 clauses = c_parser_omp_clause_uniform (parser, clauses);
11885 c_name = "uniform";
11887 case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
11888 clauses = c_parser_omp_clause_num_teams (parser, clauses);
11889 c_name = "num_teams";
11891 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
11892 clauses = c_parser_omp_clause_thread_limit (parser, clauses);
11893 c_name = "thread_limit";
11895 case PRAGMA_OMP_CLAUSE_ALIGNED:
11896 clauses = c_parser_omp_clause_aligned (parser, clauses);
11897 c_name = "aligned";
11899 case PRAGMA_OMP_CLAUSE_LINEAR:
11900 if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0)
11901 cilk_simd_fn = true;
11902 clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn);
11905 case PRAGMA_OMP_CLAUSE_DEPEND:
11906 clauses = c_parser_omp_clause_depend (parser, clauses);
11909 case PRAGMA_OMP_CLAUSE_MAP:
11910 clauses = c_parser_omp_clause_map (parser, clauses);
11913 case PRAGMA_OMP_CLAUSE_DEVICE:
11914 clauses = c_parser_omp_clause_device (parser, clauses);
11917 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
11918 clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
11919 c_name = "dist_schedule";
11921 case PRAGMA_OMP_CLAUSE_PROC_BIND:
11922 clauses = c_parser_omp_clause_proc_bind (parser, clauses);
11923 c_name = "proc_bind";
11925 case PRAGMA_OMP_CLAUSE_SAFELEN:
11926 clauses = c_parser_omp_clause_safelen (parser, clauses);
11927 c_name = "safelen";
11929 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
11930 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true);
11931 c_name = "simdlen";
11933 case PRAGMA_OMP_CLAUSE_SIMDLEN:
11934 clauses = c_parser_omp_clause_simdlen (parser, clauses);
11935 c_name = "simdlen";
11938 c_parser_error (parser, "expected %<#pragma omp%> clause");
11944 if (((mask >> c_kind) & 1) == 0)
11946 /* Remove the invalid clause(s) from the list to avoid
11947 confusing the rest of the compiler. */
11949 error_at (here, "%qs is not valid for %qs", c_name, where);
11954 c_parser_skip_to_pragma_eol (parser);
11957 return c_finish_omp_clauses (clauses);
11962 /* OpenACC 2.0, OpenMP 2.5:
11966 In practice, we're also interested in adding the statement to an
11967 outer node. So it is convenient if we work around the fact that
11968 c_parser_statement calls add_stmt. */
11971 c_parser_omp_structured_block (c_parser *parser)
11973 tree stmt = push_stmt_list ();
11974 c_parser_statement (parser);
11975 return pop_stmt_list (stmt);
11979 # pragma acc cache (variable-list) new-line
11981 LOC is the location of the #pragma token.
11985 c_parser_oacc_cache (location_t loc, c_parser *parser)
11987 tree stmt, clauses;
11989 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
11990 clauses = c_finish_omp_clauses (clauses);
11992 c_parser_skip_to_pragma_eol (parser);
11994 stmt = make_node (OACC_CACHE);
11995 TREE_TYPE (stmt) = void_type_node;
11996 OACC_CACHE_CLAUSES (stmt) = clauses;
11997 SET_EXPR_LOCATION (stmt, loc);
12004 # pragma acc data oacc-data-clause[optseq] new-line
12007 LOC is the location of the #pragma token.
12010 #define OACC_DATA_CLAUSE_MASK \
12011 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12012 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12013 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12020 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12021 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12024 c_parser_oacc_data (location_t loc, c_parser *parser)
12026 tree stmt, clauses, block;
12028 clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
12029 "#pragma acc data");
12031 block = c_begin_omp_parallel ();
12032 add_stmt (c_parser_omp_structured_block (parser));
12034 stmt = c_finish_oacc_data (loc, clauses, block);
12040 # pragma acc kernels oacc-kernels-clause[optseq] new-line
12043 LOC is the location of the #pragma token.
12046 #define OACC_KERNELS_CLAUSE_MASK \
12047 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12050 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12051 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12053 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12054 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12055 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12056 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12057 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12058 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12059 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12062 c_parser_oacc_kernels (location_t loc, c_parser *parser, char *p_name)
12064 tree stmt, clauses = NULL_TREE, block;
12066 strcat (p_name, " kernels");
12068 if (c_parser_next_token_is (parser, CPP_NAME))
12070 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12071 if (strcmp (p, "loop") == 0)
12073 c_parser_consume_token (parser);
12074 block = c_begin_omp_parallel ();
12075 c_parser_oacc_loop (loc, parser, p_name);
12076 stmt = c_finish_oacc_kernels (loc, clauses, block);
12077 OACC_KERNELS_COMBINED (stmt) = 1;
12082 clauses = c_parser_oacc_all_clauses (parser, OACC_KERNELS_CLAUSE_MASK,
12085 block = c_begin_omp_parallel ();
12086 add_stmt (c_parser_omp_structured_block (parser));
12088 stmt = c_finish_oacc_kernels (loc, clauses, block);
12094 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12098 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12101 LOC is the location of the #pragma token.
12104 #define OACC_ENTER_DATA_CLAUSE_MASK \
12105 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12106 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12107 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12108 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12109 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12110 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12111 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12113 #define OACC_EXIT_DATA_CLAUSE_MASK \
12114 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12115 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12116 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12117 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
12118 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12121 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
12123 location_t loc = c_parser_peek_token (parser)->location;
12124 tree clauses, stmt;
12126 c_parser_consume_pragma (parser);
12128 if (!c_parser_next_token_is (parser, CPP_NAME))
12130 c_parser_error (parser, enter
12131 ? "expected %<data%> in %<#pragma acc enter data%>"
12132 : "expected %<data%> in %<#pragma acc exit data%>");
12133 c_parser_skip_to_pragma_eol (parser);
12137 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12138 if (strcmp (p, "data") != 0)
12140 c_parser_error (parser, "invalid pragma");
12141 c_parser_skip_to_pragma_eol (parser);
12145 c_parser_consume_token (parser);
12148 clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
12149 "#pragma acc enter data");
12151 clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
12152 "#pragma acc exit data");
12154 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12156 error_at (loc, enter
12157 ? "%<#pragma acc enter data%> has no data movement clause"
12158 : "%<#pragma acc exit data%> has no data movement clause");
12162 stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);
12163 TREE_TYPE (stmt) = void_type_node;
12165 OACC_ENTER_DATA_CLAUSES (stmt) = clauses;
12167 OACC_EXIT_DATA_CLAUSES (stmt) = clauses;
12168 SET_EXPR_LOCATION (stmt, loc);
12175 # pragma acc loop oacc-loop-clause[optseq] new-line
12178 LOC is the location of the #pragma token.
12181 #define OACC_LOOP_CLAUSE_MASK \
12182 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
12183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12186 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name)
12188 tree stmt, clauses, block;
12190 strcat (p_name, " loop");
12192 clauses = c_parser_oacc_all_clauses (parser, OACC_LOOP_CLAUSE_MASK, p_name);
12194 block = c_begin_compound_stmt (true);
12195 stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL);
12196 block = c_end_compound_stmt (loc, block, true);
12203 # pragma acc parallel oacc-parallel-clause[optseq] new-line
12206 LOC is the location of the #pragma token.
12209 #define OACC_PARALLEL_CLAUSE_MASK \
12210 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12211 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12212 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12213 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12214 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12215 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12216 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12217 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
12218 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
12219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12221 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12222 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12224 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
12225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
12226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12229 c_parser_oacc_parallel (location_t loc, c_parser *parser, char *p_name)
12231 tree stmt, clauses = NULL_TREE, block;
12233 strcat (p_name, " parallel");
12235 if (c_parser_next_token_is (parser, CPP_NAME))
12237 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12238 if (strcmp (p, "loop") == 0)
12240 c_parser_consume_token (parser);
12241 block = c_begin_omp_parallel ();
12242 c_parser_oacc_loop (loc, parser, p_name);
12243 stmt = c_finish_oacc_parallel (loc, clauses, block);
12244 OACC_PARALLEL_COMBINED (stmt) = 1;
12249 clauses = c_parser_oacc_all_clauses (parser, OACC_PARALLEL_CLAUSE_MASK,
12252 block = c_begin_omp_parallel ();
12253 add_stmt (c_parser_omp_structured_block (parser));
12255 stmt = c_finish_oacc_parallel (loc, clauses, block);
12261 # pragma acc update oacc-update-clause[optseq] new-line
12264 #define OACC_UPDATE_CLAUSE_MASK \
12265 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
12267 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
12268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
12270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12273 c_parser_oacc_update (c_parser *parser)
12275 location_t loc = c_parser_peek_token (parser)->location;
12277 c_parser_consume_pragma (parser);
12279 tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
12280 "#pragma acc update");
12281 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
12284 "%<#pragma acc update%> must contain at least one "
12285 "%<device%> or %<host/self%> clause");
12292 tree stmt = make_node (OACC_UPDATE);
12293 TREE_TYPE (stmt) = void_type_node;
12294 OACC_UPDATE_CLAUSES (stmt) = clauses;
12295 SET_EXPR_LOCATION (stmt, loc);
12300 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12302 LOC is the location of the #pragma token.
12305 #define OACC_WAIT_CLAUSE_MASK \
12306 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12309 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
12311 tree clauses, list = NULL_TREE, stmt = NULL_TREE;
12313 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12314 list = c_parser_oacc_wait_list (parser, loc, list);
12316 strcpy (p_name, " wait");
12317 clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
12318 stmt = c_finish_oacc_wait (loc, list, clauses);
12324 # pragma omp atomic new-line
12328 x binop= expr | x++ | ++x | x-- | --x
12330 +, *, -, /, &, ^, |, <<, >>
12332 where x is an lvalue expression with scalar type.
12335 # pragma omp atomic new-line
12338 # pragma omp atomic read new-line
12341 # pragma omp atomic write new-line
12344 # pragma omp atomic update new-line
12347 # pragma omp atomic capture new-line
12350 # pragma omp atomic capture new-line
12358 expression-stmt | x = x binop expr
12360 v = expression-stmt
12362 { v = x; update-stmt; } | { update-stmt; v = x; }
12366 expression-stmt | x = x binop expr | x = expr binop x
12370 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12372 where x and v are lvalue expressions with scalar type.
12374 LOC is the location of the #pragma token. */
12377 c_parser_omp_atomic (location_t loc, c_parser *parser)
12379 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
12380 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
12381 tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
12382 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
12383 struct c_expr expr;
12385 bool structured_block = false;
12386 bool swapped = false;
12387 bool seq_cst = false;
12390 if (c_parser_next_token_is (parser, CPP_NAME))
12392 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12393 if (!strcmp (p, "seq_cst"))
12396 c_parser_consume_token (parser);
12397 if (c_parser_next_token_is (parser, CPP_COMMA)
12398 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12399 c_parser_consume_token (parser);
12402 if (c_parser_next_token_is (parser, CPP_NAME))
12404 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12406 if (!strcmp (p, "read"))
12407 code = OMP_ATOMIC_READ;
12408 else if (!strcmp (p, "write"))
12410 else if (!strcmp (p, "update"))
12412 else if (!strcmp (p, "capture"))
12413 code = OMP_ATOMIC_CAPTURE_NEW;
12417 c_parser_consume_token (parser);
12421 if (c_parser_next_token_is (parser, CPP_COMMA)
12422 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
12423 c_parser_consume_token (parser);
12425 if (c_parser_next_token_is (parser, CPP_NAME))
12428 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12429 if (!strcmp (p, "seq_cst"))
12432 c_parser_consume_token (parser);
12436 c_parser_skip_to_pragma_eol (parser);
12440 case OMP_ATOMIC_READ:
12441 case NOP_EXPR: /* atomic write */
12442 v = c_parser_cast_expression (parser, NULL).value;
12443 non_lvalue_p = !lvalue_p (v);
12444 v = c_fully_fold (v, false, NULL);
12445 if (v == error_mark_node)
12448 v = non_lvalue (v);
12449 loc = c_parser_peek_token (parser)->location;
12450 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12452 if (code == NOP_EXPR)
12454 lhs = c_parser_expression (parser).value;
12455 lhs = c_fully_fold (lhs, false, NULL);
12456 if (lhs == error_mark_node)
12461 lhs = c_parser_cast_expression (parser, NULL).value;
12462 non_lvalue_p = !lvalue_p (lhs);
12463 lhs = c_fully_fold (lhs, false, NULL);
12464 if (lhs == error_mark_node)
12467 lhs = non_lvalue (lhs);
12469 if (code == NOP_EXPR)
12471 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12479 case OMP_ATOMIC_CAPTURE_NEW:
12480 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
12482 c_parser_consume_token (parser);
12483 structured_block = true;
12487 v = c_parser_cast_expression (parser, NULL).value;
12488 non_lvalue_p = !lvalue_p (v);
12489 v = c_fully_fold (v, false, NULL);
12490 if (v == error_mark_node)
12493 v = non_lvalue (v);
12494 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12502 /* For structured_block case we don't know yet whether
12503 old or new x should be captured. */
12505 eloc = c_parser_peek_token (parser)->location;
12506 expr = c_parser_cast_expression (parser, NULL);
12508 expr = default_function_array_conversion (eloc, expr);
12509 unfolded_lhs = expr.value;
12510 lhs = c_fully_fold (lhs, false, NULL);
12512 switch (TREE_CODE (lhs))
12516 c_parser_skip_to_end_of_block_or_statement (parser);
12517 if (structured_block)
12519 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12520 c_parser_consume_token (parser);
12521 else if (code == OMP_ATOMIC_CAPTURE_NEW)
12523 c_parser_skip_to_end_of_block_or_statement (parser);
12524 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
12525 c_parser_consume_token (parser);
12530 case POSTINCREMENT_EXPR:
12531 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12532 code = OMP_ATOMIC_CAPTURE_OLD;
12534 case PREINCREMENT_EXPR:
12535 lhs = TREE_OPERAND (lhs, 0);
12536 unfolded_lhs = NULL_TREE;
12537 opcode = PLUS_EXPR;
12538 rhs = integer_one_node;
12541 case POSTDECREMENT_EXPR:
12542 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
12543 code = OMP_ATOMIC_CAPTURE_OLD;
12545 case PREDECREMENT_EXPR:
12546 lhs = TREE_OPERAND (lhs, 0);
12547 unfolded_lhs = NULL_TREE;
12548 opcode = MINUS_EXPR;
12549 rhs = integer_one_node;
12552 case COMPOUND_EXPR:
12553 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
12554 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
12555 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
12556 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
12557 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12558 (TREE_OPERAND (lhs, 1), 0), 0)))
12560 /* Undo effects of boolean_increment for post {in,de}crement. */
12561 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
12564 if (TREE_CODE (lhs) == MODIFY_EXPR
12565 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
12567 /* Undo effects of boolean_increment. */
12568 if (integer_onep (TREE_OPERAND (lhs, 1)))
12570 /* This is pre or post increment. */
12571 rhs = TREE_OPERAND (lhs, 1);
12572 lhs = TREE_OPERAND (lhs, 0);
12573 unfolded_lhs = NULL_TREE;
12575 if (code == OMP_ATOMIC_CAPTURE_NEW
12576 && !structured_block
12577 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12578 code = OMP_ATOMIC_CAPTURE_OLD;
12581 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
12582 && TREE_OPERAND (lhs, 0)
12583 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
12585 /* This is pre or post decrement. */
12586 rhs = TREE_OPERAND (lhs, 1);
12587 lhs = TREE_OPERAND (lhs, 0);
12588 unfolded_lhs = NULL_TREE;
12590 if (code == OMP_ATOMIC_CAPTURE_NEW
12591 && !structured_block
12592 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
12593 code = OMP_ATOMIC_CAPTURE_OLD;
12599 if (!lvalue_p (unfolded_lhs))
12600 lhs = non_lvalue (lhs);
12601 switch (c_parser_peek_token (parser)->type)
12604 opcode = MULT_EXPR;
12607 opcode = TRUNC_DIV_EXPR;
12610 opcode = PLUS_EXPR;
12613 opcode = MINUS_EXPR;
12615 case CPP_LSHIFT_EQ:
12616 opcode = LSHIFT_EXPR;
12618 case CPP_RSHIFT_EQ:
12619 opcode = RSHIFT_EXPR;
12622 opcode = BIT_AND_EXPR;
12625 opcode = BIT_IOR_EXPR;
12628 opcode = BIT_XOR_EXPR;
12631 c_parser_consume_token (parser);
12632 eloc = c_parser_peek_token (parser)->location;
12633 expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
12635 switch (TREE_CODE (rhs1))
12638 case TRUNC_DIV_EXPR:
12647 if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
12649 opcode = TREE_CODE (rhs1);
12650 rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12651 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12654 if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
12656 opcode = TREE_CODE (rhs1);
12657 rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
12658 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
12659 swapped = !commutative_tree_code (opcode);
12668 if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
12670 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12672 code = OMP_ATOMIC_CAPTURE_OLD;
12675 expr = default_function_array_read_conversion (eloc, expr);
12676 unfolded_lhs1 = expr.value;
12677 lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
12679 c_parser_consume_token (parser);
12682 if (structured_block)
12685 expr = default_function_array_read_conversion (eloc, expr);
12686 rhs = c_fully_fold (expr.value, false, NULL);
12691 c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
12694 c_parser_error (parser,
12695 "invalid operator for %<#pragma omp atomic%>");
12699 /* Arrange to pass the location of the assignment operator to
12700 c_finish_omp_atomic. */
12701 loc = c_parser_peek_token (parser)->location;
12702 c_parser_consume_token (parser);
12703 eloc = c_parser_peek_token (parser)->location;
12704 expr = c_parser_expression (parser);
12705 expr = default_function_array_read_conversion (eloc, expr);
12707 rhs = c_fully_fold (rhs, false, NULL);
12711 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
12713 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
12715 v = c_parser_cast_expression (parser, NULL).value;
12716 non_lvalue_p = !lvalue_p (v);
12717 v = c_fully_fold (v, false, NULL);
12718 if (v == error_mark_node)
12721 v = non_lvalue (v);
12722 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
12724 eloc = c_parser_peek_token (parser)->location;
12725 expr = c_parser_cast_expression (parser, NULL);
12727 expr = default_function_array_read_conversion (eloc, expr);
12728 unfolded_lhs1 = expr.value;
12729 lhs1 = c_fully_fold (lhs1, false, NULL);
12730 if (lhs1 == error_mark_node)
12732 if (!lvalue_p (unfolded_lhs1))
12733 lhs1 = non_lvalue (lhs1);
12735 if (structured_block)
12737 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12738 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
12741 if (unfolded_lhs && unfolded_lhs1
12742 && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
12744 error ("%<#pragma omp atomic capture%> uses two different "
12745 "expressions for memory");
12746 stmt = error_mark_node;
12749 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
12751 if (stmt != error_mark_node)
12754 if (!structured_block)
12755 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12760 # pragma omp barrier new-line
12764 c_parser_omp_barrier (c_parser *parser)
12766 location_t loc = c_parser_peek_token (parser)->location;
12767 c_parser_consume_pragma (parser);
12768 c_parser_skip_to_pragma_eol (parser);
12770 c_finish_omp_barrier (loc);
12774 # pragma omp critical [(name)] new-line
12777 LOC is the location of the #pragma itself. */
12780 c_parser_omp_critical (location_t loc, c_parser *parser)
12782 tree stmt, name = NULL;
12784 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12786 c_parser_consume_token (parser);
12787 if (c_parser_next_token_is (parser, CPP_NAME))
12789 name = c_parser_peek_token (parser)->value;
12790 c_parser_consume_token (parser);
12791 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12794 c_parser_error (parser, "expected identifier");
12796 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12797 c_parser_error (parser, "expected %<(%> or end of line");
12798 c_parser_skip_to_pragma_eol (parser);
12800 stmt = c_parser_omp_structured_block (parser);
12801 return c_finish_omp_critical (loc, stmt, name);
12805 # pragma omp flush flush-vars[opt] new-line
12808 ( variable-list ) */
12811 c_parser_omp_flush (c_parser *parser)
12813 location_t loc = c_parser_peek_token (parser)->location;
12814 c_parser_consume_pragma (parser);
12815 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12816 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
12817 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
12818 c_parser_error (parser, "expected %<(%> or end of line");
12819 c_parser_skip_to_pragma_eol (parser);
12821 c_finish_omp_flush (loc);
12824 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12825 The real trick here is to determine the loop control variable early
12826 so that we can push a new decl if necessary to make it private.
12827 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12831 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
12832 tree clauses, tree *cclauses)
12834 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
12835 tree declv, condv, incrv, initv, ret = NULL_TREE;
12836 tree pre_body = NULL_TREE, this_pre_body;
12837 bool fail = false, open_brace_parsed = false;
12838 int i, collapse = 1, nbraces = 0;
12839 location_t for_loc;
12840 vec<tree, va_gc> *for_block = make_tree_vector ();
12842 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
12843 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
12844 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
12846 gcc_assert (collapse >= 1);
12848 declv = make_tree_vec (collapse);
12849 initv = make_tree_vec (collapse);
12850 condv = make_tree_vec (collapse);
12851 incrv = make_tree_vec (collapse);
12853 if (code != CILK_FOR
12854 && !c_parser_next_token_is_keyword (parser, RID_FOR))
12856 c_parser_error (parser, "for statement expected");
12859 if (code == CILK_FOR
12860 && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR))
12862 c_parser_error (parser, "_Cilk_for statement expected");
12865 for_loc = c_parser_peek_token (parser)->location;
12866 c_parser_consume_token (parser);
12868 for (i = 0; i < collapse; i++)
12870 int bracecount = 0;
12872 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12875 /* Parse the initialization declaration or expression. */
12876 if (c_parser_next_tokens_start_declaration (parser))
12879 vec_safe_push (for_block, c_begin_compound_stmt (true));
12880 this_pre_body = push_stmt_list ();
12881 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
12885 this_pre_body = pop_stmt_list (this_pre_body);
12889 pre_body = push_stmt_list ();
12891 add_stmt (this_pre_body);
12892 pre_body = pop_stmt_list (pre_body);
12895 pre_body = this_pre_body;
12897 decl = check_for_loop_decls (for_loc, flag_isoc99);
12900 if (DECL_INITIAL (decl) == error_mark_node)
12901 decl = error_mark_node;
12904 else if (c_parser_next_token_is (parser, CPP_NAME)
12905 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
12907 struct c_expr decl_exp;
12908 struct c_expr init_exp;
12909 location_t init_loc;
12911 decl_exp = c_parser_postfix_expression (parser);
12912 decl = decl_exp.value;
12914 c_parser_require (parser, CPP_EQ, "expected %<=%>");
12916 init_loc = c_parser_peek_token (parser)->location;
12917 init_exp = c_parser_expr_no_commas (parser, NULL);
12918 init_exp = default_function_array_read_conversion (init_loc,
12920 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
12921 NOP_EXPR, init_loc, init_exp.value,
12922 init_exp.original_type);
12923 init = c_process_expr_stmt (init_loc, init);
12925 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12930 c_parser_error (parser,
12931 "expected iteration declaration or initialization");
12932 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12938 /* Parse the loop condition. */
12940 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
12942 location_t cond_loc = c_parser_peek_token (parser)->location;
12943 struct c_expr cond_expr
12944 = c_parser_binary_expression (parser, NULL, NULL_TREE);
12946 cond = cond_expr.value;
12947 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
12948 cond = c_fully_fold (cond, false, NULL);
12949 switch (cond_expr.original_code)
12957 if (code == CILK_SIMD || code == CILK_FOR)
12961 /* Can't be cond = error_mark_node, because we want to preserve
12962 the location until c_finish_omp_for. */
12963 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
12966 protected_set_expr_location (cond, cond_loc);
12968 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
12970 /* Parse the increment expression. */
12972 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
12974 location_t incr_loc = c_parser_peek_token (parser)->location;
12976 incr = c_process_expr_stmt (incr_loc,
12977 c_parser_expression (parser).value);
12979 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
12981 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
12985 TREE_VEC_ELT (declv, i) = decl;
12986 TREE_VEC_ELT (initv, i) = init;
12987 TREE_VEC_ELT (condv, i) = cond;
12988 TREE_VEC_ELT (incrv, i) = incr;
12992 if (i == collapse - 1)
12995 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12996 in between the collapsed for loops to be still considered perfectly
12997 nested. Hopefully the final version clarifies this.
12998 For now handle (multiple) {'s and empty statements. */
13001 if (c_parser_next_token_is_keyword (parser, RID_FOR))
13003 c_parser_consume_token (parser);
13006 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
13008 c_parser_consume_token (parser);
13011 else if (bracecount
13012 && c_parser_next_token_is (parser, CPP_SEMICOLON))
13013 c_parser_consume_token (parser);
13016 c_parser_error (parser, "not enough perfectly nested loops");
13019 open_brace_parsed = true;
13029 nbraces += bracecount;
13032 save_break = c_break_label;
13033 if (code == CILK_SIMD)
13034 c_break_label = build_int_cst (size_type_node, 2);
13036 c_break_label = size_one_node;
13037 save_cont = c_cont_label;
13038 c_cont_label = NULL_TREE;
13039 body = push_stmt_list ();
13041 if (open_brace_parsed)
13043 location_t here = c_parser_peek_token (parser)->location;
13044 stmt = c_begin_compound_stmt (true);
13045 c_parser_compound_statement_nostart (parser);
13046 add_stmt (c_end_compound_stmt (here, stmt, true));
13049 add_stmt (c_parser_c99_block_statement (parser));
13052 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
13053 SET_EXPR_LOCATION (t, loc);
13057 body = pop_stmt_list (body);
13058 c_break_label = save_break;
13059 c_cont_label = save_cont;
13063 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13065 c_parser_consume_token (parser);
13068 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
13069 c_parser_consume_token (parser);
13072 c_parser_error (parser, "collapsed loops not perfectly nested");
13075 location_t here = c_parser_peek_token (parser)->location;
13076 stmt = c_begin_compound_stmt (true);
13078 c_parser_compound_statement_nostart (parser);
13079 body = c_end_compound_stmt (here, stmt, true);
13086 /* Only bother calling c_finish_omp_for if we haven't already generated
13087 an error from the initialization parsing. */
13090 stmt = c_finish_omp_for (loc, code, declv, initv, condv,
13091 incrv, body, pre_body);
13094 if (cclauses != NULL
13095 && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
13098 for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
13099 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
13100 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
13101 c = &OMP_CLAUSE_CHAIN (*c);
13104 for (i = 0; i < collapse; i++)
13105 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
13108 c = &OMP_CLAUSE_CHAIN (*c);
13109 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
13112 "iteration variable %qD should not be firstprivate",
13113 OMP_CLAUSE_DECL (*c));
13114 *c = OMP_CLAUSE_CHAIN (*c);
13118 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
13120 *c = OMP_CLAUSE_CHAIN (*c);
13121 if (code == OMP_SIMD)
13123 OMP_CLAUSE_CHAIN (l)
13124 = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13125 cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
13129 OMP_CLAUSE_CHAIN (l) = clauses;
13135 OMP_FOR_CLAUSES (stmt) = clauses;
13140 while (!for_block->is_empty ())
13142 /* FIXME diagnostics: LOC below should be the actual location of
13143 this particular for block. We need to build a list of
13144 locations to go along with FOR_BLOCK. */
13145 stmt = c_end_compound_stmt (loc, for_block->pop (), true);
13148 release_tree_vector (for_block);
13152 /* Helper function for OpenMP parsing, split clauses and call
13153 finish_omp_clauses on each of the set of clauses afterwards. */
13156 omp_split_clauses (location_t loc, enum tree_code code,
13157 omp_clause_mask mask, tree clauses, tree *cclauses)
13160 c_omp_split_clauses (loc, code, mask, clauses, cclauses);
13161 for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
13163 cclauses[i] = c_finish_omp_clauses (cclauses[i]);
13167 #pragma omp simd simd-clause[optseq] new-line
13170 LOC is the location of the #pragma token.
13173 #define OMP_SIMD_CLAUSE_MASK \
13174 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
13175 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13180 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13183 c_parser_omp_simd (location_t loc, c_parser *parser,
13184 char *p_name, omp_clause_mask mask, tree *cclauses)
13186 tree block, clauses, ret;
13188 strcat (p_name, " simd");
13189 mask |= OMP_SIMD_CLAUSE_MASK;
13190 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
13192 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13195 omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
13196 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
13199 block = c_begin_compound_stmt (true);
13200 ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses);
13201 block = c_end_compound_stmt (loc, block, true);
13208 #pragma omp for for-clause[optseq] new-line
13212 #pragma omp for simd for-simd-clause[optseq] new-line
13215 LOC is the location of the #pragma token.
13218 #define OMP_FOR_CLAUSE_MASK \
13219 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13221 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13222 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
13224 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
13225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
13226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13229 c_parser_omp_for (location_t loc, c_parser *parser,
13230 char *p_name, omp_clause_mask mask, tree *cclauses)
13232 tree block, clauses, ret;
13234 strcat (p_name, " for");
13235 mask |= OMP_FOR_CLAUSE_MASK;
13237 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13239 if (c_parser_next_token_is (parser, CPP_NAME))
13241 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13243 if (strcmp (p, "simd") == 0)
13245 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13246 if (cclauses == NULL)
13247 cclauses = cclauses_buf;
13249 c_parser_consume_token (parser);
13250 if (!flag_openmp) /* flag_openmp_simd */
13251 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13252 block = c_begin_compound_stmt (true);
13253 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13254 block = c_end_compound_stmt (loc, block, true);
13255 if (ret == NULL_TREE)
13257 ret = make_node (OMP_FOR);
13258 TREE_TYPE (ret) = void_type_node;
13259 OMP_FOR_BODY (ret) = block;
13260 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13261 SET_EXPR_LOCATION (ret, loc);
13266 if (!flag_openmp) /* flag_openmp_simd */
13268 c_parser_skip_to_pragma_eol (parser, false);
13272 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13275 omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
13276 clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
13279 block = c_begin_compound_stmt (true);
13280 ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses);
13281 block = c_end_compound_stmt (loc, block, true);
13288 # pragma omp master new-line
13291 LOC is the location of the #pragma token.
13295 c_parser_omp_master (location_t loc, c_parser *parser)
13297 c_parser_skip_to_pragma_eol (parser);
13298 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
13302 # pragma omp ordered new-line
13305 LOC is the location of the #pragma itself.
13309 c_parser_omp_ordered (location_t loc, c_parser *parser)
13311 c_parser_skip_to_pragma_eol (parser);
13312 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
13318 { section-sequence }
13321 section-directive[opt] structured-block
13322 section-sequence section-directive structured-block
13324 SECTIONS_LOC is the location of the #pragma omp sections. */
13327 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
13329 tree stmt, substmt;
13330 bool error_suppress = false;
13333 loc = c_parser_peek_token (parser)->location;
13334 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
13336 /* Avoid skipping until the end of the block. */
13337 parser->error = false;
13341 stmt = push_stmt_list ();
13343 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
13345 substmt = c_parser_omp_structured_block (parser);
13346 substmt = build1 (OMP_SECTION, void_type_node, substmt);
13347 SET_EXPR_LOCATION (substmt, loc);
13348 add_stmt (substmt);
13353 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
13355 if (c_parser_next_token_is (parser, CPP_EOF))
13358 loc = c_parser_peek_token (parser)->location;
13359 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
13361 c_parser_consume_pragma (parser);
13362 c_parser_skip_to_pragma_eol (parser);
13363 error_suppress = false;
13365 else if (!error_suppress)
13367 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
13368 error_suppress = true;
13371 substmt = c_parser_omp_structured_block (parser);
13372 substmt = build1 (OMP_SECTION, void_type_node, substmt);
13373 SET_EXPR_LOCATION (substmt, loc);
13374 add_stmt (substmt);
13376 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
13377 "expected %<#pragma omp section%> or %<}%>");
13379 substmt = pop_stmt_list (stmt);
13381 stmt = make_node (OMP_SECTIONS);
13382 SET_EXPR_LOCATION (stmt, sections_loc);
13383 TREE_TYPE (stmt) = void_type_node;
13384 OMP_SECTIONS_BODY (stmt) = substmt;
13386 return add_stmt (stmt);
13390 # pragma omp sections sections-clause[optseq] newline
13393 LOC is the location of the #pragma token.
13396 #define OMP_SECTIONS_CLAUSE_MASK \
13397 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13398 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13399 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13400 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13404 c_parser_omp_sections (location_t loc, c_parser *parser,
13405 char *p_name, omp_clause_mask mask, tree *cclauses)
13407 tree block, clauses, ret;
13409 strcat (p_name, " sections");
13410 mask |= OMP_SECTIONS_CLAUSE_MASK;
13412 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
13414 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13417 omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
13418 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
13421 block = c_begin_compound_stmt (true);
13422 ret = c_parser_omp_sections_scope (loc, parser);
13424 OMP_SECTIONS_CLAUSES (ret) = clauses;
13425 block = c_end_compound_stmt (loc, block, true);
13432 # pragma omp parallel parallel-clause[optseq] new-line
13434 # pragma omp parallel for parallel-for-clause[optseq] new-line
13436 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13440 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13443 LOC is the location of the #pragma token.
13446 #define OMP_PARALLEL_CLAUSE_MASK \
13447 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13448 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13449 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13450 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13451 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13452 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13453 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13454 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13455 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13458 c_parser_omp_parallel (location_t loc, c_parser *parser,
13459 char *p_name, omp_clause_mask mask, tree *cclauses)
13461 tree stmt, clauses, block;
13463 strcat (p_name, " parallel");
13464 mask |= OMP_PARALLEL_CLAUSE_MASK;
13466 if (c_parser_next_token_is_keyword (parser, RID_FOR))
13468 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13469 if (cclauses == NULL)
13470 cclauses = cclauses_buf;
13472 c_parser_consume_token (parser);
13473 if (!flag_openmp) /* flag_openmp_simd */
13474 return c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13475 block = c_begin_omp_parallel ();
13476 tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses);
13478 = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
13480 if (ret == NULL_TREE)
13482 OMP_PARALLEL_COMBINED (stmt) = 1;
13487 error_at (loc, "expected %<for%> after %qs", p_name);
13488 c_parser_skip_to_pragma_eol (parser);
13491 else if (!flag_openmp) /* flag_openmp_simd */
13493 c_parser_skip_to_pragma_eol (parser, false);
13496 else if (c_parser_next_token_is (parser, CPP_NAME))
13498 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13499 if (strcmp (p, "sections") == 0)
13501 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13502 if (cclauses == NULL)
13503 cclauses = cclauses_buf;
13505 c_parser_consume_token (parser);
13506 block = c_begin_omp_parallel ();
13507 c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
13508 stmt = c_finish_omp_parallel (loc,
13509 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
13511 OMP_PARALLEL_COMBINED (stmt) = 1;
13516 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13518 block = c_begin_omp_parallel ();
13519 c_parser_statement (parser);
13520 stmt = c_finish_omp_parallel (loc, clauses, block);
13526 # pragma omp single single-clause[optseq] new-line
13529 LOC is the location of the #pragma.
13532 #define OMP_SINGLE_CLAUSE_MASK \
13533 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13534 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13535 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
13536 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13539 c_parser_omp_single (location_t loc, c_parser *parser)
13541 tree stmt = make_node (OMP_SINGLE);
13542 SET_EXPR_LOCATION (stmt, loc);
13543 TREE_TYPE (stmt) = void_type_node;
13545 OMP_SINGLE_CLAUSES (stmt)
13546 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
13547 "#pragma omp single");
13548 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
13550 return add_stmt (stmt);
13554 # pragma omp task task-clause[optseq] new-line
13556 LOC is the location of the #pragma.
13559 #define OMP_TASK_CLAUSE_MASK \
13560 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13561 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13562 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13568 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13571 c_parser_omp_task (location_t loc, c_parser *parser)
13573 tree clauses, block;
13575 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
13576 "#pragma omp task");
13578 block = c_begin_omp_task ();
13579 c_parser_statement (parser);
13580 return c_finish_omp_task (loc, clauses, block);
13584 # pragma omp taskwait new-line
13588 c_parser_omp_taskwait (c_parser *parser)
13590 location_t loc = c_parser_peek_token (parser)->location;
13591 c_parser_consume_pragma (parser);
13592 c_parser_skip_to_pragma_eol (parser);
13594 c_finish_omp_taskwait (loc);
13598 # pragma omp taskyield new-line
13602 c_parser_omp_taskyield (c_parser *parser)
13604 location_t loc = c_parser_peek_token (parser)->location;
13605 c_parser_consume_pragma (parser);
13606 c_parser_skip_to_pragma_eol (parser);
13608 c_finish_omp_taskyield (loc);
13612 # pragma omp taskgroup new-line
13616 c_parser_omp_taskgroup (c_parser *parser)
13618 location_t loc = c_parser_peek_token (parser)->location;
13619 c_parser_skip_to_pragma_eol (parser);
13620 return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser));
13624 # pragma omp cancel cancel-clause[optseq] new-line
13626 LOC is the location of the #pragma.
13629 #define OMP_CANCEL_CLAUSE_MASK \
13630 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13631 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13632 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13633 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13634 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13637 c_parser_omp_cancel (c_parser *parser)
13639 location_t loc = c_parser_peek_token (parser)->location;
13641 c_parser_consume_pragma (parser);
13642 tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
13643 "#pragma omp cancel");
13645 c_finish_omp_cancel (loc, clauses);
13649 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13651 LOC is the location of the #pragma.
13654 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13655 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13656 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13657 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13658 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13661 c_parser_omp_cancellation_point (c_parser *parser)
13663 location_t loc = c_parser_peek_token (parser)->location;
13665 bool point_seen = false;
13667 c_parser_consume_pragma (parser);
13668 if (c_parser_next_token_is (parser, CPP_NAME))
13670 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13671 if (strcmp (p, "point") == 0)
13673 c_parser_consume_token (parser);
13679 c_parser_error (parser, "expected %<point%>");
13680 c_parser_skip_to_pragma_eol (parser);
13685 = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
13686 "#pragma omp cancellation point");
13688 c_finish_omp_cancellation_point (loc, clauses);
13692 #pragma omp distribute distribute-clause[optseq] new-line
13695 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13696 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13697 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13698 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13699 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13702 c_parser_omp_distribute (location_t loc, c_parser *parser,
13703 char *p_name, omp_clause_mask mask, tree *cclauses)
13705 tree clauses, block, ret;
13707 strcat (p_name, " distribute");
13708 mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
13710 if (c_parser_next_token_is (parser, CPP_NAME))
13712 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13714 bool parallel = false;
13716 if (strcmp (p, "simd") == 0)
13719 parallel = strcmp (p, "parallel") == 0;
13720 if (parallel || simd)
13722 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13723 if (cclauses == NULL)
13724 cclauses = cclauses_buf;
13725 c_parser_consume_token (parser);
13726 if (!flag_openmp) /* flag_openmp_simd */
13729 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13731 return c_parser_omp_parallel (loc, parser, p_name, mask,
13734 block = c_begin_compound_stmt (true);
13736 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
13738 ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses);
13739 block = c_end_compound_stmt (loc, block, true);
13742 ret = make_node (OMP_DISTRIBUTE);
13743 TREE_TYPE (ret) = void_type_node;
13744 OMP_FOR_BODY (ret) = block;
13745 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13746 SET_EXPR_LOCATION (ret, loc);
13751 if (!flag_openmp) /* flag_openmp_simd */
13753 c_parser_skip_to_pragma_eol (parser, false);
13757 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13760 omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
13761 clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
13764 block = c_begin_compound_stmt (true);
13765 ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL);
13766 block = c_end_compound_stmt (loc, block, true);
13773 # pragma omp teams teams-clause[optseq] new-line
13774 structured-block */
13776 #define OMP_TEAMS_CLAUSE_MASK \
13777 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13778 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13779 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13780 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13781 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13782 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13783 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13786 c_parser_omp_teams (location_t loc, c_parser *parser,
13787 char *p_name, omp_clause_mask mask, tree *cclauses)
13789 tree clauses, block, ret;
13791 strcat (p_name, " teams");
13792 mask |= OMP_TEAMS_CLAUSE_MASK;
13794 if (c_parser_next_token_is (parser, CPP_NAME))
13796 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13797 if (strcmp (p, "distribute") == 0)
13799 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
13800 if (cclauses == NULL)
13801 cclauses = cclauses_buf;
13803 c_parser_consume_token (parser);
13804 if (!flag_openmp) /* flag_openmp_simd */
13805 return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13806 block = c_begin_compound_stmt (true);
13807 ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
13808 block = c_end_compound_stmt (loc, block, true);
13811 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13812 ret = make_node (OMP_TEAMS);
13813 TREE_TYPE (ret) = void_type_node;
13814 OMP_TEAMS_CLAUSES (ret) = clauses;
13815 OMP_TEAMS_BODY (ret) = block;
13816 OMP_TEAMS_COMBINED (ret) = 1;
13817 return add_stmt (ret);
13820 if (!flag_openmp) /* flag_openmp_simd */
13822 c_parser_skip_to_pragma_eol (parser, false);
13826 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
13829 omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
13830 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
13833 tree stmt = make_node (OMP_TEAMS);
13834 TREE_TYPE (stmt) = void_type_node;
13835 OMP_TEAMS_CLAUSES (stmt) = clauses;
13836 OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser);
13838 return add_stmt (stmt);
13842 # pragma omp target data target-data-clause[optseq] new-line
13843 structured-block */
13845 #define OMP_TARGET_DATA_CLAUSE_MASK \
13846 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13847 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13848 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13851 c_parser_omp_target_data (location_t loc, c_parser *parser)
13853 tree stmt = make_node (OMP_TARGET_DATA);
13854 TREE_TYPE (stmt) = void_type_node;
13856 OMP_TARGET_DATA_CLAUSES (stmt)
13857 = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
13858 "#pragma omp target data");
13859 keep_next_level ();
13860 tree block = c_begin_compound_stmt (true);
13861 add_stmt (c_parser_omp_structured_block (parser));
13862 OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13864 SET_EXPR_LOCATION (stmt, loc);
13865 return add_stmt (stmt);
13869 # pragma omp target update target-update-clause[optseq] new-line */
13871 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13872 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13874 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13875 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13878 c_parser_omp_target_update (location_t loc, c_parser *parser,
13879 enum pragma_context context)
13881 if (context == pragma_stmt)
13884 "%<#pragma omp target update%> may only be "
13885 "used in compound statements");
13886 c_parser_skip_to_pragma_eol (parser);
13891 = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
13892 "#pragma omp target update");
13893 if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
13894 && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
13897 "%<#pragma omp target update%> must contain at least one "
13898 "%<from%> or %<to%> clauses");
13902 tree stmt = make_node (OMP_TARGET_UPDATE);
13903 TREE_TYPE (stmt) = void_type_node;
13904 OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
13905 SET_EXPR_LOCATION (stmt, loc);
13911 # pragma omp target target-clause[optseq] new-line
13912 structured-block */
13914 #define OMP_TARGET_CLAUSE_MASK \
13915 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13916 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13917 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13920 c_parser_omp_target (c_parser *parser, enum pragma_context context)
13922 location_t loc = c_parser_peek_token (parser)->location;
13923 c_parser_consume_pragma (parser);
13925 if (context != pragma_stmt && context != pragma_compound)
13927 c_parser_error (parser, "expected declaration specifiers");
13928 c_parser_skip_to_pragma_eol (parser);
13932 if (c_parser_next_token_is (parser, CPP_NAME))
13934 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13936 if (strcmp (p, "teams") == 0)
13938 tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
13939 char p_name[sizeof ("#pragma omp target teams distribute "
13940 "parallel for simd")];
13942 c_parser_consume_token (parser);
13943 strcpy (p_name, "#pragma omp target");
13944 if (!flag_openmp) /* flag_openmp_simd */
13946 tree stmt = c_parser_omp_teams (loc, parser, p_name,
13947 OMP_TARGET_CLAUSE_MASK,
13949 return stmt != NULL_TREE;
13951 keep_next_level ();
13952 tree block = c_begin_compound_stmt (true);
13953 tree ret = c_parser_omp_teams (loc, parser, p_name,
13954 OMP_TARGET_CLAUSE_MASK, cclauses);
13955 block = c_end_compound_stmt (loc, block, true);
13956 if (ret == NULL_TREE)
13958 tree stmt = make_node (OMP_TARGET);
13959 TREE_TYPE (stmt) = void_type_node;
13960 OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
13961 OMP_TARGET_BODY (stmt) = block;
13965 else if (!flag_openmp) /* flag_openmp_simd */
13967 c_parser_skip_to_pragma_eol (parser, false);
13970 else if (strcmp (p, "data") == 0)
13972 c_parser_consume_token (parser);
13973 c_parser_omp_target_data (loc, parser);
13976 else if (strcmp (p, "update") == 0)
13978 c_parser_consume_token (parser);
13979 return c_parser_omp_target_update (loc, parser, context);
13983 tree stmt = make_node (OMP_TARGET);
13984 TREE_TYPE (stmt) = void_type_node;
13986 OMP_TARGET_CLAUSES (stmt)
13987 = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
13988 "#pragma omp target");
13989 keep_next_level ();
13990 tree block = c_begin_compound_stmt (true);
13991 add_stmt (c_parser_omp_structured_block (parser));
13992 OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
13994 SET_EXPR_LOCATION (stmt, loc);
14000 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
14002 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
14003 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
14004 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
14006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
14007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
14008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
14011 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
14013 vec<c_token> clauses = vNULL;
14014 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14016 c_token *token = c_parser_peek_token (parser);
14017 if (token->type == CPP_EOF)
14019 c_parser_skip_to_pragma_eol (parser);
14020 clauses.release ();
14023 clauses.safe_push (*token);
14024 c_parser_consume_token (parser);
14026 clauses.safe_push (*c_parser_peek_token (parser));
14027 c_parser_skip_to_pragma_eol (parser);
14029 while (c_parser_next_token_is (parser, CPP_PRAGMA))
14031 if (c_parser_peek_token (parser)->pragma_kind
14032 != PRAGMA_OMP_DECLARE_REDUCTION
14033 || c_parser_peek_2nd_token (parser)->type != CPP_NAME
14034 || strcmp (IDENTIFIER_POINTER
14035 (c_parser_peek_2nd_token (parser)->value),
14038 c_parser_error (parser,
14039 "%<#pragma omp declare simd%> must be followed by "
14040 "function declaration or definition or another "
14041 "%<#pragma omp declare simd%>");
14042 clauses.release ();
14045 c_parser_consume_pragma (parser);
14046 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14048 c_token *token = c_parser_peek_token (parser);
14049 if (token->type == CPP_EOF)
14051 c_parser_skip_to_pragma_eol (parser);
14052 clauses.release ();
14055 clauses.safe_push (*token);
14056 c_parser_consume_token (parser);
14058 clauses.safe_push (*c_parser_peek_token (parser));
14059 c_parser_skip_to_pragma_eol (parser);
14062 /* Make sure nothing tries to read past the end of the tokens. */
14064 memset (&eof_token, 0, sizeof (eof_token));
14065 eof_token.type = CPP_EOF;
14066 clauses.safe_push (eof_token);
14067 clauses.safe_push (eof_token);
14071 case pragma_external:
14072 if (c_parser_next_token_is (parser, CPP_KEYWORD)
14073 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14075 int ext = disable_extension_diagnostics ();
14077 c_parser_consume_token (parser);
14078 while (c_parser_next_token_is (parser, CPP_KEYWORD)
14079 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14080 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14082 restore_extension_diagnostics (ext);
14085 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14088 case pragma_struct:
14090 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14091 "function declaration or definition");
14093 case pragma_compound:
14095 if (c_parser_next_token_is (parser, CPP_KEYWORD)
14096 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14098 int ext = disable_extension_diagnostics ();
14100 c_parser_consume_token (parser);
14101 while (c_parser_next_token_is (parser, CPP_KEYWORD)
14102 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14103 if (c_parser_next_tokens_start_declaration (parser))
14105 c_parser_declaration_or_fndef (parser, true, true, true, true,
14106 true, NULL, clauses);
14107 restore_extension_diagnostics (ext);
14110 restore_extension_diagnostics (ext);
14112 else if (c_parser_next_tokens_start_declaration (parser))
14114 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
14118 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
14119 "function declaration or definition");
14122 gcc_unreachable ();
14124 clauses.release ();
14127 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14128 and put that into "omp declare simd" attribute. */
14131 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
14132 vec<c_token> clauses)
14135 && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14137 error ("%<#pragma omp declare simd%> cannot be used in the same "
14138 "function marked as a Cilk Plus SIMD-enabled function");
14139 vec_free (parser->cilk_simd_fn_tokens);
14143 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
14144 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14145 has already processed the tokens. */
14146 if (clauses.exists () && clauses[0].type == CPP_EOF)
14148 if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
14150 error ("%<#pragma omp declare simd%> not immediately followed by "
14151 "a function declaration or definition");
14152 clauses[0].type = CPP_EOF;
14155 if (clauses.exists () && clauses[0].type != CPP_NAME)
14157 error_at (DECL_SOURCE_LOCATION (fndecl),
14158 "%<#pragma omp declare simd%> not immediately followed by "
14159 "a single function declaration or definition");
14160 clauses[0].type = CPP_EOF;
14164 if (parms == NULL_TREE)
14165 parms = DECL_ARGUMENTS (fndecl);
14167 unsigned int tokens_avail = parser->tokens_avail;
14168 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14169 bool is_cilkplus_cilk_simd_fn = false;
14171 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14173 parser->tokens = parser->cilk_simd_fn_tokens->address ();
14174 parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens);
14175 is_cilkplus_cilk_simd_fn = true;
14179 parser->tokens = clauses.address ();
14180 parser->tokens_avail = clauses.length ();
14183 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
14184 while (parser->tokens_avail > 3)
14186 c_token *token = c_parser_peek_token (parser);
14187 if (!is_cilkplus_cilk_simd_fn)
14188 gcc_assert (token->type == CPP_NAME
14189 && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
14191 gcc_assert (token->type == CPP_NAME
14192 && is_cilkplus_vector_p (token->value));
14193 c_parser_consume_token (parser);
14194 parser->in_pragma = true;
14196 tree c = NULL_TREE;
14197 if (is_cilkplus_cilk_simd_fn)
14198 c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
14199 "SIMD-enabled functions attribute");
14201 c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
14202 "#pragma omp declare simd");
14203 c = c_omp_declare_simd_clauses_to_numbers (parms, c);
14204 if (c != NULL_TREE)
14205 c = tree_cons (NULL_TREE, c, NULL_TREE);
14206 if (is_cilkplus_cilk_simd_fn)
14208 tree k = build_tree_list (get_identifier ("cilk simd function"),
14210 TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
14211 DECL_ATTRIBUTES (fndecl) = k;
14213 c = build_tree_list (get_identifier ("omp declare simd"), c);
14214 TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
14215 DECL_ATTRIBUTES (fndecl) = c;
14218 parser->tokens = &parser->tokens_buf[0];
14219 parser->tokens_avail = tokens_avail;
14220 if (clauses.exists ())
14221 clauses[0].type = CPP_PRAGMA;
14223 if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens))
14224 vec_free (parser->cilk_simd_fn_tokens);
14229 # pragma omp declare target new-line
14230 declarations and definitions
14231 # pragma omp end declare target new-line */
14234 c_parser_omp_declare_target (c_parser *parser)
14236 c_parser_skip_to_pragma_eol (parser);
14237 current_omp_declare_target_attribute++;
14241 c_parser_omp_end_declare_target (c_parser *parser)
14243 location_t loc = c_parser_peek_token (parser)->location;
14244 c_parser_consume_pragma (parser);
14245 if (c_parser_next_token_is (parser, CPP_NAME)
14246 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14249 c_parser_consume_token (parser);
14250 if (c_parser_next_token_is (parser, CPP_NAME)
14251 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
14253 c_parser_consume_token (parser);
14256 c_parser_error (parser, "expected %<target%>");
14257 c_parser_skip_to_pragma_eol (parser);
14263 c_parser_error (parser, "expected %<declare%>");
14264 c_parser_skip_to_pragma_eol (parser);
14267 c_parser_skip_to_pragma_eol (parser);
14268 if (!current_omp_declare_target_attribute)
14269 error_at (loc, "%<#pragma omp end declare target%> without corresponding "
14270 "%<#pragma omp declare target%>");
14272 current_omp_declare_target_attribute--;
14277 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14278 initializer-clause[opt] new-line
14280 initializer-clause:
14281 initializer (omp_priv = initializer)
14282 initializer (function-name (argument-list)) */
14285 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
14287 unsigned int tokens_avail = 0, i;
14288 vec<tree> types = vNULL;
14289 vec<c_token> clauses = vNULL;
14290 enum tree_code reduc_code = ERROR_MARK;
14291 tree reduc_id = NULL_TREE;
14293 location_t rloc = c_parser_peek_token (parser)->location;
14295 if (context == pragma_struct || context == pragma_param)
14297 error ("%<#pragma omp declare reduction%> not at file or block scope");
14301 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14304 switch (c_parser_peek_token (parser)->type)
14307 reduc_code = PLUS_EXPR;
14310 reduc_code = MULT_EXPR;
14313 reduc_code = MINUS_EXPR;
14316 reduc_code = BIT_AND_EXPR;
14319 reduc_code = BIT_XOR_EXPR;
14322 reduc_code = BIT_IOR_EXPR;
14325 reduc_code = TRUTH_ANDIF_EXPR;
14328 reduc_code = TRUTH_ORIF_EXPR;
14332 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14333 if (strcmp (p, "min") == 0)
14335 reduc_code = MIN_EXPR;
14338 if (strcmp (p, "max") == 0)
14340 reduc_code = MAX_EXPR;
14343 reduc_id = c_parser_peek_token (parser)->value;
14346 c_parser_error (parser,
14347 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14348 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14352 tree orig_reduc_id, reduc_decl;
14353 orig_reduc_id = reduc_id;
14354 reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
14355 reduc_decl = c_omp_reduction_decl (reduc_id);
14356 c_parser_consume_token (parser);
14358 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
14363 location_t loc = c_parser_peek_token (parser)->location;
14364 struct c_type_name *ctype = c_parser_type_name (parser);
14367 type = groktypename (ctype, NULL, NULL);
14368 if (type == error_mark_node)
14370 else if ((INTEGRAL_TYPE_P (type)
14371 || TREE_CODE (type) == REAL_TYPE
14372 || TREE_CODE (type) == COMPLEX_TYPE)
14373 && orig_reduc_id == NULL_TREE)
14374 error_at (loc, "predeclared arithmetic type in "
14375 "%<#pragma omp declare reduction%>");
14376 else if (TREE_CODE (type) == FUNCTION_TYPE
14377 || TREE_CODE (type) == ARRAY_TYPE)
14378 error_at (loc, "function or array type in "
14379 "%<#pragma omp declare reduction%>");
14380 else if (TYPE_QUALS_NO_ADDR_SPACE (type))
14381 error_at (loc, "const, volatile or restrict qualified type in "
14382 "%<#pragma omp declare reduction%>");
14386 for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
14387 if (comptypes (TREE_PURPOSE (t), type))
14389 error_at (loc, "redeclaration of %qs "
14390 "%<#pragma omp declare reduction%> for "
14392 IDENTIFIER_POINTER (reduc_id)
14393 + sizeof ("omp declare reduction ") - 1,
14396 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
14398 error_at (ploc, "previous %<#pragma omp declare "
14402 if (t == NULL_TREE)
14403 types.safe_push (type);
14405 if (c_parser_next_token_is (parser, CPP_COMMA))
14406 c_parser_consume_token (parser);
14414 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
14415 || types.is_empty ())
14418 clauses.release ();
14422 c_token *token = c_parser_peek_token (parser);
14423 if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
14425 c_parser_consume_token (parser);
14427 c_parser_skip_to_pragma_eol (parser);
14431 if (types.length () > 1)
14433 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14435 c_token *token = c_parser_peek_token (parser);
14436 if (token->type == CPP_EOF)
14438 clauses.safe_push (*token);
14439 c_parser_consume_token (parser);
14441 clauses.safe_push (*c_parser_peek_token (parser));
14442 c_parser_skip_to_pragma_eol (parser);
14444 /* Make sure nothing tries to read past the end of the tokens. */
14446 memset (&eof_token, 0, sizeof (eof_token));
14447 eof_token.type = CPP_EOF;
14448 clauses.safe_push (eof_token);
14449 clauses.safe_push (eof_token);
14452 int errs = errorcount;
14453 FOR_EACH_VEC_ELT (types, i, type)
14455 tokens_avail = parser->tokens_avail;
14456 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
14457 if (!clauses.is_empty ())
14459 parser->tokens = clauses.address ();
14460 parser->tokens_avail = clauses.length ();
14461 parser->in_pragma = true;
14464 bool nested = current_function_decl != NULL_TREE;
14466 c_push_function_context ();
14467 tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
14468 reduc_id, default_function_type);
14469 current_function_decl = fndecl;
14470 allocate_struct_function (fndecl, true);
14472 tree stmt = push_stmt_list ();
14473 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14474 warn about these. */
14475 tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
14476 get_identifier ("omp_out"), type);
14477 DECL_ARTIFICIAL (omp_out) = 1;
14478 DECL_CONTEXT (omp_out) = fndecl;
14479 pushdecl (omp_out);
14480 tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
14481 get_identifier ("omp_in"), type);
14482 DECL_ARTIFICIAL (omp_in) = 1;
14483 DECL_CONTEXT (omp_in) = fndecl;
14485 struct c_expr combiner = c_parser_expression (parser);
14486 struct c_expr initializer;
14487 tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
14489 initializer.value = error_mark_node;
14490 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14492 else if (c_parser_next_token_is (parser, CPP_NAME)
14493 && strcmp (IDENTIFIER_POINTER
14494 (c_parser_peek_token (parser)->value),
14495 "initializer") == 0)
14497 c_parser_consume_token (parser);
14500 omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
14501 get_identifier ("omp_priv"), type);
14502 DECL_ARTIFICIAL (omp_priv) = 1;
14503 DECL_INITIAL (omp_priv) = error_mark_node;
14504 DECL_CONTEXT (omp_priv) = fndecl;
14505 pushdecl (omp_priv);
14506 omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
14507 get_identifier ("omp_orig"), type);
14508 DECL_ARTIFICIAL (omp_orig) = 1;
14509 DECL_CONTEXT (omp_orig) = fndecl;
14510 pushdecl (omp_orig);
14511 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14513 else if (!c_parser_next_token_is (parser, CPP_NAME))
14515 c_parser_error (parser, "expected %<omp_priv%> or "
14519 else if (strcmp (IDENTIFIER_POINTER
14520 (c_parser_peek_token (parser)->value),
14523 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
14524 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
14526 c_parser_error (parser, "expected function-name %<(%>");
14530 initializer = c_parser_postfix_expression (parser);
14531 if (initializer.value
14532 && TREE_CODE (initializer.value) == CALL_EXPR)
14535 tree c = initializer.value;
14536 for (j = 0; j < call_expr_nargs (c); j++)
14537 if (TREE_CODE (CALL_EXPR_ARG (c, j)) == ADDR_EXPR
14538 && TREE_OPERAND (CALL_EXPR_ARG (c, j), 0) == omp_priv)
14540 if (j == call_expr_nargs (c))
14541 error ("one of the initializer call arguments should be "
14547 c_parser_consume_token (parser);
14548 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
14552 tree st = push_stmt_list ();
14553 start_init (omp_priv, NULL_TREE, 0);
14554 location_t loc = c_parser_peek_token (parser)->location;
14555 struct c_expr init = c_parser_initializer (parser);
14557 finish_decl (omp_priv, loc, init.value,
14558 init.original_type, NULL_TREE);
14559 pop_stmt_list (st);
14563 && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14569 c_parser_skip_to_pragma_eol (parser);
14571 tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
14572 DECL_INITIAL (reduc_decl));
14573 DECL_INITIAL (reduc_decl) = t;
14574 DECL_SOURCE_LOCATION (omp_out) = rloc;
14575 TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
14576 TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
14577 TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
14578 walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
14579 &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
14582 DECL_SOURCE_LOCATION (omp_priv) = rloc;
14583 TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
14584 TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
14585 TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
14586 walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
14587 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14588 walk_tree (&DECL_INITIAL (omp_priv),
14589 c_check_omp_declare_reduction_r,
14590 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
14594 pop_stmt_list (stmt);
14596 if (cfun->language != NULL)
14598 ggc_free (cfun->language);
14599 cfun->language = NULL;
14602 current_function_decl = NULL_TREE;
14604 c_pop_function_context ();
14606 if (!clauses.is_empty ())
14608 parser->tokens = &parser->tokens_buf[0];
14609 parser->tokens_avail = tokens_avail;
14613 if (errs != errorcount)
14617 clauses.release ();
14623 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14624 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14625 initializer-clause[opt] new-line
14626 #pragma omp declare target new-line */
14629 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
14631 c_parser_consume_pragma (parser);
14632 if (c_parser_next_token_is (parser, CPP_NAME))
14634 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14635 if (strcmp (p, "simd") == 0)
14637 /* c_parser_consume_token (parser); done in
14638 c_parser_omp_declare_simd. */
14639 c_parser_omp_declare_simd (parser, context);
14642 if (strcmp (p, "reduction") == 0)
14644 c_parser_consume_token (parser);
14645 c_parser_omp_declare_reduction (parser, context);
14648 if (!flag_openmp) /* flag_openmp_simd */
14650 c_parser_skip_to_pragma_eol (parser, false);
14653 if (strcmp (p, "target") == 0)
14655 c_parser_consume_token (parser);
14656 c_parser_omp_declare_target (parser);
14661 c_parser_error (parser, "expected %<simd%> or %<reduction%> "
14663 c_parser_skip_to_pragma_eol (parser);
14666 /* Main entry point to parsing most OpenMP pragmas. */
14669 c_parser_omp_construct (c_parser *parser)
14671 enum pragma_kind p_kind;
14674 char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
14675 omp_clause_mask mask (0);
14677 loc = c_parser_peek_token (parser)->location;
14678 p_kind = c_parser_peek_token (parser)->pragma_kind;
14679 c_parser_consume_pragma (parser);
14683 case PRAGMA_OACC_CACHE:
14684 strcpy (p_name, "#pragma acc");
14685 stmt = c_parser_oacc_cache (loc, parser);
14687 case PRAGMA_OACC_DATA:
14688 stmt = c_parser_oacc_data (loc, parser);
14690 case PRAGMA_OACC_KERNELS:
14691 strcpy (p_name, "#pragma acc");
14692 stmt = c_parser_oacc_kernels (loc, parser, p_name);
14694 case PRAGMA_OACC_LOOP:
14695 strcpy (p_name, "#pragma acc");
14696 stmt = c_parser_oacc_loop (loc, parser, p_name);
14698 case PRAGMA_OACC_PARALLEL:
14699 strcpy (p_name, "#pragma acc");
14700 stmt = c_parser_oacc_parallel (loc, parser, p_name);
14702 case PRAGMA_OACC_WAIT:
14703 strcpy (p_name, "#pragma wait");
14704 stmt = c_parser_oacc_wait (loc, parser, p_name);
14706 case PRAGMA_OMP_ATOMIC:
14707 c_parser_omp_atomic (loc, parser);
14709 case PRAGMA_OMP_CRITICAL:
14710 stmt = c_parser_omp_critical (loc, parser);
14712 case PRAGMA_OMP_DISTRIBUTE:
14713 strcpy (p_name, "#pragma omp");
14714 stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL);
14716 case PRAGMA_OMP_FOR:
14717 strcpy (p_name, "#pragma omp");
14718 stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL);
14720 case PRAGMA_OMP_MASTER:
14721 stmt = c_parser_omp_master (loc, parser);
14723 case PRAGMA_OMP_ORDERED:
14724 stmt = c_parser_omp_ordered (loc, parser);
14726 case PRAGMA_OMP_PARALLEL:
14727 strcpy (p_name, "#pragma omp");
14728 stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL);
14730 case PRAGMA_OMP_SECTIONS:
14731 strcpy (p_name, "#pragma omp");
14732 stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
14734 case PRAGMA_OMP_SIMD:
14735 strcpy (p_name, "#pragma omp");
14736 stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL);
14738 case PRAGMA_OMP_SINGLE:
14739 stmt = c_parser_omp_single (loc, parser);
14741 case PRAGMA_OMP_TASK:
14742 stmt = c_parser_omp_task (loc, parser);
14744 case PRAGMA_OMP_TASKGROUP:
14745 stmt = c_parser_omp_taskgroup (parser);
14747 case PRAGMA_OMP_TEAMS:
14748 strcpy (p_name, "#pragma omp");
14749 stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL);
14752 gcc_unreachable ();
14756 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
14761 # pragma omp threadprivate (variable-list) */
14764 c_parser_omp_threadprivate (c_parser *parser)
14769 c_parser_consume_pragma (parser);
14770 loc = c_parser_peek_token (parser)->location;
14771 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
14773 /* Mark every variable in VARS to be assigned thread local storage. */
14774 for (t = vars; t; t = TREE_CHAIN (t))
14776 tree v = TREE_PURPOSE (t);
14778 /* FIXME diagnostics: Ideally we should keep individual
14779 locations for all the variables in the var list to make the
14780 following errors more precise. Perhaps
14781 c_parser_omp_var_list_parens() should construct a list of
14782 locations to go along with the var list. */
14784 /* If V had already been marked threadprivate, it doesn't matter
14785 whether it had been used prior to this point. */
14786 if (TREE_CODE (v) != VAR_DECL)
14787 error_at (loc, "%qD is not a variable", v);
14788 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
14789 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
14790 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
14791 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
14792 else if (TREE_TYPE (v) == error_mark_node)
14794 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
14795 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
14798 if (! DECL_THREAD_LOCAL_P (v))
14800 set_decl_tls_model (v, decl_default_tls_model (v));
14801 /* If rtl has been already set for this var, call
14802 make_decl_rtl once again, so that encode_section_info
14803 has a chance to look at the new decl flags. */
14804 if (DECL_RTL_SET_P (v))
14807 C_DECL_THREADPRIVATE_P (v) = 1;
14811 c_parser_skip_to_pragma_eol (parser);
14814 /* Cilk Plus <#pragma simd> parsing routines. */
14816 /* Helper function for c_parser_pragma. Perform some sanity checking
14817 for <#pragma simd> constructs. Returns FALSE if there was a
14821 c_parser_cilk_verify_simd (c_parser *parser,
14822 enum pragma_context context)
14824 if (!flag_cilkplus)
14826 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14827 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14830 if (context == pragma_external)
14832 c_parser_error (parser,"pragma simd must be inside a function");
14833 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
14840 This function is shared by SIMD-enabled functions and #pragma simd.
14841 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14842 CLAUSES is unused. The main purpose of this function is to parse a
14843 vectorlength attribute or clause and check for parse errors.
14844 When IS_SIMD_FN is true then the function is merely caching the tokens
14845 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14846 cache is cleared since there is no reason to continue.
14848 vectorlength ( constant-expression ) */
14851 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses,
14855 check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength");
14857 /* The vectorlength clause behaves exactly like OpenMP's safelen
14858 clause. Represent it in OpenMP terms. */
14859 check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
14861 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14864 location_t loc = c_parser_peek_token (parser)->location;
14865 tree expr = c_parser_expr_no_commas (parser, NULL).value;
14866 expr = c_fully_fold (expr, false, NULL);
14868 /* If expr is an error_mark_node then the above function would have
14869 emitted an error. No reason to do it twice. */
14870 if (expr == error_mark_node)
14872 else if (!TREE_TYPE (expr)
14873 || !TREE_CONSTANT (expr)
14874 || !INTEGRAL_TYPE_P (TREE_TYPE (expr)))
14876 error_at (loc, "vectorlength must be an integer constant");
14877 else if (wi::exact_log2 (expr) == -1)
14878 error_at (loc, "vectorlength must be a power of 2");
14883 tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN);
14884 OMP_CLAUSE_SIMDLEN_EXPR (u) = expr;
14885 OMP_CLAUSE_CHAIN (u) = clauses;
14890 tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN);
14891 OMP_CLAUSE_SAFELEN_EXPR (u) = expr;
14892 OMP_CLAUSE_CHAIN (u) = clauses;
14897 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14903 linear ( simd-linear-variable-list )
14905 simd-linear-variable-list:
14906 simd-linear-variable
14907 simd-linear-variable-list , simd-linear-variable
14909 simd-linear-variable:
14911 id-expression : simd-linear-step
14914 conditional-expression */
14917 c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
14919 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
14922 location_t loc = c_parser_peek_token (parser)->location;
14924 if (c_parser_next_token_is_not (parser, CPP_NAME)
14925 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
14926 c_parser_error (parser, "expected identifier");
14928 while (c_parser_next_token_is (parser, CPP_NAME)
14929 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
14931 tree var = lookup_name (c_parser_peek_token (parser)->value);
14935 undeclared_variable (c_parser_peek_token (parser)->location,
14936 c_parser_peek_token (parser)->value);
14937 c_parser_consume_token (parser);
14939 else if (var == error_mark_node)
14940 c_parser_consume_token (parser);
14943 tree step = integer_one_node;
14945 /* Parse the linear step if present. */
14946 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
14948 c_parser_consume_token (parser);
14949 c_parser_consume_token (parser);
14951 tree expr = c_parser_expr_no_commas (parser, NULL).value;
14952 expr = c_fully_fold (expr, false, NULL);
14954 if (TREE_TYPE (expr)
14955 && INTEGRAL_TYPE_P (TREE_TYPE (expr))
14956 && (TREE_CONSTANT (expr)
14960 c_parser_error (parser,
14961 "step size must be an integer constant "
14962 "expression or an integer variable");
14965 c_parser_consume_token (parser);
14967 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14968 tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR);
14969 OMP_CLAUSE_DECL (u) = var;
14970 OMP_CLAUSE_LINEAR_STEP (u) = step;
14971 OMP_CLAUSE_CHAIN (u) = clauses;
14975 if (c_parser_next_token_is_not (parser, CPP_COMMA))
14978 c_parser_consume_token (parser);
14981 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
14986 /* Returns the name of the next clause. If the clause is not
14987 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14988 not consumed. Otherwise, the appropriate pragma_simd_clause is
14989 returned and the token is consumed. */
14991 static pragma_omp_clause
14992 c_parser_cilk_clause_name (c_parser *parser)
14994 pragma_omp_clause result;
14995 c_token *token = c_parser_peek_token (parser);
14997 if (!token->value || token->type != CPP_NAME)
14998 return PRAGMA_CILK_CLAUSE_NONE;
15000 const char *p = IDENTIFIER_POINTER (token->value);
15002 if (!strcmp (p, "vectorlength"))
15003 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
15004 else if (!strcmp (p, "linear"))
15005 result = PRAGMA_CILK_CLAUSE_LINEAR;
15006 else if (!strcmp (p, "private"))
15007 result = PRAGMA_CILK_CLAUSE_PRIVATE;
15008 else if (!strcmp (p, "firstprivate"))
15009 result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
15010 else if (!strcmp (p, "lastprivate"))
15011 result = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
15012 else if (!strcmp (p, "reduction"))
15013 result = PRAGMA_CILK_CLAUSE_REDUCTION;
15015 return PRAGMA_CILK_CLAUSE_NONE;
15017 c_parser_consume_token (parser);
15021 /* Parse all #<pragma simd> clauses. Return the list of clauses
15025 c_parser_cilk_all_clauses (c_parser *parser)
15027 tree clauses = NULL;
15029 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15031 pragma_omp_clause c_kind;
15033 c_kind = c_parser_cilk_clause_name (parser);
15037 case PRAGMA_CILK_CLAUSE_VECTORLENGTH:
15038 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false);
15040 case PRAGMA_CILK_CLAUSE_LINEAR:
15041 clauses = c_parser_cilk_clause_linear (parser, clauses);
15043 case PRAGMA_CILK_CLAUSE_PRIVATE:
15044 /* Use the OpenMP counterpart. */
15045 clauses = c_parser_omp_clause_private (parser, clauses);
15047 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE:
15048 /* Use the OpenMP counterpart. */
15049 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
15051 case PRAGMA_CILK_CLAUSE_LASTPRIVATE:
15052 /* Use the OpenMP counterpart. */
15053 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
15055 case PRAGMA_CILK_CLAUSE_REDUCTION:
15056 /* Use the OpenMP counterpart. */
15057 clauses = c_parser_omp_clause_reduction (parser, clauses);
15060 c_parser_error (parser, "expected %<#pragma simd%> clause");
15066 c_parser_skip_to_pragma_eol (parser);
15067 return c_finish_cilk_clauses (clauses);
15070 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15071 Here is the correct syntax of this pragma:
15072 #pragma cilk grainsize = <EXP>
15076 c_parser_cilk_grainsize (c_parser *parser)
15078 extern tree convert_to_integer (tree, tree);
15080 /* consume the 'grainsize' keyword. */
15081 c_parser_consume_pragma (parser);
15083 if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0)
15085 struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL);
15086 if (g_expr.value == error_mark_node)
15088 c_parser_skip_to_pragma_eol (parser);
15091 tree grain = convert_to_integer (long_integer_type_node,
15092 c_fully_fold (g_expr.value, false,
15094 c_parser_skip_to_pragma_eol (parser);
15095 c_token *token = c_parser_peek_token (parser);
15096 if (token && token->type == CPP_KEYWORD
15097 && token->keyword == RID_CILK_FOR)
15099 if (grain == NULL_TREE || grain == error_mark_node)
15100 grain = integer_zero_node;
15101 c_parser_cilk_for (parser, grain);
15104 warning (0, "%<#pragma cilk grainsize%> is not followed by "
15108 c_parser_skip_to_pragma_eol (parser);
15111 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
15114 c_parser_cilk_simd (c_parser *parser)
15116 tree clauses = c_parser_cilk_all_clauses (parser);
15117 tree block = c_begin_compound_stmt (true);
15118 location_t loc = c_parser_peek_token (parser)->location;
15119 c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL);
15120 block = c_end_compound_stmt (loc, block, true);
15124 /* Create an artificial decl with TYPE and emit initialization of it with
15128 c_get_temp_regvar (tree type, tree init)
15130 location_t loc = EXPR_LOCATION (init);
15131 tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
15132 DECL_ARTIFICIAL (decl) = 1;
15133 DECL_IGNORED_P (decl) = 1;
15135 tree t = build2 (INIT_EXPR, type, decl, init);
15140 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15141 GRAIN is the grain value passed in through pragma or 0. */
15144 c_parser_cilk_for (c_parser *parser, tree grain)
15146 tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE);
15147 OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR;
15148 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain;
15149 clauses = c_finish_omp_clauses (clauses);
15151 tree block = c_begin_compound_stmt (true);
15152 tree sb = push_stmt_list ();
15153 location_t loc = c_parser_peek_token (parser)->location;
15154 tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL);
15155 sb = pop_stmt_list (sb);
15159 tree omp_par = make_node (OMP_PARALLEL);
15160 TREE_TYPE (omp_par) = void_type_node;
15161 OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE;
15162 tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
15163 TREE_SIDE_EFFECTS (bind) = 1;
15164 BIND_EXPR_BODY (bind) = sb;
15165 OMP_PARALLEL_BODY (omp_par) = bind;
15166 if (OMP_FOR_PRE_BODY (omp_for))
15168 add_stmt (OMP_FOR_PRE_BODY (omp_for));
15169 OMP_FOR_PRE_BODY (omp_for) = NULL_TREE;
15171 tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0);
15172 tree decl = TREE_OPERAND (init, 0);
15173 tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0);
15174 tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
15175 tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE;
15176 if (TREE_CODE (t) != INTEGER_CST)
15178 TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15179 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15180 OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1);
15181 OMP_CLAUSE_CHAIN (c) = clauses;
15184 if (TREE_CODE (incr) == MODIFY_EXPR)
15186 t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15187 if (TREE_CODE (t) != INTEGER_CST)
15189 TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
15190 = c_get_temp_regvar (TREE_TYPE (t), t);
15191 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15192 OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
15193 OMP_CLAUSE_CHAIN (c) = clauses;
15197 t = TREE_OPERAND (init, 1);
15198 if (TREE_CODE (t) != INTEGER_CST)
15200 TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t);
15201 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
15202 OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1);
15203 OMP_CLAUSE_CHAIN (c) = clauses;
15206 c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
15207 OMP_CLAUSE_DECL (c) = decl;
15208 OMP_CLAUSE_CHAIN (c) = clauses;
15210 c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_);
15211 OMP_CLAUSE_OPERAND (c, 0)
15212 = cilk_for_number_of_iterations (omp_for);
15213 OMP_CLAUSE_CHAIN (c) = clauses;
15214 OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c);
15215 add_stmt (omp_par);
15218 block = c_end_compound_stmt (loc, block, true);
15223 /* Parse a transaction attribute (GCC Extension).
15225 transaction-attribute:
15229 The transactional memory language description is written for C++,
15230 and uses the C++0x attribute syntax. For compatibility, allow the
15231 bracket style for transactions in C as well. */
15234 c_parser_transaction_attributes (c_parser *parser)
15236 tree attr_name, attr = NULL;
15238 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
15239 return c_parser_attributes (parser);
15241 if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
15243 c_parser_consume_token (parser);
15244 if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
15247 attr_name = c_parser_attribute_any_word (parser);
15250 c_parser_consume_token (parser);
15251 attr = build_tree_list (attr_name, NULL_TREE);
15254 c_parser_error (parser, "expected identifier");
15256 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15258 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15262 /* Parse a __transaction_atomic or __transaction_relaxed statement
15265 transaction-statement:
15266 __transaction_atomic transaction-attribute[opt] compound-statement
15267 __transaction_relaxed compound-statement
15269 Note that the only valid attribute is: "outer".
15273 c_parser_transaction (c_parser *parser, enum rid keyword)
15275 unsigned int old_in = parser->in_transaction;
15276 unsigned int this_in = 1, new_in;
15277 location_t loc = c_parser_peek_token (parser)->location;
15280 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15281 || keyword == RID_TRANSACTION_RELAXED)
15282 && c_parser_next_token_is_keyword (parser, keyword));
15283 c_parser_consume_token (parser);
15285 if (keyword == RID_TRANSACTION_RELAXED)
15286 this_in |= TM_STMT_ATTR_RELAXED;
15289 attrs = c_parser_transaction_attributes (parser);
15291 this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
15294 /* Keep track if we're in the lexical scope of an outer transaction. */
15295 new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
15297 parser->in_transaction = new_in;
15298 stmt = c_parser_compound_statement (parser);
15299 parser->in_transaction = old_in;
15302 stmt = c_finish_transaction (loc, stmt, this_in);
15304 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15305 "%<__transaction_atomic%> without transactional memory support enabled"
15306 : "%<__transaction_relaxed %> "
15307 "without transactional memory support enabled"));
15312 /* Parse a __transaction_atomic or __transaction_relaxed expression
15315 transaction-expression:
15316 __transaction_atomic ( expression )
15317 __transaction_relaxed ( expression )
15320 static struct c_expr
15321 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
15324 unsigned int old_in = parser->in_transaction;
15325 unsigned int this_in = 1;
15326 location_t loc = c_parser_peek_token (parser)->location;
15329 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
15330 || keyword == RID_TRANSACTION_RELAXED)
15331 && c_parser_next_token_is_keyword (parser, keyword));
15332 c_parser_consume_token (parser);
15334 if (keyword == RID_TRANSACTION_RELAXED)
15335 this_in |= TM_STMT_ATTR_RELAXED;
15338 attrs = c_parser_transaction_attributes (parser);
15340 this_in |= parse_tm_stmt_attr (attrs, 0);
15343 parser->in_transaction = this_in;
15344 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
15346 tree expr = c_parser_expression (parser).value;
15347 ret.original_type = TREE_TYPE (expr);
15348 ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
15349 if (this_in & TM_STMT_ATTR_RELAXED)
15350 TRANSACTION_EXPR_RELAXED (ret.value) = 1;
15351 SET_EXPR_LOCATION (ret.value, loc);
15352 ret.original_code = TRANSACTION_EXPR;
15353 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
15355 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
15362 ret.value = error_mark_node;
15363 ret.original_code = ERROR_MARK;
15364 ret.original_type = NULL;
15366 parser->in_transaction = old_in;
15369 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
15370 "%<__transaction_atomic%> without transactional memory support enabled"
15371 : "%<__transaction_relaxed %> "
15372 "without transactional memory support enabled"));
15377 /* Parse a __transaction_cancel statement (GCC Extension).
15379 transaction-cancel-statement:
15380 __transaction_cancel transaction-attribute[opt] ;
15382 Note that the only valid attribute is "outer".
15386 c_parser_transaction_cancel (c_parser *parser)
15388 location_t loc = c_parser_peek_token (parser)->location;
15390 bool is_outer = false;
15392 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
15393 c_parser_consume_token (parser);
15395 attrs = c_parser_transaction_attributes (parser);
15397 is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
15401 error_at (loc, "%<__transaction_cancel%> without "
15402 "transactional memory support enabled");
15405 else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
15407 error_at (loc, "%<__transaction_cancel%> within a "
15408 "%<__transaction_relaxed%>");
15413 if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
15414 && !is_tm_may_cancel_outer (current_function_decl))
15416 error_at (loc, "outer %<__transaction_cancel%> not "
15417 "within outer %<__transaction_atomic%>");
15418 error_at (loc, " or a %<transaction_may_cancel_outer%> function");
15422 else if (parser->in_transaction == 0)
15424 error_at (loc, "%<__transaction_cancel%> not within "
15425 "%<__transaction_atomic%>");
15429 return add_stmt (build_tm_abort_call (loc, is_outer));
15432 return build1 (NOP_EXPR, void_type_node, error_mark_node);
15435 /* Parse a single source file. */
15438 c_parse_file (void)
15440 /* Use local storage to begin. If the first token is a pragma, parse it.
15441 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15442 which will cause garbage collection. */
15445 memset (&tparser, 0, sizeof tparser);
15446 tparser.tokens = &tparser.tokens_buf[0];
15447 the_parser = &tparser;
15449 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
15450 c_parser_pragma_pch_preprocess (&tparser);
15452 the_parser = ggc_alloc<c_parser> ();
15453 *the_parser = tparser;
15454 if (tparser.tokens == &tparser.tokens_buf[0])
15455 the_parser->tokens = &the_parser->tokens_buf[0];
15457 /* Initialize EH, if we've been told to do so. */
15458 if (flag_exceptions)
15459 using_eh_for_cleanups ();
15461 c_parser_translation_unit (the_parser);
15465 /* This function parses Cilk Plus array notation. The starting index is
15466 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15467 return value of this function is a tree_node called VALUE_TREE of type
15468 ARRAY_NOTATION_REF. */
15471 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
15474 c_token *token = NULL;
15475 tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE;
15476 tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE;
15477 tree array_type_domain = NULL_TREE;
15479 if (array_value == error_mark_node || initial_index == error_mark_node)
15481 /* No need to continue. If either of these 2 were true, then an error
15482 must be emitted already. Thus, no need to emit them twice. */
15483 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15484 return error_mark_node;
15487 array_type = TREE_TYPE (array_value);
15488 gcc_assert (array_type);
15489 if (TREE_CODE (array_type) != ARRAY_TYPE
15490 && TREE_CODE (array_type) != POINTER_TYPE)
15492 error_at (loc, "base of array section must be pointer or array type");
15493 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15494 return error_mark_node;
15496 type = TREE_TYPE (array_type);
15497 token = c_parser_peek_token (parser);
15499 if (token->type == CPP_EOF)
15501 c_parser_error (parser, "expected %<:%> or numeral");
15504 else if (token->type == CPP_COLON)
15506 if (!initial_index)
15508 /* If we are here, then we have a case like this A[:]. */
15509 c_parser_consume_token (parser);
15510 if (TREE_CODE (array_type) == POINTER_TYPE)
15512 error_at (loc, "start-index and length fields necessary for "
15513 "using array notations in pointers");
15514 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15515 return error_mark_node;
15517 if (TREE_CODE (array_type) == FUNCTION_TYPE)
15519 error_at (loc, "array notations cannot be used with function "
15521 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15522 return error_mark_node;
15524 array_type_domain = TYPE_DOMAIN (array_type);
15526 if (!array_type_domain)
15528 error_at (loc, "start-index and length fields necessary for "
15529 "using array notations in dimensionless arrays");
15530 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15531 return error_mark_node;
15534 start_index = TYPE_MINVAL (array_type_domain);
15535 start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node,
15537 if (!TYPE_MAXVAL (array_type_domain)
15538 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain)))
15540 error_at (loc, "start-index and length fields necessary for "
15541 "using array notations in variable-length arrays");
15542 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15543 return error_mark_node;
15545 end_index = TYPE_MAXVAL (array_type_domain);
15546 end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index),
15547 end_index, integer_one_node);
15548 end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index);
15549 stride = build_int_cst (integer_type_node, 1);
15550 stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride);
15552 else if (initial_index != error_mark_node)
15554 /* If we are here, then there should be 2 possibilities:
15555 1. Array [EXPR : EXPR]
15556 2. Array [EXPR : EXPR : EXPR]
15558 start_index = initial_index;
15560 if (TREE_CODE (array_type) == FUNCTION_TYPE)
15562 error_at (loc, "array notations cannot be used with function "
15564 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
15565 return error_mark_node;
15567 c_parser_consume_token (parser); /* consume the ':' */
15568 struct c_expr ce = c_parser_expression (parser);
15569 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15570 end_index = ce.value;
15571 if (!end_index || end_index == error_mark_node)
15573 c_parser_skip_to_end_of_block_or_statement (parser);
15574 return error_mark_node;
15576 if (c_parser_peek_token (parser)->type == CPP_COLON)
15578 c_parser_consume_token (parser);
15579 ce = c_parser_expression (parser);
15580 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
15582 if (!stride || stride == error_mark_node)
15584 c_parser_skip_to_end_of_block_or_statement (parser);
15585 return error_mark_node;
15590 c_parser_error (parser, "expected array notation expression");
15593 c_parser_error (parser, "expected array notation expression");
15595 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
15597 value_tree = build_array_notation_ref (loc, array_value, start_index,
15598 end_index, stride, type);
15599 if (value_tree != error_mark_node)
15600 SET_EXPR_LOCATION (value_tree, loc);
15604 #include "gt-c-c-parser.h"