1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2018 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. */
39 #define INCLUDE_UNIQUE_PTR
41 #include "coretypes.h"
46 #include "stringpool.h"
49 #include "stor-layout.h"
51 #include "trans-mem.h"
52 #include "c-family/c-pragma.h"
54 #include "c-family/c-objc.h"
56 #include "omp-general.h"
57 #include "omp-offload.h"
59 #include "gomp-constants.h"
60 #include "c-family/c-indentation.h"
61 #include "gimple-expr.h"
63 #include "gcc-rich-location.h"
65 #include "gimple-parser.h"
66 #include "read-rtl-function.h"
67 #include "run-rtl-passes.h"
69 #include "c-family/name-hint.h"
70 #include "tree-iterator.h"
72 /* We need to walk over decls with incomplete struct/union/enum types
73 after parsing the whole translation unit.
74 In finish_decl(), if the decl is static, has incomplete
75 struct/union/enum type, it is appeneded to incomplete_record_decls.
76 In c_parser_translation_unit(), we iterate over incomplete_record_decls
77 and report error if any of the decls are still incomplete. */
79 vec<tree> incomplete_record_decls;
82 set_c_expr_source_range (c_expr *expr,
83 location_t start, location_t finish)
85 expr->src_range.m_start = start;
86 expr->src_range.m_finish = finish;
88 set_source_range (expr->value, start, finish);
92 set_c_expr_source_range (c_expr *expr,
93 source_range src_range)
95 expr->src_range = src_range;
97 set_source_range (expr->value, src_range);
101 /* Initialization routine for this file. */
106 /* The only initialization required is of the reserved word
112 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
113 the c_token structure. */
114 gcc_assert (RID_MAX <= 255);
121 mask |= D_ASM | D_EXT;
125 if (!c_dialect_objc ())
126 mask |= D_OBJC | D_CXX_OBJC;
128 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
129 for (i = 0; i < num_c_common_reswords; i++)
131 /* If a keyword is disabled, do not enter it into the table
132 and so create a canonical spelling that isn't a keyword. */
133 if (c_common_reswords[i].disable & mask)
136 && (c_common_reswords[i].disable & D_CXXWARN))
138 id = get_identifier (c_common_reswords[i].word);
139 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
140 C_IS_RESERVED_WORD (id) = 1;
145 id = get_identifier (c_common_reswords[i].word);
146 C_SET_RID_CODE (id, c_common_reswords[i].rid);
147 C_IS_RESERVED_WORD (id) = 1;
148 ridpointers [(int) c_common_reswords[i].rid] = id;
151 for (i = 0; i < NUM_INT_N_ENTS; i++)
153 /* We always create the symbols but they aren't always supported. */
155 sprintf (name, "__int%d", int_n_data[i].bitsize);
156 id = get_identifier (name);
157 C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
158 C_IS_RESERVED_WORD (id) = 1;
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 struct GTY(()) c_parser {
166 /* The look-ahead tokens. */
167 c_token * GTY((skip)) tokens;
168 /* Buffer for look-ahead tokens. */
169 c_token tokens_buf[4];
170 /* How many look-ahead tokens are available (0 - 4, or
171 more if parsing from pre-lexed tokens). */
172 unsigned int tokens_avail;
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error : 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma : 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block : 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string : 1;
185 /* Objective-C specific parser/lexer information. */
187 /* True if we are in a context where the Objective-C "PQ" keywords
188 are considered keywords. */
189 BOOL_BITFIELD objc_pq_context : 1;
190 /* True if we are parsing a (potential) Objective-C foreach
191 statement. This is set to true after we parsed 'for (' and while
192 we wait for 'in' or ';' to decide if it's a standard C for loop or an
193 Objective-C foreach loop. */
194 BOOL_BITFIELD objc_could_be_foreach_context : 1;
195 /* The following flag is needed to contextualize Objective-C lexical
196 analysis. In some cases (e.g., 'int NSObject;'), it is
197 undesirable to bind an identifier to an Objective-C class, even
198 if a class with that name exists. */
199 BOOL_BITFIELD objc_need_raw_identifier : 1;
200 /* Nonzero if we're processing a __transaction statement. The value
201 is 1 | TM_STMT_ATTR_*. */
202 unsigned int in_transaction : 4;
203 /* True if we are in a context where the Objective-C "Property attribute"
204 keywords are valid. */
205 BOOL_BITFIELD objc_property_attr_context : 1;
207 /* Location of the last consumed token. */
208 location_t last_token_location;
211 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
214 c_parser_tokens_buf (c_parser *parser, unsigned n)
216 return &parser->tokens_buf[n];
219 /* Return the error state of PARSER. */
222 c_parser_error (c_parser *parser)
224 return parser->error;
227 /* Set the error state of PARSER to ERR. */
230 c_parser_set_error (c_parser *parser, bool err)
236 /* The actual parser and external interface. ??? Does this need to be
237 garbage-collected? */
239 static GTY (()) c_parser *the_parser;
241 /* Read in and lex a single token, storing it in *TOKEN. */
244 c_lex_one_token (c_parser *parser, c_token *token)
246 timevar_push (TV_LEX);
248 token->type = c_lex_with_flags (&token->value, &token->location,
250 (parser->lex_untranslated_string
251 ? C_LEX_STRING_NO_TRANSLATE : 0));
252 token->id_kind = C_ID_NONE;
253 token->keyword = RID_MAX;
254 token->pragma_kind = PRAGMA_NONE;
262 bool objc_force_identifier = parser->objc_need_raw_identifier;
263 if (c_dialect_objc ())
264 parser->objc_need_raw_identifier = false;
266 if (C_IS_RESERVED_WORD (token->value))
268 enum rid rid_code = C_RID_CODE (token->value);
270 if (rid_code == RID_CXX_COMPAT_WARN)
272 warning_at (token->location,
274 "identifier %qE conflicts with C++ keyword",
277 else if (rid_code >= RID_FIRST_ADDR_SPACE
278 && rid_code <= RID_LAST_ADDR_SPACE)
281 as = (addr_space_t) (rid_code - RID_FIRST_ADDR_SPACE);
282 targetm.addr_space.diagnose_usage (as, token->location);
283 token->id_kind = C_ID_ADDRSPACE;
284 token->keyword = rid_code;
287 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
289 /* We found an Objective-C "pq" keyword (in, out,
290 inout, bycopy, byref, oneway). They need special
291 care because the interpretation depends on the
293 if (parser->objc_pq_context)
295 token->type = CPP_KEYWORD;
296 token->keyword = rid_code;
299 else if (parser->objc_could_be_foreach_context
300 && rid_code == RID_IN)
302 /* We are in Objective-C, inside a (potential)
303 foreach context (which means after having
304 parsed 'for (', but before having parsed ';'),
305 and we found 'in'. We consider it the keyword
306 which terminates the declaration at the
307 beginning of a foreach-statement. Note that
308 this means you can't use 'in' for anything else
309 in that context; in particular, in Objective-C
310 you can't use 'in' as the name of the running
311 variable in a C for loop. We could potentially
312 try to add code here to disambiguate, but it
313 seems a reasonable limitation. */
314 token->type = CPP_KEYWORD;
315 token->keyword = rid_code;
318 /* Else, "pq" keywords outside of the "pq" context are
319 not keywords, and we fall through to the code for
322 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
324 /* We found an Objective-C "property attribute"
325 keyword (getter, setter, readonly, etc). These are
326 only valid in the property context. */
327 if (parser->objc_property_attr_context)
329 token->type = CPP_KEYWORD;
330 token->keyword = rid_code;
333 /* Else they are not special keywords.
336 else if (c_dialect_objc ()
337 && (OBJC_IS_AT_KEYWORD (rid_code)
338 || OBJC_IS_CXX_KEYWORD (rid_code)))
340 /* We found one of the Objective-C "@" keywords (defs,
341 selector, synchronized, etc) or one of the
342 Objective-C "cxx" keywords (class, private,
343 protected, public, try, catch, throw) without a
344 preceding '@' sign. Do nothing and fall through to
345 the code for normal tokens (in C++ we would still
346 consider the CXX ones keywords, but not in C). */
351 token->type = CPP_KEYWORD;
352 token->keyword = rid_code;
357 decl = lookup_name (token->value);
360 if (TREE_CODE (decl) == TYPE_DECL)
362 token->id_kind = C_ID_TYPENAME;
366 else if (c_dialect_objc ())
368 tree objc_interface_decl = objc_is_class_name (token->value);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
372 if (objc_interface_decl
373 && (!objc_force_identifier || global_bindings_p ()))
375 token->value = objc_interface_decl;
376 token->id_kind = C_ID_CLASSNAME;
380 token->id_kind = C_ID_ID;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token->type = CPP_KEYWORD;
386 switch (C_RID_CODE (token->value))
388 /* Replace 'class' with '@class', 'private' with '@private',
389 etc. This prevents confusion with the C++ keyword
390 'class', and makes the tokens consistent with other
391 Objective-C 'AT' keywords. For example '@class' is
392 reported as RID_AT_CLASS which is consistent with
393 '@synchronized', which is reported as
396 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
397 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
398 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
399 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
400 case RID_THROW: token->keyword = RID_AT_THROW; break;
401 case RID_TRY: token->keyword = RID_AT_TRY; break;
402 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
403 case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break;
404 default: token->keyword = C_RID_CODE (token->value);
409 case CPP_CLOSE_PAREN:
411 /* These tokens may affect the interpretation of any identifiers
412 following, if doing Objective-C. */
413 if (c_dialect_objc ())
414 parser->objc_need_raw_identifier = false;
417 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
418 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
424 timevar_pop (TV_LEX);
427 /* Return a pointer to the next token from PARSER, reading it in if
431 c_parser_peek_token (c_parser *parser)
433 if (parser->tokens_avail == 0)
435 c_lex_one_token (parser, &parser->tokens[0]);
436 parser->tokens_avail = 1;
438 return &parser->tokens[0];
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
445 c_parser_peek_2nd_token (c_parser *parser)
447 if (parser->tokens_avail >= 2)
448 return &parser->tokens[1];
449 gcc_assert (parser->tokens_avail == 1);
450 gcc_assert (parser->tokens[0].type != CPP_EOF);
451 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
452 c_lex_one_token (parser, &parser->tokens[1]);
453 parser->tokens_avail = 2;
454 return &parser->tokens[1];
457 /* Return a pointer to the Nth token from PARSER, reading it
458 in if necessary. The N-1th token is already read in. */
461 c_parser_peek_nth_token (c_parser *parser, unsigned int n)
463 /* N is 1-based, not zero-based. */
466 if (parser->tokens_avail >= n)
467 return &parser->tokens[n - 1];
468 gcc_assert (parser->tokens_avail == n - 1);
469 c_lex_one_token (parser, &parser->tokens[n - 1]);
470 parser->tokens_avail = n;
471 return &parser->tokens[n - 1];
475 c_keyword_starts_typename (enum rid keyword)
510 if (keyword >= RID_FIRST_INT_N
511 && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
512 && int_n_enabled_p[keyword - RID_FIRST_INT_N])
518 /* Return true if TOKEN can start a type name,
521 c_token_starts_typename (c_token *token)
526 switch (token->id_kind)
535 gcc_assert (c_dialect_objc ());
541 return c_keyword_starts_typename (token->keyword);
543 if (c_dialect_objc ())
551 /* Return true if the next token from PARSER can start a type name,
552 false otherwise. LA specifies how to do lookahead in order to
553 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
556 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
558 c_token *token = c_parser_peek_token (parser);
559 if (c_token_starts_typename (token))
562 /* Try a bit harder to detect an unknown typename. */
563 if (la != cla_prefer_id
564 && token->type == CPP_NAME
565 && token->id_kind == C_ID_ID
567 /* Do not try too hard when we could have "object in array". */
568 && !parser->objc_could_be_foreach_context
570 && (la == cla_prefer_type
571 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
572 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
574 /* Only unknown identifiers. */
575 && !lookup_name (token->value))
581 /* Return true if TOKEN is a type qualifier, false otherwise. */
583 c_token_is_qualifier (c_token *token)
588 switch (token->id_kind)
596 switch (token->keyword)
614 /* Return true if the next token from PARSER is a type qualifier,
617 c_parser_next_token_is_qualifier (c_parser *parser)
619 c_token *token = c_parser_peek_token (parser);
620 return c_token_is_qualifier (token);
623 /* Return true if TOKEN can start declaration specifiers, false
626 c_token_starts_declspecs (c_token *token)
631 switch (token->id_kind)
640 gcc_assert (c_dialect_objc ());
646 switch (token->keyword)
687 if (token->keyword >= RID_FIRST_INT_N
688 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
689 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N])
694 if (c_dialect_objc ())
703 /* Return true if TOKEN can start declaration specifiers or a static
704 assertion, false otherwise. */
706 c_token_starts_declaration (c_token *token)
708 if (c_token_starts_declspecs (token)
709 || token->keyword == RID_STATIC_ASSERT)
715 /* Return true if the next token from PARSER can start declaration
716 specifiers, false otherwise. */
718 c_parser_next_token_starts_declspecs (c_parser *parser)
720 c_token *token = c_parser_peek_token (parser);
722 /* In Objective-C, a classname normally starts a declspecs unless it
723 is immediately followed by a dot. In that case, it is the
724 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
725 setter/getter on the class. c_token_starts_declspecs() can't
726 differentiate between the two cases because it only checks the
727 current token, so we have a special check here. */
728 if (c_dialect_objc ()
729 && token->type == CPP_NAME
730 && token->id_kind == C_ID_CLASSNAME
731 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
734 return c_token_starts_declspecs (token);
737 /* Return true if the next tokens from PARSER can start declaration
738 specifiers or a static assertion, false otherwise. */
740 c_parser_next_tokens_start_declaration (c_parser *parser)
742 c_token *token = c_parser_peek_token (parser);
745 if (c_dialect_objc ()
746 && token->type == CPP_NAME
747 && token->id_kind == C_ID_CLASSNAME
748 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
751 /* Labels do not start declarations. */
752 if (token->type == CPP_NAME
753 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
756 if (c_token_starts_declaration (token))
759 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
765 /* Consume the next token from PARSER. */
768 c_parser_consume_token (c_parser *parser)
770 gcc_assert (parser->tokens_avail >= 1);
771 gcc_assert (parser->tokens[0].type != CPP_EOF);
772 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
773 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
774 parser->last_token_location = parser->tokens[0].location;
775 if (parser->tokens != &parser->tokens_buf[0])
777 else if (parser->tokens_avail == 2)
778 parser->tokens[0] = parser->tokens[1];
779 parser->tokens_avail--;
782 /* Expect the current token to be a #pragma. Consume it and remember
783 that we've begun parsing a pragma. */
786 c_parser_consume_pragma (c_parser *parser)
788 gcc_assert (!parser->in_pragma);
789 gcc_assert (parser->tokens_avail >= 1);
790 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
791 if (parser->tokens != &parser->tokens_buf[0])
793 else if (parser->tokens_avail == 2)
794 parser->tokens[0] = parser->tokens[1];
795 parser->tokens_avail--;
796 parser->in_pragma = true;
799 /* Update the global input_location from TOKEN. */
801 c_parser_set_source_position_from_token (c_token *token)
803 if (token->type != CPP_EOF)
805 input_location = token->location;
809 /* Helper function for c_parser_error.
810 Having peeked a token of kind TOK1_KIND that might signify
811 a conflict marker, peek successor tokens to determine
812 if we actually do have a conflict marker.
813 Specifically, we consider a run of 7 '<', '=' or '>' characters
814 at the start of a line as a conflict marker.
815 These come through the lexer as three pairs and a single,
816 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
817 If it returns true, *OUT_LOC is written to with the location/range
821 c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind,
824 c_token *token2 = c_parser_peek_2nd_token (parser);
825 if (token2->type != tok1_kind)
827 c_token *token3 = c_parser_peek_nth_token (parser, 3);
828 if (token3->type != tok1_kind)
830 c_token *token4 = c_parser_peek_nth_token (parser, 4);
831 if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind))
834 /* It must be at the start of the line. */
835 location_t start_loc = c_parser_peek_token (parser)->location;
836 if (LOCATION_COLUMN (start_loc) != 1)
839 /* We have a conflict marker. Construct a location of the form:
842 with start == caret, finishing at the end of the marker. */
843 location_t finish_loc = get_finish (token4->location);
844 *out_loc = make_location (start_loc, start_loc, finish_loc);
849 /* Issue a diagnostic of the form
850 FILE:LINE: MESSAGE before TOKEN
851 where TOKEN is the next token in the input stream of PARSER.
852 MESSAGE (specified by the caller) is usually of the form "expected
855 Use RICHLOC as the location of the diagnostic.
857 Do not issue a diagnostic if still recovering from an error.
859 Return true iff an error was actually emitted.
861 ??? This is taken from the C++ parser, but building up messages in
862 this way is not i18n-friendly and some other approach should be
866 c_parser_error_richloc (c_parser *parser, const char *gmsgid,
867 rich_location *richloc)
869 c_token *token = c_parser_peek_token (parser);
872 parser->error = true;
876 /* If this is actually a conflict marker, report it as such. */
877 if (token->type == CPP_LSHIFT
878 || token->type == CPP_RSHIFT
879 || token->type == CPP_EQ_EQ)
882 if (c_parser_peek_conflict_marker (parser, token->type, &loc))
884 error_at (loc, "version control conflict marker in file");
889 c_parse_error (gmsgid,
890 /* Because c_parse_error does not understand
891 CPP_KEYWORD, keywords are treated like
893 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
894 /* ??? The C parser does not save the cpp flags of a
895 token, we need to pass 0 here and we will not get
896 the source spelling of some tokens but rather the
897 canonical spelling. */
898 token->value, /*flags=*/0, richloc);
902 /* As c_parser_error_richloc, but issue the message at the
903 location of PARSER's next token, or at input_location
904 if the next token is EOF. */
907 c_parser_error (c_parser *parser, const char *gmsgid)
909 c_token *token = c_parser_peek_token (parser);
910 c_parser_set_source_position_from_token (token);
911 rich_location richloc (line_table, input_location);
912 return c_parser_error_richloc (parser, gmsgid, &richloc);
915 /* Some tokens naturally come in pairs e.g.'(' and ')'.
916 This class is for tracking such a matching pair of symbols.
917 In particular, it tracks the location of the first token,
918 so that if the second token is missing, we can highlight the
919 location of the first token when notifying the user about the
922 template <typename traits_t>
926 /* token_pair's ctor. */
927 token_pair () : m_open_loc (UNKNOWN_LOCATION) {}
929 /* If the next token is the opening symbol for this pair, consume it and
931 Otherwise, issue an error and return false.
932 In either case, record the location of the opening token. */
934 bool require_open (c_parser *parser)
936 c_token *token = c_parser_peek_token (parser);
938 m_open_loc = token->location;
940 return c_parser_require (parser, traits_t::open_token_type,
941 traits_t::open_gmsgid);
944 /* Consume the next token from PARSER, recording its location as
945 that of the opening token within the pair. */
947 void consume_open (c_parser *parser)
949 c_token *token = c_parser_peek_token (parser);
950 gcc_assert (token->type == traits_t::open_token_type);
951 m_open_loc = token->location;
952 c_parser_consume_token (parser);
955 /* If the next token is the closing symbol for this pair, consume it
957 Otherwise, issue an error, highlighting the location of the
958 corresponding opening token, and return false. */
960 bool require_close (c_parser *parser) const
962 return c_parser_require (parser, traits_t::close_token_type,
963 traits_t::close_gmsgid, m_open_loc);
966 /* Like token_pair::require_close, except that tokens will be skipped
967 until the desired token is found. An error message is still produced
968 if the next token is not as expected. */
970 void skip_until_found_close (c_parser *parser) const
972 c_parser_skip_until_found (parser, traits_t::close_token_type,
973 traits_t::close_gmsgid, m_open_loc);
977 location_t m_open_loc;
980 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
982 struct matching_paren_traits
984 static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN;
985 static const char * const open_gmsgid;
986 static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN;
987 static const char * const close_gmsgid;
990 const char * const matching_paren_traits::open_gmsgid = "expected %<(%>";
991 const char * const matching_paren_traits::close_gmsgid = "expected %<)%>";
993 /* "matching_parens" is a token_pair<T> class for tracking matching
994 pairs of parentheses. */
996 typedef token_pair<matching_paren_traits> matching_parens;
998 /* Traits for token_pair<T> for tracking matching pairs of braces. */
1000 struct matching_brace_traits
1002 static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE;
1003 static const char * const open_gmsgid;
1004 static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE;
1005 static const char * const close_gmsgid;
1008 const char * const matching_brace_traits::open_gmsgid = "expected %<{%>";
1009 const char * const matching_brace_traits::close_gmsgid = "expected %<}%>";
1011 /* "matching_braces" is a token_pair<T> class for tracking matching
1014 typedef token_pair<matching_brace_traits> matching_braces;
1016 /* Get a description of the matching symbol to TYPE e.g. "(" for
1020 get_matching_symbol (enum cpp_ttype type)
1027 case CPP_CLOSE_PAREN:
1029 case CPP_CLOSE_BRACE:
1034 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1035 issue the error MSGID. If MSGID is NULL then a message has already
1036 been produced and no message will be produced this time. Returns
1037 true if found, false otherwise.
1039 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1040 within any error as the location of an "opening" token matching
1041 the close token TYPE (e.g. the location of the '(' when TYPE is
1044 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1045 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1046 attempt to generate a fix-it hint for the problem.
1047 Otherwise msgid describes multiple token types (e.g.
1048 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1049 generate a fix-it hint. */
1052 c_parser_require (c_parser *parser,
1053 enum cpp_ttype type,
1055 location_t matching_location,
1056 bool type_is_unique)
1058 if (c_parser_next_token_is (parser, type))
1060 c_parser_consume_token (parser);
1065 location_t next_token_loc = c_parser_peek_token (parser)->location;
1066 gcc_rich_location richloc (next_token_loc);
1068 /* Potentially supply a fix-it hint, suggesting to add the
1069 missing token immediately after the *previous* token.
1070 This may move the primary location within richloc. */
1071 if (!parser->error && type_is_unique)
1072 maybe_suggest_missing_token_insertion (&richloc, type,
1073 parser->last_token_location);
1075 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1076 Attempt to consolidate diagnostics by printing it as a
1077 secondary range within the main diagnostic. */
1078 bool added_matching_location = false;
1079 if (matching_location != UNKNOWN_LOCATION)
1080 added_matching_location
1081 = richloc.add_location_if_nearby (matching_location);
1083 if (c_parser_error_richloc (parser, msgid, &richloc))
1084 /* If we weren't able to consolidate matching_location, then
1085 print it as a secondary diagnostic. */
1086 if (matching_location != UNKNOWN_LOCATION && !added_matching_location)
1087 inform (matching_location, "to match this %qs",
1088 get_matching_symbol (type));
1094 /* If the next token is the indicated keyword, consume it. Otherwise,
1095 issue the error MSGID. Returns true if found, false otherwise. */
1098 c_parser_require_keyword (c_parser *parser,
1102 if (c_parser_next_token_is_keyword (parser, keyword))
1104 c_parser_consume_token (parser);
1109 c_parser_error (parser, msgid);
1114 /* Like c_parser_require, except that tokens will be skipped until the
1115 desired token is found. An error message is still produced if the
1116 next token is not as expected. If MSGID is NULL then a message has
1117 already been produced and no message will be produced this
1120 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1121 within any error as the location of an "opening" token matching
1122 the close token TYPE (e.g. the location of the '(' when TYPE is
1123 CPP_CLOSE_PAREN). */
1126 c_parser_skip_until_found (c_parser *parser,
1127 enum cpp_ttype type,
1129 location_t matching_location)
1131 unsigned nesting_depth = 0;
1133 if (c_parser_require (parser, type, msgid, matching_location))
1136 /* Skip tokens until the desired token is found. */
1139 /* Peek at the next token. */
1140 c_token *token = c_parser_peek_token (parser);
1141 /* If we've reached the token we want, consume it and stop. */
1142 if (token->type == type && !nesting_depth)
1144 c_parser_consume_token (parser);
1148 /* If we've run out of tokens, stop. */
1149 if (token->type == CPP_EOF)
1151 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1153 if (token->type == CPP_OPEN_BRACE
1154 || token->type == CPP_OPEN_PAREN
1155 || token->type == CPP_OPEN_SQUARE)
1157 else if (token->type == CPP_CLOSE_BRACE
1158 || token->type == CPP_CLOSE_PAREN
1159 || token->type == CPP_CLOSE_SQUARE)
1161 if (nesting_depth-- == 0)
1164 /* Consume this token. */
1165 c_parser_consume_token (parser);
1167 parser->error = false;
1170 /* Skip tokens until the end of a parameter is found, but do not
1171 consume the comma, semicolon or closing delimiter. */
1174 c_parser_skip_to_end_of_parameter (c_parser *parser)
1176 unsigned nesting_depth = 0;
1180 c_token *token = c_parser_peek_token (parser);
1181 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
1184 /* If we've run out of tokens, stop. */
1185 if (token->type == CPP_EOF)
1187 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
1189 if (token->type == CPP_OPEN_BRACE
1190 || token->type == CPP_OPEN_PAREN
1191 || token->type == CPP_OPEN_SQUARE)
1193 else if (token->type == CPP_CLOSE_BRACE
1194 || token->type == CPP_CLOSE_PAREN
1195 || token->type == CPP_CLOSE_SQUARE)
1197 if (nesting_depth-- == 0)
1200 /* Consume this token. */
1201 c_parser_consume_token (parser);
1203 parser->error = false;
1206 /* Expect to be at the end of the pragma directive and consume an
1207 end of line marker. */
1210 c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
1212 gcc_assert (parser->in_pragma);
1213 parser->in_pragma = false;
1215 if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
1216 c_parser_error (parser, "expected end of line");
1218 cpp_ttype token_type;
1221 c_token *token = c_parser_peek_token (parser);
1222 token_type = token->type;
1223 if (token_type == CPP_EOF)
1225 c_parser_consume_token (parser);
1227 while (token_type != CPP_PRAGMA_EOL);
1229 parser->error = false;
1232 /* Skip tokens until we have consumed an entire block, or until we
1233 have consumed a non-nested ';'. */
1236 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
1238 unsigned nesting_depth = 0;
1239 bool save_error = parser->error;
1245 /* Peek at the next token. */
1246 token = c_parser_peek_token (parser);
1248 switch (token->type)
1253 case CPP_PRAGMA_EOL:
1254 if (parser->in_pragma)
1259 /* If the next token is a ';', we have reached the
1260 end of the statement. */
1263 /* Consume the ';'. */
1264 c_parser_consume_token (parser);
1269 case CPP_CLOSE_BRACE:
1270 /* If the next token is a non-nested '}', then we have
1271 reached the end of the current block. */
1272 if (nesting_depth == 0 || --nesting_depth == 0)
1274 c_parser_consume_token (parser);
1279 case CPP_OPEN_BRACE:
1280 /* If it the next token is a '{', then we are entering a new
1281 block. Consume the entire block. */
1286 /* If we see a pragma, consume the whole thing at once. We
1287 have some safeguards against consuming pragmas willy-nilly.
1288 Normally, we'd expect to be here with parser->error set,
1289 which disables these safeguards. But it's possible to get
1290 here for secondary error recovery, after parser->error has
1292 c_parser_consume_pragma (parser);
1293 c_parser_skip_to_pragma_eol (parser);
1294 parser->error = save_error;
1301 c_parser_consume_token (parser);
1305 parser->error = false;
1308 /* CPP's options (initialized by c-opts.c). */
1309 extern cpp_options *cpp_opts;
1311 /* Save the warning flags which are controlled by __extension__. */
1314 disable_extension_diagnostics (void)
1317 | (warn_pointer_arith << 1)
1318 | (warn_traditional << 2)
1320 | (warn_long_long << 4)
1321 | (warn_cxx_compat << 5)
1322 | (warn_overlength_strings << 6)
1323 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1324 play tricks to properly restore it. */
1325 | ((warn_c90_c99_compat == 1) << 7)
1326 | ((warn_c90_c99_compat == -1) << 8)
1327 /* Similarly for warn_c99_c11_compat. */
1328 | ((warn_c99_c11_compat == 1) << 9)
1329 | ((warn_c99_c11_compat == -1) << 10)
1331 cpp_opts->cpp_pedantic = pedantic = 0;
1332 warn_pointer_arith = 0;
1333 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1335 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1336 warn_cxx_compat = 0;
1337 warn_overlength_strings = 0;
1338 warn_c90_c99_compat = 0;
1339 warn_c99_c11_compat = 0;
1343 /* Restore the warning flags which are controlled by __extension__.
1344 FLAGS is the return value from disable_extension_diagnostics. */
1347 restore_extension_diagnostics (int flags)
1349 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1350 warn_pointer_arith = (flags >> 1) & 1;
1351 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1352 flag_iso = (flags >> 3) & 1;
1353 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1354 warn_cxx_compat = (flags >> 5) & 1;
1355 warn_overlength_strings = (flags >> 6) & 1;
1356 /* See above for why is this needed. */
1357 warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
1358 warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
1361 /* Helper data structure for parsing #pragma acc routine. */
1362 struct oacc_routine_data {
1363 bool error_seen; /* Set if error has been reported. */
1364 bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */
1369 static void c_parser_external_declaration (c_parser *);
1370 static void c_parser_asm_definition (c_parser *);
1371 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1372 bool, bool, tree *, vec<c_token>,
1373 struct oacc_routine_data * = NULL,
1375 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1376 static void c_parser_static_assert_declaration (c_parser *);
1377 static struct c_typespec c_parser_enum_specifier (c_parser *);
1378 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1379 static tree c_parser_struct_declaration (c_parser *);
1380 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1381 static tree c_parser_alignas_specifier (c_parser *);
1382 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1384 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1386 struct c_declarator *);
1387 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1388 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1390 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1391 static tree c_parser_simple_asm_expr (c_parser *);
1392 static tree c_parser_attributes (c_parser *);
1393 static struct c_expr c_parser_initializer (c_parser *);
1394 static struct c_expr c_parser_braced_init (c_parser *, tree, bool,
1396 static void c_parser_initelt (c_parser *, struct obstack *);
1397 static void c_parser_initval (c_parser *, struct c_expr *,
1399 static tree c_parser_compound_statement (c_parser *);
1400 static void c_parser_compound_statement_nostart (c_parser *);
1401 static void c_parser_label (c_parser *);
1402 static void c_parser_statement (c_parser *, bool *, location_t * = NULL);
1403 static void c_parser_statement_after_labels (c_parser *, bool *,
1404 vec<tree> * = NULL);
1405 static tree c_parser_c99_block_statement (c_parser *, bool *,
1406 location_t * = NULL);
1407 static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
1408 static void c_parser_switch_statement (c_parser *, bool *);
1409 static void c_parser_while_statement (c_parser *, bool, unsigned short, bool *);
1410 static void c_parser_do_statement (c_parser *, bool, unsigned short);
1411 static void c_parser_for_statement (c_parser *, bool, unsigned short, bool *);
1412 static tree c_parser_asm_statement (c_parser *);
1413 static tree c_parser_asm_operands (c_parser *);
1414 static tree c_parser_asm_goto_operands (c_parser *);
1415 static tree c_parser_asm_clobbers (c_parser *);
1416 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *,
1418 static struct c_expr c_parser_conditional_expression (c_parser *,
1419 struct c_expr *, tree);
1420 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1422 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1423 static struct c_expr c_parser_unary_expression (c_parser *);
1424 static struct c_expr c_parser_sizeof_expression (c_parser *);
1425 static struct c_expr c_parser_alignof_expression (c_parser *);
1426 static struct c_expr c_parser_postfix_expression (c_parser *);
1427 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1428 struct c_type_name *,
1430 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1433 static tree c_parser_transaction (c_parser *, enum rid);
1434 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid);
1435 static tree c_parser_transaction_cancel (c_parser *);
1436 static struct c_expr c_parser_expression (c_parser *);
1437 static struct c_expr c_parser_expression_conv (c_parser *);
1438 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
1439 vec<tree, va_gc> **, location_t *,
1440 tree *, vec<location_t> *,
1441 unsigned int * = NULL);
1442 static void c_parser_oacc_declare (c_parser *);
1443 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
1444 static void c_parser_oacc_update (c_parser *);
1445 static void c_parser_omp_construct (c_parser *, bool *);
1446 static void c_parser_omp_threadprivate (c_parser *);
1447 static void c_parser_omp_barrier (c_parser *);
1448 static void c_parser_omp_flush (c_parser *);
1449 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
1450 tree, tree *, bool *);
1451 static void c_parser_omp_taskwait (c_parser *);
1452 static void c_parser_omp_taskyield (c_parser *);
1453 static void c_parser_omp_cancel (c_parser *);
1455 enum pragma_context { pragma_external, pragma_struct, pragma_param,
1456 pragma_stmt, pragma_compound };
1457 static bool c_parser_pragma (c_parser *, enum pragma_context, bool *);
1458 static void c_parser_omp_cancellation_point (c_parser *, enum pragma_context);
1459 static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
1460 static void c_parser_omp_end_declare_target (c_parser *);
1461 static void c_parser_omp_declare (c_parser *, enum pragma_context);
1462 static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
1463 static void c_parser_oacc_routine (c_parser *, enum pragma_context);
1465 /* These Objective-C parser functions are only ever called when
1466 compiling Objective-C. */
1467 static void c_parser_objc_class_definition (c_parser *, tree);
1468 static void c_parser_objc_class_instance_variables (c_parser *);
1469 static void c_parser_objc_class_declaration (c_parser *);
1470 static void c_parser_objc_alias_declaration (c_parser *);
1471 static void c_parser_objc_protocol_definition (c_parser *, tree);
1472 static bool c_parser_objc_method_type (c_parser *);
1473 static void c_parser_objc_method_definition (c_parser *);
1474 static void c_parser_objc_methodprotolist (c_parser *);
1475 static void c_parser_objc_methodproto (c_parser *);
1476 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1477 static tree c_parser_objc_type_name (c_parser *);
1478 static tree c_parser_objc_protocol_refs (c_parser *);
1479 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1480 static void c_parser_objc_synchronized_statement (c_parser *);
1481 static tree c_parser_objc_selector (c_parser *);
1482 static tree c_parser_objc_selector_arg (c_parser *);
1483 static tree c_parser_objc_receiver (c_parser *);
1484 static tree c_parser_objc_message_args (c_parser *);
1485 static tree c_parser_objc_keywordexpr (c_parser *);
1486 static void c_parser_objc_at_property_declaration (c_parser *);
1487 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1488 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1489 static bool c_parser_objc_diagnose_bad_element_prefix
1490 (c_parser *, struct c_declspecs *);
1492 static void c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass);
1494 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1497 external-declarations
1499 external-declarations:
1500 external-declaration
1501 external-declarations external-declaration
1510 c_parser_translation_unit (c_parser *parser)
1512 if (c_parser_next_token_is (parser, CPP_EOF))
1514 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1515 "ISO C forbids an empty translation unit");
1519 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1520 mark_valid_location_for_stdc_pragma (false);
1524 c_parser_external_declaration (parser);
1525 obstack_free (&parser_obstack, obstack_position);
1527 while (c_parser_next_token_is_not (parser, CPP_EOF));
1532 FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl)
1533 if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node)
1534 error ("storage size of %q+D isn%'t known", decl);
1537 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1539 external-declaration:
1545 external-declaration:
1548 __extension__ external-declaration
1552 external-declaration:
1553 objc-class-definition
1554 objc-class-declaration
1555 objc-alias-declaration
1556 objc-protocol-definition
1557 objc-method-definition
1562 c_parser_external_declaration (c_parser *parser)
1565 switch (c_parser_peek_token (parser)->type)
1568 switch (c_parser_peek_token (parser)->keyword)
1571 ext = disable_extension_diagnostics ();
1572 c_parser_consume_token (parser);
1573 c_parser_external_declaration (parser);
1574 restore_extension_diagnostics (ext);
1577 c_parser_asm_definition (parser);
1579 case RID_AT_INTERFACE:
1580 case RID_AT_IMPLEMENTATION:
1581 gcc_assert (c_dialect_objc ());
1582 c_parser_objc_class_definition (parser, NULL_TREE);
1585 gcc_assert (c_dialect_objc ());
1586 c_parser_objc_class_declaration (parser);
1589 gcc_assert (c_dialect_objc ());
1590 c_parser_objc_alias_declaration (parser);
1592 case RID_AT_PROTOCOL:
1593 gcc_assert (c_dialect_objc ());
1594 c_parser_objc_protocol_definition (parser, NULL_TREE);
1596 case RID_AT_PROPERTY:
1597 gcc_assert (c_dialect_objc ());
1598 c_parser_objc_at_property_declaration (parser);
1600 case RID_AT_SYNTHESIZE:
1601 gcc_assert (c_dialect_objc ());
1602 c_parser_objc_at_synthesize_declaration (parser);
1604 case RID_AT_DYNAMIC:
1605 gcc_assert (c_dialect_objc ());
1606 c_parser_objc_at_dynamic_declaration (parser);
1609 gcc_assert (c_dialect_objc ());
1610 c_parser_consume_token (parser);
1611 objc_finish_implementation ();
1618 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
1619 "ISO C does not allow extra %<;%> outside of a function");
1620 c_parser_consume_token (parser);
1623 mark_valid_location_for_stdc_pragma (true);
1624 c_parser_pragma (parser, pragma_external, NULL);
1625 mark_valid_location_for_stdc_pragma (false);
1629 if (c_dialect_objc ())
1631 c_parser_objc_method_definition (parser);
1634 /* Else fall through, and yield a syntax error trying to parse
1635 as a declaration or function definition. */
1639 /* A declaration or a function definition (or, in Objective-C,
1640 an @interface or @protocol with prefix attributes). We can
1641 only tell which after parsing the declaration specifiers, if
1642 any, and the first declarator. */
1643 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
1649 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
1650 static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool);
1652 /* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */
1655 add_debug_begin_stmt (location_t loc)
1657 /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */
1658 if (!MAY_HAVE_DEBUG_MARKER_STMTS || !building_stmt_list_p ())
1661 tree stmt = build0 (DEBUG_BEGIN_STMT, void_type_node);
1662 SET_EXPR_LOCATION (stmt, loc);
1666 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1667 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1668 is accepted; otherwise (old-style parameter declarations) only other
1669 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1670 assertion is accepted; otherwise (old-style parameter declarations)
1671 it is not. If NESTED is true, we are inside a function or parsing
1672 old-style parameter declarations; any functions encountered are
1673 nested functions and declaration specifiers are required; otherwise
1674 we are at top level and functions are normal functions and
1675 declaration specifiers may be optional. If EMPTY_OK is true, empty
1676 declarations are OK (subject to all other constraints); otherwise
1677 (old-style parameter declarations) they are diagnosed. If
1678 START_ATTR_OK is true, the declaration specifiers may start with
1679 attributes; otherwise they may not.
1680 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1681 declaration when parsing an Objective-C foreach statement.
1682 FALLTHRU_ATTR_P is used to signal whether this function parsed
1683 "__attribute__((fallthrough));".
1686 declaration-specifiers init-declarator-list[opt] ;
1687 static_assert-declaration
1689 function-definition:
1690 declaration-specifiers[opt] declarator declaration-list[opt]
1695 declaration-list declaration
1697 init-declarator-list:
1699 init-declarator-list , init-declarator
1702 declarator simple-asm-expr[opt] attributes[opt]
1703 declarator simple-asm-expr[opt] attributes[opt] = initializer
1707 nested-function-definition:
1708 declaration-specifiers declarator declaration-list[opt]
1714 attributes objc-class-definition
1715 attributes objc-category-definition
1716 attributes objc-protocol-definition
1718 The simple-asm-expr and attributes are GNU extensions.
1720 This function does not handle __extension__; that is handled in its
1721 callers. ??? Following the old parser, __extension__ may start
1722 external declarations, declarations in functions and declarations
1723 at the start of "for" loops, but not old-style parameter
1726 C99 requires declaration specifiers in a function definition; the
1727 absence is diagnosed through the diagnosis of implicit int. In GNU
1728 C we also allow but diagnose declarations without declaration
1729 specifiers, but only at top level (elsewhere they conflict with
1732 In Objective-C, declarations of the looping variable in a foreach
1733 statement are exceptionally terminated by 'in' (for example, 'for
1734 (NSObject *object in array) { ... }').
1739 threadprivate-directive
1743 gimple-function-definition:
1744 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1745 declaration-list[opt] compound-statement
1747 rtl-function-definition:
1748 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1749 declaration-list[opt] compound-statement */
1752 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1753 bool static_assert_ok, bool empty_ok,
1754 bool nested, bool start_attr_ok,
1755 tree *objc_foreach_object_declaration,
1756 vec<c_token> omp_declare_simd_clauses,
1757 struct oacc_routine_data *oacc_routine_data,
1758 bool *fallthru_attr_p)
1760 struct c_declspecs *specs;
1762 tree all_prefix_attrs;
1763 bool diagnosed_no_specs = false;
1764 location_t here = c_parser_peek_token (parser)->location;
1766 add_debug_begin_stmt (c_parser_peek_token (parser)->location);
1768 if (static_assert_ok
1769 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1771 c_parser_static_assert_declaration (parser);
1774 specs = build_null_declspecs ();
1776 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1777 if (c_parser_peek_token (parser)->type == CPP_NAME
1778 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1779 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1780 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1781 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1783 tree name = c_parser_peek_token (parser)->value;
1785 /* Issue a warning about NAME being an unknown type name, perhaps
1786 with some kind of hint.
1787 If the user forgot a "struct" etc, suggest inserting
1788 it. Otherwise, attempt to look for misspellings. */
1789 gcc_rich_location richloc (here);
1790 if (tag_exists_p (RECORD_TYPE, name))
1792 /* This is not C++ with its implicit typedef. */
1793 richloc.add_fixit_insert_before ("struct ");
1795 "unknown type name %qE;"
1796 " use %<struct%> keyword to refer to the type",
1799 else if (tag_exists_p (UNION_TYPE, name))
1801 richloc.add_fixit_insert_before ("union ");
1803 "unknown type name %qE;"
1804 " use %<union%> keyword to refer to the type",
1807 else if (tag_exists_p (ENUMERAL_TYPE, name))
1809 richloc.add_fixit_insert_before ("enum ");
1811 "unknown type name %qE;"
1812 " use %<enum%> keyword to refer to the type",
1817 name_hint hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME,
1821 richloc.add_fixit_replace (hint.suggestion ());
1823 "unknown type name %qE; did you mean %qs?",
1824 name, hint.suggestion ());
1827 error_at (here, "unknown type name %qE", name);
1830 /* Parse declspecs normally to get a correct pointer type, but avoid
1831 a further "fails to be a type name" error. Refuse nested functions
1832 since it is not how the user likely wants us to recover. */
1833 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1834 c_parser_peek_token (parser)->keyword = RID_VOID;
1835 c_parser_peek_token (parser)->value = error_mark_node;
1839 c_parser_declspecs (parser, specs, true, true, start_attr_ok,
1840 true, true, cla_nonabstract_decl);
1843 c_parser_skip_to_end_of_block_or_statement (parser);
1846 if (nested && !specs->declspecs_seen_p)
1848 c_parser_error (parser, "expected declaration specifiers");
1849 c_parser_skip_to_end_of_block_or_statement (parser);
1853 finish_declspecs (specs);
1854 bool auto_type_p = specs->typespec_word == cts_auto_type;
1855 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1858 error_at (here, "%<__auto_type%> in empty declaration");
1859 else if (specs->typespec_kind == ctsk_none
1860 && attribute_fallthrough_p (specs->attrs))
1862 if (fallthru_attr_p != NULL)
1863 *fallthru_attr_p = true;
1864 tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH,
1872 shadow_tag_warned (specs, 1);
1873 pedwarn (here, 0, "empty declaration");
1875 c_parser_consume_token (parser);
1876 if (oacc_routine_data)
1877 c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1881 /* Provide better error recovery. Note that a type name here is usually
1882 better diagnosed as a redeclaration. */
1884 && specs->typespec_kind == ctsk_tagdef
1885 && c_parser_next_token_starts_declspecs (parser)
1886 && !c_parser_next_token_is (parser, CPP_NAME))
1888 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1889 parser->error = false;
1890 shadow_tag_warned (specs, 1);
1893 else if (c_dialect_objc () && !auto_type_p)
1895 /* Prefix attributes are an error on method decls. */
1896 switch (c_parser_peek_token (parser)->type)
1900 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1904 warning_at (c_parser_peek_token (parser)->location,
1906 "prefix attributes are ignored for methods");
1907 specs->attrs = NULL_TREE;
1910 c_parser_objc_method_definition (parser);
1912 c_parser_objc_methodproto (parser);
1918 /* This is where we parse 'attributes @interface ...',
1919 'attributes @implementation ...', 'attributes @protocol ...'
1920 (where attributes could be, for example, __attribute__
1923 switch (c_parser_peek_token (parser)->keyword)
1925 case RID_AT_INTERFACE:
1927 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1929 c_parser_objc_class_definition (parser, specs->attrs);
1933 case RID_AT_IMPLEMENTATION:
1935 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1939 warning_at (c_parser_peek_token (parser)->location,
1941 "prefix attributes are ignored for implementations");
1942 specs->attrs = NULL_TREE;
1944 c_parser_objc_class_definition (parser, NULL_TREE);
1948 case RID_AT_PROTOCOL:
1950 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1952 c_parser_objc_protocol_definition (parser, specs->attrs);
1959 case RID_AT_PROPERTY:
1962 c_parser_error (parser, "unexpected attribute");
1963 specs->attrs = NULL;
1970 else if (attribute_fallthrough_p (specs->attrs))
1971 warning_at (here, OPT_Wattributes,
1972 "%<fallthrough%> attribute not followed by %<;%>");
1974 pending_xref_error ();
1975 prefix_attrs = specs->attrs;
1976 all_prefix_attrs = prefix_attrs;
1977 specs->attrs = NULL_TREE;
1980 struct c_declarator *declarator;
1983 tree fnbody = NULL_TREE;
1984 /* Declaring either one or more declarators (in which case we
1985 should diagnose if there were no declaration specifiers) or a
1986 function definition (in which case the diagnostic for
1987 implicit int suffices). */
1988 declarator = c_parser_declarator (parser,
1989 specs->typespec_kind != ctsk_none,
1990 C_DTR_NORMAL, &dummy);
1991 if (declarator == NULL)
1993 if (omp_declare_simd_clauses.exists ())
1994 c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
1995 omp_declare_simd_clauses);
1996 if (oacc_routine_data)
1997 c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
1998 c_parser_skip_to_end_of_block_or_statement (parser);
2001 if (auto_type_p && declarator->kind != cdk_id)
2004 "%<__auto_type%> requires a plain identifier"
2006 c_parser_skip_to_end_of_block_or_statement (parser);
2009 if (c_parser_next_token_is (parser, CPP_EQ)
2010 || c_parser_next_token_is (parser, CPP_COMMA)
2011 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2012 || c_parser_next_token_is_keyword (parser, RID_ASM)
2013 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
2014 || c_parser_next_token_is_keyword (parser, RID_IN))
2016 tree asm_name = NULL_TREE;
2017 tree postfix_attrs = NULL_TREE;
2018 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
2020 diagnosed_no_specs = true;
2021 pedwarn (here, 0, "data definition has no type or storage class");
2023 /* Having seen a data definition, there cannot now be a
2024 function definition. */
2026 if (c_parser_next_token_is_keyword (parser, RID_ASM))
2027 asm_name = c_parser_simple_asm_expr (parser);
2028 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2030 postfix_attrs = c_parser_attributes (parser);
2031 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2033 /* This means there is an attribute specifier after
2034 the declarator in a function definition. Provide
2035 some more information for the user. */
2036 error_at (here, "attributes should be specified before the "
2037 "declarator in a function definition");
2038 c_parser_skip_to_end_of_block_or_statement (parser);
2042 if (c_parser_next_token_is (parser, CPP_EQ))
2046 location_t init_loc;
2047 c_parser_consume_token (parser);
2050 init_loc = c_parser_peek_token (parser)->location;
2051 rich_location richloc (line_table, init_loc);
2052 start_init (NULL_TREE, asm_name, global_bindings_p (), &richloc);
2053 /* A parameter is initialized, which is invalid. Don't
2054 attempt to instrument the initializer. */
2055 int flag_sanitize_save = flag_sanitize;
2056 if (nested && !empty_ok)
2058 init = c_parser_expr_no_commas (parser, NULL);
2059 flag_sanitize = flag_sanitize_save;
2060 if (TREE_CODE (init.value) == COMPONENT_REF
2061 && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
2063 "%<__auto_type%> used with a bit-field"
2065 init = convert_lvalue_to_rvalue (init_loc, init, true, true);
2066 tree init_type = TREE_TYPE (init.value);
2067 /* As with typeof, remove all qualifiers from atomic types. */
2068 if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
2070 = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
2071 bool vm_type = variably_modified_type_p (init_type,
2074 init.value = save_expr (init.value);
2076 specs->typespec_kind = ctsk_typeof;
2077 specs->locations[cdw_typedef] = init_loc;
2078 specs->typedef_p = true;
2079 specs->type = init_type;
2082 bool maybe_const = true;
2083 tree type_expr = c_fully_fold (init.value, false,
2085 specs->expr_const_operands &= maybe_const;
2087 specs->expr = build2 (COMPOUND_EXPR,
2088 TREE_TYPE (type_expr),
2089 specs->expr, type_expr);
2091 specs->expr = type_expr;
2093 d = start_decl (declarator, specs, true,
2094 chainon (postfix_attrs, all_prefix_attrs));
2096 d = error_mark_node;
2097 if (omp_declare_simd_clauses.exists ())
2098 c_finish_omp_declare_simd (parser, d, NULL_TREE,
2099 omp_declare_simd_clauses);
2103 /* The declaration of the variable is in effect while
2104 its initializer is parsed. */
2105 d = start_decl (declarator, specs, true,
2106 chainon (postfix_attrs, all_prefix_attrs));
2108 d = error_mark_node;
2109 if (omp_declare_simd_clauses.exists ())
2110 c_finish_omp_declare_simd (parser, d, NULL_TREE,
2111 omp_declare_simd_clauses);
2112 init_loc = c_parser_peek_token (parser)->location;
2113 rich_location richloc (line_table, init_loc);
2114 start_init (d, asm_name, global_bindings_p (), &richloc);
2115 /* A parameter is initialized, which is invalid. Don't
2116 attempt to instrument the initializer. */
2117 int flag_sanitize_save = flag_sanitize;
2118 if (TREE_CODE (d) == PARM_DECL)
2120 init = c_parser_initializer (parser);
2121 flag_sanitize = flag_sanitize_save;
2124 if (oacc_routine_data)
2125 c_finish_oacc_routine (oacc_routine_data, d, false);
2126 if (d != error_mark_node)
2128 maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
2129 finish_decl (d, init_loc, init.value,
2130 init.original_type, asm_name);
2138 "%<__auto_type%> requires an initialized "
2139 "data declaration");
2140 c_parser_skip_to_end_of_block_or_statement (parser);
2143 tree d = start_decl (declarator, specs, false,
2144 chainon (postfix_attrs,
2146 if (d && TREE_CODE (d) == FUNCTION_DECL)
2147 if (declarator->kind == cdk_function)
2148 if (DECL_ARGUMENTS (d) == NULL_TREE)
2149 DECL_ARGUMENTS (d) = declarator->u.arg_info->parms;
2150 if (omp_declare_simd_clauses.exists ())
2152 tree parms = NULL_TREE;
2153 if (d && TREE_CODE (d) == FUNCTION_DECL)
2155 struct c_declarator *ce = declarator;
2157 if (ce->kind == cdk_function)
2159 parms = ce->u.arg_info->parms;
2163 ce = ce->declarator;
2166 temp_store_parm_decls (d, parms);
2167 c_finish_omp_declare_simd (parser, d, parms,
2168 omp_declare_simd_clauses);
2170 temp_pop_parm_decls ();
2172 if (oacc_routine_data)
2173 c_finish_oacc_routine (oacc_routine_data, d, false);
2175 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
2176 NULL_TREE, asm_name);
2178 if (c_parser_next_token_is_keyword (parser, RID_IN))
2181 *objc_foreach_object_declaration = d;
2183 *objc_foreach_object_declaration = error_mark_node;
2186 if (c_parser_next_token_is (parser, CPP_COMMA))
2191 "%<__auto_type%> may only be used with"
2192 " a single declarator");
2193 c_parser_skip_to_end_of_block_or_statement (parser);
2196 c_parser_consume_token (parser);
2197 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2198 all_prefix_attrs = chainon (c_parser_attributes (parser),
2201 all_prefix_attrs = prefix_attrs;
2204 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2206 c_parser_consume_token (parser);
2209 else if (c_parser_next_token_is_keyword (parser, RID_IN))
2211 /* This can only happen in Objective-C: we found the
2212 'in' that terminates the declaration inside an
2213 Objective-C foreach statement. Do not consume the
2214 token, so that the caller can use it to determine
2215 that this indeed is a foreach context. */
2220 c_parser_error (parser, "expected %<,%> or %<;%>");
2221 c_parser_skip_to_end_of_block_or_statement (parser);
2225 else if (auto_type_p)
2228 "%<__auto_type%> requires an initialized data declaration");
2229 c_parser_skip_to_end_of_block_or_statement (parser);
2234 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
2235 "%<asm%> or %<__attribute__%>");
2236 c_parser_skip_to_end_of_block_or_statement (parser);
2239 /* Function definition (nested or otherwise). */
2242 pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions");
2243 c_push_function_context ();
2245 if (!start_function (specs, declarator, all_prefix_attrs))
2247 /* At this point we've consumed:
2248 declaration-specifiers declarator
2249 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2250 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2252 declaration-specifiers declarator
2253 aren't grokkable as a function definition, so we have
2255 gcc_assert (!c_parser_next_token_is (parser, CPP_SEMICOLON));
2256 if (c_parser_next_token_starts_declspecs (parser))
2259 declaration-specifiers declarator decl-specs
2260 then assume we have a missing semicolon, which would
2262 declaration-specifiers declarator decl-specs
2265 <~~~~~~~~~ declaration ~~~~~~~~~~>
2266 Use c_parser_require to get an error with a fix-it hint. */
2267 c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>");
2268 parser->error = false;
2272 /* This can appear in many cases looking nothing like a
2273 function definition, so we don't give a more specific
2274 error suggesting there was one. */
2275 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2276 "or %<__attribute__%>");
2279 c_pop_function_context ();
2283 if (DECL_DECLARED_INLINE_P (current_function_decl))
2284 tv = TV_PARSE_INLINE;
2287 auto_timevar at (g_timer, tv);
2289 /* Parse old-style parameter declarations. ??? Attributes are
2290 not allowed to start declaration specifiers here because of a
2291 syntax conflict between a function declaration with attribute
2292 suffix and a function definition with an attribute prefix on
2293 first old-style parameter declaration. Following the old
2294 parser, they are not accepted on subsequent old-style
2295 parameter declarations either. However, there is no
2296 ambiguity after the first declaration, nor indeed on the
2297 first as long as we don't allow postfix attributes after a
2298 declarator with a nonempty identifier list in a definition;
2299 and postfix attributes have never been accepted here in
2300 function definitions either. */
2301 while (c_parser_next_token_is_not (parser, CPP_EOF)
2302 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
2303 c_parser_declaration_or_fndef (parser, false, false, false,
2304 true, false, NULL, vNULL);
2305 store_parm_decls ();
2306 if (omp_declare_simd_clauses.exists ())
2307 c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
2308 omp_declare_simd_clauses);
2309 if (oacc_routine_data)
2310 c_finish_oacc_routine (oacc_routine_data, current_function_decl, true);
2311 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
2312 = c_parser_peek_token (parser)->location;
2314 /* If the definition was marked with __GIMPLE then parse the
2315 function body as GIMPLE. */
2316 if (specs->gimple_p)
2318 cfun->pass_startwith = specs->gimple_or_rtl_pass;
2319 bool saved = in_late_binary_op;
2320 in_late_binary_op = true;
2321 c_parser_parse_gimple_body (parser);
2322 in_late_binary_op = saved;
2324 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2325 consuming the function body. */
2326 else if (specs->rtl_p)
2328 c_parser_parse_rtl_body (parser, specs->gimple_or_rtl_pass);
2330 /* Normally, store_parm_decls sets next_is_function_body,
2331 anticipating a function body. We need a push_scope/pop_scope
2332 pair to flush out this state, or subsequent function parsing
2341 fnbody = c_parser_compound_statement (parser);
2342 tree fndecl = current_function_decl;
2345 tree decl = current_function_decl;
2346 /* Mark nested functions as needing static-chain initially.
2347 lower_nested_functions will recompute it but the
2348 DECL_STATIC_CHAIN flag is also used before that happens,
2349 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2350 DECL_STATIC_CHAIN (decl) = 1;
2353 c_pop_function_context ();
2354 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
2362 /* Get rid of the empty stmt list for GIMPLE. */
2363 if (specs->gimple_p)
2364 DECL_SAVED_TREE (fndecl) = NULL_TREE;
2370 /* Parse an asm-definition (asm() outside a function body). This is a
2378 c_parser_asm_definition (c_parser *parser)
2380 tree asm_str = c_parser_simple_asm_expr (parser);
2382 symtab->finalize_toplevel_asm (asm_str);
2383 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
2386 /* Parse a static assertion (C11 6.7.10).
2388 static_assert-declaration:
2389 static_assert-declaration-no-semi ;
2393 c_parser_static_assert_declaration (c_parser *parser)
2395 c_parser_static_assert_declaration_no_semi (parser);
2397 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
2398 c_parser_skip_to_end_of_block_or_statement (parser);
2401 /* Parse a static assertion (C11 6.7.10), without the trailing
2404 static_assert-declaration-no-semi:
2405 _Static_assert ( constant-expression , string-literal )
2409 c_parser_static_assert_declaration_no_semi (c_parser *parser)
2411 location_t assert_loc, value_loc;
2415 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
2416 assert_loc = c_parser_peek_token (parser)->location;
2418 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2419 "ISO C99 does not support %<_Static_assert%>");
2421 pedwarn_c99 (assert_loc, OPT_Wpedantic,
2422 "ISO C90 does not support %<_Static_assert%>");
2423 c_parser_consume_token (parser);
2424 matching_parens parens;
2425 if (!parens.require_open (parser))
2427 location_t value_tok_loc = c_parser_peek_token (parser)->location;
2428 value = c_parser_expr_no_commas (parser, NULL).value;
2429 value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc);
2430 parser->lex_untranslated_string = true;
2431 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
2433 parser->lex_untranslated_string = false;
2436 switch (c_parser_peek_token (parser)->type)
2442 case CPP_UTF8STRING:
2443 string = c_parser_peek_token (parser)->value;
2444 c_parser_consume_token (parser);
2445 parser->lex_untranslated_string = false;
2448 c_parser_error (parser, "expected string literal");
2449 parser->lex_untranslated_string = false;
2452 parens.require_close (parser);
2454 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
2456 error_at (value_loc, "expression in static assertion is not an integer");
2459 if (TREE_CODE (value) != INTEGER_CST)
2461 value = c_fully_fold (value, false, NULL);
2462 /* Strip no-op conversions. */
2463 STRIP_TYPE_NOPS (value);
2464 if (TREE_CODE (value) == INTEGER_CST)
2465 pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion "
2466 "is not an integer constant expression");
2468 if (TREE_CODE (value) != INTEGER_CST)
2470 error_at (value_loc, "expression in static assertion is not constant");
2473 constant_expression_warning (value);
2474 if (integer_zerop (value))
2475 error_at (assert_loc, "static assertion failed: %E", string);
2478 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2479 6.7, C11 6.7), adding them to SPECS (which may already include some).
2480 Storage class specifiers are accepted iff SCSPEC_OK; type
2481 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2482 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2483 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2485 declaration-specifiers:
2486 storage-class-specifier declaration-specifiers[opt]
2487 type-specifier declaration-specifiers[opt]
2488 type-qualifier declaration-specifiers[opt]
2489 function-specifier declaration-specifiers[opt]
2490 alignment-specifier declaration-specifiers[opt]
2492 Function specifiers (inline) are from C99, and are currently
2493 handled as storage class specifiers, as is __thread. Alignment
2494 specifiers are from C11.
2496 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2497 storage-class-specifier:
2505 (_Thread_local is new in C11.)
2507 C99 6.7.4, C11 6.7.4:
2512 (_Noreturn is new in C11.)
2514 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2527 [_Imaginary removed in C99 TC2]
2528 struct-or-union-specifier
2531 atomic-type-specifier
2533 (_Bool and _Complex are new in C99.)
2534 (atomic-type-specifier is new in C11.)
2536 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2542 address-space-qualifier
2545 (restrict is new in C99.)
2546 (_Atomic is new in C11.)
2550 declaration-specifiers:
2551 attributes declaration-specifiers[opt]
2557 identifier recognized by the target
2559 storage-class-specifier:
2573 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2574 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2576 atomic-type-specifier
2577 _Atomic ( type-name )
2582 class-name objc-protocol-refs[opt]
2583 typedef-name objc-protocol-refs
2588 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
2589 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
2590 bool alignspec_ok, bool auto_type_ok,
2591 enum c_lookahead_kind la)
2593 bool attrs_ok = start_attr_ok;
2594 bool seen_type = specs->typespec_kind != ctsk_none;
2597 gcc_assert (la == cla_prefer_id);
2599 while (c_parser_next_token_is (parser, CPP_NAME)
2600 || c_parser_next_token_is (parser, CPP_KEYWORD)
2601 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
2603 struct c_typespec t;
2606 location_t loc = c_parser_peek_token (parser)->location;
2608 /* If we cannot accept a type, exit if the next token must start
2609 one. Also, if we already have seen a tagged definition,
2610 a typename would be an error anyway and likely the user
2611 has simply forgotten a semicolon, so we exit. */
2612 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2613 && c_parser_next_tokens_start_typename (parser, la)
2614 && !c_parser_next_token_is_qualifier (parser)
2615 && !c_parser_next_token_is_keyword (parser, RID_ALIGNAS))
2618 if (c_parser_next_token_is (parser, CPP_NAME))
2620 c_token *name_token = c_parser_peek_token (parser);
2621 tree value = name_token->value;
2622 c_id_kind kind = name_token->id_kind;
2624 if (kind == C_ID_ADDRSPACE)
2627 = name_token->keyword - RID_FIRST_ADDR_SPACE;
2628 declspecs_add_addrspace (name_token->location, specs, as);
2629 c_parser_consume_token (parser);
2634 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2636 /* If we cannot accept a type, and the next token must start one,
2637 exit. Do the same if we already have seen a tagged definition,
2638 since it would be an error anyway and likely the user has simply
2639 forgotten a semicolon. */
2640 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2643 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2644 a C_ID_CLASSNAME. */
2645 c_parser_consume_token (parser);
2648 if (kind == C_ID_ID)
2650 error_at (loc, "unknown type name %qE", value);
2651 t.kind = ctsk_typedef;
2652 t.spec = error_mark_node;
2654 else if (kind == C_ID_TYPENAME
2655 && (!c_dialect_objc ()
2656 || c_parser_next_token_is_not (parser, CPP_LESS)))
2658 t.kind = ctsk_typedef;
2659 /* For a typedef name, record the meaning, not the name.
2660 In case of 'foo foo, bar;'. */
2661 t.spec = lookup_name (value);
2665 tree proto = NULL_TREE;
2666 gcc_assert (c_dialect_objc ());
2668 if (c_parser_next_token_is (parser, CPP_LESS))
2669 proto = c_parser_objc_protocol_refs (parser);
2670 t.spec = objc_get_protocol_qualified_type (value, proto);
2673 t.expr_const_operands = true;
2674 declspecs_add_type (name_token->location, specs, t);
2677 if (c_parser_next_token_is (parser, CPP_LESS))
2679 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2680 nisse@lysator.liu.se. */
2682 gcc_assert (c_dialect_objc ());
2683 if (!typespec_ok || seen_type)
2685 proto = c_parser_objc_protocol_refs (parser);
2687 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2689 t.expr_const_operands = true;
2690 declspecs_add_type (loc, specs, t);
2693 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2694 switch (c_parser_peek_token (parser)->keyword)
2707 /* TODO: Distinguish between function specifiers (inline, noreturn)
2708 and storage class specifiers, either here or in
2709 declspecs_add_scspec. */
2710 declspecs_add_scspec (loc, specs,
2711 c_parser_peek_token (parser)->value);
2712 c_parser_consume_token (parser);
2744 if (c_dialect_objc ())
2745 parser->objc_need_raw_identifier = true;
2746 t.kind = ctsk_resword;
2747 t.spec = c_parser_peek_token (parser)->value;
2749 t.expr_const_operands = true;
2750 declspecs_add_type (loc, specs, t);
2751 c_parser_consume_token (parser);
2758 t = c_parser_enum_specifier (parser);
2759 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2760 declspecs_add_type (loc, specs, t);
2768 t = c_parser_struct_or_union_specifier (parser);
2769 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2770 declspecs_add_type (loc, specs, t);
2773 /* ??? The old parser rejected typeof after other type
2774 specifiers, but is a syntax error the best way of
2776 if (!typespec_ok || seen_type)
2780 t = c_parser_typeof_specifier (parser);
2781 declspecs_add_type (loc, specs, t);
2784 /* C parser handling of Objective-C constructs needs
2785 checking for correct lvalue-to-rvalue conversions, and
2786 the code in build_modify_expr handling various
2787 Objective-C cases, and that in build_unary_op handling
2788 Objective-C cases for increment / decrement, also needs
2789 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2790 and objc_types_are_equivalent may also need updates. */
2791 if (c_dialect_objc ())
2792 sorry ("%<_Atomic%> in Objective-C");
2794 pedwarn_c99 (loc, OPT_Wpedantic,
2795 "ISO C99 does not support the %<_Atomic%> qualifier");
2797 pedwarn_c99 (loc, OPT_Wpedantic,
2798 "ISO C90 does not support the %<_Atomic%> qualifier");
2801 value = c_parser_peek_token (parser)->value;
2802 c_parser_consume_token (parser);
2803 if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2805 /* _Atomic ( type-name ). */
2807 c_parser_consume_token (parser);
2808 struct c_type_name *type = c_parser_type_name (parser);
2809 t.kind = ctsk_typeof;
2810 t.spec = error_mark_node;
2812 t.expr_const_operands = true;
2814 t.spec = groktypename (type, &t.expr,
2815 &t.expr_const_operands);
2816 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2818 if (t.spec != error_mark_node)
2820 if (TREE_CODE (t.spec) == ARRAY_TYPE)
2821 error_at (loc, "%<_Atomic%>-qualified array type");
2822 else if (TREE_CODE (t.spec) == FUNCTION_TYPE)
2823 error_at (loc, "%<_Atomic%>-qualified function type");
2824 else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED)
2825 error_at (loc, "%<_Atomic%> applied to a qualified type");
2827 t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC);
2829 declspecs_add_type (loc, specs, t);
2832 declspecs_add_qual (loc, specs, value);
2838 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value);
2839 c_parser_consume_token (parser);
2844 attrs = c_parser_attributes (parser);
2845 declspecs_add_attrs (loc, specs, attrs);
2850 align = c_parser_alignas_specifier (parser);
2851 declspecs_add_alignas (loc, specs, align);
2855 error_at (loc, "%<__GIMPLE%> only valid with -fgimple");
2856 c_parser_consume_token (parser);
2857 specs->gimple_p = true;
2858 specs->locations[cdw_gimple] = loc;
2859 specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2862 c_parser_consume_token (parser);
2863 specs->rtl_p = true;
2864 specs->locations[cdw_rtl] = loc;
2865 specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser);
2874 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2877 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2878 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2879 enum attributes[opt] identifier
2881 The form with trailing comma is new in C99. The forms with
2882 attributes are GNU extensions. In GNU C, we accept any expression
2883 without commas in the syntax (assignment expressions, not just
2884 conditional expressions); assignment expressions will be diagnosed
2889 enumerator-list , enumerator
2892 enumeration-constant
2893 enumeration-constant = constant-expression
2898 enumeration-constant attributes[opt]
2899 enumeration-constant attributes[opt] = constant-expression
2903 static struct c_typespec
2904 c_parser_enum_specifier (c_parser *parser)
2906 struct c_typespec ret;
2908 tree ident = NULL_TREE;
2909 location_t enum_loc;
2910 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2911 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2912 c_parser_consume_token (parser);
2913 attrs = c_parser_attributes (parser);
2914 enum_loc = c_parser_peek_token (parser)->location;
2915 /* Set the location in case we create a decl now. */
2916 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2917 if (c_parser_next_token_is (parser, CPP_NAME))
2919 ident = c_parser_peek_token (parser)->value;
2920 ident_loc = c_parser_peek_token (parser)->location;
2921 enum_loc = ident_loc;
2922 c_parser_consume_token (parser);
2924 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2926 /* Parse an enum definition. */
2927 struct c_enum_contents the_enum;
2930 /* We chain the enumerators in reverse order, then put them in
2931 forward order at the end. */
2933 timevar_push (TV_PARSE_ENUM);
2934 type = start_enum (enum_loc, &the_enum, ident);
2936 c_parser_consume_token (parser);
2944 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2945 location_t decl_loc, value_loc;
2946 if (c_parser_next_token_is_not (parser, CPP_NAME))
2948 /* Give a nicer error for "enum {}". */
2949 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2952 error_at (c_parser_peek_token (parser)->location,
2953 "empty enum is invalid");
2954 parser->error = true;
2957 c_parser_error (parser, "expected identifier");
2958 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2959 values = error_mark_node;
2962 token = c_parser_peek_token (parser);
2963 enum_id = token->value;
2964 /* Set the location in case we create a decl now. */
2965 c_parser_set_source_position_from_token (token);
2966 decl_loc = value_loc = token->location;
2967 c_parser_consume_token (parser);
2968 /* Parse any specified attributes. */
2969 tree enum_attrs = c_parser_attributes (parser);
2970 if (c_parser_next_token_is (parser, CPP_EQ))
2972 c_parser_consume_token (parser);
2973 value_loc = c_parser_peek_token (parser)->location;
2974 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2977 enum_value = NULL_TREE;
2978 enum_decl = build_enumerator (decl_loc, value_loc,
2979 &the_enum, enum_id, enum_value);
2981 decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0);
2982 TREE_CHAIN (enum_decl) = values;
2985 if (c_parser_next_token_is (parser, CPP_COMMA))
2987 comma_loc = c_parser_peek_token (parser)->location;
2989 c_parser_consume_token (parser);
2991 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2994 pedwarn_c90 (comma_loc, OPT_Wpedantic,
2995 "comma at end of enumerator list");
2996 c_parser_consume_token (parser);
3001 c_parser_error (parser, "expected %<,%> or %<}%>");
3002 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
3003 values = error_mark_node;
3007 postfix_attrs = c_parser_attributes (parser);
3008 ret.spec = finish_enum (type, nreverse (values),
3009 chainon (attrs, postfix_attrs));
3010 ret.kind = ctsk_tagdef;
3011 ret.expr = NULL_TREE;
3012 ret.expr_const_operands = true;
3013 timevar_pop (TV_PARSE_ENUM);
3018 c_parser_error (parser, "expected %<{%>");
3019 ret.spec = error_mark_node;
3020 ret.kind = ctsk_tagref;
3021 ret.expr = NULL_TREE;
3022 ret.expr_const_operands = true;
3025 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
3026 /* In ISO C, enumerated types can be referred to only if already
3028 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
3031 pedwarn (enum_loc, OPT_Wpedantic,
3032 "ISO C forbids forward references to %<enum%> types");
3037 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3039 struct-or-union-specifier:
3040 struct-or-union attributes[opt] identifier[opt]
3041 { struct-contents } attributes[opt]
3042 struct-or-union attributes[opt] identifier
3045 struct-declaration-list
3047 struct-declaration-list:
3048 struct-declaration ;
3049 struct-declaration-list struct-declaration ;
3056 struct-declaration-list struct-declaration
3058 struct-declaration-list:
3059 struct-declaration-list ;
3062 (Note that in the syntax here, unlike that in ISO C, the semicolons
3063 are included here rather than in struct-declaration, in order to
3064 describe the syntax with extra semicolons and missing semicolon at
3069 struct-declaration-list:
3070 @defs ( class-name )
3072 (Note this does not include a trailing semicolon, but can be
3073 followed by further declarations, and gets a pedwarn-if-pedantic
3074 when followed by a semicolon.) */
3076 static struct c_typespec
3077 c_parser_struct_or_union_specifier (c_parser *parser)
3079 struct c_typespec ret;
3081 tree ident = NULL_TREE;
3082 location_t struct_loc;
3083 location_t ident_loc = UNKNOWN_LOCATION;
3084 enum tree_code code;
3085 switch (c_parser_peek_token (parser)->keyword)
3096 struct_loc = c_parser_peek_token (parser)->location;
3097 c_parser_consume_token (parser);
3098 attrs = c_parser_attributes (parser);
3100 /* Set the location in case we create a decl now. */
3101 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
3103 if (c_parser_next_token_is (parser, CPP_NAME))
3105 ident = c_parser_peek_token (parser)->value;
3106 ident_loc = c_parser_peek_token (parser)->location;
3107 struct_loc = ident_loc;
3108 c_parser_consume_token (parser);
3110 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3112 /* Parse a struct or union definition. Start the scope of the
3113 tag before parsing components. */
3114 struct c_struct_parse_info *struct_info;
3115 tree type = start_struct (struct_loc, code, ident, &struct_info);
3117 /* We chain the components in reverse order, then put them in
3118 forward order at the end. Each struct-declaration may
3119 declare multiple components (comma-separated), so we must use
3120 chainon to join them, although when parsing each
3121 struct-declaration we can use TREE_CHAIN directly.
3123 The theory behind all this is that there will be more
3124 semicolon separated fields than comma separated fields, and
3125 so we'll be minimizing the number of node traversals required
3128 timevar_push (TV_PARSE_STRUCT);
3129 contents = NULL_TREE;
3130 c_parser_consume_token (parser);
3131 /* Handle the Objective-C @defs construct,
3132 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3133 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
3136 gcc_assert (c_dialect_objc ());
3137 c_parser_consume_token (parser);
3138 matching_parens parens;
3139 if (!parens.require_open (parser))
3141 if (c_parser_next_token_is (parser, CPP_NAME)
3142 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
3144 name = c_parser_peek_token (parser)->value;
3145 c_parser_consume_token (parser);
3149 c_parser_error (parser, "expected class name");
3150 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3153 parens.skip_until_found_close (parser);
3154 contents = nreverse (objc_get_class_ivars (name));
3157 /* Parse the struct-declarations and semicolons. Problems with
3158 semicolons are diagnosed here; empty structures are diagnosed
3163 /* Parse any stray semicolon. */
3164 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3166 location_t semicolon_loc
3167 = c_parser_peek_token (parser)->location;
3168 gcc_rich_location richloc (semicolon_loc);
3169 richloc.add_fixit_remove ();
3170 pedwarn (&richloc, OPT_Wpedantic,
3171 "extra semicolon in struct or union specified");
3172 c_parser_consume_token (parser);
3175 /* Stop if at the end of the struct or union contents. */
3176 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3178 c_parser_consume_token (parser);
3181 /* Accept #pragmas at struct scope. */
3182 if (c_parser_next_token_is (parser, CPP_PRAGMA))
3184 c_parser_pragma (parser, pragma_struct, NULL);
3187 /* Parse some comma-separated declarations, but not the
3188 trailing semicolon if any. */
3189 decls = c_parser_struct_declaration (parser);
3190 contents = chainon (decls, contents);
3191 /* If no semicolon follows, either we have a parse error or
3192 are at the end of the struct or union and should
3194 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3195 c_parser_consume_token (parser);
3198 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3199 pedwarn (c_parser_peek_token (parser)->location, 0,
3200 "no semicolon at end of struct or union");
3201 else if (parser->error
3202 || !c_parser_next_token_starts_declspecs (parser))
3204 c_parser_error (parser, "expected %<;%>");
3205 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
3209 /* If we come here, we have already emitted an error
3210 for an expected `;', identifier or `(', and we also
3211 recovered already. Go on with the next field. */
3214 postfix_attrs = c_parser_attributes (parser);
3215 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
3216 chainon (attrs, postfix_attrs), struct_info);
3217 ret.kind = ctsk_tagdef;
3218 ret.expr = NULL_TREE;
3219 ret.expr_const_operands = true;
3220 timevar_pop (TV_PARSE_STRUCT);
3225 c_parser_error (parser, "expected %<{%>");
3226 ret.spec = error_mark_node;
3227 ret.kind = ctsk_tagref;
3228 ret.expr = NULL_TREE;
3229 ret.expr_const_operands = true;
3232 ret = parser_xref_tag (ident_loc, code, ident);
3236 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3237 *without* the trailing semicolon.
3240 specifier-qualifier-list struct-declarator-list
3241 static_assert-declaration-no-semi
3243 specifier-qualifier-list:
3244 type-specifier specifier-qualifier-list[opt]
3245 type-qualifier specifier-qualifier-list[opt]
3246 alignment-specifier specifier-qualifier-list[opt]
3247 attributes specifier-qualifier-list[opt]
3249 struct-declarator-list:
3251 struct-declarator-list , attributes[opt] struct-declarator
3254 declarator attributes[opt]
3255 declarator[opt] : constant-expression attributes[opt]
3260 __extension__ struct-declaration
3261 specifier-qualifier-list
3263 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3264 of attributes where shown is a GNU extension. In GNU C, we accept
3265 any expression without commas in the syntax (assignment
3266 expressions, not just conditional expressions); assignment
3267 expressions will be diagnosed as non-constant. */
3270 c_parser_struct_declaration (c_parser *parser)
3272 struct c_declspecs *specs;
3274 tree all_prefix_attrs;
3276 location_t decl_loc;
3277 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3281 ext = disable_extension_diagnostics ();
3282 c_parser_consume_token (parser);
3283 decl = c_parser_struct_declaration (parser);
3284 restore_extension_diagnostics (ext);
3287 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
3289 c_parser_static_assert_declaration_no_semi (parser);
3292 specs = build_null_declspecs ();
3293 decl_loc = c_parser_peek_token (parser)->location;
3294 /* Strictly by the standard, we shouldn't allow _Alignas here,
3295 but it appears to have been intended to allow it there, so
3296 we're keeping it as it is until WG14 reaches a conclusion
3298 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3299 c_parser_declspecs (parser, specs, false, true, true,
3300 true, false, cla_nonabstract_decl);
3303 if (!specs->declspecs_seen_p)
3305 c_parser_error (parser, "expected specifier-qualifier-list");
3308 finish_declspecs (specs);
3309 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3310 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3313 if (specs->typespec_kind == ctsk_none)
3315 pedwarn (decl_loc, OPT_Wpedantic,
3316 "ISO C forbids member declarations with no members");
3317 shadow_tag_warned (specs, pedantic);
3322 /* Support for unnamed structs or unions as members of
3323 structs or unions (which is [a] useful and [b] supports
3327 ret = grokfield (c_parser_peek_token (parser)->location,
3328 build_id_declarator (NULL_TREE), specs,
3331 decl_attributes (&ret, attrs, 0);
3336 /* Provide better error recovery. Note that a type name here is valid,
3337 and will be treated as a field name. */
3338 if (specs->typespec_kind == ctsk_tagdef
3339 && TREE_CODE (specs->type) != ENUMERAL_TYPE
3340 && c_parser_next_token_starts_declspecs (parser)
3341 && !c_parser_next_token_is (parser, CPP_NAME))
3343 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
3344 parser->error = false;
3348 pending_xref_error ();
3349 prefix_attrs = specs->attrs;
3350 all_prefix_attrs = prefix_attrs;
3351 specs->attrs = NULL_TREE;
3355 /* Declaring one or more declarators or un-named bit-fields. */
3356 struct c_declarator *declarator;
3358 if (c_parser_next_token_is (parser, CPP_COLON))
3359 declarator = build_id_declarator (NULL_TREE);
3361 declarator = c_parser_declarator (parser,
3362 specs->typespec_kind != ctsk_none,
3363 C_DTR_NORMAL, &dummy);
3364 if (declarator == NULL)
3366 c_parser_skip_to_end_of_block_or_statement (parser);
3369 if (c_parser_next_token_is (parser, CPP_COLON)
3370 || c_parser_next_token_is (parser, CPP_COMMA)
3371 || c_parser_next_token_is (parser, CPP_SEMICOLON)
3372 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
3373 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3375 tree postfix_attrs = NULL_TREE;
3376 tree width = NULL_TREE;
3378 if (c_parser_next_token_is (parser, CPP_COLON))
3380 c_parser_consume_token (parser);
3381 width = c_parser_expr_no_commas (parser, NULL).value;
3383 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3384 postfix_attrs = c_parser_attributes (parser);
3385 d = grokfield (c_parser_peek_token (parser)->location,
3386 declarator, specs, width, &all_prefix_attrs);
3387 decl_attributes (&d, chainon (postfix_attrs,
3388 all_prefix_attrs), 0);
3389 DECL_CHAIN (d) = decls;
3391 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3392 all_prefix_attrs = chainon (c_parser_attributes (parser),
3395 all_prefix_attrs = prefix_attrs;
3396 if (c_parser_next_token_is (parser, CPP_COMMA))
3397 c_parser_consume_token (parser);
3398 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
3399 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3401 /* Semicolon consumed in caller. */
3406 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
3412 c_parser_error (parser,
3413 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3414 "%<__attribute__%>");
3421 /* Parse a typeof specifier (a GNU extension).
3424 typeof ( expression )
3425 typeof ( type-name )
3428 static struct c_typespec
3429 c_parser_typeof_specifier (c_parser *parser)
3431 struct c_typespec ret;
3432 ret.kind = ctsk_typeof;
3433 ret.spec = error_mark_node;
3434 ret.expr = NULL_TREE;
3435 ret.expr_const_operands = true;
3436 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
3437 c_parser_consume_token (parser);
3438 c_inhibit_evaluation_warnings++;
3440 matching_parens parens;
3441 if (!parens.require_open (parser))
3443 c_inhibit_evaluation_warnings--;
3447 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3449 struct c_type_name *type = c_parser_type_name (parser);
3450 c_inhibit_evaluation_warnings--;
3454 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
3455 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
3461 location_t here = c_parser_peek_token (parser)->location;
3462 struct c_expr expr = c_parser_expression (parser);
3463 c_inhibit_evaluation_warnings--;
3465 if (TREE_CODE (expr.value) == COMPONENT_REF
3466 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
3467 error_at (here, "%<typeof%> applied to a bit-field");
3468 mark_exp_read (expr.value);
3469 ret.spec = TREE_TYPE (expr.value);
3470 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
3471 /* This is returned with the type so that when the type is
3472 evaluated, this can be evaluated. */
3474 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
3475 pop_maybe_used (was_vm);
3476 /* For use in macros such as those in <stdatomic.h>, remove all
3477 qualifiers from atomic types. (const can be an issue for more macros
3478 using typeof than just the <stdatomic.h> ones.) */
3479 if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
3480 ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
3482 parens.skip_until_found_close (parser);
3486 /* Parse an alignment-specifier.
3490 alignment-specifier:
3491 _Alignas ( type-name )
3492 _Alignas ( constant-expression )
3496 c_parser_alignas_specifier (c_parser * parser)
3498 tree ret = error_mark_node;
3499 location_t loc = c_parser_peek_token (parser)->location;
3500 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
3501 c_parser_consume_token (parser);
3503 pedwarn_c99 (loc, OPT_Wpedantic,
3504 "ISO C99 does not support %<_Alignas%>");
3506 pedwarn_c99 (loc, OPT_Wpedantic,
3507 "ISO C90 does not support %<_Alignas%>");
3508 matching_parens parens;
3509 if (!parens.require_open (parser))
3511 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
3513 struct c_type_name *type = c_parser_type_name (parser);
3515 ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL),
3519 ret = c_parser_expr_no_commas (parser, NULL).value;
3520 parens.skip_until_found_close (parser);
3524 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3525 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3526 a typedef name may be redeclared; otherwise it may not. KIND
3527 indicates which kind of declarator is wanted. Returns a valid
3528 declarator except in the case of a syntax error in which case NULL is
3529 returned. *SEEN_ID is set to true if an identifier being declared is
3530 seen; this is used to diagnose bad forms of abstract array declarators
3531 and to determine whether an identifier list is syntactically permitted.
3534 pointer[opt] direct-declarator
3538 ( attributes[opt] declarator )
3539 direct-declarator array-declarator
3540 direct-declarator ( parameter-type-list )
3541 direct-declarator ( identifier-list[opt] )
3544 * type-qualifier-list[opt]
3545 * type-qualifier-list[opt] pointer
3547 type-qualifier-list:
3550 type-qualifier-list type-qualifier
3551 type-qualifier-list attributes
3554 [ type-qualifier-list[opt] assignment-expression[opt] ]
3555 [ static type-qualifier-list[opt] assignment-expression ]
3556 [ type-qualifier-list static assignment-expression ]
3557 [ type-qualifier-list[opt] * ]
3559 parameter-type-list:
3561 parameter-list , ...
3564 parameter-declaration
3565 parameter-list , parameter-declaration
3567 parameter-declaration:
3568 declaration-specifiers declarator attributes[opt]
3569 declaration-specifiers abstract-declarator[opt] attributes[opt]
3573 identifier-list , identifier
3575 abstract-declarator:
3577 pointer[opt] direct-abstract-declarator
3579 direct-abstract-declarator:
3580 ( attributes[opt] abstract-declarator )
3581 direct-abstract-declarator[opt] array-declarator
3582 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3587 direct-declarator ( parameter-forward-declarations
3588 parameter-type-list[opt] )
3590 direct-abstract-declarator:
3591 direct-abstract-declarator[opt] ( parameter-forward-declarations
3592 parameter-type-list[opt] )
3594 parameter-forward-declarations:
3596 parameter-forward-declarations parameter-list ;
3598 The uses of attributes shown above are GNU extensions.
3600 Some forms of array declarator are not included in C99 in the
3601 syntax for abstract declarators; these are disallowed elsewhere.
3602 This may be a defect (DR#289).
3604 This function also accepts an omitted abstract declarator as being
3605 an abstract declarator, although not part of the formal syntax. */
3607 struct c_declarator *
3608 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3611 /* Parse any initial pointer part. */
3612 if (c_parser_next_token_is (parser, CPP_MULT))
3614 struct c_declspecs *quals_attrs = build_null_declspecs ();
3615 struct c_declarator *inner;
3616 c_parser_consume_token (parser);
3617 c_parser_declspecs (parser, quals_attrs, false, false, true,
3618 false, false, cla_prefer_id);
3619 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3623 return make_pointer_declarator (quals_attrs, inner);
3625 /* Now we have a direct declarator, direct abstract declarator or
3626 nothing (which counts as a direct abstract declarator here). */
3627 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
3630 /* Parse a direct declarator or direct abstract declarator; arguments
3631 as c_parser_declarator. */
3633 static struct c_declarator *
3634 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
3637 /* The direct declarator must start with an identifier (possibly
3638 omitted) or a parenthesized declarator (possibly abstract). In
3639 an ordinary declarator, initial parentheses must start a
3640 parenthesized declarator. In an abstract declarator or parameter
3641 declarator, they could start a parenthesized declarator or a
3642 parameter list. To tell which, the open parenthesis and any
3643 following attributes must be read. If a declaration specifier
3644 follows, then it is a parameter list; if the specifier is a
3645 typedef name, there might be an ambiguity about redeclaring it,
3646 which is resolved in the direction of treating it as a typedef
3647 name. If a close parenthesis follows, it is also an empty
3648 parameter list, as the syntax does not permit empty abstract
3649 declarators. Otherwise, it is a parenthesized declarator (in
3650 which case the analysis may be repeated inside it, recursively).
3652 ??? There is an ambiguity in a parameter declaration "int
3653 (__attribute__((foo)) x)", where x is not a typedef name: it
3654 could be an abstract declarator for a function, or declare x with
3655 parentheses. The proper resolution of this ambiguity needs
3656 documenting. At present we follow an accident of the old
3657 parser's implementation, whereby the first parameter must have
3658 some declaration specifiers other than just attributes. Thus as
3659 a parameter declaration it is treated as a parenthesized
3660 parameter named x, and as an abstract declarator it is
3663 ??? Also following the old parser, attributes inside an empty
3664 parameter list are ignored, making it a list not yielding a
3665 prototype, rather than giving an error or making it have one
3666 parameter with implicit type int.
3668 ??? Also following the old parser, typedef names may be
3669 redeclared in declarators, but not Objective-C class names. */
3671 if (kind != C_DTR_ABSTRACT
3672 && c_parser_next_token_is (parser, CPP_NAME)
3674 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
3675 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3676 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
3678 struct c_declarator *inner
3679 = build_id_declarator (c_parser_peek_token (parser)->value);
3681 inner->id_loc = c_parser_peek_token (parser)->location;
3682 c_parser_consume_token (parser);
3683 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3686 if (kind != C_DTR_NORMAL
3687 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3689 struct c_declarator *inner = build_id_declarator (NULL_TREE);
3690 inner->id_loc = c_parser_peek_token (parser)->location;
3691 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3694 /* Either we are at the end of an abstract declarator, or we have
3697 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3700 struct c_declarator *inner;
3701 c_parser_consume_token (parser);
3702 attrs = c_parser_attributes (parser);
3703 if (kind != C_DTR_NORMAL
3704 && (c_parser_next_token_starts_declspecs (parser)
3705 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
3707 struct c_arg_info *args
3708 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
3715 = build_function_declarator (args,
3716 build_id_declarator (NULL_TREE));
3717 return c_parser_direct_declarator_inner (parser, *seen_id,
3721 /* A parenthesized declarator. */
3722 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
3723 if (inner != NULL && attrs != NULL)
3724 inner = build_attrs_declarator (attrs, inner);
3725 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3727 c_parser_consume_token (parser);
3731 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3735 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3742 if (kind == C_DTR_NORMAL)
3744 c_parser_error (parser, "expected identifier or %<(%>");
3748 return build_id_declarator (NULL_TREE);
3752 /* Parse part of a direct declarator or direct abstract declarator,
3753 given that some (in INNER) has already been parsed; ID_PRESENT is
3754 true if an identifier is present, false for an abstract
3757 static struct c_declarator *
3758 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3759 struct c_declarator *inner)
3761 /* Parse a sequence of array declarators and parameter lists. */
3762 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3764 location_t brace_loc = c_parser_peek_token (parser)->location;
3765 struct c_declarator *declarator;
3766 struct c_declspecs *quals_attrs = build_null_declspecs ();
3769 struct c_expr dimen;
3770 dimen.value = NULL_TREE;
3771 dimen.original_code = ERROR_MARK;
3772 dimen.original_type = NULL_TREE;
3773 c_parser_consume_token (parser);
3774 c_parser_declspecs (parser, quals_attrs, false, false, true,
3775 false, false, cla_prefer_id);
3776 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3778 c_parser_consume_token (parser);
3779 if (static_seen && !quals_attrs->declspecs_seen_p)
3780 c_parser_declspecs (parser, quals_attrs, false, false, true,
3781 false, false, cla_prefer_id);
3782 if (!quals_attrs->declspecs_seen_p)
3784 /* If "static" is present, there must be an array dimension.
3785 Otherwise, there may be a dimension, "*", or no
3790 dimen = c_parser_expr_no_commas (parser, NULL);
3794 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3796 dimen.value = NULL_TREE;
3799 else if (c_parser_next_token_is (parser, CPP_MULT))
3801 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3803 dimen.value = NULL_TREE;
3805 c_parser_consume_token (parser);
3810 dimen = c_parser_expr_no_commas (parser, NULL);
3816 dimen = c_parser_expr_no_commas (parser, NULL);
3819 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3820 c_parser_consume_token (parser);
3823 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3828 dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true);
3829 declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs,
3830 static_seen, star_seen);
3831 if (declarator == NULL)
3833 inner = set_array_declarator_inner (declarator, inner);
3834 return c_parser_direct_declarator_inner (parser, id_present, inner);
3836 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3839 struct c_arg_info *args;
3840 c_parser_consume_token (parser);
3841 attrs = c_parser_attributes (parser);
3842 args = c_parser_parms_declarator (parser, id_present, attrs);
3847 inner = build_function_declarator (args, inner);
3848 return c_parser_direct_declarator_inner (parser, id_present, inner);
3854 /* Parse a parameter list or identifier list, including the closing
3855 parenthesis but not the opening one. ATTRS are the attributes at
3856 the start of the list. ID_LIST_OK is true if an identifier list is
3857 acceptable; such a list must not have attributes at the start. */
3859 static struct c_arg_info *
3860 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3863 declare_parm_level ();
3864 /* If the list starts with an identifier, it is an identifier list.
3865 Otherwise, it is either a prototype list or an empty list. */
3868 && c_parser_next_token_is (parser, CPP_NAME)
3869 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3871 /* Look ahead to detect typos in type names. */
3872 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3873 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3874 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3875 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE
3876 && c_parser_peek_2nd_token (parser)->type != CPP_KEYWORD)
3878 tree list = NULL_TREE, *nextp = &list;
3879 while (c_parser_next_token_is (parser, CPP_NAME)
3880 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3882 *nextp = build_tree_list (NULL_TREE,
3883 c_parser_peek_token (parser)->value);
3884 nextp = & TREE_CHAIN (*nextp);
3885 c_parser_consume_token (parser);
3886 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3888 c_parser_consume_token (parser);
3889 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3891 c_parser_error (parser, "expected identifier");
3895 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3897 struct c_arg_info *ret = build_arg_info ();
3899 c_parser_consume_token (parser);
3905 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3913 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3920 /* Parse a parameter list (possibly empty), including the closing
3921 parenthesis but not the opening one. ATTRS are the attributes at
3922 the start of the list. EXPR is NULL or an expression that needs to
3923 be evaluated for the side effects of array size expressions in the
3926 static struct c_arg_info *
3927 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3929 bool bad_parm = false;
3931 /* ??? Following the old parser, forward parameter declarations may
3932 use abstract declarators, and if no real parameter declarations
3933 follow the forward declarations then this is not diagnosed. Also
3934 note as above that attributes are ignored as the only contents of
3935 the parentheses, or as the only contents after forward
3937 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3939 struct c_arg_info *ret = build_arg_info ();
3940 c_parser_consume_token (parser);
3943 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3945 struct c_arg_info *ret = build_arg_info ();
3947 if (flag_allow_parameterless_variadic_functions)
3949 /* F (...) is allowed. */
3950 ret->types = NULL_TREE;
3954 /* Suppress -Wold-style-definition for this case. */
3955 ret->types = error_mark_node;
3956 error_at (c_parser_peek_token (parser)->location,
3957 "ISO C requires a named argument before %<...%>");
3959 c_parser_consume_token (parser);
3960 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3962 c_parser_consume_token (parser);
3967 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3972 /* Nonempty list of parameters, either terminated with semicolon
3973 (forward declarations; recurse) or with close parenthesis (normal
3974 function) or with ", ... )" (variadic function). */
3977 /* Parse a parameter. */
3978 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3983 push_parm_decl (parm, &expr);
3984 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3987 c_parser_consume_token (parser);
3988 mark_forward_parm_decls ();
3989 new_attrs = c_parser_attributes (parser);
3990 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3992 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3994 c_parser_consume_token (parser);
3998 return get_parm_info (false, expr);
4000 if (!c_parser_require (parser, CPP_COMMA,
4001 "expected %<;%>, %<,%> or %<)%>",
4002 UNKNOWN_LOCATION, false))
4004 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4007 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4009 c_parser_consume_token (parser);
4010 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4012 c_parser_consume_token (parser);
4016 return get_parm_info (true, expr);
4020 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4028 /* Parse a parameter declaration. ATTRS are the attributes at the
4029 start of the declaration if it is the first parameter. */
4031 static struct c_parm *
4032 c_parser_parameter_declaration (c_parser *parser, tree attrs)
4034 struct c_declspecs *specs;
4035 struct c_declarator *declarator;
4037 tree postfix_attrs = NULL_TREE;
4040 /* Accept #pragmas between parameter declarations. */
4041 while (c_parser_next_token_is (parser, CPP_PRAGMA))
4042 c_parser_pragma (parser, pragma_param, NULL);
4044 if (!c_parser_next_token_starts_declspecs (parser))
4046 c_token *token = c_parser_peek_token (parser);
4049 c_parser_set_source_position_from_token (token);
4050 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
4052 name_hint hint = lookup_name_fuzzy (token->value,
4053 FUZZY_LOOKUP_TYPENAME,
4057 gcc_rich_location richloc (token->location);
4058 richloc.add_fixit_replace (hint.suggestion ());
4060 "unknown type name %qE; did you mean %qs?",
4061 token->value, hint.suggestion ());
4064 error_at (token->location, "unknown type name %qE", token->value);
4065 parser->error = true;
4067 /* ??? In some Objective-C cases '...' isn't applicable so there
4068 should be a different message. */
4070 c_parser_error (parser,
4071 "expected declaration specifiers or %<...%>");
4072 c_parser_skip_to_end_of_parameter (parser);
4076 location_t start_loc = c_parser_peek_token (parser)->location;
4078 specs = build_null_declspecs ();
4081 declspecs_add_attrs (input_location, specs, attrs);
4084 c_parser_declspecs (parser, specs, true, true, true, true, false,
4085 cla_nonabstract_decl);
4086 finish_declspecs (specs);
4087 pending_xref_error ();
4088 prefix_attrs = specs->attrs;
4089 specs->attrs = NULL_TREE;
4090 declarator = c_parser_declarator (parser,
4091 specs->typespec_kind != ctsk_none,
4092 C_DTR_PARM, &dummy);
4093 if (declarator == NULL)
4095 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4098 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4099 postfix_attrs = c_parser_attributes (parser);
4101 /* Generate a location for the parameter, ranging from the start of the
4102 initial token to the end of the final token.
4104 If we have a identifier, then use it for the caret location, e.g.
4106 extern int callee (int one, int (*two)(int, int), float three);
4107 ~~~~~~^~~~~~~~~~~~~~
4109 otherwise, reuse the start location for the caret location e.g.:
4111 extern int callee (int one, int (*)(int, int), float three);
4114 location_t end_loc = parser->last_token_location;
4116 /* Find any cdk_id declarator; determine if we have an identifier. */
4117 c_declarator *id_declarator = declarator;
4118 while (id_declarator && id_declarator->kind != cdk_id)
4119 id_declarator = id_declarator->declarator;
4120 location_t caret_loc = (id_declarator->u.id
4121 ? id_declarator->id_loc
4123 location_t param_loc = make_location (caret_loc, start_loc, end_loc);
4125 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
4126 declarator, param_loc);
4129 /* Parse a string literal in an asm expression. It should not be
4130 translated, and wide string literals are an error although
4131 permitted by the syntax. This is a GNU extension.
4136 ??? At present, following the old parser, the caller needs to have
4137 set lex_untranslated_string to 1. It would be better to follow the
4138 C++ parser rather than using this kludge. */
4141 c_parser_asm_string_literal (c_parser *parser)
4144 int save_flag = warn_overlength_strings;
4145 warn_overlength_strings = 0;
4146 if (c_parser_next_token_is (parser, CPP_STRING))
4148 str = c_parser_peek_token (parser)->value;
4149 c_parser_consume_token (parser);
4151 else if (c_parser_next_token_is (parser, CPP_WSTRING))
4153 error_at (c_parser_peek_token (parser)->location,
4154 "wide string literal in %<asm%>");
4155 str = build_string (1, "");
4156 c_parser_consume_token (parser);
4160 c_parser_error (parser, "expected string literal");
4163 warn_overlength_strings = save_flag;
4167 /* Parse a simple asm expression. This is used in restricted
4168 contexts, where a full expression with inputs and outputs does not
4169 make sense. This is a GNU extension.
4172 asm ( asm-string-literal )
4176 c_parser_simple_asm_expr (c_parser *parser)
4179 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4180 /* ??? Follow the C++ parser rather than using the
4181 lex_untranslated_string kludge. */
4182 parser->lex_untranslated_string = true;
4183 c_parser_consume_token (parser);
4184 matching_parens parens;
4185 if (!parens.require_open (parser))
4187 parser->lex_untranslated_string = false;
4190 str = c_parser_asm_string_literal (parser);
4191 parser->lex_untranslated_string = false;
4192 if (!parens.require_close (parser))
4194 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4201 c_parser_attribute_any_word (c_parser *parser)
4203 tree attr_name = NULL_TREE;
4205 if (c_parser_next_token_is (parser, CPP_KEYWORD))
4207 /* ??? See comment above about what keywords are accepted here. */
4209 switch (c_parser_peek_token (parser)->keyword)
4240 case RID_TRANSACTION_ATOMIC:
4241 case RID_TRANSACTION_CANCEL:
4257 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4258 attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword];
4260 else if (c_parser_next_token_is (parser, CPP_NAME))
4261 attr_name = c_parser_peek_token (parser)->value;
4266 /* Parse (possibly empty) attributes. This is a GNU extension.
4270 attributes attribute
4273 __attribute__ ( ( attribute-list ) )
4277 attribute_list , attrib
4282 any-word ( identifier )
4283 any-word ( identifier , nonempty-expr-list )
4284 any-word ( expr-list )
4286 where the "identifier" must not be declared as a type, and
4287 "any-word" may be any identifier (including one declared as a
4288 type), a reserved word storage class specifier, type specifier or
4289 type qualifier. ??? This still leaves out most reserved keywords
4290 (following the old parser), shouldn't we include them, and why not
4291 allow identifiers declared as types to start the arguments? */
4294 c_parser_attributes (c_parser *parser)
4296 tree attrs = NULL_TREE;
4297 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
4299 /* ??? Follow the C++ parser rather than using the
4300 lex_untranslated_string kludge. */
4301 parser->lex_untranslated_string = true;
4302 /* Consume the `__attribute__' keyword. */
4303 c_parser_consume_token (parser);
4304 /* Look for the two `(' tokens. */
4305 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4307 parser->lex_untranslated_string = false;
4310 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4312 parser->lex_untranslated_string = false;
4313 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4316 /* Parse the attribute list. */
4317 while (c_parser_next_token_is (parser, CPP_COMMA)
4318 || c_parser_next_token_is (parser, CPP_NAME)
4319 || c_parser_next_token_is (parser, CPP_KEYWORD))
4321 tree attr, attr_name, attr_args;
4322 vec<tree, va_gc> *expr_list;
4323 if (c_parser_next_token_is (parser, CPP_COMMA))
4325 c_parser_consume_token (parser);
4329 attr_name = c_parser_attribute_any_word (parser);
4330 if (attr_name == NULL)
4332 attr_name = canonicalize_attr_name (attr_name);
4333 c_parser_consume_token (parser);
4334 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
4336 attr = build_tree_list (attr_name, NULL_TREE);
4337 /* Add this attribute to the list. */
4338 attrs = chainon (attrs, attr);
4339 /* If the next token isn't a comma, we're done. */
4340 if (!c_parser_next_token_is (parser, CPP_COMMA))
4344 c_parser_consume_token (parser);
4345 /* Parse the attribute contents. If they start with an
4346 identifier which is followed by a comma or close
4347 parenthesis, then the arguments start with that
4348 identifier; otherwise they are an expression list.
4349 In objective-c the identifier may be a classname. */
4350 if (c_parser_next_token_is (parser, CPP_NAME)
4351 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
4352 || (c_dialect_objc ()
4353 && c_parser_peek_token (parser)->id_kind
4355 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
4356 || (c_parser_peek_2nd_token (parser)->type
4357 == CPP_CLOSE_PAREN))
4358 && (attribute_takes_identifier_p (attr_name)
4359 || (c_dialect_objc ()
4360 && c_parser_peek_token (parser)->id_kind
4361 == C_ID_CLASSNAME)))
4363 tree arg1 = c_parser_peek_token (parser)->value;
4364 c_parser_consume_token (parser);
4365 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4366 attr_args = build_tree_list (NULL_TREE, arg1);
4370 c_parser_consume_token (parser);
4371 expr_list = c_parser_expr_list (parser, false, true,
4372 NULL, NULL, NULL, NULL);
4373 tree_list = build_tree_list_vec (expr_list);
4374 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
4375 release_tree_vector (expr_list);
4380 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4381 attr_args = NULL_TREE;
4384 expr_list = c_parser_expr_list (parser, false, true,
4385 NULL, NULL, NULL, NULL);
4386 attr_args = build_tree_list_vec (expr_list);
4387 release_tree_vector (expr_list);
4391 attr = build_tree_list (attr_name, attr_args);
4392 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4393 c_parser_consume_token (parser);
4396 parser->lex_untranslated_string = false;
4397 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4401 /* Add this attribute to the list. */
4402 attrs = chainon (attrs, attr);
4403 /* If the next token isn't a comma, we're done. */
4404 if (!c_parser_next_token_is (parser, CPP_COMMA))
4407 /* Look for the two `)' tokens. */
4408 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4409 c_parser_consume_token (parser);
4412 parser->lex_untranslated_string = false;
4413 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4417 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4418 c_parser_consume_token (parser);
4421 parser->lex_untranslated_string = false;
4422 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4426 parser->lex_untranslated_string = false;
4432 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4433 says whether alignment specifiers are OK (only in cases that might
4434 be the type name of a compound literal).
4437 specifier-qualifier-list abstract-declarator[opt]
4440 struct c_type_name *
4441 c_parser_type_name (c_parser *parser, bool alignas_ok)
4443 struct c_declspecs *specs = build_null_declspecs ();
4444 struct c_declarator *declarator;
4445 struct c_type_name *ret;
4447 c_parser_declspecs (parser, specs, false, true, true, alignas_ok, false,
4449 if (!specs->declspecs_seen_p)
4451 c_parser_error (parser, "expected specifier-qualifier-list");
4454 if (specs->type != error_mark_node)
4456 pending_xref_error ();
4457 finish_declspecs (specs);
4459 declarator = c_parser_declarator (parser,
4460 specs->typespec_kind != ctsk_none,
4461 C_DTR_ABSTRACT, &dummy);
4462 if (declarator == NULL)
4464 ret = XOBNEW (&parser_obstack, struct c_type_name);
4466 ret->declarator = declarator;
4470 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4473 assignment-expression
4474 { initializer-list }
4475 { initializer-list , }
4478 designation[opt] initializer
4479 initializer-list , designation[opt] initializer
4486 designator-list designator
4493 [ constant-expression ]
4505 [ constant-expression ... constant-expression ]
4507 Any expression without commas is accepted in the syntax for the
4508 constant-expressions, with non-constant expressions rejected later.
4510 This function is only used for top-level initializers; for nested
4511 ones, see c_parser_initval. */
4513 static struct c_expr
4514 c_parser_initializer (c_parser *parser)
4516 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4517 return c_parser_braced_init (parser, NULL_TREE, false, NULL);
4521 location_t loc = c_parser_peek_token (parser)->location;
4522 ret = c_parser_expr_no_commas (parser, NULL);
4523 if (TREE_CODE (ret.value) != STRING_CST
4524 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
4525 ret = convert_lvalue_to_rvalue (loc, ret, true, true);
4530 /* The location of the last comma within the current initializer list,
4531 or UNKNOWN_LOCATION if not within one. */
4533 location_t last_init_list_comma;
4535 /* Parse a braced initializer list. TYPE is the type specified for a
4536 compound literal, and NULL_TREE for other initializers and for
4537 nested braced lists. NESTED_P is true for nested braced lists,
4538 false for the list of a compound literal or the list that is the
4539 top-level initializer in a declaration. */
4541 static struct c_expr
4542 c_parser_braced_init (c_parser *parser, tree type, bool nested_p,
4543 struct obstack *outer_obstack)
4546 struct obstack braced_init_obstack;
4547 location_t brace_loc = c_parser_peek_token (parser)->location;
4548 gcc_obstack_init (&braced_init_obstack);
4549 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
4550 matching_braces braces;
4551 braces.consume_open (parser);
4554 finish_implicit_inits (brace_loc, outer_obstack);
4555 push_init_level (brace_loc, 0, &braced_init_obstack);
4558 really_start_incremental_init (type);
4559 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4561 pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces");
4565 /* Parse a non-empty initializer list, possibly with a trailing
4569 c_parser_initelt (parser, &braced_init_obstack);
4572 if (c_parser_next_token_is (parser, CPP_COMMA))
4574 last_init_list_comma = c_parser_peek_token (parser)->location;
4575 c_parser_consume_token (parser);
4579 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4583 c_token *next_tok = c_parser_peek_token (parser);
4584 if (next_tok->type != CPP_CLOSE_BRACE)
4587 ret.original_code = ERROR_MARK;
4588 ret.original_type = NULL;
4589 braces.skip_until_found_close (parser);
4590 pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma);
4591 obstack_free (&braced_init_obstack, NULL);
4594 location_t close_loc = next_tok->location;
4595 c_parser_consume_token (parser);
4596 ret = pop_init_level (brace_loc, 0, &braced_init_obstack, close_loc);
4597 obstack_free (&braced_init_obstack, NULL);
4598 set_c_expr_source_range (&ret, brace_loc, close_loc);
4602 /* Parse a nested initializer, including designators. */
4605 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
4607 /* Parse any designator or designator list. A single array
4608 designator may have the subsequent "=" omitted in GNU C, but a
4609 longer list or a structure member designator may not. */
4610 if (c_parser_next_token_is (parser, CPP_NAME)
4611 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
4613 /* Old-style structure member designator. */
4614 set_init_label (c_parser_peek_token (parser)->location,
4615 c_parser_peek_token (parser)->value,
4616 c_parser_peek_token (parser)->location,
4617 braced_init_obstack);
4618 /* Use the colon as the error location. */
4619 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
4620 "obsolete use of designated initializer with %<:%>");
4621 c_parser_consume_token (parser);
4622 c_parser_consume_token (parser);
4626 /* des_seen is 0 if there have been no designators, 1 if there
4627 has been a single array designator and 2 otherwise. */
4629 /* Location of a designator. */
4630 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4631 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
4632 || c_parser_next_token_is (parser, CPP_DOT))
4634 int des_prev = des_seen;
4636 des_loc = c_parser_peek_token (parser)->location;
4639 if (c_parser_next_token_is (parser, CPP_DOT))
4642 c_parser_consume_token (parser);
4643 if (c_parser_next_token_is (parser, CPP_NAME))
4645 set_init_label (des_loc, c_parser_peek_token (parser)->value,
4646 c_parser_peek_token (parser)->location,
4647 braced_init_obstack);
4648 c_parser_consume_token (parser);
4654 init.original_code = ERROR_MARK;
4655 init.original_type = NULL;
4656 c_parser_error (parser, "expected identifier");
4657 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4658 process_init_element (input_location, init, false,
4659 braced_init_obstack);
4666 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4667 location_t array_index_loc = UNKNOWN_LOCATION;
4668 /* ??? Following the old parser, [ objc-receiver
4669 objc-message-args ] is accepted as an initializer,
4670 being distinguished from a designator by what follows
4671 the first assignment expression inside the square
4672 brackets, but after a first array designator a
4673 subsequent square bracket is for Objective-C taken to
4674 start an expression, using the obsolete form of
4675 designated initializer without '=', rather than
4676 possibly being a second level of designation: in LALR
4677 terms, the '[' is shifted rather than reducing
4678 designator to designator-list. */
4679 if (des_prev == 1 && c_dialect_objc ())
4681 des_seen = des_prev;
4684 if (des_prev == 0 && c_dialect_objc ())
4686 /* This might be an array designator or an
4687 Objective-C message expression. If the former,
4688 continue parsing here; if the latter, parse the
4689 remainder of the initializer given the starting
4690 primary-expression. ??? It might make sense to
4691 distinguish when des_prev == 1 as well; see
4692 previous comment. */
4694 struct c_expr mexpr;
4695 c_parser_consume_token (parser);
4696 if (c_parser_peek_token (parser)->type == CPP_NAME
4697 && ((c_parser_peek_token (parser)->id_kind
4699 || (c_parser_peek_token (parser)->id_kind
4700 == C_ID_CLASSNAME)))
4702 /* Type name receiver. */
4703 tree id = c_parser_peek_token (parser)->value;
4704 c_parser_consume_token (parser);
4705 rec = objc_get_class_reference (id);
4706 goto parse_message_args;
4708 first = c_parser_expr_no_commas (parser, NULL).value;
4709 mark_exp_read (first);
4710 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
4711 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4712 goto array_desig_after_first;
4713 /* Expression receiver. So far only one part
4714 without commas has been parsed; there might be
4715 more of the expression. */
4717 while (c_parser_next_token_is (parser, CPP_COMMA))
4720 location_t comma_loc, exp_loc;
4721 comma_loc = c_parser_peek_token (parser)->location;
4722 c_parser_consume_token (parser);
4723 exp_loc = c_parser_peek_token (parser)->location;
4724 next = c_parser_expr_no_commas (parser, NULL);
4725 next = convert_lvalue_to_rvalue (exp_loc, next,
4727 rec = build_compound_expr (comma_loc, rec, next.value);
4730 /* Now parse the objc-message-args. */
4731 args = c_parser_objc_message_args (parser);
4732 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4735 = objc_build_message_expr (rec, args);
4736 mexpr.original_code = ERROR_MARK;
4737 mexpr.original_type = NULL;
4738 /* Now parse and process the remainder of the
4739 initializer, starting with this message
4740 expression as a primary-expression. */
4741 c_parser_initval (parser, &mexpr, braced_init_obstack);
4744 c_parser_consume_token (parser);
4745 array_index_loc = c_parser_peek_token (parser)->location;
4746 first = c_parser_expr_no_commas (parser, NULL).value;
4747 mark_exp_read (first);
4748 array_desig_after_first:
4749 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4751 ellipsis_loc = c_parser_peek_token (parser)->location;
4752 c_parser_consume_token (parser);
4753 second = c_parser_expr_no_commas (parser, NULL).value;
4754 mark_exp_read (second);
4758 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
4760 c_parser_consume_token (parser);
4761 set_init_index (array_index_loc, first, second,
4762 braced_init_obstack);
4764 pedwarn (ellipsis_loc, OPT_Wpedantic,
4765 "ISO C forbids specifying range of elements to initialize");
4768 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4774 if (c_parser_next_token_is (parser, CPP_EQ))
4776 pedwarn_c90 (des_loc, OPT_Wpedantic,
4777 "ISO C90 forbids specifying subobject "
4779 c_parser_consume_token (parser);
4784 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
4785 "obsolete use of designated initializer without %<=%>");
4790 init.original_code = ERROR_MARK;
4791 init.original_type = NULL;
4792 c_parser_error (parser, "expected %<=%>");
4793 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
4794 process_init_element (input_location, init, false,
4795 braced_init_obstack);
4801 c_parser_initval (parser, NULL, braced_init_obstack);
4804 /* Parse a nested initializer; as c_parser_initializer but parses
4805 initializers within braced lists, after any designators have been
4806 applied. If AFTER is not NULL then it is an Objective-C message
4807 expression which is the primary-expression starting the
4811 c_parser_initval (c_parser *parser, struct c_expr *after,
4812 struct obstack * braced_init_obstack)
4815 gcc_assert (!after || c_dialect_objc ());
4816 location_t loc = c_parser_peek_token (parser)->location;
4818 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
4819 init = c_parser_braced_init (parser, NULL_TREE, true,
4820 braced_init_obstack);
4823 init = c_parser_expr_no_commas (parser, after);
4824 if (init.value != NULL_TREE
4825 && TREE_CODE (init.value) != STRING_CST
4826 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
4827 init = convert_lvalue_to_rvalue (loc, init, true, true);
4829 process_init_element (loc, init, false, braced_init_obstack);
4832 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4833 C99 6.8.2, C11 6.8.2).
4836 { block-item-list[opt] }
4837 { label-declarations block-item-list }
4841 block-item-list block-item
4853 { label-declarations block-item-list }
4856 __extension__ nested-declaration
4857 nested-function-definition
4861 label-declarations label-declaration
4864 __label__ identifier-list ;
4866 Allowing the mixing of declarations and code is new in C99. The
4867 GNU syntax also permits (not shown above) labels at the end of
4868 compound statements, which yield an error. We don't allow labels
4869 on declarations; this might seem like a natural extension, but
4870 there would be a conflict between attributes on the label and
4871 prefix attributes on the declaration. ??? The syntax follows the
4872 old parser in requiring something after label declarations.
4873 Although they are erroneous if the labels declared aren't defined,
4874 is it useful for the syntax to be this way?
4895 cancellation-point-directive */
4898 c_parser_compound_statement (c_parser *parser)
4901 location_t brace_loc;
4902 brace_loc = c_parser_peek_token (parser)->location;
4903 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4905 /* Ensure a scope is entered and left anyway to avoid confusion
4906 if we have just prepared to enter a function body. */
4907 stmt = c_begin_compound_stmt (true);
4908 c_end_compound_stmt (brace_loc, stmt, true);
4909 return error_mark_node;
4911 stmt = c_begin_compound_stmt (true);
4912 c_parser_compound_statement_nostart (parser);
4914 return c_end_compound_stmt (brace_loc, stmt, true);
4917 /* Parse a compound statement except for the opening brace. This is
4918 used for parsing both compound statements and statement expressions
4919 (which follow different paths to handling the opening). */
4922 c_parser_compound_statement_nostart (c_parser *parser)
4924 bool last_stmt = false;
4925 bool last_label = false;
4926 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4927 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4928 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4930 add_debug_begin_stmt (c_parser_peek_token (parser)->location);
4931 c_parser_consume_token (parser);
4934 mark_valid_location_for_stdc_pragma (true);
4935 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4937 /* Read zero or more forward-declarations for labels that nested
4938 functions can jump to. */
4939 mark_valid_location_for_stdc_pragma (false);
4940 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4942 label_loc = c_parser_peek_token (parser)->location;
4943 c_parser_consume_token (parser);
4944 /* Any identifiers, including those declared as type names,
4949 if (c_parser_next_token_is_not (parser, CPP_NAME))
4951 c_parser_error (parser, "expected identifier");
4955 = declare_label (c_parser_peek_token (parser)->value);
4956 C_DECLARED_LABEL_FLAG (label) = 1;
4957 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4958 c_parser_consume_token (parser);
4959 if (c_parser_next_token_is (parser, CPP_COMMA))
4960 c_parser_consume_token (parser);
4964 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4966 pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations");
4968 /* We must now have at least one statement, label or declaration. */
4969 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4971 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4972 c_parser_error (parser, "expected declaration or statement");
4973 c_parser_consume_token (parser);
4976 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4978 location_t loc = c_parser_peek_token (parser)->location;
4979 loc = expansion_point_location_if_in_system_header (loc);
4980 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4981 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4982 || (c_parser_next_token_is (parser, CPP_NAME)
4983 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4985 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4986 label_loc = c_parser_peek_2nd_token (parser)->location;
4988 label_loc = c_parser_peek_token (parser)->location;
4991 mark_valid_location_for_stdc_pragma (false);
4992 c_parser_label (parser);
4994 else if (!last_label
4995 && c_parser_next_tokens_start_declaration (parser))
4998 mark_valid_location_for_stdc_pragma (false);
4999 bool fallthru_attr_p = false;
5000 c_parser_declaration_or_fndef (parser, true, true, true, true,
5001 true, NULL, vNULL, NULL,
5003 if (last_stmt && !fallthru_attr_p)
5004 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
5005 "ISO C90 forbids mixed declarations and code");
5006 last_stmt = fallthru_attr_p;
5008 else if (!last_label
5009 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
5011 /* __extension__ can start a declaration, but is also an
5012 unary operator that can start an expression. Consume all
5013 but the last of a possible series of __extension__ to
5015 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
5016 && (c_parser_peek_2nd_token (parser)->keyword
5018 c_parser_consume_token (parser);
5019 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
5022 ext = disable_extension_diagnostics ();
5023 c_parser_consume_token (parser);
5025 mark_valid_location_for_stdc_pragma (false);
5026 c_parser_declaration_or_fndef (parser, true, true, true, true,
5028 /* Following the old parser, __extension__ does not
5029 disable this diagnostic. */
5030 restore_extension_diagnostics (ext);
5032 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
5033 "ISO C90 forbids mixed declarations and code");
5039 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5041 /* External pragmas, and some omp pragmas, are not associated
5042 with regular c code, and so are not to be considered statements
5043 syntactically. This ensures that the user doesn't put them
5044 places that would turn into syntax errors if the directive
5046 if (c_parser_pragma (parser,
5047 last_label ? pragma_stmt : pragma_compound,
5049 last_label = false, last_stmt = true;
5051 else if (c_parser_next_token_is (parser, CPP_EOF))
5053 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
5054 c_parser_error (parser, "expected declaration or statement");
5057 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5059 if (parser->in_if_block)
5061 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
5062 error_at (loc, "expected %<}%> before %<else%>");
5067 error_at (loc, "%<else%> without a previous %<if%>");
5068 c_parser_consume_token (parser);
5077 mark_valid_location_for_stdc_pragma (false);
5078 c_parser_statement_after_labels (parser, NULL);
5081 parser->error = false;
5084 error_at (label_loc, "label at end of compound statement");
5085 c_parser_consume_token (parser);
5086 /* Restore the value we started with. */
5087 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
5090 /* Parse all consecutive labels. */
5093 c_parser_all_labels (c_parser *parser)
5095 while (c_parser_next_token_is_keyword (parser, RID_CASE)
5096 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
5097 || (c_parser_next_token_is (parser, CPP_NAME)
5098 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
5099 c_parser_label (parser);
5102 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5105 identifier : attributes[opt]
5106 case constant-expression :
5112 case constant-expression ... constant-expression :
5114 The use of attributes on labels is a GNU extension. The syntax in
5115 GNU C accepts any expressions without commas, non-constant
5116 expressions being rejected later. */
5119 c_parser_label (c_parser *parser)
5121 location_t loc1 = c_parser_peek_token (parser)->location;
5122 tree label = NULL_TREE;
5124 /* Remember whether this case or a user-defined label is allowed to fall
5126 bool fallthrough_p = c_parser_peek_token (parser)->flags & PREV_FALLTHROUGH;
5128 if (c_parser_next_token_is_keyword (parser, RID_CASE))
5131 c_parser_consume_token (parser);
5132 exp1 = c_parser_expr_no_commas (parser, NULL).value;
5133 if (c_parser_next_token_is (parser, CPP_COLON))
5135 c_parser_consume_token (parser);
5136 label = do_case (loc1, exp1, NULL_TREE);
5138 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
5140 c_parser_consume_token (parser);
5141 exp2 = c_parser_expr_no_commas (parser, NULL).value;
5142 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5143 label = do_case (loc1, exp1, exp2);
5146 c_parser_error (parser, "expected %<:%> or %<...%>");
5148 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
5150 c_parser_consume_token (parser);
5151 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5152 label = do_case (loc1, NULL_TREE, NULL_TREE);
5156 tree name = c_parser_peek_token (parser)->value;
5159 location_t loc2 = c_parser_peek_token (parser)->location;
5160 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
5161 c_parser_consume_token (parser);
5162 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
5163 c_parser_consume_token (parser);
5164 attrs = c_parser_attributes (parser);
5165 tlab = define_label (loc2, name);
5168 decl_attributes (&tlab, attrs, 0);
5169 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
5174 if (TREE_CODE (label) == LABEL_EXPR)
5175 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label)) = fallthrough_p;
5177 FALLTHROUGH_LABEL_P (CASE_LABEL (label)) = fallthrough_p;
5179 /* Allow '__attribute__((fallthrough));'. */
5180 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
5182 location_t loc = c_parser_peek_token (parser)->location;
5183 tree attrs = c_parser_attributes (parser);
5184 if (attribute_fallthrough_p (attrs))
5186 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5188 tree fn = build_call_expr_internal_loc (loc,
5194 warning_at (loc, OPT_Wattributes, "%<fallthrough%> attribute "
5195 "not followed by %<;%>");
5197 else if (attrs != NULL_TREE)
5198 warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>"
5199 " can be applied to a null statement");
5201 if (c_parser_next_tokens_start_declaration (parser))
5203 error_at (c_parser_peek_token (parser)->location,
5204 "a label can only be part of a statement and "
5205 "a declaration is not a statement");
5206 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
5207 /*static_assert_ok*/ true,
5208 /*empty_ok*/ true, /*nested*/ true,
5209 /*start_attr_ok*/ true, NULL,
5215 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5220 expression-statement
5228 expression-statement:
5231 selection-statement:
5235 iteration-statement:
5244 return expression[opt] ;
5254 expression-statement:
5260 objc-throw-statement
5261 objc-try-catch-statement
5262 objc-synchronized-statement
5264 objc-throw-statement:
5280 parallel-directive structured-block
5283 kernels-directive structured-block
5286 data-directive structured-block
5289 loop-directive structured-block
5303 parallel-for-construct
5304 parallel-for-simd-construct
5305 parallel-sections-construct
5312 parallel-directive structured-block
5315 for-directive iteration-statement
5318 simd-directive iteration-statements
5321 for-simd-directive iteration-statements
5324 sections-directive section-scope
5327 single-directive structured-block
5329 parallel-for-construct:
5330 parallel-for-directive iteration-statement
5332 parallel-for-simd-construct:
5333 parallel-for-simd-directive iteration-statement
5335 parallel-sections-construct:
5336 parallel-sections-directive section-scope
5339 master-directive structured-block
5342 critical-directive structured-block
5345 atomic-directive expression-statement
5348 ordered-directive structured-block
5350 Transactional Memory:
5353 transaction-statement
5354 transaction-cancel-statement
5356 IF_P is used to track whether there's a (possibly labeled) if statement
5357 which is not enclosed in braces and has an else clause. This is used to
5358 implement -Wparentheses. */
5361 c_parser_statement (c_parser *parser, bool *if_p, location_t *loc_after_labels)
5363 c_parser_all_labels (parser);
5364 if (loc_after_labels)
5365 *loc_after_labels = c_parser_peek_token (parser)->location;
5366 c_parser_statement_after_labels (parser, if_p, NULL);
5369 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5370 of if-else-if conditions.
5372 IF_P is used to track whether there's a (possibly labeled) if statement
5373 which is not enclosed in braces and has an else clause. This is used to
5374 implement -Wparentheses. */
5377 c_parser_statement_after_labels (c_parser *parser, bool *if_p,
5380 location_t loc = c_parser_peek_token (parser)->location;
5381 tree stmt = NULL_TREE;
5382 bool in_if_block = parser->in_if_block;
5383 parser->in_if_block = false;
5387 if (c_parser_peek_token (parser)->type != CPP_OPEN_BRACE)
5388 add_debug_begin_stmt (loc);
5390 switch (c_parser_peek_token (parser)->type)
5392 case CPP_OPEN_BRACE:
5393 add_stmt (c_parser_compound_statement (parser));
5396 switch (c_parser_peek_token (parser)->keyword)
5399 c_parser_if_statement (parser, if_p, chain);
5402 c_parser_switch_statement (parser, if_p);
5405 c_parser_while_statement (parser, false, 0, if_p);
5408 c_parser_do_statement (parser, 0, false);
5411 c_parser_for_statement (parser, false, 0, if_p);
5414 c_parser_consume_token (parser);
5415 if (c_parser_next_token_is (parser, CPP_NAME))
5417 stmt = c_finish_goto_label (loc,
5418 c_parser_peek_token (parser)->value);
5419 c_parser_consume_token (parser);
5421 else if (c_parser_next_token_is (parser, CPP_MULT))
5425 c_parser_consume_token (parser);
5426 val = c_parser_expression (parser);
5427 val = convert_lvalue_to_rvalue (loc, val, false, true);
5428 stmt = c_finish_goto_ptr (loc, val.value);
5431 c_parser_error (parser, "expected identifier or %<*%>");
5432 goto expect_semicolon;
5434 c_parser_consume_token (parser);
5435 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
5436 goto expect_semicolon;
5438 c_parser_consume_token (parser);
5439 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
5440 goto expect_semicolon;
5442 c_parser_consume_token (parser);
5443 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5445 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
5446 c_parser_consume_token (parser);
5450 location_t xloc = c_parser_peek_token (parser)->location;
5451 struct c_expr expr = c_parser_expression_conv (parser);
5452 mark_exp_read (expr.value);
5453 stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc),
5454 expr.value, expr.original_type);
5455 goto expect_semicolon;
5459 stmt = c_parser_asm_statement (parser);
5461 case RID_TRANSACTION_ATOMIC:
5462 case RID_TRANSACTION_RELAXED:
5463 stmt = c_parser_transaction (parser,
5464 c_parser_peek_token (parser)->keyword);
5466 case RID_TRANSACTION_CANCEL:
5467 stmt = c_parser_transaction_cancel (parser);
5468 goto expect_semicolon;
5470 gcc_assert (c_dialect_objc ());
5471 c_parser_consume_token (parser);
5472 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5474 stmt = objc_build_throw_stmt (loc, NULL_TREE);
5475 c_parser_consume_token (parser);
5479 struct c_expr expr = c_parser_expression (parser);
5480 expr = convert_lvalue_to_rvalue (loc, expr, false, false);
5481 expr.value = c_fully_fold (expr.value, false, NULL);
5482 stmt = objc_build_throw_stmt (loc, expr.value);
5483 goto expect_semicolon;
5487 gcc_assert (c_dialect_objc ());
5488 c_parser_objc_try_catch_finally_statement (parser);
5490 case RID_AT_SYNCHRONIZED:
5491 gcc_assert (c_dialect_objc ());
5492 c_parser_objc_synchronized_statement (parser);
5496 /* Allow '__attribute__((fallthrough));'. */
5497 tree attrs = c_parser_attributes (parser);
5498 if (attribute_fallthrough_p (attrs))
5500 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5502 tree fn = build_call_expr_internal_loc (loc,
5507 c_parser_consume_token (parser);
5510 warning_at (loc, OPT_Wattributes,
5511 "%<fallthrough%> attribute not followed "
5514 else if (attrs != NULL_TREE)
5515 warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>"
5516 " can be applied to a null statement");
5524 c_parser_consume_token (parser);
5526 case CPP_CLOSE_PAREN:
5527 case CPP_CLOSE_SQUARE:
5528 /* Avoid infinite loop in error recovery:
5529 c_parser_skip_until_found stops at a closing nesting
5530 delimiter without consuming it, but here we need to consume
5531 it to proceed further. */
5532 c_parser_error (parser, "expected statement");
5533 c_parser_consume_token (parser);
5536 c_parser_pragma (parser, pragma_stmt, if_p);
5540 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
5542 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5545 /* Two cases cannot and do not have line numbers associated: If stmt
5546 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5547 cannot hold line numbers. But that's OK because the statement
5548 will either be changed to a MODIFY_EXPR during gimplification of
5549 the statement expr, or discarded. If stmt was compound, but
5550 without new variables, we will have skipped the creation of a
5551 BIND and will have a bare STATEMENT_LIST. But that's OK because
5552 (recursively) all of the component statements should already have
5553 line numbers assigned. ??? Can we discard no-op statements
5555 if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
5556 protected_set_expr_location (stmt, loc);
5558 parser->in_if_block = in_if_block;
5561 /* Parse the condition from an if, do, while or for statements. */
5564 c_parser_condition (c_parser *parser)
5566 location_t loc = c_parser_peek_token (parser)->location;
5568 cond = c_parser_expression_conv (parser).value;
5569 cond = c_objc_common_truthvalue_conversion (loc, cond);
5570 cond = c_fully_fold (cond, false, NULL);
5571 if (warn_sequence_point)
5572 verify_sequence_points (cond);
5576 /* Parse a parenthesized condition from an if, do or while statement.
5582 c_parser_paren_condition (c_parser *parser)
5585 matching_parens parens;
5586 if (!parens.require_open (parser))
5587 return error_mark_node;
5588 cond = c_parser_condition (parser);
5589 parens.skip_until_found_close (parser);
5593 /* Parse a statement which is a block in C99.
5595 IF_P is used to track whether there's a (possibly labeled) if statement
5596 which is not enclosed in braces and has an else clause. This is used to
5597 implement -Wparentheses. */
5600 c_parser_c99_block_statement (c_parser *parser, bool *if_p,
5601 location_t *loc_after_labels)
5603 tree block = c_begin_compound_stmt (flag_isoc99);
5604 location_t loc = c_parser_peek_token (parser)->location;
5605 c_parser_statement (parser, if_p, loc_after_labels);
5606 return c_end_compound_stmt (loc, block, flag_isoc99);
5609 /* Parse the body of an if statement. This is just parsing a
5610 statement but (a) it is a block in C99, (b) we track whether the
5611 body is an if statement for the sake of -Wparentheses warnings, (c)
5612 we handle an empty body specially for the sake of -Wempty-body
5613 warnings, and (d) we call parser_compound_statement directly
5614 because c_parser_statement_after_labels resets
5615 parser->in_if_block.
5617 IF_P is used to track whether there's a (possibly labeled) if statement
5618 which is not enclosed in braces and has an else clause. This is used to
5619 implement -Wparentheses. */
5622 c_parser_if_body (c_parser *parser, bool *if_p,
5623 const token_indent_info &if_tinfo)
5625 tree block = c_begin_compound_stmt (flag_isoc99);
5626 location_t body_loc = c_parser_peek_token (parser)->location;
5627 location_t body_loc_after_labels = UNKNOWN_LOCATION;
5628 token_indent_info body_tinfo
5629 = get_token_indent_info (c_parser_peek_token (parser));
5631 c_parser_all_labels (parser);
5632 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5634 location_t loc = c_parser_peek_token (parser)->location;
5635 add_stmt (build_empty_stmt (loc));
5636 c_parser_consume_token (parser);
5637 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
5638 warning_at (loc, OPT_Wempty_body,
5639 "suggest braces around empty body in an %<if%> statement");
5641 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5642 add_stmt (c_parser_compound_statement (parser));
5645 body_loc_after_labels = c_parser_peek_token (parser)->location;
5646 c_parser_statement_after_labels (parser, if_p);
5649 token_indent_info next_tinfo
5650 = get_token_indent_info (c_parser_peek_token (parser));
5651 warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo);
5652 if (body_loc_after_labels != UNKNOWN_LOCATION
5653 && next_tinfo.type != CPP_SEMICOLON)
5654 warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location,
5655 if_tinfo.location, RID_IF);
5657 return c_end_compound_stmt (body_loc, block, flag_isoc99);
5660 /* Parse the else body of an if statement. This is just parsing a
5661 statement but (a) it is a block in C99, (b) we handle an empty body
5662 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5663 of if-else-if conditions. */
5666 c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
5669 location_t body_loc = c_parser_peek_token (parser)->location;
5670 tree block = c_begin_compound_stmt (flag_isoc99);
5671 token_indent_info body_tinfo
5672 = get_token_indent_info (c_parser_peek_token (parser));
5673 location_t body_loc_after_labels = UNKNOWN_LOCATION;
5675 c_parser_all_labels (parser);
5676 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5678 location_t loc = c_parser_peek_token (parser)->location;
5681 "suggest braces around empty body in an %<else%> statement");
5682 add_stmt (build_empty_stmt (loc));
5683 c_parser_consume_token (parser);
5687 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5688 body_loc_after_labels = c_parser_peek_token (parser)->location;
5689 c_parser_statement_after_labels (parser, NULL, chain);
5692 token_indent_info next_tinfo
5693 = get_token_indent_info (c_parser_peek_token (parser));
5694 warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo);
5695 if (body_loc_after_labels != UNKNOWN_LOCATION
5696 && next_tinfo.type != CPP_SEMICOLON)
5697 warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location,
5698 else_tinfo.location, RID_ELSE);
5700 return c_end_compound_stmt (body_loc, block, flag_isoc99);
5703 /* We might need to reclassify any previously-lexed identifier, e.g.
5704 when we've left a for loop with an if-statement without else in the
5705 body - we might have used a wrong scope for the token. See PR67784. */
5708 c_parser_maybe_reclassify_token (c_parser *parser)
5710 if (c_parser_next_token_is (parser, CPP_NAME))
5712 c_token *token = c_parser_peek_token (parser);
5714 if (token->id_kind != C_ID_CLASSNAME)
5716 tree decl = lookup_name (token->value);
5718 token->id_kind = C_ID_ID;
5721 if (TREE_CODE (decl) == TYPE_DECL)
5722 token->id_kind = C_ID_TYPENAME;
5724 else if (c_dialect_objc ())
5726 tree objc_interface_decl = objc_is_class_name (token->value);
5727 /* Objective-C class names are in the same namespace as
5728 variables and typedefs, and hence are shadowed by local
5730 if (objc_interface_decl)
5732 token->value = objc_interface_decl;
5733 token->id_kind = C_ID_CLASSNAME;
5740 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5743 if ( expression ) statement
5744 if ( expression ) statement else statement
5746 CHAIN is a vector of if-else-if conditions.
5747 IF_P is used to track whether there's a (possibly labeled) if statement
5748 which is not enclosed in braces and has an else clause. This is used to
5749 implement -Wparentheses. */
5752 c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
5757 bool nested_if = false;
5758 tree first_body, second_body;
5761 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
5762 token_indent_info if_tinfo
5763 = get_token_indent_info (c_parser_peek_token (parser));
5764 c_parser_consume_token (parser);
5765 block = c_begin_compound_stmt (flag_isoc99);
5766 loc = c_parser_peek_token (parser)->location;
5767 cond = c_parser_paren_condition (parser);
5768 in_if_block = parser->in_if_block;
5769 parser->in_if_block = true;
5770 first_body = c_parser_if_body (parser, &nested_if, if_tinfo);
5771 parser->in_if_block = in_if_block;
5773 if (warn_duplicated_cond)
5774 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain);
5776 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
5778 token_indent_info else_tinfo
5779 = get_token_indent_info (c_parser_peek_token (parser));
5780 c_parser_consume_token (parser);
5781 if (warn_duplicated_cond)
5783 if (c_parser_next_token_is_keyword (parser, RID_IF)
5786 /* We've got "if (COND) else if (COND2)". Start the
5787 condition chain and add COND as the first element. */
5788 chain = new vec<tree> ();
5789 if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond))
5790 chain->safe_push (cond);
5792 else if (!c_parser_next_token_is_keyword (parser, RID_IF))
5794 /* This is if-else without subsequent if. Zap the condition
5795 chain; we would have already warned at this point. */
5800 second_body = c_parser_else_body (parser, else_tinfo, chain);
5801 /* Set IF_P to true to indicate that this if statement has an
5802 else clause. This may trigger the Wparentheses warning
5803 below when we get back up to the parent if statement. */
5809 second_body = NULL_TREE;
5811 /* Diagnose an ambiguous else if if-then-else is nested inside
5814 warning_at (loc, OPT_Wdangling_else,
5815 "suggest explicit braces to avoid ambiguous %<else%>");
5817 if (warn_duplicated_cond)
5819 /* This if statement does not have an else clause. We don't
5820 need the condition chain anymore. */
5825 c_finish_if_stmt (loc, cond, first_body, second_body);
5826 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5828 c_parser_maybe_reclassify_token (parser);
5831 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5834 switch (expression) statement
5838 c_parser_switch_statement (c_parser *parser, bool *if_p)
5841 tree block, expr, body, save_break;
5842 location_t switch_loc = c_parser_peek_token (parser)->location;
5843 location_t switch_cond_loc;
5844 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
5845 c_parser_consume_token (parser);
5846 block = c_begin_compound_stmt (flag_isoc99);
5847 bool explicit_cast_p = false;
5848 matching_parens parens;
5849 if (parens.require_open (parser))
5851 switch_cond_loc = c_parser_peek_token (parser)->location;
5852 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5853 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5854 explicit_cast_p = true;
5855 ce = c_parser_expression (parser);
5856 ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
5858 /* ??? expr has no valid location? */
5859 parens.skip_until_found_close (parser);
5863 switch_cond_loc = UNKNOWN_LOCATION;
5864 expr = error_mark_node;
5865 ce.original_type = error_mark_node;
5867 c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
5868 save_break = c_break_label;
5869 c_break_label = NULL_TREE;
5870 location_t loc_after_labels;
5871 bool open_brace_p = c_parser_peek_token (parser)->type == CPP_OPEN_BRACE;
5872 body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
5873 location_t next_loc = c_parser_peek_token (parser)->location;
5874 if (!open_brace_p && c_parser_peek_token (parser)->type != CPP_SEMICOLON)
5875 warn_for_multistatement_macros (loc_after_labels, next_loc, switch_loc,
5879 location_t here = c_parser_peek_token (parser)->location;
5880 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
5881 SET_EXPR_LOCATION (t, here);
5882 SWITCH_BREAK_LABEL_P (c_break_label) = 1;
5883 append_to_statement_list_force (t, &body);
5885 c_finish_case (body, ce.original_type);
5886 c_break_label = save_break;
5887 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
5888 c_parser_maybe_reclassify_token (parser);
5891 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5894 while (expression) statement
5896 IF_P is used to track whether there's a (possibly labeled) if statement
5897 which is not enclosed in braces and has an else clause. This is used to
5898 implement -Wparentheses. */
5901 c_parser_while_statement (c_parser *parser, bool ivdep, unsigned short unroll,
5904 tree block, cond, body, save_break, save_cont;
5906 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
5907 token_indent_info while_tinfo
5908 = get_token_indent_info (c_parser_peek_token (parser));
5909 c_parser_consume_token (parser);
5910 block = c_begin_compound_stmt (flag_isoc99);
5911 loc = c_parser_peek_token (parser)->location;
5912 cond = c_parser_paren_condition (parser);
5913 if (ivdep && cond != error_mark_node)
5914 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5915 build_int_cst (integer_type_node,
5916 annot_expr_ivdep_kind),
5918 if (unroll && cond != error_mark_node)
5919 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5920 build_int_cst (integer_type_node,
5921 annot_expr_unroll_kind),
5922 build_int_cst (integer_type_node, unroll));
5923 save_break = c_break_label;
5924 c_break_label = NULL_TREE;
5925 save_cont = c_cont_label;
5926 c_cont_label = NULL_TREE;
5928 token_indent_info body_tinfo
5929 = get_token_indent_info (c_parser_peek_token (parser));
5931 location_t loc_after_labels;
5932 bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE);
5933 body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
5934 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
5935 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5936 c_parser_maybe_reclassify_token (parser);
5938 token_indent_info next_tinfo
5939 = get_token_indent_info (c_parser_peek_token (parser));
5940 warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo);
5942 if (next_tinfo.type != CPP_SEMICOLON && !open_brace)
5943 warn_for_multistatement_macros (loc_after_labels, next_tinfo.location,
5944 while_tinfo.location, RID_WHILE);
5946 c_break_label = save_break;
5947 c_cont_label = save_cont;
5950 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5953 do statement while ( expression ) ;
5957 c_parser_do_statement (c_parser *parser, bool ivdep, unsigned short unroll)
5959 tree block, cond, body, save_break, save_cont, new_break, new_cont;
5961 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
5962 c_parser_consume_token (parser);
5963 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5964 warning_at (c_parser_peek_token (parser)->location,
5966 "suggest braces around empty body in %<do%> statement");
5967 block = c_begin_compound_stmt (flag_isoc99);
5968 loc = c_parser_peek_token (parser)->location;
5969 save_break = c_break_label;
5970 c_break_label = NULL_TREE;
5971 save_cont = c_cont_label;
5972 c_cont_label = NULL_TREE;
5973 body = c_parser_c99_block_statement (parser, NULL);
5974 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
5975 new_break = c_break_label;
5976 c_break_label = save_break;
5977 new_cont = c_cont_label;
5978 c_cont_label = save_cont;
5979 cond = c_parser_paren_condition (parser);
5980 if (ivdep && cond != error_mark_node)
5981 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5982 build_int_cst (integer_type_node,
5983 annot_expr_ivdep_kind),
5985 if (unroll && cond != error_mark_node)
5986 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
5987 build_int_cst (integer_type_node,
5988 annot_expr_unroll_kind),
5989 build_int_cst (integer_type_node, unroll));
5990 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5991 c_parser_skip_to_end_of_block_or_statement (parser);
5992 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
5993 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
5996 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5999 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6000 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6002 The form with a declaration is new in C99.
6004 ??? In accordance with the old parser, the declaration may be a
6005 nested function, which is then rejected in check_for_loop_decls,
6006 but does it make any sense for this to be included in the grammar?
6007 Note in particular that the nested function does not include a
6008 trailing ';', whereas the "declaration" production includes one.
6009 Also, can we reject bad declarations earlier and cheaper than
6010 check_for_loop_decls?
6012 In Objective-C, there are two additional variants:
6015 for ( expression in expresssion ) statement
6016 for ( declaration in expression ) statement
6018 This is inconsistent with C, because the second variant is allowed
6019 even if c99 is not enabled.
6021 The rest of the comment documents these Objective-C foreach-statement.
6023 Here is the canonical example of the first variant:
6024 for (object in array) { do something with object }
6025 we call the first expression ("object") the "object_expression" and
6026 the second expression ("array") the "collection_expression".
6027 object_expression must be an lvalue of type "id" (a generic Objective-C
6028 object) because the loop works by assigning to object_expression the
6029 various objects from the collection_expression. collection_expression
6030 must evaluate to something of type "id" which responds to the method
6031 countByEnumeratingWithState:objects:count:.
6033 The canonical example of the second variant is:
6034 for (id object in array) { do something with object }
6035 which is completely equivalent to
6038 for (object in array) { do something with object }
6040 Note that initizializing 'object' in some way (eg, "for ((object =
6041 xxx) in array) { do something with object }") is possibly
6042 technically valid, but completely pointless as 'object' will be
6043 assigned to something else as soon as the loop starts. We should
6044 most likely reject it (TODO).
6046 The beginning of the Objective-C foreach-statement looks exactly
6047 like the beginning of the for-statement, and we can tell it is a
6048 foreach-statement only because the initial declaration or
6049 expression is terminated by 'in' instead of ';'.
6051 IF_P is used to track whether there's a (possibly labeled) if statement
6052 which is not enclosed in braces and has an else clause. This is used to
6053 implement -Wparentheses. */
6056 c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll,
6059 tree block, cond, incr, save_break, save_cont, body;
6060 /* The following are only used when parsing an ObjC foreach statement. */
6061 tree object_expression;
6062 /* Silence the bogus uninitialized warning. */
6063 tree collection_expression = NULL;
6064 location_t loc = c_parser_peek_token (parser)->location;
6065 location_t for_loc = c_parser_peek_token (parser)->location;
6066 bool is_foreach_statement = false;
6067 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
6068 token_indent_info for_tinfo
6069 = get_token_indent_info (c_parser_peek_token (parser));
6070 c_parser_consume_token (parser);
6071 /* Open a compound statement in Objective-C as well, just in case this is
6072 as foreach expression. */
6073 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
6074 cond = error_mark_node;
6075 incr = error_mark_node;
6076 matching_parens parens;
6077 if (parens.require_open (parser))
6079 /* Parse the initialization declaration or expression. */
6080 object_expression = error_mark_node;
6081 parser->objc_could_be_foreach_context = c_dialect_objc ();
6082 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6084 parser->objc_could_be_foreach_context = false;
6085 c_parser_consume_token (parser);
6086 c_finish_expr_stmt (loc, NULL_TREE);
6088 else if (c_parser_next_tokens_start_declaration (parser))
6090 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
6091 &object_expression, vNULL);
6092 parser->objc_could_be_foreach_context = false;
6094 if (c_parser_next_token_is_keyword (parser, RID_IN))
6096 c_parser_consume_token (parser);
6097 is_foreach_statement = true;
6098 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
6099 c_parser_error (parser, "multiple iterating variables in fast enumeration");
6102 check_for_loop_decls (for_loc, flag_isoc99);
6104 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
6106 /* __extension__ can start a declaration, but is also an
6107 unary operator that can start an expression. Consume all
6108 but the last of a possible series of __extension__ to
6110 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
6111 && (c_parser_peek_2nd_token (parser)->keyword
6113 c_parser_consume_token (parser);
6114 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
6117 ext = disable_extension_diagnostics ();
6118 c_parser_consume_token (parser);
6119 c_parser_declaration_or_fndef (parser, true, true, true, true,
6120 true, &object_expression, vNULL);
6121 parser->objc_could_be_foreach_context = false;
6123 restore_extension_diagnostics (ext);
6124 if (c_parser_next_token_is_keyword (parser, RID_IN))
6126 c_parser_consume_token (parser);
6127 is_foreach_statement = true;
6128 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
6129 c_parser_error (parser, "multiple iterating variables in fast enumeration");
6132 check_for_loop_decls (for_loc, flag_isoc99);
6142 tree init_expression;
6143 ce = c_parser_expression (parser);
6144 init_expression = ce.value;
6145 parser->objc_could_be_foreach_context = false;
6146 if (c_parser_next_token_is_keyword (parser, RID_IN))
6148 c_parser_consume_token (parser);
6149 is_foreach_statement = true;
6150 if (! lvalue_p (init_expression))
6151 c_parser_error (parser, "invalid iterating variable in fast enumeration");
6152 object_expression = c_fully_fold (init_expression, false, NULL);
6156 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
6157 init_expression = ce.value;
6158 c_finish_expr_stmt (loc, init_expression);
6159 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6163 /* Parse the loop condition. In the case of a foreach
6164 statement, there is no loop condition. */
6165 gcc_assert (!parser->objc_could_be_foreach_context);
6166 if (!is_foreach_statement)
6168 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6172 c_parser_error (parser, "missing loop condition in loop with "
6173 "%<GCC ivdep%> pragma");
6174 cond = error_mark_node;
6178 c_parser_error (parser, "missing loop condition in loop with "
6179 "%<GCC unroll%> pragma");
6180 cond = error_mark_node;
6184 c_parser_consume_token (parser);
6190 cond = c_parser_condition (parser);
6191 c_parser_skip_until_found (parser, CPP_SEMICOLON,
6194 if (ivdep && cond != error_mark_node)
6195 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
6196 build_int_cst (integer_type_node,
6197 annot_expr_ivdep_kind),
6199 if (unroll && cond != error_mark_node)
6200 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
6201 build_int_cst (integer_type_node,
6202 annot_expr_unroll_kind),
6203 build_int_cst (integer_type_node, unroll));
6205 /* Parse the increment expression (the third expression in a
6206 for-statement). In the case of a foreach-statement, this is
6207 the expression that follows the 'in'. */
6208 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6210 if (is_foreach_statement)
6212 c_parser_error (parser, "missing collection in fast enumeration");
6213 collection_expression = error_mark_node;
6216 incr = c_process_expr_stmt (loc, NULL_TREE);
6220 if (is_foreach_statement)
6221 collection_expression = c_fully_fold (c_parser_expression (parser).value,
6225 struct c_expr ce = c_parser_expression (parser);
6226 ce = convert_lvalue_to_rvalue (loc, ce, true, false);
6227 incr = c_process_expr_stmt (loc, ce.value);
6230 parens.skip_until_found_close (parser);
6232 save_break = c_break_label;
6233 c_break_label = NULL_TREE;
6234 save_cont = c_cont_label;
6235 c_cont_label = NULL_TREE;
6237 token_indent_info body_tinfo
6238 = get_token_indent_info (c_parser_peek_token (parser));
6240 location_t loc_after_labels;
6241 bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE);
6242 body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels);
6244 if (is_foreach_statement)
6245 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
6247 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
6248 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
6249 c_parser_maybe_reclassify_token (parser);
6251 token_indent_info next_tinfo
6252 = get_token_indent_info (c_parser_peek_token (parser));
6253 warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo);
6255 if (next_tinfo.type != CPP_SEMICOLON && !open_brace)
6256 warn_for_multistatement_macros (loc_after_labels, next_tinfo.location,
6257 for_tinfo.location, RID_FOR);
6259 c_break_label = save_break;
6260 c_cont_label = save_cont;
6263 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6264 statement with inputs, outputs, clobbers, and volatile tag
6268 asm type-qualifier[opt] ( asm-argument ) ;
6269 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6273 asm-string-literal : asm-operands[opt]
6274 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6275 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6278 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6281 Qualifiers other than volatile are accepted in the syntax but
6285 c_parser_asm_statement (c_parser *parser)
6287 tree quals, str, outputs, inputs, clobbers, labels, ret;
6288 bool simple, is_goto;
6289 location_t asm_loc = c_parser_peek_token (parser)->location;
6290 int section, nsections;
6292 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
6293 c_parser_consume_token (parser);
6294 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
6296 quals = c_parser_peek_token (parser)->value;
6297 c_parser_consume_token (parser);
6299 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
6300 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
6302 warning_at (c_parser_peek_token (parser)->location,
6304 "%E qualifier ignored on asm",
6305 c_parser_peek_token (parser)->value);
6307 c_parser_consume_token (parser);
6313 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
6315 c_parser_consume_token (parser);
6319 /* ??? Follow the C++ parser rather than using the
6320 lex_untranslated_string kludge. */
6321 parser->lex_untranslated_string = true;
6324 matching_parens parens;
6325 if (!parens.require_open (parser))
6328 str = c_parser_asm_string_literal (parser);
6329 if (str == NULL_TREE)
6330 goto error_close_paren;
6333 outputs = NULL_TREE;
6335 clobbers = NULL_TREE;
6338 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
6341 /* Parse each colon-delimited section of operands. */
6342 nsections = 3 + is_goto;
6343 for (section = 0; section < nsections; ++section)
6345 if (!c_parser_require (parser, CPP_COLON,
6347 ? G_("expected %<:%>")
6348 : G_("expected %<:%> or %<)%>"),
6349 UNKNOWN_LOCATION, is_goto))
6350 goto error_close_paren;
6352 /* Once past any colon, we're no longer a simple asm. */
6355 if ((!c_parser_next_token_is (parser, CPP_COLON)
6356 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6361 /* For asm goto, we don't allow output operands, but reserve
6362 the slot for a future extension that does allow them. */
6364 outputs = c_parser_asm_operands (parser);
6367 inputs = c_parser_asm_operands (parser);
6370 clobbers = c_parser_asm_clobbers (parser);
6373 labels = c_parser_asm_goto_operands (parser);
6379 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
6384 if (!parens.require_close (parser))
6386 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6390 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
6391 c_parser_skip_to_end_of_block_or_statement (parser);
6393 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
6394 clobbers, labels, simple));
6397 parser->lex_untranslated_string = false;
6401 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6405 /* Parse asm operands, a GNU extension.
6409 asm-operands , asm-operand
6412 asm-string-literal ( expression )
6413 [ identifier ] asm-string-literal ( expression )
6417 c_parser_asm_operands (c_parser *parser)
6419 tree list = NULL_TREE;
6424 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
6426 c_parser_consume_token (parser);
6427 if (c_parser_next_token_is (parser, CPP_NAME))
6429 tree id = c_parser_peek_token (parser)->value;
6430 c_parser_consume_token (parser);
6431 name = build_string (IDENTIFIER_LENGTH (id),
6432 IDENTIFIER_POINTER (id));
6436 c_parser_error (parser, "expected identifier");
6437 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
6440 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6445 str = c_parser_asm_string_literal (parser);
6446 if (str == NULL_TREE)
6448 parser->lex_untranslated_string = false;
6449 matching_parens parens;
6450 if (!parens.require_open (parser))
6452 parser->lex_untranslated_string = true;
6455 expr = c_parser_expression (parser);
6456 mark_exp_read (expr.value);
6457 parser->lex_untranslated_string = true;
6458 if (!parens.require_close (parser))
6460 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6463 list = chainon (list, build_tree_list (build_tree_list (name, str),
6465 if (c_parser_next_token_is (parser, CPP_COMMA))
6466 c_parser_consume_token (parser);
6473 /* Parse asm clobbers, a GNU extension.
6477 asm-clobbers , asm-string-literal
6481 c_parser_asm_clobbers (c_parser *parser)
6483 tree list = NULL_TREE;
6486 tree str = c_parser_asm_string_literal (parser);
6488 list = tree_cons (NULL_TREE, str, list);
6491 if (c_parser_next_token_is (parser, CPP_COMMA))
6492 c_parser_consume_token (parser);
6499 /* Parse asm goto labels, a GNU extension.
6503 asm-goto-operands , identifier
6507 c_parser_asm_goto_operands (c_parser *parser)
6509 tree list = NULL_TREE;
6514 if (c_parser_next_token_is (parser, CPP_NAME))
6516 c_token *tok = c_parser_peek_token (parser);
6518 label = lookup_label_for_goto (tok->location, name);
6519 c_parser_consume_token (parser);
6520 TREE_USED (label) = 1;
6524 c_parser_error (parser, "expected identifier");
6528 name = build_string (IDENTIFIER_LENGTH (name),
6529 IDENTIFIER_POINTER (name));
6530 list = tree_cons (name, label, list);
6531 if (c_parser_next_token_is (parser, CPP_COMMA))
6532 c_parser_consume_token (parser);
6534 return nreverse (list);
6538 /* Parse an expression other than a compound expression; that is, an
6539 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6540 AFTER is not NULL then it is an Objective-C message expression which
6541 is the primary-expression starting the expression as an initializer.
6543 assignment-expression:
6544 conditional-expression
6545 unary-expression assignment-operator assignment-expression
6547 assignment-operator: one of
6548 = *= /= %= += -= <<= >>= &= ^= |=
6550 In GNU C we accept any conditional expression on the LHS and
6551 diagnose the invalid lvalue rather than producing a syntax
6554 static struct c_expr
6555 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after,
6556 tree omp_atomic_lhs)
6558 struct c_expr lhs, rhs, ret;
6559 enum tree_code code;
6560 location_t op_location, exp_location;
6561 gcc_assert (!after || c_dialect_objc ());
6562 lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs);
6563 op_location = c_parser_peek_token (parser)->location;
6564 switch (c_parser_peek_token (parser)->type)
6573 code = TRUNC_DIV_EXPR;
6576 code = TRUNC_MOD_EXPR;
6591 code = BIT_AND_EXPR;
6594 code = BIT_XOR_EXPR;
6597 code = BIT_IOR_EXPR;
6602 c_parser_consume_token (parser);
6603 exp_location = c_parser_peek_token (parser)->location;
6604 rhs = c_parser_expr_no_commas (parser, NULL);
6605 rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true);
6607 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
6608 code, exp_location, rhs.value,
6610 set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ());
6611 if (code == NOP_EXPR)
6612 ret.original_code = MODIFY_EXPR;
6615 TREE_NO_WARNING (ret.value) = 1;
6616 ret.original_code = ERROR_MARK;
6618 ret.original_type = NULL;
6622 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6623 AFTER is not NULL then it is an Objective-C message expression which is
6624 the primary-expression starting the expression as an initializer.
6626 conditional-expression:
6627 logical-OR-expression
6628 logical-OR-expression ? expression : conditional-expression
6632 conditional-expression:
6633 logical-OR-expression ? : conditional-expression
6636 static struct c_expr
6637 c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
6638 tree omp_atomic_lhs)
6640 struct c_expr cond, exp1, exp2, ret;
6641 location_t start, cond_loc, colon_loc;
6643 gcc_assert (!after || c_dialect_objc ());
6645 cond = c_parser_binary_expression (parser, after, omp_atomic_lhs);
6647 if (c_parser_next_token_is_not (parser, CPP_QUERY))
6649 if (cond.value != error_mark_node)
6650 start = cond.get_start ();
6652 start = UNKNOWN_LOCATION;
6653 cond_loc = c_parser_peek_token (parser)->location;
6654 cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true);
6655 c_parser_consume_token (parser);
6656 if (c_parser_next_token_is (parser, CPP_COLON))
6658 tree eptype = NULL_TREE;
6660 location_t middle_loc = c_parser_peek_token (parser)->location;
6661 pedwarn (middle_loc, OPT_Wpedantic,
6662 "ISO C forbids omitting the middle term of a ?: expression");
6663 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
6665 eptype = TREE_TYPE (cond.value);
6666 cond.value = TREE_OPERAND (cond.value, 0);
6668 tree e = cond.value;
6669 while (TREE_CODE (e) == COMPOUND_EXPR)
6670 e = TREE_OPERAND (e, 1);
6671 warn_for_omitted_condop (middle_loc, e);
6672 /* Make sure first operand is calculated only once. */
6673 exp1.value = save_expr (default_conversion (cond.value));
6675 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
6676 exp1.original_type = NULL;
6677 exp1.src_range = cond.src_range;
6678 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
6679 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
6684 = c_objc_common_truthvalue_conversion
6685 (cond_loc, default_conversion (cond.value));
6686 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
6687 exp1 = c_parser_expression_conv (parser);
6688 mark_exp_read (exp1.value);
6689 c_inhibit_evaluation_warnings +=
6690 ((cond.value == truthvalue_true_node)
6691 - (cond.value == truthvalue_false_node));
6694 colon_loc = c_parser_peek_token (parser)->location;
6695 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6697 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6699 ret.original_code = ERROR_MARK;
6700 ret.original_type = NULL;
6704 location_t exp2_loc = c_parser_peek_token (parser)->location;
6705 exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE);
6706 exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
6708 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
6709 location_t loc1 = make_location (exp1.get_start (), exp1.src_range);
6710 location_t loc2 = make_location (exp2.get_start (), exp2.src_range);
6711 ret.value = build_conditional_expr (colon_loc, cond.value,
6712 cond.original_code == C_MAYBE_CONST_EXPR,
6713 exp1.value, exp1.original_type, loc1,
6714 exp2.value, exp2.original_type, loc2);
6715 ret.original_code = ERROR_MARK;
6716 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
6717 ret.original_type = NULL;
6722 /* If both sides are enum type, the default conversion will have
6723 made the type of the result be an integer type. We want to
6724 remember the enum types we started with. */
6725 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
6726 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
6727 ret.original_type = ((t1 != error_mark_node
6728 && t2 != error_mark_node
6729 && (TYPE_MAIN_VARIANT (t1)
6730 == TYPE_MAIN_VARIANT (t2)))
6734 set_c_expr_source_range (&ret, start, exp2.get_finish ());
6738 /* Parse a binary expression; that is, a logical-OR-expression (C90
6739 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6740 NULL then it is an Objective-C message expression which is the
6741 primary-expression starting the expression as an initializer.
6743 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6744 when it should be the unfolded lhs. In a valid OpenMP source,
6745 one of the operands of the toplevel binary expression must be equal
6746 to it. In that case, just return a build2 created binary operation
6747 rather than result of parser_build_binary_op.
6749 multiplicative-expression:
6751 multiplicative-expression * cast-expression
6752 multiplicative-expression / cast-expression
6753 multiplicative-expression % cast-expression
6755 additive-expression:
6756 multiplicative-expression
6757 additive-expression + multiplicative-expression
6758 additive-expression - multiplicative-expression
6762 shift-expression << additive-expression
6763 shift-expression >> additive-expression
6765 relational-expression:
6767 relational-expression < shift-expression
6768 relational-expression > shift-expression
6769 relational-expression <= shift-expression
6770 relational-expression >= shift-expression
6772 equality-expression:
6773 relational-expression
6774 equality-expression == relational-expression
6775 equality-expression != relational-expression
6779 AND-expression & equality-expression
6781 exclusive-OR-expression:
6783 exclusive-OR-expression ^ AND-expression
6785 inclusive-OR-expression:
6786 exclusive-OR-expression
6787 inclusive-OR-expression | exclusive-OR-expression
6789 logical-AND-expression:
6790 inclusive-OR-expression
6791 logical-AND-expression && inclusive-OR-expression
6793 logical-OR-expression:
6794 logical-AND-expression
6795 logical-OR-expression || logical-AND-expression
6798 static struct c_expr
6799 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
6800 tree omp_atomic_lhs)
6802 /* A binary expression is parsed using operator-precedence parsing,
6803 with the operands being cast expressions. All the binary
6804 operators are left-associative. Thus a binary expression is of
6807 E0 op1 E1 op2 E2 ...
6809 which we represent on a stack. On the stack, the precedence
6810 levels are strictly increasing. When a new operator is
6811 encountered of higher precedence than that at the top of the
6812 stack, it is pushed; its LHS is the top expression, and its RHS
6813 is everything parsed until it is popped. When a new operator is
6814 encountered with precedence less than or equal to that at the top
6815 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6816 by the result of the operation until the operator at the top of
6817 the stack has lower precedence than the new operator or there is
6818 only one element on the stack; then the top expression is the LHS
6819 of the new operator. In the case of logical AND and OR
6820 expressions, we also need to adjust c_inhibit_evaluation_warnings
6821 as appropriate when the operators are pushed and popped. */
6824 /* The expression at this stack level. */
6826 /* The precedence of the operator on its left, PREC_NONE at the
6827 bottom of the stack. */
6828 enum c_parser_prec prec;
6829 /* The operation on its left. */
6831 /* The source location of this operation. */
6833 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6837 /* Location of the binary operator. */
6838 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
6841 switch (stack[sp].op) \
6843 case TRUTH_ANDIF_EXPR: \
6844 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6845 == truthvalue_false_node); \
6847 case TRUTH_ORIF_EXPR: \
6848 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6849 == truthvalue_true_node); \
6851 case TRUNC_DIV_EXPR: \
6852 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6853 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6855 tree type0 = stack[sp - 1].sizeof_arg; \
6856 tree type1 = stack[sp].sizeof_arg; \
6857 tree first_arg = type0; \
6858 if (!TYPE_P (type0)) \
6859 type0 = TREE_TYPE (type0); \
6860 if (!TYPE_P (type1)) \
6861 type1 = TREE_TYPE (type1); \
6862 if (POINTER_TYPE_P (type0) \
6863 && comptypes (TREE_TYPE (type0), type1) \
6864 && !(TREE_CODE (first_arg) == PARM_DECL \
6865 && C_ARRAY_PARAMETER (first_arg) \
6866 && warn_sizeof_array_argument)) \
6867 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6868 "division %<sizeof (%T) / sizeof (%T)%> does " \
6869 "not compute the number of array elements", \
6871 if (DECL_P (first_arg)) \
6872 inform (DECL_SOURCE_LOCATION (first_arg), \
6873 "first %<sizeof%> operand was declared here"); \
6879 stack[sp - 1].expr \
6880 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6881 stack[sp - 1].expr, true, true); \
6883 = convert_lvalue_to_rvalue (stack[sp].loc, \
6884 stack[sp].expr, true, true); \
6885 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6886 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6887 && ((1 << stack[sp].prec) \
6888 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6889 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6890 && stack[sp].op != TRUNC_MOD_EXPR \
6891 && stack[0].expr.value != error_mark_node \
6892 && stack[1].expr.value != error_mark_node \
6893 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6894 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6895 stack[0].expr.value \
6896 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6897 stack[0].expr.value, stack[1].expr.value); \
6899 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6901 stack[sp - 1].expr, \
6905 gcc_assert (!after || c_dialect_objc ());
6906 stack[0].loc = c_parser_peek_token (parser)->location;
6907 stack[0].expr = c_parser_cast_expression (parser, after);
6908 stack[0].prec = PREC_NONE;
6909 stack[0].sizeof_arg = c_last_sizeof_arg;
6913 enum c_parser_prec oprec;
6914 enum tree_code ocode;
6915 source_range src_range;
6918 switch (c_parser_peek_token (parser)->type)
6926 ocode = TRUNC_DIV_EXPR;
6930 ocode = TRUNC_MOD_EXPR;
6942 ocode = LSHIFT_EXPR;
6946 ocode = RSHIFT_EXPR;
6960 case CPP_GREATER_EQ:
6973 oprec = PREC_BITAND;
6974 ocode = BIT_AND_EXPR;
6977 oprec = PREC_BITXOR;
6978 ocode = BIT_XOR_EXPR;
6982 ocode = BIT_IOR_EXPR;
6985 oprec = PREC_LOGAND;
6986 ocode = TRUTH_ANDIF_EXPR;
6990 ocode = TRUTH_ORIF_EXPR;
6993 /* Not a binary operator, so end of the binary
6997 binary_loc = c_parser_peek_token (parser)->location;
6998 while (oprec <= stack[sp].prec)
7000 c_parser_consume_token (parser);
7003 case TRUTH_ANDIF_EXPR:
7004 src_range = stack[sp].expr.src_range;
7006 = convert_lvalue_to_rvalue (stack[sp].loc,
7007 stack[sp].expr, true, true);
7008 stack[sp].expr.value = c_objc_common_truthvalue_conversion
7009 (stack[sp].loc, default_conversion (stack[sp].expr.value));
7010 c_inhibit_evaluation_warnings += (stack[sp].expr.value
7011 == truthvalue_false_node);
7012 set_c_expr_source_range (&stack[sp].expr, src_range);
7014 case TRUTH_ORIF_EXPR:
7015 src_range = stack[sp].expr.src_range;
7017 = convert_lvalue_to_rvalue (stack[sp].loc,
7018 stack[sp].expr, true, true);
7019 stack[sp].expr.value = c_objc_common_truthvalue_conversion
7020 (stack[sp].loc, default_conversion (stack[sp].expr.value));
7021 c_inhibit_evaluation_warnings += (stack[sp].expr.value
7022 == truthvalue_true_node);
7023 set_c_expr_source_range (&stack[sp].expr, src_range);
7029 stack[sp].loc = binary_loc;
7030 stack[sp].expr = c_parser_cast_expression (parser, NULL);
7031 stack[sp].prec = oprec;
7032 stack[sp].op = ocode;
7033 stack[sp].sizeof_arg = c_last_sizeof_arg;
7038 return stack[0].expr;
7042 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7043 is not NULL then it is an Objective-C message expression which is the
7044 primary-expression starting the expression as an initializer.
7048 ( type-name ) unary-expression
7051 static struct c_expr
7052 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
7054 location_t cast_loc = c_parser_peek_token (parser)->location;
7055 gcc_assert (!after || c_dialect_objc ());
7057 return c_parser_postfix_expression_after_primary (parser,
7059 /* If the expression begins with a parenthesized type name, it may
7060 be either a cast or a compound literal; we need to see whether
7061 the next character is '{' to tell the difference. If not, it is
7062 an unary expression. Full detection of unknown typenames here
7063 would require a 3-token lookahead. */
7064 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7065 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7067 struct c_type_name *type_name;
7070 matching_parens parens;
7071 parens.consume_open (parser);
7072 type_name = c_parser_type_name (parser, true);
7073 parens.skip_until_found_close (parser);
7074 if (type_name == NULL)
7077 ret.original_code = ERROR_MARK;
7078 ret.original_type = NULL;
7082 /* Save casted types in the function's used types hash table. */
7083 used_types_insert (type_name->specs->type);
7085 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7086 return c_parser_postfix_expression_after_paren_type (parser, type_name,
7088 if (type_name->specs->alignas_p)
7089 error_at (type_name->specs->locations[cdw_alignas],
7090 "alignment specified for type name in cast");
7092 location_t expr_loc = c_parser_peek_token (parser)->location;
7093 expr = c_parser_cast_expression (parser, NULL);
7094 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true);
7096 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
7097 if (ret.value && expr.value)
7098 set_c_expr_source_range (&ret, cast_loc, expr.get_finish ());
7099 ret.original_code = ERROR_MARK;
7100 ret.original_type = NULL;
7104 return c_parser_unary_expression (parser);
7107 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7113 unary-operator cast-expression
7114 sizeof unary-expression
7115 sizeof ( type-name )
7117 unary-operator: one of
7123 __alignof__ unary-expression
7124 __alignof__ ( type-name )
7127 (C11 permits _Alignof with type names only.)
7129 unary-operator: one of
7130 __extension__ __real__ __imag__
7132 Transactional Memory:
7135 transaction-expression
7137 In addition, the GNU syntax treats ++ and -- as unary operators, so
7138 they may be applied to cast expressions with errors for non-lvalues
7141 static struct c_expr
7142 c_parser_unary_expression (c_parser *parser)
7145 struct c_expr ret, op;
7146 location_t op_loc = c_parser_peek_token (parser)->location;
7149 ret.original_code = ERROR_MARK;
7150 ret.original_type = NULL;
7151 switch (c_parser_peek_token (parser)->type)
7154 c_parser_consume_token (parser);
7155 exp_loc = c_parser_peek_token (parser)->location;
7156 op = c_parser_cast_expression (parser, NULL);
7158 op = default_function_array_read_conversion (exp_loc, op);
7159 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
7160 case CPP_MINUS_MINUS:
7161 c_parser_consume_token (parser);
7162 exp_loc = c_parser_peek_token (parser)->location;
7163 op = c_parser_cast_expression (parser, NULL);
7165 op = default_function_array_read_conversion (exp_loc, op);
7166 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
7168 c_parser_consume_token (parser);
7169 op = c_parser_cast_expression (parser, NULL);
7170 mark_exp_read (op.value);
7171 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
7174 c_parser_consume_token (parser);
7175 exp_loc = c_parser_peek_token (parser)->location;
7176 op = c_parser_cast_expression (parser, NULL);
7177 finish = op.get_finish ();
7178 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7179 location_t combined_loc = make_location (op_loc, op_loc, finish);
7180 ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR);
7181 ret.src_range.m_start = op_loc;
7182 ret.src_range.m_finish = finish;
7186 if (!c_dialect_objc () && !in_system_header_at (input_location))
7189 "traditional C rejects the unary plus operator");
7190 c_parser_consume_token (parser);
7191 exp_loc = c_parser_peek_token (parser)->location;
7192 op = c_parser_cast_expression (parser, NULL);
7193 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7194 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
7196 c_parser_consume_token (parser);
7197 exp_loc = c_parser_peek_token (parser)->location;
7198 op = c_parser_cast_expression (parser, NULL);
7199 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7200 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
7202 c_parser_consume_token (parser);
7203 exp_loc = c_parser_peek_token (parser)->location;
7204 op = c_parser_cast_expression (parser, NULL);
7205 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7206 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
7208 c_parser_consume_token (parser);
7209 exp_loc = c_parser_peek_token (parser)->location;
7210 op = c_parser_cast_expression (parser, NULL);
7211 op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
7212 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
7214 /* Refer to the address of a label as a pointer. */
7215 c_parser_consume_token (parser);
7216 if (c_parser_next_token_is (parser, CPP_NAME))
7218 ret.value = finish_label_address_expr
7219 (c_parser_peek_token (parser)->value, op_loc);
7220 set_c_expr_source_range (&ret, op_loc,
7221 c_parser_peek_token (parser)->get_finish ());
7222 c_parser_consume_token (parser);
7226 c_parser_error (parser, "expected identifier");
7231 switch (c_parser_peek_token (parser)->keyword)
7234 return c_parser_sizeof_expression (parser);
7236 return c_parser_alignof_expression (parser);
7238 c_parser_consume_token (parser);
7239 ext = disable_extension_diagnostics ();
7240 ret = c_parser_cast_expression (parser, NULL);
7241 restore_extension_diagnostics (ext);
7244 c_parser_consume_token (parser);
7245 exp_loc = c_parser_peek_token (parser)->location;
7246 op = c_parser_cast_expression (parser, NULL);
7247 op = default_function_array_conversion (exp_loc, op);
7248 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
7250 c_parser_consume_token (parser);
7251 exp_loc = c_parser_peek_token (parser)->location;
7252 op = c_parser_cast_expression (parser, NULL);
7253 op = default_function_array_conversion (exp_loc, op);
7254 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
7255 case RID_TRANSACTION_ATOMIC:
7256 case RID_TRANSACTION_RELAXED:
7257 return c_parser_transaction_expression (parser,
7258 c_parser_peek_token (parser)->keyword);
7260 return c_parser_postfix_expression (parser);
7263 return c_parser_postfix_expression (parser);
7267 /* Parse a sizeof expression. */
7269 static struct c_expr
7270 c_parser_sizeof_expression (c_parser *parser)
7273 struct c_expr result;
7274 location_t expr_loc;
7275 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
7278 location_t finish = UNKNOWN_LOCATION;
7280 start = c_parser_peek_token (parser)->location;
7282 c_parser_consume_token (parser);
7283 c_inhibit_evaluation_warnings++;
7285 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7286 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7288 /* Either sizeof ( type-name ) or sizeof unary-expression
7289 starting with a compound literal. */
7290 struct c_type_name *type_name;
7291 matching_parens parens;
7292 parens.consume_open (parser);
7293 expr_loc = c_parser_peek_token (parser)->location;
7294 type_name = c_parser_type_name (parser, true);
7295 parens.skip_until_found_close (parser);
7296 finish = parser->tokens_buf[0].location;
7297 if (type_name == NULL)
7300 c_inhibit_evaluation_warnings--;
7303 ret.original_code = ERROR_MARK;
7304 ret.original_type = NULL;
7307 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7309 expr = c_parser_postfix_expression_after_paren_type (parser,
7312 finish = expr.get_finish ();
7315 /* sizeof ( type-name ). */
7316 if (type_name->specs->alignas_p)
7317 error_at (type_name->specs->locations[cdw_alignas],
7318 "alignment specified for type name in %<sizeof%>");
7319 c_inhibit_evaluation_warnings--;
7321 result = c_expr_sizeof_type (expr_loc, type_name);
7325 expr_loc = c_parser_peek_token (parser)->location;
7326 expr = c_parser_unary_expression (parser);
7327 finish = expr.get_finish ();
7329 c_inhibit_evaluation_warnings--;
7331 mark_exp_read (expr.value);
7332 if (TREE_CODE (expr.value) == COMPONENT_REF
7333 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
7334 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
7335 result = c_expr_sizeof_expr (expr_loc, expr);
7337 if (finish != UNKNOWN_LOCATION)
7338 set_c_expr_source_range (&result, start, finish);
7342 /* Parse an alignof expression. */
7344 static struct c_expr
7345 c_parser_alignof_expression (c_parser *parser)
7348 location_t start_loc = c_parser_peek_token (parser)->location;
7350 tree alignof_spelling = c_parser_peek_token (parser)->value;
7351 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
7352 bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
7354 /* A diagnostic is not required for the use of this identifier in
7355 the implementation namespace; only diagnose it for the C11
7356 spelling because of existing code using the other spellings. */
7360 pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE",
7363 pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE",
7366 c_parser_consume_token (parser);
7367 c_inhibit_evaluation_warnings++;
7369 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
7370 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
7372 /* Either __alignof__ ( type-name ) or __alignof__
7373 unary-expression starting with a compound literal. */
7375 struct c_type_name *type_name;
7377 matching_parens parens;
7378 parens.consume_open (parser);
7379 loc = c_parser_peek_token (parser)->location;
7380 type_name = c_parser_type_name (parser, true);
7381 end_loc = c_parser_peek_token (parser)->location;
7382 parens.skip_until_found_close (parser);
7383 if (type_name == NULL)
7386 c_inhibit_evaluation_warnings--;
7389 ret.original_code = ERROR_MARK;
7390 ret.original_type = NULL;
7393 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7395 expr = c_parser_postfix_expression_after_paren_type (parser,
7400 /* alignof ( type-name ). */
7401 if (type_name->specs->alignas_p)
7402 error_at (type_name->specs->locations[cdw_alignas],
7403 "alignment specified for type name in %qE",
7405 c_inhibit_evaluation_warnings--;
7407 ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name,
7409 false, is_c11_alignof, 1);
7410 ret.original_code = ERROR_MARK;
7411 ret.original_type = NULL;
7412 set_c_expr_source_range (&ret, start_loc, end_loc);
7418 expr = c_parser_unary_expression (parser);
7419 end_loc = expr.src_range.m_finish;
7421 mark_exp_read (expr.value);
7422 c_inhibit_evaluation_warnings--;
7426 OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
7428 ret.value = c_alignof_expr (start_loc, expr.value);
7429 ret.original_code = ERROR_MARK;
7430 ret.original_type = NULL;
7431 set_c_expr_source_range (&ret, start_loc, end_loc);
7436 /* Helper function to read arguments of builtins which are interfaces
7437 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7438 others. The name of the builtin is passed using BNAME parameter.
7439 Function returns true if there were no errors while parsing and
7440 stores the arguments in CEXPR_LIST. If it returns true,
7441 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7444 c_parser_get_builtin_args (c_parser *parser, const char *bname,
7445 vec<c_expr_t, va_gc> **ret_cexpr_list,
7447 location_t *out_close_paren_loc)
7449 location_t loc = c_parser_peek_token (parser)->location;
7450 vec<c_expr_t, va_gc> *cexpr_list;
7452 bool saved_force_folding_builtin_constant_p;
7454 *ret_cexpr_list = NULL;
7455 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
7457 error_at (loc, "cannot take address of %qs", bname);
7461 c_parser_consume_token (parser);
7463 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7465 *out_close_paren_loc = c_parser_peek_token (parser)->location;
7466 c_parser_consume_token (parser);
7470 saved_force_folding_builtin_constant_p
7471 = force_folding_builtin_constant_p;
7472 force_folding_builtin_constant_p |= choose_expr_p;
7473 expr = c_parser_expr_no_commas (parser, NULL);
7474 force_folding_builtin_constant_p
7475 = saved_force_folding_builtin_constant_p;
7476 vec_alloc (cexpr_list, 1);
7477 vec_safe_push (cexpr_list, expr);
7478 while (c_parser_next_token_is (parser, CPP_COMMA))
7480 c_parser_consume_token (parser);
7481 expr = c_parser_expr_no_commas (parser, NULL);
7482 vec_safe_push (cexpr_list, expr);
7485 *out_close_paren_loc = c_parser_peek_token (parser)->location;
7486 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
7489 *ret_cexpr_list = cexpr_list;
7493 /* This represents a single generic-association. */
7495 struct c_generic_association
7497 /* The location of the starting token of the type. */
7498 location_t type_location;
7499 /* The association's type, or NULL_TREE for 'default'. */
7501 /* The association's expression. */
7502 struct c_expr expression;
7505 /* Parse a generic-selection. (C11 6.5.1.1).
7508 _Generic ( assignment-expression , generic-assoc-list )
7512 generic-assoc-list , generic-association
7514 generic-association:
7515 type-name : assignment-expression
7516 default : assignment-expression
7519 static struct c_expr
7520 c_parser_generic_selection (c_parser *parser)
7522 struct c_expr selector, error_expr;
7524 struct c_generic_association matched_assoc;
7525 bool match_found = false;
7526 location_t generic_loc, selector_loc;
7528 error_expr.original_code = ERROR_MARK;
7529 error_expr.original_type = NULL;
7530 error_expr.set_error ();
7531 matched_assoc.type_location = UNKNOWN_LOCATION;
7532 matched_assoc.type = NULL_TREE;
7533 matched_assoc.expression = error_expr;
7535 gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC));
7536 generic_loc = c_parser_peek_token (parser)->location;
7537 c_parser_consume_token (parser);
7539 pedwarn_c99 (generic_loc, OPT_Wpedantic,
7540 "ISO C99 does not support %<_Generic%>");
7542 pedwarn_c99 (generic_loc, OPT_Wpedantic,
7543 "ISO C90 does not support %<_Generic%>");
7545 matching_parens parens;
7546 if (!parens.require_open (parser))
7549 c_inhibit_evaluation_warnings++;
7550 selector_loc = c_parser_peek_token (parser)->location;
7551 selector = c_parser_expr_no_commas (parser, NULL);
7552 selector = default_function_array_conversion (selector_loc, selector);
7553 c_inhibit_evaluation_warnings--;
7555 if (selector.value == error_mark_node)
7557 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7560 selector_type = TREE_TYPE (selector.value);
7561 /* In ISO C terms, rvalues (including the controlling expression of
7562 _Generic) do not have qualified types. */
7563 if (TREE_CODE (selector_type) != ARRAY_TYPE)
7564 selector_type = TYPE_MAIN_VARIANT (selector_type);
7565 /* In ISO C terms, _Noreturn is not part of the type of expressions
7566 such as &abort, but in GCC it is represented internally as a type
7568 if (FUNCTION_POINTER_TYPE_P (selector_type)
7569 && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
7571 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
7573 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
7575 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7579 auto_vec<c_generic_association> associations;
7582 struct c_generic_association assoc, *iter;
7584 c_token *token = c_parser_peek_token (parser);
7586 assoc.type_location = token->location;
7587 if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT)
7589 c_parser_consume_token (parser);
7590 assoc.type = NULL_TREE;
7594 struct c_type_name *type_name;
7596 type_name = c_parser_type_name (parser);
7597 if (type_name == NULL)
7599 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7602 assoc.type = groktypename (type_name, NULL, NULL);
7603 if (assoc.type == error_mark_node)
7605 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7609 if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
7610 error_at (assoc.type_location,
7611 "%<_Generic%> association has function type");
7612 else if (!COMPLETE_TYPE_P (assoc.type))
7613 error_at (assoc.type_location,
7614 "%<_Generic%> association has incomplete type");
7616 if (variably_modified_type_p (assoc.type, NULL_TREE))
7617 error_at (assoc.type_location,
7618 "%<_Generic%> association has "
7619 "variable length type");
7622 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7624 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7628 assoc.expression = c_parser_expr_no_commas (parser, NULL);
7629 if (assoc.expression.value == error_mark_node)
7631 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7635 for (ix = 0; associations.iterate (ix, &iter); ++ix)
7637 if (assoc.type == NULL_TREE)
7639 if (iter->type == NULL_TREE)
7641 error_at (assoc.type_location,
7642 "duplicate %<default%> case in %<_Generic%>");
7643 inform (iter->type_location, "original %<default%> is here");
7646 else if (iter->type != NULL_TREE)
7648 if (comptypes (assoc.type, iter->type))
7650 error_at (assoc.type_location,
7651 "%<_Generic%> specifies two compatible types");
7652 inform (iter->type_location, "compatible type is here");
7657 if (assoc.type == NULL_TREE)
7661 matched_assoc = assoc;
7665 else if (comptypes (assoc.type, selector_type))
7667 if (!match_found || matched_assoc.type == NULL_TREE)
7669 matched_assoc = assoc;
7674 error_at (assoc.type_location,
7675 "%<_Generic%> selector matches multiple associations");
7676 inform (matched_assoc.type_location,
7677 "other match is here");
7681 associations.safe_push (assoc);
7683 if (c_parser_peek_token (parser)->type != CPP_COMMA)
7685 c_parser_consume_token (parser);
7688 if (!parens.require_close (parser))
7690 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7696 error_at (selector_loc, "%<_Generic%> selector of type %qT is not "
7697 "compatible with any association",
7702 return matched_assoc.expression;
7705 /* Check the validity of a function pointer argument *EXPR (argument
7706 position POS) to __builtin_tgmath. Return the number of function
7707 arguments if possibly valid; return 0 having reported an error if
7711 check_tgmath_function (c_expr *expr, unsigned int pos)
7713 tree type = TREE_TYPE (expr->value);
7714 if (!FUNCTION_POINTER_TYPE_P (type))
7716 error_at (expr->get_location (),
7717 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7721 type = TREE_TYPE (type);
7722 if (!prototype_p (type))
7724 error_at (expr->get_location (),
7725 "argument %u of %<__builtin_tgmath%> is unprototyped", pos);
7728 if (stdarg_p (type))
7730 error_at (expr->get_location (),
7731 "argument %u of %<__builtin_tgmath%> has variable arguments",
7735 unsigned int nargs = 0;
7736 function_args_iterator iter;
7738 FOREACH_FUNCTION_ARGS (type, t, iter)
7740 if (t == void_type_node)
7746 error_at (expr->get_location (),
7747 "argument %u of %<__builtin_tgmath%> has no arguments", pos);
7753 /* Ways in which a parameter or return value of a type-generic macro
7754 may vary between the different functions the macro may call. */
7755 enum tgmath_parm_kind
7757 tgmath_fixed, tgmath_real, tgmath_complex
7760 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7761 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7762 call c_parser_postfix_expression_after_paren_type on encountering them.
7766 postfix-expression [ expression ]
7767 postfix-expression ( argument-expression-list[opt] )
7768 postfix-expression . identifier
7769 postfix-expression -> identifier
7770 postfix-expression ++
7771 postfix-expression --
7772 ( type-name ) { initializer-list }
7773 ( type-name ) { initializer-list , }
7775 argument-expression-list:
7777 argument-expression-list , argument-expression
7790 (treated as a keyword in GNU C)
7793 ( compound-statement )
7794 __builtin_va_arg ( assignment-expression , type-name )
7795 __builtin_offsetof ( type-name , offsetof-member-designator )
7796 __builtin_choose_expr ( assignment-expression ,
7797 assignment-expression ,
7798 assignment-expression )
7799 __builtin_types_compatible_p ( type-name , type-name )
7800 __builtin_tgmath ( expr-list )
7801 __builtin_complex ( assignment-expression , assignment-expression )
7802 __builtin_shuffle ( assignment-expression , assignment-expression )
7803 __builtin_shuffle ( assignment-expression ,
7804 assignment-expression ,
7805 assignment-expression, )
7807 offsetof-member-designator:
7809 offsetof-member-designator . identifier
7810 offsetof-member-designator [ expression ]
7815 [ objc-receiver objc-message-args ]
7816 @selector ( objc-selector-arg )
7817 @protocol ( identifier )
7818 @encode ( type-name )
7820 Classname . identifier
7823 static struct c_expr
7824 c_parser_postfix_expression (c_parser *parser)
7826 struct c_expr expr, e1;
7827 struct c_type_name *t1, *t2;
7828 location_t loc = c_parser_peek_token (parser)->location;
7829 source_range tok_range = c_parser_peek_token (parser)->get_range ();
7830 expr.original_code = ERROR_MARK;
7831 expr.original_type = NULL;
7832 switch (c_parser_peek_token (parser)->type)
7835 expr.value = c_parser_peek_token (parser)->value;
7836 set_c_expr_source_range (&expr, tok_range);
7837 loc = c_parser_peek_token (parser)->location;
7838 c_parser_consume_token (parser);
7839 if (TREE_CODE (expr.value) == FIXED_CST
7840 && !targetm.fixed_point_supported_p ())
7842 error_at (loc, "fixed-point types not supported for this target");
7850 expr.value = c_parser_peek_token (parser)->value;
7851 /* For the purpose of warning when a pointer is compared with
7852 a zero character constant. */
7853 expr.original_type = char_type_node;
7854 set_c_expr_source_range (&expr, tok_range);
7855 c_parser_consume_token (parser);
7861 case CPP_UTF8STRING:
7862 expr.value = c_parser_peek_token (parser)->value;
7863 set_c_expr_source_range (&expr, tok_range);
7864 expr.original_code = STRING_CST;
7865 c_parser_consume_token (parser);
7867 case CPP_OBJC_STRING:
7868 gcc_assert (c_dialect_objc ());
7870 = objc_build_string_object (c_parser_peek_token (parser)->value);
7871 set_c_expr_source_range (&expr, tok_range);
7872 c_parser_consume_token (parser);
7875 switch (c_parser_peek_token (parser)->id_kind)
7879 tree id = c_parser_peek_token (parser)->value;
7880 c_parser_consume_token (parser);
7881 expr.value = build_external_ref (loc, id,
7882 (c_parser_peek_token (parser)->type
7884 &expr.original_type);
7885 set_c_expr_source_range (&expr, tok_range);
7888 case C_ID_CLASSNAME:
7890 /* Here we parse the Objective-C 2.0 Class.name dot
7892 tree class_name = c_parser_peek_token (parser)->value;
7894 c_parser_consume_token (parser);
7895 gcc_assert (c_dialect_objc ());
7896 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
7901 if (c_parser_next_token_is_not (parser, CPP_NAME))
7903 c_parser_error (parser, "expected identifier");
7907 c_token *component_tok = c_parser_peek_token (parser);
7908 component = component_tok->value;
7909 location_t end_loc = component_tok->get_finish ();
7910 c_parser_consume_token (parser);
7911 expr.value = objc_build_class_component_ref (class_name,
7913 set_c_expr_source_range (&expr, loc, end_loc);
7917 c_parser_error (parser, "expected expression");
7922 case CPP_OPEN_PAREN:
7923 /* A parenthesized expression, statement expression or compound
7925 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
7927 /* A statement expression. */
7929 location_t brace_loc;
7930 c_parser_consume_token (parser);
7931 brace_loc = c_parser_peek_token (parser)->location;
7932 c_parser_consume_token (parser);
7933 if (!building_stmt_list_p ())
7935 error_at (loc, "braced-group within expression allowed "
7936 "only inside a function");
7937 parser->error = true;
7938 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
7939 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7943 stmt = c_begin_stmt_expr ();
7944 c_parser_compound_statement_nostart (parser);
7945 location_t close_loc = c_parser_peek_token (parser)->location;
7946 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7948 pedwarn (loc, OPT_Wpedantic,
7949 "ISO C forbids braced-groups within expressions");
7950 expr.value = c_finish_stmt_expr (brace_loc, stmt);
7951 set_c_expr_source_range (&expr, loc, close_loc);
7952 mark_exp_read (expr.value);
7956 /* A parenthesized expression. */
7957 location_t loc_open_paren = c_parser_peek_token (parser)->location;
7958 c_parser_consume_token (parser);
7959 expr = c_parser_expression (parser);
7960 if (TREE_CODE (expr.value) == MODIFY_EXPR)
7961 TREE_NO_WARNING (expr.value) = 1;
7962 if (expr.original_code != C_MAYBE_CONST_EXPR
7963 && expr.original_code != SIZEOF_EXPR)
7964 expr.original_code = ERROR_MARK;
7965 /* Don't change EXPR.ORIGINAL_TYPE. */
7966 location_t loc_close_paren = c_parser_peek_token (parser)->location;
7967 set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren);
7968 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7969 "expected %<)%>", loc_open_paren);
7973 switch (c_parser_peek_token (parser)->keyword)
7975 case RID_FUNCTION_NAME:
7976 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7977 "%<__FUNCTION__%> predefined identifier");
7978 expr.value = fname_decl (loc,
7979 c_parser_peek_token (parser)->keyword,
7980 c_parser_peek_token (parser)->value);
7981 set_c_expr_source_range (&expr, loc, loc);
7982 c_parser_consume_token (parser);
7984 case RID_PRETTY_FUNCTION_NAME:
7985 pedwarn (loc, OPT_Wpedantic, "ISO C does not support "
7986 "%<__PRETTY_FUNCTION__%> predefined identifier");
7987 expr.value = fname_decl (loc,
7988 c_parser_peek_token (parser)->keyword,
7989 c_parser_peek_token (parser)->value);
7990 set_c_expr_source_range (&expr, loc, loc);
7991 c_parser_consume_token (parser);
7993 case RID_C99_FUNCTION_NAME:
7994 pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support "
7995 "%<__func__%> predefined identifier");
7996 expr.value = fname_decl (loc,
7997 c_parser_peek_token (parser)->keyword,
7998 c_parser_peek_token (parser)->value);
7999 set_c_expr_source_range (&expr, loc, loc);
8000 c_parser_consume_token (parser);
8004 location_t start_loc = loc;
8005 c_parser_consume_token (parser);
8006 matching_parens parens;
8007 if (!parens.require_open (parser))
8012 e1 = c_parser_expr_no_commas (parser, NULL);
8013 mark_exp_read (e1.value);
8014 e1.value = c_fully_fold (e1.value, false, NULL);
8015 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
8017 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8021 loc = c_parser_peek_token (parser)->location;
8022 t1 = c_parser_type_name (parser);
8023 location_t end_loc = c_parser_peek_token (parser)->get_finish ();
8024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8032 tree type_expr = NULL_TREE;
8033 expr.value = c_build_va_arg (start_loc, e1.value, loc,
8034 groktypename (t1, &type_expr, NULL));
8037 expr.value = build2 (C_MAYBE_CONST_EXPR,
8038 TREE_TYPE (expr.value), type_expr,
8040 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
8042 set_c_expr_source_range (&expr, start_loc, end_loc);
8048 c_parser_consume_token (parser);
8049 matching_parens parens;
8050 if (!parens.require_open (parser))
8055 t1 = c_parser_type_name (parser);
8057 parser->error = true;
8058 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
8059 gcc_assert (parser->error);
8062 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8066 tree type = groktypename (t1, NULL, NULL);
8068 if (type == error_mark_node)
8069 offsetof_ref = error_mark_node;
8072 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
8073 SET_EXPR_LOCATION (offsetof_ref, loc);
8075 /* Parse the second argument to __builtin_offsetof. We
8076 must have one identifier, and beyond that we want to
8077 accept sub structure and sub array references. */
8078 if (c_parser_next_token_is (parser, CPP_NAME))
8080 c_token *comp_tok = c_parser_peek_token (parser);
8081 offsetof_ref = build_component_ref
8082 (loc, offsetof_ref, comp_tok->value, comp_tok->location);
8083 c_parser_consume_token (parser);
8084 while (c_parser_next_token_is (parser, CPP_DOT)
8085 || c_parser_next_token_is (parser,
8087 || c_parser_next_token_is (parser,
8090 if (c_parser_next_token_is (parser, CPP_DEREF))
8092 loc = c_parser_peek_token (parser)->location;
8093 offsetof_ref = build_array_ref (loc,
8098 else if (c_parser_next_token_is (parser, CPP_DOT))
8101 c_parser_consume_token (parser);
8102 if (c_parser_next_token_is_not (parser,
8105 c_parser_error (parser, "expected identifier");
8108 c_token *comp_tok = c_parser_peek_token (parser);
8109 offsetof_ref = build_component_ref
8110 (loc, offsetof_ref, comp_tok->value,
8111 comp_tok->location);
8112 c_parser_consume_token (parser);
8118 loc = c_parser_peek_token (parser)->location;
8119 c_parser_consume_token (parser);
8120 ce = c_parser_expression (parser);
8121 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
8123 idx = c_fully_fold (idx, false, NULL);
8124 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
8126 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
8131 c_parser_error (parser, "expected identifier");
8132 location_t end_loc = c_parser_peek_token (parser)->get_finish ();
8133 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8135 expr.value = fold_offsetof (offsetof_ref);
8136 set_c_expr_source_range (&expr, loc, end_loc);
8139 case RID_CHOOSE_EXPR:
8141 vec<c_expr_t, va_gc> *cexpr_list;
8142 c_expr_t *e1_p, *e2_p, *e3_p;
8144 location_t close_paren_loc;
8146 c_parser_consume_token (parser);
8147 if (!c_parser_get_builtin_args (parser,
8148 "__builtin_choose_expr",
8156 if (vec_safe_length (cexpr_list) != 3)
8158 error_at (loc, "wrong number of arguments to "
8159 "%<__builtin_choose_expr%>");
8164 e1_p = &(*cexpr_list)[0];
8165 e2_p = &(*cexpr_list)[1];
8166 e3_p = &(*cexpr_list)[2];
8169 mark_exp_read (e2_p->value);
8170 mark_exp_read (e3_p->value);
8171 if (TREE_CODE (c) != INTEGER_CST
8172 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
8174 "first argument to %<__builtin_choose_expr%> not"
8176 constant_expression_warning (c);
8177 expr = integer_zerop (c) ? *e3_p : *e2_p;
8178 set_c_expr_source_range (&expr, loc, close_paren_loc);
8181 case RID_TYPES_COMPATIBLE_P:
8183 c_parser_consume_token (parser);
8184 matching_parens parens;
8185 if (!parens.require_open (parser))
8190 t1 = c_parser_type_name (parser);
8196 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
8198 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8202 t2 = c_parser_type_name (parser);
8208 location_t close_paren_loc = c_parser_peek_token (parser)->location;
8209 parens.skip_until_found_close (parser);
8211 e1 = groktypename (t1, NULL, NULL);
8212 e2 = groktypename (t2, NULL, NULL);
8213 if (e1 == error_mark_node || e2 == error_mark_node)
8219 e1 = TYPE_MAIN_VARIANT (e1);
8220 e2 = TYPE_MAIN_VARIANT (e2);
8223 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
8224 set_c_expr_source_range (&expr, loc, close_paren_loc);
8227 case RID_BUILTIN_TGMATH:
8229 vec<c_expr_t, va_gc> *cexpr_list;
8230 location_t close_paren_loc;
8232 c_parser_consume_token (parser);
8233 if (!c_parser_get_builtin_args (parser,
8242 if (vec_safe_length (cexpr_list) < 3)
8244 error_at (loc, "too few arguments to %<__builtin_tgmath%>");
8251 FOR_EACH_VEC_ELT (*cexpr_list, i, p)
8252 *p = convert_lvalue_to_rvalue (loc, *p, true, true);
8253 unsigned int nargs = check_tgmath_function (&(*cexpr_list)[0], 1);
8259 if (vec_safe_length (cexpr_list) < nargs)
8261 error_at (loc, "too few arguments to %<__builtin_tgmath%>");
8265 unsigned int num_functions = vec_safe_length (cexpr_list) - nargs;
8266 if (num_functions < 2)
8268 error_at (loc, "too few arguments to %<__builtin_tgmath%>");
8273 /* The first NUM_FUNCTIONS expressions are the function
8274 pointers. The remaining NARGS expressions are the
8275 arguments that are to be passed to one of those
8276 functions, chosen following <tgmath.h> rules. */
8277 for (unsigned int j = 1; j < num_functions; j++)
8279 unsigned int this_nargs
8280 = check_tgmath_function (&(*cexpr_list)[j], j + 1);
8281 if (this_nargs == 0)
8286 if (this_nargs != nargs)
8288 error_at ((*cexpr_list)[j].get_location (),
8289 "argument %u of %<__builtin_tgmath%> has "
8290 "wrong number of arguments", j + 1);
8296 /* The functions all have the same number of arguments.
8297 Determine whether arguments and return types vary in
8298 ways permitted for <tgmath.h> functions. */
8299 /* The first entry in each of these vectors is for the
8300 return type, subsequent entries for parameter
8302 auto_vec<enum tgmath_parm_kind> parm_kind (nargs + 1);
8303 auto_vec<tree> parm_first (nargs + 1);
8304 auto_vec<bool> parm_complex (nargs + 1);
8305 auto_vec<bool> parm_varies (nargs + 1);
8306 tree first_type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[0].value));
8307 tree first_ret = TYPE_MAIN_VARIANT (TREE_TYPE (first_type));
8308 parm_first.quick_push (first_ret);
8309 parm_complex.quick_push (TREE_CODE (first_ret) == COMPLEX_TYPE);
8310 parm_varies.quick_push (false);
8311 function_args_iterator iter;
8313 unsigned int argpos;
8314 FOREACH_FUNCTION_ARGS (first_type, t, iter)
8316 if (t == void_type_node)
8318 parm_first.quick_push (TYPE_MAIN_VARIANT (t));
8319 parm_complex.quick_push (TREE_CODE (t) == COMPLEX_TYPE);
8320 parm_varies.quick_push (false);
8322 for (unsigned int j = 1; j < num_functions; j++)
8324 tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
8325 tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type));
8326 if (ret != parm_first[0])
8328 parm_varies[0] = true;
8329 if (!SCALAR_FLOAT_TYPE_P (parm_first[0])
8330 && !COMPLEX_FLOAT_TYPE_P (parm_first[0]))
8332 error_at ((*cexpr_list)[0].get_location (),
8333 "invalid type-generic return type for "
8334 "argument %u of %<__builtin_tgmath%>",
8339 if (!SCALAR_FLOAT_TYPE_P (ret)
8340 && !COMPLEX_FLOAT_TYPE_P (ret))
8342 error_at ((*cexpr_list)[j].get_location (),
8343 "invalid type-generic return type for "
8344 "argument %u of %<__builtin_tgmath%>",
8350 if (TREE_CODE (ret) == COMPLEX_TYPE)
8351 parm_complex[0] = true;
8353 FOREACH_FUNCTION_ARGS (type, t, iter)
8355 if (t == void_type_node)
8357 t = TYPE_MAIN_VARIANT (t);
8358 if (t != parm_first[argpos])
8360 parm_varies[argpos] = true;
8361 if (!SCALAR_FLOAT_TYPE_P (parm_first[argpos])
8362 && !COMPLEX_FLOAT_TYPE_P (parm_first[argpos]))
8364 error_at ((*cexpr_list)[0].get_location (),
8365 "invalid type-generic type for "
8366 "argument %u of argument %u of "
8367 "%<__builtin_tgmath%>", argpos, 1);
8371 if (!SCALAR_FLOAT_TYPE_P (t)
8372 && !COMPLEX_FLOAT_TYPE_P (t))
8374 error_at ((*cexpr_list)[j].get_location (),
8375 "invalid type-generic type for "
8376 "argument %u of argument %u of "
8377 "%<__builtin_tgmath%>", argpos, j + 1);
8382 if (TREE_CODE (t) == COMPLEX_TYPE)
8383 parm_complex[argpos] = true;
8387 enum tgmath_parm_kind max_variation = tgmath_fixed;
8388 for (unsigned int j = 0; j <= nargs; j++)
8390 enum tgmath_parm_kind this_kind;
8393 if (parm_complex[j])
8394 max_variation = this_kind = tgmath_complex;
8397 this_kind = tgmath_real;
8398 if (max_variation != tgmath_complex)
8399 max_variation = tgmath_real;
8403 this_kind = tgmath_fixed;
8404 parm_kind.quick_push (this_kind);
8406 if (max_variation == tgmath_fixed)
8408 error_at (loc, "function arguments of %<__builtin_tgmath%> "
8409 "all have the same type");
8414 /* Identify a parameter (not the return type) that varies,
8415 including with complex types if any variation includes
8416 complex types; there must be at least one such
8418 unsigned int tgarg = 0;
8419 for (unsigned int j = 1; j <= nargs; j++)
8420 if (parm_kind[j] == max_variation)
8427 error_at (loc, "function arguments of %<__builtin_tgmath%> "
8428 "lack type-generic parameter");
8433 /* Determine the type of the relevant parameter for each
8435 auto_vec<tree> tg_type (num_functions);
8436 for (unsigned int j = 0; j < num_functions; j++)
8438 tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
8440 FOREACH_FUNCTION_ARGS (type, t, iter)
8442 if (argpos == tgarg)
8444 tg_type.quick_push (TYPE_MAIN_VARIANT (t));
8451 /* Verify that the corresponding types are different for
8452 all the listed functions. Also determine whether all
8453 the types are complex, whether all the types are
8454 standard or binary, and whether all the types are
8456 bool all_complex = true;
8457 bool all_binary = true;
8458 bool all_decimal = true;
8459 hash_set<tree> tg_types;
8460 FOR_EACH_VEC_ELT (tg_type, i, t)
8462 if (TREE_CODE (t) == COMPLEX_TYPE)
8463 all_decimal = false;
8466 all_complex = false;
8467 if (DECIMAL_FLOAT_TYPE_P (t))
8470 all_decimal = false;
8472 if (tg_types.add (t))
8474 error_at ((*cexpr_list)[i].get_location (),
8475 "duplicate type-generic parameter type for "
8476 "function argument %u of %<__builtin_tgmath%>",
8483 /* Verify that other parameters and the return type whose
8484 types vary have their types varying in the correct
8486 for (unsigned int j = 0; j < num_functions; j++)
8488 tree exp_type = tg_type[j];
8489 tree exp_real_type = exp_type;
8490 if (TREE_CODE (exp_type) == COMPLEX_TYPE)
8491 exp_real_type = TREE_TYPE (exp_type);
8492 tree type = TREE_TYPE (TREE_TYPE ((*cexpr_list)[j].value));
8493 tree ret = TYPE_MAIN_VARIANT (TREE_TYPE (type));
8494 if ((parm_kind[0] == tgmath_complex && ret != exp_type)
8495 || (parm_kind[0] == tgmath_real && ret != exp_real_type))
8497 error_at ((*cexpr_list)[j].get_location (),
8498 "bad return type for function argument %u "
8499 "of %<__builtin_tgmath%>", j + 1);
8504 FOREACH_FUNCTION_ARGS (type, t, iter)
8506 if (t == void_type_node)
8508 t = TYPE_MAIN_VARIANT (t);
8509 if ((parm_kind[argpos] == tgmath_complex
8511 || (parm_kind[argpos] == tgmath_real
8512 && t != exp_real_type))
8514 error_at ((*cexpr_list)[j].get_location (),
8515 "bad type for argument %u of "
8516 "function argument %u of "
8517 "%<__builtin_tgmath%>", argpos, j + 1);
8525 /* The functions listed are a valid set of functions for a
8526 <tgmath.h> macro to select between. Identify the
8527 matching function, if any. First, the argument types
8528 must be combined following <tgmath.h> rules. Integer
8529 types are treated as _Decimal64 if any type-generic
8530 argument is decimal, or if the only alternatives for
8531 type-generic arguments are of decimal types, and are
8532 otherwise treated as double (or _Complex double for
8533 complex integer types, or _Float64 or _Complex _Float64
8534 if all the return types are the same _FloatN or
8535 _FloatNx type). After that adjustment, types are
8536 combined following the usual arithmetic conversions.
8537 If the function only accepts complex arguments, a
8538 complex type is produced. */
8539 bool arg_complex = all_complex;
8540 bool arg_binary = all_binary;
8541 bool arg_int_decimal = all_decimal;
8542 for (unsigned int j = 1; j <= nargs; j++)
8544 if (parm_kind[j] == tgmath_fixed)
8546 c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1];
8547 tree type = TREE_TYPE (ce->value);
8548 if (!INTEGRAL_TYPE_P (type)
8549 && !SCALAR_FLOAT_TYPE_P (type)
8550 && TREE_CODE (type) != COMPLEX_TYPE)
8552 error_at (ce->get_location (),
8553 "invalid type of argument %u of type-generic "
8558 if (DECIMAL_FLOAT_TYPE_P (type))
8560 arg_int_decimal = true;
8563 error_at (ce->get_location (),
8564 "decimal floating-point argument %u to "
8565 "complex-only type-generic function", j);
8569 else if (all_binary)
8571 error_at (ce->get_location (),
8572 "decimal floating-point argument %u to "
8573 "binary-only type-generic function", j);
8577 else if (arg_complex)
8579 error_at (ce->get_location (),
8580 "both complex and decimal floating-point "
8581 "arguments to type-generic function");
8585 else if (arg_binary)
8587 error_at (ce->get_location (),
8588 "both binary and decimal floating-point "
8589 "arguments to type-generic function");
8594 else if (TREE_CODE (type) == COMPLEX_TYPE)
8597 if (COMPLEX_FLOAT_TYPE_P (type))
8601 error_at (ce->get_location (),
8602 "complex argument %u to "
8603 "decimal-only type-generic function", j);
8607 else if (arg_int_decimal)
8609 error_at (ce->get_location (),
8610 "both complex and decimal floating-point "
8611 "arguments to type-generic function");
8616 else if (SCALAR_FLOAT_TYPE_P (type))
8621 error_at (ce->get_location (),
8622 "binary argument %u to "
8623 "decimal-only type-generic function", j);
8627 else if (arg_int_decimal)
8629 error_at (ce->get_location (),
8630 "both binary and decimal floating-point "
8631 "arguments to type-generic function");
8637 /* For a macro rounding its result to a narrower type, map
8638 integer types to _Float64 not double if the return type
8639 is a _FloatN or _FloatNx type. */
8640 bool arg_int_float64 = false;
8641 if (parm_kind[0] == tgmath_fixed
8642 && SCALAR_FLOAT_TYPE_P (parm_first[0])
8643 && float64_type_node != NULL_TREE)
8644 for (unsigned int j = 0; j < NUM_FLOATN_NX_TYPES; j++)
8645 if (parm_first[0] == FLOATN_TYPE_NODE (j))
8647 arg_int_float64 = true;
8650 tree arg_real = NULL_TREE;
8651 for (unsigned int j = 1; j <= nargs; j++)
8653 if (parm_kind[j] == tgmath_fixed)
8655 c_expr_t *ce = &(*cexpr_list)[num_functions + j - 1];
8656 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (ce->value));
8657 if (TREE_CODE (type) == COMPLEX_TYPE)
8658 type = TREE_TYPE (type);
8659 if (INTEGRAL_TYPE_P (type))
8660 type = (arg_int_decimal
8661 ? dfloat64_type_node
8664 : double_type_node);
8665 if (arg_real == NULL_TREE)
8668 arg_real = common_type (arg_real, type);
8669 if (arg_real == error_mark_node)
8675 tree arg_type = (arg_complex
8676 ? build_complex_type (arg_real)
8679 /* Look for a function to call with type-generic parameter
8681 c_expr_t *fn = NULL;
8682 for (unsigned int j = 0; j < num_functions; j++)
8684 if (tg_type[j] == arg_type)
8686 fn = &(*cexpr_list)[j];
8691 && parm_kind[0] == tgmath_fixed
8692 && SCALAR_FLOAT_TYPE_P (parm_first[0]))
8694 /* Presume this is a macro that rounds its result to a
8695 narrower type, and look for the first function with
8696 at least the range and precision of the argument
8698 for (unsigned int j = 0; j < num_functions; j++)
8701 != (TREE_CODE (tg_type[j]) == COMPLEX_TYPE))
8703 tree real_tg_type = (arg_complex
8704 ? TREE_TYPE (tg_type[j])
8706 if (DECIMAL_FLOAT_TYPE_P (arg_real)
8707 != DECIMAL_FLOAT_TYPE_P (real_tg_type))
8709 scalar_float_mode arg_mode
8710 = SCALAR_FLOAT_TYPE_MODE (arg_real);
8711 scalar_float_mode tg_mode
8712 = SCALAR_FLOAT_TYPE_MODE (real_tg_type);
8713 const real_format *arg_fmt = REAL_MODE_FORMAT (arg_mode);
8714 const real_format *tg_fmt = REAL_MODE_FORMAT (tg_mode);
8715 if (arg_fmt->b == tg_fmt->b
8716 && arg_fmt->p <= tg_fmt->p
8717 && arg_fmt->emax <= tg_fmt->emax
8718 && (arg_fmt->emin - arg_fmt->p
8719 >= tg_fmt->emin - tg_fmt->p))
8721 fn = &(*cexpr_list)[j];
8728 error_at (loc, "no matching function for type-generic call");
8733 /* Construct a call to FN. */
8734 vec<tree, va_gc> *args;
8735 vec_alloc (args, nargs);
8736 vec<tree, va_gc> *origtypes;
8737 vec_alloc (origtypes, nargs);
8738 auto_vec<location_t> arg_loc (nargs);
8739 for (unsigned int j = 0; j < nargs; j++)
8741 c_expr_t *ce = &(*cexpr_list)[num_functions + j];
8742 args->quick_push (ce->value);
8743 arg_loc.quick_push (ce->get_location ());
8744 origtypes->quick_push (ce->original_type);
8746 expr.value = c_build_function_call_vec (loc, arg_loc, fn->value,
8748 set_c_expr_source_range (&expr, loc, close_paren_loc);
8751 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN:
8753 vec<c_expr_t, va_gc> *cexpr_list;
8756 location_t close_paren_loc;
8758 c_parser_consume_token (parser);
8759 if (!c_parser_get_builtin_args (parser,
8760 "__builtin_call_with_static_chain",
8767 if (vec_safe_length (cexpr_list) != 2)
8769 error_at (loc, "wrong number of arguments to "
8770 "%<__builtin_call_with_static_chain%>");
8775 expr = (*cexpr_list)[0];
8776 e2_p = &(*cexpr_list)[1];
8777 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
8778 chain_value = e2_p->value;
8779 mark_exp_read (chain_value);
8781 if (TREE_CODE (expr.value) != CALL_EXPR)
8782 error_at (loc, "first argument to "
8783 "%<__builtin_call_with_static_chain%> "
8784 "must be a call expression");
8785 else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE)
8786 error_at (loc, "second argument to "
8787 "%<__builtin_call_with_static_chain%> "
8788 "must be a pointer type");
8790 CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
8791 set_c_expr_source_range (&expr, loc, close_paren_loc);
8794 case RID_BUILTIN_COMPLEX:
8796 vec<c_expr_t, va_gc> *cexpr_list;
8797 c_expr_t *e1_p, *e2_p;
8798 location_t close_paren_loc;
8800 c_parser_consume_token (parser);
8801 if (!c_parser_get_builtin_args (parser,
8802 "__builtin_complex",
8810 if (vec_safe_length (cexpr_list) != 2)
8812 error_at (loc, "wrong number of arguments to "
8813 "%<__builtin_complex%>");
8818 e1_p = &(*cexpr_list)[0];
8819 e2_p = &(*cexpr_list)[1];
8821 *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true);
8822 if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
8823 e1_p->value = convert (TREE_TYPE (e1_p->value),
8824 TREE_OPERAND (e1_p->value, 0));
8825 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true);
8826 if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
8827 e2_p->value = convert (TREE_TYPE (e2_p->value),
8828 TREE_OPERAND (e2_p->value, 0));
8829 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
8830 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
8831 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
8832 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
8834 error_at (loc, "%<__builtin_complex%> operand "
8835 "not of real binary floating-point type");
8839 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
8840 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
8843 "%<__builtin_complex%> operands of different types");
8847 pedwarn_c90 (loc, OPT_Wpedantic,
8848 "ISO C90 does not support complex types");
8849 expr.value = build2_loc (loc, COMPLEX_EXPR,
8852 (TREE_TYPE (e1_p->value))),
8853 e1_p->value, e2_p->value);
8854 set_c_expr_source_range (&expr, loc, close_paren_loc);
8857 case RID_BUILTIN_SHUFFLE:
8859 vec<c_expr_t, va_gc> *cexpr_list;
8862 location_t close_paren_loc;
8864 c_parser_consume_token (parser);
8865 if (!c_parser_get_builtin_args (parser,
8866 "__builtin_shuffle",
8874 FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p)
8875 *p = convert_lvalue_to_rvalue (loc, *p, true, true);
8877 if (vec_safe_length (cexpr_list) == 2)
8879 c_build_vec_perm_expr
8880 (loc, (*cexpr_list)[0].value,
8881 NULL_TREE, (*cexpr_list)[1].value);
8883 else if (vec_safe_length (cexpr_list) == 3)
8885 c_build_vec_perm_expr
8886 (loc, (*cexpr_list)[0].value,
8887 (*cexpr_list)[1].value,
8888 (*cexpr_list)[2].value);
8891 error_at (loc, "wrong number of arguments to "
8892 "%<__builtin_shuffle%>");
8895 set_c_expr_source_range (&expr, loc, close_paren_loc);
8898 case RID_AT_SELECTOR:
8900 gcc_assert (c_dialect_objc ());
8901 c_parser_consume_token (parser);
8902 matching_parens parens;
8903 if (!parens.require_open (parser))
8908 tree sel = c_parser_objc_selector_arg (parser);
8909 location_t close_loc = c_parser_peek_token (parser)->location;
8910 parens.skip_until_found_close (parser);
8911 expr.value = objc_build_selector_expr (loc, sel);
8912 set_c_expr_source_range (&expr, loc, close_loc);
8915 case RID_AT_PROTOCOL:
8917 gcc_assert (c_dialect_objc ());
8918 c_parser_consume_token (parser);
8919 matching_parens parens;
8920 if (!parens.require_open (parser))
8925 if (c_parser_next_token_is_not (parser, CPP_NAME))
8927 c_parser_error (parser, "expected identifier");
8928 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8932 tree id = c_parser_peek_token (parser)->value;
8933 c_parser_consume_token (parser);
8934 location_t close_loc = c_parser_peek_token (parser)->location;
8935 parens.skip_until_found_close (parser);
8936 expr.value = objc_build_protocol_expr (id);
8937 set_c_expr_source_range (&expr, loc, close_loc);
8942 /* Extension to support C-structures in the archiver. */
8943 gcc_assert (c_dialect_objc ());
8944 c_parser_consume_token (parser);
8945 matching_parens parens;
8946 if (!parens.require_open (parser))
8951 t1 = c_parser_type_name (parser);
8955 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
8958 location_t close_loc = c_parser_peek_token (parser)->location;
8959 parens.skip_until_found_close (parser);
8960 tree type = groktypename (t1, NULL, NULL);
8961 expr.value = objc_build_encode_expr (type);
8962 set_c_expr_source_range (&expr, loc, close_loc);
8966 expr = c_parser_generic_selection (parser);
8969 c_parser_error (parser, "expected expression");
8974 case CPP_OPEN_SQUARE:
8975 if (c_dialect_objc ())
8977 tree receiver, args;
8978 c_parser_consume_token (parser);
8979 receiver = c_parser_objc_receiver (parser);
8980 args = c_parser_objc_message_args (parser);
8981 location_t close_loc = c_parser_peek_token (parser)->location;
8982 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
8984 expr.value = objc_build_message_expr (receiver, args);
8985 set_c_expr_source_range (&expr, loc, close_loc);
8988 /* Else fall through to report error. */
8991 c_parser_error (parser, "expected expression");
8996 return c_parser_postfix_expression_after_primary
8997 (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr);
9000 /* Parse a postfix expression after a parenthesized type name: the
9001 brace-enclosed initializer of a compound literal, possibly followed
9002 by some postfix operators. This is separate because it is not
9003 possible to tell until after the type name whether a cast
9004 expression has a cast or a compound literal, or whether the operand
9005 of sizeof is a parenthesized type name or starts with a compound
9006 literal. TYPE_LOC is the location where TYPE_NAME starts--the
9007 location of the first token after the parentheses around the type
9010 static struct c_expr
9011 c_parser_postfix_expression_after_paren_type (c_parser *parser,
9012 struct c_type_name *type_name,
9013 location_t type_loc)
9019 location_t start_loc;
9020 tree type_expr = NULL_TREE;
9021 bool type_expr_const = true;
9022 check_compound_literal_type (type_loc, type_name);
9023 rich_location richloc (line_table, type_loc);
9024 start_init (NULL_TREE, NULL, 0, &richloc);
9025 type = groktypename (type_name, &type_expr, &type_expr_const);
9026 start_loc = c_parser_peek_token (parser)->location;
9027 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
9029 error_at (type_loc, "compound literal has variable size");
9030 type = error_mark_node;
9032 init = c_parser_braced_init (parser, type, false, NULL);
9034 maybe_warn_string_init (type_loc, type, init);
9036 if (type != error_mark_node
9037 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
9038 && current_function_decl)
9040 error ("compound literal qualified by address-space qualifier");
9041 type = error_mark_node;
9044 pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals");
9045 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
9046 ? CONSTRUCTOR_NON_CONST (init.value)
9047 : init.original_code == C_MAYBE_CONST_EXPR);
9048 non_const |= !type_expr_const;
9049 unsigned int alignas_align = 0;
9050 if (type != error_mark_node
9051 && type_name->specs->align_log != -1)
9053 alignas_align = 1U << type_name->specs->align_log;
9054 if (alignas_align < min_align_of_type (type))
9056 error_at (type_name->specs->locations[cdw_alignas],
9057 "%<_Alignas%> specifiers cannot reduce "
9058 "alignment of compound literal");
9062 expr.value = build_compound_literal (start_loc, type, init.value, non_const,
9064 set_c_expr_source_range (&expr, init.src_range);
9065 expr.original_code = ERROR_MARK;
9066 expr.original_type = NULL;
9067 if (type != error_mark_node
9068 && expr.value != error_mark_node
9071 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
9073 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
9074 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
9078 gcc_assert (!non_const);
9079 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
9080 type_expr, expr.value);
9083 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
9086 /* Callback function for sizeof_pointer_memaccess_warning to compare
9090 sizeof_ptr_memacc_comptypes (tree type1, tree type2)
9092 return comptypes (type1, type2) == 1;
9095 /* Parse a postfix expression after the initial primary or compound
9096 literal; that is, parse a series of postfix operators.
9098 EXPR_LOC is the location of the primary expression. */
9100 static struct c_expr
9101 c_parser_postfix_expression_after_primary (c_parser *parser,
9102 location_t expr_loc,
9105 struct c_expr orig_expr;
9107 location_t sizeof_arg_loc[3], comp_loc;
9109 unsigned int literal_zero_mask;
9111 vec<tree, va_gc> *exprlist;
9112 vec<tree, va_gc> *origtypes = NULL;
9113 vec<location_t> arg_loc = vNULL;
9119 location_t op_loc = c_parser_peek_token (parser)->location;
9120 switch (c_parser_peek_token (parser)->type)
9122 case CPP_OPEN_SQUARE:
9123 /* Array reference. */
9124 c_parser_consume_token (parser);
9125 idx = c_parser_expression (parser).value;
9126 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
9128 start = expr.get_start ();
9129 finish = parser->tokens_buf[0].location;
9130 expr.value = build_array_ref (op_loc, expr.value, idx);
9131 set_c_expr_source_range (&expr, start, finish);
9132 expr.original_code = ERROR_MARK;
9133 expr.original_type = NULL;
9135 case CPP_OPEN_PAREN:
9136 /* Function call. */
9137 c_parser_consume_token (parser);
9138 for (i = 0; i < 3; i++)
9140 sizeof_arg[i] = NULL_TREE;
9141 sizeof_arg_loc[i] = UNKNOWN_LOCATION;
9143 literal_zero_mask = 0;
9144 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9147 exprlist = c_parser_expr_list (parser, true, false, &origtypes,
9148 sizeof_arg_loc, sizeof_arg,
9149 &arg_loc, &literal_zero_mask);
9150 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9153 mark_exp_read (expr.value);
9154 if (warn_sizeof_pointer_memaccess)
9155 sizeof_pointer_memaccess_warning (sizeof_arg_loc,
9156 expr.value, exprlist,
9158 sizeof_ptr_memacc_comptypes);
9159 if (TREE_CODE (expr.value) == FUNCTION_DECL
9160 && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL
9161 && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET
9162 && vec_safe_length (exprlist) == 3)
9164 tree arg0 = (*exprlist)[0];
9165 tree arg2 = (*exprlist)[2];
9166 warn_for_memset (expr_loc, arg0, arg2, literal_zero_mask);
9169 start = expr.get_start ();
9170 finish = parser->tokens_buf[0].get_finish ();
9172 = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
9173 exprlist, origtypes);
9174 set_c_expr_source_range (&expr, start, finish);
9176 expr.original_code = ERROR_MARK;
9177 if (TREE_CODE (expr.value) == INTEGER_CST
9178 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
9179 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
9180 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
9181 expr.original_code = C_MAYBE_CONST_EXPR;
9182 expr.original_type = NULL;
9185 release_tree_vector (exprlist);
9186 release_tree_vector (origtypes);
9191 /* Structure element reference. */
9192 c_parser_consume_token (parser);
9193 expr = default_function_array_conversion (expr_loc, expr);
9194 if (c_parser_next_token_is (parser, CPP_NAME))
9196 c_token *comp_tok = c_parser_peek_token (parser);
9197 ident = comp_tok->value;
9198 comp_loc = comp_tok->location;
9202 c_parser_error (parser, "expected identifier");
9204 expr.original_code = ERROR_MARK;
9205 expr.original_type = NULL;
9208 start = expr.get_start ();
9209 finish = c_parser_peek_token (parser)->get_finish ();
9210 c_parser_consume_token (parser);
9211 expr.value = build_component_ref (op_loc, expr.value, ident,
9213 set_c_expr_source_range (&expr, start, finish);
9214 expr.original_code = ERROR_MARK;
9215 if (TREE_CODE (expr.value) != COMPONENT_REF)
9216 expr.original_type = NULL;
9219 /* Remember the original type of a bitfield. */
9220 tree field = TREE_OPERAND (expr.value, 1);
9221 if (TREE_CODE (field) != FIELD_DECL)
9222 expr.original_type = NULL;
9224 expr.original_type = DECL_BIT_FIELD_TYPE (field);
9228 /* Structure element reference. */
9229 c_parser_consume_token (parser);
9230 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false);
9231 if (c_parser_next_token_is (parser, CPP_NAME))
9233 c_token *comp_tok = c_parser_peek_token (parser);
9234 ident = comp_tok->value;
9235 comp_loc = comp_tok->location;
9239 c_parser_error (parser, "expected identifier");
9241 expr.original_code = ERROR_MARK;
9242 expr.original_type = NULL;
9245 start = expr.get_start ();
9246 finish = c_parser_peek_token (parser)->get_finish ();
9247 c_parser_consume_token (parser);
9248 expr.value = build_component_ref (op_loc,
9249 build_indirect_ref (op_loc,
9253 set_c_expr_source_range (&expr, start, finish);
9254 expr.original_code = ERROR_MARK;
9255 if (TREE_CODE (expr.value) != COMPONENT_REF)
9256 expr.original_type = NULL;
9259 /* Remember the original type of a bitfield. */
9260 tree field = TREE_OPERAND (expr.value, 1);
9261 if (TREE_CODE (field) != FIELD_DECL)
9262 expr.original_type = NULL;
9264 expr.original_type = DECL_BIT_FIELD_TYPE (field);
9268 /* Postincrement. */
9269 start = expr.get_start ();
9270 finish = c_parser_peek_token (parser)->get_finish ();
9271 c_parser_consume_token (parser);
9272 expr = default_function_array_read_conversion (expr_loc, expr);
9273 expr.value = build_unary_op (op_loc, POSTINCREMENT_EXPR,
9275 set_c_expr_source_range (&expr, start, finish);
9276 expr.original_code = ERROR_MARK;
9277 expr.original_type = NULL;
9279 case CPP_MINUS_MINUS:
9280 /* Postdecrement. */
9281 start = expr.get_start ();
9282 finish = c_parser_peek_token (parser)->get_finish ();
9283 c_parser_consume_token (parser);
9284 expr = default_function_array_read_conversion (expr_loc, expr);
9285 expr.value = build_unary_op (op_loc, POSTDECREMENT_EXPR,
9287 set_c_expr_source_range (&expr, start, finish);
9288 expr.original_code = ERROR_MARK;
9289 expr.original_type = NULL;
9297 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9300 assignment-expression
9301 expression , assignment-expression
9304 static struct c_expr
9305 c_parser_expression (c_parser *parser)
9307 location_t tloc = c_parser_peek_token (parser)->location;
9309 expr = c_parser_expr_no_commas (parser, NULL);
9310 if (c_parser_next_token_is (parser, CPP_COMMA))
9311 expr = convert_lvalue_to_rvalue (tloc, expr, true, false);
9312 while (c_parser_next_token_is (parser, CPP_COMMA))
9316 location_t loc = c_parser_peek_token (parser)->location;
9317 location_t expr_loc;
9318 c_parser_consume_token (parser);
9319 expr_loc = c_parser_peek_token (parser)->location;
9320 lhsval = expr.value;
9321 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
9322 lhsval = TREE_OPERAND (lhsval, 1);
9323 if (DECL_P (lhsval) || handled_component_p (lhsval))
9324 mark_exp_read (lhsval);
9325 next = c_parser_expr_no_commas (parser, NULL);
9326 next = convert_lvalue_to_rvalue (expr_loc, next, true, false);
9327 expr.value = build_compound_expr (loc, expr.value, next.value);
9328 expr.original_code = COMPOUND_EXPR;
9329 expr.original_type = next.original_type;
9334 /* Parse an expression and convert functions or arrays to pointers and
9335 lvalues to rvalues. */
9337 static struct c_expr
9338 c_parser_expression_conv (c_parser *parser)
9341 location_t loc = c_parser_peek_token (parser)->location;
9342 expr = c_parser_expression (parser);
9343 expr = convert_lvalue_to_rvalue (loc, expr, true, false);
9347 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9348 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9351 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
9354 if (idx >= HOST_BITS_PER_INT)
9357 c_token *tok = c_parser_peek_token (parser);
9365 /* If a parameter is literal zero alone, remember it
9366 for -Wmemset-transposed-args warning. */
9367 if (integer_zerop (tok->value)
9368 && !TREE_OVERFLOW (tok->value)
9369 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
9370 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
9371 *literal_zero_mask |= 1U << idx;
9377 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9378 functions and arrays to pointers and lvalues to rvalues. If
9379 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9380 locations of function arguments into this vector.
9383 assignment-expression
9384 nonempty-expr-list , assignment-expression
9387 static vec<tree, va_gc> *
9388 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
9389 vec<tree, va_gc> **p_orig_types,
9390 location_t *sizeof_arg_loc, tree *sizeof_arg,
9391 vec<location_t> *locations,
9392 unsigned int *literal_zero_mask)
9394 vec<tree, va_gc> *ret;
9395 vec<tree, va_gc> *orig_types;
9397 unsigned int idx = 0;
9399 ret = make_tree_vector ();
9400 if (p_orig_types == NULL)
9403 orig_types = make_tree_vector ();
9405 if (literal_zero_mask)
9406 c_parser_check_literal_zero (parser, literal_zero_mask, 0);
9407 expr = c_parser_expr_no_commas (parser, NULL);
9409 expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true, true);
9411 expr.value = c_fully_fold (expr.value, false, NULL);
9412 ret->quick_push (expr.value);
9414 orig_types->quick_push (expr.original_type);
9416 locations->safe_push (expr.get_location ());
9417 if (sizeof_arg != NULL
9418 && expr.original_code == SIZEOF_EXPR)
9420 sizeof_arg[0] = c_last_sizeof_arg;
9421 sizeof_arg_loc[0] = c_last_sizeof_loc;
9423 while (c_parser_next_token_is (parser, CPP_COMMA))
9425 c_parser_consume_token (parser);
9426 if (literal_zero_mask)
9427 c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1);
9428 expr = c_parser_expr_no_commas (parser, NULL);
9430 expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true,
9433 expr.value = c_fully_fold (expr.value, false, NULL);
9434 vec_safe_push (ret, expr.value);
9436 vec_safe_push (orig_types, expr.original_type);
9438 locations->safe_push (expr.get_location ());
9440 && sizeof_arg != NULL
9441 && expr.original_code == SIZEOF_EXPR)
9443 sizeof_arg[idx] = c_last_sizeof_arg;
9444 sizeof_arg_loc[idx] = c_last_sizeof_loc;
9448 *p_orig_types = orig_types;
9452 /* Parse Objective-C-specific constructs. */
9454 /* Parse an objc-class-definition.
9456 objc-class-definition:
9457 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9458 objc-class-instance-variables[opt] objc-methodprotolist @end
9459 @implementation identifier objc-superclass[opt]
9460 objc-class-instance-variables[opt]
9461 @interface identifier ( identifier ) objc-protocol-refs[opt]
9462 objc-methodprotolist @end
9463 @interface identifier ( ) objc-protocol-refs[opt]
9464 objc-methodprotolist @end
9465 @implementation identifier ( identifier )
9470 "@interface identifier (" must start "@interface identifier (
9471 identifier ) ...": objc-methodprotolist in the first production may
9472 not start with a parenthesized identifier as a declarator of a data
9473 definition with no declaration specifiers if the objc-superclass,
9474 objc-protocol-refs and objc-class-instance-variables are omitted. */
9477 c_parser_objc_class_definition (c_parser *parser, tree attributes)
9482 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
9484 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
9489 c_parser_consume_token (parser);
9490 if (c_parser_next_token_is_not (parser, CPP_NAME))
9492 c_parser_error (parser, "expected identifier");
9495 id1 = c_parser_peek_token (parser)->value;
9496 c_parser_consume_token (parser);
9497 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9499 /* We have a category or class extension. */
9501 tree proto = NULL_TREE;
9502 matching_parens parens;
9503 parens.consume_open (parser);
9504 if (c_parser_next_token_is_not (parser, CPP_NAME))
9506 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
9508 /* We have a class extension. */
9513 c_parser_error (parser, "expected identifier or %<)%>");
9514 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
9520 id2 = c_parser_peek_token (parser)->value;
9521 c_parser_consume_token (parser);
9523 parens.skip_until_found_close (parser);
9526 objc_start_category_implementation (id1, id2);
9529 if (c_parser_next_token_is (parser, CPP_LESS))
9530 proto = c_parser_objc_protocol_refs (parser);
9531 objc_start_category_interface (id1, id2, proto, attributes);
9532 c_parser_objc_methodprotolist (parser);
9533 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
9534 objc_finish_interface ();
9537 if (c_parser_next_token_is (parser, CPP_COLON))
9539 c_parser_consume_token (parser);
9540 if (c_parser_next_token_is_not (parser, CPP_NAME))
9542 c_parser_error (parser, "expected identifier");
9545 superclass = c_parser_peek_token (parser)->value;
9546 c_parser_consume_token (parser);
9549 superclass = NULL_TREE;
9552 tree proto = NULL_TREE;
9553 if (c_parser_next_token_is (parser, CPP_LESS))
9554 proto = c_parser_objc_protocol_refs (parser);
9555 objc_start_class_interface (id1, superclass, proto, attributes);
9558 objc_start_class_implementation (id1, superclass);
9559 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9560 c_parser_objc_class_instance_variables (parser);
9563 objc_continue_interface ();
9564 c_parser_objc_methodprotolist (parser);
9565 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
9566 objc_finish_interface ();
9570 objc_continue_implementation ();
9575 /* Parse objc-class-instance-variables.
9577 objc-class-instance-variables:
9578 { objc-instance-variable-decl-list[opt] }
9580 objc-instance-variable-decl-list:
9581 objc-visibility-spec
9582 objc-instance-variable-decl ;
9584 objc-instance-variable-decl-list objc-visibility-spec
9585 objc-instance-variable-decl-list objc-instance-variable-decl ;
9586 objc-instance-variable-decl-list ;
9588 objc-visibility-spec:
9593 objc-instance-variable-decl:
9598 c_parser_objc_class_instance_variables (c_parser *parser)
9600 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
9601 c_parser_consume_token (parser);
9602 while (c_parser_next_token_is_not (parser, CPP_EOF))
9605 /* Parse any stray semicolon. */
9606 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9608 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9610 c_parser_consume_token (parser);
9613 /* Stop if at the end of the instance variables. */
9614 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9616 c_parser_consume_token (parser);
9619 /* Parse any objc-visibility-spec. */
9620 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
9622 c_parser_consume_token (parser);
9623 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
9626 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
9628 c_parser_consume_token (parser);
9629 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
9632 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
9634 c_parser_consume_token (parser);
9635 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
9638 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
9640 c_parser_consume_token (parser);
9641 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
9644 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
9646 c_parser_pragma (parser, pragma_external, NULL);
9650 /* Parse some comma-separated declarations. */
9651 decls = c_parser_struct_declaration (parser);
9654 /* There is a syntax error. We want to skip the offending
9655 tokens up to the next ';' (included) or '}'
9658 /* First, skip manually a ')' or ']'. This is because they
9659 reduce the nesting level, so c_parser_skip_until_found()
9660 wouldn't be able to skip past them. */
9661 c_token *token = c_parser_peek_token (parser);
9662 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
9663 c_parser_consume_token (parser);
9665 /* Then, do the standard skipping. */
9666 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9668 /* We hopefully recovered. Start normal parsing again. */
9669 parser->error = false;
9674 /* Comma-separated instance variables are chained together
9675 in reverse order; add them one by one. */
9676 tree ivar = nreverse (decls);
9677 for (; ivar; ivar = DECL_CHAIN (ivar))
9678 objc_add_instance_variable (copy_node (ivar));
9680 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9684 /* Parse an objc-class-declaration.
9686 objc-class-declaration:
9687 @class identifier-list ;
9691 c_parser_objc_class_declaration (c_parser *parser)
9693 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
9694 c_parser_consume_token (parser);
9695 /* Any identifiers, including those declared as type names, are OK
9700 if (c_parser_next_token_is_not (parser, CPP_NAME))
9702 c_parser_error (parser, "expected identifier");
9703 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9704 parser->error = false;
9707 id = c_parser_peek_token (parser)->value;
9708 objc_declare_class (id);
9709 c_parser_consume_token (parser);
9710 if (c_parser_next_token_is (parser, CPP_COMMA))
9711 c_parser_consume_token (parser);
9715 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9718 /* Parse an objc-alias-declaration.
9720 objc-alias-declaration:
9721 @compatibility_alias identifier identifier ;
9725 c_parser_objc_alias_declaration (c_parser *parser)
9728 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
9729 c_parser_consume_token (parser);
9730 if (c_parser_next_token_is_not (parser, CPP_NAME))
9732 c_parser_error (parser, "expected identifier");
9733 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9736 id1 = c_parser_peek_token (parser)->value;
9737 c_parser_consume_token (parser);
9738 if (c_parser_next_token_is_not (parser, CPP_NAME))
9740 c_parser_error (parser, "expected identifier");
9741 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
9744 id2 = c_parser_peek_token (parser)->value;
9745 c_parser_consume_token (parser);
9746 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9747 objc_declare_alias (id1, id2);
9750 /* Parse an objc-protocol-definition.
9752 objc-protocol-definition:
9753 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9754 @protocol identifier-list ;
9756 "@protocol identifier ;" should be resolved as "@protocol
9757 identifier-list ;": objc-methodprotolist may not start with a
9758 semicolon in the first alternative if objc-protocol-refs are
9762 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
9764 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
9766 c_parser_consume_token (parser);
9767 if (c_parser_next_token_is_not (parser, CPP_NAME))
9769 c_parser_error (parser, "expected identifier");
9772 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
9773 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
9775 /* Any identifiers, including those declared as type names, are
9780 if (c_parser_next_token_is_not (parser, CPP_NAME))
9782 c_parser_error (parser, "expected identifier");
9785 id = c_parser_peek_token (parser)->value;
9786 objc_declare_protocol (id, attributes);
9787 c_parser_consume_token (parser);
9788 if (c_parser_next_token_is (parser, CPP_COMMA))
9789 c_parser_consume_token (parser);
9793 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9797 tree id = c_parser_peek_token (parser)->value;
9798 tree proto = NULL_TREE;
9799 c_parser_consume_token (parser);
9800 if (c_parser_next_token_is (parser, CPP_LESS))
9801 proto = c_parser_objc_protocol_refs (parser);
9802 parser->objc_pq_context = true;
9803 objc_start_protocol (id, proto, attributes);
9804 c_parser_objc_methodprotolist (parser);
9805 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
9806 parser->objc_pq_context = false;
9807 objc_finish_interface ();
9811 /* Parse an objc-method-type.
9817 Return true if it is a class method (+) and false if it is
9818 an instance method (-).
9821 c_parser_objc_method_type (c_parser *parser)
9823 switch (c_parser_peek_token (parser)->type)
9826 c_parser_consume_token (parser);
9829 c_parser_consume_token (parser);
9836 /* Parse an objc-method-definition.
9838 objc-method-definition:
9839 objc-method-type objc-method-decl ;[opt] compound-statement
9843 c_parser_objc_method_definition (c_parser *parser)
9845 bool is_class_method = c_parser_objc_method_type (parser);
9846 tree decl, attributes = NULL_TREE, expr = NULL_TREE;
9847 parser->objc_pq_context = true;
9848 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
9850 if (decl == error_mark_node)
9851 return; /* Bail here. */
9853 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9855 c_parser_consume_token (parser);
9856 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9857 "extra semicolon in method definition specified");
9860 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9862 c_parser_error (parser, "expected %<{%>");
9866 parser->objc_pq_context = false;
9867 if (objc_start_method_definition (is_class_method, decl, attributes, expr))
9869 add_stmt (c_parser_compound_statement (parser));
9870 objc_finish_method_definition (current_function_decl);
9874 /* This code is executed when we find a method definition
9875 outside of an @implementation context (or invalid for other
9876 reasons). Parse the method (to keep going) but do not emit
9879 c_parser_compound_statement (parser);
9883 /* Parse an objc-methodprotolist.
9885 objc-methodprotolist:
9887 objc-methodprotolist objc-methodproto
9888 objc-methodprotolist declaration
9889 objc-methodprotolist ;
9893 The declaration is a data definition, which may be missing
9894 declaration specifiers under the same rules and diagnostics as
9895 other data definitions outside functions, and the stray semicolon
9896 is diagnosed the same way as a stray semicolon outside a
9900 c_parser_objc_methodprotolist (c_parser *parser)
9904 /* The list is terminated by @end. */
9905 switch (c_parser_peek_token (parser)->type)
9908 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
9909 "ISO C does not allow extra %<;%> outside of a function");
9910 c_parser_consume_token (parser);
9914 c_parser_objc_methodproto (parser);
9917 c_parser_pragma (parser, pragma_external, NULL);
9922 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
9924 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
9925 c_parser_objc_at_property_declaration (parser);
9926 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
9928 objc_set_method_opt (true);
9929 c_parser_consume_token (parser);
9931 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
9933 objc_set_method_opt (false);
9934 c_parser_consume_token (parser);
9937 c_parser_declaration_or_fndef (parser, false, false, true,
9938 false, true, NULL, vNULL);
9944 /* Parse an objc-methodproto.
9947 objc-method-type objc-method-decl ;
9951 c_parser_objc_methodproto (c_parser *parser)
9953 bool is_class_method = c_parser_objc_method_type (parser);
9954 tree decl, attributes = NULL_TREE;
9956 /* Remember protocol qualifiers in prototypes. */
9957 parser->objc_pq_context = true;
9958 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
9960 /* Forget protocol qualifiers now. */
9961 parser->objc_pq_context = false;
9963 /* Do not allow the presence of attributes to hide an erroneous
9964 method implementation in the interface section. */
9965 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
9967 c_parser_error (parser, "expected %<;%>");
9971 if (decl != error_mark_node)
9972 objc_add_method_declaration (is_class_method, decl, attributes);
9974 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9977 /* If we are at a position that method attributes may be present, check that
9978 there are not any parsed already (a syntax error) and then collect any
9979 specified at the current location. Finally, if new attributes were present,
9980 check that the next token is legal ( ';' for decls and '{' for defs). */
9983 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
9988 c_parser_error (parser,
9989 "method attributes must be specified at the end only");
9990 *attributes = NULL_TREE;
9994 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
9995 *attributes = c_parser_attributes (parser);
9997 /* If there were no attributes here, just report any earlier error. */
9998 if (*attributes == NULL_TREE || bad)
10001 /* If the attributes are followed by a ; or {, then just report any earlier
10003 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
10004 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
10007 /* We've got attributes, but not at the end. */
10008 c_parser_error (parser,
10009 "expected %<;%> or %<{%> after method attribute definition");
10013 /* Parse an objc-method-decl.
10016 ( objc-type-name ) objc-selector
10018 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10019 objc-keyword-selector objc-optparmlist
10022 objc-keyword-selector:
10024 objc-keyword-selector objc-keyword-decl
10027 objc-selector : ( objc-type-name ) identifier
10028 objc-selector : identifier
10029 : ( objc-type-name ) identifier
10033 objc-optparms objc-optellipsis
10037 objc-opt-parms , parameter-declaration
10045 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
10046 tree *attributes, tree *expr)
10048 tree type = NULL_TREE;
10050 tree parms = NULL_TREE;
10051 bool ellipsis = false;
10052 bool attr_err = false;
10054 *attributes = NULL_TREE;
10055 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10057 matching_parens parens;
10058 parens.consume_open (parser);
10059 type = c_parser_objc_type_name (parser);
10060 parens.skip_until_found_close (parser);
10062 sel = c_parser_objc_selector (parser);
10063 /* If there is no selector, or a colon follows, we have an
10064 objc-keyword-selector. If there is a selector, and a colon does
10065 not follow, that selector ends the objc-method-decl. */
10066 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
10069 tree list = NULL_TREE;
10072 tree atype = NULL_TREE, id, keyworddecl;
10073 tree param_attr = NULL_TREE;
10074 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10076 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10078 c_parser_consume_token (parser);
10079 atype = c_parser_objc_type_name (parser);
10080 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
10083 /* New ObjC allows attributes on method parameters. */
10084 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
10085 param_attr = c_parser_attributes (parser);
10086 if (c_parser_next_token_is_not (parser, CPP_NAME))
10088 c_parser_error (parser, "expected identifier");
10089 return error_mark_node;
10091 id = c_parser_peek_token (parser)->value;
10092 c_parser_consume_token (parser);
10093 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
10094 list = chainon (list, keyworddecl);
10095 tsel = c_parser_objc_selector (parser);
10096 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
10100 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
10102 /* Parse the optional parameter list. Optional Objective-C
10103 method parameters follow the C syntax, and may include '...'
10104 to denote a variable number of arguments. */
10105 parms = make_node (TREE_LIST);
10106 while (c_parser_next_token_is (parser, CPP_COMMA))
10108 struct c_parm *parm;
10109 c_parser_consume_token (parser);
10110 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
10113 c_parser_consume_token (parser);
10114 attr_err |= c_parser_objc_maybe_method_attributes
10115 (parser, attributes) ;
10118 parm = c_parser_parameter_declaration (parser, NULL_TREE);
10121 parms = chainon (parms,
10122 build_tree_list (NULL_TREE, grokparm (parm, expr)));
10127 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
10131 c_parser_error (parser, "objective-c method declaration is expected");
10132 return error_mark_node;
10136 return error_mark_node;
10138 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
10141 /* Parse an objc-type-name.
10144 objc-type-qualifiers[opt] type-name
10145 objc-type-qualifiers[opt]
10147 objc-type-qualifiers:
10148 objc-type-qualifier
10149 objc-type-qualifiers objc-type-qualifier
10151 objc-type-qualifier: one of
10152 in out inout bycopy byref oneway
10156 c_parser_objc_type_name (c_parser *parser)
10158 tree quals = NULL_TREE;
10159 struct c_type_name *type_name = NULL;
10160 tree type = NULL_TREE;
10163 c_token *token = c_parser_peek_token (parser);
10164 if (token->type == CPP_KEYWORD
10165 && (token->keyword == RID_IN
10166 || token->keyword == RID_OUT
10167 || token->keyword == RID_INOUT
10168 || token->keyword == RID_BYCOPY
10169 || token->keyword == RID_BYREF
10170 || token->keyword == RID_ONEWAY))
10172 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
10173 c_parser_consume_token (parser);
10178 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
10179 type_name = c_parser_type_name (parser);
10181 type = groktypename (type_name, NULL, NULL);
10183 /* If the type is unknown, and error has already been produced and
10184 we need to recover from the error. In that case, use NULL_TREE
10185 for the type, as if no type had been specified; this will use the
10186 default type ('id') which is good for error recovery. */
10187 if (type == error_mark_node)
10190 return build_tree_list (quals, type);
10193 /* Parse objc-protocol-refs.
10195 objc-protocol-refs:
10196 < identifier-list >
10200 c_parser_objc_protocol_refs (c_parser *parser)
10202 tree list = NULL_TREE;
10203 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
10204 c_parser_consume_token (parser);
10205 /* Any identifiers, including those declared as type names, are OK
10210 if (c_parser_next_token_is_not (parser, CPP_NAME))
10212 c_parser_error (parser, "expected identifier");
10215 id = c_parser_peek_token (parser)->value;
10216 list = chainon (list, build_tree_list (NULL_TREE, id));
10217 c_parser_consume_token (parser);
10218 if (c_parser_next_token_is (parser, CPP_COMMA))
10219 c_parser_consume_token (parser);
10223 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
10227 /* Parse an objc-try-catch-finally-statement.
10229 objc-try-catch-finally-statement:
10230 @try compound-statement objc-catch-list[opt]
10231 @try compound-statement objc-catch-list[opt] @finally compound-statement
10234 @catch ( objc-catch-parameter-declaration ) compound-statement
10235 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10237 objc-catch-parameter-declaration:
10238 parameter-declaration
10241 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10243 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10244 for C++. Keep them in sync. */
10247 c_parser_objc_try_catch_finally_statement (c_parser *parser)
10249 location_t location;
10252 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
10253 c_parser_consume_token (parser);
10254 location = c_parser_peek_token (parser)->location;
10255 objc_maybe_warn_exceptions (location);
10256 stmt = c_parser_compound_statement (parser);
10257 objc_begin_try_stmt (location, stmt);
10259 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
10261 struct c_parm *parm;
10262 tree parameter_declaration = error_mark_node;
10263 bool seen_open_paren = false;
10265 c_parser_consume_token (parser);
10266 matching_parens parens;
10267 if (!parens.require_open (parser))
10268 seen_open_paren = true;
10269 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
10271 /* We have "@catch (...)" (where the '...' are literally
10272 what is in the code). Skip the '...'.
10273 parameter_declaration is set to NULL_TREE, and
10274 objc_being_catch_clauses() knows that that means
10276 c_parser_consume_token (parser);
10277 parameter_declaration = NULL_TREE;
10281 /* We have "@catch (NSException *exception)" or something
10282 like that. Parse the parameter declaration. */
10283 parm = c_parser_parameter_declaration (parser, NULL_TREE);
10285 parameter_declaration = error_mark_node;
10287 parameter_declaration = grokparm (parm, NULL);
10289 if (seen_open_paren)
10290 parens.require_close (parser);
10293 /* If there was no open parenthesis, we are recovering from
10294 an error, and we are trying to figure out what mistake
10295 the user has made. */
10297 /* If there is an immediate closing parenthesis, the user
10298 probably forgot the opening one (ie, they typed "@catch
10299 NSException *e)". Parse the closing parenthesis and keep
10301 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
10302 c_parser_consume_token (parser);
10304 /* If these is no immediate closing parenthesis, the user
10305 probably doesn't know that parenthesis are required at
10306 all (ie, they typed "@catch NSException *e"). So, just
10307 forget about the closing parenthesis and keep going. */
10309 objc_begin_catch_clause (parameter_declaration);
10310 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
10311 c_parser_compound_statement_nostart (parser);
10312 objc_finish_catch_clause ();
10314 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
10316 c_parser_consume_token (parser);
10317 location = c_parser_peek_token (parser)->location;
10318 stmt = c_parser_compound_statement (parser);
10319 objc_build_finally_clause (location, stmt);
10321 objc_finish_try_stmt ();
10324 /* Parse an objc-synchronized-statement.
10326 objc-synchronized-statement:
10327 @synchronized ( expression ) compound-statement
10331 c_parser_objc_synchronized_statement (c_parser *parser)
10335 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
10336 c_parser_consume_token (parser);
10337 loc = c_parser_peek_token (parser)->location;
10338 objc_maybe_warn_exceptions (loc);
10339 matching_parens parens;
10340 if (parens.require_open (parser))
10342 struct c_expr ce = c_parser_expression (parser);
10343 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
10345 expr = c_fully_fold (expr, false, NULL);
10346 parens.skip_until_found_close (parser);
10349 expr = error_mark_node;
10350 stmt = c_parser_compound_statement (parser);
10351 objc_build_synchronized (loc, expr, stmt);
10354 /* Parse an objc-selector; return NULL_TREE without an error if the
10355 next token is not an objc-selector.
10360 enum struct union if else while do for switch case default
10361 break continue return goto asm sizeof typeof __alignof
10362 unsigned long const short volatile signed restrict _Complex
10363 in out inout bycopy byref oneway int char float double void _Bool
10366 ??? Why this selection of keywords but not, for example, storage
10367 class specifiers? */
10370 c_parser_objc_selector (c_parser *parser)
10372 c_token *token = c_parser_peek_token (parser);
10373 tree value = token->value;
10374 if (token->type == CPP_NAME)
10376 c_parser_consume_token (parser);
10379 if (token->type != CPP_KEYWORD)
10381 switch (token->keyword)
10420 CASE_RID_FLOATN_NX:
10424 case RID_AUTO_TYPE:
10429 c_parser_consume_token (parser);
10436 /* Parse an objc-selector-arg.
10440 objc-keywordname-list
10442 objc-keywordname-list:
10444 objc-keywordname-list objc-keywordname
10452 c_parser_objc_selector_arg (c_parser *parser)
10454 tree sel = c_parser_objc_selector (parser);
10455 tree list = NULL_TREE;
10456 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
10460 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10462 list = chainon (list, build_tree_list (sel, NULL_TREE));
10463 sel = c_parser_objc_selector (parser);
10464 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
10470 /* Parse an objc-receiver.
10479 c_parser_objc_receiver (c_parser *parser)
10481 location_t loc = c_parser_peek_token (parser)->location;
10483 if (c_parser_peek_token (parser)->type == CPP_NAME
10484 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
10485 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
10487 tree id = c_parser_peek_token (parser)->value;
10488 c_parser_consume_token (parser);
10489 return objc_get_class_reference (id);
10491 struct c_expr ce = c_parser_expression (parser);
10492 ce = convert_lvalue_to_rvalue (loc, ce, false, false);
10493 return c_fully_fold (ce.value, false, NULL);
10496 /* Parse objc-message-args.
10500 objc-keywordarg-list
10502 objc-keywordarg-list:
10504 objc-keywordarg-list objc-keywordarg
10507 objc-selector : objc-keywordexpr
10512 c_parser_objc_message_args (c_parser *parser)
10514 tree sel = c_parser_objc_selector (parser);
10515 tree list = NULL_TREE;
10516 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
10521 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
10522 return error_mark_node;
10523 keywordexpr = c_parser_objc_keywordexpr (parser);
10524 list = chainon (list, build_tree_list (sel, keywordexpr));
10525 sel = c_parser_objc_selector (parser);
10526 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
10532 /* Parse an objc-keywordexpr.
10539 c_parser_objc_keywordexpr (c_parser *parser)
10542 vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true,
10543 NULL, NULL, NULL, NULL);
10544 if (vec_safe_length (expr_list) == 1)
10546 /* Just return the expression, remove a level of
10548 ret = (*expr_list)[0];
10552 /* We have a comma expression, we will collapse later. */
10553 ret = build_tree_list_vec (expr_list);
10555 release_tree_vector (expr_list);
10559 /* A check, needed in several places, that ObjC interface, implementation or
10560 method definitions are not prefixed by incorrect items. */
10562 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
10563 struct c_declspecs *specs)
10565 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
10566 || specs->typespec_kind != ctsk_none)
10568 c_parser_error (parser,
10569 "no type or storage class may be specified here,");
10570 c_parser_skip_to_end_of_block_or_statement (parser);
10576 /* Parse an Objective-C @property declaration. The syntax is:
10578 objc-property-declaration:
10579 '@property' objc-property-attributes[opt] struct-declaration ;
10581 objc-property-attributes:
10582 '(' objc-property-attribute-list ')'
10584 objc-property-attribute-list:
10585 objc-property-attribute
10586 objc-property-attribute-list, objc-property-attribute
10588 objc-property-attribute
10589 'getter' = identifier
10590 'setter' = identifier
10599 @property NSString *name;
10600 @property (readonly) id object;
10601 @property (retain, nonatomic, getter=getTheName) id name;
10602 @property int a, b, c;
10604 PS: This function is identical to cp_parser_objc_at_propery_declaration
10605 for C++. Keep them in sync. */
10607 c_parser_objc_at_property_declaration (c_parser *parser)
10609 /* The following variables hold the attributes of the properties as
10610 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10611 seen. When we see an attribute, we set them to 'true' (if they
10612 are boolean properties) or to the identifier (if they have an
10613 argument, ie, for getter and setter). Note that here we only
10614 parse the list of attributes, check the syntax and accumulate the
10615 attributes that we find. objc_add_property_declaration() will
10616 then process the information. */
10617 bool property_assign = false;
10618 bool property_copy = false;
10619 tree property_getter_ident = NULL_TREE;
10620 bool property_nonatomic = false;
10621 bool property_readonly = false;
10622 bool property_readwrite = false;
10623 bool property_retain = false;
10624 tree property_setter_ident = NULL_TREE;
10626 /* 'properties' is the list of properties that we read. Usually a
10627 single one, but maybe more (eg, in "@property int a, b, c;" there
10632 loc = c_parser_peek_token (parser)->location;
10633 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
10635 c_parser_consume_token (parser); /* Eat '@property'. */
10637 /* Parse the optional attribute list... */
10638 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
10640 matching_parens parens;
10643 parens.consume_open (parser);
10645 /* Property attribute keywords are valid now. */
10646 parser->objc_property_attr_context = true;
10650 bool syntax_error = false;
10651 c_token *token = c_parser_peek_token (parser);
10654 if (token->type != CPP_KEYWORD)
10656 if (token->type == CPP_CLOSE_PAREN)
10657 c_parser_error (parser, "expected identifier");
10660 c_parser_consume_token (parser);
10661 c_parser_error (parser, "unknown property attribute");
10665 keyword = token->keyword;
10666 c_parser_consume_token (parser);
10669 case RID_ASSIGN: property_assign = true; break;
10670 case RID_COPY: property_copy = true; break;
10671 case RID_NONATOMIC: property_nonatomic = true; break;
10672 case RID_READONLY: property_readonly = true; break;
10673 case RID_READWRITE: property_readwrite = true; break;
10674 case RID_RETAIN: property_retain = true; break;
10678 if (c_parser_next_token_is_not (parser, CPP_EQ))
10680 if (keyword == RID_GETTER)
10681 c_parser_error (parser,
10682 "missing %<=%> (after %<getter%> attribute)");
10684 c_parser_error (parser,
10685 "missing %<=%> (after %<setter%> attribute)");
10686 syntax_error = true;
10689 c_parser_consume_token (parser); /* eat the = */
10690 if (c_parser_next_token_is_not (parser, CPP_NAME))
10692 c_parser_error (parser, "expected identifier");
10693 syntax_error = true;
10696 if (keyword == RID_SETTER)
10698 if (property_setter_ident != NULL_TREE)
10699 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
10701 property_setter_ident = c_parser_peek_token (parser)->value;
10702 c_parser_consume_token (parser);
10703 if (c_parser_next_token_is_not (parser, CPP_COLON))
10704 c_parser_error (parser, "setter name must terminate with %<:%>");
10706 c_parser_consume_token (parser);
10710 if (property_getter_ident != NULL_TREE)
10711 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
10713 property_getter_ident = c_parser_peek_token (parser)->value;
10714 c_parser_consume_token (parser);
10718 c_parser_error (parser, "unknown property attribute");
10719 syntax_error = true;
10726 if (c_parser_next_token_is (parser, CPP_COMMA))
10727 c_parser_consume_token (parser);
10731 parser->objc_property_attr_context = false;
10732 parens.skip_until_found_close (parser);
10734 /* ... and the property declaration(s). */
10735 properties = c_parser_struct_declaration (parser);
10737 if (properties == error_mark_node)
10739 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10740 parser->error = false;
10744 if (properties == NULL_TREE)
10745 c_parser_error (parser, "expected identifier");
10748 /* Comma-separated properties are chained together in
10749 reverse order; add them one by one. */
10750 properties = nreverse (properties);
10752 for (; properties; properties = TREE_CHAIN (properties))
10753 objc_add_property_declaration (loc, copy_node (properties),
10754 property_readonly, property_readwrite,
10755 property_assign, property_retain,
10756 property_copy, property_nonatomic,
10757 property_getter_ident, property_setter_ident);
10760 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10761 parser->error = false;
10764 /* Parse an Objective-C @synthesize declaration. The syntax is:
10766 objc-synthesize-declaration:
10767 @synthesize objc-synthesize-identifier-list ;
10769 objc-synthesize-identifier-list:
10770 objc-synthesize-identifier
10771 objc-synthesize-identifier-list, objc-synthesize-identifier
10773 objc-synthesize-identifier
10775 identifier = identifier
10778 @synthesize MyProperty;
10779 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10781 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10782 for C++. Keep them in sync.
10785 c_parser_objc_at_synthesize_declaration (c_parser *parser)
10787 tree list = NULL_TREE;
10789 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
10790 loc = c_parser_peek_token (parser)->location;
10792 c_parser_consume_token (parser);
10795 tree property, ivar;
10796 if (c_parser_next_token_is_not (parser, CPP_NAME))
10798 c_parser_error (parser, "expected identifier");
10799 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10800 /* Once we find the semicolon, we can resume normal parsing.
10801 We have to reset parser->error manually because
10802 c_parser_skip_until_found() won't reset it for us if the
10803 next token is precisely a semicolon. */
10804 parser->error = false;
10807 property = c_parser_peek_token (parser)->value;
10808 c_parser_consume_token (parser);
10809 if (c_parser_next_token_is (parser, CPP_EQ))
10811 c_parser_consume_token (parser);
10812 if (c_parser_next_token_is_not (parser, CPP_NAME))
10814 c_parser_error (parser, "expected identifier");
10815 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10816 parser->error = false;
10819 ivar = c_parser_peek_token (parser)->value;
10820 c_parser_consume_token (parser);
10824 list = chainon (list, build_tree_list (ivar, property));
10825 if (c_parser_next_token_is (parser, CPP_COMMA))
10826 c_parser_consume_token (parser);
10830 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10831 objc_add_synthesize_declaration (loc, list);
10834 /* Parse an Objective-C @dynamic declaration. The syntax is:
10836 objc-dynamic-declaration:
10837 @dynamic identifier-list ;
10840 @dynamic MyProperty;
10841 @dynamic MyProperty, AnotherProperty;
10843 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10844 for C++. Keep them in sync.
10847 c_parser_objc_at_dynamic_declaration (c_parser *parser)
10849 tree list = NULL_TREE;
10851 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
10852 loc = c_parser_peek_token (parser)->location;
10854 c_parser_consume_token (parser);
10858 if (c_parser_next_token_is_not (parser, CPP_NAME))
10860 c_parser_error (parser, "expected identifier");
10861 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
10862 parser->error = false;
10865 property = c_parser_peek_token (parser)->value;
10866 list = chainon (list, build_tree_list (NULL_TREE, property));
10867 c_parser_consume_token (parser);
10868 if (c_parser_next_token_is (parser, CPP_COMMA))
10869 c_parser_consume_token (parser);
10873 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
10874 objc_add_dynamic_declaration (loc, list);
10878 /* Parse a pragma GCC ivdep. */
10881 c_parse_pragma_ivdep (c_parser *parser)
10883 c_parser_consume_pragma (parser);
10884 c_parser_skip_to_pragma_eol (parser);
10888 /* Parse a pragma GCC unroll. */
10890 static unsigned short
10891 c_parser_pragma_unroll (c_parser *parser)
10893 unsigned short unroll;
10894 c_parser_consume_pragma (parser);
10895 location_t location = c_parser_peek_token (parser)->location;
10896 tree expr = c_parser_expr_no_commas (parser, NULL).value;
10897 mark_exp_read (expr);
10898 expr = c_fully_fold (expr, false, NULL);
10899 HOST_WIDE_INT lunroll = 0;
10900 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
10901 || TREE_CODE (expr) != INTEGER_CST
10902 || (lunroll = tree_to_shwi (expr)) < 0
10903 || lunroll >= USHRT_MAX)
10905 error_at (location, "%<#pragma GCC unroll%> requires an"
10906 " assignment-expression that evaluates to a non-negative"
10907 " integral constant less than %u", USHRT_MAX);
10912 unroll = (unsigned short)lunroll;
10917 c_parser_skip_to_pragma_eol (parser);
10921 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10922 should be considered, statements. ALLOW_STMT is true if we're within
10923 the context of a function and such pragmas are to be allowed. Returns
10924 true if we actually parsed such a pragma. */
10927 c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p)
10930 const char *construct = NULL;
10932 id = c_parser_peek_token (parser)->pragma_kind;
10933 gcc_assert (id != PRAGMA_NONE);
10937 case PRAGMA_OACC_DECLARE:
10938 c_parser_oacc_declare (parser);
10941 case PRAGMA_OACC_ENTER_DATA:
10942 if (context != pragma_compound)
10944 construct = "acc enter data";
10946 if (context == pragma_stmt)
10948 error_at (c_parser_peek_token (parser)->location,
10949 "%<#pragma %s%> may only be used in compound "
10950 "statements", construct);
10951 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10956 c_parser_oacc_enter_exit_data (parser, true);
10959 case PRAGMA_OACC_EXIT_DATA:
10960 if (context != pragma_compound)
10962 construct = "acc exit data";
10965 c_parser_oacc_enter_exit_data (parser, false);
10968 case PRAGMA_OACC_ROUTINE:
10969 if (context != pragma_external)
10971 error_at (c_parser_peek_token (parser)->location,
10972 "%<#pragma acc routine%> must be at file scope");
10973 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
10976 c_parser_oacc_routine (parser, context);
10979 case PRAGMA_OACC_UPDATE:
10980 if (context != pragma_compound)
10982 construct = "acc update";
10985 c_parser_oacc_update (parser);
10988 case PRAGMA_OMP_BARRIER:
10989 if (context != pragma_compound)
10991 construct = "omp barrier";
10994 c_parser_omp_barrier (parser);
10997 case PRAGMA_OMP_FLUSH:
10998 if (context != pragma_compound)
11000 construct = "omp flush";
11003 c_parser_omp_flush (parser);
11006 case PRAGMA_OMP_TASKWAIT:
11007 if (context != pragma_compound)
11009 construct = "omp taskwait";
11012 c_parser_omp_taskwait (parser);
11015 case PRAGMA_OMP_TASKYIELD:
11016 if (context != pragma_compound)
11018 construct = "omp taskyield";
11021 c_parser_omp_taskyield (parser);
11024 case PRAGMA_OMP_CANCEL:
11025 if (context != pragma_compound)
11027 construct = "omp cancel";
11030 c_parser_omp_cancel (parser);
11033 case PRAGMA_OMP_CANCELLATION_POINT:
11034 c_parser_omp_cancellation_point (parser, context);
11037 case PRAGMA_OMP_THREADPRIVATE:
11038 c_parser_omp_threadprivate (parser);
11041 case PRAGMA_OMP_TARGET:
11042 return c_parser_omp_target (parser, context, if_p);
11044 case PRAGMA_OMP_END_DECLARE_TARGET:
11045 c_parser_omp_end_declare_target (parser);
11048 case PRAGMA_OMP_SECTION:
11049 error_at (c_parser_peek_token (parser)->location,
11050 "%<#pragma omp section%> may only be used in "
11051 "%<#pragma omp sections%> construct");
11052 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
11055 case PRAGMA_OMP_DECLARE:
11056 c_parser_omp_declare (parser, context);
11059 case PRAGMA_OMP_ORDERED:
11060 return c_parser_omp_ordered (parser, context, if_p);
11064 const bool ivdep = c_parse_pragma_ivdep (parser);
11065 unsigned short unroll;
11066 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_UNROLL)
11067 unroll = c_parser_pragma_unroll (parser);
11070 if (!c_parser_next_token_is_keyword (parser, RID_FOR)
11071 && !c_parser_next_token_is_keyword (parser, RID_WHILE)
11072 && !c_parser_next_token_is_keyword (parser, RID_DO))
11074 c_parser_error (parser, "for, while or do statement expected");
11077 if (c_parser_next_token_is_keyword (parser, RID_FOR))
11078 c_parser_for_statement (parser, ivdep, unroll, if_p);
11079 else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
11080 c_parser_while_statement (parser, ivdep, unroll, if_p);
11082 c_parser_do_statement (parser, ivdep, unroll);
11086 case PRAGMA_UNROLL:
11088 unsigned short unroll = c_parser_pragma_unroll (parser);
11090 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_IVDEP)
11091 ivdep = c_parse_pragma_ivdep (parser);
11094 if (!c_parser_next_token_is_keyword (parser, RID_FOR)
11095 && !c_parser_next_token_is_keyword (parser, RID_WHILE)
11096 && !c_parser_next_token_is_keyword (parser, RID_DO))
11098 c_parser_error (parser, "for, while or do statement expected");
11101 if (c_parser_next_token_is_keyword (parser, RID_FOR))
11102 c_parser_for_statement (parser, ivdep, unroll, if_p);
11103 else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
11104 c_parser_while_statement (parser, ivdep, unroll, if_p);
11106 c_parser_do_statement (parser, ivdep, unroll);
11110 case PRAGMA_GCC_PCH_PREPROCESS:
11111 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
11112 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
11115 case PRAGMA_OACC_WAIT:
11116 if (context != pragma_compound)
11118 construct = "acc wait";
11121 /* FALL THROUGH. */
11124 if (id < PRAGMA_FIRST_EXTERNAL)
11126 if (context != pragma_stmt && context != pragma_compound)
11129 c_parser_error (parser, "expected declaration specifiers");
11130 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
11133 c_parser_omp_construct (parser, if_p);
11139 c_parser_consume_pragma (parser);
11140 c_invoke_pragma_handler (id);
11142 /* Skip to EOL, but suppress any error message. Those will have been
11143 generated by the handler routine through calling error, as opposed
11144 to calling c_parser_error. */
11145 parser->error = true;
11146 c_parser_skip_to_pragma_eol (parser);
11151 /* The interface the pragma parsers have to the lexer. */
11154 pragma_lex (tree *value, location_t *loc)
11156 c_token *tok = c_parser_peek_token (the_parser);
11157 enum cpp_ttype ret = tok->type;
11159 *value = tok->value;
11161 *loc = tok->location;
11163 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
11167 if (ret == CPP_KEYWORD)
11169 c_parser_consume_token (the_parser);
11176 c_parser_pragma_pch_preprocess (c_parser *parser)
11180 c_parser_consume_pragma (parser);
11181 if (c_parser_next_token_is (parser, CPP_STRING))
11183 name = c_parser_peek_token (parser)->value;
11184 c_parser_consume_token (parser);
11187 c_parser_error (parser, "expected string literal");
11188 c_parser_skip_to_pragma_eol (parser);
11191 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
11194 /* OpenACC and OpenMP parsing routines. */
11196 /* Returns name of the next clause.
11197 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11198 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11199 returned and the token is consumed. */
11201 static pragma_omp_clause
11202 c_parser_omp_clause_name (c_parser *parser)
11204 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
11206 if (c_parser_next_token_is_keyword (parser, RID_AUTO))
11207 result = PRAGMA_OACC_CLAUSE_AUTO;
11208 else if (c_parser_next_token_is_keyword (parser, RID_IF))
11209 result = PRAGMA_OMP_CLAUSE_IF;
11210 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
11211 result = PRAGMA_OMP_CLAUSE_DEFAULT;
11212 else if (c_parser_next_token_is_keyword (parser, RID_FOR))
11213 result = PRAGMA_OMP_CLAUSE_FOR;
11214 else if (c_parser_next_token_is (parser, CPP_NAME))
11216 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11221 if (!strcmp ("aligned", p))
11222 result = PRAGMA_OMP_CLAUSE_ALIGNED;
11223 else if (!strcmp ("async", p))
11224 result = PRAGMA_OACC_CLAUSE_ASYNC;
11227 if (!strcmp ("collapse", p))
11228 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
11229 else if (!strcmp ("copy", p))
11230 result = PRAGMA_OACC_CLAUSE_COPY;
11231 else if (!strcmp ("copyin", p))
11232 result = PRAGMA_OMP_CLAUSE_COPYIN;
11233 else if (!strcmp ("copyout", p))
11234 result = PRAGMA_OACC_CLAUSE_COPYOUT;
11235 else if (!strcmp ("copyprivate", p))
11236 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
11237 else if (!strcmp ("create", p))
11238 result = PRAGMA_OACC_CLAUSE_CREATE;
11241 if (!strcmp ("defaultmap", p))
11242 result = PRAGMA_OMP_CLAUSE_DEFAULTMAP;
11243 else if (!strcmp ("delete", p))
11244 result = PRAGMA_OACC_CLAUSE_DELETE;
11245 else if (!strcmp ("depend", p))
11246 result = PRAGMA_OMP_CLAUSE_DEPEND;
11247 else if (!strcmp ("device", p))
11248 result = PRAGMA_OMP_CLAUSE_DEVICE;
11249 else if (!strcmp ("deviceptr", p))
11250 result = PRAGMA_OACC_CLAUSE_DEVICEPTR;
11251 else if (!strcmp ("device_resident", p))
11252 result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT;
11253 else if (!strcmp ("dist_schedule", p))
11254 result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
11257 if (!strcmp ("final", p))
11258 result = PRAGMA_OMP_CLAUSE_FINAL;
11259 else if (!strcmp ("firstprivate", p))
11260 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
11261 else if (!strcmp ("from", p))
11262 result = PRAGMA_OMP_CLAUSE_FROM;
11265 if (!strcmp ("gang", p))
11266 result = PRAGMA_OACC_CLAUSE_GANG;
11267 else if (!strcmp ("grainsize", p))
11268 result = PRAGMA_OMP_CLAUSE_GRAINSIZE;
11271 if (!strcmp ("hint", p))
11272 result = PRAGMA_OMP_CLAUSE_HINT;
11273 else if (!strcmp ("host", p))
11274 result = PRAGMA_OACC_CLAUSE_HOST;
11277 if (!strcmp ("inbranch", p))
11278 result = PRAGMA_OMP_CLAUSE_INBRANCH;
11279 else if (!strcmp ("independent", p))
11280 result = PRAGMA_OACC_CLAUSE_INDEPENDENT;
11281 else if (!strcmp ("is_device_ptr", p))
11282 result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR;
11285 if (!strcmp ("lastprivate", p))
11286 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
11287 else if (!strcmp ("linear", p))
11288 result = PRAGMA_OMP_CLAUSE_LINEAR;
11289 else if (!strcmp ("link", p))
11290 result = PRAGMA_OMP_CLAUSE_LINK;
11293 if (!strcmp ("map", p))
11294 result = PRAGMA_OMP_CLAUSE_MAP;
11295 else if (!strcmp ("mergeable", p))
11296 result = PRAGMA_OMP_CLAUSE_MERGEABLE;
11299 if (!strcmp ("nogroup", p))
11300 result = PRAGMA_OMP_CLAUSE_NOGROUP;
11301 else if (!strcmp ("notinbranch", p))
11302 result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
11303 else if (!strcmp ("nowait", p))
11304 result = PRAGMA_OMP_CLAUSE_NOWAIT;
11305 else if (!strcmp ("num_gangs", p))
11306 result = PRAGMA_OACC_CLAUSE_NUM_GANGS;
11307 else if (!strcmp ("num_tasks", p))
11308 result = PRAGMA_OMP_CLAUSE_NUM_TASKS;
11309 else if (!strcmp ("num_teams", p))
11310 result = PRAGMA_OMP_CLAUSE_NUM_TEAMS;
11311 else if (!strcmp ("num_threads", p))
11312 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
11313 else if (!strcmp ("num_workers", p))
11314 result = PRAGMA_OACC_CLAUSE_NUM_WORKERS;
11317 if (!strcmp ("ordered", p))
11318 result = PRAGMA_OMP_CLAUSE_ORDERED;
11321 if (!strcmp ("parallel", p))
11322 result = PRAGMA_OMP_CLAUSE_PARALLEL;
11323 else if (!strcmp ("present", p))
11324 result = PRAGMA_OACC_CLAUSE_PRESENT;
11325 else if (!strcmp ("present_or_copy", p)
11326 || !strcmp ("pcopy", p))
11327 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
11328 else if (!strcmp ("present_or_copyin", p)
11329 || !strcmp ("pcopyin", p))
11330 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
11331 else if (!strcmp ("present_or_copyout", p)
11332 || !strcmp ("pcopyout", p))
11333 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
11334 else if (!strcmp ("present_or_create", p)
11335 || !strcmp ("pcreate", p))
11336 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
11337 else if (!strcmp ("priority", p))
11338 result = PRAGMA_OMP_CLAUSE_PRIORITY;
11339 else if (!strcmp ("private", p))
11340 result = PRAGMA_OMP_CLAUSE_PRIVATE;
11341 else if (!strcmp ("proc_bind", p))
11342 result = PRAGMA_OMP_CLAUSE_PROC_BIND;
11345 if (!strcmp ("reduction", p))
11346 result = PRAGMA_OMP_CLAUSE_REDUCTION;
11349 if (!strcmp ("safelen", p))
11350 result = PRAGMA_OMP_CLAUSE_SAFELEN;
11351 else if (!strcmp ("schedule", p))
11352 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
11353 else if (!strcmp ("sections", p))
11354 result = PRAGMA_OMP_CLAUSE_SECTIONS;
11355 else if (!strcmp ("seq", p))
11356 result = PRAGMA_OACC_CLAUSE_SEQ;
11357 else if (!strcmp ("shared", p))
11358 result = PRAGMA_OMP_CLAUSE_SHARED;
11359 else if (!strcmp ("simd", p))
11360 result = PRAGMA_OMP_CLAUSE_SIMD;
11361 else if (!strcmp ("simdlen", p))
11362 result = PRAGMA_OMP_CLAUSE_SIMDLEN;
11363 else if (!strcmp ("self", p))
11364 result = PRAGMA_OACC_CLAUSE_SELF;
11367 if (!strcmp ("taskgroup", p))
11368 result = PRAGMA_OMP_CLAUSE_TASKGROUP;
11369 else if (!strcmp ("thread_limit", p))
11370 result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
11371 else if (!strcmp ("threads", p))
11372 result = PRAGMA_OMP_CLAUSE_THREADS;
11373 else if (!strcmp ("tile", p))
11374 result = PRAGMA_OACC_CLAUSE_TILE;
11375 else if (!strcmp ("to", p))
11376 result = PRAGMA_OMP_CLAUSE_TO;
11379 if (!strcmp ("uniform", p))
11380 result = PRAGMA_OMP_CLAUSE_UNIFORM;
11381 else if (!strcmp ("untied", p))
11382 result = PRAGMA_OMP_CLAUSE_UNTIED;
11383 else if (!strcmp ("use_device", p))
11384 result = PRAGMA_OACC_CLAUSE_USE_DEVICE;
11385 else if (!strcmp ("use_device_ptr", p))
11386 result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR;
11389 if (!strcmp ("vector", p))
11390 result = PRAGMA_OACC_CLAUSE_VECTOR;
11391 else if (!strcmp ("vector_length", p))
11392 result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH;
11395 if (!strcmp ("wait", p))
11396 result = PRAGMA_OACC_CLAUSE_WAIT;
11397 else if (!strcmp ("worker", p))
11398 result = PRAGMA_OACC_CLAUSE_WORKER;
11403 if (result != PRAGMA_OMP_CLAUSE_NONE)
11404 c_parser_consume_token (parser);
11409 /* Validate that a clause of the given type does not already exist. */
11412 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
11417 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11418 if (OMP_CLAUSE_CODE (c) == code)
11420 location_t loc = OMP_CLAUSE_LOCATION (c);
11421 error_at (loc, "too many %qs clauses", name);
11427 Parse wait clause or wait directive parameters. */
11430 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list)
11432 vec<tree, va_gc> *args;
11435 matching_parens parens;
11436 if (!parens.require_open (parser))
11439 args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
11441 if (args->length () == 0)
11443 c_parser_error (parser, "expected integer expression before ')'");
11444 release_tree_vector (args);
11448 args_tree = build_tree_list_vec (args);
11450 for (t = args_tree; t; t = TREE_CHAIN (t))
11452 tree targ = TREE_VALUE (t);
11454 if (targ != error_mark_node)
11456 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ)))
11458 c_parser_error (parser, "expression must be integral");
11459 targ = error_mark_node;
11463 tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT);
11465 OMP_CLAUSE_DECL (c) = targ;
11466 OMP_CLAUSE_CHAIN (c) = list;
11472 release_tree_vector (args);
11473 parens.require_close (parser);
11477 /* OpenACC 2.0, OpenMP 2.5:
11480 variable-list , identifier
11482 If KIND is nonzero, create the appropriate node and install the
11483 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11484 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11486 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11487 return the list created. */
11490 c_parser_omp_variable_list (c_parser *parser,
11491 location_t clause_loc,
11492 enum omp_clause_code kind, tree list)
11494 if (c_parser_next_token_is_not (parser, CPP_NAME)
11495 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
11496 c_parser_error (parser, "expected identifier");
11498 while (c_parser_next_token_is (parser, CPP_NAME)
11499 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
11501 tree t = lookup_name (c_parser_peek_token (parser)->value);
11503 if (t == NULL_TREE)
11505 undeclared_variable (c_parser_peek_token (parser)->location,
11506 c_parser_peek_token (parser)->value);
11507 t = error_mark_node;
11510 c_parser_consume_token (parser);
11512 if (t == error_mark_node)
11514 else if (kind != 0)
11518 case OMP_CLAUSE__CACHE_:
11519 /* The OpenACC cache directive explicitly only allows "array
11520 elements or subarrays". */
11521 if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
11523 c_parser_error (parser, "expected %<[%>");
11524 t = error_mark_node;
11528 case OMP_CLAUSE_MAP:
11529 case OMP_CLAUSE_FROM:
11530 case OMP_CLAUSE_TO:
11531 while (c_parser_next_token_is (parser, CPP_DOT))
11533 location_t op_loc = c_parser_peek_token (parser)->location;
11534 c_parser_consume_token (parser);
11535 if (!c_parser_next_token_is (parser, CPP_NAME))
11537 c_parser_error (parser, "expected identifier");
11538 t = error_mark_node;
11542 c_token *comp_tok = c_parser_peek_token (parser);
11543 tree ident = comp_tok->value;
11544 location_t comp_loc = comp_tok->location;
11545 c_parser_consume_token (parser);
11546 t = build_component_ref (op_loc, t, ident, comp_loc);
11549 case OMP_CLAUSE_DEPEND:
11550 case OMP_CLAUSE_REDUCTION:
11551 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
11553 tree low_bound = NULL_TREE, length = NULL_TREE;
11555 c_parser_consume_token (parser);
11556 if (!c_parser_next_token_is (parser, CPP_COLON))
11558 location_t expr_loc
11559 = c_parser_peek_token (parser)->location;
11560 c_expr expr = c_parser_expression (parser);
11561 expr = convert_lvalue_to_rvalue (expr_loc, expr,
11563 low_bound = expr.value;
11565 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
11566 length = integer_one_node;
11569 /* Look for `:'. */
11570 if (!c_parser_require (parser, CPP_COLON,
11573 t = error_mark_node;
11576 if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
11578 location_t expr_loc
11579 = c_parser_peek_token (parser)->location;
11580 c_expr expr = c_parser_expression (parser);
11581 expr = convert_lvalue_to_rvalue (expr_loc, expr,
11583 length = expr.value;
11586 /* Look for the closing `]'. */
11587 if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
11590 t = error_mark_node;
11594 t = tree_cons (low_bound, length, t);
11601 if (t != error_mark_node)
11603 tree u = build_omp_clause (clause_loc, kind);
11604 OMP_CLAUSE_DECL (u) = t;
11605 OMP_CLAUSE_CHAIN (u) = list;
11610 list = tree_cons (t, NULL_TREE, list);
11612 if (c_parser_next_token_is_not (parser, CPP_COMMA))
11615 c_parser_consume_token (parser);
11621 /* Similarly, but expect leading and trailing parenthesis. This is a very
11622 common case for OpenACC and OpenMP clauses. */
11625 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
11628 /* The clauses location. */
11629 location_t loc = c_parser_peek_token (parser)->location;
11631 matching_parens parens;
11632 if (parens.require_open (parser))
11634 list = c_parser_omp_variable_list (parser, loc, kind, list);
11635 parens.skip_until_found_close (parser);
11641 copy ( variable-list )
11642 copyin ( variable-list )
11643 copyout ( variable-list )
11644 create ( variable-list )
11645 delete ( variable-list )
11646 present ( variable-list )
11647 present_or_copy ( variable-list )
11648 pcopy ( variable-list )
11649 present_or_copyin ( variable-list )
11650 pcopyin ( variable-list )
11651 present_or_copyout ( variable-list )
11652 pcopyout ( variable-list )
11653 present_or_create ( variable-list )
11654 pcreate ( variable-list ) */
11657 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
11660 enum gomp_map_kind kind;
11663 case PRAGMA_OACC_CLAUSE_COPY:
11664 kind = GOMP_MAP_FORCE_TOFROM;
11666 case PRAGMA_OACC_CLAUSE_COPYIN:
11667 kind = GOMP_MAP_FORCE_TO;
11669 case PRAGMA_OACC_CLAUSE_COPYOUT:
11670 kind = GOMP_MAP_FORCE_FROM;
11672 case PRAGMA_OACC_CLAUSE_CREATE:
11673 kind = GOMP_MAP_FORCE_ALLOC;
11675 case PRAGMA_OACC_CLAUSE_DELETE:
11676 kind = GOMP_MAP_DELETE;
11678 case PRAGMA_OACC_CLAUSE_DEVICE:
11679 kind = GOMP_MAP_FORCE_TO;
11681 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
11682 kind = GOMP_MAP_DEVICE_RESIDENT;
11684 case PRAGMA_OACC_CLAUSE_HOST:
11685 case PRAGMA_OACC_CLAUSE_SELF:
11686 kind = GOMP_MAP_FORCE_FROM;
11688 case PRAGMA_OACC_CLAUSE_LINK:
11689 kind = GOMP_MAP_LINK;
11691 case PRAGMA_OACC_CLAUSE_PRESENT:
11692 kind = GOMP_MAP_FORCE_PRESENT;
11694 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
11695 kind = GOMP_MAP_TOFROM;
11697 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
11698 kind = GOMP_MAP_TO;
11700 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
11701 kind = GOMP_MAP_FROM;
11703 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
11704 kind = GOMP_MAP_ALLOC;
11707 gcc_unreachable ();
11710 nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list);
11712 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
11713 OMP_CLAUSE_SET_MAP_KIND (c, kind);
11719 deviceptr ( variable-list ) */
11722 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list)
11724 location_t loc = c_parser_peek_token (parser)->location;
11727 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11728 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11729 variable-list must only allow for pointer variables. */
11730 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
11731 for (t = vars; t && t; t = TREE_CHAIN (t))
11733 tree v = TREE_PURPOSE (t);
11735 /* FIXME diagnostics: Ideally we should keep individual
11736 locations for all the variables in the var list to make the
11737 following errors more precise. Perhaps
11738 c_parser_omp_var_list_parens() should construct a list of
11739 locations to go along with the var list. */
11741 if (!VAR_P (v) && TREE_CODE (v) != PARM_DECL)
11742 error_at (loc, "%qD is not a variable", v);
11743 else if (TREE_TYPE (v) == error_mark_node)
11745 else if (!POINTER_TYPE_P (TREE_TYPE (v)))
11746 error_at (loc, "%qD is not a pointer variable", v);
11748 tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
11749 OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
11750 OMP_CLAUSE_DECL (u) = v;
11751 OMP_CLAUSE_CHAIN (u) = list;
11758 /* OpenACC 2.0, OpenMP 3.0:
11759 collapse ( constant-expression ) */
11762 c_parser_omp_clause_collapse (c_parser *parser, tree list)
11764 tree c, num = error_mark_node;
11768 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
11769 check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
11771 loc = c_parser_peek_token (parser)->location;
11772 matching_parens parens;
11773 if (parens.require_open (parser))
11775 num = c_parser_expr_no_commas (parser, NULL).value;
11776 parens.skip_until_found_close (parser);
11778 if (num == error_mark_node)
11780 mark_exp_read (num);
11781 num = c_fully_fold (num, false, NULL);
11782 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
11783 || !tree_fits_shwi_p (num)
11784 || (n = tree_to_shwi (num)) <= 0
11788 "collapse argument needs positive constant integer expression");
11791 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
11792 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
11793 OMP_CLAUSE_CHAIN (c) = list;
11798 copyin ( variable-list ) */
11801 c_parser_omp_clause_copyin (c_parser *parser, tree list)
11803 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
11807 copyprivate ( variable-list ) */
11810 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
11812 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
11816 default ( none | shared )
11819 default ( none | present ) */
11822 c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc)
11824 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
11825 location_t loc = c_parser_peek_token (parser)->location;
11828 matching_parens parens;
11829 if (!parens.require_open (parser))
11831 if (c_parser_next_token_is (parser, CPP_NAME))
11833 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11838 if (strcmp ("none", p) != 0)
11840 kind = OMP_CLAUSE_DEFAULT_NONE;
11844 if (strcmp ("present", p) != 0 || !is_oacc)
11846 kind = OMP_CLAUSE_DEFAULT_PRESENT;
11850 if (strcmp ("shared", p) != 0 || is_oacc)
11852 kind = OMP_CLAUSE_DEFAULT_SHARED;
11859 c_parser_consume_token (parser);
11865 c_parser_error (parser, "expected %<none%> or %<present%>");
11867 c_parser_error (parser, "expected %<none%> or %<shared%>");
11869 parens.skip_until_found_close (parser);
11871 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
11874 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
11875 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
11876 OMP_CLAUSE_CHAIN (c) = list;
11877 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
11883 firstprivate ( variable-list ) */
11886 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
11888 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
11892 final ( expression ) */
11895 c_parser_omp_clause_final (c_parser *parser, tree list)
11897 location_t loc = c_parser_peek_token (parser)->location;
11898 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
11900 tree t = c_parser_paren_condition (parser);
11903 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
11905 c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
11906 OMP_CLAUSE_FINAL_EXPR (c) = t;
11907 OMP_CLAUSE_CHAIN (c) = list;
11911 c_parser_error (parser, "expected %<(%>");
11916 /* OpenACC, OpenMP 2.5:
11920 if ( directive-name-modifier : expression )
11922 directive-name-modifier:
11923 parallel | task | taskloop | target data | target | target update
11924 | target enter data | target exit data */
11927 c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp)
11929 location_t location = c_parser_peek_token (parser)->location;
11930 enum tree_code if_modifier = ERROR_MARK;
11932 matching_parens parens;
11933 if (!parens.require_open (parser))
11936 if (is_omp && c_parser_next_token_is (parser, CPP_NAME))
11938 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
11940 if (strcmp (p, "parallel") == 0)
11941 if_modifier = OMP_PARALLEL;
11942 else if (strcmp (p, "task") == 0)
11943 if_modifier = OMP_TASK;
11944 else if (strcmp (p, "taskloop") == 0)
11945 if_modifier = OMP_TASKLOOP;
11946 else if (strcmp (p, "target") == 0)
11948 if_modifier = OMP_TARGET;
11949 if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11951 p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value);
11952 if (strcmp ("data", p) == 0)
11953 if_modifier = OMP_TARGET_DATA;
11954 else if (strcmp ("update", p) == 0)
11955 if_modifier = OMP_TARGET_UPDATE;
11956 else if (strcmp ("enter", p) == 0)
11957 if_modifier = OMP_TARGET_ENTER_DATA;
11958 else if (strcmp ("exit", p) == 0)
11959 if_modifier = OMP_TARGET_EXIT_DATA;
11960 if (if_modifier != OMP_TARGET)
11963 c_parser_consume_token (parser);
11967 location_t loc = c_parser_peek_2nd_token (parser)->location;
11968 error_at (loc, "expected %<data%>, %<update%>, %<enter%> "
11970 if_modifier = ERROR_MARK;
11972 if (if_modifier == OMP_TARGET_ENTER_DATA
11973 || if_modifier == OMP_TARGET_EXIT_DATA)
11975 if (c_parser_peek_2nd_token (parser)->type == CPP_NAME)
11977 p = IDENTIFIER_POINTER
11978 (c_parser_peek_2nd_token (parser)->value);
11979 if (strcmp ("data", p) == 0)
11983 c_parser_consume_token (parser);
11987 = c_parser_peek_2nd_token (parser)->location;
11988 error_at (loc, "expected %<data%>");
11989 if_modifier = ERROR_MARK;
11994 if (if_modifier != ERROR_MARK)
11996 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON)
11998 c_parser_consume_token (parser);
11999 c_parser_consume_token (parser);
12005 location_t loc = c_parser_peek_2nd_token (parser)->location;
12006 error_at (loc, "expected %<:%>");
12008 if_modifier = ERROR_MARK;
12013 tree t = c_parser_condition (parser), c;
12014 parens.skip_until_found_close (parser);
12016 for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
12017 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF)
12019 if (if_modifier != ERROR_MARK
12020 && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
12022 const char *p = NULL;
12023 switch (if_modifier)
12025 case OMP_PARALLEL: p = "parallel"; break;
12026 case OMP_TASK: p = "task"; break;
12027 case OMP_TASKLOOP: p = "taskloop"; break;
12028 case OMP_TARGET_DATA: p = "target data"; break;
12029 case OMP_TARGET: p = "target"; break;
12030 case OMP_TARGET_UPDATE: p = "target update"; break;
12031 case OMP_TARGET_ENTER_DATA: p = "enter data"; break;
12032 case OMP_TARGET_EXIT_DATA: p = "exit data"; break;
12033 default: gcc_unreachable ();
12035 error_at (location, "too many %<if%> clauses with %qs modifier",
12039 else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier)
12042 error_at (location, "too many %<if%> clauses");
12044 error_at (location, "too many %<if%> clauses without modifier");
12047 else if (if_modifier == ERROR_MARK
12048 || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK)
12050 error_at (location, "if any %<if%> clause has modifier, then all "
12051 "%<if%> clauses have to use modifier");
12056 c = build_omp_clause (location, OMP_CLAUSE_IF);
12057 OMP_CLAUSE_IF_MODIFIER (c) = if_modifier;
12058 OMP_CLAUSE_IF_EXPR (c) = t;
12059 OMP_CLAUSE_CHAIN (c) = list;
12064 lastprivate ( variable-list ) */
12067 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
12069 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
12076 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
12080 /* FIXME: Should we allow duplicates? */
12081 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
12083 c = build_omp_clause (c_parser_peek_token (parser)->location,
12084 OMP_CLAUSE_MERGEABLE);
12085 OMP_CLAUSE_CHAIN (c) = list;
12094 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
12097 location_t loc = c_parser_peek_token (parser)->location;
12099 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
12101 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
12102 OMP_CLAUSE_CHAIN (c) = list;
12107 num_threads ( expression ) */
12110 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
12112 location_t num_threads_loc = c_parser_peek_token (parser)->location;
12113 matching_parens parens;
12114 if (parens.require_open (parser))
12116 location_t expr_loc = c_parser_peek_token (parser)->location;
12117 c_expr expr = c_parser_expression (parser);
12118 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12119 tree c, t = expr.value;
12120 t = c_fully_fold (t, false, NULL);
12122 parens.skip_until_found_close (parser);
12124 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12126 c_parser_error (parser, "expected integer expression");
12130 /* Attempt to statically determine when the number isn't positive. */
12131 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12132 build_int_cst (TREE_TYPE (t), 0));
12133 protected_set_expr_location (c, expr_loc);
12134 if (c == boolean_true_node)
12136 warning_at (expr_loc, 0,
12137 "%<num_threads%> value must be positive");
12138 t = integer_one_node;
12141 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
12143 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
12144 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
12145 OMP_CLAUSE_CHAIN (c) = list;
12153 num_tasks ( expression ) */
12156 c_parser_omp_clause_num_tasks (c_parser *parser, tree list)
12158 location_t num_tasks_loc = c_parser_peek_token (parser)->location;
12159 matching_parens parens;
12160 if (parens.require_open (parser))
12162 location_t expr_loc = c_parser_peek_token (parser)->location;
12163 c_expr expr = c_parser_expression (parser);
12164 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12165 tree c, t = expr.value;
12166 t = c_fully_fold (t, false, NULL);
12168 parens.skip_until_found_close (parser);
12170 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12172 c_parser_error (parser, "expected integer expression");
12176 /* Attempt to statically determine when the number isn't positive. */
12177 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12178 build_int_cst (TREE_TYPE (t), 0));
12179 if (CAN_HAVE_LOCATION_P (c))
12180 SET_EXPR_LOCATION (c, expr_loc);
12181 if (c == boolean_true_node)
12183 warning_at (expr_loc, 0, "%<num_tasks%> value must be positive");
12184 t = integer_one_node;
12187 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks");
12189 c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS);
12190 OMP_CLAUSE_NUM_TASKS_EXPR (c) = t;
12191 OMP_CLAUSE_CHAIN (c) = list;
12199 grainsize ( expression ) */
12202 c_parser_omp_clause_grainsize (c_parser *parser, tree list)
12204 location_t grainsize_loc = c_parser_peek_token (parser)->location;
12205 matching_parens parens;
12206 if (parens.require_open (parser))
12208 location_t expr_loc = c_parser_peek_token (parser)->location;
12209 c_expr expr = c_parser_expression (parser);
12210 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12211 tree c, t = expr.value;
12212 t = c_fully_fold (t, false, NULL);
12214 parens.skip_until_found_close (parser);
12216 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12218 c_parser_error (parser, "expected integer expression");
12222 /* Attempt to statically determine when the number isn't positive. */
12223 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12224 build_int_cst (TREE_TYPE (t), 0));
12225 if (CAN_HAVE_LOCATION_P (c))
12226 SET_EXPR_LOCATION (c, expr_loc);
12227 if (c == boolean_true_node)
12229 warning_at (expr_loc, 0, "%<grainsize%> value must be positive");
12230 t = integer_one_node;
12233 check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize");
12235 c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE);
12236 OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
12237 OMP_CLAUSE_CHAIN (c) = list;
12245 priority ( expression ) */
12248 c_parser_omp_clause_priority (c_parser *parser, tree list)
12250 location_t priority_loc = c_parser_peek_token (parser)->location;
12251 matching_parens parens;
12252 if (parens.require_open (parser))
12254 location_t expr_loc = c_parser_peek_token (parser)->location;
12255 c_expr expr = c_parser_expression (parser);
12256 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12257 tree c, t = expr.value;
12258 t = c_fully_fold (t, false, NULL);
12260 parens.skip_until_found_close (parser);
12262 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12264 c_parser_error (parser, "expected integer expression");
12268 /* Attempt to statically determine when the number isn't
12270 c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t,
12271 build_int_cst (TREE_TYPE (t), 0));
12272 if (CAN_HAVE_LOCATION_P (c))
12273 SET_EXPR_LOCATION (c, expr_loc);
12274 if (c == boolean_true_node)
12276 warning_at (expr_loc, 0, "%<priority%> value must be non-negative");
12277 t = integer_one_node;
12280 check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority");
12282 c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY);
12283 OMP_CLAUSE_PRIORITY_EXPR (c) = t;
12284 OMP_CLAUSE_CHAIN (c) = list;
12292 hint ( expression ) */
12295 c_parser_omp_clause_hint (c_parser *parser, tree list)
12297 location_t hint_loc = c_parser_peek_token (parser)->location;
12298 matching_parens parens;
12299 if (parens.require_open (parser))
12301 location_t expr_loc = c_parser_peek_token (parser)->location;
12302 c_expr expr = c_parser_expression (parser);
12303 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12304 tree c, t = expr.value;
12305 t = c_fully_fold (t, false, NULL);
12307 parens.skip_until_found_close (parser);
12309 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12311 c_parser_error (parser, "expected integer expression");
12315 check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint");
12317 c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT);
12318 OMP_CLAUSE_HINT_EXPR (c) = t;
12319 OMP_CLAUSE_CHAIN (c) = list;
12327 defaultmap ( tofrom : scalar ) */
12330 c_parser_omp_clause_defaultmap (c_parser *parser, tree list)
12332 location_t loc = c_parser_peek_token (parser)->location;
12336 matching_parens parens;
12337 if (!parens.require_open (parser))
12339 if (!c_parser_next_token_is (parser, CPP_NAME))
12341 c_parser_error (parser, "expected %<tofrom%>");
12344 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12345 if (strcmp (p, "tofrom") != 0)
12347 c_parser_error (parser, "expected %<tofrom%>");
12350 c_parser_consume_token (parser);
12351 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12353 if (!c_parser_next_token_is (parser, CPP_NAME))
12355 c_parser_error (parser, "expected %<scalar%>");
12358 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12359 if (strcmp (p, "scalar") != 0)
12361 c_parser_error (parser, "expected %<scalar%>");
12364 c_parser_consume_token (parser);
12365 parens.skip_until_found_close (parser);
12366 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap");
12367 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP);
12368 OMP_CLAUSE_CHAIN (c) = list;
12372 parens.skip_until_found_close (parser);
12377 use_device ( variable-list )
12380 use_device_ptr ( variable-list ) */
12383 c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list)
12385 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR,
12390 is_device_ptr ( variable-list ) */
12393 c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list)
12395 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list);
12399 num_gangs ( expression )
12400 num_workers ( expression )
12401 vector_length ( expression ) */
12404 c_parser_oacc_single_int_clause (c_parser *parser, omp_clause_code code,
12407 location_t loc = c_parser_peek_token (parser)->location;
12409 matching_parens parens;
12410 if (!parens.require_open (parser))
12413 location_t expr_loc = c_parser_peek_token (parser)->location;
12414 c_expr expr = c_parser_expression (parser);
12415 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
12416 tree c, t = expr.value;
12417 t = c_fully_fold (t, false, NULL);
12419 parens.skip_until_found_close (parser);
12421 if (t == error_mark_node)
12423 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12425 error_at (expr_loc, "%qs expression must be integral",
12426 omp_clause_code_name[code]);
12430 /* Attempt to statically determine when the number isn't positive. */
12431 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
12432 build_int_cst (TREE_TYPE (t), 0));
12433 protected_set_expr_location (c, expr_loc);
12434 if (c == boolean_true_node)
12436 warning_at (expr_loc, 0,
12437 "%qs value must be positive",
12438 omp_clause_code_name[code]);
12439 t = integer_one_node;
12442 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
12444 c = build_omp_clause (loc, code);
12445 OMP_CLAUSE_OPERAND (c, 0) = t;
12446 OMP_CLAUSE_CHAIN (c) = list;
12452 gang [( gang-arg-list )]
12453 worker [( [num:] int-expr )]
12454 vector [( [length:] int-expr )]
12456 where gang-arg is one of:
12461 and size-expr may be:
12468 c_parser_oacc_shape_clause (c_parser *parser, omp_clause_code kind,
12469 const char *str, tree list)
12471 const char *id = "num";
12472 tree ops[2] = { NULL_TREE, NULL_TREE }, c;
12473 location_t loc = c_parser_peek_token (parser)->location;
12475 if (kind == OMP_CLAUSE_VECTOR)
12478 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12480 c_parser_consume_token (parser);
12484 c_token *next = c_parser_peek_token (parser);
12487 /* Gang static argument. */
12488 if (kind == OMP_CLAUSE_GANG
12489 && c_parser_next_token_is_keyword (parser, RID_STATIC))
12491 c_parser_consume_token (parser);
12493 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12494 goto cleanup_error;
12497 if (ops[idx] != NULL_TREE)
12499 c_parser_error (parser, "too many %<static%> arguments");
12500 goto cleanup_error;
12503 /* Check for the '*' argument. */
12504 if (c_parser_next_token_is (parser, CPP_MULT)
12505 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
12506 || c_parser_peek_2nd_token (parser)->type
12507 == CPP_CLOSE_PAREN))
12509 c_parser_consume_token (parser);
12510 ops[idx] = integer_minus_one_node;
12512 if (c_parser_next_token_is (parser, CPP_COMMA))
12514 c_parser_consume_token (parser);
12521 /* Worker num: argument and vector length: arguments. */
12522 else if (c_parser_next_token_is (parser, CPP_NAME)
12523 && strcmp (id, IDENTIFIER_POINTER (next->value)) == 0
12524 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
12526 c_parser_consume_token (parser); /* id */
12527 c_parser_consume_token (parser); /* ':' */
12530 /* Now collect the actual argument. */
12531 if (ops[idx] != NULL_TREE)
12533 c_parser_error (parser, "unexpected argument");
12534 goto cleanup_error;
12537 location_t expr_loc = c_parser_peek_token (parser)->location;
12538 c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
12539 cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
12540 tree expr = cexpr.value;
12541 if (expr == error_mark_node)
12542 goto cleanup_error;
12544 expr = c_fully_fold (expr, false, NULL);
12546 /* Attempt to statically determine when the number isn't a
12547 positive integer. */
12549 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)))
12551 c_parser_error (parser, "expected integer expression");
12555 tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr,
12556 build_int_cst (TREE_TYPE (expr), 0));
12557 if (c == boolean_true_node)
12559 warning_at (loc, 0,
12560 "%qs value must be positive", str);
12561 expr = integer_one_node;
12566 if (kind == OMP_CLAUSE_GANG
12567 && c_parser_next_token_is (parser, CPP_COMMA))
12569 c_parser_consume_token (parser);
12576 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
12577 goto cleanup_error;
12580 check_no_duplicate_clause (list, kind, str);
12582 c = build_omp_clause (loc, kind);
12585 OMP_CLAUSE_OPERAND (c, 1) = ops[1];
12587 OMP_CLAUSE_OPERAND (c, 0) = ops[0];
12588 OMP_CLAUSE_CHAIN (c) = list;
12593 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
12604 c_parser_oacc_simple_clause (c_parser *parser, enum omp_clause_code code,
12607 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
12609 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
12610 OMP_CLAUSE_CHAIN (c) = list;
12616 async [( int-expr )] */
12619 c_parser_oacc_clause_async (c_parser *parser, tree list)
12622 location_t loc = c_parser_peek_token (parser)->location;
12624 t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL);
12626 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12628 c_parser_consume_token (parser);
12630 t = c_parser_expression (parser).value;
12631 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
12632 c_parser_error (parser, "expected integer expression");
12633 else if (t == error_mark_node
12634 || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
12638 t = c_fully_fold (t, false, NULL);
12640 check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async");
12642 c = build_omp_clause (loc, OMP_CLAUSE_ASYNC);
12643 OMP_CLAUSE_ASYNC_EXPR (c) = t;
12644 OMP_CLAUSE_CHAIN (c) = list;
12651 tile ( size-expr-list ) */
12654 c_parser_oacc_clause_tile (c_parser *parser, tree list)
12656 tree c, expr = error_mark_node;
12658 tree tile = NULL_TREE;
12660 check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
12661 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
12663 loc = c_parser_peek_token (parser)->location;
12664 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
12669 if (tile && !c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
12672 if (c_parser_next_token_is (parser, CPP_MULT)
12673 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
12674 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))
12676 c_parser_consume_token (parser);
12677 expr = integer_zero_node;
12681 location_t expr_loc = c_parser_peek_token (parser)->location;
12682 c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
12683 cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
12684 expr = cexpr.value;
12686 if (expr == error_mark_node)
12688 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
12693 expr = c_fully_fold (expr, false, NULL);
12695 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
12696 || !tree_fits_shwi_p (expr)
12697 || tree_to_shwi (expr) <= 0)
12699 error_at (expr_loc, "%<tile%> argument needs positive"
12700 " integral constant");
12701 expr = integer_zero_node;
12705 tile = tree_cons (NULL_TREE, expr, tile);
12707 while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN));
12709 /* Consume the trailing ')'. */
12710 c_parser_consume_token (parser);
12712 c = build_omp_clause (loc, OMP_CLAUSE_TILE);
12713 tile = nreverse (tile);
12714 OMP_CLAUSE_TILE_LIST (c) = tile;
12715 OMP_CLAUSE_CHAIN (c) = list;
12720 wait ( int-expr-list ) */
12723 c_parser_oacc_clause_wait (c_parser *parser, tree list)
12725 location_t clause_loc = c_parser_peek_token (parser)->location;
12727 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
12728 list = c_parser_oacc_wait_list (parser, clause_loc, list);
12737 ordered ( constant-expression ) */
12740 c_parser_omp_clause_ordered (c_parser *parser, tree list)
12742 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
12744 tree c, num = NULL_TREE;
12746 location_t loc = c_parser_peek_token (parser)->location;
12747 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
12749 matching_parens parens;
12750 parens.consume_open (parser);
12751 num = c_parser_expr_no_commas (parser, NULL).value;
12752 parens.skip_until_found_close (parser);
12754 if (num == error_mark_node)
12758 mark_exp_read (num);
12759 num = c_fully_fold (num, false, NULL);
12760 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
12761 || !tree_fits_shwi_p (num)
12762 || (n = tree_to_shwi (num)) <= 0
12765 error_at (loc, "ordered argument needs positive "
12766 "constant integer expression");
12770 c = build_omp_clause (loc, OMP_CLAUSE_ORDERED);
12771 OMP_CLAUSE_ORDERED_EXPR (c) = num;
12772 OMP_CLAUSE_CHAIN (c) = list;
12777 private ( variable-list ) */
12780 c_parser_omp_clause_private (c_parser *parser, tree list)
12782 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
12786 reduction ( reduction-operator : variable-list )
12788 reduction-operator:
12789 One of: + * - & ^ | && ||
12793 reduction-operator:
12794 One of: + * - & ^ | && || max min
12798 reduction-operator:
12799 One of: + * - & ^ | && ||
12803 c_parser_omp_clause_reduction (c_parser *parser, tree list)
12805 location_t clause_loc = c_parser_peek_token (parser)->location;
12806 matching_parens parens;
12807 if (parens.require_open (parser))
12809 enum tree_code code = ERROR_MARK;
12810 tree reduc_id = NULL_TREE;
12812 switch (c_parser_peek_token (parser)->type)
12824 code = BIT_AND_EXPR;
12827 code = BIT_XOR_EXPR;
12830 code = BIT_IOR_EXPR;
12833 code = TRUTH_ANDIF_EXPR;
12836 code = TRUTH_ORIF_EXPR;
12841 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
12842 if (strcmp (p, "min") == 0)
12847 if (strcmp (p, "max") == 0)
12852 reduc_id = c_parser_peek_token (parser)->value;
12856 c_parser_error (parser,
12857 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12858 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12859 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
12862 c_parser_consume_token (parser);
12863 reduc_id = c_omp_reduction_id (code, reduc_id);
12864 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
12868 nl = c_parser_omp_variable_list (parser, clause_loc,
12869 OMP_CLAUSE_REDUCTION, list);
12870 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
12872 tree d = OMP_CLAUSE_DECL (c), type;
12873 if (TREE_CODE (d) != TREE_LIST)
12874 type = TREE_TYPE (d);
12879 for (t = d; TREE_CODE (t) == TREE_LIST; t = TREE_CHAIN (t))
12881 type = TREE_TYPE (t);
12884 if (TREE_CODE (type) != POINTER_TYPE
12885 && TREE_CODE (type) != ARRAY_TYPE)
12887 type = TREE_TYPE (type);
12891 while (TREE_CODE (type) == ARRAY_TYPE)
12892 type = TREE_TYPE (type);
12893 OMP_CLAUSE_REDUCTION_CODE (c) = code;
12894 if (code == ERROR_MARK
12895 || !(INTEGRAL_TYPE_P (type)
12896 || TREE_CODE (type) == REAL_TYPE
12897 || TREE_CODE (type) == COMPLEX_TYPE))
12898 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
12899 = c_omp_reduction_lookup (reduc_id,
12900 TYPE_MAIN_VARIANT (type));
12905 parens.skip_until_found_close (parser);
12911 schedule ( schedule-kind )
12912 schedule ( schedule-kind , expression )
12915 static | dynamic | guided | runtime | auto
12918 schedule ( schedule-modifier : schedule-kind )
12919 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12927 c_parser_omp_clause_schedule (c_parser *parser, tree list)
12930 location_t loc = c_parser_peek_token (parser)->location;
12931 int modifiers = 0, nmodifiers = 0;
12933 matching_parens parens;
12934 if (!parens.require_open (parser))
12937 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
12939 while (c_parser_next_token_is (parser, CPP_NAME))
12941 tree kind = c_parser_peek_token (parser)->value;
12942 const char *p = IDENTIFIER_POINTER (kind);
12943 if (strcmp ("simd", p) == 0)
12944 OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
12945 else if (strcmp ("monotonic", p) == 0)
12946 modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC;
12947 else if (strcmp ("nonmonotonic", p) == 0)
12948 modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC;
12951 c_parser_consume_token (parser);
12952 if (nmodifiers++ == 0
12953 && c_parser_next_token_is (parser, CPP_COMMA))
12954 c_parser_consume_token (parser);
12957 c_parser_require (parser, CPP_COLON, "expected %<:%>");
12962 if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC
12963 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
12964 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12965 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
12967 error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12972 if (c_parser_next_token_is (parser, CPP_NAME))
12974 tree kind = c_parser_peek_token (parser)->value;
12975 const char *p = IDENTIFIER_POINTER (kind);
12980 if (strcmp ("dynamic", p) != 0)
12982 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
12986 if (strcmp ("guided", p) != 0)
12988 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
12992 if (strcmp ("runtime", p) != 0)
12994 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
13001 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
13002 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
13003 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
13004 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
13008 c_parser_consume_token (parser);
13009 if (c_parser_next_token_is (parser, CPP_COMMA))
13012 c_parser_consume_token (parser);
13014 here = c_parser_peek_token (parser)->location;
13015 c_expr expr = c_parser_expr_no_commas (parser, NULL);
13016 expr = convert_lvalue_to_rvalue (here, expr, false, true);
13018 t = c_fully_fold (t, false, NULL);
13020 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
13021 error_at (here, "schedule %<runtime%> does not take "
13022 "a %<chunk_size%> parameter");
13023 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
13025 "schedule %<auto%> does not take "
13026 "a %<chunk_size%> parameter");
13027 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
13029 /* Attempt to statically determine when the number isn't
13031 tree s = fold_build2_loc (loc, LE_EXPR, boolean_type_node, t,
13032 build_int_cst (TREE_TYPE (t), 0));
13033 protected_set_expr_location (s, loc);
13034 if (s == boolean_true_node)
13036 warning_at (loc, 0,
13037 "chunk size value must be positive");
13038 t = integer_one_node;
13040 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
13043 c_parser_error (parser, "expected integer expression");
13045 parens.skip_until_found_close (parser);
13048 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13049 "expected %<,%> or %<)%>");
13051 OMP_CLAUSE_SCHEDULE_KIND (c)
13052 = (enum omp_clause_schedule_kind)
13053 (OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers);
13055 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
13056 OMP_CLAUSE_CHAIN (c) = list;
13060 c_parser_error (parser, "invalid schedule kind");
13061 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
13066 shared ( variable-list ) */
13069 c_parser_omp_clause_shared (c_parser *parser, tree list)
13071 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
13078 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
13082 /* FIXME: Should we allow duplicates? */
13083 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
13085 c = build_omp_clause (c_parser_peek_token (parser)->location,
13086 OMP_CLAUSE_UNTIED);
13087 OMP_CLAUSE_CHAIN (c) = list;
13097 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED,
13098 enum omp_clause_code code, tree list)
13100 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
13102 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
13103 OMP_CLAUSE_CHAIN (c) = list;
13115 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED,
13116 enum omp_clause_code code, tree list)
13118 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
13119 OMP_CLAUSE_CHAIN (c) = list;
13128 c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list)
13130 check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup");
13131 tree c = build_omp_clause (c_parser_peek_token (parser)->location,
13132 OMP_CLAUSE_NOGROUP);
13133 OMP_CLAUSE_CHAIN (c) = list;
13142 c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED,
13143 enum omp_clause_code code, tree list)
13145 check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
13146 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
13147 OMP_CLAUSE_CHAIN (c) = list;
13152 num_teams ( expression ) */
13155 c_parser_omp_clause_num_teams (c_parser *parser, tree list)
13157 location_t num_teams_loc = c_parser_peek_token (parser)->location;
13158 matching_parens parens;
13159 if (parens.require_open (parser))
13161 location_t expr_loc = c_parser_peek_token (parser)->location;
13162 c_expr expr = c_parser_expression (parser);
13163 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13164 tree c, t = expr.value;
13165 t = c_fully_fold (t, false, NULL);
13167 parens.skip_until_found_close (parser);
13169 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
13171 c_parser_error (parser, "expected integer expression");
13175 /* Attempt to statically determine when the number isn't positive. */
13176 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
13177 build_int_cst (TREE_TYPE (t), 0));
13178 protected_set_expr_location (c, expr_loc);
13179 if (c == boolean_true_node)
13181 warning_at (expr_loc, 0, "%<num_teams%> value must be positive");
13182 t = integer_one_node;
13185 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams");
13187 c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
13188 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t;
13189 OMP_CLAUSE_CHAIN (c) = list;
13197 thread_limit ( expression ) */
13200 c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
13202 location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
13203 matching_parens parens;
13204 if (parens.require_open (parser))
13206 location_t expr_loc = c_parser_peek_token (parser)->location;
13207 c_expr expr = c_parser_expression (parser);
13208 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13209 tree c, t = expr.value;
13210 t = c_fully_fold (t, false, NULL);
13212 parens.skip_until_found_close (parser);
13214 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
13216 c_parser_error (parser, "expected integer expression");
13220 /* Attempt to statically determine when the number isn't positive. */
13221 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
13222 build_int_cst (TREE_TYPE (t), 0));
13223 protected_set_expr_location (c, expr_loc);
13224 if (c == boolean_true_node)
13226 warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
13227 t = integer_one_node;
13230 check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT,
13233 c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
13234 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
13235 OMP_CLAUSE_CHAIN (c) = list;
13243 aligned ( variable-list )
13244 aligned ( variable-list : constant-expression ) */
13247 c_parser_omp_clause_aligned (c_parser *parser, tree list)
13249 location_t clause_loc = c_parser_peek_token (parser)->location;
13252 matching_parens parens;
13253 if (!parens.require_open (parser))
13256 nl = c_parser_omp_variable_list (parser, clause_loc,
13257 OMP_CLAUSE_ALIGNED, list);
13259 if (c_parser_next_token_is (parser, CPP_COLON))
13261 c_parser_consume_token (parser);
13262 location_t expr_loc = c_parser_peek_token (parser)->location;
13263 c_expr expr = c_parser_expr_no_commas (parser, NULL);
13264 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13265 tree alignment = expr.value;
13266 alignment = c_fully_fold (alignment, false, NULL);
13267 if (TREE_CODE (alignment) != INTEGER_CST
13268 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
13269 || tree_int_cst_sgn (alignment) != 1)
13271 error_at (clause_loc, "%<aligned%> clause alignment expression must "
13272 "be positive constant integer expression");
13273 alignment = NULL_TREE;
13276 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13277 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
13280 parens.skip_until_found_close (parser);
13285 linear ( variable-list )
13286 linear ( variable-list : expression )
13289 linear ( modifier ( variable-list ) )
13290 linear ( modifier ( variable-list ) : expression ) */
13293 c_parser_omp_clause_linear (c_parser *parser, tree list)
13295 location_t clause_loc = c_parser_peek_token (parser)->location;
13297 enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT;
13299 matching_parens parens;
13300 if (!parens.require_open (parser))
13303 if (c_parser_next_token_is (parser, CPP_NAME))
13305 c_token *tok = c_parser_peek_token (parser);
13306 const char *p = IDENTIFIER_POINTER (tok->value);
13307 if (strcmp ("val", p) == 0)
13308 kind = OMP_CLAUSE_LINEAR_VAL;
13309 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN)
13310 kind = OMP_CLAUSE_LINEAR_DEFAULT;
13311 if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
13313 c_parser_consume_token (parser);
13314 c_parser_consume_token (parser);
13318 nl = c_parser_omp_variable_list (parser, clause_loc,
13319 OMP_CLAUSE_LINEAR, list);
13321 if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
13322 parens.skip_until_found_close (parser);
13324 if (c_parser_next_token_is (parser, CPP_COLON))
13326 c_parser_consume_token (parser);
13327 location_t expr_loc = c_parser_peek_token (parser)->location;
13328 c_expr expr = c_parser_expression (parser);
13329 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13331 step = c_fully_fold (step, false, NULL);
13332 if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
13334 error_at (clause_loc, "%<linear%> clause step expression must "
13336 step = integer_one_node;
13341 step = integer_one_node;
13343 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13345 OMP_CLAUSE_LINEAR_STEP (c) = step;
13346 OMP_CLAUSE_LINEAR_KIND (c) = kind;
13349 parens.skip_until_found_close (parser);
13354 safelen ( constant-expression ) */
13357 c_parser_omp_clause_safelen (c_parser *parser, tree list)
13359 location_t clause_loc = c_parser_peek_token (parser)->location;
13362 matching_parens parens;
13363 if (!parens.require_open (parser))
13366 location_t expr_loc = c_parser_peek_token (parser)->location;
13367 c_expr expr = c_parser_expr_no_commas (parser, NULL);
13368 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13370 t = c_fully_fold (t, false, NULL);
13371 if (TREE_CODE (t) != INTEGER_CST
13372 || !INTEGRAL_TYPE_P (TREE_TYPE (t))
13373 || tree_int_cst_sgn (t) != 1)
13375 error_at (clause_loc, "%<safelen%> clause expression must "
13376 "be positive constant integer expression");
13380 parens.skip_until_found_close (parser);
13381 if (t == NULL_TREE || t == error_mark_node)
13384 check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen");
13386 c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN);
13387 OMP_CLAUSE_SAFELEN_EXPR (c) = t;
13388 OMP_CLAUSE_CHAIN (c) = list;
13393 simdlen ( constant-expression ) */
13396 c_parser_omp_clause_simdlen (c_parser *parser, tree list)
13398 location_t clause_loc = c_parser_peek_token (parser)->location;
13401 matching_parens parens;
13402 if (!parens.require_open (parser))
13405 location_t expr_loc = c_parser_peek_token (parser)->location;
13406 c_expr expr = c_parser_expr_no_commas (parser, NULL);
13407 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13409 t = c_fully_fold (t, false, NULL);
13410 if (TREE_CODE (t) != INTEGER_CST
13411 || !INTEGRAL_TYPE_P (TREE_TYPE (t))
13412 || tree_int_cst_sgn (t) != 1)
13414 error_at (clause_loc, "%<simdlen%> clause expression must "
13415 "be positive constant integer expression");
13419 parens.skip_until_found_close (parser);
13420 if (t == NULL_TREE || t == error_mark_node)
13423 check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen");
13425 c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN);
13426 OMP_CLAUSE_SIMDLEN_EXPR (c) = t;
13427 OMP_CLAUSE_CHAIN (c) = list;
13433 identifier [+/- integer]
13434 vec , identifier [+/- integer]
13438 c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc,
13442 if (c_parser_next_token_is_not (parser, CPP_NAME)
13443 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
13445 c_parser_error (parser, "expected identifier");
13449 while (c_parser_next_token_is (parser, CPP_NAME)
13450 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
13452 tree t = lookup_name (c_parser_peek_token (parser)->value);
13453 tree addend = NULL;
13455 if (t == NULL_TREE)
13457 undeclared_variable (c_parser_peek_token (parser)->location,
13458 c_parser_peek_token (parser)->value);
13459 t = error_mark_node;
13462 c_parser_consume_token (parser);
13465 if (c_parser_next_token_is (parser, CPP_MINUS))
13467 else if (!c_parser_next_token_is (parser, CPP_PLUS))
13469 addend = integer_zero_node;
13471 goto add_to_vector;
13473 c_parser_consume_token (parser);
13475 if (c_parser_next_token_is_not (parser, CPP_NUMBER))
13477 c_parser_error (parser, "expected integer");
13481 addend = c_parser_peek_token (parser)->value;
13482 if (TREE_CODE (addend) != INTEGER_CST)
13484 c_parser_error (parser, "expected integer");
13487 c_parser_consume_token (parser);
13490 if (t != error_mark_node)
13492 vec = tree_cons (addend, t, vec);
13494 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1;
13497 if (c_parser_next_token_is_not (parser, CPP_COMMA))
13500 c_parser_consume_token (parser);
13503 if (vec == NULL_TREE)
13506 tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
13507 OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK;
13508 OMP_CLAUSE_DECL (u) = nreverse (vec);
13509 OMP_CLAUSE_CHAIN (u) = list;
13514 depend ( depend-kind: variable-list )
13522 depend ( sink : vec ) */
13525 c_parser_omp_clause_depend (c_parser *parser, tree list)
13527 location_t clause_loc = c_parser_peek_token (parser)->location;
13528 enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
13531 matching_parens parens;
13532 if (!parens.require_open (parser))
13535 if (c_parser_next_token_is (parser, CPP_NAME))
13537 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13538 if (strcmp ("in", p) == 0)
13539 kind = OMP_CLAUSE_DEPEND_IN;
13540 else if (strcmp ("inout", p) == 0)
13541 kind = OMP_CLAUSE_DEPEND_INOUT;
13542 else if (strcmp ("out", p) == 0)
13543 kind = OMP_CLAUSE_DEPEND_OUT;
13544 else if (strcmp ("source", p) == 0)
13545 kind = OMP_CLAUSE_DEPEND_SOURCE;
13546 else if (strcmp ("sink", p) == 0)
13547 kind = OMP_CLAUSE_DEPEND_SINK;
13554 c_parser_consume_token (parser);
13556 if (kind == OMP_CLAUSE_DEPEND_SOURCE)
13558 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
13559 OMP_CLAUSE_DEPEND_KIND (c) = kind;
13560 OMP_CLAUSE_DECL (c) = NULL_TREE;
13561 OMP_CLAUSE_CHAIN (c) = list;
13562 parens.skip_until_found_close (parser);
13566 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
13569 if (kind == OMP_CLAUSE_DEPEND_SINK)
13570 nl = c_parser_omp_clause_depend_sink (parser, clause_loc, list);
13573 nl = c_parser_omp_variable_list (parser, clause_loc,
13574 OMP_CLAUSE_DEPEND, list);
13576 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13577 OMP_CLAUSE_DEPEND_KIND (c) = kind;
13580 parens.skip_until_found_close (parser);
13584 c_parser_error (parser, "invalid depend kind");
13586 parens.skip_until_found_close (parser);
13591 map ( map-kind: variable-list )
13592 map ( variable-list )
13595 alloc | to | from | tofrom
13599 alloc | to | from | tofrom | release | delete
13601 map ( always [,] map-kind: variable-list ) */
13604 c_parser_omp_clause_map (c_parser *parser, tree list)
13606 location_t clause_loc = c_parser_peek_token (parser)->location;
13607 enum gomp_map_kind kind = GOMP_MAP_TOFROM;
13609 enum c_id_kind always_id_kind = C_ID_NONE;
13610 location_t always_loc = UNKNOWN_LOCATION;
13611 tree always_id = NULL_TREE;
13614 matching_parens parens;
13615 if (!parens.require_open (parser))
13618 if (c_parser_next_token_is (parser, CPP_NAME))
13620 c_token *tok = c_parser_peek_token (parser);
13621 const char *p = IDENTIFIER_POINTER (tok->value);
13622 always_id_kind = tok->id_kind;
13623 always_loc = tok->location;
13624 always_id = tok->value;
13625 if (strcmp ("always", p) == 0)
13627 c_token *sectok = c_parser_peek_2nd_token (parser);
13628 if (sectok->type == CPP_COMMA)
13630 c_parser_consume_token (parser);
13631 c_parser_consume_token (parser);
13634 else if (sectok->type == CPP_NAME)
13636 p = IDENTIFIER_POINTER (sectok->value);
13637 if (strcmp ("alloc", p) == 0
13638 || strcmp ("to", p) == 0
13639 || strcmp ("from", p) == 0
13640 || strcmp ("tofrom", p) == 0
13641 || strcmp ("release", p) == 0
13642 || strcmp ("delete", p) == 0)
13644 c_parser_consume_token (parser);
13651 if (c_parser_next_token_is (parser, CPP_NAME)
13652 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
13654 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13655 if (strcmp ("alloc", p) == 0)
13656 kind = GOMP_MAP_ALLOC;
13657 else if (strcmp ("to", p) == 0)
13658 kind = always ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO;
13659 else if (strcmp ("from", p) == 0)
13660 kind = always ? GOMP_MAP_ALWAYS_FROM : GOMP_MAP_FROM;
13661 else if (strcmp ("tofrom", p) == 0)
13662 kind = always ? GOMP_MAP_ALWAYS_TOFROM : GOMP_MAP_TOFROM;
13663 else if (strcmp ("release", p) == 0)
13664 kind = GOMP_MAP_RELEASE;
13665 else if (strcmp ("delete", p) == 0)
13666 kind = GOMP_MAP_DELETE;
13669 c_parser_error (parser, "invalid map kind");
13670 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13674 c_parser_consume_token (parser);
13675 c_parser_consume_token (parser);
13679 if (always_id_kind != C_ID_ID)
13681 c_parser_error (parser, "expected identifier");
13682 parens.skip_until_found_close (parser);
13686 tree t = lookup_name (always_id);
13687 if (t == NULL_TREE)
13689 undeclared_variable (always_loc, always_id);
13690 t = error_mark_node;
13692 if (t != error_mark_node)
13694 tree u = build_omp_clause (clause_loc, OMP_CLAUSE_MAP);
13695 OMP_CLAUSE_DECL (u) = t;
13696 OMP_CLAUSE_CHAIN (u) = list;
13697 OMP_CLAUSE_SET_MAP_KIND (u, kind);
13702 parens.skip_until_found_close (parser);
13707 nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list);
13709 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
13710 OMP_CLAUSE_SET_MAP_KIND (c, kind);
13712 parens.skip_until_found_close (parser);
13717 device ( expression ) */
13720 c_parser_omp_clause_device (c_parser *parser, tree list)
13722 location_t clause_loc = c_parser_peek_token (parser)->location;
13723 matching_parens parens;
13724 if (parens.require_open (parser))
13726 location_t expr_loc = c_parser_peek_token (parser)->location;
13727 c_expr expr = c_parser_expr_no_commas (parser, NULL);
13728 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13729 tree c, t = expr.value;
13730 t = c_fully_fold (t, false, NULL);
13732 parens.skip_until_found_close (parser);
13734 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
13736 c_parser_error (parser, "expected integer expression");
13740 check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device");
13742 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE);
13743 OMP_CLAUSE_DEVICE_ID (c) = t;
13744 OMP_CLAUSE_CHAIN (c) = list;
13752 dist_schedule ( static )
13753 dist_schedule ( static , expression ) */
13756 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
13758 tree c, t = NULL_TREE;
13759 location_t loc = c_parser_peek_token (parser)->location;
13761 matching_parens parens;
13762 if (!parens.require_open (parser))
13765 if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
13767 c_parser_error (parser, "invalid dist_schedule kind");
13768 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13773 c_parser_consume_token (parser);
13774 if (c_parser_next_token_is (parser, CPP_COMMA))
13776 c_parser_consume_token (parser);
13778 location_t expr_loc = c_parser_peek_token (parser)->location;
13779 c_expr expr = c_parser_expr_no_commas (parser, NULL);
13780 expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
13782 t = c_fully_fold (t, false, NULL);
13783 parens.skip_until_found_close (parser);
13786 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
13787 "expected %<,%> or %<)%>");
13789 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
13790 if (t == error_mark_node)
13793 c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE);
13794 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
13795 OMP_CLAUSE_CHAIN (c) = list;
13800 proc_bind ( proc-bind-kind )
13803 master | close | spread */
13806 c_parser_omp_clause_proc_bind (c_parser *parser, tree list)
13808 location_t clause_loc = c_parser_peek_token (parser)->location;
13809 enum omp_clause_proc_bind_kind kind;
13812 matching_parens parens;
13813 if (!parens.require_open (parser))
13816 if (c_parser_next_token_is (parser, CPP_NAME))
13818 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
13819 if (strcmp ("master", p) == 0)
13820 kind = OMP_CLAUSE_PROC_BIND_MASTER;
13821 else if (strcmp ("close", p) == 0)
13822 kind = OMP_CLAUSE_PROC_BIND_CLOSE;
13823 else if (strcmp ("spread", p) == 0)
13824 kind = OMP_CLAUSE_PROC_BIND_SPREAD;
13831 c_parser_consume_token (parser);
13832 parens.skip_until_found_close (parser);
13833 c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
13834 OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
13835 OMP_CLAUSE_CHAIN (c) = list;
13839 c_parser_error (parser, "invalid proc_bind kind");
13840 parens.skip_until_found_close (parser);
13845 to ( variable-list ) */
13848 c_parser_omp_clause_to (c_parser *parser, tree list)
13850 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list);
13854 from ( variable-list ) */
13857 c_parser_omp_clause_from (c_parser *parser, tree list)
13859 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list);
13863 uniform ( variable-list ) */
13866 c_parser_omp_clause_uniform (c_parser *parser, tree list)
13868 /* The clauses location. */
13869 location_t loc = c_parser_peek_token (parser)->location;
13871 matching_parens parens;
13872 if (parens.require_open (parser))
13874 list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
13876 parens.skip_until_found_close (parser);
13881 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13882 is a bitmask in MASK. Return the list of clauses found. */
13885 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
13886 const char *where, bool finish_p = true)
13888 tree clauses = NULL;
13891 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
13894 pragma_omp_clause c_kind;
13895 const char *c_name;
13896 tree prev = clauses;
13898 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
13899 c_parser_consume_token (parser);
13901 here = c_parser_peek_token (parser)->location;
13902 c_kind = c_parser_omp_clause_name (parser);
13906 case PRAGMA_OACC_CLAUSE_ASYNC:
13907 clauses = c_parser_oacc_clause_async (parser, clauses);
13910 case PRAGMA_OACC_CLAUSE_AUTO:
13911 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_AUTO,
13915 case PRAGMA_OACC_CLAUSE_COLLAPSE:
13916 clauses = c_parser_omp_clause_collapse (parser, clauses);
13917 c_name = "collapse";
13919 case PRAGMA_OACC_CLAUSE_COPY:
13920 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13923 case PRAGMA_OACC_CLAUSE_COPYIN:
13924 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13927 case PRAGMA_OACC_CLAUSE_COPYOUT:
13928 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13929 c_name = "copyout";
13931 case PRAGMA_OACC_CLAUSE_CREATE:
13932 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13935 case PRAGMA_OACC_CLAUSE_DELETE:
13936 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13939 case PRAGMA_OMP_CLAUSE_DEFAULT:
13940 clauses = c_parser_omp_clause_default (parser, clauses, true);
13941 c_name = "default";
13943 case PRAGMA_OACC_CLAUSE_DEVICE:
13944 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13947 case PRAGMA_OACC_CLAUSE_DEVICEPTR:
13948 clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses);
13949 c_name = "deviceptr";
13951 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
13952 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13953 c_name = "device_resident";
13955 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE:
13956 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
13957 c_name = "firstprivate";
13959 case PRAGMA_OACC_CLAUSE_GANG:
13961 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_GANG,
13964 case PRAGMA_OACC_CLAUSE_HOST:
13965 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13968 case PRAGMA_OACC_CLAUSE_IF:
13969 clauses = c_parser_omp_clause_if (parser, clauses, false);
13972 case PRAGMA_OACC_CLAUSE_INDEPENDENT:
13973 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_INDEPENDENT,
13975 c_name = "independent";
13977 case PRAGMA_OACC_CLAUSE_LINK:
13978 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13981 case PRAGMA_OACC_CLAUSE_NUM_GANGS:
13982 clauses = c_parser_oacc_single_int_clause (parser,
13983 OMP_CLAUSE_NUM_GANGS,
13985 c_name = "num_gangs";
13987 case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
13988 clauses = c_parser_oacc_single_int_clause (parser,
13989 OMP_CLAUSE_NUM_WORKERS,
13991 c_name = "num_workers";
13993 case PRAGMA_OACC_CLAUSE_PRESENT:
13994 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13995 c_name = "present";
13997 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY:
13998 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
13999 c_name = "present_or_copy";
14001 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN:
14002 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14003 c_name = "present_or_copyin";
14005 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT:
14006 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14007 c_name = "present_or_copyout";
14009 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE:
14010 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14011 c_name = "present_or_create";
14013 case PRAGMA_OACC_CLAUSE_PRIVATE:
14014 clauses = c_parser_omp_clause_private (parser, clauses);
14015 c_name = "private";
14017 case PRAGMA_OACC_CLAUSE_REDUCTION:
14018 clauses = c_parser_omp_clause_reduction (parser, clauses);
14019 c_name = "reduction";
14021 case PRAGMA_OACC_CLAUSE_SELF:
14022 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
14025 case PRAGMA_OACC_CLAUSE_SEQ:
14026 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ,
14030 case PRAGMA_OACC_CLAUSE_TILE:
14031 clauses = c_parser_oacc_clause_tile (parser, clauses);
14034 case PRAGMA_OACC_CLAUSE_USE_DEVICE:
14035 clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
14036 c_name = "use_device";
14038 case PRAGMA_OACC_CLAUSE_VECTOR:
14040 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_VECTOR,
14043 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
14044 clauses = c_parser_oacc_single_int_clause (parser,
14045 OMP_CLAUSE_VECTOR_LENGTH,
14047 c_name = "vector_length";
14049 case PRAGMA_OACC_CLAUSE_WAIT:
14050 clauses = c_parser_oacc_clause_wait (parser, clauses);
14053 case PRAGMA_OACC_CLAUSE_WORKER:
14055 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_WORKER,
14059 c_parser_error (parser, "expected %<#pragma acc%> clause");
14065 if (((mask >> c_kind) & 1) == 0)
14067 /* Remove the invalid clause(s) from the list to avoid
14068 confusing the rest of the compiler. */
14070 error_at (here, "%qs is not valid for %qs", c_name, where);
14075 c_parser_skip_to_pragma_eol (parser);
14078 return c_finish_omp_clauses (clauses, C_ORT_ACC);
14083 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14084 is a bitmask in MASK. Return the list of clauses found. */
14087 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
14088 const char *where, bool finish_p = true)
14090 tree clauses = NULL;
14093 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
14096 pragma_omp_clause c_kind;
14097 const char *c_name;
14098 tree prev = clauses;
14100 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
14101 c_parser_consume_token (parser);
14103 here = c_parser_peek_token (parser)->location;
14104 c_kind = c_parser_omp_clause_name (parser);
14108 case PRAGMA_OMP_CLAUSE_COLLAPSE:
14109 clauses = c_parser_omp_clause_collapse (parser, clauses);
14110 c_name = "collapse";
14112 case PRAGMA_OMP_CLAUSE_COPYIN:
14113 clauses = c_parser_omp_clause_copyin (parser, clauses);
14116 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
14117 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
14118 c_name = "copyprivate";
14120 case PRAGMA_OMP_CLAUSE_DEFAULT:
14121 clauses = c_parser_omp_clause_default (parser, clauses, false);
14122 c_name = "default";
14124 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
14125 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
14126 c_name = "firstprivate";
14128 case PRAGMA_OMP_CLAUSE_FINAL:
14129 clauses = c_parser_omp_clause_final (parser, clauses);
14132 case PRAGMA_OMP_CLAUSE_GRAINSIZE:
14133 clauses = c_parser_omp_clause_grainsize (parser, clauses);
14134 c_name = "grainsize";
14136 case PRAGMA_OMP_CLAUSE_HINT:
14137 clauses = c_parser_omp_clause_hint (parser, clauses);
14140 case PRAGMA_OMP_CLAUSE_DEFAULTMAP:
14141 clauses = c_parser_omp_clause_defaultmap (parser, clauses);
14142 c_name = "defaultmap";
14144 case PRAGMA_OMP_CLAUSE_IF:
14145 clauses = c_parser_omp_clause_if (parser, clauses, true);
14148 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
14149 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
14150 c_name = "lastprivate";
14152 case PRAGMA_OMP_CLAUSE_MERGEABLE:
14153 clauses = c_parser_omp_clause_mergeable (parser, clauses);
14154 c_name = "mergeable";
14156 case PRAGMA_OMP_CLAUSE_NOWAIT:
14157 clauses = c_parser_omp_clause_nowait (parser, clauses);
14160 case PRAGMA_OMP_CLAUSE_NUM_TASKS:
14161 clauses = c_parser_omp_clause_num_tasks (parser, clauses);
14162 c_name = "num_tasks";
14164 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
14165 clauses = c_parser_omp_clause_num_threads (parser, clauses);
14166 c_name = "num_threads";
14168 case PRAGMA_OMP_CLAUSE_ORDERED:
14169 clauses = c_parser_omp_clause_ordered (parser, clauses);
14170 c_name = "ordered";
14172 case PRAGMA_OMP_CLAUSE_PRIORITY:
14173 clauses = c_parser_omp_clause_priority (parser, clauses);
14174 c_name = "priority";
14176 case PRAGMA_OMP_CLAUSE_PRIVATE:
14177 clauses = c_parser_omp_clause_private (parser, clauses);
14178 c_name = "private";
14180 case PRAGMA_OMP_CLAUSE_REDUCTION:
14181 clauses = c_parser_omp_clause_reduction (parser, clauses);
14182 c_name = "reduction";
14184 case PRAGMA_OMP_CLAUSE_SCHEDULE:
14185 clauses = c_parser_omp_clause_schedule (parser, clauses);
14186 c_name = "schedule";
14188 case PRAGMA_OMP_CLAUSE_SHARED:
14189 clauses = c_parser_omp_clause_shared (parser, clauses);
14192 case PRAGMA_OMP_CLAUSE_UNTIED:
14193 clauses = c_parser_omp_clause_untied (parser, clauses);
14196 case PRAGMA_OMP_CLAUSE_INBRANCH:
14197 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH,
14199 c_name = "inbranch";
14201 case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
14202 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
14204 c_name = "notinbranch";
14206 case PRAGMA_OMP_CLAUSE_PARALLEL:
14208 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL,
14210 c_name = "parallel";
14214 error_at (here, "%qs must be the first clause of %qs",
14219 case PRAGMA_OMP_CLAUSE_FOR:
14221 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR,
14225 goto clause_not_first;
14227 case PRAGMA_OMP_CLAUSE_SECTIONS:
14229 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS,
14231 c_name = "sections";
14233 goto clause_not_first;
14235 case PRAGMA_OMP_CLAUSE_TASKGROUP:
14237 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP,
14239 c_name = "taskgroup";
14241 goto clause_not_first;
14243 case PRAGMA_OMP_CLAUSE_LINK:
14245 = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses);
14248 case PRAGMA_OMP_CLAUSE_TO:
14249 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0)
14251 = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
14254 clauses = c_parser_omp_clause_to (parser, clauses);
14257 case PRAGMA_OMP_CLAUSE_FROM:
14258 clauses = c_parser_omp_clause_from (parser, clauses);
14261 case PRAGMA_OMP_CLAUSE_UNIFORM:
14262 clauses = c_parser_omp_clause_uniform (parser, clauses);
14263 c_name = "uniform";
14265 case PRAGMA_OMP_CLAUSE_NUM_TEAMS:
14266 clauses = c_parser_omp_clause_num_teams (parser, clauses);
14267 c_name = "num_teams";
14269 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT:
14270 clauses = c_parser_omp_clause_thread_limit (parser, clauses);
14271 c_name = "thread_limit";
14273 case PRAGMA_OMP_CLAUSE_ALIGNED:
14274 clauses = c_parser_omp_clause_aligned (parser, clauses);
14275 c_name = "aligned";
14277 case PRAGMA_OMP_CLAUSE_LINEAR:
14278 clauses = c_parser_omp_clause_linear (parser, clauses);
14281 case PRAGMA_OMP_CLAUSE_DEPEND:
14282 clauses = c_parser_omp_clause_depend (parser, clauses);
14285 case PRAGMA_OMP_CLAUSE_MAP:
14286 clauses = c_parser_omp_clause_map (parser, clauses);
14289 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR:
14290 clauses = c_parser_omp_clause_use_device_ptr (parser, clauses);
14291 c_name = "use_device_ptr";
14293 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR:
14294 clauses = c_parser_omp_clause_is_device_ptr (parser, clauses);
14295 c_name = "is_device_ptr";
14297 case PRAGMA_OMP_CLAUSE_DEVICE:
14298 clauses = c_parser_omp_clause_device (parser, clauses);
14301 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE:
14302 clauses = c_parser_omp_clause_dist_schedule (parser, clauses);
14303 c_name = "dist_schedule";
14305 case PRAGMA_OMP_CLAUSE_PROC_BIND:
14306 clauses = c_parser_omp_clause_proc_bind (parser, clauses);
14307 c_name = "proc_bind";
14309 case PRAGMA_OMP_CLAUSE_SAFELEN:
14310 clauses = c_parser_omp_clause_safelen (parser, clauses);
14311 c_name = "safelen";
14313 case PRAGMA_OMP_CLAUSE_SIMDLEN:
14314 clauses = c_parser_omp_clause_simdlen (parser, clauses);
14315 c_name = "simdlen";
14317 case PRAGMA_OMP_CLAUSE_NOGROUP:
14318 clauses = c_parser_omp_clause_nogroup (parser, clauses);
14319 c_name = "nogroup";
14321 case PRAGMA_OMP_CLAUSE_THREADS:
14323 = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS,
14325 c_name = "threads";
14327 case PRAGMA_OMP_CLAUSE_SIMD:
14329 = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD,
14334 c_parser_error (parser, "expected %<#pragma omp%> clause");
14340 if (((mask >> c_kind) & 1) == 0)
14342 /* Remove the invalid clause(s) from the list to avoid
14343 confusing the rest of the compiler. */
14345 error_at (here, "%qs is not valid for %qs", c_name, where);
14350 c_parser_skip_to_pragma_eol (parser);
14354 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0)
14355 return c_finish_omp_clauses (clauses, C_ORT_OMP_DECLARE_SIMD);
14356 return c_finish_omp_clauses (clauses, C_ORT_OMP);
14362 /* OpenACC 2.0, OpenMP 2.5:
14366 In practice, we're also interested in adding the statement to an
14367 outer node. So it is convenient if we work around the fact that
14368 c_parser_statement calls add_stmt. */
14371 c_parser_omp_structured_block (c_parser *parser, bool *if_p)
14373 tree stmt = push_stmt_list ();
14374 c_parser_statement (parser, if_p);
14375 return pop_stmt_list (stmt);
14379 # pragma acc cache (variable-list) new-line
14381 LOC is the location of the #pragma token.
14385 c_parser_oacc_cache (location_t loc, c_parser *parser)
14387 tree stmt, clauses;
14389 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL);
14390 clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
14392 c_parser_skip_to_pragma_eol (parser);
14394 stmt = make_node (OACC_CACHE);
14395 TREE_TYPE (stmt) = void_type_node;
14396 OACC_CACHE_CLAUSES (stmt) = clauses;
14397 SET_EXPR_LOCATION (stmt, loc);
14404 # pragma acc data oacc-data-clause[optseq] new-line
14407 LOC is the location of the #pragma token.
14410 #define OACC_DATA_CLAUSE_MASK \
14411 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14412 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14413 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14414 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14415 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14416 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14417 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14418 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14419 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14420 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14421 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14424 c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p)
14426 tree stmt, clauses, block;
14428 clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK,
14429 "#pragma acc data");
14431 block = c_begin_omp_parallel ();
14432 add_stmt (c_parser_omp_structured_block (parser, if_p));
14434 stmt = c_finish_oacc_data (loc, clauses, block);
14440 # pragma acc declare oacc-data-clause[optseq] new-line
14443 #define OACC_DECLARE_CLAUSE_MASK \
14444 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14445 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14446 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14447 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14448 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14449 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14450 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14451 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14452 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14453 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14454 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14455 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14458 c_parser_oacc_declare (c_parser *parser)
14460 location_t pragma_loc = c_parser_peek_token (parser)->location;
14461 tree clauses, stmt, t, decl;
14463 bool error = false;
14465 c_parser_consume_pragma (parser);
14467 clauses = c_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK,
14468 "#pragma acc declare");
14471 error_at (pragma_loc,
14472 "no valid clauses specified in %<#pragma acc declare%>");
14476 for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t))
14478 location_t loc = OMP_CLAUSE_LOCATION (t);
14479 decl = OMP_CLAUSE_DECL (t);
14480 if (!DECL_P (decl))
14482 error_at (loc, "array section in %<#pragma acc declare%>");
14487 switch (OMP_CLAUSE_MAP_KIND (t))
14489 case GOMP_MAP_FIRSTPRIVATE_POINTER:
14490 case GOMP_MAP_FORCE_ALLOC:
14491 case GOMP_MAP_FORCE_TO:
14492 case GOMP_MAP_FORCE_DEVICEPTR:
14493 case GOMP_MAP_DEVICE_RESIDENT:
14496 case GOMP_MAP_LINK:
14497 if (!global_bindings_p ()
14498 && (TREE_STATIC (decl)
14499 || !DECL_EXTERNAL (decl)))
14502 "%qD must be a global variable in "
14503 "%<#pragma acc declare link%>",
14511 if (global_bindings_p ())
14513 error_at (loc, "invalid OpenACC clause at file scope");
14517 if (DECL_EXTERNAL (decl))
14520 "invalid use of %<extern%> variable %qD "
14521 "in %<#pragma acc declare%>", decl);
14525 else if (TREE_PUBLIC (decl))
14528 "invalid use of %<global%> variable %qD "
14529 "in %<#pragma acc declare%>", decl);
14536 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))
14537 || lookup_attribute ("omp declare target link",
14538 DECL_ATTRIBUTES (decl)))
14540 error_at (loc, "variable %qD used more than once with "
14541 "%<#pragma acc declare%>", decl);
14550 if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK)
14551 id = get_identifier ("omp declare target link");
14553 id = get_identifier ("omp declare target");
14555 DECL_ATTRIBUTES (decl)
14556 = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
14558 if (global_bindings_p ())
14560 symtab_node *node = symtab_node::get (decl);
14563 node->offloadable = 1;
14564 if (ENABLE_OFFLOADING)
14566 g->have_offload = true;
14567 if (is_a <varpool_node *> (node))
14568 vec_safe_push (offload_vars, decl);
14575 if (error || global_bindings_p ())
14578 stmt = make_node (OACC_DECLARE);
14579 TREE_TYPE (stmt) = void_type_node;
14580 OACC_DECLARE_CLAUSES (stmt) = clauses;
14581 SET_EXPR_LOCATION (stmt, pragma_loc);
14589 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14593 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14596 LOC is the location of the #pragma token.
14599 #define OACC_ENTER_DATA_CLAUSE_MASK \
14600 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14602 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14608 #define OACC_EXIT_DATA_CLAUSE_MASK \
14609 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14610 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14616 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter)
14618 location_t loc = c_parser_peek_token (parser)->location;
14619 tree clauses, stmt;
14620 const char *p = "";
14622 c_parser_consume_pragma (parser);
14624 if (c_parser_next_token_is (parser, CPP_NAME))
14626 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14627 c_parser_consume_token (parser);
14630 if (strcmp (p, "data") != 0)
14632 error_at (loc, "expected %<data%> after %<#pragma acc %s%>",
14633 enter ? "enter" : "exit");
14634 parser->error = true;
14635 c_parser_skip_to_pragma_eol (parser);
14640 clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK,
14641 "#pragma acc enter data");
14643 clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK,
14644 "#pragma acc exit data");
14646 if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
14648 error_at (loc, "%<#pragma acc %s data%> has no data movement clause",
14649 enter ? "enter" : "exit");
14653 stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);
14654 TREE_TYPE (stmt) = void_type_node;
14655 OMP_STANDALONE_CLAUSES (stmt) = clauses;
14656 SET_EXPR_LOCATION (stmt, loc);
14662 # pragma acc host_data oacc-data-clause[optseq] new-line
14666 #define OACC_HOST_DATA_CLAUSE_MASK \
14667 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14670 c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p)
14672 tree stmt, clauses, block;
14674 clauses = c_parser_oacc_all_clauses (parser, OACC_HOST_DATA_CLAUSE_MASK,
14675 "#pragma acc host_data");
14677 block = c_begin_omp_parallel ();
14678 add_stmt (c_parser_omp_structured_block (parser, if_p));
14679 stmt = c_finish_oacc_host_data (loc, clauses, block);
14686 # pragma acc loop oacc-loop-clause[optseq] new-line
14689 LOC is the location of the #pragma token.
14692 #define OACC_LOOP_CLAUSE_MASK \
14693 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14694 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14695 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14696 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14697 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14698 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14699 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14700 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14701 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14702 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14704 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name,
14705 omp_clause_mask mask, tree *cclauses, bool *if_p)
14707 bool is_parallel = ((mask >> PRAGMA_OACC_CLAUSE_REDUCTION) & 1) == 1;
14709 strcat (p_name, " loop");
14710 mask |= OACC_LOOP_CLAUSE_MASK;
14712 tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name,
14716 clauses = c_oacc_split_loop_clauses (clauses, cclauses, is_parallel);
14718 *cclauses = c_finish_omp_clauses (*cclauses, C_ORT_ACC);
14720 clauses = c_finish_omp_clauses (clauses, C_ORT_ACC);
14723 tree block = c_begin_compound_stmt (true);
14724 tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL,
14726 block = c_end_compound_stmt (loc, block, true);
14733 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14738 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14741 LOC is the location of the #pragma token.
14744 #define OACC_KERNELS_CLAUSE_MASK \
14745 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14747 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14748 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14749 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14750 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14753 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14754 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14755 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14756 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14763 #define OACC_PARALLEL_CLAUSE_MASK \
14764 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14765 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14766 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14767 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14768 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14769 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14770 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14771 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14772 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14773 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14774 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14775 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14776 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14777 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14778 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14779 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14780 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14781 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14782 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14783 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14786 c_parser_oacc_kernels_parallel (location_t loc, c_parser *parser,
14787 enum pragma_kind p_kind, char *p_name,
14790 omp_clause_mask mask;
14791 enum tree_code code;
14794 case PRAGMA_OACC_KERNELS:
14795 strcat (p_name, " kernels");
14796 mask = OACC_KERNELS_CLAUSE_MASK;
14797 code = OACC_KERNELS;
14799 case PRAGMA_OACC_PARALLEL:
14800 strcat (p_name, " parallel");
14801 mask = OACC_PARALLEL_CLAUSE_MASK;
14802 code = OACC_PARALLEL;
14805 gcc_unreachable ();
14808 if (c_parser_next_token_is (parser, CPP_NAME))
14810 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
14811 if (strcmp (p, "loop") == 0)
14813 c_parser_consume_token (parser);
14814 tree block = c_begin_omp_parallel ();
14816 c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p);
14817 return c_finish_omp_construct (loc, code, block, clauses);
14821 tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name);
14823 tree block = c_begin_omp_parallel ();
14824 add_stmt (c_parser_omp_structured_block (parser, if_p));
14826 return c_finish_omp_construct (loc, code, block, clauses);
14830 # pragma acc routine oacc-routine-clause[optseq] new-line
14831 function-definition
14833 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14836 #define OACC_ROUTINE_CLAUSE_MASK \
14837 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14842 /* Parse an OpenACC routine directive. For named directives, we apply
14843 immediately to the named function. For unnamed ones we then parse
14844 a declaration or definition, which must be for a function. */
14847 c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
14849 gcc_checking_assert (context == pragma_external);
14851 oacc_routine_data data;
14852 data.error_seen = false;
14853 data.fndecl_seen = false;
14854 data.clauses = NULL_TREE;
14855 data.loc = c_parser_peek_token (parser)->location;
14857 c_parser_consume_pragma (parser);
14859 /* Look for optional '( name )'. */
14860 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
14862 c_parser_consume_token (parser); /* '(' */
14864 tree decl = NULL_TREE;
14865 c_token *name_token = c_parser_peek_token (parser);
14866 location_t name_loc = name_token->location;
14867 if (name_token->type == CPP_NAME
14868 && (name_token->id_kind == C_ID_ID
14869 || name_token->id_kind == C_ID_TYPENAME))
14871 decl = lookup_name (name_token->value);
14873 error_at (name_loc,
14874 "%qE has not been declared", name_token->value);
14875 c_parser_consume_token (parser);
14878 c_parser_error (parser, "expected function name");
14881 || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
14883 c_parser_skip_to_pragma_eol (parser, false);
14888 = c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
14889 "#pragma acc routine");
14891 if (TREE_CODE (decl) != FUNCTION_DECL)
14893 error_at (name_loc, "%qD does not refer to a function", decl);
14897 c_finish_oacc_routine (&data, decl, false);
14899 else /* No optional '( name )'. */
14902 = c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
14903 "#pragma acc routine");
14905 /* Emit a helpful diagnostic if there's another pragma following this
14906 one. Also don't allow a static assertion declaration, as in the
14907 following we'll just parse a *single* "declaration or function
14908 definition", and the static assertion counts an one. */
14909 if (c_parser_next_token_is (parser, CPP_PRAGMA)
14910 || c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
14912 error_at (data.loc,
14913 "%<#pragma acc routine%> not immediately followed by"
14914 " function declaration or definition");
14915 /* ..., and then just keep going. */
14919 /* We only have to consider the pragma_external case here. */
14920 if (c_parser_next_token_is (parser, CPP_KEYWORD)
14921 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
14923 int ext = disable_extension_diagnostics ();
14925 c_parser_consume_token (parser);
14926 while (c_parser_next_token_is (parser, CPP_KEYWORD)
14927 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
14928 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14929 NULL, vNULL, &data);
14930 restore_extension_diagnostics (ext);
14933 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
14934 NULL, vNULL, &data);
14938 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14939 IS_DEFN is true if we're applying it to the definition. */
14942 c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl,
14945 /* Keep going if we're in error reporting mode. */
14946 if (data->error_seen
14947 || fndecl == error_mark_node)
14950 if (data->fndecl_seen)
14952 error_at (data->loc,
14953 "%<#pragma acc routine%> not immediately followed by"
14954 " a single function declaration or definition");
14955 data->error_seen = true;
14958 if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
14960 error_at (data->loc,
14961 "%<#pragma acc routine%> not immediately followed by"
14962 " function declaration or definition");
14963 data->error_seen = true;
14967 if (oacc_get_fn_attrib (fndecl))
14969 error_at (data->loc,
14970 "%<#pragma acc routine%> already applied to %qD", fndecl);
14971 data->error_seen = true;
14975 if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
14977 error_at (data->loc,
14979 ? G_("%<#pragma acc routine%> must be applied before use")
14980 : G_("%<#pragma acc routine%> must be applied before "
14982 data->error_seen = true;
14986 /* Process the routine's dimension clauses. */
14987 tree dims = oacc_build_routine_dims (data->clauses);
14988 oacc_replace_fn_attrib (fndecl, dims);
14990 /* Add an "omp declare target" attribute. */
14991 DECL_ATTRIBUTES (fndecl)
14992 = tree_cons (get_identifier ("omp declare target"),
14993 NULL_TREE, DECL_ATTRIBUTES (fndecl));
14995 /* Remember that we've used this "#pragma acc routine". */
14996 data->fndecl_seen = true;
15000 # pragma acc update oacc-update-clause[optseq] new-line
15003 #define OACC_UPDATE_CLAUSE_MASK \
15004 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
15006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
15007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
15009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15012 c_parser_oacc_update (c_parser *parser)
15014 location_t loc = c_parser_peek_token (parser)->location;
15016 c_parser_consume_pragma (parser);
15018 tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK,
15019 "#pragma acc update");
15020 if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE)
15023 "%<#pragma acc update%> must contain at least one "
15024 "%<device%> or %<host%> or %<self%> clause");
15031 tree stmt = make_node (OACC_UPDATE);
15032 TREE_TYPE (stmt) = void_type_node;
15033 OACC_UPDATE_CLAUSES (stmt) = clauses;
15034 SET_EXPR_LOCATION (stmt, loc);
15039 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15041 LOC is the location of the #pragma token.
15044 #define OACC_WAIT_CLAUSE_MASK \
15045 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15048 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name)
15050 tree clauses, list = NULL_TREE, stmt = NULL_TREE;
15052 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)
15053 list = c_parser_oacc_wait_list (parser, loc, list);
15055 strcpy (p_name, " wait");
15056 clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name);
15057 stmt = c_finish_oacc_wait (loc, list, clauses);
15064 # pragma omp atomic new-line
15068 x binop= expr | x++ | ++x | x-- | --x
15070 +, *, -, /, &, ^, |, <<, >>
15072 where x is an lvalue expression with scalar type.
15075 # pragma omp atomic new-line
15078 # pragma omp atomic read new-line
15081 # pragma omp atomic write new-line
15084 # pragma omp atomic update new-line
15087 # pragma omp atomic capture new-line
15090 # pragma omp atomic capture new-line
15098 expression-stmt | x = x binop expr
15100 v = expression-stmt
15102 { v = x; update-stmt; } | { update-stmt; v = x; }
15106 expression-stmt | x = x binop expr | x = expr binop x
15110 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15112 where x and v are lvalue expressions with scalar type.
15114 LOC is the location of the #pragma token. */
15117 c_parser_omp_atomic (location_t loc, c_parser *parser)
15119 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
15120 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
15121 tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
15122 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
15123 struct c_expr expr;
15125 bool structured_block = false;
15126 bool swapped = false;
15127 bool seq_cst = false;
15130 if (c_parser_next_token_is (parser, CPP_NAME))
15132 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15133 if (!strcmp (p, "seq_cst"))
15136 c_parser_consume_token (parser);
15137 if (c_parser_next_token_is (parser, CPP_COMMA)
15138 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
15139 c_parser_consume_token (parser);
15142 if (c_parser_next_token_is (parser, CPP_NAME))
15144 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15146 if (!strcmp (p, "read"))
15147 code = OMP_ATOMIC_READ;
15148 else if (!strcmp (p, "write"))
15150 else if (!strcmp (p, "update"))
15152 else if (!strcmp (p, "capture"))
15153 code = OMP_ATOMIC_CAPTURE_NEW;
15157 c_parser_consume_token (parser);
15161 if (c_parser_next_token_is (parser, CPP_COMMA)
15162 && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
15163 c_parser_consume_token (parser);
15165 if (c_parser_next_token_is (parser, CPP_NAME))
15168 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
15169 if (!strcmp (p, "seq_cst"))
15172 c_parser_consume_token (parser);
15176 c_parser_skip_to_pragma_eol (parser);
15180 case OMP_ATOMIC_READ:
15181 case NOP_EXPR: /* atomic write */
15182 v = c_parser_cast_expression (parser, NULL).value;
15183 non_lvalue_p = !lvalue_p (v);
15184 v = c_fully_fold (v, false, NULL, true);
15185 if (v == error_mark_node)
15188 v = non_lvalue (v);
15189 loc = c_parser_peek_token (parser)->location;
15190 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
15192 if (code == NOP_EXPR)
15194 lhs = c_parser_expression (parser).value;
15195 lhs = c_fully_fold (lhs, false, NULL);
15196 if (lhs == error_mark_node)
15201 lhs = c_parser_cast_expression (parser, NULL).value;
15202 non_lvalue_p = !lvalue_p (lhs);
15203 lhs = c_fully_fold (lhs, false, NULL, true);
15204 if (lhs == error_mark_node)
15207 lhs = non_lvalue (lhs);
15209 if (code == NOP_EXPR)
15211 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15219 case OMP_ATOMIC_CAPTURE_NEW:
15220 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
15222 c_parser_consume_token (parser);
15223 structured_block = true;
15227 v = c_parser_cast_expression (parser, NULL).value;
15228 non_lvalue_p = !lvalue_p (v);
15229 v = c_fully_fold (v, false, NULL, true);
15230 if (v == error_mark_node)
15233 v = non_lvalue (v);
15234 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
15242 /* For structured_block case we don't know yet whether
15243 old or new x should be captured. */
15245 eloc = c_parser_peek_token (parser)->location;
15246 expr = c_parser_cast_expression (parser, NULL);
15248 expr = default_function_array_conversion (eloc, expr);
15249 unfolded_lhs = expr.value;
15250 lhs = c_fully_fold (lhs, false, NULL, true);
15252 switch (TREE_CODE (lhs))
15256 c_parser_skip_to_end_of_block_or_statement (parser);
15257 if (structured_block)
15259 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15260 c_parser_consume_token (parser);
15261 else if (code == OMP_ATOMIC_CAPTURE_NEW)
15263 c_parser_skip_to_end_of_block_or_statement (parser);
15264 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15265 c_parser_consume_token (parser);
15270 case POSTINCREMENT_EXPR:
15271 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
15272 code = OMP_ATOMIC_CAPTURE_OLD;
15274 case PREINCREMENT_EXPR:
15275 lhs = TREE_OPERAND (lhs, 0);
15276 unfolded_lhs = NULL_TREE;
15277 opcode = PLUS_EXPR;
15278 rhs = integer_one_node;
15281 case POSTDECREMENT_EXPR:
15282 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
15283 code = OMP_ATOMIC_CAPTURE_OLD;
15285 case PREDECREMENT_EXPR:
15286 lhs = TREE_OPERAND (lhs, 0);
15287 unfolded_lhs = NULL_TREE;
15288 opcode = MINUS_EXPR;
15289 rhs = integer_one_node;
15292 case COMPOUND_EXPR:
15293 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
15294 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
15295 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
15296 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
15297 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15298 (TREE_OPERAND (lhs, 1), 0), 0)))
15300 /* Undo effects of boolean_increment for post {in,de}crement. */
15301 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
15304 if (TREE_CODE (lhs) == MODIFY_EXPR
15305 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
15307 /* Undo effects of boolean_increment. */
15308 if (integer_onep (TREE_OPERAND (lhs, 1)))
15310 /* This is pre or post increment. */
15311 rhs = TREE_OPERAND (lhs, 1);
15312 lhs = TREE_OPERAND (lhs, 0);
15313 unfolded_lhs = NULL_TREE;
15315 if (code == OMP_ATOMIC_CAPTURE_NEW
15316 && !structured_block
15317 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
15318 code = OMP_ATOMIC_CAPTURE_OLD;
15321 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
15322 && TREE_OPERAND (lhs, 0)
15323 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
15325 /* This is pre or post decrement. */
15326 rhs = TREE_OPERAND (lhs, 1);
15327 lhs = TREE_OPERAND (lhs, 0);
15328 unfolded_lhs = NULL_TREE;
15330 if (code == OMP_ATOMIC_CAPTURE_NEW
15331 && !structured_block
15332 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
15333 code = OMP_ATOMIC_CAPTURE_OLD;
15339 if (!lvalue_p (unfolded_lhs))
15340 lhs = non_lvalue (lhs);
15341 switch (c_parser_peek_token (parser)->type)
15344 opcode = MULT_EXPR;
15347 opcode = TRUNC_DIV_EXPR;
15350 opcode = PLUS_EXPR;
15353 opcode = MINUS_EXPR;
15355 case CPP_LSHIFT_EQ:
15356 opcode = LSHIFT_EXPR;
15358 case CPP_RSHIFT_EQ:
15359 opcode = RSHIFT_EXPR;
15362 opcode = BIT_AND_EXPR;
15365 opcode = BIT_IOR_EXPR;
15368 opcode = BIT_XOR_EXPR;
15371 c_parser_consume_token (parser);
15372 eloc = c_parser_peek_token (parser)->location;
15373 expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs);
15375 switch (TREE_CODE (rhs1))
15378 case TRUNC_DIV_EXPR:
15387 if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
15389 opcode = TREE_CODE (rhs1);
15390 rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
15392 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
15396 if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
15398 opcode = TREE_CODE (rhs1);
15399 rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
15401 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
15403 swapped = !commutative_tree_code (opcode);
15412 if (c_parser_peek_token (parser)->type == CPP_SEMICOLON)
15414 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
15416 code = OMP_ATOMIC_CAPTURE_OLD;
15419 expr = default_function_array_read_conversion (eloc, expr);
15420 unfolded_lhs1 = expr.value;
15421 lhs1 = c_fully_fold (unfolded_lhs1, false, NULL, true);
15423 c_parser_consume_token (parser);
15426 if (structured_block)
15429 expr = default_function_array_read_conversion (eloc, expr);
15430 rhs = c_fully_fold (expr.value, false, NULL, true);
15435 c_parser_error (parser, "invalid form of %<#pragma omp atomic%>");
15438 c_parser_error (parser,
15439 "invalid operator for %<#pragma omp atomic%>");
15443 /* Arrange to pass the location of the assignment operator to
15444 c_finish_omp_atomic. */
15445 loc = c_parser_peek_token (parser)->location;
15446 c_parser_consume_token (parser);
15447 eloc = c_parser_peek_token (parser)->location;
15448 expr = c_parser_expression (parser);
15449 expr = default_function_array_read_conversion (eloc, expr);
15451 rhs = c_fully_fold (rhs, false, NULL, true);
15455 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
15457 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
15459 v = c_parser_cast_expression (parser, NULL).value;
15460 non_lvalue_p = !lvalue_p (v);
15461 v = c_fully_fold (v, false, NULL, true);
15462 if (v == error_mark_node)
15465 v = non_lvalue (v);
15466 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
15468 eloc = c_parser_peek_token (parser)->location;
15469 expr = c_parser_cast_expression (parser, NULL);
15471 expr = default_function_array_read_conversion (eloc, expr);
15472 unfolded_lhs1 = expr.value;
15473 lhs1 = c_fully_fold (lhs1, false, NULL, true);
15474 if (lhs1 == error_mark_node)
15476 if (!lvalue_p (unfolded_lhs1))
15477 lhs1 = non_lvalue (lhs1);
15479 if (structured_block)
15481 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15482 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
15485 if (unfolded_lhs && unfolded_lhs1
15486 && !c_tree_equal (unfolded_lhs, unfolded_lhs1))
15488 error ("%<#pragma omp atomic capture%> uses two different "
15489 "expressions for memory");
15490 stmt = error_mark_node;
15493 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
15495 if (stmt != error_mark_node)
15498 if (!structured_block)
15499 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15504 # pragma omp barrier new-line
15508 c_parser_omp_barrier (c_parser *parser)
15510 location_t loc = c_parser_peek_token (parser)->location;
15511 c_parser_consume_pragma (parser);
15512 c_parser_skip_to_pragma_eol (parser);
15514 c_finish_omp_barrier (loc);
15518 # pragma omp critical [(name)] new-line
15522 # pragma omp critical [(name) [hint(expression)]] new-line
15524 LOC is the location of the #pragma itself. */
15526 #define OMP_CRITICAL_CLAUSE_MASK \
15527 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15530 c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p)
15532 tree stmt, name = NULL_TREE, clauses = NULL_TREE;
15534 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15536 c_parser_consume_token (parser);
15537 if (c_parser_next_token_is (parser, CPP_NAME))
15539 name = c_parser_peek_token (parser)->value;
15540 c_parser_consume_token (parser);
15541 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
15544 c_parser_error (parser, "expected identifier");
15546 clauses = c_parser_omp_all_clauses (parser,
15547 OMP_CRITICAL_CLAUSE_MASK,
15548 "#pragma omp critical");
15552 if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15553 c_parser_error (parser, "expected %<(%> or end of line");
15554 c_parser_skip_to_pragma_eol (parser);
15557 stmt = c_parser_omp_structured_block (parser, if_p);
15558 return c_finish_omp_critical (loc, stmt, name, clauses);
15562 # pragma omp flush flush-vars[opt] new-line
15565 ( variable-list ) */
15568 c_parser_omp_flush (c_parser *parser)
15570 location_t loc = c_parser_peek_token (parser)->location;
15571 c_parser_consume_pragma (parser);
15572 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
15573 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
15574 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
15575 c_parser_error (parser, "expected %<(%> or end of line");
15576 c_parser_skip_to_pragma_eol (parser);
15578 c_finish_omp_flush (loc);
15581 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15582 The real trick here is to determine the loop control variable early
15583 so that we can push a new decl if necessary to make it private.
15584 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15588 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
15589 tree clauses, tree *cclauses, bool *if_p)
15591 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
15592 tree declv, condv, incrv, initv, ret = NULL_TREE;
15593 tree pre_body = NULL_TREE, this_pre_body;
15594 tree ordered_cl = NULL_TREE;
15595 bool fail = false, open_brace_parsed = false;
15596 int i, collapse = 1, ordered = 0, count, nbraces = 0;
15597 location_t for_loc;
15598 bool tiling = false;
15599 vec<tree, va_gc> *for_block = make_tree_vector ();
15601 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
15602 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
15603 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
15604 else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
15607 collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
15609 else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
15610 && OMP_CLAUSE_ORDERED_EXPR (cl))
15613 ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl));
15616 if (ordered && ordered < collapse)
15618 error_at (OMP_CLAUSE_LOCATION (ordered_cl),
15619 "%<ordered%> clause parameter is less than %<collapse%>");
15620 OMP_CLAUSE_ORDERED_EXPR (ordered_cl)
15621 = build_int_cst (NULL_TREE, collapse);
15622 ordered = collapse;
15626 for (tree *pc = &clauses; *pc; )
15627 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR)
15629 error_at (OMP_CLAUSE_LOCATION (*pc),
15630 "%<linear%> clause may not be specified together "
15631 "with %<ordered%> clause with a parameter");
15632 *pc = OMP_CLAUSE_CHAIN (*pc);
15635 pc = &OMP_CLAUSE_CHAIN (*pc);
15638 gcc_assert (tiling || (collapse >= 1 && ordered >= 0));
15639 count = ordered ? ordered : collapse;
15641 declv = make_tree_vec (count);
15642 initv = make_tree_vec (count);
15643 condv = make_tree_vec (count);
15644 incrv = make_tree_vec (count);
15646 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
15648 c_parser_error (parser, "for statement expected");
15651 for_loc = c_parser_peek_token (parser)->location;
15652 c_parser_consume_token (parser);
15654 for (i = 0; i < count; i++)
15656 int bracecount = 0;
15658 matching_parens parens;
15659 if (!parens.require_open (parser))
15662 /* Parse the initialization declaration or expression. */
15663 if (c_parser_next_tokens_start_declaration (parser))
15666 vec_safe_push (for_block, c_begin_compound_stmt (true));
15667 this_pre_body = push_stmt_list ();
15668 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
15672 this_pre_body = pop_stmt_list (this_pre_body);
15676 pre_body = push_stmt_list ();
15678 add_stmt (this_pre_body);
15679 pre_body = pop_stmt_list (pre_body);
15682 pre_body = this_pre_body;
15684 decl = check_for_loop_decls (for_loc, flag_isoc99);
15687 if (DECL_INITIAL (decl) == error_mark_node)
15688 decl = error_mark_node;
15691 else if (c_parser_next_token_is (parser, CPP_NAME)
15692 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
15694 struct c_expr decl_exp;
15695 struct c_expr init_exp;
15696 location_t init_loc;
15698 decl_exp = c_parser_postfix_expression (parser);
15699 decl = decl_exp.value;
15701 c_parser_require (parser, CPP_EQ, "expected %<=%>");
15703 init_loc = c_parser_peek_token (parser)->location;
15704 init_exp = c_parser_expr_no_commas (parser, NULL);
15705 init_exp = default_function_array_read_conversion (init_loc,
15707 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
15708 NOP_EXPR, init_loc, init_exp.value,
15709 init_exp.original_type);
15710 init = c_process_expr_stmt (init_loc, init);
15712 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15717 c_parser_error (parser,
15718 "expected iteration declaration or initialization");
15719 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
15725 /* Parse the loop condition. */
15727 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
15729 location_t cond_loc = c_parser_peek_token (parser)->location;
15730 struct c_expr cond_expr
15731 = c_parser_binary_expression (parser, NULL, NULL_TREE);
15733 cond = cond_expr.value;
15734 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
15735 if (COMPARISON_CLASS_P (cond))
15737 tree op0 = TREE_OPERAND (cond, 0), op1 = TREE_OPERAND (cond, 1);
15738 op0 = c_fully_fold (op0, false, NULL);
15739 op1 = c_fully_fold (op1, false, NULL);
15740 TREE_OPERAND (cond, 0) = op0;
15741 TREE_OPERAND (cond, 1) = op1;
15743 switch (cond_expr.original_code)
15751 /* Can't be cond = error_mark_node, because we want to preserve
15752 the location until c_finish_omp_for. */
15753 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
15756 protected_set_expr_location (cond, cond_loc);
15758 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
15760 /* Parse the increment expression. */
15762 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
15764 location_t incr_loc = c_parser_peek_token (parser)->location;
15766 incr = c_process_expr_stmt (incr_loc,
15767 c_parser_expression (parser).value);
15769 parens.skip_until_found_close (parser);
15771 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
15775 TREE_VEC_ELT (declv, i) = decl;
15776 TREE_VEC_ELT (initv, i) = init;
15777 TREE_VEC_ELT (condv, i) = cond;
15778 TREE_VEC_ELT (incrv, i) = incr;
15782 if (i == count - 1)
15785 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15786 in between the collapsed for loops to be still considered perfectly
15787 nested. Hopefully the final version clarifies this.
15788 For now handle (multiple) {'s and empty statements. */
15791 if (c_parser_next_token_is_keyword (parser, RID_FOR))
15793 c_parser_consume_token (parser);
15796 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
15798 c_parser_consume_token (parser);
15801 else if (bracecount
15802 && c_parser_next_token_is (parser, CPP_SEMICOLON))
15803 c_parser_consume_token (parser);
15806 c_parser_error (parser, "not enough perfectly nested loops");
15809 open_brace_parsed = true;
15819 nbraces += bracecount;
15825 save_break = c_break_label;
15826 c_break_label = size_one_node;
15827 save_cont = c_cont_label;
15828 c_cont_label = NULL_TREE;
15829 body = push_stmt_list ();
15831 if (open_brace_parsed)
15833 location_t here = c_parser_peek_token (parser)->location;
15834 stmt = c_begin_compound_stmt (true);
15835 c_parser_compound_statement_nostart (parser);
15836 add_stmt (c_end_compound_stmt (here, stmt, true));
15839 add_stmt (c_parser_c99_block_statement (parser, if_p));
15842 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
15843 SET_EXPR_LOCATION (t, loc);
15847 body = pop_stmt_list (body);
15848 c_break_label = save_break;
15849 c_cont_label = save_cont;
15853 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
15855 c_parser_consume_token (parser);
15858 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
15859 c_parser_consume_token (parser);
15862 c_parser_error (parser, "collapsed loops not perfectly nested");
15865 location_t here = c_parser_peek_token (parser)->location;
15866 stmt = c_begin_compound_stmt (true);
15868 c_parser_compound_statement_nostart (parser);
15869 body = c_end_compound_stmt (here, stmt, true);
15876 /* Only bother calling c_finish_omp_for if we haven't already generated
15877 an error from the initialization parsing. */
15880 stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv,
15881 incrv, body, pre_body);
15883 /* Check for iterators appearing in lb, b or incr expressions. */
15884 if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL))
15891 if (cclauses != NULL
15892 && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL)
15895 for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; )
15896 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
15897 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
15898 c = &OMP_CLAUSE_CHAIN (*c);
15901 for (i = 0; i < count; i++)
15902 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
15905 c = &OMP_CLAUSE_CHAIN (*c);
15906 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
15909 "iteration variable %qD should not be firstprivate",
15910 OMP_CLAUSE_DECL (*c));
15911 *c = OMP_CLAUSE_CHAIN (*c);
15915 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15917 *c = OMP_CLAUSE_CHAIN (*c);
15918 if (code == OMP_SIMD)
15920 OMP_CLAUSE_CHAIN (l)
15921 = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
15922 cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
15926 OMP_CLAUSE_CHAIN (l) = clauses;
15932 OMP_FOR_CLAUSES (stmt) = clauses;
15937 while (!for_block->is_empty ())
15939 /* FIXME diagnostics: LOC below should be the actual location of
15940 this particular for block. We need to build a list of
15941 locations to go along with FOR_BLOCK. */
15942 stmt = c_end_compound_stmt (loc, for_block->pop (), true);
15945 release_tree_vector (for_block);
15949 /* Helper function for OpenMP parsing, split clauses and call
15950 finish_omp_clauses on each of the set of clauses afterwards. */
15953 omp_split_clauses (location_t loc, enum tree_code code,
15954 omp_clause_mask mask, tree clauses, tree *cclauses)
15957 c_omp_split_clauses (loc, code, mask, clauses, cclauses);
15958 for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
15960 cclauses[i] = c_finish_omp_clauses (cclauses[i], C_ORT_OMP);
15964 #pragma omp simd simd-clause[optseq] new-line
15967 LOC is the location of the #pragma token.
15970 #define OMP_SIMD_CLAUSE_MASK \
15971 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15972 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15973 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15981 c_parser_omp_simd (location_t loc, c_parser *parser,
15982 char *p_name, omp_clause_mask mask, tree *cclauses,
15985 tree block, clauses, ret;
15987 strcat (p_name, " simd");
15988 mask |= OMP_SIMD_CLAUSE_MASK;
15990 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
15993 omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses);
15994 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
15995 tree c = omp_find_clause (cclauses[C_OMP_CLAUSE_SPLIT_FOR],
15996 OMP_CLAUSE_ORDERED);
15997 if (c && OMP_CLAUSE_ORDERED_EXPR (c))
15999 error_at (OMP_CLAUSE_LOCATION (c),
16000 "%<ordered%> clause with parameter may not be specified "
16001 "on %qs construct", p_name);
16002 OMP_CLAUSE_ORDERED_EXPR (c) = NULL_TREE;
16006 block = c_begin_compound_stmt (true);
16007 ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p);
16008 block = c_end_compound_stmt (loc, block, true);
16015 #pragma omp for for-clause[optseq] new-line
16019 #pragma omp for simd for-simd-clause[optseq] new-line
16022 LOC is the location of the #pragma token.
16025 #define OMP_FOR_CLAUSE_MASK \
16026 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16027 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16028 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16029 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16030 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16031 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
16032 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
16033 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16034 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16037 c_parser_omp_for (location_t loc, c_parser *parser,
16038 char *p_name, omp_clause_mask mask, tree *cclauses,
16041 tree block, clauses, ret;
16043 strcat (p_name, " for");
16044 mask |= OMP_FOR_CLAUSE_MASK;
16045 /* parallel for{, simd} disallows nowait clause, but for
16046 target {teams distribute ,}parallel for{, simd} it should be accepted. */
16047 if (cclauses && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0)
16048 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
16049 /* Composite distribute parallel for{, simd} disallows ordered clause. */
16050 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
16051 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED);
16053 if (c_parser_next_token_is (parser, CPP_NAME))
16055 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16057 if (strcmp (p, "simd") == 0)
16059 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16060 if (cclauses == NULL)
16061 cclauses = cclauses_buf;
16063 c_parser_consume_token (parser);
16064 if (!flag_openmp) /* flag_openmp_simd */
16065 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
16067 block = c_begin_compound_stmt (true);
16068 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
16069 block = c_end_compound_stmt (loc, block, true);
16070 if (ret == NULL_TREE)
16072 ret = make_node (OMP_FOR);
16073 TREE_TYPE (ret) = void_type_node;
16074 OMP_FOR_BODY (ret) = block;
16075 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
16076 SET_EXPR_LOCATION (ret, loc);
16081 if (!flag_openmp) /* flag_openmp_simd */
16083 c_parser_skip_to_pragma_eol (parser, false);
16087 /* Composite distribute parallel for disallows linear clause. */
16088 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
16089 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR);
16091 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16094 omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses);
16095 clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
16098 block = c_begin_compound_stmt (true);
16099 ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p);
16100 block = c_end_compound_stmt (loc, block, true);
16107 # pragma omp master new-line
16110 LOC is the location of the #pragma token.
16114 c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p)
16116 c_parser_skip_to_pragma_eol (parser);
16117 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser,
16122 # pragma omp ordered new-line
16126 # pragma omp ordered ordered-clauses new-line
16129 # pragma omp ordered depend-clauses new-line */
16131 #define OMP_ORDERED_CLAUSE_MASK \
16132 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
16133 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16135 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
16136 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16139 c_parser_omp_ordered (c_parser *parser, enum pragma_context context,
16142 location_t loc = c_parser_peek_token (parser)->location;
16143 c_parser_consume_pragma (parser);
16145 if (context != pragma_stmt && context != pragma_compound)
16147 c_parser_error (parser, "expected declaration specifiers");
16148 c_parser_skip_to_pragma_eol (parser, false);
16152 if (c_parser_next_token_is (parser, CPP_NAME))
16154 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16156 if (!strcmp ("depend", p))
16158 if (!flag_openmp) /* flag_openmp_simd */
16160 c_parser_skip_to_pragma_eol (parser, false);
16163 if (context == pragma_stmt)
16166 "%<#pragma omp ordered%> with %<depend%> clause may "
16167 "only be used in compound statements");
16168 c_parser_skip_to_pragma_eol (parser, false);
16173 = c_parser_omp_all_clauses (parser,
16174 OMP_ORDERED_DEPEND_CLAUSE_MASK,
16175 "#pragma omp ordered");
16176 c_finish_omp_ordered (loc, clauses, NULL_TREE);
16181 tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK,
16182 "#pragma omp ordered");
16184 if (!flag_openmp /* flag_openmp_simd */
16185 && omp_find_clause (clauses, OMP_CLAUSE_SIMD) == NULL_TREE)
16188 c_finish_omp_ordered (loc, clauses,
16189 c_parser_omp_structured_block (parser, if_p));
16196 { section-sequence }
16199 section-directive[opt] structured-block
16200 section-sequence section-directive structured-block
16202 SECTIONS_LOC is the location of the #pragma omp sections. */
16205 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
16207 tree stmt, substmt;
16208 bool error_suppress = false;
16211 loc = c_parser_peek_token (parser)->location;
16212 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
16214 /* Avoid skipping until the end of the block. */
16215 parser->error = false;
16219 stmt = push_stmt_list ();
16221 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
16223 substmt = c_parser_omp_structured_block (parser, NULL);
16224 substmt = build1 (OMP_SECTION, void_type_node, substmt);
16225 SET_EXPR_LOCATION (substmt, loc);
16226 add_stmt (substmt);
16231 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
16233 if (c_parser_next_token_is (parser, CPP_EOF))
16236 loc = c_parser_peek_token (parser)->location;
16237 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
16239 c_parser_consume_pragma (parser);
16240 c_parser_skip_to_pragma_eol (parser);
16241 error_suppress = false;
16243 else if (!error_suppress)
16245 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
16246 error_suppress = true;
16249 substmt = c_parser_omp_structured_block (parser, NULL);
16250 substmt = build1 (OMP_SECTION, void_type_node, substmt);
16251 SET_EXPR_LOCATION (substmt, loc);
16252 add_stmt (substmt);
16254 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
16255 "expected %<#pragma omp section%> or %<}%>");
16257 substmt = pop_stmt_list (stmt);
16259 stmt = make_node (OMP_SECTIONS);
16260 SET_EXPR_LOCATION (stmt, sections_loc);
16261 TREE_TYPE (stmt) = void_type_node;
16262 OMP_SECTIONS_BODY (stmt) = substmt;
16264 return add_stmt (stmt);
16268 # pragma omp sections sections-clause[optseq] newline
16271 LOC is the location of the #pragma token.
16274 #define OMP_SECTIONS_CLAUSE_MASK \
16275 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16276 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16277 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16278 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16279 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16282 c_parser_omp_sections (location_t loc, c_parser *parser,
16283 char *p_name, omp_clause_mask mask, tree *cclauses)
16285 tree block, clauses, ret;
16287 strcat (p_name, " sections");
16288 mask |= OMP_SECTIONS_CLAUSE_MASK;
16290 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT);
16292 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16295 omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses);
16296 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS];
16299 block = c_begin_compound_stmt (true);
16300 ret = c_parser_omp_sections_scope (loc, parser);
16302 OMP_SECTIONS_CLAUSES (ret) = clauses;
16303 block = c_end_compound_stmt (loc, block, true);
16310 # pragma omp parallel parallel-clause[optseq] new-line
16312 # pragma omp parallel for parallel-for-clause[optseq] new-line
16314 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16318 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16321 LOC is the location of the #pragma token.
16324 #define OMP_PARALLEL_CLAUSE_MASK \
16325 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16326 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16327 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16328 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16329 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16330 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16331 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16332 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16333 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16336 c_parser_omp_parallel (location_t loc, c_parser *parser,
16337 char *p_name, omp_clause_mask mask, tree *cclauses,
16340 tree stmt, clauses, block;
16342 strcat (p_name, " parallel");
16343 mask |= OMP_PARALLEL_CLAUSE_MASK;
16344 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16345 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0
16346 && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0)
16347 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN);
16349 if (c_parser_next_token_is_keyword (parser, RID_FOR))
16351 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16352 if (cclauses == NULL)
16353 cclauses = cclauses_buf;
16355 c_parser_consume_token (parser);
16356 if (!flag_openmp) /* flag_openmp_simd */
16357 return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
16358 block = c_begin_omp_parallel ();
16359 tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
16361 = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
16363 if (ret == NULL_TREE)
16365 OMP_PARALLEL_COMBINED (stmt) = 1;
16368 /* When combined with distribute, parallel has to be followed by for.
16369 #pragma omp target parallel is allowed though. */
16371 && (mask & (OMP_CLAUSE_MASK_1
16372 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
16374 error_at (loc, "expected %<for%> after %qs", p_name);
16375 c_parser_skip_to_pragma_eol (parser);
16378 else if (!flag_openmp) /* flag_openmp_simd */
16380 c_parser_skip_to_pragma_eol (parser, false);
16383 else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME))
16385 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16386 if (strcmp (p, "sections") == 0)
16388 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16389 if (cclauses == NULL)
16390 cclauses = cclauses_buf;
16392 c_parser_consume_token (parser);
16393 block = c_begin_omp_parallel ();
16394 c_parser_omp_sections (loc, parser, p_name, mask, cclauses);
16395 stmt = c_finish_omp_parallel (loc,
16396 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
16398 OMP_PARALLEL_COMBINED (stmt) = 1;
16403 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16406 omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses);
16407 clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
16410 block = c_begin_omp_parallel ();
16411 c_parser_statement (parser, if_p);
16412 stmt = c_finish_omp_parallel (loc, clauses, block);
16418 # pragma omp single single-clause[optseq] new-line
16421 LOC is the location of the #pragma.
16424 #define OMP_SINGLE_CLAUSE_MASK \
16425 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16426 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16427 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16428 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16431 c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p)
16433 tree stmt = make_node (OMP_SINGLE);
16434 SET_EXPR_LOCATION (stmt, loc);
16435 TREE_TYPE (stmt) = void_type_node;
16437 OMP_SINGLE_CLAUSES (stmt)
16438 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
16439 "#pragma omp single");
16440 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
16442 return add_stmt (stmt);
16446 # pragma omp task task-clause[optseq] new-line
16448 LOC is the location of the #pragma.
16451 #define OMP_TASK_CLAUSE_MASK \
16452 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16453 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16454 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16455 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16456 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16457 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16458 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16459 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16460 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16461 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16464 c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p)
16466 tree clauses, block;
16468 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
16469 "#pragma omp task");
16471 block = c_begin_omp_task ();
16472 c_parser_statement (parser, if_p);
16473 return c_finish_omp_task (loc, clauses, block);
16477 # pragma omp taskwait new-line
16481 c_parser_omp_taskwait (c_parser *parser)
16483 location_t loc = c_parser_peek_token (parser)->location;
16484 c_parser_consume_pragma (parser);
16485 c_parser_skip_to_pragma_eol (parser);
16487 c_finish_omp_taskwait (loc);
16491 # pragma omp taskyield new-line
16495 c_parser_omp_taskyield (c_parser *parser)
16497 location_t loc = c_parser_peek_token (parser)->location;
16498 c_parser_consume_pragma (parser);
16499 c_parser_skip_to_pragma_eol (parser);
16501 c_finish_omp_taskyield (loc);
16505 # pragma omp taskgroup new-line
16509 c_parser_omp_taskgroup (c_parser *parser, bool *if_p)
16511 location_t loc = c_parser_peek_token (parser)->location;
16512 c_parser_skip_to_pragma_eol (parser);
16513 return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser,
16518 # pragma omp cancel cancel-clause[optseq] new-line
16520 LOC is the location of the #pragma.
16523 #define OMP_CANCEL_CLAUSE_MASK \
16524 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16525 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16527 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16528 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16531 c_parser_omp_cancel (c_parser *parser)
16533 location_t loc = c_parser_peek_token (parser)->location;
16535 c_parser_consume_pragma (parser);
16536 tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK,
16537 "#pragma omp cancel");
16539 c_finish_omp_cancel (loc, clauses);
16543 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16545 LOC is the location of the #pragma.
16548 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16549 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16551 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16552 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16555 c_parser_omp_cancellation_point (c_parser *parser, enum pragma_context context)
16557 location_t loc = c_parser_peek_token (parser)->location;
16559 bool point_seen = false;
16561 c_parser_consume_pragma (parser);
16562 if (c_parser_next_token_is (parser, CPP_NAME))
16564 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16565 if (strcmp (p, "point") == 0)
16567 c_parser_consume_token (parser);
16573 c_parser_error (parser, "expected %<point%>");
16574 c_parser_skip_to_pragma_eol (parser);
16578 if (context != pragma_compound)
16580 if (context == pragma_stmt)
16582 "%<#pragma %s%> may only be used in compound statements",
16583 "omp cancellation point");
16585 c_parser_error (parser, "expected declaration specifiers");
16586 c_parser_skip_to_pragma_eol (parser, false);
16591 = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK,
16592 "#pragma omp cancellation point");
16594 c_finish_omp_cancellation_point (loc, clauses);
16598 #pragma omp distribute distribute-clause[optseq] new-line
16601 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16602 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16609 c_parser_omp_distribute (location_t loc, c_parser *parser,
16610 char *p_name, omp_clause_mask mask, tree *cclauses,
16613 tree clauses, block, ret;
16615 strcat (p_name, " distribute");
16616 mask |= OMP_DISTRIBUTE_CLAUSE_MASK;
16618 if (c_parser_next_token_is (parser, CPP_NAME))
16620 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16622 bool parallel = false;
16624 if (strcmp (p, "simd") == 0)
16627 parallel = strcmp (p, "parallel") == 0;
16628 if (parallel || simd)
16630 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16631 if (cclauses == NULL)
16632 cclauses = cclauses_buf;
16633 c_parser_consume_token (parser);
16634 if (!flag_openmp) /* flag_openmp_simd */
16637 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
16640 return c_parser_omp_parallel (loc, parser, p_name, mask,
16643 block = c_begin_compound_stmt (true);
16645 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
16648 ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses,
16650 block = c_end_compound_stmt (loc, block, true);
16653 ret = make_node (OMP_DISTRIBUTE);
16654 TREE_TYPE (ret) = void_type_node;
16655 OMP_FOR_BODY (ret) = block;
16656 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
16657 SET_EXPR_LOCATION (ret, loc);
16662 if (!flag_openmp) /* flag_openmp_simd */
16664 c_parser_skip_to_pragma_eol (parser, false);
16668 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16671 omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses);
16672 clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
16675 block = c_begin_compound_stmt (true);
16676 ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL,
16678 block = c_end_compound_stmt (loc, block, true);
16685 # pragma omp teams teams-clause[optseq] new-line
16686 structured-block */
16688 #define OMP_TEAMS_CLAUSE_MASK \
16689 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16690 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16691 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16692 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16693 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16694 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16695 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16698 c_parser_omp_teams (location_t loc, c_parser *parser,
16699 char *p_name, omp_clause_mask mask, tree *cclauses,
16702 tree clauses, block, ret;
16704 strcat (p_name, " teams");
16705 mask |= OMP_TEAMS_CLAUSE_MASK;
16707 if (c_parser_next_token_is (parser, CPP_NAME))
16709 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16710 if (strcmp (p, "distribute") == 0)
16712 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
16713 if (cclauses == NULL)
16714 cclauses = cclauses_buf;
16716 c_parser_consume_token (parser);
16717 if (!flag_openmp) /* flag_openmp_simd */
16718 return c_parser_omp_distribute (loc, parser, p_name, mask,
16720 block = c_begin_compound_stmt (true);
16721 ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses,
16723 block = c_end_compound_stmt (loc, block, true);
16726 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
16727 ret = make_node (OMP_TEAMS);
16728 TREE_TYPE (ret) = void_type_node;
16729 OMP_TEAMS_CLAUSES (ret) = clauses;
16730 OMP_TEAMS_BODY (ret) = block;
16731 OMP_TEAMS_COMBINED (ret) = 1;
16732 return add_stmt (ret);
16735 if (!flag_openmp) /* flag_openmp_simd */
16737 c_parser_skip_to_pragma_eol (parser, false);
16741 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
16744 omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses);
16745 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
16748 tree stmt = make_node (OMP_TEAMS);
16749 TREE_TYPE (stmt) = void_type_node;
16750 OMP_TEAMS_CLAUSES (stmt) = clauses;
16751 OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
16753 return add_stmt (stmt);
16757 # pragma omp target data target-data-clause[optseq] new-line
16758 structured-block */
16760 #define OMP_TARGET_DATA_CLAUSE_MASK \
16761 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16767 c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p)
16770 = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
16771 "#pragma omp target data");
16773 for (tree *pc = &clauses; *pc;)
16775 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16776 switch (OMP_CLAUSE_MAP_KIND (*pc))
16779 case GOMP_MAP_ALWAYS_TO:
16780 case GOMP_MAP_FROM:
16781 case GOMP_MAP_ALWAYS_FROM:
16782 case GOMP_MAP_TOFROM:
16783 case GOMP_MAP_ALWAYS_TOFROM:
16784 case GOMP_MAP_ALLOC:
16787 case GOMP_MAP_FIRSTPRIVATE_POINTER:
16788 case GOMP_MAP_ALWAYS_POINTER:
16792 error_at (OMP_CLAUSE_LOCATION (*pc),
16793 "%<#pragma omp target data%> with map-type other "
16794 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16795 "on %<map%> clause");
16796 *pc = OMP_CLAUSE_CHAIN (*pc);
16799 pc = &OMP_CLAUSE_CHAIN (*pc);
16806 "%<#pragma omp target data%> must contain at least "
16807 "one %<map%> clause");
16811 tree stmt = make_node (OMP_TARGET_DATA);
16812 TREE_TYPE (stmt) = void_type_node;
16813 OMP_TARGET_DATA_CLAUSES (stmt) = clauses;
16814 keep_next_level ();
16815 tree block = c_begin_compound_stmt (true);
16816 add_stmt (c_parser_omp_structured_block (parser, if_p));
16817 OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
16819 SET_EXPR_LOCATION (stmt, loc);
16820 return add_stmt (stmt);
16824 # pragma omp target update target-update-clause[optseq] new-line */
16826 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16827 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16828 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16829 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16830 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16831 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16832 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16835 c_parser_omp_target_update (location_t loc, c_parser *parser,
16836 enum pragma_context context)
16838 if (context == pragma_stmt)
16840 error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16841 "omp target update");
16842 c_parser_skip_to_pragma_eol (parser, false);
16847 = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK,
16848 "#pragma omp target update");
16849 if (omp_find_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE
16850 && omp_find_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
16853 "%<#pragma omp target update%> must contain at least one "
16854 "%<from%> or %<to%> clauses");
16858 tree stmt = make_node (OMP_TARGET_UPDATE);
16859 TREE_TYPE (stmt) = void_type_node;
16860 OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
16861 SET_EXPR_LOCATION (stmt, loc);
16867 # pragma omp target enter data target-data-clause[optseq] new-line */
16869 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16870 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16874 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16877 c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
16878 enum pragma_context context)
16880 bool data_seen = false;
16881 if (c_parser_next_token_is (parser, CPP_NAME))
16883 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16884 if (strcmp (p, "data") == 0)
16886 c_parser_consume_token (parser);
16892 c_parser_error (parser, "expected %<data%>");
16893 c_parser_skip_to_pragma_eol (parser);
16897 if (context == pragma_stmt)
16899 error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16900 "omp target enter data");
16901 c_parser_skip_to_pragma_eol (parser, false);
16906 = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK,
16907 "#pragma omp target enter data");
16909 for (tree *pc = &clauses; *pc;)
16911 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16912 switch (OMP_CLAUSE_MAP_KIND (*pc))
16915 case GOMP_MAP_ALWAYS_TO:
16916 case GOMP_MAP_ALLOC:
16919 case GOMP_MAP_FIRSTPRIVATE_POINTER:
16920 case GOMP_MAP_ALWAYS_POINTER:
16924 error_at (OMP_CLAUSE_LOCATION (*pc),
16925 "%<#pragma omp target enter data%> with map-type other "
16926 "than %<to%> or %<alloc%> on %<map%> clause");
16927 *pc = OMP_CLAUSE_CHAIN (*pc);
16930 pc = &OMP_CLAUSE_CHAIN (*pc);
16937 "%<#pragma omp target enter data%> must contain at least "
16938 "one %<map%> clause");
16942 tree stmt = make_node (OMP_TARGET_ENTER_DATA);
16943 TREE_TYPE (stmt) = void_type_node;
16944 OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses;
16945 SET_EXPR_LOCATION (stmt, loc);
16951 # pragma omp target exit data target-data-clause[optseq] new-line */
16953 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16954 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16955 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16956 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16957 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16958 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16961 c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
16962 enum pragma_context context)
16964 bool data_seen = false;
16965 if (c_parser_next_token_is (parser, CPP_NAME))
16967 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
16968 if (strcmp (p, "data") == 0)
16970 c_parser_consume_token (parser);
16976 c_parser_error (parser, "expected %<data%>");
16977 c_parser_skip_to_pragma_eol (parser);
16981 if (context == pragma_stmt)
16983 error_at (loc, "%<#pragma %s%> may only be used in compound statements",
16984 "omp target exit data");
16985 c_parser_skip_to_pragma_eol (parser, false);
16990 = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK,
16991 "#pragma omp target exit data");
16994 for (tree *pc = &clauses; *pc;)
16996 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
16997 switch (OMP_CLAUSE_MAP_KIND (*pc))
16999 case GOMP_MAP_FROM:
17000 case GOMP_MAP_ALWAYS_FROM:
17001 case GOMP_MAP_RELEASE:
17002 case GOMP_MAP_DELETE:
17005 case GOMP_MAP_FIRSTPRIVATE_POINTER:
17006 case GOMP_MAP_ALWAYS_POINTER:
17010 error_at (OMP_CLAUSE_LOCATION (*pc),
17011 "%<#pragma omp target exit data%> with map-type other "
17012 "than %<from%>, %<release%> or %<delete%> on %<map%>"
17014 *pc = OMP_CLAUSE_CHAIN (*pc);
17017 pc = &OMP_CLAUSE_CHAIN (*pc);
17024 "%<#pragma omp target exit data%> must contain at least one "
17029 tree stmt = make_node (OMP_TARGET_EXIT_DATA);
17030 TREE_TYPE (stmt) = void_type_node;
17031 OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses;
17032 SET_EXPR_LOCATION (stmt, loc);
17038 # pragma omp target target-clause[optseq] new-line
17039 structured-block */
17041 #define OMP_TARGET_CLAUSE_MASK \
17042 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
17047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
17050 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
17053 c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p)
17055 location_t loc = c_parser_peek_token (parser)->location;
17056 c_parser_consume_pragma (parser);
17057 tree *pc = NULL, stmt, block;
17059 if (context != pragma_stmt && context != pragma_compound)
17061 c_parser_error (parser, "expected declaration specifiers");
17062 c_parser_skip_to_pragma_eol (parser);
17066 if (c_parser_next_token_is (parser, CPP_NAME))
17068 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17069 enum tree_code ccode = ERROR_MARK;
17071 if (strcmp (p, "teams") == 0)
17073 else if (strcmp (p, "parallel") == 0)
17074 ccode = OMP_PARALLEL;
17075 else if (strcmp (p, "simd") == 0)
17077 if (ccode != ERROR_MARK)
17079 tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT];
17080 char p_name[sizeof ("#pragma omp target teams distribute "
17081 "parallel for simd")];
17083 c_parser_consume_token (parser);
17084 strcpy (p_name, "#pragma omp target");
17085 if (!flag_openmp) /* flag_openmp_simd */
17091 stmt = c_parser_omp_teams (loc, parser, p_name,
17092 OMP_TARGET_CLAUSE_MASK,
17096 stmt = c_parser_omp_parallel (loc, parser, p_name,
17097 OMP_TARGET_CLAUSE_MASK,
17101 stmt = c_parser_omp_simd (loc, parser, p_name,
17102 OMP_TARGET_CLAUSE_MASK,
17106 gcc_unreachable ();
17108 return stmt != NULL_TREE;
17110 keep_next_level ();
17111 tree block = c_begin_compound_stmt (true), ret;
17115 ret = c_parser_omp_teams (loc, parser, p_name,
17116 OMP_TARGET_CLAUSE_MASK, cclauses,
17120 ret = c_parser_omp_parallel (loc, parser, p_name,
17121 OMP_TARGET_CLAUSE_MASK, cclauses,
17125 ret = c_parser_omp_simd (loc, parser, p_name,
17126 OMP_TARGET_CLAUSE_MASK, cclauses,
17130 gcc_unreachable ();
17132 block = c_end_compound_stmt (loc, block, true);
17133 if (ret == NULL_TREE)
17135 if (ccode == OMP_TEAMS)
17137 /* For combined target teams, ensure the num_teams and
17138 thread_limit clause expressions are evaluated on the host,
17139 before entering the target construct. */
17141 for (c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
17142 c; c = OMP_CLAUSE_CHAIN (c))
17143 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
17144 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT)
17145 && TREE_CODE (OMP_CLAUSE_OPERAND (c, 0)) != INTEGER_CST)
17147 tree expr = OMP_CLAUSE_OPERAND (c, 0);
17148 tree tmp = create_tmp_var_raw (TREE_TYPE (expr));
17149 expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp,
17150 expr, NULL_TREE, NULL_TREE);
17152 OMP_CLAUSE_OPERAND (c, 0) = expr;
17153 tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c),
17154 OMP_CLAUSE_FIRSTPRIVATE);
17155 OMP_CLAUSE_DECL (tc) = tmp;
17156 OMP_CLAUSE_CHAIN (tc)
17157 = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
17158 cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc;
17161 tree stmt = make_node (OMP_TARGET);
17162 TREE_TYPE (stmt) = void_type_node;
17163 OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
17164 OMP_TARGET_BODY (stmt) = block;
17165 OMP_TARGET_COMBINED (stmt) = 1;
17167 pc = &OMP_TARGET_CLAUSES (stmt);
17168 goto check_clauses;
17170 else if (!flag_openmp) /* flag_openmp_simd */
17172 c_parser_skip_to_pragma_eol (parser, false);
17175 else if (strcmp (p, "data") == 0)
17177 c_parser_consume_token (parser);
17178 c_parser_omp_target_data (loc, parser, if_p);
17181 else if (strcmp (p, "enter") == 0)
17183 c_parser_consume_token (parser);
17184 c_parser_omp_target_enter_data (loc, parser, context);
17187 else if (strcmp (p, "exit") == 0)
17189 c_parser_consume_token (parser);
17190 c_parser_omp_target_exit_data (loc, parser, context);
17193 else if (strcmp (p, "update") == 0)
17195 c_parser_consume_token (parser);
17196 return c_parser_omp_target_update (loc, parser, context);
17199 if (!flag_openmp) /* flag_openmp_simd */
17201 c_parser_skip_to_pragma_eol (parser, false);
17205 stmt = make_node (OMP_TARGET);
17206 TREE_TYPE (stmt) = void_type_node;
17208 OMP_TARGET_CLAUSES (stmt)
17209 = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK,
17210 "#pragma omp target");
17211 pc = &OMP_TARGET_CLAUSES (stmt);
17212 keep_next_level ();
17213 block = c_begin_compound_stmt (true);
17214 add_stmt (c_parser_omp_structured_block (parser, if_p));
17215 OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
17217 SET_EXPR_LOCATION (stmt, loc);
17223 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP)
17224 switch (OMP_CLAUSE_MAP_KIND (*pc))
17227 case GOMP_MAP_ALWAYS_TO:
17228 case GOMP_MAP_FROM:
17229 case GOMP_MAP_ALWAYS_FROM:
17230 case GOMP_MAP_TOFROM:
17231 case GOMP_MAP_ALWAYS_TOFROM:
17232 case GOMP_MAP_ALLOC:
17233 case GOMP_MAP_FIRSTPRIVATE_POINTER:
17234 case GOMP_MAP_ALWAYS_POINTER:
17237 error_at (OMP_CLAUSE_LOCATION (*pc),
17238 "%<#pragma omp target%> with map-type other "
17239 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17240 "on %<map%> clause");
17241 *pc = OMP_CLAUSE_CHAIN (*pc);
17244 pc = &OMP_CLAUSE_CHAIN (*pc);
17250 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17252 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17253 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17254 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17255 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17256 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17257 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17258 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17261 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
17263 auto_vec<c_token> clauses;
17264 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17266 c_token *token = c_parser_peek_token (parser);
17267 if (token->type == CPP_EOF)
17269 c_parser_skip_to_pragma_eol (parser);
17272 clauses.safe_push (*token);
17273 c_parser_consume_token (parser);
17275 clauses.safe_push (*c_parser_peek_token (parser));
17276 c_parser_skip_to_pragma_eol (parser);
17278 while (c_parser_next_token_is (parser, CPP_PRAGMA))
17280 if (c_parser_peek_token (parser)->pragma_kind
17281 != PRAGMA_OMP_DECLARE
17282 || c_parser_peek_2nd_token (parser)->type != CPP_NAME
17283 || strcmp (IDENTIFIER_POINTER
17284 (c_parser_peek_2nd_token (parser)->value),
17287 c_parser_error (parser,
17288 "%<#pragma omp declare simd%> must be followed by "
17289 "function declaration or definition or another "
17290 "%<#pragma omp declare simd%>");
17293 c_parser_consume_pragma (parser);
17294 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17296 c_token *token = c_parser_peek_token (parser);
17297 if (token->type == CPP_EOF)
17299 c_parser_skip_to_pragma_eol (parser);
17302 clauses.safe_push (*token);
17303 c_parser_consume_token (parser);
17305 clauses.safe_push (*c_parser_peek_token (parser));
17306 c_parser_skip_to_pragma_eol (parser);
17309 /* Make sure nothing tries to read past the end of the tokens. */
17311 memset (&eof_token, 0, sizeof (eof_token));
17312 eof_token.type = CPP_EOF;
17313 clauses.safe_push (eof_token);
17314 clauses.safe_push (eof_token);
17318 case pragma_external:
17319 if (c_parser_next_token_is (parser, CPP_KEYWORD)
17320 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
17322 int ext = disable_extension_diagnostics ();
17324 c_parser_consume_token (parser);
17325 while (c_parser_next_token_is (parser, CPP_KEYWORD)
17326 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
17327 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
17329 restore_extension_diagnostics (ext);
17332 c_parser_declaration_or_fndef (parser, true, true, true, false, true,
17335 case pragma_struct:
17338 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
17339 "function declaration or definition");
17341 case pragma_compound:
17342 if (c_parser_next_token_is (parser, CPP_KEYWORD)
17343 && c_parser_peek_token (parser)->keyword == RID_EXTENSION)
17345 int ext = disable_extension_diagnostics ();
17347 c_parser_consume_token (parser);
17348 while (c_parser_next_token_is (parser, CPP_KEYWORD)
17349 && c_parser_peek_token (parser)->keyword == RID_EXTENSION);
17350 if (c_parser_next_tokens_start_declaration (parser))
17352 c_parser_declaration_or_fndef (parser, true, true, true, true,
17353 true, NULL, clauses);
17354 restore_extension_diagnostics (ext);
17357 restore_extension_diagnostics (ext);
17359 else if (c_parser_next_tokens_start_declaration (parser))
17361 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
17365 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
17366 "function declaration or definition");
17369 gcc_unreachable ();
17373 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17374 and put that into "omp declare simd" attribute. */
17377 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
17378 vec<c_token> clauses)
17380 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17381 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17382 has already processed the tokens. */
17383 if (clauses.exists () && clauses[0].type == CPP_EOF)
17385 if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL)
17387 error ("%<#pragma omp declare simd%> not immediately followed by "
17388 "a function declaration or definition");
17389 clauses[0].type = CPP_EOF;
17392 if (clauses.exists () && clauses[0].type != CPP_NAME)
17394 error_at (DECL_SOURCE_LOCATION (fndecl),
17395 "%<#pragma omp declare simd%> not immediately followed by "
17396 "a single function declaration or definition");
17397 clauses[0].type = CPP_EOF;
17401 if (parms == NULL_TREE)
17402 parms = DECL_ARGUMENTS (fndecl);
17404 unsigned int tokens_avail = parser->tokens_avail;
17405 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
17408 parser->tokens = clauses.address ();
17409 parser->tokens_avail = clauses.length ();
17411 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17412 while (parser->tokens_avail > 3)
17414 c_token *token = c_parser_peek_token (parser);
17415 gcc_assert (token->type == CPP_NAME
17416 && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
17417 c_parser_consume_token (parser);
17418 parser->in_pragma = true;
17420 tree c = NULL_TREE;
17421 c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
17422 "#pragma omp declare simd");
17423 c = c_omp_declare_simd_clauses_to_numbers (parms, c);
17424 if (c != NULL_TREE)
17425 c = tree_cons (NULL_TREE, c, NULL_TREE);
17426 c = build_tree_list (get_identifier ("omp declare simd"), c);
17427 TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
17428 DECL_ATTRIBUTES (fndecl) = c;
17431 parser->tokens = &parser->tokens_buf[0];
17432 parser->tokens_avail = tokens_avail;
17433 if (clauses.exists ())
17434 clauses[0].type = CPP_PRAGMA;
17439 # pragma omp declare target new-line
17440 declarations and definitions
17441 # pragma omp end declare target new-line
17444 # pragma omp declare target ( extended-list ) new-line
17446 # pragma omp declare target declare-target-clauses[seq] new-line */
17448 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17449 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17450 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17453 c_parser_omp_declare_target (c_parser *parser)
17455 location_t loc = c_parser_peek_token (parser)->location;
17456 tree clauses = NULL_TREE;
17457 if (c_parser_next_token_is (parser, CPP_NAME))
17458 clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK,
17459 "#pragma omp declare target");
17460 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
17462 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
17464 clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
17465 c_parser_skip_to_pragma_eol (parser);
17469 c_parser_skip_to_pragma_eol (parser);
17470 current_omp_declare_target_attribute++;
17473 if (current_omp_declare_target_attribute)
17474 error_at (loc, "%<#pragma omp declare target%> with clauses in between "
17475 "%<#pragma omp declare target%> without clauses and "
17476 "%<#pragma omp end declare target%>");
17477 for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
17479 tree t = OMP_CLAUSE_DECL (c), id;
17480 tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
17481 tree at2 = lookup_attribute ("omp declare target link",
17482 DECL_ATTRIBUTES (t));
17483 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
17485 id = get_identifier ("omp declare target link");
17486 std::swap (at1, at2);
17489 id = get_identifier ("omp declare target");
17492 error_at (OMP_CLAUSE_LOCATION (c),
17493 "%qD specified both in declare target %<link%> and %<to%>"
17499 DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
17500 if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
17503 symtab_node *node = symtab_node::get (t);
17506 node->offloadable = 1;
17507 if (ENABLE_OFFLOADING)
17509 g->have_offload = true;
17510 if (is_a <varpool_node *> (node))
17511 vec_safe_push (offload_vars, t);
17519 c_parser_omp_end_declare_target (c_parser *parser)
17521 location_t loc = c_parser_peek_token (parser)->location;
17522 c_parser_consume_pragma (parser);
17523 if (c_parser_next_token_is (parser, CPP_NAME)
17524 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
17527 c_parser_consume_token (parser);
17528 if (c_parser_next_token_is (parser, CPP_NAME)
17529 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
17531 c_parser_consume_token (parser);
17534 c_parser_error (parser, "expected %<target%>");
17535 c_parser_skip_to_pragma_eol (parser);
17541 c_parser_error (parser, "expected %<declare%>");
17542 c_parser_skip_to_pragma_eol (parser);
17545 c_parser_skip_to_pragma_eol (parser);
17546 if (!current_omp_declare_target_attribute)
17547 error_at (loc, "%<#pragma omp end declare target%> without corresponding "
17548 "%<#pragma omp declare target%>");
17550 current_omp_declare_target_attribute--;
17555 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17556 initializer-clause[opt] new-line
17558 initializer-clause:
17559 initializer (omp_priv = initializer)
17560 initializer (function-name (argument-list)) */
17563 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context)
17565 unsigned int tokens_avail = 0, i;
17566 vec<tree> types = vNULL;
17567 vec<c_token> clauses = vNULL;
17568 enum tree_code reduc_code = ERROR_MARK;
17569 tree reduc_id = NULL_TREE;
17571 location_t rloc = c_parser_peek_token (parser)->location;
17573 if (context == pragma_struct || context == pragma_param)
17575 error ("%<#pragma omp declare reduction%> not at file or block scope");
17579 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17582 switch (c_parser_peek_token (parser)->type)
17585 reduc_code = PLUS_EXPR;
17588 reduc_code = MULT_EXPR;
17591 reduc_code = MINUS_EXPR;
17594 reduc_code = BIT_AND_EXPR;
17597 reduc_code = BIT_XOR_EXPR;
17600 reduc_code = BIT_IOR_EXPR;
17603 reduc_code = TRUTH_ANDIF_EXPR;
17606 reduc_code = TRUTH_ORIF_EXPR;
17610 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17611 if (strcmp (p, "min") == 0)
17613 reduc_code = MIN_EXPR;
17616 if (strcmp (p, "max") == 0)
17618 reduc_code = MAX_EXPR;
17621 reduc_id = c_parser_peek_token (parser)->value;
17624 c_parser_error (parser,
17625 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17626 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17630 tree orig_reduc_id, reduc_decl;
17631 orig_reduc_id = reduc_id;
17632 reduc_id = c_omp_reduction_id (reduc_code, reduc_id);
17633 reduc_decl = c_omp_reduction_decl (reduc_id);
17634 c_parser_consume_token (parser);
17636 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
17641 location_t loc = c_parser_peek_token (parser)->location;
17642 struct c_type_name *ctype = c_parser_type_name (parser);
17645 type = groktypename (ctype, NULL, NULL);
17646 if (type == error_mark_node)
17648 else if ((INTEGRAL_TYPE_P (type)
17649 || TREE_CODE (type) == REAL_TYPE
17650 || TREE_CODE (type) == COMPLEX_TYPE)
17651 && orig_reduc_id == NULL_TREE)
17652 error_at (loc, "predeclared arithmetic type in "
17653 "%<#pragma omp declare reduction%>");
17654 else if (TREE_CODE (type) == FUNCTION_TYPE
17655 || TREE_CODE (type) == ARRAY_TYPE)
17656 error_at (loc, "function or array type in "
17657 "%<#pragma omp declare reduction%>");
17658 else if (TYPE_ATOMIC (type))
17659 error_at (loc, "%<_Atomic%> qualified type in "
17660 "%<#pragma omp declare reduction%>");
17661 else if (TYPE_QUALS_NO_ADDR_SPACE (type))
17662 error_at (loc, "const, volatile or restrict qualified type in "
17663 "%<#pragma omp declare reduction%>");
17667 for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t))
17668 if (comptypes (TREE_PURPOSE (t), type))
17670 error_at (loc, "redeclaration of %qs "
17671 "%<#pragma omp declare reduction%> for "
17673 IDENTIFIER_POINTER (reduc_id)
17674 + sizeof ("omp declare reduction ") - 1,
17677 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t),
17679 error_at (ploc, "previous %<#pragma omp declare "
17683 if (t == NULL_TREE)
17684 types.safe_push (type);
17686 if (c_parser_next_token_is (parser, CPP_COMMA))
17687 c_parser_consume_token (parser);
17695 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")
17696 || types.is_empty ())
17699 clauses.release ();
17703 c_token *token = c_parser_peek_token (parser);
17704 if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL)
17706 c_parser_consume_token (parser);
17708 c_parser_skip_to_pragma_eol (parser);
17712 if (types.length () > 1)
17714 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
17716 c_token *token = c_parser_peek_token (parser);
17717 if (token->type == CPP_EOF)
17719 clauses.safe_push (*token);
17720 c_parser_consume_token (parser);
17722 clauses.safe_push (*c_parser_peek_token (parser));
17723 c_parser_skip_to_pragma_eol (parser);
17725 /* Make sure nothing tries to read past the end of the tokens. */
17727 memset (&eof_token, 0, sizeof (eof_token));
17728 eof_token.type = CPP_EOF;
17729 clauses.safe_push (eof_token);
17730 clauses.safe_push (eof_token);
17733 int errs = errorcount;
17734 FOR_EACH_VEC_ELT (types, i, type)
17736 tokens_avail = parser->tokens_avail;
17737 gcc_assert (parser->tokens == &parser->tokens_buf[0]);
17738 if (!clauses.is_empty ())
17740 parser->tokens = clauses.address ();
17741 parser->tokens_avail = clauses.length ();
17742 parser->in_pragma = true;
17745 bool nested = current_function_decl != NULL_TREE;
17747 c_push_function_context ();
17748 tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
17749 reduc_id, default_function_type);
17750 current_function_decl = fndecl;
17751 allocate_struct_function (fndecl, true);
17753 tree stmt = push_stmt_list ();
17754 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17755 warn about these. */
17756 tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL,
17757 get_identifier ("omp_out"), type);
17758 DECL_ARTIFICIAL (omp_out) = 1;
17759 DECL_CONTEXT (omp_out) = fndecl;
17760 pushdecl (omp_out);
17761 tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL,
17762 get_identifier ("omp_in"), type);
17763 DECL_ARTIFICIAL (omp_in) = 1;
17764 DECL_CONTEXT (omp_in) = fndecl;
17766 struct c_expr combiner = c_parser_expression (parser);
17767 struct c_expr initializer;
17768 tree omp_priv = NULL_TREE, omp_orig = NULL_TREE;
17770 initializer.set_error ();
17771 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
17773 else if (c_parser_next_token_is (parser, CPP_NAME)
17774 && strcmp (IDENTIFIER_POINTER
17775 (c_parser_peek_token (parser)->value),
17776 "initializer") == 0)
17778 c_parser_consume_token (parser);
17781 omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL,
17782 get_identifier ("omp_priv"), type);
17783 DECL_ARTIFICIAL (omp_priv) = 1;
17784 DECL_INITIAL (omp_priv) = error_mark_node;
17785 DECL_CONTEXT (omp_priv) = fndecl;
17786 pushdecl (omp_priv);
17787 omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL,
17788 get_identifier ("omp_orig"), type);
17789 DECL_ARTIFICIAL (omp_orig) = 1;
17790 DECL_CONTEXT (omp_orig) = fndecl;
17791 pushdecl (omp_orig);
17792 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
17794 else if (!c_parser_next_token_is (parser, CPP_NAME))
17796 c_parser_error (parser, "expected %<omp_priv%> or "
17800 else if (strcmp (IDENTIFIER_POINTER
17801 (c_parser_peek_token (parser)->value),
17804 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
17805 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
17807 c_parser_error (parser, "expected function-name %<(%>");
17811 initializer = c_parser_postfix_expression (parser);
17812 if (initializer.value
17813 && TREE_CODE (initializer.value) == CALL_EXPR)
17816 tree c = initializer.value;
17817 for (j = 0; j < call_expr_nargs (c); j++)
17819 tree a = CALL_EXPR_ARG (c, j);
17821 if (TREE_CODE (a) == ADDR_EXPR
17822 && TREE_OPERAND (a, 0) == omp_priv)
17825 if (j == call_expr_nargs (c))
17826 error ("one of the initializer call arguments should be "
17832 c_parser_consume_token (parser);
17833 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
17837 tree st = push_stmt_list ();
17838 location_t loc = c_parser_peek_token (parser)->location;
17839 rich_location richloc (line_table, loc);
17840 start_init (omp_priv, NULL_TREE, 0, &richloc);
17841 struct c_expr init = c_parser_initializer (parser);
17843 finish_decl (omp_priv, loc, init.value,
17844 init.original_type, NULL_TREE);
17845 pop_stmt_list (st);
17849 && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
17855 c_parser_skip_to_pragma_eol (parser);
17857 tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3),
17858 DECL_INITIAL (reduc_decl));
17859 DECL_INITIAL (reduc_decl) = t;
17860 DECL_SOURCE_LOCATION (omp_out) = rloc;
17861 TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out;
17862 TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in;
17863 TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value;
17864 walk_tree (&combiner.value, c_check_omp_declare_reduction_r,
17865 &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL);
17868 DECL_SOURCE_LOCATION (omp_priv) = rloc;
17869 TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv;
17870 TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig;
17871 TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value;
17872 walk_tree (&initializer.value, c_check_omp_declare_reduction_r,
17873 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
17874 walk_tree (&DECL_INITIAL (omp_priv),
17875 c_check_omp_declare_reduction_r,
17876 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL);
17880 pop_stmt_list (stmt);
17882 if (cfun->language != NULL)
17884 ggc_free (cfun->language);
17885 cfun->language = NULL;
17888 current_function_decl = NULL_TREE;
17890 c_pop_function_context ();
17892 if (!clauses.is_empty ())
17894 parser->tokens = &parser->tokens_buf[0];
17895 parser->tokens_avail = tokens_avail;
17899 if (errs != errorcount)
17903 clauses.release ();
17909 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17910 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17911 initializer-clause[opt] new-line
17912 #pragma omp declare target new-line */
17915 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
17917 c_parser_consume_pragma (parser);
17918 if (c_parser_next_token_is (parser, CPP_NAME))
17920 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17921 if (strcmp (p, "simd") == 0)
17923 /* c_parser_consume_token (parser); done in
17924 c_parser_omp_declare_simd. */
17925 c_parser_omp_declare_simd (parser, context);
17928 if (strcmp (p, "reduction") == 0)
17930 c_parser_consume_token (parser);
17931 c_parser_omp_declare_reduction (parser, context);
17934 if (!flag_openmp) /* flag_openmp_simd */
17936 c_parser_skip_to_pragma_eol (parser, false);
17939 if (strcmp (p, "target") == 0)
17941 c_parser_consume_token (parser);
17942 c_parser_omp_declare_target (parser);
17947 c_parser_error (parser, "expected %<simd%> or %<reduction%> "
17949 c_parser_skip_to_pragma_eol (parser);
17953 #pragma omp taskloop taskloop-clause[optseq] new-line
17956 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17959 #define OMP_TASKLOOP_CLAUSE_MASK \
17960 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17966 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17967 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17968 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17969 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17970 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17971 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17972 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17973 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17976 c_parser_omp_taskloop (location_t loc, c_parser *parser,
17977 char *p_name, omp_clause_mask mask, tree *cclauses,
17980 tree clauses, block, ret;
17982 strcat (p_name, " taskloop");
17983 mask |= OMP_TASKLOOP_CLAUSE_MASK;
17985 if (c_parser_next_token_is (parser, CPP_NAME))
17987 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
17989 if (strcmp (p, "simd") == 0)
17991 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
17992 if (cclauses == NULL)
17993 cclauses = cclauses_buf;
17994 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION);
17995 c_parser_consume_token (parser);
17996 if (!flag_openmp) /* flag_openmp_simd */
17997 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
17999 block = c_begin_compound_stmt (true);
18000 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
18001 block = c_end_compound_stmt (loc, block, true);
18004 ret = make_node (OMP_TASKLOOP);
18005 TREE_TYPE (ret) = void_type_node;
18006 OMP_FOR_BODY (ret) = block;
18007 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
18008 SET_EXPR_LOCATION (ret, loc);
18013 if (!flag_openmp) /* flag_openmp_simd */
18015 c_parser_skip_to_pragma_eol (parser, false);
18019 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
18022 omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses);
18023 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
18026 block = c_begin_compound_stmt (true);
18027 ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p);
18028 block = c_end_compound_stmt (loc, block, true);
18034 /* Main entry point to parsing most OpenMP pragmas. */
18037 c_parser_omp_construct (c_parser *parser, bool *if_p)
18039 enum pragma_kind p_kind;
18042 char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
18043 omp_clause_mask mask (0);
18045 loc = c_parser_peek_token (parser)->location;
18046 p_kind = c_parser_peek_token (parser)->pragma_kind;
18047 c_parser_consume_pragma (parser);
18051 case PRAGMA_OACC_ATOMIC:
18052 c_parser_omp_atomic (loc, parser);
18054 case PRAGMA_OACC_CACHE:
18055 strcpy (p_name, "#pragma acc");
18056 stmt = c_parser_oacc_cache (loc, parser);
18058 case PRAGMA_OACC_DATA:
18059 stmt = c_parser_oacc_data (loc, parser, if_p);
18061 case PRAGMA_OACC_HOST_DATA:
18062 stmt = c_parser_oacc_host_data (loc, parser, if_p);
18064 case PRAGMA_OACC_KERNELS:
18065 case PRAGMA_OACC_PARALLEL:
18066 strcpy (p_name, "#pragma acc");
18067 stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name,
18070 case PRAGMA_OACC_LOOP:
18071 strcpy (p_name, "#pragma acc");
18072 stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p);
18074 case PRAGMA_OACC_WAIT:
18075 strcpy (p_name, "#pragma wait");
18076 stmt = c_parser_oacc_wait (loc, parser, p_name);
18078 case PRAGMA_OMP_ATOMIC:
18079 c_parser_omp_atomic (loc, parser);
18081 case PRAGMA_OMP_CRITICAL:
18082 stmt = c_parser_omp_critical (loc, parser, if_p);
18084 case PRAGMA_OMP_DISTRIBUTE:
18085 strcpy (p_name, "#pragma omp");
18086 stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p);
18088 case PRAGMA_OMP_FOR:
18089 strcpy (p_name, "#pragma omp");
18090 stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p);
18092 case PRAGMA_OMP_MASTER:
18093 stmt = c_parser_omp_master (loc, parser, if_p);
18095 case PRAGMA_OMP_PARALLEL:
18096 strcpy (p_name, "#pragma omp");
18097 stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p);
18099 case PRAGMA_OMP_SECTIONS:
18100 strcpy (p_name, "#pragma omp");
18101 stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL);
18103 case PRAGMA_OMP_SIMD:
18104 strcpy (p_name, "#pragma omp");
18105 stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p);
18107 case PRAGMA_OMP_SINGLE:
18108 stmt = c_parser_omp_single (loc, parser, if_p);
18110 case PRAGMA_OMP_TASK:
18111 stmt = c_parser_omp_task (loc, parser, if_p);
18113 case PRAGMA_OMP_TASKGROUP:
18114 stmt = c_parser_omp_taskgroup (parser, if_p);
18116 case PRAGMA_OMP_TASKLOOP:
18117 strcpy (p_name, "#pragma omp");
18118 stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p);
18120 case PRAGMA_OMP_TEAMS:
18121 strcpy (p_name, "#pragma omp");
18122 stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p);
18125 gcc_unreachable ();
18129 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
18134 # pragma omp threadprivate (variable-list) */
18137 c_parser_omp_threadprivate (c_parser *parser)
18142 c_parser_consume_pragma (parser);
18143 loc = c_parser_peek_token (parser)->location;
18144 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
18146 /* Mark every variable in VARS to be assigned thread local storage. */
18147 for (t = vars; t; t = TREE_CHAIN (t))
18149 tree v = TREE_PURPOSE (t);
18151 /* FIXME diagnostics: Ideally we should keep individual
18152 locations for all the variables in the var list to make the
18153 following errors more precise. Perhaps
18154 c_parser_omp_var_list_parens() should construct a list of
18155 locations to go along with the var list. */
18157 /* If V had already been marked threadprivate, it doesn't matter
18158 whether it had been used prior to this point. */
18160 error_at (loc, "%qD is not a variable", v);
18161 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
18162 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
18163 else if (! is_global_var (v))
18164 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
18165 else if (TREE_TYPE (v) == error_mark_node)
18167 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
18168 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
18171 if (! DECL_THREAD_LOCAL_P (v))
18173 set_decl_tls_model (v, decl_default_tls_model (v));
18174 /* If rtl has been already set for this var, call
18175 make_decl_rtl once again, so that encode_section_info
18176 has a chance to look at the new decl flags. */
18177 if (DECL_RTL_SET_P (v))
18180 C_DECL_THREADPRIVATE_P (v) = 1;
18184 c_parser_skip_to_pragma_eol (parser);
18187 /* Parse a transaction attribute (GCC Extension).
18189 transaction-attribute:
18193 The transactional memory language description is written for C++,
18194 and uses the C++0x attribute syntax. For compatibility, allow the
18195 bracket style for transactions in C as well. */
18198 c_parser_transaction_attributes (c_parser *parser)
18200 tree attr_name, attr = NULL;
18202 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
18203 return c_parser_attributes (parser);
18205 if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
18207 c_parser_consume_token (parser);
18208 if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>"))
18211 attr_name = c_parser_attribute_any_word (parser);
18214 c_parser_consume_token (parser);
18215 attr = build_tree_list (attr_name, NULL_TREE);
18218 c_parser_error (parser, "expected identifier");
18220 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
18222 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>");
18226 /* Parse a __transaction_atomic or __transaction_relaxed statement
18229 transaction-statement:
18230 __transaction_atomic transaction-attribute[opt] compound-statement
18231 __transaction_relaxed compound-statement
18233 Note that the only valid attribute is: "outer".
18237 c_parser_transaction (c_parser *parser, enum rid keyword)
18239 unsigned int old_in = parser->in_transaction;
18240 unsigned int this_in = 1, new_in;
18241 location_t loc = c_parser_peek_token (parser)->location;
18244 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
18245 || keyword == RID_TRANSACTION_RELAXED)
18246 && c_parser_next_token_is_keyword (parser, keyword));
18247 c_parser_consume_token (parser);
18249 if (keyword == RID_TRANSACTION_RELAXED)
18250 this_in |= TM_STMT_ATTR_RELAXED;
18253 attrs = c_parser_transaction_attributes (parser);
18255 this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
18258 /* Keep track if we're in the lexical scope of an outer transaction. */
18259 new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
18261 parser->in_transaction = new_in;
18262 stmt = c_parser_compound_statement (parser);
18263 parser->in_transaction = old_in;
18266 stmt = c_finish_transaction (loc, stmt, this_in);
18268 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
18269 "%<__transaction_atomic%> without transactional memory support enabled"
18270 : "%<__transaction_relaxed %> "
18271 "without transactional memory support enabled"));
18276 /* Parse a __transaction_atomic or __transaction_relaxed expression
18279 transaction-expression:
18280 __transaction_atomic ( expression )
18281 __transaction_relaxed ( expression )
18284 static struct c_expr
18285 c_parser_transaction_expression (c_parser *parser, enum rid keyword)
18288 unsigned int old_in = parser->in_transaction;
18289 unsigned int this_in = 1;
18290 location_t loc = c_parser_peek_token (parser)->location;
18293 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC
18294 || keyword == RID_TRANSACTION_RELAXED)
18295 && c_parser_next_token_is_keyword (parser, keyword));
18296 c_parser_consume_token (parser);
18298 if (keyword == RID_TRANSACTION_RELAXED)
18299 this_in |= TM_STMT_ATTR_RELAXED;
18302 attrs = c_parser_transaction_attributes (parser);
18304 this_in |= parse_tm_stmt_attr (attrs, 0);
18307 parser->in_transaction = this_in;
18308 matching_parens parens;
18309 if (parens.require_open (parser))
18311 tree expr = c_parser_expression (parser).value;
18312 ret.original_type = TREE_TYPE (expr);
18313 ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr);
18314 if (this_in & TM_STMT_ATTR_RELAXED)
18315 TRANSACTION_EXPR_RELAXED (ret.value) = 1;
18316 SET_EXPR_LOCATION (ret.value, loc);
18317 ret.original_code = TRANSACTION_EXPR;
18318 if (!parens.require_close (parser))
18320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
18328 ret.original_code = ERROR_MARK;
18329 ret.original_type = NULL;
18331 parser->in_transaction = old_in;
18334 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ?
18335 "%<__transaction_atomic%> without transactional memory support enabled"
18336 : "%<__transaction_relaxed %> "
18337 "without transactional memory support enabled"));
18339 set_c_expr_source_range (&ret, loc, loc);
18344 /* Parse a __transaction_cancel statement (GCC Extension).
18346 transaction-cancel-statement:
18347 __transaction_cancel transaction-attribute[opt] ;
18349 Note that the only valid attribute is "outer".
18353 c_parser_transaction_cancel (c_parser *parser)
18355 location_t loc = c_parser_peek_token (parser)->location;
18357 bool is_outer = false;
18359 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL));
18360 c_parser_consume_token (parser);
18362 attrs = c_parser_transaction_attributes (parser);
18364 is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
18368 error_at (loc, "%<__transaction_cancel%> without "
18369 "transactional memory support enabled");
18372 else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
18374 error_at (loc, "%<__transaction_cancel%> within a "
18375 "%<__transaction_relaxed%>");
18380 if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
18381 && !is_tm_may_cancel_outer (current_function_decl))
18383 error_at (loc, "outer %<__transaction_cancel%> not "
18384 "within outer %<__transaction_atomic%>");
18385 error_at (loc, " or a %<transaction_may_cancel_outer%> function");
18389 else if (parser->in_transaction == 0)
18391 error_at (loc, "%<__transaction_cancel%> not within "
18392 "%<__transaction_atomic%>");
18396 return add_stmt (build_tm_abort_call (loc, is_outer));
18399 return build1 (NOP_EXPR, void_type_node, error_mark_node);
18402 /* Parse a single source file. */
18405 c_parse_file (void)
18407 /* Use local storage to begin. If the first token is a pragma, parse it.
18408 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18409 which will cause garbage collection. */
18412 memset (&tparser, 0, sizeof tparser);
18413 tparser.tokens = &tparser.tokens_buf[0];
18414 the_parser = &tparser;
18416 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
18417 c_parser_pragma_pch_preprocess (&tparser);
18419 the_parser = ggc_alloc<c_parser> ();
18420 *the_parser = tparser;
18421 if (tparser.tokens == &tparser.tokens_buf[0])
18422 the_parser->tokens = &the_parser->tokens_buf[0];
18424 /* Initialize EH, if we've been told to do so. */
18425 if (flag_exceptions)
18426 using_eh_for_cleanups ();
18428 c_parser_translation_unit (the_parser);
18432 /* Parse the body of a function declaration marked with "__RTL".
18434 The RTL parser works on the level of characters read from a
18435 FILE *, whereas c_parser works at the level of tokens.
18436 Square this circle by consuming all of the tokens up to and
18437 including the closing brace, recording the start/end of the RTL
18438 fragment, and reopening the file and re-reading the relevant
18439 lines within the RTL parser.
18441 This requires the opening and closing braces of the C function
18442 to be on separate lines from the RTL they wrap.
18444 Take ownership of START_WITH_PASS, if non-NULL. */
18447 c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass)
18449 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
18451 free (start_with_pass);
18455 location_t start_loc = c_parser_peek_token (parser)->location;
18457 /* Consume all tokens, up to the closing brace, handling
18458 matching pairs of braces in the rtl dump. */
18459 int num_open_braces = 1;
18462 switch (c_parser_peek_token (parser)->type)
18464 case CPP_OPEN_BRACE:
18467 case CPP_CLOSE_BRACE:
18468 if (--num_open_braces == 0)
18469 goto found_closing_brace;
18472 error_at (start_loc, "no closing brace");
18473 free (start_with_pass);
18478 c_parser_consume_token (parser);
18481 found_closing_brace:
18482 /* At the closing brace; record its location. */
18483 location_t end_loc = c_parser_peek_token (parser)->location;
18485 /* Consume the closing brace. */
18486 c_parser_consume_token (parser);
18488 /* Invoke the RTL parser. */
18489 if (!read_rtl_function_body_from_file_range (start_loc, end_loc))
18491 free (start_with_pass);
18495 /* If a pass name was provided for START_WITH_PASS, run the backend
18496 accordingly now, on the cfun created above, transferring
18497 ownership of START_WITH_PASS. */
18498 if (start_with_pass)
18499 run_rtl_passes (start_with_pass);
18502 #include "gt-c-c-parser.h"